2
0

test.c 2.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465
  1. /* test.c
  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. /*
  22. * Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. *
  26. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  27. * WC_USE_DEVID=0x1234
  28. */
  29. #ifdef HAVE_CONFIG_H
  30. #include <config.h>
  31. #endif
  32. #ifndef WOLFSSL_USER_SETTINGS
  33. #include <wolfssl/options.h>
  34. #endif
  35. #include <wolfssl/wolfcrypt/settings.h>
  36. #ifdef WOLFSSL_DEBUG_TRACE_ERROR_CODES
  37. #define WOLFSSL_DEBUG_TRACE_ERROR_CODES_ALWAYS
  38. #endif
  39. #ifndef NO_CRYPT_TEST
  40. #include <wolfssl/version.h>
  41. #include <wolfssl/wolfcrypt/types.h>
  42. #include <wolfssl/wolfcrypt/wc_port.h>
  43. #include <wolfssl/wolfcrypt/mem_track.h>
  44. #if defined(HAVE_WOLFCRYPT_TEST_OPTIONS)
  45. #include <wolfssl/ssl.h>
  46. #define err_sys err_sys_remap /* remap err_sys */
  47. #include <wolfssl/test.h>
  48. #undef err_sys
  49. #endif
  50. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  51. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  52. #include <stdint.h>
  53. #endif
  54. #ifdef HAVE_STACK_SIZE_VERBOSE
  55. #ifdef WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES
  56. static WC_MAYBE_UNUSED ssize_t max_relative_stack =
  57. WOLFSSL_TEST_MAX_RELATIVE_STACK_BYTES;
  58. #else
  59. static WC_MAYBE_UNUSED ssize_t max_relative_stack = -1;
  60. #endif
  61. #endif
  62. const byte const_byte_array[] = "A+Gd\0\0\0";
  63. #define CBPTR_EXPECTED 'A'
  64. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  65. #ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS
  66. static ssize_t max_relative_heap_allocs = WOLFSSL_TEST_MAX_RELATIVE_HEAP_ALLOCS;
  67. #else
  68. static ssize_t max_relative_heap_allocs = -1;
  69. #endif
  70. #ifdef WOLFSSL_TEST_MAX_RELATIVE_HEAP_BYTES
  71. static ssize_t max_relative_heap_bytes = WOLFSSL_TEST_MAX_RELATIVE_HEAP_BYTES;
  72. #else
  73. static ssize_t max_relative_heap_bytes = -1;
  74. #endif
  75. #define PRINT_HEAP_CHECKPOINT() { \
  76. const ssize_t _rha = wolfCrypt_heap_peakAllocs_checkpoint() - heap_baselineAllocs; \
  77. const ssize_t _rhb = wolfCrypt_heap_peakBytes_checkpoint() - heap_baselineBytes; \
  78. printf(" relative heap peak usage: %ld alloc%s, %ld bytes\n", \
  79. (long int)_rha, \
  80. _rha == 1 ? "" : "s", \
  81. (long int)_rhb); \
  82. if ((max_relative_heap_allocs > 0) && (_rha > max_relative_heap_allocs)) \
  83. return err_sys("heap allocs exceed designated max.", \
  84. WC_TEST_RET_ENC_NC); \
  85. if ((max_relative_heap_bytes > 0) && (_rhb > max_relative_heap_bytes)) \
  86. return err_sys("heap bytes exceed designated max.", \
  87. WC_TEST_RET_ENC_NC); \
  88. heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint(); \
  89. heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint(); \
  90. }
  91. #else
  92. #define PRINT_HEAP_CHECKPOINT() WC_DO_NOTHING
  93. #endif /* WOLFSSL_TRACK_MEMORY_VERBOSE && !WOLFSSL_STATIC_MEMORY */
  94. #ifdef USE_FLAT_TEST_H
  95. #ifdef HAVE_CONFIG_H
  96. #include "test_paths.h"
  97. #endif
  98. #include "test.h"
  99. #else
  100. #ifdef HAVE_CONFIG_H
  101. #include "wolfcrypt/test/test_paths.h"
  102. #endif
  103. #include "wolfcrypt/test/test.h"
  104. #endif
  105. /* printf mappings */
  106. #ifndef WOLFSSL_LOG_PRINTF
  107. #if defined(FREESCALE_MQX) || defined(FREESCALE_KSDK_MQX)
  108. #include <mqx.h>
  109. #include <stdlib.h>
  110. /* see wc_port.h for fio.h and nio.h includes */
  111. #elif defined(FREESCALE_KSDK_BM)
  112. #include "fsl_debug_console.h"
  113. #undef printf
  114. #define printf PRINTF
  115. #elif defined(WOLFSSL_APACHE_MYNEWT)
  116. #include <assert.h>
  117. #include <string.h>
  118. #include "sysinit/sysinit.h"
  119. #include "os/os.h"
  120. #ifdef ARCH_sim
  121. #include "mcu/mcu_sim.h"
  122. #endif
  123. #include "os/os_time.h"
  124. #elif defined(WOLFSSL_ESPIDF)
  125. #include <time.h>
  126. #include <sys/time.h>
  127. #include <esp_log.h>
  128. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  129. #define ESPIDF_TAG "wc_test"
  130. #elif defined(WOLFSSL_ZEPHYR)
  131. #include <stdio.h>
  132. #define printf printk
  133. #elif defined(MICRIUM)
  134. #include <os.h>
  135. #if (OS_VERSION < 50000)
  136. #include <bsp_ser.h>
  137. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  138. #undef printf
  139. #define printf BSP_Ser_Printf
  140. #else
  141. #include <stdio.h>
  142. #endif
  143. #elif defined(WOLFSSL_PB)
  144. #include <stdarg.h>
  145. int wolfssl_pb_print(const char*, ...);
  146. #undef printf
  147. #define printf wolfssl_pb_print
  148. #elif defined(WOLFSSL_TELIT_M2MB)
  149. #include "wolfssl/wolfcrypt/wc_port.h" /* for m2mb headers */
  150. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  151. /* remap printf */
  152. #undef printf
  153. #define printf M2M_LOG_INFO
  154. /* OS requires occasional sleep() */
  155. #ifndef TEST_SLEEP_MS
  156. #define TEST_SLEEP_MS 50
  157. #endif
  158. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  159. /* don't use file system for these tests, since ./certs dir isn't loaded */
  160. #undef NO_FILESYSTEM
  161. #define NO_FILESYSTEM
  162. #elif defined(THREADX) && !defined(WOLFSSL_WICED) && \
  163. !defined(THREADX_NO_DC_PRINTF)
  164. #ifndef NETOS
  165. /* since just testing, use THREADX log printf instead (NETOS prototypes
  166. * this elsewhere) */
  167. int dc_log_printf(char*, ...);
  168. #endif
  169. #undef printf
  170. #define printf dc_log_printf
  171. #elif defined(ANDROID)
  172. #ifdef XMALLOC_USER
  173. #include <stdlib.h> /* we're using malloc / free direct here */
  174. #endif
  175. #ifndef STRING_USER
  176. #include <stdio.h>
  177. #endif
  178. #include <android/log.h>
  179. #ifdef ANDROID_V454 /* See fips/android/wolfCrypt_v454_android */
  180. #ifndef NO_FILESYSTEM
  181. #define NO_FILESYSTEM /* Turn off tests that want to call SaveDerAndPem() */
  182. #endif
  183. #else
  184. #define printf(...) \
  185. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  186. #define fprintf(fp, ...) \
  187. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  188. #endif
  189. #elif defined(WOLFSSL_DEOS)
  190. #include <printx.h>
  191. #undef printf
  192. #define printf printx
  193. #elif defined(WOLFSSL_RENESAS_RSIP)
  194. #ifndef TEST_SLEEP
  195. #define TEST_SLEEP() vTaskDelay(50)
  196. #endif
  197. #undef vprintf
  198. #define vprintf rsip_vprintf
  199. #include <stdarg.h> /* for var args */
  200. int rsip_vprintf(const char* restrict format, va_list args)
  201. {
  202. int ret;
  203. char tmpBuf[80];
  204. ret = XVSNPRINTF(tmpBuf, sizeof(tmpBuf), format, args);
  205. printf(tmpBuf);
  206. return ret;
  207. }
  208. #else
  209. #ifdef XMALLOC_USER
  210. #include <stdlib.h> /* we're using malloc / free direct here */
  211. #endif
  212. #if !defined(STRING_USER) && !defined(WOLFSSL_LINUXKM)
  213. #include <stdio.h>
  214. #endif
  215. #if defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_LINUXKM_VERBOSE_DEBUG)
  216. #undef printf
  217. #define printf(...) ({})
  218. #endif
  219. /* enable way for customer to override test/bench printf */
  220. #ifdef XPRINTF
  221. #undef printf
  222. #define printf XPRINTF
  223. #elif !defined(printf)
  224. /* arrange for printf() to flush after every message -- this assures
  225. * redirected output (to a log file) records progress right up to the
  226. * moment of a crash/abort(); otherwise anything queued in stdout would
  227. * be lost.
  228. */
  229. #define printf(...) ( printf(__VA_ARGS__), fflush(stdout) )
  230. #endif
  231. #endif
  232. #endif /* !WOLFSSL_LOG_PRINTF */
  233. #include <wolfssl/wolfcrypt/memory.h>
  234. #include <wolfssl/wolfcrypt/wc_port.h>
  235. #include <wolfssl/wolfcrypt/logging.h>
  236. #include <wolfssl/wolfcrypt/types.h>
  237. #include <wolfssl/wolfcrypt/asn.h>
  238. #include <wolfssl/wolfcrypt/md2.h>
  239. #include <wolfssl/wolfcrypt/md5.h>
  240. #include <wolfssl/wolfcrypt/md4.h>
  241. #include <wolfssl/wolfcrypt/sha.h>
  242. #include <wolfssl/wolfcrypt/sha256.h>
  243. #include <wolfssl/wolfcrypt/sha512.h>
  244. #include <wolfssl/wolfcrypt/hash.h>
  245. #include <wolfssl/wolfcrypt/rc2.h>
  246. #include <wolfssl/wolfcrypt/arc4.h>
  247. #if !defined(WC_NO_RNG)
  248. #include <wolfssl/wolfcrypt/random.h>
  249. #endif
  250. #include <wolfssl/wolfcrypt/wolfmath.h>
  251. #include <wolfssl/wolfcrypt/coding.h>
  252. #include <wolfssl/wolfcrypt/signature.h>
  253. #include <wolfssl/wolfcrypt/rsa.h>
  254. #include <wolfssl/wolfcrypt/des3.h>
  255. #include <wolfssl/wolfcrypt/aes.h>
  256. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  257. #include <wolfssl/wolfcrypt/cmac.h>
  258. #include <wolfssl/wolfcrypt/siphash.h>
  259. #include <wolfssl/wolfcrypt/poly1305.h>
  260. #include <wolfssl/wolfcrypt/camellia.h>
  261. #include <wolfssl/wolfcrypt/hmac.h>
  262. #include <wolfssl/wolfcrypt/kdf.h>
  263. #include <wolfssl/wolfcrypt/dh.h>
  264. #include <wolfssl/wolfcrypt/dsa.h>
  265. #include <wolfssl/wolfcrypt/srp.h>
  266. #include <wolfssl/wolfcrypt/chacha.h>
  267. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  268. #include <wolfssl/wolfcrypt/pwdbased.h>
  269. #include <wolfssl/wolfcrypt/ripemd.h>
  270. #include <wolfssl/wolfcrypt/error-crypt.h>
  271. #ifdef HAVE_ECC
  272. #include <wolfssl/wolfcrypt/ecc.h>
  273. #endif
  274. #ifdef WOLFSSL_SM2
  275. #include <wolfssl/wolfcrypt/sm2.h>
  276. #endif
  277. #ifdef HAVE_HPKE
  278. #include <wolfssl/wolfcrypt/hpke.h>
  279. #endif
  280. #ifdef HAVE_CURVE25519
  281. #include <wolfssl/wolfcrypt/curve25519.h>
  282. #endif
  283. #ifdef HAVE_ED25519
  284. #include <wolfssl/wolfcrypt/ed25519.h>
  285. #endif
  286. #ifdef HAVE_CURVE448
  287. #include <wolfssl/wolfcrypt/curve448.h>
  288. #endif
  289. #ifdef HAVE_ED448
  290. #include <wolfssl/wolfcrypt/ed448.h>
  291. #endif
  292. #ifdef WOLFSSL_HAVE_KYBER
  293. #include <wolfssl/wolfcrypt/kyber.h>
  294. #ifdef WOLFSSL_WC_KYBER
  295. #include <wolfssl/wolfcrypt/wc_kyber.h>
  296. #endif
  297. #if defined(HAVE_LIBOQS)
  298. #include <wolfssl/wolfcrypt/ext_kyber.h>
  299. #endif
  300. #endif
  301. #ifdef HAVE_DILITHIUM
  302. #include <wolfssl/wolfcrypt/dilithium.h>
  303. #endif
  304. #if defined(WOLFSSL_HAVE_XMSS)
  305. #include <wolfssl/wolfcrypt/xmss.h>
  306. #ifdef HAVE_LIBXMSS
  307. #include <wolfssl/wolfcrypt/ext_xmss.h>
  308. #else
  309. #include <wolfssl/wolfcrypt/wc_xmss.h>
  310. #endif
  311. #endif
  312. #if defined(WOLFSSL_HAVE_LMS)
  313. #include <wolfssl/wolfcrypt/lms.h>
  314. #ifdef HAVE_LIBLMS
  315. #include <wolfssl/wolfcrypt/ext_lms.h>
  316. #else
  317. #include <wolfssl/wolfcrypt/wc_lms.h>
  318. #endif
  319. #endif
  320. #ifdef WOLFCRYPT_HAVE_ECCSI
  321. #include <wolfssl/wolfcrypt/eccsi.h>
  322. #endif
  323. #ifdef WOLFCRYPT_HAVE_SAKKE
  324. #include <wolfssl/wolfcrypt/sakke.h>
  325. #endif
  326. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  327. #include <wolfssl/wolfcrypt/blake2.h>
  328. #endif
  329. #ifdef WOLFSSL_SHA3
  330. #include <wolfssl/wolfcrypt/sha3.h>
  331. #endif
  332. #ifdef WOLFSSL_SM3
  333. #include <wolfssl/wolfcrypt/sm3.h>
  334. #endif
  335. #ifdef WOLFSSL_SM4
  336. #include <wolfssl/wolfcrypt/sm4.h>
  337. #endif
  338. #ifdef HAVE_LIBZ
  339. #include <wolfssl/wolfcrypt/compress.h>
  340. #endif
  341. #ifdef HAVE_PKCS7
  342. #include <wolfssl/wolfcrypt/pkcs7.h>
  343. #endif
  344. #ifdef HAVE_PKCS12
  345. #include <wolfssl/wolfcrypt/pkcs12.h>
  346. #endif
  347. #ifdef HAVE_FIPS
  348. #include <wolfssl/wolfcrypt/fips_test.h>
  349. #endif
  350. #ifdef HAVE_SELFTEST
  351. #include <wolfssl/wolfcrypt/selftest.h>
  352. #endif
  353. #ifdef WOLFSSL_ASYNC_CRYPT
  354. #include <wolfssl/wolfcrypt/async.h>
  355. #endif
  356. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  357. #include <wolfssl/wolfcrypt/logging.h>
  358. #endif
  359. #ifdef WOLFSSL_CAAM
  360. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  361. #endif
  362. #ifdef WOLF_CRYPTO_CB
  363. #include <wolfssl/wolfcrypt/cryptocb.h>
  364. #ifdef HAVE_INTEL_QA_SYNC
  365. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  366. #endif
  367. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  368. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  369. #endif
  370. #ifdef HAVE_RENESAS_SYNC
  371. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  372. #endif
  373. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  374. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  375. #endif
  376. #endif
  377. #ifdef _MSC_VER
  378. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  379. #pragma warning(disable: 4996)
  380. #endif
  381. #ifdef OPENSSL_EXTRA
  382. #ifndef WOLFCRYPT_ONLY
  383. #include <wolfssl/openssl/evp.h>
  384. #include <wolfssl/openssl/hmac.h>
  385. #endif
  386. #include <wolfssl/openssl/rand.h>
  387. #include <wolfssl/openssl/aes.h>
  388. #include <wolfssl/openssl/des.h>
  389. #endif
  390. #if defined(NO_FILESYSTEM) || defined(WC_NO_RNG)
  391. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  392. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  393. #define USE_CERT_BUFFERS_2048
  394. #endif
  395. #if !defined(USE_CERT_BUFFERS_256)
  396. #define USE_CERT_BUFFERS_256
  397. #endif
  398. #endif
  399. #if defined(WOLFSSL_CERT_GEN) && (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  400. #define ENABLE_ECC384_CERT_GEN_TEST
  401. #endif
  402. #include <wolfssl/certs_test.h>
  403. #ifdef DEVKITPRO
  404. #include <wiiuse/wpad.h>
  405. #endif
  406. #ifdef WOLFSSL_NDS
  407. #include <nds/ndstypes.h>
  408. #include <nds/arm9/console.h>
  409. #include <nds/arm9/input.h>
  410. #include <nds/interrupts.h>
  411. #include <fat.h>
  412. #endif
  413. #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  414. /* FIPS build has replaced ecc.h. */
  415. #define wc_ecc_key_get_priv(key) (&((key)->k))
  416. #define WOLFSSL_HAVE_ECC_KEY_GET_PRIV
  417. #endif
  418. #ifdef WOLFSSL_STATIC_MEMORY
  419. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  420. #else
  421. #define HEAP_HINT NULL
  422. #endif /* WOLFSSL_STATIC_MEMORY */
  423. /* these cases do not have intermediate hashing support */
  424. #if (defined(WOLFSSL_AFALG_XILINX_SHA3) && !defined(WOLFSSL_AFALG_HASH_KEEP)) \
  425. && !defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  426. #define NO_INTM_HASH_TEST
  427. #endif
  428. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  429. defined(WOLFSSL_RENESAS_SCEPROTECT_CRYPTONLY) || \
  430. defined(WOLFSSL_SECO_CAAM)
  431. #define HASH_SIZE_LIMIT
  432. #endif
  433. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  434. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  435. static void initDefaultName(void);
  436. #endif
  437. /* for async devices */
  438. #ifdef WOLFSSL_CAAM_DEVID
  439. static int devId = WOLFSSL_CAAM_DEVID;
  440. #else
  441. #ifdef WC_USE_DEVID
  442. static int devId = WC_USE_DEVID;
  443. #else
  444. static int devId = INVALID_DEVID;
  445. #endif
  446. #endif
  447. #ifdef HAVE_WNR
  448. const char* wnrConfigFile = "wnr-example.conf";
  449. #endif
  450. #define TEST_STRING "Everyone gets Friday off."
  451. #define TEST_STRING_SZ 25
  452. typedef struct testVector {
  453. const char* input;
  454. const char* output;
  455. size_t inLen;
  456. size_t outLen;
  457. } testVector;
  458. #ifdef WOLFCRYPT_TEST_LINT
  459. #define WOLFSSL_TEST_SUBROUTINE static
  460. #else
  461. PRAGMA_GCC("GCC diagnostic ignored \"-Wunused-function\"")
  462. PRAGMA_CLANG("clang diagnostic ignored \"-Wunused-function\"")
  463. #endif
  464. #ifndef WOLFSSL_TEST_SUBROUTINE
  465. #define WOLFSSL_TEST_SUBROUTINE
  466. #endif
  467. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void);
  468. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void);
  469. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void);
  470. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void);
  471. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void);
  472. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void);
  473. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void);
  474. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void);
  475. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void);
  476. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void);
  477. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void);
  478. #if !defined(WOLFSSL_NOSHA512_224) && \
  479. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  480. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void);
  481. #endif
  482. #if !defined(WOLFSSL_NOSHA512_256) && \
  483. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  484. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void);
  485. #endif
  486. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void);
  487. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void);
  488. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void);
  489. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void);
  490. #ifdef WOLFSSL_SM3
  491. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void);
  492. #endif
  493. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void);
  494. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void);
  495. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void);
  496. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void);
  497. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void);
  498. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void);
  499. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void);
  500. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void);
  501. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  502. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  503. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  504. defined(WOLFSSL_AFALG_XILINX_RSA)
  505. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  506. static wc_test_ret_t hkdf_test(void);
  507. #else
  508. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void);
  509. #endif
  510. #endif /* HAVE_HKDF && ! NO_HMAC */
  511. #ifdef WOLFSSL_HAVE_PRF
  512. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  513. #ifdef WOLFSSL_BASE16
  514. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void);
  515. #endif /* WOLFSSL_BASE16 */
  516. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  517. #endif /* WOLFSSL_HAVE_PRF */
  518. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  519. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void);
  520. #endif
  521. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void);
  522. #ifdef WOLFSSL_TLS13
  523. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void);
  524. #endif
  525. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void);
  526. #if defined(HAVE_HPKE) && defined(HAVE_ECC) && defined(HAVE_AESGCM)
  527. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void);
  528. #endif
  529. #ifdef WC_SRTP_KDF
  530. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void);
  531. #endif
  532. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void);
  533. #ifdef WC_RC2
  534. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void);
  535. #endif
  536. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void);
  537. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void);
  538. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void);
  539. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void);
  540. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void);
  541. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void);
  542. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void);
  543. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void);
  544. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void);
  545. #if defined(WOLFSSL_AES_CFB)
  546. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void);
  547. #endif
  548. #ifdef WOLFSSL_AES_XTS
  549. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void);
  550. #endif
  551. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void);
  552. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void);
  553. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void);
  554. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void);
  555. #if defined(WOLFSSL_SIPHASH)
  556. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void);
  557. #endif
  558. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void);
  559. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void);
  560. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void);
  561. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void);
  562. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void);
  563. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void);
  564. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void);
  565. #ifdef WOLFSSL_SM4
  566. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void);
  567. #endif
  568. #ifdef WC_RSA_NO_PADDING
  569. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void);
  570. #endif
  571. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void);
  572. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void);
  573. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void);
  574. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void);
  575. #ifndef WC_NO_RNG
  576. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void);
  577. #endif /* WC_NO_RNG */
  578. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void);
  579. #if defined(USE_CERT_BUFFERS_2048) && \
  580. defined(HAVE_PKCS12) && \
  581. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  582. !defined(NO_CERTS) && !defined(NO_DES3)
  583. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void);
  584. #endif
  585. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void);
  586. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  587. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void); /* test mini api */
  588. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void);
  589. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void);
  590. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void);
  591. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void);
  592. #endif
  593. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void);
  594. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void);
  595. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  596. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void);
  597. #endif
  598. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void);
  599. #ifdef HAVE_ECC
  600. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void);
  601. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  602. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  603. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void);
  604. #endif
  605. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  606. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  607. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  608. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  609. /* skip for ATECC508/608A, cannot import private key buffers */
  610. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void);
  611. #endif
  612. #endif
  613. #ifdef HAVE_CURVE25519
  614. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void);
  615. #endif
  616. #ifdef HAVE_ED25519
  617. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void);
  618. #endif
  619. #ifdef HAVE_CURVE448
  620. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void);
  621. #endif
  622. #ifdef HAVE_ED448
  623. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void);
  624. #endif
  625. #ifdef WOLFSSL_HAVE_KYBER
  626. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void);
  627. #endif
  628. #ifdef HAVE_DILITHIUM
  629. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void);
  630. #endif
  631. #if defined(WOLFSSL_HAVE_XMSS)
  632. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  633. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void);
  634. #endif
  635. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  636. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void);
  637. #endif
  638. #endif
  639. #if defined(WOLFSSL_HAVE_LMS)
  640. #if !defined(WOLFSSL_SMALL_STACK)
  641. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  642. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  643. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void);
  644. #endif
  645. #endif
  646. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  647. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void);
  648. #endif
  649. #endif
  650. #ifdef WOLFCRYPT_HAVE_ECCSI
  651. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void);
  652. #endif
  653. #ifdef WOLFCRYPT_HAVE_SAKKE
  654. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void);
  655. #endif
  656. #ifdef HAVE_BLAKE2
  657. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void);
  658. #endif
  659. #ifdef HAVE_BLAKE2S
  660. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void);
  661. #endif
  662. #ifdef HAVE_LIBZ
  663. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void);
  664. #endif
  665. #ifdef HAVE_PKCS7
  666. #ifndef NO_PKCS7_ENCRYPTED_DATA
  667. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void);
  668. #endif
  669. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  670. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void);
  671. #endif
  672. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void);
  673. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void);
  674. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  675. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void);
  676. #endif
  677. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  678. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key,
  679. word32 keySz);
  680. #endif
  681. #endif
  682. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  683. !defined(NO_FILESYSTEM)
  684. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void);
  685. #endif
  686. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  687. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  688. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void);
  689. #endif
  690. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  691. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  692. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void);
  693. #endif
  694. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void);
  695. #if defined(WOLFSSL_PUBLIC_MP) && \
  696. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  697. defined(USE_FAST_MATH))
  698. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void);
  699. #endif
  700. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  701. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void);
  702. #endif
  703. #if defined(ASN_BER_TO_DER) && \
  704. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  705. defined(OPENSSL_EXTRA_X509_SMALL))
  706. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void);
  707. #endif
  708. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void);
  709. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  710. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void);
  711. #endif
  712. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  713. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void);
  714. #else
  715. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void);
  716. #endif
  717. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  718. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void);
  719. #endif
  720. #ifdef WOLFSSL_CAAM_BLOB
  721. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void);
  722. #endif
  723. #ifdef HAVE_ARIA
  724. #include "wolfssl/wolfcrypt/port/aria/aria-crypt.h"
  725. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz);
  726. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID);
  727. #endif
  728. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  729. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void);
  730. #endif
  731. #ifdef WOLFSSL_CERT_PIV
  732. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void);
  733. #endif
  734. #ifdef WOLFSSL_AES_SIV
  735. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void);
  736. #endif
  737. #if defined(WOLFSSL_AES_EAX) && \
  738. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  739. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void);
  740. #endif /* WOLFSSL_AES_EAX */
  741. /* General big buffer size for many tests. */
  742. #define FOURK_BUF 4096
  743. /* If not defined in user_settings, the ERROR_OUT pause is 120 seconds. */
  744. #ifndef WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION
  745. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION 120
  746. #endif
  747. #if defined(WOLFSSL_ESPIDF_ERROR_PAUSE)
  748. #if defined(CONFIG_FREERTOS_HZ)
  749. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  750. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * CONFIG_FREERTOS_HZ)
  751. #else
  752. /* If not defined, assume RTOS is 1000 ticks per second. */
  753. #define WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS \
  754. (WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION * 1000)
  755. #endif
  756. /* When defined, pause at error condition rather than exit with error. */
  757. #define ERROR_OUT(err, eLabel) \
  758. do { \
  759. ret = (err); \
  760. ESP_LOGE(ESPIDF_TAG, "Failed: Error = %d during %s, line %d", \
  761. err, __FUNCTION__, __LINE__); \
  762. ESP_LOGI(ESPIDF_TAG, "Extended system info:"); \
  763. esp_ShowExtendedSystemInfo(); \
  764. ESP_LOGW(ESPIDF_TAG, "Paused for %d seconds! " \
  765. "WOLFSSL_ESPIDF_ERROR_PAUSE is enabled.", \
  766. WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION); \
  767. vTaskDelay(WOLFSSL_ESPIDF_ERROR_PAUSE_DURATION_TICKS); \
  768. goto eLabel; \
  769. } while (0)
  770. #else
  771. #define ERROR_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  772. #endif
  773. /* Not all unexpected conditions are actually errors .*/
  774. #define WARNING_OUT(err, eLabel) do { ret = (err); goto eLabel; } while (0)
  775. static void render_error_message(const char* msg, wc_test_ret_t es)
  776. {
  777. (void)msg;
  778. (void)es;
  779. #ifdef WOLFSSL_LINUXKM
  780. #define err_sys_printf lkm_printf
  781. #else
  782. #define err_sys_printf printf
  783. #endif
  784. switch (WC_TEST_RET_DEC_TAG(es)) {
  785. case WC_TEST_RET_TAG_NC:
  786. err_sys_printf("%s error L=%d\n", msg, WC_TEST_RET_DEC_LN(es));
  787. break;
  788. case WC_TEST_RET_TAG_EC:
  789. #ifdef NO_ERROR_STRINGS
  790. err_sys_printf("%s error L=%d code=%d\n", msg,
  791. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es));
  792. #elif defined(WOLFCRYPT_ONLY) || !defined(WOLFSSL_TYPES_DEFINED)
  793. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  794. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  795. wc_GetErrorString(-WC_TEST_RET_DEC_I(es))
  796. );
  797. #else
  798. err_sys_printf("%s error L=%d code=%d (%s)\n", msg,
  799. WC_TEST_RET_DEC_LN(es), -WC_TEST_RET_DEC_I(es),
  800. wolfSSL_ERR_reason_error_string(-WC_TEST_RET_DEC_I(es))
  801. );
  802. #endif
  803. break;
  804. case WC_TEST_RET_TAG_ERRNO:
  805. {
  806. /* strerror_r() comes in two mutually incompatible flavors, a native glibc
  807. * flavor that always returns a non-null char pointer that must be used
  808. * directly, and a POSIX flavor that returns an error int, and iff success,
  809. * stores an error string in the supplied buffer. this is all most
  810. * infelicitous...
  811. */
  812. #if !defined(STRING_USER) && !defined(NO_ERROR_STRINGS) && \
  813. (defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199901L)) && \
  814. ((defined(__GLIBC__) && (__GLIBC__ >= 2) && defined(__USE_GNU)) || \
  815. (defined(__USE_XOPEN2K) && \
  816. defined(_POSIX_C_SOURCE) && \
  817. (_POSIX_C_SOURCE >= 200112L)))
  818. char errno_buf[64], *errno_string;
  819. /* precisely mirror the gate used in glibc string.h */
  820. #if defined __USE_XOPEN2K && !defined __USE_GNU
  821. if (strerror_r(WC_TEST_RET_DEC_I(es),
  822. errno_buf, sizeof(errno_buf)) != 0)
  823. XSTRLCPY(errno_buf, "?", sizeof(errno_buf));
  824. errno_string = errno_buf;
  825. #else
  826. errno_string = strerror_r(WC_TEST_RET_DEC_I(es),
  827. errno_buf, sizeof(errno_buf));
  828. #endif
  829. err_sys_printf("%s error L=%d errno=%d (%s)\n", msg,
  830. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es),
  831. errno_string);
  832. #else /* can't figure out how to strerror_r(), or don't want error strings */
  833. err_sys_printf("%s error L=%d errno=%d\n", msg,
  834. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  835. #endif
  836. break;
  837. }
  838. case WC_TEST_RET_TAG_I:
  839. err_sys_printf("%s error L=%d i=%d\n", msg,
  840. WC_TEST_RET_DEC_LN(es), WC_TEST_RET_DEC_I(es));
  841. break;
  842. }
  843. #undef err_sys_printf
  844. }
  845. static void print_fiducials(void);
  846. #ifdef HAVE_STACK_SIZE
  847. static THREAD_RETURN err_sys(const char* msg, int es)
  848. #else
  849. static wc_test_ret_t err_sys(const char* msg, wc_test_ret_t es)
  850. #endif
  851. {
  852. render_error_message(msg, es);
  853. print_fiducials();
  854. #ifdef WOLFSSL_LINUXKM
  855. EXIT_TEST(es);
  856. #else
  857. EXIT_TEST(-1);
  858. #endif
  859. }
  860. #ifndef HAVE_WOLFCRYPT_TEST_OPTIONS
  861. /* func_args from test.h, so don't have to pull in other stuff */
  862. typedef struct func_args {
  863. int argc;
  864. char** argv;
  865. wc_test_ret_t return_code;
  866. } func_args;
  867. #endif /* !HAVE_WOLFCRYPT_TEST_OPTIONS */
  868. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  869. static void myFipsCb(int ok, int err, const char* hash)
  870. {
  871. printf("in my Fips callback, ok = %d, err = %d\n", ok, err);
  872. printf("message = %s\n", wc_GetErrorString(err));
  873. printf("hash = %s\n", hash);
  874. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  875. printf("In core integrity hash check failure, copy above hash\n");
  876. printf("into verifyCore[] in fips_test.c and rebuild\n");
  877. }
  878. }
  879. #endif /* HAVE_FIPS && !WOLFSSL_LINUXKM */
  880. #if defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0) && !defined(WC_NO_CONSTRUCTORS)
  881. #if !defined(NO_AES)
  882. static WC_MAYBE_UNUSED Aes* wc_AesNew(void* heap, int thisDevId, int *result_code)
  883. {
  884. int ret;
  885. Aes* aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_AES);
  886. if (aes == NULL) {
  887. ret = MEMORY_E;
  888. }
  889. else {
  890. ret = wc_AesInit(aes, heap, thisDevId);
  891. if (ret != 0) {
  892. XFREE(aes, heap, DYNAMIC_TYPE_AES);
  893. aes = NULL;
  894. }
  895. }
  896. if (result_code != NULL)
  897. *result_code = ret;
  898. return aes;
  899. }
  900. static WC_MAYBE_UNUSED int wc_AesDelete(Aes *aes, Aes** aes_p)
  901. {
  902. if (aes == NULL)
  903. return BAD_FUNC_ARG;
  904. wc_AesFree(aes);
  905. XFREE(aes, aes->heap, DYNAMIC_TYPE_AES);
  906. if (aes_p != NULL)
  907. *aes_p = NULL;
  908. return 0;
  909. }
  910. #endif /* !NO_AES */
  911. #if !defined(NO_RSA)
  912. static WC_MAYBE_UNUSED RsaKey* wc_NewRsaKey(void* heap, int thisDevId, int *result_code)
  913. {
  914. int ret;
  915. RsaKey* key = (RsaKey*)XMALLOC(sizeof(RsaKey), heap, DYNAMIC_TYPE_RSA);
  916. if (key == NULL) {
  917. ret = MEMORY_E;
  918. }
  919. else {
  920. ret = wc_InitRsaKey_ex(key, heap, thisDevId);
  921. if (ret != 0) {
  922. XFREE(key, heap, DYNAMIC_TYPE_RSA);
  923. key = NULL;
  924. }
  925. }
  926. if (result_code != NULL)
  927. *result_code = ret;
  928. return key;
  929. }
  930. static WC_MAYBE_UNUSED int wc_DeleteRsaKey(RsaKey* key, RsaKey** key_p)
  931. {
  932. if (key == NULL)
  933. return BAD_FUNC_ARG;
  934. wc_FreeRsaKey(key);
  935. XFREE(key, key->heap, DYNAMIC_TYPE_RSA);
  936. if (key_p != NULL)
  937. *key_p = NULL;
  938. return 0;
  939. }
  940. #endif /* !NO_RSA */
  941. #endif /* FIPS_VERSION3_LT(6,0,0) && !WC_NO_CONSTRUCTORS */
  942. #ifdef WOLFSSL_STATIC_MEMORY
  943. #if defined(WOLFSSL_STATIC_MEMORY_TEST_SZ)
  944. static byte gTestMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  945. #elif defined(BENCH_EMBEDDED)
  946. static byte gTestMemory[14000];
  947. #elif defined(WOLFSSL_CERT_EXT)
  948. static byte gTestMemory[140000];
  949. #elif (defined(WOLFSSL_SP_MATH_ALL) || defined(USE_FAST_MATH)) && \
  950. !defined(ALT_ECC_SIZE)
  951. static byte gTestMemory[160000];
  952. #else
  953. static byte gTestMemory[80000];
  954. #endif
  955. #endif
  956. #ifdef WOLFSSL_PB
  957. static int wolfssl_pb_print(const char* msg, ...)
  958. {
  959. int ret;
  960. va_list args;
  961. char tmpBuf[80];
  962. va_start(args, msg);
  963. ret = vsprint(tmpBuf, msg, args);
  964. va_end(args);
  965. fnDumpStringToSystemLog(tmpBuf);
  966. return ret;
  967. }
  968. #endif /* WOLFSSL_PB */
  969. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  970. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  971. /* Enable support for RNG with crypto callback */
  972. static int rng_crypto_cb(int thisDevId, wc_CryptoInfo* info, void* ctx)
  973. {
  974. int rc = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
  975. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  976. rc = wc_GenerateSeed(&info->rng.rng->seed, info->rng.out, info->rng.sz);
  977. }
  978. (void)ctx;
  979. (void)thisDevId;
  980. return rc;
  981. }
  982. #endif
  983. #if defined(WC_KDF_NIST_SP_800_56C)
  984. #define INIT_SP80056C_TEST_VECTOR(_z, _fixedInfo, _derivedKey, _hashType) \
  985. { \
  986. .z = (const byte*)_z, .zSz = sizeof(_z) - 1, \
  987. .fixedInfo = (const byte*)_fixedInfo, \
  988. .fixedInfoSz = sizeof(_fixedInfo) - 1, \
  989. .derivedKey = (const byte*)_derivedKey, \
  990. .derivedKeySz = sizeof(_derivedKey) - 1, .hashType = _hashType, \
  991. }
  992. #define SP800_56C_MAX_OUT 128
  993. static WOLFSSL_TEST_SUBROUTINE wc_test_ret_t nist_sp80056c_kdf_test(void)
  994. {
  995. struct sp800_56c_test_vector {
  996. const byte* z;
  997. word32 zSz;
  998. const byte* fixedInfo;
  999. word32 fixedInfoSz;
  1000. const byte* derivedKey;
  1001. word32 derivedKeySz;
  1002. enum wc_HashType hashType;
  1003. };
  1004. struct sp800_56c_test_vector* v;
  1005. byte output[SP800_56C_MAX_OUT];
  1006. word32 i;
  1007. int ret;
  1008. /* vectors from
  1009. * https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
  1010. *
  1011. * (KeyManagement) */
  1012. struct sp800_56c_test_vector vctors[] = {
  1013. #if !defined(NO_SHA)
  1014. /* SHA-1 */
  1015. INIT_SP80056C_TEST_VECTOR(
  1016. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  1017. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  1018. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  1019. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1020. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1021. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  1022. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  1023. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  1024. WC_HASH_TYPE_SHA),
  1025. INIT_SP80056C_TEST_VECTOR(
  1026. "\xae\x64\xab\x2b\x2b\x75\xa9\x4c\xf8\xef\x24\xda\x24\x56\xbd\x3a"
  1027. "\xa3\x6d\xb6\x14\x29\xea\x55\x21",
  1028. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1029. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1030. "\xcc\x96\x5a\x52\xd0\x5c\x94\x9e\x52\xc0\x35\xfd\x03\x53\x0d\xb7"
  1031. "\xea\xa4\x08\x70\x2c\x9d\x35\x21\x1e\x67\x21\x54\x12\x45\x91\x51"
  1032. "\xba\x22\x62\xbd\x1e\x28\xe5\x6b",
  1033. WC_HASH_TYPE_SHA),
  1034. INIT_SP80056C_TEST_VECTOR(
  1035. "\x71\x5d\xc0\xea\x24\x6b\x46\x56\x63\xa8\x9c\xde\x04\x12\xc1\x92"
  1036. "\xe1\x9e\x58\xd5\xb0\xb6\x36\x6d\xa7\x89\xad\xbf\x44\x9a\x38\xaa"
  1037. "\x46\x69\xfe\x36\x30\xa2\x0f\x7f\xa3\x14\x9c\x9b\x4b\x0a\xb5\xcd"
  1038. "\x3e\x14\x18\x2b\x75\x04\xd5\xd2\x75\x2b\xf6\x58\x7a\xab\xc9\xf4"
  1039. "\xcb\x8f\xe5\x29\x23\x6a\xb8\x15\x36\xad\xd2\xbd\x25\xd6\xbf\x9d"
  1040. "\x5f\x1d\xf5\x76\x16\x5a\xa5\x5c\x24\x99\x61\xd8\xf8\x75\x00\xed"
  1041. "\x8d\xbf\xc5\xd2\x50\x53\x4c\x07\xd9\x9a\xc9\x17\xf9\x84\x60\x46"
  1042. "\xac\x5c\xb8\xa2\x98\x74\x26\x22\xd3\xc9\x86\x18\x06\x92\x46\xe8"
  1043. "\xad\x37\x11\x25\x57\xe0\xe6\x34\xb5\x81\x32\x7a\x4a\xd3\x2c\x7c"
  1044. "\x76\x4b\xe8\xf8\x08\x0d\x37\x2c\x63\x20\x93\xa7\x67\xf1\x55\xbd"
  1045. "\x22\xec\x00\x3c\xa6\x1c\x8b\x43\x32\x0f\x3a\xbe\xb5\xdd\xc4\xa3"
  1046. "\xb1\x89\x82\xfd\xd6\x51\x0f\x88\x3c\x8d\xc1\xe0\xb1\x57\xff\xb9"
  1047. "\xcf\xc0\xa5\x9c\xe2\xd4\x05\x5f\xfc\x73\xe7\x15\x2a\x6a\x95\x43"
  1048. "\xb9\x19\xe7\x94\xe9\x49\x61\x33\xbe\x2a\x23\x18\xd9\x05\x6e\xfd"
  1049. "\x74\x48\x2d\xc6\x3c\x0d\xb5\x8f\xe6\x42\x6b\x0f\xe7\x35\x45\x42"
  1050. "\xc2\x19\x7a\xb6\xbd\x35\xf1\xa9\x2d\xce\x90\xb1\xc4\x6d\x32\xc1",
  1051. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1052. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1053. "\x1b\x5f\xcc\x8d\x81\xa5\xd9\xa9\x36\x94\xe6\x47\x77\x88\xd8\x03"
  1054. "\x15\x84\xc3\xf5\x2e\x9f\x11\x7a\xe8\x18\x4d\xba\x56\x47\x9d\x87"
  1055. "\x66\x76\x92\xf1\x2d\x7b\xd3\x8b",
  1056. WC_HASH_TYPE_SHA),
  1057. INIT_SP80056C_TEST_VECTOR(
  1058. "\x33\xe0\x50\xbd\x20\x9f\x2d\xf2\x77\x19\x78\xfc\xd1\xd4\xc8\x2e"
  1059. "\x49\xd0\x1d\x65\xbb\x62\x03\x20\xd3\x0b\xfe\xa8\x7a\xa8\x69\xe1"
  1060. "\x07\xa5\x17\xa4\xc8\x5b\x69\x28\x45\x21\xca\x54\xb7\x7f\x59\xe9"
  1061. "\x4a\x85\x6d\xaa\x30\xa3\x85\xa5\x25\xd8\xa3\xf7\xe1\x5e\xe5\xe9"
  1062. "\xaa\x12\x8d\x45\xef\x63\xf9\x0c\x10\xe0\x8f\xc5\x26\x36\x13\x77"
  1063. "\x81\x54\x7a\x58\x9f\x97\x87\xf9\xd7\xdd\x61\x43\x41\x9a\x26\x16"
  1064. "\x80\x16\x82\x40\xaa\xb2\x01\x3d\x80\x20\xdb\xe8\x4b\x7e\x2b\xed"
  1065. "\xce\x67\x1b\x94\x03\xbd\x1f\x91\x71\xa2\x57\x90\xce\x66\x7d\xed",
  1066. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1067. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1068. "\x35\x10\x85\x85\xfc\x55\x62\xb5\xf1\x8f\x20\x7b\xa8\x35\x63\xe4"
  1069. "\x49\x28\x45\x6a\x5e\x53\x63\x7e\xae\x6b\xb5\xfc\x33\x88\xae\x02"
  1070. "\x91\x79\x0a\x1d\xc8\x31\x4e\x28",
  1071. WC_HASH_TYPE_SHA),
  1072. INIT_SP80056C_TEST_VECTOR(
  1073. "\x5c\x80\x4f\x45\x4d\x30\xd9\xc4\xdf\x85\x27\x1f\x93\x52\x8c\x91"
  1074. "\xdf\x6b\x48\xab\x5f\x80\xb3\xb5\x9c\xaa\xc1\xb2\x8f\x8a\xcb\xa9"
  1075. "\xcd\x3e\x39\xf3\xcb\x61\x45\x25\xd9\x52\x1d\x2e\x64\x4c\x53\xb8"
  1076. "\x07\xb8\x10\xf3\x40\x06\x2f\x25\x7d\x7d\x6f\xbf\xe8\xd5\xe8\xf0"
  1077. "\x72\xe9\xb6\xe9\xaf\xda\x94\x13\xea\xfb\x2e\x8b\x06\x99\xb1\xfb"
  1078. "\x5a\x0c\xac\xed\xde\xae\xad\x7e\x9c\xfb\xb3\x6a\xe2\xb4\x20\x83"
  1079. "\x5b\xd8\x3a\x19\xfb\x0b\x5e\x96\xbf\x8f\xa4\xd0\x9e\x34\x55\x25"
  1080. "\x16\x7e\xcd\x91\x55\x41\x6f\x46\xf4\x08\xed\x31\xb6\x3c\x6e\x6d",
  1081. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1082. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1083. "\xfa\xa0\x22\xce\x7f\xa9\xba\x95\xeb\xa3\x9f\x3f\x44\xf3\xee\x14"
  1084. "\x96\x0a\x0b\x23\x9d\x01\x4b\x57\x70\xe4\x71\xd7\x5a\x99\xea\x87"
  1085. "\x10\xe3\x8f\x0c\xef\x0f\xfc\x67",
  1086. WC_HASH_TYPE_SHA),
  1087. INIT_SP80056C_TEST_VECTOR(
  1088. "\xad\x42\x01\x82\x63\x3f\x85\x26\xbf\xe9\x54\xac\xda\x37\x6f\x05"
  1089. "\xe5\xff\x4f\x83\x7f\x54\xfe\xbe\x0f\xb1\x2a\x1b\x3b\xeb\xf2\x63"
  1090. "\xee\x21\x64\x13\xed\x06\xa8\x4a\x12\xeb\x51\x11\x59\xf1\x33\x7d",
  1091. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1092. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1093. "\x6f\xef\x44\x2f\xc1\x7a\x7e\x2b\x0c\x9d\xec\xe0\xe4\x7a\x57\x48"
  1094. "\xac\xb4\x6a\xf1\x98\xd7\x67\x47\x0f\x28\xa1\x04\xb5\x61\x30\xae"
  1095. "\xb0\x10\x09\xa4\x56\x82\xa5\xe1",
  1096. WC_HASH_TYPE_SHA),
  1097. #endif
  1098. #if defined(WOLFSSL_SHA224)
  1099. /* SHA-224*/
  1100. INIT_SP80056C_TEST_VECTOR(
  1101. "\x8c\x5d\x6e\x5d\x36\x06\x83\xba\x55\xb0\x9d\xb1\x69\x6d\x7c\x64"
  1102. "\x02\xff\x87\x88\x5f\xf5\x07\x70\xf2\x76\x7b\x75\x54\x60\x20\x7e"
  1103. "\xd5\xc7\x43\xfd\x27\xe7\xeb\x1d\x0c\xa5\x91\xf8\x56\x38\x93\x11"
  1104. "\x73\x07\x44\xf2\x04\xd2\xe5\x5b\x8b\xd4\x46\xce\xca\x03\x1f\x7b"
  1105. "\xac\xcf\xf1\xa7\x1b\x68\x34\x59\xcc\x54\xd5\x01\xda\xbf\x4a\x84"
  1106. "\xcd\xb8\x6d\xfa\xda\xff\x31\x0f\xbd\xba\xf7\x4d\xd5\x1b\xa1\xe1"
  1107. "\xe1\x19\x1a\xf1\x4c\x9b\xf8\x94\x43\xbf\x58\x8e\x9c\xe3\x30\x34"
  1108. "\xaf\x5e\x89\xbf\x6f\xfc\x47\xd7\xd9\xca\x4a\x5e\x8f\xf8\xa0\x50"
  1109. "\x20\xbb\x0f\x95\xbc\xde\x01\x56\xd8\x7f\xb8\x60\xbd\x40\x83\xfa"
  1110. "\x5b\x53\x1a\x08\xa4\xfb\x7e\xe0\x20\x1a\xe8\xb3\xcc\xff\xe9\x9f"
  1111. "\x27\x0b\xc3\x53\x4b\xaa\xcf\xc0\x01\xcd\xd8\x0a\xd8\x7c\xce\x71"
  1112. "\xf0\x91\xe7\x66\xca\x5c\xc2\x75\xcb\x49\x14\x5a\x5e\xe6\x16\x2e"
  1113. "\xcc\xf5\x58\xce\xc4\xd3\xee\x53\x1e\x91\xe9\xa5\x29\x69\x63\x4d"
  1114. "\x3a\xf8\xd2\x6f\x8d\x15\xdc\x0d\x6f\x6e\x0a\x97\x4b\xe4\x34\x1b"
  1115. "\x68\xa0\x19\x90\xdb\xb8\x64\x95\x89\x1a\xd3\xaf\xc1\xe4\xce\xdf"
  1116. "\x4c\x6a\xe1\xf1\xcd\x60\x81\xcd\xee\xd8\xe6\xb3\x26\x4e\xc3\xbe"
  1117. "\x24\x58\xd1\xc0\xca\x24\x43\x41\x0c\xf3\xb4\x7c\x0c\x25\x4c\x7d"
  1118. "\xc8\xec\xb4\x3e\x6c\x23\x64\xe1\xc0\x62\x19\xcc\x7e\xfb\xff\xbb"
  1119. "\x63\xd7\xff\xfc\x74\x58\x12\xfd\x24\x0c\x33\xd4\x96\xb9\x99\x2f"
  1120. "\x96\x80\xa6\x3c\x07\x96\x3c\x0c\x49\xf3\xc1\xba\xef\xec\xaf\x32"
  1121. "\xe2\xaa\x8a\x2f\x7c\xd3\x0d\x8f\x05\x1e\xe2\xf5\x0f\xbf\x05\xab"
  1122. "\x13\x96\xa4\xea\x87\x44\x7d\x7b\x98\x1b\x5e\x46\x14\x28\x18\x71"
  1123. "\xa6\xf0\xf6\xbf\x1f\xe0\x02\x2f\x7e\xa1\x32\xbe\x0a\xe9\x19\x26"
  1124. "\xab\x12\xaf\x6d\xc4\x50\x64\xaa\xd5\x6b\x84\xb9\x0c\x70\x08\x37"
  1125. "\x09\xcf\xf7\xe3\x1b\x54\x8f\xb7\xfb\x2c\xf7\x5a\xbf\x96\xe0\x1c"
  1126. "\xcd\x3e\x94\x2e\xed\x91\x48\x0d\x4c\x24\xc6\xb7\xf9\x79\xfb\xbe"
  1127. "\x5d\xa2\x39\xb3\x76\x16\x7d\x68\x57\x35\x24\xff\xcb\x50\x99\x54"
  1128. "\xcc\x80\xa0\xe1\xa7\x1c\x40\xc4\xda\x17\xb8\xd1\x57\x2b\x21\x58"
  1129. "\x7a\x8d\x66\xcc\x62\x1c\x7c\xd1\x0f\x49\xab\xd5\xef\x86\x31\x13"
  1130. "\xe6\x19\x21\x08\x6f\xac\x25\x31\x2b\x74\x1c\x11\xa8\xfb\xc1\xe3"
  1131. "\x3c\x34\xd9\xda\x14\xa8\x22\x47\x7f\xcc\x36\x66\x70\x25\xc4\xf1"
  1132. "\x30\xae\x10\x0e\x36\xf1\x5d\xa0\x03\x74\xce\x87\x41\x67\x9f\x61",
  1133. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1134. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1135. "\x4b\x99\x6a\x60\xc0\x4a\x35\xc5\xe6\xd4\x74\xb1\x0a\x25\x8d\x56"
  1136. "\x2e\xa6\xdc\x52\xf6\xc6\x9b\xf3\x9e\xf8\x8c\x89\xe3\xcc\x8a\x54"
  1137. "\xda\x2f\x3c\x0b\x56\x1b\x53\xfe\x76\x55\x13\x63\xd6\x9c\x3c\xef"
  1138. "\x74\xe3\x4f\xe8\x8e\xb3\xac\x51",
  1139. WC_HASH_TYPE_SHA224),
  1140. INIT_SP80056C_TEST_VECTOR(
  1141. "\x52\x27\x2f\x50\xf4\x6f\x4e\xdc\x91\x51\x56\x90\x92\xf4\x6d\xf2"
  1142. "\xd9\x6e\xcc\x3b\x6d\xc1\x71\x4a\x4e\xa9\x49\xfa\x9f\x18\xff\x54"
  1143. "\xf8\x87\x23\x07\x3f\x64\xa6\x95\x3d\x04\x91\x4f\x45\xa2\x3e\xee"
  1144. "\x7c\xfc\x46\x67\x08\x0a\xa0\xf9",
  1145. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1146. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1147. "\x77\x56\xbc\xfd\xef\x3e\xe6\x9f\x6a\xc2\x3c\xd2\xdc\x60\x7d\x01"
  1148. "\xfa\x8c\xe1\xb2\x4f\x5c\xaa\xaa\x48\xe0\x4b\x81\x63\xe1\x73\x3a"
  1149. "\xed\x7a\x04\x0e\x73\xf2\xb5\x42\x36\x8f\x00\x54\x8b\x16\x3c\x3d"
  1150. "\xc9\x6d\x70\x09\x99\x16\xf1\x6b",
  1151. WC_HASH_TYPE_SHA224),
  1152. #endif
  1153. #if !defined(NO_SHA256)
  1154. /* SHA-256 */
  1155. INIT_SP80056C_TEST_VECTOR(
  1156. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1157. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1158. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1159. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  1160. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1161. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1162. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1163. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1164. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1165. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc\xa6",
  1166. WC_HASH_TYPE_SHA256),
  1167. INIT_SP80056C_TEST_VECTOR(
  1168. "\x44\xf4\x84\x09\xf3\x1b\xf3\x50\x94\x51\xdb\x4d\x30\x4b\xeb\xd8"
  1169. "\x3c\x2a\xd6\x50\x1c\x1b\x85\xe6\x32\xbc\x92\x58\x8e\x2d\x48\xb5"
  1170. "\xd2\xb8\x44\x44\x62\xad\x94\xe8\xa4\x44\x94\x1e\xd4\x97\x5c\x97"
  1171. "\x91\x17\xd7\x5a\x0a\x2b\xa8\x10\xdf\xa8\x80\x4a\x0f\xe9\x42\x6d"
  1172. "\xd7\xeb\x95\xf2\x9c\xa4\x30\xda\x37\xef\xa5\x2c\x42\xda\x1d\xe2"
  1173. "\x23\x76\x3b\xdd\xc9\x5e\x46\x6a\xa3\xb8\xd2\x06\xb8\x21\x8e\xdf"
  1174. "\x23\x97\x3d\x05\xf3\xc7\xc2\x2b\x22\x46\x53\xd4\xf9\x21\x85\x45"
  1175. "\x79\x83\x26\x2f\x27\xbc\x55\xa0\xa7\xae\xe5\x43\x54\x55\xd4\x3c"
  1176. "\x0e\x0c\x6d\x80\x67\xad\xaf\x90\x42\xb6\xb7\x77\x7e\x19\x8d\x67"
  1177. "\x60\x83\x0d\x96\xb2\x9a\x6a\xae\xf5\x74\xd7\x5e\x2d\x65\x43\x55"
  1178. "\x0f\x75\x55\xcf\x89\x82\xc8\x21\xc4\xec\x9b\x82\x66\x2b\x09\x36"
  1179. "\x69\xfd\x24\x6d\x4d\xcc\xbf\xf3\x1d\x98\x4e\xf6\x3c\x4f\x95\xd7"
  1180. "\x39\xc7\x7e\x66\xf6\x9b\x6d\xb0\xd9\xfc\x1a\x97\x3f\x52\x33\xd1"
  1181. "\x1f\xe7\x15\x4b\x8a\x6b\xe1\x50\x46\x7d\x92\xda\xf0\x91\x44\x34"
  1182. "\xf0\xcf\x17\x6e\x96\x1b\x31\x3f\xe3\xe2\x3b\xfe\x37\x8b\x87\xba"
  1183. "\xf2\x73\x93\x7f\xfa\xa6\x85\x65\x8b\x09\x78\x1d\x26\x97\x86\x4b"
  1184. "\x0d\x82\x48\x5c\xf7\xd6\x2f\xfc\xea\x34\x33\x88\xcf\xec\x15\x27"
  1185. "\x3a\x39\x4b\x84\x32\xee\xb6\x32\x1b\xe3\x1d\x4f\xcd\x16\x15\xc8"
  1186. "\x1c\x69\x37\xc0\x8d\x92\x41\x6e\xdb\xdd\x20\x10\xfa\x8b\x6e\x0a"
  1187. "\x8a\x60\x3d\xad\xe0\x10\xbc\x9c\xd7\x6b\x14\xe3\xe2\x19\x0e\x3b"
  1188. "\xa3\x00\xe7\x1a\xdd\xbf\x24\x4c\xf8\x06\x29\x49\x76\xea\xf0\x7d"
  1189. "\x02\x3b\xdb\x57\xfc\x5d\x19\x64\xc7\xd4\x20\x6e\x72\x06\x1b\xfe"
  1190. "\x1e\xe4\xee\xbc\x92\x00\xe1\x3a\x6c\xba\x32\x86\x9d\xbe\x80\x82"
  1191. "\xcd\xf3\x64\x5b\x5a\x72\x7d\xd2\x7c\xa5\x03\xf4\xed\xeb\x73\xe8"
  1192. "\x8a\x3a\x55\x2c\x7e\x00\xd4\xee\x72\x42\x13\x72\x36\xa0\x96\x5c"
  1193. "\x1e\xc3\xeb\xc0\xb4\x8c\x2b\x46\x7e\xb8\x42\x41\x5a\x28\x3f\x55"
  1194. "\xe2\x20\xff\xd1\x88\x19\x25\x6d\xa2\x47\x4d\x28\xfc\x3b\x04\xe0"
  1195. "\xc0\x7e\x4d\x25\xc1\x74\x93\x41\xd2\x22\x97\x01\x5c\xd8\x17\x8c"
  1196. "\x39\x18\xbe\x8c\x5c\xdf\x0f\xbf\xbb\x9a\x5a\xcc\xdd\x82\xaf\x07"
  1197. "\x83\xef\xe4\xdf\x64\xa8\xd8\x92\x82\x8f\x8d\xe5\x8c\x5d\x56\x9b"
  1198. "\x5b\x08\x45\x58\x96\xc4\xd3\xc3\x4f\xd3\xce\x93\xc4\x34\xc3\x8e"
  1199. "\xf5\x6c\xed\x30\x56\x1c\x37\x1a\xf9\xf2\xd8\x64\xfd\xc5\xb6\x2f",
  1200. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1201. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1202. "\x42\x35\xac\x89\xc9\xf3\x3e\x5d\xbb\x11\x60\x1a\x29\x83\xe3\x76"
  1203. "\xe2\x15\x39\x97\x87\xd8\x39\xa0\x38\x55\xfe\x04\x53\x3e\x1a\x67"
  1204. "\x66\x91\x5e\x67\xc2\x5e\xeb\x04\x08\x28\xe9\x6c\xd3\xd6\xef\x0a"
  1205. "\xb7\xd1\x7b\x43\x13\x43\xa7\xf3\xaa\xc6\x8f\x0c\x4a\x7e\x77\x9b",
  1206. WC_HASH_TYPE_SHA256),
  1207. /* slightly modified vector to test generation when derivedKeySz %
  1208. * hashOutSz != 0*/
  1209. INIT_SP80056C_TEST_VECTOR(
  1210. "\xdd\x0f\x53\x96\x21\x9d\x1e\xa3\x93\x31\x04\x12\xd1\x9a\x08\xf1"
  1211. "\xf5\x81\x1e\x9d\xc8\xec\x8e\xea\x7f\x80\xd2\x1c\x82\x0c\x27\x88"
  1212. "\x22\x76\x84\xe7\x1f\x5c\x31\x3f\xad\xc9\x1e\x52\x98\x07\xe3\x14"
  1213. "\x7d\x53\x14\x5b\x15\xab\xd6\xed\x41\x6a\xd3\x5c\xd7\xe6\x83\x8f",
  1214. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1215. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1216. "\xc0\x8b\x3d\xe2\x4f\x1a\x38\x1e\x7a\x56\x75\xa2\xa6\x52\x3b\x08"
  1217. "\xf3\x54\x60\x5e\xee\x46\xb9\xf3\x9e\xad\xb1\xe9\x75\x34\x41\x6d"
  1218. "\x98\xb4\x3c\xae\x8a\xb0\x4a\xfd\x53\xde\xb3\x7f\x44\x02\x23\x52"
  1219. "\xc3\xfb\xde\x1e\x2f\x2c\xec\x53\x1c\xfc\x32\x4f\xdd\x0f\xcc",
  1220. WC_HASH_TYPE_SHA256),
  1221. #endif
  1222. #if defined(WOLFSSL_SHA384)
  1223. /* SHA-384 */
  1224. INIT_SP80056C_TEST_VECTOR(
  1225. "\x5e\xa1\xfc\x4a\xf7\x25\x6d\x20\x55\x98\x1b\x11\x05\x75\xe0\xa8"
  1226. "\xca\xe5\x31\x60\x13\x7d\x90\x4c\x59\xd9\x26\xeb\x1b\x84\x56\xe4"
  1227. "\x27\xaa\x8a\x45\x40\x88\x4c\x37\xde\x15\x9a\x58\x02\x8a\xbc\x0e"
  1228. "\x88\x76\x9c\xb7\x2f\xc5\xac\x45\x7c\xd5\x8e\x89\x08\x9b\x19\x6a"
  1229. "\x70\xbf\x53\x3c\x6d\xc9\x1c\x9c\x7e\x17\x41\xdb\x5e\x7a\xb6\xb0"
  1230. "\x84\x9f\x01\xde\xa6\x5f\xed\xd0\x6c\x77\x18\x7c\xd8\x8e\xd0\x30",
  1231. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1232. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1233. "\x8e\x6e\x26\x5f\x20\x82\xf1\x4d\x34\xda\x23\xe1\x03\x2c\x90\x24"
  1234. "\x83\x4a\xf0\x15\x72\xb6\x64\x77\x82\x41\x1b\xdd\xcb\x84\xa5\xda"
  1235. "\xee\x11\x7b\xa6\xfb\xa6\xd0\xeb\x28\x08\xef\x8a\xb0\x70\x05\xee"
  1236. "\xab\xe5\x2d\x2e\xfd\x31\x12\x1c\x7b\xf9\xd5\xfa\xfc\x40\xe0\x0c"
  1237. "\x6d\x6d\xbf\x39\xef\x43\xfe\x97\x15\xc7\x20\x2c\xdc\x2d\xb7\xe8"
  1238. "\x2b\x88\xd7\x48\xeb\x84\x25\x8b\xf8\x4d\x85\x82\xf2\xbf\xd9\x40",
  1239. WC_HASH_TYPE_SHA384),
  1240. #endif
  1241. #if defined(WOLFSSL_SHA512)
  1242. /* SHA-512 */
  1243. INIT_SP80056C_TEST_VECTOR(
  1244. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1245. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1246. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1247. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1248. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1249. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1250. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1251. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1252. "\xde\x34\x54\xe4",
  1253. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1254. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1255. "\x2d\x4a\x46\xa1\x70\x99\xba\xa8\x33\x0b\xc5\x9d\x4a\x1c\xf5\xae"
  1256. "\x3a\x30\x75\xb4\xc6\x2b\xb2\x6e\x7f\xc9\x89\x24\x72\x6d\x27\x4c"
  1257. "\x09\x64\x6f\x44\x08\xe6\x85\x8c\x43\xb4\x2d\xae\xd0\x15\xef\x26"
  1258. "\x17\x08\xd5\x5e\xf2\x4d\xaa\x7d\x3e\xa3\xd1\xc4\xa0\x8c\xfd\x24"
  1259. "\xdb\x60\x00\xa5\xb8\xa6\x7d\xe7\x46\xf3\xd3\xf4\xff\x34\x85\x15"
  1260. "\x8f\xd3\xb6\x91\x55\x79\x1d\xf4\x67\x47\xd4\xdb\xbe\x17\xc4\xb5"
  1261. "\x58\x46\x2e\x26\xbe\x5e\xd3\x5f\xe6\x80\xe2\x97\x14\x22\xc3\xb0"
  1262. "\x1b\x17\xe1\x67\xfc\x43\x7f\x84\x86\x9d\x85\x49\x53\x7b\x33\x38",
  1263. WC_HASH_TYPE_SHA512),
  1264. #endif
  1265. INIT_SP80056C_TEST_VECTOR(
  1266. "\x00\xcd\xea\x89\x62\x1c\xfa\x46\xb1\x32\xf9\xe4\xcf\xe2\x26\x1c"
  1267. "\xde\x2d\x43\x68\xeb\x56\x56\x63\x4c\x7c\xc9\x8c\x7a\x00\xcd\xe5"
  1268. "\x4e\xd1\x86\x6a\x0d\xd3\xe6\x12\x6c\x9d\x2f\x84\x5d\xaf\xf8\x2c"
  1269. "\xeb\x1d\xa0\x8f\x5d\x87\x52\x1b\xb0\xeb\xec\xa7\x79\x11\x16\x9c"
  1270. "\x20\xcc\x01\x38\xa6\x72\xb6\x95\x8b\xd7\x84\xe5\xd7\xfa\x83\x73"
  1271. "\x8a\xc6\x8f\x9b\x34\x23\xb4\x83\xf9\xbf\x53\x9e\x71\x14\x1e\x45"
  1272. "\xdb\xfb\x7a\xfe\xd1\x8b\x11\xc0\x02\x8b\x13\xf1\xf8\x60\xef\x43"
  1273. "\xc4\x80\xf4\xda\xcd\xa2\x08\x10\x59\xd3\x97\x8c\x99\x9d\x5d\x1a"
  1274. "\xde\x34\x54\xe4",
  1275. "\x12\x34\x56\x78\x9a\xbc\xde\xf0\x41\x4c\x49\x43\x45\x31\x32\x33"
  1276. "\x42\x4f\x42\x42\x59\x34\x35\x36",
  1277. "\x2d\x4a",
  1278. WC_HASH_TYPE_SHA512),
  1279. };
  1280. for (i = 0; i < sizeof(vctors) / sizeof(vctors[0]); i++) {
  1281. v = &vctors[i];
  1282. ret = wc_KDA_KDF_onestep(v->z, v->zSz, v->fixedInfo, v->fixedInfoSz,
  1283. v->derivedKeySz, v->hashType, output,
  1284. /* use derivedKeySz to force the function to use a temporary buff
  1285. for the last block */
  1286. v->derivedKeySz);
  1287. if (ret != 0)
  1288. return WC_TEST_RET_ENC_EC(ret);
  1289. if (XMEMCMP(output, v->derivedKey, v->derivedKeySz) != 0)
  1290. return WC_TEST_RET_ENC_NC;
  1291. }
  1292. /* negative tests */
  1293. ret = wc_KDA_KDF_onestep(NULL, 0, (byte*)"fixed_info",
  1294. sizeof("fixed_info"), 16, WC_HASH_TYPE_SHA256, output, 16);
  1295. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1296. return WC_TEST_RET_ENC_NC;
  1297. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 1, 16,
  1298. WC_HASH_TYPE_SHA256, output, 16);
  1299. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  1300. return WC_TEST_RET_ENC_NC;
  1301. /* allow empty FixedInfo */
  1302. ret = wc_KDA_KDF_onestep((byte*)"secret", sizeof("secret"), NULL, 0, 16,
  1303. WC_HASH_TYPE_SHA256, output, 16);
  1304. if (ret != 0)
  1305. return WC_TEST_RET_ENC_EC(ret);
  1306. return 0;
  1307. }
  1308. #endif /* WC_KDF_NIST_SP_800_56C */
  1309. /* optional macro to add sleep between tests */
  1310. #ifndef TEST_SLEEP
  1311. #define TEST_SLEEP() WC_DO_NOTHING
  1312. #else
  1313. #define TEST_PASS test_pass
  1314. #include <stdarg.h> /* for var args */
  1315. static WC_INLINE void test_pass(const char* fmt, ...)
  1316. {
  1317. va_list args;
  1318. va_start(args, fmt);
  1319. STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK(max_relative_stack, vprintf(fmt, args));
  1320. va_end(args);
  1321. PRINT_HEAP_CHECKPOINT();
  1322. TEST_SLEEP();
  1323. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1););
  1324. }
  1325. #endif
  1326. /* set test pass output to printf if not overridden */
  1327. #ifndef TEST_PASS
  1328. /* redirect to printf */
  1329. #define TEST_PASS(...) { \
  1330. if (STACK_SIZE_CHECKPOINT_WITH_MAX_CHECK \
  1331. (max_relative_stack, printf(__VA_ARGS__)) < 0) { \
  1332. return err_sys("post-test check failed", WC_TEST_RET_ENC_NC);\
  1333. } \
  1334. PRINT_HEAP_CHECKPOINT(); \
  1335. ASSERT_RESTORED_VECTOR_REGISTERS(exit(1);); \
  1336. }
  1337. #endif
  1338. #ifdef TEST_ALWAYS_RUN_TO_END
  1339. #define TEST_FAIL(msg, retval) do { last_failed_test_ret = (retval); render_error_message(msg, retval); } while (0)
  1340. #elif !defined(TEST_FAIL)
  1341. #define TEST_FAIL(msg, retval) return err_sys(msg, retval)
  1342. #endif
  1343. #ifdef HAVE_STACK_SIZE
  1344. THREAD_RETURN WOLFSSL_THREAD wolfcrypt_test(void* args)
  1345. #else
  1346. wc_test_ret_t wolfcrypt_test(void* args)
  1347. #endif
  1348. {
  1349. wc_test_ret_t ret;
  1350. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1351. long heap_baselineAllocs, heap_baselineBytes;
  1352. #endif
  1353. #ifdef TEST_ALWAYS_RUN_TO_END
  1354. int last_failed_test_ret = 0;
  1355. #endif
  1356. STACK_SIZE_INIT();
  1357. #if defined(WOLFSSL_TRACK_MEMORY_VERBOSE) && !defined(WOLFSSL_STATIC_MEMORY)
  1358. (void)wolfCrypt_heap_peakAllocs_checkpoint();
  1359. heap_baselineAllocs = wolfCrypt_heap_peakAllocs_checkpoint();
  1360. (void)wolfCrypt_heap_peakBytes_checkpoint();
  1361. heap_baselineBytes = wolfCrypt_heap_peakBytes_checkpoint();
  1362. #endif
  1363. #ifdef WC_RNG_SEED_CB
  1364. wc_SetSeed_Cb(wc_GenerateSeed);
  1365. #endif
  1366. printf("------------------------------------------------------------------------------\n");
  1367. printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING);
  1368. #ifdef WOLF_CRYPTO_CB
  1369. if (devId != INVALID_DEVID)
  1370. printf(" CryptoCB with DevID:%X\n", devId);
  1371. #endif
  1372. printf("------------------------------------------------------------------------------\n");
  1373. if (args) {
  1374. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1375. int ch;
  1376. #endif
  1377. ((func_args*)args)->return_code = -1; /* error state */
  1378. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  1379. while ((ch = mygetopt(((func_args*)args)->argc, ((func_args*)args)->argv, "s:m:a:h")) != -1) {
  1380. switch(ch) {
  1381. case 's':
  1382. #ifdef HAVE_STACK_SIZE_VERBOSE
  1383. max_relative_stack = (ssize_t)atoi(myoptarg);
  1384. break;
  1385. #else
  1386. return err_sys("-s (max relative stack bytes) requires HAVE_STACK_SIZE_VERBOSE (--enable-stacksize=verbose).", WC_TEST_RET_ENC_NC);
  1387. #endif
  1388. case 'm':
  1389. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1390. max_relative_heap_bytes = (ssize_t)atoi(myoptarg);
  1391. break;
  1392. #else
  1393. return err_sys("-m (max relative heap memory bytes) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1394. #endif
  1395. case 'a':
  1396. #ifdef WOLFSSL_TRACK_MEMORY_VERBOSE
  1397. max_relative_heap_allocs = (ssize_t)atoi(myoptarg);
  1398. break;
  1399. #else
  1400. return err_sys("-a (max relative heap allocs) requires WOLFSSL_TRACK_MEMORY_VERBOSE (--enable-trackmemory=verbose).", WC_TEST_RET_ENC_NC);
  1401. #endif
  1402. case 'h':
  1403. return err_sys("\
  1404. options: [-s max_relative_stack_bytes] [-m max_relative_heap_memory_bytes]\n\
  1405. [-a max_relative_heap_allocs] [-h]\n", 0);
  1406. default:
  1407. return err_sys("unknown test option. try -h.", WC_TEST_RET_ENC_NC);
  1408. }
  1409. }
  1410. #endif
  1411. }
  1412. #ifdef WOLFSSL_STATIC_MEMORY
  1413. if (wc_LoadStaticMemory(&HEAP_HINT, gTestMemory, sizeof(gTestMemory),
  1414. WOLFMEM_GENERAL, 1) != 0) {
  1415. printf("unable to load static memory.\n");
  1416. return(EXIT_FAILURE);
  1417. }
  1418. #ifndef OPENSSL_EXTRA
  1419. wolfSSL_SetGlobalHeapHint(HEAP_HINT);
  1420. #endif
  1421. #endif
  1422. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  1423. wolfSSL_Debugging_ON();
  1424. #endif
  1425. #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
  1426. wc_SetLoggingHeap(HEAP_HINT);
  1427. #endif
  1428. #if defined(HAVE_FIPS) && !defined(WOLFSSL_LINUXKM)
  1429. wolfCrypt_SetCb_fips(myFipsCb);
  1430. #if FIPS_VERSION3_GE(6,0,0)
  1431. printf("FIPS module version in use: %s\n",
  1432. wolfCrypt_GetVersion_fips());
  1433. #endif
  1434. #endif
  1435. #if !defined(NO_BIG_INT)
  1436. if (CheckCtcSettings() != 1) {
  1437. printf("Sizeof mismatch (build) %x != (run) %lx\n",
  1438. CTC_SETTINGS, (unsigned long)CheckRunTimeSettings());
  1439. return err_sys("Build vs runtime math mismatch\n", WC_TEST_RET_ENC_NC);
  1440. }
  1441. #if defined(USE_FAST_MATH) && \
  1442. (!defined(NO_RSA) || !defined(NO_DH) || defined(HAVE_ECC))
  1443. if (CheckFastMathSettings() != 1)
  1444. return err_sys("Build vs runtime fastmath FP_MAX_BITS mismatch\n",
  1445. WC_TEST_RET_ENC_NC);
  1446. #endif /* USE_FAST_MATH */
  1447. #endif /* !NO_BIG_INT */
  1448. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  1449. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  1450. initDefaultName();
  1451. #endif
  1452. #ifdef WOLFSSL_ASYNC_CRYPT
  1453. ret = wolfAsync_DevOpen(&devId);
  1454. if (ret < 0) {
  1455. printf("Async device open failed\nRunning without async\n");
  1456. }
  1457. #else
  1458. (void)devId;
  1459. #endif /* WOLFSSL_ASYNC_CRYPT */
  1460. #ifdef WOLF_CRYPTO_CB
  1461. #ifdef HAVE_INTEL_QA_SYNC
  1462. devId = wc_CryptoCb_InitIntelQa();
  1463. if (INVALID_DEVID == devId) {
  1464. printf("Couldn't init the Intel QA\n");
  1465. }
  1466. #endif
  1467. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  1468. devId = wc_CryptoCb_InitOcteon();
  1469. if (INVALID_DEVID == devId) {
  1470. printf("Couldn't init the Cavium Octeon\n");
  1471. }
  1472. #endif
  1473. #ifdef HAVE_RENESAS_SYNC
  1474. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  1475. if (devId == INVALID_DEVID) {
  1476. printf("Couldn't get the Renesas device ID\n");
  1477. }
  1478. #endif
  1479. #endif
  1480. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  1481. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  1482. if (devId == INVALID_DEVID) {
  1483. /* for testing RNG with crypto callback register function */
  1484. devId = 100; /* any value beside -2 (INVALID_DEVID) */
  1485. wc_CryptoCb_RegisterDevice(devId, rng_crypto_cb, NULL);
  1486. }
  1487. #endif
  1488. #ifdef HAVE_SELFTEST
  1489. if ( (ret = wolfCrypt_SelfTest()) != 0)
  1490. TEST_FAIL("CAVP selftest failed!\n", ret);
  1491. else
  1492. TEST_PASS("CAVP selftest passed!\n");
  1493. #endif
  1494. if ( (ret = error_test()) != 0)
  1495. TEST_FAIL("error test failed!\n", ret);
  1496. else
  1497. TEST_PASS("error test passed!\n");
  1498. if ( (ret = memory_test()) != 0)
  1499. TEST_FAIL("MEMORY test failed!\n", ret);
  1500. else
  1501. TEST_PASS("MEMORY test passed!\n");
  1502. #ifndef NO_CODING
  1503. if ( (ret = base64_test()) != 0)
  1504. TEST_FAIL("base64 test failed!\n", ret);
  1505. else
  1506. TEST_PASS("base64 test passed!\n");
  1507. #ifdef WOLFSSL_BASE16
  1508. if ( (ret = base16_test()) != 0)
  1509. TEST_FAIL("base16 test failed!\n", ret);
  1510. else
  1511. TEST_PASS("base16 test passed!\n");
  1512. #endif
  1513. #endif /* !NO_CODING */
  1514. #ifndef NO_ASN
  1515. if ( (ret = asn_test()) != 0)
  1516. TEST_FAIL("asn test failed!\n", ret);
  1517. else
  1518. TEST_PASS("asn test passed!\n");
  1519. #endif
  1520. #ifndef WC_NO_RNG
  1521. if ( (ret = random_test()) != 0)
  1522. TEST_FAIL("RANDOM test failed!\n", ret);
  1523. else
  1524. TEST_PASS("RANDOM test passed!\n");
  1525. #endif /* WC_NO_RNG */
  1526. #ifndef NO_MD5
  1527. if ( (ret = md5_test()) != 0)
  1528. TEST_FAIL("MD5 test failed!\n", ret);
  1529. else
  1530. TEST_PASS("MD5 test passed!\n");
  1531. #endif
  1532. #ifdef WOLFSSL_MD2
  1533. if ( (ret = md2_test()) != 0)
  1534. TEST_FAIL("MD2 test failed!\n", ret);
  1535. else
  1536. TEST_PASS("MD2 test passed!\n");
  1537. #endif
  1538. #ifndef NO_MD4
  1539. if ( (ret = md4_test()) != 0)
  1540. TEST_FAIL("MD4 test failed!\n", ret);
  1541. else
  1542. TEST_PASS("MD4 test passed!\n");
  1543. #endif
  1544. #ifndef NO_SHA
  1545. if ( (ret = sha_test()) != 0)
  1546. TEST_FAIL("SHA test failed!\n", ret);
  1547. else
  1548. TEST_PASS("SHA test passed!\n");
  1549. #endif
  1550. #ifdef WOLFSSL_SHA224
  1551. if ( (ret = sha224_test()) != 0)
  1552. TEST_FAIL("SHA-224 test failed!\n", ret);
  1553. else
  1554. TEST_PASS("SHA-224 test passed!\n");
  1555. #endif
  1556. #ifndef NO_SHA256
  1557. if ( (ret = sha256_test()) != 0)
  1558. TEST_FAIL("SHA-256 test failed!\n", ret);
  1559. else
  1560. TEST_PASS("SHA-256 test passed!\n");
  1561. #endif
  1562. #ifdef WOLFSSL_SHA384
  1563. if ( (ret = sha384_test()) != 0)
  1564. TEST_FAIL("SHA-384 test failed!\n", ret);
  1565. else
  1566. TEST_PASS("SHA-384 test passed!\n");
  1567. #endif
  1568. #ifdef WOLFSSL_SHA512
  1569. if ((ret = sha512_test()) != 0) {
  1570. TEST_FAIL("SHA-512 test failed!\n", ret);
  1571. }
  1572. else {
  1573. TEST_PASS("SHA-512 test passed!\n");
  1574. }
  1575. #if !defined(WOLFSSL_NOSHA512_224) && \
  1576. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1577. if ((ret = sha512_224_test()) != 0) {
  1578. TEST_FAIL("SHA-512/224 test failed!\n", ret);
  1579. }
  1580. else
  1581. TEST_PASS("SHA-512/224 test passed!\n");
  1582. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  1583. #if !defined(WOLFSSL_NOSHA512_256) && \
  1584. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1585. if ((ret = sha512_256_test()) != 0) {
  1586. TEST_FAIL("SHA-512/256 test failed!\n", ret);
  1587. }
  1588. else
  1589. TEST_PASS("SHA-512/256 test passed!\n");
  1590. #endif /* !defined(WOLFSSL_NOSHA512_256) & !FIPS ... */
  1591. #endif /* WOLFSSL_SHA512 */
  1592. #ifdef WOLFSSL_SHA3
  1593. if ( (ret = sha3_test()) != 0)
  1594. TEST_FAIL("SHA-3 test failed!\n", ret);
  1595. else
  1596. TEST_PASS("SHA-3 test passed!\n");
  1597. #endif
  1598. #ifdef WOLFSSL_SHAKE128
  1599. if ( (ret = shake128_test()) != 0)
  1600. TEST_FAIL("SHAKE128 test failed!\n", ret);
  1601. else
  1602. TEST_PASS("SHAKE128 test passed!\n");
  1603. #endif
  1604. #ifdef WOLFSSL_SHAKE256
  1605. if ( (ret = shake256_test()) != 0)
  1606. TEST_FAIL("SHAKE256 test failed!\n", ret);
  1607. else
  1608. TEST_PASS("SHAKE256 test passed!\n");
  1609. #endif
  1610. #ifdef WOLFSSL_SM3
  1611. if ( (ret = sm3_test()) != 0)
  1612. return err_sys("SM-3 test failed!\n", ret);
  1613. else
  1614. TEST_PASS("SM-3 test passed!\n");
  1615. #endif
  1616. #ifndef NO_HASH_WRAPPER
  1617. if ( (ret = hash_test()) != 0)
  1618. TEST_FAIL("Hash test failed!\n", ret);
  1619. else
  1620. TEST_PASS("Hash test passed!\n");
  1621. #endif
  1622. #ifdef WOLFSSL_RIPEMD
  1623. if ( (ret = ripemd_test()) != 0)
  1624. TEST_FAIL("RIPEMD test failed!\n", ret);
  1625. else
  1626. TEST_PASS("RIPEMD test passed!\n");
  1627. #endif
  1628. #ifdef HAVE_BLAKE2
  1629. if ( (ret = blake2b_test()) != 0)
  1630. TEST_FAIL("BLAKE2b test failed!\n", ret);
  1631. else
  1632. TEST_PASS("BLAKE2b test passed!\n");
  1633. #endif
  1634. #ifdef HAVE_BLAKE2S
  1635. if ( (ret = blake2s_test()) != 0)
  1636. TEST_FAIL("BLAKE2s test failed!\n", ret);
  1637. else
  1638. TEST_PASS("BLAKE2s test passed!\n");
  1639. #endif
  1640. #ifndef NO_HMAC
  1641. #if !defined(NO_MD5) && !(defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) \
  1642. && (HAVE_FIPS_VERSION >= 5))
  1643. if ( (ret = hmac_md5_test()) != 0)
  1644. TEST_FAIL("HMAC-MD5 test failed!\n", ret);
  1645. else
  1646. TEST_PASS("HMAC-MD5 test passed!\n");
  1647. #endif
  1648. #ifndef NO_SHA
  1649. if ( (ret = hmac_sha_test()) != 0)
  1650. TEST_FAIL("HMAC-SHA test failed!\n", ret);
  1651. else
  1652. TEST_PASS("HMAC-SHA test passed!\n");
  1653. #endif
  1654. #ifdef WOLFSSL_SHA224
  1655. if ( (ret = hmac_sha224_test()) != 0)
  1656. TEST_FAIL("HMAC-SHA224 test failed!\n", ret);
  1657. else
  1658. TEST_PASS("HMAC-SHA224 test passed!\n");
  1659. #endif
  1660. #ifndef NO_SHA256
  1661. if ( (ret = hmac_sha256_test()) != 0)
  1662. TEST_FAIL("HMAC-SHA256 test failed!\n", ret);
  1663. else
  1664. TEST_PASS("HMAC-SHA256 test passed!\n");
  1665. #endif
  1666. #ifdef WOLFSSL_SHA384
  1667. if ( (ret = hmac_sha384_test()) != 0)
  1668. TEST_FAIL("HMAC-SHA384 test failed!\n", ret);
  1669. else
  1670. TEST_PASS("HMAC-SHA384 test passed!\n");
  1671. #endif
  1672. #ifdef WOLFSSL_SHA512
  1673. if ( (ret = hmac_sha512_test()) != 0)
  1674. TEST_FAIL("HMAC-SHA512 test failed!\n", ret);
  1675. else
  1676. TEST_PASS("HMAC-SHA512 test passed!\n");
  1677. #endif
  1678. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  1679. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  1680. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  1681. if ( (ret = hmac_sha3_test()) != 0)
  1682. TEST_FAIL("HMAC-SHA3 test failed!\n", ret);
  1683. else
  1684. TEST_PASS("HMAC-SHA3 test passed!\n");
  1685. #endif
  1686. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  1687. PRIVATE_KEY_UNLOCK();
  1688. if ( (ret = hkdf_test()) != 0)
  1689. TEST_FAIL("HMAC-KDF test failed!\n", ret);
  1690. else
  1691. TEST_PASS("HMAC-KDF test passed!\n");
  1692. PRIVATE_KEY_LOCK();
  1693. #endif
  1694. #endif /* !NO_HMAC */
  1695. #ifdef WOLFSSL_WOLFSSH
  1696. PRIVATE_KEY_UNLOCK();
  1697. if ( (ret = sshkdf_test()) != 0)
  1698. TEST_FAIL("SSH-KDF test failed!\n", ret);
  1699. else
  1700. TEST_PASS("SSH-KDF test passed!\n");
  1701. PRIVATE_KEY_LOCK();
  1702. #endif /* WOLFSSL_WOLFSSH */
  1703. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  1704. PRIVATE_KEY_UNLOCK();
  1705. if ( (ret = prf_test()) != 0)
  1706. TEST_FAIL("PRF test failed!\n", ret);
  1707. else
  1708. TEST_PASS("PRF test passed!\n");
  1709. PRIVATE_KEY_LOCK();
  1710. #endif
  1711. #ifdef WOLFSSL_HAVE_PRF
  1712. #if defined (HAVE_HKDF) && !defined(NO_HMAC)
  1713. #ifdef WOLFSSL_BASE16
  1714. PRIVATE_KEY_UNLOCK();
  1715. if ( (ret = tls12_kdf_test()) != 0)
  1716. TEST_FAIL("TLSv1.2 KDF test failed!\n", ret);
  1717. else
  1718. TEST_PASS("TLSv1.2 KDF test passed!\n");
  1719. PRIVATE_KEY_LOCK();
  1720. #endif /* WOLFSSL_BASE16 */
  1721. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  1722. #endif /* WOLFSSL_HAVE_PRF */
  1723. #ifdef WOLFSSL_TLS13
  1724. PRIVATE_KEY_UNLOCK();
  1725. if ( (ret = tls13_kdf_test()) != 0)
  1726. TEST_FAIL("TLSv1.3 KDF test failed!\n", ret);
  1727. else
  1728. TEST_PASS("TLSv1.3 KDF test passed!\n");
  1729. PRIVATE_KEY_LOCK();
  1730. #endif /* WOLFSSL_TLS13 */
  1731. #if defined(HAVE_X963_KDF) && defined(HAVE_ECC)
  1732. if ( (ret = x963kdf_test()) != 0)
  1733. TEST_FAIL("X963-KDF test failed!\n", ret);
  1734. else
  1735. TEST_PASS("X963-KDF test passed!\n");
  1736. #endif
  1737. #if defined(HAVE_HPKE) && defined(HAVE_ECC) && defined(HAVE_AESGCM)
  1738. PRIVATE_KEY_UNLOCK();
  1739. if ( (ret = hpke_test()) != 0)
  1740. TEST_FAIL("HPKE test failed!\n", ret);
  1741. else
  1742. TEST_PASS("HPKE test passed!\n");
  1743. PRIVATE_KEY_LOCK();
  1744. #endif
  1745. #if defined(WC_SRTP_KDF)
  1746. PRIVATE_KEY_UNLOCK();
  1747. if ( (ret = srtpkdf_test()) != 0)
  1748. TEST_FAIL("SRTP KDF test failed!\n", ret);
  1749. else
  1750. TEST_PASS("SRTP KDF test passed!\n");
  1751. PRIVATE_KEY_LOCK();
  1752. #endif
  1753. #if defined(WC_KDF_NIST_SP_800_56C)
  1754. if ( (ret = nist_sp80056c_kdf_test()) != 0)
  1755. TEST_FAIL("NIST SP 800-56C KDF test failed!\n", ret);
  1756. else
  1757. TEST_PASS("NIST SP 800-56C KDF test passed!\n");
  1758. #endif
  1759. #if defined(HAVE_AESGCM) && defined(WOLFSSL_AES_128) && \
  1760. !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1761. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1762. if ( (ret = gmac_test()) != 0)
  1763. TEST_FAIL("GMAC test failed!\n", ret);
  1764. else
  1765. TEST_PASS("GMAC test passed!\n");
  1766. #endif
  1767. #ifdef WC_RC2
  1768. if ( (ret = rc2_test()) != 0)
  1769. TEST_FAIL("RC2 test failed!\n", ret);
  1770. else
  1771. TEST_PASS("RC2 test passed!\n");
  1772. #endif
  1773. #ifndef NO_RC4
  1774. if ( (ret = arc4_test()) != 0)
  1775. TEST_FAIL("ARC4 test failed!\n", ret);
  1776. else
  1777. TEST_PASS("ARC4 test passed!\n");
  1778. #endif
  1779. #ifdef HAVE_CHACHA
  1780. if ( (ret = chacha_test()) != 0)
  1781. TEST_FAIL("Chacha test failed!\n", ret);
  1782. else
  1783. TEST_PASS("Chacha test passed!\n");
  1784. #endif
  1785. #ifdef HAVE_XCHACHA
  1786. if ( (ret = XChaCha_test()) != 0)
  1787. TEST_FAIL("XChacha test failed!\n", ret);
  1788. else
  1789. TEST_PASS("XChacha test passed!\n");
  1790. #endif
  1791. #ifdef HAVE_POLY1305
  1792. if ( (ret = poly1305_test()) != 0)
  1793. TEST_FAIL("POLY1305 test failed!\n", ret);
  1794. else
  1795. TEST_PASS("POLY1305 test passed!\n");
  1796. #endif
  1797. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  1798. if ( (ret = chacha20_poly1305_aead_test()) != 0)
  1799. TEST_FAIL("ChaCha20-Poly1305 AEAD test failed!\n", ret);
  1800. else
  1801. TEST_PASS("ChaCha20-Poly1305 AEAD test passed!\n");
  1802. #endif
  1803. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  1804. if ( (ret = XChaCha20Poly1305_test()) != 0)
  1805. TEST_FAIL("XChaCha20-Poly1305 AEAD test failed!\n", ret);
  1806. else
  1807. TEST_PASS("XChaCha20-Poly1305 AEAD test passed!\n");
  1808. #endif
  1809. #ifndef NO_DES3
  1810. if ( (ret = des_test()) != 0)
  1811. TEST_FAIL("DES test failed!\n", ret);
  1812. else
  1813. TEST_PASS("DES test passed!\n");
  1814. #endif
  1815. #ifndef NO_DES3
  1816. if ( (ret = des3_test()) != 0)
  1817. TEST_FAIL("DES3 test failed!\n", ret);
  1818. else
  1819. TEST_PASS("DES3 test passed!\n");
  1820. #endif
  1821. #ifndef NO_AES
  1822. /* key sizes, ECB and Direct tests */
  1823. if ( (ret = aes_test()) != 0)
  1824. TEST_FAIL("AES test failed!\n", ret);
  1825. else
  1826. TEST_PASS("AES test passed!\n");
  1827. #if defined(WOLFSSL_AES_192) && \
  1828. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY)
  1829. if ( (ret = aes192_test()) != 0)
  1830. TEST_FAIL("AES192 test failed!\n", ret);
  1831. else
  1832. TEST_PASS("AES192 test passed!\n");
  1833. #endif
  1834. #if defined(WOLFSSL_AES_256)
  1835. if ( (ret = aes256_test()) != 0)
  1836. TEST_FAIL("AES256 test failed!\n", ret);
  1837. else
  1838. TEST_PASS("AES256 test passed!\n");
  1839. #endif
  1840. #ifdef HAVE_AES_CBC
  1841. if ( (ret = aes_cbc_test()) != 0)
  1842. TEST_FAIL("AES-CBC test failed!\n", ret);
  1843. else
  1844. TEST_PASS("AES-CBC test passed!\n");
  1845. #endif
  1846. #ifdef WOLFSSL_AES_COUNTER
  1847. if ( (ret = aes_ctr_test()) != 0)
  1848. TEST_FAIL("AES-CTR test failed!\n", ret);
  1849. else
  1850. TEST_PASS("AES-CTR test passed!\n");
  1851. #endif
  1852. #ifdef WOLFSSL_AES_OFB
  1853. if ( (ret = aesofb_test()) != 0)
  1854. TEST_FAIL("AES-OFB test failed!\n", ret);
  1855. else
  1856. TEST_PASS("AES-OFB test passed!\n");
  1857. #endif
  1858. #ifdef HAVE_AESGCM
  1859. #if !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO)
  1860. if ( (ret = aesgcm_test()) != 0)
  1861. TEST_FAIL("AES-GCM test failed!\n", ret);
  1862. #endif
  1863. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT) && \
  1864. !defined(WOLFSSL_RENESAS_FSPSM_CRYPTONLY) && \
  1865. !defined(WOLFSSL_KCAPI_AES) && !(defined(WOLF_CRYPTO_CB) && \
  1866. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  1867. if ((ret = aesgcm_default_test()) != 0) {
  1868. TEST_FAIL("AES-GCM test failed!\n", ret);
  1869. }
  1870. #endif
  1871. if (ret == 0) {
  1872. TEST_PASS("AES-GCM test passed!\n");
  1873. }
  1874. #endif
  1875. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  1876. if ( (ret = aesccm_test()) != 0)
  1877. TEST_FAIL("AES-CCM test failed!\n", ret);
  1878. else
  1879. TEST_PASS("AES-CCM test passed!\n");
  1880. #endif
  1881. #ifdef WOLFSSL_AES_CFB
  1882. if ( (ret = aes_cfb_test()) != 0)
  1883. TEST_FAIL("AES-CFB test failed!\n", ret);
  1884. else
  1885. TEST_PASS("AES-CFB test passed!\n");
  1886. #endif
  1887. #ifdef WOLFSSL_AES_XTS
  1888. if ( (ret = aes_xts_test()) != 0)
  1889. TEST_FAIL("AES-XTS test failed!\n", ret);
  1890. else
  1891. TEST_PASS("AES-XTS test passed!\n");
  1892. #endif
  1893. #ifdef HAVE_AES_KEYWRAP
  1894. if ( (ret = aeskeywrap_test()) != 0)
  1895. TEST_FAIL("AES Key Wrap test failed!\n", ret);
  1896. else
  1897. TEST_PASS("AES Key Wrap test passed!\n");
  1898. #endif
  1899. #ifdef WOLFSSL_AES_SIV
  1900. if ( (ret = aes_siv_test()) != 0)
  1901. TEST_FAIL("AES-SIV test failed!\n", ret);
  1902. else
  1903. TEST_PASS("AES-SIV test passed!\n");
  1904. #endif
  1905. #endif /* !NO_AES */
  1906. #if defined(WOLFSSL_AES_EAX) && \
  1907. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  1908. if ( (ret = aes_eax_test()) != 0)
  1909. TEST_FAIL("AES-EAX test failed!\n", ret);
  1910. else
  1911. TEST_PASS("AES-EAX test passed!\n");
  1912. #endif /* WOLFSSL_AES_EAX */
  1913. #ifdef HAVE_ARIA
  1914. if ( (ret = ariagcm_test(MC_ALGID_ARIA_128BITKEY)) != 0)
  1915. TEST_FAIL("ARIA128 test failed!\n", ret);
  1916. else
  1917. TEST_PASS("ARIA128 test passed!\n");
  1918. if ( (ret = ariagcm_test(MC_ALGID_ARIA_192BITKEY)) != 0)
  1919. TEST_FAIL("ARIA192 test failed!\n", ret);
  1920. else
  1921. TEST_PASS("ARIA192 test passed!\n");
  1922. if ( (ret = ariagcm_test(MC_ALGID_ARIA_256BITKEY)) != 0)
  1923. TEST_FAIL("ARIA256 test failed!\n", ret);
  1924. else
  1925. TEST_PASS("ARIA256 test passed!\n");
  1926. #endif
  1927. #ifdef HAVE_CAMELLIA
  1928. if ( (ret = camellia_test()) != 0)
  1929. TEST_FAIL("CAMELLIA test failed!\n", ret);
  1930. else
  1931. TEST_PASS("CAMELLIA test passed!\n");
  1932. #endif
  1933. #ifdef WOLFSSL_SM4
  1934. if ( (ret = sm4_test()) != 0)
  1935. return err_sys("SM-4 test failed!\n", ret);
  1936. else
  1937. TEST_PASS("SM-4 test passed!\n");
  1938. #endif
  1939. #if !defined(NO_RSA) && !defined(HAVE_RENESAS_SYNC)
  1940. #ifdef WC_RSA_NO_PADDING
  1941. if ( (ret = rsa_no_pad_test()) != 0)
  1942. TEST_FAIL("RSA NOPAD test failed!\n", ret);
  1943. else
  1944. TEST_PASS("RSA NOPAD test passed!\n");
  1945. #endif
  1946. if ( (ret = rsa_test()) != 0)
  1947. TEST_FAIL("RSA test failed!\n", ret);
  1948. else
  1949. TEST_PASS("RSA test passed!\n");
  1950. #endif
  1951. #ifndef NO_DH
  1952. PRIVATE_KEY_UNLOCK();
  1953. if ( (ret = dh_test()) != 0)
  1954. TEST_FAIL("DH test failed!\n", ret);
  1955. else
  1956. TEST_PASS("DH test passed!\n");
  1957. PRIVATE_KEY_LOCK();
  1958. #endif
  1959. #ifndef NO_DSA
  1960. if ( (ret = dsa_test()) != 0)
  1961. TEST_FAIL("DSA test failed!\n", ret);
  1962. else
  1963. TEST_PASS("DSA test passed!\n");
  1964. #endif
  1965. #ifdef WOLFCRYPT_HAVE_SRP
  1966. if ( (ret = srp_test()) != 0)
  1967. TEST_FAIL("SRP test failed!\n", ret);
  1968. else
  1969. TEST_PASS("SRP test passed!\n");
  1970. #endif
  1971. #ifndef NO_PWDBASED
  1972. PRIVATE_KEY_UNLOCK();
  1973. if ( (ret = pwdbased_test()) != 0)
  1974. TEST_FAIL("PWDBASED test failed!\n", ret);
  1975. else
  1976. TEST_PASS("PWDBASED test passed!\n");
  1977. PRIVATE_KEY_LOCK();
  1978. #endif
  1979. #if defined(USE_CERT_BUFFERS_2048) && \
  1980. defined(HAVE_PKCS12) && \
  1981. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  1982. !defined(NO_CERTS) && !defined(NO_DES3)
  1983. if ( (ret = pkcs12_test()) != 0)
  1984. TEST_FAIL("PKCS12 test failed!\n", ret);
  1985. else
  1986. TEST_PASS("PKCS12 test passed!\n");
  1987. #endif
  1988. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  1989. if ( (ret = openssl_test()) != 0)
  1990. TEST_FAIL("OPENSSL test failed!\n", ret);
  1991. else
  1992. TEST_PASS("OPENSSL test passed!\n");
  1993. if ( (ret = openSSL_evpMD_test()) != 0)
  1994. TEST_FAIL("OPENSSL (EVP MD) test failed!\n", ret);
  1995. else
  1996. TEST_PASS("OPENSSL (EVP MD) passed!\n");
  1997. if ( (ret = openssl_pkey0_test()) != 0)
  1998. TEST_FAIL("OPENSSL (PKEY0) test failed!\n", ret);
  1999. else
  2000. TEST_PASS("OPENSSL (PKEY0) passed!\n");
  2001. if ( (ret = openssl_pkey1_test()) != 0)
  2002. TEST_FAIL("OPENSSL (PKEY1) test failed!\n", ret);
  2003. else
  2004. TEST_PASS("OPENSSL (PKEY1) passed!\n");
  2005. #if !defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  2006. if ( (ret = openssl_evpSig_test()) != 0)
  2007. TEST_FAIL("OPENSSL (EVP Sign/Verify) test failed!\n", ret);
  2008. else
  2009. TEST_PASS("OPENSSL (EVP Sign/Verify) passed!\n");
  2010. #endif
  2011. #endif
  2012. #if defined(HAVE_ECC)
  2013. PRIVATE_KEY_UNLOCK();
  2014. if ( (ret = ecc_test()) != 0)
  2015. TEST_FAIL("ECC test failed!\n", ret);
  2016. else
  2017. TEST_PASS("ECC test passed!\n");
  2018. PRIVATE_KEY_LOCK();
  2019. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  2020. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  2021. if ( (ret = ecc_encrypt_test()) != 0)
  2022. TEST_FAIL("ECC Enc test failed!\n", ret);
  2023. else
  2024. TEST_PASS("ECC Enc test passed!\n");
  2025. #endif
  2026. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  2027. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  2028. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  2029. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  2030. /* skip for ATECC508/608A, cannot import private key buffers */
  2031. if ( (ret = ecc_test_buffers()) != 0)
  2032. TEST_FAIL("ECC buffer test failed!\n", ret);
  2033. else
  2034. TEST_PASS("ECC buffer test passed!\n");
  2035. #endif
  2036. #endif
  2037. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  2038. !defined(NO_FILESYSTEM)
  2039. if ( (ret = cert_test()) != 0)
  2040. TEST_FAIL("CERT test failed!\n", ret);
  2041. else
  2042. TEST_PASS("CERT test passed!\n");
  2043. #endif
  2044. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  2045. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  2046. if ( (ret = certext_test()) != 0)
  2047. TEST_FAIL("CERT EXT test failed!\n", ret);
  2048. else
  2049. TEST_PASS("CERT EXT test passed!\n");
  2050. #endif
  2051. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  2052. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  2053. if ( (ret = decodedCertCache_test()) != 0)
  2054. TEST_FAIL("DECODED CERT CACHE test failed!\n", ret);
  2055. else
  2056. TEST_PASS("DECODED CERT CACHE test passed!\n");
  2057. #endif
  2058. #ifdef HAVE_CURVE25519
  2059. if ( (ret = curve25519_test()) != 0)
  2060. TEST_FAIL("CURVE25519 test failed!\n", ret);
  2061. else
  2062. TEST_PASS("CURVE25519 test passed!\n");
  2063. #endif
  2064. #ifdef HAVE_ED25519
  2065. PRIVATE_KEY_UNLOCK();
  2066. if ( (ret = ed25519_test()) != 0)
  2067. TEST_FAIL("ED25519 test failed!\n", ret);
  2068. else
  2069. TEST_PASS("ED25519 test passed!\n");
  2070. PRIVATE_KEY_LOCK();
  2071. #endif
  2072. #ifdef HAVE_CURVE448
  2073. if ( (ret = curve448_test()) != 0)
  2074. TEST_FAIL("CURVE448 test failed!\n", ret);
  2075. else
  2076. TEST_PASS("CURVE448 test passed!\n");
  2077. #endif
  2078. #ifdef HAVE_ED448
  2079. PRIVATE_KEY_UNLOCK();
  2080. if ( (ret = ed448_test()) != 0)
  2081. TEST_FAIL("ED448 test failed!\n", ret);
  2082. else
  2083. TEST_PASS("ED448 test passed!\n");
  2084. PRIVATE_KEY_LOCK();
  2085. #endif
  2086. #ifdef WOLFSSL_HAVE_KYBER
  2087. if ( (ret = kyber_test()) != 0)
  2088. TEST_FAIL("KYBER test failed!\n", ret);
  2089. else
  2090. TEST_PASS("KYBER test passed!\n");
  2091. #endif
  2092. #ifdef HAVE_DILITHIUM
  2093. if ( (ret = dilithium_test()) != 0)
  2094. TEST_FAIL("DILITHIUM test failed!\n", ret);
  2095. else
  2096. TEST_PASS("DILITHIUM test passed!\n");
  2097. #endif
  2098. #if defined(WOLFSSL_HAVE_XMSS)
  2099. #if !defined(WOLFSSL_SMALL_STACK) && WOLFSSL_XMSS_MIN_HEIGHT <= 10
  2100. if ( (ret = xmss_test_verify_only()) != 0)
  2101. TEST_FAIL("XMSS Vfy test failed!\n", ret);
  2102. else
  2103. TEST_PASS("XMSS Vfy test passed!\n");
  2104. #endif
  2105. #if !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  2106. if ( (ret = xmss_test()) != 0)
  2107. TEST_FAIL("XMSS test failed!\n", ret);
  2108. else
  2109. TEST_PASS("XMSS test passed!\n");
  2110. #endif
  2111. #endif /* if defined(WOLFSSL_HAVE_XMSS) */
  2112. #if defined(WOLFSSL_HAVE_LMS)
  2113. #if !defined(WOLFSSL_SMALL_STACK)
  2114. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  2115. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  2116. if ( (ret = lms_test_verify_only()) != 0)
  2117. TEST_FAIL("LMS Vfy test failed!\n", ret);
  2118. else
  2119. TEST_PASS("LMS Vfy test passed!\n");
  2120. #endif
  2121. #endif
  2122. #if !defined(WOLFSSL_LMS_VERIFY_ONLY)
  2123. if ( (ret = lms_test()) != 0)
  2124. TEST_FAIL("LMS test failed!\n", ret);
  2125. else
  2126. TEST_PASS("LMS test passed!\n");
  2127. #endif
  2128. #endif /* if defined(WOLFSSL_HAVE_LMS) */
  2129. #ifdef WOLFCRYPT_HAVE_ECCSI
  2130. if ( (ret = eccsi_test()) != 0)
  2131. TEST_FAIL("ECCSI test failed!\n", ret);
  2132. else
  2133. TEST_PASS("ECCSI test passed!\n");
  2134. #endif
  2135. #ifdef WOLFCRYPT_HAVE_SAKKE
  2136. if ( (ret = sakke_test()) != 0)
  2137. TEST_FAIL("SAKKE test failed!\n", ret);
  2138. else
  2139. TEST_PASS("SAKKE test passed!\n");
  2140. #endif
  2141. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  2142. if ( (ret = cmac_test()) != 0)
  2143. TEST_FAIL("CMAC test failed!\n", ret);
  2144. else
  2145. TEST_PASS("CMAC test passed!\n");
  2146. #endif
  2147. #if defined(WOLFSSL_SIPHASH)
  2148. if ( (ret = siphash_test()) != 0)
  2149. TEST_FAIL("SipHash test failed!\n", ret);
  2150. else
  2151. TEST_PASS("SipHash test passed!\n");
  2152. #endif
  2153. #ifdef HAVE_LIBZ
  2154. if ( (ret = compress_test()) != 0)
  2155. TEST_FAIL("COMPRESS test failed!\n", ret);
  2156. else
  2157. TEST_PASS("COMPRESS test passed!\n");
  2158. #endif
  2159. #ifdef HAVE_PKCS7
  2160. #ifndef NO_PKCS7_ENCRYPTED_DATA
  2161. if ( (ret = pkcs7encrypted_test()) != 0)
  2162. TEST_FAIL("PKCS7encrypted test failed!\n", ret);
  2163. else
  2164. TEST_PASS("PKCS7encrypted test passed!\n");
  2165. #endif
  2166. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  2167. if ( (ret = pkcs7compressed_test()) != 0)
  2168. TEST_FAIL("PKCS7compressed test failed!\n", ret);
  2169. else
  2170. TEST_PASS("PKCS7compressed test passed!\n");
  2171. #endif
  2172. if ( (ret = pkcs7signed_test()) != 0)
  2173. TEST_FAIL("PKCS7signed test failed!\n", ret);
  2174. else
  2175. TEST_PASS("PKCS7signed test passed!\n");
  2176. if ( (ret = pkcs7enveloped_test()) != 0)
  2177. TEST_FAIL("PKCS7enveloped test failed!\n", ret);
  2178. else
  2179. TEST_PASS("PKCS7enveloped test passed!\n");
  2180. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  2181. if ( (ret = pkcs7authenveloped_test()) != 0)
  2182. TEST_FAIL("PKCS7authenveloped test failed!\n", ret);
  2183. else
  2184. TEST_PASS("PKCS7authenveloped test passed!\n");
  2185. #endif
  2186. #endif
  2187. #if defined(WOLFSSL_PUBLIC_MP) && \
  2188. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  2189. defined(USE_FAST_MATH))
  2190. if ( (ret = mp_test()) != 0)
  2191. TEST_FAIL("mp test failed!\n", ret);
  2192. else
  2193. TEST_PASS("mp test passed!\n");
  2194. #endif
  2195. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  2196. if ( (ret = prime_test()) != 0)
  2197. TEST_FAIL("prime test failed!\n", ret);
  2198. else
  2199. TEST_PASS("prime test passed!\n");
  2200. #endif
  2201. #if defined(ASN_BER_TO_DER) && \
  2202. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  2203. defined(OPENSSL_EXTRA_X509_SMALL))
  2204. if ( (ret = berder_test()) != 0)
  2205. TEST_FAIL("ber-der test failed!\n", ret);
  2206. else
  2207. TEST_PASS("ber-der test passed!\n");
  2208. #endif
  2209. if ( (ret = logging_test()) != 0)
  2210. TEST_FAIL("logging test failed!\n", ret);
  2211. else
  2212. TEST_PASS("logging test passed!\n");
  2213. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  2214. if ( (ret = time_test()) != 0)
  2215. TEST_FAIL("time test failed!\n", ret);
  2216. else
  2217. TEST_PASS("time test passed!\n");
  2218. #endif
  2219. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  2220. if ((ret = wolfcrypt_mutex_test()) != 0)
  2221. #else
  2222. if ((ret = mutex_test()) != 0)
  2223. #endif
  2224. TEST_FAIL("mutex test failed!\n", ret);
  2225. else
  2226. TEST_PASS("mutex test passed!\n");
  2227. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  2228. if ( (ret = memcb_test()) != 0)
  2229. TEST_FAIL("memcb test failed!\n", ret);
  2230. else
  2231. TEST_PASS("memcb test passed!\n");
  2232. #endif
  2233. #ifdef WOLFSSL_CAAM_BLOB
  2234. if ( (ret = blob_test()) != 0)
  2235. TEST_FAIL("blob test failed!\n", ret);
  2236. else
  2237. TEST_PASS("blob test passed!\n");
  2238. #endif
  2239. #if defined(WOLF_CRYPTO_CB) && !defined(WC_TEST_NO_CRYPTOCB_SW_TEST) && \
  2240. !(defined(HAVE_INTEL_QAT_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2241. defined(WOLFSSL_QNX_CAAM) || defined(HAVE_RENESAS_SYNC))
  2242. if ( (ret = cryptocb_test()) != 0)
  2243. TEST_FAIL("crypto callback test failed!\n", ret);
  2244. else
  2245. TEST_PASS("crypto callback test passed!\n");
  2246. #endif
  2247. #ifdef WOLFSSL_CERT_PIV
  2248. if ( (ret = certpiv_test()) != 0)
  2249. TEST_FAIL("cert piv test failed!\n", ret);
  2250. else
  2251. TEST_PASS("cert piv test passed!\n");
  2252. #endif
  2253. #ifdef WOLF_CRYPTO_CB
  2254. #ifdef HAVE_INTEL_QA_SYNC
  2255. wc_CryptoCb_CleanupIntelQa(&devId);
  2256. #endif
  2257. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2258. wc_CryptoCb_CleanupOcteon(&devId);
  2259. #endif
  2260. #endif
  2261. #ifdef WOLFSSL_ASYNC_CRYPT
  2262. wolfAsync_DevClose(&devId);
  2263. #endif
  2264. /* cleanup the thread if fixed point cache is enabled and have thread local */
  2265. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  2266. wc_ecc_fp_free();
  2267. #endif
  2268. #ifdef TEST_ALWAYS_RUN_TO_END
  2269. if (last_failed_test_ret != 0)
  2270. ret = last_failed_test_ret;
  2271. #endif
  2272. if (args)
  2273. ((func_args*)args)->return_code = ret;
  2274. /* If hardware acceleration and respective metrics tracked, show results: */
  2275. #ifdef WOLFSSL_HW_METRICS
  2276. #if defined(WOLFSSL_ESP32_CRYPT_RSA_PRI) && defined(WOLFSSL_HW_METRICS)
  2277. esp_hw_show_mp_metrics();
  2278. #endif
  2279. #endif
  2280. #if defined(WOLFSSL_STATIC_MEMORY) && !defined(OPENSSL_EXTRA)
  2281. wolfSSL_SetGlobalHeapHint(NULL);
  2282. #endif
  2283. TEST_PASS("Test complete\n");
  2284. EXIT_TEST(ret);
  2285. } /* end of wolfcrypt_test() */
  2286. #ifndef NO_MAIN_DRIVER
  2287. #ifdef HAVE_WOLFCRYPT_TEST_OPTIONS
  2288. int myoptind = 0;
  2289. char* myoptarg = NULL;
  2290. #endif
  2291. /* so overall tests can pull in test function */
  2292. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  2293. wc_test_ret_t wolf_test_task(void)
  2294. #else
  2295. #ifndef NO_MAIN_FUNCTION
  2296. int main(int argc, char** argv)
  2297. {
  2298. return (int)wolfcrypt_test_main(argc, argv);
  2299. }
  2300. #endif
  2301. wc_test_ret_t wolfcrypt_test_main(int argc, char** argv)
  2302. #endif
  2303. {
  2304. wc_test_ret_t ret;
  2305. func_args args = { 0, 0, 0 };
  2306. #if defined(WOLFSSL_ESPIDF) || defined(WOLFSSL_SE050)
  2307. /* set dummy wallclock time. */
  2308. struct timeval utctime;
  2309. struct timezone tz;
  2310. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2311. utctime.tv_usec = 0;
  2312. tz.tz_minuteswest = 0;
  2313. tz.tz_dsttime = 0;
  2314. settimeofday(&utctime, &tz);
  2315. #endif
  2316. #ifdef WOLFSSL_APACHE_MYNEWT
  2317. #ifdef ARCH_sim
  2318. mcu_sim_parse_args(argc, argv);
  2319. #endif
  2320. sysinit();
  2321. /* set dummy wallclock time. */
  2322. struct os_timeval utctime;
  2323. struct os_timezone tz;
  2324. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2325. utctime.tv_usec = 0;
  2326. tz.tz_minuteswest = 0;
  2327. tz.tz_dsttime = 0;
  2328. os_settimeofday(&utctime, &tz);
  2329. #endif
  2330. #ifdef WOLFSSL_ZEPHYR
  2331. /* set dummy wallclock time. */
  2332. struct timespec utctime;
  2333. utctime.tv_sec = 1521725159; /* dummy time: 2018-03-22T13:25:59+00:00 */
  2334. utctime.tv_nsec = 0;
  2335. clock_settime(CLOCK_REALTIME, &utctime);
  2336. #endif
  2337. #ifdef DEVKITPRO
  2338. void *framebuffer;
  2339. GXRModeObj *rmode = NULL;
  2340. VIDEO_Init();
  2341. WPAD_Init();
  2342. rmode = VIDEO_GetPreferredMode(NULL);
  2343. #pragma GCC diagnostic ignored "-Wbad-function-cast"
  2344. framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  2345. #pragma GCC diagnostic pop
  2346. console_init(framebuffer,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
  2347. VIDEO_Configure(rmode);
  2348. VIDEO_SetNextFramebuffer(framebuffer);
  2349. VIDEO_SetBlack(FALSE);
  2350. VIDEO_Flush();
  2351. VIDEO_WaitVSync();
  2352. if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
  2353. #endif
  2354. #ifdef WOLFSSL_NDS
  2355. /* Init Console output */
  2356. consoleDemoInit();
  2357. /* Init the Filesystem */
  2358. fatInitDefault();
  2359. #endif
  2360. #ifdef HAVE_WNR
  2361. if ((ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000)) != 0) {
  2362. err_sys("Whitewood netRandom global config failed",
  2363. WC_TEST_RET_ENC_EC(ret));
  2364. return WC_TEST_RET_ENC_EC(ret);
  2365. }
  2366. #endif
  2367. #ifndef WOLFSSL_ESPIDF
  2368. args.argc = argc;
  2369. args.argv = argv;
  2370. #endif
  2371. if ((ret = wolfCrypt_Init()) != 0) {
  2372. printf("wolfCrypt_Init failed %d\n", (int)ret);
  2373. err_sys("Error with wolfCrypt_Init!\n", WC_TEST_RET_ENC_EC(ret));
  2374. }
  2375. #ifdef HAVE_WC_INTROSPECTION
  2376. printf("Math: %s\n", wc_GetMathInfo());
  2377. #endif
  2378. #ifdef HAVE_STACK_SIZE
  2379. StackSizeCheck(&args, wolfcrypt_test);
  2380. #else
  2381. wolfcrypt_test(&args);
  2382. #endif
  2383. if ((ret = wolfCrypt_Cleanup()) != 0) {
  2384. printf("wolfCrypt_Cleanup failed %d\n", (int)ret);
  2385. err_sys("Error with wolfCrypt_Cleanup!\n", WC_TEST_RET_ENC_EC(ret));
  2386. }
  2387. #ifdef HAVE_WNR
  2388. if ((ret = wc_FreeNetRandom()) < 0)
  2389. err_sys("Failed to free netRandom context",
  2390. WC_TEST_RET_ENC_EC(ret));
  2391. #endif /* HAVE_WNR */
  2392. #ifdef DOLPHIN_EMULATOR
  2393. /* Returning from main panics the emulator. Just hang
  2394. * and let the user force quit the emulator window. */
  2395. printf("args.return_code: %d\n", args.return_code);
  2396. printf("Testing complete. You may close the window now\n");
  2397. while (1);
  2398. #endif
  2399. #ifdef WOLFSSL_NDS
  2400. /* in Nintendo DS returning from main shuts down the Device without letting you see the Results. */
  2401. printf("args.return_code: %d\n", args.return_code);
  2402. printf("Testing complete. Press Start to exit the Program\n");
  2403. while(1) {
  2404. swiWaitForVBlank();
  2405. scanKeys();
  2406. int keys = keysDown();
  2407. if(keys & KEY_START) break;
  2408. }
  2409. #endif
  2410. #if defined(WOLFSSL_ESPIDF)
  2411. /* ESP_LOGI to print takes up a lot less memory than printf */
  2412. ESP_LOGI(ESPIDF_TAG, "Exiting main with return code: % d\n",
  2413. args.return_code);
  2414. #else
  2415. /* gate this for target platforms wishing to avoid printf reference */
  2416. printf("Exiting main with return code: %ld\n", (long int)args.return_code);
  2417. #endif
  2418. return args.return_code;
  2419. } /* wolfcrypt_test_main or wolf_test_task */
  2420. #endif /* NO_MAIN_DRIVER */
  2421. /* helper to save DER, convert to PEM and save PEM */
  2422. #if !defined(NO_ASN) && (defined(HAVE_ECC) || !defined(NO_DSA) || \
  2423. (!defined(NO_RSA) && (defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN)))) \
  2424. && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  2425. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2426. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, fD, fP, pT, WC_TEST_RET_LN)
  2427. #else
  2428. #define SaveDerAndPem(d, dSz, fD, fP, pT) _SaveDerAndPem(d, dSz, NULL, NULL, pT, WC_TEST_RET_LN)
  2429. #endif
  2430. static wc_test_ret_t _SaveDerAndPem(const byte* der, int derSz,
  2431. const char* fileDer, const char* filePem, int pemType, int calling_line)
  2432. {
  2433. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2434. wc_test_ret_t ret;
  2435. XFILE derFile;
  2436. derFile = XFOPEN(fileDer, "wb");
  2437. if (!derFile) {
  2438. return WC_TEST_RET_ENC(calling_line, 0, WC_TEST_RET_TAG_I);
  2439. }
  2440. ret = (int)XFWRITE(der, 1, (size_t)derSz, derFile);
  2441. XFCLOSE(derFile);
  2442. if (ret != derSz) {
  2443. return WC_TEST_RET_ENC(calling_line, 1, WC_TEST_RET_TAG_I);
  2444. }
  2445. #endif
  2446. #ifdef WOLFSSL_DER_TO_PEM
  2447. if (filePem) {
  2448. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2449. XFILE pemFile;
  2450. #endif
  2451. #ifndef WOLFSSL_NO_MALLOC
  2452. byte* pem;
  2453. #else
  2454. byte pem[2048];
  2455. #endif
  2456. int pemSz;
  2457. /* calculate PEM size */
  2458. pemSz = wc_DerToPem(der, (word32)derSz, NULL, 0, pemType);
  2459. if (pemSz < 0) {
  2460. return WC_TEST_RET_ENC(calling_line, 2, WC_TEST_RET_TAG_I);
  2461. }
  2462. #ifndef WOLFSSL_NO_MALLOC
  2463. pem = (byte*)XMALLOC((word32)pemSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2464. if (pem == NULL) {
  2465. return WC_TEST_RET_ENC(calling_line, 3, WC_TEST_RET_TAG_I);
  2466. }
  2467. #else
  2468. if (pemSz > (int)sizeof(pem))
  2469. return WC_TEST_RET_ENC_EC(BAD_FUNC_ARG);
  2470. #endif
  2471. /* Convert to PEM */
  2472. pemSz = wc_DerToPem(der, (word32)derSz, pem, (word32)pemSz, pemType);
  2473. if (pemSz < 0) {
  2474. #ifndef WOLFSSL_NO_MALLOC
  2475. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2476. #endif
  2477. return WC_TEST_RET_ENC(calling_line, 4, WC_TEST_RET_TAG_I);
  2478. }
  2479. #if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
  2480. pemFile = XFOPEN(filePem, "wb");
  2481. if (!pemFile) {
  2482. #ifndef WOLFSSL_NO_MALLOC
  2483. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2484. #endif
  2485. return WC_TEST_RET_ENC(calling_line, 5, WC_TEST_RET_TAG_I);
  2486. }
  2487. ret = (int)XFWRITE(pem, 1, (size_t)pemSz, pemFile);
  2488. XFCLOSE(pemFile);
  2489. if (ret != pemSz) {
  2490. #ifndef WOLFSSL_NO_MALLOC
  2491. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2492. #endif
  2493. return WC_TEST_RET_ENC(calling_line, 6, WC_TEST_RET_TAG_I);
  2494. }
  2495. #endif
  2496. #ifndef WOLFSSL_NO_MALLOC
  2497. XFREE(pem, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  2498. #endif
  2499. }
  2500. #endif /* WOLFSSL_DER_TO_PEM */
  2501. /* suppress unused variable warnings */
  2502. (void)der;
  2503. (void)derSz;
  2504. (void)filePem;
  2505. (void)fileDer;
  2506. (void)pemType;
  2507. (void)calling_line;
  2508. return 0;
  2509. }
  2510. #endif /* WOLFSSL_KEY_GEN || WOLFSSL_CERT_GEN */
  2511. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t error_test(void)
  2512. {
  2513. const char* errStr;
  2514. char out[WOLFSSL_MAX_ERROR_SZ];
  2515. const char* unknownStr = wc_GetErrorString(0);
  2516. #ifdef NO_ERROR_STRINGS
  2517. /* Ensure a valid error code's string matches an invalid code's.
  2518. * The string is that error strings are not available.
  2519. */
  2520. WOLFSSL_ENTER("error_test NO_ERROR_STRINGS");
  2521. errStr = wc_GetErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E));
  2522. wc_ErrorString(WC_NO_ERR_TRACE(OPEN_RAN_E), out);
  2523. if (XSTRCMP(errStr, unknownStr) != 0)
  2524. return WC_TEST_RET_ENC_NC;
  2525. if (XSTRCMP(out, unknownStr) != 0)
  2526. return WC_TEST_RET_ENC_NC;
  2527. #else
  2528. int i;
  2529. int j = 0;
  2530. /* Values that are not or no longer error codes. */
  2531. static const struct {
  2532. int first;
  2533. int last;
  2534. } missing[] = {
  2535. { -124, -124 },
  2536. { -166, -169 }
  2537. };
  2538. /* Check that all errors have a string and it's the same through the two
  2539. * APIs. Check that the values that are not errors map to the unknown
  2540. * string.
  2541. */
  2542. for (i = WC_FIRST_E; i >= WC_LAST_E; i--) {
  2543. int this_missing = 0;
  2544. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  2545. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  2546. this_missing = 1;
  2547. break;
  2548. }
  2549. }
  2550. errStr = wc_GetErrorString(i);
  2551. wc_ErrorString(i, out);
  2552. if (! this_missing) {
  2553. if (XSTRCMP(errStr, unknownStr) == 0) {
  2554. WOLFSSL_MSG("errStr unknown");
  2555. return WC_TEST_RET_ENC_I(-i);
  2556. }
  2557. if (XSTRCMP(out, unknownStr) == 0) {
  2558. WOLFSSL_MSG("out unknown");
  2559. return WC_TEST_RET_ENC_I(-i);
  2560. }
  2561. if (XSTRCMP(errStr, out) != 0) {
  2562. WOLFSSL_MSG("errStr does not match output");
  2563. return WC_TEST_RET_ENC_I(-i);
  2564. }
  2565. if (XSTRLEN(errStr) >= WOLFSSL_MAX_ERROR_SZ) {
  2566. WOLFSSL_MSG("errStr too long");
  2567. return WC_TEST_RET_ENC_I(-i);
  2568. }
  2569. }
  2570. else {
  2571. j++;
  2572. if (XSTRCMP(errStr, unknownStr) != 0)
  2573. return WC_TEST_RET_ENC_I(-i);
  2574. if (XSTRCMP(out, unknownStr) != 0)
  2575. return WC_TEST_RET_ENC_I(-i);
  2576. }
  2577. }
  2578. /* Check if the next possible value has been given a string. */
  2579. errStr = wc_GetErrorString(i);
  2580. wc_ErrorString(i, out);
  2581. if (XSTRCMP(errStr, unknownStr) != 0)
  2582. return WC_TEST_RET_ENC_NC;
  2583. if (XSTRCMP(out, unknownStr) != 0)
  2584. return WC_TEST_RET_ENC_NC;
  2585. #endif
  2586. return 0;
  2587. }
  2588. #ifndef NO_CODING
  2589. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void)
  2590. {
  2591. wc_test_ret_t ret;
  2592. WOLFSSL_SMALL_STACK_STATIC const byte good[] = "A+Gd\0\0\0";
  2593. WOLFSSL_SMALL_STACK_STATIC const byte goodEnd[] = "A+Gd \r\n";
  2594. WOLFSSL_SMALL_STACK_STATIC const byte good_spaces[] = " A + G d \0";
  2595. byte out[128];
  2596. word32 outLen;
  2597. #ifdef WOLFSSL_BASE64_ENCODE
  2598. byte data[3];
  2599. word32 dataLen;
  2600. byte longData[79] = { 0 };
  2601. WOLFSSL_SMALL_STACK_STATIC const byte symbols[] = "+/A=";
  2602. #endif
  2603. WOLFSSL_SMALL_STACK_STATIC const byte badSmall[] = "AAA!Gdj=";
  2604. WOLFSSL_SMALL_STACK_STATIC const byte badLarge[] = "AAA~Gdj=";
  2605. WOLFSSL_SMALL_STACK_STATIC const byte badEOL[] = "A+Gd!AA";
  2606. WOLFSSL_SMALL_STACK_STATIC const byte badPadding[] = "AA=A";
  2607. WOLFSSL_SMALL_STACK_STATIC const byte badChar[] = ",-.:;<=>?@[\\]^_`";
  2608. byte goodChar[] =
  2609. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2610. "abcdefghijklmnopqrstuvwxyz"
  2611. "0123456789+/;";
  2612. byte charTest[] = "A+Gd\0\0\0";
  2613. int i;
  2614. WOLFSSL_ENTER("base64_test");
  2615. /* Good Base64 encodings. */
  2616. outLen = sizeof(out);
  2617. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2618. if (ret != 0)
  2619. return WC_TEST_RET_ENC_EC(ret);
  2620. outLen = sizeof(out);
  2621. ret = Base64_Decode(goodEnd, sizeof(goodEnd), out, &outLen);
  2622. if (ret != 0)
  2623. return WC_TEST_RET_ENC_EC(ret);
  2624. outLen = sizeof(goodChar);
  2625. ret = Base64_Decode(goodChar, sizeof(goodChar), goodChar, &outLen);
  2626. if (ret != 0)
  2627. return WC_TEST_RET_ENC_EC(ret);
  2628. if (outLen != 64 / 4 * 3)
  2629. return WC_TEST_RET_ENC_NC;
  2630. outLen = sizeof(out);
  2631. ret = Base64_Decode(good_spaces, sizeof(good_spaces), out, &outLen);
  2632. if (ret != 0)
  2633. return WC_TEST_RET_ENC_EC(ret);
  2634. /* Bad parameters. */
  2635. outLen = 1;
  2636. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2637. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2638. return WC_TEST_RET_ENC_EC(ret);
  2639. outLen = sizeof(out);
  2640. ret = Base64_Decode(badEOL, sizeof(badEOL), out, &outLen);
  2641. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2642. return WC_TEST_RET_ENC_EC(ret);
  2643. outLen = sizeof(out);
  2644. ret = Base64_Decode(badPadding, sizeof(badPadding), out, &outLen);
  2645. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2646. return WC_TEST_RET_ENC_EC(ret);
  2647. /* Bad character at each offset 0-3. */
  2648. for (i = 0; i < 4; i++) {
  2649. outLen = sizeof(out);
  2650. ret = Base64_Decode(badSmall + i, 4, out, &outLen);
  2651. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2652. return WC_TEST_RET_ENC_I(i);
  2653. ret = Base64_Decode(badLarge + i, 4, out, &outLen);
  2654. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2655. return WC_TEST_RET_ENC_I(i);
  2656. }
  2657. /* Invalid character less than 0x2b */
  2658. for (i = 1; i < 0x2b; i++) {
  2659. outLen = sizeof(out);
  2660. charTest[0] = (byte)i;
  2661. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2662. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2663. return WC_TEST_RET_ENC_I(i);
  2664. }
  2665. /* Bad characters in range 0x2b - 0x7a. */
  2666. for (i = 0; i < (int)sizeof(badChar) - 1; i++) {
  2667. outLen = sizeof(out);
  2668. charTest[0] = badChar[i];
  2669. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2670. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2671. return WC_TEST_RET_ENC_I(i);
  2672. }
  2673. /* Invalid character greater than 0x7a */
  2674. for (i = 0x7b; i < 0x100; i++) {
  2675. outLen = sizeof(out);
  2676. charTest[0] = (byte)i;
  2677. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2678. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2679. return WC_TEST_RET_ENC_I(i);
  2680. }
  2681. #ifdef WOLFSSL_BASE64_ENCODE
  2682. /* Decode and encode all symbols - non-alphanumeric. */
  2683. dataLen = sizeof(data);
  2684. ret = Base64_Decode(symbols, sizeof(symbols), data, &dataLen);
  2685. if (ret != 0)
  2686. return WC_TEST_RET_ENC_EC(ret);
  2687. outLen = sizeof(out);
  2688. ret = Base64_Encode(data, dataLen, NULL, &outLen);
  2689. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2690. return WC_TEST_RET_ENC_EC(ret);
  2691. outLen = sizeof(out);
  2692. ret = Base64_Encode(data, dataLen, out, &outLen);
  2693. if (ret != 0)
  2694. return WC_TEST_RET_ENC_EC(ret);
  2695. outLen = 7;
  2696. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2697. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  2698. return WC_TEST_RET_ENC_EC(ret);
  2699. outLen = sizeof(out);
  2700. ret = Base64_EncodeEsc(data, dataLen, NULL, &outLen);
  2701. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2702. return WC_TEST_RET_ENC_EC(ret);
  2703. outLen = sizeof(out);
  2704. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2705. if (ret != 0)
  2706. return WC_TEST_RET_ENC_EC(ret);
  2707. outLen = sizeof(out);
  2708. ret = Base64_Encode_NoNl(data, dataLen, out, &outLen);
  2709. if (ret != 0)
  2710. return WC_TEST_RET_ENC_EC(ret);
  2711. /* Data that results in an encoding longer than one line. */
  2712. outLen = sizeof(out);
  2713. dataLen = sizeof(longData);
  2714. ret = Base64_Encode(longData, dataLen, out, &outLen);
  2715. if (ret != 0)
  2716. return WC_TEST_RET_ENC_EC(ret);
  2717. outLen = sizeof(out);
  2718. ret = Base64_EncodeEsc(longData, dataLen, out, &outLen);
  2719. if (ret != 0)
  2720. return WC_TEST_RET_ENC_EC(ret);
  2721. outLen = sizeof(out);
  2722. ret = Base64_Encode_NoNl(longData, dataLen, out, &outLen);
  2723. if (ret != 0)
  2724. return WC_TEST_RET_ENC_EC(ret);
  2725. #endif
  2726. return 0;
  2727. }
  2728. #ifdef WOLFSSL_BASE16
  2729. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void)
  2730. {
  2731. wc_test_ret_t ret;
  2732. WOLFSSL_SMALL_STACK_STATIC const byte testData[] = "SomeDataToEncode\n";
  2733. WOLFSSL_SMALL_STACK_STATIC const byte encodedTestData[] = "536F6D6544617461546F456E636F64650A00";
  2734. byte encoded[40];
  2735. word32 encodedLen;
  2736. byte plain[40];
  2737. word32 len;
  2738. WOLFSSL_ENTER("base16_test");
  2739. /* length returned includes null termination */
  2740. encodedLen = sizeof(encoded);
  2741. ret = Base16_Encode(testData, sizeof(testData), encoded, &encodedLen);
  2742. if (ret != 0)
  2743. return WC_TEST_RET_ENC_EC(ret);
  2744. len = (word32)XSTRLEN((char*)encoded);
  2745. if (len != encodedLen - 1)
  2746. return WC_TEST_RET_ENC_NC;
  2747. len = sizeof(plain);
  2748. ret = Base16_Decode(encoded, encodedLen - 1, plain, &len);
  2749. if (ret != 0)
  2750. return WC_TEST_RET_ENC_EC(ret);
  2751. if (len != sizeof(testData) || XMEMCMP(testData, plain, len) != 0)
  2752. return WC_TEST_RET_ENC_NC;
  2753. if (encodedLen != sizeof(encodedTestData) ||
  2754. XMEMCMP(encoded, encodedTestData, encodedLen) != 0) {
  2755. return WC_TEST_RET_ENC_NC;
  2756. }
  2757. return 0;
  2758. }
  2759. #endif /* WOLFSSL_BASE16 */
  2760. #endif /* !NO_CODING */
  2761. #ifndef NO_ASN
  2762. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void)
  2763. {
  2764. wc_test_ret_t ret;
  2765. /* ASN1 encoded date buffer */
  2766. WOLFSSL_SMALL_STACK_STATIC const byte dateBuf[] = {
  2767. 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x31,
  2768. 0x32, 0x30, 0x30, 0x37, 0x33, 0x37, 0x5a
  2769. };
  2770. byte format;
  2771. int length;
  2772. const byte* datePart;
  2773. #ifndef NO_ASN_TIME
  2774. struct tm timearg;
  2775. time_t now;
  2776. #endif
  2777. WOLFSSL_ENTER("asn_test");
  2778. ret = wc_GetDateInfo(dateBuf, (int)sizeof(dateBuf), &datePart, &format,
  2779. &length);
  2780. if (ret != 0)
  2781. return WC_TEST_RET_ENC_EC(ret);
  2782. #ifndef NO_ASN_TIME
  2783. /* Parameter Validation tests. */
  2784. if ((ret = wc_GetTime(NULL, sizeof(now))) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2785. return WC_TEST_RET_ENC_EC(ret);
  2786. if ((ret = wc_GetTime(&now, 0)) != WC_NO_ERR_TRACE(BUFFER_E))
  2787. return WC_TEST_RET_ENC_EC(ret);
  2788. now = 0;
  2789. if ((ret = wc_GetTime(&now, sizeof(now))) != 0) {
  2790. return WC_TEST_RET_ENC_EC(ret);
  2791. }
  2792. if (now == 0) {
  2793. printf("RTC/Time not set!\n");
  2794. return WC_TEST_RET_ENC_NC;
  2795. }
  2796. ret = wc_GetDateAsCalendarTime(datePart, length, format, &timearg);
  2797. if (ret != 0)
  2798. return WC_TEST_RET_ENC_EC(ret);
  2799. #endif /* !NO_ASN_TIME */
  2800. return 0;
  2801. }
  2802. #endif /* !NO_ASN */
  2803. #ifdef WOLFSSL_MD2
  2804. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void)
  2805. {
  2806. wc_test_ret_t ret = 0;
  2807. Md2 md2;
  2808. byte hash[MD2_DIGEST_SIZE];
  2809. testVector a, b, c, d, e, f, g;
  2810. testVector test_md2[7];
  2811. int times = sizeof(test_md2) / sizeof(testVector), i;
  2812. WOLFSSL_ENTER("md2_test");
  2813. a.input = "";
  2814. a.output = "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69"
  2815. "\x27\x73";
  2816. a.inLen = XSTRLEN(a.input);
  2817. a.outLen = MD2_DIGEST_SIZE;
  2818. b.input = "a";
  2819. b.output = "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0"
  2820. "\xb5\xd1";
  2821. b.inLen = XSTRLEN(b.input);
  2822. b.outLen = MD2_DIGEST_SIZE;
  2823. c.input = "abc";
  2824. c.output = "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde"
  2825. "\xd6\xbb";
  2826. c.inLen = XSTRLEN(c.input);
  2827. c.outLen = MD2_DIGEST_SIZE;
  2828. d.input = "message digest";
  2829. d.output = "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe"
  2830. "\x06\xb0";
  2831. d.inLen = XSTRLEN(d.input);
  2832. d.outLen = MD2_DIGEST_SIZE;
  2833. e.input = "abcdefghijklmnopqrstuvwxyz";
  2834. e.output = "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47"
  2835. "\x94\x0b";
  2836. e.inLen = XSTRLEN(e.input);
  2837. e.outLen = MD2_DIGEST_SIZE;
  2838. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2839. "6789";
  2840. f.output = "\xda\x33\xde\xf2\xa4\x2d\xf1\x39\x75\x35\x28\x46\xc3\x03"
  2841. "\x38\xcd";
  2842. f.inLen = XSTRLEN(f.input);
  2843. f.outLen = MD2_DIGEST_SIZE;
  2844. g.input = "1234567890123456789012345678901234567890123456789012345678"
  2845. "9012345678901234567890";
  2846. g.output = "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3"
  2847. "\xef\xd8";
  2848. g.inLen = XSTRLEN(g.input);
  2849. g.outLen = MD2_DIGEST_SIZE;
  2850. test_md2[0] = a;
  2851. test_md2[1] = b;
  2852. test_md2[2] = c;
  2853. test_md2[3] = d;
  2854. test_md2[4] = e;
  2855. test_md2[5] = f;
  2856. test_md2[6] = g;
  2857. wc_InitMd2(&md2);
  2858. for (i = 0; i < times; ++i) {
  2859. wc_Md2Update(&md2, (byte*)test_md2[i].input, (word32)test_md2[i].inLen);
  2860. wc_Md2Final(&md2, hash);
  2861. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0)
  2862. return WC_TEST_RET_ENC_I(i);
  2863. }
  2864. for (i = 0; i < times; ++i) {
  2865. ret = wc_Md2Hash((byte*)test_md2[i].input, (word32)test_md2[i].inLen, hash);
  2866. if (ret != 0) {
  2867. return WC_TEST_RET_ENC_I(i);
  2868. }
  2869. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) {
  2870. return WC_TEST_RET_ENC_I(i);
  2871. }
  2872. }
  2873. return 0;
  2874. }
  2875. #endif
  2876. #ifndef NO_MD5
  2877. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void)
  2878. {
  2879. wc_test_ret_t ret = 0;
  2880. wc_Md5 md5, md5Copy;
  2881. byte hash[WC_MD5_DIGEST_SIZE];
  2882. byte hashcopy[WC_MD5_DIGEST_SIZE];
  2883. testVector a, b, c, d, e, f;
  2884. testVector test_md5[6];
  2885. int times = sizeof(test_md5) / sizeof(testVector), i;
  2886. WOLFSSL_ENTER("md5_test");
  2887. a.input = "";
  2888. a.output = "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42"
  2889. "\x7e";
  2890. a.inLen = XSTRLEN(a.input);
  2891. a.outLen = WC_MD5_DIGEST_SIZE;
  2892. b.input = "abc";
  2893. b.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  2894. "\x72";
  2895. b.inLen = XSTRLEN(b.input);
  2896. b.outLen = WC_MD5_DIGEST_SIZE;
  2897. c.input = "message digest";
  2898. c.output = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
  2899. "\xd0";
  2900. c.inLen = XSTRLEN(c.input);
  2901. c.outLen = WC_MD5_DIGEST_SIZE;
  2902. d.input = "abcdefghijklmnopqrstuvwxyz";
  2903. d.output = "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
  2904. "\x3b";
  2905. d.inLen = XSTRLEN(d.input);
  2906. d.outLen = WC_MD5_DIGEST_SIZE;
  2907. e.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2908. "6789";
  2909. e.output = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
  2910. "\x9f";
  2911. e.inLen = XSTRLEN(e.input);
  2912. e.outLen = WC_MD5_DIGEST_SIZE;
  2913. f.input = "1234567890123456789012345678901234567890123456789012345678"
  2914. "9012345678901234567890";
  2915. f.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  2916. "\x7a";
  2917. f.inLen = XSTRLEN(f.input);
  2918. f.outLen = WC_MD5_DIGEST_SIZE;
  2919. test_md5[0] = a;
  2920. test_md5[1] = b;
  2921. test_md5[2] = c;
  2922. test_md5[3] = d;
  2923. test_md5[4] = e;
  2924. test_md5[5] = f;
  2925. ret = wc_InitMd5_ex(&md5, HEAP_HINT, devId);
  2926. if (ret != 0)
  2927. return WC_TEST_RET_ENC_EC(ret);
  2928. ret = wc_InitMd5_ex(&md5Copy, HEAP_HINT, devId);
  2929. if (ret != 0) {
  2930. wc_Md5Free(&md5);
  2931. return WC_TEST_RET_ENC_EC(ret);
  2932. }
  2933. for (i = 0; i < times; ++i) {
  2934. ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
  2935. (word32)test_md5[i].inLen);
  2936. if (ret != 0)
  2937. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2938. ret = wc_Md5GetHash(&md5, hashcopy);
  2939. if (ret != 0)
  2940. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2941. ret = wc_Md5Copy(&md5, &md5Copy);
  2942. if (ret != 0)
  2943. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2944. ret = wc_Md5Final(&md5, hash);
  2945. if (ret != 0)
  2946. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2947. wc_Md5Free(&md5Copy);
  2948. if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0)
  2949. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2950. if (XMEMCMP(hash, hashcopy, WC_MD5_DIGEST_SIZE) != 0)
  2951. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2952. }
  2953. #ifndef NO_LARGE_HASH_TEST
  2954. /* BEGIN LARGE HASH TEST */ {
  2955. byte large_input[1024];
  2956. const char* large_digest =
  2957. "\x44\xd0\x88\xce\xf1\x36\xd1\x78\xe9\xc8\xba\x84\xc3\xfd\xf6\xca";
  2958. for (i = 0; i < (int)sizeof(large_input); i++) {
  2959. large_input[i] = (byte)(i & 0xFF);
  2960. }
  2961. times = 100;
  2962. #ifdef WOLFSSL_PIC32MZ_HASH
  2963. wc_Md5SizeSet(&md5, times * sizeof(large_input));
  2964. #endif
  2965. for (i = 0; i < times; ++i) {
  2966. ret = wc_Md5Update(&md5, (byte*)large_input,
  2967. (word32)sizeof(large_input));
  2968. if (ret != 0)
  2969. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2970. }
  2971. ret = wc_Md5Final(&md5, hash);
  2972. if (ret != 0)
  2973. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2974. if (XMEMCMP(hash, large_digest, WC_MD5_DIGEST_SIZE) != 0)
  2975. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  2976. } /* END LARGE HASH TEST */
  2977. #endif /* NO_LARGE_HASH_TEST */
  2978. exit:
  2979. wc_Md5Free(&md5);
  2980. wc_Md5Free(&md5Copy);
  2981. return ret;
  2982. }
  2983. #endif /* NO_MD5 */
  2984. #ifndef NO_MD4
  2985. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void)
  2986. {
  2987. Md4 md4;
  2988. byte hash[MD4_DIGEST_SIZE];
  2989. testVector a, b, c, d, e, f, g;
  2990. testVector test_md4[7];
  2991. int times = sizeof(test_md4) / sizeof(testVector), i;
  2992. WOLFSSL_ENTER("md4_test");
  2993. a.input = "";
  2994. a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
  2995. "\xc0";
  2996. a.inLen = XSTRLEN(a.input);
  2997. a.outLen = MD4_DIGEST_SIZE;
  2998. b.input = "a";
  2999. b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
  3000. "\x24";
  3001. b.inLen = XSTRLEN(b.input);
  3002. b.outLen = MD4_DIGEST_SIZE;
  3003. c.input = "abc";
  3004. c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
  3005. "\x9d";
  3006. c.inLen = XSTRLEN(c.input);
  3007. c.outLen = MD4_DIGEST_SIZE;
  3008. d.input = "message digest";
  3009. d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
  3010. "\x4b";
  3011. d.inLen = XSTRLEN(d.input);
  3012. d.outLen = MD4_DIGEST_SIZE;
  3013. e.input = "abcdefghijklmnopqrstuvwxyz";
  3014. e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
  3015. "\xa9";
  3016. e.inLen = XSTRLEN(e.input);
  3017. e.outLen = MD4_DIGEST_SIZE;
  3018. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  3019. "6789";
  3020. f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
  3021. "\xe4";
  3022. f.inLen = XSTRLEN(f.input);
  3023. f.outLen = MD4_DIGEST_SIZE;
  3024. g.input = "1234567890123456789012345678901234567890123456789012345678"
  3025. "9012345678901234567890";
  3026. g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
  3027. "\x36";
  3028. g.inLen = XSTRLEN(g.input);
  3029. g.outLen = MD4_DIGEST_SIZE;
  3030. test_md4[0] = a;
  3031. test_md4[1] = b;
  3032. test_md4[2] = c;
  3033. test_md4[3] = d;
  3034. test_md4[4] = e;
  3035. test_md4[5] = f;
  3036. test_md4[6] = g;
  3037. wc_InitMd4(&md4);
  3038. for (i = 0; i < times; ++i) {
  3039. wc_Md4Update(&md4, (byte*)test_md4[i].input, (word32)test_md4[i].inLen);
  3040. wc_Md4Final(&md4, hash);
  3041. if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0)
  3042. return WC_TEST_RET_ENC_I(i);
  3043. }
  3044. return 0;
  3045. }
  3046. #endif /* NO_MD4 */
  3047. #ifndef NO_SHA
  3048. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void)
  3049. {
  3050. wc_test_ret_t ret = 0;
  3051. wc_Sha sha, shaCopy;
  3052. byte hash[WC_SHA_DIGEST_SIZE];
  3053. byte hashcopy[WC_SHA_DIGEST_SIZE];
  3054. testVector a, b, c, d, e;
  3055. testVector test_sha[5];
  3056. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3057. WOLFSSL_ENTER("sha_test");
  3058. a.input = "";
  3059. a.output = "\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18"
  3060. "\x90\xaf\xd8\x07\x09";
  3061. a.inLen = XSTRLEN(a.input);
  3062. a.outLen = WC_SHA_DIGEST_SIZE;
  3063. b.input = "abc";
  3064. b.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  3065. "\x6C\x9C\xD0\xD8\x9D";
  3066. b.inLen = XSTRLEN(b.input);
  3067. b.outLen = WC_SHA_DIGEST_SIZE;
  3068. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3069. c.output = "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
  3070. "\xE5\xE5\x46\x70\xF1";
  3071. c.inLen = XSTRLEN(c.input);
  3072. c.outLen = WC_SHA_DIGEST_SIZE;
  3073. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3074. "aaaaaa";
  3075. d.output = "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
  3076. "\x2A\x25\xEC\x64\x4D";
  3077. d.inLen = XSTRLEN(d.input);
  3078. d.outLen = WC_SHA_DIGEST_SIZE;
  3079. e.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3080. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3081. "aaaaaaaaaa";
  3082. e.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  3083. "\x53\x99\x5E\x26\xA0";
  3084. e.inLen = XSTRLEN(e.input);
  3085. e.outLen = WC_SHA_DIGEST_SIZE;
  3086. test_sha[0] = a;
  3087. test_sha[1] = b;
  3088. test_sha[2] = c;
  3089. test_sha[3] = d;
  3090. test_sha[4] = e;
  3091. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  3092. if (ret != 0)
  3093. return WC_TEST_RET_ENC_EC(ret);
  3094. ret = wc_InitSha_ex(&shaCopy, HEAP_HINT, devId);
  3095. if (ret != 0) {
  3096. wc_ShaFree(&sha);
  3097. return WC_TEST_RET_ENC_EC(ret);
  3098. }
  3099. for (i = 0; i < times; ++i) {
  3100. ret = wc_ShaUpdate(&sha, (byte*)test_sha[i].input,
  3101. (word32)test_sha[i].inLen);
  3102. if (ret != 0)
  3103. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3104. ret = wc_ShaGetHash(&sha, hashcopy);
  3105. if (ret != 0)
  3106. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3107. ret = wc_ShaCopy(&sha, &shaCopy);
  3108. if (ret != 0)
  3109. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3110. ret = wc_ShaFinal(&sha, hash);
  3111. if (ret != 0)
  3112. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3113. wc_ShaFree(&shaCopy);
  3114. if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0)
  3115. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3116. if (XMEMCMP(hash, hashcopy, WC_SHA_DIGEST_SIZE) != 0)
  3117. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3118. }
  3119. #ifndef NO_LARGE_HASH_TEST
  3120. /* BEGIN LARGE HASH TEST */ {
  3121. byte large_input[1024];
  3122. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3123. defined(HASH_SIZE_LIMIT)
  3124. const char* large_digest =
  3125. "\x1d\x6a\x5a\xf6\xe5\x7c\x86\xce\x7f\x7c\xaf\xd5\xdb\x08\xcd\x59"
  3126. "\x15\x8c\x6d\xb6";
  3127. #else
  3128. const char* large_digest =
  3129. "\x8b\x77\x02\x48\x39\xe8\xdb\xd3\x9a\xf4\x05\x24\x66\x12\x2d\x9e"
  3130. "\xc5\xd9\x0a\xac";
  3131. #endif
  3132. for (i = 0; i < (int)sizeof(large_input); i++) {
  3133. large_input[i] = (byte)(i & 0xFF);
  3134. }
  3135. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3136. defined(HASH_SIZE_LIMIT)
  3137. times = 20;
  3138. #else
  3139. times = 100;
  3140. #endif
  3141. #ifdef WOLFSSL_PIC32MZ_HASH
  3142. wc_ShaSizeSet(&sha, times * sizeof(large_input));
  3143. #endif
  3144. for (i = 0; i < times; ++i) {
  3145. ret = wc_ShaUpdate(&sha, (byte*)large_input,
  3146. (word32)sizeof(large_input));
  3147. if (ret != 0)
  3148. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3149. }
  3150. ret = wc_ShaFinal(&sha, hash);
  3151. if (ret != 0)
  3152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3153. if (XMEMCMP(hash, large_digest, WC_SHA_DIGEST_SIZE) != 0)
  3154. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3155. } /* END LARGE HASH TEST */
  3156. #endif /* NO_LARGE_HASH_TEST */
  3157. exit:
  3158. wc_ShaFree(&sha);
  3159. wc_ShaFree(&shaCopy);
  3160. return ret;
  3161. }
  3162. #endif /* NO_SHA */
  3163. #ifdef WOLFSSL_RIPEMD
  3164. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void)
  3165. {
  3166. RipeMd ripemd;
  3167. wc_test_ret_t ret;
  3168. byte hash[RIPEMD_DIGEST_SIZE];
  3169. testVector a, b, c, d;
  3170. testVector test_ripemd[4];
  3171. int times = sizeof(test_ripemd) / sizeof(struct testVector), i;
  3172. WOLFSSL_ENTER("ripemd_test");
  3173. a.input = "abc";
  3174. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  3175. "\xb0\x87\xf1\x5a\x0b\xfc";
  3176. a.inLen = XSTRLEN(a.input);
  3177. a.outLen = RIPEMD_DIGEST_SIZE;
  3178. b.input = "message digest";
  3179. b.output = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
  3180. "\x5f\xfa\x21\x59\x5f\x36";
  3181. b.inLen = XSTRLEN(b.input);
  3182. b.outLen = RIPEMD_DIGEST_SIZE;
  3183. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3184. c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
  3185. "\xf4\x9a\xda\x62\xeb\x2b";
  3186. c.inLen = XSTRLEN(c.input);
  3187. c.outLen = RIPEMD_DIGEST_SIZE;
  3188. d.input = "12345678901234567890123456789012345678901234567890123456"
  3189. "789012345678901234567890";
  3190. d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
  3191. "\x82\xbf\x63\x32\x6b\xfb";
  3192. d.inLen = XSTRLEN(d.input);
  3193. d.outLen = RIPEMD_DIGEST_SIZE;
  3194. test_ripemd[0] = a;
  3195. test_ripemd[1] = b;
  3196. test_ripemd[2] = c;
  3197. test_ripemd[3] = d;
  3198. ret = wc_InitRipeMd(&ripemd);
  3199. if (ret != 0) {
  3200. return WC_TEST_RET_ENC_EC(ret);
  3201. }
  3202. for (i = 0; i < times; ++i) {
  3203. ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
  3204. (word32)test_ripemd[i].inLen);
  3205. if (ret != 0) {
  3206. return WC_TEST_RET_ENC_I(i);
  3207. }
  3208. ret = wc_RipeMdFinal(&ripemd, hash);
  3209. if (ret != 0) {
  3210. return WC_TEST_RET_ENC_I(i);
  3211. }
  3212. if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
  3213. return WC_TEST_RET_ENC_I(i);
  3214. }
  3215. return 0;
  3216. }
  3217. #endif /* WOLFSSL_RIPEMD */
  3218. #ifdef HAVE_BLAKE2
  3219. #define BLAKE2B_TESTS 3
  3220. static const byte blake2b_vec[BLAKE2B_TESTS][BLAKE2B_OUTBYTES] =
  3221. {
  3222. {
  3223. 0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
  3224. 0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
  3225. 0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61,
  3226. 0x8A, 0x86, 0xE2, 0x17, 0xF7, 0x1F, 0x54, 0x19,
  3227. 0xD2, 0x5E, 0x10, 0x31, 0xAF, 0xEE, 0x58, 0x53,
  3228. 0x13, 0x89, 0x64, 0x44, 0x93, 0x4E, 0xB0, 0x4B,
  3229. 0x90, 0x3A, 0x68, 0x5B, 0x14, 0x48, 0xB7, 0x55,
  3230. 0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
  3231. },
  3232. {
  3233. 0x2F, 0xA3, 0xF6, 0x86, 0xDF, 0x87, 0x69, 0x95,
  3234. 0x16, 0x7E, 0x7C, 0x2E, 0x5D, 0x74, 0xC4, 0xC7,
  3235. 0xB6, 0xE4, 0x8F, 0x80, 0x68, 0xFE, 0x0E, 0x44,
  3236. 0x20, 0x83, 0x44, 0xD4, 0x80, 0xF7, 0x90, 0x4C,
  3237. 0x36, 0x96, 0x3E, 0x44, 0x11, 0x5F, 0xE3, 0xEB,
  3238. 0x2A, 0x3A, 0xC8, 0x69, 0x4C, 0x28, 0xBC, 0xB4,
  3239. 0xF5, 0xA0, 0xF3, 0x27, 0x6F, 0x2E, 0x79, 0x48,
  3240. 0x7D, 0x82, 0x19, 0x05, 0x7A, 0x50, 0x6E, 0x4B
  3241. },
  3242. {
  3243. 0x1C, 0x08, 0x79, 0x8D, 0xC6, 0x41, 0xAB, 0xA9,
  3244. 0xDE, 0xE4, 0x35, 0xE2, 0x25, 0x19, 0xA4, 0x72,
  3245. 0x9A, 0x09, 0xB2, 0xBF, 0xE0, 0xFF, 0x00, 0xEF,
  3246. 0x2D, 0xCD, 0x8E, 0xD6, 0xF8, 0xA0, 0x7D, 0x15,
  3247. 0xEA, 0xF4, 0xAE, 0xE5, 0x2B, 0xBF, 0x18, 0xAB,
  3248. 0x56, 0x08, 0xA6, 0x19, 0x0F, 0x70, 0xB9, 0x04,
  3249. 0x86, 0xC8, 0xA7, 0xD4, 0x87, 0x37, 0x10, 0xB1,
  3250. 0x11, 0x5D, 0x3D, 0xEB, 0xBB, 0x43, 0x27, 0xB5
  3251. }
  3252. };
  3253. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void)
  3254. {
  3255. Blake2b b2b;
  3256. byte digest[64];
  3257. byte input[64];
  3258. int i, ret;
  3259. WOLFSSL_ENTER("blake2b_test");
  3260. for (i = 0; i < (int)sizeof(input); i++)
  3261. input[i] = (byte)i;
  3262. for (i = 0; i < BLAKE2B_TESTS; i++) {
  3263. ret = wc_InitBlake2b(&b2b, 64);
  3264. if (ret != 0)
  3265. return WC_TEST_RET_ENC_I(i);
  3266. ret = wc_Blake2bUpdate(&b2b, input, (word32)i);
  3267. if (ret != 0)
  3268. return WC_TEST_RET_ENC_I(i);
  3269. ret = wc_Blake2bFinal(&b2b, digest, 64);
  3270. if (ret != 0)
  3271. return WC_TEST_RET_ENC_I(i);
  3272. if (XMEMCMP(digest, blake2b_vec[i], 64) != 0) {
  3273. return WC_TEST_RET_ENC_I(i);
  3274. }
  3275. }
  3276. return 0;
  3277. }
  3278. #endif /* HAVE_BLAKE2 */
  3279. #ifdef HAVE_BLAKE2S
  3280. #define BLAKE2S_TESTS 3
  3281. static const byte blake2s_vec[BLAKE2S_TESTS][BLAKE2S_OUTBYTES] =
  3282. {
  3283. {
  3284. 0x69, 0x21, 0x7a, 0x30, 0x79, 0x90, 0x80, 0x94,
  3285. 0xe1, 0x11, 0x21, 0xd0, 0x42, 0x35, 0x4a, 0x7c,
  3286. 0x1f, 0x55, 0xb6, 0x48, 0x2c, 0xa1, 0xa5, 0x1e,
  3287. 0x1b, 0x25, 0x0d, 0xfd, 0x1e, 0xd0, 0xee, 0xf9,
  3288. },
  3289. {
  3290. 0xe3, 0x4d, 0x74, 0xdb, 0xaf, 0x4f, 0xf4, 0xc6,
  3291. 0xab, 0xd8, 0x71, 0xcc, 0x22, 0x04, 0x51, 0xd2,
  3292. 0xea, 0x26, 0x48, 0x84, 0x6c, 0x77, 0x57, 0xfb,
  3293. 0xaa, 0xc8, 0x2f, 0xe5, 0x1a, 0xd6, 0x4b, 0xea,
  3294. },
  3295. {
  3296. 0xdd, 0xad, 0x9a, 0xb1, 0x5d, 0xac, 0x45, 0x49,
  3297. 0xba, 0x42, 0xf4, 0x9d, 0x26, 0x24, 0x96, 0xbe,
  3298. 0xf6, 0xc0, 0xba, 0xe1, 0xdd, 0x34, 0x2a, 0x88,
  3299. 0x08, 0xf8, 0xea, 0x26, 0x7c, 0x6e, 0x21, 0x0c,
  3300. }
  3301. };
  3302. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void)
  3303. {
  3304. Blake2s b2s;
  3305. byte digest[32];
  3306. byte input[64];
  3307. int i, ret;
  3308. WOLFSSL_ENTER("blake2s_test");
  3309. for (i = 0; i < (int)sizeof(input); i++)
  3310. input[i] = (byte)i;
  3311. for (i = 0; i < BLAKE2S_TESTS; i++) {
  3312. ret = wc_InitBlake2s(&b2s, 32);
  3313. if (ret != 0)
  3314. return WC_TEST_RET_ENC_I(i);
  3315. ret = wc_Blake2sUpdate(&b2s, input, (word32)i);
  3316. if (ret != 0)
  3317. return WC_TEST_RET_ENC_I(i);
  3318. ret = wc_Blake2sFinal(&b2s, digest, 32);
  3319. if (ret != 0)
  3320. return WC_TEST_RET_ENC_I(i);
  3321. if (XMEMCMP(digest, blake2s_vec[i], 32) != 0) {
  3322. return WC_TEST_RET_ENC_I(i);
  3323. }
  3324. }
  3325. return 0;
  3326. }
  3327. #endif /* HAVE_BLAKE2S */
  3328. #ifdef WOLFSSL_SHA224
  3329. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void)
  3330. {
  3331. wc_Sha224 sha, shaCopy;
  3332. byte hash[WC_SHA224_DIGEST_SIZE];
  3333. byte hashcopy[WC_SHA224_DIGEST_SIZE];
  3334. wc_test_ret_t ret = 0;
  3335. testVector a, b, c;
  3336. testVector test_sha[3];
  3337. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3338. WOLFSSL_ENTER("sha224_test");
  3339. a.input = "";
  3340. a.output = "\xd1\x4a\x02\x8c\x2a\x3a\x2b\xc9\x47\x61\x02\xbb\x28\x82\x34"
  3341. "\xc4\x15\xa2\xb0\x1f\x82\x8e\xa6\x2a\xc5\xb3\xe4\x2f";
  3342. a.inLen = XSTRLEN(a.input);
  3343. a.outLen = WC_SHA224_DIGEST_SIZE;
  3344. b.input = "abc";
  3345. b.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55"
  3346. "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  3347. b.inLen = XSTRLEN(b.input);
  3348. b.outLen = WC_SHA224_DIGEST_SIZE;
  3349. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3350. c.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  3351. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  3352. c.inLen = XSTRLEN(c.input);
  3353. c.outLen = WC_SHA224_DIGEST_SIZE;
  3354. test_sha[0] = a;
  3355. test_sha[1] = b;
  3356. test_sha[2] = c;
  3357. ret = wc_InitSha224_ex(&sha, HEAP_HINT, devId);
  3358. if (ret != 0)
  3359. return WC_TEST_RET_ENC_EC(ret);
  3360. ret = wc_InitSha224_ex(&shaCopy, HEAP_HINT, devId);
  3361. if (ret != 0) {
  3362. wc_Sha224Free(&sha);
  3363. return WC_TEST_RET_ENC_EC(ret);
  3364. }
  3365. for (i = 0; i < times; ++i) {
  3366. ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,
  3367. (word32)test_sha[i].inLen);
  3368. if (ret != 0)
  3369. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3370. ret = wc_Sha224GetHash(&sha, hashcopy);
  3371. if (ret != 0)
  3372. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3373. ret = wc_Sha224Copy(&sha, &shaCopy);
  3374. if (ret != 0)
  3375. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3376. ret = wc_Sha224Final(&sha, hash);
  3377. if (ret != 0)
  3378. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3379. wc_Sha224Free(&shaCopy);
  3380. if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  3381. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3382. if (XMEMCMP(hash, hashcopy, WC_SHA224_DIGEST_SIZE) != 0)
  3383. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3384. }
  3385. exit:
  3386. wc_Sha224Free(&sha);
  3387. wc_Sha224Free(&shaCopy);
  3388. return ret;
  3389. }
  3390. #endif
  3391. #ifndef NO_SHA256
  3392. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
  3393. {
  3394. wc_Sha256 sha, shaCopy;
  3395. byte hash[WC_SHA256_DIGEST_SIZE];
  3396. byte hashcopy[WC_SHA256_DIGEST_SIZE];
  3397. wc_test_ret_t ret = 0;
  3398. testVector a, b, c, d;
  3399. testVector test_sha[4];
  3400. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3401. byte i_hash[WC_SHA256_DIGEST_SIZE];
  3402. byte i_hashcopy[WC_SHA256_DIGEST_SIZE];
  3403. testVector interleave_test_sha[4];
  3404. wc_Sha256 i_sha, i_shaCopy;
  3405. #endif
  3406. #ifndef NO_LARGE_HASH_TEST
  3407. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3408. #ifdef WOLFSSL_SMALL_STACK
  3409. byte *large_input = NULL;
  3410. #else
  3411. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3412. #endif
  3413. #endif
  3414. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3415. WOLFSSL_ENTER("sha256_test");
  3416. a.input = "";
  3417. a.output = "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9"
  3418. "\x24\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52"
  3419. "\xb8\x55";
  3420. a.inLen = XSTRLEN(a.input);
  3421. a.outLen = WC_SHA256_DIGEST_SIZE;
  3422. b.input = "abc";
  3423. b.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  3424. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  3425. "\x15\xAD";
  3426. b.inLen = XSTRLEN(b.input);
  3427. b.outLen = WC_SHA256_DIGEST_SIZE;
  3428. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3429. c.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  3430. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  3431. "\x06\xC1";
  3432. c.inLen = XSTRLEN(c.input);
  3433. c.outLen = WC_SHA256_DIGEST_SIZE;
  3434. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3435. "aaaaaa"; /* this is BLOCKSIZE length */
  3436. d.output = "\xFF\xE0\x54\xFE\x7A\xE0\xCB\x6D\xC6\x5C\x3A\xF9\xB6\x1D\x52"
  3437. "\x09\xF4\x39\x85\x1D\xB4\x3D\x0B\xA5\x99\x73\x37\xDF\x15\x46"
  3438. "\x68\xEB";
  3439. d.inLen = XSTRLEN(d.input);
  3440. d.outLen = WC_SHA256_DIGEST_SIZE;
  3441. test_sha[0] = a;
  3442. test_sha[1] = b;
  3443. test_sha[2] = c;
  3444. test_sha[3] = d;
  3445. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3446. interleave_test_sha[0] = a;
  3447. interleave_test_sha[1] = b;
  3448. interleave_test_sha[2] = c;
  3449. interleave_test_sha[3] = d;
  3450. #endif
  3451. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  3452. if (ret != 0)
  3453. return WC_TEST_RET_ENC_EC(ret);
  3454. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3455. ret = wc_InitSha256_ex(&i_sha, HEAP_HINT, devId);
  3456. if (ret != 0)
  3457. return WC_TEST_RET_ENC_EC(ret);
  3458. #endif
  3459. ret = wc_InitSha256_ex(&shaCopy, HEAP_HINT, devId);
  3460. if (ret != 0) {
  3461. wc_Sha256Free(&sha);
  3462. return WC_TEST_RET_ENC_EC(ret);
  3463. }
  3464. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3465. ret = wc_InitSha256_ex(&i_shaCopy, HEAP_HINT, devId);
  3466. if (ret != 0) {
  3467. wc_Sha256Free(&sha);
  3468. wc_Sha256Free(&i_sha);
  3469. return WC_TEST_RET_ENC_EC(ret);
  3470. }
  3471. #endif
  3472. for (i = 0; i < times; ++i) {
  3473. ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input,
  3474. (word32)test_sha[i].inLen);
  3475. if (ret != 0) {
  3476. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3477. }
  3478. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3479. ret = wc_Sha256Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3480. (word32)interleave_test_sha[i].inLen);
  3481. if (ret != 0) {
  3482. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3483. }
  3484. #endif
  3485. ret = wc_Sha256GetHash(&sha, hashcopy);
  3486. if (ret != 0)
  3487. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3488. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3489. ret = wc_Sha256GetHash(&i_sha, i_hashcopy);
  3490. if (ret != 0)
  3491. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3492. #endif
  3493. ret = wc_Sha256Copy(&sha, &shaCopy);
  3494. if (ret != 0)
  3495. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3496. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3497. ret = wc_Sha256Copy(&i_sha, &i_shaCopy);
  3498. if (ret != 0)
  3499. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3500. #endif
  3501. ret = wc_Sha256Final(&sha, hash);
  3502. if (ret != 0)
  3503. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3504. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3505. ret = wc_Sha256Final(&i_sha, i_hash);
  3506. if (ret != 0)
  3507. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3508. #endif
  3509. wc_Sha256Free(&shaCopy);
  3510. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3511. wc_Sha256Free(&i_shaCopy);
  3512. #endif
  3513. if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3514. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3515. }
  3516. if (XMEMCMP(hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3517. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3518. }
  3519. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3520. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3521. WC_SHA256_DIGEST_SIZE) != 0) {
  3522. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3523. }
  3524. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3525. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3526. }
  3527. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3528. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3529. }
  3530. if (XMEMCMP(i_hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3531. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3532. }
  3533. #endif
  3534. }
  3535. #ifndef NO_LARGE_HASH_TEST
  3536. /* BEGIN LARGE HASH TEST */ {
  3537. #ifdef HASH_SIZE_LIMIT
  3538. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3539. "\xa4\x75\x9e\x7a\xa2\x03\x38\x32\x88\x66\xa2\xea\x17\xea\xf8\xc7"
  3540. "\xfe\x4e\xc6\xbb\xe3\xbb\x71\xce\xe7\xdf\x7c\x04\x61\xb3\xc2\x2f";
  3541. #else
  3542. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3543. "\x27\x78\x3e\x87\x96\x3a\x4e\xfb\x68\x29\xb5\x31\xc9\xba\x57\xb4"
  3544. "\x4f\x45\x79\x7f\x67\x70\xbd\x63\x7f\xbf\x0d\x80\x7c\xbd\xba\xe0";
  3545. #endif
  3546. #ifdef WOLFSSL_SMALL_STACK
  3547. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3548. DYNAMIC_TYPE_TMP_BUFFER);
  3549. if (large_input == NULL) {
  3550. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3551. }
  3552. #endif
  3553. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3554. large_input[i] = (byte)(i & 0xFF);
  3555. }
  3556. #ifdef HASH_SIZE_LIMIT
  3557. times = 20;
  3558. #else
  3559. times = 100;
  3560. #endif
  3561. #ifdef WOLFSSL_PIC32MZ_HASH
  3562. wc_Sha256SizeSet(&sha, times * LARGE_HASH_TEST_INPUT_SZ);
  3563. #endif
  3564. for (i = 0; i < times; ++i) {
  3565. ret = wc_Sha256Update(&sha, (byte*)large_input,
  3566. LARGE_HASH_TEST_INPUT_SZ);
  3567. if (ret != 0)
  3568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3569. }
  3570. ret = wc_Sha256Final(&sha, hash);
  3571. if (ret != 0)
  3572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3573. if (XMEMCMP(hash, large_digest, WC_SHA256_DIGEST_SIZE) != 0)
  3574. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3575. } /* END LARGE HASH TEST */
  3576. #undef LARGE_HASH_TEST_INPUT_SZ
  3577. #endif /* NO_LARGE_HASH_TEST */
  3578. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_FULL_HASH)
  3579. {
  3580. WOLFSSL_SMALL_STACK_STATIC const unsigned char
  3581. data_hb[WC_SHA256_BLOCK_SIZE] = {
  3582. 0x61, 0x62, 0x63, 0x80, 0x00, 0x00, 0x00, 0x00,
  3583. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3584. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3585. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3586. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3587. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3588. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3589. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18
  3590. };
  3591. ret = wc_Sha256HashBlock(&sha, data_hb, hash);
  3592. if (ret != 0) {
  3593. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3594. }
  3595. if (XMEMCMP(hash, b.output, WC_SHA256_DIGEST_SIZE) != 0) {
  3596. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3597. }
  3598. }
  3599. #endif
  3600. exit:
  3601. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3602. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3603. #endif
  3604. wc_Sha256Free(&sha);
  3605. wc_Sha256Free(&shaCopy);
  3606. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3607. wc_Sha256Free(&i_sha);
  3608. wc_Sha256Free(&i_shaCopy);
  3609. #endif
  3610. return ret;
  3611. }
  3612. #endif
  3613. #ifdef WOLFSSL_SHA512
  3614. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
  3615. {
  3616. /*
  3617. ** See https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf
  3618. */
  3619. wc_Sha512 sha, shaCopy;
  3620. byte hash[WC_SHA512_DIGEST_SIZE];
  3621. byte hashcopy[WC_SHA512_DIGEST_SIZE];
  3622. wc_test_ret_t ret = 0;
  3623. testVector a, b, c;
  3624. testVector test_sha[3];
  3625. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3626. wc_Sha512 i_sha, i_shaCopy;
  3627. byte i_hash[WC_SHA512_DIGEST_SIZE];
  3628. byte i_hashcopy[WC_SHA512_DIGEST_SIZE];
  3629. testVector interleave_test_sha[3];
  3630. #endif
  3631. #ifndef NO_LARGE_HASH_TEST
  3632. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3633. #ifdef WOLFSSL_SMALL_STACK
  3634. byte *large_input = NULL;
  3635. #else
  3636. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3637. #endif
  3638. #endif
  3639. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3640. WOLFSSL_ENTER("sha512_test");
  3641. a.input = "";
  3642. a.output = "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80"
  3643. "\x07\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c"
  3644. "\xe9\xce\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87"
  3645. "\x7e\xec\x2f\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a"
  3646. "\xf9\x27\xda\x3e";
  3647. a.inLen = XSTRLEN(a.input);
  3648. a.outLen = WC_SHA512_DIGEST_SIZE;
  3649. b.input = "abc";
  3650. b.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  3651. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  3652. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  3653. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  3654. "\xa5\x4c\xa4\x9f";
  3655. b.inLen = XSTRLEN(b.input);
  3656. b.outLen = WC_SHA512_DIGEST_SIZE;
  3657. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3658. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3659. c.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  3660. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  3661. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  3662. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  3663. "\x87\x4b\xe9\x09";
  3664. c.inLen = XSTRLEN(c.input);
  3665. c.outLen = WC_SHA512_DIGEST_SIZE;
  3666. test_sha[0] = a;
  3667. test_sha[1] = b;
  3668. test_sha[2] = c;
  3669. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3670. interleave_test_sha[0] = a;
  3671. interleave_test_sha[1] = b;
  3672. interleave_test_sha[2] = c;
  3673. #endif
  3674. ret = wc_InitSha512_ex(&sha, HEAP_HINT, devId);
  3675. if (ret != 0)
  3676. return WC_TEST_RET_ENC_EC(ret);
  3677. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3678. ret = wc_InitSha512_ex(&i_sha, HEAP_HINT, devId);
  3679. if (ret != 0)
  3680. return WC_TEST_RET_ENC_EC(ret);
  3681. #endif
  3682. ret = wc_InitSha512_ex(&shaCopy, HEAP_HINT, devId);
  3683. if (ret != 0) {
  3684. wc_Sha512Free(&sha);
  3685. return WC_TEST_RET_ENC_EC(ret);
  3686. }
  3687. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3688. ret = wc_InitSha512_ex(&i_shaCopy, HEAP_HINT, devId);
  3689. if (ret != 0) {
  3690. wc_Sha512Free(&sha);
  3691. wc_Sha512Free(&i_sha);
  3692. return WC_TEST_RET_ENC_EC(ret);
  3693. }
  3694. #endif
  3695. for (i = 0; i < times; ++i) {
  3696. ret = wc_Sha512Update(&sha, (byte*)test_sha[i].input,
  3697. (word32)test_sha[i].inLen);
  3698. if (ret != 0)
  3699. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3700. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3701. ret = wc_Sha512Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3702. (word32)interleave_test_sha[i].inLen);
  3703. if (ret != 0)
  3704. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3705. #endif
  3706. ret = wc_Sha512GetHash(&sha, hashcopy);
  3707. if (ret != 0)
  3708. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3709. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3710. ret = wc_Sha512GetHash(&i_sha, i_hashcopy);
  3711. if (ret != 0)
  3712. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3713. #endif
  3714. ret = wc_Sha512Copy(&sha, &shaCopy);
  3715. if (ret != 0)
  3716. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3717. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3718. ret = wc_Sha512Copy(&i_sha, &i_shaCopy);
  3719. if (ret != 0)
  3720. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3721. #endif
  3722. ret = wc_Sha512Final(&sha, hash);
  3723. if (ret != 0)
  3724. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3725. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3726. ret = wc_Sha512Final(&i_sha, i_hash);
  3727. if (ret != 0)
  3728. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3729. #endif
  3730. wc_Sha512Free(&shaCopy);
  3731. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3732. wc_Sha512Free(&i_shaCopy);
  3733. #endif
  3734. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  3735. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3736. if (XMEMCMP(hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0)
  3737. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3738. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3739. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3740. WC_SHA512_DIGEST_SIZE) != 0) {
  3741. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3742. }
  3743. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3744. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3745. }
  3746. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0) {
  3747. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3748. }
  3749. if (XMEMCMP(i_hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3750. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3751. }
  3752. #endif
  3753. }
  3754. #ifndef NO_LARGE_HASH_TEST
  3755. /* BEGIN LARGE HASH TEST */ {
  3756. #ifdef HASH_SIZE_LIMIT
  3757. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3758. "\x30\x9B\x96\xA6\xE9\x43\x78\x30\xA3\x71\x51\x61\xC1\xEB\xE1\xBE"
  3759. "\xC8\xA5\xF9\x13\x5A\xD6\x6D\x9E\x46\x31\x31\x67\x8D\xE2\xC0\x0B"
  3760. "\x2A\x1A\x03\xE1\xF3\x48\xA7\x33\xBD\x49\xF8\xFF\xF1\xC2\xC2\x95"
  3761. "\xCB\xF0\xAF\x87\x61\x85\x58\x63\x6A\xCA\x70\x9C\x8B\x83\x3F\x5D";
  3762. #else
  3763. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3764. "\x5a\x1f\x73\x90\xbd\x8c\xe4\x63\x54\xce\xa0\x9b\xef\x32\x78\x2d"
  3765. "\x2e\xe7\x0d\x5e\x2f\x9d\x15\x1b\xdd\x2d\xde\x65\x0c\x7b\xfa\x83"
  3766. "\x5e\x80\x02\x13\x84\xb8\x3f\xff\x71\x62\xb5\x09\x89\x63\xe1\xdc"
  3767. "\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
  3768. #endif
  3769. #ifdef WOLFSSL_SMALL_STACK
  3770. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3771. DYNAMIC_TYPE_TMP_BUFFER);
  3772. if (large_input == NULL) {
  3773. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3774. }
  3775. #endif
  3776. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3777. large_input[i] = (byte)(i & 0xFF);
  3778. }
  3779. #ifdef HASH_SIZE_LIMIT
  3780. times = 20;
  3781. #else
  3782. times = 100;
  3783. #endif
  3784. for (i = 0; i < times; ++i) {
  3785. ret = wc_Sha512Update(&sha, (byte*)large_input,
  3786. LARGE_HASH_TEST_INPUT_SZ);
  3787. if (ret != 0)
  3788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3789. }
  3790. ret = wc_Sha512Final(&sha, hash);
  3791. if (ret != 0)
  3792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3793. if (XMEMCMP(hash, large_digest, WC_SHA512_DIGEST_SIZE) != 0)
  3794. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3795. #ifndef NO_UNALIGNED_MEMORY_TEST
  3796. /* Unaligned memory access test */
  3797. for (i = 1; i < 16; i++) {
  3798. ret = wc_Sha512Update(&sha, (byte*)large_input + i,
  3799. LARGE_HASH_TEST_INPUT_SZ - (word32)i);
  3800. if (ret != 0)
  3801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3802. ret = wc_Sha512Final(&sha, hash);
  3803. }
  3804. #endif
  3805. } /* END LARGE HASH TEST */
  3806. #undef LARGE_HASH_TEST_INPUT_SZ
  3807. #endif /* NO_LARGE_HASH_TEST */
  3808. exit:
  3809. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3810. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3811. #endif
  3812. wc_Sha512Free(&sha);
  3813. wc_Sha512Free(&shaCopy);
  3814. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3815. wc_Sha512Free(&i_sha);
  3816. wc_Sha512Free(&i_shaCopy);
  3817. #endif
  3818. return ret;
  3819. }
  3820. #if !defined(WOLFSSL_NOSHA512_224) && \
  3821. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3822. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void)
  3823. {
  3824. /*
  3825. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3826. **
  3827. ** NIST SHA512/224 Document Example:
  3828. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_224.pdf
  3829. */
  3830. wc_Sha512 sha, shaCopy;
  3831. byte hash[WC_SHA512_224_DIGEST_SIZE];
  3832. byte hashcopy[WC_SHA512_224_DIGEST_SIZE];
  3833. wc_test_ret_t ret = 0;
  3834. testVector a, b, c;
  3835. testVector test_sha[3];
  3836. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3837. WOLFSSL_ENTER("sha512_224_test");
  3838. a.input = "";
  3839. a.output = "\x6e\xd0\xdd\x02"
  3840. "\x80\x6f\xa8\x9e" "\x25\xde\x06\x0c"
  3841. "\x19\xd3\xac\x86" "\xca\xbb\x87\xd6"
  3842. "\xa0\xdd\xd0\x5c" "\x33\x3b\x84\xf4";
  3843. a.inLen = XSTRLEN(a.input);
  3844. a.outLen = WC_SHA512_224_DIGEST_SIZE;
  3845. /*
  3846. ** See page 1 in above document for the SHA512/224 "abc" test:
  3847. */
  3848. b.input = "abc";
  3849. /*
  3850. ** See page 1 in above document for the SHA512/224 "abc" test digest:
  3851. */
  3852. b.output = "\x46\x34\x27\x0f"
  3853. "\x70\x7b\x6a\x54" "\xda\xae\x75\x30"
  3854. "\x46\x08\x42\xe2" "\x0e\x37\xed\x26"
  3855. "\x5c\xee\xe9\xa4" "\x3e\x89\x24\xaa";
  3856. b.inLen = XSTRLEN(b.input);
  3857. b.outLen = WC_SHA512_224_DIGEST_SIZE;
  3858. /*
  3859. ** See page 4 in above for the 2-block test:
  3860. */
  3861. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3862. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3863. /*
  3864. ** see page 9 in above document for the 2-block test message digest:
  3865. */
  3866. c.output = "\x23\xfe\xc5\xbb"
  3867. "\x94\xd6\x0b\x23" "\x30\x81\x92\x64"
  3868. "\x0b\x0c\x45\x33" "\x35\xd6\x64\x73"
  3869. "\x4f\xe4\x0e\x72" "\x68\x67\x4a\xf9";
  3870. c.inLen = XSTRLEN(c.input);
  3871. c.outLen = WC_SHA512_224_DIGEST_SIZE;
  3872. test_sha[0] = a;
  3873. test_sha[1] = b;
  3874. test_sha[2] = c;
  3875. ret = wc_InitSha512_224_ex(&sha, HEAP_HINT, devId);
  3876. if (ret != 0)
  3877. return WC_TEST_RET_ENC_EC(ret);
  3878. ret = wc_InitSha512_224_ex(&shaCopy, HEAP_HINT, devId);
  3879. if (ret != 0) {
  3880. wc_Sha512_224Free(&sha);
  3881. return WC_TEST_RET_ENC_EC(ret);
  3882. }
  3883. for (i = 0; i < times; ++i) {
  3884. ret = wc_Sha512_224Update(&sha, (byte*)test_sha[i].input,
  3885. (word32)test_sha[i].inLen);
  3886. if (ret != 0)
  3887. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3888. ret = wc_Sha512_224GetHash(&sha, hashcopy);
  3889. if (ret != 0)
  3890. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3891. ret = wc_Sha512_224Copy(&sha, &shaCopy);
  3892. if (ret != 0)
  3893. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3894. ret = wc_Sha512_224Final(&sha, hash);
  3895. if (ret != 0)
  3896. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3897. wc_Sha512_224Free(&shaCopy);
  3898. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_224_DIGEST_SIZE) != 0)
  3899. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3900. if (XMEMCMP(hash, hashcopy, WC_SHA512_224_DIGEST_SIZE) != 0)
  3901. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3902. }
  3903. #ifndef NO_LARGE_HASH_TEST
  3904. /* BEGIN LARGE HASH TEST */ {
  3905. byte large_input[1024];
  3906. #ifdef HASH_SIZE_LIMIT
  3907. const char* large_digest =
  3908. "\x98\x68\xc3\xd9\xb9\xef\x17\x53"
  3909. "\x43\x66\x0e\x60\xdf\x29\xf8\xef"
  3910. "\x96\xe3\x93\x34\x8c\x6f\xc0\xeb"
  3911. "\x14\x6c\xcf\x6a";
  3912. #else
  3913. const char* large_digest =
  3914. "\x26\x5f\x98\xd1\x76\x49\x71\x4e"
  3915. "\x82\xb7\x9d\x52\x32\x67\x9d\x56"
  3916. "\x91\xf5\x88\xc3\x05\xbb\x3f\x90"
  3917. "\xe2\x4e\x85\x05";
  3918. #endif
  3919. for (i = 0; i < (int)sizeof(large_input); i++) {
  3920. large_input[i] = (byte)(i & 0xFF);
  3921. }
  3922. #ifdef HASH_SIZE_LIMIT
  3923. times = 20;
  3924. #else
  3925. times = 100;
  3926. #endif
  3927. for (i = 0; i < times; ++i) {
  3928. ret = wc_Sha512_224Update(&sha, (byte*)large_input,
  3929. (word32)sizeof(large_input));
  3930. if (ret != 0)
  3931. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3932. }
  3933. ret = wc_Sha512_224Final(&sha, hash);
  3934. if (ret != 0)
  3935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3936. if (XMEMCMP(hash, large_digest, WC_SHA512_224_DIGEST_SIZE) != 0)
  3937. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3938. #ifndef NO_UNALIGNED_MEMORY_TEST
  3939. /* Unaligned memory access test */
  3940. for (i = 1; i < 16; i++) {
  3941. ret = wc_Sha512_224Update(&sha, (byte*)large_input + i,
  3942. (word32)sizeof(large_input) - (word32)i);
  3943. if (ret != 0)
  3944. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3945. ret = wc_Sha512_224Final(&sha, hash);
  3946. }
  3947. #endif
  3948. } /* END LARGE HASH TEST */
  3949. #endif /* NO_LARGE_HASH_TEST */
  3950. exit:
  3951. wc_Sha512_224Free(&sha);
  3952. wc_Sha512_224Free(&shaCopy);
  3953. return ret;
  3954. } /* sha512_224_test */
  3955. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  3956. #if !defined(WOLFSSL_NOSHA512_256) && \
  3957. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3958. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void)
  3959. {
  3960. /*
  3961. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3962. ** NIST SHA512/256 Document Example:
  3963. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_256.pdf
  3964. */
  3965. wc_Sha512 sha, shaCopy;
  3966. byte hash[WC_SHA512_256_DIGEST_SIZE];
  3967. byte hashcopy[WC_SHA512_256_DIGEST_SIZE];
  3968. wc_test_ret_t ret = 0;
  3969. testVector a, b, c;
  3970. testVector test_sha[3];
  3971. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3972. WOLFSSL_ENTER("sha512_256_test");
  3973. a.input = "";
  3974. a.output = "\xc6\x72\xb8\xd1" "\xef\x56\xed\x28"
  3975. "\xab\x87\xc3\x62" "\x2c\x51\x14\x06"
  3976. "\x9b\xdd\x3a\xd7" "\xb8\xf9\x73\x74"
  3977. "\x98\xd0\xc0\x1e" "\xce\xf0\x96\x7a";
  3978. a.inLen = XSTRLEN(a.input);
  3979. a.outLen = WC_SHA512_256_DIGEST_SIZE;
  3980. /*
  3981. ** See page 1 of above document for "abc" example:
  3982. */
  3983. b.input = "abc";
  3984. /*
  3985. ** See page 4 of above document for "abc" example digest:
  3986. */
  3987. b.output = "\x53\x04\x8e\x26" "\x81\x94\x1e\xf9"
  3988. "\x9b\x2e\x29\xb7" "\x6b\x4c\x7d\xab"
  3989. "\xe4\xc2\xd0\xc6" "\x34\xfc\x6d\x46"
  3990. "\xe0\xe2\xf1\x31" "\x07\xe7\xaf\x23";
  3991. b.inLen = XSTRLEN(b.input);
  3992. b.outLen = WC_SHA512_256_DIGEST_SIZE;
  3993. /*
  3994. ** See page 4 of above document for Two Block Message Sample:
  3995. */
  3996. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3997. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3998. /*
  3999. ** See page 10 of above document for Two Block Message Sample digest:
  4000. */
  4001. c.output = "\x39\x28\xe1\x84" "\xfb\x86\x90\xf8"
  4002. "\x40\xda\x39\x88" "\x12\x1d\x31\xbe"
  4003. "\x65\xcb\x9d\x3e" "\xf8\x3e\xe6\x14"
  4004. "\x6f\xea\xc8\x61" "\xe1\x9b\x56\x3a";
  4005. c.inLen = XSTRLEN(c.input);
  4006. c.outLen = WC_SHA512_256_DIGEST_SIZE;
  4007. test_sha[0] = a;
  4008. test_sha[1] = b;
  4009. test_sha[2] = c;
  4010. ret = wc_InitSha512_256_ex(&sha, HEAP_HINT, devId);
  4011. if (ret != 0)
  4012. return WC_TEST_RET_ENC_EC(ret);
  4013. ret = wc_InitSha512_256_ex(&shaCopy, HEAP_HINT, devId);
  4014. if (ret != 0) {
  4015. wc_Sha512_256Free(&sha);
  4016. return WC_TEST_RET_ENC_EC(ret);
  4017. }
  4018. for (i = 0; i < times; ++i) {
  4019. ret = wc_Sha512_256Update(&sha, (byte*)test_sha[i].input,
  4020. (word32)test_sha[i].inLen);
  4021. if (ret != 0)
  4022. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4023. ret = wc_Sha512_256GetHash(&sha, hashcopy);
  4024. if (ret != 0)
  4025. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4026. ret = wc_Sha512_256Copy(&sha, &shaCopy);
  4027. if (ret != 0)
  4028. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4029. ret = wc_Sha512_256Final(&sha, hash);
  4030. if (ret != 0)
  4031. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4032. wc_Sha512_256Free(&shaCopy);
  4033. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_256_DIGEST_SIZE) != 0)
  4034. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4035. if (XMEMCMP(hash, hashcopy, WC_SHA512_256_DIGEST_SIZE) != 0)
  4036. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4037. }
  4038. #ifndef NO_LARGE_HASH_TEST
  4039. /* BEGIN LARGE HASH TEST */ {
  4040. byte large_input[1024];
  4041. #ifdef HASH_SIZE_LIMIT
  4042. const char* large_digest =
  4043. "\x49\xcc\xbc\x7a\x93\x0b\x02\xb8"
  4044. "\xad\x9a\x46\x51\x00\x1f\x13\x80"
  4045. "\x35\x84\x36\xf1\xf2\x3c\xeb\xd8"
  4046. "\x41\xd4\x06\x8b\x1d\x19\xad\x72";
  4047. #else
  4048. const char* large_digest =
  4049. "\x7a\xe3\x84\x05\xcb\x06\x22\x08"
  4050. "\x7e\x2c\x65\x89\x1f\x26\x45\xfd"
  4051. "\xad\xbc\x2e\x29\x83\x12\x84\x4b"
  4052. "\xf2\xa0\xde\xbe\x06\x11\xd7\x44";
  4053. #endif
  4054. for (i = 0; i < (int)sizeof(large_input); i++) {
  4055. large_input[i] = (byte)(i & 0xFF);
  4056. }
  4057. #ifdef HASH_SIZE_LIMIT
  4058. times = 20;
  4059. #else
  4060. times = 100;
  4061. #endif
  4062. for (i = 0; i < times; ++i) {
  4063. ret = wc_Sha512_256Update(&sha, (byte*)large_input,
  4064. (word32)sizeof(large_input));
  4065. if (ret != 0)
  4066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4067. }
  4068. ret = wc_Sha512_256Final(&sha, hash);
  4069. if (ret != 0)
  4070. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4071. if (XMEMCMP(hash, large_digest, WC_SHA512_256_DIGEST_SIZE) != 0)
  4072. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4073. #ifndef NO_UNALIGNED_MEMORY_TEST
  4074. /* Unaligned memory access test */
  4075. for (i = 1; i < 16; i++) {
  4076. ret = wc_Sha512_256Update(&sha, (byte*)large_input + i,
  4077. (word32)sizeof(large_input) - (word32)i);
  4078. if (ret != 0)
  4079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4080. ret = wc_Sha512_256Final(&sha, hash);
  4081. }
  4082. #endif
  4083. } /* END LARGE HASH TEST */
  4084. #endif /* NO_LARGE_HASH_TEST */
  4085. exit:
  4086. wc_Sha512_256Free(&sha);
  4087. wc_Sha512_256Free(&shaCopy);
  4088. return ret;
  4089. } /* sha512_256_test */
  4090. #endif /* !defined(WOLFSSL_NOSHA512_256) && !FIPS ... */
  4091. #endif /* WOLFSSL_SHA512 */
  4092. #ifdef WOLFSSL_SHA384
  4093. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void)
  4094. {
  4095. wc_Sha384 sha, shaCopy;
  4096. byte hash[WC_SHA384_DIGEST_SIZE];
  4097. byte hashcopy[WC_SHA384_DIGEST_SIZE];
  4098. wc_test_ret_t ret = 0;
  4099. testVector a, b, c;
  4100. testVector test_sha[3];
  4101. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4102. WOLFSSL_ENTER("sha384_test");
  4103. a.input = "";
  4104. a.output = "\x38\xb0\x60\xa7\x51\xac\x96\x38\x4c\xd9\x32\x7e\xb1\xb1\xe3"
  4105. "\x6a\x21\xfd\xb7\x11\x14\xbe\x07\x43\x4c\x0c\xc7\xbf\x63\xf6"
  4106. "\xe1\xda\x27\x4e\xde\xbf\xe7\x6f\x65\xfb\xd5\x1a\xd2\xf1\x48"
  4107. "\x98\xb9\x5b";
  4108. a.inLen = XSTRLEN(a.input);
  4109. a.outLen = WC_SHA384_DIGEST_SIZE;
  4110. b.input = "abc";
  4111. b.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  4112. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  4113. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  4114. "\xc8\x25\xa7";
  4115. b.inLen = XSTRLEN(b.input);
  4116. b.outLen = WC_SHA384_DIGEST_SIZE;
  4117. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  4118. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  4119. c.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  4120. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  4121. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  4122. "\x74\x60\x39";
  4123. c.inLen = XSTRLEN(c.input);
  4124. c.outLen = WC_SHA384_DIGEST_SIZE;
  4125. test_sha[0] = a;
  4126. test_sha[1] = b;
  4127. test_sha[2] = c;
  4128. ret = wc_InitSha384_ex(&sha, HEAP_HINT, devId);
  4129. if (ret != 0)
  4130. return WC_TEST_RET_ENC_EC(ret);
  4131. ret = wc_InitSha384_ex(&shaCopy, HEAP_HINT, devId);
  4132. if (ret != 0) {
  4133. wc_Sha384Free(&sha);
  4134. return WC_TEST_RET_ENC_EC(ret);
  4135. }
  4136. for (i = 0; i < times; ++i) {
  4137. ret = wc_Sha384Update(&sha, (byte*)test_sha[i].input,
  4138. (word32)test_sha[i].inLen);
  4139. if (ret != 0)
  4140. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4141. ret = wc_Sha384GetHash(&sha, hashcopy);
  4142. if (ret != 0)
  4143. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4144. ret = wc_Sha384Copy(&sha, &shaCopy);
  4145. if (ret != 0)
  4146. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4147. ret = wc_Sha384Final(&sha, hash);
  4148. if (ret != 0)
  4149. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4150. wc_Sha384Free(&shaCopy);
  4151. if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  4152. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4153. if (XMEMCMP(hash, hashcopy, WC_SHA384_DIGEST_SIZE) != 0)
  4154. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4155. }
  4156. #ifndef NO_LARGE_HASH_TEST
  4157. /* BEGIN LARGE HASH TEST */ {
  4158. byte large_input[1024];
  4159. #ifdef HASH_SIZE_LIMIT
  4160. const char* large_digest =
  4161. "\xB5\xAD\x66\x6F\xD9\x58\x5E\x68\xDD\x5E\x30\xD3\x95\x72\x33\xA4"
  4162. "\xE9\x4B\x99\x3A\xEF\xF8\xE1\xBF\x1F\x05\x32\xAA\x16\x00\x82\xEC"
  4163. "\x15\xDA\xF2\x75\xEE\xE9\x06\xAF\x52\x8A\x5C\xEF\x72\x81\x80\xD6";
  4164. #else
  4165. const char* large_digest =
  4166. "\x37\x01\xdb\xff\x1e\x40\x4f\xe1\xe2\xea\x0b\x40\xbb\x3b\x39\x9a"
  4167. "\xcc\xe8\x44\x8e\x7e\xe5\x64\xb5\x6b\x7f\x56\x64\xa7\x2b\x84\xe3"
  4168. "\xc5\xd7\x79\x03\x25\x90\xf7\xa4\x58\xcb\x97\xa8\x8b\xb1\xa4\x81";
  4169. #endif
  4170. for (i = 0; i < (int)sizeof(large_input); i++) {
  4171. large_input[i] = (byte)(i & 0xFF);
  4172. }
  4173. #ifdef HASH_SIZE_LIMIT
  4174. times = 20;
  4175. #else
  4176. times = 100;
  4177. #endif
  4178. for (i = 0; i < times; ++i) {
  4179. ret = wc_Sha384Update(&sha, (byte*)large_input,
  4180. (word32)sizeof(large_input));
  4181. if (ret != 0)
  4182. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4183. }
  4184. ret = wc_Sha384Final(&sha, hash);
  4185. if (ret != 0)
  4186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4187. if (XMEMCMP(hash, large_digest, WC_SHA384_DIGEST_SIZE) != 0)
  4188. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4189. } /* END LARGE HASH TEST */
  4190. #endif /* NO_LARGE_HASH_TEST */
  4191. exit:
  4192. wc_Sha384Free(&sha);
  4193. wc_Sha384Free(&shaCopy);
  4194. return ret;
  4195. }
  4196. #endif /* WOLFSSL_SHA384 */
  4197. #ifdef WOLFSSL_SHA3
  4198. #ifndef WOLFSSL_NOSHA3_224
  4199. static wc_test_ret_t sha3_224_test(void)
  4200. {
  4201. wc_Sha3 sha;
  4202. byte hash[WC_SHA3_224_DIGEST_SIZE];
  4203. byte hashcopy[WC_SHA3_224_DIGEST_SIZE];
  4204. testVector a, b, c;
  4205. testVector test_sha[3];
  4206. wc_test_ret_t ret = 0;
  4207. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4208. a.input = "";
  4209. a.output = "\x6b\x4e\x03\x42\x36\x67\xdb\xb7\x3b\x6e\x15\x45\x4f\x0e\xb1"
  4210. "\xab\xd4\x59\x7f\x9a\x1b\x07\x8e\x3f\x5b\x5a\x6b\xc7";
  4211. a.inLen = XSTRLEN(a.input);
  4212. a.outLen = WC_SHA3_224_DIGEST_SIZE;
  4213. b.input = "abc";
  4214. b.output = "\xe6\x42\x82\x4c\x3f\x8c\xf2\x4a\xd0\x92\x34\xee\x7d\x3c\x76"
  4215. "\x6f\xc9\xa3\xa5\x16\x8d\x0c\x94\xad\x73\xb4\x6f\xdf";
  4216. b.inLen = XSTRLEN(b.input);
  4217. b.outLen = WC_SHA3_224_DIGEST_SIZE;
  4218. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4219. c.output = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55\x74\x49\x44\x79"
  4220. "\xba\x5c\x7e\x7a\xb7\x6e\xf2\x64\xea\xd0\xfc\xce\x33";
  4221. c.inLen = XSTRLEN(c.input);
  4222. c.outLen = WC_SHA3_224_DIGEST_SIZE;
  4223. test_sha[0] = a;
  4224. test_sha[1] = b;
  4225. test_sha[2] = c;
  4226. ret = wc_InitSha3_224(&sha, HEAP_HINT, devId);
  4227. if (ret != 0)
  4228. return WC_TEST_RET_ENC_EC(ret);
  4229. for (i = 0; i < times; ++i) {
  4230. ret = wc_Sha3_224_Update(&sha, (byte*)test_sha[i].input,
  4231. (word32)test_sha[i].inLen);
  4232. if (ret != 0)
  4233. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4234. ret = wc_Sha3_224_GetHash(&sha, hashcopy);
  4235. if (ret != 0)
  4236. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4237. ret = wc_Sha3_224_Final(&sha, hash);
  4238. if (ret != 0)
  4239. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4240. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_224_DIGEST_SIZE) != 0)
  4241. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4242. if (XMEMCMP(hash, hashcopy, WC_SHA3_224_DIGEST_SIZE) != 0)
  4243. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4244. }
  4245. #ifndef NO_LARGE_HASH_TEST
  4246. /* BEGIN LARGE HASH TEST */ {
  4247. byte large_input[1024];
  4248. const char* large_digest =
  4249. "\x13\xe5\xd3\x98\x7b\x94\xda\x41\x12\xc7\x1e\x92\x3a\x19"
  4250. "\x21\x20\x86\x6f\x24\xbf\x0a\x31\xbc\xfd\xd6\x70\x36\xf3";
  4251. for (i = 0; i < (int)sizeof(large_input); i++) {
  4252. large_input[i] = (byte)(i & 0xFF);
  4253. }
  4254. times = 100;
  4255. for (i = 0; i < times; ++i) {
  4256. ret = wc_Sha3_224_Update(&sha, (byte*)large_input,
  4257. (word32)sizeof(large_input));
  4258. if (ret != 0)
  4259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4260. }
  4261. ret = wc_Sha3_224_Final(&sha, hash);
  4262. if (ret != 0)
  4263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4264. if (XMEMCMP(hash, large_digest, WC_SHA3_224_DIGEST_SIZE) != 0)
  4265. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4266. } /* END LARGE HASH TEST */
  4267. #endif /* NO_LARGE_HASH_TEST */
  4268. exit:
  4269. wc_Sha3_224_Free(&sha);
  4270. return ret;
  4271. }
  4272. #endif /* WOLFSSL_NOSHA3_224 */
  4273. #ifndef WOLFSSL_NOSHA3_256
  4274. static wc_test_ret_t sha3_256_test(void)
  4275. {
  4276. wc_Sha3 sha;
  4277. byte hash[WC_SHA3_256_DIGEST_SIZE];
  4278. byte hashcopy[WC_SHA3_256_DIGEST_SIZE];
  4279. testVector a, b, c;
  4280. testVector test_sha[3];
  4281. wc_test_ret_t ret = 0;
  4282. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4283. byte large_input[1024];
  4284. const char* large_digest =
  4285. "\xdc\x90\xc0\xb1\x25\xdb\x2c\x34\x81\xa3\xff\xbc\x1e\x2e\x87\xeb"
  4286. "\x6d\x70\x85\x61\xe0\xe9\x63\x61\xff\xe5\x84\x4b\x1f\x68\x05\x15";
  4287. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4288. /* test vector with hash of empty string */
  4289. const char* Keccak256EmptyOut =
  4290. "\xc5\xd2\x46\x01\x86\xf7\x23\x3c\x92\x7e\x7d\xb2\xdc\xc7\x03\xc0"
  4291. "\xe5\x00\xb6\x53\xca\x82\x27\x3b\x7b\xfa\xd8\x04\x5d\x85\xa4\x70";
  4292. #endif
  4293. /*
  4294. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-256_Msg0.pdf
  4295. */
  4296. a.input = "";
  4297. a.output = "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66\x51\xc1\x47\x56\xa0\x61\xd6"
  4298. "\x62\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8"
  4299. "\x43\x4a";
  4300. a.inLen = XSTRLEN(a.input);
  4301. a.outLen = WC_SHA3_256_DIGEST_SIZE;
  4302. b.input = "abc";
  4303. b.output = "\x3a\x98\x5d\xa7\x4f\xe2\x25\xb2\x04\x5c\x17\x2d\x6b\xd3\x90"
  4304. "\xbd\x85\x5f\x08\x6e\x3e\x9d\x52\x5b\x46\xbf\xe2\x45\x11\x43"
  4305. "\x15\x32";
  4306. b.inLen = XSTRLEN(b.input);
  4307. b.outLen = WC_SHA3_256_DIGEST_SIZE;
  4308. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4309. c.output = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8\x23\x5e"
  4310. "\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32\xdd\x97\x49\x6d"
  4311. "\x33\x76";
  4312. c.inLen = XSTRLEN(c.input);
  4313. c.outLen = WC_SHA3_256_DIGEST_SIZE;
  4314. test_sha[0] = a;
  4315. test_sha[1] = b;
  4316. test_sha[2] = c;
  4317. ret = wc_InitSha3_256(&sha, HEAP_HINT, devId);
  4318. if (ret != 0)
  4319. return WC_TEST_RET_ENC_EC(ret);
  4320. for (i = 0; i < times; ++i) {
  4321. ret = wc_Sha3_256_Update(&sha, (byte*)test_sha[i].input,
  4322. (word32)test_sha[i].inLen);
  4323. if (ret != 0)
  4324. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4325. ret = wc_Sha3_256_GetHash(&sha, hashcopy);
  4326. if (ret != 0)
  4327. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4328. ret = wc_Sha3_256_Final(&sha, hash);
  4329. if (ret != 0)
  4330. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4331. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_256_DIGEST_SIZE) != 0)
  4332. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4333. if (XMEMCMP(hash, hashcopy, WC_SHA3_256_DIGEST_SIZE) != 0)
  4334. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4335. }
  4336. #ifndef NO_LARGE_HASH_TEST
  4337. /* BEGIN LARGE HASH TEST */ {
  4338. for (i = 0; i < (int)sizeof(large_input); i++) {
  4339. large_input[i] = (byte)(i & 0xFF);
  4340. }
  4341. times = 100;
  4342. for (i = 0; i < times; ++i) {
  4343. ret = wc_Sha3_256_Update(&sha, (byte*)large_input,
  4344. (word32)sizeof(large_input));
  4345. if (ret != 0)
  4346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4347. }
  4348. ret = wc_Sha3_256_Final(&sha, hash);
  4349. if (ret != 0)
  4350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4351. if (XMEMCMP(hash, large_digest, WC_SHA3_256_DIGEST_SIZE) != 0)
  4352. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4353. } /* END LARGE HASH TEST */
  4354. #endif /* NO_LARGE_HASH_TEST */
  4355. /* this is a software only variant of SHA3 not supported by external hardware devices */
  4356. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4357. /* Test for Keccak256 */
  4358. ret = wc_Sha3_SetFlags(&sha, WC_HASH_SHA3_KECCAK256);
  4359. if (ret != 0) {
  4360. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4361. }
  4362. ret = wc_Sha3_256_Update(&sha, (byte*)"", 0);
  4363. if (ret != 0) {
  4364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4365. }
  4366. ret = wc_Sha3_256_Final(&sha, hash);
  4367. if (ret != 0) {
  4368. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4369. }
  4370. if (XMEMCMP(hash, Keccak256EmptyOut, WC_SHA3_256_DIGEST_SIZE) != 0) {
  4371. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4372. }
  4373. #endif /* WOLFSSL_HASH_FLAGS && !WOLFSSL_ASYNC_CRYPT */
  4374. exit:
  4375. wc_Sha3_256_Free(&sha);
  4376. return ret;
  4377. }
  4378. #endif /* WOLFSSL_NOSHA3_256 */
  4379. #ifndef WOLFSSL_NOSHA3_384
  4380. static wc_test_ret_t sha3_384_test(void)
  4381. {
  4382. wc_Sha3 sha;
  4383. byte hash[WC_SHA3_384_DIGEST_SIZE];
  4384. byte buf[64];
  4385. #ifndef NO_INTM_HASH_TEST
  4386. byte hashcopy[WC_SHA3_384_DIGEST_SIZE];
  4387. #endif
  4388. testVector a, b, c;
  4389. testVector test_sha[3];
  4390. wc_test_ret_t ret;
  4391. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4392. /*
  4393. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-384_Msg0.pdf
  4394. */
  4395. a.input = "";
  4396. a.output = "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d\x01\x10\x7d\x85\x2e\x4c\x24"
  4397. "\x85\xc5\x1a\x50\xaa\xaa\x94\xfc\x61\x99\x5e\x71\xbb\xee\x98"
  4398. "\x3a\x2a\xc3\x71\x38\x31\x26\x4a\xdb\x47\xfb\x6b\xd1\xe0\x58"
  4399. "\xd5\xf0\x04";
  4400. a.inLen = XSTRLEN(a.input);
  4401. a.outLen = WC_SHA3_384_DIGEST_SIZE;
  4402. #if defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4403. /* NIST test vector with a length that is a multiple of 4 */
  4404. b.input = "\x7d\x80\xb1\x60\xc4\xb5\x36\xa3\xbe\xb7\x99\x80\x59\x93\x44"
  4405. "\x04\x7c\x5f\x82\xa1\xdf\xc3\xee\xd4";
  4406. b.output = "\x04\x1c\xc5\x86\x1b\xa3\x34\x56\x3c\x61\xd4\xef\x97\x10\xd4"
  4407. "\x89\x6c\x31\x1c\x92\xed\xbe\x0d\x7c\xd5\x3e\x80\x3b\xf2\xf4"
  4408. "\xeb\x60\x57\x23\x55\x70\x77\x0c\xe8\x7c\x55\x20\xd7\xec\x14"
  4409. "\x19\x87\x22";
  4410. b.inLen = XSTRLEN(b.input);
  4411. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4412. #else
  4413. b.input = "abc";
  4414. b.output = "\xec\x01\x49\x82\x88\x51\x6f\xc9\x26\x45\x9f\x58\xe2\xc6\xad"
  4415. "\x8d\xf9\xb4\x73\xcb\x0f\xc0\x8c\x25\x96\xda\x7c\xf0\xe4\x9b"
  4416. "\xe4\xb2\x98\xd8\x8c\xea\x92\x7a\xc7\xf5\x39\xf1\xed\xf2\x28"
  4417. "\x37\x6d\x25";
  4418. b.inLen = XSTRLEN(b.input);
  4419. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4420. #endif
  4421. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4422. c.output = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7\x8a\x49"
  4423. "\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd\xbc\x32\xb9\xd4"
  4424. "\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe\xa1\x9e\xef\x51\xac\xd0"
  4425. "\x65\x7c\x22";
  4426. c.inLen = XSTRLEN(c.input);
  4427. c.outLen = WC_SHA3_384_DIGEST_SIZE;
  4428. #if defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4429. test_sha[0] = b; /* hardware acc. pre-Versal can not handle "" string */
  4430. #else
  4431. test_sha[0] = a;
  4432. #endif
  4433. test_sha[1] = b;
  4434. test_sha[2] = c;
  4435. ret = wc_InitSha3_384(&sha, HEAP_HINT, devId);
  4436. if (ret != 0)
  4437. return WC_TEST_RET_ENC_EC(ret);
  4438. for (i = 0; i < times; ++i) {
  4439. XMEMCPY(buf, test_sha[i].input, test_sha[i].inLen);
  4440. ret = wc_Sha3_384_Update(&sha, buf,
  4441. (word32)test_sha[i].inLen);
  4442. if (ret != 0)
  4443. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4444. #ifndef NO_INTM_HASH_TEST
  4445. ret = wc_Sha3_384_GetHash(&sha, hashcopy);
  4446. if (ret != 0)
  4447. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4448. #endif
  4449. ret = wc_Sha3_384_Final(&sha, hash);
  4450. if (ret != 0)
  4451. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4452. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_384_DIGEST_SIZE) != 0)
  4453. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4454. #ifndef NO_INTM_HASH_TEST
  4455. if (XMEMCMP(hash, hashcopy, WC_SHA3_384_DIGEST_SIZE) != 0)
  4456. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4457. #endif
  4458. }
  4459. #ifndef NO_LARGE_HASH_TEST
  4460. /* BEGIN LARGE HASH TEST */ {
  4461. byte large_input[1024];
  4462. const char* large_digest =
  4463. "\x30\x44\xec\x17\xef\x47\x9f\x55\x36\x11\xd6\x3f\x8a\x31\x5a\x71"
  4464. "\x8a\x71\xa7\x1d\x8e\x84\xe8\x6c\x24\x02\x2f\x7a\x08\x4e\xea\xd7"
  4465. "\x42\x36\x5d\xa8\xc2\xb7\x42\xad\xec\x19\xfb\xca\xc6\x64\xb3\xa4";
  4466. for (i = 0; i < (int)sizeof(large_input); i++) {
  4467. large_input[i] = (byte)(i & 0xFF);
  4468. }
  4469. times = 100;
  4470. for (i = 0; i < times; ++i) {
  4471. ret = wc_Sha3_384_Update(&sha, (byte*)large_input,
  4472. (word32)sizeof(large_input));
  4473. if (ret != 0)
  4474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4475. }
  4476. ret = wc_Sha3_384_Final(&sha, hash);
  4477. if (ret != 0)
  4478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4479. if (XMEMCMP(hash, large_digest, WC_SHA3_384_DIGEST_SIZE) != 0)
  4480. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4481. } /* END LARGE HASH TEST */
  4482. #endif /* NO_LARGE_HASH_TEST */
  4483. exit:
  4484. wc_Sha3_384_Free(&sha);
  4485. return ret;
  4486. }
  4487. #endif /* WOLFSSL_NOSHA3_384 */
  4488. #ifndef WOLFSSL_NOSHA3_512
  4489. static wc_test_ret_t sha3_512_test(void)
  4490. {
  4491. wc_Sha3 sha;
  4492. byte hash[WC_SHA3_512_DIGEST_SIZE];
  4493. byte hashcopy[WC_SHA3_512_DIGEST_SIZE];
  4494. testVector a, b, c;
  4495. testVector test_sha[3];
  4496. wc_test_ret_t ret;
  4497. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4498. /*
  4499. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-512_Msg0.pdf
  4500. */
  4501. a.input = "";
  4502. a.output = "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5\xc8\xb5\x67\xdc\x18\x5a\x75"
  4503. "\x6e\x97\xc9\x82\x16\x4f\xe2\x58\x59\xe0\xd1\xdc\xc1\x47\x5c"
  4504. "\x80\xa6\x15\xb2\x12\x3a\xf1\xf5\xf9\x4c\x11\xe3\xe9\x40\x2c"
  4505. "\x3a\xc5\x58\xf5\x00\x19\x9d\x95\xb6\xd3\xe3\x01\x75\x85\x86"
  4506. "\x28\x1d\xcd\x26";
  4507. a.inLen = XSTRLEN(a.input);
  4508. a.outLen = WC_SHA3_512_DIGEST_SIZE;
  4509. b.input = "abc";
  4510. b.output = "\xb7\x51\x85\x0b\x1a\x57\x16\x8a\x56\x93\xcd\x92\x4b\x6b\x09"
  4511. "\x6e\x08\xf6\x21\x82\x74\x44\xf7\x0d\x88\x4f\x5d\x02\x40\xd2"
  4512. "\x71\x2e\x10\xe1\x16\xe9\x19\x2a\xf3\xc9\x1a\x7e\xc5\x76\x47"
  4513. "\xe3\x93\x40\x57\x34\x0b\x4c\xf4\x08\xd5\xa5\x65\x92\xf8\x27"
  4514. "\x4e\xec\x53\xf0";
  4515. b.inLen = XSTRLEN(b.input);
  4516. b.outLen = WC_SHA3_512_DIGEST_SIZE;
  4517. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4518. c.output = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10\xfc\xa8"
  4519. "\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7\xec\x2f\x1e\x91"
  4520. "\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53\x02\xba\x1b\x0d\x8d\xc7"
  4521. "\x8c\x08\x63\x46\xb5\x33\xb4\x9c\x03\x0d\x99\xa2\x7d\xaf\x11"
  4522. "\x39\xd6\xe7\x5e";
  4523. c.inLen = XSTRLEN(c.input);
  4524. c.outLen = WC_SHA3_512_DIGEST_SIZE;
  4525. test_sha[0] = a;
  4526. test_sha[1] = b;
  4527. test_sha[2] = c;
  4528. ret = wc_InitSha3_512(&sha, HEAP_HINT, devId);
  4529. if (ret != 0)
  4530. return WC_TEST_RET_ENC_EC(ret);
  4531. for (i = 0; i < times; ++i) {
  4532. ret = wc_Sha3_512_Update(&sha, (byte*)test_sha[i].input,
  4533. (word32)test_sha[i].inLen);
  4534. if (ret != 0)
  4535. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4536. ret = wc_Sha3_512_GetHash(&sha, hashcopy);
  4537. if (ret != 0)
  4538. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4539. ret = wc_Sha3_512_Final(&sha, hash);
  4540. if (ret != 0)
  4541. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4542. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_512_DIGEST_SIZE) != 0)
  4543. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4544. if (XMEMCMP(hash, hashcopy, WC_SHA3_512_DIGEST_SIZE) != 0)
  4545. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4546. }
  4547. #ifndef NO_LARGE_HASH_TEST
  4548. /* BEGIN LARGE HASH TEST */ {
  4549. byte large_input[1024];
  4550. const char* large_digest =
  4551. "\x9c\x13\x26\xb6\x26\xb2\x94\x31\xbc\xf4\x34\xe9\x6f\xf2\xd6\x29"
  4552. "\x9a\xd0\x9b\x32\x63\x2f\x18\xa7\x5f\x23\xc9\x60\xc2\x32\x0c\xbc"
  4553. "\x57\x77\x33\xf1\x83\x81\x8a\xd3\x15\x7c\x93\xdc\x80\x9f\xed\x61"
  4554. "\x41\xa7\x5b\xfd\x32\x0e\x38\x15\xb0\x46\x3b\x7a\x4f\xfd\x44\x88";
  4555. for (i = 0; i < (int)sizeof(large_input); i++) {
  4556. large_input[i] = (byte)(i & 0xFF);
  4557. }
  4558. times = 100;
  4559. for (i = 0; i < times; ++i) {
  4560. ret = wc_Sha3_512_Update(&sha, (byte*)large_input,
  4561. (word32)sizeof(large_input));
  4562. if (ret != 0)
  4563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4564. }
  4565. ret = wc_Sha3_512_Final(&sha, hash);
  4566. if (ret != 0)
  4567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4568. if (XMEMCMP(hash, large_digest, WC_SHA3_512_DIGEST_SIZE) != 0)
  4569. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4570. } /* END LARGE HASH TEST */
  4571. #endif /* NO_LARGE_HASH_TEST */
  4572. exit:
  4573. wc_Sha3_512_Free(&sha);
  4574. return ret;
  4575. }
  4576. #endif /* WOLFSSL_NOSHA3_512 */
  4577. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void)
  4578. {
  4579. wc_test_ret_t ret;
  4580. (void)ret;
  4581. WOLFSSL_ENTER("sha3_test");
  4582. #ifndef WOLFSSL_NOSHA3_224
  4583. if ((ret = sha3_224_test()) != 0)
  4584. return ret;
  4585. #endif
  4586. #ifndef WOLFSSL_NOSHA3_256
  4587. if ((ret = sha3_256_test()) != 0)
  4588. return ret;
  4589. #endif
  4590. #ifndef WOLFSSL_NOSHA3_384
  4591. if ((ret = sha3_384_test()) != 0)
  4592. return ret;
  4593. #endif
  4594. #ifndef WOLFSSL_NOSHA3_512
  4595. if ((ret = sha3_512_test()) != 0)
  4596. return ret;
  4597. #endif
  4598. return 0;
  4599. }
  4600. #endif /* WOLFSSL_SHA3 */
  4601. #ifdef WOLFSSL_SHAKE128
  4602. static wc_test_ret_t shake128_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4603. size_t large_input_buf_size)
  4604. {
  4605. testVector a, b, c, d, e;
  4606. testVector test_sha[5];
  4607. wc_test_ret_t ret = 0;
  4608. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4609. static const char large_digest[] =
  4610. "\x2b\xd1\x69\x9f\xb3\x75\x40\x74\xb8\xb2\xd2\x0b\x92\x47\x9b\xfe"
  4611. "\xc9\x91\x48\xbe\xda\xa4\x09\xd7\x61\x35\x18\x05\x07\x71\xa5\x61"
  4612. "\x4d\xc4\x94\xad\xbe\x04\x7d\xad\x95\x2f\xeb\x2c\xc0\x10\x67\x43"
  4613. "\x40\xf1\x4a\x58\x1c\x54\xfa\x24\x1c\x1a\x4e\x8d\x9b\xbc\xea\xa7"
  4614. "\x32\xf2\x4c\xc7\x86\x05\x36\xdc\xb4\x42\xd8\x35\xd1\xb4\xa2\x79"
  4615. "\xa2\xe6\xee\x67\x4f\xbf\x2a\x93\x41\x88\x25\x56\x29\x90\x1a\x06"
  4616. "\xba\xfe\x9f\xa6\x1a\x74\xe8\x7e\x85\x4a\xc8\x58\x60\xb1\x7b\x18"
  4617. "\xdf\x77\x59\x46\x04\xc1\xff\x4b\x9b\xcb\xad\xfe\x91\x28\xf0\x01"
  4618. "\xc1\x33\xd0\x99\x99\x2e\x0c\x86\x84\x67\x4d\x37\xa4\x42\x45\x10"
  4619. "\xdc\x8f\xdb\x6f\xa6\x9b\xee\x8a\x60\xa5\x1f\x95\x3f\x8f\xf5\x31"
  4620. "\x4b\x1d\x48\x1e\x45\xff\x79\x5c\xbe\x72\xfc\x56\xed\x6d\x1a\x99"
  4621. "\x7f\x23\x7c\xd1\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b"
  4622. "\xa3\x60\x51\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41"
  4623. "\x77\x2c\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59"
  4624. "\x0d\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4625. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d\xa8"
  4626. "\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb\x67\x86"
  4627. "\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b\x3d\xca\x95"
  4628. "\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47\xcf\x56\xba\x71"
  4629. "\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a\xff\xb4\xbe\x72\x26"
  4630. "\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e\xd9\xe9\xe6\xf9\xff\xa5";
  4631. byte hash[sizeof(large_digest) - 1];
  4632. /*
  4633. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4634. */
  4635. a.input = "";
  4636. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4637. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4638. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4639. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4640. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4641. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4642. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4643. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a\x04\x30\x2e\x10\xc8\xbc"
  4644. "\x1c\xbf\x1a\x0b\x3a\x51\x20\xea\x17\xcd\xa7\xcf\xad\x76\x5f"
  4645. "\x56\x23\x47\x4d\x36\x8c\xcc\xa8\xaf\x00\x07\xcd\x9f\x5e\x4c"
  4646. "\x84\x9f\x16\x7a\x58\x0b\x14\xaa\xbd\xef\xae\xe7\xee\xf4\x7c"
  4647. "\xb0\xfc\xa9";
  4648. a.inLen = XSTRLEN(a.input);
  4649. a.outLen = WC_SHA3_128_BLOCK_SIZE;
  4650. b.input = "abc";
  4651. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4652. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4653. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4654. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4655. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4656. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4657. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4658. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3\x77\xcf\xb9\xcd\xe4\xc6"
  4659. "\x35\x99\xb2\x7f\x34\x62\xbb\xa4\xa0\xed\x29\x6c\x80\x1f\x9f"
  4660. "\xf7\xf5\x73\x02\xbb\x30\x76\xee\x14\x5f\x97\xa3\x2a\xe6\x8e"
  4661. "\x76\xab\x66\xc4\x8d\x51\x67\x5b\xd4\x9a\xcc\x29\x08\x2f\x56"
  4662. "\x47\x58\x4e";
  4663. b.inLen = XSTRLEN(b.input);
  4664. b.outLen = WC_SHA3_128_BLOCK_SIZE;
  4665. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4666. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4667. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4668. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4669. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4670. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4671. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4672. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4673. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa\x54\x56\x54\xf7\x0a\xe5"
  4674. "\x86\xff\x10\x13\x14\x20\x77\x14\x83\xec\x92\xed\xab\x40\x8c"
  4675. "\x76\x7b\xf4\xc5\xb4\xff\xfa\xa8\x0c\x8c\xa2\x14\xd8\x4c\x4d"
  4676. "\xc7\x00\xd0\xc5\x06\x30\xb2\xff\xc3\x79\x3e\xa4\xd8\x72\x58"
  4677. "\xb4\xc9\x54";
  4678. c.inLen = XSTRLEN(c.input);
  4679. c.outLen = WC_SHA3_128_BLOCK_SIZE;
  4680. /* Taken from NIST CAVP test vectors - full rate output. */
  4681. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4682. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4683. "\x85\xe0";
  4684. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4685. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4686. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4687. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4688. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4689. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4690. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4691. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4692. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4693. "\xa1\x41\x9b\xaf\x60\x52\xc0\xc1\xb4\x45\xf8\x35\x17\x57\xb0"
  4694. "\xd0\x22\x87\x21\x89\xe2\xc0\x27\x3f\x82\xd9\x69\x69\x66\x3e"
  4695. "\x55\x4d\x09";
  4696. d.inLen = 32;
  4697. d.outLen = WC_SHA3_128_BLOCK_SIZE;
  4698. /* Taken from NIST CAVP test vectors - more than one output block. */
  4699. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4700. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4701. "\x47\xe4";
  4702. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4703. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4704. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4705. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4706. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4707. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4708. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4709. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4710. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4711. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4712. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4713. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4714. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4715. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4716. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4717. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4718. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d"
  4719. "\xa8\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb"
  4720. "\x67\x86\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b"
  4721. "\x3d\xca\x95\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47"
  4722. "\xcf\x56\xba\x71\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a"
  4723. "\xff\xb4\xbe\x72\x26\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e"
  4724. "\xd9\xe9\xe6\xf9\xff\xa5";
  4725. e.inLen = 32;
  4726. e.outLen = 2 * WC_SHA3_128_BLOCK_SIZE;
  4727. test_sha[0] = a;
  4728. test_sha[1] = b;
  4729. test_sha[2] = c;
  4730. test_sha[3] = d;
  4731. test_sha[4] = e;
  4732. for (i = 0; i < times; ++i) {
  4733. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4734. if (ret != 0)
  4735. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4736. ret = wc_Shake128_Absorb(sha, (byte*)test_sha[i].input,
  4737. (word32)test_sha[i].inLen);
  4738. if (ret != 0)
  4739. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4740. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4741. (word32)test_sha[i].outLen / WC_SHA3_128_BLOCK_SIZE);
  4742. if (ret != 0)
  4743. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4744. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  4745. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4746. }
  4747. #ifndef NO_LARGE_HASH_TEST
  4748. /* BEGIN LARGE HASH TEST */ {
  4749. for (i = 0; i < (int)large_input_buf_size; i++) {
  4750. large_input_buf[i] = (byte)(i & 0xFF);
  4751. }
  4752. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4753. if (ret != 0)
  4754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4755. /* Absorb is non-incremental. */
  4756. ret = wc_Shake128_Absorb(sha, (byte*)large_input_buf,
  4757. (word32)large_input_buf_size);
  4758. if (ret != 0)
  4759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4760. /* Able to squeeze out blocks incrementally. */
  4761. ret = wc_Shake128_SqueezeBlocks(sha, hash, 1);
  4762. if (ret != 0)
  4763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4764. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4765. ((word32)sizeof(hash) / WC_SHA3_128_BLOCK_SIZE) - 1);
  4766. if (ret != 0)
  4767. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4768. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  4769. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4770. } /* END LARGE HASH TEST */
  4771. #endif /* NO_LARGE_HASH_TEST */
  4772. exit:
  4773. return ret;
  4774. }
  4775. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void)
  4776. {
  4777. wc_Shake sha;
  4778. byte hash[250];
  4779. testVector a, b, c, d, e;
  4780. testVector test_sha[5];
  4781. wc_test_ret_t ret = 0;
  4782. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4783. #define SHAKE128_LARGE_INPUT_BUFSIZ 1024
  4784. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4785. byte *large_input = NULL;
  4786. #else
  4787. byte large_input[SHAKE128_LARGE_INPUT_BUFSIZ];
  4788. #endif
  4789. static const char large_digest[] =
  4790. "\x88\xd7\x0e\x86\x46\x72\x6b\x3d\x7d\x22\xe1\xa9\x2d\x02\xdb\x35"
  4791. "\x92\x4f\x1b\x03\x90\xee\xa3\xce\xd1\x3a\x08\x3a\xd7\x4e\x10\xdf"
  4792. "\x09\x67\x33\x35\x4f\xdd\x38\x50\x5b\xcb\x75\xc7\xba\x65\xe5\xe8"
  4793. "\xb8\x76\xde\xc5\xee\xd7\xf1\x65\x93\x4e\x5e\xc4\xb1\xd7\x6b\xee"
  4794. "\x4b\x57\x48\xf5\x38\x49\x9e\x45\xa0\xf7\x32\xe9\x05\x26\x6a\x10"
  4795. "\x70\xd4\x7c\x19\x01\x1f\x6d\x37\xba\x7b\x74\xc2\xbc\xb6\xbc\x74"
  4796. "\xa3\x66\x6c\x9b\x11\x84\x9d\x4a\x36\xbc\x8a\x0d\x4c\xe3\x39\xfa"
  4797. "\xfa\x1b";
  4798. WOLFSSL_ENTER("shake128_test");
  4799. /*
  4800. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4801. */
  4802. a.input = "";
  4803. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4804. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4805. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4806. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4807. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4808. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4809. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4810. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a";
  4811. a.inLen = XSTRLEN(a.input);
  4812. a.outLen = 114;
  4813. b.input = "abc";
  4814. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4815. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4816. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4817. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4818. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4819. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4820. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4821. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3";
  4822. b.inLen = XSTRLEN(b.input);
  4823. b.outLen = 114;
  4824. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4825. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4826. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4827. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4828. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4829. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4830. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4831. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4832. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa";
  4833. c.inLen = XSTRLEN(c.input);
  4834. c.outLen = 114;
  4835. /* Taken from NIST CAVP test vectors - full rate output. */
  4836. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4837. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4838. "\x85\xe0";
  4839. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4840. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4841. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4842. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4843. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4844. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4845. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4846. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4847. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4848. "\xa1";
  4849. d.inLen = 32;
  4850. d.outLen = 136;
  4851. /* Taken from NIST CAVP test vectors - more than one output block. */
  4852. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4853. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4854. "\x47\xe4";
  4855. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4856. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4857. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4858. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4859. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4860. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4861. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4862. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4863. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4864. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4865. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4866. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4867. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4868. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4869. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4870. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4871. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4";
  4872. e.inLen = 32;
  4873. e.outLen = 250;
  4874. test_sha[0] = a;
  4875. test_sha[1] = b;
  4876. test_sha[2] = c;
  4877. test_sha[3] = d;
  4878. test_sha[4] = e;
  4879. ret = wc_InitShake128(&sha, HEAP_HINT, devId);
  4880. if (ret != 0)
  4881. return WC_TEST_RET_ENC_EC(ret);
  4882. for (i = 0; i < times; ++i) {
  4883. ret = wc_Shake128_Update(&sha, (byte*)test_sha[i].input,
  4884. (word32)test_sha[i].inLen);
  4885. if (ret != 0)
  4886. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4887. ret = wc_Shake128_Final(&sha, hash, (word32)test_sha[i].outLen);
  4888. if (ret != 0)
  4889. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4890. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  4891. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4892. }
  4893. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4894. large_input = (byte *)XMALLOC(SHAKE128_LARGE_INPUT_BUFSIZ, NULL,
  4895. DYNAMIC_TYPE_TMP_BUFFER);
  4896. if (large_input == NULL)
  4897. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  4898. #endif
  4899. #ifndef NO_LARGE_HASH_TEST
  4900. /* BEGIN LARGE HASH TEST */ {
  4901. for (i = 0; i < SHAKE128_LARGE_INPUT_BUFSIZ; i++) {
  4902. large_input[i] = (byte)(i & 0xFF);
  4903. }
  4904. times = 100;
  4905. for (i = 0; i < times; ++i) {
  4906. ret = wc_Shake128_Update(&sha, (byte*)large_input,
  4907. SHAKE128_LARGE_INPUT_BUFSIZ);
  4908. if (ret != 0)
  4909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4910. }
  4911. ret = wc_Shake128_Final(&sha, hash, (word32)sizeof(hash));
  4912. if (ret != 0)
  4913. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4914. if (XMEMCMP(hash, large_digest, sizeof(large_digest) - 1) != 0)
  4915. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4916. } /* END LARGE HASH TEST */
  4917. #endif /* NO_LARGE_HASH_TEST */
  4918. ret = shake128_absorb_test(&sha, large_input, SHAKE128_LARGE_INPUT_BUFSIZ);
  4919. exit:
  4920. wc_Shake128_Free(&sha);
  4921. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4922. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4923. #endif
  4924. return ret;
  4925. }
  4926. #endif
  4927. #ifdef WOLFSSL_SHAKE256
  4928. static wc_test_ret_t shake256_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4929. size_t large_input_buf_size)
  4930. {
  4931. testVector a, b, c, d, e;
  4932. testVector test_sha[5];
  4933. wc_test_ret_t ret = 0;
  4934. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4935. static const char large_digest[] =
  4936. "\x21\x25\x8e\xae\x6e\x4f\xa7\xe1\xb9\x6d\xa7\xc9\x7d\x46\x03\x69"
  4937. "\x29\x0d\x81\x49\xba\x5d\xaf\x37\xfd\xeb\x25\x52\x1d\xd9\xbd\x65"
  4938. "\xfa\x99\xb9\xd1\x70\x6b\xeb\xd4\xc1\x2c\xea\x24\x20\x27\xa7\xcd"
  4939. "\xfa\xe1\x81\xd9\xd5\xc1\x1c\xc7\xe9\x70\xc3\xc7\x21\x6f\x32\x22"
  4940. "\xe3\x27\xdb\x58\x5e\xea\x18\x2d\x63\x4d\x14\x6c\x94\xcf\x2b\x7e"
  4941. "\x6e\x2a\x74\xf3\xe0\xac\xb3\xb2\xcc\xef\x38\xe9\xe7\x35\xb3\xc5"
  4942. "\x77\x9d\xff\xe3\x08\x8e\xf8\x2c\x89\xbb\x45\x22\x16\x99\x91\xc0"
  4943. "\xe7\x71\x57\x75\xc5\xb1\xc6\xaf\x27\xcb\x64\x8c\xc4\xee\x3d\x5f"
  4944. "\x4c\x35\xfb\x1c\xf3\xf8\x0e\xfd\x5e\xfc\x07\xd8\x4d\x55\x32\x49"
  4945. "\x45\x0d\xab\x4a\x49\xc4\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93"
  4946. "\x7a\xe6\x6b\xb4\x36\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43"
  4947. "\x2f\x3b\xfc\x09\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48"
  4948. "\x3d\x0e\xda\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08"
  4949. "\xd9\xdc\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a"
  4950. "\xb7\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  4951. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4\xe6"
  4952. "\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97\x68\x44";
  4953. byte hash[sizeof(large_digest) - 1];
  4954. /*
  4955. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  4956. */
  4957. a.input = "";
  4958. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  4959. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  4960. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  4961. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  4962. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  4963. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  4964. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  4965. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46\xc1\x85\xc1\x51\x11\xe5"
  4966. "\x95\x52\x2a\x6b\xcd\x16\xcf\x86\xf3\xd1\x22\x10\x9e\x3b\x1f"
  4967. "\xdd";
  4968. a.inLen = XSTRLEN(a.input);
  4969. a.outLen = WC_SHA3_256_BLOCK_SIZE;
  4970. b.input = "abc";
  4971. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  4972. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  4973. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  4974. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  4975. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  4976. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  4977. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  4978. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0\x9a\x3e\x6d\x51\xcb\xfc"
  4979. "\x62\x27\x20\xd7\xa7\x5c\x63\x34\xe8\xa2\xd7\xec\x71\xa7\xcc"
  4980. "\x29";
  4981. b.inLen = XSTRLEN(b.input);
  4982. b.outLen = WC_SHA3_256_BLOCK_SIZE;
  4983. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4984. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  4985. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  4986. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  4987. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  4988. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  4989. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  4990. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  4991. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4\x9d\xd3\xef\x7e\x18\x2b"
  4992. "\x15\x24\xdf\x82\xea\x1c\xef\xe1\xc6\xc3\x96\x61\x75\xf0\x22"
  4993. "\x8d";
  4994. c.inLen = XSTRLEN(c.input);
  4995. c.outLen = WC_SHA3_256_BLOCK_SIZE;
  4996. /* Taken from NIST CAVP test vectors - full rate output. */
  4997. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4998. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4999. "\x85\xe0";
  5000. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5001. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5002. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5003. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5004. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5005. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5006. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5007. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5008. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5009. "\xc2";
  5010. d.inLen = 32;
  5011. d.outLen = WC_SHA3_256_BLOCK_SIZE;
  5012. /* Taken from NIST CAVP test vectors - more than one output block. */
  5013. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5014. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5015. "\x47\xe4";
  5016. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5017. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5018. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5019. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5020. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5021. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5022. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5023. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5024. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5025. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5026. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5027. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5028. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5029. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5030. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5031. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5032. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4"
  5033. "\xe6\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97"
  5034. "\x68\x44";
  5035. e.inLen = 32;
  5036. e.outLen = 2 * WC_SHA3_256_BLOCK_SIZE;
  5037. test_sha[0] = a;
  5038. test_sha[1] = b;
  5039. test_sha[2] = c;
  5040. test_sha[3] = d;
  5041. test_sha[4] = e;
  5042. for (i = 0; i < times; ++i) {
  5043. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  5044. if (ret != 0)
  5045. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5046. ret = wc_Shake256_Absorb(sha, (byte*)test_sha[i].input,
  5047. (word32)test_sha[i].inLen);
  5048. if (ret != 0)
  5049. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5050. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  5051. (word32)test_sha[i].outLen / WC_SHA3_256_BLOCK_SIZE);
  5052. if (ret != 0)
  5053. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5054. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  5055. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5056. }
  5057. #ifndef NO_LARGE_HASH_TEST
  5058. /* BEGIN LARGE HASH TEST */ {
  5059. for (i = 0; i < (int)large_input_buf_size; i++) {
  5060. large_input_buf[i] = (byte)(i & 0xFF);
  5061. }
  5062. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  5063. if (ret != 0)
  5064. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5065. /* Absorb is non-incremental. */
  5066. ret = wc_Shake256_Absorb(sha, large_input_buf,
  5067. (word32)large_input_buf_size);
  5068. if (ret != 0)
  5069. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5070. /* Able to squeeze out blocks incrementally. */
  5071. ret = wc_Shake256_SqueezeBlocks(sha, hash, 1);
  5072. if (ret != 0)
  5073. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5074. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  5075. ((word32)sizeof(hash) / WC_SHA3_256_BLOCK_SIZE) - 1);
  5076. if (ret != 0)
  5077. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5078. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  5079. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5080. } /* END LARGE HASH TEST */
  5081. #endif /* NO_LARGE_HASH_TEST */
  5082. exit:
  5083. return ret;
  5084. }
  5085. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void)
  5086. {
  5087. wc_Shake sha;
  5088. byte hash[250];
  5089. testVector a, b, c, d, e;
  5090. testVector test_sha[5];
  5091. wc_test_ret_t ret = 0;
  5092. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  5093. #define SHAKE256_LARGE_INPUT_BUFSIZ 1024
  5094. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5095. byte *large_input = NULL;
  5096. #else
  5097. byte large_input[SHAKE256_LARGE_INPUT_BUFSIZ];
  5098. #endif
  5099. const char* large_digest =
  5100. "\x90\x32\x4a\xcc\xd1\xdf\xb8\x0b\x79\x1f\xb8\xc8\x5b\x54\xc8\xe7"
  5101. "\x45\xf5\x60\x6b\x38\x26\xb2\x0a\xee\x38\x01\xf3\xd9\xfa\x96\x9f"
  5102. "\x6a\xd7\x15\xdf\xb6\xc2\xf4\x20\x33\x44\x55\xe8\x2a\x09\x2b\x68"
  5103. "\x2e\x18\x65\x5e\x65\x93\x28\xbc\xb1\x9e\xe2\xb1\x92\xea\x98\xac"
  5104. "\x21\xef\x4c\xe1\xb4\xb7\xbe\x81\x5c\x1d\xd3\xb7\x17\xe5\xbb\xc5"
  5105. "\x8c\x68\xb7\xfb\xac\x55\x8a\x9b\x4d\x91\xe4\x9f\x72\xbb\x6e\x38"
  5106. "\xaf\x21\x7d\x21\xaa\x98\x4e\x75\xc4\xb4\x1c\x7c\x50\x45\x54\xf9"
  5107. "\xea\x26";
  5108. WOLFSSL_ENTER("shake256_test");
  5109. /*
  5110. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  5111. */
  5112. a.input = "";
  5113. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  5114. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  5115. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  5116. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  5117. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  5118. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  5119. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  5120. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46";
  5121. a.inLen = XSTRLEN(a.input);
  5122. a.outLen = 114;
  5123. b.input = "abc";
  5124. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  5125. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  5126. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  5127. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  5128. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  5129. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  5130. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  5131. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0";
  5132. b.inLen = XSTRLEN(b.input);
  5133. b.outLen = 114;
  5134. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5135. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  5136. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  5137. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  5138. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  5139. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  5140. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  5141. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  5142. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  5143. c.inLen = XSTRLEN(c.input);
  5144. c.outLen = 114;
  5145. /* Taken from NIST CAVP test vectors - full rate output. */
  5146. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  5147. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  5148. "\x85\xe0";
  5149. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5150. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5151. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5152. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5153. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5154. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5155. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5156. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5157. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5158. "\xc2";
  5159. d.inLen = 32;
  5160. d.outLen = 136;
  5161. /* Taken from NIST CAVP test vectors - more than one output block. */
  5162. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5163. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5164. "\x47\xe4";
  5165. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5166. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5167. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5168. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5169. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5170. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5171. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5172. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5173. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5174. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5175. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5176. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5177. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5178. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5179. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5180. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5181. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c";
  5182. e.inLen = 32;
  5183. e.outLen = 250;
  5184. test_sha[0] = a;
  5185. test_sha[1] = b;
  5186. test_sha[2] = c;
  5187. test_sha[3] = d;
  5188. test_sha[4] = e;
  5189. ret = wc_InitShake256(&sha, HEAP_HINT, devId);
  5190. if (ret != 0)
  5191. return WC_TEST_RET_ENC_EC(ret);
  5192. for (i = 0; i < times; ++i) {
  5193. ret = wc_Shake256_Update(&sha, (byte*)test_sha[i].input,
  5194. (word32)test_sha[i].inLen);
  5195. if (ret != 0)
  5196. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5197. ret = wc_Shake256_Final(&sha, hash, (word32)test_sha[i].outLen);
  5198. if (ret != 0)
  5199. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5200. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  5201. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5202. }
  5203. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5204. large_input = (byte *)XMALLOC(SHAKE256_LARGE_INPUT_BUFSIZ, NULL,
  5205. DYNAMIC_TYPE_TMP_BUFFER);
  5206. if (large_input == NULL)
  5207. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  5208. #endif
  5209. #ifndef NO_LARGE_HASH_TEST
  5210. /* BEGIN LARGE HASH TEST */ {
  5211. for (i = 0; i < SHAKE256_LARGE_INPUT_BUFSIZ; i++) {
  5212. large_input[i] = (byte)(i & 0xFF);
  5213. }
  5214. times = 100;
  5215. for (i = 0; i < times; ++i) {
  5216. ret = wc_Shake256_Update(&sha, (byte*)large_input,
  5217. SHAKE256_LARGE_INPUT_BUFSIZ);
  5218. if (ret != 0)
  5219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5220. }
  5221. ret = wc_Shake256_Final(&sha, hash, (word32)sizeof(hash));
  5222. if (ret != 0)
  5223. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5224. if (XMEMCMP(hash, large_digest, 114) != 0)
  5225. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5226. } /* END LARGE HASH TEST */
  5227. #endif /* NO_LARGE_HASH_TEST */
  5228. ret = shake256_absorb_test(&sha, large_input, SHAKE256_LARGE_INPUT_BUFSIZ);
  5229. exit:
  5230. wc_Shake256_Free(&sha);
  5231. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5232. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5233. #endif
  5234. return ret;
  5235. }
  5236. #endif
  5237. #ifdef WOLFSSL_SM3
  5238. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void)
  5239. {
  5240. wc_Sm3 sm3, sm3Copy;
  5241. byte hash[WC_SM3_DIGEST_SIZE];
  5242. byte hashGet[WC_SM3_DIGEST_SIZE];
  5243. byte hashCopy[WC_SM3_DIGEST_SIZE];
  5244. wc_test_ret_t ret = 0;
  5245. WOLFSSL_ENTER("sm3_test");
  5246. testVector a, b, c;
  5247. testVector test_sm3[3];
  5248. int times = sizeof(test_sm3) / sizeof(struct testVector), i;
  5249. a.input = "";
  5250. a.output = "\x1a\xb2\x1d\x83\x55\xcf\xa1\x7f\x8e\x61\x19\x48\x31\xe8\x1a"
  5251. "\x8f\x22\xbe\xc8\xc7\x28\xfe\xfb\x74\x7e\xd0\x35\xeb\x50\x82"
  5252. "\xaa\x2b";
  5253. a.inLen = XSTRLEN(a.input);
  5254. a.outLen = WC_SM3_DIGEST_SIZE;
  5255. b.input = "abc";
  5256. b.output = "\x66\xc7\xf0\xf4\x62\xee\xed\xd9\xd1\xf2\xd4\x6b\xdc\x10\xe4"
  5257. "\xe2\x41\x67\xc4\x87\x5c\xf2\xf7\xa2\x29\x7d\xa0\x2b\x8f\x4b"
  5258. "\xa8\xe0";
  5259. b.inLen = XSTRLEN(b.input);
  5260. b.outLen = WC_SM3_DIGEST_SIZE;
  5261. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5262. c.output = "\x63\x9b\x6c\xc5\xe6\x4d\x9e\x37\xa3\x90\xb1\x92\xdf\x4f\xa1"
  5263. "\xea\x07\x20\xab\x74\x7f\xf6\x92\xb9\xf3\x8c\x4e\x66\xad\x7b"
  5264. "\x8c\x05";
  5265. c.inLen = XSTRLEN(c.input);
  5266. c.outLen = WC_SM3_DIGEST_SIZE;
  5267. test_sm3[0] = a;
  5268. test_sm3[1] = b;
  5269. test_sm3[2] = c;
  5270. ret = wc_InitSm3(&sm3, HEAP_HINT, devId);
  5271. if (ret != 0)
  5272. return WC_TEST_RET_ENC_EC(ret);
  5273. ret = wc_InitSm3(&sm3Copy, HEAP_HINT, devId);
  5274. if (ret != 0) {
  5275. wc_Sm3Free(&sm3);
  5276. return WC_TEST_RET_ENC_EC(ret);
  5277. }
  5278. /* Test all the KATs. */
  5279. for (i = 0; i < times; ++i) {
  5280. ret = wc_Sm3Update(&sm3, (byte*)test_sm3[i].input,
  5281. (word32)test_sm3[i].inLen);
  5282. if (ret != 0) {
  5283. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5284. }
  5285. /* Get the final hash but leave ready for more updates. */
  5286. ret = wc_Sm3GetHash(&sm3, hashGet);
  5287. if (ret != 0)
  5288. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5289. /* Make a copy of the hash. */
  5290. ret = wc_Sm3Copy(&sm3, &sm3Copy);
  5291. if (ret != 0)
  5292. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5293. /* Get the final hash with original. */
  5294. ret = wc_Sm3Final(&sm3, hash);
  5295. if (ret != 0)
  5296. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5297. /* Get the final hash with copy. */
  5298. ret = wc_Sm3Final(&sm3Copy, hashCopy);
  5299. if (ret != 0)
  5300. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5301. /* Dispose of copy. */
  5302. wc_Sm3Free(&sm3Copy);
  5303. /* Check hashes match expected. */
  5304. if (XMEMCMP(hash, test_sm3[i].output, WC_SM3_DIGEST_SIZE) != 0)
  5305. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5306. if (XMEMCMP(hash, hashGet, WC_SM3_DIGEST_SIZE) != 0)
  5307. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5308. if (XMEMCMP(hash, hashCopy, WC_SM3_DIGEST_SIZE) != 0)
  5309. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5310. }
  5311. #ifndef NO_LARGE_HASH_TEST
  5312. {
  5313. word32 sz;
  5314. byte large_input[1024];
  5315. #ifdef HASH_SIZE_LIMIT
  5316. const char* large_digest =
  5317. "\x6c\x42\x57\x64\x8e\x45\xf3\xb6\xc0\x83\xd3\x41\x83\x66\x51\xb4"
  5318. "\x50\xfe\x06\xb5\xb7\x1e\xd5\x0d\x41\xfc\x1e\xe5\xc6\x57\x95\x0f";
  5319. times = 20;
  5320. #else
  5321. const char* large_digest =
  5322. "\x34\x51\x3c\xde\x7c\x30\xb7\xc5\xaa\x97\x3b\xed\xb3\x16\xb9\x76"
  5323. "\x35\x46\x14\x80\x2a\x57\xca\xd9\x48\xf9\x93\xcc\x1f\xdd\xab\x79";
  5324. times = 100;
  5325. #endif
  5326. /* Set large input to something. */
  5327. for (i = 0; i < (int)sizeof(large_input); i++) {
  5328. large_input[i] = (byte)(i & 0xFF);
  5329. }
  5330. /* Hash a large number of times. */
  5331. for (i = 0; i < times; ++i) {
  5332. ret = wc_Sm3Update(&sm3, (byte*)large_input,
  5333. (word32)sizeof(large_input));
  5334. if (ret != 0)
  5335. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5336. }
  5337. /* Calculate hash and compare to expected. */
  5338. ret = wc_Sm3Final(&sm3, hash);
  5339. if (ret != 0)
  5340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5341. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5343. /* Check updating with various sizes works. */
  5344. for (sz = 1; sz <= 64; sz++) {
  5345. /* Hash a large number of times. */
  5346. for (i = 0; i < times; ++i) {
  5347. word32 o;
  5348. /* Update sz bytes at a time from large input buffer. */
  5349. for (o = 0; o + sz <= (word32)sizeof(large_input); o += sz) {
  5350. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o), sz);
  5351. if (ret != 0)
  5352. ERROR_OUT(WC_TEST_RET_ENC_I(o), exit);
  5353. }
  5354. /* Check for left-overs. */
  5355. if (o < (word32)sizeof(large_input)) {
  5356. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o),
  5357. (word32)sizeof(large_input) - o);
  5358. if (ret != 0)
  5359. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5360. }
  5361. }
  5362. /* Calculate hash and compare to expected. */
  5363. ret = wc_Sm3Final(&sm3, hash);
  5364. if (ret != 0)
  5365. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5366. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5367. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5368. }
  5369. }
  5370. #endif /* NO_LARGE_HASH_TEST */
  5371. exit:
  5372. wc_Sm3Free(&sm3);
  5373. wc_Sm3Free(&sm3Copy);
  5374. return ret;
  5375. }
  5376. #endif
  5377. #ifndef NO_HASH_WRAPPER
  5378. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void)
  5379. {
  5380. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5381. wc_HashAlg *hash = NULL;
  5382. #else
  5383. wc_HashAlg hash[1];
  5384. #endif
  5385. int ret, exp_ret;
  5386. int i, j;
  5387. int digestSz;
  5388. byte data[] = "0123456789abcdef0123456789abcdef0123456";
  5389. byte out[WC_MAX_DIGEST_SIZE];
  5390. byte hashOut[WC_MAX_DIGEST_SIZE];
  5391. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5392. enum wc_HashType hashType;
  5393. #endif
  5394. enum wc_HashType typesGood[] = { WC_HASH_TYPE_MD5, WC_HASH_TYPE_SHA,
  5395. WC_HASH_TYPE_SHA224, WC_HASH_TYPE_SHA256,
  5396. WC_HASH_TYPE_SHA384, WC_HASH_TYPE_SHA512,
  5397. WC_HASH_TYPE_SHA3_224,
  5398. WC_HASH_TYPE_SHA3_256,
  5399. WC_HASH_TYPE_SHA3_384,
  5400. WC_HASH_TYPE_SHA3_512 };
  5401. enum wc_HashType typesNoImpl[] = {
  5402. #ifdef NO_MD5
  5403. WC_HASH_TYPE_MD5,
  5404. #endif
  5405. #ifdef NO_SHA
  5406. WC_HASH_TYPE_SHA,
  5407. #endif
  5408. #ifndef WOLFSSL_SHA224
  5409. WC_HASH_TYPE_SHA224,
  5410. #endif
  5411. #ifdef NO_SHA256
  5412. WC_HASH_TYPE_SHA256,
  5413. #endif
  5414. #ifndef WOLFSSL_SHA384
  5415. WC_HASH_TYPE_SHA384,
  5416. #endif
  5417. #ifndef WOLFSSL_SHA512
  5418. WC_HASH_TYPE_SHA512,
  5419. #endif
  5420. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_224)
  5421. WC_HASH_TYPE_SHA3_224,
  5422. #endif
  5423. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_256)
  5424. WC_HASH_TYPE_SHA3_256,
  5425. #endif
  5426. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_384)
  5427. WC_HASH_TYPE_SHA3_384,
  5428. #endif
  5429. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_512)
  5430. WC_HASH_TYPE_SHA3_512,
  5431. #endif
  5432. WC_HASH_TYPE_NONE
  5433. };
  5434. enum wc_HashType typesBad[] = { WC_HASH_TYPE_NONE, WC_HASH_TYPE_MD5_SHA,
  5435. WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4 };
  5436. enum wc_HashType typesHashBad[] = { WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4,
  5437. WC_HASH_TYPE_BLAKE2B,
  5438. WC_HASH_TYPE_NONE };
  5439. WOLFSSL_ENTER("hash_test");
  5440. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5441. hash = wc_HashNew(WC_HASH_TYPE_SHA256, HEAP_HINT, devId, &ret);
  5442. if (hash == NULL) {
  5443. return WC_TEST_RET_ENC_EC(ret);
  5444. }
  5445. #else
  5446. XMEMSET(hash, 0, sizeof(wc_HashAlg));
  5447. #endif
  5448. /* Parameter Validation testing. */
  5449. ret = wc_HashInit(NULL, WC_HASH_TYPE_SHA256);
  5450. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5451. return WC_TEST_RET_ENC_EC(ret);
  5452. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5453. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5454. return WC_TEST_RET_ENC_EC(ret);
  5455. ret = wc_HashUpdate(hash, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5456. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5457. return WC_TEST_RET_ENC_EC(ret);
  5458. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, data, sizeof(data));
  5459. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5460. return WC_TEST_RET_ENC_EC(ret);
  5461. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, NULL);
  5462. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5463. return WC_TEST_RET_ENC_EC(ret);
  5464. ret = wc_HashFinal(hash, WC_HASH_TYPE_SHA256, NULL);
  5465. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5466. return WC_TEST_RET_ENC_EC(ret);
  5467. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, out);
  5468. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5469. return WC_TEST_RET_ENC_EC(ret);
  5470. /* Try invalid hash algorithms. */
  5471. for (i = 0; i < (int)(sizeof(typesBad)/sizeof(*typesBad)); i++) {
  5472. ret = wc_HashInit(hash, typesBad[i]);
  5473. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5474. return WC_TEST_RET_ENC_I(i);
  5475. ret = wc_HashUpdate(hash, typesBad[i], data, sizeof(data));
  5476. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5477. return WC_TEST_RET_ENC_I(i);
  5478. ret = wc_HashFinal(hash, typesBad[i], out);
  5479. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5480. return WC_TEST_RET_ENC_I(i);
  5481. wc_HashFree(hash, typesBad[i]);
  5482. }
  5483. /* Try valid hash algorithms. */
  5484. for (i = 0, j = 0; i < (int)(sizeof(typesGood)/sizeof(*typesGood)); i++) {
  5485. exp_ret = 0;
  5486. if (typesGood[i] == typesNoImpl[j]) {
  5487. /* Recognized but no implementation compiled in. */
  5488. exp_ret = HASH_TYPE_E;
  5489. j++;
  5490. }
  5491. ret = wc_HashInit(hash, typesGood[i]);
  5492. if (ret != exp_ret)
  5493. return WC_TEST_RET_ENC_I(i);
  5494. ret = wc_HashUpdate(hash, typesGood[i], data, sizeof(data));
  5495. if (ret != exp_ret)
  5496. return WC_TEST_RET_ENC_I(i);
  5497. ret = wc_HashFinal(hash, typesGood[i], out);
  5498. if (ret != exp_ret)
  5499. return WC_TEST_RET_ENC_I(i);
  5500. wc_HashFree(hash, typesGood[i]);
  5501. digestSz = wc_HashGetDigestSize(typesGood[i]);
  5502. if (exp_ret < 0 && digestSz != exp_ret)
  5503. return WC_TEST_RET_ENC_I(i);
  5504. if (exp_ret == 0 && digestSz < 0)
  5505. return WC_TEST_RET_ENC_I(i);
  5506. if (exp_ret == 0) {
  5507. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut,
  5508. (word32)digestSz - 1);
  5509. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  5510. return WC_TEST_RET_ENC_I(i);
  5511. }
  5512. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, (word32)digestSz);
  5513. if (ret != exp_ret)
  5514. return WC_TEST_RET_ENC_I(i);
  5515. if (exp_ret == 0 && XMEMCMP(out, hashOut, (word32)digestSz) != 0)
  5516. return WC_TEST_RET_ENC_I(i);
  5517. ret = wc_HashGetBlockSize(typesGood[i]);
  5518. if (exp_ret < 0 && ret != exp_ret)
  5519. return WC_TEST_RET_ENC_I(i);
  5520. if (exp_ret == 0 && ret < 0)
  5521. return WC_TEST_RET_ENC_I(i);
  5522. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5523. ret = wc_HashGetOID(typesGood[i]);
  5524. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG) ||
  5525. (exp_ret == 0 && ret == WC_NO_ERR_TRACE(HASH_TYPE_E)) ||
  5526. (exp_ret != 0 && ret != WC_NO_ERR_TRACE(HASH_TYPE_E))) {
  5527. return WC_TEST_RET_ENC_I(i);
  5528. }
  5529. hashType = wc_OidGetHash(ret);
  5530. if (exp_ret == 0 && hashType != typesGood[i])
  5531. return WC_TEST_RET_ENC_I(i);
  5532. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5533. }
  5534. for (i = 0; i < (int)(sizeof(typesHashBad)/sizeof(*typesHashBad)); i++) {
  5535. ret = wc_Hash(typesHashBad[i], data, sizeof(data), out, sizeof(out));
  5536. if ((ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) &&
  5537. (ret != WC_NO_ERR_TRACE(BUFFER_E)) &&
  5538. (ret != WC_NO_ERR_TRACE(HASH_TYPE_E)))
  5539. {
  5540. return WC_TEST_RET_ENC_I(i);
  5541. }
  5542. }
  5543. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5544. ret = wc_HashGetOID(WC_HASH_TYPE_MD2);
  5545. #ifdef WOLFSSL_MD2
  5546. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5547. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5548. {
  5549. return WC_TEST_RET_ENC_EC(ret);
  5550. }
  5551. #else
  5552. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5553. return WC_TEST_RET_ENC_EC(ret);
  5554. #endif
  5555. hashType = wc_OidGetHash(646); /* Md2h */
  5556. #ifdef WOLFSSL_MD2
  5557. if (hashType != WC_HASH_TYPE_MD2)
  5558. return WC_TEST_RET_ENC_NC;
  5559. #else
  5560. if (hashType != WC_HASH_TYPE_NONE)
  5561. return WC_TEST_RET_ENC_NC;
  5562. #endif
  5563. ret = wc_HashGetOID(WC_HASH_TYPE_MD5_SHA);
  5564. #ifndef NO_MD5
  5565. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5566. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5567. {
  5568. return WC_TEST_RET_ENC_EC(ret);
  5569. }
  5570. #else
  5571. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5572. return WC_TEST_RET_ENC_EC(ret);
  5573. #endif
  5574. ret = wc_HashGetOID(WC_HASH_TYPE_MD4);
  5575. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5576. return WC_TEST_RET_ENC_EC(ret);
  5577. ret = wc_HashGetOID(WC_HASH_TYPE_NONE);
  5578. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5579. return WC_TEST_RET_ENC_EC(ret);
  5580. hashType = wc_OidGetHash(0);
  5581. if (hashType != WC_HASH_TYPE_NONE)
  5582. return WC_TEST_RET_ENC_NC;
  5583. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5584. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD2);
  5585. #ifdef WOLFSSL_MD2
  5586. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5587. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5588. {
  5589. return WC_TEST_RET_ENC_EC(ret);
  5590. }
  5591. #else
  5592. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5593. return WC_TEST_RET_ENC_EC(ret);
  5594. #endif
  5595. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD2);
  5596. #ifdef WOLFSSL_MD2
  5597. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5598. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5599. {
  5600. return WC_TEST_RET_ENC_EC(ret);
  5601. }
  5602. #else
  5603. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5604. return WC_TEST_RET_ENC_EC(ret);
  5605. #endif
  5606. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD4);
  5607. #ifndef NO_MD4
  5608. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5609. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5610. {
  5611. return WC_TEST_RET_ENC_EC(ret);
  5612. }
  5613. #else
  5614. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5615. return WC_TEST_RET_ENC_EC(ret);
  5616. #endif
  5617. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD4);
  5618. #ifndef NO_MD4
  5619. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5620. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5621. {
  5622. return WC_TEST_RET_ENC_EC(ret);
  5623. }
  5624. #else
  5625. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5626. return WC_TEST_RET_ENC_EC(ret);
  5627. #endif
  5628. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD5_SHA);
  5629. #if !defined(NO_MD5) && !defined(NO_SHA)
  5630. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5631. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5632. {
  5633. return WC_TEST_RET_ENC_EC(ret);
  5634. }
  5635. #else
  5636. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5637. return WC_TEST_RET_ENC_EC(ret);
  5638. #endif
  5639. ret = wc_HashGetBlockSize(WC_HASH_TYPE_BLAKE2B);
  5640. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5641. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5642. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5643. {
  5644. return WC_TEST_RET_ENC_EC(ret);
  5645. }
  5646. #else
  5647. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5648. return WC_TEST_RET_ENC_EC(ret);
  5649. #endif
  5650. ret = wc_HashGetDigestSize(WC_HASH_TYPE_BLAKE2B);
  5651. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5652. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5653. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5654. {
  5655. return WC_TEST_RET_ENC_EC(ret);
  5656. }
  5657. #else
  5658. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5659. return WC_TEST_RET_ENC_EC(ret);
  5660. #endif
  5661. ret = wc_HashGetBlockSize(WC_HASH_TYPE_NONE);
  5662. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5663. return WC_TEST_RET_ENC_EC(ret);
  5664. ret = wc_HashGetDigestSize(WC_HASH_TYPE_NONE);
  5665. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5666. return WC_TEST_RET_ENC_EC(ret);
  5667. #if !defined(NO_CERTS) && !defined(NO_ASN)
  5668. #if defined(WOLFSSL_MD2) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  5669. ret = wc_GetCTC_HashOID(MD2);
  5670. if (ret == 0)
  5671. return WC_TEST_RET_ENC_EC(ret);
  5672. #endif
  5673. #ifndef NO_MD5
  5674. ret = wc_GetCTC_HashOID(WC_MD5);
  5675. if (ret == 0)
  5676. return WC_TEST_RET_ENC_EC(ret);
  5677. #endif
  5678. #ifndef NO_SHA
  5679. ret = wc_GetCTC_HashOID(WC_SHA);
  5680. if (ret == 0)
  5681. return WC_TEST_RET_ENC_EC(ret);
  5682. #endif
  5683. #ifdef WOLFSSL_SHA224
  5684. ret = wc_GetCTC_HashOID(WC_SHA224);
  5685. if (ret == 0)
  5686. return WC_TEST_RET_ENC_EC(ret);
  5687. #endif
  5688. #ifndef NO_SHA256
  5689. ret = wc_GetCTC_HashOID(WC_SHA256);
  5690. if (ret == 0)
  5691. return WC_TEST_RET_ENC_EC(ret);
  5692. #endif
  5693. #ifdef WOLFSSL_SHA384
  5694. ret = wc_GetCTC_HashOID(WC_SHA384);
  5695. if (ret == 0)
  5696. return WC_TEST_RET_ENC_EC(ret);
  5697. #endif
  5698. #ifdef WOLFSSL_SHA512
  5699. ret = wc_GetCTC_HashOID(WC_SHA512);
  5700. if (ret == 0)
  5701. return WC_TEST_RET_ENC_EC(ret);
  5702. #endif
  5703. ret = wc_GetCTC_HashOID(-1);
  5704. if (ret != 0)
  5705. return WC_TEST_RET_ENC_EC(ret);
  5706. #endif
  5707. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5708. (void)wc_HashDelete(hash, &hash);
  5709. #endif
  5710. return 0;
  5711. }
  5712. #endif /* !NO_HASH_WRAPPER */
  5713. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS) && \
  5714. defined(HAVE_FIPS_VERSION) && \
  5715. (HAVE_FIPS_VERSION >= 5))
  5716. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void)
  5717. {
  5718. Hmac hmac;
  5719. byte hash[WC_MD5_DIGEST_SIZE];
  5720. const char* keys[]=
  5721. {
  5722. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  5723. "Jefe",
  5724. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA",
  5725. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5726. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5727. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5728. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5729. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5730. };
  5731. testVector a, b, c, d;
  5732. testVector test_hmac[4];
  5733. wc_test_ret_t ret;
  5734. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5735. WOLFSSL_ENTER("hmac_md5_test");
  5736. /* Following test vectors are from RFC 2202 section 2 */
  5737. a.input = "Hi There";
  5738. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  5739. "\x9d";
  5740. a.inLen = XSTRLEN(a.input);
  5741. a.outLen = WC_MD5_DIGEST_SIZE;
  5742. b.input = "what do ya want for nothing?";
  5743. b.output = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
  5744. "\x38";
  5745. b.inLen = XSTRLEN(b.input);
  5746. b.outLen = WC_MD5_DIGEST_SIZE;
  5747. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5748. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5749. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5750. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5751. c.output = "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
  5752. "\xf6";
  5753. c.inLen = XSTRLEN(c.input);
  5754. c.outLen = WC_MD5_DIGEST_SIZE;
  5755. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5756. d.output = "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0"
  5757. "\xcd";
  5758. d.inLen = XSTRLEN(d.input);
  5759. d.outLen = WC_MD5_DIGEST_SIZE;
  5760. test_hmac[0] = a;
  5761. test_hmac[1] = b;
  5762. test_hmac[2] = c;
  5763. test_hmac[3] = d;
  5764. for (i = 0; i < times; ++i) {
  5765. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5766. if (i == 1) {
  5767. continue; /* cavium can't handle short keys, fips not allowed */
  5768. }
  5769. #endif
  5770. ret = wc_HmacInit(&hmac, HEAP_HINT, devId);
  5771. if (ret != 0)
  5772. return WC_TEST_RET_ENC_EC(ret);
  5773. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i],
  5774. (word32)XSTRLEN(keys[i]));
  5775. if (ret != 0)
  5776. return WC_TEST_RET_ENC_EC(ret);
  5777. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5778. (word32)test_hmac[i].inLen);
  5779. if (ret != 0)
  5780. return WC_TEST_RET_ENC_EC(ret);
  5781. ret = wc_HmacFinal(&hmac, hash);
  5782. if (ret != 0)
  5783. return WC_TEST_RET_ENC_EC(ret);
  5784. if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0)
  5785. return WC_TEST_RET_ENC_I(i);
  5786. wc_HmacFree(&hmac);
  5787. }
  5788. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5789. if ((ret = wc_HmacSizeByType(WC_MD5)) != WC_MD5_DIGEST_SIZE)
  5790. return WC_TEST_RET_ENC_EC(ret);
  5791. #endif
  5792. return 0;
  5793. }
  5794. #endif /* !NO_HMAC && !NO_MD5 && (!HAVE_FIPS || (HAVE_FIPS_VERSION < 5)) */
  5795. #if !defined(NO_HMAC) && !defined(NO_SHA)
  5796. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void)
  5797. {
  5798. Hmac hmac;
  5799. byte hash[WC_SHA_DIGEST_SIZE];
  5800. const char* keys[]=
  5801. {
  5802. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5803. "\x0b\x0b\x0b",
  5804. "Jefe",
  5805. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5806. "\xAA\xAA\xAA",
  5807. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5808. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5809. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5810. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5811. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5812. };
  5813. testVector a, b, c, d;
  5814. testVector test_hmac[4];
  5815. wc_test_ret_t ret;
  5816. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5817. WOLFSSL_ENTER("hmac_sha_test");
  5818. /* Following test vectors are from RFC 2202 section 3 */
  5819. a.input = "Hi There";
  5820. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  5821. "\x8e\xf1\x46\xbe\x00";
  5822. a.inLen = XSTRLEN(a.input);
  5823. a.outLen = WC_SHA_DIGEST_SIZE;
  5824. b.input = "what do ya want for nothing?";
  5825. b.output = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf"
  5826. "\x9c\x25\x9a\x7c\x79";
  5827. b.inLen = XSTRLEN(b.input);
  5828. b.outLen = WC_SHA_DIGEST_SIZE;
  5829. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5830. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5831. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5832. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5833. c.output = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b"
  5834. "\x4f\x63\xf1\x75\xd3";
  5835. c.inLen = XSTRLEN(c.input);
  5836. c.outLen = WC_SHA_DIGEST_SIZE;
  5837. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5838. d.output = "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b"
  5839. "\x55\xed\x40\x21\x12";
  5840. d.inLen = XSTRLEN(d.input);
  5841. d.outLen = WC_SHA_DIGEST_SIZE;
  5842. test_hmac[0] = a;
  5843. test_hmac[1] = b;
  5844. test_hmac[2] = c;
  5845. test_hmac[3] = d;
  5846. #if FIPS_VERSION3_GE(6,0,0)
  5847. int allowShortKeyWithFips = 1;
  5848. #endif
  5849. for (i = 0; i < times; ++i) {
  5850. #if defined(HAVE_CAVIUM) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0))
  5851. if (i == 1)
  5852. continue; /* cavium can't handle short keys, fips not allowed */
  5853. #endif
  5854. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5855. return WC_TEST_RET_ENC_EC(ret);
  5856. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i],
  5857. (word32)XSTRLEN(keys[i]));
  5858. #if FIPS_VERSION3_GE(6,0,0)
  5859. if (i == 1) {
  5860. if (ret != WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E))
  5861. return WC_TEST_RET_ENC_EC(ret);
  5862. /* Now use the ex and allow short keys with FIPS option */
  5863. ret = wc_HmacSetKey_ex(&hmac, WC_SHA, (byte*) keys[i],
  5864. (word32)XSTRLEN(keys[i]), allowShortKeyWithFips);
  5865. }
  5866. #endif
  5867. if (ret != 0)
  5868. return WC_TEST_RET_ENC_EC(ret);
  5869. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5870. (word32)test_hmac[i].inLen);
  5871. if (ret != 0)
  5872. return WC_TEST_RET_ENC_EC(ret);
  5873. ret = wc_HmacFinal(&hmac, hash);
  5874. if (ret != 0)
  5875. return WC_TEST_RET_ENC_EC(ret);
  5876. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0)
  5877. return WC_TEST_RET_ENC_I(i);
  5878. wc_HmacFree(&hmac);
  5879. }
  5880. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5881. if ((ret = wc_HmacSizeByType(WC_SHA)) != WC_SHA_DIGEST_SIZE)
  5882. return WC_TEST_RET_ENC_EC(ret);
  5883. #endif
  5884. return 0;
  5885. }
  5886. #endif
  5887. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  5888. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void)
  5889. {
  5890. Hmac hmac;
  5891. byte hash[WC_SHA224_DIGEST_SIZE];
  5892. const char* keys[]=
  5893. {
  5894. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5895. "\x0b\x0b\x0b",
  5896. "Jefe",
  5897. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5898. "\xAA\xAA\xAA",
  5899. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5900. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5901. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5902. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5903. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5904. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5905. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5906. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5907. "\xAA\xAA\xAA"
  5908. };
  5909. testVector a, b, c, d;
  5910. testVector test_hmac[4];
  5911. wc_test_ret_t ret;
  5912. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5913. WOLFSSL_ENTER("hmac_sha224_test");
  5914. /* Following test vectors are from RFC 4231 section 4 */
  5915. a.input = "Hi There";
  5916. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  5917. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  5918. a.inLen = XSTRLEN(a.input);
  5919. a.outLen = WC_SHA224_DIGEST_SIZE;
  5920. b.input = "what do ya want for nothing?";
  5921. b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
  5922. "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
  5923. b.inLen = XSTRLEN(b.input);
  5924. b.outLen = WC_SHA224_DIGEST_SIZE;
  5925. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5926. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5927. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5928. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5929. c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
  5930. "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
  5931. c.inLen = XSTRLEN(c.input);
  5932. c.outLen = WC_SHA224_DIGEST_SIZE;
  5933. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5934. d.output = "\x95\xe9\xa0\xdb\x96\x20\x95\xad\xae\xbe\x9b\x2d\x6f\x0d\xbc\xe2\xd4\x99\xf1\x12\xf2\xd2\xb7\x27\x3f\xa6\x87\x0e";
  5935. d.inLen = XSTRLEN(d.input);
  5936. d.outLen = WC_SHA224_DIGEST_SIZE;
  5937. test_hmac[0] = a;
  5938. test_hmac[1] = b;
  5939. test_hmac[2] = c;
  5940. test_hmac[3] = d;
  5941. for (i = 0; i < times; ++i) {
  5942. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5943. if (i == 1)
  5944. continue; /* cavium can't handle short keys, fips not allowed */
  5945. #endif
  5946. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5947. return WC_TEST_RET_ENC_EC(ret);
  5948. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i],
  5949. (word32)XSTRLEN(keys[i]));
  5950. if (ret != 0)
  5951. return WC_TEST_RET_ENC_EC(ret);
  5952. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5953. (word32)test_hmac[i].inLen);
  5954. if (ret != 0)
  5955. return WC_TEST_RET_ENC_EC(ret);
  5956. ret = wc_HmacFinal(&hmac, hash);
  5957. if (ret != 0)
  5958. return WC_TEST_RET_ENC_EC(ret);
  5959. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  5960. return WC_TEST_RET_ENC_I(i);
  5961. wc_HmacFree(&hmac);
  5962. }
  5963. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5964. if ((ret = wc_HmacSizeByType(WC_SHA224)) != WC_SHA224_DIGEST_SIZE)
  5965. return WC_TEST_RET_ENC_EC(ret);
  5966. #endif
  5967. return 0;
  5968. }
  5969. #endif
  5970. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  5971. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void)
  5972. {
  5973. Hmac hmac;
  5974. byte hash[WC_SHA256_DIGEST_SIZE];
  5975. const char* keys[]=
  5976. {
  5977. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5978. "\x0b\x0b\x0b",
  5979. "Jefe",
  5980. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5981. "\xAA\xAA\xAA",
  5982. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5983. "\xAA\xAA\xAA",
  5984. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5985. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5986. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5987. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5988. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5989. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5990. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5991. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5992. "\xAA\xAA\xAA"
  5993. };
  5994. testVector a, b, c, d, e;
  5995. testVector test_hmac[5];
  5996. wc_test_ret_t ret;
  5997. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5998. WOLFSSL_ENTER("hmac_sha256_test");
  5999. /* Following test vectors are from RFC 4231 section 4 */
  6000. a.input = "Hi There";
  6001. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  6002. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  6003. "\xcf\xf7";
  6004. a.inLen = XSTRLEN(a.input);
  6005. a.outLen = WC_SHA256_DIGEST_SIZE;
  6006. b.input = "what do ya want for nothing?";
  6007. b.output = "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75"
  6008. "\xc7\x5a\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec"
  6009. "\x38\x43";
  6010. b.inLen = XSTRLEN(b.input);
  6011. b.outLen = WC_SHA256_DIGEST_SIZE;
  6012. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6013. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6014. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6015. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6016. c.output = "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81"
  6017. "\xa7\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5"
  6018. "\x65\xfe";
  6019. c.inLen = XSTRLEN(c.input);
  6020. c.outLen = WC_SHA256_DIGEST_SIZE;
  6021. d.input = 0;
  6022. d.output = "\x86\xe5\x4f\xd4\x48\x72\x5d\x7e\x5d\xcf\xe2\x23\x53\xc8\x28"
  6023. "\xaf\x48\x78\x1e\xb4\x8c\xae\x81\x06\xa7\xe1\xd4\x98\x94\x9f"
  6024. "\x3e\x46";
  6025. d.inLen = 0;
  6026. d.outLen = WC_SHA256_DIGEST_SIZE;
  6027. e.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6028. e.output = "\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7"
  6029. "\x7f\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3"
  6030. "\x7f\x54";
  6031. e.inLen = XSTRLEN(e.input);;
  6032. e.outLen = WC_SHA256_DIGEST_SIZE;
  6033. test_hmac[0] = a;
  6034. test_hmac[1] = b;
  6035. test_hmac[2] = c;
  6036. test_hmac[3] = d;
  6037. test_hmac[4] = e;
  6038. for (i = 0; i < times; ++i) {
  6039. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  6040. if (i == 1)
  6041. continue; /* cavium can't handle short keys, fips not allowed */
  6042. #endif
  6043. #if defined(HAVE_INTEL_QA) || defined(HAVE_CAVIUM)
  6044. if (i == 3)
  6045. continue; /* QuickAssist can't handle empty HMAC */
  6046. #endif
  6047. if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0)
  6048. return WC_TEST_RET_ENC_I(i);
  6049. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i],
  6050. (word32)XSTRLEN(keys[i]));
  6051. if (ret != 0)
  6052. return WC_TEST_RET_ENC_I(i);
  6053. if (test_hmac[i].input != NULL) {
  6054. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6055. (word32)test_hmac[i].inLen);
  6056. if (ret != 0)
  6057. return WC_TEST_RET_ENC_I(i);
  6058. }
  6059. ret = wc_HmacFinal(&hmac, hash);
  6060. if (ret != 0)
  6061. return WC_TEST_RET_ENC_I(i);
  6062. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0)
  6063. return WC_TEST_RET_ENC_I(i);
  6064. wc_HmacFree(&hmac);
  6065. }
  6066. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6067. if ((ret = wc_HmacSizeByType(WC_SHA256)) != WC_SHA256_DIGEST_SIZE)
  6068. return WC_TEST_RET_ENC_EC(ret);
  6069. #if FIPS_VERSION3_GE(6,0,0)
  6070. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(HMAC_KAT_FIPS_E))
  6071. #else
  6072. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  6073. #endif
  6074. {
  6075. return WC_TEST_RET_ENC_EC(ret);
  6076. }
  6077. #endif
  6078. if ((ret = wolfSSL_GetHmacMaxSize()) != WC_MAX_DIGEST_SIZE)
  6079. return WC_TEST_RET_ENC_EC(ret);
  6080. return 0;
  6081. }
  6082. #endif
  6083. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  6084. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void)
  6085. {
  6086. Hmac hmac;
  6087. byte hash[WC_SHA384_DIGEST_SIZE];
  6088. const char* keys[]=
  6089. {
  6090. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6091. "\x0b\x0b\x0b",
  6092. "Jefe",
  6093. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6094. "\xAA\xAA\xAA",
  6095. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6096. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6097. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6098. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6099. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6100. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6101. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6102. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6103. "\xAA\xAA\xAA"
  6104. };
  6105. testVector a, b, c, d;
  6106. testVector test_hmac[4];
  6107. wc_test_ret_t ret;
  6108. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6109. WOLFSSL_ENTER("hmac_sha384_test");
  6110. /* Following test vectors are from RFC 4231 section 4 */
  6111. a.input = "Hi There";
  6112. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  6113. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  6114. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  6115. "\xfa\x9c\xb6";
  6116. a.inLen = XSTRLEN(a.input);
  6117. a.outLen = WC_SHA384_DIGEST_SIZE;
  6118. b.input = "what do ya want for nothing?";
  6119. b.output = "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b"
  6120. "\x1b\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22"
  6121. "\x44\x5e\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa"
  6122. "\xb2\x16\x49";
  6123. b.inLen = XSTRLEN(b.input);
  6124. b.outLen = WC_SHA384_DIGEST_SIZE;
  6125. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6126. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6127. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6128. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6129. c.output = "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8"
  6130. "\x6f\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66"
  6131. "\x14\x4b\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01"
  6132. "\xa3\x4f\x27";
  6133. c.inLen = XSTRLEN(c.input);
  6134. c.outLen = WC_SHA384_DIGEST_SIZE;
  6135. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6136. d.output = "\x4e\xce\x08\x44\x85\x81\x3e\x90\x88\xd2\xc6\x3a\x04\x1b\xc5"
  6137. "\xb4\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f\x3c\xd1\x1f\x05\x03\x3a"
  6138. "\xc4\xc6\x0c\x2e\xf6\xab\x40\x30\xfe\x82\x96\x24\x8d\xf1\x63"
  6139. "\xf4\x49\x52";
  6140. d.inLen = XSTRLEN(d.input);
  6141. d.outLen = WC_SHA384_DIGEST_SIZE;
  6142. test_hmac[0] = a;
  6143. test_hmac[1] = b;
  6144. test_hmac[2] = c;
  6145. test_hmac[3] = d;
  6146. for (i = 0; i < times; ++i) {
  6147. #if defined(HAVE_FIPS)
  6148. if (i == 1)
  6149. continue; /* fips not allowed */
  6150. #endif
  6151. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6152. return WC_TEST_RET_ENC_EC(ret);
  6153. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i],
  6154. (word32)XSTRLEN(keys[i]));
  6155. if (ret != 0)
  6156. return WC_TEST_RET_ENC_EC(ret);
  6157. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6158. (word32)test_hmac[i].inLen);
  6159. if (ret != 0)
  6160. return WC_TEST_RET_ENC_EC(ret);
  6161. ret = wc_HmacFinal(&hmac, hash);
  6162. if (ret != 0)
  6163. return WC_TEST_RET_ENC_EC(ret);
  6164. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  6165. return WC_TEST_RET_ENC_I(i);
  6166. wc_HmacFree(&hmac);
  6167. }
  6168. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6169. if ((ret = wc_HmacSizeByType(WC_SHA384)) != WC_SHA384_DIGEST_SIZE)
  6170. return WC_TEST_RET_ENC_EC(ret);
  6171. #endif
  6172. return 0;
  6173. }
  6174. #endif
  6175. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA512)
  6176. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void)
  6177. {
  6178. Hmac hmac;
  6179. byte hash[WC_SHA512_DIGEST_SIZE];
  6180. const char* keys[]=
  6181. {
  6182. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6183. "\x0b\x0b\x0b",
  6184. "Jefe",
  6185. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6186. "\xAA\xAA\xAA",
  6187. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6188. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6189. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6190. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6191. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6192. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6193. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6194. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6195. "\xAA\xAA\xAA"
  6196. };
  6197. testVector a, b, c, d;
  6198. testVector test_hmac[4];
  6199. wc_test_ret_t ret;
  6200. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6201. WOLFSSL_ENTER("hmac_sha512_test");
  6202. /* Following test vectors are from RFC 4231 section 4 */
  6203. a.input = "Hi There";
  6204. a.output = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c"
  6205. "\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1"
  6206. "\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae"
  6207. "\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20"
  6208. "\x3a\x12\x68\x54";
  6209. a.inLen = XSTRLEN(a.input);
  6210. a.outLen = WC_SHA512_DIGEST_SIZE;
  6211. b.input = "what do ya want for nothing?";
  6212. b.output = "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2\xe3\x95\xfb\xe7\x3b\x56\xe0"
  6213. "\xa3\x87\xbd\x64\x22\x2e\x83\x1f\xd6\x10\x27\x0c\xd7\xea\x25"
  6214. "\x05\x54\x97\x58\xbf\x75\xc0\x5a\x99\x4a\x6d\x03\x4f\x65\xf8"
  6215. "\xf0\xe6\xfd\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b\x63\x6e\x07\x0a"
  6216. "\x38\xbc\xe7\x37";
  6217. b.inLen = XSTRLEN(b.input);
  6218. b.outLen = WC_SHA512_DIGEST_SIZE;
  6219. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6220. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6221. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6222. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6223. c.output = "\xfa\x73\xb0\x08\x9d\x56\xa2\x84\xef\xb0\xf0\x75\x6c\x89\x0b"
  6224. "\xe9\xb1\xb5\xdb\xdd\x8e\xe8\x1a\x36\x55\xf8\x3e\x33\xb2\x27"
  6225. "\x9d\x39\xbf\x3e\x84\x82\x79\xa7\x22\xc8\x06\xb4\x85\xa4\x7e"
  6226. "\x67\xc8\x07\xb9\x46\xa3\x37\xbe\xe8\x94\x26\x74\x27\x88\x59"
  6227. "\xe1\x32\x92\xfb";
  6228. c.inLen = XSTRLEN(c.input);
  6229. c.outLen = WC_SHA512_DIGEST_SIZE;
  6230. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6231. d.output = "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb\xb7\x14\x93\xc1\xdd\x7b\xe8"
  6232. "\xb4\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1\x12\x1b\x01\x37\x83\xf8"
  6233. "\xf3\x52\x6b\x56\xd0\x37\xe0\x5f\x25\x98\xbd\x0f\xd2\x21\x5d"
  6234. "\x6a\x1e\x52\x95\xe6\x4f\x73\xf6\x3f\x0a\xec\x8b\x91\x5a\x98"
  6235. "\x5d\x78\x65\x98";
  6236. d.inLen = XSTRLEN(d.input);
  6237. d.outLen = WC_SHA512_DIGEST_SIZE;
  6238. test_hmac[0] = a;
  6239. test_hmac[1] = b;
  6240. test_hmac[2] = c;
  6241. test_hmac[3] = d;
  6242. for (i = 0; i < times; ++i) {
  6243. #if defined(HAVE_FIPS)
  6244. if (i == 1)
  6245. continue; /* fips not allowed */
  6246. #endif
  6247. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6248. return WC_TEST_RET_ENC_EC(ret);
  6249. ret = wc_HmacSetKey(&hmac, WC_SHA512, (byte*)keys[i],
  6250. (word32)XSTRLEN(keys[i]));
  6251. if (ret != 0)
  6252. return WC_TEST_RET_ENC_EC(ret);
  6253. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6254. (word32)test_hmac[i].inLen);
  6255. if (ret != 0)
  6256. return WC_TEST_RET_ENC_EC(ret);
  6257. ret = wc_HmacFinal(&hmac, hash);
  6258. if (ret != 0)
  6259. return WC_TEST_RET_ENC_EC(ret);
  6260. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  6261. return WC_TEST_RET_ENC_I(i);
  6262. wc_HmacFree(&hmac);
  6263. }
  6264. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6265. if ((ret = wc_HmacSizeByType(WC_SHA512)) != WC_SHA512_DIGEST_SIZE)
  6266. return WC_TEST_RET_ENC_EC(ret);
  6267. #endif
  6268. return 0;
  6269. }
  6270. #endif
  6271. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  6272. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  6273. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  6274. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void)
  6275. {
  6276. Hmac hmac;
  6277. byte hash[WC_SHA3_512_DIGEST_SIZE];
  6278. const char* key[4] =
  6279. {
  6280. "Jefe",
  6281. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6282. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  6283. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
  6284. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
  6285. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6286. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6287. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6288. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6289. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6290. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6291. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6292. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6293. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6294. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6295. };
  6296. const char* input[4] =
  6297. {
  6298. "what do ya want for nothing?",
  6299. "Hi There",
  6300. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6301. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6302. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6303. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6304. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
  6305. "Big Key Input"
  6306. };
  6307. const int hashType[4] =
  6308. {
  6309. WC_SHA3_224, WC_SHA3_256, WC_SHA3_384, WC_SHA3_512
  6310. };
  6311. const int hashSz[4] =
  6312. {
  6313. WC_SHA3_224_DIGEST_SIZE, WC_SHA3_256_DIGEST_SIZE,
  6314. WC_SHA3_384_DIGEST_SIZE, WC_SHA3_512_DIGEST_SIZE
  6315. };
  6316. const char* output[16] =
  6317. {
  6318. /* key = jefe, input = what do ya want for nothing? */
  6319. /* HMAC-SHA3-224 */
  6320. "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11"
  6321. "\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66",
  6322. /* HMAC-SHA3-256 */
  6323. "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87"
  6324. "\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5",
  6325. /* HMAC-SHA3-384 */
  6326. "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21"
  6327. "\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce"
  6328. "\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a",
  6329. /* HMAC-SHA3-512 */
  6330. "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83"
  6331. "\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b"
  6332. "\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e"
  6333. "\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24",
  6334. /* key = 0b..., input = Hi There */
  6335. /* HMAC-SHA3-224 */
  6336. "\x3b\x16\x54\x6b\xbc\x7b\xe2\x70\x6a\x03\x1d\xca\xfd\x56\x37\x3d"
  6337. "\x98\x84\x36\x76\x41\xd8\xc5\x9a\xf3\xc8\x60\xf7",
  6338. /* HMAC-SHA3-256 */
  6339. "\xba\x85\x19\x23\x10\xdf\xfa\x96\xe2\xa3\xa4\x0e\x69\x77\x43\x51"
  6340. "\x14\x0b\xb7\x18\x5e\x12\x02\xcd\xcc\x91\x75\x89\xf9\x5e\x16\xbb",
  6341. /* HMAC-SHA3-384 */
  6342. "\x68\xd2\xdc\xf7\xfd\x4d\xdd\x0a\x22\x40\xc8\xa4\x37\x30\x5f\x61"
  6343. "\xfb\x73\x34\xcf\xb5\xd0\x22\x6e\x1b\xc2\x7d\xc1\x0a\x2e\x72\x3a"
  6344. "\x20\xd3\x70\xb4\x77\x43\x13\x0e\x26\xac\x7e\x3d\x53\x28\x86\xbd",
  6345. /* HMAC-SHA3-512 */
  6346. "\xeb\x3f\xbd\x4b\x2e\xaa\xb8\xf5\xc5\x04\xbd\x3a\x41\x46\x5a\xac"
  6347. "\xec\x15\x77\x0a\x7c\xab\xac\x53\x1e\x48\x2f\x86\x0b\x5e\xc7\xba"
  6348. "\x47\xcc\xb2\xc6\xf2\xaf\xce\x8f\x88\xd2\x2b\x6d\xc6\x13\x80\xf2"
  6349. "\x3a\x66\x8f\xd3\x88\x8b\xb8\x05\x37\xc0\xa0\xb8\x64\x07\x68\x9e",
  6350. /* key = aa..., output = dd... */
  6351. /* HMAC-SHA3-224 */
  6352. "\x67\x6c\xfc\x7d\x16\x15\x36\x38\x78\x03\x90\x69\x2b\xe1\x42\xd2"
  6353. "\xdf\x7c\xe9\x24\xb9\x09\xc0\xc0\x8d\xbf\xdc\x1a",
  6354. /* HMAC-SHA3-256 */
  6355. "\x84\xec\x79\x12\x4a\x27\x10\x78\x65\xce\xdd\x8b\xd8\x2d\xa9\x96"
  6356. "\x5e\x5e\xd8\xc3\x7b\x0a\xc9\x80\x05\xa7\xf3\x9e\xd5\x8a\x42\x07",
  6357. /* HMAC-SHA3-384 */
  6358. "\x27\x5c\xd0\xe6\x61\xbb\x8b\x15\x1c\x64\xd2\x88\xf1\xf7\x82\xfb"
  6359. "\x91\xa8\xab\xd5\x68\x58\xd7\x2b\xab\xb2\xd4\x76\xf0\x45\x83\x73"
  6360. "\xb4\x1b\x6a\xb5\xbf\x17\x4b\xec\x42\x2e\x53\xfc\x31\x35\xac\x6e",
  6361. /* HMAC-SHA3-512 */
  6362. "\x30\x9e\x99\xf9\xec\x07\x5e\xc6\xc6\xd4\x75\xed\xa1\x18\x06\x87"
  6363. "\xfc\xf1\x53\x11\x95\x80\x2a\x99\xb5\x67\x74\x49\xa8\x62\x51\x82"
  6364. "\x85\x1c\xb3\x32\xaf\xb6\xa8\x9c\x41\x13\x25\xfb\xcb\xcd\x42\xaf"
  6365. "\xcb\x7b\x6e\x5a\xab\x7e\xa4\x2c\x66\x0f\x97\xfd\x85\x84\xbf\x03",
  6366. /* key = big key, input = Big Key Input */
  6367. /* HMAC-SHA3-224 */
  6368. "\x29\xe0\x5e\x46\xc4\xa4\x5e\x46\x74\xbf\xd7\x2d\x1a\xd8\x66\xdb"
  6369. "\x2d\x0d\x10\x4e\x2b\xfa\xad\x53\x7d\x15\x69\x8b",
  6370. /* HMAC-SHA3-256 */
  6371. "\xb5\x5b\x8d\x64\xb6\x9c\x21\xd0\xbf\x20\x5c\xa2\xf7\xb9\xb1\x4e"
  6372. "\x88\x21\x61\x2c\x66\xc3\x91\xae\x6c\x95\x16\x85\x83\xe6\xf4\x9b",
  6373. /* HMAC-SHA3-384 */
  6374. "\xaa\x91\xb3\xa6\x2f\x56\xa1\xbe\x8c\x3e\x74\x38\xdb\x58\xd9\xd3"
  6375. "\x34\xde\xa0\x60\x6d\x8d\x46\xe0\xec\xa9\xf6\x06\x35\x14\xe6\xed"
  6376. "\x83\xe6\x7c\x77\x24\x6c\x11\xb5\x90\x82\xb5\x75\xda\x7b\x83\x2d",
  6377. /* HMAC-SHA3-512 */
  6378. "\x1c\xc3\xa9\x24\x4a\x4a\x3f\xbd\xc7\x20\x00\x16\x9b\x79\x47\x03"
  6379. "\x78\x75\x2c\xb5\xf1\x2e\x62\x7c\xbe\xef\x4e\x8f\x0b\x11\x2b\x32"
  6380. "\xa0\xee\xc9\xd0\x4d\x64\x64\x0b\x37\xf4\xdd\x66\xf7\x8b\xb3\xad"
  6381. "\x52\x52\x6b\x65\x12\xde\x0d\x7c\xc0\x8b\x60\x01\x6c\x37\xd7\xa8"
  6382. };
  6383. int i = 0, iMax = sizeof(input) / sizeof(input[0]),
  6384. j, jMax = sizeof(hashType) / sizeof(hashType[0]);
  6385. int ret;
  6386. WOLFSSL_ENTER("hmac_sha3_test");
  6387. #ifdef HAVE_FIPS
  6388. /* FIPS requires a minimum length for HMAC keys, and "Jefe" is too
  6389. * short. Skip it in FIPS builds. */
  6390. i = 1;
  6391. #endif
  6392. for (; i < iMax; i++) {
  6393. for (j = 0; j < jMax; j++) {
  6394. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6395. return WC_TEST_RET_ENC_EC(ret);
  6396. ret = wc_HmacSetKey(&hmac, hashType[j], (byte*)key[i],
  6397. (word32)XSTRLEN(key[i]));
  6398. if (ret != 0)
  6399. return WC_TEST_RET_ENC_EC(ret);
  6400. ret = wc_HmacUpdate(&hmac, (byte*)input[i],
  6401. (word32)XSTRLEN(input[i]));
  6402. if (ret != 0)
  6403. return WC_TEST_RET_ENC_EC(ret);
  6404. ret = wc_HmacFinal(&hmac, hash);
  6405. if (ret != 0)
  6406. return WC_TEST_RET_ENC_EC(ret);
  6407. if (XMEMCMP(hash, output[(i*jMax) + j], (size_t)hashSz[j]) != 0)
  6408. return WC_TEST_RET_ENC_NC;
  6409. wc_HmacFree(&hmac);
  6410. if (i > 0)
  6411. continue;
  6412. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6413. ret = wc_HmacSizeByType(hashType[j]);
  6414. if (ret != hashSz[j])
  6415. return WC_TEST_RET_ENC_EC(ret);
  6416. #endif
  6417. }
  6418. }
  6419. return 0;
  6420. }
  6421. #endif
  6422. #ifdef WC_RC2
  6423. typedef struct rc2TestVector {
  6424. const char* input;
  6425. const char* output;
  6426. const char* key; /* Key, variable up to 128 bytes */
  6427. const char* iv; /* IV, 8-bytes */
  6428. int inLen;
  6429. int outLen;
  6430. int keyLen;
  6431. int effectiveKeyBits; /* Up to 1024 bits supported */
  6432. } rc2TestVector;
  6433. static wc_test_ret_t rc2_ecb_test(void)
  6434. {
  6435. wc_test_ret_t ret = 0;
  6436. byte cipher[RC2_BLOCK_SIZE];
  6437. byte plain[RC2_BLOCK_SIZE];
  6438. rc2TestVector a, b, c, d, e, f, g, h;
  6439. rc2TestVector test_rc2[8];
  6440. int times = sizeof(test_rc2) / sizeof(rc2TestVector), i;
  6441. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6442. a.output = "\xeb\xb7\x73\xf9\x93\x27\x8e\xff";
  6443. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6444. a.inLen = RC2_BLOCK_SIZE;
  6445. a.outLen = RC2_BLOCK_SIZE;
  6446. a.keyLen = 8;
  6447. a.effectiveKeyBits = 63;
  6448. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6449. b.output = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49";
  6450. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6451. b.inLen = RC2_BLOCK_SIZE;
  6452. b.outLen = RC2_BLOCK_SIZE;
  6453. b.keyLen = 8;
  6454. b.effectiveKeyBits = 64;
  6455. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01";
  6456. c.output = "\x30\x64\x9e\xdf\x9b\xe7\xd2\xc2";
  6457. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6458. c.inLen = RC2_BLOCK_SIZE;
  6459. c.outLen = RC2_BLOCK_SIZE;
  6460. c.keyLen = 8;
  6461. c.effectiveKeyBits = 64;
  6462. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6463. d.output = "\x61\xa8\xa2\x44\xad\xac\xcc\xf0";
  6464. d.key = "\x88";
  6465. d.inLen = RC2_BLOCK_SIZE;
  6466. d.outLen = RC2_BLOCK_SIZE;
  6467. d.keyLen = 1;
  6468. d.effectiveKeyBits = 64;
  6469. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6470. e.output = "\x6c\xcf\x43\x08\x97\x4c\x26\x7f";
  6471. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6472. e.inLen = RC2_BLOCK_SIZE;
  6473. e.outLen = RC2_BLOCK_SIZE;
  6474. e.keyLen = 7;
  6475. e.effectiveKeyBits = 64;
  6476. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6477. f.output = "\x1a\x80\x7d\x27\x2b\xbe\x5d\xb1";
  6478. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6479. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6480. f.inLen = RC2_BLOCK_SIZE;
  6481. f.outLen = RC2_BLOCK_SIZE;
  6482. f.keyLen = 16;
  6483. f.effectiveKeyBits = 64;
  6484. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6485. g.output = "\x22\x69\x55\x2a\xb0\xf8\x5c\xa6";
  6486. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6487. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6488. g.inLen = RC2_BLOCK_SIZE;
  6489. g.outLen = RC2_BLOCK_SIZE;
  6490. g.keyLen = 16;
  6491. g.effectiveKeyBits = 128;
  6492. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6493. h.output = "\x5b\x78\xd3\xa4\x3d\xff\xf1\xf1";
  6494. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6495. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6496. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6497. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6498. "\x1e";
  6499. h.inLen = RC2_BLOCK_SIZE;
  6500. h.outLen = RC2_BLOCK_SIZE;
  6501. h.keyLen = 33;
  6502. h.effectiveKeyBits = 129;
  6503. a.iv = b.iv = c.iv = d.iv = e.iv = f.iv = g.iv = h.iv = NULL;
  6504. test_rc2[0] = a;
  6505. test_rc2[1] = b;
  6506. test_rc2[2] = c;
  6507. test_rc2[3] = d;
  6508. test_rc2[4] = e;
  6509. test_rc2[5] = f;
  6510. test_rc2[6] = g;
  6511. test_rc2[7] = h;
  6512. for (i = 0; i < times; ++i) {
  6513. Rc2 enc;
  6514. XMEMSET(cipher, 0, RC2_BLOCK_SIZE);
  6515. XMEMSET(plain, 0, RC2_BLOCK_SIZE);
  6516. ret = wc_Rc2SetKey(&enc, (byte*)test_rc2[i].key, test_rc2[i].keyLen,
  6517. NULL, test_rc2[i].effectiveKeyBits);
  6518. if (ret != 0) {
  6519. return WC_TEST_RET_ENC_EC(ret);
  6520. }
  6521. /* ECB encrypt */
  6522. ret = wc_Rc2EcbEncrypt(&enc, cipher, (byte*)test_rc2[i].input,
  6523. (word32)test_rc2[i].outLen);
  6524. if (ret != 0) {
  6525. return WC_TEST_RET_ENC_EC(ret);
  6526. }
  6527. if (XMEMCMP(cipher, test_rc2[i].output, test_rc2[i].outLen)) {
  6528. return WC_TEST_RET_ENC_NC;
  6529. }
  6530. /* ECB decrypt */
  6531. ret = wc_Rc2EcbDecrypt(&enc, plain, cipher, RC2_BLOCK_SIZE);
  6532. if (ret != 0) {
  6533. return WC_TEST_RET_ENC_EC(ret);
  6534. }
  6535. if (XMEMCMP(plain, test_rc2[i].input, RC2_BLOCK_SIZE)) {
  6536. return WC_TEST_RET_ENC_NC;
  6537. }
  6538. }
  6539. return 0;
  6540. }
  6541. static wc_test_ret_t rc2_cbc_test(void)
  6542. {
  6543. wc_test_ret_t ret = 0;
  6544. byte cipher[128];
  6545. byte plain[128];
  6546. rc2TestVector a, b, c, d, e, f, g, h, i;
  6547. rc2TestVector test_rc2[9];
  6548. int times = sizeof(test_rc2) / sizeof(rc2TestVector), j;
  6549. /* key length = 7, effective key bits = 63 */
  6550. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6551. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6552. a.output = "\xEB\xB7\x73\xF9\x93\x27\x8E\xFF"
  6553. "\xF0\x51\x77\x8B\x65\xDB\x13\x57";
  6554. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6555. a.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6556. a.inLen = RC2_BLOCK_SIZE*2;
  6557. a.outLen = RC2_BLOCK_SIZE*2;
  6558. a.keyLen = 8;
  6559. a.effectiveKeyBits = 63;
  6560. /* key length = 8, effective key bits = 64, all 0xFF */
  6561. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff"
  6562. "\xff\xff\xff\xff\xff\xff\xff\xff";
  6563. b.output = "\xA3\xA1\x12\x65\x4F\x81\xC5\xCD"
  6564. "\xB6\x94\x3E\xEA\x3E\x8B\x9D\x1F";
  6565. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6566. b.iv = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6567. b.inLen = RC2_BLOCK_SIZE*2;
  6568. b.outLen = RC2_BLOCK_SIZE*2;
  6569. b.keyLen = 8;
  6570. b.effectiveKeyBits = 64;
  6571. /* key length = 8, effective key bits = 64 */
  6572. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01"
  6573. "\x10\x00\x00\x00\x00\x00\x00\x01";
  6574. c.output = "\xB5\x70\x14\xA2\x5F\x40\xE3\x6D"
  6575. "\x81\x99\x8D\xE0\xB5\xD5\x3A\x05";
  6576. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6577. c.iv = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6578. c.inLen = RC2_BLOCK_SIZE*2;
  6579. c.outLen = RC2_BLOCK_SIZE*2;
  6580. c.keyLen = 8;
  6581. c.effectiveKeyBits = 64;
  6582. /* key length = 1, effective key bits = 64 */
  6583. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6584. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6585. d.output = "\x61\xA8\xA2\x44\xAD\xAC\xCC\xF0"
  6586. "\x6D\x19\xE8\xF1\xFC\xE7\x38\x87";
  6587. d.key = "\x88";
  6588. d.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6589. d.inLen = RC2_BLOCK_SIZE*2;
  6590. d.outLen = RC2_BLOCK_SIZE*2;
  6591. d.keyLen = 1;
  6592. d.effectiveKeyBits = 64;
  6593. /* key length = 7, effective key bits = 64 */
  6594. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6595. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6596. e.output = "\x6C\xCF\x43\x08\x97\x4C\x26\x7F"
  6597. "\xCC\x3C\x53\x57\x7C\xA1\xA4\x4B";
  6598. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6599. e.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6600. e.inLen = RC2_BLOCK_SIZE*2;
  6601. e.outLen = RC2_BLOCK_SIZE*2;
  6602. e.keyLen = 7;
  6603. e.effectiveKeyBits = 64;
  6604. /* key length = 16, effective key bits = 64 */
  6605. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6606. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6607. f.output = "\x1A\x80\x7D\x27\x2B\xBE\x5D\xB1"
  6608. "\x64\xEF\xE1\xC3\xB8\xAD\xFB\xBA";
  6609. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6610. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6611. f.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6612. f.inLen = RC2_BLOCK_SIZE*2;
  6613. f.outLen = RC2_BLOCK_SIZE*2;
  6614. f.keyLen = 16;
  6615. f.effectiveKeyBits = 64;
  6616. /* key length = 16, effective bits = 128 */
  6617. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6618. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6619. g.output = "\x22\x69\x55\x2A\xB0\xF8\x5C\xA6"
  6620. "\x53\x6E\xFD\x2D\x89\xE1\x2A\x73";
  6621. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6622. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6623. g.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6624. g.inLen = RC2_BLOCK_SIZE*2;
  6625. g.outLen = RC2_BLOCK_SIZE*2;
  6626. g.keyLen = 16;
  6627. g.effectiveKeyBits = 128;
  6628. /* key length = 33, effective bits = 129 */
  6629. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6630. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6631. h.output = "\x5B\x78\xD3\xA4\x3D\xFF\xF1\xF1"
  6632. "\x45\x30\xA8\xD5\xC7\x7C\x46\x19";
  6633. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6634. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6635. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6636. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6637. "\x1e";
  6638. h.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6639. h.inLen = RC2_BLOCK_SIZE*2;
  6640. h.outLen = RC2_BLOCK_SIZE*2;
  6641. h.keyLen = 33;
  6642. h.effectiveKeyBits = 129;
  6643. /* key length = 10, effective bits = 40 */
  6644. i.input = "\x11\x22\x33\x44\x55\x66\x77\x88"
  6645. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00"
  6646. "\x11\x22\x33\x44\x55\x66\x77\x88"
  6647. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00";
  6648. i.output = "\x71\x2D\x11\x99\xC9\xA0\x78\x4F"
  6649. "\xCD\xF1\x1E\x3D\xFD\x21\x7E\xDB"
  6650. "\xB2\x6E\x0D\xA4\x72\xBC\x31\x51"
  6651. "\x48\xEF\x4E\x68\x3B\xDC\xCD\x7D";
  6652. i.key = "\x26\x1E\x57\x8E\xC9\x62\xBF\xB8"
  6653. "\x3E\x96";
  6654. i.iv = "\x01\x02\x03\x04\x05\x06\x07\x08";
  6655. i.inLen = RC2_BLOCK_SIZE*4;
  6656. i.outLen = RC2_BLOCK_SIZE*4;
  6657. i.keyLen = 10;
  6658. i.effectiveKeyBits = 40;
  6659. test_rc2[0] = a;
  6660. test_rc2[1] = b;
  6661. test_rc2[2] = c;
  6662. test_rc2[3] = d;
  6663. test_rc2[4] = e;
  6664. test_rc2[5] = f;
  6665. test_rc2[6] = g;
  6666. test_rc2[7] = h;
  6667. test_rc2[8] = i;
  6668. for (j = 0; j < times; ++j) {
  6669. Rc2 rc2;
  6670. XMEMSET(cipher, 0, sizeof(cipher));
  6671. XMEMSET(plain, 0, sizeof(plain));
  6672. ret = wc_Rc2SetKey(&rc2, (byte*)test_rc2[j].key, test_rc2[j].keyLen,
  6673. (byte*)test_rc2[j].iv, test_rc2[j].effectiveKeyBits);
  6674. if (ret != 0) {
  6675. return WC_TEST_RET_ENC_EC(ret);
  6676. }
  6677. ret = wc_Rc2CbcEncrypt(&rc2, cipher, (byte*)test_rc2[j].input,
  6678. test_rc2[j].inLen);
  6679. if (ret != 0) {
  6680. return WC_TEST_RET_ENC_EC(ret);
  6681. }
  6682. if (XMEMCMP(cipher, (byte*)test_rc2[j].output, test_rc2[j].outLen)) {
  6683. return WC_TEST_RET_ENC_NC;
  6684. }
  6685. /* reset IV for decrypt, since overridden by encrypt operation */
  6686. ret = wc_Rc2SetIV(&rc2, (byte*)test_rc2[j].iv);
  6687. if (ret != 0) {
  6688. return WC_TEST_RET_ENC_EC(ret);
  6689. }
  6690. ret = wc_Rc2CbcDecrypt(&rc2, plain, cipher, test_rc2[j].outLen);
  6691. if (ret != 0) {
  6692. return WC_TEST_RET_ENC_EC(ret);
  6693. }
  6694. if (XMEMCMP(plain, (byte*)test_rc2[j].input, test_rc2[j].inLen)) {
  6695. return WC_TEST_RET_ENC_NC;
  6696. }
  6697. }
  6698. return 0;
  6699. }
  6700. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void)
  6701. {
  6702. wc_test_ret_t ret = 0;
  6703. WOLFSSL_ENTER("rc2_test");
  6704. ret = rc2_ecb_test();
  6705. if (ret != 0) {
  6706. return ret;
  6707. }
  6708. return rc2_cbc_test();
  6709. }
  6710. #endif
  6711. #ifndef NO_RC4
  6712. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void)
  6713. {
  6714. byte cipher[16];
  6715. byte plain[16];
  6716. wc_test_ret_t ret;
  6717. const char* keys[] =
  6718. {
  6719. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6720. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6721. "\x00\x00\x00\x00\x00\x00\x00\x00",
  6722. "\xef\x01\x23\x45"
  6723. };
  6724. testVector a, b, c, d;
  6725. testVector test_arc4[4];
  6726. int times = sizeof(test_arc4) / sizeof(testVector), i;
  6727. WOLFSSL_ENTER("arc4_test");
  6728. a.input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  6729. a.output = "\x75\xb7\x87\x80\x99\xe0\xc5\x96";
  6730. a.inLen = 8;
  6731. a.outLen = 8;
  6732. b.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6733. b.output = "\x74\x94\xc2\xe7\x10\x4b\x08\x79";
  6734. b.inLen = 8;
  6735. b.outLen = 8;
  6736. c.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6737. c.output = "\xde\x18\x89\x41\xa3\x37\x5d\x3a";
  6738. c.inLen = 8;
  6739. c.outLen = 8;
  6740. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  6741. d.output = "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61";
  6742. d.inLen = 10;
  6743. d.outLen = 10;
  6744. test_arc4[0] = a;
  6745. test_arc4[1] = b;
  6746. test_arc4[2] = c;
  6747. test_arc4[3] = d;
  6748. for (i = 0; i < times; ++i) {
  6749. Arc4 enc;
  6750. Arc4 dec;
  6751. int keylen = 8; /* XSTRLEN with key 0x00 not good */
  6752. if (i == 3)
  6753. keylen = 4;
  6754. ret = wc_Arc4Init(&enc, HEAP_HINT, devId);
  6755. if (ret != 0)
  6756. return WC_TEST_RET_ENC_EC(ret);
  6757. ret = wc_Arc4Init(&dec, HEAP_HINT, devId);
  6758. if (ret != 0)
  6759. return WC_TEST_RET_ENC_EC(ret);
  6760. ret = wc_Arc4SetKey(&enc, (byte*)keys[i], (word32)keylen);
  6761. if (ret != 0)
  6762. return WC_TEST_RET_ENC_EC(ret);
  6763. ret = wc_Arc4SetKey(&dec, (byte*)keys[i], (word32)keylen);
  6764. if (ret != 0)
  6765. return WC_TEST_RET_ENC_EC(ret);
  6766. ret = wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input,
  6767. (word32)test_arc4[i].outLen);
  6768. if (ret != 0)
  6769. return WC_TEST_RET_ENC_EC(ret);
  6770. ret = wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen);
  6771. if (ret != 0)
  6772. return WC_TEST_RET_ENC_EC(ret);
  6773. if (XMEMCMP(plain, test_arc4[i].input, test_arc4[i].outLen))
  6774. return WC_TEST_RET_ENC_I(i);
  6775. if (XMEMCMP(cipher, test_arc4[i].output, test_arc4[i].outLen))
  6776. return WC_TEST_RET_ENC_I(i);
  6777. wc_Arc4Free(&enc);
  6778. wc_Arc4Free(&dec);
  6779. }
  6780. return 0;
  6781. }
  6782. #endif
  6783. #ifdef HAVE_CHACHA
  6784. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void)
  6785. {
  6786. ChaCha enc;
  6787. ChaCha dec;
  6788. byte cipher[128];
  6789. byte plain[128];
  6790. byte sliver[64];
  6791. byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  6792. word32 keySz = 32;
  6793. wc_test_ret_t ret = 0;
  6794. int i;
  6795. int times = 4;
  6796. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  6797. {
  6798. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6799. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6800. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6801. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6802. };
  6803. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  6804. {
  6805. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6806. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6807. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6808. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  6809. };
  6810. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  6811. {
  6812. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6813. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6814. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6815. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6816. };
  6817. /* 128 bit key */
  6818. WOLFSSL_SMALL_STACK_STATIC const byte key4[] =
  6819. {
  6820. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6821. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6822. };
  6823. const byte* keys[] = {key1, key2, key3, key4};
  6824. WOLFSSL_SMALL_STACK_STATIC const byte ivs1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6825. WOLFSSL_SMALL_STACK_STATIC const byte ivs2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6826. WOLFSSL_SMALL_STACK_STATIC const byte ivs3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00};
  6827. WOLFSSL_SMALL_STACK_STATIC const byte ivs4[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6828. const byte* ivs[] = {ivs1, ivs2, ivs3, ivs4};
  6829. #ifndef BENCH_EMBEDDED
  6830. WOLFSSL_SMALL_STACK_STATIC const byte cipher_big_result[] = {
  6831. 0x06, 0xa6, 0x5d, 0x31, 0x21, 0x6c, 0xdb, 0x37, 0x48, 0x7c, 0x01, 0x9d,
  6832. 0x72, 0xdf, 0x0a, 0x5b, 0x64, 0x74, 0x20, 0xba, 0x9e, 0xe0, 0x26, 0x7a,
  6833. 0xbf, 0xdf, 0x83, 0x34, 0x3b, 0x4f, 0x94, 0x3f, 0x37, 0x89, 0xaf, 0x00,
  6834. 0xdf, 0x0f, 0x2e, 0x75, 0x16, 0x41, 0xf6, 0x7a, 0x86, 0x94, 0x9d, 0x32,
  6835. 0x56, 0xf0, 0x79, 0x71, 0x68, 0x6f, 0xa6, 0x6b, 0xc6, 0x59, 0x49, 0xf6,
  6836. 0x10, 0x34, 0x03, 0x03, 0x16, 0x53, 0x9a, 0x98, 0x2a, 0x46, 0xde, 0x17,
  6837. 0x06, 0x65, 0x70, 0xca, 0x0a, 0x1f, 0xab, 0x80, 0x26, 0x96, 0x3f, 0x3e,
  6838. 0x7a, 0x3c, 0xa8, 0x87, 0xbb, 0x65, 0xdd, 0x5e, 0x07, 0x7b, 0x34, 0xe0,
  6839. 0x56, 0xda, 0x32, 0x13, 0x30, 0xc9, 0x0c, 0xd7, 0xba, 0xe4, 0x1f, 0xa6,
  6840. 0x91, 0x4f, 0x72, 0x9f, 0xd9, 0x5c, 0x62, 0x7d, 0xa6, 0xc2, 0xbc, 0x87,
  6841. 0xae, 0x64, 0x11, 0x94, 0x3b, 0xbc, 0x6c, 0x23, 0xbd, 0x7d, 0x00, 0xb4,
  6842. 0x99, 0xf2, 0x68, 0xb5, 0x59, 0x70, 0x93, 0xad, 0x69, 0xd0, 0xb1, 0x28,
  6843. 0x70, 0x92, 0xeb, 0xec, 0x39, 0x80, 0x82, 0xde, 0x44, 0xe2, 0x8a, 0x26,
  6844. 0xb3, 0xe9, 0x45, 0xcf, 0x83, 0x76, 0x9f, 0x6a, 0xa0, 0x46, 0x4a, 0x3d,
  6845. 0x26, 0x56, 0xaf, 0x49, 0x41, 0x26, 0x1b, 0x6a, 0x41, 0x37, 0x65, 0x91,
  6846. 0x72, 0xc4, 0xe7, 0x3c, 0x17, 0x31, 0xae, 0x2e, 0x2b, 0x31, 0x45, 0xe4,
  6847. 0x93, 0xd3, 0x10, 0xaa, 0xc5, 0x62, 0xd5, 0x11, 0x4b, 0x57, 0x1d, 0xad,
  6848. 0x48, 0x06, 0xd0, 0x0d, 0x98, 0xa5, 0xc6, 0x5b, 0xd0, 0x9e, 0x22, 0xc0,
  6849. 0x00, 0x32, 0x5a, 0xf5, 0x1c, 0x89, 0x6d, 0x54, 0x97, 0x55, 0x6b, 0x46,
  6850. 0xc5, 0xc7, 0xc4, 0x48, 0x9c, 0xbf, 0x47, 0xdc, 0x03, 0xc4, 0x1b, 0xcb,
  6851. 0x65, 0xa6, 0x91, 0x9d, 0x6d, 0xf1, 0xb0, 0x7a, 0x4d, 0x3b, 0x03, 0x95,
  6852. 0xf4, 0x8b, 0x0b, 0xae, 0x39, 0xff, 0x3f, 0xf6, 0xc0, 0x14, 0x18, 0x8a,
  6853. 0xe5, 0x19, 0xbd, 0xc1, 0xb4, 0x05, 0x4e, 0x29, 0x2f, 0x0b, 0x33, 0x76,
  6854. 0x28, 0x16, 0xa4, 0xa6, 0x93, 0x04, 0xb5, 0x55, 0x6b, 0x89, 0x3d, 0xa5,
  6855. 0x0f, 0xd3, 0xad, 0xfa, 0xd9, 0xfd, 0x05, 0x5d, 0x48, 0x94, 0x25, 0x5a,
  6856. 0x2c, 0x9a, 0x94, 0x80, 0xb0, 0xe7, 0xcb, 0x4d, 0x77, 0xbf, 0xca, 0xd8,
  6857. 0x55, 0x48, 0xbd, 0x66, 0xb1, 0x85, 0x81, 0xb1, 0x37, 0x79, 0xab, 0x52,
  6858. 0x08, 0x14, 0x12, 0xac, 0xcd, 0x45, 0x4d, 0x53, 0x6b, 0xca, 0x96, 0xc7,
  6859. 0x3b, 0x2f, 0x73, 0xb1, 0x5a, 0x23, 0xbd, 0x65, 0xd5, 0xea, 0x17, 0xb3,
  6860. 0xdc, 0xa1, 0x17, 0x1b, 0x2d, 0xb3, 0x9c, 0xd0, 0xdb, 0x41, 0x77, 0xef,
  6861. 0x93, 0x20, 0x52, 0x3e, 0x9d, 0xf5, 0xbf, 0x33, 0xf7, 0x52, 0xc1, 0x90,
  6862. 0xa0, 0x15, 0x17, 0xce, 0xf7, 0xf7, 0xd0, 0x3a, 0x3b, 0xd1, 0x72, 0x56,
  6863. 0x31, 0x81, 0xae, 0x60, 0xab, 0x40, 0xc1, 0xd1, 0x28, 0x77, 0x53, 0xac,
  6864. 0x9f, 0x11, 0x0a, 0x88, 0x36, 0x4b, 0xda, 0x57, 0xa7, 0x28, 0x5c, 0x85,
  6865. 0xd3, 0x85, 0x9b, 0x79, 0xad, 0x05, 0x1c, 0x37, 0x14, 0x5e, 0x0d, 0xd0,
  6866. 0x23, 0x03, 0x42, 0x1d, 0x48, 0x5d, 0xc5, 0x3c, 0x5a, 0x08, 0xa9, 0x0d,
  6867. 0x6e, 0x82, 0x7c, 0x2e, 0x3c, 0x41, 0xcc, 0x96, 0x8e, 0xad, 0xee, 0x2a,
  6868. 0x61, 0x0b, 0x16, 0x0f, 0xa9, 0x24, 0x40, 0x85, 0xbc, 0x9f, 0x28, 0x8d,
  6869. 0xe6, 0x68, 0x4d, 0x8f, 0x30, 0x48, 0xd9, 0x73, 0x73, 0x6c, 0x9a, 0x7f,
  6870. 0x67, 0xf7, 0xde, 0x4c, 0x0a, 0x8b, 0xe4, 0xb3, 0x08, 0x2a, 0x52, 0xda,
  6871. 0x54, 0xee, 0xcd, 0xb5, 0x62, 0x4a, 0x26, 0x20, 0xfb, 0x40, 0xbb, 0x39,
  6872. 0x3a, 0x0f, 0x09, 0xe8, 0x00, 0xd1, 0x24, 0x97, 0x60, 0xe9, 0x83, 0x83,
  6873. 0xfe, 0x9f, 0x9c, 0x15, 0xcf, 0x69, 0x03, 0x9f, 0x03, 0xe1, 0xe8, 0x6e,
  6874. 0xbd, 0x87, 0x58, 0x68, 0xee, 0xec, 0xd8, 0x29, 0x46, 0x23, 0x49, 0x92,
  6875. 0x72, 0x95, 0x5b, 0x49, 0xca, 0xe0, 0x45, 0x59, 0xb2, 0xca, 0xf4, 0xfc,
  6876. 0xb7, 0x59, 0x37, 0x49, 0x28, 0xbc, 0xf3, 0xd7, 0x61, 0xbc, 0x4b, 0xf3,
  6877. 0xa9, 0x4b, 0x2f, 0x05, 0xa8, 0x01, 0xa5, 0xdc, 0x00, 0x6e, 0x01, 0xb6,
  6878. 0x45, 0x3c, 0xd5, 0x49, 0x7d, 0x5c, 0x25, 0xe8, 0x31, 0x87, 0xb2, 0xb9,
  6879. 0xbf, 0xb3, 0x01, 0x62, 0x0c, 0xd0, 0x48, 0x77, 0xa2, 0x34, 0x0f, 0x16,
  6880. 0x22, 0x28, 0xee, 0x54, 0x08, 0x93, 0x3b, 0xe4, 0xde, 0x7e, 0x63, 0xf7,
  6881. 0x97, 0x16, 0x5d, 0x71, 0x58, 0xc2, 0x2e, 0xf2, 0x36, 0xa6, 0x12, 0x65,
  6882. 0x94, 0x17, 0xac, 0x66, 0x23, 0x7e, 0xc6, 0x72, 0x79, 0x24, 0xce, 0x8f,
  6883. 0x55, 0x19, 0x97, 0x44, 0xfc, 0x55, 0xec, 0x85, 0x26, 0x27, 0xdb, 0x38,
  6884. 0xb1, 0x42, 0x0a, 0xdd, 0x05, 0x99, 0x28, 0xeb, 0x03, 0x6c, 0x9a, 0xe9,
  6885. 0x17, 0xf6, 0x2c, 0xb0, 0xfe, 0xe7, 0xa4, 0xa7, 0x31, 0xda, 0x4d, 0xb0,
  6886. 0x29, 0xdb, 0xdd, 0x8d, 0x12, 0x13, 0x9c, 0xb4, 0xcc, 0x83, 0x97, 0xfb,
  6887. 0x1a, 0xdc, 0x08, 0xd6, 0x30, 0x62, 0xe8, 0xeb, 0x8b, 0x61, 0xcb, 0x1d,
  6888. 0x06, 0xe3, 0xa5, 0x4d, 0x35, 0xdb, 0x59, 0xa8, 0x2d, 0x87, 0x27, 0x44,
  6889. 0x6f, 0xc0, 0x38, 0x97, 0xe4, 0x85, 0x00, 0x02, 0x09, 0xf6, 0x69, 0x3a,
  6890. 0xcf, 0x08, 0x1b, 0x21, 0xbb, 0x79, 0xb1, 0xa1, 0x34, 0x09, 0xe0, 0x80,
  6891. 0xca, 0xb0, 0x78, 0x8a, 0x11, 0x97, 0xd4, 0x07, 0xbe, 0x1b, 0x6a, 0x5d,
  6892. 0xdb, 0xd6, 0x1f, 0x76, 0x6b, 0x16, 0xf0, 0x58, 0x84, 0x5f, 0x59, 0xce,
  6893. 0x62, 0x34, 0xc3, 0xdf, 0x94, 0xb8, 0x2f, 0x84, 0x68, 0xf0, 0xb8, 0x51,
  6894. 0xd9, 0x6d, 0x8e, 0x4a, 0x1d, 0xe6, 0x5c, 0xd8, 0x86, 0x25, 0xe3, 0x24,
  6895. 0xfd, 0x21, 0x61, 0x13, 0x48, 0x3e, 0xf6, 0x7d, 0xa6, 0x71, 0x9b, 0xd2,
  6896. 0x6e, 0xe6, 0xd2, 0x08, 0x94, 0x62, 0x6c, 0x98, 0xfe, 0x2f, 0x9c, 0x88,
  6897. 0x7e, 0x78, 0x15, 0x02, 0x00, 0xf0, 0xba, 0x24, 0x91, 0xf2, 0xdc, 0x47,
  6898. 0x51, 0x4d, 0x15, 0x5e, 0x91, 0x5f, 0x57, 0x5b, 0x1d, 0x35, 0x24, 0x45,
  6899. 0x75, 0x9b, 0x88, 0x75, 0xf1, 0x2f, 0x85, 0xe7, 0x89, 0xd1, 0x01, 0xb4,
  6900. 0xc8, 0x18, 0xb7, 0x97, 0xef, 0x4b, 0x90, 0xf4, 0xbf, 0x10, 0x27, 0x3c,
  6901. 0x60, 0xff, 0xc4, 0x94, 0x20, 0x2f, 0x93, 0x4b, 0x4d, 0xe3, 0x80, 0xf7,
  6902. 0x2c, 0x71, 0xd9, 0xe3, 0x68, 0xb4, 0x77, 0x2b, 0xc7, 0x0d, 0x39, 0x92,
  6903. 0xef, 0x91, 0x0d, 0xb2, 0x11, 0x50, 0x0e, 0xe8, 0xad, 0x3b, 0xf6, 0xb5,
  6904. 0xc6, 0x14, 0x4d, 0x33, 0x53, 0xa7, 0x60, 0x15, 0xc7, 0x27, 0x51, 0xdc,
  6905. 0x54, 0x29, 0xa7, 0x0d, 0x6a, 0x7b, 0x72, 0x13, 0xad, 0x7d, 0x41, 0x19,
  6906. 0x4e, 0x42, 0x49, 0xcc, 0x42, 0xe4, 0xbd, 0x99, 0x13, 0xd9, 0x7f, 0xf3,
  6907. 0x38, 0xa4, 0xb6, 0x33, 0xed, 0x07, 0x48, 0x7e, 0x8e, 0x82, 0xfe, 0x3a,
  6908. 0x9d, 0x75, 0x93, 0xba, 0x25, 0x4e, 0x37, 0x3c, 0x0c, 0xd5, 0x69, 0xa9,
  6909. 0x2d, 0x9e, 0xfd, 0xe8, 0xbb, 0xf5, 0x0c, 0xe2, 0x86, 0xb9, 0x5e, 0x6f,
  6910. 0x28, 0xe4, 0x19, 0xb3, 0x0b, 0xa4, 0x86, 0xd7, 0x24, 0xd0, 0xb8, 0x89,
  6911. 0x7b, 0x76, 0xec, 0x05, 0x10, 0x5b, 0x68, 0xe9, 0x58, 0x66, 0xa3, 0xc5,
  6912. 0xb6, 0x63, 0x20, 0x0e, 0x0e, 0xea, 0x3d, 0x61, 0x5e, 0xda, 0x3d, 0x3c,
  6913. 0xf9, 0xfd, 0xed, 0xa9, 0xdb, 0x52, 0x94, 0x8a, 0x00, 0xca, 0x3c, 0x8d,
  6914. 0x66, 0x8f, 0xb0, 0xf0, 0x5a, 0xca, 0x3f, 0x63, 0x71, 0xbf, 0xca, 0x99,
  6915. 0x37, 0x9b, 0x75, 0x97, 0x89, 0x10, 0x6e, 0xcf, 0xf2, 0xf5, 0xe3, 0xd5,
  6916. 0x45, 0x9b, 0xad, 0x10, 0x71, 0x6c, 0x5f, 0x6f, 0x7f, 0x22, 0x77, 0x18,
  6917. 0x2f, 0xf9, 0x99, 0xc5, 0x69, 0x58, 0x03, 0x12, 0x86, 0x82, 0x3e, 0xbf,
  6918. 0xc2, 0x12, 0x35, 0x43, 0xa3, 0xd9, 0x18, 0x4f, 0x41, 0x11, 0x6b, 0xf3,
  6919. 0x67, 0xaf, 0x3d, 0x78, 0xe4, 0x22, 0x2d, 0xb3, 0x48, 0x43, 0x31, 0x1d,
  6920. 0xef, 0xa8, 0xba, 0x49, 0x8e, 0xa9, 0xa7, 0xb6, 0x18, 0x77, 0x84, 0xca,
  6921. 0xbd, 0xa2, 0x02, 0x1b, 0x6a, 0xf8, 0x5f, 0xda, 0xff, 0xcf, 0x01, 0x6a,
  6922. 0x86, 0x69, 0xa9, 0xe9, 0xcb, 0x60, 0x1e, 0x15, 0xdc, 0x8f, 0x5d, 0x39,
  6923. 0xb5, 0xce, 0x55, 0x5f, 0x47, 0x97, 0xb1, 0x19, 0x6e, 0x21, 0xd6, 0x13,
  6924. 0x39, 0xb2, 0x24, 0xe0, 0x62, 0x82, 0x9f, 0xed, 0x12, 0x81, 0xed, 0xee,
  6925. 0xab, 0xd0, 0x2f, 0x19, 0x89, 0x3f, 0x57, 0x2e, 0xc2, 0xe2, 0x67, 0xe8,
  6926. 0xae, 0x03, 0x56, 0xba, 0xd4, 0xd0, 0xa4, 0x89, 0x03, 0x06, 0x5b, 0xcc,
  6927. 0xf2, 0x22, 0xb8, 0x0e, 0x76, 0x79, 0x4a, 0x42, 0x1d, 0x37, 0x51, 0x5a,
  6928. 0xaa, 0x46, 0x6c, 0x2a, 0xdd, 0x66, 0xfe, 0xc6, 0x68, 0xc3, 0x38, 0xa2,
  6929. 0xae, 0x5b, 0x98, 0x24, 0x5d, 0x43, 0x05, 0x82, 0x38, 0x12, 0xd3, 0xd1,
  6930. 0x75, 0x2d, 0x4f, 0x61, 0xbd, 0xb9, 0x10, 0x87, 0x44, 0x2a, 0x78, 0x07,
  6931. 0xff, 0xf4, 0x0f, 0xa1, 0xf3, 0x68, 0x9f, 0xbe, 0xae, 0xa2, 0x91, 0xf0,
  6932. 0xc7, 0x55, 0x7a, 0x52, 0xd5, 0xa3, 0x8d, 0x6f, 0xe4, 0x90, 0x5c, 0xf3,
  6933. 0x5f, 0xce, 0x3d, 0x23, 0xf9, 0x8e, 0xae, 0x14, 0xfb, 0x82, 0x9a, 0xa3,
  6934. 0x04, 0x5f, 0xbf, 0xad, 0x3e, 0xf2, 0x97, 0x0a, 0x60, 0x40, 0x70, 0x19,
  6935. 0x72, 0xad, 0x66, 0xfb, 0x78, 0x1b, 0x84, 0x6c, 0x98, 0xbc, 0x8c, 0xf8,
  6936. 0x4f, 0xcb, 0xb5, 0xf6, 0xaf, 0x7a, 0xb7, 0x93, 0xef, 0x67, 0x48, 0x02,
  6937. 0x2c, 0xcb, 0xe6, 0x77, 0x0f, 0x7b, 0xc1, 0xee, 0xc5, 0xb6, 0x2d, 0x7e,
  6938. 0x62, 0xa0, 0xc0, 0xa7, 0xa5, 0x80, 0x31, 0x92, 0x50, 0xa1, 0x28, 0x22,
  6939. 0x95, 0x03, 0x17, 0xd1, 0x0f, 0xf6, 0x08, 0xe5, 0xec
  6940. };
  6941. #define CHACHA_BIG_TEST_SIZE 1305
  6942. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  6943. byte cipher_big[CHACHA_BIG_TEST_SIZE] = {0};
  6944. byte plain_big[CHACHA_BIG_TEST_SIZE] = {0};
  6945. byte input_big[CHACHA_BIG_TEST_SIZE] = {0};
  6946. #else
  6947. byte* cipher_big;
  6948. byte* plain_big;
  6949. byte* input_big;
  6950. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6951. int block_size;
  6952. #endif /* BENCH_EMBEDDED */
  6953. byte a[] = {0x76,0xb8,0xe0,0xad,0xa0,0xf1,0x3d,0x90};
  6954. byte b[] = {0x45,0x40,0xf0,0x5a,0x9f,0x1f,0xb2,0x96};
  6955. byte c[] = {0xde,0x9c,0xba,0x7b,0xf3,0xd6,0x9e,0xf5};
  6956. byte d[] = {0x89,0x67,0x09,0x52,0x60,0x83,0x64,0xfd};
  6957. byte* test_chacha[4];
  6958. test_chacha[0] = a;
  6959. test_chacha[1] = b;
  6960. test_chacha[2] = c;
  6961. test_chacha[3] = d;
  6962. WOLFSSL_ENTER("chacha_test");
  6963. #ifndef BENCH_EMBEDDED
  6964. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  6965. cipher_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6966. DYNAMIC_TYPE_TMP_BUFFER);
  6967. if (cipher_big == NULL) {
  6968. return MEMORY_E;
  6969. }
  6970. plain_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6971. DYNAMIC_TYPE_TMP_BUFFER);
  6972. if (plain_big == NULL) {
  6973. return MEMORY_E;
  6974. }
  6975. input_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6976. DYNAMIC_TYPE_TMP_BUFFER);
  6977. if (input_big == NULL) {
  6978. return MEMORY_E;
  6979. }
  6980. XMEMSET(cipher_big, 0, CHACHA_BIG_TEST_SIZE);
  6981. XMEMSET(plain_big, 0, CHACHA_BIG_TEST_SIZE);
  6982. XMEMSET(input_big, 0, CHACHA_BIG_TEST_SIZE);
  6983. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6984. #endif /* BENCH_EMBEDDED */
  6985. for (i = 0; i < times; ++i) {
  6986. if (i < 3) {
  6987. keySz = 32;
  6988. }
  6989. else {
  6990. keySz = 16;
  6991. }
  6992. XMEMCPY(plain, keys[i], keySz);
  6993. XMEMSET(cipher, 0, 32);
  6994. XMEMCPY(cipher + 4, ivs[i], 8);
  6995. ret |= wc_Chacha_SetKey(&enc, keys[i], keySz);
  6996. ret |= wc_Chacha_SetKey(&dec, keys[i], keySz);
  6997. if (ret != 0)
  6998. return ret;
  6999. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  7000. ret |= wc_Chacha_SetIV(&dec, cipher, 0);
  7001. if (ret != 0)
  7002. return ret;
  7003. XMEMCPY(plain, input, 8);
  7004. ret |= wc_Chacha_Process(&enc, cipher, plain, (word32)8);
  7005. ret |= wc_Chacha_Process(&dec, plain, cipher, (word32)8);
  7006. if (ret != 0)
  7007. return ret;
  7008. if (XMEMCMP(test_chacha[i], cipher, 8))
  7009. return WC_TEST_RET_ENC_I(i);
  7010. if (XMEMCMP(plain, input, 8))
  7011. return WC_TEST_RET_ENC_I(i);
  7012. }
  7013. /* test of starting at a different counter
  7014. encrypts all of the information and decrypts starting at 2nd chunk */
  7015. XMEMSET(plain, 0, sizeof(plain));
  7016. XMEMSET(sliver, 1, sizeof(sliver)); /* set as 1's to not match plain */
  7017. XMEMSET(cipher, 0, sizeof(cipher));
  7018. XMEMCPY(cipher + 4, ivs[0], 8);
  7019. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7020. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7021. if (ret != 0)
  7022. return ret;
  7023. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  7024. ret |= wc_Chacha_SetIV(&dec, cipher, 1);
  7025. if (ret != 0)
  7026. return ret;
  7027. ret |= wc_Chacha_Process(&enc, cipher, plain, sizeof(plain));
  7028. ret |= wc_Chacha_Process(&dec, sliver, cipher + 64, sizeof(sliver));
  7029. if (ret != 0)
  7030. return ret;
  7031. if (XMEMCMP(plain + 64, sliver, 64))
  7032. return WC_TEST_RET_ENC_NC;
  7033. #ifndef BENCH_EMBEDDED
  7034. /* test of encrypting more data */
  7035. keySz = 32;
  7036. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7037. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7038. if (ret != 0)
  7039. return ret;
  7040. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  7041. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  7042. if (ret != 0)
  7043. return ret;
  7044. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big, CHACHA_BIG_TEST_SIZE);
  7045. ret |= wc_Chacha_Process(&dec, plain_big, cipher_big,
  7046. CHACHA_BIG_TEST_SIZE);
  7047. if (ret != 0)
  7048. return ret;
  7049. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  7050. return WC_TEST_RET_ENC_NC;
  7051. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  7052. return WC_TEST_RET_ENC_NC;
  7053. for (i = 0; i < 18; ++i) {
  7054. /* this will test all paths
  7055. * block sizes: 1 3 7 15 31 63 127 255 511 (i = 0- 8)
  7056. * 2 4 8 16 32 64 128 256 512 (i = 9-17)
  7057. */
  7058. block_size = (2 << (i%9)) - (i<9?1:0);
  7059. keySz = 32;
  7060. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7061. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7062. if (ret != 0)
  7063. return ret;
  7064. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  7065. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  7066. if (ret != 0)
  7067. return ret;
  7068. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big , (word32)block_size);
  7069. ret |= wc_Chacha_Process(&dec, plain_big , cipher_big, (word32)block_size);
  7070. if (ret != 0)
  7071. return ret;
  7072. if (XMEMCMP(plain_big, input_big, (word32)block_size))
  7073. return WC_TEST_RET_ENC_I(i);
  7074. if (XMEMCMP(cipher_big, cipher_big_result, (word32)block_size))
  7075. return WC_TEST_RET_ENC_I(i);
  7076. }
  7077. /* Streaming test */
  7078. for (i = 1; i <= (int)CHACHA_CHUNK_BYTES + 1; i++) {
  7079. int j, rem;
  7080. ret = wc_Chacha_SetKey(&enc, keys[0], keySz);
  7081. if (ret != 0)
  7082. return WC_TEST_RET_ENC_EC(ret);
  7083. ret = wc_Chacha_SetKey(&dec, keys[0], keySz);
  7084. if (ret != 0)
  7085. return WC_TEST_RET_ENC_EC(ret);
  7086. ret = wc_Chacha_SetIV(&enc, ivs[2], 0);
  7087. if (ret != 0)
  7088. return WC_TEST_RET_ENC_EC(ret);
  7089. ret = wc_Chacha_SetIV(&dec, ivs[2], 0);
  7090. if (ret != 0)
  7091. return WC_TEST_RET_ENC_EC(ret);
  7092. for (j = 0; j < CHACHA_BIG_TEST_SIZE - i; j+= i) {
  7093. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)i);
  7094. if (ret != 0)
  7095. return WC_TEST_RET_ENC_EC(ret);
  7096. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)i);
  7097. if (ret != 0)
  7098. return WC_TEST_RET_ENC_EC(ret);
  7099. }
  7100. rem = CHACHA_BIG_TEST_SIZE - j;
  7101. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)rem);
  7102. if (ret != 0)
  7103. return WC_TEST_RET_ENC_EC(ret);
  7104. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)rem);
  7105. if (ret != 0)
  7106. return WC_TEST_RET_ENC_EC(ret);
  7107. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  7108. return WC_TEST_RET_ENC_I(i);
  7109. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  7110. return WC_TEST_RET_ENC_I(i);
  7111. }
  7112. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  7113. XFREE(cipher_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7114. XFREE(plain_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7115. XFREE(input_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7116. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  7117. #endif /* BENCH_EMBEDDED */
  7118. return 0;
  7119. }
  7120. #endif /* HAVE_CHACHA */
  7121. #ifdef HAVE_POLY1305
  7122. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void)
  7123. {
  7124. byte tag[16];
  7125. Poly1305 enc;
  7126. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {
  7127. 0x43,0x72,0x79,0x70,0x74,0x6f,0x67,0x72,
  7128. 0x61,0x70,0x68,0x69,0x63,0x20,0x46,0x6f,
  7129. 0x72,0x75,0x6d,0x20,0x52,0x65,0x73,0x65,
  7130. 0x61,0x72,0x63,0x68,0x20,0x47,0x72,0x6f,
  7131. 0x75,0x70
  7132. };
  7133. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {
  7134. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,
  7135. 0x6c,0x64,0x21
  7136. };
  7137. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {
  7138. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7139. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7140. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7141. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7142. };
  7143. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  7144. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7145. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7146. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7147. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7148. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7149. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7150. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7151. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7152. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7153. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7154. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7155. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7156. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7157. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7158. 0x61,0x16
  7159. };
  7160. WOLFSSL_SMALL_STACK_STATIC const byte msg5[] = {
  7161. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7162. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7163. };
  7164. WOLFSSL_SMALL_STACK_STATIC const byte msg6[] = {
  7165. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7166. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7167. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7168. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7169. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7170. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7171. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7172. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7173. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7174. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7175. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7176. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7177. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7178. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7179. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7180. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7181. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7182. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7183. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7184. 0x61,0x16
  7185. };
  7186. WOLFSSL_SMALL_STACK_STATIC const byte msg7[] = {
  7187. 0xe8,0x8c,0x85,0x03,0x43,0xaf,0xa7,0x85,
  7188. 0x21,0x6b,0xc3,0x45,0xc4,0x53,0x98,0xf8,
  7189. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7190. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7191. };
  7192. byte additional[] = {
  7193. 0x50,0x51,0x52,0x53,0xc0,0xc1,0xc2,0xc3,
  7194. 0xc4,0xc5,0xc6,0xc7
  7195. };
  7196. WOLFSSL_SMALL_STACK_STATIC const byte correct0[] = {
  7197. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7198. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7199. };
  7200. WOLFSSL_SMALL_STACK_STATIC const byte correct1[] = {
  7201. 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,
  7202. 0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9
  7203. };
  7204. WOLFSSL_SMALL_STACK_STATIC const byte correct2[] = {
  7205. 0xa6,0xf7,0x45,0x00,0x8f,0x81,0xc9,0x16,
  7206. 0xa2,0x0d,0xcc,0x74,0xee,0xf2,0xb2,0xf0
  7207. };
  7208. WOLFSSL_SMALL_STACK_STATIC const byte correct3[] = {
  7209. 0x49,0xec,0x78,0x09,0x0e,0x48,0x1e,0xc6,
  7210. 0xc2,0x6b,0x33,0xb9,0x1c,0xcc,0x03,0x07
  7211. };
  7212. WOLFSSL_SMALL_STACK_STATIC const byte correct4[] = {
  7213. 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,
  7214. 0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91
  7215. };
  7216. WOLFSSL_SMALL_STACK_STATIC const byte correct5[] = {
  7217. 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7218. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7219. };
  7220. WOLFSSL_SMALL_STACK_STATIC const byte correct6[] = {
  7221. 0xea,0x11,0x5c,0x4f,0xd0,0xc0,0x10,0xae,
  7222. 0xf7,0xdf,0xda,0x77,0xa2,0xe9,0xaf,0xca
  7223. };
  7224. WOLFSSL_SMALL_STACK_STATIC const byte correct7[] = {
  7225. 0x14,0x00,0x00,0x88,0x5c,0x00,0x00,0x88,
  7226. 0x5c,0x00,0x00,0x88,0x5c,0x00,0x00,0x88
  7227. };
  7228. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7229. 0x85,0xd6,0xbe,0x78,0x57,0x55,0x6d,0x33,
  7230. 0x7f,0x44,0x52,0xfe,0x42,0xd5,0x06,0xa8,
  7231. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7232. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7233. };
  7234. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7235. 0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,
  7236. 0x33,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,
  7237. 0x6b,0x65,0x79,0x20,0x66,0x6f,0x72,0x20,
  7238. 0x50,0x6f,0x6c,0x79,0x31,0x33,0x30,0x35
  7239. };
  7240. WOLFSSL_SMALL_STACK_STATIC const byte key4[] = {
  7241. 0x7b,0xac,0x2b,0x25,0x2d,0xb4,0x47,0xaf,
  7242. 0x09,0xb6,0x7a,0x55,0xa4,0xe9,0x55,0x84,
  7243. 0x0a,0xe1,0xd6,0x73,0x10,0x75,0xd9,0xeb,
  7244. 0x2a,0x93,0x75,0x78,0x3e,0xd5,0x53,0xff
  7245. };
  7246. WOLFSSL_SMALL_STACK_STATIC const byte key5[] = {
  7247. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7248. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7249. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7250. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7251. };
  7252. WOLFSSL_SMALL_STACK_STATIC const byte key7[] = {
  7253. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7254. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7255. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7256. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  7257. };
  7258. const byte* msgs[] = {NULL, msg1, msg2, msg3, msg5, msg6, msg7};
  7259. word32 szm[] = {0, sizeof(msg1), sizeof(msg2),
  7260. sizeof(msg3), sizeof(msg5), sizeof(msg6),
  7261. sizeof(msg7)};
  7262. const byte* keys[] = {key, key, key2, key2, key5, key, key7};
  7263. const byte* tests[] = {correct0, correct1, correct2, correct3, correct5,
  7264. correct6, correct7};
  7265. int i;
  7266. wc_test_ret_t ret = 0;
  7267. WOLFSSL_ENTER("poly1305_test");
  7268. for (i = 0; i < 7; i++) {
  7269. ret = wc_Poly1305SetKey(&enc, keys[i], 32);
  7270. if (ret != 0)
  7271. return WC_TEST_RET_ENC_I(i);
  7272. ret = wc_Poly1305Update(&enc, msgs[i], szm[i]);
  7273. if (ret != 0)
  7274. return WC_TEST_RET_ENC_I(i);
  7275. ret = wc_Poly1305Final(&enc, tag);
  7276. if (ret != 0)
  7277. return WC_TEST_RET_ENC_I(i);
  7278. if (XMEMCMP(tag, tests[i], sizeof(tag)))
  7279. return WC_TEST_RET_ENC_I(i);
  7280. }
  7281. /* Check TLS MAC function from 2.8.2 https://tools.ietf.org/html/rfc7539 */
  7282. XMEMSET(tag, 0, sizeof(tag));
  7283. ret = wc_Poly1305SetKey(&enc, key4, sizeof(key4));
  7284. if (ret != 0)
  7285. return WC_TEST_RET_ENC_EC(ret);
  7286. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7287. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7288. if (ret != 0)
  7289. return WC_TEST_RET_ENC_EC(ret);
  7290. if (XMEMCMP(tag, correct4, sizeof(tag)))
  7291. return WC_TEST_RET_ENC_NC;
  7292. /* Check fail of TLS MAC function if altering additional data */
  7293. XMEMSET(tag, 0, sizeof(tag));
  7294. additional[0]++;
  7295. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7296. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7297. if (ret != 0)
  7298. return WC_TEST_RET_ENC_EC(ret);
  7299. if (XMEMCMP(tag, correct4, sizeof(tag)) == 0)
  7300. return WC_TEST_RET_ENC_NC;
  7301. return 0;
  7302. }
  7303. #endif /* HAVE_POLY1305 */
  7304. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  7305. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void)
  7306. {
  7307. /* Test #1 from Section 2.8.2 of draft-irtf-cfrg-chacha20-poly1305-10 */
  7308. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7309. WOLFSSL_SMALL_STACK_STATIC const byte key1[] = {
  7310. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  7311. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  7312. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  7313. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  7314. };
  7315. WOLFSSL_SMALL_STACK_STATIC const byte plaintext1[] = {
  7316. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  7317. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  7318. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  7319. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  7320. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  7321. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  7322. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  7323. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  7324. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  7325. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  7326. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  7327. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  7328. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  7329. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  7330. 0x74, 0x2e
  7331. };
  7332. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] = {
  7333. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  7334. 0x44, 0x45, 0x46, 0x47
  7335. };
  7336. WOLFSSL_SMALL_STACK_STATIC const byte aad1[] = { /* additional data */
  7337. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  7338. 0xc4, 0xc5, 0xc6, 0xc7
  7339. };
  7340. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] = { /* expected output from operation */
  7341. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  7342. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  7343. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  7344. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  7345. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  7346. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  7347. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  7348. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  7349. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  7350. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  7351. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  7352. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  7353. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  7354. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  7355. 0x61, 0x16
  7356. };
  7357. WOLFSSL_SMALL_STACK_STATIC const byte authTag1[] = { /* expected output from operation */
  7358. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  7359. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  7360. };
  7361. /* Test #2 from Appendix A.2 in draft-irtf-cfrg-chacha20-poly1305-10 */
  7362. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7363. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7364. 0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
  7365. 0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
  7366. 0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
  7367. 0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0
  7368. };
  7369. WOLFSSL_SMALL_STACK_STATIC const byte plaintext2[] = {
  7370. 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
  7371. 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20,
  7372. 0x61, 0x72, 0x65, 0x20, 0x64, 0x72, 0x61, 0x66,
  7373. 0x74, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7374. 0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x6c, 0x69,
  7375. 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
  7376. 0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20,
  7377. 0x6f, 0x66, 0x20, 0x73, 0x69, 0x78, 0x20, 0x6d,
  7378. 0x6f, 0x6e, 0x74, 0x68, 0x73, 0x20, 0x61, 0x6e,
  7379. 0x64, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65,
  7380. 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
  7381. 0x2c, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63,
  7382. 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f,
  7383. 0x62, 0x73, 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x64,
  7384. 0x20, 0x62, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65,
  7385. 0x72, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7386. 0x6e, 0x74, 0x73, 0x20, 0x61, 0x74, 0x20, 0x61,
  7387. 0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x2e,
  7388. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69,
  7389. 0x6e, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72,
  7390. 0x69, 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20,
  7391. 0x75, 0x73, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65,
  7392. 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61,
  7393. 0x66, 0x74, 0x73, 0x20, 0x61, 0x73, 0x20, 0x72,
  7394. 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
  7395. 0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61,
  7396. 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x20,
  7397. 0x63, 0x69, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65,
  7398. 0x6d, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20,
  7399. 0x74, 0x68, 0x61, 0x6e, 0x20, 0x61, 0x73, 0x20,
  7400. 0x2f, 0xe2, 0x80, 0x9c, 0x77, 0x6f, 0x72, 0x6b,
  7401. 0x20, 0x69, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67,
  7402. 0x72, 0x65, 0x73, 0x73, 0x2e, 0x2f, 0xe2, 0x80,
  7403. 0x9d
  7404. };
  7405. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  7406. 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
  7407. 0x05, 0x06, 0x07, 0x08
  7408. };
  7409. WOLFSSL_SMALL_STACK_STATIC const byte aad2[] = { /* additional data */
  7410. 0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00,
  7411. 0x00, 0x00, 0x4e, 0x91
  7412. };
  7413. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] = { /* expected output from operation */
  7414. 0x64, 0xa0, 0x86, 0x15, 0x75, 0x86, 0x1a, 0xf4,
  7415. 0x60, 0xf0, 0x62, 0xc7, 0x9b, 0xe6, 0x43, 0xbd,
  7416. 0x5e, 0x80, 0x5c, 0xfd, 0x34, 0x5c, 0xf3, 0x89,
  7417. 0xf1, 0x08, 0x67, 0x0a, 0xc7, 0x6c, 0x8c, 0xb2,
  7418. 0x4c, 0x6c, 0xfc, 0x18, 0x75, 0x5d, 0x43, 0xee,
  7419. 0xa0, 0x9e, 0xe9, 0x4e, 0x38, 0x2d, 0x26, 0xb0,
  7420. 0xbd, 0xb7, 0xb7, 0x3c, 0x32, 0x1b, 0x01, 0x00,
  7421. 0xd4, 0xf0, 0x3b, 0x7f, 0x35, 0x58, 0x94, 0xcf,
  7422. 0x33, 0x2f, 0x83, 0x0e, 0x71, 0x0b, 0x97, 0xce,
  7423. 0x98, 0xc8, 0xa8, 0x4a, 0xbd, 0x0b, 0x94, 0x81,
  7424. 0x14, 0xad, 0x17, 0x6e, 0x00, 0x8d, 0x33, 0xbd,
  7425. 0x60, 0xf9, 0x82, 0xb1, 0xff, 0x37, 0xc8, 0x55,
  7426. 0x97, 0x97, 0xa0, 0x6e, 0xf4, 0xf0, 0xef, 0x61,
  7427. 0xc1, 0x86, 0x32, 0x4e, 0x2b, 0x35, 0x06, 0x38,
  7428. 0x36, 0x06, 0x90, 0x7b, 0x6a, 0x7c, 0x02, 0xb0,
  7429. 0xf9, 0xf6, 0x15, 0x7b, 0x53, 0xc8, 0x67, 0xe4,
  7430. 0xb9, 0x16, 0x6c, 0x76, 0x7b, 0x80, 0x4d, 0x46,
  7431. 0xa5, 0x9b, 0x52, 0x16, 0xcd, 0xe7, 0xa4, 0xe9,
  7432. 0x90, 0x40, 0xc5, 0xa4, 0x04, 0x33, 0x22, 0x5e,
  7433. 0xe2, 0x82, 0xa1, 0xb0, 0xa0, 0x6c, 0x52, 0x3e,
  7434. 0xaf, 0x45, 0x34, 0xd7, 0xf8, 0x3f, 0xa1, 0x15,
  7435. 0x5b, 0x00, 0x47, 0x71, 0x8c, 0xbc, 0x54, 0x6a,
  7436. 0x0d, 0x07, 0x2b, 0x04, 0xb3, 0x56, 0x4e, 0xea,
  7437. 0x1b, 0x42, 0x22, 0x73, 0xf5, 0x48, 0x27, 0x1a,
  7438. 0x0b, 0xb2, 0x31, 0x60, 0x53, 0xfa, 0x76, 0x99,
  7439. 0x19, 0x55, 0xeb, 0xd6, 0x31, 0x59, 0x43, 0x4e,
  7440. 0xce, 0xbb, 0x4e, 0x46, 0x6d, 0xae, 0x5a, 0x10,
  7441. 0x73, 0xa6, 0x72, 0x76, 0x27, 0x09, 0x7a, 0x10,
  7442. 0x49, 0xe6, 0x17, 0xd9, 0x1d, 0x36, 0x10, 0x94,
  7443. 0xfa, 0x68, 0xf0, 0xff, 0x77, 0x98, 0x71, 0x30,
  7444. 0x30, 0x5b, 0xea, 0xba, 0x2e, 0xda, 0x04, 0xdf,
  7445. 0x99, 0x7b, 0x71, 0x4d, 0x6c, 0x6f, 0x2c, 0x29,
  7446. 0xa6, 0xad, 0x5c, 0xb4, 0x02, 0x2b, 0x02, 0x70,
  7447. 0x9b
  7448. };
  7449. WOLFSSL_SMALL_STACK_STATIC const byte authTag2[] = { /* expected output from operation */
  7450. 0xee, 0xad, 0x9d, 0x67, 0x89, 0x0c, 0xbb, 0x22,
  7451. 0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38
  7452. };
  7453. byte generatedCiphertext[265]; /* max plaintext2/cipher2 */
  7454. byte generatedPlaintext[265]; /* max plaintext2/cipher2 */
  7455. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  7456. ChaChaPoly_Aead aead;
  7457. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  7458. #define TEST_SMALL_CHACHA_CHUNKS 32
  7459. #else
  7460. #define TEST_SMALL_CHACHA_CHUNKS 64
  7461. #endif
  7462. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7463. word32 testLen;
  7464. #endif
  7465. wc_test_ret_t err;
  7466. WOLFSSL_ENTER("chacha20_poly1305_aead_test");
  7467. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7468. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7469. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7470. /* Parameter Validation testing */
  7471. /* Encrypt */
  7472. err = wc_ChaCha20Poly1305_Encrypt(NULL, iv1, aad1, sizeof(aad1), plaintext1,
  7473. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7474. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7475. return WC_TEST_RET_ENC_EC(err);
  7476. err = wc_ChaCha20Poly1305_Encrypt(key1, NULL, aad1, sizeof(aad1),
  7477. plaintext1, sizeof(plaintext1), generatedCiphertext,
  7478. generatedAuthTag);
  7479. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7480. return WC_TEST_RET_ENC_EC(err);
  7481. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7482. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7483. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7484. return WC_TEST_RET_ENC_EC(err);
  7485. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7486. sizeof(plaintext1), NULL, generatedAuthTag);
  7487. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7488. return WC_TEST_RET_ENC_EC(err);
  7489. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7490. sizeof(plaintext1), generatedCiphertext, NULL);
  7491. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7492. return WC_TEST_RET_ENC_EC(err);
  7493. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7494. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7495. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7496. return WC_TEST_RET_ENC_EC(err);
  7497. /* Decrypt */
  7498. err = wc_ChaCha20Poly1305_Decrypt(NULL, iv2, aad2, sizeof(aad2), cipher2,
  7499. sizeof(cipher2), authTag2, generatedPlaintext);
  7500. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7501. return WC_TEST_RET_ENC_EC(err);
  7502. err = wc_ChaCha20Poly1305_Decrypt(key2, NULL, aad2, sizeof(aad2), cipher2,
  7503. sizeof(cipher2), authTag2, generatedPlaintext);
  7504. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7505. return WC_TEST_RET_ENC_EC(err);
  7506. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7507. sizeof(cipher2), authTag2, generatedPlaintext);
  7508. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7509. return WC_TEST_RET_ENC_EC(err);
  7510. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7511. sizeof(cipher2), NULL, generatedPlaintext);
  7512. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7513. return WC_TEST_RET_ENC_EC(err);
  7514. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7515. sizeof(cipher2), authTag2, NULL);
  7516. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7517. return WC_TEST_RET_ENC_EC(err);
  7518. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7519. sizeof(cipher2), authTag2, generatedPlaintext);
  7520. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7521. return WC_TEST_RET_ENC_EC(err);
  7522. /* Test #1 */
  7523. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1,
  7524. aad1, sizeof(aad1),
  7525. plaintext1, sizeof(plaintext1),
  7526. generatedCiphertext, generatedAuthTag);
  7527. if (err) {
  7528. return WC_TEST_RET_ENC_EC(err);
  7529. }
  7530. /* -- Check the ciphertext and authtag */
  7531. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7532. return WC_TEST_RET_ENC_NC;
  7533. }
  7534. if (XMEMCMP(generatedAuthTag, authTag1, sizeof(authTag1))) {
  7535. return WC_TEST_RET_ENC_NC;
  7536. }
  7537. /* -- Verify decryption works */
  7538. err = wc_ChaCha20Poly1305_Decrypt(key1, iv1,
  7539. aad1, sizeof(aad1),
  7540. cipher1, sizeof(cipher1),
  7541. authTag1, generatedPlaintext);
  7542. if (err) {
  7543. return err;
  7544. }
  7545. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7546. return WC_TEST_RET_ENC_NC;
  7547. }
  7548. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7549. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7550. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7551. /* Test #2 */
  7552. err = wc_ChaCha20Poly1305_Encrypt(key2, iv2,
  7553. aad2, sizeof(aad2),
  7554. plaintext2, sizeof(plaintext2),
  7555. generatedCiphertext, generatedAuthTag);
  7556. if (err) {
  7557. return err;
  7558. }
  7559. /* -- Check the ciphertext and authtag */
  7560. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7561. return WC_TEST_RET_ENC_NC;
  7562. }
  7563. if (XMEMCMP(generatedAuthTag, authTag2, sizeof(authTag2))) {
  7564. return WC_TEST_RET_ENC_NC;
  7565. }
  7566. /* -- Verify decryption works */
  7567. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2,
  7568. aad2, sizeof(aad2),
  7569. cipher2, sizeof(cipher2),
  7570. authTag2, generatedPlaintext);
  7571. if (err) {
  7572. return err;
  7573. }
  7574. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7575. return WC_TEST_RET_ENC_NC;
  7576. }
  7577. /* AEAD init/update/final - bad argument tests */
  7578. err = wc_ChaCha20Poly1305_Init(NULL, key1, iv1,
  7579. CHACHA20_POLY1305_AEAD_DECRYPT);
  7580. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7581. return WC_TEST_RET_ENC_EC(err);
  7582. err = wc_ChaCha20Poly1305_Init(&aead, NULL, iv1,
  7583. CHACHA20_POLY1305_AEAD_DECRYPT);
  7584. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7585. return WC_TEST_RET_ENC_EC(err);
  7586. err = wc_ChaCha20Poly1305_Init(&aead, key1, NULL,
  7587. CHACHA20_POLY1305_AEAD_DECRYPT);
  7588. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7589. return WC_TEST_RET_ENC_EC(err);
  7590. err = wc_ChaCha20Poly1305_UpdateAad(NULL, aad1, sizeof(aad1));
  7591. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7592. return WC_TEST_RET_ENC_EC(err);
  7593. err = wc_ChaCha20Poly1305_UpdateAad(&aead, NULL, sizeof(aad1));
  7594. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7595. return WC_TEST_RET_ENC_EC(err);
  7596. err = wc_ChaCha20Poly1305_UpdateData(NULL, generatedPlaintext,
  7597. generatedPlaintext, sizeof(plaintext1));
  7598. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7599. return WC_TEST_RET_ENC_EC(err);
  7600. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext, NULL,
  7601. sizeof(plaintext1));
  7602. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7603. return WC_TEST_RET_ENC_EC(err);
  7604. err = wc_ChaCha20Poly1305_UpdateData(&aead, NULL, generatedPlaintext,
  7605. sizeof(plaintext1));
  7606. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7607. return WC_TEST_RET_ENC_EC(err);
  7608. err = wc_ChaCha20Poly1305_Final(NULL, generatedAuthTag);
  7609. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7610. return WC_TEST_RET_ENC_EC(err);
  7611. err = wc_ChaCha20Poly1305_Final(&aead, NULL);
  7612. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7613. return WC_TEST_RET_ENC_EC(err);
  7614. /* AEAD init/update/final - bad state tests */
  7615. /* clear struct - make valgrind happy to resolve
  7616. "Conditional jump or move depends on uninitialised value(s)".
  7617. The enum is "int" size and aead.state is "byte" */
  7618. /* The wc_ChaCha20Poly1305_Init function does this normally */
  7619. XMEMSET(&aead, 0, sizeof(aead));
  7620. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7621. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7622. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7623. return WC_TEST_RET_ENC_EC(err);
  7624. aead.state = CHACHA20_POLY1305_STATE_DATA;
  7625. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7626. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7627. return WC_TEST_RET_ENC_EC(err);
  7628. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7629. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext,
  7630. generatedPlaintext, sizeof(plaintext1));
  7631. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7632. return WC_TEST_RET_ENC_EC(err);
  7633. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7634. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7635. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7636. return WC_TEST_RET_ENC_EC(err);
  7637. aead.state = CHACHA20_POLY1305_STATE_READY;
  7638. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7639. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7640. return WC_TEST_RET_ENC_EC(err);
  7641. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7642. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7643. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7644. /* Test 1 - Encrypt */
  7645. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7646. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7647. if (err != 0)
  7648. return WC_TEST_RET_ENC_EC(err);
  7649. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7650. if (err != 0)
  7651. return WC_TEST_RET_ENC_EC(err);
  7652. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7653. /* test doing data in smaller chunks */
  7654. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7655. word32 dataLen = sizeof(plaintext1) - testLen;
  7656. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7657. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7658. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext1[testLen],
  7659. &generatedCiphertext[testLen], dataLen);
  7660. if (err != 0)
  7661. return WC_TEST_RET_ENC_EC(err);
  7662. testLen += dataLen;
  7663. }
  7664. #else
  7665. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext1,
  7666. generatedCiphertext, sizeof(plaintext1));
  7667. #endif
  7668. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7669. if (err != 0)
  7670. return WC_TEST_RET_ENC_EC(err);
  7671. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7672. if (err != 0)
  7673. return WC_TEST_RET_ENC_EC(err);
  7674. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7675. return WC_TEST_RET_ENC_NC;
  7676. }
  7677. /* Test 1 - Decrypt */
  7678. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7679. CHACHA20_POLY1305_AEAD_DECRYPT);
  7680. if (err != 0)
  7681. return WC_TEST_RET_ENC_EC(err);
  7682. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7683. if (err != 0)
  7684. return WC_TEST_RET_ENC_EC(err);
  7685. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7686. /* test doing data in smaller chunks */
  7687. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7688. word32 dataLen = sizeof(plaintext1) - testLen;
  7689. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7690. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7691. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7692. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7693. dataLen);
  7694. if (err != 0)
  7695. return WC_TEST_RET_ENC_EC(err);
  7696. testLen += dataLen;
  7697. }
  7698. #else
  7699. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7700. generatedPlaintext, sizeof(cipher1));
  7701. #endif
  7702. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7703. if (err != 0)
  7704. return WC_TEST_RET_ENC_EC(err);
  7705. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7706. if (err != 0)
  7707. return WC_TEST_RET_ENC_EC(err);
  7708. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7709. return WC_TEST_RET_ENC_NC;
  7710. }
  7711. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7712. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7713. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7714. /* Test 2 - Encrypt */
  7715. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7716. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7717. if (err != 0)
  7718. return WC_TEST_RET_ENC_EC(err);
  7719. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7720. if (err != 0)
  7721. return WC_TEST_RET_ENC_EC(err);
  7722. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7723. /* test doing data in smaller chunks */
  7724. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7725. word32 dataLen = sizeof(plaintext2) - testLen;
  7726. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7727. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7728. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext2[testLen],
  7729. &generatedCiphertext[testLen], dataLen);
  7730. if (err != 0)
  7731. return WC_TEST_RET_ENC_EC(err);
  7732. testLen += dataLen;
  7733. }
  7734. #else
  7735. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext2, generatedCiphertext,
  7736. sizeof(plaintext2));
  7737. #endif
  7738. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7739. if (err != 0)
  7740. return WC_TEST_RET_ENC_EC(err);
  7741. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7742. if (err != 0)
  7743. return WC_TEST_RET_ENC_EC(err);
  7744. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7745. return WC_TEST_RET_ENC_NC;
  7746. }
  7747. /* Test 2 - Decrypt */
  7748. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7749. CHACHA20_POLY1305_AEAD_DECRYPT);
  7750. if (err != 0)
  7751. return WC_TEST_RET_ENC_EC(err);
  7752. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7753. if (err != 0)
  7754. return WC_TEST_RET_ENC_EC(err);
  7755. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7756. /* test doing data in smaller chunks */
  7757. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7758. word32 dataLen = sizeof(plaintext2) - testLen;
  7759. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7760. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7761. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7762. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7763. dataLen);
  7764. if (err != 0)
  7765. return WC_TEST_RET_ENC_EC(err);
  7766. testLen += dataLen;
  7767. }
  7768. #else
  7769. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7770. generatedPlaintext, sizeof(cipher2));
  7771. #endif
  7772. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7773. if (err != 0)
  7774. return WC_TEST_RET_ENC_EC(err);
  7775. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7776. if (err != 0)
  7777. return WC_TEST_RET_ENC_EC(err);
  7778. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7779. return WC_TEST_RET_ENC_NC;
  7780. }
  7781. return err;
  7782. }
  7783. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  7784. #ifndef NO_DES3
  7785. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void)
  7786. {
  7787. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  7788. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7789. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7790. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7791. };
  7792. byte plain[24];
  7793. byte cipher[24];
  7794. Des enc;
  7795. Des dec;
  7796. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  7797. {
  7798. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  7799. };
  7800. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  7801. {
  7802. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  7803. };
  7804. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  7805. {
  7806. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  7807. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  7808. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  7809. };
  7810. #ifdef WOLFSSL_DES_ECB
  7811. /* "Stay strong and move on!"" */
  7812. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7813. {
  7814. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7815. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7816. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7817. };
  7818. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb[] =
  7819. {
  7820. 0x70,0x4F,0x20,0xF6,0x72,0xB4,0xD0,0x2A,
  7821. 0xB5,0xA9,0x94,0x9F,0x11,0xCF,0x87,0xED,
  7822. 0x13,0x33,0x82,0xCB,0x8B,0xF1,0x82,0x56
  7823. };
  7824. /* "Lemmings" */
  7825. WOLFSSL_SMALL_STACK_STATIC const byte key_ecb[] =
  7826. {
  7827. 0x4C,0x65,0x6D,0x6D,0x69,0x6E,0x67,0x73
  7828. };
  7829. #endif /* WOLFSSL_DES_ECB */
  7830. wc_test_ret_t ret;
  7831. WOLFSSL_ENTER("des_test");
  7832. ret = wc_Des_SetKey(&enc, key, iv, DES_ENCRYPTION);
  7833. if (ret != 0)
  7834. return WC_TEST_RET_ENC_EC(ret);
  7835. ret = wc_Des_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7836. if (ret != 0)
  7837. return WC_TEST_RET_ENC_EC(ret);
  7838. ret = wc_Des_SetKey(&dec, key, iv, DES_DECRYPTION);
  7839. if (ret != 0)
  7840. return WC_TEST_RET_ENC_EC(ret);
  7841. ret = wc_Des_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7842. if (ret != 0)
  7843. return WC_TEST_RET_ENC_EC(ret);
  7844. if (XMEMCMP(plain, vector, sizeof(plain)))
  7845. return WC_TEST_RET_ENC_NC;
  7846. if (XMEMCMP(cipher, verify, sizeof(cipher)))
  7847. return WC_TEST_RET_ENC_NC;
  7848. ret = wc_Des_CbcEncryptWithKey(cipher, vector, sizeof(vector), key, iv);
  7849. if (ret != 0)
  7850. return WC_TEST_RET_ENC_EC(ret);
  7851. /* Test basic ECB Process for DES*/
  7852. #ifdef WOLFSSL_DES_ECB
  7853. ret = wc_Des_SetKey(&enc, key_ecb, iv, DES_ENCRYPTION);
  7854. if (ret != 0)
  7855. return WC_TEST_RET_ENC_EC(ret);
  7856. ret = wc_Des_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector));
  7857. if (ret != 0)
  7858. return WC_TEST_RET_ENC_EC(ret);
  7859. ret = wc_Des_SetKey(&dec, key_ecb, iv, DES_DECRYPTION);
  7860. if (ret != 0)
  7861. return WC_TEST_RET_ENC_EC(ret);
  7862. ret = wc_Des_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  7863. if (ret != 0)
  7864. return WC_TEST_RET_ENC_EC(ret);
  7865. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  7866. return WC_TEST_RET_ENC_NC;
  7867. if (XMEMCMP(cipher, verify_ecb, sizeof(cipher)))
  7868. return WC_TEST_RET_ENC_NC;
  7869. #endif /* WOLFSSL_DES_ECB */
  7870. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  7871. {
  7872. EncryptedInfo info;
  7873. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  7874. XMEMCPY(info.iv, iv, sizeof(iv));
  7875. info.ivSz = sizeof(iv);
  7876. info.keySz = sizeof(key);
  7877. info.cipherType = WC_CIPHER_DES;
  7878. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7879. sizeof(key), WC_HASH_TYPE_SHA);
  7880. if (ret != 0)
  7881. return WC_TEST_RET_ENC_EC(ret);
  7882. /* Test invalid info ptr */
  7883. ret = wc_BufferKeyEncrypt(NULL, cipher, sizeof(cipher), key,
  7884. sizeof(key), WC_HASH_TYPE_SHA);
  7885. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7886. return WC_TEST_RET_ENC_EC(ret);
  7887. #ifndef NO_PWDBASED
  7888. /* Test invalid hash type - only applies to wc_PBKDF1 call */
  7889. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7890. sizeof(key), WC_HASH_TYPE_NONE);
  7891. if (ret == 0)
  7892. return WC_TEST_RET_ENC_EC(ret);
  7893. #endif /* !NO_PWDBASED */
  7894. }
  7895. #endif
  7896. return 0;
  7897. }
  7898. #endif /* !NO_DES3 */
  7899. #ifndef NO_DES3
  7900. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void)
  7901. {
  7902. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  7903. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7904. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7905. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7906. };
  7907. byte plain[24];
  7908. byte cipher[24];
  7909. Des3 enc;
  7910. Des3 dec;
  7911. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  7912. {
  7913. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  7914. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  7915. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  7916. };
  7917. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  7918. {
  7919. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  7920. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  7921. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  7922. };
  7923. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] =
  7924. {
  7925. 0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
  7926. 0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
  7927. 0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
  7928. };
  7929. #ifdef WOLFSSL_DES_ECB
  7930. /* Stay strong and move on! */
  7931. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7932. {
  7933. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7934. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7935. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7936. };
  7937. WOLFSSL_SMALL_STACK_STATIC const byte verify3_ecb[] =
  7938. {
  7939. 0x45,0x7E,0xFA,0xA1,0x05,0xDD,0x48,0x86,
  7940. 0x4D,0xB2,0xAB,0xE4,0xF9,0x63,0xD6,0x54,
  7941. 0x7C,0x5A,0xB3,0x67,0x32,0x25,0x67,0x3D
  7942. };
  7943. /* "Life is what you make it" */
  7944. WOLFSSL_SMALL_STACK_STATIC const byte key3_ecb[] =
  7945. {
  7946. 0x4C,0x69,0x66,0x65,0x20,0x69,0x73,0x20,
  7947. 0x77,0x68,0x61,0x74,0x20,0x79,0x6F,0x75,
  7948. 0x20,0x6D,0x61,0x6B,0x65,0x20,0x69,0x74
  7949. };
  7950. #endif /* WOLFSSL_DES_ECB */
  7951. wc_test_ret_t ret;
  7952. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  7953. size_t i;
  7954. #endif
  7955. WOLFSSL_ENTER("des3_test");
  7956. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7957. if (ret != 0)
  7958. return WC_TEST_RET_ENC_EC(ret);
  7959. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7960. if (ret != 0)
  7961. return WC_TEST_RET_ENC_EC(ret);
  7962. ret = wc_Des3_SetKey(&enc, key3, iv3, DES_ENCRYPTION);
  7963. if (ret != 0)
  7964. return WC_TEST_RET_ENC_EC(ret);
  7965. ret = wc_Des3_SetKey(&dec, key3, iv3, DES_DECRYPTION);
  7966. if (ret != 0)
  7967. return WC_TEST_RET_ENC_EC(ret);
  7968. ret = wc_Des3_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7969. #if defined(WOLFSSL_ASYNC_CRYPT)
  7970. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  7971. #endif
  7972. if (ret != 0)
  7973. return WC_TEST_RET_ENC_EC(ret);
  7974. ret = wc_Des3_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7975. #if defined(WOLFSSL_ASYNC_CRYPT)
  7976. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  7977. #endif
  7978. if (ret != 0)
  7979. return WC_TEST_RET_ENC_EC(ret);
  7980. if (XMEMCMP(plain, vector, sizeof(plain)))
  7981. return WC_TEST_RET_ENC_NC;
  7982. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  7983. return WC_TEST_RET_ENC_NC;
  7984. /* Test basic ECB Process for DES3*/
  7985. #ifdef WOLFSSL_DES_ECB
  7986. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7987. if (ret != 0)
  7988. return WC_TEST_RET_ENC_EC(ret);
  7989. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7990. if (ret != 0)
  7991. return WC_TEST_RET_ENC_EC(ret);
  7992. ret = wc_Des3_SetKey(&enc, key3_ecb, NULL, DES_ENCRYPTION);
  7993. if (ret != 0)
  7994. return WC_TEST_RET_ENC_EC(ret);
  7995. ret = wc_Des3_SetKey(&dec, key3_ecb, NULL, DES_DECRYPTION);
  7996. if (ret != 0)
  7997. return WC_TEST_RET_ENC_EC(ret);
  7998. ret = wc_Des3_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector_ecb));
  7999. #if defined(WOLFSSL_ASYNC_CRYPT)
  8000. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  8001. #endif
  8002. if (ret != 0)
  8003. return WC_TEST_RET_ENC_EC(ret);
  8004. ret = wc_Des3_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  8005. #if defined(WOLFSSL_ASYNC_CRYPT)
  8006. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  8007. #endif
  8008. if (ret != 0)
  8009. return WC_TEST_RET_ENC_EC(ret);
  8010. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  8011. return WC_TEST_RET_ENC_NC;
  8012. if (XMEMCMP(cipher, verify3_ecb, sizeof(cipher)))
  8013. return WC_TEST_RET_ENC_NC;
  8014. #endif /* WOLFSSL_DES_ECB */
  8015. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  8016. /* test the same vectors with using compatibility layer */
  8017. for (i = 0; i < sizeof(vector); i += DES_BLOCK_SIZE){
  8018. DES_key_schedule ks1;
  8019. DES_key_schedule ks2;
  8020. DES_key_schedule ks3;
  8021. DES_cblock iv4;
  8022. byte tmp[sizeof(vector)];
  8023. XMEMCPY(ks1, key3, sizeof(DES_key_schedule));
  8024. XMEMCPY(ks2, key3 + 8, sizeof(DES_key_schedule));
  8025. XMEMCPY(ks3, key3 + 16, sizeof(DES_key_schedule));
  8026. XMEMSET(plain, 0, sizeof(plain));
  8027. XMEMSET(cipher, 0, sizeof(cipher));
  8028. /* Test in-place encrypt/decrypt */
  8029. XMEMCPY(tmp, vector, sizeof(vector));
  8030. /* Use i as the splitter */
  8031. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  8032. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8033. &iv4, DES_ENCRYPT);
  8034. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i),
  8035. &ks1, &ks2, &ks3, &iv4, DES_ENCRYPT);
  8036. XMEMCPY(cipher, tmp, sizeof(cipher));
  8037. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  8038. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8039. &iv4, DES_DECRYPT);
  8040. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i),
  8041. &ks1, &ks2, &ks3, &iv4, DES_DECRYPT);
  8042. XMEMCPY(plain, tmp, sizeof(plain));
  8043. if (XMEMCMP(plain, vector, sizeof(plain)))
  8044. return WC_TEST_RET_ENC_NC;
  8045. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  8046. return WC_TEST_RET_ENC_NC;
  8047. }
  8048. #endif /* OPENSSL_EXTRA */
  8049. wc_Des3Free(&enc);
  8050. wc_Des3Free(&dec);
  8051. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  8052. {
  8053. EncryptedInfo info;
  8054. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  8055. XMEMCPY(info.iv, iv3, sizeof(iv3));
  8056. info.ivSz = sizeof(iv3);
  8057. info.keySz = sizeof(key3);
  8058. info.cipherType = WC_CIPHER_DES3;
  8059. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key3,
  8060. sizeof(key3), WC_HASH_TYPE_SHA);
  8061. if (ret != 0)
  8062. return WC_TEST_RET_ENC_EC(ret);
  8063. }
  8064. #endif
  8065. return 0;
  8066. }
  8067. #endif /* NO_DES3 */
  8068. static const int fiducial1 = WC_TEST_RET_LN; /* source code reference point --
  8069. * see print_fiducials() below.
  8070. */
  8071. #ifndef NO_AES
  8072. #if defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_CFB) || \
  8073. defined(WOLFSSL_AES_XTS)
  8074. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8075. && !defined(HAVE_SELFTEST)
  8076. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  8077. /* pass in the function, key, iv, plain text and expected and this function
  8078. * tests that the encryption and decryption is successful */
  8079. static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
  8080. const byte* iv, const byte* plain, int plainSz,
  8081. const byte* expected, int expectedSz)
  8082. {
  8083. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8084. WOLFSSL_EVP_CIPHER_CTX *ctx = NULL;
  8085. #else
  8086. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  8087. #endif
  8088. int ctx_inited = 0;
  8089. int idx, cipherSz;
  8090. wc_test_ret_t ret = 0;
  8091. byte* cipher;
  8092. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8093. if ((ctx = wolfSSL_EVP_CIPHER_CTX_new()) == NULL)
  8094. return MEMORY_E;
  8095. #endif
  8096. cipher = (byte*)XMALLOC(plainSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8097. if (cipher == NULL) {
  8098. ret = WC_TEST_RET_ENC_ERRNO;
  8099. goto EVP_TEST_END;
  8100. }
  8101. /* test encrypt */
  8102. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  8103. ctx_inited = 1;
  8104. if (wolfSSL_EVP_CipherInit(ctx, type, key, iv, 1) == 0) {
  8105. ret = WC_TEST_RET_ENC_NC;
  8106. goto EVP_TEST_END;
  8107. }
  8108. if (wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, plain, expectedSz) == 0) {
  8109. ret = WC_TEST_RET_ENC_NC;
  8110. goto EVP_TEST_END;
  8111. }
  8112. cipherSz = idx;
  8113. if (wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8114. ret = WC_TEST_RET_ENC_NC;
  8115. goto EVP_TEST_END;
  8116. }
  8117. cipherSz += idx;
  8118. if (XMEMCMP(cipher, expected, plainSz)) {
  8119. ret = WC_TEST_RET_ENC_NC;
  8120. goto EVP_TEST_END;
  8121. }
  8122. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8123. ctx_inited = 0;
  8124. if (ret == WOLFSSL_SUCCESS)
  8125. ret = 0;
  8126. else {
  8127. ret = WC_TEST_RET_ENC_NC;
  8128. goto EVP_TEST_END;
  8129. }
  8130. /* test decrypt */
  8131. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  8132. ctx_inited = 1;
  8133. if (wolfSSL_EVP_CipherInit(ctx, type, key, iv, 0) == 0) {
  8134. ret = WC_TEST_RET_ENC_NC;
  8135. goto EVP_TEST_END;
  8136. }
  8137. if (wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, cipher, expectedSz) == 0) {
  8138. ret = WC_TEST_RET_ENC_NC;
  8139. goto EVP_TEST_END;
  8140. }
  8141. cipherSz = idx;
  8142. if (wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8143. ret = WC_TEST_RET_ENC_NC;
  8144. goto EVP_TEST_END;
  8145. }
  8146. cipherSz += idx;
  8147. if ((expectedSz != cipherSz) || XMEMCMP(plain, cipher, plainSz)) {
  8148. ret = WC_TEST_RET_ENC_NC;
  8149. goto EVP_TEST_END;
  8150. }
  8151. EVP_TEST_END:
  8152. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8153. (void)cipherSz;
  8154. if (ctx_inited) {
  8155. int cleanup_ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8156. if (cleanup_ret != WOLFSSL_SUCCESS)
  8157. ret = WC_TEST_RET_ENC_NC;
  8158. }
  8159. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8160. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  8161. #endif
  8162. return ret;
  8163. }
  8164. #endif /* !HAVE_FIPS || FIPS_VERSION3_GE(6,0,0) */
  8165. #endif /* OPENSSL_EXTRA && !WOLFCRYPT_ONLY && !HAVE_SELFTEST */
  8166. #endif /* WOLFSSL_AES_OFB || WOLFSSL_AES_CFB */
  8167. #ifdef WOLFSSL_AES_OFB
  8168. /* test vector from https://csrc.nist.gov/Projects/cryptographic-algorithm-validation-program/Block-Ciphers */
  8169. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void)
  8170. {
  8171. #ifdef WOLFSSL_AES_256
  8172. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8173. {
  8174. 0xc4,0xc7,0xfa,0xd6,0x53,0x5c,0xb8,0x71,
  8175. 0x4a,0x5c,0x40,0x77,0x9a,0x8b,0xa1,0xd2,
  8176. 0x53,0x3e,0x23,0xb4,0xb2,0x58,0x73,0x2a,
  8177. 0x5b,0x78,0x01,0xf4,0xe3,0x71,0xa7,0x94
  8178. };
  8179. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  8180. {
  8181. 0x5e,0xb9,0x33,0x13,0xb8,0x71,0xff,0x16,
  8182. 0xb9,0x8a,0x9b,0xcb,0x43,0x33,0x0d,0x6f
  8183. };
  8184. WOLFSSL_SMALL_STACK_STATIC const byte plain1[] =
  8185. {
  8186. 0x6d,0x0b,0xb0,0x79,0x63,0x84,0x71,0xe9,
  8187. 0x39,0xd4,0x53,0x14,0x86,0xc1,0x4c,0x25,
  8188. 0x9a,0xee,0xc6,0xf3,0xc0,0x0d,0xfd,0xd6,
  8189. 0xc0,0x50,0xa8,0xba,0xa8,0x20,0xdb,0x71,
  8190. 0xcc,0x12,0x2c,0x4e,0x0c,0x17,0x15,0xef,
  8191. 0x55,0xf3,0x99,0x5a,0x6b,0xf0,0x2a,0x4c
  8192. };
  8193. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8194. {
  8195. 0x0f,0x54,0x61,0x71,0x59,0xd0,0x3f,0xfc,
  8196. 0x1b,0xfa,0xfb,0x60,0x29,0x30,0xd7,0x00,
  8197. 0xf4,0xa4,0xa8,0xe6,0xdd,0x93,0x94,0x46,
  8198. 0x64,0xd2,0x19,0xc4,0xc5,0x4d,0xde,0x1b,
  8199. 0x04,0x53,0xe1,0x73,0xf5,0x18,0x74,0xae,
  8200. 0xfd,0x64,0xa2,0xe1,0xe2,0x76,0x13,0xb0
  8201. };
  8202. #endif /* WOLFSSL_AES_256 */
  8203. #ifdef WOLFSSL_AES_128
  8204. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8205. {
  8206. 0x10,0xa5,0x88,0x69,0xd7,0x4b,0xe5,0xa3,
  8207. 0x74,0xcf,0x86,0x7c,0xfb,0x47,0x38,0x59
  8208. };
  8209. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  8210. {
  8211. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8212. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8213. };
  8214. WOLFSSL_SMALL_STACK_STATIC const byte plain2[] =
  8215. {
  8216. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8217. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8218. };
  8219. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8220. {
  8221. 0x6d,0x25,0x1e,0x69,0x44,0xb0,0x51,0xe0,
  8222. 0x4e,0xaa,0x6f,0xb4,0xdb,0xf7,0x84,0x65
  8223. };
  8224. #endif /* WOLFSSL_AES_128 */
  8225. #ifdef WOLFSSL_AES_192
  8226. WOLFSSL_SMALL_STACK_STATIC const byte key3[] = {
  8227. 0xd0,0x77,0xa0,0x3b,0xd8,0xa3,0x89,0x73,
  8228. 0x92,0x8c,0xca,0xfe,0x4a,0x9d,0x2f,0x45,
  8229. 0x51,0x30,0xbd,0x0a,0xf5,0xae,0x46,0xa9
  8230. };
  8231. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  8232. {
  8233. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8234. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8235. };
  8236. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8237. {
  8238. 0xab,0xc7,0x86,0xfb,0x1e,0xdb,0x50,0x45,
  8239. 0x80,0xc4,0xd8,0x82,0xef,0x29,0xa0,0xc7
  8240. };
  8241. WOLFSSL_SMALL_STACK_STATIC const byte plain3[] =
  8242. {
  8243. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8244. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8245. };
  8246. #endif /* WOLFSSL_AES_192 */
  8247. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8248. Aes *enc = NULL;
  8249. #else
  8250. Aes enc[1];
  8251. #endif
  8252. byte cipher[AES_BLOCK_SIZE * 4];
  8253. #ifdef HAVE_AES_DECRYPT
  8254. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8255. Aes *dec = NULL;
  8256. #else
  8257. Aes dec[1];
  8258. #endif
  8259. byte plain [AES_BLOCK_SIZE * 4];
  8260. #endif
  8261. wc_test_ret_t ret = 0;
  8262. WOLFSSL_ENTER("aesofb_test");
  8263. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8264. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8265. if (enc == NULL)
  8266. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8267. #ifdef HAVE_AES_DECRYPT
  8268. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8269. if (dec == NULL)
  8270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8271. #endif
  8272. #else
  8273. XMEMSET(enc, 0, sizeof(Aes));
  8274. #ifdef HAVE_AES_DECRYPT
  8275. XMEMSET(dec, 0, sizeof(Aes));
  8276. #endif
  8277. ret = wc_AesInit(enc, HEAP_HINT, INVALID_DEVID);
  8278. if (ret != 0)
  8279. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8280. #ifdef HAVE_AES_DECRYPT
  8281. ret = wc_AesInit(dec, HEAP_HINT, INVALID_DEVID);
  8282. if (ret != 0)
  8283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8284. #endif
  8285. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8286. #ifdef WOLFSSL_AES_128
  8287. /* 128 key size test */
  8288. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8289. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8290. ret = EVP_test(wolfSSL_EVP_aes_128_ofb(), key2, iv2, plain2, sizeof(plain2),
  8291. cipher2, sizeof(cipher2));
  8292. if (ret != 0) {
  8293. goto out;
  8294. }
  8295. #endif
  8296. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8297. if (ret != 0)
  8298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8299. #ifdef HAVE_AES_DECRYPT
  8300. /* decrypt uses AES_ENCRYPTION */
  8301. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8302. if (ret != 0)
  8303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8304. #endif
  8305. XMEMSET(cipher, 0, sizeof(cipher));
  8306. ret = wc_AesOfbEncrypt(enc, cipher, plain2, AES_BLOCK_SIZE);
  8307. if (ret != 0)
  8308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8309. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE))
  8310. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8311. #ifdef HAVE_AES_DECRYPT
  8312. ret = wc_AesOfbDecrypt(dec, plain, cipher2, AES_BLOCK_SIZE);
  8313. if (ret != 0)
  8314. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8315. if (XMEMCMP(plain, plain2, AES_BLOCK_SIZE))
  8316. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8317. #endif /* HAVE_AES_DECRYPT */
  8318. #endif /* WOLFSSL_AES_128 */
  8319. #ifdef WOLFSSL_AES_192
  8320. /* 192 key size test */
  8321. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8322. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8323. ret = EVP_test(wolfSSL_EVP_aes_192_ofb(), key3, iv3, plain3, sizeof(plain3),
  8324. cipher3, sizeof(cipher3));
  8325. if (ret != 0) {
  8326. goto out;
  8327. }
  8328. #endif
  8329. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8330. if (ret != 0)
  8331. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8332. #ifdef HAVE_AES_DECRYPT
  8333. /* decrypt uses AES_ENCRYPTION */
  8334. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8335. if (ret != 0)
  8336. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8337. #endif
  8338. XMEMSET(cipher, 0, sizeof(cipher));
  8339. ret = wc_AesOfbEncrypt(enc, cipher, plain3, AES_BLOCK_SIZE);
  8340. if (ret != 0)
  8341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8342. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE))
  8343. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8344. #ifdef HAVE_AES_DECRYPT
  8345. ret = wc_AesOfbDecrypt(dec, plain, cipher3, AES_BLOCK_SIZE);
  8346. if (ret != 0)
  8347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8348. if (XMEMCMP(plain, plain3, AES_BLOCK_SIZE))
  8349. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8350. #endif /* HAVE_AES_DECRYPT */
  8351. #endif /* WOLFSSL_AES_192 */
  8352. #ifdef WOLFSSL_AES_256
  8353. /* 256 key size test */
  8354. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8355. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8356. ret = EVP_test(wolfSSL_EVP_aes_256_ofb(), key1, iv1, plain1, sizeof(plain1),
  8357. cipher1, sizeof(cipher1));
  8358. if (ret != 0) {
  8359. goto out;
  8360. }
  8361. #endif
  8362. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8363. if (ret != 0)
  8364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8365. #ifdef HAVE_AES_DECRYPT
  8366. /* decrypt uses AES_ENCRYPTION */
  8367. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8368. if (ret != 0)
  8369. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8370. #endif
  8371. XMEMSET(cipher, 0, sizeof(cipher));
  8372. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE);
  8373. if (ret != 0)
  8374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8375. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE))
  8376. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8377. ret = wc_AesOfbEncrypt(enc, cipher + AES_BLOCK_SIZE,
  8378. plain1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8379. if (ret != 0)
  8380. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8381. if (XMEMCMP(cipher + AES_BLOCK_SIZE, cipher1 + AES_BLOCK_SIZE,
  8382. AES_BLOCK_SIZE))
  8383. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8384. #ifdef HAVE_AES_DECRYPT
  8385. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE);
  8386. if (ret != 0)
  8387. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8388. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE))
  8389. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8390. ret = wc_AesOfbDecrypt(dec, plain + AES_BLOCK_SIZE,
  8391. cipher1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8392. if (ret != 0)
  8393. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8394. if (XMEMCMP(plain + AES_BLOCK_SIZE, plain1 + AES_BLOCK_SIZE,
  8395. AES_BLOCK_SIZE))
  8396. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8397. #endif /* HAVE_AES_DECRYPT */
  8398. /* multiple blocks at once */
  8399. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8400. if (ret != 0)
  8401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8402. #ifdef HAVE_AES_DECRYPT
  8403. /* decrypt uses AES_ENCRYPTION */
  8404. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8405. if (ret != 0)
  8406. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8407. #endif
  8408. XMEMSET(cipher, 0, sizeof(cipher));
  8409. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE * 3);
  8410. if (ret != 0)
  8411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8412. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 3))
  8413. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8414. #ifdef HAVE_AES_DECRYPT
  8415. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE * 3);
  8416. if (ret != 0)
  8417. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8418. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE * 3))
  8419. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8420. #endif /* HAVE_AES_DECRYPT */
  8421. /* inline decrypt/encrypt*/
  8422. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8423. if (ret != 0)
  8424. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8425. #ifdef HAVE_AES_DECRYPT
  8426. /* decrypt uses AES_ENCRYPTION */
  8427. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8428. if (ret != 0)
  8429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8430. #endif
  8431. XMEMCPY(cipher, plain1, AES_BLOCK_SIZE * 2);
  8432. ret = wc_AesOfbEncrypt(enc, cipher, cipher, AES_BLOCK_SIZE * 2);
  8433. if (ret != 0)
  8434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8435. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8436. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8437. #ifdef HAVE_AES_DECRYPT
  8438. ret = wc_AesOfbDecrypt(dec, cipher, cipher, AES_BLOCK_SIZE * 2);
  8439. if (ret != 0)
  8440. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8441. if (XMEMCMP(cipher, plain1, AES_BLOCK_SIZE * 2))
  8442. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8443. #endif /* HAVE_AES_DECRYPT */
  8444. /* 256 key size test leftover support */
  8445. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8446. if (ret != 0)
  8447. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8448. #ifdef HAVE_AES_DECRYPT
  8449. /* decrypt uses AES_ENCRYPTION */
  8450. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8451. if (ret != 0)
  8452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8453. #endif
  8454. XMEMSET(cipher, 0, sizeof(cipher));
  8455. ret = wc_AesOfbEncrypt(enc, cipher, plain1, 3);
  8456. if (ret != 0)
  8457. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8458. if (XMEMCMP(cipher, cipher1, 3))
  8459. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8460. ret = wc_AesOfbEncrypt(enc, cipher + 3, plain1 + 3, AES_BLOCK_SIZE);
  8461. if (ret != 0)
  8462. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8463. if (XMEMCMP(cipher + 3, cipher1 + 3, AES_BLOCK_SIZE))
  8464. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8465. #ifdef HAVE_AES_DECRYPT
  8466. ret = wc_AesOfbDecrypt(dec, plain, cipher1, 6);
  8467. if (ret != 0)
  8468. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8469. if (XMEMCMP(plain, plain1, 6))
  8470. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8471. ret = wc_AesOfbDecrypt(dec, plain + 6, cipher1 + 6, AES_BLOCK_SIZE);
  8472. if (ret != 0)
  8473. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8474. if (XMEMCMP(plain + 6, plain1 + 6, AES_BLOCK_SIZE))
  8475. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8476. #endif /* HAVE_AES_DECRYPT */
  8477. out:
  8478. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8479. wc_AesDelete(enc, &enc);
  8480. #else
  8481. wc_AesFree(enc);
  8482. #endif
  8483. #ifdef HAVE_AES_DECRYPT
  8484. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8485. wc_AesDelete(dec, &dec);
  8486. #else
  8487. wc_AesFree(dec);
  8488. #endif
  8489. #endif
  8490. #endif /* WOLFSSL_AES_256 */
  8491. return ret;
  8492. }
  8493. #endif /* WOLFSSL_AES_OFB */
  8494. #if defined(WOLFSSL_AES_CFB)
  8495. /* Test cases from NIST SP 800-38A, Recommendation for Block Cipher Modes of
  8496. * Operation Methods and Techniques
  8497. */
  8498. static wc_test_ret_t aescfb_test_0(void)
  8499. {
  8500. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8501. Aes *enc = NULL;
  8502. #else
  8503. Aes enc[1];
  8504. #endif
  8505. byte cipher[AES_BLOCK_SIZE * 4];
  8506. #ifdef HAVE_AES_DECRYPT
  8507. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8508. Aes *dec = NULL;
  8509. #else
  8510. Aes dec[1];
  8511. #endif
  8512. byte plain [AES_BLOCK_SIZE * 4];
  8513. #endif
  8514. wc_test_ret_t ret = 0;
  8515. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8516. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  8517. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  8518. };
  8519. #ifdef WOLFSSL_AES_128
  8520. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8521. {
  8522. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  8523. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  8524. };
  8525. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8526. {
  8527. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  8528. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  8529. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  8530. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b,
  8531. 0x26,0x75,0x1f,0x67,0xa3,0xcb,0xb1,0x40,
  8532. 0xb1,0x80,0x8c,0xf1,0x87,0xa4,0xf4,0xdf
  8533. };
  8534. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8535. {
  8536. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8537. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8538. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8539. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8540. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8541. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef
  8542. };
  8543. #endif /* WOLFSSL_AES_128 */
  8544. #ifdef WOLFSSL_AES_192
  8545. /* 192 size key test */
  8546. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8547. {
  8548. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  8549. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  8550. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  8551. };
  8552. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8553. {
  8554. 0xcd,0xc8,0x0d,0x6f,0xdd,0xf1,0x8c,0xab,
  8555. 0x34,0xc2,0x59,0x09,0xc9,0x9a,0x41,0x74,
  8556. 0x67,0xce,0x7f,0x7f,0x81,0x17,0x36,0x21,
  8557. 0x96,0x1a,0x2b,0x70,0x17,0x1d,0x3d,0x7a,
  8558. 0x2e,0x1e,0x8a,0x1d,0xd5,0x9b,0x88,0xb1,
  8559. 0xc8,0xe6,0x0f,0xed,0x1e,0xfa,0xc4,0xc9,
  8560. 0xc0,0x5f,0x9f,0x9c,0xa9,0x83,0x4f,0xa0,
  8561. 0x42,0xae,0x8f,0xba,0x58,0x4b,0x09,0xff
  8562. };
  8563. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8564. {
  8565. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8566. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8567. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8568. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8569. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8570. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8571. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8572. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8573. };
  8574. #endif /* WOLFSSL_AES_192 */
  8575. #ifdef WOLFSSL_AES_256
  8576. /* 256 size key simple test */
  8577. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8578. {
  8579. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  8580. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  8581. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  8582. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  8583. };
  8584. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8585. {
  8586. 0xdc,0x7e,0x84,0xbf,0xda,0x79,0x16,0x4b,
  8587. 0x7e,0xcd,0x84,0x86,0x98,0x5d,0x38,0x60,
  8588. 0x39,0xff,0xed,0x14,0x3b,0x28,0xb1,0xc8,
  8589. 0x32,0x11,0x3c,0x63,0x31,0xe5,0x40,0x7b,
  8590. 0xdf,0x10,0x13,0x24,0x15,0xe5,0x4b,0x92,
  8591. 0xa1,0x3e,0xd0,0xa8,0x26,0x7a,0xe2,0xf9,
  8592. 0x75,0xa3,0x85,0x74,0x1a,0xb9,0xce,0xf8,
  8593. 0x20,0x31,0x62,0x3d,0x55,0xb1,0xe4,0x71
  8594. };
  8595. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8596. {
  8597. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8598. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8599. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8600. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8601. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8602. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8603. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8604. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8605. };
  8606. #endif /* WOLFSSL_AES_256 */
  8607. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8608. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8609. if (enc == NULL)
  8610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8611. #ifdef HAVE_AES_DECRYPT
  8612. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8613. if (dec == NULL)
  8614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8615. #endif
  8616. #else
  8617. XMEMSET(enc, 0, sizeof(Aes));
  8618. #ifdef HAVE_AES_DECRYPT
  8619. XMEMSET(dec, 0, sizeof(Aes));
  8620. #endif
  8621. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8622. if (ret != 0)
  8623. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8624. #ifdef HAVE_AES_DECRYPT
  8625. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8626. if (ret != 0)
  8627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8628. #endif
  8629. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8630. #ifdef WOLFSSL_AES_128
  8631. /* 128 key tests */
  8632. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8633. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8634. ret = EVP_test(wolfSSL_EVP_aes_128_cfb128(), key1, iv, msg1, sizeof(msg1),
  8635. cipher1, sizeof(cipher1));
  8636. if (ret != 0) {
  8637. return ret;
  8638. }
  8639. #endif
  8640. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8641. if (ret != 0)
  8642. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8643. #ifdef HAVE_AES_DECRYPT
  8644. /* decrypt uses AES_ENCRYPTION */
  8645. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8646. if (ret != 0)
  8647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8648. #endif
  8649. XMEMSET(cipher, 0, sizeof(cipher));
  8650. ret = wc_AesCfbEncrypt(enc, cipher, msg1, AES_BLOCK_SIZE * 2);
  8651. if (ret != 0)
  8652. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8653. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8654. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8655. /* test restarting encryption process */
  8656. ret = wc_AesCfbEncrypt(enc, cipher + (AES_BLOCK_SIZE * 2),
  8657. msg1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE);
  8658. if (ret != 0)
  8659. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8660. if (XMEMCMP(cipher + (AES_BLOCK_SIZE * 2),
  8661. cipher1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE))
  8662. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8663. #ifdef HAVE_AES_DECRYPT
  8664. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 3);
  8665. if (ret != 0)
  8666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8667. if (XMEMCMP(plain, msg1, AES_BLOCK_SIZE * 3))
  8668. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8669. #endif /* HAVE_AES_DECRYPT */
  8670. #endif /* WOLFSSL_AES_128 */
  8671. #ifdef WOLFSSL_AES_192
  8672. /* 192 key size test */
  8673. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8674. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8675. ret = EVP_test(wolfSSL_EVP_aes_192_cfb128(), key2, iv, msg2, sizeof(msg2),
  8676. cipher2, sizeof(cipher2));
  8677. if (ret != 0) {
  8678. return ret;
  8679. }
  8680. #endif
  8681. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8682. if (ret != 0)
  8683. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8684. #ifdef HAVE_AES_DECRYPT
  8685. /* decrypt uses AES_ENCRYPTION */
  8686. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8687. if (ret != 0)
  8688. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8689. #endif
  8690. XMEMSET(cipher, 0, sizeof(cipher));
  8691. ret = wc_AesCfbEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE * 4);
  8692. if (ret != 0)
  8693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8694. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE * 4))
  8695. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8696. #ifdef HAVE_AES_DECRYPT
  8697. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 4);
  8698. if (ret != 0)
  8699. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8700. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE * 4))
  8701. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8702. #endif /* HAVE_AES_DECRYPT */
  8703. #endif /* WOLFSSL_AES_192 */
  8704. #ifdef WOLFSSL_AES_256
  8705. /* 256 key size test */
  8706. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8707. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8708. ret = EVP_test(wolfSSL_EVP_aes_256_cfb128(), key3, iv, msg3, sizeof(msg3),
  8709. cipher3, sizeof(cipher3));
  8710. if (ret != 0) {
  8711. return ret;
  8712. }
  8713. #endif
  8714. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8715. if (ret != 0)
  8716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8717. #ifdef HAVE_AES_DECRYPT
  8718. /* decrypt uses AES_ENCRYPTION */
  8719. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8720. if (ret != 0)
  8721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8722. #endif
  8723. /* test with data left overs, magic lengths are checking near edges */
  8724. XMEMSET(cipher, 0, sizeof(cipher));
  8725. ret = wc_AesCfbEncrypt(enc, cipher, msg3, 4);
  8726. if (ret != 0)
  8727. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8728. if (XMEMCMP(cipher, cipher3, 4))
  8729. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8730. ret = wc_AesCfbEncrypt(enc, cipher + 4, msg3 + 4, 27);
  8731. if (ret != 0)
  8732. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8733. if (XMEMCMP(cipher + 4, cipher3 + 4, 27))
  8734. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8735. ret = wc_AesCfbEncrypt(enc, cipher + 31, msg3 + 31,
  8736. (AES_BLOCK_SIZE * 4) - 31);
  8737. if (ret != 0)
  8738. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8739. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE * 4))
  8740. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8741. #ifdef HAVE_AES_DECRYPT
  8742. ret = wc_AesCfbDecrypt(dec, plain, cipher, 4);
  8743. if (ret != 0)
  8744. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8745. if (XMEMCMP(plain, msg3, 4))
  8746. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8747. ret = wc_AesCfbDecrypt(dec, plain + 4, cipher + 4, 4);
  8748. if (ret != 0)
  8749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8750. ret = wc_AesCfbDecrypt(dec, plain + 8, cipher + 8, 23);
  8751. if (ret != 0)
  8752. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8753. if (XMEMCMP(plain + 4, msg3 + 4, 27))
  8754. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8755. ret = wc_AesCfbDecrypt(dec, plain + 31, cipher + 31,
  8756. (AES_BLOCK_SIZE * 4) - 31);
  8757. if (ret != 0)
  8758. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8759. if (XMEMCMP(plain, msg3, AES_BLOCK_SIZE * 4))
  8760. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8761. #endif /* HAVE_AES_DECRYPT */
  8762. #endif /* WOLFSSL_AES_256 */
  8763. out:
  8764. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8765. wc_AesDelete(enc, &enc);
  8766. #else
  8767. wc_AesFree(enc);
  8768. #endif
  8769. #ifdef HAVE_AES_DECRYPT
  8770. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8771. wc_AesDelete(dec, &dec);
  8772. #else
  8773. wc_AesFree(dec);
  8774. #endif
  8775. #endif
  8776. return ret;
  8777. }
  8778. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0))
  8779. static wc_test_ret_t aescfb1_test(void)
  8780. {
  8781. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8782. Aes *enc = NULL;
  8783. #else
  8784. Aes enc[1];
  8785. #endif
  8786. byte cipher[AES_BLOCK_SIZE];
  8787. #ifdef HAVE_AES_DECRYPT
  8788. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8789. Aes *dec = NULL;
  8790. #else
  8791. Aes dec[1];
  8792. #endif
  8793. byte plain [AES_BLOCK_SIZE];
  8794. #endif
  8795. wc_test_ret_t ret = 0;
  8796. #ifdef WOLFSSL_AES_128
  8797. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8798. 0x4d,0xbb,0xdc,0xaa,0x59,0xf3,0x63,0xc9,
  8799. 0x2a,0x3b,0x98,0x43,0xad,0x20,0xe2,0xb7
  8800. };
  8801. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8802. {
  8803. 0xcd,0xef,0x9d,0x06,0x61,0xba,0xe4,0x73,
  8804. 0x8d,0x1a,0x58,0xa2,0xa6,0x22,0x8b,0x66
  8805. };
  8806. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8807. {
  8808. 0x00
  8809. };
  8810. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8811. {
  8812. 0xC0
  8813. };
  8814. WOLFSSL_SMALL_STACK_STATIC const byte cipher1_7bit[] =
  8815. {
  8816. 0x1C
  8817. };
  8818. #endif /* WOLFSSL_AES_128 */
  8819. #ifdef WOLFSSL_AES_192
  8820. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  8821. 0x57,0xc6,0x89,0x7c,0x99,0x52,0x28,0x13,
  8822. 0xbf,0x67,0x9c,0xe1,0x13,0x70,0xaf,0x5e
  8823. };
  8824. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8825. {
  8826. 0xba,0xa1,0x58,0xa1,0x6b,0x50,0x4a,0x10,
  8827. 0x8e,0xd4,0x33,0x2e,0xe7,0xf2,0x9b,0xf6,
  8828. 0xd1,0xac,0x46,0xa8,0xde,0x5a,0xfe,0x7a
  8829. };
  8830. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8831. {
  8832. 0x30
  8833. };
  8834. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8835. {
  8836. 0x80
  8837. };
  8838. #endif /* WOLFSSL_AES_192 */
  8839. #ifdef WOLFSSL_AES_256
  8840. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  8841. 0x63,0x2e,0x9f,0x83,0x1f,0xa3,0x80,0x5e,
  8842. 0x52,0x02,0xbc,0xe0,0x6d,0x04,0xf9,0xa0
  8843. };
  8844. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8845. {
  8846. 0xf6,0xfa,0xe4,0xf1,0x5d,0x91,0xfc,0x50,
  8847. 0x88,0x78,0x4f,0x84,0xa5,0x37,0x12,0x7e,
  8848. 0x32,0x63,0x55,0x9c,0x62,0x73,0x88,0x20,
  8849. 0xc2,0xcf,0x3d,0xe1,0x1c,0x2a,0x30,0x40
  8850. };
  8851. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8852. {
  8853. 0xF7, 0x00
  8854. };
  8855. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8856. {
  8857. 0x41, 0xC0
  8858. };
  8859. #endif /* WOLFSSL_AES_256 */
  8860. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8861. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8862. if (enc == NULL)
  8863. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8864. #ifdef HAVE_AES_DECRYPT
  8865. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8866. if (dec == NULL)
  8867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8868. #endif
  8869. #else
  8870. XMEMSET(enc, 0, sizeof(Aes));
  8871. #ifdef HAVE_AES_DECRYPT
  8872. XMEMSET(dec, 0, sizeof(Aes));
  8873. #endif
  8874. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8875. if (ret != 0)
  8876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8877. #ifdef HAVE_AES_DECRYPT
  8878. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8879. if (ret != 0)
  8880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8881. #endif
  8882. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8883. #ifdef WOLFSSL_AES_128
  8884. /* 128 key tests */
  8885. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8886. if (ret != 0)
  8887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8888. #ifdef HAVE_AES_DECRYPT
  8889. /* decrypt uses AES_ENCRYPTION */
  8890. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8891. if (ret != 0)
  8892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8893. #endif
  8894. XMEMSET(cipher, 0, sizeof(cipher));
  8895. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 2);
  8896. if (ret != 0)
  8897. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8898. if (cipher[0] != cipher1[0])
  8899. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8900. #ifdef HAVE_AES_DECRYPT
  8901. ret = wc_AesCfb1Decrypt(dec, plain, cipher, 2);
  8902. if (ret != 0)
  8903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8904. if (plain[0] != msg1[0])
  8905. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8906. #endif /* HAVE_AES_DECRYPT */
  8907. XMEMSET(cipher, 0, sizeof(cipher));
  8908. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 7);
  8909. if (ret != 0)
  8910. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8911. if (cipher[0] != cipher1_7bit[0])
  8912. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8913. #ifdef OPENSSL_EXTRA
  8914. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8915. if (ret != 0)
  8916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8917. XMEMSET(cipher, 0, sizeof(cipher));
  8918. ret = wc_AesCfb1Encrypt(enc, cipher, msg1,
  8919. sizeof(msg1) * WOLFSSL_BIT_SIZE);
  8920. if (ret != 0)
  8921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8922. #ifndef WOLFCRYPT_ONLY
  8923. ret = EVP_test(wolfSSL_EVP_aes_128_cfb1(), key1, iv, msg1, sizeof(msg1),
  8924. cipher, sizeof(msg1));
  8925. if (ret != 0) {
  8926. goto out;
  8927. }
  8928. #endif
  8929. #endif
  8930. #endif /* WOLFSSL_AES_128 */
  8931. #ifdef WOLFSSL_AES_192
  8932. /* 192 key tests */
  8933. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8934. if (ret != 0)
  8935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8936. XMEMSET(cipher, 0, sizeof(cipher));
  8937. ret = wc_AesCfb1Encrypt(enc, cipher, msg2, 4);
  8938. if (ret != 0)
  8939. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8940. if (XMEMCMP(cipher, cipher2, sizeof(cipher2)) != 0)
  8941. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8942. #ifdef OPENSSL_EXTRA
  8943. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8944. if (ret != 0)
  8945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8946. XMEMSET(cipher, 0, sizeof(cipher));
  8947. ret = wc_AesCfb1Encrypt(enc, cipher, msg2,
  8948. sizeof(msg2) * WOLFSSL_BIT_SIZE);
  8949. if (ret != 0)
  8950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8951. #ifndef WOLFCRYPT_ONLY
  8952. ret = EVP_test(wolfSSL_EVP_aes_192_cfb1(), key2, iv2, msg2, sizeof(msg2),
  8953. cipher, sizeof(msg2));
  8954. if (ret != 0) {
  8955. goto out;
  8956. }
  8957. #endif
  8958. #endif
  8959. #endif /* WOLFSSL_AES_192 */
  8960. #ifdef WOLFSSL_AES_256
  8961. /* 256 key tests */
  8962. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8963. if (ret != 0)
  8964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8965. XMEMSET(cipher, 0, sizeof(cipher));
  8966. ret = wc_AesCfb1Encrypt(enc, cipher, msg3, 10);
  8967. if (ret != 0)
  8968. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8969. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  8970. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8971. #ifdef OPENSSL_EXTRA
  8972. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8973. if (ret != 0)
  8974. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8975. XMEMSET(cipher, 0, sizeof(cipher));
  8976. ret = wc_AesCfb1Encrypt(enc, cipher, msg3,
  8977. sizeof(msg3) * WOLFSSL_BIT_SIZE);
  8978. if (ret != 0)
  8979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8980. #ifndef WOLFCRYPT_ONLY
  8981. ret = EVP_test(wolfSSL_EVP_aes_256_cfb1(), key3, iv3, msg3, sizeof(msg3),
  8982. cipher, sizeof(msg3));
  8983. if (ret != 0) {
  8984. goto out;
  8985. }
  8986. #endif
  8987. #endif
  8988. #endif /* WOLFSSL_AES_256 */
  8989. out:
  8990. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8991. wc_AesDelete(enc, &enc);
  8992. #else
  8993. wc_AesFree(enc);
  8994. #endif
  8995. #ifdef HAVE_AES_DECRYPT
  8996. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8997. wc_AesDelete(dec, &dec);
  8998. #else
  8999. wc_AesFree(dec);
  9000. #endif
  9001. #endif
  9002. return ret;
  9003. }
  9004. static wc_test_ret_t aescfb8_test(void)
  9005. {
  9006. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9007. Aes *enc = NULL;
  9008. #else
  9009. Aes enc[1];
  9010. #endif
  9011. byte cipher[AES_BLOCK_SIZE];
  9012. #ifdef HAVE_AES_DECRYPT
  9013. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9014. Aes *dec = NULL;
  9015. #else
  9016. Aes dec[1];
  9017. #endif
  9018. byte plain [AES_BLOCK_SIZE];
  9019. #endif
  9020. wc_test_ret_t ret = 0;
  9021. #ifdef WOLFSSL_AES_128
  9022. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  9023. 0xf4,0x75,0xc6,0x49,0x91,0xb2,0x0e,0xae,
  9024. 0xe1,0x83,0xa2,0x26,0x29,0xe2,0x1e,0x22
  9025. };
  9026. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  9027. {
  9028. 0xc8,0xfe,0x9b,0xf7,0x7b,0x93,0x0f,0x46,
  9029. 0xd2,0x07,0x8b,0x8c,0x0e,0x65,0x7c,0xd4
  9030. };
  9031. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  9032. {
  9033. 0xd2,0x76,0x91
  9034. };
  9035. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  9036. {
  9037. 0xc9,0x06,0x35
  9038. };
  9039. #endif /* WOLFSSL_AES_128 */
  9040. #ifdef WOLFSSL_AES_192
  9041. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  9042. 0x0a,0x02,0x84,0x6b,0x62,0xab,0xb6,0x93,
  9043. 0xef,0x31,0xd7,0x54,0x84,0x2e,0xed,0x29
  9044. };
  9045. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  9046. {
  9047. 0xba,0xf0,0x8b,0x76,0x31,0x7a,0x65,0xc5,
  9048. 0xf0,0x7a,0xe6,0xf5,0x7e,0xb0,0xe6,0x54,
  9049. 0x88,0x65,0x93,0x24,0xd2,0x97,0x09,0xe3
  9050. };
  9051. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  9052. {
  9053. 0x72,0x9c,0x0b,0x6d,0xeb,0x75,0xfa,0x6e,
  9054. 0xb5,0xe8
  9055. };
  9056. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  9057. {
  9058. 0x98,0x95,0x93,0x24,0x02,0x39,0x3d,0xc3,
  9059. 0x3a,0x60
  9060. };
  9061. #endif
  9062. #ifdef WOLFSSL_AES_256
  9063. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  9064. 0x33,0x8c,0x55,0x2f,0xf1,0xec,0xa1,0x44,
  9065. 0x08,0xe0,0x5d,0x8c,0xf9,0xf3,0xb3,0x1b
  9066. };
  9067. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  9068. {
  9069. 0x06,0x48,0x74,0x09,0x2f,0x7a,0x13,0xcc,
  9070. 0x44,0x62,0x24,0x7a,0xd4,0x23,0xd0,0xe9,
  9071. 0x6e,0xdf,0x42,0xe8,0xb6,0x7a,0x5a,0x23,
  9072. 0xb7,0xa0,0xa6,0x47,0x7b,0x09,0x8e,0x66
  9073. };
  9074. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  9075. {
  9076. 0x1c,0xff,0x95
  9077. };
  9078. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  9079. {
  9080. 0xb9,0x74,0xfa
  9081. };
  9082. #endif
  9083. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9084. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  9085. if (enc == NULL)
  9086. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9087. #ifdef HAVE_AES_DECRYPT
  9088. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  9089. if (dec == NULL)
  9090. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9091. #endif
  9092. #else
  9093. XMEMSET(enc, 0, sizeof(Aes));
  9094. #ifdef HAVE_AES_DECRYPT
  9095. XMEMSET(dec, 0, sizeof(Aes));
  9096. #endif
  9097. ret = wc_AesInit(enc, HEAP_HINT, devId);
  9098. if (ret != 0)
  9099. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9100. #ifdef HAVE_AES_DECRYPT
  9101. ret = wc_AesInit(dec, HEAP_HINT, devId);
  9102. if (ret != 0)
  9103. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9104. #endif
  9105. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  9106. #ifdef WOLFSSL_AES_128
  9107. /* 128 key tests */
  9108. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9109. ret = EVP_test(wolfSSL_EVP_aes_128_cfb8(), key1, iv, msg1, sizeof(msg1),
  9110. cipher1, sizeof(cipher1));
  9111. if (ret != 0) {
  9112. return ret;
  9113. }
  9114. #endif
  9115. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9116. if (ret != 0)
  9117. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9118. #ifdef HAVE_AES_DECRYPT
  9119. /* decrypt uses AES_ENCRYPTION */
  9120. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9121. if (ret != 0)
  9122. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9123. #endif
  9124. XMEMSET(cipher, 0, sizeof(cipher));
  9125. ret = wc_AesCfb8Encrypt(enc, cipher, msg1, sizeof(msg1));
  9126. if (ret != 0)
  9127. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9128. if (XMEMCMP(cipher, cipher1, sizeof(cipher1)) != 0)
  9129. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9130. #ifdef HAVE_AES_DECRYPT
  9131. ret = wc_AesCfb8Decrypt(dec, plain, cipher, sizeof(msg1));
  9132. if (ret != 0)
  9133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9134. if (XMEMCMP(plain, msg1, sizeof(msg1)) != 0)
  9135. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9136. #endif /* HAVE_AES_DECRYPT */
  9137. #endif /* WOLFSSL_AES_128 */
  9138. #ifdef WOLFSSL_AES_192
  9139. /* 192 key tests */
  9140. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  9141. if (ret != 0)
  9142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9143. XMEMSET(cipher, 0, sizeof(cipher));
  9144. ret = wc_AesCfb8Encrypt(enc, cipher, msg2, sizeof(msg2));
  9145. if (ret != 0)
  9146. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9147. if (XMEMCMP(cipher, cipher2, sizeof(msg2)) != 0)
  9148. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9149. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9150. ret = EVP_test(wolfSSL_EVP_aes_192_cfb8(), key2, iv2, msg2, sizeof(msg2),
  9151. cipher2, sizeof(msg2));
  9152. if (ret != 0) {
  9153. return ret;
  9154. }
  9155. #endif
  9156. #endif /* WOLFSSL_AES_192 */
  9157. #ifdef WOLFSSL_AES_256
  9158. /* 256 key tests */
  9159. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  9160. if (ret != 0)
  9161. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9162. XMEMSET(cipher, 0, sizeof(cipher));
  9163. ret = wc_AesCfb8Encrypt(enc, cipher, msg3, sizeof(msg3));
  9164. if (ret != 0)
  9165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9166. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  9167. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9168. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9169. ret = EVP_test(wolfSSL_EVP_aes_256_cfb8(), key3, iv3, msg3, sizeof(msg3),
  9170. cipher3, sizeof(msg3));
  9171. if (ret != 0) {
  9172. goto out;
  9173. }
  9174. #endif
  9175. #endif /* WOLFSSL_AES_256 */
  9176. out:
  9177. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9178. wc_AesDelete(enc, &enc);
  9179. #else
  9180. wc_AesFree(enc);
  9181. #endif
  9182. #ifdef HAVE_AES_DECRYPT
  9183. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9184. wc_AesDelete(dec, &dec);
  9185. #else
  9186. wc_AesFree(dec);
  9187. #endif
  9188. #endif
  9189. return ret;
  9190. }
  9191. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  9192. #endif /* WOLFSSL_AES_CFB */
  9193. #ifndef HAVE_RENESAS_SYNC
  9194. static wc_test_ret_t aes_key_size_test(void)
  9195. {
  9196. wc_test_ret_t ret;
  9197. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9198. Aes *aes = NULL;
  9199. #else
  9200. Aes aes[1];
  9201. #endif
  9202. byte key16[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9203. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9204. #ifndef WOLFSSL_CRYPTOCELL
  9205. byte key24[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9206. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9207. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
  9208. #endif
  9209. byte key32[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9210. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9211. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9212. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9213. byte iv[] = "1234567890abcdef";
  9214. #ifndef HAVE_FIPS
  9215. word32 keySize;
  9216. #endif
  9217. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9218. aes = wc_AesNew(HEAP_HINT, devId, &ret);
  9219. if (aes == NULL)
  9220. return WC_TEST_RET_ENC_EC(ret);
  9221. #else
  9222. ret = wc_AesInit(aes, HEAP_HINT, devId);
  9223. /* 0 check OK for FIPSv1 */
  9224. if (ret != 0)
  9225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9226. #endif
  9227. #if !defined(HAVE_FIPS) || \
  9228. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  9229. /* w/ FIPS v1 (cert 2425) wc_AesInit just returns 0 always as it's not
  9230. * supported with that FIPS version */
  9231. ret = wc_AesInit(NULL, HEAP_HINT, devId);
  9232. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9234. #endif
  9235. #ifndef HAVE_FIPS
  9236. /* Parameter Validation testing. */
  9237. ret = wc_AesGetKeySize(NULL, NULL);
  9238. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9239. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9240. ret = wc_AesGetKeySize(aes, NULL);
  9241. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9242. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9243. ret = wc_AesGetKeySize(NULL, &keySize);
  9244. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9246. /* Crashes in FIPS */
  9247. ret = wc_AesSetKey(NULL, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9248. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9249. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9250. #endif
  9251. /* NULL IV indicates to use all zeros IV. */
  9252. ret = wc_AesSetKey(aes, key16, sizeof(key16), NULL, AES_ENCRYPTION);
  9253. #ifdef WOLFSSL_AES_128
  9254. if (ret != 0)
  9255. #else
  9256. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9257. #endif
  9258. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9259. ret = wc_AesSetKey(aes, key32, sizeof(key32) - 1, iv, AES_ENCRYPTION);
  9260. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9261. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9262. /* CryptoCell handles rounds internally */
  9263. #if !defined(HAVE_FIPS) && !defined(WOLFSSL_CRYPTOCELL)
  9264. /* PSA don't use aes->rounds */
  9265. #if !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_AES)
  9266. /* Force invalid rounds */
  9267. aes->rounds = 16;
  9268. ret = wc_AesGetKeySize(aes, &keySize);
  9269. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9271. #endif
  9272. #endif
  9273. ret = wc_AesSetKey(aes, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9274. #ifdef WOLFSSL_AES_128
  9275. if (ret != 0)
  9276. #else
  9277. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9278. #endif
  9279. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9280. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128)
  9281. ret = wc_AesGetKeySize(aes, &keySize);
  9282. if (ret != 0 || keySize != sizeof(key16))
  9283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9284. #endif
  9285. #ifndef WOLFSSL_CRYPTOCELL
  9286. /* Cryptocell only supports AES-128 key size */
  9287. ret = wc_AesSetKey(aes, key24, sizeof(key24), iv, AES_ENCRYPTION);
  9288. #ifdef WOLFSSL_AES_192
  9289. if (ret != 0)
  9290. #else
  9291. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9292. #endif
  9293. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9294. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192)
  9295. ret = wc_AesGetKeySize(aes, &keySize);
  9296. if (ret != 0 || keySize != sizeof(key24))
  9297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9298. #endif
  9299. ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION);
  9300. #ifdef WOLFSSL_AES_256
  9301. if (ret != 0)
  9302. #else
  9303. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9304. #endif
  9305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9306. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256)
  9307. ret = wc_AesGetKeySize(aes, &keySize);
  9308. if (ret != 0 || keySize != sizeof(key32))
  9309. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9310. #endif
  9311. #endif /* !WOLFSSL_CRYPTOCELL */
  9312. ret = 0; /* success */
  9313. out:
  9314. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9315. wc_AesDelete(aes, &aes);
  9316. #else
  9317. wc_AesFree(aes);
  9318. #endif
  9319. return ret;
  9320. }
  9321. #endif /* !HAVE_RENESAS_SYNC */
  9322. #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  9323. /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */
  9324. #ifdef WOLFSSL_AES_128
  9325. static wc_test_ret_t aes_xts_128_test(void)
  9326. {
  9327. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9328. XtsAes *aes = NULL;
  9329. #else
  9330. XtsAes aes[1];
  9331. #endif
  9332. int aes_inited = 0;
  9333. wc_test_ret_t ret = 0;
  9334. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9335. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9336. #ifdef WOLFSSL_AESXTS_STREAM
  9337. struct XtsAesStreamData stream;
  9338. #endif
  9339. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9340. !defined(WOLFSSL_AFALG)
  9341. #define LARGE_XTS_SZ 1024
  9342. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9343. byte* large_input = NULL;
  9344. #else
  9345. byte large_input[LARGE_XTS_SZ];
  9346. #endif
  9347. #endif
  9348. /* 128 key tests */
  9349. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9350. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  9351. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  9352. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  9353. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  9354. };
  9355. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9356. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9357. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9358. };
  9359. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9360. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9361. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9362. };
  9363. /* plain text test of partial block is not from NIST test vector list */
  9364. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9365. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9366. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9367. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9368. };
  9369. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9370. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a,
  9371. 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63
  9372. };
  9373. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9374. 0x39, 0x25, 0x79, 0x05, 0xdf, 0xcc, 0x77, 0x76,
  9375. 0x6c, 0x87, 0x0a, 0x80, 0x6a, 0x60, 0xe3, 0xc0,
  9376. 0x93, 0xd1, 0x2a, 0xcf, 0xcb, 0x51, 0x42, 0xfa,
  9377. 0x09, 0x69, 0x89, 0x62, 0x5b, 0x60, 0xdb, 0x16
  9378. };
  9379. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9380. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9381. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9382. };
  9383. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9384. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9385. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9386. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9387. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9388. };
  9389. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9390. 0xd6, 0xbe, 0x04, 0x6d, 0x41, 0xf2, 0x3b, 0x5e,
  9391. 0xd7, 0x0b, 0x6b, 0x3d, 0x5c, 0x8e, 0x66, 0x23,
  9392. 0x2b, 0xe6, 0xb8, 0x07, 0xd4, 0xdc, 0xc6, 0x0e,
  9393. 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22
  9394. };
  9395. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9396. 0x2b, 0xf7, 0x2c, 0xf3, 0xeb, 0x85, 0xef, 0x7b,
  9397. 0x0b, 0x76, 0xa0, 0xaa, 0xf3, 0x3f, 0x25, 0x8b,
  9398. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
  9399. };
  9400. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9401. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9402. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9403. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9404. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9405. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9406. };
  9407. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9408. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9409. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9410. };
  9411. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9412. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9413. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9414. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9415. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9416. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9417. };
  9418. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9419. 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23,
  9420. 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12,
  9421. 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36,
  9422. 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF,
  9423. 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD
  9424. };
  9425. #endif /* HAVE_FIPS */
  9426. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9427. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9428. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9429. #endif
  9430. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  9431. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  9432. ret = EVP_test(wolfSSL_EVP_aes_128_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  9433. if (ret != 0) {
  9434. printf("EVP_aes_128_xts failed!\n");
  9435. goto out;
  9436. }
  9437. #endif
  9438. XMEMSET(buf, 0, sizeof(buf));
  9439. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9440. if (ret != 0)
  9441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9442. else
  9443. aes_inited = 1;
  9444. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9445. if (ret != 0)
  9446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9447. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9448. #if defined(WOLFSSL_ASYNC_CRYPT)
  9449. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9450. #endif
  9451. if (ret != 0)
  9452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9453. if (XMEMCMP(c2, buf, sizeof(c2)))
  9454. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9455. #ifdef WOLFSSL_AESXTS_STREAM
  9456. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9457. #if defined(WOLFSSL_ASYNC_CRYPT)
  9458. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9459. #endif
  9460. if (ret != 0)
  9461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9462. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  9463. #if defined(WOLFSSL_ASYNC_CRYPT)
  9464. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9465. #endif
  9466. if (ret != 0)
  9467. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9468. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  9469. #if defined(WOLFSSL_ASYNC_CRYPT)
  9470. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9471. #endif
  9472. if (ret != 0)
  9473. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9474. if (XMEMCMP(c2, buf, sizeof(c2)))
  9475. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9476. #endif /* WOLFSSL_AESXTS_STREAM */
  9477. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9478. defined(WC_C_DYNAMIC_FALLBACK)
  9479. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9480. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9481. #if defined(WOLFSSL_ASYNC_CRYPT)
  9482. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9483. #endif
  9484. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9485. if (ret != 0)
  9486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9487. if (XMEMCMP(c2, buf, sizeof(c2)))
  9488. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9489. #endif
  9490. XMEMSET(buf, 0, sizeof(buf));
  9491. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9492. if (ret != 0)
  9493. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9494. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9495. #if defined(WOLFSSL_ASYNC_CRYPT)
  9496. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9497. #endif
  9498. if (ret != 0)
  9499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9500. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9501. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9502. #ifdef WOLFSSL_AESXTS_STREAM
  9503. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i2), &stream);
  9504. #if defined(WOLFSSL_ASYNC_CRYPT)
  9505. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9506. #endif
  9507. if (ret != 0)
  9508. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9509. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9510. #if defined(WOLFSSL_ASYNC_CRYPT)
  9511. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9512. #endif
  9513. if (ret != 0)
  9514. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9515. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9516. #if defined(WOLFSSL_ASYNC_CRYPT)
  9517. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9518. #endif
  9519. if (ret != 0)
  9520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9521. if (XMEMCMP(c1, buf, sizeof(c1)))
  9522. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9523. #endif /* WOLFSSL_AESXTS_STREAM */
  9524. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9525. defined(WC_C_DYNAMIC_FALLBACK)
  9526. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9527. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9528. #if defined(WOLFSSL_ASYNC_CRYPT)
  9529. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9530. #endif
  9531. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9532. if (ret != 0)
  9533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9534. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9535. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9536. #endif
  9537. /* partial block encryption test */
  9538. XMEMSET(cipher, 0, sizeof(cipher));
  9539. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9540. #if defined(WOLFSSL_ASYNC_CRYPT)
  9541. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9542. #endif
  9543. if (ret != 0)
  9544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9545. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9546. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9547. #ifdef WOLFSSL_AESXTS_STREAM
  9548. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9549. #if defined(WOLFSSL_ASYNC_CRYPT)
  9550. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9551. #endif
  9552. if (ret != 0)
  9553. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9554. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  9555. #if defined(WOLFSSL_ASYNC_CRYPT)
  9556. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9557. #endif
  9558. if (ret != 0)
  9559. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9560. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9561. #if defined(WOLFSSL_ASYNC_CRYPT)
  9562. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9563. #endif
  9564. if (ret != 0)
  9565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9566. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  9567. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9568. #endif /* WOLFSSL_AESXTS_STREAM */
  9569. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9570. defined(WC_C_DYNAMIC_FALLBACK)
  9571. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9572. XMEMSET(cipher, 0, sizeof(cipher));
  9573. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9574. #if defined(WOLFSSL_ASYNC_CRYPT)
  9575. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9576. #endif
  9577. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9578. if (ret != 0)
  9579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9580. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9581. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9582. #endif
  9583. /* partial block decrypt test */
  9584. XMEMSET(buf, 0, sizeof(buf));
  9585. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9586. if (ret != 0)
  9587. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9588. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9589. #if defined(WOLFSSL_ASYNC_CRYPT)
  9590. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9591. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9592. #else
  9593. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9594. #endif
  9595. #endif
  9596. if (ret != 0)
  9597. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9598. if (XMEMCMP(pp, buf, sizeof(pp)))
  9599. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9600. #ifdef WOLFSSL_AESXTS_STREAM
  9601. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9602. #if defined(WOLFSSL_ASYNC_CRYPT)
  9603. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9604. #endif
  9605. if (ret != 0)
  9606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9607. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  9608. #if defined(WOLFSSL_ASYNC_CRYPT)
  9609. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9610. #endif
  9611. if (ret != 0)
  9612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9613. if (XMEMCMP(pp, buf, sizeof(pp)))
  9614. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9615. #endif /* WOLFSSL_AESXTS_STREAM */
  9616. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9617. defined(WC_C_DYNAMIC_FALLBACK)
  9618. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9619. XMEMSET(buf, 0, sizeof(buf));
  9620. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9621. #if defined(WOLFSSL_ASYNC_CRYPT)
  9622. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9623. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9624. #else
  9625. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9626. #endif
  9627. #endif
  9628. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9629. if (ret != 0)
  9630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9631. if (XMEMCMP(pp, buf, sizeof(pp)))
  9632. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9633. #endif
  9634. /* NIST decrypt test vector */
  9635. XMEMSET(buf, 0, sizeof(buf));
  9636. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9637. #if defined(WOLFSSL_ASYNC_CRYPT)
  9638. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9639. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9640. #else
  9641. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9642. #endif
  9643. #endif
  9644. if (ret != 0)
  9645. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9646. if (XMEMCMP(p1, buf, sizeof(p1)))
  9647. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9648. #ifdef WOLFSSL_AESXTS_STREAM
  9649. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9650. #if defined(WOLFSSL_ASYNC_CRYPT)
  9651. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9652. #endif
  9653. if (ret != 0)
  9654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9655. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  9656. #if defined(WOLFSSL_ASYNC_CRYPT)
  9657. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9658. #endif
  9659. if (ret != 0)
  9660. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9661. if (XMEMCMP(p1, buf, sizeof(p1)))
  9662. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9663. #endif /* WOLFSSL_AESXTS_STREAM */
  9664. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9665. defined(WC_C_DYNAMIC_FALLBACK)
  9666. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9667. XMEMSET(buf, 0, sizeof(buf));
  9668. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9669. #if defined(WOLFSSL_ASYNC_CRYPT)
  9670. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9671. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9672. #else
  9673. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9674. #endif
  9675. #endif
  9676. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9677. if (ret != 0)
  9678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9679. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  9680. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9681. #endif
  9682. /* fail case with decrypting using wrong key */
  9683. XMEMSET(buf, 0, sizeof(buf));
  9684. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9685. #if defined(WOLFSSL_ASYNC_CRYPT)
  9686. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9687. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9688. #else
  9689. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9690. #endif
  9691. #endif
  9692. if (ret != 0)
  9693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9694. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  9695. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9696. /* set correct key and retest */
  9697. XMEMSET(buf, 0, sizeof(buf));
  9698. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  9699. if (ret != 0)
  9700. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9701. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9702. #if defined(WOLFSSL_ASYNC_CRYPT)
  9703. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9704. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9705. #else
  9706. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9707. #endif
  9708. #endif
  9709. if (ret != 0)
  9710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9711. if (XMEMCMP(p2, buf, sizeof(p2)))
  9712. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9713. #ifndef HAVE_FIPS
  9714. /* Test ciphertext stealing in-place. */
  9715. XMEMCPY(buf, p3, sizeof(p3));
  9716. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  9717. if (ret != 0)
  9718. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9719. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  9720. #if defined(WOLFSSL_ASYNC_CRYPT)
  9721. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9722. #endif
  9723. if (ret != 0)
  9724. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9725. if (XMEMCMP(c3, buf, sizeof(c3)))
  9726. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9727. #ifdef WOLFSSL_AESXTS_STREAM
  9728. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  9729. #if defined(WOLFSSL_ASYNC_CRYPT)
  9730. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9731. #endif
  9732. if (ret != 0)
  9733. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9734. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  9735. #if defined(WOLFSSL_ASYNC_CRYPT)
  9736. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9737. #endif
  9738. if (ret != 0)
  9739. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9740. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  9741. #if defined(WOLFSSL_ASYNC_CRYPT)
  9742. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9743. #endif
  9744. if (ret != 0)
  9745. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9746. if (XMEMCMP(c3, buf, sizeof(c3)))
  9747. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9748. #endif /* WOLFSSL_AESXTS_STREAM */
  9749. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  9750. if (ret != 0)
  9751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9752. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  9753. #if defined(WOLFSSL_ASYNC_CRYPT)
  9754. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9755. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9756. #else
  9757. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9758. #endif
  9759. #endif
  9760. if (ret != 0)
  9761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9762. if (XMEMCMP(p3, buf, sizeof(p3)))
  9763. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9764. #ifdef WOLFSSL_AESXTS_STREAM
  9765. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  9766. #if defined(WOLFSSL_ASYNC_CRYPT)
  9767. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9768. #endif
  9769. if (ret != 0)
  9770. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9771. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  9772. #if defined(WOLFSSL_ASYNC_CRYPT)
  9773. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9774. #endif
  9775. if (ret != 0)
  9776. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9777. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  9778. #if defined(WOLFSSL_ASYNC_CRYPT)
  9779. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9780. #endif
  9781. if (ret != 0)
  9782. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9783. if (XMEMCMP(p3, buf, sizeof(p3)))
  9784. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9785. #endif /* WOLFSSL_AESXTS_STREAM */
  9786. #endif /* !HAVE_FIPS */
  9787. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9788. !defined(WOLFSSL_AFALG)
  9789. {
  9790. int i;
  9791. int j;
  9792. #ifdef WOLFSSL_AESXTS_STREAM
  9793. int k;
  9794. #endif
  9795. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9796. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  9797. DYNAMIC_TYPE_TMP_BUFFER);
  9798. if (large_input == NULL)
  9799. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  9800. #endif
  9801. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9802. large_input[i] = (byte)i;
  9803. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9804. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9805. if (ret != 0)
  9806. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9807. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9808. sizeof(i1));
  9809. #if defined(WOLFSSL_ASYNC_CRYPT)
  9810. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9811. #endif
  9812. if (ret != 0)
  9813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9814. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9815. if (ret != 0)
  9816. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9817. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9818. sizeof(i1));
  9819. #if defined(WOLFSSL_ASYNC_CRYPT)
  9820. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9821. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9822. WC_ASYNC_FLAG_NONE);
  9823. #else
  9824. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9825. #endif
  9826. #endif
  9827. if (ret != 0)
  9828. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9829. for (i = 0; i < j; i++) {
  9830. if (large_input[i] != (byte)i) {
  9831. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9832. }
  9833. }
  9834. }
  9835. #ifdef WOLFSSL_AESXTS_STREAM
  9836. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9837. large_input[i] = (byte)i;
  9838. /* first, encrypt block by block then decrypt with a one-shot call. */
  9839. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9840. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9841. if (ret != 0)
  9842. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9843. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9844. #if defined(WOLFSSL_ASYNC_CRYPT)
  9845. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9846. #endif
  9847. if (ret != 0)
  9848. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9849. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9850. if ((j - k) < AES_BLOCK_SIZE*2)
  9851. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9852. else
  9853. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9854. #if defined(WOLFSSL_ASYNC_CRYPT)
  9855. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9856. #endif
  9857. if (ret != 0)
  9858. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9859. if ((j - k) < AES_BLOCK_SIZE*2)
  9860. break;
  9861. }
  9862. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9863. if (ret != 0)
  9864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9865. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9866. sizeof(i1));
  9867. #if defined(WOLFSSL_ASYNC_CRYPT)
  9868. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9869. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9870. WC_ASYNC_FLAG_NONE);
  9871. #else
  9872. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9873. #endif
  9874. #endif
  9875. if (ret != 0)
  9876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9877. for (i = 0; i < j; i++) {
  9878. if (large_input[i] != (byte)i) {
  9879. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9880. }
  9881. }
  9882. }
  9883. /* second, encrypt with a one-shot call then decrypt block by block. */
  9884. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9885. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9886. if (ret != 0)
  9887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9888. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9889. sizeof(i1));
  9890. #if defined(WOLFSSL_ASYNC_CRYPT)
  9891. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9892. #endif
  9893. if (ret != 0)
  9894. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9895. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9896. if (ret != 0)
  9897. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9898. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9899. #if defined(WOLFSSL_ASYNC_CRYPT)
  9900. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9901. #endif
  9902. if (ret != 0)
  9903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9904. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9905. if ((j - k) < AES_BLOCK_SIZE*2)
  9906. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9907. else
  9908. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9909. #if defined(WOLFSSL_ASYNC_CRYPT)
  9910. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9911. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9912. WC_ASYNC_FLAG_NONE);
  9913. #else
  9914. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9915. #endif
  9916. #endif
  9917. if (ret != 0)
  9918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9919. if ((j - k) < AES_BLOCK_SIZE*2)
  9920. break;
  9921. }
  9922. for (i = 0; i < j; i++) {
  9923. if (large_input[i] != (byte)i) {
  9924. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9925. }
  9926. }
  9927. }
  9928. #endif /* WOLFSSL_AESXTS_STREAM */
  9929. }
  9930. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  9931. * !WOLFSSL_AFALG
  9932. */
  9933. out:
  9934. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9935. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  9936. !defined(WOLFSSL_NO_MALLOC)
  9937. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9938. #endif
  9939. if (aes_inited)
  9940. wc_AesXtsFree(aes);
  9941. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9942. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9943. #endif
  9944. return ret;
  9945. }
  9946. #endif /* WOLFSSL_AES_128 */
  9947. #ifdef WOLFSSL_AES_192
  9948. static wc_test_ret_t aes_xts_192_test(void)
  9949. {
  9950. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9951. XtsAes *aes = NULL;
  9952. #else
  9953. XtsAes aes[1];
  9954. #endif
  9955. int aes_inited = 0;
  9956. wc_test_ret_t ret = 0;
  9957. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9958. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9959. #ifdef WOLFSSL_AESXTS_STREAM
  9960. struct XtsAesStreamData stream;
  9961. #endif
  9962. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9963. !defined(WOLFSSL_AFALG)
  9964. #define LARGE_XTS_SZ 1024
  9965. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9966. byte* large_input = NULL;
  9967. #else
  9968. byte large_input[LARGE_XTS_SZ];
  9969. #endif
  9970. #endif
  9971. /* 192 bit key tests */
  9972. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9973. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  9974. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  9975. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  9976. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  9977. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  9978. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3
  9979. };
  9980. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9981. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9982. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9983. };
  9984. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9985. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9986. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9987. };
  9988. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9989. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9990. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9991. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9992. };
  9993. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9994. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4,
  9995. 0xdb, 0x4e, 0xd3, 0x69, 0xdf, 0x8e, 0x3a, 0xe0
  9996. };
  9997. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9998. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  9999. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10000. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10001. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10002. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10003. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a
  10004. };
  10005. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10006. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  10007. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  10008. };
  10009. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10010. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  10011. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  10012. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  10013. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  10014. };
  10015. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10016. 0x6c, 0xa6, 0xb5, 0x73, 0x48, 0xf1, 0x89, 0xfa,
  10017. 0xdd, 0x80, 0x72, 0x1f, 0xb8, 0x56, 0x0c, 0xa2,
  10018. 0x35, 0xd4, 0x08, 0xbf, 0x24, 0xcb, 0xec, 0xdb,
  10019. 0x81, 0xe0, 0xe6, 0x4f, 0x3d, 0x1c, 0x5c, 0x46
  10020. };
  10021. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  10022. 0xe9, 0x58, 0xfe, 0xab, 0x66, 0xb4, 0xf1, 0x79,
  10023. 0x91, 0x3f, 0x91, 0xdc, 0x6f, 0xdf, 0xd6, 0xac,
  10024. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4
  10025. };
  10026. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  10027. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  10028. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10029. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10030. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10031. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10032. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10033. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10034. };
  10035. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  10036. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10037. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10038. };
  10039. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  10040. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10041. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10042. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10043. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10044. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10045. };
  10046. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  10047. 0xa4, 0xf2, 0x71, 0x5d, 0x80, 0x60, 0x68, 0xa0,
  10048. 0x80, 0x61, 0xd7, 0xc1, 0x55, 0xc8, 0x3a, 0x2e,
  10049. 0xd7, 0xf4, 0x62, 0xaf, 0xbd, 0x2d, 0xf9, 0x5f,
  10050. 0xe8, 0xc5, 0x99, 0x3d, 0x58, 0x3c, 0xeb, 0xba,
  10051. 0x86, 0xea, 0x2c, 0x7e, 0x1f, 0xba, 0x81, 0xde
  10052. };
  10053. #endif /* HAVE_FIPS */
  10054. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10055. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10056. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10057. #endif
  10058. XMEMSET(buf, 0, sizeof(buf));
  10059. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10060. if (ret != 0)
  10061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10062. else
  10063. aes_inited = 1;
  10064. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10065. if (ret != 0)
  10066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10067. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10068. #if defined(WOLFSSL_ASYNC_CRYPT)
  10069. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10070. #endif
  10071. if (ret != 0)
  10072. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10073. if (XMEMCMP(c2, buf, sizeof(c2)))
  10074. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10075. #ifdef WOLFSSL_AESXTS_STREAM
  10076. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10077. #if defined(WOLFSSL_ASYNC_CRYPT)
  10078. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10079. #endif
  10080. if (ret != 0)
  10081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10082. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10083. #if defined(WOLFSSL_ASYNC_CRYPT)
  10084. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10085. #endif
  10086. if (ret != 0)
  10087. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10088. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10089. #if defined(WOLFSSL_ASYNC_CRYPT)
  10090. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10091. #endif
  10092. if (ret != 0)
  10093. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10094. if (XMEMCMP(c2, buf, sizeof(c2)))
  10095. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10096. #endif /* WOLFSSL_AESXTS_STREAM */
  10097. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10098. defined(WC_C_DYNAMIC_FALLBACK)
  10099. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10100. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10101. #if defined(WOLFSSL_ASYNC_CRYPT)
  10102. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10103. #endif
  10104. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10105. if (ret != 0)
  10106. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10107. if (XMEMCMP(c2, buf, sizeof(c2)))
  10108. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10109. #endif
  10110. XMEMSET(buf, 0, sizeof(buf));
  10111. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10112. if (ret != 0)
  10113. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10114. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10115. #if defined(WOLFSSL_ASYNC_CRYPT)
  10116. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10117. #endif
  10118. if (ret != 0)
  10119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10120. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10121. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10122. #ifdef WOLFSSL_AESXTS_STREAM
  10123. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10124. #if defined(WOLFSSL_ASYNC_CRYPT)
  10125. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10126. #endif
  10127. if (ret != 0)
  10128. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10129. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10130. #if defined(WOLFSSL_ASYNC_CRYPT)
  10131. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10132. #endif
  10133. if (ret != 0)
  10134. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10135. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10136. #if defined(WOLFSSL_ASYNC_CRYPT)
  10137. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10138. #endif
  10139. if (ret != 0)
  10140. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10141. if (XMEMCMP(c1, buf, sizeof(c1)))
  10142. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10143. #endif /* WOLFSSL_AESXTS_STREAM */
  10144. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10145. defined(WC_C_DYNAMIC_FALLBACK)
  10146. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10147. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10148. #if defined(WOLFSSL_ASYNC_CRYPT)
  10149. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10150. #endif
  10151. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10152. if (ret != 0)
  10153. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10154. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10155. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10156. #endif
  10157. /* partial block encryption test */
  10158. XMEMSET(cipher, 0, sizeof(cipher));
  10159. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10160. #if defined(WOLFSSL_ASYNC_CRYPT)
  10161. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10162. #endif
  10163. if (ret != 0)
  10164. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10165. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10166. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10167. #ifdef WOLFSSL_AESXTS_STREAM
  10168. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10169. #if defined(WOLFSSL_ASYNC_CRYPT)
  10170. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10171. #endif
  10172. if (ret != 0)
  10173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10174. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  10175. #if defined(WOLFSSL_ASYNC_CRYPT)
  10176. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10177. #endif
  10178. if (ret != 0)
  10179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10180. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10181. #if defined(WOLFSSL_ASYNC_CRYPT)
  10182. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10183. #endif
  10184. if (ret != 0)
  10185. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10186. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  10187. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10188. #endif /* WOLFSSL_AESXTS_STREAM */
  10189. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10190. defined(WC_C_DYNAMIC_FALLBACK)
  10191. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10192. XMEMSET(cipher, 0, sizeof(cipher));
  10193. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10194. #if defined(WOLFSSL_ASYNC_CRYPT)
  10195. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10196. #endif
  10197. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10198. if (ret != 0)
  10199. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10200. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10201. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10202. #endif
  10203. /* partial block decrypt test */
  10204. XMEMSET(buf, 0, sizeof(buf));
  10205. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10206. if (ret != 0)
  10207. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10208. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10209. #if defined(WOLFSSL_ASYNC_CRYPT)
  10210. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10211. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10212. #else
  10213. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10214. #endif
  10215. #endif
  10216. if (ret != 0)
  10217. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10218. if (XMEMCMP(pp, buf, sizeof(pp)))
  10219. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10220. #ifdef WOLFSSL_AESXTS_STREAM
  10221. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10222. #if defined(WOLFSSL_ASYNC_CRYPT)
  10223. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10224. #endif
  10225. if (ret != 0)
  10226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10227. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  10228. #if defined(WOLFSSL_ASYNC_CRYPT)
  10229. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10230. #endif
  10231. if (ret != 0)
  10232. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10233. if (XMEMCMP(pp, buf, sizeof(pp)))
  10234. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10235. #endif /* WOLFSSL_AESXTS_STREAM */
  10236. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10237. defined(WC_C_DYNAMIC_FALLBACK)
  10238. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10239. XMEMSET(buf, 0, sizeof(buf));
  10240. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10241. #if defined(WOLFSSL_ASYNC_CRYPT)
  10242. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10243. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10244. #else
  10245. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10246. #endif
  10247. #endif
  10248. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10249. if (ret != 0)
  10250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10251. if (XMEMCMP(pp, buf, sizeof(pp)))
  10252. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10253. #endif
  10254. /* NIST decrypt test vector */
  10255. XMEMSET(buf, 0, sizeof(buf));
  10256. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10257. #if defined(WOLFSSL_ASYNC_CRYPT)
  10258. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10259. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10260. #else
  10261. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10262. #endif
  10263. #endif
  10264. if (ret != 0)
  10265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10266. if (XMEMCMP(p1, buf, sizeof(p1)))
  10267. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10268. #ifdef WOLFSSL_AESXTS_STREAM
  10269. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10270. #if defined(WOLFSSL_ASYNC_CRYPT)
  10271. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10272. #endif
  10273. if (ret != 0)
  10274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10275. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10276. #if defined(WOLFSSL_ASYNC_CRYPT)
  10277. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10278. #endif
  10279. if (ret != 0)
  10280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10281. if (XMEMCMP(p1, buf, sizeof(p1)))
  10282. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10283. #endif /* WOLFSSL_AESXTS_STREAM */
  10284. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10285. defined(WC_C_DYNAMIC_FALLBACK)
  10286. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10287. XMEMSET(buf, 0, sizeof(buf));
  10288. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10289. #if defined(WOLFSSL_ASYNC_CRYPT)
  10290. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10291. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10292. #else
  10293. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10294. #endif
  10295. #endif
  10296. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10297. if (ret != 0)
  10298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10299. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  10300. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10301. #endif
  10302. /* fail case with decrypting using wrong key */
  10303. XMEMSET(buf, 0, sizeof(buf));
  10304. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10305. #if defined(WOLFSSL_ASYNC_CRYPT)
  10306. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10307. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10308. #else
  10309. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10310. #endif
  10311. #endif
  10312. if (ret != 0)
  10313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10314. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  10315. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10316. /* set correct key and retest */
  10317. XMEMSET(buf, 0, sizeof(buf));
  10318. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10319. if (ret != 0)
  10320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10321. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10322. #if defined(WOLFSSL_ASYNC_CRYPT)
  10323. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10324. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10325. #else
  10326. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10327. #endif
  10328. #endif
  10329. if (ret != 0)
  10330. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10331. if (XMEMCMP(p2, buf, sizeof(p2)))
  10332. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10333. #ifndef HAVE_FIPS
  10334. /* Test ciphertext stealing in-place. */
  10335. XMEMCPY(buf, p3, sizeof(p3));
  10336. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  10337. if (ret != 0)
  10338. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10339. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  10340. #if defined(WOLFSSL_ASYNC_CRYPT)
  10341. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10342. #endif
  10343. if (ret != 0)
  10344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10345. if (XMEMCMP(c3, buf, sizeof(c3)))
  10346. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10347. #ifdef WOLFSSL_AESXTS_STREAM
  10348. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  10349. #if defined(WOLFSSL_ASYNC_CRYPT)
  10350. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10351. #endif
  10352. if (ret != 0)
  10353. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10354. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  10355. #if defined(WOLFSSL_ASYNC_CRYPT)
  10356. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10357. #endif
  10358. if (ret != 0)
  10359. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10360. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  10361. #if defined(WOLFSSL_ASYNC_CRYPT)
  10362. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10363. #endif
  10364. if (ret != 0)
  10365. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10366. if (XMEMCMP(c3, buf, sizeof(c3)))
  10367. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10368. #endif /* WOLFSSL_AESXTS_STREAM */
  10369. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  10370. if (ret != 0)
  10371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10372. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  10373. #if defined(WOLFSSL_ASYNC_CRYPT)
  10374. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10375. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10376. #else
  10377. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10378. #endif
  10379. #endif
  10380. if (ret != 0)
  10381. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10382. if (XMEMCMP(p3, buf, sizeof(p3)))
  10383. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10384. #ifdef WOLFSSL_AESXTS_STREAM
  10385. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  10386. #if defined(WOLFSSL_ASYNC_CRYPT)
  10387. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10388. #endif
  10389. if (ret != 0)
  10390. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10391. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  10392. #if defined(WOLFSSL_ASYNC_CRYPT)
  10393. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10394. #endif
  10395. if (ret != 0)
  10396. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10397. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  10398. #if defined(WOLFSSL_ASYNC_CRYPT)
  10399. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10400. #endif
  10401. if (ret != 0)
  10402. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10403. if (XMEMCMP(p3, buf, sizeof(p3)))
  10404. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10405. #endif /* WOLFSSL_AESXTS_STREAM */
  10406. #endif /* !HAVE_FIPS */
  10407. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10408. !defined(WOLFSSL_AFALG)
  10409. {
  10410. int i;
  10411. int j;
  10412. #ifdef WOLFSSL_AESXTS_STREAM
  10413. int k;
  10414. #endif
  10415. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10416. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10417. DYNAMIC_TYPE_TMP_BUFFER);
  10418. if (large_input == NULL)
  10419. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10420. #endif
  10421. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10422. large_input[i] = (byte)i;
  10423. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10424. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10425. if (ret != 0)
  10426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10427. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10428. sizeof(i1));
  10429. #if defined(WOLFSSL_ASYNC_CRYPT)
  10430. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10431. #endif
  10432. if (ret != 0)
  10433. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10434. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10435. if (ret != 0)
  10436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10437. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10438. sizeof(i1));
  10439. #if defined(WOLFSSL_ASYNC_CRYPT)
  10440. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10441. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10442. WC_ASYNC_FLAG_NONE);
  10443. #else
  10444. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10445. #endif
  10446. #endif
  10447. if (ret != 0)
  10448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10449. for (i = 0; i < j; i++) {
  10450. if (large_input[i] != (byte)i) {
  10451. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10452. }
  10453. }
  10454. }
  10455. #ifdef WOLFSSL_AESXTS_STREAM
  10456. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10457. large_input[i] = (byte)i;
  10458. /* first, encrypt block by block then decrypt with a one-shot call. */
  10459. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10460. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10461. if (ret != 0)
  10462. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10463. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10464. #if defined(WOLFSSL_ASYNC_CRYPT)
  10465. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10466. #endif
  10467. if (ret != 0)
  10468. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10469. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10470. if ((j - k) < AES_BLOCK_SIZE*2)
  10471. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10472. else
  10473. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10474. #if defined(WOLFSSL_ASYNC_CRYPT)
  10475. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10476. #endif
  10477. if (ret != 0)
  10478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10479. if ((j - k) < AES_BLOCK_SIZE*2)
  10480. break;
  10481. }
  10482. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10483. if (ret != 0)
  10484. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10485. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10486. sizeof(i1));
  10487. #if defined(WOLFSSL_ASYNC_CRYPT)
  10488. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10489. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10490. WC_ASYNC_FLAG_NONE);
  10491. #else
  10492. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10493. #endif
  10494. #endif
  10495. if (ret != 0)
  10496. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10497. for (i = 0; i < j; i++) {
  10498. if (large_input[i] != (byte)i) {
  10499. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10500. }
  10501. }
  10502. }
  10503. /* second, encrypt with a one-shot call then decrypt block by block. */
  10504. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10505. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10506. if (ret != 0)
  10507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10508. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10509. sizeof(i1));
  10510. #if defined(WOLFSSL_ASYNC_CRYPT)
  10511. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10512. #endif
  10513. if (ret != 0)
  10514. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10515. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10516. if (ret != 0)
  10517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10518. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10519. #if defined(WOLFSSL_ASYNC_CRYPT)
  10520. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10521. #endif
  10522. if (ret != 0)
  10523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10524. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10525. if ((j - k) < AES_BLOCK_SIZE*2)
  10526. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10527. else
  10528. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10529. #if defined(WOLFSSL_ASYNC_CRYPT)
  10530. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10531. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10532. WC_ASYNC_FLAG_NONE);
  10533. #else
  10534. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10535. #endif
  10536. #endif
  10537. if (ret != 0)
  10538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10539. if ((j - k) < AES_BLOCK_SIZE*2)
  10540. break;
  10541. }
  10542. for (i = 0; i < j; i++) {
  10543. if (large_input[i] != (byte)i) {
  10544. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10545. }
  10546. }
  10547. }
  10548. #endif /* WOLFSSL_AESXTS_STREAM */
  10549. }
  10550. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10551. * !WOLFSSL_AFALG
  10552. */
  10553. out:
  10554. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10555. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10556. !defined(WOLFSSL_NO_MALLOC)
  10557. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10558. #endif
  10559. if (aes_inited)
  10560. wc_AesXtsFree(aes);
  10561. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10562. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10563. #endif
  10564. return ret;
  10565. }
  10566. #endif /* WOLFSSL_AES_192 */
  10567. #ifdef WOLFSSL_AES_256
  10568. static wc_test_ret_t aes_xts_256_test(void)
  10569. {
  10570. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10571. XtsAes *aes = NULL;
  10572. #else
  10573. XtsAes aes[1];
  10574. #endif
  10575. int aes_inited = 0;
  10576. wc_test_ret_t ret = 0;
  10577. unsigned char buf[AES_BLOCK_SIZE * 3];
  10578. unsigned char cipher[AES_BLOCK_SIZE * 3];
  10579. #ifdef WOLFSSL_AESXTS_STREAM
  10580. struct XtsAesStreamData stream;
  10581. #endif
  10582. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10583. !defined(WOLFSSL_AFALG)
  10584. #define LARGE_XTS_SZ 1024
  10585. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10586. byte* large_input = NULL;
  10587. #else
  10588. byte large_input[LARGE_XTS_SZ];
  10589. #endif
  10590. #endif
  10591. /* 256 key tests */
  10592. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10593. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  10594. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  10595. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  10596. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  10597. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  10598. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3,
  10599. 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58,
  10600. 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08
  10601. };
  10602. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  10603. 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2,
  10604. 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64
  10605. };
  10606. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10607. 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1,
  10608. 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64,
  10609. 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3,
  10610. 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e
  10611. };
  10612. /* plain text test of partial block is not from NIST test vector list */
  10613. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  10614. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  10615. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  10616. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  10617. };
  10618. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10619. 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5,
  10620. 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13,
  10621. 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a,
  10622. 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb
  10623. };
  10624. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10625. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10626. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10627. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10628. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10629. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10630. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a,
  10631. 0xb5, 0xb0, 0xc7, 0xe5, 0x2d, 0xb5, 0x06, 0x12,
  10632. 0xd2, 0xb5, 0x3a, 0xcb, 0x47, 0x8a, 0x53, 0xb4
  10633. };
  10634. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10635. 0xe6, 0x42, 0x19, 0xed, 0xe0, 0xe1, 0xc2, 0xa0,
  10636. 0x0e, 0xf5, 0x58, 0x6a, 0xc4, 0x9b, 0xeb, 0x6f
  10637. };
  10638. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10639. 0x24, 0xcb, 0x76, 0x22, 0x55, 0xb5, 0xa8, 0x00,
  10640. 0xf4, 0x6e, 0x80, 0x60, 0x56, 0x9e, 0x05, 0x53,
  10641. 0xbc, 0xfe, 0x86, 0x55, 0x3b, 0xca, 0xd5, 0x89,
  10642. 0xc7, 0x54, 0x1a, 0x73, 0xac, 0xc3, 0x9a, 0xbd,
  10643. 0x53, 0xc4, 0x07, 0x76, 0xd8, 0xe8, 0x22, 0x61,
  10644. 0x9e, 0xa9, 0xad, 0x77, 0xa0, 0x13, 0x4c, 0xfc
  10645. };
  10646. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10647. 0xa3, 0xc6, 0xf3, 0xf3, 0x82, 0x79, 0x5b, 0x10,
  10648. 0x87, 0xd7, 0x02, 0x50, 0xdb, 0x2c, 0xd3, 0xb1,
  10649. 0xa1, 0x62, 0xa8, 0xb6, 0xdc, 0x12, 0x60, 0x61,
  10650. 0xc1, 0x0a, 0x84, 0xa5, 0x85, 0x3f, 0x3a, 0x89,
  10651. 0xe6, 0x6c, 0xdb, 0xb7, 0x9a, 0xb4, 0x28, 0x9b,
  10652. 0xc3, 0xea, 0xd8, 0x10, 0xe9, 0xc0, 0xaf, 0x92
  10653. };
  10654. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10655. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10656. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10657. #endif
  10658. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  10659. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  10660. ret = EVP_test(wolfSSL_EVP_aes_256_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  10661. if (ret != 0) {
  10662. printf("EVP_aes_256_xts failed\n");
  10663. goto out;
  10664. }
  10665. #endif
  10666. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10667. if (ret != 0)
  10668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10669. else
  10670. aes_inited = 1;
  10671. XMEMSET(buf, 0, sizeof(buf));
  10672. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10673. if (ret != 0)
  10674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10675. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10676. #if defined(WOLFSSL_ASYNC_CRYPT)
  10677. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10678. #endif
  10679. if (ret != 0)
  10680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10681. if (XMEMCMP(c2, buf, sizeof(c2)))
  10682. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10683. #ifdef WOLFSSL_AESXTS_STREAM
  10684. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10685. #if defined(WOLFSSL_ASYNC_CRYPT)
  10686. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10687. #endif
  10688. if (ret != 0)
  10689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10690. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10691. #if defined(WOLFSSL_ASYNC_CRYPT)
  10692. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10693. #endif
  10694. if (ret != 0)
  10695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10696. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10697. #if defined(WOLFSSL_ASYNC_CRYPT)
  10698. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10699. #endif
  10700. if (ret != 0)
  10701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10702. if (XMEMCMP(c2, buf, sizeof(c2)))
  10703. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10704. #endif /* WOLFSSL_AESXTS_STREAM */
  10705. XMEMSET(buf, 0, sizeof(buf));
  10706. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10707. if (ret != 0)
  10708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10709. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10710. #if defined(WOLFSSL_ASYNC_CRYPT)
  10711. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10712. #endif
  10713. if (ret != 0)
  10714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10715. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10716. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10717. #ifdef WOLFSSL_AESXTS_STREAM
  10718. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10719. #if defined(WOLFSSL_ASYNC_CRYPT)
  10720. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10721. #endif
  10722. if (ret != 0)
  10723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10724. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10725. #if defined(WOLFSSL_ASYNC_CRYPT)
  10726. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10727. #endif
  10728. if (ret != 0)
  10729. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10730. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10731. #if defined(WOLFSSL_ASYNC_CRYPT)
  10732. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10733. #endif
  10734. if (ret != 0)
  10735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10736. if (XMEMCMP(c1, buf, sizeof(c1)))
  10737. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10738. #endif /* WOLFSSL_AESXTS_STREAM */
  10739. /* partial block encryption test */
  10740. XMEMSET(cipher, 0, sizeof(cipher));
  10741. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10742. #if defined(WOLFSSL_ASYNC_CRYPT)
  10743. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10744. #endif
  10745. if (ret != 0)
  10746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10747. /* partial block decrypt test */
  10748. XMEMSET(buf, 0, sizeof(buf));
  10749. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10750. if (ret != 0)
  10751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10752. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10753. #if defined(WOLFSSL_ASYNC_CRYPT)
  10754. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10755. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10756. #else
  10757. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10758. #endif
  10759. #endif
  10760. if (ret != 0)
  10761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10762. if (XMEMCMP(pp, buf, sizeof(pp)))
  10763. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10764. /* NIST decrypt test vector */
  10765. XMEMSET(buf, 0, sizeof(buf));
  10766. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10767. #if defined(WOLFSSL_ASYNC_CRYPT)
  10768. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10769. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10770. #else
  10771. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10772. #endif
  10773. #endif
  10774. if (ret != 0)
  10775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10776. if (XMEMCMP(p1, buf, sizeof(p1)))
  10777. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10778. #ifdef WOLFSSL_AESXTS_STREAM
  10779. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10780. #if defined(WOLFSSL_ASYNC_CRYPT)
  10781. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10782. #endif
  10783. if (ret != 0)
  10784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10785. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10786. #if defined(WOLFSSL_ASYNC_CRYPT)
  10787. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10788. #endif
  10789. if (ret != 0)
  10790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10791. if (XMEMCMP(p1, buf, sizeof(p1)))
  10792. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10793. #endif /* WOLFSSL_AESXTS_STREAM */
  10794. XMEMSET(buf, 0, sizeof(buf));
  10795. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10796. if (ret != 0)
  10797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10798. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10799. #if defined(WOLFSSL_ASYNC_CRYPT)
  10800. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10801. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10802. #else
  10803. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10804. #endif
  10805. #endif
  10806. if (ret != 0)
  10807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10808. if (XMEMCMP(p2, buf, sizeof(p2)))
  10809. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10810. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10811. !defined(WOLFSSL_AFALG)
  10812. {
  10813. int i;
  10814. int j;
  10815. #ifdef WOLFSSL_AESXTS_STREAM
  10816. int k;
  10817. #endif
  10818. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10819. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10820. DYNAMIC_TYPE_TMP_BUFFER);
  10821. if (large_input == NULL)
  10822. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10823. #endif
  10824. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10825. large_input[i] = (byte)i;
  10826. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10827. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10828. if (ret != 0)
  10829. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10830. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10831. sizeof(i1));
  10832. #if defined(WOLFSSL_ASYNC_CRYPT)
  10833. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10834. #endif
  10835. if (ret != 0)
  10836. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10837. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10838. if (ret != 0)
  10839. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10840. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10841. sizeof(i1));
  10842. #if defined(WOLFSSL_ASYNC_CRYPT)
  10843. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10844. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10845. WC_ASYNC_FLAG_NONE);
  10846. #else
  10847. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10848. #endif
  10849. #endif
  10850. if (ret != 0)
  10851. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10852. for (i = 0; i < j; i++) {
  10853. if (large_input[i] != (byte)i) {
  10854. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10855. }
  10856. }
  10857. }
  10858. #ifdef WOLFSSL_AESXTS_STREAM
  10859. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10860. large_input[i] = (byte)i;
  10861. /* first, encrypt block by block then decrypt with a one-shot call. */
  10862. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10863. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10864. if (ret != 0)
  10865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10866. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10867. #if defined(WOLFSSL_ASYNC_CRYPT)
  10868. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10869. #endif
  10870. if (ret != 0)
  10871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10872. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10873. if ((j - k) < AES_BLOCK_SIZE*2)
  10874. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10875. else
  10876. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10877. #if defined(WOLFSSL_ASYNC_CRYPT)
  10878. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10879. #endif
  10880. if (ret != 0)
  10881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10882. if ((j - k) < AES_BLOCK_SIZE*2)
  10883. break;
  10884. }
  10885. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10886. if (ret != 0)
  10887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10888. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10889. sizeof(i1));
  10890. #if defined(WOLFSSL_ASYNC_CRYPT)
  10891. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10892. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10893. WC_ASYNC_FLAG_NONE);
  10894. #else
  10895. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10896. #endif
  10897. #endif
  10898. if (ret != 0)
  10899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10900. for (i = 0; i < j; i++) {
  10901. if (large_input[i] != (byte)i) {
  10902. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10903. }
  10904. }
  10905. }
  10906. /* second, encrypt with a one-shot call then decrypt block by block. */
  10907. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10908. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10909. if (ret != 0)
  10910. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10911. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10912. sizeof(i1));
  10913. #if defined(WOLFSSL_ASYNC_CRYPT)
  10914. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10915. #endif
  10916. if (ret != 0)
  10917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10918. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10919. if (ret != 0)
  10920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10921. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10922. #if defined(WOLFSSL_ASYNC_CRYPT)
  10923. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10924. #endif
  10925. if (ret != 0)
  10926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10927. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10928. if ((j - k) < AES_BLOCK_SIZE*2)
  10929. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10930. else
  10931. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10932. #if defined(WOLFSSL_ASYNC_CRYPT)
  10933. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10934. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10935. WC_ASYNC_FLAG_NONE);
  10936. #else
  10937. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10938. #endif
  10939. #endif
  10940. if (ret != 0)
  10941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10942. if ((j - k) < AES_BLOCK_SIZE*2)
  10943. break;
  10944. }
  10945. for (i = 0; i < j; i++) {
  10946. if (large_input[i] != (byte)i) {
  10947. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10948. }
  10949. }
  10950. }
  10951. #endif /* WOLFSSL_AESXTS_STREAM */
  10952. }
  10953. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10954. * !WOLFSSL_AFALG
  10955. */
  10956. out:
  10957. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10958. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10959. !defined(WOLFSSL_NO_MALLOC)
  10960. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10961. #endif
  10962. if (aes_inited)
  10963. wc_AesXtsFree(aes);
  10964. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10965. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10966. #endif
  10967. return ret;
  10968. }
  10969. #endif /* WOLFSSL_AES_256 */
  10970. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  10971. /* both 128 and 256 bit key test */
  10972. static wc_test_ret_t aes_xts_sector_test(void)
  10973. {
  10974. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10975. XtsAes *aes = NULL;
  10976. #else
  10977. XtsAes aes[1];
  10978. #endif
  10979. int aes_inited = 0;
  10980. wc_test_ret_t ret = 0;
  10981. unsigned char buf[AES_BLOCK_SIZE * 2];
  10982. /* 128 key tests */
  10983. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10984. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  10985. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  10986. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  10987. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  10988. };
  10989. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10990. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  10991. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  10992. };
  10993. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10994. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  10995. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  10996. };
  10997. word64 s1 = 141;
  10998. /* 256 key tests */
  10999. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  11000. 0xef, 0x01, 0x0c, 0xa1, 0xa3, 0x66, 0x3e, 0x32,
  11001. 0x53, 0x43, 0x49, 0xbc, 0x0b, 0xae, 0x62, 0x23,
  11002. 0x2a, 0x15, 0x73, 0x34, 0x85, 0x68, 0xfb, 0x9e,
  11003. 0xf4, 0x17, 0x68, 0xa7, 0x67, 0x4f, 0x50, 0x7a,
  11004. 0x72, 0x7f, 0x98, 0x75, 0x53, 0x97, 0xd0, 0xe0,
  11005. 0xaa, 0x32, 0xf8, 0x30, 0x33, 0x8c, 0xc7, 0xa9,
  11006. 0x26, 0xc7, 0x73, 0xf0, 0x9e, 0x57, 0xb3, 0x57,
  11007. 0xcd, 0x15, 0x6a, 0xfb, 0xca, 0x46, 0xe1, 0xa0
  11008. };
  11009. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  11010. 0xed, 0x98, 0xe0, 0x17, 0x70, 0xa8, 0x53, 0xb4,
  11011. 0x9d, 0xb9, 0xe6, 0xaa, 0xf8, 0x8f, 0x0a, 0x41,
  11012. 0xb9, 0xb5, 0x6e, 0x91, 0xa5, 0xa2, 0xb1, 0x1d,
  11013. 0x40, 0x52, 0x92, 0x54, 0xf5, 0x52, 0x3e, 0x75
  11014. };
  11015. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  11016. 0xca, 0x20, 0xc5, 0x5e, 0x8d, 0xc1, 0x49, 0x68,
  11017. 0x7d, 0x25, 0x41, 0xde, 0x39, 0xc3, 0xdf, 0x63,
  11018. 0x00, 0xbb, 0x5a, 0x16, 0x3c, 0x10, 0xce, 0xd3,
  11019. 0x66, 0x6b, 0x13, 0x57, 0xdb, 0x8b, 0xd3, 0x9d
  11020. };
  11021. word64 s2 = 187;
  11022. #if !defined(BENCH_EMBEDDED) && \
  11023. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11024. /* Sector size for encrypt/decrypt consecutive sectors testcase */
  11025. word32 sectorSz = 512;
  11026. unsigned char data[550];
  11027. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  11028. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11029. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11030. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  11031. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  11032. };
  11033. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  11034. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11035. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11036. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11037. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11038. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11039. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11040. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11041. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11042. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11043. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11044. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11045. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11046. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11047. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11048. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11049. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11050. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11051. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11052. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11053. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11054. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11055. 0xfc, 0xfd, 0xfe, 0xff,
  11056. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11057. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11058. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11059. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11060. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11061. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11062. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11063. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11064. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11065. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11066. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11067. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11068. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11069. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11070. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11071. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11072. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11073. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11074. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11075. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11076. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11077. 0xfc, 0xfd, 0xfe, 0xff,
  11078. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11079. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11080. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  11081. };
  11082. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  11083. 0xb9, 0x6b, 0x2b, 0xfd, 0x61, 0x87, 0x84, 0xd5, 0x26, 0xd2, 0x8c, 0x62,
  11084. 0x63, 0x01, 0xca, 0x46, 0xb1, 0x82, 0xfa, 0xdc, 0xbc, 0x32, 0x18, 0xe9,
  11085. 0xda, 0xe6, 0xda, 0xd1, 0x1a, 0x52, 0x77, 0xca, 0xdb, 0x0e, 0xbe, 0x37,
  11086. 0x88, 0x36, 0x1c, 0x87, 0x16, 0x60, 0xfe, 0xa8, 0x9e, 0xf6, 0x48, 0x64,
  11087. 0x94, 0x34, 0x64, 0xed, 0xf6, 0x9a, 0xc5, 0x28, 0xc9, 0xed, 0x64, 0x80,
  11088. 0x85, 0xd8, 0x93, 0xa7, 0x50, 0xb1, 0x9d, 0x2f, 0x1e, 0x34, 0xcc, 0xb4,
  11089. 0x03, 0xfb, 0x6b, 0x43, 0x21, 0xa8, 0x5b, 0xc6, 0x59, 0x13, 0xd2, 0xb5,
  11090. 0xf5, 0x7b, 0xf6, 0xb2, 0xa4, 0x7a, 0xd2, 0x50, 0x26, 0xcb, 0xa4, 0x83,
  11091. 0xc3, 0x56, 0xb0, 0xb1, 0x14, 0x34, 0x12, 0x1b, 0xea, 0x26, 0x97, 0x24,
  11092. 0x54, 0xcc, 0x32, 0x4c, 0xa4, 0xc2, 0xa3, 0x07, 0xfa, 0x30, 0xa9, 0xf0,
  11093. 0x91, 0x17, 0x60, 0x68, 0x88, 0x7f, 0x34, 0x7e, 0xbd, 0x20, 0x33, 0x95,
  11094. 0x6e, 0xc0, 0xb6, 0x2b, 0xff, 0x7e, 0x61, 0x35, 0x9a, 0x88, 0xff, 0xd9,
  11095. 0x69, 0x21, 0xe7, 0x8f, 0x45, 0x02, 0xf9, 0xd7, 0xeb, 0xa6, 0x53, 0xf1,
  11096. 0x73, 0x04, 0xf1, 0x0b, 0x85, 0xc6, 0x1f, 0x4a, 0x51, 0x2f, 0x95, 0x87,
  11097. 0x5a, 0x67, 0x37, 0xb2, 0x87, 0xf7, 0xbe, 0x2a, 0x17, 0x57, 0xca, 0xfc,
  11098. 0xdd, 0x5f, 0x37, 0x48, 0x78, 0xbd, 0xfa, 0x75, 0xc9, 0xfa, 0x86, 0x7e,
  11099. 0xc4, 0x0f, 0x60, 0x85, 0xce, 0x12, 0x44, 0x7c, 0xd9, 0xb2, 0x50, 0xd9,
  11100. 0x57, 0x85, 0xa5, 0xd7, 0x68, 0x59, 0x03, 0x09, 0x97, 0x2e, 0x8e, 0xa5,
  11101. 0xe3, 0x98, 0xac, 0x16, 0xfb, 0x6d, 0x54, 0xc5, 0x5d, 0x7a, 0x33, 0x44,
  11102. 0x0a, 0x39, 0x91, 0xcc, 0x9f, 0x67, 0xf9, 0x89, 0xbb, 0x62, 0x02, 0xc4,
  11103. 0x22, 0xec, 0xcf, 0x97, 0x69, 0x81, 0x3d, 0x00, 0xfd, 0xeb, 0x55, 0x08,
  11104. 0xa2, 0xff, 0x97, 0xaa, 0x79, 0xde, 0x3c, 0x8a, 0x78, 0x71, 0x73, 0xa2,
  11105. 0x98, 0x2f, 0xd8, 0x5c, 0x62, 0x1c, 0x5c, 0x23, 0x0a, 0xd1, 0xf1, 0x81,
  11106. 0x8a, 0x12, 0xe7, 0x4d, 0xdd, 0x4f, 0xd4, 0xf1, 0xe8, 0x0f, 0x25, 0x79,
  11107. 0x45, 0x4a, 0x49, 0x49, 0x7e, 0x56, 0x91, 0x4e, 0xaa, 0xba, 0x18, 0xe1,
  11108. 0xe4, 0xbe, 0x21, 0xdc, 0x58, 0x60, 0x6f, 0x6a, 0x7f, 0xdc, 0x5e, 0x74,
  11109. 0x47, 0xbf, 0xeb, 0x84, 0xc4, 0x1e, 0x5a, 0x61, 0x64, 0xc8, 0x63, 0x68,
  11110. 0xfa, 0x17, 0x9c, 0xac, 0x60, 0x1c, 0xa5, 0x6e, 0x00, 0x21, 0x93, 0x3c,
  11111. 0xd7, 0xbb, 0x73, 0x45, 0xf7, 0x34, 0x81, 0x6c, 0xfa, 0xf2, 0x33, 0xfd,
  11112. 0xb1, 0x40, 0x30, 0x6b, 0x30, 0xd1, 0x83, 0x5e, 0x2e, 0x7a, 0xce, 0xa6,
  11113. 0x12, 0x2a, 0x15, 0x03, 0x78, 0x29, 0xb9, 0x07, 0xae, 0xe7, 0xc2, 0x78,
  11114. 0x74, 0x72, 0xa5, 0x0e, 0x6b, 0x1f, 0x78, 0xf2, 0x5a, 0x69, 0xb6, 0x2b,
  11115. 0x99, 0x94, 0x1f, 0x89, 0xd1, 0x21, 0x14, 0x4a, 0x54, 0xab, 0x5a, 0x9f,
  11116. 0xaa, 0xa7, 0x96, 0x0a, 0x21, 0xce, 0x30, 0xb6, 0x70, 0x81, 0xe9, 0xd3,
  11117. 0x71, 0xc0, 0xf1, 0x15, 0xe2, 0xf6, 0xd3, 0xcc, 0x41, 0x15, 0x9d, 0xd5,
  11118. 0xa3, 0xa4, 0xe0, 0xf8, 0x62, 0xc4, 0x76, 0x65, 0x63, 0x89, 0xa7, 0xe2,
  11119. 0xfb, 0xf5, 0xc9, 0x80, 0x15, 0x5b, 0xc1, 0x59, 0xb2, 0xd0, 0x01, 0x3a,
  11120. 0xf9, 0xab, 0x5b, 0x79, 0x54, 0xed, 0x6b, 0xf9, 0x1d, 0x9d, 0x87, 0x63,
  11121. 0x80, 0x4f, 0xec, 0x9c, 0x4f, 0xad, 0x97, 0x04, 0xff, 0x62, 0x4a, 0x17,
  11122. 0xc0, 0x09, 0x2a, 0x2c, 0x23, 0x4b, 0xc3, 0xb6, 0x6d, 0xed, 0xdb, 0x1a,
  11123. 0x6f, 0x56, 0x2b, 0x78, 0x92, 0x3a, 0x5c, 0x7f, 0xb2, 0x63, 0xd3, 0xd5,
  11124. 0x1a, 0xbe, 0xc2, 0x34, 0xc8, 0xad, 0x36, 0xb7, 0x12, 0xb8, 0xe1, 0xb7,
  11125. 0x52, 0x7f, 0x16, 0x84, 0x2c, 0x47, 0x7e, 0xf2, 0xa5, 0x36, 0x2e, 0xad,
  11126. 0xe7, 0xbb, 0xc0, 0x6f, 0x27, 0x8e, 0x41, 0x08, 0x75, 0xe5, 0xff, 0xde,
  11127. 0x08, 0x9f, 0x8c, 0x91, 0xba, 0xc9, 0x9d, 0x9f, 0x27, 0x90, 0x50, 0x44,
  11128. 0x24, 0xe7, 0x3d, 0x6f
  11129. };
  11130. word64 s3 = 0x000000ffffffffff;
  11131. #endif
  11132. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11133. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11134. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11135. #endif
  11136. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11137. if (ret != 0)
  11138. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11139. else
  11140. aes_inited = 1;
  11141. XMEMSET(buf, 0, sizeof(buf));
  11142. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11143. if (ret != 0)
  11144. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11145. ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1);
  11146. #if defined(WOLFSSL_ASYNC_CRYPT)
  11147. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11148. #endif
  11149. if (ret != 0)
  11150. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11151. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  11152. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11153. /* decrypt test */
  11154. XMEMSET(buf, 0, sizeof(buf));
  11155. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11156. if (ret != 0)
  11157. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11158. ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1);
  11159. #if defined(WOLFSSL_ASYNC_CRYPT)
  11160. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11161. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11162. #else
  11163. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11164. #endif
  11165. #endif
  11166. if (ret != 0)
  11167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11168. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  11169. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11170. /* 256 bit key tests */
  11171. XMEMSET(buf, 0, sizeof(buf));
  11172. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  11173. if (ret != 0)
  11174. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11175. ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2);
  11176. #if defined(WOLFSSL_ASYNC_CRYPT)
  11177. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11178. #endif
  11179. if (ret != 0)
  11180. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11181. if (XMEMCMP(c2, buf, sizeof(c2)))
  11182. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11183. /* decrypt test */
  11184. XMEMSET(buf, 0, sizeof(buf));
  11185. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  11186. if (ret != 0)
  11187. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11188. ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2);
  11189. #if defined(WOLFSSL_ASYNC_CRYPT)
  11190. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11191. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11192. #else
  11193. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11194. #endif
  11195. #endif
  11196. if (ret != 0)
  11197. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11198. if (XMEMCMP(p2, buf, sizeof(p2)))
  11199. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11200. #if !defined(BENCH_EMBEDDED) && \
  11201. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11202. /* encrypt consecutive sectors test */
  11203. XMEMSET(data, 0, sizeof(buf));
  11204. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  11205. if (ret != 0)
  11206. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11207. ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3,
  11208. sizeof(p3), s3, sectorSz);
  11209. #if defined(WOLFSSL_ASYNC_CRYPT)
  11210. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11211. #endif
  11212. if (ret != 0)
  11213. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11214. if (XMEMCMP(c3, data, sizeof(c3)))
  11215. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11216. /* decrypt consecutive sectors test */
  11217. XMEMSET(data, 0, sizeof(buf));
  11218. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  11219. if (ret != 0)
  11220. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11221. ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3,
  11222. sizeof(c3), s3, sectorSz);
  11223. #if defined(WOLFSSL_ASYNC_CRYPT)
  11224. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11225. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11226. #else
  11227. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11228. #endif
  11229. #endif
  11230. if (ret != 0)
  11231. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11232. if (XMEMCMP(p3, data, sizeof(p3)))
  11233. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11234. #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
  11235. out:
  11236. if (aes_inited)
  11237. wc_AesXtsFree(aes);
  11238. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11239. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11240. #endif
  11241. return ret;
  11242. }
  11243. #endif /* WOLFSSL_AES_128 && WOLFSSL_AES_256 */
  11244. #ifdef WOLFSSL_AES_128
  11245. /* testing of bad arguments */
  11246. static wc_test_ret_t aes_xts_args_test(void)
  11247. {
  11248. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11249. XtsAes *aes = NULL;
  11250. #else
  11251. XtsAes aes[1];
  11252. #endif
  11253. int aes_inited = 0;
  11254. wc_test_ret_t ret;
  11255. unsigned char buf[AES_BLOCK_SIZE * 2];
  11256. /* 128 key tests */
  11257. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  11258. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  11259. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  11260. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  11261. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  11262. };
  11263. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  11264. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  11265. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  11266. };
  11267. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  11268. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11269. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11270. };
  11271. word64 s1 = 141;
  11272. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11273. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11274. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11275. #endif
  11276. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11277. if (ret != 0)
  11278. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11279. else
  11280. aes_inited = 1;
  11281. if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0)
  11282. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11283. if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0)
  11284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11285. /* encryption operations */
  11286. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11287. if (ret != 0)
  11288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11289. ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
  11290. #if defined(WOLFSSL_ASYNC_CRYPT)
  11291. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11292. #endif
  11293. if (ret == 0)
  11294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11295. ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1);
  11296. #if defined(WOLFSSL_ASYNC_CRYPT)
  11297. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11298. #endif
  11299. if (ret == 0)
  11300. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11301. /* decryption operations */
  11302. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11303. if (ret != 0)
  11304. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11305. ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
  11306. #if defined(WOLFSSL_ASYNC_CRYPT)
  11307. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11308. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11309. #else
  11310. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11311. #endif
  11312. #endif
  11313. if (ret == 0)
  11314. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11315. ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1);
  11316. #if defined(WOLFSSL_ASYNC_CRYPT)
  11317. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11318. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11319. #else
  11320. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11321. #endif
  11322. #endif
  11323. if (ret == 0)
  11324. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11325. ret = 0;
  11326. out:
  11327. if (aes_inited)
  11328. wc_AesXtsFree(aes);
  11329. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11330. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11331. #endif
  11332. return ret;
  11333. }
  11334. #endif /* WOLFSSL_AES_128 */
  11335. #endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  11336. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  11337. !defined(HAVE_RENESAS_SYNC)
  11338. static wc_test_ret_t aes_cbc_oneshot_test(void)
  11339. {
  11340. byte cipher[AES_BLOCK_SIZE];
  11341. byte plain[AES_BLOCK_SIZE];
  11342. wc_test_ret_t ret;
  11343. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  11344. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  11345. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  11346. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  11347. };
  11348. byte key[] = "0123456789abcdef "; /* align */
  11349. byte iv[] = "1234567890abcdef "; /* align */
  11350. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11351. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11352. /* Parameter Validation testing. */
  11353. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL);
  11354. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11355. return WC_TEST_RET_ENC_EC(ret);
  11356. #ifdef HAVE_AES_DECRYPT
  11357. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL);
  11358. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11359. return WC_TEST_RET_ENC_EC(ret);
  11360. #endif
  11361. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key,
  11362. AES_BLOCK_SIZE, iv);
  11363. if (ret != 0)
  11364. return WC_TEST_RET_ENC_EC(ret);
  11365. #ifdef HAVE_AES_DECRYPT
  11366. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key,
  11367. AES_BLOCK_SIZE, iv);
  11368. if (ret != 0)
  11369. return WC_TEST_RET_ENC_EC(ret);
  11370. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
  11371. return WC_TEST_RET_ENC_NC;
  11372. #endif /* HAVE_AES_DECRYPT */
  11373. (void)plain;
  11374. return 0;
  11375. }
  11376. #endif
  11377. #if defined(WOLFSSL_AES_COUNTER) && defined(HAVE_AES_DECRYPT)
  11378. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void)
  11379. {
  11380. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11381. Aes *enc = NULL;
  11382. Aes *dec = NULL;
  11383. #else
  11384. Aes enc[1];
  11385. Aes dec[1];
  11386. #endif
  11387. byte cipher[AES_BLOCK_SIZE * 4];
  11388. byte plain [AES_BLOCK_SIZE * 4];
  11389. wc_test_ret_t ret = 0;
  11390. /* test vectors from "Recommendation for Block Cipher Modes of
  11391. * Operation" NIST Special Publication 800-38A */
  11392. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  11393. {
  11394. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  11395. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  11396. };
  11397. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  11398. {
  11399. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11400. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  11401. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  11402. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  11403. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  11404. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  11405. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  11406. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  11407. };
  11408. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11409. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32[] =
  11410. {
  11411. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
  11412. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11413. };
  11414. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32_2[] =
  11415. {
  11416. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11417. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xfe
  11418. };
  11419. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64[] =
  11420. {
  11421. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11422. 0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11423. };
  11424. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64_2[] =
  11425. {
  11426. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
  11427. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11428. };
  11429. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96[] =
  11430. {
  11431. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11432. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff
  11433. };
  11434. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96_2[] =
  11435. {
  11436. 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,
  11437. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11438. };
  11439. #endif
  11440. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
  11441. {
  11442. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11443. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11444. };
  11445. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11446. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128_2[] =
  11447. {
  11448. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11449. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11450. };
  11451. #endif
  11452. #ifdef WOLFSSL_AES_128
  11453. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  11454. {
  11455. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  11456. 0xc2
  11457. };
  11458. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
  11459. {
  11460. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  11461. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  11462. };
  11463. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
  11464. {
  11465. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  11466. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  11467. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  11468. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  11469. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  11470. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  11471. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  11472. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  11473. };
  11474. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11475. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32Cipher[] =
  11476. {
  11477. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11478. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11479. 0x7e,0xad,0xea,0x5c,0xd1
  11480. };
  11481. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32CipherLong[] =
  11482. {
  11483. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11484. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11485. 0x7e,0xad,0xea,0x5c,0xd1,0xb7,0x98,0xf0,
  11486. 0x22,0x20,0xfe,0x67,0xb0,0x02,0x23,0x50
  11487. };
  11488. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32_2CipherLong[] =
  11489. {
  11490. 0x6e,0xa1,0x27,0x4d,0xea,0x20,0x5f,0x39,
  11491. 0x68,0xc8,0xb6,0x78,0xde,0xfc,0x53,0x5c,
  11492. 0x90,0xc8,0xf6,0xc6,0xfa,0xe0,0x7b,0x09,
  11493. 0x7c,0xf8,0x9c,0x6a,0x5a,0xa5,0x17,0x7f,
  11494. 0x03,0x92,0x5f,0x4e,0x85,0xea,0x26,0xc9,
  11495. 0x5a,0xc2,0x74,0xe2,0xbf,0xe4,0x1b,0xd4
  11496. };
  11497. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64Cipher[] =
  11498. {
  11499. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11500. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11501. 0xae,0x74,0x94,0x72,0x8e
  11502. };
  11503. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64CipherLong[] =
  11504. {
  11505. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11506. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11507. 0xae,0x74,0x94,0x72,0x8e,0xd0,0x71,0xc0,
  11508. 0x89,0x8a,0xa1,0xb0,0x29,0xa0,0x10,0x9e
  11509. };
  11510. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64_2CipherLong[] =
  11511. {
  11512. 0x3f,0xe7,0xd5,0xf3,0xfa,0x09,0xfe,0x40,
  11513. 0xa6,0xa1,0x32,0x8b,0x57,0x12,0xb9,0xfa,
  11514. 0xf2,0x2d,0xe4,0x3c,0x66,0x1d,0x0a,0x8e,
  11515. 0x46,0xf8,0x2e,0x33,0xce,0x8d,0x4e,0x3b,
  11516. 0x17,0x67,0x9e,0x9f,0x76,0x9e,0xc2,0x99,
  11517. 0xd5,0xd4,0x71,0xed,0xb4,0x33,0xb2,0xcd
  11518. };
  11519. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96Cipher[] =
  11520. {
  11521. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11522. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11523. 0x9d,0x77,0xc9,0x5f,0x38
  11524. };
  11525. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96CipherLong[] =
  11526. {
  11527. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11528. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11529. 0x9d,0x77,0xc9,0x5f,0x38,0xb5,0x6e,0x44,
  11530. 0x21,0x8e,0xda,0x57,0xe0,0x41,0xc7,0x6a
  11531. };
  11532. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96_2CipherLong[] =
  11533. {
  11534. 0xc8,0x81,0x1a,0xbe,0xc7,0x5b,0x93,0x6f,
  11535. 0xe6,0x52,0xe4,0xb1,0x2d,0x1c,0x39,0xbc,
  11536. 0xeb,0x82,0x27,0x0a,0x7e,0xa5,0x0e,0x2d,
  11537. 0x32,0xda,0xbe,0x10,0x7a,0x10,0xcc,0xd3,
  11538. 0x6f,0xc6,0x83,0x28,0x05,0x57,0x8a,0x24,
  11539. 0x44,0x76,0x17,0x81,0xb9,0x5c,0x94,0x81
  11540. };
  11541. #endif
  11542. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
  11543. {
  11544. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11545. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11546. 0xd3,0xda,0xe1,0x5b,0x04
  11547. };
  11548. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
  11549. {
  11550. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11551. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11552. 0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
  11553. 0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
  11554. };
  11555. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11556. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128_2CipherLong[] =
  11557. {
  11558. 0xba,0x76,0xaa,0x54,0xd5,0xb5,0x60,0x67,
  11559. 0xc1,0xa7,0x90,0x3b,0x3f,0xdd,0xfa,0x89,
  11560. 0x24,0xdf,0x0c,0x56,0x5c,0xf4,0x2a,0x68,
  11561. 0x97,0x87,0x13,0xb6,0x7a,0xd1,0x24,0xfd,
  11562. 0x4d,0x3f,0x77,0x4a,0xb9,0xe4,0x7d,0xa2,
  11563. 0xdb,0xb9,0x31,0x5e,0xa3,0x11,0x06,0x80
  11564. };
  11565. #endif
  11566. #endif /* WOLFSSL_AES_128 */
  11567. #ifdef WOLFSSL_AES_192
  11568. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  11569. {
  11570. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  11571. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  11572. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  11573. };
  11574. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  11575. {
  11576. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  11577. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b,
  11578. 0x09,0x03,0x39,0xec,0x0a,0xa6,0xfa,0xef,
  11579. 0xd5,0xcc,0xc2,0xc6,0xf4,0xce,0x8e,0x94,
  11580. 0x1e,0x36,0xb2,0x6b,0xd1,0xeb,0xc6,0x70,
  11581. 0xd1,0xbd,0x1d,0x66,0x56,0x20,0xab,0xf7,
  11582. 0x4f,0x78,0xa7,0xf6,0xd2,0x98,0x09,0x58,
  11583. 0x5a,0x97,0xda,0xec,0x58,0xc6,0xb0,0x50
  11584. };
  11585. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11586. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32Cipher[] =
  11587. {
  11588. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11589. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11590. 0x0c,0x33,0x97,0x06,0xc0
  11591. };
  11592. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32CipherLong[] =
  11593. {
  11594. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11595. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11596. 0x0c,0x33,0x97,0x06,0xc0,0xbe,0x83,0x87,
  11597. 0xdd,0xd3,0xff,0xd8,0xe4,0x6a,0x5b,0x84
  11598. };
  11599. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32_2CipherLong[] =
  11600. {
  11601. 0xf5,0x00,0xa2,0x91,0x54,0xa3,0x76,0xa2,
  11602. 0xdd,0xad,0x16,0x89,0xe5,0xf0,0x1d,0x40,
  11603. 0x84,0xcd,0x74,0x84,0xcb,0x8b,0x9e,0x29,
  11604. 0xa9,0x8a,0x12,0x65,0xa0,0x79,0x5e,0xce,
  11605. 0xd9,0x50,0x65,0x21,0x86,0xb0,0x85,0x0d,
  11606. 0x98,0x2d,0x9a,0x5a,0x11,0xbe,0xa5,0x7f
  11607. };
  11608. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64Cipher[] =
  11609. {
  11610. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11611. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11612. 0x3d,0xf7,0xb4,0xfd,0x8c
  11613. };
  11614. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64CipherLong[] =
  11615. {
  11616. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11617. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11618. 0x3d,0xf7,0xb4,0xfd,0x8c,0x55,0x47,0x10,
  11619. 0xd5,0x91,0x35,0xbe,0xd8,0x0d,0xa5,0x9e
  11620. };
  11621. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64_2CipherLong[] =
  11622. {
  11623. 0x59,0xf1,0xed,0x70,0x62,0x42,0xa8,0x06,
  11624. 0x07,0x36,0xe1,0xc5,0x04,0x79,0xc3,0x9b,
  11625. 0xd1,0x14,0x5c,0xcc,0x6f,0x81,0x5f,0x2f,
  11626. 0xa0,0xde,0xcf,0x61,0x55,0x18,0x7a,0xac,
  11627. 0xb0,0x59,0x37,0x90,0x53,0xb3,0x00,0x88,
  11628. 0xb4,0x49,0x90,0x7b,0x96,0xcd,0xcc,0xc3
  11629. };
  11630. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96Cipher[] =
  11631. {
  11632. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11633. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11634. 0x47,0xb5,0xf3,0x30,0x3b
  11635. };
  11636. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96CipherLong[] =
  11637. {
  11638. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11639. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11640. 0x47,0xb5,0xf3,0x30,0x3b,0xef,0xcd,0x80,
  11641. 0xe3,0x61,0x34,0xef,0x4e,0x1b,0x79,0xc1
  11642. };
  11643. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96_2CipherLong[] =
  11644. {
  11645. 0x3c,0xb2,0xff,0xc0,0x24,0xe1,0xf5,0xc4,
  11646. 0x0f,0xd1,0x0a,0x1b,0xbe,0x1f,0x23,0xa1,
  11647. 0x8e,0xbf,0x2b,0x96,0xb6,0x37,0xc8,0x25,
  11648. 0x06,0x90,0xe2,0xca,0x71,0x24,0x52,0x95,
  11649. 0xaa,0x8c,0x80,0xdf,0xb7,0xd7,0x30,0xb0,
  11650. 0xcc,0x06,0x4f,0x28,0xa2,0x74,0x27,0xf8
  11651. };
  11652. #endif
  11653. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128Cipher[] =
  11654. {
  11655. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11656. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11657. 0x8c,0x68,0xa7,0xd9,0x57
  11658. };
  11659. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128CipherLong[] =
  11660. {
  11661. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11662. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11663. 0x8c,0x68,0xa7,0xd9,0x57,0xab,0x09,0x0f,
  11664. 0x01,0xc4,0x4e,0x62,0xaf,0xc2,0xdf,0x1a
  11665. };
  11666. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11667. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128_2CipherLong[] =
  11668. {
  11669. 0x88,0x0a,0x26,0x4e,0xa8,0x26,0x21,0xe0,
  11670. 0xfc,0xbc,0x63,0xdc,0xd9,0x60,0x52,0xb2,
  11671. 0x99,0x2f,0xbb,0x1e,0x00,0xf5,0x9f,0x6d,
  11672. 0xab,0x48,0x0f,0xc6,0x37,0x12,0x56,0xe3,
  11673. 0x12,0x8d,0x31,0xc8,0xea,0xf4,0x41,0x82,
  11674. 0x7a,0x88,0xe0,0xd7,0xf0,0x67,0x03,0xa4
  11675. };
  11676. #endif
  11677. #endif
  11678. #ifdef WOLFSSL_AES_256
  11679. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  11680. {
  11681. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11682. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11683. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11684. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11685. };
  11686. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  11687. {
  11688. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  11689. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
  11690. 0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
  11691. 0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
  11692. 0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
  11693. 0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
  11694. 0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
  11695. 0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
  11696. };
  11697. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11698. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32Cipher[] =
  11699. {
  11700. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11701. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11702. 0xa2,0x13,0x47,0x74,0xda
  11703. };
  11704. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32CipherLong[] =
  11705. {
  11706. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11707. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11708. 0xa2,0x13,0x47,0x74,0xda,0x89,0x77,0x40,
  11709. 0x28,0x9c,0xe8,0x19,0x26,0x32,0xd8,0x1f
  11710. };
  11711. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32_2CipherLong[] =
  11712. {
  11713. 0xf6,0xd9,0x22,0xc6,0x80,0x29,0xaf,0x14,
  11714. 0x54,0x6c,0x0a,0xce,0x42,0xea,0x3c,0xa1,
  11715. 0x7c,0xeb,0x36,0x0d,0x8e,0xd7,0x8c,0x59,
  11716. 0xa8,0x09,0x9f,0x9e,0xba,0x5b,0x95,0xfa,
  11717. 0x26,0x8c,0x37,0x59,0xf8,0xae,0x8e,0xaa,
  11718. 0x4d,0xe4,0x1c,0xfe,0x51,0xc7,0xb7,0xcc
  11719. };
  11720. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64Cipher[] =
  11721. {
  11722. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11723. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11724. 0xd4,0x94,0x4c,0xcd,0x4d
  11725. };
  11726. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64CipherLong[] =
  11727. {
  11728. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11729. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11730. 0xd4,0x94,0x4c,0xcd,0x4d,0x47,0x5a,0x92,
  11731. 0x26,0x49,0x81,0x7a,0xda,0x36,0x27,0x01
  11732. };
  11733. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64_2CipherLong[] =
  11734. {
  11735. 0xf7,0x9c,0xbf,0xf6,0xa2,0xaa,0x8a,0x0a,
  11736. 0x63,0x8a,0x20,0x2f,0x12,0xf1,0x8e,0x49,
  11737. 0x30,0xc0,0x8d,0x5c,0x5f,0x8b,0xbc,0x16,
  11738. 0xdd,0x71,0xee,0x13,0x14,0x7b,0xe1,0x25,
  11739. 0xcb,0x87,0x8a,0xc6,0xdc,0x1d,0x54,0x7a,
  11740. 0xe1,0xe4,0x6f,0x0d,0x95,0x1b,0xd1,0x8b
  11741. };
  11742. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96Cipher[] =
  11743. {
  11744. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11745. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11746. 0xb8,0x69,0xa1,0x48,0x45
  11747. };
  11748. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96CipherLong[] =
  11749. {
  11750. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11751. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11752. 0xb8,0x69,0xa1,0x48,0x45,0xf1,0xc6,0x27,
  11753. 0x36,0xa8,0xb2,0x4b,0x0e,0x62,0x6b,0x72
  11754. };
  11755. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96_2CipherLong[] =
  11756. {
  11757. 0xd5,0x56,0x73,0xaa,0xb8,0xe4,0x06,0xf6,
  11758. 0x83,0x45,0x3a,0xb4,0xb9,0x63,0xec,0xad,
  11759. 0x73,0xc5,0xab,0x78,0xb1,0x21,0xab,0xef,
  11760. 0x69,0x15,0xb7,0x0c,0xe9,0xb4,0x3a,0xe7,
  11761. 0xbc,0xc4,0x22,0xbd,0x93,0xba,0x52,0xe0,
  11762. 0x91,0x2f,0x5e,0x8d,0x6d,0x59,0xf7,0xc2
  11763. };
  11764. #endif
  11765. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
  11766. {
  11767. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11768. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11769. 0x4b,0x45,0x7c,0xd6,0x8a
  11770. };
  11771. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
  11772. {
  11773. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11774. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11775. 0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
  11776. 0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
  11777. };
  11778. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11779. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128_2CipherLong[] =
  11780. {
  11781. 0x24,0x5c,0x09,0xa0,0x3b,0x1a,0x5a,0x94,
  11782. 0x2b,0x93,0x56,0x13,0x48,0xa0,0x21,0xce,
  11783. 0x95,0x11,0xa3,0x76,0xd6,0x59,0x88,0x42,
  11784. 0x04,0x71,0x69,0x62,0x28,0xb2,0xee,0x9d,
  11785. 0xd5,0xa0,0xea,0xc7,0x37,0x93,0x92,0xc7,
  11786. 0xf2,0xb6,0x8d,0xd9,0x59,0x1a,0xfa,0xbb
  11787. };
  11788. #endif
  11789. #endif
  11790. int i;
  11791. struct {
  11792. const byte* key;
  11793. int keySz;
  11794. const byte* iv;
  11795. const byte* plain;
  11796. int len;
  11797. const byte* cipher;
  11798. } testVec[] = {
  11799. #ifdef WOLFSSL_AES_128
  11800. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11801. ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
  11802. /* let's try with just 9 bytes, non block size test */
  11803. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11804. ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
  11805. /* and an additional 9 bytes to reuse tmp left buffer */
  11806. { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
  11807. /* Counter wrapping */
  11808. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11809. ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
  11810. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11811. ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
  11812. ctr128Wrap128CipherLong },
  11813. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11814. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128_2,
  11815. ctrPlain, (int)sizeof(ctr128Wrap128_2CipherLong),
  11816. ctr128Wrap128_2CipherLong },
  11817. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11818. ctrPlain, (int)sizeof(ctr128Wrap96Cipher), ctr128Wrap96Cipher },
  11819. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11820. ctrPlain, (int)sizeof(ctr128Wrap96CipherLong),
  11821. ctr128Wrap96CipherLong },
  11822. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96_2,
  11823. ctrPlain, (int)sizeof(ctr128Wrap96_2CipherLong),
  11824. ctr128Wrap96_2CipherLong },
  11825. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11826. ctrPlain, (int)sizeof(ctr128Wrap64Cipher), ctr128Wrap64Cipher },
  11827. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11828. ctrPlain, (int)sizeof(ctr128Wrap64CipherLong),
  11829. ctr128Wrap64CipherLong },
  11830. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64_2,
  11831. ctrPlain, (int)sizeof(ctr128Wrap64_2CipherLong),
  11832. ctr128Wrap64_2CipherLong },
  11833. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11834. ctrPlain, (int)sizeof(ctr128Wrap32Cipher), ctr128Wrap32Cipher },
  11835. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11836. ctrPlain, (int)sizeof(ctr128Wrap32CipherLong),
  11837. ctr128Wrap32CipherLong },
  11838. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32_2,
  11839. ctrPlain, (int)sizeof(ctr128Wrap32_2CipherLong),
  11840. ctr128Wrap32_2CipherLong },
  11841. #endif
  11842. #endif
  11843. #ifdef WOLFSSL_AES_192
  11844. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11845. ctrPlain, (int)sizeof(ctrPlain), ctr192Cipher },
  11846. /* let's try with just 9 bytes, non block size test */
  11847. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11848. ctrPlain, (int)sizeof(oddCipher), ctr192Cipher },
  11849. /* Counter wrapping */
  11850. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11851. ctrPlain, (int)sizeof(ctr192Wrap128Cipher), ctr192Wrap128Cipher },
  11852. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11853. ctrPlain, (int)sizeof(ctr192Wrap128CipherLong),
  11854. ctr192Wrap128CipherLong },
  11855. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11856. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128_2,
  11857. ctrPlain, (int)sizeof(ctr192Wrap128_2CipherLong),
  11858. ctr192Wrap128_2CipherLong },
  11859. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11860. ctrPlain, (int)sizeof(ctr192Wrap96Cipher), ctr192Wrap96Cipher },
  11861. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11862. ctrPlain, (int)sizeof(ctr192Wrap96CipherLong),
  11863. ctr192Wrap96CipherLong },
  11864. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96_2,
  11865. ctrPlain, (int)sizeof(ctr192Wrap96_2CipherLong),
  11866. ctr192Wrap96_2CipherLong },
  11867. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11868. ctrPlain, (int)sizeof(ctr192Wrap64Cipher), ctr192Wrap64Cipher },
  11869. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11870. ctrPlain, (int)sizeof(ctr192Wrap64CipherLong),
  11871. ctr192Wrap64CipherLong },
  11872. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64_2,
  11873. ctrPlain, (int)sizeof(ctr192Wrap64_2CipherLong),
  11874. ctr192Wrap64_2CipherLong },
  11875. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11876. ctrPlain, (int)sizeof(ctr192Wrap32Cipher), ctr192Wrap32Cipher },
  11877. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11878. ctrPlain, (int)sizeof(ctr192Wrap32CipherLong),
  11879. ctr192Wrap32CipherLong },
  11880. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32_2,
  11881. ctrPlain, (int)sizeof(ctr192Wrap32_2CipherLong),
  11882. ctr192Wrap32_2CipherLong },
  11883. #endif
  11884. #endif
  11885. #ifdef WOLFSSL_AES_256
  11886. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11887. ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
  11888. /* let's try with just 9 bytes, non block size test */
  11889. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11890. ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
  11891. /* Counter wrapping */
  11892. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11893. ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
  11894. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11895. ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
  11896. ctr256Wrap128CipherLong },
  11897. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11898. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128_2,
  11899. ctrPlain, (int)sizeof(ctr256Wrap128_2CipherLong),
  11900. ctr256Wrap128_2CipherLong },
  11901. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11902. ctrPlain, (int)sizeof(ctr256Wrap96Cipher), ctr256Wrap96Cipher },
  11903. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11904. ctrPlain, (int)sizeof(ctr256Wrap96CipherLong),
  11905. ctr256Wrap96CipherLong },
  11906. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96_2,
  11907. ctrPlain, (int)sizeof(ctr256Wrap96_2CipherLong),
  11908. ctr256Wrap96_2CipherLong },
  11909. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11910. ctrPlain, (int)sizeof(ctr256Wrap64Cipher), ctr256Wrap64Cipher },
  11911. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11912. ctrPlain, (int)sizeof(ctr256Wrap64CipherLong),
  11913. ctr256Wrap64CipherLong },
  11914. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64_2,
  11915. ctrPlain, (int)sizeof(ctr256Wrap64_2CipherLong),
  11916. ctr256Wrap64_2CipherLong },
  11917. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11918. ctrPlain, (int)sizeof(ctr256Wrap32Cipher), ctr256Wrap32Cipher },
  11919. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11920. ctrPlain, (int)sizeof(ctr256Wrap32CipherLong),
  11921. ctr256Wrap32CipherLong },
  11922. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32_2,
  11923. ctrPlain, (int)sizeof(ctr256Wrap32_2CipherLong),
  11924. ctr256Wrap32_2CipherLong },
  11925. #endif
  11926. #endif
  11927. };
  11928. #define AES_CTR_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  11929. WOLFSSL_ENTER("aes_ctr_test");
  11930. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11931. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  11932. if (enc == NULL)
  11933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11934. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  11935. if (dec == NULL)
  11936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11937. #else
  11938. XMEMSET(enc, 0, sizeof(Aes));
  11939. XMEMSET(dec, 0, sizeof(Aes));
  11940. ret = wc_AesInit(enc, HEAP_HINT, devId);
  11941. if (ret != 0)
  11942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11943. ret = wc_AesInit(dec, HEAP_HINT, devId);
  11944. if (ret != 0)
  11945. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11946. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  11947. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11948. if (testVec[i].key != NULL) {
  11949. ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
  11950. testVec[i].iv, AES_ENCRYPTION);
  11951. if (ret != 0) {
  11952. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11953. }
  11954. /* Ctr only uses encrypt, even on key setup */
  11955. ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
  11956. testVec[i].iv, AES_ENCRYPTION);
  11957. if (ret != 0) {
  11958. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11959. }
  11960. }
  11961. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
  11962. if (ret != 0) {
  11963. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11964. }
  11965. ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
  11966. if (ret != 0) {
  11967. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11968. }
  11969. if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
  11970. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11971. }
  11972. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11973. if (XMEMCMP(cipher, testVec[i].cipher, (size_t)testVec[i].len)) {
  11974. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11975. }
  11976. #endif
  11977. }
  11978. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11979. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11980. if (testVec[i].key != NULL) {
  11981. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11982. testVec[i].iv, AES_ENCRYPTION);
  11983. if (ret != 0) {
  11984. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11985. }
  11986. /* Ctr only uses encrypt, even on key setup */
  11987. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  11988. testVec[i].iv, AES_ENCRYPTION);
  11989. if (ret != 0) {
  11990. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11991. }
  11992. }
  11993. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11994. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  11995. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11996. if (ret != 0) {
  11997. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11998. }
  11999. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12000. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12001. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12002. if (ret != 0) {
  12003. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12004. }
  12005. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12006. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12007. }
  12008. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12009. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12010. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12011. }
  12012. #endif
  12013. }
  12014. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  12015. if (testVec[i].key != NULL) {
  12016. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12017. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  12018. testVec[i].iv, AES_ENCRYPTION);
  12019. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12020. if (ret != 0) {
  12021. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12022. }
  12023. /* Ctr only uses encrypt, even on key setup */
  12024. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12025. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  12026. testVec[i].iv, AES_ENCRYPTION);
  12027. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12028. if (ret != 0) {
  12029. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12030. }
  12031. }
  12032. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12033. if (ret != 0) {
  12034. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12035. }
  12036. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12037. if (ret != 0) {
  12038. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12039. }
  12040. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12041. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12042. }
  12043. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12044. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12045. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12046. }
  12047. #endif
  12048. }
  12049. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12050. out:
  12051. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12052. wc_AesDelete(enc, &enc);
  12053. #else
  12054. wc_AesFree(enc);
  12055. #endif
  12056. #ifdef HAVE_AES_DECRYPT
  12057. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12058. wc_AesDelete(dec, &dec);
  12059. #else
  12060. wc_AesFree(dec);
  12061. #endif
  12062. #endif
  12063. return ret;
  12064. }
  12065. #endif /* WOLFSSL_AES_COUNTER */
  12066. #ifdef HAVE_AES_ECB
  12067. static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12068. {
  12069. wc_test_ret_t ret = 0;
  12070. /* keys padded to block size (16 bytes) */
  12071. WOLFSSL_SMALL_STACK_STATIC const byte key_128[] =
  12072. "0123456789abcdef ";
  12073. WOLFSSL_SMALL_STACK_STATIC const byte key_192[] =
  12074. "0123456789abcdef01234567 ";
  12075. WOLFSSL_SMALL_STACK_STATIC const byte key_256[] =
  12076. "0123456789abcdef0123456789abcdef ";
  12077. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12078. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12079. 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  12080. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20
  12081. };
  12082. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[AES_BLOCK_SIZE] = {
  12083. 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
  12084. 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
  12085. };
  12086. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[AES_BLOCK_SIZE] = {
  12087. 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1,
  12088. 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab
  12089. };
  12090. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[AES_BLOCK_SIZE] = {
  12091. 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33,
  12092. 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82
  12093. };
  12094. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] = {
  12095. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12096. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12097. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12098. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12099. };
  12100. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] = {
  12101. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12102. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12103. };
  12104. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] = {
  12105. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12106. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12107. };
  12108. int i;
  12109. struct {
  12110. const byte* key;
  12111. int keySz;
  12112. const byte* iv; /* null uses 0's */
  12113. const byte* plain;
  12114. const byte* verify;
  12115. } testVec[] = {
  12116. { key_128, 16, iv, msg, verify_ecb_128 },
  12117. { key_192, 24, iv, msg, verify_ecb_192 },
  12118. { key_256, 32, iv, msg, verify_ecb_256 },
  12119. { niKey, 32, NULL, niPlain, niCipher }
  12120. };
  12121. #define AES_ECB_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  12122. for (i = 0; i < AES_ECB_TEST_LEN; i++) {
  12123. ret = wc_AesSetKey(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12124. AES_ENCRYPTION);
  12125. if (ret != 0)
  12126. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12127. #ifdef HAVE_AES_DECRYPT
  12128. ret = wc_AesSetKey(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12129. AES_DECRYPTION);
  12130. if (ret != 0)
  12131. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12132. #endif
  12133. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12134. ret = wc_AesEcbEncrypt(enc, cipher, testVec[i].plain, AES_BLOCK_SIZE);
  12135. #if defined(WOLFSSL_ASYNC_CRYPT)
  12136. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12137. #endif
  12138. if (ret != 0)
  12139. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12140. if (XMEMCMP(cipher, testVec[i].verify, AES_BLOCK_SIZE)) {
  12141. WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!");
  12142. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12143. }
  12144. #ifdef HAVE_AES_DECRYPT
  12145. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12146. ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12147. #if defined(WOLFSSL_ASYNC_CRYPT)
  12148. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12149. #endif
  12150. if (ret != 0)
  12151. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12152. if (XMEMCMP(plain, testVec[i].plain, AES_BLOCK_SIZE))
  12153. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12154. #endif /* HAVE_AES_DECRYPT */
  12155. (void)dec;
  12156. (void)plain;
  12157. }
  12158. out:
  12159. return ret;
  12160. }
  12161. #endif /* HAVE_AES_ECB */
  12162. #ifdef WOLFSSL_AES_DIRECT
  12163. static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12164. {
  12165. wc_test_ret_t ret = 0;
  12166. WOLFSSL_ENTER("aes_direct_test");
  12167. #if defined(WOLFSSL_AES_256)
  12168. {
  12169. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  12170. {
  12171. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12172. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12173. };
  12174. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  12175. {
  12176. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12177. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12178. };
  12179. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  12180. {
  12181. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12182. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12183. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12184. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12185. };
  12186. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12187. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  12188. if (ret != 0)
  12189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12190. #if !defined(HAVE_SELFTEST) && \
  12191. (defined(WOLFSSL_LINUXKM) || \
  12192. !defined(HAVE_FIPS) || \
  12193. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12194. ret = wc_AesEncryptDirect(enc, cipher, niPlain);
  12195. if (ret != 0)
  12196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12197. #else
  12198. wc_AesEncryptDirect(enc, cipher, niPlain);
  12199. #endif
  12200. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  12201. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12202. #ifdef HAVE_AES_DECRYPT
  12203. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12204. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  12205. if (ret != 0)
  12206. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12207. #if !defined(HAVE_SELFTEST) && \
  12208. (defined(WOLFSSL_LINUXKM) || \
  12209. !defined(HAVE_FIPS) || \
  12210. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12211. ret = wc_AesDecryptDirect(dec, plain, niCipher);
  12212. if (ret != 0)
  12213. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12214. #else
  12215. wc_AesDecryptDirect(dec, plain, niCipher);
  12216. #endif
  12217. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  12218. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12219. #endif /* HAVE_AES_DECRYPT */
  12220. }
  12221. (void)dec;
  12222. (void)plain;
  12223. #endif /* WOLFSSL_AES_256 */
  12224. out:
  12225. return ret;
  12226. }
  12227. #endif /* WOLFSSL_AES_DIRECT */
  12228. #ifdef HAVE_AES_CBC
  12229. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void)
  12230. {
  12231. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12232. Aes *enc = NULL;
  12233. #else
  12234. Aes enc[1];
  12235. #endif
  12236. #ifdef HAVE_AES_DECRYPT
  12237. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12238. Aes *dec = NULL;
  12239. #else
  12240. Aes dec[1];
  12241. #endif
  12242. #endif
  12243. byte cipher[AES_BLOCK_SIZE * 4];
  12244. #ifdef HAVE_AES_DECRYPT
  12245. byte plain [AES_BLOCK_SIZE * 4];
  12246. #endif
  12247. wc_test_ret_t ret = 0;
  12248. WOLFSSL_ENTER("aes_cbc_test");
  12249. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12250. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12251. if (enc == NULL)
  12252. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12253. #ifdef HAVE_AES_DECRYPT
  12254. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12255. if (dec == NULL)
  12256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12257. #endif
  12258. #else
  12259. XMEMSET(enc, 0, sizeof(Aes));
  12260. #ifdef HAVE_AES_DECRYPT
  12261. XMEMSET(dec, 0, sizeof(Aes));
  12262. #endif
  12263. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12264. if (ret != 0)
  12265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12266. #ifdef HAVE_AES_DECRYPT
  12267. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12268. if (ret != 0)
  12269. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12270. #endif
  12271. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12272. #ifdef WOLFSSL_AES_128
  12273. {
  12274. /* "Now is the time for all " w/o trailing 0 */
  12275. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12276. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  12277. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  12278. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  12279. };
  12280. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12281. {
  12282. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  12283. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  12284. };
  12285. #ifdef HAVE_RENESAS_SYNC
  12286. const byte *key = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  12287. #else
  12288. /* padded to 16-byye */
  12289. WOLFSSL_SMALL_STACK_STATIC const byte key[] = "0123456789abcdef ";
  12290. #endif
  12291. /* padded to 16-bytes */
  12292. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12293. ret = wc_AesSetKey(enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  12294. if (ret != 0)
  12295. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12296. #ifdef HAVE_AES_DECRYPT
  12297. ret = wc_AesSetKey(dec, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
  12298. if (ret != 0)
  12299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12300. #endif
  12301. XMEMSET(cipher, 0, sizeof(cipher));
  12302. ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
  12303. #if defined(WOLFSSL_ASYNC_CRYPT)
  12304. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12305. #endif
  12306. if (ret != 0)
  12307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12308. #ifdef HAVE_AES_DECRYPT
  12309. XMEMSET(plain, 0, sizeof(plain));
  12310. ret = wc_AesCbcDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12311. #if defined(WOLFSSL_ASYNC_CRYPT)
  12312. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12313. #endif
  12314. if (ret != 0) {
  12315. WOLFSSL_MSG("failed wc_AesCbcDecrypt");
  12316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12317. }
  12318. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) {
  12319. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare");
  12320. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12321. }
  12322. #endif /* HAVE_AES_DECRYPT */
  12323. /* skipped because wrapped key use in case of renesas sm */
  12324. #ifndef HAVE_RENESAS_SYNC
  12325. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) {
  12326. WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare");
  12327. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12328. }
  12329. #endif
  12330. }
  12331. #endif /* WOLFSSL_AES_128 */
  12332. #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT)
  12333. {
  12334. WOLFSSL_SMALL_STACK_STATIC const byte bigMsg[] = {
  12335. /* "All work and no play makes Jack a dull boy. " */
  12336. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12337. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12338. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12339. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12340. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12341. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12342. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12343. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12344. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12345. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12346. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12347. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12348. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12349. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12350. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12351. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12352. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12353. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12354. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12355. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12356. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12357. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12358. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12359. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12360. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12361. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12362. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12363. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12364. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12365. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12366. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12367. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12368. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12369. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12370. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12371. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12372. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12373. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12374. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12375. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12376. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12377. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12378. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12379. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12380. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12381. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12382. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12383. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20
  12384. };
  12385. WOLFSSL_SMALL_STACK_STATIC const byte bigKey[] =
  12386. "0123456789abcdeffedcba9876543210";
  12387. /* padded to 16-bytes */
  12388. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12389. word32 keySz, msgSz;
  12390. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12391. byte *bigCipher = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12392. DYNAMIC_TYPE_TMP_BUFFER);
  12393. byte *bigPlain = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12394. DYNAMIC_TYPE_TMP_BUFFER);
  12395. if ((bigCipher == NULL) ||
  12396. (bigPlain == NULL)) {
  12397. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12398. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12399. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12400. }
  12401. #else
  12402. byte bigCipher[sizeof(bigMsg)];
  12403. byte bigPlain[sizeof(bigMsg)];
  12404. #endif
  12405. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12406. * message by AES_BLOCK_SIZE for each size of AES key. */
  12407. for (keySz = 16; keySz <= 32; keySz += 8) {
  12408. for (msgSz = AES_BLOCK_SIZE;
  12409. msgSz <= sizeof(bigMsg);
  12410. msgSz += AES_BLOCK_SIZE) {
  12411. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12412. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12413. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12414. if (ret != 0) {
  12415. ret = WC_TEST_RET_ENC_EC(ret);
  12416. break;
  12417. }
  12418. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12419. if (ret != 0) {
  12420. ret = WC_TEST_RET_ENC_EC(ret);
  12421. break;
  12422. }
  12423. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12424. #if defined(WOLFSSL_ASYNC_CRYPT)
  12425. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12426. #endif
  12427. if (ret != 0) {
  12428. ret = WC_TEST_RET_ENC_EC(ret);
  12429. break;
  12430. }
  12431. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12432. #if defined(WOLFSSL_ASYNC_CRYPT)
  12433. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12434. #endif
  12435. if (ret != 0) {
  12436. ret = WC_TEST_RET_ENC_EC(ret);
  12437. break;
  12438. }
  12439. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12440. ret = WC_TEST_RET_ENC_NC;
  12441. break;
  12442. }
  12443. }
  12444. if (ret != 0)
  12445. break;
  12446. }
  12447. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12448. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12449. * message by AES_BLOCK_SIZE for each size of AES key. */
  12450. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12451. for (keySz = 16; keySz <= 32; keySz += 8) {
  12452. for (msgSz = AES_BLOCK_SIZE;
  12453. msgSz <= sizeof(bigMsg);
  12454. msgSz += AES_BLOCK_SIZE) {
  12455. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12456. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12457. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12458. if (ret != 0) {
  12459. ret = WC_TEST_RET_ENC_EC(ret);
  12460. break;
  12461. }
  12462. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12463. if (ret != 0) {
  12464. ret = WC_TEST_RET_ENC_EC(ret);
  12465. break;
  12466. }
  12467. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12468. #if defined(WOLFSSL_ASYNC_CRYPT)
  12469. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12470. #endif
  12471. if (ret != 0) {
  12472. ret = WC_TEST_RET_ENC_EC(ret);
  12473. break;
  12474. }
  12475. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12476. #if defined(WOLFSSL_ASYNC_CRYPT)
  12477. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12478. #endif
  12479. if (ret != 0) {
  12480. ret = WC_TEST_RET_ENC_EC(ret);
  12481. break;
  12482. }
  12483. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12484. ret = WC_TEST_RET_ENC_NC;
  12485. break;
  12486. }
  12487. }
  12488. if (ret != 0)
  12489. break;
  12490. }
  12491. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12492. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12493. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12494. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12495. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12496. #endif
  12497. if (ret != 0)
  12498. goto out;
  12499. }
  12500. #endif /* WOLFSSL_AESNI && HAVE_AES_DECRYPT */
  12501. /* Test of AES IV state with encrypt/decrypt */
  12502. #if defined(WOLFSSL_AES_128) && !defined(HAVE_RENESAS_SYNC)
  12503. {
  12504. /* Test Vector from "NIST Special Publication 800-38A, 2001 Edition"
  12505. * https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf
  12506. */
  12507. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  12508. {
  12509. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  12510. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  12511. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  12512. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
  12513. };
  12514. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] =
  12515. {
  12516. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  12517. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  12518. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  12519. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2
  12520. };
  12521. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  12522. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  12523. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  12524. };
  12525. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  12526. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  12527. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  12528. };
  12529. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  12530. if (ret != 0)
  12531. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12532. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 2);
  12533. ret = wc_AesCbcEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE);
  12534. #if defined(WOLFSSL_ASYNC_CRYPT)
  12535. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12536. #endif
  12537. if (ret != 0)
  12538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12539. #ifndef HAVE_RENESAS_SYNC
  12540. if (XMEMCMP(cipher, verify2, AES_BLOCK_SIZE))
  12541. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12542. #endif
  12543. ret = wc_AesCbcEncrypt(enc, cipher + AES_BLOCK_SIZE,
  12544. msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12545. #if defined(WOLFSSL_ASYNC_CRYPT)
  12546. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12547. #endif
  12548. if (ret != 0)
  12549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12550. if (XMEMCMP(cipher + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE,
  12551. AES_BLOCK_SIZE))
  12552. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12553. #if defined(HAVE_AES_DECRYPT)
  12554. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION);
  12555. if (ret != 0)
  12556. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12557. XMEMSET(plain, 0, AES_BLOCK_SIZE * 2);
  12558. ret = wc_AesCbcDecrypt(dec, plain, verify2, AES_BLOCK_SIZE);
  12559. #if defined(WOLFSSL_ASYNC_CRYPT)
  12560. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12561. #endif
  12562. if (ret != 0)
  12563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12564. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE))
  12565. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12566. ret = wc_AesCbcDecrypt(dec, plain + AES_BLOCK_SIZE,
  12567. verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12568. #if defined(WOLFSSL_ASYNC_CRYPT)
  12569. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12570. #endif
  12571. if (ret != 0)
  12572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12573. if (XMEMCMP(plain + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE,
  12574. AES_BLOCK_SIZE)) {
  12575. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare");
  12576. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12577. }
  12578. #endif /* HAVE_AES_DECRYPT */
  12579. aes_cbc_oneshot_test();
  12580. }
  12581. #endif /* WOLFSSL_AES_128 && !HAVE_RENESAS_SYNC */
  12582. out:
  12583. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12584. wc_AesDelete(enc, &enc);
  12585. #else
  12586. wc_AesFree(enc);
  12587. #endif
  12588. #ifdef HAVE_AES_DECRYPT
  12589. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12590. wc_AesDelete(dec, &dec);
  12591. #else
  12592. wc_AesFree(dec);
  12593. #endif
  12594. #endif
  12595. return ret;
  12596. }
  12597. #endif /* HAVE_AES_CBC */
  12598. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12599. static wc_test_ret_t aes_ecb_direct_test(void)
  12600. {
  12601. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12602. Aes *enc = NULL;
  12603. #else
  12604. Aes enc[1];
  12605. #endif
  12606. #if !defined(HAVE_AES_DECRYPT) || \
  12607. (defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC))
  12608. Aes *dec = NULL;
  12609. #else
  12610. Aes dec[1];
  12611. #endif
  12612. byte cipher[AES_BLOCK_SIZE];
  12613. byte plain [AES_BLOCK_SIZE];
  12614. wc_test_ret_t ret = 0;
  12615. WOLFSSL_ENTER("aes_ecb/direct_test");
  12616. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  12617. XMEMSET(enc, 0, sizeof(Aes));
  12618. #ifdef HAVE_AES_DECRYPT
  12619. XMEMSET(dec, 0, sizeof(Aes));
  12620. #endif
  12621. #endif
  12622. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12623. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12624. if (enc == NULL)
  12625. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12626. #ifdef HAVE_AES_DECRYPT
  12627. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12628. if (dec == NULL)
  12629. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12630. #endif
  12631. #else
  12632. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12633. if (ret != 0)
  12634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12635. #ifdef HAVE_AES_DECRYPT
  12636. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12637. if (ret != 0)
  12638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12639. #endif
  12640. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12641. #ifdef HAVE_AES_ECB
  12642. ret = aes_ecb_test(enc, dec, cipher, plain);
  12643. if (ret != 0)
  12644. return ret;
  12645. #endif
  12646. #ifdef WOLFSSL_AES_DIRECT
  12647. ret = aes_direct_test(enc, dec, cipher, plain);
  12648. if (ret != 0)
  12649. return ret;
  12650. #endif
  12651. out:
  12652. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12653. wc_AesDelete(enc, &enc);
  12654. wc_AesDelete(dec, &dec);
  12655. #else
  12656. wc_AesFree(enc);
  12657. wc_AesFree(dec);
  12658. #endif
  12659. return ret;
  12660. }
  12661. #endif /* HAVE_AES_ECB || WOLFSSL_AES_DIRECT */
  12662. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
  12663. {
  12664. wc_test_ret_t ret = 0;
  12665. WOLFSSL_ENTER("aes_test");
  12666. #ifndef HAVE_RENESAS_SYNC
  12667. ret = aes_key_size_test();
  12668. if (ret != 0)
  12669. goto out;
  12670. #endif
  12671. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12672. ret = aes_ecb_direct_test();
  12673. if (ret != 0)
  12674. return ret;
  12675. #endif
  12676. out:
  12677. return ret;
  12678. }
  12679. #if defined(WOLFSSL_AES_CFB)
  12680. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
  12681. {
  12682. int ret;
  12683. WOLFSSL_ENTER("aes_cfb_test");
  12684. ret = aescfb_test_0();
  12685. if (ret != 0)
  12686. return ret;
  12687. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  12688. ret = aescfb1_test();
  12689. if (ret != 0)
  12690. return ret;
  12691. ret = aescfb8_test();
  12692. if (ret != 0)
  12693. return ret;
  12694. #endif
  12695. return 0;
  12696. }
  12697. #endif
  12698. #if defined(WOLFSSL_AES_XTS)
  12699. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void)
  12700. {
  12701. int ret = 0;
  12702. WOLFSSL_ENTER("aes_xts_test");
  12703. #ifdef WOLFSSL_AES_128
  12704. ret = aes_xts_128_test();
  12705. if (ret != 0)
  12706. return ret;
  12707. #endif
  12708. #ifdef WOLFSSL_AES_192
  12709. ret = aes_xts_192_test();
  12710. if (ret != 0)
  12711. return ret;
  12712. #endif
  12713. #ifdef WOLFSSL_AES_256
  12714. ret = aes_xts_256_test();
  12715. if (ret != 0)
  12716. return ret;
  12717. #endif
  12718. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  12719. ret = aes_xts_sector_test();
  12720. if (ret != 0)
  12721. return ret;
  12722. #endif
  12723. #ifdef WOLFSSL_AES_128
  12724. ret = aes_xts_args_test();
  12725. if (ret != 0)
  12726. return ret;
  12727. #endif
  12728. return 0;
  12729. }
  12730. #endif
  12731. #ifdef WOLFSSL_AES_192
  12732. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
  12733. {
  12734. wc_test_ret_t ret = 0;
  12735. #ifdef HAVE_AES_CBC
  12736. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12737. Aes *enc = NULL;
  12738. #else
  12739. Aes enc[1];
  12740. #endif
  12741. byte cipher[AES_BLOCK_SIZE];
  12742. #ifdef HAVE_AES_DECRYPT
  12743. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12744. Aes *dec = NULL;
  12745. #else
  12746. Aes dec[1];
  12747. #endif
  12748. byte plain[AES_BLOCK_SIZE];
  12749. #endif
  12750. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  12751. * Appendix F.2.3 */
  12752. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12753. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12754. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12755. };
  12756. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12757. {
  12758. 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  12759. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8
  12760. };
  12761. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12762. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  12763. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  12764. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  12765. };
  12766. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12767. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12768. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12769. };
  12770. WOLFSSL_ENTER("aes192_test");
  12771. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12772. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12773. if (enc == NULL)
  12774. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12775. #ifdef HAVE_AES_DECRYPT
  12776. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12777. if (dec == NULL)
  12778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12779. #endif
  12780. #else
  12781. XMEMSET(enc, 0, sizeof(Aes));
  12782. #ifdef HAVE_AES_DECRYPT
  12783. XMEMSET(dec, 0, sizeof(Aes));
  12784. #endif
  12785. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12786. if (ret != 0)
  12787. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12788. #ifdef HAVE_AES_DECRYPT
  12789. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12790. if (ret != 0)
  12791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12792. #endif
  12793. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12794. ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
  12795. if (ret != 0)
  12796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12797. #ifdef HAVE_AES_DECRYPT
  12798. ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
  12799. if (ret != 0)
  12800. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12801. #endif
  12802. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12803. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12804. #if defined(WOLFSSL_ASYNC_CRYPT)
  12805. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12806. #endif
  12807. if (ret != 0)
  12808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12809. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12810. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12811. #ifdef HAVE_AES_DECRYPT
  12812. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12813. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12814. #if defined(WOLFSSL_ASYNC_CRYPT)
  12815. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12816. #endif
  12817. if (ret != 0)
  12818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12819. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12820. WOLFSSL_MSG("failed wc_AesCbcDecrypt plain-msg compare");
  12821. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12822. }
  12823. #endif
  12824. out:
  12825. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12826. wc_AesDelete(enc, &enc);
  12827. #else
  12828. wc_AesFree(enc);
  12829. #endif
  12830. #ifdef HAVE_AES_DECRYPT
  12831. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12832. wc_AesDelete(dec, &dec);
  12833. #else
  12834. wc_AesFree(dec);
  12835. #endif
  12836. #endif
  12837. #endif /* HAVE_AES_CBC */
  12838. return ret;
  12839. }
  12840. #endif /* WOLFSSL_AES_192 */
  12841. #ifdef WOLFSSL_AES_256
  12842. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
  12843. {
  12844. #ifdef HAVE_AES_CBC
  12845. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12846. Aes *enc = NULL;
  12847. #else
  12848. Aes enc[1];
  12849. #endif
  12850. byte cipher[AES_BLOCK_SIZE];
  12851. #ifdef HAVE_AES_DECRYPT
  12852. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12853. Aes *dec = NULL;
  12854. #else
  12855. Aes dec[1];
  12856. #endif
  12857. byte plain[AES_BLOCK_SIZE];
  12858. #endif
  12859. #endif /* HAVE_AES_CBC */
  12860. wc_test_ret_t ret = 0;
  12861. #ifdef HAVE_AES_CBC
  12862. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  12863. * Appendix F.2.5 */
  12864. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12865. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12866. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12867. };
  12868. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12869. {
  12870. 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  12871. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6
  12872. };
  12873. #ifdef HAVE_RENESAS_SYNC
  12874. byte *key =
  12875. (byte*)guser_PKCbInfo.wrapped_key_aes256;
  12876. int keySz = (256/8);
  12877. #else
  12878. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12879. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12880. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12881. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12882. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12883. };
  12884. int keySz = (int)sizeof(key);
  12885. #endif
  12886. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12887. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12888. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12889. };
  12890. WOLFSSL_ENTER("aes256_test");
  12891. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12892. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12893. if (enc == NULL)
  12894. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12895. #ifdef HAVE_AES_DECRYPT
  12896. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12897. if (dec == NULL)
  12898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12899. #endif
  12900. #else
  12901. XMEMSET(enc, 0, sizeof(Aes));
  12902. #ifdef HAVE_AES_DECRYPT
  12903. XMEMSET(dec, 0, sizeof(Aes));
  12904. #endif
  12905. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12906. if (ret != 0)
  12907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12908. #ifdef HAVE_AES_DECRYPT
  12909. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12910. if (ret != 0)
  12911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12912. #endif
  12913. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12914. ret = wc_AesSetKey(enc, key, (word32)keySz, iv, AES_ENCRYPTION);
  12915. if (ret != 0)
  12916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12917. #ifdef HAVE_AES_DECRYPT
  12918. ret = wc_AesSetKey(dec, key, (word32)keySz, iv, AES_DECRYPTION);
  12919. if (ret != 0)
  12920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12921. #endif
  12922. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12923. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12924. #if defined(WOLFSSL_ASYNC_CRYPT)
  12925. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12926. #endif
  12927. if (ret != 0)
  12928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12929. #ifdef HAVE_AES_DECRYPT
  12930. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12931. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12932. #if defined(WOLFSSL_ASYNC_CRYPT)
  12933. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12934. #endif
  12935. if (ret != 0)
  12936. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12937. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12938. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12939. }
  12940. #endif
  12941. #ifndef HAVE_RENESAS_SYNC
  12942. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12944. #endif
  12945. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12946. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12947. if (ret != 0)
  12948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12949. #ifdef HAVE_AES_DECRYPT
  12950. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12951. if (ret != 0)
  12952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12953. #endif
  12954. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12955. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12956. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12957. #if defined(WOLFSSL_ASYNC_CRYPT)
  12958. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12959. #endif
  12960. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12961. if (ret != 0)
  12962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12963. #ifdef HAVE_AES_DECRYPT
  12964. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12965. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12966. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12967. #if defined(WOLFSSL_ASYNC_CRYPT)
  12968. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12969. #endif
  12970. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12971. if (ret != 0)
  12972. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12973. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12974. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12975. }
  12976. #endif
  12977. #ifndef HAVE_RENESAS_SYNC
  12978. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12979. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12980. #endif
  12981. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12982. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12983. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12984. if (ret != 0)
  12985. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12986. #ifdef HAVE_AES_DECRYPT
  12987. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12988. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12989. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12990. if (ret != 0)
  12991. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12992. #endif
  12993. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12994. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12995. #if defined(WOLFSSL_ASYNC_CRYPT)
  12996. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12997. #endif
  12998. if (ret != 0)
  12999. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13000. #ifdef HAVE_AES_DECRYPT
  13001. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  13002. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  13003. #if defined(WOLFSSL_ASYNC_CRYPT)
  13004. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13005. #endif
  13006. if (ret != 0)
  13007. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13008. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  13009. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13010. }
  13011. #endif
  13012. #ifndef HAVE_RENESAS_SYNC
  13013. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  13014. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13015. #endif
  13016. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  13017. out:
  13018. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13019. wc_AesDelete(enc, &enc);
  13020. #else
  13021. wc_AesFree(enc);
  13022. #endif
  13023. #ifdef HAVE_AES_DECRYPT
  13024. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13025. wc_AesDelete(dec, &dec);
  13026. #else
  13027. wc_AesFree(dec);
  13028. #endif
  13029. #endif
  13030. #endif /* HAVE_AES_CBC */
  13031. return ret;
  13032. }
  13033. #endif /* WOLFSSL_AES_256 */
  13034. #ifdef HAVE_AESGCM
  13035. #ifdef WOLFSSL_AES_128
  13036. static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
  13037. byte* plain, int plainSz, byte* cipher, int cipherSz,
  13038. byte* aad, int aadSz, byte* tag, int tagSz)
  13039. {
  13040. wc_test_ret_t ret;
  13041. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13042. Aes *enc = NULL;
  13043. Aes *dec = NULL;
  13044. #else
  13045. Aes enc[1];
  13046. Aes dec[1];
  13047. #endif
  13048. byte resultT[AES_BLOCK_SIZE];
  13049. byte resultP[AES_BLOCK_SIZE * 3];
  13050. byte resultC[AES_BLOCK_SIZE * 3];
  13051. XMEMSET(resultT, 0, sizeof(resultT));
  13052. XMEMSET(resultC, 0, sizeof(resultC));
  13053. XMEMSET(resultP, 0, sizeof(resultP));
  13054. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13055. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13056. if (enc == NULL)
  13057. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13058. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13059. if (dec == NULL)
  13060. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13061. #else
  13062. XMEMSET(enc, 0, sizeof(Aes));
  13063. XMEMSET(dec, 0, sizeof(Aes));
  13064. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13065. if (ret != 0)
  13066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13067. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13068. if (ret != 0)
  13069. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13070. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  13071. ret = wc_AesGcmSetKey(enc, key, (word32)keySz);
  13072. if (ret != 0)
  13073. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13074. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13075. ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, (word32)ivSz,
  13076. resultT, (word32)tagSz, aad, (word32)aadSz);
  13077. #if defined(WOLFSSL_ASYNC_CRYPT)
  13078. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13079. #endif
  13080. if (ret != 0)
  13081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13082. if (cipher != NULL) {
  13083. if (XMEMCMP(cipher, resultC, (word32)cipherSz))
  13084. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13085. }
  13086. if (XMEMCMP(tag, resultT, (unsigned long)tagSz))
  13087. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13088. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13089. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13090. ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz,
  13091. resultT, tagSz, aad, aadSz);
  13092. #if defined(WOLFSSL_ASYNC_CRYPT)
  13093. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13094. #endif
  13095. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13096. if (ret != 0)
  13097. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13098. if (cipher != NULL) {
  13099. if (XMEMCMP(cipher, resultC, (unsigned long)cipherSz))
  13100. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13101. }
  13102. if (XMEMCMP(tag, resultT, tagSz))
  13103. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13104. #endif
  13105. #ifdef HAVE_AES_DECRYPT
  13106. ret = wc_AesGcmSetKey(dec, key, (word32)keySz);
  13107. if (ret != 0)
  13108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13109. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz,
  13110. iv, (word32)ivSz, resultT, (word32)tagSz, aad, (word32)aadSz);
  13111. #if defined(WOLFSSL_ASYNC_CRYPT)
  13112. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13113. #endif
  13114. if (ret != 0)
  13115. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13116. if (plain != NULL) {
  13117. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13118. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13119. }
  13120. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13121. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13122. ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz,
  13123. iv, ivSz, resultT, tagSz, aad, aadSz);
  13124. #if defined(WOLFSSL_ASYNC_CRYPT)
  13125. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13126. #endif
  13127. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13128. if (ret != 0)
  13129. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13130. if (plain != NULL) {
  13131. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13132. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13133. }
  13134. #endif
  13135. #endif /* HAVE_AES_DECRYPT */
  13136. ret = 0;
  13137. out:
  13138. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13139. wc_AesDelete(enc, &enc);
  13140. wc_AesDelete(dec, &dec);
  13141. #else
  13142. wc_AesFree(enc);
  13143. wc_AesFree(dec);
  13144. #endif
  13145. return ret;
  13146. }
  13147. #endif
  13148. /* tests that only use 12 byte IV and 16 or less byte AAD
  13149. * test vectors are from NIST SP 800-38D
  13150. * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES*/
  13151. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void)
  13152. {
  13153. #ifdef WOLFSSL_AES_128
  13154. byte key1[] = {
  13155. 0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62,
  13156. 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc
  13157. };
  13158. byte iv1[] = {
  13159. 0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa,
  13160. 0xe4, 0xed, 0x2f, 0x6d
  13161. };
  13162. ALIGN64 byte plain1[] = {
  13163. 0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad,
  13164. 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01,
  13165. 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac,
  13166. 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01
  13167. };
  13168. byte aad1[] = {
  13169. 0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73,
  13170. 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1
  13171. };
  13172. ALIGN64 byte cipher1[] = {
  13173. 0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d,
  13174. 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d,
  13175. 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46,
  13176. 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb
  13177. };
  13178. byte tag1[] = {
  13179. 0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7,
  13180. 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2
  13181. };
  13182. byte key2[] = {
  13183. 0x01, 0x6d, 0xbb, 0x38, 0xda, 0xa7, 0x6d, 0xfe,
  13184. 0x7d, 0xa3, 0x84, 0xeb, 0xf1, 0x24, 0x03, 0x64
  13185. };
  13186. byte iv2[] = {
  13187. 0x07, 0x93, 0xef, 0x3a, 0xda, 0x78, 0x2f, 0x78,
  13188. 0xc9, 0x8a, 0xff, 0xe3
  13189. };
  13190. ALIGN64 byte plain2[] = {
  13191. 0x4b, 0x34, 0xa9, 0xec, 0x57, 0x63, 0x52, 0x4b,
  13192. 0x19, 0x1d, 0x56, 0x16, 0xc5, 0x47, 0xf6, 0xb7
  13193. };
  13194. ALIGN64 byte cipher2[] = {
  13195. 0x60, 0x9a, 0xa3, 0xf4, 0x54, 0x1b, 0xc0, 0xfe,
  13196. 0x99, 0x31, 0xda, 0xad, 0x2e, 0xe1, 0x5d, 0x0c
  13197. };
  13198. byte tag2[] = {
  13199. 0x33, 0xaf, 0xec, 0x59, 0xc4, 0x5b, 0xaf, 0x68,
  13200. 0x9a, 0x5e, 0x1b, 0x13, 0xae, 0x42, 0x36, 0x19
  13201. };
  13202. byte key3[] = {
  13203. 0xb0, 0x1e, 0x45, 0xcc, 0x30, 0x88, 0xaa, 0xba,
  13204. 0x9f, 0xa4, 0x3d, 0x81, 0xd4, 0x81, 0x82, 0x3f
  13205. };
  13206. byte iv3[] = {
  13207. 0x5a, 0x2c, 0x4a, 0x66, 0x46, 0x87, 0x13, 0x45,
  13208. 0x6a, 0x4b, 0xd5, 0xe1
  13209. };
  13210. byte tag3[] = {
  13211. 0x01, 0x42, 0x80, 0xf9, 0x44, 0xf5, 0x3c, 0x68,
  13212. 0x11, 0x64, 0xb2, 0xff
  13213. };
  13214. wc_test_ret_t ret;
  13215. WOLFSSL_ENTER("aesgcm_default_test");
  13216. ret = aesgcm_default_test_helper(key1, sizeof(key1), iv1, sizeof(iv1),
  13217. plain1, sizeof(plain1), cipher1, sizeof(cipher1),
  13218. aad1, sizeof(aad1), tag1, sizeof(tag1));
  13219. if (ret != 0) {
  13220. return ret;
  13221. }
  13222. ret = aesgcm_default_test_helper(key2, sizeof(key2), iv2, sizeof(iv2),
  13223. plain2, sizeof(plain2), cipher2, sizeof(cipher2),
  13224. NULL, 0, tag2, sizeof(tag2));
  13225. if (ret != 0) {
  13226. return ret;
  13227. }
  13228. ret = aesgcm_default_test_helper(key3, sizeof(key3), iv3, sizeof(iv3),
  13229. NULL, 0, NULL, 0,
  13230. NULL, 0, tag3, sizeof(tag3));
  13231. if (ret != 0) {
  13232. return ret;
  13233. }
  13234. #endif
  13235. return 0;
  13236. }
  13237. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
  13238. {
  13239. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13240. Aes *enc = NULL;
  13241. Aes *dec = NULL;
  13242. #else
  13243. Aes enc[1];
  13244. Aes dec[1];
  13245. #endif
  13246. /*
  13247. * This is Test Case 16 from the document Galois/
  13248. * Counter Mode of Operation (GCM) by McGrew and
  13249. * Viega.
  13250. */
  13251. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  13252. {
  13253. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  13254. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  13255. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  13256. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  13257. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  13258. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  13259. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  13260. 0xba, 0x63, 0x7b, 0x39
  13261. };
  13262. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  13263. {
  13264. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13265. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13266. 0xab, 0xad, 0xda, 0xd2
  13267. };
  13268. #ifdef WOLFSSL_AES_256
  13269. #ifdef HAVE_RENESAS_SYNC
  13270. const byte *k1 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  13271. int k1Sz = (int)(256/8);
  13272. #else
  13273. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13274. {
  13275. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13276. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13277. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13278. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  13279. };
  13280. int k1Sz = (int)sizeof(k1);
  13281. #endif
  13282. #endif /* WOLFSSL_AES_256 */
  13283. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13284. {
  13285. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  13286. 0xde, 0xca, 0xf8, 0x88
  13287. };
  13288. #if defined(WOLFSSL_AES_256) || defined(WOLFSSL_AES_192)
  13289. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  13290. {
  13291. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  13292. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  13293. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  13294. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  13295. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  13296. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  13297. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  13298. 0xbc, 0xc9, 0xf6, 0x62
  13299. };
  13300. #endif /* WOLFSSL_AES_256 || WOLFSSL_AES_192 */
  13301. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13302. {
  13303. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  13304. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  13305. };
  13306. /* FIPS, QAT and PIC32MZ HW Crypto only support 12-byte IV */
  13307. #if !defined(HAVE_FIPS) && \
  13308. !defined(WOLFSSL_PIC32MZ_CRYPT) && \
  13309. !defined(FREESCALE_LTC) && !defined(FREESCALE_MMCAU) && \
  13310. !defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13311. !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_AES) && \
  13312. !(defined(WOLF_CRYPTO_CB) && \
  13313. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  13314. #define ENABLE_NON_12BYTE_IV_TEST
  13315. #ifdef WOLFSSL_AES_192
  13316. /* Test Case 12, uses same plaintext and AAD data. */
  13317. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13318. {
  13319. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13320. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13321. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  13322. };
  13323. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13324. {
  13325. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  13326. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  13327. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  13328. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  13329. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  13330. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  13331. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  13332. 0xa6, 0x37, 0xb3, 0x9b
  13333. };
  13334. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  13335. {
  13336. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  13337. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  13338. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  13339. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  13340. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  13341. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  13342. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  13343. 0xe9, 0xb7, 0x37, 0x3b
  13344. };
  13345. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13346. {
  13347. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  13348. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  13349. };
  13350. #endif /* WOLFSSL_AES_192 */
  13351. #ifdef WOLFSSL_AES_128
  13352. /* The following is an interesting test case from the example
  13353. * FIPS test vectors for AES-GCM. IVlen = 1 byte */
  13354. WOLFSSL_SMALL_STACK_STATIC const byte p3[] =
  13355. {
  13356. 0x57, 0xce, 0x45, 0x1f, 0xa5, 0xe2, 0x35, 0xa5,
  13357. 0x8e, 0x1a, 0xa2, 0x3b, 0x77, 0xcb, 0xaf, 0xe2
  13358. };
  13359. #ifdef HAVE_RENESAS_SYNC
  13360. const byte *k3 =
  13361. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  13362. int k3Sz = (int)(128/8);
  13363. #else
  13364. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  13365. {
  13366. 0xbb, 0x01, 0xd7, 0x03, 0x81, 0x1c, 0x10, 0x1a,
  13367. 0x35, 0xe0, 0xff, 0xd2, 0x91, 0xba, 0xf2, 0x4b
  13368. };
  13369. int k3Sz = (int)sizeof(k3);
  13370. #endif
  13371. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  13372. {
  13373. 0xca
  13374. };
  13375. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  13376. {
  13377. 0x6b, 0x5f, 0xb3, 0x9d, 0xc1, 0xc5, 0x7a, 0x4f,
  13378. 0xf3, 0x51, 0x4d, 0xc2, 0xd5, 0xf0, 0xd0, 0x07
  13379. };
  13380. WOLFSSL_SMALL_STACK_STATIC const byte a3[] =
  13381. {
  13382. 0x40, 0xfc, 0xdc, 0xd7, 0x4a, 0xd7, 0x8b, 0xf1,
  13383. 0x3e, 0x7c, 0x60, 0x55, 0x50, 0x51, 0xdd, 0x54
  13384. };
  13385. WOLFSSL_SMALL_STACK_STATIC const byte t3[] =
  13386. {
  13387. 0x06, 0x90, 0xed, 0x01, 0x34, 0xdd, 0xc6, 0x95,
  13388. 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
  13389. };
  13390. #endif /* WOLFSSL_AES_128 */
  13391. #ifdef WOLFSSL_AES_256
  13392. int ivlen;
  13393. #endif
  13394. #endif
  13395. byte resultT[sizeof(t1) + AES_BLOCK_SIZE];
  13396. byte resultP[sizeof(p) + AES_BLOCK_SIZE];
  13397. byte resultC[sizeof(p) + AES_BLOCK_SIZE];
  13398. wc_test_ret_t ret = 0;
  13399. int alen = 0;
  13400. int plen = 0;
  13401. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13402. byte buf[sizeof(p) + AES_BLOCK_SIZE];
  13403. byte bufA[sizeof(a) + 1];
  13404. byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13405. #endif
  13406. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM)
  13407. #if !defined(BENCH_AESGCM_LARGE)
  13408. #define BENCH_AESGCM_LARGE 1024
  13409. #endif
  13410. #ifndef WOLFSSL_NO_MALLOC
  13411. byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13412. byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13413. byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13414. (void)alen;
  13415. (void)plen;
  13416. if ((! large_input) || (! large_output) || (! large_outdec))
  13417. ERROR_OUT(MEMORY_E, out);
  13418. #else
  13419. byte large_input[BENCH_AESGCM_LARGE];
  13420. byte large_output[BENCH_AESGCM_LARGE + AES_BLOCK_SIZE];
  13421. byte large_outdec[BENCH_AESGCM_LARGE];
  13422. #endif
  13423. XMEMSET(large_input, 0, BENCH_AESGCM_LARGE);
  13424. XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + AES_BLOCK_SIZE);
  13425. XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE);
  13426. #endif
  13427. WOLFSSL_ENTER("aesgcm_test");
  13428. XMEMSET(resultT, 0, sizeof(resultT));
  13429. XMEMSET(resultC, 0, sizeof(resultC));
  13430. XMEMSET(resultP, 0, sizeof(resultP));
  13431. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13432. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13433. if (enc == NULL)
  13434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13435. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13436. if (dec == NULL)
  13437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13438. #else
  13439. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13440. if (ret != 0)
  13441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13442. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13443. if (ret != 0)
  13444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13445. #endif
  13446. #ifdef WOLFSSL_AES_256
  13447. ret = wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13448. if (ret != 0)
  13449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13450. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13451. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13452. resultT, sizeof(t1), a, sizeof(a));
  13453. #if defined(WOLFSSL_ASYNC_CRYPT)
  13454. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13455. #endif
  13456. if (ret != 0)
  13457. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13458. #ifndef HAVE_RENESAS_SYNC
  13459. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13460. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13461. if (XMEMCMP(t1, resultT, sizeof(t1)))
  13462. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13463. #endif
  13464. #ifdef HAVE_AES_DECRYPT
  13465. ret = wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13466. if (ret != 0)
  13467. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13468. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
  13469. iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13470. #if defined(WOLFSSL_ASYNC_CRYPT)
  13471. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13472. #endif
  13473. if (ret != 0)
  13474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13475. if (XMEMCMP(p, resultP, sizeof(p)))
  13476. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13477. #endif /* HAVE_AES_DECRYPT */
  13478. /* Large buffer test */
  13479. #ifdef BENCH_AESGCM_LARGE
  13480. /* setup test buffer */
  13481. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13482. large_input[alen] = (byte)alen;
  13483. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13484. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13485. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13486. resultT, sizeof(t1), a, sizeof(a));
  13487. #if defined(WOLFSSL_ASYNC_CRYPT)
  13488. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13489. #endif
  13490. if (ret != 0)
  13491. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13492. #ifdef HAVE_AES_DECRYPT
  13493. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13494. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13495. sizeof(t1), a, sizeof(a));
  13496. #if defined(WOLFSSL_ASYNC_CRYPT)
  13497. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13498. #endif
  13499. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13500. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13501. if (ret != 0)
  13502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13503. #endif /* HAVE_AES_DECRYPT */
  13504. #endif /* BENCH_AESGCM_LARGE */
  13505. #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256)
  13506. /* Variable IV length test */
  13507. for (ivlen=1; ivlen<k1Sz; ivlen++) {
  13508. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13509. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1,
  13510. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13511. #if defined(WOLFSSL_ASYNC_CRYPT)
  13512. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13513. #endif
  13514. if (ret != 0)
  13515. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13516. #ifdef HAVE_AES_DECRYPT
  13517. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1,
  13518. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13519. #if defined(WOLFSSL_ASYNC_CRYPT)
  13520. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13521. #endif
  13522. if (ret != 0)
  13523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13524. #endif /* HAVE_AES_DECRYPT */
  13525. }
  13526. #endif
  13527. #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC))
  13528. /* Variable authenticated data length test */
  13529. for (alen=0; alen<(int)sizeof(p); alen++) {
  13530. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13531. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13532. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13533. #if defined(WOLFSSL_ASYNC_CRYPT)
  13534. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13535. #endif
  13536. if (ret != 0)
  13537. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13538. #ifdef HAVE_AES_DECRYPT
  13539. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13540. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13541. #if defined(WOLFSSL_ASYNC_CRYPT)
  13542. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13543. #endif
  13544. if (ret != 0)
  13545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13546. #endif /* HAVE_AES_DECRYPT */
  13547. }
  13548. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13549. if (! large_aad)
  13550. ERROR_OUT(MEMORY_E, out);
  13551. XMEMSET(large_aad, 0, 1024+16);
  13552. /* Variable authenticated data length test */
  13553. for (alen=0; alen<=1024; alen+=16) {
  13554. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13555. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13556. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13557. if (ret != 0)
  13558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13559. #ifdef HAVE_AES_DECRYPT
  13560. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13561. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13562. if (ret != 0)
  13563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13564. #endif /* HAVE_AES_DECRYPT */
  13565. }
  13566. /* Test unaligned memory of all potential arguments */
  13567. ret = wc_AesGcmSetKey(enc, k1, k1Sz);
  13568. if (ret != 0)
  13569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13570. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13571. XMEMCPY(&buf[1], p, sizeof(p));
  13572. XMEMCPY(&bufA[1], a, sizeof(a));
  13573. ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1),
  13574. &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13575. if (ret != 0)
  13576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13577. if (XMEMCMP(c1, &resultC[1], sizeof(c1)))
  13578. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13579. if (XMEMCMP(t1, &resultT[1], sizeof(t1)))
  13580. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13581. #ifdef HAVE_AES_DECRYPT
  13582. ret = wc_AesGcmSetKey(dec, k1, k1Sz);
  13583. if (ret != 0)
  13584. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13585. ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1),
  13586. iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13587. if (ret != 0)
  13588. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13589. if (XMEMCMP(p, &resultP[1], sizeof(p)))
  13590. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13591. #endif /* HAVE_AES_DECRYPT */
  13592. #endif /* Xilinx Versal */
  13593. #endif
  13594. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13595. #ifdef BENCH_AESGCM_LARGE
  13596. /* Variable plain text length test */
  13597. for (plen=1; plen<BENCH_AESGCM_LARGE; plen++) {
  13598. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13599. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13600. (word32)plen, iv1, sizeof(iv1), resultT,
  13601. sizeof(t1), a, sizeof(a));
  13602. #if defined(WOLFSSL_ASYNC_CRYPT)
  13603. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13604. #endif
  13605. if (ret != 0)
  13606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13607. #ifdef HAVE_AES_DECRYPT
  13608. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13609. (word32)plen, iv1, sizeof(iv1), resultT,
  13610. sizeof(t1), a, sizeof(a));
  13611. #if defined(WOLFSSL_ASYNC_CRYPT)
  13612. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13613. #endif
  13614. if (ret != 0)
  13615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13616. #endif /* HAVE_AES_DECRYPT */
  13617. }
  13618. #else /* BENCH_AESGCM_LARGE */
  13619. /* Variable plain text length test */
  13620. for (plen=1; plen<(int)sizeof(p); plen++) {
  13621. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13622. ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1,
  13623. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13624. #if defined(WOLFSSL_ASYNC_CRYPT)
  13625. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13626. #endif
  13627. if (ret != 0)
  13628. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13629. #ifdef HAVE_AES_DECRYPT
  13630. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1,
  13631. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13632. #if defined(WOLFSSL_ASYNC_CRYPT)
  13633. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13634. #endif
  13635. if (ret != 0)
  13636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13637. #endif /* HAVE_AES_DECRYPT */
  13638. }
  13639. #endif /* BENCH_AESGCM_LARGE */
  13640. #endif
  13641. #endif /* WOLFSSL_AES_256 */
  13642. /* test with IV != 12 bytes */
  13643. #ifdef ENABLE_NON_12BYTE_IV_TEST
  13644. XMEMSET(resultT, 0, sizeof(resultT));
  13645. XMEMSET(resultC, 0, sizeof(resultC));
  13646. XMEMSET(resultP, 0, sizeof(resultP));
  13647. #ifdef WOLFSSL_AES_192
  13648. wc_AesGcmSetKey(enc, k2, sizeof(k2));
  13649. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13650. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2),
  13651. resultT, sizeof(t1), a, sizeof(a));
  13652. #if defined(WOLFSSL_ASYNC_CRYPT)
  13653. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13654. #endif
  13655. if (ret != 0)
  13656. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13657. if (XMEMCMP(c2, resultC, sizeof(c2)))
  13658. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13659. if (XMEMCMP(t2, resultT, sizeof(t1)))
  13660. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13661. #ifdef HAVE_AES_DECRYPT
  13662. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1),
  13663. iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a));
  13664. #if defined(WOLFSSL_ASYNC_CRYPT)
  13665. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13666. #endif
  13667. if (ret != 0)
  13668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13669. if (XMEMCMP(p, resultP, sizeof(p)))
  13670. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13671. #endif /* HAVE_AES_DECRYPT */
  13672. /* Large buffer test */
  13673. #ifdef BENCH_AESGCM_LARGE
  13674. wc_AesGcmSetKey(enc, k2, (word32)sizeof(k2));
  13675. wc_AesGcmSetKey(dec, k2, (word32)sizeof(k2));
  13676. /* setup test buffer */
  13677. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13678. large_input[alen] = (byte)alen;
  13679. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13680. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13681. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13682. resultT, sizeof(t1), a, sizeof(a));
  13683. #if defined(WOLFSSL_ASYNC_CRYPT)
  13684. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13685. #endif
  13686. if (ret != 0)
  13687. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13688. #ifdef HAVE_AES_DECRYPT
  13689. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13690. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13691. sizeof(t1), a, sizeof(a));
  13692. #if defined(WOLFSSL_ASYNC_CRYPT)
  13693. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13694. #endif
  13695. if (ret != 0)
  13696. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13697. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13698. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13699. #endif /* HAVE_AES_DECRYPT */
  13700. #endif /* BENCH_AESGCM_LARGE */
  13701. XMEMSET(resultT, 0, sizeof(resultT));
  13702. XMEMSET(resultC, 0, sizeof(resultC));
  13703. XMEMSET(resultP, 0, sizeof(resultP));
  13704. #endif /* WOLFSSL_AES_192 */
  13705. #ifdef WOLFSSL_AES_128
  13706. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13707. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13708. ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3),
  13709. resultT, sizeof(t3), a3, sizeof(a3));
  13710. #if defined(WOLFSSL_ASYNC_CRYPT)
  13711. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13712. #endif
  13713. if (ret != 0)
  13714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13715. #ifndef HAVE_RENESAS_SYNC
  13716. if (XMEMCMP(c3, resultC, sizeof(c3)))
  13717. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13718. if (XMEMCMP(t3, resultT, sizeof(t3)))
  13719. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13720. #endif
  13721. #ifdef HAVE_AES_DECRYPT
  13722. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
  13723. iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3));
  13724. #if defined(WOLFSSL_ASYNC_CRYPT)
  13725. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13726. #endif
  13727. if (ret != 0)
  13728. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13729. if (XMEMCMP(p3, resultP, sizeof(p3)))
  13730. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13731. #endif /* HAVE_AES_DECRYPT */
  13732. /* Large buffer test */
  13733. #ifdef BENCH_AESGCM_LARGE
  13734. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13735. wc_AesGcmSetKey(dec, k3, (word32)k3Sz);
  13736. /* setup test buffer */
  13737. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13738. large_input[alen] = (byte)alen;
  13739. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13740. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13741. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13742. resultT, sizeof(t1), a, sizeof(a));
  13743. #if defined(WOLFSSL_ASYNC_CRYPT)
  13744. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13745. #endif
  13746. if (ret != 0)
  13747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13748. #ifdef HAVE_AES_DECRYPT
  13749. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13750. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13751. sizeof(t1), a, sizeof(a));
  13752. #if defined(WOLFSSL_ASYNC_CRYPT)
  13753. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13754. #endif
  13755. if (ret != 0)
  13756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13757. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13758. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13759. #endif /* HAVE_AES_DECRYPT */
  13760. #endif /* BENCH_AESGCM_LARGE */
  13761. #endif /* WOLFSSL_AES_128 */
  13762. #endif /* ENABLE_NON_12BYTE_IV_TEST */
  13763. #if defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13764. !defined(WOLFSSL_XILINX_CRYPT) && \
  13765. !(defined(WOLF_CRYPTO_CB) && \
  13766. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC))
  13767. XMEMSET(resultT, 0, sizeof(resultT));
  13768. XMEMSET(resultC, 0, sizeof(resultC));
  13769. XMEMSET(resultP, 0, sizeof(resultP));
  13770. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13771. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13772. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13773. resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13774. #if defined(WOLFSSL_ASYNC_CRYPT)
  13775. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13776. #endif
  13777. if (ret != 0)
  13778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13779. #ifndef HAVE_RENESAS_SYNC
  13780. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13781. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13782. if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1))
  13783. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13784. #endif
  13785. #ifdef HAVE_AES_DECRYPT
  13786. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
  13787. iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13788. #if defined(WOLFSSL_ASYNC_CRYPT)
  13789. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13790. #endif
  13791. if (ret != 0)
  13792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13793. if (XMEMCMP(p, resultP, sizeof(p)))
  13794. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13795. #endif /* HAVE_AES_DECRYPT */
  13796. #endif /* WOLFSSL_AES_256 */
  13797. #if !defined(HAVE_FIPS) || \
  13798. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  13799. /* Test encrypt with internally generated IV */
  13800. #if defined(WOLFSSL_AES_256) && !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST)) \
  13801. && !(defined(WOLF_CRYPTO_CB) && defined(HAVE_CAVIUM_OCTEON_SYNC))
  13802. {
  13803. WC_RNG rng;
  13804. byte randIV[12];
  13805. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13806. if (ret != 0)
  13807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13808. XMEMSET(randIV, 0, sizeof(randIV));
  13809. XMEMSET(resultT, 0, sizeof(resultT));
  13810. XMEMSET(resultC, 0, sizeof(resultC));
  13811. XMEMSET(resultP, 0, sizeof(resultP));
  13812. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13813. ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng);
  13814. if (ret != 0)
  13815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13816. ret = wc_AesGcmEncrypt_ex(enc,
  13817. resultC, p, sizeof(p),
  13818. randIV, sizeof(randIV),
  13819. resultT, sizeof(t1),
  13820. a, sizeof(a));
  13821. #if defined(WOLFSSL_ASYNC_CRYPT)
  13822. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13823. #endif
  13824. if (ret != 0)
  13825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13826. /* Check the IV has been set. */
  13827. {
  13828. word32 i, ivSum = 0;
  13829. for (i = 0; i < sizeof(randIV); i++)
  13830. ivSum += randIV[i];
  13831. if (ivSum == 0)
  13832. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13833. }
  13834. #ifdef HAVE_AES_DECRYPT
  13835. wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13836. ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng);
  13837. if (ret != 0)
  13838. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13839. ret = wc_AesGcmDecrypt(dec,
  13840. resultP, resultC, sizeof(c1),
  13841. randIV, sizeof(randIV),
  13842. resultT, sizeof(t1),
  13843. a, sizeof(a));
  13844. #if defined(WOLFSSL_ASYNC_CRYPT)
  13845. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13846. #endif
  13847. if (ret != 0)
  13848. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13849. if (XMEMCMP(p, resultP, sizeof(p)))
  13850. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13851. #endif /* HAVE_AES_DECRYPT */
  13852. wc_FreeRng(&rng);
  13853. }
  13854. #endif /* WOLFSSL_AES_256 && !(WC_NO_RNG || HAVE_SELFTEST) */
  13855. #endif /* HAVE_FIPS_VERSION >= 2 */
  13856. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13857. #ifdef WOLFSSL_AES_256
  13858. #ifdef WOLFSSL_AESGCM_STREAM
  13859. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13860. if (ret != 0)
  13861. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13862. ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a));
  13863. if (ret != 0)
  13864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13865. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13866. if (ret != 0)
  13867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13868. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13869. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13870. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13871. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13872. #ifdef HAVE_AES_DECRYPT
  13873. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13874. if (ret != 0)
  13875. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13876. ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
  13877. if (ret != 0)
  13878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13879. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13880. if (ret != 0)
  13881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13882. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13883. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13884. #endif
  13885. /* alen is the size to pass in with each update. */
  13886. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13887. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13888. if (ret != 0)
  13889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13890. /* plen is the offset into AAD to update with. */
  13891. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13892. int len = sizeof(a) - plen;
  13893. if (len > alen) len = alen;
  13894. ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13895. if (ret != 0)
  13896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13897. }
  13898. /* plen is the offset into plaintext to update with. */
  13899. for (plen = 0; plen < (int)sizeof(p); plen += alen) {
  13900. int len = sizeof(p) - plen;
  13901. if (len > alen) len = alen;
  13902. ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, (word32)len,
  13903. NULL, 0);
  13904. if (ret != 0)
  13905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13906. }
  13907. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13908. if (ret != 0)
  13909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13910. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13911. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13912. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13913. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13914. }
  13915. #ifdef HAVE_AES_DECRYPT
  13916. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13917. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13918. if (ret != 0)
  13919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13920. /* plen is the offset into AAD to update with. */
  13921. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13922. int len = sizeof(a) - plen;
  13923. if (len > alen) len = alen;
  13924. ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13925. if (ret != 0)
  13926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13927. }
  13928. /* plen is the offset into cipher text to update with. */
  13929. for (plen = 0; plen < (int)sizeof(c1); plen += alen) {
  13930. int len = sizeof(c1) - plen;
  13931. if (len > alen) len = alen;
  13932. ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, (word32)len,
  13933. NULL, 0);
  13934. if (ret != 0)
  13935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13936. }
  13937. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13938. if (ret != 0)
  13939. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13940. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13941. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13942. }
  13943. #endif /* HAVE_AES_DECRYPT */
  13944. #ifdef BENCH_AESGCM_LARGE
  13945. /* setup test buffer */
  13946. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13947. if (ret != 0)
  13948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13949. ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input,
  13950. BENCH_AESGCM_LARGE, a, sizeof(a));
  13951. if (ret != 0)
  13952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13953. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13954. if (ret != 0)
  13955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13956. #ifdef HAVE_AES_DECRYPT
  13957. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13958. if (ret != 0)
  13959. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13960. ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output,
  13961. BENCH_AESGCM_LARGE, a, sizeof(a));
  13962. if (ret != 0)
  13963. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13964. ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1));
  13965. if (ret != 0)
  13966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13967. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13968. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13969. #endif /* HAVE_AES_DECRYPT */
  13970. #endif /* BENCH_AESGCM_LARGE */
  13971. #endif /* WOLFSSL_AESGCM_STREAM */
  13972. #endif /* WOLFSSL_AES_256 */
  13973. #endif /* !WOLFSSL_AFALG_XILINX_AES && !WOLFSSL_XILINX_CRYPT */
  13974. ret = 0;
  13975. out:
  13976. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  13977. !defined(WOLFSSL_NO_MALLOC)
  13978. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13979. XFREE(large_output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13980. XFREE(large_outdec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13981. #endif
  13982. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13983. wc_AesDelete(enc, &enc);
  13984. wc_AesDelete(dec, &dec);
  13985. #else
  13986. wc_AesFree(enc);
  13987. wc_AesFree(dec);
  13988. #endif
  13989. return ret;
  13990. }
  13991. #ifdef WOLFSSL_AES_128
  13992. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void)
  13993. {
  13994. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13995. Gmac *gmac;
  13996. #else
  13997. Gmac gmac[1];
  13998. #endif
  13999. wc_test_ret_t ret;
  14000. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14001. {
  14002. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  14003. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  14004. };
  14005. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  14006. {
  14007. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  14008. 0xe2, 0x8c, 0x8f, 0x16
  14009. };
  14010. WOLFSSL_SMALL_STACK_STATIC const byte a1[] =
  14011. {
  14012. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  14013. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  14014. };
  14015. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  14016. {
  14017. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  14018. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14019. };
  14020. #if (!defined(HAVE_FIPS) || \
  14021. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
  14022. /* FIPS builds only allow 16-byte auth tags. */
  14023. /* This sample uses a 15-byte auth tag. */
  14024. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14025. {
  14026. 0x40, 0xf7, 0xec, 0xb2, 0x52, 0x6d, 0xaa, 0xd4,
  14027. 0x74, 0x25, 0x1d, 0xf4, 0x88, 0x9e, 0xf6, 0x5b
  14028. };
  14029. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  14030. {
  14031. 0xee, 0x9c, 0x6e, 0x06, 0x15, 0x45, 0x45, 0x03,
  14032. 0x1a, 0x60, 0x24, 0xa7
  14033. };
  14034. WOLFSSL_SMALL_STACK_STATIC const byte a2[] =
  14035. {
  14036. 0x94, 0x81, 0x2c, 0x87, 0x07, 0x4e, 0x15, 0x18,
  14037. 0x34, 0xb8, 0x35, 0xaf, 0x1c, 0xa5, 0x7e, 0x56
  14038. };
  14039. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  14040. {
  14041. 0xc6, 0x81, 0x79, 0x8e, 0x3d, 0xda, 0xb0, 0x9f,
  14042. 0x8d, 0x83, 0xb0, 0xbb, 0x14, 0xb6, 0x91
  14043. };
  14044. #endif
  14045. byte tag[16];
  14046. WOLFSSL_ENTER("gmac_test");
  14047. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14048. if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  14049. return WC_TEST_RET_ENC_ERRNO;
  14050. #endif
  14051. XMEMSET(gmac, 0, sizeof *gmac); /* clear context */
  14052. (void)wc_AesInit(&gmac->aes, HEAP_HINT, INVALID_DEVID); /* Make sure devId updated */
  14053. XMEMSET(tag, 0, sizeof(tag));
  14054. wc_GmacSetKey(gmac, k1, sizeof(k1));
  14055. wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1));
  14056. if (XMEMCMP(t1, tag, sizeof(t1)) != 0)
  14057. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14058. #if (!defined(HAVE_FIPS) || \
  14059. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) )
  14060. XMEMSET(tag, 0, sizeof(tag));
  14061. wc_GmacSetKey(gmac, k2, sizeof(k2));
  14062. wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2));
  14063. if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
  14064. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14065. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
  14066. {
  14067. WOLFSSL_SMALL_STACK_STATIC const byte badT[] =
  14068. {
  14069. 0xde, 0xad, 0xbe, 0xef, 0x17, 0x2e, 0xd0, 0x43,
  14070. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14071. };
  14072. WC_RNG rng;
  14073. byte iv[12];
  14074. #ifndef HAVE_FIPS
  14075. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14076. if (ret != 0)
  14077. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14078. #else
  14079. ret = wc_InitRng(&rng);
  14080. if (ret != 0)
  14081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14082. #endif
  14083. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14084. t1, sizeof(t1));
  14085. if (ret != 0)
  14086. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14087. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14088. badT, sizeof(badT));
  14089. if (ret != WC_NO_ERR_TRACE(AES_GCM_AUTH_E))
  14090. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14091. ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2),
  14092. t2, sizeof(t2));
  14093. if (ret != 0)
  14094. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14095. XMEMSET(tag, 0, sizeof(tag));
  14096. XMEMSET(iv, 0, sizeof(iv));
  14097. ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14098. tag, sizeof(tag), &rng);
  14099. if (ret != 0)
  14100. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14101. ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14102. tag, sizeof(tag));
  14103. if (ret != 0)
  14104. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14105. wc_FreeRng(&rng);
  14106. }
  14107. #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
  14108. #endif /* HAVE_FIPS */
  14109. ret = 0;
  14110. out:
  14111. wc_AesFree(&gmac->aes);
  14112. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14113. XFREE(gmac, HEAP_HINT, DYNAMIC_TYPE_AES);
  14114. #endif
  14115. return ret;
  14116. }
  14117. #endif /* WOLFSSL_AES_128 */
  14118. #endif /* HAVE_AESGCM */
  14119. #if defined(HAVE_AESCCM)
  14120. #if defined(WOLFSSL_AES_256)
  14121. static wc_test_ret_t aesccm_256_test(void)
  14122. {
  14123. wc_test_ret_t ret = 0;
  14124. /* Test vectors from NIST AES CCM 256-bit CAST Example #1 */
  14125. WOLFSSL_SMALL_STACK_STATIC const byte in_key[32] = {
  14126. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14127. 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  14128. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14129. 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  14130. };
  14131. WOLFSSL_SMALL_STACK_STATIC const byte in_nonce[7] = {
  14132. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
  14133. WOLFSSL_SMALL_STACK_STATIC const byte in_auth[8] = {
  14134. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  14135. WOLFSSL_SMALL_STACK_STATIC const byte in_plaintext[4] = {
  14136. 0x20, 0x21, 0x22, 0x23};
  14137. WOLFSSL_SMALL_STACK_STATIC const byte exp_ciphertext[4] = {
  14138. 0x8A, 0xB1, 0xA8, 0x74};
  14139. WOLFSSL_SMALL_STACK_STATIC const byte exp_tag[4] = {
  14140. 0x95, 0xFC, 0x08, 0x20};
  14141. byte output[sizeof(in_plaintext)];
  14142. byte atag[sizeof(exp_tag)];
  14143. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14144. Aes* aes = wc_AesNew(HEAP_HINT, devId, &ret);
  14145. if (aes == NULL) {
  14146. ret = WC_TEST_RET_ENC_EC(ret);
  14147. }
  14148. #else
  14149. Aes aes[1];
  14150. ret = wc_AesInit(aes, HEAP_HINT, devId);
  14151. #endif
  14152. if (ret == 0) {
  14153. ret = wc_AesCcmSetKey(aes, in_key, sizeof(in_key));
  14154. }
  14155. if (ret == 0) {
  14156. ret = wc_AesCcmEncrypt(aes, output, in_plaintext, sizeof(in_plaintext),
  14157. in_nonce, sizeof(in_nonce),
  14158. atag, sizeof(atag),
  14159. in_auth, sizeof(in_auth));
  14160. }
  14161. /* Verify we produce the proper ciphertext and tag */
  14162. if (ret == 0 &&
  14163. (XMEMCMP(output, exp_ciphertext, sizeof(output)) ||
  14164. XMEMCMP(atag, exp_tag, sizeof(atag)))) {
  14165. ret = WC_TEST_RET_ENC_NC;
  14166. }
  14167. #ifdef HAVE_AES_DECRYPT
  14168. if (ret == 0) {
  14169. /* decrypt inline */
  14170. ret = wc_AesCcmDecrypt(aes, output, output, sizeof(output),
  14171. in_nonce, sizeof(in_nonce),
  14172. atag, sizeof(atag),
  14173. in_auth, sizeof(in_auth));
  14174. }
  14175. /* Verify decryption was successful */
  14176. if (ret == 0 &&
  14177. XMEMCMP(output, in_plaintext, sizeof(output))) {
  14178. ret = WC_TEST_RET_ENC_NC;
  14179. }
  14180. #endif
  14181. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14182. wc_AesDelete(aes, &aes);
  14183. #else
  14184. wc_AesFree(aes);
  14185. #endif
  14186. return ret;
  14187. }
  14188. #endif /* WOLFSSL_AES_256 */
  14189. #if defined(WOLFSSL_AES_128)
  14190. static wc_test_ret_t aesccm_128_test(void)
  14191. {
  14192. wc_test_ret_t ret;
  14193. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14194. Aes *enc = NULL;
  14195. #else
  14196. Aes enc[1];
  14197. #endif
  14198. /* key */
  14199. WOLFSSL_SMALL_STACK_STATIC const byte k[] =
  14200. {
  14201. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  14202. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  14203. };
  14204. /* nonce */
  14205. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  14206. {
  14207. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  14208. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  14209. };
  14210. /* plaintext */
  14211. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  14212. {
  14213. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14214. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14215. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  14216. };
  14217. /* plaintext - long */
  14218. WOLFSSL_SMALL_STACK_STATIC const byte pl[] =
  14219. {
  14220. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14221. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14222. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  14223. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14224. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  14225. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  14226. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  14227. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14228. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  14229. 0x50
  14230. };
  14231. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  14232. {
  14233. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14234. };
  14235. /* ciphertext */
  14236. WOLFSSL_SMALL_STACK_STATIC const byte c[] =
  14237. {
  14238. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14239. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14240. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  14241. };
  14242. /* tag - authentication */
  14243. WOLFSSL_SMALL_STACK_STATIC const byte t[] =
  14244. {
  14245. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  14246. };
  14247. /* ciphertext - long */
  14248. WOLFSSL_SMALL_STACK_STATIC const byte cl[] =
  14249. {
  14250. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14251. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14252. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0xe0,
  14253. 0x44, 0x2d, 0xbe, 0x25, 0xfa, 0x48, 0x2b, 0xa8,
  14254. 0x36, 0x0b, 0xbf, 0x01, 0xc0, 0x12, 0x45, 0xa4,
  14255. 0x82, 0x9f, 0x20, 0x6c, 0xc3, 0xd6, 0xae, 0x5b,
  14256. 0x54, 0x8d, 0xd0, 0xb1, 0x69, 0x2c, 0xec, 0x5e,
  14257. 0x95, 0xa5, 0x6b, 0x48, 0xc3, 0xc6, 0xc8, 0x9e,
  14258. 0xc7, 0x92, 0x98, 0x9d, 0x26, 0x7d, 0x2a, 0x10,
  14259. 0x0b
  14260. };
  14261. /* tag - authentication - long */
  14262. WOLFSSL_SMALL_STACK_STATIC const byte tl[] =
  14263. {
  14264. 0x89, 0xd8, 0xd2, 0x02, 0xc5, 0xcf, 0xae, 0xf4
  14265. };
  14266. /* tag - authentication - empty plaintext */
  14267. WOLFSSL_SMALL_STACK_STATIC const byte t_empty[] =
  14268. {
  14269. 0xe4, 0x28, 0x8a, 0xc3, 0x78, 0x00, 0x0f, 0xf5
  14270. };
  14271. byte t2[sizeof(t)];
  14272. byte p2[sizeof(p)];
  14273. byte c2[sizeof(c)];
  14274. byte iv2[sizeof(iv)];
  14275. byte pl2[sizeof(pl)];
  14276. byte cl2[sizeof(cl)];
  14277. byte tl2[sizeof(tl)];
  14278. byte t_empty2[sizeof(t_empty)];
  14279. XMEMSET(t2, 0, sizeof(t2));
  14280. XMEMSET(c2, 0, sizeof(c2));
  14281. XMEMSET(p2, 0, sizeof(p2));
  14282. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14283. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  14284. if (enc == NULL)
  14285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14286. #else
  14287. XMEMSET(enc, 0, sizeof(Aes));
  14288. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14289. if (ret != 0)
  14290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14291. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  14292. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14293. if (ret != 0)
  14294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14295. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14296. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14297. t2, sizeof(t2), a, sizeof(a));
  14298. if (ret != 0)
  14299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14300. if (XMEMCMP(c, c2, sizeof(c2)))
  14301. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14302. if (XMEMCMP(t, t2, sizeof(t2)))
  14303. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14304. #ifdef HAVE_AES_DECRYPT
  14305. ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv),
  14306. t2, sizeof(t2), a, sizeof(a));
  14307. if (ret != 0)
  14308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14309. if (XMEMCMP(p, p2, sizeof(p2)))
  14310. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14311. /* Test the authentication failure */
  14312. t2[0]++; /* Corrupt the authentication tag. */
  14313. ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv),
  14314. t2, sizeof(t2), a, sizeof(a));
  14315. if (ret == 0)
  14316. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14317. /* Clear c2 to compare against p2. p2 should be set to zero in case of
  14318. * authentication fail. */
  14319. XMEMSET(c2, 0, sizeof(c2));
  14320. if (XMEMCMP(p2, c2, sizeof(p2)))
  14321. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14322. #endif
  14323. XMEMSET(t2, 0, sizeof(t2));
  14324. XMEMSET(c2, 0, sizeof(c2));
  14325. XMEMSET(p2, 0, sizeof(p2));
  14326. XMEMSET(iv2, 0, sizeof(iv2));
  14327. wc_AesFree(enc);
  14328. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14329. if (ret != 0)
  14330. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14331. #ifndef HAVE_SELFTEST
  14332. /* selftest build does not have wc_AesCcmSetNonce() or
  14333. * wc_AesCcmEncrypt_ex() */
  14334. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14335. if (ret != 0)
  14336. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14337. ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv));
  14338. if (ret != 0)
  14339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14340. ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2),
  14341. t2, sizeof(t2), a, sizeof(a));
  14342. if (ret != 0)
  14343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14344. if (XMEMCMP(iv, iv2, sizeof(iv2)))
  14345. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14346. if (XMEMCMP(c, c2, sizeof(c2)))
  14347. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14348. if (XMEMCMP(t, t2, sizeof(t2)))
  14349. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14350. #endif
  14351. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  14352. /* test fail on invalid IV sizes */
  14353. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14354. if (ret != 0)
  14355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14356. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14357. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14358. t2, 1, a, sizeof(a));
  14359. if (ret == 0) {
  14360. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14361. }
  14362. #endif
  14363. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14364. ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv),
  14365. tl2, sizeof(tl2), a, sizeof(a));
  14366. if (ret != 0)
  14367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14368. if (XMEMCMP(cl, cl2, sizeof(cl2)))
  14369. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14370. if (XMEMCMP(tl, tl2, sizeof(tl2)))
  14371. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14372. #ifdef HAVE_AES_DECRYPT
  14373. ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv),
  14374. tl2, sizeof(tl2), a, sizeof(a));
  14375. if (ret != 0)
  14376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14377. if (XMEMCMP(pl, pl2, sizeof(pl2)))
  14378. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14379. #endif
  14380. /* test empty message as null input or output with nonzero inSz. */
  14381. ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */,
  14382. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14383. a, sizeof(a));
  14384. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14385. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14386. ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14387. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14388. a, sizeof(a));
  14389. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14390. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14391. #ifdef HAVE_AES_DECRYPT
  14392. ret = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */,
  14393. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14394. sizeof(a));
  14395. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14396. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14397. ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14398. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14399. sizeof(a));
  14400. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14402. #endif
  14403. /* test empty message as null input and output with zero inSz --
  14404. * must either succeed, or fail early with BAD_FUNC_ARG.
  14405. */
  14406. ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */,
  14407. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14408. a, sizeof(a));
  14409. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  14410. if (ret != 0)
  14411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14412. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14413. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14414. #ifdef HAVE_AES_DECRYPT
  14415. ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */,
  14416. 0 /* inSz */, iv, sizeof(iv), t_empty2,
  14417. sizeof(t_empty2), a, sizeof(a));
  14418. if (ret != 0)
  14419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14420. #endif
  14421. }
  14422. /* test empty message as zero-length string -- must work. */
  14423. ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv,
  14424. sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14425. sizeof(a));
  14426. if (ret != 0)
  14427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14428. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14429. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14430. #ifdef HAVE_AES_DECRYPT
  14431. ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */,
  14432. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14433. sizeof(a));
  14434. if (ret != 0)
  14435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14436. #endif
  14437. ret = 0;
  14438. out:
  14439. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14440. wc_AesDelete(enc, &enc);
  14441. #else
  14442. wc_AesFree(enc);
  14443. #endif
  14444. return ret;
  14445. }
  14446. #endif /* WOLFSSL_AES_128 */
  14447. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void)
  14448. {
  14449. wc_test_ret_t ret = 0;
  14450. WOLFSSL_ENTER("aesccm_test");
  14451. #ifdef WOLFSSL_AES_128
  14452. if (ret == 0)
  14453. ret = aesccm_128_test();
  14454. #endif
  14455. #ifdef WOLFSSL_AES_256
  14456. if (ret == 0)
  14457. ret = aesccm_256_test();
  14458. #endif
  14459. return ret;
  14460. }
  14461. #endif /* HAVE_AESCCM */
  14462. #if defined(WOLFSSL_AES_EAX) && \
  14463. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14464. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
  14465. {
  14466. typedef struct {
  14467. byte key[AES_256_KEY_SIZE];
  14468. int key_length;
  14469. byte iv[AES_BLOCK_SIZE];
  14470. int iv_length;
  14471. byte aad[AES_BLOCK_SIZE * 2];
  14472. int aad_length;
  14473. byte msg[AES_BLOCK_SIZE * 2];
  14474. int msg_length;
  14475. byte ct[AES_BLOCK_SIZE * 2];
  14476. int ct_length;
  14477. byte tag[AES_BLOCK_SIZE];
  14478. int tag_length;
  14479. int valid;
  14480. } AadVector;
  14481. /* A small selection of Google wycheproof vectors that use vectors
  14482. * from the original paper: eprint.iacr.org/2003/069
  14483. * https://github.com/google/wycheproof/blob/master/testvectors/aes_eax_test.json
  14484. */
  14485. WOLFSSL_SMALL_STACK_STATIC const AadVector vectors[] = {
  14486. /* Vector from paper - empty message with auth data */
  14487. {
  14488. /* key, key length */
  14489. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  14490. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  14491. /* iv, iv length */
  14492. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  14493. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  14494. /* aad, aad length */
  14495. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  14496. /* msg, msg length */
  14497. {0}, 0,
  14498. /* ct, ct length */
  14499. {0}, 0,
  14500. /* tag, tag length */
  14501. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2,
  14502. 0x7b, 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  14503. /* valid */
  14504. 1,
  14505. },
  14506. /* Vector from paper - no auth data, valid auth tag */
  14507. {
  14508. /* key, key length */
  14509. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14510. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14511. /* iv , iv length */
  14512. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  14513. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  14514. /* aad, aad length */
  14515. {0}, 0,
  14516. /* msg, msg length */
  14517. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14518. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14519. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  14520. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  14521. /* ct, ct length */
  14522. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  14523. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  14524. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  14525. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  14526. /* tag, tag length */
  14527. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  14528. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  14529. /* valid */
  14530. 1,
  14531. },
  14532. /* Vector from paper - no auth data with invalid auth tag */
  14533. {
  14534. /* key, key length */
  14535. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14536. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14537. /* iv, iv length */
  14538. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14539. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  14540. /* aad, aad length */
  14541. {0}, 0,
  14542. /* msg, msg length */
  14543. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14544. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  14545. /* ct , ct length */
  14546. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  14547. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  14548. /* tag, tag length */
  14549. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  14550. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  14551. /* valid */
  14552. 0,
  14553. },
  14554. };
  14555. WOLFSSL_SMALL_STACK_STATIC byte ciphertext[sizeof(vectors[0].ct)];
  14556. WOLFSSL_SMALL_STACK_STATIC byte authtag[sizeof(vectors[0].tag)];
  14557. int i;
  14558. int len;
  14559. wc_test_ret_t ret;
  14560. WOLFSSL_ENTER("aes_eax_test");
  14561. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  14562. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14563. len = sizeof(authtag);
  14564. ret = wc_AesEaxEncryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14565. ciphertext,
  14566. vectors[i].msg, (word32)vectors[i].msg_length,
  14567. vectors[i].iv, (word32)vectors[i].iv_length,
  14568. authtag, (word32)len,
  14569. vectors[i].aad, (word32)vectors[i].aad_length);
  14570. if (ret != 0) {
  14571. return WC_TEST_RET_ENC_EC(ret);
  14572. }
  14573. /* check ciphertext matches vector */
  14574. if (XMEMCMP(ciphertext, vectors[i].ct, (size_t)vectors[i].ct_length)) {
  14575. return WC_TEST_RET_ENC_NC;
  14576. }
  14577. /* check that tag matches vector only for vectors marked as valid */
  14578. ret = XMEMCMP(authtag, vectors[i].tag, len);
  14579. if (vectors[i].valid == 1 && ret != 0 ) {
  14580. return WC_TEST_RET_ENC_NC;
  14581. }
  14582. else if (vectors[i].valid == 0 && ret == 0) {
  14583. return WC_TEST_RET_ENC_NC;
  14584. }
  14585. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14586. ret = wc_AesEaxDecryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14587. ciphertext,
  14588. vectors[i].ct, (word32)vectors[i].ct_length,
  14589. vectors[i].iv, (word32)vectors[i].iv_length,
  14590. authtag, (word32)len,
  14591. vectors[i].aad, (word32)vectors[i].aad_length);
  14592. if (ret != 0) {
  14593. return WC_TEST_RET_ENC_EC(ret);
  14594. }
  14595. /* check decrypted ciphertext matches vector plaintext */
  14596. if (XMEMCMP(ciphertext, vectors[i].msg, (size_t)vectors[i].msg_length)) {
  14597. return WC_TEST_RET_ENC_NC;
  14598. }
  14599. }
  14600. return 0;
  14601. }
  14602. #endif /* WOLFSSL_AES_EAX */
  14603. #ifdef HAVE_AES_KEYWRAP
  14604. #define MAX_KEYWRAP_TEST_OUTLEN 40
  14605. #define MAX_KEYWRAP_TEST_PLAINLEN 32
  14606. typedef struct keywrapVector {
  14607. const byte* kek;
  14608. const byte* data;
  14609. const byte* verify;
  14610. word32 kekLen;
  14611. word32 dataLen;
  14612. word32 verifyLen;
  14613. } keywrapVector;
  14614. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void)
  14615. {
  14616. int wrapSz, plainSz, testSz, i;
  14617. /* test vectors from RFC 3394 (kek, data, verify) */
  14618. #ifdef WOLFSSL_AES_128
  14619. /* Wrap 128 bits of Key Data with a 128-bit KEK */
  14620. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14621. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14622. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14623. };
  14624. WOLFSSL_SMALL_STACK_STATIC const byte d1[] = {
  14625. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14626. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14627. };
  14628. WOLFSSL_SMALL_STACK_STATIC const byte v1[] = {
  14629. 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
  14630. 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
  14631. 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
  14632. };
  14633. #endif /* WOLFSSL_AES_128 */
  14634. #ifdef WOLFSSL_AES_192
  14635. /* Wrap 128 bits of Key Data with a 192-bit KEK */
  14636. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  14637. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14638. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14639. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14640. };
  14641. WOLFSSL_SMALL_STACK_STATIC const byte d2[] = {
  14642. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14643. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14644. };
  14645. WOLFSSL_SMALL_STACK_STATIC const byte v2[] = {
  14646. 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
  14647. 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
  14648. 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
  14649. };
  14650. #endif
  14651. #ifdef WOLFSSL_AES_256
  14652. /* Wrap 128 bits of Key Data with a 256-bit KEK */
  14653. WOLFSSL_SMALL_STACK_STATIC const byte k3[] = {
  14654. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14655. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14656. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14657. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14658. };
  14659. WOLFSSL_SMALL_STACK_STATIC const byte d3[] = {
  14660. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14661. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14662. };
  14663. WOLFSSL_SMALL_STACK_STATIC const byte v3[] = {
  14664. 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
  14665. 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
  14666. 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7
  14667. };
  14668. #endif
  14669. #ifdef WOLFSSL_AES_192
  14670. /* Wrap 192 bits of Key Data with a 192-bit KEK */
  14671. WOLFSSL_SMALL_STACK_STATIC const byte k4[] = {
  14672. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14673. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14674. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14675. };
  14676. WOLFSSL_SMALL_STACK_STATIC const byte d4[] = {
  14677. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14678. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14679. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14680. };
  14681. WOLFSSL_SMALL_STACK_STATIC const byte v4[] = {
  14682. 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
  14683. 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
  14684. 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
  14685. 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
  14686. };
  14687. #endif
  14688. #ifdef WOLFSSL_AES_256
  14689. /* Wrap 192 bits of Key Data with a 256-bit KEK */
  14690. WOLFSSL_SMALL_STACK_STATIC const byte k5[] = {
  14691. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14692. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14693. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14694. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14695. };
  14696. WOLFSSL_SMALL_STACK_STATIC const byte d5[] = {
  14697. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14698. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14699. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14700. };
  14701. WOLFSSL_SMALL_STACK_STATIC const byte v5[] = {
  14702. 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
  14703. 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
  14704. 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
  14705. 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1
  14706. };
  14707. /* Wrap 256 bits of Key Data with a 256-bit KEK */
  14708. WOLFSSL_SMALL_STACK_STATIC const byte k6[] = {
  14709. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14710. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14711. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14712. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14713. };
  14714. WOLFSSL_SMALL_STACK_STATIC const byte d6[] = {
  14715. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14716. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14717. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14718. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14719. };
  14720. WOLFSSL_SMALL_STACK_STATIC const byte v6[] = {
  14721. 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
  14722. 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
  14723. 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
  14724. 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
  14725. 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
  14726. };
  14727. #endif /* WOLFSSL_AES_256 */
  14728. byte output[MAX_KEYWRAP_TEST_OUTLEN];
  14729. byte plain [MAX_KEYWRAP_TEST_PLAINLEN];
  14730. const keywrapVector test_wrap[] =
  14731. {
  14732. #ifdef WOLFSSL_AES_128
  14733. {k1, d1, v1, sizeof(k1), sizeof(d1), sizeof(v1)},
  14734. #endif
  14735. #ifdef WOLFSSL_AES_192
  14736. {k2, d2, v2, sizeof(k2), sizeof(d2), sizeof(v2)},
  14737. #endif
  14738. #ifdef WOLFSSL_AES_256
  14739. {k3, d3, v3, sizeof(k3), sizeof(d3), sizeof(v3)},
  14740. #endif
  14741. #ifdef WOLFSSL_AES_192
  14742. {k4, d4, v4, sizeof(k4), sizeof(d4), sizeof(v4)},
  14743. #endif
  14744. #ifdef WOLFSSL_AES_256
  14745. {k5, d5, v5, sizeof(k5), sizeof(d5), sizeof(v5)},
  14746. {k6, d6, v6, sizeof(k6), sizeof(d6), sizeof(v6)}
  14747. #endif
  14748. };
  14749. WOLFSSL_ENTER("aeskeywrap_test");
  14750. testSz = sizeof(test_wrap) / sizeof(keywrapVector);
  14751. XMEMSET(output, 0, sizeof(output));
  14752. XMEMSET(plain, 0, sizeof(plain));
  14753. for (i = 0; i < testSz; i++) {
  14754. wrapSz = wc_AesKeyWrap(test_wrap[i].kek, test_wrap[i].kekLen,
  14755. test_wrap[i].data, test_wrap[i].dataLen,
  14756. output, sizeof(output), NULL);
  14757. if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) )
  14758. return WC_TEST_RET_ENC_NC;
  14759. if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0)
  14760. return WC_TEST_RET_ENC_NC;
  14761. plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen,
  14762. output, (word32)wrapSz,
  14763. plain, sizeof(plain), NULL);
  14764. if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) )
  14765. return WC_TEST_RET_ENC_NC;
  14766. if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0)
  14767. return WC_TEST_RET_ENC_I(i);
  14768. }
  14769. return 0;
  14770. }
  14771. #endif /* HAVE_AES_KEYWRAP */
  14772. #endif /* !NO_AES */
  14773. #ifdef HAVE_ARIA
  14774. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz)
  14775. {
  14776. #ifndef DEBUG_WOLFSSL
  14777. (void)strName;
  14778. (void)data;
  14779. (void)dataSz;
  14780. #else
  14781. WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
  14782. WOLFSSL_BUFFER(data,dataSz);
  14783. #endif
  14784. }
  14785. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo)
  14786. {
  14787. byte data[] = TEST_STRING;
  14788. word32 dataSz = TEST_STRING_SZ;
  14789. /* Arbitrarily random long key that we will truncate to the right size */
  14790. byte key[] = { 0x1E, 0xCC, 0x95, 0xCB, 0xD3, 0x74, 0x58, 0x4F,
  14791. 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6,
  14792. 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF,
  14793. 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B };
  14794. byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[AES_BLOCK_SIZE];
  14795. word32 keySz, adSz = 256, authTagSz = sizeof(authTag);
  14796. wc_Aria aria;
  14797. int ret = 0;
  14798. WOLFSSL_ENTER("ariagcm_test");
  14799. XMEMSET((void *)&aria, 0, sizeof(aria));
  14800. ret = wc_AriaInitCrypt(&aria, algo);
  14801. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14802. ret = wc_AriaSetKey(&aria, key);
  14803. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14804. MC_GetObjectValue(aria.hSession, aria.hKey, key, &keySz);
  14805. printOutput("Key", key, keySz);
  14806. WC_RNG rng;
  14807. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14808. if (ret != 0)
  14809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14810. ret = wc_AriaGcmSetIV(&aria, GCM_NONCE_MID_SZ, NULL, 0, &rng);
  14811. if (ret != 0)
  14812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14813. wc_FreeRng(&rng);
  14814. printOutput("Plaintext", data, sizeof(data));
  14815. XMEMSET(cipher, 0, sizeof(cipher));
  14816. ret = wc_AriaEncrypt(&aria, cipher, data, dataSz,
  14817. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14818. authTag, authTagSz);
  14819. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14820. printOutput("Ciphertext", cipher, sizeof(cipher));
  14821. printOutput("AuthTag", authTag, sizeof(authTag));
  14822. XMEMSET(plain, 0, sizeof(plain));
  14823. ret = wc_AriaDecrypt(&aria, plain, cipher, dataSz,
  14824. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14825. authTag, authTagSz);
  14826. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14827. printOutput("Plaintext", plain, sizeof(plain));
  14828. if (XMEMCMP(plain, data, dataSz) != 0)
  14829. ERROR_OUT(WC_TEST_RET_ENC_NC,out);
  14830. out:
  14831. if (ret != 0) { wc_AriaFreeCrypt(&aria); }
  14832. else { ret = wc_AriaFreeCrypt(&aria); }
  14833. return ret;
  14834. }
  14835. #endif /* HAVE_ARIA */
  14836. #ifdef HAVE_CAMELLIA
  14837. enum {
  14838. CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
  14839. };
  14840. typedef struct {
  14841. int type;
  14842. const byte* plaintext;
  14843. const byte* iv;
  14844. const byte* ciphertext;
  14845. const byte* key;
  14846. word32 keySz;
  14847. int errorCode;
  14848. } test_vector_t;
  14849. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void)
  14850. {
  14851. /* Camellia ECB Test Plaintext */
  14852. WOLFSSL_SMALL_STACK_STATIC const byte pte[] =
  14853. {
  14854. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14855. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14856. };
  14857. /* Camellia ECB Test Initialization Vector */
  14858. WOLFSSL_SMALL_STACK_STATIC const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  14859. /* Test 1: Camellia ECB 128-bit key */
  14860. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14861. {
  14862. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14863. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14864. };
  14865. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  14866. {
  14867. 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
  14868. 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
  14869. };
  14870. /* Test 2: Camellia ECB 192-bit key */
  14871. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14872. {
  14873. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14874. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14875. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  14876. };
  14877. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  14878. {
  14879. 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
  14880. 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
  14881. };
  14882. /* Test 3: Camellia ECB 256-bit key */
  14883. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  14884. {
  14885. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14886. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14887. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14888. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  14889. };
  14890. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  14891. {
  14892. 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
  14893. 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
  14894. };
  14895. /* Camellia CBC Test Plaintext */
  14896. WOLFSSL_SMALL_STACK_STATIC const byte ptc[] =
  14897. {
  14898. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  14899. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  14900. };
  14901. /* Camellia CBC Test Initialization Vector */
  14902. WOLFSSL_SMALL_STACK_STATIC const byte ivc[] =
  14903. {
  14904. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14905. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14906. };
  14907. /* Test 4: Camellia-CBC 128-bit key */
  14908. WOLFSSL_SMALL_STACK_STATIC const byte k4[] =
  14909. {
  14910. 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
  14911. 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
  14912. };
  14913. WOLFSSL_SMALL_STACK_STATIC const byte c4[] =
  14914. {
  14915. 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
  14916. 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
  14917. };
  14918. /* Test 5: Camellia-CBC 192-bit key */
  14919. WOLFSSL_SMALL_STACK_STATIC const byte k5[] =
  14920. {
  14921. 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
  14922. 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
  14923. 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
  14924. };
  14925. WOLFSSL_SMALL_STACK_STATIC const byte c5[] =
  14926. {
  14927. 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
  14928. 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
  14929. };
  14930. /* Test 6: CBC 256-bit key */
  14931. WOLFSSL_SMALL_STACK_STATIC const byte k6[] =
  14932. {
  14933. 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
  14934. 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
  14935. 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
  14936. 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
  14937. };
  14938. WOLFSSL_SMALL_STACK_STATIC const byte c6[] =
  14939. {
  14940. 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
  14941. 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
  14942. };
  14943. byte out[CAMELLIA_BLOCK_SIZE];
  14944. Camellia cam;
  14945. WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] =
  14946. {
  14947. {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
  14948. {CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
  14949. {CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
  14950. {CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
  14951. {CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
  14952. {CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
  14953. {CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
  14954. {CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
  14955. {CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
  14956. {CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
  14957. {CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
  14958. {CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
  14959. };
  14960. int i, testsSz;
  14961. int ret;
  14962. WOLFSSL_ENTER("camellia_test");
  14963. testsSz = sizeof(testVectors)/sizeof(test_vector_t);
  14964. for (i = 0; i < testsSz; i++) {
  14965. if (wc_CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
  14966. testVectors[i].iv) != 0)
  14967. return testVectors[i].errorCode;
  14968. switch (testVectors[i].type) {
  14969. case CAM_ECB_ENC:
  14970. ret = wc_CamelliaEncryptDirect(&cam, out,
  14971. testVectors[i].plaintext);
  14972. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14973. CAMELLIA_BLOCK_SIZE))
  14974. return testVectors[i].errorCode;
  14975. break;
  14976. case CAM_ECB_DEC:
  14977. ret = wc_CamelliaDecryptDirect(&cam, out,
  14978. testVectors[i].ciphertext);
  14979. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14980. CAMELLIA_BLOCK_SIZE))
  14981. return testVectors[i].errorCode;
  14982. break;
  14983. case CAM_CBC_ENC:
  14984. ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
  14985. CAMELLIA_BLOCK_SIZE);
  14986. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14987. CAMELLIA_BLOCK_SIZE))
  14988. return testVectors[i].errorCode;
  14989. break;
  14990. case CAM_CBC_DEC:
  14991. ret = wc_CamelliaCbcDecrypt(&cam, out,
  14992. testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE);
  14993. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14994. CAMELLIA_BLOCK_SIZE))
  14995. return testVectors[i].errorCode;
  14996. break;
  14997. default:
  14998. break;
  14999. }
  15000. }
  15001. /* Setting the IV and checking it was actually set. */
  15002. ret = wc_CamelliaSetIV(&cam, ivc);
  15003. if (ret != 0)
  15004. return WC_TEST_RET_ENC_EC(ret);
  15005. if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE) != 0)
  15006. return WC_TEST_RET_ENC_NC;
  15007. /* Setting the IV to NULL should be same as all zeros IV */
  15008. ret = wc_CamelliaSetIV(&cam, NULL);
  15009. if (ret != 0)
  15010. return WC_TEST_RET_ENC_EC(ret);
  15011. if (XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE) != 0)
  15012. return WC_TEST_RET_ENC_NC;
  15013. /* First parameter should never be null */
  15014. if (wc_CamelliaSetIV(NULL, NULL) == 0)
  15015. return WC_TEST_RET_ENC_NC;
  15016. /* First parameter should never be null, check it fails */
  15017. if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
  15018. return WC_TEST_RET_ENC_NC;
  15019. /* Key should have a size of 16, 24, or 32 */
  15020. if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0)
  15021. return WC_TEST_RET_ENC_NC;
  15022. return 0;
  15023. }
  15024. #endif /* HAVE_CAMELLIA */
  15025. #ifdef WOLFSSL_SM4
  15026. #ifdef WOLFSSL_SM4_ECB
  15027. static int sm4_ecb_test(void)
  15028. {
  15029. /* draft-ribose-cfrg-sm4-10 A.2.1.1 */
  15030. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15031. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15032. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15033. };
  15034. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15035. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15036. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15037. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15038. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15039. };
  15040. WOLFSSL_SMALL_STACK_STATIC const byte c1_ecb[] = {
  15041. 0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
  15042. 0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
  15043. 0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
  15044. 0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04
  15045. };
  15046. wc_Sm4 sm4;
  15047. byte enc[SM4_BLOCK_SIZE * 4];
  15048. byte dec[SM4_BLOCK_SIZE * 4];
  15049. int ret;
  15050. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15051. if (ret != 0)
  15052. return WC_TEST_RET_ENC_EC(ret);
  15053. /* Encrypt and decrypt with ECB. */
  15054. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15055. if (ret != 0)
  15056. return WC_TEST_RET_ENC_EC(ret);
  15057. ret = wc_Sm4EcbEncrypt(&sm4, enc, p1, sizeof(p1));
  15058. if (ret != 0)
  15059. return WC_TEST_RET_ENC_EC(ret);
  15060. if (XMEMCMP(enc, c1_ecb, sizeof(c1_ecb)) != 0)
  15061. return WC_TEST_RET_ENC_NC;
  15062. ret = wc_Sm4EcbDecrypt(&sm4, dec, enc, sizeof(c1_ecb));
  15063. if (ret != 0)
  15064. return WC_TEST_RET_ENC_EC(ret);
  15065. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15066. return WC_TEST_RET_ENC_NC;
  15067. wc_Sm4Free(&sm4);
  15068. return 0;
  15069. }
  15070. #endif
  15071. #ifdef WOLFSSL_SM4_CBC
  15072. static int sm4_cbc_test(void)
  15073. {
  15074. /* draft-ribose-cfrg-sm4-10 A.2.2.1 */
  15075. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15076. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15077. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15078. };
  15079. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15080. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15081. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15082. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15083. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15084. };
  15085. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15086. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15087. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15088. };
  15089. WOLFSSL_SMALL_STACK_STATIC const byte c1_cbc[] = {
  15090. 0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
  15091. 0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
  15092. 0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
  15093. 0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D
  15094. };
  15095. wc_Sm4 sm4;
  15096. byte enc[SM4_BLOCK_SIZE * 4];
  15097. byte dec[SM4_BLOCK_SIZE * 4];
  15098. int ret;
  15099. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15100. if (ret != 0)
  15101. return WC_TEST_RET_ENC_EC(ret);
  15102. /* Encrypt and decrypt with CBC. */
  15103. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15104. if (ret != 0)
  15105. return WC_TEST_RET_ENC_EC(ret);
  15106. ret = wc_Sm4SetIV(&sm4, i1);
  15107. if (ret != 0)
  15108. return WC_TEST_RET_ENC_EC(ret);
  15109. ret = wc_Sm4CbcEncrypt(&sm4, enc, p1, sizeof(p1));
  15110. if (ret != 0)
  15111. return WC_TEST_RET_ENC_EC(ret);
  15112. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15113. return WC_TEST_RET_ENC_NC;
  15114. ret = wc_Sm4SetIV(&sm4, i1);
  15115. if (ret != 0)
  15116. return WC_TEST_RET_ENC_EC(ret);
  15117. ret = wc_Sm4CbcDecrypt(&sm4, dec, enc, sizeof(c1_cbc));
  15118. if (ret != 0)
  15119. return WC_TEST_RET_ENC_EC(ret);
  15120. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15121. return WC_TEST_RET_ENC_NC;
  15122. /* Encrypt and decrypt in-place with CBC. */
  15123. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15124. if (ret != 0)
  15125. return WC_TEST_RET_ENC_EC(ret);
  15126. ret = wc_Sm4SetIV(&sm4, i1);
  15127. if (ret != 0)
  15128. return WC_TEST_RET_ENC_EC(ret);
  15129. XMEMCPY(enc, p1, sizeof(p1));
  15130. ret = wc_Sm4CbcEncrypt(&sm4, enc, enc, sizeof(p1));
  15131. if (ret != 0)
  15132. return WC_TEST_RET_ENC_EC(ret);
  15133. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15134. return WC_TEST_RET_ENC_NC;
  15135. ret = wc_Sm4SetIV(&sm4, i1);
  15136. if (ret != 0)
  15137. return WC_TEST_RET_ENC_EC(ret);
  15138. ret = wc_Sm4CbcDecrypt(&sm4, enc, enc, sizeof(c1_cbc));
  15139. if (ret != 0)
  15140. return WC_TEST_RET_ENC_EC(ret);
  15141. if (XMEMCMP(enc, p1, sizeof(p1)) != 0)
  15142. return WC_TEST_RET_ENC_NC;
  15143. wc_Sm4Free(&sm4);
  15144. return 0;
  15145. }
  15146. #endif
  15147. #ifdef WOLFSSL_SM4_CTR
  15148. static int sm4_ctr_test(void)
  15149. {
  15150. /* draft-ribose-cfrg-sm4-10 A.2.5.1 */
  15151. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15152. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15153. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15154. };
  15155. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15156. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15157. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15158. };
  15159. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15160. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15161. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15162. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15163. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15164. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15165. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15166. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15167. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB
  15168. };
  15169. WOLFSSL_SMALL_STACK_STATIC const byte c2_ctr[] = {
  15170. 0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
  15171. 0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
  15172. 0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
  15173. 0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
  15174. 0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
  15175. 0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
  15176. 0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
  15177. 0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14
  15178. };
  15179. wc_Sm4 sm4;
  15180. byte enc[SM4_BLOCK_SIZE * 4];
  15181. byte dec[SM4_BLOCK_SIZE * 4];
  15182. int chunk;
  15183. int i;
  15184. int ret;
  15185. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15186. if (ret != 0)
  15187. return WC_TEST_RET_ENC_EC(ret);
  15188. /* Encrypt and decrypt using encrypt with CTR. */
  15189. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15190. if (ret != 0)
  15191. return WC_TEST_RET_ENC_EC(ret);
  15192. ret = wc_Sm4SetIV(&sm4, i1);
  15193. if (ret != 0)
  15194. return WC_TEST_RET_ENC_EC(ret);
  15195. ret = wc_Sm4CtrEncrypt(&sm4, enc, p2, sizeof(p2));
  15196. if (ret != 0)
  15197. return WC_TEST_RET_ENC_EC(ret);
  15198. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15199. return WC_TEST_RET_ENC_NC;
  15200. ret = wc_Sm4SetIV(&sm4, i1);
  15201. if (ret != 0)
  15202. return WC_TEST_RET_ENC_EC(ret);
  15203. ret = wc_Sm4CtrEncrypt(&sm4, dec, enc, sizeof(c2_ctr));
  15204. if (ret != 0)
  15205. return WC_TEST_RET_ENC_EC(ret);
  15206. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15207. return WC_TEST_RET_ENC_NC;
  15208. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15209. ret = wc_Sm4SetIV(&sm4, i1);
  15210. if (ret != 0)
  15211. return WC_TEST_RET_ENC_I(chunk);
  15212. XMEMSET(enc, 0, sizeof(enc));
  15213. for (i = 0; i + chunk <= (int)sizeof(p2); i += chunk) {
  15214. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, chunk);
  15215. if (ret != 0)
  15216. return WC_TEST_RET_ENC_I(i);
  15217. }
  15218. if (i < (int)sizeof(p2)) {
  15219. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, sizeof(p2) - i);
  15220. if (ret != 0)
  15221. return WC_TEST_RET_ENC_I(chunk);
  15222. }
  15223. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15224. return WC_TEST_RET_ENC_I(chunk);
  15225. }
  15226. wc_Sm4Free(&sm4);
  15227. return 0;
  15228. }
  15229. #endif
  15230. #ifdef WOLFSSL_SM4_GCM
  15231. static int sm4_gcm_test(void)
  15232. {
  15233. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15234. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15235. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15236. };
  15237. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15238. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15239. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15240. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15241. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15242. };
  15243. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15244. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15245. 0x08, 0x09, 0x0A, 0x0B
  15246. };
  15247. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15248. 0xFF, 0xEE, 0xDD
  15249. };
  15250. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15251. 0x83, 0xb2, 0x91, 0xcf, 0x22, 0xc9, 0x5f, 0x89,
  15252. 0xde, 0x3d, 0x52, 0x8d, 0xd7, 0x13, 0x50, 0x89
  15253. };
  15254. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15255. 0xff, 0x8b, 0xb2, 0x3b, 0x0a, 0x0a, 0x12, 0xa4,
  15256. 0xa8, 0x4c, 0x4f, 0x67, 0x06, 0x81, 0xbb, 0x88,
  15257. 0x66, 0x17, 0xc7, 0x43, 0xbf, 0xae, 0x41, 0x40,
  15258. 0xec, 0x1e, 0x03, 0x85, 0x2b, 0x56, 0xa8, 0xc0
  15259. };
  15260. /* RFC8998 A.1. */
  15261. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15262. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15263. 0x00, 0x00, 0xAB, 0xCD
  15264. };
  15265. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15266. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15267. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15268. };
  15269. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15270. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15271. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15272. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15273. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15274. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15275. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15276. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15277. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15278. };
  15279. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15280. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15281. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15282. 0xAB, 0xAD, 0xDA, 0xD2
  15283. };
  15284. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15285. 0x17, 0xF3, 0x99, 0xF0, 0x8C, 0x67, 0xD5, 0xEE,
  15286. 0x19, 0xD0, 0xDC, 0x99, 0x69, 0xC4, 0xBB, 0x7D,
  15287. 0x5F, 0xD4, 0x6F, 0xD3, 0x75, 0x64, 0x89, 0x06,
  15288. 0x91, 0x57, 0xB2, 0x82, 0xBB, 0x20, 0x07, 0x35,
  15289. 0xD8, 0x27, 0x10, 0xCA, 0x5C, 0x22, 0xF0, 0xCC,
  15290. 0xFA, 0x7C, 0xBF, 0x93, 0xD4, 0x96, 0xAC, 0x15,
  15291. 0xA5, 0x68, 0x34, 0xCB, 0xCF, 0x98, 0xC3, 0x97,
  15292. 0xB4, 0x02, 0x4A, 0x26, 0x91, 0x23, 0x3B, 0x8D
  15293. };
  15294. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15295. 0x83, 0xDE, 0x35, 0x41, 0xE4, 0xC2, 0xB5, 0x81,
  15296. 0x77, 0xE0, 0x65, 0xA9, 0xBF, 0x7B, 0x62, 0xEC
  15297. };
  15298. wc_Sm4 sm4;
  15299. byte enc[SM4_BLOCK_SIZE * 4];
  15300. byte dec[SM4_BLOCK_SIZE * 4];
  15301. byte tag[SM4_BLOCK_SIZE];
  15302. int ret;
  15303. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15304. if (ret != 0)
  15305. return WC_TEST_RET_ENC_EC(ret);
  15306. /* Encrypt and decrypt using encrypt with GCM. */
  15307. ret = wc_Sm4GcmSetKey(&sm4, k1, sizeof(k1));
  15308. if (ret != 0)
  15309. return WC_TEST_RET_ENC_EC(ret);
  15310. ret = wc_Sm4GcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15311. sizeof(tag), a1, sizeof(a1));
  15312. if (ret != 0)
  15313. return WC_TEST_RET_ENC_EC(ret);
  15314. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15315. return WC_TEST_RET_ENC_NC;
  15316. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15317. return WC_TEST_RET_ENC_NC;
  15318. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15319. sizeof(tag), a1, sizeof(a1));
  15320. if (ret != 0)
  15321. return WC_TEST_RET_ENC_EC(ret);
  15322. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15323. return WC_TEST_RET_ENC_NC;
  15324. /* RFC8998 test vector. */
  15325. ret = wc_Sm4GcmSetKey(&sm4, k2, sizeof(k2));
  15326. if (ret != 0)
  15327. return WC_TEST_RET_ENC_EC(ret);
  15328. ret = wc_Sm4GcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15329. sizeof(tag), a2, sizeof(a2));
  15330. if (ret != 0)
  15331. return WC_TEST_RET_ENC_EC(ret);
  15332. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15333. return WC_TEST_RET_ENC_NC;
  15334. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15335. return WC_TEST_RET_ENC_NC;
  15336. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15337. sizeof(tag), a2, sizeof(a2));
  15338. if (ret != 0)
  15339. return WC_TEST_RET_ENC_EC(ret);
  15340. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15341. return WC_TEST_RET_ENC_NC;
  15342. wc_Sm4Free(&sm4);
  15343. return 0;
  15344. }
  15345. #endif
  15346. #ifdef WOLFSSL_SM4_CCM
  15347. static int sm4_ccm_test(void)
  15348. {
  15349. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15350. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15351. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15352. };
  15353. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15354. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15355. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15356. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15357. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15358. };
  15359. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15360. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15361. 0x08, 0x09, 0x0A, 0x0B
  15362. };
  15363. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15364. 0xFF, 0xEE, 0xDD
  15365. };
  15366. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15367. 0x9a, 0x98, 0x04, 0xb6, 0x0f, 0x19, 0x4a, 0x46,
  15368. 0xba, 0xed, 0xe6, 0x89, 0x69, 0x34, 0xad, 0x61
  15369. };
  15370. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15371. 0xbd, 0xc0, 0x72, 0x60, 0xda, 0x2d, 0x11, 0xdc,
  15372. 0x66, 0x33, 0xcc, 0xec, 0xb2, 0xf4, 0x53, 0x59,
  15373. 0x9e, 0xb1, 0xb3, 0x6b, 0x1f, 0x1c, 0xfb, 0x29,
  15374. 0xf5, 0x37, 0xfc, 0x00, 0xf2, 0x4e, 0x70, 0x6f
  15375. };
  15376. /* RFC8998 A.1. */
  15377. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15378. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15379. 0x00, 0x00, 0xAB, 0xCD
  15380. };
  15381. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15382. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15383. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15384. };
  15385. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15386. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15387. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15388. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15389. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15390. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15391. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15392. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15393. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15394. };
  15395. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15396. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15397. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15398. 0xAB, 0xAD, 0xDA, 0xD2
  15399. };
  15400. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15401. 0x48, 0xAF, 0x93, 0x50, 0x1F, 0xA6, 0x2A, 0xDB,
  15402. 0xCD, 0x41, 0x4C, 0xCE, 0x60, 0x34, 0xD8, 0x95,
  15403. 0xDD, 0xA1, 0xBF, 0x8F, 0x13, 0x2F, 0x04, 0x20,
  15404. 0x98, 0x66, 0x15, 0x72, 0xE7, 0x48, 0x30, 0x94,
  15405. 0xFD, 0x12, 0xE5, 0x18, 0xCE, 0x06, 0x2C, 0x98,
  15406. 0xAC, 0xEE, 0x28, 0xD9, 0x5D, 0xF4, 0x41, 0x6B,
  15407. 0xED, 0x31, 0xA2, 0xF0, 0x44, 0x76, 0xC1, 0x8B,
  15408. 0xB4, 0x0C, 0x84, 0xA7, 0x4B, 0x97, 0xDC, 0x5B
  15409. };
  15410. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15411. 0x16, 0x84, 0x2D, 0x4F, 0xA1, 0x86, 0xF5, 0x6A,
  15412. 0xB3, 0x32, 0x56, 0x97, 0x1F, 0xA1, 0x10, 0xF4
  15413. };
  15414. wc_Sm4 sm4;
  15415. byte enc[SM4_BLOCK_SIZE * 4];
  15416. byte dec[SM4_BLOCK_SIZE * 4];
  15417. byte tag[SM4_BLOCK_SIZE];
  15418. int ret;
  15419. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15420. if (ret != 0)
  15421. return WC_TEST_RET_ENC_EC(ret);
  15422. /* Encrypt and decrypt using encrypt with CCM. */
  15423. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15424. if (ret != 0)
  15425. return WC_TEST_RET_ENC_EC(ret);
  15426. ret = wc_Sm4CcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15427. sizeof(tag), a1, sizeof(a1));
  15428. if (ret != 0)
  15429. return WC_TEST_RET_ENC_EC(ret);
  15430. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15431. return WC_TEST_RET_ENC_NC;
  15432. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15433. return WC_TEST_RET_ENC_NC;
  15434. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15435. sizeof(tag), a1, sizeof(a1));
  15436. if (ret != 0)
  15437. return WC_TEST_RET_ENC_EC(ret);
  15438. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15439. return WC_TEST_RET_ENC_NC;
  15440. /* RFC8998 test vector. */
  15441. ret = wc_Sm4SetKey(&sm4, k2, sizeof(k2));
  15442. if (ret != 0)
  15443. return WC_TEST_RET_ENC_EC(ret);
  15444. ret = wc_Sm4CcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15445. sizeof(tag), a2, sizeof(a2));
  15446. if (ret != 0)
  15447. return WC_TEST_RET_ENC_EC(ret);
  15448. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15449. return WC_TEST_RET_ENC_NC;
  15450. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15451. return WC_TEST_RET_ENC_NC;
  15452. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15453. sizeof(tag), a2, sizeof(a2));
  15454. if (ret != 0)
  15455. return WC_TEST_RET_ENC_EC(ret);
  15456. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15457. return WC_TEST_RET_ENC_NC;
  15458. wc_Sm4Free(&sm4);
  15459. return 0;
  15460. }
  15461. #endif
  15462. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void)
  15463. {
  15464. wc_test_ret_t ret;
  15465. WOLFSSL_ENTER("sm4_test");
  15466. #ifdef WOLFSSL_SM4_ECB
  15467. ret = sm4_ecb_test();
  15468. if (ret != 0)
  15469. return ret;
  15470. #endif
  15471. #ifdef WOLFSSL_SM4_CBC
  15472. ret = sm4_cbc_test();
  15473. if (ret != 0)
  15474. return ret;
  15475. #endif
  15476. #ifdef WOLFSSL_SM4_CTR
  15477. ret = sm4_ctr_test();
  15478. if (ret != 0)
  15479. return ret;
  15480. #endif
  15481. #ifdef WOLFSSL_SM4_GCM
  15482. ret = sm4_gcm_test();
  15483. if (ret != 0)
  15484. return ret;
  15485. #endif
  15486. #ifdef WOLFSSL_SM4_CCM
  15487. ret = sm4_ccm_test();
  15488. if (ret != 0)
  15489. return ret;
  15490. #endif
  15491. return 0;
  15492. }
  15493. #endif
  15494. #ifdef HAVE_XCHACHA
  15495. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void) {
  15496. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15497. 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */
  15498. 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, /* unced "dole") is */
  15499. 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, /* also known as t */
  15500. 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, /* he Asiatic wild */
  15501. 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, /* dog, red dog, an */
  15502. 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, /* d whistling dog. */
  15503. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, /* It is about the */
  15504. 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, /* size of a Germa */
  15505. 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, /* n shepherd but l */
  15506. 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, /* ooks more like a */
  15507. 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, /* long-legged fox */
  15508. 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, /* . This highly el */
  15509. 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, /* usive and skille */
  15510. 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, /* d jumper is clas */
  15511. 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, /* sified with wolv */
  15512. 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, /* es, coyotes, jac */
  15513. 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, /* kals, and foxes */
  15514. 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, /* in the taxonomic */
  15515. 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e /* family Canidae. */
  15516. };
  15517. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15518. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15519. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15520. };
  15521. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15522. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15523. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 }; /* PQRSTUVW */
  15524. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15525. 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f,
  15526. 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9,
  15527. 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa,
  15528. 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d,
  15529. 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a,
  15530. 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda,
  15531. 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31,
  15532. 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44,
  15533. 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b,
  15534. 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40,
  15535. 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e,
  15536. 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c,
  15537. 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41,
  15538. 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae,
  15539. 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa,
  15540. 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c,
  15541. 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20,
  15542. 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63,
  15543. 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5
  15544. };
  15545. wc_test_ret_t ret;
  15546. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15547. struct ChaCha *chacha = (struct ChaCha *)XMALLOC(sizeof *chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15548. byte *buf1 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15549. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15550. WOLFSSL_ENTER("XChaCha_test");
  15551. if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL))
  15552. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15553. #else
  15554. struct ChaCha chacha[1];
  15555. byte buf1[sizeof Plaintext];
  15556. byte buf2[sizeof Plaintext];
  15557. WOLFSSL_ENTER("XChaCha_test");
  15558. #endif
  15559. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15560. if (ret < 0)
  15561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15562. ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext);
  15563. if (ret < 0)
  15564. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15565. if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext))
  15566. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15567. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15568. if (ret < 0)
  15569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15570. ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext);
  15571. if (ret < 0)
  15572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15573. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15574. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15575. out:
  15576. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15577. XFREE(chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15578. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15579. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15580. #endif
  15581. return ret;
  15582. }
  15583. #endif /* HAVE_XCHACHA */
  15584. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  15585. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void) {
  15586. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15587. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, /* Ladies and Gentl */
  15588. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, /* emen of the clas */
  15589. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, /* s of '99: If I c */
  15590. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, /* ould offer you o */
  15591. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, /* nly one tip for */
  15592. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, /* the future, suns */
  15593. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, /* creen would be i */
  15594. 0x74, 0x2e }; /* t. */
  15595. WOLFSSL_SMALL_STACK_STATIC const byte AAD[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; /* PQRS........ */
  15596. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15597. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15598. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15599. };
  15600. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15601. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15602. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }; /* PQRSTUVW */
  15603. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15604. 0xbd, 0x6d, 0x17, 0x9d, 0x3e, 0x83, 0xd4, 0x3b, 0x95, 0x76, 0x57, 0x94, 0x93, 0xc0, 0xe9, 0x39,
  15605. 0x57, 0x2a, 0x17, 0x00, 0x25, 0x2b, 0xfa, 0xcc, 0xbe, 0xd2, 0x90, 0x2c, 0x21, 0x39, 0x6c, 0xbb,
  15606. 0x73, 0x1c, 0x7f, 0x1b, 0x0b, 0x4a, 0xa6, 0x44, 0x0b, 0xf3, 0xa8, 0x2f, 0x4e, 0xda, 0x7e, 0x39,
  15607. 0xae, 0x64, 0xc6, 0x70, 0x8c, 0x54, 0xc2, 0x16, 0xcb, 0x96, 0xb7, 0x2e, 0x12, 0x13, 0xb4, 0x52,
  15608. 0x2f, 0x8c, 0x9b, 0xa4, 0x0d, 0xb5, 0xd9, 0x45, 0xb1, 0x1b, 0x69, 0xb9, 0x82, 0xc1, 0xbb, 0x9e,
  15609. 0x3f, 0x3f, 0xac, 0x2b, 0xc3, 0x69, 0x48, 0x8f, 0x76, 0xb2, 0x38, 0x35, 0x65, 0xd3, 0xff, 0xf9,
  15610. 0x21, 0xf9, 0x66, 0x4c, 0x97, 0x63, 0x7d, 0xa9, 0x76, 0x88, 0x12, 0xf6, 0x15, 0xc6, 0x8b, 0x13,
  15611. 0xb5, 0x2e };
  15612. WOLFSSL_SMALL_STACK_STATIC const byte Tag[] = {
  15613. 0xc0, 0x87, 0x59, 0x24, 0xc1, 0xc7, 0x98, 0x79, 0x47, 0xde, 0xaf, 0xd8, 0x78, 0x0a, 0xcf, 0x49
  15614. };
  15615. wc_test_ret_t ret;
  15616. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15617. byte *buf1 = (byte *)XMALLOC(sizeof Ciphertext + sizeof Tag, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15618. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15619. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15620. if ((buf1 == NULL) || (buf2 == NULL))
  15621. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15622. #else
  15623. byte buf1[sizeof Ciphertext + sizeof Tag];
  15624. byte buf2[sizeof Plaintext];
  15625. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15626. #endif
  15627. ret = wc_XChaCha20Poly1305_Encrypt(buf1, sizeof Ciphertext + sizeof Tag,
  15628. Plaintext, sizeof Plaintext,
  15629. AAD, sizeof AAD,
  15630. IV, sizeof IV,
  15631. Key, sizeof Key);
  15632. if (ret < 0)
  15633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15634. if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext))
  15635. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15636. if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE))
  15637. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15638. ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext,
  15639. buf1, sizeof Ciphertext + sizeof Tag,
  15640. AAD, sizeof AAD,
  15641. IV, sizeof IV,
  15642. Key, sizeof Key);
  15643. if (ret < 0)
  15644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15645. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15646. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15647. out:
  15648. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15649. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15650. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15651. #endif
  15652. return ret;
  15653. }
  15654. #endif /* defined(HAVE_XCHACHA) && defined(HAVE_POLY1305) */
  15655. #ifndef WC_NO_RNG
  15656. static wc_test_ret_t _rng_test(WC_RNG* rng)
  15657. {
  15658. byte block[32];
  15659. wc_test_ret_t ret;
  15660. int i;
  15661. XMEMSET(block, 0, sizeof(block));
  15662. ret = wc_RNG_GenerateBlock(rng, block, sizeof(block));
  15663. if (ret != 0) {
  15664. return WC_TEST_RET_ENC_EC(ret);
  15665. }
  15666. /* Check for 0's */
  15667. for (i=0; i<(int)sizeof(block); i++) {
  15668. if (block[i] == 0) {
  15669. ret++;
  15670. }
  15671. }
  15672. /* All zeros count check */
  15673. if (ret >= (int)sizeof(block)) {
  15674. return WC_TEST_RET_ENC_NC;
  15675. }
  15676. ret = wc_RNG_GenerateByte(rng, block);
  15677. if (ret != 0) {
  15678. return WC_TEST_RET_ENC_EC(ret);
  15679. }
  15680. /* Parameter validation testing. */
  15681. ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block));
  15682. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15683. return WC_TEST_RET_ENC_EC(ret);
  15684. }
  15685. ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block));
  15686. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15687. return WC_TEST_RET_ENC_EC(ret);
  15688. }
  15689. ret = wc_RNG_GenerateByte(NULL, block);
  15690. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15691. return WC_TEST_RET_ENC_EC(ret);
  15692. }
  15693. ret = wc_RNG_GenerateByte(rng, NULL);
  15694. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15695. return WC_TEST_RET_ENC_EC(ret);
  15696. }
  15697. return 0;
  15698. }
  15699. static wc_test_ret_t random_rng_test(void)
  15700. {
  15701. WC_RNG localRng;
  15702. WC_RNG* rng;
  15703. wc_test_ret_t ret;
  15704. rng = &localRng;
  15705. /* Test stack based RNG. */
  15706. #ifndef HAVE_FIPS
  15707. ret = wc_InitRng_ex(rng, HEAP_HINT, devId);
  15708. #else
  15709. ret = wc_InitRng(rng);
  15710. #endif
  15711. if (ret != 0)
  15712. return WC_TEST_RET_ENC_EC(ret);
  15713. ret = _rng_test(rng);
  15714. /* Make sure and free RNG */
  15715. wc_FreeRng(rng);
  15716. if (ret != 0)
  15717. return ret;
  15718. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
  15719. {
  15720. byte nonce[8] = { 0 };
  15721. /* Test dynamic RNG */
  15722. rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
  15723. if (rng == NULL)
  15724. return WC_TEST_RET_ENC_ERRNO;
  15725. ret = _rng_test(rng);
  15726. wc_rng_free(rng);
  15727. rng = NULL;
  15728. if (ret != 0)
  15729. return ret;
  15730. /* Test dynamic RNG using extended API */
  15731. ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
  15732. HEAP_HINT, devId);
  15733. if (ret != 0)
  15734. return WC_TEST_RET_ENC_EC(ret);
  15735. ret = _rng_test(rng);
  15736. wc_rng_free(rng);
  15737. if (ret != 0)
  15738. return ret;
  15739. }
  15740. #endif
  15741. return ret;
  15742. }
  15743. #if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  15744. #ifdef WC_RNG_SEED_CB
  15745. static int seed_cb(OS_Seed* os, byte* output, word32 sz)
  15746. {
  15747. word32 i;
  15748. (void)os;
  15749. /* Known answer test. Set the seed to the same value every time. */
  15750. for (i = 0; i < sz; i++)
  15751. output[i] = (byte)i;
  15752. return 0;
  15753. }
  15754. static wc_test_ret_t rng_seed_test(void)
  15755. {
  15756. #ifndef HAVE_FIPS
  15757. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15758. {
  15759. 0x83, 0x46, 0x65, 0x2f, 0x5c, 0x44, 0x16, 0x5f,
  15760. 0xb3, 0x89, 0x26, 0xde, 0x0b, 0x6b, 0xa2, 0x06,
  15761. 0x7e, 0xa7, 0x9a, 0x55, 0x22, 0x01, 0xb0, 0x22,
  15762. 0xf4, 0x7e, 0xa2, 0x66, 0xc4, 0x08, 0x6f, 0xba
  15763. };
  15764. #else
  15765. /* FIPS uses a longer seed, so different check value. */
  15766. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15767. {
  15768. 0xaf, 0x31, 0xcc, 0xef, 0xa9, 0x29, 0x4c, 0x24,
  15769. 0xbd, 0xa5, 0xa3, 0x52, 0x69, 0xf3, 0xb9, 0xb2,
  15770. 0x1e, 0xd4, 0x52, 0x3b, 0x9a, 0x96, 0x06, 0x20,
  15771. 0xc0, 0x5f, 0x44, 0x06, 0x1f, 0x80, 0xdf, 0xe0
  15772. };
  15773. #endif
  15774. byte output[WC_SHA256_DIGEST_SIZE];
  15775. WC_RNG rng;
  15776. wc_test_ret_t ret;
  15777. ret = wc_SetSeed_Cb(seed_cb);
  15778. if (ret != 0) {
  15779. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15780. }
  15781. ret = wc_InitRng(&rng);
  15782. if (ret != 0) {
  15783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15784. }
  15785. ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output));
  15786. if (ret != 0) {
  15787. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15788. }
  15789. ret = XMEMCMP(output, check, sizeof(output));
  15790. if (ret != 0) {
  15791. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15792. }
  15793. ret = wc_FreeRng(&rng);
  15794. if (ret != 0) {
  15795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15796. }
  15797. ret = wc_SetSeed_Cb(wc_GenerateSeed);
  15798. if (ret != 0) {
  15799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15800. }
  15801. out:
  15802. return ret;
  15803. }
  15804. #endif
  15805. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15806. {
  15807. WOLFSSL_SMALL_STACK_STATIC const byte test1Entropy[] =
  15808. {
  15809. 0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e, 0xff, 0xe8, 0x75, 0xc3,
  15810. 0xa2, 0xe7, 0x1f, 0x42, 0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
  15811. 0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb, 0x85, 0x81, 0xf9, 0x31,
  15812. 0x75, 0x17, 0x27, 0x6e, 0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
  15813. };
  15814. WOLFSSL_SMALL_STACK_STATIC const byte test1Output[] =
  15815. {
  15816. 0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40, 0xb2, 0x62, 0x82, 0x64,
  15817. 0xd1, 0x75, 0x10, 0x60, 0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
  15818. 0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d, 0xaa, 0xf6, 0xa6, 0xc3,
  15819. 0x5a, 0x91, 0xbb, 0x45, 0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
  15820. 0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed, 0x52, 0x8f, 0x01, 0x81,
  15821. 0x21, 0xb3, 0xfe, 0xbd, 0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
  15822. 0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1, 0x77, 0xcf, 0xa6, 0xb7,
  15823. 0x1f, 0xe8, 0xab, 0x1d, 0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
  15824. 0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99, 0x0e, 0xea, 0xeb, 0x91,
  15825. 0x12, 0x04, 0x15, 0x52, 0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
  15826. 0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
  15827. };
  15828. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyA[] =
  15829. {
  15830. 0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46, 0x8d, 0xeb, 0x0a, 0xb4,
  15831. 0xa8, 0xed, 0x68, 0x3f, 0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
  15832. 0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69, 0x80, 0x8a, 0xa3, 0x8f,
  15833. 0x2a, 0x72, 0xa6, 0x23, 0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
  15834. };
  15835. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyB[] =
  15836. {
  15837. 0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6, 0x98, 0x05, 0x66, 0xe3,
  15838. 0xbf, 0xe3, 0xc0, 0x49, 0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
  15839. 0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
  15840. };
  15841. WOLFSSL_SMALL_STACK_STATIC const byte test2Output[] =
  15842. {
  15843. 0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c, 0x63, 0x0a, 0x1a, 0xfb,
  15844. 0xe7, 0x24, 0x94, 0x9d, 0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
  15845. 0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62, 0x1c, 0x18, 0xbd, 0xdc,
  15846. 0xdd, 0x8d, 0x99, 0xfc, 0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
  15847. 0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1, 0xdd, 0xd6, 0xc0, 0x71,
  15848. 0x31, 0x8a, 0x60, 0x18, 0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
  15849. 0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10, 0x5d, 0x92, 0x99, 0xb8,
  15850. 0xaf, 0x99, 0xaa, 0x07, 0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
  15851. 0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09, 0x88, 0x96, 0xff, 0x22,
  15852. 0x82, 0xc9, 0x55, 0xa8, 0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
  15853. 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
  15854. };
  15855. byte output[WC_SHA256_DIGEST_SIZE * 4];
  15856. wc_test_ret_t ret;
  15857. WOLFSSL_ENTER("random_test");
  15858. ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
  15859. output, sizeof(output));
  15860. if (ret != 0)
  15861. return WC_TEST_RET_ENC_EC(ret);
  15862. if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
  15863. return WC_TEST_RET_ENC_NC;
  15864. ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
  15865. test2EntropyB, sizeof(test2EntropyB),
  15866. output, sizeof(output));
  15867. if (ret != 0)
  15868. return WC_TEST_RET_ENC_EC(ret);
  15869. if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
  15870. return WC_TEST_RET_ENC_NC;
  15871. /* Basic RNG generate block test */
  15872. if ((ret = random_rng_test()) != 0)
  15873. return ret;
  15874. /* Test the seed check function. */
  15875. #if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
  15876. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  15877. {
  15878. word32 i, outputSz;
  15879. /* Repeat the same byte over and over. Should fail. */
  15880. outputSz = sizeof(output);
  15881. XMEMSET(output, 1, outputSz);
  15882. ret = wc_RNG_TestSeed(output, outputSz);
  15883. if (ret == 0)
  15884. return WC_TEST_RET_ENC_NC;
  15885. /* Every byte of the entropy scratch is different,
  15886. * entropy is a single byte that shouldn't match. */
  15887. outputSz = (sizeof(output) / 2) + 1;
  15888. for (i = 0; i < outputSz; i++)
  15889. output[i] = (byte)i;
  15890. ret = wc_RNG_TestSeed(output, outputSz);
  15891. if (ret != 0)
  15892. return WC_TEST_RET_ENC_EC(ret);
  15893. outputSz = sizeof(output);
  15894. for (i = 0; i < outputSz; i++)
  15895. output[i] = (byte)i;
  15896. ret = wc_RNG_TestSeed(output, outputSz);
  15897. if (ret != 0)
  15898. return WC_TEST_RET_ENC_EC(ret);
  15899. }
  15900. #endif
  15901. /* Test the seed callback. */
  15902. #ifdef WC_RNG_SEED_CB
  15903. if ((ret = rng_seed_test()) != 0)
  15904. return ret;
  15905. #endif
  15906. return 0;
  15907. }
  15908. #else
  15909. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15910. {
  15911. WOLFSSL_ENTER("random_test");
  15912. /* Basic RNG generate block test */
  15913. return random_rng_test();
  15914. }
  15915. #endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
  15916. #endif /* WC_NO_RNG */
  15917. #ifndef MEM_TEST_SZ
  15918. #define MEM_TEST_SZ 1024
  15919. #endif
  15920. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15921. static int simple_mem_test(size_t sz)
  15922. {
  15923. int ret = 0;
  15924. byte* b;
  15925. int i;
  15926. b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15927. if (b == NULL) {
  15928. return WC_TEST_RET_ENC_NC;
  15929. }
  15930. /* utilize memory */
  15931. for (i = 0; i < (int)sz; i++) {
  15932. b[i] = (byte)i;
  15933. }
  15934. /* read back and verify */
  15935. for (i = 0; i < (int)sz; i++) {
  15936. if (b[i] != (byte)i) {
  15937. ret = WC_TEST_RET_ENC_NC;
  15938. break;
  15939. }
  15940. }
  15941. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15942. return ret;
  15943. }
  15944. #endif
  15945. /* If successful, returns the first letter of the byte array `in`.
  15946. **
  15947. ** This is a deceptively simple test of a read-only embedded Linux file system.
  15948. ** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
  15949. ** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
  15950. ** Const is on read-only memory-mapped file system, *not* loaded in app memory.
  15951. **
  15952. ** Edit with caution. See PR #6523. */
  15953. static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
  15954. {
  15955. wc_test_ret_t ret = 0;
  15956. volatile word32 j = (word32)-1; /* must be volatile to properly detect error */
  15957. ret = (wc_test_ret_t)*in; /* accessed *in value. */
  15958. (void)ret;
  15959. j = *outJ; /* Found index to use in const array. */
  15960. if (j == 0) {
  15961. #ifdef WOLFSSL_DEBUG
  15962. printf("Testing const byte ptr reference...\n");
  15963. #endif
  15964. /* although j is zero, in[0] does not detect the Illegal instruction */
  15965. ret = in[j]; /* The big test: can we actually access the `in` data? */
  15966. }
  15967. else {
  15968. ret = WC_TEST_RET_ENC_I(j);
  15969. }
  15970. return ret;
  15971. }
  15972. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
  15973. {
  15974. wc_test_ret_t ret = 0;
  15975. word32 j = 0; /* used in embedded const pointer test */
  15976. WOLFSSL_ENTER("memory_test");
  15977. #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
  15978. int i;
  15979. #endif
  15980. #ifdef WOLFSSL_STATIC_MEMORY
  15981. word32 size[] = { WOLFMEM_BUCKETS };
  15982. word32 dist[] = { WOLFMEM_DIST };
  15983. byte buffer[30000]; /* make large enough to involve many bucket sizes */
  15984. int pad = -(int)((wc_ptr_t)buffer) & (WOLFSSL_STATIC_ALIGN - 1);
  15985. /* pad to account for if head of buffer is not at set memory
  15986. * alignment when tests are ran */
  15987. #endif
  15988. #ifdef WOLFSSL_STATIC_MEMORY
  15989. /* check macro settings */
  15990. if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15991. return WC_TEST_RET_ENC_NC;
  15992. }
  15993. if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15994. return WC_TEST_RET_ENC_NC;
  15995. }
  15996. if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
  15997. return WC_TEST_RET_ENC_NC;
  15998. }
  15999. for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
  16000. if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
  16001. /* each element in array should be divisible by alignment size */
  16002. return WC_TEST_RET_ENC_NC;
  16003. }
  16004. }
  16005. for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
  16006. if (size[i - 1] >= size[i]) {
  16007. return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
  16008. }
  16009. }
  16010. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  16011. /* check that padding size returned is possible */
  16012. if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) {
  16013. return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */
  16014. }
  16015. ret = wolfSSL_MemoryPaddingSz();
  16016. if (ret < 0) {
  16017. return WC_TEST_RET_ENC_EC(ret);
  16018. }
  16019. if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) {
  16020. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16021. }
  16022. /* check function to return optimum buffer size (rounded down) */
  16023. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL);
  16024. if (ret < 0) {
  16025. return WC_TEST_RET_ENC_EC(ret);
  16026. }
  16027. if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) {
  16028. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16029. }
  16030. if ((unsigned int)ret > sizeof(buffer)) {
  16031. return WC_TEST_RET_ENC_NC; /* did not round down as expected */
  16032. }
  16033. if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) {
  16034. return WC_TEST_RET_ENC_NC; /* return value changed when using suggested
  16035. * value
  16036. */
  16037. }
  16038. ret = wolfSSL_MemoryPaddingSz();
  16039. ret += pad; /* add space that is going to be needed if buffer not aligned */
  16040. if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) !=
  16041. (ret + (int)size[0])) {
  16042. return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket
  16043. * value
  16044. */
  16045. }
  16046. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL);
  16047. if ((ret - pad) < 0) {
  16048. return WC_TEST_RET_ENC_NC;
  16049. }
  16050. if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) {
  16051. return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */
  16052. }
  16053. if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) {
  16054. return WC_TEST_RET_ENC_NC; /* memory not aligned */
  16055. }
  16056. /* check for passing bad or unknown arguments to functions */
  16057. if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) {
  16058. return WC_TEST_RET_ENC_NC;
  16059. }
  16060. if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) {
  16061. return WC_TEST_RET_ENC_NC; /* should round to 0
  16062. since struct + bucket will not fit */
  16063. }
  16064. #endif
  16065. (void)pad;
  16066. (void)dist; /* avoid static analysis warning of variable not used */
  16067. #endif
  16068. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  16069. /* simple test */
  16070. ret = simple_mem_test((size_t)MEM_TEST_SZ);
  16071. if (ret != 0)
  16072. return ret;
  16073. #endif
  16074. #ifdef COMPLEX_MEM_TEST
  16075. /* test various size blocks */
  16076. for (i = 1; i < MEM_TEST_SZ; i*=2) {
  16077. ret = simple_mem_test((size_t)i);
  16078. if (ret != 0)
  16079. return ret;
  16080. }
  16081. #endif
  16082. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC)
  16083. /* realloc test */
  16084. {
  16085. byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT,
  16086. DYNAMIC_TYPE_TMP_BUFFER);
  16087. #ifndef WOLFSSL_NO_REALLOC
  16088. byte *c = NULL;
  16089. if (b) {
  16090. c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT,
  16091. DYNAMIC_TYPE_TMP_BUFFER);
  16092. if (c)
  16093. b = c;
  16094. }
  16095. #endif
  16096. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16097. if (b == NULL
  16098. #ifndef WOLFSSL_NO_REALLOC
  16099. || c == NULL
  16100. #endif
  16101. ) {
  16102. return WC_TEST_RET_ENC_ERRNO;
  16103. }
  16104. }
  16105. #endif
  16106. if (ret == 0) {
  16107. /* This test is only interesting on embedded R/O Flash systems */
  16108. if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
  16109. ret = 1;
  16110. }
  16111. }
  16112. return ret;
  16113. }
  16114. #ifndef NO_FILESYSTEM
  16115. /* Cert Paths */
  16116. #ifdef FREESCALE_MQX
  16117. #define CERT_PREFIX "a:\\"
  16118. #define CERT_PATH_SEP "\\"
  16119. #elif defined(WOLFSSL_uTKERNEL2)
  16120. #define CERT_PREFIX "/uda/"
  16121. #define CERT_PATH_SEP "/"
  16122. #elif defined(_WIN32_WCE)
  16123. #define CERT_PREFIX "\\windows\\"
  16124. #define CERT_PATH_SEP "\\"
  16125. #elif defined(WOLFSSL_NDS)
  16126. #undef CERT_PREFIX
  16127. #ifndef WOLFSSL_MELONDS
  16128. #define CERT_PREFIX "fat:/_nds/"
  16129. #else
  16130. #define CERT_PREFIX "_nds/"
  16131. #endif
  16132. #define CERT_PATH_SEP "/"
  16133. #endif
  16134. #ifndef CERT_PREFIX
  16135. #define CERT_PREFIX "./"
  16136. #endif
  16137. #ifndef CERT_PATH_SEP
  16138. #define CERT_PATH_SEP "/"
  16139. #endif
  16140. #ifndef CERT_WRITE_TEMP_DIR
  16141. #define CERT_WRITE_TEMP_DIR CERT_PREFIX
  16142. #endif
  16143. #define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
  16144. /* Generated Test Certs */
  16145. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16146. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16147. #if !defined(NO_RSA) && !defined(NO_ASN)
  16148. static const char* clientKey = CERT_ROOT "client-key.der";
  16149. static const char* clientCert = CERT_ROOT "client-cert.der";
  16150. #ifdef WOLFSSL_CERT_EXT
  16151. static const char* clientKeyPub = CERT_ROOT "client-keyPub.der";
  16152. #endif
  16153. #endif /* !NO_RSA && !NO_ASN */
  16154. #endif
  16155. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16156. #if !defined(NO_RSA) && !defined(NO_ASN)
  16157. #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_PKCS7)
  16158. static const char* rsaCaKeyFile = CERT_ROOT "ca-key.der";
  16159. #ifdef WOLFSSL_CERT_GEN
  16160. static const char* rsaCaCertFile = CERT_ROOT "ca-cert.pem";
  16161. #endif
  16162. #if (defined(WOLFSSL_ALT_NAMES) && !defined(WOLFSSL_NO_MALLOC)) || \
  16163. defined(HAVE_PKCS7)
  16164. static const char* rsaCaCertDerFile = CERT_ROOT "ca-cert.der";
  16165. #endif
  16166. #ifdef HAVE_PKCS7
  16167. static const char* rsaServerCertDerFile =
  16168. CERT_ROOT "server-cert.der";
  16169. static const char* rsaServerKeyDerFile =
  16170. CERT_ROOT "server-key.der";
  16171. #endif
  16172. #endif
  16173. #endif /* !NO_RSA && !NO_ASN */
  16174. #endif /* !USE_CERT_BUFFER_* */
  16175. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16176. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16177. #if !defined(NO_ASN) && !defined(NO_DH)
  16178. static const char* dhParamsFile = CERT_ROOT "dh2048.der";
  16179. #endif
  16180. #endif
  16181. #if !defined(NO_ASN) && !defined(NO_DH)
  16182. #if defined(WOLFSSL_DH_EXTRA) && (!defined(HAVE_FIPS) || \
  16183. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  16184. #if !defined(USE_CERT_BUFFERS_2048)
  16185. static const char* dhKeyFile = CERT_ROOT "statickeys/dh-ffdhe2048.der";
  16186. static const char* dhKeyPubFile = CERT_ROOT "statickeys/dh-ffdhe2048-pub.der";
  16187. #endif
  16188. #endif
  16189. #endif
  16190. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16191. #ifndef NO_DSA
  16192. static const char* dsaKey = CERT_ROOT "dsa2048.der";
  16193. #endif
  16194. #endif /* !USE_CERT_BUFFER_* */
  16195. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ECC256)
  16196. #ifdef HAVE_ECC
  16197. /* cert files to be used in rsa cert gen test, check if RSA enabled */
  16198. #ifdef HAVE_ECC_KEY_IMPORT
  16199. static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der";
  16200. #endif
  16201. #endif
  16202. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN)
  16203. #if defined(HAVE_ECC) && defined(WOLFSSL_CERT_GEN) && \
  16204. !defined(NO_ECC_SECP)
  16205. #ifndef NO_RSA
  16206. static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der";
  16207. #endif
  16208. #if !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  16209. static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der";
  16210. static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem";
  16211. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16212. static const char* eccCaKey384File =
  16213. CERT_ROOT "ca-ecc384-key.der";
  16214. static const char* eccCaCert384File =
  16215. CERT_ROOT "ca-ecc384-cert.pem";
  16216. #endif
  16217. #endif
  16218. #endif
  16219. #if defined(HAVE_PKCS7) && defined(HAVE_ECC)
  16220. static const char* eccClientKey = CERT_ROOT "ecc-client-key.der";
  16221. static const char* eccClientCert = CERT_ROOT "client-ecc-cert.der";
  16222. #endif
  16223. #endif /* HAVE_ECC */
  16224. #ifdef HAVE_ED25519
  16225. #ifdef WOLFSSL_TEST_CERT
  16226. static const char* serverEd25519Cert =
  16227. CERT_ROOT "ed25519/server-ed25519.der";
  16228. static const char* caEd25519Cert =
  16229. CERT_ROOT "ed25519/ca-ed25519.der";
  16230. #endif
  16231. #endif
  16232. #ifdef HAVE_ED448
  16233. #ifdef WOLFSSL_TEST_CERT
  16234. static const char* serverEd448Cert =
  16235. CERT_ROOT "ed448/server-ed448.der";
  16236. static const char* caEd448Cert = CERT_ROOT "ed448/ca-ed448.der";
  16237. #endif
  16238. #endif
  16239. #endif /* !USE_CERT_BUFFER_* */
  16240. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16241. !defined(NO_FILESYSTEM)
  16242. static const char* certExtNc =
  16243. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nc.der";
  16244. static const char* certExtIa =
  16245. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-ia.der";
  16246. static const char* certExtNct =
  16247. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nct.der";
  16248. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16249. static const char* certBadNegInt =
  16250. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-neg-int.der";
  16251. #endif
  16252. static const char* certBadOid =
  16253. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-oid.der";
  16254. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16255. static const char* certBadUtf8 =
  16256. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-utf8.der";
  16257. #endif
  16258. #endif
  16259. #ifndef NO_WRITE_TEMP_FILES
  16260. #ifdef HAVE_ECC
  16261. #ifndef NO_ECC_SECP
  16262. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16263. !defined(WOLFSSL_NO_MALLOC)
  16264. static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem";
  16265. static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
  16266. #endif
  16267. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  16268. static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
  16269. static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
  16270. #endif
  16271. #endif
  16272. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  16273. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT)
  16274. static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem";
  16275. static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
  16276. static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
  16277. #if defined(HAVE_PKCS8) && !defined(WC_NO_RNG) && \
  16278. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  16279. static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
  16280. #endif
  16281. #endif /* HAVE_ECC_KEY_EXPORT */
  16282. #endif /* HAVE_ECC */
  16283. #ifndef NO_RSA
  16284. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16285. !defined(WOLFSSL_NO_MALLOC)
  16286. static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
  16287. static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
  16288. static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
  16289. static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
  16290. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  16291. static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
  16292. static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
  16293. #endif
  16294. #endif
  16295. #endif /* !NO_RSA */
  16296. #if !defined(NO_RSA) || !defined(NO_DSA)
  16297. #ifdef WOLFSSL_KEY_GEN
  16298. static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
  16299. static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
  16300. #endif
  16301. #endif
  16302. #endif /* !NO_WRITE_TEMP_FILES */
  16303. #endif /* !NO_FILESYSTEM */
  16304. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  16305. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  16306. static CertName certDefaultName;
  16307. static void initDefaultName(void)
  16308. {
  16309. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16310. NameAttrib* n;
  16311. #endif
  16312. XMEMCPY(certDefaultName.country, "US", sizeof("US"));
  16313. certDefaultName.countryEnc = CTC_PRINTABLE;
  16314. XMEMCPY(certDefaultName.state, "Oregon", sizeof("Oregon"));
  16315. certDefaultName.stateEnc = CTC_UTF8;
  16316. XMEMCPY(certDefaultName.street, "Main St", sizeof("Main St"));
  16317. certDefaultName.streetEnc = CTC_UTF8;
  16318. XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
  16319. certDefaultName.localityEnc = CTC_UTF8;
  16320. XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
  16321. certDefaultName.surEnc = CTC_UTF8;
  16322. XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
  16323. certDefaultName.orgEnc = CTC_UTF8;
  16324. XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
  16325. certDefaultName.unitEnc = CTC_UTF8;
  16326. XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  16327. certDefaultName.commonNameEnc = CTC_UTF8;
  16328. XMEMCPY(certDefaultName.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  16329. certDefaultName.serialDevEnc = CTC_PRINTABLE;
  16330. XMEMCPY(certDefaultName.postalCode, "12-456", sizeof("12-456"));
  16331. certDefaultName.postalCodeEnc = CTC_PRINTABLE;
  16332. #ifdef WOLFSSL_CERT_EXT
  16333. XMEMCPY(certDefaultName.busCat, "Private Organization", sizeof("Private Organization"));
  16334. certDefaultName.busCatEnc = CTC_UTF8;
  16335. XMEMCPY(certDefaultName.joiSt, "US", sizeof("US"));
  16336. certDefaultName.joiStEnc = CTC_PRINTABLE;
  16337. XMEMCPY(certDefaultName.joiC, "Oregon", sizeof("Oregon"));
  16338. certDefaultName.joiCEnc = CTC_PRINTABLE;
  16339. #endif
  16340. XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
  16341. XMEMCPY(certDefaultName.userId, "TestUserID", sizeof("TestUserID"));
  16342. certDefaultName.userIdEnc = CTC_PRINTABLE;
  16343. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16344. /* test having additional OUs and setting DC */
  16345. n = &certDefaultName.name[0];
  16346. n->id = ASN_ORGUNIT_NAME;
  16347. n->type = CTC_UTF8;
  16348. n->sz = XSTRLEN("Development-2");
  16349. XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
  16350. #if CTC_MAX_ATTRIB > 3
  16351. n = &certDefaultName.name[1];
  16352. n->id = ASN_DOMAIN_COMPONENT;
  16353. n->type = CTC_UTF8;
  16354. n->sz = XSTRLEN("com");
  16355. XMEMCPY(n->value, "com", sizeof("com"));
  16356. n = &certDefaultName.name[2];
  16357. n->id = ASN_DOMAIN_COMPONENT;
  16358. n->type = CTC_UTF8;
  16359. n->sz = XSTRLEN("wolfssl");
  16360. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  16361. #endif
  16362. #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */
  16363. #ifdef WOLFSSL_CUSTOM_OID
  16364. /* TODO: Add test case for custom OID's */
  16365. #endif
  16366. }
  16367. #ifdef WOLFSSL_CERT_EXT
  16368. #if ((defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  16369. defined(WOLFSSL_TEST_CERT)) || defined(HAVE_ECC)
  16370. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] =
  16371. "digitalSignature,nonRepudiation";
  16372. #endif
  16373. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME)
  16374. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] =
  16375. "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement";
  16376. #endif
  16377. #endif /* WOLFSSL_CERT_EXT */
  16378. #endif /* WOLFSSL_CERT_GEN */
  16379. #ifndef NO_RSA
  16380. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16381. !defined(NO_FILESYSTEM)
  16382. static const byte minSerial[] = { 0x02, 0x01, 0x01 };
  16383. static const byte minName[] = { 0x30, 0x00 };
  16384. static const byte nameBad[] = {
  16385. 0x30, 0x08,
  16386. 0x31, 0x06,
  16387. 0x30, 0x04,
  16388. 0x06, 0x02,
  16389. 0x55, 0x04,
  16390. };
  16391. static const byte minDates[] = {
  16392. 0x30, 0x1e,
  16393. 0x17, 0x0d,
  16394. 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35,
  16395. 0x32, 0x33, 0x31, 0x30, 0x5a,
  16396. 0x17, 0x0d,
  16397. 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35,
  16398. 0x32, 0x33, 0x31, 0x30, 0x5a
  16399. };
  16400. static const byte minPubKey[] = {
  16401. 0x30, 0x1c,
  16402. 0x30, 0x0d,
  16403. 0x06, 0x09,
  16404. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16405. 0x01,
  16406. 0x05, 0x00,
  16407. 0x03, 0x0b,
  16408. 0x00, 0x30, 0x08,
  16409. 0x02, 0x01,
  16410. 0x03,
  16411. 0x02, 0x03,
  16412. 0x01, 0x00, 0x01
  16413. };
  16414. static const byte minSigAlg[] = {
  16415. 0x30, 0x0d,
  16416. 0x06, 0x09,
  16417. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16418. 0x0b,
  16419. 0x05, 0x00
  16420. };
  16421. static const byte minSig[] = {
  16422. 0x03, 0x01,
  16423. 0x00
  16424. };
  16425. static int add_seq(byte* certData, int offset, byte* data, byte length)
  16426. {
  16427. XMEMMOVE(certData + offset + 2, data, length);
  16428. certData[offset++] = 0x30;
  16429. certData[offset++] = length;
  16430. return offset + length;
  16431. }
  16432. static int add_data(byte* certData, int offset, const byte* data, byte length)
  16433. {
  16434. XMEMCPY(certData + offset, data, length);
  16435. return offset + length;
  16436. }
  16437. static wc_test_ret_t cert_asn1_test(void)
  16438. {
  16439. wc_test_ret_t ret;
  16440. int len[3];
  16441. DecodedCert cert;
  16442. byte certData[114];
  16443. byte* badCert = NULL;
  16444. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16445. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16446. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16447. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16448. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16449. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16450. len[1] = add_seq(certData, 0, certData, len[2]);
  16451. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16452. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16453. len[0] = add_seq(certData, 0, certData, len[1]);
  16454. /* Minimal good certificate */
  16455. InitDecodedCert(&cert, certData, len[0], 0);
  16456. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16457. FreeDecodedCert(&cert);
  16458. if (ret != 0)
  16459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16460. /* Bad issuer name */
  16461. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16462. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16463. len[2] = add_data(certData, len[2], nameBad, (byte)sizeof(nameBad));
  16464. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16465. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16466. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16467. len[1] = add_seq(certData, 0, certData, len[2]);
  16468. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16469. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16470. len[0] = add_seq(certData, 0, certData, len[1]);
  16471. /* Put data into allocated buffer to allow access error checking. */
  16472. badCert = (byte*)XMALLOC(len[0], HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16473. XMEMCPY(badCert, certData, len[0]);
  16474. InitDecodedCert(&cert, badCert, len[0], 0);
  16475. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16476. FreeDecodedCert(&cert);
  16477. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  16478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16479. }
  16480. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16481. badCert = NULL;
  16482. ret = 0;
  16483. done:
  16484. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16485. return ret;
  16486. }
  16487. static wc_test_ret_t cert_load_bad(const char* fname, byte* tmp, int err)
  16488. {
  16489. wc_test_ret_t ret;
  16490. DecodedCert cert;
  16491. XFILE file;
  16492. size_t bytes;
  16493. if ((fname == NULL) || (tmp == NULL)) {
  16494. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  16495. }
  16496. file = XFOPEN(fname, "rb");
  16497. if (!file) {
  16498. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16499. }
  16500. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16501. XFCLOSE(file);
  16502. if (bytes == 0) {
  16503. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16504. }
  16505. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16506. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16507. FreeDecodedCert(&cert);
  16508. if (ret != err) {
  16509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16510. }
  16511. ret = 0;
  16512. done:
  16513. return ret;
  16514. }
  16515. static wc_test_ret_t cert_bad_asn1_test(void)
  16516. {
  16517. wc_test_ret_t ret = 0;
  16518. byte* tmp;
  16519. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16520. if (tmp == NULL) {
  16521. ret = WC_TEST_RET_ENC_ERRNO;
  16522. }
  16523. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16524. if (ret == 0) {
  16525. /* Serial number: 0xff 0xa8. 0xff and top bit set on next byte invalid.
  16526. */
  16527. ret = cert_load_bad(certBadNegInt, tmp, ASN_EXPECT_0_E);
  16528. }
  16529. #endif
  16530. if (ret == 0) {
  16531. /* Subject name OID: 55 04 f4. Last byte with top bit set invalid. */
  16532. ret = cert_load_bad(certBadOid, tmp, ASN_PARSE_E);
  16533. }
  16534. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16535. if (ret == 0) {
  16536. /* Issuer name UTF8STRING: df 52 4e 44. Top bit of second byte not set.
  16537. */
  16538. ret = cert_load_bad(certBadUtf8, tmp, ASN_PARSE_E);
  16539. }
  16540. #endif
  16541. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16542. return ret;
  16543. }
  16544. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void)
  16545. {
  16546. #if !defined(NO_FILESYSTEM)
  16547. DecodedCert cert;
  16548. byte* tmp;
  16549. size_t bytes;
  16550. XFILE file;
  16551. wc_test_ret_t ret;
  16552. WOLFSSL_ENTER("cert_test");
  16553. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16554. if (tmp == NULL)
  16555. return WC_TEST_RET_ENC_ERRNO;
  16556. /* Certificate with Name Constraints extension. */
  16557. file = XFOPEN(certExtNc, "rb");
  16558. if (!file) {
  16559. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16560. }
  16561. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16562. XFCLOSE(file);
  16563. if (bytes == 0)
  16564. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16565. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16566. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16567. if (ret != 0)
  16568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16569. FreeDecodedCert(&cert);
  16570. /* Certificate with Inhibit Any Policy extension. */
  16571. file = XFOPEN(certExtIa, "rb");
  16572. if (!file) {
  16573. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16574. }
  16575. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16576. XFCLOSE(file);
  16577. if (bytes == 0)
  16578. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16579. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16580. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16581. if (ret != 0)
  16582. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16583. FreeDecodedCert(&cert);
  16584. /* Certificate with Netscape Certificate Type extension. */
  16585. file = XFOPEN(certExtNct, "rb");
  16586. if (!file) {
  16587. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16588. }
  16589. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16590. XFCLOSE(file);
  16591. if (bytes == 0)
  16592. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16593. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16594. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16595. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  16596. if (ret != 0)
  16597. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16598. #else
  16599. if (ret != WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
  16600. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16601. }
  16602. ret = 0;
  16603. #endif
  16604. done:
  16605. FreeDecodedCert(&cert);
  16606. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16607. #endif /* !NO_FILESYSTEM */
  16608. if (ret == 0)
  16609. ret = cert_asn1_test();
  16610. if (ret == 0)
  16611. ret = cert_bad_asn1_test();
  16612. return ret;
  16613. }
  16614. #endif /* WOLFSSL_TEST_CERT */
  16615. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  16616. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  16617. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void)
  16618. {
  16619. DecodedCert cert;
  16620. byte* tmp;
  16621. size_t bytes;
  16622. XFILE file;
  16623. wc_test_ret_t ret;
  16624. /* created from rsa_test : othercert.der */
  16625. byte skid_rsa[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16626. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16627. /* created from rsa_test : othercert.der */
  16628. byte akid_rsa[] = "\x27\x8E\x67\x11\x74\xC3\x26\x1D\x3F\xED"
  16629. "\x33\x63\xB3\xA4\xD8\x1D\x30\xE5\xE8\xD5";
  16630. #ifdef HAVE_ECC
  16631. /* created from ecc_test_cert_gen : certecc.der */
  16632. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16633. /* Authority key id from ./certs/ca-ecc384-cert.pem */
  16634. byte akid_ecc[] = "\xAB\xE0\xC3\x26\x4C\x18\xD4\x72\xBB\xD2"
  16635. "\x84\x8C\x9C\x0A\x05\x92\x80\x12\x53\x52";
  16636. #else
  16637. /* Authority key id from ./certs/ca-ecc-cert.pem */
  16638. byte akid_ecc[] = "\x56\x8E\x9A\xC3\xF0\x42\xDE\x18\xB9\x45"
  16639. "\x55\x6E\xF9\x93\xCF\xEA\xC3\xF3\xA5\x21";
  16640. #endif
  16641. #endif /* HAVE_ECC */
  16642. /* created from rsa_test : cert.der */
  16643. byte kid_ca[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16644. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16645. WOLFSSL_ENTER("certext_test");
  16646. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16647. if (tmp == NULL)
  16648. return WC_TEST_RET_ENC_ERRNO;
  16649. /* load othercert.der (Cert signed by an authority) */
  16650. file = XFOPEN(otherCertDerFile, "rb");
  16651. if (!file) {
  16652. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16653. return WC_TEST_RET_ENC_ERRNO;
  16654. }
  16655. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16656. XFCLOSE(file);
  16657. if (bytes == 0)
  16658. return WC_TEST_RET_ENC_ERRNO;
  16659. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16660. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16661. if (ret != 0)
  16662. return WC_TEST_RET_ENC_EC(ret);
  16663. /* check the SKID from a RSA certificate */
  16664. if ((sizeof(skid_rsa) - 1 != cert.extSubjKeyIdSz) ||
  16665. (XMEMCMP(skid_rsa, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16666. return WC_TEST_RET_ENC_NC;
  16667. /* check the AKID from an RSA certificate */
  16668. if ((sizeof(akid_rsa) - 1 != cert.extAuthKeyIdSz) ||
  16669. (XMEMCMP(akid_rsa, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16670. return WC_TEST_RET_ENC_NC;
  16671. /* check the Key Usage from an RSA certificate */
  16672. if (!cert.extKeyUsageSet)
  16673. return WC_TEST_RET_ENC_NC;
  16674. if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE))
  16675. return WC_TEST_RET_ENC_NC;
  16676. /* check the CA Basic Constraints from an RSA certificate */
  16677. if (cert.isCA)
  16678. return WC_TEST_RET_ENC_NC;
  16679. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16680. /* check the Certificate Policies Id */
  16681. if (cert.extCertPoliciesNb != 1)
  16682. return WC_TEST_RET_ENC_NC;
  16683. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16684. return WC_TEST_RET_ENC_NC;
  16685. #endif
  16686. FreeDecodedCert(&cert);
  16687. #ifdef HAVE_ECC
  16688. /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */
  16689. file = XFOPEN(certEccDerFile, "rb");
  16690. if (!file) {
  16691. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16692. return WC_TEST_RET_ENC_ERRNO;
  16693. }
  16694. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16695. XFCLOSE(file);
  16696. if (bytes == 0)
  16697. return WC_TEST_RET_ENC_ERRNO;
  16698. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16699. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16700. if (ret != 0)
  16701. return WC_TEST_RET_ENC_EC(ret);
  16702. /* check the SKID from a ECC certificate - generated dynamically */
  16703. /* check the AKID from an ECC certificate */
  16704. if ((sizeof(akid_ecc) - 1 != cert.extAuthKeyIdSz) ||
  16705. (XMEMCMP(akid_ecc, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16706. return WC_TEST_RET_ENC_NC;
  16707. /* check the Key Usage from an ECC certificate */
  16708. if (!cert.extKeyUsageSet)
  16709. return WC_TEST_RET_ENC_NC;
  16710. if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT))
  16711. return WC_TEST_RET_ENC_NC;
  16712. /* check the CA Basic Constraints from an ECC certificate */
  16713. if (cert.isCA)
  16714. return WC_TEST_RET_ENC_NC;
  16715. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16716. /* check the Certificate Policies Id */
  16717. if (cert.extCertPoliciesNb != 2)
  16718. return WC_TEST_RET_ENC_NC;
  16719. if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32))
  16720. return WC_TEST_RET_ENC_NC;
  16721. if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22))
  16722. return WC_TEST_RET_ENC_NC;
  16723. #endif
  16724. FreeDecodedCert(&cert);
  16725. #endif /* HAVE_ECC */
  16726. /* load cert.der (self signed certificate) */
  16727. file = XFOPEN(certDerFile, "rb");
  16728. if (!file) {
  16729. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16730. return WC_TEST_RET_ENC_ERRNO;
  16731. }
  16732. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16733. XFCLOSE(file);
  16734. if (bytes == 0)
  16735. return WC_TEST_RET_ENC_ERRNO;
  16736. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16737. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16738. if (ret != 0)
  16739. return WC_TEST_RET_ENC_EC(ret);
  16740. /* check the SKID from a CA certificate */
  16741. if ((sizeof(kid_ca) - 1 != cert.extSubjKeyIdSz) ||
  16742. (XMEMCMP(kid_ca, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16743. return WC_TEST_RET_ENC_NC;
  16744. /* check the AKID from an CA certificate */
  16745. if ((sizeof(kid_ca) - 1 != cert.extAuthKeyIdSz) ||
  16746. (XMEMCMP(kid_ca, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16747. return WC_TEST_RET_ENC_NC;
  16748. /* check the Key Usage from CA certificate */
  16749. if (!cert.extKeyUsageSet)
  16750. return WC_TEST_RET_ENC_NC;
  16751. if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN))
  16752. return WC_TEST_RET_ENC_NC;
  16753. /* check the CA Basic Constraints CA certificate */
  16754. if (!cert.isCA)
  16755. return WC_TEST_RET_ENC_NC;
  16756. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16757. /* check the Certificate Policies Id */
  16758. if (cert.extCertPoliciesNb != 2)
  16759. return WC_TEST_RET_ENC_NC;
  16760. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16761. return WC_TEST_RET_ENC_NC;
  16762. if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25))
  16763. return WC_TEST_RET_ENC_NC;
  16764. #endif
  16765. FreeDecodedCert(&cert);
  16766. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16767. return 0;
  16768. }
  16769. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_TEST_CERT &&
  16770. !NO_FILESYSTEM && !NO_RSA && WOLFSSL_CERT_GEN */
  16771. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  16772. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  16773. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void)
  16774. {
  16775. wc_test_ret_t ret = 0;
  16776. Cert cert;
  16777. FILE* file;
  16778. byte* der;
  16779. word32 derSz;
  16780. WOLFSSL_ENTER("decodedCertCache_test");
  16781. derSz = FOURK_BUF;
  16782. der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16783. if (der == NULL)
  16784. ret = WC_TEST_RET_ENC_NC;
  16785. if (ret == 0) {
  16786. /* load cert.der */
  16787. file = XFOPEN(certDerFile, "rb");
  16788. if (file != NULL) {
  16789. derSz = (word32)XFREAD(der, 1, FOURK_BUF, file);
  16790. XFCLOSE(file);
  16791. if (derSz == 0)
  16792. ret = WC_TEST_RET_ENC_ERRNO;
  16793. }
  16794. else
  16795. ret = WC_TEST_RET_ENC_ERRNO;
  16796. }
  16797. if (ret == 0) {
  16798. ret = wc_InitCert_ex(&cert, HEAP_HINT, devId);
  16799. if (ret != 0)
  16800. ret = WC_TEST_RET_ENC_EC(ret);
  16801. }
  16802. if (ret == 0) {
  16803. ret = wc_SetSubjectBuffer(&cert, der, derSz);
  16804. if (ret != 0)
  16805. ret = WC_TEST_RET_ENC_EC(ret);
  16806. }
  16807. if (ret == 0) {
  16808. ret = wc_SetSubjectBuffer(NULL, der, derSz);
  16809. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16810. ret = 0;
  16811. else
  16812. ret = WC_TEST_RET_ENC_EC(ret);
  16813. }
  16814. if (ret == 0) {
  16815. ret = wc_SetSubjectRaw(&cert, der, derSz);
  16816. if (ret != 0)
  16817. ret = WC_TEST_RET_ENC_EC(ret);
  16818. }
  16819. if (ret == 0) {
  16820. ret = wc_SetSubjectRaw(NULL, der, derSz);
  16821. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16822. ret = 0;
  16823. else
  16824. ret = WC_TEST_RET_ENC_EC(ret);
  16825. }
  16826. if (ret == 0) {
  16827. ret = wc_SetIssuerBuffer(&cert, der, derSz);
  16828. if (ret != 0)
  16829. ret = WC_TEST_RET_ENC_EC(ret);
  16830. }
  16831. if (ret == 0) {
  16832. ret = wc_SetIssuerBuffer(NULL, der, derSz);
  16833. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16834. ret = 0;
  16835. else
  16836. ret = WC_TEST_RET_ENC_EC(ret);
  16837. }
  16838. if (ret == 0) {
  16839. ret = wc_SetIssuerRaw(&cert, der, derSz);
  16840. if (ret != 0)
  16841. ret = WC_TEST_RET_ENC_EC(ret);
  16842. }
  16843. if (ret == 0) {
  16844. ret = wc_SetIssuerRaw(NULL, der, derSz);
  16845. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16846. ret = 0;
  16847. else
  16848. ret = WC_TEST_RET_ENC_EC(ret);
  16849. }
  16850. #ifdef WOLFSSL_ALT_NAMES
  16851. if (ret == 0) {
  16852. ret = wc_SetAltNamesBuffer(&cert, der, derSz);
  16853. if (ret != 0)
  16854. ret = WC_TEST_RET_ENC_EC(ret);
  16855. }
  16856. if (ret == 0) {
  16857. ret = wc_SetAltNamesBuffer(NULL, der, derSz);
  16858. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16859. ret = 0;
  16860. else
  16861. ret = WC_TEST_RET_ENC_EC(ret);
  16862. }
  16863. if (ret == 0) {
  16864. ret = wc_SetDatesBuffer(&cert, der, derSz);
  16865. if (ret != 0)
  16866. ret = WC_TEST_RET_ENC_EC(ret);
  16867. }
  16868. if (ret == 0) {
  16869. ret = wc_SetDatesBuffer(NULL, der, derSz);
  16870. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16871. ret = 0;
  16872. else
  16873. ret = WC_TEST_RET_ENC_EC(ret);
  16874. }
  16875. #endif
  16876. if (ret == 0) {
  16877. ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz);
  16878. if (ret != 0)
  16879. ret = WC_TEST_RET_ENC_EC(ret);
  16880. }
  16881. if (ret == 0) {
  16882. ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz);
  16883. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16884. ret = 0;
  16885. else
  16886. ret = WC_TEST_RET_ENC_NC;
  16887. }
  16888. wc_SetCert_Free(&cert);
  16889. if (ret == 0) {
  16890. if(cert.decodedCert != NULL)
  16891. ret = WC_TEST_RET_ENC_NC;
  16892. }
  16893. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16894. return ret;
  16895. }
  16896. #endif /* defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) &&
  16897. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) */
  16898. #define RSA_TEST_BYTES 512 /* up to 4096-bit key */
  16899. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  16900. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16901. static wc_test_ret_t rsa_flatten_test(RsaKey* key)
  16902. {
  16903. wc_test_ret_t ret;
  16904. byte e[RSA_TEST_BYTES];
  16905. byte n[RSA_TEST_BYTES];
  16906. word32 eSz = sizeof(e);
  16907. word32 nSz = sizeof(n);
  16908. /* Parameter Validation testing. */
  16909. ret = wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz);
  16910. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16911. return WC_TEST_RET_ENC_EC(ret);
  16912. ret = wc_RsaFlattenPublicKey(key, NULL, &eSz, n, &nSz);
  16913. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16914. return WC_TEST_RET_ENC_EC(ret);
  16915. ret = wc_RsaFlattenPublicKey(key, e, NULL, n, &nSz);
  16916. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16917. return WC_TEST_RET_ENC_EC(ret);
  16918. ret = wc_RsaFlattenPublicKey(key, e, &eSz, NULL, &nSz);
  16919. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16920. return WC_TEST_RET_ENC_EC(ret);
  16921. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, NULL);
  16922. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16923. return WC_TEST_RET_ENC_EC(ret);
  16924. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16925. if (ret != 0)
  16926. return WC_TEST_RET_ENC_EC(ret);
  16927. eSz = 0;
  16928. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16929. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16930. return WC_TEST_RET_ENC_EC(ret);
  16931. eSz = sizeof(e);
  16932. nSz = 0;
  16933. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16934. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16935. return WC_TEST_RET_ENC_EC(ret);
  16936. return 0;
  16937. }
  16938. #endif /* NO_ASN */
  16939. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  16940. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16941. static wc_test_ret_t rsa_export_key_test(RsaKey* key)
  16942. {
  16943. wc_test_ret_t ret;
  16944. byte e[3];
  16945. word32 eSz = sizeof(e);
  16946. byte n[RSA_TEST_BYTES];
  16947. word32 nSz = sizeof(n);
  16948. byte d[RSA_TEST_BYTES];
  16949. word32 dSz = sizeof(d);
  16950. byte p[RSA_TEST_BYTES/2];
  16951. word32 pSz = sizeof(p);
  16952. byte q[RSA_TEST_BYTES/2];
  16953. word32 qSz = sizeof(q);
  16954. word32 zero = 0;
  16955. ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16956. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16957. return WC_TEST_RET_ENC_EC(ret);
  16958. ret = wc_RsaExportKey(key, NULL, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16959. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16960. return WC_TEST_RET_ENC_EC(ret);
  16961. ret = wc_RsaExportKey(key, e, NULL, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16962. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16963. return WC_TEST_RET_ENC_EC(ret);
  16964. ret = wc_RsaExportKey(key, e, &eSz, NULL, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16965. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16966. return WC_TEST_RET_ENC_EC(ret);
  16967. ret = wc_RsaExportKey(key, e, &eSz, n, NULL, d, &dSz, p, &pSz, q, &qSz);
  16968. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16969. return WC_TEST_RET_ENC_EC(ret);
  16970. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, NULL, &dSz, p, &pSz, q, &qSz);
  16971. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16972. return WC_TEST_RET_ENC_EC(ret);
  16973. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, NULL, p, &pSz, q, &qSz);
  16974. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16975. return WC_TEST_RET_ENC_EC(ret);
  16976. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, NULL, &pSz, q, &qSz);
  16977. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16978. return WC_TEST_RET_ENC_EC(ret);
  16979. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, NULL, q, &qSz);
  16980. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16981. return WC_TEST_RET_ENC_EC(ret);
  16982. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, NULL, &qSz);
  16983. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16984. return WC_TEST_RET_ENC_EC(ret);
  16985. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, NULL);
  16986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16987. return WC_TEST_RET_ENC_EC(ret);
  16988. ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16989. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16990. return WC_TEST_RET_ENC_EC(ret);
  16991. ret = wc_RsaExportKey(key, e, &eSz, n, &zero, d, &dSz, p, &pSz, q, &qSz);
  16992. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16993. return WC_TEST_RET_ENC_EC(ret);
  16994. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  16995. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz);
  16996. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16997. return WC_TEST_RET_ENC_EC(ret);
  16998. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, q, &qSz);
  16999. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17000. return WC_TEST_RET_ENC_EC(ret);
  17001. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &zero);
  17002. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17003. return WC_TEST_RET_ENC_EC(ret);
  17004. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  17005. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  17006. if (ret != 0)
  17007. return WC_TEST_RET_ENC_EC(ret);
  17008. return 0;
  17009. }
  17010. #endif /* !HAVE_FIPS && !NO_ASN && !WOLFSSL_RSA_VERIFY_ONLY */
  17011. #ifndef NO_SIG_WRAPPER
  17012. static wc_test_ret_t rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
  17013. {
  17014. wc_test_ret_t ret;
  17015. word32 sigSz;
  17016. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  17017. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  17018. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17019. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17020. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17021. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17022. };
  17023. WOLFSSL_SMALL_STACK_STATIC const byte hashEnc[] = {
  17024. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  17025. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  17026. 0x00, 0x04, 0x20,
  17027. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17028. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17029. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17030. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17031. };
  17032. word32 inLen = (word32)XSTRLEN((char*)in);
  17033. byte out[RSA_TEST_BYTES];
  17034. /* Parameter Validation testing. */
  17035. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen);
  17036. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17037. return WC_TEST_RET_ENC_EC(ret);
  17038. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0);
  17039. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17040. return WC_TEST_RET_ENC_EC(ret);
  17041. sigSz = (word32)modLen;
  17042. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17043. inLen, out, &sigSz, key, keyLen, rng);
  17044. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17045. return WC_TEST_RET_ENC_EC(ret);
  17046. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17047. 0, out, &sigSz, key, keyLen, rng);
  17048. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17049. return WC_TEST_RET_ENC_EC(ret);
  17050. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17051. inLen, NULL, &sigSz, key, keyLen, rng);
  17052. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17053. return WC_TEST_RET_ENC_EC(ret);
  17054. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17055. inLen, out, NULL, key, keyLen, rng);
  17056. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17057. return WC_TEST_RET_ENC_EC(ret);
  17058. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17059. inLen, out, &sigSz, NULL, keyLen, rng);
  17060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17061. return WC_TEST_RET_ENC_EC(ret);
  17062. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17063. inLen, out, &sigSz, key, 0, rng);
  17064. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17065. return WC_TEST_RET_ENC_EC(ret);
  17066. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17067. inLen, out, &sigSz, key, keyLen, NULL);
  17068. #if defined(WOLFSSL_AFALG_XILINX_RSA) || defined(WOLFSSL_XILINX_CRYPT)
  17069. /* blinding / rng handled with hardware acceleration */
  17070. if (ret != 0)
  17071. #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
  17072. /* async may not require RNG */
  17073. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17074. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID))
  17075. #else
  17076. if (ret != 0 && ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17077. #endif
  17078. #elif defined(HAVE_FIPS) || !defined(WC_RSA_BLINDING)
  17079. /* FIPS140 implementation does not do blinding */
  17080. if (ret != 0)
  17081. #elif defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
  17082. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17083. #elif defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050)
  17084. /* RNG is handled by hardware */
  17085. if (ret != 0)
  17086. #else
  17087. if (ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17088. #endif
  17089. return WC_TEST_RET_ENC_EC(ret);
  17090. sigSz = 0;
  17091. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17092. inLen, out, &sigSz, key, keyLen, rng);
  17093. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17094. return WC_TEST_RET_ENC_EC(ret);
  17095. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17096. inLen, out, (word32)modLen, key, keyLen);
  17097. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17098. return WC_TEST_RET_ENC_EC(ret);
  17099. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17100. 0, out, (word32)modLen, key, keyLen);
  17101. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17102. return WC_TEST_RET_ENC_EC(ret);
  17103. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17104. inLen, NULL, (word32)modLen, key, keyLen);
  17105. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17106. return WC_TEST_RET_ENC_EC(ret);
  17107. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17108. inLen, out, 0, key, keyLen);
  17109. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17110. return WC_TEST_RET_ENC_EC(ret);
  17111. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17112. inLen, out, (word32)modLen, NULL, keyLen);
  17113. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17114. return WC_TEST_RET_ENC_EC(ret);
  17115. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17116. inLen, out, (word32)modLen, key, 0);
  17117. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17118. return WC_TEST_RET_ENC_EC(ret);
  17119. #ifndef HAVE_ECC
  17120. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen);
  17121. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17122. return WC_TEST_RET_ENC_EC(ret);
  17123. #endif
  17124. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17125. return 0;
  17126. #endif
  17127. /* Use APIs. */
  17128. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen);
  17129. if (ret != modLen)
  17130. return WC_TEST_RET_ENC_EC(ret);
  17131. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen);
  17132. if (ret != modLen)
  17133. return WC_TEST_RET_ENC_EC(ret);
  17134. sigSz = (word32)ret;
  17135. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  17136. XMEMSET(out, 0, sizeof(out));
  17137. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17138. inLen, out, &sigSz, key, keyLen, rng);
  17139. if (ret != 0)
  17140. return WC_TEST_RET_ENC_EC(ret);
  17141. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17142. inLen, out, (word32)modLen, key, keyLen);
  17143. if (ret != 0)
  17144. return WC_TEST_RET_ENC_EC(ret);
  17145. sigSz = (word32)sizeof(out);
  17146. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17147. in, inLen, out, &sigSz, key, keyLen, rng);
  17148. if (ret != 0)
  17149. return WC_TEST_RET_ENC_EC(ret);
  17150. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17151. in, inLen, out, (word32)modLen, key, keyLen);
  17152. if (ret != 0)
  17153. return WC_TEST_RET_ENC_EC(ret);
  17154. /* Wrong signature type. */
  17155. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17156. inLen, out, (word32)modLen, key, keyLen);
  17157. if (ret == 0)
  17158. return WC_TEST_RET_ENC_EC(ret);
  17159. /* check hash functions */
  17160. sigSz = (word32)sizeof(out);
  17161. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17162. hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng);
  17163. if (ret != 0)
  17164. return WC_TEST_RET_ENC_EC(ret);
  17165. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17166. hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen);
  17167. if (ret != 0)
  17168. return WC_TEST_RET_ENC_EC(ret);
  17169. sigSz = (word32)sizeof(out);
  17170. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17171. hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng);
  17172. if (ret != 0)
  17173. return WC_TEST_RET_ENC_EC(ret);
  17174. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17175. hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen);
  17176. if (ret != 0)
  17177. return WC_TEST_RET_ENC_EC(ret);
  17178. #else
  17179. (void)hash;
  17180. (void)hashEnc;
  17181. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  17182. return 0;
  17183. }
  17184. #endif /* !NO_SIG_WRAPPER */
  17185. #ifdef WC_RSA_NONBLOCK
  17186. static wc_test_ret_t rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out,
  17187. word32 outSz, byte* plain, word32 plainSz, WC_RNG* rng)
  17188. {
  17189. wc_test_ret_t ret = 0;
  17190. int count;
  17191. int signSz = 0;
  17192. RsaNb nb;
  17193. byte* inlinePlain = NULL;
  17194. /* Enable non-blocking RSA mode - provide context */
  17195. ret = wc_RsaSetNonBlock(key, &nb);
  17196. if (ret != 0)
  17197. return ret;
  17198. #ifdef WC_RSA_NONBLOCK_TIME
  17199. /* Enable time based RSA blocking. 8 microseconds max (3.1GHz) */
  17200. ret = wc_RsaSetNonBlockTime(key, 8, 3100);
  17201. if (ret != 0)
  17202. return ret;
  17203. #endif
  17204. count = 0;
  17205. do {
  17206. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, rng);
  17207. count++; /* track number of would blocks */
  17208. if (ret == FP_WOULDBLOCK) {
  17209. /* do "other" work here */
  17210. }
  17211. } while (ret == FP_WOULDBLOCK);
  17212. if (ret < 0) {
  17213. return ret;
  17214. }
  17215. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17216. printf("RSA non-block sign: %d times\n", count);
  17217. #endif
  17218. signSz = ret;
  17219. /* Test non-blocking verify */
  17220. XMEMSET(plain, 0, plainSz);
  17221. count = 0;
  17222. do {
  17223. ret = wc_RsaSSL_Verify(out, (word32)signSz, plain, plainSz, key);
  17224. count++; /* track number of would blocks */
  17225. if (ret == FP_WOULDBLOCK) {
  17226. /* do "other" work here */
  17227. }
  17228. } while (ret == FP_WOULDBLOCK);
  17229. if (ret < 0) {
  17230. return ret;
  17231. }
  17232. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17233. printf("RSA non-block verify: %d times\n", count);
  17234. #endif
  17235. if (signSz == ret && XMEMCMP(plain, in, (size_t)ret)) {
  17236. return SIG_VERIFY_E;
  17237. }
  17238. /* Test inline non-blocking verify */
  17239. count = 0;
  17240. do {
  17241. ret = wc_RsaSSL_VerifyInline(out, (word32)signSz, &inlinePlain, key);
  17242. count++; /* track number of would blocks */
  17243. if (ret == FP_WOULDBLOCK) {
  17244. /* do "other" work here */
  17245. }
  17246. } while (ret == FP_WOULDBLOCK);
  17247. if (ret < 0) {
  17248. return ret;
  17249. }
  17250. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17251. printf("RSA non-block inline verify: %d times\n", count);
  17252. #endif
  17253. if (signSz == ret && XMEMCMP(inlinePlain, in, (size_t)ret)) {
  17254. return SIG_VERIFY_E;
  17255. }
  17256. /* Disabling non-block RSA mode */
  17257. ret = wc_RsaSetNonBlock(key, NULL);
  17258. (void)count;
  17259. return 0;
  17260. }
  17261. #endif
  17262. #if !defined(NO_ASN)
  17263. static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
  17264. {
  17265. wc_test_ret_t ret;
  17266. word32 inSz;
  17267. word32 inOutIdx;
  17268. WOLFSSL_SMALL_STACK_STATIC const byte n[2] = { 0x00, 0x23 };
  17269. WOLFSSL_SMALL_STACK_STATIC const byte e[2] = { 0x00, 0x03 };
  17270. WOLFSSL_SMALL_STACK_STATIC const byte good[] = { 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1,
  17271. 0x03 };
  17272. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgId[] = {
  17273. 0x30, 0x18, 0x30, 0x16,
  17274. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17275. 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17276. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgIdNull[] = {
  17277. 0x30, 0x1a, 0x30, 0x18,
  17278. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17279. 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17280. 0x02, 0x1, 0x03 };
  17281. WOLFSSL_SMALL_STACK_STATIC const byte badAlgIdNull[] = {
  17282. 0x30, 0x1b, 0x30, 0x19,
  17283. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17284. 0x05, 0x01, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17285. 0x02, 0x1, 0x03 };
  17286. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitString[] = {
  17287. 0x30, 0x18, 0x30, 0x16,
  17288. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17289. 0x04, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17290. WOLFSSL_SMALL_STACK_STATIC const byte badBitStringLen[] = {
  17291. 0x30, 0x18, 0x30, 0x16,
  17292. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17293. 0x03, 0x0a, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17294. WOLFSSL_SMALL_STACK_STATIC const byte badNoSeq[] = {
  17295. 0x30, 0x16, 0x30, 0x14,
  17296. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17297. 0x07, 0x00, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17298. WOLFSSL_SMALL_STACK_STATIC const byte badNoObj[] = {
  17299. 0x30, 0x0f, 0x30, 0x0d, 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06,
  17300. 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17301. WOLFSSL_SMALL_STACK_STATIC const byte badIntN[] = {
  17302. 0x30, 0x06, 0x02, 0x05, 0x23, 0x02, 0x1, 0x03 };
  17303. WOLFSSL_SMALL_STACK_STATIC const byte badNotIntE[] = {
  17304. 0x30, 0x06, 0x02, 0x01, 0x23, 0x04, 0x1, 0x03 };
  17305. WOLFSSL_SMALL_STACK_STATIC const byte badLength[] = {
  17306. 0x30, 0x04, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17307. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrNoZero[] = {
  17308. 0x30, 0x17, 0x30, 0x15,
  17309. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17310. 0x03, 0x08, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17311. ret = wc_InitRsaKey(keyPub, NULL);
  17312. if (ret != 0)
  17313. return WC_TEST_RET_ENC_EC(ret);
  17314. /* Parameter Validation testing. */
  17315. ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, sizeof(e), keyPub);
  17316. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17317. ret = WC_TEST_RET_ENC_EC(ret);
  17318. goto done;
  17319. }
  17320. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), NULL, sizeof(e), keyPub);
  17321. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17322. ret = WC_TEST_RET_ENC_EC(ret);
  17323. goto done;
  17324. }
  17325. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), NULL);
  17326. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17327. ret = WC_TEST_RET_ENC_EC(ret);
  17328. goto done;
  17329. }
  17330. ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
  17331. #if defined(USE_INTEGER_HEAP_MATH)
  17332. if (ret != 0)
  17333. #else
  17334. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17335. #endif
  17336. {
  17337. ret = WC_TEST_RET_ENC_EC(ret);
  17338. goto done;
  17339. }
  17340. wc_FreeRsaKey(keyPub);
  17341. ret = wc_InitRsaKey(keyPub, NULL);
  17342. if (ret != 0)
  17343. return WC_TEST_RET_ENC_EC(ret);
  17344. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
  17345. #if defined(USE_INTEGER_HEAP_MATH)
  17346. if (ret != 0)
  17347. #else
  17348. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17349. #endif
  17350. {
  17351. ret = WC_TEST_RET_ENC_EC(ret);
  17352. goto done;
  17353. }
  17354. wc_FreeRsaKey(keyPub);
  17355. ret = wc_InitRsaKey(keyPub, NULL);
  17356. if (ret != 0)
  17357. return WC_TEST_RET_ENC_EC(ret);
  17358. /* Use API. */
  17359. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub);
  17360. if (ret != 0) {
  17361. ret = WC_TEST_RET_ENC_EC(ret);
  17362. goto done;
  17363. }
  17364. wc_FreeRsaKey(keyPub);
  17365. ret = wc_InitRsaKey(keyPub, NULL);
  17366. if (ret != 0)
  17367. return WC_TEST_RET_ENC_EC(ret);
  17368. /* Parameter Validation testing. */
  17369. inSz = sizeof(good);
  17370. ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, keyPub, inSz);
  17371. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17372. ret = WC_TEST_RET_ENC_EC(ret);
  17373. goto done;
  17374. }
  17375. ret = wc_RsaPublicKeyDecode(good, NULL, keyPub, inSz);
  17376. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17377. ret = WC_TEST_RET_ENC_EC(ret);
  17378. goto done;
  17379. }
  17380. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  17381. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17382. ret = WC_TEST_RET_ENC_EC(ret);
  17383. goto done;
  17384. }
  17385. /* Use good data and offset to bad data. */
  17386. inOutIdx = 2;
  17387. inSz = sizeof(good) - inOutIdx;
  17388. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17389. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17390. ret = WC_TEST_RET_ENC_EC(ret);
  17391. goto done;
  17392. }
  17393. inOutIdx = 2;
  17394. inSz = sizeof(goodAlgId) - inOutIdx;
  17395. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17396. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17397. ret = WC_TEST_RET_ENC_EC(ret);
  17398. goto done;
  17399. }
  17400. inOutIdx = 2;
  17401. inSz = sizeof(goodAlgId);
  17402. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17403. #ifndef WOLFSSL_NO_DECODE_EXTRA
  17404. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17405. #else
  17406. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E))
  17407. #endif
  17408. {
  17409. ret = WC_TEST_RET_ENC_EC(ret);
  17410. goto done;
  17411. }
  17412. /* Try different bad data. */
  17413. inSz = sizeof(badAlgIdNull);
  17414. inOutIdx = 0;
  17415. ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz);
  17416. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E)) {
  17417. ret = WC_TEST_RET_ENC_EC(ret);
  17418. goto done;
  17419. }
  17420. inSz = sizeof(badNotBitString);
  17421. inOutIdx = 0;
  17422. ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz);
  17423. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E)) {
  17424. ret = WC_TEST_RET_ENC_EC(ret);
  17425. goto done;
  17426. }
  17427. inSz = sizeof(badBitStringLen);
  17428. inOutIdx = 0;
  17429. ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz);
  17430. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17431. ret = WC_TEST_RET_ENC_EC(ret);
  17432. goto done;
  17433. }
  17434. inSz = sizeof(badNoSeq);
  17435. inOutIdx = 0;
  17436. ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz);
  17437. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17438. ret = WC_TEST_RET_ENC_EC(ret);
  17439. goto done;
  17440. }
  17441. inSz = sizeof(badNoObj);
  17442. inOutIdx = 0;
  17443. ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz);
  17444. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E) &&
  17445. ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E))
  17446. {
  17447. ret = WC_TEST_RET_ENC_EC(ret);
  17448. goto done;
  17449. }
  17450. inSz = sizeof(badIntN);
  17451. inOutIdx = 0;
  17452. ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz);
  17453. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17454. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17455. {
  17456. ret = WC_TEST_RET_ENC_EC(ret);
  17457. goto done;
  17458. }
  17459. inSz = sizeof(badNotIntE);
  17460. inOutIdx = 0;
  17461. ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz);
  17462. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17463. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17464. {
  17465. ret = WC_TEST_RET_ENC_EC(ret);
  17466. goto done;
  17467. }
  17468. /* TODO: Shouldn't pass as the sequence length is too small. */
  17469. inSz = sizeof(badLength);
  17470. inOutIdx = 0;
  17471. ret = wc_RsaPublicKeyDecode(badLength, &inOutIdx, keyPub, inSz);
  17472. #ifndef WOLFSSL_ASN_TEMPLATE
  17473. if (ret != 0)
  17474. #else
  17475. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17476. #endif
  17477. {
  17478. ret = WC_TEST_RET_ENC_EC(ret);
  17479. goto done;
  17480. }
  17481. /* TODO: Shouldn't ignore object id's data. */
  17482. wc_FreeRsaKey(keyPub);
  17483. ret = wc_InitRsaKey(keyPub, NULL);
  17484. if (ret != 0)
  17485. return WC_TEST_RET_ENC_EC(ret);
  17486. inSz = sizeof(badBitStrNoZero);
  17487. inOutIdx = 0;
  17488. ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz);
  17489. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  17490. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17491. {
  17492. ret = WC_TEST_RET_ENC_EC(ret);
  17493. goto done;
  17494. }
  17495. wc_FreeRsaKey(keyPub);
  17496. ret = wc_InitRsaKey(keyPub, NULL);
  17497. if (ret != 0)
  17498. return WC_TEST_RET_ENC_EC(ret);
  17499. /* Valid data cases. */
  17500. inSz = sizeof(good);
  17501. inOutIdx = 0;
  17502. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17503. if (ret != 0) {
  17504. ret = WC_TEST_RET_ENC_EC(ret);
  17505. goto done;
  17506. }
  17507. if (inOutIdx != inSz) {
  17508. ret = WC_TEST_RET_ENC_NC;
  17509. goto done;
  17510. }
  17511. wc_FreeRsaKey(keyPub);
  17512. ret = wc_InitRsaKey(keyPub, NULL);
  17513. if (ret != 0)
  17514. return WC_TEST_RET_ENC_EC(ret);
  17515. inSz = sizeof(goodAlgId);
  17516. inOutIdx = 0;
  17517. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17518. if (ret != 0) {
  17519. ret = WC_TEST_RET_ENC_EC(ret);
  17520. goto done;
  17521. }
  17522. if (inOutIdx != inSz) {
  17523. ret = WC_TEST_RET_ENC_NC;
  17524. goto done;
  17525. }
  17526. wc_FreeRsaKey(keyPub);
  17527. ret = wc_InitRsaKey(keyPub, NULL);
  17528. if (ret != 0)
  17529. return WC_TEST_RET_ENC_EC(ret);
  17530. inSz = sizeof(goodAlgIdNull);
  17531. inOutIdx = 0;
  17532. ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz);
  17533. if (ret != 0) {
  17534. ret = WC_TEST_RET_ENC_EC(ret);
  17535. goto done;
  17536. }
  17537. if (inOutIdx != inSz) {
  17538. ret = WC_TEST_RET_ENC_NC;
  17539. goto done;
  17540. }
  17541. done:
  17542. wc_FreeRsaKey(keyPub);
  17543. return ret;
  17544. }
  17545. #endif
  17546. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  17547. /* Need to create known good signatures to test with this. */
  17548. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  17549. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17550. static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key)
  17551. {
  17552. byte digest[WC_MAX_DIGEST_SIZE];
  17553. wc_test_ret_t ret = 0;
  17554. const char inStr[] = TEST_STRING;
  17555. word32 inLen = (word32)TEST_STRING_SZ;
  17556. word32 outSz;
  17557. word32 plainSz;
  17558. word32 digestSz;
  17559. int i, j;
  17560. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17561. int k, l;
  17562. #endif
  17563. #ifndef WOLFSSL_SE050
  17564. int len;
  17565. #endif
  17566. byte* plain;
  17567. int mgf[] = {
  17568. #ifndef NO_SHA
  17569. WC_MGF1SHA1,
  17570. #endif
  17571. #ifdef WOLFSSL_SHA224
  17572. WC_MGF1SHA224,
  17573. #endif
  17574. WC_MGF1SHA256,
  17575. #ifdef WOLFSSL_SHA384
  17576. WC_MGF1SHA384,
  17577. #endif
  17578. #ifdef WOLFSSL_SHA512
  17579. WC_MGF1SHA512
  17580. #endif
  17581. };
  17582. enum wc_HashType hash[] = {
  17583. #ifndef NO_SHA
  17584. WC_HASH_TYPE_SHA,
  17585. #endif
  17586. #ifdef WOLFSSL_SHA224
  17587. WC_HASH_TYPE_SHA224,
  17588. #endif
  17589. WC_HASH_TYPE_SHA256,
  17590. #ifdef WOLFSSL_SHA384
  17591. WC_HASH_TYPE_SHA384,
  17592. #endif
  17593. #ifdef WOLFSSL_SHA512
  17594. WC_HASH_TYPE_SHA512,
  17595. #endif
  17596. };
  17597. WC_DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17598. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17599. WC_DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17600. WC_ALLOC_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17601. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17602. WC_ALLOC_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17603. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17604. if (in == NULL || out == NULL || sig == NULL)
  17605. ERROR_OUT(MEMORY_E, exit_rsa_pss);
  17606. #endif
  17607. XMEMCPY(in, inStr, inLen);
  17608. /* Test all combinations of hash and MGF. */
  17609. for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) {
  17610. /* Calculate hash of message. */
  17611. ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest));
  17612. if (ret != 0)
  17613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17614. digestSz = (word32)wc_HashGetDigestSize(hash[j]);
  17615. #ifdef WOLFSSL_SE050
  17616. /* SE050 only supports MGF matched to same hash type */
  17617. i = j;
  17618. #else
  17619. for (i = 0; i < (int)(sizeof(mgf)/sizeof(*mgf)); i++) {
  17620. #endif
  17621. outSz = RSA_TEST_BYTES;
  17622. do {
  17623. #if defined(WOLFSSL_ASYNC_CRYPT)
  17624. ret = wc_AsyncWait(ret, &key->asyncDev,
  17625. WC_ASYNC_FLAG_CALL_AGAIN);
  17626. #endif
  17627. if (ret >= 0) {
  17628. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz,
  17629. hash[j], mgf[i], -1, key, rng);
  17630. }
  17631. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17632. if (ret <= 0)
  17633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17634. outSz = (word32)ret;
  17635. XMEMCPY(sig, out, outSz);
  17636. plain = NULL;
  17637. TEST_SLEEP();
  17638. do {
  17639. #if defined(WOLFSSL_ASYNC_CRYPT)
  17640. ret = wc_AsyncWait(ret, &key->asyncDev,
  17641. WC_ASYNC_FLAG_CALL_AGAIN);
  17642. #endif
  17643. if (ret >= 0) {
  17644. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[j],
  17645. mgf[i], -1, key);
  17646. }
  17647. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17648. if (ret <= 0)
  17649. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17650. plainSz = (word32)ret;
  17651. TEST_SLEEP();
  17652. #if defined(HAVE_SELFTEST) && \
  17653. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17654. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17655. hash[j], -1);
  17656. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17657. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17658. hash[j], -1, 0);
  17659. #else
  17660. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz,
  17661. hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT);
  17662. #endif
  17663. if (ret != 0)
  17664. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17665. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17666. for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) {
  17667. for (l = 0; l < (int)(sizeof(hash)/sizeof(*hash)); l++) {
  17668. if (i == k && j == l)
  17669. continue;
  17670. XMEMCPY(sig, out, outSz);
  17671. do {
  17672. #if defined(WOLFSSL_ASYNC_CRYPT)
  17673. ret = wc_AsyncWait(ret, &key->asyncDev,
  17674. WC_ASYNC_FLAG_CALL_AGAIN);
  17675. #endif
  17676. if (ret >= 0) {
  17677. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz,
  17678. (byte**)&plain, hash[l], mgf[k], -1, key);
  17679. }
  17680. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17681. if (ret >= 0)
  17682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17683. }
  17684. }
  17685. #endif
  17686. #ifndef WOLFSSL_SE050
  17687. } /* end mgf for loop */
  17688. #endif
  17689. }
  17690. /* SE050 generates salts internally only of hash length */
  17691. #ifndef WOLFSSL_SE050
  17692. /* Test that a salt length of zero works. */
  17693. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17694. outSz = RSA_TEST_BYTES;
  17695. do {
  17696. #if defined(WOLFSSL_ASYNC_CRYPT)
  17697. ret = wc_AsyncWait(ret, &key->asyncDev,
  17698. WC_ASYNC_FLAG_CALL_AGAIN);
  17699. #endif
  17700. if (ret >= 0) {
  17701. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17702. mgf[0], 0, key, rng);
  17703. }
  17704. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17705. if (ret <= 0)
  17706. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17707. outSz = (word32)ret;
  17708. TEST_SLEEP();
  17709. do {
  17710. #if defined(WOLFSSL_ASYNC_CRYPT)
  17711. ret = wc_AsyncWait(ret, &key->asyncDev,
  17712. WC_ASYNC_FLAG_CALL_AGAIN);
  17713. #endif
  17714. if (ret >= 0) {
  17715. ret = wc_RsaPSS_Verify_ex(out, outSz, sig, outSz, hash[0], mgf[0],
  17716. 0, key);
  17717. }
  17718. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17719. if (ret <= 0)
  17720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17721. plainSz = (word32)ret;
  17722. TEST_SLEEP();
  17723. do {
  17724. #if defined(WOLFSSL_ASYNC_CRYPT)
  17725. ret = wc_AsyncWait(ret, &key->asyncDev,
  17726. WC_ASYNC_FLAG_CALL_AGAIN);
  17727. #endif
  17728. if (ret >= 0) {
  17729. #if defined(HAVE_SELFTEST) && \
  17730. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17731. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17732. hash[0], 0);
  17733. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17734. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17735. hash[0], 0, 0);
  17736. #else
  17737. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, sig, plainSz,
  17738. hash[0], 0, 0, HEAP_HINT);
  17739. #endif
  17740. }
  17741. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17742. if (ret != 0)
  17743. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17744. XMEMCPY(sig, out, outSz);
  17745. plain = NULL;
  17746. do {
  17747. #if defined(WOLFSSL_ASYNC_CRYPT)
  17748. ret = wc_AsyncWait(ret, &key->asyncDev,
  17749. WC_ASYNC_FLAG_CALL_AGAIN);
  17750. #endif
  17751. if (ret >= 0) {
  17752. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17753. 0, key);
  17754. }
  17755. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17756. if (ret <= 0)
  17757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17758. plainSz = (word32)ret;
  17759. TEST_SLEEP();
  17760. #if defined(HAVE_SELFTEST) && \
  17761. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17762. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17763. hash[0], 0);
  17764. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17765. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17766. hash[0], 0, 0);
  17767. #else
  17768. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17769. 0, 0, HEAP_HINT);
  17770. #endif
  17771. if (ret != 0)
  17772. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17773. /* Test bad salt lengths in various APIs. */
  17774. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17775. outSz = RSA_TEST_BYTES;
  17776. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17777. len = -2;
  17778. #else
  17779. len = -3;
  17780. #endif
  17781. do {
  17782. #if defined(WOLFSSL_ASYNC_CRYPT)
  17783. ret = wc_AsyncWait(ret, &key->asyncDev,
  17784. WC_ASYNC_FLAG_CALL_AGAIN);
  17785. #endif
  17786. if (ret >= 0) {
  17787. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17788. mgf[0], len, key, rng);
  17789. }
  17790. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17791. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17793. do {
  17794. #if defined(WOLFSSL_ASYNC_CRYPT)
  17795. ret = wc_AsyncWait(ret, &key->asyncDev,
  17796. WC_ASYNC_FLAG_CALL_AGAIN);
  17797. #endif
  17798. if (ret >= 0) {
  17799. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17800. mgf[0], (int)digestSz + 1, key, rng);
  17801. }
  17802. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17803. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17804. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17805. TEST_SLEEP();
  17806. do {
  17807. #if defined(WOLFSSL_ASYNC_CRYPT)
  17808. ret = wc_AsyncWait(ret, &key->asyncDev,
  17809. WC_ASYNC_FLAG_CALL_AGAIN);
  17810. #endif
  17811. if (ret >= 0) {
  17812. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0],
  17813. mgf[0], -2, key);
  17814. }
  17815. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17816. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17817. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17818. TEST_SLEEP();
  17819. do {
  17820. #if defined(WOLFSSL_ASYNC_CRYPT)
  17821. ret = wc_AsyncWait(ret, &key->asyncDev,
  17822. WC_ASYNC_FLAG_CALL_AGAIN);
  17823. #endif
  17824. if (ret >= 0) {
  17825. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17826. (int)digestSz + 1, key);
  17827. }
  17828. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17829. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17831. TEST_SLEEP();
  17832. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17833. len = -2;
  17834. #else
  17835. len = -3;
  17836. #endif
  17837. #if defined(HAVE_SELFTEST) && \
  17838. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17839. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17840. hash[0], len);
  17841. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17842. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17843. hash[0], len, 0);
  17844. #else
  17845. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17846. len, 0, HEAP_HINT);
  17847. #endif
  17848. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17849. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17850. #ifndef WOLFSSL_PSS_LONG_SALT
  17851. len = (int)(digestSz + 1);
  17852. #else
  17853. len = (int)(plainSz - digestSz - 1);
  17854. #endif
  17855. #if defined(HAVE_SELFTEST) && \
  17856. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17857. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17858. hash[0], len);
  17859. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17861. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17862. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17863. hash[0], len, 0);
  17864. if (ret != WC_NO_ERR_TRACE(BAD_PADDING_E))
  17865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17866. #else
  17867. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17868. len, 0, HEAP_HINT);
  17869. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17870. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17871. #endif
  17872. ret = 0;
  17873. #endif /* WOLFSSL_SE050 */
  17874. exit_rsa_pss:
  17875. WC_FREE_VAR(sig, HEAP_HINT);
  17876. WC_FREE_VAR(in, HEAP_HINT);
  17877. WC_FREE_VAR(out, HEAP_HINT);
  17878. return ret;
  17879. }
  17880. #endif /* !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY */
  17881. #endif
  17882. #ifdef WC_RSA_NO_PADDING
  17883. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
  17884. {
  17885. WC_RNG rng;
  17886. byte* tmp = NULL;
  17887. size_t bytes;
  17888. wc_test_ret_t ret;
  17889. word32 inLen = 0;
  17890. word32 idx = 0;
  17891. word32 outSz = RSA_TEST_BYTES;
  17892. word32 plainSz = RSA_TEST_BYTES;
  17893. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  17894. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  17895. !defined(NO_FILESYSTEM)
  17896. XFILE file;
  17897. #endif
  17898. WC_DECLARE_VAR(key, RsaKey, 1, HEAP_HINT);
  17899. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17900. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17901. WC_ALLOC_VAR(key, RsaKey, 1, HEAP_HINT);
  17902. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17903. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17904. WOLFSSL_ENTER("rsa_no_pad_test");
  17905. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17906. if (key == NULL || out == NULL || plain == NULL)
  17907. ERROR_OUT(MEMORY_E, exit_rsa_nopadding);
  17908. #endif
  17909. /* initialize stack structures */
  17910. XMEMSET(&rng, 0, sizeof(rng));
  17911. XMEMSET(key, 0, sizeof(RsaKey));
  17912. #ifdef USE_CERT_BUFFERS_1024
  17913. bytes = (size_t)sizeof_client_key_der_1024;
  17914. if (bytes < (size_t)sizeof_client_cert_der_1024)
  17915. bytes = (size_t)sizeof_client_cert_der_1024;
  17916. #elif defined(USE_CERT_BUFFERS_2048)
  17917. bytes = (size_t)sizeof_client_key_der_2048;
  17918. if (bytes < (size_t)sizeof_client_cert_der_2048)
  17919. bytes = (size_t)sizeof_client_cert_der_2048;
  17920. #else
  17921. bytes = FOURK_BUF;
  17922. #endif
  17923. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17924. if (tmp == NULL
  17925. #ifdef WOLFSSL_ASYNC_CRYPT
  17926. || out == NULL || plain == NULL
  17927. #endif
  17928. ) {
  17929. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17930. }
  17931. #ifdef USE_CERT_BUFFERS_1024
  17932. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  17933. #elif defined(USE_CERT_BUFFERS_2048)
  17934. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  17935. #elif defined(USE_CERT_BUFFERS_3072)
  17936. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  17937. #elif defined(USE_CERT_BUFFERS_4096)
  17938. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  17939. #elif !defined(NO_FILESYSTEM)
  17940. file = XFOPEN(clientKey, "rb");
  17941. if (!file) {
  17942. err_sys("can't open clientKey, Please run from wolfSSL home dir",
  17943. WC_TEST_RET_ENC_ERRNO);
  17944. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17945. }
  17946. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  17947. XFCLOSE(file);
  17948. if (bytes == 0)
  17949. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17950. #else
  17951. /* No key to use. */
  17952. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17953. #endif /* USE_CERT_BUFFERS */
  17954. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  17955. if (ret != 0) {
  17956. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17957. }
  17958. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  17959. if (ret != 0) {
  17960. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17961. }
  17962. /* after loading in key use tmp as the test buffer */
  17963. #ifndef HAVE_FIPS
  17964. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  17965. #else
  17966. ret = wc_InitRng(&rng);
  17967. #endif
  17968. if (ret != 0) {
  17969. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17970. }
  17971. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17972. inLen = (word32)wc_RsaEncryptSize(key);
  17973. outSz = inLen;
  17974. plainSz = inLen;
  17975. XMEMSET(tmp, 7, inLen);
  17976. do {
  17977. #if defined(WOLFSSL_ASYNC_CRYPT)
  17978. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17979. #endif
  17980. if (ret >= 0) {
  17981. ret = wc_RsaDirect(tmp, inLen, out, &outSz, key,
  17982. RSA_PRIVATE_ENCRYPT, &rng);
  17983. }
  17984. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17985. if (ret <= 0) {
  17986. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17987. }
  17988. /* encrypted result should not be the same as input */
  17989. if (XMEMCMP(out, tmp, inLen) == 0) {
  17990. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17991. }
  17992. TEST_SLEEP();
  17993. /* decrypt with public key and compare result */
  17994. do {
  17995. #if defined(WOLFSSL_ASYNC_CRYPT)
  17996. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17997. #endif
  17998. if (ret >= 0) {
  17999. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key,
  18000. RSA_PUBLIC_DECRYPT, &rng);
  18001. }
  18002. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18003. if (ret <= 0) {
  18004. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18005. }
  18006. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18007. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18008. }
  18009. TEST_SLEEP();
  18010. #endif
  18011. #ifdef WC_RSA_BLINDING
  18012. ret = wc_RsaSetRNG(NULL, &rng);
  18013. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18015. }
  18016. ret = wc_RsaSetRNG(key, &rng);
  18017. if (ret < 0) {
  18018. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18019. }
  18020. #endif
  18021. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18022. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18023. do {
  18024. #if defined(WOLFSSL_ASYNC_CRYPT)
  18025. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18026. #endif
  18027. if (ret >= 0) {
  18028. ret = wc_RsaPublicEncrypt_ex(tmp, inLen, out, outSz, key, &rng,
  18029. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18030. }
  18031. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18032. if (ret < 0) {
  18033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18034. }
  18035. TEST_SLEEP();
  18036. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18037. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18038. do {
  18039. #if defined(WOLFSSL_ASYNC_CRYPT)
  18040. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18041. #endif
  18042. if (ret >= 0) {
  18043. ret = wc_RsaPrivateDecrypt_ex(out, outSz, plain, plainSz, key,
  18044. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18045. }
  18046. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18047. if (ret < 0) {
  18048. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18049. }
  18050. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18051. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18052. }
  18053. TEST_SLEEP();
  18054. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18055. /* test some bad arguments */
  18056. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1,
  18057. &rng);
  18058. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18059. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18060. }
  18061. ret = wc_RsaDirect(out, outSz, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT,
  18062. &rng);
  18063. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18064. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18065. }
  18066. ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT,
  18067. &rng);
  18068. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || plainSz != inLen) {
  18069. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18070. }
  18071. ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key,
  18072. RSA_PUBLIC_DECRYPT, &rng);
  18073. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18074. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18075. }
  18076. /* if making it to this point of code without hitting an ERROR_OUT then
  18077. * all tests have passed */
  18078. ret = 0;
  18079. exit_rsa_nopadding:
  18080. wc_FreeRsaKey(key);
  18081. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18082. WC_FREE_VAR(key, HEAP_HINT);
  18083. WC_FREE_VAR(out, HEAP_HINT);
  18084. WC_FREE_VAR(plain, HEAP_HINT);
  18085. wc_FreeRng(&rng);
  18086. return ret;
  18087. }
  18088. #endif /* WC_RSA_NO_PADDING */
  18089. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  18090. static wc_test_ret_t rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
  18091. {
  18092. byte* tmp = NULL;
  18093. size_t bytes;
  18094. wc_test_ret_t ret;
  18095. word32 inLen = 0;
  18096. #ifndef NO_ASN
  18097. word32 idx = 0;
  18098. #endif
  18099. word32 outSz = RSA_TEST_BYTES;
  18100. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18101. word32 plainSz = RSA_TEST_BYTES;
  18102. #endif
  18103. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_3072) && \
  18104. !defined(USE_CERT_BUFFERS_4096) && !defined(NO_FILESYSTEM)
  18105. XFILE file;
  18106. #endif
  18107. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18108. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18109. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18110. #endif
  18111. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18112. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18113. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18114. #endif
  18115. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18116. if (out == NULL
  18117. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18118. || plain == NULL
  18119. #endif
  18120. ) {
  18121. ERROR_OUT(MEMORY_E, exit_rsa_even_mod);
  18122. }
  18123. #endif
  18124. #if defined(USE_CERT_BUFFERS_2048)
  18125. bytes = (size_t)sizeof_client_key_der_2048;
  18126. if (bytes < (size_t)sizeof_client_cert_der_2048)
  18127. bytes = (size_t)sizeof_client_cert_der_2048;
  18128. #else
  18129. bytes = FOURK_BUF;
  18130. #endif
  18131. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18132. if (tmp == NULL
  18133. #ifdef WOLFSSL_ASYNC_CRYPT
  18134. || out == NULL || plain == NULL
  18135. #endif
  18136. ) {
  18137. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18138. }
  18139. #if defined(USE_CERT_BUFFERS_2048)
  18140. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  18141. #elif defined(USE_CERT_BUFFERS_3072)
  18142. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  18143. #elif defined(USE_CERT_BUFFERS_4096)
  18144. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  18145. #elif !defined(NO_FILESYSTEM)
  18146. file = XFOPEN(clientKey, "rb");
  18147. if (!file) {
  18148. err_sys("can't open ./certs/client-key.der, "
  18149. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  18150. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18151. }
  18152. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  18153. XFCLOSE(file);
  18154. if (bytes == 0)
  18155. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18156. #else
  18157. /* No key to use. */
  18158. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18159. #endif /* USE_CERT_BUFFERS */
  18160. #ifndef NO_ASN
  18161. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  18162. if (ret != 0) {
  18163. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18164. }
  18165. #else
  18166. #ifdef USE_CERT_BUFFERS_2048
  18167. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  18168. if (ret != 0) {
  18169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18170. }
  18171. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  18172. if (ret != 0) {
  18173. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18174. }
  18175. #ifndef NO_SIG_WRAPPER
  18176. modLen = 2048;
  18177. #endif
  18178. #else
  18179. #error Not supported yet!
  18180. #endif
  18181. #endif
  18182. key->n.dp[0] &= (mp_digit)-2;
  18183. if (ret != 0) {
  18184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18185. }
  18186. /* after loading in key use tmp as the test buffer */
  18187. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  18188. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM))) && \
  18189. !defined(WOLFSSL_XILINX_CRYPT)
  18190. /* The ARM64_ASM code that was FIPS validated did not return these expected
  18191. * failure codes. These tests cases were added after the assembly was
  18192. * in-lined in the module and validated, these tests will be available in
  18193. * the 140-3 module */
  18194. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18195. inLen = 32;
  18196. outSz = wc_RsaEncryptSize(key);
  18197. XMEMSET(tmp, 7, plainSz);
  18198. ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
  18199. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18200. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18201. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18202. {
  18203. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18204. }
  18205. ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
  18206. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18207. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18208. {
  18209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18210. }
  18211. #endif
  18212. #ifdef WC_RSA_BLINDING
  18213. ret = wc_RsaSetRNG(key, rng);
  18214. if (ret < 0) {
  18215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18216. }
  18217. #endif
  18218. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18219. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18220. ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
  18221. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18222. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18223. {
  18224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18225. }
  18226. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18227. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18228. ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
  18229. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18230. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18231. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18232. {
  18233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18234. }
  18235. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18236. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  18237. /* if making it to this point of code without hitting an ERROR_OUT then
  18238. * all tests have passed */
  18239. ret = 0;
  18240. exit_rsa_even_mod:
  18241. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18242. WC_FREE_VAR(out, HEAP_HINT);
  18243. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18244. WC_FREE_VAR(plain, HEAP_HINT);
  18245. #endif
  18246. (void)out;
  18247. (void)outSz;
  18248. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18249. (void)plain;
  18250. (void)plainSz;
  18251. #endif
  18252. (void)inLen;
  18253. (void)rng;
  18254. return ret;
  18255. }
  18256. #endif /* WOLFSSL_HAVE_SP_RSA */
  18257. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  18258. static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp)
  18259. {
  18260. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18261. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18262. #ifdef WOLFSSL_TEST_CERT
  18263. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18264. #endif
  18265. #else
  18266. RsaKey caKey[1];
  18267. #ifdef WOLFSSL_TEST_CERT
  18268. DecodedCert decode[1];
  18269. #endif
  18270. #endif
  18271. byte* der = NULL;
  18272. wc_test_ret_t ret;
  18273. Cert* myCert = NULL;
  18274. int certSz;
  18275. size_t bytes3;
  18276. word32 idx3 = 0;
  18277. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  18278. XFILE file3;
  18279. #endif
  18280. #if defined(WOLFSSL_ALT_NAMES) && !defined(NO_ASN_TIME)
  18281. struct tm beforeTime;
  18282. struct tm afterTime;
  18283. #endif
  18284. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  18285. (void)keypub;
  18286. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18287. if (caKey == NULL)
  18288. ERROR_OUT(MEMORY_E, exit_rsa);
  18289. #ifdef WOLFSSL_TEST_CERT
  18290. if (decode == NULL)
  18291. ERROR_OUT(MEMORY_E, exit_rsa);
  18292. #endif
  18293. #endif
  18294. XMEMSET(caKey, 0, sizeof *caKey);
  18295. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18296. if (der == NULL) {
  18297. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18298. }
  18299. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18300. if (myCert == NULL) {
  18301. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18302. }
  18303. /* self signed */
  18304. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18305. if (ret != 0) {
  18306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18307. }
  18308. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18309. XMEMCPY(myCert->serial, mySerial, sizeof(mySerial));
  18310. myCert->serialSz = (int)sizeof(mySerial);
  18311. myCert->isCA = 1;
  18312. #ifndef NO_SHA256
  18313. myCert->sigType = CTC_SHA256wRSA;
  18314. #else
  18315. myCert->sigType = CTC_SHAwRSA;
  18316. #endif
  18317. #ifdef WOLFSSL_CERT_EXT
  18318. /* add Policies */
  18319. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18320. CTC_MAX_CERTPOL_SZ);
  18321. XSTRNCPY(myCert->certPolicies[1], "1.2.840.113549.1.9.16.6.5",
  18322. CTC_MAX_CERTPOL_SZ);
  18323. myCert->certPoliciesNb = 2;
  18324. /* add SKID from the Public Key */
  18325. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL);
  18326. if (ret != 0) {
  18327. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18328. }
  18329. /* add AKID from the Public Key */
  18330. ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL);
  18331. if (ret != 0) {
  18332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18333. }
  18334. /* add Key Usage */
  18335. ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign");
  18336. if (ret != 0) {
  18337. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18338. }
  18339. #ifdef WOLFSSL_EKU_OID
  18340. {
  18341. const char unique[] = "2.16.840.1.111111.100.1.10.1";
  18342. ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0,
  18343. HEAP_HINT);
  18344. if (ret != 0) {
  18345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18346. }
  18347. }
  18348. #endif /* WOLFSSL_EKU_OID */
  18349. #endif /* WOLFSSL_CERT_EXT */
  18350. do {
  18351. #if defined(WOLFSSL_ASYNC_CRYPT)
  18352. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18353. #endif
  18354. if (ret >= 0) {
  18355. ret = wc_MakeSelfCert(myCert, der, FOURK_BUF, key, rng);
  18356. }
  18357. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18358. if (ret < 0) {
  18359. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18360. }
  18361. certSz = (int)ret;
  18362. #ifdef WOLFSSL_TEST_CERT
  18363. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18364. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18365. if (ret != 0) {
  18366. FreeDecodedCert(decode);
  18367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18368. }
  18369. FreeDecodedCert(decode);
  18370. #endif
  18371. ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile,
  18372. CERT_TYPE);
  18373. if (ret != 0) {
  18374. goto exit_rsa;
  18375. }
  18376. /* Setup Certificate */
  18377. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18378. if (ret < 0) {
  18379. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18380. }
  18381. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  18382. /* Get CA Cert for testing */
  18383. #ifdef USE_CERT_BUFFERS_1024
  18384. XMEMCPY(tmp, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  18385. bytes3 = sizeof_ca_cert_der_1024;
  18386. #elif defined(USE_CERT_BUFFERS_2048)
  18387. XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  18388. bytes3 = sizeof_ca_cert_der_2048;
  18389. #else
  18390. file3 = XFOPEN(rsaCaCertDerFile, "rb");
  18391. if (!file3) {
  18392. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18393. }
  18394. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18395. XFCLOSE(file3);
  18396. if (bytes3 == 0)
  18397. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18398. #endif /* USE_CERT_BUFFERS */
  18399. #if defined(WOLFSSL_ALT_NAMES)
  18400. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \
  18401. !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  18402. ret = wc_SetAltNames(myCert, rsaCaCertFile);
  18403. if (ret != 0)
  18404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18405. #endif
  18406. /* get alt names from der */
  18407. ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3);
  18408. if (ret != 0)
  18409. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18410. /* get dates from der */
  18411. ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3);
  18412. if (ret != 0)
  18413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18414. #ifndef NO_ASN_TIME
  18415. ret = wc_GetCertDates(myCert, &beforeTime, &afterTime);
  18416. if (ret < 0)
  18417. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18418. #endif
  18419. #endif /* WOLFSSL_ALT_NAMES */
  18420. #endif /* WOLFSSL_ALT_NAMES || HAVE_PKCS7 */
  18421. /* Get CA Key */
  18422. #ifdef USE_CERT_BUFFERS_1024
  18423. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18424. bytes3 = sizeof_ca_key_der_1024;
  18425. #elif defined(USE_CERT_BUFFERS_2048)
  18426. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18427. bytes3 = sizeof_ca_key_der_2048;
  18428. #else
  18429. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18430. if (!file3) {
  18431. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18432. }
  18433. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18434. XFCLOSE(file3);
  18435. if (bytes3 == 0)
  18436. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18437. #endif /* USE_CERT_BUFFERS */
  18438. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18439. if (ret != 0)
  18440. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18441. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18442. if (ret != 0)
  18443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18444. #ifndef NO_SHA256
  18445. myCert->sigType = CTC_SHA256wRSA;
  18446. #else
  18447. myCert->sigType = CTC_SHAwRSA;
  18448. #endif
  18449. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18450. #ifdef WOLFSSL_CERT_EXT
  18451. /* add Policies */
  18452. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18453. CTC_MAX_CERTPOL_SZ);
  18454. myCert->certPoliciesNb =1;
  18455. /* add SKID from the Public Key */
  18456. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL);
  18457. if (ret != 0)
  18458. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18459. /* add AKID from the CA certificate */
  18460. #if defined(USE_CERT_BUFFERS_2048)
  18461. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18462. sizeof_ca_cert_der_2048);
  18463. #elif defined(USE_CERT_BUFFERS_1024)
  18464. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18465. sizeof_ca_cert_der_1024);
  18466. #else
  18467. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18468. #endif
  18469. if (ret != 0)
  18470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18471. /* add Key Usage */
  18472. ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement");
  18473. if (ret != 0)
  18474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18475. #endif /* WOLFSSL_CERT_EXT */
  18476. #if defined(USE_CERT_BUFFERS_2048)
  18477. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18478. sizeof_ca_cert_der_2048);
  18479. #elif defined(USE_CERT_BUFFERS_1024)
  18480. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18481. sizeof_ca_cert_der_1024);
  18482. #else
  18483. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18484. #endif
  18485. if (ret < 0)
  18486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18487. certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng);
  18488. if (certSz < 0) {
  18489. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18490. }
  18491. ret = 0;
  18492. do {
  18493. #if defined(WOLFSSL_ASYNC_CRYPT)
  18494. ret = wc_AsyncWait(ret, &caKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18495. #endif
  18496. if (ret >= 0) {
  18497. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der, FOURK_BUF,
  18498. caKey, NULL, rng);
  18499. }
  18500. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18501. if (ret < 0)
  18502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18503. certSz = (int)ret;
  18504. #ifdef WOLFSSL_TEST_CERT
  18505. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18506. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18507. if (ret != 0) {
  18508. FreeDecodedCert(decode);
  18509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18510. }
  18511. FreeDecodedCert(decode);
  18512. #endif
  18513. ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile,
  18514. CERT_TYPE);
  18515. if (ret != 0) {
  18516. goto exit_rsa;
  18517. }
  18518. exit_rsa:
  18519. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18520. if (caKey != NULL) {
  18521. wc_FreeRsaKey(caKey);
  18522. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18523. }
  18524. #ifdef WOLFSSL_TEST_CERT
  18525. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18526. #endif
  18527. #else
  18528. wc_FreeRsaKey(caKey);
  18529. #endif
  18530. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18531. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18532. return ret;
  18533. }
  18534. #endif
  18535. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
  18536. defined(WOLFSSL_CERT_GEN)
  18537. /* Make Cert / Sign example for ECC cert and RSA CA */
  18538. static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
  18539. {
  18540. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18541. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18542. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18543. ecc_key *caEccKeyPub = (ecc_key *)XMALLOC(sizeof *caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18544. #ifdef WOLFSSL_TEST_CERT
  18545. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18546. #endif
  18547. #else
  18548. RsaKey caKey[1];
  18549. ecc_key caEccKey[1];
  18550. ecc_key caEccKeyPub[1];
  18551. #ifdef WOLFSSL_TEST_CERT
  18552. DecodedCert decode[1];
  18553. #endif
  18554. #endif
  18555. byte* der = NULL;
  18556. Cert* myCert = NULL;
  18557. int certSz;
  18558. size_t bytes3;
  18559. word32 idx3 = 0;
  18560. #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
  18561. || !defined(USE_CERT_BUFFERS_256)
  18562. #ifndef NO_FILESYSTEM
  18563. XFILE file3;
  18564. #endif
  18565. #endif
  18566. wc_test_ret_t ret;
  18567. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18568. if ((caKey == NULL) || (caEccKey == NULL) || (caEccKeyPub == NULL)
  18569. #ifdef WOLFSSL_TEST_CERT
  18570. || (decode == NULL)
  18571. #endif
  18572. )
  18573. ERROR_OUT(MEMORY_E, exit_rsa);
  18574. #endif
  18575. XMEMSET(caKey, 0, sizeof *caKey);
  18576. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  18577. XMEMSET(caEccKeyPub, 0, sizeof *caEccKeyPub);
  18578. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18579. if (der == NULL) {
  18580. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18581. }
  18582. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18583. if (myCert == NULL) {
  18584. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18585. }
  18586. /* Get CA Key */
  18587. #ifdef USE_CERT_BUFFERS_1024
  18588. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18589. bytes3 = sizeof_ca_key_der_1024;
  18590. #elif defined(USE_CERT_BUFFERS_2048)
  18591. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18592. bytes3 = sizeof_ca_key_der_2048;
  18593. #else
  18594. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18595. if (!file3) {
  18596. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18597. }
  18598. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18599. XFCLOSE(file3);
  18600. if (bytes3 == 0)
  18601. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18602. #endif /* USE_CERT_BUFFERS */
  18603. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18604. if (ret != 0)
  18605. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18606. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18607. if (ret != 0)
  18608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18609. /* Get Cert Key */
  18610. #if defined(USE_CERT_BUFFERS_256)
  18611. {
  18612. XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
  18613. bytes3 = sizeof_ecc_key_pub_der_256;
  18614. }
  18615. #elif !defined(NO_FILESYSTEM)
  18616. {
  18617. file3 = XFOPEN(eccKeyPubFileDer, "rb");
  18618. if (!file3) {
  18619. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18620. }
  18621. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18622. XFCLOSE(file3);
  18623. if (bytes3 == 0)
  18624. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18625. }
  18626. #else
  18627. {
  18628. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
  18629. ERROR_OUT(ASN_PARSE_E, exit_rsa);
  18630. }
  18631. #endif
  18632. ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
  18633. if (ret != 0)
  18634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18635. idx3 = 0;
  18636. ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3);
  18637. if (ret != 0)
  18638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18639. /* Setup Certificate */
  18640. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18641. if (ret != 0)
  18642. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18643. #ifndef NO_SHA256
  18644. myCert->sigType = CTC_SHA256wRSA;
  18645. #else
  18646. myCert->sigType = CTC_SHAwRSA;
  18647. #endif
  18648. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18649. #ifdef WOLFSSL_CERT_EXT
  18650. /* add Policies */
  18651. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  18652. CTC_MAX_CERTPOL_SZ);
  18653. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  18654. CTC_MAX_CERTPOL_SZ);
  18655. myCert->certPoliciesNb = 2;
  18656. /* add SKID from the Public Key */
  18657. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub);
  18658. if (ret != 0)
  18659. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18660. /* add AKID from the CA certificate */
  18661. #if defined(USE_CERT_BUFFERS_2048)
  18662. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18663. sizeof_ca_cert_der_2048);
  18664. #elif defined(USE_CERT_BUFFERS_1024)
  18665. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18666. sizeof_ca_cert_der_1024);
  18667. #else
  18668. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18669. #endif
  18670. if (ret != 0)
  18671. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18672. /* add Key Usage */
  18673. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  18674. if (ret != 0)
  18675. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18676. #endif /* WOLFSSL_CERT_EXT */
  18677. #if defined(USE_CERT_BUFFERS_2048)
  18678. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18679. sizeof_ca_cert_der_2048);
  18680. #elif defined(USE_CERT_BUFFERS_1024)
  18681. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18682. sizeof_ca_cert_der_1024);
  18683. #else
  18684. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18685. #endif
  18686. if (ret < 0)
  18687. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18688. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng);
  18689. if (certSz < 0) {
  18690. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18691. }
  18692. ret = 0;
  18693. do {
  18694. #if defined(WOLFSSL_ASYNC_CRYPT)
  18695. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18696. #endif
  18697. if (ret >= 0) {
  18698. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  18699. FOURK_BUF, caKey, NULL, rng);
  18700. }
  18701. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18702. if (ret < 0)
  18703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18704. certSz = (int)ret;
  18705. #ifdef WOLFSSL_TEST_CERT
  18706. InitDecodedCert(decode, der, certSz, 0);
  18707. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18708. if (ret != 0) {
  18709. FreeDecodedCert(decode);
  18710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18711. }
  18712. FreeDecodedCert(decode);
  18713. #endif
  18714. ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile,
  18715. CERT_TYPE);
  18716. if (ret != 0) {
  18717. goto exit_rsa;
  18718. }
  18719. exit_rsa:
  18720. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18721. if (caKey != NULL) {
  18722. wc_FreeRsaKey(caKey);
  18723. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18724. }
  18725. if (caEccKey != NULL) {
  18726. wc_ecc_free(caEccKey);
  18727. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18728. }
  18729. if (caEccKeyPub != NULL) {
  18730. wc_ecc_free(caEccKeyPub);
  18731. XFREE(caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18732. }
  18733. #ifdef WOLFSSL_TEST_CERT
  18734. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18735. #endif
  18736. #else
  18737. wc_FreeRsaKey(caKey);
  18738. wc_ecc_free(caEccKey);
  18739. wc_ecc_free(caEccKeyPub);
  18740. #endif
  18741. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18742. myCert = NULL;
  18743. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18744. der = NULL;
  18745. if (ret >= 0)
  18746. ret = 0;
  18747. return ret;
  18748. }
  18749. #endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
  18750. #ifdef WOLFSSL_KEY_GEN
  18751. static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
  18752. {
  18753. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18754. RsaKey *genKey = (RsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18755. #else
  18756. RsaKey genKey[1];
  18757. #endif
  18758. wc_test_ret_t ret;
  18759. #ifndef WOLFSSL_NO_MALLOC
  18760. byte* der = NULL;
  18761. #else
  18762. byte der[1280];
  18763. #endif
  18764. #ifndef WOLFSSL_CRYPTOCELL
  18765. word32 idx = 0;
  18766. #endif
  18767. int derSz = 0;
  18768. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FIPS) && \
  18769. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18770. int keySz = 1024;
  18771. #else
  18772. int keySz = 2048;
  18773. #endif
  18774. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18775. if (! genKey)
  18776. ERROR_OUT(MEMORY_E, exit_rsa);
  18777. #endif
  18778. XMEMSET(genKey, 0, sizeof *genKey);
  18779. ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId);
  18780. if (ret != 0)
  18781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18782. #ifdef HAVE_FIPS
  18783. for (;;) {
  18784. #endif
  18785. ret = wc_MakeRsaKey(genKey, keySz, WC_RSA_EXPONENT, rng);
  18786. #if defined(WOLFSSL_ASYNC_CRYPT)
  18787. ret = wc_AsyncWait(ret, &genKey->asyncDev, WC_ASYNC_FLAG_NONE);
  18788. #endif
  18789. #ifdef HAVE_FIPS
  18790. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  18791. continue;
  18792. break;
  18793. }
  18794. #endif
  18795. if (ret != 0)
  18796. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18797. TEST_SLEEP();
  18798. #ifdef WOLFSSL_RSA_KEY_CHECK
  18799. ret = wc_CheckRsaKey(genKey);
  18800. if (ret != 0)
  18801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18802. #endif
  18803. #ifndef WOLFSSL_NO_MALLOC
  18804. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18805. if (der == NULL) {
  18806. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18807. }
  18808. derSz = FOURK_BUF;
  18809. #else
  18810. derSz = sizeof(der);
  18811. #endif
  18812. derSz = wc_RsaKeyToDer(genKey, der, derSz);
  18813. if (derSz < 0) {
  18814. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  18815. }
  18816. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  18817. PRIVATEKEY_TYPE);
  18818. if (ret != 0) {
  18819. goto exit_rsa;
  18820. }
  18821. wc_FreeRsaKey(genKey);
  18822. ret = wc_InitRsaKey(genKey, HEAP_HINT);
  18823. if (ret != 0)
  18824. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18825. #ifndef WOLFSSL_CRYPTOCELL
  18826. idx = 0;
  18827. /* The private key part of the key gen pairs from cryptocell can't be exported */
  18828. ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, (word32)derSz);
  18829. if (ret != 0)
  18830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18831. #endif /* WOLFSSL_CRYPTOCELL */
  18832. exit_rsa:
  18833. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18834. if (genKey) {
  18835. wc_FreeRsaKey(genKey);
  18836. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18837. }
  18838. #else
  18839. wc_FreeRsaKey(genKey);
  18840. #endif
  18841. #ifndef WOLFSSL_NO_MALLOC
  18842. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18843. der = NULL;
  18844. #endif
  18845. return ret;
  18846. }
  18847. #endif
  18848. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18849. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) && \
  18850. (!defined(HAVE_FIPS) || \
  18851. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  18852. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  18853. static wc_test_ret_t rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng)
  18854. {
  18855. wc_test_ret_t ret = 0;
  18856. word32 idx = 0;
  18857. const char inStr[] = TEST_STRING;
  18858. const word32 inLen = (word32)TEST_STRING_SZ;
  18859. const word32 outSz = RSA_TEST_BYTES;
  18860. const word32 plainSz = RSA_TEST_BYTES;
  18861. byte* res = NULL;
  18862. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18863. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18864. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18865. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18866. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18867. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18868. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18869. if (in == NULL || out == NULL || plain == NULL)
  18870. ERROR_OUT(MEMORY_E, exit_rsa);
  18871. #endif
  18872. XMEMCPY(in, inStr, inLen);
  18873. #ifndef NO_SHA
  18874. do {
  18875. #if defined(WOLFSSL_ASYNC_CRYPT)
  18876. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18877. #endif
  18878. if (ret >= 0) {
  18879. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18880. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18881. }
  18882. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18883. if (ret < 0)
  18884. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18885. TEST_SLEEP();
  18886. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18887. idx = (word32)ret;
  18888. do {
  18889. #if defined(WOLFSSL_ASYNC_CRYPT)
  18890. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18891. #endif
  18892. if (ret >= 0) {
  18893. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18894. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18895. }
  18896. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18897. if (ret < 0)
  18898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18899. if (XMEMCMP(plain, in, inLen)) {
  18900. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18901. }
  18902. TEST_SLEEP();
  18903. #endif /* NO_SHA */
  18904. #endif
  18905. #ifndef NO_SHA256
  18906. XMEMSET(plain, 0, plainSz);
  18907. do {
  18908. #if defined(WOLFSSL_ASYNC_CRYPT)
  18909. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18910. #endif
  18911. if (ret >= 0) {
  18912. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18913. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18914. }
  18915. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18916. if (ret < 0)
  18917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18918. TEST_SLEEP();
  18919. idx = (word32)ret;
  18920. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18921. do {
  18922. #if defined(WOLFSSL_ASYNC_CRYPT)
  18923. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18924. #endif
  18925. if (ret >= 0) {
  18926. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18927. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18928. }
  18929. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18930. if (ret < 0)
  18931. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18932. if (XMEMCMP(plain, in, inLen)) {
  18933. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18934. }
  18935. TEST_SLEEP();
  18936. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18937. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18938. do {
  18939. #if defined(WOLFSSL_ASYNC_CRYPT)
  18940. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18941. #endif
  18942. if (ret >= 0) {
  18943. ret = wc_RsaPrivateDecryptInline_ex(out, idx, &res, key,
  18944. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18945. }
  18946. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18947. if (ret < 0)
  18948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18949. if (ret != (int)inLen) {
  18950. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18951. }
  18952. if (XMEMCMP(res, in, inLen)) {
  18953. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18954. }
  18955. TEST_SLEEP();
  18956. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18957. /* check fails if not using the same optional label */
  18958. XMEMSET(plain, 0, plainSz);
  18959. do {
  18960. #if defined(WOLFSSL_ASYNC_CRYPT)
  18961. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18962. #endif
  18963. if (ret >= 0) {
  18964. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18965. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18966. }
  18967. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18968. if (ret < 0)
  18969. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18970. TEST_SLEEP();
  18971. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18972. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18973. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18974. /* label is unused in cryptocell and SE050 so it won't detect decrypt error
  18975. * due to label */
  18976. idx = (word32)ret;
  18977. do {
  18978. #if defined(WOLFSSL_ASYNC_CRYPT)
  18979. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18980. #endif
  18981. if (ret >= 0) {
  18982. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18983. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18984. }
  18985. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18986. if (ret > 0) { /* in this case decrypt should fail */
  18987. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18988. }
  18989. ret = 0;
  18990. TEST_SLEEP();
  18991. #endif /* !HAVE_CAVIUM */
  18992. /* check using optional label with encrypt/decrypt */
  18993. XMEMSET(plain, 0, plainSz);
  18994. do {
  18995. #if defined(WOLFSSL_ASYNC_CRYPT)
  18996. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18997. #endif
  18998. if (ret >= 0) {
  18999. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19000. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19001. }
  19002. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19003. if (ret < 0)
  19004. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19005. TEST_SLEEP();
  19006. idx = (word32)ret;
  19007. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19008. do {
  19009. #if defined(WOLFSSL_ASYNC_CRYPT)
  19010. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19011. #endif
  19012. if (ret >= 0) {
  19013. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19014. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19015. }
  19016. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19017. if (ret < 0)
  19018. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19019. if (XMEMCMP(plain, in, inLen)) {
  19020. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19021. }
  19022. TEST_SLEEP();
  19023. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19024. #ifndef NO_SHA
  19025. /* check fail using mismatch hash algorithms */
  19026. XMEMSET(plain, 0, plainSz);
  19027. do {
  19028. #if defined(WOLFSSL_ASYNC_CRYPT)
  19029. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19030. #endif
  19031. if (ret >= 0) {
  19032. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19033. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen);
  19034. }
  19035. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19036. if (ret < 0)
  19037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19038. TEST_SLEEP();
  19039. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  19040. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19041. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  19042. idx = (word32)ret;
  19043. do {
  19044. #if defined(WOLFSSL_ASYNC_CRYPT)
  19045. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19046. #endif
  19047. if (ret >= 0) {
  19048. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19049. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256,
  19050. in, inLen);
  19051. }
  19052. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19053. if (ret > 0) { /* should fail */
  19054. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19055. }
  19056. ret = 0;
  19057. TEST_SLEEP();
  19058. #endif /* !HAVE_CAVIUM */
  19059. #endif /* NO_SHA */
  19060. #endif /* NO_SHA256 */
  19061. #ifdef WOLFSSL_SHA512
  19062. /* Check valid RSA key size is used while using hash length of SHA512
  19063. If key size is less than (hash length * 2) + 2 then is invalid use
  19064. and test, since OAEP padding requires this.
  19065. BAD_FUNC_ARG is returned when this case is not met */
  19066. if (wc_RsaEncryptSize(key) > ((int)WC_SHA512_DIGEST_SIZE * 2) + 2) {
  19067. XMEMSET(plain, 0, plainSz);
  19068. do {
  19069. #if defined(WOLFSSL_ASYNC_CRYPT)
  19070. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19071. #endif
  19072. if (ret >= 0) {
  19073. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19074. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19075. }
  19076. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19077. if (ret < 0)
  19078. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19079. TEST_SLEEP();
  19080. idx = (word32)ret;
  19081. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19082. do {
  19083. #if defined(WOLFSSL_ASYNC_CRYPT)
  19084. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19085. #endif
  19086. if (ret >= 0) {
  19087. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19088. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19089. }
  19090. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19091. if (ret < 0)
  19092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19093. if (XMEMCMP(plain, in, inLen)) {
  19094. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19095. }
  19096. TEST_SLEEP();
  19097. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19098. }
  19099. #endif /* WOLFSSL_SHA512 */
  19100. /* check using pkcsv15 padding with _ex API */
  19101. XMEMSET(plain, 0, plainSz);
  19102. do {
  19103. #if defined(WOLFSSL_ASYNC_CRYPT)
  19104. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19105. #endif
  19106. if (ret >= 0) {
  19107. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19108. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19109. }
  19110. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19111. if (ret < 0)
  19112. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19113. TEST_SLEEP();
  19114. idx = (word32)ret;
  19115. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19116. do {
  19117. #if defined(WOLFSSL_ASYNC_CRYPT)
  19118. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19119. #endif
  19120. if (ret >= 0) {
  19121. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19122. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19123. }
  19124. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19125. if (ret < 0)
  19126. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19127. if (XMEMCMP(plain, in, inLen)) {
  19128. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19129. }
  19130. TEST_SLEEP();
  19131. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19132. exit_rsa:
  19133. WC_FREE_VAR(in, HEAP_HINT);
  19134. WC_FREE_VAR(out, HEAP_HINT);
  19135. WC_FREE_VAR(plain, HEAP_HINT);
  19136. (void)idx;
  19137. (void)inStr;
  19138. (void)res;
  19139. if (ret >= 0)
  19140. ret = 0;
  19141. return ret;
  19142. }
  19143. #endif
  19144. #endif
  19145. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
  19146. {
  19147. wc_test_ret_t ret;
  19148. size_t bytes = 0;
  19149. WC_RNG rng;
  19150. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19151. byte* tmp = NULL;
  19152. byte* der = NULL;
  19153. RsaKey *key = NULL;
  19154. #else
  19155. RsaKey key[1];
  19156. byte tmp[FOURK_BUF];
  19157. #endif
  19158. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19159. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19160. RsaKey *keypub = NULL;
  19161. #else
  19162. RsaKey keypub[1];
  19163. #endif
  19164. #endif
  19165. word32 idx = 0;
  19166. const char inStr[] = TEST_STRING;
  19167. const word32 inLen = (word32)TEST_STRING_SZ;
  19168. const word32 outSz = RSA_TEST_BYTES;
  19169. const word32 plainSz = RSA_TEST_BYTES;
  19170. byte* res = NULL;
  19171. #ifndef NO_SIG_WRAPPER
  19172. int modLen;
  19173. #endif
  19174. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19175. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  19176. !defined(NO_FILESYSTEM)
  19177. XFILE file;
  19178. #ifdef WOLFSSL_TEST_CERT
  19179. XFILE file2;
  19180. #endif
  19181. #endif
  19182. #ifdef WOLFSSL_TEST_CERT
  19183. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19184. DecodedCert *cert = (DecodedCert *)XMALLOC(sizeof *cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19185. #else
  19186. DecodedCert cert[1];
  19187. #endif
  19188. #ifndef NO_ASN_TIME
  19189. struct tm timearg;
  19190. const byte* date;
  19191. byte dateFormat;
  19192. int dateLength;
  19193. #endif
  19194. #endif
  19195. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19196. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19197. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19198. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19199. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19200. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19201. WOLFSSL_ENTER("rsa_test");
  19202. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  19203. if (in == NULL || out == NULL || plain == NULL)
  19204. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19205. #endif
  19206. XMEMCPY(in, inStr, inLen);
  19207. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19208. key = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19209. if (key == NULL)
  19210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19211. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19212. keypub = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19213. if (keypub == NULL)
  19214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19215. #endif
  19216. #ifdef WOLFSSL_TEST_CERT
  19217. if (cert == NULL)
  19218. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19219. #endif
  19220. #else /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19221. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19222. if (ret != 0)
  19223. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19224. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19225. ret = wc_InitRsaKey_ex(keypub, HEAP_HINT, devId);
  19226. if (ret != 0)
  19227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19228. #endif
  19229. #endif /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19230. /* initialize stack structures */
  19231. XMEMSET(&rng, 0, sizeof(rng));
  19232. #if !defined(NO_ASN)
  19233. ret = rsa_decode_test(key);
  19234. if (ret != 0)
  19235. ERROR_OUT(ret, exit_rsa);
  19236. #endif
  19237. #ifdef USE_CERT_BUFFERS_1024
  19238. bytes = (size_t)sizeof_client_key_der_1024;
  19239. if (bytes < (size_t)sizeof_client_cert_der_1024)
  19240. bytes = (size_t)sizeof_client_cert_der_1024;
  19241. #elif defined(USE_CERT_BUFFERS_2048)
  19242. bytes = (size_t)sizeof_client_key_der_2048;
  19243. if (bytes < (size_t)sizeof_client_cert_der_2048)
  19244. bytes = (size_t)sizeof_client_cert_der_2048;
  19245. #elif defined(USE_CERT_BUFFERS_3072)
  19246. bytes = (size_t)sizeof_client_key_der_3072;
  19247. if (bytes < (size_t)sizeof_client_cert_der_3072)
  19248. bytes = (size_t)sizeof_client_cert_der_3072;
  19249. #elif defined(USE_CERT_BUFFERS_4096)
  19250. bytes = (size_t)sizeof_client_key_der_4096;
  19251. if (bytes < (size_t)sizeof_client_cert_der_4096)
  19252. bytes = (size_t)sizeof_client_cert_der_4096;
  19253. #else
  19254. bytes = FOURK_BUF;
  19255. #endif
  19256. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19257. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19258. if (tmp == NULL)
  19259. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19260. #endif
  19261. #ifdef USE_CERT_BUFFERS_1024
  19262. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  19263. #elif defined(USE_CERT_BUFFERS_2048)
  19264. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  19265. #elif defined(USE_CERT_BUFFERS_3072)
  19266. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  19267. #elif defined(USE_CERT_BUFFERS_4096)
  19268. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  19269. #elif !defined(NO_FILESYSTEM)
  19270. file = XFOPEN(clientKey, "rb");
  19271. if (!file) {
  19272. err_sys("can't open ./certs/client-key.der, "
  19273. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19274. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19275. }
  19276. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19277. XFCLOSE(file);
  19278. if (bytes == 0)
  19279. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19280. #else
  19281. /* No key to use. */
  19282. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19283. #endif /* USE_CERT_BUFFERS */
  19284. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19285. if (ret != 0)
  19286. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19287. #ifndef NO_ASN
  19288. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  19289. if (ret != 0)
  19290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19291. #ifndef NO_SIG_WRAPPER
  19292. modLen = wc_RsaEncryptSize(key);
  19293. #endif
  19294. #else
  19295. #ifdef USE_CERT_BUFFERS_2048
  19296. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  19297. if (ret != 0)
  19298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19299. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  19300. if (ret != 0)
  19301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19302. #ifndef NO_SIG_WRAPPER
  19303. modLen = 2048;
  19304. #endif
  19305. #else
  19306. #error Not supported yet!
  19307. #endif
  19308. #endif
  19309. #ifndef WC_NO_RNG
  19310. #ifndef HAVE_FIPS
  19311. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  19312. #else
  19313. ret = wc_InitRng(&rng);
  19314. #endif
  19315. if (ret != 0)
  19316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19317. #endif
  19318. #ifndef NO_SIG_WRAPPER
  19319. ret = rsa_sig_test(key, sizeof *key, modLen, &rng);
  19320. if (ret != 0)
  19321. goto exit_rsa;
  19322. #endif
  19323. #ifdef WC_RSA_NONBLOCK
  19324. ret = rsa_nb_test(key, in, inLen, out, outSz, plain, plainSz, &rng);
  19325. if (ret != 0)
  19326. goto exit_rsa;
  19327. #endif
  19328. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19329. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19330. do {
  19331. #if defined(WOLFSSL_ASYNC_CRYPT)
  19332. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19333. #endif
  19334. if (ret >= 0) {
  19335. ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng);
  19336. }
  19337. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19338. if (ret < 0)
  19339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19340. TEST_SLEEP();
  19341. #ifdef WC_RSA_BLINDING
  19342. {
  19343. wc_test_ret_t tmpret = ret;
  19344. ret = wc_RsaSetRNG(key, &rng);
  19345. if (ret < 0)
  19346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19347. ret = tmpret;
  19348. }
  19349. #endif
  19350. idx = (word32)ret; /* save off encrypted length */
  19351. do {
  19352. #if defined(WOLFSSL_ASYNC_CRYPT)
  19353. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19354. #endif
  19355. if (ret >= 0) {
  19356. ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key);
  19357. }
  19358. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19359. if (ret < 0)
  19360. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19361. if (XMEMCMP(plain, in, inLen)) {
  19362. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19363. }
  19364. TEST_SLEEP();
  19365. do {
  19366. #if defined(WOLFSSL_ASYNC_CRYPT)
  19367. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19368. #endif
  19369. if (ret >= 0) {
  19370. ret = wc_RsaPrivateDecryptInline(out, idx, &res, key);
  19371. }
  19372. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19373. if (ret < 0)
  19374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19375. if (ret != (int)inLen) {
  19376. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19377. }
  19378. if (XMEMCMP(res, in, inLen)) {
  19379. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19380. }
  19381. TEST_SLEEP();
  19382. do {
  19383. #if defined(WOLFSSL_ASYNC_CRYPT)
  19384. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19385. #endif
  19386. if (ret >= 0) {
  19387. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
  19388. }
  19389. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19390. if (ret < 0)
  19391. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19392. TEST_SLEEP();
  19393. #elif defined(WOLFSSL_PUBLIC_MP)
  19394. {
  19395. static const byte signature_2048[] = {
  19396. 0x07, 0x6f, 0xc9, 0x85, 0x73, 0x9e, 0x21, 0x79,
  19397. 0x47, 0xf1, 0xa3, 0xd7, 0xf4, 0x27, 0x29, 0xbe,
  19398. 0x99, 0x5d, 0xac, 0xb2, 0x10, 0x3f, 0x95, 0xda,
  19399. 0x89, 0x23, 0xb8, 0x96, 0x13, 0x57, 0x72, 0x30,
  19400. 0xa1, 0xfe, 0x5a, 0x68, 0x9c, 0x99, 0x9d, 0x1e,
  19401. 0x05, 0xa4, 0x80, 0xb0, 0xbb, 0xd9, 0xd9, 0xa1,
  19402. 0x69, 0x97, 0x74, 0xb3, 0x41, 0x21, 0x3b, 0x47,
  19403. 0xf5, 0x51, 0xb1, 0xfb, 0xc7, 0xaa, 0xcc, 0xdc,
  19404. 0xcd, 0x76, 0xa0, 0x28, 0x4d, 0x27, 0x14, 0xa4,
  19405. 0xb9, 0x41, 0x68, 0x7c, 0xb3, 0x66, 0xe6, 0x6f,
  19406. 0x40, 0x76, 0xe4, 0x12, 0xfd, 0xae, 0x29, 0xb5,
  19407. 0x63, 0x60, 0x87, 0xce, 0x49, 0x6b, 0xf3, 0x05,
  19408. 0x9a, 0x14, 0xb5, 0xcc, 0xcd, 0xf7, 0x30, 0x95,
  19409. 0xd2, 0x72, 0x52, 0x1d, 0x5b, 0x7e, 0xef, 0x4a,
  19410. 0x02, 0x96, 0x21, 0x6c, 0x55, 0xa5, 0x15, 0xb1,
  19411. 0x57, 0x63, 0x2c, 0xa3, 0x8e, 0x9d, 0x3d, 0x45,
  19412. 0xcc, 0xb8, 0xe6, 0xa1, 0xc8, 0x59, 0xcd, 0xf5,
  19413. 0xdc, 0x0a, 0x51, 0xb6, 0x9d, 0xfb, 0xf4, 0x6b,
  19414. 0xfd, 0x32, 0x71, 0x6e, 0xcf, 0xcb, 0xb3, 0xd9,
  19415. 0xe0, 0x4a, 0x77, 0x34, 0xd6, 0x61, 0xf5, 0x7c,
  19416. 0xf9, 0xa9, 0xa4, 0xb0, 0x8e, 0x3b, 0xd6, 0x04,
  19417. 0xe0, 0xde, 0x2b, 0x5b, 0x5a, 0xbf, 0xd9, 0xef,
  19418. 0x8d, 0xa3, 0xf5, 0xb1, 0x67, 0xf3, 0xb9, 0x72,
  19419. 0x0a, 0x37, 0x12, 0x35, 0x6c, 0x8e, 0x10, 0x8b,
  19420. 0x38, 0x06, 0x16, 0x4b, 0x20, 0x20, 0x13, 0x00,
  19421. 0x2e, 0x6d, 0xc2, 0x59, 0x23, 0x67, 0x4a, 0x6d,
  19422. 0xa1, 0x46, 0x8b, 0xee, 0xcf, 0x44, 0xb4, 0x3e,
  19423. 0x56, 0x75, 0x00, 0x68, 0xb5, 0x7d, 0x0f, 0x20,
  19424. 0x79, 0x5d, 0x7f, 0x12, 0x15, 0x32, 0x89, 0x61,
  19425. 0x6b, 0x29, 0xb7, 0x52, 0xf5, 0x25, 0xd8, 0x98,
  19426. 0xe8, 0x6f, 0xf9, 0x22, 0xb4, 0xbb, 0xe5, 0xff,
  19427. 0xd0, 0x92, 0x86, 0x9a, 0x88, 0xa2, 0xaf, 0x6b
  19428. };
  19429. ret = sizeof(signature_2048);
  19430. XMEMCPY(out, signature_2048, ret);
  19431. }
  19432. #endif
  19433. #if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
  19434. ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  19435. defined(WOLFSSL_PUBLIC_MP)) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19436. idx = (word32)ret;
  19437. XMEMSET(plain, 0, plainSz);
  19438. do {
  19439. #if defined(WOLFSSL_ASYNC_CRYPT)
  19440. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19441. #endif
  19442. if (ret >= 0) {
  19443. #ifndef WOLFSSL_RSA_VERIFY_INLINE
  19444. #if defined(WOLFSSL_CRYPTOCELL)
  19445. /*
  19446. Cryptocell requires the input data and signature byte array to verify.
  19447. first argument must be the input data
  19448. second argument must be the length of input data
  19449. third argument must be the signature byte array or the output from
  19450. wc_RsaSSL_Sign()
  19451. fourth argument must be the length of the signature byte array
  19452. */
  19453. ret = wc_RsaSSL_Verify(in, inLen, out, outSz, key);
  19454. #else
  19455. ret = wc_RsaSSL_Verify(out, idx, plain, plainSz, key);
  19456. #endif /* WOLFSSL_CRYPTOCELL */
  19457. #else
  19458. byte* dec = NULL;
  19459. ret = wc_RsaSSL_VerifyInline(out, idx, &dec, key);
  19460. if (ret > 0) {
  19461. XMEMCPY(plain, dec, ret);
  19462. }
  19463. #endif
  19464. }
  19465. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19466. if (ret < 0)
  19467. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19468. if (XMEMCMP(plain, in, (size_t)ret)) {
  19469. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19470. }
  19471. TEST_SLEEP();
  19472. #endif
  19473. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  19474. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG)
  19475. #if (!defined(HAVE_FIPS) || \
  19476. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  19477. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19478. ret = rsa_oaep_padding_test(key, &rng);
  19479. if (ret != 0)
  19480. goto exit_rsa;
  19481. #endif /* !HAVE_FIPS */
  19482. #endif /* WC_NO_RSA_OAEP && !WC_NO_RNG */
  19483. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  19484. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  19485. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19486. ret = rsa_export_key_test(key);
  19487. if (ret != 0)
  19488. goto exit_rsa;
  19489. #endif
  19490. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19491. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19492. ret = rsa_flatten_test(key);
  19493. if (ret != 0)
  19494. goto exit_rsa;
  19495. #endif
  19496. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_ASN) && \
  19497. !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19498. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  19499. (void)clientCert;
  19500. #endif
  19501. #ifdef WOLFSSL_TEST_CERT
  19502. #if defined(WOLFSSL_MDK_ARM)
  19503. #define sizeof(s) XSTRLEN((char *)(s))
  19504. #endif
  19505. #ifdef USE_CERT_BUFFERS_1024
  19506. XMEMCPY(tmp, client_cert_der_1024, (size_t)sizeof_client_cert_der_1024);
  19507. bytes = (size_t)sizeof_client_cert_der_1024;
  19508. #elif defined(USE_CERT_BUFFERS_2048)
  19509. XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048);
  19510. bytes = (size_t)sizeof_client_cert_der_2048;
  19511. #elif defined(USE_CERT_BUFFERS_3072)
  19512. XMEMCPY(tmp, client_cert_der_3072, (size_t)sizeof_client_cert_der_3072);
  19513. bytes = (size_t)sizeof_client_cert_der_3072;
  19514. #elif defined(USE_CERT_BUFFERS_4096)
  19515. XMEMCPY(tmp, client_cert_der_4096, (size_t)sizeof_client_cert_der_4096);
  19516. bytes = (size_t)sizeof_client_cert_der_4096;
  19517. #elif !defined(NO_FILESYSTEM)
  19518. file2 = XFOPEN(clientCert, "rb");
  19519. if (!file2) {
  19520. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19521. }
  19522. bytes = XFREAD(tmp, 1, FOURK_BUF, file2);
  19523. XFCLOSE(file2);
  19524. if (bytes == 0)
  19525. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19526. #else
  19527. /* No certificate to use. */
  19528. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19529. #endif
  19530. #ifdef sizeof
  19531. #undef sizeof
  19532. #endif
  19533. InitDecodedCert(cert, tmp, (word32)bytes, NULL);
  19534. ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
  19535. if (ret != 0) {
  19536. FreeDecodedCert(cert);
  19537. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19538. }
  19539. #ifndef NO_ASN_TIME
  19540. ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
  19541. &dateFormat, &dateLength);
  19542. if (ret != 0) {
  19543. FreeDecodedCert(cert);
  19544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19545. }
  19546. ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
  19547. if (ret != 0) {
  19548. FreeDecodedCert(cert);
  19549. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19550. }
  19551. #endif
  19552. FreeDecodedCert(cert);
  19553. #endif /* WOLFSSL_TEST_CERT */
  19554. #ifdef WOLFSSL_CERT_EXT
  19555. #ifdef USE_CERT_BUFFERS_1024
  19556. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  19557. bytes = sizeof_client_keypub_der_1024;
  19558. #elif defined(USE_CERT_BUFFERS_2048)
  19559. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  19560. bytes = sizeof_client_keypub_der_2048;
  19561. #elif defined(USE_CERT_BUFFERS_3072)
  19562. XMEMCPY(tmp, client_keypub_der_3072, sizeof_client_keypub_der_3072);
  19563. bytes = sizeof_client_keypub_der_3072;
  19564. #elif defined(USE_CERT_BUFFERS_4096)
  19565. XMEMCPY(tmp, client_keypub_der_4096, sizeof_client_keypub_der_4096);
  19566. bytes = sizeof_client_keypub_der_4096;
  19567. #else
  19568. file = XFOPEN(clientKeyPub, "rb");
  19569. if (!file) {
  19570. err_sys("can't open ./certs/client-keyPub.der, "
  19571. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19572. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19573. }
  19574. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19575. XFCLOSE(file);
  19576. if (bytes == 0)
  19577. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19578. #endif /* USE_CERT_BUFFERS */
  19579. ret = wc_InitRsaKey(keypub, HEAP_HINT);
  19580. if (ret != 0)
  19581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19582. idx = 0;
  19583. ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
  19584. if (ret != 0)
  19585. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19586. #endif /* WOLFSSL_CERT_EXT */
  19587. #ifdef WOLFSSL_KEY_GEN
  19588. ret = rsa_keygen_test(&rng);
  19589. if (ret != 0)
  19590. goto exit_rsa;
  19591. #endif
  19592. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  19593. !defined(WOLFSSL_NO_MALLOC)
  19594. /* Make Cert / Sign example for RSA cert and RSA CA */
  19595. ret = rsa_certgen_test(key, keypub, &rng, tmp);
  19596. if (ret != 0)
  19597. goto exit_rsa;
  19598. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP)
  19599. ret = rsa_ecc_certgen_test(&rng, tmp);
  19600. if (ret != 0)
  19601. goto exit_rsa;
  19602. #endif
  19603. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  19604. {
  19605. Cert *req;
  19606. int derSz;
  19607. #ifndef WOLFSSL_SMALL_STACK
  19608. byte* der = NULL;
  19609. #endif
  19610. req = (Cert *)XMALLOC(sizeof *req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19611. if (! req)
  19612. ERROR_OUT(MEMORY_E, exit_rsa);
  19613. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER);
  19614. if (der == NULL) {
  19615. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19616. }
  19617. ret = wc_InitCert_ex(req, HEAP_HINT, devId);
  19618. if (ret != 0)
  19619. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19620. req->version = 0;
  19621. req->isCA = 1;
  19622. XSTRNCPY(req->challengePw, "wolf123", CTC_NAME_SIZE);
  19623. XMEMCPY(&req->subject, &certDefaultName, sizeof(CertName));
  19624. #ifndef NO_SHA256
  19625. req->sigType = CTC_SHA256wRSA;
  19626. #else
  19627. req->sigType = CTC_SHAwRSA;
  19628. #endif
  19629. #ifdef WOLFSSL_CERT_EXT
  19630. /* add SKID from the Public Key */
  19631. ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL);
  19632. if (ret != 0)
  19633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19634. /* add Key Usage */
  19635. ret = wc_SetKeyUsage(req, certKeyUsage2);
  19636. if (ret != 0)
  19637. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19638. /* add Extended Key Usage */
  19639. ret = wc_SetExtKeyUsage(req,
  19640. "serverAuth,clientAuth,codeSigning,"
  19641. "emailProtection,timeStamping,OCSPSigning");
  19642. if (ret != 0)
  19643. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19644. #ifdef WOLFSSL_EKU_OID
  19645. {
  19646. WOLFSSL_SMALL_STACK_STATIC const char unique[] =
  19647. "2.16.840.1.111111.100.1.10.1";
  19648. ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0,
  19649. HEAP_HINT);
  19650. if (ret != 0)
  19651. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19652. }
  19653. #endif /* WOLFSSL_EKU_OID */
  19654. #endif /* WOLFSSL_CERT_EXT */
  19655. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19656. if (derSz < 0) {
  19657. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19658. }
  19659. #ifdef WOLFSSL_CERT_EXT
  19660. /* Try again with "any" flag set, will override all others */
  19661. ret = wc_SetExtKeyUsage(req, "any");
  19662. if (ret != 0)
  19663. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19664. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19665. if (derSz < 0) {
  19666. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19667. }
  19668. #endif /* WOLFSSL_CERT_EXT */
  19669. ret = 0;
  19670. do {
  19671. #if defined(WOLFSSL_ASYNC_CRYPT)
  19672. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19673. #endif
  19674. if (ret >= 0) {
  19675. ret = wc_SignCert(req->bodySz, req->sigType, der, FOURK_BUF,
  19676. key, NULL, &rng);
  19677. }
  19678. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19679. if (ret < 0)
  19680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19681. derSz = (int)ret;
  19682. ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile,
  19683. CERTREQ_TYPE);
  19684. if (ret != 0) {
  19685. goto exit_rsa;
  19686. }
  19687. derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key);
  19688. if (derSz < 0) {
  19689. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19690. }
  19691. /* Test getting the size of the buffer without providing the buffer.
  19692. * derSz is set to the "largest buffer" we are willing to allocate. */
  19693. derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL);
  19694. if (derSz < 0) {
  19695. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19696. }
  19697. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19698. XFREE(req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19699. der = NULL;
  19700. }
  19701. #endif /* WOLFSSL_CERT_REQ */
  19702. #endif /* WOLFSSL_CERT_GEN */
  19703. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  19704. /* Need to create known good signatures to test with this. */
  19705. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19706. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19707. ret = rsa_pss_test(&rng, key);
  19708. if (ret != 0)
  19709. goto exit_rsa;
  19710. #endif
  19711. #endif
  19712. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  19713. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19714. /* New key to be loaded in rsa_even_mod_test(). */
  19715. if (key != NULL)
  19716. #endif
  19717. wc_FreeRsaKey(key);
  19718. /* New key to be loaded in rsa_even_mod_test(). */
  19719. ret = rsa_even_mod_test(&rng, key);
  19720. #endif
  19721. exit_rsa:
  19722. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19723. wc_DeleteRsaKey(key, &key);
  19724. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19725. wc_DeleteRsaKey(keypub, &keypub);
  19726. #endif
  19727. #ifdef WOLFSSL_TEST_CERT
  19728. XFREE(cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19729. #endif
  19730. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19731. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19732. #else
  19733. wc_FreeRsaKey(key);
  19734. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19735. wc_FreeRsaKey(keypub);
  19736. #endif
  19737. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19738. wc_FreeRng(&rng);
  19739. WC_FREE_VAR(in, HEAP_HINT);
  19740. WC_FREE_VAR(out, HEAP_HINT);
  19741. WC_FREE_VAR(plain, HEAP_HINT);
  19742. (void)res;
  19743. (void)bytes;
  19744. (void)idx;
  19745. (void)in;
  19746. (void)out;
  19747. (void)plain;
  19748. (void)idx;
  19749. (void)inStr;
  19750. (void)inLen;
  19751. (void)outSz;
  19752. (void)plainSz;
  19753. /* ret can be greater then 0 with certgen but all negative values should
  19754. * be returned and treated as an error */
  19755. if (ret >= 0) {
  19756. return 0;
  19757. }
  19758. else {
  19759. return ret;
  19760. }
  19761. }
  19762. #endif /* !NO_RSA */
  19763. #ifndef NO_DH
  19764. static wc_test_ret_t dh_fips_generate_test(WC_RNG *rng)
  19765. {
  19766. wc_test_ret_t ret = 0;
  19767. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19768. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19769. #else
  19770. DhKey key[1];
  19771. #endif
  19772. WOLFSSL_SMALL_STACK_STATIC const byte p[] = {
  19773. 0xc5, 0x7c, 0xa2, 0x4f, 0x4b, 0xd6, 0x8c, 0x3c,
  19774. 0xda, 0xc7, 0xba, 0xaa, 0xea, 0x2e, 0x5c, 0x1e,
  19775. 0x18, 0xb2, 0x7b, 0x8c, 0x55, 0x65, 0x9f, 0xea,
  19776. 0xe0, 0xa1, 0x36, 0x53, 0x2b, 0x36, 0xe0, 0x4e,
  19777. 0x3e, 0x64, 0xa9, 0xe4, 0xfc, 0x8f, 0x32, 0x62,
  19778. 0x97, 0xe4, 0xbe, 0xf7, 0xc1, 0xde, 0x07, 0x5a,
  19779. 0x89, 0x28, 0xf3, 0xfe, 0x4f, 0xfe, 0x68, 0xbc,
  19780. 0xfb, 0x0a, 0x7c, 0xa4, 0xb3, 0x14, 0x48, 0x89,
  19781. 0x9f, 0xaf, 0xb8, 0x43, 0xe2, 0xa0, 0x62, 0x5c,
  19782. 0xb4, 0x88, 0x3f, 0x06, 0x50, 0x11, 0xfe, 0x65,
  19783. 0x8d, 0x49, 0xd2, 0xf5, 0x4b, 0x74, 0x79, 0xdb,
  19784. 0x06, 0x62, 0x92, 0x89, 0xed, 0xda, 0xcb, 0x87,
  19785. 0x37, 0x16, 0xd2, 0xa1, 0x7a, 0xe8, 0xde, 0x92,
  19786. 0xee, 0x3e, 0x41, 0x4a, 0x91, 0x5e, 0xed, 0xf3,
  19787. 0x6c, 0x6b, 0x7e, 0xfd, 0x15, 0x92, 0x18, 0xfc,
  19788. 0xa7, 0xac, 0x42, 0x85, 0x57, 0xe9, 0xdc, 0xda,
  19789. 0x55, 0xc9, 0x8b, 0x28, 0x9e, 0xc1, 0xc4, 0x46,
  19790. 0x4d, 0x88, 0xed, 0x62, 0x8e, 0xdb, 0x3f, 0xb9,
  19791. 0xd7, 0xc8, 0xe3, 0xcf, 0xb8, 0x34, 0x2c, 0xd2,
  19792. 0x6f, 0x28, 0x06, 0x41, 0xe3, 0x66, 0x8c, 0xfc,
  19793. 0x72, 0xff, 0x26, 0x3b, 0x6b, 0x6c, 0x6f, 0x73,
  19794. 0xde, 0xf2, 0x90, 0x29, 0xe0, 0x61, 0x32, 0xc4,
  19795. 0x12, 0x74, 0x09, 0x52, 0xec, 0xf3, 0x1b, 0xa6,
  19796. 0x45, 0x98, 0xac, 0xf9, 0x1c, 0x65, 0x8e, 0x3a,
  19797. 0x91, 0x84, 0x4b, 0x23, 0x8a, 0xb2, 0x3c, 0xc9,
  19798. 0xfa, 0xea, 0xf1, 0x38, 0xce, 0xd8, 0x05, 0xe0,
  19799. 0xfa, 0x44, 0x68, 0x1f, 0xeb, 0xd9, 0x57, 0xb8,
  19800. 0x4a, 0x97, 0x5b, 0x88, 0xc5, 0xf1, 0xbb, 0xb0,
  19801. 0x49, 0xc3, 0x91, 0x7c, 0xd3, 0x13, 0xb9, 0x47,
  19802. 0xbb, 0x91, 0x8f, 0xe5, 0x26, 0x07, 0xab, 0xa9,
  19803. 0xc5, 0xd0, 0x3d, 0x95, 0x41, 0x26, 0x92, 0x9d,
  19804. 0x13, 0x67, 0xf2, 0x7e, 0x11, 0x88, 0xdc, 0x2d
  19805. };
  19806. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  19807. 0x4a, 0x1a, 0xf3, 0xa4, 0x92, 0xe9, 0xee, 0x74,
  19808. 0x6e, 0x57, 0xd5, 0x8c, 0x2c, 0x5b, 0x41, 0x41,
  19809. 0x5e, 0xd4, 0x55, 0x19, 0xdc, 0xd9, 0x32, 0x91,
  19810. 0xf7, 0xfd, 0xc2, 0x57, 0xff, 0x03, 0x14, 0xdb,
  19811. 0xf1, 0xb7, 0x60, 0x0c, 0x43, 0x59, 0x3f, 0xff,
  19812. 0xac, 0xf1, 0x80, 0x9a, 0x15, 0x6f, 0xd8, 0x6e,
  19813. 0xb7, 0x85, 0x18, 0xc8, 0xec, 0x4e, 0x59, 0x4a,
  19814. 0xe2, 0x91, 0x43, 0x4c, 0xeb, 0x95, 0xb6, 0x2e,
  19815. 0x9a, 0xea, 0x53, 0x68, 0x80, 0x64, 0x69, 0x40,
  19816. 0xf9, 0xec, 0xbd, 0x85, 0x89, 0x26, 0x97, 0x67,
  19817. 0xaf, 0xb0, 0xad, 0x00, 0x1b, 0xd4, 0xfd, 0x94,
  19818. 0xd3, 0xe9, 0x92, 0xb1, 0xb4, 0xbc, 0x5a, 0xaa,
  19819. 0x92, 0x80, 0x89, 0x3b, 0x39, 0x05, 0x6c, 0x22,
  19820. 0x26, 0xfe, 0x5a, 0x28, 0x6c, 0x37, 0x50, 0x5a,
  19821. 0x38, 0x99, 0xcf, 0xf3, 0xc1, 0x96, 0x45, 0xdc,
  19822. 0x01, 0xcb, 0x20, 0x87, 0xa5, 0x00, 0x8c, 0xf5,
  19823. 0x4d, 0xc2, 0xef, 0xb8, 0x9b, 0xd1, 0x87, 0xbe,
  19824. 0xed, 0xd5, 0x0a, 0x29, 0x15, 0x34, 0x59, 0x4c,
  19825. 0x3a, 0x05, 0x22, 0x05, 0x44, 0x4f, 0x9f, 0xc8,
  19826. 0x47, 0x12, 0x24, 0x8e, 0xa8, 0x79, 0xe4, 0x67,
  19827. 0xba, 0x4d, 0x5b, 0x75, 0x56, 0x95, 0xeb, 0xe8,
  19828. 0x8a, 0xfa, 0x8e, 0x01, 0x8c, 0x1b, 0x74, 0x63,
  19829. 0xd9, 0x2f, 0xf7, 0xd3, 0x44, 0x8f, 0xa8, 0xf5,
  19830. 0xaf, 0x6c, 0x4f, 0xdb, 0xe7, 0xc9, 0x6c, 0x71,
  19831. 0x22, 0xa3, 0x1d, 0xf1, 0x40, 0xb2, 0xe0, 0x9a,
  19832. 0xb6, 0x72, 0xc9, 0xc0, 0x13, 0x16, 0xa2, 0x4a,
  19833. 0xe1, 0x92, 0xc7, 0x54, 0x23, 0xab, 0x9d, 0xa1,
  19834. 0xa1, 0xe5, 0x0b, 0xed, 0xba, 0xe8, 0x84, 0x37,
  19835. 0xb2, 0xe7, 0xfe, 0x32, 0x8d, 0xfa, 0x1c, 0x53,
  19836. 0x77, 0x97, 0xc7, 0xf3, 0x48, 0xc9, 0xdb, 0x2d,
  19837. 0x75, 0x52, 0x9d, 0x42, 0x51, 0x78, 0x62, 0x68,
  19838. 0x05, 0x45, 0x15, 0xf8, 0xa2, 0x4e, 0xf3, 0x0b
  19839. };
  19840. WOLFSSL_SMALL_STACK_STATIC const byte q[] = {
  19841. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19842. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19843. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19844. 0x40, 0x52, 0xed, 0x41
  19845. };
  19846. WOLFSSL_SMALL_STACK_STATIC const byte q0[] = {
  19847. 0x00,
  19848. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19849. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19850. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19851. 0x40, 0x52, 0xed, 0x41
  19852. };
  19853. byte priv[256];
  19854. byte pub[256];
  19855. word32 privSz = sizeof(priv);
  19856. word32 pubSz = sizeof(pub);
  19857. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19858. if (key == NULL)
  19859. ERROR_OUT(MEMORY_E, exit_gen_test);
  19860. #endif
  19861. /* Parameter Validation testing. */
  19862. ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz);
  19863. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19864. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19865. ret = wc_DhGenerateKeyPair(key, NULL, priv, &privSz, pub, &pubSz);
  19866. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19868. ret = wc_DhGenerateKeyPair(key, rng, NULL, &privSz, pub, &pubSz);
  19869. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19870. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19871. ret = wc_DhGenerateKeyPair(key, rng, priv, NULL, pub, &pubSz);
  19872. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19873. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19874. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, NULL, &pubSz);
  19875. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19877. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, NULL);
  19878. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19879. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19880. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19881. if (ret != 0)
  19882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19883. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0));
  19884. if (ret != 0)
  19885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19886. wc_FreeDhKey(key);
  19887. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19888. if (ret != 0)
  19889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19890. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q));
  19891. if (ret != 0)
  19892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19893. /* Use API. */
  19894. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19895. #if defined(WOLFSSL_ASYNC_CRYPT)
  19896. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19897. #endif
  19898. if (ret != 0)
  19899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19900. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0));
  19901. if (ret != 0)
  19902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19903. wc_FreeDhKey(key);
  19904. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19905. if (ret != 0)
  19906. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19907. ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
  19908. if (ret != 0)
  19909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19910. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q));
  19911. if (ret != 0)
  19912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19913. #ifndef HAVE_SELFTEST
  19914. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19915. if (ret != 0)
  19916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19917. /* Taint the public key so the check fails. */
  19918. pub[0]++;
  19919. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19920. if (ret != WC_NO_ERR_TRACE(MP_CMP_E)) {
  19921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19922. }
  19923. #ifdef WOLFSSL_KEY_GEN
  19924. wc_FreeDhKey(key);
  19925. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19926. if (ret != 0)
  19927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19928. ret = wc_DhGenerateParams(rng, 2048, key);
  19929. if (ret != 0)
  19930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19931. privSz = sizeof(priv);
  19932. pubSz = sizeof(pub);
  19933. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19934. #if defined(WOLFSSL_ASYNC_CRYPT)
  19935. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19936. #endif
  19937. if (ret != 0)
  19938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19939. #endif /* WOLFSSL_KEY_GEN */
  19940. #endif /* HAVE_SELFTEST */
  19941. ret = 0;
  19942. exit_gen_test:
  19943. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19944. if (key) {
  19945. wc_FreeDhKey(key);
  19946. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19947. }
  19948. #else
  19949. wc_FreeDhKey(key);
  19950. #endif
  19951. return ret;
  19952. }
  19953. static wc_test_ret_t dh_generate_test(WC_RNG *rng)
  19954. {
  19955. wc_test_ret_t ret = 0;
  19956. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19957. DhKey *smallKey = NULL;
  19958. #else
  19959. DhKey smallKey[1];
  19960. #endif
  19961. byte p[2] = { 1, 7 }; /* 263 in decimal */
  19962. byte g[2] = { 0, 2 };
  19963. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19964. #ifdef WOLFSSL_DH_CONST
  19965. /* the table for constant DH lookup will round to the lowest byte size 21 */
  19966. byte priv[21];
  19967. byte pub[21];
  19968. #else
  19969. byte priv[2];
  19970. byte pub[2];
  19971. #endif
  19972. word32 privSz = sizeof(priv);
  19973. word32 pubSz = sizeof(pub);
  19974. #endif
  19975. int smallKey_inited = 0;
  19976. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19977. if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  19978. return WC_TEST_RET_ENC_ERRNO;
  19979. #endif
  19980. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19981. if (ret != 0)
  19982. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19983. smallKey_inited = 1;
  19984. /* Parameter Validation testing. */
  19985. ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId);
  19986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19987. return WC_TEST_RET_ENC_EC(ret);
  19988. wc_FreeDhKey(NULL);
  19989. ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g));
  19990. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19991. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19992. }
  19993. ret = wc_DhSetKey(smallKey, NULL, sizeof(p), g, sizeof(g));
  19994. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19996. }
  19997. ret = wc_DhSetKey(smallKey, p, 0, g, sizeof(g));
  19998. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19999. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20000. }
  20001. ret = wc_DhSetKey(smallKey, p, sizeof(p), NULL, sizeof(g));
  20002. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20003. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20004. }
  20005. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, 0);
  20006. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  20007. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20008. }
  20009. ret = wc_DhSetKey(smallKey, p, sizeof(p), g, sizeof(g));
  20010. if (ret != 0)
  20011. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20012. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  20013. /* Use API. */
  20014. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20015. #if defined(WOLFSSL_ASYNC_CRYPT)
  20016. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20017. #endif
  20018. if (ret != 0) {
  20019. ret = WC_TEST_RET_ENC_EC(ret);
  20020. }
  20021. #else
  20022. (void)rng;
  20023. #if defined(HAVE_FIPS) || !defined(WOLFSSL_NO_DH186)
  20024. ret = 0;
  20025. #endif
  20026. #endif
  20027. #if !defined(HAVE_FIPS) && defined(WOLFSSL_NO_DH186)
  20028. {
  20029. byte priv[260];
  20030. byte pub[260];
  20031. word32 privSz = sizeof(priv);
  20032. word32 pubSz = sizeof(pub);
  20033. /* test odd ball param generation with DH */
  20034. wc_FreeDhKey(smallKey);
  20035. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  20036. if (ret != 0)
  20037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20038. /* should fail since modSz is 16 and group size is 20 */
  20039. ret = wc_DhGenerateParams(rng, 128, smallKey);
  20040. if (ret == 0)
  20041. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20042. ret = wc_DhGenerateParams(rng, 2056, smallKey);
  20043. if (ret != 0)
  20044. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20045. privSz = sizeof(priv);
  20046. pubSz = sizeof(pub);
  20047. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20048. #if defined(WOLFSSL_ASYNC_CRYPT)
  20049. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20050. #endif
  20051. if (ret != 0)
  20052. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20053. }
  20054. #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */
  20055. exit_gen_test:
  20056. if (smallKey_inited)
  20057. wc_FreeDhKey(smallKey);
  20058. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20059. XFREE(smallKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20060. #endif
  20061. return ret;
  20062. }
  20063. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20064. typedef struct dh_pubvalue_test {
  20065. const byte* data;
  20066. word32 len;
  20067. } dh_pubvalue_test;
  20068. static wc_test_ret_t dh_test_check_pubvalue(void)
  20069. {
  20070. wc_test_ret_t ret;
  20071. word32 i;
  20072. WOLFSSL_SMALL_STACK_STATIC const byte prime[] = {0x01, 0x00, 0x01};
  20073. WOLFSSL_SMALL_STACK_STATIC const byte pubValZero[] = { 0x00 };
  20074. WOLFSSL_SMALL_STACK_STATIC const byte pubValZeroLong[] = { 0x00, 0x00, 0x00 };
  20075. WOLFSSL_SMALL_STACK_STATIC const byte pubValOne[] = { 0x01 };
  20076. WOLFSSL_SMALL_STACK_STATIC const byte pubValOneLong[] = { 0x00, 0x00, 0x01 };
  20077. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeMinusOne[] = { 0x01, 0x00, 0x00 };
  20078. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeLong[] = {0x00, 0x01, 0x00, 0x01};
  20079. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimePlusOne[] = { 0x01, 0x00, 0x02 };
  20080. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig0[] = { 0x02, 0x00, 0x01 };
  20081. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig1[] = { 0x01, 0x01, 0x01 };
  20082. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooLong[] = { 0x01, 0x00, 0x00, 0x01 };
  20083. const dh_pubvalue_test dh_pubval_fail[] = {
  20084. { prime, sizeof(prime) },
  20085. { pubValZero, sizeof(pubValZero) },
  20086. { pubValZeroLong, sizeof(pubValZeroLong) },
  20087. { pubValOne, sizeof(pubValOne) },
  20088. { pubValOneLong, sizeof(pubValOneLong) },
  20089. { pubValPrimeMinusOne, sizeof(pubValPrimeMinusOne) },
  20090. { pubValPrimeLong, sizeof(pubValPrimeLong) },
  20091. { pubValPrimePlusOne, sizeof(pubValPrimePlusOne) },
  20092. { pubValTooBig0, sizeof(pubValTooBig0) },
  20093. { pubValTooBig1, sizeof(pubValTooBig1) },
  20094. { pubValTooLong, sizeof(pubValTooLong) },
  20095. };
  20096. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwo[] = { 0x02 };
  20097. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwoLong[] = { 0x00, 0x00, 0x02 };
  20098. WOLFSSL_SMALL_STACK_STATIC const byte pubValGood[] = { 0x12, 0x34 };
  20099. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLen[] = { 0x00, 0x12, 0x34 };
  20100. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLong[] = { 0x00, 0x00, 0x12, 0x34 };
  20101. const dh_pubvalue_test dh_pubval_pass[] = {
  20102. { pubValTwo, sizeof(pubValTwo) },
  20103. { pubValTwoLong, sizeof(pubValTwoLong) },
  20104. { pubValGood, sizeof(pubValGood) },
  20105. { pubValGoodLen, sizeof(pubValGoodLen) },
  20106. { pubValGoodLong, sizeof(pubValGoodLong) },
  20107. };
  20108. for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) {
  20109. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data,
  20110. dh_pubval_fail[i].len);
  20111. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  20112. return WC_TEST_RET_ENC_I(i);
  20113. }
  20114. for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) {
  20115. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data,
  20116. dh_pubval_pass[i].len);
  20117. if (ret != 0)
  20118. return WC_TEST_RET_ENC_I(i);
  20119. }
  20120. return 0;
  20121. }
  20122. #endif
  20123. #if defined(HAVE_FFDHE)
  20124. #if defined(HAVE_FFDHE_4096)
  20125. #define MAX_DH_PRIV_SZ 39
  20126. #define MAX_DH_KEY_SZ 512
  20127. #elif defined(HAVE_FFDHE_3072)
  20128. #define MAX_DH_PRIV_SZ 34
  20129. #define MAX_DH_KEY_SZ 384
  20130. #else
  20131. #define MAX_DH_PRIV_SZ 29
  20132. #define MAX_DH_KEY_SZ 256
  20133. #endif
  20134. #ifndef WC_NO_RNG
  20135. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20136. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20137. #ifdef HAVE_PUBLIC_FFDHE
  20138. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
  20139. #else
  20140. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, int name)
  20141. #endif
  20142. {
  20143. wc_test_ret_t ret;
  20144. word32 privSz, pubSz, privSz2, pubSz2;
  20145. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20146. byte *priv = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20147. byte *pub = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20148. byte *priv2 = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20149. byte *pub2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20150. byte *agree = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20151. byte *agree2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20152. DhKey *key = (DhKey*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20153. DhKey *key2 = (DhKey*)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20154. #else
  20155. byte priv[MAX_DH_PRIV_SZ];
  20156. byte pub[MAX_DH_KEY_SZ];
  20157. byte priv2[MAX_DH_PRIV_SZ];
  20158. byte pub2[MAX_DH_KEY_SZ];
  20159. byte agree[MAX_DH_KEY_SZ];
  20160. byte agree2[MAX_DH_KEY_SZ];
  20161. DhKey key[1];
  20162. DhKey key2[1];
  20163. #endif
  20164. word32 agreeSz = MAX_DH_KEY_SZ;
  20165. word32 agreeSz2 = MAX_DH_KEY_SZ;
  20166. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20167. if ((priv == NULL) ||
  20168. (pub == NULL) ||
  20169. (priv2 == NULL) ||
  20170. (pub2 == NULL) ||
  20171. (agree == NULL) ||
  20172. (agree2 == NULL) ||
  20173. (key == NULL) ||
  20174. (key2 == NULL))
  20175. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20176. #endif
  20177. pubSz = MAX_DH_KEY_SZ;
  20178. pubSz2 = MAX_DH_KEY_SZ;
  20179. #ifdef HAVE_PUBLIC_FFDHE
  20180. privSz = MAX_DH_PRIV_SZ;
  20181. privSz2 = MAX_DH_PRIV_SZ;
  20182. #else
  20183. privSz = wc_DhGetNamedKeyMinSize(name);
  20184. privSz2 = privSz;
  20185. #endif
  20186. XMEMSET(key, 0, sizeof(*key));
  20187. XMEMSET(key2, 0, sizeof(*key2));
  20188. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20189. if (ret != 0)
  20190. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20191. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20192. if (ret != 0)
  20193. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20194. #ifdef HAVE_PUBLIC_FFDHE
  20195. ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len);
  20196. #else
  20197. ret = wc_DhSetNamedKey(key, name);
  20198. #endif
  20199. if (ret != 0)
  20200. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20201. #ifdef HAVE_PUBLIC_FFDHE
  20202. ret = wc_DhSetKey(key2, params->p, params->p_len, params->g,
  20203. params->g_len);
  20204. #else
  20205. ret = wc_DhSetNamedKey(key2, name);
  20206. #endif
  20207. if (ret != 0)
  20208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20209. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20210. #if defined(WOLFSSL_ASYNC_CRYPT)
  20211. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20212. #endif
  20213. if (ret != 0)
  20214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20215. ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2);
  20216. #if defined(WOLFSSL_ASYNC_CRYPT)
  20217. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20218. #endif
  20219. if (ret != 0)
  20220. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20221. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20222. #if defined(WOLFSSL_ASYNC_CRYPT)
  20223. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20224. #endif
  20225. if (ret != 0)
  20226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20227. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20228. #if defined(WOLFSSL_ASYNC_CRYPT)
  20229. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20230. #endif
  20231. if (ret != 0)
  20232. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20233. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20234. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20235. }
  20236. #if (defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH)) && \
  20237. !defined(HAVE_INTEL_QA)
  20238. /* Make p even */
  20239. key->p.dp[0] &= (mp_digit)-2;
  20240. if (ret != 0)
  20241. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20242. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20243. #if defined(WOLFSSL_ASYNC_CRYPT)
  20244. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20245. #endif
  20246. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20247. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  20248. {
  20249. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20250. }
  20251. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20252. #if defined(WOLFSSL_ASYNC_CRYPT)
  20253. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20254. #endif
  20255. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20256. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20257. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20258. {
  20259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20260. }
  20261. #ifndef HAVE_SELFTEST
  20262. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  20263. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20264. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20265. ret != WC_NO_ERR_TRACE(MP_CMP_E) &&
  20266. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20267. {
  20268. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20269. }
  20270. #endif
  20271. /* Getting here means success - set ret to 0. */
  20272. ret = 0;
  20273. #endif /* (SP DH or Fast Math) and not Intel QuickAssist */
  20274. done:
  20275. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) && \
  20276. !defined(WC_NO_RNG)
  20277. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20278. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20279. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20280. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20281. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20282. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20283. if (key) {
  20284. wc_FreeDhKey(key);
  20285. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20286. }
  20287. if (key2) {
  20288. wc_FreeDhKey(key2);
  20289. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20290. }
  20291. #else
  20292. wc_FreeDhKey(key);
  20293. wc_FreeDhKey(key2);
  20294. #endif
  20295. return ret;
  20296. }
  20297. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  20298. #endif /* !WC_NO_RNG */
  20299. #endif /* HAVE_FFDHE */
  20300. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void)
  20301. {
  20302. wc_test_ret_t ret;
  20303. word32 bytes;
  20304. word32 idx = 0;
  20305. word32 privSz = 0;
  20306. word32 pubSz = 0;
  20307. word32 privSz2 = 0;
  20308. word32 pubSz2 = 0;
  20309. #ifndef WC_NO_RNG
  20310. WC_RNG rng;
  20311. int rngInit = 0;
  20312. #endif
  20313. int keyInit = 0, key2Init = 0;
  20314. #define DH_TEST_TMP_SIZE 1024
  20315. #if !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  20316. #define DH_TEST_BUF_SIZE 256
  20317. #else
  20318. #define DH_TEST_BUF_SIZE 512
  20319. #endif
  20320. #ifndef WC_NO_RNG
  20321. word32 agreeSz = DH_TEST_BUF_SIZE;
  20322. word32 agreeSz2 = DH_TEST_BUF_SIZE;
  20323. #endif
  20324. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20325. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20326. DhKey *key2 = (DhKey *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20327. byte *tmp = (byte *)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20328. #else
  20329. DhKey key[1];
  20330. DhKey key2[1];
  20331. byte tmp[DH_TEST_TMP_SIZE];
  20332. #endif
  20333. #ifndef WC_NO_RNG
  20334. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20335. byte *priv = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20336. byte *pub = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20337. byte *priv2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20338. byte *pub2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20339. byte *agree = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20340. byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20341. if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL ||
  20342. agree == NULL || agree2 == NULL) {
  20343. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20344. }
  20345. #else
  20346. byte priv[DH_TEST_BUF_SIZE];
  20347. byte pub[DH_TEST_BUF_SIZE];
  20348. byte priv2[DH_TEST_BUF_SIZE];
  20349. byte pub2[DH_TEST_BUF_SIZE];
  20350. byte agree[DH_TEST_BUF_SIZE];
  20351. byte agree2[DH_TEST_BUF_SIZE];
  20352. #endif
  20353. #endif /* !WC_NO_RNG */
  20354. WOLFSSL_ENTER("dh_test");
  20355. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20356. if (key == NULL || key2 == NULL || tmp == NULL) {
  20357. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20358. }
  20359. #endif
  20360. #ifdef USE_CERT_BUFFERS_1024
  20361. XMEMCPY(tmp, dh_key_der_1024, (size_t)sizeof_dh_key_der_1024);
  20362. bytes = (size_t)sizeof_dh_key_der_1024;
  20363. #elif defined(USE_CERT_BUFFERS_2048)
  20364. XMEMCPY(tmp, dh_key_der_2048, (size_t)sizeof_dh_key_der_2048);
  20365. bytes = (size_t)sizeof_dh_key_der_2048;
  20366. #elif defined(USE_CERT_BUFFERS_3072)
  20367. XMEMCPY(tmp, dh_key_der_3072, (size_t)sizeof_dh_key_der_3072);
  20368. bytes = (size_t)sizeof_dh_key_der_3072;
  20369. #elif defined(USE_CERT_BUFFERS_4096)
  20370. XMEMCPY(tmp, dh_key_der_4096, (size_t)sizeof_dh_key_der_4096);
  20371. bytes = (size_t)sizeof_dh_key_der_4096;
  20372. #elif defined(NO_ASN)
  20373. /* don't use file, no DER parsing */
  20374. #elif !defined(NO_FILESYSTEM)
  20375. {
  20376. XFILE file = XFOPEN(dhParamsFile, "rb");
  20377. if (! file)
  20378. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20379. bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20380. XFCLOSE(file);
  20381. if (bytes == 0)
  20382. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20383. }
  20384. #else
  20385. /* No DH key to use. */
  20386. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20387. #endif /* USE_CERT_BUFFERS */
  20388. (void)idx;
  20389. (void)tmp;
  20390. (void)bytes;
  20391. pubSz = DH_TEST_BUF_SIZE;
  20392. pubSz2 = DH_TEST_BUF_SIZE;
  20393. privSz = DH_TEST_BUF_SIZE;
  20394. privSz2 = DH_TEST_BUF_SIZE;
  20395. #ifndef WC_NO_RNG
  20396. XMEMSET(&rng, 0, sizeof(rng));
  20397. #endif
  20398. /* Use API for coverage. */
  20399. ret = wc_InitDhKey(key);
  20400. if (ret != 0)
  20401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20402. wc_FreeDhKey(key);
  20403. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20404. if (ret != 0)
  20405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20406. keyInit = 1;
  20407. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20408. if (ret != 0)
  20409. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20410. key2Init = 1;
  20411. #ifdef NO_ASN
  20412. #ifndef WOLFSSL_SP_MATH
  20413. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20414. if (ret != 0)
  20415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20416. ret = wc_DhSetKey(key2, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20417. if (ret != 0)
  20418. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20419. #else
  20420. ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20421. sizeof(dh2048_g));
  20422. if (ret != 0)
  20423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20424. ret = wc_DhSetKey(key2, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20425. sizeof(dh2048_g));
  20426. if (ret != 0)
  20427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20428. #endif
  20429. #else
  20430. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20431. if (ret != 0)
  20432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20433. idx = 0;
  20434. ret = wc_DhKeyDecode(tmp, &idx, key2, bytes);
  20435. if (ret != 0)
  20436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20437. #endif
  20438. #ifndef WC_NO_RNG
  20439. #ifndef HAVE_FIPS
  20440. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20441. #else
  20442. ret = wc_InitRng(&rng);
  20443. #endif
  20444. if (ret != 0)
  20445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20446. rngInit = 1;
  20447. ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz);
  20448. #if defined(WOLFSSL_ASYNC_CRYPT)
  20449. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20450. #endif
  20451. if (ret != 0)
  20452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20453. ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2);
  20454. #if defined(WOLFSSL_ASYNC_CRYPT)
  20455. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20456. #endif
  20457. if (ret != 0)
  20458. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20459. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20460. #if defined(WOLFSSL_ASYNC_CRYPT)
  20461. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20462. #endif
  20463. if (ret != 0)
  20464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20465. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20466. #if defined(WOLFSSL_ASYNC_CRYPT)
  20467. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20468. #endif
  20469. if (ret != 0)
  20470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20471. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20472. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20473. }
  20474. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) && \
  20475. !defined(HAVE_SELFTEST)
  20476. agreeSz = DH_TEST_BUF_SIZE;
  20477. agreeSz2 = DH_TEST_BUF_SIZE;
  20478. ret = wc_DhAgree_ct(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20479. if (ret != 0)
  20480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20481. ret = wc_DhAgree_ct(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20482. if (ret != 0)
  20483. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20484. #ifdef WOLFSSL_PUBLIC_MP
  20485. if (agreeSz != (word32)mp_unsigned_bin_size(&key->p))
  20486. {
  20487. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20488. }
  20489. #endif
  20490. if (agreeSz != agreeSz2)
  20491. {
  20492. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20493. }
  20494. if (XMEMCMP(agree, agree2, agreeSz) != 0)
  20495. {
  20496. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20497. }
  20498. #endif /* (!HAVE_FIPS || FIPS_VERSION_GE(7,0)) && !HAVE_SELFTEST */
  20499. #endif /* !WC_NO_RNG */
  20500. #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20501. ret = wc_DhCheckPrivKey(NULL, NULL, 0);
  20502. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20503. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20504. ret = wc_DhCheckPrivKey(key, priv, privSz);
  20505. if (ret != 0)
  20506. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20507. ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  20508. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20510. {
  20511. word32 pSz, qSz, gSz;
  20512. ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz);
  20513. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  20514. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20515. }
  20516. #endif
  20517. /* Test DH key import / export */
  20518. #if defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM) && \
  20519. (!defined(HAVE_FIPS) || \
  20520. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  20521. wc_FreeDhKey(key);
  20522. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20523. if (ret != 0)
  20524. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20525. #ifndef NO_ASN
  20526. {
  20527. /* DH Private - Key Export / Import */
  20528. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20529. byte *tmp2;
  20530. #else
  20531. byte tmp2[DH_TEST_TMP_SIZE];
  20532. #endif
  20533. #if defined(USE_CERT_BUFFERS_2048)
  20534. XMEMCPY(tmp, dh_ffdhe_statickey_der_2048, sizeof_dh_ffdhe_statickey_der_2048);
  20535. bytes = sizeof_dh_ffdhe_statickey_der_2048;
  20536. #else
  20537. XFILE file = XFOPEN(dhKeyFile, "rb");
  20538. if (!file)
  20539. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20540. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20541. XFCLOSE(file);
  20542. if (bytes == 0)
  20543. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20544. #endif
  20545. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20546. tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20547. if (tmp2 == NULL)
  20548. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20549. #endif
  20550. idx = 0;
  20551. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20552. /* Import DH Private key as DER */
  20553. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20554. if (ret == 0) {
  20555. /* Export as DER */
  20556. idx = DH_TEST_TMP_SIZE;
  20557. ret = wc_DhPrivKeyToDer(key, tmp2, &idx);
  20558. }
  20559. /* Verify export matches original */
  20560. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20561. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20562. }
  20563. /* DH Public Key - Export / Import */
  20564. #if defined(USE_CERT_BUFFERS_2048)
  20565. XMEMCPY(tmp, dh_ffdhe_pub_statickey_der_2048, sizeof_dh_ffdhe_pub_statickey_der_2048);
  20566. bytes = sizeof_dh_ffdhe_pub_statickey_der_2048;
  20567. #else
  20568. file = XFOPEN(dhKeyPubFile, "rb");
  20569. if (!file)
  20570. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20571. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20572. XFCLOSE(file);
  20573. if (bytes == 0)
  20574. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20575. #endif
  20576. /* for HAVE_WOLF_BIGINT prevent leak */
  20577. wc_FreeDhKey(key);
  20578. (void)wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20579. idx = 0;
  20580. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20581. /* Import DH Public key as DER */
  20582. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20583. if (ret == 0) {
  20584. /* Export as DER */
  20585. idx = DH_TEST_TMP_SIZE;
  20586. ret = wc_DhPubKeyToDer(key, tmp2, &idx);
  20587. }
  20588. /* Verify export matches original */
  20589. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20590. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20591. }
  20592. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20593. XFREE(tmp2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20594. #endif
  20595. }
  20596. #else
  20597. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20598. if (ret != 0)
  20599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20600. #endif /* !NO_ASN */
  20601. privSz = DH_TEST_BUF_SIZE;
  20602. pubSz = DH_TEST_BUF_SIZE;
  20603. ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz);
  20604. if (ret != 0)
  20605. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20606. ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz);
  20607. if (ret != 0)
  20608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20609. #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */
  20610. #ifndef WC_NO_RNG
  20611. ret = dh_generate_test(&rng);
  20612. if (ret != 0)
  20613. ERROR_OUT(ret, done);
  20614. ret = dh_fips_generate_test(&rng);
  20615. if (ret != 0)
  20616. ERROR_OUT(ret, done);
  20617. #endif /* !WC_NO_RNG */
  20618. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20619. ret = dh_test_check_pubvalue();
  20620. if (ret != 0)
  20621. ERROR_OUT(ret, done);
  20622. #endif
  20623. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20624. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20625. /* RNG with DH and SP_ASM code not supported in the in-lined FIPS ASM code,
  20626. * this will be available for testing in the 140-3 module */
  20627. #ifndef WC_NO_RNG
  20628. /* Specialized code for key gen when using FFDHE-2048, FFDHE-3072 and FFDHE-4096 */
  20629. #ifdef HAVE_FFDHE_2048
  20630. #ifdef HAVE_PUBLIC_FFDHE
  20631. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe2048_Get());
  20632. #else
  20633. ret = dh_ffdhe_test(&rng, WC_FFDHE_2048);
  20634. #endif
  20635. if (ret != 0)
  20636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20637. #endif
  20638. #ifdef HAVE_FFDHE_3072
  20639. #ifdef HAVE_PUBLIC_FFDHE
  20640. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe3072_Get());
  20641. #else
  20642. ret = dh_ffdhe_test(&rng, WC_FFDHE_3072);
  20643. #endif
  20644. if (ret != 0)
  20645. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20646. #endif
  20647. #ifdef HAVE_FFDHE_4096
  20648. #ifdef HAVE_PUBLIC_FFDHE
  20649. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe4096_Get());
  20650. #else
  20651. ret = dh_ffdhe_test(&rng, WC_FFDHE_4096);
  20652. #endif
  20653. if (ret != 0)
  20654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20655. #endif
  20656. #endif /* !WC_NO_RNG */
  20657. #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */
  20658. wc_FreeDhKey(key);
  20659. keyInit = 0;
  20660. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  20661. !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(WC_NO_RNG)
  20662. /* Test Check Key */
  20663. ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g),
  20664. NULL, 0, 0, &rng);
  20665. if (ret != 0)
  20666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20667. keyInit = 1; /* DhSetCheckKey also initializes the key, free it */
  20668. #endif
  20669. done:
  20670. #ifndef WC_NO_RNG
  20671. if (rngInit)
  20672. wc_FreeRng(&rng);
  20673. #endif
  20674. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20675. if (key) {
  20676. if (keyInit)
  20677. wc_FreeDhKey(key);
  20678. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20679. }
  20680. if (key2) {
  20681. if (key2Init)
  20682. wc_FreeDhKey(key2);
  20683. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20684. }
  20685. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20686. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20687. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20688. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20689. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20690. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20691. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20692. #else
  20693. if (keyInit)
  20694. wc_FreeDhKey(key);
  20695. if (key2Init)
  20696. wc_FreeDhKey(key2);
  20697. #endif
  20698. (void)privSz;
  20699. (void)pubSz;
  20700. (void)pubSz2;
  20701. (void)privSz2;
  20702. return ret;
  20703. #undef DH_TEST_BUF_SIZE
  20704. #undef DH_TEST_TMP_SIZE
  20705. }
  20706. #endif /* NO_DH */
  20707. #ifndef NO_DSA
  20708. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
  20709. {
  20710. wc_test_ret_t ret = 0;
  20711. int answer;
  20712. word32 bytes;
  20713. word32 idx = 0;
  20714. WC_RNG rng;
  20715. int rng_inited = 0;
  20716. wc_Sha sha;
  20717. byte hash[WC_SHA_DIGEST_SIZE];
  20718. byte signature[40];
  20719. int key_inited = 0;
  20720. #ifdef WOLFSSL_KEY_GEN
  20721. byte* der = 0;
  20722. int derIn_inited = 0;
  20723. int genKey_inited = 0;
  20724. #endif
  20725. #define DSA_TEST_TMP_SIZE 1024
  20726. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20727. byte *tmp = (byte *)XMALLOC(DSA_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20728. DsaKey *key = (DsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20729. #ifdef WOLFSSL_KEY_GEN
  20730. DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20731. DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20732. #endif
  20733. WOLFSSL_ENTER("dsa_test");
  20734. if ((tmp == NULL) ||
  20735. (key == NULL)
  20736. #ifdef WOLFSSL_KEY_GEN
  20737. || (derIn == NULL)
  20738. || (genKey == NULL)
  20739. #endif
  20740. ) {
  20741. ret = WC_TEST_RET_ENC_NC;
  20742. goto out;
  20743. }
  20744. #else
  20745. byte tmp[1024];
  20746. DsaKey key[1];
  20747. #ifdef WOLFSSL_KEY_GEN
  20748. DsaKey derIn[1];
  20749. DsaKey genKey[1];
  20750. #endif
  20751. #endif
  20752. #ifdef USE_CERT_BUFFERS_1024
  20753. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20754. bytes = sizeof_dsa_key_der_1024;
  20755. #elif defined(USE_CERT_BUFFERS_2048)
  20756. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20757. bytes = sizeof_dsa_key_der_2048;
  20758. #else
  20759. {
  20760. XFILE file = XFOPEN(dsaKey, "rb");
  20761. if (!file)
  20762. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20763. bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file);
  20764. XFCLOSE(file);
  20765. if (bytes == 0)
  20766. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20767. }
  20768. #endif /* USE_CERT_BUFFERS */
  20769. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  20770. if (ret != 0)
  20771. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20772. wc_ShaUpdate(&sha, tmp, bytes);
  20773. wc_ShaFinal(&sha, hash);
  20774. wc_ShaFree(&sha);
  20775. ret = wc_InitDsaKey(key);
  20776. if (ret != 0)
  20777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20778. key_inited = 1;
  20779. ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes);
  20780. if (ret != 0)
  20781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20782. #ifndef HAVE_FIPS
  20783. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20784. #else
  20785. ret = wc_InitRng(&rng);
  20786. #endif
  20787. if (ret != 0)
  20788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20789. rng_inited = 1;
  20790. ret = wc_DsaSign(hash, signature, key, &rng);
  20791. if (ret != 0)
  20792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20793. ret = wc_DsaVerify(hash, signature, key, &answer);
  20794. if (ret != 0)
  20795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20796. if (answer != 1)
  20797. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20798. wc_FreeDsaKey(key);
  20799. key_inited = 0;
  20800. ret = wc_InitDsaKey_h(key, NULL);
  20801. if (ret != 0)
  20802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20803. key_inited = 1;
  20804. #ifdef WOLFSSL_KEY_GEN
  20805. {
  20806. int derSz = 0;
  20807. ret = wc_InitDsaKey(genKey);
  20808. if (ret != 0)
  20809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20810. genKey_inited = 1;
  20811. ret = wc_MakeDsaParameters(&rng, 1024, genKey);
  20812. if (ret != 0)
  20813. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20814. ret = wc_MakeDsaKey(&rng, genKey);
  20815. if (ret != 0)
  20816. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20817. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20818. if (der == NULL)
  20819. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20820. derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF);
  20821. if (derSz < 0)
  20822. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out);
  20823. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  20824. DSA_PRIVATEKEY_TYPE);
  20825. if (ret != 0)
  20826. goto out;
  20827. ret = wc_InitDsaKey(derIn);
  20828. if (ret != 0)
  20829. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20830. derIn_inited = 1;
  20831. idx = 0;
  20832. ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, (word32)derSz);
  20833. if (ret != 0)
  20834. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20835. }
  20836. #endif /* WOLFSSL_KEY_GEN */
  20837. out:
  20838. #ifdef WOLFSSL_KEY_GEN
  20839. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20840. #endif
  20841. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20842. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20843. if (key) {
  20844. if (key_inited)
  20845. wc_FreeDsaKey(key);
  20846. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20847. }
  20848. #ifdef WOLFSSL_KEY_GEN
  20849. if (derIn) {
  20850. if (derIn_inited)
  20851. wc_FreeDsaKey(derIn);
  20852. XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20853. }
  20854. if (genKey) {
  20855. if (genKey_inited)
  20856. wc_FreeDsaKey(genKey);
  20857. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20858. }
  20859. #endif
  20860. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  20861. if (key_inited)
  20862. wc_FreeDsaKey(key);
  20863. #ifdef WOLFSSL_KEY_GEN
  20864. if (derIn_inited)
  20865. wc_FreeDsaKey(derIn);
  20866. if (genKey_inited)
  20867. wc_FreeDsaKey(genKey);
  20868. #endif
  20869. #endif
  20870. if (rng_inited)
  20871. wc_FreeRng(&rng);
  20872. return ret;
  20873. }
  20874. #endif /* NO_DSA */
  20875. #ifdef WOLFCRYPT_HAVE_SRP
  20876. static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
  20877. {
  20878. wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
  20879. WC_RNG rng;
  20880. if(NULL == buf || !size)
  20881. return WC_TEST_RET_ENC_NC;
  20882. if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) {
  20883. ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size);
  20884. wc_FreeRng(&rng);
  20885. }
  20886. return ret;
  20887. }
  20888. static wc_test_ret_t srp_test_digest(SrpType dgstType)
  20889. {
  20890. wc_test_ret_t r;
  20891. byte clientPubKey[192]; /* A */
  20892. byte serverPubKey[192]; /* B */
  20893. word32 clientPubKeySz = 192;
  20894. word32 serverPubKeySz = 192;
  20895. byte username[] = "user";
  20896. word32 usernameSz = 4;
  20897. byte password[] = "password";
  20898. word32 passwordSz = 8;
  20899. WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
  20900. 0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
  20901. 0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
  20902. 0x7a, 0xe9, 0x1f, 0x85, 0x36, 0x18, 0xc4, 0x35,
  20903. 0x3f, 0xf8, 0x8a, 0x8f, 0x8c, 0x10, 0x2e, 0x01,
  20904. 0x58, 0x1d, 0x41, 0xcb, 0xc4, 0x47, 0xa8, 0xaf,
  20905. 0x9a, 0x6f, 0x58, 0x14, 0xa4, 0x68, 0xf0, 0x9c,
  20906. 0xa6, 0xe7, 0xbf, 0x0d, 0xe9, 0x62, 0x0b, 0xd7,
  20907. 0x26, 0x46, 0x5b, 0x27, 0xcb, 0x4c, 0xf9, 0x7e,
  20908. 0x1e, 0x8b, 0xe6, 0xdd, 0x29, 0xb7, 0xb7, 0x15,
  20909. 0x2e, 0xcf, 0x23, 0xa6, 0x4b, 0x97, 0x9f, 0x89,
  20910. 0xd4, 0x86, 0xc4, 0x90, 0x63, 0x92, 0xf4, 0x30,
  20911. 0x26, 0x69, 0x48, 0x9d, 0x7a, 0x4f, 0xad, 0xb5,
  20912. 0x6a, 0x51, 0xad, 0xeb, 0xf9, 0x90, 0x31, 0x77,
  20913. 0x53, 0x30, 0x2a, 0x85, 0xf7, 0x11, 0x21, 0x0c,
  20914. 0xb8, 0x4b, 0x56, 0x03, 0x5e, 0xbb, 0x25, 0x33,
  20915. 0x7c, 0xd9, 0x5a, 0xd1, 0x5c, 0xb2, 0xd4, 0x53,
  20916. 0xc5, 0x16, 0x68, 0xf0, 0xdf, 0x48, 0x55, 0x3e,
  20917. 0xd4, 0x59, 0x87, 0x64, 0x59, 0xaa, 0x39, 0x01,
  20918. 0x45, 0x89, 0x9c, 0x72, 0xff, 0xdd, 0x8f, 0x6d,
  20919. 0xa0, 0x42, 0xbc, 0x6f, 0x6e, 0x62, 0x18, 0x2d,
  20920. 0x50, 0xe8, 0x18, 0x97, 0x87, 0xfc, 0xef, 0x1f,
  20921. 0xf5, 0x53, 0x68, 0xe8, 0x49, 0xd1, 0xa2, 0xe8,
  20922. 0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
  20923. 0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
  20924. };
  20925. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  20926. 0x02
  20927. };
  20928. byte salt[10];
  20929. byte verifier[192];
  20930. word32 v_size = sizeof(verifier);
  20931. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  20932. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  20933. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20934. Srp *cli = (Srp *)XMALLOC(sizeof *cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20935. Srp *srv = (Srp *)XMALLOC(sizeof *srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20936. byte *clientProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20937. DYNAMIC_TYPE_TMP_BUFFER); /* M1 */
  20938. byte *serverProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20939. DYNAMIC_TYPE_TMP_BUFFER); /* M2 */
  20940. if ((cli == NULL) ||
  20941. (srv == NULL) ||
  20942. (clientProof == NULL) ||
  20943. (serverProof == NULL)) {
  20944. r = WC_TEST_RET_ENC_NC;
  20945. goto out;
  20946. }
  20947. #else
  20948. Srp cli[1], srv[1];
  20949. byte clientProof[SRP_MAX_DIGEST_SIZE]; /* M1 */
  20950. byte serverProof[SRP_MAX_DIGEST_SIZE]; /* M2 */
  20951. #endif
  20952. /* set as 0's so if second init on srv not called SrpTerm is not on
  20953. * garbage values */
  20954. XMEMSET(srv, 0, sizeof *srv);
  20955. XMEMSET(cli, 0, sizeof *cli);
  20956. /* generating random salt */
  20957. r = generate_random_salt(salt, sizeof(salt));
  20958. /* client knows username and password. */
  20959. /* server knows N, g, salt and verifier. */
  20960. if (!r) r = wc_SrpInit_ex(cli, dgstType, SRP_CLIENT_SIDE, HEAP_HINT, devId);
  20961. if (!r) r = wc_SrpSetUsername(cli, username, usernameSz);
  20962. /* loading N, g and salt in advance to generate the verifier. */
  20963. if (!r) r = wc_SrpSetParams(cli, N, sizeof(N),
  20964. g, sizeof(g),
  20965. salt, sizeof(salt));
  20966. if (!r) r = wc_SrpSetPassword(cli, password, passwordSz);
  20967. if (!r) r = wc_SrpGetVerifier(cli, verifier, &v_size);
  20968. /* client sends username to server */
  20969. if (!r) r = wc_SrpInit_ex(srv, dgstType, SRP_SERVER_SIDE, HEAP_HINT, devId);
  20970. if (!r) r = wc_SrpSetUsername(srv, username, usernameSz);
  20971. if (!r) r = wc_SrpSetParams(srv, N, sizeof(N),
  20972. g, sizeof(g),
  20973. salt, sizeof(salt));
  20974. if (!r) r = wc_SrpSetVerifier(srv, verifier, v_size);
  20975. if (!r) r = wc_SrpGetPublic(srv, serverPubKey, &serverPubKeySz);
  20976. /* server sends N, g, salt and B to client */
  20977. if (!r) r = wc_SrpGetPublic(cli, clientPubKey, &clientPubKeySz);
  20978. if (!r) r = wc_SrpComputeKey(cli, clientPubKey, clientPubKeySz,
  20979. serverPubKey, serverPubKeySz);
  20980. if (!r) r = wc_SrpGetProof(cli, clientProof, &clientProofSz);
  20981. /* client sends A and M1 to server */
  20982. if (!r) r = wc_SrpComputeKey(srv, clientPubKey, clientPubKeySz,
  20983. serverPubKey, serverPubKeySz);
  20984. if (!r) r = wc_SrpVerifyPeersProof(srv, clientProof, clientProofSz);
  20985. if (!r) r = wc_SrpGetProof(srv, serverProof, &serverProofSz);
  20986. /* server sends M2 to client */
  20987. if (!r) r = wc_SrpVerifyPeersProof(cli, serverProof, serverProofSz);
  20988. wc_SrpTerm(cli);
  20989. wc_SrpTerm(srv);
  20990. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20991. out:
  20992. XFREE(cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20993. XFREE(srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20994. XFREE(clientProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20995. XFREE(serverProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20996. #endif
  20997. return r;
  20998. }
  20999. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
  21000. {
  21001. wc_test_ret_t ret;
  21002. WOLFSSL_ENTER("srp_test");
  21003. #ifndef NO_SHA
  21004. ret = srp_test_digest(SRP_TYPE_SHA);
  21005. if (ret != 0)
  21006. return ret;
  21007. #endif
  21008. #ifndef NO_SHA256
  21009. ret = srp_test_digest(SRP_TYPE_SHA256);
  21010. if (ret != 0)
  21011. return ret;
  21012. #endif
  21013. #ifdef WOLFSSL_SHA384
  21014. ret = srp_test_digest(SRP_TYPE_SHA384);
  21015. if (ret != 0)
  21016. return ret;
  21017. #endif
  21018. #ifdef WOLFSSL_SHA512
  21019. ret = srp_test_digest(SRP_TYPE_SHA512);
  21020. if (ret != 0)
  21021. return ret;
  21022. #endif
  21023. return ret;
  21024. }
  21025. #endif /* WOLFCRYPT_HAVE_SRP */
  21026. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  21027. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  21028. static wc_test_ret_t openssl_aes_test(void)
  21029. {
  21030. #ifdef HAVE_AES_CBC
  21031. #ifdef WOLFSSL_AES_128
  21032. {
  21033. /* EVP_CipherUpdate test */
  21034. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21035. {
  21036. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21037. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21038. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21039. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21040. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21041. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21042. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21043. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21044. };
  21045. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21046. "0123456789abcdef "; /* align */
  21047. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21048. "1234567890abcdef "; /* align */
  21049. byte cipher[AES_BLOCK_SIZE * 4];
  21050. byte plain [AES_BLOCK_SIZE * 4];
  21051. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21052. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21053. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21054. #else
  21055. WOLFSSL_EVP_CIPHER_CTX en[1];
  21056. WOLFSSL_EVP_CIPHER_CTX de[1];
  21057. #endif
  21058. int outlen ;
  21059. int total = 0;
  21060. int i;
  21061. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21062. if ((en == NULL) || (de == NULL))
  21063. return MEMORY_E;
  21064. #endif
  21065. wolfSSL_EVP_CIPHER_CTX_init(en);
  21066. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21067. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21068. return WC_TEST_RET_ENC_NC;
  21069. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21070. (byte*)cbcPlain, 9) == 0)
  21071. return WC_TEST_RET_ENC_NC;
  21072. if (outlen != 0)
  21073. return WC_TEST_RET_ENC_NC;
  21074. total += outlen;
  21075. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21076. (byte*)&cbcPlain[9] , 9) == 0)
  21077. return WC_TEST_RET_ENC_NC;
  21078. if (outlen != 16)
  21079. return WC_TEST_RET_ENC_NC;
  21080. total += outlen;
  21081. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21082. return WC_TEST_RET_ENC_NC;
  21083. if (outlen != 16)
  21084. return WC_TEST_RET_ENC_NC;
  21085. total += outlen;
  21086. if (total != 32)
  21087. return 3408;
  21088. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21089. total = 0;
  21090. wolfSSL_EVP_CIPHER_CTX_init(de);
  21091. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21092. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21093. return WC_TEST_RET_ENC_NC;
  21094. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  21095. return WC_TEST_RET_ENC_NC;
  21096. if (outlen != 0)
  21097. return WC_TEST_RET_ENC_NC;
  21098. total += outlen;
  21099. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21100. (byte*)&cipher[6], 12) == 0)
  21101. return WC_TEST_RET_ENC_NC;
  21102. if (outlen != 0)
  21103. total += outlen;
  21104. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21105. (byte*)&cipher[6+12], 14) == 0)
  21106. return WC_TEST_RET_ENC_NC;
  21107. if (outlen != 16)
  21108. return WC_TEST_RET_ENC_NC;
  21109. total += outlen;
  21110. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21111. return WC_TEST_RET_ENC_NC;
  21112. if (outlen != 2)
  21113. return WC_TEST_RET_ENC_NC;
  21114. total += outlen;
  21115. if (total != 18)
  21116. return 3427;
  21117. if (XMEMCMP(plain, cbcPlain, 18))
  21118. return WC_TEST_RET_ENC_NC;
  21119. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21120. /* test with encrypting/decrypting more than 16 bytes at once */
  21121. total = 0;
  21122. wolfSSL_EVP_CIPHER_CTX_init(en);
  21123. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21124. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21125. return WC_TEST_RET_ENC_NC;
  21126. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21127. (byte*)cbcPlain, 17) == 0)
  21128. return WC_TEST_RET_ENC_NC;
  21129. if (outlen != 16)
  21130. return WC_TEST_RET_ENC_NC;
  21131. total += outlen;
  21132. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21133. (byte*)&cbcPlain[17] , 1) == 0)
  21134. return WC_TEST_RET_ENC_NC;
  21135. if (outlen != 0)
  21136. return WC_TEST_RET_ENC_NC;
  21137. total += outlen;
  21138. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21139. return WC_TEST_RET_ENC_NC;
  21140. if (outlen != 16)
  21141. return WC_TEST_RET_ENC_NC;
  21142. total += outlen;
  21143. if (total != 32)
  21144. return WC_TEST_RET_ENC_NC;
  21145. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21146. total = 0;
  21147. wolfSSL_EVP_CIPHER_CTX_init(de);
  21148. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21149. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21150. return WC_TEST_RET_ENC_NC;
  21151. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0)
  21152. return WC_TEST_RET_ENC_NC;
  21153. if (outlen != 16)
  21154. return WC_TEST_RET_ENC_NC;
  21155. total += outlen;
  21156. /* final call on non block size should fail */
  21157. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21158. return WC_TEST_RET_ENC_NC;
  21159. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21160. (byte*)&cipher[17], 1) == 0)
  21161. return WC_TEST_RET_ENC_NC;
  21162. if (outlen != 0)
  21163. total += outlen;
  21164. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21165. (byte*)&cipher[17+1], 14) == 0)
  21166. return WC_TEST_RET_ENC_NC;
  21167. if (outlen != 0)
  21168. return WC_TEST_RET_ENC_NC;
  21169. total += outlen;
  21170. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21171. return WC_TEST_RET_ENC_NC;
  21172. if (outlen != 2)
  21173. return WC_TEST_RET_ENC_NC;
  21174. total += outlen;
  21175. if (total != 18)
  21176. return WC_TEST_RET_ENC_NC;
  21177. if (XMEMCMP(plain, cbcPlain, 18))
  21178. return WC_TEST_RET_ENC_NC;
  21179. /* test byte by byte decrypt */
  21180. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21181. plain[i] = i;
  21182. }
  21183. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21184. total = 0;
  21185. wolfSSL_EVP_CIPHER_CTX_init(en);
  21186. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21187. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21188. return WC_TEST_RET_ENC_NC;
  21189. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21190. (byte*)plain, AES_BLOCK_SIZE * 3) == 0)
  21191. return WC_TEST_RET_ENC_NC;
  21192. if (outlen != AES_BLOCK_SIZE * 3)
  21193. return WC_TEST_RET_ENC_NC;
  21194. total += outlen;
  21195. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21196. return WC_TEST_RET_ENC_NC;
  21197. if (outlen != AES_BLOCK_SIZE)
  21198. return WC_TEST_RET_ENC_NC;
  21199. total += outlen;
  21200. if (total != sizeof(plain))
  21201. return WC_TEST_RET_ENC_NC;
  21202. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21203. total = 0;
  21204. wolfSSL_EVP_CIPHER_CTX_init(de);
  21205. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21206. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21207. return WC_TEST_RET_ENC_NC;
  21208. for (i = 0; i < AES_BLOCK_SIZE * 4; i++) {
  21209. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain + total, &outlen,
  21210. (byte*)cipher + i, 1) == 0)
  21211. return WC_TEST_RET_ENC_NC;
  21212. if (outlen > 0) {
  21213. int j;
  21214. total += outlen;
  21215. for (j = 0; j < total; j++) {
  21216. if (plain[j] != j) {
  21217. return WC_TEST_RET_ENC_NC;
  21218. }
  21219. }
  21220. }
  21221. }
  21222. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21223. return WC_TEST_RET_ENC_NC;
  21224. total += outlen;
  21225. if (total != AES_BLOCK_SIZE * 3) {
  21226. return WC_TEST_RET_ENC_NC;
  21227. }
  21228. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21229. if (plain[i] != i) {
  21230. return WC_TEST_RET_ENC_NC;
  21231. }
  21232. }
  21233. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21234. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21235. wolfSSL_EVP_CIPHER_CTX_free(en);
  21236. wolfSSL_EVP_CIPHER_CTX_free(de);
  21237. #endif
  21238. }
  21239. /* set buffers to be exact size to catch potential over read/write */
  21240. {
  21241. /* EVP_CipherUpdate test */
  21242. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21243. {
  21244. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21245. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21246. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21247. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21248. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21249. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21250. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21251. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21252. };
  21253. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21254. "0123456789abcdef "; /* align */
  21255. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21256. "1234567890abcdef "; /* align */
  21257. #define EVP_TEST_BUF_SZ 18
  21258. #define EVP_TEST_BUF_PAD 32
  21259. byte cipher[EVP_TEST_BUF_SZ];
  21260. byte plain [EVP_TEST_BUF_SZ];
  21261. byte padded[EVP_TEST_BUF_PAD];
  21262. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21263. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21264. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21265. #else
  21266. WOLFSSL_EVP_CIPHER_CTX en[1];
  21267. WOLFSSL_EVP_CIPHER_CTX de[1];
  21268. #endif
  21269. int outlen ;
  21270. int total = 0;
  21271. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21272. if ((en == NULL) || (de == NULL))
  21273. return MEMORY_E;
  21274. #endif
  21275. wolfSSL_EVP_CIPHER_CTX_init(en);
  21276. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21277. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21278. return WC_TEST_RET_ENC_NC;
  21279. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != 1)
  21280. return WC_TEST_RET_ENC_NC;
  21281. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21282. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21283. return WC_TEST_RET_ENC_NC;
  21284. if (outlen != 16)
  21285. return WC_TEST_RET_ENC_NC;
  21286. total += outlen;
  21287. /* should fail here */
  21288. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0)
  21289. return WC_TEST_RET_ENC_NC;
  21290. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21291. /* turn padding back on and do successful encrypt */
  21292. total = 0;
  21293. wolfSSL_EVP_CIPHER_CTX_init(en);
  21294. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21295. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21296. return WC_TEST_RET_ENC_NC;
  21297. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != 1)
  21298. return WC_TEST_RET_ENC_NC;
  21299. if (wolfSSL_EVP_CipherUpdate(en, (byte*)padded, &outlen,
  21300. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21301. return WC_TEST_RET_ENC_NC;
  21302. if (outlen != 16)
  21303. return WC_TEST_RET_ENC_NC;
  21304. total += outlen;
  21305. if (wolfSSL_EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0)
  21306. return WC_TEST_RET_ENC_NC;
  21307. total += outlen;
  21308. if (total != 32)
  21309. return WC_TEST_RET_ENC_NC;
  21310. XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ);
  21311. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21312. /* test out of bounds read on buffers w/o padding during decryption */
  21313. total = 0;
  21314. wolfSSL_EVP_CIPHER_CTX_init(de);
  21315. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21316. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21317. return WC_TEST_RET_ENC_NC;
  21318. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 0) != 1)
  21319. return WC_TEST_RET_ENC_NC;
  21320. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher,
  21321. EVP_TEST_BUF_SZ) == 0)
  21322. return WC_TEST_RET_ENC_NC;
  21323. if (outlen != 16)
  21324. return WC_TEST_RET_ENC_NC;
  21325. total += outlen;
  21326. /* should fail since not using padding */
  21327. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21328. return WC_TEST_RET_ENC_NC;
  21329. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21330. total = 0;
  21331. wolfSSL_EVP_CIPHER_CTX_init(de);
  21332. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21333. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21334. return WC_TEST_RET_ENC_NC;
  21335. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 1) != 1)
  21336. return WC_TEST_RET_ENC_NC;
  21337. if (wolfSSL_EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded,
  21338. EVP_TEST_BUF_PAD) == 0)
  21339. return WC_TEST_RET_ENC_NC;
  21340. if (outlen != 16)
  21341. return WC_TEST_RET_ENC_NC;
  21342. total += outlen;
  21343. if (wolfSSL_EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0)
  21344. return WC_TEST_RET_ENC_NC;
  21345. if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ))
  21346. return WC_TEST_RET_ENC_NC;
  21347. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21348. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21349. wolfSSL_EVP_CIPHER_CTX_free(en);
  21350. wolfSSL_EVP_CIPHER_CTX_free(de);
  21351. #endif
  21352. }
  21353. { /* evp_cipher test: EVP_aes_128_cbc */
  21354. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21355. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21356. #else
  21357. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21358. #endif
  21359. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  21360. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  21361. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  21362. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  21363. };
  21364. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21365. {
  21366. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  21367. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  21368. };
  21369. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21370. "0123456789abcdef "; /* align */
  21371. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21372. "1234567890abcdef "; /* align */
  21373. byte cipher[AES_BLOCK_SIZE * 4];
  21374. byte plain [AES_BLOCK_SIZE * 4];
  21375. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21376. if (ctx == NULL)
  21377. return MEMORY_E;
  21378. #endif
  21379. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21380. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1) == 0)
  21381. return WC_TEST_RET_ENC_NC;
  21382. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21383. return WC_TEST_RET_ENC_NC;
  21384. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21385. return WC_TEST_RET_ENC_NC;
  21386. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21387. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21388. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0) == 0)
  21389. return WC_TEST_RET_ENC_NC;
  21390. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21391. return WC_TEST_RET_ENC_NC;
  21392. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21393. return WC_TEST_RET_ENC_NC;
  21394. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21395. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21396. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21397. #endif
  21398. } /* end evp_cipher test: EVP_aes_128_cbc*/
  21399. #endif /* WOLFSSL_AES_128 */
  21400. #endif /* HAVE_AES_CBC */
  21401. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21402. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  21403. { /* evp_cipher test: EVP_aes_256_ecb*/
  21404. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21405. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21406. #else
  21407. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21408. #endif
  21409. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21410. {
  21411. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21412. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21413. };
  21414. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21415. {
  21416. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21417. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21418. };
  21419. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21420. {
  21421. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21422. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21423. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21424. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21425. };
  21426. byte cipher[AES_BLOCK_SIZE * 4];
  21427. byte plain [AES_BLOCK_SIZE * 4];
  21428. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21429. if (ctx == NULL)
  21430. return MEMORY_E;
  21431. #endif
  21432. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21433. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0)
  21434. return WC_TEST_RET_ENC_NC;
  21435. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21436. return WC_TEST_RET_ENC_NC;
  21437. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21438. return WC_TEST_RET_ENC_NC;
  21439. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21440. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0)
  21441. return WC_TEST_RET_ENC_NC;
  21442. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21443. return WC_TEST_RET_ENC_NC;
  21444. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21445. return WC_TEST_RET_ENC_NC;
  21446. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21447. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21448. #endif
  21449. } /* end evp_cipher test */
  21450. #endif /* HAVE_AES_ECB && WOLFSSL_AES_256 */
  21451. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  21452. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  21453. {
  21454. /* Test: AES_encrypt/decrypt/set Key */
  21455. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21456. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21457. #ifdef HAVE_AES_DECRYPT
  21458. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21459. #endif
  21460. #else
  21461. AES_KEY enc[1];
  21462. #ifdef HAVE_AES_DECRYPT
  21463. AES_KEY dec[1];
  21464. #endif
  21465. #endif
  21466. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21467. {
  21468. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21469. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21470. };
  21471. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21472. {
  21473. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21474. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21475. };
  21476. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21477. {
  21478. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21479. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21480. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21481. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21482. };
  21483. byte plain[sizeof(msg)];
  21484. byte cipher[sizeof(msg)];
  21485. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21486. if (enc == NULL)
  21487. return MEMORY_E;
  21488. #ifdef HAVE_AES_DECRYPT
  21489. if (dec == NULL)
  21490. return MEMORY_E;
  21491. #endif
  21492. #endif
  21493. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  21494. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  21495. AES_encrypt(msg, cipher, enc);
  21496. #ifdef HAVE_AES_DECRYPT
  21497. AES_decrypt(cipher, plain, dec);
  21498. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21499. return WC_TEST_RET_ENC_NC;
  21500. #endif /* HAVE_AES_DECRYPT */
  21501. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21502. return WC_TEST_RET_ENC_NC;
  21503. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21504. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21505. #ifdef HAVE_AES_DECRYPT
  21506. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21507. #endif
  21508. #endif
  21509. }
  21510. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  21511. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21512. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  21513. #ifdef WOLFSSL_AES_COUNTER
  21514. {
  21515. byte plainBuff [64];
  21516. byte cipherBuff[64];
  21517. #ifdef WOLFSSL_AES_128
  21518. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  21519. {
  21520. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21521. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21522. };
  21523. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  21524. {
  21525. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21526. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21527. };
  21528. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  21529. {
  21530. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21531. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21532. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21533. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21534. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21535. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21536. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21537. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21538. };
  21539. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  21540. {
  21541. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  21542. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  21543. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  21544. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  21545. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  21546. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  21547. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  21548. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  21549. };
  21550. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  21551. {
  21552. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  21553. 0xc2
  21554. };
  21555. #endif
  21556. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21557. * NIST Special Publication 800-38A */
  21558. #ifdef WOLFSSL_AES_192
  21559. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  21560. {
  21561. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  21562. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  21563. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  21564. };
  21565. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  21566. {
  21567. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21568. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21569. };
  21570. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  21571. {
  21572. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21573. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21574. };
  21575. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  21576. {
  21577. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  21578. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  21579. };
  21580. #endif /* WOLFSSL_AES_192 */
  21581. #ifdef WOLFSSL_AES_256
  21582. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21583. * NIST Special Publication 800-38A */
  21584. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  21585. {
  21586. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21587. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21588. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21589. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21590. };
  21591. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  21592. {
  21593. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21594. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21595. };
  21596. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  21597. {
  21598. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21599. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21600. };
  21601. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  21602. {
  21603. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  21604. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  21605. };
  21606. #endif /* WOLFSSL_AES_256 */
  21607. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21608. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21609. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21610. #else
  21611. WOLFSSL_EVP_CIPHER_CTX en[1];
  21612. WOLFSSL_EVP_CIPHER_CTX de[1];
  21613. #endif
  21614. #ifdef WOLFSSL_AES_128
  21615. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21616. WOLFSSL_EVP_CIPHER_CTX *p_en;
  21617. WOLFSSL_EVP_CIPHER_CTX *p_de;
  21618. #endif
  21619. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21620. if ((en == NULL) || (de == NULL))
  21621. return MEMORY_E;
  21622. #endif
  21623. wolfSSL_EVP_CIPHER_CTX_init(en);
  21624. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21625. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21626. return WC_TEST_RET_ENC_NC;
  21627. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  21628. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21629. return WC_TEST_RET_ENC_NC;
  21630. wolfSSL_EVP_CIPHER_CTX_init(de);
  21631. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21632. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21633. return WC_TEST_RET_ENC_NC;
  21634. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21635. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21636. return WC_TEST_RET_ENC_NC;
  21637. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21638. return WC_TEST_RET_ENC_NC;
  21639. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21640. return WC_TEST_RET_ENC_NC;
  21641. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21642. return WC_TEST_RET_ENC_NC;
  21643. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21644. return WC_TEST_RET_ENC_NC;
  21645. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21646. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  21647. if (p_en == NULL)
  21648. return WC_TEST_RET_ENC_ERRNO;
  21649. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  21650. if (p_de == NULL)
  21651. return WC_TEST_RET_ENC_ERRNO;
  21652. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  21653. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21654. return WC_TEST_RET_ENC_NC;
  21655. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  21656. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21657. return WC_TEST_RET_ENC_NC;
  21658. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  21659. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21660. return WC_TEST_RET_ENC_NC;
  21661. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  21662. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21663. return WC_TEST_RET_ENC_NC;
  21664. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21665. return WC_TEST_RET_ENC_NC;
  21666. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21667. return WC_TEST_RET_ENC_NC;
  21668. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  21669. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  21670. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  21671. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21672. return WC_TEST_RET_ENC_NC;
  21673. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21674. return WC_TEST_RET_ENC_NC;
  21675. wolfSSL_EVP_CIPHER_CTX_init(en);
  21676. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21677. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21678. return WC_TEST_RET_ENC_NC;
  21679. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21680. return WC_TEST_RET_ENC_NC;
  21681. wolfSSL_EVP_CIPHER_CTX_init(de);
  21682. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21683. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21684. return WC_TEST_RET_ENC_NC;
  21685. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21686. return WC_TEST_RET_ENC_NC;
  21687. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21688. return WC_TEST_RET_ENC_NC;
  21689. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  21690. return WC_TEST_RET_ENC_NC;
  21691. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21692. return WC_TEST_RET_ENC_NC;
  21693. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21694. return WC_TEST_RET_ENC_NC;
  21695. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21696. return WC_TEST_RET_ENC_NC;
  21697. if (XMEMCMP(cipherBuff, oddCipher, 9))
  21698. return WC_TEST_RET_ENC_NC;
  21699. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21700. return WC_TEST_RET_ENC_NC;
  21701. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21702. return WC_TEST_RET_ENC_NC;
  21703. #endif /* WOLFSSL_AES_128 */
  21704. #ifdef WOLFSSL_AES_192
  21705. wolfSSL_EVP_CIPHER_CTX_init(en);
  21706. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  21707. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21708. return WC_TEST_RET_ENC_NC;
  21709. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  21710. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21711. return WC_TEST_RET_ENC_NC;
  21712. wolfSSL_EVP_CIPHER_CTX_init(de);
  21713. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  21714. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21715. return WC_TEST_RET_ENC_NC;
  21716. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21717. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21718. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21719. return WC_TEST_RET_ENC_NC;
  21720. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  21721. return WC_TEST_RET_ENC_NC;
  21722. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  21723. return WC_TEST_RET_ENC_NC;
  21724. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21725. return WC_TEST_RET_ENC_NC;
  21726. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21727. return WC_TEST_RET_ENC_NC;
  21728. #endif /* WOLFSSL_AES_192 */
  21729. #ifdef WOLFSSL_AES_256
  21730. wolfSSL_EVP_CIPHER_CTX_init(en);
  21731. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  21732. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21733. return WC_TEST_RET_ENC_NC;
  21734. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  21735. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21736. return WC_TEST_RET_ENC_NC;
  21737. wolfSSL_EVP_CIPHER_CTX_init(de);
  21738. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  21739. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21740. return WC_TEST_RET_ENC_NC;
  21741. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21742. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21743. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21744. return WC_TEST_RET_ENC_NC;
  21745. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  21746. return WC_TEST_RET_ENC_NC;
  21747. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  21748. return WC_TEST_RET_ENC_NC;
  21749. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21750. return WC_TEST_RET_ENC_NC;
  21751. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21752. return WC_TEST_RET_ENC_NC;
  21753. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21754. wolfSSL_EVP_CIPHER_CTX_free(en);
  21755. wolfSSL_EVP_CIPHER_CTX_free(de);
  21756. #endif
  21757. #endif /* WOLFSSL_AES_256 */
  21758. }
  21759. #endif /* HAVE_AES_COUNTER */
  21760. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21761. #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128)
  21762. {
  21763. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21764. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21765. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21766. #else
  21767. AES_KEY enc[1];
  21768. AES_KEY dec[1];
  21769. #endif
  21770. WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = {
  21771. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  21772. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  21773. };
  21774. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21775. {
  21776. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21777. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21778. };
  21779. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  21780. {
  21781. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  21782. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  21783. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  21784. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b
  21785. };
  21786. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21787. {
  21788. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21789. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21790. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21791. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51
  21792. };
  21793. byte cipher[AES_BLOCK_SIZE * 2];
  21794. byte iv[AES_BLOCK_SIZE]; /* iv buffer is updeated by API */
  21795. int num = 0;
  21796. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21797. if ((enc == NULL) || (dec == NULL))
  21798. return MEMORY_E;
  21799. #endif
  21800. XMEMCPY(iv, setIv, sizeof(setIv));
  21801. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc);
  21802. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec);
  21803. wolfSSL_AES_cfb128_encrypt(msg, cipher, AES_BLOCK_SIZE - 1, enc, iv,
  21804. &num, AES_ENCRYPT);
  21805. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE - 1))
  21806. return WC_TEST_RET_ENC_NC;
  21807. if (num != 15) /* should have used 15 of the 16 bytes */
  21808. return WC_TEST_RET_ENC_NC;
  21809. wolfSSL_AES_cfb128_encrypt(msg + AES_BLOCK_SIZE - 1,
  21810. cipher + AES_BLOCK_SIZE - 1, AES_BLOCK_SIZE + 1, enc, iv,
  21811. &num, AES_ENCRYPT);
  21812. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  21813. return WC_TEST_RET_ENC_NC;
  21814. if (num != 0)
  21815. return WC_TEST_RET_ENC_NC;
  21816. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21817. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21818. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21819. #endif
  21820. }
  21821. #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */
  21822. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21823. return 0;
  21824. }
  21825. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  21826. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void)
  21827. {
  21828. wc_test_ret_t ret;
  21829. #ifdef WOLFSSL_SMALL_STACK
  21830. WOLFSSL_EVP_MD_CTX *md_ctx = (WOLFSSL_EVP_MD_CTX *)XMALLOC(sizeof(WOLFSSL_EVP_MD_CTX), NULL, DYNAMIC_TYPE_OPENSSL);
  21831. #else
  21832. WOLFSSL_EVP_MD_CTX md_ctx[1];
  21833. #endif
  21834. testVector a, b, c, d, e, f;
  21835. byte hash[WC_SHA256_DIGEST_SIZE*2]; /* max size */
  21836. #ifdef WOLFSSL_SMALL_STACK
  21837. if (md_ctx == NULL)
  21838. return WC_TEST_RET_ENC_EC(MEMORY_E);
  21839. #endif
  21840. WOLFSSL_ENTER("openssl_test");
  21841. a.inLen = 0;
  21842. b.inLen = c.inLen = d.inLen = e.inLen = f.inLen = a.inLen;
  21843. (void)a;
  21844. (void)b;
  21845. (void)c;
  21846. (void)d;
  21847. (void)e;
  21848. (void)f;
  21849. /* test malloc / free , 10 is an arbitrary amount of memory chosen */
  21850. {
  21851. byte* p;
  21852. p = (byte*)wolfSSL_CRYPTO_malloc(10, "", 0);
  21853. if (p == NULL) {
  21854. return WC_TEST_RET_ENC_NC;
  21855. }
  21856. XMEMSET(p, 0, 10);
  21857. wolfSSL_CRYPTO_free(p, "", 0);
  21858. }
  21859. #ifndef NO_MD5
  21860. a.input = "1234567890123456789012345678901234567890123456789012345678"
  21861. "9012345678901234567890";
  21862. a.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  21863. "\x7a";
  21864. a.inLen = XSTRLEN(a.input);
  21865. a.outLen = WC_MD5_DIGEST_SIZE;
  21866. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21867. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_md5());
  21868. if (ret == WOLFSSL_SUCCESS) {
  21869. ret = wolfSSL_EVP_DigestUpdate(md_ctx, a.input, (unsigned long)a.inLen);
  21870. }
  21871. if (ret == WOLFSSL_SUCCESS) {
  21872. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21873. }
  21874. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21875. if (ret != WOLFSSL_SUCCESS)
  21876. return WC_TEST_RET_ENC_NC;
  21877. if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0)
  21878. return WC_TEST_RET_ENC_NC;
  21879. #endif /* NO_MD5 */
  21880. #ifndef NO_SHA
  21881. b.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21882. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21883. "aaaaaaaaaa";
  21884. b.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  21885. "\x53\x99\x5E\x26\xA0";
  21886. b.inLen = XSTRLEN(b.input);
  21887. b.outLen = WC_SHA_DIGEST_SIZE;
  21888. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21889. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha1());
  21890. if (ret == WOLFSSL_SUCCESS) {
  21891. ret = wolfSSL_EVP_DigestUpdate(md_ctx, b.input, (unsigned long)b.inLen);
  21892. if (ret == WOLFSSL_SUCCESS)
  21893. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21894. }
  21895. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21896. if (ret != WOLFSSL_SUCCESS)
  21897. return WC_TEST_RET_ENC_NC;
  21898. if (XMEMCMP(hash, b.output, b.outLen) != 0)
  21899. return WC_TEST_RET_ENC_NC;
  21900. #endif /* NO_SHA */
  21901. #ifdef WOLFSSL_SHA224
  21902. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21903. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21904. e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
  21905. "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
  21906. e.inLen = XSTRLEN(e.input);
  21907. e.outLen = WC_SHA224_DIGEST_SIZE;
  21908. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21909. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha224());
  21910. if (ret == WOLFSSL_SUCCESS) {
  21911. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21912. if (ret == WOLFSSL_SUCCESS)
  21913. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21914. }
  21915. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21916. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21917. return WC_TEST_RET_ENC_NC;
  21918. }
  21919. #endif /* WOLFSSL_SHA224 */
  21920. #ifndef NO_SHA256
  21921. d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  21922. d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  21923. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  21924. "\x06\xC1";
  21925. d.inLen = XSTRLEN(d.input);
  21926. d.outLen = WC_SHA256_DIGEST_SIZE;
  21927. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21928. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha256());
  21929. if (ret == WOLFSSL_SUCCESS) {
  21930. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21931. if (ret == WOLFSSL_SUCCESS)
  21932. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21933. }
  21934. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21935. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21936. return WC_TEST_RET_ENC_NC;
  21937. }
  21938. #endif /* !NO_SHA256 */
  21939. #ifdef WOLFSSL_SHA384
  21940. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21941. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21942. e.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  21943. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  21944. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  21945. "\x74\x60\x39";
  21946. e.inLen = XSTRLEN(e.input);
  21947. e.outLen = WC_SHA384_DIGEST_SIZE;
  21948. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21949. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha384());
  21950. if (ret == WOLFSSL_SUCCESS) {
  21951. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21952. if (ret == WOLFSSL_SUCCESS)
  21953. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21954. }
  21955. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21956. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21957. return WC_TEST_RET_ENC_NC;
  21958. }
  21959. #endif /* WOLFSSL_SHA384 */
  21960. #ifdef WOLFSSL_SHA512
  21961. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21962. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21963. f.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  21964. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  21965. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  21966. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  21967. "\x87\x4b\xe9\x09";
  21968. f.inLen = XSTRLEN(f.input);
  21969. f.outLen = WC_SHA512_DIGEST_SIZE;
  21970. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21971. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512());
  21972. if (ret == WOLFSSL_SUCCESS) {
  21973. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21974. if (ret == WOLFSSL_SUCCESS)
  21975. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21976. }
  21977. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21978. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21979. return WC_TEST_RET_ENC_NC;
  21980. }
  21981. #if !defined(WOLFSSL_NOSHA512_224) && \
  21982. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21983. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21984. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21985. f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45"
  21986. "\x33\x35\xd6\x64\x73\x4f\xe4\x0e\x72\x68\x67\x4a\xf9";
  21987. f.inLen = XSTRLEN(f.input);
  21988. f.outLen = WC_SHA512_224_DIGEST_SIZE;
  21989. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21990. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_224());
  21991. if (ret == WOLFSSL_SUCCESS) {
  21992. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21993. if (ret == WOLFSSL_SUCCESS)
  21994. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21995. }
  21996. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21997. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21998. return WC_TEST_RET_ENC_NC;
  21999. }
  22000. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  22001. #if !defined(WOLFSSL_NOSHA512_256) && \
  22002. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  22003. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22004. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22005. f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31"
  22006. "\xbe\x65\xcb\x9d\x3e\xf8\x3e\xe6\x14\x6f\xea\xc8\x61\xe1\x9b"
  22007. "\x56\x3a";
  22008. f.inLen = XSTRLEN(f.input);
  22009. f.outLen = WC_SHA512_256_DIGEST_SIZE;
  22010. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22011. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_256());
  22012. if (ret == WOLFSSL_SUCCESS) {
  22013. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22014. if (ret == WOLFSSL_SUCCESS)
  22015. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22016. }
  22017. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22018. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  22019. return WC_TEST_RET_ENC_NC;
  22020. }
  22021. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  22022. #endif /* WOLFSSL_SHA512 */
  22023. #ifdef WOLFSSL_SHA3
  22024. #ifndef WOLFSSL_NOSHA3_224
  22025. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22026. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22027. e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a"
  22028. "\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
  22029. e.inLen = XSTRLEN(e.input);
  22030. e.outLen = WC_SHA3_224_DIGEST_SIZE;
  22031. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22032. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_224());
  22033. if (ret == WOLFSSL_SUCCESS) {
  22034. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22035. if (ret == WOLFSSL_SUCCESS)
  22036. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22037. }
  22038. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22039. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22040. return WC_TEST_RET_ENC_NC;
  22041. }
  22042. #endif /* WOLFSSL_NOSHA3_224 */
  22043. #ifndef WOLFSSL_NOSHA3_256
  22044. d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22045. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22046. d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
  22047. "\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
  22048. "\x1d\x18";
  22049. d.inLen = XSTRLEN(d.input);
  22050. d.outLen = WC_SHA3_256_DIGEST_SIZE;
  22051. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22052. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_256());
  22053. if (ret == WOLFSSL_SUCCESS) {
  22054. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  22055. if (ret == WOLFSSL_SUCCESS)
  22056. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22057. }
  22058. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22059. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  22060. return WC_TEST_RET_ENC_NC;
  22061. }
  22062. #endif /* WOLFSSL_NOSHA3_256 */
  22063. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22064. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22065. e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47"
  22066. "\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6"
  22067. "\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79"
  22068. "\xaa\x7f\xc7";
  22069. e.inLen = XSTRLEN(e.input);
  22070. e.outLen = WC_SHA3_384_DIGEST_SIZE;
  22071. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22072. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_384());
  22073. if (ret == WOLFSSL_SUCCESS) {
  22074. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22075. if (ret == WOLFSSL_SUCCESS)
  22076. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22077. }
  22078. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22079. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22080. return WC_TEST_RET_ENC_NC;
  22081. }
  22082. #ifndef WOLFSSL_NOSHA3_512
  22083. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22084. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22085. f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78"
  22086. "\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18"
  22087. "\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8"
  22088. "\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55"
  22089. "\xf2\x1d\xd1\x85";
  22090. f.inLen = XSTRLEN(f.input);
  22091. f.outLen = WC_SHA3_512_DIGEST_SIZE;
  22092. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22093. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_512());
  22094. if (ret == WOLFSSL_SUCCESS) {
  22095. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22096. if (ret == WOLFSSL_SUCCESS)
  22097. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22098. }
  22099. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22100. if (ret != WOLFSSL_SUCCESS ||
  22101. XMEMCMP(hash, f.output, f.outLen) != 0) {
  22102. return WC_TEST_RET_ENC_NC;
  22103. }
  22104. #endif /* WOLFSSL_NOSHA3_512 */
  22105. #endif /* WOLFSSL_SHA3 */
  22106. #ifdef WOLFSSL_SMALL_STACK
  22107. XFREE(md_ctx, NULL, DYNAMIC_TYPE_OPENSSL);
  22108. md_ctx = NULL;
  22109. #endif
  22110. #ifndef WC_NO_RNG
  22111. if (wolfSSL_RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS)
  22112. return WC_TEST_RET_ENC_NC;
  22113. #endif
  22114. #ifndef NO_MD5
  22115. c.input = "what do ya want for nothing?";
  22116. c.output = "\x55\x78\xe8\x48\x4b\xcc\x93\x80\x93\xec\x53\xaf\x22\xd6\x14"
  22117. "\x76";
  22118. c.inLen = XSTRLEN(c.input);
  22119. c.outLen = WC_MD5_DIGEST_SIZE;
  22120. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)
  22121. /* Expect failure with MD5 + HMAC when using FIPS 140-3. */
  22122. if (HMAC(EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22123. hash, 0) != NULL)
  22124. #else
  22125. if (wolfSSL_HMAC(wolfSSL_EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22126. hash, 0) == NULL ||
  22127. XMEMCMP(hash, c.output, c.outLen) != 0)
  22128. #endif
  22129. {
  22130. return WC_TEST_RET_ENC_NC;
  22131. }
  22132. #endif /* NO_MD5 */
  22133. #ifndef NO_DES3
  22134. { /* des test */
  22135. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  22136. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22137. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22138. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22139. };
  22140. byte plain[24];
  22141. byte cipher[24];
  22142. const_DES_cblock key = {
  22143. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  22144. };
  22145. DES_cblock iv = {
  22146. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  22147. };
  22148. DES_key_schedule sched;
  22149. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22150. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  22151. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  22152. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  22153. };
  22154. DES_key_sched(&key, &sched);
  22155. DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, DES_ENCRYPT);
  22156. DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, DES_DECRYPT);
  22157. if (XMEMCMP(plain, vector, sizeof(vector)) != 0)
  22158. return WC_TEST_RET_ENC_NC;
  22159. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22160. return WC_TEST_RET_ENC_NC;
  22161. /* test changing iv */
  22162. DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, DES_ENCRYPT);
  22163. DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, DES_ENCRYPT);
  22164. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22165. return WC_TEST_RET_ENC_NC;
  22166. } /* end des test */
  22167. #endif /* NO_DES3 */
  22168. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  22169. if ((ret = openssl_aes_test()) != 0) {
  22170. return ret;
  22171. }
  22172. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  22173. { /* evp_cipher test: EVP_aes_128_cbc */
  22174. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22175. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22176. #else
  22177. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22178. #endif
  22179. int idx, cipherSz, plainSz;
  22180. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  22181. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22182. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22183. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22184. };
  22185. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22186. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22187. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22188. 0x3b,0x5d,0x41,0x97,0x94,0x25,0xa4,0xb4,
  22189. 0xae,0x7b,0x34,0xd0,0x3f,0x0c,0xbc,0x06
  22190. };
  22191. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  22192. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22193. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22194. 0x7d,0x37,0x7b,0x0b,0x44,0xaa,0xb5,0xf0,
  22195. 0x5f,0x34,0xb4,0xde,0xb5,0xbd,0x2a,0xbb
  22196. };
  22197. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22198. "0123456789abcdef "; /* align */
  22199. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  22200. "1234567890abcdef "; /* align */
  22201. byte cipher[AES_BLOCK_SIZE * 4];
  22202. byte plain [AES_BLOCK_SIZE * 4];
  22203. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22204. if (ctx == NULL)
  22205. return MEMORY_E;
  22206. #endif
  22207. cipherSz = 0;
  22208. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22209. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22210. if (ret == WOLFSSL_SUCCESS) {
  22211. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, (byte*)msg, sizeof(msg));
  22212. if (ret == WOLFSSL_SUCCESS)
  22213. cipherSz += idx;
  22214. }
  22215. if (ret == WOLFSSL_SUCCESS) {
  22216. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22217. if (ret == WOLFSSL_SUCCESS)
  22218. cipherSz += idx;
  22219. }
  22220. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22221. if (ret != WOLFSSL_SUCCESS)
  22222. return WC_TEST_RET_ENC_NC;
  22223. if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz))
  22224. return WC_TEST_RET_ENC_NC;
  22225. /* check partial decrypt (not enough padding for full block) */
  22226. plainSz = 0;
  22227. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22228. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22229. if (ret == WOLFSSL_SUCCESS) {
  22230. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, 1);
  22231. if (ret == WOLFSSL_SUCCESS)
  22232. plainSz += idx;
  22233. }
  22234. if (ret == WOLFSSL_SUCCESS) {
  22235. /* this test should fail... not enough padding for full block */
  22236. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22237. if (plainSz == 0 && ret != WOLFSSL_SUCCESS)
  22238. ret = WOLFSSL_SUCCESS;
  22239. else
  22240. ret = WC_TEST_RET_ENC_NC;
  22241. }
  22242. else
  22243. ret = WC_TEST_RET_ENC_NC;
  22244. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22245. if (ret != WOLFSSL_SUCCESS)
  22246. return ret;
  22247. plainSz = 0;
  22248. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22249. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22250. if (ret == WOLFSSL_SUCCESS) {
  22251. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, cipherSz);
  22252. if (ret == WOLFSSL_SUCCESS)
  22253. plainSz += idx;
  22254. }
  22255. if (ret == WOLFSSL_SUCCESS) {
  22256. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22257. if (ret == WOLFSSL_SUCCESS)
  22258. plainSz += idx;
  22259. }
  22260. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22261. if (ret != WOLFSSL_SUCCESS)
  22262. return WC_TEST_RET_ENC_NC;
  22263. if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg)))
  22264. return WC_TEST_RET_ENC_NC;
  22265. cipherSz = 0;
  22266. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22267. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22268. if (ret == WOLFSSL_SUCCESS) {
  22269. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, msg, AES_BLOCK_SIZE);
  22270. if (ret == WOLFSSL_SUCCESS)
  22271. cipherSz += idx;
  22272. }
  22273. if (ret == WOLFSSL_SUCCESS) {
  22274. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22275. if (ret == WOLFSSL_SUCCESS)
  22276. cipherSz += idx;
  22277. }
  22278. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22279. if (ret != WOLFSSL_SUCCESS)
  22280. return WC_TEST_RET_ENC_NC;
  22281. if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz))
  22282. return WC_TEST_RET_ENC_NC;
  22283. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22284. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22285. #endif
  22286. } /* end evp_cipher test: EVP_aes_128_cbc*/
  22287. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22288. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  22289. { /* evp_cipher test: EVP_aes_256_ecb*/
  22290. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22291. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22292. #else
  22293. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22294. #endif
  22295. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  22296. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22297. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22298. };
  22299. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22300. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22301. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22302. };
  22303. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  22304. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22305. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22306. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22307. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22308. };
  22309. byte cipher[AES_BLOCK_SIZE * 4];
  22310. byte plain [AES_BLOCK_SIZE * 4];
  22311. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22312. if (ctx == NULL)
  22313. return MEMORY_E;
  22314. #endif
  22315. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22316. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1);
  22317. if (ret == WOLFSSL_SUCCESS)
  22318. ret = wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16);
  22319. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22320. if (ret != 16)
  22321. return WC_TEST_RET_ENC_NC;
  22322. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22323. return WC_TEST_RET_ENC_NC;
  22324. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22325. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0);
  22326. if (ret == WOLFSSL_SUCCESS)
  22327. ret = wolfSSL_EVP_Cipher(ctx, plain, cipher, 16);
  22328. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22329. if (ret != 16)
  22330. return WC_TEST_RET_ENC_NC;
  22331. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22332. return WC_TEST_RET_ENC_NC;
  22333. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22334. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22335. #endif
  22336. } /* end evp_cipher test */
  22337. #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */
  22338. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  22339. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  22340. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  22341. {
  22342. /* Test: AES_encrypt/decrypt/set Key */
  22343. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22344. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22345. #ifdef HAVE_AES_DECRYPT
  22346. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22347. #endif
  22348. #else
  22349. AES_KEY enc[1];
  22350. #ifdef HAVE_AES_DECRYPT
  22351. AES_KEY dec[1];
  22352. #endif
  22353. #endif
  22354. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  22355. {
  22356. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22357. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22358. };
  22359. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  22360. {
  22361. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22362. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22363. };
  22364. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22365. {
  22366. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22367. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22368. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22369. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22370. };
  22371. byte plain[sizeof(msg)];
  22372. byte cipher[sizeof(msg)];
  22373. printf("openSSL extra test\n") ;
  22374. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22375. if (enc == NULL)
  22376. return MEMORY_E;
  22377. #ifdef HAVE_AES_DECRYPT
  22378. if (dec == NULL)
  22379. return MEMORY_E;
  22380. #endif
  22381. #endif
  22382. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  22383. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  22384. AES_encrypt(msg, cipher, enc);
  22385. #ifdef HAVE_AES_DECRYPT
  22386. AES_decrypt(cipher, plain, dec);
  22387. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22388. return WC_TEST_RET_ENC_NC;
  22389. #endif /* HAVE_AES_DECRYPT */
  22390. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22391. return WC_TEST_RET_ENC_NC;
  22392. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22393. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22394. #ifdef HAVE_AES_DECRYPT
  22395. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22396. #endif
  22397. #endif
  22398. }
  22399. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  22400. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  22401. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  22402. #ifdef WOLFSSL_AES_COUNTER
  22403. {
  22404. byte plainBuff [64];
  22405. byte cipherBuff[64];
  22406. #ifdef WOLFSSL_AES_128
  22407. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  22408. {
  22409. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  22410. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  22411. };
  22412. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  22413. {
  22414. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22415. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22416. };
  22417. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  22418. {
  22419. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22420. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22421. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22422. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22423. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22424. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22425. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22426. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22427. };
  22428. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  22429. {
  22430. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  22431. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  22432. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  22433. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  22434. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  22435. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  22436. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  22437. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  22438. };
  22439. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  22440. {
  22441. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  22442. 0xc2
  22443. };
  22444. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22445. WOLFSSL_EVP_CIPHER_CTX *p_en;
  22446. WOLFSSL_EVP_CIPHER_CTX *p_de;
  22447. #endif
  22448. #endif /* WOLFSSL_AES_128 */
  22449. #ifdef WOLFSSL_AES_192
  22450. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22451. * NIST Special Publication 800-38A */
  22452. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  22453. {
  22454. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  22455. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  22456. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  22457. };
  22458. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  22459. {
  22460. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22461. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22462. };
  22463. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  22464. {
  22465. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22466. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22467. };
  22468. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  22469. {
  22470. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  22471. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  22472. };
  22473. #endif /* WOLFSSL_AES_192 */
  22474. #ifdef WOLFSSL_AES_256
  22475. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22476. * NIST Special Publication 800-38A */
  22477. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  22478. {
  22479. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22480. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22481. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22482. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22483. };
  22484. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  22485. {
  22486. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22487. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22488. };
  22489. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  22490. {
  22491. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22492. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22493. };
  22494. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  22495. {
  22496. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  22497. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  22498. };
  22499. #endif /* WOLFSSL_AES_256 */
  22500. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22501. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22502. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22503. if ((en == NULL) || (de == NULL))
  22504. return MEMORY_E;
  22505. #else
  22506. WOLFSSL_EVP_CIPHER_CTX en[1];
  22507. WOLFSSL_EVP_CIPHER_CTX de[1];
  22508. #endif
  22509. #ifdef WOLFSSL_AES_128
  22510. wolfSSL_EVP_CIPHER_CTX_init(en);
  22511. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22512. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22513. return WC_TEST_RET_ENC_NC;
  22514. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  22515. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22516. return WC_TEST_RET_ENC_NC;
  22517. wolfSSL_EVP_CIPHER_CTX_init(de);
  22518. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22519. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22520. return WC_TEST_RET_ENC_NC;
  22521. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22522. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22523. return WC_TEST_RET_ENC_NC;
  22524. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22525. return WC_TEST_RET_ENC_NC;
  22526. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22527. return WC_TEST_RET_ENC_NC;
  22528. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22529. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22530. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22531. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  22532. if (p_en == NULL)
  22533. return WC_TEST_RET_ENC_ERRNO;
  22534. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  22535. if (p_de == NULL)
  22536. return WC_TEST_RET_ENC_ERRNO;
  22537. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  22538. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22539. return WC_TEST_RET_ENC_NC;
  22540. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  22541. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22542. return WC_TEST_RET_ENC_NC;
  22543. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  22544. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22545. return WC_TEST_RET_ENC_NC;
  22546. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  22547. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22548. return WC_TEST_RET_ENC_NC;
  22549. wolfSSL_EVP_CIPHER_CTX_cleanup(p_en);
  22550. wolfSSL_EVP_CIPHER_CTX_cleanup(p_de);
  22551. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  22552. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  22553. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  22554. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22555. return WC_TEST_RET_ENC_NC;
  22556. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22557. return WC_TEST_RET_ENC_NC;
  22558. wolfSSL_EVP_CIPHER_CTX_init(en);
  22559. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22560. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22561. return WC_TEST_RET_ENC_NC;
  22562. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22563. return WC_TEST_RET_ENC_NC;
  22564. wolfSSL_EVP_CIPHER_CTX_init(de);
  22565. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22566. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22567. return WC_TEST_RET_ENC_NC;
  22568. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22569. return WC_TEST_RET_ENC_NC;
  22570. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22571. return WC_TEST_RET_ENC_NC;
  22572. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  22573. return WC_TEST_RET_ENC_NC;
  22574. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22575. return WC_TEST_RET_ENC_NC;
  22576. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22577. return WC_TEST_RET_ENC_NC;
  22578. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22579. return WC_TEST_RET_ENC_NC;
  22580. if (XMEMCMP(cipherBuff, oddCipher, 9))
  22581. return WC_TEST_RET_ENC_NC;
  22582. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22583. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22584. #endif /* WOLFSSL_AES_128 */
  22585. #ifdef WOLFSSL_AES_192
  22586. wolfSSL_EVP_CIPHER_CTX_init(en);
  22587. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  22588. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22589. return WC_TEST_RET_ENC_NC;
  22590. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  22591. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22592. return WC_TEST_RET_ENC_NC;
  22593. wolfSSL_EVP_CIPHER_CTX_init(de);
  22594. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  22595. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22596. return WC_TEST_RET_ENC_NC;
  22597. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22598. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22599. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22600. return WC_TEST_RET_ENC_NC;
  22601. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  22602. return WC_TEST_RET_ENC_NC;
  22603. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  22604. return WC_TEST_RET_ENC_NC;
  22605. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22606. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22607. #endif /* WOLFSSL_AES_192 */
  22608. #ifdef WOLFSSL_AES_256
  22609. wolfSSL_EVP_CIPHER_CTX_init(en);
  22610. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  22611. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22612. return WC_TEST_RET_ENC_NC;
  22613. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  22614. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22615. return WC_TEST_RET_ENC_NC;
  22616. wolfSSL_EVP_CIPHER_CTX_init(de);
  22617. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  22618. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22619. return WC_TEST_RET_ENC_NC;
  22620. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22621. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22622. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22623. return WC_TEST_RET_ENC_NC;
  22624. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  22625. return WC_TEST_RET_ENC_NC;
  22626. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  22627. return WC_TEST_RET_ENC_NC;
  22628. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22629. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22630. #endif /* WOLFSSL_AES_256 */
  22631. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22632. wolfSSL_EVP_CIPHER_CTX_free(en);
  22633. wolfSSL_EVP_CIPHER_CTX_free(de);
  22634. #endif
  22635. }
  22636. #endif /* HAVE_AES_COUNTER */
  22637. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22638. {
  22639. /* EVP_CipherUpdate test */
  22640. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  22641. {
  22642. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22643. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22644. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22645. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22646. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22647. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22648. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22649. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22650. };
  22651. byte key[] = "0123456789abcdef "; /* align */
  22652. byte iv[] = "1234567890abcdef "; /* align */
  22653. byte cipher[AES_BLOCK_SIZE * 4];
  22654. byte plain [AES_BLOCK_SIZE * 4];
  22655. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22656. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22657. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22658. #else
  22659. WOLFSSL_EVP_CIPHER_CTX en[1];
  22660. WOLFSSL_EVP_CIPHER_CTX de[1];
  22661. #endif
  22662. int outlen ;
  22663. int total = 0;
  22664. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22665. if ((en == NULL) || (de == NULL))
  22666. return MEMORY_E;
  22667. #endif
  22668. wolfSSL_EVP_CIPHER_CTX_init(en);
  22669. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22670. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22671. return WC_TEST_RET_ENC_NC;
  22672. /* openSSL compatibility, if(inlen == 0)return 1; */
  22673. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22674. (byte*)cbcPlain, 0) != 1)
  22675. return WC_TEST_RET_ENC_NC;
  22676. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22677. return WC_TEST_RET_ENC_NC;
  22678. wolfSSL_EVP_CIPHER_CTX_init(en);
  22679. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22680. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22681. return WC_TEST_RET_ENC_NC;
  22682. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22683. (byte*)cbcPlain, 9) == 0)
  22684. return WC_TEST_RET_ENC_NC;
  22685. if(outlen != 0)
  22686. return WC_TEST_RET_ENC_NC;
  22687. total += outlen;
  22688. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  22689. (byte*)&cbcPlain[9] , 9) == 0)
  22690. return WC_TEST_RET_ENC_NC;
  22691. if(outlen != 16)
  22692. return WC_TEST_RET_ENC_NC;
  22693. total += outlen;
  22694. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22695. return WC_TEST_RET_ENC_NC;
  22696. if(outlen != 16)
  22697. return WC_TEST_RET_ENC_NC;
  22698. total += outlen;
  22699. if(total != 32)
  22700. return WC_TEST_RET_ENC_NC;
  22701. total = 0;
  22702. wolfSSL_EVP_CIPHER_CTX_init(de);
  22703. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  22704. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22705. return WC_TEST_RET_ENC_NC;
  22706. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22707. return WC_TEST_RET_ENC_NC;
  22708. if(outlen != 0)
  22709. return WC_TEST_RET_ENC_NC;
  22710. total += outlen;
  22711. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22712. (byte*)&cipher[6], 12) == 0)
  22713. return WC_TEST_RET_ENC_NC;
  22714. if(outlen != 0)
  22715. total += outlen;
  22716. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22717. (byte*)&cipher[6+12], 14) == 0)
  22718. return WC_TEST_RET_ENC_NC;
  22719. if(outlen != 16)
  22720. return WC_TEST_RET_ENC_NC;
  22721. total += outlen;
  22722. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  22723. return WC_TEST_RET_ENC_NC;
  22724. if(outlen != 2)
  22725. return WC_TEST_RET_ENC_NC;
  22726. total += outlen;
  22727. if(total != 18)
  22728. return WC_TEST_RET_ENC_NC;
  22729. if (XMEMCMP(plain, cbcPlain, 18))
  22730. return WC_TEST_RET_ENC_NC;
  22731. total = 0;
  22732. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22733. return WC_TEST_RET_ENC_NC;
  22734. wolfSSL_EVP_CIPHER_CTX_init(en);
  22735. if (wolfSSL_EVP_EncryptInit(en, wolfSSL_EVP_aes_128_cbc(),
  22736. (unsigned char*)key, (unsigned char*)iv) == 0)
  22737. return WC_TEST_RET_ENC_NC;
  22738. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0)
  22739. return WC_TEST_RET_ENC_NC;
  22740. if(outlen != 0)
  22741. return WC_TEST_RET_ENC_NC;
  22742. total += outlen;
  22743. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0)
  22744. return WC_TEST_RET_ENC_NC;
  22745. if(outlen != 16)
  22746. return WC_TEST_RET_ENC_NC;
  22747. total += outlen;
  22748. if (wolfSSL_EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22749. return WC_TEST_RET_ENC_NC;
  22750. if(outlen != 16)
  22751. return WC_TEST_RET_ENC_NC;
  22752. total += outlen;
  22753. if(total != 32)
  22754. return 3438;
  22755. total = 0;
  22756. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22757. return WC_TEST_RET_ENC_NC;
  22758. wolfSSL_EVP_CIPHER_CTX_init(de);
  22759. if (wolfSSL_EVP_DecryptInit(de, wolfSSL_EVP_aes_128_cbc(),
  22760. (unsigned char*)key, (unsigned char*)iv) == 0)
  22761. return WC_TEST_RET_ENC_NC;
  22762. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22763. return WC_TEST_RET_ENC_NC;
  22764. if(outlen != 0)
  22765. return WC_TEST_RET_ENC_NC;
  22766. total += outlen;
  22767. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0)
  22768. return WC_TEST_RET_ENC_NC;
  22769. if(outlen != 0)
  22770. total += outlen;
  22771. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0)
  22772. return WC_TEST_RET_ENC_NC;
  22773. if(outlen != 16)
  22774. return WC_TEST_RET_ENC_NC;
  22775. total += outlen;
  22776. if (wolfSSL_EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0)
  22777. return WC_TEST_RET_ENC_NC;
  22778. if(outlen != 2)
  22779. return WC_TEST_RET_ENC_NC;
  22780. total += outlen;
  22781. if(total != 18)
  22782. return 3447;
  22783. if (XMEMCMP(plain, cbcPlain, 18))
  22784. return WC_TEST_RET_ENC_NC;
  22785. if (wolfSSL_EVP_Cipher_key_length(NULL) != 0)
  22786. return WC_TEST_RET_ENC_NC;
  22787. if (wolfSSL_EVP_Cipher_key_length(wolfSSL_EVP_aes_128_cbc()) != 16)
  22788. return WC_TEST_RET_ENC_NC;
  22789. if (wolfSSL_EVP_CIPHER_CTX_mode(NULL) != 0)
  22790. return WC_TEST_RET_ENC_NC;
  22791. if (wolfSSL_EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE))
  22792. return WC_TEST_RET_ENC_NC;
  22793. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22794. return WC_TEST_RET_ENC_NC;
  22795. wolfSSL_EVP_CIPHER_CTX_init(en);
  22796. if (wolfSSL_EVP_CipherInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22797. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22798. return WC_TEST_RET_ENC_NC;
  22799. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22800. return WC_TEST_RET_ENC_NC;
  22801. wolfSSL_EVP_CIPHER_CTX_init(en);
  22802. if (wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22803. (unsigned char*)key, (unsigned char*)iv) == 0)
  22804. return WC_TEST_RET_ENC_NC;
  22805. if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL)
  22806. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22807. {
  22808. return WC_TEST_RET_ENC_NC;
  22809. }
  22810. if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL)
  22811. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22812. {
  22813. return WC_TEST_RET_ENC_NC;
  22814. }
  22815. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22816. return WC_TEST_RET_ENC_NC;
  22817. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22818. return WC_TEST_RET_ENC_NC;
  22819. wolfSSL_EVP_CIPHER_CTX_init(de);
  22820. if (wolfSSL_EVP_DecryptInit_ex(de, wolfSSL_EVP_aes_128_cbc(), NULL,
  22821. (unsigned char*)key, (unsigned char*)iv) == 0)
  22822. return WC_TEST_RET_ENC_NC;
  22823. if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL)
  22824. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22825. {
  22826. return WC_TEST_RET_ENC_NC;
  22827. }
  22828. if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL)
  22829. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22830. {
  22831. return WC_TEST_RET_ENC_NC;
  22832. }
  22833. if (wolfSSL_EVP_CIPHER_CTX_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22834. return WC_TEST_RET_ENC_NC;
  22835. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22836. return WC_TEST_RET_ENC_NC;
  22837. wolfSSL_EVP_CIPHER_CTX_init(en);
  22838. wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22839. (unsigned char*)key, (unsigned char*)iv);
  22840. if (wolfSSL_EVP_CIPHER_CTX_block_size(en) != en->block_size)
  22841. return WC_TEST_RET_ENC_NC;
  22842. if (wolfSSL_EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22843. return WC_TEST_RET_ENC_NC;
  22844. if (wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_128_cbc()) != AES_BLOCK_SIZE)
  22845. return WC_TEST_RET_ENC_NC;
  22846. if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0)
  22847. return WC_TEST_RET_ENC_NC;
  22848. if (wolfSSL_EVP_CIPHER_flags(wolfSSL_EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE)
  22849. return WC_TEST_RET_ENC_NC;
  22850. wolfSSL_EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF);
  22851. wolfSSL_EVP_CIPHER_CTX_set_flags(en, 42);
  22852. if (en->flags != 42)
  22853. return WC_TEST_RET_ENC_NC;
  22854. if (wolfSSL_EVP_CIPHER_CTX_set_padding(NULL, 0) !=
  22855. WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22856. return WC_TEST_RET_ENC_NC;
  22857. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS)
  22858. return WC_TEST_RET_ENC_NC;
  22859. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS)
  22860. return WC_TEST_RET_ENC_NC;
  22861. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22862. return WC_TEST_RET_ENC_NC;
  22863. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22864. return WC_TEST_RET_ENC_NC;
  22865. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22866. wolfSSL_EVP_CIPHER_CTX_free(en);
  22867. wolfSSL_EVP_CIPHER_CTX_free(de);
  22868. #endif
  22869. }
  22870. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22871. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  22872. return 0;
  22873. }
  22874. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void)
  22875. {
  22876. wc_test_ret_t ret = 0;
  22877. #if !defined(NO_SHA256) && !defined(NO_SHA)
  22878. WOLFSSL_EVP_MD_CTX* ctx;
  22879. WOLFSSL_EVP_MD_CTX* ctx2;
  22880. WOLFSSL_ENTER("openSSL_evpMD_test");
  22881. ctx = wolfSSL_EVP_MD_CTX_new();
  22882. ctx2 = wolfSSL_EVP_MD_CTX_new();
  22883. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha256());
  22884. if (ret != WOLFSSL_SUCCESS) {
  22885. ret = WC_TEST_RET_ENC_NC;
  22886. goto openSSL_evpMD_test_done;
  22887. }
  22888. ret = wolfSSL_EVP_MD_CTX_copy(ctx2, ctx);
  22889. if (ret != WOLFSSL_SUCCESS) {
  22890. ret = WC_TEST_RET_ENC_NC;
  22891. goto openSSL_evpMD_test_done;
  22892. }
  22893. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22894. ret = WC_TEST_RET_ENC_NC;
  22895. goto openSSL_evpMD_test_done;
  22896. }
  22897. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha1());
  22898. if (ret != WOLFSSL_SUCCESS) {
  22899. ret = WC_TEST_RET_ENC_NC;
  22900. goto openSSL_evpMD_test_done;
  22901. }
  22902. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22903. ret = WC_TEST_RET_ENC_NC;
  22904. goto openSSL_evpMD_test_done;
  22905. }
  22906. ret = wolfSSL_EVP_MD_CTX_copy_ex(ctx2, ctx);
  22907. if (ret != WOLFSSL_SUCCESS) {
  22908. ret = WC_TEST_RET_ENC_NC;
  22909. goto openSSL_evpMD_test_done;
  22910. }
  22911. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) == wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22912. ret = WC_TEST_RET_ENC_NC;
  22913. goto openSSL_evpMD_test_done;
  22914. }
  22915. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha1()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22916. ret = WC_TEST_RET_ENC_NC;
  22917. goto openSSL_evpMD_test_done;
  22918. }
  22919. if (wolfSSL_EVP_DigestInit_ex(ctx, wolfSSL_EVP_sha1(), NULL) != WOLFSSL_SUCCESS) {
  22920. ret = WC_TEST_RET_ENC_NC;
  22921. goto openSSL_evpMD_test_done;
  22922. }
  22923. if (wolfSSL_EVP_add_digest(NULL) != 0) {
  22924. ret = WC_TEST_RET_ENC_NC;
  22925. goto openSSL_evpMD_test_done;
  22926. }
  22927. if (wolfSSL_EVP_add_cipher(NULL) != 0) {
  22928. ret = WC_TEST_RET_ENC_NC;
  22929. goto openSSL_evpMD_test_done;
  22930. }
  22931. ret = 0; /* got to success state without jumping to end with a fail */
  22932. openSSL_evpMD_test_done:
  22933. wolfSSL_EVP_MD_CTX_free(ctx);
  22934. wolfSSL_EVP_MD_CTX_free(ctx2);
  22935. #endif /* NO_SHA256 */
  22936. return ret;
  22937. }
  22938. #ifdef DEBUG_SIGN
  22939. static void show(const char *title, const char *p, unsigned int s) {
  22940. char* i;
  22941. printf("%s: ", title);
  22942. for (i = p;
  22943. i < p + s;
  22944. printf("%c", *i), i++);
  22945. printf("\n");
  22946. }
  22947. #else
  22948. #define show(a,b,c) WC_DO_NOTHING
  22949. #endif
  22950. #define FOURK_BUFF 4096
  22951. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void)
  22952. {
  22953. wc_test_ret_t ret = 0;
  22954. #if !defined(NO_RSA) && !defined(NO_SHA)
  22955. byte* prvTmp;
  22956. byte* pubTmp;
  22957. int prvBytes;
  22958. int pubBytes;
  22959. WOLFSSL_RSA *prvRsa = NULL;
  22960. WOLFSSL_RSA *pubRsa = NULL;
  22961. WOLFSSL_EVP_PKEY *prvPkey = NULL;
  22962. WOLFSSL_EVP_PKEY *pubPkey = NULL;
  22963. WOLFSSL_EVP_PKEY_CTX *enc = NULL;
  22964. WOLFSSL_EVP_PKEY_CTX *dec = NULL;
  22965. byte in[] = TEST_STRING;
  22966. byte out[256];
  22967. size_t outlen;
  22968. size_t keySz;
  22969. byte plain[256];
  22970. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  22971. XFILE keyFile;
  22972. XFILE keypubFile;
  22973. char cliKey[] = "./certs/client-key.der";
  22974. char cliKeypub[] = "./certs/client-keyPub.der";
  22975. #endif
  22976. WOLFSSL_ENTER("openssl_pkey0_test");
  22977. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22978. if (prvTmp == NULL)
  22979. return WC_TEST_RET_ENC_ERRNO;
  22980. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22981. if (pubTmp == NULL) {
  22982. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22983. return WC_TEST_RET_ENC_NC;
  22984. }
  22985. #ifdef USE_CERT_BUFFERS_1024
  22986. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  22987. prvBytes = sizeof_client_key_der_1024;
  22988. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  22989. pubBytes = sizeof_client_keypub_der_1024;
  22990. #elif defined(USE_CERT_BUFFERS_2048)
  22991. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  22992. prvBytes = sizeof_client_key_der_2048;
  22993. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  22994. pubBytes = sizeof_client_keypub_der_2048;
  22995. #else
  22996. keyFile = XFOPEN(cliKey, "rb");
  22997. if (!keyFile) {
  22998. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22999. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23000. err_sys("can't open ./certs/client-key.der, "
  23001. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23002. return WC_TEST_RET_ENC_ERRNO;
  23003. }
  23004. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23005. XFCLOSE(keyFile);
  23006. if (prvBytes == 0) {
  23007. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23008. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23009. return WC_TEST_RET_ENC_ERRNO;
  23010. }
  23011. keypubFile = XFOPEN(cliKeypub, "rb");
  23012. if (!keypubFile) {
  23013. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23014. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23015. err_sys("can't open ./certs/client-cert.der, "
  23016. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23017. return WC_TEST_RET_ENC_ERRNO;
  23018. }
  23019. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23020. XFCLOSE(keypubFile);
  23021. if (pubBytes == 0) {
  23022. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23023. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23024. return WC_TEST_RET_ENC_ERRNO;
  23025. }
  23026. #endif /* USE_CERT_BUFFERS */
  23027. prvRsa = wolfSSL_RSA_new();
  23028. pubRsa = wolfSSL_RSA_new();
  23029. if((prvRsa == NULL) || (pubRsa == NULL)){
  23030. printf("error with RSA_new\n");
  23031. ret = WC_TEST_RET_ENC_ERRNO;
  23032. goto openssl_pkey0_test_done;
  23033. }
  23034. ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23035. if(ret != WOLFSSL_SUCCESS){
  23036. printf("error with RSA_LoadDer_ex\n");
  23037. ret = WC_TEST_RET_ENC_EC(ret);
  23038. goto openssl_pkey0_test_done;
  23039. }
  23040. ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23041. if(ret != WOLFSSL_SUCCESS){
  23042. printf("error with RSA_LoadDer_ex\n");
  23043. ret = WC_TEST_RET_ENC_EC(ret);
  23044. goto openssl_pkey0_test_done;
  23045. }
  23046. keySz = (size_t)wolfSSL_RSA_size(pubRsa);
  23047. prvPkey = wolfSSL_EVP_PKEY_new();
  23048. pubPkey = wolfSSL_EVP_PKEY_new();
  23049. if((prvPkey == NULL) || (pubPkey == NULL)){
  23050. printf("error with PKEY_new\n");
  23051. ret = WC_TEST_RET_ENC_NC;
  23052. goto openssl_pkey0_test_done;
  23053. }
  23054. ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23055. ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23056. if(ret != 2){
  23057. printf("error with PKEY_set1_RSA\n");
  23058. ret = WC_TEST_RET_ENC_I(ret);
  23059. goto openssl_pkey0_test_done;
  23060. }
  23061. dec = wolfSSL_EVP_PKEY_CTX_new(prvPkey, NULL);
  23062. enc = wolfSSL_EVP_PKEY_CTX_new(pubPkey, NULL);
  23063. if((dec == NULL)||(enc==NULL)){
  23064. printf("error with EVP_PKEY_CTX_new\n");
  23065. ret = WC_TEST_RET_ENC_NC;
  23066. goto openssl_pkey0_test_done;
  23067. }
  23068. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23069. if (ret != 1) {
  23070. printf("error with decrypt init\n");
  23071. ret = WC_TEST_RET_ENC_NC;
  23072. goto openssl_pkey0_test_done;
  23073. }
  23074. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23075. if (ret != 1) {
  23076. printf("error with encrypt init\n");
  23077. ret = WC_TEST_RET_ENC_NC;
  23078. goto openssl_pkey0_test_done;
  23079. }
  23080. XMEMSET(out, 0, sizeof(out));
  23081. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23082. if (ret != 1) {
  23083. printf("error encrypting msg\n");
  23084. ret = WC_TEST_RET_ENC_NC;
  23085. goto openssl_pkey0_test_done;
  23086. }
  23087. show("encrypted msg", out, outlen);
  23088. XMEMSET(plain, 0, sizeof(plain));
  23089. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23090. if (ret != 1) {
  23091. printf("error decrypting msg\n");
  23092. ret = WC_TEST_RET_ENC_NC;
  23093. goto openssl_pkey0_test_done;
  23094. }
  23095. show("decrypted msg", plain, outlen);
  23096. /* RSA_PKCS1_OAEP_PADDING test */
  23097. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23098. if (ret != 1) {
  23099. printf("error with decrypt init\n");
  23100. ret = WC_TEST_RET_ENC_NC;
  23101. goto openssl_pkey0_test_done;
  23102. }
  23103. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23104. if (ret != 1) {
  23105. printf("error with encrypt init\n");
  23106. ret = WC_TEST_RET_ENC_NC;
  23107. goto openssl_pkey0_test_done;
  23108. }
  23109. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23110. printf("first set rsa padding error\n");
  23111. ret = WC_TEST_RET_ENC_EC(ret);
  23112. goto openssl_pkey0_test_done;
  23113. }
  23114. #ifndef HAVE_FIPS
  23115. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23116. printf("second set rsa padding error\n");
  23117. ret = WC_TEST_RET_ENC_EC(ret);
  23118. goto openssl_pkey0_test_done;
  23119. }
  23120. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23121. printf("third set rsa padding error\n");
  23122. ret = WC_TEST_RET_ENC_EC(ret);
  23123. goto openssl_pkey0_test_done;
  23124. }
  23125. #endif
  23126. XMEMSET(out, 0, sizeof(out));
  23127. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23128. if (ret != 1) {
  23129. printf("error encrypting msg\n");
  23130. ret = WC_TEST_RET_ENC_NC;
  23131. goto openssl_pkey0_test_done;
  23132. }
  23133. show("encrypted msg", out, outlen);
  23134. XMEMSET(plain, 0, sizeof(plain));
  23135. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23136. if (ret != 1) {
  23137. printf("error decrypting msg\n");
  23138. ret = WC_TEST_RET_ENC_NC;
  23139. goto openssl_pkey0_test_done;
  23140. }
  23141. show("decrypted msg", plain, outlen);
  23142. ret = 0; /* made it to this point without error then set success */
  23143. openssl_pkey0_test_done:
  23144. wolfSSL_RSA_free(prvRsa);
  23145. wolfSSL_RSA_free(pubRsa);
  23146. wolfSSL_EVP_PKEY_free(pubPkey);
  23147. wolfSSL_EVP_PKEY_free(prvPkey);
  23148. wolfSSL_EVP_PKEY_CTX_free(dec);
  23149. wolfSSL_EVP_PKEY_CTX_free(enc);
  23150. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23151. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23152. #endif /* NO_RSA */
  23153. return ret;
  23154. }
  23155. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void)
  23156. {
  23157. wc_test_ret_t ret = 0;
  23158. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_SHA)
  23159. WOLFSSL_EVP_PKEY_CTX* dec = NULL;
  23160. WOLFSSL_EVP_PKEY_CTX* enc = NULL;
  23161. WOLFSSL_EVP_PKEY* pubKey = NULL;
  23162. WOLFSSL_EVP_PKEY* prvKey = NULL;
  23163. WOLFSSL_X509* x509 = NULL;
  23164. WOLFSSL_SMALL_STACK_STATIC const unsigned char msg[] = "sugar slapped";
  23165. const unsigned char* clikey;
  23166. long cliKeySz;
  23167. size_t outlen;
  23168. int keyLenBits = 2048;
  23169. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23170. unsigned char *tmp = (unsigned char *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23171. unsigned char *cipher = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23172. unsigned char *plain = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23173. if ((tmp == NULL) ||
  23174. (cipher == NULL) ||
  23175. (plain == NULL)) {
  23176. ret = WC_TEST_RET_ENC_NC;
  23177. goto openssl_pkey1_test_done;
  23178. }
  23179. #else
  23180. unsigned char tmp[FOURK_BUF];
  23181. unsigned char cipher[RSA_TEST_BYTES];
  23182. unsigned char plain[RSA_TEST_BYTES];
  23183. #endif
  23184. WOLFSSL_ENTER("openssl_pkey1_test");
  23185. #if defined(USE_CERT_BUFFERS_1024)
  23186. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  23187. cliKeySz = (long)sizeof_client_key_der_1024;
  23188. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_1024,
  23189. sizeof_client_cert_der_1024, SSL_FILETYPE_ASN1);
  23190. keyLenBits = 1024;
  23191. #elif defined(USE_CERT_BUFFERS_2048)
  23192. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  23193. cliKeySz = (long)sizeof_client_key_der_2048;
  23194. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048,
  23195. sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1);
  23196. #elif defined(USE_CERT_BUFFERS_3072)
  23197. XMEMCPY(tmp, client_key_der_3072, sizeof_client_key_der_3072);
  23198. cliKeySz = (long)sizeof_client_key_der_3072;
  23199. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_3072,
  23200. sizeof_client_cert_der_3072, SSL_FILETYPE_ASN1);
  23201. keyLenBits = 3072;
  23202. #elif defined(USE_CERT_BUFFERS_4096)
  23203. XMEMCPY(tmp, client_key_der_4096, sizeof_client_key_der_4096);
  23204. cliKeySz = (long)sizeof_client_key_der_4096;
  23205. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_4096,
  23206. sizeof_client_cert_der_4096, SSL_FILETYPE_ASN1);
  23207. keyLenBits = 4096;
  23208. #else
  23209. {
  23210. XFILE f;
  23211. f = XFOPEN(clientKey, "rb");
  23212. if (!f) {
  23213. err_sys("can't open ./certs/client-key.der, "
  23214. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23215. ret = WC_TEST_RET_ENC_ERRNO;
  23216. goto openssl_pkey1_test_done;
  23217. }
  23218. cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f);
  23219. XFCLOSE(f);
  23220. if (cliKeySz == 0)
  23221. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done);
  23222. }
  23223. /* using existing wolfSSL api to get public and private key */
  23224. x509 = wolfSSL_X509_load_certificate_file(clientCert, WOLFSSL_FILETYPE_ASN1);
  23225. #endif /* USE_CERT_BUFFERS */
  23226. clikey = tmp;
  23227. if ((prvKey = wolfSSL_EVP_PKEY_new()) == NULL) {
  23228. ret = WC_TEST_RET_ENC_ERRNO;
  23229. goto openssl_pkey1_test_done;
  23230. }
  23231. wolfSSL_EVP_PKEY_free(prvKey);
  23232. prvKey = NULL;
  23233. if (x509 == NULL) {
  23234. ret = WC_TEST_RET_ENC_NC;
  23235. goto openssl_pkey1_test_done;
  23236. }
  23237. pubKey = wolfSSL_X509_get_pubkey(x509);
  23238. if (pubKey == NULL) {
  23239. ret = WC_TEST_RET_ENC_NC;
  23240. goto openssl_pkey1_test_done;
  23241. }
  23242. prvKey = wolfSSL_d2i_PrivateKey(WC_EVP_PKEY_RSA, NULL, &clikey, cliKeySz);
  23243. if (prvKey == NULL) {
  23244. ret = WC_TEST_RET_ENC_NC;
  23245. goto openssl_pkey1_test_done;
  23246. }
  23247. /* phase 2 API to create WOLFSSL_EVP_PKEY_CTX and encrypt/decrypt */
  23248. if (wolfSSL_EVP_PKEY_bits(prvKey) != keyLenBits) {
  23249. ret = WC_TEST_RET_ENC_NC;
  23250. goto openssl_pkey1_test_done;
  23251. }
  23252. if (wolfSSL_EVP_PKEY_size(prvKey) != keyLenBits/8) {
  23253. ret = WC_TEST_RET_ENC_NC;
  23254. goto openssl_pkey1_test_done;
  23255. }
  23256. dec = wolfSSL_EVP_PKEY_CTX_new(prvKey, NULL);
  23257. enc = wolfSSL_EVP_PKEY_CTX_new(pubKey, NULL);
  23258. if (dec == NULL || enc == NULL) {
  23259. ret = WC_TEST_RET_ENC_ERRNO;
  23260. goto openssl_pkey1_test_done;
  23261. }
  23262. if (wolfSSL_EVP_PKEY_decrypt_init(dec) != 1) {
  23263. ret = WC_TEST_RET_ENC_NC;
  23264. goto openssl_pkey1_test_done;
  23265. }
  23266. if (wolfSSL_EVP_PKEY_encrypt_init(enc) != 1) {
  23267. ret = WC_TEST_RET_ENC_NC;
  23268. goto openssl_pkey1_test_done;
  23269. }
  23270. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23271. ret = WC_TEST_RET_ENC_NC;
  23272. goto openssl_pkey1_test_done;
  23273. }
  23274. #ifndef HAVE_FIPS
  23275. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23276. ret = WC_TEST_RET_ENC_EC(ret);
  23277. goto openssl_pkey1_test_done;
  23278. }
  23279. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23280. ret = WC_TEST_RET_ENC_EC(ret);
  23281. goto openssl_pkey1_test_done;
  23282. }
  23283. #endif
  23284. XMEMSET(cipher, 0, RSA_TEST_BYTES);
  23285. outlen = (size_t)(keyLenBits/8);
  23286. if (wolfSSL_EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) {
  23287. ret = WC_TEST_RET_ENC_EC(ret);
  23288. goto openssl_pkey1_test_done;
  23289. }
  23290. XMEMSET(plain, 0, RSA_TEST_BYTES);
  23291. if (wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) {
  23292. ret = WC_TEST_RET_ENC_NC;
  23293. goto openssl_pkey1_test_done;
  23294. }
  23295. openssl_pkey1_test_done:
  23296. if (pubKey != NULL) {
  23297. wolfSSL_EVP_PKEY_free(pubKey);
  23298. }
  23299. if (prvKey != NULL) {
  23300. wolfSSL_EVP_PKEY_free(prvKey);
  23301. }
  23302. if (dec != NULL) {
  23303. wolfSSL_EVP_PKEY_CTX_free(dec);
  23304. }
  23305. if (enc != NULL) {
  23306. wolfSSL_EVP_PKEY_CTX_free(enc);
  23307. }
  23308. if (x509 != NULL) {
  23309. wolfSSL_X509_free(x509);
  23310. }
  23311. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23312. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23313. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23314. XFREE(plain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23315. #endif
  23316. #endif
  23317. return ret;
  23318. }
  23319. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void)
  23320. {
  23321. #if !defined(NO_RSA) && !defined(NO_SHA)
  23322. byte* prvTmp;
  23323. byte* pubTmp;
  23324. int prvBytes;
  23325. int pubBytes;
  23326. WOLFSSL_RSA *prvRsa;
  23327. WOLFSSL_RSA *pubRsa;
  23328. WOLFSSL_EVP_PKEY *prvPkey;
  23329. WOLFSSL_EVP_PKEY *pubPkey;
  23330. WOLFSSL_EVP_MD_CTX* sign;
  23331. WOLFSSL_EVP_MD_CTX* verf;
  23332. char msg[] = "see spot run";
  23333. unsigned char sig[256];
  23334. unsigned int sigSz;
  23335. const void* pt;
  23336. unsigned int count;
  23337. wc_test_ret_t ret, ret1, ret2;
  23338. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  23339. XFILE keyFile;
  23340. XFILE keypubFile;
  23341. char cliKey[] = "./certs/client-key.der";
  23342. char cliKeypub[] = "./certs/client-keyPub.der";
  23343. #endif
  23344. WOLFSSL_ENTER("openssl_evpSig_test");
  23345. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23346. if (prvTmp == NULL)
  23347. return WC_TEST_RET_ENC_ERRNO;
  23348. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23349. if (pubTmp == NULL) {
  23350. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23351. return WC_TEST_RET_ENC_NC;
  23352. }
  23353. #ifdef USE_CERT_BUFFERS_1024
  23354. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  23355. prvBytes = sizeof_client_key_der_1024;
  23356. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  23357. pubBytes = sizeof_client_keypub_der_1024;
  23358. #elif defined(USE_CERT_BUFFERS_2048)
  23359. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  23360. prvBytes = sizeof_client_key_der_2048;
  23361. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  23362. pubBytes = sizeof_client_keypub_der_2048;
  23363. #else
  23364. keyFile = XFOPEN(cliKey, "rb");
  23365. if (!keyFile) {
  23366. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23367. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23368. err_sys("can't open ./certs/client-key.der, "
  23369. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23370. return WC_TEST_RET_ENC_ERRNO;
  23371. }
  23372. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23373. XFCLOSE(keyFile);
  23374. if (prvBytes == 0) {
  23375. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23376. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23377. return WC_TEST_RET_ENC_ERRNO;
  23378. }
  23379. keypubFile = XFOPEN(cliKeypub, "rb");
  23380. if (!keypubFile) {
  23381. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23382. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23383. err_sys("can't open ./certs/client-cert.der, "
  23384. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23385. return WC_TEST_RET_ENC_ERRNO;
  23386. }
  23387. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23388. XFCLOSE(keypubFile);
  23389. if (pubBytes == 0) {
  23390. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23391. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23392. return WC_TEST_RET_ENC_ERRNO;
  23393. }
  23394. #endif /* USE_CERT_BUFFERS */
  23395. prvRsa = wolfSSL_RSA_new();
  23396. pubRsa = wolfSSL_RSA_new();
  23397. if((prvRsa == NULL) || (pubRsa == NULL)){
  23398. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23399. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23400. err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC);
  23401. return WC_TEST_RET_ENC_NC;
  23402. }
  23403. ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23404. ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23405. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23406. printf("error with RSA_LoadDer_ex\n");
  23407. return WC_TEST_RET_ENC_NC;
  23408. }
  23409. prvPkey = wolfSSL_EVP_PKEY_new();
  23410. pubPkey = wolfSSL_EVP_PKEY_new();
  23411. if((prvPkey == NULL) || (pubPkey == NULL)){
  23412. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23413. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23414. printf("error with KEY_new\n");
  23415. return WC_TEST_RET_ENC_NC;
  23416. }
  23417. ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23418. ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23419. if((ret1 != 1) || (ret2 != 1)){
  23420. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23421. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23422. printf("error with WOLFSSL_EVP_PKEY_set1_RSA\n");
  23423. return WC_TEST_RET_ENC_NC;
  23424. }
  23425. /****************** sign and verify *******************/
  23426. sign = wolfSSL_EVP_MD_CTX_new();
  23427. verf = wolfSSL_EVP_MD_CTX_new();
  23428. if((sign == NULL)||(verf == NULL)){
  23429. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23430. wolfSSL_EVP_MD_CTX_free(sign);
  23431. wolfSSL_EVP_MD_CTX_free(verf);
  23432. return WC_TEST_RET_ENC_NC;
  23433. }
  23434. ret = wolfSSL_EVP_SignInit(sign, wolfSSL_EVP_sha1());
  23435. if (ret != WOLFSSL_SUCCESS){
  23436. printf("error with EVP_SignInit\n");
  23437. wolfSSL_EVP_MD_CTX_free(sign);
  23438. wolfSSL_EVP_MD_CTX_free(verf);
  23439. return WC_TEST_RET_ENC_NC;
  23440. }
  23441. count = sizeof(msg);
  23442. show("message = ", (char *)msg, count);
  23443. /* sign */
  23444. XMEMSET(sig, 0, sizeof(sig));
  23445. pt = (const void*)msg;
  23446. ret1 = wolfSSL_EVP_SignUpdate(sign, pt, count);
  23447. ret2 = wolfSSL_EVP_SignFinal(sign, sig, &sigSz, prvPkey);
  23448. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23449. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23450. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23451. wolfSSL_EVP_MD_CTX_free(sign);
  23452. wolfSSL_EVP_MD_CTX_free(verf);
  23453. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23454. return WC_TEST_RET_ENC_NC;
  23455. }
  23456. show("signature = ", (char *)sig, sigSz);
  23457. /* verify */
  23458. pt = (const void*)msg;
  23459. ret1 = wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23460. ret2 = wolfSSL_EVP_VerifyUpdate(verf, pt, count);
  23461. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23462. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23463. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23464. wolfSSL_EVP_MD_CTX_free(sign);
  23465. wolfSSL_EVP_MD_CTX_free(verf);
  23466. printf("error with EVP_Verify\n");
  23467. return WC_TEST_RET_ENC_NC;
  23468. }
  23469. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) {
  23470. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23471. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23472. wolfSSL_EVP_MD_CTX_free(sign);
  23473. wolfSSL_EVP_MD_CTX_free(verf);
  23474. printf("error with EVP_VerifyFinal\n");
  23475. return WC_TEST_RET_ENC_NC;
  23476. }
  23477. /* expect fail without update */
  23478. wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23479. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) {
  23480. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23481. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23482. wolfSSL_EVP_MD_CTX_free(sign);
  23483. wolfSSL_EVP_MD_CTX_free(verf);
  23484. printf("EVP_VerifyInit without update not detected\n");
  23485. return WC_TEST_RET_ENC_NC;
  23486. }
  23487. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23488. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23489. wolfSSL_EVP_MD_CTX_free(sign);
  23490. wolfSSL_EVP_MD_CTX_free(verf);
  23491. wolfSSL_RSA_free(prvRsa);
  23492. wolfSSL_RSA_free(pubRsa);
  23493. wolfSSL_EVP_PKEY_free(pubPkey);
  23494. wolfSSL_EVP_PKEY_free(prvPkey);
  23495. #endif /* NO_RSA */
  23496. return 0;
  23497. }
  23498. #endif /* OPENSSL_EXTRA */
  23499. #ifndef NO_PWDBASED
  23500. #ifdef HAVE_SCRYPT
  23501. /* Test vectors taken from RFC 7914: scrypt PBKDF - Section 12. */
  23502. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
  23503. {
  23504. #ifdef HAVE_FIPS
  23505. /* RFC 7914 test vector keys are too short for FIPS. */
  23506. #else
  23507. wc_test_ret_t ret;
  23508. byte derived[64];
  23509. WOLFSSL_SMALL_STACK_STATIC const byte verify1[] = {
  23510. 0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20,
  23511. 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97,
  23512. 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8,
  23513. 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42,
  23514. 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8,
  23515. 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17,
  23516. 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28,
  23517. 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06
  23518. };
  23519. #if !defined(BENCH_EMBEDDED)
  23520. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23521. 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00,
  23522. 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe,
  23523. 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30,
  23524. 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62,
  23525. 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88,
  23526. 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda,
  23527. 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d,
  23528. 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40
  23529. };
  23530. #endif
  23531. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23532. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  23533. 0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48,
  23534. 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb,
  23535. 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e,
  23536. 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2,
  23537. 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf,
  23538. 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9,
  23539. 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40,
  23540. 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87
  23541. };
  23542. #endif
  23543. #ifdef SCRYPT_TEST_ALL
  23544. /* Test case is very slow.
  23545. * Use for confirmation after code change or new platform.
  23546. */
  23547. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  23548. 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae,
  23549. 0xad, 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81,
  23550. 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d,
  23551. 0xab, 0xe5, 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47,
  23552. 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, 0x9f,
  23553. 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3,
  23554. 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, 0x52, 0xfb,
  23555. 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4
  23556. };
  23557. #endif
  23558. WOLFSSL_ENTER("scrypt_test");
  23559. ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1));
  23560. if (ret != 0)
  23561. return WC_TEST_RET_ENC_EC(ret);
  23562. if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0)
  23563. return WC_TEST_RET_ENC_NC;
  23564. #if !defined(BENCH_EMBEDDED)
  23565. ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16,
  23566. sizeof(verify2));
  23567. if (ret != 0)
  23568. return WC_TEST_RET_ENC_EC(ret);
  23569. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23570. return WC_TEST_RET_ENC_NC;
  23571. #endif
  23572. /* Test case with parallel overflowing */
  23573. ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608,
  23574. sizeof(verify1));
  23575. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  23576. return WC_TEST_RET_ENC_EC(ret);
  23577. /* Don't run these test on embedded, since they use large mallocs */
  23578. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23579. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23580. (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3));
  23581. if (ret != 0)
  23582. return WC_TEST_RET_ENC_EC(ret);
  23583. if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0)
  23584. return WC_TEST_RET_ENC_NC;
  23585. #ifdef SCRYPT_TEST_ALL
  23586. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23587. (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4));
  23588. if (ret != 0)
  23589. return WC_TEST_RET_ENC_EC(ret);
  23590. if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0)
  23591. return WC_TEST_RET_ENC_NC;
  23592. #endif
  23593. #else
  23594. #ifdef SCRYPT_TEST_ALL
  23595. (void)verify4;
  23596. #endif
  23597. #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
  23598. #if !defined(BENCH_EMBEDDED)
  23599. ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10,
  23600. 8, 16, sizeof(verify2));
  23601. if (ret != 0)
  23602. return WC_TEST_RET_ENC_EC(ret);
  23603. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23604. return WC_TEST_RET_ENC_NC;
  23605. #endif
  23606. #endif /* !HAVE_FIPS */
  23607. return 0;
  23608. }
  23609. #endif
  23610. #ifdef HAVE_PKCS12
  23611. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void)
  23612. {
  23613. WOLFSSL_SMALL_STACK_STATIC const byte passwd[] = { 0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
  23614. 0x00, 0x00 };
  23615. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f };
  23616. WOLFSSL_SMALL_STACK_STATIC const byte passwd2[] = { 0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
  23617. 0x00, 0x67, 0x00, 0x00 };
  23618. WOLFSSL_SMALL_STACK_STATIC const byte salt2[] = { 0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5 };
  23619. byte derived[64];
  23620. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23621. 0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
  23622. 0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
  23623. 0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
  23624. };
  23625. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23626. 0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
  23627. 0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
  23628. 0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
  23629. };
  23630. int id = 1;
  23631. int kLen = 24;
  23632. int iterations = 1;
  23633. wc_test_ret_t ret;
  23634. WOLFSSL_ENTER("pkcs12_pbkdf_test");
  23635. ret = wc_PKCS12_PBKDF(derived, passwd, sizeof(passwd), salt, 8,
  23636. iterations, kLen, WC_SHA256, id);
  23637. if (ret < 0)
  23638. return WC_TEST_RET_ENC_EC(ret);
  23639. if (XMEMCMP(derived, verify, (unsigned long)kLen) != 0)
  23640. return WC_TEST_RET_ENC_NC;
  23641. iterations = 1000;
  23642. ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8,
  23643. iterations, kLen, WC_SHA256, id);
  23644. if (ret < 0)
  23645. return WC_TEST_RET_ENC_EC(ret);
  23646. ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8,
  23647. iterations, kLen, WC_SHA256, id, HEAP_HINT);
  23648. if (ret < 0)
  23649. return WC_TEST_RET_ENC_EC(ret);
  23650. if (XMEMCMP(derived, verify2, 24) != 0)
  23651. return WC_TEST_RET_ENC_NC;
  23652. return 0;
  23653. }
  23654. #endif /* HAVE_PKCS12 */
  23655. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23656. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
  23657. {
  23658. char passwd[] = "passwordpassword";
  23659. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a,
  23660. 0x5d, 0x63, 0xcb, 0x06 };
  23661. int iterations = 2048;
  23662. int kLen = 24;
  23663. byte derived[64];
  23664. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23665. 0x43, 0x6d, 0xb5, 0xe8, 0xd0, 0xfb, 0x3f, 0x35, 0x42, 0x48, 0x39, 0xbc,
  23666. 0x2d, 0xd4, 0xf9, 0x37, 0xd4, 0x95, 0x16, 0xa7, 0x2a, 0x9a, 0x21, 0xd1
  23667. };
  23668. wc_test_ret_t ret;
  23669. WOLFSSL_ENTER("pbkdf2_test");
  23670. ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
  23671. salt, (int)sizeof(salt), iterations,
  23672. kLen, WC_SHA256, HEAP_HINT, devId);
  23673. if (ret != 0)
  23674. return WC_TEST_RET_ENC_EC(ret);
  23675. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23676. return WC_TEST_RET_ENC_NC;
  23677. return 0;
  23678. }
  23679. #endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
  23680. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23681. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void)
  23682. {
  23683. char passwd[] = "password";
  23684. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  23685. int iterations = 1000;
  23686. int kLen = 16;
  23687. byte derived[16];
  23688. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23689. 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F,
  23690. 0xAF, 0x10, 0xEB, 0xFB, 0x4A, 0x3D, 0x2A, 0x20
  23691. };
  23692. wc_test_ret_t ret;
  23693. WOLFSSL_ENTER("pbkdf1_test");
  23694. ret = wc_PBKDF1_ex(derived, kLen, NULL, 0, (byte*)passwd,
  23695. (int)XSTRLEN(passwd), salt, (int)sizeof(salt), iterations, WC_SHA,
  23696. HEAP_HINT);
  23697. if (ret != 0)
  23698. return ret;
  23699. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23700. return WC_TEST_RET_ENC_NC;
  23701. return 0;
  23702. }
  23703. #endif /* HAVE_PBKDF2 && !NO_SHA */
  23704. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void)
  23705. {
  23706. wc_test_ret_t ret = 0;
  23707. WOLFSSL_ENTER("pwdbased_test");
  23708. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23709. ret = pbkdf1_test();
  23710. if (ret != 0)
  23711. return ret;
  23712. #endif
  23713. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23714. ret = pbkdf2_test();
  23715. if (ret != 0)
  23716. return ret;
  23717. #endif
  23718. #ifdef HAVE_PKCS12
  23719. ret = pkcs12_pbkdf_test();
  23720. if (ret != 0)
  23721. return ret;
  23722. #endif
  23723. #ifdef HAVE_SCRYPT
  23724. ret = scrypt_test();
  23725. if (ret != 0)
  23726. return ret;
  23727. #endif
  23728. return ret;
  23729. }
  23730. #endif /* NO_PWDBASED */
  23731. #if defined(USE_CERT_BUFFERS_2048) && \
  23732. defined(HAVE_PKCS12) && \
  23733. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  23734. !defined(NO_CERTS) && !defined(NO_DES3)
  23735. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
  23736. {
  23737. wc_test_ret_t ret = 0;
  23738. WC_PKCS12* pkcs12 = NULL;
  23739. /* Gen vars */
  23740. byte* pkcs12der = NULL;
  23741. int pkcs12derSz = 0;
  23742. WC_DerCertList derCaList = {
  23743. (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
  23744. };
  23745. char* pass = (char*)"wolfSSL test";
  23746. /* Parsing vars */
  23747. WC_DerCertList* derCaListOut = NULL;
  23748. byte* keyDer = NULL;
  23749. byte* certDer = NULL;
  23750. word32 keySz;
  23751. word32 certSz;
  23752. WOLFSSL_ENTER("pkcs12_test");
  23753. pkcs12 = wc_PKCS12_create(pass, (word32)XSTRLEN(pass),
  23754. (char*)"friendlyName" /* not used currently */,
  23755. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  23756. (byte*)server_cert_der_2048, sizeof_server_cert_der_2048,
  23757. &derCaList, PBE_SHA1_DES3, PBE_SHA1_DES3, 100, 100,
  23758. 0 /* not used currently */, HEAP_HINT);
  23759. if (pkcs12 == NULL) {
  23760. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23761. goto out;
  23762. }
  23763. ret = wc_i2d_PKCS12(pkcs12, NULL, &pkcs12derSz);
  23764. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  23765. if (ret == 0)
  23766. ret = WC_TEST_RET_ENC_NC;
  23767. else
  23768. ret = WC_TEST_RET_ENC_I(ret);
  23769. goto out;
  23770. }
  23771. pkcs12der = (byte*)XMALLOC(pkcs12derSz, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23772. if (pkcs12der == NULL) {
  23773. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23774. goto out;
  23775. }
  23776. {
  23777. /* Use tmp pointer to avoid advancing pkcs12der */
  23778. byte* tmp = pkcs12der;
  23779. ret = wc_i2d_PKCS12(pkcs12, &tmp, &pkcs12derSz);
  23780. if (ret <= 0) {
  23781. if (ret == 0)
  23782. ret = WC_TEST_RET_ENC_NC;
  23783. else
  23784. ret = WC_TEST_RET_ENC_I(ret);
  23785. goto out;
  23786. }
  23787. }
  23788. wc_PKCS12_free(pkcs12);
  23789. pkcs12 = wc_PKCS12_new_ex(HEAP_HINT);
  23790. if (pkcs12 == NULL) {
  23791. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23792. goto out;
  23793. }
  23794. /* convert the DER file into an internal structure */
  23795. ret = wc_d2i_PKCS12(pkcs12der, pkcs12derSz, pkcs12);
  23796. if (ret != 0) {
  23797. ret = WC_TEST_RET_ENC_EC(ret);
  23798. goto out;
  23799. }
  23800. /* parse the internal structure into its parts */
  23801. ret = wc_PKCS12_parse(pkcs12, "wolfSSL test", &keyDer, &keySz,
  23802. &certDer, &certSz, &derCaListOut);
  23803. if (ret != 0) {
  23804. ret = WC_TEST_RET_ENC_EC(ret);
  23805. goto out;
  23806. }
  23807. if (keyDer == NULL || certDer == NULL || derCaListOut == NULL) {
  23808. ret = WC_TEST_RET_ENC_NC;
  23809. goto out;
  23810. }
  23811. out:
  23812. if (derCaListOut)
  23813. wc_FreeCertList(derCaListOut, HEAP_HINT);
  23814. XFREE(keyDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23815. XFREE(certDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23816. if (pkcs12)
  23817. wc_PKCS12_free(pkcs12);
  23818. XFREE(pkcs12der, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23819. return ret;
  23820. }
  23821. #endif
  23822. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  23823. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  23824. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  23825. defined(WOLFSSL_AFALG_XILINX_RSA)
  23826. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  23827. static wc_test_ret_t hkdf_test(void)
  23828. #else
  23829. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void)
  23830. #endif
  23831. {
  23832. wc_test_ret_t ret = 0;
  23833. #if !defined(NO_SHA) || !defined(NO_SHA256)
  23834. int L;
  23835. byte okm1[42];
  23836. byte ikm1[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23837. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23838. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  23839. #ifndef HAVE_FIPS
  23840. byte salt1[13] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  23841. 0x08, 0x09, 0x0a, 0x0b, 0x0c };
  23842. byte info1[10] ={ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  23843. 0xf8, 0xf9 };
  23844. #endif
  23845. #ifndef NO_SHA
  23846. byte res1[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
  23847. 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
  23848. 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
  23849. 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
  23850. 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
  23851. 0x49, 0x18 };
  23852. #ifndef HAVE_FIPS
  23853. byte res2[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
  23854. 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
  23855. 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
  23856. 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
  23857. 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
  23858. 0xf8, 0x96 };
  23859. #endif
  23860. #endif /* !NO_SHA */
  23861. #ifndef NO_SHA256
  23862. byte res3[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
  23863. 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
  23864. 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
  23865. 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
  23866. 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
  23867. 0x96, 0xc8 };
  23868. #ifndef HAVE_FIPS
  23869. byte res4[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
  23870. 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
  23871. 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
  23872. 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
  23873. 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
  23874. 0x58, 0x65 };
  23875. #endif
  23876. #endif /* !NO_SHA256 */
  23877. WOLFSSL_ENTER("hkdf_test");
  23878. XMEMSET(okm1, 0, sizeof(okm1));
  23879. L = (int)sizeof(okm1);
  23880. #ifndef NO_SHA
  23881. ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23882. okm1, (word32)L);
  23883. if (ret != 0)
  23884. return WC_TEST_RET_ENC_EC(ret);
  23885. if (XMEMCMP(okm1, res1, (unsigned long)L) != 0)
  23886. return WC_TEST_RET_ENC_NC;
  23887. #ifndef HAVE_FIPS
  23888. /* fips can't have key size under 14 bytes, salt is key too */
  23889. L = (int)sizeof(okm1);
  23890. ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1),
  23891. info1, (word32)sizeof(info1), okm1, (word32)L);
  23892. if (ret != 0)
  23893. return WC_TEST_RET_ENC_EC(ret);
  23894. if (XMEMCMP(okm1, res2, (unsigned long)L) != 0)
  23895. return WC_TEST_RET_ENC_NC;
  23896. #endif /* HAVE_FIPS */
  23897. #endif /* !NO_SHA */
  23898. #ifndef NO_SHA256
  23899. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23900. okm1, (word32)L);
  23901. if (ret != 0)
  23902. return WC_TEST_RET_ENC_EC(ret);
  23903. if (XMEMCMP(okm1, res3, (unsigned long)L) != 0)
  23904. return WC_TEST_RET_ENC_NC;
  23905. #ifndef HAVE_FIPS
  23906. /* fips can't have key size under 14 bytes, salt is key too */
  23907. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1),
  23908. salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, (word32)L);
  23909. if (ret != 0)
  23910. return WC_TEST_RET_ENC_EC(ret);
  23911. if (XMEMCMP(okm1, res4, (unsigned long)L) != 0)
  23912. return WC_TEST_RET_ENC_NC;
  23913. #endif /* HAVE_FIPS */
  23914. #endif /* !NO_SHA256 */
  23915. #endif /* !NO_SHA || !NO_SHA256 */
  23916. return ret;
  23917. }
  23918. #endif /* HAVE_HKDF */
  23919. #ifdef WOLFSSL_WOLFSSH
  23920. typedef struct {
  23921. byte hashId;
  23922. byte keyId;
  23923. const byte* k;
  23924. word32 kSz;
  23925. const byte* h;
  23926. word32 hSz;
  23927. const byte* sessionId;
  23928. word32 sessionIdSz;
  23929. const byte* expectedKey;
  23930. word32 expectedKeySz;
  23931. } SshKdfTestVector;
  23932. /** Test Vector Set #3: SHA-256 **/
  23933. static const byte sshKdfTvSet3k[] = {
  23934. 0x6A, 0xC3, 0x82, 0xEA, 0xAC, 0xA0, 0x93, 0xE1,
  23935. 0x25, 0xE2, 0x5C, 0x24, 0xBE, 0xBC, 0x84, 0x64,
  23936. 0x0C, 0x11, 0x98, 0x75, 0x07, 0x34, 0x4B, 0x5C,
  23937. 0x73, 0x9C, 0xEB, 0x84, 0xA9, 0xE0, 0xB2, 0x22,
  23938. 0xB9, 0xA8, 0xB5, 0x1C, 0x83, 0x9E, 0x5E, 0xBE,
  23939. 0x49, 0xCF, 0xAD, 0xBF, 0xB3, 0x95, 0x99, 0x76,
  23940. 0x4E, 0xD5, 0x22, 0x09, 0x9D, 0xC9, 0x12, 0x75,
  23941. 0x19, 0x50, 0xDC, 0x7D, 0xC9, 0x7F, 0xBD, 0xC0,
  23942. 0x63, 0x28, 0xB6, 0x8F, 0x22, 0x78, 0x1F, 0xD3,
  23943. 0x15, 0xAF, 0x56, 0x80, 0x09, 0xA5, 0x50, 0x9E,
  23944. 0x5B, 0x87, 0xA1, 0x1B, 0xF5, 0x27, 0xC0, 0x56,
  23945. 0xDA, 0xFF, 0xD8, 0x2A, 0xB6, 0xCB, 0xC2, 0x5C,
  23946. 0xCA, 0x37, 0x14, 0x34, 0x59, 0xE7, 0xBC, 0x63,
  23947. 0xBC, 0xDE, 0x52, 0x75, 0x7A, 0xDE, 0xB7, 0xDF,
  23948. 0x01, 0xCF, 0x12, 0x17, 0x3F, 0x1F, 0xEF, 0x81,
  23949. 0x02, 0xEC, 0x5A, 0xB1, 0x42, 0xC2, 0x13, 0xDD,
  23950. 0x9D, 0x30, 0x69, 0x62, 0x78, 0xA8, 0xD8, 0xBC,
  23951. 0x32, 0xDD, 0xE9, 0x59, 0x2D, 0x28, 0xC0, 0x78,
  23952. 0xC6, 0xD9, 0x2B, 0x94, 0x7D, 0x82, 0x5A, 0xCA,
  23953. 0xAB, 0x64, 0x94, 0x84, 0x6A, 0x49, 0xDE, 0x24,
  23954. 0xB9, 0x62, 0x3F, 0x48, 0x89, 0xE8, 0xAD, 0xC3,
  23955. 0x8E, 0x8C, 0x66, 0x9E, 0xFF, 0xEF, 0x17, 0x60,
  23956. 0x40, 0xAD, 0x94, 0x5E, 0x90, 0xA7, 0xD3, 0xEE,
  23957. 0xC1, 0x5E, 0xFE, 0xEE, 0x78, 0xAE, 0x71, 0x04,
  23958. 0x3C, 0x96, 0x51, 0x11, 0x03, 0xA1, 0x6B, 0xA7,
  23959. 0xCA, 0xF0, 0xAC, 0xD0, 0x64, 0x2E, 0xFD, 0xBE,
  23960. 0x80, 0x99, 0x34, 0xFA, 0xA1, 0xA5, 0xF1, 0xBD,
  23961. 0x11, 0x04, 0x36, 0x49, 0xB2, 0x5C, 0xCD, 0x1F,
  23962. 0xEE, 0x2E, 0x38, 0x81, 0x5D, 0x4D, 0x5F, 0x5F,
  23963. 0xC6, 0xB4, 0x10, 0x29, 0x69, 0xF2, 0x1C, 0x22,
  23964. 0xAE, 0x1B, 0x0E, 0x7D, 0x36, 0x03, 0xA5, 0x56,
  23965. 0xA1, 0x32, 0x62, 0xFF, 0x62, 0x8D, 0xE2, 0x22
  23966. };
  23967. static const byte sshKdfTvSet3h[] = {
  23968. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23969. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23970. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23971. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23972. };
  23973. static const byte sshKdfTvSet3sid[] = {
  23974. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23975. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23976. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23977. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23978. };
  23979. static const byte sshKdfTvSet3a[] = {
  23980. 0x81, 0xF0, 0x33, 0x0E, 0xF6, 0xF0, 0x53, 0x61,
  23981. 0xB3, 0x82, 0x3B, 0xFD, 0xED, 0x6E, 0x1D, 0xE9
  23982. };
  23983. static const byte sshKdfTvSet3b[] = {
  23984. 0x3F, 0x6F, 0xD2, 0x06, 0x5E, 0xEB, 0x2B, 0x0B,
  23985. 0x1D, 0x93, 0x19, 0x5A, 0x1F, 0xED, 0x48, 0xA5
  23986. };
  23987. static const byte sshKdfTvSet3c[] = {
  23988. 0xC3, 0x54, 0x71, 0x03, 0x4E, 0x6F, 0xD6, 0x54,
  23989. 0x76, 0x13, 0x17, 0x8E, 0x23, 0x43, 0x5F, 0x21
  23990. };
  23991. static const byte sshKdfTvSet3d[] = {
  23992. 0x7E, 0x9D, 0x79, 0x03, 0x20, 0x90, 0xD9, 0x9F,
  23993. 0x98, 0xB0, 0x15, 0x63, 0x4D, 0xD9, 0xF4, 0x62
  23994. };
  23995. static const byte sshKdfTvSet3e[] = {
  23996. 0x24, 0xEE, 0x55, 0x9A, 0xD7, 0xCE, 0x71, 0x2B,
  23997. 0x68, 0x5D, 0x0B, 0x22, 0x71, 0xE4, 0x43, 0xC1,
  23998. 0x7A, 0xB1, 0xD1, 0xDC, 0xEB, 0x5A, 0x36, 0x05,
  23999. 0x69, 0xD2, 0x5D, 0x5D, 0xC2, 0x43, 0x00, 0x2F
  24000. };
  24001. static const byte sshKdfTvSet3f[] = {
  24002. 0xC3, 0x41, 0x9C, 0x2B, 0x96, 0x62, 0x35, 0x86,
  24003. 0x9D, 0x71, 0x4B, 0xA5, 0xAC, 0x48, 0xDD, 0xB7,
  24004. 0xD9, 0xE3, 0x5C, 0x8C, 0x19, 0xAA, 0xC7, 0x34,
  24005. 0x22, 0x33, 0x7A, 0x37, 0x34, 0x53, 0x60, 0x7E
  24006. };
  24007. static const SshKdfTestVector sshKdfTestVectors[] = {
  24008. {WC_HASH_TYPE_SHA256, 'A',
  24009. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24010. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24011. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24012. sshKdfTvSet3a, sizeof(sshKdfTvSet3a)},
  24013. {WC_HASH_TYPE_SHA256, 'B',
  24014. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24015. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24016. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24017. sshKdfTvSet3b, sizeof(sshKdfTvSet3b)},
  24018. {WC_HASH_TYPE_SHA256, 'C',
  24019. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24020. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24021. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24022. sshKdfTvSet3c, sizeof(sshKdfTvSet3c)},
  24023. {WC_HASH_TYPE_SHA256, 'D',
  24024. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24025. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24026. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24027. sshKdfTvSet3d, sizeof(sshKdfTvSet3d)},
  24028. {WC_HASH_TYPE_SHA256, 'E',
  24029. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24030. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24031. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24032. sshKdfTvSet3e, sizeof(sshKdfTvSet3e)},
  24033. {WC_HASH_TYPE_SHA256, 'F',
  24034. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24035. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24036. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24037. sshKdfTvSet3f, sizeof(sshKdfTvSet3f)},
  24038. };
  24039. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
  24040. {
  24041. byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and AES_BLOCK_SIZE */
  24042. word32 i;
  24043. word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector);
  24044. const SshKdfTestVector* tv = NULL;
  24045. wc_test_ret_t result = 0;
  24046. WOLFSSL_ENTER("sshkdf_test");
  24047. /* sId - Session ID, eKey - Expected Key, cKey - Calculated Key */
  24048. for (i = 0, tv = sshKdfTestVectors; i < tc; i++, tv++) {
  24049. result = wc_SSH_KDF(tv->hashId, tv->keyId,
  24050. cKey, tv->expectedKeySz,
  24051. tv->k, tv->kSz, tv->h, tv->hSz,
  24052. tv->sessionId, tv->sessionIdSz);
  24053. if (result != 0) {
  24054. printf("KDF: Could not derive key.\n");
  24055. result = WC_TEST_RET_ENC_EC(result);
  24056. }
  24057. else {
  24058. if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) {
  24059. printf("KDF: Calculated Key does not match Expected Key.\n");
  24060. result = WC_TEST_RET_ENC_EC(result);
  24061. }
  24062. }
  24063. if (result != 0) break;
  24064. }
  24065. return result;
  24066. }
  24067. #endif /* WOLFSSL_WOLFSSH */
  24068. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  24069. #define DIGL 12
  24070. #define SECL 48
  24071. #define LBSL 63
  24072. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
  24073. {
  24074. int ret;
  24075. byte dig[DIGL] = {0};
  24076. byte secret[SECL] = {
  24077. 0x10, 0xbc, 0xb4, 0xa2, 0xe8, 0xdc, 0xf1, 0x9b, 0x4c,
  24078. 0x51, 0x9c, 0xed, 0x31, 0x1b, 0x51, 0x57, 0x02, 0x3f,
  24079. 0xa1, 0x7d, 0xfb, 0x0e, 0xf3, 0x4e, 0x8f, 0x6f, 0x71,
  24080. 0xa3, 0x67, 0x76, 0x6b, 0xfa, 0x5d, 0x46, 0x4a, 0xe8,
  24081. 0x61, 0x18, 0x81, 0xc4, 0x66, 0xcc, 0x6f, 0x09, 0x99,
  24082. 0x9d, 0xfc, 0x47
  24083. };
  24084. byte lablSd[LBSL] = {
  24085. 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69,
  24086. 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x0b, 0x46, 0xba,
  24087. 0x56, 0xbf, 0x1f, 0x5d, 0x99, 0xff, 0xe9, 0xbb, 0x43,
  24088. 0x01, 0xe7, 0xca, 0x2c, 0x00, 0xdf, 0x9a, 0x39, 0x6e,
  24089. 0xcf, 0x6d, 0x15, 0x27, 0x4d, 0xf2, 0x93, 0x96, 0x4a,
  24090. 0x91, 0xde, 0x5c, 0xc0, 0x47, 0x7c, 0xa8, 0xae, 0xcf,
  24091. 0x5d, 0x93, 0x5f, 0x4c, 0x92, 0xcc, 0x98, 0x5b, 0x43
  24092. };
  24093. byte expected[DIGL] = {
  24094. 0xee, 0xcb, 0xb1, 0x30, 0xf2, 0xcd, 0xb3, 0x4a,
  24095. 0xbe, 0xda, 0xc1, 0xf6
  24096. };
  24097. int digL = DIGL;
  24098. int secL = SECL;
  24099. int lblsdL = LBSL;
  24100. int hash_type = sha384_mac;
  24101. ret = wc_PRF(dig, (word32)digL, secret, (word32)secL, lablSd,
  24102. (word32)lblsdL, hash_type,
  24103. HEAP_HINT, INVALID_DEVID);
  24104. if (ret != 0) {
  24105. printf("Failed w/ code: %d\n", ret);
  24106. return WC_TEST_RET_ENC_EC(ret);
  24107. }
  24108. if (XMEMCMP(expected, dig, DIGL) != 0) {
  24109. printf("Got unexpected digest\n");
  24110. return WC_TEST_RET_ENC_NC;
  24111. }
  24112. return 0;
  24113. }
  24114. #endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
  24115. #ifdef WOLFSSL_HAVE_PRF
  24116. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  24117. #ifdef WOLFSSL_BASE16
  24118. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
  24119. {
  24120. const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
  24121. "4E6C2E6C34A165B24540E2970875D641"
  24122. "2AA6515871B389B4C199BB8389C71CED";
  24123. const char* helloRandom = "162B81EDFBEAE4F25240320B87E7651C"
  24124. "865564191DD782DB0B9ECA275FBA1BB9"
  24125. "5A1DA3DF436D68DA86C5E7B4B4A36E46"
  24126. "B977C61767983A31BE270D74517BD0F6";
  24127. const char* masterSecret = "EB38B8D89B98B1C266DE44BB3CA14E83"
  24128. "C32F009F9955B1D994E61D3C51EE8760"
  24129. "90B4EF89CC7AF42F46E72201BFCC7977";
  24130. const char* label = "master secret";
  24131. byte pms[48] = {0};
  24132. byte seed[64] = {0};
  24133. byte ms[48] = {0};
  24134. byte result[48] = {0};
  24135. word32 pmsSz = (word32)sizeof(pms);
  24136. word32 seedSz = (word32)sizeof(seed);
  24137. word32 msSz = (word32)sizeof(ms);
  24138. int ret;
  24139. ret = Base16_Decode((const byte*)preMasterSecret,
  24140. (word32)XSTRLEN(preMasterSecret), pms, &pmsSz);
  24141. if (ret != 0)
  24142. return ret;
  24143. ret = Base16_Decode((const byte*)helloRandom,
  24144. (word32)XSTRLEN(helloRandom), seed, &seedSz);
  24145. if (ret != 0)
  24146. return ret;
  24147. ret = Base16_Decode((const byte*)masterSecret,
  24148. (word32)XSTRLEN(masterSecret), ms, &msSz);
  24149. if (ret != 0)
  24150. return ret;
  24151. ret = wc_PRF_TLS(result, msSz, pms, pmsSz,
  24152. (const byte*)label, (word32)XSTRLEN(label), seed, seedSz,
  24153. 1, sha256_mac, NULL, INVALID_DEVID);
  24154. if (ret != 0) {
  24155. if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
  24156. printf(" wc_PRF_TLSv12: Private key locked.\n");
  24157. }
  24158. return WC_TEST_RET_ENC_NC;
  24159. }
  24160. if (XMEMCMP(result, ms, msSz) != 0)
  24161. return WC_TEST_RET_ENC_NC;
  24162. return 0;
  24163. }
  24164. #endif /* WOLFSSL_BASE16 */
  24165. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  24166. #endif /* WOLFSSL_HAVE_PRF */
  24167. #ifdef WOLFSSL_TLS13
  24168. #define TLSV13_PSK_DHE_SZ 40
  24169. typedef struct {
  24170. enum wc_HashType hashAlg;
  24171. word32 pskSz;
  24172. word32 dheSz;
  24173. byte psk[TLSV13_PSK_DHE_SZ];
  24174. byte dhe[TLSV13_PSK_DHE_SZ];
  24175. byte hashHello1[WC_MAX_DIGEST_SIZE];
  24176. byte hashHello2[WC_MAX_DIGEST_SIZE];
  24177. byte hashFinished1[WC_MAX_DIGEST_SIZE];
  24178. byte hashFinished2[WC_MAX_DIGEST_SIZE];
  24179. /* Expected */
  24180. byte clientEarlyTrafficSecret[WC_MAX_DIGEST_SIZE];
  24181. byte earlyExporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24182. byte clientHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24183. byte serverHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24184. byte clientApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24185. byte serverApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24186. byte exporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24187. byte resumptionMasterSecret[WC_MAX_DIGEST_SIZE];
  24188. } Tls13KdfTestVector;
  24189. /* The following tests come from the CAVP test vectors we used for
  24190. * our FIPS validation. The hash values used are the components from
  24191. * the test hashed together. hashHello1 is the hash of the
  24192. * clientHelloRandom value of the test vector. hashHello2 is the hash
  24193. * of the clientHelloRandom and serverHelloRandom values from the test
  24194. * vector. hashFinished1 is clientHelloRandom, serverHelloRandom, and
  24195. * serverFinishedRandom. hashFinished2 is clientHelloRandom,
  24196. * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom
  24197. * hashed together. */
  24198. static const Tls13KdfTestVector tls13KdfTestVectors[] = {
  24199. { /* 1 */
  24200. WC_HASH_TYPE_SHA256, 35, 35,
  24201. { /* PSK */
  24202. 0x7b, 0xf1, 0x05, 0x31, 0x36, 0xfa, 0x03, 0xdc,
  24203. 0x31, 0x97, 0x88, 0x04, 0x9c, 0xbc, 0xee, 0xf7,
  24204. 0x8d, 0x84, 0x95, 0x26, 0xaf, 0x1d, 0x68, 0xb0,
  24205. 0x60, 0x7a, 0xcc, 0x4f, 0xc1, 0xd3, 0xa1, 0x68,
  24206. 0x7f, 0x6d, 0xbe
  24207. },
  24208. { /* DHE */
  24209. 0x6e, 0xa1, 0x77, 0xab, 0x2f, 0x43, 0xd2, 0x4b,
  24210. 0xe5, 0xa1, 0x09, 0xe0, 0x7a, 0xd0, 0x01, 0x35,
  24211. 0x8d, 0xf8, 0xf2, 0x5c, 0x91, 0x02, 0xb0, 0x6c,
  24212. 0x3f, 0xeb, 0xee, 0xa4, 0x42, 0x19, 0xce, 0xdc,
  24213. 0x81, 0x26, 0x40
  24214. },
  24215. { /* Hello 1 */
  24216. 0xd9, 0x4b, 0xe4, 0x17, 0xef, 0x58, 0x73, 0x7d,
  24217. 0x28, 0x3d, 0xf0, 0xcc, 0x05, 0x03, 0xaf, 0xac,
  24218. 0x3d, 0x92, 0x79, 0x48, 0xe8, 0x8c, 0xdb, 0xce,
  24219. 0x95, 0x82, 0x21, 0x31, 0x7b, 0x61, 0xd7, 0xc6
  24220. },
  24221. { /* Hello 2 */
  24222. 0xb7, 0x7f, 0x29, 0x91, 0xa4, 0x8b, 0x34, 0xdb,
  24223. 0xbd, 0xc7, 0x54, 0x1c, 0x3b, 0x86, 0xa3, 0x69,
  24224. 0xfe, 0x26, 0xe4, 0x7b, 0xac, 0x57, 0x71, 0xb3,
  24225. 0x32, 0x97, 0xed, 0xd2, 0x0e, 0x95, 0xb8, 0x63
  24226. },
  24227. { /* Finished 1 */
  24228. 0x65, 0xdb, 0x6d, 0x71, 0x71, 0xd0, 0xd8, 0x49,
  24229. 0xd0, 0x3c, 0x8e, 0x2b, 0x24, 0xdf, 0xc2, 0xe9,
  24230. 0xd6, 0xfd, 0xea, 0x04, 0x95, 0x7c, 0xf0, 0x7e,
  24231. 0x57, 0x74, 0x7c, 0xdd, 0xa3, 0x0b, 0x2b, 0x36
  24232. },
  24233. { /* Finished 2 */
  24234. 0x28, 0xf2, 0xf2, 0x79, 0xcf, 0x20, 0x52, 0x90,
  24235. 0x1d, 0x91, 0x05, 0xad, 0x44, 0x26, 0x23, 0x96,
  24236. 0x32, 0xce, 0xec, 0x61, 0xd1, 0xbf, 0x00, 0x48,
  24237. 0x4a, 0xa5, 0x60, 0xcc, 0x28, 0xb5, 0x8d, 0x98
  24238. },
  24239. { /* Client Early Traffic Secret */
  24240. 0x07, 0x14, 0x6a, 0x26, 0x5b, 0x6c, 0x7f, 0x4d, 0x6b, 0x47, 0x3f, 0xd5,
  24241. 0x03, 0x1d, 0xd2, 0x23, 0x3d, 0x89, 0x3e, 0xc6, 0x51, 0xd1, 0xac, 0xf8,
  24242. 0x28, 0xae, 0x4b, 0x76, 0xc8, 0x10, 0x7e, 0xdd
  24243. },
  24244. { /* Early Exporter Master Secret */
  24245. 0xb8, 0xd3, 0x25, 0x7e, 0x2d, 0x41, 0x7b, 0xcb, 0x5e, 0x82, 0x49, 0xf5,
  24246. 0x51, 0x3d, 0xb7, 0x59, 0x32, 0xb3, 0xdf, 0x99, 0x4e, 0x04, 0x69, 0xc6,
  24247. 0x96, 0x8e, 0xe6, 0x3d, 0x91, 0xe4, 0x81, 0x11
  24248. },
  24249. { /* Client Handshake Traffic Secret */
  24250. 0xd9, 0x3b, 0x54, 0xe2, 0xb0, 0xd1, 0x85, 0xf0, 0xfd, 0xf3, 0x48, 0x4a,
  24251. 0xf8, 0x0b, 0xa5, 0xdc, 0x4c, 0x37, 0xcb, 0xd4, 0x20, 0xaf, 0x60, 0xc7,
  24252. 0xd5, 0x50, 0x5d, 0x0c, 0x77, 0x3b, 0x6f, 0xd2
  24253. },
  24254. { /* Server Handshake Traffic Secret */
  24255. 0x4d, 0x40, 0x2b, 0xd2, 0x8c, 0x33, 0x90, 0x39, 0x67, 0x67, 0x05, 0xf7,
  24256. 0x5d, 0x37, 0x1e, 0xdc, 0x4a, 0x70, 0x6b, 0x9e, 0xf8, 0x06, 0x61, 0x89,
  24257. 0x70, 0xe1, 0x3d, 0x36, 0xad, 0x88, 0x7e, 0x5b
  24258. },
  24259. { /* Client Application Traffic Secret */
  24260. 0x74, 0x6e, 0xa0, 0x13, 0x18, 0x34, 0x48, 0x4d, 0x23, 0x31, 0xf1, 0xf9,
  24261. 0xee, 0x44, 0x6d, 0xad, 0xc1, 0xad, 0x92, 0x73, 0xca, 0x27, 0x16, 0x91,
  24262. 0xa2, 0x50, 0x9a, 0xfc, 0xec, 0xf0, 0x6b, 0x24
  24263. },
  24264. { /* Server Application Traffic Secret */
  24265. 0x89, 0x18, 0x7e, 0x34, 0x8d, 0xfc, 0x14, 0xb1, 0x4f, 0x21, 0xd8, 0x29,
  24266. 0xdb, 0x9b, 0xfb, 0x55, 0xcf, 0xa1, 0x4f, 0x95, 0xf8, 0xe0, 0xb0, 0x83,
  24267. 0xd5, 0x34, 0x9e, 0x0b, 0x83, 0x37, 0x42, 0x93
  24268. },
  24269. { /* Exporter Master Secret */
  24270. 0x7d, 0xc8, 0x88, 0x46, 0xd5, 0x57, 0x15, 0xb6, 0x24, 0x25, 0x92, 0x61,
  24271. 0xb1, 0x18, 0x86, 0x2a, 0x6d, 0xa5, 0x84, 0xeb, 0x59, 0xdf, 0x13, 0xbd,
  24272. 0x73, 0xaa, 0x5d, 0x65, 0xab, 0xd9, 0xb4, 0x56
  24273. },
  24274. { /* Resumption Master Secret */
  24275. 0x20, 0xb7, 0xd0, 0xe3, 0x82, 0x01, 0xa1, 0x04, 0xb8, 0x13, 0x29, 0xed,
  24276. 0x35, 0xe4, 0x2f, 0xbf, 0x58, 0x23, 0x7f, 0x21, 0xdb, 0x9f, 0xf8, 0xe0,
  24277. 0xe8, 0xe4, 0xab, 0xc4, 0xa1, 0x61, 0xb9, 0xbb
  24278. }
  24279. },
  24280. { /* 6 */
  24281. WC_HASH_TYPE_SHA256, 0, 33,
  24282. { 0 }, /* PSK */
  24283. { /* DHE */
  24284. 0x7a, 0x46, 0x8c, 0x5a, 0xd1, 0x8e, 0x95, 0xba,
  24285. 0x61, 0xe6, 0x6f, 0xe6, 0x76, 0x0c, 0x20, 0x43,
  24286. 0x16, 0x82, 0x15, 0xfe, 0x54, 0xa3, 0xc7, 0xfd,
  24287. 0x3b, 0x2c, 0x88, 0xb4, 0xd3, 0x42, 0x70, 0x12,
  24288. 0x18
  24289. },
  24290. { /* Hello 1 */
  24291. 0x63, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
  24292. 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
  24293. 0x7d, 0x5b, 0x42, 0xdc, 0xa8, 0xaa, 0x06, 0xfb,
  24294. 0x20, 0xa5, 0xbb, 0x85, 0xdb, 0x54, 0xd8, 0x8b
  24295. },
  24296. { /* Hello 2 */
  24297. 0xea, 0xfe, 0x9e, 0x8e, 0xff, 0x1f, 0x6f, 0x43,
  24298. 0xf9, 0x5d, 0xfd, 0xbf, 0xe2, 0x5f, 0x02, 0x2f,
  24299. 0x6d, 0x47, 0x60, 0x9a, 0x48, 0x9a, 0x75, 0xfb,
  24300. 0xb5, 0x4a, 0xbf, 0x9c, 0x4e, 0xff, 0xbf, 0x0b
  24301. },
  24302. { /* Finished 1 */
  24303. 0xca, 0x25, 0xb3, 0x53, 0x8e, 0x6d, 0xc3, 0x36,
  24304. 0x17, 0x30, 0x07, 0xdf, 0x0d, 0xd7, 0x79, 0xb0,
  24305. 0x7f, 0xcb, 0xbe, 0x7a, 0xbc, 0x2d, 0x9f, 0x2d,
  24306. 0x94, 0x44, 0x94, 0xe6, 0xa4, 0xf3, 0xe8, 0x53
  24307. },
  24308. { /* Finished 2 */
  24309. 0x2e, 0xa6, 0x5a, 0xaf, 0xb5, 0xba, 0x9f, 0x2f,
  24310. 0x74, 0x83, 0x5d, 0xbf, 0x86, 0xa4, 0xa6, 0xf6,
  24311. 0xb9, 0x89, 0xdf, 0x17, 0xe1, 0xa8, 0x14, 0xc0,
  24312. 0xe1, 0x50, 0xfa, 0xec, 0xfa, 0xae, 0x8b, 0x7b
  24313. },
  24314. {
  24315. 0x20, 0x18, 0x72, 0x7c, 0xde, 0x3a, 0x85, 0x17, 0x72, 0xdc, 0xd7, 0x72,
  24316. 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
  24317. 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
  24318. },
  24319. {
  24320. 0x68, 0x10, 0x20, 0xd1, 0x5e, 0xfc, 0x0c, 0x53, 0x85, 0xbb, 0xdb, 0x18,
  24321. 0xa8, 0x78, 0xf1, 0x2b, 0x13, 0xba, 0x64, 0x1d, 0xe7, 0x09, 0xbe, 0x13,
  24322. 0x49, 0x26, 0xf9, 0x98, 0x56, 0xf1, 0x43, 0xfb
  24323. },
  24324. {
  24325. 0x24, 0x35, 0x3e, 0x10, 0x6f, 0x39, 0x50, 0xd6, 0xa2, 0x12, 0x99, 0xf2,
  24326. 0xd5, 0xf5, 0x19, 0xf5, 0x84, 0xed, 0xee, 0x78, 0x2a, 0xa6, 0xfa, 0x3d,
  24327. 0x06, 0xa8, 0xa7, 0x5d, 0x97, 0x78, 0xd6, 0x58
  24328. },
  24329. {
  24330. 0xf4, 0x57, 0xac, 0x24, 0x7a, 0xfb, 0x7c, 0x3b, 0xb6, 0x39, 0x17, 0x14,
  24331. 0xd9, 0xd4, 0x58, 0x4d, 0x46, 0xd5, 0x1b, 0xde, 0xf7, 0x9d, 0x06, 0xee,
  24332. 0x8d, 0x1a, 0x2c, 0x25, 0x6d, 0x64, 0xde, 0x89
  24333. },
  24334. {
  24335. 0xb6, 0x00, 0xce, 0x63, 0xed, 0x65, 0x8b, 0x66, 0x66, 0x42, 0xc6, 0xbd,
  24336. 0x89, 0xc4, 0x71, 0x6f, 0xce, 0x28, 0xb2, 0xac, 0x97, 0x07, 0x5b, 0xea,
  24337. 0xb8, 0x1d, 0x4c, 0xeb, 0x9e, 0x71, 0x07, 0x8f
  24338. },
  24339. {
  24340. 0xf8, 0x92, 0xc8, 0xba, 0xe7, 0x83, 0xfe, 0x68, 0xe4, 0xd6, 0x5e, 0xcb,
  24341. 0xb3, 0xef, 0x49, 0xd0, 0xe7, 0xb1, 0xac, 0xcb, 0x39, 0x19, 0xfd, 0xa7,
  24342. 0xf7, 0xca, 0xab, 0x1e, 0x42, 0x14, 0xd8, 0xe7
  24343. },
  24344. {
  24345. 0x32, 0x4a, 0x1a, 0xad, 0xe2, 0xbb, 0x55, 0x8a, 0xdd, 0xe9, 0xa5, 0x2a,
  24346. 0x46, 0x5e, 0x6c, 0x83, 0x66, 0x27, 0x27, 0x94, 0xdd, 0x68, 0x59, 0xa0,
  24347. 0xbb, 0xe8, 0x31, 0x7c, 0x39, 0xd7, 0xfd, 0x6d
  24348. },
  24349. {
  24350. 0x58, 0xbc, 0x6c, 0x5b, 0x24, 0xad, 0x82, 0xb3, 0xcc, 0xc7, 0xd1, 0xa1,
  24351. 0xaa, 0x2b, 0x98, 0x9f, 0x2f, 0x7e, 0xa9, 0x63, 0xc2, 0x8e, 0xb6, 0x06,
  24352. 0xc2, 0x2b, 0x74, 0x4b, 0x79, 0x19, 0x7e, 0x2e
  24353. }
  24354. },
  24355. { /* 11 */
  24356. WC_HASH_TYPE_SHA256, 33, 0,
  24357. { /* PSK */
  24358. 0x3d, 0x39, 0x49, 0x36, 0x98, 0xc5, 0xfd, 0xcd,
  24359. 0xa0, 0x17, 0xbd, 0x65, 0x0a, 0xdb, 0xd4, 0x07,
  24360. 0x56, 0xa2, 0x7b, 0xb8, 0x2a, 0x7e, 0xfb, 0x26,
  24361. 0x74, 0xe1, 0xbc, 0x08, 0x4b, 0xf0, 0x30, 0x14,
  24362. 0x12
  24363. },
  24364. { 0 }, /* DHE */
  24365. { /* Hello 1 */
  24366. 0xb7, 0x44, 0x74, 0x6c, 0x57, 0x1f, 0xf3, 0x84,
  24367. 0x8f, 0x63, 0xfb, 0x8c, 0x94, 0x6c, 0x16, 0x68,
  24368. 0x4b, 0xe1, 0xb5, 0xb5, 0x2a, 0x4e, 0x5f, 0xdf,
  24369. 0x4b, 0x53, 0xb2, 0x35, 0xfc, 0x30, 0xf1, 0x36
  24370. },
  24371. { /* Hello 2 */
  24372. 0xe6, 0x4f, 0x3a, 0x4f, 0xd7, 0xe0, 0x64, 0xd4,
  24373. 0x69, 0x50, 0xe4, 0x8b, 0xba, 0xbc, 0x47, 0x74,
  24374. 0xa7, 0x9b, 0x40, 0x91, 0x8f, 0xa8, 0x72, 0x22,
  24375. 0x97, 0xad, 0x43, 0xa7, 0x11, 0x86, 0xb5, 0x72
  24376. },
  24377. { /* Finished 1 */
  24378. 0x5f, 0xa6, 0x10, 0xe2, 0xa3, 0x99, 0x0b, 0x5e,
  24379. 0x57, 0xee, 0xc3, 0x3a, 0x8e, 0x04, 0xf3, 0x0e,
  24380. 0x58, 0x02, 0x09, 0xb2, 0x7e, 0x2d, 0xc6, 0xd2,
  24381. 0x08, 0xae, 0x68, 0x0a, 0x55, 0xa5, 0xda, 0x51
  24382. },
  24383. { /* Finished 2 */
  24384. 0xfc, 0x5b, 0xc0, 0x7e, 0x1b, 0xaa, 0xc0, 0xb4,
  24385. 0x34, 0x85, 0x49, 0x8e, 0x16, 0x31, 0x98, 0xdf,
  24386. 0x10, 0x54, 0x22, 0xda, 0x1e, 0x6b, 0x51, 0xf6,
  24387. 0x97, 0x57, 0xa0, 0x7a, 0x92, 0xe7, 0x47, 0x52
  24388. },
  24389. {
  24390. 0x80, 0xfa, 0x36, 0x30, 0xb8, 0x65, 0xb3, 0x2a, 0x1d, 0x68, 0x91, 0x06,
  24391. 0x98, 0xa0, 0x17, 0x8f, 0xee, 0xb7, 0x9e, 0x3d, 0xd8, 0x84, 0x99, 0x30,
  24392. 0xb9, 0xd6, 0x09, 0x25, 0x5e, 0xfb, 0x8f, 0xd3 },
  24393. {
  24394. 0xa9, 0x89, 0x29, 0x70, 0xe4, 0x55, 0xec, 0x97, 0xfb, 0x24, 0x5b, 0xf9,
  24395. 0xf1, 0xa3, 0x19, 0x3d, 0xf1, 0x31, 0x14, 0xcd, 0x2a, 0xed, 0x21, 0xc8,
  24396. 0xb1, 0x53, 0xad, 0x11, 0x0b, 0x9e, 0x5a, 0xee },
  24397. {
  24398. 0x72, 0xad, 0x8d, 0x7f, 0xfc, 0xb7, 0x68, 0xda, 0x27, 0x60, 0x37, 0xa3,
  24399. 0x4a, 0x63, 0xe8, 0xa5, 0xc8, 0xcd, 0x36, 0x6a, 0x77, 0x99, 0x0d, 0xa9,
  24400. 0xb1, 0x5b, 0x2f, 0x47, 0x2e, 0x22, 0xa7, 0x5e },
  24401. {
  24402. 0x95, 0x6e, 0x85, 0x09, 0xe5, 0x04, 0x88, 0x14, 0x28, 0x8d, 0xdf, 0xe6,
  24403. 0x0d, 0x0f, 0x0d, 0x6b, 0x4e, 0x66, 0x1c, 0x03, 0xb9, 0xaa, 0x2d, 0x45,
  24404. 0x56, 0x67, 0x5c, 0x55, 0x29, 0xd6, 0x89, 0xd0 },
  24405. {
  24406. 0xe8, 0xf2, 0x14, 0xf9, 0x9b, 0x2b, 0x9f, 0x24, 0x2b, 0x37, 0xbe, 0x86,
  24407. 0xdb, 0x23, 0x4b, 0xbe, 0x39, 0x57, 0xe8, 0xa9, 0xa5, 0xee, 0x08, 0xf2,
  24408. 0x75, 0x58, 0xdb, 0xd9, 0x51, 0xc1, 0x46, 0x02 },
  24409. {
  24410. 0x3d, 0x19, 0xaf, 0xa3, 0x0b, 0x21, 0xf7, 0x3d, 0xe7, 0x37, 0x6e, 0x32,
  24411. 0x13, 0x48, 0x9d, 0xea, 0xe0, 0x90, 0xbf, 0x64, 0x48, 0xf7, 0x1e, 0xcc,
  24412. 0xf0, 0xbc, 0x92, 0xd7, 0x8a, 0x4a, 0xa8, 0xc1 },
  24413. {
  24414. 0x16, 0x35, 0xb1, 0x66, 0x28, 0xa3, 0x3e, 0x19, 0xf5, 0x2d, 0x92, 0x22,
  24415. 0x95, 0x48, 0xe8, 0x34, 0x7b, 0x30, 0x50, 0xa2, 0xa0, 0xd9, 0xc2, 0x59,
  24416. 0x39, 0xf9, 0x8c, 0x69, 0xf2, 0x2a, 0xb9, 0xff },
  24417. {
  24418. 0x32, 0x71, 0xa6, 0x87, 0x0c, 0x97, 0x42, 0x07, 0xdd, 0x5f, 0xc9, 0x44,
  24419. 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b,
  24420. 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 }
  24421. },
  24422. #ifdef WOLFSSL_SHA384
  24423. { /* 26 */
  24424. WC_HASH_TYPE_SHA384, 35, 35,
  24425. { /* PSK */
  24426. 0x62, 0x83, 0x25, 0xc7, 0xcc, 0x08, 0x5e, 0x63,
  24427. 0x64, 0x56, 0xf0, 0xc6, 0x88, 0x27, 0x5a, 0x5b,
  24428. 0x68, 0x59, 0x0b, 0x14, 0x55, 0x13, 0x2e, 0xfd,
  24429. 0x8f, 0x28, 0x5b, 0x3d, 0xe3, 0xad, 0x67, 0xe4,
  24430. 0x68, 0xba, 0xf9
  24431. },
  24432. { /* DHE */
  24433. 0xa8, 0xb1, 0xab, 0xd8, 0xc8, 0x5b, 0x52, 0xdf,
  24434. 0x7f, 0x49, 0x10, 0xf4, 0xa1, 0x31, 0xd1, 0x91,
  24435. 0x36, 0xc1, 0x87, 0x5d, 0x42, 0x2a, 0xe7, 0x1d,
  24436. 0x2c, 0x29, 0x3d, 0x40, 0x64, 0x61, 0x63, 0x76,
  24437. 0xd8, 0x66, 0xac
  24438. },
  24439. { /* Hello 1 */
  24440. 0x6f, 0xc6, 0x4c, 0xe1, 0xc6, 0x68, 0x34, 0x8c,
  24441. 0x0a, 0xe1, 0xf8, 0xb8, 0x3e, 0xd4, 0xf8, 0x0b,
  24442. 0x54, 0x50, 0xe4, 0xc5, 0x4a, 0x33, 0x7d, 0xbd,
  24443. 0x90, 0xd2, 0xa2, 0xb9, 0xb7, 0x92, 0xed, 0xab,
  24444. 0x14, 0xf1, 0xe4, 0x86, 0x22, 0x67, 0xd7, 0x44,
  24445. 0x03, 0x21, 0xdc, 0x51, 0x52, 0x7f, 0x35, 0x80
  24446. },
  24447. { /* Hello 2 */
  24448. 0x3e, 0xcf, 0x2f, 0xc3, 0x87, 0xba, 0xc5, 0xbd,
  24449. 0x7c, 0xe8, 0x35, 0x5b, 0x95, 0x51, 0x30, 0x3b,
  24450. 0x08, 0xcc, 0x2a, 0x7d, 0xb5, 0x74, 0x7c, 0x16,
  24451. 0xb3, 0x0b, 0xe7, 0x61, 0xa3, 0x7c, 0x6c, 0xbd,
  24452. 0x39, 0x74, 0xfd, 0x1e, 0x4c, 0xff, 0xc8, 0xcc,
  24453. 0xa0, 0xef, 0x29, 0x4d, 0x94, 0xaa, 0x55, 0x6f,
  24454. },
  24455. { /* Finished 1 */
  24456. 0x06, 0xc1, 0x47, 0x78, 0x66, 0x53, 0x6f, 0x24,
  24457. 0x94, 0x61, 0x69, 0xec, 0xd8, 0x60, 0x31, 0x2f,
  24458. 0xbf, 0xd6, 0x8a, 0x29, 0x17, 0xff, 0xa3, 0x88,
  24459. 0x13, 0x09, 0x8c, 0x9d, 0x6c, 0x64, 0x84, 0x48,
  24460. 0x44, 0xdd, 0x2d, 0x29, 0x4d, 0xe6, 0x98, 0x2b,
  24461. 0x45, 0x3b, 0x84, 0x33, 0x79, 0xb2, 0x75, 0x68
  24462. },
  24463. { /* Finished 2 */
  24464. 0x28, 0x1e, 0x18, 0xf7, 0x9c, 0x32, 0xa9, 0xbf,
  24465. 0x0c, 0x24, 0x58, 0x21, 0xce, 0xbc, 0xf2, 0x44,
  24466. 0xb1, 0x18, 0xaf, 0x9d, 0xd9, 0x20, 0xf9, 0xf4,
  24467. 0xed, 0xcc, 0x53, 0x82, 0x66, 0x5c, 0x46, 0x94,
  24468. 0x8c, 0x36, 0x5e, 0xca, 0x9f, 0xd8, 0x9a, 0xd3,
  24469. 0xf0, 0xe1, 0x53, 0x71, 0xdd, 0x19, 0x1e, 0x59
  24470. },
  24471. {
  24472. 0xd0, 0xef, 0xa8, 0xcb, 0x5b, 0x14, 0x0f, 0x0a, 0x62, 0xba, 0x5a, 0xb1,
  24473. 0xc5, 0xb5, 0x3f, 0x11, 0xda, 0xa1, 0x0c, 0x9c, 0xb4, 0x32, 0x48, 0x4e,
  24474. 0xfa, 0x84, 0x4f, 0xe4, 0xe7, 0x91, 0x8f, 0x42, 0x3f, 0xc7, 0x4e, 0xd3,
  24475. 0x83, 0x3d, 0x7f, 0x70, 0x12, 0xee, 0x9a, 0x37, 0x01, 0xbb, 0x14, 0xd3
  24476. },
  24477. {
  24478. 0x48, 0x6f, 0x77, 0x1d, 0x39, 0x1b, 0xa5, 0x9a, 0x76, 0xd9, 0x1d, 0x7d,
  24479. 0xb3, 0xd9, 0xb9, 0x78, 0x35, 0x0f, 0xd0, 0xe1, 0x07, 0x1f, 0x8d, 0xe5,
  24480. 0x75, 0x00, 0xda, 0xc0, 0x19, 0x01, 0xfb, 0x08, 0x35, 0xe7, 0x18, 0x8f,
  24481. 0xf0, 0x19, 0xfb, 0x46, 0xf6, 0xa5, 0x77, 0x0e, 0x90, 0x38, 0x8b, 0x15
  24482. },
  24483. {
  24484. 0x80, 0x8c, 0xa7, 0x24, 0x97, 0xf9, 0xd3, 0x52, 0xb0, 0x69, 0x9d, 0x4b,
  24485. 0xa4, 0x19, 0x4a, 0xb1, 0x46, 0x53, 0x3a, 0xc8, 0xe4, 0x02, 0x69, 0xf2,
  24486. 0xe7, 0xb6, 0x1d, 0x33, 0x51, 0xcc, 0x14, 0x40, 0x4a, 0xb0, 0xe7, 0x58,
  24487. 0x84, 0xba, 0xc2, 0x14, 0x58, 0x6b, 0xb9, 0xdc, 0x50, 0x98, 0x67, 0x01
  24488. },
  24489. {
  24490. 0xb1, 0xa8, 0xc0, 0x06, 0xb3, 0x2e, 0xa7, 0x8a, 0x6a, 0x12, 0x88, 0x00,
  24491. 0x65, 0x88, 0x9c, 0x5d, 0x35, 0xee, 0xe5, 0x51, 0x0b, 0x62, 0xf8, 0x67,
  24492. 0xe5, 0xef, 0x15, 0x1f, 0x23, 0x02, 0x74, 0x08, 0x9c, 0xc8, 0xba, 0x27,
  24493. 0x5d, 0x32, 0x19, 0x6f, 0x6d, 0x5d, 0x72, 0x5e, 0x15, 0xde, 0x30, 0xc3
  24494. },
  24495. {
  24496. 0xfd, 0xce, 0xf5, 0x65, 0x45, 0x84, 0xfb, 0x8c, 0x79, 0xa4, 0x6c, 0x1b,
  24497. 0x0e, 0x1b, 0xfd, 0x26, 0xa2, 0x53, 0xf4, 0x4e, 0x00, 0x4d, 0x4b, 0x0b,
  24498. 0x24, 0x6d, 0x35, 0x35, 0xd9, 0x97, 0x70, 0xc5, 0xf4, 0xee, 0xe3, 0xba,
  24499. 0x31, 0x1e, 0x2a, 0x42, 0xcb, 0xdf, 0x40, 0xb1, 0x14, 0xb8, 0x53, 0xce
  24500. },
  24501. {
  24502. 0xbb, 0xb3, 0x26, 0x7c, 0x22, 0x21, 0x9b, 0x72, 0x32, 0xa1, 0x97, 0xfb,
  24503. 0x78, 0x8c, 0xbe, 0x3d, 0x71, 0x45, 0xb8, 0xf5, 0x24, 0x8f, 0x0f, 0xac,
  24504. 0x42, 0x5b, 0x81, 0xe8, 0xd0, 0x71, 0x4a, 0xcb, 0x32, 0x3f, 0x03, 0xfb,
  24505. 0xec, 0x6a, 0x1f, 0x76, 0x80, 0x65, 0x01, 0x7a, 0x3d, 0xce, 0xc4, 0xdf
  24506. },
  24507. {
  24508. 0x3f, 0xcf, 0x2f, 0x63, 0x94, 0x94, 0x99, 0xfd, 0x04, 0x3a, 0x89, 0x83,
  24509. 0xcf, 0x06, 0x05, 0xec, 0x20, 0x3e, 0x5f, 0x51, 0x9d, 0x6e, 0x4a, 0xc6,
  24510. 0xf1, 0x2b, 0x37, 0x17, 0x34, 0x72, 0x6e, 0x1d, 0x2a, 0xfd, 0xc7, 0x73,
  24511. 0xb5, 0x07, 0x22, 0x81, 0x32, 0x2e, 0x21, 0x85, 0xaf, 0x10, 0xb2, 0x73
  24512. },
  24513. {
  24514. 0x52, 0x0c, 0x3d, 0x2e, 0x2d, 0x4a, 0x11, 0xae, 0x96, 0x78, 0xe9, 0x5b,
  24515. 0xd8, 0x0f, 0x6c, 0xf4, 0xbd, 0x96, 0x13, 0x55, 0x88, 0xdd, 0xa3, 0x67,
  24516. 0x36, 0x86, 0x1e, 0x0b, 0x36, 0x41, 0xec, 0xf6, 0x04, 0xb2, 0xc4, 0x16,
  24517. 0xbc, 0x2c, 0xdb, 0x30, 0x02, 0x94, 0xd4, 0x42, 0xbf, 0x38, 0xee, 0x9d
  24518. }
  24519. },
  24520. { /* 36 */
  24521. WC_HASH_TYPE_SHA384, 0, 33,
  24522. { 0 }, /* PSK */
  24523. { /* DHE */
  24524. 0xd3, 0x00, 0x72, 0x9a, 0xa8, 0xc5, 0xf3, 0xc4,
  24525. 0xf1, 0xa0, 0x26, 0x89, 0x65, 0x70, 0xc7, 0x0b,
  24526. 0x77, 0xbb, 0xe1, 0x4b, 0x2b, 0xa8, 0x4f, 0xa6,
  24527. 0x09, 0x4b, 0xba, 0x45, 0x36, 0x15, 0xee, 0x68,
  24528. 0xfd
  24529. },
  24530. { /* Hello 1 */
  24531. 0x10, 0x9d, 0x8b, 0xa2, 0x93, 0xe7, 0xd3, 0xb9,
  24532. 0xb4, 0x0f, 0xeb, 0x6a, 0xb9, 0x69, 0xcb, 0x39,
  24533. 0x16, 0x29, 0xcc, 0xd3, 0xcc, 0x1a, 0x4c, 0x1b,
  24534. 0x53, 0x7c, 0x33, 0x88, 0x06, 0xbc, 0x0a, 0x02,
  24535. 0xa0, 0xbe, 0x62, 0xc0, 0xe6, 0x5e, 0x97, 0x5b,
  24536. 0x6a, 0xa1, 0x98, 0xf3, 0xd2, 0x1e, 0xcd, 0xc5
  24537. },
  24538. { /* Hello 2 */
  24539. 0x74, 0xc0, 0x07, 0x2c, 0xc1, 0x63, 0xcc, 0x11,
  24540. 0xad, 0x1a, 0x55, 0x63, 0xbc, 0x20, 0x77, 0x96,
  24541. 0x30, 0x1c, 0x68, 0x45, 0x1e, 0x9b, 0xa7, 0xb4,
  24542. 0xf3, 0x04, 0x45, 0x16, 0x76, 0x55, 0xf9, 0xdf,
  24543. 0x4b, 0x2f, 0x1a, 0xdf, 0x5a, 0xb0, 0x93, 0xc9,
  24544. 0xab, 0xf5, 0x32, 0x47, 0x79, 0x9c, 0x01, 0xeb
  24545. },
  24546. { /* Finished 1 */
  24547. 0x27, 0x08, 0x8e, 0xa5, 0xf1, 0x30, 0xe1, 0xd6,
  24548. 0x4f, 0xa2, 0x9e, 0x3b, 0x03, 0x2d, 0x2e, 0xa3,
  24549. 0x84, 0x75, 0x51, 0x3a, 0xc3, 0xf6, 0xee, 0x2e,
  24550. 0x37, 0x0c, 0xe3, 0x28, 0x46, 0xa5, 0x2d, 0xc7,
  24551. 0xf0, 0x64, 0x78, 0x53, 0x66, 0x43, 0x02, 0xa4,
  24552. 0x7a, 0x43, 0x66, 0x4b, 0xa7, 0xcb, 0x97, 0x16
  24553. },
  24554. { /* Finished 2 */
  24555. 0x1d, 0x0d, 0xf8, 0xe1, 0x81, 0xa5, 0xbd, 0xa8,
  24556. 0x6f, 0x9d, 0x01, 0xa4, 0x9a, 0x92, 0xe2, 0xef,
  24557. 0x08, 0xab, 0xef, 0x3e, 0x2d, 0xd4, 0x82, 0xac,
  24558. 0x68, 0x9d, 0xe0, 0x54, 0x17, 0xde, 0x1a, 0xed,
  24559. 0x57, 0xcb, 0xd9, 0x2d, 0xc8, 0xbc, 0x93, 0xe6,
  24560. 0xa3, 0xec, 0xde, 0xee, 0xa1, 0x1c, 0x41, 0x85
  24561. },
  24562. {
  24563. 0x7f, 0x1f, 0xe6, 0x7b, 0xd8, 0xf5, 0x2b, 0x37, 0xbe, 0xb7, 0xd0, 0x37,
  24564. 0xce, 0x46, 0xad, 0x04, 0x2f, 0xc7, 0xdb, 0xc9, 0x9a, 0xb6, 0x00, 0x3f,
  24565. 0xc1, 0x97, 0xe9, 0x5c, 0x5e, 0x14, 0xd1, 0x38, 0x4d, 0x55, 0xe1, 0x07,
  24566. 0xb5, 0x85, 0x6d, 0xfa, 0xa7, 0x66, 0xad, 0xfa, 0xb6, 0xad, 0x29, 0x44
  24567. },
  24568. {
  24569. 0x4e, 0x6b, 0x20, 0x99, 0x55, 0x1b, 0x21, 0x89, 0xb6, 0x70, 0xdb, 0xe8,
  24570. 0xa7, 0x16, 0x55, 0xf2, 0x93, 0x13, 0x90, 0x7d, 0xfa, 0x62, 0x65, 0x53,
  24571. 0xa0, 0x97, 0xe9, 0xb4, 0xc0, 0xf1, 0xc9, 0x1a, 0x67, 0xdd, 0xca, 0x57,
  24572. 0xbc, 0xca, 0x39, 0xe6, 0x39, 0x6b, 0x63, 0x47, 0x25, 0x08, 0x3a, 0xd7
  24573. },
  24574. {
  24575. 0x35, 0x0d, 0xac, 0xd8, 0x10, 0x6a, 0x46, 0x50, 0x66, 0xae, 0x02, 0xc9,
  24576. 0xde, 0x13, 0x48, 0xce, 0x53, 0xd4, 0x92, 0x62, 0xc5, 0x65, 0x10, 0x08,
  24577. 0xc2, 0xc2, 0x82, 0xed, 0x9d, 0xc9, 0x6f, 0xa8, 0xc3, 0xc1, 0x0b, 0x7c,
  24578. 0xe1, 0x97, 0x85, 0xd6, 0x46, 0x29, 0x0e, 0x42, 0x51, 0xc1, 0x35, 0xcf
  24579. },
  24580. {
  24581. 0x3d, 0x5d, 0x84, 0xbd, 0x16, 0x46, 0x34, 0xb3, 0xf6, 0x31, 0x49, 0x3e,
  24582. 0x8d, 0xdc, 0xcb, 0x8c, 0x6a, 0x42, 0xf4, 0x88, 0xfc, 0x19, 0xfa, 0xa2,
  24583. 0x25, 0xc7, 0xa0, 0xa4, 0xca, 0xf0, 0xea, 0x2d, 0xe8, 0xc4, 0x02, 0x14,
  24584. 0x63, 0xfb, 0xd3, 0x7b, 0x51, 0x1c, 0xce, 0xca, 0xa3, 0xc3, 0xe4, 0xa5
  24585. },
  24586. {
  24587. 0x7c, 0x3a, 0x55, 0x92, 0x2e, 0xdd, 0x75, 0xdd, 0x76, 0x54, 0x4a, 0x9f,
  24588. 0xd0, 0xa2, 0x88, 0x83, 0xe9, 0x27, 0xda, 0x30, 0xe9, 0x96, 0x58, 0xc5,
  24589. 0xb7, 0x56, 0xfc, 0x4b, 0xb8, 0x5d, 0xee, 0x46, 0x70, 0x4e, 0x1b, 0x06,
  24590. 0x86, 0xaf, 0x48, 0x5c, 0x17, 0x35, 0xfa, 0x69, 0xc2, 0x4d, 0xfb, 0x09
  24591. },
  24592. {
  24593. 0x00, 0x0e, 0x28, 0x51, 0xc1, 0x7f, 0x41, 0x89, 0x6f, 0x9a, 0xca, 0x15,
  24594. 0xee, 0xed, 0x43, 0xca, 0x6d, 0x65, 0x6f, 0x51, 0x18, 0x6c, 0x08, 0x4b,
  24595. 0x77, 0xca, 0x75, 0xc4, 0xc3, 0xde, 0x29, 0x41, 0x8b, 0xaf, 0xa7, 0x1c,
  24596. 0x28, 0x37, 0xa0, 0xa0, 0x74, 0x8e, 0x09, 0x42, 0x7a, 0x1b, 0x68, 0xdb
  24597. },
  24598. {
  24599. 0x14, 0x8f, 0xab, 0x28, 0x64, 0xea, 0x45, 0x88, 0xdb, 0xc1, 0xc6, 0xa0,
  24600. 0x48, 0xdf, 0x15, 0xd0, 0x28, 0x07, 0x2d, 0x6c, 0xb8, 0x42, 0xbb, 0x60,
  24601. 0x02, 0x08, 0x9e, 0x29, 0x9b, 0x8d, 0xd6, 0x1c, 0xaf, 0xf2, 0x1a, 0xdc,
  24602. 0xf0, 0x78, 0x0b, 0x4d, 0x90, 0xa1, 0x0c, 0xb3, 0x13, 0xde, 0xca, 0x5a
  24603. },
  24604. {
  24605. 0x4d, 0x80, 0x7d, 0x0b, 0xb9, 0x00, 0x6f, 0x65, 0x51, 0x65, 0x23, 0xde,
  24606. 0x72, 0xdc, 0x4f, 0x04, 0xa5, 0xa2, 0x90, 0x45, 0x51, 0x9e, 0xd0, 0x3a,
  24607. 0xe4, 0xd7, 0x78, 0xa3, 0x0f, 0x2d, 0x65, 0x12, 0xad, 0xc8, 0x92, 0x30,
  24608. 0x79, 0x9d, 0x9d, 0x08, 0x7a, 0x9c, 0x9f, 0x83, 0xb1, 0xca, 0x59, 0x56
  24609. }
  24610. },
  24611. { /* 41 */
  24612. WC_HASH_TYPE_SHA384, 33, 0,
  24613. { /* PSK */
  24614. 0xa4, 0x8b, 0x1b, 0x5f, 0xd0, 0xea, 0x75, 0x62,
  24615. 0x06, 0x4d, 0x68, 0x40, 0x85, 0x20, 0x45, 0x95,
  24616. 0x4a, 0x00, 0xca, 0x05, 0xeb, 0xd4, 0x1d, 0x48,
  24617. 0x81, 0x89, 0xe8, 0x86, 0x43, 0xfa, 0x28, 0x17,
  24618. 0x12
  24619. },
  24620. { 0 }, /* DHE */
  24621. { /* Hello 1 */
  24622. 0x03, 0x7c, 0x33, 0x75, 0xdc, 0xc5, 0x46, 0x3a,
  24623. 0x0d, 0x56, 0xc6, 0xfb, 0xab, 0x1e, 0x1d, 0xda,
  24624. 0x59, 0xc2, 0xb2, 0xb1, 0x7c, 0x48, 0x9b, 0x06,
  24625. 0x0a, 0x5a, 0xbb, 0xf8, 0x98, 0x53, 0x78, 0x2d,
  24626. 0xd2, 0xcc, 0x87, 0x68, 0x25, 0xdd, 0x88, 0x22,
  24627. 0xcd, 0xb7, 0x74, 0x55, 0x21, 0xf9, 0x34, 0x98
  24628. },
  24629. { /* Hello 2 */
  24630. 0x03, 0xb4, 0xfb, 0xcc, 0x28, 0x2c, 0xc1, 0x70,
  24631. 0x42, 0x73, 0x57, 0xac, 0xdb, 0x47, 0x71, 0xf6,
  24632. 0x2e, 0x11, 0x8a, 0x5b, 0x47, 0x2f, 0x02, 0x54,
  24633. 0x95, 0x34, 0xed, 0x5f, 0x19, 0xc1, 0x75, 0xe0,
  24634. 0x76, 0xad, 0xb0, 0x90, 0x57, 0xcd, 0xfd, 0xd7,
  24635. 0x58, 0x1f, 0x0d, 0x6b, 0x9e, 0x51, 0x3c, 0x08
  24636. },
  24637. { /* Finished 1 */
  24638. 0x2b, 0x50, 0xd9, 0xa7, 0x43, 0x24, 0xda, 0x2c,
  24639. 0x7a, 0xaa, 0x0e, 0x37, 0xd7, 0x6b, 0x2c, 0xab,
  24640. 0x8e, 0xb2, 0xfe, 0x31, 0x1b, 0xa8, 0x12, 0x59,
  24641. 0x5b, 0x7b, 0xdc, 0x3e, 0xa7, 0x86, 0xa5, 0x48,
  24642. 0xe4, 0x46, 0x2b, 0x4c, 0xc1, 0x66, 0x4b, 0xf3,
  24643. 0x2a, 0x99, 0x93, 0x08, 0xbc, 0x3d, 0x08, 0x76
  24644. },
  24645. { /* Finished 2 */
  24646. 0x7c, 0x34, 0xc8, 0x56, 0x17, 0xf1, 0x62, 0x1c,
  24647. 0x9f, 0x0b, 0xeb, 0xfd, 0x69, 0x72, 0x51, 0xc5,
  24648. 0xfa, 0x74, 0x87, 0xc9, 0xbd, 0x50, 0xe9, 0x48,
  24649. 0xa7, 0x3c, 0x94, 0x3e, 0x06, 0x7d, 0xe8, 0x8e,
  24650. 0xc1, 0xd1, 0x08, 0x1f, 0x5d, 0x48, 0x8a, 0x25,
  24651. 0xfc, 0xea, 0xe7, 0xd9, 0xd4, 0xd0, 0xf9, 0xad
  24652. },
  24653. {
  24654. 0x4b, 0x0b, 0xed, 0xb9, 0xc8, 0xb8, 0xa8, 0x1e, 0xb0, 0x81, 0x76, 0xd5,
  24655. 0x33, 0x22, 0x71, 0x33, 0x3a, 0x85, 0x19, 0x67, 0x7e, 0x91, 0x37, 0xf2,
  24656. 0xa6, 0x11, 0x22, 0xdf, 0x41, 0x04, 0x3d, 0xa9, 0x13, 0xb9, 0xb2, 0xb1,
  24657. 0xbb, 0xd8, 0xef, 0x23, 0x7c, 0xc2, 0xab, 0x70, 0x1b, 0x51, 0x9f, 0xc9
  24658. },
  24659. {
  24660. 0xeb, 0x96, 0x10, 0x8c, 0x7d, 0x92, 0xea, 0x80, 0x86, 0xb2, 0xf8, 0x27,
  24661. 0xf2, 0x9a, 0x09, 0xc1, 0x7c, 0x09, 0x43, 0xbc, 0xfe, 0xc8, 0x75, 0xe0,
  24662. 0x97, 0xe7, 0x6d, 0xd5, 0xb2, 0x3c, 0xed, 0x12, 0xb7, 0x74, 0x0e, 0xe3,
  24663. 0xb6, 0xe0, 0xba, 0xe1, 0x8d, 0x89, 0xcf, 0x4f, 0x57, 0xf6, 0x6d, 0x90
  24664. },
  24665. {
  24666. 0x22, 0xb0, 0x39, 0x34, 0xb6, 0x6c, 0x2d, 0x7a, 0x97, 0x1c, 0x5d, 0xcc,
  24667. 0x78, 0x84, 0x71, 0xbb, 0xc6, 0x7b, 0xb6, 0xbc, 0xcc, 0x0b, 0xf8, 0xac,
  24668. 0x8e, 0xd7, 0x20, 0xbd, 0xbe, 0x32, 0xf0, 0xd6, 0xe9, 0x69, 0x13, 0xf2,
  24669. 0x9a, 0xce, 0xfe, 0x86, 0xd3, 0xee, 0xba, 0x69, 0x51, 0xb6, 0x77, 0x56
  24670. },
  24671. {
  24672. 0x16, 0xfd, 0xda, 0xf3, 0x5e, 0xb9, 0xa6, 0x17, 0x24, 0xb2, 0x16, 0x9f,
  24673. 0xb6, 0x59, 0x13, 0x0f, 0x25, 0x5a, 0xf1, 0x5b, 0x5f, 0xe4, 0x54, 0x2a,
  24674. 0xa7, 0xbf, 0x29, 0xaf, 0x5a, 0x77, 0xf4, 0x4f, 0x25, 0xba, 0x94, 0xad,
  24675. 0x6b, 0x91, 0x3b, 0xe7, 0xd5, 0x73, 0x0d, 0xff, 0xaa, 0xe3, 0x72, 0x2c
  24676. },
  24677. {
  24678. 0x22, 0xb4, 0x94, 0xc0, 0x53, 0xd7, 0x82, 0x06, 0x38, 0x9d, 0x4a, 0xa0,
  24679. 0x3f, 0xf1, 0x5f, 0x6e, 0x23, 0x8d, 0x09, 0x62, 0xbf, 0x6f, 0x7c, 0x84,
  24680. 0xc6, 0x3e, 0x15, 0xad, 0x18, 0x37, 0x76, 0x29, 0xc7, 0xd6, 0x68, 0x0c,
  24681. 0x1e, 0xc6, 0x93, 0x31, 0xef, 0x85, 0x69, 0x30, 0x68, 0xf0, 0x1e, 0x37
  24682. },
  24683. {
  24684. 0x6d, 0x4d, 0x20, 0xaf, 0x47, 0xe8, 0x1b, 0xfa, 0xd0, 0xb6, 0xc8, 0x97,
  24685. 0xd1, 0x03, 0xfc, 0x9d, 0x59, 0xa0, 0x68, 0x9d, 0xe9, 0x17, 0x8b, 0xce,
  24686. 0x48, 0x2c, 0x77, 0x8a, 0x22, 0x4b, 0x5c, 0x54, 0x22, 0xa1, 0x15, 0x12,
  24687. 0xe1, 0x07, 0x8e, 0x15, 0xd8, 0x7b, 0x16, 0x65, 0x99, 0x6b, 0xcb, 0x71
  24688. },
  24689. {
  24690. 0x79, 0x64, 0x79, 0xdd, 0x75, 0x5c, 0x6f, 0x98, 0xac, 0x03, 0xe0, 0xcd,
  24691. 0x92, 0xba, 0x0e, 0x2d, 0xb4, 0xd1, 0x8b, 0x97, 0xd0, 0x85, 0xbb, 0x2e,
  24692. 0x4f, 0x26, 0x93, 0xf5, 0x1d, 0xf3, 0xd2, 0x43, 0x4f, 0xd2, 0x47, 0xaa,
  24693. 0x91, 0x1e, 0xf3, 0x67, 0x10, 0x18, 0x2c, 0xb9, 0x01, 0xba, 0x10, 0x9f
  24694. },
  24695. {
  24696. 0x79, 0xb6, 0x9c, 0xbe, 0xf1, 0x6a, 0xb0, 0x92, 0xa0, 0x29, 0x52, 0x61,
  24697. 0xf1, 0xcd, 0x3a, 0x67, 0xe1, 0x6b, 0xb8, 0x9d, 0x0d, 0x95, 0xb6, 0x03,
  24698. 0x80, 0x1f, 0xd5, 0x75, 0xb6, 0x1d, 0x79, 0x02, 0x93, 0x43, 0x77, 0xa7,
  24699. 0x9d, 0x2f, 0xc3, 0x84, 0xc6, 0x83, 0x76, 0x16, 0x06, 0x98, 0x7b, 0x79
  24700. }
  24701. },
  24702. #endif /* WOLFSSL_SHA384 */
  24703. };
  24704. static const char protocolLabel[] = "tls13 ";
  24705. static const char ceTrafficLabel[] = "c e traffic";
  24706. static const char eExpMasterLabel[] = "e exp master";
  24707. static const char cHsTrafficLabel[] = "c hs traffic";
  24708. static const char sHsTrafficLabel[] = "s hs traffic";
  24709. static const char cAppTrafficLabel[] = "c ap traffic";
  24710. static const char sAppTrafficLabel[] = "s ap traffic";
  24711. static const char expMasterLabel[] = "exp master";
  24712. static const char resMasterLabel[] = "res master";
  24713. static const char derivedLabel[] = "derived";
  24714. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void)
  24715. {
  24716. wc_test_ret_t ret = 0;
  24717. word32 i;
  24718. word32 tc = sizeof(tls13KdfTestVectors)/sizeof(Tls13KdfTestVector);
  24719. const Tls13KdfTestVector* tv = NULL;
  24720. WOLFSSL_ENTER("tls13_kdf_test");
  24721. for (i = 0, tv = tls13KdfTestVectors; i < tc; i++, tv++) {
  24722. byte output[WC_MAX_DIGEST_SIZE];
  24723. byte secret[WC_MAX_DIGEST_SIZE];
  24724. byte salt[WC_MAX_DIGEST_SIZE];
  24725. byte zeroes[WC_MAX_DIGEST_SIZE];
  24726. byte hashZero[WC_MAX_DIGEST_SIZE];
  24727. int hashAlgSz;
  24728. XMEMSET(zeroes, 0, sizeof zeroes);
  24729. hashAlgSz = wc_HashGetDigestSize(tv->hashAlg);
  24730. if (hashAlgSz == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) break;
  24731. ret = wc_Hash(tv->hashAlg, NULL, 0, hashZero, (word32)hashAlgSz);
  24732. if (ret != 0) break;
  24733. ret = wc_Tls13_HKDF_Extract(secret, NULL, 0,
  24734. (tv->pskSz == 0) ? zeroes : (byte*)tv->psk,
  24735. tv->pskSz, (int)tv->hashAlg);
  24736. if (ret != 0) break;
  24737. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24738. secret, (word32)hashAlgSz,
  24739. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24740. (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel),
  24741. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24742. if (ret != 0) break;
  24743. ret = XMEMCMP(tv->clientEarlyTrafficSecret, output,
  24744. (unsigned long)hashAlgSz);
  24745. if (ret != 0) break;
  24746. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24747. secret, (word32)hashAlgSz,
  24748. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24749. (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel),
  24750. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24751. if (ret != 0) break;
  24752. ret = XMEMCMP(tv->earlyExporterMasterSecret, output,
  24753. (unsigned long)hashAlgSz);
  24754. if (ret != 0) break;
  24755. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24756. secret, (word32)hashAlgSz,
  24757. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24758. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24759. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24760. if (ret != 0) break;
  24761. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24762. (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe,
  24763. tv->dheSz, (int)tv->hashAlg);
  24764. if (ret != 0) break;
  24765. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24766. secret, (word32)hashAlgSz,
  24767. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24768. (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel),
  24769. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24770. if (ret != 0) break;
  24771. ret = XMEMCMP(tv->clientHandshakeTrafficSecret,
  24772. output, (unsigned long)hashAlgSz);
  24773. if (ret != 0) break;
  24774. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24775. secret, (word32)hashAlgSz,
  24776. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24777. (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel),
  24778. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24779. if (ret != 0) break;
  24780. ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output,
  24781. (unsigned long)hashAlgSz);
  24782. if (ret != 0) break;
  24783. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24784. secret, (word32)hashAlgSz,
  24785. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24786. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24787. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24788. if (ret != 0) break;
  24789. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24790. zeroes, (word32)(word32)hashAlgSz, (int)tv->hashAlg);
  24791. if (ret != 0) break;
  24792. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24793. secret, (word32)hashAlgSz,
  24794. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24795. (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel),
  24796. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24797. if (ret != 0) break;
  24798. ret = XMEMCMP(tv->clientApplicationTrafficSecret, output,
  24799. (unsigned long)hashAlgSz);
  24800. if (ret != 0) break;
  24801. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24802. secret, (word32)hashAlgSz,
  24803. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24804. (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel),
  24805. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24806. if (ret != 0) break;
  24807. ret = XMEMCMP(tv->serverApplicationTrafficSecret, output,
  24808. (unsigned long)hashAlgSz);
  24809. if (ret != 0) break;
  24810. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24811. secret, (word32)hashAlgSz,
  24812. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24813. (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel),
  24814. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24815. if (ret != 0) break;
  24816. ret = XMEMCMP(tv->exporterMasterSecret, output, (unsigned long)hashAlgSz);
  24817. if (ret != 0) break;
  24818. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24819. secret, (word32)hashAlgSz,
  24820. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24821. (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel),
  24822. tv->hashFinished2, (word32)hashAlgSz, (int)tv->hashAlg);
  24823. if (ret != 0) break;
  24824. ret = XMEMCMP(tv->resumptionMasterSecret, output,
  24825. (unsigned long)hashAlgSz);
  24826. if (ret != 0) break;
  24827. }
  24828. return ret;
  24829. }
  24830. #endif /* WOLFSSL_TLS13 */
  24831. static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point --
  24832. * see print_fiducials() below.
  24833. */
  24834. #if defined(HAVE_ECC) && defined(HAVE_X963_KDF)
  24835. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void)
  24836. {
  24837. wc_test_ret_t ret;
  24838. byte kek[128];
  24839. #ifndef NO_SHA
  24840. /* SHA-1, COUNT = 0
  24841. * shared secret length: 192
  24842. * SharedInfo length: 0
  24843. * key data length: 128
  24844. */
  24845. WOLFSSL_SMALL_STACK_STATIC const byte Z[] = {
  24846. 0x1c, 0x7d, 0x7b, 0x5f, 0x05, 0x97, 0xb0, 0x3d,
  24847. 0x06, 0xa0, 0x18, 0x46, 0x6e, 0xd1, 0xa9, 0x3e,
  24848. 0x30, 0xed, 0x4b, 0x04, 0xdc, 0x64, 0xcc, 0xdd
  24849. };
  24850. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  24851. 0xbf, 0x71, 0xdf, 0xfd, 0x8f, 0x4d, 0x99, 0x22,
  24852. 0x39, 0x36, 0xbe, 0xb4, 0x6f, 0xee, 0x8c, 0xcc
  24853. };
  24854. #endif
  24855. #ifndef NO_SHA256
  24856. /* SHA-256, COUNT = 3
  24857. * shared secret length: 192
  24858. * SharedInfo length: 0
  24859. * key data length: 128
  24860. */
  24861. WOLFSSL_SMALL_STACK_STATIC const byte Z2[] = {
  24862. 0xd3, 0x8b, 0xdb, 0xe5, 0xc4, 0xfc, 0x16, 0x4c,
  24863. 0xdd, 0x96, 0x7f, 0x63, 0xc0, 0x4f, 0xe0, 0x7b,
  24864. 0x60, 0xcd, 0xe8, 0x81, 0xc2, 0x46, 0x43, 0x8c
  24865. };
  24866. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  24867. 0x5e, 0x67, 0x4d, 0xb9, 0x71, 0xba, 0xc2, 0x0a,
  24868. 0x80, 0xba, 0xd0, 0xd4, 0x51, 0x4d, 0xc4, 0x84
  24869. };
  24870. #endif
  24871. #ifdef WOLFSSL_SHA512
  24872. /* SHA-512, COUNT = 0
  24873. * shared secret length: 192
  24874. * SharedInfo length: 0
  24875. * key data length: 128
  24876. */
  24877. WOLFSSL_SMALL_STACK_STATIC const byte Z3[] = {
  24878. 0x87, 0xfc, 0x0d, 0x8c, 0x44, 0x77, 0x48, 0x5b,
  24879. 0xb5, 0x74, 0xf5, 0xfc, 0xea, 0x26, 0x4b, 0x30,
  24880. 0x88, 0x5d, 0xc8, 0xd9, 0x0a, 0xd8, 0x27, 0x82
  24881. };
  24882. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  24883. 0x94, 0x76, 0x65, 0xfb, 0xb9, 0x15, 0x21, 0x53,
  24884. 0xef, 0x46, 0x02, 0x38, 0x50, 0x6a, 0x02, 0x45
  24885. };
  24886. /* SHA-512, COUNT = 0
  24887. * shared secret length: 521
  24888. * SharedInfo length: 128
  24889. * key data length: 1024
  24890. */
  24891. WOLFSSL_SMALL_STACK_STATIC const byte Z4[] = {
  24892. 0x00, 0xaa, 0x5b, 0xb7, 0x9b, 0x33, 0xe3, 0x89,
  24893. 0xfa, 0x58, 0xce, 0xad, 0xc0, 0x47, 0x19, 0x7f,
  24894. 0x14, 0xe7, 0x37, 0x12, 0xf4, 0x52, 0xca, 0xa9,
  24895. 0xfc, 0x4c, 0x9a, 0xdb, 0x36, 0x93, 0x48, 0xb8,
  24896. 0x15, 0x07, 0x39, 0x2f, 0x1a, 0x86, 0xdd, 0xfd,
  24897. 0xb7, 0xc4, 0xff, 0x82, 0x31, 0xc4, 0xbd, 0x0f,
  24898. 0x44, 0xe4, 0x4a, 0x1b, 0x55, 0xb1, 0x40, 0x47,
  24899. 0x47, 0xa9, 0xe2, 0xe7, 0x53, 0xf5, 0x5e, 0xf0,
  24900. 0x5a, 0x2d
  24901. };
  24902. WOLFSSL_SMALL_STACK_STATIC const byte info4[] = {
  24903. 0xe3, 0xb5, 0xb4, 0xc1, 0xb0, 0xd5, 0xcf, 0x1d,
  24904. 0x2b, 0x3a, 0x2f, 0x99, 0x37, 0x89, 0x5d, 0x31
  24905. };
  24906. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  24907. 0x44, 0x63, 0xf8, 0x69, 0xf3, 0xcc, 0x18, 0x76,
  24908. 0x9b, 0x52, 0x26, 0x4b, 0x01, 0x12, 0xb5, 0x85,
  24909. 0x8f, 0x7a, 0xd3, 0x2a, 0x5a, 0x2d, 0x96, 0xd8,
  24910. 0xcf, 0xfa, 0xbf, 0x7f, 0xa7, 0x33, 0x63, 0x3d,
  24911. 0x6e, 0x4d, 0xd2, 0xa5, 0x99, 0xac, 0xce, 0xb3,
  24912. 0xea, 0x54, 0xa6, 0x21, 0x7c, 0xe0, 0xb5, 0x0e,
  24913. 0xef, 0x4f, 0x6b, 0x40, 0xa5, 0xc3, 0x02, 0x50,
  24914. 0xa5, 0xa8, 0xee, 0xee, 0x20, 0x80, 0x02, 0x26,
  24915. 0x70, 0x89, 0xdb, 0xf3, 0x51, 0xf3, 0xf5, 0x02,
  24916. 0x2a, 0xa9, 0x63, 0x8b, 0xf1, 0xee, 0x41, 0x9d,
  24917. 0xea, 0x9c, 0x4f, 0xf7, 0x45, 0xa2, 0x5a, 0xc2,
  24918. 0x7b, 0xda, 0x33, 0xca, 0x08, 0xbd, 0x56, 0xdd,
  24919. 0x1a, 0x59, 0xb4, 0x10, 0x6c, 0xf2, 0xdb, 0xbc,
  24920. 0x0a, 0xb2, 0xaa, 0x8e, 0x2e, 0xfa, 0x7b, 0x17,
  24921. 0x90, 0x2d, 0x34, 0x27, 0x69, 0x51, 0xce, 0xcc,
  24922. 0xab, 0x87, 0xf9, 0x66, 0x1c, 0x3e, 0x88, 0x16
  24923. };
  24924. #endif
  24925. WOLFSSL_ENTER("x963kdf_test");
  24926. #ifndef NO_SHA
  24927. ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0,
  24928. kek, sizeof(verify));
  24929. if (ret != 0)
  24930. return WC_TEST_RET_ENC_EC(ret);
  24931. if (XMEMCMP(verify, kek, sizeof(verify)) != 0)
  24932. return WC_TEST_RET_ENC_NC;
  24933. #endif
  24934. #ifndef NO_SHA256
  24935. ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0,
  24936. kek, sizeof(verify2));
  24937. if (ret != 0)
  24938. return WC_TEST_RET_ENC_EC(ret);
  24939. if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0)
  24940. return WC_TEST_RET_ENC_NC;
  24941. #endif
  24942. #ifdef WOLFSSL_SHA512
  24943. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0,
  24944. kek, sizeof(verify3));
  24945. if (ret != 0)
  24946. return WC_TEST_RET_ENC_EC(ret);
  24947. if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0)
  24948. return WC_TEST_RET_ENC_NC;
  24949. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4,
  24950. sizeof(info4), kek, sizeof(verify4));
  24951. if (ret != 0)
  24952. return WC_TEST_RET_ENC_EC(ret);
  24953. if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0)
  24954. return WC_TEST_RET_ENC_NC;
  24955. #endif
  24956. return 0;
  24957. }
  24958. #endif /* HAVE_X963_KDF */
  24959. #if defined(HAVE_HPKE) && \
  24960. (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) && \
  24961. defined(HAVE_AESGCM)
  24962. static wc_test_ret_t hpke_test_single(Hpke* hpke)
  24963. {
  24964. wc_test_ret_t ret = 0;
  24965. int rngRet = 0;
  24966. WC_RNG rng[1];
  24967. const char* start_text = "this is a test";
  24968. const char* info_text = "info";
  24969. const char* aad_text = "aad";
  24970. byte ciphertext[MAX_HPKE_LABEL_SZ];
  24971. byte plaintext[MAX_HPKE_LABEL_SZ];
  24972. void* receiverKey = NULL;
  24973. void* ephemeralKey = NULL;
  24974. #ifdef WOLFSSL_SMALL_STACK
  24975. byte *pubKey = NULL; /* public key */
  24976. word16 pubKeySz = (word16)HPKE_Npk_MAX;
  24977. #else
  24978. byte pubKey[HPKE_Npk_MAX]; /* public key */
  24979. word16 pubKeySz = (word16)sizeof(pubKey);
  24980. #endif
  24981. rngRet = ret = wc_InitRng(rng);
  24982. if (ret != 0)
  24983. return WC_TEST_RET_ENC_EC(ret);
  24984. #ifdef WOLFSSL_SMALL_STACK
  24985. if (ret == 0) {
  24986. pubKey = (byte *)XMALLOC(pubKeySz, HEAP_HINT,
  24987. DYNAMIC_TYPE_TMP_BUFFER);
  24988. if (pubKey == NULL)
  24989. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  24990. }
  24991. #endif
  24992. /* generate the keys */
  24993. if (ret == 0) {
  24994. ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng);
  24995. if (ret != 0)
  24996. ret = WC_TEST_RET_ENC_EC(ret);
  24997. }
  24998. if (ret == 0) {
  24999. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng);
  25000. if (ret != 0)
  25001. ret = WC_TEST_RET_ENC_EC(ret);
  25002. }
  25003. /* seal */
  25004. if (ret == 0) {
  25005. ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey,
  25006. (byte*)info_text, (word32)XSTRLEN(info_text),
  25007. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25008. (byte*)start_text, (word32)XSTRLEN(start_text),
  25009. ciphertext);
  25010. if (ret != 0)
  25011. ret = WC_TEST_RET_ENC_EC(ret);
  25012. }
  25013. /* export ephemeral key */
  25014. if (ret == 0) {
  25015. ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz);
  25016. if (ret != 0)
  25017. ret = WC_TEST_RET_ENC_EC(ret);
  25018. }
  25019. /* open with exported ephemeral key */
  25020. if (ret == 0) {
  25021. ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz,
  25022. (byte*)info_text, (word32)XSTRLEN(info_text),
  25023. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25024. ciphertext, (word32)XSTRLEN(start_text),
  25025. plaintext);
  25026. if (ret != 0)
  25027. ret = WC_TEST_RET_ENC_EC(ret);
  25028. }
  25029. if (ret == 0) {
  25030. ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text));
  25031. if (ret != 0)
  25032. ret = WC_TEST_RET_ENC_NC;
  25033. }
  25034. /* Negative test case with NULL argument */
  25035. if (ret == 0) {
  25036. ret = wc_HpkeGenerateKeyPair(NULL, &receiverKey, rng);
  25037. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25038. ret = WC_TEST_RET_ENC_EC(ret);
  25039. else
  25040. ret = 0;
  25041. }
  25042. if (ret == 0) {
  25043. ret = wc_HpkeGenerateKeyPair(hpke, NULL, rng);
  25044. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25045. ret = WC_TEST_RET_ENC_EC(ret);
  25046. else
  25047. ret = 0;
  25048. }
  25049. if (ret == 0) {
  25050. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, NULL);
  25051. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25052. ret = WC_TEST_RET_ENC_EC(ret);
  25053. else
  25054. ret = 0;
  25055. }
  25056. if (ephemeralKey != NULL)
  25057. wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
  25058. if (receiverKey != NULL)
  25059. wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
  25060. #ifdef WOLFSSL_SMALL_STACK
  25061. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25062. #endif
  25063. if (rngRet == 0)
  25064. wc_FreeRng(rng);
  25065. return ret;
  25066. }
  25067. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void)
  25068. {
  25069. wc_test_ret_t ret = 0;
  25070. Hpke hpke[1];
  25071. WOLFSSL_ENTER("hpke_test");
  25072. #if defined(HAVE_ECC)
  25073. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
  25074. /* p256 */
  25075. ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256,
  25076. HPKE_AES_128_GCM, NULL);
  25077. if (ret != 0)
  25078. return WC_TEST_RET_ENC_EC(ret);
  25079. ret = hpke_test_single(hpke);
  25080. if (ret != 0)
  25081. return ret;
  25082. #endif
  25083. #if defined(WOLFSSL_SHA384) && \
  25084. (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  25085. /* p384 */
  25086. ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384,
  25087. HPKE_AES_128_GCM, NULL);
  25088. if (ret != 0)
  25089. return WC_TEST_RET_ENC_EC(ret);
  25090. ret = hpke_test_single(hpke);
  25091. if (ret != 0)
  25092. return ret;
  25093. #endif
  25094. #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \
  25095. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25096. /* p521 */
  25097. ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512,
  25098. HPKE_AES_128_GCM, NULL);
  25099. if (ret != 0)
  25100. return WC_TEST_RET_ENC_EC(ret);
  25101. ret = hpke_test_single(hpke);
  25102. if (ret != 0)
  25103. return ret;
  25104. #endif
  25105. #endif
  25106. #if defined(HAVE_CURVE25519)
  25107. /* test with curve25519 and aes256 */
  25108. ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256,
  25109. HPKE_AES_256_GCM, NULL);
  25110. if (ret != 0)
  25111. return WC_TEST_RET_ENC_EC(ret);
  25112. ret = hpke_test_single(hpke);
  25113. if (ret != 0)
  25114. return ret;
  25115. #endif
  25116. #if defined(HAVE_CURVE448) && \
  25117. (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512))
  25118. /* test with curve448 and aes256 */
  25119. ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512,
  25120. HPKE_AES_256_GCM, NULL);
  25121. /* HPKE does not support X448 yet, so expect failure */
  25122. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25123. return WC_TEST_RET_ENC_EC(ret);
  25124. ret = hpke_test_single(hpke);
  25125. /* HPKE does not support X448 yet, so expect failure */
  25126. if (WC_TEST_RET_DEC_EC(ret) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25127. return ret;
  25128. ret = 0; /* reset error code */
  25129. #endif
  25130. /* TODO: HPKE chacha20 is not implemented */
  25131. return ret;
  25132. }
  25133. #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */
  25134. #if defined(WC_SRTP_KDF)
  25135. typedef struct Srtp_Kdf_Tv {
  25136. const unsigned char* key;
  25137. word32 keySz;
  25138. const unsigned char* salt;
  25139. word32 saltSz;
  25140. int kdfIdx;
  25141. const unsigned char* index;
  25142. const unsigned char* ke;
  25143. const unsigned char* ka;
  25144. const unsigned char* ks;
  25145. const unsigned char* index_c;
  25146. const unsigned char* ke_c;
  25147. const unsigned char* ka_c;
  25148. const unsigned char* ks_c;
  25149. word32 keSz;
  25150. word32 kaSz;
  25151. word32 ksSz;
  25152. } Srtp_Kdf_Tv;
  25153. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
  25154. {
  25155. wc_test_ret_t ret = 0;
  25156. /* 128-bit key, kdrIdx = -1 */
  25157. WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = {
  25158. 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72,
  25159. 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90
  25160. };
  25161. WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = {
  25162. 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56,
  25163. 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6
  25164. };
  25165. WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = {
  25166. 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca
  25167. };
  25168. WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = {
  25169. 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a,
  25170. 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f
  25171. };
  25172. WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = {
  25173. 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee,
  25174. 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3,
  25175. 0xbd, 0x32, 0x6e, 0xe4
  25176. };
  25177. WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = {
  25178. 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6,
  25179. 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c
  25180. };
  25181. WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = {
  25182. 0x56, 0xf3, 0xf1, 0x97
  25183. };
  25184. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = {
  25185. 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf,
  25186. 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38
  25187. };
  25188. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = {
  25189. 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba,
  25190. 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7,
  25191. 0xc3, 0xd8, 0x77, 0x0e
  25192. };
  25193. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = {
  25194. 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96,
  25195. 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8
  25196. };
  25197. /* 192-bit key, kdrIdx = 0 */
  25198. WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = {
  25199. 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c,
  25200. 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70,
  25201. 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2
  25202. };
  25203. WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = {
  25204. 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6,
  25205. 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52
  25206. };
  25207. WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = {
  25208. 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76
  25209. };
  25210. WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = {
  25211. 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3,
  25212. 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93,
  25213. 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60
  25214. };
  25215. WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = {
  25216. 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d,
  25217. 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78,
  25218. 0xd1, 0xd1, 0x47, 0x08
  25219. };
  25220. WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = {
  25221. 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe,
  25222. 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea
  25223. };
  25224. WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = {
  25225. 0x40, 0xbf, 0xd4, 0xa9
  25226. };
  25227. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = {
  25228. 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65,
  25229. 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11,
  25230. 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84
  25231. };
  25232. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = {
  25233. 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef,
  25234. 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2,
  25235. 0xf3, 0x3b, 0x8e, 0x29
  25236. };
  25237. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = {
  25238. 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4,
  25239. 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0
  25240. };
  25241. /* 256-bit key, kdrIdx = 1 */
  25242. WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = {
  25243. 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee,
  25244. 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02,
  25245. 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50,
  25246. 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb
  25247. };
  25248. WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = {
  25249. 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74,
  25250. 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a
  25251. };
  25252. WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = {
  25253. 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42
  25254. };
  25255. WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = {
  25256. 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98,
  25257. 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f,
  25258. 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb,
  25259. 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb
  25260. };
  25261. WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = {
  25262. 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84,
  25263. 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57,
  25264. 0x65, 0xc7, 0x50, 0xc1
  25265. };
  25266. WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = {
  25267. 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c,
  25268. 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a
  25269. };
  25270. WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = {
  25271. 0x31, 0x2d, 0x58, 0x15
  25272. };
  25273. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = {
  25274. 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1,
  25275. 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4,
  25276. 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa,
  25277. 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd
  25278. };
  25279. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = {
  25280. 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13,
  25281. 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6,
  25282. 0x35, 0x78, 0xdf, 0xa4
  25283. };
  25284. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = {
  25285. 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f,
  25286. 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff
  25287. };
  25288. /* 128-bit key, kdrIdx = 8 */
  25289. WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = {
  25290. 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76,
  25291. 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04
  25292. };
  25293. WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = {
  25294. 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3,
  25295. 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76
  25296. };
  25297. WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = {
  25298. 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60
  25299. };
  25300. WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = {
  25301. 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2,
  25302. 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74
  25303. };
  25304. WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = {
  25305. 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6,
  25306. 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66,
  25307. 0xea, 0x31, 0x24, 0xe6
  25308. };
  25309. WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = {
  25310. 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a,
  25311. 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f
  25312. };
  25313. WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = {
  25314. 0x4a, 0x7d, 0xaa, 0x85
  25315. };
  25316. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = {
  25317. 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c,
  25318. 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88
  25319. };
  25320. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = {
  25321. 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13,
  25322. 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17,
  25323. 0x05, 0x18, 0xe3, 0xed
  25324. };
  25325. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = {
  25326. 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46,
  25327. 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6
  25328. };
  25329. /* SRTCP w/ 48-bit idx - KDR 0 (-1) */
  25330. WOLFSSL_SMALL_STACK_STATIC const byte mk48_1[] = {
  25331. 0xFF, 0xB6, 0xCB, 0x09, 0x71, 0x3F, 0x63, 0x4D,
  25332. 0x7F, 0x42, 0xED, 0xA8, 0x12, 0x81, 0x50, 0xE6
  25333. };
  25334. WOLFSSL_SMALL_STACK_STATIC const byte ms48_1[] = {
  25335. 0x1F, 0x04, 0x76, 0xC8, 0x7F, 0x58, 0x23, 0xEF,
  25336. 0xD3, 0x57, 0xB2, 0xBD, 0xF1, 0x32
  25337. };
  25338. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_1[] = {
  25339. 0x00, 0x00, 0x08, 0x56, 0xBC, 0x39
  25340. };
  25341. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_1[] = {
  25342. 0xD2, 0xC3, 0xF3, 0x49, 0x00, 0x1A, 0x18, 0x0F,
  25343. 0xB6, 0x05, 0x5A, 0x5A, 0x67, 0x8E, 0xE5, 0xB2
  25344. };
  25345. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_1[] = {
  25346. 0x8D, 0x54, 0xBE, 0xB5, 0x7B, 0x7F, 0x7A, 0xAB,
  25347. 0xF5, 0x46, 0xCE, 0x5B, 0x45, 0x69, 0x4A, 0x75,
  25348. 0x81, 0x2A, 0xE2, 0xCB
  25349. };
  25350. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_1[] = {
  25351. 0x76, 0x3C, 0x97, 0x6A, 0x45, 0x31, 0xA7, 0x79,
  25352. 0x3C, 0x28, 0x4A, 0xA6, 0x82, 0x03
  25353. };
  25354. /* SRTCP w/ 48-bit idx - KDR 19 */
  25355. WOLFSSL_SMALL_STACK_STATIC const byte mk48_2[] = {
  25356. 0xBD, 0x1D, 0x71, 0x6B, 0xDA, 0x28, 0xE3, 0xFC,
  25357. 0xA5, 0xA0, 0x66, 0x3F, 0x2E, 0x34, 0xA8, 0x58
  25358. };
  25359. WOLFSSL_SMALL_STACK_STATIC const byte ms48_2[] = {
  25360. 0x79, 0x06, 0xE5, 0xAB, 0x5C, 0x2B, 0x1B, 0x69,
  25361. 0xFA, 0xEE, 0xD2, 0x29, 0x57, 0x3C
  25362. };
  25363. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_2[] = {
  25364. 0x00, 0x00, 0x59, 0xD0, 0xC2, 0xE8
  25365. };
  25366. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_2[] = {
  25367. 0xB9, 0xD7, 0xAD, 0xD8, 0x90, 0x94, 0xC2, 0x92,
  25368. 0xA5, 0x04, 0x87, 0xC4, 0x8C, 0xEF, 0xE2, 0xA3
  25369. };
  25370. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_2[] = {
  25371. 0x07, 0xD5, 0xC4, 0xD2, 0x06, 0xFB, 0x63, 0x15,
  25372. 0xC2, 0x9C, 0x7F, 0x55, 0xD1, 0x16, 0x5C, 0xB5,
  25373. 0xB7, 0x44, 0x54, 0xBD
  25374. };
  25375. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_2[] = {
  25376. 0x0C, 0x5E, 0x53, 0xC1, 0xD0, 0x75, 0xAD, 0x65,
  25377. 0xBF, 0x51, 0x74, 0x50, 0x89, 0xD7
  25378. };
  25379. int kdr_48_1 = -1;
  25380. int kdr_48_2 = 19;
  25381. #define SRTP_TV_CNT 4
  25382. Srtp_Kdf_Tv tv[SRTP_TV_CNT] = {
  25383. { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1,
  25384. index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0,
  25385. 16, 20, 14 },
  25386. { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0,
  25387. index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1,
  25388. 24, 20, 14 },
  25389. { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1,
  25390. index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2,
  25391. 32, 20, 14 },
  25392. { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8,
  25393. index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3,
  25394. 16, 20, 14 },
  25395. };
  25396. int i;
  25397. int idx;
  25398. unsigned char keyE[32];
  25399. unsigned char keyA[20];
  25400. unsigned char keyS[14];
  25401. WOLFSSL_ENTER("srtpkdf_test");
  25402. for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) {
  25403. #ifndef WOLFSSL_AES_128
  25404. if (tv[i].keySz == AES_128_KEY_SIZE) {
  25405. continue;
  25406. }
  25407. #endif
  25408. #ifndef WOLFSSL_AES_192
  25409. if (tv[i].keySz == AES_192_KEY_SIZE) {
  25410. continue;
  25411. }
  25412. #endif
  25413. #ifndef WOLFSSL_AES_256
  25414. if (tv[i].keySz == AES_256_KEY_SIZE) {
  25415. continue;
  25416. }
  25417. #endif
  25418. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25419. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25420. keyS, tv[i].ksSz);
  25421. if (ret != 0)
  25422. return WC_TEST_RET_ENC_EC(ret);
  25423. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25424. return WC_TEST_RET_ENC_NC;
  25425. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25426. return WC_TEST_RET_ENC_NC;
  25427. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25428. return WC_TEST_RET_ENC_NC;
  25429. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25430. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION,
  25431. keyE, tv[i].keSz);
  25432. if (ret != 0)
  25433. return WC_TEST_RET_ENC_EC(ret);
  25434. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25435. return WC_TEST_RET_ENC_NC;
  25436. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25437. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH,
  25438. keyA, tv[i].kaSz);
  25439. if (ret != 0)
  25440. return WC_TEST_RET_ENC_EC(ret);
  25441. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25442. return WC_TEST_RET_ENC_NC;
  25443. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25444. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS,
  25445. tv[i].ksSz);
  25446. if (ret != 0)
  25447. return WC_TEST_RET_ENC_EC(ret);
  25448. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25449. return WC_TEST_RET_ENC_NC;
  25450. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25451. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25452. keyS, tv[i].ksSz);
  25453. if (ret != 0)
  25454. return WC_TEST_RET_ENC_EC(ret);
  25455. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25456. return WC_TEST_RET_ENC_NC;
  25457. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25458. return WC_TEST_RET_ENC_NC;
  25459. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25460. return WC_TEST_RET_ENC_NC;
  25461. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25462. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c,
  25463. WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz);
  25464. if (ret != 0)
  25465. return WC_TEST_RET_ENC_EC(ret);
  25466. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25467. return WC_TEST_RET_ENC_NC;
  25468. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25469. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH,
  25470. keyA, tv[i].kaSz);
  25471. if (ret != 0)
  25472. return WC_TEST_RET_ENC_EC(ret);
  25473. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25474. return WC_TEST_RET_ENC_NC;
  25475. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25476. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
  25477. keyS, tv[i].ksSz);
  25478. if (ret != 0)
  25479. return WC_TEST_RET_ENC_EC(ret);
  25480. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25481. return WC_TEST_RET_ENC_NC;
  25482. }
  25483. #ifdef WOLFSSL_AES_128
  25484. i = 0;
  25485. #elif defined(WOLFSSL_AES_192)
  25486. i = 1;
  25487. #else
  25488. i = 2;
  25489. #endif
  25490. ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25491. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25492. keyS, tv[i].ksSz);
  25493. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25494. return WC_TEST_RET_ENC_EC(ret);
  25495. ret = wc_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25496. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25497. keyS, tv[i].ksSz);
  25498. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25499. return WC_TEST_RET_ENC_EC(ret);
  25500. ret = wc_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25501. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25502. keyS, tv[i].ksSz);
  25503. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25504. return WC_TEST_RET_ENC_EC(ret);
  25505. ret = wc_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25506. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25507. keyS, tv[i].ksSz);
  25508. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25509. return WC_TEST_RET_ENC_EC(ret);
  25510. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25511. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25512. keyS, tv[i].ksSz);
  25513. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25514. return WC_TEST_RET_ENC_EC(ret);
  25515. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25516. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25517. keyS, tv[i].ksSz);
  25518. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25519. return WC_TEST_RET_ENC_EC(ret);
  25520. ret = wc_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25521. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25522. keyS, tv[i].ksSz);
  25523. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25524. return WC_TEST_RET_ENC_EC(ret);
  25525. ret = wc_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25526. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25527. keyS, tv[i].ksSz);
  25528. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25529. return WC_TEST_RET_ENC_EC(ret);
  25530. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25531. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25532. keyS, tv[i].ksSz);
  25533. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25534. return WC_TEST_RET_ENC_EC(ret);
  25535. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25536. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25537. keyS, tv[i].ksSz);
  25538. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25539. return WC_TEST_RET_ENC_EC(ret);
  25540. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25541. 25, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25542. keyS, tv[i].ksSz);
  25543. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25544. return WC_TEST_RET_ENC_EC(ret);
  25545. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25546. 25, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25547. keyS, tv[i].ksSz);
  25548. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25549. return WC_TEST_RET_ENC_EC(ret);
  25550. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25551. -2, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25552. keyS, tv[i].ksSz);
  25553. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25554. return WC_TEST_RET_ENC_EC(ret);
  25555. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25556. -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25557. keyS, tv[i].ksSz);
  25558. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25559. return WC_TEST_RET_ENC_EC(ret);
  25560. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25561. tv[i].kdfIdx, tv[i].index, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25562. keyS, tv[i].ksSz);
  25563. if (ret != 0)
  25564. return WC_TEST_RET_ENC_EC(ret);
  25565. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25566. tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25567. keyS, tv[i].ksSz);
  25568. if (ret != 0)
  25569. return WC_TEST_RET_ENC_EC(ret);
  25570. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25571. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25572. keyS, tv[i].ksSz);
  25573. if (ret != 0)
  25574. return WC_TEST_RET_ENC_EC(ret);
  25575. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25576. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25577. keyS, tv[i].ksSz);
  25578. if (ret != 0)
  25579. return WC_TEST_RET_ENC_EC(ret);
  25580. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25581. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25582. NULL, tv[i].ksSz);
  25583. if (ret != 0)
  25584. return WC_TEST_RET_ENC_EC(ret);
  25585. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25586. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25587. NULL, tv[i].ksSz);
  25588. if (ret != 0)
  25589. return WC_TEST_RET_ENC_EC(ret);
  25590. idx = wc_SRTP_KDF_kdr_to_idx(0);
  25591. if (idx != -1)
  25592. return WC_TEST_RET_ENC_NC;
  25593. for (i = 0; i < 32; i++) {
  25594. word32 kdr = 1U << i;
  25595. /* SRTCP w/ 48-bit IDX, 128-bit key test */
  25596. if (i == 0) {
  25597. ret = wc_SRTCP_KDF_ex(mk48_1, (word32)sizeof(mk48_1),
  25598. ms48_1, (word32)sizeof(ms48_1),
  25599. kdr_48_1, srtcp48idx_1, keyE, tv[i].keSz,
  25600. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25601. WC_SRTCP_48BIT_IDX);
  25602. if (ret != 0)
  25603. return WC_TEST_RET_ENC_EC(ret);
  25604. if (XMEMCMP(keyE, srtcpKe_48_1, tv[i].keSz) != 0)
  25605. return WC_TEST_RET_ENC_NC;
  25606. if (XMEMCMP(keyA, srtcpKa_48_1, tv[i].kaSz) != 0)
  25607. return WC_TEST_RET_ENC_NC;
  25608. if (XMEMCMP(keyS, srtcpKs_48_1, tv[i].ksSz) != 0)
  25609. return WC_TEST_RET_ENC_NC;
  25610. ret = wc_SRTCP_KDF_ex(mk48_2, (word32)sizeof(mk48_2),
  25611. ms48_2, (word32)sizeof(ms48_2),
  25612. kdr_48_2, srtcp48idx_2, keyE, tv[i].keSz,
  25613. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25614. WC_SRTCP_48BIT_IDX);
  25615. if (ret != 0)
  25616. return WC_TEST_RET_ENC_EC(ret);
  25617. if (XMEMCMP(keyE, srtcpKe_48_2, tv[i].keSz) != 0)
  25618. return WC_TEST_RET_ENC_NC;
  25619. if (XMEMCMP(keyA, srtcpKa_48_2, tv[i].kaSz) != 0)
  25620. return WC_TEST_RET_ENC_NC;
  25621. if (XMEMCMP(keyS, srtcpKs_48_2, tv[i].ksSz) != 0)
  25622. return WC_TEST_RET_ENC_NC;
  25623. }
  25624. idx = wc_SRTP_KDF_kdr_to_idx(kdr);
  25625. if (idx != i)
  25626. return WC_TEST_RET_ENC_NC;
  25627. }
  25628. return 0;
  25629. }
  25630. #endif
  25631. #ifdef HAVE_ECC
  25632. /* size to use for ECC key gen tests */
  25633. #ifndef ECC_KEYGEN_SIZE
  25634. #if !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  25635. #define ECC_KEYGEN_SIZE 32
  25636. #elif defined(HAVE_ECC384)
  25637. #define ECC_KEYGEN_SIZE 48
  25638. #elif defined(HAVE_ECC224)
  25639. #define ECC_KEYGEN_SIZE 28
  25640. #elif defined(HAVE_ECC521)
  25641. #define ECC_KEYGEN_SIZE 66
  25642. #else
  25643. #error No ECC keygen size defined for test
  25644. #endif
  25645. #endif
  25646. #ifdef BENCH_EMBEDDED
  25647. #define ECC_SHARED_SIZE 128
  25648. #else
  25649. #define ECC_SHARED_SIZE MAX_ECC_BYTES
  25650. #endif
  25651. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  25652. #define HAVE_ECC_DETERMINISTIC_K
  25653. #define ECC_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  25654. #else
  25655. #define ECC_DIGEST_SIZE MAX_ECC_BYTES
  25656. #endif
  25657. #define ECC_SIG_SIZE ECC_MAX_SIG_SIZE
  25658. #ifdef NO_ECC_SECP
  25659. #define NO_ECC_VECTOR_TEST
  25660. #endif
  25661. #ifndef NO_ECC_VECTOR_TEST
  25662. #if (defined(HAVE_ECC192) || defined(HAVE_ECC224) ||\
  25663. !defined(NO_ECC256) || defined(HAVE_ECC384) ||\
  25664. defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25665. #define HAVE_ECC_VECTOR_TEST
  25666. #endif
  25667. #endif
  25668. #ifdef HAVE_ECC_VECTOR_TEST
  25669. typedef struct eccVector {
  25670. const char* msg; /* SHA-1 Encoded Message */
  25671. const char* Qx;
  25672. const char* Qy;
  25673. const char* d; /* Private Key */
  25674. const char* R;
  25675. const char* S;
  25676. const char* curveName;
  25677. word32 msgLen;
  25678. word32 keySize;
  25679. const byte* r;
  25680. word32 rSz;
  25681. const byte* s;
  25682. word32 sSz;
  25683. } eccVector;
  25684. #if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  25685. static wc_test_ret_t ecc_test_vector_item(const eccVector* vector)
  25686. {
  25687. wc_test_ret_t ret = 0;
  25688. int verify = 0;
  25689. word32 sigSz;
  25690. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25691. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25692. #else
  25693. ecc_key userA[1];
  25694. #endif
  25695. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25696. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25697. word32 sigRawSz, rSz = MAX_ECC_BYTES, sSz = MAX_ECC_BYTES;
  25698. WC_DECLARE_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25699. WC_DECLARE_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25700. WC_DECLARE_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25701. #endif
  25702. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25703. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25704. WC_ALLOC_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25705. WC_ALLOC_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25706. WC_ALLOC_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25707. #endif
  25708. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  25709. if (sig == NULL)
  25710. ERROR_OUT(MEMORY_E, done);
  25711. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25712. if (sigRaw == NULL || r == NULL || s == NULL)
  25713. ERROR_OUT(MEMORY_E, done);
  25714. #endif
  25715. #endif
  25716. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25717. if (userA == NULL)
  25718. ERROR_OUT(MEMORY_E, done);
  25719. #endif
  25720. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  25721. if (ret != 0)
  25722. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25723. ret = wc_ecc_import_raw(userA, vector->Qx, vector->Qy,
  25724. vector->d, vector->curveName);
  25725. if (ret != 0)
  25726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25727. #if !defined(NO_ASN)
  25728. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25729. sigSz = ECC_SIG_SIZE;
  25730. ret = wc_ecc_rs_to_sig(vector->R, vector->S, sig, &sigSz);
  25731. if (ret != 0)
  25732. goto done;
  25733. #if !defined(HAVE_SELFTEST)
  25734. XMEMSET(sigRaw, 0, ECC_SIG_SIZE);
  25735. sigRawSz = ECC_SIG_SIZE;
  25736. ret = wc_ecc_rs_raw_to_sig(vector->r, vector->rSz, vector->s, vector->sSz,
  25737. sigRaw, &sigRawSz);
  25738. if (ret != 0)
  25739. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25740. if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) {
  25741. ret = WC_TEST_RET_ENC_NC;
  25742. goto done;
  25743. }
  25744. ret = wc_ecc_sig_to_rs(sig, sigSz, r, &rSz, s, &sSz);
  25745. if (ret != 0)
  25746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25747. if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 ||
  25748. sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) {
  25749. ret = WC_TEST_RET_ENC_NC;
  25750. goto done;
  25751. }
  25752. #endif /* !HAVE_SELFTEST */
  25753. #else
  25754. /* Signature will be R+S directly */
  25755. /* Make sure and zero pad if r or s is less than key size */
  25756. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25757. sigSz = vector->keySize * 2;
  25758. XMEMCPY(sig + (vector->keySize - vector->rSz),
  25759. vector->r, vector->rSz);
  25760. XMEMCPY(sig + vector->keySize + (vector->keySize - vector->sSz),
  25761. vector->s, vector->sSz);
  25762. #endif /* !NO_ASN */
  25763. #ifdef HAVE_ECC_VERIFY
  25764. do {
  25765. #if defined(WOLFSSL_ASYNC_CRYPT)
  25766. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25767. #endif
  25768. if (ret == 0)
  25769. ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg,
  25770. vector->msgLen, &verify, userA);
  25771. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25772. if (ret != 0)
  25773. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25774. TEST_SLEEP();
  25775. if (verify != 1)
  25776. ret = WC_TEST_RET_ENC_NC;
  25777. #endif
  25778. done:
  25779. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25780. if (userA != NULL) {
  25781. wc_ecc_free(userA);
  25782. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25783. }
  25784. #else
  25785. wc_ecc_free(userA);
  25786. #endif
  25787. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25788. WC_FREE_VAR(sigRaw, HEAP_HINT);
  25789. WC_FREE_VAR(r, HEAP_HINT);
  25790. WC_FREE_VAR(s, HEAP_HINT);
  25791. #endif
  25792. WC_FREE_VAR(sig, HEAP_HINT);
  25793. return ret;
  25794. }
  25795. static wc_test_ret_t ecc_test_vector(int keySize)
  25796. {
  25797. wc_test_ret_t ret;
  25798. eccVector vec;
  25799. XMEMSET(&vec, 0, sizeof(vec));
  25800. vec.keySize = (word32)keySize;
  25801. switch(keySize) {
  25802. #if defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)
  25803. case 14:
  25804. return 0;
  25805. #endif /* HAVE_ECC112 */
  25806. #if defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)
  25807. case 16:
  25808. return 0;
  25809. #endif /* HAVE_ECC128 */
  25810. #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)
  25811. case 20:
  25812. return 0;
  25813. #endif /* HAVE_ECC160 */
  25814. #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
  25815. case 24:
  25816. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  25817. #if 1
  25818. vec.msg = "\x60\x80\x79\x42\x3f\x12\x42\x1d\xe6\x16\xb7\x49\x3e\xbe\x55\x1c\xf4\xd6\x5b\x92";
  25819. vec.msgLen = 20;
  25820. #else
  25821. /* This is the raw message prior to SHA-1 */
  25822. vec.msg =
  25823. "\xeb\xf7\x48\xd7\x48\xeb\xbc\xa7\xd2\x9f\xb4\x73\x69\x8a\x6e\x6b"
  25824. "\x4f\xb1\x0c\x86\x5d\x4a\xf0\x24\xcc\x39\xae\x3d\xf3\x46\x4b\xa4"
  25825. "\xf1\xd6\xd4\x0f\x32\xbf\x96\x18\xa9\x1b\xb5\x98\x6f\xa1\xa2\xaf"
  25826. "\x04\x8a\x0e\x14\xdc\x51\xe5\x26\x7e\xb0\x5e\x12\x7d\x68\x9d\x0a"
  25827. "\xc6\xf1\xa7\xf1\x56\xce\x06\x63\x16\xb9\x71\xcc\x7a\x11\xd0\xfd"
  25828. "\x7a\x20\x93\xe2\x7c\xf2\xd0\x87\x27\xa4\xe6\x74\x8c\xc3\x2f\xd5"
  25829. "\x9c\x78\x10\xc5\xb9\x01\x9d\xf2\x1c\xdc\xc0\xbc\xa4\x32\xc0\xa3"
  25830. "\xee\xd0\x78\x53\x87\x50\x88\x77\x11\x43\x59\xce\xe4\xa0\x71\xcf";
  25831. vec.msgLen = 128;
  25832. #endif
  25833. vec.Qx = "07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6";
  25834. vec.Qy = "76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477";
  25835. vec.d = "e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3";
  25836. vec.R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  25837. vec.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  25838. vec.curveName = "SECP192R1";
  25839. vec.r = (byte*)"\x69\x94\xd9\x62\xbd\xd0\xd7\x93\xff\xdd\xf8\x55"
  25840. "\xec\x5b\xf2\xf9\x1a\x96\x98\xb4\x62\x58\xa6\x3e";
  25841. vec.rSz = 24;
  25842. vec.s = (byte*)"\x02\xba\x64\x65\xa2\x34\x90\x37\x44\xab\x02\xbc"
  25843. "\x85\x21\x40\x5b\x73\xcf\x5f\xc0\x0e\x1a\x9f\x41";
  25844. vec.sSz = 24;
  25845. break;
  25846. #endif /* HAVE_ECC192 */
  25847. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  25848. case 28:
  25849. /* first [P-224,SHA-1] vector from FIPS 186-3 NIST vectors */
  25850. #if 1
  25851. vec.msg = "\xb9\xa3\xb8\x6d\xb0\xba\x99\xfd\xc6\xd2\x94\x6b\xfe\xbe\x9c\xe8\x3f\x10\x74\xfc";
  25852. vec.msgLen = 20;
  25853. #else
  25854. /* This is the raw message prior to SHA-1 */
  25855. vec.msg =
  25856. "\x36\xc8\xb2\x29\x86\x48\x7f\x67\x7c\x18\xd0\x97\x2a\x9e\x20\x47"
  25857. "\xb3\xaf\xa5\x9e\xc1\x62\x76\x4e\xc3\x0b\x5b\x69\xe0\x63\x0f\x99"
  25858. "\x0d\x4e\x05\xc2\x73\xb0\xe5\xa9\xd4\x28\x27\xb6\x95\xfc\x2d\x64"
  25859. "\xd9\x13\x8b\x1c\xf4\xc1\x21\x55\x89\x4c\x42\x13\x21\xa7\xbb\x97"
  25860. "\x0b\xdc\xe0\xfb\xf0\xd2\xae\x85\x61\xaa\xd8\x71\x7f\x2e\x46\xdf"
  25861. "\xe3\xff\x8d\xea\xb4\xd7\x93\x23\x56\x03\x2c\x15\x13\x0d\x59\x9e"
  25862. "\x26\xc1\x0f\x2f\xec\x96\x30\x31\xac\x69\x38\xa1\x8d\x66\x45\x38"
  25863. "\xb9\x4d\xac\x55\x34\xef\x7b\x59\x94\x24\xd6\x9b\xe1\xf7\x1c\x20";
  25864. vec.msgLen = 128;
  25865. #endif
  25866. vec.Qx = "8a4dca35136c4b70e588e23554637ae251077d1365a6ba5db9585de7";
  25867. vec.Qy = "ad3dee06de0be8279d4af435d7245f14f3b4f82eb578e519ee0057b1";
  25868. vec.d = "97c4b796e1639dd1035b708fc00dc7ba1682cec44a1002a1a820619f";
  25869. vec.R = "147b33758321e722a0360a4719738af848449e2c1d08defebc1671a7";
  25870. vec.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b";
  25871. vec.curveName = "SECP224R1";
  25872. vec.r = (byte*)"\x14\x7b\x33\x75\x83\x21\xe7\x22\xa0\x36\x0a\x47"
  25873. "\x19\x73\x8a\xf8\x48\x44\x9e\x2c\x1d\x08\xde\xfe"
  25874. "\xbc\x16\x71\xa7";
  25875. vec.rSz = 28;
  25876. vec.s = (byte*)"\x24\xfc\x7e\xd7\xf1\x35\x2c\xa3\x87\x2a\xa0\x91"
  25877. "\x61\x91\x28\x9e\x2e\x04\xd4\x54\x93\x5d\x50\xfe"
  25878. "\x6a\xf3\xad\x5b";
  25879. vec.sSz = 28;
  25880. break;
  25881. #endif /* HAVE_ECC224 */
  25882. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  25883. case 30:
  25884. return 0;
  25885. #endif /* HAVE_ECC239 */
  25886. #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
  25887. case 32:
  25888. /* first [P-256,SHA-1] vector from FIPS 186-3 NIST vectors */
  25889. #if 1
  25890. vec.msg = "\xa3\xf9\x1a\xe2\x1b\xa6\xb3\x03\x98\x64\x47\x2f\x18\x41\x44\xc6\xaf\x62\xcd\x0e";
  25891. vec.msgLen = 20;
  25892. #else
  25893. /* This is the raw message prior to SHA-1 */
  25894. vec.msg =
  25895. "\xa2\x4b\x21\x76\x2e\x6e\xdb\x15\x3c\xc1\x14\x38\xdb\x0e\x92\xcd"
  25896. "\xf5\x2b\x86\xb0\x6c\xa9\x70\x16\x06\x27\x59\xc7\x0d\x36\xd1\x56"
  25897. "\x2c\xc9\x63\x0d\x7f\xc7\xc7\x74\xb2\x8b\x54\xe3\x1e\xf5\x58\x72"
  25898. "\xb2\xa6\x5d\xf1\xd7\xec\x26\xde\xbb\x33\xe7\xd9\x27\xef\xcc\xf4"
  25899. "\x6b\x63\xde\x52\xa4\xf4\x31\xea\xca\x59\xb0\x5d\x2e\xde\xc4\x84"
  25900. "\x5f\xff\xc0\xee\x15\x03\x94\xd6\x1f\x3d\xfe\xcb\xcd\xbf\x6f\x5a"
  25901. "\x73\x38\xd0\xbe\x3f\x2a\x77\x34\x51\x98\x3e\xba\xeb\x48\xf6\x73"
  25902. "\x8f\xc8\x95\xdf\x35\x7e\x1a\x48\xa6\x53\xbb\x35\x5a\x31\xa1\xb4"
  25903. vec.msgLen = 128;
  25904. #endif
  25905. vec.Qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  25906. vec.Qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  25907. vec.d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  25908. vec.R = "2b826f5d44e2d0b6de531ad96b51e8f0c56fdfead3c236892e4d84eacfc3b75c";
  25909. vec.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248";
  25910. vec.r = (byte*)"\x2b\x82\x6f\x5d\x44\xe2\xd0\xb6\xde\x53\x1a\xd9"
  25911. "\x6b\x51\xe8\xf0\xc5\x6f\xdf\xea\xd3\xc2\x36\x89"
  25912. "\x2e\x4d\x84\xea\xcf\xc3\xb7\x5c";
  25913. vec.rSz = 32;
  25914. vec.s = (byte*)"\xa2\x24\x8b\x62\xc0\x3d\xb3\x5a\x7c\xd6\x3e\x8a"
  25915. "\x12\x0a\x35\x21\xa8\x9d\x3d\x2f\x61\xff\x99\x03"
  25916. "\x5a\x21\x48\xae\x32\xe3\xa2\x48";
  25917. vec.sSz = 32;
  25918. vec.curveName = "SECP256R1";
  25919. break;
  25920. #endif /* !NO_ECC256 */
  25921. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  25922. case 40:
  25923. return 0;
  25924. #endif /* HAVE_ECC320 */
  25925. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  25926. case 48:
  25927. /* first [P-384,SHA-1] vector from FIPS 186-3 NIST vectors */
  25928. #if 1
  25929. vec.msg = "\x9b\x9f\x8c\x95\x35\xa5\xca\x26\x60\x5d\xb7\xf2\xfa\x57\x3b\xdf\xc3\x2e\xab\x8b";
  25930. vec.msgLen = 20;
  25931. #else
  25932. /* This is the raw message prior to SHA-1 */
  25933. vec.msg =
  25934. "\xab\xe1\x0a\xce\x13\xe7\xe1\xd9\x18\x6c\x48\xf7\x88\x9d\x51\x47"
  25935. "\x3d\x3a\x09\x61\x98\x4b\xc8\x72\xdf\x70\x8e\xcc\x3e\xd3\xb8\x16"
  25936. "\x9d\x01\xe3\xd9\x6f\xc4\xf1\xd5\xea\x00\xa0\x36\x92\xbc\xc5\xcf"
  25937. "\xfd\x53\x78\x7c\x88\xb9\x34\xaf\x40\x4c\x03\x9d\x32\x89\xb5\xba"
  25938. "\xc5\xae\x7d\xb1\x49\x68\x75\xb5\xdc\x73\xc3\x09\xf9\x25\xc1\x3d"
  25939. "\x1c\x01\xab\xda\xaf\xeb\xcd\xac\x2c\xee\x43\x39\x39\xce\x8d\x4a"
  25940. "\x0a\x5d\x57\xbb\x70\x5f\x3b\xf6\xec\x08\x47\x95\x11\xd4\xb4\xa3"
  25941. "\x21\x1f\x61\x64\x9a\xd6\x27\x43\x14\xbf\x0d\x43\x8a\x81\xe0\x60"
  25942. vec.msgLen = 128;
  25943. #endif
  25944. vec.Qx = "e55fee6c49d8d523f5ce7bf9c0425ce4ff650708b7de5cfb095901523979a7f042602db30854735369813b5c3f5ef868";
  25945. vec.Qy = "28f59cc5dc509892a988d38a8e2519de3d0c4fd0fbdb0993e38f18506c17606c5e24249246f1ce94983a5361c5be983e";
  25946. vec.d = "a492ce8fa90084c227e1a32f7974d39e9ff67a7e8705ec3419b35fb607582bebd461e0b1520ac76ec2dd4e9b63ebae71";
  25947. vec.R = "6820b8585204648aed63bdff47f6d9acebdea62944774a7d14f0e14aa0b9a5b99545b2daee6b3c74ebf606667a3f39b7";
  25948. vec.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907";
  25949. vec.curveName = "SECP384R1";
  25950. vec.r = (byte*)"\x68\x20\xb8\x58\x52\x04\x64\x8a\xed\x63\xbd\xff"
  25951. "\x47\xf6\xd9\xac\xeb\xde\xa6\x29\x44\x77\x4a\x7d"
  25952. "\x14\xf0\xe1\x4a\xa0\xb9\xa5\xb9\x95\x45\xb2\xda"
  25953. "\xee\x6b\x3c\x74\xeb\xf6\x06\x66\x7a\x3f\x39\xb7";
  25954. vec.rSz = 48;
  25955. vec.s = (byte*)"\x49\x1a\xf1\xd0\xcc\xcd\x56\xdd\xd5\x20\xb2\x33"
  25956. "\x77\x5d\x0b\xc6\xb4\x0a\x62\x55\xcc\x55\x20\x7d"
  25957. "\x8e\x93\x56\x74\x1f\x23\xc9\x6c\x14\x71\x42\x21"
  25958. "\x07\x8d\xbd\x5c\x17\xf4\xfd\xd8\x9b\x32\xa9\x07";
  25959. vec.sSz = 48;
  25960. break;
  25961. #endif /* HAVE_ECC384 */
  25962. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  25963. case 64:
  25964. return 0;
  25965. #endif /* HAVE_ECC512 */
  25966. #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  25967. case 66:
  25968. /* first [P-521,SHA-1] vector from FIPS 186-3 NIST vectors */
  25969. #if 1
  25970. vec.msg = "\x1b\xf7\x03\x9c\xca\x23\x94\x27\x3f\x11\xa1\xd4\x8d\xcc\xb4\x46\x6f\x31\x61\xdf";
  25971. vec.msgLen = 20;
  25972. #else
  25973. /* This is the raw message prior to SHA-1 */
  25974. vec.msg =
  25975. "\x50\x3f\x79\x39\x34\x0a\xc7\x23\xcd\x4a\x2f\x4e\x6c\xcc\x27\x33"
  25976. "\x38\x3a\xca\x2f\xba\x90\x02\x19\x9d\x9e\x1f\x94\x8b\xe0\x41\x21"
  25977. "\x07\xa3\xfd\xd5\x14\xd9\x0c\xd4\xf3\x7c\xc3\xac\x62\xef\x00\x3a"
  25978. "\x2d\xb1\xd9\x65\x7a\xb7\x7f\xe7\x55\xbf\x71\xfa\x59\xe4\xd9\x6e"
  25979. "\xa7\x2a\xe7\xbf\x9d\xe8\x7d\x79\x34\x3b\xc1\xa4\xbb\x14\x4d\x16"
  25980. "\x28\xd1\xe9\xe9\xc8\xed\x80\x8b\x96\x2c\x54\xe5\xf9\x6d\x53\xda"
  25981. "\x14\x7a\x96\x38\xf9\x4a\x91\x75\xd8\xed\x61\x05\x5f\x0b\xa5\x73"
  25982. "\xa8\x2b\xb7\xe0\x18\xee\xda\xc4\xea\x7b\x36\x2e\xc8\x9c\x38\x2b"
  25983. vec.msgLen = 128;
  25984. #endif
  25985. vec.Qx = "12fbcaeffa6a51f3ee4d3d2b51c5dec6d7c726ca353fc014ea2bf7cfbb9b910d32cbfa6a00fe39b6cdb8946f22775398b2e233c0cf144d78c8a7742b5c7a3bb5d23";
  25986. vec.Qy = "09cdef823dd7bf9a79e8cceacd2e4527c231d0ae5967af0958e931d7ddccf2805a3e618dc3039fec9febbd33052fe4c0fee98f033106064982d88f4e03549d4a64d";
  25987. vec.d = "1bd56bd106118eda246155bd43b42b8e13f0a6e25dd3bb376026fab4dc92b6157bc6dfec2d15dd3d0cf2a39aa68494042af48ba9601118da82c6f2108a3a203ad74";
  25988. vec.R = "0bd117b4807710898f9dd7778056485777668f0e78e6ddf5b000356121eb7a220e9493c7f9a57c077947f89ac45d5acb6661bbcd17abb3faea149ba0aa3bb1521be";
  25989. vec.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c";
  25990. vec.curveName = "SECP521R1";
  25991. vec.r = (byte*)"\xbd\x11\x7b\x48\x07\x71\x08\x98\xf9\xdd\x77\x78"
  25992. "\x05\x64\x85\x77\x76\x68\xf0\xe7\x8e\x6d\xdf\x5b"
  25993. "\x00\x03\x56\x12\x1e\xb7\xa2\x20\xe9\x49\x3c\x7f"
  25994. "\x9a\x57\xc0\x77\x94\x7f\x89\xac\x45\xd5\xac\xb6"
  25995. "\x66\x1b\xbc\xd1\x7a\xbb\x3f\xae\xa1\x49\xba\x0a"
  25996. "\xa3\xbb\x15\x21\xbe";
  25997. vec.rSz = 65;
  25998. vec.s = (byte*)"\x19\xcd\x2c\x5c\x3f\x98\x70\xec\xde\xb9\xb3\x23"
  25999. "\xab\xdf\x3a\x98\xcd\x5e\x23\x1d\x85\xc6\xdd\xc5"
  26000. "\xb7\x1a\xb1\x90\x73\x9f\x7f\x22\x6e\x6b\x13\x4b"
  26001. "\xa1\xd5\x88\x9d\xde\xb2\x75\x1d\xab\xd9\x79\x11"
  26002. "\xdf\xf9\x0c\x34\x68\x4c\xdb\xe7\xbb\x66\x9b\x6c"
  26003. "\x3d\x22\xf2\x48\x0c";
  26004. vec.sSz = 65;
  26005. break;
  26006. #endif /* HAVE_ECC521 */
  26007. default:
  26008. return WC_TEST_RET_ENC_EC(NOT_COMPILED_IN); /* Invalid key size /
  26009. * Not supported
  26010. */
  26011. }; /* Switch */
  26012. ret = ecc_test_vector_item(&vec);
  26013. if (ret < 0) {
  26014. return ret;
  26015. }
  26016. return 0;
  26017. }
  26018. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26019. #if defined(HAVE_ECC_SIGN) && \
  26020. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  26021. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  26022. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  26023. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  26024. static wc_test_ret_t ecdsa_test_deterministic_k_sig(ecc_key *key,
  26025. enum wc_HashType hashType, const char* msg, WC_RNG* rng, const byte* expSig,
  26026. size_t expSigSz)
  26027. {
  26028. wc_test_ret_t ret;
  26029. int verify;
  26030. byte sig[ECC_MAX_SIG_SIZE];
  26031. word32 sigSz;
  26032. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26033. ret = wc_Hash(hashType,
  26034. (byte*)msg, (word32)XSTRLEN(msg),
  26035. hash, sizeof(hash));
  26036. if (ret != 0)
  26037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26038. /* Sign test */
  26039. sigSz = sizeof(sig);
  26040. do {
  26041. #if defined(WOLFSSL_ASYNC_CRYPT)
  26042. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26043. #endif
  26044. if (ret == 0)
  26045. ret = wc_ecc_sign_hash(hash, wc_HashGetDigestSize(hashType),
  26046. sig, &sigSz, rng, key);
  26047. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26048. if (ret != 0)
  26049. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26050. TEST_SLEEP();
  26051. /* Compare test vector */
  26052. if (sigSz != expSigSz) {
  26053. ret = WC_TEST_RET_ENC_NC;
  26054. goto done;
  26055. }
  26056. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26057. ret = WC_TEST_RET_ENC_NC;
  26058. goto done;
  26059. }
  26060. /* Verification */
  26061. verify = 0;
  26062. do {
  26063. #if defined(WOLFSSL_ASYNC_CRYPT)
  26064. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26065. #endif
  26066. if (ret == 0)
  26067. ret = wc_ecc_verify_hash(sig, sigSz,
  26068. hash, wc_HashGetDigestSize(hashType), &verify, key);
  26069. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26070. if (ret != 0)
  26071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26072. if (verify != 1) {
  26073. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26074. }
  26075. done:
  26076. return ret;
  26077. }
  26078. static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
  26079. {
  26080. wc_test_ret_t ret;
  26081. #ifdef WOLFSSL_SMALL_STACK
  26082. ecc_key *key = NULL;
  26083. #else
  26084. ecc_key key[1];
  26085. #endif
  26086. int key_inited = 0;
  26087. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26088. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26089. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721";
  26090. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26091. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6";
  26092. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26093. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299";
  26094. #ifndef NO_SHA256
  26095. WOLFSSL_SMALL_STACK_STATIC const byte expSig256[] = {
  26096. 0x30, 0x46, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26097. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26098. 0x00, 0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8,
  26099. 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81,
  26100. 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9,
  26101. 0x91, 0xC3, 0x4D, 0x0E, 0xA8, 0x4E, 0xAF, 0x37,
  26102. 0x16,
  26103. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26104. 0x00, 0xF7, 0xCB, 0x1C, 0x94, 0x2D, 0x65, 0x7C,
  26105. 0x41, 0xD4, 0x36, 0xC7, 0xA1, 0xB6, 0xE2, 0x9F,
  26106. 0x65, 0xF3, 0xE9, 0x00, 0xDB, 0xB9, 0xAF, 0xF4,
  26107. 0x06, 0x4D, 0xC4, 0xAB, 0x2F, 0x84, 0x3A, 0xCD,
  26108. 0xA8
  26109. };
  26110. #endif
  26111. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26112. WOLFSSL_SMALL_STACK_STATIC const byte expSig384[] = {
  26113. 0x30, 0x44, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26114. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26115. 0x0e, 0xaf, 0xea, 0x03, 0x9b, 0x20, 0xe9, 0xb4,
  26116. 0x23, 0x09, 0xfb, 0x1d, 0x89, 0xe2, 0x13, 0x05,
  26117. 0x7c, 0xbf, 0x97, 0x3d, 0xc0, 0xcf, 0xc8, 0xf1,
  26118. 0x29, 0xed, 0xdd, 0xc8, 0x00, 0xef, 0x77, 0x19,
  26119. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26120. 0x48, 0x61, 0xf0, 0x49, 0x1e, 0x69, 0x98, 0xb9,
  26121. 0x45, 0x51, 0x93, 0xe3, 0x4e, 0x7b, 0x0d, 0x28,
  26122. 0x4d, 0xdd, 0x71, 0x49, 0xa7, 0x4b, 0x95, 0xb9,
  26123. 0x26, 0x1f, 0x13, 0xab, 0xde, 0x94, 0x09, 0x54
  26124. };
  26125. #endif
  26126. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26127. WOLFSSL_SMALL_STACK_STATIC const byte expSig512[] = {
  26128. 0x30, 0x45, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26129. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26130. 0x00, 0x84, 0x96, 0xa6, 0x0b, 0x5e, 0x9b, 0x47,
  26131. 0xc8, 0x25, 0x48, 0x88, 0x27, 0xe0, 0x49, 0x5b,
  26132. 0x0e, 0x3f, 0xa1, 0x09, 0xec, 0x45, 0x68, 0xfd,
  26133. 0x3f, 0x8d, 0x10, 0x97, 0x67, 0x8e, 0xb9, 0x7f,
  26134. 0x00,
  26135. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26136. 0x23, 0x62, 0xab, 0x1a, 0xdb, 0xe2, 0xb8, 0xad,
  26137. 0xf9, 0xcb, 0x9e, 0xda, 0xb7, 0x40, 0xea, 0x60,
  26138. 0x49, 0xc0, 0x28, 0x11, 0x4f, 0x24, 0x60, 0xf9,
  26139. 0x65, 0x54, 0xf6, 0x1f, 0xae, 0x33, 0x02, 0xfe
  26140. };
  26141. #endif
  26142. #ifdef WOLFSSL_SMALL_STACK
  26143. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26144. if (key == NULL)
  26145. return MEMORY_E;
  26146. #endif
  26147. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26148. if (ret != 0)
  26149. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26150. key_inited = 1;
  26151. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26152. if (ret != 0)
  26153. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26154. ret = wc_ecc_set_deterministic(key, 1);
  26155. if (ret != 0)
  26156. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26157. #ifndef NO_SHA256
  26158. /* Test for SHA2-256 */
  26159. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA256, msg, rng,
  26160. expSig256, sizeof(expSig256));
  26161. if (ret != 0)
  26162. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26163. #endif /* !NO_SHA256 */
  26164. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26165. /* Test for SHA2-384 */
  26166. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA384, msg, rng,
  26167. expSig384, sizeof(expSig384));
  26168. if (ret != 0)
  26169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26170. #endif /* WOLFSSL_SHA384 */
  26171. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26172. /* Test for SHA2-512 */
  26173. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA512, msg, rng,
  26174. expSig512, sizeof(expSig512));
  26175. if (ret != 0)
  26176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26177. #endif /* WOLFSSL_SHA512 */
  26178. done:
  26179. if (key_inited)
  26180. wc_ecc_free(key);
  26181. #ifdef WOLFSSL_SMALL_STACK
  26182. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26183. #endif
  26184. return ret;
  26185. }
  26186. #endif /* NO_ECC256 || HAVE_ALL_CURVES */
  26187. #ifdef WOLFSSL_PUBLIC_MP
  26188. static wc_test_ret_t ecdsa_test_deterministic_k_rs(ecc_key *key,
  26189. enum wc_HashType hashType, const char* msg, WC_RNG* rng,
  26190. mp_int* r, mp_int* s,
  26191. mp_int* expR, mp_int* expS)
  26192. {
  26193. wc_test_ret_t ret;
  26194. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26195. int verify;
  26196. ret = wc_Hash(hashType,
  26197. (byte*)msg, (word32)XSTRLEN(msg),
  26198. hash, sizeof(hash));
  26199. if (ret != 0)
  26200. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26201. ret = wc_ecc_sign_hash_ex(hash, wc_HashGetDigestSize(hashType), rng, key,
  26202. r, s);
  26203. #if defined(WOLFSSL_ASYNC_CRYPT)
  26204. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26205. #endif
  26206. if (ret != 0)
  26207. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26208. TEST_SLEEP();
  26209. if (mp_cmp(r, expR) != MP_EQ && mp_cmp(s, expS) != MP_EQ) {
  26210. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26211. }
  26212. /* Verification */
  26213. verify = 0;
  26214. ret = wc_ecc_verify_hash_ex(r, s, hash, wc_HashGetDigestSize(hashType),
  26215. &verify, key);
  26216. #if defined(WOLFSSL_ASYNC_CRYPT)
  26217. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26218. #endif
  26219. if (ret != 0)
  26220. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26221. if (verify != 1) {
  26222. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26223. }
  26224. done:
  26225. return ret;
  26226. }
  26227. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  26228. /* KAT from RFC6979 */
  26229. static wc_test_ret_t ecc384_test_deterministic_k(WC_RNG* rng)
  26230. {
  26231. wc_test_ret_t ret;
  26232. #ifdef WOLFSSL_SMALL_STACK
  26233. ecc_key *key;
  26234. mp_int *r, *s, *expR, *expS;
  26235. #else
  26236. ecc_key key[1];
  26237. mp_int r[1], s[1], expR[1], expS[1];
  26238. #endif
  26239. int key_inited = 0,
  26240. tmp_mp_ints_inited = 0;
  26241. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26242. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26243. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8"
  26244. "96D5724E4C70A825F872C9EA60D2EDF5";
  26245. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26246. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64"
  26247. "DEF8F0EA9055866064A254515480BC13";
  26248. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26249. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1"
  26250. "288B231C3AE0D4FE7344FD2533264720";
  26251. #ifndef NO_SHA256
  26252. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26253. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33"
  26254. "BDE1E888E63355D92FA2B3C36D8FB2CD";
  26255. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26256. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB"
  26257. "EFDC63ECCD1AC42EC0CB8668A4FA0AB0";
  26258. #endif
  26259. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26260. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26261. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C"
  26262. "81A648152E44ACF96E36DD1E80FABE46";
  26263. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26264. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F"
  26265. "A329C145786E679E7B82C71A38628AC8";
  26266. #endif
  26267. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26268. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26269. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C"
  26270. "FE30F35CC900056D7C99CD7882433709";
  26271. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26272. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112"
  26273. "DC7CC3EF3446DEFCEB01A45C2667FDD5";
  26274. #endif
  26275. #ifdef WOLFSSL_SMALL_STACK
  26276. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26277. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26278. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26279. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26280. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26281. if ((key == NULL) ||
  26282. (r == NULL) ||
  26283. (s == NULL) ||
  26284. (expR == NULL) ||
  26285. (expS == NULL))
  26286. {
  26287. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26288. }
  26289. #endif
  26290. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26291. if (ret != MP_OKAY)
  26292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26293. tmp_mp_ints_inited = 1;
  26294. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26295. if (ret != 0)
  26296. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26297. key_inited = 1;
  26298. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP384R1");
  26299. if (ret != 0)
  26300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26301. ret = wc_ecc_set_deterministic(key, 1);
  26302. if (ret != 0)
  26303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26304. #ifndef NO_SHA256
  26305. /* Test for SHA2-256 */
  26306. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26307. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26308. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26309. r, s, expR, expS);
  26310. if (ret != 0)
  26311. ERROR_OUT(ret, done);
  26312. #endif /* NO_SHA256 */
  26313. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26314. /* Test for SHA2-384 */
  26315. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26316. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26317. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26318. r, s, expR, expS);
  26319. if (ret != 0)
  26320. ERROR_OUT(ret, done);
  26321. #endif /* WOLFSSL_SHA384 */
  26322. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26323. /* Test for SHA2-512 */
  26324. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26325. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26326. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26327. r, s, expR, expS);
  26328. if (ret != 0)
  26329. ERROR_OUT(ret, done);
  26330. #endif /* WOLFSSL_SHA512 */
  26331. done:
  26332. if (key_inited)
  26333. wc_ecc_free(key);
  26334. if (tmp_mp_ints_inited) {
  26335. mp_free(r);
  26336. mp_free(s);
  26337. mp_free(expR);
  26338. mp_free(expS);
  26339. }
  26340. #ifdef WOLFSSL_SMALL_STACK
  26341. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26342. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26343. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26344. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26345. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26346. #endif
  26347. return ret;
  26348. }
  26349. #endif /* HAVE_ECC384 */
  26350. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  26351. /* KAT from RFC6979 */
  26352. static wc_test_ret_t ecc521_test_deterministic_k(WC_RNG* rng)
  26353. {
  26354. wc_test_ret_t ret;
  26355. #ifdef WOLFSSL_SMALL_STACK
  26356. ecc_key *key;
  26357. mp_int *r, *s, *expR, *expS;
  26358. #else
  26359. ecc_key key[1];
  26360. mp_int r[1], s[1], expR[1], expS[1];
  26361. #endif
  26362. int key_inited = 0,
  26363. tmp_mp_ints_inited = 0;
  26364. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26365. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26366. "0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C"
  26367. "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83"
  26368. "538";
  26369. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26370. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD3"
  26371. "71123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F502"
  26372. "3A4";
  26373. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26374. "0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A2"
  26375. "8A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDF"
  26376. "CF5";
  26377. #ifndef NO_SHA256
  26378. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26379. "1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659"
  26380. "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E"
  26381. "1A7";
  26382. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26383. "04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916"
  26384. "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E"
  26385. "CFC";
  26386. #endif
  26387. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26388. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26389. "1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4"
  26390. "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67"
  26391. "451";
  26392. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26393. "1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5"
  26394. "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65"
  26395. "D61";
  26396. #endif
  26397. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26398. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26399. "0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1"
  26400. "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37"
  26401. "7FA";
  26402. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26403. "0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2"
  26404. "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A"
  26405. "67A";
  26406. #endif
  26407. #ifdef WOLFSSL_SMALL_STACK
  26408. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26409. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26410. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26411. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26412. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26413. if ((key == NULL) ||
  26414. (r == NULL) ||
  26415. (s == NULL) ||
  26416. (expR == NULL) ||
  26417. (expS == NULL))
  26418. {
  26419. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26420. goto done;
  26421. }
  26422. #endif
  26423. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26424. if (ret != MP_OKAY)
  26425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26426. tmp_mp_ints_inited = 1;
  26427. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26428. if (ret != 0)
  26429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26430. key_inited = 1;
  26431. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP521R1");
  26432. if (ret != 0)
  26433. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26434. ret = wc_ecc_set_deterministic(key, 1);
  26435. if (ret != 0)
  26436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26437. #ifndef NO_SHA256
  26438. /* Test for SHA2-256 */
  26439. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26440. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26441. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26442. r, s, expR, expS);
  26443. if (ret != 0)
  26444. ERROR_OUT(ret, done);
  26445. #endif /* NO_SHA256 */
  26446. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26447. /* Test for SHA2-384 */
  26448. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26449. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26450. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26451. r, s, expR, expS);
  26452. if (ret != 0)
  26453. ERROR_OUT(ret, done);
  26454. #endif /* WOLFSSL_SHA384 */
  26455. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26456. /* Test for SHA2-512 */
  26457. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26458. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26459. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26460. r, s, expR, expS);
  26461. if (ret != 0)
  26462. ERROR_OUT(ret, done);
  26463. #endif /* WOLFSSL_SHA512 */
  26464. done:
  26465. if (key_inited)
  26466. wc_ecc_free(key);
  26467. if (tmp_mp_ints_inited) {
  26468. mp_free(r);
  26469. mp_free(s);
  26470. mp_free(expR);
  26471. mp_free(expS);
  26472. }
  26473. #ifdef WOLFSSL_SMALL_STACK
  26474. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26475. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26476. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26477. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26478. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26479. #endif
  26480. return ret;
  26481. }
  26482. #endif /* HAVE_ECC521 */
  26483. #endif /* WOLFSSL_PUBLIC_MP */
  26484. #endif /* HAVE_ECC_SIGN && (WOLFSSL_ECDSA_DETERMINISTIC_K ||
  26485. WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  26486. && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  26487. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  26488. !defined(WOLFSSL_KCAPI_ECC)
  26489. static wc_test_ret_t ecc_test_sign_vectors(WC_RNG* rng)
  26490. {
  26491. wc_test_ret_t ret;
  26492. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26493. ecc_key *key = NULL;
  26494. #else
  26495. ecc_key key[1];
  26496. #endif
  26497. int key_inited = 0;
  26498. byte sig[72];
  26499. word32 sigSz;
  26500. WOLFSSL_SMALL_STACK_STATIC const unsigned char hash[32] = "test wolfSSL deterministic sign";
  26501. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26502. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26503. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26504. WOLFSSL_SMALL_STACK_STATIC const byte k[1] = { 0x02 };
  26505. WOLFSSL_SMALL_STACK_STATIC const byte expSig[71] = {
  26506. 0x30, 0x45, 0x02, 0x20, 0x7c, 0xf2, 0x7b, 0x18,
  26507. 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03,
  26508. 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2,
  26509. 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc,
  26510. 0x47, 0x66, 0x99, 0x78, 0x02, 0x21, 0x00, 0xa8,
  26511. 0x43, 0xa0, 0xce, 0x6c, 0x5e, 0x17, 0x8a, 0x53,
  26512. 0x4d, 0xaf, 0xd2, 0x95, 0x78, 0x9f, 0x84, 0x4f,
  26513. 0x94, 0xb8, 0x75, 0xa3, 0x19, 0xa5, 0xd4, 0xdf,
  26514. 0xe1, 0xd4, 0x5e, 0x9d, 0x97, 0xfe, 0x81
  26515. };
  26516. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26517. if ((key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  26518. return MEMORY_E;
  26519. #endif
  26520. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26521. if (ret != 0)
  26522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26523. key_inited = 1;
  26524. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26525. if (ret != 0)
  26526. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26527. #if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \
  26528. && (HAVE_FIPS_VERSION > 2)))
  26529. wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN);
  26530. #endif
  26531. ret = wc_ecc_sign_set_k(k, sizeof(k), key);
  26532. if (ret != 0)
  26533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26534. sigSz = sizeof(sig);
  26535. do {
  26536. #if defined(WOLFSSL_ASYNC_CRYPT)
  26537. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26538. #endif
  26539. if (ret == 0)
  26540. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26541. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26542. if (ret != 0)
  26543. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26544. TEST_SLEEP();
  26545. if (sigSz != sizeof(expSig)) {
  26546. ret = WC_TEST_RET_ENC_NC;
  26547. goto done;
  26548. }
  26549. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26550. ret = WC_TEST_RET_ENC_NC;
  26551. goto done;
  26552. }
  26553. sigSz = sizeof(sig);
  26554. do {
  26555. #if defined(WOLFSSL_ASYNC_CRYPT)
  26556. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26557. #endif
  26558. if (ret == 0)
  26559. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26560. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26561. if (ret != 0)
  26562. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26563. TEST_SLEEP();
  26564. done:
  26565. if (key_inited)
  26566. wc_ecc_free(key);
  26567. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26568. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26569. #endif
  26570. return ret;
  26571. }
  26572. #endif
  26573. #if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE)
  26574. static wc_test_ret_t ecc_test_cdh_vectors(WC_RNG* rng)
  26575. {
  26576. wc_test_ret_t ret;
  26577. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26578. ecc_key *pub_key = (ecc_key *)XMALLOC(sizeof *pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26579. ecc_key *priv_key = (ecc_key *)XMALLOC(sizeof *priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26580. #else
  26581. ecc_key pub_key[1], priv_key[1];
  26582. #endif
  26583. byte sharedA[32] = {0}, sharedB[32] = {0};
  26584. word32 x, z;
  26585. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
  26586. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
  26587. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26588. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26589. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26590. WOLFSSL_SMALL_STACK_STATIC const char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b";
  26591. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26592. if ((pub_key == NULL) ||
  26593. (priv_key == NULL)) {
  26594. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26595. goto done;
  26596. }
  26597. #endif
  26598. XMEMSET(pub_key, 0, sizeof *pub_key);
  26599. XMEMSET(priv_key, 0, sizeof *priv_key);
  26600. /* setup private and public keys */
  26601. ret = wc_ecc_init_ex(pub_key, HEAP_HINT, devId);
  26602. if (ret != 0)
  26603. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26604. ret = wc_ecc_init_ex(priv_key, HEAP_HINT, devId);
  26605. if (ret != 0)
  26606. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26607. wc_ecc_set_flags(pub_key, WC_ECC_FLAG_COFACTOR);
  26608. wc_ecc_set_flags(priv_key, WC_ECC_FLAG_COFACTOR);
  26609. ret = wc_ecc_import_raw(pub_key, QCAVSx, QCAVSy, NULL, "SECP256R1");
  26610. if (ret != 0)
  26611. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26612. ret = wc_ecc_import_raw(priv_key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26613. if (ret != 0)
  26614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26615. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26616. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26617. !defined(HAVE_SELFTEST)
  26618. ret = wc_ecc_set_rng(priv_key, rng);
  26619. if (ret != 0)
  26620. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26621. #else
  26622. (void)rng;
  26623. #endif
  26624. /* compute ECC Cofactor shared secret */
  26625. x = sizeof(sharedA);
  26626. do {
  26627. #if defined(WOLFSSL_ASYNC_CRYPT)
  26628. ret = wc_AsyncWait(ret, &priv_key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26629. #endif
  26630. if (ret == 0)
  26631. ret = wc_ecc_shared_secret(priv_key, pub_key, sharedA, &x);
  26632. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26633. if (ret != 0)
  26634. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26635. TEST_SLEEP();
  26636. /* read in expected Z */
  26637. z = sizeof(sharedB);
  26638. ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
  26639. if (ret != 0)
  26640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26641. /* compare results */
  26642. if (x != z || XMEMCMP(sharedA, sharedB, x)) {
  26643. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26644. }
  26645. done:
  26646. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26647. if (priv_key) {
  26648. wc_ecc_free(priv_key);
  26649. XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26650. }
  26651. if (pub_key) {
  26652. wc_ecc_free(pub_key);
  26653. XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26654. }
  26655. #else
  26656. wc_ecc_free(priv_key);
  26657. wc_ecc_free(pub_key);
  26658. #endif
  26659. return ret;
  26660. }
  26661. #endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */
  26662. #endif /* HAVE_ECC_VECTOR_TEST */
  26663. #ifdef HAVE_ECC_KEY_IMPORT
  26664. /* returns 0 on success */
  26665. static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
  26666. {
  26667. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26668. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26669. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26670. ecc_key *pub = (ecc_key *)XMALLOC(sizeof *pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26671. #endif
  26672. byte *exportBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26673. byte *tmp = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26674. #else
  26675. ecc_key key[1];
  26676. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  26677. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26678. ecc_key pub[1];
  26679. #endif
  26680. byte exportBuf[ECC_BUFSIZE];
  26681. byte tmp[ECC_BUFSIZE];
  26682. #endif
  26683. const byte* msg = (const byte*)"test wolfSSL ECC public gen";
  26684. word32 x;
  26685. word32 tmpSz;
  26686. wc_test_ret_t ret = 0;
  26687. ecc_point* pubPoint = NULL;
  26688. #ifdef HAVE_ECC_VERIFY
  26689. int verify = 0;
  26690. #endif
  26691. #ifdef NO_ASN
  26692. /* private d for eccKeyDerFile / ecc_key_der_256 */
  26693. const byte keyPriv[] = {
  26694. 0x45, 0xB6, 0x69, 0x02, 0x73, 0x9C, 0x6C, 0x85,
  26695. 0xA1, 0x38, 0x5B, 0x72, 0xE8, 0xE8, 0xC7, 0xAC,
  26696. 0xC4, 0x03, 0x8D, 0x53, 0x35, 0x04, 0xFA, 0x6C,
  26697. 0x28, 0xDC, 0x34, 0x8D, 0xE1, 0xA8, 0x09, 0x8C
  26698. };
  26699. #endif
  26700. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26701. if ((key == NULL) ||
  26702. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26703. (pub == NULL) ||
  26704. #endif
  26705. (exportBuf == NULL) ||
  26706. (tmp == NULL))
  26707. ERROR_OUT(MEMORY_E, done);
  26708. #endif
  26709. (void)msg;
  26710. (void)verify;
  26711. (void)exportBuf;
  26712. (void)rng;
  26713. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26714. #ifndef NO_ECC256
  26715. #if defined(USE_CERT_BUFFERS_256)
  26716. {
  26717. XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
  26718. tmpSz = (size_t)sizeof_ecc_key_der_256;
  26719. }
  26720. #elif !defined(NO_FILESYSTEM)
  26721. {
  26722. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  26723. if (!file) {
  26724. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26725. }
  26726. tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file);
  26727. XFCLOSE(file);
  26728. if (tmpSz == 0)
  26729. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26730. }
  26731. #else
  26732. {
  26733. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
  26734. ERROR_OUT(ASN_PARSE_E, done);
  26735. }
  26736. #endif /* USE_CERT_BUFFERS_256 */
  26737. /* import private only then test with */
  26738. ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL);
  26739. if (ret == 0) {
  26740. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26741. }
  26742. ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key);
  26743. if (ret == 0) {
  26744. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26745. }
  26746. #ifndef NO_ASN
  26747. x = 0;
  26748. ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz);
  26749. if (ret != 0)
  26750. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26751. #ifdef HAVE_ECC_KEY_EXPORT
  26752. x = ECC_BUFSIZE;
  26753. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26754. if (ret != 0)
  26755. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26756. /* make private only key */
  26757. wc_ecc_free(key);
  26758. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26759. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26760. if (ret != 0)
  26761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26762. x = ECC_BUFSIZE;
  26763. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26764. if (ret == 0) {
  26765. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26766. }
  26767. #endif /* HAVE_ECC_KEY_EXPORT */
  26768. #else
  26769. /* Load raw private d directly */
  26770. ret = wc_ecc_import_private_key(keyPriv, sizeof(keyPriv), NULL, 0, key);
  26771. #endif /* !NO_ASN */
  26772. ret = wc_ecc_make_pub(NULL, NULL);
  26773. if (ret == 0) {
  26774. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26775. }
  26776. TEST_SLEEP();
  26777. #ifndef WOLFSSL_NO_MALLOC
  26778. pubPoint = wc_ecc_new_point_h(HEAP_HINT);
  26779. if (pubPoint == NULL) {
  26780. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26781. }
  26782. #if !defined(WOLFSSL_CRYPTOCELL)
  26783. ret = wc_ecc_make_pub(key, pubPoint);
  26784. #if defined(WOLFSSL_ASYNC_CRYPT)
  26785. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26786. #endif
  26787. if (ret != 0)
  26788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26789. #endif /* !WOLFSSL_CRYPTOCELL */
  26790. TEST_SLEEP();
  26791. #ifdef HAVE_ECC_KEY_EXPORT
  26792. /* export should still fail, is private only key */
  26793. x = ECC_BUFSIZE;
  26794. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26795. if (ret == 0) {
  26796. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26797. }
  26798. #endif /* HAVE_ECC_KEY_EXPORT */
  26799. #endif /* !WOLFSSL_NO_MALLOC */
  26800. #endif /* !NO_ECC256 */
  26801. /* create a new key since above test for loading key is not supported */
  26802. #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \
  26803. defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \
  26804. defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM)
  26805. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  26806. if (ret != 0)
  26807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26808. #endif
  26809. #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \
  26810. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG))) && \
  26811. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(HAVE_ECC_DETERMINISTIC_K)
  26812. tmpSz = ECC_BUFSIZE;
  26813. ret = 0;
  26814. do {
  26815. #if defined(WOLFSSL_ASYNC_CRYPT)
  26816. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26817. #endif
  26818. if (ret == 0) {
  26819. ret = wc_ecc_sign_hash(msg, (word32)XSTRLEN((const char* )msg), tmp,
  26820. &tmpSz, rng, key);
  26821. }
  26822. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26823. if (ret != 0)
  26824. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26825. TEST_SLEEP();
  26826. #ifdef HAVE_ECC_VERIFY
  26827. /* try verify with private only key */
  26828. ret = 0;
  26829. do {
  26830. #if defined(WOLFSSL_ASYNC_CRYPT)
  26831. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26832. #endif
  26833. if (ret == 0) {
  26834. ret = wc_ecc_verify_hash(tmp, tmpSz, msg,
  26835. (word32)XSTRLEN((const char*)msg), &verify, key);
  26836. }
  26837. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26838. if (ret != 0)
  26839. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26840. if (verify != 1) {
  26841. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26842. }
  26843. TEST_SLEEP();
  26844. #ifdef HAVE_ECC_KEY_EXPORT
  26845. /* exporting the public part should now work */
  26846. x = ECC_BUFSIZE;
  26847. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26848. if (ret != 0)
  26849. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26850. #endif /* HAVE_ECC_KEY_EXPORT */
  26851. #endif /* HAVE_ECC_VERIFY */
  26852. #endif /* HAVE_ECC_SIGN */
  26853. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  26854. /* now test private only key with creating a shared secret */
  26855. x = ECC_BUFSIZE;
  26856. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26857. if (ret != 0)
  26858. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26859. #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050)
  26860. /* make private only key */
  26861. wc_ecc_free(key);
  26862. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26863. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26864. if (ret != 0)
  26865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26866. /* check that public export fails with private only key */
  26867. x = ECC_BUFSIZE;
  26868. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26869. if (ret == 0) {
  26870. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26871. }
  26872. #endif /* WOLFSSL_QNX_CAAM */
  26873. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  26874. /* make public key for shared secret */
  26875. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  26876. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, pub);
  26877. #ifdef HAVE_ECC_CDH
  26878. wc_ecc_set_flags(key, WC_ECC_FLAG_COFACTOR);
  26879. #endif
  26880. #if defined(WOLFSSL_ASYNC_CRYPT)
  26881. ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE);
  26882. #endif
  26883. if (ret != 0)
  26884. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26885. TEST_SLEEP();
  26886. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26887. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26888. !defined(HAVE_SELFTEST)
  26889. ret = wc_ecc_set_rng(key, rng);
  26890. if (ret != 0)
  26891. goto done;
  26892. #endif
  26893. x = ECC_BUFSIZE;
  26894. do {
  26895. #if defined(WOLFSSL_ASYNC_CRYPT)
  26896. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26897. #endif
  26898. if (ret == 0) {
  26899. ret = wc_ecc_shared_secret(key, pub, exportBuf, &x);
  26900. }
  26901. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26902. wc_ecc_free(pub);
  26903. if (ret != 0)
  26904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26905. TEST_SLEEP();
  26906. #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */
  26907. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26908. ret = 0;
  26909. done:
  26910. wc_ecc_del_point_h(pubPoint, HEAP_HINT);
  26911. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26912. if (key != NULL) {
  26913. wc_ecc_free(key);
  26914. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26915. }
  26916. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26917. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26918. #endif
  26919. XFREE(exportBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26920. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26921. #else
  26922. wc_ecc_free(key);
  26923. #endif
  26924. return ret;
  26925. }
  26926. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26927. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26928. static wc_test_ret_t ecc_test_key_decode(WC_RNG* rng, int keySize)
  26929. {
  26930. wc_test_ret_t ret;
  26931. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26932. ecc_key *eccKey = (ecc_key *)XMALLOC(sizeof *eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26933. byte *tmpBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26934. #else
  26935. ecc_key eccKey[1];
  26936. byte tmpBuf[ECC_BUFSIZE];
  26937. #endif
  26938. word32 tmpSz;
  26939. word32 idx;
  26940. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26941. if ((eccKey == NULL) || (tmpBuf == NULL))
  26942. ERROR_OUT(MEMORY_E, done);
  26943. #endif
  26944. ret = wc_ecc_init(eccKey);
  26945. if (ret != 0) {
  26946. goto done;
  26947. }
  26948. ret = wc_ecc_make_key(rng, keySize, eccKey);
  26949. #if defined(WOLFSSL_ASYNC_CRYPT)
  26950. ret = wc_AsyncWait(ret, &eccKey->asyncDev, WC_ASYNC_FLAG_NONE);
  26951. #endif
  26952. if (ret != 0) {
  26953. goto done;
  26954. }
  26955. tmpSz = ECC_BUFSIZE;
  26956. ret = wc_EccKeyToDer(eccKey, tmpBuf, tmpSz);
  26957. wc_ecc_free(eccKey);
  26958. if (ret < 0) {
  26959. goto done;
  26960. }
  26961. tmpSz = (word32)ret;
  26962. ret = wc_ecc_init(eccKey);
  26963. if (ret != 0) {
  26964. goto done;
  26965. }
  26966. idx = 0;
  26967. ret = wc_EccPrivateKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26968. if (ret != 0) {
  26969. goto done;
  26970. }
  26971. wc_ecc_free(eccKey);
  26972. ret = wc_ecc_init(eccKey);
  26973. if (ret != 0) {
  26974. goto done;
  26975. }
  26976. idx = 0;
  26977. ret = wc_EccPublicKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26978. if (ret != 0) {
  26979. goto done;
  26980. }
  26981. ret = 0;
  26982. done:
  26983. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26984. if (eccKey != NULL) {
  26985. wc_ecc_free(eccKey);
  26986. XFREE(eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26987. }
  26988. XFREE(tmpBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26989. #else
  26990. wc_ecc_free(eccKey);
  26991. #endif
  26992. return ret;
  26993. }
  26994. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26995. #endif /* HAVE_ECC_KEY_IMPORT */
  26996. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26997. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26998. static wc_test_ret_t ecc_test_key_gen(WC_RNG* rng, int keySize)
  26999. {
  27000. wc_test_ret_t ret = 0;
  27001. int derSz;
  27002. #ifdef HAVE_PKCS8
  27003. word32 pkcs8Sz;
  27004. #endif
  27005. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27006. byte *der = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27007. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27008. #else
  27009. byte der[ECC_BUFSIZE];
  27010. ecc_key userA[1];
  27011. #endif
  27012. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27013. if ((der == NULL) || (userA == NULL))
  27014. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  27015. #endif
  27016. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27017. if (ret != 0)
  27018. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27019. ret = wc_ecc_make_key(rng, keySize, userA);
  27020. #if defined(WOLFSSL_ASYNC_CRYPT)
  27021. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27022. #endif
  27023. if (ret != 0)
  27024. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27025. TEST_SLEEP();
  27026. ret = wc_ecc_check_key(userA);
  27027. if (ret != 0)
  27028. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27029. TEST_SLEEP();
  27030. derSz = wc_EccKeyToDer(userA, der, ECC_BUFSIZE);
  27031. if (derSz < 0) {
  27032. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27033. }
  27034. ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile,
  27035. ECC_PRIVATEKEY_TYPE);
  27036. if (ret != 0)
  27037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27038. /* test export of public key */
  27039. derSz = wc_EccPublicKeyToDer(userA, der, ECC_BUFSIZE, 1);
  27040. if (derSz < 0) {
  27041. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27042. }
  27043. if (derSz == 0) {
  27044. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27045. }
  27046. #ifdef HAVE_COMP_KEY
  27047. /* test export of compressed public key */
  27048. derSz = wc_EccPublicKeyToDer_ex(userA, der, ECC_BUFSIZE, 1, 1);
  27049. if (derSz < 0) {
  27050. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27051. }
  27052. if (derSz == 0) {
  27053. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27054. }
  27055. #endif
  27056. ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0);
  27057. if (ret != 0)
  27058. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27059. #ifdef HAVE_PKCS8
  27060. /* test export of PKCS#8 unencrypted private key */
  27061. pkcs8Sz = FOURK_BUF;
  27062. derSz = wc_EccPrivateKeyToPKCS8(userA, der, &pkcs8Sz);
  27063. if (derSz < 0) {
  27064. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27065. }
  27066. if (derSz == 0) {
  27067. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27068. }
  27069. ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0);
  27070. if (ret != 0) {
  27071. goto done;
  27072. }
  27073. #endif /* HAVE_PKCS8 */
  27074. done:
  27075. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27076. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27077. if (userA != NULL) {
  27078. wc_ecc_free(userA);
  27079. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27080. }
  27081. #else
  27082. wc_ecc_free(userA);
  27083. #endif
  27084. return ret;
  27085. }
  27086. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  27087. static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
  27088. int curve_id, const ecc_set_type* dp)
  27089. {
  27090. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27091. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27092. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27093. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27094. word32 y;
  27095. #endif
  27096. #ifdef HAVE_ECC_KEY_EXPORT
  27097. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  27098. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27099. #endif
  27100. word32 x = 0;
  27101. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27102. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27103. defined(HAVE_ECC_SIGN)
  27104. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27105. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27106. int i;
  27107. #ifdef HAVE_ECC_VERIFY
  27108. int verify;
  27109. #endif /* HAVE_ECC_VERIFY */
  27110. #endif /* HAVE_ECC_SIGN */
  27111. wc_test_ret_t ret;
  27112. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27113. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27114. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27115. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27116. #else
  27117. ecc_key userA[1];
  27118. ecc_key userB[1];
  27119. ecc_key pubKey[1];
  27120. #endif
  27121. #ifndef WC_NO_RNG
  27122. int curveSize;
  27123. #endif
  27124. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27125. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27126. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27127. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27128. #endif
  27129. #ifdef HAVE_ECC_KEY_EXPORT
  27130. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27131. #endif
  27132. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27133. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27134. defined(HAVE_ECC_SIGN)
  27135. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27136. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27137. #endif
  27138. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  27139. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \
  27140. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27141. if (sharedA == NULL || sharedB == NULL)
  27142. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27143. #endif
  27144. #ifdef HAVE_ECC_KEY_EXPORT
  27145. if (exportBuf == NULL)
  27146. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27147. #endif
  27148. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27149. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27150. defined(HAVE_ECC_SIGN)
  27151. if (sig == NULL || digest == NULL)
  27152. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27153. #endif
  27154. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  27155. (void)testVerifyCount;
  27156. (void)dp;
  27157. (void)x;
  27158. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27159. if ((userA == NULL) ||
  27160. (userB == NULL) ||
  27161. (pubKey == NULL))
  27162. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27163. #endif
  27164. XMEMSET(userA, 0, sizeof *userA);
  27165. XMEMSET(userB, 0, sizeof *userB);
  27166. XMEMSET(pubKey, 0, sizeof *pubKey);
  27167. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27168. if (ret != 0)
  27169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27170. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  27171. if (ret != 0)
  27172. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27173. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27174. if (ret != 0)
  27175. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27176. #ifdef WOLFSSL_CUSTOM_CURVES
  27177. if (dp != NULL) {
  27178. ret = wc_ecc_set_custom_curve(userA, dp);
  27179. if (ret != 0)
  27180. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27181. ret = wc_ecc_set_custom_curve(userB, dp);
  27182. if (ret != 0)
  27183. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27184. }
  27185. #endif
  27186. #ifndef WC_NO_RNG
  27187. ret = wc_ecc_make_key_ex(rng, keySize, userA, curve_id);
  27188. #if defined(WOLFSSL_ASYNC_CRYPT)
  27189. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27190. #endif
  27191. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  27192. if (ret == WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  27193. ret = 0;
  27194. goto done; /* no software case */
  27195. }
  27196. #endif
  27197. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  27198. goto done; /* catch case, where curve is not supported */
  27199. if (ret != 0)
  27200. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27201. TEST_SLEEP();
  27202. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  27203. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  27204. if (curveSize != userA->dp->size)
  27205. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27206. }
  27207. ret = wc_ecc_check_key(userA);
  27208. if (ret != 0)
  27209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27210. TEST_SLEEP();
  27211. /* ATECC508/608 configuration may not support more than one ECDH key */
  27212. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27213. ret = wc_ecc_make_key_ex(rng, keySize, userB, curve_id);
  27214. #if defined(WOLFSSL_ASYNC_CRYPT)
  27215. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  27216. #endif
  27217. if (ret != 0)
  27218. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27219. TEST_SLEEP();
  27220. /* only perform the below tests if the key size matches */
  27221. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  27222. /* Not an error, just not a key size match */
  27223. WARNING_OUT(ECC_CURVE_OID_E, done);
  27224. #ifdef HAVE_ECC_DHE
  27225. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27226. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27227. !defined(HAVE_SELFTEST)
  27228. ret = wc_ecc_set_rng(userA, rng);
  27229. if (ret != 0)
  27230. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27231. ret = wc_ecc_set_rng(userB, rng);
  27232. if (ret != 0)
  27233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27234. #endif
  27235. x = ECC_SHARED_SIZE;
  27236. do {
  27237. #if defined(WOLFSSL_ASYNC_CRYPT)
  27238. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27239. #endif
  27240. if (ret == 0)
  27241. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27242. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27243. if (ret != 0)
  27244. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27245. TEST_SLEEP();
  27246. y = ECC_SHARED_SIZE;
  27247. do {
  27248. #if defined(WOLFSSL_ASYNC_CRYPT)
  27249. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27250. #endif
  27251. if (ret == 0)
  27252. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27253. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27254. if (ret != 0)
  27255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27256. if (y != x)
  27257. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27258. if (XMEMCMP(sharedA, sharedB, x))
  27259. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27260. TEST_SLEEP();
  27261. #ifdef HAVE_ECC_CDH
  27262. /* add cofactor flag */
  27263. wc_ecc_set_flags(userA, WC_ECC_FLAG_COFACTOR);
  27264. wc_ecc_set_flags(userB, WC_ECC_FLAG_COFACTOR);
  27265. x = ECC_SHARED_SIZE;
  27266. do {
  27267. #if defined(WOLFSSL_ASYNC_CRYPT)
  27268. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27269. #endif
  27270. if (ret == 0)
  27271. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27272. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27273. if (ret != 0)
  27274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27275. TEST_SLEEP();
  27276. y = ECC_SHARED_SIZE;
  27277. do {
  27278. #if defined(WOLFSSL_ASYNC_CRYPT)
  27279. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27280. #endif
  27281. if (ret == 0)
  27282. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27283. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27284. if (ret != 0)
  27285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27286. if (y != x)
  27287. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27288. if (XMEMCMP(sharedA, sharedB, x))
  27289. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27290. TEST_SLEEP();
  27291. /* remove cofactor flag */
  27292. wc_ecc_set_flags(userA, 0);
  27293. wc_ecc_set_flags(userB, 0);
  27294. #endif /* HAVE_ECC_CDH */
  27295. #endif /* HAVE_ECC_DHE */
  27296. #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
  27297. #ifdef HAVE_ECC_KEY_EXPORT
  27298. x = ECC_KEY_EXPORT_BUF_SIZE;
  27299. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  27300. if (ret != 0)
  27301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27302. #ifdef HAVE_ECC_KEY_IMPORT
  27303. #ifdef WOLFSSL_CUSTOM_CURVES
  27304. if (dp != NULL) {
  27305. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27306. if (ret != 0)
  27307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27308. }
  27309. #endif
  27310. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27311. if (ret != 0)
  27312. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27313. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27314. #ifdef HAVE_ECC_DHE
  27315. y = ECC_SHARED_SIZE;
  27316. do {
  27317. #if defined(WOLFSSL_ASYNC_CRYPT)
  27318. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27319. #endif
  27320. if (ret == 0)
  27321. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27322. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27323. if (ret != 0)
  27324. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27325. if (XMEMCMP(sharedA, sharedB, y))
  27326. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27327. TEST_SLEEP();
  27328. #endif /* HAVE_ECC_DHE */
  27329. #ifdef HAVE_COMP_KEY
  27330. /* try compressed export / import too */
  27331. x = ECC_KEY_EXPORT_BUF_SIZE;
  27332. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  27333. if (ret != 0)
  27334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27335. wc_ecc_free(pubKey);
  27336. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27337. if (ret != 0)
  27338. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27339. #ifdef WOLFSSL_CUSTOM_CURVES
  27340. if (dp != NULL) {
  27341. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27342. if (ret != 0)
  27343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27344. }
  27345. #endif
  27346. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27347. if (ret != 0)
  27348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27349. #ifdef HAVE_ECC_DHE
  27350. y = ECC_SHARED_SIZE;
  27351. do {
  27352. #if defined(WOLFSSL_ASYNC_CRYPT)
  27353. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27354. #endif
  27355. if (ret == 0)
  27356. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27357. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27358. if (ret != 0)
  27359. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27360. if (XMEMCMP(sharedA, sharedB, y))
  27361. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27362. TEST_SLEEP();
  27363. #endif /* HAVE_ECC_DHE */
  27364. #endif /* HAVE_COMP_KEY */
  27365. #endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A */
  27366. #endif /* !WC_NO_RNG */
  27367. #endif /* HAVE_ECC_KEY_IMPORT */
  27368. #endif /* HAVE_ECC_KEY_EXPORT */
  27369. /* For KCAPI cannot sign using generated ECDH key */
  27370. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27371. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
  27372. #ifdef HAVE_ECC_SIGN
  27373. /* some hardware doesn't support sign/verify of all zero digest */
  27374. #if !defined(WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST)
  27375. /* test DSA sign hash with zeros */
  27376. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27377. digest[i] = 0;
  27378. }
  27379. x = ECC_SIG_SIZE;
  27380. do {
  27381. #if defined(WOLFSSL_ASYNC_CRYPT)
  27382. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27383. #endif
  27384. if (ret == 0)
  27385. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
  27386. userA);
  27387. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27388. if (ret != 0)
  27389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27390. TEST_SLEEP();
  27391. #ifdef HAVE_ECC_VERIFY
  27392. for (i=0; i<testVerifyCount; i++) {
  27393. verify = 0;
  27394. do {
  27395. #if defined(WOLFSSL_ASYNC_CRYPT)
  27396. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27397. #endif
  27398. if (ret == 0)
  27399. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
  27400. &verify, userA);
  27401. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27402. if (ret != 0)
  27403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27404. if (verify != 1)
  27405. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27406. TEST_SLEEP();
  27407. }
  27408. #endif /* HAVE_ECC_VERIFY */
  27409. #endif /* !WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST */
  27410. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  27411. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27412. digest[i] = (byte)i;
  27413. }
  27414. x = ECC_SIG_SIZE;
  27415. do {
  27416. #if defined(WOLFSSL_ASYNC_CRYPT)
  27417. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27418. #endif
  27419. if (ret == 0)
  27420. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  27421. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27422. if (ret != 0)
  27423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27424. TEST_SLEEP();
  27425. #ifdef HAVE_ECC_VERIFY
  27426. for (i=0; i<testVerifyCount; i++) {
  27427. verify = 0;
  27428. do {
  27429. #if defined(WOLFSSL_ASYNC_CRYPT)
  27430. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27431. #endif
  27432. if (ret == 0)
  27433. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA);
  27434. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27435. if (ret != 0)
  27436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27437. if (verify != 1)
  27438. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27439. TEST_SLEEP();
  27440. }
  27441. #endif /* HAVE_ECC_VERIFY */
  27442. #endif /* HAVE_ECC_SIGN */
  27443. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT &&
  27444. * !WC_NO_RNG && !WOLFSSL_KCAPI_ECC) */
  27445. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  27446. !defined(WOLFSSL_ATECC508) && !defined(WOLFSSL_ATECC608A) && \
  27447. !defined(WOLFSSL_KCAPI_ECC)
  27448. x = ECC_KEY_EXPORT_BUF_SIZE;
  27449. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  27450. if (ret != 0)
  27451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27452. #elif defined(HAVE_ECC_KEY_EXPORT)
  27453. (void)exportBuf;
  27454. #endif /* HAVE_ECC_KEY_EXPORT */
  27455. done:
  27456. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27457. if (userA != NULL) {
  27458. wc_ecc_free(userA);
  27459. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27460. }
  27461. if (userB != NULL) {
  27462. wc_ecc_free(userB);
  27463. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27464. }
  27465. if (pubKey != NULL) {
  27466. wc_ecc_free(pubKey);
  27467. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27468. }
  27469. #else
  27470. wc_ecc_free(pubKey);
  27471. wc_ecc_free(userB);
  27472. wc_ecc_free(userA);
  27473. #endif
  27474. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  27475. WC_FREE_VAR(sharedA, HEAP_HINT);
  27476. WC_FREE_VAR(sharedB, HEAP_HINT);
  27477. #endif
  27478. #ifdef HAVE_ECC_KEY_EXPORT
  27479. WC_FREE_VAR(exportBuf, HEAP_HINT);
  27480. #endif
  27481. #ifdef HAVE_ECC_SIGN
  27482. WC_FREE_VAR(sig, HEAP_HINT);
  27483. WC_FREE_VAR(digest, HEAP_HINT);
  27484. #endif
  27485. (void)keySize;
  27486. (void)curve_id;
  27487. (void)rng;
  27488. return ret;
  27489. }
  27490. #undef ECC_TEST_VERIFY_COUNT
  27491. #define ECC_TEST_VERIFY_COUNT 2
  27492. static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
  27493. {
  27494. wc_test_ret_t ret;
  27495. WOLFSSL_MSG_EX("ecc_test_curve keySize = %d", keySize);
  27496. #if FIPS_VERSION3_GE(6,0,0)
  27497. #ifdef DEBUG_WOLFSSL
  27498. printf("keySize is %d\n", keySize);
  27499. #endif
  27500. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27501. goto skip_A;
  27502. }
  27503. #endif
  27504. ret = ecc_test_curve_size(rng, keySize, ECC_TEST_VERIFY_COUNT, curve_id,
  27505. NULL);
  27506. if (ret < 0) {
  27507. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27508. /* ignore error for curves not found */
  27509. /* some curve sizes are only available with:
  27510. HAVE_ECC_SECPR2, HAVE_ECC_SECPR3, HAVE_ECC_BRAINPOOL
  27511. and HAVE_ECC_KOBLITZ */
  27512. }
  27513. else {
  27514. printf("ecc_test_curve_size %d failed!\n", keySize);
  27515. return ret;
  27516. }
  27517. }
  27518. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27519. #if FIPS_VERSION3_GE(6,0,0)
  27520. skip_A:
  27521. #endif
  27522. #ifdef HAVE_ECC_VECTOR_TEST
  27523. ret = ecc_test_vector(keySize);
  27524. if (ret < 0) {
  27525. printf("ecc_test_vector %d failed!\n", keySize);
  27526. return ret;
  27527. }
  27528. #endif
  27529. #if FIPS_VERSION3_GE(6,0,0)
  27530. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27531. goto skip_B;
  27532. }
  27533. #endif
  27534. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27535. !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27536. ret = ecc_test_key_decode(rng, keySize);
  27537. if (ret < 0) {
  27538. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27539. /* ignore error for curves not found */
  27540. }
  27541. else {
  27542. printf("ecc_test_key_decode %d failed!\n", keySize);
  27543. return ret;
  27544. }
  27545. }
  27546. #endif
  27547. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27548. ret = ecc_test_key_gen(rng, keySize);
  27549. if (ret < 0) {
  27550. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27551. /* ignore error for curves not found */
  27552. }
  27553. else {
  27554. printf("ecc_test_key_gen %d failed!\n", keySize);
  27555. return ret;
  27556. }
  27557. }
  27558. #endif
  27559. #if FIPS_VERSION3_GE(6,0,0)
  27560. skip_B:
  27561. #endif
  27562. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  27563. return 0;
  27564. }
  27565. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  27566. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  27567. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27568. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27569. static wc_test_ret_t ecc_point_test(void)
  27570. {
  27571. wc_test_ret_t ret;
  27572. ecc_point* point;
  27573. ecc_point* point2;
  27574. #ifdef HAVE_COMP_KEY
  27575. ecc_point* point3;
  27576. ecc_point* point4;
  27577. #endif
  27578. word32 outLen;
  27579. byte out[65];
  27580. byte der[] = { 0x04, /* = Uncompressed */
  27581. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27582. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27583. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27584. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27585. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27586. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27587. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27588. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27589. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27590. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27591. byte derComp0[] = { 0x02, /* = Compressed, y even */
  27592. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27593. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27594. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27595. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27596. byte derComp1[] = { 0x03, /* = Compressed, y odd */
  27597. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27598. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27599. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27600. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27601. #endif
  27602. byte altDer[] = { 0x04, /* = Uncompressed */
  27603. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27604. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27605. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27606. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27607. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27608. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27609. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27610. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  27611. int curve_idx = wc_ecc_get_curve_idx(ECC_SECP256R1);
  27612. /* if curve P256 is not enabled then test should not fail */
  27613. if (curve_idx == ECC_CURVE_INVALID)
  27614. return 0;
  27615. outLen = sizeof(out);
  27616. point = wc_ecc_new_point();
  27617. if (point == NULL)
  27618. return WC_TEST_RET_ENC_ERRNO;
  27619. point2 = wc_ecc_new_point();
  27620. if (point2 == NULL) {
  27621. wc_ecc_del_point(point);
  27622. return WC_TEST_RET_ENC_NC;
  27623. }
  27624. #ifdef HAVE_COMP_KEY
  27625. point3 = wc_ecc_new_point();
  27626. if (point3 == NULL) {
  27627. wc_ecc_del_point(point2);
  27628. wc_ecc_del_point(point);
  27629. return WC_TEST_RET_ENC_NC;
  27630. }
  27631. point4 = wc_ecc_new_point();
  27632. if (point4 == NULL) {
  27633. wc_ecc_del_point(point3);
  27634. wc_ecc_del_point(point2);
  27635. wc_ecc_del_point(point);
  27636. return WC_TEST_RET_ENC_NC;
  27637. }
  27638. #endif
  27639. /* Parameter Validation testing. */
  27640. wc_ecc_del_point(NULL);
  27641. ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, point);
  27642. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27643. ret = WC_TEST_RET_ENC_EC(ret);
  27644. goto done;
  27645. }
  27646. ret = wc_ecc_import_point_der(der, sizeof(der), ECC_CURVE_INVALID, point);
  27647. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27648. ret = WC_TEST_RET_ENC_EC(ret);
  27649. goto done;
  27650. }
  27651. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, NULL);
  27652. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27653. ret = WC_TEST_RET_ENC_EC(ret);
  27654. goto done;
  27655. }
  27656. ret = wc_ecc_export_point_der(-1, point, out, &outLen);
  27657. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27658. ret = WC_TEST_RET_ENC_EC(ret);
  27659. goto done;
  27660. }
  27661. ret = wc_ecc_export_point_der(curve_idx, NULL, out, &outLen);
  27662. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27663. ret = WC_TEST_RET_ENC_EC(ret);
  27664. goto done;
  27665. }
  27666. ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen);
  27667. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || outLen != sizeof(out)) {
  27668. ret = WC_TEST_RET_ENC_EC(ret);
  27669. goto done;
  27670. }
  27671. ret = wc_ecc_export_point_der(curve_idx, point, out, NULL);
  27672. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27673. ret = WC_TEST_RET_ENC_EC(ret);
  27674. goto done;
  27675. }
  27676. outLen = 0;
  27677. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27678. if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
  27679. ret = WC_TEST_RET_ENC_EC(ret);
  27680. goto done;
  27681. }
  27682. ret = wc_ecc_copy_point(NULL, NULL);
  27683. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27684. ret = WC_TEST_RET_ENC_EC(ret);
  27685. goto done;
  27686. }
  27687. ret = wc_ecc_copy_point(NULL, point2);
  27688. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27689. ret = WC_TEST_RET_ENC_EC(ret);
  27690. goto done;
  27691. }
  27692. ret = wc_ecc_copy_point(point, NULL);
  27693. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27694. ret = WC_TEST_RET_ENC_EC(ret);
  27695. goto done;
  27696. }
  27697. ret = wc_ecc_cmp_point(NULL, NULL);
  27698. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27699. ret = WC_TEST_RET_ENC_EC(ret);
  27700. goto done;
  27701. }
  27702. ret = wc_ecc_cmp_point(NULL, point2);
  27703. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27704. ret = WC_TEST_RET_ENC_EC(ret);
  27705. goto done;
  27706. }
  27707. ret = wc_ecc_cmp_point(point, NULL);
  27708. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27709. ret = WC_TEST_RET_ENC_EC(ret);
  27710. goto done;
  27711. }
  27712. /* Use API. */
  27713. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point);
  27714. if (ret != 0)
  27715. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27716. outLen = sizeof(out);
  27717. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27718. if (ret != 0)
  27719. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27720. if (outLen != sizeof(der)) {
  27721. ret = WC_TEST_RET_ENC_NC;
  27722. goto done;
  27723. }
  27724. if (XMEMCMP(out, der, outLen) != 0) {
  27725. ret = WC_TEST_RET_ENC_NC;
  27726. goto done;
  27727. }
  27728. ret = wc_ecc_copy_point(point2, point);
  27729. if (ret != MP_OKAY) {
  27730. ret = WC_TEST_RET_ENC_EC(ret);
  27731. goto done;
  27732. }
  27733. ret = wc_ecc_cmp_point(point2, point);
  27734. if (ret != MP_EQ) {
  27735. ret = WC_TEST_RET_ENC_EC(ret);
  27736. goto done;
  27737. }
  27738. ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2);
  27739. if (ret != 0)
  27740. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27741. ret = wc_ecc_cmp_point(point2, point);
  27742. if (ret != MP_GT) {
  27743. ret = WC_TEST_RET_ENC_EC(ret);
  27744. goto done;
  27745. }
  27746. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27747. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27748. ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3);
  27749. if (ret != 0)
  27750. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27751. ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0);
  27752. if (ret != 0)
  27753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27754. ret = wc_ecc_cmp_point(point3, point4);
  27755. if (ret != MP_EQ) {
  27756. ret = WC_TEST_RET_ENC_EC(ret);
  27757. goto done;
  27758. }
  27759. ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3);
  27760. if (ret != 0)
  27761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27762. ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0);
  27763. if (ret != 0)
  27764. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27765. ret = wc_ecc_cmp_point(point3, point4);
  27766. if (ret != MP_EQ) {
  27767. ret = WC_TEST_RET_ENC_EC(ret);
  27768. goto done;
  27769. }
  27770. #endif
  27771. done:
  27772. #ifdef HAVE_COMP_KEY
  27773. wc_ecc_del_point(point4);
  27774. wc_ecc_del_point(point3);
  27775. #endif
  27776. wc_ecc_del_point(point2);
  27777. wc_ecc_del_point(point);
  27778. return ret;
  27779. }
  27780. #endif /* !WOLFSSL_ATECC508A && HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27781. #if !defined(NO_SIG_WRAPPER) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27782. static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key)
  27783. {
  27784. wc_test_ret_t ret;
  27785. word32 sigSz;
  27786. int size;
  27787. byte out[ECC_MAX_SIG_SIZE];
  27788. byte in[] = TEST_STRING;
  27789. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  27790. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  27791. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  27792. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  27793. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  27794. };
  27795. word32 inLen = (word32)XSTRLEN((char*)in);
  27796. size = wc_ecc_sig_size(key);
  27797. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key));
  27798. if (ret != size)
  27799. return WC_TEST_RET_ENC_NC;
  27800. sigSz = (word32)ret;
  27801. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27802. inLen, out, &sigSz, key, sizeof(*key), rng);
  27803. if (ret != 0)
  27804. return WC_TEST_RET_ENC_EC(ret);
  27805. TEST_SLEEP();
  27806. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27807. inLen, out, sigSz, key, sizeof(*key));
  27808. if (ret != 0)
  27809. return WC_TEST_RET_ENC_EC(ret);
  27810. TEST_SLEEP();
  27811. sigSz = (word32)sizeof(out);
  27812. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27813. hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng);
  27814. if (ret != 0)
  27815. return WC_TEST_RET_ENC_EC(ret);
  27816. TEST_SLEEP();
  27817. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27818. hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key));
  27819. if (ret != 0)
  27820. return WC_TEST_RET_ENC_EC(ret);
  27821. TEST_SLEEP();
  27822. return 0;
  27823. }
  27824. #endif
  27825. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27826. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27827. static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
  27828. {
  27829. wc_test_ret_t ret;
  27830. int curve_id;
  27831. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27832. ecc_key *keyImp = (ecc_key *)XMALLOC(sizeof *keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27833. #else
  27834. ecc_key keyImp[1];
  27835. #endif
  27836. byte priv[32];
  27837. word32 privLen;
  27838. byte pub[65*2];
  27839. word32 pubLen, pubLenX, pubLenY;
  27840. const char qx[] = "7a4e287890a1a47ad3457e52f2f76a83"
  27841. "ce46cbc947616d0cbaa82323818a793d";
  27842. const char qy[] = "eec4084f5b29ebf29c44cce3b3059610"
  27843. "922f8b30ea6e8811742ac7238fe87308";
  27844. const char d[] = "8c14b793cb19137e323a6d2e2a870bca"
  27845. "2e7a493ec1153b3a95feb8a4873f8d08";
  27846. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27847. if (keyImp == NULL)
  27848. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27849. #endif
  27850. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27851. privLen = sizeof(priv);
  27852. ret = wc_ecc_export_private_only(key, priv, &privLen);
  27853. if (ret != 0)
  27854. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27855. pubLen = sizeof(pub);
  27856. ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen);
  27857. if (ret != 0)
  27858. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27859. ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp);
  27860. if (ret != 0)
  27861. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27862. wc_ecc_free(keyImp);
  27863. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27864. ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1);
  27865. if (ret != 0)
  27866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27867. wc_ecc_free(keyImp);
  27868. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27869. curve_id = wc_ecc_get_curve_id(key->idx);
  27870. if (curve_id < 0) {
  27871. ret = WC_TEST_RET_ENC_EC(curve_id);
  27872. goto done;
  27873. }
  27874. /* test import private only */
  27875. ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp,
  27876. curve_id);
  27877. if (ret != 0)
  27878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27879. wc_ecc_free(keyImp);
  27880. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27881. /* test export public raw */
  27882. pubLenX = pubLenY = 32;
  27883. ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY);
  27884. if (ret != 0)
  27885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27886. #ifndef HAVE_SELFTEST
  27887. /* test import of public */
  27888. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1);
  27889. if (ret != 0)
  27890. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27891. #endif
  27892. wc_ecc_free(keyImp);
  27893. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27894. /* test export private and public raw */
  27895. pubLenX = pubLenY = privLen = 32;
  27896. ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY,
  27897. priv, &privLen);
  27898. if (ret != 0)
  27899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27900. #ifndef HAVE_SELFTEST
  27901. /* test import of private and public */
  27902. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1);
  27903. if (ret != 0)
  27904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27905. #endif
  27906. done:
  27907. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27908. if (keyImp != NULL) {
  27909. wc_ecc_free(keyImp);
  27910. XFREE(keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27911. }
  27912. #else
  27913. wc_ecc_free(keyImp);
  27914. #endif
  27915. return ret;
  27916. }
  27917. #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27918. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  27919. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27920. static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
  27921. {
  27922. wc_test_ret_t ret;
  27923. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27924. ecc_key *key2 = (ecc_key *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27925. ecc_key *key3 = (ecc_key *)XMALLOC(sizeof *key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27926. #else
  27927. ecc_key key2[1];
  27928. ecc_key key3[1];
  27929. #endif
  27930. #ifdef WOLFSSL_PUBLIC_MP
  27931. mp_int* priv;
  27932. #endif
  27933. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27934. if ((key2 == NULL) || (key3 == NULL))
  27935. ERROR_OUT(MEMORY_E, done);
  27936. #endif
  27937. wc_ecc_init_ex(key2, HEAP_HINT, devId);
  27938. wc_ecc_init_ex(key3, HEAP_HINT, devId);
  27939. /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */
  27940. /* Need base point (Gx,Gy) and parameter A - load them as the public and
  27941. * private key in key2.
  27942. */
  27943. ret = wc_ecc_import_raw_ex(key2, key1->dp->Gx, key1->dp->Gy, key1->dp->Af,
  27944. ECC_SECP256R1);
  27945. if (ret != 0)
  27946. goto done;
  27947. /* Need a point (Gx,Gy) and prime - load them as the public and private key
  27948. * in key3.
  27949. */
  27950. ret = wc_ecc_import_raw_ex(key3, key1->dp->Gx, key1->dp->Gy,
  27951. key1->dp->prime, ECC_SECP256R1);
  27952. if (ret != 0)
  27953. goto done;
  27954. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27955. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27956. 1);
  27957. if (ret != 0)
  27958. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27959. #ifdef WOLFSSL_PUBLIC_MP
  27960. priv = wc_ecc_key_get_priv(key1);
  27961. mp_zero(priv);
  27962. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27963. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27964. 1);
  27965. if (ret != 0)
  27966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27967. if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
  27968. ret = WC_TEST_RET_ENC_EC(ret);
  27969. goto done;
  27970. }
  27971. if (mp_cmp_d(key3->pubkey.z, 1) != MP_EQ) {
  27972. ret = WC_TEST_RET_ENC_EC(ret);
  27973. goto done;
  27974. }
  27975. #endif
  27976. done:
  27977. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27978. if (key2 != NULL) {
  27979. wc_ecc_free(key2);
  27980. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27981. }
  27982. if (key3 != NULL) {
  27983. wc_ecc_free(key3);
  27984. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27985. }
  27986. #else
  27987. wc_ecc_free(key3);
  27988. wc_ecc_free(key2);
  27989. #endif
  27990. return ret;
  27991. }
  27992. #endif
  27993. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27994. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
  27995. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  27996. !defined(WOLFSSL_CRYPTOCELL)
  27997. static wc_test_ret_t ecc_ssh_test(ecc_key* key, WC_RNG* rng)
  27998. {
  27999. wc_test_ret_t ret;
  28000. byte out[128];
  28001. word32 outLen = sizeof(out);
  28002. /* Parameter Validation testing. */
  28003. ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen);
  28004. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28005. return WC_TEST_RET_ENC_EC(ret);
  28006. ret = wc_ecc_shared_secret_ssh(key, NULL, out, &outLen);
  28007. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28008. return WC_TEST_RET_ENC_EC(ret);
  28009. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, NULL, &outLen);
  28010. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28011. return WC_TEST_RET_ENC_EC(ret);
  28012. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, NULL);
  28013. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28014. return WC_TEST_RET_ENC_EC(ret);
  28015. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  28016. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  28017. !defined(HAVE_SELFTEST)
  28018. ret = wc_ecc_set_rng(key, rng);
  28019. if (ret != 0)
  28020. return WC_TEST_RET_ENC_EC(ret);
  28021. #else
  28022. (void)rng;
  28023. #endif
  28024. /* Use API. */
  28025. ret = 0;
  28026. do {
  28027. #if defined(WOLFSSL_ASYNC_CRYPT)
  28028. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  28029. #endif
  28030. if (ret == 0)
  28031. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen);
  28032. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  28033. if (ret != 0)
  28034. return WC_TEST_RET_ENC_EC(ret);
  28035. TEST_SLEEP();
  28036. return 0;
  28037. }
  28038. #endif /* HAVE_ECC_DHE && !WC_NO_RNG */
  28039. static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
  28040. {
  28041. wc_test_ret_t ret;
  28042. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28043. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28044. #else
  28045. ecc_key key[1];
  28046. #endif
  28047. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28048. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28049. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28050. word32 idx = 0;
  28051. #endif
  28052. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28053. if (key == NULL)
  28054. ERROR_OUT(MEMORY_E, done);
  28055. #endif
  28056. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28057. /* Use API */
  28058. ret = wc_ecc_set_flags(NULL, 0);
  28059. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28060. ret = WC_TEST_RET_ENC_EC(ret);
  28061. goto done;
  28062. }
  28063. ret = wc_ecc_set_flags(key, 0);
  28064. if (ret != 0)
  28065. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28066. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  28067. #ifndef WC_NO_RNG
  28068. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  28069. #if defined(WOLFSSL_ASYNC_CRYPT)
  28070. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  28071. #endif
  28072. if (ret != 0) {
  28073. goto done;
  28074. }
  28075. #ifndef NO_SIG_WRAPPER
  28076. ret = ecc_sig_test(rng, key);
  28077. if (ret < 0)
  28078. goto done;
  28079. #endif
  28080. TEST_SLEEP();
  28081. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
  28082. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  28083. ret = ecc_ssh_test(key, rng);
  28084. if (ret < 0)
  28085. goto done;
  28086. #endif
  28087. wc_ecc_free(key);
  28088. #else
  28089. (void)rng;
  28090. #endif /* !WC_NO_RNG */
  28091. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28092. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28093. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28094. /* Use test ECC key - ensure real private "d" exists */
  28095. #if defined(USE_CERT_BUFFERS_256)
  28096. {
  28097. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  28098. sizeof_ecc_key_der_256);
  28099. }
  28100. #elif !defined(NO_FILESYSTEM)
  28101. {
  28102. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  28103. byte der[128];
  28104. word32 derSz;
  28105. if (!file) {
  28106. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28107. }
  28108. derSz = (word32)XFREAD(der, 1, sizeof(der), file);
  28109. XFCLOSE(file);
  28110. if (derSz == 0)
  28111. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28112. ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
  28113. }
  28114. #else
  28115. {
  28116. (void)idx;
  28117. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
  28118. ERROR_OUT(ASN_PARSE_E, done);
  28119. }
  28120. #endif
  28121. if (ret != 0) {
  28122. goto done;
  28123. }
  28124. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
  28125. ret = ecc_exp_imp_test(key);
  28126. if (ret < 0)
  28127. goto done;
  28128. #endif
  28129. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  28130. !defined(WOLFSSL_CRYPTOCELL)
  28131. ret = ecc_mulmod_test(key);
  28132. if (ret < 0)
  28133. goto done;
  28134. #endif
  28135. #endif
  28136. #else
  28137. (void)rng;
  28138. (void)idx;
  28139. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  28140. done:
  28141. wc_ecc_free(key);
  28142. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28143. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28144. #endif
  28145. return ret;
  28146. }
  28147. #endif /* !NO_ECC256 || HAVE_ALL_CURVES */
  28148. #if defined(WOLFSSL_CERT_EXT) && \
  28149. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  28150. static wc_test_ret_t ecc_decode_test(void)
  28151. {
  28152. wc_test_ret_t ret;
  28153. word32 inSz;
  28154. word32 inOutIdx;
  28155. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28156. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28157. #else
  28158. ecc_key key[1];
  28159. #endif
  28160. /* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
  28161. /* This is ecc_clikeypub_der_256. */
  28162. WOLFSSL_SMALL_STACK_STATIC const byte good[] = {
  28163. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  28164. 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  28165. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xbf, 0xf4,
  28166. 0x0f, 0x44, 0x50, 0x9a, 0x3d, 0xce, 0x9b, 0xb7, 0xf0, 0xc5,
  28167. 0x4d, 0xf5, 0x70, 0x7b, 0xd4, 0xec, 0x24, 0x8e, 0x19, 0x80,
  28168. 0xec, 0x5a, 0x4c, 0xa2, 0x24, 0x03, 0x62, 0x2c, 0x9b, 0xda,
  28169. 0xef, 0xa2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xc6, 0x56,
  28170. 0x95, 0x06, 0xcc, 0x01, 0xa9, 0xbd, 0xf6, 0x75, 0x1a, 0x42,
  28171. 0xf7, 0xbd, 0xa9, 0xb2, 0x36, 0x22, 0x5f, 0xc7, 0x5d, 0x7f,
  28172. 0xb4 };
  28173. WOLFSSL_SMALL_STACK_STATIC const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
  28174. 0x00, 0x04, 0x01, 0x01 };
  28175. WOLFSSL_SMALL_STACK_STATIC const byte badOneObjId[] = { 0x30, 0x0a, 0x30, 0x08, 0x06, 0x00,
  28176. 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28177. WOLFSSL_SMALL_STACK_STATIC const byte badObjId1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x09,
  28178. 0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28179. WOLFSSL_SMALL_STACK_STATIC const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
  28180. 0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28181. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28182. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28183. 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28184. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28185. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28186. 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
  28187. WOLFSSL_SMALL_STACK_STATIC const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
  28188. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28189. 0x03, 0x03, 0x04, 0x01, 0x01 };
  28190. WOLFSSL_SMALL_STACK_STATIC const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
  28191. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28192. 0x03, 0x03, 0x00, 0x04, 0x01 };
  28193. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28194. if (key == NULL)
  28195. ERROR_OUT(MEMORY_E, done);
  28196. #endif
  28197. XMEMSET(key, 0, sizeof *key);
  28198. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28199. inSz = sizeof(good);
  28200. ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, key, inSz);
  28201. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28202. ret = WC_TEST_RET_ENC_EC(ret);
  28203. goto done;
  28204. }
  28205. ret = wc_EccPublicKeyDecode(good, NULL, key, inSz);
  28206. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28207. ret = WC_TEST_RET_ENC_EC(ret);
  28208. goto done;
  28209. }
  28210. ret = wc_EccPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  28211. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28212. ret = WC_TEST_RET_ENC_EC(ret);
  28213. goto done;
  28214. }
  28215. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0);
  28216. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28217. ret = WC_TEST_RET_ENC_EC(ret);
  28218. goto done;
  28219. }
  28220. /* Change offset to produce bad input data. */
  28221. inOutIdx = 2;
  28222. inSz = sizeof(good) - inOutIdx;
  28223. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28224. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28225. ret = WC_TEST_RET_ENC_EC(ret);
  28226. goto done;
  28227. }
  28228. inOutIdx = 4;
  28229. inSz = sizeof(good) - inOutIdx;
  28230. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28231. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28232. ret = WC_TEST_RET_ENC_EC(ret);
  28233. goto done;
  28234. }
  28235. /* Bad data. */
  28236. inSz = sizeof(badNoObjId);
  28237. inOutIdx = 0;
  28238. ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz);
  28239. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28240. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28241. {
  28242. ret = WC_TEST_RET_ENC_EC(ret);
  28243. goto done;
  28244. }
  28245. inSz = sizeof(badOneObjId);
  28246. inOutIdx = 0;
  28247. ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz);
  28248. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28249. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28250. {
  28251. ret = WC_TEST_RET_ENC_EC(ret);
  28252. goto done;
  28253. }
  28254. inSz = sizeof(badObjId1Len);
  28255. inOutIdx = 0;
  28256. ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz);
  28257. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28258. ret = WC_TEST_RET_ENC_EC(ret);
  28259. goto done;
  28260. }
  28261. inSz = sizeof(badObj2d1Len);
  28262. inOutIdx = 0;
  28263. ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz);
  28264. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28265. ret = WC_TEST_RET_ENC_EC(ret);
  28266. goto done;
  28267. }
  28268. inSz = sizeof(badNotBitStr);
  28269. inOutIdx = 0;
  28270. ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz);
  28271. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E) &&
  28272. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28273. {
  28274. ret = WC_TEST_RET_ENC_EC(ret);
  28275. goto done;
  28276. }
  28277. inSz = sizeof(badBitStrLen);
  28278. inOutIdx = 0;
  28279. ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz);
  28280. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28281. ret = WC_TEST_RET_ENC_EC(ret);
  28282. goto done;
  28283. }
  28284. inSz = sizeof(badNoBitStrZero);
  28285. inOutIdx = 0;
  28286. ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz);
  28287. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  28288. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28289. {
  28290. ret = WC_TEST_RET_ENC_EC(ret);
  28291. goto done;
  28292. }
  28293. inSz = sizeof(badPoint);
  28294. inOutIdx = 0;
  28295. ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz);
  28296. if (ret != WC_NO_ERR_TRACE(ASN_ECC_KEY_E) &&
  28297. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28298. {
  28299. ret = WC_TEST_RET_ENC_EC(ret);
  28300. goto done;
  28301. }
  28302. inSz = sizeof(good);
  28303. inOutIdx = 0;
  28304. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28305. if (ret != 0)
  28306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28307. done:
  28308. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28309. if (key != NULL) {
  28310. wc_ecc_free(key);
  28311. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28312. }
  28313. #else
  28314. wc_ecc_free(key);
  28315. #endif
  28316. return ret;
  28317. }
  28318. #endif /* WOLFSSL_CERT_EXT */
  28319. #ifdef WOLFSSL_CUSTOM_CURVES
  28320. static const byte eccKeyExplicitCurve[] = {
  28321. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  28322. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  28323. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  28324. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  28325. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  28326. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28327. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28328. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  28329. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  28330. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  28331. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  28332. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  28333. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  28334. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  28335. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  28336. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  28337. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  28338. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  28339. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28340. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28341. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  28342. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  28343. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  28344. 0x3c, 0x4c, 0xc9, 0x5e, 0x2e, 0xa2, 0x3d, 0x49,
  28345. 0xcc, 0x5b, 0xff, 0x4f, 0xc9, 0x2e, 0x1d, 0x4a,
  28346. 0xc6, 0x21, 0xf6, 0xf3, 0xe6, 0x0b, 0x4f, 0xa9,
  28347. 0x9d, 0x74, 0x99, 0xdd, 0x97, 0xc7, 0x6e, 0xbe,
  28348. 0x14, 0x2b, 0x39, 0x9d, 0x63, 0xc7, 0x97, 0x0d,
  28349. 0x45, 0x25, 0x40, 0x30, 0x77, 0x05, 0x76, 0x88,
  28350. 0x38, 0x96, 0x29, 0x7d, 0x9c, 0xe1, 0x50, 0xbe,
  28351. 0xac, 0xf0, 0x1d, 0x86, 0xf4, 0x2f, 0x65, 0x0b
  28352. };
  28353. static wc_test_ret_t ecc_test_custom_curves(WC_RNG* rng)
  28354. {
  28355. wc_test_ret_t ret;
  28356. word32 inOutIdx;
  28357. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28358. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28359. #else
  28360. ecc_key key[1];
  28361. #endif
  28362. /* test use of custom curve - using BRAINPOOLP256R1 for test */
  28363. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28364. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28365. WOLFSSL_SMALL_STACK_STATIC const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
  28366. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
  28367. };
  28368. #define ecc_oid_brainpoolp256r1_sz \
  28369. (sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t))
  28370. #else
  28371. #define ecc_oid_brainpoolp256r1 { \
  28372. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 \
  28373. }
  28374. #define ecc_oid_brainpoolp256r1_sz 9
  28375. #endif
  28376. #define ecc_oid_brainpoolp256r1_sum 104
  28377. WOLFSSL_SMALL_STACK_STATIC const ecc_set_type ecc_dp_brainpool256r1 = {
  28378. 32, /* size/bytes */
  28379. ECC_CURVE_CUSTOM, /* ID */
  28380. "BRAINPOOLP256R1", /* curve name */
  28381. "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
  28382. "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
  28383. "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", /* B */
  28384. "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", /* order */
  28385. "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", /* Gx */
  28386. "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
  28387. ecc_oid_brainpoolp256r1, /* oid/oidSz */
  28388. ecc_oid_brainpoolp256r1_sz,
  28389. ecc_oid_brainpoolp256r1_sum, /* oid sum */
  28390. 1, /* cofactor */
  28391. };
  28392. #endif /* HAVE_ECC_BRAINPOOL */
  28393. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28394. if (! key) {
  28395. ret = MEMORY_E;
  28396. goto done;
  28397. }
  28398. #endif
  28399. XMEMSET(key, 0, sizeof *key);
  28400. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28401. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, ECC_CURVE_DEF,
  28402. &ecc_dp_brainpool256r1);
  28403. if (ret != 0) {
  28404. printf("ECC test for custom curve failed!\n");
  28405. goto done;
  28406. }
  28407. #endif
  28408. #if defined(HAVE_ECC_BRAINPOOL) || defined(HAVE_ECC_KOBLITZ)
  28409. {
  28410. int curve_id;
  28411. #ifdef HAVE_ECC_BRAINPOOL
  28412. curve_id = ECC_BRAINPOOLP256R1;
  28413. #else
  28414. curve_id = ECC_SECP256K1;
  28415. #endif
  28416. /* Test and demonstrate use of non-SECP curve */
  28417. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, curve_id, NULL);
  28418. if (ret < 0) {
  28419. printf("ECC test for curve_id %d failed!\n", curve_id);
  28420. goto done;
  28421. }
  28422. }
  28423. #endif
  28424. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  28425. if (ret != 0)
  28426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28427. inOutIdx = 0;
  28428. ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key,
  28429. sizeof(eccKeyExplicitCurve));
  28430. if (ret != 0)
  28431. ret = WC_TEST_RET_ENC_EC(ret);
  28432. done:
  28433. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28434. if (key) {
  28435. wc_ecc_free(key);
  28436. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28437. }
  28438. #else
  28439. wc_ecc_free(key);
  28440. #endif
  28441. (void)rng;
  28442. return ret;
  28443. }
  28444. #endif /* WOLFSSL_CUSTOM_CURVES */
  28445. #ifdef WOLFSSL_SM2
  28446. #ifdef HAVE_ECC_VERIFY
  28447. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28448. #ifdef HAVE_OID_ENCODING
  28449. #define CODED_SM2P256V1 {1,2,156,10197,1,301}
  28450. #define CODED_SM2P256V1_SZ 6
  28451. #else
  28452. #define CODED_SM2P256V1 {0x06,0x08,0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D}
  28453. #define CODED_SM2P256V1_SZ 10
  28454. #endif
  28455. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28456. static const ecc_oid_t ecc_oid_sm2p256v1[] = CODED_SM2P256V1;
  28457. #else
  28458. #define ecc_oid_sm2p256v1 CODED_SM2P256V1
  28459. #endif
  28460. #define ecc_oid_sm2p256v1_sz CODED_SM2P256V1_SZ
  28461. #define ECC_SM2P256V1_TEST 102
  28462. static int test_sm2_verify_caseA2(void)
  28463. {
  28464. ecc_key key;
  28465. int ret, res;
  28466. mp_int r,s;
  28467. /* test key values */
  28468. const char qx[] = "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A";
  28469. const char qy[] = "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857";
  28470. const char d[] = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
  28471. const ecc_set_type ecc_sm2_A2 = {
  28472. 32, /* size/bytes */
  28473. ECC_SM2P256V1_TEST, /* ID */
  28474. "SM2P256V1_TEST", /* curve name */
  28475. /* from test case A.2 in draft-shen-sm2-ecdsa-02 */
  28476. "8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", /* prime */
  28477. "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", /* A */
  28478. "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", /* B */
  28479. "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", /* order n */
  28480. "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", /* Gx */
  28481. "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", /* Gy */
  28482. ecc_oid_sm2p256v1, /* oid/oidSz */
  28483. ecc_oid_sm2p256v1_sz,
  28484. ECC_SM2P256V1_OID, /* oid sum */
  28485. 1, /* cofactor */
  28486. };
  28487. /* use canned hash value hash = H(ZA||M) */
  28488. const byte hash[] = {
  28489. 0xB5,0x24,0xF5,0x52,0xCD,0x82,0xB8,0xB0,
  28490. 0x28,0x47,0x6E,0x00,0x5C,0x37,0x7F,0xB1,
  28491. 0x9A,0x87,0xE6,0xFC,0x68,0x2D,0x48,0xBB,
  28492. 0x5D,0x42,0xE3,0xD9,0xB9,0xEF,0xFE,0x76
  28493. };
  28494. /* canned r and s */
  28495. const byte rCan[] = {
  28496. 0x40,0xF1,0xEC,0x59,0xF7,0x93,0xD9,0xF4,
  28497. 0x9E,0x09,0xDC,0xEF,0x49,0x13,0x0D,0x41,
  28498. 0x94,0xF7,0x9F,0xB1,0xEE,0xD2,0xCA,0xA5,
  28499. 0x5B,0xAC,0xDB,0x49,0xC4,0xE7,0x55,0xD1
  28500. };
  28501. const byte sCan[] = {
  28502. 0x6F,0xC6,0xDA,0xC3,0x2C,0x5D,0x5C,0xF1,
  28503. 0x0C,0x77,0xDF,0xB2,0x0F,0x7C,0x2E,0xB6,
  28504. 0x67,0xA4,0x57,0x87,0x2F,0xB0,0x9E,0xC5,
  28505. 0x63,0x27,0xA6,0x7E,0xC7,0xDE,0xEB,0xE7
  28506. };
  28507. mp_init(&r);
  28508. mp_init(&s);
  28509. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28510. if (ret != 0)
  28511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28512. ret = wc_ecc_set_custom_curve(&key, &ecc_sm2_A2);
  28513. if (ret != 0)
  28514. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28515. ret = wc_ecc_import_raw_ex(&key, qx, qy, d, ECC_SM2P256V1_TEST);
  28516. if (ret != 0)
  28517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28518. mp_read_unsigned_bin(&r, rCan, sizeof(rCan));
  28519. mp_read_unsigned_bin(&s, sCan, sizeof(sCan));
  28520. ret = wc_ecc_sm2_verify_hash_ex(&r, &s, hash, sizeof(hash), &res, &key);
  28521. if (ret != 0)
  28522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28523. if (res != 1)
  28524. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28525. done:
  28526. mp_free(&r);
  28527. mp_free(&s);
  28528. wc_ecc_free(&key);
  28529. return ret;
  28530. }
  28531. #endif /* WOLFSSL_PUBLIC_MP && WOLFSSL_CUSTOM_CURVES */
  28532. static int test_sm2_verify_case(void)
  28533. {
  28534. ecc_key key;
  28535. int ret, res;
  28536. /* test key values */
  28537. const char qx[] = "637F1B135036C933DC3F7A8EBB1B7B2FD1DFBD268D4F894B5AD47DBDBECD558F";
  28538. const char qy[] = "E88101D08048E36CCBF61CA38DDF7ABA542B4486E99E49F3A7470A857A096433";
  28539. /* use canned hash value hash = H(ZA||M) */
  28540. const byte hash[] = {
  28541. 0x3B,0xFA,0x5F,0xFB,0xC4,0x27,0x8C,0x9D,
  28542. 0x02,0x3A,0x19,0xCB,0x1E,0xAA,0xD2,0xF1,
  28543. 0x50,0x69,0x5B,0x20
  28544. };
  28545. const byte sig[] = {
  28546. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28547. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28548. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28549. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28550. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28551. 0xB5,0xB5,0xD9,0xD8,0xF1,0x20,0xDD,0x97,
  28552. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28553. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28554. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28555. };
  28556. const byte badSig[] = {
  28557. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28558. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28559. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28560. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28561. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28562. 0xB5,0xB5,0xE9,0xD8,0xF1,0x20,0xDD,0x97,
  28563. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28564. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28565. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28566. };
  28567. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28568. if (ret != 0)
  28569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28570. ret = wc_ecc_import_raw(&key, qx, qy, NULL, "SM2P256V1");
  28571. if (ret != 0)
  28572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28573. ret = wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash), &res,
  28574. &key);
  28575. if (ret != 0)
  28576. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28577. if (res != 1)
  28578. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28579. /* now test a case that should fail */
  28580. ret = wc_ecc_sm2_verify_hash(badSig, sizeof(badSig), hash, sizeof(hash),
  28581. &res, &key);
  28582. if (ret != 0)
  28583. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28584. if (res == 1)
  28585. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28586. done:
  28587. wc_ecc_free(&key);
  28588. return ret;
  28589. }
  28590. static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
  28591. {
  28592. const ecc_set_type* dp = wc_ecc_get_curve_params(
  28593. wc_ecc_get_curve_idx(ECC_SM2P256V1));
  28594. int keySize = 32;
  28595. int curve_id = ECC_SM2P256V1;
  28596. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28597. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28598. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28599. #endif
  28600. #ifdef HAVE_ECC_KEY_EXPORT
  28601. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  28602. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28603. #endif
  28604. word32 x = 0;
  28605. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28606. word32 y;
  28607. #endif
  28608. #ifdef HAVE_ECC_SIGN
  28609. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28610. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28611. int i;
  28612. int verify;
  28613. #endif /* HAVE_ECC_SIGN */
  28614. int ret;
  28615. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28616. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28617. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28618. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28619. #else
  28620. ecc_key userA[1];
  28621. ecc_key userB[1];
  28622. ecc_key pubKey[1];
  28623. #endif
  28624. #ifndef WC_NO_RNG
  28625. int curveSize;
  28626. #endif
  28627. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28628. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28629. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28630. #endif
  28631. #ifdef HAVE_ECC_KEY_EXPORT
  28632. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28633. #endif
  28634. #ifdef HAVE_ECC_SIGN
  28635. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28636. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28637. #endif
  28638. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  28639. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28640. if (sharedA == NULL || sharedB == NULL)
  28641. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28642. #endif
  28643. #ifdef HAVE_ECC_KEY_EXPORT
  28644. if (exportBuf == NULL)
  28645. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28646. #endif
  28647. #ifdef HAVE_ECC_SIGN
  28648. if (sig == NULL || digest == NULL)
  28649. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28650. #endif
  28651. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  28652. (void)testVerifyCount;
  28653. (void)dp;
  28654. (void)x;
  28655. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28656. if ((userA == NULL) ||
  28657. (userB == NULL) ||
  28658. (pubKey == NULL))
  28659. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28660. #endif
  28661. XMEMSET(userA, 0, sizeof *userA);
  28662. XMEMSET(userB, 0, sizeof *userB);
  28663. XMEMSET(pubKey, 0, sizeof *pubKey);
  28664. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  28665. if (ret != 0)
  28666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28667. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  28668. if (ret != 0)
  28669. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28670. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28671. if (ret != 0)
  28672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28673. #ifndef WC_NO_RNG
  28674. ret = wc_ecc_sm2_make_key(rng, userA, WC_ECC_FLAG_NONE);
  28675. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  28676. goto done; /* catch case, where curve is not supported */
  28677. if (ret != 0)
  28678. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28679. TEST_SLEEP();
  28680. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  28681. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  28682. if (curveSize != userA->dp->size) {
  28683. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28684. }
  28685. }
  28686. ret = wc_ecc_check_key(userA);
  28687. if (ret != 0)
  28688. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28689. TEST_SLEEP();
  28690. ret = wc_ecc_sm2_make_key(rng, userB, WC_ECC_FLAG_NONE);
  28691. if (ret != 0)
  28692. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28693. /* only perform the below tests if the key size matches */
  28694. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  28695. if (ret != 0) {
  28696. ret = ECC_CURVE_OID_E;
  28697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28698. }
  28699. #ifdef HAVE_ECC_DHE
  28700. #if defined(ECC_TIMING_RESISTANT)
  28701. ret = wc_ecc_set_rng(userA, rng);
  28702. if (ret != 0)
  28703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28704. ret = wc_ecc_set_rng(userB, rng);
  28705. if (ret != 0)
  28706. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28707. #endif
  28708. x = ECC_SHARED_SIZE;
  28709. ret = wc_ecc_sm2_shared_secret(userA, userB, sharedA, &x);
  28710. if (ret != 0)
  28711. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28712. y = ECC_SHARED_SIZE;
  28713. ret = wc_ecc_sm2_shared_secret(userB, userA, sharedB, &y);
  28714. if (ret != 0)
  28715. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28716. if (y != x)
  28717. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28718. if (XMEMCMP(sharedA, sharedB, x))
  28719. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28720. #endif /* HAVE_ECC_DHE */
  28721. #ifdef HAVE_ECC_KEY_EXPORT
  28722. x = ECC_KEY_EXPORT_BUF_SIZE;
  28723. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  28724. if (ret != 0)
  28725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28726. #ifdef HAVE_ECC_KEY_IMPORT
  28727. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28728. if (ret != 0)
  28729. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28730. #ifdef HAVE_ECC_DHE
  28731. y = ECC_SHARED_SIZE;
  28732. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28733. if (ret != 0)
  28734. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28735. if (XMEMCMP(sharedA, sharedB, y))
  28736. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28737. #endif /* HAVE_ECC_DHE */
  28738. #ifdef HAVE_COMP_KEY
  28739. /* try compressed export / import too */
  28740. x = ECC_KEY_EXPORT_BUF_SIZE;
  28741. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  28742. if (ret != 0)
  28743. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28744. wc_ecc_free(pubKey);
  28745. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28746. if (ret != 0)
  28747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28748. #endif
  28749. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28750. if (ret != 0)
  28751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28752. #ifdef HAVE_ECC_DHE
  28753. y = ECC_SHARED_SIZE;
  28754. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28755. if (ret != 0)
  28756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28757. if (XMEMCMP(sharedA, sharedB, y))
  28758. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28759. #endif /* HAVE_ECC_DHE */
  28760. #endif /* HAVE_ECC_KEY_IMPORT */
  28761. #endif /* HAVE_ECC_KEY_EXPORT */
  28762. #endif /* !WC_NO_RNG */
  28763. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  28764. !defined(WC_NO_RNG))
  28765. #ifdef HAVE_ECC_SIGN
  28766. /* ECC w/out Shamir has issue with all 0 digest */
  28767. /* WC_BIGINT doesn't have 0 len well on hardware */
  28768. /* Cryptocell has issues with all 0 digest */
  28769. #if defined(ECC_SHAMIR)
  28770. /* test DSA sign hash with zeros */
  28771. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28772. digest[i] = 0;
  28773. }
  28774. x = ECC_SIG_SIZE;
  28775. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28776. if (ret != 0)
  28777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28778. for (i = 0; i < testVerifyCount; i++) {
  28779. verify = 0;
  28780. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28781. userA);
  28782. if (ret != 0)
  28783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28784. if (verify != 1)
  28785. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28786. }
  28787. #endif /* ECC_SHAMIR */
  28788. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  28789. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28790. digest[i] = (byte)i;
  28791. }
  28792. x = ECC_SIG_SIZE;
  28793. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28794. if (ret != 0)
  28795. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28796. for (i = 0; i < testVerifyCount; i++) {
  28797. verify = 0;
  28798. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28799. userA);
  28800. if (ret != 0)
  28801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28802. if (verify != 1)
  28803. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28804. }
  28805. #endif /* HAVE_ECC_SIGN */
  28806. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT && !WC_NO_RNG) */
  28807. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  28808. x = ECC_KEY_EXPORT_BUF_SIZE;
  28809. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  28810. if (ret != 0)
  28811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28812. #elif defined(HAVE_ECC_KEY_EXPORT)
  28813. (void)exportBuf;
  28814. #endif /* HAVE_ECC_KEY_EXPORT */
  28815. done:
  28816. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28817. if (userA != NULL) {
  28818. wc_ecc_free(userA);
  28819. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28820. }
  28821. if (userB != NULL) {
  28822. wc_ecc_free(userB);
  28823. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28824. }
  28825. if (pubKey != NULL) {
  28826. wc_ecc_free(pubKey);
  28827. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28828. }
  28829. #else
  28830. wc_ecc_free(pubKey);
  28831. wc_ecc_free(userB);
  28832. wc_ecc_free(userA);
  28833. #endif
  28834. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  28835. WC_FREE_VAR(sharedA, HEAP_HINT);
  28836. WC_FREE_VAR(sharedB, HEAP_HINT);
  28837. #endif
  28838. #ifdef HAVE_ECC_KEY_EXPORT
  28839. WC_FREE_VAR(exportBuf, HEAP_HINT);
  28840. #endif
  28841. #ifdef HAVE_ECC_SIGN
  28842. WC_FREE_VAR(sig, HEAP_HINT);
  28843. WC_FREE_VAR(digest, HEAP_HINT);
  28844. #endif
  28845. (void)keySize;
  28846. (void)curve_id;
  28847. (void)rng;
  28848. return ret;
  28849. }
  28850. #endif /* HAVE_ECC_VERIFY */
  28851. static int test_sm2_create_digest(void)
  28852. {
  28853. #ifndef WOLFSSL_SM3
  28854. const byte msg[] = "message to sign";
  28855. const byte id[] = "0123456789";
  28856. const byte badId[] = "0123556789";
  28857. byte expected[] = {
  28858. 0xdd, 0x4d, 0x65, 0x49, 0xa3, 0x64, 0x76, 0xc0,
  28859. 0x73, 0x05, 0xdc, 0x05, 0x16, 0xb5, 0xee, 0x9f,
  28860. 0x82, 0xf9, 0xe9, 0x7d, 0x01, 0x1a, 0xdc, 0x88,
  28861. 0x5a, 0x59, 0x9c, 0x44, 0xcc, 0x47, 0xa4, 0x78
  28862. };
  28863. ecc_key key;
  28864. int ret;
  28865. /* test key values */
  28866. const char qx[] =
  28867. "af178b7b8740cc9d5b493fbd22049c12621bc27dcc5802e75ff4d045a4158baf";
  28868. const char qy[] =
  28869. "89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
  28870. const char d[] =
  28871. "b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
  28872. int hash_type = WC_HASH_TYPE_SHA256;
  28873. byte digest[WC_SHA256_DIGEST_SIZE];
  28874. #else
  28875. ecc_key key;
  28876. int ret;
  28877. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
  28878. 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
  28879. const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28880. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28881. 0x00 };
  28882. const byte badId[] = "0123556789";
  28883. const char qx[] =
  28884. "09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
  28885. const char qy[] =
  28886. "CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
  28887. const char d[] =
  28888. "3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
  28889. byte expected[] = {
  28890. 0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
  28891. 0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
  28892. 0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
  28893. 0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
  28894. };
  28895. int hash_type = WC_HASH_TYPE_SM3;
  28896. byte digest[WC_SM3_DIGEST_SIZE];
  28897. #endif
  28898. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28899. if (ret != 0)
  28900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28901. ret = wc_ecc_import_raw(&key, qx, qy, d, "SM2P256V1");
  28902. if (ret != 0)
  28903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28904. ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
  28905. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28906. &key);
  28907. if (ret != 0)
  28908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28909. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
  28910. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28911. ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
  28912. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28913. &key);
  28914. if (ret != 0)
  28915. goto done;
  28916. /* should be different than the previous ID used */
  28917. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) == 0)
  28918. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28919. done:
  28920. wc_ecc_free(&key);
  28921. return ret;
  28922. }
  28923. static int test_sm2_verify(void)
  28924. {
  28925. int ret = 0;
  28926. #ifdef HAVE_ECC_VERIFY
  28927. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28928. ret = test_sm2_verify_caseA2();
  28929. if (ret != 0)
  28930. return ret;
  28931. #endif
  28932. ret = test_sm2_verify_case();
  28933. if (ret != 0)
  28934. return ret;
  28935. #endif /* HAVE_ECC_VERIFY */
  28936. ret = test_sm2_create_digest();
  28937. return ret;
  28938. }
  28939. #endif /* WOLFSSL_SM2 */
  28940. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  28941. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  28942. /* Make Cert / Sign example for ECC cert and ECC CA */
  28943. static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
  28944. {
  28945. wc_test_ret_t ret;
  28946. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28947. Cert *myCert = (Cert *)XMALLOC(sizeof *myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28948. #ifdef WOLFSSL_TEST_CERT
  28949. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28950. #endif
  28951. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28952. ecc_key *certPubKey = (ecc_key *)XMALLOC(sizeof *certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28953. #else
  28954. Cert myCert[1];
  28955. #ifdef WOLFSSL_TEST_CERT
  28956. DecodedCert decode[1];
  28957. #endif
  28958. ecc_key caEccKey[1];
  28959. ecc_key certPubKey[1];
  28960. #endif
  28961. int certSz;
  28962. size_t bytes = 0;
  28963. word32 idx = 0;
  28964. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
  28965. XFILE file;
  28966. #endif
  28967. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28968. byte* der = NULL;
  28969. #else
  28970. byte der[FOURK_BUF];
  28971. #endif
  28972. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28973. if ((myCert == NULL)
  28974. #ifdef WOLFSSL_TEST_CERT
  28975. || (decode == NULL)
  28976. #endif
  28977. || (caEccKey == NULL) || (certPubKey == NULL))
  28978. ERROR_OUT(MEMORY_E, exit);
  28979. #endif
  28980. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  28981. XMEMSET(certPubKey, 0, sizeof *certPubKey);
  28982. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28983. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28984. if (der == NULL) {
  28985. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28986. }
  28987. #endif
  28988. /* Get cert private key */
  28989. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28990. /* Get Cert Key 384 */
  28991. #ifdef USE_CERT_BUFFERS_256
  28992. XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
  28993. bytes = sizeof_ca_ecc_key_der_384;
  28994. #elif !defined(NO_FILESYSTEM)
  28995. file = XFOPEN(eccCaKey384File, "rb");
  28996. if (!file) {
  28997. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28998. }
  28999. bytes = XFREAD(der, 1, FOURK_BUF, file);
  29000. XFCLOSE(file);
  29001. if (bytes == 0)
  29002. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29003. (void)eccCaKeyFile;
  29004. #else
  29005. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
  29006. ERROR_OUT(ASN_PARSE_E, exit);
  29007. #endif /* USE_CERT_BUFFERS_256 */
  29008. /* end if ENABLE_ECC384_CERT_GEN_TEST */
  29009. #else
  29010. /* !ENABLE_ECC384_CERT_GEN_TEST */
  29011. #ifdef USE_CERT_BUFFERS_256
  29012. XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
  29013. bytes = sizeof_ca_ecc_key_der_256;
  29014. #else
  29015. file = XFOPEN(eccCaKeyFile, "rb");
  29016. if (!file) {
  29017. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29018. }
  29019. bytes = XFREAD(der, 1, FOURK_BUF, file);
  29020. XFCLOSE(file);
  29021. if (bytes == 0)
  29022. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29023. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29024. (void)eccCaKey384File;
  29025. #endif
  29026. #endif /* USE_CERT_BUFFERS_256 */
  29027. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29028. /* Get CA Key */
  29029. ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId);
  29030. if (ret != 0)
  29031. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29032. ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes);
  29033. if (ret != 0)
  29034. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29035. /* Make a public key */
  29036. ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId);
  29037. if (ret != 0)
  29038. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29039. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey);
  29040. #if defined(WOLFSSL_ASYNC_CRYPT)
  29041. ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE);
  29042. #endif
  29043. if (ret != 0)
  29044. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29045. TEST_SLEEP();
  29046. /* Setup Certificate */
  29047. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  29048. if (ret != 0)
  29049. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29050. #ifndef NO_SHA256
  29051. myCert->sigType = CTC_SHA256wECDSA;
  29052. #else
  29053. myCert->sigType = CTC_SHAwECDSA;
  29054. #endif
  29055. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  29056. #ifdef WOLFSSL_CERT_EXT
  29057. /* add Policies */
  29058. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  29059. CTC_MAX_CERTPOL_SZ);
  29060. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  29061. CTC_MAX_CERTPOL_SZ);
  29062. myCert->certPoliciesNb = 2;
  29063. /* add SKID from the Public Key */
  29064. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey);
  29065. if (ret != 0)
  29066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29067. /* add AKID from the Public Key */
  29068. ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey);
  29069. if (ret != 0)
  29070. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29071. /* add Key Usage */
  29072. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  29073. if (ret != 0)
  29074. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29075. #endif /* WOLFSSL_CERT_EXT */
  29076. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29077. #if defined(USE_CERT_BUFFERS_256)
  29078. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
  29079. sizeof_ca_ecc_cert_der_384);
  29080. #elif !defined(NO_FILESYSTEM)
  29081. ret = wc_SetIssuer(myCert, eccCaCert384File);
  29082. (void)eccCaCertFile;
  29083. #else
  29084. /* not testing with embedded, no file system target */
  29085. ERROR_OUT(ASN_PARSE_E, exit);
  29086. #endif /* USE_CERT_BUFFERS_256 */
  29087. #else
  29088. /* not ENABLE_ECC384_CERT_GEN_TEST */
  29089. #if defined(USE_CERT_BUFFERS_256)
  29090. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
  29091. sizeof_ca_ecc_cert_der_256);
  29092. #else
  29093. ret = wc_SetIssuer(myCert, eccCaCertFile);
  29094. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29095. (void)eccCaCert384File;
  29096. #endif
  29097. #endif
  29098. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29099. if (ret < 0)
  29100. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29101. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng);
  29102. if (certSz < 0) {
  29103. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit);
  29104. }
  29105. ret = 0;
  29106. do {
  29107. #if defined(WOLFSSL_ASYNC_CRYPT)
  29108. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  29109. #endif
  29110. if (ret >= 0) {
  29111. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  29112. FOURK_BUF, NULL, caEccKey, rng);
  29113. }
  29114. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  29115. if (ret < 0)
  29116. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29117. certSz = (int)ret;
  29118. TEST_SLEEP();
  29119. #ifdef WOLFSSL_TEST_CERT
  29120. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  29121. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  29122. if (ret != 0) {
  29123. FreeDecodedCert(decode);
  29124. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29125. }
  29126. FreeDecodedCert(decode);
  29127. #endif
  29128. ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile,
  29129. CERT_TYPE);
  29130. if (ret != 0) {
  29131. goto exit;
  29132. }
  29133. exit:
  29134. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29135. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29136. #endif
  29137. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29138. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29139. #ifdef WOLFSSL_TEST_CERT
  29140. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29141. #endif
  29142. if (caEccKey != NULL) {
  29143. wc_ecc_free(caEccKey);
  29144. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29145. }
  29146. if (certPubKey != NULL) {
  29147. wc_ecc_free(certPubKey);
  29148. XFREE(certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29149. }
  29150. #else
  29151. wc_ecc_free(certPubKey);
  29152. wc_ecc_free(caEccKey);
  29153. #endif
  29154. return ret;
  29155. }
  29156. #endif /* WOLFSSL_CERT_GEN */
  29157. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  29158. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
  29159. (!defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES))
  29160. /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */
  29161. static wc_test_ret_t ecc_test_allocator(WC_RNG* rng)
  29162. {
  29163. wc_test_ret_t ret = 0;
  29164. ecc_key* key;
  29165. #ifdef WC_NO_RNG
  29166. word32 idx = 0;
  29167. #endif
  29168. key = wc_ecc_key_new(HEAP_HINT);
  29169. if (key == NULL) {
  29170. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29171. }
  29172. #ifndef WC_NO_RNG
  29173. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  29174. #if defined(WOLFSSL_ASYNC_CRYPT)
  29175. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  29176. #endif
  29177. if (ret != 0)
  29178. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29179. #else
  29180. /* use test ECC key */
  29181. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  29182. (word32)sizeof_ecc_key_der_256);
  29183. (void)rng;
  29184. #endif
  29185. exit:
  29186. wc_ecc_key_free(key);
  29187. return ret;
  29188. }
  29189. #endif
  29190. /* ECC Non-blocking tests for Sign and Verify */
  29191. /* Requires SP math and supports P384 or P256 */
  29192. /* ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" */
  29193. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_HAVE_SP_ECC) && \
  29194. defined(WOLFSSL_PUBLIC_MP)
  29195. /* ECC Private Key "d" */
  29196. static const byte p256PrivKey[] = {
  29197. /* SECP256R1 */
  29198. /* d */
  29199. 0x1e, 0xe7, 0x70, 0x07, 0xd3, 0x30, 0x94, 0x39,
  29200. 0x28, 0x90, 0xdf, 0x23, 0x88, 0x2c, 0x4a, 0x34,
  29201. 0x15, 0xdb, 0x4c, 0x43, 0xcd, 0xfa, 0xe5, 0x1f,
  29202. 0x3d, 0x4c, 0x37, 0xfe, 0x59, 0x3b, 0x96, 0xd8
  29203. };
  29204. #ifdef HAVE_ECC384
  29205. static const byte p384PrivKey[] = {
  29206. /* SECP384R1 */
  29207. /* d */
  29208. 0xa4, 0xe5, 0x06, 0xe8, 0x06, 0x16, 0x3e, 0xab,
  29209. 0x89, 0xf8, 0x60, 0x43, 0xc0, 0x60, 0x25, 0xdb,
  29210. 0xba, 0x7b, 0xfe, 0x19, 0x35, 0x08, 0x55, 0x65,
  29211. 0x76, 0xe2, 0xdc, 0xe0, 0x01, 0x8b, 0x6b, 0x68,
  29212. 0xdf, 0xcf, 0x6f, 0x80, 0x12, 0xce, 0x79, 0x37,
  29213. 0xeb, 0x2b, 0x9c, 0x7b, 0xc4, 0x68, 0x1c, 0x74
  29214. };
  29215. #endif /* HAVE_ECC384 */
  29216. #ifdef HAVE_ECC521
  29217. static const byte p521PrivKey[] = {
  29218. /* SECP521R1 */
  29219. /* d */
  29220. 0x01, 0x68, 0x91, 0x33, 0x53, 0xe2, 0x90, 0x68,
  29221. 0x11, 0x8f, 0xaa, 0xa8, 0x76, 0x0c, 0xf7, 0x2a,
  29222. 0x07, 0x1b, 0x92, 0x2a, 0xa7, 0x82, 0x3d, 0xfa,
  29223. 0x83, 0xce, 0x70, 0xc8, 0xc2, 0x60, 0x82, 0xfe,
  29224. 0x18, 0x88, 0x68, 0xda, 0x6a, 0x83, 0x46, 0x78,
  29225. 0xe4, 0xe9, 0xe9, 0xcc, 0x51, 0x7f, 0xed, 0x81,
  29226. 0x02, 0x32, 0xee, 0x26, 0x87, 0xcc, 0xed, 0x63,
  29227. 0x3f, 0x39, 0x27, 0xf0, 0xd7, 0x17, 0x77, 0xa1,
  29228. 0xa4, 0x36
  29229. };
  29230. #endif /* HAVE_ECC521 */
  29231. /* ECC public key Qx/Qy */
  29232. static const byte p256PubKey[] = {
  29233. /* SECP256R1 */
  29234. /* Qx */
  29235. 0x96, 0x93, 0x1c, 0x53, 0x0b, 0x43, 0x6c, 0x42,
  29236. 0x0c, 0x52, 0x90, 0xe4, 0xa7, 0xec, 0x98, 0xb1,
  29237. 0xaf, 0xd4, 0x14, 0x49, 0xd8, 0xc1, 0x42, 0x82,
  29238. 0x04, 0x78, 0xd1, 0x90, 0xae, 0xa0, 0x6c, 0x07,
  29239. /* Qy */
  29240. 0xf2, 0x3a, 0xb5, 0x10, 0x32, 0x8d, 0xce, 0x9e,
  29241. 0x76, 0xa0, 0xd2, 0x8c, 0xf3, 0xfc, 0xa9, 0x94,
  29242. 0x43, 0x24, 0xe6, 0x82, 0x00, 0x40, 0xc6, 0xdb,
  29243. 0x1c, 0x2f, 0xcd, 0x38, 0x4b, 0x60, 0xdd, 0x61
  29244. };
  29245. #ifdef HAVE_ECC384
  29246. static const byte p384PubKey[] = {
  29247. /* SECP384R1 */
  29248. /* Qx */
  29249. 0xea, 0xcf, 0x93, 0x4f, 0x2c, 0x09, 0xbb, 0x39,
  29250. 0x14, 0x0f, 0x56, 0x64, 0xc3, 0x40, 0xb4, 0xdf,
  29251. 0x0e, 0x63, 0xae, 0xe5, 0x71, 0x4b, 0x00, 0xcc,
  29252. 0x04, 0x97, 0xff, 0xe1, 0xe9, 0x38, 0x96, 0xbb,
  29253. 0x5f, 0x91, 0xb2, 0x6a, 0xcc, 0xb5, 0x39, 0x5f,
  29254. 0x8f, 0x70, 0x59, 0xf1, 0x01, 0xf6, 0x5a, 0x2b,
  29255. /* Qy */
  29256. 0x01, 0x6c, 0x68, 0x0b, 0xcf, 0x55, 0x25, 0xaf,
  29257. 0x6d, 0x98, 0x48, 0x0a, 0xa8, 0x74, 0xc9, 0xa9,
  29258. 0x17, 0xa0, 0x0c, 0xc3, 0xfb, 0xd3, 0x23, 0x68,
  29259. 0xfe, 0x04, 0x3c, 0x63, 0x50, 0x88, 0x3b, 0xb9,
  29260. 0x4f, 0x7c, 0x67, 0x34, 0xf7, 0x3b, 0xa9, 0x73,
  29261. 0xe7, 0x1b, 0xc3, 0x51, 0x5e, 0x22, 0x18, 0xec
  29262. };
  29263. #endif
  29264. #ifdef HAVE_ECC521
  29265. static const byte p521PubKey[] = {
  29266. /* SECP521R1 */
  29267. /* Qx */
  29268. 0x01, 0x62, 0x6e, 0xf1, 0x00, 0xec, 0xd8, 0x99,
  29269. 0x58, 0x9b, 0x80, 0x6b, 0xfe, 0x2c, 0xf1, 0xb2,
  29270. 0xf0, 0xc8, 0x48, 0xdf, 0xac, 0xd2, 0x3b, 0x71,
  29271. 0x29, 0xab, 0xf0, 0x66, 0x63, 0xd8, 0x8e, 0xb5,
  29272. 0xc8, 0xc2, 0xfc, 0x99, 0x44, 0xe2, 0x45, 0xb1,
  29273. 0x5a, 0x7b, 0xb9, 0x73, 0x01, 0xda, 0x79, 0xec,
  29274. 0x9c, 0x26, 0x27, 0x34, 0x45, 0x26, 0xd5, 0x89,
  29275. 0x4b, 0x44, 0xfe, 0x69, 0x4e, 0x72, 0x14, 0xe3,
  29276. 0x8b, 0xbc,
  29277. /* Qy */
  29278. 0x00, 0x0f, 0x09, 0xa2, 0x03, 0xc3, 0x5a, 0xdc,
  29279. 0x95, 0x82, 0xf6, 0xf9, 0xf6, 0x9c, 0xff, 0xb5,
  29280. 0x6b, 0x75, 0x95, 0x4b, 0xa4, 0x28, 0x5d, 0x9e,
  29281. 0x90, 0x04, 0xd1, 0xc0, 0x1e, 0xd5, 0xfd, 0x43,
  29282. 0x9e, 0x1e, 0x83, 0xc0, 0x11, 0x2b, 0x2b, 0x07,
  29283. 0x6d, 0xa9, 0x7a, 0x10, 0xd7, 0x67, 0xe7, 0x51,
  29284. 0x37, 0x24, 0xd8, 0xbf, 0x03, 0x0d, 0x8b, 0xb5,
  29285. 0x40, 0x5c, 0x4f, 0xd6, 0x13, 0x73, 0x42, 0xbc,
  29286. 0x91, 0xd9
  29287. };
  29288. /* perform verify of signature and hash using public key */
  29289. /* key is public Qx + public Qy */
  29290. /* sig is r + s */
  29291. static wc_test_ret_t crypto_ecc_verify(const byte *key, uint32_t keySz,
  29292. const byte *hash, uint32_t hashSz, const byte *sig, uint32_t sigSz,
  29293. uint32_t curveSz, int curveId)
  29294. {
  29295. wc_test_ret_t ret;
  29296. int verify_res = 0, count = 0;
  29297. mp_int r, s;
  29298. ecc_key ecc;
  29299. ecc_nb_ctx_t nb_ctx;
  29300. /* validate arguments */
  29301. if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 ||
  29302. hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2))
  29303. {
  29304. return WC_TEST_RET_ENC_NC;
  29305. }
  29306. /* Setup the ECC key */
  29307. ret = wc_ecc_init(&ecc);
  29308. if (ret < 0) {
  29309. return WC_TEST_RET_ENC_EC(ret);
  29310. }
  29311. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29312. if (ret != MP_OKAY) {
  29313. wc_ecc_free(&ecc);
  29314. return WC_TEST_RET_ENC_EC(ret);
  29315. }
  29316. /* Setup the signature r/s variables */
  29317. ret = mp_init(&r);
  29318. if (ret != MP_OKAY) {
  29319. wc_ecc_free(&ecc);
  29320. return WC_TEST_RET_ENC_EC(ret);
  29321. }
  29322. ret = mp_init(&s);
  29323. if (ret != MP_OKAY) {
  29324. mp_clear(&r);
  29325. wc_ecc_free(&ecc);
  29326. return WC_TEST_RET_ENC_EC(ret);
  29327. }
  29328. /* Import public key x/y */
  29329. ret = wc_ecc_import_unsigned(
  29330. &ecc,
  29331. (byte*)key, /* Public "x" Coordinate */
  29332. (byte*)(key + curveSz), /* Public "y" Coordinate */
  29333. NULL, /* Private "d" (optional) */
  29334. curveId /* ECC Curve Id */
  29335. );
  29336. /* Make sure it was a public key imported */
  29337. if (ret == 0 && ecc.type != ECC_PUBLICKEY) {
  29338. ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */
  29339. }
  29340. /* Import signature r/s */
  29341. if (ret == 0) {
  29342. ret = mp_read_unsigned_bin(&r, sig, curveSz);
  29343. if (ret < 0)
  29344. ret = WC_TEST_RET_ENC_EC(ret);
  29345. }
  29346. if (ret == 0) {
  29347. ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz);
  29348. if (ret < 0)
  29349. ret = WC_TEST_RET_ENC_EC(ret);
  29350. }
  29351. /* Verify ECC Signature */
  29352. if (ret == 0) {
  29353. do {
  29354. ret = wc_ecc_verify_hash_ex(
  29355. &r, &s, /* r/s as mp_int */
  29356. hash, hashSz, /* computed hash digest */
  29357. &verify_res, /* verification result 1=success */
  29358. &ecc
  29359. );
  29360. count++;
  29361. /* This is where real-time work could be called */
  29362. } while (ret == FP_WOULDBLOCK);
  29363. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29364. printf("ECC non-block verify: %d times\n", count);
  29365. #endif
  29366. if (ret < 0)
  29367. ret = WC_TEST_RET_ENC_EC(ret);
  29368. }
  29369. /* check verify result */
  29370. if (ret == 0 && verify_res == 0) {
  29371. ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */;
  29372. }
  29373. mp_clear(&r);
  29374. mp_clear(&s);
  29375. wc_ecc_free(&ecc);
  29376. (void)count;
  29377. return ret;
  29378. }
  29379. /* perform signature operation against hash using private key */
  29380. static wc_test_ret_t crypto_ecc_sign(const byte *key, uint32_t keySz,
  29381. const byte *hash, uint32_t hashSz, byte *sig, uint32_t* sigSz,
  29382. uint32_t curveSz, int curveId, WC_RNG* rng)
  29383. {
  29384. wc_test_ret_t ret;
  29385. int count = 0;
  29386. mp_int r, s;
  29387. ecc_key ecc;
  29388. ecc_nb_ctx_t nb_ctx;
  29389. /* validate arguments */
  29390. if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL ||
  29391. curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2))
  29392. {
  29393. return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */;
  29394. }
  29395. /* Initialize signature result */
  29396. memset(sig, 0, curveSz*2);
  29397. /* Setup the ECC key */
  29398. ret = wc_ecc_init(&ecc);
  29399. if (ret < 0) {
  29400. return WC_TEST_RET_ENC_EC(ret);
  29401. }
  29402. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29403. if (ret != MP_OKAY) {
  29404. wc_ecc_free(&ecc);
  29405. return WC_TEST_RET_ENC_EC(ret);
  29406. }
  29407. /* Setup the signature r/s variables */
  29408. ret = mp_init(&r);
  29409. if (ret != MP_OKAY) {
  29410. wc_ecc_free(&ecc);
  29411. return WC_TEST_RET_ENC_EC(ret);
  29412. }
  29413. ret = mp_init(&s);
  29414. if (ret != MP_OKAY) {
  29415. mp_clear(&r);
  29416. wc_ecc_free(&ecc);
  29417. return WC_TEST_RET_ENC_EC(ret);
  29418. }
  29419. /* Import private key "k" */
  29420. ret = wc_ecc_import_private_key_ex(
  29421. key, keySz, /* private key "d" */
  29422. NULL, 0, /* public (optional) */
  29423. &ecc,
  29424. curveId /* ECC Curve Id */
  29425. );
  29426. if (ret < 0)
  29427. ret = WC_TEST_RET_ENC_EC(ret);
  29428. if (ret == 0) {
  29429. do {
  29430. /* Verify ECC Signature */
  29431. ret = wc_ecc_sign_hash_ex(
  29432. hash, hashSz, /* computed hash digest */
  29433. rng, &ecc, /* random and key context */
  29434. &r, &s /* r/s as mp_int */
  29435. );
  29436. count++;
  29437. /* This is where real-time work could be called */
  29438. } while (ret == FP_WOULDBLOCK);
  29439. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29440. printf("ECC non-block sign: %d times\n", count);
  29441. #endif
  29442. if (ret < 0)
  29443. ret = WC_TEST_RET_ENC_EC(ret);
  29444. }
  29445. if (ret == 0) {
  29446. /* export r/s */
  29447. mp_to_unsigned_bin_len(&r, sig, curveSz);
  29448. mp_to_unsigned_bin_len(&s, sig + curveSz, curveSz);
  29449. }
  29450. mp_clear(&r);
  29451. mp_clear(&s);
  29452. wc_ecc_free(&ecc);
  29453. (void)count;
  29454. return ret;
  29455. }
  29456. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29457. /*
  29458. * This test doesn't work with WOLFSSL_VALIDATE_ECC_KEYGEN defined because we
  29459. * don't have non-blocking versions of the key checking functions, yet.
  29460. */
  29461. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29462. static wc_test_ret_t ecc_test_nonblock_dhe(int curveId, word32 curveSz,
  29463. const byte* privKey, const byte* pubKey, WC_RNG* rng)
  29464. {
  29465. wc_test_ret_t ret;
  29466. ecc_key keyA;
  29467. ecc_key keyB;
  29468. ecc_nb_ctx_t nbCtxA;
  29469. ecc_nb_ctx_t nbCtxB;
  29470. byte secretA[ECC_SHARED_SIZE];
  29471. byte secretB[ECC_SHARED_SIZE];
  29472. word32 secretSzA = ECC_SHARED_SIZE;
  29473. word32 secretSzB = ECC_SHARED_SIZE;
  29474. int count = 0;
  29475. ret = wc_ecc_init(&keyA);
  29476. if (ret == 0) {
  29477. ret = wc_ecc_init(&keyB);
  29478. if (ret < 0)
  29479. ret = WC_TEST_RET_ENC_EC(ret);
  29480. }
  29481. if (ret == 0) {
  29482. ret = wc_ecc_set_nonblock(&keyA, &nbCtxA);
  29483. if (ret < 0)
  29484. ret = WC_TEST_RET_ENC_EC(ret);
  29485. }
  29486. if (ret == 0) {
  29487. ret = wc_ecc_set_nonblock(&keyB, &nbCtxB);
  29488. if (ret < 0)
  29489. ret = WC_TEST_RET_ENC_EC(ret);
  29490. }
  29491. if (ret == 0) {
  29492. do {
  29493. ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId);
  29494. count++;
  29495. } while (ret == FP_WOULDBLOCK);
  29496. if (ret < 0)
  29497. ret = WC_TEST_RET_ENC_EC(ret);
  29498. }
  29499. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29500. fprintf(stderr, "ECC non-block key gen: %d times\n", count);
  29501. #endif
  29502. if (ret == 0) {
  29503. ret = wc_ecc_check_key(&keyA);
  29504. if (ret < 0)
  29505. ret = WC_TEST_RET_ENC_EC(ret);
  29506. }
  29507. if (ret == 0) {
  29508. ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz,
  29509. privKey, curveId);
  29510. if (ret < 0)
  29511. ret = WC_TEST_RET_ENC_EC(ret);
  29512. }
  29513. count = 0;
  29514. if (ret == 0) {
  29515. do {
  29516. ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA);
  29517. count++;
  29518. } while (ret == FP_WOULDBLOCK);
  29519. if (ret < 0)
  29520. ret = WC_TEST_RET_ENC_EC(ret);
  29521. }
  29522. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29523. fprintf(stderr, "ECC non-block shared secret: %d times\n", count);
  29524. #endif
  29525. if (ret == 0) {
  29526. do {
  29527. ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB);
  29528. } while (ret == FP_WOULDBLOCK);
  29529. if (ret < 0)
  29530. ret = WC_TEST_RET_ENC_EC(ret);
  29531. }
  29532. if (ret == 0) {
  29533. if (secretSzA != secretSzB ||
  29534. XMEMCMP(secretA, secretB, secretSzA) != 0) {
  29535. ret = WC_TEST_RET_ENC_NC;
  29536. }
  29537. }
  29538. wc_ecc_free(&keyA);
  29539. wc_ecc_free(&keyB);
  29540. return ret;
  29541. }
  29542. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29543. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29544. static wc_test_ret_t ecc_test_nonblock_ecdsa(int curveId, word32 curveSz,
  29545. const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz,
  29546. WC_RNG* rng)
  29547. {
  29548. wc_test_ret_t ret = 0;
  29549. byte* sig = NULL;
  29550. word32 sigSz = curveSz * 2;
  29551. static const byte hash[] = {
  29552. 0x8d, 0x28, 0xa3, 0x8b, 0x0b, 0xa9, 0xfe, 0xd4, 0x0e, 0x54, 0xc4, 0x17,
  29553. 0x3d, 0x54, 0x66, 0x34, 0xbf, 0x5d, 0x6f, 0x46, 0xc2, 0x20, 0xcb, 0xc3,
  29554. 0x22, 0xe9, 0xb0, 0xdf, 0xe7, 0x64, 0x3f, 0xd9
  29555. };
  29556. sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29557. if (sig == NULL) {
  29558. ret = WC_TEST_RET_ENC_ERRNO;
  29559. }
  29560. if (ret == 0) {
  29561. /* Sign hash using private key */
  29562. /* Note: result of an ECC sign varies for each call even with same
  29563. private key and hash. This is because a new random public key is
  29564. used for each operation. */
  29565. ret = crypto_ecc_sign(privKey, privKeySz, hash, sizeof(hash), sig,
  29566. &sigSz, curveSz, curveId, rng);
  29567. }
  29568. if (ret == 0) {
  29569. /* Verify generated signature is valid */
  29570. ret = crypto_ecc_verify(pubKey, pubKeySz, hash, sizeof(hash), sig,
  29571. sigSz, curveSz, curveId);
  29572. }
  29573. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29574. return ret;
  29575. }
  29576. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29577. static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng)
  29578. {
  29579. wc_test_ret_t ret = 0;
  29580. word32 i;
  29581. int curveIds[3] = {0, 0, 0};
  29582. word32 curveSzs[3] = {0, 0, 0};
  29583. const byte* privKeys[3] = {NULL, NULL, NULL};
  29584. word32 privKeySzs[3] = {0, 0, 0};
  29585. const byte* pubKeys[3] = {NULL, NULL, NULL};
  29586. word32 pubKeySzs[3] = {0, 0, 0};
  29587. curveIds[0] = ECC_SECP256R1;
  29588. curveSzs[0] = 32;
  29589. privKeys[0] = p256PrivKey;
  29590. privKeySzs[0] = sizeof(p256PrivKey);
  29591. pubKeys[0] = p256PubKey;
  29592. pubKeySzs[0] = sizeof(p256PubKey);
  29593. #ifdef HAVE_ECC384
  29594. curveIds[1] = ECC_SECP384R1;
  29595. curveSzs[1] = 48;
  29596. privKeys[1] = p384PrivKey;
  29597. privKeySzs[1] = sizeof(p384PrivKey);
  29598. pubKeys[1] = p384PubKey;
  29599. pubKeySzs[1] = sizeof(p384PubKey);
  29600. #endif
  29601. #ifdef HAVE_ECC521
  29602. curveIds[2] = ECC_SECP521R1;
  29603. curveSzs[2] = 66;
  29604. privKeys[2] = p521PrivKey;
  29605. privKeySzs[2] = sizeof(p521PrivKey);
  29606. pubKeys[2] = p521PubKey;
  29607. pubKeySzs[2] = sizeof(p521PubKey);
  29608. #endif
  29609. for (i = 0; ret == 0 && i < sizeof(curveIds) / sizeof(curveIds[0]); ++i) {
  29610. if (curveIds[i] == 0) {
  29611. continue;
  29612. }
  29613. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29614. ret = ecc_test_nonblock_ecdsa(curveIds[i], curveSzs[i], privKeys[i],
  29615. privKeySzs[i], pubKeys[i], pubKeySzs[i], rng);
  29616. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29617. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29618. if (ret == 0) {
  29619. ret = ecc_test_nonblock_dhe(curveIds[i], curveSzs[i], privKeys[i],
  29620. pubKeys[i], rng);
  29621. }
  29622. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29623. }
  29624. return ret;
  29625. }
  29626. #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */
  29627. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29628. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29629. (HAVE_FIPS_VERSION > 2)))
  29630. static int ecc_test_raw_enc_dec(void)
  29631. {
  29632. int ret;
  29633. unsigned char r[1];
  29634. word32 rSz;
  29635. unsigned char s[1];
  29636. word32 sSz;
  29637. unsigned char rZero[] = { 0, 0, 0, 0 };
  29638. unsigned char sOne[] = { 0, 0, 1 };
  29639. unsigned char sigRaw[32];
  29640. word32 sigRawSz;
  29641. unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 };
  29642. sigRawSz = sizeof(sigRaw);
  29643. ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne),
  29644. sigRaw, &sigRawSz);
  29645. if (ret != 0) {
  29646. return WC_TEST_RET_ENC_EC(ret);
  29647. }
  29648. if (sigRawSz != sizeof(expSig)) {
  29649. return WC_TEST_RET_ENC_EC((int)sigRawSz);
  29650. }
  29651. if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) {
  29652. return WC_TEST_RET_ENC_NC;
  29653. }
  29654. rSz = sizeof(r);
  29655. sSz = sizeof(s);
  29656. ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz);
  29657. if (ret != 0) {
  29658. return WC_TEST_RET_ENC_EC(ret);
  29659. }
  29660. if (rSz != 1) {
  29661. return WC_TEST_RET_ENC_EC((int)rSz);
  29662. }
  29663. if (sSz != 1) {
  29664. return WC_TEST_RET_ENC_EC((int)sSz);
  29665. }
  29666. if (r[0] != 0) {
  29667. return WC_TEST_RET_ENC_EC(r[0]);
  29668. }
  29669. if (s[0] != 1) {
  29670. return WC_TEST_RET_ENC_EC(s[0]);
  29671. }
  29672. return ret;
  29673. }
  29674. #endif
  29675. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void)
  29676. {
  29677. wc_test_ret_t ret;
  29678. WC_RNG rng;
  29679. WOLFSSL_ENTER("ecc_test");
  29680. #if defined(ECC_MIN_KEY_SZ)
  29681. WOLFSSL_MSG_EX("ecc_test ECC_MIN_KEY_SZ = %d\n", ECC_MIN_KEY_SZ);
  29682. #else
  29683. WOLFSSL_MSG("ecc_test ECC_MIN_KEY_SZ not defined.");
  29684. #endif
  29685. #if defined(WOLFSSL_CERT_EXT) && \
  29686. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29687. ret = ecc_decode_test();
  29688. if (ret < 0)
  29689. return ret;
  29690. #endif
  29691. #ifndef HAVE_FIPS
  29692. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  29693. #else
  29694. ret = wc_InitRng(&rng);
  29695. #endif
  29696. #ifndef WC_NO_RNG
  29697. if (ret != 0)
  29698. return WC_TEST_RET_ENC_EC(ret);
  29699. #else
  29700. (void)ret;
  29701. #endif
  29702. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  29703. ret = ecc_test_curve(&rng, 14, ECC_CURVE_DEF);
  29704. if (ret < 0) {
  29705. printf("keySize=14, Default\n");
  29706. goto done;
  29707. }
  29708. #endif /* HAVE_ECC112 */
  29709. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  29710. ret = ecc_test_curve(&rng, 16, ECC_CURVE_DEF);
  29711. if (ret < 0) {
  29712. printf("keySize=16, Default\n");
  29713. goto done;
  29714. }
  29715. #endif /* HAVE_ECC128 */
  29716. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  29717. ret = ecc_test_curve(&rng, 20, ECC_CURVE_DEF);
  29718. if (ret < 0) {
  29719. printf("keySize=20, Default\n");
  29720. goto done;
  29721. }
  29722. #endif /* HAVE_ECC160 */
  29723. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  29724. #if !FIPS_VERSION3_GE(6,0,0)
  29725. ret = ecc_test_curve(&rng, 24, ECC_CURVE_DEF);
  29726. if (ret < 0) {
  29727. printf("keySize=24, Default\n");
  29728. goto done;
  29729. }
  29730. #endif
  29731. #endif /* HAVE_ECC192 */
  29732. #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224
  29733. ret = ecc_test_curve(&rng, 28, ECC_CURVE_DEF);
  29734. if (ret < 0) {
  29735. printf("keySize=28, Default\n");
  29736. goto done;
  29737. }
  29738. #endif /* HAVE_ECC224 */
  29739. #if (defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 239
  29740. ret = ecc_test_curve(&rng, 30, ECC_CURVE_DEF);
  29741. if (ret < 0) {
  29742. printf("keySize=30, Default\n");
  29743. goto done;
  29744. }
  29745. #endif /* HAVE_ECC239 */
  29746. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29747. ret = ecc_test_curve(&rng, 32, ECC_CURVE_DEF);
  29748. if (ret < 0) {
  29749. printf("keySize=32, Default\n");
  29750. goto done;
  29751. }
  29752. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29753. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  29754. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  29755. ret = ecc_point_test();
  29756. if (ret < 0) {
  29757. goto done;
  29758. }
  29759. #endif
  29760. #if !defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES)
  29761. ret = ecc_def_curve_test(&rng);
  29762. if (ret < 0) {
  29763. printf("Default\n");
  29764. goto done;
  29765. }
  29766. #endif
  29767. #endif /* !NO_ECC256 */
  29768. #if (defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 320
  29769. ret = ecc_test_curve(&rng, 40, ECC_CURVE_DEF);
  29770. if (ret < 0) {
  29771. printf("keySize=40, Default\n");
  29772. goto done;
  29773. }
  29774. #endif /* HAVE_ECC320 */
  29775. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  29776. ret = ecc_test_curve(&rng, 48, ECC_CURVE_DEF);
  29777. if (ret < 0) {
  29778. printf("keySize=48, Default\n");
  29779. goto done;
  29780. }
  29781. #endif /* HAVE_ECC384 */
  29782. #if (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 512
  29783. ret = ecc_test_curve(&rng, 64, ECC_CURVE_DEF);
  29784. if (ret < 0) {
  29785. printf("keySize=64, Default\n");
  29786. goto done;
  29787. }
  29788. #endif /* HAVE_ECC512 */
  29789. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  29790. ret = ecc_test_curve(&rng, 66, ECC_CURVE_DEF);
  29791. if (ret < 0) {
  29792. printf("keySize=66, Default\n");
  29793. goto done;
  29794. }
  29795. #endif /* HAVE_ECC521 */
  29796. #ifdef WOLFSSL_SM2
  29797. ret = ecc_test_curve(&rng, 32, ECC_SM2P256V1);
  29798. if (ret < 0) {
  29799. printf("SM2\n");
  29800. goto done;
  29801. }
  29802. #endif
  29803. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29804. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29805. (HAVE_FIPS_VERSION > 2)))
  29806. ret = ecc_test_raw_enc_dec();
  29807. if (ret != 0) {
  29808. printf("raw sig encode/decode\n");
  29809. goto done;
  29810. }
  29811. #endif
  29812. #if defined(WOLFSSL_CUSTOM_CURVES)
  29813. ret = ecc_test_custom_curves(&rng);
  29814. if (ret != 0) {
  29815. printf("Custom\n");
  29816. goto done;
  29817. }
  29818. #endif
  29819. #if defined(WOLFSSL_SM2)
  29820. ret = test_sm2_verify();
  29821. if (ret != 0) {
  29822. printf("SM2 Verify\n");
  29823. goto done;
  29824. }
  29825. ret = ecc_sm2_test_curve(&rng, ECC_TEST_VERIFY_COUNT);
  29826. if (ret != 0) {
  29827. printf("SM2 test\n");
  29828. goto done;
  29829. }
  29830. #endif
  29831. #if defined(HAVE_ECC_SIGN) && \
  29832. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  29833. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  29834. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  29835. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29836. ret = ecc_test_deterministic_k(&rng);
  29837. if (ret != 0) {
  29838. printf("ecc_test_deterministic_k failed!\n");
  29839. goto done;
  29840. }
  29841. #endif
  29842. #ifdef WOLFSSL_PUBLIC_MP
  29843. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  29844. ECC_MIN_KEY_SZ <= 384
  29845. ret = ecc384_test_deterministic_k(&rng);
  29846. if (ret != 0) {
  29847. printf("ecc384_test_deterministic_k failed!\n");
  29848. goto done;
  29849. }
  29850. #endif
  29851. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && \
  29852. ECC_MIN_KEY_SZ <= 521
  29853. ret = ecc521_test_deterministic_k(&rng);
  29854. if (ret != 0) {
  29855. printf("ecc512_test_deterministic_k failed!\n");
  29856. goto done;
  29857. }
  29858. #endif
  29859. #endif
  29860. #endif
  29861. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  29862. !defined(WOLFSSL_KCAPI_ECC)
  29863. ret = ecc_test_sign_vectors(&rng);
  29864. if (ret != 0) {
  29865. printf("ecc_test_sign_vectors failed!\n");
  29866. goto done;
  29867. }
  29868. #endif
  29869. #if defined(HAVE_ECC_VECTOR_TEST) && defined(HAVE_ECC_CDH) && \
  29870. defined(HAVE_ECC_DHE)
  29871. ret = ecc_test_cdh_vectors(&rng);
  29872. if (ret != 0) {
  29873. printf("ecc_test_cdh_vectors failed!\n");
  29874. goto done;
  29875. }
  29876. #endif
  29877. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29878. !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
  29879. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  29880. ret = ecc_test_make_pub(&rng);
  29881. if (ret != 0) {
  29882. printf("ecc_test_make_pub failed!\n");
  29883. goto done;
  29884. }
  29885. #elif defined(HAVE_ECC_KEY_IMPORT)
  29886. (void)ecc_test_make_pub; /* for compiler warning */
  29887. #endif
  29888. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  29889. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  29890. ret = ecc_test_cert_gen(&rng);
  29891. if (ret != 0) {
  29892. printf("ecc_test_cert_gen failed!\n");
  29893. goto done;
  29894. }
  29895. #endif
  29896. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) && \
  29897. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && (!defined(NO_ECC_SECP) || \
  29898. defined(WOLFSSL_CUSTOM_CURVES))
  29899. ret = ecc_test_allocator(&rng);
  29900. if (ret != 0) {
  29901. printf("ecc_test_allocator failed!\n");
  29902. goto done;
  29903. }
  29904. #endif
  29905. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  29906. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29907. ret = ecc_test_nonblock(&rng);
  29908. if (ret != 0) {
  29909. printf("ecc_test_nonblock failed!\n");
  29910. goto done;
  29911. }
  29912. #endif
  29913. done:
  29914. wc_FreeRng(&rng);
  29915. return ret;
  29916. }
  29917. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  29918. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  29919. #if !defined(WOLFSSL_NO_MALLOC)
  29920. #if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3))
  29921. /* maximum encrypted message:
  29922. * msgSz (14) + pad (2) + pubKeySz(1+66*2) + ivSz(16) + digestSz(32) = 197 */
  29923. #define MAX_ECIES_TEST_SZ 200
  29924. static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
  29925. {
  29926. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29927. byte* plaintext;
  29928. byte* encrypted;
  29929. byte* decrypted;
  29930. #else
  29931. byte plaintext[MAX_ECIES_TEST_SZ];
  29932. byte encrypted[MAX_ECIES_TEST_SZ];
  29933. byte decrypted[MAX_ECIES_TEST_SZ];
  29934. #endif
  29935. ecEncCtx* aCtx = NULL;
  29936. ecEncCtx* bCtx = NULL;
  29937. static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  29938. 14, 15};
  29939. wc_test_ret_t ret = 0;
  29940. static const char message[] = "Hello wolfSSL!";
  29941. word32 plaintextLen;
  29942. word32 encryptLen = MAX_ECIES_TEST_SZ;
  29943. word32 decryptLen = MAX_ECIES_TEST_SZ;
  29944. int aInit = 0;
  29945. int bInit = 0;
  29946. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29947. plaintext = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29948. encrypted = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29949. decrypted = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29950. #endif
  29951. wc_ecc_free(a);
  29952. wc_ecc_free(b);
  29953. ret = wc_ecc_init(a);
  29954. if (ret != 0) {
  29955. ret = WC_TEST_RET_ENC_EC(ret);
  29956. }
  29957. else {
  29958. aInit = 1;
  29959. }
  29960. if (ret == 0) {
  29961. ret = wc_ecc_init(b);
  29962. if (ret != 0) {
  29963. ret = WC_TEST_RET_ENC_EC(ret);
  29964. }
  29965. else {
  29966. bInit = 1;
  29967. }
  29968. }
  29969. if (ret == 0)
  29970. ret = wc_ecc_make_key(rng, 32, a);
  29971. if (ret == 0)
  29972. ret = wc_ecc_make_key(rng, 32, b);
  29973. /* create context */
  29974. if (ret == 0) {
  29975. aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  29976. if (aCtx == NULL)
  29977. ret = WC_TEST_RET_ENC_NC;
  29978. }
  29979. if (ret == 0) {
  29980. bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  29981. if (bCtx == NULL)
  29982. ret = WC_TEST_RET_ENC_NC;
  29983. }
  29984. /* set salt */
  29985. if (ret == 0) {
  29986. ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt));
  29987. if (ret != 0)
  29988. ret = 10472;
  29989. }
  29990. if (ret == 0) {
  29991. ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt));
  29992. if (ret != 0)
  29993. ret = 10473;
  29994. }
  29995. XMEMSET(plaintext, 0, MAX_ECIES_TEST_SZ);
  29996. XSTRLCPY((char *)plaintext, message, sizeof plaintext);
  29997. plaintextLen = (((word32)XSTRLEN(message) + AES_BLOCK_SIZE - 1) /
  29998. AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
  29999. /* encrypt */
  30000. if (ret == 0) {
  30001. ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted,
  30002. &encryptLen, aCtx);
  30003. if (ret != 0)
  30004. ret = WC_TEST_RET_ENC_EC(ret);
  30005. }
  30006. /* decrypt */
  30007. if (ret == 0) {
  30008. ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted,
  30009. &decryptLen, bCtx);
  30010. if (ret != 0)
  30011. ret = WC_TEST_RET_ENC_EC(ret);
  30012. }
  30013. /* compare */
  30014. if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
  30015. ret = WC_TEST_RET_ENC_NC;
  30016. if (aInit) {
  30017. wc_ecc_free(a);
  30018. }
  30019. if (bInit) {
  30020. wc_ecc_free(b);
  30021. }
  30022. wc_ecc_ctx_free(aCtx);
  30023. wc_ecc_ctx_free(bCtx);
  30024. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30025. XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30026. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30027. XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30028. #endif
  30029. return ret;
  30030. }
  30031. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30032. #endif /* !WOLFSSL_NO_MALLOC */
  30033. /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in
  30034. * wolfFIPS 5.3.
  30035. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test().
  30036. */
  30037. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30038. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30039. ECC_MIN_KEY_SZ <= 256 && defined(WOLFSSL_AES_128)
  30040. static wc_test_ret_t ecc_encrypt_kat(WC_RNG *rng)
  30041. {
  30042. wc_test_ret_t ret = 0;
  30043. #ifdef WOLFSSL_ECIES_OLD
  30044. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30045. ecc_key* userA = NULL;
  30046. #else
  30047. ecc_key userA[1];
  30048. #endif
  30049. int userAInit = 0;
  30050. #endif
  30051. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30052. ecc_key* userB = NULL;
  30053. #else
  30054. ecc_key userB[1];
  30055. #endif
  30056. int userBInit = 0;
  30057. ecc_key* tmpKey;
  30058. byte plain[48];
  30059. word32 plainSz = sizeof(plain);
  30060. WOLFSSL_SMALL_STACK_STATIC const byte privKey[] = {
  30061. 0x04, 0x80, 0xef, 0x1d, 0xbe, 0x02, 0x0c, 0x20,
  30062. 0x5b, 0xab, 0x80, 0x35, 0x5b, 0x2a, 0x0f, 0x6d,
  30063. 0xd3, 0xb0, 0x7f, 0x7e, 0x7f, 0x86, 0x8a, 0x49,
  30064. 0xee, 0xb4, 0xaa, 0x09, 0x2d, 0x1e, 0x1d, 0x02
  30065. };
  30066. #if defined(WOLFSSL_ECIES_OLD) || defined(WOLFSSL_QNX_CAAM)
  30067. WOLFSSL_SMALL_STACK_STATIC const byte pubKey[] = {
  30068. 0x04,
  30069. /* X */
  30070. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30071. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30072. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30073. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30074. /* X */
  30075. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30076. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30077. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30078. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28
  30079. };
  30080. #endif
  30081. WOLFSSL_SMALL_STACK_STATIC const byte enc_msg[] = {
  30082. #ifdef WOLFSSL_ECIES_OLD
  30083. 0x42, 0x70, 0xbf, 0xf9, 0xf4, 0x7e, 0x4b, 0x9b,
  30084. 0xb5, 0x4c, 0xcc, 0xc5, 0x94, 0xa7, 0xef, 0xaa,
  30085. 0xc3, 0x7c, 0x85, 0xa6, 0x51, 0x6e, 0xd3, 0xfa,
  30086. 0x56, 0xc9, 0x10, 0x4d, 0x14, 0x32, 0x61, 0xb8,
  30087. 0xbb, 0x66, 0x7a, 0xb5, 0xbc, 0x95, 0xf8, 0xca,
  30088. 0xd1, 0x2a, 0x19, 0x51, 0x44, 0xd8, 0x0e, 0x57,
  30089. 0x34, 0xed, 0x45, 0x89, 0x2e, 0x57, 0xbe, 0xd5,
  30090. 0x06, 0x22, 0xd7, 0x13, 0x0a, 0x0e, 0x40, 0x36,
  30091. 0x0d, 0x05, 0x0d, 0xb6, 0xae, 0x61, 0x37, 0x18,
  30092. 0x83, 0x90, 0x0a, 0x27, 0x95, 0x41, 0x8c, 0x45
  30093. #elif defined(WOLFSSL_ECIES_ISO18033)
  30094. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30095. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30096. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30097. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30098. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30099. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30100. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30101. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30102. 0x28, 0xbb, 0x9f, 0xa8, 0x2d, 0xe1, 0xf1, 0x67,
  30103. 0x45, 0x02, 0x19, 0xdc, 0xc8, 0x24, 0x8b, 0x20,
  30104. 0x02, 0xa0, 0x8f, 0x95, 0x12, 0x55, 0x51, 0xf8,
  30105. 0x03, 0xc4, 0x54, 0x13, 0x98, 0x2d, 0xf0, 0x31,
  30106. 0x51, 0x80, 0x45, 0x24, 0xcb, 0x8b, 0x48, 0xa6,
  30107. 0x8b, 0x8e, 0x97, 0x9c, 0x56, 0x4d, 0x70, 0x00,
  30108. 0x53, 0xd3, 0x47, 0x00, 0x5a, 0x23, 0x8c, 0xf9,
  30109. 0xfd, 0xd2, 0x33, 0x2c, 0x43, 0x6e, 0x9e, 0xb2,
  30110. 0xf4, 0x95, 0xd4, 0xcf, 0x30, 0xd6, 0xa2, 0xc5,
  30111. 0x35, 0x96, 0x6a, 0xd4, 0x36, 0x15, 0xa9, 0xbd,
  30112. 0x7f
  30113. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30114. /* EC P-256 point */
  30115. 0x04,
  30116. /* X */
  30117. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30118. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30119. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30120. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30121. /* Y */
  30122. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30123. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30124. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30125. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28,
  30126. /* IV */
  30127. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30128. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30129. /* Encrypted Msg */
  30130. 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d, 0x50,
  30131. 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c, 0x1f,
  30132. 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc, 0x44,
  30133. 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca, 0x65,
  30134. 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61, 0xbd,
  30135. 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1, 0xde,
  30136. /* HMAC */
  30137. 0x5a, 0x22, 0xc1, 0x5d, 0x99, 0x66, 0x3f, 0x24,
  30138. 0x35, 0x96, 0xac, 0xf7, 0xf6, 0x28, 0x45, 0x16,
  30139. 0x52, 0x19, 0x0d, 0xe4, 0xb2, 0xca, 0x5b, 0x28,
  30140. 0x4e, 0xbb, 0xf3, 0x98, 0x57, 0xd7, 0x3b, 0xe2
  30141. #else
  30142. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30143. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30144. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30145. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30146. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30147. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30148. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30149. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30150. 0x28, 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d,
  30151. 0x50, 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c,
  30152. 0x1f, 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc,
  30153. 0x44, 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca,
  30154. 0x65, 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61,
  30155. 0xbd, 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1,
  30156. 0xde, 0xc7, 0x3f, 0x6f, 0xce, 0xbe, 0x49, 0x61,
  30157. 0x48, 0x01, 0x77, 0x41, 0xd0, 0xd8, 0x5b, 0x48,
  30158. 0xca, 0x4e, 0x47, 0x3e, 0x47, 0xbf, 0x1d, 0x28,
  30159. 0x4c, 0x18, 0x1a, 0xfb, 0x96, 0x95, 0xda, 0xde,
  30160. 0x55
  30161. #endif
  30162. };
  30163. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  30164. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  30165. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  30166. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  30167. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  30168. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  30169. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  30170. };
  30171. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30172. userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT,
  30173. DYNAMIC_TYPE_TMP_BUFFER);
  30174. if (userB == NULL) {
  30175. ret = WC_TEST_RET_ENC_ERRNO;
  30176. }
  30177. #ifdef WOLFSSL_ECIES_OLD
  30178. if (ret == 0) {
  30179. userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT,
  30180. DYNAMIC_TYPE_TMP_BUFFER);
  30181. if (userA == NULL) {
  30182. ret = WC_TEST_RET_ENC_ERRNO;
  30183. }
  30184. }
  30185. #endif
  30186. #endif
  30187. if (ret == 0) {
  30188. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30189. if (ret != 0)
  30190. ret = WC_TEST_RET_ENC_EC(ret);
  30191. }
  30192. if (ret == 0) {
  30193. userBInit = 1;
  30194. #ifdef WOLFSSL_ECIES_OLD
  30195. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30196. if (ret != 0)
  30197. ret = WC_TEST_RET_ENC_EC(ret);
  30198. }
  30199. if (ret == 0) {
  30200. userAInit = 1;
  30201. tmpKey = userA;
  30202. #else
  30203. tmpKey = NULL;
  30204. #endif
  30205. }
  30206. if (ret == 0) {
  30207. #ifdef WOLFSSL_QNX_CAAM
  30208. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), pubKey,
  30209. sizeof(pubKey), userB, ECC_SECP256R1);
  30210. #else
  30211. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), NULL, 0,
  30212. userB, ECC_SECP256R1);
  30213. #endif
  30214. if (ret != 0)
  30215. ret = WC_TEST_RET_ENC_EC(ret);
  30216. }
  30217. #ifdef WOLFSSL_ECIES_OLD
  30218. if (ret == 0) {
  30219. ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA,
  30220. ECC_SECP256R1);
  30221. if (ret != 0)
  30222. ret = WC_TEST_RET_ENC_EC(ret);
  30223. }
  30224. #endif
  30225. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30226. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30227. !defined(HAVE_SELFTEST)
  30228. if (ret == 0) {
  30229. ret = wc_ecc_set_rng(userB, rng);
  30230. if (ret != 0) {
  30231. ret = WC_TEST_RET_ENC_EC(ret);
  30232. }
  30233. }
  30234. #else
  30235. (void)rng;
  30236. #endif
  30237. if (ret == 0) {
  30238. ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain,
  30239. &plainSz, NULL);
  30240. if (ret != 0)
  30241. ret = WC_TEST_RET_ENC_EC(ret);
  30242. }
  30243. if (ret == 0) {
  30244. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30245. ret = WC_TEST_RET_ENC_NC;
  30246. }
  30247. }
  30248. if (userBInit)
  30249. wc_ecc_free(userB);
  30250. #ifdef WOLFSSL_ECIES_OLD
  30251. if (userAInit)
  30252. wc_ecc_free(userA);
  30253. #endif
  30254. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30255. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30256. #ifdef WOLFSSL_ECIES_OLD
  30257. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30258. #endif
  30259. #endif
  30260. return ret;
  30261. }
  30262. #endif
  30263. #ifndef WOLFSSL_NO_MALLOC
  30264. static wc_test_ret_t ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB,
  30265. byte encAlgo, byte kdfAlgo, byte macAlgo)
  30266. {
  30267. wc_test_ret_t ret = 0;
  30268. byte msg[48];
  30269. byte plain[48];
  30270. #ifdef WOLFSSL_ECIES_OLD
  30271. byte out[80];
  30272. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30273. byte out[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30274. #else
  30275. byte out[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30276. #endif
  30277. word32 outSz = sizeof(out);
  30278. word32 plainSz = sizeof(plain);
  30279. int i;
  30280. ecEncCtx* cliCtx = NULL;
  30281. ecEncCtx* srvCtx = NULL;
  30282. byte cliSalt[EXCHANGE_SALT_SZ];
  30283. byte srvSalt[EXCHANGE_SALT_SZ];
  30284. const byte* tmpSalt;
  30285. byte msg2[48];
  30286. byte plain2[48];
  30287. #ifdef WOLFSSL_ECIES_OLD
  30288. byte out2[80];
  30289. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30290. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30291. #else
  30292. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30293. #endif
  30294. word32 outSz2 = sizeof(out2);
  30295. word32 plainSz2 = sizeof(plain2);
  30296. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30297. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof(ecc_key), HEAP_HINT,
  30298. DYNAMIC_TYPE_TMP_BUFFER);
  30299. #else
  30300. ecc_key tmpKey[1];
  30301. #endif
  30302. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30303. if (tmpKey == NULL) {
  30304. ERROR_OUT(MEMORY_E, done);
  30305. }
  30306. #endif
  30307. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30308. if (ret != 0)
  30309. goto done;
  30310. /* set message to incrementing 0,1,2,etc... */
  30311. for (i = 0; i < (int)sizeof(msg); i++)
  30312. msg[i] = i;
  30313. /* encrypt msg to B */
  30314. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL);
  30315. if (ret != 0) {
  30316. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30317. }
  30318. #ifdef WOLFSSL_ECIES_OLD
  30319. tmpKey->dp = userA->dp;
  30320. ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey);
  30321. if (ret != 0) {
  30322. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30323. }
  30324. #endif
  30325. /* decrypt msg from A */
  30326. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL);
  30327. if (ret != 0) {
  30328. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30329. }
  30330. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30331. ret = WC_TEST_RET_ENC_NC; goto done;
  30332. }
  30333. #ifndef WOLFSSL_ECIES_OLD
  30334. /* A decrypts msg (response) from B */
  30335. ret = wc_ecc_decrypt(userB, NULL, out, outSz, plain2, &plainSz2, NULL);
  30336. if (ret != 0)
  30337. goto done;
  30338. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30339. ret = WC_TEST_RET_ENC_NC; goto done;
  30340. }
  30341. #endif
  30342. /* let's verify message exchange works, A is client, B is server */
  30343. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30344. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30345. if (cliCtx == NULL || srvCtx == NULL) {
  30346. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30347. }
  30348. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30349. if (ret != 0)
  30350. goto done;
  30351. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30352. if (ret != 0)
  30353. goto done;
  30354. /* get salt to send to peer */
  30355. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30356. if (tmpSalt == NULL) {
  30357. ret = WC_TEST_RET_ENC_NC; goto done;
  30358. }
  30359. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30360. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30361. if (tmpSalt == NULL) {
  30362. ret = WC_TEST_RET_ENC_NC; goto done;
  30363. }
  30364. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30365. /* in actual use, we'd get the peer's salt over the transport */
  30366. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30367. if (ret != 0)
  30368. goto done;
  30369. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30370. if (ret != 0)
  30371. goto done;
  30372. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 11);
  30373. if (ret != 0)
  30374. goto done;
  30375. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 11);
  30376. if (ret != 0)
  30377. goto done;
  30378. /* get encrypted msg (request) to send to B */
  30379. outSz = sizeof(out);
  30380. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz,cliCtx);
  30381. if (ret != 0)
  30382. goto done;
  30383. #ifndef WOLFSSL_ECIES_OLD
  30384. wc_ecc_free(tmpKey);
  30385. #endif
  30386. /* B decrypts msg (request) from A */
  30387. plainSz = sizeof(plain);
  30388. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30389. if (ret != 0)
  30390. goto done;
  30391. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30392. ret = WC_TEST_RET_ENC_NC; goto done;
  30393. }
  30394. /* msg2 (response) from B to A */
  30395. for (i = 0; i < (int)sizeof(msg2); i++)
  30396. msg2[i] = i + sizeof(msg2);
  30397. /* get encrypted msg (response) to send to B */
  30398. ret = wc_ecc_encrypt(userB, userA, msg2, sizeof(msg2), out2,
  30399. &outSz2, srvCtx);
  30400. if (ret != 0)
  30401. goto done;
  30402. #ifdef WOLFSSL_ECIES_OLD
  30403. tmpKey->dp = userB->dp;
  30404. ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey);
  30405. if (ret != 0) {
  30406. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30407. }
  30408. #else
  30409. wc_ecc_free(tmpKey);
  30410. #endif
  30411. /* A decrypts msg (response) from B */
  30412. ret = wc_ecc_decrypt(userA, tmpKey, out2, outSz2, plain2, &plainSz2,
  30413. cliCtx);
  30414. if (ret != 0)
  30415. goto done;
  30416. if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) {
  30417. ret = WC_TEST_RET_ENC_NC; goto done;
  30418. }
  30419. #if defined(HAVE_COMP_KEY) && \
  30420. (! defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  30421. /* Create new client and server contexts. */
  30422. wc_ecc_ctx_free(srvCtx);
  30423. wc_ecc_ctx_free(cliCtx);
  30424. /* let's verify message exchange works, A is client, B is server */
  30425. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30426. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30427. if (cliCtx == NULL || srvCtx == NULL) {
  30428. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30429. }
  30430. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30431. if (ret != 0)
  30432. goto done;
  30433. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30434. if (ret != 0)
  30435. goto done;
  30436. /* get salt to send to peer */
  30437. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30438. if (tmpSalt == NULL) {
  30439. ret = WC_TEST_RET_ENC_NC; goto done;
  30440. }
  30441. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30442. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30443. if (tmpSalt == NULL) {
  30444. ret = WC_TEST_RET_ENC_NC; goto done;
  30445. }
  30446. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30447. /* in actual use, we'd get the peer's salt over the transport */
  30448. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30449. if (ret != 0)
  30450. goto done;
  30451. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30452. if (ret != 0)
  30453. goto done;
  30454. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 12);
  30455. if (ret != 0)
  30456. goto done;
  30457. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 12);
  30458. if (ret != 0)
  30459. goto done;
  30460. /* get encrypted msg (request) to send to B - compressed public key */
  30461. outSz = sizeof(out);
  30462. ret = wc_ecc_encrypt_ex(userA, userB, msg, sizeof(msg), out, &outSz, cliCtx,
  30463. 1);
  30464. if (ret != 0)
  30465. goto done;
  30466. #ifndef WOLFSSL_ECIES_OLD
  30467. wc_ecc_free(tmpKey);
  30468. #endif
  30469. /* B decrypts msg (request) from A - out has a compressed public key */
  30470. plainSz = sizeof(plain);
  30471. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30472. if (ret != 0)
  30473. goto done;
  30474. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30475. ret = WC_TEST_RET_ENC_NC; goto done;
  30476. }
  30477. #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */
  30478. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30479. (ECC_MIN_KEY_SZ <= 256) && defined(WOLFSSL_AES_128)
  30480. ret = ecc_encrypt_kat(rng);
  30481. #endif
  30482. done:
  30483. /* cleanup */
  30484. wc_ecc_ctx_free(srvCtx);
  30485. wc_ecc_ctx_free(cliCtx);
  30486. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30487. if (tmpKey != NULL) {
  30488. wc_ecc_free(tmpKey);
  30489. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30490. }
  30491. #else
  30492. wc_ecc_free(tmpKey);
  30493. #endif
  30494. return ret;
  30495. }
  30496. #endif
  30497. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30498. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void)
  30499. {
  30500. WC_RNG rng;
  30501. wc_test_ret_t ret;
  30502. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30503. ecc_key *userA;
  30504. ecc_key *userB;
  30505. #else
  30506. ecc_key userA[1];
  30507. ecc_key userB[1];
  30508. #endif
  30509. WOLFSSL_ENTER("ecc_encrypt_test");
  30510. #ifndef HAVE_FIPS
  30511. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30512. #else
  30513. ret = wc_InitRng(&rng);
  30514. #endif
  30515. if (ret != 0)
  30516. return WC_TEST_RET_ENC_EC(ret);
  30517. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30518. userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT,
  30519. DYNAMIC_TYPE_TMP_BUFFER);
  30520. userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT,
  30521. DYNAMIC_TYPE_TMP_BUFFER);
  30522. if ((userA == NULL) || (userB == NULL)) {
  30523. ERROR_OUT(MEMORY_E, done);
  30524. }
  30525. #endif
  30526. XMEMSET(userA, 0, sizeof *userA);
  30527. XMEMSET(userB, 0, sizeof *userB);
  30528. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30529. if (ret != 0)
  30530. goto done;
  30531. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30532. if (ret != 0)
  30533. goto done;
  30534. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userA);
  30535. #if defined(WOLFSSL_ASYNC_CRYPT)
  30536. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  30537. #endif
  30538. if (ret != 0){
  30539. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30540. }
  30541. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB);
  30542. #if defined(WOLFSSL_ASYNC_CRYPT)
  30543. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  30544. #endif
  30545. if (ret != 0){
  30546. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30547. }
  30548. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30549. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30550. !defined(HAVE_SELFTEST)
  30551. ret = wc_ecc_set_rng(userA, &rng);
  30552. if (ret != 0) {
  30553. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30554. }
  30555. ret = wc_ecc_set_rng(userB, &rng);
  30556. if (ret != 0) {
  30557. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30558. }
  30559. #endif
  30560. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30561. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30562. #ifdef WOLFSSL_AES_128
  30563. if (ret == 0) {
  30564. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30565. ecHKDF_SHA256, ecHMAC_SHA256);
  30566. if (ret != 0) {
  30567. printf("ECIES: AES_128_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30568. }
  30569. }
  30570. #ifdef HAVE_X963_KDF
  30571. if (ret == 0) {
  30572. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30573. ecKDF_X963_SHA256, ecHMAC_SHA256);
  30574. if (ret != 0) {
  30575. printf("ECIES: AES_128_CBC, KDF_X963_SHA256, HMAC_SHA256\n");
  30576. }
  30577. }
  30578. if (ret == 0) {
  30579. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30580. ecKDF_SHA256, ecHMAC_SHA256);
  30581. if (ret != 0) {
  30582. printf("ECIES: AES_128_CBC, KDF_SHA256, HMAC_SHA256\n");
  30583. }
  30584. }
  30585. #endif
  30586. #endif
  30587. #ifdef WOLFSSL_AES_256
  30588. if (ret == 0) {
  30589. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CBC,
  30590. ecHKDF_SHA256, ecHMAC_SHA256);
  30591. if (ret != 0) {
  30592. printf("ECIES: AES_256_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30593. }
  30594. }
  30595. #endif
  30596. #endif
  30597. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && !defined(WOLFSSL_NO_MALLOC)
  30598. #ifdef WOLFSSL_AES_128
  30599. if (ret == 0) {
  30600. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CTR,
  30601. ecHKDF_SHA256, ecHMAC_SHA256);
  30602. if (ret != 0) {
  30603. printf("ECIES: AES_128_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30604. }
  30605. }
  30606. #endif
  30607. #ifdef WOLFSSL_AES_256
  30608. if (ret == 0) {
  30609. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CTR,
  30610. ecHKDF_SHA256, ecHMAC_SHA256);
  30611. if (ret != 0) {
  30612. printf("ECIES: AES_256_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30613. }
  30614. }
  30615. #endif
  30616. #endif /* !NO_AES && WOLFSSL_AES_COUNTER */
  30617. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30618. if (ret == 0) {
  30619. ret = ecc_ctx_kdf_salt_test(&rng, userA, userB);
  30620. }
  30621. #endif
  30622. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30623. done:
  30624. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30625. if (userA != NULL) {
  30626. wc_ecc_free(userA);
  30627. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30628. }
  30629. if (userB != NULL) {
  30630. wc_ecc_free(userB);
  30631. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30632. }
  30633. #else
  30634. wc_ecc_free(userB);
  30635. wc_ecc_free(userA);
  30636. #endif
  30637. wc_FreeRng(&rng);
  30638. return ret;
  30639. }
  30640. #endif /* HAVE_ECC_ENCRYPT && HAVE_AES_CBC && WOLFSSL_AES_128 */
  30641. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  30642. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  30643. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  30644. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  30645. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void)
  30646. {
  30647. size_t bytes;
  30648. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30649. ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30650. ecc_key *servKey = (ecc_key *)XMALLOC(sizeof *servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30651. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof *tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30652. #else
  30653. ecc_key cliKey[1];
  30654. ecc_key servKey[1];
  30655. ecc_key tmpKey[1];
  30656. #endif
  30657. WC_RNG rng;
  30658. word32 idx = 0;
  30659. wc_test_ret_t ret;
  30660. /* pad our test message to 32 bytes so evenly divisible by AES_BLOCK_SZ */
  30661. byte in[] = "Everyone gets Friday off. ecc p";
  30662. word32 inLen = (word32)XSTRLEN((char*)in);
  30663. byte out[256];
  30664. byte plain[256];
  30665. int verify = 0;
  30666. word32 x;
  30667. WOLFSSL_ENTER("ecc_test_buffers");
  30668. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30669. if ((cliKey == NULL) || (servKey == NULL) || (tmpKey == NULL))
  30670. ERROR_OUT(MEMORY_E, done);
  30671. #endif
  30672. ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId);
  30673. if (ret != 0)
  30674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30675. ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId);
  30676. if (ret != 0)
  30677. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30678. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30679. if (ret != 0)
  30680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30681. bytes = (size_t)sizeof_ecc_clikey_der_256;
  30682. /* place client key into ecc_key struct cliKey */
  30683. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey,
  30684. (word32)bytes);
  30685. if (ret != 0)
  30686. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30687. idx = 0;
  30688. bytes = (size_t)sizeof_ecc_key_der_256;
  30689. /* place server key into ecc_key struct servKey */
  30690. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey,
  30691. (word32)bytes);
  30692. if (ret != 0)
  30693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30694. #ifndef WC_NO_RNG
  30695. #ifndef HAVE_FIPS
  30696. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30697. #else
  30698. ret = wc_InitRng(&rng);
  30699. #endif
  30700. if (ret != 0)
  30701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30702. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30703. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30704. !defined(HAVE_SELFTEST)
  30705. ret = wc_ecc_set_rng(cliKey, &rng);
  30706. if (ret != 0)
  30707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30708. ret = wc_ecc_set_rng(servKey, &rng);
  30709. if (ret != 0)
  30710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30711. #endif
  30712. #endif /* !WC_NO_RNG */
  30713. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_HKDF) && \
  30714. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  30715. {
  30716. word32 y;
  30717. /* test encrypt and decrypt if they're available */
  30718. x = sizeof(out);
  30719. ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL);
  30720. if (ret < 0)
  30721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30722. #ifdef WOLFSSL_ECIES_OLD
  30723. tmpKey->dp = cliKey->dp;
  30724. ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey);
  30725. if (ret != 0) {
  30726. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30727. }
  30728. #endif
  30729. y = sizeof(plain);
  30730. ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL);
  30731. if (ret < 0)
  30732. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30733. if (XMEMCMP(plain, in, inLen))
  30734. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30735. }
  30736. #endif
  30737. x = sizeof(out);
  30738. do {
  30739. #if defined(WOLFSSL_ASYNC_CRYPT)
  30740. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30741. #endif
  30742. if (ret == 0)
  30743. ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey);
  30744. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30745. if (ret < 0)
  30746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30747. TEST_SLEEP();
  30748. XMEMSET(plain, 0, sizeof(plain));
  30749. do {
  30750. #if defined(WOLFSSL_ASYNC_CRYPT)
  30751. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30752. #endif
  30753. if (ret == 0)
  30754. ret = wc_ecc_verify_hash(out, x, in, inLen, &verify,
  30755. cliKey);
  30756. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30757. if (ret < 0)
  30758. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30759. if (verify != 1)
  30760. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30761. TEST_SLEEP();
  30762. #ifdef WOLFSSL_CERT_EXT
  30763. idx = 0;
  30764. bytes = sizeof_ecc_clikeypub_der_256;
  30765. ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey,
  30766. (word32) bytes);
  30767. if (ret != 0)
  30768. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30769. #endif
  30770. ret = 0;
  30771. done:
  30772. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30773. if (cliKey != NULL) {
  30774. wc_ecc_free(cliKey);
  30775. XFREE(cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30776. }
  30777. if (servKey != NULL) {
  30778. wc_ecc_free(servKey);
  30779. XFREE(servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30780. }
  30781. if (tmpKey != NULL) {
  30782. wc_ecc_free(tmpKey);
  30783. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30784. }
  30785. #else
  30786. wc_ecc_free(cliKey);
  30787. wc_ecc_free(servKey);
  30788. wc_ecc_free(tmpKey);
  30789. #endif
  30790. wc_FreeRng(&rng);
  30791. return ret;
  30792. }
  30793. #endif /* USE_CERT_BUFFERS_256 && !WOLFSSL_ATECCX08A && !NO_ECC256 */
  30794. #endif /* HAVE_ECC */
  30795. #ifdef HAVE_CURVE25519
  30796. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30797. defined(HAVE_CURVE25519_KEY_IMPORT)
  30798. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30799. #define X25519_TEST_CNT 5
  30800. #else
  30801. #define X25519_TEST_CNT 1
  30802. #endif
  30803. static wc_test_ret_t curve25519_overflow_test(void)
  30804. {
  30805. /* secret key for party a */
  30806. byte sa[X25519_TEST_CNT][32] = {
  30807. {
  30808. 0x8d,0xaf,0x6e,0x7a,0xc1,0xeb,0x8d,0x30,
  30809. 0x99,0x86,0xd3,0x90,0x47,0x96,0x21,0x3c,
  30810. 0x3a,0x75,0xc0,0x7b,0x75,0x01,0x75,0xa3,
  30811. 0x81,0x4b,0xff,0x5a,0xbc,0x96,0x87,0x28
  30812. },
  30813. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30814. {
  30815. 0x9d,0x63,0x5f,0xce,0xe2,0xe8,0xd7,0xfb,
  30816. 0x68,0x77,0x0e,0x44,0xd1,0xad,0x87,0x2b,
  30817. 0xf4,0x65,0x06,0xb7,0xbb,0xdb,0xbe,0x6e,
  30818. 0x02,0x43,0x24,0xc7,0x3d,0x7b,0x88,0x60
  30819. },
  30820. {
  30821. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30822. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30823. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30824. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30825. },
  30826. {
  30827. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30828. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30829. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30830. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30831. },
  30832. {
  30833. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30834. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30835. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30836. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30837. }
  30838. #endif
  30839. };
  30840. /* public key for party b */
  30841. byte pb[X25519_TEST_CNT][32] = {
  30842. {
  30843. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30844. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30845. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30846. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30847. },
  30848. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30849. {
  30850. /* 0xff first byte in original - invalid! */
  30851. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30852. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30853. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30854. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30855. },
  30856. {
  30857. 0x36,0x1a,0x74,0x87,0x28,0x59,0xe0,0xb6,
  30858. 0xe4,0x2b,0x17,0x9b,0x16,0xb0,0x3b,0xf8,
  30859. 0xb8,0x9f,0x2a,0x8f,0xc5,0x33,0x68,0x4f,
  30860. 0xde,0x4d,0xd8,0x80,0x63,0xe7,0xb4,0x0a
  30861. },
  30862. {
  30863. 0x00,0x80,0x38,0x59,0x19,0x3a,0x66,0x12,
  30864. 0xfd,0xa1,0xec,0x1c,0x40,0x84,0x40,0xbd,
  30865. 0x64,0x10,0x8b,0x53,0x81,0x21,0x03,0x2d,
  30866. 0x7d,0x33,0xb4,0x01,0x57,0x0d,0xe1,0x89
  30867. },
  30868. {
  30869. 0x1d,0xf8,0xf8,0x33,0x89,0x6c,0xb7,0xba,
  30870. 0x94,0x73,0xfa,0xc2,0x36,0xac,0xbe,0x49,
  30871. 0xaf,0x85,0x3e,0x93,0x5f,0xae,0xb2,0xc0,
  30872. 0xc8,0x80,0x8f,0x4a,0xaa,0xd3,0x55,0x2b
  30873. }
  30874. #endif
  30875. };
  30876. /* expected shared key */
  30877. byte ss[X25519_TEST_CNT][32] = {
  30878. {
  30879. 0x5c,0x4c,0x85,0x5f,0xfb,0x20,0x38,0xcc,
  30880. 0x55,0x16,0x5b,0x8a,0xa7,0xed,0x57,0x6e,
  30881. 0x35,0xaa,0x71,0x67,0x85,0x1f,0xb6,0x28,
  30882. 0x17,0x07,0x7b,0xda,0x76,0xdd,0xe0,0xb4
  30883. },
  30884. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30885. {
  30886. 0x33,0xf6,0xc1,0x34,0x62,0x92,0x06,0x02,
  30887. 0x95,0xdb,0x91,0x4c,0x5d,0x52,0x54,0xc7,
  30888. 0xd2,0x5b,0x24,0xb5,0x4f,0x33,0x59,0x79,
  30889. 0x9f,0x6d,0x7e,0x4a,0x4c,0x30,0xd6,0x38
  30890. },
  30891. {
  30892. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30893. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30894. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30895. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02
  30896. },
  30897. {
  30898. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30899. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30900. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30901. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
  30902. },
  30903. {
  30904. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30905. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30906. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30907. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10
  30908. }
  30909. #endif
  30910. };
  30911. wc_test_ret_t ret = 0;
  30912. int i;
  30913. word32 y;
  30914. byte shared[32];
  30915. curve25519_key userA;
  30916. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  30917. for (i = 0; i < X25519_TEST_CNT; i++) {
  30918. if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i],
  30919. sizeof(pb[i]), &userA) != 0) {
  30920. ret = WC_TEST_RET_ENC_I(i); break;
  30921. }
  30922. /* test against known test vector */
  30923. XMEMSET(shared, 0, sizeof(shared));
  30924. y = sizeof(shared);
  30925. if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
  30926. ret = WC_TEST_RET_ENC_I(i); break;
  30927. }
  30928. if (XMEMCMP(ss[i], shared, y)) {
  30929. ret = WC_TEST_RET_ENC_I(i); break;
  30930. }
  30931. }
  30932. wc_curve25519_free(&userA);
  30933. return ret;
  30934. }
  30935. /* Test the wc_curve25519_check_public API.
  30936. *
  30937. * returns 0 on success and -ve on failure.
  30938. */
  30939. static wc_test_ret_t curve25519_check_public_test(void)
  30940. {
  30941. wc_test_ret_t ret;
  30942. /* Little-endian values that will fail */
  30943. byte fail_le[][CURVE25519_KEYSIZE] = {
  30944. {
  30945. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30946. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30947. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30948. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30949. },
  30950. {
  30951. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30952. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30953. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30954. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30955. },
  30956. {
  30957. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30958. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30959. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30960. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81
  30961. },
  30962. };
  30963. /* Big-endian values that will fail */
  30964. byte fail_be[][CURVE25519_KEYSIZE] = {
  30965. {
  30966. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30967. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30968. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30969. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30970. },
  30971. {
  30972. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30973. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30974. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30975. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30976. },
  30977. {
  30978. 0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30979. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30980. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30981. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30982. },
  30983. };
  30984. /* Good or valid public value */
  30985. byte good[CURVE25519_KEYSIZE] = {
  30986. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30987. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30988. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30989. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30990. };
  30991. int i;
  30992. /* Parameter checks */
  30993. /* NULL pointer */
  30994. ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN);
  30995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30996. return WC_TEST_RET_ENC_EC(ret);
  30997. }
  30998. ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN);
  30999. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  31000. return WC_TEST_RET_ENC_EC(ret);
  31001. }
  31002. /* Length of 0 treated differently to other invalid lengths for TLS */
  31003. ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN);
  31004. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31005. return WC_TEST_RET_ENC_EC(ret);
  31006. ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN);
  31007. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31008. return WC_TEST_RET_ENC_EC(ret);
  31009. /* Length not CURVE25519_KEYSIZE */
  31010. for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) {
  31011. if (i == CURVE25519_KEYSIZE)
  31012. continue;
  31013. if (wc_curve25519_check_public(good, (word32)i, EC25519_LITTLE_ENDIAN) !=
  31014. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31015. return WC_TEST_RET_ENC_I(i);
  31016. }
  31017. if (wc_curve25519_check_public(good, (word32)i, EC25519_BIG_ENDIAN) !=
  31018. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31019. return WC_TEST_RET_ENC_I(i);
  31020. }
  31021. }
  31022. /* Little-endian fail cases */
  31023. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  31024. if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE,
  31025. EC25519_LITTLE_ENDIAN) == 0) {
  31026. return WC_TEST_RET_ENC_I(i);
  31027. }
  31028. }
  31029. /* Big-endian fail cases */
  31030. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  31031. if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE,
  31032. EC25519_BIG_ENDIAN) == 0) {
  31033. return WC_TEST_RET_ENC_I(i);
  31034. }
  31035. }
  31036. /* Check a valid public value works! */
  31037. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31038. EC25519_LITTLE_ENDIAN);
  31039. if (ret != 0) {
  31040. return WC_TEST_RET_ENC_EC(ret);
  31041. }
  31042. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31043. EC25519_BIG_ENDIAN);
  31044. if (ret != 0) {
  31045. return WC_TEST_RET_ENC_EC(ret);
  31046. }
  31047. return 0;
  31048. }
  31049. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31050. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31051. defined(HAVE_CURVE25519_KEY_IMPORT)
  31052. static wc_test_ret_t curve255519_der_test(void)
  31053. {
  31054. wc_test_ret_t ret = 0;
  31055. /* certs/statickeys/x25519.der */
  31056. const byte kCurve25519PrivDer[] = {
  31057. 0x30, 0x2E, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E,
  31058. 0x04, 0x22, 0x04, 0x20, 0x78, 0x8E, 0x31, 0x5C, 0x33, 0xA9, 0x19, 0xC0,
  31059. 0x5E, 0x36, 0x70, 0x1B, 0xA4, 0xE8, 0xEF, 0xC1, 0x89, 0x8C, 0xB3, 0x15,
  31060. 0xC6, 0x79, 0xD3, 0xAC, 0x22, 0x00, 0xAE, 0xFA, 0xB3, 0xB7, 0x0F, 0x78
  31061. };
  31062. /* certs/statickeys/x25519-pub.der */
  31063. const byte kCurve25519PubDer[] = {
  31064. 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00,
  31065. 0x09, 0xBC, 0x8C, 0xC7, 0x45, 0x0D, 0xC1, 0xC2, 0x02, 0x57, 0x9A, 0x68,
  31066. 0x3A, 0xFD, 0x7A, 0xA8, 0xA5, 0x2F, 0xF0, 0x99, 0x39, 0x98, 0xEA, 0x26,
  31067. 0xA2, 0x5B, 0x38, 0xFD, 0x96, 0xDB, 0x2A, 0x26
  31068. };
  31069. curve25519_key key;
  31070. byte output[128];
  31071. word32 outputSz = 128;
  31072. word32 idx;
  31073. ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId);
  31074. if (ret != 0)
  31075. return WC_TEST_RET_ENC_EC(ret);
  31076. /* Test decode / encode of Curve25519 private key only */
  31077. if (ret == 0) {
  31078. idx = 0;
  31079. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key,
  31080. (word32)sizeof(kCurve25519PrivDer));
  31081. if (ret < 0)
  31082. ret = WC_TEST_RET_ENC_EC(ret);
  31083. }
  31084. if (ret == 0) {
  31085. outputSz = (word32)sizeof(output);
  31086. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31087. if (ret >= 0) {
  31088. outputSz = (word32)ret;
  31089. ret = 0;
  31090. }
  31091. else {
  31092. ret = WC_TEST_RET_ENC_EC(ret);
  31093. }
  31094. }
  31095. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31096. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31097. ret = WC_TEST_RET_ENC_NC;
  31098. }
  31099. /* Test decode / encode of Curve25519 public key only */
  31100. if (ret == 0) {
  31101. idx = 0;
  31102. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key,
  31103. (word32)sizeof(kCurve25519PubDer));
  31104. if (ret < 0)
  31105. ret = WC_TEST_RET_ENC_EC(ret);
  31106. }
  31107. if (ret == 0) {
  31108. outputSz = (word32)sizeof(output);
  31109. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31110. if (ret >= 0) {
  31111. outputSz = (word32)ret;
  31112. ret = 0;
  31113. }
  31114. else {
  31115. ret = WC_TEST_RET_ENC_EC(ret);
  31116. }
  31117. }
  31118. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31119. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31120. ret = WC_TEST_RET_ENC_NC;
  31121. }
  31122. /* Test decode/encode of Curve25519 private key (only) using generic API */
  31123. if (ret == 0) {
  31124. /* clear key, since generic API will try to decode all fields */
  31125. XMEMSET(&key, 0, sizeof(key));
  31126. idx = 0;
  31127. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31128. (word32)sizeof(kCurve25519PrivDer));
  31129. if (ret < 0) {
  31130. ret = WC_TEST_RET_ENC_EC(ret);
  31131. }
  31132. }
  31133. if (ret == 0) {
  31134. outputSz = (word32)sizeof(output);
  31135. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31136. if (ret >= 0) {
  31137. outputSz = (word32)ret;
  31138. ret = 0;
  31139. }
  31140. else {
  31141. ret = WC_TEST_RET_ENC_EC(ret);
  31142. }
  31143. }
  31144. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31145. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31146. ret = WC_TEST_RET_ENC_NC;
  31147. }
  31148. /* Test decode/encode of Curve25519 public key (only) using generic API */
  31149. if (ret == 0) {
  31150. /* clear key, since generic API will try to decode all fields */
  31151. XMEMSET(&key, 0, sizeof(key));
  31152. idx = 0;
  31153. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31154. (word32)sizeof(kCurve25519PubDer));
  31155. if (ret < 0) {
  31156. ret = WC_TEST_RET_ENC_EC(ret);
  31157. }
  31158. }
  31159. if (ret == 0) {
  31160. outputSz = (word32)sizeof(output);
  31161. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31162. if (ret >= 0) {
  31163. outputSz = (word32)ret;
  31164. ret = 0;
  31165. }
  31166. else {
  31167. ret = WC_TEST_RET_ENC_EC(ret);
  31168. }
  31169. }
  31170. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31171. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31172. ret = WC_TEST_RET_ENC_NC;
  31173. }
  31174. /* Test decode/encode key data containing both public and private fields */
  31175. if (ret == 0) {
  31176. XMEMSET(&key, 0 , sizeof(key));
  31177. /* Decode public key */
  31178. idx = 0;
  31179. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31180. (word32)sizeof(kCurve25519PubDer));
  31181. if (ret < 0) {
  31182. ret = WC_TEST_RET_ENC_EC(ret);
  31183. }
  31184. if (ret == 0) {
  31185. /* Decode private key */
  31186. idx = 0;
  31187. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31188. (word32)sizeof(kCurve25519PrivDer));
  31189. if (ret < 0) {
  31190. ret = WC_TEST_RET_ENC_EC(ret);
  31191. }
  31192. }
  31193. /* Both public and private flags should be set */
  31194. if ((ret == 0) && (!key.pubSet && !key.privSet)) {
  31195. ret = WC_TEST_RET_ENC_NC;
  31196. }
  31197. if (ret == 0) {
  31198. /* Export key to temporary DER */
  31199. outputSz = (word32)sizeof(output);
  31200. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31201. if (ret >= 0) {
  31202. outputSz = (word32)ret;
  31203. ret = 0;
  31204. }
  31205. else {
  31206. ret = WC_TEST_RET_ENC_EC(ret);
  31207. }
  31208. /* Re-import temporary DER */
  31209. if (ret == 0) {
  31210. idx = 0;
  31211. ret = wc_Curve25519KeyDecode(output, &idx, &key, sizeof(output));
  31212. if (ret < 0) {
  31213. ret = WC_TEST_RET_ENC_EC(ret);
  31214. }
  31215. }
  31216. /* Ensure public and private keys survived combined keypair
  31217. * export/import by re-exporting DER for private and public keys,
  31218. * individually, and re-checking output against known good vectors.
  31219. * This is slightly circuitous but does test the functionality
  31220. * without requiring the addition of new test keys */
  31221. if (ret == 0) {
  31222. idx = 0;
  31223. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx,
  31224. &key, (word32)sizeof(kCurve25519PrivDer));
  31225. if (ret < 0)
  31226. ret = WC_TEST_RET_ENC_EC(ret);
  31227. }
  31228. if (ret == 0) {
  31229. outputSz = (word32)sizeof(output);
  31230. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31231. if (ret >= 0) {
  31232. outputSz = (word32)ret;
  31233. ret = 0;
  31234. }
  31235. else {
  31236. ret = WC_TEST_RET_ENC_EC(ret);
  31237. }
  31238. }
  31239. if ((ret == 0) &&
  31240. (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31241. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31242. ret = WC_TEST_RET_ENC_NC;
  31243. }
  31244. if (ret == 0) {
  31245. idx = 0;
  31246. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx,
  31247. &key, (word32)sizeof(kCurve25519PubDer));
  31248. if (ret < 0)
  31249. ret = WC_TEST_RET_ENC_EC(ret);
  31250. }
  31251. if (ret == 0) {
  31252. outputSz = (word32)sizeof(output);
  31253. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31254. if (ret >= 0) {
  31255. outputSz = (word32)ret;
  31256. ret = 0;
  31257. }
  31258. else {
  31259. ret = WC_TEST_RET_ENC_EC(ret);
  31260. }
  31261. }
  31262. if ((ret == 0) &&
  31263. (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31264. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31265. ret = WC_TEST_RET_ENC_NC;
  31266. }
  31267. }
  31268. }
  31269. wc_curve25519_free(&key);
  31270. return ret;
  31271. }
  31272. #endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
  31273. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
  31274. {
  31275. WC_RNG rng;
  31276. wc_test_ret_t ret;
  31277. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31278. byte sharedA[32];
  31279. byte sharedB[32];
  31280. word32 y;
  31281. #endif
  31282. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31283. byte exportBuf[32];
  31284. #endif
  31285. word32 x = 0;
  31286. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31287. curve25519_key *userA = NULL, *userB = NULL, *pubKey = NULL;
  31288. #else
  31289. curve25519_key userA[1], userB[1], pubKey[1];
  31290. #endif
  31291. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31292. defined(HAVE_CURVE25519_KEY_IMPORT)
  31293. /* test vectors from
  31294. https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
  31295. */
  31296. /* secret key for party a */
  31297. byte sa[] = {
  31298. 0x5A,0xC9,0x9F,0x33,0x63,0x2E,0x5A,0x76,
  31299. 0x8D,0xE7,0xE8,0x1B,0xF8,0x54,0xC2,0x7C,
  31300. 0x46,0xE3,0xFB,0xF2,0xAB,0xBA,0xCD,0x29,
  31301. 0xEC,0x4A,0xFF,0x51,0x73,0x69,0xC6,0x60
  31302. };
  31303. /* public key for party a */
  31304. byte pa[] = {
  31305. 0x05,0x7E,0x23,0xEA,0x9F,0x1C,0xBE,0x8A,
  31306. 0x27,0x16,0x8F,0x6E,0x69,0x6A,0x79,0x1D,
  31307. 0xE6,0x1D,0xD3,0xAF,0x7A,0xCD,0x4E,0xEA,
  31308. 0xCC,0x6E,0x7B,0xA5,0x14,0xFD,0xA8,0x63
  31309. };
  31310. /* secret key for party b */
  31311. byte sb[] = {
  31312. 0x47,0xDC,0x3D,0x21,0x41,0x74,0x82,0x0E,
  31313. 0x11,0x54,0xB4,0x9B,0xC6,0xCD,0xB2,0xAB,
  31314. 0xD4,0x5E,0xE9,0x58,0x17,0x05,0x5D,0x25,
  31315. 0x5A,0xA3,0x58,0x31,0xB7,0x0D,0x32,0x60
  31316. };
  31317. /* public key for party b */
  31318. byte pb[] = {
  31319. 0x6E,0xB8,0x9D,0xA9,0x19,0x89,0xAE,0x37,
  31320. 0xC7,0xEA,0xC7,0x61,0x8D,0x9E,0x5C,0x49,
  31321. 0x51,0xDB,0xA1,0xD7,0x3C,0x28,0x5A,0xE1,
  31322. 0xCD,0x26,0xA8,0x55,0x02,0x0E,0xEF,0x04
  31323. };
  31324. /* expected shared key */
  31325. byte ss[] = {
  31326. 0x61,0x45,0x0C,0xD9,0x8E,0x36,0x01,0x6B,
  31327. 0x58,0x77,0x6A,0x89,0x7A,0x9F,0x0A,0xEF,
  31328. 0x73,0x8B,0x99,0xF0,0x94,0x68,0xB8,0xD6,
  31329. 0xB8,0x51,0x11,0x84,0xD5,0x34,0x94,0xAB
  31330. };
  31331. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  31332. (void)x;
  31333. WOLFSSL_ENTER("curve25519_test");
  31334. /* wc_FreeRng is always called on exit. Therefore wc_InitRng should be
  31335. * called before any exit goto's */
  31336. #ifndef HAVE_FIPS
  31337. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31338. #else
  31339. ret = wc_InitRng(&rng);
  31340. #endif
  31341. if (ret != 0)
  31342. return WC_TEST_RET_ENC_EC(ret);
  31343. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31344. userA = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31345. if (ret != 0)
  31346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31347. userB = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31348. if (ret != 0)
  31349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31350. pubKey = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31351. if (ret != 0)
  31352. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31353. #else
  31354. wc_curve25519_init_ex(userA, HEAP_HINT, devId);
  31355. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31356. wc_curve25519_init_ex(pubKey, HEAP_HINT, devId);
  31357. #endif
  31358. /* make curve25519 keys */
  31359. ret = wc_curve25519_make_key(&rng, 32, userA);
  31360. if (ret != 0)
  31361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31362. ret = wc_curve25519_make_key(&rng, 32, userB);
  31363. if (ret != 0)
  31364. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31365. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31366. /* find shared secret key */
  31367. x = sizeof(sharedA);
  31368. if ((ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x)) != 0) {
  31369. printf("wc_curve25519_shared_secret 1 failed\n");
  31370. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31371. }
  31372. y = sizeof(sharedB);
  31373. if ((ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y)) != 0) {
  31374. printf("wc_curve25519_shared_secret 2 failed\n");
  31375. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31376. }
  31377. /* compare shared secret keys to test they are the same */
  31378. if (y != x)
  31379. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31380. if (XMEMCMP(sharedA, sharedB, x))
  31381. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31382. #endif
  31383. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31384. /* export a public key and import it for another user */
  31385. x = sizeof(exportBuf);
  31386. ret = wc_curve25519_export_public(userA, exportBuf, &x);
  31387. if (ret != 0)
  31388. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31389. #ifdef HAVE_CURVE25519_KEY_IMPORT
  31390. ret = wc_curve25519_import_public(exportBuf, x, pubKey);
  31391. if (ret != 0)
  31392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31393. #endif
  31394. #endif
  31395. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31396. defined(HAVE_CURVE25519_KEY_IMPORT)
  31397. /* test shared key after importing a public key */
  31398. XMEMSET(sharedB, 0, sizeof(sharedB));
  31399. y = sizeof(sharedB);
  31400. if (wc_curve25519_shared_secret(userB, pubKey, sharedB, &y) != 0) {
  31401. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31402. }
  31403. if (XMEMCMP(sharedA, sharedB, y))
  31404. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31405. /* import RFC test vectors and compare shared key */
  31406. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31407. userA);
  31408. if (ret != 0)
  31409. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31410. ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb),
  31411. userB);
  31412. if (ret != 0)
  31413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31414. /* test against known test vector */
  31415. XMEMSET(sharedB, 0, sizeof(sharedB));
  31416. y = sizeof(sharedB);
  31417. ret = wc_curve25519_shared_secret(userA, userB, sharedB, &y);
  31418. if (ret != 0)
  31419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31420. if (XMEMCMP(ss, sharedB, y))
  31421. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31422. /* test swapping roles of keys and generating same shared key */
  31423. XMEMSET(sharedB, 0, sizeof(sharedB));
  31424. y = sizeof(sharedB);
  31425. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31426. if (ret != 0)
  31427. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31428. if (XMEMCMP(ss, sharedB, y))
  31429. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31430. /* test with 1 generated key and 1 from known test vector */
  31431. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31432. userA);
  31433. if (ret != 0)
  31434. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31435. wc_curve25519_free(userB);
  31436. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31437. ret = wc_curve25519_make_key(&rng, 32, userB);
  31438. if (ret != 0)
  31439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31440. x = sizeof(sharedA);
  31441. ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x);
  31442. if (ret != 0)
  31443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31444. y = sizeof(sharedB);
  31445. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31446. if (ret != 0)
  31447. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31448. /* compare shared secret keys to test they are the same */
  31449. if (y != x)
  31450. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31451. if (XMEMCMP(sharedA, sharedB, x))
  31452. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31453. ret = curve25519_overflow_test();
  31454. if (ret != 0)
  31455. goto cleanup;
  31456. ret = curve25519_check_public_test();
  31457. if (ret != 0)
  31458. goto cleanup;
  31459. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31460. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31461. defined(HAVE_CURVE25519_KEY_IMPORT)
  31462. ret = curve255519_der_test();
  31463. if (ret != 0)
  31464. goto cleanup;
  31465. #endif
  31466. cleanup:
  31467. /* clean up keys when done */
  31468. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31469. wc_curve25519_delete(pubKey, &pubKey);
  31470. wc_curve25519_delete(userB, &userB);
  31471. wc_curve25519_delete(userA, &userA);
  31472. #else
  31473. wc_curve25519_free(pubKey);
  31474. wc_curve25519_free(userB);
  31475. wc_curve25519_free(userA);
  31476. #endif
  31477. wc_FreeRng(&rng);
  31478. return ret;
  31479. }
  31480. #endif /* HAVE_CURVE25519 */
  31481. #ifdef HAVE_ED25519
  31482. #ifdef WOLFSSL_TEST_CERT
  31483. static wc_test_ret_t ed25519_test_cert(void)
  31484. {
  31485. DecodedCert cert[2];
  31486. DecodedCert* serverCert = NULL;
  31487. DecodedCert* caCert = NULL;
  31488. #ifdef HAVE_ED25519_VERIFY
  31489. ed25519_key key;
  31490. ed25519_key* pubKey = NULL;
  31491. int verify;
  31492. #endif /* HAVE_ED25519_VERIFY */
  31493. wc_test_ret_t ret;
  31494. byte* tmp;
  31495. size_t bytes;
  31496. XFILE file;
  31497. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31498. if (tmp == NULL) {
  31499. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31500. }
  31501. #ifdef USE_CERT_BUFFERS_256
  31502. XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert);
  31503. bytes = sizeof_ca_ed25519_cert;
  31504. #elif !defined(NO_FILESYSTEM)
  31505. file = XFOPEN(caEd25519Cert, "rb");
  31506. if (file == NULL) {
  31507. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31508. }
  31509. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31510. XFCLOSE(file);
  31511. if (bytes == 0)
  31512. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31513. #else
  31514. /* No certificate to use. */
  31515. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31516. #endif
  31517. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  31518. caCert = &cert[0];
  31519. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  31520. if (ret != 0)
  31521. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31522. #ifdef USE_CERT_BUFFERS_256
  31523. XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert);
  31524. bytes = sizeof_server_ed25519_cert;
  31525. #elif !defined(NO_FILESYSTEM)
  31526. file = XFOPEN(serverEd25519Cert, "rb");
  31527. if (file == NULL) {
  31528. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31529. }
  31530. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31531. XFCLOSE(file);
  31532. if (bytes == 0)
  31533. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31534. #else
  31535. /* No certificate to use. */
  31536. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31537. #endif
  31538. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  31539. serverCert = &cert[1];
  31540. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  31541. if (ret != 0)
  31542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31543. #ifdef HAVE_ED25519_VERIFY
  31544. ret = wc_ed25519_init(&key);
  31545. if (ret < 0)
  31546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31547. pubKey = &key;
  31548. ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize,
  31549. pubKey);
  31550. if (ret < 0)
  31551. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31552. ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength,
  31553. serverCert->source + serverCert->certBegin,
  31554. serverCert->sigIndex - serverCert->certBegin,
  31555. &verify, pubKey);
  31556. if (ret < 0 || verify != 1)
  31557. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31558. #endif /* HAVE_ED25519_VERIFY */
  31559. done:
  31560. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31561. #ifdef HAVE_ED25519_VERIFY
  31562. wc_ed25519_free(pubKey);
  31563. #endif /* HAVE_ED25519_VERIFY */
  31564. if (caCert != NULL)
  31565. FreeDecodedCert(caCert);
  31566. if (serverCert != NULL)
  31567. FreeDecodedCert(serverCert);
  31568. return ret;
  31569. }
  31570. static wc_test_ret_t ed25519_test_make_cert(void)
  31571. {
  31572. WC_RNG rng;
  31573. Cert cert;
  31574. DecodedCert decode;
  31575. ed25519_key key;
  31576. ed25519_key* privKey = NULL;
  31577. wc_test_ret_t ret = 0;
  31578. byte* tmp = NULL;
  31579. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  31580. #ifndef HAVE_FIPS
  31581. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31582. #else
  31583. ret = wc_InitRng(&rng);
  31584. #endif
  31585. if (ret != 0)
  31586. return WC_TEST_RET_ENC_EC(ret);
  31587. wc_ed25519_init(&key);
  31588. privKey = &key;
  31589. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, privKey);
  31590. cert.daysValid = 365 * 2;
  31591. cert.selfSigned = 1;
  31592. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  31593. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  31594. cert.isCA = 0;
  31595. #ifdef WOLFSSL_CERT_EXT
  31596. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  31597. if (ret < 0)
  31598. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31599. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31600. if (ret < 0)
  31601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31602. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31603. if (ret < 0)
  31604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31605. #endif
  31606. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31607. if (tmp == NULL) {
  31608. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31609. }
  31610. cert.sigType = CTC_ED25519;
  31611. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng);
  31612. if (ret < 0)
  31613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31614. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF,
  31615. ED25519_TYPE, privKey, &rng);
  31616. if (ret < 0)
  31617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31618. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  31619. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  31620. FreeDecodedCert(&decode);
  31621. if (ret != 0)
  31622. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31623. done:
  31624. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31625. wc_ed25519_free(privKey);
  31626. wc_FreeRng(&rng);
  31627. return ret;
  31628. }
  31629. #endif /* WOLFSSL_TEST_CERT */
  31630. #if defined(HAVE_ED25519_KEY_IMPORT)
  31631. static wc_test_ret_t ed25519_test_check_key(void)
  31632. {
  31633. /* Fails to find x-ordinate from this y-ordinate. */
  31634. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  31635. 0x40,
  31636. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31637. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31638. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31639. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31640. };
  31641. /* Y-ordinate value larger than prime. */
  31642. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  31643. 0x40,
  31644. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31645. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31646. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31647. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31648. };
  31649. /* Y-ordinate value equal to prime. */
  31650. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  31651. 0x40,
  31652. 0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31653. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31654. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31655. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31656. };
  31657. /* Y-ordinate value equal to prime - 1. */
  31658. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  31659. 0x40,
  31660. 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31661. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31662. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31663. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31664. };
  31665. ed25519_key key;
  31666. int ret;
  31667. int res = 0;
  31668. /* Initialize key for use. */
  31669. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31670. if (ret != 0) {
  31671. return WC_TEST_RET_ENC_NC;
  31672. }
  31673. /* Load bad public key only and perform checks. */
  31674. ret = wc_ed25519_import_public(key_bad_y, ED25519_PUB_KEY_SIZE + 1, &key);
  31675. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31676. res = WC_TEST_RET_ENC_NC;
  31677. }
  31678. if (res == 0) {
  31679. /* Load bad public key only and perform checks. */
  31680. ret = wc_ed25519_import_public(key_bad_y_max, ED25519_PUB_KEY_SIZE + 1,
  31681. &key);
  31682. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31683. res = WC_TEST_RET_ENC_NC;
  31684. }
  31685. }
  31686. if (res == 0) {
  31687. /* Load bad public key only and perform checks. */
  31688. ret = wc_ed25519_import_public(key_bad_y_is_p, ED25519_PUB_KEY_SIZE + 1,
  31689. &key);
  31690. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31691. res = WC_TEST_RET_ENC_NC;
  31692. }
  31693. }
  31694. if (res == 0) {
  31695. /* Load good public key only and perform checks. */
  31696. ret = wc_ed25519_import_public(key_y_is_p_minus_1,
  31697. ED25519_PUB_KEY_SIZE + 1, &key);
  31698. if (ret != 0) {
  31699. res = WC_TEST_RET_ENC_NC;
  31700. }
  31701. }
  31702. /* Dispose of key. */
  31703. wc_ed25519_free(&key);
  31704. return res;
  31705. }
  31706. #endif
  31707. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31708. defined(HAVE_ED25519_KEY_IMPORT)
  31709. static wc_test_ret_t ed25519ctx_test(void)
  31710. {
  31711. wc_test_ret_t ret;
  31712. byte out[ED25519_SIG_SIZE];
  31713. word32 outlen;
  31714. #ifdef HAVE_ED25519_VERIFY
  31715. int verify = 0;
  31716. #endif /* HAVE_ED25519_VERIFY */
  31717. ed25519_key key;
  31718. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  31719. 0x03,0x05,0x33,0x4e,0x38,0x1a,0xf7,0x8f,
  31720. 0x14,0x1c,0xb6,0x66,0xf6,0x19,0x9f,0x57,
  31721. 0xbc,0x34,0x95,0x33,0x5a,0x25,0x6a,0x95,
  31722. 0xbd,0x2a,0x55,0xbf,0x54,0x66,0x63,0xf6
  31723. };
  31724. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  31725. 0xdf,0xc9,0x42,0x5e,0x4f,0x96,0x8f,0x7f,
  31726. 0x0c,0x29,0xf0,0x25,0x9c,0xf5,0xf9,0xae,
  31727. 0xd6,0x85,0x1c,0x2b,0xb4,0xad,0x8b,0xfb,
  31728. 0x86,0x0c,0xfe,0xe0,0xab,0x24,0x82,0x92
  31729. };
  31730. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx1[] = {
  31731. 0x55,0xa4,0xcc,0x2f,0x70,0xa5,0x4e,0x04,
  31732. 0x28,0x8c,0x5f,0x4c,0xd1,0xe4,0x5a,0x7b,
  31733. 0xb5,0x20,0xb3,0x62,0x92,0x91,0x18,0x76,
  31734. 0xca,0xda,0x73,0x23,0x19,0x8d,0xd8,0x7a,
  31735. 0x8b,0x36,0x95,0x0b,0x95,0x13,0x00,0x22,
  31736. 0x90,0x7a,0x7f,0xb7,0xc4,0xe9,0xb2,0xd5,
  31737. 0xf6,0xcc,0xa6,0x85,0xa5,0x87,0xb4,0xb2,
  31738. 0x1f,0x4b,0x88,0x8e,0x4e,0x7e,0xdb,0x0d
  31739. };
  31740. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx2[] = {
  31741. 0xcc,0x5e,0x63,0xa2,0x7e,0x94,0xaf,0xd3,
  31742. 0x41,0x83,0x38,0xd2,0x48,0x6f,0xa9,0x2a,
  31743. 0xf9,0x91,0x7c,0x2d,0x98,0x9e,0x06,0xe5,
  31744. 0x02,0x77,0x72,0x1c,0x34,0x38,0x18,0xb4,
  31745. 0x21,0x96,0xbc,0x29,0x2e,0x68,0xf3,0x4d,
  31746. 0x85,0x9b,0xbe,0xad,0x17,0x9f,0x54,0x54,
  31747. 0x2d,0x4b,0x04,0xdc,0xfb,0xfa,0x4a,0x68,
  31748. 0x4e,0x39,0x50,0xfb,0x1c,0xcd,0x8d,0x0d
  31749. };
  31750. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  31751. 0xf7,0x26,0x93,0x6d,0x19,0xc8,0x00,0x49,
  31752. 0x4e,0x3f,0xda,0xff,0x20,0xb2,0x76,0xa8
  31753. };
  31754. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  31755. 0x66,0x6f,0x6f
  31756. };
  31757. outlen = sizeof(out);
  31758. XMEMSET(out, 0, sizeof(out));
  31759. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31760. if (ret != 0)
  31761. return 10800;
  31762. ret = wc_ed25519_import_private_key(sKeyCtx, ED25519_KEY_SIZE, pKeyCtx,
  31763. sizeof(pKeyCtx), &key);
  31764. if (ret == 0)
  31765. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31766. contextCtx, sizeof(contextCtx));
  31767. if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0)
  31768. ret = WC_TEST_RET_ENC_NC;
  31769. #if defined(HAVE_ED25519_VERIFY)
  31770. /* test verify on good msg */
  31771. if (ret == 0)
  31772. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31773. &verify, &key, contextCtx, sizeof(contextCtx));
  31774. if (ret == 0 && verify != 1)
  31775. ret = WC_TEST_RET_ENC_NC;
  31776. #endif
  31777. if (ret == 0)
  31778. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31779. NULL, 0);
  31780. if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0)
  31781. ret = WC_TEST_RET_ENC_NC;
  31782. #if defined(HAVE_ED25519_VERIFY)
  31783. /* test verify on good msg */
  31784. if (ret == 0)
  31785. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31786. &verify, &key, NULL, 0);
  31787. if (ret == 0 && verify != 1)
  31788. ret = WC_TEST_RET_ENC_NC;
  31789. #endif
  31790. wc_ed25519_free(&key);
  31791. return ret;
  31792. }
  31793. static wc_test_ret_t ed25519ph_test(void)
  31794. {
  31795. wc_test_ret_t ret = 0;
  31796. byte out[ED25519_SIG_SIZE];
  31797. word32 outlen;
  31798. #ifdef HAVE_ED25519_VERIFY
  31799. int verify = 0;
  31800. #endif /* HAVE_ED25519_VERIFY */
  31801. ed25519_key key;
  31802. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  31803. 0x83,0x3f,0xe6,0x24,0x09,0x23,0x7b,0x9d,
  31804. 0x62,0xec,0x77,0x58,0x75,0x20,0x91,0x1e,
  31805. 0x9a,0x75,0x9c,0xec,0x1d,0x19,0x75,0x5b,
  31806. 0x7d,0xa9,0x01,0xb9,0x6d,0xca,0x3d,0x42
  31807. };
  31808. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  31809. 0xec,0x17,0x2b,0x93,0xad,0x5e,0x56,0x3b,
  31810. 0xf4,0x93,0x2c,0x70,0xe1,0x24,0x50,0x34,
  31811. 0xc3,0x54,0x67,0xef,0x2e,0xfd,0x4d,0x64,
  31812. 0xeb,0xf8,0x19,0x68,0x34,0x67,0xe2,0xbf
  31813. };
  31814. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  31815. 0x98,0xa7,0x02,0x22,0xf0,0xb8,0x12,0x1a,
  31816. 0xa9,0xd3,0x0f,0x81,0x3d,0x68,0x3f,0x80,
  31817. 0x9e,0x46,0x2b,0x46,0x9c,0x7f,0xf8,0x76,
  31818. 0x39,0x49,0x9b,0xb9,0x4e,0x6d,0xae,0x41,
  31819. 0x31,0xf8,0x50,0x42,0x46,0x3c,0x2a,0x35,
  31820. 0x5a,0x20,0x03,0xd0,0x62,0xad,0xf5,0xaa,
  31821. 0xa1,0x0b,0x8c,0x61,0xe6,0x36,0x06,0x2a,
  31822. 0xaa,0xd1,0x1c,0x2a,0x26,0x08,0x34,0x06
  31823. };
  31824. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  31825. 0xe0,0x39,0x70,0x2b,0x4c,0x25,0x95,0xa6,
  31826. 0xa5,0x41,0xac,0x85,0x09,0x23,0x6e,0x29,
  31827. 0x90,0x47,0x47,0x95,0x33,0x0c,0x9b,0x34,
  31828. 0xa7,0x5f,0x58,0xa6,0x60,0x12,0x9e,0x08,
  31829. 0xfd,0x73,0x69,0x43,0xfb,0x19,0x43,0xa5,
  31830. 0x57,0x20,0xb9,0xe0,0x95,0x7b,0x1e,0xd6,
  31831. 0x73,0x48,0x16,0x61,0x9f,0x13,0x88,0xf4,
  31832. 0x3f,0x73,0xe6,0xe3,0xba,0xa8,0x1c,0x0e
  31833. };
  31834. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  31835. 0x61,0x62,0x63
  31836. };
  31837. /* SHA-512 hash of msgPh */
  31838. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  31839. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  31840. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  31841. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  31842. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  31843. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  31844. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  31845. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  31846. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f
  31847. };
  31848. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  31849. 0x66,0x6f,0x6f
  31850. };
  31851. outlen = sizeof(out);
  31852. XMEMSET(out, 0, sizeof(out));
  31853. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31854. if (ret != 0)
  31855. return WC_TEST_RET_ENC_EC(ret);
  31856. ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh,
  31857. sizeof(pKeyPh), &key);
  31858. if (ret == 0)
  31859. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31860. NULL, 0);
  31861. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31862. ret = WC_TEST_RET_ENC_NC;
  31863. #if defined(HAVE_ED25519_VERIFY)
  31864. /* test verify on good msg */
  31865. if (ret == 0)
  31866. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh),
  31867. &verify, &key, NULL, 0);
  31868. if (ret == 0 && verify != 1)
  31869. ret = WC_TEST_RET_ENC_NC;
  31870. #endif
  31871. if (ret == 0)
  31872. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31873. contextPh2, sizeof(contextPh2));
  31874. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31875. ret = WC_TEST_RET_ENC_NC;
  31876. #if defined(HAVE_ED25519_VERIFY)
  31877. /* test verify on good msg */
  31878. if (ret == 0)
  31879. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify,
  31880. &key, contextPh2, sizeof(contextPh2));
  31881. if (ret == 0 && verify != 1)
  31882. ret = WC_TEST_RET_ENC_NC;
  31883. #endif
  31884. if (ret == 0)
  31885. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31886. NULL, 0);
  31887. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31888. ret = WC_TEST_RET_ENC_NC;
  31889. #if defined(HAVE_ED25519_VERIFY)
  31890. if (ret == 0)
  31891. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh),
  31892. &verify, &key, NULL, 0);
  31893. if (ret == 0 && verify != 1)
  31894. ret = WC_TEST_RET_ENC_NC;
  31895. #endif
  31896. if (ret == 0)
  31897. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31898. contextPh2, sizeof(contextPh2));
  31899. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31900. ret = WC_TEST_RET_ENC_NC;
  31901. #if defined(HAVE_ED25519_VERIFY)
  31902. if (ret == 0)
  31903. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  31904. &key, contextPh2, sizeof(contextPh2));
  31905. if (ret == 0 && verify != 1)
  31906. ret = WC_TEST_RET_ENC_NC;
  31907. #endif
  31908. wc_ed25519_free(&key);
  31909. return ret;
  31910. }
  31911. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31912. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
  31913. {
  31914. wc_test_ret_t ret;
  31915. WC_RNG rng;
  31916. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31917. defined(HAVE_ED25519_KEY_IMPORT)
  31918. byte out[ED25519_SIG_SIZE];
  31919. byte exportPKey[ED25519_KEY_SIZE];
  31920. byte exportSKey[ED25519_KEY_SIZE];
  31921. word32 exportPSz;
  31922. word32 exportSSz;
  31923. int i;
  31924. word32 outlen;
  31925. #ifdef HAVE_ED25519_VERIFY
  31926. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  31927. int j;
  31928. #endif
  31929. int verify;
  31930. #endif /* HAVE_ED25519_VERIFY */
  31931. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31932. word32 keySz, sigSz;
  31933. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31934. ed25519_key* key = NULL;
  31935. ed25519_key* key2 = NULL;
  31936. #else
  31937. ed25519_key key[1];
  31938. ed25519_key key2[1];
  31939. #endif
  31940. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31941. defined(HAVE_ED25519_KEY_IMPORT)
  31942. /* test vectors from
  31943. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02
  31944. */
  31945. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  31946. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31947. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31948. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31949. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31950. };
  31951. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  31952. 0x4c,0xcd,0x08,0x9b,0x28,0xff,0x96,0xda,
  31953. 0x9d,0xb6,0xc3,0x46,0xec,0x11,0x4e,0x0f,
  31954. 0x5b,0x8a,0x31,0x9f,0x35,0xab,0xa6,0x24,
  31955. 0xda,0x8c,0xf6,0xed,0x4f,0xb8,0xa6,0xfb
  31956. };
  31957. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  31958. 0xc5,0xaa,0x8d,0xf4,0x3f,0x9f,0x83,0x7b,
  31959. 0xed,0xb7,0x44,0x2f,0x31,0xdc,0xb7,0xb1,
  31960. 0x66,0xd3,0x85,0x35,0x07,0x6f,0x09,0x4b,
  31961. 0x85,0xce,0x3a,0x2e,0x0b,0x44,0x58,0xf7
  31962. };
  31963. /* uncompressed test */
  31964. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  31965. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31966. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31967. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31968. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31969. };
  31970. /* compressed prefix test */
  31971. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  31972. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31973. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31974. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31975. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31976. };
  31977. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  31978. 0xf5,0xe5,0x76,0x7c,0xf1,0x53,0x31,0x95,
  31979. 0x17,0x63,0x0f,0x22,0x68,0x76,0xb8,0x6c,
  31980. 0x81,0x60,0xcc,0x58,0x3b,0xc0,0x13,0x74,
  31981. 0x4c,0x6b,0xf2,0x55,0xf5,0xcc,0x0e,0xe5
  31982. };
  31983. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  31984. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  31985. 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31986. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31987. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31988. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31989. };
  31990. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  31991. 0x3d,0x40,0x17,0xc3,0xe8,0x43,0x89,0x5a,
  31992. 0x92,0xb7,0x0a,0xa7,0x4d,0x1b,0x7e,0xbc,
  31993. 0x9c,0x98,0x2c,0xcf,0x2e,0xc4,0x96,0x8c,
  31994. 0xc0,0xcd,0x55,0xf1,0x2a,0xf4,0x66,0x0c
  31995. };
  31996. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  31997. 0xfc,0x51,0xcd,0x8e,0x62,0x18,0xa1,0xa3,
  31998. 0x8d,0xa4,0x7e,0xd0,0x02,0x30,0xf0,0x58,
  31999. 0x08,0x16,0xed,0x13,0xba,0x33,0x03,0xac,
  32000. 0x5d,0xeb,0x91,0x15,0x48,0x90,0x80,0x25
  32001. };
  32002. /* uncompressed test */
  32003. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  32004. 0x04,0x55,0xd0,0xe0,0x9a,0x2b,0x9d,0x34,
  32005. 0x29,0x22,0x97,0xe0,0x8d,0x60,0xd0,0xf6,
  32006. 0x20,0xc5,0x13,0xd4,0x72,0x53,0x18,0x7c,
  32007. 0x24,0xb1,0x27,0x86,0xbd,0x77,0x76,0x45,
  32008. 0xce,0x1a,0x51,0x07,0xf7,0x68,0x1a,0x02,
  32009. 0xaf,0x25,0x23,0xa6,0xda,0xf3,0x72,0xe1,
  32010. 0x0e,0x3a,0x07,0x64,0xc9,0xd3,0xfe,0x4b,
  32011. 0xd5,0xb7,0x0a,0xb1,0x82,0x01,0x98,0x5a,
  32012. 0xd7
  32013. };
  32014. /* compressed prefix */
  32015. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  32016. 0x40,0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  32017. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  32018. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  32019. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  32020. };
  32021. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  32022. 0x27,0x81,0x17,0xfc,0x14,0x4c,0x72,0x34,
  32023. 0x0f,0x67,0xd0,0xf2,0x31,0x6e,0x83,0x86,
  32024. 0xce,0xff,0xbf,0x2b,0x24,0x28,0xc9,0xc5,
  32025. 0x1f,0xef,0x7c,0x59,0x7f,0x1d,0x42,0x6e
  32026. };
  32027. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  32028. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  32029. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  32030. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  32031. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32032. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32033. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32034. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32035. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32036. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32037. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32038. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32039. };
  32040. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  32041. 0x92,0xa0,0x09,0xa9,0xf0,0xd4,0xca,0xb8,
  32042. 0x72,0x0e,0x82,0x0b,0x5f,0x64,0x25,0x40,
  32043. 0xa2,0xb2,0x7b,0x54,0x16,0x50,0x3f,0x8f,
  32044. 0xb3,0x76,0x22,0x23,0xeb,0xdb,0x69,0xda,
  32045. 0x08,0x5a,0xc1,0xe4,0x3e,0x15,0x99,0x6e,
  32046. 0x45,0x8f,0x36,0x13,0xd0,0xf1,0x1d,0x8c,
  32047. 0x38,0x7b,0x2e,0xae,0xb4,0x30,0x2a,0xee,
  32048. 0xb0,0x0d,0x29,0x16,0x12,0xbb,0x0c,0x00
  32049. };
  32050. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  32051. 0x62,0x91,0xd6,0x57,0xde,0xec,0x24,0x02,
  32052. 0x48,0x27,0xe6,0x9c,0x3a,0xbe,0x01,0xa3,
  32053. 0x0c,0xe5,0x48,0xa2,0x84,0x74,0x3a,0x44,
  32054. 0x5e,0x36,0x80,0xd7,0xdb,0x5a,0xc3,0xac,
  32055. 0x18,0xff,0x9b,0x53,0x8d,0x16,0xf2,0x90,
  32056. 0xae,0x67,0xf7,0x60,0x98,0x4d,0xc6,0x59,
  32057. 0x4a,0x7c,0x15,0xe9,0x71,0x6e,0xd2,0x8d,
  32058. 0xc0,0x27,0xbe,0xce,0xea,0x1e,0xc4,0x0a
  32059. };
  32060. /* uncompressed test */
  32061. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  32062. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32063. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32064. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32065. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32066. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32067. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32068. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32069. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32070. };
  32071. /* compressed prefix */
  32072. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  32073. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32074. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32075. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32076. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32077. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32078. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32079. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32080. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32081. };
  32082. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  32083. 0x0a,0xab,0x4c,0x90,0x05,0x01,0xb3,0xe2,
  32084. 0x4d,0x7c,0xdf,0x46,0x63,0x32,0x6a,0x3a,
  32085. 0x87,0xdf,0x5e,0x48,0x43,0xb2,0xcb,0xdb,
  32086. 0x67,0xcb,0xf6,0xe4,0x60,0xfe,0xc3,0x50,
  32087. 0xaa,0x53,0x71,0xb1,0x50,0x8f,0x9f,0x45,
  32088. 0x28,0xec,0xea,0x23,0xc4,0x36,0xd9,0x4b,
  32089. 0x5e,0x8f,0xcd,0x4f,0x68,0x1e,0x30,0xa6,
  32090. 0xac,0x00,0xa9,0x70,0x4a,0x18,0x8a,0x03
  32091. };
  32092. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  32093. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {0x0 };
  32094. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {0x72};
  32095. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {0xAF,0x82};
  32096. /* test of a 1024 byte long message */
  32097. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  32098. 0x08,0xb8,0xb2,0xb7,0x33,0x42,0x42,0x43,
  32099. 0x76,0x0f,0xe4,0x26,0xa4,0xb5,0x49,0x08,
  32100. 0x63,0x21,0x10,0xa6,0x6c,0x2f,0x65,0x91,
  32101. 0xea,0xbd,0x33,0x45,0xe3,0xe4,0xeb,0x98,
  32102. 0xfa,0x6e,0x26,0x4b,0xf0,0x9e,0xfe,0x12,
  32103. 0xee,0x50,0xf8,0xf5,0x4e,0x9f,0x77,0xb1,
  32104. 0xe3,0x55,0xf6,0xc5,0x05,0x44,0xe2,0x3f,
  32105. 0xb1,0x43,0x3d,0xdf,0x73,0xbe,0x84,0xd8,
  32106. 0x79,0xde,0x7c,0x00,0x46,0xdc,0x49,0x96,
  32107. 0xd9,0xe7,0x73,0xf4,0xbc,0x9e,0xfe,0x57,
  32108. 0x38,0x82,0x9a,0xdb,0x26,0xc8,0x1b,0x37,
  32109. 0xc9,0x3a,0x1b,0x27,0x0b,0x20,0x32,0x9d,
  32110. 0x65,0x86,0x75,0xfc,0x6e,0xa5,0x34,0xe0,
  32111. 0x81,0x0a,0x44,0x32,0x82,0x6b,0xf5,0x8c,
  32112. 0x94,0x1e,0xfb,0x65,0xd5,0x7a,0x33,0x8b,
  32113. 0xbd,0x2e,0x26,0x64,0x0f,0x89,0xff,0xbc,
  32114. 0x1a,0x85,0x8e,0xfc,0xb8,0x55,0x0e,0xe3,
  32115. 0xa5,0xe1,0x99,0x8b,0xd1,0x77,0xe9,0x3a,
  32116. 0x73,0x63,0xc3,0x44,0xfe,0x6b,0x19,0x9e,
  32117. 0xe5,0xd0,0x2e,0x82,0xd5,0x22,0xc4,0xfe,
  32118. 0xba,0x15,0x45,0x2f,0x80,0x28,0x8a,0x82,
  32119. 0x1a,0x57,0x91,0x16,0xec,0x6d,0xad,0x2b,
  32120. 0x3b,0x31,0x0d,0xa9,0x03,0x40,0x1a,0xa6,
  32121. 0x21,0x00,0xab,0x5d,0x1a,0x36,0x55,0x3e,
  32122. 0x06,0x20,0x3b,0x33,0x89,0x0c,0xc9,0xb8,
  32123. 0x32,0xf7,0x9e,0xf8,0x05,0x60,0xcc,0xb9,
  32124. 0xa3,0x9c,0xe7,0x67,0x96,0x7e,0xd6,0x28,
  32125. 0xc6,0xad,0x57,0x3c,0xb1,0x16,0xdb,0xef,
  32126. 0xef,0xd7,0x54,0x99,0xda,0x96,0xbd,0x68,
  32127. 0xa8,0xa9,0x7b,0x92,0x8a,0x8b,0xbc,0x10,
  32128. 0x3b,0x66,0x21,0xfc,0xde,0x2b,0xec,0xa1,
  32129. 0x23,0x1d,0x20,0x6b,0xe6,0xcd,0x9e,0xc7,
  32130. 0xaf,0xf6,0xf6,0xc9,0x4f,0xcd,0x72,0x04,
  32131. 0xed,0x34,0x55,0xc6,0x8c,0x83,0xf4,0xa4,
  32132. 0x1d,0xa4,0xaf,0x2b,0x74,0xef,0x5c,0x53,
  32133. 0xf1,0xd8,0xac,0x70,0xbd,0xcb,0x7e,0xd1,
  32134. 0x85,0xce,0x81,0xbd,0x84,0x35,0x9d,0x44,
  32135. 0x25,0x4d,0x95,0x62,0x9e,0x98,0x55,0xa9,
  32136. 0x4a,0x7c,0x19,0x58,0xd1,0xf8,0xad,0xa5,
  32137. 0xd0,0x53,0x2e,0xd8,0xa5,0xaa,0x3f,0xb2,
  32138. 0xd1,0x7b,0xa7,0x0e,0xb6,0x24,0x8e,0x59,
  32139. 0x4e,0x1a,0x22,0x97,0xac,0xbb,0xb3,0x9d,
  32140. 0x50,0x2f,0x1a,0x8c,0x6e,0xb6,0xf1,0xce,
  32141. 0x22,0xb3,0xde,0x1a,0x1f,0x40,0xcc,0x24,
  32142. 0x55,0x41,0x19,0xa8,0x31,0xa9,0xaa,0xd6,
  32143. 0x07,0x9c,0xad,0x88,0x42,0x5d,0xe6,0xbd,
  32144. 0xe1,0xa9,0x18,0x7e,0xbb,0x60,0x92,0xcf,
  32145. 0x67,0xbf,0x2b,0x13,0xfd,0x65,0xf2,0x70,
  32146. 0x88,0xd7,0x8b,0x7e,0x88,0x3c,0x87,0x59,
  32147. 0xd2,0xc4,0xf5,0xc6,0x5a,0xdb,0x75,0x53,
  32148. 0x87,0x8a,0xd5,0x75,0xf9,0xfa,0xd8,0x78,
  32149. 0xe8,0x0a,0x0c,0x9b,0xa6,0x3b,0xcb,0xcc,
  32150. 0x27,0x32,0xe6,0x94,0x85,0xbb,0xc9,0xc9,
  32151. 0x0b,0xfb,0xd6,0x24,0x81,0xd9,0x08,0x9b,
  32152. 0xec,0xcf,0x80,0xcf,0xe2,0xdf,0x16,0xa2,
  32153. 0xcf,0x65,0xbd,0x92,0xdd,0x59,0x7b,0x07,
  32154. 0x07,0xe0,0x91,0x7a,0xf4,0x8b,0xbb,0x75,
  32155. 0xfe,0xd4,0x13,0xd2,0x38,0xf5,0x55,0x5a,
  32156. 0x7a,0x56,0x9d,0x80,0xc3,0x41,0x4a,0x8d,
  32157. 0x08,0x59,0xdc,0x65,0xa4,0x61,0x28,0xba,
  32158. 0xb2,0x7a,0xf8,0x7a,0x71,0x31,0x4f,0x31,
  32159. 0x8c,0x78,0x2b,0x23,0xeb,0xfe,0x80,0x8b,
  32160. 0x82,0xb0,0xce,0x26,0x40,0x1d,0x2e,0x22,
  32161. 0xf0,0x4d,0x83,0xd1,0x25,0x5d,0xc5,0x1a,
  32162. 0xdd,0xd3,0xb7,0x5a,0x2b,0x1a,0xe0,0x78,
  32163. 0x45,0x04,0xdf,0x54,0x3a,0xf8,0x96,0x9b,
  32164. 0xe3,0xea,0x70,0x82,0xff,0x7f,0xc9,0x88,
  32165. 0x8c,0x14,0x4d,0xa2,0xaf,0x58,0x42,0x9e,
  32166. 0xc9,0x60,0x31,0xdb,0xca,0xd3,0xda,0xd9,
  32167. 0xaf,0x0d,0xcb,0xaa,0xaf,0x26,0x8c,0xb8,
  32168. 0xfc,0xff,0xea,0xd9,0x4f,0x3c,0x7c,0xa4,
  32169. 0x95,0xe0,0x56,0xa9,0xb4,0x7a,0xcd,0xb7,
  32170. 0x51,0xfb,0x73,0xe6,0x66,0xc6,0xc6,0x55,
  32171. 0xad,0xe8,0x29,0x72,0x97,0xd0,0x7a,0xd1,
  32172. 0xba,0x5e,0x43,0xf1,0xbc,0xa3,0x23,0x01,
  32173. 0x65,0x13,0x39,0xe2,0x29,0x04,0xcc,0x8c,
  32174. 0x42,0xf5,0x8c,0x30,0xc0,0x4a,0xaf,0xdb,
  32175. 0x03,0x8d,0xda,0x08,0x47,0xdd,0x98,0x8d,
  32176. 0xcd,0xa6,0xf3,0xbf,0xd1,0x5c,0x4b,0x4c,
  32177. 0x45,0x25,0x00,0x4a,0xa0,0x6e,0xef,0xf8,
  32178. 0xca,0x61,0x78,0x3a,0xac,0xec,0x57,0xfb,
  32179. 0x3d,0x1f,0x92,0xb0,0xfe,0x2f,0xd1,0xa8,
  32180. 0x5f,0x67,0x24,0x51,0x7b,0x65,0xe6,0x14,
  32181. 0xad,0x68,0x08,0xd6,0xf6,0xee,0x34,0xdf,
  32182. 0xf7,0x31,0x0f,0xdc,0x82,0xae,0xbf,0xd9,
  32183. 0x04,0xb0,0x1e,0x1d,0xc5,0x4b,0x29,0x27,
  32184. 0x09,0x4b,0x2d,0xb6,0x8d,0x6f,0x90,0x3b,
  32185. 0x68,0x40,0x1a,0xde,0xbf,0x5a,0x7e,0x08,
  32186. 0xd7,0x8f,0xf4,0xef,0x5d,0x63,0x65,0x3a,
  32187. 0x65,0x04,0x0c,0xf9,0xbf,0xd4,0xac,0xa7,
  32188. 0x98,0x4a,0x74,0xd3,0x71,0x45,0x98,0x67,
  32189. 0x80,0xfc,0x0b,0x16,0xac,0x45,0x16,0x49,
  32190. 0xde,0x61,0x88,0xa7,0xdb,0xdf,0x19,0x1f,
  32191. 0x64,0xb5,0xfc,0x5e,0x2a,0xb4,0x7b,0x57,
  32192. 0xf7,0xf7,0x27,0x6c,0xd4,0x19,0xc1,0x7a,
  32193. 0x3c,0xa8,0xe1,0xb9,0x39,0xae,0x49,0xe4,
  32194. 0x88,0xac,0xba,0x6b,0x96,0x56,0x10,0xb5,
  32195. 0x48,0x01,0x09,0xc8,0xb1,0x7b,0x80,0xe1,
  32196. 0xb7,0xb7,0x50,0xdf,0xc7,0x59,0x8d,0x5d,
  32197. 0x50,0x11,0xfd,0x2d,0xcc,0x56,0x00,0xa3,
  32198. 0x2e,0xf5,0xb5,0x2a,0x1e,0xcc,0x82,0x0e,
  32199. 0x30,0x8a,0xa3,0x42,0x72,0x1a,0xac,0x09,
  32200. 0x43,0xbf,0x66,0x86,0xb6,0x4b,0x25,0x79,
  32201. 0x37,0x65,0x04,0xcc,0xc4,0x93,0xd9,0x7e,
  32202. 0x6a,0xed,0x3f,0xb0,0xf9,0xcd,0x71,0xa4,
  32203. 0x3d,0xd4,0x97,0xf0,0x1f,0x17,0xc0,0xe2,
  32204. 0xcb,0x37,0x97,0xaa,0x2a,0x2f,0x25,0x66,
  32205. 0x56,0x16,0x8e,0x6c,0x49,0x6a,0xfc,0x5f,
  32206. 0xb9,0x32,0x46,0xf6,0xb1,0x11,0x63,0x98,
  32207. 0xa3,0x46,0xf1,0xa6,0x41,0xf3,0xb0,0x41,
  32208. 0xe9,0x89,0xf7,0x91,0x4f,0x90,0xcc,0x2c,
  32209. 0x7f,0xff,0x35,0x78,0x76,0xe5,0x06,0xb5,
  32210. 0x0d,0x33,0x4b,0xa7,0x7c,0x22,0x5b,0xc3,
  32211. 0x07,0xba,0x53,0x71,0x52,0xf3,0xf1,0x61,
  32212. 0x0e,0x4e,0xaf,0xe5,0x95,0xf6,0xd9,0xd9,
  32213. 0x0d,0x11,0xfa,0xa9,0x33,0xa1,0x5e,0xf1,
  32214. 0x36,0x95,0x46,0x86,0x8a,0x7f,0x3a,0x45,
  32215. 0xa9,0x67,0x68,0xd4,0x0f,0xd9,0xd0,0x34,
  32216. 0x12,0xc0,0x91,0xc6,0x31,0x5c,0xf4,0xfd,
  32217. 0xe7,0xcb,0x68,0x60,0x69,0x37,0x38,0x0d,
  32218. 0xb2,0xea,0xaa,0x70,0x7b,0x4c,0x41,0x85,
  32219. 0xc3,0x2e,0xdd,0xcd,0xd3,0x06,0x70,0x5e,
  32220. 0x4d,0xc1,0xff,0xc8,0x72,0xee,0xee,0x47,
  32221. 0x5a,0x64,0xdf,0xac,0x86,0xab,0xa4,0x1c,
  32222. 0x06,0x18,0x98,0x3f,0x87,0x41,0xc5,0xef,
  32223. 0x68,0xd3,0xa1,0x01,0xe8,0xa3,0xb8,0xca,
  32224. 0xc6,0x0c,0x90,0x5c,0x15,0xfc,0x91,0x08,
  32225. 0x40,0xb9,0x4c,0x00,0xa0,0xb9,0xd0
  32226. };
  32227. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  32228. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  32229. sizeof(msg2),
  32230. sizeof(msg3),
  32231. 0 /*sizeof(msg1)*/,
  32232. 0 /*sizeof(msg1)*/,
  32233. sizeof(msg4)
  32234. };
  32235. #ifndef NO_ASN
  32236. static const byte privateEd25519[] = {
  32237. 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
  32238. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32239. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32240. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32241. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32242. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  32243. };
  32244. static const byte badPrivateEd25519[] = {
  32245. 0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
  32246. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32247. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32248. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32249. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32250. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32251. 0xa1,0x22,0x04,0x21,0xd7,0x5a,0x98,0x01, /* octet len 0x20 -> 0x21 */
  32252. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32253. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32254. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32255. 0xf7,0x07,0x51,0x1a,
  32256. 0x00 /* add additional bytes to make the pubkey bigger */
  32257. };
  32258. static const byte publicEd25519[] = {
  32259. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32260. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32261. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32262. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32263. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32264. 0xf7,0x07,0x51,0x1a
  32265. };
  32266. /* size has been altered to catch if sanity check is done */
  32267. static const byte badPublicEd25519[] = {
  32268. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32269. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32270. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32271. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32272. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32273. 0xf7,0x07,0x51,0x1a,
  32274. 0x00 /* add an additional byte to make the pubkey appear bigger */
  32275. };
  32276. static const byte privPubEd25519[] = {
  32277. 0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
  32278. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32279. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32280. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32281. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32282. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32283. 0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
  32284. 0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
  32285. 0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
  32286. 0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
  32287. 0x51,0x1a
  32288. };
  32289. word32 idx;
  32290. #endif /* NO_ASN */
  32291. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32292. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32293. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32294. ed25519_key* key3 = NULL;
  32295. #else
  32296. ed25519_key key3[1];
  32297. #endif
  32298. #endif
  32299. WOLFSSL_ENTER("ed25519_test");
  32300. /* create ed25519 keys */
  32301. #ifndef HAVE_FIPS
  32302. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32303. #else
  32304. ret = wc_InitRng(&rng);
  32305. #endif
  32306. if (ret != 0)
  32307. return WC_TEST_RET_ENC_EC(ret);
  32308. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32309. key = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32310. if (ret != 0)
  32311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32312. key2 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32313. if (ret != 0)
  32314. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32315. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32316. key3 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32317. if (ret != 0)
  32318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32319. #endif
  32320. #else
  32321. wc_ed25519_init_ex(key, HEAP_HINT, devId);
  32322. wc_ed25519_init_ex(key2, HEAP_HINT, devId);
  32323. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32324. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32325. #endif
  32326. #endif
  32327. #ifdef HAVE_ED25519_MAKE_KEY
  32328. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
  32329. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key2);
  32330. #endif
  32331. /* helper functions for signature and key size */
  32332. keySz = (word32)wc_ed25519_size(key);
  32333. sigSz = (word32)wc_ed25519_sig_size(key);
  32334. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  32335. defined(HAVE_ED25519_KEY_IMPORT)
  32336. for (i = 0; i < 6; i++) {
  32337. outlen = sizeof(out);
  32338. XMEMSET(out, 0, sizeof(out));
  32339. if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i],
  32340. pKeySz[i], key) != 0)
  32341. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32342. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key) != 0)
  32343. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32344. if (XMEMCMP(out, sigs[i], 64))
  32345. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32346. #if defined(HAVE_ED25519_VERIFY)
  32347. /* test verify on good msg */
  32348. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32349. key) != 0 || verify != 1)
  32350. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32351. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  32352. /* test verify on good msg using streaming interface directly */
  32353. if (wc_ed25519_verify_msg_init(out, outlen,
  32354. key, (byte)Ed25519, NULL, 0) != 0)
  32355. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32356. for (j = 0; j < msgSz[i]; j += i) {
  32357. if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  32358. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32359. }
  32360. if (wc_ed25519_verify_msg_final(out, outlen, &verify,
  32361. key) != 0 || verify != 1)
  32362. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32363. #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */
  32364. /* test verify on bad msg */
  32365. out[outlen-1] = out[outlen-1] + 1;
  32366. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32367. key) == 0 || verify == 1)
  32368. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32369. #endif /* HAVE_ED25519_VERIFY */
  32370. /* test api for import/exporting keys */
  32371. exportPSz = sizeof(exportPKey);
  32372. exportSSz = sizeof(exportSKey);
  32373. if (wc_ed25519_export_public(key, exportPKey, &exportPSz) != 0)
  32374. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32375. if (wc_ed25519_import_public_ex(exportPKey, exportPSz, key2, 1) != 0)
  32376. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32377. if (wc_ed25519_export_private_only(key, exportSKey, &exportSSz) != 0)
  32378. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32379. if (wc_ed25519_import_private_key(exportSKey, exportSSz,
  32380. exportPKey, exportPSz, key2) != 0)
  32381. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32382. /* clear "out" buffer and test sign with imported keys */
  32383. outlen = sizeof(out);
  32384. XMEMSET(out, 0, sizeof(out));
  32385. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key2) != 0)
  32386. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32387. #if defined(HAVE_ED25519_VERIFY)
  32388. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32389. key2) != 0 || verify != 1)
  32390. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32391. if (XMEMCMP(out, sigs[i], 64))
  32392. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32393. #endif /* HAVE_ED25519_VERIFY */
  32394. }
  32395. {
  32396. /* Run tests for some rare code paths */
  32397. /* sig is exactly equal to the order */
  32398. static const byte rareEd1[] = {
  32399. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32400. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32401. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32402. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32403. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32404. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32405. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32406. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32407. };
  32408. /* sig is larger than the order before we get to the low part */
  32409. static const byte rareEd2[] = {
  32410. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32411. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32412. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32413. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32414. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32415. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32416. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32417. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10
  32418. };
  32419. /* sig is larger than the order in the low part */
  32420. static const byte rareEd3[] = {
  32421. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32422. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32423. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32425. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32426. 0xd6, 0x9c, 0xf9, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32427. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32428. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32429. };
  32430. /* sig is smaller than the order */
  32431. static const byte rareEd4[] = {
  32432. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32433. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32434. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32435. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32436. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32437. 0xd6, 0x9c, 0xf1, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32438. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32439. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32440. };
  32441. ret = wc_ed25519_import_private_key(sKeys[0], ED25519_KEY_SIZE,
  32442. pKeys[0], pKeySz[0], key);
  32443. if (ret != 0)
  32444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32445. ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
  32446. &verify, key);
  32447. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32449. ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), msgs[0], msgSz[0],
  32450. &verify, key);
  32451. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32452. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32453. ret = wc_ed25519_verify_msg(rareEd3, sizeof(rareEd3), msgs[0], msgSz[0],
  32454. &verify, key);
  32455. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32456. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32457. ret = wc_ed25519_verify_msg(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
  32458. &verify, key);
  32459. if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
  32460. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32461. }
  32462. ret = ed25519ctx_test();
  32463. if (ret != 0)
  32464. goto cleanup;
  32465. ret = ed25519ph_test();
  32466. if (ret != 0)
  32467. goto cleanup;
  32468. #ifndef NO_ASN
  32469. /* Try ASN.1 encoded private-only key and public key. */
  32470. idx = 0;
  32471. ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, key3,
  32472. sizeof(privateEd25519));
  32473. if (ret != 0)
  32474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32475. idx = 0;
  32476. if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, key3,
  32477. sizeof(badPrivateEd25519)) == 0)
  32478. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32479. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32480. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32482. /* try with a buffer size that is too large */
  32483. idx = 0;
  32484. if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, key3,
  32485. sizeof(badPublicEd25519)) == 0)
  32486. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32487. idx = 0;
  32488. ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, key3,
  32489. sizeof(publicEd25519));
  32490. if (ret != 0)
  32491. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32492. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32493. if (ret != 0)
  32494. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32495. if (XMEMCMP(out, sigs[0], 64))
  32496. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32497. #if defined(HAVE_ED25519_VERIFY)
  32498. /* test verify on good msg */
  32499. ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3);
  32500. if (ret != 0 || verify != 1)
  32501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32502. #endif /* HAVE_ED25519_VERIFY */
  32503. wc_ed25519_free(key3);
  32504. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32505. idx = 0;
  32506. ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, key3,
  32507. sizeof(privPubEd25519));
  32508. if (ret != 0)
  32509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32510. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32511. if (ret != 0)
  32512. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32513. if (XMEMCMP(out, sigs[0], 64))
  32514. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32515. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32516. wc_ed25519_delete(key3, &key3);
  32517. #else
  32518. wc_ed25519_free(key3);
  32519. #endif
  32520. #endif /* NO_ASN */
  32521. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32522. ret = ed25519_test_check_key();
  32523. if (ret < 0)
  32524. goto cleanup;
  32525. #ifdef WOLFSSL_TEST_CERT
  32526. ret = ed25519_test_cert();
  32527. if (ret < 0)
  32528. goto cleanup;
  32529. #if defined(WOLFSSL_CERT_GEN) && defined(HAVE_ED25519_MAKE_KEY)
  32530. ret = ed25519_test_make_cert();
  32531. if (ret < 0)
  32532. goto cleanup;
  32533. #endif /* WOLFSSL_CERT_GEN */
  32534. #endif /* WOLFSSL_TEST_CERT */
  32535. cleanup:
  32536. /* clean up keys when done */
  32537. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32538. wc_ed25519_delete(key, &key);
  32539. wc_ed25519_delete(key2, &key2);
  32540. #else
  32541. wc_ed25519_free(key);
  32542. wc_ed25519_free(key2);
  32543. #endif
  32544. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  32545. wc_FreeRng(&rng);
  32546. #endif
  32547. /* hush warnings of unused keySz and sigSz */
  32548. (void)keySz;
  32549. (void)sigSz;
  32550. return ret;
  32551. }
  32552. #endif /* HAVE_ED25519 */
  32553. #ifdef HAVE_CURVE448
  32554. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32555. defined(HAVE_CURVE448_KEY_IMPORT)
  32556. /* Test the wc_curve448_check_public API.
  32557. *
  32558. * returns 0 on success and -ve on failure.
  32559. */
  32560. static wc_test_ret_t curve448_check_public_test(void)
  32561. {
  32562. /* Little-endian values that will fail */
  32563. byte fail_le[][CURVE448_KEY_SIZE] = {
  32564. {
  32565. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32566. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32567. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32568. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32569. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32570. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32571. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32572. },
  32573. {
  32574. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32575. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32576. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32577. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32578. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32579. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32580. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32581. },
  32582. };
  32583. /* Big-endian values that will fail */
  32584. byte fail_be[][CURVE448_KEY_SIZE] = {
  32585. {
  32586. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32587. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32588. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32589. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32590. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32591. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32592. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  32593. },
  32594. {
  32595. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32596. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32597. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32598. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32599. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32600. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32601. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32602. },
  32603. };
  32604. /* Good or valid public value */
  32605. byte good[CURVE448_KEY_SIZE] = {
  32606. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32607. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32608. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32609. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32610. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32611. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32612. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32613. };
  32614. int i;
  32615. wc_test_ret_t ret;
  32616. /* Parameter checks */
  32617. /* NULL pointer */
  32618. ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN);
  32619. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32620. return WC_TEST_RET_ENC_EC(ret);
  32621. ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN);
  32622. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32623. return WC_TEST_RET_ENC_EC(ret);
  32624. /* Length of 0 treated differently to other invalid lengths for TLS */
  32625. ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN);
  32626. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32627. return WC_TEST_RET_ENC_EC(ret);
  32628. ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN);
  32629. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32630. return WC_TEST_RET_ENC_EC(ret);
  32631. /* Length not CURVE448_KEY_SIZE */
  32632. for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) {
  32633. if (i == CURVE448_KEY_SIZE)
  32634. continue;
  32635. if (wc_curve448_check_public(good, (word32)i, EC448_LITTLE_ENDIAN) !=
  32636. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32637. return WC_TEST_RET_ENC_I(i);
  32638. }
  32639. if (wc_curve448_check_public(good, (word32)i, EC448_BIG_ENDIAN) !=
  32640. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32641. return WC_TEST_RET_ENC_I(i);
  32642. }
  32643. }
  32644. /* Little-endian fail cases */
  32645. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  32646. if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE,
  32647. EC448_LITTLE_ENDIAN) == 0) {
  32648. return WC_TEST_RET_ENC_I(i);
  32649. }
  32650. }
  32651. /* Big-endian fail cases */
  32652. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  32653. if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE,
  32654. EC448_BIG_ENDIAN) == 0) {
  32655. return WC_TEST_RET_ENC_I(i);
  32656. }
  32657. }
  32658. /* Check a valid public value works! */
  32659. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE,
  32660. EC448_LITTLE_ENDIAN);
  32661. if (ret != 0)
  32662. return WC_TEST_RET_ENC_EC(ret);
  32663. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN);
  32664. if (ret != 0)
  32665. return WC_TEST_RET_ENC_EC(ret);
  32666. return 0;
  32667. }
  32668. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32669. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
  32670. {
  32671. WC_RNG rng;
  32672. wc_test_ret_t ret;
  32673. #ifdef HAVE_CURVE448_SHARED_SECRET
  32674. byte sharedA[CURVE448_KEY_SIZE];
  32675. byte sharedB[CURVE448_KEY_SIZE];
  32676. word32 y;
  32677. #endif
  32678. #ifdef HAVE_CURVE448_KEY_EXPORT
  32679. byte exportBuf[CURVE448_KEY_SIZE];
  32680. #endif
  32681. word32 x = 0;
  32682. curve448_key userA, userB, pubKey;
  32683. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32684. defined(HAVE_CURVE448_KEY_IMPORT)
  32685. /* test vectors from
  32686. https://www.rfc-editor.org/rfc/rfc7748.html
  32687. */
  32688. /* secret key for party a */
  32689. byte sa[] = {
  32690. 0x6b, 0x72, 0x98, 0xa5, 0xc0, 0xd8, 0xc2, 0x9a,
  32691. 0x1d, 0xab, 0x27, 0xf1, 0xa6, 0x82, 0x63, 0x00,
  32692. 0x91, 0x73, 0x89, 0x44, 0x97, 0x41, 0xa9, 0x74,
  32693. 0xf5, 0xba, 0xc9, 0xd9, 0x8d, 0xc2, 0x98, 0xd4,
  32694. 0x65, 0x55, 0xbc, 0xe8, 0xba, 0xe8, 0x9e, 0xee,
  32695. 0xd4, 0x00, 0x58, 0x4b, 0xb0, 0x46, 0xcf, 0x75,
  32696. 0x57, 0x9f, 0x51, 0xd1, 0x25, 0x49, 0x8f, 0x9a,
  32697. };
  32698. /* public key for party a */
  32699. byte pa[] = {
  32700. 0xa0, 0x1f, 0xc4, 0x32, 0xe5, 0x80, 0x7f, 0x17,
  32701. 0x53, 0x0d, 0x12, 0x88, 0xda, 0x12, 0x5b, 0x0c,
  32702. 0xd4, 0x53, 0xd9, 0x41, 0x72, 0x64, 0x36, 0xc8,
  32703. 0xbb, 0xd9, 0xc5, 0x22, 0x2c, 0x3d, 0xa7, 0xfa,
  32704. 0x63, 0x9c, 0xe0, 0x3d, 0xb8, 0xd2, 0x3b, 0x27,
  32705. 0x4a, 0x07, 0x21, 0xa1, 0xae, 0xd5, 0x22, 0x7d,
  32706. 0xe6, 0xe3, 0xb7, 0x31, 0xcc, 0xf7, 0x08, 0x9b,
  32707. };
  32708. /* secret key for party b */
  32709. byte sb[] = {
  32710. 0x2d, 0x99, 0x73, 0x51, 0xb6, 0x10, 0x6f, 0x36,
  32711. 0xb0, 0xd1, 0x09, 0x1b, 0x92, 0x9c, 0x4c, 0x37,
  32712. 0x21, 0x3e, 0x0d, 0x2b, 0x97, 0xe8, 0x5e, 0xbb,
  32713. 0x20, 0xc1, 0x27, 0x69, 0x1d, 0x0d, 0xad, 0x8f,
  32714. 0x1d, 0x81, 0x75, 0xb0, 0x72, 0x37, 0x45, 0xe6,
  32715. 0x39, 0xa3, 0xcb, 0x70, 0x44, 0x29, 0x0b, 0x99,
  32716. 0xe0, 0xe2, 0xa0, 0xc2, 0x7a, 0x6a, 0x30, 0x1c,
  32717. };
  32718. /* public key for party b */
  32719. byte pb[] = {
  32720. 0x09, 0x36, 0xf3, 0x7b, 0xc6, 0xc1, 0xbd, 0x07,
  32721. 0xae, 0x3d, 0xec, 0x7a, 0xb5, 0xdc, 0x06, 0xa7,
  32722. 0x3c, 0xa1, 0x32, 0x42, 0xfb, 0x34, 0x3e, 0xfc,
  32723. 0x72, 0xb9, 0xd8, 0x27, 0x30, 0xb4, 0x45, 0xf3,
  32724. 0xd4, 0xb0, 0xbd, 0x07, 0x71, 0x62, 0xa4, 0x6d,
  32725. 0xcf, 0xec, 0x6f, 0x9b, 0x59, 0x0b, 0xfc, 0xbc,
  32726. 0xf5, 0x20, 0xcd, 0xb0, 0x29, 0xa8, 0xb7, 0x3e,
  32727. };
  32728. /* expected shared key */
  32729. byte ss[] = {
  32730. 0x9d, 0x87, 0x4a, 0x51, 0x37, 0x50, 0x9a, 0x44,
  32731. 0x9a, 0xd5, 0x85, 0x30, 0x40, 0x24, 0x1c, 0x52,
  32732. 0x36, 0x39, 0x54, 0x35, 0xc3, 0x64, 0x24, 0xfd,
  32733. 0x56, 0x0b, 0x0c, 0xb6, 0x2b, 0x28, 0x1d, 0x28,
  32734. 0x52, 0x75, 0xa7, 0x40, 0xce, 0x32, 0xa2, 0x2d,
  32735. 0xd1, 0x74, 0x0f, 0x4a, 0xa9, 0x16, 0x1c, 0xec,
  32736. 0x95, 0xcc, 0xc6, 0x1a, 0x18, 0xf4, 0xff, 0x07,
  32737. };
  32738. #endif /* HAVE_CURVE448_SHARED_SECRET */
  32739. (void)x;
  32740. WOLFSSL_ENTER("curve448_test");
  32741. #ifndef HAVE_FIPS
  32742. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32743. #else
  32744. ret = wc_InitRng(&rng);
  32745. #endif
  32746. if (ret != 0)
  32747. return WC_TEST_RET_ENC_EC(ret);
  32748. wc_curve448_init(&userA);
  32749. wc_curve448_init(&userB);
  32750. wc_curve448_init(&pubKey);
  32751. /* make curve448 keys */
  32752. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA);
  32753. if (ret != 0)
  32754. return WC_TEST_RET_ENC_EC(ret);
  32755. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB);
  32756. if (ret != 0)
  32757. return WC_TEST_RET_ENC_EC(ret);
  32758. #ifdef HAVE_CURVE448_SHARED_SECRET
  32759. /* find shared secret key */
  32760. x = sizeof(sharedA);
  32761. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32762. if (ret != 0)
  32763. return WC_TEST_RET_ENC_EC(ret);
  32764. y = sizeof(sharedB);
  32765. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32766. if (ret != 0)
  32767. return WC_TEST_RET_ENC_EC(ret);
  32768. /* compare shared secret keys to test they are the same */
  32769. if (y != x)
  32770. return WC_TEST_RET_ENC_NC;
  32771. if (XMEMCMP(sharedA, sharedB, x))
  32772. return WC_TEST_RET_ENC_NC;
  32773. #endif
  32774. #ifdef HAVE_CURVE448_KEY_EXPORT
  32775. /* export a public key and import it for another user */
  32776. x = sizeof(exportBuf);
  32777. ret = wc_curve448_export_public(&userA, exportBuf, &x);
  32778. if (ret != 0)
  32779. return WC_TEST_RET_ENC_EC(ret);
  32780. #ifdef HAVE_CURVE448_KEY_IMPORT
  32781. ret = wc_curve448_import_public(exportBuf, x, &pubKey);
  32782. if (ret != 0)
  32783. return WC_TEST_RET_ENC_EC(ret);
  32784. #endif
  32785. #endif
  32786. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32787. defined(HAVE_CURVE448_KEY_IMPORT)
  32788. /* test shared key after importing a public key */
  32789. XMEMSET(sharedB, 0, sizeof(sharedB));
  32790. y = sizeof(sharedB);
  32791. ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y);
  32792. if (ret != 0)
  32793. return WC_TEST_RET_ENC_EC(ret);
  32794. if (XMEMCMP(sharedA, sharedB, y))
  32795. return WC_TEST_RET_ENC_NC;
  32796. /* import RFC test vectors and compare shared key */
  32797. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32798. if (ret != 0)
  32799. return WC_TEST_RET_ENC_EC(ret);
  32800. ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB);
  32801. if (ret != 0)
  32802. return WC_TEST_RET_ENC_EC(ret);
  32803. /* test against known test vector */
  32804. XMEMSET(sharedB, 0, sizeof(sharedB));
  32805. y = sizeof(sharedB);
  32806. ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y);
  32807. if (ret != 0)
  32808. return WC_TEST_RET_ENC_EC(ret);
  32809. if (XMEMCMP(ss, sharedB, y))
  32810. return WC_TEST_RET_ENC_NC;
  32811. /* test swapping roles of keys and generating same shared key */
  32812. XMEMSET(sharedB, 0, sizeof(sharedB));
  32813. y = sizeof(sharedB);
  32814. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32815. if (ret != 0)
  32816. return WC_TEST_RET_ENC_EC(ret);
  32817. if (XMEMCMP(ss, sharedB, y))
  32818. return WC_TEST_RET_ENC_NC;
  32819. /* test with 1 generated key and 1 from known test vector */
  32820. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32821. if (ret != 0)
  32822. return WC_TEST_RET_ENC_EC(ret);
  32823. ret = wc_curve448_make_key(&rng, 56, &userB);
  32824. if (ret != 0)
  32825. return WC_TEST_RET_ENC_EC(ret);
  32826. x = sizeof(sharedA);
  32827. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32828. if (ret != 0)
  32829. return WC_TEST_RET_ENC_EC(ret);
  32830. y = sizeof(sharedB);
  32831. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32832. if (ret != 0)
  32833. return WC_TEST_RET_ENC_EC(ret);
  32834. /* compare shared secret keys to test they are the same */
  32835. if (y != x)
  32836. return WC_TEST_RET_ENC_NC;
  32837. if (XMEMCMP(sharedA, sharedB, x))
  32838. return WC_TEST_RET_ENC_NC;
  32839. ret = curve448_check_public_test();
  32840. if (ret != 0)
  32841. return ret;
  32842. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32843. /* clean up keys when done */
  32844. wc_curve448_free(&pubKey);
  32845. wc_curve448_free(&userB);
  32846. wc_curve448_free(&userA);
  32847. wc_FreeRng(&rng);
  32848. return 0;
  32849. }
  32850. #endif /* HAVE_CURVE448 */
  32851. #ifdef HAVE_ED448
  32852. #ifdef WOLFSSL_TEST_CERT
  32853. static wc_test_ret_t ed448_test_cert(void)
  32854. {
  32855. DecodedCert cert[2];
  32856. DecodedCert* serverCert = NULL;
  32857. DecodedCert* caCert = NULL;
  32858. #ifdef HAVE_ED448_VERIFY
  32859. ed448_key key;
  32860. ed448_key* pubKey = NULL;
  32861. int verify;
  32862. #endif /* HAVE_ED448_VERIFY */
  32863. wc_test_ret_t ret;
  32864. byte* tmp;
  32865. size_t bytes;
  32866. XFILE file;
  32867. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32868. if (tmp == NULL) {
  32869. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32870. }
  32871. #ifdef USE_CERT_BUFFERS_256
  32872. XMEMCPY(tmp, ca_ed448_cert, sizeof_ca_ed448_cert);
  32873. bytes = sizeof_ca_ed448_cert;
  32874. #elif !defined(NO_FILESYSTEM)
  32875. file = XFOPEN(caEd448Cert, "rb");
  32876. if (file == NULL) {
  32877. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32878. }
  32879. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32880. XFCLOSE(file);
  32881. if (bytes == 0)
  32882. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32883. #else
  32884. /* No certificate to use. */
  32885. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32886. #endif
  32887. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  32888. caCert = &cert[0];
  32889. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  32890. if (ret != 0)
  32891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32892. #ifdef USE_CERT_BUFFERS_256
  32893. XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert);
  32894. bytes = sizeof_server_ed448_cert;
  32895. #elif !defined(NO_FILESYSTEM)
  32896. file = XFOPEN(serverEd448Cert, "rb");
  32897. if (file == NULL) {
  32898. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32899. }
  32900. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32901. XFCLOSE(file);
  32902. if (bytes == 0)
  32903. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32904. #else
  32905. /* No certificate to use. */
  32906. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32907. #endif
  32908. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  32909. serverCert = &cert[1];
  32910. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  32911. if (ret != 0)
  32912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32913. #ifdef HAVE_ED448_VERIFY
  32914. ret = wc_ed448_init(&key);
  32915. if (ret < 0)
  32916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32917. pubKey = &key;
  32918. ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey);
  32919. if (ret < 0)
  32920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32921. ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength,
  32922. serverCert->source + serverCert->certBegin,
  32923. serverCert->sigIndex - serverCert->certBegin,
  32924. &verify, pubKey, NULL, 0);
  32925. if (ret < 0 || verify != 1) {
  32926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32927. }
  32928. #endif /* HAVE_ED448_VERIFY */
  32929. done:
  32930. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32931. #ifdef HAVE_ED448_VERIFY
  32932. wc_ed448_free(pubKey);
  32933. #endif /* HAVE_ED448_VERIFY */
  32934. if (caCert != NULL)
  32935. FreeDecodedCert(caCert);
  32936. if (serverCert != NULL)
  32937. FreeDecodedCert(serverCert);
  32938. return ret;
  32939. }
  32940. static wc_test_ret_t ed448_test_make_cert(void)
  32941. {
  32942. WC_RNG rng;
  32943. Cert cert;
  32944. DecodedCert decode;
  32945. ed448_key key;
  32946. ed448_key* privKey = NULL;
  32947. wc_test_ret_t ret = 0;
  32948. byte* tmp = NULL;
  32949. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  32950. #ifndef HAVE_FIPS
  32951. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32952. #else
  32953. ret = wc_InitRng(&rng);
  32954. #endif
  32955. if (ret != 0)
  32956. return WC_TEST_RET_ENC_EC(ret);
  32957. wc_ed448_init(&key);
  32958. privKey = &key;
  32959. wc_ed448_make_key(&rng, ED448_KEY_SIZE, privKey);
  32960. cert.daysValid = 365 * 2;
  32961. cert.selfSigned = 1;
  32962. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  32963. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  32964. cert.isCA = 0;
  32965. #ifdef WOLFSSL_CERT_EXT
  32966. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  32967. if (ret < 0)
  32968. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32969. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32970. if (ret < 0)
  32971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32972. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32973. if (ret < 0)
  32974. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32975. #endif
  32976. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32977. if (tmp == NULL) {
  32978. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32979. }
  32980. cert.sigType = CTC_ED448;
  32981. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng);
  32982. if (ret < 0)
  32983. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32984. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE,
  32985. privKey, &rng);
  32986. if (ret < 0)
  32987. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32988. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  32989. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  32990. FreeDecodedCert(&decode);
  32991. if (ret != 0)
  32992. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32993. done:
  32994. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32995. wc_ed448_free(privKey);
  32996. wc_FreeRng(&rng);
  32997. return ret;
  32998. }
  32999. #endif /* WOLFSSL_TEST_CERT */
  33000. #if defined(HAVE_ED448_KEY_IMPORT)
  33001. static wc_test_ret_t ed448_test_check_key(void)
  33002. {
  33003. /* Fails to find x-ordinate from this y-ordinate. */
  33004. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  33005. 0x40,
  33006. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33007. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33008. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33009. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33010. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33011. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33012. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33013. 0x00
  33014. };
  33015. /* Y-ordinate value larger than prime. */
  33016. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  33017. 0x40,
  33018. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33019. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33020. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33021. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33022. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33023. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33024. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33025. 0xff
  33026. };
  33027. /* Y-ordinate value equal to prime. */
  33028. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  33029. 0x40,
  33030. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33031. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33032. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33033. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  33034. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33035. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33036. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33037. 0xff
  33038. };
  33039. /* Y-ordinate value equal to prime - 1. */
  33040. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  33041. 0x40,
  33042. 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33043. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33044. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33045. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  33046. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33047. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33048. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33049. 0xff
  33050. };
  33051. ed448_key key;
  33052. int ret;
  33053. int res = 0;
  33054. /* Initialize key for use. */
  33055. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33056. if (ret != 0) {
  33057. return WC_TEST_RET_ENC_NC;
  33058. }
  33059. /* Load bad public key only and perform checks. */
  33060. ret = wc_ed448_import_public(key_bad_y, ED448_PUB_KEY_SIZE + 1, &key);
  33061. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33062. res = WC_TEST_RET_ENC_NC;
  33063. }
  33064. if (ret == 0) {
  33065. /* Load bad public key only and perform checks. */
  33066. ret = wc_ed448_import_public(key_bad_y_max, ED448_PUB_KEY_SIZE + 1,
  33067. &key);
  33068. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33069. res = WC_TEST_RET_ENC_NC;
  33070. }
  33071. }
  33072. if (res == 0) {
  33073. /* Load bad public key only and perform checks. */
  33074. ret = wc_ed448_import_public(key_bad_y_is_p, ED448_PUB_KEY_SIZE + 1,
  33075. &key);
  33076. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33077. res = WC_TEST_RET_ENC_NC;
  33078. }
  33079. }
  33080. if (res == 0) {
  33081. /* Load good public key only and perform checks. */
  33082. ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1,
  33083. &key);
  33084. if (ret != 0) {
  33085. res = WC_TEST_RET_ENC_NC;
  33086. }
  33087. }
  33088. /* Dispose of key. */
  33089. wc_ed448_free(&key);
  33090. return res;
  33091. }
  33092. #endif
  33093. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33094. defined(HAVE_ED448_KEY_IMPORT)
  33095. static wc_test_ret_t ed448_ctx_test(void)
  33096. {
  33097. wc_test_ret_t ret;
  33098. byte out[ED448_SIG_SIZE];
  33099. word32 outlen;
  33100. #ifdef HAVE_ED448_VERIFY
  33101. int verify;
  33102. #endif /* HAVE_ED448_VERIFY */
  33103. ed448_key key;
  33104. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  33105. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33106. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33107. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33108. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33109. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33110. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33111. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33112. 0x4e
  33113. };
  33114. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  33115. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33116. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33117. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33118. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33119. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33120. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33121. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33122. 0x80
  33123. };
  33124. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx[] = {
  33125. 0xd4, 0xf8, 0xf6, 0x13, 0x17, 0x70, 0xdd, 0x46,
  33126. 0xf4, 0x08, 0x67, 0xd6, 0xfd, 0x5d, 0x50, 0x55,
  33127. 0xde, 0x43, 0x54, 0x1f, 0x8c, 0x5e, 0x35, 0xab,
  33128. 0xbc, 0xd0, 0x01, 0xb3, 0x2a, 0x89, 0xf7, 0xd2,
  33129. 0x15, 0x1f, 0x76, 0x47, 0xf1, 0x1d, 0x8c, 0xa2,
  33130. 0xae, 0x27, 0x9f, 0xb8, 0x42, 0xd6, 0x07, 0x21,
  33131. 0x7f, 0xce, 0x6e, 0x04, 0x2f, 0x68, 0x15, 0xea,
  33132. 0x00, 0x0c, 0x85, 0x74, 0x1d, 0xe5, 0xc8, 0xda,
  33133. 0x11, 0x44, 0xa6, 0xa1, 0xab, 0xa7, 0xf9, 0x6d,
  33134. 0xe4, 0x25, 0x05, 0xd7, 0xa7, 0x29, 0x85, 0x24,
  33135. 0xfd, 0xa5, 0x38, 0xfc, 0xcb, 0xbb, 0x75, 0x4f,
  33136. 0x57, 0x8c, 0x1c, 0xad, 0x10, 0xd5, 0x4d, 0x0d,
  33137. 0x54, 0x28, 0x40, 0x7e, 0x85, 0xdc, 0xbc, 0x98,
  33138. 0xa4, 0x91, 0x55, 0xc1, 0x37, 0x64, 0xe6, 0x6c,
  33139. 0x3c, 0x00
  33140. };
  33141. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  33142. 0x03
  33143. };
  33144. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  33145. 0x66,0x6f,0x6f
  33146. };
  33147. outlen = sizeof(out);
  33148. XMEMSET(out, 0, sizeof(out));
  33149. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33150. if (ret != 0)
  33151. return WC_TEST_RET_ENC_EC(ret);
  33152. ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx,
  33153. sizeof(pKeyCtx), &key);
  33154. if (ret != 0)
  33155. return WC_TEST_RET_ENC_EC(ret);
  33156. ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  33157. contextCtx, sizeof(contextCtx));
  33158. if (ret != 0)
  33159. return WC_TEST_RET_ENC_EC(ret);
  33160. if (XMEMCMP(out, sigCtx, sizeof(sigCtx)))
  33161. return WC_TEST_RET_ENC_NC;
  33162. #if defined(HAVE_ED448_VERIFY)
  33163. /* test verify on good msg */
  33164. ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key,
  33165. contextCtx, sizeof(contextCtx));
  33166. if (ret != 0 || verify != 1)
  33167. return WC_TEST_RET_ENC_EC(ret);
  33168. #endif
  33169. wc_ed448_free(&key);
  33170. return 0;
  33171. }
  33172. static wc_test_ret_t ed448ph_test(void)
  33173. {
  33174. wc_test_ret_t ret;
  33175. byte out[ED448_SIG_SIZE];
  33176. word32 outlen;
  33177. #ifdef HAVE_ED448_VERIFY
  33178. int verify;
  33179. #endif /* HAVE_ED448_VERIFY */
  33180. ed448_key key;
  33181. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  33182. 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
  33183. 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
  33184. 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
  33185. 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42,
  33186. 0xef, 0x78, 0x22, 0xe0, 0xd5, 0x10, 0x41, 0x27,
  33187. 0xdc, 0x05, 0xd6, 0xdb, 0xef, 0xde, 0x69, 0xe3,
  33188. 0xab, 0x2c, 0xec, 0x7c, 0x86, 0x7c, 0x6e, 0x2c,
  33189. 0x49
  33190. };
  33191. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  33192. 0x25, 0x9b, 0x71, 0xc1, 0x9f, 0x83, 0xef, 0x77,
  33193. 0xa7, 0xab, 0xd2, 0x65, 0x24, 0xcb, 0xdb, 0x31,
  33194. 0x61, 0xb5, 0x90, 0xa4, 0x8f, 0x7d, 0x17, 0xde,
  33195. 0x3e, 0xe0, 0xba, 0x9c, 0x52, 0xbe, 0xb7, 0x43,
  33196. 0xc0, 0x94, 0x28, 0xa1, 0x31, 0xd6, 0xb1, 0xb5,
  33197. 0x73, 0x03, 0xd9, 0x0d, 0x81, 0x32, 0xc2, 0x76,
  33198. 0xd5, 0xed, 0x3d, 0x5d, 0x01, 0xc0, 0xf5, 0x38,
  33199. 0x80
  33200. };
  33201. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  33202. 0x82, 0x2f, 0x69, 0x01, 0xf7, 0x48, 0x0f, 0x3d,
  33203. 0x5f, 0x56, 0x2c, 0x59, 0x29, 0x94, 0xd9, 0x69,
  33204. 0x36, 0x02, 0x87, 0x56, 0x14, 0x48, 0x32, 0x56,
  33205. 0x50, 0x56, 0x00, 0xbb, 0xc2, 0x81, 0xae, 0x38,
  33206. 0x1f, 0x54, 0xd6, 0xbc, 0xe2, 0xea, 0x91, 0x15,
  33207. 0x74, 0x93, 0x2f, 0x52, 0xa4, 0xe6, 0xca, 0xdd,
  33208. 0x78, 0x76, 0x93, 0x75, 0xec, 0x3f, 0xfd, 0x1b,
  33209. 0x80, 0x1a, 0x0d, 0x9b, 0x3f, 0x40, 0x30, 0xcd,
  33210. 0x43, 0x39, 0x64, 0xb6, 0x45, 0x7e, 0xa3, 0x94,
  33211. 0x76, 0x51, 0x12, 0x14, 0xf9, 0x74, 0x69, 0xb5,
  33212. 0x7d, 0xd3, 0x2d, 0xbc, 0x56, 0x0a, 0x9a, 0x94,
  33213. 0xd0, 0x0b, 0xff, 0x07, 0x62, 0x04, 0x64, 0xa3,
  33214. 0xad, 0x20, 0x3d, 0xf7, 0xdc, 0x7c, 0xe3, 0x60,
  33215. 0xc3, 0xcd, 0x36, 0x96, 0xd9, 0xd9, 0xfa, 0xb9,
  33216. 0x0f, 0x00
  33217. };
  33218. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  33219. 0xc3, 0x22, 0x99, 0xd4, 0x6e, 0xc8, 0xff, 0x02,
  33220. 0xb5, 0x45, 0x40, 0x98, 0x28, 0x14, 0xdc, 0xe9,
  33221. 0xa0, 0x58, 0x12, 0xf8, 0x19, 0x62, 0xb6, 0x49,
  33222. 0xd5, 0x28, 0x09, 0x59, 0x16, 0xa2, 0xaa, 0x48,
  33223. 0x10, 0x65, 0xb1, 0x58, 0x04, 0x23, 0xef, 0x92,
  33224. 0x7e, 0xcf, 0x0a, 0xf5, 0x88, 0x8f, 0x90, 0xda,
  33225. 0x0f, 0x6a, 0x9a, 0x85, 0xad, 0x5d, 0xc3, 0xf2,
  33226. 0x80, 0xd9, 0x12, 0x24, 0xba, 0x99, 0x11, 0xa3,
  33227. 0x65, 0x3d, 0x00, 0xe4, 0x84, 0xe2, 0xce, 0x23,
  33228. 0x25, 0x21, 0x48, 0x1c, 0x86, 0x58, 0xdf, 0x30,
  33229. 0x4b, 0xb7, 0x74, 0x5a, 0x73, 0x51, 0x4c, 0xdb,
  33230. 0x9b, 0xf3, 0xe1, 0x57, 0x84, 0xab, 0x71, 0x28,
  33231. 0x4f, 0x8d, 0x07, 0x04, 0xa6, 0x08, 0xc5, 0x4a,
  33232. 0x6b, 0x62, 0xd9, 0x7b, 0xeb, 0x51, 0x1d, 0x13,
  33233. 0x21, 0x00
  33234. };
  33235. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  33236. 0x61,0x62,0x63
  33237. };
  33238. /* SHA-512 hash of msgPh */
  33239. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  33240. 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
  33241. 0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
  33242. 0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
  33243. 0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39,
  33244. 0xd5, 0xa1, 0x5b, 0xef, 0x18, 0x6a, 0x53, 0x86,
  33245. 0xc7, 0x57, 0x44, 0xc0, 0x52, 0x7e, 0x1f, 0xaa,
  33246. 0x9f, 0x87, 0x26, 0xe4, 0x62, 0xa1, 0x2a, 0x4f,
  33247. 0xeb, 0x06, 0xbd, 0x88, 0x01, 0xe7, 0x51, 0xe4
  33248. };
  33249. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  33250. 0x66,0x6f,0x6f
  33251. };
  33252. outlen = sizeof(out);
  33253. XMEMSET(out, 0, sizeof(out));
  33254. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33255. if (ret != 0)
  33256. return WC_TEST_RET_ENC_EC(ret);
  33257. ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh,
  33258. sizeof(pKeyPh), &key);
  33259. if (ret != 0)
  33260. return WC_TEST_RET_ENC_EC(ret);
  33261. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL,
  33262. 0);
  33263. if (ret != 0)
  33264. return WC_TEST_RET_ENC_EC(ret);
  33265. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33266. return WC_TEST_RET_ENC_NC;
  33267. #if defined(HAVE_ED448_VERIFY)
  33268. /* test verify on good msg */
  33269. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33270. NULL, 0);
  33271. if (ret != 0 || verify != 1) {
  33272. return WC_TEST_RET_ENC_EC(ret);
  33273. }
  33274. #endif
  33275. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  33276. contextPh2, sizeof(contextPh2));
  33277. if (ret != 0)
  33278. return WC_TEST_RET_ENC_EC(ret);
  33279. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33280. return WC_TEST_RET_ENC_NC;
  33281. #if defined(HAVE_ED448_VERIFY)
  33282. /* test verify on good msg */
  33283. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33284. contextPh2, sizeof(contextPh2));
  33285. if (ret != 0 || verify != 1) {
  33286. return WC_TEST_RET_ENC_EC(ret);
  33287. }
  33288. #endif
  33289. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL,
  33290. 0);
  33291. if (ret != 0)
  33292. return WC_TEST_RET_ENC_EC(ret);
  33293. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33294. return WC_TEST_RET_ENC_NC;
  33295. #if defined(HAVE_ED448_VERIFY)
  33296. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33297. &key, NULL, 0);
  33298. if (ret != 0 || verify != 1) {
  33299. return WC_TEST_RET_ENC_EC(ret);
  33300. }
  33301. #endif
  33302. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  33303. contextPh2, sizeof(contextPh2));
  33304. if (ret != 0)
  33305. return WC_TEST_RET_ENC_EC(ret);
  33306. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33307. return WC_TEST_RET_ENC_NC;
  33308. #if defined(HAVE_ED448_VERIFY)
  33309. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33310. &key, contextPh2, sizeof(contextPh2));
  33311. if (ret != 0 || verify != 1) {
  33312. return WC_TEST_RET_ENC_EC(ret);
  33313. }
  33314. #endif
  33315. wc_ed448_free(&key);
  33316. return 0;
  33317. }
  33318. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33319. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
  33320. {
  33321. wc_test_ret_t ret;
  33322. WC_RNG rng;
  33323. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33324. defined(HAVE_ED448_KEY_IMPORT)
  33325. byte out[ED448_SIG_SIZE];
  33326. int i;
  33327. word32 outlen;
  33328. #ifdef HAVE_ED448_VERIFY
  33329. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33330. int j;
  33331. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33332. int verify;
  33333. #endif /* HAVE_ED448_VERIFY */
  33334. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33335. word32 keySz, sigSz;
  33336. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33337. ed448_key *key = NULL;
  33338. ed448_key *key2 = NULL;
  33339. #else
  33340. ed448_key key[1];
  33341. ed448_key key2[1];
  33342. #endif
  33343. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33344. defined(HAVE_ED448_KEY_IMPORT)
  33345. /* test vectors from
  33346. https://tools.ietf.org/html/rfc8032
  33347. */
  33348. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  33349. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33350. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33351. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33352. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33353. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33354. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33355. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33356. 0x5b
  33357. };
  33358. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  33359. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33360. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33361. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33362. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33363. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33364. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33365. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33366. 0x4e
  33367. };
  33368. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  33369. 0x25, 0x8c, 0xdd, 0x4a, 0xda, 0x32, 0xed, 0x9c,
  33370. 0x9f, 0xf5, 0x4e, 0x63, 0x75, 0x6a, 0xe5, 0x82,
  33371. 0xfb, 0x8f, 0xab, 0x2a, 0xc7, 0x21, 0xf2, 0xc8,
  33372. 0xe6, 0x76, 0xa7, 0x27, 0x68, 0x51, 0x3d, 0x93,
  33373. 0x9f, 0x63, 0xdd, 0xdb, 0x55, 0x60, 0x91, 0x33,
  33374. 0xf2, 0x9a, 0xdf, 0x86, 0xec, 0x99, 0x29, 0xdc,
  33375. 0xcb, 0x52, 0xc1, 0xc5, 0xfd, 0x2f, 0xf7, 0xe2,
  33376. 0x1b
  33377. };
  33378. /* uncompressed test */
  33379. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  33380. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33381. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33382. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33383. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33384. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33385. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33386. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33387. 0x5b
  33388. };
  33389. /* compressed prefix test */
  33390. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  33391. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33392. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33393. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33394. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33395. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33396. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33397. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33398. 0x5b
  33399. };
  33400. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  33401. 0x87, 0x2d, 0x09, 0x37, 0x80, 0xf5, 0xd3, 0x73,
  33402. 0x0d, 0xf7, 0xc2, 0x12, 0x66, 0x4b, 0x37, 0xb8,
  33403. 0xa0, 0xf2, 0x4f, 0x56, 0x81, 0x0d, 0xaa, 0x83,
  33404. 0x82, 0xcd, 0x4f, 0xa3, 0xf7, 0x76, 0x34, 0xec,
  33405. 0x44, 0xdc, 0x54, 0xf1, 0xc2, 0xed, 0x9b, 0xea,
  33406. 0x86, 0xfa, 0xfb, 0x76, 0x32, 0xd8, 0xbe, 0x19,
  33407. 0x9e, 0xa1, 0x65, 0xf5, 0xad, 0x55, 0xdd, 0x9c,
  33408. 0xe8
  33409. };
  33410. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  33411. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  33412. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33413. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33414. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33415. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33416. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33417. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33418. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33419. 0x80
  33420. };
  33421. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  33422. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33423. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33424. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33425. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33426. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33427. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33428. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33429. 0x80
  33430. };
  33431. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  33432. 0x3b, 0xa1, 0x6d, 0xa0, 0xc6, 0xf2, 0xcc, 0x1f,
  33433. 0x30, 0x18, 0x77, 0x40, 0x75, 0x6f, 0x5e, 0x79,
  33434. 0x8d, 0x6b, 0xc5, 0xfc, 0x01, 0x5d, 0x7c, 0x63,
  33435. 0xcc, 0x95, 0x10, 0xee, 0x3f, 0xd4, 0x4a, 0xdc,
  33436. 0x24, 0xd8, 0xe9, 0x68, 0xb6, 0xe4, 0x6e, 0x6f,
  33437. 0x94, 0xd1, 0x9b, 0x94, 0x53, 0x61, 0x72, 0x6b,
  33438. 0xd7, 0x5e, 0x14, 0x9e, 0xf0, 0x98, 0x17, 0xf5,
  33439. 0x80
  33440. };
  33441. /* uncompressed test */
  33442. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  33443. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33444. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33445. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33446. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33447. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33448. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33449. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33450. 0x80
  33451. };
  33452. /* compressed prefix */
  33453. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  33454. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33455. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33456. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33457. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33458. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33459. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33460. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33461. 0x80
  33462. };
  33463. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  33464. 0xa8, 0x1b, 0x2e, 0x8a, 0x70, 0xa5, 0xac, 0x94,
  33465. 0xff, 0xdb, 0xcc, 0x9b, 0xad, 0xfc, 0x3f, 0xeb,
  33466. 0x08, 0x01, 0xf2, 0x58, 0x57, 0x8b, 0xb1, 0x14,
  33467. 0xad, 0x44, 0xec, 0xe1, 0xec, 0x0e, 0x79, 0x9d,
  33468. 0xa0, 0x8e, 0xff, 0xb8, 0x1c, 0x5d, 0x68, 0x5c,
  33469. 0x0c, 0x56, 0xf6, 0x4e, 0xec, 0xae, 0xf8, 0xcd,
  33470. 0xf1, 0x1c, 0xc3, 0x87, 0x37, 0x83, 0x8c, 0xf4,
  33471. 0x00
  33472. };
  33473. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  33474. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  33475. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  33476. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  33477. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33478. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33479. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33480. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33481. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33482. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33483. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33484. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33485. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33486. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33487. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33488. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33489. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33490. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33491. 0x26, 0x00
  33492. };
  33493. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  33494. 0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89,
  33495. 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3, 0x77,
  33496. 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35,
  33497. 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10, 0xf4, 0x35,
  33498. 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7,
  33499. 0xe1, 0x8f, 0x62, 0xde, 0x8c, 0xcd, 0xf6, 0x33,
  33500. 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79,
  33501. 0x80, 0x5e, 0x0d, 0xbc, 0xc0, 0xaa, 0xe1, 0xcb,
  33502. 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36,
  33503. 0xbc, 0x04, 0xdc, 0xec, 0xbf, 0x15, 0x43, 0x36,
  33504. 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29,
  33505. 0x05, 0xe7, 0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f,
  33506. 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf,
  33507. 0xd1, 0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0,
  33508. 0x3a, 0x00
  33509. };
  33510. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  33511. 0x7e, 0xee, 0xab, 0x7c, 0x4e, 0x50, 0xfb, 0x79,
  33512. 0x9b, 0x41, 0x8e, 0xe5, 0xe3, 0x19, 0x7f, 0xf6,
  33513. 0xbf, 0x15, 0xd4, 0x3a, 0x14, 0xc3, 0x43, 0x89,
  33514. 0xb5, 0x9d, 0xd1, 0xa7, 0xb1, 0xb8, 0x5b, 0x4a,
  33515. 0xe9, 0x04, 0x38, 0xac, 0xa6, 0x34, 0xbe, 0xa4,
  33516. 0x5e, 0x3a, 0x26, 0x95, 0xf1, 0x27, 0x0f, 0x07,
  33517. 0xfd, 0xcd, 0xf7, 0xc6, 0x2b, 0x8e, 0xfe, 0xaf,
  33518. 0x00, 0xb4, 0x5c, 0x2c, 0x96, 0xba, 0x45, 0x7e,
  33519. 0xb1, 0xa8, 0xbf, 0x07, 0x5a, 0x3d, 0xb2, 0x8e,
  33520. 0x5c, 0x24, 0xf6, 0xb9, 0x23, 0xed, 0x4a, 0xd7,
  33521. 0x47, 0xc3, 0xc9, 0xe0, 0x3c, 0x70, 0x79, 0xef,
  33522. 0xb8, 0x7c, 0xb1, 0x10, 0xd3, 0xa9, 0x98, 0x61,
  33523. 0xe7, 0x20, 0x03, 0xcb, 0xae, 0x6d, 0x6b, 0x8b,
  33524. 0x82, 0x7e, 0x4e, 0x6c, 0x14, 0x30, 0x64, 0xff,
  33525. 0x3c, 0x00
  33526. };
  33527. /* uncompressed test */
  33528. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  33529. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33530. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33531. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33532. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33533. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33534. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33535. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33536. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33537. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33538. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33539. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33540. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33541. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33542. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33543. 0x26, 0x00
  33544. };
  33545. /* compressed prefix */
  33546. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  33547. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33548. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33549. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33550. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33551. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33552. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33553. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33554. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33555. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33556. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33557. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33558. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33559. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33560. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33561. 0x26, 0x00
  33562. };
  33563. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  33564. 0xe3, 0x01, 0x34, 0x5a, 0x41, 0xa3, 0x9a, 0x4d,
  33565. 0x72, 0xff, 0xf8, 0xdf, 0x69, 0xc9, 0x80, 0x75,
  33566. 0xa0, 0xcc, 0x08, 0x2b, 0x80, 0x2f, 0xc9, 0xb2,
  33567. 0xb6, 0xbc, 0x50, 0x3f, 0x92, 0x6b, 0x65, 0xbd,
  33568. 0xdf, 0x7f, 0x4c, 0x8f, 0x1c, 0xb4, 0x9f, 0x63,
  33569. 0x96, 0xaf, 0xc8, 0xa7, 0x0a, 0xbe, 0x6d, 0x8a,
  33570. 0xef, 0x0d, 0xb4, 0x78, 0xd4, 0xc6, 0xb2, 0x97,
  33571. 0x00, 0x76, 0xc6, 0xa0, 0x48, 0x4f, 0xe7, 0x6d,
  33572. 0x76, 0xb3, 0xa9, 0x76, 0x25, 0xd7, 0x9f, 0x1c,
  33573. 0xe2, 0x40, 0xe7, 0xc5, 0x76, 0x75, 0x0d, 0x29,
  33574. 0x55, 0x28, 0x28, 0x6f, 0x71, 0x9b, 0x41, 0x3d,
  33575. 0xe9, 0xad, 0xa3, 0xe8, 0xeb, 0x78, 0xed, 0x57,
  33576. 0x36, 0x03, 0xce, 0x30, 0xd8, 0xbb, 0x76, 0x17,
  33577. 0x85, 0xdc, 0x30, 0xdb, 0xc3, 0x20, 0x86, 0x9e,
  33578. 0x1a, 0x00
  33579. };
  33580. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  33581. #define SIGSZ sizeof(sig1)
  33582. PEDANTIC_EXTENSION WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = { 0 };
  33583. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = { 0x03 };
  33584. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = { 0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd,
  33585. 0x66, 0x81, 0x1e, 0x29, 0x15 };
  33586. /* test of a 1023 byte long message */
  33587. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  33588. 0x6d, 0xdf, 0x80, 0x2e, 0x1a, 0xae, 0x49, 0x86,
  33589. 0x93, 0x5f, 0x7f, 0x98, 0x1b, 0xa3, 0xf0, 0x35,
  33590. 0x1d, 0x62, 0x73, 0xc0, 0xa0, 0xc2, 0x2c, 0x9c,
  33591. 0x0e, 0x83, 0x39, 0x16, 0x8e, 0x67, 0x54, 0x12,
  33592. 0xa3, 0xde, 0xbf, 0xaf, 0x43, 0x5e, 0xd6, 0x51,
  33593. 0x55, 0x80, 0x07, 0xdb, 0x43, 0x84, 0xb6, 0x50,
  33594. 0xfc, 0xc0, 0x7e, 0x3b, 0x58, 0x6a, 0x27, 0xa4,
  33595. 0xf7, 0xa0, 0x0a, 0xc8, 0xa6, 0xfe, 0xc2, 0xcd,
  33596. 0x86, 0xae, 0x4b, 0xf1, 0x57, 0x0c, 0x41, 0xe6,
  33597. 0xa4, 0x0c, 0x93, 0x1d, 0xb2, 0x7b, 0x2f, 0xaa,
  33598. 0x15, 0xa8, 0xce, 0xdd, 0x52, 0xcf, 0xf7, 0x36,
  33599. 0x2c, 0x4e, 0x6e, 0x23, 0xda, 0xec, 0x0f, 0xbc,
  33600. 0x3a, 0x79, 0xb6, 0x80, 0x6e, 0x31, 0x6e, 0xfc,
  33601. 0xc7, 0xb6, 0x81, 0x19, 0xbf, 0x46, 0xbc, 0x76,
  33602. 0xa2, 0x60, 0x67, 0xa5, 0x3f, 0x29, 0x6d, 0xaf,
  33603. 0xdb, 0xdc, 0x11, 0xc7, 0x7f, 0x77, 0x77, 0xe9,
  33604. 0x72, 0x66, 0x0c, 0xf4, 0xb6, 0xa9, 0xb3, 0x69,
  33605. 0xa6, 0x66, 0x5f, 0x02, 0xe0, 0xcc, 0x9b, 0x6e,
  33606. 0xdf, 0xad, 0x13, 0x6b, 0x4f, 0xab, 0xe7, 0x23,
  33607. 0xd2, 0x81, 0x3d, 0xb3, 0x13, 0x6c, 0xfd, 0xe9,
  33608. 0xb6, 0xd0, 0x44, 0x32, 0x2f, 0xee, 0x29, 0x47,
  33609. 0x95, 0x2e, 0x03, 0x1b, 0x73, 0xab, 0x5c, 0x60,
  33610. 0x33, 0x49, 0xb3, 0x07, 0xbd, 0xc2, 0x7b, 0xc6,
  33611. 0xcb, 0x8b, 0x8b, 0xbd, 0x7b, 0xd3, 0x23, 0x21,
  33612. 0x9b, 0x80, 0x33, 0xa5, 0x81, 0xb5, 0x9e, 0xad,
  33613. 0xeb, 0xb0, 0x9b, 0x3c, 0x4f, 0x3d, 0x22, 0x77,
  33614. 0xd4, 0xf0, 0x34, 0x36, 0x24, 0xac, 0xc8, 0x17,
  33615. 0x80, 0x47, 0x28, 0xb2, 0x5a, 0xb7, 0x97, 0x17,
  33616. 0x2b, 0x4c, 0x5c, 0x21, 0xa2, 0x2f, 0x9c, 0x78,
  33617. 0x39, 0xd6, 0x43, 0x00, 0x23, 0x2e, 0xb6, 0x6e,
  33618. 0x53, 0xf3, 0x1c, 0x72, 0x3f, 0xa3, 0x7f, 0xe3,
  33619. 0x87, 0xc7, 0xd3, 0xe5, 0x0b, 0xdf, 0x98, 0x13,
  33620. 0xa3, 0x0e, 0x5b, 0xb1, 0x2c, 0xf4, 0xcd, 0x93,
  33621. 0x0c, 0x40, 0xcf, 0xb4, 0xe1, 0xfc, 0x62, 0x25,
  33622. 0x92, 0xa4, 0x95, 0x88, 0x79, 0x44, 0x94, 0xd5,
  33623. 0x6d, 0x24, 0xea, 0x4b, 0x40, 0xc8, 0x9f, 0xc0,
  33624. 0x59, 0x6c, 0xc9, 0xeb, 0xb9, 0x61, 0xc8, 0xcb,
  33625. 0x10, 0xad, 0xde, 0x97, 0x6a, 0x5d, 0x60, 0x2b,
  33626. 0x1c, 0x3f, 0x85, 0xb9, 0xb9, 0xa0, 0x01, 0xed,
  33627. 0x3c, 0x6a, 0x4d, 0x3b, 0x14, 0x37, 0xf5, 0x20,
  33628. 0x96, 0xcd, 0x19, 0x56, 0xd0, 0x42, 0xa5, 0x97,
  33629. 0xd5, 0x61, 0xa5, 0x96, 0xec, 0xd3, 0xd1, 0x73,
  33630. 0x5a, 0x8d, 0x57, 0x0e, 0xa0, 0xec, 0x27, 0x22,
  33631. 0x5a, 0x2c, 0x4a, 0xaf, 0xf2, 0x63, 0x06, 0xd1,
  33632. 0x52, 0x6c, 0x1a, 0xf3, 0xca, 0x6d, 0x9c, 0xf5,
  33633. 0xa2, 0xc9, 0x8f, 0x47, 0xe1, 0xc4, 0x6d, 0xb9,
  33634. 0xa3, 0x32, 0x34, 0xcf, 0xd4, 0xd8, 0x1f, 0x2c,
  33635. 0x98, 0x53, 0x8a, 0x09, 0xeb, 0xe7, 0x69, 0x98,
  33636. 0xd0, 0xd8, 0xfd, 0x25, 0x99, 0x7c, 0x7d, 0x25,
  33637. 0x5c, 0x6d, 0x66, 0xec, 0xe6, 0xfa, 0x56, 0xf1,
  33638. 0x11, 0x44, 0x95, 0x0f, 0x02, 0x77, 0x95, 0xe6,
  33639. 0x53, 0x00, 0x8f, 0x4b, 0xd7, 0xca, 0x2d, 0xee,
  33640. 0x85, 0xd8, 0xe9, 0x0f, 0x3d, 0xc3, 0x15, 0x13,
  33641. 0x0c, 0xe2, 0xa0, 0x03, 0x75, 0xa3, 0x18, 0xc7,
  33642. 0xc3, 0xd9, 0x7b, 0xe2, 0xc8, 0xce, 0x5b, 0x6d,
  33643. 0xb4, 0x1a, 0x62, 0x54, 0xff, 0x26, 0x4f, 0xa6,
  33644. 0x15, 0x5b, 0xae, 0xe3, 0xb0, 0x77, 0x3c, 0x0f,
  33645. 0x49, 0x7c, 0x57, 0x3f, 0x19, 0xbb, 0x4f, 0x42,
  33646. 0x40, 0x28, 0x1f, 0x0b, 0x1f, 0x4f, 0x7b, 0xe8,
  33647. 0x57, 0xa4, 0xe5, 0x9d, 0x41, 0x6c, 0x06, 0xb4,
  33648. 0xc5, 0x0f, 0xa0, 0x9e, 0x18, 0x10, 0xdd, 0xc6,
  33649. 0xb1, 0x46, 0x7b, 0xae, 0xac, 0x5a, 0x36, 0x68,
  33650. 0xd1, 0x1b, 0x6e, 0xca, 0xa9, 0x01, 0x44, 0x00,
  33651. 0x16, 0xf3, 0x89, 0xf8, 0x0a, 0xcc, 0x4d, 0xb9,
  33652. 0x77, 0x02, 0x5e, 0x7f, 0x59, 0x24, 0x38, 0x8c,
  33653. 0x7e, 0x34, 0x0a, 0x73, 0x2e, 0x55, 0x44, 0x40,
  33654. 0xe7, 0x65, 0x70, 0xf8, 0xdd, 0x71, 0xb7, 0xd6,
  33655. 0x40, 0xb3, 0x45, 0x0d, 0x1f, 0xd5, 0xf0, 0x41,
  33656. 0x0a, 0x18, 0xf9, 0xa3, 0x49, 0x4f, 0x70, 0x7c,
  33657. 0x71, 0x7b, 0x79, 0xb4, 0xbf, 0x75, 0xc9, 0x84,
  33658. 0x00, 0xb0, 0x96, 0xb2, 0x16, 0x53, 0xb5, 0xd2,
  33659. 0x17, 0xcf, 0x35, 0x65, 0xc9, 0x59, 0x74, 0x56,
  33660. 0xf7, 0x07, 0x03, 0x49, 0x7a, 0x07, 0x87, 0x63,
  33661. 0x82, 0x9b, 0xc0, 0x1b, 0xb1, 0xcb, 0xc8, 0xfa,
  33662. 0x04, 0xea, 0xdc, 0x9a, 0x6e, 0x3f, 0x66, 0x99,
  33663. 0x58, 0x7a, 0x9e, 0x75, 0xc9, 0x4e, 0x5b, 0xab,
  33664. 0x00, 0x36, 0xe0, 0xb2, 0xe7, 0x11, 0x39, 0x2c,
  33665. 0xff, 0x00, 0x47, 0xd0, 0xd6, 0xb0, 0x5b, 0xd2,
  33666. 0xa5, 0x88, 0xbc, 0x10, 0x97, 0x18, 0x95, 0x42,
  33667. 0x59, 0xf1, 0xd8, 0x66, 0x78, 0xa5, 0x79, 0xa3,
  33668. 0x12, 0x0f, 0x19, 0xcf, 0xb2, 0x96, 0x3f, 0x17,
  33669. 0x7a, 0xeb, 0x70, 0xf2, 0xd4, 0x84, 0x48, 0x26,
  33670. 0x26, 0x2e, 0x51, 0xb8, 0x02, 0x71, 0x27, 0x20,
  33671. 0x68, 0xef, 0x5b, 0x38, 0x56, 0xfa, 0x85, 0x35,
  33672. 0xaa, 0x2a, 0x88, 0xb2, 0xd4, 0x1f, 0x2a, 0x0e,
  33673. 0x2f, 0xda, 0x76, 0x24, 0xc2, 0x85, 0x02, 0x72,
  33674. 0xac, 0x4a, 0x2f, 0x56, 0x1f, 0x8f, 0x2f, 0x7a,
  33675. 0x31, 0x8b, 0xfd, 0x5c, 0xaf, 0x96, 0x96, 0x14,
  33676. 0x9e, 0x4a, 0xc8, 0x24, 0xad, 0x34, 0x60, 0x53,
  33677. 0x8f, 0xdc, 0x25, 0x42, 0x1b, 0xee, 0xc2, 0xcc,
  33678. 0x68, 0x18, 0x16, 0x2d, 0x06, 0xbb, 0xed, 0x0c,
  33679. 0x40, 0xa3, 0x87, 0x19, 0x23, 0x49, 0xdb, 0x67,
  33680. 0xa1, 0x18, 0xba, 0xda, 0x6c, 0xd5, 0xab, 0x01,
  33681. 0x40, 0xee, 0x27, 0x32, 0x04, 0xf6, 0x28, 0xaa,
  33682. 0xd1, 0xc1, 0x35, 0xf7, 0x70, 0x27, 0x9a, 0x65,
  33683. 0x1e, 0x24, 0xd8, 0xc1, 0x4d, 0x75, 0xa6, 0x05,
  33684. 0x9d, 0x76, 0xb9, 0x6a, 0x6f, 0xd8, 0x57, 0xde,
  33685. 0xf5, 0xe0, 0xb3, 0x54, 0xb2, 0x7a, 0xb9, 0x37,
  33686. 0xa5, 0x81, 0x5d, 0x16, 0xb5, 0xfa, 0xe4, 0x07,
  33687. 0xff, 0x18, 0x22, 0x2c, 0x6d, 0x1e, 0xd2, 0x63,
  33688. 0xbe, 0x68, 0xc9, 0x5f, 0x32, 0xd9, 0x08, 0xbd,
  33689. 0x89, 0x5c, 0xd7, 0x62, 0x07, 0xae, 0x72, 0x64,
  33690. 0x87, 0x56, 0x7f, 0x9a, 0x67, 0xda, 0xd7, 0x9a,
  33691. 0xbe, 0xc3, 0x16, 0xf6, 0x83, 0xb1, 0x7f, 0x2d,
  33692. 0x02, 0xbf, 0x07, 0xe0, 0xac, 0x8b, 0x5b, 0xc6,
  33693. 0x16, 0x2c, 0xf9, 0x46, 0x97, 0xb3, 0xc2, 0x7c,
  33694. 0xd1, 0xfe, 0xa4, 0x9b, 0x27, 0xf2, 0x3b, 0xa2,
  33695. 0x90, 0x18, 0x71, 0x96, 0x25, 0x06, 0x52, 0x0c,
  33696. 0x39, 0x2d, 0xa8, 0xb6, 0xad, 0x0d, 0x99, 0xf7,
  33697. 0x01, 0x3f, 0xbc, 0x06, 0xc2, 0xc1, 0x7a, 0x56,
  33698. 0x95, 0x00, 0xc8, 0xa7, 0x69, 0x64, 0x81, 0xc1,
  33699. 0xcd, 0x33, 0xe9, 0xb1, 0x4e, 0x40, 0xb8, 0x2e,
  33700. 0x79, 0xa5, 0xf5, 0xdb, 0x82, 0x57, 0x1b, 0xa9,
  33701. 0x7b, 0xae, 0x3a, 0xd3, 0xe0, 0x47, 0x95, 0x15,
  33702. 0xbb, 0x0e, 0x2b, 0x0f, 0x3b, 0xfc, 0xd1, 0xfd,
  33703. 0x33, 0x03, 0x4e, 0xfc, 0x62, 0x45, 0xed, 0xdd,
  33704. 0x7e, 0xe2, 0x08, 0x6d, 0xda, 0xe2, 0x60, 0x0d,
  33705. 0x8c, 0xa7, 0x3e, 0x21, 0x4e, 0x8c, 0x2b, 0x0b,
  33706. 0xdb, 0x2b, 0x04, 0x7c, 0x6a, 0x46, 0x4a, 0x56,
  33707. 0x2e, 0xd7, 0x7b, 0x73, 0xd2, 0xd8, 0x41, 0xc4,
  33708. 0xb3, 0x49, 0x73, 0x55, 0x12, 0x57, 0x71, 0x3b,
  33709. 0x75, 0x36, 0x32, 0xef, 0xba, 0x34, 0x81, 0x69,
  33710. 0xab, 0xc9, 0x0a, 0x68, 0xf4, 0x26, 0x11, 0xa4,
  33711. 0x01, 0x26, 0xd7, 0xcb, 0x21, 0xb5, 0x86, 0x95,
  33712. 0x56, 0x81, 0x86, 0xf7, 0xe5, 0x69, 0xd2, 0xff,
  33713. 0x0f, 0x9e, 0x74, 0x5d, 0x04, 0x87, 0xdd, 0x2e,
  33714. 0xb9, 0x97, 0xca, 0xfc, 0x5a, 0xbf, 0x9d, 0xd1,
  33715. 0x02, 0xe6, 0x2f, 0xf6, 0x6c, 0xba, 0x87
  33716. };
  33717. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  33718. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  33719. sizeof(msg2),
  33720. sizeof(msg3),
  33721. 0 /*sizeof(msg1)*/,
  33722. 0 /*sizeof(msg1)*/,
  33723. sizeof(msg4)
  33724. };
  33725. #ifndef NO_ASN
  33726. static const byte privateEd448[] = {
  33727. 0x30, 0x47, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
  33728. 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04, 0x39,
  33729. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33730. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33731. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33732. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33733. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33734. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33735. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33736. 0x5b
  33737. };
  33738. static const byte publicEd448[] = {
  33739. 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
  33740. 0x71, 0x03, 0x3a, 0x00, 0x5f, 0xd7, 0x44, 0x9b,
  33741. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33742. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33743. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33744. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33745. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33746. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33747. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33748. };
  33749. static const byte privPubEd448[] = {
  33750. 0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
  33751. 0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
  33752. 0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
  33753. 0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
  33754. 0xbf, 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c,
  33755. 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48,
  33756. 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
  33757. 0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
  33758. 0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
  33759. 0xf9, 0x5b, 0x81, 0x39, 0x5f, 0xd7, 0x44, 0x9b,
  33760. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33761. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33762. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33763. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33764. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33765. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33766. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33767. };
  33768. word32 idx;
  33769. #endif /* NO_ASN */
  33770. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33771. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33772. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33773. ed448_key *key3 = NULL;
  33774. #else
  33775. ed448_key key3[1];
  33776. #endif
  33777. #endif
  33778. WOLFSSL_ENTER("ed448_test");
  33779. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33780. key = (ed448_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33781. key2 = (ed448_key *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33782. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33783. key3 = (ed448_key *)XMALLOC(sizeof(*key3), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33784. #endif
  33785. #endif
  33786. /* create ed448 keys */
  33787. #ifndef HAVE_FIPS
  33788. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  33789. #else
  33790. ret = wc_InitRng(&rng);
  33791. #endif
  33792. if (ret != 0) {
  33793. XMEMSET(&rng, 0, sizeof(rng));
  33794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33795. }
  33796. ret = wc_ed448_init(key);
  33797. if (ret < 0)
  33798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33799. ret = wc_ed448_init(key2);
  33800. if (ret < 0)
  33801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33802. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33803. ret = wc_ed448_init(key3);
  33804. if (ret < 0)
  33805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33806. #endif
  33807. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key);
  33808. if (ret < 0)
  33809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33810. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2);
  33811. if (ret < 0)
  33812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33813. /* helper functions for signature and key size */
  33814. keySz = (word32)wc_ed448_size(key);
  33815. sigSz = (word32)wc_ed448_sig_size(key);
  33816. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33817. defined(HAVE_ED448_KEY_IMPORT)
  33818. for (i = 0; i < 6; i++) {
  33819. outlen = sizeof(out);
  33820. XMEMSET(out, 0, sizeof(out));
  33821. if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i],
  33822. pKeySz[i], key) != 0)
  33823. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33824. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL,
  33825. 0) != 0)
  33826. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33827. if (XMEMCMP(out, sigs[i], 114))
  33828. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33829. #if defined(HAVE_ED448_VERIFY)
  33830. /* test verify on good msg */
  33831. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33832. NULL, 0) != 0 || verify != 1)
  33833. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33834. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33835. /* test verify on good msg using streaming interface directly */
  33836. if (wc_ed448_verify_msg_init(out, outlen,
  33837. key, (byte)Ed448, NULL, 0) != 0)
  33838. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33839. for (j = 0; j < msgSz[i]; j += i) {
  33840. if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  33841. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33842. }
  33843. if (wc_ed448_verify_msg_final(out, outlen, &verify,
  33844. key) != 0 || verify != 1)
  33845. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33846. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33847. /* test verify on bad msg */
  33848. out[outlen-2] = out[outlen-2] + 1;
  33849. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33850. NULL, 0) == 0 || verify == 1)
  33851. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33852. #endif /* HAVE_ED448_VERIFY */
  33853. /* test api for import/exporting keys */
  33854. {
  33855. word32 exportPSz = ED448_KEY_SIZE;
  33856. word32 exportSSz = ED448_KEY_SIZE;
  33857. #ifdef WOLFSSL_NO_MALLOC
  33858. byte exportPKey[exportPSz];
  33859. byte exportSKey[exportSSz];
  33860. #else
  33861. byte *exportPKey = NULL;
  33862. byte *exportSKey = NULL;
  33863. exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33864. exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33865. if ((exportPKey == NULL) || (exportSKey == NULL))
  33866. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33867. #endif
  33868. ret = 0;
  33869. do {
  33870. if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) {
  33871. ret = WC_TEST_RET_ENC_I(i);
  33872. break;
  33873. }
  33874. if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) {
  33875. ret = WC_TEST_RET_ENC_I(i);
  33876. break;
  33877. }
  33878. if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) {
  33879. ret = WC_TEST_RET_ENC_I(i);
  33880. break;
  33881. }
  33882. if (wc_ed448_import_private_key(exportSKey, exportSSz,
  33883. exportPKey, exportPSz, key2) != 0) {
  33884. ret = WC_TEST_RET_ENC_I(i);
  33885. break;
  33886. }
  33887. /* clear "out" buffer and test sign with imported keys */
  33888. outlen = sizeof(out);
  33889. XMEMSET(out, 0, sizeof(out));
  33890. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL,
  33891. 0) != 0) {
  33892. ret = WC_TEST_RET_ENC_I(i);
  33893. break;
  33894. }
  33895. } while(0);
  33896. #ifndef WOLFSSL_NO_MALLOC
  33897. XFREE(exportPKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33898. XFREE(exportSKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33899. #endif
  33900. if (ret != 0)
  33901. goto out;
  33902. }
  33903. #if defined(HAVE_ED448_VERIFY)
  33904. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2,
  33905. NULL, 0) != 0 || verify != 1)
  33906. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33907. if (XMEMCMP(out, sigs[i], SIGSZ))
  33908. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33909. #endif /* HAVE_ED448_VERIFY */
  33910. }
  33911. ret = ed448_ctx_test();
  33912. if (ret != 0)
  33913. goto out;
  33914. ret = ed448ph_test();
  33915. if (ret != 0)
  33916. goto out;
  33917. #ifndef NO_ASN
  33918. /* Try ASN.1 encoded private-only key and public key. */
  33919. idx = 0;
  33920. ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3,
  33921. sizeof(privateEd448));
  33922. if (ret != 0)
  33923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33924. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33925. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  33926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33927. idx = 0;
  33928. ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448));
  33929. if (ret != 0)
  33930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33931. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33932. if (ret != 0)
  33933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33934. if (XMEMCMP(out, sigs[0], SIGSZ))
  33935. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33936. #if defined(HAVE_ED448_VERIFY)
  33937. /* test verify on good msg */
  33938. ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3,
  33939. NULL, 0);
  33940. if (ret != 0 || verify != 1)
  33941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33942. #endif /* HAVE_ED448_VERIFY */
  33943. wc_ed448_free(key3);
  33944. ret = wc_ed448_init(key3);
  33945. if (ret < 0)
  33946. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33947. idx = 0;
  33948. ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3,
  33949. sizeof(privPubEd448));
  33950. if (ret != 0)
  33951. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33952. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33953. if (ret != 0)
  33954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33955. if (XMEMCMP(out, sigs[0], SIGSZ))
  33956. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33957. #endif /* NO_ASN */
  33958. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33959. ret = 0;
  33960. out:
  33961. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33962. if (key) {
  33963. wc_ed448_free(key);
  33964. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33965. }
  33966. if (key2) {
  33967. wc_ed448_free(key2);
  33968. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33969. }
  33970. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33971. if (key3) {
  33972. wc_ed448_free(key3);
  33973. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33974. }
  33975. #endif
  33976. #else
  33977. wc_ed448_free(key);
  33978. wc_ed448_free(key2);
  33979. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33980. wc_ed448_free(key3);
  33981. #endif
  33982. #endif
  33983. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  33984. wc_FreeRng(&rng);
  33985. #endif
  33986. if (ret < 0)
  33987. return ret;
  33988. /* hush warnings of unused keySz and sigSz */
  33989. (void)keySz;
  33990. (void)sigSz;
  33991. ret = ed448_test_check_key();
  33992. if (ret < 0)
  33993. return ret;
  33994. #ifdef WOLFSSL_TEST_CERT
  33995. ret = ed448_test_cert();
  33996. if (ret < 0)
  33997. return ret;
  33998. #ifdef WOLFSSL_CERT_GEN
  33999. ret = ed448_test_make_cert();
  34000. if (ret < 0)
  34001. return ret;
  34002. #endif /* WOLFSSL_CERT_GEN */
  34003. #endif /* WOLFSSL_TEST_CERT */
  34004. return 0;
  34005. }
  34006. #endif /* HAVE_ED448 */
  34007. #ifdef WOLFSSL_HAVE_KYBER
  34008. #ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
  34009. #ifdef WOLFSSL_KYBER512
  34010. static wc_test_ret_t kyber512_kat(void)
  34011. {
  34012. wc_test_ret_t ret;
  34013. #ifdef WOLFSSL_SMALL_STACK
  34014. KyberKey *key = NULL;
  34015. byte *priv = NULL;
  34016. byte *pub = NULL;
  34017. byte *ct = NULL;
  34018. byte *ss = NULL;
  34019. byte *ss_dec = NULL;
  34020. #else
  34021. KyberKey key[1];
  34022. byte priv[KYBER512_PRIVATE_KEY_SIZE];
  34023. byte pub[KYBER512_PUBLIC_KEY_SIZE];
  34024. byte ct[KYBER512_CIPHER_TEXT_SIZE];
  34025. byte ss[KYBER_SS_SZ];
  34026. byte ss_dec[KYBER_SS_SZ];
  34027. #endif
  34028. int key_inited = 0;
  34029. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_rand[] = {
  34030. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34031. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34032. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34033. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34034. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34035. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34036. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34037. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34038. };
  34039. WOLFSSL_SMALL_STACK_STATIC const byte kyber512enc_rand[] = {
  34040. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34041. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34042. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34043. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34044. };
  34045. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_pk[] = {
  34046. #ifdef WOLFSSL_KYBER_ORIGINAL
  34047. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34048. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34049. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34050. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34051. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34052. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34053. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34054. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34055. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34056. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34057. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34058. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34059. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34060. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34061. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34062. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34063. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34064. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34065. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34066. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34067. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34068. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34069. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34070. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34071. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34072. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34073. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34074. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34075. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34076. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34077. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34078. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34079. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34080. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34081. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34082. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34083. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34084. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34085. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34086. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34087. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34088. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34089. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34090. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34091. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34092. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34093. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34094. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34095. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34096. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34097. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34098. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34099. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34100. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34101. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34102. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34103. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34104. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34105. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34106. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34107. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34108. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34109. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34110. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34111. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34112. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34113. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34114. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34115. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34116. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34117. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34118. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34119. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34120. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34121. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34122. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34123. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34124. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34125. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34126. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34127. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34128. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34129. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34130. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34131. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34132. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34133. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34134. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34135. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34136. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34137. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34138. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34139. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34140. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34141. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34142. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34143. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34144. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34145. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34146. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  34147. #else
  34148. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34149. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34150. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34151. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34152. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34153. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34154. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34155. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34156. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34157. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34158. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34159. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34160. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34161. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34162. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34163. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34164. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34165. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34166. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34167. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34168. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34169. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34170. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34171. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34172. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34173. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34174. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34175. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34176. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34177. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34178. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34179. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34180. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34181. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34182. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34183. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34184. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34185. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34186. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34187. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34188. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34189. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34190. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34191. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34192. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34193. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34194. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34195. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34196. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34197. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34198. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34199. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34200. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34201. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34202. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34203. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34204. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34205. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34206. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34207. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34208. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34209. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34210. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34211. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34212. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34213. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34214. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34215. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34216. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34217. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34218. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34219. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34220. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34221. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34222. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34223. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34224. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34225. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34226. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34227. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34228. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34229. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34230. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34231. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34232. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34233. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34234. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34235. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34236. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34237. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34238. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34239. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34240. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34241. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34242. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34243. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34244. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34245. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34246. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34247. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39
  34248. #endif
  34249. };
  34250. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_sk[] = {
  34251. #ifdef WOLFSSL_KYBER_ORIGINAL
  34252. 0x6C, 0x89, 0x2B, 0x02, 0x97, 0xA9, 0xC7, 0x64,
  34253. 0x14, 0x93, 0xF8, 0x7D, 0xAF, 0x35, 0x33, 0xEE,
  34254. 0xD6, 0x1F, 0x07, 0xF4, 0x65, 0x20, 0x66, 0x33,
  34255. 0x7E, 0xD7, 0x40, 0x46, 0xDC, 0xC7, 0x1B, 0xA0,
  34256. 0x3F, 0x30, 0x96, 0x01, 0x03, 0x16, 0x1F, 0x7D,
  34257. 0xEB, 0x53, 0xA7, 0x1B, 0x11, 0x61, 0x72, 0x63,
  34258. 0xFE, 0x2A, 0x80, 0x97, 0x69, 0xCE, 0x6D, 0x70,
  34259. 0xA8, 0x5F, 0xE6, 0x00, 0xEC, 0xE2, 0x9D, 0x7F,
  34260. 0x36, 0xA1, 0x6D, 0x33, 0x1B, 0x8B, 0x2A, 0x9E,
  34261. 0x1D, 0xB8, 0xC0, 0x90, 0x74, 0x2D, 0xF0, 0x73,
  34262. 0x9F, 0xF0, 0x60, 0xCE, 0xB4, 0xEC, 0xC5, 0xAB,
  34263. 0x1C, 0x5E, 0x55, 0xAC, 0x97, 0xBB, 0x66, 0xA7,
  34264. 0xF8, 0x95, 0x10, 0x5D, 0x57, 0x78, 0x2B, 0x22,
  34265. 0x95, 0x38, 0xE3, 0x42, 0x15, 0x44, 0xA3, 0x42,
  34266. 0x14, 0x08, 0xDB, 0xF4, 0x49, 0x10, 0x93, 0x4C,
  34267. 0xC4, 0x23, 0x77, 0x4F, 0x16, 0x76, 0xFF, 0x1C,
  34268. 0x30, 0x6F, 0x97, 0x55, 0x5F, 0x57, 0xB4, 0xAE,
  34269. 0xD7, 0xA6, 0xBA, 0xB9, 0x50, 0xA8, 0x16, 0x3C,
  34270. 0x8D, 0x31, 0x8D, 0xEA, 0x62, 0x75, 0x1B, 0xD6,
  34271. 0xAB, 0xC5, 0x06, 0x9C, 0x06, 0xC8, 0x8F, 0x33,
  34272. 0x00, 0x26, 0xA1, 0x98, 0x06, 0xA0, 0x3B, 0x97,
  34273. 0xA7, 0x69, 0x6B, 0x56, 0xDA, 0x21, 0x82, 0x7B,
  34274. 0xB4, 0xE8, 0xDC, 0x03, 0x11, 0x52, 0xB4, 0x1B,
  34275. 0x89, 0x2A, 0x9E, 0x99, 0xAD, 0xF6, 0xE1, 0x96,
  34276. 0x3E, 0x96, 0x57, 0x88, 0x28, 0x15, 0x4F, 0x46,
  34277. 0x70, 0x33, 0x84, 0x69, 0x20, 0xFB, 0xB4, 0xB8,
  34278. 0x05, 0x44, 0xE7, 0xE8, 0xA8, 0x1A, 0xE9, 0x63,
  34279. 0xCF, 0x36, 0x8C, 0x9B, 0xA0, 0x37, 0xA8, 0xC2,
  34280. 0xAD, 0x62, 0xE3, 0x2B, 0x6E, 0x61, 0xC9, 0x1D,
  34281. 0x75, 0xCE, 0x00, 0x5A, 0xB3, 0x0F, 0x80, 0x99,
  34282. 0xA1, 0xF2, 0x9D, 0x7B, 0x63, 0x05, 0xB4, 0xDC,
  34283. 0x06, 0xE2, 0x56, 0x80, 0xBB, 0x00, 0x99, 0x2F,
  34284. 0x71, 0x7F, 0xE6, 0xC1, 0x15, 0xA8, 0x08, 0x42,
  34285. 0x31, 0xCC, 0x79, 0xDD, 0x70, 0x0E, 0xA6, 0x91,
  34286. 0x2A, 0xC7, 0xFA, 0x0D, 0x93, 0x7B, 0xB6, 0xA7,
  34287. 0x56, 0x66, 0x22, 0x30, 0x47, 0x0C, 0x18, 0x9B,
  34288. 0x5A, 0xA1, 0x65, 0x3D, 0xEB, 0x93, 0x7D, 0x5A,
  34289. 0x9C, 0x25, 0xA2, 0x1D, 0x93, 0xB1, 0x90, 0x74,
  34290. 0xFC, 0x23, 0x9D, 0x81, 0x53, 0x53, 0x97, 0x97,
  34291. 0xC7, 0xD4, 0xAB, 0x62, 0x64, 0x9D, 0x76, 0xAA,
  34292. 0x55, 0x37, 0x36, 0xA9, 0x49, 0x02, 0x2C, 0x22,
  34293. 0xC5, 0x2B, 0xAE, 0xEC, 0x60, 0x5B, 0x32, 0xCE,
  34294. 0x9E, 0x5B, 0x93, 0x84, 0x90, 0x35, 0x58, 0xCA,
  34295. 0x9D, 0x6A, 0x3A, 0xBA, 0x90, 0x42, 0x3E, 0xED,
  34296. 0xA0, 0x1C, 0x94, 0x19, 0x8B, 0x19, 0x2A, 0x8B,
  34297. 0xA9, 0x06, 0x34, 0x97, 0xA0, 0xC5, 0x01, 0x33,
  34298. 0x07, 0xDD, 0xD8, 0x63, 0x52, 0x64, 0x71, 0xA4,
  34299. 0xD9, 0x95, 0x23, 0xEB, 0x41, 0x7F, 0x29, 0x1A,
  34300. 0xAC, 0x0C, 0x3A, 0x58, 0x1B, 0x6D, 0xA0, 0x07,
  34301. 0x32, 0xE5, 0xE8, 0x1B, 0x1F, 0x7C, 0x87, 0x9B,
  34302. 0x16, 0x93, 0xC1, 0x3B, 0x6F, 0x9F, 0x79, 0x31,
  34303. 0x62, 0x24, 0x29, 0xE5, 0x42, 0xAF, 0x40, 0x69,
  34304. 0x22, 0x2F, 0x04, 0x55, 0x44, 0xE0, 0xCC, 0x4F,
  34305. 0xB2, 0x4D, 0x44, 0x48, 0xCF, 0x2C, 0x65, 0x96,
  34306. 0xF5, 0xCB, 0x08, 0x62, 0x4B, 0x11, 0x85, 0x01,
  34307. 0x3B, 0x6B, 0x02, 0x08, 0x92, 0xF9, 0x6B, 0xDF,
  34308. 0xD4, 0xAD, 0xA9, 0x17, 0x9D, 0xE7, 0x27, 0xB8,
  34309. 0xD9, 0x42, 0x6E, 0x09, 0x96, 0xB5, 0xD3, 0x49,
  34310. 0x48, 0xCE, 0x02, 0xD0, 0xC3, 0x69, 0xB3, 0x7C,
  34311. 0xBB, 0x54, 0xD3, 0x47, 0x9E, 0xD8, 0xB5, 0x82,
  34312. 0xE9, 0xE7, 0x28, 0x92, 0x9B, 0x4C, 0x71, 0xC9,
  34313. 0xBE, 0x11, 0xD4, 0x5B, 0x20, 0xC4, 0xBD, 0xC3,
  34314. 0xC7, 0x43, 0x13, 0x22, 0x3F, 0x58, 0x27, 0x4E,
  34315. 0x8B, 0xA5, 0x24, 0x44, 0x47, 0xC4, 0x95, 0x95,
  34316. 0x0B, 0x84, 0xCB, 0x0C, 0x3C, 0x27, 0x36, 0x40,
  34317. 0x10, 0x8A, 0x33, 0x97, 0x94, 0x45, 0x73, 0x27,
  34318. 0x93, 0x28, 0x99, 0x6C, 0xDC, 0x0C, 0x91, 0x3C,
  34319. 0x95, 0x8A, 0xD6, 0x20, 0xBA, 0x8B, 0x5E, 0x5E,
  34320. 0xCB, 0xBB, 0x7E, 0x13, 0xCB, 0x9C, 0x70, 0xBD,
  34321. 0x5A, 0xB3, 0x0E, 0xB7, 0x48, 0x8C, 0x97, 0x00,
  34322. 0x1C, 0x20, 0x49, 0x8F, 0x1D, 0x7C, 0xC0, 0x6D,
  34323. 0xA7, 0x6B, 0xF5, 0x20, 0xC6, 0x58, 0xCC, 0xAD,
  34324. 0xFA, 0x29, 0x56, 0x42, 0x45, 0x57, 0xAB, 0xEA,
  34325. 0x8A, 0xB8, 0x92, 0x39, 0xC1, 0x78, 0x33, 0xDC,
  34326. 0x3A, 0x49, 0xB3, 0x6A, 0x9A, 0xE9, 0xA4, 0x86,
  34327. 0x94, 0x05, 0x40, 0xEB, 0x44, 0x4F, 0x97, 0x15,
  34328. 0x23, 0x57, 0xE0, 0x20, 0x35, 0x93, 0x9D, 0x75,
  34329. 0xA3, 0xC0, 0x25, 0xF4, 0x1A, 0x40, 0x08, 0x23,
  34330. 0x82, 0xA0, 0x73, 0x3C, 0x39, 0xB0, 0x62, 0x2B,
  34331. 0x74, 0x0E, 0x40, 0x75, 0x92, 0xC6, 0x2E, 0xCA,
  34332. 0xEB, 0x14, 0x32, 0xC4, 0x45, 0xB3, 0x70, 0x3A,
  34333. 0x86, 0xF6, 0x98, 0x1A, 0x27, 0x81, 0x57, 0xEA,
  34334. 0x95, 0xA6, 0xE9, 0x2D, 0x55, 0xE4, 0xB9, 0x72,
  34335. 0xF9, 0x36, 0xC2, 0xF0, 0xA6, 0x58, 0x28, 0x0E,
  34336. 0xA2, 0xB0, 0x7A, 0x48, 0x99, 0x2D, 0xF8, 0x93,
  34337. 0x7E, 0x0A, 0x2A, 0xC1, 0xDC, 0xC9, 0x74, 0xFE,
  34338. 0x00, 0xAA, 0xE1, 0xF5, 0x61, 0xFA, 0x25, 0x8E,
  34339. 0x2D, 0x25, 0x9C, 0x3E, 0x86, 0x1D, 0xCE, 0x23,
  34340. 0x60, 0x39, 0x12, 0x76, 0x06, 0xFC, 0x1C, 0xE0,
  34341. 0x09, 0x00, 0x3A, 0x7B, 0xAC, 0x94, 0x21, 0x01,
  34342. 0xDC, 0xB8, 0x22, 0xB1, 0xF3, 0xC1, 0x2B, 0xF7,
  34343. 0x32, 0x38, 0xF5, 0x46, 0xE0, 0x1C, 0x36, 0xB5,
  34344. 0xA6, 0x93, 0x61, 0x92, 0x99, 0x5C, 0xC6, 0x9C,
  34345. 0x63, 0x23, 0x74, 0x09, 0xCB, 0x53, 0xC2, 0xE3,
  34346. 0x5D, 0x74, 0x89, 0x0D, 0x18, 0x88, 0x53, 0x76,
  34347. 0xFA, 0x55, 0x03, 0xB1, 0x07, 0xA2, 0xA3, 0x92,
  34348. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34349. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34350. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34351. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34352. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34353. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34354. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34355. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34356. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34357. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34358. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34359. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34360. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34361. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34362. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34363. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34364. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34365. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34366. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34367. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34368. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34369. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34370. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34371. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34372. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34373. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34374. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34375. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34376. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34377. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34378. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34379. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34380. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34381. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34382. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34383. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34384. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34385. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34386. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34387. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34388. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34389. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34390. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34391. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34392. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34393. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34394. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34395. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34396. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34397. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34398. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34399. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34400. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34401. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34402. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34403. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34404. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34405. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34406. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34407. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34408. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34409. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34410. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34411. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34412. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34413. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34414. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34415. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34416. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34417. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34418. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34419. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34420. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34421. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34422. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34423. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34424. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34425. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34426. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34427. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34428. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34429. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34430. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34431. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34432. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34433. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34434. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34435. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34436. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34437. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34438. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34439. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34440. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34441. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34442. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34443. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34444. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34445. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34446. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34447. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  34448. 0x7F, 0xFA, 0xD1, 0xBC, 0x8A, 0xF7, 0x3B, 0x7E,
  34449. 0x87, 0x49, 0x56, 0xB8, 0x1C, 0x2A, 0x2E, 0xF0,
  34450. 0xBF, 0xAB, 0xE8, 0xDC, 0x93, 0xD7, 0x7B, 0x2F,
  34451. 0xBC, 0x9E, 0x0C, 0x64, 0xEF, 0xA0, 0x1E, 0x84,
  34452. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34453. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34454. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34455. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34456. #else
  34457. 0x9c, 0xda, 0x16, 0x86, 0xa3, 0x39, 0x6a, 0x7c,
  34458. 0x10, 0x9b, 0x41, 0x52, 0x89, 0xf5, 0x6a, 0x9e,
  34459. 0xc4, 0x4c, 0xd5, 0xb9, 0xb6, 0x74, 0xc3, 0x8a,
  34460. 0x3b, 0xba, 0xb3, 0x0a, 0x2c, 0x90, 0xf0, 0x04,
  34461. 0x37, 0xa2, 0x64, 0xb0, 0xbe, 0x9a, 0x1e, 0x8b,
  34462. 0xa8, 0x87, 0xd3, 0xc3, 0xb1, 0x00, 0x89, 0x80,
  34463. 0x54, 0x27, 0x2f, 0x94, 0x1c, 0x88, 0xa1, 0xf2,
  34464. 0x08, 0xf1, 0xc9, 0x14, 0xf9, 0x64, 0xc1, 0xaa,
  34465. 0xd6, 0x13, 0xa6, 0xa8, 0x4f, 0x88, 0xe4, 0x2d,
  34466. 0x35, 0x56, 0x83, 0x5f, 0xb1, 0x61, 0xfd, 0xc5,
  34467. 0xcd, 0x15, 0xa3, 0xbc, 0x7e, 0x74, 0xb6, 0xf2,
  34468. 0x61, 0x2f, 0xa8, 0x27, 0x1c, 0x7e, 0xa1, 0x12,
  34469. 0xb0, 0x5c, 0x2a, 0x36, 0xcc, 0x70, 0x7c, 0xe3,
  34470. 0x8d, 0x5d, 0x1a, 0xcc, 0x51, 0x15, 0x46, 0x2a,
  34471. 0x8c, 0x1a, 0xab, 0xf0, 0x72, 0x76, 0xc7, 0x23,
  34472. 0x18, 0x33, 0x7f, 0x74, 0xb5, 0xcb, 0xef, 0xea,
  34473. 0x7a, 0x80, 0x37, 0x90, 0xbc, 0x03, 0x93, 0xf3,
  34474. 0xa5, 0x4c, 0x72, 0x4a, 0x57, 0x65, 0xa4, 0x8f,
  34475. 0x29, 0x6b, 0x03, 0xf4, 0x84, 0x37, 0x60, 0x23,
  34476. 0x62, 0x69, 0x30, 0x22, 0x27, 0x04, 0xc0, 0x8f,
  34477. 0xd3, 0xbc, 0x72, 0x93, 0x15, 0xd1, 0xfc, 0x70,
  34478. 0xeb, 0x79, 0x75, 0xa9, 0x7b, 0x9d, 0xee, 0xd1,
  34479. 0x62, 0xf4, 0x86, 0xbb, 0xc6, 0x4a, 0x09, 0x71,
  34480. 0x11, 0x95, 0x2d, 0x89, 0xb5, 0x7d, 0x76, 0x5e,
  34481. 0x8a, 0x99, 0x1a, 0x2e, 0x56, 0x42, 0x06, 0xea,
  34482. 0x7b, 0xf5, 0xe4, 0x00, 0x7a, 0x66, 0x35, 0x88,
  34483. 0x31, 0xca, 0x0e, 0x34, 0xb2, 0xf6, 0xa8, 0x4d,
  34484. 0x10, 0xf7, 0x9c, 0x47, 0x7c, 0xb6, 0x6a, 0x8a,
  34485. 0x95, 0x25, 0x69, 0x36, 0x73, 0x88, 0x13, 0x0d,
  34486. 0x7b, 0x97, 0x4a, 0x63, 0xaa, 0x51, 0x99, 0x6c,
  34487. 0x97, 0x70, 0x9b, 0xb8, 0xea, 0xbc, 0x94, 0xe6,
  34488. 0xa5, 0x35, 0xd7, 0x92, 0xd2, 0x90, 0x54, 0x74,
  34489. 0x95, 0x2d, 0x6b, 0x8c, 0x22, 0x22, 0xb2, 0xae,
  34490. 0x56, 0xdc, 0x66, 0xfb, 0x04, 0x61, 0x19, 0x20,
  34491. 0x66, 0xcd, 0xdb, 0x43, 0xec, 0x05, 0x98, 0x4f,
  34492. 0xb4, 0x98, 0x26, 0x49, 0x77, 0x13, 0x97, 0xc6,
  34493. 0xa8, 0x37, 0x9f, 0x3b, 0x56, 0x43, 0x06, 0x98,
  34494. 0x48, 0x87, 0x59, 0x19, 0xe8, 0x9c, 0xc4, 0x39,
  34495. 0xa3, 0xbe, 0x2f, 0x08, 0x14, 0x90, 0xf3, 0x41,
  34496. 0xbd, 0x12, 0x40, 0xad, 0xd8, 0x0d, 0xdb, 0x8c,
  34497. 0x99, 0x63, 0xb4, 0x7a, 0x2a, 0x09, 0x92, 0x29,
  34498. 0x03, 0x38, 0xda, 0x9c, 0x3b, 0x72, 0x5c, 0x6d,
  34499. 0xa4, 0x47, 0x18, 0xc0, 0x10, 0x46, 0x81, 0x25,
  34500. 0x62, 0xaf, 0xb0, 0x84, 0x83, 0x7a, 0xcb, 0x3c,
  34501. 0x57, 0x5e, 0x4f, 0x93, 0x93, 0x6c, 0x35, 0x2a,
  34502. 0xc0, 0xe7, 0x0a, 0xa3, 0x84, 0x5e, 0xe4, 0x85,
  34503. 0x29, 0x6e, 0x6b, 0x02, 0xde, 0x0b, 0x47, 0xb5,
  34504. 0xc4, 0xc9, 0x6b, 0x0b, 0x7c, 0xf9, 0x4c, 0x4a,
  34505. 0xbe, 0x95, 0x48, 0x61, 0x53, 0x11, 0x8e, 0x43,
  34506. 0xc2, 0xb9, 0xc8, 0x4d, 0x9d, 0xa9, 0x1c, 0x6c,
  34507. 0x5a, 0xcd, 0x5a, 0x57, 0x00, 0x2d, 0x05, 0x84,
  34508. 0x97, 0x99, 0x27, 0x99, 0xe5, 0xba, 0x1c, 0xe6,
  34509. 0xc2, 0x5e, 0xb2, 0x98, 0x44, 0xd8, 0x58, 0xba,
  34510. 0x1c, 0x37, 0x85, 0x0c, 0x0c, 0x2f, 0x57, 0xc6,
  34511. 0x0d, 0xe3, 0x7f, 0x77, 0xc0, 0x82, 0xec, 0x14,
  34512. 0x49, 0x4e, 0xba, 0x28, 0x8a, 0x65, 0x91, 0x51,
  34513. 0x16, 0xc2, 0x0a, 0x32, 0x5d, 0xe3, 0x1a, 0xaa,
  34514. 0xdd, 0x68, 0x0d, 0xb1, 0x9c, 0x0c, 0xfc, 0xc3,
  34515. 0x46, 0x0f, 0x0a, 0xa0, 0x1a, 0x87, 0xa6, 0xa5,
  34516. 0x80, 0xc6, 0xca, 0x29, 0x1f, 0xae, 0xf0, 0xcc,
  34517. 0xc4, 0x9b, 0x76, 0xa8, 0xda, 0xc4, 0xf9, 0xd4,
  34518. 0x16, 0x40, 0x50, 0x9d, 0xbd, 0x0b, 0x40, 0x45,
  34519. 0xc1, 0x53, 0x0e, 0xd3, 0x47, 0x55, 0xd4, 0x74,
  34520. 0x62, 0x70, 0x0f, 0x2a, 0x8c, 0xaf, 0x96, 0x80,
  34521. 0xa6, 0xd7, 0xe3, 0x8a, 0x7e, 0x2a, 0x63, 0xe9,
  34522. 0x37, 0x65, 0x0a, 0x23, 0x30, 0x6d, 0x85, 0x5d,
  34523. 0xa2, 0xa2, 0xb7, 0xef, 0x50, 0x5c, 0xa5, 0x96,
  34524. 0xab, 0x04, 0x85, 0x01, 0x3e, 0xa9, 0x27, 0xc7,
  34525. 0x34, 0x23, 0x43, 0x61, 0x36, 0x43, 0xba, 0x40,
  34526. 0x07, 0xd6, 0xc8, 0x74, 0xb9, 0x80, 0xc7, 0x9c,
  34527. 0x3a, 0xa1, 0xc7, 0x4f, 0x85, 0x81, 0xc3, 0x48,
  34528. 0x49, 0xb3, 0x6e, 0xa7, 0x98, 0x15, 0xfb, 0xb4,
  34529. 0xcc, 0xf9, 0x61, 0x05, 0x83, 0x08, 0x1d, 0x7c,
  34530. 0x5b, 0x44, 0x09, 0xb8, 0xd0, 0x53, 0x1c, 0x04,
  34531. 0xbc, 0xaf, 0x7c, 0xc7, 0x51, 0x10, 0x3a, 0x5f,
  34532. 0xd1, 0xba, 0x44, 0x70, 0x83, 0x3e, 0x89, 0x77,
  34533. 0x5a, 0xde, 0xd9, 0x70, 0xb5, 0x47, 0x18, 0x59,
  34534. 0x25, 0x0f, 0xe7, 0x26, 0x71, 0x05, 0x83, 0x5f,
  34535. 0x39, 0x00, 0x30, 0xc5, 0xe7, 0xcd, 0x3f, 0x96,
  34536. 0x10, 0x19, 0xea, 0xae, 0xa2, 0x37, 0x77, 0xd3,
  34537. 0x47, 0xbb, 0x2a, 0xdc, 0xb6, 0x73, 0xc0, 0x20,
  34538. 0x34, 0xf3, 0x94, 0x34, 0x22, 0x71, 0xbc, 0xea,
  34539. 0x64, 0x14, 0xe5, 0x46, 0xc3, 0xb2, 0x0b, 0xd5,
  34540. 0x74, 0x81, 0xc7, 0xea, 0x14, 0xc7, 0x7c, 0x38,
  34541. 0x8c, 0xc8, 0x62, 0x51, 0xc1, 0x25, 0x58, 0xb1,
  34542. 0x00, 0xf8, 0xc5, 0xb3, 0xd0, 0x3c, 0xa2, 0xc7,
  34543. 0x07, 0x13, 0x90, 0x96, 0x59, 0xc8, 0xba, 0x26,
  34544. 0xd0, 0xd1, 0x76, 0x5e, 0x0b, 0xc8, 0x23, 0xd6,
  34545. 0x8c, 0xa5, 0x57, 0x0d, 0xe6, 0x00, 0xcd, 0x09,
  34546. 0x41, 0x72, 0x5d, 0x38, 0x6e, 0x14, 0xc1, 0x01,
  34547. 0x2d, 0xf5, 0x95, 0x1b, 0xeb, 0x8d, 0x82, 0x81,
  34548. 0xa4, 0xf6, 0x81, 0x5d, 0x37, 0x60, 0xb7, 0x64,
  34549. 0x29, 0x5a, 0xd0, 0x40, 0x6c, 0x2b, 0xf7, 0x92,
  34550. 0x8a, 0xd6, 0x50, 0x32, 0xb6, 0x5f, 0x14, 0xb7,
  34551. 0x7c, 0xcb, 0x89, 0x17, 0xc9, 0x3a, 0x29, 0xd6,
  34552. 0x28, 0x7d, 0x8a, 0x60, 0x62, 0x39, 0x9c, 0xb6,
  34553. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34554. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34555. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34556. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34557. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34558. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34559. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34560. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34561. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34562. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34563. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34564. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34565. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34566. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34567. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34568. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34569. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34570. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34571. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34572. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34573. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34574. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34575. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34576. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34577. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34578. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34579. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34580. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34581. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34582. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34583. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34584. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34585. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34586. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34587. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34588. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34589. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34590. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34591. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34592. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34593. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34594. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34595. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34596. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34597. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34598. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34599. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34600. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34601. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34602. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34603. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34604. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34605. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34606. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34607. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34608. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34609. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34610. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34611. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34612. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34613. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34614. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34615. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34616. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34617. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34618. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34619. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34620. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34621. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34622. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34623. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34624. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34625. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34626. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34627. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34628. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34629. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34630. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34631. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34632. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34633. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34634. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34635. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34636. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34637. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34638. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34639. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34640. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34641. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34642. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34643. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34644. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34645. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34646. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34647. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34648. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34649. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34650. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34651. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34652. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39,
  34653. 0x50, 0xc8, 0xdd, 0x15, 0x2a, 0x45, 0x31, 0xaa,
  34654. 0xb5, 0x60, 0xd2, 0xfc, 0x7c, 0xa9, 0xa4, 0x0a,
  34655. 0xd8, 0xaf, 0x25, 0xad, 0x1d, 0xd0, 0x8c, 0x6d,
  34656. 0x79, 0xaf, 0xe4, 0xdd, 0x4d, 0x1e, 0xee, 0x5a,
  34657. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  34658. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  34659. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  34660. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  34661. #endif
  34662. };
  34663. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ct[] = {
  34664. #ifdef WOLFSSL_KYBER_ORIGINAL
  34665. 0xED, 0xF2, 0x41, 0x45, 0xE4, 0x3B, 0x4F, 0x6D,
  34666. 0xC6, 0xBF, 0x83, 0x32, 0xF5, 0x4E, 0x02, 0xCA,
  34667. 0xB0, 0x2D, 0xBF, 0x3B, 0x56, 0x05, 0xDD, 0xC9,
  34668. 0x0A, 0x15, 0xC8, 0x86, 0xAD, 0x3E, 0xD4, 0x89,
  34669. 0x46, 0x26, 0x99, 0xE4, 0xAB, 0xED, 0x44, 0x35,
  34670. 0x0B, 0xC3, 0x75, 0x7E, 0x26, 0x96, 0xFB, 0xFB,
  34671. 0x25, 0x34, 0x41, 0x2E, 0x8D, 0xD2, 0x01, 0xF1,
  34672. 0xE4, 0x54, 0x0A, 0x39, 0x70, 0xB0, 0x55, 0xFE,
  34673. 0x3B, 0x0B, 0xEC, 0x3A, 0x71, 0xF9, 0xE1, 0x15,
  34674. 0xB3, 0xF9, 0xF3, 0x91, 0x02, 0x06, 0x5B, 0x1C,
  34675. 0xCA, 0x83, 0x14, 0xDC, 0xC7, 0x95, 0xE3, 0xC0,
  34676. 0xE8, 0xFA, 0x98, 0xEE, 0x83, 0xCA, 0x66, 0x28,
  34677. 0x45, 0x70, 0x28, 0xA4, 0xD0, 0x9E, 0x83, 0x9E,
  34678. 0x55, 0x48, 0x62, 0xCF, 0x0B, 0x7B, 0xF5, 0x6C,
  34679. 0x5C, 0x0A, 0x82, 0x9E, 0x86, 0x57, 0x94, 0x79,
  34680. 0x45, 0xFE, 0x9C, 0x22, 0x56, 0x4F, 0xBA, 0xEB,
  34681. 0xC1, 0xB3, 0xAF, 0x35, 0x0D, 0x79, 0x55, 0x50,
  34682. 0x8A, 0x26, 0xD8, 0xA8, 0xEB, 0x54, 0x7B, 0x8B,
  34683. 0x1A, 0x2C, 0xF0, 0x3C, 0xCA, 0x1A, 0xAB, 0xCE,
  34684. 0x6C, 0x34, 0x97, 0x78, 0x3B, 0x64, 0x65, 0xBA,
  34685. 0x0B, 0x6E, 0x7A, 0xCB, 0xA8, 0x21, 0x19, 0x51,
  34686. 0x24, 0xAE, 0xF0, 0x9E, 0x62, 0x83, 0x82, 0xA1,
  34687. 0xF9, 0x14, 0x04, 0x3B, 0xE7, 0x09, 0x6E, 0x95,
  34688. 0x2C, 0xBC, 0x4F, 0xB4, 0xAF, 0xED, 0x13, 0x60,
  34689. 0x90, 0x46, 0x11, 0x7C, 0x01, 0x1F, 0xD7, 0x41,
  34690. 0xEE, 0x28, 0x6C, 0x83, 0x77, 0x16, 0x90, 0xF0,
  34691. 0xAE, 0xB5, 0x0D, 0xA0, 0xD7, 0x12, 0x85, 0xA1,
  34692. 0x79, 0xB2, 0x15, 0xC6, 0x03, 0x6D, 0xEB, 0x78,
  34693. 0x0F, 0x4D, 0x16, 0x76, 0x9F, 0x72, 0xDE, 0x16,
  34694. 0xFD, 0xAD, 0xAC, 0x73, 0xBE, 0xFA, 0x5B, 0xEF,
  34695. 0x89, 0x43, 0x19, 0x7F, 0x44, 0xC5, 0x95, 0x89,
  34696. 0xDC, 0x9F, 0x49, 0x73, 0xDE, 0x14, 0x50, 0xBA,
  34697. 0x1D, 0x0C, 0x32, 0x90, 0xD6, 0xB1, 0xD6, 0x83,
  34698. 0xF2, 0x94, 0xE7, 0x59, 0xC9, 0x54, 0xAB, 0xE8,
  34699. 0xA7, 0xDA, 0x5B, 0x10, 0x54, 0xFD, 0x6D, 0x21,
  34700. 0x32, 0x9B, 0x8E, 0x73, 0xD3, 0x75, 0x6A, 0xFD,
  34701. 0xA0, 0xDC, 0xB1, 0xFC, 0x8B, 0x15, 0x82, 0xD1,
  34702. 0xF9, 0x0C, 0xF2, 0x75, 0xA1, 0x02, 0xAB, 0xC6,
  34703. 0xAC, 0x69, 0x9D, 0xF0, 0xC5, 0x87, 0x0E, 0x50,
  34704. 0xA1, 0xF9, 0x89, 0xE4, 0xE6, 0x24, 0x1B, 0x60,
  34705. 0xAA, 0xA2, 0xEC, 0xF9, 0xE8, 0xE3, 0x3E, 0x0F,
  34706. 0xFC, 0xF4, 0x0F, 0xE8, 0x31, 0xE8, 0xFD, 0xC2,
  34707. 0xE8, 0x3B, 0x52, 0xCA, 0x7A, 0xB6, 0xD9, 0x3F,
  34708. 0x14, 0x6D, 0x29, 0xDC, 0xA5, 0x3C, 0x7D, 0xA1,
  34709. 0xDB, 0x4A, 0xC4, 0xF2, 0xDB, 0x39, 0xEA, 0x12,
  34710. 0x0D, 0x90, 0xFA, 0x60, 0xF4, 0xD4, 0x37, 0xC6,
  34711. 0xD0, 0x0E, 0xF4, 0x83, 0xBC, 0x94, 0xA3, 0x17,
  34712. 0x5C, 0xDA, 0x16, 0x3F, 0xC1, 0xC2, 0x82, 0x8B,
  34713. 0xE4, 0xDB, 0xD6, 0x43, 0x05, 0x07, 0xB5, 0x84,
  34714. 0xBB, 0x51, 0x77, 0xE1, 0x71, 0xB8, 0xDD, 0xA9,
  34715. 0xA4, 0x29, 0x3C, 0x32, 0x00, 0x29, 0x5C, 0x80,
  34716. 0x3A, 0x86, 0x5D, 0x6D, 0x21, 0x66, 0xF6, 0x6B,
  34717. 0xA5, 0x40, 0x1F, 0xB7, 0xA0, 0xE8, 0x53, 0x16,
  34718. 0x86, 0x00, 0xA2, 0x94, 0x84, 0x37, 0xE0, 0x36,
  34719. 0xE3, 0xBF, 0x19, 0xE1, 0x2F, 0xD3, 0xF2, 0xA2,
  34720. 0xB8, 0xB3, 0x43, 0xF7, 0x84, 0x24, 0x8E, 0x8D,
  34721. 0x68, 0x5E, 0xB0, 0xAF, 0xDE, 0x63, 0x15, 0x33,
  34722. 0x87, 0x30, 0xE7, 0xA1, 0x00, 0x1C, 0x27, 0xD8,
  34723. 0xD2, 0xA7, 0x6F, 0xA6, 0x9D, 0x15, 0x7B, 0xA1,
  34724. 0xAC, 0x7A, 0xD5, 0x6D, 0xA5, 0xA8, 0xC7, 0x0F,
  34725. 0xE4, 0xB5, 0xB8, 0xD7, 0x86, 0xDC, 0x6F, 0xC0,
  34726. 0x56, 0x6B, 0xA8, 0xE1, 0xB8, 0x81, 0x63, 0x34,
  34727. 0xD3, 0x2A, 0x3F, 0xB1, 0xCE, 0x7D, 0x4D, 0x5E,
  34728. 0x4C, 0x33, 0x2A, 0xF7, 0xB0, 0x03, 0xD0, 0x91,
  34729. 0x74, 0x1A, 0x3D, 0x5C, 0x96, 0x52, 0x92, 0x25,
  34730. 0x5D, 0xFF, 0x8E, 0xD2, 0xBB, 0xF1, 0xF9, 0x11,
  34731. 0x6B, 0xE5, 0x0C, 0x17, 0xB8, 0xE5, 0x48, 0x74,
  34732. 0x8A, 0xD4, 0xB2, 0xE9, 0x57, 0xBB, 0xD1, 0x95,
  34733. 0x34, 0x82, 0xA2, 0xE1, 0x71, 0x8C, 0xEC, 0x66,
  34734. 0xCD, 0x2C, 0x81, 0xF5, 0x72, 0xD5, 0x52, 0xB7,
  34735. 0x18, 0x78, 0x85, 0xE6, 0xB8, 0x94, 0x3D, 0x64,
  34736. 0x31, 0x41, 0x3C, 0x59, 0xEB, 0xB7, 0xE0, 0x36,
  34737. 0x04, 0x84, 0x90, 0xBE, 0x52, 0x89, 0xE9, 0x5B,
  34738. 0x20, 0xA8, 0x9E, 0x8B, 0x15, 0x9F, 0x61, 0xA9,
  34739. 0xA9, 0x88, 0x6E, 0x14, 0x75, 0x68, 0xF4, 0xC9,
  34740. 0x02, 0x1F, 0x36, 0x2F, 0x02, 0x68, 0x8A, 0x1C,
  34741. 0x8C, 0x3B, 0xB0, 0xD2, 0x40, 0x86, 0x88, 0x0E,
  34742. 0x55, 0xB6, 0xED, 0xB4, 0x3F, 0x37, 0x45, 0xD2,
  34743. 0xC1, 0x66, 0xDC, 0x1C, 0xB7, 0x43, 0xC7, 0x6F,
  34744. 0xE6, 0xBE, 0x52, 0x3A, 0x89, 0x3C, 0xC7, 0x64,
  34745. 0xD1, 0x64, 0x35, 0xC3, 0x78, 0x51, 0x25, 0x2A,
  34746. 0x81, 0xE2, 0xFF, 0xBA, 0x0F, 0x18, 0x97, 0x1A,
  34747. 0x3D, 0xEE, 0x37, 0xD4, 0x87, 0x7C, 0xB9, 0x28,
  34748. 0xE3, 0x6E, 0x52, 0x35, 0x03, 0x7A, 0x6B, 0x20,
  34749. 0x57, 0x89, 0x7D, 0x51, 0x8A, 0x5F, 0x0E, 0x34,
  34750. 0x8E, 0x3A, 0xB6, 0xD5, 0xB5, 0x2D, 0xFC, 0x60,
  34751. 0x75, 0x7F, 0x3B, 0x41, 0xA4, 0xFE, 0xC7, 0x82,
  34752. 0x8F, 0x1D, 0xEE, 0xAF, 0x45, 0x87, 0xCC, 0xC8,
  34753. 0xEA, 0xDF, 0x64, 0x7F, 0x4D, 0x20, 0x3B, 0x2F,
  34754. 0xAA, 0x05, 0xA6, 0x49, 0xB5, 0x82, 0x34, 0x0C,
  34755. 0xB4, 0xCA, 0xCE, 0x57, 0xA3, 0x07, 0x11, 0xBE,
  34756. 0x75, 0x2F, 0xAC, 0xF0, 0x22, 0x7D, 0x0A, 0x80,
  34757. 0xC4, 0x12, 0x84, 0x42, 0xDD, 0xC5, 0x44, 0xBE,
  34758. 0x80, 0x5B, 0x9C, 0xFE, 0x8F, 0xE9, 0xB1, 0x23,
  34759. 0x7C, 0x80, 0xF9, 0x67, 0x87, 0xCD, 0x92, 0x81,
  34760. 0xCC, 0xF2, 0x70, 0xC1, 0xAF, 0xC0, 0x67, 0x0D
  34761. #else
  34762. 0x11, 0x3d, 0xb2, 0xdd, 0x06, 0x87, 0x12, 0x35,
  34763. 0xe7, 0xbc, 0x36, 0xc9, 0xdc, 0xaa, 0x52, 0x8f,
  34764. 0xc2, 0x6c, 0xe5, 0xdb, 0x9e, 0xcc, 0x1d, 0xc3,
  34765. 0x2e, 0x95, 0x7d, 0x7f, 0xfb, 0x3c, 0x74, 0x29,
  34766. 0xd5, 0x0c, 0x3c, 0x35, 0x77, 0xa5, 0x15, 0xd3,
  34767. 0x18, 0x3a, 0x1b, 0x9d, 0x26, 0x7b, 0x93, 0x6b,
  34768. 0x7e, 0xb8, 0xf5, 0x43, 0xa3, 0xaf, 0xb7, 0x77,
  34769. 0x65, 0xca, 0x79, 0x38, 0xf7, 0x8a, 0xa6, 0x43,
  34770. 0x8c, 0xe8, 0x0a, 0x06, 0xa6, 0x96, 0x6d, 0x0d,
  34771. 0x06, 0xaf, 0x75, 0xba, 0x3e, 0x0d, 0x4f, 0x37,
  34772. 0xba, 0xc7, 0x33, 0x69, 0xf5, 0xa7, 0x29, 0xf7,
  34773. 0x3e, 0x85, 0x72, 0x9e, 0xdd, 0x97, 0xc8, 0xc2,
  34774. 0xa8, 0xcc, 0x26, 0x19, 0xe4, 0xcf, 0x7b, 0x60,
  34775. 0x91, 0x86, 0x9e, 0x90, 0x9f, 0xd4, 0x7d, 0x97,
  34776. 0x09, 0x14, 0x92, 0x04, 0xb0, 0x83, 0x7d, 0x8d,
  34777. 0x6f, 0x25, 0xd2, 0x67, 0x97, 0x2b, 0xe6, 0x3b,
  34778. 0xad, 0x34, 0xb5, 0x44, 0x52, 0x3c, 0x01, 0xc0,
  34779. 0x9d, 0xe3, 0xb1, 0xfa, 0x1d, 0x6b, 0x7b, 0x05,
  34780. 0x9e, 0xee, 0x9e, 0x65, 0x20, 0x62, 0xfe, 0x87,
  34781. 0x0f, 0x68, 0xc6, 0x80, 0x05, 0x33, 0x9e, 0xa1,
  34782. 0x81, 0xe1, 0xd0, 0x76, 0x7c, 0x15, 0x2a, 0xeb,
  34783. 0x38, 0xfa, 0xf0, 0xf9, 0x24, 0x5a, 0xe5, 0x9d,
  34784. 0x5c, 0xb0, 0xd2, 0xb7, 0xf2, 0x01, 0x22, 0x9e,
  34785. 0xd9, 0x70, 0x20, 0xd0, 0x62, 0x3a, 0x46, 0x10,
  34786. 0x0d, 0x09, 0x7b, 0x0c, 0xe1, 0x15, 0x4e, 0x02,
  34787. 0x8a, 0xe6, 0x19, 0x4d, 0xe0, 0x5d, 0xe9, 0x7d,
  34788. 0xd9, 0xae, 0x2e, 0x85, 0xff, 0xd2, 0x5d, 0x95,
  34789. 0xeb, 0x22, 0xef, 0xfe, 0x5b, 0xa1, 0x9c, 0xd8,
  34790. 0x07, 0xc5, 0x30, 0xeb, 0xaa, 0x9f, 0xe9, 0xf6,
  34791. 0x42, 0xcc, 0xac, 0xff, 0x47, 0xed, 0x15, 0xc2,
  34792. 0x2b, 0xfe, 0x30, 0x36, 0xeb, 0xf8, 0xad, 0x9c,
  34793. 0x8e, 0xd2, 0x32, 0x40, 0xae, 0xeb, 0xaa, 0x24,
  34794. 0xd1, 0x35, 0x75, 0x51, 0x00, 0xb8, 0x5e, 0xce,
  34795. 0xe3, 0x17, 0x49, 0x06, 0xe4, 0x63, 0x12, 0x06,
  34796. 0x2c, 0xee, 0xca, 0xc7, 0x5d, 0xe5, 0x27, 0x52,
  34797. 0x56, 0xc2, 0xc1, 0xa6, 0x53, 0xfd, 0x69, 0x15,
  34798. 0xb1, 0xb3, 0x0c, 0x8e, 0xcb, 0xb6, 0xfd, 0x42,
  34799. 0x80, 0x43, 0x74, 0x53, 0x17, 0x3a, 0x96, 0x23,
  34800. 0x8b, 0xc7, 0xd1, 0x08, 0x89, 0x23, 0x43, 0xe0,
  34801. 0x33, 0xbc, 0xd9, 0x8e, 0x43, 0x7e, 0x78, 0x9f,
  34802. 0xc5, 0xbe, 0xba, 0xa1, 0x2b, 0x26, 0x34, 0xb5,
  34803. 0x1e, 0xd0, 0xd5, 0x89, 0xf1, 0x11, 0x43, 0xa0,
  34804. 0x21, 0xd8, 0xec, 0xce, 0x59, 0x4f, 0xdd, 0x48,
  34805. 0xda, 0xe8, 0x4c, 0x80, 0x63, 0xef, 0x35, 0x81,
  34806. 0xbc, 0x37, 0x8a, 0x48, 0xda, 0x4e, 0x51, 0xbb,
  34807. 0x17, 0x5b, 0x0d, 0xb4, 0x7f, 0x9d, 0xcf, 0x99,
  34808. 0x31, 0x8c, 0x30, 0x22, 0x5c, 0xa7, 0xfa, 0x79,
  34809. 0xc8, 0x79, 0xbf, 0x1c, 0x93, 0x97, 0xb5, 0xcc,
  34810. 0xc5, 0xef, 0xad, 0x94, 0xc5, 0x00, 0xed, 0x7f,
  34811. 0x9f, 0x38, 0x5d, 0x08, 0x8e, 0x34, 0x93, 0x22,
  34812. 0x21, 0xfc, 0x0f, 0xc9, 0xaf, 0xe5, 0x1f, 0x68,
  34813. 0x75, 0x54, 0x81, 0x31, 0x69, 0x76, 0x95, 0x47,
  34814. 0x8a, 0xbd, 0xc8, 0x73, 0x6f, 0x10, 0x09, 0x5a,
  34815. 0x6b, 0x92, 0xec, 0x67, 0x9f, 0xe0, 0xe2, 0xae,
  34816. 0x5d, 0x8b, 0x33, 0x53, 0x55, 0xd5, 0x8d, 0xae,
  34817. 0x4d, 0x4f, 0x0b, 0x17, 0xaa, 0x5d, 0x1e, 0x52,
  34818. 0xf1, 0xd4, 0x55, 0x84, 0xa8, 0x92, 0xc3, 0x4c,
  34819. 0xe4, 0xb0, 0x4f, 0xcd, 0x00, 0x98, 0x1d, 0x51,
  34820. 0xca, 0xa1, 0x60, 0x64, 0xba, 0xd9, 0x2d, 0x01,
  34821. 0x9d, 0xc3, 0xad, 0xed, 0x91, 0x96, 0x84, 0x11,
  34822. 0x2b, 0x29, 0xda, 0xa2, 0x8b, 0x9d, 0xae, 0x09,
  34823. 0xb8, 0x6b, 0x21, 0xa9, 0x33, 0x10, 0xd5, 0xfb,
  34824. 0xc6, 0x52, 0x7b, 0x22, 0x4b, 0x9c, 0xe8, 0x7d,
  34825. 0x27, 0x82, 0xbb, 0x29, 0x46, 0x73, 0xf0, 0xec,
  34826. 0x06, 0xf2, 0x6b, 0x08, 0x76, 0x52, 0xa1, 0x8d,
  34827. 0x6a, 0xd7, 0xb1, 0xc9, 0x33, 0x03, 0xef, 0x05,
  34828. 0x61, 0xc0, 0xfc, 0x9c, 0xd4, 0xf6, 0x78, 0xf6,
  34829. 0x06, 0xf1, 0x92, 0xcf, 0x5d, 0xf9, 0x2b, 0x15,
  34830. 0x48, 0xf5, 0xdd, 0x26, 0x87, 0xed, 0xbe, 0xcc,
  34831. 0xfc, 0x6d, 0x4e, 0x9d, 0xe4, 0xbd, 0x50, 0xd3,
  34832. 0xc7, 0x4f, 0xb2, 0x75, 0xab, 0xd9, 0xb3, 0xe9,
  34833. 0x02, 0x77, 0xdb, 0x4a, 0x00, 0x69, 0xc0, 0xa2,
  34834. 0xa7, 0x13, 0x6f, 0x50, 0xce, 0xad, 0x4b, 0x2f,
  34835. 0x19, 0x95, 0xfa, 0xaf, 0x16, 0x80, 0x40, 0xe9,
  34836. 0xe4, 0xbe, 0xb7, 0xc5, 0x72, 0x20, 0x49, 0xd6,
  34837. 0xda, 0x64, 0x02, 0x99, 0x2f, 0xce, 0xa4, 0x50,
  34838. 0x97, 0xdf, 0x7c, 0x1c, 0x20, 0xfb, 0x06, 0x82,
  34839. 0x22, 0x00, 0x05, 0x76, 0x93, 0x5a, 0x08, 0x06,
  34840. 0x77, 0x34, 0x51, 0x92, 0x1f, 0x54, 0xc5, 0x5f,
  34841. 0xbf, 0x59, 0x3a, 0x4f, 0x14, 0x7c, 0x1f, 0xef,
  34842. 0x3a, 0xca, 0xf0, 0xcf, 0xa9, 0x07, 0xae, 0x48,
  34843. 0xc8, 0xc0, 0x63, 0x12, 0xcf, 0xdf, 0x51, 0x86,
  34844. 0x90, 0x4b, 0xec, 0x7f, 0xed, 0x4e, 0xd9, 0x33,
  34845. 0xc9, 0x25, 0x6a, 0xb0, 0x4c, 0xbf, 0xa0, 0x3a,
  34846. 0x96, 0x7c, 0x1f, 0x7e, 0xad, 0x4a, 0xb4, 0x0d,
  34847. 0xf1, 0x16, 0xbe, 0x66, 0x0e, 0x27, 0xca, 0x2b,
  34848. 0x54, 0x35, 0x26, 0xd4, 0xb9, 0x68, 0x4c, 0x31,
  34849. 0xe1, 0xe4, 0x23, 0x83, 0xb9, 0x69, 0xf8, 0x96,
  34850. 0x29, 0x9d, 0x71, 0x39, 0x0c, 0xc8, 0x5b, 0x70,
  34851. 0x32, 0x02, 0xac, 0xad, 0xec, 0xfa, 0x8c, 0x40,
  34852. 0x96, 0x5c, 0x08, 0xc5, 0x3b, 0x56, 0x71, 0xe0,
  34853. 0xd5, 0x94, 0x55, 0xbc, 0x5a, 0x85, 0x86, 0xc6,
  34854. 0x55, 0xdb, 0x8c, 0x2a, 0xde, 0x4b, 0xa8, 0x87,
  34855. 0x7f, 0x19, 0xb6, 0x00, 0x0e, 0x18, 0xf8, 0xfe,
  34856. 0xad, 0xda, 0x7e, 0xde, 0x8f, 0xe8, 0x0a, 0xa6,
  34857. 0x62, 0xd6, 0x94, 0xc6, 0xd8, 0xc3, 0x3b, 0x52
  34858. #endif
  34859. };
  34860. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ss[] = {
  34861. #ifdef WOLFSSL_KYBER_ORIGINAL
  34862. 0x0A, 0x69, 0x25, 0x67, 0x6F, 0x24, 0xB2, 0x2C,
  34863. 0x28, 0x6F, 0x4C, 0x81, 0xA4, 0x22, 0x4C, 0xEC,
  34864. 0x50, 0x6C, 0x9B, 0x25, 0x7D, 0x48, 0x0E, 0x02,
  34865. 0xE3, 0xB4, 0x9F, 0x44, 0xCA, 0xA3, 0x23, 0x7F
  34866. #else
  34867. 0x31, 0x98, 0x39, 0xe8, 0x2a, 0xb6, 0xb2, 0x22,
  34868. 0xde, 0x7b, 0x61, 0x9e, 0x80, 0xda, 0x83, 0x91,
  34869. 0x52, 0x2b, 0xbb, 0x37, 0x67, 0x70, 0x18, 0x49,
  34870. 0x4a, 0x47, 0x42, 0xc5, 0x3f, 0x9a, 0xbf, 0xdf
  34871. #endif
  34872. };
  34873. #ifdef WOLFSSL_SMALL_STACK
  34874. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  34875. DYNAMIC_TYPE_TMP_BUFFER);
  34876. priv = (byte *)XMALLOC(KYBER512_PRIVATE_KEY_SIZE, HEAP_HINT,
  34877. DYNAMIC_TYPE_TMP_BUFFER);
  34878. pub = (byte *)XMALLOC(KYBER512_PUBLIC_KEY_SIZE, HEAP_HINT,
  34879. DYNAMIC_TYPE_TMP_BUFFER);
  34880. ct = (byte *)XMALLOC(KYBER512_CIPHER_TEXT_SIZE, HEAP_HINT,
  34881. DYNAMIC_TYPE_TMP_BUFFER);
  34882. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34883. DYNAMIC_TYPE_TMP_BUFFER);
  34884. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34885. DYNAMIC_TYPE_TMP_BUFFER);
  34886. if (! (key && priv && pub && ct && ss && ss_dec))
  34887. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  34888. #endif
  34889. ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
  34890. if (ret != 0)
  34891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34892. else
  34893. key_inited = 1;
  34894. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34895. sizeof(kyber512_rand));
  34896. if (ret != 0)
  34897. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34898. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
  34899. if (ret != 0)
  34900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34901. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
  34902. if (ret != 0)
  34903. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34904. if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0)
  34905. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34906. if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
  34907. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34908. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34909. sizeof(kyber512enc_rand));
  34910. if (ret != 0)
  34911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34912. if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0)
  34913. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34914. if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34915. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34916. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
  34917. if (ret != 0)
  34918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34919. if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34920. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34921. out:
  34922. if (key_inited)
  34923. wc_KyberKey_Free(key);
  34924. #ifdef WOLFSSL_SMALL_STACK
  34925. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34926. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34927. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34928. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34929. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34930. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34931. #endif
  34932. return ret;
  34933. }
  34934. #endif /* WOLFSSL_KYBER512 */
  34935. #ifdef WOLFSSL_KYBER768
  34936. static wc_test_ret_t kyber768_kat(void)
  34937. {
  34938. wc_test_ret_t ret;
  34939. #ifdef WOLFSSL_SMALL_STACK
  34940. KyberKey *key = NULL;
  34941. byte *priv = NULL;
  34942. byte *pub = NULL;
  34943. byte *ct = NULL;
  34944. byte *ss = NULL;
  34945. byte *ss_dec = NULL;
  34946. #else
  34947. KyberKey key[1];
  34948. byte priv[KYBER768_PRIVATE_KEY_SIZE];
  34949. byte pub[KYBER768_PUBLIC_KEY_SIZE];
  34950. byte ct[KYBER768_CIPHER_TEXT_SIZE];
  34951. byte ss[KYBER_SS_SZ];
  34952. byte ss_dec[KYBER_SS_SZ];
  34953. #endif
  34954. int key_inited = 0;
  34955. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_rand[] = {
  34956. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34957. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34958. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34959. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34960. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34961. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34962. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34963. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34964. };
  34965. WOLFSSL_SMALL_STACK_STATIC const byte kyber768enc_rand[] = {
  34966. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34967. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34968. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34969. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34970. };
  34971. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_pk[] = {
  34972. #ifdef WOLFSSL_KYBER_ORIGINAL
  34973. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  34974. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  34975. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  34976. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  34977. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  34978. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  34979. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  34980. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  34981. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  34982. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  34983. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  34984. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  34985. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  34986. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  34987. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  34988. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  34989. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  34990. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  34991. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  34992. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  34993. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  34994. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  34995. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  34996. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  34997. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  34998. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  34999. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35000. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35001. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35002. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35003. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35004. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35005. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35006. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35007. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35008. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35009. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35010. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35011. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35012. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35013. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35014. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35015. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35016. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35017. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35018. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35019. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35020. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35021. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35022. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35023. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35024. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35025. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35026. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35027. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35028. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35029. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35030. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35031. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35032. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35033. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35034. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35035. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35036. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35037. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35038. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35039. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35040. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35041. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35042. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35043. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35044. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35045. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35046. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35047. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35048. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35049. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35050. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35051. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35052. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35053. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35054. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35055. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35056. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35057. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35058. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35059. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35060. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35061. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35062. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35063. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35064. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35065. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35066. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35067. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35068. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35069. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35070. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35071. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35072. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35073. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35074. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35075. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35076. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35077. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35078. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35079. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35080. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35081. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35082. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35083. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35084. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35085. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35086. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35087. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35088. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35089. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35090. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35091. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35092. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35093. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35094. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35095. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35096. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35097. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35098. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35099. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35100. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35101. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35102. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35103. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35104. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35105. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35106. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35107. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35108. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35109. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35110. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35111. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35112. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35113. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35114. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35115. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35116. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35117. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35118. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35119. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35120. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  35121. #else
  35122. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35123. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35124. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35125. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35126. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35127. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35128. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35129. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35130. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35131. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35132. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35133. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35134. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35135. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35136. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35137. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35138. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35139. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35140. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35141. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35142. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35143. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35144. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35145. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35146. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35147. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35148. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35149. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35150. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35151. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35152. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35153. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35154. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35155. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35156. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35157. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35158. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35159. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35160. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35161. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35162. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35163. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35164. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35165. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35166. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35167. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35168. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35169. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35170. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35171. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35172. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35173. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35174. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35175. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35176. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35177. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35178. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35179. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35180. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35181. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35182. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35183. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35184. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35185. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35186. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35187. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35188. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35189. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35190. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35191. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35192. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35193. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35194. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35195. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35196. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35197. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35198. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35199. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35200. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35201. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35202. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35203. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35204. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35205. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35206. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35207. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35208. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35209. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35210. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35211. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35212. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35213. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35214. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35215. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35216. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35217. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35218. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35219. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35220. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35221. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35222. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35223. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35224. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35225. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35226. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35227. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35228. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35229. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35230. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35231. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35232. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35233. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35234. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35235. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35236. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35237. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35238. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35239. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35240. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35241. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35242. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35243. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35244. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35245. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35246. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35247. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35248. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35249. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35250. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35251. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35252. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35253. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35254. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35255. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35256. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35257. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35258. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35259. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35260. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35261. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35262. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35263. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35264. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35265. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35266. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35267. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35268. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35269. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28
  35270. #endif
  35271. };
  35272. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_sk[] = {
  35273. #ifdef WOLFSSL_KYBER_ORIGINAL
  35274. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  35275. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  35276. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  35277. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  35278. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  35279. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  35280. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  35281. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  35282. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  35283. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  35284. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  35285. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  35286. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  35287. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  35288. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  35289. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  35290. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  35291. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  35292. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  35293. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  35294. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  35295. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  35296. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  35297. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  35298. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  35299. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  35300. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  35301. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  35302. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  35303. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  35304. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  35305. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  35306. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  35307. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  35308. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  35309. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  35310. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  35311. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  35312. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  35313. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  35314. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  35315. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  35316. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  35317. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  35318. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  35319. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  35320. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  35321. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  35322. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  35323. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  35324. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  35325. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  35326. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  35327. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  35328. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  35329. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  35330. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  35331. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  35332. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  35333. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  35334. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  35335. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  35336. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  35337. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  35338. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  35339. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  35340. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  35341. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  35342. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  35343. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  35344. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  35345. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  35346. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  35347. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  35348. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  35349. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  35350. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  35351. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  35352. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  35353. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  35354. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  35355. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  35356. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  35357. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  35358. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  35359. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  35360. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  35361. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  35362. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  35363. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  35364. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  35365. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  35366. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  35367. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  35368. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  35369. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  35370. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  35371. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  35372. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  35373. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  35374. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  35375. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  35376. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  35377. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  35378. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  35379. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  35380. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  35381. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  35382. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  35383. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  35384. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  35385. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  35386. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  35387. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  35388. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  35389. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  35390. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  35391. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  35392. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  35393. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  35394. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  35395. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  35396. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  35397. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  35398. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  35399. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  35400. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  35401. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  35402. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  35403. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  35404. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  35405. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  35406. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  35407. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  35408. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  35409. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  35410. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  35411. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  35412. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  35413. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  35414. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  35415. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  35416. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  35417. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  35418. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35419. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35420. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35421. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35422. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35423. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35424. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35425. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35426. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35427. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35428. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35429. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35430. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35431. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35432. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35433. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35434. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35435. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35436. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35437. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35438. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35439. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35440. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35441. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35442. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35443. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35444. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35445. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35446. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35447. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35448. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35449. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35450. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35451. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35452. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35453. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35454. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35455. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35456. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35457. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35458. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35459. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35460. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35461. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35462. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35463. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35464. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35465. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35466. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35467. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35468. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35469. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35470. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35471. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35472. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35473. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35474. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35475. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35476. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35477. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35478. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35479. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35480. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35481. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35482. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35483. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35484. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35485. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35486. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35487. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35488. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35489. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35490. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35491. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35492. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35493. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35494. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35495. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35496. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35497. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35498. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35499. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35500. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35501. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35502. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35503. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35504. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35505. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35506. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35507. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35508. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35509. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35510. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35511. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35512. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35513. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35514. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35515. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35516. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35517. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35518. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35519. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35520. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35521. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35522. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35523. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35524. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35525. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35526. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35527. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35528. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35529. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35530. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35531. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35532. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35533. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35534. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35535. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35536. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35537. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35538. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35539. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35540. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35541. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35542. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35543. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35544. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35545. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35546. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35547. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35548. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35549. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35550. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35551. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35552. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35553. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35554. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35555. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35556. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35557. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35558. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35559. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35560. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35561. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35562. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35563. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35564. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35565. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  35566. 0xD4, 0xEC, 0x14, 0x3B, 0x50, 0xF0, 0x14, 0x23,
  35567. 0xB1, 0x77, 0x89, 0x5E, 0xDE, 0xE2, 0x2B, 0xB7,
  35568. 0x39, 0xF6, 0x47, 0xEC, 0xF8, 0x5F, 0x50, 0xBC,
  35569. 0x25, 0xEF, 0x7B, 0x5A, 0x72, 0x5D, 0xEE, 0x86,
  35570. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35571. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35572. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35573. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35574. #else
  35575. 0xda, 0x0a, 0xc7, 0xb6, 0x60, 0x40, 0x4e, 0x61,
  35576. 0x3a, 0xa1, 0xf9, 0x80, 0x38, 0x0c, 0xb3, 0x6d,
  35577. 0xba, 0x18, 0xd2, 0x32, 0x56, 0xc7, 0x26, 0x7a,
  35578. 0x00, 0xa6, 0x7b, 0xa6, 0xc2, 0xa2, 0xb1, 0x4c,
  35579. 0x41, 0x42, 0x39, 0x66, 0x2f, 0x68, 0xbd, 0x44,
  35580. 0x6c, 0x8e, 0xfd, 0xf3, 0x66, 0x56, 0xa0, 0x89,
  35581. 0x1a, 0x3c, 0xc6, 0x23, 0xfc, 0x68, 0xb6, 0x57,
  35582. 0x2f, 0x7b, 0x29, 0xa6, 0xde, 0x12, 0x80, 0x14,
  35583. 0x41, 0x1e, 0xe4, 0x19, 0x06, 0xd0, 0x80, 0x71,
  35584. 0xf9, 0x48, 0x56, 0xe3, 0x6a, 0x83, 0x2b, 0x40,
  35585. 0x33, 0x8d, 0x74, 0x35, 0x16, 0x65, 0x9b, 0xd2,
  35586. 0x58, 0x79, 0xc0, 0x07, 0xa5, 0x2b, 0xc9, 0x58,
  35587. 0x6f, 0x79, 0x87, 0x6a, 0xfa, 0xc6, 0xc9, 0xa3,
  35588. 0x0d, 0x8f, 0xac, 0x24, 0x3b, 0xd2, 0x24, 0x25,
  35589. 0xd6, 0xad, 0xce, 0x42, 0xab, 0x7e, 0xd3, 0x90,
  35590. 0x14, 0x75, 0x7a, 0x95, 0x8b, 0xc8, 0xa7, 0x45,
  35591. 0x65, 0xf0, 0x19, 0x23, 0x4f, 0xf0, 0x4b, 0x34,
  35592. 0x89, 0x3e, 0xd6, 0xd0, 0x55, 0x01, 0xc3, 0x72,
  35593. 0x55, 0x23, 0x9a, 0xae, 0x2a, 0xc1, 0x9f, 0x8c,
  35594. 0x75, 0xac, 0x59, 0x00, 0xda, 0xe8, 0x30, 0x0d,
  35595. 0xbb, 0xa7, 0x10, 0xdc, 0x2c, 0xaa, 0xe1, 0xbc,
  35596. 0xa3, 0xa3, 0x8c, 0x58, 0x34, 0x2b, 0x28, 0x6b,
  35597. 0x85, 0x18, 0xf1, 0x36, 0xad, 0x15, 0xb9, 0xf7,
  35598. 0xbc, 0xbb, 0x06, 0xa5, 0x60, 0x7d, 0xb3, 0x75,
  35599. 0xdb, 0xe9, 0x76, 0x45, 0x7c, 0x26, 0xc6, 0x59,
  35600. 0x82, 0x57, 0x53, 0x1b, 0x2c, 0xfb, 0x6e, 0xe7,
  35601. 0xf5, 0x15, 0x91, 0x84, 0x08, 0x04, 0xc3, 0x83,
  35602. 0x88, 0x37, 0x6c, 0x27, 0x14, 0x84, 0x13, 0xda,
  35603. 0x9e, 0x92, 0x92, 0x0b, 0xfd, 0x9a, 0x06, 0x9e,
  35604. 0x01, 0x8b, 0xd2, 0x72, 0x05, 0x3d, 0xa8, 0x77,
  35605. 0x5c, 0x0b, 0x73, 0x9f, 0x76, 0x1d, 0xb2, 0x10,
  35606. 0x7c, 0xf3, 0x5a, 0x43, 0x4d, 0x69, 0xb0, 0x7e,
  35607. 0x5b, 0xcd, 0xb8, 0x74, 0x34, 0x13, 0x8b, 0x0c,
  35608. 0xb5, 0x56, 0x76, 0x1b, 0xa5, 0x22, 0xa5, 0x74,
  35609. 0x7b, 0x28, 0x74, 0x7d, 0x80, 0xeb, 0x9d, 0x6c,
  35610. 0xc6, 0x73, 0xbe, 0xe5, 0x76, 0x93, 0x77, 0xb9,
  35611. 0x96, 0xd3, 0x6c, 0xeb, 0x0c, 0x0c, 0x7e, 0xd9,
  35612. 0xa6, 0x58, 0x53, 0x33, 0x24, 0x86, 0x9c, 0x18,
  35613. 0xa1, 0xa3, 0x6f, 0x31, 0x47, 0x0f, 0x14, 0xc5,
  35614. 0xae, 0x49, 0xab, 0x07, 0x05, 0x07, 0xf8, 0x24,
  35615. 0x9c, 0xe4, 0x04, 0xb4, 0x9c, 0x0a, 0x8c, 0x3e,
  35616. 0xe4, 0x2f, 0xea, 0x96, 0x31, 0xfa, 0x1a, 0x0d,
  35617. 0x10, 0xd8, 0x6b, 0x93, 0xf9, 0x86, 0xe0, 0xe3,
  35618. 0xa8, 0x2e, 0x70, 0x3b, 0x74, 0xe5, 0xae, 0x61,
  35619. 0x01, 0x24, 0x24, 0x21, 0xa8, 0x9a, 0xa0, 0x7f,
  35620. 0xe6, 0x85, 0x88, 0x46, 0x0b, 0xaa, 0x36, 0x87,
  35621. 0x86, 0x48, 0x6a, 0x72, 0xe4, 0xf2, 0x4d, 0x2d,
  35622. 0xd7, 0x6c, 0xfc, 0x03, 0xb6, 0x94, 0xa5, 0xba,
  35623. 0x91, 0xa7, 0x55, 0xa0, 0xb9, 0x8f, 0x3b, 0xf9,
  35624. 0x33, 0x07, 0xc0, 0xab, 0x64, 0x63, 0x9a, 0xea,
  35625. 0x7a, 0x64, 0x98, 0xa3, 0xc3, 0xdd, 0xc5, 0x71,
  35626. 0x14, 0x1a, 0xbc, 0xa4, 0x67, 0x8c, 0xd2, 0xe2,
  35627. 0xb8, 0x57, 0xfb, 0x88, 0xf6, 0x00, 0xca, 0xa5,
  35628. 0x96, 0xb4, 0x4b, 0xc4, 0x22, 0x25, 0x0b, 0x28,
  35629. 0x19, 0xe0, 0x51, 0x5f, 0x04, 0x72, 0x39, 0x18,
  35630. 0x53, 0x70, 0x0b, 0x01, 0xef, 0xf9, 0x45, 0x3f,
  35631. 0xd1, 0x18, 0x76, 0xb7, 0xc7, 0x59, 0xa0, 0x7d,
  35632. 0xd8, 0x45, 0xca, 0xba, 0x45, 0x55, 0x26, 0x4a,
  35633. 0x82, 0x76, 0x51, 0x93, 0xfd, 0xf8, 0x1b, 0x62,
  35634. 0x0a, 0x1e, 0x1f, 0x92, 0x3f, 0xb2, 0x44, 0x42,
  35635. 0xcd, 0x1c, 0xbe, 0x94, 0x17, 0x50, 0x03, 0xec,
  35636. 0x06, 0xce, 0x77, 0xa3, 0xc6, 0x44, 0x93, 0xc1,
  35637. 0x99, 0x98, 0x7a, 0x30, 0x0c, 0x95, 0xc5, 0x3c,
  35638. 0x00, 0x89, 0xb5, 0xd6, 0x5c, 0x92, 0xea, 0x97,
  35639. 0x1b, 0x2f, 0xfa, 0x93, 0xb5, 0x2a, 0x46, 0x1e,
  35640. 0xa2, 0xac, 0x8c, 0x19, 0x9c, 0x2f, 0x4c, 0x2b,
  35641. 0x70, 0x42, 0x97, 0xce, 0x3c, 0x39, 0x49, 0xe0,
  35642. 0x73, 0x5e, 0xa8, 0xa1, 0x4a, 0xa5, 0x9e, 0x8d,
  35643. 0xec, 0x0c, 0x87, 0x83, 0x99, 0xff, 0x70, 0x74,
  35644. 0x7a, 0xb2, 0x44, 0xce, 0x46, 0xb5, 0xf2, 0x23,
  35645. 0x04, 0x73, 0x32, 0x3d, 0x25, 0xc6, 0x6f, 0xe6,
  35646. 0xb4, 0x19, 0xb1, 0xf4, 0xa1, 0x12, 0xe5, 0x21,
  35647. 0x40, 0x35, 0x25, 0x6b, 0xc4, 0x3f, 0xfd, 0x2b,
  35648. 0x6b, 0x7b, 0x37, 0x87, 0x69, 0xa6, 0xb4, 0x70,
  35649. 0x00, 0xbf, 0xb6, 0x35, 0x7d, 0x45, 0x81, 0x4b,
  35650. 0xae, 0xf3, 0x85, 0x7d, 0x37, 0x9e, 0x2f, 0xb8,
  35651. 0xb5, 0xe5, 0x20, 0x1a, 0xb2, 0x62, 0x74, 0xbb,
  35652. 0x1b, 0x70, 0xad, 0x32, 0x2c, 0xd0, 0x43, 0x9b,
  35653. 0x2d, 0xb1, 0x09, 0xcf, 0xf0, 0xa2, 0xf8, 0xe6,
  35654. 0x00, 0x99, 0x55, 0x71, 0xff, 0xc3, 0x8c, 0x59,
  35655. 0x0b, 0xc4, 0xc7, 0x61, 0x5c, 0x69, 0xd0, 0xc9,
  35656. 0x8e, 0xf4, 0x30, 0xf3, 0x08, 0x61, 0xa7, 0x72,
  35657. 0x38, 0xff, 0xc0, 0x70, 0x61, 0xe4, 0x75, 0xd6,
  35658. 0xa3, 0x0a, 0xd1, 0xb4, 0x7f, 0xd0, 0x39, 0xc3,
  35659. 0xa4, 0x47, 0x76, 0x2d, 0xb2, 0x21, 0x1d, 0xc3,
  35660. 0x1d, 0x0a, 0xca, 0xcf, 0xd5, 0x58, 0x90, 0xa5,
  35661. 0x82, 0x47, 0x98, 0xf9, 0xae, 0xad, 0x74, 0x13,
  35662. 0xdf, 0xe0, 0x28, 0xb1, 0x01, 0x2b, 0xe8, 0xb6,
  35663. 0xca, 0x10, 0x26, 0x66, 0x6a, 0xc6, 0xbc, 0x94,
  35664. 0x40, 0xa4, 0x49, 0xb5, 0x1a, 0xd8, 0xbb, 0xa7,
  35665. 0xb0, 0x92, 0x1d, 0xd4, 0xd8, 0xb4, 0xa5, 0x78,
  35666. 0x13, 0x6d, 0x1a, 0x05, 0xdb, 0x38, 0xcc, 0x85,
  35667. 0x84, 0x37, 0xb2, 0x51, 0x61, 0xd1, 0xc3, 0xc2,
  35668. 0x8e, 0xe0, 0x7b, 0xbc, 0xf2, 0xb2, 0x49, 0x11,
  35669. 0x0d, 0x22, 0x78, 0x1d, 0xc3, 0x05, 0x0d, 0x8c,
  35670. 0xc0, 0x09, 0x00, 0x96, 0xb3, 0x8a, 0x85, 0x06,
  35671. 0x96, 0xf8, 0x6e, 0x9e, 0x6b, 0xab, 0x32, 0x52,
  35672. 0x71, 0xb2, 0x24, 0x86, 0x75, 0x01, 0x19, 0x68,
  35673. 0x50, 0x28, 0x81, 0x09, 0x04, 0x97, 0xfa, 0xc0,
  35674. 0xaf, 0x84, 0x3c, 0x1a, 0xea, 0x76, 0xdd, 0x81,
  35675. 0xcf, 0x29, 0xc0, 0x12, 0xc6, 0x62, 0x27, 0xb7,
  35676. 0xf0, 0x6d, 0x99, 0x61, 0x30, 0x9b, 0x02, 0x62,
  35677. 0xf7, 0x32, 0xc9, 0xa4, 0xd0, 0xbb, 0xd0, 0x67,
  35678. 0x27, 0xab, 0xb8, 0x37, 0x1f, 0xf2, 0xc1, 0x18,
  35679. 0x99, 0xa0, 0x98, 0x37, 0x5c, 0x46, 0x05, 0x16,
  35680. 0xb2, 0xcc, 0x88, 0xbc, 0xf6, 0x28, 0xed, 0xe3,
  35681. 0x7d, 0x8f, 0x3b, 0x33, 0x42, 0xe4, 0x49, 0x0a,
  35682. 0x85, 0x60, 0x6e, 0xc0, 0x3d, 0xa2, 0x9b, 0x02,
  35683. 0x56, 0x27, 0x53, 0x82, 0xa3, 0x31, 0x3d, 0xc0,
  35684. 0x41, 0x11, 0x48, 0x01, 0x03, 0x2c, 0x51, 0x9f,
  35685. 0x35, 0x0c, 0x3e, 0x6a, 0xba, 0xc3, 0xe3, 0x3b,
  35686. 0x93, 0xb4, 0xa1, 0x9f, 0x7c, 0x54, 0x66, 0xe5,
  35687. 0x8c, 0xb1, 0xdc, 0x14, 0xb4, 0xa9, 0x6c, 0x47,
  35688. 0x57, 0x29, 0xf9, 0x71, 0xbd, 0xf1, 0x73, 0xcd,
  35689. 0xf3, 0x54, 0x82, 0x4d, 0x01, 0x94, 0x27, 0xf9,
  35690. 0x5b, 0x3b, 0x4a, 0x4a, 0x4a, 0x95, 0x8e, 0x47,
  35691. 0x6a, 0x6e, 0x69, 0x91, 0xce, 0x6f, 0x06, 0xcb,
  35692. 0x5d, 0xfc, 0xa7, 0xd4, 0x38, 0x0c, 0x3d, 0x92,
  35693. 0x0b, 0x57, 0x11, 0xac, 0x1f, 0xcb, 0xaf, 0x4b,
  35694. 0x9a, 0xc8, 0x00, 0xb9, 0x76, 0xd1, 0xec, 0x76,
  35695. 0x6a, 0x62, 0x6c, 0xc1, 0x90, 0x0b, 0x66, 0xb3,
  35696. 0xa9, 0xdc, 0x62, 0xc5, 0xc1, 0x44, 0x52, 0x7a,
  35697. 0x29, 0x6b, 0xaf, 0x70, 0x43, 0x3b, 0xf6, 0x57,
  35698. 0xc0, 0x43, 0x7f, 0x87, 0x59, 0x7b, 0xd7, 0xc8,
  35699. 0xbb, 0xbe, 0x9a, 0xbc, 0x37, 0x05, 0x09, 0x31,
  35700. 0xa4, 0xa8, 0x69, 0x82, 0xa2, 0x02, 0x8a, 0x74,
  35701. 0x45, 0x4c, 0x9b, 0x81, 0x0c, 0x88, 0xd1, 0x70,
  35702. 0x1c, 0x8c, 0xc9, 0x8a, 0x1d, 0x4c, 0xa1, 0x07,
  35703. 0xa6, 0xb2, 0x5e, 0x96, 0x2f, 0xe4, 0xb6, 0xb0,
  35704. 0x3c, 0x95, 0x45, 0x32, 0x60, 0xb8, 0x07, 0x22,
  35705. 0x86, 0x37, 0xcc, 0x9e, 0xb1, 0x2a, 0xcc, 0x09,
  35706. 0x54, 0x95, 0x9a, 0x52, 0xae, 0x54, 0xd1, 0x97,
  35707. 0x73, 0x00, 0xab, 0xa0, 0xba, 0x2c, 0x14, 0x60,
  35708. 0x9b, 0xb2, 0x8c, 0x11, 0xd5, 0xfa, 0xc5, 0xca,
  35709. 0xc8, 0x82, 0x97, 0x60, 0x32, 0x83, 0xe8, 0x67,
  35710. 0xa3, 0x64, 0x83, 0x66, 0xc7, 0x24, 0xd9, 0x35,
  35711. 0x4c, 0xd7, 0xa1, 0x96, 0xdb, 0xd9, 0x80, 0x2f,
  35712. 0x7b, 0x88, 0xd3, 0xfa, 0x00, 0x1f, 0x9c, 0x97,
  35713. 0x73, 0x22, 0x54, 0x62, 0x23, 0x5e, 0x91, 0x35,
  35714. 0x2a, 0x20, 0x79, 0x1f, 0xd8, 0xb8, 0x7f, 0xe3,
  35715. 0x37, 0x7e, 0xc6, 0xa3, 0x94, 0x0b, 0x11, 0x30,
  35716. 0xa0, 0xbb, 0x04, 0xe7, 0x41, 0x0a, 0x34, 0xe2,
  35717. 0x58, 0x0d, 0x07, 0x1d, 0x6c, 0x56, 0x20, 0x20,
  35718. 0x86, 0x78, 0x7a, 0x65, 0x90, 0xf8, 0x43, 0x93,
  35719. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35720. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35721. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35722. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35723. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35724. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35725. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35726. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35727. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35728. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35729. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35730. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35731. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35732. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35733. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35734. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35735. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35736. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35737. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35738. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35739. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35740. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35741. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35742. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35743. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35744. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35745. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35746. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35747. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35748. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35749. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35750. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35751. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35752. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35753. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35754. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35755. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35756. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35757. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35758. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35759. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35760. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35761. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35762. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35763. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35764. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35765. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35766. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35767. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35768. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35769. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35770. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35771. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35772. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35773. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35774. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35775. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35776. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35777. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35778. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35779. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35780. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35781. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35782. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35783. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35784. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35785. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35786. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35787. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35788. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35789. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35790. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35791. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35792. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35793. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35794. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35795. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35796. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35797. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35798. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35799. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35800. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35801. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35802. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35803. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35804. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35805. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35806. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35807. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35808. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35809. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35810. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35811. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35812. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35813. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35814. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35815. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35816. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35817. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35818. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35819. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35820. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35821. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35822. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35823. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35824. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35825. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35826. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35827. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35828. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35829. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35830. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35831. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35832. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35833. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35834. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35835. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35836. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35837. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35838. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35839. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35840. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35841. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35842. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35843. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35844. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35845. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35846. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35847. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35848. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35849. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35850. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35851. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35852. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35853. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35854. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35855. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35856. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35857. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35858. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35859. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35860. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35861. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35862. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35863. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35864. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35865. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35866. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28,
  35867. 0xf5, 0x72, 0x62, 0x66, 0x13, 0x58, 0xcd, 0xe8,
  35868. 0xd3, 0xeb, 0xf9, 0x90, 0xe5, 0xfd, 0x1d, 0x5b,
  35869. 0x89, 0x6c, 0x99, 0x2c, 0xcf, 0xaa, 0xdb, 0x52,
  35870. 0x56, 0xb6, 0x8b, 0xbf, 0x59, 0x43, 0xb1, 0x32,
  35871. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  35872. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  35873. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  35874. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  35875. #endif
  35876. };
  35877. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ct[] = {
  35878. #ifdef WOLFSSL_KYBER_ORIGINAL
  35879. 0xB5, 0x2C, 0x56, 0xB9, 0x2A, 0x4B, 0x7C, 0xE9,
  35880. 0xE4, 0xCB, 0x7C, 0x5B, 0x1B, 0x16, 0x31, 0x67,
  35881. 0xA8, 0xA1, 0x67, 0x5B, 0x2F, 0xDE, 0xF8, 0x4A,
  35882. 0x5B, 0x67, 0xCA, 0x15, 0xDB, 0x69, 0x4C, 0x9F,
  35883. 0x11, 0xBD, 0x02, 0x7C, 0x30, 0xAE, 0x22, 0xEC,
  35884. 0x92, 0x1A, 0x1D, 0x91, 0x15, 0x99, 0xAF, 0x05,
  35885. 0x85, 0xE4, 0x8D, 0x20, 0xDA, 0x70, 0xDF, 0x9F,
  35886. 0x39, 0xE3, 0x2E, 0xF9, 0x5D, 0x4C, 0x8F, 0x44,
  35887. 0xBF, 0xEF, 0xDA, 0xA5, 0xDA, 0x64, 0xF1, 0x05,
  35888. 0x46, 0x31, 0xD0, 0x4D, 0x6D, 0x3C, 0xFD, 0x0A,
  35889. 0x54, 0x0D, 0xD7, 0xBA, 0x38, 0x86, 0xE4, 0xB5,
  35890. 0xF1, 0x3E, 0x87, 0x87, 0x88, 0x60, 0x4C, 0x95,
  35891. 0xC0, 0x96, 0xEA, 0xB3, 0x91, 0x9F, 0x42, 0x75,
  35892. 0x21, 0x41, 0x9A, 0x94, 0x6C, 0x26, 0xCC, 0x04,
  35893. 0x14, 0x75, 0xD7, 0x12, 0x4C, 0xDC, 0x01, 0xD0,
  35894. 0x37, 0x3E, 0x5B, 0x09, 0xC7, 0xA7, 0x06, 0x03,
  35895. 0xCF, 0xDB, 0x4F, 0xB3, 0x40, 0x50, 0x23, 0xF2,
  35896. 0x26, 0x4D, 0xC3, 0xF9, 0x83, 0xC4, 0xFC, 0x02,
  35897. 0xA2, 0xD1, 0xB2, 0x68, 0xF2, 0x20, 0x8A, 0x1F,
  35898. 0x6E, 0x2A, 0x62, 0x09, 0xBF, 0xF1, 0x2F, 0x6F,
  35899. 0x46, 0x5F, 0x0B, 0x06, 0x9C, 0x3A, 0x7F, 0x84,
  35900. 0xF6, 0x06, 0xD8, 0xA9, 0x40, 0x64, 0x00, 0x3D,
  35901. 0x6E, 0xC1, 0x14, 0xC8, 0xE8, 0x08, 0xD3, 0x05,
  35902. 0x38, 0x84, 0xC1, 0xD5, 0xA1, 0x42, 0xFB, 0xF2,
  35903. 0x01, 0x12, 0xEB, 0x36, 0x0F, 0xDA, 0x3F, 0x0F,
  35904. 0x28, 0xB1, 0x72, 0xAE, 0x50, 0xF5, 0xE7, 0xD8,
  35905. 0x38, 0x01, 0xFB, 0x3F, 0x00, 0x64, 0xB6, 0x87,
  35906. 0x18, 0x70, 0x74, 0xBD, 0x7F, 0xE3, 0x0E, 0xDD,
  35907. 0xAA, 0x33, 0x4C, 0xF8, 0xFC, 0x04, 0xFA, 0x8C,
  35908. 0xED, 0x89, 0x9C, 0xEA, 0xDE, 0x4B, 0x4F, 0x28,
  35909. 0xB6, 0x83, 0x72, 0xBA, 0xF9, 0x8F, 0xF4, 0x82,
  35910. 0xA4, 0x15, 0xB7, 0x31, 0x15, 0x5B, 0x75, 0xCE,
  35911. 0xB9, 0x76, 0xBE, 0x0E, 0xA0, 0x28, 0x5B, 0xA0,
  35912. 0x1A, 0x27, 0xF1, 0x85, 0x7A, 0x8F, 0xB3, 0x77,
  35913. 0xA3, 0xAE, 0x0C, 0x23, 0xB2, 0xAA, 0x9A, 0x07,
  35914. 0x9B, 0xFA, 0xBF, 0xF0, 0xD5, 0xB2, 0xF1, 0xCD,
  35915. 0x9B, 0x71, 0x8B, 0xEA, 0x03, 0xC4, 0x2F, 0x34,
  35916. 0x3A, 0x39, 0xB4, 0xF1, 0x42, 0xD0, 0x1A, 0xD8,
  35917. 0xAC, 0xBB, 0x50, 0xE3, 0x88, 0x53, 0xCF, 0x9A,
  35918. 0x50, 0xC8, 0xB4, 0x4C, 0x3C, 0xF6, 0x71, 0xA4,
  35919. 0xA9, 0x04, 0x3B, 0x26, 0xDD, 0xBB, 0x24, 0x95,
  35920. 0x9A, 0xD6, 0x71, 0x5C, 0x08, 0x52, 0x18, 0x55,
  35921. 0xC7, 0x9A, 0x23, 0xB9, 0xC3, 0xD6, 0x47, 0x17,
  35922. 0x49, 0xC4, 0x07, 0x25, 0xBD, 0xD5, 0xC2, 0x77,
  35923. 0x6D, 0x43, 0xAE, 0xD2, 0x02, 0x04, 0xBA, 0xA1,
  35924. 0x41, 0xEF, 0xB3, 0x30, 0x49, 0x17, 0x47, 0x4B,
  35925. 0x7F, 0x9F, 0x7A, 0x4B, 0x08, 0xB1, 0xA9, 0x3D,
  35926. 0xAE, 0xD9, 0x8C, 0x67, 0x49, 0x53, 0x59, 0xD3,
  35927. 0x7D, 0x67, 0xF7, 0x43, 0x8B, 0xEE, 0x5E, 0x43,
  35928. 0x58, 0x56, 0x34, 0xB2, 0x6C, 0x6B, 0x38, 0x10,
  35929. 0xD7, 0xCD, 0xCB, 0xC0, 0xF6, 0xEB, 0x87, 0x7A,
  35930. 0x60, 0x87, 0xE6, 0x8A, 0xCB, 0x84, 0x80, 0xD3,
  35931. 0xA8, 0xCF, 0x69, 0x00, 0x44, 0x7E, 0x49, 0xB4,
  35932. 0x17, 0xF1, 0x5A, 0x53, 0xB6, 0x07, 0xA0, 0xE2,
  35933. 0x16, 0xB8, 0x55, 0x97, 0x0D, 0x37, 0x40, 0x68,
  35934. 0x70, 0xB4, 0x56, 0x87, 0x22, 0xDA, 0x77, 0xA4,
  35935. 0x08, 0x47, 0x03, 0x81, 0x67, 0x84, 0xE2, 0xF1,
  35936. 0x6B, 0xED, 0x18, 0x99, 0x65, 0x32, 0xC5, 0xD8,
  35937. 0xB7, 0xF5, 0xD2, 0x14, 0x46, 0x4E, 0x5F, 0x3F,
  35938. 0x6E, 0x90, 0x58, 0x67, 0xB0, 0xCE, 0x11, 0x9E,
  35939. 0x25, 0x2A, 0x66, 0x71, 0x32, 0x53, 0x54, 0x46,
  35940. 0x85, 0xD2, 0x08, 0xE1, 0x72, 0x39, 0x08, 0xA0,
  35941. 0xCE, 0x97, 0x83, 0x46, 0x52, 0xE0, 0x8A, 0xE7,
  35942. 0xBD, 0xC8, 0x81, 0xA1, 0x31, 0xB7, 0x3C, 0x71,
  35943. 0xE8, 0x4D, 0x20, 0xD6, 0x8F, 0xDE, 0xFF, 0x4F,
  35944. 0x5D, 0x70, 0xCD, 0x1A, 0xF5, 0x7B, 0x78, 0xE3,
  35945. 0x49, 0x1A, 0x98, 0x65, 0x94, 0x23, 0x21, 0x80,
  35946. 0x0A, 0x20, 0x3C, 0x05, 0xED, 0x1F, 0xEE, 0xB5,
  35947. 0xA2, 0x8E, 0x58, 0x4E, 0x19, 0xF6, 0x53, 0x5E,
  35948. 0x7F, 0x84, 0xE4, 0xA2, 0x4F, 0x84, 0xA7, 0x2D,
  35949. 0xCA, 0xF5, 0x64, 0x8B, 0x4A, 0x42, 0x35, 0xDD,
  35950. 0x66, 0x44, 0x64, 0x48, 0x2F, 0x03, 0x17, 0x6E,
  35951. 0x88, 0x8C, 0x28, 0xBF, 0xC6, 0xC1, 0xCB, 0x23,
  35952. 0x8C, 0xFF, 0xA3, 0x5A, 0x32, 0x1E, 0x71, 0x79,
  35953. 0x1D, 0x9E, 0xA8, 0xED, 0x08, 0x78, 0xC6, 0x11,
  35954. 0x21, 0xBF, 0x8D, 0x2A, 0x4A, 0xB2, 0xC1, 0xA5,
  35955. 0xE1, 0x20, 0xBC, 0x40, 0xAB, 0xB1, 0x89, 0x2D,
  35956. 0x17, 0x15, 0x09, 0x0A, 0x0E, 0xE4, 0x82, 0x52,
  35957. 0xCA, 0x29, 0x7A, 0x99, 0xAA, 0x0E, 0x51, 0x0C,
  35958. 0xF2, 0x6B, 0x1A, 0xDD, 0x06, 0xCA, 0x54, 0x3E,
  35959. 0x1C, 0x5D, 0x6B, 0xDC, 0xD3, 0xB9, 0xC5, 0x85,
  35960. 0xC8, 0x53, 0x80, 0x45, 0xDB, 0x5C, 0x25, 0x2E,
  35961. 0xC3, 0xC8, 0xC3, 0xC9, 0x54, 0xD9, 0xBE, 0x59,
  35962. 0x07, 0x09, 0x4A, 0x89, 0x4E, 0x60, 0xEA, 0xB4,
  35963. 0x35, 0x38, 0xCF, 0xEE, 0x82, 0xE8, 0xFF, 0xC0,
  35964. 0x79, 0x1B, 0x0D, 0x0F, 0x43, 0xAC, 0x16, 0x27,
  35965. 0x83, 0x0A, 0x61, 0xD5, 0x6D, 0xAD, 0x96, 0xC6,
  35966. 0x29, 0x58, 0xB0, 0xDE, 0x78, 0x0B, 0x78, 0xBD,
  35967. 0x47, 0xA6, 0x04, 0x55, 0x0D, 0xAB, 0x83, 0xFF,
  35968. 0xF2, 0x27, 0xC3, 0x24, 0x04, 0x94, 0x71, 0xF3,
  35969. 0x52, 0x48, 0xCF, 0xB8, 0x49, 0xB2, 0x57, 0x24,
  35970. 0xFF, 0x70, 0x4D, 0x52, 0x77, 0xAA, 0x35, 0x2D,
  35971. 0x55, 0x09, 0x58, 0xBE, 0x3B, 0x23, 0x7D, 0xFF,
  35972. 0x47, 0x3E, 0xC2, 0xAD, 0xBA, 0xEA, 0x48, 0xCA,
  35973. 0x26, 0x58, 0xAE, 0xFC, 0xC7, 0x7B, 0xBD, 0x42,
  35974. 0x64, 0xAB, 0x37, 0x4D, 0x70, 0xEA, 0xE5, 0xB9,
  35975. 0x64, 0x41, 0x6C, 0xE8, 0x22, 0x6A, 0x7E, 0x32,
  35976. 0x55, 0xA0, 0xF8, 0xD7, 0xE2, 0xAD, 0xCA, 0x06,
  35977. 0x2B, 0xCD, 0x6D, 0x78, 0xD6, 0x0D, 0x1B, 0x32,
  35978. 0xE1, 0x14, 0x05, 0xBE, 0x54, 0xB6, 0x6E, 0xF0,
  35979. 0xFD, 0xDD, 0x56, 0x77, 0x02, 0xA3, 0xBC, 0xCF,
  35980. 0xED, 0xE3, 0xC5, 0x84, 0x70, 0x12, 0x69, 0xED,
  35981. 0x14, 0x80, 0x9F, 0x06, 0xF8, 0x96, 0x83, 0x56,
  35982. 0xBB, 0x92, 0x67, 0xFE, 0x86, 0xE5, 0x14, 0x25,
  35983. 0x2E, 0x88, 0xBB, 0x5C, 0x30, 0xA7, 0xEC, 0xB3,
  35984. 0xD0, 0xE6, 0x21, 0x02, 0x1E, 0xE0, 0xFB, 0xF7,
  35985. 0x87, 0x1B, 0x09, 0x34, 0x2B, 0xF8, 0x4F, 0x55,
  35986. 0xC9, 0x7E, 0xAF, 0x86, 0xC4, 0x81, 0x89, 0xC7,
  35987. 0xFF, 0x4D, 0xF3, 0x89, 0xF0, 0x77, 0xE2, 0x80,
  35988. 0x6E, 0x5F, 0xA7, 0x3B, 0x3E, 0x94, 0x58, 0xA1,
  35989. 0x6C, 0x7E, 0x27, 0x5F, 0x4F, 0x60, 0x22, 0x75,
  35990. 0x58, 0x0E, 0xB7, 0xB7, 0x13, 0x5F, 0xB5, 0x37,
  35991. 0xFA, 0x0C, 0xD9, 0x5D, 0x6E, 0xA5, 0x8C, 0x10,
  35992. 0x8C, 0xD8, 0x94, 0x3D, 0x70, 0xC1, 0x64, 0x31,
  35993. 0x11, 0xF4, 0xF0, 0x1C, 0xA8, 0xA8, 0x27, 0x6A,
  35994. 0x90, 0x26, 0x66, 0xED, 0x81, 0xB7, 0x8D, 0x16,
  35995. 0x8B, 0x00, 0x6F, 0x16, 0xAA, 0xA3, 0xD8, 0xE4,
  35996. 0xCE, 0x4F, 0x4D, 0x0F, 0xB0, 0x99, 0x7E, 0x41,
  35997. 0xAE, 0xFF, 0xB5, 0xB3, 0xDA, 0xA8, 0x38, 0x73,
  35998. 0x2F, 0x35, 0x73, 0x49, 0x44, 0x7F, 0x38, 0x77,
  35999. 0x76, 0xC7, 0x93, 0xC0, 0x47, 0x9D, 0xE9, 0xE9,
  36000. 0x94, 0x98, 0xCC, 0x35, 0x6F, 0xDB, 0x00, 0x75,
  36001. 0xA7, 0x03, 0xF2, 0x3C, 0x55, 0xD4, 0x7B, 0x55,
  36002. 0x0E, 0xC8, 0x9B, 0x02, 0xAD, 0xE8, 0x93, 0x29,
  36003. 0x08, 0x6A, 0x50, 0x84, 0x34, 0x56, 0xFE, 0xDC,
  36004. 0x37, 0x88, 0xAC, 0x8D, 0x97, 0x23, 0x3C, 0x54,
  36005. 0x56, 0x04, 0x67, 0xEE, 0x1D, 0x0F, 0x02, 0x4B,
  36006. 0x18, 0x42, 0x8F, 0x0D, 0x73, 0xB3, 0x0E, 0x19,
  36007. 0xF5, 0xC6, 0x3B, 0x9A, 0xBF, 0x11, 0x41, 0x5B,
  36008. 0xEA, 0x4D, 0x01, 0x70, 0x13, 0x0B, 0xAA, 0xBD,
  36009. 0x33, 0xC0, 0x5E, 0x65, 0x24, 0xE5, 0xFB, 0x55,
  36010. 0x81, 0xB2, 0x2B, 0x04, 0x33, 0x34, 0x22, 0x48,
  36011. 0x26, 0x6D, 0x0F, 0x10, 0x53, 0xB2, 0x45, 0xCC,
  36012. 0x24, 0x62, 0xDC, 0x44, 0xD3, 0x49, 0x65, 0x10,
  36013. 0x24, 0x82, 0xA8, 0xED, 0x9E, 0x4E, 0x96, 0x4D,
  36014. 0x56, 0x83, 0xE5, 0xD4, 0x5D, 0x0C, 0x82, 0x69
  36015. #else
  36016. 0xc8, 0x39, 0x10, 0x85, 0xb8, 0xd3, 0xea, 0x97,
  36017. 0x94, 0x21, 0x25, 0x41, 0xb2, 0x91, 0x4f, 0x08,
  36018. 0x96, 0x4d, 0x33, 0x52, 0x1d, 0x3f, 0x67, 0xad,
  36019. 0x66, 0x09, 0x6e, 0xbf, 0xb1, 0xf7, 0x06, 0x42,
  36020. 0x4b, 0x49, 0x55, 0x8f, 0x75, 0x5b, 0x56, 0x25,
  36021. 0xba, 0xe2, 0x36, 0xf2, 0xe0, 0x07, 0x96, 0x01,
  36022. 0xc7, 0x66, 0xf7, 0xd9, 0x60, 0x80, 0x8f, 0x7e,
  36023. 0x2b, 0xb0, 0xc7, 0xa5, 0xe0, 0x66, 0xed, 0x34,
  36024. 0x6d, 0xe6, 0x28, 0xf8, 0xc5, 0x7e, 0xeb, 0xab,
  36025. 0xbb, 0x0c, 0x22, 0xd9, 0x11, 0x54, 0x84, 0x63,
  36026. 0x69, 0x3e, 0xf3, 0xce, 0x52, 0xa5, 0x3f, 0x7f,
  36027. 0xf4, 0x15, 0xf0, 0x0e, 0x65, 0x7a, 0xe1, 0xc5,
  36028. 0xa4, 0x8f, 0xa5, 0xec, 0x6e, 0x4b, 0xe5, 0xcf,
  36029. 0x46, 0x2d, 0xaf, 0xfc, 0x84, 0xd2, 0xf6, 0xd5,
  36030. 0xff, 0x55, 0xdc, 0x9b, 0xbe, 0x8b, 0xb0, 0xd7,
  36031. 0x25, 0xec, 0x64, 0xfd, 0x4c, 0xd4, 0xbd, 0x8d,
  36032. 0xba, 0x0a, 0x84, 0x4e, 0x8b, 0x5c, 0xe4, 0xb6,
  36033. 0xa2, 0x89, 0x34, 0xd7, 0xf7, 0xa0, 0x50, 0x99,
  36034. 0x1f, 0xe1, 0x85, 0xb5, 0x06, 0xb4, 0x51, 0xda,
  36035. 0xbf, 0xad, 0x52, 0xd5, 0x2c, 0xb2, 0x11, 0x4c,
  36036. 0xa7, 0xd9, 0xa5, 0xcf, 0x98, 0x6c, 0x8f, 0xdc,
  36037. 0x1b, 0xc1, 0x0e, 0xc0, 0xc1, 0x86, 0x9e, 0x50,
  36038. 0xc0, 0x3c, 0x55, 0xa7, 0x61, 0x92, 0xa1, 0x04,
  36039. 0x9a, 0xca, 0x63, 0x6b, 0xa9, 0x02, 0x0b, 0xda,
  36040. 0xa8, 0xd0, 0xf5, 0x8c, 0x76, 0x3b, 0x0b, 0x89,
  36041. 0x84, 0x5c, 0xa0, 0x6d, 0x4c, 0x4d, 0xdc, 0x21,
  36042. 0x43, 0x3e, 0x16, 0xb9, 0xc6, 0x2e, 0x44, 0x87,
  36043. 0x1f, 0xdb, 0xc0, 0x5b, 0xa2, 0x18, 0xaf, 0x87,
  36044. 0x1f, 0xdd, 0x7d, 0xcf, 0xa4, 0x64, 0xe6, 0x0f,
  36045. 0xaa, 0x52, 0x65, 0x26, 0x4c, 0xe1, 0x39, 0x1b,
  36046. 0xd9, 0xa8, 0xc5, 0xfa, 0xa7, 0x62, 0x6d, 0x5f,
  36047. 0x15, 0x9b, 0x98, 0x05, 0xb9, 0x75, 0x71, 0x0a,
  36048. 0x35, 0x03, 0xa0, 0xb8, 0x58, 0xa1, 0x1c, 0x6a,
  36049. 0x64, 0x7c, 0xc0, 0xe1, 0x9a, 0xc8, 0x8b, 0x1b,
  36050. 0xe9, 0x05, 0x6c, 0x95, 0xb4, 0xd2, 0x08, 0x7d,
  36051. 0x09, 0x51, 0xd1, 0xd2, 0xf4, 0x99, 0x24, 0x91,
  36052. 0x11, 0x7e, 0x63, 0x47, 0x79, 0x4b, 0xa5, 0x45,
  36053. 0x71, 0xec, 0x49, 0xbb, 0xa7, 0x1a, 0xf3, 0x41,
  36054. 0x3d, 0x38, 0xa3, 0x0b, 0xf5, 0x87, 0x22, 0x48,
  36055. 0xd1, 0xf6, 0xd0, 0x7c, 0x86, 0xba, 0xf7, 0x82,
  36056. 0xe7, 0x3d, 0x26, 0x37, 0xf0, 0x43, 0xd3, 0x41,
  36057. 0xa0, 0x09, 0x21, 0x85, 0x7d, 0x8b, 0x21, 0xdd,
  36058. 0xf3, 0xe1, 0xd6, 0x31, 0x00, 0x36, 0xed, 0x27,
  36059. 0xaf, 0x49, 0xe5, 0xde, 0x1b, 0x90, 0x0f, 0xe4,
  36060. 0xde, 0x79, 0x80, 0x8f, 0xf2, 0x9f, 0x95, 0x70,
  36061. 0x85, 0x96, 0x12, 0xb1, 0x5a, 0xdc, 0x01, 0xfb,
  36062. 0xb2, 0x65, 0xb3, 0x05, 0xb1, 0xe3, 0xa1, 0x2a,
  36063. 0xe4, 0x19, 0xda, 0x5b, 0x74, 0x26, 0x1f, 0xa2,
  36064. 0x84, 0xc1, 0x01, 0xda, 0x3d, 0x8d, 0xca, 0x8b,
  36065. 0x2e, 0x45, 0x21, 0xac, 0xa5, 0x71, 0xef, 0x44,
  36066. 0xa0, 0x58, 0xe8, 0x44, 0xff, 0x32, 0xb1, 0x6d,
  36067. 0x5a, 0xae, 0xa0, 0x5f, 0x7f, 0x3a, 0xf8, 0xe2,
  36068. 0xab, 0x16, 0x22, 0x2e, 0x34, 0x76, 0x62, 0xed,
  36069. 0xdf, 0xb8, 0x91, 0xd0, 0xec, 0xc2, 0xa5, 0x5c,
  36070. 0x56, 0x38, 0xf9, 0xdd, 0xe9, 0x2d, 0x9a, 0x3d,
  36071. 0x54, 0x4a, 0x5f, 0x90, 0x1a, 0xc5, 0x01, 0xac,
  36072. 0xd1, 0xea, 0x6a, 0x01, 0x02, 0x01, 0xfc, 0xb1,
  36073. 0x0a, 0xd7, 0x02, 0xc4, 0x25, 0xa9, 0x4b, 0xdf,
  36074. 0x58, 0x90, 0xd5, 0x00, 0xa2, 0xa1, 0x47, 0xee,
  36075. 0xe1, 0xd1, 0xfc, 0xba, 0x8c, 0x3a, 0xbe, 0x7c,
  36076. 0x2d, 0xfe, 0x70, 0xf3, 0x46, 0xf0, 0x33, 0xd8,
  36077. 0x16, 0xa0, 0xb2, 0x79, 0x1b, 0x4f, 0x0b, 0x2d,
  36078. 0x95, 0x6d, 0x9e, 0xe5, 0x97, 0x17, 0x15, 0x39,
  36079. 0x9a, 0x56, 0x88, 0x30, 0x24, 0x95, 0xe2, 0xe0,
  36080. 0x7c, 0x1c, 0x8c, 0x01, 0x52, 0x71, 0x84, 0xbc,
  36081. 0xd0, 0xc2, 0x08, 0xbc, 0x15, 0x9f, 0x2e, 0x13,
  36082. 0x31, 0x8c, 0x0b, 0xb3, 0xdd, 0x24, 0xa6, 0xa7,
  36083. 0xfc, 0x84, 0x9f, 0x83, 0x38, 0x5e, 0xd4, 0xdb,
  36084. 0xa0, 0x7f, 0xe1, 0xd7, 0xbd, 0x56, 0x40, 0xcc,
  36085. 0x9e, 0xd5, 0xcc, 0xfd, 0xd6, 0x87, 0x63, 0xcb,
  36086. 0x0d, 0x0e, 0xdf, 0x61, 0xb2, 0x92, 0x17, 0x7f,
  36087. 0xc1, 0xd2, 0xd3, 0xc1, 0x1d, 0xd0, 0x49, 0x50,
  36088. 0x56, 0xbc, 0xb1, 0x25, 0x58, 0xae, 0xbc, 0xfd,
  36089. 0xde, 0xf9, 0xfe, 0xb4, 0xae, 0xbc, 0x57, 0xaf,
  36090. 0xd9, 0x02, 0x3c, 0x65, 0xcf, 0xe6, 0x5a, 0x24,
  36091. 0xe3, 0x3f, 0x1b, 0x00, 0x11, 0x1e, 0x92, 0xe6,
  36092. 0x3e, 0x01, 0x1e, 0xaf, 0x0b, 0x21, 0x2c, 0xf9,
  36093. 0x57, 0x43, 0xcd, 0x07, 0xf5, 0x18, 0x9e, 0xce,
  36094. 0x1f, 0x20, 0x5b, 0x7f, 0x6f, 0xcb, 0x2e, 0x6b,
  36095. 0x19, 0x61, 0xb5, 0x40, 0x4c, 0xeb, 0xe4, 0x7c,
  36096. 0x8c, 0xd1, 0x3b, 0x85, 0x99, 0xd5, 0xb4, 0x9e,
  36097. 0x6d, 0x87, 0xee, 0xda, 0x36, 0xe9, 0xb8, 0xfc,
  36098. 0x4c, 0x00, 0x63, 0x58, 0x96, 0xaa, 0x2b, 0x75,
  36099. 0x89, 0x6e, 0x33, 0x6d, 0x1b, 0x61, 0x2e, 0xe1,
  36100. 0x3d, 0xb8, 0x11, 0xe1, 0xf0, 0x7e, 0x61, 0x74,
  36101. 0x8d, 0x92, 0x0f, 0x48, 0x65, 0xf3, 0xf1, 0x17,
  36102. 0x41, 0x39, 0x9d, 0xc6, 0x16, 0x2c, 0x91, 0xca,
  36103. 0x16, 0x8a, 0x02, 0x32, 0x9d, 0xff, 0x82, 0x1d,
  36104. 0x58, 0x19, 0x87, 0x12, 0xdd, 0x55, 0x8a, 0xbb,
  36105. 0x09, 0x9b, 0x3a, 0x0b, 0xaf, 0x9d, 0xa1, 0xb7,
  36106. 0x30, 0xb2, 0xaa, 0x73, 0xbc, 0xf5, 0x8d, 0x74,
  36107. 0xf3, 0x57, 0xb0, 0x6f, 0x72, 0x11, 0xc8, 0x04,
  36108. 0xb6, 0xc8, 0xaf, 0x16, 0xff, 0x35, 0x09, 0xfa,
  36109. 0xd1, 0xd3, 0x5b, 0x14, 0xbf, 0xdc, 0xed, 0x7d,
  36110. 0xb8, 0xa6, 0xa2, 0x5c, 0x48, 0xe5, 0x95, 0x64,
  36111. 0x80, 0x72, 0x4d, 0xaa, 0x05, 0x7c, 0xd6, 0x60,
  36112. 0xb6, 0x7e, 0xe3, 0xe4, 0x72, 0x57, 0x41, 0x82,
  36113. 0x67, 0x9d, 0x48, 0x58, 0x38, 0xa6, 0x47, 0x6e,
  36114. 0xac, 0x02, 0x14, 0x10, 0x75, 0xc8, 0x12, 0xaf,
  36115. 0x79, 0x67, 0xba, 0x7c, 0x91, 0x85, 0xcc, 0x2a,
  36116. 0xbd, 0x2a, 0x45, 0x45, 0xb8, 0x0f, 0x3d, 0x31,
  36117. 0x04, 0xd5, 0x8d, 0x65, 0x4a, 0x57, 0x79, 0x2d,
  36118. 0xcf, 0xab, 0xbe, 0x9c, 0x07, 0x15, 0xe8, 0xde,
  36119. 0x2e, 0xf8, 0x1e, 0xf4, 0x04, 0xc8, 0x16, 0x8f,
  36120. 0xd7, 0xa4, 0x3e, 0xfa, 0xb3, 0xd4, 0x48, 0xe6,
  36121. 0x86, 0xa0, 0x88, 0xef, 0xd2, 0x6a, 0x26, 0x15,
  36122. 0x99, 0x48, 0x92, 0x67, 0x23, 0xd7, 0xec, 0xcc,
  36123. 0x39, 0xe3, 0xc1, 0xb7, 0x19, 0xcf, 0x8b, 0xec,
  36124. 0xb7, 0xbe, 0x7e, 0x96, 0x4f, 0x22, 0xcd, 0x8c,
  36125. 0xb1, 0xb7, 0xe2, 0x5e, 0x80, 0x0e, 0xa9, 0x7d,
  36126. 0x60, 0xa6, 0x4c, 0xc0, 0xbb, 0xd9, 0xcb, 0x40,
  36127. 0x7a, 0x3a, 0xb9, 0xf8, 0x8f, 0x5e, 0x29, 0x16,
  36128. 0x9e, 0xea, 0xfd, 0x4e, 0x03, 0x22, 0xfd, 0xe6,
  36129. 0x59, 0x0a, 0xe0, 0x93, 0xce, 0x8f, 0xee, 0xae,
  36130. 0x98, 0xb6, 0x22, 0xca, 0xa7, 0x55, 0x6f, 0xf4,
  36131. 0x26, 0xc9, 0xe7, 0xa4, 0x04, 0xce, 0x69, 0x35,
  36132. 0x58, 0x30, 0xa7, 0xa6, 0x77, 0x67, 0xa7, 0x6c,
  36133. 0x7d, 0x9a, 0x97, 0xb8, 0x4b, 0xfc, 0xf5, 0x0a,
  36134. 0x02, 0xf7, 0x5c, 0x23, 0x5d, 0x2f, 0x9c, 0x67,
  36135. 0x11, 0x38, 0x04, 0x9f, 0xfc, 0x7c, 0x80, 0x55,
  36136. 0x92, 0x6c, 0x03, 0xeb, 0x3f, 0xb8, 0x7f, 0x96,
  36137. 0x95, 0x18, 0x5a, 0x42, 0xec, 0xa9, 0xa4, 0x16,
  36138. 0x55, 0x87, 0x3d, 0x30, 0xa6, 0xb3, 0xbf, 0x42,
  36139. 0x8b, 0x24, 0x62, 0x23, 0x48, 0x4a, 0x8f, 0xf6,
  36140. 0x1e, 0xe3, 0xee, 0xaf, 0xff, 0x10, 0xe9, 0x9c,
  36141. 0x2c, 0x13, 0xa7, 0x62, 0x84, 0xd0, 0x63, 0xe5,
  36142. 0x6a, 0xb7, 0x11, 0xa3, 0x5a, 0x85, 0xb5, 0x38,
  36143. 0x3d, 0xf8, 0x1d, 0xa2, 0x34, 0x90, 0xf6, 0x6e,
  36144. 0x8e, 0xa3, 0xfc, 0xba, 0x06, 0x7f, 0x55, 0x30,
  36145. 0xc6, 0x54, 0x1c, 0x2b, 0x8f, 0x74, 0x71, 0x7c,
  36146. 0x35, 0x02, 0x3e, 0x7b, 0x9b, 0x39, 0x56, 0xc3,
  36147. 0xee, 0x2f, 0xf8, 0x4b, 0xa0, 0x3c, 0xcf, 0x4b,
  36148. 0x4b, 0x53, 0x21, 0xb9, 0x24, 0x08, 0x95, 0x48,
  36149. 0x1b, 0xc6, 0xd6, 0x3c, 0x16, 0x93, 0xc1, 0x84,
  36150. 0x78, 0x52, 0xf8, 0xe9, 0x7f, 0x50, 0xa1, 0x33,
  36151. 0x53, 0x2a, 0xc3, 0xee, 0x1e, 0x52, 0xd4, 0x64
  36152. #endif
  36153. };
  36154. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ss[] = {
  36155. #ifdef WOLFSSL_KYBER_ORIGINAL
  36156. 0x91, 0x4C, 0xB6, 0x7F, 0xE5, 0xC3, 0x8E, 0x73,
  36157. 0xBF, 0x74, 0x18, 0x1C, 0x0A, 0xC5, 0x04, 0x28,
  36158. 0xDE, 0xDF, 0x77, 0x50, 0xA9, 0x80, 0x58, 0xF7,
  36159. 0xD5, 0x36, 0x70, 0x87, 0x74, 0x53, 0x5B, 0x29
  36160. #else
  36161. 0xe7, 0x18, 0x4a, 0x09, 0x75, 0xee, 0x34, 0x70,
  36162. 0x87, 0x8d, 0x2d, 0x15, 0x9e, 0xc8, 0x31, 0x29,
  36163. 0xc8, 0xae, 0xc2, 0x53, 0xd4, 0xee, 0x17, 0xb4,
  36164. 0x81, 0x03, 0x11, 0xd1, 0x98, 0xcd, 0x03, 0x68
  36165. #endif
  36166. };
  36167. #ifdef WOLFSSL_SMALL_STACK
  36168. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  36169. DYNAMIC_TYPE_TMP_BUFFER);
  36170. priv = (byte *)XMALLOC(KYBER768_PRIVATE_KEY_SIZE, HEAP_HINT,
  36171. DYNAMIC_TYPE_TMP_BUFFER);
  36172. pub = (byte *)XMALLOC(KYBER768_PUBLIC_KEY_SIZE, HEAP_HINT,
  36173. DYNAMIC_TYPE_TMP_BUFFER);
  36174. ct = (byte *)XMALLOC(KYBER768_CIPHER_TEXT_SIZE, HEAP_HINT,
  36175. DYNAMIC_TYPE_TMP_BUFFER);
  36176. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36177. DYNAMIC_TYPE_TMP_BUFFER);
  36178. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36179. DYNAMIC_TYPE_TMP_BUFFER);
  36180. if (! (key && priv && pub && ct && ss && ss_dec))
  36181. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  36182. #endif
  36183. ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
  36184. if (ret != 0)
  36185. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36186. else
  36187. key_inited = 1;
  36188. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36189. sizeof(kyber768_rand));
  36190. if (ret != 0)
  36191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36192. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
  36193. if (ret != 0)
  36194. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36195. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
  36196. if (ret != 0)
  36197. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36198. if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0)
  36199. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36200. if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
  36201. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36202. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36203. sizeof(kyber768enc_rand));
  36204. if (ret != 0)
  36205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36206. if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0)
  36207. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36208. if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36209. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36210. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
  36211. if (ret != 0)
  36212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36213. if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36214. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36215. out:
  36216. if (key_inited)
  36217. wc_KyberKey_Free(key);
  36218. #ifdef WOLFSSL_SMALL_STACK
  36219. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36220. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36221. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36222. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36223. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36224. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36225. #endif
  36226. return ret;
  36227. }
  36228. #endif /* WOLFSSL_KYBER768 */
  36229. #ifdef WOLFSSL_KYBER1024
  36230. static wc_test_ret_t kyber1024_kat(void)
  36231. {
  36232. wc_test_ret_t ret;
  36233. #ifdef WOLFSSL_SMALL_STACK
  36234. KyberKey *key = NULL;
  36235. byte *priv = NULL;
  36236. byte *pub = NULL;
  36237. byte *ct = NULL;
  36238. byte *ss = NULL;
  36239. byte *ss_dec = NULL;
  36240. #else
  36241. KyberKey key[1];
  36242. byte priv[KYBER1024_PRIVATE_KEY_SIZE];
  36243. byte pub[KYBER1024_PUBLIC_KEY_SIZE];
  36244. byte ct[KYBER1024_CIPHER_TEXT_SIZE];
  36245. byte ss[KYBER_SS_SZ];
  36246. byte ss_dec[KYBER_SS_SZ];
  36247. #endif
  36248. int key_inited = 0;
  36249. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_rand[] = {
  36250. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  36251. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  36252. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  36253. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  36254. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  36255. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  36256. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  36257. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  36258. };
  36259. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024enc_rand[] = {
  36260. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  36261. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  36262. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  36263. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  36264. };
  36265. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_pk[] = {
  36266. #ifdef WOLFSSL_KYBER_ORIGINAL
  36267. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36268. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36269. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36270. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36271. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36272. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36273. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36274. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36275. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36276. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36277. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36278. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36279. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36280. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36281. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36282. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36283. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36284. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36285. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36286. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36287. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36288. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36289. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36290. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36291. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36292. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36293. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36294. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36295. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36296. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36297. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36298. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36299. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36300. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36301. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36302. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36303. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36304. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36305. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36306. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36307. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36308. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36309. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36310. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36311. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36312. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36313. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36314. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36315. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36316. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36317. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36318. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36319. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36320. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36321. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36322. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36323. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36324. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36325. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36326. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36327. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36328. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36329. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36330. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36331. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36332. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36333. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36334. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36335. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36336. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36337. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36338. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36339. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36340. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36341. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36342. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36343. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36344. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36345. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36346. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36347. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36348. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36349. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36350. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36351. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36352. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36353. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36354. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36355. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36356. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36357. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36358. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36359. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36360. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36361. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36362. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36363. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36364. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36365. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36366. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36367. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36368. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36369. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36370. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36371. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36372. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36373. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36374. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36375. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36376. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36377. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36378. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36379. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36380. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36381. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36382. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36383. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36384. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36385. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36386. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36387. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36388. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36389. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36390. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36391. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36392. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36393. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36394. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36395. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36396. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36397. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36398. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36399. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36400. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36401. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36402. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36403. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36404. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36405. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36406. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36407. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36408. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36409. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36410. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36411. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36412. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36413. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36414. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36415. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36416. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36417. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36418. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36419. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36420. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36421. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36422. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36423. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36424. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36425. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36426. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36427. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36428. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36429. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36430. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36431. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36432. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36433. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36434. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36435. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36436. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36437. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36438. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36439. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36440. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36441. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36442. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36443. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36444. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36445. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36446. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36447. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36448. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36449. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36450. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36451. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36452. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36453. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36454. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36455. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36456. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36457. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36458. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36459. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36460. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36461. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36462. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  36463. #else
  36464. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36465. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36466. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36467. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36468. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36469. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36470. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36471. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36472. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36473. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36474. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36475. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36476. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36477. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36478. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36479. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36480. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36481. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36482. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36483. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36484. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36485. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36486. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36487. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36488. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36489. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36490. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36491. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36492. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36493. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36494. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36495. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36496. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36497. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36498. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36499. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36500. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36501. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36502. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36503. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36504. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36505. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36506. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36507. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36508. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36509. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36510. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36511. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36512. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36513. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36514. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36515. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36516. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36517. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36518. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36519. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36520. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36521. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36522. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36523. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36524. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36525. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36526. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36527. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36528. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36529. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36530. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36531. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36532. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36533. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36534. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36535. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36536. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36537. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36538. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36539. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36540. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36541. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36542. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36543. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36544. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36545. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36546. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36547. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36548. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36549. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36550. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36551. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36552. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36553. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36554. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36555. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36556. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36557. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36558. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36559. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36560. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36561. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36562. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36563. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36564. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36565. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  36566. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  36567. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  36568. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  36569. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  36570. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  36571. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  36572. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  36573. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  36574. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  36575. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  36576. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  36577. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  36578. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  36579. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  36580. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  36581. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  36582. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  36583. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  36584. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  36585. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  36586. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  36587. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  36588. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  36589. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  36590. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  36591. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  36592. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  36593. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  36594. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  36595. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  36596. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  36597. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  36598. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  36599. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  36600. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  36601. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  36602. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  36603. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  36604. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  36605. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  36606. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  36607. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  36608. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  36609. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  36610. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  36611. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  36612. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  36613. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  36614. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  36615. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  36616. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  36617. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  36618. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  36619. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  36620. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  36621. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  36622. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  36623. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  36624. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  36625. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  36626. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  36627. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  36628. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  36629. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  36630. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  36631. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  36632. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  36633. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  36634. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  36635. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  36636. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  36637. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  36638. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  36639. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  36640. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  36641. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  36642. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  36643. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  36644. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  36645. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  36646. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  36647. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  36648. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  36649. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  36650. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  36651. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  36652. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  36653. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  36654. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  36655. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  36656. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  36657. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  36658. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  36659. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb
  36660. #endif
  36661. };
  36662. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_sk[] = {
  36663. #ifdef WOLFSSL_KYBER_ORIGINAL
  36664. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  36665. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  36666. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  36667. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  36668. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  36669. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  36670. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  36671. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  36672. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  36673. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  36674. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  36675. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  36676. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  36677. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  36678. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  36679. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  36680. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  36681. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  36682. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  36683. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  36684. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  36685. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  36686. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  36687. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  36688. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  36689. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  36690. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  36691. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  36692. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  36693. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  36694. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  36695. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  36696. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  36697. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  36698. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  36699. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  36700. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  36701. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  36702. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  36703. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  36704. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  36705. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  36706. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  36707. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  36708. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  36709. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  36710. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  36711. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  36712. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  36713. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  36714. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  36715. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  36716. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  36717. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  36718. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  36719. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  36720. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  36721. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  36722. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  36723. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  36724. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  36725. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  36726. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  36727. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  36728. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  36729. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  36730. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  36731. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  36732. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  36733. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  36734. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  36735. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  36736. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  36737. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  36738. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  36739. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  36740. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  36741. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  36742. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  36743. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  36744. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  36745. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  36746. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  36747. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  36748. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  36749. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  36750. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  36751. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  36752. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  36753. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  36754. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  36755. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  36756. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  36757. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  36758. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  36759. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  36760. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  36761. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  36762. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  36763. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  36764. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  36765. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  36766. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  36767. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  36768. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  36769. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  36770. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  36771. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  36772. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  36773. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  36774. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  36775. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  36776. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  36777. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  36778. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  36779. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  36780. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  36781. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  36782. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  36783. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  36784. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  36785. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  36786. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  36787. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  36788. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  36789. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  36790. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  36791. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  36792. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  36793. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  36794. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  36795. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  36796. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  36797. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  36798. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  36799. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  36800. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  36801. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  36802. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  36803. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  36804. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  36805. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  36806. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  36807. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  36808. 0x85, 0xA4, 0xC1, 0xA1, 0xAB, 0x9B, 0x6A, 0xEB,
  36809. 0x49, 0xCC, 0xE1, 0xC2, 0xF8, 0xA9, 0x7C, 0x35,
  36810. 0x16, 0xC7, 0x2A, 0x00, 0xA4, 0x62, 0x63, 0xBA,
  36811. 0xA6, 0x96, 0xBF, 0x25, 0x72, 0x77, 0x19, 0xC3,
  36812. 0x21, 0x64, 0x23, 0x61, 0x8F, 0xF3, 0x33, 0x80,
  36813. 0x93, 0x4A, 0x6C, 0x10, 0x54, 0x5C, 0x4C, 0x5C,
  36814. 0x51, 0x55, 0xB1, 0x24, 0x86, 0x18, 0x1F, 0xC7,
  36815. 0xA2, 0x31, 0x98, 0x73, 0x97, 0x8B, 0x6A, 0x2A,
  36816. 0x67, 0x49, 0x0F, 0x82, 0x56, 0xBD, 0x21, 0x96,
  36817. 0xFE, 0x17, 0x92, 0xA4, 0xC0, 0x00, 0x77, 0xB8,
  36818. 0x12, 0xEA, 0xE8, 0xBE, 0xD3, 0x57, 0x24, 0x99,
  36819. 0x68, 0x4A, 0xB3, 0x37, 0x18, 0x76, 0x76, 0x1E,
  36820. 0x45, 0x0C, 0x9F, 0x9D, 0x27, 0x68, 0xA3, 0x68,
  36821. 0x06, 0xD7, 0xAB, 0x20, 0x46, 0xC9, 0x1F, 0x17,
  36822. 0x59, 0x9E, 0x9A, 0xC5, 0x92, 0x99, 0x08, 0x08,
  36823. 0xDC, 0xD7, 0xB4, 0xD0, 0x91, 0x90, 0x72, 0xF1,
  36824. 0x4E, 0xC3, 0x61, 0x77, 0x3B, 0x72, 0x52, 0x44,
  36825. 0x4C, 0x32, 0x3C, 0x30, 0x83, 0x26, 0xF4, 0xA3,
  36826. 0x0F, 0x86, 0x80, 0xD2, 0xF7, 0x48, 0xF5, 0x6A,
  36827. 0x13, 0x2B, 0x82, 0x67, 0x4E, 0xD0, 0x18, 0x46,
  36828. 0x20, 0xB8, 0x2A, 0xD2, 0xCB, 0x18, 0x2C, 0x97,
  36829. 0xB4, 0x81, 0x62, 0x66, 0x47, 0x49, 0x12, 0x90,
  36830. 0xA0, 0x11, 0xCC, 0x73, 0x82, 0x86, 0x85, 0xA8,
  36831. 0xC3, 0x67, 0xA5, 0xB9, 0xCF, 0x8D, 0x62, 0x1B,
  36832. 0x0D, 0x5C, 0x1E, 0xFF, 0x03, 0x17, 0x27, 0x58,
  36833. 0xBD, 0x00, 0x49, 0x78, 0xC2, 0x51, 0xCD, 0x51,
  36834. 0x34, 0x22, 0x28, 0x98, 0x9C, 0xAE, 0x63, 0x32,
  36835. 0xAC, 0x48, 0x64, 0x37, 0xCB, 0x5C, 0x57, 0xD4,
  36836. 0x30, 0x74, 0x62, 0x86, 0x52, 0x53, 0xBE, 0x21,
  36837. 0x7B, 0x35, 0x15, 0xC7, 0x3D, 0xF4, 0x05, 0xB7,
  36838. 0xF2, 0x82, 0x17, 0xAD, 0x0B, 0x8C, 0xF6, 0x0C,
  36839. 0x2F, 0xFF, 0xAA, 0x0A, 0x00, 0x48, 0xB1, 0xFB,
  36840. 0x4A, 0xCD, 0xCD, 0xC3, 0x8B, 0x52, 0x50, 0xCF,
  36841. 0xEC, 0x35, 0x6A, 0x6D, 0xE2, 0x6C, 0xFA, 0x7A,
  36842. 0x58, 0x8F, 0xDC, 0x86, 0xF9, 0x8C, 0x85, 0x4A,
  36843. 0xC6, 0x4C, 0x7B, 0xFA, 0xA9, 0x6F, 0x5A, 0x32,
  36844. 0xCC, 0x06, 0x10, 0x93, 0x4B, 0xAA, 0x6A, 0x58,
  36845. 0x6B, 0x9A, 0x20, 0x54, 0xF1, 0x3B, 0xA2, 0x74,
  36846. 0x17, 0x4A, 0xA0, 0xD2, 0xB3, 0xA8, 0x1B, 0x96,
  36847. 0xA9, 0x40, 0x66, 0x6F, 0x78, 0x9B, 0x5A, 0x6B,
  36848. 0xCD, 0xC0, 0xA6, 0xA0, 0x17, 0x8A, 0x0C, 0x9A,
  36849. 0x02, 0x57, 0x8A, 0x49, 0x3F, 0x6E, 0xEA, 0x0D,
  36850. 0x2E, 0x6C, 0x13, 0x95, 0x1C, 0x9F, 0x24, 0x9A,
  36851. 0x5E, 0x8D, 0xD7, 0x1D, 0xD4, 0x9A, 0x74, 0x2D,
  36852. 0x45, 0x1F, 0x1A, 0xBB, 0xA1, 0x9A, 0xF8, 0xC5,
  36853. 0x47, 0x85, 0x5E, 0x0A, 0xFC, 0x72, 0x8E, 0x90,
  36854. 0xAB, 0xB4, 0x99, 0xC9, 0xBE, 0xEB, 0x76, 0x6F,
  36855. 0x47, 0x29, 0xCD, 0xA2, 0x22, 0x63, 0xE3, 0x24,
  36856. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36857. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36858. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36859. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36860. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36861. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36862. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36863. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36864. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36865. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36866. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36867. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36868. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36869. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36870. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36871. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36872. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36873. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36874. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36875. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36876. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36877. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36878. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36879. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36880. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36881. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36882. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36883. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36884. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36885. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36886. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36887. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36888. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36889. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36890. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36891. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36892. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36893. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36894. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36895. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36896. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36897. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36898. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36899. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36900. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36901. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36902. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36903. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36904. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36905. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36906. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36907. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36908. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36909. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36910. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36911. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36912. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36913. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36914. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36915. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36916. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36917. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36918. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36919. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36920. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36921. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36922. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36923. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36924. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36925. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36926. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36927. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36928. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36929. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36930. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36931. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36932. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36933. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36934. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36935. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36936. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36937. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36938. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36939. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36940. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36941. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36942. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36943. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36944. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36945. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36946. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36947. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36948. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36949. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36950. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36951. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36952. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36953. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36954. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36955. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36956. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36957. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36958. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36959. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36960. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36961. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36962. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36963. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36964. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36965. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36966. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36967. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36968. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36969. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36970. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36971. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36972. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36973. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36974. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36975. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36976. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36977. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36978. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36979. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36980. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36981. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36982. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36983. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36984. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36985. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36986. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36987. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36988. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36989. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36990. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36991. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36992. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36993. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36994. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36995. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36996. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36997. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36998. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36999. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  37000. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  37001. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  37002. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  37003. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  37004. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  37005. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  37006. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  37007. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  37008. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  37009. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  37010. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  37011. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  37012. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  37013. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  37014. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  37015. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  37016. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  37017. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  37018. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  37019. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  37020. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  37021. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  37022. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  37023. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  37024. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  37025. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  37026. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  37027. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  37028. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  37029. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  37030. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  37031. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  37032. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  37033. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  37034. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  37035. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  37036. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  37037. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  37038. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  37039. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  37040. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  37041. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  37042. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  37043. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  37044. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  37045. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  37046. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  37047. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  37048. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  37049. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  37050. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  37051. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  37052. 0x8A, 0x39, 0xE8, 0x7D, 0x53, 0x1F, 0x35, 0x27,
  37053. 0xC2, 0x07, 0xED, 0xCC, 0x1D, 0xB7, 0xFA, 0xDD,
  37054. 0xCF, 0x96, 0x28, 0x39, 0x18, 0x79, 0xB3, 0x35,
  37055. 0xC7, 0x07, 0x83, 0x9A, 0x0D, 0xB0, 0x51, 0xA8,
  37056. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  37057. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  37058. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  37059. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  37060. #else
  37061. 0x43, 0x3a, 0x70, 0xee, 0x69, 0x50, 0xf9, 0x88,
  37062. 0x2a, 0xcd, 0xd5, 0xa4, 0x78, 0x20, 0xa6, 0xa8,
  37063. 0x16, 0x37, 0x08, 0xf0, 0x4d, 0x45, 0x7c, 0x77,
  37064. 0x99, 0x79, 0xb8, 0x3f, 0xe1, 0x17, 0x22, 0x47,
  37065. 0x01, 0x49, 0x08, 0x30, 0x38, 0x66, 0x37, 0xda,
  37066. 0x33, 0x2e, 0x74, 0xb1, 0xae, 0xda, 0x0b, 0x2f,
  37067. 0x81, 0xca, 0x4f, 0x9b, 0xb2, 0xc2, 0xb0, 0x2b,
  37068. 0x0c, 0xfd, 0x68, 0x0c, 0x11, 0x48, 0x2f, 0x33,
  37069. 0x5a, 0xcf, 0x7b, 0x91, 0x39, 0xb5, 0xb8, 0x8a,
  37070. 0x34, 0xe3, 0x54, 0x2c, 0x68, 0x61, 0x37, 0x75,
  37071. 0x45, 0x98, 0x33, 0x43, 0xcd, 0x82, 0x94, 0x14,
  37072. 0xe4, 0x78, 0x64, 0x21, 0x2e, 0x78, 0xf8, 0x55,
  37073. 0xf5, 0x23, 0x90, 0x37, 0x9a, 0xcc, 0x3a, 0x62,
  37074. 0x95, 0x31, 0x31, 0xb6, 0x3e, 0xe8, 0x32, 0xad,
  37075. 0xb3, 0xbf, 0x4b, 0xf5, 0x8e, 0x24, 0x73, 0x49,
  37076. 0xb5, 0xe0, 0x97, 0xe5, 0x5a, 0xbe, 0x49, 0x7b,
  37077. 0x15, 0x98, 0x23, 0x73, 0xae, 0x73, 0x2e, 0x04,
  37078. 0x39, 0xac, 0x67, 0xd0, 0x5c, 0x7f, 0x03, 0x7c,
  37079. 0x8a, 0x73, 0x9b, 0x18, 0x14, 0x0e, 0x14, 0x4c,
  37080. 0x85, 0x1d, 0xc9, 0x61, 0x1f, 0x4b, 0xcf, 0x04,
  37081. 0xf3, 0xa2, 0x09, 0x3c, 0x19, 0x7b, 0xd6, 0x3b,
  37082. 0xb5, 0xe6, 0x19, 0x01, 0x00, 0x54, 0x5f, 0xf8,
  37083. 0x1d, 0xb7, 0xfc, 0xcd, 0xdd, 0x9a, 0x32, 0x4b,
  37084. 0x0b, 0xac, 0x3c, 0x2c, 0x23, 0x82, 0x28, 0x40,
  37085. 0x58, 0xf0, 0x8b, 0x96, 0x19, 0x52, 0xc0, 0x94,
  37086. 0x01, 0x9c, 0x10, 0xbe, 0x37, 0xa5, 0x3d, 0x5a,
  37087. 0xc7, 0x94, 0xc0, 0x10, 0xa9, 0xd0, 0x82, 0x1f,
  37088. 0x15, 0x02, 0x7a, 0x1c, 0x41, 0x9c, 0x3c, 0x71,
  37089. 0xc9, 0xa1, 0xd2, 0x8a, 0xed, 0x02, 0x59, 0x7a,
  37090. 0xb7, 0x9b, 0x87, 0x53, 0x94, 0x62, 0x6b, 0xa3,
  37091. 0x9a, 0xdc, 0x09, 0x0c, 0x3a, 0x90, 0xcf, 0x75,
  37092. 0x87, 0x1a, 0x65, 0x27, 0x5e, 0xb1, 0xc5, 0xb0,
  37093. 0x33, 0x72, 0xe1, 0x3a, 0x1a, 0x23, 0xd0, 0xcf,
  37094. 0x93, 0x74, 0x11, 0x1f, 0x80, 0xcc, 0x83, 0xa9,
  37095. 0x05, 0x62, 0x2b, 0x83, 0xfc, 0x51, 0x39, 0x71,
  37096. 0xec, 0x84, 0x19, 0xf0, 0x88, 0x0c, 0x30, 0x67,
  37097. 0x63, 0x36, 0x71, 0xb0, 0x9b, 0x54, 0x56, 0xab,
  37098. 0x60, 0x57, 0x93, 0x6d, 0x19, 0xa4, 0xa2, 0xa2,
  37099. 0x67, 0x91, 0x1b, 0x00, 0x0a, 0x13, 0x95, 0x6f,
  37100. 0xbd, 0x49, 0x38, 0x21, 0xda, 0x07, 0x2c, 0x04,
  37101. 0x64, 0x2b, 0x0c, 0x20, 0xda, 0x6c, 0xc0, 0xd9,
  37102. 0xd8, 0x64, 0xa3, 0x93, 0x65, 0xdf, 0xd6, 0x4f,
  37103. 0x10, 0x18, 0x78, 0x25, 0xfa, 0x33, 0x25, 0x07,
  37104. 0x49, 0xcb, 0xc0, 0xc9, 0x05, 0xd7, 0xb1, 0xff,
  37105. 0x3c, 0xae, 0x24, 0x12, 0xbf, 0x86, 0xb8, 0x1a,
  37106. 0x81, 0x7b, 0x86, 0xba, 0xa3, 0x0e, 0xdf, 0x78,
  37107. 0x62, 0xe5, 0xf6, 0xba, 0xc9, 0x87, 0x26, 0xe5,
  37108. 0x6b, 0x3c, 0xec, 0x60, 0x66, 0x4c, 0xaa, 0x2a,
  37109. 0x7d, 0xf6, 0x70, 0xc5, 0xe2, 0x07, 0xdf, 0xac,
  37110. 0x03, 0x82, 0x4c, 0x89, 0x89, 0x7c, 0xb4, 0x90,
  37111. 0xea, 0xa7, 0x65, 0x21, 0x22, 0x2c, 0x86, 0x20,
  37112. 0x51, 0x69, 0xc9, 0x1c, 0x32, 0x9c, 0x4a, 0x18,
  37113. 0x4d, 0x78, 0x72, 0x1a, 0xf8, 0x36, 0xad, 0x4d,
  37114. 0xb0, 0xca, 0x78, 0x46, 0x4d, 0x41, 0x71, 0x47,
  37115. 0x30, 0x12, 0xb7, 0xd1, 0x83, 0xba, 0xfa, 0x62,
  37116. 0x75, 0x85, 0xc6, 0x4b, 0xe3, 0x80, 0x9d, 0x7e,
  37117. 0x60, 0x04, 0xcb, 0xdc, 0x79, 0xa5, 0x46, 0x0f,
  37118. 0x0a, 0xd6, 0x77, 0xcb, 0x71, 0x65, 0x12, 0x40,
  37119. 0x7d, 0x3a, 0x61, 0x9a, 0xd0, 0x95, 0x43, 0xb7,
  37120. 0x39, 0x54, 0x74, 0x72, 0xa7, 0x06, 0xb3, 0x17,
  37121. 0xa5, 0x09, 0xbe, 0x5d, 0x86, 0x1f, 0xd6, 0x6c,
  37122. 0x7d, 0x0e, 0xd9, 0x4c, 0xd5, 0x00, 0x47, 0x95,
  37123. 0xc1, 0x81, 0x59, 0xe3, 0xa3, 0x3d, 0x79, 0x87,
  37124. 0x11, 0x52, 0x5f, 0x16, 0x35, 0xa6, 0x84, 0x28,
  37125. 0x17, 0x29, 0x23, 0x24, 0x96, 0x35, 0xaa, 0xd0,
  37126. 0x32, 0xb9, 0xe5, 0x66, 0x64, 0xbd, 0xd4, 0x8e,
  37127. 0xd2, 0x4a, 0xc7, 0x5c, 0x64, 0x68, 0xd1, 0x90,
  37128. 0x3e, 0x47, 0x10, 0x86, 0xc5, 0xf1, 0x56, 0x7e,
  37129. 0x83, 0x1a, 0x05, 0x08, 0xc5, 0x39, 0x63, 0x25,
  37130. 0x91, 0xab, 0x57, 0x7d, 0x32, 0x4a, 0x82, 0x42,
  37131. 0x97, 0x25, 0x80, 0x99, 0x50, 0x76, 0x1d, 0x84,
  37132. 0x34, 0x28, 0x8c, 0x14, 0x03, 0x4f, 0x1c, 0x06,
  37133. 0xc1, 0xd0, 0xaa, 0xe0, 0x9a, 0x71, 0xc7, 0x40,
  37134. 0xa5, 0x57, 0x01, 0xc2, 0x8f, 0xf8, 0x44, 0x99,
  37135. 0xf2, 0xbb, 0x18, 0xb6, 0x62, 0x8c, 0xaa, 0xa3,
  37136. 0xfe, 0x75, 0xac, 0x4d, 0xe0, 0x4c, 0x6f, 0x91,
  37137. 0x39, 0x00, 0xd8, 0x6c, 0x88, 0x12, 0x62, 0x52,
  37138. 0xa1, 0x7c, 0x4d, 0x30, 0x39, 0x91, 0xdb, 0x02,
  37139. 0x87, 0x12, 0x08, 0x81, 0xbb, 0x88, 0x47, 0x8a,
  37140. 0xaa, 0x9a, 0xf9, 0xbc, 0x53, 0xd3, 0x72, 0x98,
  37141. 0x43, 0x85, 0x8f, 0xdb, 0x46, 0x48, 0x05, 0x9c,
  37142. 0xac, 0x82, 0xc1, 0xa1, 0x08, 0x78, 0xba, 0x39,
  37143. 0x82, 0x3b, 0x04, 0x1b, 0xd0, 0xe2, 0x58, 0x48,
  37144. 0x7b, 0x56, 0xcc, 0x8a, 0x32, 0x20, 0xc1, 0xa5,
  37145. 0x8b, 0xf6, 0x6a, 0x17, 0x2b, 0x5b, 0x9a, 0x0c,
  37146. 0x63, 0x2d, 0x67, 0x4e, 0xae, 0x88, 0x5a, 0x01,
  37147. 0x5c, 0x4e, 0x37, 0xba, 0x07, 0x36, 0x80, 0xbe,
  37148. 0xde, 0x75, 0x34, 0xf3, 0xe3, 0x4b, 0x60, 0x50,
  37149. 0xc8, 0x6b, 0x21, 0xc3, 0xc0, 0x90, 0x94, 0x1f,
  37150. 0x23, 0xb7, 0xf6, 0x73, 0x1e, 0x2b, 0xda, 0x0e,
  37151. 0x6e, 0xa4, 0x64, 0x67, 0x71, 0xce, 0xc5, 0x72,
  37152. 0xb9, 0x8c, 0xa0, 0xa1, 0x58, 0x91, 0x9a, 0xdb,
  37153. 0xeb, 0x84, 0xce, 0x58, 0x5f, 0xf9, 0xf2, 0x5e,
  37154. 0xbd, 0xda, 0x6c, 0xb6, 0xf0, 0x7a, 0x8f, 0x81,
  37155. 0x12, 0x32, 0x60, 0x7e, 0x72, 0x17, 0xbb, 0x03,
  37156. 0x9b, 0xab, 0xd0, 0xd9, 0x19, 0x34, 0xa8, 0x59,
  37157. 0x40, 0x59, 0xc9, 0x68, 0x77, 0x23, 0xc0, 0x43,
  37158. 0x81, 0xbf, 0xd6, 0x27, 0xa1, 0x05, 0x17, 0xf5,
  37159. 0xf4, 0xbf, 0xc7, 0x77, 0x77, 0xaa, 0x26, 0x71,
  37160. 0xae, 0x12, 0x4f, 0x2b, 0x7a, 0x5f, 0x4d, 0x56,
  37161. 0x14, 0x02, 0x91, 0x97, 0xe6, 0x58, 0x6f, 0xa8,
  37162. 0xc1, 0x7e, 0x0a, 0xd9, 0x07, 0x81, 0xbc, 0x7b,
  37163. 0xb1, 0x9a, 0x77, 0x2d, 0x5a, 0x4e, 0xfe, 0x32,
  37164. 0xca, 0xc8, 0x9b, 0x76, 0xc4, 0x2a, 0x5e, 0xde,
  37165. 0x9b, 0xcc, 0x20, 0xc1, 0x89, 0x8c, 0x08, 0xa5,
  37166. 0xb0, 0xc0, 0x7e, 0x47, 0x8b, 0x1b, 0xbc, 0x22,
  37167. 0x6e, 0xfa, 0xd1, 0x5f, 0x2a, 0xc7, 0x37, 0x51,
  37168. 0x4b, 0x8c, 0x61, 0x49, 0x81, 0x07, 0x79, 0x22,
  37169. 0x24, 0x16, 0x53, 0x7e, 0xd0, 0x0d, 0xae, 0xab,
  37170. 0x17, 0x7e, 0x90, 0x3e, 0xad, 0x6b, 0x4a, 0xc4,
  37171. 0x23, 0x70, 0xaf, 0x1b, 0x1f, 0x50, 0xeb, 0xaf,
  37172. 0xaa, 0x1c, 0x6e, 0x64, 0x7b, 0xba, 0xcc, 0xe7,
  37173. 0x2c, 0x7d, 0x0b, 0x88, 0xae, 0xb0, 0xb0, 0x6f,
  37174. 0xc1, 0xa4, 0x54, 0x57, 0xa9, 0xc1, 0x87, 0x57,
  37175. 0x9b, 0xf1, 0x84, 0x57, 0x9c, 0xc3, 0x51, 0xc4,
  37176. 0x3d, 0xff, 0x94, 0x26, 0x05, 0xaa, 0x56, 0x04,
  37177. 0xfc, 0x85, 0xfc, 0x55, 0x83, 0xf6, 0xf1, 0x49,
  37178. 0x6f, 0xe6, 0x1d, 0x70, 0xd6, 0xcd, 0xe2, 0x32,
  37179. 0x7f, 0xee, 0x71, 0x3d, 0x86, 0xf2, 0x9b, 0x3a,
  37180. 0xfc, 0xbb, 0x54, 0xe9, 0xa9, 0x2a, 0x33, 0xa6,
  37181. 0xc1, 0xea, 0x6f, 0xfa, 0x30, 0x95, 0x66, 0xb0,
  37182. 0x68, 0x62, 0x33, 0xc0, 0xf3, 0xb1, 0xc3, 0x14,
  37183. 0x48, 0x90, 0xe4, 0xf0, 0x82, 0x9a, 0x60, 0x99,
  37184. 0xc5, 0x74, 0x9c, 0xde, 0xc8, 0x43, 0x28, 0xec,
  37185. 0x2c, 0xb6, 0x4a, 0x73, 0x85, 0xa7, 0x61, 0xd6,
  37186. 0x4b, 0x3a, 0x23, 0xc4, 0x89, 0x34, 0x33, 0x43,
  37187. 0xb9, 0x77, 0x23, 0xae, 0x78, 0xc7, 0xd8, 0x05,
  37188. 0x45, 0x8e, 0x16, 0x20, 0xf0, 0x29, 0x28, 0x97,
  37189. 0x69, 0x17, 0x04, 0xcb, 0x76, 0xe3, 0xb0, 0xb2,
  37190. 0x81, 0xa8, 0x3c, 0xf6, 0x44, 0x90, 0x49, 0x8c,
  37191. 0xbc, 0xaf, 0x04, 0x80, 0x24, 0x16, 0xb3, 0x3c,
  37192. 0x56, 0x51, 0x71, 0xd7, 0x72, 0xd3, 0xb9, 0x35,
  37193. 0x40, 0x37, 0x58, 0x76, 0x29, 0xae, 0x14, 0xa5,
  37194. 0xc5, 0x03, 0x1a, 0xc3, 0x66, 0x71, 0xa0, 0xd0,
  37195. 0xc9, 0x1c, 0xc0, 0xb4, 0xcd, 0x69, 0xd8, 0x40,
  37196. 0x2e, 0x33, 0xb9, 0xbc, 0xc2, 0xbb, 0xaf, 0x6b,
  37197. 0x97, 0x1e, 0x30, 0x3f, 0xa1, 0x37, 0xbe, 0x23,
  37198. 0x25, 0x98, 0xa4, 0x99, 0x9b, 0xc0, 0x12, 0x57,
  37199. 0x4c, 0x81, 0x65, 0x1b, 0x38, 0xb3, 0x83, 0x96,
  37200. 0xc1, 0xc3, 0x65, 0x30, 0x3a, 0xd2, 0x5d, 0x49,
  37201. 0xfc, 0x6b, 0x68, 0x99, 0x51, 0xa1, 0xcc, 0x4c,
  37202. 0x60, 0x07, 0x61, 0x30, 0x65, 0x49, 0x5f, 0x97,
  37203. 0x91, 0x0f, 0x97, 0x35, 0xd4, 0xea, 0x4e, 0x44,
  37204. 0x2a, 0xcb, 0x2f, 0xab, 0xae, 0xcf, 0xe1, 0xad,
  37205. 0xef, 0x06, 0x67, 0xba, 0x42, 0x2c, 0x95, 0x4a,
  37206. 0x05, 0xd1, 0xb6, 0x16, 0x7a, 0x26, 0x3e, 0x12,
  37207. 0x75, 0xc6, 0xad, 0xa8, 0x38, 0x59, 0x65, 0x30,
  37208. 0x4b, 0x30, 0x32, 0x40, 0x40, 0x54, 0x2c, 0xf5,
  37209. 0xa4, 0x51, 0xbc, 0xaf, 0xc7, 0x47, 0x88, 0xbe,
  37210. 0x3b, 0x9b, 0x9f, 0xcc, 0x45, 0xd4, 0x79, 0x0e,
  37211. 0x2d, 0x73, 0x35, 0xc6, 0x0a, 0x14, 0xf0, 0xa4,
  37212. 0x9d, 0x13, 0x05, 0x3f, 0x26, 0x26, 0xa6, 0x27,
  37213. 0xca, 0x19, 0x55, 0x3c, 0xb3, 0x36, 0xa2, 0xcb,
  37214. 0x4a, 0x45, 0x5d, 0x8e, 0xf3, 0x98, 0x94, 0x91,
  37215. 0x47, 0x2b, 0xa0, 0x05, 0x1e, 0xf7, 0x41, 0x6e,
  37216. 0x0b, 0xbf, 0x1a, 0x61, 0x08, 0xfa, 0x07, 0xc1,
  37217. 0x61, 0x54, 0x8e, 0x7c, 0x62, 0x33, 0x1a, 0xe5,
  37218. 0xa2, 0xb4, 0xe4, 0xa1, 0x08, 0xa5, 0x10, 0x93,
  37219. 0xd3, 0x15, 0x08, 0x21, 0xa2, 0xfb, 0x54, 0x71,
  37220. 0x70, 0xa1, 0xb7, 0x3c, 0x43, 0xc5, 0x50, 0xc6,
  37221. 0x55, 0x7a, 0x40, 0x48, 0xa5, 0x8a, 0x2c, 0xd7,
  37222. 0x7a, 0x24, 0x42, 0x34, 0xb2, 0x23, 0x51, 0x75,
  37223. 0xa0, 0x89, 0x7d, 0x50, 0x61, 0xb4, 0x61, 0x34,
  37224. 0x82, 0xdc, 0x13, 0x64, 0x14, 0x04, 0x8c, 0x11,
  37225. 0xdb, 0x37, 0xea, 0xe0, 0xa5, 0xdf, 0x87, 0xc1,
  37226. 0x93, 0x14, 0xb0, 0xe8, 0x23, 0x97, 0xa0, 0xd3,
  37227. 0x38, 0xdc, 0x21, 0x53, 0x8a, 0xf3, 0x61, 0x49,
  37228. 0xd9, 0x3f, 0x8b, 0x1a, 0x11, 0xc5, 0x3b, 0xb5,
  37229. 0xde, 0xf8, 0xb7, 0xa2, 0xcc, 0xa3, 0x36, 0x2b,
  37230. 0x7f, 0xe3, 0xa1, 0x40, 0x8a, 0x25, 0x47, 0xe2,
  37231. 0x09, 0x05, 0x8c, 0x67, 0x3a, 0x75, 0x66, 0xc2,
  37232. 0x61, 0x23, 0xa6, 0xd8, 0xb6, 0x92, 0xa5, 0xf3,
  37233. 0x3e, 0xbd, 0xcb, 0x26, 0x24, 0xb7, 0x9d, 0x87,
  37234. 0x7b, 0xce, 0x5f, 0xa1, 0x4e, 0x42, 0xe8, 0x3f,
  37235. 0xaa, 0xd8, 0x2e, 0x99, 0x00, 0x55, 0x3a, 0x3c,
  37236. 0x60, 0x45, 0xca, 0x32, 0x9f, 0xea, 0x4a, 0x50,
  37237. 0x65, 0x58, 0xc4, 0x91, 0xb6, 0xa6, 0x16, 0xc6,
  37238. 0xfd, 0x40, 0x0b, 0x42, 0x13, 0x6f, 0x44, 0xcb,
  37239. 0x0d, 0x02, 0x57, 0x65, 0x08, 0x19, 0x01, 0x8d,
  37240. 0x3c, 0x56, 0x8e, 0xf6, 0xc6, 0x0c, 0x6c, 0x40,
  37241. 0x9e, 0x70, 0xa8, 0x29, 0x28, 0x71, 0x08, 0xc1,
  37242. 0xb6, 0xa4, 0xd3, 0x2f, 0x76, 0xe5, 0xcc, 0x4d,
  37243. 0x10, 0x4b, 0x02, 0x43, 0x8e, 0xf7, 0xa4, 0x67,
  37244. 0x91, 0x23, 0x98, 0xea, 0x9c, 0x7c, 0xbd, 0x99,
  37245. 0x81, 0x58, 0x9a, 0x34, 0x18, 0x97, 0x68, 0x7b,
  37246. 0x51, 0x6a, 0x13, 0x30, 0x7d, 0x66, 0xc0, 0x68,
  37247. 0xc4, 0x44, 0xb4, 0xb9, 0x49, 0xa1, 0x74, 0x12,
  37248. 0x41, 0x33, 0x15, 0xcc, 0xf4, 0x9b, 0x99, 0x98,
  37249. 0x00, 0x34, 0xb5, 0xb8, 0xcf, 0xde, 0xc4, 0xa6,
  37250. 0x0b, 0x9c, 0x1e, 0x74, 0x55, 0xaa, 0xfb, 0xf3,
  37251. 0xa7, 0x57, 0x34, 0x69, 0x90, 0xcc, 0x32, 0xb0,
  37252. 0x59, 0x9b, 0xa2, 0x17, 0xa6, 0xc5, 0xfc, 0x39,
  37253. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  37254. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  37255. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  37256. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  37257. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  37258. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  37259. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  37260. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  37261. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  37262. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  37263. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  37264. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  37265. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  37266. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  37267. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  37268. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  37269. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  37270. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  37271. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  37272. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  37273. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  37274. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  37275. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  37276. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  37277. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  37278. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  37279. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  37280. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  37281. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  37282. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  37283. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  37284. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  37285. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  37286. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  37287. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  37288. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  37289. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  37290. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  37291. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  37292. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  37293. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  37294. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  37295. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  37296. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  37297. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  37298. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  37299. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  37300. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  37301. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  37302. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  37303. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  37304. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  37305. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  37306. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  37307. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  37308. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  37309. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  37310. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  37311. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  37312. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  37313. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  37314. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  37315. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  37316. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  37317. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  37318. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  37319. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  37320. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  37321. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  37322. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  37323. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  37324. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  37325. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  37326. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  37327. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  37328. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  37329. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  37330. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  37331. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  37332. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  37333. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  37334. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  37335. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  37336. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  37337. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  37338. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  37339. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  37340. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  37341. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  37342. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  37343. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  37344. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  37345. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  37346. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  37347. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  37348. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  37349. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  37350. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  37351. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  37352. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  37353. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  37354. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  37355. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  37356. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  37357. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  37358. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  37359. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  37360. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  37361. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  37362. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  37363. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  37364. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  37365. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  37366. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  37367. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  37368. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  37369. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  37370. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  37371. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  37372. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  37373. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  37374. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  37375. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  37376. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  37377. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  37378. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  37379. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  37380. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  37381. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  37382. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  37383. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  37384. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  37385. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  37386. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  37387. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  37388. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  37389. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  37390. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  37391. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  37392. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  37393. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  37394. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  37395. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  37396. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  37397. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  37398. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  37399. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  37400. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  37401. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  37402. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  37403. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  37404. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  37405. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  37406. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  37407. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  37408. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  37409. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  37410. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  37411. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  37412. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  37413. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  37414. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  37415. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  37416. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  37417. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  37418. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  37419. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  37420. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  37421. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  37422. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  37423. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  37424. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  37425. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  37426. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  37427. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  37428. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  37429. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  37430. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  37431. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  37432. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  37433. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  37434. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  37435. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  37436. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  37437. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  37438. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  37439. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  37440. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  37441. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  37442. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  37443. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  37444. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  37445. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  37446. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  37447. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  37448. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb,
  37449. 0xeb, 0xbe, 0x41, 0xcd, 0x4d, 0xea, 0x48, 0x9d,
  37450. 0xed, 0xd0, 0x0e, 0x76, 0xae, 0x0b, 0xcf, 0x54,
  37451. 0xaa, 0x85, 0x50, 0x20, 0x29, 0x20, 0xeb, 0x64,
  37452. 0xd5, 0x89, 0x2a, 0xd0, 0x2b, 0x13, 0xf2, 0xe5,
  37453. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  37454. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  37455. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  37456. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  37457. #endif
  37458. };
  37459. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ct[] = {
  37460. #ifdef WOLFSSL_KYBER_ORIGINAL
  37461. 0xA6, 0xAF, 0x29, 0xD5, 0xF5, 0xB8, 0x0B, 0xD1,
  37462. 0x30, 0xF5, 0x18, 0xBA, 0xDD, 0xD6, 0xC8, 0xF1,
  37463. 0x75, 0x45, 0x41, 0x3D, 0x86, 0x0F, 0xB3, 0xDE,
  37464. 0x45, 0x19, 0x79, 0xEB, 0xFA, 0x5E, 0x4E, 0x31,
  37465. 0x12, 0xC7, 0xC0, 0xAD, 0xF9, 0x98, 0x24, 0xBB,
  37466. 0x52, 0x6F, 0x2C, 0x35, 0x50, 0x74, 0x8E, 0xD0,
  37467. 0xE1, 0x34, 0xF0, 0x45, 0x7A, 0x7C, 0x61, 0xF9,
  37468. 0xF5, 0x26, 0xF0, 0x02, 0xBA, 0xAD, 0xC0, 0x3F,
  37469. 0xC1, 0x3E, 0x38, 0x13, 0x12, 0x19, 0x51, 0x3C,
  37470. 0x3E, 0xDE, 0x06, 0x16, 0x61, 0xE7, 0x4F, 0x60,
  37471. 0x3C, 0x4F, 0xCF, 0x79, 0x51, 0xC8, 0xE5, 0x2C,
  37472. 0x9C, 0x21, 0x3B, 0x0D, 0x22, 0xD9, 0x29, 0x36,
  37473. 0x63, 0xD6, 0x69, 0xA6, 0xB5, 0x8E, 0xD8, 0xFC,
  37474. 0xEF, 0xCF, 0x82, 0x49, 0xD7, 0xBB, 0x52, 0x98,
  37475. 0xF5, 0x57, 0x61, 0x44, 0x5B, 0x2B, 0x83, 0xCE,
  37476. 0x7F, 0x00, 0x5C, 0xB0, 0x42, 0x48, 0xAE, 0xC8,
  37477. 0xBD, 0xA2, 0x2F, 0xD2, 0xD4, 0x2A, 0xA7, 0x66,
  37478. 0x32, 0x20, 0x14, 0xEA, 0x03, 0x8C, 0xC3, 0x2C,
  37479. 0x55, 0xC8, 0xE4, 0xB9, 0xE2, 0x8E, 0xC9, 0x11,
  37480. 0x9F, 0x52, 0x73, 0x41, 0xE4, 0xF6, 0x6A, 0x03,
  37481. 0x51, 0x21, 0x07, 0x3B, 0x85, 0xDE, 0x67, 0x06,
  37482. 0xDA, 0x19, 0xE0, 0x83, 0x8A, 0x9F, 0x33, 0xB7,
  37483. 0x19, 0xA6, 0x8F, 0x03, 0x9B, 0x66, 0x4D, 0xC0,
  37484. 0x02, 0x65, 0x9E, 0xAB, 0xFC, 0x39, 0x86, 0x79,
  37485. 0xAA, 0x70, 0x09, 0xCE, 0x0C, 0xD0, 0x1C, 0xDA,
  37486. 0xFB, 0x6C, 0xD2, 0xA2, 0x6F, 0xE4, 0x10, 0x16,
  37487. 0x72, 0xC9, 0x8F, 0xF5, 0x8F, 0x7C, 0x47, 0xD5,
  37488. 0xBD, 0xA2, 0x90, 0x66, 0x53, 0xB3, 0xA6, 0xF9,
  37489. 0x65, 0x1F, 0x7A, 0x12, 0x1E, 0xA7, 0x7E, 0xA7,
  37490. 0x47, 0x23, 0xFA, 0xE5, 0xB8, 0x73, 0xF9, 0xBB,
  37491. 0x7B, 0x66, 0x4F, 0x0C, 0x8A, 0x93, 0x83, 0x1E,
  37492. 0xF9, 0xD5, 0x1C, 0x7C, 0xC1, 0xEF, 0x44, 0xAC,
  37493. 0x0E, 0x55, 0xA5, 0x5C, 0xA7, 0x6D, 0x13, 0x7F,
  37494. 0xE9, 0xB7, 0x5F, 0x40, 0x50, 0x9C, 0xEF, 0x15,
  37495. 0x6E, 0x5A, 0xD1, 0x8F, 0x9F, 0xB9, 0x99, 0x68,
  37496. 0x00, 0x08, 0xE5, 0x47, 0xD5, 0x5E, 0xEC, 0xD5,
  37497. 0xB4, 0xD1, 0xCB, 0x1D, 0x9F, 0x07, 0x6C, 0xEC,
  37498. 0x21, 0x50, 0x1C, 0x74, 0x02, 0x50, 0x9E, 0xCB,
  37499. 0x77, 0xAF, 0xB2, 0xCB, 0x9A, 0x61, 0x34, 0x0A,
  37500. 0x8B, 0xD1, 0x51, 0x4C, 0x6E, 0x71, 0xB4, 0xAA,
  37501. 0x45, 0xE4, 0x7E, 0xC3, 0x75, 0x12, 0x27, 0x1B,
  37502. 0x91, 0x1F, 0x8F, 0xB4, 0x6C, 0x90, 0x82, 0xC9,
  37503. 0xDF, 0x07, 0x20, 0x4A, 0xBB, 0x5A, 0x50, 0xE6,
  37504. 0xE3, 0x64, 0x7A, 0x8A, 0xD4, 0xD8, 0xD5, 0xD7,
  37505. 0xBF, 0xF1, 0x9C, 0x8A, 0x50, 0x93, 0x08, 0xBC,
  37506. 0xFB, 0x89, 0x55, 0x36, 0xD0, 0x45, 0xCA, 0x2B,
  37507. 0x97, 0xCB, 0x16, 0xA2, 0x9B, 0xB7, 0x18, 0x1C,
  37508. 0xAD, 0x05, 0x09, 0xDD, 0xB9, 0x17, 0x35, 0x02,
  37509. 0x8E, 0xBA, 0x8C, 0x31, 0xD7, 0x4B, 0xD2, 0x75,
  37510. 0xEA, 0xA6, 0x5B, 0x53, 0x40, 0xB3, 0xA4, 0x3F,
  37511. 0xBF, 0xE0, 0xB3, 0x06, 0x1D, 0x6B, 0xAE, 0x7E,
  37512. 0x75, 0xB7, 0x09, 0x8C, 0xDA, 0xBE, 0x91, 0xD4,
  37513. 0xB3, 0x1E, 0x36, 0xC9, 0xAA, 0x7A, 0x82, 0x98,
  37514. 0x86, 0x2A, 0xD6, 0x3C, 0x8F, 0xD2, 0x82, 0xE0,
  37515. 0x3B, 0x46, 0x0B, 0x3A, 0xB4, 0x64, 0xCE, 0x0F,
  37516. 0x27, 0xB1, 0xC3, 0xD1, 0x11, 0x55, 0xAC, 0xAA,
  37517. 0x01, 0x1E, 0xB9, 0xE2, 0xAE, 0x3E, 0x6D, 0xDA,
  37518. 0x07, 0xD6, 0xF4, 0x91, 0x73, 0x7C, 0xBC, 0xE9,
  37519. 0xB0, 0x5F, 0x9B, 0xC5, 0x6B, 0xE2, 0x0E, 0x8D,
  37520. 0x32, 0x6B, 0xA1, 0x32, 0xC5, 0x7F, 0xB2, 0x35,
  37521. 0x16, 0x11, 0x44, 0x51, 0x9C, 0xDF, 0x40, 0x56,
  37522. 0x0F, 0xBE, 0x27, 0x9B, 0xDE, 0x41, 0x1E, 0x11,
  37523. 0x25, 0x31, 0xF8, 0x26, 0xD6, 0xAB, 0x10, 0xD4,
  37524. 0x54, 0x73, 0x50, 0xAD, 0xD2, 0xA9, 0xDE, 0x8D,
  37525. 0x62, 0xC2, 0xAC, 0x82, 0xCA, 0xBE, 0x68, 0x15,
  37526. 0x64, 0x6F, 0x4D, 0xC9, 0x74, 0x2B, 0xB0, 0xC2,
  37527. 0xA3, 0xF7, 0x7E, 0xC7, 0xB4, 0x6C, 0x6B, 0x53,
  37528. 0x76, 0x05, 0xFA, 0x31, 0x79, 0x8C, 0xD8, 0x92,
  37529. 0x81, 0x22, 0x1A, 0x33, 0xDF, 0xB9, 0x79, 0x6E,
  37530. 0x64, 0x43, 0x05, 0x63, 0x03, 0x32, 0xC2, 0xCB,
  37531. 0x93, 0x14, 0x08, 0xAB, 0x48, 0x1A, 0x16, 0xD9,
  37532. 0x53, 0xF6, 0xBE, 0xAE, 0x38, 0x91, 0xD6, 0xD9,
  37533. 0xAC, 0x1F, 0xAB, 0x38, 0x22, 0x2D, 0x92, 0x71,
  37534. 0x87, 0x2D, 0x9D, 0x0C, 0xAD, 0xB9, 0x1A, 0xBE,
  37535. 0x9B, 0x4E, 0x26, 0x5F, 0x75, 0xC6, 0xE5, 0xE8,
  37536. 0x29, 0xE1, 0x46, 0xC3, 0xD8, 0xCE, 0x1E, 0x9D,
  37537. 0x12, 0xE0, 0xD1, 0x29, 0x80, 0x19, 0x57, 0xF4,
  37538. 0x6B, 0x0D, 0x2D, 0xBE, 0x1F, 0x74, 0x9B, 0x1D,
  37539. 0x08, 0xE2, 0x34, 0x5F, 0x62, 0x39, 0xA7, 0x31,
  37540. 0x34, 0x2E, 0xB7, 0x5B, 0x0C, 0xF1, 0xBF, 0x41,
  37541. 0x17, 0x49, 0xBC, 0x2C, 0xAF, 0x28, 0x10, 0xB7,
  37542. 0x88, 0xC6, 0xB7, 0x23, 0x8B, 0x4D, 0x3D, 0xA2,
  37543. 0xD6, 0x31, 0x5C, 0xE9, 0x54, 0x2E, 0x24, 0x40,
  37544. 0x4F, 0x14, 0x57, 0x55, 0xA3, 0x0A, 0xB8, 0x51,
  37545. 0xE4, 0x44, 0x58, 0x41, 0xBD, 0x33, 0xF7, 0x16,
  37546. 0xA5, 0x86, 0x88, 0x48, 0x88, 0xEC, 0xC6, 0xBC,
  37547. 0x64, 0x98, 0xAA, 0x32, 0x91, 0x9A, 0xE8, 0x1D,
  37548. 0x20, 0xC2, 0x69, 0x73, 0xC2, 0xBD, 0x54, 0x58,
  37549. 0x2A, 0x0F, 0x6A, 0xD9, 0x8A, 0xBF, 0xD2, 0x62,
  37550. 0x7E, 0x15, 0x69, 0x0A, 0x72, 0x7E, 0x69, 0xF5,
  37551. 0x81, 0xDD, 0x2A, 0x71, 0x27, 0x98, 0x2A, 0x90,
  37552. 0xE3, 0x3E, 0x2D, 0x4A, 0x03, 0xFE, 0x33, 0x91,
  37553. 0x42, 0xC7, 0xE4, 0x4C, 0x32, 0x6A, 0xC4, 0x6E,
  37554. 0xD3, 0x95, 0xA2, 0x25, 0xD3, 0x03, 0x33, 0x89,
  37555. 0x91, 0x73, 0x28, 0xB4, 0x53, 0x16, 0xB1, 0x58,
  37556. 0x5A, 0x01, 0xB2, 0xC3, 0x04, 0xB2, 0x94, 0x4E,
  37557. 0x90, 0x3A, 0xBB, 0xB3, 0xEC, 0x56, 0x19, 0x44,
  37558. 0x1C, 0xFC, 0x89, 0x65, 0xA4, 0x46, 0xDF, 0x75,
  37559. 0xDE, 0xFA, 0x80, 0xC6, 0xE1, 0x5A, 0xDB, 0xD5,
  37560. 0x06, 0xB7, 0xAB, 0x2D, 0xE1, 0x2D, 0xDA, 0x9B,
  37561. 0xC8, 0x14, 0x41, 0xCF, 0xC8, 0x90, 0x52, 0xE2,
  37562. 0xE5, 0x80, 0x8F, 0x71, 0x26, 0xC6, 0xFD, 0x3A,
  37563. 0xC6, 0xAC, 0x80, 0x81, 0x25, 0x8A, 0x84, 0xA0,
  37564. 0x9A, 0xE5, 0x0F, 0x6C, 0xD7, 0xCC, 0x0F, 0x4A,
  37565. 0xF3, 0x36, 0xFD, 0x1D, 0x64, 0x3E, 0x99, 0x07,
  37566. 0x99, 0x96, 0x26, 0x8C, 0x2D, 0x32, 0xD9, 0x09,
  37567. 0xF2, 0x2E, 0x35, 0x04, 0xF0, 0x7F, 0xBB, 0x56,
  37568. 0x31, 0x96, 0xD4, 0x31, 0x2F, 0xDD, 0xB9, 0x33,
  37569. 0x5D, 0x5C, 0x1D, 0x36, 0xE8, 0xC5, 0xEE, 0xA2,
  37570. 0x27, 0x8D, 0xBA, 0x23, 0xB9, 0x4D, 0x19, 0x3C,
  37571. 0x94, 0x7C, 0xC4, 0x1C, 0xA9, 0x93, 0xDC, 0x7D,
  37572. 0xB1, 0x39, 0x63, 0x40, 0xAD, 0x9C, 0x4F, 0xE6,
  37573. 0x87, 0xDD, 0x7B, 0x8D, 0x0C, 0x7A, 0x51, 0x20,
  37574. 0xAE, 0x02, 0x04, 0xF2, 0xC6, 0x65, 0xBD, 0x5F,
  37575. 0x47, 0x3D, 0x64, 0x4C, 0x7F, 0xF2, 0x6B, 0xFF,
  37576. 0xBA, 0x7A, 0x36, 0x98, 0x08, 0x30, 0x70, 0x21,
  37577. 0x28, 0xA7, 0xE6, 0x61, 0xD6, 0x77, 0xA0, 0x92,
  37578. 0xA3, 0x6E, 0x74, 0x28, 0xA4, 0x13, 0x9F, 0xB2,
  37579. 0x9B, 0x00, 0x95, 0xCC, 0x11, 0x08, 0x6F, 0x44,
  37580. 0x7D, 0x2A, 0x9E, 0xF6, 0xC9, 0xB1, 0x61, 0xF1,
  37581. 0x89, 0xC6, 0x29, 0x9E, 0x08, 0x4C, 0xB7, 0xAA,
  37582. 0x00, 0xFA, 0xF7, 0x87, 0x79, 0x7B, 0xFB, 0x06,
  37583. 0x9F, 0xBC, 0x08, 0x7F, 0xDE, 0x26, 0x25, 0x2A,
  37584. 0x16, 0x64, 0xF1, 0x9C, 0x5A, 0x8A, 0x22, 0xEC,
  37585. 0x5E, 0xE1, 0xAE, 0xB0, 0x76, 0x35, 0x7B, 0x7D,
  37586. 0xC3, 0x7E, 0x6B, 0x0F, 0x15, 0x20, 0xF9, 0x58,
  37587. 0xF7, 0x85, 0x1B, 0xAC, 0xB9, 0x2C, 0x89, 0xFD,
  37588. 0x11, 0x4A, 0x72, 0xFE, 0xAC, 0x54, 0x65, 0x2D,
  37589. 0x45, 0xB0, 0x9E, 0x1A, 0xE7, 0x65, 0x1A, 0xBD,
  37590. 0x16, 0x4B, 0xCD, 0x53, 0x7D, 0x58, 0xFA, 0x39,
  37591. 0xD3, 0xEC, 0x8A, 0xCD, 0xCD, 0xF9, 0x84, 0x25,
  37592. 0x00, 0x58, 0x62, 0xFA, 0x59, 0x69, 0x2D, 0xE1,
  37593. 0x62, 0xB7, 0x7E, 0x62, 0x97, 0xC6, 0x62, 0x33,
  37594. 0x34, 0x84, 0x08, 0xA8, 0xAB, 0x69, 0x5C, 0xE2,
  37595. 0xF2, 0x72, 0x8D, 0xB9, 0xFB, 0xE2, 0x7E, 0x95,
  37596. 0x89, 0x67, 0xEC, 0x59, 0x74, 0x76, 0x7C, 0x5A,
  37597. 0x66, 0x02, 0x30, 0x74, 0xB4, 0xA7, 0x1A, 0xFD,
  37598. 0x26, 0x4A, 0xD2, 0x89, 0x0E, 0x97, 0x0A, 0x1F,
  37599. 0x31, 0xD6, 0xE3, 0x31, 0x1B, 0x73, 0x6F, 0x9F,
  37600. 0x94, 0x88, 0x79, 0x3D, 0xDC, 0x88, 0xF2, 0x34,
  37601. 0x58, 0x06, 0x42, 0x54, 0xC8, 0x2A, 0x1D, 0x9E,
  37602. 0x59, 0xEA, 0xD2, 0xFC, 0xEC, 0x40, 0xB4, 0x30,
  37603. 0x68, 0x7C, 0x4B, 0x7E, 0x28, 0x96, 0x09, 0x26,
  37604. 0xAF, 0xCA, 0xCC, 0x9B, 0xD7, 0x56, 0xA7, 0x10,
  37605. 0x88, 0xC7, 0x84, 0x50, 0xE2, 0x0A, 0x2E, 0x98,
  37606. 0x0A, 0xED, 0xE9, 0xEB, 0xED, 0xFE, 0x7F, 0xAB,
  37607. 0xD6, 0xAB, 0xFE, 0x96, 0xF9, 0x34, 0xC4, 0xB0,
  37608. 0x2C, 0x01, 0xCA, 0x19, 0x4D, 0x01, 0xB7, 0x3C,
  37609. 0x25, 0xD5, 0x99, 0x70, 0x39, 0xD3, 0xFC, 0xD0,
  37610. 0xF0, 0x99, 0x52, 0x1F, 0x70, 0xCA, 0xEE, 0x69,
  37611. 0x11, 0x0A, 0xC1, 0xFC, 0x5A, 0x99, 0x91, 0x7A,
  37612. 0xD7, 0x52, 0xFC, 0x96, 0xAD, 0xFA, 0xD7, 0x18,
  37613. 0x6D, 0x0A, 0x7C, 0x9C, 0xFE, 0x56, 0x01, 0xC0,
  37614. 0x75, 0x14, 0xEA, 0x64, 0x48, 0xD6, 0x61, 0xC5,
  37615. 0x7A, 0xA2, 0x02, 0x42, 0x10, 0x3C, 0x42, 0x76,
  37616. 0xA0, 0x70, 0xA4, 0x89, 0xA4, 0xCB, 0x6B, 0xCA,
  37617. 0x0F, 0x9E, 0xCC, 0x43, 0x79, 0xFB, 0x22, 0x02,
  37618. 0x15, 0xFD, 0x91, 0xF8, 0x10, 0x19, 0xD5, 0xB0,
  37619. 0xAE, 0x61, 0x93, 0x58, 0xB5, 0x24, 0x68, 0xF2,
  37620. 0x72, 0xC1, 0x78, 0xE3, 0xA7, 0x4C, 0xF6, 0x77,
  37621. 0x5A, 0xA9, 0x24, 0xFE, 0x32, 0x9C, 0x31, 0x75,
  37622. 0xD9, 0xE4, 0xC3, 0xE2, 0x1A, 0xB9, 0xEC, 0x83,
  37623. 0x6E, 0xDC, 0x3A, 0xCA, 0xB2, 0xE3, 0x89, 0x1E,
  37624. 0xE8, 0xDE, 0xDA, 0x51, 0x5D, 0x39, 0xAF, 0x9B,
  37625. 0x8D, 0xDD, 0x0E, 0xE7, 0xB0, 0x16, 0x4F, 0x80,
  37626. 0x5C, 0x38, 0x35, 0xF6, 0xD2, 0xBA, 0xBD, 0xB3,
  37627. 0x0E, 0xAB, 0x47, 0x56, 0xE7, 0xEC, 0x7F, 0x82,
  37628. 0x9E, 0xCE, 0x01, 0xE8, 0xEA, 0xDF, 0xBB, 0xED,
  37629. 0x12, 0xFC, 0x28, 0x3B, 0x3D, 0x4C, 0x69, 0xF5,
  37630. 0x75, 0xE7, 0xF8, 0x04, 0x17, 0x68, 0x9F, 0xDF,
  37631. 0xCF, 0xC7, 0xBE, 0x27, 0xEE, 0x3B, 0x8C, 0xDF,
  37632. 0x57, 0xAA, 0xEB, 0xEC, 0x4A, 0x95, 0xB7, 0xE5,
  37633. 0xBB, 0x58, 0x5B, 0x85, 0x22, 0x7F, 0x7C, 0x32,
  37634. 0xBE, 0x30, 0xDB, 0x3E, 0x65, 0xE4, 0x2E, 0x30,
  37635. 0xDC, 0xF5, 0xA5, 0xFA, 0x07, 0x3D, 0xBA, 0x39,
  37636. 0x9D, 0x94, 0x2F, 0x22, 0x22, 0xAD, 0xB9, 0xB9,
  37637. 0x89, 0x81, 0x02, 0xAF, 0xE5, 0x43, 0x2E, 0xDC,
  37638. 0x7F, 0x04, 0xAE, 0x34, 0xA8, 0xFE, 0xC2, 0xD8,
  37639. 0x1C, 0xB4, 0x9A, 0x9A, 0x9B, 0x43, 0x81, 0x4C,
  37640. 0xE7, 0x1D, 0x97, 0xF7, 0x26, 0xE2, 0xB1, 0xE8,
  37641. 0xF6, 0x4B, 0x50, 0xE6, 0x5D, 0xFB, 0x48, 0x16,
  37642. 0xE1, 0x2E, 0x82, 0xA3, 0x19, 0x74, 0x84, 0xA4,
  37643. 0xE9, 0xBB, 0xA4, 0xD2, 0xD6, 0x9E, 0x3F, 0x19,
  37644. 0xD0, 0xB7, 0x5C, 0x21, 0xE2, 0xBF, 0xFE, 0x9F,
  37645. 0xC0, 0xC9, 0x8C, 0xF4, 0x8A, 0x3A, 0xAF, 0x08,
  37646. 0xD4, 0x67, 0xF7, 0x26, 0x87, 0xDF, 0x01, 0x78,
  37647. 0x17, 0x4B, 0x78, 0x97, 0xF7, 0x34, 0x34, 0x9B,
  37648. 0x18, 0x1E, 0xCA, 0x86, 0xA5, 0x98, 0xA0, 0xC5,
  37649. 0xE8, 0xC2, 0x59, 0x46, 0xF2, 0x4D, 0xC5, 0x57,
  37650. 0x2B, 0xD3, 0x24, 0xA4, 0x04, 0x58, 0xA7, 0x88,
  37651. 0xE5, 0x13, 0x7F, 0x3C, 0x7A, 0x7C, 0x97, 0xFC,
  37652. 0x9F, 0x12, 0xA3, 0xC4, 0x63, 0xA8, 0xFE, 0x94,
  37653. 0x49, 0x10, 0x1C, 0xCE, 0x96, 0x6D, 0x7C, 0x00,
  37654. 0x93, 0x23, 0x93, 0x29, 0x98, 0xD5, 0x6E, 0xF4,
  37655. 0x30, 0xC7, 0x3B, 0xC2, 0x4F, 0x5D, 0x95, 0xF7,
  37656. 0x37, 0x85, 0x8D, 0xDC, 0x4F, 0x32, 0xC0, 0x13
  37657. #else
  37658. 0xc9, 0xbe, 0xad, 0x6b, 0x0c, 0x11, 0x14, 0x38,
  37659. 0x9b, 0xd4, 0x76, 0x1c, 0x73, 0xab, 0x90, 0x95,
  37660. 0xb5, 0x80, 0x9d, 0xaa, 0xc9, 0xf6, 0x59, 0xbb,
  37661. 0x56, 0x4a, 0xf2, 0x26, 0x17, 0x30, 0x52, 0xa4,
  37662. 0xa3, 0xe7, 0xf2, 0xe5, 0xfd, 0x47, 0xd2, 0xb0,
  37663. 0x2a, 0xae, 0xb5, 0x18, 0x9e, 0x06, 0xb9, 0xf4,
  37664. 0xae, 0x98, 0xb6, 0x19, 0xcb, 0x63, 0xef, 0xbd,
  37665. 0xf3, 0x98, 0x9a, 0x94, 0xb3, 0x6e, 0x8e, 0xa0,
  37666. 0xd7, 0x00, 0x63, 0x3b, 0x95, 0x0a, 0x0a, 0xe2,
  37667. 0xa7, 0x8e, 0xd9, 0x2e, 0x85, 0xc8, 0x5c, 0x70,
  37668. 0xe1, 0x3e, 0x62, 0x6f, 0xb2, 0x63, 0xfa, 0xc9,
  37669. 0x68, 0x15, 0x21, 0xc3, 0xab, 0x22, 0xfd, 0xab,
  37670. 0x29, 0x17, 0x3c, 0x96, 0x16, 0xa2, 0xb0, 0x37,
  37671. 0x08, 0x3f, 0xf7, 0xb2, 0xe0, 0x19, 0xb5, 0xbc,
  37672. 0xde, 0x06, 0x8f, 0xac, 0x25, 0x7e, 0xf8, 0xf1,
  37673. 0x27, 0x98, 0x41, 0x16, 0x93, 0xc1, 0xbd, 0xcc,
  37674. 0x65, 0x42, 0x09, 0x97, 0xa5, 0x13, 0xa8, 0xa6,
  37675. 0x95, 0x02, 0x62, 0x0b, 0xe8, 0xe4, 0xce, 0x73,
  37676. 0x62, 0xe4, 0x12, 0xa7, 0x6c, 0xf5, 0x1c, 0x1f,
  37677. 0x24, 0x33, 0xf1, 0xab, 0x64, 0xce, 0x0e, 0x5d,
  37678. 0x2f, 0x56, 0xd7, 0xc9, 0xad, 0xe9, 0x94, 0xd0,
  37679. 0xe3, 0x5d, 0x0a, 0xee, 0xf3, 0xac, 0x51, 0x5b,
  37680. 0x48, 0x24, 0x37, 0x66, 0x4d, 0x8c, 0x1d, 0x25,
  37681. 0xe5, 0xa5, 0x50, 0x7c, 0xf8, 0x0f, 0x97, 0x0d,
  37682. 0x3e, 0xa7, 0x22, 0x6a, 0xac, 0xdc, 0x45, 0x7c,
  37683. 0xbf, 0x88, 0xa0, 0x56, 0x0a, 0xa3, 0x5b, 0xb2,
  37684. 0xc5, 0xc4, 0x55, 0x86, 0x7e, 0x21, 0x59, 0x91,
  37685. 0x0a, 0x35, 0x81, 0x0b, 0xef, 0xe3, 0xaa, 0x10,
  37686. 0xeb, 0x04, 0xd8, 0xd5, 0x71, 0x47, 0xcb, 0x8f,
  37687. 0x66, 0xd2, 0xb0, 0x70, 0xba, 0xc4, 0x3d, 0x1f,
  37688. 0x1f, 0xfd, 0xd5, 0x7a, 0x93, 0x99, 0x95, 0x1f,
  37689. 0x64, 0x96, 0x57, 0x27, 0xbc, 0xb9, 0xf6, 0x6a,
  37690. 0xd4, 0x23, 0x09, 0xda, 0xfc, 0x79, 0x9c, 0x1c,
  37691. 0x54, 0x0a, 0xf1, 0xaf, 0x93, 0xef, 0xf6, 0x8a,
  37692. 0x86, 0xd6, 0x1f, 0x51, 0x15, 0xdb, 0x66, 0x2d,
  37693. 0xee, 0x7a, 0xc9, 0xa3, 0x62, 0x67, 0x77, 0x62,
  37694. 0xb6, 0xa1, 0x64, 0xa0, 0xfa, 0x0a, 0x4d, 0x85,
  37695. 0x9e, 0x4b, 0x8c, 0x8d, 0xbd, 0xb4, 0xe1, 0x83,
  37696. 0xf5, 0xe6, 0x80, 0x8f, 0xc5, 0x22, 0x29, 0x65,
  37697. 0x0c, 0xaf, 0x7c, 0xf3, 0xe1, 0x6d, 0xe3, 0xd8,
  37698. 0x95, 0xd1, 0x48, 0xc3, 0x54, 0x48, 0xab, 0x8c,
  37699. 0x27, 0x53, 0xc9, 0x83, 0x1b, 0x24, 0xbd, 0x49,
  37700. 0x21, 0x49, 0x7e, 0xaa, 0x19, 0x25, 0x65, 0xca,
  37701. 0xbf, 0xd8, 0x3c, 0x0c, 0x68, 0xdf, 0xe7, 0xd3,
  37702. 0x92, 0xab, 0xf5, 0xe5, 0xe6, 0xf8, 0x4b, 0xb9,
  37703. 0xf5, 0xaf, 0x4b, 0x71, 0x18, 0xc0, 0xb5, 0x58,
  37704. 0x10, 0x5f, 0x9c, 0x10, 0xc9, 0xb6, 0xd7, 0x06,
  37705. 0x82, 0xe1, 0xde, 0x6e, 0x06, 0x89, 0xd7, 0x10,
  37706. 0x6a, 0x63, 0x74, 0xbd, 0x34, 0xae, 0xd7, 0x22,
  37707. 0x9e, 0x6c, 0xb3, 0x56, 0xf2, 0xea, 0x65, 0xe6,
  37708. 0x80, 0xce, 0x7b, 0x1e, 0x2c, 0x37, 0x04, 0xe1,
  37709. 0x16, 0xa3, 0x85, 0x42, 0x82, 0x6e, 0x8a, 0x00,
  37710. 0x11, 0x41, 0xba, 0xf2, 0xe3, 0x4d, 0xe3, 0x7a,
  37711. 0x03, 0x04, 0x09, 0x86, 0xd4, 0xc0, 0xcd, 0x5d,
  37712. 0x57, 0xf0, 0x70, 0x1c, 0xe9, 0x30, 0x98, 0x6f,
  37713. 0xd9, 0x52, 0x5b, 0x58, 0xe2, 0xe5, 0x9f, 0x45,
  37714. 0xb8, 0xdd, 0x04, 0xc0, 0xf3, 0x5b, 0x0f, 0x47,
  37715. 0x97, 0x0c, 0xc6, 0x70, 0x79, 0x61, 0x8e, 0xb9,
  37716. 0xe6, 0xd9, 0x1e, 0x9b, 0x0f, 0x8c, 0x6d, 0x2e,
  37717. 0x16, 0x5c, 0xf4, 0x48, 0xa2, 0xc1, 0xeb, 0xf7,
  37718. 0x1b, 0x65, 0x37, 0xe0, 0xf3, 0x75, 0x18, 0x5d,
  37719. 0xfa, 0xfe, 0xf6, 0x98, 0xb6, 0x23, 0x9b, 0xb3,
  37720. 0x55, 0x80, 0xb3, 0x15, 0xbc, 0xb5, 0xed, 0x40,
  37721. 0x8c, 0x35, 0x7f, 0x19, 0x2d, 0xef, 0x89, 0xbc,
  37722. 0x1b, 0x75, 0xcd, 0xd6, 0xaa, 0xe8, 0xb5, 0xfa,
  37723. 0xf0, 0xc3, 0xe1, 0x38, 0x03, 0xf6, 0xbd, 0xfa,
  37724. 0x76, 0xfb, 0x40, 0x7f, 0xcb, 0xda, 0x79, 0x0c,
  37725. 0x32, 0x9b, 0x3e, 0xe4, 0x2f, 0xd3, 0xd3, 0xb0,
  37726. 0x3b, 0xd5, 0x00, 0x3f, 0x0b, 0xc4, 0x32, 0xf7,
  37727. 0xba, 0x39, 0x63, 0x11, 0x12, 0x45, 0x2d, 0xfd,
  37728. 0x12, 0x14, 0x04, 0x33, 0xff, 0x89, 0x80, 0xeb,
  37729. 0x6a, 0x52, 0x6b, 0xa8, 0x5e, 0xf9, 0x94, 0x77,
  37730. 0x37, 0x8b, 0x4d, 0xc7, 0x66, 0x35, 0xa5, 0xcd,
  37731. 0x50, 0x40, 0xe4, 0x3b, 0x8c, 0x1f, 0xe4, 0xee,
  37732. 0x5e, 0x15, 0x8e, 0x42, 0x3b, 0xfc, 0x0c, 0x89,
  37733. 0x3c, 0x1d, 0x56, 0x13, 0xbe, 0xd0, 0x8d, 0xa7,
  37734. 0x19, 0xc9, 0x07, 0x31, 0x84, 0xee, 0xb3, 0x6f,
  37735. 0xd3, 0x57, 0x38, 0x0f, 0xb1, 0x87, 0x3d, 0x8c,
  37736. 0xbd, 0x36, 0xe2, 0x25, 0x5e, 0x98, 0x5b, 0x1b,
  37737. 0x76, 0x81, 0x97, 0x43, 0xa6, 0x58, 0x4a, 0x9b,
  37738. 0x3a, 0x58, 0x09, 0x96, 0xc9, 0xc2, 0xee, 0xd9,
  37739. 0xbb, 0xbf, 0xff, 0x78, 0xa6, 0x20, 0x4b, 0x5e,
  37740. 0x5e, 0xea, 0xe5, 0xf4, 0xef, 0xd2, 0x66, 0x00,
  37741. 0x78, 0xb3, 0x7f, 0x07, 0x54, 0xab, 0x5d, 0xa8,
  37742. 0x62, 0xe6, 0x66, 0xb1, 0x45, 0xb5, 0xf2, 0x3f,
  37743. 0x3d, 0x09, 0x77, 0x79, 0x99, 0x29, 0xdf, 0xa2,
  37744. 0xae, 0xdd, 0xa5, 0x3d, 0x15, 0x2e, 0xda, 0x1d,
  37745. 0x0d, 0x0e, 0x4e, 0xa4, 0x3f, 0x6e, 0xd8, 0x89,
  37746. 0xbb, 0x96, 0x5e, 0xef, 0xe0, 0xa7, 0xc6, 0x85,
  37747. 0xbb, 0x36, 0x77, 0x0e, 0xaa, 0x87, 0x42, 0x42,
  37748. 0xc0, 0xe2, 0x29, 0xcf, 0x6c, 0xe5, 0x6d, 0xef,
  37749. 0xa5, 0xae, 0xae, 0x64, 0xd0, 0xc4, 0x0d, 0xda,
  37750. 0x8a, 0xa2, 0x6e, 0xae, 0xb3, 0x14, 0x58, 0xf0,
  37751. 0x70, 0xa3, 0xbc, 0x72, 0xe1, 0x61, 0x9e, 0xe9,
  37752. 0xb5, 0xf6, 0x42, 0x29, 0x1c, 0x56, 0xdf, 0x5b,
  37753. 0x7e, 0x43, 0xdb, 0x6c, 0x80, 0x2f, 0xc7, 0x4f,
  37754. 0x4f, 0x3f, 0x9b, 0x5c, 0x0d, 0x35, 0x5c, 0x3a,
  37755. 0xae, 0x52, 0x0a, 0xa3, 0x12, 0x29, 0xd1, 0x2f,
  37756. 0x3e, 0x7c, 0xc5, 0xd4, 0x8e, 0x69, 0x11, 0x91,
  37757. 0xa3, 0x6b, 0x28, 0x37, 0x65, 0xf4, 0x13, 0x3f,
  37758. 0x0f, 0xf1, 0xfe, 0x2f, 0x01, 0xc6, 0x64, 0x8b,
  37759. 0x27, 0x98, 0xa7, 0x4e, 0xb5, 0xd8, 0x42, 0xa2,
  37760. 0x48, 0xf5, 0x24, 0xa7, 0xe7, 0xf8, 0x97, 0x42,
  37761. 0x11, 0x29, 0x7b, 0x44, 0xf0, 0xdd, 0x19, 0xf3,
  37762. 0x86, 0xe8, 0x6b, 0xe6, 0xba, 0x78, 0x2d, 0xe7,
  37763. 0x7f, 0xde, 0x88, 0x72, 0x26, 0xf3, 0x7a, 0x1c,
  37764. 0x77, 0xbc, 0x5e, 0xdd, 0xee, 0xe5, 0xbf, 0x46,
  37765. 0xb6, 0x7f, 0xb7, 0x47, 0x8d, 0x55, 0x98, 0x65,
  37766. 0xf2, 0x62, 0xca, 0xa8, 0x4d, 0x64, 0xa8, 0xce,
  37767. 0x59, 0xe4, 0xdf, 0x08, 0x18, 0xe1, 0x48, 0x61,
  37768. 0x52, 0x6a, 0xcd, 0x34, 0x83, 0x60, 0x0f, 0x3d,
  37769. 0xae, 0x79, 0x59, 0xd3, 0x5d, 0x81, 0x81, 0xca,
  37770. 0x6a, 0x81, 0xce, 0x79, 0x1b, 0xe0, 0x07, 0x52,
  37771. 0xda, 0x77, 0x59, 0x44, 0x6a, 0x2c, 0xfb, 0xe0,
  37772. 0x0b, 0x82, 0x48, 0xb9, 0x34, 0x91, 0xde, 0xbd,
  37773. 0x52, 0x02, 0x20, 0xb7, 0x55, 0x41, 0x6d, 0x2f,
  37774. 0xc6, 0xb7, 0xc8, 0xaf, 0x2f, 0xf7, 0x5e, 0x5b,
  37775. 0xcb, 0xb8, 0xe7, 0x53, 0x73, 0x80, 0xa5, 0x72,
  37776. 0x1c, 0x77, 0x48, 0x49, 0x57, 0xa6, 0x92, 0x71,
  37777. 0xd8, 0xba, 0xfc, 0xe0, 0xf1, 0x66, 0x73, 0x5f,
  37778. 0xf8, 0x69, 0x23, 0x2d, 0xe5, 0xd3, 0x81, 0xaf,
  37779. 0xbf, 0x0e, 0x44, 0xd6, 0x91, 0x72, 0xb7, 0x9a,
  37780. 0x35, 0x19, 0x19, 0x49, 0xde, 0x09, 0x70, 0x3b,
  37781. 0x94, 0x22, 0x2b, 0x13, 0xc3, 0x85, 0xc6, 0x08,
  37782. 0x1e, 0x6d, 0x2e, 0xde, 0x1e, 0x57, 0xfe, 0x18,
  37783. 0x4e, 0xf8, 0xf6, 0x01, 0x96, 0xb9, 0xa3, 0xa7,
  37784. 0xb7, 0xef, 0xf7, 0x49, 0x71, 0x91, 0xca, 0x87,
  37785. 0x41, 0xb5, 0xa0, 0x1e, 0x79, 0xcb, 0x69, 0xa6,
  37786. 0x11, 0x42, 0xe6, 0xf5, 0xd0, 0x80, 0xfb, 0xb3,
  37787. 0xe5, 0x66, 0xf7, 0x9e, 0x14, 0x6f, 0x75, 0xc8,
  37788. 0xa1, 0x09, 0x78, 0x60, 0x84, 0x1b, 0x47, 0x47,
  37789. 0xdf, 0x60, 0x4d, 0xba, 0x95, 0x4e, 0x4a, 0x8d,
  37790. 0x9e, 0x0d, 0xcc, 0xc1, 0xf6, 0x09, 0xd0, 0x5c,
  37791. 0xf8, 0xd3, 0x12, 0x19, 0xec, 0xd6, 0x0c, 0x31,
  37792. 0x2d, 0xe6, 0x84, 0x55, 0x2f, 0x09, 0x22, 0x7c,
  37793. 0xb8, 0x29, 0x29, 0x1c, 0x64, 0x57, 0x32, 0xc5,
  37794. 0xf5, 0xd4, 0xd7, 0x11, 0x63, 0x9f, 0x42, 0xa2,
  37795. 0x30, 0x80, 0xaa, 0x34, 0xfe, 0x14, 0x20, 0xf2,
  37796. 0x19, 0xbd, 0x6b, 0xcf, 0x4e, 0x3b, 0x29, 0xb9,
  37797. 0xd0, 0x22, 0x93, 0xb2, 0xda, 0x81, 0x38, 0x3e,
  37798. 0x0a, 0x51, 0xd2, 0xbb, 0x18, 0x6c, 0x7b, 0x0a,
  37799. 0x21, 0x1a, 0x0c, 0xd6, 0x3a, 0xcb, 0xfc, 0x02,
  37800. 0x10, 0x40, 0x1e, 0x98, 0x5d, 0x43, 0x6b, 0x38,
  37801. 0x03, 0xd5, 0x60, 0x1c, 0x24, 0x13, 0x6a, 0xfd,
  37802. 0x15, 0x62, 0x52, 0x2e, 0x45, 0xb4, 0x57, 0xcb,
  37803. 0x43, 0x91, 0x78, 0xbe, 0x4a, 0x87, 0xcc, 0xe4,
  37804. 0x03, 0x46, 0xd3, 0x4a, 0xe0, 0xf3, 0xc3, 0x91,
  37805. 0x03, 0xc8, 0xa3, 0xeb, 0xc9, 0xc8, 0x6c, 0x8d,
  37806. 0xb8, 0xfc, 0x55, 0x61, 0xeb, 0x0f, 0x3a, 0x14,
  37807. 0x3d, 0x4e, 0x9f, 0xe9, 0x3a, 0x5c, 0xba, 0x6f,
  37808. 0x6f, 0xca, 0xe5, 0x65, 0x0d, 0x3f, 0x43, 0xd2,
  37809. 0x66, 0x8a, 0x59, 0x56, 0xc9, 0x22, 0x89, 0x3b,
  37810. 0x81, 0x66, 0x47, 0xde, 0xd0, 0xaf, 0xc0, 0x52,
  37811. 0xa6, 0xc3, 0xd9, 0xd0, 0x1a, 0x3d, 0x3a, 0xf0,
  37812. 0xf1, 0xba, 0x80, 0x7f, 0xf1, 0x04, 0x91, 0xe1,
  37813. 0x31, 0xdc, 0x15, 0xe1, 0x65, 0xcf, 0xd0, 0x65,
  37814. 0x0a, 0x1f, 0x2c, 0x31, 0x3d, 0x79, 0x56, 0x14,
  37815. 0x1e, 0xdc, 0xc6, 0x1c, 0xb9, 0x0e, 0x9e, 0x7a,
  37816. 0xbf, 0x2f, 0xe3, 0x5f, 0xc9, 0xdc, 0x1b, 0xde,
  37817. 0x88, 0x93, 0x9f, 0xa1, 0x1f, 0x7b, 0xbe, 0x3e,
  37818. 0xb4, 0xd8, 0xff, 0xa6, 0x43, 0xb0, 0x74, 0xd7,
  37819. 0x4f, 0x45, 0x11, 0x35, 0x86, 0xe9, 0xbb, 0x12,
  37820. 0x06, 0x00, 0x03, 0xd7, 0x19, 0x41, 0xf2, 0xda,
  37821. 0x09, 0x8d, 0xc0, 0xe9, 0x6c, 0xad, 0x32, 0x55,
  37822. 0xcf, 0x32, 0x8e, 0xa2, 0xd3, 0x30, 0x8c, 0x1f,
  37823. 0x45, 0x85, 0xe8, 0x9c, 0x61, 0x3c, 0x42, 0x6b,
  37824. 0x7e, 0x79, 0x8e, 0x1e, 0xc4, 0xe9, 0x8f, 0xe6,
  37825. 0xc7, 0x1e, 0x74, 0x91, 0xf5, 0xec, 0xa0, 0xcd,
  37826. 0x05, 0x11, 0x58, 0x61, 0xbd, 0x16, 0x0e, 0x3f,
  37827. 0xe7, 0x3a, 0x58, 0xa0, 0x26, 0xba, 0x53, 0x8e,
  37828. 0x0e, 0x25, 0x6b, 0x92, 0xf1, 0xd7, 0xa2, 0x49,
  37829. 0x75, 0x70, 0x59, 0x48, 0x56, 0x86, 0x0f, 0xfd,
  37830. 0x06, 0xb6, 0x01, 0xac, 0x57, 0x55, 0x92, 0xf4,
  37831. 0xac, 0x61, 0x2b, 0x5d, 0xe7, 0x86, 0x60, 0x42,
  37832. 0x12, 0x3e, 0xbc, 0x60, 0xc5, 0x57, 0x68, 0xe3,
  37833. 0xa7, 0x60, 0x0a, 0x32, 0x60, 0x55, 0x1f, 0x2b,
  37834. 0xea, 0x22, 0xbb, 0xf6, 0xb6, 0xc8, 0x24, 0x6e,
  37835. 0x80, 0xf9, 0x12, 0x5c, 0x4b, 0xb9, 0xdb, 0x35,
  37836. 0x4d, 0xd6, 0x4a, 0xe6, 0x95, 0xc1, 0x5f, 0x50,
  37837. 0x71, 0xf4, 0xab, 0xb9, 0x63, 0x92, 0x07, 0xca,
  37838. 0xc7, 0x33, 0x1b, 0x31, 0x0f, 0x69, 0xa0, 0x5f,
  37839. 0x54, 0xb9, 0x95, 0xde, 0x52, 0x9a, 0x02, 0x3f,
  37840. 0x03, 0x3b, 0x05, 0x5d, 0xb9, 0x52, 0x87, 0xa1,
  37841. 0x4b, 0xa3, 0x0a, 0x7c, 0xc5, 0x26, 0xbb, 0x72,
  37842. 0x4c, 0x41, 0x7f, 0xba, 0x29, 0x06, 0x36, 0xa9,
  37843. 0x96, 0xf2, 0x86, 0xe3, 0xe9, 0xe9, 0x39, 0xe4,
  37844. 0xfe, 0x1c, 0x39, 0x8b, 0x5c, 0x65, 0x99, 0x95,
  37845. 0x9d, 0x0b, 0x44, 0x45, 0xa3, 0x27, 0xec, 0x46,
  37846. 0x9a, 0x16, 0x53, 0xcf, 0xae, 0xa7, 0x55, 0x2c,
  37847. 0xec, 0xec, 0x08, 0x5c, 0xca, 0xa6, 0x89, 0x38,
  37848. 0xae, 0x4a, 0xc3, 0xc4, 0x24, 0xf7, 0xe4, 0x80,
  37849. 0x43, 0x9e, 0xbd, 0x2c, 0x99, 0x2b, 0x5f, 0x6f,
  37850. 0x95, 0xec, 0x24, 0x4b, 0x65, 0x7d, 0xbd, 0xea,
  37851. 0xa9, 0xae, 0x11, 0x0a, 0xaf, 0x4d, 0x68, 0xbf,
  37852. 0x4e, 0x27, 0x41, 0x0d, 0x43, 0xce, 0xef, 0x3e,
  37853. 0x88, 0xe9, 0xc7, 0x17, 0xdd, 0x44, 0xc9, 0xee
  37854. #endif
  37855. };
  37856. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ss[] = {
  37857. #ifdef WOLFSSL_KYBER_ORIGINAL
  37858. 0xB1, 0x0F, 0x73, 0x94, 0x92, 0x6A, 0xD3, 0xB4,
  37859. 0x9C, 0x5D, 0x62, 0xD5, 0xAE, 0xB5, 0x31, 0xD5,
  37860. 0x75, 0x75, 0x38, 0xBC, 0xC0, 0xDA, 0x9E, 0x55,
  37861. 0x0D, 0x43, 0x8F, 0x1B, 0x61, 0xBD, 0x74, 0x19
  37862. #else
  37863. 0x48, 0x9d, 0xd1, 0xe9, 0xc2, 0xbe, 0x4a, 0xf3,
  37864. 0x48, 0x2b, 0xdb, 0x35, 0xbb, 0x26, 0xce, 0x76,
  37865. 0x0e, 0x6e, 0x41, 0x4d, 0xa6, 0xec, 0xbe, 0x48,
  37866. 0x99, 0x85, 0x74, 0x8a, 0x82, 0x5f, 0x1c, 0xd6
  37867. #endif
  37868. };
  37869. #ifdef WOLFSSL_SMALL_STACK
  37870. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37871. DYNAMIC_TYPE_TMP_BUFFER);
  37872. priv = (byte *)XMALLOC(KYBER1024_PRIVATE_KEY_SIZE, HEAP_HINT,
  37873. DYNAMIC_TYPE_TMP_BUFFER);
  37874. pub = (byte *)XMALLOC(KYBER1024_PUBLIC_KEY_SIZE, HEAP_HINT,
  37875. DYNAMIC_TYPE_TMP_BUFFER);
  37876. ct = (byte *)XMALLOC(KYBER1024_CIPHER_TEXT_SIZE, HEAP_HINT,
  37877. DYNAMIC_TYPE_TMP_BUFFER);
  37878. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37879. DYNAMIC_TYPE_TMP_BUFFER);
  37880. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37881. DYNAMIC_TYPE_TMP_BUFFER);
  37882. if (! (key && priv && pub && ct && ss && ss_dec))
  37883. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37884. #endif
  37885. ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
  37886. if (ret != 0)
  37887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37888. else
  37889. key_inited = 1;
  37890. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  37891. sizeof(kyber1024_rand));
  37892. if (ret != 0)
  37893. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37894. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
  37895. if (ret != 0)
  37896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37897. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
  37898. if (ret != 0)
  37899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37900. if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0)
  37901. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37902. if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
  37903. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37904. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  37905. sizeof(kyber1024enc_rand));
  37906. if (ret != 0)
  37907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37908. if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0)
  37909. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37910. if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  37911. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37912. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
  37913. if (ret != 0)
  37914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37915. if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  37916. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  37917. out:
  37918. if (key_inited)
  37919. wc_KyberKey_Free(key);
  37920. #ifdef WOLFSSL_SMALL_STACK
  37921. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37922. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37923. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37924. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37925. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37926. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  37927. #endif
  37928. return ret;
  37929. }
  37930. #endif /* WOLFSSL_KYBER1024 */
  37931. #endif /* WOLFSSL_WC_KYBER */
  37932. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
  37933. {
  37934. wc_test_ret_t ret;
  37935. WC_RNG rng;
  37936. int i;
  37937. #ifdef WOLFSSL_SMALL_STACK
  37938. KyberKey *key = NULL;
  37939. byte *priv = NULL;
  37940. byte *pub = NULL;
  37941. byte *priv2 = NULL;
  37942. byte *pub2 = NULL;
  37943. byte *ct = NULL;
  37944. byte *ss = NULL;
  37945. byte *ss_dec = NULL;
  37946. #else
  37947. KyberKey key[1];
  37948. byte priv[KYBER_MAX_PRIVATE_KEY_SIZE];
  37949. byte pub[KYBER_MAX_PUBLIC_KEY_SIZE];
  37950. byte priv2[KYBER_MAX_PRIVATE_KEY_SIZE];
  37951. byte pub2[KYBER_MAX_PUBLIC_KEY_SIZE];
  37952. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  37953. byte ss[KYBER_SS_SZ];
  37954. byte ss_dec[KYBER_SS_SZ];
  37955. #endif
  37956. int key_inited = 0;
  37957. static const int testData[][4] = {
  37958. #ifdef WOLFSSL_KYBER512
  37959. { KYBER512, KYBER512_PRIVATE_KEY_SIZE, KYBER512_PUBLIC_KEY_SIZE,
  37960. KYBER512_CIPHER_TEXT_SIZE },
  37961. #endif
  37962. #ifdef WOLFSSL_KYBER768
  37963. { KYBER768, KYBER768_PRIVATE_KEY_SIZE, KYBER768_PUBLIC_KEY_SIZE,
  37964. KYBER768_CIPHER_TEXT_SIZE },
  37965. #endif
  37966. #ifdef WOLFSSL_KYBER1024
  37967. { KYBER1024, KYBER1024_PRIVATE_KEY_SIZE, KYBER1024_PUBLIC_KEY_SIZE,
  37968. KYBER1024_CIPHER_TEXT_SIZE },
  37969. #endif
  37970. };
  37971. WOLFSSL_ENTER("kyber_test");
  37972. #ifdef WOLFSSL_SMALL_STACK
  37973. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37974. DYNAMIC_TYPE_TMP_BUFFER);
  37975. priv = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  37976. DYNAMIC_TYPE_TMP_BUFFER);
  37977. pub = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  37978. DYNAMIC_TYPE_TMP_BUFFER);
  37979. priv2 = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  37980. DYNAMIC_TYPE_TMP_BUFFER);
  37981. pub2 = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  37982. DYNAMIC_TYPE_TMP_BUFFER);
  37983. ct = (byte *)XMALLOC(KYBER_MAX_CIPHER_TEXT_SIZE, HEAP_HINT,
  37984. DYNAMIC_TYPE_TMP_BUFFER);
  37985. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37986. DYNAMIC_TYPE_TMP_BUFFER);
  37987. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37988. DYNAMIC_TYPE_TMP_BUFFER);
  37989. if (! (key && priv && pub && priv2 && pub2 && ct && ss && ss_dec))
  37990. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37991. #endif
  37992. #ifndef HAVE_FIPS
  37993. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  37994. #else
  37995. ret = wc_InitRng(&rng);
  37996. #endif
  37997. if (ret != 0)
  37998. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37999. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  38000. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38001. if (ret != 0)
  38002. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38003. else
  38004. key_inited = 1;
  38005. ret = wc_KyberKey_MakeKey(key, &rng);
  38006. if (ret != 0)
  38007. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38008. ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
  38009. if (ret != 0)
  38010. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38011. ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
  38012. if (ret != 0)
  38013. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38014. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38015. if (ret != 0)
  38016. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38017. ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
  38018. if (ret != 0)
  38019. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38020. ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
  38021. if (ret != 0)
  38022. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38023. ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
  38024. if (ret != 0)
  38025. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38026. if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
  38027. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38028. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38029. if (ret != 0)
  38030. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38031. ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
  38032. if (ret != 0)
  38033. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38034. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
  38035. if (ret != 0)
  38036. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38037. if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
  38038. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38039. ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
  38040. if (ret != 0)
  38041. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38042. if (XMEMCMP(priv, priv2, testData[i][2]) != 0)
  38043. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38044. }
  38045. wc_FreeRng(&rng);
  38046. #ifdef WOLFSSL_WC_KYBER
  38047. #ifdef WOLFSSL_KYBER512
  38048. ret = kyber512_kat();
  38049. if (ret != 0)
  38050. goto out;
  38051. #endif
  38052. #ifdef WOLFSSL_KYBER768
  38053. ret = kyber768_kat();
  38054. if (ret != 0)
  38055. goto out;
  38056. #endif
  38057. #ifdef WOLFSSL_KYBER1024
  38058. ret = kyber1024_kat();
  38059. if (ret != 0)
  38060. goto out;
  38061. #endif
  38062. #endif /* WOLFSSL_WC_KYBER */
  38063. out:
  38064. if (key_inited)
  38065. wc_KyberKey_Free(key);
  38066. #ifdef WOLFSSL_SMALL_STACK
  38067. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38068. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38069. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38070. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38071. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38072. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38073. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38074. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38075. #endif
  38076. return ret;
  38077. }
  38078. #endif /* WOLFSSL_HAVE_KYBER */
  38079. #ifdef HAVE_DILITHIUM
  38080. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  38081. static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
  38082. word32 pubKeyLen, const byte* sig, word32 sigLen)
  38083. {
  38084. byte msg[512];
  38085. dilithium_key* key;
  38086. byte * pubExported = NULL;
  38087. wc_test_ret_t ret;
  38088. int i;
  38089. int res = 0;
  38090. word32 lenExported = pubKeyLen;
  38091. int n_diff = 0;
  38092. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  38093. DYNAMIC_TYPE_TMP_BUFFER);
  38094. if (key == NULL) {
  38095. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38096. }
  38097. pubExported = (byte*)XMALLOC(pubKeyLen, HEAP_HINT,
  38098. DYNAMIC_TYPE_TMP_BUFFER);
  38099. if (pubExported == NULL) {
  38100. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38101. }
  38102. /* make dummy msg */
  38103. for (i = 0; i < (int)sizeof(msg); i++) {
  38104. msg[i] = (byte)i;
  38105. }
  38106. ret = wc_dilithium_init(key);
  38107. if (ret != 0) {
  38108. ret = WC_TEST_RET_ENC_EC(ret);
  38109. return ret;
  38110. }
  38111. ret = wc_dilithium_set_level(key, param);
  38112. if (ret != 0)
  38113. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38114. ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
  38115. if (ret != 0)
  38116. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38117. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38118. if (param >= WC_ML_DSA_DRAFT) {
  38119. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg),
  38120. &res, key);
  38121. }
  38122. else
  38123. #endif
  38124. {
  38125. ret = wc_dilithium_verify_ctx_msg(sig, sigLen, NULL, 0, msg,
  38126. (word32)sizeof(msg), &res, key);
  38127. }
  38128. if (ret != 0)
  38129. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38130. if (res != 1)
  38131. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  38132. /* Now test the export pub raw API, verify we recover the original pub. */
  38133. ret = wc_dilithium_export_public(key, pubExported, &lenExported);
  38134. if (ret != 0) {
  38135. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38136. }
  38137. if (lenExported <= 0 || lenExported != pubKeyLen) {
  38138. ERROR_OUT(WC_TEST_RET_ENC_EC(lenExported), out);
  38139. }
  38140. n_diff = XMEMCMP(pubExported, pubKey, pubKeyLen);
  38141. if (n_diff) {
  38142. ERROR_OUT(WC_TEST_RET_ENC_EC(n_diff), out);
  38143. }
  38144. out:
  38145. wc_dilithium_free(key);
  38146. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38147. XFREE(pubExported, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38148. return ret;
  38149. }
  38150. #ifndef WOLFSSL_NO_ML_DSA_44
  38151. static wc_test_ret_t dilithium_param_44_vfy_test(void)
  38152. {
  38153. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_pub_key[] = {
  38154. 0xd8, 0xac, 0xaf, 0xd8, 0x2e, 0x14, 0x23, 0x78, 0xf7, 0x0d, 0x9a, 0x04,
  38155. 0x2b, 0x92, 0x48, 0x67, 0x60, 0x55, 0x34, 0xd9, 0xac, 0x0b, 0xc4, 0x1f,
  38156. 0x46, 0xe8, 0x85, 0xb9, 0x2e, 0x1b, 0x10, 0x3a, 0x75, 0x7a, 0xc2, 0xbc,
  38157. 0x76, 0xf0, 0x6d, 0x05, 0xa4, 0x78, 0x48, 0x84, 0x26, 0x69, 0xbd, 0x26,
  38158. 0x1d, 0x73, 0x60, 0xaa, 0x57, 0x9d, 0x8c, 0x66, 0xb1, 0x19, 0xea, 0x11,
  38159. 0xff, 0xbb, 0xf6, 0xeb, 0x26, 0x26, 0xac, 0x78, 0x74, 0x46, 0x6d, 0x51,
  38160. 0x6e, 0x92, 0xdf, 0x6a, 0x98, 0x41, 0xe9, 0x10, 0xf2, 0xcc, 0xa8, 0x7a,
  38161. 0x50, 0xdb, 0x1f, 0x4c, 0x42, 0x19, 0xd5, 0xbc, 0x76, 0x20, 0x6f, 0x2f,
  38162. 0xbf, 0xc2, 0xc9, 0x1b, 0x02, 0xb5, 0xb1, 0x09, 0x46, 0x06, 0x87, 0x02,
  38163. 0xac, 0x3d, 0xcf, 0xc3, 0xa5, 0x1b, 0xf0, 0xce, 0xd4, 0x9e, 0x84, 0x34,
  38164. 0x3c, 0x24, 0x7d, 0x89, 0xf3, 0xbf, 0x9c, 0x18, 0x9d, 0x1b, 0x1d, 0xd4,
  38165. 0xf6, 0xda, 0xc9, 0xa4, 0x14, 0xc4, 0x6b, 0xd7, 0x05, 0x6d, 0xed, 0x54,
  38166. 0x42, 0x6b, 0x5f, 0x6d, 0x1e, 0xda, 0x6b, 0x47, 0x70, 0xe5, 0x4e, 0xe7,
  38167. 0x25, 0x06, 0xf8, 0x28, 0x24, 0x34, 0xd6, 0xe5, 0xbe, 0xc5, 0x4f, 0x9e,
  38168. 0x5d, 0x33, 0xfc, 0xef, 0xe4, 0xe9, 0x55, 0x67, 0x93, 0x1f, 0x2e, 0x11,
  38169. 0x3a, 0x2e, 0xf2, 0xbb, 0x82, 0x09, 0x8d, 0xb2, 0x09, 0xf3, 0x2f, 0xef,
  38170. 0x6f, 0x38, 0xc6, 0x56, 0xf2, 0x23, 0x08, 0x63, 0x99, 0x7f, 0x4e, 0xc0,
  38171. 0x9d, 0x08, 0x9d, 0xa1, 0x59, 0x6e, 0xe1, 0x00, 0x2c, 0x99, 0xec, 0x83,
  38172. 0x2f, 0x12, 0x97, 0x2f, 0x75, 0x04, 0x67, 0x44, 0xb5, 0x95, 0xce, 0xc6,
  38173. 0x3e, 0x7a, 0x10, 0x77, 0x5e, 0xbe, 0x9c, 0x0f, 0xb3, 0xc7, 0x38, 0xbf,
  38174. 0x9e, 0x35, 0x8f, 0xe4, 0x8d, 0x19, 0xc3, 0x41, 0xb1, 0x0b, 0x8c, 0x10,
  38175. 0x9a, 0x58, 0xec, 0x4f, 0xb3, 0xe9, 0x5b, 0x72, 0x4b, 0xb8, 0x99, 0x34,
  38176. 0x9a, 0xcd, 0xb0, 0x69, 0xd0, 0x67, 0xef, 0x96, 0xb9, 0xe5, 0x54, 0x92,
  38177. 0xb7, 0x1a, 0x52, 0xf6, 0x0a, 0xc2, 0x23, 0x8d, 0x4f, 0xad, 0x00, 0xae,
  38178. 0x0f, 0x97, 0xfa, 0xce, 0x96, 0xba, 0xe7, 0x74, 0x55, 0xd4, 0xaf, 0xbf,
  38179. 0xa1, 0x32, 0x91, 0x2d, 0x03, 0x9f, 0xe3, 0x10, 0x8c, 0x77, 0x5d, 0x26,
  38180. 0x76, 0xf1, 0x87, 0x90, 0xf0, 0x20, 0xd1, 0xea, 0xf7, 0xa4, 0xe8, 0x2c,
  38181. 0x32, 0x1c, 0x55, 0xc0, 0x5d, 0xc9, 0xcd, 0x4e, 0x8f, 0x0d, 0xef, 0x0a,
  38182. 0x27, 0xb6, 0x4f, 0xa4, 0xd3, 0xa4, 0xed, 0x33, 0x22, 0xa1, 0xd3, 0x15,
  38183. 0xac, 0x1a, 0x20, 0x4e, 0x28, 0x8c, 0x8c, 0xd0, 0x71, 0xd1, 0xf2, 0xdb,
  38184. 0x33, 0x63, 0xb6, 0xa4, 0xf2, 0x17, 0x3c, 0x12, 0xb0, 0xad, 0xef, 0x31,
  38185. 0x91, 0xfe, 0xe5, 0x53, 0x99, 0xb6, 0x85, 0x63, 0xfa, 0xe6, 0xcd, 0xf6,
  38186. 0xb9, 0xce, 0x4a, 0x7d, 0x4a, 0x49, 0x29, 0xd2, 0xd9, 0xc9, 0x47, 0x4a,
  38187. 0x8a, 0x5c, 0x14, 0x5e, 0x0f, 0x7c, 0xc3, 0x91, 0xb0, 0xab, 0x37, 0xf5,
  38188. 0x26, 0x8d, 0x46, 0x74, 0x49, 0xad, 0x51, 0xc3, 0x11, 0xfa, 0x85, 0x15,
  38189. 0xa5, 0x84, 0xc1, 0xe0, 0x3c, 0x13, 0x6d, 0x13, 0xa3, 0xe6, 0xa8, 0x3c,
  38190. 0x22, 0xac, 0x17, 0x48, 0x57, 0x7c, 0x81, 0xe2, 0x4e, 0xd8, 0x33, 0x5d,
  38191. 0x4d, 0x65, 0xf7, 0xe1, 0xb8, 0x00, 0x78, 0x09, 0x16, 0xb0, 0x0b, 0xca,
  38192. 0x15, 0x0d, 0xcd, 0x9a, 0xd8, 0x47, 0x4c, 0x9b, 0x69, 0xb2, 0xa0, 0x9d,
  38193. 0x96, 0x96, 0x52, 0x6d, 0x89, 0xad, 0xff, 0x55, 0xde, 0x7b, 0xd6, 0x3d,
  38194. 0x1d, 0x5e, 0x8d, 0xf1, 0xfc, 0x48, 0x1c, 0x50, 0x59, 0x55, 0xb9, 0x07,
  38195. 0xfd, 0x6b, 0xcb, 0x95, 0xa6, 0x14, 0x73, 0xdb, 0x40, 0x40, 0x1c, 0x44,
  38196. 0xe6, 0x79, 0x30, 0x88, 0xbd, 0xa0, 0xde, 0x9b, 0xb8, 0x76, 0xf8, 0x98,
  38197. 0x56, 0x4b, 0xb9, 0x7a, 0xf6, 0xd4, 0x73, 0x89, 0x6b, 0xf7, 0x7d, 0x05,
  38198. 0x33, 0xbe, 0xb6, 0x1c, 0x4d, 0xa7, 0x12, 0x3b, 0x3f, 0xed, 0x4a, 0x0f,
  38199. 0xae, 0xa7, 0x6a, 0x26, 0x0d, 0x01, 0x84, 0x84, 0xa8, 0x0e, 0xc1, 0xc1,
  38200. 0xfd, 0xe4, 0xa9, 0xe2, 0x3f, 0xab, 0xce, 0x20, 0x90, 0x86, 0x79, 0xa2,
  38201. 0x40, 0xd0, 0xef, 0x79, 0x34, 0x2b, 0xe8, 0xc9, 0x54, 0xa7, 0x19, 0x62,
  38202. 0xcc, 0x20, 0x79, 0x3f, 0x5b, 0x9c, 0x61, 0xc2, 0xc1, 0xd2, 0x36, 0x7c,
  38203. 0x8e, 0xe3, 0x01, 0xbe, 0xc4, 0xb2, 0xb8, 0x07, 0x51, 0x23, 0x5b, 0x5d,
  38204. 0x00, 0xe6, 0x7f, 0xd6, 0xbb, 0x32, 0xa9, 0x7e, 0xb4, 0x30, 0xeb, 0x5e,
  38205. 0x6d, 0xed, 0xb2, 0xc3, 0x88, 0x81, 0xa3, 0x3b, 0x1f, 0x1e, 0xf9, 0x48,
  38206. 0x10, 0xd6, 0x01, 0x65, 0x5f, 0x6d, 0xc5, 0xeb, 0x76, 0x5f, 0x10, 0x79,
  38207. 0xaa, 0xc0, 0x86, 0xe7, 0x44, 0x95, 0x44, 0x4b, 0x54, 0x0c, 0x46, 0x2a,
  38208. 0x98, 0x01, 0x6e, 0xc0, 0xb9, 0x59, 0x2a, 0xff, 0x8f, 0xb3, 0x80, 0x15,
  38209. 0xec, 0xcd, 0x39, 0x36, 0xd7, 0x2f, 0x20, 0x9e, 0x3a, 0xc1, 0x90, 0xe5,
  38210. 0x99, 0x27, 0x16, 0xd7, 0x6c, 0x30, 0x10, 0x12, 0x03, 0x3e, 0xdc, 0xb9,
  38211. 0x03, 0x25, 0xb0, 0x8a, 0x27, 0x4d, 0x1a, 0x32, 0x36, 0x54, 0xc0, 0xba,
  38212. 0x22, 0xb2, 0xe2, 0xf6, 0x39, 0x23, 0x03, 0xc4, 0xc9, 0xe4, 0x0d, 0x99,
  38213. 0xfb, 0x98, 0xa5, 0x9b, 0x12, 0x9b, 0x58, 0x44, 0x74, 0x9f, 0x65, 0x61,
  38214. 0x51, 0xba, 0x31, 0x60, 0x9c, 0xec, 0xf8, 0x4d, 0x36, 0x61, 0xd1, 0x33,
  38215. 0x6d, 0xa6, 0x28, 0x75, 0xba, 0x7c, 0x82, 0xcb, 0x7e, 0xbe, 0x8f, 0x2d,
  38216. 0x21, 0x84, 0xb9, 0xf2, 0x4e, 0x7b, 0x95, 0x99, 0x11, 0xf3, 0xe1, 0xc0,
  38217. 0x6a, 0x44, 0xae, 0x11, 0xcb, 0x04, 0xa0, 0xf2, 0x3e, 0x17, 0xdf, 0xb2,
  38218. 0x6a, 0xdf, 0x5c, 0xf3, 0x8a, 0xf8, 0x90, 0x86, 0x64, 0xea, 0x0a, 0x32,
  38219. 0x7f, 0x9f, 0x90, 0xa8, 0x9d, 0x33, 0x12, 0xa6, 0xa4, 0xe7, 0x74, 0xa0,
  38220. 0x75, 0xa9, 0x65, 0xf8, 0x39, 0xae, 0x14, 0x32, 0x79, 0xcc, 0xaa, 0x34,
  38221. 0x86, 0x55, 0xcc, 0x99, 0xb7, 0x00, 0x05, 0x8b, 0xe3, 0x76, 0x28, 0x12,
  38222. 0xb6, 0x2a, 0x3e, 0x44, 0x8d, 0xf4, 0xba, 0xef, 0xf6, 0xdc, 0x29, 0x08,
  38223. 0x29, 0x7d, 0xd1, 0x1d, 0x17, 0x15, 0xb6, 0xb6, 0x58, 0x67, 0xd5, 0xd3,
  38224. 0x12, 0x05, 0x4e, 0xb0, 0xc3, 0x83, 0xe0, 0x35, 0x30, 0x60, 0x59, 0xa0,
  38225. 0xc5, 0x97, 0x5b, 0x81, 0xd3, 0x68, 0x6c, 0x8c, 0x17, 0x28, 0xa9, 0x24,
  38226. 0x4f, 0x80, 0x20, 0xa5, 0x21, 0x9f, 0x8f, 0x15, 0x89, 0x2d, 0x87, 0xae,
  38227. 0x2e, 0xcc, 0x73, 0x3e, 0x06, 0x43, 0xbc, 0xb3, 0x1b, 0xa6, 0x72, 0xaa,
  38228. 0xa3, 0xaa, 0xbb, 0x6f, 0x2d, 0x68, 0x60, 0xcf, 0x05, 0x94, 0x25, 0x3e,
  38229. 0x59, 0xf3, 0x64, 0x61, 0x5e, 0x78, 0x9a, 0x7e, 0x0d, 0x50, 0x45, 0x78,
  38230. 0x51, 0xab, 0x11, 0xb1, 0xc6, 0x95, 0xfc, 0x29, 0x28, 0x10, 0x9c, 0x1a,
  38231. 0x8c, 0x37, 0xb5, 0x4f, 0x0e, 0xed, 0x4a, 0x28, 0x6c, 0xaa, 0xb7, 0x0d,
  38232. 0x12, 0xfa, 0x87, 0x5d, 0xd4, 0x9a, 0xb7, 0x2b, 0x46, 0x90, 0x58, 0x4e,
  38233. 0xd7, 0x8b, 0x41, 0x1b, 0xf8, 0xc4, 0xc2, 0xde, 0xda, 0xec, 0x61, 0xe7,
  38234. 0xbf, 0x11, 0xdd, 0x6e, 0x4e, 0x6a, 0xd4, 0x87, 0x01, 0xe4, 0xac, 0xe8,
  38235. 0xaf, 0x2b, 0x01, 0xe1, 0x09, 0x20, 0xe0, 0xbd, 0x7d, 0x03, 0x73, 0x23,
  38236. 0xdf, 0x77, 0x71, 0xa4, 0x25, 0x8b, 0x0a, 0x93, 0x49, 0x32, 0x45, 0x1a,
  38237. 0xa4, 0x94, 0x31, 0x61, 0x2e, 0x17, 0x39, 0x8a, 0x66, 0xc9, 0xf9, 0x20,
  38238. 0x2d, 0x6a, 0x97, 0x2f, 0xe7, 0x26, 0xd8, 0x01, 0x42, 0x65, 0xcf, 0xce,
  38239. 0xd4, 0x24, 0x41, 0xfb, 0x9b, 0x6f, 0xf1, 0xc2, 0x9e, 0xd5, 0x08, 0x0c,
  38240. 0xdc, 0x4d, 0x8e, 0xae, 0xcb, 0x5f, 0xd4, 0xcd, 0x7c, 0xf6, 0x82, 0xc6,
  38241. 0xee, 0xf9, 0x88, 0x3a, 0x34, 0x07, 0x04, 0xb4, 0x84, 0x69, 0xb3, 0xa4,
  38242. 0x67, 0xab, 0x09, 0xc0, 0x83, 0xfe, 0x59, 0xaf, 0x18, 0x2c, 0xc8, 0x09,
  38243. 0xc1, 0xbb, 0x13, 0x7c, 0xce, 0x01, 0x5d, 0x85, 0xaa, 0x10, 0x28, 0xa2,
  38244. 0x96, 0x98, 0x69, 0x23, 0xa3, 0xe7, 0x67, 0xbc, 0x7c, 0x7e, 0xde, 0x4b,
  38245. 0x36, 0xab, 0x94, 0xd2, 0xb8, 0xf9, 0xdf, 0xee, 0xa1, 0x69, 0xa1, 0xc8,
  38246. 0xe9, 0x83, 0x21, 0xac, 0x1b, 0x39, 0xf7, 0x6d, 0xbf, 0x8c, 0xdb, 0xd6,
  38247. 0x2f, 0xc9, 0x3c, 0x3d, 0x50, 0xcf, 0x7f, 0xbe, 0x4a, 0x8d, 0xd8, 0x14,
  38248. 0xad, 0x69, 0xb0, 0x3e, 0x8a, 0xaf, 0xeb, 0xd9, 0x1a, 0x15, 0x4a, 0xe4,
  38249. 0xdd, 0xd9, 0xb2, 0xf8, 0x6b, 0xe2, 0x42, 0x9e, 0x29, 0x16, 0xfc, 0x85,
  38250. 0x9c, 0x47, 0x4b, 0x1f, 0x3d, 0x7b, 0x8c, 0xe1, 0x6d, 0xa3, 0xb8, 0x0a,
  38251. 0xe6, 0xfa, 0x27, 0xfe, 0x52, 0x72, 0xab, 0x3a, 0xa6, 0x58, 0xd7, 0x53,
  38252. 0xaf, 0x9f, 0xee, 0x03, 0x85, 0xfc, 0xa4, 0x7a, 0x72, 0x29, 0x7e, 0x62,
  38253. 0x28, 0x08, 0x79, 0xa8, 0xb8, 0xc7, 0x51, 0x8d, 0xaa, 0x40, 0x2d, 0x4a,
  38254. 0xd9, 0x47, 0xb4, 0xa8, 0xa2, 0x0a, 0x43, 0xd0, 0xe0, 0x4a, 0x39, 0xa3,
  38255. 0x06, 0x08, 0x9a, 0xe2, 0xf3, 0xf2, 0xf8, 0xb9, 0x9f, 0x63, 0x32, 0xa0,
  38256. 0x65, 0x0b, 0xb0, 0x50, 0x96, 0xa6, 0xa8, 0x7a, 0x18, 0xdd, 0x6c, 0xd1,
  38257. 0x9b, 0xd9, 0x4e, 0x76, 0x8f, 0xfb, 0x22, 0xa6, 0x1d, 0x29, 0xfc, 0xb8,
  38258. 0x47, 0x29, 0xb6, 0xd1, 0xb1, 0x63, 0x4a, 0x36, 0x1b, 0x10, 0xe6, 0x4c,
  38259. 0x65, 0x68, 0x1f, 0xad, 0x4f, 0x7d, 0x6b, 0x01, 0x41, 0x18, 0x5f, 0xba,
  38260. 0x3d, 0xa6, 0x54, 0x28, 0x58, 0xd5, 0x81, 0x60, 0xdf, 0x84, 0x76, 0x00,
  38261. 0x21, 0x53, 0xeb, 0xd3, 0xa6, 0xec, 0x7d, 0x3c, 0xb8, 0xcd, 0x91, 0x4c,
  38262. 0x2f, 0x4b, 0x2e, 0x23, 0x4c, 0x0f, 0x0f, 0xe0, 0x14, 0xa5, 0xe7, 0xe5,
  38263. 0x70, 0x8d, 0x8b, 0x9c
  38264. };
  38265. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38266. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_pub_key[] = {
  38267. 0xea, 0x05, 0x24, 0x0d, 0x80, 0x72, 0x25, 0x55, 0xf4, 0x5b,
  38268. 0xc2, 0x13, 0x8b, 0x87, 0x5d, 0x31, 0x99, 0x2f, 0x1d, 0xa9,
  38269. 0x41, 0x09, 0x05, 0x76, 0xa7, 0xb7, 0x5e, 0x8c, 0x44, 0xe2,
  38270. 0x64, 0x79, 0xa0, 0xec, 0x1f, 0x24, 0xb6, 0xc8, 0x05, 0x5b,
  38271. 0xc1, 0x18, 0xb0, 0xb7, 0xcf, 0x8c, 0x60, 0x67, 0x6b, 0x81,
  38272. 0x44, 0x27, 0xb6, 0x0e, 0xfd, 0x9b, 0xc3, 0xcb, 0x52, 0x31,
  38273. 0xfa, 0xc9, 0x34, 0x8d, 0x22, 0x1e, 0x07, 0x9d, 0x96, 0x6a,
  38274. 0x63, 0x83, 0x5c, 0xd7, 0x83, 0x2d, 0x7f, 0x48, 0x64, 0x79,
  38275. 0xca, 0xb4, 0x9f, 0xa2, 0x02, 0xb7, 0x86, 0x1d, 0x0e, 0xc7,
  38276. 0xf9, 0x6c, 0x07, 0xc0, 0x35, 0x6a, 0x34, 0x79, 0x7c, 0xb8,
  38277. 0x0f, 0xed, 0x98, 0x50, 0xfb, 0x51, 0xe0, 0x36, 0x44, 0x4c,
  38278. 0xc6, 0x35, 0xa2, 0xbb, 0x55, 0xb0, 0x5c, 0x39, 0x08, 0x02,
  38279. 0x20, 0x35, 0x5c, 0x56, 0x6d, 0x2e, 0xb9, 0xef, 0x21, 0x26,
  38280. 0x87, 0x87, 0x85, 0x8a, 0x32, 0xb5, 0xa7, 0x68, 0x70, 0x3a,
  38281. 0xfd, 0x0d, 0x21, 0x48, 0x91, 0xa3, 0x29, 0xc1, 0x2a, 0x38,
  38282. 0xe5, 0x26, 0x31, 0x1f, 0x42, 0xde, 0x0b, 0x25, 0xff, 0x1d,
  38283. 0x6b, 0xb4, 0xe0, 0x5d, 0x2d, 0xcf, 0x44, 0xd5, 0x7d, 0xc4,
  38284. 0xf6, 0x95, 0xf2, 0x06, 0x4f, 0x83, 0x88, 0x9d, 0x1e, 0xeb,
  38285. 0x1c, 0x09, 0x45, 0x62, 0x67, 0x3d, 0xff, 0x51, 0x47, 0xe8,
  38286. 0xbc, 0x9b, 0x03, 0x1f, 0xc7, 0x72, 0x65, 0xce, 0xa8, 0x8c,
  38287. 0xc2, 0xa0, 0xc2, 0xbd, 0x5b, 0x7c, 0x17, 0x16, 0x8b, 0x72,
  38288. 0xfa, 0xb1, 0xbd, 0xdf, 0x49, 0xd6, 0xa1, 0x00, 0x65, 0xbe,
  38289. 0x82, 0xe7, 0x68, 0xc7, 0xe7, 0xbc, 0xc2, 0xa4, 0xdb, 0xaa,
  38290. 0xcc, 0xea, 0x41, 0x52, 0x7f, 0x56, 0xb4, 0x68, 0x1f, 0x92,
  38291. 0x96, 0x0f, 0xce, 0xd4, 0xd0, 0x87, 0x4c, 0x4a, 0x73, 0xb5,
  38292. 0x6c, 0xd4, 0x69, 0x55, 0x15, 0x47, 0xdc, 0x94, 0x7f, 0xd2,
  38293. 0x54, 0x5e, 0xb2, 0x90, 0xc2, 0x47, 0xe4, 0xf5, 0xde, 0x8b,
  38294. 0x9b, 0xc6, 0x5d, 0x50, 0x95, 0x60, 0xe0, 0xf0, 0xa7, 0x4e,
  38295. 0xe0, 0xcd, 0x41, 0x09, 0xef, 0xb3, 0x3d, 0x90, 0x5c, 0x77,
  38296. 0x54, 0xec, 0x9e, 0x5d, 0x8a, 0xe7, 0x09, 0x5c, 0xc9, 0x58,
  38297. 0x0c, 0xd0, 0x42, 0x35, 0xd2, 0x14, 0x59, 0x38, 0x69, 0xad,
  38298. 0xf9, 0xb5, 0xbf, 0x8a, 0x8e, 0x33, 0xd8, 0x5e, 0x7a, 0x55,
  38299. 0xd0, 0x53, 0x15, 0x40, 0x4e, 0xc5, 0x86, 0xd7, 0x8f, 0x5f,
  38300. 0x2f, 0x55, 0x82, 0xc2, 0x4f, 0x16, 0xe5, 0xea, 0x1c, 0xbc,
  38301. 0xff, 0x5e, 0x1f, 0x39, 0x46, 0x70, 0x54, 0x7a, 0x3a, 0x27,
  38302. 0x16, 0x1a, 0x2b, 0x6c, 0xd2, 0xb7, 0x80, 0xd3, 0xd1, 0x9d,
  38303. 0x25, 0x59, 0xed, 0xe6, 0x51, 0xb1, 0xf2, 0xad, 0x7e, 0x51,
  38304. 0x78, 0x14, 0x2b, 0x19, 0xae, 0x64, 0x72, 0x0f, 0xd8, 0x18,
  38305. 0x79, 0x8e, 0x66, 0x88, 0xd3, 0xa4, 0xa3, 0xc3, 0x76, 0x21,
  38306. 0xcb, 0xe4, 0x79, 0x5e, 0x95, 0x74, 0xe3, 0x31, 0x18, 0x79,
  38307. 0xed, 0xc7, 0xe7, 0xfb, 0x86, 0x48, 0x1b, 0x7b, 0x75, 0x5b,
  38308. 0x7f, 0x7c, 0x82, 0xc5, 0xab, 0x11, 0xb4, 0x5d, 0x59, 0x6f,
  38309. 0x78, 0xb2, 0xa5, 0x39, 0xc6, 0x63, 0x38, 0x6c, 0xeb, 0x50,
  38310. 0x06, 0x14, 0x76, 0xf0, 0xe8, 0xfb, 0x11, 0x95, 0x1f, 0x9d,
  38311. 0x9c, 0xa6, 0xe1, 0xe2, 0x0d, 0xa3, 0x66, 0xfc, 0x20, 0x83,
  38312. 0x50, 0x0e, 0x53, 0x75, 0xb5, 0x12, 0xf4, 0xdf, 0x31, 0x46,
  38313. 0x83, 0xac, 0x5b, 0xf3, 0x99, 0xa6, 0xd1, 0x7b, 0x2b, 0xc5,
  38314. 0xdc, 0x71, 0x07, 0x27, 0x33, 0x35, 0x34, 0xf5, 0x30, 0x19,
  38315. 0xc1, 0x3b, 0xba, 0x8a, 0xaf, 0x7e, 0x49, 0x93, 0x48, 0x5b,
  38316. 0x38, 0xc0, 0xbc, 0x2e, 0xc7, 0x59, 0x1b, 0xd9, 0xf5, 0xcc,
  38317. 0x86, 0xf5, 0x7b, 0x4d, 0xd7, 0x39, 0xa7, 0xa2, 0x56, 0x20,
  38318. 0x48, 0x98, 0x7d, 0x4f, 0x75, 0x56, 0x9b, 0xb8, 0x95, 0x45,
  38319. 0x17, 0xf3, 0x86, 0x3d, 0x97, 0x0a, 0x49, 0x1b, 0xca, 0xff,
  38320. 0x20, 0xc0, 0x24, 0x2c, 0x51, 0xc2, 0x0a, 0x3c, 0xbf, 0x07,
  38321. 0x60, 0x1c, 0x88, 0x85, 0x9b, 0x85, 0x2d, 0x4a, 0xfe, 0x5a,
  38322. 0x1c, 0x90, 0xf5, 0x90, 0x12, 0xd3, 0x03, 0x3c, 0x8c, 0x2e,
  38323. 0x95, 0x4a, 0x47, 0x76, 0x0f, 0x1f, 0x5d, 0x9e, 0xed, 0xc5,
  38324. 0x64, 0xc4, 0x9b, 0xbf, 0x86, 0xc5, 0x63, 0x84, 0x33, 0x00,
  38325. 0xf1, 0x26, 0x18, 0x21, 0xf3, 0x88, 0x1a, 0x08, 0x18, 0x6d,
  38326. 0x2f, 0xef, 0xd5, 0xeb, 0x2f, 0x69, 0xc8, 0x6e, 0x92, 0x34,
  38327. 0xfc, 0x72, 0x3d, 0x9a, 0xa7, 0x9e, 0x51, 0xfb, 0x56, 0xe3,
  38328. 0xdc, 0xf4, 0x8f, 0x9b, 0x6d, 0x0d, 0x2a, 0xec, 0x66, 0x12,
  38329. 0x26, 0x35, 0xbd, 0x61, 0xc2, 0x67, 0x19, 0xf5, 0x7e, 0xa1,
  38330. 0x67, 0xa2, 0x9c, 0x3b, 0x67, 0xb0, 0xc2, 0x51, 0x6a, 0x37,
  38331. 0x7c, 0x48, 0xe9, 0x4b, 0xb9, 0xa3, 0x38, 0x2f, 0xfc, 0xde,
  38332. 0xb4, 0x7c, 0xda, 0x52, 0x84, 0x0b, 0xb0, 0xd9, 0x08, 0xe9,
  38333. 0x7a, 0x4a, 0x6f, 0x79, 0x29, 0x3d, 0xc4, 0x5c, 0x78, 0xee,
  38334. 0x63, 0xb6, 0x96, 0x68, 0xd9, 0x82, 0x4e, 0xc1, 0x1b, 0x6f,
  38335. 0x52, 0xf5, 0xb3, 0xfb, 0xe8, 0xc4, 0x2a, 0x07, 0xc6, 0x3b,
  38336. 0x85, 0x0d, 0xf4, 0xbf, 0xb0, 0x6b, 0xfb, 0xce, 0x1d, 0xb4,
  38337. 0xbf, 0x63, 0x0b, 0x91, 0x67, 0xc4, 0xa3, 0x06, 0xa4, 0xaf,
  38338. 0x6c, 0xd3, 0xe5, 0x8b, 0x87, 0x4e, 0x64, 0x9c, 0xb1, 0xf3,
  38339. 0x70, 0x7c, 0x68, 0x43, 0x46, 0x13, 0x46, 0xee, 0x27, 0x75,
  38340. 0x12, 0x45, 0x42, 0xde, 0xa5, 0x8d, 0xcf, 0xf7, 0x09, 0x87,
  38341. 0xa8, 0x80, 0x3d, 0xb6, 0x45, 0xee, 0x41, 0x2d, 0x7c, 0x45,
  38342. 0x01, 0x9d, 0xaa, 0x78, 0xa8, 0x10, 0xa4, 0xfd, 0xb5, 0x5f,
  38343. 0xee, 0x0f, 0x77, 0xba, 0x73, 0xff, 0x49, 0xdc, 0xfa, 0x39,
  38344. 0xd6, 0xa3, 0x6f, 0x25, 0xb9, 0x63, 0x2c, 0x92, 0xc5, 0xdf,
  38345. 0xfb, 0xba, 0x89, 0xf9, 0xfa, 0x94, 0x5b, 0x6f, 0x5a, 0x4d,
  38346. 0x1c, 0xe4, 0xc9, 0x10, 0xf9, 0xa0, 0xe8, 0xc4, 0xcb, 0x55,
  38347. 0x1a, 0xdb, 0x56, 0x5f, 0x8e, 0x91, 0x03, 0x23, 0xca, 0xb0,
  38348. 0x1f, 0xef, 0xb8, 0x6c, 0x13, 0x5a, 0x99, 0x25, 0xf0, 0x49,
  38349. 0xa9, 0x5a, 0x45, 0xf7, 0xfd, 0x1a, 0xc2, 0x71, 0x06, 0xe3,
  38350. 0x2d, 0x25, 0x64, 0xb0, 0x52, 0x12, 0x03, 0x62, 0xc7, 0xb6,
  38351. 0xf9, 0xdc, 0x1f, 0x78, 0xff, 0x8b, 0xfa, 0xde, 0x7f, 0x71,
  38352. 0xa6, 0x35, 0x3e, 0xac, 0x20, 0x54, 0x94, 0xa7, 0x2e, 0x9d,
  38353. 0x47, 0x17, 0x4b, 0xad, 0x92, 0xb3, 0x14, 0x26, 0x8c, 0x5a,
  38354. 0xd0, 0x16, 0x4b, 0x22, 0xe9, 0x0c, 0x79, 0x6b, 0x8e, 0xac,
  38355. 0x0d, 0x12, 0xf5, 0x66, 0x8e, 0x82, 0x1a, 0x44, 0xf3, 0xe9,
  38356. 0x56, 0x5a, 0xcd, 0x1c, 0x1b, 0x81, 0x7b, 0x63, 0x59, 0xfe,
  38357. 0xc8, 0xc0, 0xe3, 0xda, 0x16, 0x6b, 0x6f, 0x0d, 0xba, 0x0e,
  38358. 0x47, 0x12, 0x86, 0x9e, 0xf0, 0x3b, 0x4d, 0x87, 0x3b, 0xf2,
  38359. 0x75, 0x73, 0x2d, 0xdf, 0xca, 0x76, 0x0b, 0xbd, 0xe7, 0xb7,
  38360. 0x74, 0x24, 0xf3, 0xc6, 0xe6, 0x75, 0x3f, 0x8b, 0x6a, 0xd9,
  38361. 0xad, 0xed, 0xc0, 0x70, 0x04, 0x1e, 0x0b, 0x8e, 0x8b, 0x7f,
  38362. 0xea, 0xbc, 0x39, 0x6b, 0x8a, 0x44, 0xa6, 0x9a, 0x2d, 0x0d,
  38363. 0x8c, 0x21, 0x60, 0x09, 0xd2, 0x4a, 0xe0, 0x62, 0xcf, 0xfa,
  38364. 0xe8, 0x9b, 0x35, 0x6f, 0x23, 0x2f, 0xb5, 0x65, 0x08, 0x60,
  38365. 0x92, 0x15, 0xd0, 0x5b, 0x63, 0xcc, 0x65, 0x05, 0xd1, 0xef,
  38366. 0x0f, 0x7e, 0x1b, 0xb3, 0x8e, 0xc6, 0x12, 0x85, 0xc9, 0x82,
  38367. 0x53, 0x79, 0x2e, 0x80, 0x5f, 0x0c, 0x7b, 0xc7, 0x1c, 0x83,
  38368. 0x41, 0x06, 0xd8, 0x41, 0xc9, 0xe7, 0xb9, 0x4b, 0xa1, 0x61,
  38369. 0xc6, 0x86, 0x67, 0xf5, 0x10, 0xf7, 0x34, 0x0d, 0x39, 0x9e,
  38370. 0x2b, 0x5f, 0x19, 0x06, 0x02, 0xa5, 0x02, 0x23, 0x71, 0xc2,
  38371. 0x12, 0x65, 0xcc, 0x81, 0x06, 0xfd, 0x8d, 0x09, 0x68, 0x37,
  38372. 0x06, 0x3b, 0xff, 0xc4, 0x24, 0xb3, 0x1f, 0xd6, 0xe6, 0x8f,
  38373. 0x9c, 0x74, 0x2c, 0x5e, 0xc5, 0xf4, 0xe9, 0xeb, 0xca, 0xd3,
  38374. 0x04, 0x5b, 0x92, 0x9e, 0x5c, 0x1a, 0x1d, 0xa1, 0xa7, 0x34,
  38375. 0xd2, 0x05, 0xae, 0xdb, 0x3d, 0x71, 0x10, 0x6e, 0x30, 0xd9,
  38376. 0xa3, 0x44, 0xa0, 0xbd, 0x9e, 0x7b, 0xb5, 0x12, 0x8a, 0x12,
  38377. 0x07, 0x60, 0xd7, 0x1f, 0x92, 0xe6, 0xfe, 0x04, 0xa9, 0x3e,
  38378. 0x62, 0x64, 0x00, 0x5f, 0x7c, 0x7b, 0x34, 0x09, 0xeb, 0x4a,
  38379. 0x18, 0x9e, 0x77, 0x72, 0x3a, 0x31, 0x1a, 0x62, 0x2a, 0xb5,
  38380. 0xcb, 0x4e, 0x53, 0xce, 0xad, 0x8b, 0x5a, 0x20, 0x4f, 0xd7,
  38381. 0x3e, 0x16, 0xf8, 0x10, 0xe2, 0xae, 0xbd, 0x3f, 0x02, 0xa9,
  38382. 0x18, 0xa0, 0x01, 0x18, 0x84, 0x95, 0x22, 0x2e, 0x93, 0x76,
  38383. 0x44, 0x4e, 0x11, 0x7b, 0x03, 0x51, 0x50, 0x19, 0x79, 0xe7,
  38384. 0xbb, 0x5c, 0x7b, 0xca, 0x74, 0xb4, 0x25, 0x26, 0xdb, 0x66,
  38385. 0xaa, 0x0b, 0x21, 0x07, 0xfb, 0x7a, 0x96, 0x10, 0x7d, 0x99,
  38386. 0xa9, 0x16, 0xcb, 0x0e, 0xba, 0x63, 0xab, 0x95, 0xfc, 0x5a,
  38387. 0xbe, 0xa6, 0x7f, 0xd8, 0xb4, 0xcd, 0x7c, 0xc5, 0xd0, 0xb1,
  38388. 0x1b, 0x48, 0x40, 0xfb, 0xe6, 0x2f, 0x2b, 0x94, 0xfe, 0x68,
  38389. 0xa2, 0xc4, 0x36, 0xd9, 0xcd, 0xc1, 0x93, 0x6d, 0xef, 0x39,
  38390. 0x5e, 0x43, 0x30, 0x5a, 0x2e, 0x66, 0xb6, 0xf2, 0xed, 0x9a,
  38391. 0x8d, 0x12, 0xdf, 0x5c, 0xae, 0xad, 0x16, 0x12, 0x7e, 0x81,
  38392. 0x82, 0x91, 0x7d, 0x2b, 0x12, 0xe9, 0x96, 0xb8, 0xb7, 0x42,
  38393. 0xcb, 0x1f, 0xf8, 0xd1, 0xfd, 0x83, 0x7a, 0xe4, 0x36, 0x1d,
  38394. 0x04, 0x27, 0x4c, 0xe5, 0xbd, 0x75, 0x24, 0xf7, 0xbd, 0xb6,
  38395. 0x6a, 0x68, 0x4e, 0x2c, 0x1b, 0x56, 0x3e, 0x60, 0xa4, 0x42,
  38396. 0xca, 0x7a, 0x54, 0xe5, 0x06, 0xe3, 0xda, 0x05, 0xf7, 0x77,
  38397. 0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
  38398. 0xfe, 0x4b
  38399. };
  38400. #endif
  38401. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_sig[] = {
  38402. 0x27, 0x3b, 0x58, 0xa0, 0xcf, 0x00, 0x29, 0x5e, 0x1a, 0x63, 0xbf, 0xb4,
  38403. 0x97, 0x16, 0xa1, 0x9c, 0x78, 0xd1, 0x33, 0xdc, 0x72, 0xde, 0xa3, 0xfc,
  38404. 0xf4, 0x09, 0xb1, 0x09, 0x16, 0x3f, 0x80, 0x72, 0x22, 0x68, 0x65, 0x68,
  38405. 0xb9, 0x80, 0x5a, 0x4a, 0x0d, 0x73, 0x49, 0xe1, 0xc6, 0xde, 0xca, 0x08,
  38406. 0x4f, 0xca, 0xf8, 0xb2, 0xf8, 0x45, 0x3b, 0x6b, 0x8c, 0x6c, 0xfd, 0x3a,
  38407. 0xf4, 0xde, 0xde, 0x82, 0xd8, 0x04, 0xbe, 0x4f, 0x4a, 0xdb, 0x92, 0x47,
  38408. 0x83, 0x2d, 0xc4, 0x55, 0xed, 0x20, 0x4f, 0x71, 0xb1, 0x58, 0xd9, 0x70,
  38409. 0x73, 0xbd, 0xb0, 0x3a, 0xb4, 0x8f, 0xd6, 0x9e, 0x32, 0x98, 0x2b, 0x9e,
  38410. 0xff, 0x2a, 0x7c, 0xcb, 0x05, 0x1b, 0x8e, 0xe6, 0x3a, 0x45, 0xc6, 0x7a,
  38411. 0xc8, 0xaf, 0x62, 0xd3, 0x04, 0xfa, 0x69, 0x4f, 0xda, 0x1b, 0x74, 0x16,
  38412. 0x0d, 0xb3, 0x1a, 0xee, 0x71, 0xd7, 0xb0, 0xef, 0x69, 0xf5, 0xe2, 0xe9,
  38413. 0xc2, 0xcc, 0x15, 0x66, 0x28, 0x0a, 0xac, 0xe2, 0x63, 0x06, 0xb7, 0x21,
  38414. 0x0d, 0xd8, 0x5c, 0x94, 0x63, 0xfd, 0x51, 0x18, 0x9f, 0x07, 0x19, 0x3d,
  38415. 0xa2, 0x50, 0x40, 0xd3, 0xe9, 0x05, 0xd4, 0x11, 0x13, 0x15, 0xaa, 0x46,
  38416. 0xda, 0x3e, 0x5f, 0xcd, 0x3c, 0xfa, 0x42, 0xba, 0x79, 0x4a, 0xb7, 0x43,
  38417. 0x91, 0xa5, 0xcb, 0xbc, 0xeb, 0x37, 0x94, 0xf1, 0x9c, 0xb9, 0xdb, 0x41,
  38418. 0x06, 0xd8, 0x7b, 0x5e, 0x90, 0xe3, 0x3c, 0x8a, 0x10, 0x62, 0x9a, 0x15,
  38419. 0x27, 0x78, 0xed, 0x69, 0x11, 0x2c, 0xb5, 0xb4, 0xdb, 0xc8, 0x70, 0x50,
  38420. 0x62, 0x47, 0x96, 0xcb, 0xd9, 0xb2, 0x3e, 0x59, 0x2f, 0x1c, 0xac, 0xcb,
  38421. 0xcf, 0x22, 0xc2, 0x9b, 0xc7, 0x92, 0xe9, 0x4d, 0x8d, 0x5d, 0xcf, 0x06,
  38422. 0x53, 0x7e, 0xf4, 0x4e, 0xfe, 0x9e, 0x41, 0x5d, 0x00, 0x8c, 0x08, 0xf4,
  38423. 0x02, 0x79, 0x33, 0x1c, 0x27, 0x1d, 0xe3, 0x94, 0xac, 0xe6, 0x87, 0xa0,
  38424. 0x08, 0xb4, 0x60, 0x0c, 0xff, 0x47, 0xdc, 0x16, 0x3a, 0x1d, 0x89, 0xc0,
  38425. 0x6a, 0xa4, 0x3d, 0x71, 0x33, 0xdd, 0x1e, 0x70, 0xfe, 0xd4, 0x8b, 0xed,
  38426. 0x7c, 0x91, 0xe4, 0xe2, 0x15, 0x06, 0xc1, 0x83, 0x24, 0x55, 0xa7, 0x2a,
  38427. 0x9f, 0x4e, 0xd9, 0x56, 0x7a, 0x95, 0xa8, 0xdd, 0xc4, 0xf0, 0x71, 0x3a,
  38428. 0x99, 0x65, 0x31, 0x4b, 0xb7, 0x96, 0x2c, 0x53, 0x54, 0x83, 0xec, 0xc9,
  38429. 0x97, 0x2f, 0x0c, 0xa4, 0x8f, 0xbb, 0x93, 0x9d, 0xea, 0xae, 0xf9, 0xcb,
  38430. 0xb2, 0xb9, 0xa3, 0x61, 0x5f, 0x77, 0x8c, 0xb6, 0x5a, 0x56, 0xbe, 0x5f,
  38431. 0x85, 0xd1, 0xb5, 0x0a, 0x53, 0xe2, 0xc7, 0xbf, 0x76, 0x8b, 0x97, 0x6f,
  38432. 0x10, 0xdd, 0x1f, 0x44, 0x69, 0x66, 0x03, 0xc4, 0x6b, 0x59, 0xf7, 0xb4,
  38433. 0xc1, 0x12, 0xcc, 0x00, 0x70, 0xe8, 0xbd, 0x44, 0x28, 0xf5, 0xfa, 0x96,
  38434. 0xf3, 0x59, 0xed, 0x81, 0x67, 0xe0, 0xbe, 0x47, 0x75, 0xb3, 0xa8, 0x9f,
  38435. 0x21, 0x70, 0x2e, 0x6f, 0xef, 0x54, 0x11, 0x3f, 0x34, 0xaf, 0x0d, 0x73,
  38436. 0x5b, 0x9e, 0x6d, 0x86, 0x58, 0xb7, 0x34, 0xc2, 0xc2, 0xb3, 0x64, 0xd5,
  38437. 0x9b, 0x6e, 0xb9, 0x99, 0x6a, 0xe4, 0xfd, 0xc3, 0x17, 0xf3, 0x10, 0xfc,
  38438. 0x6e, 0xf5, 0x65, 0xe1, 0x9c, 0x59, 0x15, 0x11, 0x00, 0xea, 0x96, 0x81,
  38439. 0x69, 0x9b, 0x05, 0x4d, 0xf3, 0xce, 0xf3, 0xf0, 0xa9, 0x01, 0x3f, 0x13,
  38440. 0xbb, 0xb0, 0xac, 0xc3, 0x92, 0x1c, 0x2b, 0x61, 0xe3, 0x01, 0x22, 0x45,
  38441. 0x4a, 0x23, 0x19, 0x80, 0xca, 0xb9, 0xef, 0x4e, 0x76, 0x52, 0xc5, 0x9d,
  38442. 0x91, 0x33, 0x17, 0xc4, 0x28, 0x83, 0x55, 0x61, 0x49, 0x72, 0x04, 0xaa,
  38443. 0xf8, 0xe3, 0x4b, 0x20, 0xf7, 0x6a, 0x74, 0x56, 0x64, 0xf9, 0xb3, 0xc9,
  38444. 0x67, 0x5b, 0x55, 0x29, 0x9a, 0x89, 0xa5, 0x14, 0x67, 0xea, 0x6d, 0x6a,
  38445. 0xde, 0x98, 0x58, 0x73, 0x25, 0xa3, 0xdb, 0xed, 0x3d, 0x62, 0xaa, 0xe0,
  38446. 0x79, 0x7f, 0xa3, 0xd9, 0xb5, 0x4c, 0xe9, 0xa8, 0xdf, 0xfd, 0x59, 0x31,
  38447. 0x42, 0x81, 0x9e, 0xb7, 0x81, 0x3f, 0x0e, 0xfb, 0xef, 0x80, 0x71, 0x9d,
  38448. 0xb7, 0xa5, 0xfc, 0xb1, 0x80, 0xc9, 0x7e, 0x31, 0xd9, 0x47, 0xe2, 0xca,
  38449. 0x10, 0x7b, 0xd1, 0xa1, 0x1c, 0x28, 0xc7, 0x7f, 0x51, 0x26, 0xb1, 0x4e,
  38450. 0x57, 0xdd, 0x7d, 0x76, 0x5c, 0x5a, 0x85, 0xa7, 0x7b, 0x8c, 0xc5, 0x6e,
  38451. 0xac, 0x20, 0xf8, 0x49, 0x16, 0xd6, 0x64, 0xf5, 0xf4, 0x2c, 0x32, 0xa1,
  38452. 0x5d, 0xfb, 0x87, 0xb6, 0x14, 0xfe, 0x68, 0x7c, 0x4d, 0xce, 0xd7, 0x94,
  38453. 0xf9, 0x8b, 0xf0, 0x61, 0xfd, 0xe0, 0x83, 0x7f, 0x13, 0xec, 0x7a, 0xb7,
  38454. 0x41, 0x04, 0x51, 0x6e, 0x30, 0xa2, 0x01, 0xf7, 0x30, 0x12, 0xec, 0xd2,
  38455. 0x8f, 0x73, 0xe7, 0x8e, 0x12, 0xb4, 0xe5, 0xc1, 0xff, 0xdf, 0x67, 0x14,
  38456. 0xb1, 0xe9, 0xba, 0x36, 0x19, 0x18, 0xf4, 0xaa, 0xe0, 0xe4, 0x9d, 0xcd,
  38457. 0xe8, 0xe7, 0x2b, 0x33, 0xb3, 0xdc, 0xb9, 0x19, 0xd7, 0xad, 0xa4, 0x68,
  38458. 0xcd, 0x83, 0x77, 0x98, 0x36, 0x49, 0xd9, 0x32, 0x20, 0xfd, 0xfc, 0x34,
  38459. 0xe7, 0x54, 0xd9, 0xb5, 0x05, 0xab, 0x0e, 0x08, 0x0e, 0x16, 0x8a, 0x7d,
  38460. 0x91, 0x4c, 0xaa, 0x19, 0x04, 0x37, 0x35, 0xa5, 0xab, 0x6c, 0xee, 0xc4,
  38461. 0x90, 0xf0, 0x5f, 0xc7, 0xae, 0x82, 0xfd, 0x59, 0x53, 0xe5, 0x36, 0x5a,
  38462. 0x56, 0x37, 0x61, 0x69, 0xda, 0xe5, 0x8f, 0xfd, 0x2e, 0xd4, 0x9c, 0x7f,
  38463. 0xb6, 0x39, 0xa4, 0x8d, 0x0a, 0xab, 0x82, 0x0f, 0xfe, 0x84, 0x69, 0x44,
  38464. 0x8a, 0xa6, 0xd0, 0x39, 0xf9, 0x72, 0x68, 0xe7, 0x97, 0xd8, 0x6c, 0x7b,
  38465. 0xec, 0x85, 0x8c, 0x52, 0xc9, 0x97, 0xbb, 0xc4, 0x7a, 0x67, 0x22, 0x60,
  38466. 0x46, 0x9f, 0x16, 0xf1, 0x67, 0x0e, 0x1b, 0x50, 0x7c, 0xc4, 0x29, 0x15,
  38467. 0xbc, 0x55, 0x6a, 0x67, 0xf6, 0xa8, 0x85, 0x66, 0x89, 0x9f, 0xff, 0x38,
  38468. 0x28, 0xaa, 0x87, 0x91, 0xce, 0xde, 0x8d, 0x45, 0x5c, 0xa1, 0x25, 0x95,
  38469. 0xe2, 0x86, 0xdd, 0xa1, 0x87, 0x6a, 0x0a, 0xa8, 0x3e, 0x63, 0x0e, 0x21,
  38470. 0xa5, 0x6e, 0x08, 0x4d, 0x07, 0xb6, 0x26, 0xa8, 0x92, 0xdb, 0xed, 0x13,
  38471. 0x01, 0xc3, 0xba, 0xcf, 0xad, 0x01, 0xbc, 0xe5, 0xc0, 0xba, 0xbe, 0x7c,
  38472. 0x75, 0xf1, 0xb9, 0xfe, 0xd3, 0xf0, 0xa5, 0x2c, 0x8e, 0x10, 0xff, 0x99,
  38473. 0xcb, 0xe2, 0x2d, 0xdc, 0x2f, 0x76, 0x00, 0xf8, 0x51, 0x7c, 0xcc, 0x52,
  38474. 0x16, 0x0f, 0x18, 0x98, 0xea, 0x34, 0x06, 0x7f, 0xb7, 0x2e, 0xe9, 0x40,
  38475. 0xf0, 0x2d, 0x30, 0x3d, 0xc0, 0x67, 0x4c, 0xe6, 0x63, 0x40, 0x41, 0x42,
  38476. 0x96, 0xbb, 0x0b, 0xd6, 0xc9, 0x1c, 0x22, 0x7a, 0xa9, 0x4d, 0xcc, 0x5b,
  38477. 0xaa, 0x03, 0xc6, 0x3b, 0x1e, 0x2f, 0x11, 0xae, 0x34, 0x6f, 0x0c, 0xe9,
  38478. 0x16, 0x9c, 0x82, 0x3b, 0x90, 0x4c, 0x0e, 0xf0, 0xf9, 0x7f, 0x02, 0xca,
  38479. 0xb9, 0xa9, 0x49, 0x6d, 0x27, 0x73, 0xd0, 0xbf, 0x15, 0x61, 0x52, 0xbc,
  38480. 0xd6, 0x31, 0x59, 0x2b, 0x52, 0x5b, 0xaf, 0x3c, 0xc0, 0x8f, 0xdc, 0xd5,
  38481. 0x2c, 0x1d, 0xe4, 0xe9, 0x41, 0xe8, 0xd3, 0x35, 0xd6, 0xb1, 0xf3, 0x32,
  38482. 0xe0, 0x52, 0x08, 0x73, 0x99, 0xb6, 0x6b, 0xbc, 0x26, 0xfb, 0x2e, 0xa7,
  38483. 0xb7, 0xcd, 0x14, 0xf0, 0xf9, 0xe5, 0x3a, 0xd0, 0x05, 0x5b, 0x2b, 0x38,
  38484. 0xbd, 0x7c, 0xda, 0xd4, 0x15, 0x45, 0xfa, 0x3b, 0x6f, 0x94, 0x8e, 0x22,
  38485. 0xce, 0xfa, 0x53, 0xe0, 0x5f, 0xa6, 0x9d, 0x1c, 0x26, 0x91, 0x8a, 0xab,
  38486. 0x72, 0x5b, 0x18, 0x78, 0x69, 0x98, 0x3f, 0x8d, 0x33, 0x7c, 0x21, 0x93,
  38487. 0x9e, 0xf0, 0xaf, 0xb7, 0x30, 0xc8, 0xac, 0xbc, 0xdb, 0x9c, 0x29, 0x17,
  38488. 0x6b, 0x9d, 0x0f, 0x16, 0xd6, 0xc0, 0xcc, 0x3b, 0xce, 0x11, 0xe9, 0x64,
  38489. 0xc8, 0xd4, 0x4c, 0x98, 0x7c, 0x8f, 0xf1, 0x5e, 0x84, 0xe4, 0x72, 0xf9,
  38490. 0x69, 0xf5, 0x9d, 0xad, 0x95, 0x3b, 0xfb, 0x6d, 0x30, 0x7e, 0x0a, 0x47,
  38491. 0x5b, 0x26, 0xb2, 0x4e, 0xeb, 0x1a, 0xc3, 0x37, 0x16, 0x28, 0x79, 0x62,
  38492. 0xb4, 0x36, 0x85, 0x4a, 0x15, 0x5a, 0xc3, 0x6e, 0xbe, 0x7e, 0x00, 0xe9,
  38493. 0x4a, 0xa5, 0xd7, 0x90, 0xcf, 0x59, 0x63, 0x2d, 0x2b, 0xc2, 0xc6, 0x47,
  38494. 0xe6, 0x77, 0xb7, 0x6e, 0x9b, 0xc8, 0x0d, 0x18, 0x2b, 0x45, 0x2b, 0xc9,
  38495. 0x5a, 0x6e, 0xb4, 0x50, 0xa5, 0x23, 0x7d, 0x17, 0xcc, 0x49, 0xe2, 0xb3,
  38496. 0xf4, 0x6d, 0xb4, 0xb7, 0xbb, 0x9e, 0xdd, 0x20, 0x99, 0x19, 0xf5, 0x53,
  38497. 0x1f, 0xd0, 0xff, 0x67, 0xf3, 0x8e, 0x6a, 0xcd, 0x2a, 0x6e, 0x2b, 0x0a,
  38498. 0x90, 0xd7, 0xdb, 0xe1, 0xff, 0x1c, 0x40, 0xa1, 0xb0, 0x5d, 0x94, 0x4d,
  38499. 0x20, 0x14, 0x01, 0xa1, 0xa8, 0xd1, 0x15, 0xd2, 0xd9, 0x1b, 0xbf, 0xc2,
  38500. 0x8a, 0xd0, 0x02, 0xf6, 0x16, 0xa1, 0xb7, 0x40, 0xe0, 0x36, 0x88, 0xc8,
  38501. 0x17, 0x0a, 0xf0, 0xb6, 0x0d, 0x3c, 0x53, 0xb9, 0x51, 0xed, 0xef, 0x20,
  38502. 0x6f, 0xf3, 0x0c, 0xb5, 0xce, 0x0e, 0x9e, 0xfd, 0x0f, 0x5e, 0x3f, 0x8f,
  38503. 0x3c, 0xb7, 0x2a, 0xdb, 0xc6, 0xa7, 0xf2, 0x11, 0x6e, 0xdc, 0x05, 0x33,
  38504. 0xd4, 0xd8, 0xb0, 0x2d, 0x8a, 0xe5, 0x39, 0x82, 0x00, 0x49, 0x7d, 0xfd,
  38505. 0x32, 0x29, 0xbb, 0x79, 0x5d, 0xcb, 0x21, 0x7b, 0x2d, 0x36, 0x58, 0x73,
  38506. 0x52, 0x57, 0x52, 0x96, 0x4d, 0x89, 0x61, 0xf4, 0xad, 0x1f, 0x48, 0xd5,
  38507. 0x7a, 0x4a, 0xaa, 0x1c, 0xa1, 0xf4, 0xb4, 0x9c, 0x43, 0x3b, 0x95, 0x72,
  38508. 0xd0, 0x0e, 0x35, 0x82, 0x26, 0xd4, 0x2e, 0xe3, 0x83, 0x96, 0x97, 0x5a,
  38509. 0x7b, 0xfc, 0x48, 0x17, 0x3c, 0xba, 0x9e, 0x5f, 0x46, 0x1a, 0x53, 0xe3,
  38510. 0x2e, 0x78, 0x79, 0x80, 0xf6, 0x2d, 0x24, 0xcf, 0x62, 0xb6, 0x86, 0xeb,
  38511. 0xee, 0xec, 0xf2, 0x1d, 0x00, 0xc8, 0x28, 0x9d, 0x93, 0x16, 0xa7, 0xd9,
  38512. 0x11, 0x47, 0xe3, 0xc4, 0xb6, 0xc4, 0xa0, 0x99, 0x83, 0xc1, 0x17, 0xd8,
  38513. 0x8e, 0xde, 0x69, 0x1d, 0xcb, 0xdd, 0xe7, 0x86, 0x6f, 0xf2, 0x36, 0x07,
  38514. 0x23, 0x86, 0x0d, 0xe9, 0xad, 0x87, 0xae, 0x76, 0x98, 0x95, 0x51, 0xf2,
  38515. 0xb3, 0x11, 0xc5, 0x34, 0xf0, 0x0c, 0xf8, 0x29, 0x9c, 0x84, 0x4f, 0x81,
  38516. 0x49, 0x85, 0x63, 0x25, 0x16, 0xb0, 0xc3, 0xaa, 0xd7, 0x8a, 0x2e, 0x4b,
  38517. 0x97, 0x60, 0x74, 0xf8, 0xa7, 0x39, 0xec, 0x6c, 0x2c, 0x9b, 0x33, 0x3a,
  38518. 0x11, 0xbd, 0xa6, 0x90, 0x48, 0x65, 0xb1, 0xe7, 0x38, 0x53, 0x47, 0x1b,
  38519. 0x62, 0xd5, 0xb7, 0xa8, 0xd4, 0xae, 0xf5, 0x12, 0x06, 0x12, 0x54, 0xa2,
  38520. 0xce, 0xf1, 0x6b, 0x3a, 0xda, 0x63, 0x2e, 0x37, 0x2a, 0x25, 0x89, 0x30,
  38521. 0x98, 0x77, 0x1d, 0x4b, 0x5a, 0x1e, 0xb7, 0x3d, 0xed, 0x19, 0xec, 0x9f,
  38522. 0x64, 0x46, 0xa8, 0x2a, 0x79, 0xf3, 0x70, 0x39, 0x9f, 0x8c, 0xc3, 0x28,
  38523. 0xcc, 0x2a, 0xc0, 0xd0, 0xe6, 0x80, 0xf5, 0x01, 0x78, 0x72, 0x7f, 0xe7,
  38524. 0x2e, 0x7b, 0x5f, 0x05, 0xc3, 0x41, 0x33, 0x07, 0xdb, 0x9c, 0xa8, 0x96,
  38525. 0xa7, 0x21, 0x20, 0x23, 0xd0, 0x59, 0x39, 0x06, 0x19, 0xa4, 0x29, 0xe5,
  38526. 0x72, 0x39, 0x69, 0x23, 0xe3, 0xfa, 0x28, 0x63, 0xf5, 0x42, 0x3b, 0xca,
  38527. 0x88, 0x5d, 0x7e, 0x47, 0x93, 0xa8, 0x8c, 0x75, 0xf2, 0x19, 0x44, 0x43,
  38528. 0x15, 0x39, 0x03, 0x42, 0xd8, 0x1d, 0x81, 0x30, 0x8e, 0x84, 0x31, 0x24,
  38529. 0x75, 0x67, 0x4e, 0xbe, 0xfe, 0x0a, 0xd8, 0xc3, 0xe7, 0x5b, 0xe1, 0xd5,
  38530. 0x12, 0x6a, 0x69, 0x99, 0xcd, 0x35, 0xca, 0x22, 0x02, 0x65, 0xb3, 0x0f,
  38531. 0x50, 0xb6, 0xaa, 0xc6, 0x91, 0x5c, 0x4d, 0xd4, 0x07, 0x93, 0x46, 0xf0,
  38532. 0xcc, 0xe1, 0x92, 0x14, 0x91, 0x21, 0x43, 0xc4, 0xba, 0x45, 0x1c, 0x47,
  38533. 0x29, 0xdf, 0xff, 0x89, 0x60, 0xee, 0x89, 0x1e, 0xc3, 0xb4, 0xb9, 0x0b,
  38534. 0xc9, 0x7e, 0xd9, 0x15, 0xb0, 0x80, 0x91, 0xbe, 0xb9, 0x43, 0x48, 0x12,
  38535. 0x86, 0x8e, 0x79, 0x38, 0x4d, 0xce, 0x36, 0x7f, 0xc3, 0xe8, 0xb7, 0xb9,
  38536. 0x92, 0xbf, 0x27, 0x20, 0x54, 0xc8, 0x05, 0x63, 0x3b, 0xf5, 0x48, 0x1a,
  38537. 0xa9, 0x04, 0x6c, 0xb6, 0x0e, 0x11, 0xea, 0xf3, 0x59, 0xb9, 0xa6, 0xf6,
  38538. 0xf8, 0x0b, 0x15, 0xed, 0x30, 0xf9, 0xe4, 0xe5, 0x26, 0x2d, 0xbb, 0xc6,
  38539. 0x5b, 0x36, 0xbb, 0x73, 0xa6, 0x4f, 0xf5, 0x43, 0x9f, 0xd7, 0xb9, 0x0f,
  38540. 0xbc, 0x4f, 0x8d, 0xb8, 0xec, 0x1d, 0x42, 0x19, 0x56, 0x37, 0xc4, 0xcb,
  38541. 0xd0, 0x16, 0x85, 0xff, 0xd3, 0x9b, 0xef, 0xc8, 0x75, 0x37, 0xd1, 0x92,
  38542. 0xad, 0x21, 0x94, 0x1e, 0x9a, 0xf6, 0x2f, 0x6d, 0x30, 0xba, 0x37, 0xc3,
  38543. 0xdc, 0x11, 0xe0, 0x79, 0xa4, 0x92, 0x1f, 0xe4, 0xaa, 0x7a, 0x6b, 0x2a,
  38544. 0xe4, 0x04, 0xb7, 0xf9, 0x86, 0x95, 0xdb, 0xa8, 0xfc, 0x8a, 0x53, 0x21,
  38545. 0x31, 0x14, 0xf7, 0x40, 0x01, 0x78, 0x4e, 0x73, 0x18, 0xb3, 0x54, 0xd7,
  38546. 0xa6, 0x93, 0xf0, 0x70, 0x04, 0x1c, 0xe0, 0x2b, 0xef, 0xee, 0xd4, 0x64,
  38547. 0xa7, 0xd9, 0x9f, 0x81, 0x4f, 0xe5, 0x1e, 0xbe, 0x6e, 0xd2, 0xf6, 0x3a,
  38548. 0xba, 0xcf, 0x8c, 0x96, 0x2a, 0x3d, 0xf7, 0xe5, 0x5c, 0x59, 0x40, 0x9c,
  38549. 0xe3, 0xf9, 0x2b, 0x6d, 0x3d, 0xf2, 0x6f, 0x81, 0xd6, 0xab, 0x9c, 0xab,
  38550. 0xc6, 0xf7, 0x8f, 0xaa, 0xe5, 0x71, 0xe3, 0xc9, 0x8c, 0x1a, 0xeb, 0xc5,
  38551. 0x87, 0xe7, 0xb0, 0xde, 0x18, 0xba, 0xaa, 0x1e, 0xda, 0x12, 0x32, 0x16,
  38552. 0x94, 0x3a, 0x6e, 0x4f, 0x84, 0x06, 0x8e, 0x33, 0xf7, 0xfa, 0x35, 0xb8,
  38553. 0x45, 0xe4, 0x5e, 0x9e, 0x46, 0x05, 0x7a, 0xf7, 0xf4, 0x99, 0xad, 0xb9,
  38554. 0xdd, 0x55, 0xd9, 0x52, 0x3b, 0x93, 0xe3, 0x9b, 0x54, 0x1b, 0xe6, 0xa9,
  38555. 0x70, 0xd3, 0x48, 0xf9, 0x3d, 0xdb, 0x88, 0x63, 0x66, 0xa0, 0xab, 0x72,
  38556. 0x83, 0x6e, 0x8f, 0x78, 0x9d, 0x55, 0x46, 0x21, 0xca, 0x7c, 0xb7, 0x5d,
  38557. 0x16, 0xe8, 0x66, 0x3b, 0x7b, 0xaa, 0xfe, 0x9c, 0x9c, 0x33, 0xc9, 0xc2,
  38558. 0xa4, 0x3c, 0x78, 0x97, 0xf3, 0x5b, 0xc2, 0x29, 0x36, 0x98, 0x68, 0x28,
  38559. 0xfe, 0x0a, 0xae, 0x6f, 0xe5, 0xf7, 0xfb, 0x9d, 0xf8, 0x8c, 0xd9, 0xd0,
  38560. 0x4d, 0xfe, 0xc7, 0xd0, 0xb0, 0xe3, 0x9c, 0xdb, 0xac, 0x9e, 0x1b, 0x55,
  38561. 0x7e, 0x24, 0xfe, 0xc4, 0x12, 0xcb, 0xc2, 0xdd, 0x0a, 0xda, 0x31, 0x40,
  38562. 0x41, 0xb7, 0xfc, 0x3f, 0x6d, 0xe2, 0xd3, 0x8a, 0x0f, 0x21, 0x33, 0x3a,
  38563. 0xbc, 0xa7, 0x62, 0x18, 0xb3, 0xaf, 0x48, 0xc6, 0xe2, 0xa3, 0xdd, 0x1d,
  38564. 0x20, 0x62, 0xe4, 0x4b, 0x81, 0x6b, 0x3a, 0xc5, 0xb1, 0x07, 0xe1, 0xf1,
  38565. 0xe1, 0xba, 0xf6, 0x01, 0xc6, 0xf2, 0xea, 0xc0, 0x97, 0x73, 0x79, 0x19,
  38566. 0x06, 0xaa, 0x62, 0x42, 0xcb, 0x21, 0x5f, 0x08, 0x97, 0x7d, 0x72, 0xb5,
  38567. 0x39, 0x4d, 0x99, 0xe3, 0xa2, 0x3f, 0xb9, 0xb4, 0xed, 0xf4, 0x61, 0x35,
  38568. 0xe1, 0x50, 0xfb, 0x56, 0x7c, 0x35, 0xfd, 0x44, 0x8a, 0x57, 0x22, 0xed,
  38569. 0x30, 0x33, 0xc3, 0x0b, 0xf1, 0x88, 0xe4, 0x44, 0x46, 0xf5, 0x73, 0x6d,
  38570. 0x9b, 0x98, 0x88, 0x92, 0xf5, 0x34, 0x85, 0x18, 0x66, 0xef, 0x70, 0xbe,
  38571. 0x7b, 0xc1, 0x0f, 0x1c, 0x78, 0x2d, 0x42, 0x13, 0x2d, 0x2f, 0x4d, 0x40,
  38572. 0x8e, 0xe2, 0x6f, 0xe0, 0x04, 0xdb, 0x58, 0xbc, 0x65, 0x80, 0xba, 0xfc,
  38573. 0x89, 0xee, 0xf3, 0x78, 0xb2, 0xd9, 0x78, 0x93, 0x6d, 0xbf, 0xd4, 0x74,
  38574. 0x24, 0xf4, 0x5c, 0x37, 0x89, 0x0c, 0x14, 0xd5, 0xbd, 0xc5, 0xfc, 0x37,
  38575. 0xe8, 0x8b, 0xe0, 0xc5, 0x89, 0xc9, 0x70, 0xb3, 0x76, 0x46, 0xce, 0x0d,
  38576. 0x7c, 0x3d, 0xa4, 0x5d, 0x02, 0x95, 0x03, 0xba, 0x24, 0xaa, 0xf7, 0xd0,
  38577. 0x75, 0x35, 0x78, 0x27, 0x9c, 0x6d, 0x2a, 0xef, 0xaa, 0xac, 0x85, 0xef,
  38578. 0x8d, 0xfc, 0xc0, 0xfc, 0x72, 0x02, 0xf4, 0xa3, 0xd3, 0x87, 0xfc, 0x4d,
  38579. 0xce, 0x3d, 0xcb, 0xc2, 0x74, 0x5b, 0xb0, 0x83, 0xc5, 0x72, 0x72, 0xd6,
  38580. 0xa1, 0x67, 0x4d, 0xa1, 0xd6, 0xaa, 0xe7, 0x9b, 0xe7, 0xc0, 0xfd, 0x86,
  38581. 0x91, 0x08, 0xfa, 0x48, 0x2f, 0x50, 0xce, 0x17, 0xea, 0x1c, 0xe3, 0x90,
  38582. 0x35, 0xe6, 0x6c, 0xc9, 0x66, 0x7d, 0x51, 0x32, 0x20, 0x0c, 0x2d, 0x4b,
  38583. 0xa1, 0xbf, 0x78, 0x87, 0xe1, 0x5a, 0x28, 0x0e, 0x9a, 0x85, 0xf6, 0x7e,
  38584. 0x39, 0x60, 0xbc, 0x64, 0x42, 0x5d, 0xf0, 0x0a, 0xd7, 0x3e, 0xbb, 0xa0,
  38585. 0x6d, 0x7c, 0xfa, 0x75, 0xee, 0x34, 0x39, 0x23, 0x0e, 0xbd, 0x50, 0x19,
  38586. 0x7a, 0x2a, 0xb7, 0x17, 0x3a, 0x8b, 0xb7, 0xb6, 0xf4, 0xd8, 0x47, 0x71,
  38587. 0x6b, 0x21, 0x1b, 0x56, 0xcc, 0xfb, 0x7b, 0x81, 0x99, 0x46, 0x88, 0x23,
  38588. 0x40, 0x49, 0x66, 0x8b, 0xac, 0x84, 0x16, 0x8a, 0x86, 0xae, 0x38, 0xc4,
  38589. 0x5b, 0x1f, 0x2b, 0xfa, 0xf2, 0x8b, 0x81, 0xc1, 0x22, 0x61, 0x61, 0x6c,
  38590. 0x43, 0x16, 0x8c, 0x1d, 0x37, 0xb2, 0xaf, 0x3c, 0x3a, 0x90, 0x33, 0xed,
  38591. 0xf5, 0x08, 0x78, 0xfd, 0x5a, 0xde, 0xd3, 0x38, 0x6d, 0xd7, 0x1c, 0x23,
  38592. 0xeb, 0xb4, 0x9b, 0x8e, 0xc2, 0x48, 0x47, 0x8e, 0x84, 0xbb, 0xc4, 0xd0,
  38593. 0xcc, 0xf9, 0x55, 0x5a, 0x57, 0xb9, 0x99, 0x52, 0x82, 0x21, 0x3b, 0x83,
  38594. 0xda, 0x8f, 0xa3, 0x88, 0x9c, 0x57, 0xe0, 0x4b, 0xc1, 0xce, 0xbe, 0xd3,
  38595. 0xea, 0xdd, 0xf2, 0x07, 0xc1, 0x73, 0x6f, 0xc0, 0x5e, 0x8e, 0x85, 0x72,
  38596. 0xab, 0x2f, 0xa9, 0xac, 0x39, 0xee, 0x05, 0x34, 0x13, 0x16, 0x1b, 0x1c,
  38597. 0x21, 0x24, 0x41, 0x49, 0x78, 0x87, 0x8b, 0x97, 0x9c, 0x9f, 0xa3, 0xa8,
  38598. 0xb9, 0xbc, 0xc6, 0xcc, 0xf2, 0xfd, 0x18, 0x2a, 0x46, 0x58, 0x5a, 0x88,
  38599. 0xa2, 0xb5, 0xcc, 0xd2, 0xda, 0xe1, 0xe3, 0x0d, 0x20, 0x23, 0x2b, 0x2f,
  38600. 0x47, 0x57, 0x5e, 0x64, 0x87, 0x97, 0x9c, 0xa7, 0xaa, 0xbc, 0xc1, 0xe4,
  38601. 0xe5, 0xea, 0x0b, 0x16, 0x3b, 0x3c, 0x3e, 0x45, 0x58, 0x63, 0x6a, 0x6f,
  38602. 0x7c, 0x8c, 0x8d, 0x92, 0x99, 0x9c, 0xad, 0xb5, 0xb7, 0xce, 0x00, 0x00,
  38603. 0x00, 0x00, 0x00, 0x00, 0x16, 0x23, 0x36, 0x4a
  38604. };
  38605. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38606. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_sig[] = {
  38607. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  38608. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  38609. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  38610. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  38611. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  38612. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  38613. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  38614. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  38615. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  38616. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  38617. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  38618. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  38619. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  38620. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  38621. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  38622. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  38623. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  38624. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  38625. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  38626. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  38627. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  38628. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  38629. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  38630. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  38631. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  38632. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  38633. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  38634. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  38635. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  38636. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  38637. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  38638. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  38639. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  38640. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  38641. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  38642. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  38643. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  38644. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  38645. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  38646. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  38647. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  38648. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  38649. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  38650. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  38651. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  38652. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  38653. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  38654. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  38655. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  38656. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  38657. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  38658. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  38659. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  38660. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  38661. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  38662. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  38663. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  38664. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  38665. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  38666. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  38667. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  38668. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  38669. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  38670. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  38671. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  38672. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  38673. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  38674. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  38675. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  38676. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  38677. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  38678. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  38679. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  38680. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  38681. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  38682. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  38683. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  38684. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  38685. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  38686. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  38687. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  38688. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  38689. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  38690. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  38691. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  38692. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  38693. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  38694. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  38695. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  38696. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  38697. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  38698. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  38699. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  38700. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  38701. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  38702. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  38703. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  38704. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  38705. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  38706. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  38707. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  38708. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  38709. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  38710. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  38711. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  38712. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  38713. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  38714. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  38715. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  38716. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  38717. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  38718. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  38719. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  38720. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  38721. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  38722. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  38723. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  38724. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  38725. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  38726. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  38727. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  38728. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  38729. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  38730. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  38731. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  38732. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  38733. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  38734. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  38735. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  38736. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  38737. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  38738. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  38739. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  38740. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  38741. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  38742. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  38743. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  38744. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  38745. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  38746. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  38747. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  38748. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  38749. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  38750. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  38751. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  38752. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  38753. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  38754. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  38755. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  38756. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  38757. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  38758. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  38759. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  38760. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  38761. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  38762. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  38763. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  38764. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  38765. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  38766. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  38767. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  38768. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  38769. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  38770. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  38771. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  38772. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  38773. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  38774. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  38775. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  38776. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  38777. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  38778. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  38779. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  38780. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  38781. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  38782. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  38783. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  38784. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  38785. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  38786. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  38787. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  38788. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  38789. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  38790. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  38791. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  38792. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  38793. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  38794. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  38795. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  38796. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  38797. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  38798. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  38799. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  38800. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  38801. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  38802. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  38803. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  38804. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  38805. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  38806. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  38807. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  38808. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  38809. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  38810. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  38811. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  38812. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  38813. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  38814. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  38815. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  38816. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  38817. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  38818. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  38819. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  38820. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  38821. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  38822. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  38823. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  38824. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  38825. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  38826. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  38827. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  38828. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  38829. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  38830. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  38831. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  38832. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  38833. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  38834. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  38835. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  38836. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  38837. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  38838. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  38839. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  38840. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  38841. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  38842. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  38843. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  38844. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  38845. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  38846. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  38847. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  38848. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46
  38849. };
  38850. #endif
  38851. wc_test_ret_t ret;
  38852. ret = dilithium_param_vfy_test(WC_ML_DSA_44, ml_dsa_44_pub_key,
  38853. (word32)sizeof(ml_dsa_44_pub_key), ml_dsa_44_sig,
  38854. (word32)sizeof(ml_dsa_44_sig));
  38855. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38856. if (ret == 0) {
  38857. ret = dilithium_param_vfy_test(WC_ML_DSA_44_DRAFT,
  38858. ml_dsa_44_draft_pub_key, (word32)sizeof(ml_dsa_44_draft_pub_key),
  38859. ml_dsa_44_draft_sig, (word32)sizeof(ml_dsa_44_draft_sig));
  38860. }
  38861. #endif
  38862. return ret;
  38863. }
  38864. #endif
  38865. #ifndef WOLFSSL_NO_ML_DSA_65
  38866. static wc_test_ret_t dilithium_param_65_vfy_test(void)
  38867. {
  38868. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_pub_key[] = {
  38869. 0x2c, 0x32, 0xfa, 0x59, 0x71, 0x16, 0x4a, 0x0e, 0x45, 0x0f, 0x21, 0xfd,
  38870. 0x65, 0xee, 0x50, 0xb0, 0xbf, 0xea, 0x8e, 0x4e, 0xa2, 0x55, 0x71, 0xa6,
  38871. 0x65, 0x48, 0x56, 0x20, 0x8a, 0x48, 0x9d, 0xd7, 0xc9, 0x2c, 0x80, 0x62,
  38872. 0x88, 0x68, 0x4d, 0x5f, 0xbe, 0x5f, 0xe5, 0xf5, 0xa4, 0x75, 0xb6, 0x88,
  38873. 0x26, 0xae, 0x7d, 0x11, 0x43, 0x89, 0xcd, 0xe9, 0x67, 0x0c, 0x91, 0x0b,
  38874. 0xd1, 0xd8, 0x8b, 0x7b, 0x73, 0x75, 0x94, 0xc1, 0xc9, 0x61, 0xc7, 0x35,
  38875. 0x21, 0x99, 0x2e, 0xab, 0xe0, 0xdf, 0x4d, 0xac, 0x0d, 0xd0, 0xa2, 0x61,
  38876. 0x5f, 0x04, 0x08, 0x83, 0x66, 0x5c, 0x67, 0x47, 0x0c, 0xab, 0x2c, 0xb7,
  38877. 0x6d, 0x0e, 0x32, 0x4c, 0x8c, 0x25, 0x80, 0xf5, 0xe5, 0x7e, 0x3b, 0xa1,
  38878. 0xc6, 0xc5, 0x87, 0xd8, 0x68, 0xb2, 0xd5, 0x67, 0xf9, 0x5a, 0x8b, 0x88,
  38879. 0xf8, 0xcd, 0x0c, 0xda, 0x4f, 0xfc, 0xd2, 0xaf, 0xb2, 0xa2, 0x38, 0x21,
  38880. 0xf9, 0xd8, 0xf1, 0x1c, 0x8d, 0xb4, 0xe8, 0xfb, 0x76, 0x36, 0x87, 0xf4,
  38881. 0x7d, 0x03, 0xc4, 0x06, 0xab, 0x87, 0xac, 0x52, 0xe8, 0xd5, 0xf7, 0x63,
  38882. 0xf0, 0xa8, 0x0b, 0x95, 0xbd, 0x07, 0xf1, 0x1d, 0x33, 0x7b, 0x8a, 0x2c,
  38883. 0xef, 0x85, 0xbe, 0xf8, 0xc1, 0x4b, 0xa2, 0xb0, 0xe0, 0x7a, 0x85, 0xfa,
  38884. 0x52, 0x36, 0x05, 0xa7, 0x65, 0x4a, 0x0c, 0x21, 0x5c, 0xc0, 0x4f, 0x18,
  38885. 0xb8, 0x66, 0x02, 0xe6, 0xd0, 0x45, 0x60, 0x56, 0xfc, 0x40, 0x94, 0xb5,
  38886. 0xa5, 0x2b, 0xc7, 0x57, 0xc3, 0xc5, 0x30, 0x72, 0x1c, 0x4c, 0x2a, 0xd5,
  38887. 0x75, 0xae, 0x43, 0x9f, 0x01, 0x71, 0xac, 0x5c, 0xdf, 0x9c, 0x0a, 0x3c,
  38888. 0xb5, 0x89, 0x07, 0x9b, 0x28, 0x25, 0x31, 0x31, 0xc5, 0xb7, 0x24, 0x53,
  38889. 0x2c, 0x3c, 0x2a, 0x96, 0xe5, 0x0d, 0xa2, 0x97, 0xa7, 0x08, 0x9d, 0x31,
  38890. 0xc0, 0xcd, 0x53, 0xd5, 0xa8, 0x58, 0xa6, 0xac, 0x43, 0x2d, 0xac, 0x39,
  38891. 0x01, 0x2c, 0x60, 0xf6, 0x82, 0x86, 0xd0, 0xaf, 0xad, 0x61, 0x3f, 0x82,
  38892. 0x80, 0xa1, 0xe1, 0x12, 0x83, 0x6e, 0x1d, 0x5e, 0xfe, 0xc6, 0x1e, 0x2a,
  38893. 0x7a, 0x44, 0xcd, 0xc2, 0x0a, 0xf5, 0xc8, 0x72, 0x3e, 0x29, 0xc7, 0x0a,
  38894. 0xd1, 0x4c, 0x17, 0xdd, 0x1f, 0xb6, 0x95, 0x34, 0xc2, 0x6c, 0xdc, 0x63,
  38895. 0xd1, 0x7e, 0xb0, 0x52, 0x06, 0x18, 0x6c, 0xb1, 0x99, 0x6a, 0xbe, 0x42,
  38896. 0xa9, 0xc0, 0x22, 0xcc, 0x09, 0x11, 0x84, 0x1f, 0x16, 0x9a, 0x0e, 0xdd,
  38897. 0x18, 0x7a, 0x39, 0x34, 0xb0, 0x49, 0x44, 0xcb, 0x88, 0x1f, 0x91, 0x93,
  38898. 0x49, 0x3f, 0xcc, 0x62, 0x56, 0x33, 0x15, 0xcb, 0x02, 0x9b, 0x33, 0xe8,
  38899. 0xd7, 0xab, 0x51, 0xc0, 0x91, 0xe0, 0x9c, 0xd2, 0xf9, 0x52, 0x05, 0x0c,
  38900. 0xbf, 0xf1, 0x97, 0x42, 0xfe, 0xd0, 0x32, 0x27, 0x34, 0xf8, 0x82, 0x2d,
  38901. 0x65, 0x3a, 0x36, 0xce, 0xd1, 0x07, 0x82, 0x3a, 0x6a, 0xaa, 0x56, 0xf1,
  38902. 0x9b, 0x98, 0xca, 0x8e, 0x55, 0xff, 0xa0, 0x74, 0xd6, 0x6a, 0x42, 0xaa,
  38903. 0x0a, 0xd4, 0x59, 0x74, 0xfb, 0xd4, 0xdb, 0x14, 0x10, 0xee, 0xca, 0x78,
  38904. 0x83, 0x83, 0x95, 0x9b, 0x77, 0xf1, 0x9a, 0x48, 0xe0, 0x8f, 0xa4, 0x5a,
  38905. 0x4d, 0xa9, 0x3f, 0x32, 0x78, 0x4a, 0x25, 0x96, 0x9c, 0x20, 0x0a, 0xcc,
  38906. 0x5b, 0xd8, 0xca, 0x19, 0x47, 0x77, 0xb8, 0x7c, 0x51, 0x3e, 0xd6, 0x30,
  38907. 0xdb, 0x45, 0xb0, 0xe6, 0x9d, 0x6f, 0xc5, 0x0a, 0x5d, 0x5f, 0x55, 0xcd,
  38908. 0x0f, 0x20, 0x22, 0x7e, 0x09, 0x99, 0xac, 0xb8, 0x9c, 0x9d, 0xf7, 0x3e,
  38909. 0x7e, 0x07, 0xd7, 0xbc, 0x21, 0x76, 0x8c, 0x27, 0x81, 0x94, 0xab, 0x57,
  38910. 0x4a, 0xe2, 0x91, 0x1c, 0xa4, 0x77, 0x4a, 0xd2, 0x96, 0x52, 0x9d, 0x33,
  38911. 0xb5, 0x58, 0x70, 0xd7, 0xff, 0x22, 0xe8, 0x14, 0xea, 0xd0, 0x8c, 0xd4,
  38912. 0x06, 0x08, 0xd8, 0x73, 0x66, 0x4b, 0x93, 0x41, 0xc9, 0x73, 0x5b, 0x07,
  38913. 0x5f, 0x31, 0xc5, 0x25, 0x98, 0x7b, 0x7b, 0xa5, 0x26, 0x83, 0x94, 0x22,
  38914. 0x42, 0x1c, 0x51, 0xe6, 0x80, 0x48, 0xca, 0xd4, 0x53, 0x40, 0x3a, 0xee,
  38915. 0x2c, 0x29, 0x07, 0xed, 0xdf, 0x97, 0x44, 0x19, 0xe5, 0xe5, 0x35, 0x66,
  38916. 0x1f, 0xbd, 0x29, 0x77, 0x0c, 0x15, 0x6c, 0x95, 0x08, 0x81, 0xe0, 0x76,
  38917. 0x86, 0x5e, 0x6d, 0x77, 0x78, 0x76, 0x07, 0xdd, 0x21, 0x97, 0x59, 0xdb,
  38918. 0xd4, 0xbd, 0xb6, 0x4c, 0x3f, 0x07, 0x93, 0xb6, 0x4a, 0xce, 0xf7, 0x08,
  38919. 0x86, 0xfd, 0x9c, 0x03, 0x08, 0x94, 0x00, 0xea, 0x4b, 0xd6, 0x1e, 0x17,
  38920. 0xfb, 0xb5, 0xba, 0xde, 0x25, 0x95, 0xe7, 0xf8, 0x97, 0x9e, 0x99, 0xae,
  38921. 0x5d, 0xdd, 0xf6, 0x32, 0x1a, 0xf2, 0x4f, 0xcf, 0x0c, 0x17, 0x55, 0xb8,
  38922. 0xfb, 0xae, 0xc8, 0x46, 0xb0, 0x3e, 0x86, 0x2b, 0x5e, 0xef, 0x36, 0xca,
  38923. 0x24, 0xed, 0x32, 0x5b, 0xc8, 0xfb, 0x88, 0x35, 0x6a, 0x26, 0xfe, 0x06,
  38924. 0x54, 0x0c, 0x3e, 0x2c, 0x71, 0xdf, 0x98, 0xf0, 0xbb, 0xb2, 0xe0, 0x9d,
  38925. 0xf7, 0xeb, 0xce, 0x07, 0xfa, 0xc4, 0xab, 0x88, 0xc3, 0x14, 0x33, 0x60,
  38926. 0x48, 0xcf, 0x39, 0x26, 0x90, 0xac, 0xfa, 0x39, 0x6f, 0x2d, 0x9d, 0x6d,
  38927. 0x15, 0x7f, 0x84, 0x6b, 0x0a, 0x1c, 0xf4, 0x6c, 0x78, 0x62, 0x52, 0x93,
  38928. 0x2c, 0x7e, 0x9f, 0x4a, 0x51, 0x7a, 0x2e, 0xad, 0xea, 0xe4, 0xe5, 0x9c,
  38929. 0x15, 0x15, 0x28, 0x4d, 0x3e, 0x5e, 0xb4, 0x3b, 0xff, 0x81, 0xe0, 0x56,
  38930. 0x44, 0x33, 0x33, 0xd9, 0x4b, 0xb2, 0x23, 0x60, 0xed, 0x0d, 0xa5, 0x4e,
  38931. 0x9f, 0x7d, 0xbc, 0x6e, 0x3a, 0xf9, 0x7e, 0x16, 0x47, 0x66, 0xb1, 0x6c,
  38932. 0xc7, 0x26, 0x62, 0x9b, 0x3c, 0x53, 0xb3, 0xa1, 0x16, 0x62, 0x31, 0x64,
  38933. 0xd2, 0xbb, 0x28, 0x5c, 0xe8, 0x21, 0xc3, 0xfc, 0xc3, 0x6d, 0xa7, 0x35,
  38934. 0x4d, 0x57, 0xe0, 0xbd, 0x54, 0x1a, 0x84, 0xf7, 0x9c, 0x8a, 0x54, 0x3d,
  38935. 0x59, 0xb3, 0xa2, 0x46, 0x3b, 0x16, 0x48, 0x3b, 0x3a, 0x3c, 0x5e, 0x88,
  38936. 0xc3, 0x60, 0x63, 0x7e, 0xca, 0x68, 0xb7, 0x2f, 0x2b, 0xb5, 0x62, 0x2e,
  38937. 0x51, 0x89, 0xbe, 0x78, 0xf7, 0xfa, 0x19, 0xcc, 0xca, 0x87, 0x9a, 0xf5,
  38938. 0xef, 0x0d, 0x21, 0x08, 0x3b, 0xd6, 0x9a, 0x94, 0xc5, 0xd1, 0x1b, 0xa9,
  38939. 0x7c, 0xc8, 0x9f, 0x9a, 0xb0, 0xb8, 0xf7, 0x02, 0x12, 0x31, 0x70, 0x52,
  38940. 0x52, 0xda, 0xb5, 0x9a, 0x08, 0x20, 0xc3, 0xc4, 0x0c, 0x6a, 0x34, 0x58,
  38941. 0x75, 0x9b, 0xdc, 0x1a, 0x6a, 0x37, 0x42, 0x9f, 0x16, 0x70, 0xbb, 0x39,
  38942. 0x86, 0xbd, 0x09, 0x9c, 0x04, 0x44, 0xbe, 0x1a, 0xe5, 0xe9, 0x50, 0x9b,
  38943. 0x14, 0x50, 0x4f, 0x00, 0xba, 0xb0, 0xf6, 0x36, 0x4d, 0x69, 0x16, 0x11,
  38944. 0x40, 0x5a, 0x4e, 0x8b, 0x39, 0xb4, 0xf1, 0xb2, 0x11, 0x36, 0x2f, 0x02,
  38945. 0x15, 0xca, 0x78, 0xde, 0x75, 0x07, 0x64, 0x72, 0xfd, 0xd4, 0x48, 0xdd,
  38946. 0xfb, 0xf5, 0x8a, 0x3d, 0xa8, 0x8e, 0x14, 0xd1, 0x69, 0xe3, 0x21, 0x50,
  38947. 0x39, 0xfd, 0xd0, 0x3b, 0xa0, 0x22, 0x61, 0x5c, 0x7e, 0x88, 0x91, 0xe1,
  38948. 0xf0, 0xf6, 0x16, 0x23, 0xdb, 0xdb, 0x50, 0x0e, 0x39, 0xcc, 0x86, 0xf1,
  38949. 0xab, 0x89, 0x60, 0xb0, 0xac, 0x28, 0xc6, 0x57, 0xe4, 0xee, 0xa9, 0x1b,
  38950. 0xae, 0x78, 0xc5, 0x67, 0x1a, 0xeb, 0xb3, 0x43, 0xbc, 0xea, 0x11, 0x0c,
  38951. 0x64, 0xf6, 0xd2, 0x52, 0xa0, 0x7e, 0xcd, 0x6d, 0x84, 0x8c, 0xf8, 0x80,
  38952. 0xb7, 0xdb, 0x26, 0x91, 0x4a, 0xa0, 0x61, 0x69, 0x2f, 0x6f, 0x1c, 0x9d,
  38953. 0x2a, 0x20, 0x44, 0xdc, 0x58, 0xaf, 0x7d, 0xfe, 0x4d, 0xa2, 0x10, 0x21,
  38954. 0x88, 0xef, 0x42, 0x2e, 0x8e, 0xfb, 0x63, 0xbc, 0xc8, 0x26, 0xe7, 0x80,
  38955. 0xa5, 0xbf, 0xe0, 0x7a, 0xcb, 0xf3, 0x31, 0x1c, 0xd9, 0xa3, 0x12, 0x00,
  38956. 0x2f, 0x20, 0xc6, 0xc1, 0x15, 0xfd, 0x5b, 0x0d, 0x8a, 0x4d, 0xfb, 0x84,
  38957. 0x4d, 0xb4, 0x64, 0xeb, 0x12, 0xf3, 0x78, 0x6b, 0x4d, 0xc6, 0x98, 0x46,
  38958. 0x4c, 0xb3, 0xb4, 0x59, 0xdc, 0xb7, 0xdc, 0xbb, 0x56, 0x0f, 0x09, 0x14,
  38959. 0x28, 0x43, 0x9f, 0xb8, 0x75, 0xed, 0xcb, 0x97, 0x25, 0xaf, 0xa5, 0xeb,
  38960. 0x46, 0x14, 0xa6, 0x38, 0x68, 0x06, 0xe0, 0x6e, 0x55, 0x68, 0x6b, 0xf3,
  38961. 0xd8, 0x6d, 0x59, 0x65, 0x65, 0xff, 0x48, 0xfd, 0xdb, 0x3d, 0xe2, 0x21,
  38962. 0xb4, 0x7b, 0x78, 0x6a, 0x2e, 0x28, 0xb8, 0x21, 0xc4, 0x72, 0xf4, 0xef,
  38963. 0xfb, 0x74, 0x43, 0x29, 0xf2, 0x30, 0xc9, 0xca, 0x78, 0x93, 0x72, 0xfd,
  38964. 0x84, 0xa4, 0x95, 0xe0, 0xcd, 0xb1, 0x48, 0x29, 0xe7, 0xd1, 0x27, 0xf7,
  38965. 0xdc, 0x31, 0x6e, 0x00, 0x04, 0xd7, 0x7c, 0xfd, 0x2d, 0x25, 0xe9, 0xdb,
  38966. 0xc2, 0xb8, 0x14, 0x26, 0xed, 0x63, 0xb1, 0x50, 0x0a, 0x3c, 0xb2, 0x79,
  38967. 0x98, 0x79, 0x81, 0x2d, 0xdb, 0x60, 0x97, 0x99, 0xc0, 0x0a, 0x89, 0x9f,
  38968. 0x90, 0x19, 0x0b, 0xb3, 0x97, 0xd2, 0xf7, 0x50, 0xa5, 0x1d, 0x7d, 0x71,
  38969. 0x75, 0xe6, 0x58, 0x62, 0x53, 0x95, 0x40, 0x9e, 0xc7, 0xd3, 0x72, 0xa1,
  38970. 0xae, 0x07, 0xb3, 0x8a, 0x56, 0x61, 0x99, 0x81, 0x3e, 0xe4, 0x5e, 0x78,
  38971. 0x57, 0xd1, 0x8a, 0xc4, 0x04, 0x38, 0x13, 0xa0, 0x5d, 0x68, 0x6d, 0x22,
  38972. 0xae, 0xda, 0xfc, 0x67, 0xbb, 0xfb, 0x8e, 0x1a, 0xdc, 0x24, 0xf7, 0xc8,
  38973. 0xf9, 0x92, 0x6f, 0x4e, 0xb5, 0xe7, 0x6d, 0x13, 0x88, 0x05, 0x5c, 0xbb,
  38974. 0xe0, 0x24, 0x2a, 0x96, 0xc6, 0x70, 0x52, 0x14, 0xd0, 0xd9, 0xd8, 0xb2,
  38975. 0x5b, 0xdc, 0x85, 0xcf, 0x62, 0xb4, 0xcf, 0x77, 0xf1, 0xe5, 0x51, 0xeb,
  38976. 0xef, 0xe9, 0x3e, 0xf0, 0x16, 0xd2, 0xcc, 0x38, 0x0a, 0x47, 0x91, 0xc0,
  38977. 0xe0, 0x14, 0x1a, 0xf9, 0x74, 0xd1, 0x32, 0x8b, 0x02, 0x36, 0x05, 0x55,
  38978. 0x62, 0xa7, 0xae, 0x77, 0xb0, 0x01, 0x3d, 0x2c, 0x91, 0xbe, 0xfa, 0xdd,
  38979. 0x9c, 0x17, 0x42, 0xc1, 0x01, 0x4d, 0xd8, 0x27, 0x3c, 0x10, 0x82, 0x66,
  38980. 0x11, 0x91, 0x8b, 0xc8, 0x52, 0xd5, 0xc1, 0x1d, 0xee, 0xb2, 0x90, 0x17,
  38981. 0xed, 0xf3, 0xad, 0xa5, 0xd5, 0xeb, 0xf2, 0x9b, 0x78, 0xbf, 0x2d, 0x5a,
  38982. 0xad, 0xe5, 0x53, 0xe6, 0xc1, 0x3b, 0xd8, 0xf3, 0x6b, 0xc5, 0x4c, 0x87,
  38983. 0x0a, 0xe3, 0xc8, 0xc7, 0xe5, 0x42, 0x2c, 0xe2, 0x13, 0x1a, 0xe7, 0x27,
  38984. 0x20, 0x3e, 0x95, 0x13, 0x1e, 0xbb, 0x03, 0xae, 0xc0, 0x84, 0x14, 0x6d,
  38985. 0x7b, 0xf7, 0x98, 0x08, 0x18, 0x12, 0xb4, 0x4f, 0x99, 0x4a, 0xcf, 0xd0,
  38986. 0x4a, 0x5d, 0x21, 0x16, 0xf6, 0xdf, 0x10, 0xc7, 0xbe, 0xe6, 0x79, 0x3b,
  38987. 0x35, 0x2a, 0xa6, 0xd6, 0x19, 0x9c, 0xde, 0xbd, 0xaf, 0x72, 0xd2, 0x25,
  38988. 0xe0, 0xa4, 0xde, 0x99, 0x44, 0x18, 0x66, 0x41, 0xc7, 0x56, 0xf7, 0xdc,
  38989. 0x32, 0x56, 0x57, 0x39, 0x18, 0x31, 0xc8, 0x75, 0x01, 0xc3, 0xf3, 0x46,
  38990. 0xcf, 0xbf, 0xc6, 0x10, 0xb5, 0x1c, 0x38, 0xf9, 0xa4, 0xa5, 0x44, 0xa1,
  38991. 0x0b, 0x25, 0x48, 0x9c, 0xd3, 0x1c, 0x55, 0x54, 0x15, 0x9f, 0xe3, 0x74,
  38992. 0x5b, 0xb1, 0x92, 0xb6, 0x52, 0x61, 0xba, 0x2f, 0x53, 0x91, 0x17, 0x44,
  38993. 0x94, 0x00, 0xe4, 0x43, 0xa0, 0xe7, 0x0d, 0xaa, 0x8a, 0x5b, 0x81, 0x43,
  38994. 0xad, 0xfb, 0x50, 0xfe, 0xcf, 0x85, 0x2d, 0xfa, 0xc8, 0x1d, 0xad, 0xc8,
  38995. 0x7a, 0x7c, 0x5e, 0xf3, 0x90, 0x35, 0x5e, 0x67, 0xce, 0x57, 0x4d, 0xa0,
  38996. 0x22, 0x9e, 0x07, 0x4a, 0xf5, 0x9e, 0x5f, 0x91, 0x45, 0xd8, 0x62, 0xe0,
  38997. 0xf3, 0x87, 0x3b, 0xb7, 0x89, 0x2f, 0xdf, 0x8b, 0x82, 0xb1, 0x86, 0xc3,
  38998. 0xa4, 0xa3, 0x68, 0xc7, 0x73, 0x9e, 0x68, 0x8d, 0x24, 0x6a, 0x29, 0x94,
  38999. 0x58, 0x57, 0x4b, 0x81, 0x00, 0xe2, 0x2b, 0x94, 0x0a, 0xf5, 0x96, 0xa3,
  39000. 0x23, 0x9a, 0x7b, 0xd0, 0x2d, 0xcb, 0x6a, 0x8e, 0xae, 0x1b, 0x1c, 0x34,
  39001. 0xed, 0x30, 0x4e, 0xca, 0x29, 0x21, 0xfc, 0x3d, 0x70, 0x11, 0xc1, 0x5f,
  39002. 0x3e, 0xc2, 0x9e, 0x88, 0x71, 0x29, 0xa3, 0x8f, 0x92, 0xf5, 0x46, 0x77,
  39003. 0xd5, 0x47, 0x2d, 0x2b, 0x66, 0x1c, 0x07, 0xf0, 0xfc, 0x7b, 0xa0, 0x13,
  39004. 0x00, 0xae, 0xa5, 0x61, 0x92, 0x36, 0xeb, 0x7e, 0x43, 0x91, 0x20, 0x72,
  39005. 0xe5, 0xba, 0x7f, 0x79, 0x23, 0x12, 0x3e, 0xb2, 0x4b, 0x13, 0xa1, 0x8c,
  39006. 0x84, 0x72, 0x3b, 0x45, 0x62, 0xcf, 0x2e, 0x78, 0xc4, 0x9c, 0x22, 0x09,
  39007. 0xfa, 0x59, 0x9d, 0xdf, 0x13, 0x54, 0x66, 0xe2, 0x6f, 0xfa, 0xb5, 0x2a,
  39008. 0x27, 0x3e, 0x17, 0x82, 0xf3, 0x2a, 0x4d, 0x36, 0xd3, 0xf0, 0x8d, 0x43,
  39009. 0x40, 0x2c, 0x84, 0x68, 0xbe, 0x40, 0x50, 0x7d, 0xa3, 0x27, 0x5e, 0xde,
  39010. 0x4d, 0x04, 0x6f, 0xe8, 0x96, 0x9c, 0x7a, 0x1d, 0xb8, 0x2b, 0x8a, 0xb1,
  39011. 0x6e, 0xe2, 0x36, 0x07, 0x22, 0x50, 0xd9, 0x71, 0x93, 0x48, 0xb5, 0x51,
  39012. 0xce, 0x2a, 0x64, 0x6b, 0x11, 0xa6, 0xb9, 0x40, 0x2d, 0x6c, 0xd2, 0x76,
  39013. 0x52, 0xc6, 0xe3, 0xa6, 0x6b, 0xd2, 0x3f, 0x39, 0xd2, 0x13, 0x28, 0xa4,
  39014. 0xa9, 0x58, 0x99, 0xe8, 0x3d, 0x08, 0xfa, 0x3c, 0x34, 0x39, 0x4d, 0x7d,
  39015. 0x5e, 0x10, 0x72, 0x51, 0x96, 0x1d, 0x4b, 0xd9, 0x3e, 0xc9, 0x22, 0x4c,
  39016. 0x72, 0x63, 0xf8, 0x87, 0x4b, 0xe7, 0x41, 0xac, 0xcd, 0xd6, 0x34, 0xa2,
  39017. 0xe1, 0xe8, 0x66, 0x81, 0x04, 0x7d, 0x70, 0x95, 0xba, 0x37, 0x86, 0x9e,
  39018. 0x1f, 0x9a, 0x1b, 0xe4, 0x35, 0xac, 0xe6, 0xcf, 0x48, 0x55, 0x6e, 0xbb,
  39019. 0x9d, 0x40, 0x79, 0x96, 0xdd, 0xac, 0xf8, 0xf5, 0x99, 0xad, 0x43, 0x0d,
  39020. 0xad, 0xa9, 0x62, 0xc0, 0x70, 0x8b, 0x50, 0x9b, 0xca, 0x0d, 0x3e, 0x54,
  39021. 0x9c, 0x27, 0xd5, 0x9e, 0x20, 0xe2, 0xe0, 0xb0, 0xb0, 0xbe, 0x8e, 0x56,
  39022. 0x43, 0x95, 0x9b, 0x34, 0xd1, 0x05, 0x28, 0xa0, 0xee, 0xd9, 0xab, 0x6a,
  39023. 0xa7, 0xbb, 0xb7, 0x1b, 0x3a, 0x5d, 0x33, 0x97, 0x25, 0x54, 0xe4, 0x0e,
  39024. 0x64, 0x79, 0xed, 0x16, 0x62, 0x89, 0x70, 0x4a, 0xa6, 0x47, 0x40, 0xd7,
  39025. 0xa3, 0xd2, 0x6f, 0x28, 0xdd, 0xc5, 0x04, 0xab, 0x7e, 0x7e, 0x1e, 0xb0,
  39026. 0x19, 0x02, 0x48, 0xb5, 0x88, 0x82, 0x75, 0xaf, 0x66, 0x74, 0xca, 0xf6,
  39027. 0xd7, 0xe8, 0x6d, 0xfa, 0x5e, 0xfa, 0xaf, 0xa8, 0x04, 0xaa, 0x2c, 0x09,
  39028. 0xf1, 0x4c, 0x36, 0x75, 0xb5, 0xdc, 0xe8, 0x04, 0x80, 0xd3, 0x14, 0x78,
  39029. 0x09, 0x5b, 0xfd, 0x52, 0x6f, 0xd9, 0x3c, 0x1c, 0x02, 0x3b, 0x77, 0xb8,
  39030. 0xa1, 0xe9, 0xa4, 0xb7, 0x42, 0x62, 0xee, 0xea, 0x43, 0xf3, 0xd8, 0xd0,
  39031. 0x7a, 0x53, 0x91, 0x34, 0x7f, 0xe7, 0x9a, 0xc6
  39032. };
  39033. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39034. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_pub_key[] = {
  39035. 0x15, 0xc9, 0xe5, 0x53, 0x2f, 0xd8, 0x1f, 0xb4, 0xa3, 0x9f,
  39036. 0xae, 0xad, 0xb3, 0x10, 0xd0, 0x72, 0x69, 0xd3, 0x02, 0xf3,
  39037. 0xdf, 0x67, 0x5a, 0x31, 0x52, 0x19, 0xca, 0x39, 0x27, 0x77,
  39038. 0x61, 0x6d, 0x0f, 0xc1, 0x33, 0x26, 0x09, 0xf0, 0xf9, 0x4d,
  39039. 0x12, 0x7a, 0xef, 0xf7, 0x21, 0x26, 0x2c, 0xe0, 0xe2, 0x92,
  39040. 0x1f, 0x9d, 0xd1, 0xaa, 0xaf, 0x08, 0x14, 0xf2, 0xaa, 0x24,
  39041. 0x99, 0x0f, 0x20, 0x57, 0x35, 0x04, 0x32, 0x96, 0x8e, 0x6e,
  39042. 0x10, 0x64, 0xe3, 0xe3, 0x57, 0x26, 0x33, 0x32, 0x7b, 0xe4,
  39043. 0x18, 0x41, 0x77, 0xd3, 0x24, 0x63, 0x3d, 0x11, 0xea, 0xdc,
  39044. 0xbe, 0x59, 0xff, 0x8d, 0xc2, 0xe4, 0xc7, 0x04, 0xf3, 0xd4,
  39045. 0xe0, 0x1d, 0x5e, 0x09, 0x46, 0xbf, 0x02, 0x05, 0xc7, 0xa6,
  39046. 0xb7, 0x82, 0x40, 0x1f, 0x55, 0xe9, 0x77, 0x82, 0xc0, 0xcc,
  39047. 0x86, 0x99, 0x19, 0x99, 0xa2, 0xc9, 0x1b, 0x4f, 0xdd, 0x49,
  39048. 0x4c, 0x78, 0x0a, 0x58, 0xb8, 0xf0, 0x23, 0xac, 0x1a, 0x71,
  39049. 0x57, 0x6d, 0xd6, 0x3a, 0x3a, 0x6f, 0x93, 0xb3, 0x2b, 0x09,
  39050. 0xbe, 0xec, 0x7b, 0x5b, 0xf7, 0x3a, 0xed, 0xf9, 0xd0, 0xb1,
  39051. 0xfe, 0x9f, 0x9b, 0xec, 0x11, 0xb6, 0x6b, 0xd1, 0xb6, 0x00,
  39052. 0x72, 0x7f, 0x68, 0x9a, 0x61, 0xa5, 0xf5, 0x6e, 0xe9, 0x46,
  39053. 0xa4, 0x82, 0x08, 0x9f, 0x50, 0x4c, 0x75, 0xc3, 0x48, 0x85,
  39054. 0x76, 0x39, 0xea, 0x0c, 0xf2, 0xe8, 0x7e, 0x48, 0x69, 0xd9,
  39055. 0x6f, 0x9a, 0x89, 0x7d, 0x98, 0xc1, 0x16, 0xdc, 0x2f, 0xc7,
  39056. 0x0a, 0x11, 0xa8, 0xbb, 0xe7, 0x91, 0xb1, 0x0f, 0x0e, 0xf0,
  39057. 0xb4, 0xc8, 0x41, 0x7e, 0x62, 0x9e, 0x3c, 0x30, 0x4c, 0xbc,
  39058. 0x4c, 0xeb, 0x37, 0xaf, 0x48, 0x72, 0x59, 0x64, 0x8e, 0xfb,
  39059. 0x77, 0x11, 0x28, 0xdd, 0x30, 0x52, 0x8e, 0x69, 0x8c, 0x9f,
  39060. 0x3d, 0xec, 0xdf, 0xa7, 0x5f, 0x42, 0x18, 0xda, 0xba, 0x1a,
  39061. 0x96, 0x91, 0x7d, 0x62, 0xd5, 0x52, 0xff, 0x44, 0xc9, 0x1d,
  39062. 0x29, 0xa6, 0xb9, 0x03, 0x9a, 0x26, 0x26, 0xcf, 0x57, 0x40,
  39063. 0x70, 0x7e, 0x2b, 0xbd, 0xf0, 0x81, 0x71, 0x0f, 0x0b, 0x2e,
  39064. 0x9b, 0x03, 0xba, 0x31, 0x41, 0x68, 0x37, 0xc8, 0xff, 0xea,
  39065. 0xc4, 0x73, 0xa5, 0xf9, 0xc2, 0x92, 0x78, 0x0c, 0xe7, 0xfd,
  39066. 0x5d, 0xb2, 0x01, 0xb5, 0x8d, 0xeb, 0x64, 0xd4, 0x14, 0xea,
  39067. 0x7a, 0xd1, 0x42, 0xc8, 0x99, 0xe4, 0x7d, 0x5b, 0x7e, 0x3b,
  39068. 0x8f, 0xab, 0x82, 0x12, 0xdf, 0xbb, 0xa1, 0x45, 0x30, 0xc9,
  39069. 0x0f, 0xb9, 0xe5, 0xba, 0xe6, 0x8a, 0xf3, 0x78, 0x61, 0xcc,
  39070. 0x9f, 0xe1, 0x46, 0x2a, 0x9a, 0x18, 0x0e, 0x2a, 0x57, 0xf3,
  39071. 0xe5, 0x56, 0xd1, 0x42, 0x48, 0xe1, 0x5a, 0x8e, 0x33, 0xce,
  39072. 0x19, 0xe5, 0x3e, 0x7f, 0x00, 0x70, 0x9c, 0x4c, 0xd3, 0xe1,
  39073. 0x0c, 0xa1, 0x7e, 0xd4, 0xa9, 0x9e, 0x8b, 0xe2, 0xf0, 0xac,
  39074. 0xdb, 0xa6, 0x72, 0x75, 0x67, 0xa6, 0x57, 0xed, 0x79, 0x2e,
  39075. 0xca, 0x8d, 0xeb, 0x9b, 0x9e, 0xb7, 0xbf, 0x30, 0x02, 0x2b,
  39076. 0xb3, 0x43, 0x89, 0x9b, 0xa8, 0x88, 0xa5, 0xbb, 0x33, 0xd9,
  39077. 0x99, 0x30, 0x7c, 0xc7, 0xd4, 0x28, 0x5e, 0x5e, 0x3f, 0x9d,
  39078. 0x6d, 0x35, 0x75, 0x33, 0x8e, 0xff, 0x84, 0x2e, 0x2d, 0xda,
  39079. 0xf0, 0xff, 0x70, 0xe5, 0xb5, 0x62, 0x96, 0x33, 0x3a, 0xd9,
  39080. 0xb5, 0x82, 0x25, 0x81, 0x81, 0x40, 0x5d, 0x4f, 0x11, 0x86,
  39081. 0x63, 0x1a, 0x06, 0xc1, 0x67, 0xc7, 0x49, 0x03, 0xc7, 0xe4,
  39082. 0x6f, 0xb4, 0x13, 0x3e, 0x57, 0x62, 0xfd, 0x8a, 0xc6, 0x2b,
  39083. 0x65, 0x5b, 0xa4, 0x29, 0x57, 0x8d, 0xde, 0xa5, 0xee, 0x32,
  39084. 0xc2, 0x76, 0x03, 0xca, 0xce, 0xc1, 0x48, 0xec, 0x45, 0xcf,
  39085. 0x30, 0x21, 0x28, 0x7f, 0x10, 0x47, 0xd2, 0xdb, 0xee, 0xca,
  39086. 0x5b, 0x0f, 0xd5, 0x39, 0x3a, 0xc3, 0xa6, 0x78, 0xb2, 0x15,
  39087. 0xaf, 0x82, 0x3c, 0x2f, 0xc4, 0x51, 0x5c, 0x52, 0xad, 0xf2,
  39088. 0x89, 0x92, 0x8e, 0xf3, 0x50, 0x38, 0xed, 0xf8, 0xc9, 0x14,
  39089. 0x4c, 0xe4, 0xa3, 0x9a, 0xaf, 0xc4, 0x5c, 0xf3, 0x9f, 0xc3,
  39090. 0xa3, 0xc0, 0xbe, 0x45, 0x1b, 0x21, 0x63, 0xfa, 0xe0, 0xe0,
  39091. 0x91, 0x2b, 0x42, 0xca, 0x91, 0xfb, 0x5e, 0x97, 0x9a, 0x0a,
  39092. 0xd4, 0x88, 0xba, 0xb8, 0x22, 0xc6, 0xbf, 0x56, 0x58, 0x1e,
  39093. 0x92, 0xa9, 0x9d, 0xa7, 0xed, 0xc9, 0xab, 0x54, 0x4f, 0x75,
  39094. 0x8d, 0x42, 0xc1, 0xe1, 0x61, 0xd0, 0x91, 0x9a, 0x3a, 0x40,
  39095. 0x9a, 0xa3, 0xfb, 0x7b, 0x4e, 0xf0, 0x85, 0xf0, 0xdc, 0x40,
  39096. 0x72, 0x9f, 0x05, 0xa8, 0xbe, 0x95, 0x5a, 0x7f, 0xba, 0x75,
  39097. 0x00, 0x6e, 0x95, 0x76, 0xbd, 0xb2, 0x40, 0xf5, 0xb0, 0x64,
  39098. 0x0a, 0x2f, 0x06, 0x3d, 0x9f, 0xac, 0x6a, 0xa5, 0x46, 0x5a,
  39099. 0x85, 0xa4, 0x6f, 0xee, 0x27, 0xa0, 0xeb, 0x5f, 0x1f, 0x91,
  39100. 0xbd, 0x2b, 0x02, 0x16, 0xdf, 0x74, 0x97, 0x2c, 0xd0, 0xa8,
  39101. 0x9f, 0x3a, 0x7b, 0xdf, 0x3e, 0x98, 0x4a, 0x91, 0xdc, 0x19,
  39102. 0x96, 0x88, 0x75, 0x21, 0x1a, 0x6a, 0xa8, 0x4b, 0x1f, 0x35,
  39103. 0xd1, 0x92, 0xf5, 0x76, 0xf4, 0x72, 0x55, 0x13, 0xdb, 0x5d,
  39104. 0x07, 0x8d, 0xd9, 0x72, 0xe4, 0x75, 0xde, 0x80, 0xbc, 0xe9,
  39105. 0x9c, 0xf0, 0x5c, 0x6a, 0x8a, 0x0e, 0x34, 0xf6, 0x3f, 0x5c,
  39106. 0xef, 0x0e, 0xcc, 0x52, 0x38, 0x2d, 0x7b, 0xc2, 0x1b, 0x69,
  39107. 0x9f, 0xe5, 0xed, 0x14, 0xb0, 0x91, 0x0b, 0xe9, 0x4d, 0x34,
  39108. 0xd5, 0xaa, 0xd4, 0xd2, 0x46, 0x39, 0x45, 0x7e, 0x85, 0x2f,
  39109. 0xdb, 0x89, 0xf4, 0xff, 0x05, 0x74, 0x51, 0xba, 0xdd, 0xee,
  39110. 0xf6, 0xc2, 0xc1, 0x0a, 0x8f, 0xd9, 0xeb, 0xc7, 0x61, 0x30,
  39111. 0x8f, 0x86, 0x8b, 0x1f, 0x82, 0xc1, 0x22, 0xfd, 0x83, 0xf4,
  39112. 0x5d, 0xc5, 0x94, 0xf5, 0xd7, 0x17, 0xc7, 0x7b, 0x71, 0xf5,
  39113. 0x5e, 0x15, 0x49, 0x70, 0xb2, 0x57, 0xa0, 0xc0, 0x57, 0x63,
  39114. 0x53, 0x35, 0xb6, 0x52, 0x20, 0x7b, 0x83, 0xd4, 0x57, 0x63,
  39115. 0x25, 0x8e, 0x83, 0xb3, 0x8e, 0x26, 0x1f, 0x09, 0xde, 0x14,
  39116. 0xd6, 0xa6, 0xfc, 0xe5, 0x93, 0x3c, 0x88, 0x8e, 0xf5, 0x10,
  39117. 0x57, 0xb9, 0xc9, 0x9b, 0xff, 0x72, 0x9d, 0x3d, 0x3f, 0x97,
  39118. 0xd9, 0x3c, 0x20, 0xe2, 0x57, 0xfd, 0x2a, 0x5c, 0x17, 0x12,
  39119. 0xe6, 0x08, 0xaf, 0xe4, 0x26, 0x96, 0xb9, 0x6d, 0xc3, 0xac,
  39120. 0x22, 0xf3, 0x8b, 0x89, 0xde, 0xc7, 0x8a, 0x93, 0x06, 0xf7,
  39121. 0x1d, 0x08, 0x21, 0x36, 0x16, 0x74, 0x2b, 0x97, 0x23, 0xe4,
  39122. 0x79, 0x31, 0x08, 0x23, 0x62, 0x30, 0x67, 0xe2, 0xed, 0x30,
  39123. 0x9b, 0x0c, 0xf9, 0x08, 0x7a, 0x29, 0x73, 0xc6, 0x77, 0x8a,
  39124. 0xbb, 0x2a, 0x1c, 0x66, 0xd0, 0xdd, 0x9e, 0xa3, 0xe9, 0x62,
  39125. 0xcc, 0xb7, 0x88, 0x25, 0x4a, 0x5f, 0xbc, 0xaa, 0xe3, 0xe4,
  39126. 0x4f, 0xec, 0xa6, 0x8e, 0xa6, 0xa4, 0x1b, 0x22, 0x2b, 0x2c,
  39127. 0x8f, 0x57, 0x7f, 0xb7, 0x33, 0xfe, 0x16, 0x43, 0x85, 0xc5,
  39128. 0xd2, 0x95, 0xe6, 0xb9, 0x21, 0x68, 0x88, 0x98, 0x33, 0x8c,
  39129. 0x1d, 0x15, 0x9c, 0x4d, 0x62, 0x1f, 0x6b, 0xe8, 0x7a, 0x2d,
  39130. 0x6b, 0x0e, 0xc3, 0xde, 0x1a, 0xa8, 0xed, 0x67, 0xb3, 0xb3,
  39131. 0x36, 0x5b, 0x4b, 0xcb, 0xe8, 0xa8, 0x5c, 0x0b, 0x2f, 0xca,
  39132. 0xd7, 0x71, 0xe8, 0x85, 0xe7, 0x4d, 0xe5, 0x7b, 0x45, 0xed,
  39133. 0xb2, 0x4c, 0x69, 0x04, 0x7e, 0x4f, 0xc0, 0xef, 0x1a, 0xca,
  39134. 0x0d, 0xa6, 0xc4, 0x79, 0x15, 0x78, 0x9c, 0xd2, 0x91, 0x3c,
  39135. 0x32, 0x55, 0x40, 0xe7, 0xcb, 0x7e, 0xde, 0x07, 0xa6, 0x97,
  39136. 0x00, 0x2d, 0x70, 0xf6, 0x3d, 0x15, 0xdf, 0x29, 0x8e, 0xa3,
  39137. 0x96, 0x6d, 0xf2, 0xbb, 0xa5, 0x1b, 0x7b, 0x58, 0x30, 0xf6,
  39138. 0x17, 0xbd, 0xda, 0x13, 0xf7, 0x33, 0xc2, 0x62, 0x32, 0xd4,
  39139. 0x1c, 0x2e, 0x31, 0x74, 0x92, 0xad, 0x99, 0x8c, 0x0e, 0x7c,
  39140. 0x50, 0x21, 0xcd, 0xff, 0x41, 0xeb, 0xd1, 0xca, 0x14, 0xb7,
  39141. 0xb2, 0x31, 0x2f, 0xbe, 0x16, 0xce, 0x4f, 0x26, 0x16, 0x04,
  39142. 0xc2, 0xaf, 0xbe, 0x0d, 0x24, 0xab, 0x9a, 0x21, 0x37, 0x06,
  39143. 0xac, 0x50, 0x23, 0xf1, 0xbe, 0x5c, 0xbb, 0x64, 0xf3, 0xd3,
  39144. 0x66, 0xa3, 0xb8, 0xbe, 0x8b, 0x49, 0x8d, 0xf6, 0xc7, 0xb9,
  39145. 0x8f, 0x4e, 0x31, 0x06, 0x51, 0xe5, 0xf3, 0x0e, 0x56, 0xc4,
  39146. 0x24, 0x30, 0xf5, 0xe9, 0x36, 0x71, 0xbc, 0xc9, 0x70, 0x2c,
  39147. 0x6c, 0x4c, 0x15, 0x43, 0x44, 0xa4, 0xfc, 0xf1, 0xd2, 0x71,
  39148. 0x6c, 0x4c, 0xce, 0x30, 0x6c, 0x05, 0x7d, 0x2e, 0xb7, 0xbc,
  39149. 0xe4, 0x65, 0x76, 0x24, 0x75, 0x36, 0xdf, 0x28, 0xfc, 0xcd,
  39150. 0x9a, 0xba, 0xc2, 0xcd, 0xb0, 0x30, 0xdb, 0xe7, 0x2e, 0x3c,
  39151. 0x92, 0x63, 0x1d, 0x30, 0x23, 0x74, 0xb1, 0xb8, 0xcc, 0xd7,
  39152. 0xb6, 0x90, 0x65, 0x73, 0xa2, 0x2a, 0x6e, 0x49, 0x95, 0x0d,
  39153. 0xab, 0x24, 0xdf, 0x2d, 0xbf, 0x76, 0x46, 0x01, 0x44, 0xe4,
  39154. 0x18, 0x8e, 0xd5, 0x9a, 0x76, 0xc9, 0xc6, 0xbc, 0xdb, 0x7f,
  39155. 0x80, 0x52, 0xc6, 0x40, 0x41, 0x12, 0x36, 0x7c, 0x80, 0x69,
  39156. 0xce, 0x7b, 0xe1, 0xa0, 0x53, 0xa2, 0xd6, 0x8f, 0x3f, 0xf7,
  39157. 0xd7, 0x61, 0x09, 0x70, 0xa2, 0xa0, 0xc6, 0xaf, 0xa0, 0xd0,
  39158. 0xfa, 0x13, 0xbf, 0xc0, 0x69, 0x15, 0xce, 0x15, 0xec, 0x24,
  39159. 0x4b, 0x6b, 0xdc, 0x93, 0x51, 0xc6, 0x82, 0x19, 0x92, 0x84,
  39160. 0x5d, 0x99, 0xb0, 0x90, 0x2c, 0xcc, 0x2a, 0x81, 0x6b, 0x22,
  39161. 0x64, 0x0a, 0xcb, 0x51, 0x25, 0x82, 0x50, 0x02, 0x2d, 0x3e,
  39162. 0xd4, 0x72, 0xb3, 0x0c, 0x15, 0x77, 0xd2, 0xca, 0x98, 0x2f,
  39163. 0x41, 0x93, 0x14, 0xb2, 0x7f, 0xa1, 0x97, 0xa3, 0xb8, 0x8a,
  39164. 0x56, 0x24, 0x38, 0xa7, 0x36, 0xc5, 0x01, 0xc0, 0x9f, 0x3f,
  39165. 0x3e, 0x9a, 0xf6, 0xe9, 0x16, 0x82, 0x01, 0x58, 0x70, 0x0e,
  39166. 0x0d, 0xbc, 0xfa, 0x03, 0x57, 0x65, 0xa8, 0x5a, 0x3d, 0x57,
  39167. 0x81, 0x23, 0xbe, 0x6e, 0xa9, 0xe8, 0x22, 0xdf, 0x2f, 0x70,
  39168. 0xeb, 0x0a, 0x03, 0x96, 0x6b, 0xef, 0x20, 0x9f, 0xf2, 0x62,
  39169. 0xe7, 0xb2, 0x6e, 0x3a, 0x1e, 0x40, 0x1f, 0xd2, 0x97, 0x48,
  39170. 0xd1, 0x18, 0xf0, 0xeb, 0x52, 0x58, 0x02, 0x26, 0xce, 0x75,
  39171. 0xb1, 0x3a, 0x9d, 0x5b, 0x52, 0x94, 0xb2, 0x6e, 0x0e, 0x3f,
  39172. 0x39, 0xb6, 0xd9, 0x8a, 0x9d, 0xe8, 0x7c, 0x83, 0x32, 0xcc,
  39173. 0x43, 0x35, 0x9b, 0x7a, 0xed, 0xb2, 0x1e, 0x51, 0x37, 0x6c,
  39174. 0x14, 0xd8, 0xb8, 0x55, 0xb3, 0x91, 0xef, 0x0c, 0x3a, 0xe5,
  39175. 0x77, 0xd0, 0xbd, 0xb0, 0x7d, 0x38, 0x84, 0x2a, 0x47, 0xb2,
  39176. 0xb6, 0xda, 0xd7, 0x75, 0xd6, 0x2e, 0x60, 0xc7, 0x10, 0x52,
  39177. 0xf7, 0xdd, 0x09, 0x15, 0x6f, 0x04, 0x31, 0xc3, 0x5a, 0x6b,
  39178. 0x0c, 0x60, 0x10, 0xa8, 0x6e, 0x20, 0xa9, 0xdd, 0xb7, 0x72,
  39179. 0xc3, 0x9e, 0x85, 0xd2, 0x8f, 0x16, 0x7e, 0x3d, 0xe0, 0x63,
  39180. 0x81, 0x32, 0xfd, 0xca, 0xbc, 0x0f, 0xef, 0x3e, 0x74, 0x6a,
  39181. 0xb1, 0x60, 0xc1, 0x10, 0x50, 0x7c, 0x67, 0xa4, 0x19, 0xa7,
  39182. 0xb8, 0xed, 0xe6, 0xf5, 0x4e, 0x41, 0x53, 0xa6, 0x72, 0x1b,
  39183. 0x2c, 0x33, 0x6a, 0x37, 0xf1, 0xb5, 0x1c, 0x01, 0x7d, 0xa2,
  39184. 0x1f, 0x2c, 0x4e, 0x0a, 0xbf, 0xd4, 0x2c, 0x24, 0x91, 0x58,
  39185. 0x62, 0xfb, 0xf8, 0x63, 0xd9, 0xf8, 0x78, 0xf5, 0xc7, 0x78,
  39186. 0x32, 0xda, 0x99, 0xeb, 0x58, 0x20, 0x25, 0x19, 0xb1, 0x06,
  39187. 0x7f, 0x6a, 0x29, 0x20, 0xdb, 0xc8, 0x22, 0x48, 0xa9, 0x7f,
  39188. 0x24, 0x54, 0x8d, 0x7d, 0x8d, 0xb1, 0x69, 0xb2, 0xa3, 0x98,
  39189. 0x14, 0x0f, 0xba, 0xfa, 0xb6, 0x15, 0xe8, 0x28, 0x99, 0x3f,
  39190. 0x30, 0x04, 0x50, 0xab, 0x5a, 0x3c, 0xf1, 0x97, 0xe1, 0xc8,
  39191. 0x0f, 0x0e, 0xb4, 0x11, 0x63, 0x5a, 0x79, 0x08, 0x48, 0x75,
  39192. 0xaf, 0x9b, 0xca, 0xd9, 0x13, 0x18, 0xcc, 0xb1, 0xb3, 0xee,
  39193. 0xdd, 0x63, 0xdd, 0xf4, 0x21, 0x98, 0x76, 0xe2, 0x3e, 0xd5,
  39194. 0x86, 0x23, 0x33, 0x7e, 0xc7, 0xb4, 0x35, 0x4b, 0xc2, 0x2d,
  39195. 0xe1, 0xe2, 0xb0, 0x6c, 0x8b, 0x9b, 0x20, 0x3d, 0x48, 0x24,
  39196. 0x7c, 0xea, 0xa1, 0x75, 0x27, 0xe5, 0xf4, 0x70, 0xeb, 0x3b,
  39197. 0xc7, 0x26, 0x37, 0x04, 0xff, 0x8a, 0x7a, 0xd0, 0xc2, 0xb7,
  39198. 0x84, 0xb7, 0x29, 0xfb, 0x0e, 0xa3, 0xa8, 0x71, 0xcd, 0x58,
  39199. 0x06, 0x36, 0xe2, 0xf2, 0x77, 0xcc, 0x0f, 0x78, 0x08, 0x2b,
  39200. 0xbb, 0xe3, 0x53, 0x05, 0x71, 0xdc, 0x6c, 0x37, 0x32, 0x91,
  39201. 0x46, 0x42, 0x4f, 0x21, 0xe0, 0x34, 0xad, 0x3f, 0x30, 0x5a,
  39202. 0xc7, 0x0d, 0x17, 0x19, 0x39, 0x31, 0x58, 0x69, 0x3c, 0x8c,
  39203. 0xbe, 0xe7, 0xa6, 0x3b, 0xad, 0xfb, 0x46, 0x89, 0x06, 0xc1,
  39204. 0x8c, 0x16, 0x9a, 0x06, 0x3a, 0xd0, 0x7e, 0xd6, 0xb0, 0x7b,
  39205. 0x7d, 0xf8, 0x91, 0x7c, 0xfa, 0xd9, 0x66, 0x39, 0xfa, 0xbc,
  39206. 0x57, 0xa7, 0x78, 0x8b, 0x36, 0x78, 0xc0, 0x1c, 0x0e, 0x23,
  39207. 0x05, 0x0e, 0x04, 0x61, 0x16, 0x34, 0xf9, 0xc6, 0x63, 0x58,
  39208. 0xdf, 0xf4, 0x52, 0xce, 0xd0, 0x0f, 0x0c, 0xec, 0xb1, 0x82,
  39209. 0xf4, 0x72, 0x73, 0x72, 0x3f, 0x02, 0xbe, 0xe3, 0x9c, 0x63,
  39210. 0x73, 0xc8, 0x21, 0x65, 0xba, 0x57, 0x52, 0xa9, 0x19, 0xac,
  39211. 0x68, 0x50, 0xbd, 0x2d, 0x72, 0x5b, 0x93, 0x0f, 0x1c, 0x81,
  39212. 0x77, 0xd7, 0x2e, 0xc3, 0x93, 0x52, 0x6e, 0xdc, 0x79, 0x52,
  39213. 0x9f, 0xe3, 0xde, 0xe1, 0xba, 0x58, 0x55, 0xab, 0x8a, 0xf2,
  39214. 0x35, 0x6a, 0xcf, 0x94, 0x1f, 0x17, 0xa4, 0x23, 0x2e, 0x8e,
  39215. 0x18, 0x21, 0xbe, 0x14, 0xfa, 0xe7, 0x59, 0xc5, 0x44, 0x34,
  39216. 0xce, 0x03, 0xf4, 0xb7, 0x75, 0xd3, 0x51, 0x55, 0xdf, 0xff,
  39217. 0xcf, 0x4f, 0x44, 0xee, 0x13, 0x9b, 0xcb, 0x12, 0xae, 0xe5,
  39218. 0x5b, 0x44, 0x65, 0x28, 0xcb, 0x6a, 0x9c, 0x24, 0x1d, 0xea,
  39219. 0x2d, 0x5e, 0xa5, 0xc3, 0x78, 0xad, 0xed, 0x0c, 0x05, 0xa6,
  39220. 0xaf, 0x95, 0x04, 0xd2, 0xb5, 0x91, 0x0e, 0xa0, 0x06, 0x77,
  39221. 0xc5, 0x82, 0xf6, 0xdd, 0x72, 0x83, 0x04, 0xcc, 0xb0, 0xab,
  39222. 0x7a, 0xf0, 0xb4, 0x4d, 0x36, 0x71, 0x72, 0x1a, 0x9a, 0x0d,
  39223. 0xcd, 0xa3, 0x11, 0xa8, 0x0d, 0x7d, 0x49, 0xce, 0x9c, 0x09,
  39224. 0x1d, 0x08, 0xa4, 0x39, 0x2e, 0x03, 0xdf, 0x3a, 0xc8, 0xfe,
  39225. 0x6a, 0x2b, 0x0b, 0x07, 0x80, 0x55, 0x8a, 0xa8, 0xe6, 0x0e,
  39226. 0xc9, 0x7e, 0x83, 0xce, 0x3a, 0x98, 0x98, 0x4e, 0x3e, 0x08,
  39227. 0x20, 0x8f, 0x10, 0xfc, 0xc1, 0xc4, 0xcf, 0x37, 0x8d, 0x69,
  39228. 0xd8, 0x57, 0x9d, 0x48, 0x80, 0x6a, 0xef, 0x0c, 0xdd, 0x27,
  39229. 0x99, 0xf9, 0xe7, 0xd0, 0xd2, 0x36, 0xd8, 0xed, 0x41, 0x14,
  39230. 0x1b, 0x10
  39231. };
  39232. #endif
  39233. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_sig[] = {
  39234. 0xb1, 0xd1, 0x8e, 0x83, 0x0b, 0x0d, 0xd2, 0x71, 0xb2, 0xaa, 0x31, 0x38,
  39235. 0x16, 0xf0, 0xb4, 0xbc, 0x64, 0x2b, 0x97, 0xa1, 0x08, 0x19, 0x4f, 0x52,
  39236. 0xfe, 0x99, 0x1a, 0xa9, 0xd4, 0x08, 0x93, 0x99, 0x88, 0xfd, 0x6a, 0xd6,
  39237. 0xd8, 0xdb, 0xf0, 0x71, 0x2a, 0xc9, 0x04, 0x83, 0xc9, 0x45, 0x59, 0x5d,
  39238. 0xe0, 0x36, 0x59, 0x53, 0x1b, 0xb8, 0x5a, 0xa6, 0x1f, 0xb4, 0x1b, 0x0a,
  39239. 0xfb, 0x3a, 0xba, 0xe3, 0xb7, 0x5e, 0x04, 0x14, 0x59, 0x09, 0x9a, 0x8e,
  39240. 0xc2, 0x77, 0x5a, 0x3d, 0xf1, 0x43, 0x67, 0x74, 0x78, 0xfc, 0xcd, 0x34,
  39241. 0xed, 0x35, 0x16, 0x38, 0x04, 0xe6, 0xe7, 0xd6, 0xd2, 0x90, 0x1b, 0x28,
  39242. 0xb6, 0x66, 0x1b, 0x57, 0x85, 0x5e, 0xa7, 0x9f, 0x86, 0x1a, 0x0d, 0xc3,
  39243. 0x7e, 0xed, 0xbd, 0x32, 0x8a, 0x35, 0xe1, 0xb3, 0x01, 0xdc, 0x9b, 0x44,
  39244. 0x88, 0xa1, 0x0b, 0x87, 0x6e, 0x55, 0x31, 0xb1, 0x27, 0xcb, 0x85, 0xa4,
  39245. 0x27, 0x56, 0x33, 0xb0, 0x39, 0x0d, 0xd3, 0x4b, 0xd1, 0xa2, 0x47, 0x07,
  39246. 0xc6, 0xf4, 0xe6, 0x1f, 0x88, 0x70, 0x70, 0x13, 0x7e, 0x2e, 0x17, 0x32,
  39247. 0x0a, 0x6b, 0x38, 0x34, 0xcf, 0x2f, 0x00, 0x36, 0x58, 0x8d, 0xe1, 0xdd,
  39248. 0xa7, 0x94, 0x2a, 0x8f, 0x87, 0x99, 0x67, 0x02, 0x4d, 0x5b, 0x56, 0xaf,
  39249. 0xef, 0xc4, 0x3c, 0xff, 0x72, 0x53, 0x95, 0x27, 0x03, 0x49, 0x94, 0x4f,
  39250. 0x94, 0x87, 0x1f, 0x52, 0x33, 0xed, 0xb9, 0x14, 0x7b, 0xe5, 0x6c, 0xef,
  39251. 0x7a, 0x17, 0x5a, 0xa4, 0x89, 0x2a, 0xfe, 0x68, 0xda, 0xdd, 0x48, 0xc2,
  39252. 0xf0, 0x92, 0xf4, 0xe4, 0xd6, 0xa6, 0x48, 0x08, 0x2c, 0xe8, 0xcd, 0x72,
  39253. 0xf6, 0x94, 0x3e, 0xc1, 0x82, 0xb8, 0x01, 0x58, 0xb2, 0xef, 0xef, 0xf4,
  39254. 0xcb, 0x93, 0x63, 0x2e, 0x33, 0x5b, 0xc9, 0xd6, 0x6a, 0xde, 0xad, 0xe8,
  39255. 0x1e, 0x3f, 0xa3, 0xf2, 0x35, 0x87, 0xc1, 0xc9, 0x48, 0x2f, 0x1b, 0x00,
  39256. 0xea, 0x3d, 0x04, 0x29, 0xd5, 0xc0, 0xe9, 0x1a, 0xc5, 0xce, 0x5e, 0xdb,
  39257. 0xd1, 0xee, 0x16, 0x9c, 0x05, 0x40, 0xf9, 0x21, 0x13, 0x72, 0x08, 0x39,
  39258. 0x6b, 0x63, 0x19, 0xcd, 0x6f, 0x64, 0xa0, 0xc3, 0x77, 0xb7, 0x50, 0xed,
  39259. 0xe9, 0x2d, 0xd5, 0x72, 0xea, 0xa6, 0xc1, 0x97, 0xb9, 0x6b, 0xe5, 0x81,
  39260. 0x91, 0x8e, 0xd1, 0x36, 0x11, 0xee, 0xfb, 0x2b, 0x66, 0xba, 0xe4, 0x3e,
  39261. 0xd0, 0xdd, 0x17, 0xc5, 0x24, 0x3b, 0xc3, 0x5b, 0x75, 0xfc, 0xd5, 0xb6,
  39262. 0x8c, 0xba, 0x8c, 0x66, 0xb2, 0xee, 0x40, 0x45, 0x8c, 0x23, 0xbb, 0xe0,
  39263. 0xc8, 0xd6, 0x05, 0xfd, 0x71, 0x5b, 0x24, 0xbb, 0x37, 0x65, 0x5f, 0x57,
  39264. 0x92, 0x22, 0x13, 0xb2, 0x9a, 0x70, 0x22, 0x4b, 0xbe, 0x03, 0xd1, 0x54,
  39265. 0xb0, 0x3a, 0x30, 0x50, 0x71, 0x24, 0xf7, 0x81, 0x8c, 0x20, 0x67, 0x74,
  39266. 0x5a, 0xef, 0xa1, 0x6a, 0xe3, 0xd0, 0x04, 0xd6, 0xa5, 0x6e, 0xad, 0xa7,
  39267. 0x15, 0x41, 0xf3, 0x21, 0xe8, 0xd9, 0xe6, 0xe5, 0x97, 0xbd, 0xc2, 0x1b,
  39268. 0xbb, 0xd1, 0x4e, 0x7e, 0x5a, 0xd6, 0xe4, 0x19, 0xa5, 0xe4, 0x76, 0xf4,
  39269. 0xce, 0x00, 0x94, 0x76, 0xef, 0x1b, 0xb3, 0x47, 0xb9, 0xa3, 0x32, 0xf7,
  39270. 0x45, 0x6d, 0x32, 0x73, 0x06, 0xc0, 0xb9, 0xaf, 0x9c, 0x46, 0x99, 0xbe,
  39271. 0x14, 0x06, 0xcd, 0x35, 0x7c, 0x90, 0x7c, 0xe7, 0x97, 0x0a, 0x9f, 0xb4,
  39272. 0x21, 0xff, 0xf0, 0xea, 0x83, 0xc0, 0x86, 0x68, 0x9f, 0x36, 0xb0, 0xad,
  39273. 0xe1, 0x8d, 0xc5, 0x76, 0x55, 0xb5, 0xb6, 0x7e, 0x1f, 0xa7, 0x5b, 0x26,
  39274. 0x6c, 0xb5, 0xf9, 0x54, 0x1f, 0x76, 0xc1, 0x9c, 0xfc, 0x57, 0xc8, 0x86,
  39275. 0xc1, 0x7d, 0x59, 0x55, 0x92, 0xa5, 0xb8, 0x03, 0xfa, 0xa5, 0x72, 0xd1,
  39276. 0x5c, 0x8d, 0x9b, 0x2e, 0x84, 0x07, 0x18, 0xee, 0x49, 0xc5, 0x99, 0x8e,
  39277. 0x15, 0x7c, 0xbf, 0xad, 0x8b, 0x13, 0xcd, 0x97, 0xf9, 0x3c, 0xa2, 0x89,
  39278. 0x9c, 0x9c, 0x89, 0xc9, 0x7a, 0x46, 0xb3, 0x42, 0x7b, 0xd4, 0x28, 0x0d,
  39279. 0x55, 0x63, 0x28, 0xd6, 0xc1, 0x65, 0xf5, 0x34, 0x6e, 0x38, 0x2a, 0xb4,
  39280. 0x35, 0x40, 0xed, 0x7e, 0x80, 0x61, 0x9d, 0x8f, 0x68, 0x4f, 0x74, 0x0c,
  39281. 0x30, 0x35, 0x0e, 0xb3, 0x07, 0xf4, 0x92, 0xed, 0x9c, 0x7f, 0xf5, 0xed,
  39282. 0x3e, 0x17, 0x5b, 0x6e, 0x91, 0x46, 0xa1, 0x25, 0x1d, 0x83, 0x50, 0x93,
  39283. 0x35, 0x06, 0x6c, 0x2f, 0x99, 0x8b, 0x21, 0x4c, 0x5c, 0x34, 0xb1, 0xa7,
  39284. 0x82, 0xbc, 0x70, 0x28, 0x56, 0x61, 0x29, 0x35, 0x89, 0x0b, 0x41, 0x21,
  39285. 0xf0, 0xf7, 0xff, 0x69, 0x3d, 0xa4, 0x28, 0x1e, 0x0d, 0x5d, 0xa7, 0x0e,
  39286. 0xaa, 0xd3, 0x4a, 0x95, 0x49, 0xfe, 0x35, 0x5f, 0xa9, 0xc0, 0xe4, 0xe1,
  39287. 0x9a, 0x03, 0xd4, 0xac, 0x96, 0xe3, 0xea, 0x7e, 0xa6, 0x85, 0x7e, 0xb0,
  39288. 0xb8, 0xc2, 0xe8, 0x07, 0xd6, 0xd3, 0x1a, 0x84, 0x90, 0x24, 0x04, 0xef,
  39289. 0x7c, 0x93, 0x15, 0x83, 0xea, 0xe2, 0x42, 0xc6, 0xe7, 0x13, 0x45, 0xbf,
  39290. 0x35, 0xae, 0x5d, 0x50, 0x79, 0x16, 0xbb, 0x11, 0x17, 0x1b, 0xf4, 0x08,
  39291. 0x88, 0x9d, 0x66, 0x14, 0x6a, 0xa0, 0x71, 0x76, 0x80, 0x51, 0x73, 0x7c,
  39292. 0x1d, 0xb0, 0xc1, 0xad, 0x58, 0xfb, 0xbe, 0xcf, 0x73, 0xe0, 0xd9, 0xf8,
  39293. 0xd5, 0xac, 0xd7, 0x49, 0xd9, 0xc9, 0x59, 0xbf, 0xfa, 0xf5, 0xb1, 0xd2,
  39294. 0x5a, 0x01, 0xcd, 0x8b, 0x07, 0x8b, 0x59, 0x37, 0xc0, 0x8c, 0x7d, 0xa9,
  39295. 0x71, 0x83, 0xf9, 0x7c, 0x58, 0xa9, 0x77, 0x01, 0x3d, 0x39, 0x56, 0x5c,
  39296. 0x93, 0xfe, 0x40, 0x87, 0x5a, 0x31, 0x81, 0x53, 0x8e, 0x0d, 0x99, 0x7e,
  39297. 0xdf, 0x37, 0xd9, 0xe3, 0x91, 0xb8, 0x60, 0x3a, 0x5b, 0xca, 0xe8, 0x91,
  39298. 0x56, 0x89, 0x59, 0x61, 0xc6, 0x31, 0xe2, 0x6c, 0x81, 0xda, 0xc7, 0x5c,
  39299. 0x04, 0x9d, 0xe4, 0x23, 0x12, 0x73, 0xfc, 0x48, 0xfb, 0xa5, 0xce, 0x87,
  39300. 0x37, 0x47, 0x71, 0x5c, 0xd1, 0x2a, 0x63, 0x89, 0xdc, 0x07, 0xe7, 0x7f,
  39301. 0x5d, 0x48, 0xe6, 0xd2, 0x96, 0xc6, 0x6f, 0xed, 0xee, 0x8c, 0xed, 0x5e,
  39302. 0x41, 0x38, 0xbd, 0xdf, 0x21, 0xaa, 0x9e, 0x51, 0x16, 0x22, 0x4a, 0xdc,
  39303. 0xd8, 0x12, 0xdf, 0x5a, 0x83, 0xd6, 0xd0, 0x07, 0xa4, 0x42, 0x41, 0x13,
  39304. 0xe1, 0x08, 0xc9, 0x00, 0x0f, 0x37, 0xc0, 0x7d, 0xda, 0xb2, 0x25, 0xfc,
  39305. 0xc9, 0xbc, 0xa8, 0x86, 0xcc, 0x38, 0x0e, 0x06, 0x51, 0x1b, 0x37, 0xc1,
  39306. 0x0e, 0x2a, 0x58, 0x49, 0xbc, 0x7c, 0xa7, 0xf0, 0xda, 0xd7, 0x74, 0x34,
  39307. 0xf5, 0xd8, 0x99, 0x8c, 0x94, 0x86, 0xe3, 0x1e, 0x6b, 0xf5, 0x68, 0xfa,
  39308. 0xa6, 0x69, 0x63, 0x22, 0x5a, 0x3c, 0x6f, 0x29, 0xc9, 0x40, 0xc0, 0xbe,
  39309. 0x8d, 0xb5, 0xcc, 0x82, 0x6e, 0x9d, 0xd1, 0x1f, 0x13, 0x63, 0xd8, 0x24,
  39310. 0x63, 0x38, 0x59, 0xf0, 0x4a, 0x8c, 0x0f, 0x28, 0x8a, 0x77, 0x81, 0xa2,
  39311. 0xa0, 0x23, 0x11, 0x59, 0xa9, 0x5a, 0x2d, 0x71, 0x8f, 0x82, 0xa7, 0xbd,
  39312. 0x85, 0x26, 0x4d, 0xc2, 0x2f, 0x11, 0xe8, 0xff, 0x96, 0xa1, 0x2d, 0xf2,
  39313. 0xd5, 0xf3, 0x1d, 0x54, 0xd0, 0x5f, 0x71, 0x07, 0xaf, 0x22, 0xa0, 0xcd,
  39314. 0x78, 0xb3, 0x47, 0xb1, 0x40, 0x3d, 0x6b, 0xfd, 0x10, 0x1b, 0xc6, 0x60,
  39315. 0xef, 0x5c, 0x24, 0xa3, 0x1f, 0xee, 0xc0, 0x0b, 0xed, 0x1d, 0x38, 0xc8,
  39316. 0xf2, 0x8c, 0xec, 0x5e, 0xd9, 0x70, 0x1a, 0x2b, 0x25, 0xe6, 0xed, 0xa9,
  39317. 0x0c, 0xb3, 0x78, 0xe1, 0x91, 0x01, 0x41, 0x2e, 0xfe, 0x7d, 0xbd, 0xfe,
  39318. 0xcf, 0x48, 0x6d, 0x2e, 0x05, 0x31, 0x89, 0x24, 0xc4, 0xd7, 0xc4, 0x26,
  39319. 0x2f, 0x64, 0x43, 0xa3, 0xdd, 0x56, 0x11, 0x5c, 0x65, 0x76, 0x96, 0xcc,
  39320. 0x3c, 0x12, 0x42, 0xf2, 0x6b, 0x20, 0xc2, 0xe6, 0xc3, 0x5c, 0xfa, 0x91,
  39321. 0xb1, 0xbd, 0x3b, 0xd3, 0x99, 0xde, 0x59, 0x7a, 0x34, 0x40, 0x56, 0xb0,
  39322. 0x88, 0x02, 0x19, 0xc8, 0xf9, 0xf9, 0x8f, 0xe7, 0x60, 0xfb, 0x42, 0x87,
  39323. 0x57, 0xb4, 0x42, 0xb4, 0x65, 0x94, 0x0a, 0x5f, 0xdb, 0xf5, 0x32, 0xe9,
  39324. 0x49, 0x28, 0xbe, 0xa6, 0x64, 0x0d, 0x6d, 0x08, 0x43, 0x91, 0x16, 0x7a,
  39325. 0x6c, 0xa9, 0x02, 0xe4, 0x84, 0x03, 0x39, 0x48, 0x08, 0xcc, 0xcb, 0x56,
  39326. 0xad, 0x52, 0x95, 0x9e, 0x9a, 0x2b, 0xf1, 0x6d, 0x3f, 0x4b, 0x02, 0xc6,
  39327. 0x52, 0xc7, 0x09, 0x6b, 0x3f, 0xa9, 0x60, 0xe2, 0x19, 0x5d, 0x0a, 0x61,
  39328. 0xcd, 0xc8, 0x36, 0xdb, 0x8e, 0x57, 0xd2, 0x11, 0x49, 0x1c, 0x26, 0x58,
  39329. 0x04, 0x07, 0x32, 0x2a, 0x34, 0xf0, 0x6a, 0x88, 0xcf, 0x63, 0xb7, 0xef,
  39330. 0x7e, 0x93, 0xcc, 0x64, 0x07, 0x14, 0xfa, 0x63, 0x38, 0xdd, 0xc0, 0xf0,
  39331. 0xaa, 0x56, 0xa1, 0xed, 0x16, 0xaa, 0x53, 0x8c, 0x99, 0xc0, 0xd4, 0xda,
  39332. 0x94, 0x58, 0x13, 0xd9, 0x5f, 0x98, 0x9a, 0xa1, 0x57, 0xbd, 0x89, 0xca,
  39333. 0x9d, 0x3e, 0xdf, 0x75, 0x26, 0x29, 0x0f, 0xb2, 0x33, 0x4b, 0x83, 0xb3,
  39334. 0x99, 0x1f, 0x06, 0x5d, 0x10, 0xf5, 0x1c, 0x75, 0x97, 0xec, 0x5b, 0x87,
  39335. 0xc7, 0xf1, 0xd8, 0xbd, 0x0e, 0x4c, 0x1a, 0xb0, 0x59, 0x3b, 0x27, 0x73,
  39336. 0xdc, 0xde, 0xca, 0x0c, 0x2e, 0x1f, 0x42, 0x7f, 0xd8, 0x0f, 0x9b, 0x3f,
  39337. 0x49, 0x3f, 0x63, 0x7d, 0x71, 0xe3, 0x77, 0x79, 0xcc, 0x9c, 0xbf, 0xff,
  39338. 0x23, 0xa9, 0x74, 0xa2, 0xda, 0xb7, 0xca, 0x86, 0x7f, 0x12, 0xc1, 0x1b,
  39339. 0x41, 0x35, 0xb5, 0xc7, 0x10, 0x09, 0xc0, 0xa2, 0x1b, 0x41, 0x31, 0x5e,
  39340. 0x6c, 0x35, 0xb5, 0x63, 0x13, 0x19, 0x61, 0x8e, 0xbd, 0x89, 0xf6, 0x0a,
  39341. 0xbd, 0x16, 0x15, 0xd8, 0xfa, 0xcc, 0x9f, 0x97, 0x02, 0x8f, 0x1b, 0x34,
  39342. 0x40, 0xbc, 0x4a, 0xb1, 0x39, 0x12, 0xf8, 0x66, 0xda, 0x34, 0x03, 0xf2,
  39343. 0x5c, 0x33, 0x9c, 0x63, 0x0b, 0xb6, 0x8f, 0xca, 0x81, 0xa2, 0x4a, 0x43,
  39344. 0xe7, 0xe7, 0x66, 0x41, 0x45, 0x6b, 0x7c, 0xd1, 0x1d, 0xbc, 0x4f, 0x91,
  39345. 0xab, 0x24, 0x0b, 0x9f, 0x60, 0x47, 0x36, 0x04, 0x8b, 0x72, 0xb6, 0x65,
  39346. 0x35, 0xfc, 0xbf, 0xc9, 0x26, 0xaf, 0x84, 0x04, 0x30, 0x32, 0x02, 0xc0,
  39347. 0x94, 0x98, 0xbc, 0x17, 0x33, 0x99, 0xac, 0xb1, 0x4e, 0xdd, 0xf0, 0x46,
  39348. 0x68, 0x6a, 0xac, 0x6d, 0xdb, 0x85, 0xfd, 0xc6, 0x3b, 0xc8, 0x93, 0x89,
  39349. 0xbf, 0xd7, 0xd9, 0x94, 0xe4, 0xa4, 0x37, 0xb9, 0x67, 0x52, 0x84, 0xcf,
  39350. 0x88, 0xba, 0x01, 0x8b, 0xe4, 0xd4, 0x3e, 0xde, 0x94, 0xa1, 0xa9, 0xd8,
  39351. 0x15, 0xb5, 0x6e, 0xa0, 0x62, 0x92, 0x5c, 0xb1, 0x1b, 0xbf, 0x4f, 0xaf,
  39352. 0xf5, 0x99, 0x35, 0xce, 0x7d, 0xa9, 0x4b, 0xa8, 0x60, 0x31, 0xf5, 0x0a,
  39353. 0x83, 0x58, 0xf5, 0x83, 0xde, 0xb2, 0xfe, 0xf3, 0x12, 0x08, 0x3d, 0xe3,
  39354. 0x14, 0x89, 0x17, 0x93, 0x5c, 0x87, 0xe4, 0x89, 0xcb, 0xb7, 0x67, 0x3e,
  39355. 0xea, 0x0e, 0x08, 0x57, 0xf1, 0xca, 0xe0, 0x18, 0xd7, 0xae, 0x5f, 0x9e,
  39356. 0x62, 0x5c, 0xd7, 0x6a, 0x2f, 0xd6, 0x30, 0x67, 0xfb, 0x5e, 0xed, 0xcf,
  39357. 0xa9, 0x88, 0x04, 0x0a, 0xf2, 0x62, 0x50, 0xc5, 0x39, 0xc6, 0xa1, 0x3c,
  39358. 0xe4, 0x9a, 0x81, 0x55, 0x96, 0xca, 0x60, 0xb2, 0x53, 0x62, 0xee, 0xa1,
  39359. 0x1d, 0xfc, 0xd9, 0x5c, 0x51, 0xbf, 0x55, 0x65, 0x1d, 0x13, 0x2a, 0x13,
  39360. 0x58, 0xa3, 0x18, 0x52, 0x6b, 0xb4, 0xae, 0x60, 0x1c, 0x26, 0x3e, 0xb1,
  39361. 0x4c, 0xb1, 0x72, 0x1b, 0x8a, 0x4c, 0xaa, 0xb5, 0x5b, 0x8a, 0x3b, 0x2f,
  39362. 0x1f, 0xc3, 0x29, 0x41, 0xe6, 0x6d, 0xd7, 0x96, 0x26, 0xdd, 0x37, 0x67,
  39363. 0x4f, 0x9d, 0x31, 0xc6, 0x54, 0x51, 0xaa, 0xba, 0x73, 0xae, 0xd2, 0x00,
  39364. 0x0b, 0x05, 0x98, 0x73, 0xd6, 0x9c, 0xb4, 0x2e, 0x23, 0xd0, 0xc3, 0xac,
  39365. 0x46, 0x6f, 0x3e, 0x05, 0x43, 0xf8, 0x96, 0xa0, 0xe0, 0xfe, 0x17, 0x3f,
  39366. 0xfa, 0xc2, 0xc3, 0xf6, 0x1a, 0x46, 0xd0, 0x05, 0x53, 0x0e, 0xea, 0xd8,
  39367. 0xba, 0xa3, 0xab, 0xb6, 0x58, 0xd1, 0x40, 0x1c, 0x97, 0x38, 0xd4, 0x77,
  39368. 0x58, 0x03, 0xf5, 0x8a, 0xc7, 0x48, 0x19, 0x71, 0x71, 0xb5, 0x4b, 0x08,
  39369. 0x85, 0x35, 0x1c, 0xdf, 0xbd, 0xa9, 0xc9, 0xd1, 0x40, 0x62, 0xa3, 0xd6,
  39370. 0x3b, 0xa1, 0xf7, 0x4e, 0xc6, 0xfe, 0xc4, 0x07, 0x2f, 0xf5, 0xc9, 0x0c,
  39371. 0xb6, 0xa0, 0xb3, 0x25, 0x3e, 0x2a, 0x07, 0xe3, 0x63, 0xe3, 0x9e, 0x8d,
  39372. 0x0d, 0x7a, 0x70, 0x1e, 0x65, 0x95, 0x47, 0x37, 0xa8, 0xd2, 0x35, 0x09,
  39373. 0x09, 0x70, 0xf5, 0xc9, 0xc9, 0x30, 0x95, 0xd9, 0xf2, 0x5d, 0x10, 0x3c,
  39374. 0xc3, 0x66, 0x66, 0xb6, 0xdc, 0x14, 0xf6, 0x91, 0xc2, 0x7b, 0x4b, 0x71,
  39375. 0x42, 0xf9, 0x35, 0xe7, 0x08, 0x1e, 0xb6, 0x9a, 0x5c, 0x0e, 0x8b, 0x41,
  39376. 0x44, 0x7f, 0xad, 0xca, 0x8a, 0x4b, 0x6a, 0x02, 0x81, 0x96, 0xe7, 0xe1,
  39377. 0xb0, 0x5b, 0xaf, 0xf2, 0x17, 0x44, 0x7f, 0xd1, 0x49, 0x77, 0xfd, 0x07,
  39378. 0x59, 0x53, 0x8e, 0x51, 0xac, 0x0f, 0x0c, 0xb4, 0xa3, 0xf6, 0x24, 0x16,
  39379. 0x47, 0xf3, 0xa4, 0x36, 0x17, 0x3e, 0x01, 0x1e, 0xf1, 0xec, 0x78, 0x4a,
  39380. 0xcb, 0xbd, 0x2a, 0xfd, 0x01, 0xdd, 0xa5, 0xad, 0x7b, 0xef, 0x5e, 0x56,
  39381. 0xb2, 0x60, 0xb4, 0xf2, 0x27, 0xc8, 0x9b, 0x5b, 0x31, 0x49, 0x54, 0xbc,
  39382. 0x69, 0x9b, 0xc6, 0x1a, 0x79, 0xe7, 0xd4, 0x46, 0xc8, 0x50, 0xc3, 0xaa,
  39383. 0xfc, 0xb5, 0x28, 0x87, 0x1e, 0xa0, 0x0c, 0xc6, 0x1a, 0xa7, 0x34, 0xd6,
  39384. 0xbb, 0x9d, 0x9c, 0x0d, 0x90, 0x6f, 0x1a, 0x3c, 0xdc, 0x3b, 0x95, 0xc4,
  39385. 0x38, 0x25, 0x7a, 0xc6, 0x46, 0x82, 0x9f, 0x68, 0xca, 0x6a, 0x63, 0xa7,
  39386. 0x99, 0xfe, 0x64, 0xe6, 0x6f, 0x11, 0xcd, 0x2c, 0x76, 0x1e, 0xe6, 0x08,
  39387. 0xb8, 0x33, 0x64, 0x43, 0x51, 0xbd, 0x52, 0xf7, 0x05, 0x06, 0xd5, 0xcc,
  39388. 0x6a, 0xde, 0x1a, 0xa2, 0xbe, 0xf8, 0x8c, 0x44, 0x5e, 0x2d, 0xc2, 0x28,
  39389. 0xcd, 0x9a, 0x53, 0x04, 0x96, 0xcc, 0x1e, 0xbb, 0x96, 0x07, 0xc9, 0x17,
  39390. 0x04, 0xf8, 0xd8, 0xd9, 0xdd, 0x35, 0x35, 0x3d, 0x53, 0x30, 0x60, 0xb3,
  39391. 0x87, 0x5d, 0xf3, 0xe5, 0xa7, 0x20, 0x30, 0x9d, 0xb0, 0x5b, 0xc4, 0x36,
  39392. 0xf7, 0xd7, 0xb6, 0x3e, 0x44, 0x98, 0x99, 0xe7, 0xc3, 0x29, 0xcb, 0x70,
  39393. 0xc4, 0x91, 0x8b, 0xfc, 0x63, 0x60, 0x29, 0x95, 0xeb, 0x61, 0x7f, 0xdf,
  39394. 0xf7, 0x3a, 0x69, 0x3a, 0xeb, 0xa1, 0x73, 0x1d, 0x13, 0x18, 0x29, 0x2c,
  39395. 0x89, 0x82, 0x56, 0x42, 0xe7, 0xa3, 0xba, 0xe9, 0x59, 0x2e, 0xfd, 0xff,
  39396. 0xb6, 0xf7, 0xbd, 0x2a, 0xc9, 0xff, 0x4c, 0x63, 0xef, 0x54, 0x63, 0x82,
  39397. 0x7c, 0xa5, 0x11, 0x44, 0xc7, 0x68, 0xf5, 0x7b, 0x44, 0x2c, 0xee, 0xab,
  39398. 0xa3, 0x84, 0x5a, 0x99, 0x28, 0x98, 0x97, 0x2e, 0x8b, 0x07, 0x09, 0x6c,
  39399. 0xea, 0xc1, 0x81, 0x0b, 0xe0, 0xc4, 0xb7, 0xc2, 0x73, 0xbe, 0x8b, 0x72,
  39400. 0xf8, 0xc9, 0x8d, 0x50, 0x28, 0xf2, 0x95, 0x54, 0x8a, 0x3b, 0x23, 0x86,
  39401. 0xc4, 0xe8, 0xe8, 0xe5, 0x45, 0x0d, 0xdf, 0xa3, 0xe6, 0x00, 0x71, 0xe8,
  39402. 0x20, 0xd2, 0x6d, 0x22, 0x23, 0xaf, 0x37, 0x04, 0x55, 0x05, 0x8d, 0xc9,
  39403. 0x38, 0x38, 0x12, 0x4c, 0x9f, 0x28, 0x56, 0x14, 0x76, 0xe5, 0x10, 0x54,
  39404. 0xd9, 0x68, 0xca, 0xc3, 0x97, 0x9f, 0xd2, 0x25, 0x2c, 0x0d, 0xa0, 0xff,
  39405. 0xea, 0xab, 0x61, 0xd2, 0xb2, 0x06, 0xc2, 0x93, 0xfd, 0x5a, 0xfe, 0xe3,
  39406. 0x98, 0xbf, 0x37, 0x2e, 0xa5, 0x74, 0x56, 0xd0, 0x7a, 0x5a, 0x23, 0x3b,
  39407. 0xd2, 0xa0, 0x1f, 0x4b, 0xeb, 0x7f, 0x5a, 0xc5, 0x51, 0x79, 0xf6, 0x95,
  39408. 0x19, 0x50, 0xb1, 0x6a, 0x80, 0xcb, 0xcf, 0x19, 0xa4, 0x67, 0xf4, 0x08,
  39409. 0x0f, 0x6a, 0xd9, 0x3f, 0x15, 0x96, 0x2c, 0x6d, 0xd5, 0x69, 0x7a, 0x56,
  39410. 0x4d, 0x17, 0xc8, 0xcb, 0xba, 0x9b, 0x6e, 0x65, 0xa2, 0x3d, 0x66, 0xed,
  39411. 0xea, 0xe2, 0x54, 0x88, 0x6c, 0xc1, 0x1a, 0x11, 0xde, 0x4e, 0x0c, 0x8a,
  39412. 0x42, 0x04, 0xe1, 0x77, 0xc3, 0x0c, 0xff, 0x10, 0x7d, 0x4a, 0x45, 0x3f,
  39413. 0xb8, 0x40, 0xf9, 0x75, 0x76, 0x9f, 0x65, 0x42, 0x2f, 0x78, 0x5b, 0x0b,
  39414. 0x32, 0xbc, 0x45, 0xfc, 0xd4, 0x29, 0x49, 0x34, 0x76, 0xda, 0x5f, 0xe8,
  39415. 0x39, 0x35, 0x9e, 0xba, 0x7f, 0x19, 0x7e, 0x14, 0xe6, 0x71, 0x9c, 0x72,
  39416. 0x6a, 0xce, 0xcc, 0xa6, 0x72, 0x73, 0x3f, 0x4e, 0x9b, 0x9e, 0x94, 0x0c,
  39417. 0xce, 0x00, 0x15, 0xb4, 0x50, 0xff, 0xcf, 0xcd, 0x78, 0xd3, 0x08, 0x0e,
  39418. 0x95, 0x48, 0x24, 0x13, 0x16, 0x54, 0xb4, 0xe0, 0xa9, 0x29, 0xa3, 0x05,
  39419. 0x77, 0x2f, 0x5d, 0x47, 0x6a, 0xa5, 0xb0, 0x4e, 0xf3, 0xa9, 0x4a, 0x82,
  39420. 0xb9, 0x2c, 0x26, 0x07, 0x9c, 0x33, 0xc6, 0x68, 0xc2, 0xe0, 0xc0, 0x7d,
  39421. 0x70, 0x48, 0x74, 0xb9, 0xf5, 0x1e, 0x6c, 0x15, 0x7f, 0xba, 0xe5, 0xa1,
  39422. 0xb4, 0x36, 0x41, 0x20, 0xf4, 0x2d, 0x97, 0x27, 0x0b, 0x10, 0x30, 0x57,
  39423. 0x7f, 0x38, 0x66, 0xe1, 0xc4, 0xf6, 0xa4, 0xc9, 0x8d, 0xbc, 0x2b, 0x4f,
  39424. 0x14, 0xb3, 0xf0, 0x1e, 0x80, 0x70, 0xc0, 0x0f, 0x69, 0x06, 0xe7, 0x95,
  39425. 0xd1, 0x53, 0x65, 0x49, 0x1c, 0xa8, 0xfa, 0x9e, 0x2b, 0xcc, 0x33, 0x71,
  39426. 0x76, 0xa4, 0x0b, 0x4a, 0xc7, 0xea, 0xa0, 0xfa, 0x1b, 0x2b, 0xfb, 0xa5,
  39427. 0x59, 0x06, 0x2a, 0xef, 0x4b, 0xbf, 0x05, 0x4b, 0x87, 0x70, 0x3c, 0xde,
  39428. 0xc7, 0xb2, 0x4f, 0xf2, 0x5b, 0x1a, 0xbe, 0xda, 0x04, 0x31, 0x57, 0xff,
  39429. 0xf2, 0xa5, 0x43, 0x12, 0xff, 0x8d, 0xf4, 0x99, 0x05, 0xe1, 0x34, 0xa9,
  39430. 0xb9, 0x0a, 0xb3, 0x1f, 0x3d, 0x6d, 0x0d, 0xb7, 0xd3, 0x35, 0x0b, 0x04,
  39431. 0x44, 0x77, 0x60, 0xc0, 0x96, 0x99, 0x7b, 0xa8, 0x8e, 0x79, 0x4a, 0x96,
  39432. 0x24, 0xef, 0xb1, 0xf4, 0x8a, 0x2f, 0x3e, 0x08, 0xf3, 0x3d, 0xf2, 0xfe,
  39433. 0x5f, 0x0a, 0xf7, 0x0a, 0xf5, 0xd8, 0xf2, 0xa0, 0x1b, 0xe7, 0x9e, 0xc9,
  39434. 0x0b, 0xcf, 0x58, 0x97, 0x92, 0x90, 0xad, 0x3d, 0xfc, 0x42, 0xc1, 0x7f,
  39435. 0x39, 0xe8, 0xd1, 0x35, 0x14, 0x8a, 0xb3, 0x77, 0xb1, 0xa9, 0xdb, 0xb4,
  39436. 0x3a, 0x3d, 0xeb, 0x59, 0x0b, 0x5b, 0x3a, 0x63, 0x54, 0x70, 0xda, 0xf0,
  39437. 0xf0, 0xb9, 0xe6, 0x07, 0x69, 0x27, 0x9d, 0xc6, 0xb6, 0x00, 0x2d, 0xd6,
  39438. 0xc7, 0xd7, 0x2e, 0xf8, 0x9c, 0xfe, 0x4c, 0xfb, 0xc0, 0x7b, 0xbf, 0xa2,
  39439. 0x25, 0xb8, 0x2a, 0x5c, 0x06, 0xca, 0x12, 0x2c, 0x96, 0xa4, 0x27, 0xa6,
  39440. 0x73, 0x0b, 0xb8, 0x42, 0x93, 0x51, 0x87, 0xfe, 0xe6, 0x8f, 0xca, 0x00,
  39441. 0x53, 0xdc, 0xc0, 0x38, 0x03, 0x9e, 0x66, 0x13, 0x84, 0x68, 0xe7, 0x04,
  39442. 0x93, 0x79, 0x0c, 0x3e, 0x4c, 0x90, 0xe2, 0xf7, 0x81, 0x15, 0x49, 0x05,
  39443. 0xe1, 0x8f, 0xe6, 0xfc, 0xc8, 0x40, 0xae, 0x3d, 0x7a, 0x16, 0xec, 0xc6,
  39444. 0x39, 0xa5, 0x04, 0x95, 0x35, 0xac, 0xdd, 0x0d, 0x19, 0xd6, 0xa9, 0xd9,
  39445. 0xd2, 0x53, 0x71, 0x31, 0x38, 0xa2, 0xf1, 0x9c, 0x13, 0x2c, 0x8c, 0x21,
  39446. 0x9c, 0x3a, 0x1b, 0xf2, 0xd8, 0x4c, 0xeb, 0xe9, 0x8b, 0x27, 0x52, 0xd3,
  39447. 0x6c, 0x01, 0xc0, 0x60, 0x32, 0x8c, 0x6e, 0xfb, 0xd6, 0xd6, 0x1b, 0xc6,
  39448. 0x93, 0xff, 0xdc, 0xdb, 0x38, 0xf5, 0x0e, 0xd5, 0x15, 0xcd, 0x65, 0x76,
  39449. 0x78, 0x42, 0x13, 0x37, 0x6b, 0x2e, 0xe8, 0xe2, 0x54, 0x4d, 0x45, 0x34,
  39450. 0x73, 0x1b, 0x61, 0x35, 0x2c, 0xf7, 0x20, 0x3e, 0xe9, 0x7c, 0xf0, 0xf3,
  39451. 0xba, 0x41, 0xfc, 0x49, 0xe4, 0x5d, 0xd4, 0xb8, 0x07, 0x15, 0x7b, 0x16,
  39452. 0xc7, 0x7f, 0x78, 0xef, 0xd6, 0x53, 0x3f, 0xe4, 0xa6, 0x33, 0xcf, 0xcc,
  39453. 0x78, 0x53, 0x0c, 0x59, 0xf7, 0x28, 0xa5, 0x83, 0x2b, 0x5a, 0xd3, 0xd6,
  39454. 0xb7, 0xb2, 0xd1, 0x73, 0x63, 0xa9, 0xad, 0x16, 0xf2, 0xed, 0x48, 0x6e,
  39455. 0x88, 0x22, 0xbd, 0x16, 0x9d, 0x6a, 0xc2, 0x48, 0x83, 0xdf, 0x40, 0xb7,
  39456. 0x0a, 0x50, 0x23, 0x3d, 0x58, 0x50, 0x00, 0x02, 0x04, 0xd2, 0x31, 0x72,
  39457. 0x28, 0x7b, 0x10, 0x96, 0xe0, 0xe7, 0x3f, 0xe0, 0xd0, 0x61, 0x70, 0x5c,
  39458. 0x0a, 0xdb, 0xc0, 0x7b, 0xea, 0xef, 0xba, 0xc0, 0x90, 0xe0, 0xf9, 0x0e,
  39459. 0x83, 0x8c, 0x3b, 0x05, 0x2b, 0xb6, 0xcb, 0xbb, 0x37, 0xa1, 0xd3, 0x28,
  39460. 0x02, 0x40, 0xe3, 0x76, 0xbf, 0x27, 0x0b, 0x4f, 0x82, 0xb9, 0x22, 0xee,
  39461. 0x0b, 0x3a, 0xcb, 0xcc, 0x56, 0x13, 0x51, 0xb8, 0xb6, 0x2d, 0xd3, 0x6c,
  39462. 0x96, 0x10, 0xd9, 0x51, 0x24, 0x7b, 0x2b, 0xb8, 0x7b, 0xbd, 0x8d, 0xd9,
  39463. 0xf2, 0x50, 0x61, 0xbb, 0x0c, 0xb7, 0x71, 0x65, 0x3a, 0x25, 0x18, 0x09,
  39464. 0x1a, 0x9d, 0x41, 0xf4, 0xdb, 0x5a, 0x1c, 0x61, 0x0a, 0xbb, 0x43, 0x27,
  39465. 0x8a, 0xa8, 0x83, 0x60, 0x8c, 0x5d, 0x4c, 0x9b, 0xa9, 0xe5, 0xa7, 0x67,
  39466. 0x99, 0x98, 0xdc, 0x7a, 0x3a, 0x55, 0x0d, 0x25, 0x69, 0x47, 0x21, 0xb1,
  39467. 0xd7, 0x0c, 0x0c, 0x43, 0x58, 0xc9, 0xbf, 0x74, 0x91, 0x1b, 0x2b, 0xf3,
  39468. 0x29, 0x8d, 0x10, 0x41, 0xaf, 0xdd, 0x42, 0x0a, 0x71, 0xe3, 0xb8, 0x4d,
  39469. 0x3a, 0xf3, 0x9c, 0x5a, 0x46, 0x4e, 0x70, 0xbe, 0xdb, 0x0d, 0x03, 0xee,
  39470. 0xcb, 0xfb, 0x61, 0x45, 0xbd, 0x25, 0xb4, 0x72, 0xd1, 0x51, 0x03, 0x19,
  39471. 0x82, 0x53, 0x83, 0x18, 0xab, 0xa3, 0x6c, 0x9e, 0xa2, 0xe9, 0x15, 0xb1,
  39472. 0x74, 0x61, 0xa1, 0xaf, 0x09, 0x4b, 0x4a, 0x34, 0x9b, 0xd0, 0xd2, 0x80,
  39473. 0x43, 0xd9, 0x90, 0x53, 0x71, 0x38, 0xb9, 0x80, 0x58, 0x1b, 0x9f, 0x9e,
  39474. 0xfe, 0x07, 0x1b, 0x33, 0x24, 0xb2, 0x58, 0x7f, 0x01, 0xbe, 0xe8, 0x25,
  39475. 0x53, 0x08, 0x06, 0x77, 0x7d, 0x5a, 0x16, 0x83, 0x67, 0x91, 0x0b, 0xa2,
  39476. 0xd2, 0x1e, 0x5f, 0x9c, 0x39, 0xda, 0x57, 0xbc, 0x67, 0xc5, 0x39, 0xbe,
  39477. 0xb9, 0x73, 0x03, 0x19, 0x97, 0x34, 0x4f, 0x1e, 0x6b, 0x4d, 0x87, 0xef,
  39478. 0x79, 0x4f, 0xd1, 0xdd, 0x80, 0x13, 0xbe, 0x3b, 0x0f, 0xea, 0x77, 0x9a,
  39479. 0x1a, 0x46, 0x63, 0xc5, 0x2f, 0x93, 0xfe, 0x18, 0x71, 0xfb, 0x70, 0xbf,
  39480. 0x85, 0x3b, 0x3e, 0x54, 0xe6, 0xf8, 0xe0, 0xb9, 0xd0, 0x9d, 0xf5, 0x2b,
  39481. 0x12, 0x22, 0x39, 0x6a, 0x8d, 0x13, 0xa1, 0x3a, 0x95, 0xd0, 0xe7, 0x07,
  39482. 0xa4, 0x2c, 0x33, 0xba, 0x43, 0x1d, 0xd8, 0xb5, 0xd0, 0x8e, 0x6c, 0x85,
  39483. 0x6f, 0xf8, 0x8f, 0xd3, 0x72, 0x65, 0xc1, 0xff, 0x8f, 0xf6, 0xb5, 0x19,
  39484. 0x59, 0x34, 0xf9, 0xe8, 0xdb, 0xf3, 0x10, 0x68, 0xbd, 0xd5, 0x59, 0xf7,
  39485. 0xe5, 0xf2, 0x84, 0x98, 0x8d, 0xd6, 0x6f, 0xcc, 0xde, 0xc5, 0xee, 0xf7,
  39486. 0x16, 0xca, 0xec, 0xc4, 0x00, 0x89, 0x2e, 0x0d, 0x0d, 0xb6, 0xa8, 0xe0,
  39487. 0x9a, 0xb0, 0xe5, 0x8e, 0xb6, 0x64, 0x47, 0x7d, 0x01, 0x59, 0x8a, 0x90,
  39488. 0xa6, 0x9b, 0x2b, 0x63, 0xad, 0x70, 0xc8, 0x07, 0x36, 0x3e, 0xa9, 0x8f,
  39489. 0xd9, 0xc2, 0xf7, 0x4b, 0xec, 0x95, 0x53, 0xec, 0x6b, 0x2d, 0x1f, 0xb5,
  39490. 0x91, 0xbf, 0x9f, 0xc5, 0x85, 0x61, 0x3a, 0xc7, 0x5c, 0x15, 0x2a, 0x0b,
  39491. 0x4b, 0x3c, 0x38, 0x6d, 0xc9, 0x2c, 0x91, 0x11, 0xc6, 0x6b, 0x44, 0x71,
  39492. 0x9f, 0x89, 0xd5, 0xde, 0x27, 0x99, 0x81, 0xa2, 0x59, 0x8b, 0x57, 0x97,
  39493. 0x83, 0x46, 0x33, 0xe1, 0x8c, 0xdf, 0xcf, 0x5b, 0x6b, 0xb3, 0x0e, 0x17,
  39494. 0x1a, 0xb8, 0x7d, 0x6e, 0x71, 0xe5, 0xc8, 0x4c, 0xa9, 0xe2, 0x52, 0x81,
  39495. 0xf6, 0x2f, 0x3a, 0xef, 0x5a, 0x1b, 0x6b, 0x7b, 0x61, 0x51, 0xcb, 0xd5,
  39496. 0x7b, 0x5f, 0xf0, 0x1c, 0xb8, 0xeb, 0x9a, 0xe4, 0x0a, 0x6e, 0x53, 0x59,
  39497. 0x2e, 0x2d, 0x78, 0x27, 0xb7, 0x47, 0x35, 0x1a, 0x01, 0x25, 0x0a, 0xcc,
  39498. 0x67, 0xae, 0xda, 0xaf, 0xfe, 0x22, 0x63, 0xe8, 0xa2, 0x1c, 0x34, 0xe6,
  39499. 0x6b, 0x73, 0xcf, 0x6f, 0x3e, 0x0a, 0x4a, 0x36, 0xbc, 0xda, 0x43, 0xbc,
  39500. 0x5e, 0x9c, 0x91, 0xe4, 0x8b, 0x34, 0x2e, 0x09, 0x87, 0x69, 0x96, 0x93,
  39501. 0xb4, 0xff, 0x97, 0xbc, 0x4e, 0xd6, 0xa2, 0xb4, 0x16, 0x78, 0x7c, 0x62,
  39502. 0xd0, 0x78, 0x3f, 0x37, 0xdb, 0xf2, 0x92, 0xad, 0x9b, 0x51, 0x77, 0x08,
  39503. 0x19, 0xd2, 0x09, 0x12, 0xf7, 0x52, 0xe8, 0xc8, 0xb2, 0xfb, 0x6f, 0xcd,
  39504. 0x05, 0x5b, 0xd2, 0x8e, 0x0d, 0x6e, 0x0c, 0x16, 0x5b, 0x8a, 0xc2, 0x09,
  39505. 0x13, 0x3b, 0x69, 0x85, 0xbd, 0xc0, 0xcc, 0x2b, 0x48, 0x65, 0xa7, 0xc1,
  39506. 0xc3, 0xe0, 0xea, 0x14, 0x67, 0x6f, 0xa4, 0xb8, 0xc6, 0xf0, 0x12, 0x3e,
  39507. 0x96, 0x0d, 0x23, 0x2b, 0x37, 0x87, 0x8d, 0xc8, 0xf7, 0x00, 0x00, 0x00,
  39508. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39509. 0x00, 0x00, 0x00, 0x03, 0x0b, 0x13, 0x1a, 0x1d, 0x25
  39510. };
  39511. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39512. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_sig[] = {
  39513. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  39514. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  39515. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  39516. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  39517. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  39518. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  39519. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  39520. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  39521. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  39522. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  39523. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  39524. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  39525. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  39526. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  39527. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  39528. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  39529. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  39530. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  39531. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  39532. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  39533. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  39534. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  39535. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  39536. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  39537. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  39538. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  39539. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  39540. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  39541. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  39542. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  39543. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  39544. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  39545. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  39546. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  39547. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  39548. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  39549. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  39550. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  39551. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  39552. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  39553. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  39554. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  39555. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  39556. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  39557. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  39558. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  39559. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  39560. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  39561. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  39562. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  39563. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  39564. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  39565. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  39566. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  39567. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  39568. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  39569. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  39570. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  39571. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  39572. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  39573. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  39574. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  39575. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  39576. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  39577. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  39578. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  39579. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  39580. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  39581. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  39582. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  39583. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  39584. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  39585. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  39586. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  39587. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  39588. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  39589. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  39590. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  39591. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  39592. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  39593. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  39594. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  39595. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  39596. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  39597. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  39598. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  39599. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  39600. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  39601. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  39602. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  39603. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  39604. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  39605. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  39606. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  39607. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  39608. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  39609. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  39610. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  39611. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  39612. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  39613. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  39614. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  39615. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  39616. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  39617. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  39618. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  39619. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  39620. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  39621. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  39622. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  39623. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  39624. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  39625. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  39626. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  39627. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  39628. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  39629. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  39630. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  39631. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  39632. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  39633. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  39634. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  39635. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  39636. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  39637. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  39638. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  39639. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  39640. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  39641. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  39642. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  39643. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  39644. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  39645. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  39646. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  39647. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  39648. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  39649. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  39650. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  39651. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  39652. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  39653. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  39654. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  39655. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  39656. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  39657. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  39658. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  39659. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  39660. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  39661. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  39662. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  39663. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  39664. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  39665. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  39666. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  39667. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  39668. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  39669. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  39670. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  39671. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  39672. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  39673. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  39674. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  39675. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  39676. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  39677. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  39678. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  39679. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  39680. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  39681. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  39682. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  39683. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  39684. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  39685. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  39686. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  39687. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  39688. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  39689. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  39690. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  39691. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  39692. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  39693. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  39694. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  39695. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  39696. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  39697. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  39698. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  39699. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  39700. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  39701. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  39702. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  39703. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  39704. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  39705. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  39706. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  39707. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  39708. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  39709. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  39710. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  39711. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  39712. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  39713. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  39714. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  39715. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  39716. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  39717. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  39718. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  39719. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  39720. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  39721. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  39722. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  39723. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  39724. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  39725. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  39726. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  39727. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  39728. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  39729. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  39730. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  39731. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  39732. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  39733. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  39734. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  39735. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  39736. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  39737. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  39738. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  39739. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  39740. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  39741. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  39742. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  39743. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  39744. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  39745. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  39746. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  39747. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  39748. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  39749. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  39750. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  39751. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  39752. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  39753. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  39754. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  39755. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  39756. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  39757. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  39758. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  39759. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  39760. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  39761. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  39762. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  39763. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  39764. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  39765. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  39766. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  39767. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  39768. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  39769. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  39770. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  39771. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  39772. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  39773. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  39774. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  39775. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  39776. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  39777. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  39778. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  39779. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  39780. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  39781. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  39782. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  39783. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  39784. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  39785. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  39786. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  39787. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  39788. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  39789. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  39790. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  39791. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  39792. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  39793. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  39794. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  39795. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  39796. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  39797. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  39798. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  39799. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  39800. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  39801. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  39802. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  39803. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  39804. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  39805. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  39806. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  39807. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  39808. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  39809. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  39810. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  39811. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  39812. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  39813. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  39814. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  39815. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  39816. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  39817. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  39818. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  39819. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  39820. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  39821. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  39822. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  39823. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  39824. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  39825. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  39826. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  39827. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  39828. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  39829. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  39830. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  39831. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  39832. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  39833. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  39834. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  39835. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  39836. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  39837. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  39838. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  39839. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  39840. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  39841. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  39842. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39843. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28
  39844. };
  39845. #endif
  39846. wc_test_ret_t ret;
  39847. ret = dilithium_param_vfy_test(WC_ML_DSA_65, ml_dsa_65_pub_key,
  39848. (word32)sizeof(ml_dsa_65_pub_key), ml_dsa_65_sig,
  39849. (word32)sizeof(ml_dsa_65_sig));
  39850. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39851. if (ret == 0) {
  39852. ret = dilithium_param_vfy_test(WC_ML_DSA_65_DRAFT,
  39853. ml_dsa_65_draft_pub_key, (word32)sizeof(ml_dsa_65_draft_pub_key),
  39854. ml_dsa_65_draft_sig, (word32)sizeof(ml_dsa_65_draft_sig));
  39855. }
  39856. #endif
  39857. return ret;
  39858. }
  39859. #endif
  39860. #ifndef WOLFSSL_NO_ML_DSA_87
  39861. static wc_test_ret_t dilithium_param_87_vfy_test(void)
  39862. {
  39863. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_pub_key[] = {
  39864. 0x8a, 0x66, 0xe3, 0x6e, 0x3c, 0x11, 0x70, 0x9f, 0x82, 0xdd, 0xeb, 0x9e,
  39865. 0xc0, 0xd7, 0x25, 0x87, 0x0c, 0x65, 0x07, 0x9d, 0x47, 0x39, 0x5d, 0x04,
  39866. 0x42, 0x5c, 0xd6, 0x0a, 0xdc, 0x39, 0x44, 0x04, 0xd9, 0x79, 0x43, 0x87,
  39867. 0x98, 0x64, 0x88, 0x82, 0x3a, 0x31, 0xbd, 0xec, 0x66, 0xcb, 0x01, 0x90,
  39868. 0xf9, 0x85, 0xcc, 0xde, 0x54, 0x69, 0x7d, 0x84, 0xb3, 0x84, 0x3c, 0x42,
  39869. 0x0d, 0x09, 0x63, 0xdb, 0xe6, 0x5d, 0xc2, 0x8a, 0xcf, 0xe1, 0xf4, 0x86,
  39870. 0x13, 0x05, 0x09, 0x9a, 0x4d, 0x05, 0xd4, 0x31, 0xe7, 0x27, 0x39, 0xfd,
  39871. 0x3a, 0xdb, 0x63, 0x9f, 0x1c, 0x67, 0x0b, 0x01, 0xec, 0xf9, 0xff, 0xf3,
  39872. 0xda, 0xa9, 0xf4, 0x9a, 0x59, 0x52, 0x76, 0xc2, 0xd2, 0xd5, 0xdd, 0x8d,
  39873. 0xb1, 0xa2, 0xef, 0xb3, 0x73, 0x99, 0xe3, 0xcd, 0x1c, 0xf5, 0xca, 0x6e,
  39874. 0x39, 0xfa, 0x26, 0x83, 0x45, 0xe7, 0xd0, 0x9c, 0x1b, 0xf7, 0xb2, 0x64,
  39875. 0xf1, 0x70, 0x00, 0x10, 0xc0, 0x7c, 0x7f, 0xb2, 0x32, 0xce, 0x6d, 0x71,
  39876. 0xa5, 0x43, 0x7c, 0x40, 0x71, 0x09, 0x54, 0x74, 0xac, 0xb5, 0xeb, 0xe0,
  39877. 0x04, 0x02, 0xe5, 0x82, 0x4d, 0x5a, 0x85, 0x1e, 0x19, 0x86, 0x39, 0x33,
  39878. 0x92, 0x2f, 0xa9, 0xa8, 0x10, 0xd2, 0x31, 0x60, 0x16, 0x08, 0x99, 0xe3,
  39879. 0x2c, 0x93, 0x13, 0xc4, 0x4b, 0x10, 0xe0, 0x42, 0xca, 0x3f, 0x32, 0xa7,
  39880. 0xa4, 0xd2, 0xfc, 0x9c, 0x93, 0xb6, 0x5f, 0xe2, 0x5b, 0x6e, 0x40, 0x0c,
  39881. 0x63, 0xf8, 0xf8, 0xe1, 0x2d, 0xcd, 0x86, 0x07, 0x79, 0xdb, 0x61, 0xad,
  39882. 0x24, 0xfd, 0x1e, 0x66, 0x3e, 0x8d, 0x76, 0xba, 0x98, 0x8e, 0x94, 0xc7,
  39883. 0x57, 0xb1, 0x65, 0xce, 0x4f, 0x97, 0xfa, 0x34, 0x7c, 0x97, 0x6b, 0xcd,
  39884. 0x3c, 0x42, 0x81, 0xa4, 0xd1, 0x75, 0xeb, 0x6d, 0x0c, 0x31, 0x0e, 0x6f,
  39885. 0xd5, 0x75, 0xe7, 0xff, 0x83, 0xdd, 0x7a, 0x4d, 0x83, 0x67, 0xa7, 0x4b,
  39886. 0xc1, 0x74, 0xad, 0x37, 0x38, 0x99, 0xe0, 0xf5, 0x5a, 0x44, 0x36, 0xa2,
  39887. 0x20, 0x2b, 0xfc, 0xc9, 0xfa, 0x68, 0xcb, 0xf0, 0x6f, 0x0a, 0x46, 0x1d,
  39888. 0xb5, 0xca, 0x5b, 0x96, 0x1b, 0x3a, 0xaf, 0x7d, 0x01, 0x7a, 0xd2, 0x09,
  39889. 0xcc, 0xd4, 0xe4, 0xb1, 0x49, 0x34, 0x56, 0x68, 0x9c, 0x0f, 0x23, 0xe9,
  39890. 0xb3, 0x4b, 0xed, 0x3d, 0xe7, 0x8d, 0x19, 0x6e, 0xe6, 0xfa, 0x06, 0x55,
  39891. 0xb8, 0x06, 0x4d, 0xa8, 0x45, 0x20, 0x91, 0xf7, 0xfa, 0x0b, 0x6b, 0xce,
  39892. 0x55, 0xa7, 0x14, 0x1b, 0xf9, 0xea, 0xc5, 0x79, 0x78, 0xf7, 0x3a, 0xd9,
  39893. 0xfc, 0x07, 0x43, 0x06, 0x90, 0x94, 0x5e, 0xc9, 0x48, 0x51, 0xe5, 0x96,
  39894. 0x68, 0x78, 0xc8, 0xcb, 0xd1, 0xf3, 0x65, 0xef, 0x14, 0x91, 0xa3, 0xca,
  39895. 0x8b, 0x77, 0x40, 0x84, 0xf4, 0x2e, 0xe7, 0x56, 0xe3, 0xab, 0xa0, 0xa8,
  39896. 0x61, 0x93, 0x17, 0x95, 0x9e, 0xff, 0x3a, 0xd4, 0x12, 0xea, 0x13, 0xe6,
  39897. 0x82, 0x16, 0xed, 0x14, 0x70, 0x91, 0xcc, 0x72, 0x58, 0x99, 0xa1, 0x7f,
  39898. 0xf3, 0x84, 0x10, 0xf4, 0x01, 0x0d, 0x05, 0x45, 0x4d, 0xca, 0x05, 0x03,
  39899. 0x75, 0x7e, 0xbb, 0x44, 0x2e, 0xf5, 0xee, 0xed, 0x64, 0x9b, 0xd3, 0xde,
  39900. 0x3e, 0xfc, 0x31, 0x8c, 0xca, 0x23, 0x66, 0x25, 0xac, 0x5f, 0x0f, 0x33,
  39901. 0x0f, 0xd2, 0xe9, 0xc9, 0x96, 0x2a, 0xe2, 0xb8, 0xed, 0x93, 0xd3, 0x78,
  39902. 0xd8, 0x81, 0xe4, 0x52, 0x9a, 0xc6, 0x64, 0x1d, 0x2d, 0x5f, 0x93, 0x9a,
  39903. 0x2e, 0x73, 0xc4, 0x17, 0xae, 0xc6, 0x08, 0x0d, 0x2d, 0xe9, 0x4b, 0x10,
  39904. 0x29, 0xa8, 0x4e, 0x8c, 0x08, 0x59, 0x87, 0x10, 0x0d, 0x5d, 0xfa, 0xec,
  39905. 0xd6, 0x42, 0xf6, 0x5c, 0xa4, 0x0d, 0xaa, 0x64, 0x8e, 0x20, 0xa5, 0x50,
  39906. 0x9f, 0x0b, 0x85, 0x37, 0x57, 0x15, 0x7c, 0xb1, 0xe4, 0xdd, 0xd5, 0x19,
  39907. 0x3b, 0x10, 0x7d, 0x22, 0xdb, 0x53, 0x8b, 0x7b, 0x32, 0xf7, 0xf2, 0x24,
  39908. 0x92, 0xb2, 0x05, 0xd1, 0xfd, 0xfc, 0x11, 0xd6, 0xfd, 0x3c, 0x8d, 0xd7,
  39909. 0xb0, 0x58, 0x50, 0x06, 0x84, 0x61, 0xa6, 0x78, 0x04, 0x1d, 0x7f, 0x92,
  39910. 0x0e, 0x8b, 0xb3, 0x63, 0x43, 0xc5, 0x30, 0x4c, 0xce, 0x2b, 0x44, 0x70,
  39911. 0x53, 0x7c, 0xb5, 0xbd, 0x30, 0xcb, 0x41, 0x19, 0x27, 0x69, 0xfe, 0x41,
  39912. 0x92, 0xae, 0xf0, 0x37, 0x33, 0xf0, 0x95, 0xe4, 0xe8, 0x4f, 0x75, 0x41,
  39913. 0x64, 0x87, 0xc5, 0x68, 0xd3, 0xce, 0xfa, 0xaa, 0xe8, 0x59, 0x88, 0xfe,
  39914. 0x24, 0x46, 0x27, 0x60, 0x71, 0x36, 0x78, 0x66, 0x3c, 0x36, 0x8e, 0xdb,
  39915. 0x90, 0x67, 0xa5, 0x6a, 0xfe, 0xd3, 0x23, 0x28, 0x91, 0x34, 0x24, 0x67,
  39916. 0x4b, 0x01, 0x6a, 0x0e, 0x02, 0xb7, 0xf0, 0xa8, 0xd4, 0x76, 0xd5, 0xa8,
  39917. 0x1c, 0xd3, 0xb3, 0x7d, 0x74, 0xc6, 0x17, 0x96, 0xa7, 0xf9, 0xad, 0x24,
  39918. 0x36, 0xd2, 0xeb, 0x34, 0x5a, 0xcc, 0x9c, 0x01, 0x99, 0xbe, 0x21, 0x4f,
  39919. 0x27, 0x9d, 0x6b, 0xca, 0x27, 0x1b, 0x60, 0x51, 0x41, 0x23, 0xe1, 0xcb,
  39920. 0xfc, 0x17, 0x2e, 0x1a, 0x4d, 0x3d, 0x51, 0xb3, 0x91, 0x8c, 0x53, 0x4d,
  39921. 0xd7, 0xbc, 0xa4, 0x07, 0xd7, 0x17, 0x19, 0x18, 0x61, 0x38, 0x4e, 0x05,
  39922. 0x81, 0x3f, 0x43, 0x8a, 0x00, 0x60, 0xdc, 0x30, 0xf4, 0x38, 0x3f, 0x93,
  39923. 0x82, 0x10, 0x29, 0x73, 0xa9, 0xbd, 0x63, 0x15, 0x7d, 0xac, 0x2e, 0xc9,
  39924. 0x05, 0xc1, 0x01, 0x41, 0x18, 0x5a, 0xc0, 0xc8, 0xc7, 0x81, 0x69, 0xe7,
  39925. 0x24, 0x21, 0x57, 0xaf, 0x88, 0x73, 0x7c, 0x53, 0x29, 0xae, 0x5a, 0xdf,
  39926. 0x76, 0x37, 0x56, 0x4f, 0x1f, 0x6b, 0xfd, 0x71, 0xbb, 0x80, 0x4a, 0xd7,
  39927. 0x53, 0x50, 0x10, 0x2d, 0xfc, 0x1a, 0xaf, 0x7c, 0x1f, 0xe8, 0xd0, 0x6c,
  39928. 0xa6, 0x45, 0x3d, 0xb5, 0x3d, 0xb2, 0xfc, 0x97, 0xa9, 0xbf, 0x7c, 0x0f,
  39929. 0x32, 0x7a, 0xcc, 0xa9, 0x2f, 0xd0, 0xc6, 0xe6, 0xcd, 0x04, 0x1d, 0x71,
  39930. 0x91, 0xb9, 0x59, 0x4b, 0xad, 0xa0, 0xde, 0x9e, 0xdc, 0x9c, 0x10, 0xeb,
  39931. 0x8d, 0xd6, 0x65, 0x57, 0xbc, 0x96, 0xfd, 0x0f, 0xcc, 0x73, 0xbe, 0x39,
  39932. 0x27, 0x99, 0x94, 0xf5, 0xe1, 0xbb, 0x32, 0xcd, 0x27, 0x7e, 0x08, 0xa0,
  39933. 0xd2, 0x92, 0x39, 0xeb, 0x71, 0xc8, 0xe8, 0x34, 0x57, 0x34, 0x4b, 0x20,
  39934. 0x3f, 0xe2, 0x68, 0xec, 0xc0, 0x8a, 0x71, 0xa3, 0x16, 0xa2, 0x91, 0x77,
  39935. 0xde, 0x41, 0x12, 0xa5, 0xf5, 0x2a, 0x63, 0x60, 0x55, 0xd0, 0x33, 0xa4,
  39936. 0xa7, 0x2e, 0xcb, 0x80, 0x08, 0xe5, 0x76, 0x16, 0x75, 0x04, 0x57, 0xe3,
  39937. 0x14, 0x71, 0x4e, 0x57, 0x29, 0x23, 0x0e, 0xc0, 0xcc, 0xad, 0xba, 0xdc,
  39938. 0x96, 0x5d, 0x23, 0x49, 0x42, 0xd8, 0x91, 0x08, 0x0d, 0x52, 0xf4, 0x5f,
  39939. 0xcd, 0xb7, 0x03, 0xaa, 0x73, 0x26, 0xa8, 0xd5, 0x5b, 0x0c, 0x85, 0xc8,
  39940. 0x84, 0x50, 0x9e, 0x70, 0x18, 0x45, 0x27, 0x82, 0x20, 0x75, 0xad, 0x52,
  39941. 0x5c, 0x80, 0x4b, 0xb1, 0x0b, 0x3b, 0x30, 0x39, 0x02, 0x54, 0x18, 0x5d,
  39942. 0x02, 0x9e, 0x85, 0x31, 0x4a, 0x07, 0x9c, 0x59, 0x5d, 0xab, 0x13, 0x4f,
  39943. 0x8f, 0x6e, 0x39, 0x20, 0xb2, 0xc5, 0x31, 0x93, 0xc6, 0xcc, 0xfb, 0xdc,
  39944. 0x15, 0xba, 0x3d, 0xcc, 0xbb, 0xd2, 0x6f, 0x04, 0x21, 0xdf, 0x0b, 0x27,
  39945. 0x5c, 0xd2, 0x6e, 0xfa, 0xda, 0x86, 0x5d, 0xe4, 0xca, 0xa4, 0x90, 0x22,
  39946. 0xa2, 0x80, 0xb5, 0x33, 0x17, 0xdb, 0x9b, 0x7b, 0x0a, 0xcc, 0x0f, 0x9b,
  39947. 0x38, 0x06, 0xdf, 0x10, 0x11, 0xa1, 0xd7, 0x2c, 0x24, 0xf0, 0xa8, 0x34,
  39948. 0x24, 0xfb, 0x99, 0xba, 0x0a, 0xb5, 0xa1, 0x94, 0x6c, 0x2d, 0xf8, 0xda,
  39949. 0x74, 0xaf, 0x19, 0x59, 0x84, 0xb2, 0x68, 0x1c, 0xef, 0xa1, 0xf5, 0x18,
  39950. 0x8f, 0x10, 0xf6, 0xb3, 0x6d, 0x33, 0x87, 0xe0, 0x25, 0xc8, 0x65, 0x5c,
  39951. 0x2f, 0x51, 0x07, 0x83, 0x69, 0x1b, 0xce, 0xa8, 0xe6, 0xe4, 0x27, 0x62,
  39952. 0x5d, 0x9b, 0x7f, 0xa7, 0x07, 0xc8, 0x54, 0x86, 0x90, 0xa5, 0x06, 0x6a,
  39953. 0x94, 0x80, 0x84, 0x97, 0xaa, 0x2a, 0xb9, 0x79, 0xe5, 0x19, 0x7a, 0x91,
  39954. 0xef, 0x8b, 0x58, 0xdc, 0xf9, 0x90, 0x94, 0xa2, 0x25, 0x4c, 0x69, 0xd8,
  39955. 0x6e, 0x9e, 0xad, 0xf8, 0x82, 0x17, 0x37, 0xc9, 0x20, 0x15, 0x24, 0x40,
  39956. 0xe5, 0xc6, 0xc1, 0xc7, 0xbd, 0xd4, 0x62, 0xff, 0x16, 0x6d, 0xa5, 0xec,
  39957. 0xe9, 0x67, 0x41, 0x9d, 0x3e, 0xfb, 0x22, 0x81, 0x80, 0x61, 0x37, 0x45,
  39958. 0xa5, 0x9f, 0x70, 0xff, 0xd4, 0x99, 0x3d, 0x79, 0x45, 0xd0, 0x27, 0xc2,
  39959. 0x32, 0xbe, 0xd4, 0xe2, 0x53, 0xa8, 0x8c, 0x94, 0x8b, 0xbe, 0x8a, 0x43,
  39960. 0xf7, 0x2a, 0x28, 0x49, 0xf4, 0xce, 0x2e, 0x0b, 0x98, 0xc7, 0xaf, 0x7d,
  39961. 0x51, 0x2e, 0xda, 0xd0, 0x7a, 0xfa, 0x91, 0x3a, 0xe6, 0xe7, 0x64, 0xd6,
  39962. 0x09, 0xd8, 0x5d, 0x6a, 0x97, 0xcf, 0x89, 0x96, 0x72, 0x21, 0x97, 0x61,
  39963. 0xc5, 0x1b, 0xd8, 0xa1, 0xf0, 0xcd, 0x9d, 0xe4, 0xe9, 0x13, 0xd0, 0x16,
  39964. 0x41, 0x20, 0xa4, 0x2c, 0x33, 0xf5, 0x3d, 0xfe, 0x80, 0xe8, 0xb2, 0x52,
  39965. 0x0e, 0x18, 0x31, 0x19, 0x50, 0xeb, 0xc6, 0x99, 0x43, 0xab, 0x9a, 0x59,
  39966. 0x5d, 0x6c, 0x84, 0x00, 0x88, 0x45, 0x7c, 0x73, 0xdf, 0x56, 0x61, 0x3a,
  39967. 0xe1, 0x55, 0xb8, 0x59, 0x13, 0xcc, 0x0e, 0x53, 0xe9, 0xf4, 0x74, 0xa0,
  39968. 0xf2, 0x15, 0xd2, 0xa8, 0xf9, 0xd4, 0x0d, 0x3d, 0xe7, 0x3d, 0x7d, 0x5b,
  39969. 0x19, 0x89, 0x8b, 0x2c, 0x4d, 0x8a, 0xeb, 0xc3, 0x43, 0x31, 0x9a, 0x45,
  39970. 0x72, 0x5b, 0x25, 0xb6, 0xa2, 0xc1, 0x98, 0xe3, 0x8a, 0xd4, 0x90, 0xd0,
  39971. 0x3e, 0x13, 0xf0, 0xd7, 0x90, 0x34, 0x94, 0xcc, 0xf1, 0x0a, 0xa9, 0x30,
  39972. 0xd1, 0x95, 0x43, 0x07, 0xcd, 0xd2, 0xca, 0xb0, 0xe5, 0xd4, 0xf1, 0xa1,
  39973. 0xc5, 0x9b, 0xf4, 0x98, 0x28, 0xba, 0xde, 0x40, 0xd6, 0x98, 0x98, 0x20,
  39974. 0x9c, 0x84, 0x9e, 0xc6, 0x57, 0xd8, 0x84, 0xc4, 0xa2, 0x9b, 0x53, 0x50,
  39975. 0xa5, 0xa6, 0x0b, 0x47, 0xe8, 0x08, 0x7d, 0xd7, 0x09, 0xa4, 0x0c, 0x2b,
  39976. 0x27, 0xde, 0xf9, 0x78, 0xbc, 0xa4, 0xb6, 0xc6, 0x1b, 0xda, 0xce, 0x6a,
  39977. 0xf8, 0x1a, 0xf5, 0xfe, 0x7b, 0xab, 0x58, 0x7c, 0xdc, 0x72, 0x02, 0x94,
  39978. 0x99, 0xf0, 0x3c, 0x37, 0x87, 0x5b, 0xd2, 0x4b, 0x5a, 0x80, 0x83, 0xd7,
  39979. 0xfc, 0x9d, 0xa7, 0x51, 0x81, 0xb8, 0x62, 0xff, 0x4b, 0xb3, 0x9f, 0x07,
  39980. 0xc3, 0x54, 0xfb, 0x41, 0x85, 0x42, 0x9d, 0xac, 0x27, 0x81, 0x2e, 0xaf,
  39981. 0x98, 0x67, 0x8c, 0x23, 0xad, 0x45, 0xfe, 0x6a, 0x57, 0x9f, 0x18, 0xc5,
  39982. 0x71, 0x8c, 0xad, 0x3f, 0x30, 0x3c, 0xaa, 0x47, 0x8d, 0xba, 0xc8, 0x7f,
  39983. 0x03, 0x1c, 0x86, 0xee, 0xba, 0x3f, 0x59, 0x45, 0xd4, 0xd0, 0xf5, 0x54,
  39984. 0x9e, 0xcb, 0x08, 0xcf, 0xca, 0x40, 0x0a, 0x06, 0xc0, 0x1e, 0x60, 0x1f,
  39985. 0x33, 0xbf, 0x2c, 0xa8, 0x5f, 0xce, 0x23, 0xa0, 0xe2, 0x1c, 0x2d, 0x56,
  39986. 0x2a, 0x44, 0x61, 0x58, 0xf1, 0x84, 0x63, 0x4f, 0x0d, 0x5e, 0xfb, 0x83,
  39987. 0x0f, 0x36, 0x1b, 0xf4, 0x8f, 0x17, 0x82, 0x2e, 0x04, 0x2c, 0x77, 0x9d,
  39988. 0x32, 0x58, 0xb8, 0xb0, 0xf9, 0x44, 0xd2, 0xf6, 0x84, 0xa4, 0x8b, 0x28,
  39989. 0x53, 0xd6, 0x99, 0x81, 0x84, 0x43, 0xf0, 0xc1, 0x15, 0xc6, 0x74, 0x4f,
  39990. 0xab, 0x05, 0xcc, 0x80, 0xdf, 0xef, 0xcf, 0xaf, 0x14, 0x82, 0xdf, 0x51,
  39991. 0x7c, 0x28, 0x5e, 0x5b, 0x27, 0x5e, 0x91, 0x8b, 0x54, 0x3d, 0x54, 0x26,
  39992. 0xb0, 0x3f, 0xd7, 0xc5, 0xce, 0xf3, 0x6d, 0x2c, 0x12, 0xc6, 0xb4, 0x48,
  39993. 0x60, 0x11, 0x9c, 0xef, 0x29, 0x98, 0x9c, 0x76, 0x4e, 0x73, 0x2b, 0xd2,
  39994. 0x23, 0x53, 0x7d, 0x03, 0xc2, 0x2f, 0x8a, 0xa1, 0xe2, 0x84, 0x54, 0x2d,
  39995. 0xd8, 0xc6, 0x55, 0x77, 0x9d, 0x07, 0x67, 0x1f, 0x1a, 0xd3, 0x57, 0x4c,
  39996. 0x25, 0x79, 0x8f, 0xd8, 0x82, 0xc2, 0x4d, 0x87, 0x84, 0x33, 0xdc, 0x47,
  39997. 0xed, 0x9e, 0xfb, 0xd2, 0x62, 0xc8, 0x50, 0x76, 0xda, 0x3c, 0x3c, 0x05,
  39998. 0x0e, 0x2d, 0x30, 0x56, 0xca, 0x4d, 0x6a, 0xe2, 0x17, 0x24, 0x26, 0x9c,
  39999. 0xff, 0x09, 0xec, 0xb3, 0x94, 0xec, 0xab, 0x69, 0xb2, 0xf0, 0xa5, 0x66,
  40000. 0x18, 0x92, 0x49, 0x6b, 0x90, 0xf5, 0x77, 0x5a, 0x18, 0xe5, 0x51, 0x36,
  40001. 0x4a, 0x35, 0x54, 0x98, 0x48, 0x04, 0xa9, 0x0f, 0xcb, 0x55, 0xf1, 0x71,
  40002. 0xad, 0x1a, 0x4a, 0x2c, 0x0e, 0x5d, 0x5e, 0x77, 0x47, 0xf5, 0x46, 0x17,
  40003. 0x6b, 0x94, 0x2a, 0xbc, 0x40, 0xe5, 0xa7, 0xa6, 0x88, 0x41, 0x76, 0x22,
  40004. 0x47, 0xd1, 0xe8, 0x2b, 0x18, 0x48, 0x21, 0xc0, 0xe8, 0x4f, 0xe2, 0xb2,
  40005. 0x7e, 0x03, 0xbb, 0x25, 0x9c, 0xc8, 0x68, 0x66, 0x48, 0x25, 0x6a, 0xf2,
  40006. 0x64, 0x29, 0xec, 0x79, 0xba, 0xdb, 0x34, 0xe1, 0xd4, 0xf9, 0x52, 0x0e,
  40007. 0xfd, 0x8d, 0x86, 0x94, 0x71, 0xd8, 0xe0, 0x86, 0x02, 0x9b, 0xd4, 0x65,
  40008. 0x69, 0x5e, 0x01, 0x32, 0x87, 0x59, 0xd8, 0x6c, 0xbc, 0x8a, 0x9f, 0x58,
  40009. 0x28, 0x8c, 0x97, 0xef, 0x33, 0xb2, 0xda, 0x45, 0xa0, 0xec, 0xe5, 0x5b,
  40010. 0xac, 0xc6, 0x65, 0xc1, 0xb6, 0xcb, 0xf7, 0x85, 0x0e, 0xfa, 0x78, 0x36,
  40011. 0x30, 0x84, 0x90, 0xa8, 0xf8, 0x42, 0x25, 0xa5, 0xdd, 0xdc, 0xdc, 0x89,
  40012. 0xd3, 0xf0, 0x73, 0x9a, 0xd8, 0x95, 0x8f, 0x04, 0xbf, 0xc1, 0xfd, 0x94,
  40013. 0xff, 0xe6, 0xf8, 0x4e, 0xc6, 0x43, 0xc9, 0x60, 0x30, 0xe9, 0x68, 0xa8,
  40014. 0x76, 0xfb, 0xfa, 0xdf, 0xc0, 0x9b, 0xbc, 0xbc, 0x34, 0xe4, 0x38, 0xfd,
  40015. 0x93, 0xb0, 0x47, 0xb2, 0x3e, 0x83, 0x6c, 0xef, 0xe1, 0xaf, 0x35, 0xb4,
  40016. 0x90, 0x2a, 0x32, 0xaf, 0x25, 0x3f, 0x3e, 0x72, 0x61, 0xc0, 0x0f, 0x29,
  40017. 0xbb, 0x46, 0x6e, 0x2e, 0x94, 0x7d, 0xdd, 0xb7, 0x67, 0x1f, 0x7b, 0x64,
  40018. 0xcb, 0xa5, 0x9a, 0x58, 0x63, 0x20, 0xa7, 0xc0, 0x94, 0xa9, 0xad, 0x90,
  40019. 0x7d, 0xf3, 0x2b, 0x61, 0x2b, 0x64, 0x3d, 0x8a, 0xc3, 0xd1, 0xcb, 0xad,
  40020. 0x36, 0x44, 0xe6, 0x29, 0x8b, 0x3d, 0x95, 0x7c, 0xa7, 0xa2, 0xfa, 0x1b,
  40021. 0x16, 0x8d, 0x9e, 0xc4, 0xf8, 0x4c, 0x76, 0x20, 0x00, 0x68, 0x07, 0x99,
  40022. 0x9c, 0x60, 0xe6, 0x16, 0x6a, 0x6f, 0x8a, 0xbe, 0x71, 0x95, 0xa1, 0xcb,
  40023. 0xfe, 0x7c, 0x41, 0x59, 0x61, 0x20, 0xf9, 0x54, 0x3c, 0xb1, 0x19, 0x5c,
  40024. 0x42, 0x67, 0x3f, 0xff, 0xf3, 0x32, 0x21, 0x9c, 0x9e, 0x88, 0xf9, 0x97,
  40025. 0x00, 0x43, 0x73, 0x4a, 0xfc, 0x54, 0xeb, 0x27, 0x79, 0x14, 0x85, 0xd3,
  40026. 0xdc, 0x47, 0xb3, 0x6d, 0x24, 0xd3, 0xf7, 0x7a, 0xfb, 0x90, 0x7c, 0x6e,
  40027. 0xcd, 0x4e, 0xbf, 0x26, 0x76, 0xd2, 0xe8, 0xcc, 0x67, 0xd1, 0x23, 0x3c,
  40028. 0x94, 0x16, 0x1e, 0x07, 0x36, 0x7c, 0x96, 0xf6, 0xe8, 0x50, 0x72, 0x26,
  40029. 0x56, 0x67, 0x89, 0xa9, 0x11, 0xfb, 0x1d, 0xb8, 0xb9, 0x2a, 0x55, 0xb7,
  40030. 0x85, 0xf7, 0x40, 0xa2, 0xfc, 0x9f, 0x30, 0xec, 0x8f, 0x9a, 0x1c, 0xc8,
  40031. 0xe4, 0xc5, 0x1f, 0xcb, 0x0a, 0x60, 0x80, 0x41, 0xec, 0x88, 0x8a, 0xda,
  40032. 0x7c, 0x7a, 0xa1, 0x96, 0x51, 0x62, 0x16, 0x63, 0x75, 0x36, 0x28, 0x7c,
  40033. 0xc9, 0xd0, 0x27, 0x0c, 0x9e, 0x18, 0x4a, 0x82, 0xf7, 0x02, 0xb9, 0x40,
  40034. 0x8f, 0xd5, 0x97, 0x7a, 0x35, 0xa9, 0x3a, 0xb3, 0x8b, 0x6b, 0xf1, 0x9a,
  40035. 0xd1, 0xe7, 0x14, 0x38, 0x5e, 0xba, 0x8c, 0xbf, 0x32, 0xaa, 0x34, 0x30,
  40036. 0x7c, 0x1e, 0x11, 0xcd, 0x1f, 0x9f, 0xcf, 0x4d, 0x14, 0xce, 0x67, 0xf9,
  40037. 0x9c, 0x89, 0x07, 0x92, 0x44, 0x6e, 0x9a, 0x16, 0xe4, 0xfb, 0x67, 0x01,
  40038. 0x3f, 0x4c, 0x14, 0x89, 0x33, 0x87, 0x46, 0xc6, 0xe4, 0x66, 0x94, 0xd4,
  40039. 0x87, 0x4f, 0x2c, 0x92, 0x1b, 0xae, 0x82, 0xe7, 0x99, 0xaa, 0xb4, 0x99,
  40040. 0x81, 0x26, 0xa6, 0x6f, 0x1d, 0xc1, 0x95, 0x80, 0xe9, 0xea, 0xe3, 0x44,
  40041. 0x6a, 0x2b, 0xd2, 0xe0, 0x0d, 0x69, 0x42, 0xf7, 0x27, 0x6b, 0x4f, 0x02,
  40042. 0x7a, 0x33, 0x7b, 0x43, 0x3d, 0xef, 0x10, 0xaa, 0xab, 0xc5, 0xa2, 0xf0,
  40043. 0xbb, 0x07, 0x4b, 0x26, 0x0c, 0x58, 0xcd, 0x3b, 0xd2, 0x6d, 0xa5, 0x32,
  40044. 0x37, 0x88, 0x4e, 0x8b, 0xe3, 0x75, 0xb0, 0xbb, 0x87, 0xea, 0xa4, 0x53,
  40045. 0xf3, 0xff, 0x39, 0x92, 0x44, 0xab, 0x7b, 0x71, 0x62, 0x31, 0x6b, 0x31,
  40046. 0xca, 0x97, 0xba, 0xd7, 0x41, 0xe0, 0x47, 0x47, 0x4f, 0x77, 0xa2, 0x35,
  40047. 0x62, 0x7a, 0xc1, 0xb6, 0x69, 0x10, 0x09, 0xce, 0xfc, 0x92, 0xcc, 0xc5,
  40048. 0x7a, 0x11, 0xf1, 0xc1, 0xa0, 0x80, 0xe5, 0x42, 0x17, 0xb6, 0x3f, 0xab,
  40049. 0xc1, 0xa2, 0x41, 0xfb, 0xe3, 0x98, 0x2d, 0x7a, 0xe4, 0x1b, 0x1f, 0x7e,
  40050. 0x71, 0x3c, 0x3e, 0x90, 0x8c, 0x60, 0x30, 0xb7, 0x73, 0x06, 0x1f, 0x8a,
  40051. 0xce, 0x50, 0x20, 0x7c, 0xfa, 0x8c, 0xf2, 0x14, 0xd9, 0x00, 0xa2, 0x21,
  40052. 0xea, 0x10, 0x36, 0x21, 0x6f, 0x7f, 0x13, 0xe3, 0x6c, 0xb2, 0xd6, 0xa5,
  40053. 0xa6, 0x6e, 0xa9, 0xe7, 0x1d, 0xdf, 0xc9, 0x97, 0x60, 0x75, 0xa3, 0x55,
  40054. 0xa1, 0x2c, 0x94, 0xd7, 0x85, 0x4b, 0x44, 0xc6, 0x9c, 0x17, 0xc2, 0xad,
  40055. 0xe6, 0x56, 0x72, 0x1d, 0xb9, 0x13, 0x54, 0xfe, 0x8c, 0xec, 0xf4, 0xa3,
  40056. 0x54, 0x6b, 0x31, 0xbc, 0x55, 0x9e, 0x01, 0xd4, 0x9b, 0x24, 0x9e, 0x51,
  40057. 0xaf, 0x67, 0x76, 0x02, 0xf7, 0x34, 0x6a, 0xaa, 0xb0, 0x3c, 0x70, 0x2e,
  40058. 0xc8, 0x86, 0xfa, 0x40, 0x89, 0x12, 0xb7, 0x49, 0x38, 0x0b, 0xf7, 0x66,
  40059. 0xd2, 0x2e, 0x58, 0xf1, 0x22, 0x3b, 0xb3, 0x40, 0x6b, 0x7a, 0x68, 0x4d,
  40060. 0x42, 0xfd, 0xbf, 0xa0, 0xf7, 0x2f, 0x63, 0x4a, 0x87, 0xe7, 0x99, 0x52,
  40061. 0x6e, 0xe7, 0xdd, 0xca, 0x19, 0x71, 0xee, 0x92, 0xe2, 0x68, 0x0e, 0xe1,
  40062. 0xb7, 0x90, 0x1f, 0xc4, 0xef, 0xf8, 0xf6, 0x85, 0x53, 0x18, 0x33, 0x86,
  40063. 0x15, 0xc8, 0x29, 0x58, 0x6f, 0xf0, 0x1c, 0x14, 0x73, 0xa9, 0x8e, 0x88,
  40064. 0x74, 0xd4, 0x21, 0xf5, 0xc6, 0x7c, 0xd8, 0x96, 0x0f, 0xb0, 0xa6, 0x7b,
  40065. 0xf7, 0x72, 0x15, 0xd7, 0x30, 0x6b, 0x15, 0x1d, 0x3f, 0xb7, 0x4e, 0xaa,
  40066. 0xc0, 0x52, 0x1d, 0x84, 0xbf, 0x98, 0xbd, 0x33, 0x02, 0xab, 0x8b, 0xd0,
  40067. 0x9c, 0x85, 0x2f, 0xa3, 0xfb, 0x46, 0x8d, 0x4d, 0x97, 0x1a, 0x8a, 0x3c,
  40068. 0x73, 0x5b, 0x3b, 0x58, 0x26, 0xba, 0x6b, 0x45, 0x2e, 0x24, 0x66, 0x79,
  40069. 0x7d, 0xc4, 0xf8, 0x8c, 0x05, 0x7d, 0x5c, 0x23, 0xb9, 0xe8, 0x5d, 0xfe,
  40070. 0xc9, 0x84, 0xe5, 0x58, 0x40, 0xa4, 0xb7, 0x55, 0x74, 0x69, 0x92, 0x9c,
  40071. 0x3e, 0x19, 0xb1, 0xb6, 0x51, 0xe9, 0x71, 0xcc, 0x96, 0x2b, 0x01, 0x71,
  40072. 0xf5, 0xb9, 0xde, 0x77, 0xfe, 0x2e, 0x74, 0x9c, 0x6a, 0x52, 0x17, 0x1e,
  40073. 0xea, 0xd9, 0xc8, 0x14, 0xbe, 0x61, 0xdf, 0xe9, 0x96, 0x24, 0x5a, 0x9a,
  40074. 0xd8, 0xd7, 0xad, 0x71, 0xe0, 0xf4, 0xbb, 0x9e, 0xae, 0x95, 0xcd, 0x58,
  40075. 0x94, 0x81, 0xee, 0x46, 0x84, 0x65, 0x39, 0xb1, 0x1b, 0x1e, 0xf5, 0x50,
  40076. 0xad, 0x56, 0x58, 0xb7, 0x53, 0x9b, 0x2a, 0x2f, 0x09, 0x61, 0x57, 0xda,
  40077. 0xf5, 0xdc, 0x9f, 0x3c, 0x6c, 0x69, 0x0d, 0x61, 0x49, 0xb2, 0xe0, 0xb2,
  40078. 0xe5, 0xef, 0x19, 0xbe, 0x04, 0xf6, 0x6b, 0xad, 0x41, 0x4c, 0x5a, 0x50,
  40079. 0xf6, 0xac, 0x1b, 0x25, 0x8a, 0xdd, 0xe3, 0x57, 0xab, 0x7c, 0x92, 0xe4
  40080. };
  40081. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40082. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_pub_key[] = {
  40083. 0xef, 0x49, 0x79, 0x47, 0x15, 0xc4, 0x8a, 0xa9, 0x74, 0x2a,
  40084. 0xf0, 0x36, 0x94, 0x5c, 0x91, 0x1c, 0x5d, 0xff, 0x2c, 0x83,
  40085. 0xf2, 0x8b, 0x04, 0xfc, 0x5d, 0x64, 0xbd, 0x49, 0x73, 0xcd,
  40086. 0xcc, 0x99, 0x50, 0x5f, 0x2b, 0x16, 0x3a, 0xbb, 0x98, 0xc0,
  40087. 0xa7, 0x69, 0x0e, 0x95, 0x99, 0x0b, 0xa2, 0x6c, 0xfe, 0x6c,
  40088. 0xdb, 0xc8, 0xa7, 0x09, 0x46, 0x6c, 0x90, 0x50, 0xa4, 0x75,
  40089. 0x30, 0xf7, 0x90, 0xac, 0x31, 0xb6, 0xdd, 0x21, 0xaf, 0xc6,
  40090. 0xf9, 0xfe, 0xee, 0xc6, 0x5b, 0xa8, 0x8f, 0x0a, 0x2e, 0xd0,
  40091. 0x42, 0xab, 0xa8, 0x3c, 0x8d, 0xbf, 0xf7, 0x44, 0xbd, 0x0d,
  40092. 0xcf, 0xf4, 0x68, 0xfc, 0x16, 0x67, 0xf7, 0x39, 0x48, 0x5f,
  40093. 0x56, 0xd1, 0xe7, 0x1f, 0x49, 0x80, 0x50, 0xbe, 0x54, 0xd1,
  40094. 0xb7, 0xc9, 0xd2, 0x32, 0xc7, 0x08, 0x8c, 0xde, 0x2c, 0x31,
  40095. 0xf6, 0x1d, 0xc7, 0xac, 0xb3, 0x79, 0xd7, 0x4b, 0x1b, 0x23,
  40096. 0x89, 0x0a, 0xdc, 0x8e, 0x44, 0x41, 0x14, 0x28, 0x99, 0x13,
  40097. 0xb3, 0x26, 0xa6, 0x0e, 0x83, 0x60, 0xaa, 0x8d, 0x7c, 0x23,
  40098. 0x13, 0xba, 0x6c, 0x28, 0x90, 0x56, 0x84, 0xa1, 0x23, 0x8b,
  40099. 0x81, 0x20, 0x97, 0x7c, 0x66, 0x3f, 0xed, 0x5d, 0xd0, 0xe4,
  40100. 0x5d, 0xee, 0x46, 0xbc, 0x4b, 0x3c, 0x03, 0xb5, 0xbc, 0x4d,
  40101. 0x8d, 0x37, 0xa3, 0x56, 0x4b, 0x33, 0xad, 0xef, 0xd4, 0xb6,
  40102. 0xec, 0xdb, 0x04, 0x9a, 0x19, 0x58, 0x57, 0xd8, 0x00, 0x3a,
  40103. 0x92, 0x61, 0x0c, 0x0b, 0xc8, 0x52, 0xe5, 0x04, 0x02, 0x9a,
  40104. 0x00, 0x7e, 0xec, 0x7e, 0x94, 0xaa, 0xef, 0x2d, 0x7f, 0xb6,
  40105. 0x2e, 0x7c, 0xb0, 0x73, 0xa2, 0x20, 0xc0, 0x07, 0x30, 0x41,
  40106. 0x50, 0x20, 0x14, 0x18, 0x21, 0x5e, 0x2a, 0x6f, 0x70, 0x21,
  40107. 0xd6, 0x97, 0x13, 0xb9, 0xc1, 0x9e, 0x90, 0x67, 0xcc, 0x55,
  40108. 0x8a, 0xec, 0xec, 0x0a, 0x1e, 0x90, 0xdc, 0x3f, 0xb0, 0x4d,
  40109. 0xd1, 0x18, 0xea, 0x4f, 0xcb, 0x5d, 0x15, 0x4c, 0xb8, 0x35,
  40110. 0x9b, 0x34, 0x24, 0x30, 0x06, 0x53, 0x17, 0xf0, 0xbe, 0x27,
  40111. 0x36, 0xb3, 0x04, 0x6a, 0xbd, 0xbf, 0xa7, 0x39, 0xee, 0xa9,
  40112. 0x8f, 0x0e, 0x98, 0xc5, 0xf5, 0x9f, 0x46, 0x25, 0x93, 0xc9,
  40113. 0xf2, 0xf6, 0x2b, 0x8e, 0x92, 0x06, 0x01, 0x3d, 0x81, 0x18,
  40114. 0xf2, 0xec, 0xf1, 0x05, 0x4c, 0xad, 0x4b, 0xcb, 0x98, 0xa4,
  40115. 0xb5, 0x61, 0x20, 0xda, 0x81, 0xa1, 0xfb, 0x92, 0x4c, 0xaf,
  40116. 0x87, 0x6f, 0x6e, 0xd2, 0x57, 0xec, 0xcd, 0x94, 0xb3, 0x79,
  40117. 0xbf, 0x59, 0x88, 0x17, 0x81, 0xce, 0x8a, 0x57, 0xce, 0x57,
  40118. 0xae, 0x3e, 0x82, 0x81, 0x2f, 0x83, 0x61, 0xd8, 0xf9, 0x68,
  40119. 0x21, 0xe7, 0x72, 0x5b, 0xd6, 0x80, 0x55, 0x68, 0x5d, 0x67,
  40120. 0x15, 0x0c, 0x8b, 0xdc, 0x4f, 0xc3, 0x89, 0x36, 0x3c, 0xac,
  40121. 0xaf, 0x16, 0x5e, 0x1c, 0xfa, 0x68, 0x74, 0x6a, 0xab, 0x68,
  40122. 0xd8, 0x59, 0x96, 0x2d, 0x33, 0x62, 0xe4, 0xbd, 0xb3, 0xb7,
  40123. 0x4d, 0x88, 0x35, 0xb8, 0xed, 0xb2, 0x16, 0x85, 0x97, 0x08,
  40124. 0x71, 0x71, 0x39, 0x7e, 0x0c, 0x53, 0x16, 0xda, 0x38, 0xe5,
  40125. 0x28, 0x09, 0x9c, 0xd9, 0x46, 0xec, 0x68, 0xda, 0x8d, 0xd0,
  40126. 0xad, 0xb2, 0x79, 0x28, 0x3b, 0x1e, 0x12, 0xc9, 0xdf, 0xa9,
  40127. 0x6d, 0x3d, 0x29, 0x99, 0x2f, 0x53, 0xc2, 0xd0, 0xf9, 0x88,
  40128. 0x26, 0x94, 0x47, 0xaf, 0xf6, 0x96, 0xf3, 0xe1, 0x11, 0xa6,
  40129. 0x82, 0x3d, 0x43, 0x3f, 0x1f, 0xbc, 0xf6, 0x98, 0xbe, 0xff,
  40130. 0x06, 0x86, 0x61, 0x27, 0xdc, 0x91, 0x54, 0xd4, 0xfc, 0x68,
  40131. 0x83, 0xe8, 0x35, 0x3e, 0xee, 0x94, 0x59, 0x28, 0x2f, 0xde,
  40132. 0xdd, 0x03, 0x60, 0x66, 0xc1, 0x49, 0x57, 0xdd, 0xbc, 0xd5,
  40133. 0x0a, 0x67, 0x34, 0xf1, 0xa6, 0x0a, 0x57, 0x94, 0x65, 0x02,
  40134. 0x2c, 0x52, 0x43, 0x70, 0x3b, 0xc1, 0x9a, 0xff, 0xda, 0x6f,
  40135. 0xb9, 0x54, 0x47, 0x01, 0xda, 0x27, 0xe4, 0x48, 0x4a, 0x90,
  40136. 0x9f, 0xb5, 0xc3, 0xee, 0x0e, 0x09, 0x57, 0xfe, 0x48, 0x51,
  40137. 0x08, 0x34, 0x5e, 0x8f, 0x16, 0xc9, 0x0b, 0x74, 0xd9, 0x7d,
  40138. 0x22, 0x3f, 0xd6, 0xb7, 0x5d, 0xd6, 0x76, 0x00, 0x8d, 0x4e,
  40139. 0x78, 0x73, 0x86, 0xd6, 0xdb, 0x2a, 0x65, 0xab, 0xdf, 0xb0,
  40140. 0xea, 0x11, 0xad, 0xdf, 0xba, 0x43, 0xdb, 0xa8, 0x0a, 0xfb,
  40141. 0x04, 0x38, 0x81, 0x2b, 0xa3, 0x29, 0xfc, 0x95, 0x73, 0x9a,
  40142. 0x0c, 0x6c, 0x9e, 0xcd, 0xdc, 0xcf, 0x0a, 0x0c, 0x18, 0x41,
  40143. 0x6f, 0x1d, 0xa3, 0xf6, 0x12, 0x4c, 0x13, 0xf2, 0x02, 0xc6,
  40144. 0x50, 0x99, 0x86, 0x73, 0xa7, 0xf9, 0x7e, 0x84, 0x7f, 0x4c,
  40145. 0x00, 0xce, 0x2e, 0x21, 0x76, 0x8e, 0x17, 0x7a, 0x87, 0x6f,
  40146. 0x81, 0xe6, 0xc0, 0x52, 0xa5, 0xa0, 0x3c, 0x54, 0x3c, 0xec,
  40147. 0xb0, 0x9d, 0x1c, 0x3b, 0xec, 0xe5, 0x4e, 0x4a, 0x37, 0xe7,
  40148. 0xd5, 0xa9, 0x07, 0x87, 0x23, 0x28, 0x5d, 0x3d, 0x22, 0x02,
  40149. 0x79, 0x40, 0x3f, 0x2d, 0x40, 0xc9, 0xe5, 0xa6, 0x9b, 0xa8,
  40150. 0xb8, 0x76, 0xf6, 0x77, 0x5b, 0x8d, 0x72, 0x96, 0x3e, 0x13,
  40151. 0xbf, 0x76, 0xfa, 0x7b, 0xb7, 0x82, 0x5f, 0xe7, 0x9d, 0x54,
  40152. 0x0e, 0x05, 0x1a, 0x9f, 0xa4, 0x42, 0xa5, 0xb4, 0x93, 0x23,
  40153. 0x06, 0x59, 0x43, 0xa8, 0xe8, 0x5c, 0xfc, 0x18, 0x97, 0xdb,
  40154. 0xad, 0x9a, 0x80, 0x0a, 0xf2, 0x20, 0x50, 0xac, 0xc1, 0x13,
  40155. 0x3e, 0x98, 0x09, 0xde, 0xf2, 0x70, 0x9e, 0x14, 0xc2, 0x5c,
  40156. 0xec, 0x65, 0x07, 0x0b, 0xfa, 0x02, 0x5c, 0xf8, 0x71, 0xaa,
  40157. 0x9b, 0x45, 0x62, 0xe2, 0x27, 0xaf, 0x77, 0xf8, 0xe3, 0xeb,
  40158. 0x7b, 0x24, 0x7b, 0x3c, 0x67, 0xc2, 0x6d, 0x6e, 0x17, 0xae,
  40159. 0x6e, 0x86, 0x6f, 0x98, 0xc9, 0xac, 0x13, 0x9f, 0x87, 0x64,
  40160. 0x3d, 0x4d, 0x6f, 0xa0, 0xb3, 0x39, 0xc6, 0x68, 0x1b, 0xa7,
  40161. 0xeb, 0x3e, 0x0f, 0x6b, 0xc7, 0xa4, 0xe2, 0x20, 0x27, 0x75,
  40162. 0x3f, 0x09, 0x16, 0xff, 0x1a, 0xcc, 0xa7, 0xc4, 0x6d, 0xc2,
  40163. 0xfc, 0xc3, 0x0b, 0x37, 0x63, 0xff, 0x9b, 0x10, 0xe6, 0x00,
  40164. 0xf7, 0x18, 0x43, 0x9f, 0x07, 0x50, 0x31, 0x51, 0xd4, 0xfd,
  40165. 0xad, 0xa2, 0x0f, 0x77, 0xda, 0x41, 0xc1, 0x0a, 0x6f, 0x86,
  40166. 0xd7, 0xdc, 0x8a, 0x52, 0xd6, 0xa1, 0x27, 0xdb, 0x14, 0x67,
  40167. 0x26, 0x91, 0xb3, 0xcd, 0x01, 0x5f, 0x60, 0xa1, 0x7f, 0x43,
  40168. 0x15, 0x1a, 0x82, 0x0f, 0xd3, 0x66, 0x5f, 0x60, 0x57, 0x2f,
  40169. 0xb2, 0x8c, 0x27, 0x2a, 0x9d, 0x1b, 0xf9, 0xf2, 0x59, 0x20,
  40170. 0x39, 0xd9, 0xc5, 0xaf, 0xf2, 0x36, 0x8c, 0x58, 0x00, 0x1b,
  40171. 0xd0, 0xc5, 0x8e, 0x1a, 0x49, 0xa8, 0x60, 0xbe, 0xd1, 0xd7,
  40172. 0x2a, 0xb0, 0xc2, 0xab, 0x58, 0x8a, 0x7a, 0xa9, 0x41, 0x68,
  40173. 0x70, 0xbd, 0xea, 0x73, 0xa5, 0x03, 0x11, 0xb2, 0x27, 0xd9,
  40174. 0xcd, 0xf5, 0x09, 0xe8, 0x1c, 0xe2, 0x4f, 0x50, 0x6a, 0x84,
  40175. 0x34, 0x62, 0x2e, 0x36, 0xaa, 0x4c, 0xc1, 0x83, 0x78, 0x98,
  40176. 0x35, 0x7a, 0x27, 0x7e, 0xfe, 0xf1, 0x6f, 0x59, 0x27, 0x35,
  40177. 0x73, 0xce, 0x74, 0xaa, 0xb4, 0x72, 0x82, 0xa8, 0xe2, 0x81,
  40178. 0x7a, 0x6b, 0xca, 0x33, 0xa5, 0xda, 0xa2, 0x63, 0xca, 0x2e,
  40179. 0x90, 0x03, 0x32, 0xec, 0x63, 0xdb, 0x52, 0x7b, 0x16, 0xfc,
  40180. 0x01, 0x2d, 0x30, 0x12, 0x1e, 0xf9, 0xa3, 0x72, 0x21, 0x3c,
  40181. 0x75, 0x0c, 0x61, 0x9c, 0x7e, 0x73, 0x04, 0x71, 0x41, 0x45,
  40182. 0x5d, 0x7f, 0x49, 0x1c, 0x09, 0x08, 0xa4, 0xec, 0x2f, 0xfd,
  40183. 0xc4, 0xfb, 0x59, 0x6a, 0x27, 0x7a, 0xd4, 0xfc, 0x5f, 0x20,
  40184. 0x04, 0x34, 0x7d, 0x08, 0xed, 0x82, 0x5a, 0x90, 0xe1, 0xab,
  40185. 0xfd, 0x35, 0x3a, 0x8d, 0xbb, 0x0a, 0x9d, 0x73, 0xff, 0x69,
  40186. 0xe5, 0xe9, 0x09, 0x55, 0x14, 0xd9, 0x7b, 0x6f, 0x0d, 0x99,
  40187. 0xd2, 0x7e, 0x71, 0xf8, 0x4f, 0x72, 0x2f, 0xbb, 0xc6, 0xc4,
  40188. 0x36, 0xc9, 0x01, 0xd3, 0x9b, 0x94, 0xab, 0x41, 0x0f, 0x4a,
  40189. 0x61, 0x5c, 0x68, 0xe5, 0xd7, 0x0d, 0x94, 0xaa, 0xee, 0xba,
  40190. 0x95, 0xcb, 0x8c, 0x0e, 0x85, 0x3a, 0x02, 0x6b, 0x95, 0x50,
  40191. 0xfd, 0x02, 0xfd, 0xa4, 0x58, 0x29, 0x78, 0x4f, 0xd0, 0xae,
  40192. 0x66, 0xd6, 0x5c, 0xe7, 0x45, 0xfe, 0x98, 0xb0, 0xa3, 0xe2,
  40193. 0x87, 0xc0, 0xd2, 0x81, 0x08, 0xf1, 0xf1, 0xe7, 0xda, 0x62,
  40194. 0x9e, 0xa0, 0x34, 0x86, 0xeb, 0xa1, 0x6e, 0x4a, 0x26, 0x8e,
  40195. 0x39, 0x0c, 0x51, 0x10, 0x33, 0x11, 0x87, 0xf8, 0x79, 0x3c,
  40196. 0x49, 0x7a, 0x8b, 0xce, 0xc1, 0x0a, 0x0e, 0xe1, 0xd5, 0x2a,
  40197. 0xac, 0xf0, 0x3a, 0x1d, 0x6a, 0x6a, 0xe5, 0xe1, 0x81, 0x70,
  40198. 0xad, 0xaf, 0x15, 0x4c, 0x2a, 0x70, 0x2a, 0x6b, 0x22, 0x0d,
  40199. 0x30, 0xe7, 0x56, 0xed, 0x2d, 0x4b, 0x85, 0x17, 0x49, 0x72,
  40200. 0x3a, 0x1b, 0x6f, 0x57, 0x1c, 0xf7, 0x72, 0x9e, 0x20, 0xdb,
  40201. 0x57, 0x1c, 0xfb, 0x36, 0x50, 0x52, 0xec, 0x5b, 0xd6, 0x6a,
  40202. 0x1b, 0xf8, 0x74, 0xad, 0xe6, 0x00, 0x74, 0x04, 0xc5, 0x99,
  40203. 0x83, 0xe4, 0x5a, 0x0c, 0xc3, 0xe8, 0x6d, 0x3a, 0xd7, 0x3c,
  40204. 0x3c, 0xc0, 0x1a, 0x28, 0xb3, 0x29, 0x7a, 0x10, 0x9e, 0x39,
  40205. 0x66, 0x5b, 0xc1, 0x38, 0xac, 0x21, 0x4e, 0xcd, 0x01, 0xf2,
  40206. 0xf6, 0x30, 0x2c, 0x2b, 0xb6, 0xbf, 0xf5, 0xea, 0x61, 0xaf,
  40207. 0x0c, 0xa6, 0x01, 0x11, 0x15, 0x19, 0x09, 0x8c, 0x7e, 0x69,
  40208. 0xdf, 0x3b, 0xea, 0xd3, 0x0a, 0x3a, 0xd7, 0xbd, 0xe1, 0x17,
  40209. 0xaf, 0x92, 0x3c, 0xf5, 0xfe, 0x35, 0xd6, 0xcf, 0x07, 0xa6,
  40210. 0xf7, 0xe9, 0xc1, 0x99, 0xed, 0x80, 0xe3, 0x12, 0xd5, 0x4b,
  40211. 0xb9, 0xdf, 0xaf, 0x4e, 0x52, 0xad, 0x8e, 0x66, 0x87, 0xe5,
  40212. 0x2c, 0xd0, 0x45, 0x70, 0xd9, 0x78, 0x8f, 0x4b, 0xf4, 0xe1,
  40213. 0xf1, 0x22, 0xf2, 0xe3, 0xed, 0x1f, 0xeb, 0xe9, 0x70, 0x31,
  40214. 0x4c, 0x65, 0x5f, 0x55, 0xee, 0x5d, 0xaa, 0x83, 0x87, 0x76,
  40215. 0xbe, 0x11, 0xae, 0xd7, 0xf2, 0xfb, 0x43, 0xe7, 0x17, 0x81,
  40216. 0x33, 0x15, 0x47, 0xa0, 0xf3, 0x8e, 0x84, 0x57, 0xff, 0x35,
  40217. 0x9e, 0x4a, 0x8a, 0xab, 0x50, 0x3a, 0x45, 0xe0, 0xc3, 0x73,
  40218. 0xca, 0x77, 0x61, 0x68, 0x38, 0xd0, 0xa3, 0x5f, 0x03, 0x8d,
  40219. 0x41, 0xc2, 0xd3, 0x4a, 0x17, 0xe0, 0xa8, 0xaa, 0x00, 0xf3,
  40220. 0xf2, 0x5b, 0xa8, 0xe1, 0x06, 0xa6, 0x2b, 0xdb, 0xe1, 0x74,
  40221. 0xbd, 0xc4, 0xd2, 0x2b, 0x55, 0x9a, 0xb0, 0xf8, 0x35, 0xd8,
  40222. 0x6b, 0xec, 0xdb, 0xc5, 0xf4, 0x6c, 0x40, 0x90, 0x6a, 0x68,
  40223. 0xc9, 0xb5, 0xcb, 0xbb, 0xd0, 0xb0, 0xbc, 0x9f, 0xb9, 0xaa,
  40224. 0x50, 0x14, 0x93, 0x3b, 0x9f, 0x25, 0xcb, 0x40, 0xb8, 0x08,
  40225. 0xcc, 0x13, 0xe5, 0xdc, 0x3f, 0x84, 0x96, 0xe0, 0x73, 0x7b,
  40226. 0x7d, 0x9e, 0x41, 0x92, 0x5d, 0xcc, 0xa4, 0xea, 0x4f, 0x93,
  40227. 0x0c, 0x40, 0x2e, 0x42, 0x8a, 0xe9, 0xb9, 0x12, 0x74, 0xbb,
  40228. 0x79, 0x7c, 0xb0, 0x37, 0x20, 0xb6, 0xaf, 0x43, 0x3a, 0x88,
  40229. 0x59, 0x7c, 0x68, 0x28, 0x5f, 0x98, 0xc2, 0xf0, 0x2a, 0xbc,
  40230. 0xa1, 0x61, 0x88, 0x1f, 0x43, 0xbc, 0x42, 0x8f, 0x43, 0xf3,
  40231. 0x7e, 0x16, 0x96, 0xfa, 0x92, 0x70, 0xaf, 0x3c, 0x9f, 0x4b,
  40232. 0xd9, 0x60, 0xe9, 0xf6, 0x2e, 0x84, 0xda, 0x88, 0x31, 0x34,
  40233. 0xa6, 0x85, 0x10, 0x05, 0xef, 0x40, 0xa8, 0xa5, 0x4f, 0x92,
  40234. 0x59, 0xf7, 0xe0, 0xc4, 0x2b, 0x12, 0x17, 0x71, 0xbe, 0x8c,
  40235. 0x4a, 0x02, 0xfe, 0x12, 0xb6, 0x3b, 0x85, 0x75, 0x37, 0xf3,
  40236. 0x73, 0x2d, 0x9c, 0x00, 0x5d, 0x80, 0xad, 0x20, 0x2f, 0x5a,
  40237. 0x0b, 0x17, 0x7e, 0x67, 0x72, 0x24, 0x5a, 0xb9, 0xf3, 0xb1,
  40238. 0x33, 0xa4, 0x57, 0x1d, 0x49, 0x72, 0x2c, 0x7f, 0x47, 0x15,
  40239. 0x07, 0xe0, 0x45, 0x14, 0xdd, 0x77, 0x86, 0x6d, 0x03, 0xbe,
  40240. 0x57, 0xd0, 0xaa, 0x18, 0xa6, 0xdd, 0x94, 0x18, 0x3f, 0x8a,
  40241. 0xf3, 0xb5, 0xd7, 0x5a, 0xec, 0xc8, 0x79, 0x7f, 0x51, 0x61,
  40242. 0x3c, 0x9b, 0xb2, 0x9b, 0xf3, 0xb4, 0x35, 0xd1, 0x38, 0xbf,
  40243. 0x37, 0xce, 0x54, 0xd1, 0xf8, 0xb6, 0x45, 0xeb, 0x52, 0x0d,
  40244. 0x9a, 0x09, 0x58, 0x0d, 0x2c, 0x0b, 0xb1, 0xf2, 0x30, 0x3a,
  40245. 0x95, 0xc1, 0x13, 0x91, 0xd2, 0x9f, 0x8d, 0x8d, 0xd0, 0x38,
  40246. 0x3e, 0x4c, 0xae, 0x4a, 0x55, 0xa7, 0x42, 0x11, 0x83, 0xc4,
  40247. 0x70, 0xf0, 0x2b, 0x68, 0x9e, 0x07, 0xad, 0xb7, 0x83, 0xc6,
  40248. 0x53, 0x3c, 0xfb, 0x0a, 0x5d, 0x24, 0xdc, 0xe1, 0x55, 0x72,
  40249. 0xcf, 0xce, 0x3e, 0xc8, 0xd0, 0x57, 0x8a, 0x82, 0x5e, 0x78,
  40250. 0x2b, 0x80, 0xc5, 0xb9, 0x09, 0x46, 0xf8, 0x90, 0x39, 0x52,
  40251. 0xa9, 0xce, 0x3f, 0x3d, 0x41, 0x3b, 0x28, 0x45, 0xa3, 0xb3,
  40252. 0x21, 0xc2, 0xcd, 0x14, 0x49, 0x41, 0x6c, 0x38, 0xda, 0x1b,
  40253. 0x5f, 0x16, 0x49, 0xf9, 0x65, 0x00, 0x4e, 0xb4, 0x20, 0x55,
  40254. 0x70, 0xe8, 0x58, 0x1a, 0x18, 0xbf, 0x41, 0xef, 0x31, 0xb1,
  40255. 0xe7, 0x8d, 0x89, 0xc1, 0x48, 0xe8, 0xf5, 0x57, 0x35, 0xfa,
  40256. 0xc1, 0x79, 0xee, 0x2c, 0xe8, 0x7d, 0xb6, 0x03, 0xcc, 0x66,
  40257. 0x09, 0x6f, 0x52, 0x84, 0x0a, 0x34, 0x18, 0x2c, 0x01, 0x45,
  40258. 0x81, 0x00, 0xe5, 0x5e, 0x8d, 0xae, 0x1c, 0x96, 0x8b, 0x45,
  40259. 0x73, 0x00, 0x0a, 0xb5, 0xcf, 0x8d, 0x0e, 0x35, 0x5d, 0x1a,
  40260. 0x0e, 0xbf, 0x64, 0x9a, 0x52, 0x20, 0x48, 0xc6, 0xb9, 0x40,
  40261. 0xd3, 0x2c, 0x52, 0xca, 0x93, 0xcf, 0xbb, 0x94, 0x06, 0xf3,
  40262. 0x97, 0xee, 0xcc, 0x5d, 0xa3, 0xea, 0xf8, 0x5a, 0x39, 0x77,
  40263. 0x34, 0xd7, 0xf6, 0x4e, 0xbe, 0x8a, 0x07, 0x5f, 0x51, 0x53,
  40264. 0xc5, 0x1b, 0x8c, 0x47, 0x8f, 0x34, 0x0e, 0x60, 0x0a, 0x90,
  40265. 0xe2, 0xda, 0x7b, 0xef, 0xd6, 0xf5, 0x5d, 0xe5, 0x32, 0x37,
  40266. 0x75, 0x99, 0x81, 0x4a, 0x2a, 0x78, 0x71, 0xdc, 0xf4, 0xe5,
  40267. 0xca, 0xd8, 0x6b, 0x3b, 0x90, 0x68, 0x2e, 0x93, 0xc5, 0x10,
  40268. 0x42, 0x5d, 0x38, 0x90, 0x32, 0x46, 0xea, 0x87, 0xe0, 0xbc,
  40269. 0xb8, 0x9a, 0x18, 0x20, 0x68, 0x85, 0x6d, 0x9b, 0xc9, 0x8f,
  40270. 0x9b, 0xd2, 0xbe, 0x15, 0x12, 0x68, 0xd0, 0xb0, 0x16, 0x5f,
  40271. 0xe2, 0x69, 0x1d, 0x04, 0x00, 0xfc, 0x63, 0x33, 0xcd, 0x1f,
  40272. 0x89, 0xcd, 0x52, 0xff, 0xec, 0x19, 0x69, 0x74, 0xa3, 0xce,
  40273. 0x4d, 0xab, 0x93, 0xe4, 0xc6, 0x13, 0x56, 0x27, 0xc9, 0x25,
  40274. 0x5a, 0x01, 0xb2, 0x36, 0x8b, 0x61, 0xe5, 0x8b, 0x98, 0xac,
  40275. 0xe4, 0x2a, 0xb6, 0x40, 0x9f, 0x42, 0xe4, 0x1b, 0x52, 0xf7,
  40276. 0xfd, 0xd8, 0x30, 0x07, 0x33, 0xf9, 0x47, 0xcb, 0x3c, 0xad,
  40277. 0x12, 0xc1, 0xcc, 0x29, 0x62, 0x49, 0x04, 0x0c, 0x23, 0x97,
  40278. 0x5a, 0xa4, 0x84, 0x67, 0xde, 0x5a, 0xe5, 0x36, 0xd2, 0x88,
  40279. 0xf1, 0xd4, 0xeb, 0x13, 0x81, 0x54, 0x51, 0x11, 0xe3, 0xba,
  40280. 0xbc, 0xee, 0xdd, 0x6c, 0xcd, 0xe6, 0xb4, 0xa1, 0x8b, 0x0b,
  40281. 0x66, 0xfb, 0x8e, 0x50, 0xa0, 0xda, 0x69, 0x8d, 0xcc, 0x2d,
  40282. 0xe4, 0x2c, 0xc4, 0x37, 0xdf, 0x61, 0xc0, 0x03, 0xbd, 0x8b,
  40283. 0x28, 0xca, 0xd2, 0x8c, 0x1c, 0xf1, 0xa4, 0x26, 0x69, 0xe5,
  40284. 0xcf, 0x45, 0xdb, 0x5a, 0x47, 0x79, 0xed, 0x9f, 0xf7, 0xd2,
  40285. 0xdb, 0xba, 0x46, 0x53, 0x4f, 0xce, 0xa8, 0xbe, 0x8f, 0x4a,
  40286. 0xd6, 0xdf, 0x2e, 0x06, 0xe6, 0x4c, 0x9a, 0xc1, 0xb6, 0x49,
  40287. 0xed, 0xc4, 0xeb, 0xaa, 0xa4, 0x29, 0x6d, 0xd4, 0xcc, 0x8c,
  40288. 0xb6, 0x40, 0x11, 0x39, 0x69, 0xf7, 0x75, 0xcd, 0xb1, 0x99,
  40289. 0x46, 0x4e, 0xde, 0xcb, 0xf6, 0x9d, 0x32, 0xf3, 0xc9, 0x47,
  40290. 0x47, 0x7a, 0xcb, 0xfb, 0xa3, 0x0c, 0x3b, 0xdf, 0xb7, 0xde,
  40291. 0xec, 0x99, 0xde, 0xb0, 0x26, 0x04, 0x34, 0xae, 0x6b, 0xfc,
  40292. 0x99, 0xbc, 0xde, 0xd5, 0xbe, 0xe7, 0xeb, 0xf9, 0xe7, 0xa6,
  40293. 0x01, 0x9a, 0x0c, 0x5e, 0x66, 0xe6, 0x53, 0xe4, 0xd1, 0x58,
  40294. 0xac, 0xda, 0x69, 0x77, 0x7b, 0x68, 0xd6, 0x30, 0x2a, 0x9c,
  40295. 0x6b, 0xbe, 0x9f, 0x3d, 0x71, 0xd6, 0x54, 0xcd, 0x59, 0x4e,
  40296. 0x1f, 0xe3, 0x83, 0x4e, 0xd1, 0x8e, 0xaf, 0x97, 0xa8, 0xe5,
  40297. 0xb6, 0x59, 0x77, 0xa8, 0x02, 0x20, 0xe4, 0xeb, 0x44, 0x71,
  40298. 0xbc, 0x07, 0x14, 0x79, 0x4f, 0x0c, 0x27, 0x06, 0x39, 0xcf,
  40299. 0x7c, 0xef, 0x2b, 0x9b, 0x5e, 0xc4, 0x6d, 0x79, 0x13, 0x00,
  40300. 0x43, 0x6f, 0x51, 0x77, 0xb5, 0xc3, 0x72, 0xad, 0x13, 0xa9,
  40301. 0xe5, 0x9a, 0x5b, 0x1a, 0x99, 0x74, 0xc0, 0x7a, 0xf9, 0xc5,
  40302. 0xb0, 0x58, 0x35, 0x1c, 0xa5, 0x51, 0xdb, 0xa1, 0x14, 0xcd,
  40303. 0x26, 0x71, 0xb1, 0xe7, 0xaa, 0x14, 0xa7, 0x46, 0x93, 0xd3,
  40304. 0x5c, 0x8c, 0x1a, 0x91, 0x77, 0x46, 0x2e, 0x15, 0xaa, 0x9e,
  40305. 0xf7, 0x2b, 0x79, 0x41, 0x76, 0xf7, 0x22, 0x53, 0x7d, 0x51,
  40306. 0xdb, 0x98, 0x3d, 0x5b, 0x78, 0x5f, 0xc3, 0xc9, 0x29, 0xa3,
  40307. 0xff, 0x75, 0x82, 0x06, 0x9a, 0x16, 0x5e, 0xa4, 0x79, 0x0d,
  40308. 0xd1, 0x6d, 0x08, 0xff, 0x43, 0xef, 0x9c, 0xf3, 0x1b, 0x7a,
  40309. 0x3f, 0x34, 0xbe, 0x19, 0x15, 0x06, 0x33, 0xdb, 0xa5, 0x71,
  40310. 0xcb, 0x5f, 0x6b, 0x8d, 0xbd, 0x5b, 0x32, 0x91, 0xb2, 0x37,
  40311. 0x3d, 0xb4, 0x40, 0x9e, 0x02, 0x9b, 0xb7, 0x68, 0x20, 0x58,
  40312. 0x5c, 0xab, 0xcb, 0xc8, 0x23, 0x2d, 0x77, 0xcc, 0x0b, 0xf6,
  40313. 0x78, 0x6b, 0x80, 0x06, 0x91, 0xa9, 0xfd, 0x7e, 0xfa, 0x25,
  40314. 0x98, 0x9f, 0xcc, 0x79, 0x0a, 0x1a, 0x54, 0x83, 0xac, 0x64,
  40315. 0x16, 0x90, 0xe5, 0xd9, 0xa7, 0xd7, 0x1b, 0x86, 0x0d, 0xe6,
  40316. 0xe6, 0x22, 0x2b, 0x1f, 0x44, 0x49, 0x98, 0x9c, 0x51, 0x6f,
  40317. 0xcf, 0x58, 0x4a, 0xfa, 0xfa, 0x84, 0x12, 0xa5, 0x10, 0xf4,
  40318. 0xca, 0xf0, 0x98, 0x2b, 0xc9, 0x03, 0x71, 0x37, 0xe7, 0xdc,
  40319. 0xc2, 0xb1, 0x4e, 0x64, 0xde, 0x4f, 0x46, 0x0d, 0x6b, 0x25,
  40320. 0x88, 0x5d, 0xd6, 0xff, 0x23, 0x46, 0x57, 0x36, 0x14, 0x18,
  40321. 0xa7, 0xcb, 0xb8, 0xbd, 0xf0, 0xc5, 0x37, 0x36, 0xee, 0xe1,
  40322. 0xed, 0x9f, 0x4d, 0xd4, 0x39, 0xe5, 0x92, 0xcf, 0x95, 0x4d,
  40323. 0x66, 0x36, 0x5d, 0xd0, 0xcc, 0x07, 0xcf, 0x15, 0x5a, 0xce,
  40324. 0x14, 0xb8, 0xda, 0x0d, 0x3d, 0x1b, 0x45, 0xc5, 0x2e, 0x34,
  40325. 0x43, 0x25, 0x02, 0x3a, 0xcd, 0x14, 0x45, 0xfb, 0x3e, 0xf9,
  40326. 0x88, 0x5d, 0x0d, 0x29, 0x31, 0xb9, 0xa1, 0xe6, 0x31, 0x18,
  40327. 0x52, 0x46, 0x3f, 0x22, 0x4f, 0x9f, 0x7a, 0x65, 0x36, 0x88,
  40328. 0xa3, 0x1c, 0x3e, 0x6f, 0x50, 0x7a, 0x36, 0xbe, 0x56, 0x7e,
  40329. 0x50, 0xcb, 0x7a, 0x10, 0xa0, 0xec, 0xf6, 0x82, 0xd6, 0x30,
  40330. 0x1c, 0xe8, 0x4c, 0x50, 0xf9, 0x3e, 0xdb, 0xac, 0xbe, 0x4f,
  40331. 0x90, 0xb1, 0xd5, 0x1b, 0x12, 0x95, 0xfb, 0xe8, 0x08, 0x64,
  40332. 0x56, 0x7c, 0x96, 0xcc, 0x90, 0xb1, 0xbc, 0xa0, 0xf5, 0x32,
  40333. 0x69, 0xb3, 0x5f, 0x27, 0x0f, 0xbe, 0xc9, 0xbd, 0xeb, 0xfa,
  40334. 0x4b, 0x5c, 0xc5, 0x99, 0x9e, 0x5a, 0x04, 0xcc, 0xd0, 0x4d,
  40335. 0x29, 0xe8, 0x84, 0x55, 0x8c, 0xd7, 0xc4, 0x06, 0x13, 0x4d,
  40336. 0x92, 0xe5, 0x98, 0x9c, 0x4c, 0xc1, 0xf7, 0xaf, 0x7b, 0xd5,
  40337. 0x2b, 0x92, 0x68, 0x68, 0x19, 0x70, 0x4c, 0x9e, 0x46, 0xb8,
  40338. 0x34, 0xeb, 0x01, 0x47, 0xbe, 0x59, 0xab, 0x0b, 0x22, 0x25,
  40339. 0xe7, 0x56, 0xa8, 0xb4, 0x93, 0x3c, 0xd5, 0x98, 0x9f, 0x61,
  40340. 0x2e, 0xfa, 0xcb, 0x5f, 0x5b, 0xd8, 0x09, 0x83, 0xe9, 0x40,
  40341. 0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
  40342. 0x0a, 0x93
  40343. };
  40344. #endif
  40345. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_sig[] = {
  40346. 0x20, 0xff, 0x12, 0xe1, 0x87, 0xf6, 0x11, 0x38, 0xff, 0x41, 0xd0, 0x8f,
  40347. 0xcd, 0x7e, 0xd1, 0xf6, 0x21, 0x17, 0xd0, 0x46, 0xe9, 0x86, 0x83, 0x1b,
  40348. 0xaf, 0xe5, 0x2b, 0x59, 0x21, 0xd1, 0x6b, 0xc9, 0xdb, 0x34, 0xdc, 0xba,
  40349. 0xfd, 0xd3, 0xf8, 0x71, 0x49, 0xd8, 0x31, 0xbc, 0x48, 0x83, 0x22, 0x7b,
  40350. 0xfd, 0x6a, 0x93, 0xa6, 0x39, 0x4c, 0xda, 0xdb, 0x15, 0xe7, 0x41, 0x14,
  40351. 0xb4, 0xb8, 0xfe, 0xb0, 0x1f, 0xf9, 0x0a, 0x2c, 0x0b, 0xc0, 0xac, 0x09,
  40352. 0x84, 0x69, 0x5e, 0x64, 0x8c, 0xa8, 0xee, 0xa1, 0x52, 0x22, 0xde, 0x0d,
  40353. 0xc7, 0x25, 0xef, 0xa8, 0xfd, 0x8c, 0xb9, 0x45, 0x4f, 0xa4, 0x9c, 0xbc,
  40354. 0x70, 0xf2, 0x88, 0xea, 0x79, 0x13, 0xb0, 0xfc, 0xe6, 0x41, 0x48, 0x1c,
  40355. 0x33, 0x48, 0xa2, 0x77, 0x75, 0x37, 0x9f, 0xc1, 0x86, 0x94, 0xcd, 0x69,
  40356. 0x98, 0x87, 0x47, 0x49, 0x75, 0x93, 0xf1, 0xa4, 0x2d, 0x8e, 0xa8, 0x7e,
  40357. 0x0f, 0x95, 0xf5, 0x3e, 0x5d, 0x31, 0x2d, 0xc9, 0x58, 0x1c, 0x42, 0xfd,
  40358. 0x79, 0x6a, 0x49, 0xa3, 0x84, 0xc5, 0x2e, 0x8d, 0x96, 0x9c, 0xc8, 0x05,
  40359. 0x93, 0xdb, 0x6d, 0xbf, 0x83, 0x34, 0xc2, 0x81, 0x47, 0x90, 0xc9, 0xa9,
  40360. 0x82, 0xbd, 0xe1, 0xc8, 0x89, 0xa2, 0x36, 0x47, 0xed, 0xfb, 0x47, 0x57,
  40361. 0x01, 0x1a, 0x75, 0x8c, 0x6b, 0x83, 0xcf, 0x56, 0xae, 0x52, 0x66, 0x8b,
  40362. 0xab, 0x7f, 0x0c, 0xec, 0xde, 0x5c, 0x13, 0xbe, 0xbd, 0x5b, 0x74, 0x28,
  40363. 0xb5, 0xd7, 0x68, 0xd5, 0xd2, 0xe9, 0x96, 0x3b, 0x55, 0xda, 0x3a, 0x93,
  40364. 0x3c, 0xd9, 0x9f, 0x53, 0x2a, 0x31, 0x84, 0x45, 0x3f, 0xee, 0x2b, 0xfc,
  40365. 0x92, 0xb0, 0x9c, 0xc6, 0x16, 0x16, 0x4f, 0x33, 0x41, 0x17, 0x58, 0xbe,
  40366. 0x5d, 0x57, 0x4b, 0x04, 0x82, 0xe3, 0xb3, 0x68, 0xdf, 0x7c, 0x93, 0xce,
  40367. 0x9d, 0xf6, 0x7e, 0x21, 0x3d, 0x28, 0x1c, 0xf0, 0x37, 0x46, 0xf2, 0xc2,
  40368. 0x73, 0x7c, 0xbe, 0x98, 0x0e, 0x09, 0x75, 0xa7, 0x21, 0x11, 0xa9, 0xd6,
  40369. 0xd1, 0x47, 0xac, 0xd0, 0x19, 0x48, 0x3b, 0x74, 0xc1, 0x3c, 0x37, 0x43,
  40370. 0x49, 0x12, 0x62, 0xee, 0xaf, 0x5c, 0x38, 0xf7, 0x8a, 0xce, 0xb3, 0x7a,
  40371. 0x05, 0x16, 0xd4, 0x71, 0x8b, 0xbe, 0x1a, 0xe0, 0x1e, 0xbc, 0x4b, 0x54,
  40372. 0x0f, 0xb5, 0x73, 0x2b, 0xb8, 0x3a, 0x75, 0xf0, 0x26, 0xcd, 0xf9, 0xca,
  40373. 0x32, 0xf9, 0x7e, 0x15, 0x38, 0x75, 0x9c, 0x4d, 0xbc, 0x11, 0xf8, 0xea,
  40374. 0x8e, 0xe8, 0x38, 0x17, 0xc5, 0x62, 0xf4, 0x34, 0xfb, 0xd6, 0xf5, 0x76,
  40375. 0xfc, 0xa3, 0xf3, 0x44, 0xf9, 0xab, 0x2e, 0x9a, 0x68, 0xcd, 0xa1, 0x29,
  40376. 0xff, 0xda, 0xe8, 0xb5, 0xb0, 0x20, 0x5d, 0x02, 0x01, 0x62, 0x26, 0x44,
  40377. 0x32, 0xc8, 0x94, 0xf8, 0xf1, 0xaa, 0xf9, 0xc2, 0x86, 0xcb, 0x55, 0x7f,
  40378. 0x8d, 0xb3, 0xf6, 0x63, 0xb1, 0xa4, 0x95, 0x57, 0xb8, 0x1d, 0xc3, 0x42,
  40379. 0xd2, 0x4b, 0x69, 0xcd, 0x7a, 0x10, 0x5b, 0x6a, 0x13, 0xd1, 0x02, 0x98,
  40380. 0x38, 0x87, 0x9b, 0x9a, 0x5a, 0x66, 0x73, 0xcb, 0x75, 0xd0, 0x7a, 0x4b,
  40381. 0xad, 0x23, 0x06, 0x1c, 0xc8, 0x6b, 0x0c, 0xa8, 0xfe, 0x7b, 0x8f, 0x65,
  40382. 0x50, 0xd7, 0xf7, 0x76, 0x88, 0x42, 0xe0, 0x5e, 0x18, 0x91, 0x8b, 0x99,
  40383. 0x37, 0x56, 0x08, 0x91, 0xe7, 0x01, 0xe7, 0x05, 0xd5, 0xed, 0x43, 0x25,
  40384. 0x71, 0x7e, 0x3e, 0xfc, 0xc4, 0xfd, 0xed, 0x8b, 0x85, 0x16, 0x8c, 0xe3,
  40385. 0x05, 0xee, 0x51, 0x02, 0xa4, 0x4b, 0xd8, 0x3c, 0xcf, 0x4d, 0x2f, 0x2d,
  40386. 0x68, 0x6e, 0xc1, 0xd5, 0xfa, 0x91, 0xfd, 0x6a, 0xe0, 0x64, 0x85, 0x35,
  40387. 0x9c, 0x75, 0xe6, 0x0d, 0xb8, 0xec, 0x97, 0x88, 0x62, 0x98, 0x78, 0x75,
  40388. 0xc7, 0x1e, 0x68, 0xa7, 0xb9, 0x7b, 0xab, 0x75, 0x7a, 0x72, 0x3c, 0x7b,
  40389. 0xab, 0x60, 0x03, 0xb7, 0x38, 0x13, 0xe4, 0x96, 0x6e, 0xcb, 0x95, 0xcc,
  40390. 0xdc, 0x6a, 0x47, 0x67, 0x77, 0xd7, 0x95, 0xc4, 0x87, 0x66, 0xc2, 0x7e,
  40391. 0x42, 0x90, 0x59, 0x4f, 0xd6, 0xf3, 0xf4, 0xa7, 0xd0, 0x29, 0xf9, 0x5d,
  40392. 0x4b, 0x06, 0x06, 0xf7, 0x6e, 0xb2, 0xab, 0xb0, 0x8e, 0x21, 0xa6, 0xff,
  40393. 0x5e, 0x7b, 0x47, 0xb6, 0x3a, 0xa6, 0x9e, 0x19, 0xf6, 0xdf, 0x9b, 0x3b,
  40394. 0x3d, 0x07, 0x37, 0xd1, 0x0b, 0xa8, 0xf3, 0x9c, 0x43, 0x89, 0xee, 0xba,
  40395. 0x03, 0xee, 0x38, 0x74, 0x13, 0x09, 0x8e, 0x47, 0x4e, 0xa9, 0x14, 0xf5,
  40396. 0xb0, 0x55, 0xe0, 0x03, 0xe5, 0xb9, 0x53, 0xef, 0x03, 0x15, 0x60, 0xb3,
  40397. 0x4a, 0x71, 0x31, 0x4b, 0xf1, 0xc8, 0xe4, 0x63, 0x9b, 0x8b, 0x78, 0x3c,
  40398. 0x1f, 0xac, 0x27, 0x20, 0xa8, 0x53, 0x7d, 0xdd, 0x72, 0xd3, 0x90, 0x8f,
  40399. 0x71, 0xa6, 0xa7, 0xeb, 0xb0, 0xeb, 0x42, 0x96, 0xa4, 0xc3, 0xba, 0xc6,
  40400. 0x3c, 0xe7, 0x7b, 0x15, 0x1e, 0xfa, 0x15, 0x23, 0x37, 0xf3, 0xc8, 0xb2,
  40401. 0xf9, 0x46, 0x04, 0xd1, 0x5e, 0x44, 0xd7, 0x8f, 0x70, 0xb1, 0x0a, 0xde,
  40402. 0x6a, 0xe3, 0xaf, 0x9e, 0x49, 0x55, 0x78, 0x79, 0x11, 0x22, 0x87, 0xa9,
  40403. 0x54, 0x7c, 0xb4, 0x83, 0xe1, 0x25, 0xcd, 0x89, 0xa6, 0x91, 0x21, 0x7b,
  40404. 0xbe, 0x3d, 0x2f, 0x46, 0xb5, 0x5b, 0x50, 0x1a, 0xc8, 0x8d, 0x32, 0xf3,
  40405. 0x62, 0x1f, 0x24, 0x64, 0xe8, 0xb6, 0x02, 0x4f, 0x1f, 0x52, 0x3c, 0x40,
  40406. 0xfc, 0x72, 0x38, 0xd4, 0xba, 0x40, 0x8e, 0xb7, 0xc0, 0x97, 0x06, 0x16,
  40407. 0xd5, 0xe3, 0x39, 0x45, 0xd7, 0x7c, 0x0e, 0xed, 0x6b, 0x19, 0x19, 0x0a,
  40408. 0x8e, 0xcb, 0x2b, 0xee, 0x4d, 0xa1, 0x5e, 0x84, 0x22, 0x66, 0xcd, 0x4f,
  40409. 0xb9, 0x1a, 0x25, 0x85, 0x02, 0xc0, 0x67, 0xc4, 0xd5, 0x1a, 0xcb, 0xbb,
  40410. 0xde, 0x4d, 0x3c, 0x3c, 0x62, 0x9f, 0x76, 0x8f, 0x15, 0x29, 0xa5, 0xbb,
  40411. 0x5a, 0x48, 0x38, 0x66, 0xfa, 0x56, 0x0a, 0x09, 0xbd, 0xdf, 0xdf, 0x4a,
  40412. 0xe7, 0x0e, 0xa6, 0xb1, 0xb5, 0x7c, 0xe1, 0xed, 0x8d, 0x63, 0x07, 0x42,
  40413. 0xf3, 0xf8, 0x15, 0x28, 0x7c, 0x09, 0xf5, 0x02, 0x69, 0x1b, 0x88, 0x1e,
  40414. 0x3d, 0xad, 0x5f, 0x46, 0xed, 0xab, 0x2b, 0x11, 0x96, 0x73, 0xa8, 0xe8,
  40415. 0xe6, 0x64, 0x7d, 0xae, 0x13, 0xa1, 0x7d, 0x54, 0xae, 0xc0, 0x82, 0xeb,
  40416. 0x2a, 0xd1, 0x76, 0xb7, 0x9f, 0xbd, 0x33, 0x8f, 0xe7, 0xe6, 0x79, 0x92,
  40417. 0xa6, 0xaf, 0x61, 0x91, 0x49, 0xbc, 0xd2, 0x3c, 0x6f, 0x8b, 0xbe, 0x8f,
  40418. 0x5f, 0x1f, 0x00, 0x2c, 0x2e, 0x2c, 0xa0, 0x14, 0xcf, 0x34, 0x42, 0x44,
  40419. 0x41, 0x11, 0xd7, 0x37, 0xd3, 0x99, 0x44, 0x36, 0x43, 0x03, 0xb9, 0x50,
  40420. 0x4f, 0xab, 0xfe, 0x48, 0xe2, 0x4b, 0xed, 0x51, 0x8b, 0xe0, 0x04, 0x3c,
  40421. 0x93, 0x28, 0x55, 0xc8, 0x5a, 0xb3, 0x52, 0x2c, 0x56, 0xbd, 0x43, 0xb9,
  40422. 0x4a, 0x6c, 0x4c, 0xcc, 0xda, 0xba, 0x9c, 0xe6, 0x3e, 0x50, 0x8b, 0x1a,
  40423. 0xe5, 0x83, 0xc1, 0x60, 0x55, 0xb2, 0x02, 0x16, 0x54, 0x33, 0x62, 0x69,
  40424. 0x7c, 0x7d, 0x94, 0xf2, 0xb0, 0x3a, 0x22, 0xf0, 0x21, 0x46, 0xd7, 0x94,
  40425. 0x53, 0xec, 0x63, 0x4c, 0x3e, 0xc3, 0x71, 0xd1, 0xb9, 0x2e, 0x16, 0xe8,
  40426. 0x17, 0x63, 0x7e, 0x0c, 0x83, 0x05, 0x72, 0xe6, 0x20, 0x60, 0x34, 0xae,
  40427. 0x0e, 0x54, 0xa0, 0x57, 0x75, 0x93, 0x2e, 0xb8, 0x6c, 0xec, 0xda, 0x44,
  40428. 0x1b, 0xac, 0xd6, 0x75, 0xc5, 0x79, 0x3c, 0xc2, 0xa6, 0xa2, 0x7f, 0x3a,
  40429. 0xb0, 0xec, 0xeb, 0xc1, 0xe6, 0xd6, 0xae, 0xac, 0x2e, 0x55, 0x30, 0x1c,
  40430. 0x81, 0xa4, 0x4c, 0x35, 0x0e, 0xd8, 0xa6, 0x4e, 0xea, 0x0e, 0xbf, 0x79,
  40431. 0xf7, 0xdf, 0x55, 0xfc, 0xf9, 0x24, 0xb0, 0xa6, 0xba, 0xc3, 0x72, 0x42,
  40432. 0x60, 0x06, 0x44, 0x03, 0xe3, 0x40, 0x3c, 0x2a, 0x13, 0xf7, 0xdf, 0x3d,
  40433. 0xb7, 0x0d, 0x86, 0x6c, 0xb0, 0x0f, 0x2e, 0x72, 0x91, 0x16, 0x4f, 0x5f,
  40434. 0xd0, 0x3e, 0x8c, 0x36, 0xed, 0xa8, 0x6f, 0xbc, 0x65, 0xb0, 0x65, 0x99,
  40435. 0x47, 0x50, 0xa5, 0x9c, 0xea, 0xee, 0x8a, 0x44, 0x70, 0xf5, 0x31, 0x1a,
  40436. 0xe9, 0x11, 0xc1, 0xce, 0xe0, 0x21, 0x52, 0x70, 0x89, 0xf7, 0xc3, 0x35,
  40437. 0xfa, 0x55, 0x5a, 0xc5, 0x10, 0x02, 0xc4, 0xc7, 0xf7, 0xe1, 0xaf, 0x49,
  40438. 0x48, 0x61, 0xe7, 0x0d, 0xa1, 0x2d, 0x7d, 0x03, 0x00, 0x38, 0xa7, 0xd5,
  40439. 0xd3, 0xbf, 0x95, 0x29, 0xed, 0xcc, 0x70, 0x3e, 0xbe, 0x95, 0x8a, 0xdf,
  40440. 0xaf, 0xbf, 0xec, 0xf8, 0x6a, 0x4f, 0x9e, 0x69, 0xee, 0x4e, 0x3d, 0x8b,
  40441. 0x58, 0xa0, 0x2e, 0xb5, 0x83, 0x6a, 0x0e, 0x04, 0xa4, 0xa9, 0x74, 0xcb,
  40442. 0x4f, 0xb0, 0x39, 0x37, 0x8f, 0xcf, 0xbf, 0x77, 0xe4, 0x1a, 0x74, 0xcf,
  40443. 0x0e, 0x0d, 0x2d, 0x6e, 0x1d, 0xba, 0xc1, 0xf5, 0x7c, 0x54, 0x6e, 0x92,
  40444. 0xec, 0x4b, 0x03, 0xc3, 0xa4, 0x44, 0xad, 0x3e, 0x4f, 0xa4, 0xd9, 0xe9,
  40445. 0x71, 0x3c, 0xe6, 0xb6, 0xbe, 0xe7, 0xfc, 0x72, 0x76, 0x86, 0x9a, 0x73,
  40446. 0xb1, 0xb3, 0xf3, 0x84, 0xb6, 0x2a, 0x40, 0x0b, 0x8c, 0xae, 0xb3, 0xc4,
  40447. 0xdc, 0xb5, 0x21, 0x85, 0x87, 0xdc, 0x19, 0x18, 0xd5, 0xba, 0xa4, 0x5e,
  40448. 0x88, 0x89, 0xa4, 0xf4, 0x88, 0x75, 0xc2, 0x7a, 0xb4, 0xee, 0x9d, 0x54,
  40449. 0x66, 0x97, 0x70, 0x08, 0x8f, 0x99, 0x84, 0x5d, 0x5e, 0xa7, 0x6f, 0x92,
  40450. 0xe8, 0xa3, 0x65, 0xfa, 0x0e, 0x87, 0xfb, 0x3c, 0xe9, 0x17, 0x2d, 0xc7,
  40451. 0x2d, 0x30, 0x8f, 0x41, 0x82, 0x68, 0x2b, 0xf1, 0x67, 0x8e, 0xf7, 0x05,
  40452. 0x78, 0xfa, 0xc3, 0x61, 0xba, 0x35, 0xe7, 0x2f, 0x19, 0xef, 0x71, 0x36,
  40453. 0xac, 0x5b, 0xf0, 0x45, 0x30, 0x70, 0xdc, 0xc7, 0xab, 0x7b, 0x62, 0x17,
  40454. 0x9d, 0xc4, 0x43, 0x6f, 0xfc, 0x02, 0x56, 0x5f, 0x65, 0xaa, 0x68, 0x3b,
  40455. 0x5c, 0xfa, 0x71, 0x28, 0x89, 0xe9, 0x28, 0x2f, 0x95, 0x4b, 0xfc, 0xe6,
  40456. 0xe7, 0xc8, 0x44, 0x28, 0x5c, 0x3c, 0x08, 0x5f, 0x9c, 0xbc, 0x41, 0x68,
  40457. 0x91, 0x98, 0x7a, 0x00, 0x63, 0xc9, 0x5c, 0x75, 0x8f, 0xcc, 0x33, 0x77,
  40458. 0x7b, 0xd0, 0x2d, 0xe8, 0xa2, 0x98, 0xa4, 0x1b, 0xfa, 0x09, 0x67, 0x7b,
  40459. 0x25, 0x96, 0x19, 0xf4, 0x77, 0x33, 0x20, 0x4f, 0x19, 0xf6, 0x9c, 0x6c,
  40460. 0x2e, 0xd9, 0x68, 0x95, 0xb0, 0xe2, 0x18, 0x06, 0xe5, 0x84, 0x8e, 0xf7,
  40461. 0xbf, 0x6c, 0x96, 0xa8, 0x9d, 0x37, 0xc7, 0x28, 0xa1, 0x3d, 0x90, 0x8c,
  40462. 0x40, 0x3d, 0xe2, 0x51, 0xfd, 0x55, 0x09, 0xf8, 0x83, 0x43, 0x44, 0x4d,
  40463. 0x1c, 0x8a, 0x8d, 0x36, 0x84, 0x64, 0xc4, 0xfa, 0x1d, 0x72, 0x04, 0x0b,
  40464. 0x1d, 0x49, 0x13, 0x88, 0x78, 0x5f, 0x07, 0x9b, 0xc8, 0x01, 0x9c, 0x3c,
  40465. 0xfc, 0xff, 0x0f, 0xd5, 0x13, 0xcd, 0x15, 0x98, 0xcc, 0xe6, 0x59, 0x1e,
  40466. 0x83, 0x38, 0x8f, 0x6c, 0x75, 0xbe, 0xdf, 0xe9, 0x1b, 0xc5, 0xb9, 0x6b,
  40467. 0xa4, 0x5a, 0x0c, 0xae, 0x98, 0x8d, 0x93, 0xfa, 0x76, 0x7f, 0x0d, 0x0b,
  40468. 0xe8, 0xa0, 0x3b, 0x9e, 0x5e, 0xc8, 0xa8, 0xcc, 0x02, 0xc9, 0x86, 0x9c,
  40469. 0x78, 0xaf, 0x6e, 0x6a, 0xf4, 0xfe, 0x49, 0xad, 0xc5, 0x93, 0xae, 0x62,
  40470. 0xbd, 0xe3, 0x3a, 0xa8, 0xf2, 0x60, 0xb5, 0x29, 0xde, 0x5f, 0x12, 0x02,
  40471. 0x2d, 0x43, 0x90, 0xf5, 0x9d, 0x9d, 0x97, 0x29, 0xfa, 0xdd, 0x60, 0x41,
  40472. 0x64, 0xb7, 0xa5, 0x03, 0x72, 0x10, 0x2b, 0xdd, 0x5b, 0x60, 0xe6, 0xf0,
  40473. 0xe1, 0xd7, 0xa5, 0x97, 0xec, 0xb4, 0x9a, 0x4c, 0x3e, 0x16, 0xa2, 0x82,
  40474. 0xb3, 0xc3, 0x3f, 0x3e, 0x5d, 0x32, 0xac, 0x5a, 0x40, 0xb4, 0x00, 0xfa,
  40475. 0xd9, 0x47, 0xe8, 0x77, 0xa8, 0x96, 0x5c, 0x60, 0x04, 0x9c, 0x5c, 0xdf,
  40476. 0x24, 0x3b, 0xa7, 0x4a, 0x58, 0x25, 0x12, 0x9a, 0xa8, 0x7b, 0x3e, 0x14,
  40477. 0xc8, 0x06, 0x79, 0x23, 0xea, 0x91, 0x7f, 0xe1, 0x78, 0x41, 0x6c, 0xdb,
  40478. 0x8c, 0xeb, 0x66, 0x35, 0x87, 0x87, 0x81, 0x65, 0x2c, 0xef, 0x3a, 0x6e,
  40479. 0xae, 0xb3, 0x6c, 0xe9, 0x86, 0x50, 0x6d, 0x89, 0xd6, 0x27, 0x0a, 0xdb,
  40480. 0xf8, 0xd4, 0xb8, 0x85, 0x8e, 0x37, 0xa6, 0x56, 0xf7, 0x58, 0x18, 0x4c,
  40481. 0x44, 0xcf, 0xeb, 0xc4, 0x79, 0x19, 0xfc, 0x2e, 0x53, 0x18, 0x0e, 0x7b,
  40482. 0x51, 0x86, 0xf3, 0x59, 0x13, 0xb2, 0xaf, 0xd3, 0xee, 0xf4, 0xd5, 0xbf,
  40483. 0x2c, 0xb8, 0x6d, 0x71, 0x74, 0x7c, 0x67, 0x54, 0xa7, 0x4b, 0x03, 0xa9,
  40484. 0x1b, 0x62, 0x95, 0x9f, 0xc3, 0xf0, 0x71, 0x39, 0x2d, 0x26, 0xaf, 0xaf,
  40485. 0xa7, 0xa5, 0x58, 0xf8, 0xf8, 0x8a, 0xe0, 0x62, 0x90, 0x3f, 0x72, 0x9d,
  40486. 0x21, 0x82, 0x76, 0x3e, 0x4c, 0x5d, 0xe0, 0xb5, 0x67, 0x23, 0xe3, 0x13,
  40487. 0x1a, 0x29, 0xa3, 0xda, 0xa4, 0xb4, 0x5c, 0x1d, 0x47, 0xdf, 0xdf, 0xc9,
  40488. 0x93, 0x6c, 0xb2, 0xb5, 0x22, 0xb3, 0x47, 0x2b, 0xcf, 0xf0, 0x36, 0x87,
  40489. 0x51, 0x3c, 0x79, 0x41, 0x70, 0xbd, 0xea, 0x70, 0xa2, 0x29, 0x90, 0x55,
  40490. 0x30, 0x6f, 0x3e, 0x50, 0xc8, 0x38, 0xd6, 0xfa, 0x6f, 0xe3, 0x39, 0x67,
  40491. 0x88, 0x52, 0x1f, 0xd3, 0x52, 0xbf, 0x3e, 0x7b, 0x2a, 0xe5, 0x1e, 0xcd,
  40492. 0xf9, 0xf1, 0x91, 0x1d, 0x04, 0x61, 0x25, 0xbb, 0xe1, 0x33, 0xe3, 0x66,
  40493. 0x46, 0xed, 0x06, 0x8d, 0xc3, 0x4f, 0x20, 0xc6, 0x24, 0xa7, 0xb5, 0x49,
  40494. 0x3b, 0xc7, 0xe6, 0xa0, 0x77, 0x58, 0xd9, 0x70, 0xb1, 0xf5, 0xec, 0x94,
  40495. 0x19, 0xf3, 0x5b, 0x0f, 0x9a, 0xe4, 0xad, 0x37, 0x81, 0xaf, 0x68, 0x7b,
  40496. 0xe5, 0x67, 0xb5, 0xae, 0x7f, 0x2d, 0x64, 0x78, 0x68, 0x5a, 0xd1, 0x8f,
  40497. 0x1c, 0xc0, 0xc3, 0x5b, 0x21, 0x77, 0xe4, 0xa8, 0x5d, 0x05, 0x50, 0xc1,
  40498. 0x92, 0xee, 0x36, 0x2d, 0xd2, 0xff, 0xee, 0xc2, 0x11, 0x99, 0xee, 0xd7,
  40499. 0x48, 0xfb, 0x6a, 0xa3, 0xc9, 0xb7, 0x0c, 0xc1, 0xe5, 0x12, 0xbf, 0x6f,
  40500. 0x58, 0x66, 0x35, 0x34, 0x26, 0xaa, 0xbe, 0xc3, 0x33, 0x86, 0xfd, 0xc0,
  40501. 0x1c, 0xa5, 0xe4, 0x1e, 0x91, 0xc4, 0x55, 0x4e, 0xf1, 0xcb, 0xd2, 0x0b,
  40502. 0xe8, 0x0d, 0x89, 0x6a, 0x00, 0xbd, 0x7b, 0xf5, 0x3d, 0x1a, 0x4a, 0x48,
  40503. 0xfc, 0xf0, 0x5b, 0xcd, 0xdb, 0xb2, 0xa0, 0x27, 0x4b, 0x8f, 0xf7, 0x87,
  40504. 0x78, 0x13, 0xdb, 0x3f, 0xfb, 0x0b, 0xda, 0x22, 0xb3, 0x2b, 0x3a, 0x38,
  40505. 0xd2, 0x29, 0x73, 0x77, 0xb8, 0xd6, 0xec, 0xab, 0xb4, 0xfe, 0xbe, 0xbb,
  40506. 0x6e, 0xe2, 0xc8, 0x45, 0x7b, 0x0d, 0x36, 0x28, 0x0f, 0x45, 0x72, 0xea,
  40507. 0x6d, 0x38, 0x02, 0x5e, 0x48, 0x89, 0x12, 0x24, 0x1b, 0x33, 0x0f, 0xe9,
  40508. 0xf4, 0xce, 0xf8, 0x27, 0x16, 0x37, 0x29, 0xae, 0xe8, 0x22, 0x03, 0x31,
  40509. 0xa9, 0xa0, 0x73, 0x0c, 0x40, 0xe4, 0xfc, 0x6b, 0xe2, 0x1c, 0x8d, 0x7c,
  40510. 0x40, 0x82, 0x72, 0x28, 0xd0, 0x7d, 0xe5, 0xef, 0x05, 0x14, 0x80, 0x28,
  40511. 0x11, 0x32, 0x0d, 0x63, 0x8a, 0xc3, 0x7c, 0xfe, 0xf5, 0x06, 0x0e, 0xb0,
  40512. 0x78, 0x5c, 0x3a, 0xb6, 0x54, 0x37, 0x46, 0xa7, 0x43, 0x4f, 0x05, 0xec,
  40513. 0xe4, 0x9f, 0xd8, 0x55, 0x1f, 0x70, 0xb3, 0xe6, 0xbc, 0x46, 0x34, 0x9e,
  40514. 0xfc, 0xa4, 0x57, 0x8f, 0x0f, 0x25, 0x6f, 0x9f, 0xb3, 0x80, 0x21, 0x0b,
  40515. 0xa1, 0xca, 0x59, 0xcd, 0x37, 0xf7, 0xc9, 0xcb, 0xbe, 0x91, 0xad, 0x07,
  40516. 0x4f, 0xc7, 0x4e, 0x04, 0xbd, 0x38, 0x8b, 0x63, 0xb5, 0x51, 0xac, 0xc8,
  40517. 0x83, 0x3a, 0xa7, 0xe1, 0x77, 0xbc, 0xa4, 0x0c, 0x6c, 0x50, 0xeb, 0x46,
  40518. 0xe1, 0x45, 0x9a, 0x7b, 0x01, 0xca, 0x54, 0xf0, 0x0f, 0xa0, 0x1f, 0x43,
  40519. 0x9a, 0x19, 0x70, 0x2e, 0x70, 0x5a, 0xcf, 0x3b, 0x1b, 0x41, 0xfd, 0xd3,
  40520. 0x9a, 0xa2, 0x36, 0x14, 0xf0, 0xdd, 0xb0, 0x12, 0x6d, 0xcf, 0x55, 0x3f,
  40521. 0xef, 0x0a, 0xc1, 0x80, 0xa9, 0x68, 0xc3, 0x98, 0x03, 0x46, 0x34, 0xce,
  40522. 0x91, 0xb2, 0x7a, 0x94, 0xd2, 0xe7, 0xb9, 0x9c, 0x56, 0xb8, 0xf8, 0xd6,
  40523. 0xff, 0xbf, 0x8b, 0x39, 0x45, 0x04, 0x45, 0xc9, 0xa2, 0xe2, 0xbb, 0x50,
  40524. 0x68, 0x13, 0x32, 0x1e, 0x09, 0x51, 0xb7, 0xb9, 0xcf, 0x5f, 0xcc, 0x54,
  40525. 0xd2, 0xf3, 0xc1, 0x9d, 0xa0, 0x8d, 0x22, 0xc8, 0x7e, 0x1b, 0xc6, 0x14,
  40526. 0xde, 0x5f, 0x52, 0xb4, 0x69, 0x71, 0xca, 0x58, 0x1d, 0x1e, 0x89, 0xcb,
  40527. 0x56, 0x78, 0x7a, 0x85, 0xee, 0xfd, 0xf6, 0x7e, 0xbe, 0x49, 0x9b, 0xb1,
  40528. 0x05, 0x95, 0x12, 0xe9, 0x63, 0xbd, 0x61, 0x9a, 0x26, 0xf9, 0x0b, 0x9f,
  40529. 0x23, 0x0a, 0x59, 0x55, 0x93, 0xd3, 0x2d, 0xca, 0x66, 0x45, 0x03, 0xb7,
  40530. 0xf0, 0x88, 0x9e, 0xc1, 0x11, 0xbb, 0x62, 0x2c, 0x6f, 0xac, 0x3e, 0x87,
  40531. 0xd7, 0xe6, 0x4a, 0x44, 0x83, 0x04, 0x5d, 0x5d, 0xbc, 0x3c, 0xce, 0x83,
  40532. 0x2b, 0x11, 0x42, 0x02, 0x73, 0x1c, 0x24, 0x90, 0xd9, 0x1a, 0x7d, 0x96,
  40533. 0x82, 0x33, 0x75, 0x1e, 0x59, 0xea, 0xa7, 0x99, 0xe1, 0x5b, 0xdc, 0xe4,
  40534. 0x07, 0xc5, 0x48, 0x07, 0xb4, 0xbc, 0x80, 0x0e, 0xbd, 0x63, 0x6e, 0x66,
  40535. 0xf1, 0x12, 0xb6, 0x67, 0xe0, 0x14, 0x74, 0x9f, 0xbb, 0xb3, 0xb8, 0x16,
  40536. 0xd0, 0x25, 0xe9, 0x21, 0x80, 0x1a, 0x32, 0xb0, 0x58, 0x9a, 0x62, 0x17,
  40537. 0x18, 0x9d, 0x64, 0x2d, 0x47, 0x89, 0x82, 0x3b, 0x8c, 0x5d, 0x60, 0xc4,
  40538. 0x54, 0x69, 0xaa, 0xb4, 0x6a, 0x1d, 0x16, 0xb0, 0xe2, 0x5d, 0x7d, 0xeb,
  40539. 0xb9, 0x80, 0x37, 0xcd, 0x5b, 0xf0, 0xa1, 0xa8, 0x39, 0xb2, 0xd6, 0x3a,
  40540. 0xc8, 0xcd, 0xca, 0xaf, 0xcb, 0x3b, 0x54, 0xc2, 0x67, 0x49, 0xf3, 0xf1,
  40541. 0x11, 0x4d, 0x53, 0x7c, 0x46, 0x8d, 0x22, 0xf6, 0x9a, 0x0d, 0x9e, 0xda,
  40542. 0x37, 0xc6, 0x06, 0x00, 0xca, 0xb6, 0xb6, 0x99, 0xc5, 0xb6, 0x81, 0x7e,
  40543. 0x87, 0x62, 0xcf, 0x07, 0x76, 0xc1, 0x5f, 0xfe, 0x86, 0xfc, 0x5b, 0xa0,
  40544. 0xac, 0xca, 0xcb, 0x7d, 0xf5, 0x5a, 0xc2, 0x5e, 0x41, 0x48, 0x35, 0xc4,
  40545. 0x71, 0x9d, 0xc4, 0x0a, 0x79, 0x6f, 0xe3, 0x6d, 0x47, 0xd4, 0xaa, 0xfd,
  40546. 0x97, 0xe7, 0xb0, 0x7e, 0x61, 0xf1, 0x7d, 0x7e, 0xf8, 0x78, 0x4c, 0x2e,
  40547. 0x65, 0x51, 0xeb, 0x99, 0xd0, 0x3e, 0x24, 0x4c, 0xe0, 0x40, 0x7e, 0x2d,
  40548. 0xf7, 0x00, 0x9d, 0x50, 0x87, 0xce, 0x1f, 0x9a, 0xd2, 0x76, 0x00, 0x09,
  40549. 0xeb, 0x10, 0x1b, 0x4c, 0xf1, 0x43, 0x0e, 0x35, 0xbb, 0x23, 0x2e, 0x26,
  40550. 0x3d, 0x66, 0xa3, 0x0f, 0xf6, 0x10, 0x8b, 0x67, 0xce, 0x66, 0xfd, 0xb5,
  40551. 0x07, 0xdc, 0x04, 0x69, 0xad, 0xe0, 0x4d, 0xdf, 0xdb, 0x2f, 0x87, 0xf7,
  40552. 0xde, 0xc3, 0x77, 0x89, 0x71, 0xfd, 0x70, 0x38, 0xed, 0xe6, 0x27, 0xb1,
  40553. 0xbd, 0x94, 0x5f, 0x39, 0x20, 0x72, 0x59, 0xc4, 0x39, 0xd0, 0x20, 0x5d,
  40554. 0xe2, 0xe7, 0xe0, 0x00, 0x61, 0xc7, 0x65, 0xbd, 0xef, 0x05, 0xb3, 0xc7,
  40555. 0x7e, 0xae, 0xc5, 0x83, 0x7f, 0xc1, 0x32, 0x4e, 0x2a, 0x17, 0x64, 0x4e,
  40556. 0x2a, 0x9a, 0x2d, 0x26, 0x99, 0xa2, 0xd7, 0x37, 0x3a, 0x10, 0x6a, 0x89,
  40557. 0x72, 0x43, 0x0e, 0x3a, 0x03, 0x4c, 0xf9, 0xfe, 0xe8, 0xfc, 0x87, 0x71,
  40558. 0x37, 0x71, 0x5a, 0x05, 0xbc, 0x4e, 0x20, 0x4c, 0xd7, 0xf9, 0x8d, 0x4e,
  40559. 0xb8, 0xb8, 0x56, 0x07, 0xc8, 0x6e, 0x34, 0x6d, 0x45, 0x83, 0x34, 0xf0,
  40560. 0x77, 0xfb, 0x18, 0xec, 0x72, 0xf6, 0x4c, 0xfb, 0xba, 0x84, 0xe9, 0x89,
  40561. 0x3d, 0xfd, 0xb7, 0x0d, 0x70, 0xae, 0xa4, 0x48, 0x6b, 0x39, 0xf8, 0x62,
  40562. 0xc0, 0x7f, 0x0c, 0xf2, 0xa3, 0xfa, 0x7a, 0x64, 0x83, 0x57, 0x7d, 0x4c,
  40563. 0x04, 0x96, 0xd7, 0x9d, 0x10, 0x8b, 0x34, 0x48, 0x17, 0xff, 0x74, 0x5c,
  40564. 0x9c, 0xbe, 0xeb, 0xe5, 0x52, 0x94, 0x6a, 0x34, 0x6f, 0xf7, 0x95, 0x32,
  40565. 0x38, 0x5a, 0x9b, 0x08, 0xf6, 0xda, 0x8c, 0x0f, 0x9c, 0x5d, 0x04, 0x45,
  40566. 0xd4, 0xe9, 0xa4, 0x7a, 0xc4, 0xfd, 0x70, 0xfe, 0xa1, 0x3d, 0x21, 0xa0,
  40567. 0x01, 0xe5, 0x21, 0xca, 0xa7, 0xd9, 0xf1, 0x9f, 0x45, 0xe1, 0xe8, 0x2d,
  40568. 0x27, 0xe6, 0x87, 0xc8, 0x0d, 0xad, 0x13, 0xdb, 0xfe, 0x2f, 0xaa, 0x2b,
  40569. 0xdc, 0xa6, 0x1a, 0xc9, 0x19, 0x78, 0x1a, 0x1f, 0x10, 0xcf, 0x31, 0xe1,
  40570. 0x06, 0x28, 0x66, 0xb3, 0xa7, 0xa2, 0xa6, 0xf1, 0x3b, 0x2d, 0xd3, 0x81,
  40571. 0xaf, 0x6f, 0xc9, 0x88, 0x76, 0xe9, 0x83, 0x6c, 0x52, 0xb9, 0x70, 0x51,
  40572. 0x87, 0x6b, 0x8b, 0xbd, 0x5b, 0x9c, 0xa9, 0xf3, 0xcb, 0x55, 0xd1, 0x76,
  40573. 0x40, 0xe1, 0x90, 0xb9, 0x4c, 0xbd, 0xab, 0x1d, 0xa0, 0x5b, 0x5b, 0x34,
  40574. 0x14, 0x2f, 0x87, 0x8f, 0x63, 0xa0, 0x2d, 0x29, 0x4e, 0x50, 0x4b, 0x18,
  40575. 0x5f, 0x86, 0xac, 0x1b, 0x93, 0xe9, 0x59, 0x38, 0xa1, 0x2a, 0x36, 0x21,
  40576. 0xb2, 0xa4, 0xc0, 0x79, 0xc1, 0x60, 0xfc, 0x0f, 0xbf, 0x99, 0x04, 0x9d,
  40577. 0x4b, 0x17, 0x60, 0x5b, 0xcd, 0x78, 0x03, 0xd7, 0x7c, 0x4b, 0x9b, 0x17,
  40578. 0x58, 0x24, 0x60, 0xb8, 0x08, 0x92, 0x48, 0x4f, 0x66, 0x42, 0x9a, 0x98,
  40579. 0x2a, 0x99, 0x9a, 0x8f, 0xdd, 0xd7, 0x09, 0xf3, 0x22, 0x66, 0x62, 0xef,
  40580. 0xe5, 0x64, 0xd3, 0xdf, 0x31, 0xaa, 0x84, 0x4c, 0xa5, 0x3f, 0x4e, 0x27,
  40581. 0x48, 0x37, 0x96, 0x63, 0xbf, 0x8d, 0xe1, 0xf0, 0xd1, 0xef, 0x95, 0x1a,
  40582. 0xe6, 0xf4, 0x02, 0x61, 0xbf, 0xe3, 0xbc, 0x8b, 0x3d, 0x0b, 0x77, 0x91,
  40583. 0xc0, 0x5d, 0xfb, 0xe6, 0x7e, 0xab, 0x5e, 0xc5, 0x1c, 0x5b, 0x16, 0xfd,
  40584. 0x88, 0xa4, 0x78, 0x4c, 0x06, 0x77, 0xc3, 0x6e, 0x84, 0x0c, 0xda, 0xbf,
  40585. 0xf3, 0x8e, 0xd3, 0x61, 0x65, 0xac, 0xf2, 0x18, 0x70, 0x68, 0x84, 0x6f,
  40586. 0x9f, 0x3a, 0x94, 0x81, 0xa6, 0xc7, 0xc3, 0x92, 0xee, 0x4b, 0x20, 0x15,
  40587. 0x4e, 0x03, 0x76, 0x51, 0x5b, 0x4e, 0xe1, 0x5c, 0x51, 0x5e, 0x1b, 0x9c,
  40588. 0x30, 0x25, 0x79, 0xdd, 0x70, 0x12, 0xec, 0xdc, 0x45, 0x95, 0x45, 0x43,
  40589. 0xcd, 0xbb, 0xae, 0xa0, 0x0d, 0x43, 0xb4, 0xc9, 0x8c, 0x62, 0xfd, 0x7b,
  40590. 0xed, 0x50, 0x78, 0xb7, 0xa6, 0x94, 0xcb, 0x98, 0xb0, 0xbe, 0x09, 0xd9,
  40591. 0x0c, 0xb2, 0xc4, 0x8b, 0x96, 0x93, 0xd9, 0x26, 0xc6, 0x6d, 0x26, 0x93,
  40592. 0x32, 0x4e, 0x86, 0x72, 0x74, 0x92, 0x00, 0x72, 0x0b, 0x20, 0xa3, 0x2b,
  40593. 0x94, 0xe6, 0x10, 0x56, 0x5a, 0x41, 0x71, 0x92, 0x08, 0xce, 0x6c, 0xc4,
  40594. 0x1d, 0x9e, 0x71, 0x82, 0x64, 0x23, 0xe5, 0x15, 0xef, 0x4a, 0x7c, 0x4d,
  40595. 0xe3, 0x92, 0xbc, 0xa3, 0xa2, 0x29, 0xb7, 0x46, 0xfa, 0x8f, 0x9f, 0xc2,
  40596. 0x5d, 0xe4, 0xc0, 0x9c, 0x3f, 0x40, 0x17, 0xae, 0x44, 0xf3, 0x28, 0x10,
  40597. 0x29, 0x24, 0xa9, 0x1c, 0x9e, 0xd2, 0x55, 0x4c, 0xee, 0x45, 0xfe, 0x4a,
  40598. 0x45, 0x12, 0xf5, 0xde, 0xc7, 0x64, 0x15, 0xc3, 0x4a, 0x77, 0x63, 0x05,
  40599. 0x8d, 0xa6, 0x31, 0xa0, 0xad, 0x64, 0xaf, 0x3c, 0x69, 0x2c, 0x25, 0x78,
  40600. 0xae, 0xa0, 0x88, 0x96, 0x8a, 0xc2, 0x9b, 0x8d, 0xee, 0x6f, 0x2e, 0x79,
  40601. 0x1f, 0xec, 0x32, 0x35, 0x75, 0x83, 0x19, 0x8b, 0xda, 0xca, 0xd0, 0xaf,
  40602. 0x6a, 0x6c, 0x42, 0xe8, 0x81, 0xb5, 0x69, 0x31, 0x0b, 0x7d, 0xbc, 0xd8,
  40603. 0xd2, 0xb7, 0x7a, 0x8f, 0xfa, 0xcf, 0x91, 0x07, 0x1f, 0xda, 0xa9, 0x1f,
  40604. 0xb7, 0x2d, 0xff, 0x50, 0x15, 0x2a, 0xef, 0x8c, 0xa1, 0xe3, 0x7f, 0x08,
  40605. 0x95, 0xf2, 0x99, 0x83, 0x1f, 0x97, 0x71, 0x3e, 0x35, 0x3c, 0x8c, 0xe7,
  40606. 0x08, 0xd8, 0xa6, 0x1f, 0x0c, 0xa6, 0x52, 0xdc, 0x73, 0xa0, 0xfc, 0xd2,
  40607. 0x73, 0xe9, 0x27, 0x9d, 0xfd, 0x7a, 0x4a, 0x29, 0xd3, 0x12, 0x26, 0x13,
  40608. 0x0f, 0xce, 0xea, 0x56, 0x99, 0x61, 0x78, 0x47, 0x2c, 0xa0, 0x16, 0xa0,
  40609. 0xe2, 0x64, 0x97, 0x57, 0x31, 0xf0, 0x32, 0x5b, 0x44, 0x93, 0x76, 0x8b,
  40610. 0x59, 0x63, 0x5c, 0x5b, 0x0f, 0xe1, 0xe7, 0x74, 0x98, 0x11, 0x2d, 0x90,
  40611. 0xe4, 0xde, 0xd4, 0x3a, 0xc2, 0xfd, 0x24, 0xe3, 0x1f, 0x7a, 0xf4, 0x40,
  40612. 0xbb, 0x51, 0x92, 0x8f, 0x68, 0x9c, 0x51, 0xab, 0xdc, 0xf6, 0x1e, 0x96,
  40613. 0xca, 0x56, 0x5c, 0x92, 0xca, 0xb2, 0x1b, 0x2e, 0x6d, 0x20, 0x28, 0xb3,
  40614. 0x0a, 0x8e, 0xfd, 0xa9, 0xa2, 0x38, 0x74, 0x60, 0x37, 0xa6, 0x96, 0x02,
  40615. 0x20, 0x8a, 0x9a, 0x2b, 0x8c, 0xb9, 0x6d, 0xec, 0xff, 0xbf, 0x88, 0xbd,
  40616. 0x6c, 0xb4, 0x10, 0xbd, 0xfa, 0x5a, 0xeb, 0xb2, 0x6b, 0x74, 0x13, 0x2d,
  40617. 0xa5, 0xdb, 0x60, 0x93, 0xc6, 0xed, 0x39, 0x4f, 0xc5, 0x63, 0xe1, 0x9e,
  40618. 0x57, 0x1f, 0xe7, 0x47, 0xa4, 0xfb, 0x7f, 0xfa, 0x3a, 0x46, 0x50, 0x3a,
  40619. 0xd8, 0xd3, 0x83, 0xf5, 0xe6, 0x5e, 0xf8, 0x09, 0x0d, 0xfa, 0x33, 0xe1,
  40620. 0x50, 0xe4, 0x36, 0x3e, 0x0a, 0x5d, 0xe6, 0xf8, 0x2e, 0x17, 0x87, 0x8f,
  40621. 0xe1, 0x8c, 0x82, 0x73, 0xbd, 0xdd, 0x3b, 0x77, 0x47, 0x9f, 0x42, 0xd7,
  40622. 0xf4, 0x2d, 0x6c, 0xef, 0xcc, 0x22, 0x15, 0x3c, 0xe9, 0x26, 0xea, 0xbc,
  40623. 0xee, 0x09, 0xd3, 0xea, 0x84, 0x0f, 0x46, 0xa8, 0xe0, 0xda, 0xc5, 0x57,
  40624. 0x02, 0x54, 0xb6, 0x88, 0x2b, 0x37, 0xe5, 0x96, 0xc5, 0x33, 0xb7, 0x45,
  40625. 0x5d, 0xb7, 0xc7, 0xfd, 0xa0, 0xfa, 0x85, 0x1b, 0x2f, 0xe1, 0xec, 0x89,
  40626. 0xc6, 0xb2, 0x51, 0x71, 0xcb, 0x08, 0x82, 0x3e, 0xc9, 0xed, 0x80, 0x9d,
  40627. 0x37, 0x31, 0x9d, 0x15, 0xde, 0x24, 0x6f, 0xbd, 0x0e, 0x73, 0xa2, 0xb8,
  40628. 0x7e, 0x29, 0x7e, 0x96, 0xe4, 0xbb, 0xd6, 0x23, 0x17, 0xff, 0x33, 0x97,
  40629. 0x9c, 0x87, 0xe0, 0xe5, 0x0f, 0xb9, 0xb6, 0x31, 0x33, 0xad, 0xf8, 0xd8,
  40630. 0xdb, 0xa0, 0x71, 0x13, 0xe4, 0x1c, 0xce, 0xd0, 0x7e, 0x65, 0x7b, 0xa0,
  40631. 0x38, 0x17, 0x53, 0x4f, 0x71, 0x75, 0x6d, 0x02, 0x61, 0xc4, 0x52, 0xf8,
  40632. 0xe4, 0x2e, 0xbc, 0x52, 0xc1, 0xb1, 0x7e, 0x83, 0x0a, 0xa1, 0xd1, 0xcd,
  40633. 0x2f, 0xa0, 0x30, 0xfd, 0x41, 0x86, 0x7f, 0x26, 0xd1, 0xe7, 0xfc, 0xd7,
  40634. 0xc7, 0x37, 0xe5, 0x11, 0xa6, 0xc0, 0x9a, 0x75, 0x18, 0x04, 0x36, 0xca,
  40635. 0x8e, 0x26, 0x7d, 0xcf, 0xa2, 0x6a, 0x94, 0x9b, 0xc4, 0xf7, 0xc7, 0xeb,
  40636. 0x51, 0x13, 0xa3, 0x6f, 0x8c, 0x80, 0x5f, 0xae, 0xf0, 0x18, 0xa0, 0x88,
  40637. 0xe0, 0x8d, 0xb7, 0x80, 0x4e, 0x8c, 0xec, 0xc8, 0x7b, 0xeb, 0xac, 0x29,
  40638. 0xb7, 0x4a, 0x0f, 0x33, 0xdd, 0x9d, 0x89, 0x0a, 0x10, 0xb0, 0xce, 0x74,
  40639. 0x59, 0xa2, 0x62, 0x91, 0xc9, 0xac, 0x56, 0xcd, 0x69, 0xd3, 0x01, 0x6d,
  40640. 0x51, 0xe7, 0x04, 0xc3, 0xfb, 0xe9, 0x79, 0x1b, 0x72, 0x72, 0x1a, 0x90,
  40641. 0x0a, 0x20, 0x55, 0x85, 0xc1, 0x8b, 0xeb, 0x1e, 0x9f, 0x9f, 0x4a, 0x81,
  40642. 0x47, 0x97, 0x96, 0xbc, 0xc2, 0xe4, 0xc2, 0xfe, 0xa0, 0x20, 0xda, 0x70,
  40643. 0x0c, 0x2b, 0xe2, 0xd4, 0xc8, 0xcb, 0x46, 0x00, 0xb6, 0x7c, 0xfb, 0xbd,
  40644. 0x56, 0x94, 0x3d, 0x7f, 0x64, 0xf7, 0x88, 0xb5, 0xa7, 0xfe, 0xbe, 0x64,
  40645. 0x8a, 0xe4, 0x00, 0x08, 0x82, 0x5b, 0x8f, 0x98, 0x77, 0x87, 0xda, 0xaf,
  40646. 0x16, 0x25, 0x4a, 0x9a, 0xed, 0xfb, 0x50, 0x18, 0x45, 0x46, 0x2b, 0x73,
  40647. 0xff, 0xb9, 0xb9, 0xab, 0xa2, 0x8f, 0x3a, 0xaf, 0xc5, 0x0a, 0x14, 0x91,
  40648. 0xb2, 0x3f, 0xa6, 0x93, 0xf4, 0x81, 0x20, 0x77, 0xfa, 0x51, 0x79, 0x62,
  40649. 0xe8, 0xe6, 0x89, 0x52, 0x39, 0xd5, 0x01, 0xa2, 0x87, 0xa3, 0x53, 0x74,
  40650. 0x3c, 0x36, 0x8a, 0xc3, 0xb4, 0x44, 0x3b, 0x15, 0x21, 0xf6, 0xdc, 0x18,
  40651. 0x02, 0xd2, 0x57, 0xe5, 0x10, 0xf0, 0x3d, 0x61, 0xa7, 0x16, 0x85, 0x6f,
  40652. 0x71, 0x07, 0x75, 0x50, 0x4b, 0x21, 0x53, 0x47, 0x38, 0x35, 0x9e, 0xa7,
  40653. 0xd8, 0xfd, 0x74, 0x59, 0x15, 0x32, 0x7b, 0x89, 0xd0, 0x2c, 0xd9, 0xf6,
  40654. 0x40, 0x49, 0x79, 0xdc, 0xfb, 0x0a, 0x64, 0x59, 0x9b, 0x17, 0x47, 0x36,
  40655. 0xcb, 0xf0, 0xc3, 0xcc, 0x14, 0x8e, 0x1f, 0xa8, 0x12, 0xaa, 0xb7, 0x6a,
  40656. 0xba, 0x45, 0xf9, 0xc4, 0x44, 0xe7, 0xb5, 0x7c, 0xdd, 0xbe, 0x16, 0x76,
  40657. 0x52, 0x92, 0x3d, 0x78, 0xb7, 0xec, 0x81, 0x96, 0xd8, 0x7f, 0x34, 0x2a,
  40658. 0xa2, 0x64, 0x5f, 0xfd, 0xb1, 0x42, 0x4c, 0x79, 0x98, 0xc9, 0x17, 0x48,
  40659. 0x74, 0x12, 0x72, 0x2c, 0xde, 0x91, 0x7e, 0xa9, 0x49, 0x2a, 0xcc, 0x5c,
  40660. 0x60, 0x05, 0x25, 0x09, 0x72, 0x20, 0x80, 0x42, 0x7b, 0x18, 0xc2, 0xfc,
  40661. 0x2a, 0x5e, 0x3e, 0x2d, 0x61, 0xa6, 0xf6, 0x82, 0x42, 0x83, 0x81, 0x66,
  40662. 0x4d, 0xa6, 0xe1, 0xf9, 0xf6, 0x48, 0xd4, 0xc8, 0x69, 0xed, 0xee, 0xb5,
  40663. 0x7a, 0xcb, 0xf6, 0x0a, 0x76, 0x0e, 0x61, 0x8b, 0xf2, 0x1a, 0x8a, 0xa7,
  40664. 0x88, 0xb0, 0x90, 0xd5, 0x23, 0xaa, 0xe0, 0x2b, 0xd6, 0xd0, 0xef, 0x49,
  40665. 0x13, 0x88, 0xc7, 0x50, 0xf0, 0x9e, 0xd5, 0x28, 0xe1, 0xaa, 0x1d, 0xaf,
  40666. 0xd9, 0x73, 0xb3, 0x9e, 0xa7, 0xd8, 0xfc, 0xb9, 0x22, 0x97, 0x0e, 0x21,
  40667. 0xa0, 0xb9, 0xf9, 0xea, 0x1e, 0x95, 0x88, 0xda, 0x85, 0x7c, 0x32, 0x7c,
  40668. 0xbd, 0xef, 0xf8, 0x44, 0x25, 0x5f, 0x23, 0xfd, 0x14, 0x78, 0xc6, 0xdb,
  40669. 0x86, 0xee, 0xf8, 0xda, 0xc0, 0xae, 0x92, 0x6a, 0x03, 0xa9, 0x0a, 0xee,
  40670. 0x4a, 0x22, 0x5a, 0x6c, 0x39, 0xd3, 0x91, 0x7d, 0x91, 0x43, 0xac, 0x79,
  40671. 0xad, 0xab, 0xb7, 0x91, 0xb1, 0x20, 0x84, 0x7f, 0x0a, 0xd7, 0xa8, 0x62,
  40672. 0x95, 0xab, 0x04, 0xb6, 0xb2, 0xf1, 0xd4, 0xb0, 0xac, 0x52, 0x89, 0xb0,
  40673. 0x93, 0xdf, 0xdf, 0x80, 0x26, 0x0c, 0x32, 0x31, 0xb3, 0xba, 0xa1, 0xba,
  40674. 0x6f, 0xa3, 0x14, 0x5c, 0xfa, 0x37, 0x3b, 0x6a, 0xf2, 0xc4, 0x34, 0x27,
  40675. 0x08, 0x1a, 0xe4, 0xfc, 0x89, 0x58, 0x79, 0x34, 0x36, 0xe4, 0xad, 0x4b,
  40676. 0x3f, 0x57, 0x7b, 0xc1, 0x59, 0x2d, 0xb6, 0x54, 0x44, 0xbe, 0x4e, 0x5d,
  40677. 0x0d, 0x6a, 0xf3, 0xcd, 0xbf, 0xcd, 0x4d, 0x9f, 0x9a, 0x50, 0x09, 0xa4,
  40678. 0x6b, 0x8b, 0xb3, 0x01, 0x69, 0x6c, 0x69, 0x5d, 0x28, 0x73, 0x9e, 0xb5,
  40679. 0xc2, 0xc7, 0x6e, 0xff, 0x4c, 0x5c, 0x6b, 0x93, 0x22, 0xc1, 0x9f, 0xa6,
  40680. 0x71, 0xbf, 0x4d, 0x2d, 0x4e, 0x4e, 0x98, 0xa3, 0x6d, 0xab, 0x05, 0xa0,
  40681. 0xde, 0x34, 0x41, 0x28, 0xa4, 0x38, 0x75, 0x4e, 0xdf, 0x7f, 0xc9, 0xdd,
  40682. 0xbf, 0x5a, 0xd4, 0xcd, 0x38, 0x0c, 0x89, 0xe7, 0x0e, 0xfc, 0x0f, 0x27,
  40683. 0x39, 0x21, 0xa4, 0xa6, 0x07, 0x7b, 0x2a, 0x13, 0x56, 0xe7, 0x4e, 0x55,
  40684. 0x57, 0x71, 0x98, 0xb9, 0x3d, 0x59, 0xb5, 0xa8, 0x24, 0x18, 0x08, 0xa2,
  40685. 0x6e, 0x9a, 0xe5, 0x97, 0xa7, 0x38, 0xd9, 0x43, 0x9b, 0x19, 0x17, 0x34,
  40686. 0x03, 0xd6, 0xba, 0xe9, 0x71, 0x38, 0x26, 0x90, 0x78, 0x9e, 0x1c, 0x41,
  40687. 0x8d, 0x60, 0xdd, 0x0e, 0x12, 0x46, 0x37, 0xb4, 0x79, 0x87, 0x33, 0x12,
  40688. 0x24, 0xc4, 0x5a, 0x6c, 0x70, 0xa2, 0xb2, 0x58, 0xbb, 0xe7, 0xd6, 0x88,
  40689. 0x42, 0x2d, 0x49, 0xc8, 0x67, 0x1e, 0xc5, 0xed, 0x16, 0xa8, 0x1f, 0x36,
  40690. 0x2b, 0xfb, 0x0d, 0x51, 0x96, 0xc8, 0x78, 0xf2, 0xab, 0x82, 0xa1, 0xe2,
  40691. 0xaf, 0x8c, 0xa4, 0x13, 0x54, 0x90, 0xf1, 0xe7, 0xbb, 0xd1, 0x09, 0x23,
  40692. 0x76, 0x0e, 0x50, 0x32, 0xc5, 0x54, 0xbb, 0x1e, 0x12, 0x5d, 0x59, 0xf3,
  40693. 0xe9, 0xc9, 0xa4, 0xaa, 0xbc, 0x13, 0x1d, 0xf0, 0x79, 0x54, 0xae, 0x70,
  40694. 0xc0, 0xea, 0xcb, 0x21, 0x32, 0xe6, 0xe6, 0x8e, 0xaa, 0x51, 0x46, 0x25,
  40695. 0x1e, 0xf1, 0x3f, 0x9f, 0xf6, 0xff, 0x19, 0x53, 0x97, 0xbc, 0xa2, 0xb6,
  40696. 0x91, 0x59, 0x27, 0x1e, 0x39, 0x76, 0x76, 0x02, 0x0b, 0x03, 0x25, 0x6b,
  40697. 0x00, 0x02, 0xfa, 0x7d, 0x69, 0x5e, 0xde, 0x64, 0x33, 0xbf, 0xab, 0x3e,
  40698. 0x3f, 0x24, 0x32, 0x68, 0xbf, 0x90, 0x8f, 0x0f, 0xc5, 0x36, 0x58, 0x9e,
  40699. 0x9b, 0x11, 0xd1, 0x2a, 0x8a, 0x0d, 0xac, 0x3a, 0x23, 0xe2, 0x8e, 0xd6,
  40700. 0x0d, 0x4a, 0x8b, 0x45, 0x04, 0x47, 0xd9, 0x5a, 0x46, 0x6c, 0x70, 0x82,
  40701. 0xc7, 0x81, 0x67, 0xdc, 0xa6, 0xfa, 0x6a, 0x86, 0xfd, 0x01, 0xed, 0x90,
  40702. 0xf6, 0xe6, 0x26, 0x6d, 0xac, 0x52, 0x03, 0x4a, 0x91, 0x08, 0x7b, 0xa5,
  40703. 0x9c, 0xca, 0xd3, 0x2d, 0x79, 0xf1, 0xed, 0xcb, 0xaa, 0x8f, 0x77, 0xc8,
  40704. 0x17, 0xa8, 0xfb, 0x6c, 0x15, 0x62, 0xab, 0x34, 0xd1, 0xdd, 0x94, 0x3e,
  40705. 0xd4, 0x0c, 0x47, 0xed, 0x04, 0x91, 0xd2, 0xd7, 0x98, 0xb4, 0x43, 0x57,
  40706. 0xd1, 0x54, 0xef, 0x63, 0xba, 0xe3, 0x8a, 0x72, 0xc5, 0xb9, 0xf4, 0x30,
  40707. 0xfa, 0x16, 0x3c, 0xe1, 0xbb, 0xbe, 0x57, 0x90, 0xb9, 0xa1, 0xa0, 0x23,
  40708. 0xfa, 0xdd, 0xbe, 0x2f, 0xb3, 0xec, 0x41, 0x8b, 0x64, 0xeb, 0xc5, 0x41,
  40709. 0xea, 0xa8, 0x16, 0x76, 0x6f, 0x28, 0xda, 0x2b, 0x5f, 0x03, 0x0b, 0xe8,
  40710. 0x1c, 0x29, 0x71, 0xd8, 0x4e, 0x41, 0xdf, 0x39, 0x8e, 0x6a, 0x95, 0x79,
  40711. 0x85, 0x9c, 0xa9, 0x79, 0xd9, 0x8f, 0x33, 0xaf, 0x15, 0x3b, 0x5a, 0x82,
  40712. 0x56, 0x32, 0x98, 0x0c, 0xf6, 0xf6, 0x64, 0x42, 0xd4, 0x6a, 0x15, 0x0f,
  40713. 0xb9, 0x75, 0x22, 0xbd, 0x9a, 0x58, 0xa6, 0x01, 0x3a, 0x63, 0xf0, 0x80,
  40714. 0x78, 0x22, 0x80, 0xa0, 0x14, 0xe1, 0x37, 0x6b, 0xd4, 0x99, 0x3f, 0xc2,
  40715. 0xba, 0x2b, 0x8f, 0xf3, 0x56, 0xc8, 0x1b, 0xe4, 0x7a, 0x5e, 0x96, 0x60,
  40716. 0xee, 0x74, 0x54, 0xb6, 0x6d, 0x5c, 0x3d, 0x3e, 0x05, 0xf0, 0x9a, 0xf6,
  40717. 0xcd, 0xdd, 0x06, 0xdb, 0x8c, 0x21, 0xb9, 0xf5, 0x28, 0x57, 0x9c, 0x4f,
  40718. 0xb4, 0x08, 0xcf, 0xac, 0x6c, 0xfe, 0x30, 0xaf, 0xa2, 0xef, 0xcf, 0x93,
  40719. 0x15, 0xdd, 0x12, 0x16, 0x19, 0x7d, 0xbc, 0x57, 0xd9, 0xce, 0xbe, 0x0e,
  40720. 0xfc, 0xe1, 0xf0, 0x4a, 0x7c, 0xaa, 0xbf, 0x20, 0x64, 0x00, 0x34, 0x59,
  40721. 0xed, 0xea, 0x12, 0x58, 0x46, 0x4c, 0xc6, 0x2f, 0x77, 0x62, 0x1d, 0x82,
  40722. 0x5c, 0xe8, 0x98, 0x0d, 0xef, 0x5c, 0x0e, 0xec, 0x5d, 0x2e, 0x5f, 0xd2,
  40723. 0x22, 0x43, 0x2d, 0xe1, 0x02, 0xd5, 0x4a, 0x0a, 0x79, 0x6f, 0xa5, 0xec,
  40724. 0x48, 0xaa, 0xee, 0xf8, 0xe3, 0x5f, 0xdd, 0xe7, 0x26, 0x87, 0xb5, 0xc4,
  40725. 0xcf, 0xd9, 0x7f, 0xa8, 0xaa, 0xb6, 0xbe, 0xe9, 0x02, 0x49, 0x5d, 0x5f,
  40726. 0x81, 0x8b, 0xb9, 0xbd, 0xc0, 0xc9, 0xd5, 0xfe, 0x36, 0x3e, 0x49, 0x56,
  40727. 0x63, 0x8b, 0xce, 0xef, 0x48, 0x6e, 0xc0, 0xd4, 0x04, 0x0c, 0x33, 0x45,
  40728. 0x6e, 0x97, 0x9e, 0xa3, 0xae, 0xbc, 0xc2, 0xce, 0xdc, 0xe3, 0xff, 0x48,
  40729. 0x51, 0x68, 0x89, 0xad, 0xae, 0xc7, 0xd1, 0xde, 0xe2, 0xf9, 0xfe, 0x00,
  40730. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40731. 0x0c, 0x18, 0x20, 0x24, 0x2f, 0x33, 0x3f
  40732. };
  40733. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40734. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_sig[] = {
  40735. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  40736. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  40737. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  40738. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  40739. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  40740. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  40741. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  40742. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  40743. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  40744. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  40745. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  40746. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  40747. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  40748. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  40749. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  40750. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  40751. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  40752. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  40753. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  40754. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  40755. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  40756. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  40757. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  40758. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  40759. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  40760. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  40761. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  40762. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  40763. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  40764. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  40765. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  40766. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  40767. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  40768. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  40769. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  40770. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  40771. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  40772. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  40773. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  40774. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  40775. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  40776. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  40777. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  40778. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  40779. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  40780. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  40781. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  40782. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  40783. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  40784. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  40785. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  40786. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  40787. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  40788. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  40789. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  40790. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  40791. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  40792. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  40793. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  40794. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  40795. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  40796. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  40797. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  40798. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  40799. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  40800. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  40801. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  40802. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  40803. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  40804. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  40805. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  40806. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  40807. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  40808. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  40809. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  40810. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  40811. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  40812. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  40813. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  40814. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  40815. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  40816. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  40817. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  40818. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  40819. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  40820. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  40821. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  40822. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  40823. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  40824. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  40825. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  40826. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  40827. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  40828. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  40829. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  40830. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  40831. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  40832. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  40833. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  40834. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  40835. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  40836. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  40837. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  40838. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  40839. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  40840. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  40841. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  40842. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  40843. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  40844. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  40845. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  40846. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  40847. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  40848. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  40849. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  40850. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  40851. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  40852. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  40853. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  40854. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  40855. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  40856. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  40857. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  40858. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  40859. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  40860. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  40861. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  40862. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  40863. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  40864. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  40865. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  40866. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  40867. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  40868. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  40869. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  40870. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  40871. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  40872. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  40873. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  40874. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  40875. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  40876. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  40877. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  40878. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  40879. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  40880. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  40881. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  40882. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  40883. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  40884. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  40885. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  40886. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  40887. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  40888. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  40889. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  40890. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  40891. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  40892. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  40893. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  40894. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  40895. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  40896. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  40897. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  40898. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  40899. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  40900. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  40901. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  40902. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  40903. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  40904. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  40905. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  40906. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  40907. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  40908. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  40909. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  40910. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  40911. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  40912. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  40913. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  40914. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  40915. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  40916. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  40917. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  40918. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  40919. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  40920. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  40921. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  40922. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  40923. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  40924. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  40925. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  40926. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  40927. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  40928. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  40929. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  40930. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  40931. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  40932. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  40933. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  40934. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  40935. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  40936. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  40937. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  40938. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  40939. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  40940. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  40941. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  40942. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  40943. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  40944. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  40945. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  40946. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  40947. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  40948. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  40949. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  40950. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  40951. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  40952. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  40953. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  40954. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  40955. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  40956. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  40957. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  40958. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  40959. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  40960. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  40961. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  40962. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  40963. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  40964. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  40965. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  40966. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  40967. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  40968. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  40969. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  40970. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  40971. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  40972. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  40973. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  40974. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  40975. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  40976. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  40977. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  40978. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  40979. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  40980. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  40981. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  40982. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  40983. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  40984. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  40985. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  40986. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  40987. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  40988. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  40989. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  40990. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  40991. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  40992. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  40993. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  40994. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  40995. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  40996. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  40997. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  40998. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  40999. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  41000. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  41001. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  41002. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  41003. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  41004. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  41005. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  41006. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  41007. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  41008. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  41009. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  41010. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  41011. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  41012. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  41013. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  41014. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  41015. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  41016. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  41017. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  41018. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  41019. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  41020. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  41021. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  41022. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  41023. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  41024. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  41025. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  41026. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  41027. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  41028. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  41029. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  41030. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  41031. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  41032. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  41033. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  41034. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  41035. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  41036. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  41037. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  41038. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  41039. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  41040. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  41041. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  41042. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  41043. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  41044. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  41045. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  41046. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  41047. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  41048. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  41049. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  41050. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  41051. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  41052. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  41053. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  41054. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  41055. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  41056. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  41057. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  41058. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  41059. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  41060. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  41061. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  41062. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  41063. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  41064. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  41065. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  41066. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  41067. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  41068. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  41069. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  41070. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  41071. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  41072. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  41073. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  41074. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  41075. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  41076. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  41077. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  41078. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  41079. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  41080. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  41081. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  41082. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  41083. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  41084. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  41085. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  41086. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  41087. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  41088. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  41089. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  41090. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  41091. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  41092. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  41093. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  41094. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  41095. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  41096. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  41097. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  41098. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  41099. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  41100. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  41101. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  41102. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  41103. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  41104. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  41105. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  41106. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  41107. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  41108. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  41109. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  41110. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  41111. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  41112. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  41113. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  41114. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  41115. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  41116. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  41117. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  41118. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  41119. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  41120. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  41121. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  41122. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  41123. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  41124. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  41125. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  41126. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  41127. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  41128. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  41129. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  41130. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  41131. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  41132. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  41133. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  41134. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  41135. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  41136. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  41137. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  41138. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  41139. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  41140. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  41141. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  41142. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  41143. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  41144. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  41145. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  41146. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  41147. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  41148. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  41149. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  41150. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  41151. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  41152. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  41153. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  41154. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  41155. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  41156. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  41157. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  41158. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  41159. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  41160. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  41161. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  41162. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  41163. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  41164. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  41165. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  41166. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  41167. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  41168. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  41169. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  41170. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  41171. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  41172. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  41173. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  41174. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  41175. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  41176. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  41177. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  41178. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  41179. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  41180. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  41181. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  41182. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  41183. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  41184. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  41185. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  41186. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  41187. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  41188. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  41189. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  41190. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  41191. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  41192. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  41193. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  41194. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  41195. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  41196. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  41197. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f
  41198. };
  41199. #endif
  41200. wc_test_ret_t ret;
  41201. ret = dilithium_param_vfy_test(WC_ML_DSA_87, ml_dsa_87_pub_key,
  41202. (word32)sizeof(ml_dsa_87_pub_key), ml_dsa_87_sig,
  41203. (word32)sizeof(ml_dsa_87_sig));
  41204. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41205. if (ret == 0) {
  41206. ret = dilithium_param_vfy_test(WC_ML_DSA_87_DRAFT,
  41207. ml_dsa_87_draft_pub_key, (word32)sizeof(ml_dsa_87_draft_pub_key),
  41208. ml_dsa_87_draft_sig, (word32)sizeof(ml_dsa_87_draft_sig));
  41209. }
  41210. #endif
  41211. return ret;
  41212. }
  41213. #endif
  41214. #endif
  41215. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41216. static wc_test_ret_t dilithium_param_test(int param, WC_RNG* rng)
  41217. {
  41218. wc_test_ret_t ret;
  41219. dilithium_key* key;
  41220. byte* sig = NULL;
  41221. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41222. word32 sigLen;
  41223. byte msg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  41224. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41225. int res = 0;
  41226. #endif
  41227. #endif
  41228. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  41229. DYNAMIC_TYPE_TMP_BUFFER);
  41230. if (key == NULL) {
  41231. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41232. }
  41233. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
  41234. DYNAMIC_TYPE_TMP_BUFFER);
  41235. if (sig == NULL) {
  41236. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41237. }
  41238. ret = wc_dilithium_init(key);
  41239. if (ret != 0) {
  41240. ret = WC_TEST_RET_ENC_EC(ret);
  41241. return ret;
  41242. }
  41243. ret = wc_dilithium_set_level(key, param);
  41244. if (ret != 0)
  41245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41246. ret = wc_dilithium_make_key(key, rng);
  41247. if (ret != 0)
  41248. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41249. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41250. sigLen = wc_dilithium_sig_size(key);
  41251. if (sigLen <= 0)
  41252. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41253. ret = wc_dilithium_sign_msg(msg, (word32)sizeof(msg), sig, &sigLen, key,
  41254. rng);
  41255. if (ret != 0)
  41256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41257. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41258. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  41259. key);
  41260. if (ret != 0)
  41261. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41262. if (res != 1)
  41263. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  41264. #endif
  41265. #endif
  41266. out:
  41267. wc_dilithium_free(key);
  41268. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41269. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41270. return ret;
  41271. }
  41272. #endif
  41273. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
  41274. {
  41275. wc_test_ret_t ret;
  41276. WC_RNG rng;
  41277. #ifndef HAVE_FIPS
  41278. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41279. #else
  41280. ret = wc_InitRng(&rng);
  41281. #endif
  41282. if (ret != 0) {
  41283. ret = WC_TEST_RET_ENC_EC(ret);
  41284. return ret;
  41285. }
  41286. #ifndef WOLFSSL_NO_ML_DSA_44
  41287. #ifdef WOLFSSL_WC_DILITHIUM
  41288. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41289. ret = dilithium_param_44_vfy_test();
  41290. if (ret != 0)
  41291. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41292. #endif
  41293. #endif
  41294. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41295. ret = dilithium_param_test(WC_ML_DSA_44, &rng);
  41296. if (ret != 0)
  41297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41298. #endif
  41299. #endif
  41300. #ifndef WOLFSSL_NO_ML_DSA_65
  41301. #ifdef WOLFSSL_WC_DILITHIUM
  41302. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41303. ret = dilithium_param_65_vfy_test();
  41304. if (ret != 0)
  41305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41306. #endif
  41307. #endif
  41308. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41309. ret = dilithium_param_test(WC_ML_DSA_65, &rng);
  41310. if (ret != 0)
  41311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41312. #endif
  41313. #endif
  41314. #ifndef WOLFSSL_NO_ML_DSA_87
  41315. #ifdef WOLFSSL_WC_DILITHIUM
  41316. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41317. ret = dilithium_param_87_vfy_test();
  41318. if (ret != 0)
  41319. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41320. #endif
  41321. #endif
  41322. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41323. ret = dilithium_param_test(WC_ML_DSA_87, &rng);
  41324. if (ret != 0)
  41325. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41326. #endif
  41327. #endif
  41328. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  41329. !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  41330. out:
  41331. #endif
  41332. wc_FreeRng(&rng);
  41333. return ret;
  41334. }
  41335. #endif /* HAVE_DILITHIUM */
  41336. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  41337. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  41338. void *context)
  41339. {
  41340. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41341. * BE USED FOR TESTING PURPOSES! Production applications should
  41342. * write only to non-volatile storage. */
  41343. XMEMCPY(context, priv, privSz);
  41344. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  41345. }
  41346. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  41347. void *context)
  41348. {
  41349. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41350. * BE USED FOR TESTING PURPOSES! */
  41351. XMEMCPY(priv, context, privSz);
  41352. return WC_XMSS_RC_READ_TO_MEMORY;
  41353. }
  41354. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
  41355. {
  41356. int i = 0;
  41357. int j = 0;
  41358. XmssKey signingKey;
  41359. XmssKey verifyKey;
  41360. WC_RNG rng;
  41361. word32 pkSz = 0;
  41362. word32 skSz = 0;
  41363. word32 sigSz = 0;
  41364. word32 bufSz = 0;
  41365. unsigned char * sk = NULL;
  41366. unsigned char * old_sk = NULL;
  41367. const char * msg = "XMSS post quantum signature test";
  41368. word32 msgSz = (word32) XSTRLEN(msg);
  41369. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41370. const char * param = "XMSS-SHA2_10_256";
  41371. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 20
  41372. const char * param = "XMSSMT-SHA2_20/4_256";
  41373. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 40
  41374. const char * param = "XMSSMT-SHA2_40/8_256";
  41375. #else
  41376. const char * param = "XMSSMT-SHA2_60/12_256";
  41377. #endif
  41378. byte * sig = NULL;
  41379. int ret2 = -1;
  41380. int ret = WC_TEST_RET_ENC_NC;
  41381. WOLFSSL_ENTER("xmss_test");
  41382. #ifndef HAVE_FIPS
  41383. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41384. #else
  41385. ret = wc_InitRng(&rng);
  41386. #endif
  41387. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41388. ret = wc_XmssKey_Init(&signingKey, NULL, INVALID_DEVID);
  41389. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41390. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41391. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41392. /* Set the parameter string to the signing key, and
  41393. * get sizes for secret key, pub key, and signature. */
  41394. ret = wc_XmssKey_SetParamStr(&signingKey, param);
  41395. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41396. ret = wc_XmssKey_GetPubLen(&signingKey, &pkSz);
  41397. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41398. if (pkSz != XMSS_SHA256_PUBLEN) {
  41399. return WC_TEST_RET_ENC_EC(pkSz);
  41400. }
  41401. ret = wc_XmssKey_GetPrivLen(&signingKey, &skSz);
  41402. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41403. ret = wc_XmssKey_GetSigLen(&signingKey, &sigSz);
  41404. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41405. /* Allocate signature array. */
  41406. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41407. if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41408. bufSz = sigSz;
  41409. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41410. fprintf(stderr, "param: %s\n", param);
  41411. fprintf(stderr, "pkSz: %d\n", pkSz);
  41412. fprintf(stderr, "skSz: %d\n", skSz);
  41413. fprintf(stderr, "sigSz: %d\n", sigSz);
  41414. #endif
  41415. /* Allocate current and old secret keys.*/
  41416. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41417. if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41418. old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41419. if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41420. XMEMSET(sk, 0, skSz);
  41421. XMEMSET(old_sk, 0, skSz);
  41422. XMEMSET(sig, 0, sigSz);
  41423. ret = wc_XmssKey_SetWriteCb(&signingKey, xmss_write_key_mem);
  41424. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41425. ret = wc_XmssKey_SetReadCb(&signingKey, xmss_read_key_mem);
  41426. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41427. ret = wc_XmssKey_SetContext(&signingKey, (void *) sk);
  41428. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41429. ret = wc_XmssKey_MakeKey(&signingKey, &rng);
  41430. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41431. /* Export the pub to a verify key. */
  41432. ret = wc_XmssKey_ExportPub(&verifyKey, &signingKey);
  41433. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41434. /* Repeat a few times to check that:
  41435. * 1. The secret key is mutated on each sign.
  41436. * 2. We can verify each new signature.
  41437. * Only do a few times, because the full signature space
  41438. * for this parameter set is huge. */
  41439. for (i = 0; i < 10; ++i) {
  41440. XMEMCPY(old_sk, sk, skSz);
  41441. ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41442. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41443. if (sigSz != bufSz) { return WC_TEST_RET_ENC_I(i); }
  41444. /* Old secret key and current secret key should not match. */
  41445. ret = XMEMCMP(old_sk, sk, skSz);
  41446. if (ret == 0) { return WC_TEST_RET_ENC_I(i); }
  41447. ret = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41448. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41449. /* Flip bits in a few places throughout the signature, stepping in multiple
  41450. * of hash size. These should all fail with -1. */
  41451. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41452. sig[j] ^= 1;
  41453. ret2 = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41454. msgSz);
  41455. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41456. /* Verify passed when it should have failed. */
  41457. return WC_TEST_RET_ENC_I(j);
  41458. }
  41459. /* Flip this spot back. */
  41460. sig[j] ^= 1;
  41461. }
  41462. }
  41463. /* Cleanup everything. */
  41464. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41465. sig = NULL;
  41466. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41467. sk = NULL;
  41468. XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41469. old_sk = NULL;
  41470. wc_XmssKey_Free(&signingKey);
  41471. wc_FreeRng(&rng);
  41472. return ret;
  41473. }
  41474. #endif /*if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)*/
  41475. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_SMALL_STACK) && \
  41476. WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41477. /* A simple xmss verify only test using:
  41478. * XMSS-SHA2_10_256
  41479. * pub len: 68
  41480. * msg len: 32
  41481. * sig len: 2500
  41482. *
  41483. * These were generated with the test xmss_fast, from the unpatched
  41484. * xmss-reference repository:
  41485. * https://github.com/XMSS/xmss-reference
  41486. * */
  41487. static const byte xmss_pub[XMSS_SHA256_PUBLEN] =
  41488. {
  41489. 0x00,0x00,0x00,0x01,0xA5,0x41,0x31,0x96,
  41490. 0x0A,0xF9,0xF3,0xB2,0x4B,0x2E,0x5B,0x3E,
  41491. 0xCA,0x74,0xAD,0x6C,0xA5,0x89,0xAD,0x2C,
  41492. 0x0E,0x96,0xB3,0x54,0xFB,0x5B,0x63,0x50,
  41493. 0x96,0x81,0xE2,0x59,0x72,0x10,0x09,0x54,
  41494. 0xBB,0x39,0xAC,0xEE,0x78,0xEF,0x95,0xEC,
  41495. 0x01,0x1D,0xF0,0x36,0x68,0xE2,0xC4,0xA5,
  41496. 0x2F,0x60,0x42,0x7E,0xD3,0x8E,0xAA,0x27,
  41497. 0xC9,0xB7,0x39,0x4E
  41498. };
  41499. static /* not const */ byte xmss_msg[32] =
  41500. {
  41501. 0x07,0x9F,0x80,0x86,0xDB,0x76,0x27,0xDF,
  41502. 0xED,0x5B,0x2A,0x81,0x60,0x60,0x7D,0xB4,
  41503. 0xE8,0x7A,0x69,0x45,0x20,0x6B,0xA2,0x96,
  41504. 0xC0,0x21,0xA5,0x46,0x29,0x63,0x9B,0x37
  41505. };
  41506. /* This was actually the 5th signature produced from
  41507. * xmss_fast test in xmss-reference. */
  41508. static /* not const */ byte xmss_sig[2500] =
  41509. {
  41510. 0x00,0x00,0x00,0x05,0xF0,0x15,0x34,0xBA,
  41511. 0x92,0x03,0x6A,0xB9,0xA5,0x23,0x86,0x11,
  41512. 0xAE,0x65,0x0A,0x5C,0x78,0x2C,0xC9,0xBE,
  41513. 0x7E,0xA6,0xDC,0xA2,0x8B,0xA9,0x9C,0x50,
  41514. 0xF6,0x61,0x8D,0x9D,0xD7,0xE9,0xC0,0xF8,
  41515. 0x67,0xCD,0x8A,0xC4,0x9B,0x74,0x96,0x07,
  41516. 0x5D,0xF2,0xC9,0xCC,0x28,0x05,0xB1,0xBE,
  41517. 0x5E,0xA4,0xBA,0xBE,0xAB,0xD8,0x21,0x6B,
  41518. 0x21,0x5F,0xAB,0xB7,0x6C,0xEC,0x2F,0xC8,
  41519. 0xC6,0x74,0x3E,0x97,0x1B,0xC3,0x45,0x57,
  41520. 0xAF,0xAA,0x1E,0xA8,0xF2,0x86,0xA8,0xAA,
  41521. 0x43,0x6D,0x66,0xE9,0x81,0x14,0xDE,0x09,
  41522. 0x39,0xD2,0xAF,0xD1,0x4C,0xE7,0x75,0x18,
  41523. 0x0D,0xAA,0x29,0xA1,0x92,0x53,0xCC,0xE9,
  41524. 0xF3,0x0B,0x1E,0x3B,0xE2,0xAE,0x80,0x0C,
  41525. 0xE7,0x7A,0x7C,0x13,0x8A,0x28,0xC6,0x5F,
  41526. 0x0A,0xA4,0xA3,0x73,0x0A,0x3A,0xC2,0xA6,
  41527. 0x3B,0xB4,0x30,0x67,0xC0,0x36,0x18,0xA1,
  41528. 0x58,0xCD,0xAD,0x54,0x36,0x64,0xCE,0xFD,
  41529. 0x52,0xFF,0x70,0x7E,0x09,0xFB,0x13,0xA2,
  41530. 0xEA,0xDF,0x67,0x8D,0x6C,0x42,0xB2,0x78,
  41531. 0xF5,0x7D,0x5C,0x4B,0xF7,0x8E,0xCF,0x3E,
  41532. 0xB7,0xC6,0xC1,0x23,0xFA,0x65,0xDE,0xD2,
  41533. 0xFA,0x40,0x51,0x97,0x0D,0x52,0x32,0x76,
  41534. 0x7E,0x82,0x8D,0xD0,0xB9,0x1E,0x62,0xD9,
  41535. 0x1E,0xC1,0xDB,0x40,0x43,0x37,0x4A,0x23,
  41536. 0x8A,0x1D,0x35,0xFA,0xF4,0x53,0x11,0x5A,
  41537. 0xB5,0x6D,0x1E,0x8B,0x22,0xC8,0x7D,0x2A,
  41538. 0xE4,0x94,0xAA,0x25,0x20,0x40,0x96,0xDB,
  41539. 0x82,0x62,0xBA,0x8F,0x8B,0x45,0xCB,0x4F,
  41540. 0x35,0x88,0x33,0xEB,0xEF,0xB3,0xBA,0xA7,
  41541. 0x09,0x72,0xB3,0x4C,0xEC,0xF2,0xC3,0xC7,
  41542. 0x5E,0x02,0x6C,0x41,0x93,0xCB,0x3C,0x89,
  41543. 0x12,0x09,0x68,0x54,0x8E,0xEC,0x6A,0x7E,
  41544. 0x20,0xE1,0x70,0x3D,0x8C,0xEB,0xB4,0x36,
  41545. 0xBE,0x91,0xBE,0x97,0xB5,0xA6,0x34,0x16,
  41546. 0x95,0x0F,0x10,0x26,0xA9,0x13,0x80,0x88,
  41547. 0x9C,0xAA,0x68,0xEC,0x34,0x70,0x4A,0x15,
  41548. 0x9B,0x5E,0x57,0x05,0x87,0x1C,0xF8,0x35,
  41549. 0x45,0x29,0xE9,0x6E,0xF2,0x70,0x13,0x42,
  41550. 0x89,0x4E,0x77,0xC0,0x18,0xC7,0x55,0x6D,
  41551. 0xE7,0xFA,0x0D,0x63,0x83,0x16,0x19,0x01,
  41552. 0x2D,0xFD,0x31,0x14,0x94,0xCA,0x3E,0x0E,
  41553. 0xD6,0x11,0x34,0x81,0x57,0x58,0xEC,0x24,
  41554. 0xA4,0x17,0x63,0xD3,0x25,0x00,0xBF,0x7D,
  41555. 0x78,0x5D,0xC5,0xD8,0xC6,0xC1,0xBD,0x8C,
  41556. 0xD0,0x94,0x0A,0xB1,0x33,0xA5,0x4B,0x31,
  41557. 0x25,0xF5,0xAF,0xE7,0x84,0x26,0xAA,0x05,
  41558. 0xBB,0xF3,0x9A,0xAF,0x58,0x36,0x40,0xEF,
  41559. 0x3D,0xA2,0xBD,0xCA,0xA1,0x8D,0x2F,0x6D,
  41560. 0x54,0xD2,0x62,0x33,0x09,0xAE,0xE6,0x73,
  41561. 0xD6,0x44,0xE8,0x7C,0x5C,0x39,0x2B,0x78,
  41562. 0x94,0x14,0xC7,0xC9,0xAF,0xEC,0x77,0x36,
  41563. 0xA1,0x61,0x61,0xF1,0xD0,0x09,0xA2,0xEE,
  41564. 0xE7,0x55,0xD7,0x35,0x89,0x89,0x9B,0xCF,
  41565. 0xFA,0xA6,0x09,0x1E,0x3B,0xBD,0x5D,0xD9,
  41566. 0x25,0xE7,0xED,0xDD,0x7C,0xF0,0x1C,0x57,
  41567. 0xE0,0x06,0xBB,0x08,0x39,0x59,0xDF,0xD7,
  41568. 0xAF,0x4B,0x88,0x0D,0x87,0x8F,0x4A,0xF3,
  41569. 0x1C,0xD4,0x4B,0xB3,0xE2,0xF3,0x1B,0x86,
  41570. 0x4F,0xCD,0x35,0x75,0xE2,0x03,0xF9,0x1D,
  41571. 0xBF,0x3E,0xD1,0x7B,0xC7,0x23,0x11,0x75,
  41572. 0x5F,0x92,0x0D,0x98,0xEE,0x14,0xE1,0xDA,
  41573. 0x7A,0x02,0x17,0x47,0x6B,0x41,0xEA,0x47,
  41574. 0xA1,0xAF,0x06,0x79,0x1A,0x52,0x6F,0x19,
  41575. 0x31,0x70,0x71,0xBD,0xC2,0x61,0x8D,0xB7,
  41576. 0xEE,0x6B,0x69,0x2A,0xE8,0x21,0x7A,0x95,
  41577. 0xBE,0x86,0x2A,0xA1,0xF4,0xE2,0x2F,0x17,
  41578. 0x02,0xFD,0xAD,0x17,0x9F,0x0A,0x0A,0x78,
  41579. 0xA9,0x92,0x30,0x21,0x72,0x2B,0x28,0xF8,
  41580. 0xF2,0x3E,0x05,0xD5,0xAC,0xC0,0x82,0xF8,
  41581. 0xD2,0xDA,0xD0,0xA3,0xBC,0x93,0xDB,0xA5,
  41582. 0x46,0xDE,0x14,0x1E,0xD4,0x3A,0x5D,0x79,
  41583. 0x3D,0x31,0x4B,0x06,0xCE,0x22,0x29,0x3C,
  41584. 0x98,0xB6,0x18,0x8A,0xAE,0xF7,0xBA,0x22,
  41585. 0x88,0xA1,0xEE,0xC0,0x14,0x4C,0x4A,0xA0,
  41586. 0x57,0x0A,0xD3,0x18,0xA2,0x3D,0xDD,0xC7,
  41587. 0x83,0x73,0xFC,0x38,0x9B,0x31,0xA3,0xE1,
  41588. 0x17,0x76,0xA1,0xA2,0x69,0xFC,0xAB,0x08,
  41589. 0x80,0x72,0x8D,0xF5,0xE4,0x14,0xB7,0x6B,
  41590. 0x03,0xFF,0xE8,0x11,0x4B,0x06,0x55,0x7E,
  41591. 0x36,0x21,0x2F,0xD7,0x54,0x82,0xC9,0x31,
  41592. 0xB4,0x85,0x68,0x41,0xEF,0x75,0xB0,0x3A,
  41593. 0xEA,0x4F,0xE0,0xEC,0x72,0xCC,0x33,0x96,
  41594. 0xCE,0x7D,0xAD,0xDD,0x0D,0x27,0x05,0x6E,
  41595. 0xA2,0xD4,0x11,0x07,0xD8,0x7D,0x27,0xD4,
  41596. 0x80,0x8F,0x00,0x22,0xE4,0xFC,0x2C,0x9D,
  41597. 0xD5,0xD8,0x18,0x7F,0x4E,0xF4,0xB9,0x7F,
  41598. 0xEF,0xD6,0x00,0x08,0x5C,0x05,0x04,0x1E,
  41599. 0x9A,0xC6,0x8D,0xCC,0x19,0xD9,0x0B,0x06,
  41600. 0xCC,0x6A,0x17,0xE2,0x03,0x23,0xDB,0x1C,
  41601. 0xBC,0xA2,0xB9,0xA2,0x95,0x3C,0x73,0xD8,
  41602. 0xFF,0xE6,0x0E,0xAE,0x04,0xB2,0xFC,0x91,
  41603. 0x4F,0xEF,0x8A,0x58,0xB7,0x31,0x68,0x4C,
  41604. 0x1E,0xD0,0x5B,0x85,0xCC,0x03,0xDC,0xF4,
  41605. 0xAC,0xDB,0x03,0x9B,0x35,0x33,0x08,0x71,
  41606. 0xD0,0x50,0x8D,0xDC,0xE3,0x3A,0x98,0x40,
  41607. 0x41,0x80,0xDD,0x35,0xE1,0xA2,0xAF,0x14,
  41608. 0x9A,0xDB,0xD3,0x68,0x14,0xE2,0x50,0x7A,
  41609. 0x76,0x3F,0xE4,0xA4,0x1B,0xAA,0xC1,0x06,
  41610. 0x87,0x9A,0x92,0xF9,0xBE,0x9E,0x86,0x8C,
  41611. 0x92,0x1D,0x74,0xB1,0x7F,0x27,0x43,0xC0,
  41612. 0xEE,0x2E,0xC2,0x6C,0x6D,0xAA,0x0C,0x0E,
  41613. 0x71,0xC9,0x56,0xD6,0x3A,0x56,0xCB,0x90,
  41614. 0xD1,0x7E,0x6E,0x1C,0x6A,0x00,0x2D,0x02,
  41615. 0x2C,0x96,0xF0,0x2A,0x37,0x37,0x18,0x07,
  41616. 0x0B,0xF4,0xB4,0x8C,0x30,0xF2,0xA4,0xAB,
  41617. 0x66,0xFB,0x8B,0x22,0xC0,0x00,0x7E,0x05,
  41618. 0xB6,0xF9,0x95,0x49,0x33,0xA1,0xDC,0x97,
  41619. 0x0C,0x5C,0x61,0x46,0xE2,0xD7,0x87,0x4B,
  41620. 0xC4,0xC7,0x5F,0x26,0x06,0x84,0xD7,0x47,
  41621. 0x05,0xF1,0x33,0xFF,0x85,0x85,0xB2,0xBD,
  41622. 0x1F,0x44,0xC6,0xC2,0x7D,0x51,0xBE,0x0E,
  41623. 0xB5,0xC4,0x44,0x2F,0xFE,0x73,0x5F,0xF4,
  41624. 0xA4,0xEF,0xE2,0xF1,0x73,0x0B,0xEF,0x3E,
  41625. 0x2B,0xD7,0xCC,0x9F,0xDA,0x1A,0x7E,0x92,
  41626. 0x39,0xA1,0x55,0xBF,0x60,0x0A,0xDB,0x23,
  41627. 0x74,0xFE,0xE7,0x05,0x63,0xA9,0x85,0x52,
  41628. 0x9F,0xCC,0xC3,0xFF,0xF6,0x6C,0x1B,0x4E,
  41629. 0x4F,0x01,0xBD,0xC3,0xEB,0x37,0xEC,0x29,
  41630. 0x21,0x3B,0x2C,0xC9,0x2E,0x93,0x20,0x3E,
  41631. 0x19,0xC0,0x8B,0xE8,0x33,0xCD,0xC6,0x6A,
  41632. 0x6E,0x72,0x13,0x15,0xA1,0x90,0x20,0x0C,
  41633. 0x14,0x66,0xED,0xCC,0xA4,0xDD,0x7F,0x58,
  41634. 0x53,0xBC,0x4A,0x68,0xFC,0x86,0x3E,0xAA,
  41635. 0xF1,0x17,0x0F,0x3E,0x20,0x54,0x93,0xF4,
  41636. 0x98,0xBF,0xB4,0x07,0x05,0xBD,0x70,0xE7,
  41637. 0xD7,0x34,0xFD,0xE3,0x69,0xDF,0xCD,0xF5,
  41638. 0x1A,0x73,0x6E,0xC9,0x2B,0x21,0xFB,0xB8,
  41639. 0x7E,0x44,0x10,0x83,0x56,0xCE,0xD5,0x15,
  41640. 0x9A,0x75,0xFC,0x91,0x8E,0x6B,0x9E,0x1A,
  41641. 0x3A,0x33,0x39,0x35,0xB4,0x0D,0x74,0xF4,
  41642. 0xFB,0x4C,0x0E,0x37,0xFE,0x82,0x95,0x46,
  41643. 0x6B,0xD2,0x6E,0xEE,0xCD,0x4D,0x38,0xAF,
  41644. 0x0A,0xAA,0xF1,0xD5,0xA4,0x7C,0x04,0xD8,
  41645. 0xB9,0xDB,0x11,0x68,0x88,0x35,0x41,0xDE,
  41646. 0x31,0x33,0x0C,0xDC,0x2D,0x4C,0xA8,0x20,
  41647. 0xCC,0x2C,0x4C,0x63,0xAB,0xBA,0xDF,0x48,
  41648. 0x84,0xD5,0x25,0xBC,0x70,0xE3,0x49,0xAA,
  41649. 0x43,0xCA,0x8B,0xE7,0x9F,0xDD,0x20,0x76,
  41650. 0x9B,0x38,0xF4,0xBA,0x4D,0x4E,0x34,0x4A,
  41651. 0xAF,0x81,0xE7,0x0B,0xEC,0xE9,0x59,0xC1,
  41652. 0x35,0x22,0x7F,0x69,0x46,0x62,0xD2,0x18,
  41653. 0x6E,0x1F,0x79,0xD1,0xAD,0xC3,0x84,0x95,
  41654. 0x96,0xB2,0x18,0x58,0x5E,0x7E,0x0C,0x25,
  41655. 0x0A,0x0F,0x69,0xA3,0x1D,0xEC,0x29,0xCB,
  41656. 0xDA,0xA2,0xD1,0x1A,0x10,0xA5,0x52,0xC3,
  41657. 0x62,0x1E,0xC5,0x83,0xFF,0xA3,0x56,0xC2,
  41658. 0xFD,0x87,0x3B,0x57,0x52,0x98,0x36,0x95,
  41659. 0x77,0x6B,0xE5,0x49,0x10,0x8E,0x39,0xDD,
  41660. 0xCA,0x4B,0xB3,0x9F,0x4C,0x0C,0x11,0x62,
  41661. 0xF3,0x22,0x78,0xDB,0x48,0xEB,0x68,0xFE,
  41662. 0xE4,0x2A,0xE9,0xAA,0x8F,0x7A,0x2F,0x69,
  41663. 0xA5,0xC5,0x03,0x2D,0xEF,0x62,0xA8,0x71,
  41664. 0x65,0x06,0x40,0x84,0x10,0x0F,0xF2,0xED,
  41665. 0xBC,0x70,0x71,0x69,0x24,0xA2,0xBF,0x83,
  41666. 0x39,0xDD,0xFA,0xA2,0x7B,0xE5,0xEC,0x3D,
  41667. 0xFE,0x3B,0x52,0x6E,0x3D,0x82,0xA6,0x2A,
  41668. 0x86,0x01,0x61,0x51,0x63,0xBF,0xF9,0x0A,
  41669. 0x06,0x72,0xF1,0xD5,0x39,0x0C,0xBA,0xC9,
  41670. 0x78,0xC6,0x77,0x22,0xE4,0x96,0x6E,0xB1,
  41671. 0x48,0x62,0x84,0x62,0x2D,0xEA,0x49,0x56,
  41672. 0x50,0x86,0x3F,0x90,0xC3,0x01,0x42,0x45,
  41673. 0xED,0xE6,0x9A,0x65,0x19,0x93,0x7F,0x48,
  41674. 0x16,0xF2,0x50,0xA7,0x70,0xB3,0xF5,0xDB,
  41675. 0x0E,0x5E,0x22,0x9E,0x64,0x04,0x26,0x69,
  41676. 0xC1,0x16,0xEE,0x65,0x08,0x82,0x27,0x65,
  41677. 0xEC,0x3D,0xDF,0x51,0x5E,0x2D,0xE8,0x76,
  41678. 0xF2,0xE3,0xE4,0x24,0x04,0x88,0x06,0x0F,
  41679. 0xB2,0x7B,0x9B,0x72,0x3D,0x4C,0x7D,0x6A,
  41680. 0x1F,0xB2,0xA2,0xD2,0x35,0xD6,0x40,0x25,
  41681. 0xC2,0x0B,0x25,0xF9,0xDF,0x26,0xE4,0xDC,
  41682. 0xFB,0xB1,0x84,0x84,0x77,0x1B,0x45,0x51,
  41683. 0x60,0xD5,0xF0,0xB6,0x09,0xE6,0xBC,0xE3,
  41684. 0x1C,0x70,0x96,0x2C,0xD3,0x9D,0x7D,0x7F,
  41685. 0xB1,0x70,0xDA,0x79,0xB8,0x74,0x99,0xBF,
  41686. 0x84,0x95,0xCC,0x93,0xD7,0x51,0xDD,0x66,
  41687. 0xD3,0x70,0x0C,0x75,0x86,0x09,0x06,0xFD,
  41688. 0x66,0x14,0x80,0xCD,0xF3,0x59,0xB4,0x92,
  41689. 0x5F,0xE4,0xEE,0x00,0xA8,0xB0,0x8B,0x5C,
  41690. 0x3E,0xDB,0x8A,0x9C,0x0B,0xB5,0x99,0xC2,
  41691. 0x0D,0x81,0x09,0x06,0x6C,0x28,0xC0,0x7E,
  41692. 0xA5,0x07,0x70,0x64,0xD7,0x41,0xF4,0xC3,
  41693. 0x66,0x61,0x1C,0xA8,0x51,0xF6,0x3C,0xBA,
  41694. 0xE0,0x94,0xA3,0x11,0x8C,0x2E,0xBA,0x13,
  41695. 0xB2,0x47,0x48,0x93,0xB4,0x1A,0x2C,0x9A,
  41696. 0x6E,0x8E,0x30,0x66,0x7B,0xD3,0xBB,0x3B,
  41697. 0x5D,0x97,0x0D,0xE4,0xEA,0x24,0x28,0x9E,
  41698. 0xB4,0x88,0xCE,0x1D,0x7D,0x6F,0x39,0xB3,
  41699. 0x87,0x21,0xE5,0x08,0x93,0xF0,0xD4,0x9D,
  41700. 0x2D,0x91,0xC9,0xFD,0x0C,0x74,0x34,0xB4,
  41701. 0x1F,0xFE,0xDA,0xDC,0x10,0x5B,0x8D,0x2B,
  41702. 0x87,0xD3,0x42,0xB4,0xAE,0x32,0x9C,0xAE,
  41703. 0x4C,0x99,0xD8,0xED,0x44,0x41,0x07,0xE0,
  41704. 0x8F,0xBD,0xA5,0x7C,0x5A,0xDF,0x91,0x29,
  41705. 0x00,0xB5,0x4B,0xC3,0x3A,0x40,0x6C,0x48,
  41706. 0xAB,0x2A,0xF3,0x02,0xCB,0xB3,0x69,0xDA,
  41707. 0x06,0x0C,0x4D,0x5C,0x45,0xC3,0x28,0xAC,
  41708. 0x7A,0x01,0xD4,0xF8,0xCB,0x07,0x63,0x89,
  41709. 0x09,0x34,0x78,0xA7,0x14,0x39,0xCF,0x2D,
  41710. 0x94,0x8D,0x7A,0x4E,0x4E,0xBD,0xC4,0x32,
  41711. 0xAB,0x21,0xC9,0xDA,0x3F,0x5F,0x04,0x6B,
  41712. 0x14,0x40,0x18,0x18,0x2F,0xF9,0x46,0x17,
  41713. 0x57,0x54,0x9B,0x28,0x7B,0xBD,0xF9,0xA2,
  41714. 0x13,0xAC,0x69,0x24,0xB1,0x31,0x39,0xBF,
  41715. 0x8D,0x75,0xC3,0xFD,0x03,0x54,0x5A,0xFD,
  41716. 0xD4,0x7A,0xB7,0x56,0x4F,0x66,0x43,0x57,
  41717. 0x1B,0xFB,0xF9,0x92,0x7A,0x83,0xE6,0xFF,
  41718. 0xB4,0xBA,0x83,0xD2,0x61,0x8E,0x4A,0x82,
  41719. 0x82,0xA8,0xF5,0x0C,0xD2,0x43,0x53,0xA8,
  41720. 0x85,0x0A,0xD4,0x69,0x7B,0x04,0x71,0x3B,
  41721. 0x80,0x49,0x27,0x47,0x12,0xB6,0xB0,0xEA,
  41722. 0x90,0x0A,0xFA,0xA8,0xC8,0x78,0x61,0xDE,
  41723. 0x30,0x12,0xBB,0xDC,0xA6,0x57,0x56,0x30,
  41724. 0x6E,0xF1,0xA8,0x3B,0xF6,0x09,0x07,0xEA,
  41725. 0x31,0xE2,0x08,0x23,0x31,0x0F,0xD4,0x34,
  41726. 0xE3,0x60,0xC2,0x2B,0xDB,0x5A,0x99,0xCF,
  41727. 0xD4,0x6B,0x4E,0x75,0x65,0x35,0xE8,0x8B,
  41728. 0x93,0x7D,0xCA,0x11,0x47,0xF0,0x3E,0x11,
  41729. 0x5C,0xD1,0xEE,0x4B,0x11,0xB4,0x65,0x2B,
  41730. 0x6B,0x79,0xC0,0x86,0x60,0xA4,0x4B,0x24,
  41731. 0xA0,0x5C,0x70,0x34,0xC3,0x7C,0xE7,0x4F,
  41732. 0x97,0x89,0x4D,0xFE,0x22,0x89,0x3A,0xE9,
  41733. 0x07,0xB9,0x1A,0x86,0xB8,0x7A,0x12,0x38,
  41734. 0xE1,0x24,0x46,0xBC,0x9B,0x21,0xCD,0xAC,
  41735. 0x30,0xAB,0x98,0x21,0x31,0xC5,0x17,0x3F,
  41736. 0x1E,0x56,0xC3,0x18,0xCE,0xF0,0xA1,0xCC,
  41737. 0xFF,0x9D,0xA8,0x53,0xAF,0x74,0x77,0x54,
  41738. 0x02,0x9A,0x8F,0xA4,0xD4,0xBD,0xB2,0x1A,
  41739. 0xBA,0x52,0x2E,0x19,0xBE,0x49,0x11,0x45,
  41740. 0x02,0x01,0x7A,0xBF,0x28,0xD6,0x18,0xED,
  41741. 0xBD,0xCE,0xE4,0xDE,0xB5,0xF1,0x53,0x5D,
  41742. 0x65,0xF9,0x5F,0x83,0x8F,0x2D,0xF2,0x82,
  41743. 0xA0,0x2D,0x28,0xD3,0x0A,0x9E,0x0F,0x7F,
  41744. 0xC7,0xC4,0x43,0x7F,0xC3,0x0E,0x06,0xEB,
  41745. 0x4E,0xB4,0x2D,0xFA,0xDD,0x48,0xAB,0xF4,
  41746. 0x7D,0x41,0x48,0x33,0x5A,0xE6,0x70,0x02,
  41747. 0xE7,0x71,0x8D,0xD9,0x6B,0x0C,0x5A,0x8F,
  41748. 0xA4,0xC1,0xB7,0x4E,0x96,0x83,0xD6,0xA7,
  41749. 0x1D,0xF1,0x88,0xB3,0x6E,0xF4,0x12,0xA9,
  41750. 0xF6,0x31,0x69,0x66,0xFE,0xFE,0x02,0xF2,
  41751. 0x86,0x6D,0xBB,0x57,0x51,0x8C,0x4C,0xE9,
  41752. 0x7C,0x92,0x3E,0x3A,0xD3,0x2D,0xA8,0x82,
  41753. 0x53,0x84,0x26,0x89,0xBB,0xCC,0x13,0x12,
  41754. 0x3D,0x94,0xBB,0xDF,0x3D,0x4C,0xDF,0x27,
  41755. 0x9B,0x1F,0xB8,0xB6,0xE4,0xEA,0xA2,0x07,
  41756. 0xF8,0x4D,0x42,0x8F,0x29,0x90,0xFE,0x21,
  41757. 0x20,0xE9,0x55,0x02,0xAD,0x90,0xA7,0x77,
  41758. 0x4E,0x29,0xB6,0xD9,0x14,0x94,0xB2,0x25,
  41759. 0xA4,0xB2,0x0E,0x96,0x31,0xAB,0x9E,0x93,
  41760. 0x49,0xAC,0xA9,0xCB,0x68,0x22,0xBA,0xB8,
  41761. 0x57,0x5C,0x9D,0x65,0xC1,0xF1,0xFC,0x99,
  41762. 0x7C,0x3C,0xE9,0xEA,0x4B,0x29,0x22,0x2F,
  41763. 0xDB,0x17,0x21,0x8D,0xB0,0x13,0xBF,0xEE,
  41764. 0x7D,0xE4,0x8B,0x6D,0x17,0xE0,0x53,0x92,
  41765. 0x0B,0x32,0x6B,0xB1,0x65,0x2E,0xA7,0x83,
  41766. 0xFD,0x62,0x62,0xE3,0xAA,0x81,0xE8,0xD6,
  41767. 0xF7,0xB1,0x30,0x65,0x80,0x9F,0x77,0x1E,
  41768. 0x4A,0xEA,0xE8,0x45,0x32,0x12,0x3A,0xFB,
  41769. 0x22,0xE9,0xA9,0xF6,0xCB,0xAB,0xA8,0x0C,
  41770. 0x20,0xA8,0x7C,0xF9,0xF7,0x53,0xC1,0xB4,
  41771. 0xC0,0x5D,0x06,0x45,0xDD,0x7E,0xA7,0x34,
  41772. 0xA1,0x21,0xC2,0x62,0xAB,0x22,0x45,0x3D,
  41773. 0x73,0x4C,0x26,0xD1,0x1A,0xB2,0xF0,0xB2,
  41774. 0x6D,0x11,0x70,0x58,0xAA,0xF5,0xA4,0xF5,
  41775. 0xF8,0x0B,0x3D,0xC1,0xF6,0x17,0x70,0x15,
  41776. 0xCD,0x72,0x02,0x7E,0x4E,0x94,0x96,0x0A,
  41777. 0x56,0xCC,0xA5,0xA3,0xB3,0x7E,0xDD,0x5A,
  41778. 0x72,0xD2,0xFB,0xAC,0x3D,0x0E,0x66,0x65,
  41779. 0xE9,0x08,0x6C,0xB0,0x1C,0xE2,0x1A,0x82,
  41780. 0xF6,0xF3,0x34,0x89,0x73,0x02,0x5B,0x42,
  41781. 0x6D,0x40,0x61,0xB6,0xE0,0xE6,0x53,0x32,
  41782. 0xA5,0x72,0x17,0x4F,0x3B,0x51,0x4F,0xBC,
  41783. 0x00,0xE0,0x69,0x26,0xA9,0xAE,0x83,0xE3,
  41784. 0x73,0x7F,0x71,0x97,0xE0,0xDC,0x7C,0x63,
  41785. 0x9C,0x85,0x5F,0xDF,0x7D,0xE4,0x6C,0xD8,
  41786. 0xA9,0x3A,0x6F,0x5E,0x4A,0x2E,0xB0,0xE7,
  41787. 0x8B,0x45,0xE2,0x90,0x05,0x37,0xE8,0xAB,
  41788. 0x49,0x48,0x4C,0xC0,0x59,0x1D,0x8C,0x46,
  41789. 0x5B,0x84,0xE0,0x83,0xCE,0xEA,0x4B,0xF9,
  41790. 0xD4,0xDC,0x63,0xDF,0x79,0xB7,0x5C,0x11,
  41791. 0x25,0x7F,0x90,0x2E,0x0A,0x38,0x03,0xEA,
  41792. 0xEA,0xA1,0x26,0x52,0x20,0x19,0xA3,0xBE,
  41793. 0xFC,0x9D,0xB7,0x6E,0xA6,0x58,0x8E,0x6D,
  41794. 0xC5,0x58,0xE9,0xED,0x2F,0x55,0x43,0x8B,
  41795. 0x03,0x8B,0xE6,0xA4,0xC2,0x25,0x4B,0x36,
  41796. 0xBA,0xD3,0x27,0x48,0x40,0x2E,0x87,0xA2,
  41797. 0xD4,0x12,0xC6,0x05,0x36,0x03,0x11,0x51,
  41798. 0xD1,0xF2,0xAC,0x71,0x2C,0xB6,0xC3,0xA5,
  41799. 0x57,0x0F,0xAF,0x4B,0xBD,0xCD,0x47,0x4C,
  41800. 0x3A,0x52,0x6F,0x47,0xE7,0x0B,0xB7,0xD5,
  41801. 0xF7,0xA6,0x39,0x63,0x82,0x08,0x4C,0x41,
  41802. 0x0E,0x2A,0x52,0x42,0x5A,0xEA,0x59,0xC7,
  41803. 0x94,0xFB,0xD0,0x88,0x47,0x27,0xF6,0x97,
  41804. 0x03,0x9E,0x29,0xB8,0x3A,0x67,0xE6,0xF3,
  41805. 0x95,0xA7,0x42,0xC1,0x96,0xD1,0x9A,0xA6,
  41806. 0xF0,0x09,0x0C,0xEA,0xE0,0xAB,0x0F,0x15,
  41807. 0xE9,0xC3,0xEB,0xA5,0x89,0x86,0x98,0x32,
  41808. 0x83,0xAB,0x30,0x33,0xAE,0x90,0x8D,0x2E,
  41809. 0xB3,0xAA,0x91,0xA6,0xD9,0xA4,0x4A,0x54,
  41810. 0xE0,0xD3,0x08,0xCC,0x79,0xCE,0xE4,0x15,
  41811. 0x31,0xA6,0xCE,0x61,0xCF,0x03,0x06,0xEE,
  41812. 0x8E,0xE2,0x64,0x29,0xD1,0x54,0x9B,0xD0,
  41813. 0x5F,0x09,0x2B,0x8B,0xD5,0xF8,0xD4,0x7D,
  41814. 0xF1,0x97,0x32,0xD9,0xEA,0x5A,0x0E,0x10,
  41815. 0x8C,0x4D,0xFB,0x55,0xE6,0x27,0x0C,0xBA,
  41816. 0xC1,0x73,0xC1,0x73,0xE3,0x1C,0x09,0xB3,
  41817. 0x6F,0xB4,0x12,0xFA,0xF3,0x29,0xDC,0x23,
  41818. 0x32,0xED,0x80,0x87,0x83,0xC2,0xF6,0x07,
  41819. 0xB5,0xA9,0x22,0xDE,0x66,0x1A,0xA7,0x4A,
  41820. 0x86,0xF1,0x39,0x9B,0xF4,0xE7,0x50,0x15,
  41821. 0x4A,0x55,0x3C,0x93,0xB9,0xF9,0xFD,0xDC,
  41822. 0xB3,0x5D,0x73,0x52
  41823. };
  41824. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void)
  41825. {
  41826. XmssKey verifyKey;
  41827. unsigned char pub_raw[XMSS_SHA256_PUBLEN];
  41828. word32 pub_len = sizeof(pub_raw);
  41829. word32 pkSz = 0;
  41830. word32 sigSz = 0;
  41831. const char * param = "XMSS-SHA2_10_256";
  41832. int j = 0;
  41833. int ret2 = WC_TEST_RET_ENC_NC;
  41834. int ret = WC_TEST_RET_ENC_NC;
  41835. int n_diff = 0;
  41836. WOLFSSL_ENTER("xmss_test_verify_only");
  41837. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  41838. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41839. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41840. ret = wc_XmssKey_SetParamStr(&verifyKey, param);
  41841. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41842. ret = wc_XmssKey_GetPubLen(&verifyKey, &pkSz);
  41843. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41844. if (pkSz != XMSS_SHA256_PUBLEN) {
  41845. return WC_TEST_RET_ENC_EC(pkSz);
  41846. }
  41847. ret = wc_XmssKey_GetSigLen(&verifyKey, &sigSz);
  41848. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41849. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41850. fprintf(stderr, "param: %s\n", param);
  41851. fprintf(stderr, "pkSz: %d\n", pkSz);
  41852. fprintf(stderr, "sigSz: %d\n", sigSz);
  41853. #endif
  41854. if (sigSz != sizeof(xmss_sig)) {
  41855. return WC_TEST_RET_ENC_EC(sigSz);
  41856. }
  41857. ret = wc_XmssKey_ImportPubRaw(&verifyKey, xmss_pub, XMSS_SHA256_PUBLEN);
  41858. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41859. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41860. (byte *) xmss_msg, sizeof(xmss_msg));
  41861. if (ret != 0) {
  41862. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  41863. return WC_TEST_RET_ENC_EC(ret);
  41864. }
  41865. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  41866. ret = wc_XmssKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  41867. if (ret != 0) {
  41868. printf("error: wc_XmssKey_ExportPubRaw returned %d, expected 0\n", ret);
  41869. return WC_TEST_RET_ENC_EC(ret);
  41870. }
  41871. if (pub_len != XMSS_SHA256_PUBLEN) {
  41872. printf("error: xmss pub len %u, expected %d\n", pub_len,
  41873. XMSS_SHA256_PUBLEN);
  41874. return WC_TEST_RET_ENC_EC(pub_len);
  41875. }
  41876. n_diff = XMEMCMP(pub_raw, xmss_pub, sizeof(xmss_pub));
  41877. if (n_diff != 0) {
  41878. printf("error: exported and imported pub raw do not match: %d\n",
  41879. n_diff);
  41880. return WC_TEST_RET_ENC_EC(n_diff);
  41881. }
  41882. /* Flip bits in message. This should fail. */
  41883. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  41884. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41885. (byte *) xmss_msg, sizeof(xmss_msg));
  41886. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41887. printf("error: wc_XmssKey_Verify returned %d, expected -1\n", ret2);
  41888. return WC_TEST_RET_ENC_EC(ret2);
  41889. }
  41890. /* Flip it back. This should pass again. */
  41891. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  41892. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41893. (byte *) xmss_msg, sizeof(xmss_msg));
  41894. if (ret != 0) {
  41895. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  41896. return WC_TEST_RET_ENC_EC(ret);
  41897. }
  41898. /* Flip bits in a few places throughout the signature, stepping in multiple
  41899. * of hash size. These should all fail with -1. */
  41900. for (j = 0; j < (int) sizeof(xmss_sig); j+= 4 * 32) {
  41901. xmss_sig[j] ^= 1;
  41902. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  41903. (byte *) xmss_msg, sizeof(xmss_msg));
  41904. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41905. /* Verify passed when it should have failed. */
  41906. return WC_TEST_RET_ENC_I(j);
  41907. }
  41908. /* Flip this spot back. */
  41909. xmss_sig[j] ^= 1;
  41910. }
  41911. /* Cleanup everything. */
  41912. wc_XmssKey_Free(&verifyKey);
  41913. return ret;
  41914. }
  41915. #endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_SMALL_STACK &&
  41916. * WOLFSSL_XMSS_MIN_HEIGHT <= 10 */
  41917. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  41918. static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
  41919. {
  41920. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41921. * BE USED FOR TESTING PURPOSES! Production applications should
  41922. * write only to non-volatile storage. */
  41923. XMEMCPY(context, priv, privSz);
  41924. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  41925. }
  41926. static int lms_read_key_mem(byte * priv, word32 privSz, void *context)
  41927. {
  41928. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41929. * BE USED FOR TESTING PURPOSES! */
  41930. XMEMCPY(priv, context, privSz);
  41931. return WC_LMS_RC_READ_TO_MEMORY;
  41932. }
  41933. /* LMS signature sizes are a function of their parameters. This
  41934. * test has a signature of 8688 bytes. */
  41935. #ifndef WOLFSSL_NO_LMS_SHA256_256
  41936. #define WC_TEST_LMS_SIG_LEN (8688)
  41937. #else
  41938. #define WC_TEST_LMS_SIG_LEN (4984)
  41939. #endif
  41940. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
  41941. {
  41942. int i = 0;
  41943. int j = 0;
  41944. int ret = WC_TEST_RET_ENC_NC;
  41945. int ret2 = WC_TEST_RET_ENC_NC;
  41946. int sigsLeft = 0;
  41947. LmsKey signingKey;
  41948. LmsKey verifyKey;
  41949. WC_RNG rng;
  41950. word32 sigSz = 0;
  41951. const char * msg = "LMS HSS post quantum signature test";
  41952. word32 msgSz = (word32) XSTRLEN(msg);
  41953. unsigned char priv[HSS_MAX_PRIVATE_KEY_LEN];
  41954. unsigned char old_priv[HSS_MAX_PRIVATE_KEY_LEN];
  41955. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  41956. byte * sig = XMALLOC(WC_TEST_LMS_SIG_LEN, HEAP_HINT,
  41957. DYNAMIC_TYPE_TMP_BUFFER);
  41958. if (sig == NULL) {
  41959. return WC_TEST_RET_ENC_ERRNO;
  41960. }
  41961. #else
  41962. byte sig[WC_TEST_LMS_SIG_LEN];
  41963. #endif
  41964. WOLFSSL_ENTER("lms_test");
  41965. XMEMSET(priv, 0, sizeof(priv));
  41966. XMEMSET(old_priv, 0, sizeof(old_priv));
  41967. XMEMSET(sig, 0, WC_TEST_LMS_SIG_LEN);
  41968. #ifndef HAVE_FIPS
  41969. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41970. #else
  41971. ret = wc_InitRng(&rng);
  41972. #endif
  41973. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41974. /* This test:
  41975. * levels: 1
  41976. * height: 5
  41977. * winternitz: 1
  41978. *
  41979. * max sigs: 2 ** (1 * 5) = 32
  41980. * signature length: 8688
  41981. */
  41982. ret = wc_LmsKey_Init(&signingKey, NULL, INVALID_DEVID);
  41983. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41984. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41985. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41986. ret = wc_LmsKey_SetParameters(&signingKey, 1, 5, 1);
  41987. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41988. ret = wc_LmsKey_SetWriteCb(&signingKey, lms_write_key_mem);
  41989. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41990. ret = wc_LmsKey_SetReadCb(&signingKey, lms_read_key_mem);
  41991. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41992. ret = wc_LmsKey_SetContext(&signingKey, (void *) priv);
  41993. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41994. ret = wc_LmsKey_MakeKey(&signingKey, &rng);
  41995. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41996. XMEMCPY(old_priv, priv, sizeof(priv));
  41997. ret = wc_LmsKey_ExportPub(&verifyKey, &signingKey);
  41998. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41999. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42000. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42001. if (sigSz != WC_TEST_LMS_SIG_LEN) {
  42002. printf("error: got %u, expected %d\n", sigSz, WC_TEST_LMS_SIG_LEN);
  42003. return WC_TEST_RET_ENC_EC(sigSz);
  42004. }
  42005. /* 2 ** 5 should be the max number of signatures */
  42006. for (i = 0; i < 32; ++i) {
  42007. /* We should have remaining signstures. */
  42008. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42009. if (sigsLeft == 0) {
  42010. return WC_TEST_RET_ENC_EC(sigsLeft);
  42011. }
  42012. /* Sign with key. The private key will be updated on every signature. */
  42013. ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  42014. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42015. /* The updated private key should not match the old one. */
  42016. if (XMEMCMP(old_priv, priv, sizeof(priv)) == 0) {
  42017. printf("error: current priv key should not match old: %d\n", i);
  42018. return WC_TEST_RET_ENC_I(i);
  42019. }
  42020. XMEMCPY(old_priv, priv, sizeof(priv));
  42021. ret = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  42022. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42023. /* Flip bits in a few places throughout the signature, stepping in multiple
  42024. * of hash size. These should all fail with -1. */
  42025. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42026. sig[j] ^= 1;
  42027. ret2 = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  42028. msgSz);
  42029. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42030. /* Verify passed when it should have failed. */
  42031. return WC_TEST_RET_ENC_I(j);
  42032. }
  42033. /* Flip this spot back. */
  42034. sig[j] ^= 1;
  42035. }
  42036. }
  42037. /* This should be the last signature. */
  42038. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42039. if (sigsLeft != 0) {
  42040. return WC_TEST_RET_ENC_EC(sigsLeft);
  42041. }
  42042. wc_LmsKey_Free(&signingKey);
  42043. wc_LmsKey_Free(&verifyKey);
  42044. wc_FreeRng(&rng);
  42045. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42046. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42047. #endif
  42048. return ret;
  42049. }
  42050. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  42051. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
  42052. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  42053. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  42054. /* A simple LMS verify only test.
  42055. *
  42056. * Note: LMS signature sizes are a function of their parameters. This
  42057. * test has a signature of 1456 bytes:
  42058. * levels: 1
  42059. * height: 10
  42060. * winternitz: 8
  42061. * max sigs: 2 ** (1 * 10) = 1024
  42062. * signature length: 1456
  42063. * */
  42064. /* "wolfSSL LMS example message!" without null terminator. */
  42065. static byte lms_msg[28] =
  42066. {
  42067. 0x77,0x6F,0x6C,0x66,0x53,0x53,0x4C,0x20,
  42068. 0x4C,0x4D,0x53,0x20,0x65,0x78,0x61,0x6D,
  42069. 0x70,0x6C,0x65,0x20,0x6D,0x65,0x73,0x73,
  42070. 0x61,0x67,0x65,0x21
  42071. };
  42072. static const byte lms_L1H10W8_pub[HSS_MAX_PUBLIC_KEY_LEN] =
  42073. {
  42074. 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,
  42075. 0x00,0x00,0x00,0x04,0xA1,0x26,0x76,0xF8,
  42076. 0xBB,0x0B,0xC0,0x82,0x21,0x71,0x0B,0x2E,
  42077. 0x8C,0xA6,0xEF,0x12,0xED,0x41,0x0E,0x8C,
  42078. 0xAF,0x11,0x93,0x34,0x7B,0x49,0x79,0xB7,
  42079. 0xDE,0x63,0x1C,0xFE,0x1F,0xD1,0x17,0x49,
  42080. 0xCD,0x5C,0xD4,0x26,0xA0,0x53,0x26,0x1A,
  42081. 0xC5,0xB4,0x8F,0x23
  42082. };
  42083. #define LMS_L1H10W8_SIGLEN (1456)
  42084. static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
  42085. {
  42086. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  42087. 0x00,0x00,0x00,0x04,0x18,0x70,0x09,0x2E,
  42088. 0x21,0xC9,0x6A,0xC9,0x5C,0xB6,0xB0,0xAA,
  42089. 0xC3,0xED,0x6E,0x66,0x2F,0xCC,0x45,0x81,
  42090. 0xBC,0xBA,0x44,0x96,0x1C,0xBF,0x4E,0xFB,
  42091. 0x7A,0x46,0xFB,0xBE,0x9A,0x0C,0xE4,0x50,
  42092. 0x90,0xC7,0x92,0xAC,0x53,0xAE,0x53,0x76,
  42093. 0x29,0xA6,0x65,0xF1,0x09,0xED,0x1A,0x8E,
  42094. 0x03,0x2E,0x5A,0x06,0x51,0xE3,0x1E,0xE6,
  42095. 0xF6,0xFE,0x3A,0x6E,0xD1,0x92,0x31,0x1D,
  42096. 0xA1,0x6A,0x5C,0x30,0x3A,0xC7,0xFD,0x5B,
  42097. 0xFE,0x71,0x2C,0x5C,0x2F,0x5B,0x5B,0xCF,
  42098. 0xBC,0x7F,0xBF,0x6C,0xAF,0x44,0x8A,0xAE,
  42099. 0x14,0x60,0xAB,0x88,0xED,0x0E,0x4F,0xF8,
  42100. 0xC7,0x1B,0x74,0x28,0x72,0xB3,0x96,0xA6,
  42101. 0xE6,0x46,0x22,0x82,0xCF,0x1F,0x4D,0xA6,
  42102. 0xEA,0x22,0x06,0x07,0x52,0xF5,0x26,0x16,
  42103. 0x0B,0x90,0xE3,0xFF,0x64,0xA9,0xE4,0x61,
  42104. 0x1E,0x9C,0x12,0x9C,0xF6,0xD4,0x63,0x29,
  42105. 0xEA,0x02,0xF7,0x18,0x52,0x79,0x6C,0x43,
  42106. 0xDC,0xCF,0x43,0x23,0xB9,0xCC,0x4A,0x25,
  42107. 0x9D,0x10,0xAF,0xA3,0xE6,0x47,0x5A,0x1C,
  42108. 0xFE,0x68,0x89,0xAF,0x1B,0x2D,0x88,0x3E,
  42109. 0xCA,0xDC,0x70,0xEA,0xAC,0x11,0x00,0x8A,
  42110. 0x6E,0xE0,0xC7,0xD0,0xD2,0x1A,0x36,0x18,
  42111. 0x97,0xB3,0x5F,0x0E,0x75,0x48,0x28,0xF8,
  42112. 0xA8,0xF5,0x90,0xD1,0xA1,0x84,0xFB,0xA4,
  42113. 0xAD,0x50,0xBE,0xE9,0x39,0x8C,0xC5,0xA1,
  42114. 0x67,0x51,0xA1,0x8C,0xD6,0x6B,0x97,0x1F,
  42115. 0x47,0x99,0xEE,0xE0,0x70,0x01,0xC7,0x07,
  42116. 0x50,0xF3,0x5E,0x3F,0xE7,0x06,0xD6,0x8D,
  42117. 0x26,0xD6,0x5A,0x59,0x18,0x72,0x6B,0x12,
  42118. 0xD2,0xAF,0x9B,0xB4,0x2B,0xD0,0xB2,0xF2,
  42119. 0x96,0x2F,0x40,0xEA,0xBE,0xE6,0xAC,0x1F,
  42120. 0xB8,0x33,0xC2,0x76,0xDC,0x8C,0xAC,0xC1,
  42121. 0x46,0x5E,0x04,0x84,0x1B,0xC8,0xB9,0x65,
  42122. 0x8D,0xAD,0x96,0xB5,0xB1,0xF6,0x17,0x4A,
  42123. 0x19,0x87,0xE7,0xBF,0x29,0xC7,0x9B,0xB9,
  42124. 0xD6,0x11,0x2C,0x92,0x2F,0xB7,0x24,0xD5,
  42125. 0x01,0x1D,0x80,0x37,0x54,0xED,0x33,0x32,
  42126. 0xAB,0x7A,0x12,0xD4,0x02,0x1D,0x27,0x52,
  42127. 0x89,0xDB,0x32,0xBF,0x61,0xD4,0xBB,0xB4,
  42128. 0x46,0x78,0x1B,0x64,0x17,0x84,0x4B,0x8A,
  42129. 0xBA,0xC6,0xC1,0xCF,0xC7,0x5D,0x8F,0x93,
  42130. 0xC5,0x9A,0x27,0x90,0xAC,0x17,0x98,0xFF,
  42131. 0xC8,0x22,0x59,0x55,0x90,0xB2,0x29,0x39,
  42132. 0xA0,0xBE,0x00,0x23,0x55,0x6B,0xDA,0x83,
  42133. 0xD8,0x5B,0x57,0x7C,0x67,0x1B,0xC3,0x6B,
  42134. 0x6D,0xC7,0x9B,0x2B,0x9E,0xB7,0x95,0xB3,
  42135. 0xF0,0x1B,0x89,0x5A,0xD7,0x4B,0x67,0xAF,
  42136. 0xDC,0x9E,0xCF,0x7E,0x1A,0xBA,0x1B,0xB9,
  42137. 0x3B,0x7A,0xDD,0x3F,0x0D,0xEE,0x4C,0x0B,
  42138. 0xD1,0x4F,0x34,0xF2,0x93,0xF7,0x21,0x64,
  42139. 0x2C,0x07,0x00,0x15,0x4F,0xE3,0x6A,0x9F,
  42140. 0x08,0x52,0xC2,0x65,0x47,0x1F,0x34,0x64,
  42141. 0x66,0x07,0xBC,0xEA,0xAF,0x9B,0xAA,0x39,
  42142. 0x15,0x8B,0x08,0x8C,0x24,0x41,0x9B,0x46,
  42143. 0x1B,0x5B,0x91,0x11,0xC4,0xFD,0xA9,0x88,
  42144. 0x35,0x0E,0x7D,0xAF,0xFD,0xB7,0x90,0x7E,
  42145. 0xD7,0x29,0x02,0x0A,0xDC,0xC8,0x3F,0xC0,
  42146. 0xFD,0x97,0xAF,0x50,0x49,0xA6,0x5E,0x12,
  42147. 0xC1,0xCD,0xEC,0x52,0xC5,0x51,0xF2,0x80,
  42148. 0x17,0x61,0xC7,0x7E,0xBE,0xD1,0x1B,0x65,
  42149. 0xA4,0xAB,0x92,0x8D,0x89,0xB2,0xC5,0x8F,
  42150. 0xFF,0xA5,0x6F,0xFA,0x62,0x75,0xE4,0xA1,
  42151. 0xD4,0x22,0xA8,0x9E,0x40,0x04,0x27,0x1F,
  42152. 0xCC,0x81,0xBA,0x28,0x67,0xA0,0x1C,0x80,
  42153. 0xEB,0xCA,0xB0,0x61,0xA5,0x48,0xD0,0x8A,
  42154. 0x25,0xEB,0x9E,0x67,0x8C,0x8E,0x9B,0xD1,
  42155. 0xAD,0xBB,0xC3,0xEA,0xD3,0xD4,0xC5,0x12,
  42156. 0x7B,0xDD,0x00,0x57,0x7F,0xF6,0xF7,0xF6,
  42157. 0x3C,0x05,0xCF,0xFC,0x12,0xE1,0x93,0x05,
  42158. 0xE5,0x9B,0x79,0x87,0x69,0xD8,0x82,0xD9,
  42159. 0xD7,0x1D,0x41,0x73,0xE4,0x52,0x1D,0x3E,
  42160. 0xE5,0x8C,0x8D,0x34,0xE1,0x75,0xA9,0xF1,
  42161. 0x9D,0x09,0xA2,0x5B,0xEF,0xDA,0x96,0x6E,
  42162. 0x76,0x3D,0xEA,0x50,0xD9,0xCF,0x4F,0xAC,
  42163. 0xAD,0x1D,0x35,0x72,0x1B,0x88,0x8B,0xCD,
  42164. 0x8C,0x8A,0x8A,0xE0,0x96,0x04,0xD8,0xBB,
  42165. 0x28,0x43,0x16,0x77,0x60,0x98,0x63,0xF9,
  42166. 0xB9,0x71,0x46,0xB7,0xE1,0xA7,0xA9,0x84,
  42167. 0xC3,0x65,0x82,0xE1,0x1B,0x67,0x04,0x2D,
  42168. 0x55,0x6B,0xF9,0xC0,0x79,0x09,0x09,0xE7,
  42169. 0xFD,0x06,0x4D,0x09,0x9B,0x1A,0xCE,0x35,
  42170. 0xFA,0x27,0x6F,0x2F,0x01,0x65,0x0D,0xA0,
  42171. 0x97,0x59,0x11,0xF0,0x48,0xD2,0xE7,0x46,
  42172. 0xBE,0xB4,0x0A,0xA3,0xE2,0x75,0x0E,0x09,
  42173. 0x94,0xD9,0x69,0x28,0xD4,0xDA,0x64,0xBA,
  42174. 0xFE,0xA4,0xB9,0xF0,0xBA,0xEB,0xBA,0xAC,
  42175. 0xA8,0xF9,0xD3,0x82,0x4C,0x36,0x80,0xFA,
  42176. 0xE5,0xF6,0x76,0xC3,0x80,0xFA,0x90,0x29,
  42177. 0xF4,0x85,0xA4,0xC6,0x25,0x22,0x79,0x7E,
  42178. 0x39,0x1E,0x30,0xB8,0x65,0x72,0xCF,0xE1,
  42179. 0x99,0xF0,0x75,0xE8,0x09,0xB4,0x92,0x96,
  42180. 0x1B,0x68,0x50,0x88,0xF1,0x2C,0x97,0xE3,
  42181. 0x2D,0x26,0x8F,0xC5,0x30,0xCF,0x24,0xCB,
  42182. 0xB2,0x60,0x77,0xDC,0x02,0x72,0x0D,0xD9,
  42183. 0x2E,0xF2,0x52,0xEA,0x00,0xF6,0x32,0x65,
  42184. 0xA5,0xC6,0x43,0x29,0x29,0x69,0xAB,0x27,
  42185. 0x0C,0x39,0xDF,0x76,0x3E,0x93,0x95,0xB1,
  42186. 0x2C,0xA2,0x0D,0x18,0xCE,0xA0,0x97,0x10,
  42187. 0x3C,0x90,0xC0,0xEF,0x0E,0x04,0xA6,0xC8,
  42188. 0xA0,0x21,0x3C,0x0B,0x22,0x77,0x7A,0x66,
  42189. 0xA5,0x90,0x25,0xA4,0x09,0x3E,0xD5,0x27,
  42190. 0x1F,0x6C,0x99,0x85,0x5C,0xA2,0x99,0x7A,
  42191. 0x25,0xEE,0x8D,0x32,0x3D,0xD3,0xDC,0xF5,
  42192. 0x00,0x5A,0x34,0x61,0xB6,0xCD,0x4E,0xBC,
  42193. 0x26,0x36,0xFB,0x44,0x97,0x35,0xBD,0x06,
  42194. 0x7D,0x2E,0x4A,0xA2,0xDC,0x24,0xFE,0x70,
  42195. 0x0A,0xF9,0x57,0xE3,0xEE,0xAB,0xD1,0x17,
  42196. 0xF3,0x7C,0xD6,0x37,0x26,0xFA,0x83,0x9F,
  42197. 0xDD,0xB2,0xE1,0xD7,0xF9,0xC7,0x0E,0x15,
  42198. 0x01,0xA6,0x58,0x32,0x98,0x04,0x32,0xD4,
  42199. 0xDE,0xB9,0xEF,0x09,0xFA,0xE4,0x5A,0xD7,
  42200. 0xDD,0x09,0x1C,0xC9,0xAC,0xB8,0x6A,0xF5,
  42201. 0x00,0x5D,0x6B,0x95,0x12,0x8C,0x2F,0xCC,
  42202. 0xD8,0xB9,0x50,0x3A,0xEB,0x74,0x86,0xD2,
  42203. 0x3F,0xA1,0x05,0x8F,0x6E,0xEF,0xF5,0xA4,
  42204. 0xD6,0x6E,0x53,0xFA,0x9E,0xFA,0xCE,0xDB,
  42205. 0x99,0x46,0xE7,0xC5,0xDA,0x92,0x51,0x4F,
  42206. 0x22,0x07,0xF3,0xA5,0x38,0x26,0xD3,0xEC,
  42207. 0xD6,0x01,0xDD,0x31,0x3A,0x48,0x93,0xF6,
  42208. 0x69,0x4F,0xD8,0xF6,0xC2,0x91,0xA5,0x7C,
  42209. 0xDF,0x51,0x64,0xF1,0x3B,0x79,0xBC,0x0A,
  42210. 0x2C,0xDC,0x33,0x5A,0x29,0xF6,0xB2,0x09,
  42211. 0x66,0xCA,0x24,0x9F,0x1A,0x18,0xF3,0x76,
  42212. 0x4C,0x5E,0x0B,0x81,0x7F,0x29,0x84,0xD8,
  42213. 0x7A,0xA8,0xD6,0x11,0xAC,0xEC,0xD9,0x07,
  42214. 0x91,0xEC,0xB6,0x6D,0xEC,0xDB,0xBE,0x6F,
  42215. 0x9F,0xC5,0x19,0x5E,0x56,0x87,0x20,0x80,
  42216. 0x75,0xD5,0x64,0xE9,0x80,0xBF,0x2D,0xD5,
  42217. 0x94,0x9F,0x8C,0xA4,0x54,0x41,0xAB,0xB1,
  42218. 0x8E,0xAD,0x51,0xE4,0x3C,0x24,0xF7,0x1D,
  42219. 0xFE,0x02,0x48,0x7C,0x6D,0xED,0xF1,0xAC,
  42220. 0xD9,0x79,0x42,0xE5,0x3A,0xCF,0x6A,0x4C,
  42221. 0x6D,0xE2,0x13,0xD2,0x2B,0x9D,0xAB,0x1F,
  42222. 0x70,0xD3,0xC0,0x6F,0x81,0xE9,0x9A,0x86,
  42223. 0x33,0x39,0x60,0xE7,0x6A,0x00,0x1F,0x97,
  42224. 0xEB,0xE5,0x1D,0x0D,0x66,0x15,0xC9,0xA2,
  42225. 0xB1,0xC0,0xF0,0x2E,0xF4,0x07,0xA2,0x2E,
  42226. 0x49,0x92,0x95,0x13,0xA3,0x18,0x46,0x25,
  42227. 0xB9,0x3C,0xA1,0x4B,0x00,0x00,0x00,0x06,
  42228. 0xAB,0xAA,0xF9,0x3F,0x7E,0x21,0xF4,0x0E,
  42229. 0xCE,0xFD,0xE0,0x44,0xAC,0xC7,0x1A,0x30,
  42230. 0x22,0x9D,0x0A,0xD7,0x96,0x2D,0x8F,0x9A,
  42231. 0x99,0x1F,0x40,0x75,0x7F,0x62,0xF9,0xC1,
  42232. 0x81,0x7B,0x4A,0x1B,0xFA,0xD6,0x87,0xB9,
  42233. 0xEF,0x58,0x48,0xE4,0x5C,0x79,0xE5,0xB1,
  42234. 0x2C,0x59,0xA4,0x42,0xDB,0xA6,0x53,0x70,
  42235. 0x80,0x61,0x17,0xD4,0xD3,0x77,0xBD,0x53,
  42236. 0x26,0x7C,0x0E,0x0E,0xFF,0x30,0x4B,0xD0,
  42237. 0x86,0xFC,0x02,0x20,0x24,0x46,0x5B,0xF5,
  42238. 0xE3,0x99,0x73,0x85,0x60,0x00,0x36,0x47,
  42239. 0x17,0xEE,0x0C,0xD2,0x80,0x71,0x46,0x0E,
  42240. 0x2B,0xB0,0xEF,0x7F,0xFE,0x3B,0xE5,0xE1,
  42241. 0x87,0xC2,0xAF,0x1A,0x6F,0x63,0xF4,0x5A,
  42242. 0xC4,0x16,0xF7,0xAD,0x07,0x70,0x71,0x85,
  42243. 0x7D,0x3D,0x67,0x08,0xB8,0xD8,0xE2,0xF0,
  42244. 0xA1,0xAC,0xD2,0x94,0x7D,0x93,0x03,0xDD,
  42245. 0x54,0xF9,0x64,0x19,0xB3,0xED,0x24,0x22,
  42246. 0x01,0xD7,0x12,0x5E,0xC1,0x2B,0x39,0x10,
  42247. 0x13,0xE2,0x56,0x1C,0xEE,0xF4,0x2A,0x49,
  42248. 0x7B,0xFB,0x36,0x8D,0xF8,0xAF,0x60,0xDF,
  42249. 0x10,0xF0,0x72,0xA2,0xED,0xB6,0x53,0x88,
  42250. 0xA9,0x0C,0xED,0x9C,0x18,0x33,0x7D,0x65,
  42251. 0x9B,0xB2,0x9C,0x3E,0xE9,0x1E,0x43,0x51,
  42252. 0x7E,0xBE,0x01,0x95,0xF6,0x60,0x65,0xBE,
  42253. 0xD1,0xF4,0xE2,0x83,0x6B,0xCA,0x7A,0x70,
  42254. 0x41,0x83,0x72,0xC0,0x23,0x51,0x13,0x11,
  42255. 0x2D,0xF9,0xC0,0x0D,0x7D,0x73,0x76,0xA5,
  42256. 0x30,0x83,0x68,0x10,0x35,0xA2,0x18,0x22,
  42257. 0x4E,0x21,0x93,0x27,0x6A,0x19,0x28,0x83,
  42258. 0x7F,0xDD,0xDD,0xFF,0xC3,0x8A,0x64,0x00,
  42259. 0x5F,0x1C,0x0D,0xF8,0xBB,0xD7,0x15,0xB9,
  42260. 0xEF,0xE0,0x07,0x62,0x05,0x9E,0xCF,0xFC,
  42261. 0x08,0x52,0x1E,0x65,0x41,0x56,0x6A,0xEB,
  42262. 0x81,0x53,0x30,0x7B,0xF2,0xFD,0x65,0xFF,
  42263. 0xA2,0x14,0xF5,0x62,0x1E,0x24,0x48,0x47,
  42264. 0xA5,0x41,0x80,0xB4,0xC5,0xDC,0xB2,0xB4,
  42265. 0x2D,0x17,0xE7,0xBE,0x49,0x53,0x7A,0x25,
  42266. 0xC5,0x0D,0x19,0x59,0xF4,0x88,0x59,0xED,
  42267. 0x92,0x13,0xEE,0x7A,0x4F,0x12,0x98,0x4C
  42268. };
  42269. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
  42270. {
  42271. LmsKey verifyKey;
  42272. unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
  42273. word32 pub_len = sizeof(pub_raw);
  42274. word32 sigSz = 0;
  42275. word32 msgSz = sizeof(lms_msg);
  42276. word32 pubSz = 0;
  42277. int levels = 0;
  42278. int height = 0;
  42279. int winternitz = 0;
  42280. int ret = WC_TEST_RET_ENC_NC;
  42281. int ret2 = WC_TEST_RET_ENC_NC;
  42282. int j = 0;
  42283. int n_diff = 0;
  42284. WOLFSSL_ENTER("lms_test_verify_only");
  42285. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42286. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42287. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42288. ret = wc_LmsKey_SetParameters(&verifyKey, 1, 10, 8);
  42289. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42290. ret = wc_LmsKey_ImportPubRaw(&verifyKey, lms_L1H10W8_pub,
  42291. HSS_MAX_PUBLIC_KEY_LEN);
  42292. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42293. /* Verify parameters, pub length, and sig length are correct. */
  42294. ret = wc_LmsKey_GetParameters(&verifyKey, &levels, &height, &winternitz);
  42295. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42296. if (levels != 1 || height != 10 || winternitz != 8) {
  42297. printf("error: invalid LMS parameters: L%d-H%d-W%d\n", levels, height,
  42298. winternitz);
  42299. return WC_TEST_RET_ENC_NC;
  42300. }
  42301. ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
  42302. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42303. if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
  42304. printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
  42305. return WC_TEST_RET_ENC_EC(pubSz);
  42306. }
  42307. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42308. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42309. if (sigSz != LMS_L1H10W8_SIGLEN) {
  42310. printf("error: got %u, expected %d\n", sigSz, LMS_L1H10W8_SIGLEN);
  42311. return WC_TEST_RET_ENC_EC(sigSz);
  42312. }
  42313. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42314. (byte *) lms_msg, msgSz);
  42315. if (ret != 0) {
  42316. printf("error: wc_LmsKey_Verify returned %d\n", ret);
  42317. return WC_TEST_RET_ENC_EC(ret);
  42318. }
  42319. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42320. ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42321. if (ret != 0) {
  42322. printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
  42323. return WC_TEST_RET_ENC_EC(ret);
  42324. }
  42325. if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
  42326. printf("error: LMS pub len %u, expected %d\n", pub_len,
  42327. HSS_MAX_PUBLIC_KEY_LEN);
  42328. return WC_TEST_RET_ENC_EC(pub_len);
  42329. }
  42330. n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
  42331. if (n_diff != 0) {
  42332. printf("error: exported and imported pub raw do not match: %d\n",
  42333. n_diff);
  42334. return WC_TEST_RET_ENC_EC(n_diff);
  42335. }
  42336. /* Flip bits in message. This should fail. */
  42337. lms_msg[msgSz / 2] ^= 1;
  42338. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42339. (byte *) lms_msg, msgSz);
  42340. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42341. printf("error: wc_LmsKey_Verify returned %d, expected -1\n", ret2);
  42342. return WC_TEST_RET_ENC_EC(ret);
  42343. }
  42344. /* Flip it back. This should pass again. */
  42345. lms_msg[msgSz / 2] ^= 1;
  42346. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42347. (byte *) lms_msg, msgSz);
  42348. if (ret != 0) {
  42349. printf("error: wc_LmsKey_Verify returned %d, expected 0\n", ret);
  42350. return WC_TEST_RET_ENC_EC(ret);
  42351. }
  42352. /* Flip bits in a few places throughout the signature, stepping in multiple
  42353. * of hash size. These should all fail with -1. */
  42354. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42355. lms_L1H10W8_sig[j] ^= 1;
  42356. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig,
  42357. LMS_L1H10W8_SIGLEN,
  42358. (byte *) lms_msg, msgSz);
  42359. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42360. /* Verify passed when it should have failed. */
  42361. return WC_TEST_RET_ENC_I(j);
  42362. }
  42363. /* Flip this spot back. */
  42364. lms_L1H10W8_sig[j] ^= 1;
  42365. }
  42366. wc_LmsKey_Free(&verifyKey);
  42367. return ret;
  42368. }
  42369. #endif
  42370. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK) */
  42371. static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --
  42372. * see print_fiducials() below.
  42373. */
  42374. #ifdef WOLFCRYPT_HAVE_ECCSI
  42375. static wc_test_ret_t eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk,
  42376. ecc_point* pvt)
  42377. {
  42378. wc_test_ret_t ret;
  42379. byte id[1] = { 0x00 };
  42380. int valid;
  42381. word32 sz;
  42382. byte data[256];
  42383. byte hash[WC_MAX_DIGEST_SIZE];
  42384. byte hashSz;
  42385. byte sig[257];
  42386. word32 sigSz;
  42387. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42388. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42389. return WC_TEST_RET_ENC_EC(ret);
  42390. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42391. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42392. return WC_TEST_RET_ENC_EC(ret);
  42393. ret = wc_InitEccsiKey(NULL, NULL, INVALID_DEVID);
  42394. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42395. return WC_TEST_RET_ENC_EC(ret);
  42396. ret = wc_InitEccsiKey(NULL, HEAP_HINT, INVALID_DEVID);
  42397. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42398. return WC_TEST_RET_ENC_EC(ret);
  42399. wc_FreeEccsiKey(NULL);
  42400. /* Create a valid key. */
  42401. ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID);
  42402. if (ret != 0)
  42403. return WC_TEST_RET_ENC_EC(ret);
  42404. ret = wc_MakeEccsiKey(NULL, NULL);
  42405. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42406. return WC_TEST_RET_ENC_EC(ret);
  42407. ret = wc_MakeEccsiKey(key, NULL);
  42408. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42409. return WC_TEST_RET_ENC_EC(ret);
  42410. ret = wc_MakeEccsiKey(NULL, rng);
  42411. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42412. return WC_TEST_RET_ENC_EC(ret);
  42413. ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL,
  42414. NULL);
  42415. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42416. return WC_TEST_RET_ENC_EC(ret);
  42417. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL);
  42418. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42419. return WC_TEST_RET_ENC_EC(ret);
  42420. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt);
  42421. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42422. return WC_TEST_RET_ENC_EC(ret);
  42423. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt);
  42424. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42425. return WC_TEST_RET_ENC_EC(ret);
  42426. ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42427. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42428. return WC_TEST_RET_ENC_EC(ret);
  42429. ret = wc_MakeEccsiPair(NULL, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42430. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42431. return WC_TEST_RET_ENC_EC(ret);
  42432. /* No key set */
  42433. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42434. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42435. return WC_TEST_RET_ENC_EC(ret);
  42436. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL,
  42437. NULL);
  42438. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42439. return WC_TEST_RET_ENC_EC(ret);
  42440. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42441. NULL);
  42442. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42443. return WC_TEST_RET_ENC_EC(ret);
  42444. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL,
  42445. &valid);
  42446. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42447. return WC_TEST_RET_ENC_EC(ret);
  42448. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt,
  42449. &valid);
  42450. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42451. return WC_TEST_RET_ENC_EC(ret);
  42452. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt,
  42453. &valid);
  42454. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42455. return WC_TEST_RET_ENC_EC(ret);
  42456. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42457. &valid);
  42458. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42459. return WC_TEST_RET_ENC_EC(ret);
  42460. /* No key set */
  42461. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42462. &valid);
  42463. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42464. return WC_TEST_RET_ENC_EC(ret);
  42465. ret = wc_ValidateEccsiPvt(NULL, NULL, NULL);
  42466. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42467. return WC_TEST_RET_ENC_EC(ret);
  42468. ret = wc_ValidateEccsiPvt(key, NULL, NULL);
  42469. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42470. return WC_TEST_RET_ENC_EC(ret);
  42471. ret = wc_ValidateEccsiPvt(NULL, pvt, NULL);
  42472. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42473. return WC_TEST_RET_ENC_EC(ret);
  42474. ret = wc_ValidateEccsiPvt(NULL, NULL, &valid);
  42475. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42476. return WC_TEST_RET_ENC_EC(ret);
  42477. ret = wc_ValidateEccsiPvt(key, pvt, NULL);
  42478. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42479. return WC_TEST_RET_ENC_EC(ret);
  42480. ret = wc_ValidateEccsiPvt(key, NULL, &valid);
  42481. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42482. return WC_TEST_RET_ENC_EC(ret);
  42483. ret = wc_ValidateEccsiPvt(NULL, pvt, &valid);
  42484. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42485. return WC_TEST_RET_ENC_EC(ret);
  42486. ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL);
  42487. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42488. return WC_TEST_RET_ENC_EC(ret);
  42489. ret = wc_EncodeEccsiPair(key, ssk, pvt, data, NULL);
  42490. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42491. return WC_TEST_RET_ENC_EC(ret);
  42492. ret = wc_EncodeEccsiPair(key, ssk, NULL, data, &sz);
  42493. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42494. return WC_TEST_RET_ENC_EC(ret);
  42495. ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz);
  42496. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42497. return WC_TEST_RET_ENC_EC(ret);
  42498. ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz);
  42499. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42500. return WC_TEST_RET_ENC_EC(ret);
  42501. /* No key created so no curve information. */
  42502. ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz);
  42503. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42504. return WC_TEST_RET_ENC_EC(ret);
  42505. ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL);
  42506. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42507. return WC_TEST_RET_ENC_EC(ret);
  42508. ret = wc_EncodeEccsiSsk(key, ssk, data, NULL);
  42509. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42510. return WC_TEST_RET_ENC_EC(ret);
  42511. ret = wc_EncodeEccsiSsk(key, NULL, data, &sz);
  42512. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42513. return WC_TEST_RET_ENC_EC(ret);
  42514. ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz);
  42515. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42516. return WC_TEST_RET_ENC_EC(ret);
  42517. ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1);
  42518. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42519. return WC_TEST_RET_ENC_EC(ret);
  42520. ret = wc_EncodeEccsiPvt(key, pvt, data, NULL, 1);
  42521. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42522. return WC_TEST_RET_ENC_EC(ret);
  42523. ret = wc_EncodeEccsiPvt(key, NULL, data, &sz, 1);
  42524. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42525. return WC_TEST_RET_ENC_EC(ret);
  42526. ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1);
  42527. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42528. return WC_TEST_RET_ENC_EC(ret);
  42529. ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL);
  42530. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42531. return WC_TEST_RET_ENC_EC(ret);
  42532. ret = wc_DecodeEccsiPair(key, data, 0, ssk, NULL);
  42533. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42534. return WC_TEST_RET_ENC_EC(ret);
  42535. ret = wc_DecodeEccsiPair(key, data, 0, NULL, pvt);
  42536. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42537. return WC_TEST_RET_ENC_EC(ret);
  42538. ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt);
  42539. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42540. return WC_TEST_RET_ENC_EC(ret);
  42541. ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt);
  42542. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42543. return WC_TEST_RET_ENC_EC(ret);
  42544. ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL);
  42545. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42546. return WC_TEST_RET_ENC_EC(ret);
  42547. ret = wc_DecodeEccsiSsk(key, data, 0, NULL);
  42548. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42549. return WC_TEST_RET_ENC_EC(ret);
  42550. ret = wc_DecodeEccsiSsk(key, NULL, 0, ssk);
  42551. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42552. return WC_TEST_RET_ENC_EC(ret);
  42553. ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk);
  42554. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42555. return WC_TEST_RET_ENC_EC(ret);
  42556. ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL);
  42557. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42558. return WC_TEST_RET_ENC_EC(ret);
  42559. ret = wc_DecodeEccsiPvt(key, data, 0, NULL);
  42560. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42561. return WC_TEST_RET_ENC_EC(ret);
  42562. ret = wc_DecodeEccsiPvt(key, NULL, 0, pvt);
  42563. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42564. return WC_TEST_RET_ENC_EC(ret);
  42565. ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt);
  42566. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42567. return WC_TEST_RET_ENC_EC(ret);
  42568. ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL);
  42569. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42570. return WC_TEST_RET_ENC_EC(ret);
  42571. ret = wc_DecodeEccsiPvtFromSig(key, data, 0, NULL);
  42572. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42573. return WC_TEST_RET_ENC_EC(ret);
  42574. ret = wc_DecodeEccsiPvtFromSig(key, NULL, 0, pvt);
  42575. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42576. return WC_TEST_RET_ENC_EC(ret);
  42577. ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt);
  42578. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42579. return WC_TEST_RET_ENC_EC(ret);
  42580. ret = wc_ExportEccsiKey(NULL, data, NULL);
  42581. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42582. return WC_TEST_RET_ENC_EC(ret);
  42583. ret = wc_ExportEccsiKey(key, data, NULL);
  42584. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42585. return WC_TEST_RET_ENC_EC(ret);
  42586. ret = wc_ExportEccsiKey(NULL, data, &sz);
  42587. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42588. return WC_TEST_RET_ENC_EC(ret);
  42589. /* No key to export */
  42590. ret = wc_ExportEccsiKey(key, NULL, &sz);
  42591. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42592. return WC_TEST_RET_ENC_EC(ret);
  42593. ret = wc_ImportEccsiKey(NULL, NULL, 0);
  42594. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42595. return WC_TEST_RET_ENC_EC(ret);
  42596. ret = wc_ImportEccsiKey(key, NULL, 0);
  42597. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42598. return WC_TEST_RET_ENC_EC(ret);
  42599. ret = wc_ImportEccsiKey(NULL, data, 0);
  42600. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42601. return WC_TEST_RET_ENC_EC(ret);
  42602. ret = wc_ExportEccsiPrivateKey(NULL, data, NULL);
  42603. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42604. return WC_TEST_RET_ENC_EC(ret);
  42605. ret = wc_ExportEccsiPrivateKey(key, data, NULL);
  42606. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42607. return WC_TEST_RET_ENC_EC(ret);
  42608. ret = wc_ExportEccsiPrivateKey(NULL, data, &sz);
  42609. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42610. return WC_TEST_RET_ENC_EC(ret);
  42611. /* No key to export */
  42612. ret = wc_ExportEccsiPrivateKey(key, NULL, &sz);
  42613. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42614. return WC_TEST_RET_ENC_EC(ret);
  42615. ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0);
  42616. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42617. return WC_TEST_RET_ENC_EC(ret);
  42618. ret = wc_ImportEccsiPrivateKey(key, NULL, 0);
  42619. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42620. return WC_TEST_RET_ENC_EC(ret);
  42621. ret = wc_ImportEccsiPrivateKey(NULL, data, 0);
  42622. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42623. return WC_TEST_RET_ENC_EC(ret);
  42624. ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1);
  42625. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42626. return WC_TEST_RET_ENC_EC(ret);
  42627. ret = wc_ExportEccsiPublicKey(key, data, NULL, 1);
  42628. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42629. return WC_TEST_RET_ENC_EC(ret);
  42630. ret = wc_ExportEccsiPublicKey(NULL, data, &sz, 1);
  42631. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42632. return WC_TEST_RET_ENC_EC(ret);
  42633. /* No key to export */
  42634. ret = wc_ExportEccsiPublicKey(key, data, &sz, 1);
  42635. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42636. return WC_TEST_RET_ENC_EC(ret);
  42637. ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1);
  42638. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42639. return WC_TEST_RET_ENC_EC(ret);
  42640. ret = wc_ImportEccsiPublicKey(key, NULL, 0, 1);
  42641. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42642. return WC_TEST_RET_ENC_EC(ret);
  42643. ret = wc_ImportEccsiPublicKey(NULL, data, 0, 1);
  42644. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42645. return WC_TEST_RET_ENC_EC(ret);
  42646. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL);
  42647. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42648. return WC_TEST_RET_ENC_EC(ret);
  42649. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, NULL);
  42650. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42651. return WC_TEST_RET_ENC_EC(ret);
  42652. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, NULL, &hashSz);
  42653. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42654. return WC_TEST_RET_ENC_EC(ret);
  42655. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, NULL, hash, &hashSz);
  42656. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42657. return WC_TEST_RET_ENC_EC(ret);
  42658. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, NULL, 1, pvt, hash,
  42659. &hashSz);
  42660. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42661. return WC_TEST_RET_ENC_EC(ret);
  42662. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  42663. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42664. return WC_TEST_RET_ENC_EC(ret);
  42665. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  42666. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42667. return WC_TEST_RET_ENC_EC(ret);
  42668. ret = wc_SetEccsiHash(NULL, NULL, 1);
  42669. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42670. return WC_TEST_RET_ENC_EC(ret);
  42671. ret = wc_SetEccsiHash(key, NULL, 1);
  42672. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42673. return WC_TEST_RET_ENC_EC(ret);
  42674. ret = wc_SetEccsiHash(NULL, hash, 1);
  42675. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42676. return WC_TEST_RET_ENC_EC(ret);
  42677. ret = wc_SetEccsiPair(NULL, NULL, NULL);
  42678. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42679. return WC_TEST_RET_ENC_EC(ret);
  42680. ret = wc_SetEccsiPair(key, NULL, NULL);
  42681. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42682. return WC_TEST_RET_ENC_EC(ret);
  42683. ret = wc_SetEccsiPair(NULL, ssk, NULL);
  42684. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42685. return WC_TEST_RET_ENC_EC(ret);
  42686. ret = wc_SetEccsiPair(NULL, NULL, pvt);
  42687. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42688. return WC_TEST_RET_ENC_EC(ret);
  42689. ret = wc_SetEccsiPair(key, ssk, NULL);
  42690. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42691. return WC_TEST_RET_ENC_EC(ret);
  42692. ret = wc_SetEccsiPair(key, NULL, pvt);
  42693. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42694. return WC_TEST_RET_ENC_EC(ret);
  42695. ret = wc_SetEccsiPair(NULL, ssk, pvt);
  42696. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42697. return WC_TEST_RET_ENC_EC(ret);
  42698. ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL);
  42699. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42700. return WC_TEST_RET_ENC_EC(ret);
  42701. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, sig, NULL);
  42702. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42703. return WC_TEST_RET_ENC_EC(ret);
  42704. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, NULL, 0, sig,
  42705. &sigSz);
  42706. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42707. return WC_TEST_RET_ENC_EC(ret);
  42708. ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig,
  42709. &sigSz);
  42710. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42711. return WC_TEST_RET_ENC_EC(ret);
  42712. ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig,
  42713. &sigSz);
  42714. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42715. return WC_TEST_RET_ENC_EC(ret);
  42716. /* Key not set. */
  42717. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  42718. &sigSz);
  42719. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42720. return WC_TEST_RET_ENC_EC(ret);
  42721. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  42722. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42723. return WC_TEST_RET_ENC_EC(ret);
  42724. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  42725. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42726. return WC_TEST_RET_ENC_EC(ret);
  42727. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, NULL, 0, NULL);
  42728. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42729. return WC_TEST_RET_ENC_EC(ret);
  42730. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, NULL);
  42731. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42732. return WC_TEST_RET_ENC_EC(ret);
  42733. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0,
  42734. &valid);
  42735. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42736. return WC_TEST_RET_ENC_EC(ret);
  42737. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL);
  42738. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42739. return WC_TEST_RET_ENC_EC(ret);
  42740. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, NULL, 0,
  42741. &valid);
  42742. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42743. return WC_TEST_RET_ENC_EC(ret);
  42744. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0,
  42745. &valid);
  42746. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42747. return WC_TEST_RET_ENC_EC(ret);
  42748. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  42749. &valid);
  42750. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42751. return WC_TEST_RET_ENC_EC(ret);
  42752. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  42753. &valid);
  42754. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42755. return WC_TEST_RET_ENC_EC(ret);
  42756. ret = wc_SetEccsiPair(key, ssk, pvt);
  42757. if (ret != 0)
  42758. return WC_TEST_RET_ENC_EC(ret);
  42759. /* Identity hash not set. */
  42760. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  42761. &sigSz);
  42762. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42763. return WC_TEST_RET_ENC_EC(ret);
  42764. wc_FreeEccsiKey(key);
  42765. return 0;
  42766. }
  42767. /* RFC 6507: Appendix A */
  42768. static wc_test_ret_t eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt)
  42769. {
  42770. wc_test_ret_t ret;
  42771. int verified;
  42772. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00 };
  42773. word32 msgSz = sizeof(msg);
  42774. byte hash[WC_SHA256_DIGEST_SIZE];
  42775. byte hashSz = WC_SHA256_DIGEST_SIZE;
  42776. static const byte id[] = {
  42777. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  42778. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  42779. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  42780. 0x33, 0x00
  42781. };
  42782. word32 idSz = sizeof(id);
  42783. static const byte sig[] = {
  42784. 0x26, 0x9D, 0x4C, 0x8F, 0xDE, 0xB6, 0x6A, 0x74,
  42785. 0xE4, 0xEF, 0x8C, 0x0D, 0x5D, 0xCC, 0x59, 0x7D,
  42786. 0xDF, 0xE6, 0x02, 0x9C, 0x2A, 0xFF, 0xC4, 0x93,
  42787. 0x60, 0x08, 0xCD, 0x2C, 0xC1, 0x04, 0x5D, 0x81,
  42788. 0xE0, 0x9B, 0x52, 0x8D, 0x0E, 0xF8, 0xD6, 0xDF,
  42789. 0x1A, 0xA3, 0xEC, 0xBF, 0x80, 0x11, 0x0C, 0xFC,
  42790. 0xEC, 0x9F, 0xC6, 0x82, 0x52, 0xCE, 0xBB, 0x67,
  42791. 0x9F, 0x41, 0x34, 0x84, 0x69, 0x40, 0xCC, 0xFD,
  42792. 0x04,
  42793. 0x75, 0x8A, 0x14, 0x27, 0x79, 0xBE, 0x89, 0xE8,
  42794. 0x29, 0xE7, 0x19, 0x84, 0xCB, 0x40, 0xEF, 0x75,
  42795. 0x8C, 0xC4, 0xAD, 0x77, 0x5F, 0xC5, 0xB9, 0xA3,
  42796. 0xE1, 0xC8, 0xED, 0x52, 0xF6, 0xFA, 0x36, 0xD9,
  42797. 0xA7, 0x9D, 0x24, 0x76, 0x92, 0xF4, 0xED, 0xA3,
  42798. 0xA6, 0xBD, 0xAB, 0x77, 0xD6, 0xAA, 0x64, 0x74,
  42799. 0xA4, 0x64, 0xAE, 0x49, 0x34, 0x66, 0x3C, 0x52,
  42800. 0x65, 0xBA, 0x70, 0x18, 0xBA, 0x09, 0x1F, 0x79
  42801. };
  42802. word32 sigSz = sizeof(sig);
  42803. static const byte pubData[] = {
  42804. 0x50, 0xD4, 0x67, 0x0B, 0xDE, 0x75, 0x24, 0x4F,
  42805. 0x28, 0xD2, 0x83, 0x8A, 0x0D, 0x25, 0x55, 0x8A,
  42806. 0x7A, 0x72, 0x68, 0x6D, 0x45, 0x22, 0xD4, 0xC8,
  42807. 0x27, 0x3F, 0xB6, 0x44, 0x2A, 0xEB, 0xFA, 0x93,
  42808. 0xDB, 0xDD, 0x37, 0x55, 0x1A, 0xFD, 0x26, 0x3B,
  42809. 0x5D, 0xFD, 0x61, 0x7F, 0x39, 0x60, 0xC6, 0x5A,
  42810. 0x8C, 0x29, 0x88, 0x50, 0xFF, 0x99, 0xF2, 0x03,
  42811. 0x66, 0xDC, 0xE7, 0xD4, 0x36, 0x72, 0x17, 0xF4
  42812. };
  42813. static const byte expHash[] = {
  42814. 0x49, 0x0f, 0x3f, 0xeb, 0xbc, 0x1c, 0x90, 0x2f,
  42815. 0x62, 0x89, 0x72, 0x3d, 0x7f, 0x8c, 0xbf, 0x79,
  42816. 0xdb, 0x88, 0x93, 0x08, 0x49, 0xd1, 0x9f, 0x38,
  42817. 0xf0, 0x29, 0x5b, 0x5c, 0x27, 0x6c, 0x14, 0xd1
  42818. };
  42819. ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0);
  42820. if (ret != 0)
  42821. return WC_TEST_RET_ENC_EC(ret);
  42822. ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt);
  42823. if (ret != 0)
  42824. return WC_TEST_RET_ENC_EC(ret);
  42825. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash,
  42826. &hashSz);
  42827. if (ret != 0)
  42828. return WC_TEST_RET_ENC_EC(ret);
  42829. if (hashSz != sizeof(expHash))
  42830. return WC_TEST_RET_ENC_NC;
  42831. if (XMEMCMP(hash, expHash, hashSz) != 0)
  42832. return WC_TEST_RET_ENC_NC;
  42833. ret = wc_SetEccsiHash(key, hash, hashSz);
  42834. if (ret != 0)
  42835. return WC_TEST_RET_ENC_EC(ret);
  42836. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  42837. &verified);
  42838. if (ret != 0)
  42839. return WC_TEST_RET_ENC_EC(ret);
  42840. if (!verified)
  42841. return WC_TEST_RET_ENC_NC;
  42842. return 0;
  42843. }
  42844. static wc_test_ret_t eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt)
  42845. {
  42846. wc_test_ret_t ret;
  42847. byte data[32 * 3];
  42848. word32 sz;
  42849. ecc_point* decPvt = NULL;
  42850. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42851. mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT,
  42852. DYNAMIC_TYPE_TMP_BUFFER);
  42853. if (decSsk == NULL)
  42854. return WC_TEST_RET_ENC_ERRNO;
  42855. #else
  42856. mp_int decSsk[1];
  42857. #endif
  42858. ret = mp_init(decSsk);
  42859. if (ret != 0)
  42860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42861. decPvt = wc_ecc_new_point();
  42862. if (decPvt == NULL)
  42863. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  42864. ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz);
  42865. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42867. if (sz != 32 * 3)
  42868. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42869. ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz);
  42870. if (ret != 0)
  42871. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42872. if (sz != 32* 3)
  42873. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42874. ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt);
  42875. if (ret != 0)
  42876. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42877. ret = mp_cmp(ssk, decSsk);
  42878. if (ret != MP_EQ)
  42879. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42880. ret = wc_ecc_cmp_point(pvt, decPvt);
  42881. if (ret != MP_EQ)
  42882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42883. ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz);
  42884. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42886. if (sz != 32)
  42887. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42888. ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz);
  42889. if (ret != 0)
  42890. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42891. if (sz != 32)
  42892. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42893. ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk);
  42894. if (ret != 0)
  42895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42896. ret = mp_cmp(ssk, decSsk);
  42897. if (ret != MP_EQ)
  42898. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42899. ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1);
  42900. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42902. if (sz != 32 * 2)
  42903. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42904. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1);
  42905. if (ret != 0)
  42906. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42907. if (sz != 32 * 2)
  42908. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42909. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  42910. if (ret != 0)
  42911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42912. ret = wc_ecc_cmp_point(pvt, decPvt);
  42913. if (ret != MP_EQ)
  42914. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42915. sz = sizeof(data);
  42916. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0);
  42917. if (ret != 0)
  42918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42919. if (sz != 32 * 2 + 1)
  42920. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42921. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  42922. if (ret != 0)
  42923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  42924. ret = wc_ecc_cmp_point(pvt, decPvt);
  42925. if (ret != MP_EQ)
  42926. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  42927. wc_ecc_del_point(decPvt);
  42928. out:
  42929. mp_free(decSsk);
  42930. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42931. XFREE(decSsk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42932. #endif
  42933. return ret;
  42934. }
  42935. static wc_test_ret_t eccsi_imp_exp_key_test(EccsiKey* priv)
  42936. {
  42937. wc_test_ret_t ret;
  42938. byte data[32 * 3];
  42939. byte out[32 * 3];
  42940. word32 sz;
  42941. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  42942. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42943. return WC_TEST_RET_ENC_EC(ret);
  42944. if (sz != 32 * 3)
  42945. return WC_TEST_RET_ENC_NC;
  42946. ret = wc_ExportEccsiKey(priv, data, &sz);
  42947. if (ret != 0)
  42948. return WC_TEST_RET_ENC_EC(ret);
  42949. ret = wc_ImportEccsiKey(priv, data, sz);
  42950. if (ret != 0)
  42951. return WC_TEST_RET_ENC_EC(ret);
  42952. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  42953. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42954. return WC_TEST_RET_ENC_EC(ret);
  42955. if (sz != 32 * 3)
  42956. return WC_TEST_RET_ENC_NC;
  42957. ret = wc_ExportEccsiKey(priv, out, &sz);
  42958. if (ret != 0)
  42959. return WC_TEST_RET_ENC_EC(ret);
  42960. if (sz != 32 * 3)
  42961. return WC_TEST_RET_ENC_NC;
  42962. if (XMEMCMP(data, out, sz) != 0)
  42963. return WC_TEST_RET_ENC_NC;
  42964. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  42965. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42966. return WC_TEST_RET_ENC_EC(ret);
  42967. if (sz != 32)
  42968. return WC_TEST_RET_ENC_NC;
  42969. ret = wc_ExportEccsiPrivateKey(priv, data, &sz);
  42970. if (ret != 0)
  42971. return WC_TEST_RET_ENC_EC(ret);
  42972. ret = wc_ImportEccsiPrivateKey(priv, data, sz);
  42973. if (ret != 0)
  42974. return WC_TEST_RET_ENC_EC(ret);
  42975. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  42976. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42977. return WC_TEST_RET_ENC_EC(ret);
  42978. if (sz != 32)
  42979. return WC_TEST_RET_ENC_NC;
  42980. ret = wc_ExportEccsiPrivateKey(priv, out, &sz);
  42981. if (ret != 0)
  42982. return WC_TEST_RET_ENC_EC(ret);
  42983. if (sz != 32)
  42984. return WC_TEST_RET_ENC_NC;
  42985. if (XMEMCMP(data, out, sz) != 0)
  42986. return WC_TEST_RET_ENC_NC;
  42987. return 0;
  42988. }
  42989. static wc_test_ret_t eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2)
  42990. {
  42991. wc_test_ret_t ret;
  42992. byte data[32 * 2 + 1];
  42993. byte pubData[32 * 2 + 1];
  42994. word32 sz;
  42995. ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1);
  42996. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42997. return WC_TEST_RET_ENC_EC(ret);
  42998. if (sz != 32 * 2)
  42999. return WC_TEST_RET_ENC_NC;
  43000. ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1);
  43001. if (ret != 0)
  43002. return WC_TEST_RET_ENC_EC(ret);
  43003. ret = wc_ImportEccsiPublicKey(key2, data, sz, 1);
  43004. if (ret != 0)
  43005. return WC_TEST_RET_ENC_EC(ret);
  43006. sz = sizeof(pubData);
  43007. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1);
  43008. if (ret != 0)
  43009. return WC_TEST_RET_ENC_EC(ret);
  43010. if (sz != 32 * 2)
  43011. return WC_TEST_RET_ENC_NC;
  43012. if (XMEMCMP(data, pubData, sz) != 0)
  43013. return WC_TEST_RET_ENC_NC;
  43014. sz = sizeof(pubData);
  43015. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0);
  43016. if (ret != 0)
  43017. return WC_TEST_RET_ENC_EC(ret);
  43018. if (sz != 32 * 2 + 1)
  43019. return WC_TEST_RET_ENC_NC;
  43020. if (pubData[0] != 0x04)
  43021. return WC_TEST_RET_ENC_NC;
  43022. if (XMEMCMP(pubData + 1, data, sz - 1) != 0)
  43023. return WC_TEST_RET_ENC_NC;
  43024. ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0);
  43025. if (ret != 0)
  43026. return WC_TEST_RET_ENC_EC(ret);
  43027. return 0;
  43028. }
  43029. static wc_test_ret_t eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43030. mp_int* ssk, ecc_point* pvt)
  43031. {
  43032. wc_test_ret_t ret;
  43033. char mail[] = "test@wolfssl.com";
  43034. byte* id = (byte*)mail;
  43035. word32 idSz = (word32) XSTRLEN(mail);
  43036. int valid;
  43037. ret = wc_MakeEccsiKey(priv, rng);
  43038. if (ret != 0)
  43039. return WC_TEST_RET_ENC_EC(ret);
  43040. ret = eccsi_imp_exp_key_test(priv);
  43041. if (ret < 0)
  43042. return ret;
  43043. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43044. if (ret < 0)
  43045. return ret;
  43046. ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt);
  43047. if (ret != 0)
  43048. return WC_TEST_RET_ENC_EC(ret);
  43049. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43050. &valid);
  43051. if (ret != 0)
  43052. return WC_TEST_RET_ENC_EC(ret);
  43053. if (!valid)
  43054. return WC_TEST_RET_ENC_NC;
  43055. ret = eccsi_enc_dec_pair_test(priv, ssk, pvt);
  43056. if (ret != 0)
  43057. return ret;
  43058. return 0;
  43059. }
  43060. static wc_test_ret_t eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43061. mp_int* ssk, ecc_point* pvt)
  43062. {
  43063. wc_test_ret_t ret;
  43064. byte hashPriv[WC_MAX_DIGEST_SIZE];
  43065. byte hashPub[WC_MAX_DIGEST_SIZE];
  43066. byte hashSz;
  43067. byte sig[144];
  43068. word32 sigSz;
  43069. int verified, valid;
  43070. char mail[] = "test@wolfssl.com";
  43071. byte* id = (byte*)mail;
  43072. word32 idSz = (word32) XSTRLEN(mail);
  43073. byte msg[] = { 0x00 };
  43074. word32 msgSz = sizeof(msg);
  43075. #ifdef WOLFSSL_SHA384
  43076. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv,
  43077. &hashSz);
  43078. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43079. return WC_TEST_RET_ENC_EC(ret);
  43080. #endif
  43081. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv,
  43082. &hashSz);
  43083. if (ret != 0)
  43084. return WC_TEST_RET_ENC_EC(ret);
  43085. if (hashSz != 32)
  43086. return WC_TEST_RET_ENC_NC;
  43087. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub,
  43088. &hashSz);
  43089. if (ret != 0)
  43090. return WC_TEST_RET_ENC_EC(ret);
  43091. if (hashSz != 32)
  43092. return WC_TEST_RET_ENC_NC;
  43093. if (XMEMCMP(hashPriv, hashPub, hashSz) != 0)
  43094. return WC_TEST_RET_ENC_NC;
  43095. ret = wc_SetEccsiHash(priv, hashPriv, hashSz);
  43096. if (ret != 0)
  43097. return WC_TEST_RET_ENC_EC(ret);
  43098. ret = wc_SetEccsiPair(priv, ssk, pvt);
  43099. if (ret != 0)
  43100. return WC_TEST_RET_ENC_EC(ret);
  43101. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL,
  43102. &sigSz);
  43103. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43104. return WC_TEST_RET_ENC_EC(ret);
  43105. if (sigSz != 129)
  43106. return WC_TEST_RET_ENC_NC;
  43107. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig,
  43108. &sigSz);
  43109. if (ret != 0)
  43110. return WC_TEST_RET_ENC_EC(ret);
  43111. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43112. if (ret != 0)
  43113. return WC_TEST_RET_ENC_EC(ret);
  43114. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43115. &verified);
  43116. if (ret != 0)
  43117. return WC_TEST_RET_ENC_EC(ret);
  43118. if (!verified)
  43119. return WC_TEST_RET_ENC_NC;
  43120. /* Check that changing HS results in verification failure. */
  43121. hashPub[0] ^= 0x80;
  43122. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43123. if (ret != 0)
  43124. return WC_TEST_RET_ENC_EC(ret);
  43125. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43126. &verified);
  43127. if (ret != 0)
  43128. return WC_TEST_RET_ENC_EC(ret);
  43129. if (verified)
  43130. return WC_TEST_RET_ENC_NC;
  43131. hashPub[0] ^= 0x80;
  43132. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43133. if (ret != 0)
  43134. return WC_TEST_RET_ENC_EC(ret);
  43135. /* Check that changing msg results in verification failure. */
  43136. msg[0] ^= 0x80;
  43137. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43138. &verified);
  43139. if (ret != 0)
  43140. return WC_TEST_RET_ENC_EC(ret);
  43141. if (verified)
  43142. return WC_TEST_RET_ENC_NC;
  43143. msg[0] ^= 0x80;
  43144. /* Check that changing signature results in verification failure. */
  43145. sig[0] ^= 0x80;
  43146. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43147. &verified);
  43148. if (ret != 0)
  43149. return WC_TEST_RET_ENC_EC(ret);
  43150. if (verified)
  43151. return WC_TEST_RET_ENC_NC;
  43152. sig[0] ^= 0x80;
  43153. /* Check that key state hasn't been invalidated. */
  43154. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43155. &verified);
  43156. if (ret != 0)
  43157. return WC_TEST_RET_ENC_EC(ret);
  43158. if (!verified)
  43159. return WC_TEST_RET_ENC_NC;
  43160. /* Check that verifying with the private key works. */
  43161. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43162. &verified);
  43163. if (ret != 0)
  43164. return WC_TEST_RET_ENC_EC(ret);
  43165. if (!verified)
  43166. return WC_TEST_RET_ENC_NC;
  43167. /* Check that the KPAK is converted from montgomery form. */
  43168. ret = eccsi_imp_exp_key_test(priv);
  43169. if (ret != 0)
  43170. return ret;
  43171. /* Check that KPAK can converted to Montgomery form again. */
  43172. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43173. &verified);
  43174. if (ret != 0)
  43175. return WC_TEST_RET_ENC_EC(ret);
  43176. if (!verified)
  43177. return WC_TEST_RET_ENC_NC;
  43178. /* Check that the KPAK is converted from montgomery form. */
  43179. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43180. &valid);
  43181. if (ret != 0)
  43182. return WC_TEST_RET_ENC_EC(ret);
  43183. if (!valid)
  43184. return WC_TEST_RET_ENC_NC;
  43185. /* Check that KPAK can converted to Montgomery form again. */
  43186. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43187. &verified);
  43188. if (ret != 0)
  43189. return WC_TEST_RET_ENC_EC(ret);
  43190. if (!verified)
  43191. return WC_TEST_RET_ENC_NC;
  43192. /* Check that the KPAK is converted from montgomery form. */
  43193. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43194. if (ret != 0)
  43195. return ret;
  43196. return 0;
  43197. }
  43198. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void)
  43199. {
  43200. wc_test_ret_t ret = 0;
  43201. WC_RNG rng;
  43202. int rng_inited = 0;
  43203. EccsiKey* priv = NULL;
  43204. EccsiKey* pub = NULL;
  43205. mp_int* ssk = NULL;
  43206. ecc_point* pvt = NULL;
  43207. WOLFSSL_ENTER("eccsi_test");
  43208. priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43209. DYNAMIC_TYPE_TMP_BUFFER);
  43210. if (priv == NULL)
  43211. ret = WC_TEST_RET_ENC_NC;
  43212. else
  43213. XMEMSET(priv, 0, sizeof(*priv));
  43214. if (ret == 0) {
  43215. pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43216. DYNAMIC_TYPE_TMP_BUFFER);
  43217. if (pub == NULL)
  43218. ret = WC_TEST_RET_ENC_NC;
  43219. else
  43220. XMEMSET(pub, 0, sizeof(*pub));
  43221. }
  43222. if (ret == 0) {
  43223. ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT,
  43224. DYNAMIC_TYPE_TMP_BUFFER);
  43225. if (ssk == NULL)
  43226. ret = WC_TEST_RET_ENC_NC;
  43227. else
  43228. XMEMSET(ssk, 0, sizeof(*ssk));
  43229. }
  43230. if (ret == 0) {
  43231. #ifndef HAVE_FIPS
  43232. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  43233. #else
  43234. ret = wc_InitRng(&rng);
  43235. #endif
  43236. if (ret != 0)
  43237. ret = WC_TEST_RET_ENC_EC(ret);
  43238. else
  43239. rng_inited = 1;
  43240. }
  43241. if (ret == 0) {
  43242. pvt = wc_ecc_new_point();
  43243. if (pvt == NULL)
  43244. ret = WC_TEST_RET_ENC_NC;
  43245. }
  43246. if (ret == 0) {
  43247. ret = mp_init(ssk);
  43248. if (ret != 0)
  43249. ret = WC_TEST_RET_ENC_EC(ret);
  43250. }
  43251. if (ret == 0) {
  43252. ret = eccsi_api_test(&rng, priv, ssk, pvt);
  43253. }
  43254. if (ret == 0) {
  43255. ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID);
  43256. if (ret != 0)
  43257. ret = WC_TEST_RET_ENC_EC(ret);
  43258. }
  43259. if (ret == 0) {
  43260. ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID);
  43261. if (ret != 0)
  43262. ret = WC_TEST_RET_ENC_EC(ret);
  43263. }
  43264. if (ret == 0) {
  43265. ret = eccsi_kat_verify_test(pub, pvt);
  43266. }
  43267. if (ret == 0) {
  43268. ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt);
  43269. }
  43270. if (ret == 0) {
  43271. ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt);
  43272. }
  43273. if (pvt != NULL)
  43274. wc_ecc_del_point(pvt);
  43275. if (rng_inited)
  43276. wc_FreeRng(&rng);
  43277. if (ssk != NULL) {
  43278. mp_free(ssk);
  43279. XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43280. }
  43281. if (pub != NULL) {
  43282. wc_FreeEccsiKey(pub);
  43283. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43284. }
  43285. if (priv != NULL) {
  43286. wc_FreeEccsiKey(priv);
  43287. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43288. }
  43289. return ret;
  43290. }
  43291. #endif /* WOLFCRYPT_HAVE_ECCSI */
  43292. #ifdef WOLFCRYPT_HAVE_SAKKE
  43293. static wc_test_ret_t sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk)
  43294. {
  43295. wc_test_ret_t ret;
  43296. byte id[1] = { 0x00 };
  43297. int valid;
  43298. byte data[256];
  43299. word32 sz;
  43300. byte auth[257];
  43301. word16 authSz;
  43302. byte ssv[256];
  43303. word16 ssvSz;
  43304. word32 len;
  43305. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43306. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43307. return WC_TEST_RET_ENC_EC(ret);
  43308. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43309. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43310. return WC_TEST_RET_ENC_EC(ret);
  43311. wc_FreeSakkeKey(NULL);
  43312. XMEMSET(key, 0, sizeof(*key));
  43313. wc_FreeSakkeKey(key);
  43314. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43315. if (ret != 0)
  43316. return WC_TEST_RET_ENC_EC(ret);
  43317. ret = wc_MakeSakkeKey(NULL, NULL);
  43318. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43319. return WC_TEST_RET_ENC_EC(ret);
  43320. ret = wc_MakeSakkeKey(key, NULL);
  43321. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43322. return WC_TEST_RET_ENC_EC(ret);
  43323. ret = wc_MakeSakkeKey(NULL, rng);
  43324. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43325. return WC_TEST_RET_ENC_EC(ret);
  43326. ret = wc_MakeSakkePublicKey(NULL, NULL);
  43327. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43328. return WC_TEST_RET_ENC_EC(ret);
  43329. ret = wc_MakeSakkePublicKey(key, NULL);
  43330. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43331. return WC_TEST_RET_ENC_EC(ret);
  43332. ret = wc_MakeSakkePublicKey(NULL, rsk);
  43333. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43334. return WC_TEST_RET_ENC_EC(ret);
  43335. ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL);
  43336. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43337. return WC_TEST_RET_ENC_EC(ret);
  43338. ret = wc_MakeSakkeRsk(key, id, 1, NULL);
  43339. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43340. return WC_TEST_RET_ENC_EC(ret);
  43341. ret = wc_MakeSakkeRsk(key, NULL, 1, rsk);
  43342. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43343. return WC_TEST_RET_ENC_EC(ret);
  43344. ret = wc_MakeSakkeRsk(NULL, id, 1, rsk);
  43345. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43346. return WC_TEST_RET_ENC_EC(ret);
  43347. ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL);
  43348. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43349. return WC_TEST_RET_ENC_EC(ret);
  43350. ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL);
  43351. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43352. return WC_TEST_RET_ENC_EC(ret);
  43353. ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid);
  43354. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43355. return WC_TEST_RET_ENC_EC(ret);
  43356. ret = wc_ExportSakkeKey(NULL, NULL, NULL);
  43357. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43358. return WC_TEST_RET_ENC_EC(ret);
  43359. ret = wc_ExportSakkeKey(key, data, NULL);
  43360. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43361. return WC_TEST_RET_ENC_EC(ret);
  43362. ret = wc_ExportSakkeKey(NULL, data, &sz);
  43363. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43364. return WC_TEST_RET_ENC_EC(ret);
  43365. ret = wc_ImportSakkeKey(NULL, NULL, 1);
  43366. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43367. return WC_TEST_RET_ENC_EC(ret);
  43368. ret = wc_ImportSakkeKey(key, NULL, 1);
  43369. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43370. return WC_TEST_RET_ENC_EC(ret);
  43371. ret = wc_ImportSakkeKey(NULL, data, 1);
  43372. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43373. return WC_TEST_RET_ENC_EC(ret);
  43374. ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL);
  43375. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43376. return WC_TEST_RET_ENC_EC(ret);
  43377. ret = wc_ExportSakkePrivateKey(key, data, NULL);
  43378. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43379. return WC_TEST_RET_ENC_EC(ret);
  43380. ret = wc_ExportSakkePrivateKey(NULL, data, &sz);
  43381. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43382. return WC_TEST_RET_ENC_EC(ret);
  43383. ret = wc_ImportSakkePrivateKey(NULL, NULL, 1);
  43384. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43385. return WC_TEST_RET_ENC_EC(ret);
  43386. ret = wc_ImportSakkePrivateKey(key, NULL, 1);
  43387. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43388. return WC_TEST_RET_ENC_EC(ret);
  43389. ret = wc_ImportSakkePrivateKey(NULL, data, 1);
  43390. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43391. return WC_TEST_RET_ENC_EC(ret);
  43392. sz = sizeof(data);
  43393. ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1);
  43394. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43395. return WC_TEST_RET_ENC_EC(ret);
  43396. ret = wc_EncodeSakkeRsk(key, rsk, data, NULL, 1);
  43397. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43398. return WC_TEST_RET_ENC_EC(ret);
  43399. ret = wc_EncodeSakkeRsk(key, NULL, data, &sz, 1);
  43400. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43401. return WC_TEST_RET_ENC_EC(ret);
  43402. ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1);
  43403. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43404. return WC_TEST_RET_ENC_EC(ret);
  43405. ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL);
  43406. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43407. return WC_TEST_RET_ENC_EC(ret);
  43408. ret = wc_DecodeSakkeRsk(key, data, sz, NULL);
  43409. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43410. return WC_TEST_RET_ENC_EC(ret);
  43411. ret = wc_DecodeSakkeRsk(key, NULL, sz, rsk);
  43412. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43413. return WC_TEST_RET_ENC_EC(ret);
  43414. ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk);
  43415. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43416. return WC_TEST_RET_ENC_EC(ret);
  43417. ret = wc_ImportSakkeRsk(NULL, NULL, sz);
  43418. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43419. return WC_TEST_RET_ENC_EC(ret);
  43420. ret = wc_ImportSakkeRsk(key, NULL, sz);
  43421. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43422. return WC_TEST_RET_ENC_EC(ret);
  43423. ret = wc_ImportSakkeRsk(NULL, data, sz);
  43424. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43425. return WC_TEST_RET_ENC_EC(ret);
  43426. ret = wc_ImportSakkeRsk(key, data, 1);
  43427. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43428. return WC_TEST_RET_ENC_EC(ret);
  43429. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL);
  43430. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43431. return WC_TEST_RET_ENC_EC(ret);
  43432. ret = wc_GenerateSakkeRskTable(key, NULL, data, NULL);
  43433. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43434. return WC_TEST_RET_ENC_EC(ret);
  43435. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, NULL);
  43436. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43437. return WC_TEST_RET_ENC_EC(ret);
  43438. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, &len);
  43439. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43440. return WC_TEST_RET_ENC_EC(ret);
  43441. ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL);
  43442. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43443. return WC_TEST_RET_ENC_EC(ret);
  43444. ret = wc_GenerateSakkeRskTable(key, NULL, data, &len);
  43445. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43446. return WC_TEST_RET_ENC_EC(ret);
  43447. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len);
  43448. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43449. return WC_TEST_RET_ENC_EC(ret);
  43450. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43451. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43452. return WC_TEST_RET_ENC_EC(ret);
  43453. len--;
  43454. ret = wc_GenerateSakkeRskTable(key, rsk, data, &len);
  43455. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43456. return WC_TEST_RET_ENC_EC(ret);
  43457. ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1);
  43458. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43459. return WC_TEST_RET_ENC_EC(ret);
  43460. ret = wc_ExportSakkePublicKey(key, data, NULL, 1);
  43461. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43462. return WC_TEST_RET_ENC_EC(ret);
  43463. ret = wc_ExportSakkePublicKey(NULL, data, &sz, 1);
  43464. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43465. return WC_TEST_RET_ENC_EC(ret);
  43466. ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1);
  43467. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43468. return WC_TEST_RET_ENC_EC(ret);
  43469. ret = wc_ImportSakkePublicKey(key, NULL, sz, 1);
  43470. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43471. return WC_TEST_RET_ENC_EC(ret);
  43472. ret = wc_ImportSakkePublicKey(NULL, data, sz, 1);
  43473. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43474. return WC_TEST_RET_ENC_EC(ret);
  43475. ret = wc_GetSakkeAuthSize(NULL, NULL);
  43476. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43477. return WC_TEST_RET_ENC_EC(ret);
  43478. ret = wc_GetSakkeAuthSize(key, NULL);
  43479. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43480. return WC_TEST_RET_ENC_EC(ret);
  43481. ret = wc_GetSakkeAuthSize(NULL, &authSz);
  43482. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43483. return WC_TEST_RET_ENC_EC(ret);
  43484. ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1);
  43485. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43486. return WC_TEST_RET_ENC_EC(ret);
  43487. ret = wc_MakeSakkePointI(key, NULL, SAKKE_ID_MAX_SIZE + 1);
  43488. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43489. return WC_TEST_RET_ENC_EC(ret);
  43490. ret = wc_MakeSakkePointI(NULL, id, 1);
  43491. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43492. return WC_TEST_RET_ENC_EC(ret);
  43493. ret = wc_MakeSakkePointI(NULL, NULL, 1);
  43494. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43495. return WC_TEST_RET_ENC_EC(ret);
  43496. ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1);
  43497. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43498. return WC_TEST_RET_ENC_EC(ret);
  43499. ret = wc_MakeSakkePointI(key, NULL, 1);
  43500. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43501. return WC_TEST_RET_ENC_EC(ret);
  43502. ret = wc_MakeSakkePointI(NULL, id, 1);
  43503. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43504. return WC_TEST_RET_ENC_EC(ret);
  43505. ret = wc_GenerateSakkePointITable(NULL, data, NULL);
  43506. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43507. return WC_TEST_RET_ENC_EC(ret);
  43508. ret = wc_GenerateSakkePointITable(key, data, NULL);
  43509. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43510. return WC_TEST_RET_ENC_EC(ret);
  43511. ret = wc_GenerateSakkePointITable(NULL, data, &len);
  43512. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43513. return WC_TEST_RET_ENC_EC(ret);
  43514. ret = wc_GenerateSakkePointITable(key, NULL, &len);
  43515. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43516. return WC_TEST_RET_ENC_EC(ret);
  43517. len--;
  43518. ret = wc_GenerateSakkePointITable(key, data, &len);
  43519. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43520. return WC_TEST_RET_ENC_EC(ret);
  43521. ret = wc_SetSakkePointITable(NULL, NULL, 1);
  43522. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43523. return WC_TEST_RET_ENC_EC(ret);
  43524. ret = wc_SetSakkePointITable(key, NULL, 1);
  43525. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43526. return WC_TEST_RET_ENC_EC(ret);
  43527. ret = wc_SetSakkePointITable(NULL, data, 1);
  43528. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43529. return WC_TEST_RET_ENC_EC(ret);
  43530. ret = wc_SetSakkePointITable(key, data, 1);
  43531. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43532. return WC_TEST_RET_ENC_EC(ret);
  43533. ret = wc_ClearSakkePointITable(NULL);
  43534. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43535. return WC_TEST_RET_ENC_EC(ret);
  43536. ret = wc_GetSakkePointI(NULL, data, NULL);
  43537. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43538. return WC_TEST_RET_ENC_EC(ret);
  43539. ret = wc_GetSakkePointI(key, data, NULL);
  43540. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43541. return WC_TEST_RET_ENC_EC(ret);
  43542. ret = wc_GetSakkePointI(NULL, data, &sz);
  43543. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43544. return WC_TEST_RET_ENC_EC(ret);
  43545. sz = 1;
  43546. ret = wc_GetSakkePointI(key, data, &sz);
  43547. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43548. return WC_TEST_RET_ENC_EC(ret);
  43549. sz = 256;
  43550. ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz);
  43551. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43552. return WC_TEST_RET_ENC_EC(ret);
  43553. ret = wc_SetSakkePointI(key, NULL, 1, NULL, sz);
  43554. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43555. return WC_TEST_RET_ENC_EC(ret);
  43556. ret = wc_SetSakkePointI(NULL, id, 1, NULL, sz);
  43557. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43558. return WC_TEST_RET_ENC_EC(ret);
  43559. ret = wc_SetSakkePointI(NULL, NULL, 1, data, sz);
  43560. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43561. return WC_TEST_RET_ENC_EC(ret);
  43562. ret = wc_SetSakkePointI(key, id, 1, NULL, sz);
  43563. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43564. return WC_TEST_RET_ENC_EC(ret);
  43565. ret = wc_SetSakkePointI(key, NULL, 1, data, sz);
  43566. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43567. return WC_TEST_RET_ENC_EC(ret);
  43568. ret = wc_SetSakkePointI(NULL, id, 1, data, sz);
  43569. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43570. return WC_TEST_RET_ENC_EC(ret);
  43571. ret = wc_SetSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz);
  43572. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43573. return WC_TEST_RET_ENC_EC(ret);
  43574. ret = wc_SetSakkePointI(key, id, 1, data, sz - 1);
  43575. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43576. return WC_TEST_RET_ENC_EC(ret);
  43577. ret = wc_SetSakkeIdentity(NULL, NULL, 1);
  43578. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43579. return WC_TEST_RET_ENC_EC(ret);
  43580. ret = wc_SetSakkeIdentity(key, NULL, 1);
  43581. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43582. return WC_TEST_RET_ENC_EC(ret);
  43583. ret = wc_SetSakkeIdentity(NULL, id, 1);
  43584. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43585. return WC_TEST_RET_ENC_EC(ret);
  43586. ssvSz = sizeof(ssv);
  43587. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43588. auth, NULL);
  43589. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43590. return WC_TEST_RET_ENC_EC(ret);
  43591. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43592. auth, NULL);
  43593. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43594. return WC_TEST_RET_ENC_EC(ret);
  43595. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43596. auth, NULL);
  43597. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43598. return WC_TEST_RET_ENC_EC(ret);
  43599. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43600. auth, &authSz);
  43601. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43602. return WC_TEST_RET_ENC_EC(ret);
  43603. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43604. auth, NULL);
  43605. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43606. return WC_TEST_RET_ENC_EC(ret);
  43607. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43608. auth, &authSz);
  43609. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43610. return WC_TEST_RET_ENC_EC(ret);
  43611. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43612. auth, &authSz);
  43613. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43614. return WC_TEST_RET_ENC_EC(ret);
  43615. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43616. auth, &authSz);
  43617. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43618. return WC_TEST_RET_ENC_EC(ret);
  43619. ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL);
  43620. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43621. return WC_TEST_RET_ENC_EC(ret);
  43622. ret = wc_GenerateSakkeSSV(key, rng, data, NULL);
  43623. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43624. return WC_TEST_RET_ENC_EC(ret);
  43625. ret = wc_GenerateSakkeSSV(key, NULL, data, &ssvSz);
  43626. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43627. return WC_TEST_RET_ENC_EC(ret);
  43628. ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz);
  43629. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43630. return WC_TEST_RET_ENC_EC(ret);
  43631. ret = wc_SetSakkeRsk(NULL, NULL, data, 1);
  43632. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43633. return WC_TEST_RET_ENC_EC(ret);
  43634. ret = wc_SetSakkeRsk(key, NULL, data, 1);
  43635. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43636. return WC_TEST_RET_ENC_EC(ret);
  43637. ret = wc_SetSakkeRsk(NULL, rsk, data, 1);
  43638. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43639. return WC_TEST_RET_ENC_EC(ret);
  43640. ssvSz = sizeof(ssv);
  43641. authSz = sizeof(auth);
  43642. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43643. authSz);
  43644. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43645. return WC_TEST_RET_ENC_EC(ret);
  43646. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  43647. authSz);
  43648. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43649. return WC_TEST_RET_ENC_EC(ret);
  43650. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  43651. authSz);
  43652. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43653. return WC_TEST_RET_ENC_EC(ret);
  43654. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  43655. authSz);
  43656. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43657. return WC_TEST_RET_ENC_EC(ret);
  43658. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  43659. authSz);
  43660. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43661. return WC_TEST_RET_ENC_EC(ret);
  43662. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  43663. authSz);
  43664. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43665. return WC_TEST_RET_ENC_EC(ret);
  43666. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43667. authSz);
  43668. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43669. return WC_TEST_RET_ENC_EC(ret);
  43670. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43671. authSz);
  43672. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43673. return WC_TEST_RET_ENC_EC(ret);
  43674. ret = wc_SetSakkeIdentity(key, id, 1);
  43675. if (ret != 0)
  43676. return WC_TEST_RET_ENC_EC(ret);
  43677. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43678. authSz);
  43679. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43680. return WC_TEST_RET_ENC_EC(ret);
  43681. ret = wc_SetSakkeIdentity(key, id, 0);
  43682. if (ret != 0)
  43683. return WC_TEST_RET_ENC_EC(ret);
  43684. ret = wc_SetSakkeRsk(key, rsk, data, 1);
  43685. if (ret != 0)
  43686. return WC_TEST_RET_ENC_EC(ret);
  43687. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  43688. authSz);
  43689. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43690. return WC_TEST_RET_ENC_EC(ret);
  43691. wc_FreeSakkeKey(key);
  43692. return 0;
  43693. }
  43694. static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
  43695. {
  43696. WOLFSSL_SMALL_STACK_STATIC const byte pubData[] = {
  43697. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  43698. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  43699. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  43700. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  43701. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  43702. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  43703. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  43704. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  43705. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  43706. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  43707. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  43708. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  43709. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  43710. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  43711. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  43712. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  43713. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  43714. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  43715. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  43716. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  43717. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  43718. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  43719. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  43720. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  43721. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  43722. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  43723. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  43724. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  43725. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  43726. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  43727. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  43728. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  43729. };
  43730. WOLFSSL_SMALL_STACK_STATIC const byte rskData[] = {
  43731. 0x93, 0xAF, 0x67, 0xE5, 0x00, 0x7B, 0xA6, 0xE6,
  43732. 0xA8, 0x0D, 0xA7, 0x93, 0xDA, 0x30, 0x0F, 0xA4,
  43733. 0xB5, 0x2D, 0x0A, 0x74, 0xE2, 0x5E, 0x6E, 0x7B,
  43734. 0x2B, 0x3D, 0x6E, 0xE9, 0xD1, 0x8A, 0x9B, 0x5C,
  43735. 0x50, 0x23, 0x59, 0x7B, 0xD8, 0x2D, 0x80, 0x62,
  43736. 0xD3, 0x40, 0x19, 0x56, 0x3B, 0xA1, 0xD2, 0x5C,
  43737. 0x0D, 0xC5, 0x6B, 0x7B, 0x97, 0x9D, 0x74, 0xAA,
  43738. 0x50, 0xF2, 0x9F, 0xBF, 0x11, 0xCC, 0x2C, 0x93,
  43739. 0xF5, 0xDF, 0xCA, 0x61, 0x5E, 0x60, 0x92, 0x79,
  43740. 0xF6, 0x17, 0x5C, 0xEA, 0xDB, 0x00, 0xB5, 0x8C,
  43741. 0x6B, 0xEE, 0x1E, 0x7A, 0x2A, 0x47, 0xC4, 0xF0,
  43742. 0xC4, 0x56, 0xF0, 0x52, 0x59, 0xA6, 0xFA, 0x94,
  43743. 0xA6, 0x34, 0xA4, 0x0D, 0xAE, 0x1D, 0xF5, 0x93,
  43744. 0xD4, 0xFE, 0xCF, 0x68, 0x8D, 0x5F, 0xC6, 0x78,
  43745. 0xBE, 0x7E, 0xFC, 0x6D, 0xF3, 0xD6, 0x83, 0x53,
  43746. 0x25, 0xB8, 0x3B, 0x2C, 0x6E, 0x69, 0x03, 0x6B,
  43747. 0x15, 0x5F, 0x0A, 0x27, 0x24, 0x10, 0x94, 0xB0,
  43748. 0x4B, 0xFB, 0x0B, 0xDF, 0xAC, 0x6C, 0x67, 0x0A,
  43749. 0x65, 0xC3, 0x25, 0xD3, 0x9A, 0x06, 0x9F, 0x03,
  43750. 0x65, 0x9D, 0x44, 0xCA, 0x27, 0xD3, 0xBE, 0x8D,
  43751. 0xF3, 0x11, 0x17, 0x2B, 0x55, 0x41, 0x60, 0x18,
  43752. 0x1C, 0xBE, 0x94, 0xA2, 0xA7, 0x83, 0x32, 0x0C,
  43753. 0xED, 0x59, 0x0B, 0xC4, 0x26, 0x44, 0x70, 0x2C,
  43754. 0xF3, 0x71, 0x27, 0x1E, 0x49, 0x6B, 0xF2, 0x0F,
  43755. 0x58, 0x8B, 0x78, 0xA1, 0xBC, 0x01, 0xEC, 0xBB,
  43756. 0x65, 0x59, 0x93, 0x4B, 0xDD, 0x2F, 0xB6, 0x5D,
  43757. 0x28, 0x84, 0x31, 0x8A, 0x33, 0xD1, 0xA4, 0x2A,
  43758. 0xDF, 0x5E, 0x33, 0xCC, 0x58, 0x00, 0x28, 0x0B,
  43759. 0x28, 0x35, 0x64, 0x97, 0xF8, 0x71, 0x35, 0xBA,
  43760. 0xB9, 0x61, 0x2A, 0x17, 0x26, 0x04, 0x24, 0x40,
  43761. 0x9A, 0xC1, 0x5F, 0xEE, 0x99, 0x6B, 0x74, 0x4C,
  43762. 0x33, 0x21, 0x51, 0x23, 0x5D, 0xEC, 0xB0, 0xF5
  43763. };
  43764. WOLFSSL_SMALL_STACK_STATIC const byte id[] = {
  43765. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43766. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43767. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43768. 0x33, 0x00
  43769. };
  43770. WOLFSSL_SMALL_STACK_STATIC const byte ssv[] = {
  43771. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  43772. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  43773. };
  43774. WOLFSSL_SMALL_STACK_STATIC const byte auth[] = {
  43775. 0x04,
  43776. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  43777. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  43778. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  43779. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  43780. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  43781. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  43782. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  43783. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  43784. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  43785. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  43786. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  43787. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  43788. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  43789. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  43790. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  43791. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  43792. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  43793. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  43794. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  43795. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  43796. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  43797. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  43798. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  43799. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  43800. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  43801. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  43802. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  43803. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  43804. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  43805. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  43806. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  43807. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  43808. };
  43809. WOLFSSL_SMALL_STACK_STATIC const byte encSsv[] = {
  43810. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  43811. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  43812. };
  43813. wc_test_ret_t ret;
  43814. int valid;
  43815. byte pubKey[sizeof(pubData) + 1];
  43816. word32 sz = sizeof(pubKey);
  43817. byte tmpSsv[sizeof(encSsv)];
  43818. byte* iTable = NULL;
  43819. word32 iTableLen;
  43820. byte* table = NULL;
  43821. word32 len;
  43822. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  43823. if (ret != 0)
  43824. return WC_TEST_RET_ENC_EC(ret);
  43825. ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk);
  43826. if (ret != 0)
  43827. return WC_TEST_RET_ENC_EC(ret);
  43828. ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid);
  43829. if (ret != 0)
  43830. return WC_TEST_RET_ENC_EC(ret);
  43831. if (valid != 1)
  43832. return WC_TEST_RET_ENC_NC;
  43833. ret = wc_SetSakkeRsk(key, rsk, NULL, 0);
  43834. if (ret != 0)
  43835. return WC_TEST_RET_ENC_EC(ret);
  43836. ret = wc_SetSakkeIdentity(key, id, sizeof(id));
  43837. if (ret != 0)
  43838. return WC_TEST_RET_ENC_EC(ret);
  43839. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  43840. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  43841. auth, sizeof(auth));
  43842. if (ret != 0)
  43843. return WC_TEST_RET_ENC_EC(ret);
  43844. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  43845. return WC_TEST_RET_ENC_NC;
  43846. ret = wc_MakeSakkePointI(key, id, sizeof(id));
  43847. if (ret != 0)
  43848. return WC_TEST_RET_ENC_EC(ret);
  43849. iTableLen = 0;
  43850. ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen);
  43851. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43852. return WC_TEST_RET_ENC_EC(ret);
  43853. if (iTableLen != 0) {
  43854. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43855. if (iTable == NULL)
  43856. return WC_TEST_RET_ENC_ERRNO;
  43857. ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
  43858. if (ret != 0)
  43859. return WC_TEST_RET_ENC_EC(ret);
  43860. }
  43861. len = 0;
  43862. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43863. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43864. return WC_TEST_RET_ENC_EC(ret);
  43865. if (len > 0) {
  43866. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43867. if (table == NULL)
  43868. return WC_TEST_RET_ENC_ERRNO;
  43869. ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
  43870. if (ret != 0)
  43871. return WC_TEST_RET_ENC_EC(ret);
  43872. }
  43873. ret = wc_SetSakkeRsk(key, rsk, table, len);
  43874. if (ret != 0)
  43875. return WC_TEST_RET_ENC_EC(ret);
  43876. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  43877. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  43878. auth, sizeof(auth));
  43879. if (ret != 0)
  43880. return WC_TEST_RET_ENC_EC(ret);
  43881. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  43882. return WC_TEST_RET_ENC_NC;
  43883. /* Don't reference table that is about to be freed. */
  43884. ret = wc_ClearSakkePointITable(key);
  43885. if (ret != 0)
  43886. return WC_TEST_RET_ENC_EC(ret);
  43887. /* Dispose of tables */
  43888. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43889. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43890. /* Make sure the key public key is exportable - convert to Montgomery form
  43891. * in Validation.
  43892. */
  43893. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1);
  43894. if (ret != 0)
  43895. return WC_TEST_RET_ENC_EC(ret);
  43896. if (sz != sizeof(pubData))
  43897. return WC_TEST_RET_ENC_NC;
  43898. if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0)
  43899. return WC_TEST_RET_ENC_NC;
  43900. sz = sizeof(pubData) + 1;
  43901. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0);
  43902. if (ret != 0)
  43903. return WC_TEST_RET_ENC_EC(ret);
  43904. if (sz != sizeof(pubData) + 1)
  43905. return WC_TEST_RET_ENC_NC;
  43906. if (pubKey[0] != 0x04)
  43907. return WC_TEST_RET_ENC_NC;
  43908. if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0)
  43909. return WC_TEST_RET_ENC_NC;
  43910. return 0;
  43911. }
  43912. static wc_test_ret_t sakke_kat_encapsulate_test(SakkeKey* key)
  43913. {
  43914. static const byte pubData[] = {
  43915. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  43916. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  43917. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  43918. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  43919. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  43920. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  43921. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  43922. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  43923. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  43924. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  43925. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  43926. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  43927. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  43928. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  43929. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  43930. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  43931. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  43932. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  43933. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  43934. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  43935. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  43936. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  43937. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  43938. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  43939. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  43940. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  43941. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  43942. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  43943. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  43944. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  43945. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  43946. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  43947. };
  43948. static const byte id[] = {
  43949. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43950. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43951. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43952. 0x33, 0x00
  43953. };
  43954. static const word32 idSz = sizeof(id);
  43955. byte ssv[] = {
  43956. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  43957. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  43958. };
  43959. static const word16 ssvSz = sizeof(ssv);
  43960. static const byte expAuth[] = {
  43961. 0x04,
  43962. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  43963. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  43964. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  43965. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  43966. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  43967. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  43968. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  43969. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  43970. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  43971. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  43972. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  43973. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  43974. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  43975. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  43976. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  43977. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  43978. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  43979. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  43980. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  43981. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  43982. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  43983. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  43984. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  43985. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  43986. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  43987. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  43988. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  43989. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  43990. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  43991. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  43992. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  43993. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  43994. };
  43995. static const byte encSsv[] = {
  43996. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  43997. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  43998. };
  43999. wc_test_ret_t ret;
  44000. byte auth[257];
  44001. word16 authSz = sizeof(auth);
  44002. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44003. if (ret != 0)
  44004. return WC_TEST_RET_ENC_EC(ret);
  44005. ret = wc_SetSakkeIdentity(key, id, idSz);
  44006. if (ret != 0)
  44007. return WC_TEST_RET_ENC_EC(ret);
  44008. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44009. auth, &authSz);
  44010. if (ret != 0)
  44011. return WC_TEST_RET_ENC_EC(ret);
  44012. if (authSz != 257)
  44013. return WC_TEST_RET_ENC_NC;
  44014. if (XMEMCMP(ssv, encSsv, ssvSz) != 0)
  44015. return WC_TEST_RET_ENC_NC;
  44016. if (XMEMCMP(auth, expAuth, authSz) != 0)
  44017. return WC_TEST_RET_ENC_NC;
  44018. return 0;
  44019. }
  44020. static wc_test_ret_t sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key,
  44021. WC_RNG* rng, ecc_point* rsk)
  44022. {
  44023. wc_test_ret_t ret;
  44024. byte data[440];
  44025. byte pubData[257];
  44026. word32 sz;
  44027. char mail[] = "test@wolfssl.com";
  44028. byte* id = (byte*)mail;
  44029. word32 idSz = (word32)XSTRLEN(mail);
  44030. int valid;
  44031. ecc_point* pubKey = rsk;
  44032. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44033. if (ret != 0)
  44034. return WC_TEST_RET_ENC_EC(ret);
  44035. ret = wc_MakeSakkeKey(priv, rng);
  44036. if (ret != 0)
  44037. return WC_TEST_RET_ENC_EC(ret);
  44038. ret = wc_ExportSakkeKey(priv, NULL, &sz);
  44039. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44040. return WC_TEST_RET_ENC_EC(ret);
  44041. if (sz != 384)
  44042. return WC_TEST_RET_ENC_NC;
  44043. sz--;
  44044. ret = wc_ExportSakkeKey(priv, data, &sz);
  44045. if (ret == 0)
  44046. return WC_TEST_RET_ENC_NC;
  44047. sz++;
  44048. ret = wc_ExportSakkeKey(priv, data, &sz);
  44049. if (ret != 0)
  44050. return WC_TEST_RET_ENC_EC(ret);
  44051. if (sz != 384)
  44052. return WC_TEST_RET_ENC_NC;
  44053. ret = wc_ImportSakkeKey(key, data, sz - 1);
  44054. if (ret == 0)
  44055. return WC_TEST_RET_ENC_NC;
  44056. ret = wc_ImportSakkeKey(key, data, sz);
  44057. if (ret != 0)
  44058. return WC_TEST_RET_ENC_EC(ret);
  44059. wc_FreeSakkeKey(key);
  44060. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44061. if (ret != 0)
  44062. return WC_TEST_RET_ENC_EC(ret);
  44063. ret = wc_ExportSakkePrivateKey(priv, NULL, &sz);
  44064. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44065. return WC_TEST_RET_ENC_EC(ret);
  44066. if (sz != 128)
  44067. return WC_TEST_RET_ENC_NC;
  44068. sz--;
  44069. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44070. if (ret == 0)
  44071. return WC_TEST_RET_ENC_NC;
  44072. sz++;
  44073. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44074. if (ret != 0)
  44075. return WC_TEST_RET_ENC_EC(ret);
  44076. if (sz != 128)
  44077. return WC_TEST_RET_ENC_NC;
  44078. ret = wc_ImportSakkePrivateKey(key, data, sz - 1);
  44079. if (ret == 0)
  44080. return WC_TEST_RET_ENC_NC;
  44081. ret = wc_ImportSakkePrivateKey(key, data, sz);
  44082. if (ret != 0)
  44083. return WC_TEST_RET_ENC_EC(ret);
  44084. ret = wc_MakeSakkePublicKey(key, pubKey);
  44085. if (ret != 0)
  44086. return WC_TEST_RET_ENC_EC(ret);
  44087. ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1);
  44088. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44089. return WC_TEST_RET_ENC_EC(ret);
  44090. if (sz != 256)
  44091. return WC_TEST_RET_ENC_NC;
  44092. sz--;
  44093. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44094. if (ret == 0)
  44095. return WC_TEST_RET_ENC_NC;
  44096. sz++;
  44097. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44098. if (ret != 0)
  44099. return WC_TEST_RET_ENC_EC(ret);
  44100. if (sz != 256)
  44101. return WC_TEST_RET_ENC_NC;
  44102. ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1);
  44103. if (ret == 0)
  44104. return WC_TEST_RET_ENC_NC;
  44105. ret = wc_ImportSakkePublicKey(pub, data, sz, 1);
  44106. if (ret != 0)
  44107. return WC_TEST_RET_ENC_EC(ret);
  44108. ret = wc_ExportSakkePublicKey(pub, pubData, &sz, 1);
  44109. if (ret != 0)
  44110. return WC_TEST_RET_ENC_EC(ret);
  44111. if (sz != 256)
  44112. return WC_TEST_RET_ENC_NC;
  44113. if (XMEMCMP(data, pubData, sz) != 0)
  44114. return WC_TEST_RET_ENC_NC;
  44115. ret = wc_MakeSakkeRsk(priv, id, idSz, rsk);
  44116. if (ret != 0)
  44117. return WC_TEST_RET_ENC_EC(ret);
  44118. ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid);
  44119. if (ret != 0)
  44120. return WC_TEST_RET_ENC_EC(ret);
  44121. if (valid != 1)
  44122. return WC_TEST_RET_ENC_NC;
  44123. ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid);
  44124. if (ret != 0)
  44125. return WC_TEST_RET_ENC_EC(ret);
  44126. if (valid != 1)
  44127. return WC_TEST_RET_ENC_NC;
  44128. sz = sizeof(data);
  44129. ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1);
  44130. if (ret != 0)
  44131. return WC_TEST_RET_ENC_EC(ret);
  44132. if (sz != 256)
  44133. return WC_TEST_RET_ENC_NC;
  44134. ret = wc_DecodeSakkeRsk(priv, data, sz, rsk);
  44135. if (ret != 0)
  44136. return WC_TEST_RET_ENC_EC(ret);
  44137. sz = sizeof(pubData);
  44138. ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0);
  44139. if (ret != 0)
  44140. return WC_TEST_RET_ENC_EC(ret);
  44141. if (sz != sizeof(pubData))
  44142. return WC_TEST_RET_ENC_NC;
  44143. ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk);
  44144. if (ret != 0)
  44145. return WC_TEST_RET_ENC_EC(ret);
  44146. wc_FreeSakkeKey(key);
  44147. return 0;
  44148. }
  44149. static wc_test_ret_t sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng,
  44150. ecc_point* rsk)
  44151. {
  44152. wc_test_ret_t ret;
  44153. byte ssv[16];
  44154. word16 ssvSz;
  44155. byte auth[257];
  44156. word16 authSz;
  44157. char mail[] = "test@wolfssl.com";
  44158. byte* id = (byte*)mail;
  44159. word32 idSz = (word32)XSTRLEN(mail);
  44160. byte pointI[256];
  44161. word32 sz;
  44162. ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz);
  44163. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44164. return WC_TEST_RET_ENC_EC(ret);
  44165. if (ssvSz != 16)
  44166. return WC_TEST_RET_ENC_NC;
  44167. ssvSz += 128;
  44168. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44169. if (ret == 0)
  44170. return WC_TEST_RET_ENC_NC;
  44171. ssvSz -= 128;
  44172. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44173. if (ret != 0)
  44174. return WC_TEST_RET_ENC_EC(ret);
  44175. if (ssvSz != 16)
  44176. return WC_TEST_RET_ENC_NC;
  44177. ret = wc_GetSakkeAuthSize(pub, &authSz);
  44178. if (ret != 0)
  44179. return WC_TEST_RET_ENC_EC(ret);
  44180. ret = wc_SetSakkeIdentity(pub, id, idSz);
  44181. if (ret != 0)
  44182. return WC_TEST_RET_ENC_EC(ret);
  44183. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44184. NULL, &authSz);
  44185. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44186. return WC_TEST_RET_ENC_EC(ret);
  44187. if (authSz != 257)
  44188. return WC_TEST_RET_ENC_NC;
  44189. authSz--;
  44190. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44191. auth, &authSz);
  44192. if (ret == 0)
  44193. return WC_TEST_RET_ENC_NC;
  44194. authSz++;
  44195. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44196. auth, &authSz);
  44197. if (ret != 0)
  44198. return WC_TEST_RET_ENC_EC(ret);
  44199. if (authSz != 257)
  44200. return WC_TEST_RET_ENC_NC;
  44201. ret = wc_GetSakkePointI(pub, NULL, &sz);
  44202. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44203. return WC_TEST_RET_ENC_EC(ret);
  44204. if (sz != 256)
  44205. return WC_TEST_RET_ENC_NC;
  44206. ret = wc_GetSakkePointI(pub, pointI, &sz);
  44207. if (ret != 0)
  44208. return WC_TEST_RET_ENC_EC(ret);
  44209. if (sz != 256)
  44210. return WC_TEST_RET_ENC_NC;
  44211. /* Bogus identity - make it check and regenerate I. */
  44212. ret = wc_MakeSakkePointI(pub, ssv, ssvSz);
  44213. if (ret != 0)
  44214. return WC_TEST_RET_ENC_EC(ret);
  44215. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44216. auth, &authSz);
  44217. if (ret != 0)
  44218. return WC_TEST_RET_ENC_EC(ret);
  44219. if (authSz != 257)
  44220. return WC_TEST_RET_ENC_NC;
  44221. ret = wc_SetSakkeRsk(priv, rsk, NULL, 0);
  44222. if (ret != 0)
  44223. return WC_TEST_RET_ENC_EC(ret);
  44224. ret = wc_SetSakkeIdentity(priv, id, idSz);
  44225. if (ret != 0)
  44226. return WC_TEST_RET_ENC_EC(ret);
  44227. authSz--;
  44228. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44229. authSz);
  44230. if (ret == 0)
  44231. return WC_TEST_RET_ENC_NC;
  44232. authSz++;
  44233. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44234. authSz);
  44235. if (ret != 0)
  44236. return WC_TEST_RET_ENC_EC(ret);
  44237. ssv[0] ^= 0x80;
  44238. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44239. authSz);
  44240. if (ret != WC_NO_ERR_TRACE(SAKKE_VERIFY_FAIL_E))
  44241. return WC_TEST_RET_ENC_EC(ret);
  44242. ssv[0] ^= 0x80;
  44243. /* Bogus identity - make it check and regenerate I. */
  44244. ret = wc_MakeSakkePointI(pub, ssv, idSz);
  44245. if (ret != 0)
  44246. return WC_TEST_RET_ENC_EC(ret);
  44247. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44248. authSz);
  44249. if (ret != 0)
  44250. return WC_TEST_RET_ENC_EC(ret);
  44251. return 0;
  44252. }
  44253. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void)
  44254. {
  44255. wc_test_ret_t ret = 0;
  44256. WC_RNG rng;
  44257. int rng_inited = 0;
  44258. SakkeKey* priv = NULL;
  44259. SakkeKey* pub = NULL;
  44260. SakkeKey* key = NULL;
  44261. ecc_point* rsk = NULL;
  44262. WOLFSSL_ENTER("sakke_test");
  44263. priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44264. DYNAMIC_TYPE_TMP_BUFFER);
  44265. if (priv == NULL)
  44266. ret = WC_TEST_RET_ENC_NC;
  44267. else
  44268. XMEMSET(priv, 0, sizeof(*priv));
  44269. if (ret == 0) {
  44270. pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44271. DYNAMIC_TYPE_TMP_BUFFER);
  44272. if (pub == NULL)
  44273. ret = WC_TEST_RET_ENC_NC;
  44274. else
  44275. XMEMSET(pub, 0, sizeof(*pub));
  44276. }
  44277. if (ret == 0) {
  44278. key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44279. DYNAMIC_TYPE_TMP_BUFFER);
  44280. if (key == NULL)
  44281. ret = WC_TEST_RET_ENC_NC;
  44282. else
  44283. XMEMSET(key, 0, sizeof(*key));
  44284. }
  44285. if (ret == 0) {
  44286. #ifndef HAVE_FIPS
  44287. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  44288. #else
  44289. ret = wc_InitRng(&rng);
  44290. #endif
  44291. if (ret == 0)
  44292. rng_inited = 1;
  44293. else
  44294. ret = WC_TEST_RET_ENC_EC(ret);
  44295. }
  44296. if (ret == 0) {
  44297. rsk = wc_ecc_new_point();
  44298. if (rsk == NULL)
  44299. ret = WC_TEST_RET_ENC_NC;
  44300. }
  44301. if (ret == 0) {
  44302. ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID);
  44303. if (ret != 0)
  44304. ret = WC_TEST_RET_ENC_EC(ret);
  44305. }
  44306. if (ret == 0) {
  44307. ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID);
  44308. if (ret != 0)
  44309. ret = WC_TEST_RET_ENC_EC(ret);
  44310. }
  44311. if (ret == 0) {
  44312. ret = sakke_api_test(&rng, key, rsk);
  44313. }
  44314. if (ret == 0) {
  44315. ret = sakke_kat_derive_test(pub, rsk);
  44316. }
  44317. if (ret == 0) {
  44318. ret = sakke_kat_encapsulate_test(pub);
  44319. }
  44320. if (ret == 0) {
  44321. ret = sakke_make_key_test(priv, pub, key, &rng, rsk);
  44322. }
  44323. if (ret == 0) {
  44324. ret = sakke_op_test(priv, pub, &rng, rsk);
  44325. }
  44326. if (rsk != NULL) {
  44327. wc_ecc_forcezero_point(rsk);
  44328. wc_ecc_del_point(rsk);
  44329. }
  44330. if (rng_inited)
  44331. wc_FreeRng(&rng);
  44332. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44333. if (pub != NULL) {
  44334. wc_FreeSakkeKey(pub);
  44335. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44336. }
  44337. if (priv != NULL) {
  44338. wc_FreeSakkeKey(priv);
  44339. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44340. }
  44341. return ret;
  44342. }
  44343. #endif /* WOLFCRYPT_HAVE_SAKKE */
  44344. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  44345. typedef struct CMAC_Test_Case {
  44346. int type;
  44347. int partial;
  44348. const byte* m;
  44349. word32 mSz;
  44350. const byte* k;
  44351. word32 kSz;
  44352. const byte* t;
  44353. word32 tSz;
  44354. } CMAC_Test_Case;
  44355. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void)
  44356. {
  44357. #ifdef WOLFSSL_AES_128
  44358. WOLFSSL_SMALL_STACK_STATIC const byte k128[] =
  44359. {
  44360. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  44361. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  44362. };
  44363. #define KLEN_128 (sizeof(k128))
  44364. #endif
  44365. #ifdef WOLFSSL_AES_192
  44366. WOLFSSL_SMALL_STACK_STATIC const byte k192[] =
  44367. {
  44368. 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
  44369. 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
  44370. 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
  44371. };
  44372. #define KLEN_192 (sizeof(k192))
  44373. #endif
  44374. #ifdef WOLFSSL_AES_256
  44375. WOLFSSL_SMALL_STACK_STATIC const byte k256[] =
  44376. {
  44377. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  44378. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  44379. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  44380. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  44381. };
  44382. #define KLEN_256 (sizeof(k256))
  44383. #endif
  44384. WOLFSSL_SMALL_STACK_STATIC const byte m[] =
  44385. {
  44386. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  44387. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  44388. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  44389. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  44390. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  44391. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  44392. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  44393. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  44394. };
  44395. #define MLEN_0 (0)
  44396. #define MLEN_128 (128/8)
  44397. #define MLEN_320 (320/8)
  44398. #define MLEN_319 (MLEN_320 - 1)
  44399. #define MLEN_512 (512/8)
  44400. #ifdef WOLFSSL_AES_128
  44401. WOLFSSL_SMALL_STACK_STATIC const byte t128_0[] =
  44402. {
  44403. 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
  44404. 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
  44405. };
  44406. WOLFSSL_SMALL_STACK_STATIC const byte t128_128[] =
  44407. {
  44408. 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
  44409. 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
  44410. };
  44411. WOLFSSL_SMALL_STACK_STATIC const byte t128_319[] =
  44412. {
  44413. 0x2c, 0x17, 0x84, 0x4c, 0x93, 0x1c, 0x07, 0x95,
  44414. 0x15, 0x92, 0x73, 0x0a, 0x34, 0xd0, 0xd9, 0xd2
  44415. };
  44416. WOLFSSL_SMALL_STACK_STATIC const byte t128_320[] =
  44417. {
  44418. 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
  44419. 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
  44420. };
  44421. WOLFSSL_SMALL_STACK_STATIC const byte t128_512[] =
  44422. {
  44423. 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
  44424. 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
  44425. };
  44426. #endif
  44427. #ifdef WOLFSSL_AES_192
  44428. WOLFSSL_SMALL_STACK_STATIC const byte t192_0[] =
  44429. {
  44430. 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
  44431. 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
  44432. };
  44433. WOLFSSL_SMALL_STACK_STATIC const byte t192_128[] =
  44434. {
  44435. 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
  44436. 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
  44437. };
  44438. WOLFSSL_SMALL_STACK_STATIC const byte t192_320[] =
  44439. {
  44440. 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
  44441. 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
  44442. };
  44443. WOLFSSL_SMALL_STACK_STATIC const byte t192_512[] =
  44444. {
  44445. 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
  44446. 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
  44447. };
  44448. #endif
  44449. #ifdef WOLFSSL_AES_256
  44450. WOLFSSL_SMALL_STACK_STATIC const byte t256_0[] =
  44451. {
  44452. 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
  44453. 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
  44454. };
  44455. WOLFSSL_SMALL_STACK_STATIC const byte t256_128[] =
  44456. {
  44457. 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
  44458. 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
  44459. };
  44460. WOLFSSL_SMALL_STACK_STATIC const byte t256_320[] =
  44461. {
  44462. 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
  44463. 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
  44464. };
  44465. WOLFSSL_SMALL_STACK_STATIC const byte t256_512[] =
  44466. {
  44467. 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
  44468. 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
  44469. };
  44470. #endif
  44471. const CMAC_Test_Case testCases[] =
  44472. {
  44473. #ifdef WOLFSSL_AES_128
  44474. {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, AES_BLOCK_SIZE},
  44475. {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, AES_BLOCK_SIZE},
  44476. {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, AES_BLOCK_SIZE},
  44477. {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44478. {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44479. #endif
  44480. #ifdef WOLFSSL_AES_192
  44481. {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, AES_BLOCK_SIZE},
  44482. {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, AES_BLOCK_SIZE},
  44483. {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, AES_BLOCK_SIZE},
  44484. {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, AES_BLOCK_SIZE},
  44485. #endif
  44486. #ifdef WOLFSSL_AES_256
  44487. {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, AES_BLOCK_SIZE},
  44488. {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, AES_BLOCK_SIZE},
  44489. {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, AES_BLOCK_SIZE},
  44490. {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, AES_BLOCK_SIZE},
  44491. #endif
  44492. #ifdef WOLFSSL_AES_128
  44493. {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, AES_BLOCK_SIZE}
  44494. #endif
  44495. };
  44496. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44497. Cmac *cmac;
  44498. #else
  44499. Cmac cmac[1];
  44500. #endif
  44501. byte tag[AES_BLOCK_SIZE];
  44502. const CMAC_Test_Case* tc;
  44503. word32 i, tagSz;
  44504. wc_test_ret_t ret;
  44505. WOLFSSL_ENTER("cmac_test");
  44506. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44507. if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL)
  44508. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  44509. #endif
  44510. for (i = 0, tc = testCases;
  44511. i < sizeof(testCases)/sizeof(CMAC_Test_Case);
  44512. i++, tc++) {
  44513. XMEMSET(tag, 0, sizeof(tag));
  44514. tagSz = AES_BLOCK_SIZE;
  44515. #if !defined(HAVE_FIPS) || \
  44516. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)
  44517. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44518. #else
  44519. ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL);
  44520. #endif
  44521. if (ret != 0)
  44522. {
  44523. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44524. }
  44525. if (tc->partial) {
  44526. ret = wc_CmacUpdate(cmac, tc->m,
  44527. tc->mSz/2 - tc->partial);
  44528. if (ret != 0)
  44529. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44530. ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial,
  44531. tc->mSz/2 + tc->partial);
  44532. if (ret != 0)
  44533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44534. }
  44535. else {
  44536. ret = wc_CmacUpdate(cmac, tc->m, tc->mSz);
  44537. if (ret != 0)
  44538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44539. }
  44540. ret = wc_CmacFinal(cmac, tag, &tagSz);
  44541. if (ret != 0)
  44542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44543. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44544. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44545. XMEMSET(tag, 0, sizeof(tag));
  44546. tagSz = sizeof(tag);
  44547. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44548. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44549. tc->k, tc->kSz, NULL, devId);
  44550. #else
  44551. ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz,
  44552. tc->k, tc->kSz);
  44553. #endif
  44554. if (ret != 0)
  44555. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44556. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44557. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44558. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44559. ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz,
  44560. tc->k, tc->kSz, HEAP_HINT, devId);
  44561. #else
  44562. ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz,
  44563. tc->k, tc->kSz);
  44564. #endif
  44565. if (ret != 0)
  44566. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44567. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44568. /* Test that keyless generate with init is the same */
  44569. XMEMSET(tag, 0, sizeof(tag));
  44570. tagSz = sizeof(tag);
  44571. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44572. if (ret != 0) {
  44573. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44574. }
  44575. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44576. NULL, 0, HEAP_HINT, devId);
  44577. if (ret != 0) {
  44578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44579. }
  44580. #endif
  44581. }
  44582. ret = 0;
  44583. out:
  44584. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44585. XFREE(cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC);
  44586. #endif
  44587. return ret;
  44588. }
  44589. #endif /* !NO_AES && WOLFSSL_CMAC */
  44590. #if defined(WOLFSSL_SIPHASH)
  44591. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44592. /* Test vectors from:
  44593. * https://github.com/veorq/SipHash/blob/master/vectors.h
  44594. */
  44595. static const unsigned char siphash_key[SIPHASH_KEY_SIZE] = {
  44596. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44597. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  44598. };
  44599. static const unsigned char siphash_msg[64] = {
  44600. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44601. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44602. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  44603. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  44604. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  44605. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  44606. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  44607. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  44608. };
  44609. static const unsigned char siphash_r8[64][SIPHASH_MAC_SIZE_8] = {
  44610. { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
  44611. { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
  44612. { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, },
  44613. { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, },
  44614. { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, },
  44615. { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, },
  44616. { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, },
  44617. { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, },
  44618. { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, },
  44619. { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, },
  44620. { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, },
  44621. { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, },
  44622. { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, },
  44623. { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, },
  44624. { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, },
  44625. { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, },
  44626. { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, },
  44627. { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, },
  44628. { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, },
  44629. { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, },
  44630. { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, },
  44631. { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, },
  44632. { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, },
  44633. { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, },
  44634. { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, },
  44635. { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, },
  44636. { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, },
  44637. { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, },
  44638. { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, },
  44639. { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, },
  44640. { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, },
  44641. { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, },
  44642. { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, },
  44643. { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, },
  44644. { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, },
  44645. { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, },
  44646. { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, },
  44647. { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, },
  44648. { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, },
  44649. { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, },
  44650. { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, },
  44651. { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, },
  44652. { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, },
  44653. { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, },
  44654. { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, },
  44655. { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
  44656. { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
  44657. { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
  44658. { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
  44659. { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
  44660. { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
  44661. { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
  44662. { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
  44663. { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
  44664. { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
  44665. { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
  44666. { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
  44667. { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
  44668. { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
  44669. { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
  44670. { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
  44671. { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
  44672. { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
  44673. { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, },
  44674. };
  44675. static const unsigned char siphash_r16[64][SIPHASH_MAC_SIZE_16] = {
  44676. { 0xa3, 0x81, 0x7f, 0x04, 0xba, 0x25, 0xa8, 0xe6,
  44677. 0x6d, 0xf6, 0x72, 0x14, 0xc7, 0x55, 0x02, 0x93, },
  44678. { 0xda, 0x87, 0xc1, 0xd8, 0x6b, 0x99, 0xaf, 0x44,
  44679. 0x34, 0x76, 0x59, 0x11, 0x9b, 0x22, 0xfc, 0x45, },
  44680. { 0x81, 0x77, 0x22, 0x8d, 0xa4, 0xa4, 0x5d, 0xc7,
  44681. 0xfc, 0xa3, 0x8b, 0xde, 0xf6, 0x0a, 0xff, 0xe4, },
  44682. { 0x9c, 0x70, 0xb6, 0x0c, 0x52, 0x67, 0xa9, 0x4e,
  44683. 0x5f, 0x33, 0xb6, 0xb0, 0x29, 0x85, 0xed, 0x51, },
  44684. { 0xf8, 0x81, 0x64, 0xc1, 0x2d, 0x9c, 0x8f, 0xaf,
  44685. 0x7d, 0x0f, 0x6e, 0x7c, 0x7b, 0xcd, 0x55, 0x79, },
  44686. { 0x13, 0x68, 0x87, 0x59, 0x80, 0x77, 0x6f, 0x88,
  44687. 0x54, 0x52, 0x7a, 0x07, 0x69, 0x0e, 0x96, 0x27, },
  44688. { 0x14, 0xee, 0xca, 0x33, 0x8b, 0x20, 0x86, 0x13,
  44689. 0x48, 0x5e, 0xa0, 0x30, 0x8f, 0xd7, 0xa1, 0x5e, },
  44690. { 0xa1, 0xf1, 0xeb, 0xbe, 0xd8, 0xdb, 0xc1, 0x53,
  44691. 0xc0, 0xb8, 0x4a, 0xa6, 0x1f, 0xf0, 0x82, 0x39, },
  44692. { 0x3b, 0x62, 0xa9, 0xba, 0x62, 0x58, 0xf5, 0x61,
  44693. 0x0f, 0x83, 0xe2, 0x64, 0xf3, 0x14, 0x97, 0xb4, },
  44694. { 0x26, 0x44, 0x99, 0x06, 0x0a, 0xd9, 0xba, 0xab,
  44695. 0xc4, 0x7f, 0x8b, 0x02, 0xbb, 0x6d, 0x71, 0xed, },
  44696. { 0x00, 0x11, 0x0d, 0xc3, 0x78, 0x14, 0x69, 0x56,
  44697. 0xc9, 0x54, 0x47, 0xd3, 0xf3, 0xd0, 0xfb, 0xba, },
  44698. { 0x01, 0x51, 0xc5, 0x68, 0x38, 0x6b, 0x66, 0x77,
  44699. 0xa2, 0xb4, 0xdc, 0x6f, 0x81, 0xe5, 0xdc, 0x18, },
  44700. { 0xd6, 0x26, 0xb2, 0x66, 0x90, 0x5e, 0xf3, 0x58,
  44701. 0x82, 0x63, 0x4d, 0xf6, 0x85, 0x32, 0xc1, 0x25, },
  44702. { 0x98, 0x69, 0xe2, 0x47, 0xe9, 0xc0, 0x8b, 0x10,
  44703. 0xd0, 0x29, 0x93, 0x4f, 0xc4, 0xb9, 0x52, 0xf7, },
  44704. { 0x31, 0xfc, 0xef, 0xac, 0x66, 0xd7, 0xde, 0x9c,
  44705. 0x7e, 0xc7, 0x48, 0x5f, 0xe4, 0x49, 0x49, 0x02, },
  44706. { 0x54, 0x93, 0xe9, 0x99, 0x33, 0xb0, 0xa8, 0x11,
  44707. 0x7e, 0x08, 0xec, 0x0f, 0x97, 0xcf, 0xc3, 0xd9, },
  44708. { 0x6e, 0xe2, 0xa4, 0xca, 0x67, 0xb0, 0x54, 0xbb,
  44709. 0xfd, 0x33, 0x15, 0xbf, 0x85, 0x23, 0x05, 0x77, },
  44710. { 0x47, 0x3d, 0x06, 0xe8, 0x73, 0x8d, 0xb8, 0x98,
  44711. 0x54, 0xc0, 0x66, 0xc4, 0x7a, 0xe4, 0x77, 0x40, },
  44712. { 0xa4, 0x26, 0xe5, 0xe4, 0x23, 0xbf, 0x48, 0x85,
  44713. 0x29, 0x4d, 0xa4, 0x81, 0xfe, 0xae, 0xf7, 0x23, },
  44714. { 0x78, 0x01, 0x77, 0x31, 0xcf, 0x65, 0xfa, 0xb0,
  44715. 0x74, 0xd5, 0x20, 0x89, 0x52, 0x51, 0x2e, 0xb1, },
  44716. { 0x9e, 0x25, 0xfc, 0x83, 0x3f, 0x22, 0x90, 0x73,
  44717. 0x3e, 0x93, 0x44, 0xa5, 0xe8, 0x38, 0x39, 0xeb, },
  44718. { 0x56, 0x8e, 0x49, 0x5a, 0xbe, 0x52, 0x5a, 0x21,
  44719. 0x8a, 0x22, 0x14, 0xcd, 0x3e, 0x07, 0x1d, 0x12, },
  44720. { 0x4a, 0x29, 0xb5, 0x45, 0x52, 0xd1, 0x6b, 0x9a,
  44721. 0x46, 0x9c, 0x10, 0x52, 0x8e, 0xff, 0x0a, 0xae, },
  44722. { 0xc9, 0xd1, 0x84, 0xdd, 0xd5, 0xa9, 0xf5, 0xe0,
  44723. 0xcf, 0x8c, 0xe2, 0x9a, 0x9a, 0xbf, 0x69, 0x1c, },
  44724. { 0x2d, 0xb4, 0x79, 0xae, 0x78, 0xbd, 0x50, 0xd8,
  44725. 0x88, 0x2a, 0x8a, 0x17, 0x8a, 0x61, 0x32, 0xad, },
  44726. { 0x8e, 0xce, 0x5f, 0x04, 0x2d, 0x5e, 0x44, 0x7b,
  44727. 0x50, 0x51, 0xb9, 0xea, 0xcb, 0x8d, 0x8f, 0x6f, },
  44728. { 0x9c, 0x0b, 0x53, 0xb4, 0xb3, 0xc3, 0x07, 0xe8,
  44729. 0x7e, 0xae, 0xe0, 0x86, 0x78, 0x14, 0x1f, 0x66, },
  44730. { 0xab, 0xf2, 0x48, 0xaf, 0x69, 0xa6, 0xea, 0xe4,
  44731. 0xbf, 0xd3, 0xeb, 0x2f, 0x12, 0x9e, 0xeb, 0x94, },
  44732. { 0x06, 0x64, 0xda, 0x16, 0x68, 0x57, 0x4b, 0x88,
  44733. 0xb9, 0x35, 0xf3, 0x02, 0x73, 0x58, 0xae, 0xf4, },
  44734. { 0xaa, 0x4b, 0x9d, 0xc4, 0xbf, 0x33, 0x7d, 0xe9,
  44735. 0x0c, 0xd4, 0xfd, 0x3c, 0x46, 0x7c, 0x6a, 0xb7, },
  44736. { 0xea, 0x5c, 0x7f, 0x47, 0x1f, 0xaf, 0x6b, 0xde,
  44737. 0x2b, 0x1a, 0xd7, 0xd4, 0x68, 0x6d, 0x22, 0x87, },
  44738. { 0x29, 0x39, 0xb0, 0x18, 0x32, 0x23, 0xfa, 0xfc,
  44739. 0x17, 0x23, 0xde, 0x4f, 0x52, 0xc4, 0x3d, 0x35, },
  44740. { 0x7c, 0x39, 0x56, 0xca, 0x5e, 0xea, 0xfc, 0x3e,
  44741. 0x36, 0x3e, 0x9d, 0x55, 0x65, 0x46, 0xeb, 0x68, },
  44742. { 0x77, 0xc6, 0x07, 0x71, 0x46, 0xf0, 0x1c, 0x32,
  44743. 0xb6, 0xb6, 0x9d, 0x5f, 0x4e, 0xa9, 0xff, 0xcf, },
  44744. { 0x37, 0xa6, 0x98, 0x6c, 0xb8, 0x84, 0x7e, 0xdf,
  44745. 0x09, 0x25, 0xf0, 0xf1, 0x30, 0x9b, 0x54, 0xde, },
  44746. { 0xa7, 0x05, 0xf0, 0xe6, 0x9d, 0xa9, 0xa8, 0xf9,
  44747. 0x07, 0x24, 0x1a, 0x2e, 0x92, 0x3c, 0x8c, 0xc8, },
  44748. { 0x3d, 0xc4, 0x7d, 0x1f, 0x29, 0xc4, 0x48, 0x46,
  44749. 0x1e, 0x9e, 0x76, 0xed, 0x90, 0x4f, 0x67, 0x11, },
  44750. { 0x0d, 0x62, 0xbf, 0x01, 0xe6, 0xfc, 0x0e, 0x1a,
  44751. 0x0d, 0x3c, 0x47, 0x51, 0xc5, 0xd3, 0x69, 0x2b, },
  44752. { 0x8c, 0x03, 0x46, 0x8b, 0xca, 0x7c, 0x66, 0x9e,
  44753. 0xe4, 0xfd, 0x5e, 0x08, 0x4b, 0xbe, 0xe7, 0xb5, },
  44754. { 0x52, 0x8a, 0x5b, 0xb9, 0x3b, 0xaf, 0x2c, 0x9c,
  44755. 0x44, 0x73, 0xcc, 0xe5, 0xd0, 0xd2, 0x2b, 0xd9, },
  44756. { 0xdf, 0x6a, 0x30, 0x1e, 0x95, 0xc9, 0x5d, 0xad,
  44757. 0x97, 0xae, 0x0c, 0xc8, 0xc6, 0x91, 0x3b, 0xd8, },
  44758. { 0x80, 0x11, 0x89, 0x90, 0x2c, 0x85, 0x7f, 0x39,
  44759. 0xe7, 0x35, 0x91, 0x28, 0x5e, 0x70, 0xb6, 0xdb, },
  44760. { 0xe6, 0x17, 0x34, 0x6a, 0xc9, 0xc2, 0x31, 0xbb,
  44761. 0x36, 0x50, 0xae, 0x34, 0xcc, 0xca, 0x0c, 0x5b, },
  44762. { 0x27, 0xd9, 0x34, 0x37, 0xef, 0xb7, 0x21, 0xaa,
  44763. 0x40, 0x18, 0x21, 0xdc, 0xec, 0x5a, 0xdf, 0x89, },
  44764. { 0x89, 0x23, 0x7d, 0x9d, 0xed, 0x9c, 0x5e, 0x78,
  44765. 0xd8, 0xb1, 0xc9, 0xb1, 0x66, 0xcc, 0x73, 0x42, },
  44766. { 0x4a, 0x6d, 0x80, 0x91, 0xbf, 0x5e, 0x7d, 0x65,
  44767. 0x11, 0x89, 0xfa, 0x94, 0xa2, 0x50, 0xb1, 0x4c, },
  44768. { 0x0e, 0x33, 0xf9, 0x60, 0x55, 0xe7, 0xae, 0x89,
  44769. 0x3f, 0xfc, 0x0e, 0x3d, 0xcf, 0x49, 0x29, 0x02, },
  44770. { 0xe6, 0x1c, 0x43, 0x2b, 0x72, 0x0b, 0x19, 0xd1,
  44771. 0x8e, 0xc8, 0xd8, 0x4b, 0xdc, 0x63, 0x15, 0x1b, },
  44772. { 0xf7, 0xe5, 0xae, 0xf5, 0x49, 0xf7, 0x82, 0xcf,
  44773. 0x37, 0x90, 0x55, 0xa6, 0x08, 0x26, 0x9b, 0x16, },
  44774. { 0x43, 0x8d, 0x03, 0x0f, 0xd0, 0xb7, 0xa5, 0x4f,
  44775. 0xa8, 0x37, 0xf2, 0xad, 0x20, 0x1a, 0x64, 0x03, },
  44776. { 0xa5, 0x90, 0xd3, 0xee, 0x4f, 0xbf, 0x04, 0xe3,
  44777. 0x24, 0x7e, 0x0d, 0x27, 0xf2, 0x86, 0x42, 0x3f, },
  44778. { 0x5f, 0xe2, 0xc1, 0xa1, 0x72, 0xfe, 0x93, 0xc4,
  44779. 0xb1, 0x5c, 0xd3, 0x7c, 0xae, 0xf9, 0xf5, 0x38, },
  44780. { 0x2c, 0x97, 0x32, 0x5c, 0xbd, 0x06, 0xb3, 0x6e,
  44781. 0xb2, 0x13, 0x3d, 0xd0, 0x8b, 0x3a, 0x01, 0x7c, },
  44782. { 0x92, 0xc8, 0x14, 0x22, 0x7a, 0x6b, 0xca, 0x94,
  44783. 0x9f, 0xf0, 0x65, 0x9f, 0x00, 0x2a, 0xd3, 0x9e, },
  44784. { 0xdc, 0xe8, 0x50, 0x11, 0x0b, 0xd8, 0x32, 0x8c,
  44785. 0xfb, 0xd5, 0x08, 0x41, 0xd6, 0x91, 0x1d, 0x87, },
  44786. { 0x67, 0xf1, 0x49, 0x84, 0xc7, 0xda, 0x79, 0x12,
  44787. 0x48, 0xe3, 0x2b, 0xb5, 0x92, 0x25, 0x83, 0xda, },
  44788. { 0x19, 0x38, 0xf2, 0xcf, 0x72, 0xd5, 0x4e, 0xe9,
  44789. 0x7e, 0x94, 0x16, 0x6f, 0xa9, 0x1d, 0x2a, 0x36, },
  44790. { 0x74, 0x48, 0x1e, 0x96, 0x46, 0xed, 0x49, 0xfe,
  44791. 0x0f, 0x62, 0x24, 0x30, 0x16, 0x04, 0x69, 0x8e, },
  44792. { 0x57, 0xfc, 0xa5, 0xde, 0x98, 0xa9, 0xd6, 0xd8,
  44793. 0x00, 0x64, 0x38, 0xd0, 0x58, 0x3d, 0x8a, 0x1d, },
  44794. { 0x9f, 0xec, 0xde, 0x1c, 0xef, 0xdc, 0x1c, 0xbe,
  44795. 0xd4, 0x76, 0x36, 0x74, 0xd9, 0x57, 0x53, 0x59, },
  44796. { 0xe3, 0x04, 0x0c, 0x00, 0xeb, 0x28, 0xf1, 0x53,
  44797. 0x66, 0xca, 0x73, 0xcb, 0xd8, 0x72, 0xe7, 0x40, },
  44798. { 0x76, 0x97, 0x00, 0x9a, 0x6a, 0x83, 0x1d, 0xfe,
  44799. 0xcc, 0xa9, 0x1c, 0x59, 0x93, 0x67, 0x0f, 0x7a, },
  44800. { 0x58, 0x53, 0x54, 0x23, 0x21, 0xf5, 0x67, 0xa0,
  44801. 0x05, 0xd5, 0x47, 0xa4, 0xf0, 0x47, 0x59, 0xbd, },
  44802. { 0x51, 0x50, 0xd1, 0x77, 0x2f, 0x50, 0x83, 0x4a,
  44803. 0x50, 0x3e, 0x06, 0x9a, 0x97, 0x3f, 0xbd, 0x7c, },
  44804. };
  44805. #endif
  44806. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void)
  44807. {
  44808. wc_test_ret_t ret = 0;
  44809. int i;
  44810. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44811. unsigned char res[SIPHASH_MAC_SIZE_16];
  44812. unsigned char tmp[SIPHASH_MAC_SIZE_8];
  44813. SipHash siphash;
  44814. WOLFSSL_ENTER("siphash_test (1)");
  44815. for (i = 0; i < 64; i++) {
  44816. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44817. if (ret != 0)
  44818. return WC_TEST_RET_ENC_I(i);
  44819. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  44820. if (ret != 0)
  44821. return WC_TEST_RET_ENC_I(i);
  44822. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  44823. if (ret != 0)
  44824. return WC_TEST_RET_ENC_I(i);
  44825. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  44826. return WC_TEST_RET_ENC_I(i);
  44827. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_8);
  44828. if (ret != 0)
  44829. return WC_TEST_RET_ENC_I(i);
  44830. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  44831. return WC_TEST_RET_ENC_I(i);
  44832. }
  44833. for (i = 0; i < 64; i++) {
  44834. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16);
  44835. if (ret != 0)
  44836. return WC_TEST_RET_ENC_I(i);
  44837. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  44838. if (ret != 0)
  44839. return WC_TEST_RET_ENC_I(i);
  44840. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  44841. if (ret != 0)
  44842. return WC_TEST_RET_ENC_I(i);
  44843. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  44844. return WC_TEST_RET_ENC_I(i);
  44845. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_16);
  44846. if (ret != 0)
  44847. return WC_TEST_RET_ENC_I(i);
  44848. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  44849. return WC_TEST_RET_ENC_I(i);
  44850. }
  44851. #else
  44852. WOLFSSL_ENTER("siphash_test (1)");
  44853. #endif
  44854. /* Testing bad parameters. */
  44855. ret = wc_InitSipHash(NULL, NULL, SIPHASH_MAC_SIZE_8);
  44856. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44857. return WC_TEST_RET_ENC_EC(ret);
  44858. ret = wc_InitSipHash(NULL, siphash_key, SIPHASH_MAC_SIZE_8);
  44859. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44860. return WC_TEST_RET_ENC_EC(ret);
  44861. ret = wc_InitSipHash(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  44862. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44863. return WC_TEST_RET_ENC_EC(ret);
  44864. ret = wc_InitSipHash(&siphash, siphash_key, 7);
  44865. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44866. return WC_TEST_RET_ENC_EC(ret);
  44867. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44868. if (ret != 0)
  44869. return WC_TEST_RET_ENC_EC(ret);
  44870. ret = wc_SipHashUpdate(NULL, NULL, 0);
  44871. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44872. return WC_TEST_RET_ENC_EC(ret);
  44873. ret = wc_SipHashUpdate(&siphash, NULL, 1);
  44874. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44875. return WC_TEST_RET_ENC_EC(ret);
  44876. ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8);
  44877. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44878. return WC_TEST_RET_ENC_EC(ret);
  44879. ret = wc_SipHashFinal(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  44880. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44881. return WC_TEST_RET_ENC_EC(ret);
  44882. ret = wc_SipHashFinal(NULL, res, SIPHASH_MAC_SIZE_8);
  44883. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44884. return WC_TEST_RET_ENC_EC(ret);
  44885. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  44886. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44887. return WC_TEST_RET_ENC_EC(ret);
  44888. ret = wc_SipHash(NULL, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  44889. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44890. return WC_TEST_RET_ENC_EC(ret);
  44891. ret = wc_SipHash(siphash_key, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  44892. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44893. return WC_TEST_RET_ENC_EC(ret);
  44894. ret = wc_SipHash(NULL, NULL, 0, res, SIPHASH_MAC_SIZE_16);
  44895. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44896. return WC_TEST_RET_ENC_EC(ret);
  44897. ret = wc_SipHash(siphash_key, NULL, 0, res, 15);
  44898. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44899. return WC_TEST_RET_ENC_EC(ret);
  44900. ret = wc_SipHash(siphash_key, NULL, 1, res, SIPHASH_MAC_SIZE_16);
  44901. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44902. return WC_TEST_RET_ENC_EC(ret);
  44903. /* Test cache with multiple non blocksize bytes */
  44904. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44905. if (ret != 0)
  44906. return WC_TEST_RET_ENC_EC(ret);
  44907. ret = wc_SipHashUpdate(&siphash, siphash_msg, 5);
  44908. if (ret != 0)
  44909. return WC_TEST_RET_ENC_EC(ret);
  44910. ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4);
  44911. if (ret != 0)
  44912. return WC_TEST_RET_ENC_EC(ret);
  44913. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  44914. if (ret != 0)
  44915. return WC_TEST_RET_ENC_EC(ret);
  44916. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  44917. if (ret != 0)
  44918. return WC_TEST_RET_ENC_EC(ret);
  44919. ret = wc_SipHashUpdate(&siphash, siphash_msg, 9);
  44920. if (ret != 0)
  44921. return WC_TEST_RET_ENC_EC(ret);
  44922. ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8);
  44923. if (ret != 0)
  44924. return WC_TEST_RET_ENC_EC(ret);
  44925. if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0)
  44926. return WC_TEST_RET_ENC_NC;
  44927. return 0;
  44928. }
  44929. #endif /* WOLFSSL_SIPHASH */
  44930. #ifdef HAVE_LIBZ
  44931. static const byte sample_text[] =
  44932. "Biodiesel cupidatat marfa, cliche aute put a bird on it incididunt elit\n"
  44933. "polaroid. Sunt tattooed bespoke reprehenderit. Sint twee organic id\n"
  44934. "marfa. Commodo veniam ad esse gastropub. 3 wolf moon sartorial vero,\n"
  44935. "plaid delectus biodiesel squid +1 vice. Post-ironic keffiyeh leggings\n"
  44936. "selfies cray fap hoodie, forage anim. Carles cupidatat shoreditch, VHS\n"
  44937. "small batch meggings kogi dolore food truck bespoke gastropub.\n"
  44938. "\n"
  44939. "Terry richardson adipisicing actually typewriter tumblr, twee whatever\n"
  44940. "four loko you probably haven't heard of them high life. Messenger bag\n"
  44941. "whatever tattooed deep v mlkshk. Brooklyn pinterest assumenda chillwave\n"
  44942. "et, banksy ullamco messenger bag umami pariatur direct trade forage.\n"
  44943. "Typewriter culpa try-hard, pariatur sint brooklyn meggings. Gentrify\n"
  44944. "food truck next level, tousled irony non semiotics PBR ethical anim cred\n"
  44945. "readymade. Mumblecore brunch lomo odd future, portland organic terry\n"
  44946. "richardson elit leggings adipisicing ennui raw denim banjo hella. Godard\n"
  44947. "mixtape polaroid, pork belly readymade organic cray typewriter helvetica\n"
  44948. "four loko whatever street art yr farm-to-table.\n"
  44949. "\n"
  44950. "Vinyl keytar vice tofu. Locavore you probably haven't heard of them pug\n"
  44951. "pickled, hella tonx labore truffaut DIY mlkshk elit cosby sweater sint\n"
  44952. "et mumblecore. Elit swag semiotics, reprehenderit DIY sartorial nisi ugh\n"
  44953. "nesciunt pug pork belly wayfarers selfies delectus. Ethical hoodie\n"
  44954. "seitan fingerstache kale chips. Terry richardson artisan williamsburg,\n"
  44955. "eiusmod fanny pack irony tonx ennui lo-fi incididunt tofu YOLO\n"
  44956. "readymade. 8-bit sed ethnic beard officia. Pour-over iphone DIY butcher,\n"
  44957. "ethnic art party qui letterpress nisi proident jean shorts mlkshk\n"
  44958. "locavore.\n"
  44959. "\n"
  44960. "Narwhal flexitarian letterpress, do gluten-free voluptate next level\n"
  44961. "banh mi tonx incididunt carles DIY. Odd future nulla 8-bit beard ut\n"
  44962. "cillum pickled velit, YOLO officia you probably haven't heard of them\n"
  44963. "trust fund gastropub. Nisi adipisicing tattooed, Austin mlkshk 90's\n"
  44964. "small batch american apparel. Put a bird on it cosby sweater before they\n"
  44965. "sold out pork belly kogi hella. Street art mollit sustainable polaroid,\n"
  44966. "DIY ethnic ea pug beard dreamcatcher cosby sweater magna scenester nisi.\n"
  44967. "Sed pork belly skateboard mollit, labore proident eiusmod. Sriracha\n"
  44968. "excepteur cosby sweater, anim deserunt laborum eu aliquip ethical et\n"
  44969. "neutra PBR selvage.\n"
  44970. "\n"
  44971. "Raw denim pork belly truffaut, irony plaid sustainable put a bird on it\n"
  44972. "next level jean shorts exercitation. Hashtag keytar whatever, nihil\n"
  44973. "authentic aliquip disrupt laborum. Tattooed selfies deserunt trust fund\n"
  44974. "wayfarers. 3 wolf moon synth church-key sartorial, gastropub leggings\n"
  44975. "tattooed. Labore high life commodo, meggings raw denim fingerstache pug\n"
  44976. "trust fund leggings seitan forage. Nostrud ullamco duis, reprehenderit\n"
  44977. "incididunt flannel sustainable helvetica pork belly pug banksy you\n"
  44978. "probably haven't heard of them nesciunt farm-to-table. Disrupt nostrud\n"
  44979. "mollit magna, sriracha sartorial helvetica.\n"
  44980. "\n"
  44981. "Nulla kogi reprehenderit, skateboard sustainable duis adipisicing viral\n"
  44982. "ad fanny pack salvia. Fanny pack trust fund you probably haven't heard\n"
  44983. "of them YOLO vice nihil. Keffiyeh cray lo-fi pinterest cardigan aliqua,\n"
  44984. "reprehenderit aute. Culpa tousled williamsburg, marfa lomo actually anim\n"
  44985. "skateboard. Iphone aliqua ugh, semiotics pariatur vero readymade\n"
  44986. "organic. Marfa squid nulla, in laborum disrupt laboris irure gastropub.\n"
  44987. "Veniam sunt food truck leggings, sint vinyl fap.\n"
  44988. "\n"
  44989. "Hella dolore pork belly, truffaut carles you probably haven't heard of\n"
  44990. "them PBR helvetica in sapiente. Fashion axe ugh bushwick american\n"
  44991. "apparel. Fingerstache sed iphone, jean shorts blue bottle nisi bushwick\n"
  44992. "flexitarian officia veniam plaid bespoke fap YOLO lo-fi. Blog\n"
  44993. "letterpress mumblecore, food truck id cray brooklyn cillum ad sed.\n"
  44994. "Assumenda chambray wayfarers vinyl mixtape sustainable. VHS vinyl\n"
  44995. "delectus, culpa williamsburg polaroid cliche swag church-key synth kogi\n"
  44996. "magna pop-up literally. Swag thundercats ennui shoreditch vegan\n"
  44997. "pitchfork neutra truffaut etsy, sed single-origin coffee craft beer.\n"
  44998. "\n"
  44999. "Odio letterpress brooklyn elit. Nulla single-origin coffee in occaecat\n"
  45000. "meggings. Irony meggings 8-bit, chillwave lo-fi adipisicing cred\n"
  45001. "dreamcatcher veniam. Put a bird on it irony umami, trust fund bushwick\n"
  45002. "locavore kale chips. Sriracha swag thundercats, chillwave disrupt\n"
  45003. "tousled beard mollit mustache leggings portland next level. Nihil esse\n"
  45004. "est, skateboard art party etsy thundercats sed dreamcatcher ut iphone\n"
  45005. "swag consectetur et. Irure skateboard banjo, nulla deserunt messenger\n"
  45006. "bag dolor terry richardson sapiente.\n";
  45007. static const byte sample_text_gz[] = {
  45008. 0x1F, 0x8B, 0x08, 0x08, 0xC5, 0x49, 0xB5, 0x5B, 0x00, 0x03, 0x63, 0x69, 0x70,
  45009. 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x8D,
  45010. 0x58, 0xCB, 0x92, 0xE4, 0xB6, 0x11, 0xBC, 0xE3, 0x2B, 0xEA, 0xA6, 0x83, 0xD9,
  45011. 0x1D, 0x72, 0xF8, 0x22, 0x1F, 0xB5, 0x96, 0xA5, 0xDD, 0x90, 0xBC, 0xAB, 0xD0,
  45012. 0x28, 0x36, 0x42, 0x47, 0x90, 0x2C, 0x36, 0xA1, 0x06, 0x09, 0x0A, 0x8F, 0xEE,
  45013. 0xE1, 0xDF, 0x3B, 0x0B, 0xE0, 0x73, 0x2C, 0x4B, 0xBA, 0xCD, 0xCE, 0x80, 0x78,
  45014. 0x64, 0x65, 0x65, 0x66, 0xED, 0x3B, 0xE3, 0x5A, 0xC3, 0x81, 0x2D, 0x35, 0x69,
  45015. 0x32, 0xAD, 0x8E, 0x3A, 0xD2, 0xA0, 0x7D, 0xA7, 0x2B, 0x6A, 0xAC, 0x69, 0x7A,
  45016. 0x26, 0x9D, 0x22, 0xD3, 0x94, 0x22, 0x69, 0xAA, 0x8D, 0x6F, 0xC9, 0x8D, 0x64,
  45017. 0x22, 0x99, 0xB1, 0x31, 0xAD, 0x69, 0xD3, 0x18, 0x89, 0xAD, 0x89, 0x6A, 0x72,
  45018. 0x56, 0x7B, 0x67, 0xDA, 0x2B, 0xBD, 0xC8, 0xEF, 0xB0, 0x4D, 0x74, 0x8E, 0x5B,
  45019. 0xAA, 0x39, 0x4C, 0xEE, 0xCE, 0xE4, 0x79, 0xF2, 0xDC, 0xF3, 0xD8, 0xB2, 0x37,
  45020. 0x11, 0x8B, 0x8C, 0x2C, 0x7A, 0x32, 0x93, 0xF3, 0x37, 0x3D, 0x9A, 0x86, 0x4C,
  45021. 0xAB, 0xF2, 0xB9, 0x57, 0xFA, 0x97, 0x1B, 0x06, 0xD7, 0x3A, 0x7A, 0xF0, 0x68,
  45022. 0xF4, 0x40, 0xBA, 0x25, 0x0E, 0x81, 0xE9, 0xA6, 0x43, 0xF4, 0x6E, 0x4A, 0xF5,
  45023. 0x95, 0xFE, 0x41, 0x4F, 0x67, 0x3B, 0x1A, 0x1C, 0xEE, 0x12, 0xB4, 0x8F, 0xCE,
  45024. 0x1B, 0x6D, 0xB1, 0xDE, 0xBB, 0x4A, 0x4D, 0x56, 0x9B, 0x96, 0x5A, 0xB6, 0xDC,
  45025. 0xC4, 0x14, 0x70, 0xE5, 0xF5, 0x7D, 0xE1, 0xB7, 0x84, 0x3F, 0xFC, 0xED, 0xEF,
  45026. 0xF4, 0x30, 0x0D, 0x5F, 0xE9, 0x47, 0x17, 0xE2, 0xC5, 0x78, 0x27, 0x67, 0xDF,
  45027. 0xB9, 0xEB, 0xCC, 0xCC, 0x3D, 0x59, 0xBE, 0xDD, 0xCC, 0x78, 0x0B, 0x0A, 0x1F,
  45028. 0x74, 0xF8, 0x8C, 0x1A, 0xAF, 0x67, 0xEA, 0xF4, 0x44, 0xBD, 0x93, 0x7D, 0x2A,
  45029. 0xEA, 0x9C, 0xD7, 0x37, 0x80, 0x32, 0x9A, 0x01, 0x37, 0xD5, 0xDE, 0xCA, 0xA2,
  45030. 0x0D, 0xB9, 0xD0, 0x3B, 0xCF, 0xAD, 0x89, 0x4D, 0x5F, 0xD1, 0xE7, 0xF7, 0x2F,
  45031. 0x2A, 0x0C, 0xDA, 0x5A, 0xAA, 0x35, 0x7E, 0x41, 0xC3, 0xB2, 0x37, 0xDD, 0xDD,
  45032. 0xCD, 0x50, 0xEB, 0x2C, 0x96, 0x62, 0x3B, 0xD7, 0x52, 0xF4, 0xA9, 0xB9, 0x6F,
  45033. 0x48, 0xED, 0xEF, 0x54, 0xEA, 0x67, 0xF6, 0x7E, 0x26, 0x8F, 0x3A, 0x68, 0xDF,
  45034. 0x06, 0xBC, 0x56, 0xB7, 0x66, 0x32, 0xC1, 0x34, 0xD8, 0x88, 0x34, 0x1E, 0x88,
  45035. 0xED, 0x67, 0x8A, 0xF3, 0xC4, 0x4F, 0xC0, 0xCA, 0x9E, 0x62, 0x1A, 0x6A, 0xEB,
  45036. 0xAB, 0x02, 0xED, 0xB3, 0xD7, 0x91, 0x81, 0x8A, 0xEA, 0x5C, 0xF2, 0x64, 0xDD,
  45037. 0xDD, 0xD1, 0xEC, 0x12, 0x4D, 0xDE, 0xD5, 0xBA, 0xC6, 0x77, 0xBD, 0x06, 0xC4,
  45038. 0x5F, 0x44, 0xEA, 0x59, 0x4B, 0x5D, 0x3B, 0x8A, 0x3D, 0x0F, 0xD4, 0x9B, 0x1B,
  45039. 0x80, 0x30, 0x1D, 0x30, 0xFA, 0x8F, 0x00, 0x3F, 0xDE, 0xB0, 0x6F, 0xAD, 0x6F,
  45040. 0x6A, 0xDD, 0x6E, 0x2F, 0x6E, 0xCB, 0x3C, 0xD1, 0x83, 0x06, 0x7B, 0x0F, 0xFD,
  45041. 0xFD, 0x4A, 0xEF, 0xBC, 0x73, 0x77, 0x3B, 0x8F, 0x34, 0xA1, 0xBA, 0xEC, 0x39,
  45042. 0x80, 0x33, 0x21, 0xA4, 0x01, 0x55, 0xD7, 0xD4, 0xF4, 0xC6, 0xDA, 0x27, 0x4E,
  45043. 0x54, 0x1C, 0x2B, 0xEC, 0x37, 0xDE, 0xC3, 0x4C, 0xC9, 0x5A, 0x3D, 0x34, 0x0E,
  45044. 0xD8, 0x1C, 0x0E, 0xA2, 0x34, 0xE8, 0xC1, 0xD0, 0xA4, 0x51, 0xD5, 0x88, 0x8B,
  45045. 0xB7, 0xC6, 0xA3, 0x96, 0x40, 0x49, 0xB7, 0xBC, 0xE0, 0x7F, 0x55, 0x3F, 0xEF,
  45046. 0x6F, 0x6E, 0x92, 0x9D, 0x34, 0xFE, 0x3C, 0x5F, 0x04, 0xA5, 0x6A, 0xFF, 0x30,
  45047. 0x08, 0xC9, 0xEA, 0xF5, 0x52, 0x2B, 0xFE, 0x57, 0xFA, 0x8E, 0xC7, 0xE8, 0x4D,
  45048. 0x37, 0xAB, 0x03, 0xFA, 0x23, 0xBF, 0x46, 0x94, 0xFF, 0xC1, 0x16, 0xE0, 0xB9,
  45049. 0x14, 0x2C, 0x9E, 0x27, 0xEC, 0x98, 0x69, 0x14, 0x92, 0xF1, 0x60, 0x5C, 0x34,
  45050. 0x4D, 0xA0, 0x1F, 0xDF, 0xFD, 0x44, 0x1C, 0x7B, 0xD3, 0x80, 0x70, 0x42, 0x02,
  45051. 0x30, 0x84, 0x5B, 0xE5, 0x59, 0xB7, 0xF3, 0x80, 0xFB, 0x01, 0x33, 0xA9, 0x00,
  45052. 0x37, 0x52, 0xDC, 0xDA, 0xA7, 0x11, 0x85, 0xB7, 0x6E, 0x70, 0xE4, 0xDA, 0x96,
  45053. 0xBA, 0x84, 0x5B, 0x81, 0x43, 0x93, 0xF3, 0xD1, 0xEA, 0xB1, 0xDD, 0xB8, 0x1F,
  45054. 0xA5, 0xCC, 0xEA, 0x50, 0x66, 0x69, 0xA9, 0x8D, 0x8C, 0xA7, 0xA2, 0xF3, 0x38,
  45055. 0x26, 0x43, 0x5E, 0x3F, 0x01, 0xBE, 0x1C, 0x0F, 0x20, 0x7F, 0x75, 0xA8, 0x20,
  45056. 0x80, 0xC4, 0xC3, 0x5C, 0x8B, 0x0D, 0xD4, 0x60, 0x5E, 0xA3, 0x9E, 0xD0, 0xB4,
  45057. 0x4B, 0x4F, 0xE6, 0x13, 0x85, 0x60, 0x42, 0x96, 0xED, 0xAA, 0xDB, 0xE9, 0x99,
  45058. 0xE3, 0x07, 0x0E, 0x61, 0xB3, 0x07, 0xE3, 0xB1, 0xFA, 0xC0, 0x9B, 0xAD, 0xF6,
  45059. 0xE0, 0x26, 0x33, 0xEA, 0xEA, 0x23, 0xCD, 0x1E, 0x9D, 0xE1, 0x87, 0x4B, 0x74,
  45060. 0x97, 0x08, 0x3E, 0xA1, 0x28, 0xEA, 0xB3, 0x19, 0x67, 0x8B, 0x76, 0x9A, 0xA3,
  45061. 0xF6, 0xB9, 0xCF, 0x80, 0x65, 0x97, 0xAE, 0xF4, 0x83, 0x6B, 0xF4, 0x43, 0x20,
  45062. 0xF9, 0x0B, 0xFC, 0x9B, 0xD2, 0x4D, 0x4D, 0xA6, 0xB9, 0xA3, 0x02, 0x55, 0x79,
  45063. 0x18, 0x36, 0x19, 0x5F, 0xC9, 0xEA, 0x5A, 0x76, 0x40, 0xB9, 0xBA, 0x0E, 0x9A,
  45064. 0x44, 0xDF, 0x7C, 0xF8, 0x65, 0x61, 0x5E, 0x81, 0xAB, 0x71, 0xA1, 0x9E, 0x29,
  45065. 0x3C, 0x59, 0xCB, 0x23, 0xA4, 0xF6, 0x60, 0x1A, 0x0D, 0x5B, 0x39, 0xAE, 0xF4,
  45066. 0x6F, 0x59, 0x16, 0x9E, 0x60, 0xD8, 0x56, 0xCF, 0xEA, 0x2C, 0x4C, 0x79, 0xD3,
  45067. 0x5D, 0x51, 0x46, 0xA0, 0x4E, 0xE9, 0xD6, 0xAB, 0x91, 0x43, 0x63, 0x44, 0xD7,
  45068. 0x70, 0xB9, 0x23, 0x98, 0x4F, 0x3D, 0x03, 0x02, 0xF6, 0x81, 0x56, 0xC1, 0x58,
  45069. 0x85, 0x07, 0xA7, 0x2D, 0x2C, 0x29, 0xCA, 0x01, 0x45, 0x31, 0x51, 0x8F, 0xD4,
  45070. 0x19, 0xA1, 0x79, 0x88, 0x5A, 0xA4, 0xF5, 0xAE, 0x2D, 0x4B, 0x63, 0x4C, 0x58,
  45071. 0xFE, 0xBF, 0xAD, 0xEE, 0xA3, 0x09, 0xF8, 0xE2, 0x89, 0xBE, 0x81, 0x0E, 0x86,
  45072. 0x3A, 0xF9, 0x5B, 0xA5, 0xD8, 0xA4, 0x00, 0x75, 0x04, 0xF2, 0x23, 0xB8, 0x39,
  45073. 0x69, 0x50, 0xB7, 0xD0, 0x34, 0x63, 0x54, 0xD8, 0x61, 0xDD, 0xA5, 0x33, 0x47,
  45074. 0x85, 0x96, 0x22, 0xD0, 0x2F, 0x9F, 0x7E, 0xF8, 0x74, 0x24, 0xEA, 0x57, 0x97,
  45075. 0x5A, 0xE0, 0x00, 0xCF, 0xC1, 0x67, 0xE1, 0x41, 0xBD, 0x94, 0xA1, 0x03, 0xD3,
  45076. 0xB4, 0x08, 0x64, 0xF2, 0x17, 0x27, 0x35, 0x37, 0x53, 0xEF, 0x46, 0xCE, 0xD8,
  45077. 0xD4, 0x09, 0x52, 0xC6, 0x1E, 0xF7, 0x28, 0xDF, 0x08, 0x0F, 0xD0, 0x6F, 0x71,
  45078. 0xA6, 0xDF, 0xE4, 0x60, 0x8E, 0xC0, 0x1E, 0x78, 0x86, 0x50, 0xB0, 0x9B, 0x84,
  45079. 0x7E, 0xE8, 0x36, 0xFA, 0x95, 0xF1, 0x12, 0x51, 0xC7, 0x18, 0x96, 0xA2, 0x29,
  45080. 0xBB, 0x70, 0x02, 0xB4, 0xF9, 0xA8, 0x3D, 0x08, 0x66, 0xA9, 0xB3, 0xFC, 0x0A,
  45081. 0x94, 0x80, 0xFD, 0x78, 0xDC, 0xAB, 0x82, 0x5A, 0xD2, 0xCD, 0xC2, 0x87, 0xC6,
  45082. 0x4B, 0x07, 0xFA, 0xD1, 0xC3, 0xD9, 0x34, 0x41, 0x85, 0xF8, 0xD0, 0xB6, 0x0A,
  45083. 0x9D, 0x00, 0x91, 0x35, 0x05, 0x88, 0xC3, 0xE3, 0x9B, 0x22, 0xD2, 0xB8, 0xFD,
  45084. 0x95, 0x3E, 0x6D, 0x5D, 0x48, 0xA3, 0x68, 0xCF, 0x02, 0x42, 0x79, 0x79, 0x8A,
  45085. 0xAA, 0x01, 0xD6, 0x09, 0x14, 0x2C, 0xF4, 0x83, 0xA3, 0x80, 0x31, 0x55, 0x46,
  45086. 0x6E, 0xC5, 0xE5, 0x2F, 0x30, 0x58, 0x81, 0xA2, 0x90, 0xBE, 0x2E, 0xA1, 0xC3,
  45087. 0x0F, 0xA6, 0xF5, 0x51, 0x00, 0x39, 0xB6, 0xF2, 0x2A, 0xA3, 0x15, 0x7D, 0x8D,
  45088. 0xF5, 0x66, 0x5C, 0xD9, 0xFC, 0xCF, 0x2F, 0xBF, 0x08, 0x27, 0xE7, 0xD0, 0x03,
  45089. 0xB8, 0xD9, 0x00, 0x13, 0x3D, 0x01, 0x6B, 0xB6, 0xA8, 0xCD, 0x5B, 0x3B, 0x3E,
  45090. 0x93, 0xBF, 0xE6, 0x2E, 0xB7, 0x4A, 0xCF, 0xB3, 0x0A, 0xCE, 0x62, 0x11, 0xD6,
  45091. 0x1F, 0x68, 0x9B, 0x1D, 0x68, 0xD1, 0x8C, 0x97, 0xBD, 0xA1, 0x07, 0x67, 0x73,
  45092. 0x87, 0xE0, 0x36, 0xDA, 0x8C, 0xD2, 0xD2, 0xBB, 0x84, 0x28, 0xA9, 0xFE, 0x52,
  45093. 0x74, 0xD6, 0xB9, 0x0F, 0x0A, 0x6A, 0x2D, 0x28, 0x35, 0x34, 0x3A, 0xD3, 0xE2,
  45094. 0xCD, 0x35, 0x06, 0x7D, 0x1B, 0x35, 0x85, 0x86, 0xD1, 0x3E, 0xF2, 0x6F, 0xA1,
  45095. 0xC4, 0x55, 0xBD, 0x00, 0xD8, 0xC3, 0x5D, 0xC2, 0x1D, 0x6B, 0x6B, 0x27, 0x5B,
  45096. 0x95, 0xF3, 0xAB, 0xB5, 0xD3, 0x37, 0xF2, 0x2C, 0x9C, 0xC7, 0x5D, 0xBD, 0xF1,
  45097. 0x68, 0x1C, 0xAD, 0xF8, 0xB5, 0xE1, 0x29, 0x72, 0x7A, 0x73, 0x62, 0x55, 0x24,
  45098. 0xB9, 0x85, 0xDF, 0x7B, 0x29, 0x7D, 0xDE, 0x08, 0xF5, 0xE4, 0x44, 0xDA, 0x1A,
  45099. 0x30, 0x74, 0xDA, 0xB4, 0x9B, 0x23, 0x9A, 0x3A, 0xC1, 0x53, 0xB2, 0xA2, 0xA3,
  45100. 0x7B, 0x1F, 0xD9, 0x56, 0xD4, 0x4F, 0x9B, 0xB2, 0x1E, 0xEE, 0xB8, 0x6A, 0x4E,
  45101. 0xB5, 0xF4, 0x5A, 0xC9, 0x18, 0x27, 0x9C, 0xDE, 0x14, 0x44, 0xED, 0xC4, 0x3C,
  45102. 0x71, 0x9F, 0x5F, 0xD9, 0x37, 0xA0, 0x78, 0x34, 0x6E, 0xBC, 0xD2, 0x7B, 0x1D,
  45103. 0xFA, 0x08, 0x39, 0x5A, 0x04, 0x73, 0x15, 0xD9, 0x0A, 0x48, 0xC1, 0x2D, 0x15,
  45104. 0x4E, 0x84, 0x30, 0x45, 0x69, 0xB3, 0xE5, 0xF6, 0xAD, 0x09, 0x1E, 0xCC, 0x5F,
  45105. 0x1F, 0x06, 0xD5, 0x58, 0xAD, 0x78, 0xD7, 0x9F, 0xE5, 0xED, 0x3B, 0x09, 0xD5,
  45106. 0xA6, 0x52, 0x6F, 0x92, 0xD3, 0x3C, 0xC6, 0x1E, 0xF2, 0x93, 0x7C, 0xD3, 0x5F,
  45107. 0x70, 0x85, 0x5D, 0xF8, 0xAA, 0x9D, 0xB7, 0x7B, 0x24, 0x5A, 0xE9, 0x0A, 0x35,
  45108. 0x2F, 0xF5, 0xD9, 0x82, 0x02, 0x8A, 0x90, 0x13, 0x5B, 0xB5, 0x67, 0x9C, 0xDD,
  45109. 0xA0, 0x4E, 0x82, 0x27, 0xDA, 0x7E, 0xE8, 0x8E, 0xCD, 0xE1, 0x56, 0x71, 0x2C,
  45110. 0xE6, 0x4E, 0x1F, 0x91, 0xCD, 0x7C, 0x6A, 0xB7, 0x78, 0xD0, 0x26, 0xF3, 0x56,
  45111. 0xA9, 0xD5, 0xA1, 0xC3, 0x3B, 0x98, 0xE9, 0x28, 0x09, 0xEF, 0x50, 0x90, 0xCD,
  45112. 0xC4, 0x8E, 0x75, 0xCC, 0xAC, 0x2D, 0xC9, 0x03, 0x6D, 0xAC, 0xFE, 0xC4, 0x88,
  45113. 0x36, 0xD1, 0x3F, 0xBB, 0x1C, 0x7D, 0xB3, 0x14, 0x61, 0x2C, 0xB7, 0x54, 0x4B,
  45114. 0xDB, 0x64, 0xB6, 0x57, 0x14, 0x16, 0x8E, 0x1E, 0x6C, 0x64, 0xBB, 0x8B, 0x48,
  45115. 0x5D, 0x96, 0x9D, 0xDC, 0x80, 0xA7, 0xF7, 0x54, 0xC7, 0x46, 0x38, 0x3E, 0x44,
  45116. 0xDE, 0x7E, 0x92, 0x8D, 0x07, 0xF6, 0x07, 0x37, 0x4E, 0x16, 0x10, 0xB4, 0x7D,
  45117. 0x88, 0x66, 0x7F, 0xBB, 0xFF, 0xEA, 0x00, 0xF3, 0xFF, 0x97, 0x2C, 0xB5, 0xBE,
  45118. 0x35, 0x4B, 0x5C, 0x36, 0xEC, 0x4C, 0xBD, 0x2B, 0x7D, 0xBF, 0x46, 0xE2, 0x9C,
  45119. 0x0E, 0x8A, 0xA3, 0xEC, 0xB1, 0x0E, 0x9A, 0xDA, 0x9A, 0x9B, 0x28, 0x92, 0x10,
  45120. 0x53, 0x57, 0xEA, 0xEC, 0xA2, 0x32, 0x32, 0x20, 0x1D, 0x97, 0x5C, 0xB6, 0x84,
  45121. 0xA9, 0x93, 0x8D, 0x95, 0x11, 0xA3, 0x24, 0xA3, 0x2D, 0xC6, 0x4A, 0xEF, 0xAA,
  45122. 0x1D, 0x85, 0x2B, 0x7D, 0x28, 0xBE, 0x53, 0xCE, 0x10, 0x1F, 0xAE, 0x0E, 0x41,
  45123. 0x6C, 0x4B, 0x79, 0x12, 0xFB, 0xF7, 0x54, 0xA3, 0x96, 0x54, 0x83, 0x20, 0x96,
  45124. 0x8F, 0x28, 0xA9, 0x3F, 0x8B, 0x3D, 0xBA, 0x77, 0xDC, 0x24, 0xE1, 0xD4, 0x49,
  45125. 0x40, 0xD8, 0x78, 0x31, 0x85, 0x43, 0xF6, 0xFE, 0x5C, 0xA6, 0x8F, 0x90, 0x09,
  45126. 0xB0, 0xE7, 0xC4, 0x95, 0xB2, 0x55, 0x49, 0x97, 0x8F, 0x1C, 0x78, 0x30, 0x20,
  45127. 0xA0, 0xB4, 0xEF, 0x73, 0x56, 0x59, 0x82, 0xFD, 0xCE, 0xBA, 0x6A, 0x8F, 0x2C,
  45128. 0x8B, 0x15, 0xFD, 0xA1, 0x85, 0xA8, 0x5C, 0x0F, 0x11, 0xA5, 0x9D, 0xC2, 0x46,
  45129. 0xC6, 0x9C, 0xC9, 0x40, 0x0B, 0x58, 0x6A, 0x1C, 0x7A, 0x23, 0xF9, 0xE0, 0x95,
  45130. 0x05, 0x13, 0x58, 0x72, 0xE8, 0x9F, 0x30, 0xAC, 0xCD, 0x26, 0xD4, 0x66, 0x13,
  45131. 0xDF, 0x1E, 0x7B, 0x4F, 0x9C, 0xBE, 0x38, 0x79, 0x75, 0x92, 0xA4, 0xDA, 0x26,
  45132. 0x44, 0x55, 0x17, 0xA3, 0xE5, 0x62, 0xDA, 0xEB, 0x86, 0xEA, 0x68, 0xC7, 0xAB,
  45133. 0xFD, 0x2D, 0x43, 0x59, 0x51, 0xC0, 0x75, 0x64, 0x91, 0x01, 0x29, 0x33, 0x28,
  45134. 0xF3, 0x04, 0x83, 0x80, 0x75, 0x37, 0x75, 0x0C, 0x03, 0x7B, 0x0A, 0xAB, 0x8E,
  45135. 0x60, 0x62, 0x8B, 0x4C, 0xAF, 0x2D, 0xA3, 0x2F, 0xFE, 0xAB, 0x45, 0xCF, 0xDA,
  45136. 0xAB, 0xFA, 0xFA, 0x30, 0x3D, 0xE8, 0xA1, 0x96, 0xA5, 0x7B, 0xE2, 0x2A, 0xD0,
  45137. 0xAF, 0x59, 0xF7, 0xD0, 0x32, 0x57, 0x19, 0xBD, 0xCA, 0x9F, 0xD5, 0x1A, 0xC7,
  45138. 0xAA, 0x65, 0x4A, 0x38, 0xB2, 0x70, 0x33, 0xB7, 0x75, 0xD2, 0xCD, 0xD1, 0xF0,
  45139. 0xA8, 0x87, 0x59, 0x20, 0xA5, 0x57, 0x55, 0xB1, 0xB2, 0xC9, 0x4D, 0x97, 0x34,
  45140. 0x41, 0xF3, 0xF0, 0x30, 0xA1, 0x2C, 0x1C, 0x49, 0x3E, 0x89, 0x7D, 0x12, 0xE2,
  45141. 0xC3, 0x04, 0xC3, 0x92, 0xC0, 0xF6, 0x39, 0x10, 0x80, 0x81, 0x8F, 0x08, 0xB4,
  45142. 0xF8, 0xB9, 0x13, 0x4E, 0x2C, 0xAE, 0xB3, 0x71, 0x82, 0x63, 0x98, 0xAB, 0x5C,
  45143. 0x1C, 0x10, 0xEA, 0x66, 0xF9, 0x02, 0x3A, 0x82, 0x61, 0xD0, 0xD4, 0xAE, 0x43,
  45144. 0xD4, 0x01, 0x3E, 0x9D, 0x04, 0x14, 0xF6, 0x60, 0xD8, 0xA7, 0xD6, 0xB8, 0x53,
  45145. 0xC8, 0xDA, 0x80, 0x93, 0xA0, 0x02, 0xDD, 0xCC, 0xE2, 0xF2, 0xBB, 0xFB, 0xE0,
  45146. 0x27, 0xD7, 0x34, 0x9A, 0x71, 0x49, 0xB5, 0x4F, 0x42, 0x1F, 0xB2, 0x9D, 0x6D,
  45147. 0xAA, 0x9D, 0xD3, 0x50, 0xB5, 0x8F, 0x6A, 0x4B, 0xDF, 0x1F, 0xD5, 0x27, 0x8F,
  45148. 0x3B, 0x27, 0xCF, 0x2F, 0x8C, 0xF8, 0x9D, 0x4C, 0x52, 0xBC, 0x32, 0x0F, 0x73,
  45149. 0xD5, 0x51, 0x8E, 0x36, 0x7E, 0xAD, 0x09, 0xF0, 0x94, 0x83, 0x5F, 0x36, 0xFD,
  45150. 0x7C, 0x03, 0xED, 0xF1, 0x5E, 0x4B, 0xF7, 0xAA, 0x55, 0x5C, 0x4A, 0x14, 0x59,
  45151. 0x85, 0x38, 0x2D, 0x8C, 0xDF, 0xEC, 0x65, 0x1B, 0xB8, 0x76, 0x57, 0x96, 0x3C,
  45152. 0x86, 0xED, 0xF2, 0x7F, 0x2D, 0x28, 0x48, 0xDA, 0x49, 0x7F, 0xF7, 0x54, 0x2B,
  45153. 0xD5, 0x39, 0xD5, 0x57, 0x0A, 0x75, 0x7A, 0x3E, 0x5E, 0x5D, 0xBA, 0x4A, 0x15,
  45154. 0xFA, 0xB8, 0x31, 0x80, 0x71, 0x2C, 0xCA, 0xC4, 0x51, 0x10, 0x16, 0x5D, 0x39,
  45155. 0xEC, 0x9D, 0x07, 0xB6, 0x6A, 0x89, 0x9F, 0x9B, 0x5B, 0x6F, 0x03, 0xB0, 0x92,
  45156. 0x01, 0x38, 0x6B, 0x48, 0x99, 0x0A, 0x8F, 0x13, 0xC1, 0xA6, 0x01, 0xEA, 0xBF,
  45157. 0x6F, 0x86, 0x43, 0x51, 0xB6, 0x11, 0x00, 0x00
  45158. };
  45159. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void)
  45160. {
  45161. wc_test_ret_t ret = 0;
  45162. word32 dSz = sizeof(sample_text);
  45163. word32 cSz = (dSz + (word32)(dSz * 0.001) + 12);
  45164. byte *c;
  45165. byte *d;
  45166. WOLFSSL_ENTER("compress_test");
  45167. c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45168. d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45169. if (c == NULL || d == NULL) {
  45170. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  45171. }
  45172. /* follow calloc and initialize to 0 */
  45173. XMEMSET(c, 0, cSz);
  45174. XMEMSET(d, 0, dSz);
  45175. if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) {
  45176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45177. }
  45178. cSz = (word32)ret;
  45179. if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) {
  45180. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45181. }
  45182. dSz = (word32)ret;
  45183. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45184. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45185. }
  45186. /* GZIP tests */
  45187. cSz = (dSz + (word32)(dSz * 0.001) + 12); /* reset cSz */
  45188. XMEMSET(c, 0, cSz);
  45189. XMEMSET(d, 0, dSz);
  45190. ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP);
  45191. if (ret < 0)
  45192. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45193. cSz = (word32)ret;
  45194. ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP);
  45195. if (ret < 0)
  45196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45197. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45198. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45199. }
  45200. /* Try with gzip generated output */
  45201. XMEMSET(d, 0, dSz);
  45202. ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz),
  45203. LIBZ_WINBITS_GZIP);
  45204. if (ret < 0)
  45205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45206. dSz = (word32)ret;
  45207. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45208. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45209. }
  45210. ret = 0; /* success */
  45211. exit:
  45212. XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45213. XFREE(d, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45214. return ret;
  45215. }
  45216. #endif /* HAVE_LIBZ */
  45217. #ifdef HAVE_PKCS7
  45218. /* External Debugging/Testing Note:
  45219. *
  45220. * PKCS#7 test functions can output generated PKCS#7/CMS bundles for
  45221. * additional testing. To dump bundles to files DER encoded files, please
  45222. * define:
  45223. *
  45224. * #define PKCS7_OUTPUT_TEST_BUNDLES
  45225. */
  45226. /* Loads certs and keys for use with PKCS7 tests, from either files
  45227. * or buffers.
  45228. *
  45229. * rsaClientCertBuf - output buffer for RSA client cert
  45230. * rsaClientCertBufSz - IN/OUT size of output buffer, size of RSA client cert
  45231. * rsaClientPrivKeyBuf - output buffer for RSA client private key
  45232. * rsaClientPrivKeyBufSz - IN/OUT size of output buffer, size of RSA client key
  45233. *
  45234. * rsaServerCertBuf - output buffer for RSA server cert
  45235. * rsaServerCertBufSz - IN/OUT size of output buffer, size of RSA server cert
  45236. * rsaServerPrivKeyBuf - output buffer for RSA server private key
  45237. * rsaServerPrivKeyBufSz - IN/OUT size of output buffer, size of RSA server key
  45238. *
  45239. * rsaCaCertBuf - output buffer for RSA CA cert
  45240. * rsaCaCertBufSz - IN/OUT size of output buffer, size of RSA ca cert
  45241. * rsaCaPrivKeyBuf - output buffer for RSA CA private key
  45242. * rsaCaPrivKeyBufSz - IN/OUT size of output buffer, size of RSA CA key
  45243. *
  45244. * eccClientCertBuf - output buffer for ECC cert
  45245. * eccClientCertBufSz - IN/OUT size of output buffer, size of ECC cert
  45246. * eccClientPrivKeyBuf - output buffer for ECC private key
  45247. * eccClientPrivKeyBufSz - IN/OUT size of output buffer, size of ECC private key
  45248. *
  45249. * Returns 0 on success, negative on error
  45250. */
  45251. static wc_test_ret_t pkcs7_load_certs_keys(
  45252. byte* rsaClientCertBuf, word32* rsaClientCertBufSz,
  45253. byte* rsaClientPrivKeyBuf, word32* rsaClientPrivKeyBufSz,
  45254. byte* rsaServerCertBuf, word32* rsaServerCertBufSz,
  45255. byte* rsaServerPrivKeyBuf, word32* rsaServerPrivKeyBufSz,
  45256. byte* rsaCaCertBuf, word32* rsaCaCertBufSz,
  45257. byte* rsaCaPrivKeyBuf, word32* rsaCaPrivKeyBufSz,
  45258. byte* eccClientCertBuf, word32* eccClientCertBufSz,
  45259. byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz)
  45260. {
  45261. #ifndef NO_FILESYSTEM
  45262. XFILE certFile;
  45263. XFILE keyFile;
  45264. (void)certFile;
  45265. (void)keyFile;
  45266. #endif
  45267. #ifndef NO_RSA
  45268. if (rsaClientCertBuf == NULL || rsaClientCertBufSz == NULL ||
  45269. rsaClientPrivKeyBuf == NULL || rsaClientPrivKeyBufSz == NULL)
  45270. return BAD_FUNC_ARG;
  45271. #endif
  45272. #ifdef HAVE_ECC
  45273. if (eccClientCertBuf == NULL || eccClientCertBufSz == NULL ||
  45274. eccClientPrivKeyBuf == NULL || eccClientPrivKeyBufSz == NULL)
  45275. return BAD_FUNC_ARG;
  45276. #endif
  45277. /* RSA */
  45278. #ifndef NO_RSA
  45279. #ifdef USE_CERT_BUFFERS_1024
  45280. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024)
  45281. return WC_TEST_RET_ENC_NC;
  45282. XMEMCPY(rsaClientCertBuf, client_cert_der_1024,
  45283. sizeof_client_cert_der_1024);
  45284. *rsaClientCertBufSz = sizeof_client_cert_der_1024;
  45285. if (rsaServerCertBuf != NULL) {
  45286. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024)
  45287. return WC_TEST_RET_ENC_NC;
  45288. XMEMCPY(rsaServerCertBuf, server_cert_der_1024,
  45289. sizeof_server_cert_der_1024);
  45290. *rsaServerCertBufSz = sizeof_server_cert_der_1024;
  45291. }
  45292. if (rsaCaCertBuf != NULL) {
  45293. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024)
  45294. return WC_TEST_RET_ENC_NC;
  45295. XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  45296. *rsaCaCertBufSz = sizeof_ca_cert_der_1024;
  45297. }
  45298. #elif defined(USE_CERT_BUFFERS_2048)
  45299. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048)
  45300. return WC_TEST_RET_ENC_NC;
  45301. XMEMCPY(rsaClientCertBuf, client_cert_der_2048,
  45302. sizeof_client_cert_der_2048);
  45303. *rsaClientCertBufSz = sizeof_client_cert_der_2048;
  45304. if (rsaServerCertBuf != NULL) {
  45305. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048)
  45306. return WC_TEST_RET_ENC_NC;
  45307. XMEMCPY(rsaServerCertBuf, server_cert_der_2048,
  45308. sizeof_server_cert_der_2048);
  45309. *rsaServerCertBufSz = sizeof_server_cert_der_2048;
  45310. }
  45311. if (rsaCaCertBuf != NULL) {
  45312. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048)
  45313. return WC_TEST_RET_ENC_NC;
  45314. XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  45315. *rsaCaCertBufSz = sizeof_ca_cert_der_2048;
  45316. }
  45317. #else
  45318. certFile = XFOPEN(clientCert, "rb");
  45319. if (!certFile)
  45320. return WC_TEST_RET_ENC_ERRNO;
  45321. *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1,
  45322. *rsaClientCertBufSz, certFile);
  45323. XFCLOSE(certFile);
  45324. if (*rsaClientCertBufSz == 0)
  45325. return WC_TEST_RET_ENC_ERRNO;
  45326. if (rsaServerCertBuf != NULL) {
  45327. certFile = XFOPEN(rsaServerCertDerFile, "rb");
  45328. if (!certFile)
  45329. return WC_TEST_RET_ENC_ERRNO;
  45330. *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1,
  45331. *rsaServerCertBufSz, certFile);
  45332. XFCLOSE(certFile);
  45333. if (*rsaServerCertBufSz == 0)
  45334. return WC_TEST_RET_ENC_ERRNO;
  45335. }
  45336. if (rsaCaCertBuf != NULL) {
  45337. certFile = XFOPEN(rsaCaCertDerFile, "rb");
  45338. if (!certFile)
  45339. return WC_TEST_RET_ENC_ERRNO;
  45340. *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz,
  45341. certFile);
  45342. XFCLOSE(certFile);
  45343. if (*rsaCaCertBufSz == 0)
  45344. return WC_TEST_RET_ENC_ERRNO;
  45345. }
  45346. #endif
  45347. #ifdef USE_CERT_BUFFERS_1024
  45348. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024)
  45349. return WC_TEST_RET_ENC_NC;
  45350. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024,
  45351. sizeof_client_key_der_1024);
  45352. *rsaClientPrivKeyBufSz = sizeof_client_key_der_1024;
  45353. if (rsaServerPrivKeyBuf != NULL) {
  45354. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024)
  45355. return WC_TEST_RET_ENC_NC;
  45356. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024,
  45357. sizeof_server_key_der_1024);
  45358. *rsaServerPrivKeyBufSz = sizeof_server_key_der_1024;
  45359. }
  45360. if (rsaCaPrivKeyBuf != NULL) {
  45361. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024)
  45362. return WC_TEST_RET_ENC_NC;
  45363. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024);
  45364. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024;
  45365. }
  45366. #elif defined(USE_CERT_BUFFERS_2048)
  45367. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048)
  45368. return WC_TEST_RET_ENC_NC;
  45369. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048,
  45370. sizeof_client_key_der_2048);
  45371. *rsaClientPrivKeyBufSz = sizeof_client_key_der_2048;
  45372. if (rsaServerPrivKeyBuf != NULL) {
  45373. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048)
  45374. return WC_TEST_RET_ENC_NC;
  45375. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048,
  45376. sizeof_server_key_der_2048);
  45377. *rsaServerPrivKeyBufSz = sizeof_server_key_der_2048;
  45378. }
  45379. if (rsaCaPrivKeyBuf != NULL) {
  45380. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048)
  45381. return WC_TEST_RET_ENC_NC;
  45382. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048);
  45383. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048;
  45384. }
  45385. #else
  45386. keyFile = XFOPEN(clientKey, "rb");
  45387. if (!keyFile)
  45388. return WC_TEST_RET_ENC_ERRNO;
  45389. *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1,
  45390. *rsaClientPrivKeyBufSz, keyFile);
  45391. XFCLOSE(keyFile);
  45392. if (*rsaClientPrivKeyBufSz == 0)
  45393. return WC_TEST_RET_ENC_ERRNO;
  45394. if (rsaServerPrivKeyBuf != NULL) {
  45395. keyFile = XFOPEN(rsaServerKeyDerFile, "rb");
  45396. if (!keyFile)
  45397. return WC_TEST_RET_ENC_ERRNO;
  45398. *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1,
  45399. *rsaServerPrivKeyBufSz, keyFile);
  45400. XFCLOSE(keyFile);
  45401. if (*rsaServerPrivKeyBufSz == 0)
  45402. return WC_TEST_RET_ENC_ERRNO;
  45403. }
  45404. if (rsaCaPrivKeyBuf != NULL) {
  45405. keyFile = XFOPEN(rsaCaKeyFile, "rb");
  45406. if (!keyFile)
  45407. return WC_TEST_RET_ENC_ERRNO;
  45408. *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1,
  45409. *rsaCaPrivKeyBufSz, keyFile);
  45410. XFCLOSE(keyFile);
  45411. if (*rsaCaPrivKeyBufSz == 0)
  45412. return WC_TEST_RET_ENC_ERRNO;
  45413. }
  45414. #endif /* USE_CERT_BUFFERS */
  45415. #endif /* NO_RSA */
  45416. /* ECC */
  45417. #ifdef HAVE_ECC
  45418. #ifdef USE_CERT_BUFFERS_256
  45419. if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256)
  45420. return WC_TEST_RET_ENC_NC;
  45421. XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45422. *eccClientCertBufSz = sizeof_cliecc_cert_der_256;
  45423. #else
  45424. certFile = XFOPEN(eccClientCert, "rb");
  45425. if (!certFile)
  45426. return WC_TEST_RET_ENC_ERRNO;
  45427. *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1,
  45428. *eccClientCertBufSz, certFile);
  45429. XFCLOSE(certFile);
  45430. if (*eccClientCertBufSz == 0)
  45431. return WC_TEST_RET_ENC_ERRNO;
  45432. #endif /* USE_CERT_BUFFERS_256 */
  45433. #ifdef USE_CERT_BUFFERS_256
  45434. if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256)
  45435. return WC_TEST_RET_ENC_NC;
  45436. XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45437. *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256;
  45438. #else
  45439. keyFile = XFOPEN(eccClientKey, "rb");
  45440. if (!keyFile)
  45441. return WC_TEST_RET_ENC_ERRNO;
  45442. *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1,
  45443. *eccClientPrivKeyBufSz, keyFile);
  45444. XFCLOSE(keyFile);
  45445. if (*eccClientPrivKeyBufSz == 0)
  45446. return WC_TEST_RET_ENC_ERRNO;
  45447. #endif /* USE_CERT_BUFFERS_256 */
  45448. #endif /* HAVE_ECC */
  45449. #ifdef NO_RSA
  45450. (void)rsaClientCertBuf;
  45451. (void)rsaClientCertBufSz;
  45452. (void)rsaClientPrivKeyBuf;
  45453. (void)rsaClientPrivKeyBufSz;
  45454. (void)rsaServerCertBuf;
  45455. (void)rsaServerCertBufSz;
  45456. (void)rsaServerPrivKeyBuf;
  45457. (void)rsaServerPrivKeyBufSz;
  45458. (void)rsaCaCertBuf;
  45459. (void)rsaCaCertBufSz;
  45460. (void)rsaCaPrivKeyBuf;
  45461. (void)rsaCaPrivKeyBufSz;
  45462. #endif
  45463. #ifndef HAVE_ECC
  45464. (void)eccClientCertBuf;
  45465. (void)eccClientCertBufSz;
  45466. (void)eccClientPrivKeyBuf;
  45467. (void)eccClientPrivKeyBufSz;
  45468. #endif
  45469. #ifndef NO_FILESYSTEM
  45470. (void)certFile;
  45471. (void)keyFile;
  45472. #endif
  45473. return 0;
  45474. }
  45475. typedef struct {
  45476. const byte* content;
  45477. word32 contentSz;
  45478. int contentOID;
  45479. int encryptOID;
  45480. int keyWrapOID;
  45481. int keyAgreeOID;
  45482. byte* cert;
  45483. size_t certSz;
  45484. byte* privateKey;
  45485. word32 privateKeySz;
  45486. byte* optionalUkm;
  45487. word32 optionalUkmSz;
  45488. int ktriOptions; /* KTRI options flags */
  45489. int kariOptions; /* KARI options flags */
  45490. /* KEKRI specific */
  45491. const byte* secretKey; /* key, only for kekri RecipientInfo types */
  45492. word32 secretKeySz; /* size of secretKey, bytes */
  45493. const byte* secretKeyId; /* key identifier */
  45494. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45495. void* timePtr; /* time_t pointer */
  45496. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45497. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45498. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45499. word32 otherAttrSz; /* size of otherAttr, bytes */
  45500. int kekriOptions; /* KEKRI options flags */
  45501. /* PWRI specific */
  45502. const char* password;
  45503. word32 passwordSz;
  45504. const byte* salt;
  45505. word32 saltSz;
  45506. int kdfOID;
  45507. int hashOID;
  45508. int kdfIterations;
  45509. int pwriOptions; /* PWRI options flags */
  45510. /* ORI specific */
  45511. int isOri;
  45512. int oriOptions; /* ORI options flags */
  45513. const char* outFileName;
  45514. } pkcs7EnvelopedVector;
  45515. static const byte asnDataOid[] = {
  45516. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
  45517. };
  45518. /* ORI encrypt callback, responsible for encrypting content-encryption key (CEK)
  45519. * and giving wolfCrypt the value for oriOID and oriValue to place in
  45520. * OtherRecipientInfo.
  45521. *
  45522. * Returns 0 on success, negative upon error. */
  45523. static int myOriEncryptCb(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType,
  45524. word32* oriTypeSz, byte* oriValue, word32* oriValueSz,
  45525. void* ctx)
  45526. {
  45527. int i;
  45528. /* make sure buffers are large enough */
  45529. if (*oriValueSz < (2 + cekSz))
  45530. return WC_TEST_RET_ENC_NC;
  45531. if (*oriTypeSz < sizeof(asnDataOid))
  45532. return WC_TEST_RET_ENC_NC;
  45533. /* our simple encryption algorithm will be take the bitwise complement */
  45534. oriValue[0] = 0x04; /*ASN OCTET STRING */
  45535. oriValue[1] = (byte)cekSz; /* length */
  45536. for (i = 0; i < (int)cekSz; i++) {
  45537. oriValue[2 + i] = ~cek[i];
  45538. }
  45539. *oriValueSz = 2 + cekSz;
  45540. /* set oriType to ASN.1 encoded data OID */
  45541. XMEMCPY(oriType, asnDataOid, sizeof(asnDataOid));
  45542. *oriTypeSz = sizeof(asnDataOid);
  45543. (void)pkcs7;
  45544. (void)ctx;
  45545. return 0;
  45546. }
  45547. /* ORI decrypt callback, responsible for providing a decrypted content
  45548. * encryption key (CEK) placed into decryptedKey and size placed into
  45549. * decryptedKeySz. oriOID and oriValue are given to the callback to help
  45550. * in decrypting the encrypted CEK.
  45551. *
  45552. * Returns 0 on success, negative upon error. */
  45553. static int myOriDecryptCb(wc_PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  45554. byte* oriValue, word32 oriValueSz, byte* decryptedKey,
  45555. word32* decryptedKeySz, void* ctx)
  45556. {
  45557. int i;
  45558. /* make sure oriType matches what we expect */
  45559. if (oriTypeSz != sizeof(asnDataOid))
  45560. return WC_TEST_RET_ENC_NC;
  45561. if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0)
  45562. return WC_TEST_RET_ENC_NC;
  45563. /* make sure decrypted buffer is large enough */
  45564. if (*decryptedKeySz < oriValueSz)
  45565. return WC_TEST_RET_ENC_NC;
  45566. /* decrypt encrypted CEK using simple bitwise complement,
  45567. only for example */
  45568. for (i = 0; i < (int)oriValueSz - 2; i++) {
  45569. decryptedKey[i] = ~oriValue[2 + i];
  45570. }
  45571. *decryptedKeySz = oriValueSz - 2;
  45572. (void)pkcs7;
  45573. (void)ctx;
  45574. return 0;
  45575. }
  45576. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45577. /* returns 0 on success */
  45578. static int myDecryptionFunc(wc_PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45579. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45580. byte* in, int inSz, byte* out, void* usrCtx)
  45581. {
  45582. wc_test_ret_t ret;
  45583. int keyId = -1, keySz;
  45584. word32 keyIdSz = 8;
  45585. const byte* key;
  45586. byte keyIdRaw[8];
  45587. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45588. Aes *aes;
  45589. #else
  45590. Aes aes[1];
  45591. #endif
  45592. /* looking for KEY ID
  45593. * fwDecryptKeyID OID "1.2.840.113549.1.9.16.2.37
  45594. */
  45595. WOLFSSL_SMALL_STACK_STATIC const unsigned char OID[] = {
  45596. /* 0x06, 0x0B do not pass in tag and length */
  45597. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  45598. 0x01, 0x09, 0x10, 0x02, 0x25
  45599. };
  45600. WOLFSSL_SMALL_STACK_STATIC const byte defKey[] = {
  45601. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45602. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45603. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45604. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45605. };
  45606. WOLFSSL_SMALL_STACK_STATIC const byte altKey[] = {
  45607. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45608. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45609. };
  45610. /* test user context passed in */
  45611. if (usrCtx == NULL || *(int*)usrCtx != 1) {
  45612. return WC_TEST_RET_ENC_NC;
  45613. }
  45614. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45615. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  45616. return WC_TEST_RET_ENC_ERRNO;
  45617. #endif
  45618. /* if needing to find keyIdSz can call with NULL */
  45619. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), NULL,
  45620. &keyIdSz);
  45621. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  45622. printf("Unexpected error %d when getting keyIdSz\n", ret);
  45623. printf("Possibly no KEY ID attribute set\n");
  45624. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45625. }
  45626. else {
  45627. XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw));
  45628. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw,
  45629. &keyIdSz);
  45630. if (ret < 0) {
  45631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45632. }
  45633. if (keyIdSz < 3) {
  45634. printf("keyIdSz is smaller than expected\n");
  45635. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45636. }
  45637. if (keyIdSz > 2 + sizeof(int)) {
  45638. printf("example case was only expecting a keyId of int size\n");
  45639. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45640. }
  45641. /* keyIdRaw[0] OCTET TAG */
  45642. /* keyIdRaw[1] Length */
  45643. #ifdef BIG_ENDIAN_ORDER
  45644. if (keyIdRaw[1] == 0x01) {
  45645. keyId = 1;
  45646. }
  45647. #else
  45648. XMEMCPY(&keyId, keyIdRaw + 2, sizeof(keyId));
  45649. #endif
  45650. }
  45651. /* Use keyID here if found to select key and decrypt in HSM or in this
  45652. * example just select key and do software decryption */
  45653. if (keyId == 1) {
  45654. key = altKey;
  45655. keySz = sizeof(altKey);
  45656. }
  45657. else {
  45658. key = defKey;
  45659. keySz = sizeof(defKey);
  45660. }
  45661. switch (encryptOID) {
  45662. #ifdef WOLFSSL_AES_256
  45663. case AES256CBCb:
  45664. if ((keySz != 32 ) || (ivSz != AES_BLOCK_SIZE))
  45665. WARNING_OUT(BAD_FUNC_ARG, out);
  45666. break;
  45667. #endif
  45668. #ifdef WOLFSSL_AES_128
  45669. case AES128CBCb:
  45670. if ((keySz != 16 ) || (ivSz != AES_BLOCK_SIZE))
  45671. ERROR_OUT(BAD_FUNC_ARG, out);
  45672. break;
  45673. #endif
  45674. default:
  45675. printf("Unsupported content cipher type for example");
  45676. ERROR_OUT(ALGO_ID_E, out);
  45677. };
  45678. ret = wc_AesInit(aes, HEAP_HINT, INVALID_DEVID);
  45679. if (ret == 0) {
  45680. ret = wc_AesSetKey(aes, key, (word32)keySz, iv, AES_DECRYPTION);
  45681. if (ret == 0)
  45682. ret = wc_AesCbcDecrypt(aes, out, in, (word32)inSz);
  45683. wc_AesFree(aes);
  45684. }
  45685. out:
  45686. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45687. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45688. #endif
  45689. (void)aad;
  45690. (void)aadSz;
  45691. (void)authTag;
  45692. (void)authTagSz;
  45693. return (int)ret;
  45694. }
  45695. #endif /* !NO_AES && HAVE_AES_CBC */
  45696. #define PKCS7_BUF_SIZE 2048
  45697. static wc_test_ret_t pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  45698. byte* rsaPrivKey, word32 rsaPrivKeySz,
  45699. byte* eccCert, word32 eccCertSz,
  45700. byte* eccPrivKey, word32 eccPrivKeySz)
  45701. {
  45702. wc_test_ret_t ret = 0;
  45703. int testSz = 0, i;
  45704. int envelopedSz, decodedSz;
  45705. byte *enveloped = NULL;
  45706. byte *decoded = NULL;
  45707. wc_PKCS7* pkcs7 = NULL;
  45708. #ifdef ECC_TIMING_RESISTANT
  45709. WC_RNG rng;
  45710. #endif
  45711. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  45712. XFILE pkcs7File;
  45713. #endif
  45714. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  45715. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  45716. 0x72,0x6c,0x64
  45717. };
  45718. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256) && \
  45719. defined(HAVE_ECC) && defined(WOLFSSL_SHA512)
  45720. byte optionalUkm[] = {
  45721. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45722. };
  45723. #endif /* !NO_AES */
  45724. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  45725. !defined(NO_SHA)
  45726. /* encryption key for kekri recipient types */
  45727. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  45728. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  45729. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  45730. };
  45731. /* encryption key identifier */
  45732. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  45733. 0x02,0x02,0x03,0x04
  45734. };
  45735. #endif
  45736. #if !defined(NO_PWDBASED) && !defined(NO_SHA) && \
  45737. !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  45738. #ifndef HAVE_FIPS
  45739. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password"; /* NOTE: Password is too short for FIPS */
  45740. #else
  45741. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  45742. #endif
  45743. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  45744. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  45745. };
  45746. #endif
  45747. #define MAX_TESTVECTORS_LEN 13
  45748. #define ADD_PKCS7ENVELOPEDVECTOR(...) { \
  45749. pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \
  45750. if (testSz == MAX_TESTVECTORS_LEN) { \
  45751. ret = WC_TEST_RET_ENC_NC; \
  45752. goto out; \
  45753. } \
  45754. XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\
  45755. }
  45756. pkcs7EnvelopedVector *testVectors = NULL;
  45757. #ifdef ECC_TIMING_RESISTANT
  45758. XMEMSET(&rng, 0, sizeof(rng));
  45759. #endif
  45760. testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  45761. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45762. if (testVectors == NULL) {
  45763. ret = WC_TEST_RET_ENC_ERRNO;
  45764. goto out;
  45765. }
  45766. {
  45767. /* key transport key encryption technique */
  45768. #ifndef NO_RSA
  45769. #ifndef NO_DES3
  45770. ADD_PKCS7ENVELOPEDVECTOR(
  45771. data, (word32)sizeof(data), DATA, DES3b, 0, 0, rsaCert, rsaCertSz,
  45772. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45773. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45774. "pkcs7envelopedDataDES3.der");
  45775. #endif
  45776. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45777. #ifdef WOLFSSL_AES_128
  45778. ADD_PKCS7ENVELOPEDVECTOR(
  45779. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, rsaCert, rsaCertSz,
  45780. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45781. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45782. "pkcs7envelopedDataAES128CBC.der");
  45783. #endif
  45784. #ifdef WOLFSSL_AES_192
  45785. ADD_PKCS7ENVELOPEDVECTOR(
  45786. data, (word32)sizeof(data), DATA, AES192CBCb, 0, 0, rsaCert, rsaCertSz,
  45787. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45788. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45789. "pkcs7envelopedDataAES192CBC.der");
  45790. #endif
  45791. #ifdef WOLFSSL_AES_256
  45792. ADD_PKCS7ENVELOPEDVECTOR(
  45793. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45794. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  45795. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45796. "pkcs7envelopedDataAES256CBC.der");
  45797. /* explicitly using SKID for SubjectKeyIdentifier */
  45798. ADD_PKCS7ENVELOPEDVECTOR(
  45799. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45800. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_SKID, 0, NULL, 0, NULL, 0, NULL,
  45801. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45802. "pkcs7envelopedDataAES256CBC_SKID.der");
  45803. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  45804. ADD_PKCS7ENVELOPEDVECTOR(
  45805. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  45806. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_ISSUER_AND_SERIAL_NUMBER, 0,
  45807. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  45808. 0, 0, 0, 0, "pkcs7envelopedDataAES256CBC_IANDS.der");
  45809. #endif
  45810. #endif /* !NO_AES && HAVE_AES_CBC */
  45811. #endif
  45812. /* key agreement key encryption technique*/
  45813. #ifdef HAVE_ECC
  45814. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45815. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45816. ADD_PKCS7ENVELOPEDVECTOR(
  45817. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP,
  45818. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45819. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45820. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45821. "pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der");
  45822. #endif
  45823. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  45824. ADD_PKCS7ENVELOPEDVECTOR(
  45825. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45826. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45827. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45828. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45829. "pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der");
  45830. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  45831. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  45832. ADD_PKCS7ENVELOPEDVECTOR(
  45833. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45834. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45835. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  45836. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45837. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der");
  45838. /* with optional user keying material (ukm) */
  45839. ADD_PKCS7ENVELOPEDVECTOR(
  45840. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  45841. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  45842. eccPrivKeySz, optionalUkm, sizeof(optionalUkm), 0, 0, NULL, 0,
  45843. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45844. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF_ukm.der");
  45845. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  45846. #endif /* !NO_AES && HAVE_AES_CBC */
  45847. #endif
  45848. /* kekri (KEKRecipientInfo) recipient types */
  45849. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45850. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45851. ADD_PKCS7ENVELOPEDVECTOR(
  45852. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP, 0,
  45853. NULL, 0, NULL, 0, NULL, 0, 0, 0, secretKey, sizeof(secretKey),
  45854. secretKeyId, sizeof(secretKeyId), NULL, NULL, 0, NULL, 0,
  45855. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  45856. "pkcs7envelopedDataAES128CBC_KEKRI.der");
  45857. #endif
  45858. #endif /* !NO_AES && HAVE_AES_CBC */
  45859. /* pwri (PasswordRecipientInfo) recipient types */
  45860. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  45861. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  45862. ADD_PKCS7ENVELOPEDVECTOR(
  45863. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0,
  45864. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  45865. NULL, 0, NULL, NULL, 0, NULL, 0, 0, password,
  45866. (word32)XSTRLEN(password), salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  45867. 0, 0, 0, "pkcs7envelopedDataAES128CBC_PWRI.der");
  45868. #endif
  45869. #endif
  45870. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_128)
  45871. /* ori (OtherRecipientInfo) recipient types */
  45872. ADD_PKCS7ENVELOPEDVECTOR(
  45873. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, NULL, 0, NULL, 0,
  45874. NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0,
  45875. NULL, 0, 0, 0, 0, 0, 1, 0, "pkcs7envelopedDataAES128CBC_ORI.der");
  45876. #endif
  45877. };
  45878. #undef MAX_TESTVECTORS_LEN
  45879. #undef ADD_PKCS7ENVELOPEDVECTOR
  45880. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45881. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45882. if ((! enveloped) || (! decoded)) {
  45883. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  45884. }
  45885. #ifdef ECC_TIMING_RESISTANT
  45886. #ifndef HAVE_FIPS
  45887. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  45888. #else
  45889. ret = wc_InitRng(&rng);
  45890. #endif
  45891. if (ret != 0)
  45892. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45893. #endif
  45894. for (i = 0; i < testSz; i++) {
  45895. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  45896. #ifdef WOLFSSL_ASYNC_CRYPT
  45897. INVALID_DEVID /* async PKCS7 is not supported */
  45898. #else
  45899. devId
  45900. #endif
  45901. );
  45902. if (pkcs7 == NULL) {
  45903. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  45904. }
  45905. if (testVectors[i].secretKey != NULL) {
  45906. /* KEKRI recipient type */
  45907. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45908. if (ret != 0)
  45909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45910. pkcs7->content = (byte*)testVectors[i].content;
  45911. pkcs7->contentSz = testVectors[i].contentSz;
  45912. pkcs7->contentOID = testVectors[i].contentOID;
  45913. pkcs7->encryptOID = testVectors[i].encryptOID;
  45914. pkcs7->ukm = testVectors[i].optionalUkm;
  45915. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45916. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  45917. (byte *)testVectors[i].secretKey, testVectors[i].secretKeySz,
  45918. (byte *)testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  45919. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  45920. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  45921. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  45922. if (ret < 0) {
  45923. wc_PKCS7_Free(pkcs7);
  45924. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45925. }
  45926. /* set key, for decryption */
  45927. ret = wc_PKCS7_SetKey(pkcs7, (byte *)testVectors[i].secretKey,
  45928. testVectors[i].secretKeySz);
  45929. if (ret != 0) {
  45930. wc_PKCS7_Free(pkcs7);
  45931. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45932. }
  45933. } else if (testVectors[i].password != NULL) {
  45934. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  45935. /* PWRI recipient type */
  45936. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45937. if (ret != 0)
  45938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45939. pkcs7->content = (byte*)testVectors[i].content;
  45940. pkcs7->contentSz = testVectors[i].contentSz;
  45941. pkcs7->contentOID = testVectors[i].contentOID;
  45942. pkcs7->encryptOID = testVectors[i].encryptOID;
  45943. pkcs7->ukm = testVectors[i].optionalUkm;
  45944. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  45945. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  45946. (byte *)testVectors[i].password, testVectors[i].passwordSz,
  45947. (byte *)testVectors[i].salt, testVectors[i].saltSz,
  45948. testVectors[i].kdfOID,
  45949. testVectors[i].hashOID, testVectors[i].kdfIterations,
  45950. testVectors[i].encryptOID, testVectors[i].pwriOptions);
  45951. if (ret < 0) {
  45952. wc_PKCS7_Free(pkcs7);
  45953. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45954. }
  45955. /* set password, for decryption */
  45956. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  45957. testVectors[i].passwordSz);
  45958. if (ret < 0) {
  45959. wc_PKCS7_Free(pkcs7);
  45960. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45961. }
  45962. #endif /* ! NO_PWDBASED && ! NO_SHA */
  45963. } else if (testVectors[i].isOri == 1) {
  45964. /* ORI recipient type */
  45965. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45966. if (ret != 0)
  45967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45968. pkcs7->content = (byte*)testVectors[i].content;
  45969. pkcs7->contentSz = testVectors[i].contentSz;
  45970. pkcs7->contentOID = testVectors[i].contentOID;
  45971. pkcs7->encryptOID = testVectors[i].encryptOID;
  45972. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  45973. testVectors[i].oriOptions);
  45974. if (ret < 0) {
  45975. wc_PKCS7_Free(pkcs7);
  45976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45977. }
  45978. /* set decrypt callback for decryption */
  45979. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  45980. if (ret < 0) {
  45981. wc_PKCS7_Free(pkcs7);
  45982. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45983. }
  45984. } else {
  45985. /* KTRI or KARI recipient types */
  45986. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  45987. if (ret != 0)
  45988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45989. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  45990. (word32)testVectors[i].certSz);
  45991. if (ret != 0) {
  45992. wc_PKCS7_Free(pkcs7);
  45993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45994. }
  45995. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  45996. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  45997. pkcs7->privateKey = testVectors[i].privateKey;
  45998. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  45999. pkcs7->content = (byte*)testVectors[i].content;
  46000. pkcs7->contentSz = testVectors[i].contentSz;
  46001. pkcs7->contentOID = testVectors[i].contentOID;
  46002. pkcs7->encryptOID = testVectors[i].encryptOID;
  46003. pkcs7->ukm = testVectors[i].optionalUkm;
  46004. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46005. /* set SubjectIdentifier type for KTRI types */
  46006. if (testVectors[i].ktriOptions & CMS_SKID) {
  46007. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46008. if (ret != 0) {
  46009. wc_PKCS7_Free(pkcs7);
  46010. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46011. }
  46012. } else if (testVectors[i].ktriOptions &
  46013. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46014. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46015. CMS_ISSUER_AND_SERIAL_NUMBER);
  46016. if (ret != 0) {
  46017. wc_PKCS7_Free(pkcs7);
  46018. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46019. }
  46020. }
  46021. }
  46022. #ifdef ECC_TIMING_RESISTANT
  46023. pkcs7->rng = &rng;
  46024. #endif
  46025. /* encode envelopedData */
  46026. envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, enveloped,
  46027. PKCS7_BUF_SIZE);
  46028. if (envelopedSz <= 0) {
  46029. wc_PKCS7_Free(pkcs7);
  46030. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46031. }
  46032. /* decode envelopedData */
  46033. pkcs7->contentOID = 0;
  46034. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, (word32)envelopedSz,
  46035. decoded, PKCS7_BUF_SIZE);
  46036. if (pkcs7->contentOID != testVectors[i].contentOID ||
  46037. decodedSz <= 0) {
  46038. wc_PKCS7_Free(pkcs7);
  46039. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46040. }
  46041. /* test decode result */
  46042. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46043. wc_PKCS7_Free(pkcs7);
  46044. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46045. }
  46046. #ifndef NO_PKCS7_STREAM
  46047. { /* test reading byte by byte */
  46048. int z;
  46049. for (z = 0; z < envelopedSz; z++) {
  46050. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped + z, 1,
  46051. decoded, PKCS7_BUF_SIZE);
  46052. if (decodedSz <= 0 &&
  46053. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46054. {
  46055. printf("unexpected error %d\n", decodedSz);
  46056. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46057. }
  46058. }
  46059. /* test decode result */
  46060. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46061. printf("stream read compare failed\n");
  46062. wc_PKCS7_Free(pkcs7);
  46063. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46064. }
  46065. }
  46066. #endif
  46067. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46068. /* output pkcs7 envelopedData for external testing */
  46069. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46070. if (!pkcs7File) {
  46071. wc_PKCS7_Free(pkcs7);
  46072. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46073. }
  46074. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46075. XFCLOSE(pkcs7File);
  46076. if (ret != envelopedSz) {
  46077. wc_PKCS7_Free(pkcs7);
  46078. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46079. } else {
  46080. /* reset ret to 0 for success */
  46081. ret = 0;
  46082. }
  46083. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46084. wc_PKCS7_Free(pkcs7);
  46085. pkcs7 = NULL;
  46086. }
  46087. #ifdef ECC_TIMING_RESISTANT
  46088. wc_FreeRng(&rng);
  46089. #endif
  46090. (void)eccCert;
  46091. (void)eccCertSz;
  46092. (void)eccPrivKey;
  46093. (void)eccPrivKeySz;
  46094. (void)rsaCert;
  46095. (void)rsaCertSz;
  46096. (void)rsaPrivKey;
  46097. (void)rsaPrivKeySz;
  46098. out:
  46099. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46100. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46101. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46102. return ret;
  46103. }
  46104. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void)
  46105. {
  46106. wc_test_ret_t ret = 0;
  46107. byte* rsaCert = NULL;
  46108. byte* rsaPrivKey = NULL;
  46109. word32 rsaCertSz = 0;
  46110. word32 rsaPrivKeySz = 0;
  46111. byte* eccCert = NULL;
  46112. byte* eccPrivKey = NULL;
  46113. word32 eccCertSz = 0;
  46114. word32 eccPrivKeySz = 0;
  46115. WOLFSSL_ENTER("pkcs7enveloped_test");
  46116. #ifndef NO_RSA
  46117. /* read client RSA cert and key in DER format */
  46118. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46119. if (rsaCert == NULL)
  46120. return WC_TEST_RET_ENC_ERRNO;
  46121. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46122. if (rsaPrivKey == NULL) {
  46123. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46124. return WC_TEST_RET_ENC_NC;
  46125. }
  46126. rsaCertSz = FOURK_BUF;
  46127. rsaPrivKeySz = FOURK_BUF;
  46128. #endif /* NO_RSA */
  46129. #ifdef HAVE_ECC
  46130. /* read client ECC cert and key in DER format */
  46131. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46132. if (eccCert == NULL) {
  46133. #ifndef NO_RSA
  46134. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46135. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46136. #endif
  46137. return WC_TEST_RET_ENC_NC;
  46138. }
  46139. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46140. if (eccPrivKey == NULL) {
  46141. #ifndef NO_RSA
  46142. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46143. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46144. #endif
  46145. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46146. return WC_TEST_RET_ENC_NC;
  46147. }
  46148. eccCertSz = FOURK_BUF;
  46149. eccPrivKeySz = FOURK_BUF;
  46150. #endif /* HAVE_ECC */
  46151. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46152. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46153. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46154. eccPrivKey, &eccPrivKeySz);
  46155. if (ret < 0) {
  46156. #ifndef NO_RSA
  46157. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46158. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46159. #endif
  46160. #ifdef HAVE_ECC
  46161. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46162. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46163. #endif
  46164. return WC_TEST_RET_ENC_EC(ret);
  46165. }
  46166. ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46167. rsaPrivKey, (word32)rsaPrivKeySz,
  46168. eccCert, (word32)eccCertSz,
  46169. eccPrivKey, (word32)eccPrivKeySz);
  46170. #ifndef NO_RSA
  46171. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46172. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46173. #endif
  46174. #ifdef HAVE_ECC
  46175. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46176. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46177. #endif
  46178. return ret;
  46179. }
  46180. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  46181. typedef struct {
  46182. const byte* content;
  46183. word32 contentSz;
  46184. int contentOID;
  46185. int encryptOID;
  46186. int keyWrapOID;
  46187. int keyAgreeOID;
  46188. byte* cert;
  46189. size_t certSz;
  46190. byte* privateKey;
  46191. word32 privateKeySz;
  46192. PKCS7Attrib* authAttribs;
  46193. word32 authAttribsSz;
  46194. PKCS7Attrib* unauthAttribs;
  46195. word32 unauthAttribsSz;
  46196. /* KARI / KTRI specific */
  46197. byte* optionalUkm;
  46198. word32 optionalUkmSz;
  46199. int ktriOptions; /* KTRI options flags */
  46200. int kariOptions; /* KARI options flags */
  46201. /* KEKRI specific */
  46202. byte* secretKey; /* key, only for kekri RecipientInfo types */
  46203. word32 secretKeySz; /* size of secretKey, bytes */
  46204. byte* secretKeyId; /* key identifier */
  46205. word32 secretKeyIdSz; /* size of key identifier, bytes */
  46206. void* timePtr; /* time_t pointer */
  46207. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  46208. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  46209. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  46210. word32 otherAttrSz; /* size of otherAttr, bytes */
  46211. int kekriOptions; /* KEKRI options flags */
  46212. /* PWRI specific */
  46213. char* password; /* password */
  46214. word32 passwordSz; /* password size, bytes */
  46215. byte* salt; /* KDF salt */
  46216. word32 saltSz; /* KDF salt size, bytes */
  46217. int kdfOID; /* KDF OID */
  46218. int hashOID; /* KDF hash algorithm OID */
  46219. int kdfIterations; /* KDF iterations */
  46220. int kekEncryptOID; /* KEK encryption algorithm OID */
  46221. int pwriOptions; /* PWRI options flags */
  46222. /* ORI specific */
  46223. int isOri;
  46224. int oriOptions; /* ORI options flags */
  46225. const char* outFileName;
  46226. } pkcs7AuthEnvelopedVector;
  46227. static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46228. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46229. byte* eccCert, word32 eccCertSz,
  46230. byte* eccPrivKey, word32 eccPrivKeySz)
  46231. {
  46232. wc_test_ret_t ret = 0;
  46233. int testSz = 0, i;
  46234. int envelopedSz, decodedSz;
  46235. byte *enveloped = NULL;
  46236. byte *decoded = NULL;
  46237. WC_RNG rng;
  46238. wc_PKCS7* pkcs7;
  46239. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46240. XFILE pkcs7File;
  46241. #endif
  46242. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46243. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46244. 0x72,0x6c,0x64
  46245. };
  46246. byte senderNonce[PKCS7_NONCE_SZ + 2];
  46247. #ifdef HAVE_ECC
  46248. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46249. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46250. WOLFSSL_SMALL_STACK_STATIC const byte senderNonceOid[] =
  46251. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  46252. 0x09, 0x05 };
  46253. PKCS7Attrib attribs[] =
  46254. {
  46255. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  46256. sizeof(senderNonce) }
  46257. };
  46258. #endif
  46259. #endif
  46260. #endif
  46261. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \
  46262. defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM)
  46263. WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = {
  46264. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46265. };
  46266. #endif /* !NO_AES */
  46267. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46268. /* encryption key for kekri recipient types */
  46269. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46270. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46271. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46272. };
  46273. /* encryption key identifier */
  46274. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46275. 0x02,0x02,0x03,0x04
  46276. };
  46277. #endif
  46278. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  46279. !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46280. #ifndef HAVE_FIPS
  46281. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password";
  46282. #else
  46283. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46284. #endif
  46285. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46286. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46287. };
  46288. #endif
  46289. #define MAX_TESTVECTORS_LEN 20
  46290. #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \
  46291. pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46292. if (testSz == MAX_TESTVECTORS_LEN) { \
  46293. ret = WC_TEST_RET_ENC_NC; \
  46294. goto out; \
  46295. } \
  46296. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  46297. sizeof _this_vector); \
  46298. }
  46299. pkcs7AuthEnvelopedVector *testVectors = NULL;
  46300. XMEMSET(&rng, 0, sizeof(rng));
  46301. testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46302. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46303. if (testVectors == NULL) {
  46304. ret = WC_TEST_RET_ENC_ERRNO;
  46305. goto out;
  46306. }
  46307. {
  46308. /* key transport key encryption technique */
  46309. #ifndef NO_RSA
  46310. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46311. #ifdef WOLFSSL_AES_128
  46312. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46313. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, rsaCert, rsaCertSz,
  46314. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46315. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46316. 0, 0, "pkcs7authEnvelopedDataAES128GCM.der");
  46317. #endif
  46318. #ifdef WOLFSSL_AES_192
  46319. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46320. data, (word32)sizeof(data), DATA, AES192GCMb, 0, 0, rsaCert, rsaCertSz,
  46321. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46322. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46323. 0, 0, "pkcs7authEnvelopedDataAES192GCM.der");
  46324. #endif
  46325. #ifdef WOLFSSL_AES_256
  46326. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46327. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46328. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46329. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46330. 0, 0, "pkcs7authEnvelopedDataAES256GCM.der");
  46331. /* test with contentType set to FirmwarePkgData */
  46332. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46333. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, 0, 0,
  46334. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL,
  46335. 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL,
  46336. 0, 0, 0, 0, 0, 0, 0, 0,
  46337. "pkcs7authEnvelopedDataAES256GCM_firmwarePkgData.der");
  46338. /* explicitly using SKID for SubjectKeyIdentifier */
  46339. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46340. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46341. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, CMS_SKID, 0,
  46342. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46343. 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_SKID.der");
  46344. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46345. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46346. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46347. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0,
  46348. CMS_ISSUER_AND_SERIAL_NUMBER, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46349. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46350. "pkcs7authEnvelopedDataAES256GCM_IANDS.der");
  46351. #endif
  46352. #else
  46353. (void)rsaCert;
  46354. (void)rsaCertSz;
  46355. (void)rsaPrivKey;
  46356. (void)rsaPrivKeySz;
  46357. #endif /* !NO_AES && !HAVE_AESGCM */
  46358. #endif
  46359. /* key agreement key encryption technique*/
  46360. #ifdef HAVE_ECC
  46361. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46362. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46363. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46364. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP,
  46365. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46366. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46367. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46368. "pkcs7authEnvelopedDataAES128GCM_ECDH_SHA1KDF.der");
  46369. #endif
  46370. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46371. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46372. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46373. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46374. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46375. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46376. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF.der");
  46377. /* with authenticated attributes */
  46378. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46379. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46380. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46381. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46382. NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46383. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46384. 0, 0, 0,
  46385. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_authAttribs.der");
  46386. /* with unauthenticated attributes */
  46387. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46388. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46389. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46390. eccPrivKeySz, NULL, 0, attribs,
  46391. (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0, NULL, 0,
  46392. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46393. 0, 0, 0,
  46394. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_unauthAttribs.der");
  46395. /* with authenticated AND unauthenticated attributes */
  46396. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46397. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46398. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46399. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46400. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46401. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46402. 0, 0, 0, 0, 0, 0,
  46403. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_bothAttribs.der");
  46404. /* with authenticated AND unauthenticated attributes AND
  46405. * contentType of FirmwarePkgData */
  46406. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46407. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, AES256_WRAP,
  46408. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46409. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46410. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46411. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46412. 0, 0, 0, 0, 0, 0,
  46413. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_fw_bothAttribs.der");
  46414. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46415. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46416. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46417. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46418. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46419. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL,
  46420. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46421. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF.der");
  46422. /* with optional user keying material (ukm) */
  46423. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46424. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46425. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46426. eccPrivKeySz, NULL, 0, NULL, 0, (byte *)optionalUkm, sizeof(optionalUkm), 0,
  46427. 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46428. 0, 0, 0, 0, 0, 0,
  46429. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF_ukm.der");
  46430. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46431. #endif /* !NO_AES && HAVE_AESGCM */
  46432. #endif
  46433. /* kekri (KEKRecipientInfo) recipient types */
  46434. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46435. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46436. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46437. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP, 0,
  46438. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0,
  46439. (byte *)secretKey, sizeof(secretKey), (byte *)secretKeyId, sizeof(secretKeyId),
  46440. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46441. "pkcs7authEnvelopedDataAES128GCM_KEKRI.der");
  46442. #endif
  46443. #endif
  46444. /* pwri (PasswordRecipientInfo) recipient types */
  46445. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM)
  46446. #if !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46447. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46448. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0,
  46449. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46450. NULL, 0, NULL, NULL, 0, NULL, 0, 0, (char *)password,
  46451. (word32)XSTRLEN(password), (byte *)salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46452. AES128CBCb, 0, 0, 0, "pkcs7authEnvelopedDataAES128GCM_PWRI.der");
  46453. #endif
  46454. #endif
  46455. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46456. #ifdef WOLFSSL_AES_128
  46457. /* ori (OtherRecipientInfo) recipient types */
  46458. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46459. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, NULL, 0, NULL, 0,
  46460. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46461. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0,
  46462. "pkcs7authEnvelopedDataAES128GCM_ORI.der");
  46463. #endif
  46464. #endif
  46465. }
  46466. #undef MAX_TESTVECTORS_LEN
  46467. #undef ADD_PKCS7AUTHENVELOPEDVECTOR
  46468. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46469. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46470. if ((! enveloped) || (! decoded)) {
  46471. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46472. }
  46473. /* generate senderNonce */
  46474. {
  46475. #ifndef HAVE_FIPS
  46476. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46477. #else
  46478. ret = wc_InitRng(&rng);
  46479. #endif
  46480. if (ret != 0)
  46481. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46482. senderNonce[0] = 0x04;
  46483. senderNonce[1] = PKCS7_NONCE_SZ;
  46484. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  46485. if (ret != 0) {
  46486. wc_FreeRng(&rng);
  46487. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46488. }
  46489. }
  46490. for (i = 0; i < testSz; i++) {
  46491. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46492. #ifdef WOLFSSL_ASYNC_CRYPT
  46493. INVALID_DEVID /* async PKCS7 is not supported */
  46494. #else
  46495. devId
  46496. #endif
  46497. );
  46498. if (pkcs7 == NULL) {
  46499. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46500. }
  46501. if (testVectors[i].secretKey != NULL) {
  46502. /* KEKRI recipient type */
  46503. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46504. if (ret != 0)
  46505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46506. pkcs7->content = (byte*)testVectors[i].content;
  46507. pkcs7->contentSz = testVectors[i].contentSz;
  46508. pkcs7->contentOID = testVectors[i].contentOID;
  46509. pkcs7->encryptOID = testVectors[i].encryptOID;
  46510. pkcs7->ukm = testVectors[i].optionalUkm;
  46511. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46512. pkcs7->authAttribs = testVectors[i].authAttribs;
  46513. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46514. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46515. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46516. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46517. testVectors[i].secretKey, testVectors[i].secretKeySz,
  46518. testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46519. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46520. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46521. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46522. if (ret < 0) {
  46523. wc_PKCS7_Free(pkcs7);
  46524. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46525. }
  46526. /* set key, for decryption */
  46527. ret = wc_PKCS7_SetKey(pkcs7, testVectors[i].secretKey,
  46528. testVectors[i].secretKeySz);
  46529. if (ret != 0) {
  46530. wc_PKCS7_Free(pkcs7);
  46531. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46532. }
  46533. } else if (testVectors[i].password != NULL) {
  46534. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46535. /* PWRI recipient type */
  46536. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46537. if (ret != 0)
  46538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46539. pkcs7->content = (byte*)testVectors[i].content;
  46540. pkcs7->contentSz = testVectors[i].contentSz;
  46541. pkcs7->contentOID = testVectors[i].contentOID;
  46542. pkcs7->encryptOID = testVectors[i].encryptOID;
  46543. pkcs7->ukm = testVectors[i].optionalUkm;
  46544. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46545. pkcs7->authAttribs = testVectors[i].authAttribs;
  46546. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46547. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46548. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46549. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46550. (byte*)testVectors[i].password,
  46551. testVectors[i].passwordSz, testVectors[i].salt,
  46552. testVectors[i].saltSz, testVectors[i].kdfOID,
  46553. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46554. testVectors[i].kekEncryptOID, testVectors[i].pwriOptions);
  46555. if (ret < 0) {
  46556. wc_PKCS7_Free(pkcs7);
  46557. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46558. }
  46559. /* set password, for decryption */
  46560. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46561. testVectors[i].passwordSz);
  46562. if (ret < 0) {
  46563. wc_PKCS7_Free(pkcs7);
  46564. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46565. }
  46566. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46567. } else if (testVectors[i].isOri == 1) {
  46568. /* ORI recipient type */
  46569. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46570. if (ret != 0)
  46571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46572. pkcs7->content = (byte*)testVectors[i].content;
  46573. pkcs7->contentSz = testVectors[i].contentSz;
  46574. pkcs7->contentOID = testVectors[i].contentOID;
  46575. pkcs7->encryptOID = testVectors[i].encryptOID;
  46576. pkcs7->authAttribs = testVectors[i].authAttribs;
  46577. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46578. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46579. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46580. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46581. testVectors[i].oriOptions);
  46582. if (ret < 0) {
  46583. wc_PKCS7_Free(pkcs7);
  46584. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46585. }
  46586. /* set decrypt callback for decryption */
  46587. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46588. if (ret < 0) {
  46589. wc_PKCS7_Free(pkcs7);
  46590. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46591. }
  46592. } else {
  46593. /* KTRI or KARI recipient types */
  46594. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46595. (word32)testVectors[i].certSz);
  46596. if (ret != 0) {
  46597. wc_PKCS7_Free(pkcs7);
  46598. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46599. }
  46600. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46601. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46602. pkcs7->privateKey = testVectors[i].privateKey;
  46603. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46604. pkcs7->content = (byte*)testVectors[i].content;
  46605. pkcs7->contentSz = testVectors[i].contentSz;
  46606. pkcs7->contentOID = testVectors[i].contentOID;
  46607. pkcs7->encryptOID = testVectors[i].encryptOID;
  46608. pkcs7->ukm = testVectors[i].optionalUkm;
  46609. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46610. pkcs7->authAttribs = testVectors[i].authAttribs;
  46611. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46612. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46613. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46614. /* set SubjectIdentifier type for KTRI types */
  46615. if (testVectors[i].ktriOptions & CMS_SKID) {
  46616. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46617. if (ret != 0) {
  46618. wc_PKCS7_Free(pkcs7);
  46619. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46620. }
  46621. } else if (testVectors[i].ktriOptions &
  46622. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46623. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46624. CMS_ISSUER_AND_SERIAL_NUMBER);
  46625. if (ret != 0) {
  46626. wc_PKCS7_Free(pkcs7);
  46627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46628. }
  46629. }
  46630. }
  46631. #ifdef ECC_TIMING_RESISTANT
  46632. pkcs7->rng = &rng;
  46633. #endif
  46634. /* encode envelopedData */
  46635. envelopedSz = wc_PKCS7_EncodeAuthEnvelopedData(pkcs7, enveloped,
  46636. PKCS7_BUF_SIZE);
  46637. if (envelopedSz <= 0) {
  46638. wc_PKCS7_Free(pkcs7);
  46639. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46640. }
  46641. #ifndef NO_PKCS7_STREAM
  46642. { /* test reading byte by byte */
  46643. int z;
  46644. for (z = 0; z < envelopedSz; z++) {
  46645. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7,
  46646. enveloped + z, 1, decoded, PKCS7_BUF_SIZE);
  46647. if (decodedSz <= 0 &&
  46648. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46649. {
  46650. printf("unexpected error %d\n", decodedSz);
  46651. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46652. }
  46653. }
  46654. /* test decode result */
  46655. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46656. printf("stream read compare failed\n");
  46657. wc_PKCS7_Free(pkcs7);
  46658. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46659. }
  46660. }
  46661. #endif
  46662. /* decode envelopedData */
  46663. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, enveloped,
  46664. (word32)envelopedSz, decoded,
  46665. PKCS7_BUF_SIZE);
  46666. if (decodedSz <= 0) {
  46667. wc_PKCS7_Free(pkcs7);
  46668. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46669. }
  46670. /* test decode result */
  46671. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46672. wc_PKCS7_Free(pkcs7);
  46673. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46674. }
  46675. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46676. /* output pkcs7 envelopedData for external testing */
  46677. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46678. if (!pkcs7File) {
  46679. wc_PKCS7_Free(pkcs7);
  46680. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46681. }
  46682. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46683. XFCLOSE(pkcs7File);
  46684. if (ret != envelopedSz) {
  46685. wc_PKCS7_Free(pkcs7);
  46686. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46687. } else {
  46688. /* reset ret to 0 for success */
  46689. ret = 0;
  46690. }
  46691. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46692. wc_PKCS7_Free(pkcs7);
  46693. pkcs7 = NULL;
  46694. }
  46695. wc_FreeRng(&rng);
  46696. (void)eccCert;
  46697. (void)eccCertSz;
  46698. (void)eccPrivKey;
  46699. (void)eccPrivKeySz;
  46700. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46701. (void)secretKey;
  46702. (void)secretKeyId;
  46703. #endif
  46704. #ifdef NO_RSA
  46705. (void)rsaCert;
  46706. (void)rsaCertSz;
  46707. (void)rsaPrivKey;
  46708. (void)rsaPrivKeySz;
  46709. #endif
  46710. out:
  46711. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46712. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46713. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46714. return ret;
  46715. }
  46716. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void)
  46717. {
  46718. wc_test_ret_t ret = 0;
  46719. byte* rsaCert = NULL;
  46720. byte* rsaPrivKey = NULL;
  46721. word32 rsaCertSz = 0;
  46722. word32 rsaPrivKeySz = 0;
  46723. byte* eccCert = NULL;
  46724. byte* eccPrivKey = NULL;
  46725. word32 eccCertSz = 0;
  46726. word32 eccPrivKeySz = 0;
  46727. WOLFSSL_ENTER("pkcs7authenveloped_test");
  46728. #ifndef NO_RSA
  46729. /* read client RSA cert and key in DER format */
  46730. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46731. if (rsaCert == NULL)
  46732. return WC_TEST_RET_ENC_ERRNO;
  46733. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46734. if (rsaPrivKey == NULL) {
  46735. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46736. return WC_TEST_RET_ENC_NC;
  46737. }
  46738. rsaCertSz = FOURK_BUF;
  46739. rsaPrivKeySz = FOURK_BUF;
  46740. #endif /* NO_RSA */
  46741. #ifdef HAVE_ECC
  46742. /* read client ECC cert and key in DER format */
  46743. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46744. if (eccCert == NULL) {
  46745. #ifndef NO_RSA
  46746. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46747. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46748. #endif
  46749. return WC_TEST_RET_ENC_NC;
  46750. }
  46751. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46752. if (eccPrivKey == NULL) {
  46753. #ifndef NO_RSA
  46754. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46755. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46756. #endif
  46757. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46758. return WC_TEST_RET_ENC_NC;
  46759. }
  46760. eccCertSz = FOURK_BUF;
  46761. eccPrivKeySz = FOURK_BUF;
  46762. #endif /* HAVE_ECC */
  46763. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46764. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46765. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46766. eccPrivKey, &eccPrivKeySz);
  46767. if (ret < 0) {
  46768. #ifndef NO_RSA
  46769. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46770. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46771. #endif
  46772. #ifdef HAVE_ECC
  46773. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46774. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46775. #endif
  46776. return WC_TEST_RET_ENC_EC(ret);
  46777. }
  46778. ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46779. rsaPrivKey, (word32)rsaPrivKeySz,
  46780. eccCert, (word32)eccCertSz,
  46781. eccPrivKey, (word32)eccPrivKeySz);
  46782. #ifndef NO_RSA
  46783. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46784. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46785. #endif
  46786. #ifdef HAVE_ECC
  46787. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46788. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46789. #endif
  46790. return ret;
  46791. }
  46792. #endif /* HAVE_AESGCM || HAVE_AESCCM */
  46793. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46794. static const byte p7DefKey[] = {
  46795. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46796. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46797. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46798. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46799. };
  46800. static const byte p7AltKey[] = {
  46801. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  46802. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  46803. };
  46804. static int myCEKwrapFunc(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  46805. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  46806. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  46807. {
  46808. wc_test_ret_t ret;
  46809. if (cek == NULL || out == NULL)
  46810. return BAD_FUNC_ARG;
  46811. /* test case sanity checks */
  46812. if (keyIdSz != 1) {
  46813. return WC_TEST_RET_ENC_NC;
  46814. }
  46815. if (keyId[0] != 0x00) {
  46816. return WC_TEST_RET_ENC_NC;
  46817. }
  46818. if (type != (int)PKCS7_KEKRI) {
  46819. return WC_TEST_RET_ENC_NC;
  46820. }
  46821. switch (keyWrapAlgo) {
  46822. case AES256_WRAP:
  46823. ret = wc_AesKeyUnWrap(p7DefKey, sizeof(p7DefKey), cek, cekSz,
  46824. out, outSz, NULL);
  46825. if (ret <= 0)
  46826. return (int)ret;
  46827. break;
  46828. default:
  46829. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  46830. return BAD_KEYWRAP_ALG_E;
  46831. };
  46832. (void)pkcs7;
  46833. (void)direction;
  46834. (void)orginKey; /* used with KAKRI */
  46835. (void)orginKeySz;
  46836. return (int)ret;
  46837. }
  46838. /* returns key size on success */
  46839. static wc_test_ret_t getFirmwareKey(wc_PKCS7* pkcs7, byte* key, word32 keySz)
  46840. {
  46841. wc_test_ret_t ret;
  46842. word32 atrSz;
  46843. byte atr[256];
  46844. /* Additionally can look for fwWrappedFirmwareKey
  46845. * 1.2.840.113529.1.9.16.1.16 */
  46846. const unsigned char fwWrappedFirmwareKey[] = {
  46847. /* 0x06, 0x0B */
  46848. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46849. 0x01, 0x09, 0x10, 0x02, 0x27
  46850. };
  46851. /* find keyID in fwWrappedFirmwareKey */
  46852. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  46853. sizeof(fwWrappedFirmwareKey), NULL, &atrSz);
  46854. if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  46855. XMEMSET(atr, 0, sizeof(atr));
  46856. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  46857. sizeof(fwWrappedFirmwareKey), atr, &atrSz);
  46858. /* keyIdRaw[0] OCTET TAG */
  46859. /* keyIdRaw[1] Length */
  46860. if (ret > 0) {
  46861. wc_PKCS7* envPkcs7;
  46862. envPkcs7 = wc_PKCS7_New(NULL, 0);
  46863. if (envPkcs7 == NULL) {
  46864. return MEMORY_E;
  46865. }
  46866. wc_PKCS7_Init(envPkcs7, NULL, 0);
  46867. ret = wc_PKCS7_SetWrapCEKCb(envPkcs7, myCEKwrapFunc);
  46868. if (ret == 0) {
  46869. /* expecting FIRMWARE_PKG_DATA content */
  46870. envPkcs7->contentOID = FIRMWARE_PKG_DATA;
  46871. ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
  46872. key, keySz);
  46873. if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
  46874. /* the contentOID should have been set to the inner
  46875. * FIRMWARE_PKG_DATA content */
  46876. ret = BAD_STATE_E;
  46877. }
  46878. }
  46879. wc_PKCS7_Free(envPkcs7);
  46880. }
  46881. }
  46882. return ret;
  46883. }
  46884. /* create a KEKRI enveloped data
  46885. * return size on success */
  46886. static wc_test_ret_t envelopedData_encrypt(byte* in, word32 inSz, byte* out,
  46887. word32 outSz)
  46888. {
  46889. wc_test_ret_t ret;
  46890. wc_PKCS7* pkcs7;
  46891. WOLFSSL_SMALL_STACK_STATIC const byte keyId[] = { 0x00 };
  46892. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  46893. if (pkcs7 == NULL)
  46894. return WC_TEST_RET_ENC_ERRNO;
  46895. pkcs7->content = in;
  46896. pkcs7->contentSz = inSz;
  46897. pkcs7->contentOID = FIRMWARE_PKG_DATA;
  46898. pkcs7->encryptOID = AES256CBCb;
  46899. pkcs7->ukm = NULL;
  46900. pkcs7->ukmSz = 0;
  46901. /* add recipient (KEKRI type) */
  46902. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP, (byte*)p7DefKey,
  46903. sizeof(p7DefKey), (byte*)keyId,
  46904. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0);
  46905. if (ret < 0) {
  46906. printf("wc_PKCS7_AddRecipient_KEKRI() failed\n");
  46907. wc_PKCS7_Free(pkcs7);
  46908. return WC_TEST_RET_ENC_EC(ret);
  46909. }
  46910. /* encode envelopedData, returns size */
  46911. ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
  46912. if (ret <= 0) {
  46913. printf("wc_PKCS7_EncodeEnvelopedData() failed\n");
  46914. wc_PKCS7_Free(pkcs7);
  46915. return WC_TEST_RET_ENC_EC(ret);
  46916. }
  46917. wc_PKCS7_Free(pkcs7);
  46918. return ret;
  46919. }
  46920. /*
  46921. * keyHint is the KeyID to be set in the fwDecryptKeyID attribute
  46922. * returns size of buffer output on success
  46923. */
  46924. static wc_test_ret_t generateBundle(byte* out, word32 *outSz, const byte* encryptKey,
  46925. word32 encryptKeySz, byte keyHint, byte* cert, word32 certSz,
  46926. byte* key, word32 keySz)
  46927. {
  46928. wc_test_ret_t ret;
  46929. int attribNum = 1;
  46930. wc_PKCS7* pkcs7;
  46931. /* KEY ID
  46932. * fwDecryptKeyID OID 1.2.840.113549.1.9.16.2.37
  46933. */
  46934. const unsigned char fwDecryptKeyID[] = {
  46935. 0x06, 0x0B,
  46936. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46937. 0x01, 0x09, 0x10, 0x02, 0x25
  46938. };
  46939. /* fwWrappedFirmwareKey 1.2.840.113529.1.9.16.1.16 */
  46940. const unsigned char fwWrappedFirmwareKey[] = {
  46941. 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  46942. 0x01, 0x09, 0x10, 0x02, 0x27
  46943. };
  46944. byte keyID[] = { 0x04, 0x01, 0x00 };
  46945. byte env[256];
  46946. char data[] = "Test of wolfSSL PKCS7 decrypt callback";
  46947. PKCS7Attrib attribs[] =
  46948. {
  46949. { fwDecryptKeyID, sizeof(fwDecryptKeyID), keyID, sizeof(keyID) },
  46950. { fwWrappedFirmwareKey, sizeof(fwWrappedFirmwareKey), env, 0 }
  46951. };
  46952. keyID[2] = keyHint;
  46953. /* If using keyHint 0 then create a bundle with fwWrappedFirmwareKey */
  46954. if (keyHint == 0) {
  46955. ret = envelopedData_encrypt((byte*)p7DefKey, sizeof(p7DefKey), env,
  46956. sizeof(env));
  46957. if (ret <= 0) {
  46958. return ret;
  46959. }
  46960. attribs[1].valueSz = (word32)ret;
  46961. attribNum++;
  46962. }
  46963. /* init PKCS7 */
  46964. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  46965. if (pkcs7 == NULL)
  46966. return WC_TEST_RET_ENC_ERRNO;
  46967. ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
  46968. if (ret != 0) {
  46969. printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret);
  46970. wc_PKCS7_Free(pkcs7);
  46971. return WC_TEST_RET_ENC_EC(ret);
  46972. }
  46973. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46974. if (ret != 0) {
  46975. wc_PKCS7_Free(pkcs7);
  46976. return WC_TEST_RET_ENC_EC(ret);
  46977. }
  46978. /* encode Signed Encrypted FirmwarePkgData */
  46979. if (encryptKeySz == 16) {
  46980. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  46981. encryptKeySz, key, keySz, AES128CBCb, RSAk, SHA256h,
  46982. (byte*)data, sizeof(data), NULL, 0,
  46983. attribs, (word32)attribNum, out, *outSz);
  46984. }
  46985. else {
  46986. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  46987. encryptKeySz, key, keySz, AES256CBCb, RSAk, SHA256h,
  46988. (byte*)data, sizeof(data), NULL, 0,
  46989. attribs, (word32)attribNum, out, *outSz);
  46990. }
  46991. if (ret <= 0) {
  46992. printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, "
  46993. "ret = %d\n", ret);
  46994. wc_PKCS7_Free(pkcs7);
  46995. return WC_TEST_RET_ENC_EC(ret);
  46996. } else {
  46997. *outSz = (word32)ret;
  46998. }
  46999. wc_PKCS7_Free(pkcs7);
  47000. return ret;
  47001. }
  47002. /* test verification and decryption of PKCS7 bundle
  47003. * return 0 on success
  47004. */
  47005. static wc_test_ret_t verifyBundle(byte* derBuf, word32 derSz, int keyHint)
  47006. {
  47007. wc_test_ret_t ret = 0;
  47008. int usrCtx = 1; /* test value to pass as user context to callback */
  47009. wc_PKCS7* pkcs7 = NULL;
  47010. byte* sid = NULL;
  47011. word32 sidSz;
  47012. byte key[256];
  47013. word32 keySz = sizeof(key);
  47014. byte *decoded = NULL;
  47015. int decodedSz = FOURK_BUF/2;
  47016. WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = {
  47017. #ifdef NO_SHA
  47018. #ifdef USE_CERT_BUFFERS_1024
  47019. 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9,
  47020. 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2,
  47021. 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06,
  47022. 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9
  47023. #else
  47024. 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36,
  47025. 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e,
  47026. 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4,
  47027. 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71
  47028. #endif
  47029. #else /* !NO_SHA */
  47030. #ifdef USE_CERT_BUFFERS_1024
  47031. 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34,
  47032. 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75,
  47033. 0x10, 0x69, 0x59, 0xec,
  47034. #else
  47035. 0x33, 0xD8, 0x45, 0x66, 0xD7, 0x68, 0x87, 0x18,
  47036. 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26,
  47037. 0xD7, 0x85, 0x65, 0xC0
  47038. #endif
  47039. #endif /* !NO_SHA */
  47040. };
  47041. decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47042. if (decoded == NULL) {
  47043. ret = MEMORY_E;
  47044. goto out;
  47045. }
  47046. pkcs7 = wc_PKCS7_New(HEAP_HINT, INVALID_DEVID);
  47047. if (pkcs7 == NULL) {
  47048. ret = MEMORY_E;
  47049. goto out;
  47050. }
  47051. /* Test verify */
  47052. ret = wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID);
  47053. if (ret != 0)
  47054. goto out;
  47055. ret = wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47056. if (ret != 0)
  47057. goto out;
  47058. ret = wc_PKCS7_VerifySignedData(pkcs7, derBuf, derSz);
  47059. if (ret != 0)
  47060. goto out;
  47061. /* Get size of SID and print it out */
  47062. ret = wc_PKCS7_GetSignerSID(pkcs7, NULL, &sidSz);
  47063. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47064. goto out;
  47065. sid = (byte*)XMALLOC(sidSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47066. if (sid == NULL) {
  47067. ret = MEMORY_E;
  47068. goto out;
  47069. }
  47070. ret = wc_PKCS7_GetSignerSID(pkcs7, sid, &sidSz);
  47071. if (ret != 0)
  47072. goto out;
  47073. ret = XMEMCMP(sid, expectedSid, sidSz);
  47074. if (ret != 0) {
  47075. ret = PKCS7_NO_SIGNER_E; /* close enough */
  47076. goto out;
  47077. }
  47078. /* get expected fwWrappedFirmwareKey */
  47079. if (keyHint == 0) {
  47080. ret = getFirmwareKey(pkcs7, key, keySz);
  47081. if (ret < 0)
  47082. goto out;
  47083. pkcs7->encryptionKey = key;
  47084. pkcs7->encryptionKeySz = (word32)ret;
  47085. }
  47086. else {
  47087. decodedSz = PKCS7_BUF_SIZE;
  47088. ret = wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc);
  47089. if (ret != 0)
  47090. goto out;
  47091. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)&usrCtx);
  47092. if (ret != 0)
  47093. goto out;
  47094. }
  47095. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47096. pkcs7->contentSz, decoded, (word32)decodedSz);
  47097. if (decodedSz < 0) {
  47098. ret = decodedSz;
  47099. goto out;
  47100. }
  47101. ret = 0;
  47102. out:
  47103. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47104. if (pkcs7)
  47105. wc_PKCS7_Free(pkcs7);
  47106. XFREE(sid, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47107. return ret;
  47108. }
  47109. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key, word32 keySz)
  47110. {
  47111. wc_test_ret_t ret = 0;
  47112. word32 derSz;
  47113. byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47114. WOLFSSL_ENTER("pkcs7callback_test");
  47115. if (! derBuf)
  47116. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47117. /* Doing default generation and verify */
  47118. derSz = FOURK_BUF;
  47119. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert,
  47120. certSz, key, keySz);
  47121. if (ret <= 0) {
  47122. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47123. }
  47124. ret = verifyBundle(derBuf, derSz, 0);
  47125. if (ret != 0)
  47126. ERROR_OUT(ret, out);
  47127. /* test choosing other key with keyID */
  47128. derSz = FOURK_BUF;
  47129. ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1,
  47130. cert, certSz, key, keySz);
  47131. if (ret <= 0) {
  47132. ERROR_OUT(ret, out);
  47133. }
  47134. ret = verifyBundle(derBuf, derSz, 1);
  47135. if (ret != 0)
  47136. ERROR_OUT(ret, out);
  47137. /* test fail case with wrong keyID */
  47138. derSz = FOURK_BUF;
  47139. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1,
  47140. cert, certSz, key, keySz);
  47141. if (ret <= 0) {
  47142. ERROR_OUT(ret, out);
  47143. }
  47144. ret = verifyBundle(derBuf, derSz, 1);
  47145. if (ret == 0) {
  47146. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47147. }
  47148. ret = 0;
  47149. out:
  47150. XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47151. return ret;
  47152. }
  47153. #endif /* !NO_AES && HAVE_AES_CBC */
  47154. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47155. typedef struct {
  47156. const byte* content;
  47157. word32 contentSz;
  47158. int contentOID;
  47159. int encryptOID;
  47160. byte* encryptionKey;
  47161. word32 encryptionKeySz;
  47162. PKCS7Attrib* attribs;
  47163. word32 attribsSz;
  47164. const char* outFileName;
  47165. } pkcs7EncryptedVector;
  47166. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void)
  47167. {
  47168. wc_test_ret_t ret = 0;
  47169. int i, testSz;
  47170. int encryptedSz, decodedSz, attribIdx;
  47171. wc_PKCS7* pkcs7;
  47172. byte *encrypted;
  47173. byte *decoded;
  47174. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47175. XFILE pkcs7File;
  47176. #endif
  47177. PKCS7Attrib* expectedAttrib;
  47178. PKCS7DecodedAttrib* decodedAttrib;
  47179. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47180. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47181. 0x72,0x6c,0x64
  47182. };
  47183. #ifndef NO_DES3
  47184. byte desKey[] = {
  47185. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  47186. };
  47187. byte des3Key[] = {
  47188. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  47189. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  47190. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  47191. };
  47192. #endif
  47193. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47194. #ifdef WOLFSSL_AES_128
  47195. byte aes128Key[] = {
  47196. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47197. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47198. };
  47199. #endif
  47200. #ifdef WOLFSSL_AES_192
  47201. byte aes192Key[] = {
  47202. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47203. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47204. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47205. };
  47206. #endif
  47207. #ifdef WOLFSSL_AES_256
  47208. byte aes256Key[] = {
  47209. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47210. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47211. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47212. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47213. };
  47214. #endif
  47215. #ifdef WOLFSSL_AES_256
  47216. /* Attribute example from RFC 4134, Section 7.2
  47217. * OID = 1.2.5555
  47218. * OCTET STRING = 'This is a test General ASN Attribute, number 1.' */
  47219. static const byte genAttrOid[] = { 0x06, 0x03, 0x2a, 0xab, 0x33 };
  47220. static const byte genAttr[] = { 0x04, 47,
  47221. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47222. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47223. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47224. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47225. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47226. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x31, 0x2e };
  47227. static const byte genAttrOid2[] = { 0x06, 0x03, 0x2a, 0xab, 0x34 };
  47228. static const byte genAttr2[] = { 0x04, 47,
  47229. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47230. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47231. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47232. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47233. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47234. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x32, 0x2e };
  47235. PKCS7Attrib attribs[] =
  47236. {
  47237. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }
  47238. };
  47239. PKCS7Attrib multiAttribs[] =
  47240. {
  47241. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) },
  47242. { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) }
  47243. };
  47244. #endif
  47245. #endif /* NO_AES */
  47246. const pkcs7EncryptedVector testVectors[] =
  47247. {
  47248. #ifndef NO_DES3
  47249. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key),
  47250. NULL, 0, "pkcs7encryptedDataDES3.der"},
  47251. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey),
  47252. NULL, 0, "pkcs7encryptedDataDES.der"},
  47253. #endif /* NO_DES3 */
  47254. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47255. #ifdef WOLFSSL_AES_128
  47256. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  47257. sizeof(aes128Key), NULL, 0, "pkcs7encryptedDataAES128CBC.der"},
  47258. #endif
  47259. #ifdef WOLFSSL_AES_192
  47260. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  47261. sizeof(aes192Key), NULL, 0, "pkcs7encryptedDataAES192CBC.der"},
  47262. #endif
  47263. #ifdef WOLFSSL_AES_256
  47264. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47265. sizeof(aes256Key), NULL, 0, "pkcs7encryptedDataAES256CBC.der"},
  47266. /* test with optional unprotected attributes */
  47267. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47268. sizeof(aes256Key), attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47269. "pkcs7encryptedDataAES256CBC_attribs.der"},
  47270. /* test with multiple optional unprotected attributes */
  47271. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47272. sizeof(aes256Key), multiAttribs,
  47273. (sizeof(multiAttribs)/sizeof(PKCS7Attrib)),
  47274. "pkcs7encryptedDataAES256CBC_multi_attribs.der"},
  47275. /* test with contentType set to FirmwarePkgData */
  47276. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256CBCb, aes256Key,
  47277. sizeof(aes256Key), NULL, 0,
  47278. "pkcs7encryptedDataAES256CBC_firmwarePkgData.der"},
  47279. #endif
  47280. #endif /* !NO_AES && HAVE_AES_CBC */
  47281. };
  47282. WOLFSSL_ENTER("pkcs7encrypted_test");
  47283. encrypted = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47284. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47285. if ((! encrypted) || (! decoded)) {
  47286. ERROR_OUT(MEMORY_E, out);
  47287. }
  47288. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  47289. for (i = 0; i < testSz; i++) {
  47290. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47291. if (pkcs7 == NULL) {
  47292. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47293. }
  47294. pkcs7->content = (byte*)testVectors[i].content;
  47295. pkcs7->contentSz = testVectors[i].contentSz;
  47296. pkcs7->contentOID = testVectors[i].contentOID;
  47297. pkcs7->encryptOID = testVectors[i].encryptOID;
  47298. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  47299. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  47300. pkcs7->unprotectedAttribs = testVectors[i].attribs;
  47301. pkcs7->unprotectedAttribsSz = testVectors[i].attribsSz;
  47302. /* encode encryptedData */
  47303. encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47304. PKCS7_BUF_SIZE);
  47305. if (encryptedSz <= 0) {
  47306. wc_PKCS7_Free(pkcs7);
  47307. ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out);
  47308. }
  47309. /* decode encryptedData */
  47310. #ifndef NO_PKCS7_STREAM
  47311. { /* test reading byte by byte */
  47312. int z;
  47313. for (z = 0; z < encryptedSz; z++) {
  47314. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted + z, 1,
  47315. decoded, PKCS7_BUF_SIZE);
  47316. if (decodedSz <= 0 &&
  47317. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47318. {
  47319. printf("unexpected error %d\n", decodedSz);
  47320. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47321. }
  47322. }
  47323. /* test decode result */
  47324. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47325. printf("stream read failed\n");
  47326. wc_PKCS7_Free(pkcs7);
  47327. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47328. }
  47329. }
  47330. #endif
  47331. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47332. decoded, PKCS7_BUF_SIZE);
  47333. if (decodedSz <= 0){
  47334. wc_PKCS7_Free(pkcs7);
  47335. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47336. }
  47337. /* test decode result */
  47338. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47339. wc_PKCS7_Free(pkcs7);
  47340. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47341. }
  47342. /* verify decoded unprotected attributes */
  47343. if (pkcs7->decodedAttrib != NULL) {
  47344. decodedAttrib = pkcs7->decodedAttrib;
  47345. attribIdx = 1;
  47346. while (decodedAttrib != NULL) {
  47347. /* expected attribute, stored list is reversed */
  47348. expectedAttrib = &(pkcs7->unprotectedAttribs
  47349. [pkcs7->unprotectedAttribsSz - attribIdx]);
  47350. /* verify oid */
  47351. if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid,
  47352. decodedAttrib->oidSz) != 0) {
  47353. wc_PKCS7_Free(pkcs7);
  47354. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47355. }
  47356. /* verify value */
  47357. if (XMEMCMP(decodedAttrib->value, expectedAttrib->value,
  47358. decodedAttrib->valueSz) != 0) {
  47359. wc_PKCS7_Free(pkcs7);
  47360. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47361. }
  47362. decodedAttrib = decodedAttrib->next;
  47363. attribIdx++;
  47364. }
  47365. }
  47366. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47367. /* output pkcs7 envelopedData for external testing */
  47368. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47369. if (!pkcs7File) {
  47370. wc_PKCS7_Free(pkcs7);
  47371. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47372. }
  47373. ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File);
  47374. if (ret < 0)
  47375. ret = WC_TEST_RET_ENC_ERRNO;
  47376. else
  47377. ret = 0;
  47378. XFCLOSE(pkcs7File);
  47379. #endif
  47380. wc_PKCS7_Free(pkcs7);
  47381. }
  47382. out:
  47383. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47384. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47385. return ret;
  47386. }
  47387. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47388. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47389. typedef struct {
  47390. const byte* content;
  47391. word32 contentSz;
  47392. int contentOID;
  47393. const char* outFileName;
  47394. } pkcs7CompressedVector;
  47395. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void)
  47396. {
  47397. wc_test_ret_t ret = 0;
  47398. int i, testSz;
  47399. int compressedSz, decodedSz;
  47400. wc_PKCS7* pkcs7;
  47401. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47402. byte *compressed;
  47403. byte *decoded;
  47404. #else
  47405. byte compressed[PKCS7_BUF_SIZE];
  47406. byte decoded[PKCS7_BUF_SIZE];
  47407. #endif
  47408. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47409. XFILE pkcs7File;
  47410. #endif
  47411. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47412. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47413. 0x72,0x6c,0x64
  47414. };
  47415. const pkcs7CompressedVector testVectors[] =
  47416. {
  47417. {data, (word32)sizeof(data), DATA,
  47418. "pkcs7compressedData_data_zlib.der"},
  47419. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA,
  47420. "pkcs7compressedData_firmwarePkgData_zlib.der"},
  47421. };
  47422. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47423. compressed = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47424. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47425. if ((! compressed) || (! decoded)) {
  47426. ERROR_OUT(MEMORY_E, out);
  47427. }
  47428. #endif
  47429. WOLFSSL_ENTER("pkcs7compressed_test");
  47430. testSz = sizeof(testVectors) / sizeof(pkcs7CompressedVector);
  47431. for (i = 0; i < testSz; i++) {
  47432. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47433. if (pkcs7 == NULL) {
  47434. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47435. }
  47436. pkcs7->content = (byte*)testVectors[i].content;
  47437. pkcs7->contentSz = testVectors[i].contentSz;
  47438. pkcs7->contentOID = testVectors[i].contentOID;
  47439. /* encode compressedData */
  47440. compressedSz = wc_PKCS7_EncodeCompressedData(pkcs7, compressed,
  47441. PKCS7_BUF_SIZE);
  47442. if (compressedSz <= 0) {
  47443. wc_PKCS7_Free(pkcs7);
  47444. ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out);
  47445. }
  47446. /* decode compressedData */
  47447. decodedSz = wc_PKCS7_DecodeCompressedData(pkcs7, compressed,
  47448. compressedSz, decoded,
  47449. PKCS7_BUF_SIZE);
  47450. if (decodedSz <= 0){
  47451. wc_PKCS7_Free(pkcs7);
  47452. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47453. }
  47454. /* test decode result */
  47455. if (XMEMCMP(decoded, testVectors[i].content,
  47456. testVectors[i].contentSz) != 0) {
  47457. wc_PKCS7_Free(pkcs7);
  47458. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47459. }
  47460. /* make sure content type is the same */
  47461. if (testVectors[i].contentOID != pkcs7->contentOID) {
  47462. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47463. }
  47464. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47465. /* output pkcs7 compressedData for external testing */
  47466. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47467. if (!pkcs7File) {
  47468. wc_PKCS7_Free(pkcs7);
  47469. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47470. }
  47471. ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File);
  47472. if (ret < 0)
  47473. ret = WC_TEST_RET_ENC_ERRNO;
  47474. else
  47475. ret = 0;
  47476. XFCLOSE(pkcs7File);
  47477. #endif
  47478. wc_PKCS7_Free(pkcs7);
  47479. }
  47480. out:
  47481. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47482. XFREE(compressed, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47483. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47484. #endif
  47485. return ret;
  47486. } /* pkcs7compressed_test() */
  47487. #undef PKCS7_BUF_SIZE
  47488. #endif /* HAVE_LIBZ */
  47489. typedef struct {
  47490. const byte* content;
  47491. word32 contentSz;
  47492. int hashOID;
  47493. int signOID;
  47494. byte* privateKey;
  47495. word32 privateKeySz;
  47496. byte* cert;
  47497. size_t certSz;
  47498. byte* caCert;
  47499. size_t caCertSz;
  47500. PKCS7Attrib* signedAttribs;
  47501. word32 signedAttribsSz;
  47502. const char* outFileName;
  47503. int contentOID;
  47504. const byte* contentType;
  47505. word32 contentTypeSz;
  47506. int sidType;
  47507. int encryptOID; /* for single-shot encrypt alg OID */
  47508. int encCompFlag; /* for single-shot. 1 = enc, 2 = comp, 3 = both*/
  47509. const byte* encryptKey; /* for single-shot, encryptedData */
  47510. word32 encryptKeySz; /* for single-shot, encryptedData */
  47511. PKCS7Attrib* unprotectedAttribs; /* for single-shot, encryptedData */
  47512. word32 unprotectedAttribsSz; /* for single-shot, encryptedData */
  47513. word16 detachedSignature; /* generate detached signature (0:1) */
  47514. } pkcs7SignedVector;
  47515. static wc_test_ret_t pkcs7signed_run_vectors(
  47516. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47517. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47518. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47519. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47520. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47521. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47522. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47523. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47524. {
  47525. wc_test_ret_t ret;
  47526. int testSz = 0, i;
  47527. int encodedSz;
  47528. byte* out = NULL;
  47529. word32 outSz;
  47530. WC_RNG rng;
  47531. wc_PKCS7* pkcs7 = NULL;
  47532. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47533. XFILE file;
  47534. #endif
  47535. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47536. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47537. 0x72,0x6c,0x64
  47538. };
  47539. static const byte transIdOid[] =
  47540. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47541. 0x09, 0x07 };
  47542. static const byte messageTypeOid[] =
  47543. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47544. 0x09, 0x02 };
  47545. static const byte senderNonceOid[] =
  47546. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47547. 0x09, 0x05 };
  47548. #ifndef NO_SHA
  47549. byte transId[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47550. #else
  47551. byte transId[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47552. #endif
  47553. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47554. byte senderNonce[PKCS7_NONCE_SZ + 2];
  47555. PKCS7Attrib attribs[] =
  47556. {
  47557. { transIdOid, sizeof(transIdOid), transId,
  47558. sizeof(transId) - 1 }, /* take off the null */
  47559. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47560. sizeof(messageType) },
  47561. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  47562. sizeof(senderNonce) }
  47563. };
  47564. /* for testing custom contentType, FirmwarePkgData */
  47565. static const byte customContentType[] = { 0x06, 0x0B, 0x2A, 0x86,
  47566. 0x48, 0x86, 0xF7, 0x0D,
  47567. 0x01, 0x09, 0x10, 0x01, 0x10 };
  47568. #define MAX_TESTVECTORS_LEN 20
  47569. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47570. const pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47571. if (testSz == MAX_TESTVECTORS_LEN) { \
  47572. ret = WC_TEST_RET_ENC_NC; \
  47573. goto out; \
  47574. } \
  47575. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47576. sizeof _this_vector); \
  47577. }
  47578. pkcs7SignedVector *testVectors = NULL;
  47579. XMEMSET(&rng, 0, sizeof(rng));
  47580. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47581. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47582. if (testVectors == NULL) {
  47583. ret = WC_TEST_RET_ENC_ERRNO;
  47584. goto out;
  47585. }
  47586. {
  47587. #ifndef NO_RSA
  47588. #ifndef NO_SHA
  47589. /* RSA with SHA */
  47590. ADD_PKCS7SIGNEDVECTOR(
  47591. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47592. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47593. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47594. "pkcs7signedData_RSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0, NULL,
  47595. 0, 0);
  47596. /* RSA with SHA, no signed attributes */
  47597. ADD_PKCS7SIGNEDVECTOR(
  47598. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47599. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz,
  47600. NULL, 0, NULL, 0,
  47601. "pkcs7signedData_RSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47602. NULL, 0, 0);
  47603. #endif
  47604. #ifdef WOLFSSL_SHA224
  47605. /* RSA with SHA224 */
  47606. ADD_PKCS7SIGNEDVECTOR(
  47607. data, (word32)sizeof(data), SHA224h, RSAk, rsaClientPrivKeyBuf,
  47608. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47609. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47610. "pkcs7signedData_RSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47611. NULL, 0, 0);
  47612. #endif
  47613. #ifndef NO_SHA256
  47614. /* RSA with SHA256 */
  47615. ADD_PKCS7SIGNEDVECTOR(
  47616. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47617. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47618. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47619. "pkcs7signedData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47620. NULL, 0, 0);
  47621. /* RSA with SHA256, detached signature */
  47622. ADD_PKCS7SIGNEDVECTOR(
  47623. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47624. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47625. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47626. "pkcs7signedData_RSA_SHA256_detachedSig.der", 0, NULL, 0, 0, 0, 0,
  47627. NULL, 0, NULL, 0, 1);
  47628. /* RSA with SHA256 and SubjectKeyIdentifier in SignerIdentifier */
  47629. ADD_PKCS7SIGNEDVECTOR(
  47630. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47631. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47632. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47633. "pkcs7signedData_RSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47634. NULL, 0, NULL, 0, 0);
  47635. /* RSA with SHA256 and custom contentType */
  47636. ADD_PKCS7SIGNEDVECTOR(
  47637. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47638. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47639. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47640. "pkcs7signedData_RSA_SHA256_custom_contentType.der", 0,
  47641. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  47642. NULL, 0, 0);
  47643. /* RSA with SHA256 and FirmwarePkgData contentType */
  47644. ADD_PKCS7SIGNEDVECTOR(
  47645. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47646. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47647. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47648. "pkcs7signedData_RSA_SHA256_firmwarePkgData.der",
  47649. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47650. /* RSA with SHA256 using server cert and ca cert */
  47651. ADD_PKCS7SIGNEDVECTOR(
  47652. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  47653. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  47654. rsaCaCertBuf, rsaCaCertBufSz,
  47655. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47656. "pkcs7signedData_RSA_SHA256_with_ca_cert.der", 0, NULL, 0, 0, 0, 0,
  47657. NULL, 0, NULL, 0, 0);
  47658. #endif
  47659. #if defined(WOLFSSL_SHA384)
  47660. /* RSA with SHA384 */
  47661. ADD_PKCS7SIGNEDVECTOR(
  47662. data, (word32)sizeof(data), SHA384h, RSAk, rsaClientPrivKeyBuf,
  47663. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47664. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47665. "pkcs7signedData_RSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47666. NULL, 0, 0);
  47667. #endif
  47668. #if defined(WOLFSSL_SHA512)
  47669. /* RSA with SHA512 */
  47670. ADD_PKCS7SIGNEDVECTOR(
  47671. data, (word32)sizeof(data), SHA512h, RSAk, rsaClientPrivKeyBuf,
  47672. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47673. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47674. "pkcs7signedData_RSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47675. NULL, 0, 0);
  47676. #endif
  47677. #endif /* NO_RSA */
  47678. #ifdef HAVE_ECC
  47679. #ifndef NO_SHA
  47680. /* ECDSA with SHA */
  47681. ADD_PKCS7SIGNEDVECTOR(
  47682. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  47683. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47684. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47685. "pkcs7signedData_ECDSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47686. NULL, 0, 0);
  47687. /* ECDSA with SHA, no signed attributes */
  47688. ADD_PKCS7SIGNEDVECTOR(
  47689. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  47690. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz,
  47691. NULL, 0, NULL, 0,
  47692. "pkcs7signedData_ECDSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47693. NULL, 0, 0);
  47694. #endif
  47695. #ifdef WOLFSSL_SHA224
  47696. /* ECDSA with SHA224 */
  47697. ADD_PKCS7SIGNEDVECTOR(
  47698. data, (word32)sizeof(data), SHA224h, ECDSAk, eccClientPrivKeyBuf,
  47699. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47700. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47701. "pkcs7signedData_ECDSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47702. NULL, 0, 0);
  47703. #endif
  47704. #ifndef NO_SHA256
  47705. /* ECDSA with SHA256 */
  47706. ADD_PKCS7SIGNEDVECTOR(
  47707. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47708. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47709. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47710. "pkcs7signedData_ECDSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47711. NULL, 0, 0);
  47712. /* ECDSA with SHA256 and SubjectKeyIdentifier in SigherIdentifier */
  47713. ADD_PKCS7SIGNEDVECTOR(
  47714. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47715. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47716. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47717. "pkcs7signedData_ECDSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47718. NULL, 0, NULL, 0, 0);
  47719. /* ECDSA with SHA256 and custom contentType */
  47720. ADD_PKCS7SIGNEDVECTOR(
  47721. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47722. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47723. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47724. "pkcs7signedData_ECDSA_SHA256_custom_contentType.der", 0,
  47725. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  47726. NULL, 0, 0);
  47727. /* ECDSA with SHA256 and FirmwarePkgData contentType */
  47728. ADD_PKCS7SIGNEDVECTOR(
  47729. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  47730. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47731. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47732. "pkcs7signedData_ECDSA_SHA256_firmwarePkgData.der",
  47733. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  47734. #endif
  47735. #ifdef WOLFSSL_SHA384
  47736. /* ECDSA with SHA384 */
  47737. ADD_PKCS7SIGNEDVECTOR(
  47738. data, (word32)sizeof(data), SHA384h, ECDSAk, eccClientPrivKeyBuf,
  47739. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47740. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47741. "pkcs7signedData_ECDSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47742. NULL, 0, 0);
  47743. #endif
  47744. #ifdef WOLFSSL_SHA512
  47745. /* ECDSA with SHA512 */
  47746. ADD_PKCS7SIGNEDVECTOR(
  47747. data, (word32)sizeof(data), SHA512h, ECDSAk, eccClientPrivKeyBuf,
  47748. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  47749. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47750. "pkcs7signedData_ECDSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47751. NULL, 0, 0);
  47752. #endif
  47753. #endif /* HAVE_ECC */
  47754. };
  47755. #undef MAX_TESTVECTORS_LEN
  47756. #undef ADD_PKCS7SIGNEDVECTOR
  47757. outSz = FOURK_BUF;
  47758. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47759. if (out == NULL)
  47760. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47761. XMEMSET(out, 0, outSz);
  47762. /* test inner pad size error with block size being 0 */
  47763. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
  47764. if (ret > 0)
  47765. ERROR_OUT(-1, out);
  47766. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  47767. if (ret < 0)
  47768. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47769. #ifndef HAVE_FIPS
  47770. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  47771. #else
  47772. ret = wc_InitRng(&rng);
  47773. #endif
  47774. if (ret != 0)
  47775. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47776. for (i = 0; i < testSz; i++) {
  47777. if (pkcs7)
  47778. wc_PKCS7_Free(pkcs7);
  47779. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47780. if (pkcs7 == NULL)
  47781. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47782. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  47783. (word32)testVectors[i].certSz);
  47784. if (ret != 0)
  47785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47786. /* load CA certificate, if present */
  47787. if (testVectors[i].caCert != NULL) {
  47788. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  47789. (word32)testVectors[i].caCertSz);
  47790. if (ret != 0)
  47791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47792. }
  47793. pkcs7->rng = &rng;
  47794. pkcs7->content = (byte*)testVectors[i].content;
  47795. pkcs7->contentSz = testVectors[i].contentSz;
  47796. pkcs7->contentOID = testVectors[i].contentOID;
  47797. pkcs7->hashOID = testVectors[i].hashOID;
  47798. pkcs7->encryptOID = testVectors[i].signOID;
  47799. pkcs7->privateKey = testVectors[i].privateKey;
  47800. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  47801. pkcs7->signedAttribs = testVectors[i].signedAttribs;
  47802. pkcs7->signedAttribsSz = testVectors[i].signedAttribsSz;
  47803. /* optional custom contentType, default is DATA,
  47804. overrides contentOID if set */
  47805. if (testVectors[i].contentType != NULL) {
  47806. ret = wc_PKCS7_SetContentType(pkcs7,
  47807. (byte *)testVectors[i].contentType,
  47808. testVectors[i].contentTypeSz);
  47809. if (ret != 0)
  47810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47811. }
  47812. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  47813. default is IssuerAndSerialNumber */
  47814. if (testVectors[i].sidType == CMS_SKID) {
  47815. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47816. if (ret != 0)
  47817. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47818. }
  47819. /* generate senderNonce */
  47820. {
  47821. senderNonce[0] = 0x04;
  47822. senderNonce[1] = PKCS7_NONCE_SZ;
  47823. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  47824. if (ret != 0)
  47825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47826. }
  47827. /* generate transactionID (used with SCEP) */
  47828. {
  47829. #ifndef NO_SHA
  47830. wc_Sha sha;
  47831. byte digest[WC_SHA_DIGEST_SIZE];
  47832. #else
  47833. wc_Sha256 sha;
  47834. byte digest[WC_SHA256_DIGEST_SIZE];
  47835. #endif
  47836. int j,k;
  47837. transId[0] = 0x13;
  47838. transId[1] = sizeof(digest) * 2;
  47839. #ifndef NO_SHA
  47840. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  47841. if (ret != 0)
  47842. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47843. wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  47844. wc_ShaFinal(&sha, digest);
  47845. wc_ShaFree(&sha);
  47846. #else
  47847. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  47848. if (ret != 0)
  47849. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47850. wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  47851. wc_Sha256Final(&sha, digest);
  47852. wc_Sha256Free(&sha);
  47853. #endif
  47854. for (j = 0, k = 2; j < (int)sizeof(digest); j++, k += 2) {
  47855. (void)XSNPRINTF((char*)&transId[k], 3, "%02x", digest[j]);
  47856. }
  47857. }
  47858. /* enable detached signature generation, if set */
  47859. if (testVectors[i].detachedSignature == 1) {
  47860. ret = wc_PKCS7_SetDetached(pkcs7, 1);
  47861. if (ret != 0)
  47862. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47863. }
  47864. encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz);
  47865. if (encodedSz < 0)
  47866. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  47867. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47868. /* write PKCS#7 to output file for more testing */
  47869. file = XFOPEN(testVectors[i].outFileName, "wb");
  47870. if (!file) {
  47871. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47872. }
  47873. ret = (int)XFWRITE(out, 1, encodedSz, file);
  47874. XFCLOSE(file);
  47875. if (ret != (int)encodedSz)
  47876. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47877. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47878. wc_PKCS7_Free(pkcs7);
  47879. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47880. if (pkcs7 == NULL)
  47881. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47882. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47883. if (testVectors[i].detachedSignature == 1) {
  47884. /* set content for verifying detached signatures */
  47885. pkcs7->content = (byte*)testVectors[i].content;
  47886. pkcs7->contentSz = testVectors[i].contentSz;
  47887. }
  47888. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  47889. if (ret < 0)
  47890. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47891. /* verify contentType extracted successfully for custom content types */
  47892. if (testVectors[i].contentTypeSz > 0) {
  47893. if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) {
  47894. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47895. } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType,
  47896. pkcs7->contentTypeSz) != 0) {
  47897. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47898. }
  47899. }
  47900. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  47901. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47902. {
  47903. /* check getting signed attributes */
  47904. #ifndef NO_SHA
  47905. byte buf[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47906. #else
  47907. byte buf[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47908. #endif
  47909. const byte* oidPt = transIdOid + 2; /* skip object id tag and size */
  47910. int oidSz = (int)sizeof(transIdOid) - 2;
  47911. int bufSz = 0;
  47912. if (testVectors[i].signedAttribs != NULL) {
  47913. ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  47914. NULL, (word32*)&bufSz);
  47915. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47917. ret = 0;
  47918. }
  47919. if (bufSz > (int)sizeof(buf))
  47920. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47921. bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  47922. buf, (word32*)&bufSz);
  47923. if ((testVectors[i].signedAttribs != NULL && bufSz < 0) ||
  47924. (testVectors[i].signedAttribs == NULL && bufSz > 0))
  47925. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47926. }
  47927. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47928. file = XFOPEN("./pkcs7cert.der", "wb");
  47929. if (!file)
  47930. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47931. ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file);
  47932. if (ret < 0)
  47933. ret = WC_TEST_RET_ENC_ERRNO;
  47934. else
  47935. ret = 0;
  47936. XFCLOSE(file);
  47937. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47938. }
  47939. out:
  47940. if (pkcs7 != NULL)
  47941. wc_PKCS7_Free(pkcs7);
  47942. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47943. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47944. wc_FreeRng(&rng);
  47945. if (ret > 0)
  47946. return 0;
  47947. (void)rsaClientCertBuf;
  47948. (void)rsaClientCertBufSz;
  47949. (void)rsaClientPrivKeyBuf;
  47950. (void)rsaClientPrivKeyBufSz;
  47951. (void)rsaServerCertBuf;
  47952. (void)rsaServerCertBufSz;
  47953. (void)rsaServerPrivKeyBuf;
  47954. (void)rsaServerPrivKeyBufSz;
  47955. (void)rsaCaCertBuf;
  47956. (void)rsaCaCertBufSz;
  47957. (void)rsaCaPrivKeyBuf;
  47958. (void)rsaCaPrivKeyBufSz;
  47959. (void)eccClientCertBuf;
  47960. (void)eccClientCertBufSz;
  47961. (void)eccClientPrivKeyBuf;
  47962. (void)eccClientPrivKeyBufSz;
  47963. return ret;
  47964. }
  47965. static wc_test_ret_t pkcs7signed_run_SingleShotVectors(
  47966. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47967. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47968. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47969. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47970. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47971. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47972. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47973. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47974. {
  47975. wc_test_ret_t ret;
  47976. int testSz = 0, i;
  47977. int encodedSz;
  47978. byte* out = NULL;
  47979. word32 outSz;
  47980. WC_RNG rng;
  47981. wc_PKCS7* pkcs7 = NULL;
  47982. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47983. XFILE file;
  47984. #endif
  47985. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  47986. !defined(NO_PKCS7_ENCRYPTED_DATA)
  47987. byte* encryptedTmp = NULL;
  47988. int encryptedTmpSz;
  47989. #endif
  47990. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47991. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47992. 0x72,0x6c,0x64
  47993. };
  47994. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  47995. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  47996. static const byte aes256Key[] = {
  47997. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47998. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47999. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48000. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  48001. };
  48002. #endif
  48003. static const byte messageTypeOid[] =
  48004. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  48005. 0x09, 0x02 };
  48006. static const byte messageType[] = { 0x13, 2, '1', '9' };
  48007. PKCS7Attrib attribs[] =
  48008. {
  48009. { messageTypeOid, sizeof(messageTypeOid), messageType,
  48010. sizeof(messageType) },
  48011. };
  48012. #define MAX_TESTVECTORS_LEN 19
  48013. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  48014. pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  48015. if (testSz == MAX_TESTVECTORS_LEN) { \
  48016. ret = WC_TEST_RET_ENC_NC; \
  48017. goto out; \
  48018. } \
  48019. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  48020. sizeof _this_vector); \
  48021. }
  48022. pkcs7SignedVector *testVectors = NULL;
  48023. XMEMSET(&rng, 0, sizeof(rng));
  48024. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  48025. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48026. if (testVectors == NULL) {
  48027. ret = WC_TEST_RET_ENC_ERRNO;
  48028. goto out;
  48029. }
  48030. {
  48031. #ifndef NO_RSA
  48032. #ifndef NO_SHA256
  48033. /* Signed FirmwarePkgData, RSA, SHA256, no attribs */
  48034. ADD_PKCS7SIGNEDVECTOR(
  48035. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48036. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48037. NULL, 0,
  48038. "pkcs7signedFirmwarePkgData_RSA_SHA256_noattr.der", 0, NULL, 0, 0,
  48039. 0, 0, NULL, 0, NULL, 0, 0);
  48040. /* Signed FirmwarePkgData, RSA, SHA256, attrs */
  48041. ADD_PKCS7SIGNEDVECTOR(
  48042. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48043. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48044. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48045. "pkcs7signedFirmwarePkgData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0,
  48046. NULL, 0, NULL, 0, 0);
  48047. /* Signed FirmwarePkgData, RSA, SHA256, SubjectKeyIdentifier, attrs */
  48048. ADD_PKCS7SIGNEDVECTOR(
  48049. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48050. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48051. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48052. "pkcs7signedFirmwarePkgData_RSA_SHA256_SKID.der", 0, NULL,
  48053. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48054. /* Signed FirmwraePkgData, RSA, SHA256, server cert and ca cert, attr */
  48055. ADD_PKCS7SIGNEDVECTOR(
  48056. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48057. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48058. rsaCaCertBuf, rsaCaCertBufSz,
  48059. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48060. "pkcs7signedFirmwarePkgData_RSA_SHA256_with_ca_cert.der", 0, NULL,
  48061. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48062. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48063. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48064. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, no attribs */
  48065. ADD_PKCS7SIGNEDVECTOR(
  48066. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48067. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48068. NULL, 0,
  48069. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48070. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48071. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, attribs */
  48072. ADD_PKCS7SIGNEDVECTOR(
  48073. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48074. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48075. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48076. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256.der", 0,
  48077. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48078. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48079. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48080. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48081. /* Signed Compressed FirmwarePkgData, RSA, SHA256, no attribs */
  48082. ADD_PKCS7SIGNEDVECTOR(
  48083. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48084. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48085. NULL, 0,
  48086. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48087. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48088. /* Signed Compressed FirmwarePkgData, RSA, SHA256, attribs */
  48089. ADD_PKCS7SIGNEDVECTOR(
  48090. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48091. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48092. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48093. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256.der", 0,
  48094. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48095. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48096. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48097. no attribs */
  48098. ADD_PKCS7SIGNEDVECTOR(
  48099. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48100. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48101. NULL, 0,
  48102. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der",
  48103. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48104. 0, 0);
  48105. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48106. attribs */
  48107. ADD_PKCS7SIGNEDVECTOR(
  48108. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48109. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48110. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48111. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der",
  48112. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48113. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48114. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48115. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48116. #endif /* NO_SHA256 */
  48117. #endif /* NO_RSA */
  48118. #ifdef HAVE_ECC
  48119. #ifndef NO_SHA256
  48120. /* Signed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48121. ADD_PKCS7SIGNEDVECTOR(
  48122. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48123. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48124. NULL, 0,
  48125. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48126. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48127. /* Signed FirmwarePkgData, ECDSA, SHA256, attribs */
  48128. ADD_PKCS7SIGNEDVECTOR(
  48129. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48130. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48131. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48132. "pkcs7signedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48133. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48134. /* Signed FirmwarePkgData, ECDSA, SHA256, SubjectKeyIdentifier, attr */
  48135. ADD_PKCS7SIGNEDVECTOR(
  48136. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48137. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48138. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48139. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_SKID.der", 0, NULL,
  48140. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48141. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48142. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48143. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, no attribs */
  48144. ADD_PKCS7SIGNEDVECTOR(
  48145. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48146. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48147. NULL, 0,
  48148. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48149. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48150. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, attribs */
  48151. ADD_PKCS7SIGNEDVECTOR(
  48152. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48153. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48154. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48155. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48156. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48157. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48158. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48159. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48160. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48161. ADD_PKCS7SIGNEDVECTOR(
  48162. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48163. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48164. NULL, 0,
  48165. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48166. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48167. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, attrib */
  48168. ADD_PKCS7SIGNEDVECTOR(
  48169. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48170. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48171. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48172. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48173. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48174. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48175. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48176. no attribs */
  48177. ADD_PKCS7SIGNEDVECTOR(
  48178. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48179. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48180. NULL, 0,
  48181. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der",
  48182. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48183. 0, 0);
  48184. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48185. attribs */
  48186. ADD_PKCS7SIGNEDVECTOR(
  48187. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48188. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48189. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48190. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der",
  48191. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48192. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48193. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48194. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48195. #endif /* NO_SHA256 */
  48196. #endif /* HAVE_ECC */
  48197. };
  48198. #undef MAX_TESTVECTORS_LEN
  48199. #undef ADD_PKCS7SIGNEDVECTOR
  48200. outSz = FOURK_BUF;
  48201. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48202. if (out == NULL)
  48203. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48204. XMEMSET(out, 0, outSz);
  48205. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48206. if (ret < 0)
  48207. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48208. #ifndef HAVE_FIPS
  48209. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48210. #else
  48211. ret = wc_InitRng(&rng);
  48212. #endif
  48213. if (ret != 0)
  48214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48215. for (i = 0; i < testSz; i++) {
  48216. if (pkcs7)
  48217. wc_PKCS7_Free(pkcs7);
  48218. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48219. if (pkcs7 == NULL)
  48220. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48221. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48222. (word32)testVectors[i].certSz);
  48223. if (ret != 0)
  48224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48225. /* load CA certificate, if present */
  48226. if (testVectors[i].caCert != NULL) {
  48227. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48228. (word32)testVectors[i].caCertSz);
  48229. if (ret != 0)
  48230. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48231. }
  48232. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48233. default is IssuerAndSerialNumber */
  48234. if (testVectors[i].sidType == CMS_SKID) {
  48235. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48236. if (ret != 0)
  48237. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48238. }
  48239. if (testVectors[i].encCompFlag == 0) {
  48240. /* encode Signed FirmwarePkgData */
  48241. encodedSz = wc_PKCS7_EncodeSignedFPD(pkcs7,
  48242. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48243. testVectors[i].signOID, testVectors[i].hashOID,
  48244. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48245. testVectors[i].signedAttribs,
  48246. testVectors[i].signedAttribsSz, out, outSz);
  48247. if (encodedSz < 0)
  48248. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48249. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48250. } else if (testVectors[i].encCompFlag == 1) {
  48251. /* encode Signed Encrypted FirmwarePkgData */
  48252. encodedSz = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7,
  48253. (byte *)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48254. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48255. testVectors[i].encryptOID, testVectors[i].signOID,
  48256. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48257. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48258. testVectors[i].unprotectedAttribsSz,
  48259. testVectors[i].signedAttribs,
  48260. testVectors[i].signedAttribsSz, out, outSz);
  48261. if (encodedSz <= 0)
  48262. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48263. #endif
  48264. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48265. } else if (testVectors[i].encCompFlag == 2) {
  48266. /* encode Signed Compressed FirmwarePkgData */
  48267. encodedSz = wc_PKCS7_EncodeSignedCompressedFPD(pkcs7,
  48268. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48269. testVectors[i].signOID, testVectors[i].hashOID,
  48270. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48271. testVectors[i].signedAttribs,
  48272. testVectors[i].signedAttribsSz, out, outSz);
  48273. if (encodedSz <= 0)
  48274. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48275. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48276. } else if (testVectors[i].encCompFlag == 3) {
  48277. /* encode Signed Encrypted Compressed FirmwarePkgData */
  48278. encodedSz = wc_PKCS7_EncodeSignedEncryptedCompressedFPD(pkcs7,
  48279. (byte*)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48280. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48281. testVectors[i].encryptOID, testVectors[i].signOID,
  48282. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48283. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48284. testVectors[i].unprotectedAttribsSz,
  48285. testVectors[i].signedAttribs,
  48286. testVectors[i].signedAttribsSz, out, outSz);
  48287. if (encodedSz <= 0)
  48288. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48289. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48290. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48291. } else {
  48292. /* unsupported SignedData single-shot combination */
  48293. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48294. }
  48295. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48296. /* write PKCS#7 to output file for more testing */
  48297. file = XFOPEN(testVectors[i].outFileName, "wb");
  48298. if (!file)
  48299. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48300. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48301. XFCLOSE(file);
  48302. file = NULL;
  48303. if (ret != (int)encodedSz)
  48304. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48305. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48306. wc_PKCS7_Free(pkcs7);
  48307. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48308. if (pkcs7 == NULL)
  48309. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48310. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48311. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48312. if (ret < 0)
  48313. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48314. #ifndef NO_PKCS7_STREAM
  48315. {
  48316. word32 z;
  48317. for (z = 0; z < outSz && ret != 0; z++) {
  48318. ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1);
  48319. if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  48320. printf("unexpected error %d\n", ret);
  48321. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48322. }
  48323. }
  48324. }
  48325. #endif
  48326. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48327. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48328. if (testVectors[i].encCompFlag == 0) {
  48329. /* verify decoded content matches expected */
  48330. if ((pkcs7->contentSz != testVectors[i].contentSz) ||
  48331. XMEMCMP(pkcs7->content, testVectors[i].content,
  48332. pkcs7->contentSz)) {
  48333. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48334. }
  48335. }
  48336. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48337. else if (testVectors[i].encCompFlag == 1) {
  48338. /* decrypt inner encryptedData */
  48339. pkcs7->encryptionKey = (byte *)testVectors[i].encryptKey;
  48340. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48341. ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48342. pkcs7->contentSz, out, outSz);
  48343. if (ret < 0)
  48344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48345. /* compare decrypted to expected */
  48346. if (((word32)ret != testVectors[i].contentSz) ||
  48347. XMEMCMP(out, testVectors[i].content, ret))
  48348. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48349. }
  48350. #endif
  48351. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48352. else if (testVectors[i].encCompFlag == 2) {
  48353. /* decompress inner compressedData */
  48354. ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content,
  48355. pkcs7->contentSz, out, outSz);
  48356. if (ret < 0)
  48357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48358. /* compare decompressed to expected */
  48359. if (((word32)ret != testVectors[i].contentSz) ||
  48360. XMEMCMP(out, testVectors[i].content, ret))
  48361. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48362. }
  48363. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48364. else if (testVectors[i].encCompFlag == 3) {
  48365. encryptedTmpSz = FOURK_BUF;
  48366. encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT,
  48367. DYNAMIC_TYPE_TMP_BUFFER);
  48368. if (encryptedTmp == NULL)
  48369. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48370. XMEMSET(encryptedTmp, 0, encryptedTmpSz);
  48371. /* decrypt inner encryptedData */
  48372. pkcs7->encryptionKey = (byte*)testVectors[i].encryptKey;
  48373. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48374. encryptedTmpSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48375. pkcs7->contentSz, encryptedTmp,
  48376. encryptedTmpSz);
  48377. if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA)
  48378. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48379. /* decompress inner compressedData */
  48380. ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp,
  48381. encryptedTmpSz, out, outSz);
  48382. if (ret < 0)
  48383. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48384. /* compare decompressed to expected */
  48385. if (((word32)ret != testVectors[i].contentSz) ||
  48386. XMEMCMP(out, testVectors[i].content, ret))
  48387. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48388. }
  48389. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48390. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48391. }
  48392. out:
  48393. if (pkcs7 != NULL)
  48394. wc_PKCS7_Free(pkcs7);
  48395. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48396. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48397. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48398. XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48399. #endif
  48400. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48401. wc_FreeRng(&rng);
  48402. if (ret > 0)
  48403. return 0;
  48404. (void)eccClientCertBuf;
  48405. (void)eccClientCertBufSz;
  48406. (void)eccClientPrivKeyBuf;
  48407. (void)eccClientPrivKeyBufSz;
  48408. (void)rsaClientCertBuf;
  48409. (void)rsaClientCertBufSz;
  48410. (void)rsaClientPrivKeyBuf;
  48411. (void)rsaClientPrivKeyBufSz;
  48412. (void)rsaServerCertBuf;
  48413. (void)rsaServerCertBufSz;
  48414. (void)rsaServerPrivKeyBuf;
  48415. (void)rsaServerPrivKeyBufSz;
  48416. (void)rsaCaCertBuf;
  48417. (void)rsaCaCertBufSz;
  48418. (void)rsaCaPrivKeyBuf;
  48419. (void)rsaCaPrivKeyBufSz;
  48420. return ret;
  48421. }
  48422. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void)
  48423. {
  48424. wc_test_ret_t ret = 0;
  48425. byte* rsaClientCertBuf = NULL;
  48426. byte* rsaServerCertBuf = NULL;
  48427. byte* rsaCaCertBuf = NULL;
  48428. byte* eccClientCertBuf = NULL;
  48429. byte* rsaClientPrivKeyBuf = NULL;
  48430. byte* rsaServerPrivKeyBuf = NULL;
  48431. byte* rsaCaPrivKeyBuf = NULL;
  48432. byte* eccClientPrivKeyBuf = NULL;
  48433. word32 rsaClientCertBufSz = 0;
  48434. word32 rsaServerCertBufSz = 0;
  48435. word32 rsaCaCertBufSz = 0;
  48436. word32 eccClientCertBufSz = 0;
  48437. word32 rsaClientPrivKeyBufSz = 0;
  48438. word32 rsaServerPrivKeyBufSz = 0;
  48439. word32 rsaCaPrivKeyBufSz = 0;
  48440. word32 eccClientPrivKeyBufSz = 0;
  48441. WOLFSSL_ENTER("pkcs7signed_test");
  48442. #ifndef NO_RSA
  48443. /* read client RSA cert and key in DER format */
  48444. rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48445. DYNAMIC_TYPE_TMP_BUFFER);
  48446. if (rsaClientCertBuf == NULL)
  48447. ret = WC_TEST_RET_ENC_NC;
  48448. rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48449. DYNAMIC_TYPE_TMP_BUFFER);
  48450. if (ret == 0 && rsaClientPrivKeyBuf == NULL) {
  48451. ret = WC_TEST_RET_ENC_ERRNO;
  48452. }
  48453. rsaClientCertBufSz = FOURK_BUF;
  48454. rsaClientPrivKeyBufSz = FOURK_BUF;
  48455. /* read server RSA cert and key in DER format */
  48456. rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48457. DYNAMIC_TYPE_TMP_BUFFER);
  48458. if (ret == 0 && rsaServerCertBuf == NULL)
  48459. ret = WC_TEST_RET_ENC_NC;
  48460. rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48461. DYNAMIC_TYPE_TMP_BUFFER);
  48462. if (ret == 0 && rsaServerPrivKeyBuf == NULL) {
  48463. ret = WC_TEST_RET_ENC_ERRNO;
  48464. }
  48465. rsaServerCertBufSz = FOURK_BUF;
  48466. rsaServerPrivKeyBufSz = FOURK_BUF;
  48467. /* read CA RSA cert and key in DER format, for use with server cert */
  48468. rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48469. DYNAMIC_TYPE_TMP_BUFFER);
  48470. if (ret == 0 && rsaCaCertBuf == NULL)
  48471. ret = WC_TEST_RET_ENC_NC;
  48472. rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48473. DYNAMIC_TYPE_TMP_BUFFER);
  48474. if (ret == 0 && rsaCaPrivKeyBuf == NULL) {
  48475. ret = WC_TEST_RET_ENC_ERRNO;
  48476. }
  48477. rsaCaCertBufSz = FOURK_BUF;
  48478. rsaCaPrivKeyBufSz = FOURK_BUF;
  48479. #endif /* NO_RSA */
  48480. #ifdef HAVE_ECC
  48481. /* read client ECC cert and key in DER format */
  48482. eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48483. DYNAMIC_TYPE_TMP_BUFFER);
  48484. if (ret == 0 && eccClientCertBuf == NULL) {
  48485. ret = WC_TEST_RET_ENC_ERRNO;
  48486. }
  48487. eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48488. DYNAMIC_TYPE_TMP_BUFFER);
  48489. if (ret == 0 && eccClientPrivKeyBuf == NULL) {
  48490. ret = WC_TEST_RET_ENC_ERRNO;
  48491. }
  48492. eccClientCertBufSz = FOURK_BUF;
  48493. eccClientPrivKeyBufSz = FOURK_BUF;
  48494. #endif /* HAVE_ECC */
  48495. if (ret >= 0)
  48496. ret = pkcs7_load_certs_keys(rsaClientCertBuf, &rsaClientCertBufSz,
  48497. rsaClientPrivKeyBuf, &rsaClientPrivKeyBufSz,
  48498. rsaServerCertBuf, &rsaServerCertBufSz,
  48499. rsaServerPrivKeyBuf, &rsaServerPrivKeyBufSz,
  48500. rsaCaCertBuf, &rsaCaCertBufSz,
  48501. rsaCaPrivKeyBuf, &rsaCaPrivKeyBufSz,
  48502. eccClientCertBuf, &eccClientCertBufSz,
  48503. eccClientPrivKeyBuf, &eccClientPrivKeyBufSz);
  48504. if (ret < 0) {
  48505. ret = WC_TEST_RET_ENC_EC(ret);
  48506. }
  48507. if (ret >= 0)
  48508. ret = pkcs7signed_run_vectors(rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48509. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48510. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48511. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48512. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48513. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48514. eccClientCertBuf, (word32)eccClientCertBufSz,
  48515. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48516. if (ret >= 0)
  48517. ret = pkcs7signed_run_SingleShotVectors(
  48518. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48519. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48520. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48521. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48522. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48523. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48524. eccClientCertBuf, (word32)eccClientCertBufSz,
  48525. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48526. #if !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  48527. if (ret >= 0)
  48528. ret = pkcs7callback_test(
  48529. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48530. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz);
  48531. #endif
  48532. XFREE(rsaClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48533. XFREE(rsaClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48534. XFREE(rsaServerCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48535. XFREE(rsaServerPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48536. XFREE(rsaCaCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48537. XFREE(rsaCaPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48538. XFREE(eccClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48539. XFREE(eccClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48540. return ret;
  48541. }
  48542. #endif /* HAVE_PKCS7 */
  48543. #if defined(WOLFSSL_PUBLIC_MP) && \
  48544. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48545. defined(USE_FAST_MATH))
  48546. /* Maximum number of bytes in a number to test. */
  48547. #define MP_MAX_TEST_BYTE_LEN 32
  48548. static wc_test_ret_t randNum(mp_int* n, int len, WC_RNG* rng, void* heap)
  48549. {
  48550. byte d[MP_MAX_TEST_BYTE_LEN];
  48551. wc_test_ret_t ret;
  48552. (void)heap;
  48553. do {
  48554. ret = wc_RNG_GenerateBlock(rng, d, (word32)len);
  48555. if (ret != 0)
  48556. return ret;
  48557. ret = mp_read_unsigned_bin(n, d, (word32)len);
  48558. if (ret != 0)
  48559. return ret;
  48560. } while (mp_iszero(n));
  48561. return 0;
  48562. }
  48563. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  48564. static wc_test_ret_t mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng)
  48565. {
  48566. int i, j;
  48567. mp_digit rem;
  48568. mp_digit rem2;
  48569. wc_test_ret_t ret;
  48570. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48571. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48572. for (i = 0; i < 10; i++) {
  48573. for (j = 1; j < 10; j++) {
  48574. ret = randNum(a, j, rng, NULL);
  48575. if (ret != 0)
  48576. return WC_TEST_RET_ENC_EC(ret);
  48577. ret = mp_div_3(a, r, &rem);
  48578. if (ret != 0)
  48579. return WC_TEST_RET_ENC_EC(ret);
  48580. ret = mp_mul_d(r, 3, r);
  48581. if (ret != 0)
  48582. return WC_TEST_RET_ENC_EC(ret);
  48583. ret = mp_add_d(r, rem, r);
  48584. if (ret != 0)
  48585. return WC_TEST_RET_ENC_EC(ret);
  48586. ret = mp_cmp(r, a);
  48587. if (ret != MP_EQ)
  48588. return WC_TEST_RET_ENC_NC;
  48589. }
  48590. }
  48591. ret = mp_div_3(a, r, &rem);
  48592. if (ret != 0)
  48593. return WC_TEST_RET_ENC_NC;
  48594. ret = mp_div_3(a, a, NULL);
  48595. if (ret != 0)
  48596. return WC_TEST_RET_ENC_NC;
  48597. ret = mp_cmp(r, a);
  48598. if (ret != MP_EQ)
  48599. return WC_TEST_RET_ENC_NC;
  48600. #endif
  48601. #if defined(WOLFSSL_SP_MATH_ALL)
  48602. ret = mp_div_d(a, 10, r, &rem);
  48603. if (ret != 0)
  48604. return WC_TEST_RET_ENC_EC(ret);
  48605. ret = mp_div_d(a, 10, a, NULL);
  48606. if (ret != 0)
  48607. return WC_TEST_RET_ENC_EC(ret);
  48608. ret = mp_cmp(r, a);
  48609. if (ret != MP_EQ)
  48610. return WC_TEST_RET_ENC_NC;
  48611. ret = mp_div_d(a, 12, r, &rem);
  48612. if (ret != 0)
  48613. return WC_TEST_RET_ENC_EC(ret);
  48614. ret = mp_div_d(a, 12, a, NULL);
  48615. if (ret != 0)
  48616. return WC_TEST_RET_ENC_EC(ret);
  48617. ret = mp_cmp(r, a);
  48618. if (ret != MP_EQ)
  48619. return WC_TEST_RET_ENC_NC;
  48620. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem);
  48621. if (ret != 0)
  48622. return WC_TEST_RET_ENC_EC(ret);
  48623. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2);
  48624. if (ret != 0)
  48625. return WC_TEST_RET_ENC_EC(ret);
  48626. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL);
  48627. if (ret != 0)
  48628. return WC_TEST_RET_ENC_EC(ret);
  48629. ret = mp_cmp(r, a);
  48630. if (ret != MP_EQ)
  48631. return WC_TEST_RET_ENC_NC;
  48632. if (rem != rem2)
  48633. return WC_TEST_RET_ENC_NC;
  48634. #endif
  48635. (void)a;
  48636. (void)r;
  48637. (void)rng;
  48638. (void)i;
  48639. (void)j;
  48640. (void)rem;
  48641. (void)rem2;
  48642. (void)ret;
  48643. return 0;
  48644. }
  48645. #endif /* WOLFSSL_SP_MATH || !USE_FAST_MATH */
  48646. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  48647. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48648. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  48649. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  48650. static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
  48651. {
  48652. wc_test_ret_t ret;
  48653. int i, j;
  48654. int size;
  48655. char str[30];
  48656. WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
  48657. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
  48658. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  48659. WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
  48660. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  48661. for (i = 0; i < 10; i++) {
  48662. for (j = 2; j < 12; j++) {
  48663. ret = randNum(a, j, rng, NULL);
  48664. if (ret != 0)
  48665. return WC_TEST_RET_ENC_EC(ret);
  48666. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  48667. if (ret != MP_OKAY)
  48668. return WC_TEST_RET_ENC_EC(ret);
  48669. ret = mp_toradix(a, str, MP_RADIX_DEC);
  48670. if (ret != MP_OKAY)
  48671. return WC_TEST_RET_ENC_EC(ret);
  48672. if ((int)XSTRLEN(str) != size - 1)
  48673. return WC_TEST_RET_ENC_NC;
  48674. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  48675. if (ret != MP_OKAY)
  48676. return WC_TEST_RET_ENC_EC(ret);
  48677. ret = mp_cmp(a, r);
  48678. if (ret != MP_EQ)
  48679. return WC_TEST_RET_ENC_NC;
  48680. }
  48681. }
  48682. ret = mp_read_radix(r, badStr1, MP_RADIX_DEC);
  48683. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48684. return WC_TEST_RET_ENC_EC(ret);
  48685. ret = mp_read_radix(r, badStr2, MP_RADIX_DEC);
  48686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48687. return WC_TEST_RET_ENC_EC(ret);
  48688. ret = mp_read_radix(r, empty2, MP_RADIX_DEC);
  48689. if (ret != MP_OKAY)
  48690. return WC_TEST_RET_ENC_EC(ret);
  48691. ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
  48692. if (ret != MP_OKAY)
  48693. return WC_TEST_RET_ENC_EC(ret);
  48694. if (!mp_iszero(r))
  48695. return WC_TEST_RET_ENC_NC;
  48696. mp_set(r, 1);
  48697. ret = mp_read_radix(r, empty, MP_RADIX_DEC);
  48698. if (ret != MP_OKAY)
  48699. return WC_TEST_RET_ENC_EC(ret);
  48700. if (!mp_iszero(r))
  48701. return WC_TEST_RET_ENC_NC;
  48702. mp_zero(a);
  48703. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  48704. if (ret != 0)
  48705. return WC_TEST_RET_ENC_EC(ret);
  48706. if (size != 2)
  48707. return WC_TEST_RET_ENC_NC;
  48708. ret = mp_toradix(a, str, MP_RADIX_DEC);
  48709. if (ret != 0)
  48710. return WC_TEST_RET_ENC_EC(ret);
  48711. if ((int)XSTRLEN(str) != size - 1)
  48712. return WC_TEST_RET_ENC_NC;
  48713. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  48714. if (ret != 0)
  48715. return WC_TEST_RET_ENC_EC(ret);
  48716. if (!mp_iszero(r))
  48717. return WC_TEST_RET_ENC_NC;
  48718. return 0;
  48719. }
  48720. #endif
  48721. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  48722. defined(HAVE_ECC))
  48723. static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
  48724. {
  48725. wc_test_ret_t ret;
  48726. int i, j;
  48727. int size;
  48728. char str[30];
  48729. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  48730. static char longStr[2 * sizeof(a->dp) + 2];
  48731. #endif
  48732. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  48733. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
  48734. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  48735. for (i = 0; i < 10; i++) {
  48736. for (j = 2; j < 12; j++) {
  48737. ret = randNum(a, j, rng, NULL);
  48738. if (ret != 0)
  48739. return WC_TEST_RET_ENC_EC(ret);
  48740. mp_radix_size(a, MP_RADIX_HEX, &size);
  48741. mp_toradix(a, str, MP_RADIX_HEX);
  48742. if ((int)XSTRLEN(str) != size - 1)
  48743. return WC_TEST_RET_ENC_NC;
  48744. mp_read_radix(r, str, MP_RADIX_HEX);
  48745. ret = mp_cmp(a, r);
  48746. if (ret != MP_EQ)
  48747. return WC_TEST_RET_ENC_NC;
  48748. }
  48749. }
  48750. ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
  48751. if (ret != MP_OKAY)
  48752. return WC_TEST_RET_ENC_EC(ret);
  48753. ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
  48754. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48755. return WC_TEST_RET_ENC_EC(ret);
  48756. mp_set(r, 1);
  48757. ret = mp_read_radix(r, empty, MP_RADIX_HEX);
  48758. if (ret != MP_OKAY)
  48759. return WC_TEST_RET_ENC_EC(ret);
  48760. if (!mp_iszero(r))
  48761. return WC_TEST_RET_ENC_NC;
  48762. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  48763. /* Fixed MP data size - string can be too long. */
  48764. longStr[0] = '8';
  48765. XMEMSET(longStr+1, '0', sizeof(longStr) - 2);
  48766. longStr[sizeof(longStr)-1] = '\0';
  48767. ret = mp_read_radix(r, longStr, MP_RADIX_HEX);
  48768. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48769. return WC_TEST_RET_ENC_EC(ret);
  48770. #endif
  48771. mp_zero(a);
  48772. ret = mp_radix_size(a, MP_RADIX_HEX, &size);
  48773. if (ret != 0)
  48774. return WC_TEST_RET_ENC_EC(ret);
  48775. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  48776. if (size != 3)
  48777. #else
  48778. if (size != 2)
  48779. #endif
  48780. return WC_TEST_RET_ENC_NC;
  48781. ret = mp_toradix(a, str, MP_RADIX_HEX);
  48782. if (ret != 0)
  48783. return WC_TEST_RET_ENC_EC(ret);
  48784. if ((int)XSTRLEN(str) != size - 1)
  48785. return WC_TEST_RET_ENC_NC;
  48786. ret = mp_read_radix(r, str, MP_RADIX_HEX);
  48787. if (ret != 0)
  48788. return WC_TEST_RET_ENC_EC(ret);
  48789. if (!mp_iszero(r))
  48790. return WC_TEST_RET_ENC_NC;
  48791. #ifdef WOLFSSL_SP_MATH
  48792. ret = mp_toradix(a, str, 8);
  48793. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48794. return WC_TEST_RET_ENC_EC(ret);
  48795. ret = mp_radix_size(a, 8, &size);
  48796. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48797. return WC_TEST_RET_ENC_EC(ret);
  48798. #endif
  48799. return 0;
  48800. }
  48801. #endif
  48802. static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
  48803. {
  48804. int i;
  48805. wc_test_ret_t ret;
  48806. ret = randNum(a, 4, rng, NULL);
  48807. if (ret != 0)
  48808. return WC_TEST_RET_ENC_EC(ret);
  48809. for (i = 0; i < 4; i++) {
  48810. mp_copy(r1, a);
  48811. ret = mp_lshd(r1, i);
  48812. if (ret != MP_OKAY)
  48813. return WC_TEST_RET_ENC_EC(ret);
  48814. #ifndef WOLFSSL_SP_MATH
  48815. mp_rshd(r1, i);
  48816. #else
  48817. mp_rshb(r1, i * SP_WORD_SIZE);
  48818. #endif
  48819. ret = mp_cmp(a, r1);
  48820. if (ret != MP_EQ)
  48821. return WC_TEST_RET_ENC_NC;
  48822. }
  48823. #ifndef WOLFSSL_SP_MATH
  48824. for (i = 0; i < DIGIT_BIT+1; i++) {
  48825. ret = mp_mul_2d(a, i, r1);
  48826. if (ret != MP_OKAY)
  48827. return WC_TEST_RET_ENC_EC(ret);
  48828. mp_rshb(r1, i);
  48829. ret = mp_cmp(a, r1);
  48830. if (ret != MP_EQ)
  48831. return WC_TEST_RET_ENC_NC;
  48832. }
  48833. #endif
  48834. return 0;
  48835. }
  48836. static wc_test_ret_t mp_test_add_sub_d(mp_int* a, mp_int* r1)
  48837. {
  48838. int i, j;
  48839. wc_test_ret_t ret;
  48840. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  48841. mp_zero(a);
  48842. mp_set_bit(a, i);
  48843. if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT)
  48844. return WC_TEST_RET_ENC_NC;
  48845. for (j = 0; j < i && j < DIGIT_BIT; j++) {
  48846. mp_zero(r1);
  48847. mp_set_bit(r1, i);
  48848. ret = mp_sub_d(r1, (mp_digit)1 << j, r1);
  48849. if (ret != MP_OKAY)
  48850. return WC_TEST_RET_ENC_EC(ret);
  48851. ret = mp_add_d(r1, (mp_digit)1 << j, r1);
  48852. if (ret != MP_OKAY)
  48853. return WC_TEST_RET_ENC_EC(ret);
  48854. ret = mp_cmp(a, r1);
  48855. if (ret != MP_EQ)
  48856. return WC_TEST_RET_ENC_NC;
  48857. }
  48858. }
  48859. mp_zero(r1);
  48860. ret = mp_add_d(r1, 1, r1);
  48861. if (ret != MP_OKAY)
  48862. return WC_TEST_RET_ENC_EC(ret);
  48863. if (r1->used != 1)
  48864. return WC_TEST_RET_ENC_NC;
  48865. ret = mp_sub_d(r1, 1, r1);
  48866. if (ret != MP_OKAY)
  48867. return WC_TEST_RET_ENC_EC(ret);
  48868. if (r1->used != 0)
  48869. return WC_TEST_RET_ENC_NC;
  48870. return 0;
  48871. }
  48872. static wc_test_ret_t mp_test_read_to_bin(mp_int* a)
  48873. {
  48874. WOLFSSL_SMALL_STACK_STATIC const byte in[16] = {
  48875. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7, 0x08,
  48876. 0x93, 0xa4, 0xb4, 0xc5, 0xd6, 0xe7, 0xf8, 0x09
  48877. };
  48878. byte out[24];
  48879. int i, j, k;
  48880. const byte* p;
  48881. wc_test_ret_t ret;
  48882. for (i = 0; i < (int)sizeof(in); i++) {
  48883. p = in + sizeof(in) - i;
  48884. ret = mp_read_unsigned_bin(a, p, (word32)i);
  48885. if (ret != 0)
  48886. return WC_TEST_RET_ENC_EC(ret);
  48887. for (j = i; j < (int)sizeof(out); j++) {
  48888. XMEMSET(out, 0xff, sizeof(out));
  48889. ret = mp_to_unsigned_bin_len(a, out, j);
  48890. if (ret != 0)
  48891. return WC_TEST_RET_ENC_EC(ret);
  48892. for (k = 0; k < j - i; k++) {
  48893. if (out[k] != 0)
  48894. return WC_TEST_RET_ENC_NC;
  48895. }
  48896. for (; k < j; k++) {
  48897. if (out[k] != p[k - (j - i)])
  48898. return WC_TEST_RET_ENC_NC;
  48899. }
  48900. }
  48901. }
  48902. /* Length too small. */
  48903. ret = mp_to_unsigned_bin_len(a, out, 1);
  48904. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48905. return WC_TEST_RET_ENC_EC(ret);
  48906. ret = mp_read_unsigned_bin(a, NULL, 0);
  48907. if (ret != 0)
  48908. return WC_TEST_RET_ENC_EC(ret);
  48909. if (!mp_iszero(a))
  48910. return WC_TEST_RET_ENC_NC;
  48911. return 0;
  48912. }
  48913. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  48914. static wc_test_ret_t mp_test_set_int(mp_int* a)
  48915. {
  48916. #if SP_ULONG_BITS == 64
  48917. unsigned long n = 0xfedcba9876543210UL;
  48918. byte exp[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
  48919. byte out[8] = { 0 };
  48920. #elif SP_ULONG_BITS == 32
  48921. unsigned long n = 0xfedcba98UL;
  48922. byte exp[4] = { 0xfe, 0xdc, 0xba, 0x98 };
  48923. byte out[4] = { 0 };
  48924. #elif SP_ULONG_BITS == 16
  48925. unsigned long n = 0xfedc;
  48926. byte exp[2] = { 0xfe, 0xdc };
  48927. byte out[2] = { 0 };
  48928. #elif SP_ULONG_BITS == 8
  48929. unsigned long n = 0xfe;
  48930. byte exp[1] = { 0xfe };
  48931. byte out[1] = { 0 };
  48932. #endif
  48933. wc_test_ret_t ret;
  48934. ret = mp_set_int(a, n);
  48935. if (ret != 0)
  48936. return WC_TEST_RET_ENC_EC(ret);
  48937. ret = mp_unsigned_bin_size(a);
  48938. if (ret != sizeof(exp))
  48939. return WC_TEST_RET_ENC_NC;
  48940. ret = mp_to_unsigned_bin(a, out);
  48941. if (ret != 0)
  48942. return WC_TEST_RET_ENC_EC(ret);
  48943. if (XMEMCMP(exp, out, sizeof(exp)) != 0)
  48944. return WC_TEST_RET_ENC_NC;
  48945. return 0;
  48946. }
  48947. #endif
  48948. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  48949. static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
  48950. {
  48951. byte buffer[16];
  48952. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  48953. char hexStr[] = "abcdef0123456789";
  48954. #ifndef WOLFSSL_SP_INT_NEGATIVE
  48955. char negStr[] = "-1234";
  48956. #endif
  48957. #endif
  48958. #if !defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
  48959. defined(HAVE_COMP_KEY)
  48960. char decStr[] = "0987654321";
  48961. #endif
  48962. wc_test_ret_t ret;
  48963. #ifdef WOLFSSL_SP_MATH_ALL
  48964. mp_digit rho;
  48965. int size;
  48966. #endif
  48967. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  48968. int result;
  48969. #endif
  48970. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  48971. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  48972. mp_digit rd;
  48973. #endif
  48974. (void)rng;
  48975. (void)r;
  48976. ret = mp_init(NULL);
  48977. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48978. return WC_TEST_RET_ENC_EC(ret);
  48979. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  48980. ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL);
  48981. if (ret != MP_OKAY)
  48982. return WC_TEST_RET_ENC_EC(ret);
  48983. #endif
  48984. mp_free(NULL);
  48985. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  48986. ret = mp_grow(NULL, 1);
  48987. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48988. return WC_TEST_RET_ENC_EC(ret);
  48989. #ifdef WOLFSSL_SP_MATH
  48990. ret = mp_grow(a, SP_INT_DIGITS + 1);
  48991. if (ret != WC_NO_ERR_TRACE(MP_MEM))
  48992. return WC_TEST_RET_ENC_EC(ret);
  48993. #endif
  48994. #endif
  48995. mp_clear(NULL);
  48996. ret = mp_abs(NULL, NULL);
  48997. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  48998. return WC_TEST_RET_ENC_EC(ret);
  48999. ret = mp_abs(a, NULL);
  49000. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49001. return WC_TEST_RET_ENC_EC(ret);
  49002. ret = mp_abs(NULL, b);
  49003. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49004. return WC_TEST_RET_ENC_EC(ret);
  49005. ret = mp_unsigned_bin_size(NULL);
  49006. if (ret != 0)
  49007. return WC_TEST_RET_ENC_EC(ret);
  49008. /* clear buffer to avoid provoking uninitvar errors. */
  49009. XMEMSET(buffer, 0, sizeof(buffer));
  49010. ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer));
  49011. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49012. return WC_TEST_RET_ENC_EC(ret);
  49013. ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer));
  49014. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49015. return WC_TEST_RET_ENC_EC(ret);
  49016. ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
  49017. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49018. return WC_TEST_RET_ENC_EC(ret);
  49019. ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
  49020. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49021. return WC_TEST_RET_ENC_EC(ret);
  49022. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49023. ret = mp_read_radix(NULL, NULL, 16);
  49024. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49025. return WC_TEST_RET_ENC_EC(ret);
  49026. ret = mp_read_radix(a, NULL, 16);
  49027. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49028. return WC_TEST_RET_ENC_EC(ret);
  49029. ret = mp_read_radix(NULL, hexStr, 16);
  49030. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49031. return WC_TEST_RET_ENC_EC(ret);
  49032. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49033. ret = mp_read_radix(a, negStr, 16);
  49034. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49035. return WC_TEST_RET_ENC_EC(ret);
  49036. #ifdef WOLFSSL_SP_MATH_ALL
  49037. ret = mp_read_radix(a, negStr, 10);
  49038. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49039. return WC_TEST_RET_ENC_EC(ret);
  49040. #endif /* WOLFSSL_SP_MATH_ALL */
  49041. #endif /* WOLFSSL_SP_INT_NEGATIVE */
  49042. #endif
  49043. #ifndef WOLFSSL_SP_MATH_ALL
  49044. /* Radix 10 only supported with ALL. */
  49045. ret = mp_read_radix(a, decStr, 10);
  49046. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49047. return WC_TEST_RET_ENC_EC(ret);
  49048. #endif
  49049. /* Radix 8 not supported SP_INT. */
  49050. ret = mp_read_radix(a, "0123", 8);
  49051. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49052. return WC_TEST_RET_ENC_EC(ret);
  49053. ret = mp_count_bits(NULL);
  49054. if (ret != 0)
  49055. return WC_TEST_RET_ENC_EC(ret);
  49056. ret = mp_is_bit_set(NULL, 0);
  49057. if (ret != 0)
  49058. return WC_TEST_RET_ENC_EC(ret);
  49059. ret = mp_leading_bit(NULL);
  49060. if (ret != 0)
  49061. return WC_TEST_RET_ENC_EC(ret);
  49062. mp_zero(a);
  49063. ret = mp_leading_bit(a);
  49064. if (ret != 0)
  49065. return WC_TEST_RET_ENC_EC(ret);
  49066. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49067. defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \
  49068. !defined(NO_RSA)
  49069. ret = mp_set_bit(NULL, 1);
  49070. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49071. return WC_TEST_RET_ENC_EC(ret);
  49072. #endif
  49073. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49074. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49075. ret = mp_to_unsigned_bin(NULL, NULL);
  49076. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49077. return WC_TEST_RET_ENC_EC(ret);
  49078. ret = mp_to_unsigned_bin(a, NULL);
  49079. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49080. return WC_TEST_RET_ENC_EC(ret);
  49081. ret = mp_to_unsigned_bin(NULL, buffer);
  49082. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49083. return WC_TEST_RET_ENC_EC(ret);
  49084. #endif
  49085. ret = mp_to_unsigned_bin_len(NULL, NULL, 1);
  49086. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49087. return WC_TEST_RET_ENC_EC(ret);
  49088. ret = mp_to_unsigned_bin_len(a, NULL, 1);
  49089. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49090. return WC_TEST_RET_ENC_EC(ret);
  49091. ret = mp_to_unsigned_bin_len(NULL, buffer, 1);
  49092. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49093. return WC_TEST_RET_ENC_EC(ret);
  49094. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49095. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49096. ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL);
  49097. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49098. return WC_TEST_RET_ENC_EC(ret);
  49099. ret = mp_to_unsigned_bin_at_pos(0, a, NULL);
  49100. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49101. return WC_TEST_RET_ENC_EC(ret);
  49102. ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer);
  49103. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49104. return WC_TEST_RET_ENC_EC(ret);
  49105. ret = mp_to_unsigned_bin_at_pos(0, a, buffer);
  49106. if (ret != MP_OKAY)
  49107. return WC_TEST_RET_ENC_EC(ret);
  49108. #endif
  49109. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49110. ret = mp_copy(NULL, NULL);
  49111. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49112. return WC_TEST_RET_ENC_EC(ret);
  49113. ret = mp_copy(a, NULL);
  49114. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49115. return WC_TEST_RET_ENC_EC(ret);
  49116. ret = mp_copy(NULL, b);
  49117. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49118. return WC_TEST_RET_ENC_EC(ret);
  49119. #endif
  49120. #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH)
  49121. ret = sp_2expt(NULL, 1);
  49122. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49123. return WC_TEST_RET_ENC_EC(ret);
  49124. #endif
  49125. ret = mp_set(NULL, 0);
  49126. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49127. return WC_TEST_RET_ENC_EC(ret);
  49128. ret = mp_cmp_d(NULL, 0);
  49129. if (ret != MP_LT)
  49130. return WC_TEST_RET_ENC_EC(ret);
  49131. ret = mp_cmp(NULL, NULL);
  49132. if (ret != MP_EQ)
  49133. return WC_TEST_RET_ENC_NC;
  49134. ret = mp_cmp(a, NULL);
  49135. if (ret != MP_GT)
  49136. return WC_TEST_RET_ENC_NC;
  49137. ret = mp_cmp(NULL, b);
  49138. if (ret != MP_LT)
  49139. return WC_TEST_RET_ENC_NC;
  49140. #ifdef WOLFSSL_SP_MATH_ALL
  49141. mp_rshd(NULL, 1);
  49142. #endif
  49143. mp_zero(NULL);
  49144. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49145. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49146. ret = mp_lshd(NULL, 0);
  49147. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49148. return WC_TEST_RET_ENC_EC(ret);
  49149. ret = mp_lshd(a, SP_INT_DIGITS + 1);
  49150. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49151. return WC_TEST_RET_ENC_EC(ret);
  49152. #endif
  49153. #if defined(WOLFSSL_SP_MATH_ALL)
  49154. ret = mp_div(NULL, NULL, a, b);
  49155. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49156. return WC_TEST_RET_ENC_EC(ret);
  49157. ret = mp_div(a, NULL, a, b);
  49158. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49159. return WC_TEST_RET_ENC_EC(ret);
  49160. ret = mp_div(NULL, b, a, b);
  49161. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49162. return WC_TEST_RET_ENC_EC(ret);
  49163. ret = mp_div(a, b, NULL, NULL);
  49164. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49165. return WC_TEST_RET_ENC_EC(ret);
  49166. #endif
  49167. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49168. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49169. ret = mp_mod(NULL, NULL, NULL);
  49170. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49171. return WC_TEST_RET_ENC_EC(ret);
  49172. ret = mp_mod(a, NULL, NULL);
  49173. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49174. return WC_TEST_RET_ENC_EC(ret);
  49175. ret = mp_mod(NULL, b, NULL);
  49176. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49177. return WC_TEST_RET_ENC_EC(ret);
  49178. ret = mp_mod(NULL, NULL, r);
  49179. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49180. return WC_TEST_RET_ENC_EC(ret);
  49181. ret = mp_mod(a, b, NULL);
  49182. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49183. return WC_TEST_RET_ENC_EC(ret);
  49184. ret = mp_mod(a, NULL, r);
  49185. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49186. return WC_TEST_RET_ENC_EC(ret);
  49187. ret = mp_mod(NULL, b, r);
  49188. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49189. return WC_TEST_RET_ENC_EC(ret);
  49190. #endif
  49191. #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL)
  49192. ret = mp_set_int(NULL, 0);
  49193. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49194. return WC_TEST_RET_ENC_EC(ret);
  49195. #endif
  49196. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  49197. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  49198. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49199. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49200. return WC_TEST_RET_ENC_EC(ret);
  49201. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49202. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49203. return WC_TEST_RET_ENC_EC(ret);
  49204. ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL);
  49205. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49206. return WC_TEST_RET_ENC_EC(ret);
  49207. ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL);
  49208. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49209. return WC_TEST_RET_ENC_EC(ret);
  49210. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49211. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49212. return WC_TEST_RET_ENC_EC(ret);
  49213. ret = mp_exptmod_ex(a, a, 1, a, NULL);
  49214. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49215. return WC_TEST_RET_ENC_EC(ret);
  49216. ret = mp_exptmod_ex(a, a, 1, NULL, a);
  49217. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49218. return WC_TEST_RET_ENC_EC(ret);
  49219. ret = mp_exptmod_ex(a, NULL, 1, a, a);
  49220. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49221. return WC_TEST_RET_ENC_EC(ret);
  49222. ret = mp_exptmod_ex(NULL, a, 1, a, a);
  49223. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49224. return WC_TEST_RET_ENC_EC(ret);
  49225. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49226. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49227. return WC_TEST_RET_ENC_EC(ret);
  49228. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49229. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49230. return WC_TEST_RET_ENC_EC(ret);
  49231. ret = mp_exptmod_nct(NULL, a, NULL, NULL);
  49232. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49233. return WC_TEST_RET_ENC_EC(ret);
  49234. ret = mp_exptmod_nct(NULL, NULL, a, NULL);
  49235. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49236. return WC_TEST_RET_ENC_EC(ret);
  49237. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49238. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49239. return WC_TEST_RET_ENC_EC(ret);
  49240. ret = mp_exptmod_nct(a, a, a, NULL);
  49241. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49242. return WC_TEST_RET_ENC_EC(ret);
  49243. ret = mp_exptmod_nct(a, a, NULL, a);
  49244. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49245. return WC_TEST_RET_ENC_EC(ret);
  49246. ret = mp_exptmod_nct(a, NULL, a, a);
  49247. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49248. return WC_TEST_RET_ENC_EC(ret);
  49249. ret = mp_exptmod_nct(NULL, a, a, a);
  49250. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49251. return WC_TEST_RET_ENC_EC(ret);
  49252. #endif
  49253. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49254. !defined(WC_NO_RNG)
  49255. ret = mp_rand_prime(NULL, 32, NULL, NULL);
  49256. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49257. return WC_TEST_RET_ENC_EC(ret);
  49258. ret = mp_rand_prime(a, 32, NULL, NULL);
  49259. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49260. return WC_TEST_RET_ENC_EC(ret);
  49261. ret = mp_rand_prime(NULL, 32, rng, NULL);
  49262. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49263. return WC_TEST_RET_ENC_EC(ret);
  49264. ret = mp_rand_prime(a, 0, rng, NULL);
  49265. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49266. return WC_TEST_RET_ENC_EC(ret);
  49267. #endif
  49268. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49269. ret = mp_mul(NULL, NULL, NULL);
  49270. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49271. return WC_TEST_RET_ENC_EC(ret);
  49272. ret = mp_mul(a, NULL, NULL);
  49273. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49274. return WC_TEST_RET_ENC_EC(ret);
  49275. ret = mp_mul(NULL, b, NULL);
  49276. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49277. return WC_TEST_RET_ENC_EC(ret);
  49278. ret = mp_mul(NULL, NULL, r);
  49279. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49280. return WC_TEST_RET_ENC_EC(ret);
  49281. ret = mp_mul(a, b, NULL);
  49282. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49283. return WC_TEST_RET_ENC_EC(ret);
  49284. ret = mp_mul(a, NULL, r);
  49285. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49286. return WC_TEST_RET_ENC_EC(ret);
  49287. ret = mp_mul(NULL, b, r);
  49288. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49289. return WC_TEST_RET_ENC_EC(ret);
  49290. #endif
  49291. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49292. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49293. ret = mp_sqr(NULL, NULL);
  49294. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49295. return WC_TEST_RET_ENC_EC(ret);
  49296. ret = mp_sqr(a, NULL);
  49297. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49298. return WC_TEST_RET_ENC_EC(ret);
  49299. ret = mp_sqr(NULL, r);
  49300. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49301. return WC_TEST_RET_ENC_EC(ret);
  49302. #endif
  49303. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49304. ret = mp_sqrmod(NULL, NULL, NULL);
  49305. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49306. return WC_TEST_RET_ENC_EC(ret);
  49307. ret = mp_sqrmod(a, NULL, NULL);
  49308. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49309. return WC_TEST_RET_ENC_EC(ret);
  49310. ret = mp_sqrmod(NULL, a, NULL);
  49311. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49312. return WC_TEST_RET_ENC_EC(ret);
  49313. ret = mp_sqrmod(NULL, NULL, a);
  49314. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49315. return WC_TEST_RET_ENC_EC(ret);
  49316. ret = mp_sqrmod(a, b, NULL);
  49317. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49318. return WC_TEST_RET_ENC_EC(ret);
  49319. ret = mp_sqrmod(a, NULL, b);
  49320. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49321. return WC_TEST_RET_ENC_EC(ret);
  49322. ret = mp_sqrmod(NULL, a, b);
  49323. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49324. return WC_TEST_RET_ENC_EC(ret);
  49325. ret = mp_mulmod(NULL, NULL, NULL, NULL);
  49326. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49327. return WC_TEST_RET_ENC_EC(ret);
  49328. ret = mp_mulmod(a, NULL, NULL, NULL);
  49329. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49330. return WC_TEST_RET_ENC_EC(ret);
  49331. ret = mp_mulmod(NULL, a, NULL, NULL);
  49332. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49333. return WC_TEST_RET_ENC_EC(ret);
  49334. ret = mp_mulmod(NULL, NULL, a, NULL);
  49335. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49336. return WC_TEST_RET_ENC_EC(ret);
  49337. ret = mp_mulmod(NULL, NULL, NULL, a);
  49338. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49339. return WC_TEST_RET_ENC_EC(ret);
  49340. ret = mp_mulmod(a, b, b, NULL);
  49341. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49342. return WC_TEST_RET_ENC_EC(ret);
  49343. ret = mp_mulmod(a, b, NULL, a);
  49344. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49345. return WC_TEST_RET_ENC_EC(ret);
  49346. ret = mp_mulmod(a, NULL, b, a);
  49347. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49348. return WC_TEST_RET_ENC_EC(ret);
  49349. ret = mp_mulmod(NULL, b, b, a);
  49350. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49351. return WC_TEST_RET_ENC_EC(ret);
  49352. #endif
  49353. #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
  49354. !defined(NO_RSA) || !defined(NO_DSA)
  49355. ret = mp_add_d(NULL, 1, NULL);
  49356. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49357. return WC_TEST_RET_ENC_EC(ret);
  49358. ret = mp_add_d(a, 1, NULL);
  49359. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49360. return WC_TEST_RET_ENC_EC(ret);
  49361. ret = mp_add_d(NULL, 1, b);
  49362. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49363. return WC_TEST_RET_ENC_EC(ret);
  49364. #endif
  49365. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49366. !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA)
  49367. ret = mp_sub_d(NULL, 1, NULL);
  49368. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49369. return WC_TEST_RET_ENC_EC(ret);
  49370. ret = mp_sub_d(a, 1, NULL);
  49371. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49372. return WC_TEST_RET_ENC_EC(ret);
  49373. ret = mp_sub_d(NULL, 1, b);
  49374. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49375. return WC_TEST_RET_ENC_EC(ret);
  49376. #endif
  49377. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49378. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49379. ret = mp_div_d(NULL, 0, NULL, NULL);
  49380. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49381. return WC_TEST_RET_ENC_EC(ret);
  49382. ret = mp_div_d(a, 0, NULL, NULL);
  49383. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49384. return WC_TEST_RET_ENC_EC(ret);
  49385. ret = mp_div_d(NULL, 1, NULL, NULL);
  49386. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49387. return WC_TEST_RET_ENC_EC(ret);
  49388. #endif
  49389. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49390. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49391. ret = mp_mod_d(NULL, 0, NULL);
  49392. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49393. return WC_TEST_RET_ENC_EC(ret);
  49394. ret = mp_mod_d(a, 0, NULL);
  49395. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49396. return WC_TEST_RET_ENC_EC(ret);
  49397. ret = mp_mod_d(NULL, 0, &rd);
  49398. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49399. return WC_TEST_RET_ENC_EC(ret);
  49400. #endif
  49401. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  49402. ret = mp_gcd(NULL, NULL, NULL);
  49403. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49404. return WC_TEST_RET_ENC_EC(ret);
  49405. ret = mp_gcd(a, NULL, NULL);
  49406. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49407. return WC_TEST_RET_ENC_EC(ret);
  49408. ret = mp_gcd(NULL, a, NULL);
  49409. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49410. return WC_TEST_RET_ENC_EC(ret);
  49411. ret = mp_gcd(NULL, NULL, a);
  49412. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49413. return WC_TEST_RET_ENC_EC(ret);
  49414. ret = mp_gcd(a, b, NULL);
  49415. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49416. return WC_TEST_RET_ENC_EC(ret);
  49417. ret = mp_gcd(a, NULL, b);
  49418. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49419. return WC_TEST_RET_ENC_EC(ret);
  49420. ret = mp_gcd(NULL, a, b);
  49421. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49422. return WC_TEST_RET_ENC_EC(ret);
  49423. #endif
  49424. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49425. ret = mp_div_2_mod_ct(NULL, NULL, NULL);
  49426. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49427. return WC_TEST_RET_ENC_EC(ret);
  49428. ret = mp_div_2_mod_ct(a, NULL, NULL);
  49429. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49430. return WC_TEST_RET_ENC_EC(ret);
  49431. ret = mp_div_2_mod_ct(NULL, b, NULL);
  49432. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49433. return WC_TEST_RET_ENC_EC(ret);
  49434. ret = mp_div_2_mod_ct(NULL, NULL, a);
  49435. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49436. return WC_TEST_RET_ENC_EC(ret);
  49437. ret = mp_div_2_mod_ct(a, b, NULL);
  49438. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49439. return WC_TEST_RET_ENC_EC(ret);
  49440. ret = mp_div_2_mod_ct(a, b, NULL);
  49441. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49442. return WC_TEST_RET_ENC_EC(ret);
  49443. ret = mp_div_2_mod_ct(NULL, b, a);
  49444. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49445. return WC_TEST_RET_ENC_EC(ret);
  49446. ret = mp_div_2(NULL, NULL);
  49447. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49448. return WC_TEST_RET_ENC_EC(ret);
  49449. ret = mp_div_2(a, NULL);
  49450. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49451. return WC_TEST_RET_ENC_EC(ret);
  49452. ret = mp_div_2(NULL, a);
  49453. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49454. return WC_TEST_RET_ENC_EC(ret);
  49455. #endif
  49456. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49457. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  49458. ret = mp_invmod(NULL, NULL, NULL);
  49459. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49460. return WC_TEST_RET_ENC_EC(ret);
  49461. ret = mp_invmod(a, NULL, NULL);
  49462. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49463. return WC_TEST_RET_ENC_EC(ret);
  49464. ret = mp_invmod(NULL, b, NULL);
  49465. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49466. return WC_TEST_RET_ENC_EC(ret);
  49467. ret = mp_invmod(NULL, NULL, a);
  49468. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49469. return WC_TEST_RET_ENC_EC(ret);
  49470. ret = mp_invmod(a, b, NULL);
  49471. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49472. return WC_TEST_RET_ENC_EC(ret);
  49473. ret = mp_invmod(a, NULL, a);
  49474. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49475. return WC_TEST_RET_ENC_EC(ret);
  49476. ret = mp_invmod(NULL, b, a);
  49477. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49478. return WC_TEST_RET_ENC_EC(ret);
  49479. #endif
  49480. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49481. ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1);
  49482. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49483. return WC_TEST_RET_ENC_EC(ret);
  49484. ret = mp_invmod_mont_ct(a, NULL, NULL, 1);
  49485. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49486. return WC_TEST_RET_ENC_EC(ret);
  49487. ret = mp_invmod_mont_ct(NULL, b, NULL, 1);
  49488. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49489. return WC_TEST_RET_ENC_EC(ret);
  49490. ret = mp_invmod_mont_ct(NULL, NULL, a, 1);
  49491. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49492. return WC_TEST_RET_ENC_EC(ret);
  49493. ret = mp_invmod_mont_ct(a, b, NULL, 1);
  49494. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49495. return WC_TEST_RET_ENC_EC(ret);
  49496. ret = mp_invmod_mont_ct(a, NULL, a, 1);
  49497. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49498. return WC_TEST_RET_ENC_EC(ret);
  49499. ret = mp_invmod_mont_ct(NULL, b, a, 1);
  49500. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49501. return WC_TEST_RET_ENC_EC(ret);
  49502. #endif
  49503. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49504. ret = mp_lcm(NULL, NULL, NULL);
  49505. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49506. return WC_TEST_RET_ENC_EC(ret);
  49507. ret = mp_lcm(a, NULL, NULL);
  49508. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49509. return WC_TEST_RET_ENC_EC(ret);
  49510. ret = mp_lcm(NULL, b, NULL);
  49511. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49512. return WC_TEST_RET_ENC_EC(ret);
  49513. ret = mp_lcm(NULL, NULL, a);
  49514. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49515. return WC_TEST_RET_ENC_EC(ret);
  49516. ret = mp_lcm(a, b, NULL);
  49517. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49518. return WC_TEST_RET_ENC_EC(ret);
  49519. ret = mp_lcm(a, NULL, a);
  49520. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49521. return WC_TEST_RET_ENC_EC(ret);
  49522. ret = mp_lcm(NULL, b, a);
  49523. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49524. return WC_TEST_RET_ENC_EC(ret);
  49525. #endif
  49526. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49527. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49528. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49529. return WC_TEST_RET_ENC_EC(ret);
  49530. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49531. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49532. return WC_TEST_RET_ENC_EC(ret);
  49533. ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL);
  49534. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49535. return WC_TEST_RET_ENC_EC(ret);
  49536. ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL);
  49537. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49538. return WC_TEST_RET_ENC_EC(ret);
  49539. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49540. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49541. return WC_TEST_RET_ENC_EC(ret);
  49542. ret = mp_exptmod_ex(a, b, 1, b, NULL);
  49543. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49544. return WC_TEST_RET_ENC_EC(ret);
  49545. ret = mp_exptmod_ex(a, b, 1, NULL, a);
  49546. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49547. return WC_TEST_RET_ENC_EC(ret);
  49548. ret = mp_exptmod_ex(a, NULL, 1, b, a);
  49549. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49550. return WC_TEST_RET_ENC_EC(ret);
  49551. ret = mp_exptmod_ex(NULL, b, 1, b, a);
  49552. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49553. return WC_TEST_RET_ENC_EC(ret);
  49554. ret = mp_exptmod(NULL, NULL, NULL, NULL);
  49555. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49556. return WC_TEST_RET_ENC_EC(ret);
  49557. ret = mp_exptmod(a, NULL, NULL, NULL);
  49558. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49559. return WC_TEST_RET_ENC_EC(ret);
  49560. ret = mp_exptmod(NULL, b, NULL, NULL);
  49561. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49562. return WC_TEST_RET_ENC_EC(ret);
  49563. ret = mp_exptmod(NULL, NULL, b, NULL);
  49564. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49565. return WC_TEST_RET_ENC_EC(ret);
  49566. ret = mp_exptmod(NULL, NULL, NULL, a);
  49567. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49568. return WC_TEST_RET_ENC_EC(ret);
  49569. ret = mp_exptmod(a, b, b, NULL);
  49570. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49571. return WC_TEST_RET_ENC_EC(ret);
  49572. ret = mp_exptmod(a, b, NULL, a);
  49573. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49574. return WC_TEST_RET_ENC_EC(ret);
  49575. ret = mp_exptmod(a, NULL, b, a);
  49576. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49577. return WC_TEST_RET_ENC_EC(ret);
  49578. ret = mp_exptmod(NULL, b, b, a);
  49579. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49580. return WC_TEST_RET_ENC_EC(ret);
  49581. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49582. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49583. return WC_TEST_RET_ENC_EC(ret);
  49584. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49585. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49586. return WC_TEST_RET_ENC_EC(ret);
  49587. ret = mp_exptmod_nct(NULL, b, NULL, NULL);
  49588. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49589. return WC_TEST_RET_ENC_EC(ret);
  49590. ret = mp_exptmod_nct(NULL, NULL, b, NULL);
  49591. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49592. return WC_TEST_RET_ENC_EC(ret);
  49593. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49594. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49595. return WC_TEST_RET_ENC_EC(ret);
  49596. ret = mp_exptmod_nct(a, b, b, NULL);
  49597. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49598. return WC_TEST_RET_ENC_EC(ret);
  49599. ret = mp_exptmod_nct(a, b, NULL, a);
  49600. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49601. return WC_TEST_RET_ENC_EC(ret);
  49602. ret = mp_exptmod_nct(a, NULL, b, a);
  49603. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49604. return WC_TEST_RET_ENC_EC(ret);
  49605. ret = mp_exptmod_nct(NULL, b, b, a);
  49606. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49607. return WC_TEST_RET_ENC_EC(ret);
  49608. #endif
  49609. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  49610. ret = mp_cnt_lsb(NULL);
  49611. if (ret != 0)
  49612. return WC_TEST_RET_ENC_EC(ret);
  49613. #endif
  49614. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49615. ret = mp_prime_is_prime(NULL, 1, NULL);
  49616. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49617. return WC_TEST_RET_ENC_EC(ret);
  49618. ret = mp_prime_is_prime(a, 1, NULL);
  49619. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49620. return WC_TEST_RET_ENC_EC(ret);
  49621. ret = mp_prime_is_prime(NULL, 1, &result);
  49622. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49623. return WC_TEST_RET_ENC_EC(ret);
  49624. ret = mp_prime_is_prime(a, 0, &result);
  49625. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49626. return WC_TEST_RET_ENC_EC(ret);
  49627. ret = mp_prime_is_prime(a, 1024, &result);
  49628. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49629. return WC_TEST_RET_ENC_EC(ret);
  49630. ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL);
  49631. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49632. return WC_TEST_RET_ENC_EC(ret);
  49633. ret = mp_prime_is_prime_ex(a, 1, NULL, NULL);
  49634. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49635. return WC_TEST_RET_ENC_EC(ret);
  49636. ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL);
  49637. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49638. return WC_TEST_RET_ENC_EC(ret);
  49639. ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng);
  49640. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49641. return WC_TEST_RET_ENC_EC(ret);
  49642. ret = mp_prime_is_prime_ex(a, 1, &result, NULL);
  49643. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49644. return WC_TEST_RET_ENC_EC(ret);
  49645. ret = mp_prime_is_prime_ex(a, 1, NULL, rng);
  49646. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49647. return WC_TEST_RET_ENC_EC(ret);
  49648. ret = mp_prime_is_prime_ex(NULL, 1, &result, rng);
  49649. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49650. return WC_TEST_RET_ENC_EC(ret);
  49651. #endif
  49652. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
  49653. ret = mp_exch(NULL, NULL);
  49654. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49655. return WC_TEST_RET_ENC_EC(ret);
  49656. ret = mp_exch(a, NULL);
  49657. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49658. return WC_TEST_RET_ENC_EC(ret);
  49659. ret = mp_exch(NULL, b);
  49660. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49661. return WC_TEST_RET_ENC_EC(ret);
  49662. #endif
  49663. #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \
  49664. defined(WOLFSSL_SP_MATH_ALL)
  49665. ret = mp_mul_d(NULL, 1, NULL);
  49666. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49667. return WC_TEST_RET_ENC_EC(ret);
  49668. ret = mp_mul_d(a, 1, NULL);
  49669. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49670. return WC_TEST_RET_ENC_EC(ret);
  49671. ret = mp_mul_d(NULL, 1, b);
  49672. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49673. return WC_TEST_RET_ENC_EC(ret);
  49674. #endif
  49675. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49676. ret = mp_add(NULL, NULL, NULL);
  49677. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49678. return WC_TEST_RET_ENC_EC(ret);
  49679. ret = mp_add(a, NULL, NULL);
  49680. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49681. return WC_TEST_RET_ENC_EC(ret);
  49682. ret = mp_add(NULL, b, NULL);
  49683. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49684. return WC_TEST_RET_ENC_EC(ret);
  49685. ret = mp_add(NULL, NULL, r);
  49686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49687. return WC_TEST_RET_ENC_EC(ret);
  49688. ret = mp_add(a, b, NULL);
  49689. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49690. return WC_TEST_RET_ENC_EC(ret);
  49691. ret = mp_add(a, NULL, r);
  49692. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49693. return WC_TEST_RET_ENC_EC(ret);
  49694. ret = mp_add(NULL, b, r);
  49695. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49696. return WC_TEST_RET_ENC_EC(ret);
  49697. #endif
  49698. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49699. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49700. ret = mp_sub(NULL, NULL, NULL);
  49701. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49702. return WC_TEST_RET_ENC_EC(ret);
  49703. ret = mp_sub(a, NULL, NULL);
  49704. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49705. return WC_TEST_RET_ENC_EC(ret);
  49706. ret = mp_sub(NULL, b, NULL);
  49707. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49708. return WC_TEST_RET_ENC_EC(ret);
  49709. ret = mp_sub(NULL, NULL, r);
  49710. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49711. return WC_TEST_RET_ENC_EC(ret);
  49712. ret = mp_sub(a, b, NULL);
  49713. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49714. return WC_TEST_RET_ENC_EC(ret);
  49715. ret = mp_sub(a, NULL, r);
  49716. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49717. return WC_TEST_RET_ENC_EC(ret);
  49718. ret = mp_sub(NULL, b, r);
  49719. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49720. return WC_TEST_RET_ENC_EC(ret);
  49721. #endif
  49722. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
  49723. defined(WOLFSSL_CUSTOM_CURVES))
  49724. ret = mp_addmod(NULL, NULL, NULL, NULL);
  49725. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49726. return WC_TEST_RET_ENC_EC(ret);
  49727. ret = mp_addmod(a, NULL, NULL, NULL);
  49728. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49729. return WC_TEST_RET_ENC_EC(ret);
  49730. ret = mp_addmod(NULL, b, NULL, NULL);
  49731. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49732. return WC_TEST_RET_ENC_EC(ret);
  49733. ret = mp_addmod(NULL, NULL, b, NULL);
  49734. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49735. return WC_TEST_RET_ENC_EC(ret);
  49736. ret = mp_addmod(NULL, NULL, NULL, a);
  49737. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49738. return WC_TEST_RET_ENC_EC(ret);
  49739. ret = mp_addmod(a, b, b, NULL);
  49740. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49741. return WC_TEST_RET_ENC_EC(ret);
  49742. ret = mp_addmod(a, b, NULL, a);
  49743. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49744. return WC_TEST_RET_ENC_EC(ret);
  49745. ret = mp_addmod(a, NULL, b, a);
  49746. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49747. return WC_TEST_RET_ENC_EC(ret);
  49748. ret = mp_addmod(NULL, b, b, a);
  49749. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49750. return WC_TEST_RET_ENC_EC(ret);
  49751. #endif
  49752. #ifdef WOLFSSL_SP_MATH_ALL
  49753. ret = mp_submod(NULL, NULL, NULL, NULL);
  49754. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49755. return WC_TEST_RET_ENC_EC(ret);
  49756. ret = mp_submod(a, NULL, NULL, NULL);
  49757. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49758. return WC_TEST_RET_ENC_EC(ret);
  49759. ret = mp_submod(NULL, b, NULL, NULL);
  49760. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49761. return WC_TEST_RET_ENC_EC(ret);
  49762. ret = mp_submod(NULL, NULL, b, NULL);
  49763. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49764. return WC_TEST_RET_ENC_EC(ret);
  49765. ret = mp_submod(NULL, NULL, NULL, a);
  49766. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49767. return WC_TEST_RET_ENC_EC(ret);
  49768. ret = mp_submod(a, b, b, NULL);
  49769. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49770. return WC_TEST_RET_ENC_EC(ret);
  49771. ret = mp_submod(a, b, NULL, a);
  49772. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49773. return WC_TEST_RET_ENC_EC(ret);
  49774. ret = mp_submod(a, NULL, b, a);
  49775. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49776. return WC_TEST_RET_ENC_EC(ret);
  49777. ret = mp_submod(NULL, b, b, a);
  49778. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49779. return WC_TEST_RET_ENC_EC(ret);
  49780. #endif
  49781. #ifdef WOLFSSL_SP_MATH_ALL
  49782. ret = mp_div_2d(NULL, 1, a, b);
  49783. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49784. return WC_TEST_RET_ENC_EC(ret);
  49785. ret = mp_mod_2d(NULL, 1, NULL);
  49786. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49787. return WC_TEST_RET_ENC_EC(ret);
  49788. ret = mp_mod_2d(a, 1, NULL);
  49789. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49790. return WC_TEST_RET_ENC_EC(ret);
  49791. ret = mp_mod_2d(NULL, 1, b);
  49792. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49793. return WC_TEST_RET_ENC_EC(ret);
  49794. ret = mp_mul_2d(NULL, 1, NULL);
  49795. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49796. return WC_TEST_RET_ENC_EC(ret);
  49797. ret = mp_mul_2d(a, 1, NULL);
  49798. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49799. return WC_TEST_RET_ENC_EC(ret);
  49800. ret = mp_mul_2d(NULL, 1, b);
  49801. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49802. return WC_TEST_RET_ENC_EC(ret);
  49803. #endif
  49804. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49805. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49806. ret = mp_montgomery_reduce(NULL, NULL, 1);
  49807. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49808. return WC_TEST_RET_ENC_EC(ret);
  49809. ret = mp_montgomery_reduce(a, NULL, 1);
  49810. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49811. return WC_TEST_RET_ENC_EC(ret);
  49812. ret = mp_montgomery_reduce(NULL, b, 1);
  49813. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49814. return WC_TEST_RET_ENC_EC(ret);
  49815. mp_zero(b);
  49816. ret = mp_montgomery_reduce(a, b, 1);
  49817. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49818. return WC_TEST_RET_ENC_EC(ret);
  49819. #endif
  49820. #ifdef WOLFSSL_SP_MATH_ALL
  49821. ret = mp_montgomery_setup(NULL, NULL);
  49822. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49823. return WC_TEST_RET_ENC_EC(ret);
  49824. ret = mp_montgomery_setup(a, NULL);
  49825. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49826. return WC_TEST_RET_ENC_EC(ret);
  49827. ret = mp_montgomery_setup(NULL, &rho);
  49828. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49829. return WC_TEST_RET_ENC_EC(ret);
  49830. ret = mp_montgomery_calc_normalization(NULL, NULL);
  49831. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49832. return WC_TEST_RET_ENC_EC(ret);
  49833. ret = mp_montgomery_calc_normalization(a, NULL);
  49834. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49835. return WC_TEST_RET_ENC_EC(ret);
  49836. ret = mp_montgomery_calc_normalization(NULL, b);
  49837. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49838. return WC_TEST_RET_ENC_EC(ret);
  49839. #endif
  49840. ret = mp_unsigned_bin_size(NULL);
  49841. if (ret != 0)
  49842. return WC_TEST_RET_ENC_EC(ret);
  49843. #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL)
  49844. ret = mp_tohex(NULL, NULL);
  49845. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49846. return WC_TEST_RET_ENC_EC(ret);
  49847. ret = mp_tohex(a, NULL);
  49848. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49849. return WC_TEST_RET_ENC_EC(ret);
  49850. ret = mp_tohex(NULL, hexStr);
  49851. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49852. return WC_TEST_RET_ENC_EC(ret);
  49853. #endif
  49854. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49855. ret = mp_todecimal(NULL, NULL);
  49856. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49857. return WC_TEST_RET_ENC_EC(ret);
  49858. ret = mp_todecimal(a, NULL);
  49859. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49860. return WC_TEST_RET_ENC_EC(ret);
  49861. ret = mp_todecimal(NULL, decStr);
  49862. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49863. return WC_TEST_RET_ENC_EC(ret);
  49864. #endif
  49865. #ifdef WOLFSSL_SP_MATH_ALL
  49866. ret = mp_toradix(NULL, NULL, MP_RADIX_HEX);
  49867. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49868. return WC_TEST_RET_ENC_EC(ret);
  49869. ret = mp_toradix(a, NULL, MP_RADIX_HEX);
  49870. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49871. return WC_TEST_RET_ENC_EC(ret);
  49872. ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX);
  49873. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49874. return WC_TEST_RET_ENC_EC(ret);
  49875. ret = mp_toradix(a, hexStr, 3);
  49876. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49877. return WC_TEST_RET_ENC_EC(ret);
  49878. ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL);
  49879. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49880. return WC_TEST_RET_ENC_EC(ret);
  49881. ret = mp_radix_size(a, MP_RADIX_HEX, NULL);
  49882. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49883. return WC_TEST_RET_ENC_EC(ret);
  49884. ret = mp_radix_size(NULL, MP_RADIX_HEX, &size);
  49885. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49886. return WC_TEST_RET_ENC_EC(ret);
  49887. ret = mp_radix_size(a, 3, &size);
  49888. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49889. return WC_TEST_RET_ENC_EC(ret);
  49890. #endif
  49891. return 0;
  49892. }
  49893. #endif
  49894. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49895. static wc_test_ret_t mp_test_set_is_bit(mp_int* a)
  49896. {
  49897. int i, j;
  49898. wc_test_ret_t ret;
  49899. mp_zero(a);
  49900. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49901. if (mp_is_bit_set(a, i))
  49902. return WC_TEST_RET_ENC_NC;
  49903. for (j = 0; j < i; j++) {
  49904. if (!mp_is_bit_set(a, j))
  49905. return WC_TEST_RET_ENC_NC;
  49906. }
  49907. if (mp_set_bit(a, i) != 0)
  49908. return WC_TEST_RET_ENC_NC;
  49909. if (!mp_is_bit_set(a, i))
  49910. return WC_TEST_RET_ENC_NC;
  49911. }
  49912. mp_zero(a);
  49913. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49914. if (mp_is_bit_set(a, i))
  49915. return WC_TEST_RET_ENC_NC;
  49916. }
  49917. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49918. mp_zero(a);
  49919. if (mp_set_bit(a, i) != 0)
  49920. return WC_TEST_RET_ENC_NC;
  49921. for (j = 0; j < i; j++) {
  49922. if (mp_is_bit_set(a, j))
  49923. return WC_TEST_RET_ENC_NC;
  49924. }
  49925. if (!mp_is_bit_set(a, i))
  49926. return WC_TEST_RET_ENC_NC;
  49927. }
  49928. #ifdef WOLFSSL_KEY_GEN
  49929. for (i = 0; i < DIGIT_BIT * 2; i++) {
  49930. mp_set(a, 1);
  49931. ret = mp_2expt(a, i);
  49932. if (ret != 0)
  49933. return WC_TEST_RET_ENC_EC(ret);
  49934. for (j = 0; j < i; j++) {
  49935. if (mp_is_bit_set(a, j))
  49936. return WC_TEST_RET_ENC_NC;
  49937. }
  49938. if (!mp_is_bit_set(a, i))
  49939. return WC_TEST_RET_ENC_NC;
  49940. }
  49941. #endif
  49942. #ifdef WOLFSSL_SP_MATH
  49943. mp_zero(a);
  49944. for (j = 1; j <= 3; j++) {
  49945. i = SP_INT_MAX_BITS - j;
  49946. if (mp_is_bit_set(a, i))
  49947. return WC_TEST_RET_ENC_NC;
  49948. if (mp_set_bit(a, i) != 0)
  49949. return WC_TEST_RET_ENC_NC;
  49950. if (!mp_is_bit_set(a, i))
  49951. return WC_TEST_RET_ENC_NC;
  49952. #ifdef WOLFSSL_KEY_GEN
  49953. ret = mp_2expt(a, i);
  49954. if (ret != 0)
  49955. return WC_TEST_RET_ENC_EC(ret);
  49956. if (!mp_is_bit_set(a, i))
  49957. return WC_TEST_RET_ENC_NC;
  49958. #endif
  49959. }
  49960. mp_zero(a);
  49961. for (j = 0; j <= 3; j++) {
  49962. i = SP_INT_MAX_BITS + j;
  49963. if (mp_is_bit_set(a, i))
  49964. return WC_TEST_RET_ENC_NC;
  49965. if (mp_set_bit(a, i) != WC_NO_ERR_TRACE(MP_VAL))
  49966. return WC_TEST_RET_ENC_NC;
  49967. #ifdef WOLFSSL_KEY_GEN
  49968. ret = mp_2expt(a, i);
  49969. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49970. return WC_TEST_RET_ENC_EC(ret);
  49971. #endif
  49972. }
  49973. #endif
  49974. (void)ret;
  49975. return 0;
  49976. }
  49977. #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */
  49978. static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
  49979. {
  49980. wc_test_ret_t ret;
  49981. mp_zero(a);
  49982. mp_zero(b);
  49983. ret = mp_cmp_d(a, 0);
  49984. if (ret != MP_EQ)
  49985. return WC_TEST_RET_ENC_EC(ret);
  49986. ret = mp_cmp_d(a, 1);
  49987. if (ret != MP_LT)
  49988. return WC_TEST_RET_ENC_EC(ret);
  49989. ret = mp_cmp(a, b);
  49990. if (ret != MP_EQ)
  49991. return WC_TEST_RET_ENC_NC;
  49992. mp_set(a, 1);
  49993. ret = mp_cmp_d(a, 0);
  49994. if (ret != MP_GT)
  49995. return WC_TEST_RET_ENC_EC(ret);
  49996. ret = mp_cmp_d(a, 1);
  49997. if (ret != MP_EQ)
  49998. return WC_TEST_RET_ENC_EC(ret);
  49999. ret = mp_cmp_d(a, 2);
  50000. if (ret != MP_LT)
  50001. return WC_TEST_RET_ENC_EC(ret);
  50002. ret = mp_cmp(a, b);
  50003. if (ret != MP_GT)
  50004. return WC_TEST_RET_ENC_NC;
  50005. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50006. mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX);
  50007. ret = mp_cmp_d(b, -1);
  50008. if (ret != MP_GT)
  50009. return WC_TEST_RET_ENC_EC(ret);
  50010. ret = mp_cmp(a, b);
  50011. if (ret != MP_LT)
  50012. return WC_TEST_RET_ENC_NC;
  50013. ret = mp_cmp(b, a);
  50014. if (ret != MP_GT)
  50015. return WC_TEST_RET_ENC_NC;
  50016. ret = mp_cmp(b, b);
  50017. if (ret != MP_EQ)
  50018. return WC_TEST_RET_ENC_NC;
  50019. #endif
  50020. #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
  50021. defined(WOLFSSL_SP_INT_NEGATIVE)
  50022. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50023. mp_read_radix(a, "-1", MP_RADIX_HEX);
  50024. mp_read_radix(a, "1", MP_RADIX_HEX);
  50025. ret = mp_cmp(a, b);
  50026. if (ret != MP_LT)
  50027. return WC_TEST_RET_ENC_NC;
  50028. ret = mp_cmp(b, a);
  50029. if (ret != MP_GT)
  50030. return WC_TEST_RET_ENC_NC;
  50031. mp_read_radix(b, "-2", MP_RADIX_HEX);
  50032. ret = mp_cmp(a, b);
  50033. if (ret != MP_GT)
  50034. return WC_TEST_RET_ENC_NC;
  50035. ret = mp_cmp(b, a);
  50036. if (ret != MP_LT)
  50037. return WC_TEST_RET_ENC_NC;
  50038. #endif
  50039. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50040. mp_read_radix(a, "-2", MP_RADIX_HEX);
  50041. ret = mp_cmp(a, b);
  50042. if (ret != MP_EQ)
  50043. return WC_TEST_RET_ENC_NC;
  50044. #endif
  50045. #endif
  50046. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  50047. defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING)
  50048. mp_zero(a);
  50049. mp_zero(b);
  50050. ret = mp_cmp_ct(a, b, 1);
  50051. if (ret != MP_EQ)
  50052. return WC_TEST_RET_ENC_EC(ret);
  50053. ret = mp_cmp_ct(a, a, a->used);
  50054. if (ret != MP_EQ)
  50055. return WC_TEST_RET_ENC_EC(ret);
  50056. #ifdef WOLFSSL_SP_MATH_ALL
  50057. ret = mp_cmp_ct(a, NULL, a->used);
  50058. if (ret != MP_GT)
  50059. return WC_TEST_RET_ENC_EC(ret);
  50060. ret = mp_cmp_ct(NULL, a, a->used);
  50061. if (ret != MP_LT)
  50062. return WC_TEST_RET_ENC_EC(ret);
  50063. #endif
  50064. mp_read_radix(a, "1", MP_RADIX_HEX);
  50065. ret = mp_cmp_ct(a, b, 1);
  50066. if (ret != MP_GT)
  50067. return WC_TEST_RET_ENC_EC(ret);
  50068. ret = mp_cmp_ct(b, a, 1);
  50069. if (ret != MP_LT)
  50070. return WC_TEST_RET_ENC_EC(ret);
  50071. mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50072. ret = mp_cmp_ct(a, b, a->used);
  50073. if (ret != MP_GT)
  50074. return WC_TEST_RET_ENC_EC(ret);
  50075. ret = mp_cmp_ct(b, a, a->used);
  50076. if (ret != MP_LT)
  50077. return WC_TEST_RET_ENC_EC(ret);
  50078. mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50079. ret = mp_cmp_ct(b, a, a->used);
  50080. if (ret != MP_GT)
  50081. return WC_TEST_RET_ENC_EC(ret);
  50082. ret = mp_cmp_ct(a, b, a->used);
  50083. if (ret != MP_LT)
  50084. return WC_TEST_RET_ENC_EC(ret);
  50085. mp_read_radix(b, "0123456789abcdef0123456789abcdf0", MP_RADIX_HEX);
  50086. ret = mp_cmp_ct(b, a, a->used);
  50087. if (ret != MP_GT)
  50088. return WC_TEST_RET_ENC_EC(ret);
  50089. ret = mp_cmp_ct(a, b, a->used);
  50090. if (ret != MP_LT)
  50091. return WC_TEST_RET_ENC_EC(ret);
  50092. mp_read_radix(b, "0123456789abcdf0", MP_RADIX_HEX);
  50093. ret = mp_cmp_ct(a, b, a->used);
  50094. if (ret != MP_GT)
  50095. return WC_TEST_RET_ENC_EC(ret);
  50096. ret = mp_cmp_ct(b, a, a->used);
  50097. if (ret != MP_LT)
  50098. return WC_TEST_RET_ENC_EC(ret);
  50099. #endif
  50100. return 0;
  50101. }
  50102. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50103. static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
  50104. {
  50105. wc_test_ret_t ret;
  50106. int i, j, k;
  50107. #ifndef WOLFSSL_SP_MATH
  50108. for (i = 0; i < 10; i++) {
  50109. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50110. ret = randNum(a, j, rng, NULL);
  50111. if (ret != MP_OKAY)
  50112. return WC_TEST_RET_ENC_EC(ret);
  50113. mp_copy(a, b);
  50114. for (k = 0; k <= DIGIT_BIT * 2; k++) {
  50115. ret = mp_mul_2d(a, k, a);
  50116. if (ret != MP_OKAY)
  50117. return WC_TEST_RET_ENC_EC(ret);
  50118. mp_rshb(a, k);
  50119. ret = mp_cmp(a, b);
  50120. if (ret != MP_EQ)
  50121. return WC_TEST_RET_ENC_NC;
  50122. }
  50123. }
  50124. }
  50125. #endif
  50126. for (i = 0; i < 10; i++) {
  50127. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50128. ret = randNum(a, j, rng, NULL);
  50129. if (ret != MP_OKAY)
  50130. return WC_TEST_RET_ENC_EC(ret);
  50131. mp_copy(a, b);
  50132. for (k = 0; k < 10; k++) {
  50133. ret = mp_lshd(a, k);
  50134. if (ret != MP_OKAY)
  50135. return WC_TEST_RET_ENC_EC(ret);
  50136. #ifndef WOLFSSL_SP_MATH
  50137. mp_rshd(a, k);
  50138. #else
  50139. mp_rshb(a, k * SP_WORD_SIZE);
  50140. #endif
  50141. ret = mp_cmp(a, b);
  50142. if (ret != MP_EQ)
  50143. return WC_TEST_RET_ENC_NC;
  50144. }
  50145. }
  50146. }
  50147. #ifndef WOLFSSL_SP_MATH
  50148. mp_zero(a);
  50149. mp_rshd(a, 1);
  50150. if (!mp_iszero(a))
  50151. return WC_TEST_RET_ENC_NC;
  50152. mp_set(a, 1);
  50153. mp_rshd(a, 1);
  50154. if (!mp_iszero(a))
  50155. return WC_TEST_RET_ENC_NC;
  50156. mp_set(a, 1);
  50157. mp_rshd(a, 2);
  50158. if (!mp_iszero(a))
  50159. return WC_TEST_RET_ENC_NC;
  50160. #endif
  50161. return 0;
  50162. }
  50163. #endif
  50164. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50165. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  50166. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50167. static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
  50168. WC_RNG* rng)
  50169. {
  50170. wc_test_ret_t ret;
  50171. int i, j, k;
  50172. mp_zero(a);
  50173. mp_zero(d);
  50174. ret = mp_div(a, d, r, rem);
  50175. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50176. return WC_TEST_RET_ENC_EC(ret);
  50177. mp_set(d, 1);
  50178. ret = mp_div(a, d, r, rem);
  50179. if (ret != MP_OKAY)
  50180. return WC_TEST_RET_ENC_EC(ret);
  50181. if (!mp_iszero(r))
  50182. return WC_TEST_RET_ENC_EC(ret);
  50183. if (!mp_iszero(rem))
  50184. return WC_TEST_RET_ENC_EC(ret);
  50185. mp_set(a, 1);
  50186. ret = mp_div(a, d, r, rem);
  50187. if (ret != MP_OKAY)
  50188. return WC_TEST_RET_ENC_EC(ret);
  50189. if (!mp_isone(r))
  50190. return WC_TEST_RET_ENC_EC(ret);
  50191. if (!mp_iszero(rem))
  50192. return WC_TEST_RET_ENC_EC(ret);
  50193. for (i = 0; i < 100; i++) {
  50194. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) {
  50195. ret = randNum(d, j, rng, NULL);
  50196. if (ret != MP_OKAY)
  50197. return WC_TEST_RET_ENC_EC(ret);
  50198. for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) {
  50199. ret = randNum(a, k, rng, NULL);
  50200. if (ret != MP_OKAY)
  50201. return WC_TEST_RET_ENC_EC(ret);
  50202. ret = mp_div(a, d, NULL, rem);
  50203. if (ret != MP_OKAY)
  50204. return WC_TEST_RET_ENC_EC(ret);
  50205. ret = mp_div(a, d, r, NULL);
  50206. if (ret != MP_OKAY)
  50207. return WC_TEST_RET_ENC_EC(ret);
  50208. ret = mp_div(a, d, r, rem);
  50209. if (ret != MP_OKAY)
  50210. return WC_TEST_RET_ENC_EC(ret);
  50211. mp_mul(r, d, r);
  50212. mp_add(r, rem, r);
  50213. if (mp_cmp(r, a) != MP_EQ)
  50214. return WC_TEST_RET_ENC_NC;
  50215. }
  50216. }
  50217. }
  50218. ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL);
  50219. if (ret != MP_OKAY)
  50220. return WC_TEST_RET_ENC_EC(ret);
  50221. mp_add(d, d, a);
  50222. mp_set(rem, 1);
  50223. mp_div(a, d, NULL, rem);
  50224. if (ret != MP_OKAY)
  50225. return WC_TEST_RET_ENC_EC(ret);
  50226. if (!mp_iszero(rem))
  50227. return WC_TEST_RET_ENC_EC(ret);
  50228. mp_set(r, 1);
  50229. mp_div(a, d, r, NULL);
  50230. if (ret != MP_OKAY)
  50231. return WC_TEST_RET_ENC_EC(ret);
  50232. if (mp_cmp_d(r, 2) != MP_EQ)
  50233. return WC_TEST_RET_ENC_EC(ret);
  50234. mp_set(r, 1);
  50235. mp_set(rem, 1);
  50236. mp_div(a, d, r, rem);
  50237. if (ret != MP_OKAY)
  50238. return WC_TEST_RET_ENC_EC(ret);
  50239. if (mp_cmp_d(r, 2) != MP_EQ)
  50240. return WC_TEST_RET_ENC_EC(ret);
  50241. if (!mp_iszero(rem))
  50242. return WC_TEST_RET_ENC_EC(ret);
  50243. mp_set(a, 0xfe);
  50244. mp_lshd(a, 3);
  50245. mp_add_d(a, 0xff, a);
  50246. mp_set(d, 0xfe);
  50247. mp_lshd(d, 2);
  50248. ret = mp_div(a, d, r, rem);
  50249. if (ret != MP_OKAY)
  50250. return WC_TEST_RET_ENC_EC(ret);
  50251. mp_mul(r, d, d);
  50252. mp_add(rem, d, d);
  50253. if (mp_cmp(a, d) != MP_EQ)
  50254. return WC_TEST_RET_ENC_NC;
  50255. /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in
  50256. * a digit. So mp_div must detect and handle.
  50257. * For example: 0x800000 / 0x8001, DIGIT_BIT = 8
  50258. */
  50259. mp_zero(a);
  50260. mp_set_bit(a, DIGIT_BIT * 3 - 1);
  50261. mp_zero(d);
  50262. mp_set_bit(d, DIGIT_BIT * 2 - 1);
  50263. mp_add_d(d, 1, d);
  50264. ret = mp_div(a, d, r, rem);
  50265. if (ret != MP_OKAY)
  50266. return WC_TEST_RET_ENC_EC(ret);
  50267. /* Make sure [d | d] / d is handled. */
  50268. mp_zero(a);
  50269. mp_set_bit(a, DIGIT_BIT * 2 - 1);
  50270. mp_set_bit(a, DIGIT_BIT * 1 - 1);
  50271. mp_zero(d);
  50272. mp_set_bit(d, DIGIT_BIT - 1);
  50273. ret = mp_div(a, d, r, rem);
  50274. if (ret != MP_OKAY)
  50275. return WC_TEST_RET_ENC_EC(ret);
  50276. mp_zero(a);
  50277. mp_set_bit(a, DIGIT_BIT);
  50278. mp_set_bit(a, 0);
  50279. mp_zero(d);
  50280. if (mp_cmp(r, a) != MP_EQ)
  50281. return WC_TEST_RET_ENC_NC;
  50282. if (mp_cmp(rem, d) != MP_EQ)
  50283. return WC_TEST_RET_ENC_NC;
  50284. return 0;
  50285. }
  50286. #endif
  50287. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50288. !defined(WC_NO_RNG)
  50289. static wc_test_ret_t mp_test_prime(mp_int* a, WC_RNG* rng)
  50290. {
  50291. wc_test_ret_t ret;
  50292. int res;
  50293. ret = mp_rand_prime(a, 1, rng, NULL);
  50294. #if defined(WOLFSSL_SP_MATH_ALL)
  50295. if (ret != 0)
  50296. return WC_TEST_RET_ENC_EC(ret);
  50297. #else
  50298. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50299. return WC_TEST_RET_ENC_NC;
  50300. #endif
  50301. #ifndef WOLFSSL_SP_MATH
  50302. ret = mp_rand_prime(a, -5, rng, NULL);
  50303. if (ret != 0 || (a->dp[0] & 3) != 3)
  50304. return WC_TEST_RET_ENC_NC;
  50305. #endif
  50306. ret = mp_prime_is_prime(a, 1, &res);
  50307. if (ret != MP_OKAY)
  50308. return WC_TEST_RET_ENC_EC(ret);
  50309. #ifndef WOLFSSL_SP_MATH
  50310. if (res != MP_YES)
  50311. return WC_TEST_RET_ENC_EC(res);
  50312. #else
  50313. if (res != MP_NO)
  50314. return WC_TEST_RET_ENC_EC(res);
  50315. #endif
  50316. ret = mp_prime_is_prime(a, 0, &res);
  50317. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50318. return WC_TEST_RET_ENC_EC(ret);
  50319. ret = mp_prime_is_prime(a, -1, &res);
  50320. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50321. return WC_TEST_RET_ENC_EC(ret);
  50322. ret = mp_prime_is_prime(a, 257, &res);
  50323. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50324. return WC_TEST_RET_ENC_EC(ret);
  50325. mp_set(a, 1);
  50326. ret = mp_prime_is_prime(a, 1, &res);
  50327. if (ret != MP_OKAY)
  50328. return WC_TEST_RET_ENC_EC(ret);
  50329. if (res != MP_NO)
  50330. return WC_TEST_RET_ENC_EC(res);
  50331. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50332. if (ret != MP_OKAY)
  50333. return WC_TEST_RET_ENC_EC(ret);
  50334. if (res != MP_NO)
  50335. return WC_TEST_RET_ENC_EC(res);
  50336. mp_set(a, 2);
  50337. ret = mp_prime_is_prime(a, 1, &res);
  50338. if (ret != MP_OKAY)
  50339. return WC_TEST_RET_ENC_EC(ret);
  50340. if (res != MP_YES)
  50341. return WC_TEST_RET_ENC_EC(res);
  50342. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50343. if (ret != MP_OKAY)
  50344. return WC_TEST_RET_ENC_EC(ret);
  50345. if (res != MP_YES)
  50346. return WC_TEST_RET_ENC_EC(res);
  50347. mp_set(a, 0xfb);
  50348. ret = mp_prime_is_prime(a, 1, &res);
  50349. if (ret != MP_OKAY)
  50350. return WC_TEST_RET_ENC_EC(ret);
  50351. if (res != MP_YES)
  50352. return WC_TEST_RET_ENC_EC(res);
  50353. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50354. if (ret != MP_OKAY)
  50355. return WC_TEST_RET_ENC_EC(ret);
  50356. if (res != MP_YES)
  50357. return WC_TEST_RET_ENC_EC(res);
  50358. mp_set(a, 0x6);
  50359. ret = mp_prime_is_prime(a, 1, &res);
  50360. if (ret != MP_OKAY)
  50361. return WC_TEST_RET_ENC_EC(ret);
  50362. if (res != MP_NO)
  50363. return WC_TEST_RET_ENC_EC(res);
  50364. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50365. if (ret != MP_OKAY)
  50366. return WC_TEST_RET_ENC_EC(ret);
  50367. if (res != MP_NO)
  50368. return WC_TEST_RET_ENC_EC(res);
  50369. mp_set_int(a, 0x655 * 0x65b);
  50370. ret = mp_prime_is_prime(a, 10, &res);
  50371. if (ret != MP_OKAY)
  50372. return WC_TEST_RET_ENC_EC(ret);
  50373. if (res != MP_NO)
  50374. return WC_TEST_RET_ENC_EC(res);
  50375. ret = mp_prime_is_prime_ex(a, 10, &res, rng);
  50376. if (ret != MP_OKAY)
  50377. return WC_TEST_RET_ENC_EC(ret);
  50378. if (res != MP_NO)
  50379. return WC_TEST_RET_ENC_EC(res);
  50380. return 0;
  50381. }
  50382. #endif
  50383. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50384. static wc_test_ret_t mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp,
  50385. WC_RNG* rng)
  50386. {
  50387. wc_test_ret_t ret;
  50388. int i;
  50389. WOLFSSL_SMALL_STACK_STATIC const int kat[][3] = {
  50390. { 1, 1, 1 }, { 2, 1, 2 }, { 1, 2, 2 }, { 2, 4, 4 }, { 4, 2, 4 },
  50391. { 12, 56, 168 }, { 56, 12, 168 }
  50392. };
  50393. (void)exp;
  50394. mp_set(a, 0);
  50395. mp_set(b, 1);
  50396. ret = mp_lcm(a, a, r);
  50397. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50398. return WC_TEST_RET_ENC_EC(ret);
  50399. ret = mp_lcm(a, b, r);
  50400. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50401. return WC_TEST_RET_ENC_EC(ret);
  50402. ret = mp_lcm(b, a, r);
  50403. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50404. return WC_TEST_RET_ENC_EC(ret);
  50405. for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) {
  50406. mp_set(a, kat[i][0]);
  50407. mp_set(b, kat[i][1]);
  50408. ret = mp_lcm(a, b, r);
  50409. if (ret != MP_OKAY)
  50410. return WC_TEST_RET_ENC_EC(ret);
  50411. mp_set(exp, kat[i][2]);
  50412. ret = mp_cmp(r, exp);
  50413. if (ret != MP_EQ)
  50414. return WC_TEST_RET_ENC_NC;
  50415. }
  50416. (void)rng;
  50417. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50418. !defined(WC_NO_RNG)
  50419. ret = mp_rand_prime(a, 20, rng, NULL);
  50420. if (ret != MP_OKAY)
  50421. return WC_TEST_RET_ENC_EC(ret);
  50422. ret = mp_rand_prime(b, 20, rng, NULL);
  50423. if (ret != MP_OKAY)
  50424. return WC_TEST_RET_ENC_EC(ret);
  50425. ret = mp_mul(a, b, exp);
  50426. if (ret != MP_OKAY)
  50427. return WC_TEST_RET_ENC_EC(ret);
  50428. ret = mp_lcm(a, b, r);
  50429. if (ret != MP_OKAY)
  50430. return WC_TEST_RET_ENC_EC(ret);
  50431. ret = mp_cmp(r, exp);
  50432. if (ret != MP_EQ)
  50433. return WC_TEST_RET_ENC_NC;
  50434. ret = mp_lcm(b, a, r);
  50435. if (ret != MP_OKAY)
  50436. return WC_TEST_RET_ENC_EC(ret);
  50437. ret = mp_cmp(r, exp);
  50438. if (ret != MP_EQ)
  50439. return WC_TEST_RET_ENC_NC;
  50440. #endif
  50441. mp_set(a, 11);
  50442. mp_zero(b);
  50443. ret = mp_gcd(a, b, r);
  50444. if (ret != MP_OKAY)
  50445. return WC_TEST_RET_ENC_EC(ret);
  50446. ret = mp_cmp_d(r, 11);
  50447. if (ret != MP_EQ)
  50448. return WC_TEST_RET_ENC_EC(ret);
  50449. ret = mp_gcd(b, a, r);
  50450. if (ret != MP_OKAY)
  50451. return WC_TEST_RET_ENC_EC(ret);
  50452. ret = mp_cmp_d(r, 11);
  50453. if (ret != MP_EQ)
  50454. return WC_TEST_RET_ENC_EC(ret);
  50455. ret = mp_gcd(b, b, r);
  50456. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50457. return WC_TEST_RET_ENC_EC(ret);
  50458. return 0;
  50459. }
  50460. #endif
  50461. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50462. defined(WOLFSSL_SP_MATH_ALL)
  50463. static wc_test_ret_t mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng)
  50464. {
  50465. wc_test_ret_t ret;
  50466. int i;
  50467. int j;
  50468. mp_set(a, 10);
  50469. ret = mp_mod_2d(a, 0, r);
  50470. if (ret != MP_OKAY)
  50471. return WC_TEST_RET_ENC_EC(ret);
  50472. if (!mp_iszero(r))
  50473. return WC_TEST_RET_ENC_NC;
  50474. ret = mp_mod_2d(a, 1, r);
  50475. if (ret != MP_OKAY)
  50476. return WC_TEST_RET_ENC_EC(ret);
  50477. if (!mp_iszero(r))
  50478. return WC_TEST_RET_ENC_NC;
  50479. ret = mp_mod_2d(a, 2, r);
  50480. if (ret != MP_OKAY)
  50481. return WC_TEST_RET_ENC_EC(ret);
  50482. ret = mp_cmp_d(r, 2);
  50483. if (ret != 0)
  50484. return WC_TEST_RET_ENC_EC(ret);
  50485. for (i = 2; i < 20; i++) {
  50486. ret = randNum(a, i, rng, NULL);
  50487. if (ret != 0)
  50488. return WC_TEST_RET_ENC_EC(ret);
  50489. for (j = 1; j <= mp_count_bits(a); j++) {
  50490. /* Get top part */
  50491. ret = mp_div_2d(a, j, t, NULL);
  50492. if (ret != 0)
  50493. return WC_TEST_RET_ENC_EC(ret);
  50494. ret = mp_mul_2d(t, j, t);
  50495. if (ret != 0)
  50496. return WC_TEST_RET_ENC_EC(ret);
  50497. /* Get bottom part */
  50498. ret = mp_mod_2d(a, j, r);
  50499. if (ret != 0)
  50500. return WC_TEST_RET_ENC_EC(ret);
  50501. /* Reassemble */
  50502. ret = mp_add(t, r, r);
  50503. if (ret != 0)
  50504. return WC_TEST_RET_ENC_EC(ret);
  50505. ret = mp_cmp(a, r);
  50506. if (ret != MP_EQ)
  50507. return WC_TEST_RET_ENC_NC;
  50508. }
  50509. }
  50510. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_SP_INT_NEGATIVE)
  50511. /* Test negative value being moded. */
  50512. for (j = 0; j < 20; j++) {
  50513. ret = randNum(a, 2, rng, NULL);
  50514. if (ret != 0)
  50515. return WC_TEST_RET_ENC_EC(ret);
  50516. a->sign = MP_NEG;
  50517. for (i = 1; i < DIGIT_BIT * 3 + 1; i++) {
  50518. ret = mp_mod_2d(a, i, r);
  50519. if (ret != 0)
  50520. return WC_TEST_RET_ENC_EC(ret);
  50521. mp_zero(t);
  50522. ret = mp_set_bit(t, i);
  50523. if (ret != 0)
  50524. return WC_TEST_RET_ENC_EC(ret);
  50525. ret = mp_mod(a, t, t);
  50526. if (ret != 0)
  50527. return WC_TEST_RET_ENC_EC(ret);
  50528. ret = mp_cmp(r, t);
  50529. if (ret != MP_EQ)
  50530. return WC_TEST_RET_ENC_NC;
  50531. }
  50532. }
  50533. #endif
  50534. return 0;
  50535. }
  50536. #endif
  50537. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50538. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50539. static wc_test_ret_t mp_test_mod_d(mp_int* a, WC_RNG* rng)
  50540. {
  50541. wc_test_ret_t ret;
  50542. mp_digit r;
  50543. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50544. mp_digit rem;
  50545. int i;
  50546. #endif
  50547. (void)rng;
  50548. ret = mp_set(a, 1);
  50549. if (ret != MP_OKAY)
  50550. return WC_TEST_RET_ENC_EC(ret);
  50551. ret = mp_mod_d(a, 0, &r);
  50552. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50553. return WC_TEST_RET_ENC_EC(ret);
  50554. mp_zero(a);
  50555. ret = mp_mod_d(a, 1, &r);
  50556. if (ret != MP_OKAY)
  50557. return WC_TEST_RET_ENC_EC(ret);
  50558. ret = mp_mod_d(a, 3, &r);
  50559. if (ret != MP_OKAY)
  50560. return WC_TEST_RET_ENC_EC(ret);
  50561. ret = mp_mod_d(a, 5, &r);
  50562. if (ret != MP_OKAY)
  50563. return WC_TEST_RET_ENC_EC(ret);
  50564. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50565. for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) {
  50566. ret = randNum(a, i, rng, NULL);
  50567. if (ret != MP_OKAY)
  50568. return WC_TEST_RET_ENC_EC(ret);
  50569. ret = mp_mod_d(a, 3, &r);
  50570. if (ret != MP_OKAY)
  50571. return WC_TEST_RET_ENC_EC(ret);
  50572. ret = mp_div_d(a, 3, a, &rem);
  50573. if (ret != MP_OKAY)
  50574. return WC_TEST_RET_ENC_EC(ret);
  50575. if (r != rem)
  50576. return WC_TEST_RET_ENC_NC;
  50577. }
  50578. #endif
  50579. return 0;
  50580. }
  50581. #endif
  50582. static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2,
  50583. WC_RNG* rng)
  50584. {
  50585. wc_test_ret_t ret;
  50586. int i;
  50587. for (i = 1; i < 16; i++) {
  50588. ret = randNum(a, i, rng, NULL);
  50589. if (ret != 0)
  50590. return WC_TEST_RET_ENC_EC(ret);
  50591. ret = mp_mul(a, a, r1);
  50592. if (ret != 0)
  50593. return WC_TEST_RET_ENC_EC(ret);
  50594. ret = mp_sqr(a, r2);
  50595. if (ret != 0)
  50596. return WC_TEST_RET_ENC_EC(ret);
  50597. ret = mp_cmp(r1, r2);
  50598. if (ret != MP_EQ)
  50599. return WC_TEST_RET_ENC_NC;
  50600. }
  50601. ret = mp_set(b, 0);
  50602. if (ret != MP_OKAY)
  50603. return WC_TEST_RET_ENC_EC(ret);
  50604. ret = mp_mul(a, b, r1);
  50605. if (ret != MP_OKAY)
  50606. return WC_TEST_RET_ENC_EC(ret);
  50607. if (!mp_iszero(r1))
  50608. return WC_TEST_RET_ENC_EC(ret);
  50609. ret = mp_sqr(b, r1);
  50610. if (ret != MP_OKAY)
  50611. return WC_TEST_RET_ENC_EC(ret);
  50612. if (!mp_iszero(r1))
  50613. return WC_TEST_RET_ENC_NC;
  50614. #ifdef WOLFSSL_SP_MATH_ALL
  50615. ret = mp_set(a, 1);
  50616. if (ret != MP_OKAY)
  50617. return WC_TEST_RET_ENC_EC(ret);
  50618. i = (SP_INT_DIGITS / 2) + 1;
  50619. ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a);
  50620. if (ret != MP_OKAY)
  50621. return WC_TEST_RET_ENC_EC(ret);
  50622. ret = mp_set(b, 1);
  50623. if (ret != MP_OKAY)
  50624. return WC_TEST_RET_ENC_EC(ret);
  50625. ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b);
  50626. if (ret != MP_OKAY)
  50627. return WC_TEST_RET_ENC_EC(ret);
  50628. ret = mp_mul(a, b, r1);
  50629. if (ret != MP_OKAY)
  50630. return WC_TEST_RET_ENC_EC(ret);
  50631. ret = mp_mul(a, a, r1);
  50632. if (ret == MP_OKAY)
  50633. return WC_TEST_RET_ENC_NC;
  50634. ret = mp_sqr(a, r1);
  50635. if (ret == MP_OKAY)
  50636. return WC_TEST_RET_ENC_NC;
  50637. ret = mp_sqr(b, r1);
  50638. if (ret != MP_OKAY)
  50639. return WC_TEST_RET_ENC_EC(ret);
  50640. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50641. (defined(HAVE_ECC) && defined(FP_ECC))
  50642. ret = mp_mulmod(a, b, b, r1);
  50643. if (ret != MP_OKAY)
  50644. return WC_TEST_RET_ENC_EC(ret);
  50645. ret = mp_mulmod(a, a, b, r1);
  50646. if (ret == MP_OKAY)
  50647. return WC_TEST_RET_ENC_NC;
  50648. #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC))
  50649. ret = mp_sqrmod(a, b, r1);
  50650. if (ret == MP_OKAY)
  50651. return WC_TEST_RET_ENC_NC;
  50652. ret = mp_sqrmod(b, a, r1);
  50653. if (ret != MP_OKAY)
  50654. return WC_TEST_RET_ENC_EC(ret);
  50655. #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */
  50656. #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
  50657. #endif /* WOLFSSL_SP_MATH_ALL */
  50658. return 0;
  50659. }
  50660. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  50661. defined(OPENSSL_EXTRA)
  50662. static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
  50663. {
  50664. wc_test_ret_t ret;
  50665. mp_set(a, 0);
  50666. mp_set(m, 1);
  50667. ret = mp_invmod(a, m, r);
  50668. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50669. return WC_TEST_RET_ENC_EC(ret);
  50670. ret = mp_invmod(m, a, r);
  50671. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50672. return WC_TEST_RET_ENC_EC(ret);
  50673. mp_set(a, 2);
  50674. mp_set(m, 4);
  50675. ret = mp_invmod(a, m, r);
  50676. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50677. return WC_TEST_RET_ENC_EC(ret);
  50678. mp_set(a, 3);
  50679. mp_set(m, 6);
  50680. ret = mp_invmod(a, m, r);
  50681. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50682. return WC_TEST_RET_ENC_EC(ret);
  50683. mp_set(a, 5*9);
  50684. mp_set(m, 6*9);
  50685. ret = mp_invmod(a, m, r);
  50686. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50687. return WC_TEST_RET_ENC_EC(ret);
  50688. mp_set(a, 1);
  50689. mp_set(m, 4);
  50690. ret = mp_invmod(a, m, r);
  50691. if (ret != MP_OKAY)
  50692. return WC_TEST_RET_ENC_EC(ret);
  50693. if (!mp_isone(r))
  50694. return WC_TEST_RET_ENC_NC;
  50695. mp_set(a, 3);
  50696. mp_set(m, 4);
  50697. ret = mp_invmod(a, m, r);
  50698. if (ret != MP_OKAY)
  50699. return WC_TEST_RET_ENC_EC(ret);
  50700. ret = mp_cmp_d(r, 3);
  50701. if (ret != 0)
  50702. return WC_TEST_RET_ENC_EC(ret);
  50703. mp_set(a, 3);
  50704. mp_set(m, 5);
  50705. ret = mp_invmod(a, m, r);
  50706. if (ret != MP_OKAY)
  50707. return WC_TEST_RET_ENC_EC(ret);
  50708. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50709. /* Maximum 'a' */
  50710. mp_set(a, 0);
  50711. mp_set_bit(a, (r->size / 2)* SP_WORD_SIZE - 1);
  50712. mp_sub_d(a, 1, a);
  50713. /* Modulus too big. */
  50714. mp_set(m, 0);
  50715. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE);
  50716. ret = mp_invmod(a, m, r);
  50717. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50718. return WC_TEST_RET_ENC_EC(ret);
  50719. /* Maximum modulus - even. */
  50720. mp_set(m, 0);
  50721. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1);
  50722. ret = mp_invmod(a, m, r);
  50723. if (ret != MP_OKAY)
  50724. return WC_TEST_RET_ENC_EC(ret);
  50725. #endif
  50726. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE)
  50727. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50728. mp_read_radix(a, "-3", 16);
  50729. ret = mp_invmod(a, m, r);
  50730. if (ret != MP_OKAY)
  50731. return WC_TEST_RET_ENC_EC(ret);
  50732. #endif
  50733. #endif
  50734. #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
  50735. mp_set(a, 0);
  50736. mp_set(m, 3);
  50737. ret = mp_invmod_mont_ct(a, m, r, 1);
  50738. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50739. return WC_TEST_RET_ENC_EC(ret);
  50740. mp_set(a, 1);
  50741. mp_set(m, 0);
  50742. ret = mp_invmod_mont_ct(a, m, r, 1);
  50743. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50744. return WC_TEST_RET_ENC_EC(ret);
  50745. mp_set(a, 1);
  50746. mp_set(m, 1);
  50747. ret = mp_invmod_mont_ct(a, m, r, 1);
  50748. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50749. return WC_TEST_RET_ENC_EC(ret);
  50750. mp_set(a, 1);
  50751. mp_set(m, 2);
  50752. ret = mp_invmod_mont_ct(a, m, r, 1);
  50753. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50754. return WC_TEST_RET_ENC_EC(ret);
  50755. mp_set(a, 1);
  50756. mp_set(m, 3);
  50757. ret = mp_invmod_mont_ct(a, m, r, 1);
  50758. if (ret != MP_OKAY)
  50759. return WC_TEST_RET_ENC_EC(ret);
  50760. #endif
  50761. return 0;
  50762. }
  50763. #endif /* !NO_RSA || HAVE_ECC || !NO_DSA || OPENSSL_EXTRA */
  50764. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  50765. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  50766. static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r)
  50767. {
  50768. wc_test_ret_t ret;
  50769. mp_set(b, 0x2);
  50770. mp_set(e, 0x3);
  50771. mp_set(m, 0x0);
  50772. ret = mp_exptmod_ex(b, e, 1, m, r);
  50773. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50774. return WC_TEST_RET_ENC_EC(ret);
  50775. ret = mp_exptmod_nct(b, e, m, r);
  50776. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50777. return WC_TEST_RET_ENC_EC(ret);
  50778. mp_set(b, 0x2);
  50779. mp_set(e, 0x3);
  50780. mp_set(m, 0x1);
  50781. ret = mp_exptmod_ex(b, e, 1, m, r);
  50782. if (ret != MP_OKAY)
  50783. return WC_TEST_RET_ENC_EC(ret);
  50784. if (!mp_iszero(r))
  50785. return WC_TEST_RET_ENC_NC;
  50786. ret = mp_exptmod_nct(b, e, m, r);
  50787. if (ret != MP_OKAY)
  50788. return WC_TEST_RET_ENC_EC(ret);
  50789. if (!mp_iszero(r))
  50790. return WC_TEST_RET_ENC_NC;
  50791. mp_set(b, 0x2);
  50792. mp_set(e, 0x0);
  50793. mp_set(m, 0x7);
  50794. ret = mp_exptmod_ex(b, e, 1, m, r);
  50795. if (ret != MP_OKAY)
  50796. return WC_TEST_RET_ENC_EC(ret);
  50797. if (!mp_isone(r))
  50798. return WC_TEST_RET_ENC_NC;
  50799. ret = mp_exptmod_nct(b, e, m, r);
  50800. if (ret != MP_OKAY)
  50801. return WC_TEST_RET_ENC_EC(ret);
  50802. if (!mp_isone(r))
  50803. return WC_TEST_RET_ENC_NC;
  50804. mp_set(b, 0x0);
  50805. mp_set(e, 0x3);
  50806. mp_set(m, 0x7);
  50807. ret = mp_exptmod_ex(b, e, 1, m, r);
  50808. if (ret != MP_OKAY)
  50809. return WC_TEST_RET_ENC_EC(ret);
  50810. if (!mp_iszero(r))
  50811. return WC_TEST_RET_ENC_NC;
  50812. ret = mp_exptmod_nct(b, e, m, r);
  50813. if (ret != MP_OKAY)
  50814. return WC_TEST_RET_ENC_EC(ret);
  50815. if (!mp_iszero(r))
  50816. return WC_TEST_RET_ENC_NC;
  50817. mp_set(b, 0x10);
  50818. mp_set(e, 0x3);
  50819. mp_set(m, 0x7);
  50820. ret = mp_exptmod_ex(b, e, 1, m, r);
  50821. if (ret != MP_OKAY)
  50822. return WC_TEST_RET_ENC_EC(ret);
  50823. ret = mp_exptmod_nct(b, e, m, r);
  50824. if (ret != MP_OKAY)
  50825. return WC_TEST_RET_ENC_EC(ret);
  50826. mp_set(b, 0x7);
  50827. mp_set(e, 0x3);
  50828. mp_set(m, 0x7);
  50829. ret = mp_exptmod_ex(b, e, 1, m, r);
  50830. if (ret != MP_OKAY)
  50831. return WC_TEST_RET_ENC_EC(ret);
  50832. if (!mp_iszero(r))
  50833. return WC_TEST_RET_ENC_NC;
  50834. ret = mp_exptmod_nct(b, e, m, r);
  50835. if (ret != MP_OKAY)
  50836. return WC_TEST_RET_ENC_EC(ret);
  50837. if (!mp_iszero(r))
  50838. return WC_TEST_RET_ENC_NC;
  50839. #ifndef WOLFSSL_SP_MATH
  50840. mp_set(b, 0x01);
  50841. mp_mul_2d(b, DIGIT_BIT, b);
  50842. mp_add_d(b, 1, b);
  50843. mp_set(e, 0x3);
  50844. mp_copy(b, m);
  50845. ret = mp_exptmod_ex(b, e, 1, m, r);
  50846. if (ret != MP_OKAY)
  50847. return WC_TEST_RET_ENC_EC(ret);
  50848. if (!mp_iszero(r))
  50849. return WC_TEST_RET_ENC_NC;
  50850. ret = mp_exptmod_nct(b, e, m, r);
  50851. if (ret != MP_OKAY)
  50852. return WC_TEST_RET_ENC_EC(ret);
  50853. if (!mp_iszero(r))
  50854. return WC_TEST_RET_ENC_NC;
  50855. #endif
  50856. mp_set(b, 0x2);
  50857. mp_set(e, 0x3);
  50858. mp_set(m, 0x7);
  50859. ret = mp_exptmod_ex(b, e, 1, m, r);
  50860. if (ret != MP_OKAY)
  50861. return WC_TEST_RET_ENC_EC(ret);
  50862. ret = mp_exptmod_nct(b, e, m, r);
  50863. if (ret != MP_OKAY)
  50864. return WC_TEST_RET_ENC_EC(ret);
  50865. #ifdef WOLFSSL_SP_MATH_ALL
  50866. mp_set(b, 0x2);
  50867. mp_set(e, 0x3);
  50868. mp_set(m, 0x01);
  50869. mp_mul_2d(m, SP_WORD_SIZE * SP_INT_DIGITS / 2, m);
  50870. mp_add_d(m, 0x01, m);
  50871. ret = mp_exptmod_ex(b, e, 1, m, r);
  50872. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50873. return WC_TEST_RET_ENC_EC(ret);
  50874. ret = mp_exptmod_nct(b, e, m, r);
  50875. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50876. return WC_TEST_RET_ENC_EC(ret);
  50877. #endif
  50878. return 0;
  50879. }
  50880. #endif /* !NO_RSA || !NO_DSA || !NO_DH || (HAVE_ECC && HAVE_COMP_KEY) ||
  50881. * OPENSSL_EXTRA */
  50882. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50883. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50884. static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng)
  50885. {
  50886. wc_test_ret_t ret;
  50887. mp_digit mp;
  50888. static int exp[] = { 7, 8, 16, 27, 32, 64,
  50889. 127, 128, 255, 256,
  50890. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  50891. 383, 384, 2033, 2048
  50892. #endif
  50893. };
  50894. static mp_digit sub[] = { 0x01, 0x05, 0x0f, 0x27, 0x05, 0x3b,
  50895. 0x01, 0x9f, 0x13, 0xbd,
  50896. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  50897. 0x1f, 0x13d, 0x45, 0x615
  50898. #endif
  50899. };
  50900. int bits[] = { 256, 384,
  50901. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 4096
  50902. 2048,
  50903. #endif
  50904. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 6144
  50905. 3072
  50906. #endif
  50907. };
  50908. int i;
  50909. int j;
  50910. for (i = 0; i < (int)(sizeof(exp) / sizeof(*exp)); i++) {
  50911. if (exp[i] >= DIGIT_BIT)
  50912. continue;
  50913. mp_zero(m);
  50914. ret = mp_set_bit(m, exp[i]);
  50915. if (ret != MP_OKAY)
  50916. return WC_TEST_RET_ENC_EC(ret);
  50917. ret = mp_sub_d(m, sub[i], m);
  50918. if (ret != MP_OKAY)
  50919. return WC_TEST_RET_ENC_EC(ret);
  50920. ret = mp_montgomery_setup(m, &mp);
  50921. if (ret != MP_OKAY)
  50922. return WC_TEST_RET_ENC_EC(ret);
  50923. ret = mp_montgomery_calc_normalization(n, m);
  50924. if (ret != MP_OKAY)
  50925. return WC_TEST_RET_ENC_EC(ret);
  50926. for (j = 0; j < 10; j++) {
  50927. ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL);
  50928. if (ret != 0)
  50929. return WC_TEST_RET_ENC_EC(ret);
  50930. ret = mp_mod(a, m, a);
  50931. if (ret != 0)
  50932. return WC_TEST_RET_ENC_EC(ret);
  50933. /* r = a * a */
  50934. ret = mp_sqrmod(a, m, r);
  50935. if (ret != MP_OKAY)
  50936. return WC_TEST_RET_ENC_EC(ret);
  50937. /* Convert to Montgomery form = a*n */
  50938. ret = mp_mulmod(a, n, m, a);
  50939. if (ret != MP_OKAY)
  50940. return WC_TEST_RET_ENC_EC(ret);
  50941. /* a*a mod m == ((a*n) * (a*n)) / n / n */
  50942. ret = mp_sqr(a, a);
  50943. if (ret != MP_OKAY)
  50944. return WC_TEST_RET_ENC_EC(ret);
  50945. ret = mp_montgomery_reduce(a, m, mp);
  50946. if (ret != MP_OKAY)
  50947. return WC_TEST_RET_ENC_EC(ret);
  50948. ret = mp_montgomery_reduce(a, m, mp);
  50949. if (ret != MP_OKAY)
  50950. return WC_TEST_RET_ENC_EC(ret);
  50951. if (mp_cmp(a, r) != MP_EQ)
  50952. return WC_TEST_RET_ENC_NC;
  50953. }
  50954. }
  50955. /* Force carries. */
  50956. for (i = 0; i < (int)(sizeof(bits) / sizeof(*bits)); i++) {
  50957. /* a = 2^(bits*2) - 1 */
  50958. mp_zero(a);
  50959. mp_set_bit(a, bits[i] * 2);
  50960. ret = mp_sub_d(a, 1, a);
  50961. if (ret != MP_OKAY)
  50962. return WC_TEST_RET_ENC_EC(ret);
  50963. /* m = 2^(bits) - 1 */
  50964. mp_zero(m);
  50965. mp_set_bit(m, bits[i]);
  50966. ret = mp_sub_d(m, 1, m);
  50967. if (ret != MP_OKAY)
  50968. return WC_TEST_RET_ENC_EC(ret);
  50969. mp = 1;
  50970. /* result = r = 2^(bits) - 1 */
  50971. mp_zero(r);
  50972. mp_set_bit(r, bits[i]);
  50973. ret = mp_sub_d(r, 1, r);
  50974. if (ret != MP_OKAY)
  50975. return WC_TEST_RET_ENC_EC(ret);
  50976. ret = mp_montgomery_reduce(a, m, mp);
  50977. if (ret != MP_OKAY)
  50978. return WC_TEST_RET_ENC_EC(ret);
  50979. /* Result is m or 0 if reduced to range of modulus. */
  50980. if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES)
  50981. return WC_TEST_RET_ENC_NC;
  50982. }
  50983. return 0;
  50984. }
  50985. #endif
  50986. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
  50987. {
  50988. WC_RNG rng;
  50989. int rng_inited = 0;
  50990. wc_test_ret_t ret;
  50991. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  50992. int i, j;
  50993. #ifndef WOLFSSL_SP_MATH
  50994. int k;
  50995. #endif
  50996. mp_digit d = 0;
  50997. #endif
  50998. #ifdef WOLFSSL_SMALL_STACK
  50999. mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51000. DYNAMIC_TYPE_TMP_BUFFER),
  51001. *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51002. DYNAMIC_TYPE_TMP_BUFFER),
  51003. *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51004. DYNAMIC_TYPE_TMP_BUFFER),
  51005. *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51006. DYNAMIC_TYPE_TMP_BUFFER),
  51007. *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51008. DYNAMIC_TYPE_TMP_BUFFER);
  51009. if ((a == NULL) ||
  51010. (b == NULL) ||
  51011. (r1 == NULL) ||
  51012. (r2 == NULL) ||
  51013. (p == NULL))
  51014. {
  51015. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  51016. }
  51017. #else
  51018. mp_int a[1], b[1], r1[1], r2[1], p[1];
  51019. #endif
  51020. WOLFSSL_ENTER("mp_test");
  51021. ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
  51022. if (ret != 0)
  51023. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51024. #ifdef WOLFSSL_SP_MATH_ALL
  51025. mp_init_copy(p, a);
  51026. #else
  51027. ret = mp_init(p);
  51028. if (ret != 0)
  51029. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51030. #endif
  51031. #ifndef HAVE_FIPS
  51032. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  51033. #else
  51034. ret = wc_InitRng(&rng);
  51035. #endif
  51036. if (ret != 0)
  51037. goto done;
  51038. rng_inited = 1;
  51039. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51040. mp_set_int(a, 0);
  51041. if (a->used != 0 || a->dp[0] != 0)
  51042. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51043. for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) {
  51044. for (i = 0; i < 4 * j; i++) {
  51045. /* New values to use. */
  51046. ret = randNum(p, j, &rng, NULL);
  51047. if (ret != 0)
  51048. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51049. ret = randNum(a, j, &rng, NULL);
  51050. if (ret != 0)
  51051. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51052. ret = randNum(b, j, &rng, NULL);
  51053. if (ret != 0)
  51054. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51055. ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d));
  51056. if (ret != 0)
  51057. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51058. d &= MP_MASK;
  51059. #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \
  51060. (defined(ECC_SHAMIR) || defined(FP_ECC)))
  51061. /* Ensure sqrmod produce same result as mulmod. */
  51062. ret = mp_sqrmod(a, p, r1);
  51063. if (ret != 0)
  51064. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51065. ret = mp_mulmod(a, a, p, r2);
  51066. if (ret != 0)
  51067. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51068. if (mp_cmp(r1, r2) != 0) {
  51069. WOLFSSL_MSG("Fail: mp_mulmod result does not match mp_sqrmod!");
  51070. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51071. }
  51072. #endif
  51073. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51074. #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \
  51075. !defined(WOLFSSL_SP_INT_NEGATIVE))
  51076. ret = mp_addmod(a, b, p, r1);
  51077. if (ret != 0)
  51078. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51079. ret = mp_submod(r1, b, p, r2);
  51080. if (ret != 0)
  51081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51082. ret = mp_mod(a, p, r1);
  51083. if (ret != 0)
  51084. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51085. if (mp_cmp(r1, r2) != MP_EQ)
  51086. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51087. #else
  51088. /* Ensure add with mod produce same result as sub with mod. */
  51089. ret = mp_addmod(a, b, p, r1);
  51090. if (ret != 0)
  51091. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51092. b->sign ^= 1;
  51093. ret = mp_submod(a, b, p, r2);
  51094. if (ret != 0)
  51095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51096. if (mp_cmp(r1, r2) != 0)
  51097. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51098. #endif
  51099. #endif
  51100. /* Ensure add digit produce same result as sub digit. */
  51101. ret = mp_add_d(a, d, r1);
  51102. if (ret != 0)
  51103. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51104. ret = mp_sub_d(r1, d, r2);
  51105. if (ret != 0)
  51106. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51107. if (mp_cmp(a, r2) != 0)
  51108. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51109. /* Invert - if p is even it will use the slow impl.
  51110. * - if p and a are even it will fail.
  51111. */
  51112. ret = mp_invmod(a, p, r1);
  51113. if (ret != 0 && ret != WC_NO_ERR_TRACE(MP_VAL))
  51114. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51115. #ifndef WOLFSSL_SP_MATH
  51116. /* Shift up and down number all bits in a digit. */
  51117. for (k = 0; k < DIGIT_BIT; k++) {
  51118. mp_mul_2d(a, k, r1);
  51119. mp_div_2d(r1, k, r2, p);
  51120. if (mp_cmp(a, r2) != 0)
  51121. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51122. if (!mp_iszero(p))
  51123. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51124. mp_rshb(r1, k);
  51125. if (mp_cmp(a, r1) != 0)
  51126. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51127. }
  51128. #endif
  51129. }
  51130. }
  51131. /* Test adding and subtracting zero from zero. */
  51132. mp_zero(a);
  51133. ret = mp_add_d(a, 0, r1);
  51134. if (ret != 0)
  51135. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51136. if (!mp_iszero(r1)) {
  51137. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51138. }
  51139. ret = mp_sub_d(a, 0, r2);
  51140. if (ret != 0)
  51141. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51142. if (!mp_iszero(r2)) {
  51143. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51144. }
  51145. #if DIGIT_BIT >= 32
  51146. /* Check that setting a 32-bit digit works. */
  51147. d &= 0xffffffffU;
  51148. mp_set_int(a, d);
  51149. if (a->used != 1 || a->dp[0] != d)
  51150. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51151. #endif
  51152. /* Check setting a bit and testing a bit works. */
  51153. for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) {
  51154. mp_zero(a);
  51155. mp_set_bit(a, i);
  51156. if (!mp_is_bit_set(a, i))
  51157. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51158. }
  51159. #endif
  51160. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  51161. mp_zero(a);
  51162. i = mp_cnt_lsb(a);
  51163. if (i != 0)
  51164. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51165. mp_set(a, 1);
  51166. i = mp_cnt_lsb(a);
  51167. if (i != 0)
  51168. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51169. mp_set(a, 32);
  51170. i = mp_cnt_lsb(a);
  51171. if (i != 5)
  51172. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51173. mp_zero(a);
  51174. mp_set_bit(a, 129);
  51175. i = mp_cnt_lsb(a);
  51176. if (i != 129)
  51177. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51178. #endif
  51179. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51180. if ((ret = mp_test_param(a, b, r1, &rng)) != 0)
  51181. goto done;
  51182. #endif
  51183. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  51184. if ((ret = mp_test_div_3(a, r1, &rng)) != 0)
  51185. goto done;
  51186. #endif
  51187. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  51188. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  51189. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  51190. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  51191. if ((ret = mp_test_radix_10(a, r1, &rng)) != 0)
  51192. goto done;
  51193. #endif
  51194. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  51195. defined(HAVE_ECC))
  51196. if ((ret = mp_test_radix_16(a, r1, &rng)) != 0)
  51197. goto done;
  51198. #endif
  51199. if ((ret = mp_test_shift(a, r1, &rng)) != 0)
  51200. goto done;
  51201. if ((ret = mp_test_add_sub_d(a, r1)) != 0)
  51202. goto done;
  51203. if ((ret = mp_test_read_to_bin(a)) != 0)
  51204. goto done;
  51205. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51206. if ((ret = mp_test_set_int(a)) != 0)
  51207. goto done;
  51208. #endif
  51209. if ((ret = mp_test_cmp(a, r1)) != 0)
  51210. goto done;
  51211. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51212. if ((ret = mp_test_shbd(a, b, &rng)) != 0)
  51213. goto done;
  51214. #endif
  51215. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51216. if ((ret = mp_test_set_is_bit(a)) != 0)
  51217. goto done;
  51218. #endif
  51219. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  51220. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  51221. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  51222. if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
  51223. goto done;
  51224. #endif
  51225. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  51226. !defined(WC_NO_RNG)
  51227. if ((ret = mp_test_prime(a, &rng)) != 0)
  51228. goto done;
  51229. #endif
  51230. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  51231. if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0)
  51232. goto done;
  51233. #endif
  51234. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  51235. defined(WOLFSSL_SP_MATH_ALL)
  51236. if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0)
  51237. goto done;
  51238. #endif
  51239. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  51240. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  51241. if ((ret = mp_test_mod_d(a, &rng)) != 0)
  51242. goto done;
  51243. #endif
  51244. if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
  51245. goto done;
  51246. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  51247. defined(OPENSSL_EXTRA)
  51248. if ((ret = mp_test_invmod(a, b, r1)) != 0)
  51249. goto done;
  51250. #endif
  51251. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51252. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51253. if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0)
  51254. goto done;
  51255. #endif
  51256. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51257. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51258. if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0)
  51259. goto done;
  51260. #endif
  51261. done:
  51262. #ifdef WOLFSSL_SMALL_STACK
  51263. if (p) {
  51264. mp_clear(p);
  51265. XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51266. }
  51267. if (r2) {
  51268. mp_clear(r2);
  51269. XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51270. }
  51271. if (r1) {
  51272. mp_clear(r1);
  51273. XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51274. }
  51275. if (b) {
  51276. mp_clear(b);
  51277. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51278. }
  51279. if (a) {
  51280. mp_clear(a);
  51281. XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51282. }
  51283. #else
  51284. mp_clear(p);
  51285. mp_clear(r2);
  51286. mp_clear(r1);
  51287. mp_clear(b);
  51288. mp_clear(a);
  51289. #endif
  51290. if (rng_inited)
  51291. wc_FreeRng(&rng);
  51292. return ret;
  51293. }
  51294. #endif /* WOLFSSL_PUBLIC_MP && ((WOLFSSL_SP_MATH_ALL &&
  51295. * !WOLFSSL_RSA_VERIFY_ONLY) || USE_FAST_MATH) */
  51296. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  51297. typedef struct pairs_t {
  51298. const unsigned char* coeff;
  51299. int coeffSz;
  51300. int exp;
  51301. } pairs_t;
  51302. /*
  51303. n =p1p2p3, where pi = ki(p1-1)+1 with (k2,k3) = (173,293)
  51304. p1 = 2^192 * 0x000000000000e24fd4f6d6363200bf2323ec46285cac1d3a
  51305. + 2^0 * 0x0b2488b0c29d96c5e67f8bec15b54b189ae5636efe89b45b
  51306. */
  51307. static const unsigned char c192a[] =
  51308. {
  51309. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x4f,
  51310. 0xd4, 0xf6, 0xd6, 0x36, 0x32, 0x00, 0xbf, 0x23,
  51311. 0x23, 0xec, 0x46, 0x28, 0x5c, 0xac, 0x1d, 0x3a
  51312. };
  51313. static const unsigned char c0a[] =
  51314. {
  51315. 0x0b, 0x24, 0x88, 0xb0, 0xc2, 0x9d, 0x96, 0xc5,
  51316. 0xe6, 0x7f, 0x8b, 0xec, 0x15, 0xb5, 0x4b, 0x18,
  51317. 0x9a, 0xe5, 0x63, 0x6e, 0xfe, 0x89, 0xb4, 0x5b
  51318. };
  51319. static const pairs_t ecPairsA[] =
  51320. {
  51321. {c192a, sizeof(c192a), 192},
  51322. {c0a, sizeof(c0a), 0}
  51323. };
  51324. static const int kA[] = {173, 293};
  51325. static const unsigned char controlPrime[] = {
  51326. 0xe1, 0x76, 0x45, 0x80, 0x59, 0xb6, 0xd3, 0x49,
  51327. 0xdf, 0x0a, 0xef, 0x12, 0xd6, 0x0f, 0xf0, 0xb7,
  51328. 0xcb, 0x2a, 0x37, 0xbf, 0xa7, 0xf8, 0xb5, 0x4d,
  51329. 0xf5, 0x31, 0x35, 0xad, 0xe4, 0xa3, 0x94, 0xa1,
  51330. 0xdb, 0xf1, 0x96, 0xad, 0xb5, 0x05, 0x64, 0x85,
  51331. 0x83, 0xfc, 0x1b, 0x5b, 0x29, 0xaa, 0xbe, 0xf8,
  51332. 0x26, 0x3f, 0x76, 0x7e, 0xad, 0x1c, 0xf0, 0xcb,
  51333. 0xd7, 0x26, 0xb4, 0x1b, 0x05, 0x8e, 0x56, 0x86,
  51334. 0x7e, 0x08, 0x62, 0x21, 0xc1, 0x86, 0xd6, 0x47,
  51335. 0x79, 0x3e, 0xb7, 0x5d, 0xa4, 0xc6, 0x3a, 0xd7,
  51336. 0xb1, 0x74, 0x20, 0xf6, 0x50, 0x97, 0x41, 0x04,
  51337. 0x53, 0xed, 0x3f, 0x26, 0xd6, 0x6f, 0x91, 0xfa,
  51338. 0x68, 0x26, 0xec, 0x2a, 0xdc, 0x9a, 0xf1, 0xe7,
  51339. 0xdc, 0xfb, 0x73, 0xf0, 0x79, 0x43, 0x1b, 0x21,
  51340. 0xa3, 0x59, 0x04, 0x63, 0x52, 0x07, 0xc9, 0xd7,
  51341. 0xe6, 0xd1, 0x1b, 0x5d, 0x5e, 0x96, 0xfa, 0x53
  51342. };
  51343. static const unsigned char testOne[] = { 1 };
  51344. static wc_test_ret_t GenerateNextP(mp_int* p1, mp_int* p2, int k)
  51345. {
  51346. wc_test_ret_t ret;
  51347. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51348. mp_int *ki = (mp_int *)XMALLOC(sizeof(*ki), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51349. if (ki == NULL)
  51350. return MEMORY_E;
  51351. #else
  51352. mp_int ki[1];
  51353. #endif
  51354. ret = mp_init(ki);
  51355. if (ret != 0)
  51356. ret = WC_TEST_RET_ENC_EC(ret);
  51357. if (ret == 0) {
  51358. ret = mp_set(ki, (mp_digit)k);
  51359. if (ret != 0)
  51360. ret = WC_TEST_RET_ENC_EC(ret);
  51361. }
  51362. if (ret == 0) {
  51363. ret = mp_sub_d(p1, 1, p2);
  51364. if (ret != 0)
  51365. ret = WC_TEST_RET_ENC_EC(ret);
  51366. }
  51367. if (ret == 0) {
  51368. ret = mp_mul(p2, ki, p2);
  51369. if (ret != 0)
  51370. ret = WC_TEST_RET_ENC_EC(ret);
  51371. }
  51372. if (ret == 0) {
  51373. ret = mp_add_d(p2, 1, p2);
  51374. if (ret != 0)
  51375. ret = WC_TEST_RET_ENC_EC(ret);
  51376. }
  51377. mp_clear(ki);
  51378. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51379. XFREE(ki, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51380. #endif
  51381. return ret;
  51382. }
  51383. static wc_test_ret_t GenerateP(mp_int* p1, mp_int* p2, mp_int* p3,
  51384. const pairs_t* ecPairs, int ecPairsSz,
  51385. const int* k)
  51386. {
  51387. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51388. mp_int *x = NULL, *y = NULL;
  51389. #else
  51390. mp_int x[1], y[1];
  51391. #endif
  51392. wc_test_ret_t ret;
  51393. int i;
  51394. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51395. if (((x = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) ||
  51396. ((y = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)) {
  51397. ret = MEMORY_E;
  51398. goto out;
  51399. }
  51400. #endif
  51401. ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL);
  51402. if (ret != 0) {
  51403. ret = WC_TEST_RET_ENC_EC(ret);
  51404. goto out;
  51405. }
  51406. for (i = 0; ret == 0 && i < ecPairsSz; i++) {
  51407. ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, (word32)ecPairs[i].coeffSz);
  51408. if (ret != 0) {
  51409. ret = WC_TEST_RET_ENC_EC(ret);
  51410. break;
  51411. }
  51412. /* p1 = 2^exp */
  51413. ret = mp_2expt(y, ecPairs[i].exp);
  51414. if (ret != 0) {
  51415. ret = WC_TEST_RET_ENC_EC(ret);
  51416. break;
  51417. }
  51418. /* p1 = p1 * m */
  51419. ret = mp_mul(x, y, x);
  51420. if (ret != 0) {
  51421. ret = WC_TEST_RET_ENC_EC(ret);
  51422. break;
  51423. }
  51424. /* p1 += */
  51425. ret = mp_add(p1, x, p1);
  51426. if (ret != 0) {
  51427. ret = WC_TEST_RET_ENC_EC(ret);
  51428. break;
  51429. }
  51430. mp_zero(x);
  51431. mp_zero(y);
  51432. }
  51433. if (ret == 0)
  51434. ret = GenerateNextP(p1, p2, k[0]);
  51435. if (ret == 0)
  51436. ret = GenerateNextP(p1, p3, k[1]);
  51437. out:
  51438. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51439. if (x != NULL) {
  51440. mp_clear(x);
  51441. XFREE(x, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51442. }
  51443. if (y != NULL) {
  51444. mp_clear(y);
  51445. XFREE(y, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51446. }
  51447. #else
  51448. mp_clear(x);
  51449. mp_clear(y);
  51450. #endif
  51451. return ret;
  51452. }
  51453. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void)
  51454. {
  51455. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51456. mp_int *n = (mp_int *)XMALLOC(sizeof *n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51457. *p1 = (mp_int *)XMALLOC(sizeof *p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51458. *p2 = (mp_int *)XMALLOC(sizeof *p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51459. *p3 = (mp_int *)XMALLOC(sizeof *p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51460. #else
  51461. mp_int n[1],
  51462. p1[1],
  51463. p2[1],
  51464. p3[1];
  51465. #endif
  51466. wc_test_ret_t ret;
  51467. int isPrime = 0;
  51468. WC_RNG rng;
  51469. WOLFSSL_ENTER("prime_test");
  51470. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51471. if ((n == NULL) ||
  51472. (p1 == NULL) ||
  51473. (p2 == NULL) ||
  51474. (p3 == NULL))
  51475. ERROR_OUT(MEMORY_E, out);
  51476. #endif
  51477. ret = wc_InitRng(&rng);
  51478. if (ret != 0)
  51479. ret = WC_TEST_RET_ENC_EC(ret);
  51480. if (ret == 0) {
  51481. ret = mp_init_multi(n, p1, p2, p3, NULL, NULL);
  51482. if (ret != 0)
  51483. ret = WC_TEST_RET_ENC_EC(ret);
  51484. }
  51485. if (ret == 0)
  51486. ret = GenerateP(p1, p2, p3,
  51487. ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA);
  51488. if (ret == 0) {
  51489. ret = mp_mul(p1, p2, n);
  51490. if (ret != 0)
  51491. ret = WC_TEST_RET_ENC_EC(ret);
  51492. }
  51493. if (ret == 0) {
  51494. ret = mp_mul(n, p3, n);
  51495. if (ret != 0)
  51496. ret = WC_TEST_RET_ENC_EC(ret);
  51497. }
  51498. if (ret != 0)
  51499. ERROR_OUT(ret, out);
  51500. /* Check the old prime test using the number that false positives.
  51501. * This test result should indicate as not prime. */
  51502. ret = mp_prime_is_prime(n, 40, &isPrime);
  51503. if (ret != 0)
  51504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51505. if (isPrime)
  51506. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51507. /* This test result should fail. It should indicate the value as prime. */
  51508. ret = mp_prime_is_prime(n, 8, &isPrime);
  51509. if (ret != 0)
  51510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51511. if (!isPrime)
  51512. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51513. /* This test result should indicate the value as not prime. */
  51514. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51515. if (ret != 0)
  51516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51517. if (isPrime)
  51518. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51519. ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime));
  51520. if (ret != 0)
  51521. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51522. /* This test result should indicate the value as prime. */
  51523. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51524. if (ret != 0)
  51525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51526. if (!isPrime)
  51527. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51528. /* This test result should indicate the value as prime. */
  51529. isPrime = -1;
  51530. ret = mp_prime_is_prime(n, 8, &isPrime);
  51531. if (ret != 0)
  51532. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51533. if (!isPrime)
  51534. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51535. ret = mp_read_unsigned_bin(n, testOne, sizeof(testOne));
  51536. if (ret != 0)
  51537. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51538. /* This test result should indicate the value as not prime. */
  51539. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51540. if (ret != 0)
  51541. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51542. if (isPrime)
  51543. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51544. ret = mp_prime_is_prime(n, 8, &isPrime);
  51545. if (ret != 0)
  51546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51547. if (isPrime)
  51548. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51549. ret = 0;
  51550. out:
  51551. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51552. if (n != NULL) {
  51553. mp_clear(n);
  51554. XFREE(n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51555. }
  51556. if (p1 != NULL) {
  51557. mp_clear(p1);
  51558. XFREE(p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51559. }
  51560. if (p2 != NULL) {
  51561. mp_clear(p2);
  51562. XFREE(p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51563. }
  51564. if (p3 != NULL) {
  51565. mp_clear(p3);
  51566. XFREE(p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51567. }
  51568. #else
  51569. mp_clear(p3);
  51570. mp_clear(p2);
  51571. mp_clear(p1);
  51572. mp_clear(n);
  51573. #endif
  51574. wc_FreeRng(&rng);
  51575. return ret;
  51576. }
  51577. #endif /* WOLFSSL_PUBLIC_MP */
  51578. #if defined(ASN_BER_TO_DER) && \
  51579. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  51580. defined(OPENSSL_EXTRA_X509_SMALL))
  51581. /* wc_BerToDer is only public facing in the case of test cert or opensslextra */
  51582. typedef struct berDerTestData {
  51583. const byte *in;
  51584. word32 inSz;
  51585. const byte *out;
  51586. word32 outSz;
  51587. } berDerTestData;
  51588. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void)
  51589. {
  51590. wc_test_ret_t ret;
  51591. int i;
  51592. word32 len = 0, l;
  51593. byte out[32];
  51594. WOLFSSL_SMALL_STACK_STATIC const byte good1_in[] = { 0x30, 0x80, 0x00, 0x00 };
  51595. WOLFSSL_SMALL_STACK_STATIC const byte good1_out[] = { 0x30, 0x00 };
  51596. WOLFSSL_SMALL_STACK_STATIC const byte good2_in[] = { 0x30, 0x80, 0x02, 0x01, 0x01, 0x00, 0x00 };
  51597. WOLFSSL_SMALL_STACK_STATIC const byte good2_out[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51598. WOLFSSL_SMALL_STACK_STATIC const byte good3_in[] = {
  51599. 0x24, 0x80, 0x04, 0x01, 0x01, 0x00, 0x00
  51600. };
  51601. WOLFSSL_SMALL_STACK_STATIC const byte good3_out[] = { 0x04, 0x1, 0x01 };
  51602. WOLFSSL_SMALL_STACK_STATIC const byte good4_in[] = {
  51603. 0x30, 0x80,
  51604. 0x02, 0x01, 0x01,
  51605. 0x30, 0x80,
  51606. 0x24, 0x80,
  51607. 0x04, 0x01, 0x01,
  51608. 0x04, 0x02, 0x02, 0x03,
  51609. 0x00, 0x00,
  51610. 0x06, 0x01, 0x01,
  51611. 0x00, 0x00,
  51612. 0x31, 0x80,
  51613. 0x06, 0x01, 0x01,
  51614. 0x00, 0x00,
  51615. 0x00, 0x00,
  51616. };
  51617. WOLFSSL_SMALL_STACK_STATIC const byte good4_out[] = {
  51618. 0x30, 0x12,
  51619. 0x02, 0x01, 0x01,
  51620. 0x30, 0x08,
  51621. 0x04, 0x03, 0x01, 0x02, 0x03,
  51622. 0x06, 0x01, 0x01,
  51623. 0x31, 0x03,
  51624. 0x06, 0x01, 0x01
  51625. };
  51626. WOLFSSL_SMALL_STACK_STATIC const byte good5_in[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51627. berDerTestData testData[] = {
  51628. { good1_in, sizeof(good1_in), good1_out, sizeof(good1_out) },
  51629. { good2_in, sizeof(good2_in), good2_out, sizeof(good2_out) },
  51630. { good3_in, sizeof(good3_in), good3_out, sizeof(good3_out) },
  51631. { good4_in, sizeof(good4_in), good4_out, sizeof(good4_out) },
  51632. { good5_in, sizeof(good5_in), good5_in , sizeof(good5_in ) },
  51633. };
  51634. WOLFSSL_ENTER("berder_test");
  51635. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  51636. ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len);
  51637. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  51638. return WC_TEST_RET_ENC_I(i);
  51639. if (len != testData[i].outSz)
  51640. return WC_TEST_RET_ENC_I(i);
  51641. len = testData[i].outSz;
  51642. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len);
  51643. if (ret != 0)
  51644. return WC_TEST_RET_ENC_I(i);
  51645. if (XMEMCMP(out, testData[i].out, len) != 0)
  51646. return WC_TEST_RET_ENC_I(i);
  51647. for (l = 1; l < testData[i].inSz; l++) {
  51648. ret = wc_BerToDer(testData[i].in, l, NULL, &len);
  51649. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  51650. return WC_TEST_RET_ENC_EC(ret);
  51651. len = testData[i].outSz;
  51652. ret = wc_BerToDer(testData[i].in, l, out, &len);
  51653. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  51654. return WC_TEST_RET_ENC_EC(ret);
  51655. }
  51656. for (l = 0; l < testData[i].outSz-1; l++) {
  51657. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l);
  51658. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  51659. return WC_TEST_RET_ENC_EC(ret);
  51660. }
  51661. }
  51662. ret = wc_BerToDer(NULL, 4, NULL, NULL);
  51663. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51664. return WC_TEST_RET_ENC_EC(ret);
  51665. ret = wc_BerToDer(out, 4, NULL, NULL);
  51666. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51667. return WC_TEST_RET_ENC_EC(ret);
  51668. ret = wc_BerToDer(NULL, 4, NULL, &len);
  51669. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51670. return WC_TEST_RET_ENC_EC(ret);
  51671. ret = wc_BerToDer(NULL, 4, out, NULL);
  51672. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51673. return WC_TEST_RET_ENC_EC(ret);
  51674. ret = wc_BerToDer(out, 4, out, NULL);
  51675. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51676. return WC_TEST_RET_ENC_EC(ret);
  51677. ret = wc_BerToDer(NULL, 4, out, &len);
  51678. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  51679. return WC_TEST_RET_ENC_EC(ret);
  51680. for (l = 1; l < sizeof(good4_out); l++) {
  51681. len = l;
  51682. ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len);
  51683. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  51684. return WC_TEST_RET_ENC_EC(ret);
  51685. }
  51686. return 0;
  51687. }
  51688. #endif /* ASN_BER_TO_DER && (WOLFSSL_TEST_CERT || OPENSSL_EXTRA ||
  51689. OPENSSL_EXTRA_X509_SMALL */
  51690. #ifdef DEBUG_WOLFSSL
  51691. static THREAD_LS_T int log_cnt = 0;
  51692. static void my_Logging_cb(const int logLevel, const char *const logMessage)
  51693. {
  51694. (void)logLevel;
  51695. (void)logMessage;
  51696. log_cnt++;
  51697. }
  51698. #endif /* DEBUG_WOLFSSL */
  51699. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void)
  51700. {
  51701. wc_test_ret_t ret;
  51702. #ifdef DEBUG_WOLFSSL
  51703. const char* msg = "Testing, testing. 1, 2, 3, 4 ...";
  51704. byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  51705. byte b[256];
  51706. int i;
  51707. WOLFSSL_ENTER("logging_test (debug)");
  51708. for (i = 0; i < (int)sizeof(b); i++)
  51709. b[i] = i;
  51710. ret = wolfSSL_Debugging_ON();
  51711. if (ret != 0)
  51712. return WC_TEST_RET_ENC_EC(ret);
  51713. ret = wolfSSL_SetLoggingCb(my_Logging_cb);
  51714. if (ret != 0)
  51715. return WC_TEST_RET_ENC_EC(ret);
  51716. WOLFSSL_MSG(msg);
  51717. WOLFSSL_BUFFER(a, sizeof(a));
  51718. WOLFSSL_BUFFER(b, sizeof(b));
  51719. WOLFSSL_BUFFER(NULL, 0);
  51720. WOLFSSL_ERROR(MEMORY_E);
  51721. WOLFSSL_ERROR_MSG(msg);
  51722. /* turn off logs */
  51723. wolfSSL_Debugging_OFF();
  51724. /* capture log count */
  51725. i = log_cnt;
  51726. /* validate no logs are output when disabled */
  51727. WOLFSSL_MSG(msg);
  51728. WOLFSSL_BUFFER(a, sizeof(a));
  51729. WOLFSSL_BUFFER(b, sizeof(b));
  51730. WOLFSSL_BUFFER(NULL, 0);
  51731. WOLFSSL_ERROR(MEMORY_E);
  51732. WOLFSSL_ERROR_MSG(msg);
  51733. /* check the logs were disabled */
  51734. if (i != log_cnt)
  51735. return WC_TEST_RET_ENC_NC;
  51736. /* restore callback and leave logging enabled */
  51737. wolfSSL_SetLoggingCb(NULL);
  51738. wolfSSL_Debugging_ON();
  51739. /* suppress unused args */
  51740. (void)a;
  51741. (void)b;
  51742. #else
  51743. WOLFSSL_ENTER("logging_test");
  51744. ret = wolfSSL_Debugging_ON();
  51745. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  51746. return WC_TEST_RET_ENC_EC(ret);
  51747. wolfSSL_Debugging_OFF();
  51748. ret = wolfSSL_SetLoggingCb(NULL);
  51749. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  51750. return WC_TEST_RET_ENC_EC(ret);
  51751. #endif /* DEBUG_WOLFSSL */
  51752. return 0;
  51753. }
  51754. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  51755. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void)
  51756. #else
  51757. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void)
  51758. #endif
  51759. {
  51760. #ifdef WOLFSSL_PTHREADS
  51761. wolfSSL_Mutex m;
  51762. #endif
  51763. #if defined(WOLFSSL_PTHREADS) || (!defined(WOLFSSL_NO_MALLOC) && \
  51764. !defined(WOLFSSL_USER_MUTEX) && defined(WOLFSSL_STATIC_MEMORY))
  51765. wc_test_ret_t ret;
  51766. #endif
  51767. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX)
  51768. #ifndef WOLFSSL_STATIC_MEMORY
  51769. wolfSSL_Mutex *mm = wc_InitAndAllocMutex();
  51770. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (1)");
  51771. #else
  51772. wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex),
  51773. HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51774. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (2)");
  51775. if (mm != NULL) {
  51776. ret = wc_InitMutex(mm);
  51777. if (ret != 0) {
  51778. WOLFSSL_MSG("Init Mutex failed");
  51779. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51780. return WC_TEST_RET_ENC_EC(ret);
  51781. }
  51782. }
  51783. #endif
  51784. if (mm == NULL)
  51785. return WC_TEST_RET_ENC_ERRNO;
  51786. wc_FreeMutex(mm);
  51787. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  51788. #endif
  51789. /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */
  51790. #ifdef WOLFSSL_PTHREADS
  51791. ret = wc_InitMutex(&m);
  51792. if (ret != 0)
  51793. return WC_TEST_RET_ENC_EC(ret);
  51794. ret = wc_LockMutex(&m);
  51795. if (ret != 0)
  51796. return WC_TEST_RET_ENC_EC(ret);
  51797. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  51798. /* trying to free a locked mutex is not portable behavior with pthread */
  51799. /* Attempting to destroy a locked mutex results in undefined behavior */
  51800. ret = wc_FreeMutex(&m);
  51801. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51802. return WC_TEST_RET_ENC_EC(ret);
  51803. #endif
  51804. ret = wc_UnLockMutex(&m);
  51805. if (ret != 0)
  51806. return WC_TEST_RET_ENC_EC(ret);
  51807. ret = wc_FreeMutex(&m);
  51808. if (ret != 0)
  51809. return WC_TEST_RET_ENC_EC(ret);
  51810. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  51811. /* Trying to use a pthread after free'ing is not portable behavior */
  51812. ret = wc_LockMutex(&m);
  51813. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51814. return WC_TEST_RET_ENC_EC(ret);
  51815. ret = wc_UnLockMutex(&m);
  51816. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  51817. return WC_TEST_RET_ENC_EC(ret);
  51818. #endif
  51819. #endif
  51820. return 0;
  51821. }
  51822. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  51823. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \
  51824. !defined(WOLFSSL_STATIC_MEMORY)
  51825. static wc_test_ret_t malloc_cnt = 0;
  51826. static wc_test_ret_t realloc_cnt = 0;
  51827. static wc_test_ret_t free_cnt = 0;
  51828. #ifdef WOLFSSL_DEBUG_MEMORY
  51829. static void *my_Malloc_cb(size_t size, const char* func, unsigned int line)
  51830. {
  51831. (void) func;
  51832. (void) line;
  51833. #else
  51834. static void *my_Malloc_cb(size_t size)
  51835. {
  51836. #endif
  51837. malloc_cnt++;
  51838. #ifndef WOLFSSL_NO_MALLOC
  51839. return malloc(size);
  51840. #else
  51841. WOLFSSL_MSG("No malloc available");
  51842. (void)size;
  51843. return NULL;
  51844. #endif
  51845. }
  51846. #ifdef WOLFSSL_DEBUG_MEMORY
  51847. static void my_Free_cb(void *ptr, const char* func, unsigned int line)
  51848. {
  51849. (void) func;
  51850. (void) line;
  51851. #else
  51852. static void my_Free_cb(void *ptr)
  51853. {
  51854. #endif
  51855. free_cnt++;
  51856. #ifndef WOLFSSL_NO_MALLOC
  51857. free(ptr);
  51858. #else
  51859. WOLFSSL_MSG("No free available");
  51860. (void)ptr;
  51861. #endif
  51862. }
  51863. #ifdef WOLFSSL_DEBUG_MEMORY
  51864. static void *my_Realloc_cb(void *ptr, size_t size, const char* func, unsigned int line)
  51865. {
  51866. (void) func;
  51867. (void) line;
  51868. #else
  51869. static void *my_Realloc_cb(void *ptr, size_t size)
  51870. {
  51871. #endif
  51872. realloc_cnt++;
  51873. #ifndef WOLFSSL_NO_MALLOC
  51874. return realloc(ptr, size);
  51875. #else
  51876. WOLFSSL_MSG("No realloc available");
  51877. (void)ptr;
  51878. (void)size;
  51879. return NULL;
  51880. #endif
  51881. }
  51882. #endif /* !WOLFSSL_NO_MALLOC */
  51883. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void)
  51884. {
  51885. wc_test_ret_t ret = 0;
  51886. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51887. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51888. byte* b = NULL;
  51889. #endif
  51890. wolfSSL_Malloc_cb mc;
  51891. wolfSSL_Free_cb fc;
  51892. wolfSSL_Realloc_cb rc;
  51893. WOLFSSL_ENTER("memcb_test");
  51894. /* Save existing memory callbacks */
  51895. ret = wolfSSL_GetAllocators(&mc, &fc, &rc);
  51896. if (ret != 0)
  51897. return WC_TEST_RET_ENC_EC(ret);
  51898. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51899. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51900. /* test realloc */
  51901. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51902. if (b == NULL) {
  51903. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb);
  51904. }
  51905. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51906. b = NULL;
  51907. /* Use API. */
  51908. ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb,
  51909. (wolfSSL_Free_cb)my_Free_cb,
  51910. (wolfSSL_Realloc_cb)my_Realloc_cb);
  51911. if (ret != 0) {
  51912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb);
  51913. }
  51914. b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51915. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51916. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51917. #ifndef WOLFSSL_STATIC_MEMORY
  51918. #ifndef WOLFSSL_CHECK_MEM_ZERO
  51919. if (malloc_cnt != 1 || free_cnt != 1 || realloc_cnt != 1)
  51920. #else
  51921. /* Checking zeroized memory means realloc is a malloc and free. */
  51922. if (malloc_cnt != 2 || free_cnt != 2 || realloc_cnt != 0)
  51923. #endif
  51924. #else
  51925. if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0)
  51926. #endif
  51927. ret = WC_TEST_RET_ENC_NC;
  51928. #endif /* !WOLFSSL_NO_MALLOC */
  51929. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  51930. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  51931. exit_memcb:
  51932. /* reset malloc/free/realloc counts */
  51933. malloc_cnt = 0;
  51934. free_cnt = 0;
  51935. realloc_cnt = 0;
  51936. #endif
  51937. /* restore memory callbacks */
  51938. wolfSSL_SetAllocators(mc, fc, rc);
  51939. return ret;
  51940. }
  51941. #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */
  51942. #if defined(WOLFSSL_CAAM_BLOB)
  51943. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void)
  51944. {
  51945. wc_test_ret_t ret = 0;
  51946. byte out[112];
  51947. byte blob[112];
  51948. word32 outSz;
  51949. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  51950. {
  51951. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  51952. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  51953. };
  51954. WOLFSSL_SMALL_STACK_STATIC const byte text[] =
  51955. {
  51956. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  51957. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  51958. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  51959. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  51960. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  51961. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  51962. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  51963. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  51964. };
  51965. WOLFSSL_ENTER("blob_test");
  51966. XMEMSET(blob, 0, sizeof(blob));
  51967. XMEMSET(out, 0, sizeof(out));
  51968. outSz = sizeof(blob);
  51969. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  51970. if (ret != 0)
  51971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51972. blob[outSz - 2] += 1;
  51973. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51974. if (ret == 0) { /* should fail with altered blob */
  51975. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51976. }
  51977. XMEMSET(blob, 0, sizeof(blob));
  51978. outSz = sizeof(blob);
  51979. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  51980. if (ret != 0)
  51981. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51982. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51983. if (ret != 0)
  51984. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51985. if (XMEMCMP(out, iv, sizeof(iv))) {
  51986. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51987. }
  51988. XMEMSET(blob, 0, sizeof(blob));
  51989. outSz = sizeof(blob);
  51990. ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz);
  51991. if (ret != 0)
  51992. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51993. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  51994. if (ret != 0)
  51995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  51996. if (XMEMCMP(out, text, sizeof(text))) {
  51997. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  51998. }
  51999. exit_blob:
  52000. return ret;
  52001. }
  52002. #endif /* WOLFSSL_CAAM_BLOB */
  52003. #ifdef WOLF_CRYPTO_CB
  52004. /* Example custom context for crypto callback */
  52005. typedef struct {
  52006. int exampleVar; /* flag for testing if only crypt is enabled. */
  52007. } myCryptoDevCtx;
  52008. #ifdef WOLF_CRYPTO_CB_ONLY_RSA
  52009. /* Testing rsa cb when CB_ONLY_RSA is enabled
  52010. * When CB_ONLY_RSA is enabled, software imple. is not available.
  52011. *
  52012. * ctx callback ctx
  52013. * returen 0 on success, otherwise return negative
  52014. */
  52015. static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
  52016. {
  52017. wc_test_ret_t ret = 0;
  52018. #if !defined(NO_RSA)
  52019. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52020. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key,
  52021. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52022. byte* tmp = NULL;
  52023. #else
  52024. RsaKey key[1];
  52025. byte tmp[FOURK_BUF];
  52026. #endif
  52027. size_t bytes;
  52028. const word32 inLen = (word32)TEST_STRING_SZ;
  52029. word32 idx = 0;
  52030. word32 sigSz;
  52031. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  52032. byte out[RSA_TEST_BYTES];
  52033. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  52034. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  52035. !defined(NO_FILESYSTEM)
  52036. XFILE file;
  52037. #endif
  52038. #ifdef WOLFSSL_KEY_GEN
  52039. WC_RNG rng;
  52040. #endif
  52041. #ifdef USE_CERT_BUFFERS_1024
  52042. bytes = (size_t)sizeof_client_key_der_1024;
  52043. if (bytes < (size_t)sizeof_client_cert_der_1024)
  52044. bytes = (size_t)sizeof_client_cert_der_1024;
  52045. #elif defined(USE_CERT_BUFFERS_2048)
  52046. bytes = (size_t)sizeof_client_key_der_2048;
  52047. if (bytes < (size_t)sizeof_client_cert_der_2048)
  52048. bytes = (size_t)sizeof_client_cert_der_2048;
  52049. #elif defined(USE_CERT_BUFFERS_3072)
  52050. bytes = (size_t)sizeof_client_key_der_3072;
  52051. if (bytes < (size_t)sizeof_client_cert_der_3072)
  52052. bytes = (size_t)sizeof_client_cert_der_3072;
  52053. #elif defined(USE_CERT_BUFFERS_4096)
  52054. bytes = (size_t)sizeof_client_key_der_4096;
  52055. if (bytes < (size_t)sizeof_client_cert_der_4096)
  52056. bytes = (size_t)sizeof_client_cert_der_4096;
  52057. #else
  52058. bytes = FOURK_BUF;
  52059. #endif
  52060. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52061. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52062. if (tmp == NULL)
  52063. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52064. #endif
  52065. #ifdef USE_CERT_BUFFERS_1024
  52066. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  52067. #elif defined(USE_CERT_BUFFERS_2048)
  52068. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  52069. #elif defined(USE_CERT_BUFFERS_3072)
  52070. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  52071. #elif defined(USE_CERT_BUFFERS_4096)
  52072. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  52073. #elif !defined(NO_FILESYSTEM)
  52074. file = XFOPEN(clientKey, "rb");
  52075. if (!file) {
  52076. ret = WC_TEST_RET_ENC_ERRNO;
  52077. err_sys("can't open ./certs/client-key.der, "
  52078. "Please run from wolfSSL home dir", ret);
  52079. ERROR_OUT(ret, exit_onlycb);
  52080. }
  52081. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  52082. XFCLOSE(file);
  52083. if (bytes == 0)
  52084. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52085. #endif
  52086. #ifdef WOLFSSL_KEY_GEN
  52087. /* wc_CryptoCb_MakeRsaKey cb test, no actual making key
  52088. * wc_MakeRsaKey() -> rsa cb ->
  52089. * myCryptoDevCb -> wc_MakeRsaKey(CBONLY_TEST_DEVID)
  52090. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
  52091. */
  52092. ctx->exampleVar = 99;
  52093. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52094. if (ret != 0)
  52095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52096. /* wc_MakeRsaKey() -> rsa cb ->
  52097. * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
  52098. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
  52099. */
  52100. ctx->exampleVar = 1;
  52101. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52102. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52103. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52104. } else
  52105. /* reset return code */
  52106. ret = 0;
  52107. #endif
  52108. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  52109. if (ret != 0)
  52110. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52111. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  52112. if (ret != 0)
  52113. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52114. sigSz = (word32)wc_RsaEncryptSize(key);
  52115. /* wc_CryptoCb_Rsa cb test, no actual rsa operation */
  52116. if (ret == 0) {
  52117. /* wc_SignatureGenerate() -> rsa cb ->
  52118. * myCryptoDevCb -> wc_RsaFunction(CBONLY_TEST_DEVID)
  52119. * wc_RsaFunction(CBONLY_TEST_DEVID) expects to return 0(success)
  52120. */
  52121. ctx->exampleVar = 99;
  52122. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52123. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52124. if (ret != 0)
  52125. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52126. }
  52127. if (ret == 0) {
  52128. /* wc_SignatureGenerate() -> rsa cb ->
  52129. * myCryptoDevCb -> wc_RsaFunction(INVALID_DEVID)
  52130. * wc_SignatureGenerate(INVALID_DEVID) expects to
  52131. * return NO_VALID_DEVID(failure)
  52132. */
  52133. ctx->exampleVar = 1;
  52134. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52135. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52136. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52137. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52138. } else
  52139. /* reset return code */
  52140. ret = 0;
  52141. }
  52142. exit_onlycb:
  52143. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52144. if (key != NULL) {
  52145. wc_FreeRsaKey(key);
  52146. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52147. }
  52148. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52149. #else
  52150. wc_FreeRsaKey(key);
  52151. #endif
  52152. #endif
  52153. return ret;
  52154. }
  52155. #endif
  52156. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  52157. /* Testing rsa cb when CB_ONLY_ECC is enabled
  52158. * When CB_ONLY_ECC is enabled, software imple. is not available.
  52159. *
  52160. * ctx callback ctx
  52161. * returen 0 on success, otherwise return negative
  52162. */
  52163. static wc_test_ret_t ecc_onlycb_test(myCryptoDevCtx *ctx)
  52164. {
  52165. wc_test_ret_t ret = 0;
  52166. #if defined(HAVE_ECC)
  52167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52168. ecc_key* key = (ecc_key *)XMALLOC(sizeof *key,
  52169. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52170. ecc_key* pub = (ecc_key *)XMALLOC(sizeof *pub,
  52171. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52172. byte* out = (byte*)XMALLOC(sizeof(byte),
  52173. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52174. #ifdef OPENSSL_EXTRA
  52175. byte* check = (byte*)XMALLOC(sizeof(byte)*(256), HEAP_HINT,
  52176. DYNAMIC_TYPE_TMP_BUFFER);
  52177. #endif
  52178. #else
  52179. ecc_key key[1];
  52180. ecc_key pub[1];
  52181. byte out[256];
  52182. #ifdef OPENSSL_EXTRA
  52183. unsigned char check[256];
  52184. #endif
  52185. #endif
  52186. #ifdef OPENSSL_EXTRA
  52187. WOLFSSL_EVP_PKEY* privKey = NULL;
  52188. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52189. #ifdef USE_CERT_BUFFERS_256
  52190. ecc_key* pkey;
  52191. const unsigned char* cp;
  52192. #endif
  52193. WOLFSSL_EVP_MD_CTX mdCtx;
  52194. const char testData[] = "Hi There";
  52195. size_t checkSz = -1;
  52196. const unsigned char* p;
  52197. const unsigned char check_v[256] = {
  52198. 0x30,0x45,0x02,0x20,0x1b,0x5c,0x2a,0xf0,0x18,0x09,
  52199. 0x74,0x65,0xa1,0x04,0x76,0x3a,0xce,0xcc,0xe5,0x34,
  52200. 0x5e,0x89,0xed,0x40,0x1e,0x5a,0xb1,0x53,0xb4,0xff,
  52201. 0xc7,0x18,0xfe,0x0f,0xc7,0xa6,0x02,0x21,0x00,0xe5,
  52202. 0x70,0x21,0xfc,0xf9,0x63,0x36,0xfd,0x16,0x18,0x08,
  52203. 0x9a,0x63,0x61,0x0f,0xe7,0x7c,0xa3,0xc9,0x14,0xa3,
  52204. 0x30,0x87,0xf7,0xf5,0x70,0x19,0xaf,0x56,0x96,0x9b,
  52205. 0xd8,0x64,0xcd,0xd9,0xff,0x7b,0x2a,0x55,0x52,0xca,
  52206. 0x41,0xb2,0xa6,0xa4,0x8a,0x3b,0x02,0x20,0x8c,0xc5,
  52207. 0xf9,0xc1,0x7d,0x2a,0x65,0x6c,0xe6,0x5a,0xe3,0x76,
  52208. 0x9b,0xab,0x0b,0x9f,0xaf,0x62,0x5d,0xb2,0x60,0xd7,
  52209. 0xeb,0xb4,0x1b,0x73,0xdc,0x01,0x7d,0x7b,0xab,0xc1,
  52210. 0x0c,0x74,0x96,0x41,0xe6,0x3f,0xc5,0x86,0xe6,0x7d,
  52211. 0x2b,0x9d,0x54,0x6b,0xcd,0x31,0x35,0x1f,0xdb,0x49,
  52212. 0x1f,0x32,0x34,0xf8,0x57,0x12,0x86,0x5c,0x0e,0x80,
  52213. 0x55,0x8d,0xff,0xd8,0xbd,0xdf,0x32,0x26,0x62,0x42,
  52214. 0x09,0xda,0xf7,0x74,0xf2,0x3f,0xe6,0xf1,0x77,0x82,
  52215. 0xce,0xe4,0xbb,0x61,0xa6,0xc0,0x17,0x0c,0x6c,0x47,
  52216. 0x2a,0x40,0x1c,0x2b,0xe0,0x98,0x3b,0xbf,0xc6,0xf8,
  52217. 0x6d,0xfd,0xd0,0xfa,0xc1,0x02,0xfb,0x5f,0xfb,0xb0,
  52218. 0xcb,0xd9,0xa3,0x59,0x94,0xe9,0x0f,0x74,0xbb,0x3f,
  52219. 0x64,0xa3,0x83,0xc4,0x2b,0xf7,0xd2,0x97,0xbf,0x3b,
  52220. 0xcf,0xbb,0x60,0x81,0x33,0x94,0xfa,0x0d,0x35,0xd2,
  52221. 0x3d,0xb9,0x99,0xe3,0x12,0xf8,0xf4,0xa3,0x74,0xf4,
  52222. 0x94,0x1d,0x7a,0x66,0xf8,0xd1,0x1d,0xcf,0xb0,0x48,
  52223. 0xef,0x8c,0x94,0x6f,0xdd,0x62,
  52224. };
  52225. #endif
  52226. WC_RNG rng;
  52227. EncryptedInfo encInfo;
  52228. int keyFormat = 0;
  52229. word32 keyIdx = 0;
  52230. byte in[] = "Everyone gets Friday off. ecc p";
  52231. word32 inLen = (word32)XSTRLEN((char*)in);
  52232. word32 outLen;
  52233. int verify;
  52234. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52235. if (key == NULL || pub == NULL) {
  52236. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52237. }
  52238. #endif
  52239. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  52240. if (ret != 0)
  52241. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52242. /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */
  52243. ctx->exampleVar = 99;
  52244. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52245. if (ret != 0)
  52246. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52247. ctx->exampleVar = 1;
  52248. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52249. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52250. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52251. } else
  52252. /* reset return code */
  52253. ret = 0;
  52254. #ifdef USE_CERT_BUFFERS_256
  52255. if (ret == 0) {
  52256. /* load ECC private key and perform private transform */
  52257. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx,
  52258. key, sizeof_ecc_key_der_256);
  52259. }
  52260. if (ret != 0)
  52261. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52262. /* wc_CryptoCb_EccSign cb test, no actual testing */
  52263. ctx->exampleVar = 99;
  52264. if (ret == 0) {
  52265. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52266. }
  52267. if (ret != 0)
  52268. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52269. ctx->exampleVar = 1;
  52270. if (ret == 0) {
  52271. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52272. }
  52273. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52274. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52275. }
  52276. else
  52277. ret = 0;
  52278. /* wc_CryptoCb_EccVerify cb test, no actual testing */
  52279. ctx->exampleVar = 99;
  52280. if (ret == 0) {
  52281. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52282. }
  52283. if (ret != 0)
  52284. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52285. ctx->exampleVar = 1;
  52286. if (ret == 0) {
  52287. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52288. }
  52289. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52291. }
  52292. else
  52293. ret = 0;
  52294. /* wc_CryptoCb_Ecdh cb test, no actual testing */
  52295. /* make public key for shared secret */
  52296. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  52297. ctx->exampleVar = 99;
  52298. if (ret == 0) {
  52299. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52300. }
  52301. if (ret != 0)
  52302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52303. ctx->exampleVar = 1;
  52304. if (ret == 0) {
  52305. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52306. }
  52307. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52309. }
  52310. else
  52311. ret = 0;
  52312. #ifdef OPENSSL_EXTRA
  52313. (void)pkey;
  52314. cp = ecc_clikey_der_256;
  52315. privKey = d2i_PrivateKey(WC_EVP_PKEY_EC, NULL, &cp,
  52316. sizeof_ecc_clikey_der_256);
  52317. if (privKey == NULL) {
  52318. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52319. }
  52320. pkey = (ecc_key*)privKey->ecc->internal;
  52321. pkey->devId = devId;
  52322. p = ecc_clikeypub_der_256;
  52323. pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256);
  52324. if (pubKey == NULL) {
  52325. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52326. }
  52327. pkey = (ecc_key*)pubKey->ecc->internal;
  52328. pkey->devId = devId;
  52329. /* sign */
  52330. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52331. ret = EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, privKey);
  52332. if (ret != WOLFSSL_SUCCESS) {
  52333. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52334. }
  52335. ret = EVP_DigestSignUpdate(&mdCtx, testData,
  52336. (unsigned int)XSTRLEN(testData));
  52337. if (ret != WOLFSSL_SUCCESS) {
  52338. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52339. }
  52340. ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz);
  52341. if (ret != WOLFSSL_SUCCESS) {
  52342. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52343. }
  52344. ctx->exampleVar = 99;
  52345. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52346. /* just called crypt callback as dummy
  52347. * EVP_DigestSignFinal returns 0 internally.
  52348. */
  52349. if (ret != 0)
  52350. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52351. ctx->exampleVar = 1;
  52352. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52353. /* just called crypt callback as dummy
  52354. * EVP_DigestSignFinal returns 0 internally.
  52355. */
  52356. if (ret != 0)
  52357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52358. /* restore checkSz for verify */
  52359. checkSz = 71;
  52360. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52361. if (ret != WOLFSSL_SUCCESS) {
  52362. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52363. }
  52364. /* verify */
  52365. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52366. if (ret == WOLFSSL_SUCCESS) {
  52367. ret = EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, pubKey);
  52368. }
  52369. if (ret != WOLFSSL_SUCCESS) {
  52370. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52371. }
  52372. if (ret == WOLFSSL_SUCCESS) {
  52373. ret = EVP_DigestVerifyUpdate(&mdCtx, testData,
  52374. (unsigned int)XSTRLEN(testData));
  52375. }
  52376. if (ret != WOLFSSL_SUCCESS) {
  52377. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52378. }
  52379. ctx->exampleVar = 99;
  52380. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52381. /* just called crypt callback as dummy
  52382. * EVP_DigestSignFinal returns 0 internally.
  52383. */
  52384. if (ret != 0)
  52385. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52386. ctx->exampleVar = 1;
  52387. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52388. /* just called crypt callback as dummy
  52389. * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID.
  52390. */
  52391. if (ret != -1) {
  52392. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52393. }
  52394. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52395. if (ret != WOLFSSL_SUCCESS) {
  52396. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52397. } else
  52398. ret = 0;
  52399. #endif
  52400. #else
  52401. (void)verify;
  52402. (void)outLen;
  52403. (void)inLen;
  52404. (void)out;
  52405. (void)pub;
  52406. #ifdef OPENSSL_EXTRA
  52407. (void)privKey;
  52408. (void)pubKey;
  52409. (void)mdCtx;
  52410. (void)check;
  52411. (void)checkSz;
  52412. (void)p;
  52413. #endif
  52414. #endif
  52415. (void)keyFormat;
  52416. (void)encInfo;
  52417. exit_onlycb:
  52418. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52419. if (key != NULL) {
  52420. wc_ecc_free(key);
  52421. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52422. }
  52423. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52424. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52425. #ifdef OPENSSL_EXTRA
  52426. if (check) {
  52427. FREE(check, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52428. }
  52429. #endif
  52430. #else
  52431. wc_ecc_free(key);
  52432. #ifdef OPENSSL_EXTRA
  52433. if (privKey)
  52434. wolfSSL_EVP_PKEY_free(privKey);
  52435. if (pubKey)
  52436. wolfSSL_EVP_PKEY_free(pubKey);
  52437. #endif
  52438. #endif
  52439. #endif /* HAVE_ECC */
  52440. return ret;
  52441. }
  52442. #endif
  52443. /* Example crypto dev callback function that calls software version */
  52444. static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
  52445. {
  52446. int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); /* return this to bypass HW and
  52447. use SW */
  52448. myCryptoDevCtx* myCtx = (myCryptoDevCtx*)ctx;
  52449. if (info == NULL)
  52450. return BAD_FUNC_ARG;
  52451. #ifdef DEBUG_WOLFSSL
  52452. WOLFSSL_MSG_EX("CryptoDevCb: Algo Type %d\n", info->algo_type);
  52453. #endif
  52454. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  52455. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  52456. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  52457. /* if RNG only supports crypto callback, just use seed */
  52458. ret = wc_GenerateSeed(&info->rng.rng->seed,
  52459. info->rng.out, info->rng.sz);
  52460. #elif !defined(WC_NO_RNG)
  52461. /* set devId to invalid, so software is used */
  52462. info->rng.rng->devId = INVALID_DEVID;
  52463. ret = wc_RNG_GenerateBlock(info->rng.rng,
  52464. info->rng.out, info->rng.sz);
  52465. /* reset devId */
  52466. info->rng.rng->devId = devIdArg;
  52467. #endif
  52468. }
  52469. else if (info->algo_type == WC_ALGO_TYPE_SEED) {
  52470. #ifndef WC_NO_RNG
  52471. ALIGN32 static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 };
  52472. word32* seedWord32 = (word32*)seed;
  52473. word32 len;
  52474. /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */
  52475. while (info->seed.sz > 0) {
  52476. len = (word32)sizeof(seed);
  52477. if (info->seed.sz < len)
  52478. len = info->seed.sz;
  52479. XMEMCPY(info->seed.seed, seed, sizeof(seed));
  52480. info->seed.seed += len;
  52481. info->seed.sz -= len;
  52482. (*seedWord32)++;
  52483. }
  52484. ret = 0;
  52485. #endif
  52486. }
  52487. else if (info->algo_type == WC_ALGO_TYPE_PK) {
  52488. #ifdef DEBUG_WOLFSSL
  52489. WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type);
  52490. #endif
  52491. #ifndef NO_RSA
  52492. if (info->pk.type == WC_PK_TYPE_RSA) {
  52493. /* set devId to invalid, so software is used */
  52494. info->pk.rsa.key->devId = INVALID_DEVID;
  52495. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52496. #ifdef DEBUG_WOLFSSL
  52497. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52498. #endif
  52499. if (myCtx->exampleVar == 99) {
  52500. info->pk.rsa.key->devId = devIdArg;
  52501. return 0;
  52502. }
  52503. #endif
  52504. switch (info->pk.rsa.type) {
  52505. case RSA_PUBLIC_ENCRYPT:
  52506. case RSA_PUBLIC_DECRYPT:
  52507. /* perform software based RSA public op */
  52508. ret = wc_RsaFunction(
  52509. info->pk.rsa.in, info->pk.rsa.inLen,
  52510. info->pk.rsa.out, info->pk.rsa.outLen,
  52511. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52512. break;
  52513. case RSA_PRIVATE_ENCRYPT:
  52514. case RSA_PRIVATE_DECRYPT:
  52515. /* perform software based RSA private op */
  52516. ret = wc_RsaFunction(
  52517. info->pk.rsa.in, info->pk.rsa.inLen,
  52518. info->pk.rsa.out, info->pk.rsa.outLen,
  52519. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52520. break;
  52521. }
  52522. /* reset devId */
  52523. info->pk.rsa.key->devId = devIdArg;
  52524. }
  52525. #ifdef WOLFSSL_KEY_GEN
  52526. else if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
  52527. info->pk.rsakg.key->devId = INVALID_DEVID;
  52528. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52529. #ifdef DEBUG_WOLFSSL
  52530. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52531. #endif
  52532. if (myCtx->exampleVar == 99) {
  52533. info->pk.rsakg.key->devId = devIdArg;
  52534. return 0;
  52535. }
  52536. #endif
  52537. #ifdef HAVE_FIPS
  52538. for (;;) {
  52539. #endif
  52540. ret = wc_MakeRsaKey(info->pk.rsakg.key, info->pk.rsakg.size,
  52541. info->pk.rsakg.e, info->pk.rsakg.rng);
  52542. #ifdef HAVE_FIPS
  52543. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  52544. continue;
  52545. break;
  52546. }
  52547. #endif
  52548. /* reset devId */
  52549. info->pk.rsakg.key->devId = devIdArg;
  52550. }
  52551. #endif
  52552. #endif /* !NO_RSA */
  52553. #ifdef HAVE_ECC
  52554. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  52555. /* set devId to invalid, so software is used */
  52556. info->pk.eckg.key->devId = INVALID_DEVID;
  52557. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52558. #ifdef DEBUG_WOLFSSL
  52559. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52560. #endif
  52561. if (myCtx->exampleVar == 99) {
  52562. info->pk.eckg.key->devId = devIdArg;
  52563. return 0;
  52564. }
  52565. #endif
  52566. ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
  52567. info->pk.eckg.key, info->pk.eckg.curveId);
  52568. /* reset devId */
  52569. info->pk.eckg.key->devId = devIdArg;
  52570. }
  52571. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  52572. /* set devId to invalid, so software is used */
  52573. info->pk.eccsign.key->devId = INVALID_DEVID;
  52574. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52575. #ifdef DEBUG_WOLFSSL
  52576. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52577. #endif
  52578. if (myCtx->exampleVar == 99) {
  52579. info->pk.eccsign.key->devId = devIdArg;
  52580. return 0;
  52581. }
  52582. #endif
  52583. ret = wc_ecc_sign_hash(
  52584. info->pk.eccsign.in, info->pk.eccsign.inlen,
  52585. info->pk.eccsign.out, info->pk.eccsign.outlen,
  52586. info->pk.eccsign.rng, info->pk.eccsign.key);
  52587. /* reset devId */
  52588. info->pk.eccsign.key->devId = devIdArg;
  52589. }
  52590. else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
  52591. /* set devId to invalid, so software is used */
  52592. info->pk.eccverify.key->devId = INVALID_DEVID;
  52593. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52594. #ifdef DEBUG_WOLFSSL
  52595. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52596. #endif
  52597. if (myCtx->exampleVar == 99) {
  52598. info->pk.eccverify.key->devId = devIdArg;
  52599. return 0;
  52600. }
  52601. #endif
  52602. ret = wc_ecc_verify_hash(
  52603. info->pk.eccverify.sig, info->pk.eccverify.siglen,
  52604. info->pk.eccverify.hash, info->pk.eccverify.hashlen,
  52605. info->pk.eccverify.res, info->pk.eccverify.key);
  52606. /* reset devId */
  52607. info->pk.eccverify.key->devId = devIdArg;
  52608. }
  52609. else if (info->pk.type == WC_PK_TYPE_ECDH) {
  52610. /* set devId to invalid, so software is used */
  52611. info->pk.ecdh.private_key->devId = INVALID_DEVID;
  52612. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52613. #ifdef DEBUG_WOLFSSL
  52614. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52615. #endif
  52616. if (myCtx->exampleVar == 99) {
  52617. info->pk.ecdh.private_key->devId = devIdArg;
  52618. return 0;
  52619. }
  52620. #endif
  52621. ret = wc_ecc_shared_secret(
  52622. info->pk.ecdh.private_key, info->pk.ecdh.public_key,
  52623. info->pk.ecdh.out, info->pk.ecdh.outlen);
  52624. /* reset devId */
  52625. info->pk.ecdh.private_key->devId = devIdArg;
  52626. }
  52627. #endif /* HAVE_ECC */
  52628. #ifdef HAVE_CURVE25519
  52629. if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
  52630. /* set devId to invalid, so software is used */
  52631. info->pk.curve25519kg.key->devId = INVALID_DEVID;
  52632. ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
  52633. info->pk.curve25519kg.size, info->pk.curve25519kg.key);
  52634. /* reset devId */
  52635. info->pk.curve25519kg.key->devId = devIdArg;
  52636. }
  52637. else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
  52638. /* set devId to invalid, so software is used */
  52639. info->pk.curve25519.private_key->devId = INVALID_DEVID;
  52640. ret = wc_curve25519_shared_secret_ex(
  52641. info->pk.curve25519.private_key, info->pk.curve25519.public_key,
  52642. info->pk.curve25519.out, info->pk.curve25519.outlen,
  52643. info->pk.curve25519.endian);
  52644. /* reset devId */
  52645. info->pk.curve25519.private_key->devId = devIdArg;
  52646. }
  52647. #endif /* HAVE_CURVE25519 */
  52648. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  52649. if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
  52650. /* set devId to invalid, so software is used */
  52651. info->pk.ed25519kg.key->devId = INVALID_DEVID;
  52652. ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
  52653. info->pk.ed25519kg.size, info->pk.ed25519kg.key);
  52654. /* reset devId */
  52655. info->pk.ed25519kg.key->devId = devIdArg;
  52656. }
  52657. #ifdef HAVE_ED25519_SIGN
  52658. else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  52659. /* set devId to invalid, so software is used */
  52660. info->pk.ed25519sign.key->devId = INVALID_DEVID;
  52661. ret = wc_ed25519_sign_msg_ex(
  52662. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  52663. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  52664. info->pk.ed25519sign.key, info->pk.ed25519sign.type,
  52665. info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
  52666. /* reset devId */
  52667. info->pk.ed25519sign.key->devId = devIdArg;
  52668. }
  52669. #endif
  52670. #ifdef HAVE_ED25519_VERIFY
  52671. else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
  52672. /* set devId to invalid, so software is used */
  52673. info->pk.ed25519verify.key->devId = INVALID_DEVID;
  52674. ret = wc_ed25519_verify_msg_ex(
  52675. info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
  52676. info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
  52677. info->pk.ed25519verify.res, info->pk.ed25519verify.key,
  52678. info->pk.ed25519verify.type, info->pk.ed25519verify.context,
  52679. info->pk.ed25519verify.contextLen);
  52680. /* reset devId */
  52681. info->pk.ed25519verify.key->devId = devIdArg;
  52682. }
  52683. #endif
  52684. #endif /* HAVE_ED25519 */
  52685. }
  52686. else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
  52687. #if !defined(NO_AES) || !defined(NO_DES3)
  52688. #ifdef HAVE_AESGCM
  52689. if (info->cipher.type == WC_CIPHER_AES_GCM) {
  52690. if (info->cipher.enc) {
  52691. /* set devId to invalid, so software is used */
  52692. info->cipher.aesgcm_enc.aes->devId = INVALID_DEVID;
  52693. ret = wc_AesGcmEncrypt(
  52694. info->cipher.aesgcm_enc.aes,
  52695. info->cipher.aesgcm_enc.out,
  52696. info->cipher.aesgcm_enc.in,
  52697. info->cipher.aesgcm_enc.sz,
  52698. info->cipher.aesgcm_enc.iv,
  52699. info->cipher.aesgcm_enc.ivSz,
  52700. info->cipher.aesgcm_enc.authTag,
  52701. info->cipher.aesgcm_enc.authTagSz,
  52702. info->cipher.aesgcm_enc.authIn,
  52703. info->cipher.aesgcm_enc.authInSz);
  52704. /* reset devId */
  52705. info->cipher.aesgcm_enc.aes->devId = devIdArg;
  52706. }
  52707. else {
  52708. /* set devId to invalid, so software is used */
  52709. info->cipher.aesgcm_dec.aes->devId = INVALID_DEVID;
  52710. ret = wc_AesGcmDecrypt(
  52711. info->cipher.aesgcm_dec.aes,
  52712. info->cipher.aesgcm_dec.out,
  52713. info->cipher.aesgcm_dec.in,
  52714. info->cipher.aesgcm_dec.sz,
  52715. info->cipher.aesgcm_dec.iv,
  52716. info->cipher.aesgcm_dec.ivSz,
  52717. info->cipher.aesgcm_dec.authTag,
  52718. info->cipher.aesgcm_dec.authTagSz,
  52719. info->cipher.aesgcm_dec.authIn,
  52720. info->cipher.aesgcm_dec.authInSz);
  52721. /* reset devId */
  52722. info->cipher.aesgcm_dec.aes->devId = devIdArg;
  52723. }
  52724. }
  52725. #endif /* HAVE_AESGCM */
  52726. #ifdef HAVE_AES_CBC
  52727. if (info->cipher.type == WC_CIPHER_AES_CBC) {
  52728. if (info->cipher.enc) {
  52729. /* set devId to invalid, so software is used */
  52730. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  52731. ret = wc_AesCbcEncrypt(
  52732. info->cipher.aescbc.aes,
  52733. info->cipher.aescbc.out,
  52734. info->cipher.aescbc.in,
  52735. info->cipher.aescbc.sz);
  52736. /* reset devId */
  52737. info->cipher.aescbc.aes->devId = devIdArg;
  52738. }
  52739. else {
  52740. /* set devId to invalid, so software is used */
  52741. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  52742. ret = wc_AesCbcDecrypt(
  52743. info->cipher.aescbc.aes,
  52744. info->cipher.aescbc.out,
  52745. info->cipher.aescbc.in,
  52746. info->cipher.aescbc.sz);
  52747. /* reset devId */
  52748. info->cipher.aescbc.aes->devId = devIdArg;
  52749. }
  52750. }
  52751. #endif /* HAVE_AES_CBC */
  52752. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  52753. if (info->cipher.type == WC_CIPHER_AES_ECB) {
  52754. if (info->cipher.enc) {
  52755. /* set devId to invalid, so software is used */
  52756. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  52757. ret = wc_AesEcbEncrypt(
  52758. info->cipher.aesecb.aes,
  52759. info->cipher.aesecb.out,
  52760. info->cipher.aesecb.in,
  52761. info->cipher.aesecb.sz);
  52762. /* reset devId */
  52763. info->cipher.aesecb.aes->devId = devIdArg;
  52764. }
  52765. else {
  52766. /* set devId to invalid, so software is used */
  52767. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  52768. ret = wc_AesEcbDecrypt(
  52769. info->cipher.aesecb.aes,
  52770. info->cipher.aesecb.out,
  52771. info->cipher.aesecb.in,
  52772. info->cipher.aesecb.sz);
  52773. /* reset devId */
  52774. info->cipher.aesecb.aes->devId = devIdArg;
  52775. }
  52776. }
  52777. #endif /* HAVE_AES_ECB */
  52778. #if defined(WOLFSSL_AES_COUNTER) && !defined(HAVE_FIPS) && \
  52779. !defined(HAVE_SELFTEST)
  52780. if (info->cipher.type == WC_CIPHER_AES_CTR) {
  52781. /* set devId to invalid, so software is used */
  52782. info->cipher.aesctr.aes->devId = INVALID_DEVID;
  52783. ret = wc_AesCtrEncrypt(
  52784. info->cipher.aesctr.aes,
  52785. info->cipher.aesctr.out,
  52786. info->cipher.aesctr.in,
  52787. info->cipher.aesctr.sz);
  52788. /* reset devId */
  52789. info->cipher.aesctr.aes->devId = devIdArg;
  52790. }
  52791. #endif /* WOLFSSL_AES_COUNTER */
  52792. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  52793. if (info->cipher.type == WC_CIPHER_AES_CCM) {
  52794. if (info->cipher.enc) {
  52795. /* set devId to invalid, so software is used */
  52796. info->cipher.aesccm_enc.aes->devId = INVALID_DEVID;
  52797. ret = wc_AesCcmEncrypt(
  52798. info->cipher.aesccm_enc.aes,
  52799. info->cipher.aesccm_enc.out,
  52800. info->cipher.aesccm_enc.in,
  52801. info->cipher.aesccm_enc.sz,
  52802. info->cipher.aesccm_enc.nonce,
  52803. info->cipher.aesccm_enc.nonceSz,
  52804. info->cipher.aesccm_enc.authTag,
  52805. info->cipher.aesccm_enc.authTagSz,
  52806. info->cipher.aesccm_enc.authIn,
  52807. info->cipher.aesccm_enc.authInSz);
  52808. /* reset devId */
  52809. info->cipher.aesccm_enc.aes->devId = devIdArg;
  52810. }
  52811. else {
  52812. /* set devId to invalid, so software is used */
  52813. info->cipher.aesccm_dec.aes->devId = INVALID_DEVID;
  52814. ret = wc_AesCcmDecrypt(
  52815. info->cipher.aesccm_dec.aes,
  52816. info->cipher.aesccm_dec.out,
  52817. info->cipher.aesccm_dec.in,
  52818. info->cipher.aesccm_dec.sz,
  52819. info->cipher.aesccm_dec.nonce,
  52820. info->cipher.aesccm_dec.nonceSz,
  52821. info->cipher.aesccm_dec.authTag,
  52822. info->cipher.aesccm_dec.authTagSz,
  52823. info->cipher.aesccm_dec.authIn,
  52824. info->cipher.aesccm_dec.authInSz);
  52825. /* reset devId */
  52826. info->cipher.aesccm_dec.aes->devId = devIdArg;
  52827. }
  52828. }
  52829. #endif
  52830. #ifndef NO_DES3
  52831. if (info->cipher.type == WC_CIPHER_DES3) {
  52832. if (info->cipher.enc) {
  52833. /* set devId to invalid, so software is used */
  52834. info->cipher.des3.des->devId = INVALID_DEVID;
  52835. ret = wc_Des3_CbcEncrypt(
  52836. info->cipher.des3.des,
  52837. info->cipher.des3.out,
  52838. info->cipher.des3.in,
  52839. info->cipher.des3.sz);
  52840. /* reset devId */
  52841. info->cipher.des3.des->devId = devIdArg;
  52842. }
  52843. else {
  52844. /* set devId to invalid, so software is used */
  52845. info->cipher.des3.des->devId = INVALID_DEVID;
  52846. ret = wc_Des3_CbcDecrypt(
  52847. info->cipher.des3.des,
  52848. info->cipher.des3.out,
  52849. info->cipher.des3.in,
  52850. info->cipher.des3.sz);
  52851. /* reset devId */
  52852. info->cipher.des3.des->devId = devIdArg;
  52853. }
  52854. }
  52855. #endif /* !NO_DES3 */
  52856. #endif /* !NO_AES || !NO_DES3 */
  52857. }
  52858. #if !defined(NO_SHA) || !defined(NO_SHA256) || \
  52859. defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
  52860. else if (info->algo_type == WC_ALGO_TYPE_HASH) {
  52861. #if !defined(NO_SHA)
  52862. if (info->hash.type == WC_HASH_TYPE_SHA) {
  52863. if (info->hash.sha1 == NULL)
  52864. return NOT_COMPILED_IN;
  52865. /* set devId to invalid, so software is used */
  52866. info->hash.sha1->devId = INVALID_DEVID;
  52867. if (info->hash.in != NULL) {
  52868. ret = wc_ShaUpdate(
  52869. info->hash.sha1,
  52870. info->hash.in,
  52871. info->hash.inSz);
  52872. }
  52873. if (info->hash.digest != NULL) {
  52874. ret = wc_ShaFinal(
  52875. info->hash.sha1,
  52876. info->hash.digest);
  52877. }
  52878. /* reset devId */
  52879. info->hash.sha1->devId = devIdArg;
  52880. }
  52881. else
  52882. #endif
  52883. #if !defined(NO_SHA256)
  52884. if (info->hash.type == WC_HASH_TYPE_SHA256) {
  52885. if (info->hash.sha256 == NULL)
  52886. return NOT_COMPILED_IN;
  52887. /* set devId to invalid, so software is used */
  52888. info->hash.sha256->devId = INVALID_DEVID;
  52889. if (info->hash.in != NULL) {
  52890. ret = wc_Sha256Update(
  52891. info->hash.sha256,
  52892. info->hash.in,
  52893. info->hash.inSz);
  52894. }
  52895. if (info->hash.digest != NULL) {
  52896. ret = wc_Sha256Final(
  52897. info->hash.sha256,
  52898. info->hash.digest);
  52899. }
  52900. /* reset devId */
  52901. info->hash.sha256->devId = devIdArg;
  52902. }
  52903. else
  52904. #endif
  52905. #ifdef WOLFSSL_SHA384
  52906. if (info->hash.type == WC_HASH_TYPE_SHA384) {
  52907. if (info->hash.sha384 == NULL)
  52908. return NOT_COMPILED_IN;
  52909. #ifndef NO_SHA2_CRYPTO_CB
  52910. /* set devId to invalid, so software is used */
  52911. info->hash.sha384->devId = INVALID_DEVID;
  52912. #endif
  52913. if (info->hash.in != NULL) {
  52914. ret = wc_Sha384Update(
  52915. info->hash.sha384,
  52916. info->hash.in,
  52917. info->hash.inSz);
  52918. }
  52919. if (info->hash.digest != NULL) {
  52920. ret = wc_Sha384Final(
  52921. info->hash.sha384,
  52922. info->hash.digest);
  52923. }
  52924. #ifndef NO_SHA2_CRYPTO_CB
  52925. /* reset devId */
  52926. info->hash.sha384->devId = devIdArg;
  52927. #endif
  52928. }
  52929. else
  52930. #endif
  52931. #ifdef WOLFSSL_SHA512
  52932. if (info->hash.type == WC_HASH_TYPE_SHA512) {
  52933. if (info->hash.sha512 == NULL)
  52934. return NOT_COMPILED_IN;
  52935. #ifndef NO_SHA2_CRYPTO_CB
  52936. /* set devId to invalid, so software is used */
  52937. info->hash.sha512->devId = INVALID_DEVID;
  52938. #endif
  52939. if (info->hash.in != NULL) {
  52940. ret = wc_Sha512Update(
  52941. info->hash.sha512,
  52942. info->hash.in,
  52943. info->hash.inSz);
  52944. }
  52945. if (info->hash.digest != NULL) {
  52946. ret = wc_Sha512Final(
  52947. info->hash.sha512,
  52948. info->hash.digest);
  52949. }
  52950. #ifndef NO_SHA2_CRYPTO_CB
  52951. /* reset devId */
  52952. info->hash.sha512->devId = devIdArg;
  52953. #endif
  52954. }
  52955. else
  52956. #endif
  52957. #if defined(WOLFSSL_SHA3) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0))
  52958. if (info->hash.type == WC_HASH_TYPE_SHA3_224) {
  52959. if (info->hash.sha3 == NULL)
  52960. return NOT_COMPILED_IN;
  52961. /* set devId to invalid, so software is used */
  52962. info->hash.sha3->devId = INVALID_DEVID;
  52963. if (info->hash.in != NULL) {
  52964. ret = wc_Sha3_224_Update(
  52965. info->hash.sha3,
  52966. info->hash.in,
  52967. info->hash.inSz);
  52968. }
  52969. if (info->hash.digest != NULL) {
  52970. ret = wc_Sha3_224_Final(
  52971. info->hash.sha3,
  52972. info->hash.digest);
  52973. }
  52974. /* reset devId */
  52975. info->hash.sha3->devId = devIdArg;
  52976. }
  52977. else if (info->hash.type == WC_HASH_TYPE_SHA3_256) {
  52978. if (info->hash.sha3 == NULL)
  52979. return NOT_COMPILED_IN;
  52980. /* set devId to invalid, so software is used */
  52981. info->hash.sha3->devId = INVALID_DEVID;
  52982. if (info->hash.in != NULL) {
  52983. ret = wc_Sha3_256_Update(
  52984. info->hash.sha3,
  52985. info->hash.in,
  52986. info->hash.inSz);
  52987. }
  52988. if (info->hash.digest != NULL) {
  52989. ret = wc_Sha3_256_Final(
  52990. info->hash.sha3,
  52991. info->hash.digest);
  52992. }
  52993. /* reset devId */
  52994. info->hash.sha3->devId = devIdArg;
  52995. }
  52996. else if (info->hash.type == WC_HASH_TYPE_SHA3_384) {
  52997. if (info->hash.sha3 == NULL)
  52998. return NOT_COMPILED_IN;
  52999. /* set devId to invalid, so software is used */
  53000. info->hash.sha3->devId = INVALID_DEVID;
  53001. if (info->hash.in != NULL) {
  53002. ret = wc_Sha3_384_Update(
  53003. info->hash.sha3,
  53004. info->hash.in,
  53005. info->hash.inSz);
  53006. }
  53007. if (info->hash.digest != NULL) {
  53008. ret = wc_Sha3_384_Final(
  53009. info->hash.sha3,
  53010. info->hash.digest);
  53011. }
  53012. /* reset devId */
  53013. info->hash.sha3->devId = devIdArg;
  53014. }
  53015. else if (info->hash.type == WC_HASH_TYPE_SHA3_512) {
  53016. if (info->hash.sha3 == NULL)
  53017. return NOT_COMPILED_IN;
  53018. /* set devId to invalid, so software is used */
  53019. info->hash.sha3->devId = INVALID_DEVID;
  53020. if (info->hash.in != NULL) {
  53021. ret = wc_Sha3_512_Update(
  53022. info->hash.sha3,
  53023. info->hash.in,
  53024. info->hash.inSz);
  53025. }
  53026. if (info->hash.digest != NULL) {
  53027. ret = wc_Sha3_512_Final(
  53028. info->hash.sha3,
  53029. info->hash.digest);
  53030. }
  53031. /* reset devId */
  53032. info->hash.sha3->devId = devIdArg;
  53033. }
  53034. else
  53035. #endif
  53036. {
  53037. }
  53038. }
  53039. #endif /* !NO_SHA || !NO_SHA256 */
  53040. #ifndef NO_HMAC
  53041. else if (info->algo_type == WC_ALGO_TYPE_HMAC) {
  53042. if (info->hmac.hmac == NULL)
  53043. return NOT_COMPILED_IN;
  53044. /* set devId to invalid, so software is used */
  53045. info->hmac.hmac->devId = INVALID_DEVID;
  53046. if (info->hmac.in != NULL) {
  53047. ret = wc_HmacUpdate(
  53048. info->hmac.hmac,
  53049. info->hmac.in,
  53050. info->hmac.inSz);
  53051. }
  53052. else if (info->hmac.digest != NULL) {
  53053. ret = wc_HmacFinal(
  53054. info->hmac.hmac,
  53055. info->hmac.digest);
  53056. }
  53057. /* reset devId */
  53058. info->hmac.hmac->devId = devIdArg;
  53059. }
  53060. #endif
  53061. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53062. else if (info->algo_type == WC_ALGO_TYPE_CMAC) {
  53063. if (info->cmac.cmac == NULL) {
  53064. return NOT_COMPILED_IN;
  53065. }
  53066. /* set devId to invalid so software is used */
  53067. info->cmac.cmac->devId = INVALID_DEVID;
  53068. /* Handle one-shot cases */
  53069. if (info->cmac.key != NULL && info->cmac.in != NULL
  53070. && info->cmac.out != NULL) {
  53071. ret = wc_AesCmacGenerate(info->cmac.out,
  53072. info->cmac.outSz,
  53073. info->cmac.in,
  53074. info->cmac.inSz,
  53075. info->cmac.key,
  53076. info->cmac.keySz);
  53077. /* Sequentially handle incremental cases */
  53078. } else {
  53079. if (info->cmac.key != NULL) {
  53080. ret = wc_InitCmac(info->cmac.cmac,
  53081. info->cmac.key,
  53082. info->cmac.keySz,
  53083. info->cmac.type,
  53084. NULL);
  53085. }
  53086. if ((ret == 0) && (info->cmac.in != NULL)) {
  53087. ret = wc_CmacUpdate(info->cmac.cmac,
  53088. info->cmac.in,
  53089. info->cmac.inSz);
  53090. }
  53091. if ((ret ==0) && (info->cmac.out != NULL)) {
  53092. ret = wc_CmacFinal(info->cmac.cmac,
  53093. info->cmac.out,
  53094. info->cmac.outSz);
  53095. }
  53096. }
  53097. /* reset devId */
  53098. info->cmac.cmac->devId = devIdArg;
  53099. }
  53100. #endif /* WOLFSSL_CMAC && !(NO_AES) && WOLFSSL_AES_DIRECT */
  53101. (void)devIdArg;
  53102. (void)myCtx;
  53103. return ret;
  53104. }
  53105. #ifdef WOLF_CRYPTO_CB_FIND
  53106. static int myCryptoCbFind(int currentId, int algoType)
  53107. {
  53108. /* can have algo specific overrides here
  53109. switch (algoType) {
  53110. i.e.
  53111. WC_ALGO_TYPE_CMAC
  53112. WC_ALGO_TYPE_SEED
  53113. WC_ALGO_TYPE_HMAC
  53114. WC_ALGO_TYPE_HASH
  53115. WC_ALGO_TYPE_CIPHER
  53116. WC_ALGO_TYPE_PK
  53117. }
  53118. */
  53119. (void)algoType;
  53120. if (currentId == INVALID_DEVID) {
  53121. /* can override invalid devid found with 1 */
  53122. }
  53123. return currentId;
  53124. }
  53125. #endif /* WOLF_CRYPTO_CB_FIND */
  53126. #if !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  53127. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
  53128. {
  53129. wc_test_ret_t ret = 0;
  53130. int origDevId = devId;
  53131. myCryptoDevCtx myCtx;
  53132. WOLFSSL_ENTER("cryptocb_test");
  53133. /* example data for callback */
  53134. myCtx.exampleVar = 1;
  53135. /* set devId to something other than INVALID_DEVID */
  53136. devId = 1;
  53137. ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
  53138. #ifdef WOLF_CRYPTO_CB_FIND
  53139. wc_CryptoCb_SetDeviceFindCb(myCryptoCbFind);
  53140. #endif /* WOLF_CRYPTO_CB_FIND */
  53141. #ifndef WC_NO_RNG
  53142. if (ret == 0)
  53143. ret = random_test();
  53144. #endif /* WC_NO_RNG */
  53145. #if !defined(NO_RSA)
  53146. PRIVATE_KEY_UNLOCK();
  53147. if (ret == 0)
  53148. ret = rsa_test();
  53149. PRIVATE_KEY_LOCK();
  53150. #endif
  53151. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  53152. PRIVATE_KEY_UNLOCK();
  53153. if (ret == 0)
  53154. ret = rsa_onlycb_test(&myCtx);
  53155. PRIVATE_KEY_LOCK();
  53156. #endif
  53157. #if defined(HAVE_ECC)
  53158. PRIVATE_KEY_UNLOCK();
  53159. if (ret == 0)
  53160. ret = ecc_test();
  53161. PRIVATE_KEY_LOCK();
  53162. #endif
  53163. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  53164. PRIVATE_KEY_UNLOCK();
  53165. if (ret == 0)
  53166. ret = ecc_onlycb_test(&myCtx);
  53167. PRIVATE_KEY_LOCK();
  53168. #endif
  53169. #ifdef HAVE_ED25519
  53170. PRIVATE_KEY_UNLOCK();
  53171. if (ret == 0)
  53172. ret = ed25519_test();
  53173. PRIVATE_KEY_LOCK();
  53174. #endif
  53175. #ifdef HAVE_CURVE25519
  53176. if (ret == 0)
  53177. ret = curve25519_test();
  53178. #endif
  53179. #ifndef NO_AES
  53180. #ifdef HAVE_AESGCM
  53181. if (ret == 0)
  53182. ret = aesgcm_test();
  53183. #endif
  53184. #ifdef HAVE_AES_CBC
  53185. if (ret == 0)
  53186. ret = aes_test();
  53187. #endif
  53188. #ifdef WOLFSSL_AES_XTS
  53189. if (ret == 0)
  53190. ret = aes_xts_test();
  53191. #endif
  53192. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53193. if (ret == 0)
  53194. ret = aesccm_test();
  53195. #endif
  53196. #endif /* !NO_AES */
  53197. #ifndef NO_DES3
  53198. if (ret == 0)
  53199. ret = des3_test();
  53200. #endif /* !NO_DES3 */
  53201. #ifndef NO_SHA
  53202. if (ret == 0)
  53203. ret = sha_test();
  53204. #endif
  53205. #ifndef NO_SHA256
  53206. if (ret == 0)
  53207. ret = sha256_test();
  53208. #endif
  53209. #ifdef WOLFSSL_SHA384
  53210. if (ret == 0)
  53211. ret = sha384_test();
  53212. #endif
  53213. #ifdef WOLFSSL_SHA512
  53214. if (ret == 0)
  53215. ret = sha512_test();
  53216. #ifdef WOLFSSL_SHA3
  53217. if (ret == 0)
  53218. ret = sha3_test();
  53219. #endif
  53220. #endif
  53221. #ifndef NO_HMAC
  53222. #ifndef NO_SHA
  53223. if (ret == 0)
  53224. ret = hmac_sha_test();
  53225. #endif
  53226. #ifndef NO_SHA256
  53227. if (ret == 0)
  53228. ret = hmac_sha256_test();
  53229. #endif
  53230. #ifdef WOLFSSL_SHA3
  53231. if (ret == 0)
  53232. ret = hmac_sha3_test();
  53233. #endif
  53234. #endif
  53235. #ifndef NO_PWDBASED
  53236. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  53237. PRIVATE_KEY_UNLOCK();
  53238. if (ret == 0)
  53239. ret = pbkdf2_test();
  53240. PRIVATE_KEY_LOCK();
  53241. #endif
  53242. #endif
  53243. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53244. if (ret == 0)
  53245. ret = cmac_test();
  53246. #endif
  53247. /* restore devId */
  53248. devId = origDevId;
  53249. return ret;
  53250. }
  53251. #endif /* ! WC_TEST_NO_CRYPTOCB_SW_TEST */
  53252. #endif /* WOLF_CRYPTO_CB */
  53253. #ifdef WOLFSSL_CERT_PIV
  53254. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void)
  53255. {
  53256. wc_test_ret_t ret;
  53257. wc_CertPIV piv;
  53258. /* Template for Identiv PIV cert, nonce and signature */
  53259. WOLFSSL_SMALL_STACK_STATIC const byte pivCertIdentiv[] = {
  53260. 0x0A, 0x0B,
  53261. 0x53, 0x09, /* NIST PIV Cert */
  53262. 0x70, 0x02, /* Certificate */
  53263. 0x30, 0x00,
  53264. 0x71, 0x01, 0x05, /* Cert Info */
  53265. 0xFE, 0x00, /* Error Detection */
  53266. 0x0B, 0x01, 0x00, /* Nonce */
  53267. 0x0C, 0x01, 0x00, /* Signed Nonce */
  53268. };
  53269. /* PIV certificate data including certificate, info and error detection. */
  53270. WOLFSSL_SMALL_STACK_STATIC const byte pivCert[] = {
  53271. 0x53, 0x09, /* NIST PIV Cert */
  53272. 0x70, 0x02, /* Certificate */
  53273. 0x30, 0x00,
  53274. 0x71, 0x01, 0x04, /* Cert Info */
  53275. 0xFE, 0x00, /* Error Detection */
  53276. };
  53277. WOLFSSL_ENTER("certpiv_test");
  53278. XMEMSET(&piv, 0, sizeof(piv));
  53279. /* Test with Identiv 0x0A, 0x0B and 0x0C markers */
  53280. ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv));
  53281. if (ret != 0) {
  53282. return WC_TEST_RET_ENC_EC(ret);
  53283. }
  53284. if (!piv.isIdentiv) {
  53285. return WC_TEST_RET_ENC_NC;
  53286. }
  53287. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53288. return WC_TEST_RET_ENC_NC;
  53289. }
  53290. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53291. return WC_TEST_RET_ENC_NC;
  53292. }
  53293. if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) {
  53294. return WC_TEST_RET_ENC_NC;
  53295. }
  53296. if (!piv.isX509) {
  53297. return WC_TEST_RET_ENC_NC;
  53298. }
  53299. if ((piv.nonce == NULL) || (piv.nonceSz != 1)) {
  53300. return WC_TEST_RET_ENC_NC;
  53301. }
  53302. if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) {
  53303. return WC_TEST_RET_ENC_NC;
  53304. }
  53305. XMEMSET(&piv, 0, sizeof(piv));
  53306. /* Test with NIST PIV format */
  53307. ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
  53308. if (ret != 0) {
  53309. return WC_TEST_RET_ENC_EC(ret);
  53310. }
  53311. if (piv.isIdentiv) {
  53312. return WC_TEST_RET_ENC_NC;
  53313. }
  53314. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53315. return WC_TEST_RET_ENC_NC;
  53316. }
  53317. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53318. return WC_TEST_RET_ENC_NC;
  53319. }
  53320. if ((piv.compression != 0)) {
  53321. return WC_TEST_RET_ENC_NC;
  53322. }
  53323. if (!piv.isX509) {
  53324. return WC_TEST_RET_ENC_NC;
  53325. }
  53326. return ret;
  53327. }
  53328. #endif /* WOLFSSL_CERT_PIV */
  53329. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  53330. static time_t time_cb(time_t* t)
  53331. {
  53332. if (t != NULL) {
  53333. *t = 99;
  53334. }
  53335. return 99;
  53336. }
  53337. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void)
  53338. {
  53339. time_t t;
  53340. wc_test_ret_t ret;
  53341. WOLFSSL_ENTER("time_test");
  53342. ret = wc_SetTimeCb(time_cb);
  53343. if (ret != 0)
  53344. return WC_TEST_RET_ENC_EC(ret);
  53345. t = wc_Time(NULL);
  53346. if (t != 99)
  53347. return WC_TEST_RET_ENC_NC;
  53348. ret = wc_GetTime(&t, sizeof(time_t));
  53349. if (ret != 0)
  53350. return WC_TEST_RET_ENC_EC(ret);
  53351. if (t != 99)
  53352. return WC_TEST_RET_ENC_NC;
  53353. ret = wc_SetTimeCb(NULL);
  53354. if (ret != 0)
  53355. return WC_TEST_RET_ENC_EC(ret);
  53356. return 0;
  53357. }
  53358. #endif
  53359. #ifdef WOLFSSL_AES_SIV
  53360. typedef struct {
  53361. const byte key[33];
  53362. word32 keySz;
  53363. const byte nonce[49];
  53364. word32 nonceSz;
  53365. byte numAssoc;
  53366. const byte assoc1[81];
  53367. word32 assoc1Sz;
  53368. const byte assoc2[11];
  53369. word32 assoc2Sz;
  53370. const byte plaintext[83];
  53371. word32 plaintextSz;
  53372. const byte siv[AES_BLOCK_SIZE+1];
  53373. const byte ciphertext[82];
  53374. word32 ciphertextSz;
  53375. } AesSivTestVector;
  53376. #define AES_SIV_TEST_VECTORS 9
  53377. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
  53378. {
  53379. WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
  53380. /* These test vectors come from chrony 4.1's SIV unit tests. */
  53381. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53382. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53383. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53384. 1,
  53385. "", 0,
  53386. "", 0,
  53387. "", 0,
  53388. "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
  53389. "", 0
  53390. },
  53391. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53392. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53393. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53394. 1,
  53395. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53396. "", 0,
  53397. "", 0,
  53398. "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
  53399. "", 0
  53400. },
  53401. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53402. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53403. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53404. 1,
  53405. "", 0,
  53406. "", 0,
  53407. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53408. "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
  53409. "\x14\xff\xb3\x97\x34\x5c\xcb\xe4\x4a\xa4\xde\xac\xd9\x36\x90\x46", 16
  53410. },
  53411. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53412. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53413. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
  53414. 1,
  53415. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
  53416. "", 0,
  53417. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
  53418. "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
  53419. "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
  53420. },
  53421. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53422. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53423. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53424. 1,
  53425. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53426. "", 0,
  53427. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
  53428. "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
  53429. "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
  53430. },
  53431. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53432. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53433. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53434. "\xd5", 17,
  53435. 1,
  53436. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
  53437. "\xa0", 17,
  53438. "", 0,
  53439. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
  53440. "\x08", 17,
  53441. "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
  53442. "\xa5\x11\xcd\xb6\x08\xf3\x76\xa0\xb6\xfa\x15\x82\xf3\x95\xe1\xeb"
  53443. "\xbd", 17
  53444. },
  53445. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53446. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53447. "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
  53448. "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
  53449. "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
  53450. 1,
  53451. "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
  53452. "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
  53453. "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
  53454. "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
  53455. "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
  53456. "", 0,
  53457. "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
  53458. "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
  53459. "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
  53460. "\xae\x81\xa1\xca\x5b\x5f\x45\xa6\x6f\x0c\x8a\xf3\xd4\x67\x40\x81"
  53461. "\x26\xe2\x01\x86\xe8\x5a\xd5\xf8\x58\x80\x9f\x56\xaa\x76\x96\xbf"
  53462. "\x31", 81,
  53463. "\x9a\x06\x33\xe0\xee\x00\x6a\x9b\xc8\x20\xd5\xe2\xc2\xed\xb5\x75",
  53464. "\xfa\x9e\x42\x2a\x31\x6b\xda\xca\xaa\x7d\x31\x8b\x84\x7a\xb8\xd7"
  53465. "\x8a\x81\x25\x64\xed\x41\x9b\xa9\x77\x10\xbd\x05\x0c\x4e\xc5\x31"
  53466. "\x0c\xa2\x86\xec\x8a\x94\xc8\x24\x23\x3c\x13\xee\xa5\x51\xc9\xdf"
  53467. "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
  53468. "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
  53469. "\xa1", 81
  53470. },
  53471. /* Example A.1 from RFC5297 */
  53472. {
  53473. "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
  53474. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
  53475. "", 0,
  53476. 1,
  53477. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53478. "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
  53479. "", 0,
  53480. "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
  53481. "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
  53482. "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
  53483. },
  53484. /* Example A.2 from RFC5297 */
  53485. {
  53486. "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
  53487. "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
  53488. "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
  53489. 2,
  53490. "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
  53491. "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
  53492. "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
  53493. "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
  53494. "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
  53495. "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
  53496. "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
  53497. "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
  53498. "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
  53499. "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
  53500. "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
  53501. }
  53502. };
  53503. int i;
  53504. byte computedCiphertext[82];
  53505. byte computedPlaintext[82];
  53506. byte siv[AES_BLOCK_SIZE];
  53507. wc_test_ret_t ret = 0;
  53508. WOLFSSL_ENTER("aes_siv_test");
  53509. /* First test legacy "exactly one Assoc" interface. */
  53510. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53511. if (testVectors[i].numAssoc != 1)
  53512. continue;
  53513. ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
  53514. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53515. testVectors[i].nonce, testVectors[i].nonceSz,
  53516. testVectors[i].plaintext,
  53517. testVectors[i].plaintextSz, siv,
  53518. computedCiphertext);
  53519. if (ret != 0) {
  53520. return WC_TEST_RET_ENC_EC(ret);
  53521. }
  53522. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53523. if (ret != 0) {
  53524. return WC_TEST_RET_ENC_NC;
  53525. }
  53526. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53527. testVectors[i].ciphertextSz);
  53528. if (ret != 0) {
  53529. return WC_TEST_RET_ENC_NC;
  53530. }
  53531. ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
  53532. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53533. testVectors[i].nonce, testVectors[i].nonceSz,
  53534. computedCiphertext, testVectors[i].plaintextSz,
  53535. siv, computedPlaintext);
  53536. if (ret != 0) {
  53537. return WC_TEST_RET_ENC_EC(ret);
  53538. }
  53539. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53540. testVectors[i].plaintextSz);
  53541. if (ret != 0) {
  53542. return WC_TEST_RET_ENC_NC;
  53543. }
  53544. }
  53545. /* Then test "multiple Assoc" interface. */
  53546. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53547. const struct AesSivAssoc assoc[2] = {
  53548. { testVectors[i].assoc1, testVectors[i].assoc1Sz },
  53549. { testVectors[i].assoc2, testVectors[i].assoc2Sz }
  53550. };
  53551. ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53552. assoc, testVectors[i].numAssoc,
  53553. testVectors[i].nonce, testVectors[i].nonceSz,
  53554. testVectors[i].plaintext,
  53555. testVectors[i].plaintextSz, siv,
  53556. computedCiphertext);
  53557. if (ret != 0) {
  53558. return WC_TEST_RET_ENC_EC(ret);
  53559. }
  53560. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53561. if (ret != 0) {
  53562. return WC_TEST_RET_ENC_NC;
  53563. }
  53564. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53565. testVectors[i].ciphertextSz);
  53566. if (ret != 0) {
  53567. return WC_TEST_RET_ENC_NC;
  53568. }
  53569. ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53570. assoc, testVectors[i].numAssoc,
  53571. testVectors[i].nonce, testVectors[i].nonceSz,
  53572. computedCiphertext,
  53573. testVectors[i].plaintextSz, siv,
  53574. computedPlaintext);
  53575. if (ret != 0) {
  53576. return WC_TEST_RET_ENC_EC(ret);
  53577. }
  53578. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53579. testVectors[i].plaintextSz);
  53580. if (ret != 0) {
  53581. return WC_TEST_RET_ENC_NC;
  53582. }
  53583. }
  53584. return 0;
  53585. }
  53586. #endif
  53587. #undef ERROR_OUT
  53588. static const int fiducial4 = WC_TEST_RET_LN;
  53589. /* print the fiducial line numbers assigned above, allowing confirmation of
  53590. * source code version match when in doubt.
  53591. */
  53592. static void print_fiducials(void) {
  53593. printf(" [fiducial line numbers: %d %d %d %d]\n",
  53594. fiducial1, fiducial2, fiducial3, fiducial4);
  53595. }
  53596. #else
  53597. #ifndef NO_MAIN_DRIVER
  53598. int main(void) { return 0; }
  53599. #endif
  53600. #endif /* NO_CRYPT_TEST */