1
0

test.c 2.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886
  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. { WC_SPAN1_LAST_E - 1, WC_SPAN2_FIRST_E + 1 },
  2538. { WC_SPAN2_LAST_E - 1, WC_SPAN2_MIN_CODE_E }
  2539. };
  2540. /* Check that all errors have a string and it's the same through the two
  2541. * APIs. Check that the values that are not errors map to the unknown
  2542. * string.
  2543. */
  2544. for (i = WC_SPAN1_FIRST_E; i >= WC_SPAN2_MIN_CODE_E; i--) {
  2545. int this_missing = 0;
  2546. for (j = 0; j < (int)XELEM_CNT(missing); ++j) {
  2547. if ((i <= missing[j].first) && (i >= missing[j].last)) {
  2548. this_missing = 1;
  2549. break;
  2550. }
  2551. }
  2552. errStr = wc_GetErrorString(i);
  2553. wc_ErrorString(i, out);
  2554. if (! this_missing) {
  2555. if (XSTRCMP(errStr, unknownStr) == 0) {
  2556. WOLFSSL_MSG("errStr unknown");
  2557. return WC_TEST_RET_ENC_I(-i);
  2558. }
  2559. if (XSTRCMP(out, unknownStr) == 0) {
  2560. WOLFSSL_MSG("out unknown");
  2561. return WC_TEST_RET_ENC_I(-i);
  2562. }
  2563. if (XSTRCMP(errStr, out) != 0) {
  2564. WOLFSSL_MSG("errStr does not match output");
  2565. return WC_TEST_RET_ENC_I(-i);
  2566. }
  2567. if (XSTRLEN(errStr) >= WOLFSSL_MAX_ERROR_SZ) {
  2568. WOLFSSL_MSG("errStr too long");
  2569. return WC_TEST_RET_ENC_I(-i);
  2570. }
  2571. }
  2572. else {
  2573. j++;
  2574. if (XSTRCMP(errStr, unknownStr) != 0)
  2575. return WC_TEST_RET_ENC_I(-i);
  2576. if (XSTRCMP(out, unknownStr) != 0)
  2577. return WC_TEST_RET_ENC_I(-i);
  2578. }
  2579. }
  2580. /* Check if the next possible value has been given a string. */
  2581. errStr = wc_GetErrorString(i);
  2582. wc_ErrorString(i, out);
  2583. if (XSTRCMP(errStr, unknownStr) != 0)
  2584. return WC_TEST_RET_ENC_NC;
  2585. if (XSTRCMP(out, unknownStr) != 0)
  2586. return WC_TEST_RET_ENC_NC;
  2587. #endif
  2588. return 0;
  2589. }
  2590. #ifndef NO_CODING
  2591. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base64_test(void)
  2592. {
  2593. wc_test_ret_t ret;
  2594. WOLFSSL_SMALL_STACK_STATIC const byte good[] = "A+Gd\0\0\0";
  2595. WOLFSSL_SMALL_STACK_STATIC const byte goodEnd[] = "A+Gd \r\n";
  2596. WOLFSSL_SMALL_STACK_STATIC const byte good_spaces[] = " A + G d \0";
  2597. byte out[128];
  2598. word32 outLen;
  2599. #ifdef WOLFSSL_BASE64_ENCODE
  2600. byte data[3];
  2601. word32 dataLen;
  2602. byte longData[79] = { 0 };
  2603. WOLFSSL_SMALL_STACK_STATIC const byte symbols[] = "+/A=";
  2604. #endif
  2605. WOLFSSL_SMALL_STACK_STATIC const byte badSmall[] = "AAA!Gdj=";
  2606. WOLFSSL_SMALL_STACK_STATIC const byte badLarge[] = "AAA~Gdj=";
  2607. WOLFSSL_SMALL_STACK_STATIC const byte badEOL[] = "A+Gd!AA";
  2608. WOLFSSL_SMALL_STACK_STATIC const byte badPadding[] = "AA=A";
  2609. WOLFSSL_SMALL_STACK_STATIC const byte badChar[] = ",-.:;<=>?@[\\]^_`";
  2610. byte goodChar[] =
  2611. "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  2612. "abcdefghijklmnopqrstuvwxyz"
  2613. "0123456789+/;";
  2614. byte charTest[] = "A+Gd\0\0\0";
  2615. int i;
  2616. WOLFSSL_ENTER("base64_test");
  2617. /* Good Base64 encodings. */
  2618. outLen = sizeof(out);
  2619. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2620. if (ret != 0)
  2621. return WC_TEST_RET_ENC_EC(ret);
  2622. outLen = sizeof(out);
  2623. ret = Base64_Decode(goodEnd, sizeof(goodEnd), out, &outLen);
  2624. if (ret != 0)
  2625. return WC_TEST_RET_ENC_EC(ret);
  2626. outLen = sizeof(goodChar);
  2627. ret = Base64_Decode(goodChar, sizeof(goodChar), goodChar, &outLen);
  2628. if (ret != 0)
  2629. return WC_TEST_RET_ENC_EC(ret);
  2630. if (outLen != 64 / 4 * 3)
  2631. return WC_TEST_RET_ENC_NC;
  2632. outLen = sizeof(out);
  2633. ret = Base64_Decode(good_spaces, sizeof(good_spaces), out, &outLen);
  2634. if (ret != 0)
  2635. return WC_TEST_RET_ENC_EC(ret);
  2636. /* Bad parameters. */
  2637. outLen = 1;
  2638. ret = Base64_Decode(good, sizeof(good), out, &outLen);
  2639. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2640. return WC_TEST_RET_ENC_EC(ret);
  2641. outLen = sizeof(out);
  2642. ret = Base64_Decode(badEOL, sizeof(badEOL), out, &outLen);
  2643. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2644. return WC_TEST_RET_ENC_EC(ret);
  2645. outLen = sizeof(out);
  2646. ret = Base64_Decode(badPadding, sizeof(badPadding), out, &outLen);
  2647. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2648. return WC_TEST_RET_ENC_EC(ret);
  2649. /* Bad character at each offset 0-3. */
  2650. for (i = 0; i < 4; i++) {
  2651. outLen = sizeof(out);
  2652. ret = Base64_Decode(badSmall + i, 4, out, &outLen);
  2653. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2654. return WC_TEST_RET_ENC_I(i);
  2655. ret = Base64_Decode(badLarge + i, 4, out, &outLen);
  2656. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2657. return WC_TEST_RET_ENC_I(i);
  2658. }
  2659. /* Invalid character less than 0x2b */
  2660. for (i = 1; i < 0x2b; i++) {
  2661. outLen = sizeof(out);
  2662. charTest[0] = (byte)i;
  2663. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2664. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2665. return WC_TEST_RET_ENC_I(i);
  2666. }
  2667. /* Bad characters in range 0x2b - 0x7a. */
  2668. for (i = 0; i < (int)sizeof(badChar) - 1; i++) {
  2669. outLen = sizeof(out);
  2670. charTest[0] = badChar[i];
  2671. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2672. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2673. return WC_TEST_RET_ENC_I(i);
  2674. }
  2675. /* Invalid character greater than 0x7a */
  2676. for (i = 0x7b; i < 0x100; i++) {
  2677. outLen = sizeof(out);
  2678. charTest[0] = (byte)i;
  2679. ret = Base64_Decode(charTest, sizeof(charTest), out, &outLen);
  2680. if (ret != WC_NO_ERR_TRACE(ASN_INPUT_E))
  2681. return WC_TEST_RET_ENC_I(i);
  2682. }
  2683. #ifdef WOLFSSL_BASE64_ENCODE
  2684. /* Decode and encode all symbols - non-alphanumeric. */
  2685. dataLen = sizeof(data);
  2686. ret = Base64_Decode(symbols, sizeof(symbols), data, &dataLen);
  2687. if (ret != 0)
  2688. return WC_TEST_RET_ENC_EC(ret);
  2689. outLen = sizeof(out);
  2690. ret = Base64_Encode(data, dataLen, NULL, &outLen);
  2691. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2692. return WC_TEST_RET_ENC_EC(ret);
  2693. outLen = sizeof(out);
  2694. ret = Base64_Encode(data, dataLen, out, &outLen);
  2695. if (ret != 0)
  2696. return WC_TEST_RET_ENC_EC(ret);
  2697. outLen = 7;
  2698. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2699. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  2700. return WC_TEST_RET_ENC_EC(ret);
  2701. outLen = sizeof(out);
  2702. ret = Base64_EncodeEsc(data, dataLen, NULL, &outLen);
  2703. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  2704. return WC_TEST_RET_ENC_EC(ret);
  2705. outLen = sizeof(out);
  2706. ret = Base64_EncodeEsc(data, dataLen, out, &outLen);
  2707. if (ret != 0)
  2708. return WC_TEST_RET_ENC_EC(ret);
  2709. outLen = sizeof(out);
  2710. ret = Base64_Encode_NoNl(data, dataLen, out, &outLen);
  2711. if (ret != 0)
  2712. return WC_TEST_RET_ENC_EC(ret);
  2713. /* Data that results in an encoding longer than one line. */
  2714. outLen = sizeof(out);
  2715. dataLen = sizeof(longData);
  2716. ret = Base64_Encode(longData, dataLen, out, &outLen);
  2717. if (ret != 0)
  2718. return WC_TEST_RET_ENC_EC(ret);
  2719. outLen = sizeof(out);
  2720. ret = Base64_EncodeEsc(longData, dataLen, out, &outLen);
  2721. if (ret != 0)
  2722. return WC_TEST_RET_ENC_EC(ret);
  2723. outLen = sizeof(out);
  2724. ret = Base64_Encode_NoNl(longData, dataLen, out, &outLen);
  2725. if (ret != 0)
  2726. return WC_TEST_RET_ENC_EC(ret);
  2727. #endif
  2728. return 0;
  2729. }
  2730. #ifdef WOLFSSL_BASE16
  2731. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t base16_test(void)
  2732. {
  2733. wc_test_ret_t ret;
  2734. WOLFSSL_SMALL_STACK_STATIC const byte testData[] = "SomeDataToEncode\n";
  2735. WOLFSSL_SMALL_STACK_STATIC const byte encodedTestData[] = "536F6D6544617461546F456E636F64650A00";
  2736. byte encoded[40];
  2737. word32 encodedLen;
  2738. byte plain[40];
  2739. word32 len;
  2740. WOLFSSL_ENTER("base16_test");
  2741. /* length returned includes null termination */
  2742. encodedLen = sizeof(encoded);
  2743. ret = Base16_Encode(testData, sizeof(testData), encoded, &encodedLen);
  2744. if (ret != 0)
  2745. return WC_TEST_RET_ENC_EC(ret);
  2746. len = (word32)XSTRLEN((char*)encoded);
  2747. if (len != encodedLen - 1)
  2748. return WC_TEST_RET_ENC_NC;
  2749. len = sizeof(plain);
  2750. ret = Base16_Decode(encoded, encodedLen - 1, plain, &len);
  2751. if (ret != 0)
  2752. return WC_TEST_RET_ENC_EC(ret);
  2753. if (len != sizeof(testData) || XMEMCMP(testData, plain, len) != 0)
  2754. return WC_TEST_RET_ENC_NC;
  2755. if (encodedLen != sizeof(encodedTestData) ||
  2756. XMEMCMP(encoded, encodedTestData, encodedLen) != 0) {
  2757. return WC_TEST_RET_ENC_NC;
  2758. }
  2759. return 0;
  2760. }
  2761. #endif /* WOLFSSL_BASE16 */
  2762. #endif /* !NO_CODING */
  2763. #ifndef NO_ASN
  2764. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t asn_test(void)
  2765. {
  2766. wc_test_ret_t ret;
  2767. /* ASN1 encoded date buffer */
  2768. WOLFSSL_SMALL_STACK_STATIC const byte dateBuf[] = {
  2769. 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x31,
  2770. 0x32, 0x30, 0x30, 0x37, 0x33, 0x37, 0x5a
  2771. };
  2772. byte format;
  2773. int length;
  2774. const byte* datePart;
  2775. #ifndef NO_ASN_TIME
  2776. struct tm timearg;
  2777. time_t now;
  2778. #endif
  2779. WOLFSSL_ENTER("asn_test");
  2780. ret = wc_GetDateInfo(dateBuf, (int)sizeof(dateBuf), &datePart, &format,
  2781. &length);
  2782. if (ret != 0)
  2783. return WC_TEST_RET_ENC_EC(ret);
  2784. #ifndef NO_ASN_TIME
  2785. /* Parameter Validation tests. */
  2786. if ((ret = wc_GetTime(NULL, sizeof(now))) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  2787. return WC_TEST_RET_ENC_EC(ret);
  2788. if ((ret = wc_GetTime(&now, 0)) != WC_NO_ERR_TRACE(BUFFER_E))
  2789. return WC_TEST_RET_ENC_EC(ret);
  2790. now = 0;
  2791. if ((ret = wc_GetTime(&now, sizeof(now))) != 0) {
  2792. return WC_TEST_RET_ENC_EC(ret);
  2793. }
  2794. if (now == 0) {
  2795. printf("RTC/Time not set!\n");
  2796. return WC_TEST_RET_ENC_NC;
  2797. }
  2798. ret = wc_GetDateAsCalendarTime(datePart, length, format, &timearg);
  2799. if (ret != 0)
  2800. return WC_TEST_RET_ENC_EC(ret);
  2801. #endif /* !NO_ASN_TIME */
  2802. return 0;
  2803. }
  2804. #endif /* !NO_ASN */
  2805. #ifdef WOLFSSL_MD2
  2806. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md2_test(void)
  2807. {
  2808. wc_test_ret_t ret = 0;
  2809. Md2 md2;
  2810. byte hash[MD2_DIGEST_SIZE];
  2811. testVector a, b, c, d, e, f, g;
  2812. testVector test_md2[7];
  2813. int times = sizeof(test_md2) / sizeof(testVector), i;
  2814. WOLFSSL_ENTER("md2_test");
  2815. a.input = "";
  2816. a.output = "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69"
  2817. "\x27\x73";
  2818. a.inLen = XSTRLEN(a.input);
  2819. a.outLen = MD2_DIGEST_SIZE;
  2820. b.input = "a";
  2821. b.output = "\x32\xec\x01\xec\x4a\x6d\xac\x72\xc0\xab\x96\xfb\x34\xc0"
  2822. "\xb5\xd1";
  2823. b.inLen = XSTRLEN(b.input);
  2824. b.outLen = MD2_DIGEST_SIZE;
  2825. c.input = "abc";
  2826. c.output = "\xda\x85\x3b\x0d\x3f\x88\xd9\x9b\x30\x28\x3a\x69\xe6\xde"
  2827. "\xd6\xbb";
  2828. c.inLen = XSTRLEN(c.input);
  2829. c.outLen = MD2_DIGEST_SIZE;
  2830. d.input = "message digest";
  2831. d.output = "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe"
  2832. "\x06\xb0";
  2833. d.inLen = XSTRLEN(d.input);
  2834. d.outLen = MD2_DIGEST_SIZE;
  2835. e.input = "abcdefghijklmnopqrstuvwxyz";
  2836. e.output = "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47"
  2837. "\x94\x0b";
  2838. e.inLen = XSTRLEN(e.input);
  2839. e.outLen = MD2_DIGEST_SIZE;
  2840. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2841. "6789";
  2842. f.output = "\xda\x33\xde\xf2\xa4\x2d\xf1\x39\x75\x35\x28\x46\xc3\x03"
  2843. "\x38\xcd";
  2844. f.inLen = XSTRLEN(f.input);
  2845. f.outLen = MD2_DIGEST_SIZE;
  2846. g.input = "1234567890123456789012345678901234567890123456789012345678"
  2847. "9012345678901234567890";
  2848. g.output = "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3"
  2849. "\xef\xd8";
  2850. g.inLen = XSTRLEN(g.input);
  2851. g.outLen = MD2_DIGEST_SIZE;
  2852. test_md2[0] = a;
  2853. test_md2[1] = b;
  2854. test_md2[2] = c;
  2855. test_md2[3] = d;
  2856. test_md2[4] = e;
  2857. test_md2[5] = f;
  2858. test_md2[6] = g;
  2859. wc_InitMd2(&md2);
  2860. for (i = 0; i < times; ++i) {
  2861. wc_Md2Update(&md2, (byte*)test_md2[i].input, (word32)test_md2[i].inLen);
  2862. wc_Md2Final(&md2, hash);
  2863. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0)
  2864. return WC_TEST_RET_ENC_I(i);
  2865. }
  2866. for (i = 0; i < times; ++i) {
  2867. ret = wc_Md2Hash((byte*)test_md2[i].input, (word32)test_md2[i].inLen, hash);
  2868. if (ret != 0) {
  2869. return WC_TEST_RET_ENC_I(i);
  2870. }
  2871. if (XMEMCMP(hash, test_md2[i].output, MD2_DIGEST_SIZE) != 0) {
  2872. return WC_TEST_RET_ENC_I(i);
  2873. }
  2874. }
  2875. return 0;
  2876. }
  2877. #endif
  2878. #ifndef NO_MD5
  2879. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md5_test(void)
  2880. {
  2881. wc_test_ret_t ret = 0;
  2882. wc_Md5 md5, md5Copy;
  2883. byte hash[WC_MD5_DIGEST_SIZE];
  2884. byte hashcopy[WC_MD5_DIGEST_SIZE];
  2885. testVector a, b, c, d, e, f;
  2886. testVector test_md5[6];
  2887. int times = sizeof(test_md5) / sizeof(testVector), i;
  2888. WOLFSSL_ENTER("md5_test");
  2889. a.input = "";
  2890. a.output = "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\x09\x98\xec\xf8\x42"
  2891. "\x7e";
  2892. a.inLen = XSTRLEN(a.input);
  2893. a.outLen = WC_MD5_DIGEST_SIZE;
  2894. b.input = "abc";
  2895. b.output = "\x90\x01\x50\x98\x3c\xd2\x4f\xb0\xd6\x96\x3f\x7d\x28\xe1\x7f"
  2896. "\x72";
  2897. b.inLen = XSTRLEN(b.input);
  2898. b.outLen = WC_MD5_DIGEST_SIZE;
  2899. c.input = "message digest";
  2900. c.output = "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d\x52\x5a\x2f\x31\xaa\xf1\x61"
  2901. "\xd0";
  2902. c.inLen = XSTRLEN(c.input);
  2903. c.outLen = WC_MD5_DIGEST_SIZE;
  2904. d.input = "abcdefghijklmnopqrstuvwxyz";
  2905. d.output = "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1"
  2906. "\x3b";
  2907. d.inLen = XSTRLEN(d.input);
  2908. d.outLen = WC_MD5_DIGEST_SIZE;
  2909. e.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  2910. "6789";
  2911. e.output = "\xd1\x74\xab\x98\xd2\x77\xd9\xf5\xa5\x61\x1c\x2c\x9f\x41\x9d"
  2912. "\x9f";
  2913. e.inLen = XSTRLEN(e.input);
  2914. e.outLen = WC_MD5_DIGEST_SIZE;
  2915. f.input = "1234567890123456789012345678901234567890123456789012345678"
  2916. "9012345678901234567890";
  2917. f.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  2918. "\x7a";
  2919. f.inLen = XSTRLEN(f.input);
  2920. f.outLen = WC_MD5_DIGEST_SIZE;
  2921. test_md5[0] = a;
  2922. test_md5[1] = b;
  2923. test_md5[2] = c;
  2924. test_md5[3] = d;
  2925. test_md5[4] = e;
  2926. test_md5[5] = f;
  2927. ret = wc_InitMd5_ex(&md5, HEAP_HINT, devId);
  2928. if (ret != 0)
  2929. return WC_TEST_RET_ENC_EC(ret);
  2930. ret = wc_InitMd5_ex(&md5Copy, HEAP_HINT, devId);
  2931. if (ret != 0) {
  2932. wc_Md5Free(&md5);
  2933. return WC_TEST_RET_ENC_EC(ret);
  2934. }
  2935. for (i = 0; i < times; ++i) {
  2936. ret = wc_Md5Update(&md5, (byte*)test_md5[i].input,
  2937. (word32)test_md5[i].inLen);
  2938. if (ret != 0)
  2939. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2940. ret = wc_Md5GetHash(&md5, hashcopy);
  2941. if (ret != 0)
  2942. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2943. ret = wc_Md5Copy(&md5, &md5Copy);
  2944. if (ret != 0)
  2945. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2946. ret = wc_Md5Final(&md5, hash);
  2947. if (ret != 0)
  2948. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2949. wc_Md5Free(&md5Copy);
  2950. if (XMEMCMP(hash, test_md5[i].output, WC_MD5_DIGEST_SIZE) != 0)
  2951. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2952. if (XMEMCMP(hash, hashcopy, WC_MD5_DIGEST_SIZE) != 0)
  2953. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  2954. }
  2955. #ifndef NO_LARGE_HASH_TEST
  2956. /* BEGIN LARGE HASH TEST */ {
  2957. byte large_input[1024];
  2958. const char* large_digest =
  2959. "\x44\xd0\x88\xce\xf1\x36\xd1\x78\xe9\xc8\xba\x84\xc3\xfd\xf6\xca";
  2960. for (i = 0; i < (int)sizeof(large_input); i++) {
  2961. large_input[i] = (byte)(i & 0xFF);
  2962. }
  2963. times = 100;
  2964. #ifdef WOLFSSL_PIC32MZ_HASH
  2965. wc_Md5SizeSet(&md5, times * sizeof(large_input));
  2966. #endif
  2967. for (i = 0; i < times; ++i) {
  2968. ret = wc_Md5Update(&md5, (byte*)large_input,
  2969. (word32)sizeof(large_input));
  2970. if (ret != 0)
  2971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2972. }
  2973. ret = wc_Md5Final(&md5, hash);
  2974. if (ret != 0)
  2975. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  2976. if (XMEMCMP(hash, large_digest, WC_MD5_DIGEST_SIZE) != 0)
  2977. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  2978. } /* END LARGE HASH TEST */
  2979. #endif /* NO_LARGE_HASH_TEST */
  2980. exit:
  2981. wc_Md5Free(&md5);
  2982. wc_Md5Free(&md5Copy);
  2983. return ret;
  2984. }
  2985. #endif /* NO_MD5 */
  2986. #ifndef NO_MD4
  2987. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t md4_test(void)
  2988. {
  2989. Md4 md4;
  2990. byte hash[MD4_DIGEST_SIZE];
  2991. testVector a, b, c, d, e, f, g;
  2992. testVector test_md4[7];
  2993. int times = sizeof(test_md4) / sizeof(testVector), i;
  2994. WOLFSSL_ENTER("md4_test");
  2995. a.input = "";
  2996. a.output = "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89"
  2997. "\xc0";
  2998. a.inLen = XSTRLEN(a.input);
  2999. a.outLen = MD4_DIGEST_SIZE;
  3000. b.input = "a";
  3001. b.output = "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb"
  3002. "\x24";
  3003. b.inLen = XSTRLEN(b.input);
  3004. b.outLen = MD4_DIGEST_SIZE;
  3005. c.input = "abc";
  3006. c.output = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72"
  3007. "\x9d";
  3008. c.inLen = XSTRLEN(c.input);
  3009. c.outLen = MD4_DIGEST_SIZE;
  3010. d.input = "message digest";
  3011. d.output = "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01"
  3012. "\x4b";
  3013. d.inLen = XSTRLEN(d.input);
  3014. d.outLen = MD4_DIGEST_SIZE;
  3015. e.input = "abcdefghijklmnopqrstuvwxyz";
  3016. e.output = "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d"
  3017. "\xa9";
  3018. e.inLen = XSTRLEN(e.input);
  3019. e.outLen = MD4_DIGEST_SIZE;
  3020. f.input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345"
  3021. "6789";
  3022. f.output = "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0"
  3023. "\xe4";
  3024. f.inLen = XSTRLEN(f.input);
  3025. f.outLen = MD4_DIGEST_SIZE;
  3026. g.input = "1234567890123456789012345678901234567890123456789012345678"
  3027. "9012345678901234567890";
  3028. g.output = "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05"
  3029. "\x36";
  3030. g.inLen = XSTRLEN(g.input);
  3031. g.outLen = MD4_DIGEST_SIZE;
  3032. test_md4[0] = a;
  3033. test_md4[1] = b;
  3034. test_md4[2] = c;
  3035. test_md4[3] = d;
  3036. test_md4[4] = e;
  3037. test_md4[5] = f;
  3038. test_md4[6] = g;
  3039. wc_InitMd4(&md4);
  3040. for (i = 0; i < times; ++i) {
  3041. wc_Md4Update(&md4, (byte*)test_md4[i].input, (word32)test_md4[i].inLen);
  3042. wc_Md4Final(&md4, hash);
  3043. if (XMEMCMP(hash, test_md4[i].output, MD4_DIGEST_SIZE) != 0)
  3044. return WC_TEST_RET_ENC_I(i);
  3045. }
  3046. return 0;
  3047. }
  3048. #endif /* NO_MD4 */
  3049. #ifndef NO_SHA
  3050. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha_test(void)
  3051. {
  3052. wc_test_ret_t ret = 0;
  3053. wc_Sha sha, shaCopy;
  3054. byte hash[WC_SHA_DIGEST_SIZE];
  3055. byte hashcopy[WC_SHA_DIGEST_SIZE];
  3056. testVector a, b, c, d, e;
  3057. testVector test_sha[5];
  3058. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3059. WOLFSSL_ENTER("sha_test");
  3060. a.input = "";
  3061. a.output = "\xda\x39\xa3\xee\x5e\x6b\x4b\x0d\x32\x55\xbf\xef\x95\x60\x18"
  3062. "\x90\xaf\xd8\x07\x09";
  3063. a.inLen = XSTRLEN(a.input);
  3064. a.outLen = WC_SHA_DIGEST_SIZE;
  3065. b.input = "abc";
  3066. b.output = "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E\x25\x71\x78\x50\xC2"
  3067. "\x6C\x9C\xD0\xD8\x9D";
  3068. b.inLen = XSTRLEN(b.input);
  3069. b.outLen = WC_SHA_DIGEST_SIZE;
  3070. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3071. c.output = "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE\x4A\xA1\xF9\x51\x29"
  3072. "\xE5\xE5\x46\x70\xF1";
  3073. c.inLen = XSTRLEN(c.input);
  3074. c.outLen = WC_SHA_DIGEST_SIZE;
  3075. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3076. "aaaaaa";
  3077. d.output = "\x00\x98\xBA\x82\x4B\x5C\x16\x42\x7B\xD7\xA1\x12\x2A\x5A\x44"
  3078. "\x2A\x25\xEC\x64\x4D";
  3079. d.inLen = XSTRLEN(d.input);
  3080. d.outLen = WC_SHA_DIGEST_SIZE;
  3081. e.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3082. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3083. "aaaaaaaaaa";
  3084. e.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  3085. "\x53\x99\x5E\x26\xA0";
  3086. e.inLen = XSTRLEN(e.input);
  3087. e.outLen = WC_SHA_DIGEST_SIZE;
  3088. test_sha[0] = a;
  3089. test_sha[1] = b;
  3090. test_sha[2] = c;
  3091. test_sha[3] = d;
  3092. test_sha[4] = e;
  3093. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  3094. if (ret != 0)
  3095. return WC_TEST_RET_ENC_EC(ret);
  3096. ret = wc_InitSha_ex(&shaCopy, HEAP_HINT, devId);
  3097. if (ret != 0) {
  3098. wc_ShaFree(&sha);
  3099. return WC_TEST_RET_ENC_EC(ret);
  3100. }
  3101. for (i = 0; i < times; ++i) {
  3102. ret = wc_ShaUpdate(&sha, (byte*)test_sha[i].input,
  3103. (word32)test_sha[i].inLen);
  3104. if (ret != 0)
  3105. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3106. ret = wc_ShaGetHash(&sha, hashcopy);
  3107. if (ret != 0)
  3108. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3109. ret = wc_ShaCopy(&sha, &shaCopy);
  3110. if (ret != 0)
  3111. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3112. ret = wc_ShaFinal(&sha, hash);
  3113. if (ret != 0)
  3114. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3115. wc_ShaFree(&shaCopy);
  3116. if (XMEMCMP(hash, test_sha[i].output, WC_SHA_DIGEST_SIZE) != 0)
  3117. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3118. if (XMEMCMP(hash, hashcopy, WC_SHA_DIGEST_SIZE) != 0)
  3119. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3120. }
  3121. #ifndef NO_LARGE_HASH_TEST
  3122. /* BEGIN LARGE HASH TEST */ {
  3123. byte large_input[1024];
  3124. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3125. defined(HASH_SIZE_LIMIT)
  3126. const char* large_digest =
  3127. "\x1d\x6a\x5a\xf6\xe5\x7c\x86\xce\x7f\x7c\xaf\xd5\xdb\x08\xcd\x59"
  3128. "\x15\x8c\x6d\xb6";
  3129. #else
  3130. const char* large_digest =
  3131. "\x8b\x77\x02\x48\x39\xe8\xdb\xd3\x9a\xf4\x05\x24\x66\x12\x2d\x9e"
  3132. "\xc5\xd9\x0a\xac";
  3133. #endif
  3134. for (i = 0; i < (int)sizeof(large_input); i++) {
  3135. large_input[i] = (byte)(i & 0xFF);
  3136. }
  3137. #if defined(WOLFSSL_RENESAS_TSIP) || defined(WOLFSSL_RENESAS_SCEPROTECT) || \
  3138. defined(HASH_SIZE_LIMIT)
  3139. times = 20;
  3140. #else
  3141. times = 100;
  3142. #endif
  3143. #ifdef WOLFSSL_PIC32MZ_HASH
  3144. wc_ShaSizeSet(&sha, times * sizeof(large_input));
  3145. #endif
  3146. for (i = 0; i < times; ++i) {
  3147. ret = wc_ShaUpdate(&sha, (byte*)large_input,
  3148. (word32)sizeof(large_input));
  3149. if (ret != 0)
  3150. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3151. }
  3152. ret = wc_ShaFinal(&sha, hash);
  3153. if (ret != 0)
  3154. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3155. if (XMEMCMP(hash, large_digest, WC_SHA_DIGEST_SIZE) != 0)
  3156. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3157. } /* END LARGE HASH TEST */
  3158. #endif /* NO_LARGE_HASH_TEST */
  3159. exit:
  3160. wc_ShaFree(&sha);
  3161. wc_ShaFree(&shaCopy);
  3162. return ret;
  3163. }
  3164. #endif /* NO_SHA */
  3165. #ifdef WOLFSSL_RIPEMD
  3166. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ripemd_test(void)
  3167. {
  3168. RipeMd ripemd;
  3169. wc_test_ret_t ret;
  3170. byte hash[RIPEMD_DIGEST_SIZE];
  3171. testVector a, b, c, d;
  3172. testVector test_ripemd[4];
  3173. int times = sizeof(test_ripemd) / sizeof(struct testVector), i;
  3174. WOLFSSL_ENTER("ripemd_test");
  3175. a.input = "abc";
  3176. a.output = "\x8e\xb2\x08\xf7\xe0\x5d\x98\x7a\x9b\x04\x4a\x8e\x98\xc6"
  3177. "\xb0\x87\xf1\x5a\x0b\xfc";
  3178. a.inLen = XSTRLEN(a.input);
  3179. a.outLen = RIPEMD_DIGEST_SIZE;
  3180. b.input = "message digest";
  3181. b.output = "\x5d\x06\x89\xef\x49\xd2\xfa\xe5\x72\xb8\x81\xb1\x23\xa8"
  3182. "\x5f\xfa\x21\x59\x5f\x36";
  3183. b.inLen = XSTRLEN(b.input);
  3184. b.outLen = RIPEMD_DIGEST_SIZE;
  3185. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3186. c.output = "\x12\xa0\x53\x38\x4a\x9c\x0c\x88\xe4\x05\xa0\x6c\x27\xdc"
  3187. "\xf4\x9a\xda\x62\xeb\x2b";
  3188. c.inLen = XSTRLEN(c.input);
  3189. c.outLen = RIPEMD_DIGEST_SIZE;
  3190. d.input = "12345678901234567890123456789012345678901234567890123456"
  3191. "789012345678901234567890";
  3192. d.output = "\x9b\x75\x2e\x45\x57\x3d\x4b\x39\xf4\xdb\xd3\x32\x3c\xab"
  3193. "\x82\xbf\x63\x32\x6b\xfb";
  3194. d.inLen = XSTRLEN(d.input);
  3195. d.outLen = RIPEMD_DIGEST_SIZE;
  3196. test_ripemd[0] = a;
  3197. test_ripemd[1] = b;
  3198. test_ripemd[2] = c;
  3199. test_ripemd[3] = d;
  3200. ret = wc_InitRipeMd(&ripemd);
  3201. if (ret != 0) {
  3202. return WC_TEST_RET_ENC_EC(ret);
  3203. }
  3204. for (i = 0; i < times; ++i) {
  3205. ret = wc_RipeMdUpdate(&ripemd, (byte*)test_ripemd[i].input,
  3206. (word32)test_ripemd[i].inLen);
  3207. if (ret != 0) {
  3208. return WC_TEST_RET_ENC_I(i);
  3209. }
  3210. ret = wc_RipeMdFinal(&ripemd, hash);
  3211. if (ret != 0) {
  3212. return WC_TEST_RET_ENC_I(i);
  3213. }
  3214. if (XMEMCMP(hash, test_ripemd[i].output, RIPEMD_DIGEST_SIZE) != 0)
  3215. return WC_TEST_RET_ENC_I(i);
  3216. }
  3217. return 0;
  3218. }
  3219. #endif /* WOLFSSL_RIPEMD */
  3220. #ifdef HAVE_BLAKE2
  3221. #define BLAKE2B_TESTS 3
  3222. static const byte blake2b_vec[BLAKE2B_TESTS][BLAKE2B_OUTBYTES] =
  3223. {
  3224. {
  3225. 0x78, 0x6A, 0x02, 0xF7, 0x42, 0x01, 0x59, 0x03,
  3226. 0xC6, 0xC6, 0xFD, 0x85, 0x25, 0x52, 0xD2, 0x72,
  3227. 0x91, 0x2F, 0x47, 0x40, 0xE1, 0x58, 0x47, 0x61,
  3228. 0x8A, 0x86, 0xE2, 0x17, 0xF7, 0x1F, 0x54, 0x19,
  3229. 0xD2, 0x5E, 0x10, 0x31, 0xAF, 0xEE, 0x58, 0x53,
  3230. 0x13, 0x89, 0x64, 0x44, 0x93, 0x4E, 0xB0, 0x4B,
  3231. 0x90, 0x3A, 0x68, 0x5B, 0x14, 0x48, 0xB7, 0x55,
  3232. 0xD5, 0x6F, 0x70, 0x1A, 0xFE, 0x9B, 0xE2, 0xCE
  3233. },
  3234. {
  3235. 0x2F, 0xA3, 0xF6, 0x86, 0xDF, 0x87, 0x69, 0x95,
  3236. 0x16, 0x7E, 0x7C, 0x2E, 0x5D, 0x74, 0xC4, 0xC7,
  3237. 0xB6, 0xE4, 0x8F, 0x80, 0x68, 0xFE, 0x0E, 0x44,
  3238. 0x20, 0x83, 0x44, 0xD4, 0x80, 0xF7, 0x90, 0x4C,
  3239. 0x36, 0x96, 0x3E, 0x44, 0x11, 0x5F, 0xE3, 0xEB,
  3240. 0x2A, 0x3A, 0xC8, 0x69, 0x4C, 0x28, 0xBC, 0xB4,
  3241. 0xF5, 0xA0, 0xF3, 0x27, 0x6F, 0x2E, 0x79, 0x48,
  3242. 0x7D, 0x82, 0x19, 0x05, 0x7A, 0x50, 0x6E, 0x4B
  3243. },
  3244. {
  3245. 0x1C, 0x08, 0x79, 0x8D, 0xC6, 0x41, 0xAB, 0xA9,
  3246. 0xDE, 0xE4, 0x35, 0xE2, 0x25, 0x19, 0xA4, 0x72,
  3247. 0x9A, 0x09, 0xB2, 0xBF, 0xE0, 0xFF, 0x00, 0xEF,
  3248. 0x2D, 0xCD, 0x8E, 0xD6, 0xF8, 0xA0, 0x7D, 0x15,
  3249. 0xEA, 0xF4, 0xAE, 0xE5, 0x2B, 0xBF, 0x18, 0xAB,
  3250. 0x56, 0x08, 0xA6, 0x19, 0x0F, 0x70, 0xB9, 0x04,
  3251. 0x86, 0xC8, 0xA7, 0xD4, 0x87, 0x37, 0x10, 0xB1,
  3252. 0x11, 0x5D, 0x3D, 0xEB, 0xBB, 0x43, 0x27, 0xB5
  3253. }
  3254. };
  3255. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2b_test(void)
  3256. {
  3257. Blake2b b2b;
  3258. byte digest[64];
  3259. byte input[64];
  3260. int i, ret;
  3261. WOLFSSL_ENTER("blake2b_test");
  3262. for (i = 0; i < (int)sizeof(input); i++)
  3263. input[i] = (byte)i;
  3264. for (i = 0; i < BLAKE2B_TESTS; i++) {
  3265. ret = wc_InitBlake2b(&b2b, 64);
  3266. if (ret != 0)
  3267. return WC_TEST_RET_ENC_I(i);
  3268. ret = wc_Blake2bUpdate(&b2b, input, (word32)i);
  3269. if (ret != 0)
  3270. return WC_TEST_RET_ENC_I(i);
  3271. ret = wc_Blake2bFinal(&b2b, digest, 64);
  3272. if (ret != 0)
  3273. return WC_TEST_RET_ENC_I(i);
  3274. if (XMEMCMP(digest, blake2b_vec[i], 64) != 0) {
  3275. return WC_TEST_RET_ENC_I(i);
  3276. }
  3277. }
  3278. return 0;
  3279. }
  3280. #endif /* HAVE_BLAKE2 */
  3281. #ifdef HAVE_BLAKE2S
  3282. #define BLAKE2S_TESTS 3
  3283. static const byte blake2s_vec[BLAKE2S_TESTS][BLAKE2S_OUTBYTES] =
  3284. {
  3285. {
  3286. 0x69, 0x21, 0x7a, 0x30, 0x79, 0x90, 0x80, 0x94,
  3287. 0xe1, 0x11, 0x21, 0xd0, 0x42, 0x35, 0x4a, 0x7c,
  3288. 0x1f, 0x55, 0xb6, 0x48, 0x2c, 0xa1, 0xa5, 0x1e,
  3289. 0x1b, 0x25, 0x0d, 0xfd, 0x1e, 0xd0, 0xee, 0xf9,
  3290. },
  3291. {
  3292. 0xe3, 0x4d, 0x74, 0xdb, 0xaf, 0x4f, 0xf4, 0xc6,
  3293. 0xab, 0xd8, 0x71, 0xcc, 0x22, 0x04, 0x51, 0xd2,
  3294. 0xea, 0x26, 0x48, 0x84, 0x6c, 0x77, 0x57, 0xfb,
  3295. 0xaa, 0xc8, 0x2f, 0xe5, 0x1a, 0xd6, 0x4b, 0xea,
  3296. },
  3297. {
  3298. 0xdd, 0xad, 0x9a, 0xb1, 0x5d, 0xac, 0x45, 0x49,
  3299. 0xba, 0x42, 0xf4, 0x9d, 0x26, 0x24, 0x96, 0xbe,
  3300. 0xf6, 0xc0, 0xba, 0xe1, 0xdd, 0x34, 0x2a, 0x88,
  3301. 0x08, 0xf8, 0xea, 0x26, 0x7c, 0x6e, 0x21, 0x0c,
  3302. }
  3303. };
  3304. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blake2s_test(void)
  3305. {
  3306. Blake2s b2s;
  3307. byte digest[32];
  3308. byte input[64];
  3309. int i, ret;
  3310. WOLFSSL_ENTER("blake2s_test");
  3311. for (i = 0; i < (int)sizeof(input); i++)
  3312. input[i] = (byte)i;
  3313. for (i = 0; i < BLAKE2S_TESTS; i++) {
  3314. ret = wc_InitBlake2s(&b2s, 32);
  3315. if (ret != 0)
  3316. return WC_TEST_RET_ENC_I(i);
  3317. ret = wc_Blake2sUpdate(&b2s, input, (word32)i);
  3318. if (ret != 0)
  3319. return WC_TEST_RET_ENC_I(i);
  3320. ret = wc_Blake2sFinal(&b2s, digest, 32);
  3321. if (ret != 0)
  3322. return WC_TEST_RET_ENC_I(i);
  3323. if (XMEMCMP(digest, blake2s_vec[i], 32) != 0) {
  3324. return WC_TEST_RET_ENC_I(i);
  3325. }
  3326. }
  3327. return 0;
  3328. }
  3329. #endif /* HAVE_BLAKE2S */
  3330. #ifdef WOLFSSL_SHA224
  3331. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha224_test(void)
  3332. {
  3333. wc_Sha224 sha, shaCopy;
  3334. byte hash[WC_SHA224_DIGEST_SIZE];
  3335. byte hashcopy[WC_SHA224_DIGEST_SIZE];
  3336. wc_test_ret_t ret = 0;
  3337. testVector a, b, c;
  3338. testVector test_sha[3];
  3339. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3340. WOLFSSL_ENTER("sha224_test");
  3341. a.input = "";
  3342. a.output = "\xd1\x4a\x02\x8c\x2a\x3a\x2b\xc9\x47\x61\x02\xbb\x28\x82\x34"
  3343. "\xc4\x15\xa2\xb0\x1f\x82\x8e\xa6\x2a\xc5\xb3\xe4\x2f";
  3344. a.inLen = XSTRLEN(a.input);
  3345. a.outLen = WC_SHA224_DIGEST_SIZE;
  3346. b.input = "abc";
  3347. b.output = "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55"
  3348. "\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7";
  3349. b.inLen = XSTRLEN(b.input);
  3350. b.outLen = WC_SHA224_DIGEST_SIZE;
  3351. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3352. c.output = "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01"
  3353. "\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25";
  3354. c.inLen = XSTRLEN(c.input);
  3355. c.outLen = WC_SHA224_DIGEST_SIZE;
  3356. test_sha[0] = a;
  3357. test_sha[1] = b;
  3358. test_sha[2] = c;
  3359. ret = wc_InitSha224_ex(&sha, HEAP_HINT, devId);
  3360. if (ret != 0)
  3361. return WC_TEST_RET_ENC_EC(ret);
  3362. ret = wc_InitSha224_ex(&shaCopy, HEAP_HINT, devId);
  3363. if (ret != 0) {
  3364. wc_Sha224Free(&sha);
  3365. return WC_TEST_RET_ENC_EC(ret);
  3366. }
  3367. for (i = 0; i < times; ++i) {
  3368. ret = wc_Sha224Update(&sha, (byte*)test_sha[i].input,
  3369. (word32)test_sha[i].inLen);
  3370. if (ret != 0)
  3371. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3372. ret = wc_Sha224GetHash(&sha, hashcopy);
  3373. if (ret != 0)
  3374. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3375. ret = wc_Sha224Copy(&sha, &shaCopy);
  3376. if (ret != 0)
  3377. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3378. ret = wc_Sha224Final(&sha, hash);
  3379. if (ret != 0)
  3380. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3381. wc_Sha224Free(&shaCopy);
  3382. if (XMEMCMP(hash, test_sha[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  3383. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3384. if (XMEMCMP(hash, hashcopy, WC_SHA224_DIGEST_SIZE) != 0)
  3385. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3386. }
  3387. exit:
  3388. wc_Sha224Free(&sha);
  3389. wc_Sha224Free(&shaCopy);
  3390. return ret;
  3391. }
  3392. #endif
  3393. #ifndef NO_SHA256
  3394. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
  3395. {
  3396. wc_Sha256 sha, shaCopy;
  3397. byte hash[WC_SHA256_DIGEST_SIZE];
  3398. byte hashcopy[WC_SHA256_DIGEST_SIZE];
  3399. wc_test_ret_t ret = 0;
  3400. testVector a, b, c, d;
  3401. testVector test_sha[4];
  3402. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3403. byte i_hash[WC_SHA256_DIGEST_SIZE];
  3404. byte i_hashcopy[WC_SHA256_DIGEST_SIZE];
  3405. testVector interleave_test_sha[4];
  3406. wc_Sha256 i_sha, i_shaCopy;
  3407. #endif
  3408. #ifndef NO_LARGE_HASH_TEST
  3409. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3410. #ifdef WOLFSSL_SMALL_STACK
  3411. byte *large_input = NULL;
  3412. #else
  3413. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3414. #endif
  3415. #endif
  3416. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3417. WOLFSSL_ENTER("sha256_test");
  3418. a.input = "";
  3419. a.output = "\xe3\xb0\xc4\x42\x98\xfc\x1c\x14\x9a\xfb\xf4\xc8\x99\x6f\xb9"
  3420. "\x24\x27\xae\x41\xe4\x64\x9b\x93\x4c\xa4\x95\x99\x1b\x78\x52"
  3421. "\xb8\x55";
  3422. a.inLen = XSTRLEN(a.input);
  3423. a.outLen = WC_SHA256_DIGEST_SIZE;
  3424. b.input = "abc";
  3425. b.output = "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22"
  3426. "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00"
  3427. "\x15\xAD";
  3428. b.inLen = XSTRLEN(b.input);
  3429. b.outLen = WC_SHA256_DIGEST_SIZE;
  3430. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  3431. c.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  3432. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  3433. "\x06\xC1";
  3434. c.inLen = XSTRLEN(c.input);
  3435. c.outLen = WC_SHA256_DIGEST_SIZE;
  3436. d.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  3437. "aaaaaa"; /* this is BLOCKSIZE length */
  3438. d.output = "\xFF\xE0\x54\xFE\x7A\xE0\xCB\x6D\xC6\x5C\x3A\xF9\xB6\x1D\x52"
  3439. "\x09\xF4\x39\x85\x1D\xB4\x3D\x0B\xA5\x99\x73\x37\xDF\x15\x46"
  3440. "\x68\xEB";
  3441. d.inLen = XSTRLEN(d.input);
  3442. d.outLen = WC_SHA256_DIGEST_SIZE;
  3443. test_sha[0] = a;
  3444. test_sha[1] = b;
  3445. test_sha[2] = c;
  3446. test_sha[3] = d;
  3447. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3448. interleave_test_sha[0] = a;
  3449. interleave_test_sha[1] = b;
  3450. interleave_test_sha[2] = c;
  3451. interleave_test_sha[3] = d;
  3452. #endif
  3453. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  3454. if (ret != 0)
  3455. return WC_TEST_RET_ENC_EC(ret);
  3456. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3457. ret = wc_InitSha256_ex(&i_sha, HEAP_HINT, devId);
  3458. if (ret != 0)
  3459. return WC_TEST_RET_ENC_EC(ret);
  3460. #endif
  3461. ret = wc_InitSha256_ex(&shaCopy, HEAP_HINT, devId);
  3462. if (ret != 0) {
  3463. wc_Sha256Free(&sha);
  3464. return WC_TEST_RET_ENC_EC(ret);
  3465. }
  3466. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3467. ret = wc_InitSha256_ex(&i_shaCopy, HEAP_HINT, devId);
  3468. if (ret != 0) {
  3469. wc_Sha256Free(&sha);
  3470. wc_Sha256Free(&i_sha);
  3471. return WC_TEST_RET_ENC_EC(ret);
  3472. }
  3473. #endif
  3474. for (i = 0; i < times; ++i) {
  3475. ret = wc_Sha256Update(&sha, (byte*)test_sha[i].input,
  3476. (word32)test_sha[i].inLen);
  3477. if (ret != 0) {
  3478. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3479. }
  3480. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3481. ret = wc_Sha256Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3482. (word32)interleave_test_sha[i].inLen);
  3483. if (ret != 0) {
  3484. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3485. }
  3486. #endif
  3487. ret = wc_Sha256GetHash(&sha, hashcopy);
  3488. if (ret != 0)
  3489. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3490. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3491. ret = wc_Sha256GetHash(&i_sha, i_hashcopy);
  3492. if (ret != 0)
  3493. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3494. #endif
  3495. ret = wc_Sha256Copy(&sha, &shaCopy);
  3496. if (ret != 0)
  3497. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3498. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3499. ret = wc_Sha256Copy(&i_sha, &i_shaCopy);
  3500. if (ret != 0)
  3501. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3502. #endif
  3503. ret = wc_Sha256Final(&sha, hash);
  3504. if (ret != 0)
  3505. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3506. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3507. ret = wc_Sha256Final(&i_sha, i_hash);
  3508. if (ret != 0)
  3509. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3510. #endif
  3511. wc_Sha256Free(&shaCopy);
  3512. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3513. wc_Sha256Free(&i_shaCopy);
  3514. #endif
  3515. if (XMEMCMP(hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3516. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3517. }
  3518. if (XMEMCMP(hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3519. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3520. }
  3521. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3522. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3523. WC_SHA256_DIGEST_SIZE) != 0) {
  3524. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3525. }
  3526. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3527. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3528. }
  3529. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA256_DIGEST_SIZE) != 0) {
  3530. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3531. }
  3532. if (XMEMCMP(i_hash, hashcopy, WC_SHA256_DIGEST_SIZE) != 0) {
  3533. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3534. }
  3535. #endif
  3536. }
  3537. #ifndef NO_LARGE_HASH_TEST
  3538. /* BEGIN LARGE HASH TEST */ {
  3539. #ifdef HASH_SIZE_LIMIT
  3540. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3541. "\xa4\x75\x9e\x7a\xa2\x03\x38\x32\x88\x66\xa2\xea\x17\xea\xf8\xc7"
  3542. "\xfe\x4e\xc6\xbb\xe3\xbb\x71\xce\xe7\xdf\x7c\x04\x61\xb3\xc2\x2f";
  3543. #else
  3544. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3545. "\x27\x78\x3e\x87\x96\x3a\x4e\xfb\x68\x29\xb5\x31\xc9\xba\x57\xb4"
  3546. "\x4f\x45\x79\x7f\x67\x70\xbd\x63\x7f\xbf\x0d\x80\x7c\xbd\xba\xe0";
  3547. #endif
  3548. #ifdef WOLFSSL_SMALL_STACK
  3549. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3550. DYNAMIC_TYPE_TMP_BUFFER);
  3551. if (large_input == NULL) {
  3552. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3553. }
  3554. #endif
  3555. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3556. large_input[i] = (byte)(i & 0xFF);
  3557. }
  3558. #ifdef HASH_SIZE_LIMIT
  3559. times = 20;
  3560. #else
  3561. times = 100;
  3562. #endif
  3563. #ifdef WOLFSSL_PIC32MZ_HASH
  3564. wc_Sha256SizeSet(&sha, times * LARGE_HASH_TEST_INPUT_SZ);
  3565. #endif
  3566. for (i = 0; i < times; ++i) {
  3567. ret = wc_Sha256Update(&sha, (byte*)large_input,
  3568. LARGE_HASH_TEST_INPUT_SZ);
  3569. if (ret != 0)
  3570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3571. }
  3572. ret = wc_Sha256Final(&sha, hash);
  3573. if (ret != 0)
  3574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3575. if (XMEMCMP(hash, large_digest, WC_SHA256_DIGEST_SIZE) != 0)
  3576. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3577. } /* END LARGE HASH TEST */
  3578. #undef LARGE_HASH_TEST_INPUT_SZ
  3579. #endif /* NO_LARGE_HASH_TEST */
  3580. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_FULL_HASH)
  3581. {
  3582. WOLFSSL_SMALL_STACK_STATIC const unsigned char
  3583. data_hb[WC_SHA256_BLOCK_SIZE] = {
  3584. 0x61, 0x62, 0x63, 0x80, 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, 0x00,
  3590. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3591. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18
  3592. };
  3593. ret = wc_Sha256HashBlock(&sha, data_hb, hash);
  3594. if (ret != 0) {
  3595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3596. }
  3597. if (XMEMCMP(hash, b.output, WC_SHA256_DIGEST_SIZE) != 0) {
  3598. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3599. }
  3600. }
  3601. #endif
  3602. exit:
  3603. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3604. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3605. #endif
  3606. wc_Sha256Free(&sha);
  3607. wc_Sha256Free(&shaCopy);
  3608. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3609. wc_Sha256Free(&i_sha);
  3610. wc_Sha256Free(&i_shaCopy);
  3611. #endif
  3612. return ret;
  3613. }
  3614. #endif
  3615. #ifdef WOLFSSL_SHA512
  3616. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
  3617. {
  3618. /*
  3619. ** See https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512.pdf
  3620. */
  3621. wc_Sha512 sha, shaCopy;
  3622. byte hash[WC_SHA512_DIGEST_SIZE];
  3623. byte hashcopy[WC_SHA512_DIGEST_SIZE];
  3624. wc_test_ret_t ret = 0;
  3625. testVector a, b, c;
  3626. testVector test_sha[3];
  3627. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3628. wc_Sha512 i_sha, i_shaCopy;
  3629. byte i_hash[WC_SHA512_DIGEST_SIZE];
  3630. byte i_hashcopy[WC_SHA512_DIGEST_SIZE];
  3631. testVector interleave_test_sha[3];
  3632. #endif
  3633. #ifndef NO_LARGE_HASH_TEST
  3634. #define LARGE_HASH_TEST_INPUT_SZ 1024
  3635. #ifdef WOLFSSL_SMALL_STACK
  3636. byte *large_input = NULL;
  3637. #else
  3638. byte large_input[LARGE_HASH_TEST_INPUT_SZ];
  3639. #endif
  3640. #endif
  3641. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3642. WOLFSSL_ENTER("sha512_test");
  3643. a.input = "";
  3644. a.output = "\xcf\x83\xe1\x35\x7e\xef\xb8\xbd\xf1\x54\x28\x50\xd6\x6d\x80"
  3645. "\x07\xd6\x20\xe4\x05\x0b\x57\x15\xdc\x83\xf4\xa9\x21\xd3\x6c"
  3646. "\xe9\xce\x47\xd0\xd1\x3c\x5d\x85\xf2\xb0\xff\x83\x18\xd2\x87"
  3647. "\x7e\xec\x2f\x63\xb9\x31\xbd\x47\x41\x7a\x81\xa5\x38\x32\x7a"
  3648. "\xf9\x27\xda\x3e";
  3649. a.inLen = XSTRLEN(a.input);
  3650. a.outLen = WC_SHA512_DIGEST_SIZE;
  3651. b.input = "abc";
  3652. b.output = "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41"
  3653. "\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55"
  3654. "\xd3\x9a\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3"
  3655. "\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f"
  3656. "\xa5\x4c\xa4\x9f";
  3657. b.inLen = XSTRLEN(b.input);
  3658. b.outLen = WC_SHA512_DIGEST_SIZE;
  3659. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3660. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3661. c.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  3662. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  3663. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  3664. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  3665. "\x87\x4b\xe9\x09";
  3666. c.inLen = XSTRLEN(c.input);
  3667. c.outLen = WC_SHA512_DIGEST_SIZE;
  3668. test_sha[0] = a;
  3669. test_sha[1] = b;
  3670. test_sha[2] = c;
  3671. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3672. interleave_test_sha[0] = a;
  3673. interleave_test_sha[1] = b;
  3674. interleave_test_sha[2] = c;
  3675. #endif
  3676. ret = wc_InitSha512_ex(&sha, HEAP_HINT, devId);
  3677. if (ret != 0)
  3678. return WC_TEST_RET_ENC_EC(ret);
  3679. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3680. ret = wc_InitSha512_ex(&i_sha, HEAP_HINT, devId);
  3681. if (ret != 0)
  3682. return WC_TEST_RET_ENC_EC(ret);
  3683. #endif
  3684. ret = wc_InitSha512_ex(&shaCopy, HEAP_HINT, devId);
  3685. if (ret != 0) {
  3686. wc_Sha512Free(&sha);
  3687. return WC_TEST_RET_ENC_EC(ret);
  3688. }
  3689. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3690. ret = wc_InitSha512_ex(&i_shaCopy, HEAP_HINT, devId);
  3691. if (ret != 0) {
  3692. wc_Sha512Free(&sha);
  3693. wc_Sha512Free(&i_sha);
  3694. return WC_TEST_RET_ENC_EC(ret);
  3695. }
  3696. #endif
  3697. for (i = 0; i < times; ++i) {
  3698. ret = wc_Sha512Update(&sha, (byte*)test_sha[i].input,
  3699. (word32)test_sha[i].inLen);
  3700. if (ret != 0)
  3701. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3702. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3703. ret = wc_Sha512Update(&i_sha, (byte*)interleave_test_sha[i].input,
  3704. (word32)interleave_test_sha[i].inLen);
  3705. if (ret != 0)
  3706. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3707. #endif
  3708. ret = wc_Sha512GetHash(&sha, hashcopy);
  3709. if (ret != 0)
  3710. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3711. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3712. ret = wc_Sha512GetHash(&i_sha, i_hashcopy);
  3713. if (ret != 0)
  3714. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3715. #endif
  3716. ret = wc_Sha512Copy(&sha, &shaCopy);
  3717. if (ret != 0)
  3718. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3719. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3720. ret = wc_Sha512Copy(&i_sha, &i_shaCopy);
  3721. if (ret != 0)
  3722. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3723. #endif
  3724. ret = wc_Sha512Final(&sha, hash);
  3725. if (ret != 0)
  3726. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3727. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3728. ret = wc_Sha512Final(&i_sha, i_hash);
  3729. if (ret != 0)
  3730. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3731. #endif
  3732. wc_Sha512Free(&shaCopy);
  3733. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3734. wc_Sha512Free(&i_shaCopy);
  3735. #endif
  3736. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  3737. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3738. if (XMEMCMP(hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0)
  3739. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3740. #ifndef NO_WOLFSSL_SHA512_INTERLEAVE
  3741. if (XMEMCMP(i_hash, interleave_test_sha[i].output,
  3742. WC_SHA512_DIGEST_SIZE) != 0) {
  3743. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3744. }
  3745. if (XMEMCMP(i_hash, i_hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3746. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3747. }
  3748. if (XMEMCMP(i_hash, test_sha[i].output, WC_SHA512_DIGEST_SIZE) != 0) {
  3749. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3750. }
  3751. if (XMEMCMP(i_hash, hashcopy, WC_SHA512_DIGEST_SIZE) != 0) {
  3752. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3753. }
  3754. #endif
  3755. }
  3756. #ifndef NO_LARGE_HASH_TEST
  3757. /* BEGIN LARGE HASH TEST */ {
  3758. #ifdef HASH_SIZE_LIMIT
  3759. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3760. "\x30\x9B\x96\xA6\xE9\x43\x78\x30\xA3\x71\x51\x61\xC1\xEB\xE1\xBE"
  3761. "\xC8\xA5\xF9\x13\x5A\xD6\x6D\x9E\x46\x31\x31\x67\x8D\xE2\xC0\x0B"
  3762. "\x2A\x1A\x03\xE1\xF3\x48\xA7\x33\xBD\x49\xF8\xFF\xF1\xC2\xC2\x95"
  3763. "\xCB\xF0\xAF\x87\x61\x85\x58\x63\x6A\xCA\x70\x9C\x8B\x83\x3F\x5D";
  3764. #else
  3765. WOLFSSL_SMALL_STACK_STATIC const char* large_digest =
  3766. "\x5a\x1f\x73\x90\xbd\x8c\xe4\x63\x54\xce\xa0\x9b\xef\x32\x78\x2d"
  3767. "\x2e\xe7\x0d\x5e\x2f\x9d\x15\x1b\xdd\x2d\xde\x65\x0c\x7b\xfa\x83"
  3768. "\x5e\x80\x02\x13\x84\xb8\x3f\xff\x71\x62\xb5\x09\x89\x63\xe1\xdc"
  3769. "\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
  3770. #endif
  3771. #ifdef WOLFSSL_SMALL_STACK
  3772. large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
  3773. DYNAMIC_TYPE_TMP_BUFFER);
  3774. if (large_input == NULL) {
  3775. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
  3776. }
  3777. #endif
  3778. for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
  3779. large_input[i] = (byte)(i & 0xFF);
  3780. }
  3781. #ifdef HASH_SIZE_LIMIT
  3782. times = 20;
  3783. #else
  3784. times = 100;
  3785. #endif
  3786. for (i = 0; i < times; ++i) {
  3787. ret = wc_Sha512Update(&sha, (byte*)large_input,
  3788. LARGE_HASH_TEST_INPUT_SZ);
  3789. if (ret != 0)
  3790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3791. }
  3792. ret = wc_Sha512Final(&sha, hash);
  3793. if (ret != 0)
  3794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3795. if (XMEMCMP(hash, large_digest, WC_SHA512_DIGEST_SIZE) != 0)
  3796. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3797. #ifndef NO_UNALIGNED_MEMORY_TEST
  3798. /* Unaligned memory access test */
  3799. for (i = 1; i < 16; i++) {
  3800. ret = wc_Sha512Update(&sha, (byte*)large_input + i,
  3801. LARGE_HASH_TEST_INPUT_SZ - (word32)i);
  3802. if (ret != 0)
  3803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3804. ret = wc_Sha512Final(&sha, hash);
  3805. }
  3806. #endif
  3807. } /* END LARGE HASH TEST */
  3808. #undef LARGE_HASH_TEST_INPUT_SZ
  3809. #endif /* NO_LARGE_HASH_TEST */
  3810. exit:
  3811. #if !defined(NO_LARGE_HASH_TEST) && defined(WOLFSSL_SMALL_STACK)
  3812. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3813. #endif
  3814. wc_Sha512Free(&sha);
  3815. wc_Sha512Free(&shaCopy);
  3816. #ifndef NO_WOLFSSL_SHA256_INTERLEAVE
  3817. wc_Sha512Free(&i_sha);
  3818. wc_Sha512Free(&i_shaCopy);
  3819. #endif
  3820. return ret;
  3821. }
  3822. #if !defined(WOLFSSL_NOSHA512_224) && \
  3823. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3824. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_224_test(void)
  3825. {
  3826. /*
  3827. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3828. **
  3829. ** NIST SHA512/224 Document Example:
  3830. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_224.pdf
  3831. */
  3832. wc_Sha512 sha, shaCopy;
  3833. byte hash[WC_SHA512_224_DIGEST_SIZE];
  3834. byte hashcopy[WC_SHA512_224_DIGEST_SIZE];
  3835. wc_test_ret_t ret = 0;
  3836. testVector a, b, c;
  3837. testVector test_sha[3];
  3838. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3839. WOLFSSL_ENTER("sha512_224_test");
  3840. a.input = "";
  3841. a.output = "\x6e\xd0\xdd\x02"
  3842. "\x80\x6f\xa8\x9e" "\x25\xde\x06\x0c"
  3843. "\x19\xd3\xac\x86" "\xca\xbb\x87\xd6"
  3844. "\xa0\xdd\xd0\x5c" "\x33\x3b\x84\xf4";
  3845. a.inLen = XSTRLEN(a.input);
  3846. a.outLen = WC_SHA512_224_DIGEST_SIZE;
  3847. /*
  3848. ** See page 1 in above document for the SHA512/224 "abc" test:
  3849. */
  3850. b.input = "abc";
  3851. /*
  3852. ** See page 1 in above document for the SHA512/224 "abc" test digest:
  3853. */
  3854. b.output = "\x46\x34\x27\x0f"
  3855. "\x70\x7b\x6a\x54" "\xda\xae\x75\x30"
  3856. "\x46\x08\x42\xe2" "\x0e\x37\xed\x26"
  3857. "\x5c\xee\xe9\xa4" "\x3e\x89\x24\xaa";
  3858. b.inLen = XSTRLEN(b.input);
  3859. b.outLen = WC_SHA512_224_DIGEST_SIZE;
  3860. /*
  3861. ** See page 4 in above for the 2-block test:
  3862. */
  3863. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3864. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  3865. /*
  3866. ** see page 9 in above document for the 2-block test message digest:
  3867. */
  3868. c.output = "\x23\xfe\xc5\xbb"
  3869. "\x94\xd6\x0b\x23" "\x30\x81\x92\x64"
  3870. "\x0b\x0c\x45\x33" "\x35\xd6\x64\x73"
  3871. "\x4f\xe4\x0e\x72" "\x68\x67\x4a\xf9";
  3872. c.inLen = XSTRLEN(c.input);
  3873. c.outLen = WC_SHA512_224_DIGEST_SIZE;
  3874. test_sha[0] = a;
  3875. test_sha[1] = b;
  3876. test_sha[2] = c;
  3877. ret = wc_InitSha512_224_ex(&sha, HEAP_HINT, devId);
  3878. if (ret != 0)
  3879. return WC_TEST_RET_ENC_EC(ret);
  3880. ret = wc_InitSha512_224_ex(&shaCopy, HEAP_HINT, devId);
  3881. if (ret != 0) {
  3882. wc_Sha512_224Free(&sha);
  3883. return WC_TEST_RET_ENC_EC(ret);
  3884. }
  3885. for (i = 0; i < times; ++i) {
  3886. ret = wc_Sha512_224Update(&sha, (byte*)test_sha[i].input,
  3887. (word32)test_sha[i].inLen);
  3888. if (ret != 0)
  3889. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3890. ret = wc_Sha512_224GetHash(&sha, hashcopy);
  3891. if (ret != 0)
  3892. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3893. ret = wc_Sha512_224Copy(&sha, &shaCopy);
  3894. if (ret != 0)
  3895. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3896. ret = wc_Sha512_224Final(&sha, hash);
  3897. if (ret != 0)
  3898. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3899. wc_Sha512_224Free(&shaCopy);
  3900. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_224_DIGEST_SIZE) != 0)
  3901. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3902. if (XMEMCMP(hash, hashcopy, WC_SHA512_224_DIGEST_SIZE) != 0)
  3903. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  3904. }
  3905. #ifndef NO_LARGE_HASH_TEST
  3906. /* BEGIN LARGE HASH TEST */ {
  3907. byte large_input[1024];
  3908. #ifdef HASH_SIZE_LIMIT
  3909. const char* large_digest =
  3910. "\x98\x68\xc3\xd9\xb9\xef\x17\x53"
  3911. "\x43\x66\x0e\x60\xdf\x29\xf8\xef"
  3912. "\x96\xe3\x93\x34\x8c\x6f\xc0\xeb"
  3913. "\x14\x6c\xcf\x6a";
  3914. #else
  3915. const char* large_digest =
  3916. "\x26\x5f\x98\xd1\x76\x49\x71\x4e"
  3917. "\x82\xb7\x9d\x52\x32\x67\x9d\x56"
  3918. "\x91\xf5\x88\xc3\x05\xbb\x3f\x90"
  3919. "\xe2\x4e\x85\x05";
  3920. #endif
  3921. for (i = 0; i < (int)sizeof(large_input); i++) {
  3922. large_input[i] = (byte)(i & 0xFF);
  3923. }
  3924. #ifdef HASH_SIZE_LIMIT
  3925. times = 20;
  3926. #else
  3927. times = 100;
  3928. #endif
  3929. for (i = 0; i < times; ++i) {
  3930. ret = wc_Sha512_224Update(&sha, (byte*)large_input,
  3931. (word32)sizeof(large_input));
  3932. if (ret != 0)
  3933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3934. }
  3935. ret = wc_Sha512_224Final(&sha, hash);
  3936. if (ret != 0)
  3937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3938. if (XMEMCMP(hash, large_digest, WC_SHA512_224_DIGEST_SIZE) != 0)
  3939. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  3940. #ifndef NO_UNALIGNED_MEMORY_TEST
  3941. /* Unaligned memory access test */
  3942. for (i = 1; i < 16; i++) {
  3943. ret = wc_Sha512_224Update(&sha, (byte*)large_input + i,
  3944. (word32)sizeof(large_input) - (word32)i);
  3945. if (ret != 0)
  3946. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  3947. ret = wc_Sha512_224Final(&sha, hash);
  3948. }
  3949. #endif
  3950. } /* END LARGE HASH TEST */
  3951. #endif /* NO_LARGE_HASH_TEST */
  3952. exit:
  3953. wc_Sha512_224Free(&sha);
  3954. wc_Sha512_224Free(&shaCopy);
  3955. return ret;
  3956. } /* sha512_224_test */
  3957. #endif /* !defined(WOLFSSL_NOSHA512_224) && !FIPS ... */
  3958. #if !defined(WOLFSSL_NOSHA512_256) && \
  3959. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3960. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_256_test(void)
  3961. {
  3962. /*
  3963. ** See https://csrc.nist.gov/Projects/cryptographic-standards-and-guidelines/example-values
  3964. ** NIST SHA512/256 Document Example:
  3965. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA512_256.pdf
  3966. */
  3967. wc_Sha512 sha, shaCopy;
  3968. byte hash[WC_SHA512_256_DIGEST_SIZE];
  3969. byte hashcopy[WC_SHA512_256_DIGEST_SIZE];
  3970. wc_test_ret_t ret = 0;
  3971. testVector a, b, c;
  3972. testVector test_sha[3];
  3973. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  3974. WOLFSSL_ENTER("sha512_256_test");
  3975. a.input = "";
  3976. a.output = "\xc6\x72\xb8\xd1" "\xef\x56\xed\x28"
  3977. "\xab\x87\xc3\x62" "\x2c\x51\x14\x06"
  3978. "\x9b\xdd\x3a\xd7" "\xb8\xf9\x73\x74"
  3979. "\x98\xd0\xc0\x1e" "\xce\xf0\x96\x7a";
  3980. a.inLen = XSTRLEN(a.input);
  3981. a.outLen = WC_SHA512_256_DIGEST_SIZE;
  3982. /*
  3983. ** See page 1 of above document for "abc" example:
  3984. */
  3985. b.input = "abc";
  3986. /*
  3987. ** See page 4 of above document for "abc" example digest:
  3988. */
  3989. b.output = "\x53\x04\x8e\x26" "\x81\x94\x1e\xf9"
  3990. "\x9b\x2e\x29\xb7" "\x6b\x4c\x7d\xab"
  3991. "\xe4\xc2\xd0\xc6" "\x34\xfc\x6d\x46"
  3992. "\xe0\xe2\xf1\x31" "\x07\xe7\xaf\x23";
  3993. b.inLen = XSTRLEN(b.input);
  3994. b.outLen = WC_SHA512_256_DIGEST_SIZE;
  3995. /*
  3996. ** See page 4 of above document for Two Block Message Sample:
  3997. */
  3998. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  3999. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  4000. /*
  4001. ** See page 10 of above document for Two Block Message Sample digest:
  4002. */
  4003. c.output = "\x39\x28\xe1\x84" "\xfb\x86\x90\xf8"
  4004. "\x40\xda\x39\x88" "\x12\x1d\x31\xbe"
  4005. "\x65\xcb\x9d\x3e" "\xf8\x3e\xe6\x14"
  4006. "\x6f\xea\xc8\x61" "\xe1\x9b\x56\x3a";
  4007. c.inLen = XSTRLEN(c.input);
  4008. c.outLen = WC_SHA512_256_DIGEST_SIZE;
  4009. test_sha[0] = a;
  4010. test_sha[1] = b;
  4011. test_sha[2] = c;
  4012. ret = wc_InitSha512_256_ex(&sha, HEAP_HINT, devId);
  4013. if (ret != 0)
  4014. return WC_TEST_RET_ENC_EC(ret);
  4015. ret = wc_InitSha512_256_ex(&shaCopy, HEAP_HINT, devId);
  4016. if (ret != 0) {
  4017. wc_Sha512_256Free(&sha);
  4018. return WC_TEST_RET_ENC_EC(ret);
  4019. }
  4020. for (i = 0; i < times; ++i) {
  4021. ret = wc_Sha512_256Update(&sha, (byte*)test_sha[i].input,
  4022. (word32)test_sha[i].inLen);
  4023. if (ret != 0)
  4024. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4025. ret = wc_Sha512_256GetHash(&sha, hashcopy);
  4026. if (ret != 0)
  4027. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4028. ret = wc_Sha512_256Copy(&sha, &shaCopy);
  4029. if (ret != 0)
  4030. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4031. ret = wc_Sha512_256Final(&sha, hash);
  4032. if (ret != 0)
  4033. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4034. wc_Sha512_256Free(&shaCopy);
  4035. if (XMEMCMP(hash, test_sha[i].output, WC_SHA512_256_DIGEST_SIZE) != 0)
  4036. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4037. if (XMEMCMP(hash, hashcopy, WC_SHA512_256_DIGEST_SIZE) != 0)
  4038. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4039. }
  4040. #ifndef NO_LARGE_HASH_TEST
  4041. /* BEGIN LARGE HASH TEST */ {
  4042. byte large_input[1024];
  4043. #ifdef HASH_SIZE_LIMIT
  4044. const char* large_digest =
  4045. "\x49\xcc\xbc\x7a\x93\x0b\x02\xb8"
  4046. "\xad\x9a\x46\x51\x00\x1f\x13\x80"
  4047. "\x35\x84\x36\xf1\xf2\x3c\xeb\xd8"
  4048. "\x41\xd4\x06\x8b\x1d\x19\xad\x72";
  4049. #else
  4050. const char* large_digest =
  4051. "\x7a\xe3\x84\x05\xcb\x06\x22\x08"
  4052. "\x7e\x2c\x65\x89\x1f\x26\x45\xfd"
  4053. "\xad\xbc\x2e\x29\x83\x12\x84\x4b"
  4054. "\xf2\xa0\xde\xbe\x06\x11\xd7\x44";
  4055. #endif
  4056. for (i = 0; i < (int)sizeof(large_input); i++) {
  4057. large_input[i] = (byte)(i & 0xFF);
  4058. }
  4059. #ifdef HASH_SIZE_LIMIT
  4060. times = 20;
  4061. #else
  4062. times = 100;
  4063. #endif
  4064. for (i = 0; i < times; ++i) {
  4065. ret = wc_Sha512_256Update(&sha, (byte*)large_input,
  4066. (word32)sizeof(large_input));
  4067. if (ret != 0)
  4068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4069. }
  4070. ret = wc_Sha512_256Final(&sha, hash);
  4071. if (ret != 0)
  4072. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4073. if (XMEMCMP(hash, large_digest, WC_SHA512_256_DIGEST_SIZE) != 0)
  4074. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4075. #ifndef NO_UNALIGNED_MEMORY_TEST
  4076. /* Unaligned memory access test */
  4077. for (i = 1; i < 16; i++) {
  4078. ret = wc_Sha512_256Update(&sha, (byte*)large_input + i,
  4079. (word32)sizeof(large_input) - (word32)i);
  4080. if (ret != 0)
  4081. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4082. ret = wc_Sha512_256Final(&sha, hash);
  4083. }
  4084. #endif
  4085. } /* END LARGE HASH TEST */
  4086. #endif /* NO_LARGE_HASH_TEST */
  4087. exit:
  4088. wc_Sha512_256Free(&sha);
  4089. wc_Sha512_256Free(&shaCopy);
  4090. return ret;
  4091. } /* sha512_256_test */
  4092. #endif /* !defined(WOLFSSL_NOSHA512_256) && !FIPS ... */
  4093. #endif /* WOLFSSL_SHA512 */
  4094. #ifdef WOLFSSL_SHA384
  4095. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha384_test(void)
  4096. {
  4097. wc_Sha384 sha, shaCopy;
  4098. byte hash[WC_SHA384_DIGEST_SIZE];
  4099. byte hashcopy[WC_SHA384_DIGEST_SIZE];
  4100. wc_test_ret_t ret = 0;
  4101. testVector a, b, c;
  4102. testVector test_sha[3];
  4103. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4104. WOLFSSL_ENTER("sha384_test");
  4105. a.input = "";
  4106. a.output = "\x38\xb0\x60\xa7\x51\xac\x96\x38\x4c\xd9\x32\x7e\xb1\xb1\xe3"
  4107. "\x6a\x21\xfd\xb7\x11\x14\xbe\x07\x43\x4c\x0c\xc7\xbf\x63\xf6"
  4108. "\xe1\xda\x27\x4e\xde\xbf\xe7\x6f\x65\xfb\xd5\x1a\xd2\xf1\x48"
  4109. "\x98\xb9\x5b";
  4110. a.inLen = XSTRLEN(a.input);
  4111. a.outLen = WC_SHA384_DIGEST_SIZE;
  4112. b.input = "abc";
  4113. b.output = "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50"
  4114. "\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff"
  4115. "\x5b\xed\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34"
  4116. "\xc8\x25\xa7";
  4117. b.inLen = XSTRLEN(b.input);
  4118. b.outLen = WC_SHA384_DIGEST_SIZE;
  4119. c.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  4120. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  4121. c.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  4122. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  4123. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  4124. "\x74\x60\x39";
  4125. c.inLen = XSTRLEN(c.input);
  4126. c.outLen = WC_SHA384_DIGEST_SIZE;
  4127. test_sha[0] = a;
  4128. test_sha[1] = b;
  4129. test_sha[2] = c;
  4130. ret = wc_InitSha384_ex(&sha, HEAP_HINT, devId);
  4131. if (ret != 0)
  4132. return WC_TEST_RET_ENC_EC(ret);
  4133. ret = wc_InitSha384_ex(&shaCopy, HEAP_HINT, devId);
  4134. if (ret != 0) {
  4135. wc_Sha384Free(&sha);
  4136. return WC_TEST_RET_ENC_EC(ret);
  4137. }
  4138. for (i = 0; i < times; ++i) {
  4139. ret = wc_Sha384Update(&sha, (byte*)test_sha[i].input,
  4140. (word32)test_sha[i].inLen);
  4141. if (ret != 0)
  4142. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4143. ret = wc_Sha384GetHash(&sha, hashcopy);
  4144. if (ret != 0)
  4145. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4146. ret = wc_Sha384Copy(&sha, &shaCopy);
  4147. if (ret != 0)
  4148. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4149. ret = wc_Sha384Final(&sha, hash);
  4150. if (ret != 0)
  4151. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4152. wc_Sha384Free(&shaCopy);
  4153. if (XMEMCMP(hash, test_sha[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  4154. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4155. if (XMEMCMP(hash, hashcopy, WC_SHA384_DIGEST_SIZE) != 0)
  4156. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4157. }
  4158. #ifndef NO_LARGE_HASH_TEST
  4159. /* BEGIN LARGE HASH TEST */ {
  4160. byte large_input[1024];
  4161. #ifdef HASH_SIZE_LIMIT
  4162. const char* large_digest =
  4163. "\xB5\xAD\x66\x6F\xD9\x58\x5E\x68\xDD\x5E\x30\xD3\x95\x72\x33\xA4"
  4164. "\xE9\x4B\x99\x3A\xEF\xF8\xE1\xBF\x1F\x05\x32\xAA\x16\x00\x82\xEC"
  4165. "\x15\xDA\xF2\x75\xEE\xE9\x06\xAF\x52\x8A\x5C\xEF\x72\x81\x80\xD6";
  4166. #else
  4167. const char* large_digest =
  4168. "\x37\x01\xdb\xff\x1e\x40\x4f\xe1\xe2\xea\x0b\x40\xbb\x3b\x39\x9a"
  4169. "\xcc\xe8\x44\x8e\x7e\xe5\x64\xb5\x6b\x7f\x56\x64\xa7\x2b\x84\xe3"
  4170. "\xc5\xd7\x79\x03\x25\x90\xf7\xa4\x58\xcb\x97\xa8\x8b\xb1\xa4\x81";
  4171. #endif
  4172. for (i = 0; i < (int)sizeof(large_input); i++) {
  4173. large_input[i] = (byte)(i & 0xFF);
  4174. }
  4175. #ifdef HASH_SIZE_LIMIT
  4176. times = 20;
  4177. #else
  4178. times = 100;
  4179. #endif
  4180. for (i = 0; i < times; ++i) {
  4181. ret = wc_Sha384Update(&sha, (byte*)large_input,
  4182. (word32)sizeof(large_input));
  4183. if (ret != 0)
  4184. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4185. }
  4186. ret = wc_Sha384Final(&sha, hash);
  4187. if (ret != 0)
  4188. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4189. if (XMEMCMP(hash, large_digest, WC_SHA384_DIGEST_SIZE) != 0)
  4190. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4191. } /* END LARGE HASH TEST */
  4192. #endif /* NO_LARGE_HASH_TEST */
  4193. exit:
  4194. wc_Sha384Free(&sha);
  4195. wc_Sha384Free(&shaCopy);
  4196. return ret;
  4197. }
  4198. #endif /* WOLFSSL_SHA384 */
  4199. #ifdef WOLFSSL_SHA3
  4200. #ifndef WOLFSSL_NOSHA3_224
  4201. static wc_test_ret_t sha3_224_test(void)
  4202. {
  4203. wc_Sha3 sha;
  4204. byte hash[WC_SHA3_224_DIGEST_SIZE];
  4205. byte hashcopy[WC_SHA3_224_DIGEST_SIZE];
  4206. testVector a, b, c;
  4207. testVector test_sha[3];
  4208. wc_test_ret_t ret = 0;
  4209. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4210. a.input = "";
  4211. a.output = "\x6b\x4e\x03\x42\x36\x67\xdb\xb7\x3b\x6e\x15\x45\x4f\x0e\xb1"
  4212. "\xab\xd4\x59\x7f\x9a\x1b\x07\x8e\x3f\x5b\x5a\x6b\xc7";
  4213. a.inLen = XSTRLEN(a.input);
  4214. a.outLen = WC_SHA3_224_DIGEST_SIZE;
  4215. b.input = "abc";
  4216. b.output = "\xe6\x42\x82\x4c\x3f\x8c\xf2\x4a\xd0\x92\x34\xee\x7d\x3c\x76"
  4217. "\x6f\xc9\xa3\xa5\x16\x8d\x0c\x94\xad\x73\xb4\x6f\xdf";
  4218. b.inLen = XSTRLEN(b.input);
  4219. b.outLen = WC_SHA3_224_DIGEST_SIZE;
  4220. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4221. c.output = "\x8a\x24\x10\x8b\x15\x4a\xda\x21\xc9\xfd\x55\x74\x49\x44\x79"
  4222. "\xba\x5c\x7e\x7a\xb7\x6e\xf2\x64\xea\xd0\xfc\xce\x33";
  4223. c.inLen = XSTRLEN(c.input);
  4224. c.outLen = WC_SHA3_224_DIGEST_SIZE;
  4225. test_sha[0] = a;
  4226. test_sha[1] = b;
  4227. test_sha[2] = c;
  4228. ret = wc_InitSha3_224(&sha, HEAP_HINT, devId);
  4229. if (ret != 0)
  4230. return WC_TEST_RET_ENC_EC(ret);
  4231. for (i = 0; i < times; ++i) {
  4232. ret = wc_Sha3_224_Update(&sha, (byte*)test_sha[i].input,
  4233. (word32)test_sha[i].inLen);
  4234. if (ret != 0)
  4235. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4236. ret = wc_Sha3_224_GetHash(&sha, hashcopy);
  4237. if (ret != 0)
  4238. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4239. ret = wc_Sha3_224_Final(&sha, hash);
  4240. if (ret != 0)
  4241. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4242. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_224_DIGEST_SIZE) != 0)
  4243. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4244. if (XMEMCMP(hash, hashcopy, WC_SHA3_224_DIGEST_SIZE) != 0)
  4245. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4246. }
  4247. #ifndef NO_LARGE_HASH_TEST
  4248. /* BEGIN LARGE HASH TEST */ {
  4249. byte large_input[1024];
  4250. const char* large_digest =
  4251. "\x13\xe5\xd3\x98\x7b\x94\xda\x41\x12\xc7\x1e\x92\x3a\x19"
  4252. "\x21\x20\x86\x6f\x24\xbf\x0a\x31\xbc\xfd\xd6\x70\x36\xf3";
  4253. for (i = 0; i < (int)sizeof(large_input); i++) {
  4254. large_input[i] = (byte)(i & 0xFF);
  4255. }
  4256. times = 100;
  4257. for (i = 0; i < times; ++i) {
  4258. ret = wc_Sha3_224_Update(&sha, (byte*)large_input,
  4259. (word32)sizeof(large_input));
  4260. if (ret != 0)
  4261. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4262. }
  4263. ret = wc_Sha3_224_Final(&sha, hash);
  4264. if (ret != 0)
  4265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4266. if (XMEMCMP(hash, large_digest, WC_SHA3_224_DIGEST_SIZE) != 0)
  4267. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4268. } /* END LARGE HASH TEST */
  4269. #endif /* NO_LARGE_HASH_TEST */
  4270. exit:
  4271. wc_Sha3_224_Free(&sha);
  4272. return ret;
  4273. }
  4274. #endif /* WOLFSSL_NOSHA3_224 */
  4275. #ifndef WOLFSSL_NOSHA3_256
  4276. static wc_test_ret_t sha3_256_test(void)
  4277. {
  4278. wc_Sha3 sha;
  4279. byte hash[WC_SHA3_256_DIGEST_SIZE];
  4280. byte hashcopy[WC_SHA3_256_DIGEST_SIZE];
  4281. testVector a, b, c;
  4282. testVector test_sha[3];
  4283. wc_test_ret_t ret = 0;
  4284. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4285. byte large_input[1024];
  4286. const char* large_digest =
  4287. "\xdc\x90\xc0\xb1\x25\xdb\x2c\x34\x81\xa3\xff\xbc\x1e\x2e\x87\xeb"
  4288. "\x6d\x70\x85\x61\xe0\xe9\x63\x61\xff\xe5\x84\x4b\x1f\x68\x05\x15";
  4289. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4290. /* test vector with hash of empty string */
  4291. const char* Keccak256EmptyOut =
  4292. "\xc5\xd2\x46\x01\x86\xf7\x23\x3c\x92\x7e\x7d\xb2\xdc\xc7\x03\xc0"
  4293. "\xe5\x00\xb6\x53\xca\x82\x27\x3b\x7b\xfa\xd8\x04\x5d\x85\xa4\x70";
  4294. #endif
  4295. /*
  4296. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-256_Msg0.pdf
  4297. */
  4298. a.input = "";
  4299. a.output = "\xa7\xff\xc6\xf8\xbf\x1e\xd7\x66\x51\xc1\x47\x56\xa0\x61\xd6"
  4300. "\x62\xf5\x80\xff\x4d\xe4\x3b\x49\xfa\x82\xd8\x0a\x4b\x80\xf8"
  4301. "\x43\x4a";
  4302. a.inLen = XSTRLEN(a.input);
  4303. a.outLen = WC_SHA3_256_DIGEST_SIZE;
  4304. b.input = "abc";
  4305. b.output = "\x3a\x98\x5d\xa7\x4f\xe2\x25\xb2\x04\x5c\x17\x2d\x6b\xd3\x90"
  4306. "\xbd\x85\x5f\x08\x6e\x3e\x9d\x52\x5b\x46\xbf\xe2\x45\x11\x43"
  4307. "\x15\x32";
  4308. b.inLen = XSTRLEN(b.input);
  4309. b.outLen = WC_SHA3_256_DIGEST_SIZE;
  4310. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4311. c.output = "\x41\xc0\xdb\xa2\xa9\xd6\x24\x08\x49\x10\x03\x76\xa8\x23\x5e"
  4312. "\x2c\x82\xe1\xb9\x99\x8a\x99\x9e\x21\xdb\x32\xdd\x97\x49\x6d"
  4313. "\x33\x76";
  4314. c.inLen = XSTRLEN(c.input);
  4315. c.outLen = WC_SHA3_256_DIGEST_SIZE;
  4316. test_sha[0] = a;
  4317. test_sha[1] = b;
  4318. test_sha[2] = c;
  4319. ret = wc_InitSha3_256(&sha, HEAP_HINT, devId);
  4320. if (ret != 0)
  4321. return WC_TEST_RET_ENC_EC(ret);
  4322. for (i = 0; i < times; ++i) {
  4323. ret = wc_Sha3_256_Update(&sha, (byte*)test_sha[i].input,
  4324. (word32)test_sha[i].inLen);
  4325. if (ret != 0)
  4326. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4327. ret = wc_Sha3_256_GetHash(&sha, hashcopy);
  4328. if (ret != 0)
  4329. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4330. ret = wc_Sha3_256_Final(&sha, hash);
  4331. if (ret != 0)
  4332. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4333. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_256_DIGEST_SIZE) != 0)
  4334. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4335. if (XMEMCMP(hash, hashcopy, WC_SHA3_256_DIGEST_SIZE) != 0)
  4336. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4337. }
  4338. #ifndef NO_LARGE_HASH_TEST
  4339. /* BEGIN LARGE HASH TEST */ {
  4340. for (i = 0; i < (int)sizeof(large_input); i++) {
  4341. large_input[i] = (byte)(i & 0xFF);
  4342. }
  4343. times = 100;
  4344. for (i = 0; i < times; ++i) {
  4345. ret = wc_Sha3_256_Update(&sha, (byte*)large_input,
  4346. (word32)sizeof(large_input));
  4347. if (ret != 0)
  4348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4349. }
  4350. ret = wc_Sha3_256_Final(&sha, hash);
  4351. if (ret != 0)
  4352. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4353. if (XMEMCMP(hash, large_digest, WC_SHA3_256_DIGEST_SIZE) != 0)
  4354. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4355. } /* END LARGE HASH TEST */
  4356. #endif /* NO_LARGE_HASH_TEST */
  4357. /* this is a software only variant of SHA3 not supported by external hardware devices */
  4358. #if defined(WOLFSSL_HASH_FLAGS) && !defined(WOLFSSL_ASYNC_CRYPT)
  4359. /* Test for Keccak256 */
  4360. ret = wc_Sha3_SetFlags(&sha, WC_HASH_SHA3_KECCAK256);
  4361. if (ret != 0) {
  4362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4363. }
  4364. ret = wc_Sha3_256_Update(&sha, (byte*)"", 0);
  4365. if (ret != 0) {
  4366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4367. }
  4368. ret = wc_Sha3_256_Final(&sha, hash);
  4369. if (ret != 0) {
  4370. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4371. }
  4372. if (XMEMCMP(hash, Keccak256EmptyOut, WC_SHA3_256_DIGEST_SIZE) != 0) {
  4373. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4374. }
  4375. #endif /* WOLFSSL_HASH_FLAGS && !WOLFSSL_ASYNC_CRYPT */
  4376. exit:
  4377. wc_Sha3_256_Free(&sha);
  4378. return ret;
  4379. }
  4380. #endif /* WOLFSSL_NOSHA3_256 */
  4381. #ifndef WOLFSSL_NOSHA3_384
  4382. static wc_test_ret_t sha3_384_test(void)
  4383. {
  4384. wc_Sha3 sha;
  4385. byte hash[WC_SHA3_384_DIGEST_SIZE];
  4386. byte buf[64];
  4387. #ifndef NO_INTM_HASH_TEST
  4388. byte hashcopy[WC_SHA3_384_DIGEST_SIZE];
  4389. #endif
  4390. testVector a, b, c;
  4391. testVector test_sha[3];
  4392. wc_test_ret_t ret;
  4393. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4394. /*
  4395. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-384_Msg0.pdf
  4396. */
  4397. a.input = "";
  4398. a.output = "\x0c\x63\xa7\x5b\x84\x5e\x4f\x7d\x01\x10\x7d\x85\x2e\x4c\x24"
  4399. "\x85\xc5\x1a\x50\xaa\xaa\x94\xfc\x61\x99\x5e\x71\xbb\xee\x98"
  4400. "\x3a\x2a\xc3\x71\x38\x31\x26\x4a\xdb\x47\xfb\x6b\xd1\xe0\x58"
  4401. "\xd5\xf0\x04";
  4402. a.inLen = XSTRLEN(a.input);
  4403. a.outLen = WC_SHA3_384_DIGEST_SIZE;
  4404. #if defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4405. /* NIST test vector with a length that is a multiple of 4 */
  4406. b.input = "\x7d\x80\xb1\x60\xc4\xb5\x36\xa3\xbe\xb7\x99\x80\x59\x93\x44"
  4407. "\x04\x7c\x5f\x82\xa1\xdf\xc3\xee\xd4";
  4408. b.output = "\x04\x1c\xc5\x86\x1b\xa3\x34\x56\x3c\x61\xd4\xef\x97\x10\xd4"
  4409. "\x89\x6c\x31\x1c\x92\xed\xbe\x0d\x7c\xd5\x3e\x80\x3b\xf2\xf4"
  4410. "\xeb\x60\x57\x23\x55\x70\x77\x0c\xe8\x7c\x55\x20\xd7\xec\x14"
  4411. "\x19\x87\x22";
  4412. b.inLen = XSTRLEN(b.input);
  4413. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4414. #else
  4415. b.input = "abc";
  4416. b.output = "\xec\x01\x49\x82\x88\x51\x6f\xc9\x26\x45\x9f\x58\xe2\xc6\xad"
  4417. "\x8d\xf9\xb4\x73\xcb\x0f\xc0\x8c\x25\x96\xda\x7c\xf0\xe4\x9b"
  4418. "\xe4\xb2\x98\xd8\x8c\xea\x92\x7a\xc7\xf5\x39\xf1\xed\xf2\x28"
  4419. "\x37\x6d\x25";
  4420. b.inLen = XSTRLEN(b.input);
  4421. b.outLen = WC_SHA3_384_DIGEST_SIZE;
  4422. #endif
  4423. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4424. c.output = "\x99\x1c\x66\x57\x55\xeb\x3a\x4b\x6b\xbd\xfb\x75\xc7\x8a\x49"
  4425. "\x2e\x8c\x56\xa2\x2c\x5c\x4d\x7e\x42\x9b\xfd\xbc\x32\xb9\xd4"
  4426. "\xad\x5a\xa0\x4a\x1f\x07\x6e\x62\xfe\xa1\x9e\xef\x51\xac\xd0"
  4427. "\x65\x7c\x22";
  4428. c.inLen = XSTRLEN(c.input);
  4429. c.outLen = WC_SHA3_384_DIGEST_SIZE;
  4430. #if defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4431. test_sha[0] = b; /* hardware acc. pre-Versal can not handle "" string */
  4432. #else
  4433. test_sha[0] = a;
  4434. #endif
  4435. test_sha[1] = b;
  4436. test_sha[2] = c;
  4437. ret = wc_InitSha3_384(&sha, HEAP_HINT, devId);
  4438. if (ret != 0)
  4439. return WC_TEST_RET_ENC_EC(ret);
  4440. for (i = 0; i < times; ++i) {
  4441. XMEMCPY(buf, test_sha[i].input, test_sha[i].inLen);
  4442. ret = wc_Sha3_384_Update(&sha, buf,
  4443. (word32)test_sha[i].inLen);
  4444. if (ret != 0)
  4445. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4446. #ifndef NO_INTM_HASH_TEST
  4447. ret = wc_Sha3_384_GetHash(&sha, hashcopy);
  4448. if (ret != 0)
  4449. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4450. #endif
  4451. ret = wc_Sha3_384_Final(&sha, hash);
  4452. if (ret != 0)
  4453. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4454. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_384_DIGEST_SIZE) != 0)
  4455. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4456. #ifndef NO_INTM_HASH_TEST
  4457. if (XMEMCMP(hash, hashcopy, WC_SHA3_384_DIGEST_SIZE) != 0)
  4458. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4459. #endif
  4460. }
  4461. #ifndef NO_LARGE_HASH_TEST
  4462. /* BEGIN LARGE HASH TEST */ {
  4463. byte large_input[1024];
  4464. const char* large_digest =
  4465. "\x30\x44\xec\x17\xef\x47\x9f\x55\x36\x11\xd6\x3f\x8a\x31\x5a\x71"
  4466. "\x8a\x71\xa7\x1d\x8e\x84\xe8\x6c\x24\x02\x2f\x7a\x08\x4e\xea\xd7"
  4467. "\x42\x36\x5d\xa8\xc2\xb7\x42\xad\xec\x19\xfb\xca\xc6\x64\xb3\xa4";
  4468. for (i = 0; i < (int)sizeof(large_input); i++) {
  4469. large_input[i] = (byte)(i & 0xFF);
  4470. }
  4471. times = 100;
  4472. for (i = 0; i < times; ++i) {
  4473. ret = wc_Sha3_384_Update(&sha, (byte*)large_input,
  4474. (word32)sizeof(large_input));
  4475. if (ret != 0)
  4476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4477. }
  4478. ret = wc_Sha3_384_Final(&sha, hash);
  4479. if (ret != 0)
  4480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4481. if (XMEMCMP(hash, large_digest, WC_SHA3_384_DIGEST_SIZE) != 0)
  4482. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4483. } /* END LARGE HASH TEST */
  4484. #endif /* NO_LARGE_HASH_TEST */
  4485. exit:
  4486. wc_Sha3_384_Free(&sha);
  4487. return ret;
  4488. }
  4489. #endif /* WOLFSSL_NOSHA3_384 */
  4490. #ifndef WOLFSSL_NOSHA3_512
  4491. static wc_test_ret_t sha3_512_test(void)
  4492. {
  4493. wc_Sha3 sha;
  4494. byte hash[WC_SHA3_512_DIGEST_SIZE];
  4495. byte hashcopy[WC_SHA3_512_DIGEST_SIZE];
  4496. testVector a, b, c;
  4497. testVector test_sha[3];
  4498. wc_test_ret_t ret;
  4499. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4500. /*
  4501. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHA3-512_Msg0.pdf
  4502. */
  4503. a.input = "";
  4504. a.output = "\xa6\x9f\x73\xcc\xa2\x3a\x9a\xc5\xc8\xb5\x67\xdc\x18\x5a\x75"
  4505. "\x6e\x97\xc9\x82\x16\x4f\xe2\x58\x59\xe0\xd1\xdc\xc1\x47\x5c"
  4506. "\x80\xa6\x15\xb2\x12\x3a\xf1\xf5\xf9\x4c\x11\xe3\xe9\x40\x2c"
  4507. "\x3a\xc5\x58\xf5\x00\x19\x9d\x95\xb6\xd3\xe3\x01\x75\x85\x86"
  4508. "\x28\x1d\xcd\x26";
  4509. a.inLen = XSTRLEN(a.input);
  4510. a.outLen = WC_SHA3_512_DIGEST_SIZE;
  4511. b.input = "abc";
  4512. b.output = "\xb7\x51\x85\x0b\x1a\x57\x16\x8a\x56\x93\xcd\x92\x4b\x6b\x09"
  4513. "\x6e\x08\xf6\x21\x82\x74\x44\xf7\x0d\x88\x4f\x5d\x02\x40\xd2"
  4514. "\x71\x2e\x10\xe1\x16\xe9\x19\x2a\xf3\xc9\x1a\x7e\xc5\x76\x47"
  4515. "\xe3\x93\x40\x57\x34\x0b\x4c\xf4\x08\xd5\xa5\x65\x92\xf8\x27"
  4516. "\x4e\xec\x53\xf0";
  4517. b.inLen = XSTRLEN(b.input);
  4518. b.outLen = WC_SHA3_512_DIGEST_SIZE;
  4519. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4520. c.output = "\x04\xa3\x71\xe8\x4e\xcf\xb5\xb8\xb7\x7c\xb4\x86\x10\xfc\xa8"
  4521. "\x18\x2d\xd4\x57\xce\x6f\x32\x6a\x0f\xd3\xd7\xec\x2f\x1e\x91"
  4522. "\x63\x6d\xee\x69\x1f\xbe\x0c\x98\x53\x02\xba\x1b\x0d\x8d\xc7"
  4523. "\x8c\x08\x63\x46\xb5\x33\xb4\x9c\x03\x0d\x99\xa2\x7d\xaf\x11"
  4524. "\x39\xd6\xe7\x5e";
  4525. c.inLen = XSTRLEN(c.input);
  4526. c.outLen = WC_SHA3_512_DIGEST_SIZE;
  4527. test_sha[0] = a;
  4528. test_sha[1] = b;
  4529. test_sha[2] = c;
  4530. ret = wc_InitSha3_512(&sha, HEAP_HINT, devId);
  4531. if (ret != 0)
  4532. return WC_TEST_RET_ENC_EC(ret);
  4533. for (i = 0; i < times; ++i) {
  4534. ret = wc_Sha3_512_Update(&sha, (byte*)test_sha[i].input,
  4535. (word32)test_sha[i].inLen);
  4536. if (ret != 0)
  4537. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4538. ret = wc_Sha3_512_GetHash(&sha, hashcopy);
  4539. if (ret != 0)
  4540. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4541. ret = wc_Sha3_512_Final(&sha, hash);
  4542. if (ret != 0)
  4543. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4544. if (XMEMCMP(hash, test_sha[i].output, WC_SHA3_512_DIGEST_SIZE) != 0)
  4545. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4546. if (XMEMCMP(hash, hashcopy, WC_SHA3_512_DIGEST_SIZE) != 0)
  4547. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4548. }
  4549. #ifndef NO_LARGE_HASH_TEST
  4550. /* BEGIN LARGE HASH TEST */ {
  4551. byte large_input[1024];
  4552. const char* large_digest =
  4553. "\x9c\x13\x26\xb6\x26\xb2\x94\x31\xbc\xf4\x34\xe9\x6f\xf2\xd6\x29"
  4554. "\x9a\xd0\x9b\x32\x63\x2f\x18\xa7\x5f\x23\xc9\x60\xc2\x32\x0c\xbc"
  4555. "\x57\x77\x33\xf1\x83\x81\x8a\xd3\x15\x7c\x93\xdc\x80\x9f\xed\x61"
  4556. "\x41\xa7\x5b\xfd\x32\x0e\x38\x15\xb0\x46\x3b\x7a\x4f\xfd\x44\x88";
  4557. for (i = 0; i < (int)sizeof(large_input); i++) {
  4558. large_input[i] = (byte)(i & 0xFF);
  4559. }
  4560. times = 100;
  4561. for (i = 0; i < times; ++i) {
  4562. ret = wc_Sha3_512_Update(&sha, (byte*)large_input,
  4563. (word32)sizeof(large_input));
  4564. if (ret != 0)
  4565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4566. }
  4567. ret = wc_Sha3_512_Final(&sha, hash);
  4568. if (ret != 0)
  4569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4570. if (XMEMCMP(hash, large_digest, WC_SHA3_512_DIGEST_SIZE) != 0)
  4571. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4572. } /* END LARGE HASH TEST */
  4573. #endif /* NO_LARGE_HASH_TEST */
  4574. exit:
  4575. wc_Sha3_512_Free(&sha);
  4576. return ret;
  4577. }
  4578. #endif /* WOLFSSL_NOSHA3_512 */
  4579. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha3_test(void)
  4580. {
  4581. wc_test_ret_t ret;
  4582. (void)ret;
  4583. WOLFSSL_ENTER("sha3_test");
  4584. #ifndef WOLFSSL_NOSHA3_224
  4585. if ((ret = sha3_224_test()) != 0)
  4586. return ret;
  4587. #endif
  4588. #ifndef WOLFSSL_NOSHA3_256
  4589. if ((ret = sha3_256_test()) != 0)
  4590. return ret;
  4591. #endif
  4592. #ifndef WOLFSSL_NOSHA3_384
  4593. if ((ret = sha3_384_test()) != 0)
  4594. return ret;
  4595. #endif
  4596. #ifndef WOLFSSL_NOSHA3_512
  4597. if ((ret = sha3_512_test()) != 0)
  4598. return ret;
  4599. #endif
  4600. return 0;
  4601. }
  4602. #endif /* WOLFSSL_SHA3 */
  4603. #ifdef WOLFSSL_SHAKE128
  4604. static wc_test_ret_t shake128_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4605. size_t large_input_buf_size)
  4606. {
  4607. testVector a, b, c, d, e;
  4608. testVector test_sha[5];
  4609. wc_test_ret_t ret = 0;
  4610. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4611. static const char large_digest[] =
  4612. "\x2b\xd1\x69\x9f\xb3\x75\x40\x74\xb8\xb2\xd2\x0b\x92\x47\x9b\xfe"
  4613. "\xc9\x91\x48\xbe\xda\xa4\x09\xd7\x61\x35\x18\x05\x07\x71\xa5\x61"
  4614. "\x4d\xc4\x94\xad\xbe\x04\x7d\xad\x95\x2f\xeb\x2c\xc0\x10\x67\x43"
  4615. "\x40\xf1\x4a\x58\x1c\x54\xfa\x24\x1c\x1a\x4e\x8d\x9b\xbc\xea\xa7"
  4616. "\x32\xf2\x4c\xc7\x86\x05\x36\xdc\xb4\x42\xd8\x35\xd1\xb4\xa2\x79"
  4617. "\xa2\xe6\xee\x67\x4f\xbf\x2a\x93\x41\x88\x25\x56\x29\x90\x1a\x06"
  4618. "\xba\xfe\x9f\xa6\x1a\x74\xe8\x7e\x85\x4a\xc8\x58\x60\xb1\x7b\x18"
  4619. "\xdf\x77\x59\x46\x04\xc1\xff\x4b\x9b\xcb\xad\xfe\x91\x28\xf0\x01"
  4620. "\xc1\x33\xd0\x99\x99\x2e\x0c\x86\x84\x67\x4d\x37\xa4\x42\x45\x10"
  4621. "\xdc\x8f\xdb\x6f\xa6\x9b\xee\x8a\x60\xa5\x1f\x95\x3f\x8f\xf5\x31"
  4622. "\x4b\x1d\x48\x1e\x45\xff\x79\x5c\xbe\x72\xfc\x56\xed\x6d\x1a\x99"
  4623. "\x7f\x23\x7c\xd1\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b"
  4624. "\xa3\x60\x51\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41"
  4625. "\x77\x2c\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59"
  4626. "\x0d\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4627. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d\xa8"
  4628. "\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb\x67\x86"
  4629. "\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b\x3d\xca\x95"
  4630. "\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47\xcf\x56\xba\x71"
  4631. "\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a\xff\xb4\xbe\x72\x26"
  4632. "\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e\xd9\xe9\xe6\xf9\xff\xa5";
  4633. byte hash[sizeof(large_digest) - 1];
  4634. /*
  4635. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4636. */
  4637. a.input = "";
  4638. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4639. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4640. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4641. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4642. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4643. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4644. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4645. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a\x04\x30\x2e\x10\xc8\xbc"
  4646. "\x1c\xbf\x1a\x0b\x3a\x51\x20\xea\x17\xcd\xa7\xcf\xad\x76\x5f"
  4647. "\x56\x23\x47\x4d\x36\x8c\xcc\xa8\xaf\x00\x07\xcd\x9f\x5e\x4c"
  4648. "\x84\x9f\x16\x7a\x58\x0b\x14\xaa\xbd\xef\xae\xe7\xee\xf4\x7c"
  4649. "\xb0\xfc\xa9";
  4650. a.inLen = XSTRLEN(a.input);
  4651. a.outLen = WC_SHA3_128_BLOCK_SIZE;
  4652. b.input = "abc";
  4653. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4654. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4655. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4656. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4657. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4658. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4659. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4660. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3\x77\xcf\xb9\xcd\xe4\xc6"
  4661. "\x35\x99\xb2\x7f\x34\x62\xbb\xa4\xa0\xed\x29\x6c\x80\x1f\x9f"
  4662. "\xf7\xf5\x73\x02\xbb\x30\x76\xee\x14\x5f\x97\xa3\x2a\xe6\x8e"
  4663. "\x76\xab\x66\xc4\x8d\x51\x67\x5b\xd4\x9a\xcc\x29\x08\x2f\x56"
  4664. "\x47\x58\x4e";
  4665. b.inLen = XSTRLEN(b.input);
  4666. b.outLen = WC_SHA3_128_BLOCK_SIZE;
  4667. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4668. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4669. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4670. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4671. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4672. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4673. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4674. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4675. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa\x54\x56\x54\xf7\x0a\xe5"
  4676. "\x86\xff\x10\x13\x14\x20\x77\x14\x83\xec\x92\xed\xab\x40\x8c"
  4677. "\x76\x7b\xf4\xc5\xb4\xff\xfa\xa8\x0c\x8c\xa2\x14\xd8\x4c\x4d"
  4678. "\xc7\x00\xd0\xc5\x06\x30\xb2\xff\xc3\x79\x3e\xa4\xd8\x72\x58"
  4679. "\xb4\xc9\x54";
  4680. c.inLen = XSTRLEN(c.input);
  4681. c.outLen = WC_SHA3_128_BLOCK_SIZE;
  4682. /* Taken from NIST CAVP test vectors - full rate output. */
  4683. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4684. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4685. "\x85\xe0";
  4686. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4687. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4688. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4689. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4690. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4691. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4692. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4693. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4694. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4695. "\xa1\x41\x9b\xaf\x60\x52\xc0\xc1\xb4\x45\xf8\x35\x17\x57\xb0"
  4696. "\xd0\x22\x87\x21\x89\xe2\xc0\x27\x3f\x82\xd9\x69\x69\x66\x3e"
  4697. "\x55\x4d\x09";
  4698. d.inLen = 32;
  4699. d.outLen = WC_SHA3_128_BLOCK_SIZE;
  4700. /* Taken from NIST CAVP test vectors - more than one output block. */
  4701. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4702. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4703. "\x47\xe4";
  4704. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4705. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4706. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4707. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4708. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4709. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4710. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4711. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4712. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4713. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4714. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4715. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4716. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4717. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4718. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4719. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4720. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4\xcb\x87\xd8\xb7\x9d"
  4721. "\xa8\xbf\xc5\x2e\x5e\xfc\xd3\x6c\x45\xd4\x5d\x72\x0f\x66\xeb"
  4722. "\x67\x86\xfa\x6c\xd6\x80\xa4\x23\xcb\x5d\xed\x3c\xde\xdc\x5b"
  4723. "\x3d\xca\x95\x43\x4b\xdc\xe8\x49\xd3\xe1\x01\xd4\xf1\xe4\x47"
  4724. "\xcf\x56\xba\x71\xb4\x69\xed\xe7\xdb\x0f\x89\xd6\xbb\xcd\x1a"
  4725. "\xff\xb4\xbe\x72\x26\xdc\x76\x79\xb3\x1a\x4b\xe6\x8d\x9b\x8e"
  4726. "\xd9\xe9\xe6\xf9\xff\xa5";
  4727. e.inLen = 32;
  4728. e.outLen = 2 * WC_SHA3_128_BLOCK_SIZE;
  4729. test_sha[0] = a;
  4730. test_sha[1] = b;
  4731. test_sha[2] = c;
  4732. test_sha[3] = d;
  4733. test_sha[4] = e;
  4734. for (i = 0; i < times; ++i) {
  4735. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4736. if (ret != 0)
  4737. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4738. ret = wc_Shake128_Absorb(sha, (byte*)test_sha[i].input,
  4739. (word32)test_sha[i].inLen);
  4740. if (ret != 0)
  4741. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4742. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4743. (word32)test_sha[i].outLen / WC_SHA3_128_BLOCK_SIZE);
  4744. if (ret != 0)
  4745. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4746. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  4747. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4748. }
  4749. #ifndef NO_LARGE_HASH_TEST
  4750. /* BEGIN LARGE HASH TEST */ {
  4751. for (i = 0; i < (int)large_input_buf_size; i++) {
  4752. large_input_buf[i] = (byte)(i & 0xFF);
  4753. }
  4754. ret = wc_InitShake128(sha, HEAP_HINT, devId);
  4755. if (ret != 0)
  4756. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4757. /* Absorb is non-incremental. */
  4758. ret = wc_Shake128_Absorb(sha, (byte*)large_input_buf,
  4759. (word32)large_input_buf_size);
  4760. if (ret != 0)
  4761. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4762. /* Able to squeeze out blocks incrementally. */
  4763. ret = wc_Shake128_SqueezeBlocks(sha, hash, 1);
  4764. if (ret != 0)
  4765. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4766. ret = wc_Shake128_SqueezeBlocks(sha, hash,
  4767. ((word32)sizeof(hash) / WC_SHA3_128_BLOCK_SIZE) - 1);
  4768. if (ret != 0)
  4769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4770. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  4771. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4772. } /* END LARGE HASH TEST */
  4773. #endif /* NO_LARGE_HASH_TEST */
  4774. exit:
  4775. return ret;
  4776. }
  4777. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake128_test(void)
  4778. {
  4779. wc_Shake sha;
  4780. byte hash[250];
  4781. testVector a, b, c, d, e;
  4782. testVector test_sha[5];
  4783. wc_test_ret_t ret = 0;
  4784. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4785. #define SHAKE128_LARGE_INPUT_BUFSIZ 1024
  4786. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4787. byte *large_input = NULL;
  4788. #else
  4789. byte large_input[SHAKE128_LARGE_INPUT_BUFSIZ];
  4790. #endif
  4791. static const char large_digest[] =
  4792. "\x88\xd7\x0e\x86\x46\x72\x6b\x3d\x7d\x22\xe1\xa9\x2d\x02\xdb\x35"
  4793. "\x92\x4f\x1b\x03\x90\xee\xa3\xce\xd1\x3a\x08\x3a\xd7\x4e\x10\xdf"
  4794. "\x09\x67\x33\x35\x4f\xdd\x38\x50\x5b\xcb\x75\xc7\xba\x65\xe5\xe8"
  4795. "\xb8\x76\xde\xc5\xee\xd7\xf1\x65\x93\x4e\x5e\xc4\xb1\xd7\x6b\xee"
  4796. "\x4b\x57\x48\xf5\x38\x49\x9e\x45\xa0\xf7\x32\xe9\x05\x26\x6a\x10"
  4797. "\x70\xd4\x7c\x19\x01\x1f\x6d\x37\xba\x7b\x74\xc2\xbc\xb6\xbc\x74"
  4798. "\xa3\x66\x6c\x9b\x11\x84\x9d\x4a\x36\xbc\x8a\x0d\x4c\xe3\x39\xfa"
  4799. "\xfa\x1b";
  4800. WOLFSSL_ENTER("shake128_test");
  4801. /*
  4802. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE128_Msg0.pdf
  4803. */
  4804. a.input = "";
  4805. a.output = "\x7f\x9c\x2b\xa4\xe8\x8f\x82\x7d\x61\x60\x45\x50\x76\x05\x85"
  4806. "\x3e\xd7\x3b\x80\x93\xf6\xef\xbc\x88\xeb\x1a\x6e\xac\xfa\x66"
  4807. "\xef\x26\x3c\xb1\xee\xa9\x88\x00\x4b\x93\x10\x3c\xfb\x0a\xee"
  4808. "\xfd\x2a\x68\x6e\x01\xfa\x4a\x58\xe8\xa3\x63\x9c\xa8\xa1\xe3"
  4809. "\xf9\xae\x57\xe2\x35\xb8\xcc\x87\x3c\x23\xdc\x62\xb8\xd2\x60"
  4810. "\x16\x9a\xfa\x2f\x75\xab\x91\x6a\x58\xd9\x74\x91\x88\x35\xd2"
  4811. "\x5e\x6a\x43\x50\x85\xb2\xba\xdf\xd6\xdf\xaa\xc3\x59\xa5\xef"
  4812. "\xbb\x7b\xcc\x4b\x59\xd5\x38\xdf\x9a";
  4813. a.inLen = XSTRLEN(a.input);
  4814. a.outLen = 114;
  4815. b.input = "abc";
  4816. b.output = "\x58\x81\x09\x2d\xd8\x18\xbf\x5c\xf8\xa3\xdd\xb7\x93\xfb\xcb"
  4817. "\xa7\x40\x97\xd5\xc5\x26\xa6\xd3\x5f\x97\xb8\x33\x51\x94\x0f"
  4818. "\x2c\xc8\x44\xc5\x0a\xf3\x2a\xcd\x3f\x2c\xdd\x06\x65\x68\x70"
  4819. "\x6f\x50\x9b\xc1\xbd\xde\x58\x29\x5d\xae\x3f\x89\x1a\x9a\x0f"
  4820. "\xca\x57\x83\x78\x9a\x41\xf8\x61\x12\x14\xce\x61\x23\x94\xdf"
  4821. "\x28\x6a\x62\xd1\xa2\x25\x2a\xa9\x4d\xb9\xc5\x38\x95\x6c\x71"
  4822. "\x7d\xc2\xbe\xd4\xf2\x32\xa0\x29\x4c\x85\x7c\x73\x0a\xa1\x60"
  4823. "\x67\xac\x10\x62\xf1\x20\x1f\xb0\xd3";
  4824. b.inLen = XSTRLEN(b.input);
  4825. b.outLen = 114;
  4826. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4827. c.output = "\x1a\x96\x18\x2b\x50\xfb\x8c\x7e\x74\xe0\xa7\x07\x78\x8f\x55"
  4828. "\xe9\x82\x09\xb8\xd9\x1f\xad\xe8\xf3\x2f\x8d\xd5\xcf\xf7\xbf"
  4829. "\x21\xf5\x4e\xe5\xf1\x95\x50\x82\x5a\x6e\x07\x00\x30\x51\x9e"
  4830. "\x94\x42\x63\xac\x1c\x67\x65\x28\x70\x65\x62\x1f\x9f\xcb\x32"
  4831. "\x01\x72\x3e\x32\x23\xb6\x3a\x46\xc2\x93\x8a\xa9\x53\xba\x84"
  4832. "\x01\xd0\xea\x77\xb8\xd2\x64\x90\x77\x55\x66\x40\x7b\x95\x67"
  4833. "\x3c\x0f\x4c\xc1\xce\x9f\xd9\x66\x14\x8d\x7e\xfd\xff\x26\xbb"
  4834. "\xf9\xf4\x8a\x21\xc6\xda\x35\xbf\xaa";
  4835. c.inLen = XSTRLEN(c.input);
  4836. c.outLen = 114;
  4837. /* Taken from NIST CAVP test vectors - full rate output. */
  4838. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  4839. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  4840. "\x85\xe0";
  4841. d.output = "\x93\x68\xf0\x15\x10\x92\x44\xeb\x02\x47\xfa\x3a\x0e\x57\xf5"
  4842. "\x2e\xa7\xd9\xeb\xa2\x3d\xae\x7a\x19\x7f\x0a\x29\xe9\x22\x55"
  4843. "\x06\x05\x98\x16\xb7\x84\x48\xb6\x49\x7a\x76\xeb\x96\x2d\xb3"
  4844. "\xf8\x4d\x37\x60\xf1\xfe\xb4\xbd\xc1\xfd\x4a\xc9\x4e\x91\x7a"
  4845. "\xc2\xea\x5e\x4f\x38\x37\x4a\xa5\x6e\x4f\x47\x67\xb8\xd7\x83"
  4846. "\x1b\x2d\x51\x49\x5a\xb8\xea\xb7\xc9\x82\x20\xaf\x13\x41\x5a"
  4847. "\x59\xbb\x7c\x17\x7a\xcd\x62\x8e\xf0\xff\xe3\x6c\xeb\x18\x59"
  4848. "\x5d\x14\x4c\xbf\x25\xef\xc0\x6c\xd9\x56\xa5\x78\x20\x6e\xa8"
  4849. "\xf9\x14\x5e\xf9\xce\x19\x50\x6a\x9d\x04\x4e\xc7\x00\x79\x9f"
  4850. "\xa1";
  4851. d.inLen = 32;
  4852. d.outLen = 136;
  4853. /* Taken from NIST CAVP test vectors - more than one output block. */
  4854. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  4855. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  4856. "\x47\xe4";
  4857. e.output = "\xe1\x7e\xab\x0d\xa4\x04\xf9\xb6\xac\xc0\x84\x97\x2f\xc5\x79"
  4858. "\xe8\x6d\xaa\x76\x10\xa5\xe1\x7c\x23\x2f\x79\x19\x83\x96\xfd"
  4859. "\x01\xc2\x4c\x34\xbb\x54\xf4\xb0\x1e\xf7\x40\xb4\x25\x33\x4a"
  4860. "\x55\xdd\x24\x81\x3d\xc8\xea\x86\xf5\x6e\xf7\x27\x67\x26\x2b"
  4861. "\xf2\x25\x74\x8c\xcc\x3d\x9f\x48\x6f\xfb\x72\x8f\x4e\xad\x29"
  4862. "\x60\xc9\x6c\x3e\x44\x63\x86\xea\xce\x21\x9c\x84\x28\x16\x11"
  4863. "\x63\x58\xb0\xf4\x2d\x7d\xff\xf7\xdd\x24\x11\xfa\x2a\x56\x79"
  4864. "\xfd\x7a\x94\x77\x45\x75\xba\xf9\xfc\xad\x68\xa1\x9e\x30\xd1"
  4865. "\x49\xb0\x59\xb5\x9c\x44\x6c\x4e\xdc\xa5\x9b\xc5\xa4\x79\x9d"
  4866. "\xc4\x65\xaa\x9e\x78\x2c\xed\x9f\x21\xc5\x5d\xe2\x42\xdd\x25"
  4867. "\xd0\xd9\xde\x60\xd0\x9f\xf8\x6a\xba\xf3\xa0\x3a\x76\x71\xb3"
  4868. "\x05\x42\xdf\xbe\x72\xfc\x56\xed\x6d\x1a\x99\x7f\x23\x7c\xd1"
  4869. "\xa5\x50\x9e\xb0\x4d\x61\x37\xa5\xcb\x24\x71\x3b\xa3\x60\x51"
  4870. "\x2e\x80\x83\x8b\xe0\x55\x50\xa7\x1e\xcc\x9f\xac\x41\x77\x2c"
  4871. "\x79\x22\x30\x09\x1b\x1a\x83\x5b\x2c\x48\xdc\x09\x7d\x59\x0d"
  4872. "\xf0\x54\x17\xfb\x5e\x38\x68\xde\xdb\xc5\x93\xab\x17\x5f\x4b"
  4873. "\x4d\x6d\xf2\xc7\x4e\x15\x1e\x10\x76\xc4";
  4874. e.inLen = 32;
  4875. e.outLen = 250;
  4876. test_sha[0] = a;
  4877. test_sha[1] = b;
  4878. test_sha[2] = c;
  4879. test_sha[3] = d;
  4880. test_sha[4] = e;
  4881. ret = wc_InitShake128(&sha, HEAP_HINT, devId);
  4882. if (ret != 0)
  4883. return WC_TEST_RET_ENC_EC(ret);
  4884. for (i = 0; i < times; ++i) {
  4885. ret = wc_Shake128_Update(&sha, (byte*)test_sha[i].input,
  4886. (word32)test_sha[i].inLen);
  4887. if (ret != 0)
  4888. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4889. ret = wc_Shake128_Final(&sha, hash, (word32)test_sha[i].outLen);
  4890. if (ret != 0)
  4891. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4892. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  4893. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  4894. }
  4895. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4896. large_input = (byte *)XMALLOC(SHAKE128_LARGE_INPUT_BUFSIZ, NULL,
  4897. DYNAMIC_TYPE_TMP_BUFFER);
  4898. if (large_input == NULL)
  4899. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  4900. #endif
  4901. #ifndef NO_LARGE_HASH_TEST
  4902. /* BEGIN LARGE HASH TEST */ {
  4903. for (i = 0; i < SHAKE128_LARGE_INPUT_BUFSIZ; i++) {
  4904. large_input[i] = (byte)(i & 0xFF);
  4905. }
  4906. times = 100;
  4907. for (i = 0; i < times; ++i) {
  4908. ret = wc_Shake128_Update(&sha, (byte*)large_input,
  4909. SHAKE128_LARGE_INPUT_BUFSIZ);
  4910. if (ret != 0)
  4911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4912. }
  4913. ret = wc_Shake128_Final(&sha, hash, (word32)sizeof(hash));
  4914. if (ret != 0)
  4915. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  4916. if (XMEMCMP(hash, large_digest, sizeof(large_digest) - 1) != 0)
  4917. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  4918. } /* END LARGE HASH TEST */
  4919. #endif /* NO_LARGE_HASH_TEST */
  4920. ret = shake128_absorb_test(&sha, large_input, SHAKE128_LARGE_INPUT_BUFSIZ);
  4921. exit:
  4922. wc_Shake128_Free(&sha);
  4923. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  4924. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  4925. #endif
  4926. return ret;
  4927. }
  4928. #endif
  4929. #ifdef WOLFSSL_SHAKE256
  4930. static wc_test_ret_t shake256_absorb_test(wc_Shake* sha, byte *large_input_buf,
  4931. size_t large_input_buf_size)
  4932. {
  4933. testVector a, b, c, d, e;
  4934. testVector test_sha[5];
  4935. wc_test_ret_t ret = 0;
  4936. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  4937. static const char large_digest[] =
  4938. "\x21\x25\x8e\xae\x6e\x4f\xa7\xe1\xb9\x6d\xa7\xc9\x7d\x46\x03\x69"
  4939. "\x29\x0d\x81\x49\xba\x5d\xaf\x37\xfd\xeb\x25\x52\x1d\xd9\xbd\x65"
  4940. "\xfa\x99\xb9\xd1\x70\x6b\xeb\xd4\xc1\x2c\xea\x24\x20\x27\xa7\xcd"
  4941. "\xfa\xe1\x81\xd9\xd5\xc1\x1c\xc7\xe9\x70\xc3\xc7\x21\x6f\x32\x22"
  4942. "\xe3\x27\xdb\x58\x5e\xea\x18\x2d\x63\x4d\x14\x6c\x94\xcf\x2b\x7e"
  4943. "\x6e\x2a\x74\xf3\xe0\xac\xb3\xb2\xcc\xef\x38\xe9\xe7\x35\xb3\xc5"
  4944. "\x77\x9d\xff\xe3\x08\x8e\xf8\x2c\x89\xbb\x45\x22\x16\x99\x91\xc0"
  4945. "\xe7\x71\x57\x75\xc5\xb1\xc6\xaf\x27\xcb\x64\x8c\xc4\xee\x3d\x5f"
  4946. "\x4c\x35\xfb\x1c\xf3\xf8\x0e\xfd\x5e\xfc\x07\xd8\x4d\x55\x32\x49"
  4947. "\x45\x0d\xab\x4a\x49\xc4\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93"
  4948. "\x7a\xe6\x6b\xb4\x36\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43"
  4949. "\x2f\x3b\xfc\x09\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48"
  4950. "\x3d\x0e\xda\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08"
  4951. "\xd9\xdc\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a"
  4952. "\xb7\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  4953. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4\xe6"
  4954. "\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97\x68\x44";
  4955. byte hash[sizeof(large_digest) - 1];
  4956. /*
  4957. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  4958. */
  4959. a.input = "";
  4960. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  4961. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  4962. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  4963. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  4964. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  4965. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  4966. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  4967. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46\xc1\x85\xc1\x51\x11\xe5"
  4968. "\x95\x52\x2a\x6b\xcd\x16\xcf\x86\xf3\xd1\x22\x10\x9e\x3b\x1f"
  4969. "\xdd";
  4970. a.inLen = XSTRLEN(a.input);
  4971. a.outLen = WC_SHA3_256_BLOCK_SIZE;
  4972. b.input = "abc";
  4973. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  4974. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  4975. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  4976. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  4977. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  4978. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  4979. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  4980. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0\x9a\x3e\x6d\x51\xcb\xfc"
  4981. "\x62\x27\x20\xd7\xa7\x5c\x63\x34\xe8\xa2\xd7\xec\x71\xa7\xcc"
  4982. "\x29";
  4983. b.inLen = XSTRLEN(b.input);
  4984. b.outLen = WC_SHA3_256_BLOCK_SIZE;
  4985. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  4986. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  4987. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  4988. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  4989. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  4990. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  4991. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  4992. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  4993. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4\x9d\xd3\xef\x7e\x18\x2b"
  4994. "\x15\x24\xdf\x82\xea\x1c\xef\xe1\xc6\xc3\x96\x61\x75\xf0\x22"
  4995. "\x8d";
  4996. c.inLen = XSTRLEN(c.input);
  4997. c.outLen = WC_SHA3_256_BLOCK_SIZE;
  4998. /* Taken from NIST CAVP test vectors - full rate output. */
  4999. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  5000. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  5001. "\x85\xe0";
  5002. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5003. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5004. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5005. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5006. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5007. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5008. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5009. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5010. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5011. "\xc2";
  5012. d.inLen = 32;
  5013. d.outLen = WC_SHA3_256_BLOCK_SIZE;
  5014. /* Taken from NIST CAVP test vectors - more than one output block. */
  5015. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5016. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5017. "\x47\xe4";
  5018. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5019. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5020. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5021. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5022. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5023. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5024. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5025. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5026. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5027. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5028. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5029. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5030. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5031. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5032. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5033. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5034. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c\x68\x1b\x30\xdd\xc4"
  5035. "\xe6\x83\x8b\x0f\x23\x58\x7e\x06\x5f\x4a\x2b\xed\xc9\x6c\x97"
  5036. "\x68\x44";
  5037. e.inLen = 32;
  5038. e.outLen = 2 * WC_SHA3_256_BLOCK_SIZE;
  5039. test_sha[0] = a;
  5040. test_sha[1] = b;
  5041. test_sha[2] = c;
  5042. test_sha[3] = d;
  5043. test_sha[4] = e;
  5044. for (i = 0; i < times; ++i) {
  5045. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  5046. if (ret != 0)
  5047. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5048. ret = wc_Shake256_Absorb(sha, (byte*)test_sha[i].input,
  5049. (word32)test_sha[i].inLen);
  5050. if (ret != 0)
  5051. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5052. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  5053. (word32)test_sha[i].outLen / WC_SHA3_256_BLOCK_SIZE);
  5054. if (ret != 0)
  5055. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5056. if (XMEMCMP(hash, test_sha[i].output, (word32)test_sha[i].outLen) != 0)
  5057. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5058. }
  5059. #ifndef NO_LARGE_HASH_TEST
  5060. /* BEGIN LARGE HASH TEST */ {
  5061. for (i = 0; i < (int)large_input_buf_size; i++) {
  5062. large_input_buf[i] = (byte)(i & 0xFF);
  5063. }
  5064. ret = wc_InitShake256(sha, HEAP_HINT, devId);
  5065. if (ret != 0)
  5066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5067. /* Absorb is non-incremental. */
  5068. ret = wc_Shake256_Absorb(sha, large_input_buf,
  5069. (word32)large_input_buf_size);
  5070. if (ret != 0)
  5071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5072. /* Able to squeeze out blocks incrementally. */
  5073. ret = wc_Shake256_SqueezeBlocks(sha, hash, 1);
  5074. if (ret != 0)
  5075. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5076. ret = wc_Shake256_SqueezeBlocks(sha, hash,
  5077. ((word32)sizeof(hash) / WC_SHA3_256_BLOCK_SIZE) - 1);
  5078. if (ret != 0)
  5079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5080. if (XMEMCMP(hash, large_digest, sizeof(hash)) != 0)
  5081. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5082. } /* END LARGE HASH TEST */
  5083. #endif /* NO_LARGE_HASH_TEST */
  5084. exit:
  5085. return ret;
  5086. }
  5087. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t shake256_test(void)
  5088. {
  5089. wc_Shake sha;
  5090. byte hash[250];
  5091. testVector a, b, c, d, e;
  5092. testVector test_sha[5];
  5093. wc_test_ret_t ret = 0;
  5094. int times = sizeof(test_sha) / sizeof(struct testVector), i;
  5095. #define SHAKE256_LARGE_INPUT_BUFSIZ 1024
  5096. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5097. byte *large_input = NULL;
  5098. #else
  5099. byte large_input[SHAKE256_LARGE_INPUT_BUFSIZ];
  5100. #endif
  5101. const char* large_digest =
  5102. "\x90\x32\x4a\xcc\xd1\xdf\xb8\x0b\x79\x1f\xb8\xc8\x5b\x54\xc8\xe7"
  5103. "\x45\xf5\x60\x6b\x38\x26\xb2\x0a\xee\x38\x01\xf3\xd9\xfa\x96\x9f"
  5104. "\x6a\xd7\x15\xdf\xb6\xc2\xf4\x20\x33\x44\x55\xe8\x2a\x09\x2b\x68"
  5105. "\x2e\x18\x65\x5e\x65\x93\x28\xbc\xb1\x9e\xe2\xb1\x92\xea\x98\xac"
  5106. "\x21\xef\x4c\xe1\xb4\xb7\xbe\x81\x5c\x1d\xd3\xb7\x17\xe5\xbb\xc5"
  5107. "\x8c\x68\xb7\xfb\xac\x55\x8a\x9b\x4d\x91\xe4\x9f\x72\xbb\x6e\x38"
  5108. "\xaf\x21\x7d\x21\xaa\x98\x4e\x75\xc4\xb4\x1c\x7c\x50\x45\x54\xf9"
  5109. "\xea\x26";
  5110. WOLFSSL_ENTER("shake256_test");
  5111. /*
  5112. ** https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/SHAKE256_Msg0.pdf
  5113. */
  5114. a.input = "";
  5115. a.output = "\x46\xb9\xdd\x2b\x0b\xa8\x8d\x13\x23\x3b\x3f\xeb\x74\x3e\xeb"
  5116. "\x24\x3f\xcd\x52\xea\x62\xb8\x1b\x82\xb5\x0c\x27\x64\x6e\xd5"
  5117. "\x76\x2f\xd7\x5d\xc4\xdd\xd8\xc0\xf2\x00\xcb\x05\x01\x9d\x67"
  5118. "\xb5\x92\xf6\xfc\x82\x1c\x49\x47\x9a\xb4\x86\x40\x29\x2e\xac"
  5119. "\xb3\xb7\xc4\xbe\x14\x1e\x96\x61\x6f\xb1\x39\x57\x69\x2c\xc7"
  5120. "\xed\xd0\xb4\x5a\xe3\xdc\x07\x22\x3c\x8e\x92\x93\x7b\xef\x84"
  5121. "\xbc\x0e\xab\x86\x28\x53\x34\x9e\xc7\x55\x46\xf5\x8f\xb7\xc2"
  5122. "\x77\x5c\x38\x46\x2c\x50\x10\xd8\x46";
  5123. a.inLen = XSTRLEN(a.input);
  5124. a.outLen = 114;
  5125. b.input = "abc";
  5126. b.output = "\x48\x33\x66\x60\x13\x60\xa8\x77\x1c\x68\x63\x08\x0c\xc4\x11"
  5127. "\x4d\x8d\xb4\x45\x30\xf8\xf1\xe1\xee\x4f\x94\xea\x37\xe7\x8b"
  5128. "\x57\x39\xd5\xa1\x5b\xef\x18\x6a\x53\x86\xc7\x57\x44\xc0\x52"
  5129. "\x7e\x1f\xaa\x9f\x87\x26\xe4\x62\xa1\x2a\x4f\xeb\x06\xbd\x88"
  5130. "\x01\xe7\x51\xe4\x13\x85\x14\x12\x04\xf3\x29\x97\x9f\xd3\x04"
  5131. "\x7a\x13\xc5\x65\x77\x24\xad\xa6\x4d\x24\x70\x15\x7b\x3c\xdc"
  5132. "\x28\x86\x20\x94\x4d\x78\xdb\xcd\xdb\xd9\x12\x99\x3f\x09\x13"
  5133. "\xf1\x64\xfb\x2c\xe9\x51\x31\xa2\xd0";
  5134. b.inLen = XSTRLEN(b.input);
  5135. b.outLen = 114;
  5136. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5137. c.output = "\x4d\x8c\x2d\xd2\x43\x5a\x01\x28\xee\xfb\xb8\xc3\x6f\x6f\x87"
  5138. "\x13\x3a\x79\x11\xe1\x8d\x97\x9e\xe1\xae\x6b\xe5\xd4\xfd\x2e"
  5139. "\x33\x29\x40\xd8\x68\x8a\x4e\x6a\x59\xaa\x80\x60\xf1\xf9\xbc"
  5140. "\x99\x6c\x05\xac\xa3\xc6\x96\xa8\xb6\x62\x79\xdc\x67\x2c\x74"
  5141. "\x0b\xb2\x24\xec\x37\xa9\x2b\x65\xdb\x05\x39\xc0\x20\x34\x55"
  5142. "\xf5\x1d\x97\xcc\xe4\xcf\xc4\x91\x27\xd7\x26\x0a\xfc\x67\x3a"
  5143. "\xf2\x08\xba\xf1\x9b\xe2\x12\x33\xf3\xde\xbe\x78\xd0\x67\x60"
  5144. "\xcf\xa5\x51\xee\x1e\x07\x91\x41\xd4";
  5145. c.inLen = XSTRLEN(c.input);
  5146. c.outLen = 114;
  5147. /* Taken from NIST CAVP test vectors - full rate output. */
  5148. d.input = "\xdc\x88\x6d\xf3\xf6\x9c\x49\x51\x3d\xe3\x62\x7e\x94\x81\xdb"
  5149. "\x58\x71\xe8\xee\x88\xeb\x9f\x99\x61\x15\x41\x93\x0a\x8b\xc8"
  5150. "\x85\xe0";
  5151. d.output = "\x00\x64\x8a\xfb\xc5\xe6\x51\x64\x9d\xb1\xfd\x82\x93\x6b\x00"
  5152. "\xdb\xbc\x12\x2f\xb4\xc8\x77\x86\x0d\x38\x5c\x49\x50\xd5\x6d"
  5153. "\xe7\xe0\x96\xd6\x13\xd7\xa3\xf2\x7e\xd8\xf2\x63\x34\xb0\xcc"
  5154. "\xc1\x40\x7b\x41\xdc\xcb\x23\xdf\xaa\x52\x98\x18\xd1\x12\x5c"
  5155. "\xd5\x34\x80\x92\x52\x43\x66\xb8\x5f\xab\xb9\x7c\x6c\xd1\xe6"
  5156. "\x06\x6f\x45\x9b\xcc\x56\x6d\xa8\x7e\xc9\xb7\xba\x36\x79\x2d"
  5157. "\x11\x8a\xc3\x9a\x4c\xce\xf6\x19\x2b\xbf\x3a\x54\xaf\x18\xe5"
  5158. "\x7b\x0c\x14\x61\x01\xf6\xae\xaa\x82\x2b\xc4\xb4\xc9\x70\x8b"
  5159. "\x09\xf0\xb3\xba\xb4\x1b\xcc\xe9\x64\xd9\x99\xd1\x10\x7b\xd7"
  5160. "\xc2";
  5161. d.inLen = 32;
  5162. d.outLen = 136;
  5163. /* Taken from NIST CAVP test vectors - more than one output block. */
  5164. e.input = "\x8d\x80\x01\xe2\xc0\x96\xf1\xb8\x8e\x7c\x92\x24\xa0\x86\xef"
  5165. "\xd4\x79\x7f\xbf\x74\xa8\x03\x3a\x2d\x42\x2a\x2b\x6b\x8f\x67"
  5166. "\x47\xe4";
  5167. e.output = "\x2e\x97\x5f\x6a\x8a\x14\xf0\x70\x4d\x51\xb1\x36\x67\xd8\x19"
  5168. "\x5c\x21\x9f\x71\xe6\x34\x56\x96\xc4\x9f\xa4\xb9\xd0\x8e\x92"
  5169. "\x25\xd3\xd3\x93\x93\x42\x51\x52\xc9\x7e\x71\xdd\x24\x60\x1c"
  5170. "\x11\xab\xcf\xa0\xf1\x2f\x53\xc6\x80\xbd\x3a\xe7\x57\xb8\x13"
  5171. "\x4a\x9c\x10\xd4\x29\x61\x58\x69\x21\x7f\xdd\x58\x85\xc4\xdb"
  5172. "\x17\x49\x85\x70\x3a\x6d\x6d\xe9\x4a\x66\x7e\xac\x30\x23\x44"
  5173. "\x3a\x83\x37\xae\x1b\xc6\x01\xb7\x6d\x7d\x38\xec\x3c\x34\x46"
  5174. "\x31\x05\xf0\xd3\x94\x9d\x78\xe5\x62\xa0\x39\xe4\x46\x95\x48"
  5175. "\xb6\x09\x39\x5d\xe5\xa4\xfd\x43\xc4\x6c\xa9\xfd\x6e\xe2\x9a"
  5176. "\xda\x5e\xfc\x07\xd8\x4d\x55\x32\x49\x45\x0d\xab\x4a\x49\xc4"
  5177. "\x83\xde\xd2\x50\xc9\x33\x8f\x85\xcd\x93\x7a\xe6\x6b\xb4\x36"
  5178. "\xf3\xb4\x02\x6e\x85\x9f\xda\x1c\xa5\x71\x43\x2f\x3b\xfc\x09"
  5179. "\xe7\xc0\x3c\xa4\xd1\x83\xb7\x41\x11\x1c\xa0\x48\x3d\x0e\xda"
  5180. "\xbc\x03\xfe\xb2\x3b\x17\xee\x48\xe8\x44\xba\x24\x08\xd9\xdc"
  5181. "\xfd\x01\x39\xd2\xe8\xc7\x31\x01\x25\xae\xe8\x01\xc6\x1a\xb7"
  5182. "\x90\x0d\x1e\xfc\x47\xc0\x78\x28\x17\x66\xf3\x61\xc5\xe6\x11"
  5183. "\x13\x46\x23\x5e\x1d\xc3\x83\x25\x66\x6c";
  5184. e.inLen = 32;
  5185. e.outLen = 250;
  5186. test_sha[0] = a;
  5187. test_sha[1] = b;
  5188. test_sha[2] = c;
  5189. test_sha[3] = d;
  5190. test_sha[4] = e;
  5191. ret = wc_InitShake256(&sha, HEAP_HINT, devId);
  5192. if (ret != 0)
  5193. return WC_TEST_RET_ENC_EC(ret);
  5194. for (i = 0; i < times; ++i) {
  5195. ret = wc_Shake256_Update(&sha, (byte*)test_sha[i].input,
  5196. (word32)test_sha[i].inLen);
  5197. if (ret != 0)
  5198. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5199. ret = wc_Shake256_Final(&sha, hash, (word32)test_sha[i].outLen);
  5200. if (ret != 0)
  5201. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5202. if (XMEMCMP(hash, test_sha[i].output, test_sha[i].outLen) != 0)
  5203. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5204. }
  5205. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5206. large_input = (byte *)XMALLOC(SHAKE256_LARGE_INPUT_BUFSIZ, NULL,
  5207. DYNAMIC_TYPE_TMP_BUFFER);
  5208. if (large_input == NULL)
  5209. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  5210. #endif
  5211. #ifndef NO_LARGE_HASH_TEST
  5212. /* BEGIN LARGE HASH TEST */ {
  5213. for (i = 0; i < SHAKE256_LARGE_INPUT_BUFSIZ; i++) {
  5214. large_input[i] = (byte)(i & 0xFF);
  5215. }
  5216. times = 100;
  5217. for (i = 0; i < times; ++i) {
  5218. ret = wc_Shake256_Update(&sha, (byte*)large_input,
  5219. SHAKE256_LARGE_INPUT_BUFSIZ);
  5220. if (ret != 0)
  5221. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5222. }
  5223. ret = wc_Shake256_Final(&sha, hash, (word32)sizeof(hash));
  5224. if (ret != 0)
  5225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5226. if (XMEMCMP(hash, large_digest, 114) != 0)
  5227. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  5228. } /* END LARGE HASH TEST */
  5229. #endif /* NO_LARGE_HASH_TEST */
  5230. ret = shake256_absorb_test(&sha, large_input, SHAKE256_LARGE_INPUT_BUFSIZ);
  5231. exit:
  5232. wc_Shake256_Free(&sha);
  5233. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5234. XFREE(large_input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
  5235. #endif
  5236. return ret;
  5237. }
  5238. #endif
  5239. #ifdef WOLFSSL_SM3
  5240. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm3_test(void)
  5241. {
  5242. wc_Sm3 sm3, sm3Copy;
  5243. byte hash[WC_SM3_DIGEST_SIZE];
  5244. byte hashGet[WC_SM3_DIGEST_SIZE];
  5245. byte hashCopy[WC_SM3_DIGEST_SIZE];
  5246. wc_test_ret_t ret = 0;
  5247. WOLFSSL_ENTER("sm3_test");
  5248. testVector a, b, c;
  5249. testVector test_sm3[3];
  5250. int times = sizeof(test_sm3) / sizeof(struct testVector), i;
  5251. a.input = "";
  5252. a.output = "\x1a\xb2\x1d\x83\x55\xcf\xa1\x7f\x8e\x61\x19\x48\x31\xe8\x1a"
  5253. "\x8f\x22\xbe\xc8\xc7\x28\xfe\xfb\x74\x7e\xd0\x35\xeb\x50\x82"
  5254. "\xaa\x2b";
  5255. a.inLen = XSTRLEN(a.input);
  5256. a.outLen = WC_SM3_DIGEST_SIZE;
  5257. b.input = "abc";
  5258. b.output = "\x66\xc7\xf0\xf4\x62\xee\xed\xd9\xd1\xf2\xd4\x6b\xdc\x10\xe4"
  5259. "\xe2\x41\x67\xc4\x87\x5c\xf2\xf7\xa2\x29\x7d\xa0\x2b\x8f\x4b"
  5260. "\xa8\xe0";
  5261. b.inLen = XSTRLEN(b.input);
  5262. b.outLen = WC_SM3_DIGEST_SIZE;
  5263. c.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  5264. c.output = "\x63\x9b\x6c\xc5\xe6\x4d\x9e\x37\xa3\x90\xb1\x92\xdf\x4f\xa1"
  5265. "\xea\x07\x20\xab\x74\x7f\xf6\x92\xb9\xf3\x8c\x4e\x66\xad\x7b"
  5266. "\x8c\x05";
  5267. c.inLen = XSTRLEN(c.input);
  5268. c.outLen = WC_SM3_DIGEST_SIZE;
  5269. test_sm3[0] = a;
  5270. test_sm3[1] = b;
  5271. test_sm3[2] = c;
  5272. ret = wc_InitSm3(&sm3, HEAP_HINT, devId);
  5273. if (ret != 0)
  5274. return WC_TEST_RET_ENC_EC(ret);
  5275. ret = wc_InitSm3(&sm3Copy, HEAP_HINT, devId);
  5276. if (ret != 0) {
  5277. wc_Sm3Free(&sm3);
  5278. return WC_TEST_RET_ENC_EC(ret);
  5279. }
  5280. /* Test all the KATs. */
  5281. for (i = 0; i < times; ++i) {
  5282. ret = wc_Sm3Update(&sm3, (byte*)test_sm3[i].input,
  5283. (word32)test_sm3[i].inLen);
  5284. if (ret != 0) {
  5285. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5286. }
  5287. /* Get the final hash but leave ready for more updates. */
  5288. ret = wc_Sm3GetHash(&sm3, hashGet);
  5289. if (ret != 0)
  5290. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5291. /* Make a copy of the hash. */
  5292. ret = wc_Sm3Copy(&sm3, &sm3Copy);
  5293. if (ret != 0)
  5294. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5295. /* Get the final hash with original. */
  5296. ret = wc_Sm3Final(&sm3, hash);
  5297. if (ret != 0)
  5298. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5299. /* Get the final hash with copy. */
  5300. ret = wc_Sm3Final(&sm3Copy, hashCopy);
  5301. if (ret != 0)
  5302. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5303. /* Dispose of copy. */
  5304. wc_Sm3Free(&sm3Copy);
  5305. /* Check hashes match expected. */
  5306. if (XMEMCMP(hash, test_sm3[i].output, WC_SM3_DIGEST_SIZE) != 0)
  5307. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5308. if (XMEMCMP(hash, hashGet, WC_SM3_DIGEST_SIZE) != 0)
  5309. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5310. if (XMEMCMP(hash, hashCopy, WC_SM3_DIGEST_SIZE) != 0)
  5311. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5312. }
  5313. #ifndef NO_LARGE_HASH_TEST
  5314. {
  5315. word32 sz;
  5316. byte large_input[1024];
  5317. #ifdef HASH_SIZE_LIMIT
  5318. const char* large_digest =
  5319. "\x6c\x42\x57\x64\x8e\x45\xf3\xb6\xc0\x83\xd3\x41\x83\x66\x51\xb4"
  5320. "\x50\xfe\x06\xb5\xb7\x1e\xd5\x0d\x41\xfc\x1e\xe5\xc6\x57\x95\x0f";
  5321. times = 20;
  5322. #else
  5323. const char* large_digest =
  5324. "\x34\x51\x3c\xde\x7c\x30\xb7\xc5\xaa\x97\x3b\xed\xb3\x16\xb9\x76"
  5325. "\x35\x46\x14\x80\x2a\x57\xca\xd9\x48\xf9\x93\xcc\x1f\xdd\xab\x79";
  5326. times = 100;
  5327. #endif
  5328. /* Set large input to something. */
  5329. for (i = 0; i < (int)sizeof(large_input); i++) {
  5330. large_input[i] = (byte)(i & 0xFF);
  5331. }
  5332. /* Hash a large number of times. */
  5333. for (i = 0; i < times; ++i) {
  5334. ret = wc_Sm3Update(&sm3, (byte*)large_input,
  5335. (word32)sizeof(large_input));
  5336. if (ret != 0)
  5337. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5338. }
  5339. /* Calculate hash and compare to expected. */
  5340. ret = wc_Sm3Final(&sm3, hash);
  5341. if (ret != 0)
  5342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5343. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  5345. /* Check updating with various sizes works. */
  5346. for (sz = 1; sz <= 64; sz++) {
  5347. /* Hash a large number of times. */
  5348. for (i = 0; i < times; ++i) {
  5349. word32 o;
  5350. /* Update sz bytes at a time from large input buffer. */
  5351. for (o = 0; o + sz <= (word32)sizeof(large_input); o += sz) {
  5352. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o), sz);
  5353. if (ret != 0)
  5354. ERROR_OUT(WC_TEST_RET_ENC_I(o), exit);
  5355. }
  5356. /* Check for left-overs. */
  5357. if (o < (word32)sizeof(large_input)) {
  5358. ret = wc_Sm3Update(&sm3, (byte*)(large_input + o),
  5359. (word32)sizeof(large_input) - o);
  5360. if (ret != 0)
  5361. ERROR_OUT(WC_TEST_RET_ENC_I(i), exit);
  5362. }
  5363. }
  5364. /* Calculate hash and compare to expected. */
  5365. ret = wc_Sm3Final(&sm3, hash);
  5366. if (ret != 0)
  5367. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5368. if (XMEMCMP(hash, large_digest, WC_SM3_DIGEST_SIZE) != 0)
  5369. ERROR_OUT(WC_TEST_RET_ENC_I(sz), exit);
  5370. }
  5371. }
  5372. #endif /* NO_LARGE_HASH_TEST */
  5373. exit:
  5374. wc_Sm3Free(&sm3);
  5375. wc_Sm3Free(&sm3Copy);
  5376. return ret;
  5377. }
  5378. #endif
  5379. #ifndef NO_HASH_WRAPPER
  5380. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hash_test(void)
  5381. {
  5382. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5383. wc_HashAlg *hash = NULL;
  5384. #else
  5385. wc_HashAlg hash[1];
  5386. #endif
  5387. int ret, exp_ret;
  5388. int i, j;
  5389. int digestSz;
  5390. byte data[] = "0123456789abcdef0123456789abcdef0123456";
  5391. byte out[WC_MAX_DIGEST_SIZE];
  5392. byte hashOut[WC_MAX_DIGEST_SIZE];
  5393. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5394. enum wc_HashType hashType;
  5395. #endif
  5396. enum wc_HashType typesGood[] = { WC_HASH_TYPE_MD5, WC_HASH_TYPE_SHA,
  5397. WC_HASH_TYPE_SHA224, WC_HASH_TYPE_SHA256,
  5398. WC_HASH_TYPE_SHA384, WC_HASH_TYPE_SHA512,
  5399. WC_HASH_TYPE_SHA3_224,
  5400. WC_HASH_TYPE_SHA3_256,
  5401. WC_HASH_TYPE_SHA3_384,
  5402. WC_HASH_TYPE_SHA3_512 };
  5403. enum wc_HashType typesNoImpl[] = {
  5404. #ifdef NO_MD5
  5405. WC_HASH_TYPE_MD5,
  5406. #endif
  5407. #ifdef NO_SHA
  5408. WC_HASH_TYPE_SHA,
  5409. #endif
  5410. #ifndef WOLFSSL_SHA224
  5411. WC_HASH_TYPE_SHA224,
  5412. #endif
  5413. #ifdef NO_SHA256
  5414. WC_HASH_TYPE_SHA256,
  5415. #endif
  5416. #ifndef WOLFSSL_SHA384
  5417. WC_HASH_TYPE_SHA384,
  5418. #endif
  5419. #ifndef WOLFSSL_SHA512
  5420. WC_HASH_TYPE_SHA512,
  5421. #endif
  5422. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_224)
  5423. WC_HASH_TYPE_SHA3_224,
  5424. #endif
  5425. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_256)
  5426. WC_HASH_TYPE_SHA3_256,
  5427. #endif
  5428. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_384)
  5429. WC_HASH_TYPE_SHA3_384,
  5430. #endif
  5431. #if !defined(WOLFSSL_SHA3) || defined(WOLFSSL_NOSHA3_512)
  5432. WC_HASH_TYPE_SHA3_512,
  5433. #endif
  5434. WC_HASH_TYPE_NONE
  5435. };
  5436. enum wc_HashType typesBad[] = { WC_HASH_TYPE_NONE, WC_HASH_TYPE_MD5_SHA,
  5437. WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4 };
  5438. enum wc_HashType typesHashBad[] = { WC_HASH_TYPE_MD2, WC_HASH_TYPE_MD4,
  5439. WC_HASH_TYPE_BLAKE2B,
  5440. WC_HASH_TYPE_NONE };
  5441. WOLFSSL_ENTER("hash_test");
  5442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5443. hash = wc_HashNew(WC_HASH_TYPE_SHA256, HEAP_HINT, devId, &ret);
  5444. if (hash == NULL) {
  5445. return WC_TEST_RET_ENC_EC(ret);
  5446. }
  5447. #else
  5448. XMEMSET(hash, 0, sizeof(wc_HashAlg));
  5449. #endif
  5450. /* Parameter Validation testing. */
  5451. ret = wc_HashInit(NULL, WC_HASH_TYPE_SHA256);
  5452. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5453. return WC_TEST_RET_ENC_EC(ret);
  5454. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5455. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5456. return WC_TEST_RET_ENC_EC(ret);
  5457. ret = wc_HashUpdate(hash, WC_HASH_TYPE_SHA256, NULL, sizeof(data));
  5458. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5459. return WC_TEST_RET_ENC_EC(ret);
  5460. ret = wc_HashUpdate(NULL, WC_HASH_TYPE_SHA256, data, sizeof(data));
  5461. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5462. return WC_TEST_RET_ENC_EC(ret);
  5463. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, NULL);
  5464. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5465. return WC_TEST_RET_ENC_EC(ret);
  5466. ret = wc_HashFinal(hash, WC_HASH_TYPE_SHA256, NULL);
  5467. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5468. return WC_TEST_RET_ENC_EC(ret);
  5469. ret = wc_HashFinal(NULL, WC_HASH_TYPE_SHA256, out);
  5470. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5471. return WC_TEST_RET_ENC_EC(ret);
  5472. /* Try invalid hash algorithms. */
  5473. for (i = 0; i < (int)(sizeof(typesBad)/sizeof(*typesBad)); i++) {
  5474. ret = wc_HashInit(hash, typesBad[i]);
  5475. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5476. return WC_TEST_RET_ENC_I(i);
  5477. ret = wc_HashUpdate(hash, typesBad[i], data, sizeof(data));
  5478. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5479. return WC_TEST_RET_ENC_I(i);
  5480. ret = wc_HashFinal(hash, typesBad[i], out);
  5481. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5482. return WC_TEST_RET_ENC_I(i);
  5483. wc_HashFree(hash, typesBad[i]);
  5484. }
  5485. /* Try valid hash algorithms. */
  5486. for (i = 0, j = 0; i < (int)(sizeof(typesGood)/sizeof(*typesGood)); i++) {
  5487. exp_ret = 0;
  5488. if (typesGood[i] == typesNoImpl[j]) {
  5489. /* Recognized but no implementation compiled in. */
  5490. exp_ret = HASH_TYPE_E;
  5491. j++;
  5492. }
  5493. ret = wc_HashInit(hash, typesGood[i]);
  5494. if (ret != exp_ret)
  5495. return WC_TEST_RET_ENC_I(i);
  5496. ret = wc_HashUpdate(hash, typesGood[i], data, sizeof(data));
  5497. if (ret != exp_ret)
  5498. return WC_TEST_RET_ENC_I(i);
  5499. ret = wc_HashFinal(hash, typesGood[i], out);
  5500. if (ret != exp_ret)
  5501. return WC_TEST_RET_ENC_I(i);
  5502. wc_HashFree(hash, typesGood[i]);
  5503. digestSz = wc_HashGetDigestSize(typesGood[i]);
  5504. if (exp_ret < 0 && digestSz != exp_ret)
  5505. return WC_TEST_RET_ENC_I(i);
  5506. if (exp_ret == 0 && digestSz < 0)
  5507. return WC_TEST_RET_ENC_I(i);
  5508. if (exp_ret == 0) {
  5509. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut,
  5510. (word32)digestSz - 1);
  5511. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  5512. return WC_TEST_RET_ENC_I(i);
  5513. }
  5514. ret = wc_Hash(typesGood[i], data, sizeof(data), hashOut, (word32)digestSz);
  5515. if (ret != exp_ret)
  5516. return WC_TEST_RET_ENC_I(i);
  5517. if (exp_ret == 0 && XMEMCMP(out, hashOut, (word32)digestSz) != 0)
  5518. return WC_TEST_RET_ENC_I(i);
  5519. ret = wc_HashGetBlockSize(typesGood[i]);
  5520. if (exp_ret < 0 && ret != exp_ret)
  5521. return WC_TEST_RET_ENC_I(i);
  5522. if (exp_ret == 0 && ret < 0)
  5523. return WC_TEST_RET_ENC_I(i);
  5524. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5525. ret = wc_HashGetOID(typesGood[i]);
  5526. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG) ||
  5527. (exp_ret == 0 && ret == WC_NO_ERR_TRACE(HASH_TYPE_E)) ||
  5528. (exp_ret != 0 && ret != WC_NO_ERR_TRACE(HASH_TYPE_E))) {
  5529. return WC_TEST_RET_ENC_I(i);
  5530. }
  5531. hashType = wc_OidGetHash(ret);
  5532. if (exp_ret == 0 && hashType != typesGood[i])
  5533. return WC_TEST_RET_ENC_I(i);
  5534. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5535. }
  5536. for (i = 0; i < (int)(sizeof(typesHashBad)/sizeof(*typesHashBad)); i++) {
  5537. ret = wc_Hash(typesHashBad[i], data, sizeof(data), out, sizeof(out));
  5538. if ((ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) &&
  5539. (ret != WC_NO_ERR_TRACE(BUFFER_E)) &&
  5540. (ret != WC_NO_ERR_TRACE(HASH_TYPE_E)))
  5541. {
  5542. return WC_TEST_RET_ENC_I(i);
  5543. }
  5544. }
  5545. #if !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC)
  5546. ret = wc_HashGetOID(WC_HASH_TYPE_MD2);
  5547. #ifdef WOLFSSL_MD2
  5548. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5549. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5550. {
  5551. return WC_TEST_RET_ENC_EC(ret);
  5552. }
  5553. #else
  5554. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5555. return WC_TEST_RET_ENC_EC(ret);
  5556. #endif
  5557. hashType = wc_OidGetHash(646); /* Md2h */
  5558. #ifdef WOLFSSL_MD2
  5559. if (hashType != WC_HASH_TYPE_MD2)
  5560. return WC_TEST_RET_ENC_NC;
  5561. #else
  5562. if (hashType != WC_HASH_TYPE_NONE)
  5563. return WC_TEST_RET_ENC_NC;
  5564. #endif
  5565. ret = wc_HashGetOID(WC_HASH_TYPE_MD5_SHA);
  5566. #ifndef NO_MD5
  5567. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5568. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5569. {
  5570. return WC_TEST_RET_ENC_EC(ret);
  5571. }
  5572. #else
  5573. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5574. return WC_TEST_RET_ENC_EC(ret);
  5575. #endif
  5576. ret = wc_HashGetOID(WC_HASH_TYPE_MD4);
  5577. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5578. return WC_TEST_RET_ENC_EC(ret);
  5579. ret = wc_HashGetOID(WC_HASH_TYPE_NONE);
  5580. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5581. return WC_TEST_RET_ENC_EC(ret);
  5582. hashType = wc_OidGetHash(0);
  5583. if (hashType != WC_HASH_TYPE_NONE)
  5584. return WC_TEST_RET_ENC_NC;
  5585. #endif /* !defined(NO_ASN) || !defined(NO_DH) || defined(HAVE_ECC) */
  5586. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD2);
  5587. #ifdef WOLFSSL_MD2
  5588. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5589. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5590. {
  5591. return WC_TEST_RET_ENC_EC(ret);
  5592. }
  5593. #else
  5594. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5595. return WC_TEST_RET_ENC_EC(ret);
  5596. #endif
  5597. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD2);
  5598. #ifdef WOLFSSL_MD2
  5599. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5600. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5601. {
  5602. return WC_TEST_RET_ENC_EC(ret);
  5603. }
  5604. #else
  5605. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5606. return WC_TEST_RET_ENC_EC(ret);
  5607. #endif
  5608. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD4);
  5609. #ifndef NO_MD4
  5610. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5611. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5612. {
  5613. return WC_TEST_RET_ENC_EC(ret);
  5614. }
  5615. #else
  5616. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5617. return WC_TEST_RET_ENC_EC(ret);
  5618. #endif
  5619. ret = wc_HashGetDigestSize(WC_HASH_TYPE_MD4);
  5620. #ifndef NO_MD4
  5621. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5622. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5623. {
  5624. return WC_TEST_RET_ENC_EC(ret);
  5625. }
  5626. #else
  5627. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5628. return WC_TEST_RET_ENC_EC(ret);
  5629. #endif
  5630. ret = wc_HashGetBlockSize(WC_HASH_TYPE_MD5_SHA);
  5631. #if !defined(NO_MD5) && !defined(NO_SHA)
  5632. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5633. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5634. {
  5635. return WC_TEST_RET_ENC_EC(ret);
  5636. }
  5637. #else
  5638. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5639. return WC_TEST_RET_ENC_EC(ret);
  5640. #endif
  5641. ret = wc_HashGetBlockSize(WC_HASH_TYPE_BLAKE2B);
  5642. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5643. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5644. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5645. {
  5646. return WC_TEST_RET_ENC_EC(ret);
  5647. }
  5648. #else
  5649. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5650. return WC_TEST_RET_ENC_EC(ret);
  5651. #endif
  5652. ret = wc_HashGetDigestSize(WC_HASH_TYPE_BLAKE2B);
  5653. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  5654. if (ret == WC_NO_ERR_TRACE(HASH_TYPE_E) ||
  5655. ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5656. {
  5657. return WC_TEST_RET_ENC_EC(ret);
  5658. }
  5659. #else
  5660. if (ret != WC_NO_ERR_TRACE(HASH_TYPE_E))
  5661. return WC_TEST_RET_ENC_EC(ret);
  5662. #endif
  5663. ret = wc_HashGetBlockSize(WC_HASH_TYPE_NONE);
  5664. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5665. return WC_TEST_RET_ENC_EC(ret);
  5666. ret = wc_HashGetDigestSize(WC_HASH_TYPE_NONE);
  5667. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  5668. return WC_TEST_RET_ENC_EC(ret);
  5669. #if !defined(NO_CERTS) && !defined(NO_ASN)
  5670. #if defined(WOLFSSL_MD2) && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  5671. ret = wc_GetCTC_HashOID(MD2);
  5672. if (ret == 0)
  5673. return WC_TEST_RET_ENC_EC(ret);
  5674. #endif
  5675. #ifndef NO_MD5
  5676. ret = wc_GetCTC_HashOID(WC_MD5);
  5677. if (ret == 0)
  5678. return WC_TEST_RET_ENC_EC(ret);
  5679. #endif
  5680. #ifndef NO_SHA
  5681. ret = wc_GetCTC_HashOID(WC_SHA);
  5682. if (ret == 0)
  5683. return WC_TEST_RET_ENC_EC(ret);
  5684. #endif
  5685. #ifdef WOLFSSL_SHA224
  5686. ret = wc_GetCTC_HashOID(WC_SHA224);
  5687. if (ret == 0)
  5688. return WC_TEST_RET_ENC_EC(ret);
  5689. #endif
  5690. #ifndef NO_SHA256
  5691. ret = wc_GetCTC_HashOID(WC_SHA256);
  5692. if (ret == 0)
  5693. return WC_TEST_RET_ENC_EC(ret);
  5694. #endif
  5695. #ifdef WOLFSSL_SHA384
  5696. ret = wc_GetCTC_HashOID(WC_SHA384);
  5697. if (ret == 0)
  5698. return WC_TEST_RET_ENC_EC(ret);
  5699. #endif
  5700. #ifdef WOLFSSL_SHA512
  5701. ret = wc_GetCTC_HashOID(WC_SHA512);
  5702. if (ret == 0)
  5703. return WC_TEST_RET_ENC_EC(ret);
  5704. #endif
  5705. ret = wc_GetCTC_HashOID(-1);
  5706. if (ret != 0)
  5707. return WC_TEST_RET_ENC_EC(ret);
  5708. #endif
  5709. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  5710. (void)wc_HashDelete(hash, &hash);
  5711. #endif
  5712. return 0;
  5713. }
  5714. #endif /* !NO_HASH_WRAPPER */
  5715. #if !defined(NO_HMAC) && !defined(NO_MD5) && !(defined(HAVE_FIPS) && \
  5716. defined(HAVE_FIPS_VERSION) && \
  5717. (HAVE_FIPS_VERSION >= 5))
  5718. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_md5_test(void)
  5719. {
  5720. Hmac hmac;
  5721. byte hash[WC_MD5_DIGEST_SIZE];
  5722. const char* keys[]=
  5723. {
  5724. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  5725. "Jefe",
  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. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5731. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5732. };
  5733. testVector a, b, c, d;
  5734. testVector test_hmac[4];
  5735. wc_test_ret_t ret;
  5736. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5737. WOLFSSL_ENTER("hmac_md5_test");
  5738. /* Following test vectors are from RFC 2202 section 2 */
  5739. a.input = "Hi There";
  5740. a.output = "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc"
  5741. "\x9d";
  5742. a.inLen = XSTRLEN(a.input);
  5743. a.outLen = WC_MD5_DIGEST_SIZE;
  5744. b.input = "what do ya want for nothing?";
  5745. b.output = "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7"
  5746. "\x38";
  5747. b.inLen = XSTRLEN(b.input);
  5748. b.outLen = WC_MD5_DIGEST_SIZE;
  5749. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5750. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5751. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5752. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5753. c.output = "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3"
  5754. "\xf6";
  5755. c.inLen = XSTRLEN(c.input);
  5756. c.outLen = WC_MD5_DIGEST_SIZE;
  5757. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5758. d.output = "\x6b\x1a\xb7\xfe\x4b\xd7\xbf\x8f\x0b\x62\xe6\xce\x61\xb9\xd0"
  5759. "\xcd";
  5760. d.inLen = XSTRLEN(d.input);
  5761. d.outLen = WC_MD5_DIGEST_SIZE;
  5762. test_hmac[0] = a;
  5763. test_hmac[1] = b;
  5764. test_hmac[2] = c;
  5765. test_hmac[3] = d;
  5766. for (i = 0; i < times; ++i) {
  5767. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5768. if (i == 1) {
  5769. continue; /* cavium can't handle short keys, fips not allowed */
  5770. }
  5771. #endif
  5772. ret = wc_HmacInit(&hmac, HEAP_HINT, devId);
  5773. if (ret != 0)
  5774. return WC_TEST_RET_ENC_EC(ret);
  5775. ret = wc_HmacSetKey(&hmac, WC_MD5, (byte*)keys[i],
  5776. (word32)XSTRLEN(keys[i]));
  5777. if (ret != 0)
  5778. return WC_TEST_RET_ENC_EC(ret);
  5779. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5780. (word32)test_hmac[i].inLen);
  5781. if (ret != 0)
  5782. return WC_TEST_RET_ENC_EC(ret);
  5783. ret = wc_HmacFinal(&hmac, hash);
  5784. if (ret != 0)
  5785. return WC_TEST_RET_ENC_EC(ret);
  5786. if (XMEMCMP(hash, test_hmac[i].output, WC_MD5_DIGEST_SIZE) != 0)
  5787. return WC_TEST_RET_ENC_I(i);
  5788. wc_HmacFree(&hmac);
  5789. }
  5790. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5791. if ((ret = wc_HmacSizeByType(WC_MD5)) != WC_MD5_DIGEST_SIZE)
  5792. return WC_TEST_RET_ENC_EC(ret);
  5793. #endif
  5794. return 0;
  5795. }
  5796. #endif /* !NO_HMAC && !NO_MD5 && (!HAVE_FIPS || (HAVE_FIPS_VERSION < 5)) */
  5797. #if !defined(NO_HMAC) && !defined(NO_SHA)
  5798. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha_test(void)
  5799. {
  5800. Hmac hmac;
  5801. byte hash[WC_SHA_DIGEST_SIZE];
  5802. const char* keys[]=
  5803. {
  5804. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5805. "\x0b\x0b\x0b",
  5806. "Jefe",
  5807. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5808. "\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. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5813. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5814. };
  5815. testVector a, b, c, d;
  5816. testVector test_hmac[4];
  5817. wc_test_ret_t ret;
  5818. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5819. WOLFSSL_ENTER("hmac_sha_test");
  5820. /* Following test vectors are from RFC 2202 section 3 */
  5821. a.input = "Hi There";
  5822. a.output = "\xb6\x17\x31\x86\x55\x05\x72\x64\xe2\x8b\xc0\xb6\xfb\x37\x8c"
  5823. "\x8e\xf1\x46\xbe\x00";
  5824. a.inLen = XSTRLEN(a.input);
  5825. a.outLen = WC_SHA_DIGEST_SIZE;
  5826. b.input = "what do ya want for nothing?";
  5827. b.output = "\xef\xfc\xdf\x6a\xe5\xeb\x2f\xa2\xd2\x74\x16\xd5\xf1\x84\xdf"
  5828. "\x9c\x25\x9a\x7c\x79";
  5829. b.inLen = XSTRLEN(b.input);
  5830. b.outLen = WC_SHA_DIGEST_SIZE;
  5831. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5832. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5833. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5834. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5835. c.output = "\x12\x5d\x73\x42\xb9\xac\x11\xcd\x91\xa3\x9a\xf4\x8a\xa1\x7b"
  5836. "\x4f\x63\xf1\x75\xd3";
  5837. c.inLen = XSTRLEN(c.input);
  5838. c.outLen = WC_SHA_DIGEST_SIZE;
  5839. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5840. d.output = "\xaa\x4a\xe5\xe1\x52\x72\xd0\x0e\x95\x70\x56\x37\xce\x8a\x3b"
  5841. "\x55\xed\x40\x21\x12";
  5842. d.inLen = XSTRLEN(d.input);
  5843. d.outLen = WC_SHA_DIGEST_SIZE;
  5844. test_hmac[0] = a;
  5845. test_hmac[1] = b;
  5846. test_hmac[2] = c;
  5847. test_hmac[3] = d;
  5848. #if FIPS_VERSION3_GE(6,0,0)
  5849. int allowShortKeyWithFips = 1;
  5850. #endif
  5851. for (i = 0; i < times; ++i) {
  5852. #if defined(HAVE_CAVIUM) || (defined(HAVE_FIPS) && FIPS_VERSION3_LT(6,0,0))
  5853. if (i == 1)
  5854. continue; /* cavium can't handle short keys, fips not allowed */
  5855. #endif
  5856. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5857. return WC_TEST_RET_ENC_EC(ret);
  5858. ret = wc_HmacSetKey(&hmac, WC_SHA, (byte*)keys[i],
  5859. (word32)XSTRLEN(keys[i]));
  5860. #if FIPS_VERSION3_GE(6,0,0)
  5861. if (i == 1) {
  5862. if (ret != WC_NO_ERR_TRACE(HMAC_MIN_KEYLEN_E))
  5863. return WC_TEST_RET_ENC_EC(ret);
  5864. /* Now use the ex and allow short keys with FIPS option */
  5865. ret = wc_HmacSetKey_ex(&hmac, WC_SHA, (byte*) keys[i],
  5866. (word32)XSTRLEN(keys[i]), allowShortKeyWithFips);
  5867. }
  5868. #endif
  5869. if (ret != 0)
  5870. return WC_TEST_RET_ENC_EC(ret);
  5871. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5872. (word32)test_hmac[i].inLen);
  5873. if (ret != 0)
  5874. return WC_TEST_RET_ENC_EC(ret);
  5875. ret = wc_HmacFinal(&hmac, hash);
  5876. if (ret != 0)
  5877. return WC_TEST_RET_ENC_EC(ret);
  5878. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA_DIGEST_SIZE) != 0)
  5879. return WC_TEST_RET_ENC_I(i);
  5880. wc_HmacFree(&hmac);
  5881. }
  5882. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5883. if ((ret = wc_HmacSizeByType(WC_SHA)) != WC_SHA_DIGEST_SIZE)
  5884. return WC_TEST_RET_ENC_EC(ret);
  5885. #endif
  5886. return 0;
  5887. }
  5888. #endif
  5889. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA224)
  5890. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha224_test(void)
  5891. {
  5892. Hmac hmac;
  5893. byte hash[WC_SHA224_DIGEST_SIZE];
  5894. const char* keys[]=
  5895. {
  5896. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5897. "\x0b\x0b\x0b",
  5898. "Jefe",
  5899. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5900. "\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\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5908. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5909. "\xAA\xAA\xAA"
  5910. };
  5911. testVector a, b, c, d;
  5912. testVector test_hmac[4];
  5913. wc_test_ret_t ret;
  5914. int times = sizeof(test_hmac) / sizeof(testVector), i;
  5915. WOLFSSL_ENTER("hmac_sha224_test");
  5916. /* Following test vectors are from RFC 4231 section 4 */
  5917. a.input = "Hi There";
  5918. a.output = "\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3"
  5919. "\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22";
  5920. a.inLen = XSTRLEN(a.input);
  5921. a.outLen = WC_SHA224_DIGEST_SIZE;
  5922. b.input = "what do ya want for nothing?";
  5923. b.output = "\xa3\x0e\x01\x09\x8b\xc6\xdb\xbf\x45\x69\x0f\x3a\x7e\x9e\x6d"
  5924. "\x0f\x8b\xbe\xa2\xa3\x9e\x61\x48\x00\x8f\xd0\x5e\x44";
  5925. b.inLen = XSTRLEN(b.input);
  5926. b.outLen = WC_SHA224_DIGEST_SIZE;
  5927. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5928. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5929. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  5930. "\xDD\xDD\xDD\xDD\xDD\xDD";
  5931. c.output = "\x7f\xb3\xcb\x35\x88\xc6\xc1\xf6\xff\xa9\x69\x4d\x7d\x6a\xd2"
  5932. "\x64\x93\x65\xb0\xc1\xf6\x5d\x69\xd1\xec\x83\x33\xea";
  5933. c.inLen = XSTRLEN(c.input);
  5934. c.outLen = WC_SHA224_DIGEST_SIZE;
  5935. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  5936. 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";
  5937. d.inLen = XSTRLEN(d.input);
  5938. d.outLen = WC_SHA224_DIGEST_SIZE;
  5939. test_hmac[0] = a;
  5940. test_hmac[1] = b;
  5941. test_hmac[2] = c;
  5942. test_hmac[3] = d;
  5943. for (i = 0; i < times; ++i) {
  5944. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  5945. if (i == 1)
  5946. continue; /* cavium can't handle short keys, fips not allowed */
  5947. #endif
  5948. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  5949. return WC_TEST_RET_ENC_EC(ret);
  5950. ret = wc_HmacSetKey(&hmac, WC_SHA224, (byte*)keys[i],
  5951. (word32)XSTRLEN(keys[i]));
  5952. if (ret != 0)
  5953. return WC_TEST_RET_ENC_EC(ret);
  5954. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  5955. (word32)test_hmac[i].inLen);
  5956. if (ret != 0)
  5957. return WC_TEST_RET_ENC_EC(ret);
  5958. ret = wc_HmacFinal(&hmac, hash);
  5959. if (ret != 0)
  5960. return WC_TEST_RET_ENC_EC(ret);
  5961. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA224_DIGEST_SIZE) != 0)
  5962. return WC_TEST_RET_ENC_I(i);
  5963. wc_HmacFree(&hmac);
  5964. }
  5965. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  5966. if ((ret = wc_HmacSizeByType(WC_SHA224)) != WC_SHA224_DIGEST_SIZE)
  5967. return WC_TEST_RET_ENC_EC(ret);
  5968. #endif
  5969. return 0;
  5970. }
  5971. #endif
  5972. #if !defined(NO_HMAC) && !defined(NO_SHA256)
  5973. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha256_test(void)
  5974. {
  5975. Hmac hmac;
  5976. byte hash[WC_SHA256_DIGEST_SIZE];
  5977. const char* keys[]=
  5978. {
  5979. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  5980. "\x0b\x0b\x0b",
  5981. "Jefe",
  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\xAA"
  5985. "\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\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5993. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  5994. "\xAA\xAA\xAA"
  5995. };
  5996. testVector a, b, c, d, e;
  5997. testVector test_hmac[5];
  5998. wc_test_ret_t ret;
  5999. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6000. WOLFSSL_ENTER("hmac_sha256_test");
  6001. /* Following test vectors are from RFC 4231 section 4 */
  6002. a.input = "Hi There";
  6003. a.output = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1"
  6004. "\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32"
  6005. "\xcf\xf7";
  6006. a.inLen = XSTRLEN(a.input);
  6007. a.outLen = WC_SHA256_DIGEST_SIZE;
  6008. b.input = "what do ya want for nothing?";
  6009. b.output = "\x5b\xdc\xc1\x46\xbf\x60\x75\x4e\x6a\x04\x24\x26\x08\x95\x75"
  6010. "\xc7\x5a\x00\x3f\x08\x9d\x27\x39\x83\x9d\xec\x58\xb9\x64\xec"
  6011. "\x38\x43";
  6012. b.inLen = XSTRLEN(b.input);
  6013. b.outLen = WC_SHA256_DIGEST_SIZE;
  6014. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6015. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6016. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6017. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6018. c.output = "\x77\x3e\xa9\x1e\x36\x80\x0e\x46\x85\x4d\xb8\xeb\xd0\x91\x81"
  6019. "\xa7\x29\x59\x09\x8b\x3e\xf8\xc1\x22\xd9\x63\x55\x14\xce\xd5"
  6020. "\x65\xfe";
  6021. c.inLen = XSTRLEN(c.input);
  6022. c.outLen = WC_SHA256_DIGEST_SIZE;
  6023. d.input = 0;
  6024. d.output = "\x86\xe5\x4f\xd4\x48\x72\x5d\x7e\x5d\xcf\xe2\x23\x53\xc8\x28"
  6025. "\xaf\x48\x78\x1e\xb4\x8c\xae\x81\x06\xa7\xe1\xd4\x98\x94\x9f"
  6026. "\x3e\x46";
  6027. d.inLen = 0;
  6028. d.outLen = WC_SHA256_DIGEST_SIZE;
  6029. e.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6030. e.output = "\x60\xe4\x31\x59\x1e\xe0\xb6\x7f\x0d\x8a\x26\xaa\xcb\xf5\xb7"
  6031. "\x7f\x8e\x0b\xc6\x21\x37\x28\xc5\x14\x05\x46\x04\x0f\x0e\xe3"
  6032. "\x7f\x54";
  6033. e.inLen = XSTRLEN(e.input);;
  6034. e.outLen = WC_SHA256_DIGEST_SIZE;
  6035. test_hmac[0] = a;
  6036. test_hmac[1] = b;
  6037. test_hmac[2] = c;
  6038. test_hmac[3] = d;
  6039. test_hmac[4] = e;
  6040. for (i = 0; i < times; ++i) {
  6041. #if defined(HAVE_FIPS) || defined(HAVE_CAVIUM)
  6042. if (i == 1)
  6043. continue; /* cavium can't handle short keys, fips not allowed */
  6044. #endif
  6045. #if defined(HAVE_INTEL_QA) || defined(HAVE_CAVIUM)
  6046. if (i == 3)
  6047. continue; /* QuickAssist can't handle empty HMAC */
  6048. #endif
  6049. if (wc_HmacInit(&hmac, HEAP_HINT, devId) != 0)
  6050. return WC_TEST_RET_ENC_I(i);
  6051. ret = wc_HmacSetKey(&hmac, WC_SHA256, (byte*)keys[i],
  6052. (word32)XSTRLEN(keys[i]));
  6053. if (ret != 0)
  6054. return WC_TEST_RET_ENC_I(i);
  6055. if (test_hmac[i].input != NULL) {
  6056. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6057. (word32)test_hmac[i].inLen);
  6058. if (ret != 0)
  6059. return WC_TEST_RET_ENC_I(i);
  6060. }
  6061. ret = wc_HmacFinal(&hmac, hash);
  6062. if (ret != 0)
  6063. return WC_TEST_RET_ENC_I(i);
  6064. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA256_DIGEST_SIZE) != 0)
  6065. return WC_TEST_RET_ENC_I(i);
  6066. wc_HmacFree(&hmac);
  6067. }
  6068. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6069. if ((ret = wc_HmacSizeByType(WC_SHA256)) != WC_SHA256_DIGEST_SIZE)
  6070. return WC_TEST_RET_ENC_EC(ret);
  6071. #if FIPS_VERSION3_GE(6,0,0)
  6072. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(HMAC_KAT_FIPS_E))
  6073. #else
  6074. if ((ret = wc_HmacSizeByType(21)) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  6075. #endif
  6076. {
  6077. return WC_TEST_RET_ENC_EC(ret);
  6078. }
  6079. #endif
  6080. if ((ret = wolfSSL_GetHmacMaxSize()) != WC_MAX_DIGEST_SIZE)
  6081. return WC_TEST_RET_ENC_EC(ret);
  6082. return 0;
  6083. }
  6084. #endif
  6085. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  6086. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha384_test(void)
  6087. {
  6088. Hmac hmac;
  6089. byte hash[WC_SHA384_DIGEST_SIZE];
  6090. const char* keys[]=
  6091. {
  6092. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6093. "\x0b\x0b\x0b",
  6094. "Jefe",
  6095. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6096. "\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\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6104. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6105. "\xAA\xAA\xAA"
  6106. };
  6107. testVector a, b, c, d;
  6108. testVector test_hmac[4];
  6109. wc_test_ret_t ret;
  6110. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6111. WOLFSSL_ENTER("hmac_sha384_test");
  6112. /* Following test vectors are from RFC 4231 section 4 */
  6113. a.input = "Hi There";
  6114. a.output = "\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90"
  6115. "\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb"
  6116. "\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2"
  6117. "\xfa\x9c\xb6";
  6118. a.inLen = XSTRLEN(a.input);
  6119. a.outLen = WC_SHA384_DIGEST_SIZE;
  6120. b.input = "what do ya want for nothing?";
  6121. b.output = "\xaf\x45\xd2\xe3\x76\x48\x40\x31\x61\x7f\x78\xd2\xb5\x8a\x6b"
  6122. "\x1b\x9c\x7e\xf4\x64\xf5\xa0\x1b\x47\xe4\x2e\xc3\x73\x63\x22"
  6123. "\x44\x5e\x8e\x22\x40\xca\x5e\x69\xe2\xc7\x8b\x32\x39\xec\xfa"
  6124. "\xb2\x16\x49";
  6125. b.inLen = XSTRLEN(b.input);
  6126. b.outLen = WC_SHA384_DIGEST_SIZE;
  6127. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6128. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6129. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6130. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6131. c.output = "\x88\x06\x26\x08\xd3\xe6\xad\x8a\x0a\xa2\xac\xe0\x14\xc8\xa8"
  6132. "\x6f\x0a\xa6\x35\xd9\x47\xac\x9f\xeb\xe8\x3e\xf4\xe5\x59\x66"
  6133. "\x14\x4b\x2a\x5a\xb3\x9d\xc1\x38\x14\xb9\x4e\x3a\xb6\xe1\x01"
  6134. "\xa3\x4f\x27";
  6135. c.inLen = XSTRLEN(c.input);
  6136. c.outLen = WC_SHA384_DIGEST_SIZE;
  6137. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6138. d.output = "\x4e\xce\x08\x44\x85\x81\x3e\x90\x88\xd2\xc6\x3a\x04\x1b\xc5"
  6139. "\xb4\x4f\x9e\xf1\x01\x2a\x2b\x58\x8f\x3c\xd1\x1f\x05\x03\x3a"
  6140. "\xc4\xc6\x0c\x2e\xf6\xab\x40\x30\xfe\x82\x96\x24\x8d\xf1\x63"
  6141. "\xf4\x49\x52";
  6142. d.inLen = XSTRLEN(d.input);
  6143. d.outLen = WC_SHA384_DIGEST_SIZE;
  6144. test_hmac[0] = a;
  6145. test_hmac[1] = b;
  6146. test_hmac[2] = c;
  6147. test_hmac[3] = d;
  6148. for (i = 0; i < times; ++i) {
  6149. #if defined(HAVE_FIPS)
  6150. if (i == 1)
  6151. continue; /* fips not allowed */
  6152. #endif
  6153. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6154. return WC_TEST_RET_ENC_EC(ret);
  6155. ret = wc_HmacSetKey(&hmac, WC_SHA384, (byte*)keys[i],
  6156. (word32)XSTRLEN(keys[i]));
  6157. if (ret != 0)
  6158. return WC_TEST_RET_ENC_EC(ret);
  6159. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6160. (word32)test_hmac[i].inLen);
  6161. if (ret != 0)
  6162. return WC_TEST_RET_ENC_EC(ret);
  6163. ret = wc_HmacFinal(&hmac, hash);
  6164. if (ret != 0)
  6165. return WC_TEST_RET_ENC_EC(ret);
  6166. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA384_DIGEST_SIZE) != 0)
  6167. return WC_TEST_RET_ENC_I(i);
  6168. wc_HmacFree(&hmac);
  6169. }
  6170. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6171. if ((ret = wc_HmacSizeByType(WC_SHA384)) != WC_SHA384_DIGEST_SIZE)
  6172. return WC_TEST_RET_ENC_EC(ret);
  6173. #endif
  6174. return 0;
  6175. }
  6176. #endif
  6177. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA512)
  6178. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha512_test(void)
  6179. {
  6180. Hmac hmac;
  6181. byte hash[WC_SHA512_DIGEST_SIZE];
  6182. const char* keys[]=
  6183. {
  6184. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6185. "\x0b\x0b\x0b",
  6186. "Jefe",
  6187. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6188. "\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\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6196. "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
  6197. "\xAA\xAA\xAA"
  6198. };
  6199. testVector a, b, c, d;
  6200. testVector test_hmac[4];
  6201. wc_test_ret_t ret;
  6202. int times = sizeof(test_hmac) / sizeof(testVector), i;
  6203. WOLFSSL_ENTER("hmac_sha512_test");
  6204. /* Following test vectors are from RFC 4231 section 4 */
  6205. a.input = "Hi There";
  6206. a.output = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c"
  6207. "\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1"
  6208. "\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae"
  6209. "\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20"
  6210. "\x3a\x12\x68\x54";
  6211. a.inLen = XSTRLEN(a.input);
  6212. a.outLen = WC_SHA512_DIGEST_SIZE;
  6213. b.input = "what do ya want for nothing?";
  6214. b.output = "\x16\x4b\x7a\x7b\xfc\xf8\x19\xe2\xe3\x95\xfb\xe7\x3b\x56\xe0"
  6215. "\xa3\x87\xbd\x64\x22\x2e\x83\x1f\xd6\x10\x27\x0c\xd7\xea\x25"
  6216. "\x05\x54\x97\x58\xbf\x75\xc0\x5a\x99\x4a\x6d\x03\x4f\x65\xf8"
  6217. "\xf0\xe6\xfd\xca\xea\xb1\xa3\x4d\x4a\x6b\x4b\x63\x6e\x07\x0a"
  6218. "\x38\xbc\xe7\x37";
  6219. b.inLen = XSTRLEN(b.input);
  6220. b.outLen = WC_SHA512_DIGEST_SIZE;
  6221. c.input = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6222. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6223. "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
  6224. "\xDD\xDD\xDD\xDD\xDD\xDD";
  6225. c.output = "\xfa\x73\xb0\x08\x9d\x56\xa2\x84\xef\xb0\xf0\x75\x6c\x89\x0b"
  6226. "\xe9\xb1\xb5\xdb\xdd\x8e\xe8\x1a\x36\x55\xf8\x3e\x33\xb2\x27"
  6227. "\x9d\x39\xbf\x3e\x84\x82\x79\xa7\x22\xc8\x06\xb4\x85\xa4\x7e"
  6228. "\x67\xc8\x07\xb9\x46\xa3\x37\xbe\xe8\x94\x26\x74\x27\x88\x59"
  6229. "\xe1\x32\x92\xfb";
  6230. c.inLen = XSTRLEN(c.input);
  6231. c.outLen = WC_SHA512_DIGEST_SIZE;
  6232. d.input = "Test Using Larger Than Block-Size Key - Hash Key First";
  6233. d.output = "\x80\xb2\x42\x63\xc7\xc1\xa3\xeb\xb7\x14\x93\xc1\xdd\x7b\xe8"
  6234. "\xb4\x9b\x46\xd1\xf4\x1b\x4a\xee\xc1\x12\x1b\x01\x37\x83\xf8"
  6235. "\xf3\x52\x6b\x56\xd0\x37\xe0\x5f\x25\x98\xbd\x0f\xd2\x21\x5d"
  6236. "\x6a\x1e\x52\x95\xe6\x4f\x73\xf6\x3f\x0a\xec\x8b\x91\x5a\x98"
  6237. "\x5d\x78\x65\x98";
  6238. d.inLen = XSTRLEN(d.input);
  6239. d.outLen = WC_SHA512_DIGEST_SIZE;
  6240. test_hmac[0] = a;
  6241. test_hmac[1] = b;
  6242. test_hmac[2] = c;
  6243. test_hmac[3] = d;
  6244. for (i = 0; i < times; ++i) {
  6245. #if defined(HAVE_FIPS)
  6246. if (i == 1)
  6247. continue; /* fips not allowed */
  6248. #endif
  6249. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6250. return WC_TEST_RET_ENC_EC(ret);
  6251. ret = wc_HmacSetKey(&hmac, WC_SHA512, (byte*)keys[i],
  6252. (word32)XSTRLEN(keys[i]));
  6253. if (ret != 0)
  6254. return WC_TEST_RET_ENC_EC(ret);
  6255. ret = wc_HmacUpdate(&hmac, (byte*)test_hmac[i].input,
  6256. (word32)test_hmac[i].inLen);
  6257. if (ret != 0)
  6258. return WC_TEST_RET_ENC_EC(ret);
  6259. ret = wc_HmacFinal(&hmac, hash);
  6260. if (ret != 0)
  6261. return WC_TEST_RET_ENC_EC(ret);
  6262. if (XMEMCMP(hash, test_hmac[i].output, WC_SHA512_DIGEST_SIZE) != 0)
  6263. return WC_TEST_RET_ENC_I(i);
  6264. wc_HmacFree(&hmac);
  6265. }
  6266. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6267. if ((ret = wc_HmacSizeByType(WC_SHA512)) != WC_SHA512_DIGEST_SIZE)
  6268. return WC_TEST_RET_ENC_EC(ret);
  6269. #endif
  6270. return 0;
  6271. }
  6272. #endif
  6273. #if !defined(NO_HMAC) && defined(WOLFSSL_SHA3) && \
  6274. !defined(WOLFSSL_NOSHA3_224) && !defined(WOLFSSL_NOSHA3_256) && \
  6275. !defined(WOLFSSL_NOSHA3_384) && !defined(WOLFSSL_NOSHA3_512)
  6276. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hmac_sha3_test(void)
  6277. {
  6278. Hmac hmac;
  6279. byte hash[WC_SHA3_512_DIGEST_SIZE];
  6280. const char* key[4] =
  6281. {
  6282. "Jefe",
  6283. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
  6284. "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",
  6285. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
  6286. "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa",
  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. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6296. "\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
  6297. };
  6298. const char* input[4] =
  6299. {
  6300. "what do ya want for nothing?",
  6301. "Hi There",
  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. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
  6306. "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd",
  6307. "Big Key Input"
  6308. };
  6309. const int hashType[4] =
  6310. {
  6311. WC_SHA3_224, WC_SHA3_256, WC_SHA3_384, WC_SHA3_512
  6312. };
  6313. const int hashSz[4] =
  6314. {
  6315. WC_SHA3_224_DIGEST_SIZE, WC_SHA3_256_DIGEST_SIZE,
  6316. WC_SHA3_384_DIGEST_SIZE, WC_SHA3_512_DIGEST_SIZE
  6317. };
  6318. const char* output[16] =
  6319. {
  6320. /* key = jefe, input = what do ya want for nothing? */
  6321. /* HMAC-SHA3-224 */
  6322. "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d\x1b\x79\x86\x34\xad\x38\x68\x11"
  6323. "\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b\xba\xce\x5e\x66",
  6324. /* HMAC-SHA3-256 */
  6325. "\xc7\xd4\x07\x2e\x78\x88\x77\xae\x35\x96\xbb\xb0\xda\x73\xb8\x87"
  6326. "\xc9\x17\x1f\x93\x09\x5b\x29\x4a\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5",
  6327. /* HMAC-SHA3-384 */
  6328. "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd\x67\x64\xd2\xed\x61\x90\x3f\x21"
  6329. "\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2\x3c\xa1\x35\x08\xa9\x32\x43\xce"
  6330. "\x48\xc0\x45\xdc\x00\x7f\x26\xa2\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a",
  6331. /* HMAC-SHA3-512 */
  6332. "\x5a\x4b\xfe\xab\x61\x66\x42\x7c\x7a\x36\x47\xb7\x47\x29\x2b\x83"
  6333. "\x84\x53\x7c\xdb\x89\xaf\xb3\xbf\x56\x65\xe4\xc5\xe7\x09\x35\x0b"
  6334. "\x28\x7b\xae\xc9\x21\xfd\x7c\xa0\xee\x7a\x0c\x31\xd0\x22\xa9\x5e"
  6335. "\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83\x96\x02\x75\xbe\xb4\xe6\x20\x24",
  6336. /* key = 0b..., input = Hi There */
  6337. /* HMAC-SHA3-224 */
  6338. "\x3b\x16\x54\x6b\xbc\x7b\xe2\x70\x6a\x03\x1d\xca\xfd\x56\x37\x3d"
  6339. "\x98\x84\x36\x76\x41\xd8\xc5\x9a\xf3\xc8\x60\xf7",
  6340. /* HMAC-SHA3-256 */
  6341. "\xba\x85\x19\x23\x10\xdf\xfa\x96\xe2\xa3\xa4\x0e\x69\x77\x43\x51"
  6342. "\x14\x0b\xb7\x18\x5e\x12\x02\xcd\xcc\x91\x75\x89\xf9\x5e\x16\xbb",
  6343. /* HMAC-SHA3-384 */
  6344. "\x68\xd2\xdc\xf7\xfd\x4d\xdd\x0a\x22\x40\xc8\xa4\x37\x30\x5f\x61"
  6345. "\xfb\x73\x34\xcf\xb5\xd0\x22\x6e\x1b\xc2\x7d\xc1\x0a\x2e\x72\x3a"
  6346. "\x20\xd3\x70\xb4\x77\x43\x13\x0e\x26\xac\x7e\x3d\x53\x28\x86\xbd",
  6347. /* HMAC-SHA3-512 */
  6348. "\xeb\x3f\xbd\x4b\x2e\xaa\xb8\xf5\xc5\x04\xbd\x3a\x41\x46\x5a\xac"
  6349. "\xec\x15\x77\x0a\x7c\xab\xac\x53\x1e\x48\x2f\x86\x0b\x5e\xc7\xba"
  6350. "\x47\xcc\xb2\xc6\xf2\xaf\xce\x8f\x88\xd2\x2b\x6d\xc6\x13\x80\xf2"
  6351. "\x3a\x66\x8f\xd3\x88\x8b\xb8\x05\x37\xc0\xa0\xb8\x64\x07\x68\x9e",
  6352. /* key = aa..., output = dd... */
  6353. /* HMAC-SHA3-224 */
  6354. "\x67\x6c\xfc\x7d\x16\x15\x36\x38\x78\x03\x90\x69\x2b\xe1\x42\xd2"
  6355. "\xdf\x7c\xe9\x24\xb9\x09\xc0\xc0\x8d\xbf\xdc\x1a",
  6356. /* HMAC-SHA3-256 */
  6357. "\x84\xec\x79\x12\x4a\x27\x10\x78\x65\xce\xdd\x8b\xd8\x2d\xa9\x96"
  6358. "\x5e\x5e\xd8\xc3\x7b\x0a\xc9\x80\x05\xa7\xf3\x9e\xd5\x8a\x42\x07",
  6359. /* HMAC-SHA3-384 */
  6360. "\x27\x5c\xd0\xe6\x61\xbb\x8b\x15\x1c\x64\xd2\x88\xf1\xf7\x82\xfb"
  6361. "\x91\xa8\xab\xd5\x68\x58\xd7\x2b\xab\xb2\xd4\x76\xf0\x45\x83\x73"
  6362. "\xb4\x1b\x6a\xb5\xbf\x17\x4b\xec\x42\x2e\x53\xfc\x31\x35\xac\x6e",
  6363. /* HMAC-SHA3-512 */
  6364. "\x30\x9e\x99\xf9\xec\x07\x5e\xc6\xc6\xd4\x75\xed\xa1\x18\x06\x87"
  6365. "\xfc\xf1\x53\x11\x95\x80\x2a\x99\xb5\x67\x74\x49\xa8\x62\x51\x82"
  6366. "\x85\x1c\xb3\x32\xaf\xb6\xa8\x9c\x41\x13\x25\xfb\xcb\xcd\x42\xaf"
  6367. "\xcb\x7b\x6e\x5a\xab\x7e\xa4\x2c\x66\x0f\x97\xfd\x85\x84\xbf\x03",
  6368. /* key = big key, input = Big Key Input */
  6369. /* HMAC-SHA3-224 */
  6370. "\x29\xe0\x5e\x46\xc4\xa4\x5e\x46\x74\xbf\xd7\x2d\x1a\xd8\x66\xdb"
  6371. "\x2d\x0d\x10\x4e\x2b\xfa\xad\x53\x7d\x15\x69\x8b",
  6372. /* HMAC-SHA3-256 */
  6373. "\xb5\x5b\x8d\x64\xb6\x9c\x21\xd0\xbf\x20\x5c\xa2\xf7\xb9\xb1\x4e"
  6374. "\x88\x21\x61\x2c\x66\xc3\x91\xae\x6c\x95\x16\x85\x83\xe6\xf4\x9b",
  6375. /* HMAC-SHA3-384 */
  6376. "\xaa\x91\xb3\xa6\x2f\x56\xa1\xbe\x8c\x3e\x74\x38\xdb\x58\xd9\xd3"
  6377. "\x34\xde\xa0\x60\x6d\x8d\x46\xe0\xec\xa9\xf6\x06\x35\x14\xe6\xed"
  6378. "\x83\xe6\x7c\x77\x24\x6c\x11\xb5\x90\x82\xb5\x75\xda\x7b\x83\x2d",
  6379. /* HMAC-SHA3-512 */
  6380. "\x1c\xc3\xa9\x24\x4a\x4a\x3f\xbd\xc7\x20\x00\x16\x9b\x79\x47\x03"
  6381. "\x78\x75\x2c\xb5\xf1\x2e\x62\x7c\xbe\xef\x4e\x8f\x0b\x11\x2b\x32"
  6382. "\xa0\xee\xc9\xd0\x4d\x64\x64\x0b\x37\xf4\xdd\x66\xf7\x8b\xb3\xad"
  6383. "\x52\x52\x6b\x65\x12\xde\x0d\x7c\xc0\x8b\x60\x01\x6c\x37\xd7\xa8"
  6384. };
  6385. int i = 0, iMax = sizeof(input) / sizeof(input[0]),
  6386. j, jMax = sizeof(hashType) / sizeof(hashType[0]);
  6387. int ret;
  6388. WOLFSSL_ENTER("hmac_sha3_test");
  6389. #ifdef HAVE_FIPS
  6390. /* FIPS requires a minimum length for HMAC keys, and "Jefe" is too
  6391. * short. Skip it in FIPS builds. */
  6392. i = 1;
  6393. #endif
  6394. for (; i < iMax; i++) {
  6395. for (j = 0; j < jMax; j++) {
  6396. if ((ret = wc_HmacInit(&hmac, HEAP_HINT, devId)) != 0)
  6397. return WC_TEST_RET_ENC_EC(ret);
  6398. ret = wc_HmacSetKey(&hmac, hashType[j], (byte*)key[i],
  6399. (word32)XSTRLEN(key[i]));
  6400. if (ret != 0)
  6401. return WC_TEST_RET_ENC_EC(ret);
  6402. ret = wc_HmacUpdate(&hmac, (byte*)input[i],
  6403. (word32)XSTRLEN(input[i]));
  6404. if (ret != 0)
  6405. return WC_TEST_RET_ENC_EC(ret);
  6406. ret = wc_HmacFinal(&hmac, hash);
  6407. if (ret != 0)
  6408. return WC_TEST_RET_ENC_EC(ret);
  6409. if (XMEMCMP(hash, output[(i*jMax) + j], (size_t)hashSz[j]) != 0)
  6410. return WC_TEST_RET_ENC_NC;
  6411. wc_HmacFree(&hmac);
  6412. if (i > 0)
  6413. continue;
  6414. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  6415. ret = wc_HmacSizeByType(hashType[j]);
  6416. if (ret != hashSz[j])
  6417. return WC_TEST_RET_ENC_EC(ret);
  6418. #endif
  6419. }
  6420. }
  6421. return 0;
  6422. }
  6423. #endif
  6424. #ifdef WC_RC2
  6425. typedef struct rc2TestVector {
  6426. const char* input;
  6427. const char* output;
  6428. const char* key; /* Key, variable up to 128 bytes */
  6429. const char* iv; /* IV, 8-bytes */
  6430. int inLen;
  6431. int outLen;
  6432. int keyLen;
  6433. int effectiveKeyBits; /* Up to 1024 bits supported */
  6434. } rc2TestVector;
  6435. static wc_test_ret_t rc2_ecb_test(void)
  6436. {
  6437. wc_test_ret_t ret = 0;
  6438. byte cipher[RC2_BLOCK_SIZE];
  6439. byte plain[RC2_BLOCK_SIZE];
  6440. rc2TestVector a, b, c, d, e, f, g, h;
  6441. rc2TestVector test_rc2[8];
  6442. int times = sizeof(test_rc2) / sizeof(rc2TestVector), i;
  6443. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6444. a.output = "\xeb\xb7\x73\xf9\x93\x27\x8e\xff";
  6445. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6446. a.inLen = RC2_BLOCK_SIZE;
  6447. a.outLen = RC2_BLOCK_SIZE;
  6448. a.keyLen = 8;
  6449. a.effectiveKeyBits = 63;
  6450. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6451. b.output = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49";
  6452. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6453. b.inLen = RC2_BLOCK_SIZE;
  6454. b.outLen = RC2_BLOCK_SIZE;
  6455. b.keyLen = 8;
  6456. b.effectiveKeyBits = 64;
  6457. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01";
  6458. c.output = "\x30\x64\x9e\xdf\x9b\xe7\xd2\xc2";
  6459. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6460. c.inLen = RC2_BLOCK_SIZE;
  6461. c.outLen = RC2_BLOCK_SIZE;
  6462. c.keyLen = 8;
  6463. c.effectiveKeyBits = 64;
  6464. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6465. d.output = "\x61\xa8\xa2\x44\xad\xac\xcc\xf0";
  6466. d.key = "\x88";
  6467. d.inLen = RC2_BLOCK_SIZE;
  6468. d.outLen = RC2_BLOCK_SIZE;
  6469. d.keyLen = 1;
  6470. d.effectiveKeyBits = 64;
  6471. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6472. e.output = "\x6c\xcf\x43\x08\x97\x4c\x26\x7f";
  6473. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6474. e.inLen = RC2_BLOCK_SIZE;
  6475. e.outLen = RC2_BLOCK_SIZE;
  6476. e.keyLen = 7;
  6477. e.effectiveKeyBits = 64;
  6478. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6479. f.output = "\x1a\x80\x7d\x27\x2b\xbe\x5d\xb1";
  6480. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6481. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6482. f.inLen = RC2_BLOCK_SIZE;
  6483. f.outLen = RC2_BLOCK_SIZE;
  6484. f.keyLen = 16;
  6485. f.effectiveKeyBits = 64;
  6486. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6487. g.output = "\x22\x69\x55\x2a\xb0\xf8\x5c\xa6";
  6488. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6489. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6490. g.inLen = RC2_BLOCK_SIZE;
  6491. g.outLen = RC2_BLOCK_SIZE;
  6492. g.keyLen = 16;
  6493. g.effectiveKeyBits = 128;
  6494. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6495. h.output = "\x5b\x78\xd3\xa4\x3d\xff\xf1\xf1";
  6496. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6497. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6498. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6499. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6500. "\x1e";
  6501. h.inLen = RC2_BLOCK_SIZE;
  6502. h.outLen = RC2_BLOCK_SIZE;
  6503. h.keyLen = 33;
  6504. h.effectiveKeyBits = 129;
  6505. a.iv = b.iv = c.iv = d.iv = e.iv = f.iv = g.iv = h.iv = NULL;
  6506. test_rc2[0] = a;
  6507. test_rc2[1] = b;
  6508. test_rc2[2] = c;
  6509. test_rc2[3] = d;
  6510. test_rc2[4] = e;
  6511. test_rc2[5] = f;
  6512. test_rc2[6] = g;
  6513. test_rc2[7] = h;
  6514. for (i = 0; i < times; ++i) {
  6515. Rc2 enc;
  6516. XMEMSET(cipher, 0, RC2_BLOCK_SIZE);
  6517. XMEMSET(plain, 0, RC2_BLOCK_SIZE);
  6518. ret = wc_Rc2SetKey(&enc, (byte*)test_rc2[i].key, test_rc2[i].keyLen,
  6519. NULL, test_rc2[i].effectiveKeyBits);
  6520. if (ret != 0) {
  6521. return WC_TEST_RET_ENC_EC(ret);
  6522. }
  6523. /* ECB encrypt */
  6524. ret = wc_Rc2EcbEncrypt(&enc, cipher, (byte*)test_rc2[i].input,
  6525. (word32)test_rc2[i].outLen);
  6526. if (ret != 0) {
  6527. return WC_TEST_RET_ENC_EC(ret);
  6528. }
  6529. if (XMEMCMP(cipher, test_rc2[i].output, test_rc2[i].outLen)) {
  6530. return WC_TEST_RET_ENC_NC;
  6531. }
  6532. /* ECB decrypt */
  6533. ret = wc_Rc2EcbDecrypt(&enc, plain, cipher, RC2_BLOCK_SIZE);
  6534. if (ret != 0) {
  6535. return WC_TEST_RET_ENC_EC(ret);
  6536. }
  6537. if (XMEMCMP(plain, test_rc2[i].input, RC2_BLOCK_SIZE)) {
  6538. return WC_TEST_RET_ENC_NC;
  6539. }
  6540. }
  6541. return 0;
  6542. }
  6543. static wc_test_ret_t rc2_cbc_test(void)
  6544. {
  6545. wc_test_ret_t ret = 0;
  6546. byte cipher[128];
  6547. byte plain[128];
  6548. rc2TestVector a, b, c, d, e, f, g, h, i;
  6549. rc2TestVector test_rc2[9];
  6550. int times = sizeof(test_rc2) / sizeof(rc2TestVector), j;
  6551. /* key length = 7, effective key bits = 63 */
  6552. a.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6553. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6554. a.output = "\xEB\xB7\x73\xF9\x93\x27\x8E\xFF"
  6555. "\xF0\x51\x77\x8B\x65\xDB\x13\x57";
  6556. a.key = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6557. a.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6558. a.inLen = RC2_BLOCK_SIZE*2;
  6559. a.outLen = RC2_BLOCK_SIZE*2;
  6560. a.keyLen = 8;
  6561. a.effectiveKeyBits = 63;
  6562. /* key length = 8, effective key bits = 64, all 0xFF */
  6563. b.input = "\xff\xff\xff\xff\xff\xff\xff\xff"
  6564. "\xff\xff\xff\xff\xff\xff\xff\xff";
  6565. b.output = "\xA3\xA1\x12\x65\x4F\x81\xC5\xCD"
  6566. "\xB6\x94\x3E\xEA\x3E\x8B\x9D\x1F";
  6567. b.key = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6568. b.iv = "\xff\xff\xff\xff\xff\xff\xff\xff";
  6569. b.inLen = RC2_BLOCK_SIZE*2;
  6570. b.outLen = RC2_BLOCK_SIZE*2;
  6571. b.keyLen = 8;
  6572. b.effectiveKeyBits = 64;
  6573. /* key length = 8, effective key bits = 64 */
  6574. c.input = "\x10\x00\x00\x00\x00\x00\x00\x01"
  6575. "\x10\x00\x00\x00\x00\x00\x00\x01";
  6576. c.output = "\xB5\x70\x14\xA2\x5F\x40\xE3\x6D"
  6577. "\x81\x99\x8D\xE0\xB5\xD5\x3A\x05";
  6578. c.key = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6579. c.iv = "\x30\x00\x00\x00\x00\x00\x00\x00";
  6580. c.inLen = RC2_BLOCK_SIZE*2;
  6581. c.outLen = RC2_BLOCK_SIZE*2;
  6582. c.keyLen = 8;
  6583. c.effectiveKeyBits = 64;
  6584. /* key length = 1, effective key bits = 64 */
  6585. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6586. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6587. d.output = "\x61\xA8\xA2\x44\xAD\xAC\xCC\xF0"
  6588. "\x6D\x19\xE8\xF1\xFC\xE7\x38\x87";
  6589. d.key = "\x88";
  6590. d.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6591. d.inLen = RC2_BLOCK_SIZE*2;
  6592. d.outLen = RC2_BLOCK_SIZE*2;
  6593. d.keyLen = 1;
  6594. d.effectiveKeyBits = 64;
  6595. /* key length = 7, effective key bits = 64 */
  6596. e.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6597. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6598. e.output = "\x6C\xCF\x43\x08\x97\x4C\x26\x7F"
  6599. "\xCC\x3C\x53\x57\x7C\xA1\xA4\x4B";
  6600. e.key = "\x88\xbc\xa9\x0e\x90\x87\x5a";
  6601. e.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6602. e.inLen = RC2_BLOCK_SIZE*2;
  6603. e.outLen = RC2_BLOCK_SIZE*2;
  6604. e.keyLen = 7;
  6605. e.effectiveKeyBits = 64;
  6606. /* key length = 16, effective key bits = 64 */
  6607. f.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6608. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6609. f.output = "\x1A\x80\x7D\x27\x2B\xBE\x5D\xB1"
  6610. "\x64\xEF\xE1\xC3\xB8\xAD\xFB\xBA";
  6611. f.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6612. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6613. f.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6614. f.inLen = RC2_BLOCK_SIZE*2;
  6615. f.outLen = RC2_BLOCK_SIZE*2;
  6616. f.keyLen = 16;
  6617. f.effectiveKeyBits = 64;
  6618. /* key length = 16, effective bits = 128 */
  6619. g.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6620. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6621. g.output = "\x22\x69\x55\x2A\xB0\xF8\x5C\xA6"
  6622. "\x53\x6E\xFD\x2D\x89\xE1\x2A\x73";
  6623. g.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6624. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2";
  6625. g.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6626. g.inLen = RC2_BLOCK_SIZE*2;
  6627. g.outLen = RC2_BLOCK_SIZE*2;
  6628. g.keyLen = 16;
  6629. g.effectiveKeyBits = 128;
  6630. /* key length = 33, effective bits = 129 */
  6631. h.input = "\x00\x00\x00\x00\x00\x00\x00\x00"
  6632. "\x00\x00\x00\x00\x00\x00\x00\x00";
  6633. h.output = "\x5B\x78\xD3\xA4\x3D\xFF\xF1\xF1"
  6634. "\x45\x30\xA8\xD5\xC7\x7C\x46\x19";
  6635. h.key = "\x88\xbc\xa9\x0e\x90\x87\x5a\x7f"
  6636. "\x0f\x79\xc3\x84\x62\x7b\xaf\xb2"
  6637. "\x16\xf8\x0a\x6f\x85\x92\x05\x84"
  6638. "\xc4\x2f\xce\xb0\xbe\x25\x5d\xaf"
  6639. "\x1e";
  6640. h.iv = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6641. h.inLen = RC2_BLOCK_SIZE*2;
  6642. h.outLen = RC2_BLOCK_SIZE*2;
  6643. h.keyLen = 33;
  6644. h.effectiveKeyBits = 129;
  6645. /* key length = 10, effective bits = 40 */
  6646. i.input = "\x11\x22\x33\x44\x55\x66\x77\x88"
  6647. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00"
  6648. "\x11\x22\x33\x44\x55\x66\x77\x88"
  6649. "\x99\xAA\xBB\xCC\xDD\xEE\xFF\x00";
  6650. i.output = "\x71\x2D\x11\x99\xC9\xA0\x78\x4F"
  6651. "\xCD\xF1\x1E\x3D\xFD\x21\x7E\xDB"
  6652. "\xB2\x6E\x0D\xA4\x72\xBC\x31\x51"
  6653. "\x48\xEF\x4E\x68\x3B\xDC\xCD\x7D";
  6654. i.key = "\x26\x1E\x57\x8E\xC9\x62\xBF\xB8"
  6655. "\x3E\x96";
  6656. i.iv = "\x01\x02\x03\x04\x05\x06\x07\x08";
  6657. i.inLen = RC2_BLOCK_SIZE*4;
  6658. i.outLen = RC2_BLOCK_SIZE*4;
  6659. i.keyLen = 10;
  6660. i.effectiveKeyBits = 40;
  6661. test_rc2[0] = a;
  6662. test_rc2[1] = b;
  6663. test_rc2[2] = c;
  6664. test_rc2[3] = d;
  6665. test_rc2[4] = e;
  6666. test_rc2[5] = f;
  6667. test_rc2[6] = g;
  6668. test_rc2[7] = h;
  6669. test_rc2[8] = i;
  6670. for (j = 0; j < times; ++j) {
  6671. Rc2 rc2;
  6672. XMEMSET(cipher, 0, sizeof(cipher));
  6673. XMEMSET(plain, 0, sizeof(plain));
  6674. ret = wc_Rc2SetKey(&rc2, (byte*)test_rc2[j].key, test_rc2[j].keyLen,
  6675. (byte*)test_rc2[j].iv, test_rc2[j].effectiveKeyBits);
  6676. if (ret != 0) {
  6677. return WC_TEST_RET_ENC_EC(ret);
  6678. }
  6679. ret = wc_Rc2CbcEncrypt(&rc2, cipher, (byte*)test_rc2[j].input,
  6680. test_rc2[j].inLen);
  6681. if (ret != 0) {
  6682. return WC_TEST_RET_ENC_EC(ret);
  6683. }
  6684. if (XMEMCMP(cipher, (byte*)test_rc2[j].output, test_rc2[j].outLen)) {
  6685. return WC_TEST_RET_ENC_NC;
  6686. }
  6687. /* reset IV for decrypt, since overridden by encrypt operation */
  6688. ret = wc_Rc2SetIV(&rc2, (byte*)test_rc2[j].iv);
  6689. if (ret != 0) {
  6690. return WC_TEST_RET_ENC_EC(ret);
  6691. }
  6692. ret = wc_Rc2CbcDecrypt(&rc2, plain, cipher, test_rc2[j].outLen);
  6693. if (ret != 0) {
  6694. return WC_TEST_RET_ENC_EC(ret);
  6695. }
  6696. if (XMEMCMP(plain, (byte*)test_rc2[j].input, test_rc2[j].inLen)) {
  6697. return WC_TEST_RET_ENC_NC;
  6698. }
  6699. }
  6700. return 0;
  6701. }
  6702. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rc2_test(void)
  6703. {
  6704. wc_test_ret_t ret = 0;
  6705. WOLFSSL_ENTER("rc2_test");
  6706. ret = rc2_ecb_test();
  6707. if (ret != 0) {
  6708. return ret;
  6709. }
  6710. return rc2_cbc_test();
  6711. }
  6712. #endif
  6713. #ifndef NO_RC4
  6714. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t arc4_test(void)
  6715. {
  6716. byte cipher[16];
  6717. byte plain[16];
  6718. wc_test_ret_t ret;
  6719. const char* keys[] =
  6720. {
  6721. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6722. "\x01\x23\x45\x67\x89\xab\xcd\xef",
  6723. "\x00\x00\x00\x00\x00\x00\x00\x00",
  6724. "\xef\x01\x23\x45"
  6725. };
  6726. testVector a, b, c, d;
  6727. testVector test_arc4[4];
  6728. int times = sizeof(test_arc4) / sizeof(testVector), i;
  6729. WOLFSSL_ENTER("arc4_test");
  6730. a.input = "\x01\x23\x45\x67\x89\xab\xcd\xef";
  6731. a.output = "\x75\xb7\x87\x80\x99\xe0\xc5\x96";
  6732. a.inLen = 8;
  6733. a.outLen = 8;
  6734. b.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6735. b.output = "\x74\x94\xc2\xe7\x10\x4b\x08\x79";
  6736. b.inLen = 8;
  6737. b.outLen = 8;
  6738. c.input = "\x00\x00\x00\x00\x00\x00\x00\x00";
  6739. c.output = "\xde\x18\x89\x41\xa3\x37\x5d\x3a";
  6740. c.inLen = 8;
  6741. c.outLen = 8;
  6742. d.input = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  6743. d.output = "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61";
  6744. d.inLen = 10;
  6745. d.outLen = 10;
  6746. test_arc4[0] = a;
  6747. test_arc4[1] = b;
  6748. test_arc4[2] = c;
  6749. test_arc4[3] = d;
  6750. for (i = 0; i < times; ++i) {
  6751. Arc4 enc;
  6752. Arc4 dec;
  6753. int keylen = 8; /* XSTRLEN with key 0x00 not good */
  6754. if (i == 3)
  6755. keylen = 4;
  6756. ret = wc_Arc4Init(&enc, HEAP_HINT, devId);
  6757. if (ret != 0)
  6758. return WC_TEST_RET_ENC_EC(ret);
  6759. ret = wc_Arc4Init(&dec, HEAP_HINT, devId);
  6760. if (ret != 0)
  6761. return WC_TEST_RET_ENC_EC(ret);
  6762. ret = wc_Arc4SetKey(&enc, (byte*)keys[i], (word32)keylen);
  6763. if (ret != 0)
  6764. return WC_TEST_RET_ENC_EC(ret);
  6765. ret = wc_Arc4SetKey(&dec, (byte*)keys[i], (word32)keylen);
  6766. if (ret != 0)
  6767. return WC_TEST_RET_ENC_EC(ret);
  6768. ret = wc_Arc4Process(&enc, cipher, (byte*)test_arc4[i].input,
  6769. (word32)test_arc4[i].outLen);
  6770. if (ret != 0)
  6771. return WC_TEST_RET_ENC_EC(ret);
  6772. ret = wc_Arc4Process(&dec, plain, cipher, (word32)test_arc4[i].outLen);
  6773. if (ret != 0)
  6774. return WC_TEST_RET_ENC_EC(ret);
  6775. if (XMEMCMP(plain, test_arc4[i].input, test_arc4[i].outLen))
  6776. return WC_TEST_RET_ENC_I(i);
  6777. if (XMEMCMP(cipher, test_arc4[i].output, test_arc4[i].outLen))
  6778. return WC_TEST_RET_ENC_I(i);
  6779. wc_Arc4Free(&enc);
  6780. wc_Arc4Free(&dec);
  6781. }
  6782. return 0;
  6783. }
  6784. #endif
  6785. #ifdef HAVE_CHACHA
  6786. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha_test(void)
  6787. {
  6788. ChaCha enc;
  6789. ChaCha dec;
  6790. byte cipher[128];
  6791. byte plain[128];
  6792. byte sliver[64];
  6793. byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  6794. word32 keySz = 32;
  6795. wc_test_ret_t ret = 0;
  6796. int i;
  6797. int times = 4;
  6798. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  6799. {
  6800. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6801. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6802. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6803. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6804. };
  6805. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  6806. {
  6807. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6808. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6809. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6810. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  6811. };
  6812. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  6813. {
  6814. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6815. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6816. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6817. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6818. };
  6819. /* 128 bit key */
  6820. WOLFSSL_SMALL_STACK_STATIC const byte key4[] =
  6821. {
  6822. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  6823. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  6824. };
  6825. const byte* keys[] = {key1, key2, key3, key4};
  6826. WOLFSSL_SMALL_STACK_STATIC const byte ivs1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6827. WOLFSSL_SMALL_STACK_STATIC const byte ivs2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6828. WOLFSSL_SMALL_STACK_STATIC const byte ivs3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00};
  6829. WOLFSSL_SMALL_STACK_STATIC const byte ivs4[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  6830. const byte* ivs[] = {ivs1, ivs2, ivs3, ivs4};
  6831. #ifndef BENCH_EMBEDDED
  6832. WOLFSSL_SMALL_STACK_STATIC const byte cipher_big_result[] = {
  6833. 0x06, 0xa6, 0x5d, 0x31, 0x21, 0x6c, 0xdb, 0x37, 0x48, 0x7c, 0x01, 0x9d,
  6834. 0x72, 0xdf, 0x0a, 0x5b, 0x64, 0x74, 0x20, 0xba, 0x9e, 0xe0, 0x26, 0x7a,
  6835. 0xbf, 0xdf, 0x83, 0x34, 0x3b, 0x4f, 0x94, 0x3f, 0x37, 0x89, 0xaf, 0x00,
  6836. 0xdf, 0x0f, 0x2e, 0x75, 0x16, 0x41, 0xf6, 0x7a, 0x86, 0x94, 0x9d, 0x32,
  6837. 0x56, 0xf0, 0x79, 0x71, 0x68, 0x6f, 0xa6, 0x6b, 0xc6, 0x59, 0x49, 0xf6,
  6838. 0x10, 0x34, 0x03, 0x03, 0x16, 0x53, 0x9a, 0x98, 0x2a, 0x46, 0xde, 0x17,
  6839. 0x06, 0x65, 0x70, 0xca, 0x0a, 0x1f, 0xab, 0x80, 0x26, 0x96, 0x3f, 0x3e,
  6840. 0x7a, 0x3c, 0xa8, 0x87, 0xbb, 0x65, 0xdd, 0x5e, 0x07, 0x7b, 0x34, 0xe0,
  6841. 0x56, 0xda, 0x32, 0x13, 0x30, 0xc9, 0x0c, 0xd7, 0xba, 0xe4, 0x1f, 0xa6,
  6842. 0x91, 0x4f, 0x72, 0x9f, 0xd9, 0x5c, 0x62, 0x7d, 0xa6, 0xc2, 0xbc, 0x87,
  6843. 0xae, 0x64, 0x11, 0x94, 0x3b, 0xbc, 0x6c, 0x23, 0xbd, 0x7d, 0x00, 0xb4,
  6844. 0x99, 0xf2, 0x68, 0xb5, 0x59, 0x70, 0x93, 0xad, 0x69, 0xd0, 0xb1, 0x28,
  6845. 0x70, 0x92, 0xeb, 0xec, 0x39, 0x80, 0x82, 0xde, 0x44, 0xe2, 0x8a, 0x26,
  6846. 0xb3, 0xe9, 0x45, 0xcf, 0x83, 0x76, 0x9f, 0x6a, 0xa0, 0x46, 0x4a, 0x3d,
  6847. 0x26, 0x56, 0xaf, 0x49, 0x41, 0x26, 0x1b, 0x6a, 0x41, 0x37, 0x65, 0x91,
  6848. 0x72, 0xc4, 0xe7, 0x3c, 0x17, 0x31, 0xae, 0x2e, 0x2b, 0x31, 0x45, 0xe4,
  6849. 0x93, 0xd3, 0x10, 0xaa, 0xc5, 0x62, 0xd5, 0x11, 0x4b, 0x57, 0x1d, 0xad,
  6850. 0x48, 0x06, 0xd0, 0x0d, 0x98, 0xa5, 0xc6, 0x5b, 0xd0, 0x9e, 0x22, 0xc0,
  6851. 0x00, 0x32, 0x5a, 0xf5, 0x1c, 0x89, 0x6d, 0x54, 0x97, 0x55, 0x6b, 0x46,
  6852. 0xc5, 0xc7, 0xc4, 0x48, 0x9c, 0xbf, 0x47, 0xdc, 0x03, 0xc4, 0x1b, 0xcb,
  6853. 0x65, 0xa6, 0x91, 0x9d, 0x6d, 0xf1, 0xb0, 0x7a, 0x4d, 0x3b, 0x03, 0x95,
  6854. 0xf4, 0x8b, 0x0b, 0xae, 0x39, 0xff, 0x3f, 0xf6, 0xc0, 0x14, 0x18, 0x8a,
  6855. 0xe5, 0x19, 0xbd, 0xc1, 0xb4, 0x05, 0x4e, 0x29, 0x2f, 0x0b, 0x33, 0x76,
  6856. 0x28, 0x16, 0xa4, 0xa6, 0x93, 0x04, 0xb5, 0x55, 0x6b, 0x89, 0x3d, 0xa5,
  6857. 0x0f, 0xd3, 0xad, 0xfa, 0xd9, 0xfd, 0x05, 0x5d, 0x48, 0x94, 0x25, 0x5a,
  6858. 0x2c, 0x9a, 0x94, 0x80, 0xb0, 0xe7, 0xcb, 0x4d, 0x77, 0xbf, 0xca, 0xd8,
  6859. 0x55, 0x48, 0xbd, 0x66, 0xb1, 0x85, 0x81, 0xb1, 0x37, 0x79, 0xab, 0x52,
  6860. 0x08, 0x14, 0x12, 0xac, 0xcd, 0x45, 0x4d, 0x53, 0x6b, 0xca, 0x96, 0xc7,
  6861. 0x3b, 0x2f, 0x73, 0xb1, 0x5a, 0x23, 0xbd, 0x65, 0xd5, 0xea, 0x17, 0xb3,
  6862. 0xdc, 0xa1, 0x17, 0x1b, 0x2d, 0xb3, 0x9c, 0xd0, 0xdb, 0x41, 0x77, 0xef,
  6863. 0x93, 0x20, 0x52, 0x3e, 0x9d, 0xf5, 0xbf, 0x33, 0xf7, 0x52, 0xc1, 0x90,
  6864. 0xa0, 0x15, 0x17, 0xce, 0xf7, 0xf7, 0xd0, 0x3a, 0x3b, 0xd1, 0x72, 0x56,
  6865. 0x31, 0x81, 0xae, 0x60, 0xab, 0x40, 0xc1, 0xd1, 0x28, 0x77, 0x53, 0xac,
  6866. 0x9f, 0x11, 0x0a, 0x88, 0x36, 0x4b, 0xda, 0x57, 0xa7, 0x28, 0x5c, 0x85,
  6867. 0xd3, 0x85, 0x9b, 0x79, 0xad, 0x05, 0x1c, 0x37, 0x14, 0x5e, 0x0d, 0xd0,
  6868. 0x23, 0x03, 0x42, 0x1d, 0x48, 0x5d, 0xc5, 0x3c, 0x5a, 0x08, 0xa9, 0x0d,
  6869. 0x6e, 0x82, 0x7c, 0x2e, 0x3c, 0x41, 0xcc, 0x96, 0x8e, 0xad, 0xee, 0x2a,
  6870. 0x61, 0x0b, 0x16, 0x0f, 0xa9, 0x24, 0x40, 0x85, 0xbc, 0x9f, 0x28, 0x8d,
  6871. 0xe6, 0x68, 0x4d, 0x8f, 0x30, 0x48, 0xd9, 0x73, 0x73, 0x6c, 0x9a, 0x7f,
  6872. 0x67, 0xf7, 0xde, 0x4c, 0x0a, 0x8b, 0xe4, 0xb3, 0x08, 0x2a, 0x52, 0xda,
  6873. 0x54, 0xee, 0xcd, 0xb5, 0x62, 0x4a, 0x26, 0x20, 0xfb, 0x40, 0xbb, 0x39,
  6874. 0x3a, 0x0f, 0x09, 0xe8, 0x00, 0xd1, 0x24, 0x97, 0x60, 0xe9, 0x83, 0x83,
  6875. 0xfe, 0x9f, 0x9c, 0x15, 0xcf, 0x69, 0x03, 0x9f, 0x03, 0xe1, 0xe8, 0x6e,
  6876. 0xbd, 0x87, 0x58, 0x68, 0xee, 0xec, 0xd8, 0x29, 0x46, 0x23, 0x49, 0x92,
  6877. 0x72, 0x95, 0x5b, 0x49, 0xca, 0xe0, 0x45, 0x59, 0xb2, 0xca, 0xf4, 0xfc,
  6878. 0xb7, 0x59, 0x37, 0x49, 0x28, 0xbc, 0xf3, 0xd7, 0x61, 0xbc, 0x4b, 0xf3,
  6879. 0xa9, 0x4b, 0x2f, 0x05, 0xa8, 0x01, 0xa5, 0xdc, 0x00, 0x6e, 0x01, 0xb6,
  6880. 0x45, 0x3c, 0xd5, 0x49, 0x7d, 0x5c, 0x25, 0xe8, 0x31, 0x87, 0xb2, 0xb9,
  6881. 0xbf, 0xb3, 0x01, 0x62, 0x0c, 0xd0, 0x48, 0x77, 0xa2, 0x34, 0x0f, 0x16,
  6882. 0x22, 0x28, 0xee, 0x54, 0x08, 0x93, 0x3b, 0xe4, 0xde, 0x7e, 0x63, 0xf7,
  6883. 0x97, 0x16, 0x5d, 0x71, 0x58, 0xc2, 0x2e, 0xf2, 0x36, 0xa6, 0x12, 0x65,
  6884. 0x94, 0x17, 0xac, 0x66, 0x23, 0x7e, 0xc6, 0x72, 0x79, 0x24, 0xce, 0x8f,
  6885. 0x55, 0x19, 0x97, 0x44, 0xfc, 0x55, 0xec, 0x85, 0x26, 0x27, 0xdb, 0x38,
  6886. 0xb1, 0x42, 0x0a, 0xdd, 0x05, 0x99, 0x28, 0xeb, 0x03, 0x6c, 0x9a, 0xe9,
  6887. 0x17, 0xf6, 0x2c, 0xb0, 0xfe, 0xe7, 0xa4, 0xa7, 0x31, 0xda, 0x4d, 0xb0,
  6888. 0x29, 0xdb, 0xdd, 0x8d, 0x12, 0x13, 0x9c, 0xb4, 0xcc, 0x83, 0x97, 0xfb,
  6889. 0x1a, 0xdc, 0x08, 0xd6, 0x30, 0x62, 0xe8, 0xeb, 0x8b, 0x61, 0xcb, 0x1d,
  6890. 0x06, 0xe3, 0xa5, 0x4d, 0x35, 0xdb, 0x59, 0xa8, 0x2d, 0x87, 0x27, 0x44,
  6891. 0x6f, 0xc0, 0x38, 0x97, 0xe4, 0x85, 0x00, 0x02, 0x09, 0xf6, 0x69, 0x3a,
  6892. 0xcf, 0x08, 0x1b, 0x21, 0xbb, 0x79, 0xb1, 0xa1, 0x34, 0x09, 0xe0, 0x80,
  6893. 0xca, 0xb0, 0x78, 0x8a, 0x11, 0x97, 0xd4, 0x07, 0xbe, 0x1b, 0x6a, 0x5d,
  6894. 0xdb, 0xd6, 0x1f, 0x76, 0x6b, 0x16, 0xf0, 0x58, 0x84, 0x5f, 0x59, 0xce,
  6895. 0x62, 0x34, 0xc3, 0xdf, 0x94, 0xb8, 0x2f, 0x84, 0x68, 0xf0, 0xb8, 0x51,
  6896. 0xd9, 0x6d, 0x8e, 0x4a, 0x1d, 0xe6, 0x5c, 0xd8, 0x86, 0x25, 0xe3, 0x24,
  6897. 0xfd, 0x21, 0x61, 0x13, 0x48, 0x3e, 0xf6, 0x7d, 0xa6, 0x71, 0x9b, 0xd2,
  6898. 0x6e, 0xe6, 0xd2, 0x08, 0x94, 0x62, 0x6c, 0x98, 0xfe, 0x2f, 0x9c, 0x88,
  6899. 0x7e, 0x78, 0x15, 0x02, 0x00, 0xf0, 0xba, 0x24, 0x91, 0xf2, 0xdc, 0x47,
  6900. 0x51, 0x4d, 0x15, 0x5e, 0x91, 0x5f, 0x57, 0x5b, 0x1d, 0x35, 0x24, 0x45,
  6901. 0x75, 0x9b, 0x88, 0x75, 0xf1, 0x2f, 0x85, 0xe7, 0x89, 0xd1, 0x01, 0xb4,
  6902. 0xc8, 0x18, 0xb7, 0x97, 0xef, 0x4b, 0x90, 0xf4, 0xbf, 0x10, 0x27, 0x3c,
  6903. 0x60, 0xff, 0xc4, 0x94, 0x20, 0x2f, 0x93, 0x4b, 0x4d, 0xe3, 0x80, 0xf7,
  6904. 0x2c, 0x71, 0xd9, 0xe3, 0x68, 0xb4, 0x77, 0x2b, 0xc7, 0x0d, 0x39, 0x92,
  6905. 0xef, 0x91, 0x0d, 0xb2, 0x11, 0x50, 0x0e, 0xe8, 0xad, 0x3b, 0xf6, 0xb5,
  6906. 0xc6, 0x14, 0x4d, 0x33, 0x53, 0xa7, 0x60, 0x15, 0xc7, 0x27, 0x51, 0xdc,
  6907. 0x54, 0x29, 0xa7, 0x0d, 0x6a, 0x7b, 0x72, 0x13, 0xad, 0x7d, 0x41, 0x19,
  6908. 0x4e, 0x42, 0x49, 0xcc, 0x42, 0xe4, 0xbd, 0x99, 0x13, 0xd9, 0x7f, 0xf3,
  6909. 0x38, 0xa4, 0xb6, 0x33, 0xed, 0x07, 0x48, 0x7e, 0x8e, 0x82, 0xfe, 0x3a,
  6910. 0x9d, 0x75, 0x93, 0xba, 0x25, 0x4e, 0x37, 0x3c, 0x0c, 0xd5, 0x69, 0xa9,
  6911. 0x2d, 0x9e, 0xfd, 0xe8, 0xbb, 0xf5, 0x0c, 0xe2, 0x86, 0xb9, 0x5e, 0x6f,
  6912. 0x28, 0xe4, 0x19, 0xb3, 0x0b, 0xa4, 0x86, 0xd7, 0x24, 0xd0, 0xb8, 0x89,
  6913. 0x7b, 0x76, 0xec, 0x05, 0x10, 0x5b, 0x68, 0xe9, 0x58, 0x66, 0xa3, 0xc5,
  6914. 0xb6, 0x63, 0x20, 0x0e, 0x0e, 0xea, 0x3d, 0x61, 0x5e, 0xda, 0x3d, 0x3c,
  6915. 0xf9, 0xfd, 0xed, 0xa9, 0xdb, 0x52, 0x94, 0x8a, 0x00, 0xca, 0x3c, 0x8d,
  6916. 0x66, 0x8f, 0xb0, 0xf0, 0x5a, 0xca, 0x3f, 0x63, 0x71, 0xbf, 0xca, 0x99,
  6917. 0x37, 0x9b, 0x75, 0x97, 0x89, 0x10, 0x6e, 0xcf, 0xf2, 0xf5, 0xe3, 0xd5,
  6918. 0x45, 0x9b, 0xad, 0x10, 0x71, 0x6c, 0x5f, 0x6f, 0x7f, 0x22, 0x77, 0x18,
  6919. 0x2f, 0xf9, 0x99, 0xc5, 0x69, 0x58, 0x03, 0x12, 0x86, 0x82, 0x3e, 0xbf,
  6920. 0xc2, 0x12, 0x35, 0x43, 0xa3, 0xd9, 0x18, 0x4f, 0x41, 0x11, 0x6b, 0xf3,
  6921. 0x67, 0xaf, 0x3d, 0x78, 0xe4, 0x22, 0x2d, 0xb3, 0x48, 0x43, 0x31, 0x1d,
  6922. 0xef, 0xa8, 0xba, 0x49, 0x8e, 0xa9, 0xa7, 0xb6, 0x18, 0x77, 0x84, 0xca,
  6923. 0xbd, 0xa2, 0x02, 0x1b, 0x6a, 0xf8, 0x5f, 0xda, 0xff, 0xcf, 0x01, 0x6a,
  6924. 0x86, 0x69, 0xa9, 0xe9, 0xcb, 0x60, 0x1e, 0x15, 0xdc, 0x8f, 0x5d, 0x39,
  6925. 0xb5, 0xce, 0x55, 0x5f, 0x47, 0x97, 0xb1, 0x19, 0x6e, 0x21, 0xd6, 0x13,
  6926. 0x39, 0xb2, 0x24, 0xe0, 0x62, 0x82, 0x9f, 0xed, 0x12, 0x81, 0xed, 0xee,
  6927. 0xab, 0xd0, 0x2f, 0x19, 0x89, 0x3f, 0x57, 0x2e, 0xc2, 0xe2, 0x67, 0xe8,
  6928. 0xae, 0x03, 0x56, 0xba, 0xd4, 0xd0, 0xa4, 0x89, 0x03, 0x06, 0x5b, 0xcc,
  6929. 0xf2, 0x22, 0xb8, 0x0e, 0x76, 0x79, 0x4a, 0x42, 0x1d, 0x37, 0x51, 0x5a,
  6930. 0xaa, 0x46, 0x6c, 0x2a, 0xdd, 0x66, 0xfe, 0xc6, 0x68, 0xc3, 0x38, 0xa2,
  6931. 0xae, 0x5b, 0x98, 0x24, 0x5d, 0x43, 0x05, 0x82, 0x38, 0x12, 0xd3, 0xd1,
  6932. 0x75, 0x2d, 0x4f, 0x61, 0xbd, 0xb9, 0x10, 0x87, 0x44, 0x2a, 0x78, 0x07,
  6933. 0xff, 0xf4, 0x0f, 0xa1, 0xf3, 0x68, 0x9f, 0xbe, 0xae, 0xa2, 0x91, 0xf0,
  6934. 0xc7, 0x55, 0x7a, 0x52, 0xd5, 0xa3, 0x8d, 0x6f, 0xe4, 0x90, 0x5c, 0xf3,
  6935. 0x5f, 0xce, 0x3d, 0x23, 0xf9, 0x8e, 0xae, 0x14, 0xfb, 0x82, 0x9a, 0xa3,
  6936. 0x04, 0x5f, 0xbf, 0xad, 0x3e, 0xf2, 0x97, 0x0a, 0x60, 0x40, 0x70, 0x19,
  6937. 0x72, 0xad, 0x66, 0xfb, 0x78, 0x1b, 0x84, 0x6c, 0x98, 0xbc, 0x8c, 0xf8,
  6938. 0x4f, 0xcb, 0xb5, 0xf6, 0xaf, 0x7a, 0xb7, 0x93, 0xef, 0x67, 0x48, 0x02,
  6939. 0x2c, 0xcb, 0xe6, 0x77, 0x0f, 0x7b, 0xc1, 0xee, 0xc5, 0xb6, 0x2d, 0x7e,
  6940. 0x62, 0xa0, 0xc0, 0xa7, 0xa5, 0x80, 0x31, 0x92, 0x50, 0xa1, 0x28, 0x22,
  6941. 0x95, 0x03, 0x17, 0xd1, 0x0f, 0xf6, 0x08, 0xe5, 0xec
  6942. };
  6943. #define CHACHA_BIG_TEST_SIZE 1305
  6944. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  6945. byte cipher_big[CHACHA_BIG_TEST_SIZE] = {0};
  6946. byte plain_big[CHACHA_BIG_TEST_SIZE] = {0};
  6947. byte input_big[CHACHA_BIG_TEST_SIZE] = {0};
  6948. #else
  6949. byte* cipher_big;
  6950. byte* plain_big;
  6951. byte* input_big;
  6952. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6953. int block_size;
  6954. #endif /* BENCH_EMBEDDED */
  6955. byte a[] = {0x76,0xb8,0xe0,0xad,0xa0,0xf1,0x3d,0x90};
  6956. byte b[] = {0x45,0x40,0xf0,0x5a,0x9f,0x1f,0xb2,0x96};
  6957. byte c[] = {0xde,0x9c,0xba,0x7b,0xf3,0xd6,0x9e,0xf5};
  6958. byte d[] = {0x89,0x67,0x09,0x52,0x60,0x83,0x64,0xfd};
  6959. byte* test_chacha[4];
  6960. test_chacha[0] = a;
  6961. test_chacha[1] = b;
  6962. test_chacha[2] = c;
  6963. test_chacha[3] = d;
  6964. WOLFSSL_ENTER("chacha_test");
  6965. #ifndef BENCH_EMBEDDED
  6966. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  6967. cipher_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6968. DYNAMIC_TYPE_TMP_BUFFER);
  6969. if (cipher_big == NULL) {
  6970. return MEMORY_E;
  6971. }
  6972. plain_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6973. DYNAMIC_TYPE_TMP_BUFFER);
  6974. if (plain_big == NULL) {
  6975. return MEMORY_E;
  6976. }
  6977. input_big = (byte*)XMALLOC(CHACHA_BIG_TEST_SIZE, HEAP_HINT,
  6978. DYNAMIC_TYPE_TMP_BUFFER);
  6979. if (input_big == NULL) {
  6980. return MEMORY_E;
  6981. }
  6982. XMEMSET(cipher_big, 0, CHACHA_BIG_TEST_SIZE);
  6983. XMEMSET(plain_big, 0, CHACHA_BIG_TEST_SIZE);
  6984. XMEMSET(input_big, 0, CHACHA_BIG_TEST_SIZE);
  6985. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  6986. #endif /* BENCH_EMBEDDED */
  6987. for (i = 0; i < times; ++i) {
  6988. if (i < 3) {
  6989. keySz = 32;
  6990. }
  6991. else {
  6992. keySz = 16;
  6993. }
  6994. XMEMCPY(plain, keys[i], keySz);
  6995. XMEMSET(cipher, 0, 32);
  6996. XMEMCPY(cipher + 4, ivs[i], 8);
  6997. ret |= wc_Chacha_SetKey(&enc, keys[i], keySz);
  6998. ret |= wc_Chacha_SetKey(&dec, keys[i], keySz);
  6999. if (ret != 0)
  7000. return ret;
  7001. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  7002. ret |= wc_Chacha_SetIV(&dec, cipher, 0);
  7003. if (ret != 0)
  7004. return ret;
  7005. XMEMCPY(plain, input, 8);
  7006. ret |= wc_Chacha_Process(&enc, cipher, plain, (word32)8);
  7007. ret |= wc_Chacha_Process(&dec, plain, cipher, (word32)8);
  7008. if (ret != 0)
  7009. return ret;
  7010. if (XMEMCMP(test_chacha[i], cipher, 8))
  7011. return WC_TEST_RET_ENC_I(i);
  7012. if (XMEMCMP(plain, input, 8))
  7013. return WC_TEST_RET_ENC_I(i);
  7014. }
  7015. /* test of starting at a different counter
  7016. encrypts all of the information and decrypts starting at 2nd chunk */
  7017. XMEMSET(plain, 0, sizeof(plain));
  7018. XMEMSET(sliver, 1, sizeof(sliver)); /* set as 1's to not match plain */
  7019. XMEMSET(cipher, 0, sizeof(cipher));
  7020. XMEMCPY(cipher + 4, ivs[0], 8);
  7021. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7022. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7023. if (ret != 0)
  7024. return ret;
  7025. ret |= wc_Chacha_SetIV(&enc, cipher, 0);
  7026. ret |= wc_Chacha_SetIV(&dec, cipher, 1);
  7027. if (ret != 0)
  7028. return ret;
  7029. ret |= wc_Chacha_Process(&enc, cipher, plain, sizeof(plain));
  7030. ret |= wc_Chacha_Process(&dec, sliver, cipher + 64, sizeof(sliver));
  7031. if (ret != 0)
  7032. return ret;
  7033. if (XMEMCMP(plain + 64, sliver, 64))
  7034. return WC_TEST_RET_ENC_NC;
  7035. #ifndef BENCH_EMBEDDED
  7036. /* test of encrypting more data */
  7037. keySz = 32;
  7038. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7039. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7040. if (ret != 0)
  7041. return ret;
  7042. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  7043. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  7044. if (ret != 0)
  7045. return ret;
  7046. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big, CHACHA_BIG_TEST_SIZE);
  7047. ret |= wc_Chacha_Process(&dec, plain_big, cipher_big,
  7048. CHACHA_BIG_TEST_SIZE);
  7049. if (ret != 0)
  7050. return ret;
  7051. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  7052. return WC_TEST_RET_ENC_NC;
  7053. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  7054. return WC_TEST_RET_ENC_NC;
  7055. for (i = 0; i < 18; ++i) {
  7056. /* this will test all paths
  7057. * block sizes: 1 3 7 15 31 63 127 255 511 (i = 0- 8)
  7058. * 2 4 8 16 32 64 128 256 512 (i = 9-17)
  7059. */
  7060. block_size = (2 << (i%9)) - (i<9?1:0);
  7061. keySz = 32;
  7062. ret |= wc_Chacha_SetKey(&enc, keys[0], keySz);
  7063. ret |= wc_Chacha_SetKey(&dec, keys[0], keySz);
  7064. if (ret != 0)
  7065. return ret;
  7066. ret |= wc_Chacha_SetIV(&enc, ivs[2], 0);
  7067. ret |= wc_Chacha_SetIV(&dec, ivs[2], 0);
  7068. if (ret != 0)
  7069. return ret;
  7070. ret |= wc_Chacha_Process(&enc, cipher_big, plain_big , (word32)block_size);
  7071. ret |= wc_Chacha_Process(&dec, plain_big , cipher_big, (word32)block_size);
  7072. if (ret != 0)
  7073. return ret;
  7074. if (XMEMCMP(plain_big, input_big, (word32)block_size))
  7075. return WC_TEST_RET_ENC_I(i);
  7076. if (XMEMCMP(cipher_big, cipher_big_result, (word32)block_size))
  7077. return WC_TEST_RET_ENC_I(i);
  7078. }
  7079. /* Streaming test */
  7080. for (i = 1; i <= (int)CHACHA_CHUNK_BYTES + 1; i++) {
  7081. int j, rem;
  7082. ret = wc_Chacha_SetKey(&enc, keys[0], keySz);
  7083. if (ret != 0)
  7084. return WC_TEST_RET_ENC_EC(ret);
  7085. ret = wc_Chacha_SetKey(&dec, keys[0], keySz);
  7086. if (ret != 0)
  7087. return WC_TEST_RET_ENC_EC(ret);
  7088. ret = wc_Chacha_SetIV(&enc, ivs[2], 0);
  7089. if (ret != 0)
  7090. return WC_TEST_RET_ENC_EC(ret);
  7091. ret = wc_Chacha_SetIV(&dec, ivs[2], 0);
  7092. if (ret != 0)
  7093. return WC_TEST_RET_ENC_EC(ret);
  7094. for (j = 0; j < CHACHA_BIG_TEST_SIZE - i; j+= i) {
  7095. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)i);
  7096. if (ret != 0)
  7097. return WC_TEST_RET_ENC_EC(ret);
  7098. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)i);
  7099. if (ret != 0)
  7100. return WC_TEST_RET_ENC_EC(ret);
  7101. }
  7102. rem = CHACHA_BIG_TEST_SIZE - j;
  7103. ret = wc_Chacha_Process(&enc, cipher_big + j, plain_big + j, (word32)rem);
  7104. if (ret != 0)
  7105. return WC_TEST_RET_ENC_EC(ret);
  7106. ret = wc_Chacha_Process(&dec, plain_big + j, cipher_big + j, (word32)rem);
  7107. if (ret != 0)
  7108. return WC_TEST_RET_ENC_EC(ret);
  7109. if (XMEMCMP(plain_big, input_big, CHACHA_BIG_TEST_SIZE))
  7110. return WC_TEST_RET_ENC_I(i);
  7111. if (XMEMCMP(cipher_big, cipher_big_result, CHACHA_BIG_TEST_SIZE))
  7112. return WC_TEST_RET_ENC_I(i);
  7113. }
  7114. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  7115. XFREE(cipher_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7116. XFREE(plain_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7117. XFREE(input_big, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  7118. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  7119. #endif /* BENCH_EMBEDDED */
  7120. return 0;
  7121. }
  7122. #endif /* HAVE_CHACHA */
  7123. #ifdef HAVE_POLY1305
  7124. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t poly1305_test(void)
  7125. {
  7126. byte tag[16];
  7127. Poly1305 enc;
  7128. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {
  7129. 0x43,0x72,0x79,0x70,0x74,0x6f,0x67,0x72,
  7130. 0x61,0x70,0x68,0x69,0x63,0x20,0x46,0x6f,
  7131. 0x72,0x75,0x6d,0x20,0x52,0x65,0x73,0x65,
  7132. 0x61,0x72,0x63,0x68,0x20,0x47,0x72,0x6f,
  7133. 0x75,0x70
  7134. };
  7135. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {
  7136. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x77,0x6f,0x72,
  7137. 0x6c,0x64,0x21
  7138. };
  7139. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {
  7140. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7141. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7142. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7143. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7144. };
  7145. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  7146. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7147. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7148. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7149. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7150. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7151. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7152. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7153. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7154. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7155. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7156. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7157. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7158. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7159. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7160. 0x61,0x16
  7161. };
  7162. WOLFSSL_SMALL_STACK_STATIC const byte msg5[] = {
  7163. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7164. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7165. };
  7166. WOLFSSL_SMALL_STACK_STATIC const byte msg6[] = {
  7167. 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,
  7168. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7169. 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,
  7170. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7171. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7172. 0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b,
  7173. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7174. 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,
  7175. 0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6,
  7176. 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,
  7177. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7178. 0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36,
  7179. 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,
  7180. 0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2,
  7181. 0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58,
  7182. 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,
  7183. 0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc,
  7184. 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,
  7185. 0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b,
  7186. 0x61,0x16
  7187. };
  7188. WOLFSSL_SMALL_STACK_STATIC const byte msg7[] = {
  7189. 0xe8,0x8c,0x85,0x03,0x43,0xaf,0xa7,0x85,
  7190. 0x21,0x6b,0xc3,0x45,0xc4,0x53,0x98,0xf8,
  7191. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7192. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7193. };
  7194. byte additional[] = {
  7195. 0x50,0x51,0x52,0x53,0xc0,0xc1,0xc2,0xc3,
  7196. 0xc4,0xc5,0xc6,0xc7
  7197. };
  7198. WOLFSSL_SMALL_STACK_STATIC const byte correct0[] = {
  7199. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7200. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7201. };
  7202. WOLFSSL_SMALL_STACK_STATIC const byte correct1[] = {
  7203. 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,
  7204. 0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9
  7205. };
  7206. WOLFSSL_SMALL_STACK_STATIC const byte correct2[] = {
  7207. 0xa6,0xf7,0x45,0x00,0x8f,0x81,0xc9,0x16,
  7208. 0xa2,0x0d,0xcc,0x74,0xee,0xf2,0xb2,0xf0
  7209. };
  7210. WOLFSSL_SMALL_STACK_STATIC const byte correct3[] = {
  7211. 0x49,0xec,0x78,0x09,0x0e,0x48,0x1e,0xc6,
  7212. 0xc2,0x6b,0x33,0xb9,0x1c,0xcc,0x03,0x07
  7213. };
  7214. WOLFSSL_SMALL_STACK_STATIC const byte correct4[] = {
  7215. 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,
  7216. 0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91
  7217. };
  7218. WOLFSSL_SMALL_STACK_STATIC const byte correct5[] = {
  7219. 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7220. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7221. };
  7222. WOLFSSL_SMALL_STACK_STATIC const byte correct6[] = {
  7223. 0xea,0x11,0x5c,0x4f,0xd0,0xc0,0x10,0xae,
  7224. 0xf7,0xdf,0xda,0x77,0xa2,0xe9,0xaf,0xca
  7225. };
  7226. WOLFSSL_SMALL_STACK_STATIC const byte correct7[] = {
  7227. 0x14,0x00,0x00,0x88,0x5c,0x00,0x00,0x88,
  7228. 0x5c,0x00,0x00,0x88,0x5c,0x00,0x00,0x88
  7229. };
  7230. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7231. 0x85,0xd6,0xbe,0x78,0x57,0x55,0x6d,0x33,
  7232. 0x7f,0x44,0x52,0xfe,0x42,0xd5,0x06,0xa8,
  7233. 0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,
  7234. 0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b
  7235. };
  7236. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7237. 0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,
  7238. 0x33,0x32,0x2d,0x62,0x79,0x74,0x65,0x20,
  7239. 0x6b,0x65,0x79,0x20,0x66,0x6f,0x72,0x20,
  7240. 0x50,0x6f,0x6c,0x79,0x31,0x33,0x30,0x35
  7241. };
  7242. WOLFSSL_SMALL_STACK_STATIC const byte key4[] = {
  7243. 0x7b,0xac,0x2b,0x25,0x2d,0xb4,0x47,0xaf,
  7244. 0x09,0xb6,0x7a,0x55,0xa4,0xe9,0x55,0x84,
  7245. 0x0a,0xe1,0xd6,0x73,0x10,0x75,0xd9,0xeb,
  7246. 0x2a,0x93,0x75,0x78,0x3e,0xd5,0x53,0xff
  7247. };
  7248. WOLFSSL_SMALL_STACK_STATIC const byte key5[] = {
  7249. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7250. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7251. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  7252. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  7253. };
  7254. WOLFSSL_SMALL_STACK_STATIC const byte key7[] = {
  7255. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7256. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7257. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  7258. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  7259. };
  7260. const byte* msgs[] = {NULL, msg1, msg2, msg3, msg5, msg6, msg7};
  7261. word32 szm[] = {0, sizeof(msg1), sizeof(msg2),
  7262. sizeof(msg3), sizeof(msg5), sizeof(msg6),
  7263. sizeof(msg7)};
  7264. const byte* keys[] = {key, key, key2, key2, key5, key, key7};
  7265. const byte* tests[] = {correct0, correct1, correct2, correct3, correct5,
  7266. correct6, correct7};
  7267. int i;
  7268. wc_test_ret_t ret = 0;
  7269. WOLFSSL_ENTER("poly1305_test");
  7270. for (i = 0; i < 7; i++) {
  7271. ret = wc_Poly1305SetKey(&enc, keys[i], 32);
  7272. if (ret != 0)
  7273. return WC_TEST_RET_ENC_I(i);
  7274. ret = wc_Poly1305Update(&enc, msgs[i], szm[i]);
  7275. if (ret != 0)
  7276. return WC_TEST_RET_ENC_I(i);
  7277. ret = wc_Poly1305Final(&enc, tag);
  7278. if (ret != 0)
  7279. return WC_TEST_RET_ENC_I(i);
  7280. if (XMEMCMP(tag, tests[i], sizeof(tag)))
  7281. return WC_TEST_RET_ENC_I(i);
  7282. }
  7283. /* Check TLS MAC function from 2.8.2 https://tools.ietf.org/html/rfc7539 */
  7284. XMEMSET(tag, 0, sizeof(tag));
  7285. ret = wc_Poly1305SetKey(&enc, key4, sizeof(key4));
  7286. if (ret != 0)
  7287. return WC_TEST_RET_ENC_EC(ret);
  7288. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7289. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7290. if (ret != 0)
  7291. return WC_TEST_RET_ENC_EC(ret);
  7292. if (XMEMCMP(tag, correct4, sizeof(tag)))
  7293. return WC_TEST_RET_ENC_NC;
  7294. /* Check fail of TLS MAC function if altering additional data */
  7295. XMEMSET(tag, 0, sizeof(tag));
  7296. additional[0]++;
  7297. ret = wc_Poly1305_MAC(&enc, additional, sizeof(additional),
  7298. (byte*)msg4, sizeof(msg4), tag, sizeof(tag));
  7299. if (ret != 0)
  7300. return WC_TEST_RET_ENC_EC(ret);
  7301. if (XMEMCMP(tag, correct4, sizeof(tag)) == 0)
  7302. return WC_TEST_RET_ENC_NC;
  7303. return 0;
  7304. }
  7305. #endif /* HAVE_POLY1305 */
  7306. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  7307. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t chacha20_poly1305_aead_test(void)
  7308. {
  7309. /* Test #1 from Section 2.8.2 of draft-irtf-cfrg-chacha20-poly1305-10 */
  7310. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7311. WOLFSSL_SMALL_STACK_STATIC const byte key1[] = {
  7312. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  7313. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  7314. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  7315. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  7316. };
  7317. WOLFSSL_SMALL_STACK_STATIC const byte plaintext1[] = {
  7318. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61,
  7319. 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c,
  7320. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20,
  7321. 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73,
  7322. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39,
  7323. 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63,
  7324. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66,
  7325. 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f,
  7326. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20,
  7327. 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20,
  7328. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75,
  7329. 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73,
  7330. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f,
  7331. 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69,
  7332. 0x74, 0x2e
  7333. };
  7334. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] = {
  7335. 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43,
  7336. 0x44, 0x45, 0x46, 0x47
  7337. };
  7338. WOLFSSL_SMALL_STACK_STATIC const byte aad1[] = { /* additional data */
  7339. 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3,
  7340. 0xc4, 0xc5, 0xc6, 0xc7
  7341. };
  7342. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] = { /* expected output from operation */
  7343. 0xd3, 0x1a, 0x8d, 0x34, 0x64, 0x8e, 0x60, 0xdb,
  7344. 0x7b, 0x86, 0xaf, 0xbc, 0x53, 0xef, 0x7e, 0xc2,
  7345. 0xa4, 0xad, 0xed, 0x51, 0x29, 0x6e, 0x08, 0xfe,
  7346. 0xa9, 0xe2, 0xb5, 0xa7, 0x36, 0xee, 0x62, 0xd6,
  7347. 0x3d, 0xbe, 0xa4, 0x5e, 0x8c, 0xa9, 0x67, 0x12,
  7348. 0x82, 0xfa, 0xfb, 0x69, 0xda, 0x92, 0x72, 0x8b,
  7349. 0x1a, 0x71, 0xde, 0x0a, 0x9e, 0x06, 0x0b, 0x29,
  7350. 0x05, 0xd6, 0xa5, 0xb6, 0x7e, 0xcd, 0x3b, 0x36,
  7351. 0x92, 0xdd, 0xbd, 0x7f, 0x2d, 0x77, 0x8b, 0x8c,
  7352. 0x98, 0x03, 0xae, 0xe3, 0x28, 0x09, 0x1b, 0x58,
  7353. 0xfa, 0xb3, 0x24, 0xe4, 0xfa, 0xd6, 0x75, 0x94,
  7354. 0x55, 0x85, 0x80, 0x8b, 0x48, 0x31, 0xd7, 0xbc,
  7355. 0x3f, 0xf4, 0xde, 0xf0, 0x8e, 0x4b, 0x7a, 0x9d,
  7356. 0xe5, 0x76, 0xd2, 0x65, 0x86, 0xce, 0xc6, 0x4b,
  7357. 0x61, 0x16
  7358. };
  7359. WOLFSSL_SMALL_STACK_STATIC const byte authTag1[] = { /* expected output from operation */
  7360. 0x1a, 0xe1, 0x0b, 0x59, 0x4f, 0x09, 0xe2, 0x6a,
  7361. 0x7e, 0x90, 0x2e, 0xcb, 0xd0, 0x60, 0x06, 0x91
  7362. };
  7363. /* Test #2 from Appendix A.2 in draft-irtf-cfrg-chacha20-poly1305-10 */
  7364. /* https://tools.ietf.org/html/draft-irtf-cfrg-chacha20-poly1305-10 */
  7365. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  7366. 0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
  7367. 0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
  7368. 0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
  7369. 0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0
  7370. };
  7371. WOLFSSL_SMALL_STACK_STATIC const byte plaintext2[] = {
  7372. 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
  7373. 0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20,
  7374. 0x61, 0x72, 0x65, 0x20, 0x64, 0x72, 0x61, 0x66,
  7375. 0x74, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7376. 0x6e, 0x74, 0x73, 0x20, 0x76, 0x61, 0x6c, 0x69,
  7377. 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x61, 0x20,
  7378. 0x6d, 0x61, 0x78, 0x69, 0x6d, 0x75, 0x6d, 0x20,
  7379. 0x6f, 0x66, 0x20, 0x73, 0x69, 0x78, 0x20, 0x6d,
  7380. 0x6f, 0x6e, 0x74, 0x68, 0x73, 0x20, 0x61, 0x6e,
  7381. 0x64, 0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65,
  7382. 0x20, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
  7383. 0x2c, 0x20, 0x72, 0x65, 0x70, 0x6c, 0x61, 0x63,
  7384. 0x65, 0x64, 0x2c, 0x20, 0x6f, 0x72, 0x20, 0x6f,
  7385. 0x62, 0x73, 0x6f, 0x6c, 0x65, 0x74, 0x65, 0x64,
  7386. 0x20, 0x62, 0x79, 0x20, 0x6f, 0x74, 0x68, 0x65,
  7387. 0x72, 0x20, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65,
  7388. 0x6e, 0x74, 0x73, 0x20, 0x61, 0x74, 0x20, 0x61,
  7389. 0x6e, 0x79, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x2e,
  7390. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x69,
  7391. 0x6e, 0x61, 0x70, 0x70, 0x72, 0x6f, 0x70, 0x72,
  7392. 0x69, 0x61, 0x74, 0x65, 0x20, 0x74, 0x6f, 0x20,
  7393. 0x75, 0x73, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65,
  7394. 0x72, 0x6e, 0x65, 0x74, 0x2d, 0x44, 0x72, 0x61,
  7395. 0x66, 0x74, 0x73, 0x20, 0x61, 0x73, 0x20, 0x72,
  7396. 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
  7397. 0x20, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61,
  7398. 0x6c, 0x20, 0x6f, 0x72, 0x20, 0x74, 0x6f, 0x20,
  7399. 0x63, 0x69, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65,
  7400. 0x6d, 0x20, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x20,
  7401. 0x74, 0x68, 0x61, 0x6e, 0x20, 0x61, 0x73, 0x20,
  7402. 0x2f, 0xe2, 0x80, 0x9c, 0x77, 0x6f, 0x72, 0x6b,
  7403. 0x20, 0x69, 0x6e, 0x20, 0x70, 0x72, 0x6f, 0x67,
  7404. 0x72, 0x65, 0x73, 0x73, 0x2e, 0x2f, 0xe2, 0x80,
  7405. 0x9d
  7406. };
  7407. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  7408. 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04,
  7409. 0x05, 0x06, 0x07, 0x08
  7410. };
  7411. WOLFSSL_SMALL_STACK_STATIC const byte aad2[] = { /* additional data */
  7412. 0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00,
  7413. 0x00, 0x00, 0x4e, 0x91
  7414. };
  7415. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] = { /* expected output from operation */
  7416. 0x64, 0xa0, 0x86, 0x15, 0x75, 0x86, 0x1a, 0xf4,
  7417. 0x60, 0xf0, 0x62, 0xc7, 0x9b, 0xe6, 0x43, 0xbd,
  7418. 0x5e, 0x80, 0x5c, 0xfd, 0x34, 0x5c, 0xf3, 0x89,
  7419. 0xf1, 0x08, 0x67, 0x0a, 0xc7, 0x6c, 0x8c, 0xb2,
  7420. 0x4c, 0x6c, 0xfc, 0x18, 0x75, 0x5d, 0x43, 0xee,
  7421. 0xa0, 0x9e, 0xe9, 0x4e, 0x38, 0x2d, 0x26, 0xb0,
  7422. 0xbd, 0xb7, 0xb7, 0x3c, 0x32, 0x1b, 0x01, 0x00,
  7423. 0xd4, 0xf0, 0x3b, 0x7f, 0x35, 0x58, 0x94, 0xcf,
  7424. 0x33, 0x2f, 0x83, 0x0e, 0x71, 0x0b, 0x97, 0xce,
  7425. 0x98, 0xc8, 0xa8, 0x4a, 0xbd, 0x0b, 0x94, 0x81,
  7426. 0x14, 0xad, 0x17, 0x6e, 0x00, 0x8d, 0x33, 0xbd,
  7427. 0x60, 0xf9, 0x82, 0xb1, 0xff, 0x37, 0xc8, 0x55,
  7428. 0x97, 0x97, 0xa0, 0x6e, 0xf4, 0xf0, 0xef, 0x61,
  7429. 0xc1, 0x86, 0x32, 0x4e, 0x2b, 0x35, 0x06, 0x38,
  7430. 0x36, 0x06, 0x90, 0x7b, 0x6a, 0x7c, 0x02, 0xb0,
  7431. 0xf9, 0xf6, 0x15, 0x7b, 0x53, 0xc8, 0x67, 0xe4,
  7432. 0xb9, 0x16, 0x6c, 0x76, 0x7b, 0x80, 0x4d, 0x46,
  7433. 0xa5, 0x9b, 0x52, 0x16, 0xcd, 0xe7, 0xa4, 0xe9,
  7434. 0x90, 0x40, 0xc5, 0xa4, 0x04, 0x33, 0x22, 0x5e,
  7435. 0xe2, 0x82, 0xa1, 0xb0, 0xa0, 0x6c, 0x52, 0x3e,
  7436. 0xaf, 0x45, 0x34, 0xd7, 0xf8, 0x3f, 0xa1, 0x15,
  7437. 0x5b, 0x00, 0x47, 0x71, 0x8c, 0xbc, 0x54, 0x6a,
  7438. 0x0d, 0x07, 0x2b, 0x04, 0xb3, 0x56, 0x4e, 0xea,
  7439. 0x1b, 0x42, 0x22, 0x73, 0xf5, 0x48, 0x27, 0x1a,
  7440. 0x0b, 0xb2, 0x31, 0x60, 0x53, 0xfa, 0x76, 0x99,
  7441. 0x19, 0x55, 0xeb, 0xd6, 0x31, 0x59, 0x43, 0x4e,
  7442. 0xce, 0xbb, 0x4e, 0x46, 0x6d, 0xae, 0x5a, 0x10,
  7443. 0x73, 0xa6, 0x72, 0x76, 0x27, 0x09, 0x7a, 0x10,
  7444. 0x49, 0xe6, 0x17, 0xd9, 0x1d, 0x36, 0x10, 0x94,
  7445. 0xfa, 0x68, 0xf0, 0xff, 0x77, 0x98, 0x71, 0x30,
  7446. 0x30, 0x5b, 0xea, 0xba, 0x2e, 0xda, 0x04, 0xdf,
  7447. 0x99, 0x7b, 0x71, 0x4d, 0x6c, 0x6f, 0x2c, 0x29,
  7448. 0xa6, 0xad, 0x5c, 0xb4, 0x02, 0x2b, 0x02, 0x70,
  7449. 0x9b
  7450. };
  7451. WOLFSSL_SMALL_STACK_STATIC const byte authTag2[] = { /* expected output from operation */
  7452. 0xee, 0xad, 0x9d, 0x67, 0x89, 0x0c, 0xbb, 0x22,
  7453. 0x39, 0x23, 0x36, 0xfe, 0xa1, 0x85, 0x1f, 0x38
  7454. };
  7455. byte generatedCiphertext[265]; /* max plaintext2/cipher2 */
  7456. byte generatedPlaintext[265]; /* max plaintext2/cipher2 */
  7457. byte generatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
  7458. ChaChaPoly_Aead aead;
  7459. #if !defined(USE_INTEL_CHACHA_SPEEDUP) && !defined(WOLFSSL_ARMASM)
  7460. #define TEST_SMALL_CHACHA_CHUNKS 32
  7461. #else
  7462. #define TEST_SMALL_CHACHA_CHUNKS 64
  7463. #endif
  7464. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7465. word32 testLen;
  7466. #endif
  7467. wc_test_ret_t err;
  7468. WOLFSSL_ENTER("chacha20_poly1305_aead_test");
  7469. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7470. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7471. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7472. /* Parameter Validation testing */
  7473. /* Encrypt */
  7474. err = wc_ChaCha20Poly1305_Encrypt(NULL, iv1, aad1, sizeof(aad1), plaintext1,
  7475. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7476. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7477. return WC_TEST_RET_ENC_EC(err);
  7478. err = wc_ChaCha20Poly1305_Encrypt(key1, NULL, aad1, sizeof(aad1),
  7479. plaintext1, sizeof(plaintext1), generatedCiphertext,
  7480. generatedAuthTag);
  7481. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7482. return WC_TEST_RET_ENC_EC(err);
  7483. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7484. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7485. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7486. return WC_TEST_RET_ENC_EC(err);
  7487. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7488. sizeof(plaintext1), NULL, generatedAuthTag);
  7489. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7490. return WC_TEST_RET_ENC_EC(err);
  7491. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), plaintext1,
  7492. sizeof(plaintext1), generatedCiphertext, NULL);
  7493. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7494. return WC_TEST_RET_ENC_EC(err);
  7495. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1, aad1, sizeof(aad1), NULL,
  7496. sizeof(plaintext1), generatedCiphertext, generatedAuthTag);
  7497. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7498. return WC_TEST_RET_ENC_EC(err);
  7499. /* Decrypt */
  7500. err = wc_ChaCha20Poly1305_Decrypt(NULL, iv2, aad2, sizeof(aad2), cipher2,
  7501. sizeof(cipher2), authTag2, generatedPlaintext);
  7502. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7503. return WC_TEST_RET_ENC_EC(err);
  7504. err = wc_ChaCha20Poly1305_Decrypt(key2, NULL, aad2, sizeof(aad2), cipher2,
  7505. sizeof(cipher2), authTag2, generatedPlaintext);
  7506. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7507. return WC_TEST_RET_ENC_EC(err);
  7508. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7509. sizeof(cipher2), authTag2, generatedPlaintext);
  7510. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7511. return WC_TEST_RET_ENC_EC(err);
  7512. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7513. sizeof(cipher2), NULL, generatedPlaintext);
  7514. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7515. return WC_TEST_RET_ENC_EC(err);
  7516. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), cipher2,
  7517. sizeof(cipher2), authTag2, NULL);
  7518. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7519. return WC_TEST_RET_ENC_EC(err);
  7520. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2, aad2, sizeof(aad2), NULL,
  7521. sizeof(cipher2), authTag2, generatedPlaintext);
  7522. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7523. return WC_TEST_RET_ENC_EC(err);
  7524. /* Test #1 */
  7525. err = wc_ChaCha20Poly1305_Encrypt(key1, iv1,
  7526. aad1, sizeof(aad1),
  7527. plaintext1, sizeof(plaintext1),
  7528. generatedCiphertext, generatedAuthTag);
  7529. if (err) {
  7530. return WC_TEST_RET_ENC_EC(err);
  7531. }
  7532. /* -- Check the ciphertext and authtag */
  7533. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7534. return WC_TEST_RET_ENC_NC;
  7535. }
  7536. if (XMEMCMP(generatedAuthTag, authTag1, sizeof(authTag1))) {
  7537. return WC_TEST_RET_ENC_NC;
  7538. }
  7539. /* -- Verify decryption works */
  7540. err = wc_ChaCha20Poly1305_Decrypt(key1, iv1,
  7541. aad1, sizeof(aad1),
  7542. cipher1, sizeof(cipher1),
  7543. authTag1, generatedPlaintext);
  7544. if (err) {
  7545. return err;
  7546. }
  7547. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7548. return WC_TEST_RET_ENC_NC;
  7549. }
  7550. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7551. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7552. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7553. /* Test #2 */
  7554. err = wc_ChaCha20Poly1305_Encrypt(key2, iv2,
  7555. aad2, sizeof(aad2),
  7556. plaintext2, sizeof(plaintext2),
  7557. generatedCiphertext, generatedAuthTag);
  7558. if (err) {
  7559. return err;
  7560. }
  7561. /* -- Check the ciphertext and authtag */
  7562. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7563. return WC_TEST_RET_ENC_NC;
  7564. }
  7565. if (XMEMCMP(generatedAuthTag, authTag2, sizeof(authTag2))) {
  7566. return WC_TEST_RET_ENC_NC;
  7567. }
  7568. /* -- Verify decryption works */
  7569. err = wc_ChaCha20Poly1305_Decrypt(key2, iv2,
  7570. aad2, sizeof(aad2),
  7571. cipher2, sizeof(cipher2),
  7572. authTag2, generatedPlaintext);
  7573. if (err) {
  7574. return err;
  7575. }
  7576. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7577. return WC_TEST_RET_ENC_NC;
  7578. }
  7579. /* AEAD init/update/final - bad argument tests */
  7580. err = wc_ChaCha20Poly1305_Init(NULL, key1, iv1,
  7581. CHACHA20_POLY1305_AEAD_DECRYPT);
  7582. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7583. return WC_TEST_RET_ENC_EC(err);
  7584. err = wc_ChaCha20Poly1305_Init(&aead, NULL, iv1,
  7585. CHACHA20_POLY1305_AEAD_DECRYPT);
  7586. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7587. return WC_TEST_RET_ENC_EC(err);
  7588. err = wc_ChaCha20Poly1305_Init(&aead, key1, NULL,
  7589. CHACHA20_POLY1305_AEAD_DECRYPT);
  7590. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7591. return WC_TEST_RET_ENC_EC(err);
  7592. err = wc_ChaCha20Poly1305_UpdateAad(NULL, aad1, sizeof(aad1));
  7593. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7594. return WC_TEST_RET_ENC_EC(err);
  7595. err = wc_ChaCha20Poly1305_UpdateAad(&aead, NULL, sizeof(aad1));
  7596. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7597. return WC_TEST_RET_ENC_EC(err);
  7598. err = wc_ChaCha20Poly1305_UpdateData(NULL, generatedPlaintext,
  7599. generatedPlaintext, sizeof(plaintext1));
  7600. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7601. return WC_TEST_RET_ENC_EC(err);
  7602. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext, NULL,
  7603. sizeof(plaintext1));
  7604. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7605. return WC_TEST_RET_ENC_EC(err);
  7606. err = wc_ChaCha20Poly1305_UpdateData(&aead, NULL, generatedPlaintext,
  7607. sizeof(plaintext1));
  7608. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7609. return WC_TEST_RET_ENC_EC(err);
  7610. err = wc_ChaCha20Poly1305_Final(NULL, generatedAuthTag);
  7611. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7612. return WC_TEST_RET_ENC_EC(err);
  7613. err = wc_ChaCha20Poly1305_Final(&aead, NULL);
  7614. if (err != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7615. return WC_TEST_RET_ENC_EC(err);
  7616. /* AEAD init/update/final - bad state tests */
  7617. /* clear struct - make valgrind happy to resolve
  7618. "Conditional jump or move depends on uninitialised value(s)".
  7619. The enum is "int" size and aead.state is "byte" */
  7620. /* The wc_ChaCha20Poly1305_Init function does this normally */
  7621. XMEMSET(&aead, 0, sizeof(aead));
  7622. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7623. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7624. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7625. return WC_TEST_RET_ENC_EC(err);
  7626. aead.state = CHACHA20_POLY1305_STATE_DATA;
  7627. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7628. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7629. return WC_TEST_RET_ENC_EC(err);
  7630. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7631. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedPlaintext,
  7632. generatedPlaintext, sizeof(plaintext1));
  7633. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7634. return WC_TEST_RET_ENC_EC(err);
  7635. aead.state = CHACHA20_POLY1305_STATE_INIT;
  7636. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7637. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7638. return WC_TEST_RET_ENC_EC(err);
  7639. aead.state = CHACHA20_POLY1305_STATE_READY;
  7640. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7641. if (err != WC_NO_ERR_TRACE(BAD_STATE_E))
  7642. return WC_TEST_RET_ENC_EC(err);
  7643. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7644. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7645. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7646. /* Test 1 - Encrypt */
  7647. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7648. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7649. if (err != 0)
  7650. return WC_TEST_RET_ENC_EC(err);
  7651. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7652. if (err != 0)
  7653. return WC_TEST_RET_ENC_EC(err);
  7654. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7655. /* test doing data in smaller chunks */
  7656. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7657. word32 dataLen = sizeof(plaintext1) - testLen;
  7658. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7659. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7660. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext1[testLen],
  7661. &generatedCiphertext[testLen], dataLen);
  7662. if (err != 0)
  7663. return WC_TEST_RET_ENC_EC(err);
  7664. testLen += dataLen;
  7665. }
  7666. #else
  7667. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext1,
  7668. generatedCiphertext, sizeof(plaintext1));
  7669. #endif
  7670. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7671. if (err != 0)
  7672. return WC_TEST_RET_ENC_EC(err);
  7673. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7674. if (err != 0)
  7675. return WC_TEST_RET_ENC_EC(err);
  7676. if (XMEMCMP(generatedCiphertext, cipher1, sizeof(cipher1))) {
  7677. return WC_TEST_RET_ENC_NC;
  7678. }
  7679. /* Test 1 - Decrypt */
  7680. err = wc_ChaCha20Poly1305_Init(&aead, key1, iv1,
  7681. CHACHA20_POLY1305_AEAD_DECRYPT);
  7682. if (err != 0)
  7683. return WC_TEST_RET_ENC_EC(err);
  7684. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad1, sizeof(aad1));
  7685. if (err != 0)
  7686. return WC_TEST_RET_ENC_EC(err);
  7687. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7688. /* test doing data in smaller chunks */
  7689. for (testLen=0; testLen<sizeof(plaintext1); ) {
  7690. word32 dataLen = sizeof(plaintext1) - testLen;
  7691. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7692. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7693. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7694. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7695. dataLen);
  7696. if (err != 0)
  7697. return WC_TEST_RET_ENC_EC(err);
  7698. testLen += dataLen;
  7699. }
  7700. #else
  7701. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7702. generatedPlaintext, sizeof(cipher1));
  7703. #endif
  7704. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7705. if (err != 0)
  7706. return WC_TEST_RET_ENC_EC(err);
  7707. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag1);
  7708. if (err != 0)
  7709. return WC_TEST_RET_ENC_EC(err);
  7710. if (XMEMCMP(generatedPlaintext, plaintext1, sizeof(plaintext1))) {
  7711. return WC_TEST_RET_ENC_NC;
  7712. }
  7713. XMEMSET(generatedCiphertext, 0, sizeof(generatedCiphertext));
  7714. XMEMSET(generatedAuthTag, 0, sizeof(generatedAuthTag));
  7715. XMEMSET(generatedPlaintext, 0, sizeof(generatedPlaintext));
  7716. /* Test 2 - Encrypt */
  7717. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7718. CHACHA20_POLY1305_AEAD_ENCRYPT);
  7719. if (err != 0)
  7720. return WC_TEST_RET_ENC_EC(err);
  7721. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7722. if (err != 0)
  7723. return WC_TEST_RET_ENC_EC(err);
  7724. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7725. /* test doing data in smaller chunks */
  7726. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7727. word32 dataLen = sizeof(plaintext2) - testLen;
  7728. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7729. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7730. err = wc_ChaCha20Poly1305_UpdateData(&aead, &plaintext2[testLen],
  7731. &generatedCiphertext[testLen], dataLen);
  7732. if (err != 0)
  7733. return WC_TEST_RET_ENC_EC(err);
  7734. testLen += dataLen;
  7735. }
  7736. #else
  7737. err = wc_ChaCha20Poly1305_UpdateData(&aead, plaintext2, generatedCiphertext,
  7738. sizeof(plaintext2));
  7739. #endif
  7740. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7741. if (err != 0)
  7742. return WC_TEST_RET_ENC_EC(err);
  7743. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7744. if (err != 0)
  7745. return WC_TEST_RET_ENC_EC(err);
  7746. if (XMEMCMP(generatedCiphertext, cipher2, sizeof(cipher2))) {
  7747. return WC_TEST_RET_ENC_NC;
  7748. }
  7749. /* Test 2 - Decrypt */
  7750. err = wc_ChaCha20Poly1305_Init(&aead, key2, iv2,
  7751. CHACHA20_POLY1305_AEAD_DECRYPT);
  7752. if (err != 0)
  7753. return WC_TEST_RET_ENC_EC(err);
  7754. err = wc_ChaCha20Poly1305_UpdateAad(&aead, aad2, sizeof(aad2));
  7755. if (err != 0)
  7756. return WC_TEST_RET_ENC_EC(err);
  7757. #ifdef TEST_SMALL_CHACHA_CHUNKS
  7758. /* test doing data in smaller chunks */
  7759. for (testLen=0; testLen<sizeof(plaintext2); ) {
  7760. word32 dataLen = sizeof(plaintext2) - testLen;
  7761. if (dataLen > TEST_SMALL_CHACHA_CHUNKS)
  7762. dataLen = TEST_SMALL_CHACHA_CHUNKS;
  7763. err = wc_ChaCha20Poly1305_UpdateData(&aead,
  7764. &generatedCiphertext[testLen], &generatedPlaintext[testLen],
  7765. dataLen);
  7766. if (err != 0)
  7767. return WC_TEST_RET_ENC_EC(err);
  7768. testLen += dataLen;
  7769. }
  7770. #else
  7771. err = wc_ChaCha20Poly1305_UpdateData(&aead, generatedCiphertext,
  7772. generatedPlaintext, sizeof(cipher2));
  7773. #endif
  7774. err = wc_ChaCha20Poly1305_Final(&aead, generatedAuthTag);
  7775. if (err != 0)
  7776. return WC_TEST_RET_ENC_EC(err);
  7777. err = wc_ChaCha20Poly1305_CheckTag(generatedAuthTag, authTag2);
  7778. if (err != 0)
  7779. return WC_TEST_RET_ENC_EC(err);
  7780. if (XMEMCMP(generatedPlaintext, plaintext2, sizeof(plaintext2))) {
  7781. return WC_TEST_RET_ENC_NC;
  7782. }
  7783. return err;
  7784. }
  7785. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  7786. #ifndef NO_DES3
  7787. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des_test(void)
  7788. {
  7789. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  7790. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7791. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7792. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7793. };
  7794. byte plain[24];
  7795. byte cipher[24];
  7796. Des enc;
  7797. Des dec;
  7798. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  7799. {
  7800. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  7801. };
  7802. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  7803. {
  7804. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  7805. };
  7806. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  7807. {
  7808. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  7809. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  7810. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  7811. };
  7812. #ifdef WOLFSSL_DES_ECB
  7813. /* "Stay strong and move on!"" */
  7814. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7815. {
  7816. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7817. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7818. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7819. };
  7820. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb[] =
  7821. {
  7822. 0x70,0x4F,0x20,0xF6,0x72,0xB4,0xD0,0x2A,
  7823. 0xB5,0xA9,0x94,0x9F,0x11,0xCF,0x87,0xED,
  7824. 0x13,0x33,0x82,0xCB,0x8B,0xF1,0x82,0x56
  7825. };
  7826. /* "Lemmings" */
  7827. WOLFSSL_SMALL_STACK_STATIC const byte key_ecb[] =
  7828. {
  7829. 0x4C,0x65,0x6D,0x6D,0x69,0x6E,0x67,0x73
  7830. };
  7831. #endif /* WOLFSSL_DES_ECB */
  7832. wc_test_ret_t ret;
  7833. WOLFSSL_ENTER("des_test");
  7834. ret = wc_Des_SetKey(&enc, key, iv, DES_ENCRYPTION);
  7835. if (ret != 0)
  7836. return WC_TEST_RET_ENC_EC(ret);
  7837. ret = wc_Des_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7838. if (ret != 0)
  7839. return WC_TEST_RET_ENC_EC(ret);
  7840. ret = wc_Des_SetKey(&dec, key, iv, DES_DECRYPTION);
  7841. if (ret != 0)
  7842. return WC_TEST_RET_ENC_EC(ret);
  7843. ret = wc_Des_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7844. if (ret != 0)
  7845. return WC_TEST_RET_ENC_EC(ret);
  7846. if (XMEMCMP(plain, vector, sizeof(plain)))
  7847. return WC_TEST_RET_ENC_NC;
  7848. if (XMEMCMP(cipher, verify, sizeof(cipher)))
  7849. return WC_TEST_RET_ENC_NC;
  7850. ret = wc_Des_CbcEncryptWithKey(cipher, vector, sizeof(vector), key, iv);
  7851. if (ret != 0)
  7852. return WC_TEST_RET_ENC_EC(ret);
  7853. /* Test basic ECB Process for DES*/
  7854. #ifdef WOLFSSL_DES_ECB
  7855. ret = wc_Des_SetKey(&enc, key_ecb, iv, DES_ENCRYPTION);
  7856. if (ret != 0)
  7857. return WC_TEST_RET_ENC_EC(ret);
  7858. ret = wc_Des_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector));
  7859. if (ret != 0)
  7860. return WC_TEST_RET_ENC_EC(ret);
  7861. ret = wc_Des_SetKey(&dec, key_ecb, iv, DES_DECRYPTION);
  7862. if (ret != 0)
  7863. return WC_TEST_RET_ENC_EC(ret);
  7864. ret = wc_Des_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  7865. if (ret != 0)
  7866. return WC_TEST_RET_ENC_EC(ret);
  7867. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  7868. return WC_TEST_RET_ENC_NC;
  7869. if (XMEMCMP(cipher, verify_ecb, sizeof(cipher)))
  7870. return WC_TEST_RET_ENC_NC;
  7871. #endif /* WOLFSSL_DES_ECB */
  7872. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  7873. {
  7874. EncryptedInfo info;
  7875. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  7876. XMEMCPY(info.iv, iv, sizeof(iv));
  7877. info.ivSz = sizeof(iv);
  7878. info.keySz = sizeof(key);
  7879. info.cipherType = WC_CIPHER_DES;
  7880. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7881. sizeof(key), WC_HASH_TYPE_SHA);
  7882. if (ret != 0)
  7883. return WC_TEST_RET_ENC_EC(ret);
  7884. /* Test invalid info ptr */
  7885. ret = wc_BufferKeyEncrypt(NULL, cipher, sizeof(cipher), key,
  7886. sizeof(key), WC_HASH_TYPE_SHA);
  7887. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  7888. return WC_TEST_RET_ENC_EC(ret);
  7889. #ifndef NO_PWDBASED
  7890. /* Test invalid hash type - only applies to wc_PBKDF1 call */
  7891. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key,
  7892. sizeof(key), WC_HASH_TYPE_NONE);
  7893. if (ret == 0)
  7894. return WC_TEST_RET_ENC_EC(ret);
  7895. #endif /* !NO_PWDBASED */
  7896. }
  7897. #endif
  7898. return 0;
  7899. }
  7900. #endif /* !NO_DES3 */
  7901. #ifndef NO_DES3
  7902. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t des3_test(void)
  7903. {
  7904. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "Now is the time for all " w/o trailing 0 */
  7905. 0x4e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  7906. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  7907. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  7908. };
  7909. byte plain[24];
  7910. byte cipher[24];
  7911. Des3 enc;
  7912. Des3 dec;
  7913. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  7914. {
  7915. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  7916. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  7917. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  7918. };
  7919. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  7920. {
  7921. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  7922. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  7923. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  7924. };
  7925. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] =
  7926. {
  7927. 0x43,0xa0,0x29,0x7e,0xd1,0x84,0xf8,0x0e,
  7928. 0x89,0x64,0x84,0x32,0x12,0xd5,0x08,0x98,
  7929. 0x18,0x94,0x15,0x74,0x87,0x12,0x7d,0xb0
  7930. };
  7931. #ifdef WOLFSSL_DES_ECB
  7932. /* Stay strong and move on! */
  7933. WOLFSSL_SMALL_STACK_STATIC const byte vector_ecb[] =
  7934. {
  7935. 0x53,0x74,0x61,0x79,0x20,0x73,0x74,0x72,
  7936. 0x6F,0x6E,0x67,0x20,0x61,0x6E,0x64,0x20,
  7937. 0x6D,0x6F,0x76,0x65,0x20,0x6F,0x6E,0x21
  7938. };
  7939. WOLFSSL_SMALL_STACK_STATIC const byte verify3_ecb[] =
  7940. {
  7941. 0x45,0x7E,0xFA,0xA1,0x05,0xDD,0x48,0x86,
  7942. 0x4D,0xB2,0xAB,0xE4,0xF9,0x63,0xD6,0x54,
  7943. 0x7C,0x5A,0xB3,0x67,0x32,0x25,0x67,0x3D
  7944. };
  7945. /* "Life is what you make it" */
  7946. WOLFSSL_SMALL_STACK_STATIC const byte key3_ecb[] =
  7947. {
  7948. 0x4C,0x69,0x66,0x65,0x20,0x69,0x73,0x20,
  7949. 0x77,0x68,0x61,0x74,0x20,0x79,0x6F,0x75,
  7950. 0x20,0x6D,0x61,0x6B,0x65,0x20,0x69,0x74
  7951. };
  7952. #endif /* WOLFSSL_DES_ECB */
  7953. wc_test_ret_t ret;
  7954. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  7955. size_t i;
  7956. #endif
  7957. WOLFSSL_ENTER("des3_test");
  7958. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7959. if (ret != 0)
  7960. return WC_TEST_RET_ENC_EC(ret);
  7961. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7962. if (ret != 0)
  7963. return WC_TEST_RET_ENC_EC(ret);
  7964. ret = wc_Des3_SetKey(&enc, key3, iv3, DES_ENCRYPTION);
  7965. if (ret != 0)
  7966. return WC_TEST_RET_ENC_EC(ret);
  7967. ret = wc_Des3_SetKey(&dec, key3, iv3, DES_DECRYPTION);
  7968. if (ret != 0)
  7969. return WC_TEST_RET_ENC_EC(ret);
  7970. ret = wc_Des3_CbcEncrypt(&enc, cipher, vector, sizeof(vector));
  7971. #if defined(WOLFSSL_ASYNC_CRYPT)
  7972. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  7973. #endif
  7974. if (ret != 0)
  7975. return WC_TEST_RET_ENC_EC(ret);
  7976. ret = wc_Des3_CbcDecrypt(&dec, plain, cipher, sizeof(cipher));
  7977. #if defined(WOLFSSL_ASYNC_CRYPT)
  7978. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  7979. #endif
  7980. if (ret != 0)
  7981. return WC_TEST_RET_ENC_EC(ret);
  7982. if (XMEMCMP(plain, vector, sizeof(plain)))
  7983. return WC_TEST_RET_ENC_NC;
  7984. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  7985. return WC_TEST_RET_ENC_NC;
  7986. /* Test basic ECB Process for DES3*/
  7987. #ifdef WOLFSSL_DES_ECB
  7988. ret = wc_Des3Init(&enc, HEAP_HINT, devId);
  7989. if (ret != 0)
  7990. return WC_TEST_RET_ENC_EC(ret);
  7991. ret = wc_Des3Init(&dec, HEAP_HINT, devId);
  7992. if (ret != 0)
  7993. return WC_TEST_RET_ENC_EC(ret);
  7994. ret = wc_Des3_SetKey(&enc, key3_ecb, NULL, DES_ENCRYPTION);
  7995. if (ret != 0)
  7996. return WC_TEST_RET_ENC_EC(ret);
  7997. ret = wc_Des3_SetKey(&dec, key3_ecb, NULL, DES_DECRYPTION);
  7998. if (ret != 0)
  7999. return WC_TEST_RET_ENC_EC(ret);
  8000. ret = wc_Des3_EcbEncrypt(&enc, cipher, vector_ecb, sizeof(vector_ecb));
  8001. #if defined(WOLFSSL_ASYNC_CRYPT)
  8002. ret = wc_AsyncWait(ret, &enc.asyncDev, WC_ASYNC_FLAG_NONE);
  8003. #endif
  8004. if (ret != 0)
  8005. return WC_TEST_RET_ENC_EC(ret);
  8006. ret = wc_Des3_EcbDecrypt(&dec, plain, cipher, sizeof(cipher));
  8007. #if defined(WOLFSSL_ASYNC_CRYPT)
  8008. ret = wc_AsyncWait(ret, &dec.asyncDev, WC_ASYNC_FLAG_NONE);
  8009. #endif
  8010. if (ret != 0)
  8011. return WC_TEST_RET_ENC_EC(ret);
  8012. if (XMEMCMP(plain, vector_ecb, sizeof(plain)))
  8013. return WC_TEST_RET_ENC_NC;
  8014. if (XMEMCMP(cipher, verify3_ecb, sizeof(cipher)))
  8015. return WC_TEST_RET_ENC_NC;
  8016. #endif /* WOLFSSL_DES_ECB */
  8017. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  8018. /* test the same vectors with using compatibility layer */
  8019. for (i = 0; i < sizeof(vector); i += DES_BLOCK_SIZE){
  8020. DES_key_schedule ks1;
  8021. DES_key_schedule ks2;
  8022. DES_key_schedule ks3;
  8023. DES_cblock iv4;
  8024. byte tmp[sizeof(vector)];
  8025. XMEMCPY(ks1, key3, sizeof(DES_key_schedule));
  8026. XMEMCPY(ks2, key3 + 8, sizeof(DES_key_schedule));
  8027. XMEMCPY(ks3, key3 + 16, sizeof(DES_key_schedule));
  8028. XMEMSET(plain, 0, sizeof(plain));
  8029. XMEMSET(cipher, 0, sizeof(cipher));
  8030. /* Test in-place encrypt/decrypt */
  8031. XMEMCPY(tmp, vector, sizeof(vector));
  8032. /* Use i as the splitter */
  8033. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  8034. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8035. &iv4, DES_ENCRYPT);
  8036. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(vector) - i),
  8037. &ks1, &ks2, &ks3, &iv4, DES_ENCRYPT);
  8038. XMEMCPY(cipher, tmp, sizeof(cipher));
  8039. XMEMCPY(iv4, iv3, sizeof(DES_cblock));
  8040. DES_ede3_cbc_encrypt(tmp, tmp, (long)i, &ks1, &ks2, &ks3,
  8041. &iv4, DES_DECRYPT);
  8042. DES_ede3_cbc_encrypt(tmp + i, tmp + i, (long)(sizeof(cipher) - i),
  8043. &ks1, &ks2, &ks3, &iv4, DES_DECRYPT);
  8044. XMEMCPY(plain, tmp, sizeof(plain));
  8045. if (XMEMCMP(plain, vector, sizeof(plain)))
  8046. return WC_TEST_RET_ENC_NC;
  8047. if (XMEMCMP(cipher, verify3, sizeof(cipher)))
  8048. return WC_TEST_RET_ENC_NC;
  8049. }
  8050. #endif /* OPENSSL_EXTRA */
  8051. wc_Des3Free(&enc);
  8052. wc_Des3Free(&dec);
  8053. #if defined(WOLFSSL_ENCRYPTED_KEYS) && !defined(NO_SHA)
  8054. {
  8055. EncryptedInfo info;
  8056. XMEMSET(&info, 0, sizeof(EncryptedInfo));
  8057. XMEMCPY(info.iv, iv3, sizeof(iv3));
  8058. info.ivSz = sizeof(iv3);
  8059. info.keySz = sizeof(key3);
  8060. info.cipherType = WC_CIPHER_DES3;
  8061. ret = wc_BufferKeyEncrypt(&info, cipher, sizeof(cipher), key3,
  8062. sizeof(key3), WC_HASH_TYPE_SHA);
  8063. if (ret != 0)
  8064. return WC_TEST_RET_ENC_EC(ret);
  8065. }
  8066. #endif
  8067. return 0;
  8068. }
  8069. #endif /* NO_DES3 */
  8070. static const int fiducial1 = WC_TEST_RET_LN; /* source code reference point --
  8071. * see print_fiducials() below.
  8072. */
  8073. #ifndef NO_AES
  8074. #if defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_CFB) || \
  8075. defined(WOLFSSL_AES_XTS)
  8076. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8077. && !defined(HAVE_SELFTEST)
  8078. #if !defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0)
  8079. /* pass in the function, key, iv, plain text and expected and this function
  8080. * tests that the encryption and decryption is successful */
  8081. static wc_test_ret_t EVP_test(const WOLFSSL_EVP_CIPHER* type, const byte* key,
  8082. const byte* iv, const byte* plain, int plainSz,
  8083. const byte* expected, int expectedSz)
  8084. {
  8085. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8086. WOLFSSL_EVP_CIPHER_CTX *ctx = NULL;
  8087. #else
  8088. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  8089. #endif
  8090. int ctx_inited = 0;
  8091. int idx, cipherSz;
  8092. wc_test_ret_t ret = 0;
  8093. byte* cipher;
  8094. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8095. if ((ctx = wolfSSL_EVP_CIPHER_CTX_new()) == NULL)
  8096. return MEMORY_E;
  8097. #endif
  8098. cipher = (byte*)XMALLOC(plainSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8099. if (cipher == NULL) {
  8100. ret = WC_TEST_RET_ENC_ERRNO;
  8101. goto EVP_TEST_END;
  8102. }
  8103. /* test encrypt */
  8104. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  8105. ctx_inited = 1;
  8106. if (wolfSSL_EVP_CipherInit(ctx, type, key, iv, 1) == 0) {
  8107. ret = WC_TEST_RET_ENC_NC;
  8108. goto EVP_TEST_END;
  8109. }
  8110. if (wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, plain, expectedSz) == 0) {
  8111. ret = WC_TEST_RET_ENC_NC;
  8112. goto EVP_TEST_END;
  8113. }
  8114. cipherSz = idx;
  8115. if (wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8116. ret = WC_TEST_RET_ENC_NC;
  8117. goto EVP_TEST_END;
  8118. }
  8119. cipherSz += idx;
  8120. if (XMEMCMP(cipher, expected, plainSz)) {
  8121. ret = WC_TEST_RET_ENC_NC;
  8122. goto EVP_TEST_END;
  8123. }
  8124. ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8125. ctx_inited = 0;
  8126. if (ret == WOLFSSL_SUCCESS)
  8127. ret = 0;
  8128. else {
  8129. ret = WC_TEST_RET_ENC_NC;
  8130. goto EVP_TEST_END;
  8131. }
  8132. /* test decrypt */
  8133. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  8134. ctx_inited = 1;
  8135. if (wolfSSL_EVP_CipherInit(ctx, type, key, iv, 0) == 0) {
  8136. ret = WC_TEST_RET_ENC_NC;
  8137. goto EVP_TEST_END;
  8138. }
  8139. if (wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, cipher, expectedSz) == 0) {
  8140. ret = WC_TEST_RET_ENC_NC;
  8141. goto EVP_TEST_END;
  8142. }
  8143. cipherSz = idx;
  8144. if (wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx) == 0) {
  8145. ret = WC_TEST_RET_ENC_NC;
  8146. goto EVP_TEST_END;
  8147. }
  8148. cipherSz += idx;
  8149. if ((expectedSz != cipherSz) || XMEMCMP(plain, cipher, plainSz)) {
  8150. ret = WC_TEST_RET_ENC_NC;
  8151. goto EVP_TEST_END;
  8152. }
  8153. EVP_TEST_END:
  8154. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8155. (void)cipherSz;
  8156. if (ctx_inited) {
  8157. int cleanup_ret = wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  8158. if (cleanup_ret != WOLFSSL_SUCCESS)
  8159. ret = WC_TEST_RET_ENC_NC;
  8160. }
  8161. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8162. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  8163. #endif
  8164. return ret;
  8165. }
  8166. #endif /* !HAVE_FIPS || FIPS_VERSION3_GE(6,0,0) */
  8167. #endif /* OPENSSL_EXTRA && !WOLFCRYPT_ONLY && !HAVE_SELFTEST */
  8168. #endif /* WOLFSSL_AES_OFB || WOLFSSL_AES_CFB */
  8169. #ifdef WOLFSSL_AES_OFB
  8170. /* test vector from https://csrc.nist.gov/Projects/cryptographic-algorithm-validation-program/Block-Ciphers */
  8171. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesofb_test(void)
  8172. {
  8173. #ifdef WOLFSSL_AES_256
  8174. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8175. {
  8176. 0xc4,0xc7,0xfa,0xd6,0x53,0x5c,0xb8,0x71,
  8177. 0x4a,0x5c,0x40,0x77,0x9a,0x8b,0xa1,0xd2,
  8178. 0x53,0x3e,0x23,0xb4,0xb2,0x58,0x73,0x2a,
  8179. 0x5b,0x78,0x01,0xf4,0xe3,0x71,0xa7,0x94
  8180. };
  8181. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  8182. {
  8183. 0x5e,0xb9,0x33,0x13,0xb8,0x71,0xff,0x16,
  8184. 0xb9,0x8a,0x9b,0xcb,0x43,0x33,0x0d,0x6f
  8185. };
  8186. WOLFSSL_SMALL_STACK_STATIC const byte plain1[] =
  8187. {
  8188. 0x6d,0x0b,0xb0,0x79,0x63,0x84,0x71,0xe9,
  8189. 0x39,0xd4,0x53,0x14,0x86,0xc1,0x4c,0x25,
  8190. 0x9a,0xee,0xc6,0xf3,0xc0,0x0d,0xfd,0xd6,
  8191. 0xc0,0x50,0xa8,0xba,0xa8,0x20,0xdb,0x71,
  8192. 0xcc,0x12,0x2c,0x4e,0x0c,0x17,0x15,0xef,
  8193. 0x55,0xf3,0x99,0x5a,0x6b,0xf0,0x2a,0x4c
  8194. };
  8195. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8196. {
  8197. 0x0f,0x54,0x61,0x71,0x59,0xd0,0x3f,0xfc,
  8198. 0x1b,0xfa,0xfb,0x60,0x29,0x30,0xd7,0x00,
  8199. 0xf4,0xa4,0xa8,0xe6,0xdd,0x93,0x94,0x46,
  8200. 0x64,0xd2,0x19,0xc4,0xc5,0x4d,0xde,0x1b,
  8201. 0x04,0x53,0xe1,0x73,0xf5,0x18,0x74,0xae,
  8202. 0xfd,0x64,0xa2,0xe1,0xe2,0x76,0x13,0xb0
  8203. };
  8204. #endif /* WOLFSSL_AES_256 */
  8205. #ifdef WOLFSSL_AES_128
  8206. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8207. {
  8208. 0x10,0xa5,0x88,0x69,0xd7,0x4b,0xe5,0xa3,
  8209. 0x74,0xcf,0x86,0x7c,0xfb,0x47,0x38,0x59
  8210. };
  8211. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  8212. {
  8213. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8214. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8215. };
  8216. WOLFSSL_SMALL_STACK_STATIC const byte plain2[] =
  8217. {
  8218. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8219. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8220. };
  8221. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8222. {
  8223. 0x6d,0x25,0x1e,0x69,0x44,0xb0,0x51,0xe0,
  8224. 0x4e,0xaa,0x6f,0xb4,0xdb,0xf7,0x84,0x65
  8225. };
  8226. #endif /* WOLFSSL_AES_128 */
  8227. #ifdef WOLFSSL_AES_192
  8228. WOLFSSL_SMALL_STACK_STATIC const byte key3[] = {
  8229. 0xd0,0x77,0xa0,0x3b,0xd8,0xa3,0x89,0x73,
  8230. 0x92,0x8c,0xca,0xfe,0x4a,0x9d,0x2f,0x45,
  8231. 0x51,0x30,0xbd,0x0a,0xf5,0xae,0x46,0xa9
  8232. };
  8233. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  8234. {
  8235. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8236. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8237. };
  8238. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8239. {
  8240. 0xab,0xc7,0x86,0xfb,0x1e,0xdb,0x50,0x45,
  8241. 0x80,0xc4,0xd8,0x82,0xef,0x29,0xa0,0xc7
  8242. };
  8243. WOLFSSL_SMALL_STACK_STATIC const byte plain3[] =
  8244. {
  8245. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8246. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  8247. };
  8248. #endif /* WOLFSSL_AES_192 */
  8249. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8250. Aes *enc = NULL;
  8251. #else
  8252. Aes enc[1];
  8253. #endif
  8254. byte cipher[AES_BLOCK_SIZE * 4];
  8255. #ifdef HAVE_AES_DECRYPT
  8256. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8257. Aes *dec = NULL;
  8258. #else
  8259. Aes dec[1];
  8260. #endif
  8261. byte plain [AES_BLOCK_SIZE * 4];
  8262. #endif
  8263. wc_test_ret_t ret = 0;
  8264. WOLFSSL_ENTER("aesofb_test");
  8265. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8266. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8267. if (enc == NULL)
  8268. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8269. #ifdef HAVE_AES_DECRYPT
  8270. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8271. if (dec == NULL)
  8272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8273. #endif
  8274. #else
  8275. XMEMSET(enc, 0, sizeof(Aes));
  8276. #ifdef HAVE_AES_DECRYPT
  8277. XMEMSET(dec, 0, sizeof(Aes));
  8278. #endif
  8279. ret = wc_AesInit(enc, HEAP_HINT, INVALID_DEVID);
  8280. if (ret != 0)
  8281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8282. #ifdef HAVE_AES_DECRYPT
  8283. ret = wc_AesInit(dec, HEAP_HINT, INVALID_DEVID);
  8284. if (ret != 0)
  8285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8286. #endif
  8287. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8288. #ifdef WOLFSSL_AES_128
  8289. /* 128 key size test */
  8290. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8291. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8292. ret = EVP_test(wolfSSL_EVP_aes_128_ofb(), key2, iv2, plain2, sizeof(plain2),
  8293. cipher2, sizeof(cipher2));
  8294. if (ret != 0) {
  8295. goto out;
  8296. }
  8297. #endif
  8298. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8299. if (ret != 0)
  8300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8301. #ifdef HAVE_AES_DECRYPT
  8302. /* decrypt uses AES_ENCRYPTION */
  8303. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8304. if (ret != 0)
  8305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8306. #endif
  8307. XMEMSET(cipher, 0, sizeof(cipher));
  8308. ret = wc_AesOfbEncrypt(enc, cipher, plain2, AES_BLOCK_SIZE);
  8309. if (ret != 0)
  8310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8311. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE))
  8312. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8313. #ifdef HAVE_AES_DECRYPT
  8314. ret = wc_AesOfbDecrypt(dec, plain, cipher2, AES_BLOCK_SIZE);
  8315. if (ret != 0)
  8316. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8317. if (XMEMCMP(plain, plain2, AES_BLOCK_SIZE))
  8318. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8319. #endif /* HAVE_AES_DECRYPT */
  8320. #endif /* WOLFSSL_AES_128 */
  8321. #ifdef WOLFSSL_AES_192
  8322. /* 192 key size test */
  8323. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8324. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8325. ret = EVP_test(wolfSSL_EVP_aes_192_ofb(), key3, iv3, plain3, sizeof(plain3),
  8326. cipher3, sizeof(cipher3));
  8327. if (ret != 0) {
  8328. goto out;
  8329. }
  8330. #endif
  8331. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8332. if (ret != 0)
  8333. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8334. #ifdef HAVE_AES_DECRYPT
  8335. /* decrypt uses AES_ENCRYPTION */
  8336. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8337. if (ret != 0)
  8338. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8339. #endif
  8340. XMEMSET(cipher, 0, sizeof(cipher));
  8341. ret = wc_AesOfbEncrypt(enc, cipher, plain3, AES_BLOCK_SIZE);
  8342. if (ret != 0)
  8343. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8344. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE))
  8345. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8346. #ifdef HAVE_AES_DECRYPT
  8347. ret = wc_AesOfbDecrypt(dec, plain, cipher3, AES_BLOCK_SIZE);
  8348. if (ret != 0)
  8349. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8350. if (XMEMCMP(plain, plain3, AES_BLOCK_SIZE))
  8351. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8352. #endif /* HAVE_AES_DECRYPT */
  8353. #endif /* WOLFSSL_AES_192 */
  8354. #ifdef WOLFSSL_AES_256
  8355. /* 256 key size test */
  8356. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8357. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8358. ret = EVP_test(wolfSSL_EVP_aes_256_ofb(), key1, iv1, plain1, sizeof(plain1),
  8359. cipher1, sizeof(cipher1));
  8360. if (ret != 0) {
  8361. goto out;
  8362. }
  8363. #endif
  8364. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8365. if (ret != 0)
  8366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8367. #ifdef HAVE_AES_DECRYPT
  8368. /* decrypt uses AES_ENCRYPTION */
  8369. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8370. if (ret != 0)
  8371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8372. #endif
  8373. XMEMSET(cipher, 0, sizeof(cipher));
  8374. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE);
  8375. if (ret != 0)
  8376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8377. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE))
  8378. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8379. ret = wc_AesOfbEncrypt(enc, cipher + AES_BLOCK_SIZE,
  8380. plain1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8381. if (ret != 0)
  8382. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8383. if (XMEMCMP(cipher + AES_BLOCK_SIZE, cipher1 + AES_BLOCK_SIZE,
  8384. AES_BLOCK_SIZE))
  8385. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8386. #ifdef HAVE_AES_DECRYPT
  8387. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE);
  8388. if (ret != 0)
  8389. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8390. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE))
  8391. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8392. ret = wc_AesOfbDecrypt(dec, plain + AES_BLOCK_SIZE,
  8393. cipher1 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  8394. if (ret != 0)
  8395. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8396. if (XMEMCMP(plain + AES_BLOCK_SIZE, plain1 + AES_BLOCK_SIZE,
  8397. AES_BLOCK_SIZE))
  8398. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8399. #endif /* HAVE_AES_DECRYPT */
  8400. /* multiple blocks at once */
  8401. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8402. if (ret != 0)
  8403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8404. #ifdef HAVE_AES_DECRYPT
  8405. /* decrypt uses AES_ENCRYPTION */
  8406. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8407. if (ret != 0)
  8408. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8409. #endif
  8410. XMEMSET(cipher, 0, sizeof(cipher));
  8411. ret = wc_AesOfbEncrypt(enc, cipher, plain1, AES_BLOCK_SIZE * 3);
  8412. if (ret != 0)
  8413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8414. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 3))
  8415. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8416. #ifdef HAVE_AES_DECRYPT
  8417. ret = wc_AesOfbDecrypt(dec, plain, cipher1, AES_BLOCK_SIZE * 3);
  8418. if (ret != 0)
  8419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8420. if (XMEMCMP(plain, plain1, AES_BLOCK_SIZE * 3))
  8421. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8422. #endif /* HAVE_AES_DECRYPT */
  8423. /* inline decrypt/encrypt*/
  8424. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8425. if (ret != 0)
  8426. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8427. #ifdef HAVE_AES_DECRYPT
  8428. /* decrypt uses AES_ENCRYPTION */
  8429. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8430. if (ret != 0)
  8431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8432. #endif
  8433. XMEMCPY(cipher, plain1, AES_BLOCK_SIZE * 2);
  8434. ret = wc_AesOfbEncrypt(enc, cipher, cipher, AES_BLOCK_SIZE * 2);
  8435. if (ret != 0)
  8436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8437. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8438. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8439. #ifdef HAVE_AES_DECRYPT
  8440. ret = wc_AesOfbDecrypt(dec, cipher, cipher, AES_BLOCK_SIZE * 2);
  8441. if (ret != 0)
  8442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8443. if (XMEMCMP(cipher, plain1, AES_BLOCK_SIZE * 2))
  8444. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8445. #endif /* HAVE_AES_DECRYPT */
  8446. /* 256 key size test leftover support */
  8447. ret = wc_AesSetKey(enc, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8448. if (ret != 0)
  8449. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8450. #ifdef HAVE_AES_DECRYPT
  8451. /* decrypt uses AES_ENCRYPTION */
  8452. ret = wc_AesSetKey(dec, key1, sizeof(key1), iv1, AES_ENCRYPTION);
  8453. if (ret != 0)
  8454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8455. #endif
  8456. XMEMSET(cipher, 0, sizeof(cipher));
  8457. ret = wc_AesOfbEncrypt(enc, cipher, plain1, 3);
  8458. if (ret != 0)
  8459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8460. if (XMEMCMP(cipher, cipher1, 3))
  8461. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8462. ret = wc_AesOfbEncrypt(enc, cipher + 3, plain1 + 3, AES_BLOCK_SIZE);
  8463. if (ret != 0)
  8464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8465. if (XMEMCMP(cipher + 3, cipher1 + 3, AES_BLOCK_SIZE))
  8466. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8467. #ifdef HAVE_AES_DECRYPT
  8468. ret = wc_AesOfbDecrypt(dec, plain, cipher1, 6);
  8469. if (ret != 0)
  8470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8471. if (XMEMCMP(plain, plain1, 6))
  8472. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8473. ret = wc_AesOfbDecrypt(dec, plain + 6, cipher1 + 6, AES_BLOCK_SIZE);
  8474. if (ret != 0)
  8475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8476. if (XMEMCMP(plain + 6, plain1 + 6, AES_BLOCK_SIZE))
  8477. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8478. #endif /* HAVE_AES_DECRYPT */
  8479. out:
  8480. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8481. wc_AesDelete(enc, &enc);
  8482. #else
  8483. wc_AesFree(enc);
  8484. #endif
  8485. #ifdef HAVE_AES_DECRYPT
  8486. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8487. wc_AesDelete(dec, &dec);
  8488. #else
  8489. wc_AesFree(dec);
  8490. #endif
  8491. #endif
  8492. #endif /* WOLFSSL_AES_256 */
  8493. return ret;
  8494. }
  8495. #endif /* WOLFSSL_AES_OFB */
  8496. #if defined(WOLFSSL_AES_CFB)
  8497. /* Test cases from NIST SP 800-38A, Recommendation for Block Cipher Modes of
  8498. * Operation Methods and Techniques
  8499. */
  8500. static wc_test_ret_t aescfb_test_0(void)
  8501. {
  8502. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8503. Aes *enc = NULL;
  8504. #else
  8505. Aes enc[1];
  8506. #endif
  8507. byte cipher[AES_BLOCK_SIZE * 4];
  8508. #ifdef HAVE_AES_DECRYPT
  8509. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8510. Aes *dec = NULL;
  8511. #else
  8512. Aes dec[1];
  8513. #endif
  8514. byte plain [AES_BLOCK_SIZE * 4];
  8515. #endif
  8516. wc_test_ret_t ret = 0;
  8517. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8518. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  8519. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  8520. };
  8521. #ifdef WOLFSSL_AES_128
  8522. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8523. {
  8524. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  8525. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  8526. };
  8527. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8528. {
  8529. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  8530. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  8531. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  8532. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b,
  8533. 0x26,0x75,0x1f,0x67,0xa3,0xcb,0xb1,0x40,
  8534. 0xb1,0x80,0x8c,0xf1,0x87,0xa4,0xf4,0xdf
  8535. };
  8536. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8537. {
  8538. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8539. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8540. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8541. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8542. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8543. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef
  8544. };
  8545. #endif /* WOLFSSL_AES_128 */
  8546. #ifdef WOLFSSL_AES_192
  8547. /* 192 size key test */
  8548. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8549. {
  8550. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  8551. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  8552. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  8553. };
  8554. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8555. {
  8556. 0xcd,0xc8,0x0d,0x6f,0xdd,0xf1,0x8c,0xab,
  8557. 0x34,0xc2,0x59,0x09,0xc9,0x9a,0x41,0x74,
  8558. 0x67,0xce,0x7f,0x7f,0x81,0x17,0x36,0x21,
  8559. 0x96,0x1a,0x2b,0x70,0x17,0x1d,0x3d,0x7a,
  8560. 0x2e,0x1e,0x8a,0x1d,0xd5,0x9b,0x88,0xb1,
  8561. 0xc8,0xe6,0x0f,0xed,0x1e,0xfa,0xc4,0xc9,
  8562. 0xc0,0x5f,0x9f,0x9c,0xa9,0x83,0x4f,0xa0,
  8563. 0x42,0xae,0x8f,0xba,0x58,0x4b,0x09,0xff
  8564. };
  8565. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8566. {
  8567. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8568. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8569. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8570. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8571. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8572. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8573. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8574. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8575. };
  8576. #endif /* WOLFSSL_AES_192 */
  8577. #ifdef WOLFSSL_AES_256
  8578. /* 256 size key simple test */
  8579. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8580. {
  8581. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  8582. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  8583. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  8584. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  8585. };
  8586. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8587. {
  8588. 0xdc,0x7e,0x84,0xbf,0xda,0x79,0x16,0x4b,
  8589. 0x7e,0xcd,0x84,0x86,0x98,0x5d,0x38,0x60,
  8590. 0x39,0xff,0xed,0x14,0x3b,0x28,0xb1,0xc8,
  8591. 0x32,0x11,0x3c,0x63,0x31,0xe5,0x40,0x7b,
  8592. 0xdf,0x10,0x13,0x24,0x15,0xe5,0x4b,0x92,
  8593. 0xa1,0x3e,0xd0,0xa8,0x26,0x7a,0xe2,0xf9,
  8594. 0x75,0xa3,0x85,0x74,0x1a,0xb9,0xce,0xf8,
  8595. 0x20,0x31,0x62,0x3d,0x55,0xb1,0xe4,0x71
  8596. };
  8597. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8598. {
  8599. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  8600. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  8601. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  8602. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  8603. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  8604. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  8605. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  8606. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  8607. };
  8608. #endif /* WOLFSSL_AES_256 */
  8609. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8610. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8611. if (enc == NULL)
  8612. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8613. #ifdef HAVE_AES_DECRYPT
  8614. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8615. if (dec == NULL)
  8616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8617. #endif
  8618. #else
  8619. XMEMSET(enc, 0, sizeof(Aes));
  8620. #ifdef HAVE_AES_DECRYPT
  8621. XMEMSET(dec, 0, sizeof(Aes));
  8622. #endif
  8623. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8624. if (ret != 0)
  8625. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8626. #ifdef HAVE_AES_DECRYPT
  8627. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8628. if (ret != 0)
  8629. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8630. #endif
  8631. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8632. #ifdef WOLFSSL_AES_128
  8633. /* 128 key tests */
  8634. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8635. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8636. ret = EVP_test(wolfSSL_EVP_aes_128_cfb128(), key1, iv, msg1, sizeof(msg1),
  8637. cipher1, sizeof(cipher1));
  8638. if (ret != 0) {
  8639. return ret;
  8640. }
  8641. #endif
  8642. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8643. if (ret != 0)
  8644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8645. #ifdef HAVE_AES_DECRYPT
  8646. /* decrypt uses AES_ENCRYPTION */
  8647. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8648. if (ret != 0)
  8649. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8650. #endif
  8651. XMEMSET(cipher, 0, sizeof(cipher));
  8652. ret = wc_AesCfbEncrypt(enc, cipher, msg1, AES_BLOCK_SIZE * 2);
  8653. if (ret != 0)
  8654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8655. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  8656. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8657. /* test restarting encryption process */
  8658. ret = wc_AesCfbEncrypt(enc, cipher + (AES_BLOCK_SIZE * 2),
  8659. msg1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE);
  8660. if (ret != 0)
  8661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8662. if (XMEMCMP(cipher + (AES_BLOCK_SIZE * 2),
  8663. cipher1 + (AES_BLOCK_SIZE * 2), AES_BLOCK_SIZE))
  8664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8665. #ifdef HAVE_AES_DECRYPT
  8666. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 3);
  8667. if (ret != 0)
  8668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8669. if (XMEMCMP(plain, msg1, AES_BLOCK_SIZE * 3))
  8670. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8671. #endif /* HAVE_AES_DECRYPT */
  8672. #endif /* WOLFSSL_AES_128 */
  8673. #ifdef WOLFSSL_AES_192
  8674. /* 192 key size test */
  8675. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8676. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8677. ret = EVP_test(wolfSSL_EVP_aes_192_cfb128(), key2, iv, msg2, sizeof(msg2),
  8678. cipher2, sizeof(cipher2));
  8679. if (ret != 0) {
  8680. return ret;
  8681. }
  8682. #endif
  8683. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8684. if (ret != 0)
  8685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8686. #ifdef HAVE_AES_DECRYPT
  8687. /* decrypt uses AES_ENCRYPTION */
  8688. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv, AES_ENCRYPTION);
  8689. if (ret != 0)
  8690. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8691. #endif
  8692. XMEMSET(cipher, 0, sizeof(cipher));
  8693. ret = wc_AesCfbEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE * 4);
  8694. if (ret != 0)
  8695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8696. if (XMEMCMP(cipher, cipher2, AES_BLOCK_SIZE * 4))
  8697. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8698. #ifdef HAVE_AES_DECRYPT
  8699. ret = wc_AesCfbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE * 4);
  8700. if (ret != 0)
  8701. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8702. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE * 4))
  8703. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8704. #endif /* HAVE_AES_DECRYPT */
  8705. #endif /* WOLFSSL_AES_192 */
  8706. #ifdef WOLFSSL_AES_256
  8707. /* 256 key size test */
  8708. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  8709. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  8710. ret = EVP_test(wolfSSL_EVP_aes_256_cfb128(), key3, iv, msg3, sizeof(msg3),
  8711. cipher3, sizeof(cipher3));
  8712. if (ret != 0) {
  8713. return ret;
  8714. }
  8715. #endif
  8716. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8717. if (ret != 0)
  8718. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8719. #ifdef HAVE_AES_DECRYPT
  8720. /* decrypt uses AES_ENCRYPTION */
  8721. ret = wc_AesSetKey(dec, key3, sizeof(key3), iv, AES_ENCRYPTION);
  8722. if (ret != 0)
  8723. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8724. #endif
  8725. /* test with data left overs, magic lengths are checking near edges */
  8726. XMEMSET(cipher, 0, sizeof(cipher));
  8727. ret = wc_AesCfbEncrypt(enc, cipher, msg3, 4);
  8728. if (ret != 0)
  8729. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8730. if (XMEMCMP(cipher, cipher3, 4))
  8731. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8732. ret = wc_AesCfbEncrypt(enc, cipher + 4, msg3 + 4, 27);
  8733. if (ret != 0)
  8734. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8735. if (XMEMCMP(cipher + 4, cipher3 + 4, 27))
  8736. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8737. ret = wc_AesCfbEncrypt(enc, cipher + 31, msg3 + 31,
  8738. (AES_BLOCK_SIZE * 4) - 31);
  8739. if (ret != 0)
  8740. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8741. if (XMEMCMP(cipher, cipher3, AES_BLOCK_SIZE * 4))
  8742. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8743. #ifdef HAVE_AES_DECRYPT
  8744. ret = wc_AesCfbDecrypt(dec, plain, cipher, 4);
  8745. if (ret != 0)
  8746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8747. if (XMEMCMP(plain, msg3, 4))
  8748. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8749. ret = wc_AesCfbDecrypt(dec, plain + 4, cipher + 4, 4);
  8750. if (ret != 0)
  8751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8752. ret = wc_AesCfbDecrypt(dec, plain + 8, cipher + 8, 23);
  8753. if (ret != 0)
  8754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8755. if (XMEMCMP(plain + 4, msg3 + 4, 27))
  8756. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8757. ret = wc_AesCfbDecrypt(dec, plain + 31, cipher + 31,
  8758. (AES_BLOCK_SIZE * 4) - 31);
  8759. if (ret != 0)
  8760. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8761. if (XMEMCMP(plain, msg3, AES_BLOCK_SIZE * 4))
  8762. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8763. #endif /* HAVE_AES_DECRYPT */
  8764. #endif /* WOLFSSL_AES_256 */
  8765. out:
  8766. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8767. wc_AesDelete(enc, &enc);
  8768. #else
  8769. wc_AesFree(enc);
  8770. #endif
  8771. #ifdef HAVE_AES_DECRYPT
  8772. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8773. wc_AesDelete(dec, &dec);
  8774. #else
  8775. wc_AesFree(dec);
  8776. #endif
  8777. #endif
  8778. return ret;
  8779. }
  8780. #if !defined(HAVE_SELFTEST) && (!defined(HAVE_FIPS) || FIPS_VERSION3_GE(6,0,0))
  8781. static wc_test_ret_t aescfb1_test(void)
  8782. {
  8783. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8784. Aes *enc = NULL;
  8785. #else
  8786. Aes enc[1];
  8787. #endif
  8788. byte cipher[AES_BLOCK_SIZE];
  8789. #ifdef HAVE_AES_DECRYPT
  8790. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8791. Aes *dec = NULL;
  8792. #else
  8793. Aes dec[1];
  8794. #endif
  8795. byte plain [AES_BLOCK_SIZE];
  8796. #endif
  8797. wc_test_ret_t ret = 0;
  8798. #ifdef WOLFSSL_AES_128
  8799. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  8800. 0x4d,0xbb,0xdc,0xaa,0x59,0xf3,0x63,0xc9,
  8801. 0x2a,0x3b,0x98,0x43,0xad,0x20,0xe2,0xb7
  8802. };
  8803. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  8804. {
  8805. 0xcd,0xef,0x9d,0x06,0x61,0xba,0xe4,0x73,
  8806. 0x8d,0x1a,0x58,0xa2,0xa6,0x22,0x8b,0x66
  8807. };
  8808. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  8809. {
  8810. 0x00
  8811. };
  8812. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  8813. {
  8814. 0xC0
  8815. };
  8816. WOLFSSL_SMALL_STACK_STATIC const byte cipher1_7bit[] =
  8817. {
  8818. 0x1C
  8819. };
  8820. #endif /* WOLFSSL_AES_128 */
  8821. #ifdef WOLFSSL_AES_192
  8822. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  8823. 0x57,0xc6,0x89,0x7c,0x99,0x52,0x28,0x13,
  8824. 0xbf,0x67,0x9c,0xe1,0x13,0x70,0xaf,0x5e
  8825. };
  8826. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  8827. {
  8828. 0xba,0xa1,0x58,0xa1,0x6b,0x50,0x4a,0x10,
  8829. 0x8e,0xd4,0x33,0x2e,0xe7,0xf2,0x9b,0xf6,
  8830. 0xd1,0xac,0x46,0xa8,0xde,0x5a,0xfe,0x7a
  8831. };
  8832. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  8833. {
  8834. 0x30
  8835. };
  8836. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  8837. {
  8838. 0x80
  8839. };
  8840. #endif /* WOLFSSL_AES_192 */
  8841. #ifdef WOLFSSL_AES_256
  8842. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  8843. 0x63,0x2e,0x9f,0x83,0x1f,0xa3,0x80,0x5e,
  8844. 0x52,0x02,0xbc,0xe0,0x6d,0x04,0xf9,0xa0
  8845. };
  8846. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  8847. {
  8848. 0xf6,0xfa,0xe4,0xf1,0x5d,0x91,0xfc,0x50,
  8849. 0x88,0x78,0x4f,0x84,0xa5,0x37,0x12,0x7e,
  8850. 0x32,0x63,0x55,0x9c,0x62,0x73,0x88,0x20,
  8851. 0xc2,0xcf,0x3d,0xe1,0x1c,0x2a,0x30,0x40
  8852. };
  8853. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  8854. {
  8855. 0xF7, 0x00
  8856. };
  8857. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  8858. {
  8859. 0x41, 0xC0
  8860. };
  8861. #endif /* WOLFSSL_AES_256 */
  8862. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8863. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  8864. if (enc == NULL)
  8865. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8866. #ifdef HAVE_AES_DECRYPT
  8867. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  8868. if (dec == NULL)
  8869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8870. #endif
  8871. #else
  8872. XMEMSET(enc, 0, sizeof(Aes));
  8873. #ifdef HAVE_AES_DECRYPT
  8874. XMEMSET(dec, 0, sizeof(Aes));
  8875. #endif
  8876. ret = wc_AesInit(enc, HEAP_HINT, devId);
  8877. if (ret != 0)
  8878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8879. #ifdef HAVE_AES_DECRYPT
  8880. ret = wc_AesInit(dec, HEAP_HINT, devId);
  8881. if (ret != 0)
  8882. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8883. #endif
  8884. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  8885. #ifdef WOLFSSL_AES_128
  8886. /* 128 key tests */
  8887. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8888. if (ret != 0)
  8889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8890. #ifdef HAVE_AES_DECRYPT
  8891. /* decrypt uses AES_ENCRYPTION */
  8892. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8893. if (ret != 0)
  8894. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8895. #endif
  8896. XMEMSET(cipher, 0, sizeof(cipher));
  8897. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 2);
  8898. if (ret != 0)
  8899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8900. if (cipher[0] != cipher1[0])
  8901. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8902. #ifdef HAVE_AES_DECRYPT
  8903. ret = wc_AesCfb1Decrypt(dec, plain, cipher, 2);
  8904. if (ret != 0)
  8905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8906. if (plain[0] != msg1[0])
  8907. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8908. #endif /* HAVE_AES_DECRYPT */
  8909. XMEMSET(cipher, 0, sizeof(cipher));
  8910. ret = wc_AesCfb1Encrypt(enc, cipher, msg1, 7);
  8911. if (ret != 0)
  8912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8913. if (cipher[0] != cipher1_7bit[0])
  8914. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8915. #ifdef OPENSSL_EXTRA
  8916. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  8917. if (ret != 0)
  8918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8919. XMEMSET(cipher, 0, sizeof(cipher));
  8920. ret = wc_AesCfb1Encrypt(enc, cipher, msg1,
  8921. sizeof(msg1) * WOLFSSL_BIT_SIZE);
  8922. if (ret != 0)
  8923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8924. #ifndef WOLFCRYPT_ONLY
  8925. ret = EVP_test(wolfSSL_EVP_aes_128_cfb1(), key1, iv, msg1, sizeof(msg1),
  8926. cipher, sizeof(msg1));
  8927. if (ret != 0) {
  8928. goto out;
  8929. }
  8930. #endif
  8931. #endif
  8932. #endif /* WOLFSSL_AES_128 */
  8933. #ifdef WOLFSSL_AES_192
  8934. /* 192 key tests */
  8935. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8936. if (ret != 0)
  8937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8938. XMEMSET(cipher, 0, sizeof(cipher));
  8939. ret = wc_AesCfb1Encrypt(enc, cipher, msg2, 4);
  8940. if (ret != 0)
  8941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8942. if (XMEMCMP(cipher, cipher2, sizeof(cipher2)) != 0)
  8943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8944. #ifdef OPENSSL_EXTRA
  8945. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  8946. if (ret != 0)
  8947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8948. XMEMSET(cipher, 0, sizeof(cipher));
  8949. ret = wc_AesCfb1Encrypt(enc, cipher, msg2,
  8950. sizeof(msg2) * WOLFSSL_BIT_SIZE);
  8951. if (ret != 0)
  8952. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8953. #ifndef WOLFCRYPT_ONLY
  8954. ret = EVP_test(wolfSSL_EVP_aes_192_cfb1(), key2, iv2, msg2, sizeof(msg2),
  8955. cipher, sizeof(msg2));
  8956. if (ret != 0) {
  8957. goto out;
  8958. }
  8959. #endif
  8960. #endif
  8961. #endif /* WOLFSSL_AES_192 */
  8962. #ifdef WOLFSSL_AES_256
  8963. /* 256 key tests */
  8964. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8965. if (ret != 0)
  8966. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8967. XMEMSET(cipher, 0, sizeof(cipher));
  8968. ret = wc_AesCfb1Encrypt(enc, cipher, msg3, 10);
  8969. if (ret != 0)
  8970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8971. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  8972. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  8973. #ifdef OPENSSL_EXTRA
  8974. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  8975. if (ret != 0)
  8976. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8977. XMEMSET(cipher, 0, sizeof(cipher));
  8978. ret = wc_AesCfb1Encrypt(enc, cipher, msg3,
  8979. sizeof(msg3) * WOLFSSL_BIT_SIZE);
  8980. if (ret != 0)
  8981. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  8982. #ifndef WOLFCRYPT_ONLY
  8983. ret = EVP_test(wolfSSL_EVP_aes_256_cfb1(), key3, iv3, msg3, sizeof(msg3),
  8984. cipher, sizeof(msg3));
  8985. if (ret != 0) {
  8986. goto out;
  8987. }
  8988. #endif
  8989. #endif
  8990. #endif /* WOLFSSL_AES_256 */
  8991. out:
  8992. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8993. wc_AesDelete(enc, &enc);
  8994. #else
  8995. wc_AesFree(enc);
  8996. #endif
  8997. #ifdef HAVE_AES_DECRYPT
  8998. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  8999. wc_AesDelete(dec, &dec);
  9000. #else
  9001. wc_AesFree(dec);
  9002. #endif
  9003. #endif
  9004. return ret;
  9005. }
  9006. static wc_test_ret_t aescfb8_test(void)
  9007. {
  9008. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9009. Aes *enc = NULL;
  9010. #else
  9011. Aes enc[1];
  9012. #endif
  9013. byte cipher[AES_BLOCK_SIZE];
  9014. #ifdef HAVE_AES_DECRYPT
  9015. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9016. Aes *dec = NULL;
  9017. #else
  9018. Aes dec[1];
  9019. #endif
  9020. byte plain [AES_BLOCK_SIZE];
  9021. #endif
  9022. wc_test_ret_t ret = 0;
  9023. #ifdef WOLFSSL_AES_128
  9024. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  9025. 0xf4,0x75,0xc6,0x49,0x91,0xb2,0x0e,0xae,
  9026. 0xe1,0x83,0xa2,0x26,0x29,0xe2,0x1e,0x22
  9027. };
  9028. WOLFSSL_SMALL_STACK_STATIC const byte key1[] =
  9029. {
  9030. 0xc8,0xfe,0x9b,0xf7,0x7b,0x93,0x0f,0x46,
  9031. 0xd2,0x07,0x8b,0x8c,0x0e,0x65,0x7c,0xd4
  9032. };
  9033. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  9034. {
  9035. 0xd2,0x76,0x91
  9036. };
  9037. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] =
  9038. {
  9039. 0xc9,0x06,0x35
  9040. };
  9041. #endif /* WOLFSSL_AES_128 */
  9042. #ifdef WOLFSSL_AES_192
  9043. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  9044. 0x0a,0x02,0x84,0x6b,0x62,0xab,0xb6,0x93,
  9045. 0xef,0x31,0xd7,0x54,0x84,0x2e,0xed,0x29
  9046. };
  9047. WOLFSSL_SMALL_STACK_STATIC const byte key2[] =
  9048. {
  9049. 0xba,0xf0,0x8b,0x76,0x31,0x7a,0x65,0xc5,
  9050. 0xf0,0x7a,0xe6,0xf5,0x7e,0xb0,0xe6,0x54,
  9051. 0x88,0x65,0x93,0x24,0xd2,0x97,0x09,0xe3
  9052. };
  9053. WOLFSSL_SMALL_STACK_STATIC const byte cipher2[] =
  9054. {
  9055. 0x72,0x9c,0x0b,0x6d,0xeb,0x75,0xfa,0x6e,
  9056. 0xb5,0xe8
  9057. };
  9058. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  9059. {
  9060. 0x98,0x95,0x93,0x24,0x02,0x39,0x3d,0xc3,
  9061. 0x3a,0x60
  9062. };
  9063. #endif
  9064. #ifdef WOLFSSL_AES_256
  9065. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] = {
  9066. 0x33,0x8c,0x55,0x2f,0xf1,0xec,0xa1,0x44,
  9067. 0x08,0xe0,0x5d,0x8c,0xf9,0xf3,0xb3,0x1b
  9068. };
  9069. WOLFSSL_SMALL_STACK_STATIC const byte key3[] =
  9070. {
  9071. 0x06,0x48,0x74,0x09,0x2f,0x7a,0x13,0xcc,
  9072. 0x44,0x62,0x24,0x7a,0xd4,0x23,0xd0,0xe9,
  9073. 0x6e,0xdf,0x42,0xe8,0xb6,0x7a,0x5a,0x23,
  9074. 0xb7,0xa0,0xa6,0x47,0x7b,0x09,0x8e,0x66
  9075. };
  9076. WOLFSSL_SMALL_STACK_STATIC const byte cipher3[] =
  9077. {
  9078. 0x1c,0xff,0x95
  9079. };
  9080. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] =
  9081. {
  9082. 0xb9,0x74,0xfa
  9083. };
  9084. #endif
  9085. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9086. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  9087. if (enc == NULL)
  9088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9089. #ifdef HAVE_AES_DECRYPT
  9090. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  9091. if (dec == NULL)
  9092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9093. #endif
  9094. #else
  9095. XMEMSET(enc, 0, sizeof(Aes));
  9096. #ifdef HAVE_AES_DECRYPT
  9097. XMEMSET(dec, 0, sizeof(Aes));
  9098. #endif
  9099. ret = wc_AesInit(enc, HEAP_HINT, devId);
  9100. if (ret != 0)
  9101. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9102. #ifdef HAVE_AES_DECRYPT
  9103. ret = wc_AesInit(dec, HEAP_HINT, devId);
  9104. if (ret != 0)
  9105. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9106. #endif
  9107. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  9108. #ifdef WOLFSSL_AES_128
  9109. /* 128 key tests */
  9110. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9111. ret = EVP_test(wolfSSL_EVP_aes_128_cfb8(), key1, iv, msg1, sizeof(msg1),
  9112. cipher1, sizeof(cipher1));
  9113. if (ret != 0) {
  9114. return ret;
  9115. }
  9116. #endif
  9117. ret = wc_AesSetKey(enc, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9118. if (ret != 0)
  9119. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9120. #ifdef HAVE_AES_DECRYPT
  9121. /* decrypt uses AES_ENCRYPTION */
  9122. ret = wc_AesSetKey(dec, key1, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  9123. if (ret != 0)
  9124. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9125. #endif
  9126. XMEMSET(cipher, 0, sizeof(cipher));
  9127. ret = wc_AesCfb8Encrypt(enc, cipher, msg1, sizeof(msg1));
  9128. if (ret != 0)
  9129. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9130. if (XMEMCMP(cipher, cipher1, sizeof(cipher1)) != 0)
  9131. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9132. #ifdef HAVE_AES_DECRYPT
  9133. ret = wc_AesCfb8Decrypt(dec, plain, cipher, sizeof(msg1));
  9134. if (ret != 0)
  9135. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9136. if (XMEMCMP(plain, msg1, sizeof(msg1)) != 0)
  9137. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9138. #endif /* HAVE_AES_DECRYPT */
  9139. #endif /* WOLFSSL_AES_128 */
  9140. #ifdef WOLFSSL_AES_192
  9141. /* 192 key tests */
  9142. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  9143. if (ret != 0)
  9144. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9145. XMEMSET(cipher, 0, sizeof(cipher));
  9146. ret = wc_AesCfb8Encrypt(enc, cipher, msg2, sizeof(msg2));
  9147. if (ret != 0)
  9148. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9149. if (XMEMCMP(cipher, cipher2, sizeof(msg2)) != 0)
  9150. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9151. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9152. ret = EVP_test(wolfSSL_EVP_aes_192_cfb8(), key2, iv2, msg2, sizeof(msg2),
  9153. cipher2, sizeof(msg2));
  9154. if (ret != 0) {
  9155. return ret;
  9156. }
  9157. #endif
  9158. #endif /* WOLFSSL_AES_192 */
  9159. #ifdef WOLFSSL_AES_256
  9160. /* 256 key tests */
  9161. ret = wc_AesSetKey(enc, key3, sizeof(key3), iv3, AES_ENCRYPTION);
  9162. if (ret != 0)
  9163. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9164. XMEMSET(cipher, 0, sizeof(cipher));
  9165. ret = wc_AesCfb8Encrypt(enc, cipher, msg3, sizeof(msg3));
  9166. if (ret != 0)
  9167. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9168. if (XMEMCMP(cipher, cipher3, sizeof(cipher3)) != 0)
  9169. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9170. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  9171. ret = EVP_test(wolfSSL_EVP_aes_256_cfb8(), key3, iv3, msg3, sizeof(msg3),
  9172. cipher3, sizeof(msg3));
  9173. if (ret != 0) {
  9174. goto out;
  9175. }
  9176. #endif
  9177. #endif /* WOLFSSL_AES_256 */
  9178. out:
  9179. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9180. wc_AesDelete(enc, &enc);
  9181. #else
  9182. wc_AesFree(enc);
  9183. #endif
  9184. #ifdef HAVE_AES_DECRYPT
  9185. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9186. wc_AesDelete(dec, &dec);
  9187. #else
  9188. wc_AesFree(dec);
  9189. #endif
  9190. #endif
  9191. return ret;
  9192. }
  9193. #endif /* !HAVE_SELFTEST && !HAVE_FIPS */
  9194. #endif /* WOLFSSL_AES_CFB */
  9195. #ifndef HAVE_RENESAS_SYNC
  9196. static wc_test_ret_t aes_key_size_test(void)
  9197. {
  9198. wc_test_ret_t ret;
  9199. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9200. Aes *aes = NULL;
  9201. #else
  9202. Aes aes[1];
  9203. #endif
  9204. byte key16[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9205. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9206. #ifndef WOLFSSL_CRYPTOCELL
  9207. byte key24[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9208. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9209. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 };
  9210. #endif
  9211. byte key32[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9212. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
  9213. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  9214. 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66 };
  9215. byte iv[] = "1234567890abcdef";
  9216. #ifndef HAVE_FIPS
  9217. word32 keySize;
  9218. #endif
  9219. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9220. aes = wc_AesNew(HEAP_HINT, devId, &ret);
  9221. if (aes == NULL)
  9222. return WC_TEST_RET_ENC_EC(ret);
  9223. #else
  9224. ret = wc_AesInit(aes, HEAP_HINT, devId);
  9225. /* 0 check OK for FIPSv1 */
  9226. if (ret != 0)
  9227. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9228. #endif
  9229. #if !defined(HAVE_FIPS) || \
  9230. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  9231. /* w/ FIPS v1 (cert 2425) wc_AesInit just returns 0 always as it's not
  9232. * supported with that FIPS version */
  9233. ret = wc_AesInit(NULL, HEAP_HINT, devId);
  9234. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9236. #endif
  9237. #ifndef HAVE_FIPS
  9238. /* Parameter Validation testing. */
  9239. ret = wc_AesGetKeySize(NULL, NULL);
  9240. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9241. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9242. ret = wc_AesGetKeySize(aes, NULL);
  9243. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9244. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9245. ret = wc_AesGetKeySize(NULL, &keySize);
  9246. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9247. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9248. /* Crashes in FIPS */
  9249. ret = wc_AesSetKey(NULL, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9250. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9252. #endif
  9253. /* NULL IV indicates to use all zeros IV. */
  9254. ret = wc_AesSetKey(aes, key16, sizeof(key16), NULL, AES_ENCRYPTION);
  9255. #ifdef WOLFSSL_AES_128
  9256. if (ret != 0)
  9257. #else
  9258. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9259. #endif
  9260. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9261. ret = wc_AesSetKey(aes, key32, sizeof(key32) - 1, iv, AES_ENCRYPTION);
  9262. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9264. /* CryptoCell handles rounds internally */
  9265. #if !defined(HAVE_FIPS) && !defined(WOLFSSL_CRYPTOCELL)
  9266. /* PSA don't use aes->rounds */
  9267. #if !defined(WOLFSSL_HAVE_PSA) || defined(WOLFSSL_PSA_NO_AES)
  9268. /* Force invalid rounds */
  9269. aes->rounds = 16;
  9270. ret = wc_AesGetKeySize(aes, &keySize);
  9271. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9273. #endif
  9274. #endif
  9275. ret = wc_AesSetKey(aes, key16, sizeof(key16), iv, AES_ENCRYPTION);
  9276. #ifdef WOLFSSL_AES_128
  9277. if (ret != 0)
  9278. #else
  9279. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9280. #endif
  9281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9282. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_128)
  9283. ret = wc_AesGetKeySize(aes, &keySize);
  9284. if (ret != 0 || keySize != sizeof(key16))
  9285. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9286. #endif
  9287. #ifndef WOLFSSL_CRYPTOCELL
  9288. /* Cryptocell only supports AES-128 key size */
  9289. ret = wc_AesSetKey(aes, key24, sizeof(key24), iv, AES_ENCRYPTION);
  9290. #ifdef WOLFSSL_AES_192
  9291. if (ret != 0)
  9292. #else
  9293. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9294. #endif
  9295. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9296. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_192)
  9297. ret = wc_AesGetKeySize(aes, &keySize);
  9298. if (ret != 0 || keySize != sizeof(key24))
  9299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9300. #endif
  9301. ret = wc_AesSetKey(aes, key32, sizeof(key32), iv, AES_ENCRYPTION);
  9302. #ifdef WOLFSSL_AES_256
  9303. if (ret != 0)
  9304. #else
  9305. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  9306. #endif
  9307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9308. #if !defined(HAVE_FIPS) && defined(WOLFSSL_AES_256)
  9309. ret = wc_AesGetKeySize(aes, &keySize);
  9310. if (ret != 0 || keySize != sizeof(key32))
  9311. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9312. #endif
  9313. #endif /* !WOLFSSL_CRYPTOCELL */
  9314. ret = 0; /* success */
  9315. out:
  9316. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9317. wc_AesDelete(aes, &aes);
  9318. #else
  9319. wc_AesFree(aes);
  9320. #endif
  9321. return ret;
  9322. }
  9323. #endif /* !HAVE_RENESAS_SYNC */
  9324. #if defined(WOLFSSL_AES_XTS) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  9325. /* test vectors from http://csrc.nist.gov/groups/STM/cavp/block-cipher-modes.html */
  9326. #ifdef WOLFSSL_AES_128
  9327. static wc_test_ret_t aes_xts_128_test(void)
  9328. {
  9329. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9330. XtsAes *aes = NULL;
  9331. #else
  9332. XtsAes aes[1];
  9333. #endif
  9334. int aes_inited = 0;
  9335. wc_test_ret_t ret = 0;
  9336. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9337. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9338. #ifdef WOLFSSL_AESXTS_STREAM
  9339. struct XtsAesStreamData stream;
  9340. #endif
  9341. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9342. !defined(WOLFSSL_AFALG)
  9343. #define LARGE_XTS_SZ 1024
  9344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9345. byte* large_input = NULL;
  9346. #else
  9347. byte large_input[LARGE_XTS_SZ];
  9348. #endif
  9349. #endif
  9350. /* 128 key tests */
  9351. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9352. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  9353. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  9354. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  9355. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  9356. };
  9357. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9358. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9359. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9360. };
  9361. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9362. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9363. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9364. };
  9365. /* plain text test of partial block is not from NIST test vector list */
  9366. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9367. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9368. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9369. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9370. };
  9371. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9372. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a,
  9373. 0x82, 0x50, 0x81, 0xd5, 0xbe, 0x47, 0x1c, 0x63
  9374. };
  9375. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  9376. 0x39, 0x25, 0x79, 0x05, 0xdf, 0xcc, 0x77, 0x76,
  9377. 0x6c, 0x87, 0x0a, 0x80, 0x6a, 0x60, 0xe3, 0xc0,
  9378. 0x93, 0xd1, 0x2a, 0xcf, 0xcb, 0x51, 0x42, 0xfa,
  9379. 0x09, 0x69, 0x89, 0x62, 0x5b, 0x60, 0xdb, 0x16
  9380. };
  9381. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  9382. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  9383. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  9384. };
  9385. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  9386. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  9387. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  9388. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  9389. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  9390. };
  9391. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  9392. 0xd6, 0xbe, 0x04, 0x6d, 0x41, 0xf2, 0x3b, 0x5e,
  9393. 0xd7, 0x0b, 0x6b, 0x3d, 0x5c, 0x8e, 0x66, 0x23,
  9394. 0x2b, 0xe6, 0xb8, 0x07, 0xd4, 0xdc, 0xc6, 0x0e,
  9395. 0xff, 0x8d, 0xbc, 0x1d, 0x9f, 0x7f, 0xc8, 0x22
  9396. };
  9397. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  9398. 0x2b, 0xf7, 0x2c, 0xf3, 0xeb, 0x85, 0xef, 0x7b,
  9399. 0x0b, 0x76, 0xa0, 0xaa, 0xf3, 0x3f, 0x25, 0x8b,
  9400. 0x77, 0x8a, 0xe8, 0xb4, 0x3c, 0xb9, 0x8d, 0x5a
  9401. };
  9402. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  9403. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  9404. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9405. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9406. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9407. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9408. };
  9409. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  9410. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9411. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9412. };
  9413. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  9414. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9415. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9416. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9417. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  9418. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  9419. };
  9420. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  9421. 0xA2, 0x07, 0x47, 0x76, 0x3F, 0xEC, 0x0C, 0x23,
  9422. 0x1B, 0xD0, 0xBD, 0x46, 0x9A, 0x27, 0x38, 0x12,
  9423. 0x95, 0x02, 0x3D, 0x5D, 0xC6, 0x94, 0x51, 0x36,
  9424. 0xA0, 0x85, 0xD2, 0x69, 0x6E, 0x87, 0x0A, 0xBF,
  9425. 0xB5, 0x5A, 0xDD, 0xCB, 0x80, 0xE0, 0xFC, 0xCD
  9426. };
  9427. #endif /* HAVE_FIPS */
  9428. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9429. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  9430. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  9431. #endif
  9432. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  9433. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  9434. ret = EVP_test(wolfSSL_EVP_aes_128_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  9435. if (ret != 0) {
  9436. printf("EVP_aes_128_xts failed!\n");
  9437. goto out;
  9438. }
  9439. #endif
  9440. XMEMSET(buf, 0, sizeof(buf));
  9441. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  9442. if (ret != 0)
  9443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9444. else
  9445. aes_inited = 1;
  9446. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  9447. if (ret != 0)
  9448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9449. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9450. #if defined(WOLFSSL_ASYNC_CRYPT)
  9451. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9452. #endif
  9453. if (ret != 0)
  9454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9455. if (XMEMCMP(c2, buf, sizeof(c2)))
  9456. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9457. #ifdef WOLFSSL_AESXTS_STREAM
  9458. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  9459. #if defined(WOLFSSL_ASYNC_CRYPT)
  9460. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9461. #endif
  9462. if (ret != 0)
  9463. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9464. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  9465. #if defined(WOLFSSL_ASYNC_CRYPT)
  9466. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9467. #endif
  9468. if (ret != 0)
  9469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9470. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  9471. #if defined(WOLFSSL_ASYNC_CRYPT)
  9472. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9473. #endif
  9474. if (ret != 0)
  9475. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9476. if (XMEMCMP(c2, buf, sizeof(c2)))
  9477. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9478. #endif /* WOLFSSL_AESXTS_STREAM */
  9479. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9480. defined(WC_C_DYNAMIC_FALLBACK)
  9481. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9482. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  9483. #if defined(WOLFSSL_ASYNC_CRYPT)
  9484. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9485. #endif
  9486. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9487. if (ret != 0)
  9488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9489. if (XMEMCMP(c2, buf, sizeof(c2)))
  9490. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9491. #endif
  9492. XMEMSET(buf, 0, sizeof(buf));
  9493. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9494. if (ret != 0)
  9495. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9496. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9497. #if defined(WOLFSSL_ASYNC_CRYPT)
  9498. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9499. #endif
  9500. if (ret != 0)
  9501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9502. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9503. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9504. #ifdef WOLFSSL_AESXTS_STREAM
  9505. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i2), &stream);
  9506. #if defined(WOLFSSL_ASYNC_CRYPT)
  9507. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9508. #endif
  9509. if (ret != 0)
  9510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9511. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  9512. #if defined(WOLFSSL_ASYNC_CRYPT)
  9513. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9514. #endif
  9515. if (ret != 0)
  9516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9517. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9518. #if defined(WOLFSSL_ASYNC_CRYPT)
  9519. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9520. #endif
  9521. if (ret != 0)
  9522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9523. if (XMEMCMP(c1, buf, sizeof(c1)))
  9524. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9525. #endif /* WOLFSSL_AESXTS_STREAM */
  9526. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9527. defined(WC_C_DYNAMIC_FALLBACK)
  9528. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9529. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  9530. #if defined(WOLFSSL_ASYNC_CRYPT)
  9531. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9532. #endif
  9533. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9534. if (ret != 0)
  9535. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9536. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  9537. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9538. #endif
  9539. /* partial block encryption test */
  9540. XMEMSET(cipher, 0, sizeof(cipher));
  9541. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9542. #if defined(WOLFSSL_ASYNC_CRYPT)
  9543. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9544. #endif
  9545. if (ret != 0)
  9546. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9547. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9548. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9549. #ifdef WOLFSSL_AESXTS_STREAM
  9550. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9551. #if defined(WOLFSSL_ASYNC_CRYPT)
  9552. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9553. #endif
  9554. if (ret != 0)
  9555. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9556. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  9557. #if defined(WOLFSSL_ASYNC_CRYPT)
  9558. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9559. #endif
  9560. if (ret != 0)
  9561. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9562. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  9563. #if defined(WOLFSSL_ASYNC_CRYPT)
  9564. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9565. #endif
  9566. if (ret != 0)
  9567. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9568. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  9569. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9570. #endif /* WOLFSSL_AESXTS_STREAM */
  9571. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9572. defined(WC_C_DYNAMIC_FALLBACK)
  9573. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9574. XMEMSET(cipher, 0, sizeof(cipher));
  9575. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  9576. #if defined(WOLFSSL_ASYNC_CRYPT)
  9577. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9578. #endif
  9579. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9580. if (ret != 0)
  9581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9582. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  9583. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9584. #endif
  9585. /* partial block decrypt test */
  9586. XMEMSET(buf, 0, sizeof(buf));
  9587. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9588. if (ret != 0)
  9589. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9590. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9591. #if defined(WOLFSSL_ASYNC_CRYPT)
  9592. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9593. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9594. #else
  9595. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9596. #endif
  9597. #endif
  9598. if (ret != 0)
  9599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9600. if (XMEMCMP(pp, buf, sizeof(pp)))
  9601. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9602. #ifdef WOLFSSL_AESXTS_STREAM
  9603. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9604. #if defined(WOLFSSL_ASYNC_CRYPT)
  9605. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9606. #endif
  9607. if (ret != 0)
  9608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9609. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  9610. #if defined(WOLFSSL_ASYNC_CRYPT)
  9611. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9612. #endif
  9613. if (ret != 0)
  9614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9615. if (XMEMCMP(pp, buf, sizeof(pp)))
  9616. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9617. #endif /* WOLFSSL_AESXTS_STREAM */
  9618. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9619. defined(WC_C_DYNAMIC_FALLBACK)
  9620. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9621. XMEMSET(buf, 0, sizeof(buf));
  9622. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  9623. #if defined(WOLFSSL_ASYNC_CRYPT)
  9624. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9625. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9626. #else
  9627. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9628. #endif
  9629. #endif
  9630. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9631. if (ret != 0)
  9632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9633. if (XMEMCMP(pp, buf, sizeof(pp)))
  9634. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9635. #endif
  9636. /* NIST decrypt test vector */
  9637. XMEMSET(buf, 0, sizeof(buf));
  9638. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9639. #if defined(WOLFSSL_ASYNC_CRYPT)
  9640. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9641. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9642. #else
  9643. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9644. #endif
  9645. #endif
  9646. if (ret != 0)
  9647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9648. if (XMEMCMP(p1, buf, sizeof(p1)))
  9649. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9650. #ifdef WOLFSSL_AESXTS_STREAM
  9651. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9652. #if defined(WOLFSSL_ASYNC_CRYPT)
  9653. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9654. #endif
  9655. if (ret != 0)
  9656. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9657. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  9658. #if defined(WOLFSSL_ASYNC_CRYPT)
  9659. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9660. #endif
  9661. if (ret != 0)
  9662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9663. if (XMEMCMP(p1, buf, sizeof(p1)))
  9664. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9665. #endif /* WOLFSSL_AESXTS_STREAM */
  9666. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  9667. defined(WC_C_DYNAMIC_FALLBACK)
  9668. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  9669. XMEMSET(buf, 0, sizeof(buf));
  9670. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  9671. #if defined(WOLFSSL_ASYNC_CRYPT)
  9672. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9673. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9674. #else
  9675. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9676. #endif
  9677. #endif
  9678. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  9679. if (ret != 0)
  9680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9681. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  9682. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9683. #endif
  9684. /* fail case with decrypting using wrong key */
  9685. XMEMSET(buf, 0, sizeof(buf));
  9686. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9687. #if defined(WOLFSSL_ASYNC_CRYPT)
  9688. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9689. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9690. #else
  9691. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9692. #endif
  9693. #endif
  9694. if (ret != 0)
  9695. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9696. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  9697. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9698. /* set correct key and retest */
  9699. XMEMSET(buf, 0, sizeof(buf));
  9700. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  9701. if (ret != 0)
  9702. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9703. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  9704. #if defined(WOLFSSL_ASYNC_CRYPT)
  9705. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9706. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9707. #else
  9708. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9709. #endif
  9710. #endif
  9711. if (ret != 0)
  9712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9713. if (XMEMCMP(p2, buf, sizeof(p2)))
  9714. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9715. #ifndef HAVE_FIPS
  9716. /* Test ciphertext stealing in-place. */
  9717. XMEMCPY(buf, p3, sizeof(p3));
  9718. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  9719. if (ret != 0)
  9720. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9721. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  9722. #if defined(WOLFSSL_ASYNC_CRYPT)
  9723. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9724. #endif
  9725. if (ret != 0)
  9726. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9727. if (XMEMCMP(c3, buf, sizeof(c3)))
  9728. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9729. #ifdef WOLFSSL_AESXTS_STREAM
  9730. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  9731. #if defined(WOLFSSL_ASYNC_CRYPT)
  9732. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9733. #endif
  9734. if (ret != 0)
  9735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9736. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  9737. #if defined(WOLFSSL_ASYNC_CRYPT)
  9738. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9739. #endif
  9740. if (ret != 0)
  9741. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9742. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  9743. #if defined(WOLFSSL_ASYNC_CRYPT)
  9744. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9745. #endif
  9746. if (ret != 0)
  9747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9748. if (XMEMCMP(c3, buf, sizeof(c3)))
  9749. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9750. #endif /* WOLFSSL_AESXTS_STREAM */
  9751. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  9752. if (ret != 0)
  9753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9754. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  9755. #if defined(WOLFSSL_ASYNC_CRYPT)
  9756. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9757. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  9758. #else
  9759. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9760. #endif
  9761. #endif
  9762. if (ret != 0)
  9763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9764. if (XMEMCMP(p3, buf, sizeof(p3)))
  9765. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9766. #ifdef WOLFSSL_AESXTS_STREAM
  9767. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  9768. #if defined(WOLFSSL_ASYNC_CRYPT)
  9769. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9770. #endif
  9771. if (ret != 0)
  9772. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9773. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  9774. #if defined(WOLFSSL_ASYNC_CRYPT)
  9775. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9776. #endif
  9777. if (ret != 0)
  9778. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9779. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  9780. #if defined(WOLFSSL_ASYNC_CRYPT)
  9781. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9782. #endif
  9783. if (ret != 0)
  9784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9785. if (XMEMCMP(p3, buf, sizeof(p3)))
  9786. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9787. #endif /* WOLFSSL_AESXTS_STREAM */
  9788. #endif /* !HAVE_FIPS */
  9789. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9790. !defined(WOLFSSL_AFALG)
  9791. {
  9792. int i;
  9793. int j;
  9794. #ifdef WOLFSSL_AESXTS_STREAM
  9795. int k;
  9796. #endif
  9797. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9798. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  9799. DYNAMIC_TYPE_TMP_BUFFER);
  9800. if (large_input == NULL)
  9801. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  9802. #endif
  9803. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9804. large_input[i] = (byte)i;
  9805. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9806. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9807. if (ret != 0)
  9808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9809. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9810. sizeof(i1));
  9811. #if defined(WOLFSSL_ASYNC_CRYPT)
  9812. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9813. #endif
  9814. if (ret != 0)
  9815. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9816. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9817. if (ret != 0)
  9818. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9819. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9820. sizeof(i1));
  9821. #if defined(WOLFSSL_ASYNC_CRYPT)
  9822. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9823. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9824. WC_ASYNC_FLAG_NONE);
  9825. #else
  9826. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9827. #endif
  9828. #endif
  9829. if (ret != 0)
  9830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9831. for (i = 0; i < j; i++) {
  9832. if (large_input[i] != (byte)i) {
  9833. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9834. }
  9835. }
  9836. }
  9837. #ifdef WOLFSSL_AESXTS_STREAM
  9838. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  9839. large_input[i] = (byte)i;
  9840. /* first, encrypt block by block then decrypt with a one-shot call. */
  9841. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9842. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9843. if (ret != 0)
  9844. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9845. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  9846. #if defined(WOLFSSL_ASYNC_CRYPT)
  9847. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9848. #endif
  9849. if (ret != 0)
  9850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9851. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9852. if ((j - k) < AES_BLOCK_SIZE*2)
  9853. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9854. else
  9855. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9856. #if defined(WOLFSSL_ASYNC_CRYPT)
  9857. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9858. #endif
  9859. if (ret != 0)
  9860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9861. if ((j - k) < AES_BLOCK_SIZE*2)
  9862. break;
  9863. }
  9864. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9865. if (ret != 0)
  9866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9867. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  9868. sizeof(i1));
  9869. #if defined(WOLFSSL_ASYNC_CRYPT)
  9870. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9871. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9872. WC_ASYNC_FLAG_NONE);
  9873. #else
  9874. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9875. #endif
  9876. #endif
  9877. if (ret != 0)
  9878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9879. for (i = 0; i < j; i++) {
  9880. if (large_input[i] != (byte)i) {
  9881. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9882. }
  9883. }
  9884. }
  9885. /* second, encrypt with a one-shot call then decrypt block by block. */
  9886. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  9887. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  9888. if (ret != 0)
  9889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9890. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  9891. sizeof(i1));
  9892. #if defined(WOLFSSL_ASYNC_CRYPT)
  9893. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9894. #endif
  9895. if (ret != 0)
  9896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9897. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  9898. if (ret != 0)
  9899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9900. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  9901. #if defined(WOLFSSL_ASYNC_CRYPT)
  9902. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9903. #endif
  9904. if (ret != 0)
  9905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9906. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  9907. if ((j - k) < AES_BLOCK_SIZE*2)
  9908. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  9909. else
  9910. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  9911. #if defined(WOLFSSL_ASYNC_CRYPT)
  9912. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  9913. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  9914. WC_ASYNC_FLAG_NONE);
  9915. #else
  9916. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  9917. #endif
  9918. #endif
  9919. if (ret != 0)
  9920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  9921. if ((j - k) < AES_BLOCK_SIZE*2)
  9922. break;
  9923. }
  9924. for (i = 0; i < j; i++) {
  9925. if (large_input[i] != (byte)i) {
  9926. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  9927. }
  9928. }
  9929. }
  9930. #endif /* WOLFSSL_AESXTS_STREAM */
  9931. }
  9932. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  9933. * !WOLFSSL_AFALG
  9934. */
  9935. out:
  9936. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9937. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  9938. !defined(WOLFSSL_NO_MALLOC)
  9939. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9940. #endif
  9941. if (aes_inited)
  9942. wc_AesXtsFree(aes);
  9943. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9944. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  9945. #endif
  9946. return ret;
  9947. }
  9948. #endif /* WOLFSSL_AES_128 */
  9949. #ifdef WOLFSSL_AES_192
  9950. static wc_test_ret_t aes_xts_192_test(void)
  9951. {
  9952. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9953. XtsAes *aes = NULL;
  9954. #else
  9955. XtsAes aes[1];
  9956. #endif
  9957. int aes_inited = 0;
  9958. wc_test_ret_t ret = 0;
  9959. unsigned char buf[AES_BLOCK_SIZE * 2 + 8];
  9960. unsigned char cipher[AES_BLOCK_SIZE * 2 + 8];
  9961. #ifdef WOLFSSL_AESXTS_STREAM
  9962. struct XtsAesStreamData stream;
  9963. #endif
  9964. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  9965. !defined(WOLFSSL_AFALG)
  9966. #define LARGE_XTS_SZ 1024
  9967. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  9968. byte* large_input = NULL;
  9969. #else
  9970. byte large_input[LARGE_XTS_SZ];
  9971. #endif
  9972. #endif
  9973. /* 192 bit key tests */
  9974. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  9975. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  9976. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  9977. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  9978. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  9979. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  9980. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3
  9981. };
  9982. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  9983. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  9984. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9985. };
  9986. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  9987. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9988. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c
  9989. };
  9990. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  9991. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  9992. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  9993. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  9994. };
  9995. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  9996. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4,
  9997. 0xdb, 0x4e, 0xd3, 0x69, 0xdf, 0x8e, 0x3a, 0xe0
  9998. };
  9999. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10000. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10001. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10002. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10003. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10004. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10005. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a
  10006. };
  10007. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10008. 0x5c, 0xf7, 0x9d, 0xb6, 0xc5, 0xcd, 0x99, 0x1a,
  10009. 0x1c, 0x78, 0x81, 0x42, 0x24, 0x95, 0x1e, 0x84
  10010. };
  10011. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10012. 0xbd, 0xc5, 0x46, 0x8f, 0xbc, 0x8d, 0x50, 0xa1,
  10013. 0x0d, 0x1c, 0x85, 0x7f, 0x79, 0x1c, 0x5c, 0xba,
  10014. 0xb3, 0x81, 0x0d, 0x0d, 0x73, 0xcf, 0x8f, 0x20,
  10015. 0x46, 0xb1, 0xd1, 0x9e, 0x7d, 0x5d, 0x8a, 0x56
  10016. };
  10017. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10018. 0x6c, 0xa6, 0xb5, 0x73, 0x48, 0xf1, 0x89, 0xfa,
  10019. 0xdd, 0x80, 0x72, 0x1f, 0xb8, 0x56, 0x0c, 0xa2,
  10020. 0x35, 0xd4, 0x08, 0xbf, 0x24, 0xcb, 0xec, 0xdb,
  10021. 0x81, 0xe0, 0xe6, 0x4f, 0x3d, 0x1c, 0x5c, 0x46
  10022. };
  10023. WOLFSSL_SMALL_STACK_STATIC unsigned char cp2[] = {
  10024. 0xe9, 0x58, 0xfe, 0xab, 0x66, 0xb4, 0xf1, 0x79,
  10025. 0x91, 0x3f, 0x91, 0xdc, 0x6f, 0xdf, 0xd6, 0xac,
  10026. 0x65, 0x37, 0x15, 0x53, 0xf1, 0x98, 0xab, 0xb4
  10027. };
  10028. #ifndef HAVE_FIPS /* FIPS requires different keys for main and tweak. */
  10029. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  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. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10035. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10036. };
  10037. WOLFSSL_SMALL_STACK_STATIC unsigned char i3[] = {
  10038. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10039. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10040. };
  10041. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  10042. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10043. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10044. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10045. 0x20, 0xff, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
  10046. 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
  10047. };
  10048. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  10049. 0xa4, 0xf2, 0x71, 0x5d, 0x80, 0x60, 0x68, 0xa0,
  10050. 0x80, 0x61, 0xd7, 0xc1, 0x55, 0xc8, 0x3a, 0x2e,
  10051. 0xd7, 0xf4, 0x62, 0xaf, 0xbd, 0x2d, 0xf9, 0x5f,
  10052. 0xe8, 0xc5, 0x99, 0x3d, 0x58, 0x3c, 0xeb, 0xba,
  10053. 0x86, 0xea, 0x2c, 0x7e, 0x1f, 0xba, 0x81, 0xde
  10054. };
  10055. #endif /* HAVE_FIPS */
  10056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10057. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10058. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10059. #endif
  10060. XMEMSET(buf, 0, sizeof(buf));
  10061. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10062. if (ret != 0)
  10063. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10064. else
  10065. aes_inited = 1;
  10066. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10067. if (ret != 0)
  10068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10069. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10070. #if defined(WOLFSSL_ASYNC_CRYPT)
  10071. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10072. #endif
  10073. if (ret != 0)
  10074. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10075. if (XMEMCMP(c2, buf, sizeof(c2)))
  10076. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10077. #ifdef WOLFSSL_AESXTS_STREAM
  10078. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10079. #if defined(WOLFSSL_ASYNC_CRYPT)
  10080. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10081. #endif
  10082. if (ret != 0)
  10083. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10084. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10085. #if defined(WOLFSSL_ASYNC_CRYPT)
  10086. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10087. #endif
  10088. if (ret != 0)
  10089. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10090. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10091. #if defined(WOLFSSL_ASYNC_CRYPT)
  10092. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10093. #endif
  10094. if (ret != 0)
  10095. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10096. if (XMEMCMP(c2, buf, sizeof(c2)))
  10097. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10098. #endif /* WOLFSSL_AESXTS_STREAM */
  10099. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10100. defined(WC_C_DYNAMIC_FALLBACK)
  10101. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10102. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10103. #if defined(WOLFSSL_ASYNC_CRYPT)
  10104. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10105. #endif
  10106. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10107. if (ret != 0)
  10108. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10109. if (XMEMCMP(c2, buf, sizeof(c2)))
  10110. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10111. #endif
  10112. XMEMSET(buf, 0, sizeof(buf));
  10113. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10114. if (ret != 0)
  10115. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10116. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10117. #if defined(WOLFSSL_ASYNC_CRYPT)
  10118. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10119. #endif
  10120. if (ret != 0)
  10121. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10122. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10123. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10124. #ifdef WOLFSSL_AESXTS_STREAM
  10125. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10126. #if defined(WOLFSSL_ASYNC_CRYPT)
  10127. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10128. #endif
  10129. if (ret != 0)
  10130. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10131. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10132. #if defined(WOLFSSL_ASYNC_CRYPT)
  10133. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10134. #endif
  10135. if (ret != 0)
  10136. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10137. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10138. #if defined(WOLFSSL_ASYNC_CRYPT)
  10139. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10140. #endif
  10141. if (ret != 0)
  10142. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10143. if (XMEMCMP(c1, buf, sizeof(c1)))
  10144. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10145. #endif /* WOLFSSL_AESXTS_STREAM */
  10146. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10147. defined(WC_C_DYNAMIC_FALLBACK)
  10148. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10149. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10150. #if defined(WOLFSSL_ASYNC_CRYPT)
  10151. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10152. #endif
  10153. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10154. if (ret != 0)
  10155. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10156. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10157. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10158. #endif
  10159. /* partial block encryption test */
  10160. XMEMSET(cipher, 0, sizeof(cipher));
  10161. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10162. #if defined(WOLFSSL_ASYNC_CRYPT)
  10163. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10164. #endif
  10165. if (ret != 0)
  10166. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10167. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10168. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10169. #ifdef WOLFSSL_AESXTS_STREAM
  10170. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10171. #if defined(WOLFSSL_ASYNC_CRYPT)
  10172. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10173. #endif
  10174. if (ret != 0)
  10175. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10176. ret = wc_AesXtsEncryptFinal(aes, buf, pp, sizeof(pp), &stream);
  10177. #if defined(WOLFSSL_ASYNC_CRYPT)
  10178. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10179. #endif
  10180. if (ret != 0)
  10181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10182. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10183. #if defined(WOLFSSL_ASYNC_CRYPT)
  10184. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10185. #endif
  10186. if (ret != 0)
  10187. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10188. if (XMEMCMP(cp2, buf, sizeof(cp2)))
  10189. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10190. #endif /* WOLFSSL_AESXTS_STREAM */
  10191. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10192. defined(WC_C_DYNAMIC_FALLBACK)
  10193. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10194. XMEMSET(cipher, 0, sizeof(cipher));
  10195. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10196. #if defined(WOLFSSL_ASYNC_CRYPT)
  10197. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10198. #endif
  10199. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10200. if (ret != 0)
  10201. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10202. if (XMEMCMP(cp2, cipher, sizeof(cp2)))
  10203. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10204. #endif
  10205. /* partial block decrypt test */
  10206. XMEMSET(buf, 0, sizeof(buf));
  10207. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10208. if (ret != 0)
  10209. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10210. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10211. #if defined(WOLFSSL_ASYNC_CRYPT)
  10212. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10213. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10214. #else
  10215. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10216. #endif
  10217. #endif
  10218. if (ret != 0)
  10219. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10220. if (XMEMCMP(pp, buf, sizeof(pp)))
  10221. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10222. #ifdef WOLFSSL_AESXTS_STREAM
  10223. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10224. #if defined(WOLFSSL_ASYNC_CRYPT)
  10225. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10226. #endif
  10227. if (ret != 0)
  10228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10229. ret = wc_AesXtsDecryptFinal(aes, buf, cipher, sizeof(pp), &stream);
  10230. #if defined(WOLFSSL_ASYNC_CRYPT)
  10231. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10232. #endif
  10233. if (ret != 0)
  10234. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10235. if (XMEMCMP(pp, buf, sizeof(pp)))
  10236. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10237. #endif /* WOLFSSL_AESXTS_STREAM */
  10238. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10239. defined(WC_C_DYNAMIC_FALLBACK)
  10240. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10241. XMEMSET(buf, 0, sizeof(buf));
  10242. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10243. #if defined(WOLFSSL_ASYNC_CRYPT)
  10244. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10245. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10246. #else
  10247. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10248. #endif
  10249. #endif
  10250. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10251. if (ret != 0)
  10252. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10253. if (XMEMCMP(pp, buf, sizeof(pp)))
  10254. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10255. #endif
  10256. /* NIST decrypt test vector */
  10257. XMEMSET(buf, 0, sizeof(buf));
  10258. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10259. #if defined(WOLFSSL_ASYNC_CRYPT)
  10260. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10261. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10262. #else
  10263. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10264. #endif
  10265. #endif
  10266. if (ret != 0)
  10267. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10268. if (XMEMCMP(p1, buf, sizeof(p1)))
  10269. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10270. #ifdef WOLFSSL_AESXTS_STREAM
  10271. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10272. #if defined(WOLFSSL_ASYNC_CRYPT)
  10273. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10274. #endif
  10275. if (ret != 0)
  10276. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10277. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10278. #if defined(WOLFSSL_ASYNC_CRYPT)
  10279. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10280. #endif
  10281. if (ret != 0)
  10282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10283. if (XMEMCMP(p1, buf, sizeof(p1)))
  10284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10285. #endif /* WOLFSSL_AESXTS_STREAM */
  10286. #if defined(DEBUG_VECTOR_REGISTER_ACCESS_AESXTS) && \
  10287. defined(WC_C_DYNAMIC_FALLBACK)
  10288. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  10289. XMEMSET(buf, 0, sizeof(buf));
  10290. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10291. #if defined(WOLFSSL_ASYNC_CRYPT)
  10292. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10293. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10294. #else
  10295. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10296. #endif
  10297. #endif
  10298. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  10299. if (ret != 0)
  10300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10301. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  10302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10303. #endif
  10304. /* fail case with decrypting using wrong key */
  10305. XMEMSET(buf, 0, sizeof(buf));
  10306. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10307. #if defined(WOLFSSL_ASYNC_CRYPT)
  10308. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10309. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10310. #else
  10311. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10312. #endif
  10313. #endif
  10314. if (ret != 0)
  10315. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10316. if (XMEMCMP(p2, buf, sizeof(p2)) == 0) /* fail case with wrong key */
  10317. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10318. /* set correct key and retest */
  10319. XMEMSET(buf, 0, sizeof(buf));
  10320. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10321. if (ret != 0)
  10322. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10323. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10324. #if defined(WOLFSSL_ASYNC_CRYPT)
  10325. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10326. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10327. #else
  10328. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10329. #endif
  10330. #endif
  10331. if (ret != 0)
  10332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10333. if (XMEMCMP(p2, buf, sizeof(p2)))
  10334. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10335. #ifndef HAVE_FIPS
  10336. /* Test ciphertext stealing in-place. */
  10337. XMEMCPY(buf, p3, sizeof(p3));
  10338. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  10339. if (ret != 0)
  10340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10341. ret = wc_AesXtsEncrypt(aes, buf, buf, sizeof(p3), i3, sizeof(i3));
  10342. #if defined(WOLFSSL_ASYNC_CRYPT)
  10343. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10344. #endif
  10345. if (ret != 0)
  10346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10347. if (XMEMCMP(c3, buf, sizeof(c3)))
  10348. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10349. #ifdef WOLFSSL_AESXTS_STREAM
  10350. ret = wc_AesXtsEncryptInit(aes, i3, sizeof(i3), &stream);
  10351. #if defined(WOLFSSL_ASYNC_CRYPT)
  10352. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10353. #endif
  10354. if (ret != 0)
  10355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10356. ret = wc_AesXtsEncryptUpdate(aes, buf, p3, AES_BLOCK_SIZE, &stream);
  10357. #if defined(WOLFSSL_ASYNC_CRYPT)
  10358. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10359. #endif
  10360. if (ret != 0)
  10361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10362. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p3 + AES_BLOCK_SIZE, sizeof(p3) - AES_BLOCK_SIZE, &stream);
  10363. #if defined(WOLFSSL_ASYNC_CRYPT)
  10364. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10365. #endif
  10366. if (ret != 0)
  10367. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10368. if (XMEMCMP(c3, buf, sizeof(c3)))
  10369. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10370. #endif /* WOLFSSL_AESXTS_STREAM */
  10371. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  10372. if (ret != 0)
  10373. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10374. ret = wc_AesXtsDecrypt(aes, buf, buf, sizeof(c3), i3, sizeof(i3));
  10375. #if defined(WOLFSSL_ASYNC_CRYPT)
  10376. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10377. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10378. #else
  10379. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10380. #endif
  10381. #endif
  10382. if (ret != 0)
  10383. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10384. if (XMEMCMP(p3, buf, sizeof(p3)))
  10385. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10386. #ifdef WOLFSSL_AESXTS_STREAM
  10387. ret = wc_AesXtsDecryptInit(aes, i3, sizeof(i3), &stream);
  10388. #if defined(WOLFSSL_ASYNC_CRYPT)
  10389. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10390. #endif
  10391. if (ret != 0)
  10392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10393. ret = wc_AesXtsDecryptUpdate(aes, buf, c3, AES_BLOCK_SIZE, &stream);
  10394. #if defined(WOLFSSL_ASYNC_CRYPT)
  10395. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10396. #endif
  10397. if (ret != 0)
  10398. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10399. ret = wc_AesXtsDecryptFinal(aes, buf + AES_BLOCK_SIZE, c3 + AES_BLOCK_SIZE, sizeof(c3) - AES_BLOCK_SIZE, &stream);
  10400. #if defined(WOLFSSL_ASYNC_CRYPT)
  10401. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10402. #endif
  10403. if (ret != 0)
  10404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10405. if (XMEMCMP(p3, buf, sizeof(p3)))
  10406. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10407. #endif /* WOLFSSL_AESXTS_STREAM */
  10408. #endif /* !HAVE_FIPS */
  10409. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10410. !defined(WOLFSSL_AFALG)
  10411. {
  10412. int i;
  10413. int j;
  10414. #ifdef WOLFSSL_AESXTS_STREAM
  10415. int k;
  10416. #endif
  10417. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10418. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10419. DYNAMIC_TYPE_TMP_BUFFER);
  10420. if (large_input == NULL)
  10421. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10422. #endif
  10423. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10424. large_input[i] = (byte)i;
  10425. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10426. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10427. if (ret != 0)
  10428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10429. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10430. sizeof(i1));
  10431. #if defined(WOLFSSL_ASYNC_CRYPT)
  10432. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10433. #endif
  10434. if (ret != 0)
  10435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10436. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10437. if (ret != 0)
  10438. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10439. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10440. sizeof(i1));
  10441. #if defined(WOLFSSL_ASYNC_CRYPT)
  10442. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10443. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10444. WC_ASYNC_FLAG_NONE);
  10445. #else
  10446. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10447. #endif
  10448. #endif
  10449. if (ret != 0)
  10450. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10451. for (i = 0; i < j; i++) {
  10452. if (large_input[i] != (byte)i) {
  10453. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10454. }
  10455. }
  10456. }
  10457. #ifdef WOLFSSL_AESXTS_STREAM
  10458. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10459. large_input[i] = (byte)i;
  10460. /* first, encrypt block by block then decrypt with a one-shot call. */
  10461. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10462. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10463. if (ret != 0)
  10464. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10465. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10466. #if defined(WOLFSSL_ASYNC_CRYPT)
  10467. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10468. #endif
  10469. if (ret != 0)
  10470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10471. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10472. if ((j - k) < AES_BLOCK_SIZE*2)
  10473. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10474. else
  10475. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10476. #if defined(WOLFSSL_ASYNC_CRYPT)
  10477. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10478. #endif
  10479. if (ret != 0)
  10480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10481. if ((j - k) < AES_BLOCK_SIZE*2)
  10482. break;
  10483. }
  10484. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10485. if (ret != 0)
  10486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10487. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10488. sizeof(i1));
  10489. #if defined(WOLFSSL_ASYNC_CRYPT)
  10490. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10491. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10492. WC_ASYNC_FLAG_NONE);
  10493. #else
  10494. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10495. #endif
  10496. #endif
  10497. if (ret != 0)
  10498. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10499. for (i = 0; i < j; i++) {
  10500. if (large_input[i] != (byte)i) {
  10501. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10502. }
  10503. }
  10504. }
  10505. /* second, encrypt with a one-shot call then decrypt block by block. */
  10506. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10507. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10508. if (ret != 0)
  10509. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10510. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10511. sizeof(i1));
  10512. #if defined(WOLFSSL_ASYNC_CRYPT)
  10513. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10514. #endif
  10515. if (ret != 0)
  10516. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10517. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10518. if (ret != 0)
  10519. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10520. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10521. #if defined(WOLFSSL_ASYNC_CRYPT)
  10522. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10523. #endif
  10524. if (ret != 0)
  10525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10526. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10527. if ((j - k) < AES_BLOCK_SIZE*2)
  10528. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10529. else
  10530. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10531. #if defined(WOLFSSL_ASYNC_CRYPT)
  10532. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10533. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10534. WC_ASYNC_FLAG_NONE);
  10535. #else
  10536. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10537. #endif
  10538. #endif
  10539. if (ret != 0)
  10540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10541. if ((j - k) < AES_BLOCK_SIZE*2)
  10542. break;
  10543. }
  10544. for (i = 0; i < j; i++) {
  10545. if (large_input[i] != (byte)i) {
  10546. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10547. }
  10548. }
  10549. }
  10550. #endif /* WOLFSSL_AESXTS_STREAM */
  10551. }
  10552. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10553. * !WOLFSSL_AFALG
  10554. */
  10555. out:
  10556. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10557. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10558. !defined(WOLFSSL_NO_MALLOC)
  10559. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10560. #endif
  10561. if (aes_inited)
  10562. wc_AesXtsFree(aes);
  10563. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10564. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10565. #endif
  10566. return ret;
  10567. }
  10568. #endif /* WOLFSSL_AES_192 */
  10569. #ifdef WOLFSSL_AES_256
  10570. static wc_test_ret_t aes_xts_256_test(void)
  10571. {
  10572. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10573. XtsAes *aes = NULL;
  10574. #else
  10575. XtsAes aes[1];
  10576. #endif
  10577. int aes_inited = 0;
  10578. wc_test_ret_t ret = 0;
  10579. unsigned char buf[AES_BLOCK_SIZE * 3];
  10580. unsigned char cipher[AES_BLOCK_SIZE * 3];
  10581. #ifdef WOLFSSL_AESXTS_STREAM
  10582. struct XtsAesStreamData stream;
  10583. #endif
  10584. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10585. !defined(WOLFSSL_AFALG)
  10586. #define LARGE_XTS_SZ 1024
  10587. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10588. byte* large_input = NULL;
  10589. #else
  10590. byte large_input[LARGE_XTS_SZ];
  10591. #endif
  10592. #endif
  10593. /* 256 key tests */
  10594. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10595. 0x1e, 0xa6, 0x61, 0xc5, 0x8d, 0x94, 0x3a, 0x0e,
  10596. 0x48, 0x01, 0xe4, 0x2f, 0x4b, 0x09, 0x47, 0x14,
  10597. 0x9e, 0x7f, 0x9f, 0x8e, 0x3e, 0x68, 0xd0, 0xc7,
  10598. 0x50, 0x52, 0x10, 0xbd, 0x31, 0x1a, 0x0e, 0x7c,
  10599. 0xd6, 0xe1, 0x3f, 0xfd, 0xf2, 0x41, 0x8d, 0x8d,
  10600. 0x19, 0x11, 0xc0, 0x04, 0xcd, 0xa5, 0x8d, 0xa3,
  10601. 0xd6, 0x19, 0xb7, 0xe2, 0xb9, 0x14, 0x1e, 0x58,
  10602. 0x31, 0x8e, 0xea, 0x39, 0x2c, 0xf4, 0x1b, 0x08
  10603. };
  10604. WOLFSSL_SMALL_STACK_STATIC unsigned char i1[] = {
  10605. 0xad, 0xf8, 0xd9, 0x26, 0x27, 0x46, 0x4a, 0xd2,
  10606. 0xf0, 0x42, 0x8e, 0x84, 0xa9, 0xf8, 0x75, 0x64
  10607. };
  10608. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10609. 0x2e, 0xed, 0xea, 0x52, 0xcd, 0x82, 0x15, 0xe1,
  10610. 0xac, 0xc6, 0x47, 0xe8, 0x10, 0xbb, 0xc3, 0x64,
  10611. 0x2e, 0x87, 0x28, 0x7f, 0x8d, 0x2e, 0x57, 0xe3,
  10612. 0x6c, 0x0a, 0x24, 0xfb, 0xc1, 0x2a, 0x20, 0x2e
  10613. };
  10614. /* plain text test of partial block is not from NIST test vector list */
  10615. WOLFSSL_SMALL_STACK_STATIC unsigned char pp[] = {
  10616. 0xeb, 0xab, 0xce, 0x95, 0xb1, 0x4d, 0x3c, 0x8d,
  10617. 0x6f, 0xb3, 0x50, 0x39, 0x07, 0x90, 0x31, 0x1c,
  10618. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  10619. };
  10620. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10621. 0xcb, 0xaa, 0xd0, 0xe2, 0xf6, 0xce, 0xa3, 0xf5,
  10622. 0x0b, 0x37, 0xf9, 0x34, 0xd4, 0x6a, 0x9b, 0x13,
  10623. 0x0b, 0x9d, 0x54, 0xf0, 0x7e, 0x34, 0xf3, 0x6a,
  10624. 0xf7, 0x93, 0xe8, 0x6f, 0x73, 0xc6, 0xd7, 0xdb
  10625. };
  10626. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  10627. 0xad, 0x50, 0x4b, 0x85, 0xd7, 0x51, 0xbf, 0xba,
  10628. 0x69, 0x13, 0xb4, 0xcc, 0x79, 0xb6, 0x5a, 0x62,
  10629. 0xf7, 0xf3, 0x9d, 0x36, 0x0f, 0x35, 0xb5, 0xec,
  10630. 0x4a, 0x7e, 0x95, 0xbd, 0x9b, 0xa5, 0xf2, 0xec,
  10631. 0xc1, 0xd7, 0x7e, 0xa3, 0xc3, 0x74, 0xbd, 0x4b,
  10632. 0x13, 0x1b, 0x07, 0x83, 0x87, 0xdd, 0x55, 0x5a,
  10633. 0xb5, 0xb0, 0xc7, 0xe5, 0x2d, 0xb5, 0x06, 0x12,
  10634. 0xd2, 0xb5, 0x3a, 0xcb, 0x47, 0x8a, 0x53, 0xb4
  10635. };
  10636. WOLFSSL_SMALL_STACK_STATIC unsigned char i2[] = {
  10637. 0xe6, 0x42, 0x19, 0xed, 0xe0, 0xe1, 0xc2, 0xa0,
  10638. 0x0e, 0xf5, 0x58, 0x6a, 0xc4, 0x9b, 0xeb, 0x6f
  10639. };
  10640. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  10641. 0x24, 0xcb, 0x76, 0x22, 0x55, 0xb5, 0xa8, 0x00,
  10642. 0xf4, 0x6e, 0x80, 0x60, 0x56, 0x9e, 0x05, 0x53,
  10643. 0xbc, 0xfe, 0x86, 0x55, 0x3b, 0xca, 0xd5, 0x89,
  10644. 0xc7, 0x54, 0x1a, 0x73, 0xac, 0xc3, 0x9a, 0xbd,
  10645. 0x53, 0xc4, 0x07, 0x76, 0xd8, 0xe8, 0x22, 0x61,
  10646. 0x9e, 0xa9, 0xad, 0x77, 0xa0, 0x13, 0x4c, 0xfc
  10647. };
  10648. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  10649. 0xa3, 0xc6, 0xf3, 0xf3, 0x82, 0x79, 0x5b, 0x10,
  10650. 0x87, 0xd7, 0x02, 0x50, 0xdb, 0x2c, 0xd3, 0xb1,
  10651. 0xa1, 0x62, 0xa8, 0xb6, 0xdc, 0x12, 0x60, 0x61,
  10652. 0xc1, 0x0a, 0x84, 0xa5, 0x85, 0x3f, 0x3a, 0x89,
  10653. 0xe6, 0x6c, 0xdb, 0xb7, 0x9a, 0xb4, 0x28, 0x9b,
  10654. 0xc3, 0xea, 0xd8, 0x10, 0xe9, 0xc0, 0xaf, 0x92
  10655. };
  10656. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10657. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  10658. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  10659. #endif
  10660. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY) \
  10661. && !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  10662. ret = EVP_test(wolfSSL_EVP_aes_256_xts(), k2, i2, p2, sizeof(p2), c2, sizeof(c2));
  10663. if (ret != 0) {
  10664. printf("EVP_aes_256_xts failed\n");
  10665. goto out;
  10666. }
  10667. #endif
  10668. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  10669. if (ret != 0)
  10670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10671. else
  10672. aes_inited = 1;
  10673. XMEMSET(buf, 0, sizeof(buf));
  10674. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  10675. if (ret != 0)
  10676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10677. ret = wc_AesXtsEncrypt(aes, buf, p2, sizeof(p2), i2, sizeof(i2));
  10678. #if defined(WOLFSSL_ASYNC_CRYPT)
  10679. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10680. #endif
  10681. if (ret != 0)
  10682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10683. if (XMEMCMP(c2, buf, sizeof(c2)))
  10684. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10685. #ifdef WOLFSSL_AESXTS_STREAM
  10686. ret = wc_AesXtsEncryptInit(aes, i2, sizeof(i2), &stream);
  10687. #if defined(WOLFSSL_ASYNC_CRYPT)
  10688. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10689. #endif
  10690. if (ret != 0)
  10691. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10692. ret = wc_AesXtsEncryptUpdate(aes, buf, p2, AES_BLOCK_SIZE, &stream);
  10693. #if defined(WOLFSSL_ASYNC_CRYPT)
  10694. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10695. #endif
  10696. if (ret != 0)
  10697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10698. ret = wc_AesXtsEncryptFinal(aes, buf + AES_BLOCK_SIZE, p2 + AES_BLOCK_SIZE, sizeof(p2) - AES_BLOCK_SIZE, &stream);
  10699. #if defined(WOLFSSL_ASYNC_CRYPT)
  10700. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10701. #endif
  10702. if (ret != 0)
  10703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10704. if (XMEMCMP(c2, buf, sizeof(c2)))
  10705. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10706. #endif /* WOLFSSL_AESXTS_STREAM */
  10707. XMEMSET(buf, 0, sizeof(buf));
  10708. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10709. if (ret != 0)
  10710. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10711. ret = wc_AesXtsEncrypt(aes, buf, p1, sizeof(p1), i1, sizeof(i1));
  10712. #if defined(WOLFSSL_ASYNC_CRYPT)
  10713. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10714. #endif
  10715. if (ret != 0)
  10716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10717. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  10718. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10719. #ifdef WOLFSSL_AESXTS_STREAM
  10720. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10721. #if defined(WOLFSSL_ASYNC_CRYPT)
  10722. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10723. #endif
  10724. if (ret != 0)
  10725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10726. ret = wc_AesXtsEncryptUpdate(aes, buf, p1, sizeof(p1), &stream);
  10727. #if defined(WOLFSSL_ASYNC_CRYPT)
  10728. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10729. #endif
  10730. if (ret != 0)
  10731. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10732. ret = wc_AesXtsEncryptFinal(aes, buf, NULL, 0, &stream);
  10733. #if defined(WOLFSSL_ASYNC_CRYPT)
  10734. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10735. #endif
  10736. if (ret != 0)
  10737. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10738. if (XMEMCMP(c1, buf, sizeof(c1)))
  10739. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10740. #endif /* WOLFSSL_AESXTS_STREAM */
  10741. /* partial block encryption test */
  10742. XMEMSET(cipher, 0, sizeof(cipher));
  10743. ret = wc_AesXtsEncrypt(aes, cipher, pp, sizeof(pp), i1, sizeof(i1));
  10744. #if defined(WOLFSSL_ASYNC_CRYPT)
  10745. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10746. #endif
  10747. if (ret != 0)
  10748. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10749. /* partial block decrypt test */
  10750. XMEMSET(buf, 0, sizeof(buf));
  10751. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10752. if (ret != 0)
  10753. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10754. ret = wc_AesXtsDecrypt(aes, buf, cipher, sizeof(pp), i1, sizeof(i1));
  10755. #if defined(WOLFSSL_ASYNC_CRYPT)
  10756. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10757. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10758. #else
  10759. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10760. #endif
  10761. #endif
  10762. if (ret != 0)
  10763. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10764. if (XMEMCMP(pp, buf, sizeof(pp)))
  10765. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10766. /* NIST decrypt test vector */
  10767. XMEMSET(buf, 0, sizeof(buf));
  10768. ret = wc_AesXtsDecrypt(aes, buf, c1, sizeof(c1), i1, sizeof(i1));
  10769. #if defined(WOLFSSL_ASYNC_CRYPT)
  10770. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10771. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10772. #else
  10773. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10774. #endif
  10775. #endif
  10776. if (ret != 0)
  10777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10778. if (XMEMCMP(p1, buf, sizeof(p1)))
  10779. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10780. #ifdef WOLFSSL_AESXTS_STREAM
  10781. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10782. #if defined(WOLFSSL_ASYNC_CRYPT)
  10783. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10784. #endif
  10785. if (ret != 0)
  10786. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10787. ret = wc_AesXtsDecryptFinal(aes, buf, c1, sizeof(c1), &stream);
  10788. #if defined(WOLFSSL_ASYNC_CRYPT)
  10789. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10790. #endif
  10791. if (ret != 0)
  10792. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10793. if (XMEMCMP(p1, buf, sizeof(p1)))
  10794. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10795. #endif /* WOLFSSL_AESXTS_STREAM */
  10796. XMEMSET(buf, 0, sizeof(buf));
  10797. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  10798. if (ret != 0)
  10799. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10800. ret = wc_AesXtsDecrypt(aes, buf, c2, sizeof(c2), i2, sizeof(i2));
  10801. #if defined(WOLFSSL_ASYNC_CRYPT)
  10802. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10803. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  10804. #else
  10805. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10806. #endif
  10807. #endif
  10808. if (ret != 0)
  10809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10810. if (XMEMCMP(p2, buf, sizeof(p2)))
  10811. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10812. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10813. !defined(WOLFSSL_AFALG)
  10814. {
  10815. int i;
  10816. int j;
  10817. #ifdef WOLFSSL_AESXTS_STREAM
  10818. int k;
  10819. #endif
  10820. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10821. large_input = (byte *)XMALLOC(LARGE_XTS_SZ, HEAP_HINT,
  10822. DYNAMIC_TYPE_TMP_BUFFER);
  10823. if (large_input == NULL)
  10824. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);
  10825. #endif
  10826. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10827. large_input[i] = (byte)i;
  10828. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10829. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10830. if (ret != 0)
  10831. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10832. ret = wc_AesXtsEncrypt(aes, large_input, large_input, j, i1,
  10833. sizeof(i1));
  10834. #if defined(WOLFSSL_ASYNC_CRYPT)
  10835. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10836. #endif
  10837. if (ret != 0)
  10838. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10839. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10840. if (ret != 0)
  10841. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10842. ret = wc_AesXtsDecrypt(aes, large_input, large_input, j, i1,
  10843. sizeof(i1));
  10844. #if defined(WOLFSSL_ASYNC_CRYPT)
  10845. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10846. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10847. WC_ASYNC_FLAG_NONE);
  10848. #else
  10849. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10850. #endif
  10851. #endif
  10852. if (ret != 0)
  10853. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10854. for (i = 0; i < j; i++) {
  10855. if (large_input[i] != (byte)i) {
  10856. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10857. }
  10858. }
  10859. }
  10860. #ifdef WOLFSSL_AESXTS_STREAM
  10861. for (i = 0; i < (int)LARGE_XTS_SZ; i++)
  10862. large_input[i] = (byte)i;
  10863. /* first, encrypt block by block then decrypt with a one-shot call. */
  10864. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10865. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10866. if (ret != 0)
  10867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10868. ret = wc_AesXtsEncryptInit(aes, i1, sizeof(i1), &stream);
  10869. #if defined(WOLFSSL_ASYNC_CRYPT)
  10870. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10871. #endif
  10872. if (ret != 0)
  10873. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10874. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10875. if ((j - k) < AES_BLOCK_SIZE*2)
  10876. ret = wc_AesXtsEncryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10877. else
  10878. ret = wc_AesXtsEncryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10879. #if defined(WOLFSSL_ASYNC_CRYPT)
  10880. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10881. #endif
  10882. if (ret != 0)
  10883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10884. if ((j - k) < AES_BLOCK_SIZE*2)
  10885. break;
  10886. }
  10887. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10888. if (ret != 0)
  10889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10890. ret = wc_AesXtsDecrypt(aes, large_input, large_input, (word32)j, i1,
  10891. sizeof(i1));
  10892. #if defined(WOLFSSL_ASYNC_CRYPT)
  10893. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10894. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10895. WC_ASYNC_FLAG_NONE);
  10896. #else
  10897. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10898. #endif
  10899. #endif
  10900. if (ret != 0)
  10901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10902. for (i = 0; i < j; i++) {
  10903. if (large_input[i] != (byte)i) {
  10904. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10905. }
  10906. }
  10907. }
  10908. /* second, encrypt with a one-shot call then decrypt block by block. */
  10909. for (j = 16; j < (int)LARGE_XTS_SZ; j++) {
  10910. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  10911. if (ret != 0)
  10912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10913. ret = wc_AesXtsEncrypt(aes, large_input, large_input, (word32)j, i1,
  10914. sizeof(i1));
  10915. #if defined(WOLFSSL_ASYNC_CRYPT)
  10916. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10917. #endif
  10918. if (ret != 0)
  10919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10920. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  10921. if (ret != 0)
  10922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10923. ret = wc_AesXtsDecryptInit(aes, i1, sizeof(i1), &stream);
  10924. #if defined(WOLFSSL_ASYNC_CRYPT)
  10925. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10926. #endif
  10927. if (ret != 0)
  10928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10929. for (k = 0; k < j; k += AES_BLOCK_SIZE) {
  10930. if ((j - k) < AES_BLOCK_SIZE*2)
  10931. ret = wc_AesXtsDecryptFinal(aes, large_input + k, large_input + k, j - k, &stream);
  10932. else
  10933. ret = wc_AesXtsDecryptUpdate(aes, large_input + k, large_input + k, AES_BLOCK_SIZE, &stream);
  10934. #if defined(WOLFSSL_ASYNC_CRYPT)
  10935. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  10936. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev,
  10937. WC_ASYNC_FLAG_NONE);
  10938. #else
  10939. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  10940. #endif
  10941. #endif
  10942. if (ret != 0)
  10943. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  10944. if ((j - k) < AES_BLOCK_SIZE*2)
  10945. break;
  10946. }
  10947. for (i = 0; i < j; i++) {
  10948. if (large_input[i] != (byte)i) {
  10949. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  10950. }
  10951. }
  10952. }
  10953. #endif /* WOLFSSL_AESXTS_STREAM */
  10954. }
  10955. #endif /* !BENCH_EMBEDDED && !HAVE_CAVIUM &&
  10956. * !WOLFSSL_AFALG
  10957. */
  10958. out:
  10959. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  10960. !defined(WOLFSSL_AFALG) && defined(WOLFSSL_SMALL_STACK) && \
  10961. !defined(WOLFSSL_NO_MALLOC)
  10962. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10963. #endif
  10964. if (aes_inited)
  10965. wc_AesXtsFree(aes);
  10966. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10967. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  10968. #endif
  10969. return ret;
  10970. }
  10971. #endif /* WOLFSSL_AES_256 */
  10972. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  10973. /* both 128 and 256 bit key test */
  10974. static wc_test_ret_t aes_xts_sector_test(void)
  10975. {
  10976. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  10977. XtsAes *aes = NULL;
  10978. #else
  10979. XtsAes aes[1];
  10980. #endif
  10981. int aes_inited = 0;
  10982. wc_test_ret_t ret = 0;
  10983. unsigned char buf[AES_BLOCK_SIZE * 2];
  10984. /* 128 key tests */
  10985. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  10986. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  10987. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  10988. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  10989. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  10990. };
  10991. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  10992. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  10993. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  10994. };
  10995. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  10996. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  10997. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  10998. };
  10999. word64 s1 = 141;
  11000. /* 256 key tests */
  11001. WOLFSSL_SMALL_STACK_STATIC unsigned char k2[] = {
  11002. 0xef, 0x01, 0x0c, 0xa1, 0xa3, 0x66, 0x3e, 0x32,
  11003. 0x53, 0x43, 0x49, 0xbc, 0x0b, 0xae, 0x62, 0x23,
  11004. 0x2a, 0x15, 0x73, 0x34, 0x85, 0x68, 0xfb, 0x9e,
  11005. 0xf4, 0x17, 0x68, 0xa7, 0x67, 0x4f, 0x50, 0x7a,
  11006. 0x72, 0x7f, 0x98, 0x75, 0x53, 0x97, 0xd0, 0xe0,
  11007. 0xaa, 0x32, 0xf8, 0x30, 0x33, 0x8c, 0xc7, 0xa9,
  11008. 0x26, 0xc7, 0x73, 0xf0, 0x9e, 0x57, 0xb3, 0x57,
  11009. 0xcd, 0x15, 0x6a, 0xfb, 0xca, 0x46, 0xe1, 0xa0
  11010. };
  11011. WOLFSSL_SMALL_STACK_STATIC unsigned char p2[] = {
  11012. 0xed, 0x98, 0xe0, 0x17, 0x70, 0xa8, 0x53, 0xb4,
  11013. 0x9d, 0xb9, 0xe6, 0xaa, 0xf8, 0x8f, 0x0a, 0x41,
  11014. 0xb9, 0xb5, 0x6e, 0x91, 0xa5, 0xa2, 0xb1, 0x1d,
  11015. 0x40, 0x52, 0x92, 0x54, 0xf5, 0x52, 0x3e, 0x75
  11016. };
  11017. WOLFSSL_SMALL_STACK_STATIC unsigned char c2[] = {
  11018. 0xca, 0x20, 0xc5, 0x5e, 0x8d, 0xc1, 0x49, 0x68,
  11019. 0x7d, 0x25, 0x41, 0xde, 0x39, 0xc3, 0xdf, 0x63,
  11020. 0x00, 0xbb, 0x5a, 0x16, 0x3c, 0x10, 0xce, 0xd3,
  11021. 0x66, 0x6b, 0x13, 0x57, 0xdb, 0x8b, 0xd3, 0x9d
  11022. };
  11023. word64 s2 = 187;
  11024. #if !defined(BENCH_EMBEDDED) && \
  11025. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11026. /* Sector size for encrypt/decrypt consecutive sectors testcase */
  11027. word32 sectorSz = 512;
  11028. unsigned char data[550];
  11029. WOLFSSL_SMALL_STACK_STATIC unsigned char k3[] = {
  11030. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11031. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  11032. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  11033. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  11034. };
  11035. WOLFSSL_SMALL_STACK_STATIC unsigned char p3[] = {
  11036. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11037. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11038. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11039. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11040. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11041. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11042. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11043. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11044. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11045. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11046. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11047. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11048. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11049. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11050. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11051. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11052. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11053. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11054. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11055. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11056. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11057. 0xfc, 0xfd, 0xfe, 0xff,
  11058. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11059. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11060. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  11061. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  11062. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
  11063. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  11064. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  11065. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  11066. 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  11067. 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
  11068. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81, 0x82, 0x83,
  11069. 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  11070. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b,
  11071. 0x9c, 0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  11072. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3,
  11073. 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
  11074. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb,
  11075. 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  11076. 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3,
  11077. 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
  11078. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb,
  11079. 0xfc, 0xfd, 0xfe, 0xff,
  11080. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
  11081. 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  11082. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  11083. };
  11084. WOLFSSL_SMALL_STACK_STATIC unsigned char c3[] = {
  11085. 0xb9, 0x6b, 0x2b, 0xfd, 0x61, 0x87, 0x84, 0xd5, 0x26, 0xd2, 0x8c, 0x62,
  11086. 0x63, 0x01, 0xca, 0x46, 0xb1, 0x82, 0xfa, 0xdc, 0xbc, 0x32, 0x18, 0xe9,
  11087. 0xda, 0xe6, 0xda, 0xd1, 0x1a, 0x52, 0x77, 0xca, 0xdb, 0x0e, 0xbe, 0x37,
  11088. 0x88, 0x36, 0x1c, 0x87, 0x16, 0x60, 0xfe, 0xa8, 0x9e, 0xf6, 0x48, 0x64,
  11089. 0x94, 0x34, 0x64, 0xed, 0xf6, 0x9a, 0xc5, 0x28, 0xc9, 0xed, 0x64, 0x80,
  11090. 0x85, 0xd8, 0x93, 0xa7, 0x50, 0xb1, 0x9d, 0x2f, 0x1e, 0x34, 0xcc, 0xb4,
  11091. 0x03, 0xfb, 0x6b, 0x43, 0x21, 0xa8, 0x5b, 0xc6, 0x59, 0x13, 0xd2, 0xb5,
  11092. 0xf5, 0x7b, 0xf6, 0xb2, 0xa4, 0x7a, 0xd2, 0x50, 0x26, 0xcb, 0xa4, 0x83,
  11093. 0xc3, 0x56, 0xb0, 0xb1, 0x14, 0x34, 0x12, 0x1b, 0xea, 0x26, 0x97, 0x24,
  11094. 0x54, 0xcc, 0x32, 0x4c, 0xa4, 0xc2, 0xa3, 0x07, 0xfa, 0x30, 0xa9, 0xf0,
  11095. 0x91, 0x17, 0x60, 0x68, 0x88, 0x7f, 0x34, 0x7e, 0xbd, 0x20, 0x33, 0x95,
  11096. 0x6e, 0xc0, 0xb6, 0x2b, 0xff, 0x7e, 0x61, 0x35, 0x9a, 0x88, 0xff, 0xd9,
  11097. 0x69, 0x21, 0xe7, 0x8f, 0x45, 0x02, 0xf9, 0xd7, 0xeb, 0xa6, 0x53, 0xf1,
  11098. 0x73, 0x04, 0xf1, 0x0b, 0x85, 0xc6, 0x1f, 0x4a, 0x51, 0x2f, 0x95, 0x87,
  11099. 0x5a, 0x67, 0x37, 0xb2, 0x87, 0xf7, 0xbe, 0x2a, 0x17, 0x57, 0xca, 0xfc,
  11100. 0xdd, 0x5f, 0x37, 0x48, 0x78, 0xbd, 0xfa, 0x75, 0xc9, 0xfa, 0x86, 0x7e,
  11101. 0xc4, 0x0f, 0x60, 0x85, 0xce, 0x12, 0x44, 0x7c, 0xd9, 0xb2, 0x50, 0xd9,
  11102. 0x57, 0x85, 0xa5, 0xd7, 0x68, 0x59, 0x03, 0x09, 0x97, 0x2e, 0x8e, 0xa5,
  11103. 0xe3, 0x98, 0xac, 0x16, 0xfb, 0x6d, 0x54, 0xc5, 0x5d, 0x7a, 0x33, 0x44,
  11104. 0x0a, 0x39, 0x91, 0xcc, 0x9f, 0x67, 0xf9, 0x89, 0xbb, 0x62, 0x02, 0xc4,
  11105. 0x22, 0xec, 0xcf, 0x97, 0x69, 0x81, 0x3d, 0x00, 0xfd, 0xeb, 0x55, 0x08,
  11106. 0xa2, 0xff, 0x97, 0xaa, 0x79, 0xde, 0x3c, 0x8a, 0x78, 0x71, 0x73, 0xa2,
  11107. 0x98, 0x2f, 0xd8, 0x5c, 0x62, 0x1c, 0x5c, 0x23, 0x0a, 0xd1, 0xf1, 0x81,
  11108. 0x8a, 0x12, 0xe7, 0x4d, 0xdd, 0x4f, 0xd4, 0xf1, 0xe8, 0x0f, 0x25, 0x79,
  11109. 0x45, 0x4a, 0x49, 0x49, 0x7e, 0x56, 0x91, 0x4e, 0xaa, 0xba, 0x18, 0xe1,
  11110. 0xe4, 0xbe, 0x21, 0xdc, 0x58, 0x60, 0x6f, 0x6a, 0x7f, 0xdc, 0x5e, 0x74,
  11111. 0x47, 0xbf, 0xeb, 0x84, 0xc4, 0x1e, 0x5a, 0x61, 0x64, 0xc8, 0x63, 0x68,
  11112. 0xfa, 0x17, 0x9c, 0xac, 0x60, 0x1c, 0xa5, 0x6e, 0x00, 0x21, 0x93, 0x3c,
  11113. 0xd7, 0xbb, 0x73, 0x45, 0xf7, 0x34, 0x81, 0x6c, 0xfa, 0xf2, 0x33, 0xfd,
  11114. 0xb1, 0x40, 0x30, 0x6b, 0x30, 0xd1, 0x83, 0x5e, 0x2e, 0x7a, 0xce, 0xa6,
  11115. 0x12, 0x2a, 0x15, 0x03, 0x78, 0x29, 0xb9, 0x07, 0xae, 0xe7, 0xc2, 0x78,
  11116. 0x74, 0x72, 0xa5, 0x0e, 0x6b, 0x1f, 0x78, 0xf2, 0x5a, 0x69, 0xb6, 0x2b,
  11117. 0x99, 0x94, 0x1f, 0x89, 0xd1, 0x21, 0x14, 0x4a, 0x54, 0xab, 0x5a, 0x9f,
  11118. 0xaa, 0xa7, 0x96, 0x0a, 0x21, 0xce, 0x30, 0xb6, 0x70, 0x81, 0xe9, 0xd3,
  11119. 0x71, 0xc0, 0xf1, 0x15, 0xe2, 0xf6, 0xd3, 0xcc, 0x41, 0x15, 0x9d, 0xd5,
  11120. 0xa3, 0xa4, 0xe0, 0xf8, 0x62, 0xc4, 0x76, 0x65, 0x63, 0x89, 0xa7, 0xe2,
  11121. 0xfb, 0xf5, 0xc9, 0x80, 0x15, 0x5b, 0xc1, 0x59, 0xb2, 0xd0, 0x01, 0x3a,
  11122. 0xf9, 0xab, 0x5b, 0x79, 0x54, 0xed, 0x6b, 0xf9, 0x1d, 0x9d, 0x87, 0x63,
  11123. 0x80, 0x4f, 0xec, 0x9c, 0x4f, 0xad, 0x97, 0x04, 0xff, 0x62, 0x4a, 0x17,
  11124. 0xc0, 0x09, 0x2a, 0x2c, 0x23, 0x4b, 0xc3, 0xb6, 0x6d, 0xed, 0xdb, 0x1a,
  11125. 0x6f, 0x56, 0x2b, 0x78, 0x92, 0x3a, 0x5c, 0x7f, 0xb2, 0x63, 0xd3, 0xd5,
  11126. 0x1a, 0xbe, 0xc2, 0x34, 0xc8, 0xad, 0x36, 0xb7, 0x12, 0xb8, 0xe1, 0xb7,
  11127. 0x52, 0x7f, 0x16, 0x84, 0x2c, 0x47, 0x7e, 0xf2, 0xa5, 0x36, 0x2e, 0xad,
  11128. 0xe7, 0xbb, 0xc0, 0x6f, 0x27, 0x8e, 0x41, 0x08, 0x75, 0xe5, 0xff, 0xde,
  11129. 0x08, 0x9f, 0x8c, 0x91, 0xba, 0xc9, 0x9d, 0x9f, 0x27, 0x90, 0x50, 0x44,
  11130. 0x24, 0xe7, 0x3d, 0x6f
  11131. };
  11132. word64 s3 = 0x000000ffffffffff;
  11133. #endif
  11134. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11135. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11136. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11137. #endif
  11138. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11139. if (ret != 0)
  11140. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11141. else
  11142. aes_inited = 1;
  11143. XMEMSET(buf, 0, sizeof(buf));
  11144. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11145. if (ret != 0)
  11146. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11147. ret = wc_AesXtsEncryptSector(aes, buf, p1, sizeof(p1), s1);
  11148. #if defined(WOLFSSL_ASYNC_CRYPT)
  11149. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11150. #endif
  11151. if (ret != 0)
  11152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11153. if (XMEMCMP(c1, buf, AES_BLOCK_SIZE))
  11154. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11155. /* decrypt test */
  11156. XMEMSET(buf, 0, sizeof(buf));
  11157. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11158. if (ret != 0)
  11159. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11160. ret = wc_AesXtsDecryptSector(aes, buf, c1, sizeof(c1), s1);
  11161. #if defined(WOLFSSL_ASYNC_CRYPT)
  11162. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11163. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11164. #else
  11165. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11166. #endif
  11167. #endif
  11168. if (ret != 0)
  11169. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11170. if (XMEMCMP(p1, buf, AES_BLOCK_SIZE))
  11171. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11172. /* 256 bit key tests */
  11173. XMEMSET(buf, 0, sizeof(buf));
  11174. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_ENCRYPTION);
  11175. if (ret != 0)
  11176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11177. ret = wc_AesXtsEncryptSector(aes, buf, p2, sizeof(p2), s2);
  11178. #if defined(WOLFSSL_ASYNC_CRYPT)
  11179. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11180. #endif
  11181. if (ret != 0)
  11182. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11183. if (XMEMCMP(c2, buf, sizeof(c2)))
  11184. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11185. /* decrypt test */
  11186. XMEMSET(buf, 0, sizeof(buf));
  11187. ret = wc_AesXtsSetKeyNoInit(aes, k2, sizeof(k2), AES_DECRYPTION);
  11188. if (ret != 0)
  11189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11190. ret = wc_AesXtsDecryptSector(aes, buf, c2, sizeof(c2), s2);
  11191. #if defined(WOLFSSL_ASYNC_CRYPT)
  11192. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11193. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11194. #else
  11195. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11196. #endif
  11197. #endif
  11198. if (ret != 0)
  11199. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11200. if (XMEMCMP(p2, buf, sizeof(p2)))
  11201. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11202. #if !defined(BENCH_EMBEDDED) && \
  11203. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  11204. /* encrypt consecutive sectors test */
  11205. XMEMSET(data, 0, sizeof(buf));
  11206. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_ENCRYPTION);
  11207. if (ret != 0)
  11208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11209. ret = wc_AesXtsEncryptConsecutiveSectors(aes, data, p3,
  11210. sizeof(p3), s3, sectorSz);
  11211. #if defined(WOLFSSL_ASYNC_CRYPT)
  11212. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11213. #endif
  11214. if (ret != 0)
  11215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11216. if (XMEMCMP(c3, data, sizeof(c3)))
  11217. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11218. /* decrypt consecutive sectors test */
  11219. XMEMSET(data, 0, sizeof(buf));
  11220. ret = wc_AesXtsSetKeyNoInit(aes, k3, sizeof(k3), AES_DECRYPTION);
  11221. if (ret != 0)
  11222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11223. ret = wc_AesXtsDecryptConsecutiveSectors(aes, data, c3,
  11224. sizeof(c3), s3, sectorSz);
  11225. #if defined(WOLFSSL_ASYNC_CRYPT)
  11226. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11227. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11228. #else
  11229. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11230. #endif
  11231. #endif
  11232. if (ret != 0)
  11233. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11234. if (XMEMCMP(p3, data, sizeof(p3)))
  11235. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11236. #endif /* !BENCH_EMBEDDED && (!HAVE_FIPS || FIPS_VERSION_GE(5, 3)) */
  11237. out:
  11238. if (aes_inited)
  11239. wc_AesXtsFree(aes);
  11240. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11241. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11242. #endif
  11243. return ret;
  11244. }
  11245. #endif /* WOLFSSL_AES_128 && WOLFSSL_AES_256 */
  11246. #ifdef WOLFSSL_AES_128
  11247. /* testing of bad arguments */
  11248. static wc_test_ret_t aes_xts_args_test(void)
  11249. {
  11250. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11251. XtsAes *aes = NULL;
  11252. #else
  11253. XtsAes aes[1];
  11254. #endif
  11255. int aes_inited = 0;
  11256. wc_test_ret_t ret;
  11257. unsigned char buf[AES_BLOCK_SIZE * 2];
  11258. /* 128 key tests */
  11259. WOLFSSL_SMALL_STACK_STATIC unsigned char k1[] = {
  11260. 0xa3, 0xe4, 0x0d, 0x5b, 0xd4, 0xb6, 0xbb, 0xed,
  11261. 0xb2, 0xd1, 0x8c, 0x70, 0x0a, 0xd2, 0xdb, 0x22,
  11262. 0x10, 0xc8, 0x11, 0x90, 0x64, 0x6d, 0x67, 0x3c,
  11263. 0xbc, 0xa5, 0x3f, 0x13, 0x3e, 0xab, 0x37, 0x3c
  11264. };
  11265. WOLFSSL_SMALL_STACK_STATIC unsigned char p1[] = {
  11266. 0x20, 0xe0, 0x71, 0x94, 0x05, 0x99, 0x3f, 0x09,
  11267. 0xa6, 0x6a, 0xe5, 0xbb, 0x50, 0x0e, 0x56, 0x2c
  11268. };
  11269. WOLFSSL_SMALL_STACK_STATIC unsigned char c1[] = {
  11270. 0x74, 0x62, 0x35, 0x51, 0x21, 0x02, 0x16, 0xac,
  11271. 0x92, 0x6b, 0x96, 0x50, 0xb6, 0xd3, 0xfa, 0x52
  11272. };
  11273. word64 s1 = 141;
  11274. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11275. if ((aes = (XtsAes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  11276. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  11277. #endif
  11278. ret = wc_AesXtsInit(aes, HEAP_HINT, devId);
  11279. if (ret != 0)
  11280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11281. else
  11282. aes_inited = 1;
  11283. if (wc_AesXtsSetKeyNoInit(NULL, k1, sizeof(k1), AES_ENCRYPTION) == 0)
  11284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11285. if (wc_AesXtsSetKeyNoInit(aes, NULL, sizeof(k1), AES_ENCRYPTION) == 0)
  11286. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11287. /* encryption operations */
  11288. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_ENCRYPTION);
  11289. if (ret != 0)
  11290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11291. ret = wc_AesXtsEncryptSector(NULL, buf, p1, sizeof(p1), s1);
  11292. #if defined(WOLFSSL_ASYNC_CRYPT)
  11293. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11294. #endif
  11295. if (ret == 0)
  11296. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11297. ret = wc_AesXtsEncryptSector(aes, NULL, p1, sizeof(p1), s1);
  11298. #if defined(WOLFSSL_ASYNC_CRYPT)
  11299. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11300. #endif
  11301. if (ret == 0)
  11302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11303. /* decryption operations */
  11304. ret = wc_AesXtsSetKeyNoInit(aes, k1, sizeof(k1), AES_DECRYPTION);
  11305. if (ret != 0)
  11306. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11307. ret = wc_AesXtsDecryptSector(NULL, buf, c1, sizeof(c1), s1);
  11308. #if defined(WOLFSSL_ASYNC_CRYPT)
  11309. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11310. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11311. #else
  11312. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11313. #endif
  11314. #endif
  11315. if (ret == 0)
  11316. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11317. ret = wc_AesXtsDecryptSector(aes, NULL, c1, sizeof(c1), s1);
  11318. #if defined(WOLFSSL_ASYNC_CRYPT)
  11319. #ifdef WC_AES_XTS_SUPPORT_SIMULTANEOUS_ENC_AND_DEC_KEYS
  11320. ret = wc_AsyncWait(ret, &aes->aes_decrypt.asyncDev, WC_ASYNC_FLAG_NONE);
  11321. #else
  11322. ret = wc_AsyncWait(ret, &aes->aes.asyncDev, WC_ASYNC_FLAG_NONE);
  11323. #endif
  11324. #endif
  11325. if (ret == 0)
  11326. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  11327. ret = 0;
  11328. out:
  11329. if (aes_inited)
  11330. wc_AesXtsFree(aes);
  11331. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11332. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_AES);
  11333. #endif
  11334. return ret;
  11335. }
  11336. #endif /* WOLFSSL_AES_128 */
  11337. #endif /* WOLFSSL_AES_XTS && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  11338. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  11339. !defined(HAVE_RENESAS_SYNC)
  11340. static wc_test_ret_t aes_cbc_oneshot_test(void)
  11341. {
  11342. byte cipher[AES_BLOCK_SIZE];
  11343. byte plain[AES_BLOCK_SIZE];
  11344. wc_test_ret_t ret;
  11345. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  11346. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  11347. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  11348. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  11349. };
  11350. byte key[] = "0123456789abcdef "; /* align */
  11351. byte iv[] = "1234567890abcdef "; /* align */
  11352. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  11353. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  11354. /* Parameter Validation testing. */
  11355. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key, 17, NULL);
  11356. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11357. return WC_TEST_RET_ENC_EC(ret);
  11358. #ifdef HAVE_AES_DECRYPT
  11359. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key, 17, NULL);
  11360. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  11361. return WC_TEST_RET_ENC_EC(ret);
  11362. #endif
  11363. ret = wc_AesCbcEncryptWithKey(cipher, msg, AES_BLOCK_SIZE, key,
  11364. AES_BLOCK_SIZE, iv);
  11365. if (ret != 0)
  11366. return WC_TEST_RET_ENC_EC(ret);
  11367. #ifdef HAVE_AES_DECRYPT
  11368. ret = wc_AesCbcDecryptWithKey(plain, cipher, AES_BLOCK_SIZE, key,
  11369. AES_BLOCK_SIZE, iv);
  11370. if (ret != 0)
  11371. return WC_TEST_RET_ENC_EC(ret);
  11372. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE) != 0)
  11373. return WC_TEST_RET_ENC_NC;
  11374. #endif /* HAVE_AES_DECRYPT */
  11375. (void)plain;
  11376. return 0;
  11377. }
  11378. #endif
  11379. #if defined(WOLFSSL_AES_COUNTER) && defined(HAVE_AES_DECRYPT)
  11380. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_ctr_test(void)
  11381. {
  11382. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11383. Aes *enc = NULL;
  11384. Aes *dec = NULL;
  11385. #else
  11386. Aes enc[1];
  11387. Aes dec[1];
  11388. #endif
  11389. byte cipher[AES_BLOCK_SIZE * 4];
  11390. byte plain [AES_BLOCK_SIZE * 4];
  11391. wc_test_ret_t ret = 0;
  11392. /* test vectors from "Recommendation for Block Cipher Modes of
  11393. * Operation" NIST Special Publication 800-38A */
  11394. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  11395. {
  11396. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  11397. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  11398. };
  11399. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  11400. {
  11401. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  11402. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  11403. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  11404. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  11405. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  11406. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  11407. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  11408. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  11409. };
  11410. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11411. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32[] =
  11412. {
  11413. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff,
  11414. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11415. };
  11416. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap32_2[] =
  11417. {
  11418. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11419. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xfe
  11420. };
  11421. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64[] =
  11422. {
  11423. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11424. 0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11425. };
  11426. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap64_2[] =
  11427. {
  11428. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,
  11429. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11430. };
  11431. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96[] =
  11432. {
  11433. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11434. 0xff,0xff,0xff,0xff,0x0f,0xff,0xff,0xff
  11435. };
  11436. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap96_2[] =
  11437. {
  11438. 0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,
  11439. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11440. };
  11441. #endif
  11442. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
  11443. {
  11444. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11445. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  11446. };
  11447. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11448. WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128_2[] =
  11449. {
  11450. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  11451. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfe
  11452. };
  11453. #endif
  11454. #ifdef WOLFSSL_AES_128
  11455. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  11456. {
  11457. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  11458. 0xc2
  11459. };
  11460. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
  11461. {
  11462. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  11463. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  11464. };
  11465. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
  11466. {
  11467. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  11468. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  11469. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  11470. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  11471. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  11472. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  11473. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  11474. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  11475. };
  11476. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11477. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32Cipher[] =
  11478. {
  11479. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11480. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11481. 0x7e,0xad,0xea,0x5c,0xd1
  11482. };
  11483. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32CipherLong[] =
  11484. {
  11485. 0xb3,0x8b,0x58,0xbc,0xce,0xf4,0x71,0x78,
  11486. 0xf6,0x7c,0xdb,0xb4,0x27,0x2b,0x0a,0xbf,
  11487. 0x7e,0xad,0xea,0x5c,0xd1,0xb7,0x98,0xf0,
  11488. 0x22,0x20,0xfe,0x67,0xb0,0x02,0x23,0x50
  11489. };
  11490. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap32_2CipherLong[] =
  11491. {
  11492. 0x6e,0xa1,0x27,0x4d,0xea,0x20,0x5f,0x39,
  11493. 0x68,0xc8,0xb6,0x78,0xde,0xfc,0x53,0x5c,
  11494. 0x90,0xc8,0xf6,0xc6,0xfa,0xe0,0x7b,0x09,
  11495. 0x7c,0xf8,0x9c,0x6a,0x5a,0xa5,0x17,0x7f,
  11496. 0x03,0x92,0x5f,0x4e,0x85,0xea,0x26,0xc9,
  11497. 0x5a,0xc2,0x74,0xe2,0xbf,0xe4,0x1b,0xd4
  11498. };
  11499. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64Cipher[] =
  11500. {
  11501. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11502. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11503. 0xae,0x74,0x94,0x72,0x8e
  11504. };
  11505. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64CipherLong[] =
  11506. {
  11507. 0xdd,0x17,0x10,0x7c,0x45,0x04,0xac,0x43,
  11508. 0xef,0xa8,0xcc,0x32,0x34,0x87,0x88,0xd7,
  11509. 0xae,0x74,0x94,0x72,0x8e,0xd0,0x71,0xc0,
  11510. 0x89,0x8a,0xa1,0xb0,0x29,0xa0,0x10,0x9e
  11511. };
  11512. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap64_2CipherLong[] =
  11513. {
  11514. 0x3f,0xe7,0xd5,0xf3,0xfa,0x09,0xfe,0x40,
  11515. 0xa6,0xa1,0x32,0x8b,0x57,0x12,0xb9,0xfa,
  11516. 0xf2,0x2d,0xe4,0x3c,0x66,0x1d,0x0a,0x8e,
  11517. 0x46,0xf8,0x2e,0x33,0xce,0x8d,0x4e,0x3b,
  11518. 0x17,0x67,0x9e,0x9f,0x76,0x9e,0xc2,0x99,
  11519. 0xd5,0xd4,0x71,0xed,0xb4,0x33,0xb2,0xcd
  11520. };
  11521. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96Cipher[] =
  11522. {
  11523. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11524. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11525. 0x9d,0x77,0xc9,0x5f,0x38
  11526. };
  11527. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96CipherLong[] =
  11528. {
  11529. 0x55,0x24,0xc2,0x73,0xca,0xa3,0x48,0x03,
  11530. 0x0b,0x72,0x8d,0xd7,0x6c,0x99,0x8e,0x04,
  11531. 0x9d,0x77,0xc9,0x5f,0x38,0xb5,0x6e,0x44,
  11532. 0x21,0x8e,0xda,0x57,0xe0,0x41,0xc7,0x6a
  11533. };
  11534. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap96_2CipherLong[] =
  11535. {
  11536. 0xc8,0x81,0x1a,0xbe,0xc7,0x5b,0x93,0x6f,
  11537. 0xe6,0x52,0xe4,0xb1,0x2d,0x1c,0x39,0xbc,
  11538. 0xeb,0x82,0x27,0x0a,0x7e,0xa5,0x0e,0x2d,
  11539. 0x32,0xda,0xbe,0x10,0x7a,0x10,0xcc,0xd3,
  11540. 0x6f,0xc6,0x83,0x28,0x05,0x57,0x8a,0x24,
  11541. 0x44,0x76,0x17,0x81,0xb9,0x5c,0x94,0x81
  11542. };
  11543. #endif
  11544. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
  11545. {
  11546. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11547. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11548. 0xd3,0xda,0xe1,0x5b,0x04
  11549. };
  11550. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
  11551. {
  11552. 0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
  11553. 0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
  11554. 0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
  11555. 0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
  11556. };
  11557. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11558. WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128_2CipherLong[] =
  11559. {
  11560. 0xba,0x76,0xaa,0x54,0xd5,0xb5,0x60,0x67,
  11561. 0xc1,0xa7,0x90,0x3b,0x3f,0xdd,0xfa,0x89,
  11562. 0x24,0xdf,0x0c,0x56,0x5c,0xf4,0x2a,0x68,
  11563. 0x97,0x87,0x13,0xb6,0x7a,0xd1,0x24,0xfd,
  11564. 0x4d,0x3f,0x77,0x4a,0xb9,0xe4,0x7d,0xa2,
  11565. 0xdb,0xb9,0x31,0x5e,0xa3,0x11,0x06,0x80
  11566. };
  11567. #endif
  11568. #endif /* WOLFSSL_AES_128 */
  11569. #ifdef WOLFSSL_AES_192
  11570. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  11571. {
  11572. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  11573. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  11574. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  11575. };
  11576. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  11577. {
  11578. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  11579. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b,
  11580. 0x09,0x03,0x39,0xec,0x0a,0xa6,0xfa,0xef,
  11581. 0xd5,0xcc,0xc2,0xc6,0xf4,0xce,0x8e,0x94,
  11582. 0x1e,0x36,0xb2,0x6b,0xd1,0xeb,0xc6,0x70,
  11583. 0xd1,0xbd,0x1d,0x66,0x56,0x20,0xab,0xf7,
  11584. 0x4f,0x78,0xa7,0xf6,0xd2,0x98,0x09,0x58,
  11585. 0x5a,0x97,0xda,0xec,0x58,0xc6,0xb0,0x50
  11586. };
  11587. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11588. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32Cipher[] =
  11589. {
  11590. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11591. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11592. 0x0c,0x33,0x97,0x06,0xc0
  11593. };
  11594. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32CipherLong[] =
  11595. {
  11596. 0x28,0xaa,0xfa,0x90,0x72,0x74,0x86,0xaf,
  11597. 0x72,0x73,0x35,0x17,0x70,0x4e,0x7d,0xca,
  11598. 0x0c,0x33,0x97,0x06,0xc0,0xbe,0x83,0x87,
  11599. 0xdd,0xd3,0xff,0xd8,0xe4,0x6a,0x5b,0x84
  11600. };
  11601. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap32_2CipherLong[] =
  11602. {
  11603. 0xf5,0x00,0xa2,0x91,0x54,0xa3,0x76,0xa2,
  11604. 0xdd,0xad,0x16,0x89,0xe5,0xf0,0x1d,0x40,
  11605. 0x84,0xcd,0x74,0x84,0xcb,0x8b,0x9e,0x29,
  11606. 0xa9,0x8a,0x12,0x65,0xa0,0x79,0x5e,0xce,
  11607. 0xd9,0x50,0x65,0x21,0x86,0xb0,0x85,0x0d,
  11608. 0x98,0x2d,0x9a,0x5a,0x11,0xbe,0xa5,0x7f
  11609. };
  11610. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64Cipher[] =
  11611. {
  11612. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11613. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11614. 0x3d,0xf7,0xb4,0xfd,0x8c
  11615. };
  11616. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64CipherLong[] =
  11617. {
  11618. 0xfe,0x39,0x27,0x97,0xac,0xe5,0xb8,0x74,
  11619. 0xb9,0x8c,0xbf,0x58,0x71,0xa4,0x80,0x33,
  11620. 0x3d,0xf7,0xb4,0xfd,0x8c,0x55,0x47,0x10,
  11621. 0xd5,0x91,0x35,0xbe,0xd8,0x0d,0xa5,0x9e
  11622. };
  11623. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap64_2CipherLong[] =
  11624. {
  11625. 0x59,0xf1,0xed,0x70,0x62,0x42,0xa8,0x06,
  11626. 0x07,0x36,0xe1,0xc5,0x04,0x79,0xc3,0x9b,
  11627. 0xd1,0x14,0x5c,0xcc,0x6f,0x81,0x5f,0x2f,
  11628. 0xa0,0xde,0xcf,0x61,0x55,0x18,0x7a,0xac,
  11629. 0xb0,0x59,0x37,0x90,0x53,0xb3,0x00,0x88,
  11630. 0xb4,0x49,0x90,0x7b,0x96,0xcd,0xcc,0xc3
  11631. };
  11632. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96Cipher[] =
  11633. {
  11634. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11635. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11636. 0x47,0xb5,0xf3,0x30,0x3b
  11637. };
  11638. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96CipherLong[] =
  11639. {
  11640. 0x41,0x21,0x40,0x31,0xfb,0xc8,0xad,0x23,
  11641. 0xde,0x00,0x03,0xd8,0x96,0x45,0xc7,0xb5,
  11642. 0x47,0xb5,0xf3,0x30,0x3b,0xef,0xcd,0x80,
  11643. 0xe3,0x61,0x34,0xef,0x4e,0x1b,0x79,0xc1
  11644. };
  11645. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap96_2CipherLong[] =
  11646. {
  11647. 0x3c,0xb2,0xff,0xc0,0x24,0xe1,0xf5,0xc4,
  11648. 0x0f,0xd1,0x0a,0x1b,0xbe,0x1f,0x23,0xa1,
  11649. 0x8e,0xbf,0x2b,0x96,0xb6,0x37,0xc8,0x25,
  11650. 0x06,0x90,0xe2,0xca,0x71,0x24,0x52,0x95,
  11651. 0xaa,0x8c,0x80,0xdf,0xb7,0xd7,0x30,0xb0,
  11652. 0xcc,0x06,0x4f,0x28,0xa2,0x74,0x27,0xf8
  11653. };
  11654. #endif
  11655. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128Cipher[] =
  11656. {
  11657. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11658. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11659. 0x8c,0x68,0xa7,0xd9,0x57
  11660. };
  11661. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128CipherLong[] =
  11662. {
  11663. 0x5c,0xc3,0x8f,0xab,0x30,0xb6,0xac,0x67,
  11664. 0xdc,0xc2,0x1e,0x7b,0x01,0x2e,0xcf,0x98,
  11665. 0x8c,0x68,0xa7,0xd9,0x57,0xab,0x09,0x0f,
  11666. 0x01,0xc4,0x4e,0x62,0xaf,0xc2,0xdf,0x1a
  11667. };
  11668. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11669. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Wrap128_2CipherLong[] =
  11670. {
  11671. 0x88,0x0a,0x26,0x4e,0xa8,0x26,0x21,0xe0,
  11672. 0xfc,0xbc,0x63,0xdc,0xd9,0x60,0x52,0xb2,
  11673. 0x99,0x2f,0xbb,0x1e,0x00,0xf5,0x9f,0x6d,
  11674. 0xab,0x48,0x0f,0xc6,0x37,0x12,0x56,0xe3,
  11675. 0x12,0x8d,0x31,0xc8,0xea,0xf4,0x41,0x82,
  11676. 0x7a,0x88,0xe0,0xd7,0xf0,0x67,0x03,0xa4
  11677. };
  11678. #endif
  11679. #endif
  11680. #ifdef WOLFSSL_AES_256
  11681. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  11682. {
  11683. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  11684. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  11685. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  11686. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  11687. };
  11688. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  11689. {
  11690. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  11691. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
  11692. 0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
  11693. 0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
  11694. 0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
  11695. 0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
  11696. 0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
  11697. 0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
  11698. };
  11699. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11700. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32Cipher[] =
  11701. {
  11702. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11703. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11704. 0xa2,0x13,0x47,0x74,0xda
  11705. };
  11706. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32CipherLong[] =
  11707. {
  11708. 0xb0,0xa8,0xc0,0x65,0x85,0x20,0x0d,0x5c,
  11709. 0x25,0xcf,0xe7,0x58,0x63,0xc8,0xd4,0xea,
  11710. 0xa2,0x13,0x47,0x74,0xda,0x89,0x77,0x40,
  11711. 0x28,0x9c,0xe8,0x19,0x26,0x32,0xd8,0x1f
  11712. };
  11713. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap32_2CipherLong[] =
  11714. {
  11715. 0xf6,0xd9,0x22,0xc6,0x80,0x29,0xaf,0x14,
  11716. 0x54,0x6c,0x0a,0xce,0x42,0xea,0x3c,0xa1,
  11717. 0x7c,0xeb,0x36,0x0d,0x8e,0xd7,0x8c,0x59,
  11718. 0xa8,0x09,0x9f,0x9e,0xba,0x5b,0x95,0xfa,
  11719. 0x26,0x8c,0x37,0x59,0xf8,0xae,0x8e,0xaa,
  11720. 0x4d,0xe4,0x1c,0xfe,0x51,0xc7,0xb7,0xcc
  11721. };
  11722. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64Cipher[] =
  11723. {
  11724. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11725. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11726. 0xd4,0x94,0x4c,0xcd,0x4d
  11727. };
  11728. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64CipherLong[] =
  11729. {
  11730. 0x74,0x1a,0x52,0x41,0x76,0xb4,0x11,0x8f,
  11731. 0xfd,0x57,0x31,0xfd,0x3d,0x76,0x8f,0x07,
  11732. 0xd4,0x94,0x4c,0xcd,0x4d,0x47,0x5a,0x92,
  11733. 0x26,0x49,0x81,0x7a,0xda,0x36,0x27,0x01
  11734. };
  11735. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap64_2CipherLong[] =
  11736. {
  11737. 0xf7,0x9c,0xbf,0xf6,0xa2,0xaa,0x8a,0x0a,
  11738. 0x63,0x8a,0x20,0x2f,0x12,0xf1,0x8e,0x49,
  11739. 0x30,0xc0,0x8d,0x5c,0x5f,0x8b,0xbc,0x16,
  11740. 0xdd,0x71,0xee,0x13,0x14,0x7b,0xe1,0x25,
  11741. 0xcb,0x87,0x8a,0xc6,0xdc,0x1d,0x54,0x7a,
  11742. 0xe1,0xe4,0x6f,0x0d,0x95,0x1b,0xd1,0x8b
  11743. };
  11744. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96Cipher[] =
  11745. {
  11746. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11747. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11748. 0xb8,0x69,0xa1,0x48,0x45
  11749. };
  11750. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96CipherLong[] =
  11751. {
  11752. 0xb9,0x07,0x02,0xb8,0xbe,0x94,0xbf,0x53,
  11753. 0xdf,0x83,0x8e,0x23,0x8c,0x67,0x0c,0x81,
  11754. 0xb8,0x69,0xa1,0x48,0x45,0xf1,0xc6,0x27,
  11755. 0x36,0xa8,0xb2,0x4b,0x0e,0x62,0x6b,0x72
  11756. };
  11757. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap96_2CipherLong[] =
  11758. {
  11759. 0xd5,0x56,0x73,0xaa,0xb8,0xe4,0x06,0xf6,
  11760. 0x83,0x45,0x3a,0xb4,0xb9,0x63,0xec,0xad,
  11761. 0x73,0xc5,0xab,0x78,0xb1,0x21,0xab,0xef,
  11762. 0x69,0x15,0xb7,0x0c,0xe9,0xb4,0x3a,0xe7,
  11763. 0xbc,0xc4,0x22,0xbd,0x93,0xba,0x52,0xe0,
  11764. 0x91,0x2f,0x5e,0x8d,0x6d,0x59,0xf7,0xc2
  11765. };
  11766. #endif
  11767. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
  11768. {
  11769. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11770. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11771. 0x4b,0x45,0x7c,0xd6,0x8a
  11772. };
  11773. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
  11774. {
  11775. 0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
  11776. 0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
  11777. 0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
  11778. 0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
  11779. };
  11780. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11781. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128_2CipherLong[] =
  11782. {
  11783. 0x24,0x5c,0x09,0xa0,0x3b,0x1a,0x5a,0x94,
  11784. 0x2b,0x93,0x56,0x13,0x48,0xa0,0x21,0xce,
  11785. 0x95,0x11,0xa3,0x76,0xd6,0x59,0x88,0x42,
  11786. 0x04,0x71,0x69,0x62,0x28,0xb2,0xee,0x9d,
  11787. 0xd5,0xa0,0xea,0xc7,0x37,0x93,0x92,0xc7,
  11788. 0xf2,0xb6,0x8d,0xd9,0x59,0x1a,0xfa,0xbb
  11789. };
  11790. #endif
  11791. #endif
  11792. int i;
  11793. struct {
  11794. const byte* key;
  11795. int keySz;
  11796. const byte* iv;
  11797. const byte* plain;
  11798. int len;
  11799. const byte* cipher;
  11800. } testVec[] = {
  11801. #ifdef WOLFSSL_AES_128
  11802. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11803. ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
  11804. /* let's try with just 9 bytes, non block size test */
  11805. { ctr128Key, (int)sizeof(ctr128Key), ctrIv,
  11806. ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
  11807. /* and an additional 9 bytes to reuse tmp left buffer */
  11808. { NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
  11809. /* Counter wrapping */
  11810. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11811. ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
  11812. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
  11813. ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
  11814. ctr128Wrap128CipherLong },
  11815. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11816. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128_2,
  11817. ctrPlain, (int)sizeof(ctr128Wrap128_2CipherLong),
  11818. ctr128Wrap128_2CipherLong },
  11819. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11820. ctrPlain, (int)sizeof(ctr128Wrap96Cipher), ctr128Wrap96Cipher },
  11821. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96,
  11822. ctrPlain, (int)sizeof(ctr128Wrap96CipherLong),
  11823. ctr128Wrap96CipherLong },
  11824. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap96_2,
  11825. ctrPlain, (int)sizeof(ctr128Wrap96_2CipherLong),
  11826. ctr128Wrap96_2CipherLong },
  11827. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11828. ctrPlain, (int)sizeof(ctr128Wrap64Cipher), ctr128Wrap64Cipher },
  11829. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64,
  11830. ctrPlain, (int)sizeof(ctr128Wrap64CipherLong),
  11831. ctr128Wrap64CipherLong },
  11832. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap64_2,
  11833. ctrPlain, (int)sizeof(ctr128Wrap64_2CipherLong),
  11834. ctr128Wrap64_2CipherLong },
  11835. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11836. ctrPlain, (int)sizeof(ctr128Wrap32Cipher), ctr128Wrap32Cipher },
  11837. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32,
  11838. ctrPlain, (int)sizeof(ctr128Wrap32CipherLong),
  11839. ctr128Wrap32CipherLong },
  11840. { ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap32_2,
  11841. ctrPlain, (int)sizeof(ctr128Wrap32_2CipherLong),
  11842. ctr128Wrap32_2CipherLong },
  11843. #endif
  11844. #endif
  11845. #ifdef WOLFSSL_AES_192
  11846. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11847. ctrPlain, (int)sizeof(ctrPlain), ctr192Cipher },
  11848. /* let's try with just 9 bytes, non block size test */
  11849. { ctr192Key, (int)sizeof(ctr192Key), ctrIv,
  11850. ctrPlain, (int)sizeof(oddCipher), ctr192Cipher },
  11851. /* Counter wrapping */
  11852. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11853. ctrPlain, (int)sizeof(ctr192Wrap128Cipher), ctr192Wrap128Cipher },
  11854. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128,
  11855. ctrPlain, (int)sizeof(ctr192Wrap128CipherLong),
  11856. ctr192Wrap128CipherLong },
  11857. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11858. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap128_2,
  11859. ctrPlain, (int)sizeof(ctr192Wrap128_2CipherLong),
  11860. ctr192Wrap128_2CipherLong },
  11861. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11862. ctrPlain, (int)sizeof(ctr192Wrap96Cipher), ctr192Wrap96Cipher },
  11863. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96,
  11864. ctrPlain, (int)sizeof(ctr192Wrap96CipherLong),
  11865. ctr192Wrap96CipherLong },
  11866. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap96_2,
  11867. ctrPlain, (int)sizeof(ctr192Wrap96_2CipherLong),
  11868. ctr192Wrap96_2CipherLong },
  11869. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11870. ctrPlain, (int)sizeof(ctr192Wrap64Cipher), ctr192Wrap64Cipher },
  11871. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64,
  11872. ctrPlain, (int)sizeof(ctr192Wrap64CipherLong),
  11873. ctr192Wrap64CipherLong },
  11874. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap64_2,
  11875. ctrPlain, (int)sizeof(ctr192Wrap64_2CipherLong),
  11876. ctr192Wrap64_2CipherLong },
  11877. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11878. ctrPlain, (int)sizeof(ctr192Wrap32Cipher), ctr192Wrap32Cipher },
  11879. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32,
  11880. ctrPlain, (int)sizeof(ctr192Wrap32CipherLong),
  11881. ctr192Wrap32CipherLong },
  11882. { ctr192Key, (int)sizeof(ctr192Key), ctrIvWrap32_2,
  11883. ctrPlain, (int)sizeof(ctr192Wrap32_2CipherLong),
  11884. ctr192Wrap32_2CipherLong },
  11885. #endif
  11886. #endif
  11887. #ifdef WOLFSSL_AES_256
  11888. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11889. ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
  11890. /* let's try with just 9 bytes, non block size test */
  11891. { ctr256Key, (int)sizeof(ctr256Key), ctrIv,
  11892. ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
  11893. /* Counter wrapping */
  11894. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11895. ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
  11896. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
  11897. ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
  11898. ctr256Wrap128CipherLong },
  11899. #if defined(WOLFSSL_ARMASM) || defined(WOLFSSL_RISCV_ASM)
  11900. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128_2,
  11901. ctrPlain, (int)sizeof(ctr256Wrap128_2CipherLong),
  11902. ctr256Wrap128_2CipherLong },
  11903. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11904. ctrPlain, (int)sizeof(ctr256Wrap96Cipher), ctr256Wrap96Cipher },
  11905. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96,
  11906. ctrPlain, (int)sizeof(ctr256Wrap96CipherLong),
  11907. ctr256Wrap96CipherLong },
  11908. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap96_2,
  11909. ctrPlain, (int)sizeof(ctr256Wrap96_2CipherLong),
  11910. ctr256Wrap96_2CipherLong },
  11911. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11912. ctrPlain, (int)sizeof(ctr256Wrap64Cipher), ctr256Wrap64Cipher },
  11913. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64,
  11914. ctrPlain, (int)sizeof(ctr256Wrap64CipherLong),
  11915. ctr256Wrap64CipherLong },
  11916. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap64_2,
  11917. ctrPlain, (int)sizeof(ctr256Wrap64_2CipherLong),
  11918. ctr256Wrap64_2CipherLong },
  11919. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11920. ctrPlain, (int)sizeof(ctr256Wrap32Cipher), ctr256Wrap32Cipher },
  11921. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32,
  11922. ctrPlain, (int)sizeof(ctr256Wrap32CipherLong),
  11923. ctr256Wrap32CipherLong },
  11924. { ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap32_2,
  11925. ctrPlain, (int)sizeof(ctr256Wrap32_2CipherLong),
  11926. ctr256Wrap32_2CipherLong },
  11927. #endif
  11928. #endif
  11929. };
  11930. #define AES_CTR_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  11931. WOLFSSL_ENTER("aes_ctr_test");
  11932. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  11933. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  11934. if (enc == NULL)
  11935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11936. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  11937. if (dec == NULL)
  11938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11939. #else
  11940. XMEMSET(enc, 0, sizeof(Aes));
  11941. XMEMSET(dec, 0, sizeof(Aes));
  11942. ret = wc_AesInit(enc, HEAP_HINT, devId);
  11943. if (ret != 0)
  11944. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11945. ret = wc_AesInit(dec, HEAP_HINT, devId);
  11946. if (ret != 0)
  11947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  11948. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  11949. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11950. if (testVec[i].key != NULL) {
  11951. ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
  11952. testVec[i].iv, AES_ENCRYPTION);
  11953. if (ret != 0) {
  11954. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11955. }
  11956. /* Ctr only uses encrypt, even on key setup */
  11957. ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
  11958. testVec[i].iv, AES_ENCRYPTION);
  11959. if (ret != 0) {
  11960. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11961. }
  11962. }
  11963. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
  11964. if (ret != 0) {
  11965. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11966. }
  11967. ret = wc_AesCtrEncrypt(dec, plain, cipher, (word32)testVec[i].len);
  11968. if (ret != 0) {
  11969. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11970. }
  11971. if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
  11972. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11973. }
  11974. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  11975. if (XMEMCMP(cipher, testVec[i].cipher, (size_t)testVec[i].len)) {
  11976. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11977. }
  11978. #endif
  11979. }
  11980. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  11981. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  11982. if (testVec[i].key != NULL) {
  11983. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  11984. testVec[i].iv, AES_ENCRYPTION);
  11985. if (ret != 0) {
  11986. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11987. }
  11988. /* Ctr only uses encrypt, even on key setup */
  11989. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  11990. testVec[i].iv, AES_ENCRYPTION);
  11991. if (ret != 0) {
  11992. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  11993. }
  11994. }
  11995. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  11996. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  11997. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  11998. if (ret != 0) {
  11999. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12000. }
  12001. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12002. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12003. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12004. if (ret != 0) {
  12005. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12006. }
  12007. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12008. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12009. }
  12010. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12011. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12012. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12013. }
  12014. #endif
  12015. }
  12016. for (i = 0; i < AES_CTR_TEST_LEN; i++) {
  12017. if (testVec[i].key != NULL) {
  12018. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12019. ret = wc_AesSetKeyDirect(enc, testVec[i].key, testVec[i].keySz,
  12020. testVec[i].iv, AES_ENCRYPTION);
  12021. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12022. if (ret != 0) {
  12023. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12024. }
  12025. /* Ctr only uses encrypt, even on key setup */
  12026. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12027. ret = wc_AesSetKeyDirect(dec, testVec[i].key, testVec[i].keySz,
  12028. testVec[i].iv, AES_ENCRYPTION);
  12029. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12030. if (ret != 0) {
  12031. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12032. }
  12033. }
  12034. ret = wc_AesCtrEncrypt(enc, cipher, testVec[i].plain, testVec[i].len);
  12035. if (ret != 0) {
  12036. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12037. }
  12038. ret = wc_AesCtrEncrypt(dec, plain, cipher, testVec[i].len);
  12039. if (ret != 0) {
  12040. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12041. }
  12042. if (XMEMCMP(plain, ctrPlain, testVec[i].len)) {
  12043. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12044. }
  12045. #if !(FIPS_VERSION_EQ(2,0) && defined(WOLFSSL_ARMASM))
  12046. if (XMEMCMP(cipher, testVec[i].cipher, testVec[i].len)) {
  12047. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12048. }
  12049. #endif
  12050. }
  12051. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12052. out:
  12053. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12054. wc_AesDelete(enc, &enc);
  12055. #else
  12056. wc_AesFree(enc);
  12057. #endif
  12058. #ifdef HAVE_AES_DECRYPT
  12059. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12060. wc_AesDelete(dec, &dec);
  12061. #else
  12062. wc_AesFree(dec);
  12063. #endif
  12064. #endif
  12065. return ret;
  12066. }
  12067. #endif /* WOLFSSL_AES_COUNTER */
  12068. #ifdef HAVE_AES_ECB
  12069. static wc_test_ret_t aes_ecb_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12070. {
  12071. wc_test_ret_t ret = 0;
  12072. /* keys padded to block size (16 bytes) */
  12073. WOLFSSL_SMALL_STACK_STATIC const byte key_128[] =
  12074. "0123456789abcdef ";
  12075. WOLFSSL_SMALL_STACK_STATIC const byte key_192[] =
  12076. "0123456789abcdef01234567 ";
  12077. WOLFSSL_SMALL_STACK_STATIC const byte key_256[] =
  12078. "0123456789abcdef0123456789abcdef ";
  12079. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12080. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12081. 0x6e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74,
  12082. 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20
  12083. };
  12084. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_128[AES_BLOCK_SIZE] = {
  12085. 0xd0, 0xc9, 0xd9, 0xc9, 0x40, 0xe8, 0x97, 0xb6,
  12086. 0xc8, 0x8c, 0x33, 0x3b, 0xb5, 0x8f, 0x85, 0xd1
  12087. };
  12088. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_192[AES_BLOCK_SIZE] = {
  12089. 0x06, 0x57, 0xee, 0x78, 0x3f, 0x96, 0x00, 0xb1,
  12090. 0xec, 0x76, 0x94, 0x30, 0x29, 0xbe, 0x15, 0xab
  12091. };
  12092. WOLFSSL_SMALL_STACK_STATIC const byte verify_ecb_256[AES_BLOCK_SIZE] = {
  12093. 0xcd, 0xf2, 0x81, 0x3e, 0x73, 0x3e, 0xf7, 0x33,
  12094. 0x3d, 0x18, 0xfd, 0x41, 0x85, 0x37, 0x04, 0x82
  12095. };
  12096. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] = {
  12097. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12098. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12099. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12100. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12101. };
  12102. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] = {
  12103. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12104. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12105. };
  12106. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] = {
  12107. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12108. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12109. };
  12110. int i;
  12111. struct {
  12112. const byte* key;
  12113. int keySz;
  12114. const byte* iv; /* null uses 0's */
  12115. const byte* plain;
  12116. const byte* verify;
  12117. } testVec[] = {
  12118. { key_128, 16, iv, msg, verify_ecb_128 },
  12119. { key_192, 24, iv, msg, verify_ecb_192 },
  12120. { key_256, 32, iv, msg, verify_ecb_256 },
  12121. { niKey, 32, NULL, niPlain, niCipher }
  12122. };
  12123. #define AES_ECB_TEST_LEN (int)(sizeof(testVec) / sizeof(*testVec))
  12124. for (i = 0; i < AES_ECB_TEST_LEN; i++) {
  12125. ret = wc_AesSetKey(enc, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12126. AES_ENCRYPTION);
  12127. if (ret != 0)
  12128. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12129. #ifdef HAVE_AES_DECRYPT
  12130. ret = wc_AesSetKey(dec, testVec[i].key, testVec[i].keySz, testVec[i].iv,
  12131. AES_DECRYPTION);
  12132. if (ret != 0)
  12133. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12134. #endif
  12135. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12136. ret = wc_AesEcbEncrypt(enc, cipher, testVec[i].plain, AES_BLOCK_SIZE);
  12137. #if defined(WOLFSSL_ASYNC_CRYPT)
  12138. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12139. #endif
  12140. if (ret != 0)
  12141. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12142. if (XMEMCMP(cipher, testVec[i].verify, AES_BLOCK_SIZE)) {
  12143. WOLFSSL_MSG("aes_test cipher vs verify_ecb mismatch!");
  12144. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12145. }
  12146. #ifdef HAVE_AES_DECRYPT
  12147. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12148. ret = wc_AesEcbDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12149. #if defined(WOLFSSL_ASYNC_CRYPT)
  12150. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12151. #endif
  12152. if (ret != 0)
  12153. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12154. if (XMEMCMP(plain, testVec[i].plain, AES_BLOCK_SIZE))
  12155. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  12156. #endif /* HAVE_AES_DECRYPT */
  12157. (void)dec;
  12158. (void)plain;
  12159. }
  12160. out:
  12161. return ret;
  12162. }
  12163. #endif /* HAVE_AES_ECB */
  12164. #ifdef WOLFSSL_AES_DIRECT
  12165. static wc_test_ret_t aes_direct_test(Aes* enc, Aes* dec, byte* cipher, byte* plain)
  12166. {
  12167. wc_test_ret_t ret = 0;
  12168. WOLFSSL_ENTER("aes_direct_test");
  12169. #if defined(WOLFSSL_AES_256)
  12170. {
  12171. WOLFSSL_SMALL_STACK_STATIC const byte niPlain[] =
  12172. {
  12173. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12174. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12175. };
  12176. WOLFSSL_SMALL_STACK_STATIC const byte niCipher[] =
  12177. {
  12178. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  12179. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  12180. };
  12181. WOLFSSL_SMALL_STACK_STATIC const byte niKey[] =
  12182. {
  12183. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12184. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12185. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12186. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12187. };
  12188. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12189. ret = wc_AesSetKey(enc, niKey, sizeof(niKey), cipher, AES_ENCRYPTION);
  12190. if (ret != 0)
  12191. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12192. #if !defined(HAVE_SELFTEST) && \
  12193. (defined(WOLFSSL_LINUXKM) || \
  12194. !defined(HAVE_FIPS) || \
  12195. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12196. ret = wc_AesEncryptDirect(enc, cipher, niPlain);
  12197. if (ret != 0)
  12198. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12199. #else
  12200. wc_AesEncryptDirect(enc, cipher, niPlain);
  12201. #endif
  12202. if (XMEMCMP(cipher, niCipher, AES_BLOCK_SIZE) != 0)
  12203. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12204. #ifdef HAVE_AES_DECRYPT
  12205. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12206. ret = wc_AesSetKey(dec, niKey, sizeof(niKey), plain, AES_DECRYPTION);
  12207. if (ret != 0)
  12208. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12209. #if !defined(HAVE_SELFTEST) && \
  12210. (defined(WOLFSSL_LINUXKM) || \
  12211. !defined(HAVE_FIPS) || \
  12212. (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  12213. ret = wc_AesDecryptDirect(dec, plain, niCipher);
  12214. if (ret != 0)
  12215. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12216. #else
  12217. wc_AesDecryptDirect(dec, plain, niCipher);
  12218. #endif
  12219. if (XMEMCMP(plain, niPlain, AES_BLOCK_SIZE) != 0)
  12220. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12221. #endif /* HAVE_AES_DECRYPT */
  12222. }
  12223. (void)dec;
  12224. (void)plain;
  12225. #endif /* WOLFSSL_AES_256 */
  12226. out:
  12227. return ret;
  12228. }
  12229. #endif /* WOLFSSL_AES_DIRECT */
  12230. #ifdef HAVE_AES_CBC
  12231. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cbc_test(void)
  12232. {
  12233. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12234. Aes *enc = NULL;
  12235. #else
  12236. Aes enc[1];
  12237. #endif
  12238. #ifdef HAVE_AES_DECRYPT
  12239. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12240. Aes *dec = NULL;
  12241. #else
  12242. Aes dec[1];
  12243. #endif
  12244. #endif
  12245. byte cipher[AES_BLOCK_SIZE * 4];
  12246. #ifdef HAVE_AES_DECRYPT
  12247. byte plain [AES_BLOCK_SIZE * 4];
  12248. #endif
  12249. wc_test_ret_t ret = 0;
  12250. WOLFSSL_ENTER("aes_cbc_test");
  12251. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12252. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12253. if (enc == NULL)
  12254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12255. #ifdef HAVE_AES_DECRYPT
  12256. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12257. if (dec == NULL)
  12258. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12259. #endif
  12260. #else
  12261. XMEMSET(enc, 0, sizeof(Aes));
  12262. #ifdef HAVE_AES_DECRYPT
  12263. XMEMSET(dec, 0, sizeof(Aes));
  12264. #endif
  12265. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12266. if (ret != 0)
  12267. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12268. #ifdef HAVE_AES_DECRYPT
  12269. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12270. if (ret != 0)
  12271. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12272. #endif
  12273. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12274. #ifdef WOLFSSL_AES_128
  12275. {
  12276. /* "Now is the time for all " w/o trailing 0 */
  12277. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12278. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  12279. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  12280. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  12281. };
  12282. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12283. {
  12284. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  12285. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  12286. };
  12287. #ifdef HAVE_RENESAS_SYNC
  12288. const byte *key = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  12289. #else
  12290. /* padded to 16-byye */
  12291. WOLFSSL_SMALL_STACK_STATIC const byte key[] = "0123456789abcdef ";
  12292. #endif
  12293. /* padded to 16-bytes */
  12294. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12295. ret = wc_AesSetKey(enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION);
  12296. if (ret != 0)
  12297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12298. #ifdef HAVE_AES_DECRYPT
  12299. ret = wc_AesSetKey(dec, key, AES_BLOCK_SIZE, iv, AES_DECRYPTION);
  12300. if (ret != 0)
  12301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12302. #endif
  12303. XMEMSET(cipher, 0, sizeof(cipher));
  12304. ret = wc_AesCbcEncrypt(enc, cipher, msg, AES_BLOCK_SIZE);
  12305. #if defined(WOLFSSL_ASYNC_CRYPT)
  12306. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12307. #endif
  12308. if (ret != 0)
  12309. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12310. #ifdef HAVE_AES_DECRYPT
  12311. XMEMSET(plain, 0, sizeof(plain));
  12312. ret = wc_AesCbcDecrypt(dec, plain, cipher, AES_BLOCK_SIZE);
  12313. #if defined(WOLFSSL_ASYNC_CRYPT)
  12314. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12315. #endif
  12316. if (ret != 0) {
  12317. WOLFSSL_MSG("failed wc_AesCbcDecrypt");
  12318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12319. }
  12320. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE)) {
  12321. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain compare");
  12322. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12323. }
  12324. #endif /* HAVE_AES_DECRYPT */
  12325. /* skipped because wrapped key use in case of renesas sm */
  12326. #ifndef HAVE_RENESAS_SYNC
  12327. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE)) {
  12328. WOLFSSL_MSG("wc_AesCbcDecrypt failed cipher-verify compare");
  12329. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12330. }
  12331. #endif
  12332. }
  12333. #endif /* WOLFSSL_AES_128 */
  12334. #if defined(WOLFSSL_AESNI) && defined(HAVE_AES_DECRYPT)
  12335. {
  12336. WOLFSSL_SMALL_STACK_STATIC const byte bigMsg[] = {
  12337. /* "All work and no play makes Jack a dull boy. " */
  12338. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12339. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12340. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12341. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12342. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12343. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12344. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12345. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12346. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12347. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12348. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12349. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12350. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12351. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12352. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12353. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12354. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12355. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12356. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12357. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12358. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12359. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12360. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12361. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12362. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12363. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12364. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12365. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12366. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12367. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12368. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12369. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12370. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12371. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12372. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12373. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12374. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20,
  12375. 0x61,0x20,0x64,0x75,0x6c,0x6c,0x20,0x62,
  12376. 0x6f,0x79,0x2e,0x20,0x41,0x6c,0x6c,0x20,
  12377. 0x77,0x6f,0x72,0x6b,0x20,0x61,0x6e,0x64,
  12378. 0x20,0x6e,0x6f,0x20,0x70,0x6c,0x61,0x79,
  12379. 0x20,0x6d,0x61,0x6b,0x65,0x73,0x20,0x4a,
  12380. 0x61,0x63,0x6b,0x20,0x61,0x20,0x64,0x75,
  12381. 0x6c,0x6c,0x20,0x62,0x6f,0x79,0x2e,0x20,
  12382. 0x41,0x6c,0x6c,0x20,0x77,0x6f,0x72,0x6b,
  12383. 0x20,0x61,0x6e,0x64,0x20,0x6e,0x6f,0x20,
  12384. 0x70,0x6c,0x61,0x79,0x20,0x6d,0x61,0x6b,
  12385. 0x65,0x73,0x20,0x4a,0x61,0x63,0x6b,0x20
  12386. };
  12387. WOLFSSL_SMALL_STACK_STATIC const byte bigKey[] =
  12388. "0123456789abcdeffedcba9876543210";
  12389. /* padded to 16-bytes */
  12390. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = "1234567890abcdef ";
  12391. word32 keySz, msgSz;
  12392. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12393. byte *bigCipher = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12394. DYNAMIC_TYPE_TMP_BUFFER);
  12395. byte *bigPlain = (byte *)XMALLOC(sizeof(bigMsg), HEAP_HINT,
  12396. DYNAMIC_TYPE_TMP_BUFFER);
  12397. if ((bigCipher == NULL) ||
  12398. (bigPlain == NULL)) {
  12399. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12400. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12401. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12402. }
  12403. #else
  12404. byte bigCipher[sizeof(bigMsg)];
  12405. byte bigPlain[sizeof(bigMsg)];
  12406. #endif
  12407. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12408. * message by AES_BLOCK_SIZE for each size of AES key. */
  12409. for (keySz = 16; keySz <= 32; keySz += 8) {
  12410. for (msgSz = AES_BLOCK_SIZE;
  12411. msgSz <= sizeof(bigMsg);
  12412. msgSz += AES_BLOCK_SIZE) {
  12413. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12414. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12415. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12416. if (ret != 0) {
  12417. ret = WC_TEST_RET_ENC_EC(ret);
  12418. break;
  12419. }
  12420. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12421. if (ret != 0) {
  12422. ret = WC_TEST_RET_ENC_EC(ret);
  12423. break;
  12424. }
  12425. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12426. #if defined(WOLFSSL_ASYNC_CRYPT)
  12427. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12428. #endif
  12429. if (ret != 0) {
  12430. ret = WC_TEST_RET_ENC_EC(ret);
  12431. break;
  12432. }
  12433. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12434. #if defined(WOLFSSL_ASYNC_CRYPT)
  12435. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12436. #endif
  12437. if (ret != 0) {
  12438. ret = WC_TEST_RET_ENC_EC(ret);
  12439. break;
  12440. }
  12441. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12442. ret = WC_TEST_RET_ENC_NC;
  12443. break;
  12444. }
  12445. }
  12446. if (ret != 0)
  12447. break;
  12448. }
  12449. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12450. /* Iterate from one AES_BLOCK_SIZE of bigMsg through the whole
  12451. * message by AES_BLOCK_SIZE for each size of AES key. */
  12452. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12453. for (keySz = 16; keySz <= 32; keySz += 8) {
  12454. for (msgSz = AES_BLOCK_SIZE;
  12455. msgSz <= sizeof(bigMsg);
  12456. msgSz += AES_BLOCK_SIZE) {
  12457. XMEMSET(bigCipher, 0, sizeof(bigMsg));
  12458. XMEMSET(bigPlain, 0, sizeof(bigMsg));
  12459. ret = wc_AesSetKey(enc, bigKey, keySz, iv, AES_ENCRYPTION);
  12460. if (ret != 0) {
  12461. ret = WC_TEST_RET_ENC_EC(ret);
  12462. break;
  12463. }
  12464. ret = wc_AesSetKey(dec, bigKey, keySz, iv, AES_DECRYPTION);
  12465. if (ret != 0) {
  12466. ret = WC_TEST_RET_ENC_EC(ret);
  12467. break;
  12468. }
  12469. ret = wc_AesCbcEncrypt(enc, bigCipher, bigMsg, msgSz);
  12470. #if defined(WOLFSSL_ASYNC_CRYPT)
  12471. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12472. #endif
  12473. if (ret != 0) {
  12474. ret = WC_TEST_RET_ENC_EC(ret);
  12475. break;
  12476. }
  12477. ret = wc_AesCbcDecrypt(dec, bigPlain, bigCipher, msgSz);
  12478. #if defined(WOLFSSL_ASYNC_CRYPT)
  12479. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12480. #endif
  12481. if (ret != 0) {
  12482. ret = WC_TEST_RET_ENC_EC(ret);
  12483. break;
  12484. }
  12485. if (XMEMCMP(bigPlain, bigMsg, msgSz)) {
  12486. ret = WC_TEST_RET_ENC_NC;
  12487. break;
  12488. }
  12489. }
  12490. if (ret != 0)
  12491. break;
  12492. }
  12493. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12494. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  12495. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12496. XFREE(bigCipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12497. XFREE(bigPlain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  12498. #endif
  12499. if (ret != 0)
  12500. goto out;
  12501. }
  12502. #endif /* WOLFSSL_AESNI && HAVE_AES_DECRYPT */
  12503. /* Test of AES IV state with encrypt/decrypt */
  12504. #if defined(WOLFSSL_AES_128) && !defined(HAVE_RENESAS_SYNC)
  12505. {
  12506. /* Test Vector from "NIST Special Publication 800-38A, 2001 Edition"
  12507. * https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38a.pdf
  12508. */
  12509. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] =
  12510. {
  12511. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  12512. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  12513. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  12514. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51
  12515. };
  12516. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] =
  12517. {
  12518. 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
  12519. 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
  12520. 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
  12521. 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2
  12522. };
  12523. WOLFSSL_SMALL_STACK_STATIC const byte key2[] = {
  12524. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  12525. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  12526. };
  12527. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] = {
  12528. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  12529. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  12530. };
  12531. ret = wc_AesSetKey(enc, key2, sizeof(key2), iv2, AES_ENCRYPTION);
  12532. if (ret != 0)
  12533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12534. XMEMSET(cipher, 0, AES_BLOCK_SIZE * 2);
  12535. ret = wc_AesCbcEncrypt(enc, cipher, msg2, AES_BLOCK_SIZE);
  12536. #if defined(WOLFSSL_ASYNC_CRYPT)
  12537. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12538. #endif
  12539. if (ret != 0)
  12540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12541. #ifndef HAVE_RENESAS_SYNC
  12542. if (XMEMCMP(cipher, verify2, AES_BLOCK_SIZE))
  12543. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12544. #endif
  12545. ret = wc_AesCbcEncrypt(enc, cipher + AES_BLOCK_SIZE,
  12546. msg2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12547. #if defined(WOLFSSL_ASYNC_CRYPT)
  12548. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12549. #endif
  12550. if (ret != 0)
  12551. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12552. if (XMEMCMP(cipher + AES_BLOCK_SIZE, verify2 + AES_BLOCK_SIZE,
  12553. AES_BLOCK_SIZE))
  12554. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12555. #if defined(HAVE_AES_DECRYPT)
  12556. ret = wc_AesSetKey(dec, key2, sizeof(key2), iv2, AES_DECRYPTION);
  12557. if (ret != 0)
  12558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12559. XMEMSET(plain, 0, AES_BLOCK_SIZE * 2);
  12560. ret = wc_AesCbcDecrypt(dec, plain, verify2, AES_BLOCK_SIZE);
  12561. #if defined(WOLFSSL_ASYNC_CRYPT)
  12562. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12563. #endif
  12564. if (ret != 0)
  12565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12566. if (XMEMCMP(plain, msg2, AES_BLOCK_SIZE))
  12567. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12568. ret = wc_AesCbcDecrypt(dec, plain + AES_BLOCK_SIZE,
  12569. verify2 + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
  12570. #if defined(WOLFSSL_ASYNC_CRYPT)
  12571. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12572. #endif
  12573. if (ret != 0)
  12574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12575. if (XMEMCMP(plain + AES_BLOCK_SIZE, msg2 + AES_BLOCK_SIZE,
  12576. AES_BLOCK_SIZE)) {
  12577. WOLFSSL_MSG("wc_AesCbcDecrypt failed plain-msg2 compare");
  12578. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12579. }
  12580. #endif /* HAVE_AES_DECRYPT */
  12581. aes_cbc_oneshot_test();
  12582. }
  12583. #endif /* WOLFSSL_AES_128 && !HAVE_RENESAS_SYNC */
  12584. out:
  12585. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12586. wc_AesDelete(enc, &enc);
  12587. #else
  12588. wc_AesFree(enc);
  12589. #endif
  12590. #ifdef HAVE_AES_DECRYPT
  12591. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12592. wc_AesDelete(dec, &dec);
  12593. #else
  12594. wc_AesFree(dec);
  12595. #endif
  12596. #endif
  12597. return ret;
  12598. }
  12599. #endif /* HAVE_AES_CBC */
  12600. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12601. static wc_test_ret_t aes_ecb_direct_test(void)
  12602. {
  12603. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12604. Aes *enc = NULL;
  12605. #else
  12606. Aes enc[1];
  12607. #endif
  12608. #if !defined(HAVE_AES_DECRYPT) || \
  12609. (defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC))
  12610. Aes *dec = NULL;
  12611. #else
  12612. Aes dec[1];
  12613. #endif
  12614. byte cipher[AES_BLOCK_SIZE];
  12615. byte plain [AES_BLOCK_SIZE];
  12616. wc_test_ret_t ret = 0;
  12617. WOLFSSL_ENTER("aes_ecb/direct_test");
  12618. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_NO_MALLOC)
  12619. XMEMSET(enc, 0, sizeof(Aes));
  12620. #ifdef HAVE_AES_DECRYPT
  12621. XMEMSET(dec, 0, sizeof(Aes));
  12622. #endif
  12623. #endif
  12624. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12625. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12626. if (enc == NULL)
  12627. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12628. #ifdef HAVE_AES_DECRYPT
  12629. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12630. if (dec == NULL)
  12631. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12632. #endif
  12633. #else
  12634. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12635. if (ret != 0)
  12636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12637. #ifdef HAVE_AES_DECRYPT
  12638. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12639. if (ret != 0)
  12640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12641. #endif
  12642. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12643. #ifdef HAVE_AES_ECB
  12644. ret = aes_ecb_test(enc, dec, cipher, plain);
  12645. if (ret != 0)
  12646. return ret;
  12647. #endif
  12648. #ifdef WOLFSSL_AES_DIRECT
  12649. ret = aes_direct_test(enc, dec, cipher, plain);
  12650. if (ret != 0)
  12651. return ret;
  12652. #endif
  12653. out:
  12654. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12655. wc_AesDelete(enc, &enc);
  12656. wc_AesDelete(dec, &dec);
  12657. #else
  12658. wc_AesFree(enc);
  12659. wc_AesFree(dec);
  12660. #endif
  12661. return ret;
  12662. }
  12663. #endif /* HAVE_AES_ECB || WOLFSSL_AES_DIRECT */
  12664. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_test(void)
  12665. {
  12666. wc_test_ret_t ret = 0;
  12667. WOLFSSL_ENTER("aes_test");
  12668. #ifndef HAVE_RENESAS_SYNC
  12669. ret = aes_key_size_test();
  12670. if (ret != 0)
  12671. goto out;
  12672. #endif
  12673. #if defined(HAVE_AES_ECB) || defined(WOLFSSL_AES_DIRECT)
  12674. ret = aes_ecb_direct_test();
  12675. if (ret != 0)
  12676. return ret;
  12677. #endif
  12678. out:
  12679. return ret;
  12680. }
  12681. #if defined(WOLFSSL_AES_CFB)
  12682. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_cfb_test(void)
  12683. {
  12684. int ret;
  12685. WOLFSSL_ENTER("aes_cfb_test");
  12686. ret = aescfb_test_0();
  12687. if (ret != 0)
  12688. return ret;
  12689. #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)
  12690. ret = aescfb1_test();
  12691. if (ret != 0)
  12692. return ret;
  12693. ret = aescfb8_test();
  12694. if (ret != 0)
  12695. return ret;
  12696. #endif
  12697. return 0;
  12698. }
  12699. #endif
  12700. #if defined(WOLFSSL_AES_XTS)
  12701. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_xts_test(void)
  12702. {
  12703. int ret = 0;
  12704. WOLFSSL_ENTER("aes_xts_test");
  12705. #ifdef WOLFSSL_AES_128
  12706. ret = aes_xts_128_test();
  12707. if (ret != 0)
  12708. return ret;
  12709. #endif
  12710. #ifdef WOLFSSL_AES_192
  12711. ret = aes_xts_192_test();
  12712. if (ret != 0)
  12713. return ret;
  12714. #endif
  12715. #ifdef WOLFSSL_AES_256
  12716. ret = aes_xts_256_test();
  12717. if (ret != 0)
  12718. return ret;
  12719. #endif
  12720. #if defined(WOLFSSL_AES_128) && defined(WOLFSSL_AES_256)
  12721. ret = aes_xts_sector_test();
  12722. if (ret != 0)
  12723. return ret;
  12724. #endif
  12725. #ifdef WOLFSSL_AES_128
  12726. ret = aes_xts_args_test();
  12727. if (ret != 0)
  12728. return ret;
  12729. #endif
  12730. return 0;
  12731. }
  12732. #endif
  12733. #ifdef WOLFSSL_AES_192
  12734. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
  12735. {
  12736. wc_test_ret_t ret = 0;
  12737. #ifdef HAVE_AES_CBC
  12738. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12739. Aes *enc = NULL;
  12740. #else
  12741. Aes enc[1];
  12742. #endif
  12743. byte cipher[AES_BLOCK_SIZE];
  12744. #ifdef HAVE_AES_DECRYPT
  12745. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12746. Aes *dec = NULL;
  12747. #else
  12748. Aes dec[1];
  12749. #endif
  12750. byte plain[AES_BLOCK_SIZE];
  12751. #endif
  12752. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition
  12753. * Appendix F.2.3 */
  12754. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12755. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12756. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12757. };
  12758. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12759. {
  12760. 0x4f,0x02,0x1d,0xb2,0x43,0xbc,0x63,0x3d,
  12761. 0x71,0x78,0x18,0x3a,0x9f,0xa0,0x71,0xe8
  12762. };
  12763. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12764. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  12765. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  12766. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  12767. };
  12768. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12769. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12770. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12771. };
  12772. WOLFSSL_ENTER("aes192_test");
  12773. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12774. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12775. if (enc == NULL)
  12776. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12777. #ifdef HAVE_AES_DECRYPT
  12778. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12779. if (dec == NULL)
  12780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12781. #endif
  12782. #else
  12783. XMEMSET(enc, 0, sizeof(Aes));
  12784. #ifdef HAVE_AES_DECRYPT
  12785. XMEMSET(dec, 0, sizeof(Aes));
  12786. #endif
  12787. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12788. if (ret != 0)
  12789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12790. #ifdef HAVE_AES_DECRYPT
  12791. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12792. if (ret != 0)
  12793. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12794. #endif
  12795. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12796. ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
  12797. if (ret != 0)
  12798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12799. #ifdef HAVE_AES_DECRYPT
  12800. ret = wc_AesSetKey(dec, key, (int) sizeof(key), iv, AES_DECRYPTION);
  12801. if (ret != 0)
  12802. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12803. #endif
  12804. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12805. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12806. #if defined(WOLFSSL_ASYNC_CRYPT)
  12807. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12808. #endif
  12809. if (ret != 0)
  12810. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12811. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12812. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12813. #ifdef HAVE_AES_DECRYPT
  12814. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12815. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12816. #if defined(WOLFSSL_ASYNC_CRYPT)
  12817. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12818. #endif
  12819. if (ret != 0)
  12820. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12821. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12822. WOLFSSL_MSG("failed wc_AesCbcDecrypt plain-msg compare");
  12823. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12824. }
  12825. #endif
  12826. out:
  12827. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12828. wc_AesDelete(enc, &enc);
  12829. #else
  12830. wc_AesFree(enc);
  12831. #endif
  12832. #ifdef HAVE_AES_DECRYPT
  12833. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12834. wc_AesDelete(dec, &dec);
  12835. #else
  12836. wc_AesFree(dec);
  12837. #endif
  12838. #endif
  12839. #endif /* HAVE_AES_CBC */
  12840. return ret;
  12841. }
  12842. #endif /* WOLFSSL_AES_192 */
  12843. #ifdef WOLFSSL_AES_256
  12844. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
  12845. {
  12846. #ifdef HAVE_AES_CBC
  12847. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12848. Aes *enc = NULL;
  12849. #else
  12850. Aes enc[1];
  12851. #endif
  12852. byte cipher[AES_BLOCK_SIZE];
  12853. #ifdef HAVE_AES_DECRYPT
  12854. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12855. Aes *dec = NULL;
  12856. #else
  12857. Aes dec[1];
  12858. #endif
  12859. byte plain[AES_BLOCK_SIZE];
  12860. #endif
  12861. #endif /* HAVE_AES_CBC */
  12862. wc_test_ret_t ret = 0;
  12863. #ifdef HAVE_AES_CBC
  12864. /* Test vectors from NIST Special Publication 800-38A, 2001 Edition,
  12865. * Appendix F.2.5 */
  12866. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  12867. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  12868. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  12869. };
  12870. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  12871. {
  12872. 0xf5,0x8c,0x4c,0x04,0xd6,0xe5,0xf1,0xba,
  12873. 0x77,0x9e,0xab,0xfb,0x5f,0x7b,0xfb,0xd6
  12874. };
  12875. #ifdef HAVE_RENESAS_SYNC
  12876. byte *key =
  12877. (byte*)guser_PKCbInfo.wrapped_key_aes256;
  12878. int keySz = (256/8);
  12879. #else
  12880. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  12881. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  12882. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  12883. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  12884. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  12885. };
  12886. int keySz = (int)sizeof(key);
  12887. #endif
  12888. WOLFSSL_SMALL_STACK_STATIC const byte iv[] = {
  12889. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  12890. 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F
  12891. };
  12892. WOLFSSL_ENTER("aes256_test");
  12893. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  12894. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  12895. if (enc == NULL)
  12896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12897. #ifdef HAVE_AES_DECRYPT
  12898. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  12899. if (dec == NULL)
  12900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12901. #endif
  12902. #else
  12903. XMEMSET(enc, 0, sizeof(Aes));
  12904. #ifdef HAVE_AES_DECRYPT
  12905. XMEMSET(dec, 0, sizeof(Aes));
  12906. #endif
  12907. ret = wc_AesInit(enc, HEAP_HINT, devId);
  12908. if (ret != 0)
  12909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12910. #ifdef HAVE_AES_DECRYPT
  12911. ret = wc_AesInit(dec, HEAP_HINT, devId);
  12912. if (ret != 0)
  12913. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12914. #endif
  12915. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  12916. ret = wc_AesSetKey(enc, key, (word32)keySz, iv, AES_ENCRYPTION);
  12917. if (ret != 0)
  12918. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12919. #ifdef HAVE_AES_DECRYPT
  12920. ret = wc_AesSetKey(dec, key, (word32)keySz, iv, AES_DECRYPTION);
  12921. if (ret != 0)
  12922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12923. #endif
  12924. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12925. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12926. #if defined(WOLFSSL_ASYNC_CRYPT)
  12927. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12928. #endif
  12929. if (ret != 0)
  12930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12931. #ifdef HAVE_AES_DECRYPT
  12932. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12933. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12934. #if defined(WOLFSSL_ASYNC_CRYPT)
  12935. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12936. #endif
  12937. if (ret != 0)
  12938. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12939. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12940. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12941. }
  12942. #endif
  12943. #ifndef HAVE_RENESAS_SYNC
  12944. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12945. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12946. #endif
  12947. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  12948. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12949. if (ret != 0)
  12950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12951. #ifdef HAVE_AES_DECRYPT
  12952. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12953. if (ret != 0)
  12954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12955. #endif
  12956. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12957. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12958. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12959. #if defined(WOLFSSL_ASYNC_CRYPT)
  12960. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12961. #endif
  12962. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12963. if (ret != 0)
  12964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12965. #ifdef HAVE_AES_DECRYPT
  12966. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  12967. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12968. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  12969. #if defined(WOLFSSL_ASYNC_CRYPT)
  12970. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  12971. #endif
  12972. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12973. if (ret != 0)
  12974. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12975. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  12976. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12977. }
  12978. #endif
  12979. #ifndef HAVE_RENESAS_SYNC
  12980. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  12981. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  12982. #endif
  12983. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12984. ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
  12985. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12986. if (ret != 0)
  12987. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12988. #ifdef HAVE_AES_DECRYPT
  12989. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  12990. ret = wc_AesSetKey(dec, key, keySz, iv, AES_DECRYPTION);
  12991. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  12992. if (ret != 0)
  12993. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  12994. #endif
  12995. XMEMSET(cipher, 0, AES_BLOCK_SIZE);
  12996. ret = wc_AesCbcEncrypt(enc, cipher, msg, (int) sizeof(msg));
  12997. #if defined(WOLFSSL_ASYNC_CRYPT)
  12998. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  12999. #endif
  13000. if (ret != 0)
  13001. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13002. #ifdef HAVE_AES_DECRYPT
  13003. XMEMSET(plain, 0, AES_BLOCK_SIZE);
  13004. ret = wc_AesCbcDecrypt(dec, plain, cipher, (int) sizeof(cipher));
  13005. #if defined(WOLFSSL_ASYNC_CRYPT)
  13006. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13007. #endif
  13008. if (ret != 0)
  13009. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13010. if (XMEMCMP(plain, msg, (int) sizeof(plain))) {
  13011. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13012. }
  13013. #endif
  13014. #ifndef HAVE_RENESAS_SYNC
  13015. if (XMEMCMP(cipher, verify, (int) sizeof(cipher)))
  13016. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13017. #endif
  13018. #endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_C_DYNAMIC_FALLBACK */
  13019. out:
  13020. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13021. wc_AesDelete(enc, &enc);
  13022. #else
  13023. wc_AesFree(enc);
  13024. #endif
  13025. #ifdef HAVE_AES_DECRYPT
  13026. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13027. wc_AesDelete(dec, &dec);
  13028. #else
  13029. wc_AesFree(dec);
  13030. #endif
  13031. #endif
  13032. #endif /* HAVE_AES_CBC */
  13033. return ret;
  13034. }
  13035. #endif /* WOLFSSL_AES_256 */
  13036. #ifdef HAVE_AESGCM
  13037. #ifdef WOLFSSL_AES_128
  13038. static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
  13039. byte* plain, int plainSz, byte* cipher, int cipherSz,
  13040. byte* aad, int aadSz, byte* tag, int tagSz)
  13041. {
  13042. wc_test_ret_t ret;
  13043. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13044. Aes *enc = NULL;
  13045. Aes *dec = NULL;
  13046. #else
  13047. Aes enc[1];
  13048. Aes dec[1];
  13049. #endif
  13050. byte resultT[AES_BLOCK_SIZE];
  13051. byte resultP[AES_BLOCK_SIZE * 3];
  13052. byte resultC[AES_BLOCK_SIZE * 3];
  13053. XMEMSET(resultT, 0, sizeof(resultT));
  13054. XMEMSET(resultC, 0, sizeof(resultC));
  13055. XMEMSET(resultP, 0, sizeof(resultP));
  13056. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13057. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13058. if (enc == NULL)
  13059. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13060. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13061. if (dec == NULL)
  13062. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13063. #else
  13064. XMEMSET(enc, 0, sizeof(Aes));
  13065. XMEMSET(dec, 0, sizeof(Aes));
  13066. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13067. if (ret != 0)
  13068. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13069. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13070. if (ret != 0)
  13071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13072. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  13073. ret = wc_AesGcmSetKey(enc, key, (word32)keySz);
  13074. if (ret != 0)
  13075. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13076. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13077. ret = wc_AesGcmEncrypt(enc, resultC, plain, (word32)plainSz, iv, (word32)ivSz,
  13078. resultT, (word32)tagSz, aad, (word32)aadSz);
  13079. #if defined(WOLFSSL_ASYNC_CRYPT)
  13080. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13081. #endif
  13082. if (ret != 0)
  13083. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13084. if (cipher != NULL) {
  13085. if (XMEMCMP(cipher, resultC, (word32)cipherSz))
  13086. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13087. }
  13088. if (XMEMCMP(tag, resultT, (unsigned long)tagSz))
  13089. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13090. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13091. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13092. ret = wc_AesGcmEncrypt(enc, resultC, plain, plainSz, iv, ivSz,
  13093. resultT, tagSz, aad, aadSz);
  13094. #if defined(WOLFSSL_ASYNC_CRYPT)
  13095. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13096. #endif
  13097. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13098. if (ret != 0)
  13099. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13100. if (cipher != NULL) {
  13101. if (XMEMCMP(cipher, resultC, (unsigned long)cipherSz))
  13102. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13103. }
  13104. if (XMEMCMP(tag, resultT, tagSz))
  13105. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13106. #endif
  13107. #ifdef HAVE_AES_DECRYPT
  13108. ret = wc_AesGcmSetKey(dec, key, (word32)keySz);
  13109. if (ret != 0)
  13110. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13111. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)cipherSz,
  13112. iv, (word32)ivSz, resultT, (word32)tagSz, aad, (word32)aadSz);
  13113. #if defined(WOLFSSL_ASYNC_CRYPT)
  13114. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13115. #endif
  13116. if (ret != 0)
  13117. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13118. if (plain != NULL) {
  13119. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13120. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13121. }
  13122. #if defined(DEBUG_VECTOR_REGISTER_ACCESS) && defined(WC_C_DYNAMIC_FALLBACK)
  13123. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(WC_NO_ERR_TRACE(SYSLIB_FAILED_E));
  13124. ret = wc_AesGcmDecrypt(dec, resultP, resultC, cipherSz,
  13125. iv, ivSz, resultT, tagSz, aad, aadSz);
  13126. #if defined(WOLFSSL_ASYNC_CRYPT)
  13127. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13128. #endif
  13129. WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL(0);
  13130. if (ret != 0)
  13131. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13132. if (plain != NULL) {
  13133. if (XMEMCMP(plain, resultP, (unsigned long)plainSz))
  13134. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13135. }
  13136. #endif
  13137. #endif /* HAVE_AES_DECRYPT */
  13138. ret = 0;
  13139. out:
  13140. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13141. wc_AesDelete(enc, &enc);
  13142. wc_AesDelete(dec, &dec);
  13143. #else
  13144. wc_AesFree(enc);
  13145. wc_AesFree(dec);
  13146. #endif
  13147. return ret;
  13148. }
  13149. #endif
  13150. /* tests that only use 12 byte IV and 16 or less byte AAD
  13151. * test vectors are from NIST SP 800-38D
  13152. * https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/CAVP-TESTING-BLOCK-CIPHER-MODES*/
  13153. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_default_test(void)
  13154. {
  13155. #ifdef WOLFSSL_AES_128
  13156. byte key1[] = {
  13157. 0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62,
  13158. 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc
  13159. };
  13160. byte iv1[] = {
  13161. 0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa,
  13162. 0xe4, 0xed, 0x2f, 0x6d
  13163. };
  13164. ALIGN64 byte plain1[] = {
  13165. 0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad,
  13166. 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01,
  13167. 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac,
  13168. 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01
  13169. };
  13170. byte aad1[] = {
  13171. 0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73,
  13172. 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1
  13173. };
  13174. ALIGN64 byte cipher1[] = {
  13175. 0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d,
  13176. 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d,
  13177. 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46,
  13178. 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb
  13179. };
  13180. byte tag1[] = {
  13181. 0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7,
  13182. 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2
  13183. };
  13184. byte key2[] = {
  13185. 0x01, 0x6d, 0xbb, 0x38, 0xda, 0xa7, 0x6d, 0xfe,
  13186. 0x7d, 0xa3, 0x84, 0xeb, 0xf1, 0x24, 0x03, 0x64
  13187. };
  13188. byte iv2[] = {
  13189. 0x07, 0x93, 0xef, 0x3a, 0xda, 0x78, 0x2f, 0x78,
  13190. 0xc9, 0x8a, 0xff, 0xe3
  13191. };
  13192. ALIGN64 byte plain2[] = {
  13193. 0x4b, 0x34, 0xa9, 0xec, 0x57, 0x63, 0x52, 0x4b,
  13194. 0x19, 0x1d, 0x56, 0x16, 0xc5, 0x47, 0xf6, 0xb7
  13195. };
  13196. ALIGN64 byte cipher2[] = {
  13197. 0x60, 0x9a, 0xa3, 0xf4, 0x54, 0x1b, 0xc0, 0xfe,
  13198. 0x99, 0x31, 0xda, 0xad, 0x2e, 0xe1, 0x5d, 0x0c
  13199. };
  13200. byte tag2[] = {
  13201. 0x33, 0xaf, 0xec, 0x59, 0xc4, 0x5b, 0xaf, 0x68,
  13202. 0x9a, 0x5e, 0x1b, 0x13, 0xae, 0x42, 0x36, 0x19
  13203. };
  13204. byte key3[] = {
  13205. 0xb0, 0x1e, 0x45, 0xcc, 0x30, 0x88, 0xaa, 0xba,
  13206. 0x9f, 0xa4, 0x3d, 0x81, 0xd4, 0x81, 0x82, 0x3f
  13207. };
  13208. byte iv3[] = {
  13209. 0x5a, 0x2c, 0x4a, 0x66, 0x46, 0x87, 0x13, 0x45,
  13210. 0x6a, 0x4b, 0xd5, 0xe1
  13211. };
  13212. byte tag3[] = {
  13213. 0x01, 0x42, 0x80, 0xf9, 0x44, 0xf5, 0x3c, 0x68,
  13214. 0x11, 0x64, 0xb2, 0xff
  13215. };
  13216. wc_test_ret_t ret;
  13217. WOLFSSL_ENTER("aesgcm_default_test");
  13218. ret = aesgcm_default_test_helper(key1, sizeof(key1), iv1, sizeof(iv1),
  13219. plain1, sizeof(plain1), cipher1, sizeof(cipher1),
  13220. aad1, sizeof(aad1), tag1, sizeof(tag1));
  13221. if (ret != 0) {
  13222. return ret;
  13223. }
  13224. ret = aesgcm_default_test_helper(key2, sizeof(key2), iv2, sizeof(iv2),
  13225. plain2, sizeof(plain2), cipher2, sizeof(cipher2),
  13226. NULL, 0, tag2, sizeof(tag2));
  13227. if (ret != 0) {
  13228. return ret;
  13229. }
  13230. ret = aesgcm_default_test_helper(key3, sizeof(key3), iv3, sizeof(iv3),
  13231. NULL, 0, NULL, 0,
  13232. NULL, 0, tag3, sizeof(tag3));
  13233. if (ret != 0) {
  13234. return ret;
  13235. }
  13236. #endif
  13237. return 0;
  13238. }
  13239. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesgcm_test(void)
  13240. {
  13241. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13242. Aes *enc = NULL;
  13243. Aes *dec = NULL;
  13244. #else
  13245. Aes enc[1];
  13246. Aes dec[1];
  13247. #endif
  13248. /*
  13249. * This is Test Case 16 from the document Galois/
  13250. * Counter Mode of Operation (GCM) by McGrew and
  13251. * Viega.
  13252. */
  13253. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  13254. {
  13255. 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
  13256. 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
  13257. 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
  13258. 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
  13259. 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
  13260. 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
  13261. 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
  13262. 0xba, 0x63, 0x7b, 0x39
  13263. };
  13264. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  13265. {
  13266. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13267. 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
  13268. 0xab, 0xad, 0xda, 0xd2
  13269. };
  13270. #ifdef WOLFSSL_AES_256
  13271. #ifdef HAVE_RENESAS_SYNC
  13272. const byte *k1 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  13273. int k1Sz = (int)(256/8);
  13274. #else
  13275. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  13276. {
  13277. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13278. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13279. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13280. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
  13281. };
  13282. int k1Sz = (int)sizeof(k1);
  13283. #endif
  13284. #endif /* WOLFSSL_AES_256 */
  13285. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  13286. {
  13287. 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
  13288. 0xde, 0xca, 0xf8, 0x88
  13289. };
  13290. #if defined(WOLFSSL_AES_256) || defined(WOLFSSL_AES_192)
  13291. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  13292. {
  13293. 0x52, 0x2d, 0xc1, 0xf0, 0x99, 0x56, 0x7d, 0x07,
  13294. 0xf4, 0x7f, 0x37, 0xa3, 0x2a, 0x84, 0x42, 0x7d,
  13295. 0x64, 0x3a, 0x8c, 0xdc, 0xbf, 0xe5, 0xc0, 0xc9,
  13296. 0x75, 0x98, 0xa2, 0xbd, 0x25, 0x55, 0xd1, 0xaa,
  13297. 0x8c, 0xb0, 0x8e, 0x48, 0x59, 0x0d, 0xbb, 0x3d,
  13298. 0xa7, 0xb0, 0x8b, 0x10, 0x56, 0x82, 0x88, 0x38,
  13299. 0xc5, 0xf6, 0x1e, 0x63, 0x93, 0xba, 0x7a, 0x0a,
  13300. 0xbc, 0xc9, 0xf6, 0x62
  13301. };
  13302. #endif /* WOLFSSL_AES_256 || WOLFSSL_AES_192 */
  13303. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  13304. {
  13305. 0x76, 0xfc, 0x6e, 0xce, 0x0f, 0x4e, 0x17, 0x68,
  13306. 0xcd, 0xdf, 0x88, 0x53, 0xbb, 0x2d, 0x55, 0x1b
  13307. };
  13308. /* FIPS, QAT and PIC32MZ HW Crypto only support 12-byte IV */
  13309. #if !defined(HAVE_FIPS) && \
  13310. !defined(WOLFSSL_PIC32MZ_CRYPT) && \
  13311. !defined(FREESCALE_LTC) && !defined(FREESCALE_MMCAU) && \
  13312. !defined(WOLFSSL_XILINX_CRYPT) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13313. !defined(WOLFSSL_SILABS_SE_ACCEL) && !defined(WOLFSSL_KCAPI_AES) && \
  13314. !(defined(WOLF_CRYPTO_CB) && \
  13315. (defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC)))
  13316. #define ENABLE_NON_12BYTE_IV_TEST
  13317. #ifdef WOLFSSL_AES_192
  13318. /* Test Case 12, uses same plaintext and AAD data. */
  13319. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  13320. {
  13321. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
  13322. 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
  13323. 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c
  13324. };
  13325. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  13326. {
  13327. 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
  13328. 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
  13329. 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
  13330. 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
  13331. 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
  13332. 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
  13333. 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
  13334. 0xa6, 0x37, 0xb3, 0x9b
  13335. };
  13336. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  13337. {
  13338. 0xd2, 0x7e, 0x88, 0x68, 0x1c, 0xe3, 0x24, 0x3c,
  13339. 0x48, 0x30, 0x16, 0x5a, 0x8f, 0xdc, 0xf9, 0xff,
  13340. 0x1d, 0xe9, 0xa1, 0xd8, 0xe6, 0xb4, 0x47, 0xef,
  13341. 0x6e, 0xf7, 0xb7, 0x98, 0x28, 0x66, 0x6e, 0x45,
  13342. 0x81, 0xe7, 0x90, 0x12, 0xaf, 0x34, 0xdd, 0xd9,
  13343. 0xe2, 0xf0, 0x37, 0x58, 0x9b, 0x29, 0x2d, 0xb3,
  13344. 0xe6, 0x7c, 0x03, 0x67, 0x45, 0xfa, 0x22, 0xe7,
  13345. 0xe9, 0xb7, 0x37, 0x3b
  13346. };
  13347. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  13348. {
  13349. 0xdc, 0xf5, 0x66, 0xff, 0x29, 0x1c, 0x25, 0xbb,
  13350. 0xb8, 0x56, 0x8f, 0xc3, 0xd3, 0x76, 0xa6, 0xd9
  13351. };
  13352. #endif /* WOLFSSL_AES_192 */
  13353. #ifdef WOLFSSL_AES_128
  13354. /* The following is an interesting test case from the example
  13355. * FIPS test vectors for AES-GCM. IVlen = 1 byte */
  13356. WOLFSSL_SMALL_STACK_STATIC const byte p3[] =
  13357. {
  13358. 0x57, 0xce, 0x45, 0x1f, 0xa5, 0xe2, 0x35, 0xa5,
  13359. 0x8e, 0x1a, 0xa2, 0x3b, 0x77, 0xcb, 0xaf, 0xe2
  13360. };
  13361. #ifdef HAVE_RENESAS_SYNC
  13362. const byte *k3 =
  13363. (byte*)guser_PKCbInfo.wrapped_key_aes128;
  13364. int k3Sz = (int)(128/8);
  13365. #else
  13366. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  13367. {
  13368. 0xbb, 0x01, 0xd7, 0x03, 0x81, 0x1c, 0x10, 0x1a,
  13369. 0x35, 0xe0, 0xff, 0xd2, 0x91, 0xba, 0xf2, 0x4b
  13370. };
  13371. int k3Sz = (int)sizeof(k3);
  13372. #endif
  13373. WOLFSSL_SMALL_STACK_STATIC const byte iv3[] =
  13374. {
  13375. 0xca
  13376. };
  13377. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  13378. {
  13379. 0x6b, 0x5f, 0xb3, 0x9d, 0xc1, 0xc5, 0x7a, 0x4f,
  13380. 0xf3, 0x51, 0x4d, 0xc2, 0xd5, 0xf0, 0xd0, 0x07
  13381. };
  13382. WOLFSSL_SMALL_STACK_STATIC const byte a3[] =
  13383. {
  13384. 0x40, 0xfc, 0xdc, 0xd7, 0x4a, 0xd7, 0x8b, 0xf1,
  13385. 0x3e, 0x7c, 0x60, 0x55, 0x50, 0x51, 0xdd, 0x54
  13386. };
  13387. WOLFSSL_SMALL_STACK_STATIC const byte t3[] =
  13388. {
  13389. 0x06, 0x90, 0xed, 0x01, 0x34, 0xdd, 0xc6, 0x95,
  13390. 0x31, 0x2e, 0x2a, 0xf9, 0x57, 0x7a, 0x1e, 0xa6
  13391. };
  13392. #endif /* WOLFSSL_AES_128 */
  13393. #ifdef WOLFSSL_AES_256
  13394. int ivlen;
  13395. #endif
  13396. #endif
  13397. byte resultT[sizeof(t1) + AES_BLOCK_SIZE];
  13398. byte resultP[sizeof(p) + AES_BLOCK_SIZE];
  13399. byte resultC[sizeof(p) + AES_BLOCK_SIZE];
  13400. wc_test_ret_t ret = 0;
  13401. int alen = 0;
  13402. int plen = 0;
  13403. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13404. byte buf[sizeof(p) + AES_BLOCK_SIZE];
  13405. byte bufA[sizeof(a) + 1];
  13406. byte *large_aad = (byte*)XMALLOC((size_t)1024 + 16, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13407. #endif
  13408. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM)
  13409. #if !defined(BENCH_AESGCM_LARGE)
  13410. #define BENCH_AESGCM_LARGE 1024
  13411. #endif
  13412. #ifndef WOLFSSL_NO_MALLOC
  13413. byte *large_input = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13414. byte *large_output = (byte *)XMALLOC(BENCH_AESGCM_LARGE + AES_BLOCK_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13415. byte *large_outdec = (byte *)XMALLOC(BENCH_AESGCM_LARGE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13416. (void)alen;
  13417. (void)plen;
  13418. if ((! large_input) || (! large_output) || (! large_outdec))
  13419. ERROR_OUT(MEMORY_E, out);
  13420. #else
  13421. byte large_input[BENCH_AESGCM_LARGE];
  13422. byte large_output[BENCH_AESGCM_LARGE + AES_BLOCK_SIZE];
  13423. byte large_outdec[BENCH_AESGCM_LARGE];
  13424. #endif
  13425. XMEMSET(large_input, 0, BENCH_AESGCM_LARGE);
  13426. XMEMSET(large_output, 0, BENCH_AESGCM_LARGE + AES_BLOCK_SIZE);
  13427. XMEMSET(large_outdec, 0, BENCH_AESGCM_LARGE);
  13428. #endif
  13429. WOLFSSL_ENTER("aesgcm_test");
  13430. XMEMSET(resultT, 0, sizeof(resultT));
  13431. XMEMSET(resultC, 0, sizeof(resultC));
  13432. XMEMSET(resultP, 0, sizeof(resultP));
  13433. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13434. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  13435. if (enc == NULL)
  13436. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13437. dec = wc_AesNew(HEAP_HINT, devId, &ret);
  13438. if (dec == NULL)
  13439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13440. #else
  13441. ret = wc_AesInit(enc, HEAP_HINT, devId);
  13442. if (ret != 0)
  13443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13444. ret = wc_AesInit(dec, HEAP_HINT, devId);
  13445. if (ret != 0)
  13446. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13447. #endif
  13448. #ifdef WOLFSSL_AES_256
  13449. ret = wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13450. if (ret != 0)
  13451. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13452. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13453. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13454. resultT, sizeof(t1), a, sizeof(a));
  13455. #if defined(WOLFSSL_ASYNC_CRYPT)
  13456. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13457. #endif
  13458. if (ret != 0)
  13459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13460. #ifndef HAVE_RENESAS_SYNC
  13461. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13462. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13463. if (XMEMCMP(t1, resultT, sizeof(t1)))
  13464. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13465. #endif
  13466. #ifdef HAVE_AES_DECRYPT
  13467. ret = wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13468. if (ret != 0)
  13469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13470. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1),
  13471. iv1, sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13472. #if defined(WOLFSSL_ASYNC_CRYPT)
  13473. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13474. #endif
  13475. if (ret != 0)
  13476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13477. if (XMEMCMP(p, resultP, sizeof(p)))
  13478. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13479. #endif /* HAVE_AES_DECRYPT */
  13480. /* Large buffer test */
  13481. #ifdef BENCH_AESGCM_LARGE
  13482. /* setup test buffer */
  13483. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13484. large_input[alen] = (byte)alen;
  13485. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13486. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13487. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13488. resultT, sizeof(t1), a, sizeof(a));
  13489. #if defined(WOLFSSL_ASYNC_CRYPT)
  13490. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13491. #endif
  13492. if (ret != 0)
  13493. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13494. #ifdef HAVE_AES_DECRYPT
  13495. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13496. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13497. sizeof(t1), a, sizeof(a));
  13498. #if defined(WOLFSSL_ASYNC_CRYPT)
  13499. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13500. #endif
  13501. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13502. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13503. if (ret != 0)
  13504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13505. #endif /* HAVE_AES_DECRYPT */
  13506. #endif /* BENCH_AESGCM_LARGE */
  13507. #if defined(ENABLE_NON_12BYTE_IV_TEST) && defined(WOLFSSL_AES_256)
  13508. /* Variable IV length test */
  13509. for (ivlen=1; ivlen<k1Sz; ivlen++) {
  13510. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13511. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), k1,
  13512. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13513. #if defined(WOLFSSL_ASYNC_CRYPT)
  13514. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13515. #endif
  13516. if (ret != 0)
  13517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13518. #ifdef HAVE_AES_DECRYPT
  13519. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), k1,
  13520. (word32)ivlen, resultT, sizeof(t1), a, sizeof(a));
  13521. #if defined(WOLFSSL_ASYNC_CRYPT)
  13522. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13523. #endif
  13524. if (ret != 0)
  13525. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13526. #endif /* HAVE_AES_DECRYPT */
  13527. }
  13528. #endif
  13529. #if !(defined(WOLF_CRYPTO_CB) && defined(HAVE_INTEL_QA_SYNC))
  13530. /* Variable authenticated data length test */
  13531. for (alen=0; alen<(int)sizeof(p); alen++) {
  13532. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13533. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13534. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13535. #if defined(WOLFSSL_ASYNC_CRYPT)
  13536. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13537. #endif
  13538. if (ret != 0)
  13539. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13540. #ifdef HAVE_AES_DECRYPT
  13541. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13542. sizeof(iv1), resultT, sizeof(t1), p, (word32)alen);
  13543. #if defined(WOLFSSL_ASYNC_CRYPT)
  13544. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13545. #endif
  13546. if (ret != 0)
  13547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13548. #endif /* HAVE_AES_DECRYPT */
  13549. }
  13550. #if defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  13551. if (! large_aad)
  13552. ERROR_OUT(MEMORY_E, out);
  13553. XMEMSET(large_aad, 0, 1024+16);
  13554. /* Variable authenticated data length test */
  13555. for (alen=0; alen<=1024; alen+=16) {
  13556. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13557. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1,
  13558. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13559. if (ret != 0)
  13560. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13561. #ifdef HAVE_AES_DECRYPT
  13562. ret = wc_AesGcmDecrypt(dec, resultP, resultC, sizeof(c1), iv1,
  13563. sizeof(iv1), resultT, sizeof(t1), large_aad, (word32)alen);
  13564. if (ret != 0)
  13565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13566. #endif /* HAVE_AES_DECRYPT */
  13567. }
  13568. /* Test unaligned memory of all potential arguments */
  13569. ret = wc_AesGcmSetKey(enc, k1, k1Sz);
  13570. if (ret != 0)
  13571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13572. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13573. XMEMCPY(&buf[1], p, sizeof(p));
  13574. XMEMCPY(&bufA[1], a, sizeof(a));
  13575. ret = wc_AesGcmEncrypt(enc, &resultC[1], &buf[1], sizeof(p), iv1, sizeof(iv1),
  13576. &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13577. if (ret != 0)
  13578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13579. if (XMEMCMP(c1, &resultC[1], sizeof(c1)))
  13580. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13581. if (XMEMCMP(t1, &resultT[1], sizeof(t1)))
  13582. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13583. #ifdef HAVE_AES_DECRYPT
  13584. ret = wc_AesGcmSetKey(dec, k1, k1Sz);
  13585. if (ret != 0)
  13586. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13587. ret = wc_AesGcmDecrypt(dec, &resultP[1], &resultC[1], sizeof(c1),
  13588. iv1, sizeof(iv1), &resultT[1], sizeof(t1), &bufA[1], sizeof(a));
  13589. if (ret != 0)
  13590. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13591. if (XMEMCMP(p, &resultP[1], sizeof(p)))
  13592. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13593. #endif /* HAVE_AES_DECRYPT */
  13594. #endif /* Xilinx Versal */
  13595. #endif
  13596. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13597. #ifdef BENCH_AESGCM_LARGE
  13598. /* Variable plain text length test */
  13599. for (plen=1; plen<BENCH_AESGCM_LARGE; plen++) {
  13600. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13601. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13602. (word32)plen, iv1, sizeof(iv1), resultT,
  13603. sizeof(t1), a, sizeof(a));
  13604. #if defined(WOLFSSL_ASYNC_CRYPT)
  13605. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13606. #endif
  13607. if (ret != 0)
  13608. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13609. #ifdef HAVE_AES_DECRYPT
  13610. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13611. (word32)plen, iv1, sizeof(iv1), resultT,
  13612. sizeof(t1), a, sizeof(a));
  13613. #if defined(WOLFSSL_ASYNC_CRYPT)
  13614. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13615. #endif
  13616. if (ret != 0)
  13617. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13618. #endif /* HAVE_AES_DECRYPT */
  13619. }
  13620. #else /* BENCH_AESGCM_LARGE */
  13621. /* Variable plain text length test */
  13622. for (plen=1; plen<(int)sizeof(p); plen++) {
  13623. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13624. ret = wc_AesGcmEncrypt(enc, resultC, p, (word32)plen, iv1,
  13625. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13626. #if defined(WOLFSSL_ASYNC_CRYPT)
  13627. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13628. #endif
  13629. if (ret != 0)
  13630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13631. #ifdef HAVE_AES_DECRYPT
  13632. ret = wc_AesGcmDecrypt(dec, resultP, resultC, (word32)plen, iv1,
  13633. sizeof(iv1), resultT, sizeof(t1), a, sizeof(a));
  13634. #if defined(WOLFSSL_ASYNC_CRYPT)
  13635. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13636. #endif
  13637. if (ret != 0)
  13638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13639. #endif /* HAVE_AES_DECRYPT */
  13640. }
  13641. #endif /* BENCH_AESGCM_LARGE */
  13642. #endif
  13643. #endif /* WOLFSSL_AES_256 */
  13644. /* test with IV != 12 bytes */
  13645. #ifdef ENABLE_NON_12BYTE_IV_TEST
  13646. XMEMSET(resultT, 0, sizeof(resultT));
  13647. XMEMSET(resultC, 0, sizeof(resultC));
  13648. XMEMSET(resultP, 0, sizeof(resultP));
  13649. #ifdef WOLFSSL_AES_192
  13650. wc_AesGcmSetKey(enc, k2, sizeof(k2));
  13651. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13652. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv2, sizeof(iv2),
  13653. resultT, sizeof(t1), a, sizeof(a));
  13654. #if defined(WOLFSSL_ASYNC_CRYPT)
  13655. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13656. #endif
  13657. if (ret != 0)
  13658. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13659. if (XMEMCMP(c2, resultC, sizeof(c2)))
  13660. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13661. if (XMEMCMP(t2, resultT, sizeof(t1)))
  13662. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13663. #ifdef HAVE_AES_DECRYPT
  13664. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c1),
  13665. iv2, sizeof(iv2), resultT, sizeof(t1), a, sizeof(a));
  13666. #if defined(WOLFSSL_ASYNC_CRYPT)
  13667. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13668. #endif
  13669. if (ret != 0)
  13670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13671. if (XMEMCMP(p, resultP, sizeof(p)))
  13672. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13673. #endif /* HAVE_AES_DECRYPT */
  13674. /* Large buffer test */
  13675. #ifdef BENCH_AESGCM_LARGE
  13676. wc_AesGcmSetKey(enc, k2, (word32)sizeof(k2));
  13677. wc_AesGcmSetKey(dec, k2, (word32)sizeof(k2));
  13678. /* setup test buffer */
  13679. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13680. large_input[alen] = (byte)alen;
  13681. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13682. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13683. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13684. resultT, sizeof(t1), a, sizeof(a));
  13685. #if defined(WOLFSSL_ASYNC_CRYPT)
  13686. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13687. #endif
  13688. if (ret != 0)
  13689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13690. #ifdef HAVE_AES_DECRYPT
  13691. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13692. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13693. sizeof(t1), a, sizeof(a));
  13694. #if defined(WOLFSSL_ASYNC_CRYPT)
  13695. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13696. #endif
  13697. if (ret != 0)
  13698. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13699. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13700. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13701. #endif /* HAVE_AES_DECRYPT */
  13702. #endif /* BENCH_AESGCM_LARGE */
  13703. XMEMSET(resultT, 0, sizeof(resultT));
  13704. XMEMSET(resultC, 0, sizeof(resultC));
  13705. XMEMSET(resultP, 0, sizeof(resultP));
  13706. #endif /* WOLFSSL_AES_192 */
  13707. #ifdef WOLFSSL_AES_128
  13708. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13709. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13710. ret = wc_AesGcmEncrypt(enc, resultC, p3, sizeof(p3), iv3, sizeof(iv3),
  13711. resultT, sizeof(t3), a3, sizeof(a3));
  13712. #if defined(WOLFSSL_ASYNC_CRYPT)
  13713. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13714. #endif
  13715. if (ret != 0)
  13716. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13717. #ifndef HAVE_RENESAS_SYNC
  13718. if (XMEMCMP(c3, resultC, sizeof(c3)))
  13719. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13720. if (XMEMCMP(t3, resultT, sizeof(t3)))
  13721. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13722. #endif
  13723. #ifdef HAVE_AES_DECRYPT
  13724. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(c3),
  13725. iv3, sizeof(iv3), resultT, sizeof(t3), a3, sizeof(a3));
  13726. #if defined(WOLFSSL_ASYNC_CRYPT)
  13727. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13728. #endif
  13729. if (ret != 0)
  13730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13731. if (XMEMCMP(p3, resultP, sizeof(p3)))
  13732. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13733. #endif /* HAVE_AES_DECRYPT */
  13734. /* Large buffer test */
  13735. #ifdef BENCH_AESGCM_LARGE
  13736. wc_AesGcmSetKey(enc, k3, (word32)k3Sz);
  13737. wc_AesGcmSetKey(dec, k3, (word32)k3Sz);
  13738. /* setup test buffer */
  13739. for (alen=0; alen<BENCH_AESGCM_LARGE; alen++)
  13740. large_input[alen] = (byte)alen;
  13741. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13742. ret = wc_AesGcmEncrypt(enc, large_output, large_input,
  13743. BENCH_AESGCM_LARGE, iv1, sizeof(iv1),
  13744. resultT, sizeof(t1), a, sizeof(a));
  13745. #if defined(WOLFSSL_ASYNC_CRYPT)
  13746. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13747. #endif
  13748. if (ret != 0)
  13749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13750. #ifdef HAVE_AES_DECRYPT
  13751. ret = wc_AesGcmDecrypt(dec, large_outdec, large_output,
  13752. BENCH_AESGCM_LARGE, iv1, sizeof(iv1), resultT,
  13753. sizeof(t1), a, sizeof(a));
  13754. #if defined(WOLFSSL_ASYNC_CRYPT)
  13755. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13756. #endif
  13757. if (ret != 0)
  13758. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13759. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13760. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13761. #endif /* HAVE_AES_DECRYPT */
  13762. #endif /* BENCH_AESGCM_LARGE */
  13763. #endif /* WOLFSSL_AES_128 */
  13764. #endif /* ENABLE_NON_12BYTE_IV_TEST */
  13765. #if defined(WOLFSSL_AES_256) && !defined(WOLFSSL_AFALG_XILINX_AES) && \
  13766. !defined(WOLFSSL_XILINX_CRYPT) && \
  13767. !(defined(WOLF_CRYPTO_CB) && \
  13768. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC))
  13769. XMEMSET(resultT, 0, sizeof(resultT));
  13770. XMEMSET(resultC, 0, sizeof(resultC));
  13771. XMEMSET(resultP, 0, sizeof(resultP));
  13772. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13773. /* AES-GCM encrypt and decrypt both use AES encrypt internally */
  13774. ret = wc_AesGcmEncrypt(enc, resultC, p, sizeof(p), iv1, sizeof(iv1),
  13775. resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13776. #if defined(WOLFSSL_ASYNC_CRYPT)
  13777. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13778. #endif
  13779. if (ret != 0)
  13780. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13781. #ifndef HAVE_RENESAS_SYNC
  13782. if (XMEMCMP(c1, resultC, sizeof(c1)))
  13783. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13784. if (XMEMCMP(t1, resultT + 1, sizeof(t1) - 1))
  13785. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13786. #endif
  13787. #ifdef HAVE_AES_DECRYPT
  13788. ret = wc_AesGcmDecrypt(enc, resultP, resultC, sizeof(p),
  13789. iv1, sizeof(iv1), resultT + 1, sizeof(t1) - 1, a, sizeof(a));
  13790. #if defined(WOLFSSL_ASYNC_CRYPT)
  13791. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13792. #endif
  13793. if (ret != 0)
  13794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13795. if (XMEMCMP(p, resultP, sizeof(p)))
  13796. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13797. #endif /* HAVE_AES_DECRYPT */
  13798. #endif /* WOLFSSL_AES_256 */
  13799. #if !defined(HAVE_FIPS) || \
  13800. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  13801. /* Test encrypt with internally generated IV */
  13802. #if defined(WOLFSSL_AES_256) && !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST)) \
  13803. && !(defined(WOLF_CRYPTO_CB) && defined(HAVE_CAVIUM_OCTEON_SYNC))
  13804. {
  13805. WC_RNG rng;
  13806. byte randIV[12];
  13807. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  13808. if (ret != 0)
  13809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13810. XMEMSET(randIV, 0, sizeof(randIV));
  13811. XMEMSET(resultT, 0, sizeof(resultT));
  13812. XMEMSET(resultC, 0, sizeof(resultC));
  13813. XMEMSET(resultP, 0, sizeof(resultP));
  13814. wc_AesGcmSetKey(enc, k1, (word32)k1Sz);
  13815. ret = wc_AesGcmSetIV(enc, sizeof(randIV), NULL, 0, &rng);
  13816. if (ret != 0)
  13817. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13818. ret = wc_AesGcmEncrypt_ex(enc,
  13819. resultC, p, sizeof(p),
  13820. randIV, sizeof(randIV),
  13821. resultT, sizeof(t1),
  13822. a, sizeof(a));
  13823. #if defined(WOLFSSL_ASYNC_CRYPT)
  13824. ret = wc_AsyncWait(ret, &enc->asyncDev, WC_ASYNC_FLAG_NONE);
  13825. #endif
  13826. if (ret != 0)
  13827. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13828. /* Check the IV has been set. */
  13829. {
  13830. word32 i, ivSum = 0;
  13831. for (i = 0; i < sizeof(randIV); i++)
  13832. ivSum += randIV[i];
  13833. if (ivSum == 0)
  13834. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13835. }
  13836. #ifdef HAVE_AES_DECRYPT
  13837. wc_AesGcmSetKey(dec, k1, (word32)k1Sz);
  13838. ret = wc_AesGcmSetIV(dec, sizeof(randIV), NULL, 0, &rng);
  13839. if (ret != 0)
  13840. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13841. ret = wc_AesGcmDecrypt(dec,
  13842. resultP, resultC, sizeof(c1),
  13843. randIV, sizeof(randIV),
  13844. resultT, sizeof(t1),
  13845. a, sizeof(a));
  13846. #if defined(WOLFSSL_ASYNC_CRYPT)
  13847. ret = wc_AsyncWait(ret, &dec->asyncDev, WC_ASYNC_FLAG_NONE);
  13848. #endif
  13849. if (ret != 0)
  13850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13851. if (XMEMCMP(p, resultP, sizeof(p)))
  13852. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13853. #endif /* HAVE_AES_DECRYPT */
  13854. wc_FreeRng(&rng);
  13855. }
  13856. #endif /* WOLFSSL_AES_256 && !(WC_NO_RNG || HAVE_SELFTEST) */
  13857. #endif /* HAVE_FIPS_VERSION >= 2 */
  13858. #if !defined(WOLFSSL_AFALG_XILINX_AES) && !defined(WOLFSSL_XILINX_CRYPT)
  13859. #ifdef WOLFSSL_AES_256
  13860. #ifdef WOLFSSL_AESGCM_STREAM
  13861. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13862. if (ret != 0)
  13863. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13864. ret = wc_AesGcmEncryptUpdate(enc, resultC, p, sizeof(p), a, sizeof(a));
  13865. if (ret != 0)
  13866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13867. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13868. if (ret != 0)
  13869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13870. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13871. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13872. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13873. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13874. #ifdef HAVE_AES_DECRYPT
  13875. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13876. if (ret != 0)
  13877. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13878. ret = wc_AesGcmDecryptUpdate(enc, resultP, c1, sizeof(c1), a, sizeof(a));
  13879. if (ret != 0)
  13880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13881. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13882. if (ret != 0)
  13883. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13884. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13885. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13886. #endif
  13887. /* alen is the size to pass in with each update. */
  13888. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13889. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13890. if (ret != 0)
  13891. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13892. /* plen is the offset into AAD to update with. */
  13893. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13894. int len = sizeof(a) - plen;
  13895. if (len > alen) len = alen;
  13896. ret = wc_AesGcmEncryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13897. if (ret != 0)
  13898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13899. }
  13900. /* plen is the offset into plaintext to update with. */
  13901. for (plen = 0; plen < (int)sizeof(p); plen += alen) {
  13902. int len = sizeof(p) - plen;
  13903. if (len > alen) len = alen;
  13904. ret = wc_AesGcmEncryptUpdate(enc, resultC + plen, p + plen, (word32)len,
  13905. NULL, 0);
  13906. if (ret != 0)
  13907. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13908. }
  13909. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13910. if (ret != 0)
  13911. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13912. if (XMEMCMP(resultC, c1, sizeof(c1)) != 0)
  13913. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13914. if (XMEMCMP(resultT, t1, sizeof(t1)) != 0)
  13915. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13916. }
  13917. #ifdef HAVE_AES_DECRYPT
  13918. for (alen = 1; alen < AES_BLOCK_SIZE + 1; alen++) {
  13919. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13920. if (ret != 0)
  13921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13922. /* plen is the offset into AAD to update with. */
  13923. for (plen = 0; plen < (int)sizeof(a); plen += alen) {
  13924. int len = sizeof(a) - plen;
  13925. if (len > alen) len = alen;
  13926. ret = wc_AesGcmDecryptUpdate(enc, NULL, NULL, 0, a + plen, (word32)len);
  13927. if (ret != 0)
  13928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13929. }
  13930. /* plen is the offset into cipher text to update with. */
  13931. for (plen = 0; plen < (int)sizeof(c1); plen += alen) {
  13932. int len = sizeof(c1) - plen;
  13933. if (len > alen) len = alen;
  13934. ret = wc_AesGcmDecryptUpdate(enc, resultP + plen, c1 + plen, (word32)len,
  13935. NULL, 0);
  13936. if (ret != 0)
  13937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13938. }
  13939. ret = wc_AesGcmDecryptFinal(enc, t1, sizeof(t1));
  13940. if (ret != 0)
  13941. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13942. if (XMEMCMP(resultP, p, sizeof(p)) != 0)
  13943. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13944. }
  13945. #endif /* HAVE_AES_DECRYPT */
  13946. #ifdef BENCH_AESGCM_LARGE
  13947. /* setup test buffer */
  13948. ret = wc_AesGcmEncryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13949. if (ret != 0)
  13950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13951. ret = wc_AesGcmEncryptUpdate(enc, large_output, large_input,
  13952. BENCH_AESGCM_LARGE, a, sizeof(a));
  13953. if (ret != 0)
  13954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13955. ret = wc_AesGcmEncryptFinal(enc, resultT, sizeof(t1));
  13956. if (ret != 0)
  13957. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13958. #ifdef HAVE_AES_DECRYPT
  13959. ret = wc_AesGcmDecryptInit(enc, k1, sizeof(k1), iv1, sizeof(iv1));
  13960. if (ret != 0)
  13961. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13962. ret = wc_AesGcmDecryptUpdate(enc, large_outdec, large_output,
  13963. BENCH_AESGCM_LARGE, a, sizeof(a));
  13964. if (ret != 0)
  13965. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13966. ret = wc_AesGcmDecryptFinal(enc, resultT, sizeof(t1));
  13967. if (ret != 0)
  13968. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  13969. if (XMEMCMP(large_input, large_outdec, BENCH_AESGCM_LARGE))
  13970. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  13971. #endif /* HAVE_AES_DECRYPT */
  13972. #endif /* BENCH_AESGCM_LARGE */
  13973. #endif /* WOLFSSL_AESGCM_STREAM */
  13974. #endif /* WOLFSSL_AES_256 */
  13975. #endif /* !WOLFSSL_AFALG_XILINX_AES && !WOLFSSL_XILINX_CRYPT */
  13976. ret = 0;
  13977. out:
  13978. #if !defined(BENCH_EMBEDDED) && !defined(HAVE_CAVIUM) && \
  13979. !defined(WOLFSSL_NO_MALLOC)
  13980. XFREE(large_input, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13981. XFREE(large_output, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13982. XFREE(large_outdec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  13983. #endif
  13984. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13985. wc_AesDelete(enc, &enc);
  13986. wc_AesDelete(dec, &dec);
  13987. #else
  13988. wc_AesFree(enc);
  13989. wc_AesFree(dec);
  13990. #endif
  13991. return ret;
  13992. }
  13993. #ifdef WOLFSSL_AES_128
  13994. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t gmac_test(void)
  13995. {
  13996. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  13997. Gmac *gmac;
  13998. #else
  13999. Gmac gmac[1];
  14000. #endif
  14001. wc_test_ret_t ret;
  14002. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14003. {
  14004. 0x89, 0xc9, 0x49, 0xe9, 0xc8, 0x04, 0xaf, 0x01,
  14005. 0x4d, 0x56, 0x04, 0xb3, 0x94, 0x59, 0xf2, 0xc8
  14006. };
  14007. WOLFSSL_SMALL_STACK_STATIC const byte iv1[] =
  14008. {
  14009. 0xd1, 0xb1, 0x04, 0xc8, 0x15, 0xbf, 0x1e, 0x94,
  14010. 0xe2, 0x8c, 0x8f, 0x16
  14011. };
  14012. WOLFSSL_SMALL_STACK_STATIC const byte a1[] =
  14013. {
  14014. 0x82, 0xad, 0xcd, 0x63, 0x8d, 0x3f, 0xa9, 0xd9,
  14015. 0xf3, 0xe8, 0x41, 0x00, 0xd6, 0x1e, 0x07, 0x77
  14016. };
  14017. WOLFSSL_SMALL_STACK_STATIC const byte t1[] =
  14018. {
  14019. 0x88, 0xdb, 0x9d, 0x62, 0x17, 0x2e, 0xd0, 0x43,
  14020. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14021. };
  14022. #if (!defined(HAVE_FIPS) || \
  14023. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)))
  14024. /* FIPS builds only allow 16-byte auth tags. */
  14025. /* This sample uses a 15-byte auth tag. */
  14026. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14027. {
  14028. 0x40, 0xf7, 0xec, 0xb2, 0x52, 0x6d, 0xaa, 0xd4,
  14029. 0x74, 0x25, 0x1d, 0xf4, 0x88, 0x9e, 0xf6, 0x5b
  14030. };
  14031. WOLFSSL_SMALL_STACK_STATIC const byte iv2[] =
  14032. {
  14033. 0xee, 0x9c, 0x6e, 0x06, 0x15, 0x45, 0x45, 0x03,
  14034. 0x1a, 0x60, 0x24, 0xa7
  14035. };
  14036. WOLFSSL_SMALL_STACK_STATIC const byte a2[] =
  14037. {
  14038. 0x94, 0x81, 0x2c, 0x87, 0x07, 0x4e, 0x15, 0x18,
  14039. 0x34, 0xb8, 0x35, 0xaf, 0x1c, 0xa5, 0x7e, 0x56
  14040. };
  14041. WOLFSSL_SMALL_STACK_STATIC const byte t2[] =
  14042. {
  14043. 0xc6, 0x81, 0x79, 0x8e, 0x3d, 0xda, 0xb0, 0x9f,
  14044. 0x8d, 0x83, 0xb0, 0xbb, 0x14, 0xb6, 0x91
  14045. };
  14046. #endif
  14047. byte tag[16];
  14048. WOLFSSL_ENTER("gmac_test");
  14049. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14050. if ((gmac = (Gmac *)XMALLOC(sizeof *gmac, HEAP_HINT, DYNAMIC_TYPE_AES)) == NULL)
  14051. return WC_TEST_RET_ENC_ERRNO;
  14052. #endif
  14053. XMEMSET(gmac, 0, sizeof *gmac); /* clear context */
  14054. (void)wc_AesInit(&gmac->aes, HEAP_HINT, INVALID_DEVID); /* Make sure devId updated */
  14055. XMEMSET(tag, 0, sizeof(tag));
  14056. wc_GmacSetKey(gmac, k1, sizeof(k1));
  14057. wc_GmacUpdate(gmac, iv1, sizeof(iv1), a1, sizeof(a1), tag, sizeof(t1));
  14058. if (XMEMCMP(t1, tag, sizeof(t1)) != 0)
  14059. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14060. #if (!defined(HAVE_FIPS) || \
  14061. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)) )
  14062. XMEMSET(tag, 0, sizeof(tag));
  14063. wc_GmacSetKey(gmac, k2, sizeof(k2));
  14064. wc_GmacUpdate(gmac, iv2, sizeof(iv2), a2, sizeof(a2), tag, sizeof(t2));
  14065. if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
  14066. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14067. #if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
  14068. {
  14069. WOLFSSL_SMALL_STACK_STATIC const byte badT[] =
  14070. {
  14071. 0xde, 0xad, 0xbe, 0xef, 0x17, 0x2e, 0xd0, 0x43,
  14072. 0xaa, 0x10, 0xf1, 0x6d, 0x22, 0x7d, 0xc4, 0x1b
  14073. };
  14074. WC_RNG rng;
  14075. byte iv[12];
  14076. #ifndef HAVE_FIPS
  14077. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14078. if (ret != 0)
  14079. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14080. #else
  14081. ret = wc_InitRng(&rng);
  14082. if (ret != 0)
  14083. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14084. #endif
  14085. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14086. t1, sizeof(t1));
  14087. if (ret != 0)
  14088. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14089. ret = wc_GmacVerify(k1, sizeof(k1), iv1, sizeof(iv1), a1, sizeof(a1),
  14090. badT, sizeof(badT));
  14091. if (ret != WC_NO_ERR_TRACE(AES_GCM_AUTH_E))
  14092. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14093. ret = wc_GmacVerify(k2, sizeof(k2), iv2, sizeof(iv2), a2, sizeof(a2),
  14094. t2, sizeof(t2));
  14095. if (ret != 0)
  14096. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14097. XMEMSET(tag, 0, sizeof(tag));
  14098. XMEMSET(iv, 0, sizeof(iv));
  14099. ret = wc_Gmac(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14100. tag, sizeof(tag), &rng);
  14101. if (ret != 0)
  14102. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14103. ret = wc_GmacVerify(k1, sizeof(k1), iv, sizeof(iv), a1, sizeof(a1),
  14104. tag, sizeof(tag));
  14105. if (ret != 0)
  14106. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14107. wc_FreeRng(&rng);
  14108. }
  14109. #endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
  14110. #endif /* HAVE_FIPS */
  14111. ret = 0;
  14112. out:
  14113. wc_AesFree(&gmac->aes);
  14114. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14115. XFREE(gmac, HEAP_HINT, DYNAMIC_TYPE_AES);
  14116. #endif
  14117. return ret;
  14118. }
  14119. #endif /* WOLFSSL_AES_128 */
  14120. #endif /* HAVE_AESGCM */
  14121. #if defined(HAVE_AESCCM)
  14122. #if defined(WOLFSSL_AES_256)
  14123. static wc_test_ret_t aesccm_256_test(void)
  14124. {
  14125. wc_test_ret_t ret = 0;
  14126. /* Test vectors from NIST AES CCM 256-bit CAST Example #1 */
  14127. WOLFSSL_SMALL_STACK_STATIC const byte in_key[32] = {
  14128. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14129. 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
  14130. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14131. 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F
  14132. };
  14133. WOLFSSL_SMALL_STACK_STATIC const byte in_nonce[7] = {
  14134. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
  14135. WOLFSSL_SMALL_STACK_STATIC const byte in_auth[8] = {
  14136. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  14137. WOLFSSL_SMALL_STACK_STATIC const byte in_plaintext[4] = {
  14138. 0x20, 0x21, 0x22, 0x23};
  14139. WOLFSSL_SMALL_STACK_STATIC const byte exp_ciphertext[4] = {
  14140. 0x8A, 0xB1, 0xA8, 0x74};
  14141. WOLFSSL_SMALL_STACK_STATIC const byte exp_tag[4] = {
  14142. 0x95, 0xFC, 0x08, 0x20};
  14143. byte output[sizeof(in_plaintext)];
  14144. byte atag[sizeof(exp_tag)];
  14145. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14146. Aes* aes = wc_AesNew(HEAP_HINT, devId, &ret);
  14147. if (aes == NULL) {
  14148. ret = WC_TEST_RET_ENC_EC(ret);
  14149. }
  14150. #else
  14151. Aes aes[1];
  14152. ret = wc_AesInit(aes, HEAP_HINT, devId);
  14153. #endif
  14154. if (ret == 0) {
  14155. ret = wc_AesCcmSetKey(aes, in_key, sizeof(in_key));
  14156. }
  14157. if (ret == 0) {
  14158. ret = wc_AesCcmEncrypt(aes, output, in_plaintext, sizeof(in_plaintext),
  14159. in_nonce, sizeof(in_nonce),
  14160. atag, sizeof(atag),
  14161. in_auth, sizeof(in_auth));
  14162. }
  14163. /* Verify we produce the proper ciphertext and tag */
  14164. if (ret == 0 &&
  14165. (XMEMCMP(output, exp_ciphertext, sizeof(output)) ||
  14166. XMEMCMP(atag, exp_tag, sizeof(atag)))) {
  14167. ret = WC_TEST_RET_ENC_NC;
  14168. }
  14169. #ifdef HAVE_AES_DECRYPT
  14170. if (ret == 0) {
  14171. /* decrypt inline */
  14172. ret = wc_AesCcmDecrypt(aes, output, output, sizeof(output),
  14173. in_nonce, sizeof(in_nonce),
  14174. atag, sizeof(atag),
  14175. in_auth, sizeof(in_auth));
  14176. }
  14177. /* Verify decryption was successful */
  14178. if (ret == 0 &&
  14179. XMEMCMP(output, in_plaintext, sizeof(output))) {
  14180. ret = WC_TEST_RET_ENC_NC;
  14181. }
  14182. #endif
  14183. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14184. wc_AesDelete(aes, &aes);
  14185. #else
  14186. wc_AesFree(aes);
  14187. #endif
  14188. return ret;
  14189. }
  14190. #endif /* WOLFSSL_AES_256 */
  14191. #if defined(WOLFSSL_AES_128)
  14192. static wc_test_ret_t aesccm_128_test(void)
  14193. {
  14194. wc_test_ret_t ret;
  14195. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14196. Aes *enc = NULL;
  14197. #else
  14198. Aes enc[1];
  14199. #endif
  14200. /* key */
  14201. WOLFSSL_SMALL_STACK_STATIC const byte k[] =
  14202. {
  14203. 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  14204. 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf
  14205. };
  14206. /* nonce */
  14207. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  14208. {
  14209. 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xa0,
  14210. 0xa1, 0xa2, 0xa3, 0xa4, 0xa5
  14211. };
  14212. /* plaintext */
  14213. WOLFSSL_SMALL_STACK_STATIC const byte p[] =
  14214. {
  14215. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14216. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14217. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e
  14218. };
  14219. /* plaintext - long */
  14220. WOLFSSL_SMALL_STACK_STATIC const byte pl[] =
  14221. {
  14222. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  14223. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14224. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  14225. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14226. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  14227. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  14228. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  14229. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  14230. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  14231. 0x50
  14232. };
  14233. WOLFSSL_SMALL_STACK_STATIC const byte a[] =
  14234. {
  14235. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14236. };
  14237. /* ciphertext */
  14238. WOLFSSL_SMALL_STACK_STATIC const byte c[] =
  14239. {
  14240. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14241. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14242. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84
  14243. };
  14244. /* tag - authentication */
  14245. WOLFSSL_SMALL_STACK_STATIC const byte t[] =
  14246. {
  14247. 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0
  14248. };
  14249. /* ciphertext - long */
  14250. WOLFSSL_SMALL_STACK_STATIC const byte cl[] =
  14251. {
  14252. 0x58, 0x8c, 0x97, 0x9a, 0x61, 0xc6, 0x63, 0xd2,
  14253. 0xf0, 0x66, 0xd0, 0xc2, 0xc0, 0xf9, 0x89, 0x80,
  14254. 0x6d, 0x5f, 0x6b, 0x61, 0xda, 0xc3, 0x84, 0xe0,
  14255. 0x44, 0x2d, 0xbe, 0x25, 0xfa, 0x48, 0x2b, 0xa8,
  14256. 0x36, 0x0b, 0xbf, 0x01, 0xc0, 0x12, 0x45, 0xa4,
  14257. 0x82, 0x9f, 0x20, 0x6c, 0xc3, 0xd6, 0xae, 0x5b,
  14258. 0x54, 0x8d, 0xd0, 0xb1, 0x69, 0x2c, 0xec, 0x5e,
  14259. 0x95, 0xa5, 0x6b, 0x48, 0xc3, 0xc6, 0xc8, 0x9e,
  14260. 0xc7, 0x92, 0x98, 0x9d, 0x26, 0x7d, 0x2a, 0x10,
  14261. 0x0b
  14262. };
  14263. /* tag - authentication - long */
  14264. WOLFSSL_SMALL_STACK_STATIC const byte tl[] =
  14265. {
  14266. 0x89, 0xd8, 0xd2, 0x02, 0xc5, 0xcf, 0xae, 0xf4
  14267. };
  14268. /* tag - authentication - empty plaintext */
  14269. WOLFSSL_SMALL_STACK_STATIC const byte t_empty[] =
  14270. {
  14271. 0xe4, 0x28, 0x8a, 0xc3, 0x78, 0x00, 0x0f, 0xf5
  14272. };
  14273. byte t2[sizeof(t)];
  14274. byte p2[sizeof(p)];
  14275. byte c2[sizeof(c)];
  14276. byte iv2[sizeof(iv)];
  14277. byte pl2[sizeof(pl)];
  14278. byte cl2[sizeof(cl)];
  14279. byte tl2[sizeof(tl)];
  14280. byte t_empty2[sizeof(t_empty)];
  14281. XMEMSET(t2, 0, sizeof(t2));
  14282. XMEMSET(c2, 0, sizeof(c2));
  14283. XMEMSET(p2, 0, sizeof(p2));
  14284. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14285. enc = wc_AesNew(HEAP_HINT, devId, &ret);
  14286. if (enc == NULL)
  14287. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14288. #else
  14289. XMEMSET(enc, 0, sizeof(Aes));
  14290. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14291. if (ret != 0)
  14292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14293. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  14294. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14295. if (ret != 0)
  14296. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14297. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14298. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14299. t2, sizeof(t2), a, sizeof(a));
  14300. if (ret != 0)
  14301. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14302. if (XMEMCMP(c, c2, sizeof(c2)))
  14303. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14304. if (XMEMCMP(t, t2, sizeof(t2)))
  14305. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14306. #ifdef HAVE_AES_DECRYPT
  14307. ret = wc_AesCcmDecrypt(enc, p2, c2, sizeof(p2), iv, sizeof(iv),
  14308. t2, sizeof(t2), a, sizeof(a));
  14309. if (ret != 0)
  14310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14311. if (XMEMCMP(p, p2, sizeof(p2)))
  14312. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14313. /* Test the authentication failure */
  14314. t2[0]++; /* Corrupt the authentication tag. */
  14315. ret = wc_AesCcmDecrypt(enc, p2, c, sizeof(p2), iv, sizeof(iv),
  14316. t2, sizeof(t2), a, sizeof(a));
  14317. if (ret == 0)
  14318. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14319. /* Clear c2 to compare against p2. p2 should be set to zero in case of
  14320. * authentication fail. */
  14321. XMEMSET(c2, 0, sizeof(c2));
  14322. if (XMEMCMP(p2, c2, sizeof(p2)))
  14323. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14324. #endif
  14325. XMEMSET(t2, 0, sizeof(t2));
  14326. XMEMSET(c2, 0, sizeof(c2));
  14327. XMEMSET(p2, 0, sizeof(p2));
  14328. XMEMSET(iv2, 0, sizeof(iv2));
  14329. wc_AesFree(enc);
  14330. ret = wc_AesInit(enc, HEAP_HINT, devId);
  14331. if (ret != 0)
  14332. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14333. #ifndef HAVE_SELFTEST
  14334. /* selftest build does not have wc_AesCcmSetNonce() or
  14335. * wc_AesCcmEncrypt_ex() */
  14336. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14337. if (ret != 0)
  14338. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14339. ret = wc_AesCcmSetNonce(enc, iv, sizeof(iv));
  14340. if (ret != 0)
  14341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14342. ret = wc_AesCcmEncrypt_ex(enc, c2, p, sizeof(c2), iv2, sizeof(iv2),
  14343. t2, sizeof(t2), a, sizeof(a));
  14344. if (ret != 0)
  14345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14346. if (XMEMCMP(iv, iv2, sizeof(iv2)))
  14347. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14348. if (XMEMCMP(c, c2, sizeof(c2)))
  14349. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14350. if (XMEMCMP(t, t2, sizeof(t2)))
  14351. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14352. #endif
  14353. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  14354. /* test fail on invalid IV sizes */
  14355. ret = wc_AesCcmSetKey(enc, k, sizeof(k));
  14356. if (ret != 0)
  14357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14358. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14359. ret = wc_AesCcmEncrypt(enc, c2, p, sizeof(c2), iv, sizeof(iv),
  14360. t2, 1, a, sizeof(a));
  14361. if (ret == 0) {
  14362. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14363. }
  14364. #endif
  14365. /* AES-CCM encrypt and decrypt both use AES encrypt internally */
  14366. ret = wc_AesCcmEncrypt(enc, cl2, pl, sizeof(cl2), iv, sizeof(iv),
  14367. tl2, sizeof(tl2), a, sizeof(a));
  14368. if (ret != 0)
  14369. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14370. if (XMEMCMP(cl, cl2, sizeof(cl2)))
  14371. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14372. if (XMEMCMP(tl, tl2, sizeof(tl2)))
  14373. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14374. #ifdef HAVE_AES_DECRYPT
  14375. ret = wc_AesCcmDecrypt(enc, pl2, cl2, sizeof(pl2), iv, sizeof(iv),
  14376. tl2, sizeof(tl2), a, sizeof(a));
  14377. if (ret != 0)
  14378. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14379. if (XMEMCMP(pl, pl2, sizeof(pl2)))
  14380. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14381. #endif
  14382. /* test empty message as null input or output with nonzero inSz. */
  14383. ret = wc_AesCcmEncrypt(enc, pl2 /* out */, NULL /* in */, 1 /* inSz */,
  14384. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14385. a, sizeof(a));
  14386. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14387. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14388. ret = wc_AesCcmEncrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14389. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14390. a, sizeof(a));
  14391. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14392. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14393. #ifdef HAVE_AES_DECRYPT
  14394. ret = wc_AesCcmDecrypt(enc, pl2, NULL /* in */, 1 /* inSz */,
  14395. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14396. sizeof(a));
  14397. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14398. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14399. ret = wc_AesCcmDecrypt(enc, NULL /* out */, (const byte *)"" /* in */, 1 /* inSz */,
  14400. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14401. sizeof(a));
  14402. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  14403. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14404. #endif
  14405. /* test empty message as null input and output with zero inSz --
  14406. * must either succeed, or fail early with BAD_FUNC_ARG.
  14407. */
  14408. ret = wc_AesCcmEncrypt(enc, NULL /* out */, NULL /* in */, 0 /* inSz */,
  14409. iv, sizeof(iv), t_empty2, sizeof(t_empty2),
  14410. a, sizeof(a));
  14411. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  14412. if (ret != 0)
  14413. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14414. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14415. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14416. #ifdef HAVE_AES_DECRYPT
  14417. ret = wc_AesCcmDecrypt(enc, NULL /* out */, NULL /* in */,
  14418. 0 /* inSz */, iv, sizeof(iv), t_empty2,
  14419. sizeof(t_empty2), a, sizeof(a));
  14420. if (ret != 0)
  14421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14422. #endif
  14423. }
  14424. /* test empty message as zero-length string -- must work. */
  14425. ret = wc_AesCcmEncrypt(enc, pl2, (const byte *)"", 0 /* inSz */, iv,
  14426. sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14427. sizeof(a));
  14428. if (ret != 0)
  14429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14430. if (XMEMCMP(t_empty, t_empty2, sizeof(t_empty2)))
  14431. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  14432. #ifdef HAVE_AES_DECRYPT
  14433. ret = wc_AesCcmDecrypt(enc, pl2, (const byte *)"", 0 /* inSz */,
  14434. iv, sizeof(iv), t_empty2, sizeof(t_empty2), a,
  14435. sizeof(a));
  14436. if (ret != 0)
  14437. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14438. #endif
  14439. ret = 0;
  14440. out:
  14441. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  14442. wc_AesDelete(enc, &enc);
  14443. #else
  14444. wc_AesFree(enc);
  14445. #endif
  14446. return ret;
  14447. }
  14448. #endif /* WOLFSSL_AES_128 */
  14449. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aesccm_test(void)
  14450. {
  14451. wc_test_ret_t ret = 0;
  14452. WOLFSSL_ENTER("aesccm_test");
  14453. #ifdef WOLFSSL_AES_128
  14454. if (ret == 0)
  14455. ret = aesccm_128_test();
  14456. #endif
  14457. #ifdef WOLFSSL_AES_256
  14458. if (ret == 0)
  14459. ret = aesccm_256_test();
  14460. #endif
  14461. return ret;
  14462. }
  14463. #endif /* HAVE_AESCCM */
  14464. #if defined(WOLFSSL_AES_EAX) && \
  14465. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  14466. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_eax_test(void)
  14467. {
  14468. typedef struct {
  14469. byte key[AES_256_KEY_SIZE];
  14470. int key_length;
  14471. byte iv[AES_BLOCK_SIZE];
  14472. int iv_length;
  14473. byte aad[AES_BLOCK_SIZE * 2];
  14474. int aad_length;
  14475. byte msg[AES_BLOCK_SIZE * 2];
  14476. int msg_length;
  14477. byte ct[AES_BLOCK_SIZE * 2];
  14478. int ct_length;
  14479. byte tag[AES_BLOCK_SIZE];
  14480. int tag_length;
  14481. int valid;
  14482. } AadVector;
  14483. /* A small selection of Google wycheproof vectors that use vectors
  14484. * from the original paper: eprint.iacr.org/2003/069
  14485. * https://github.com/google/wycheproof/blob/master/testvectors/aes_eax_test.json
  14486. */
  14487. WOLFSSL_SMALL_STACK_STATIC const AadVector vectors[] = {
  14488. /* Vector from paper - empty message with auth data */
  14489. {
  14490. /* key, key length */
  14491. {0x23, 0x39, 0x52, 0xde, 0xe4, 0xd5, 0xed, 0x5f,
  14492. 0x9b, 0x9c, 0x6d, 0x6f, 0xf8, 0x0f, 0xf4, 0x78}, 16,
  14493. /* iv, iv length */
  14494. {0x62, 0xec, 0x67, 0xf9, 0xc3, 0xa4, 0xa4, 0x07,
  14495. 0xfc, 0xb2, 0xa8, 0xc4, 0x90, 0x31, 0xa8, 0xb3}, 16,
  14496. /* aad, aad length */
  14497. {0x6b, 0xfb, 0x91, 0x4f, 0xd0, 0x7e, 0xae, 0x6b}, 8,
  14498. /* msg, msg length */
  14499. {0}, 0,
  14500. /* ct, ct length */
  14501. {0}, 0,
  14502. /* tag, tag length */
  14503. {0xe0, 0x37, 0x83, 0x0e, 0x83, 0x89, 0xf2,
  14504. 0x7b, 0x02, 0x5a, 0x2d, 0x65, 0x27, 0xe7, 0x9d, 0x01}, 16,
  14505. /* valid */
  14506. 1,
  14507. },
  14508. /* Vector from paper - no auth data, valid auth tag */
  14509. {
  14510. /* key, key length */
  14511. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14512. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14513. /* iv , iv length */
  14514. {0x3c, 0x8c, 0xc2, 0x97, 0x0a, 0x00, 0x8f, 0x75,
  14515. 0xcc, 0x5b, 0xea, 0xe2, 0x84, 0x72, 0x58, 0xc2}, 16,
  14516. /* aad, aad length */
  14517. {0}, 0,
  14518. /* msg, msg length */
  14519. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14520. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14521. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  14522. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, 32,
  14523. /* ct, ct length */
  14524. {0x3c, 0x44, 0x1f, 0x32, 0xce, 0x07, 0x82, 0x23,
  14525. 0x64, 0xd7, 0xa2, 0x99, 0x0e, 0x50, 0xbb, 0x13,
  14526. 0xd7, 0xb0, 0x2a, 0x26, 0x96, 0x9e, 0x4a, 0x93,
  14527. 0x7e, 0x5e, 0x90, 0x73, 0xb0, 0xd9, 0xc9, 0x68}, 32,
  14528. /* tag, tag length */
  14529. {0xdb, 0x90, 0xbd, 0xb3, 0xda, 0x3d, 0x00, 0xaf,
  14530. 0xd0, 0xfc, 0x6a, 0x83, 0x55, 0x1d, 0xa9, 0x5e}, 16,
  14531. /* valid */
  14532. 1,
  14533. },
  14534. /* Vector from paper - no auth data with invalid auth tag */
  14535. {
  14536. /* key, key length */
  14537. {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14538. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, 16,
  14539. /* iv, iv length */
  14540. {0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  14541. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f}, 16,
  14542. /* aad, aad length */
  14543. {0}, 0,
  14544. /* msg, msg length */
  14545. {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  14546. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f}, 16,
  14547. /* ct , ct length */
  14548. {0x29, 0xa0, 0x91, 0x4f, 0xec, 0x4b, 0xef, 0x54,
  14549. 0xba, 0xbf, 0x66, 0x13, 0xa9, 0xf9, 0xcd, 0x70}, 16,
  14550. /* tag, tag length */
  14551. {0xe7, 0x0e, 0x7c, 0x50, 0x13, 0xa6, 0xdb, 0xf2,
  14552. 0x52, 0x98, 0xb1, 0x92, 0x9b, 0xc3, 0x56, 0xa7}, 16,
  14553. /* valid */
  14554. 0,
  14555. },
  14556. };
  14557. WOLFSSL_SMALL_STACK_STATIC byte ciphertext[sizeof(vectors[0].ct)];
  14558. WOLFSSL_SMALL_STACK_STATIC byte authtag[sizeof(vectors[0].tag)];
  14559. int i;
  14560. int len;
  14561. wc_test_ret_t ret;
  14562. WOLFSSL_ENTER("aes_eax_test");
  14563. for (i = 0; i < (int)(sizeof(vectors)/sizeof(vectors[0])); i++) {
  14564. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14565. len = sizeof(authtag);
  14566. ret = wc_AesEaxEncryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14567. ciphertext,
  14568. vectors[i].msg, (word32)vectors[i].msg_length,
  14569. vectors[i].iv, (word32)vectors[i].iv_length,
  14570. authtag, (word32)len,
  14571. vectors[i].aad, (word32)vectors[i].aad_length);
  14572. if (ret != 0) {
  14573. return WC_TEST_RET_ENC_EC(ret);
  14574. }
  14575. /* check ciphertext matches vector */
  14576. if (XMEMCMP(ciphertext, vectors[i].ct, (size_t)vectors[i].ct_length)) {
  14577. return WC_TEST_RET_ENC_NC;
  14578. }
  14579. /* check that tag matches vector only for vectors marked as valid */
  14580. ret = XMEMCMP(authtag, vectors[i].tag, len);
  14581. if (vectors[i].valid == 1 && ret != 0 ) {
  14582. return WC_TEST_RET_ENC_NC;
  14583. }
  14584. else if (vectors[i].valid == 0 && ret == 0) {
  14585. return WC_TEST_RET_ENC_NC;
  14586. }
  14587. XMEMSET(ciphertext, 0, sizeof(ciphertext));
  14588. ret = wc_AesEaxDecryptAuth(vectors[i].key, (word32)vectors[i].key_length,
  14589. ciphertext,
  14590. vectors[i].ct, (word32)vectors[i].ct_length,
  14591. vectors[i].iv, (word32)vectors[i].iv_length,
  14592. authtag, (word32)len,
  14593. vectors[i].aad, (word32)vectors[i].aad_length);
  14594. if (ret != 0) {
  14595. return WC_TEST_RET_ENC_EC(ret);
  14596. }
  14597. /* check decrypted ciphertext matches vector plaintext */
  14598. if (XMEMCMP(ciphertext, vectors[i].msg, (size_t)vectors[i].msg_length)) {
  14599. return WC_TEST_RET_ENC_NC;
  14600. }
  14601. }
  14602. return 0;
  14603. }
  14604. #endif /* WOLFSSL_AES_EAX */
  14605. #ifdef HAVE_AES_KEYWRAP
  14606. #define MAX_KEYWRAP_TEST_OUTLEN 40
  14607. #define MAX_KEYWRAP_TEST_PLAINLEN 32
  14608. typedef struct keywrapVector {
  14609. const byte* kek;
  14610. const byte* data;
  14611. const byte* verify;
  14612. word32 kekLen;
  14613. word32 dataLen;
  14614. word32 verifyLen;
  14615. } keywrapVector;
  14616. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aeskeywrap_test(void)
  14617. {
  14618. int wrapSz, plainSz, testSz, i;
  14619. /* test vectors from RFC 3394 (kek, data, verify) */
  14620. #ifdef WOLFSSL_AES_128
  14621. /* Wrap 128 bits of Key Data with a 128-bit KEK */
  14622. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  14623. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14624. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14625. };
  14626. WOLFSSL_SMALL_STACK_STATIC const byte d1[] = {
  14627. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14628. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14629. };
  14630. WOLFSSL_SMALL_STACK_STATIC const byte v1[] = {
  14631. 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47,
  14632. 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82,
  14633. 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5
  14634. };
  14635. #endif /* WOLFSSL_AES_128 */
  14636. #ifdef WOLFSSL_AES_192
  14637. /* Wrap 128 bits of Key Data with a 192-bit KEK */
  14638. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  14639. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14640. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14641. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14642. };
  14643. WOLFSSL_SMALL_STACK_STATIC const byte d2[] = {
  14644. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14645. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14646. };
  14647. WOLFSSL_SMALL_STACK_STATIC const byte v2[] = {
  14648. 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35,
  14649. 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2,
  14650. 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D
  14651. };
  14652. #endif
  14653. #ifdef WOLFSSL_AES_256
  14654. /* Wrap 128 bits of Key Data with a 256-bit KEK */
  14655. WOLFSSL_SMALL_STACK_STATIC const byte k3[] = {
  14656. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14657. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14658. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14659. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14660. };
  14661. WOLFSSL_SMALL_STACK_STATIC const byte d3[] = {
  14662. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14663. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
  14664. };
  14665. WOLFSSL_SMALL_STACK_STATIC const byte v3[] = {
  14666. 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2,
  14667. 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A,
  14668. 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7
  14669. };
  14670. #endif
  14671. #ifdef WOLFSSL_AES_192
  14672. /* Wrap 192 bits of Key Data with a 192-bit KEK */
  14673. WOLFSSL_SMALL_STACK_STATIC const byte k4[] = {
  14674. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14675. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14676. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
  14677. };
  14678. WOLFSSL_SMALL_STACK_STATIC const byte d4[] = {
  14679. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14680. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14681. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14682. };
  14683. WOLFSSL_SMALL_STACK_STATIC const byte v4[] = {
  14684. 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32,
  14685. 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC,
  14686. 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93,
  14687. 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2
  14688. };
  14689. #endif
  14690. #ifdef WOLFSSL_AES_256
  14691. /* Wrap 192 bits of Key Data with a 256-bit KEK */
  14692. WOLFSSL_SMALL_STACK_STATIC const byte k5[] = {
  14693. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14694. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14695. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14696. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14697. };
  14698. WOLFSSL_SMALL_STACK_STATIC const byte d5[] = {
  14699. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14700. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14701. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
  14702. };
  14703. WOLFSSL_SMALL_STACK_STATIC const byte v5[] = {
  14704. 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F,
  14705. 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4,
  14706. 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95,
  14707. 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1
  14708. };
  14709. /* Wrap 256 bits of Key Data with a 256-bit KEK */
  14710. WOLFSSL_SMALL_STACK_STATIC const byte k6[] = {
  14711. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14712. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  14713. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  14714. 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
  14715. };
  14716. WOLFSSL_SMALL_STACK_STATIC const byte d6[] = {
  14717. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14718. 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
  14719. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14720. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14721. };
  14722. WOLFSSL_SMALL_STACK_STATIC const byte v6[] = {
  14723. 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4,
  14724. 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26,
  14725. 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26,
  14726. 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B,
  14727. 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21
  14728. };
  14729. #endif /* WOLFSSL_AES_256 */
  14730. byte output[MAX_KEYWRAP_TEST_OUTLEN];
  14731. byte plain [MAX_KEYWRAP_TEST_PLAINLEN];
  14732. const keywrapVector test_wrap[] =
  14733. {
  14734. #ifdef WOLFSSL_AES_128
  14735. {k1, d1, v1, sizeof(k1), sizeof(d1), sizeof(v1)},
  14736. #endif
  14737. #ifdef WOLFSSL_AES_192
  14738. {k2, d2, v2, sizeof(k2), sizeof(d2), sizeof(v2)},
  14739. #endif
  14740. #ifdef WOLFSSL_AES_256
  14741. {k3, d3, v3, sizeof(k3), sizeof(d3), sizeof(v3)},
  14742. #endif
  14743. #ifdef WOLFSSL_AES_192
  14744. {k4, d4, v4, sizeof(k4), sizeof(d4), sizeof(v4)},
  14745. #endif
  14746. #ifdef WOLFSSL_AES_256
  14747. {k5, d5, v5, sizeof(k5), sizeof(d5), sizeof(v5)},
  14748. {k6, d6, v6, sizeof(k6), sizeof(d6), sizeof(v6)}
  14749. #endif
  14750. };
  14751. WOLFSSL_ENTER("aeskeywrap_test");
  14752. testSz = sizeof(test_wrap) / sizeof(keywrapVector);
  14753. XMEMSET(output, 0, sizeof(output));
  14754. XMEMSET(plain, 0, sizeof(plain));
  14755. for (i = 0; i < testSz; i++) {
  14756. wrapSz = wc_AesKeyWrap(test_wrap[i].kek, test_wrap[i].kekLen,
  14757. test_wrap[i].data, test_wrap[i].dataLen,
  14758. output, sizeof(output), NULL);
  14759. if ( (wrapSz < 0) || (wrapSz != (int)test_wrap[i].verifyLen) )
  14760. return WC_TEST_RET_ENC_NC;
  14761. if (XMEMCMP(output, test_wrap[i].verify, test_wrap[i].verifyLen) != 0)
  14762. return WC_TEST_RET_ENC_NC;
  14763. plainSz = wc_AesKeyUnWrap((byte*)test_wrap[i].kek, test_wrap[i].kekLen,
  14764. output, (word32)wrapSz,
  14765. plain, sizeof(plain), NULL);
  14766. if ( (plainSz < 0) || (plainSz != (int)test_wrap[i].dataLen) )
  14767. return WC_TEST_RET_ENC_NC;
  14768. if (XMEMCMP(plain, test_wrap[i].data, test_wrap[i].dataLen) != 0)
  14769. return WC_TEST_RET_ENC_I(i);
  14770. }
  14771. return 0;
  14772. }
  14773. #endif /* HAVE_AES_KEYWRAP */
  14774. #endif /* !NO_AES */
  14775. #ifdef HAVE_ARIA
  14776. void printOutput(const char *strName, unsigned char *data, unsigned int dataSz)
  14777. {
  14778. #ifndef DEBUG_WOLFSSL
  14779. (void)strName;
  14780. (void)data;
  14781. (void)dataSz;
  14782. #else
  14783. WOLFSSL_MSG_EX("%s (%d):", strName,dataSz);
  14784. WOLFSSL_BUFFER(data,dataSz);
  14785. #endif
  14786. }
  14787. WOLFSSL_TEST_SUBROUTINE int ariagcm_test(MC_ALGID algo)
  14788. {
  14789. byte data[] = TEST_STRING;
  14790. word32 dataSz = TEST_STRING_SZ;
  14791. /* Arbitrarily random long key that we will truncate to the right size */
  14792. byte key[] = { 0x1E, 0xCC, 0x95, 0xCB, 0xD3, 0x74, 0x58, 0x4F,
  14793. 0x6F, 0x8A, 0x70, 0x26, 0xF7, 0x3C, 0x8D, 0xB6,
  14794. 0xDC, 0x32, 0x76, 0x20, 0xCF, 0x05, 0x4A, 0xCF,
  14795. 0x11, 0x86, 0xCD, 0x23, 0x5E, 0xC1, 0x6E, 0x2B };
  14796. byte cipher[2*TEST_STRING_SZ], plain[TEST_STRING_SZ], ad[256], authTag[AES_BLOCK_SIZE];
  14797. word32 keySz, adSz = 256, authTagSz = sizeof(authTag);
  14798. wc_Aria aria;
  14799. int ret = 0;
  14800. WOLFSSL_ENTER("ariagcm_test");
  14801. XMEMSET((void *)&aria, 0, sizeof(aria));
  14802. ret = wc_AriaInitCrypt(&aria, algo);
  14803. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14804. ret = wc_AriaSetKey(&aria, key);
  14805. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14806. MC_GetObjectValue(aria.hSession, aria.hKey, key, &keySz);
  14807. printOutput("Key", key, keySz);
  14808. WC_RNG rng;
  14809. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  14810. if (ret != 0)
  14811. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14812. ret = wc_AriaGcmSetIV(&aria, GCM_NONCE_MID_SZ, NULL, 0, &rng);
  14813. if (ret != 0)
  14814. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  14815. wc_FreeRng(&rng);
  14816. printOutput("Plaintext", data, sizeof(data));
  14817. XMEMSET(cipher, 0, sizeof(cipher));
  14818. ret = wc_AriaEncrypt(&aria, cipher, data, dataSz,
  14819. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14820. authTag, authTagSz);
  14821. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14822. printOutput("Ciphertext", cipher, sizeof(cipher));
  14823. printOutput("AuthTag", authTag, sizeof(authTag));
  14824. XMEMSET(plain, 0, sizeof(plain));
  14825. ret = wc_AriaDecrypt(&aria, plain, cipher, dataSz,
  14826. (byte *)aria.nonce, aria.nonceSz, ad, adSz,
  14827. authTag, authTagSz);
  14828. if (ret != 0) { ERROR_OUT(WC_TEST_RET_ENC_EC(ret),out); }
  14829. printOutput("Plaintext", plain, sizeof(plain));
  14830. if (XMEMCMP(plain, data, dataSz) != 0)
  14831. ERROR_OUT(WC_TEST_RET_ENC_NC,out);
  14832. out:
  14833. if (ret != 0) { wc_AriaFreeCrypt(&aria); }
  14834. else { ret = wc_AriaFreeCrypt(&aria); }
  14835. return ret;
  14836. }
  14837. #endif /* HAVE_ARIA */
  14838. #ifdef HAVE_CAMELLIA
  14839. enum {
  14840. CAM_ECB_ENC, CAM_ECB_DEC, CAM_CBC_ENC, CAM_CBC_DEC
  14841. };
  14842. typedef struct {
  14843. int type;
  14844. const byte* plaintext;
  14845. const byte* iv;
  14846. const byte* ciphertext;
  14847. const byte* key;
  14848. word32 keySz;
  14849. int errorCode;
  14850. } test_vector_t;
  14851. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t camellia_test(void)
  14852. {
  14853. /* Camellia ECB Test Plaintext */
  14854. WOLFSSL_SMALL_STACK_STATIC const byte pte[] =
  14855. {
  14856. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14857. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14858. };
  14859. /* Camellia ECB Test Initialization Vector */
  14860. WOLFSSL_SMALL_STACK_STATIC const byte ive[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  14861. /* Test 1: Camellia ECB 128-bit key */
  14862. WOLFSSL_SMALL_STACK_STATIC const byte k1[] =
  14863. {
  14864. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14865. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
  14866. };
  14867. WOLFSSL_SMALL_STACK_STATIC const byte c1[] =
  14868. {
  14869. 0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
  14870. 0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
  14871. };
  14872. /* Test 2: Camellia ECB 192-bit key */
  14873. WOLFSSL_SMALL_STACK_STATIC const byte k2[] =
  14874. {
  14875. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14876. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14877. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
  14878. };
  14879. WOLFSSL_SMALL_STACK_STATIC const byte c2[] =
  14880. {
  14881. 0xb4, 0x99, 0x34, 0x01, 0xb3, 0xe9, 0x96, 0xf8,
  14882. 0x4e, 0xe5, 0xce, 0xe7, 0xd7, 0x9b, 0x09, 0xb9
  14883. };
  14884. /* Test 3: Camellia ECB 256-bit key */
  14885. WOLFSSL_SMALL_STACK_STATIC const byte k3[] =
  14886. {
  14887. 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
  14888. 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
  14889. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  14890. 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
  14891. };
  14892. WOLFSSL_SMALL_STACK_STATIC const byte c3[] =
  14893. {
  14894. 0x9a, 0xcc, 0x23, 0x7d, 0xff, 0x16, 0xd7, 0x6c,
  14895. 0x20, 0xef, 0x7c, 0x91, 0x9e, 0x3a, 0x75, 0x09
  14896. };
  14897. /* Camellia CBC Test Plaintext */
  14898. WOLFSSL_SMALL_STACK_STATIC const byte ptc[] =
  14899. {
  14900. 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
  14901. 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A
  14902. };
  14903. /* Camellia CBC Test Initialization Vector */
  14904. WOLFSSL_SMALL_STACK_STATIC const byte ivc[] =
  14905. {
  14906. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  14907. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  14908. };
  14909. /* Test 4: Camellia-CBC 128-bit key */
  14910. WOLFSSL_SMALL_STACK_STATIC const byte k4[] =
  14911. {
  14912. 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
  14913. 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
  14914. };
  14915. WOLFSSL_SMALL_STACK_STATIC const byte c4[] =
  14916. {
  14917. 0x16, 0x07, 0xCF, 0x49, 0x4B, 0x36, 0xBB, 0xF0,
  14918. 0x0D, 0xAE, 0xB0, 0xB5, 0x03, 0xC8, 0x31, 0xAB
  14919. };
  14920. /* Test 5: Camellia-CBC 192-bit key */
  14921. WOLFSSL_SMALL_STACK_STATIC const byte k5[] =
  14922. {
  14923. 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
  14924. 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
  14925. 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B
  14926. };
  14927. WOLFSSL_SMALL_STACK_STATIC const byte c5[] =
  14928. {
  14929. 0x2A, 0x48, 0x30, 0xAB, 0x5A, 0xC4, 0xA1, 0xA2,
  14930. 0x40, 0x59, 0x55, 0xFD, 0x21, 0x95, 0xCF, 0x93
  14931. };
  14932. /* Test 6: CBC 256-bit key */
  14933. WOLFSSL_SMALL_STACK_STATIC const byte k6[] =
  14934. {
  14935. 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
  14936. 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
  14937. 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
  14938. 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4
  14939. };
  14940. WOLFSSL_SMALL_STACK_STATIC const byte c6[] =
  14941. {
  14942. 0xE6, 0xCF, 0xA3, 0x5F, 0xC0, 0x2B, 0x13, 0x4A,
  14943. 0x4D, 0x2C, 0x0B, 0x67, 0x37, 0xAC, 0x3E, 0xDA
  14944. };
  14945. byte out[CAMELLIA_BLOCK_SIZE];
  14946. Camellia cam;
  14947. WOLFSSL_SMALL_STACK_STATIC const test_vector_t testVectors[] =
  14948. {
  14949. {CAM_ECB_ENC, pte, ive, c1, k1, sizeof(k1), -114},
  14950. {CAM_ECB_ENC, pte, ive, c2, k2, sizeof(k2), -115},
  14951. {CAM_ECB_ENC, pte, ive, c3, k3, sizeof(k3), -116},
  14952. {CAM_ECB_DEC, pte, ive, c1, k1, sizeof(k1), -117},
  14953. {CAM_ECB_DEC, pte, ive, c2, k2, sizeof(k2), -118},
  14954. {CAM_ECB_DEC, pte, ive, c3, k3, sizeof(k3), -119},
  14955. {CAM_CBC_ENC, ptc, ivc, c4, k4, sizeof(k4), -120},
  14956. {CAM_CBC_ENC, ptc, ivc, c5, k5, sizeof(k5), -121},
  14957. {CAM_CBC_ENC, ptc, ivc, c6, k6, sizeof(k6), -122},
  14958. {CAM_CBC_DEC, ptc, ivc, c4, k4, sizeof(k4), -123},
  14959. {CAM_CBC_DEC, ptc, ivc, c5, k5, sizeof(k5), -124},
  14960. {CAM_CBC_DEC, ptc, ivc, c6, k6, sizeof(k6), -125}
  14961. };
  14962. int i, testsSz;
  14963. int ret;
  14964. WOLFSSL_ENTER("camellia_test");
  14965. testsSz = sizeof(testVectors)/sizeof(test_vector_t);
  14966. for (i = 0; i < testsSz; i++) {
  14967. if (wc_CamelliaSetKey(&cam, testVectors[i].key, testVectors[i].keySz,
  14968. testVectors[i].iv) != 0)
  14969. return testVectors[i].errorCode;
  14970. switch (testVectors[i].type) {
  14971. case CAM_ECB_ENC:
  14972. ret = wc_CamelliaEncryptDirect(&cam, out,
  14973. testVectors[i].plaintext);
  14974. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14975. CAMELLIA_BLOCK_SIZE))
  14976. return testVectors[i].errorCode;
  14977. break;
  14978. case CAM_ECB_DEC:
  14979. ret = wc_CamelliaDecryptDirect(&cam, out,
  14980. testVectors[i].ciphertext);
  14981. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14982. CAMELLIA_BLOCK_SIZE))
  14983. return testVectors[i].errorCode;
  14984. break;
  14985. case CAM_CBC_ENC:
  14986. ret = wc_CamelliaCbcEncrypt(&cam, out, testVectors[i].plaintext,
  14987. CAMELLIA_BLOCK_SIZE);
  14988. if (ret != 0 || XMEMCMP(out, testVectors[i].ciphertext,
  14989. CAMELLIA_BLOCK_SIZE))
  14990. return testVectors[i].errorCode;
  14991. break;
  14992. case CAM_CBC_DEC:
  14993. ret = wc_CamelliaCbcDecrypt(&cam, out,
  14994. testVectors[i].ciphertext, CAMELLIA_BLOCK_SIZE);
  14995. if (ret != 0 || XMEMCMP(out, testVectors[i].plaintext,
  14996. CAMELLIA_BLOCK_SIZE))
  14997. return testVectors[i].errorCode;
  14998. break;
  14999. default:
  15000. break;
  15001. }
  15002. }
  15003. /* Setting the IV and checking it was actually set. */
  15004. ret = wc_CamelliaSetIV(&cam, ivc);
  15005. if (ret != 0)
  15006. return WC_TEST_RET_ENC_EC(ret);
  15007. if (XMEMCMP(cam.reg, ivc, CAMELLIA_BLOCK_SIZE) != 0)
  15008. return WC_TEST_RET_ENC_NC;
  15009. /* Setting the IV to NULL should be same as all zeros IV */
  15010. ret = wc_CamelliaSetIV(&cam, NULL);
  15011. if (ret != 0)
  15012. return WC_TEST_RET_ENC_EC(ret);
  15013. if (XMEMCMP(cam.reg, ive, CAMELLIA_BLOCK_SIZE) != 0)
  15014. return WC_TEST_RET_ENC_NC;
  15015. /* First parameter should never be null */
  15016. if (wc_CamelliaSetIV(NULL, NULL) == 0)
  15017. return WC_TEST_RET_ENC_NC;
  15018. /* First parameter should never be null, check it fails */
  15019. if (wc_CamelliaSetKey(NULL, k1, sizeof(k1), NULL) == 0)
  15020. return WC_TEST_RET_ENC_NC;
  15021. /* Key should have a size of 16, 24, or 32 */
  15022. if (wc_CamelliaSetKey(&cam, k1, 0, NULL) == 0)
  15023. return WC_TEST_RET_ENC_NC;
  15024. return 0;
  15025. }
  15026. #endif /* HAVE_CAMELLIA */
  15027. #ifdef WOLFSSL_SM4
  15028. #ifdef WOLFSSL_SM4_ECB
  15029. static int sm4_ecb_test(void)
  15030. {
  15031. /* draft-ribose-cfrg-sm4-10 A.2.1.1 */
  15032. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15033. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15034. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15035. };
  15036. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15037. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15038. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15039. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15040. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15041. };
  15042. WOLFSSL_SMALL_STACK_STATIC const byte c1_ecb[] = {
  15043. 0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
  15044. 0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
  15045. 0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
  15046. 0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04
  15047. };
  15048. wc_Sm4 sm4;
  15049. byte enc[SM4_BLOCK_SIZE * 4];
  15050. byte dec[SM4_BLOCK_SIZE * 4];
  15051. int ret;
  15052. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15053. if (ret != 0)
  15054. return WC_TEST_RET_ENC_EC(ret);
  15055. /* Encrypt and decrypt with ECB. */
  15056. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15057. if (ret != 0)
  15058. return WC_TEST_RET_ENC_EC(ret);
  15059. ret = wc_Sm4EcbEncrypt(&sm4, enc, p1, sizeof(p1));
  15060. if (ret != 0)
  15061. return WC_TEST_RET_ENC_EC(ret);
  15062. if (XMEMCMP(enc, c1_ecb, sizeof(c1_ecb)) != 0)
  15063. return WC_TEST_RET_ENC_NC;
  15064. ret = wc_Sm4EcbDecrypt(&sm4, dec, enc, sizeof(c1_ecb));
  15065. if (ret != 0)
  15066. return WC_TEST_RET_ENC_EC(ret);
  15067. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15068. return WC_TEST_RET_ENC_NC;
  15069. wc_Sm4Free(&sm4);
  15070. return 0;
  15071. }
  15072. #endif
  15073. #ifdef WOLFSSL_SM4_CBC
  15074. static int sm4_cbc_test(void)
  15075. {
  15076. /* draft-ribose-cfrg-sm4-10 A.2.2.1 */
  15077. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15078. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15079. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15080. };
  15081. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15082. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15083. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15084. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15085. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15086. };
  15087. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15088. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15089. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15090. };
  15091. WOLFSSL_SMALL_STACK_STATIC const byte c1_cbc[] = {
  15092. 0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
  15093. 0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
  15094. 0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
  15095. 0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D
  15096. };
  15097. wc_Sm4 sm4;
  15098. byte enc[SM4_BLOCK_SIZE * 4];
  15099. byte dec[SM4_BLOCK_SIZE * 4];
  15100. int ret;
  15101. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15102. if (ret != 0)
  15103. return WC_TEST_RET_ENC_EC(ret);
  15104. /* Encrypt and decrypt with CBC. */
  15105. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15106. if (ret != 0)
  15107. return WC_TEST_RET_ENC_EC(ret);
  15108. ret = wc_Sm4SetIV(&sm4, i1);
  15109. if (ret != 0)
  15110. return WC_TEST_RET_ENC_EC(ret);
  15111. ret = wc_Sm4CbcEncrypt(&sm4, enc, p1, sizeof(p1));
  15112. if (ret != 0)
  15113. return WC_TEST_RET_ENC_EC(ret);
  15114. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15115. return WC_TEST_RET_ENC_NC;
  15116. ret = wc_Sm4SetIV(&sm4, i1);
  15117. if (ret != 0)
  15118. return WC_TEST_RET_ENC_EC(ret);
  15119. ret = wc_Sm4CbcDecrypt(&sm4, dec, enc, sizeof(c1_cbc));
  15120. if (ret != 0)
  15121. return WC_TEST_RET_ENC_EC(ret);
  15122. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15123. return WC_TEST_RET_ENC_NC;
  15124. /* Encrypt and decrypt in-place with CBC. */
  15125. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15126. if (ret != 0)
  15127. return WC_TEST_RET_ENC_EC(ret);
  15128. ret = wc_Sm4SetIV(&sm4, i1);
  15129. if (ret != 0)
  15130. return WC_TEST_RET_ENC_EC(ret);
  15131. XMEMCPY(enc, p1, sizeof(p1));
  15132. ret = wc_Sm4CbcEncrypt(&sm4, enc, enc, sizeof(p1));
  15133. if (ret != 0)
  15134. return WC_TEST_RET_ENC_EC(ret);
  15135. if (XMEMCMP(enc, c1_cbc, sizeof(c1_cbc)) != 0)
  15136. return WC_TEST_RET_ENC_NC;
  15137. ret = wc_Sm4SetIV(&sm4, i1);
  15138. if (ret != 0)
  15139. return WC_TEST_RET_ENC_EC(ret);
  15140. ret = wc_Sm4CbcDecrypt(&sm4, enc, enc, sizeof(c1_cbc));
  15141. if (ret != 0)
  15142. return WC_TEST_RET_ENC_EC(ret);
  15143. if (XMEMCMP(enc, p1, sizeof(p1)) != 0)
  15144. return WC_TEST_RET_ENC_NC;
  15145. wc_Sm4Free(&sm4);
  15146. return 0;
  15147. }
  15148. #endif
  15149. #ifdef WOLFSSL_SM4_CTR
  15150. static int sm4_ctr_test(void)
  15151. {
  15152. /* draft-ribose-cfrg-sm4-10 A.2.5.1 */
  15153. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15154. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15155. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15156. };
  15157. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15158. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15159. 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
  15160. };
  15161. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15162. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15163. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15164. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15165. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15166. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15167. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15168. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15169. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB
  15170. };
  15171. WOLFSSL_SMALL_STACK_STATIC const byte c2_ctr[] = {
  15172. 0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
  15173. 0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
  15174. 0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
  15175. 0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
  15176. 0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
  15177. 0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
  15178. 0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
  15179. 0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14
  15180. };
  15181. wc_Sm4 sm4;
  15182. byte enc[SM4_BLOCK_SIZE * 4];
  15183. byte dec[SM4_BLOCK_SIZE * 4];
  15184. int chunk;
  15185. int i;
  15186. int ret;
  15187. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15188. if (ret != 0)
  15189. return WC_TEST_RET_ENC_EC(ret);
  15190. /* Encrypt and decrypt using encrypt with CTR. */
  15191. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15192. if (ret != 0)
  15193. return WC_TEST_RET_ENC_EC(ret);
  15194. ret = wc_Sm4SetIV(&sm4, i1);
  15195. if (ret != 0)
  15196. return WC_TEST_RET_ENC_EC(ret);
  15197. ret = wc_Sm4CtrEncrypt(&sm4, enc, p2, sizeof(p2));
  15198. if (ret != 0)
  15199. return WC_TEST_RET_ENC_EC(ret);
  15200. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15201. return WC_TEST_RET_ENC_NC;
  15202. ret = wc_Sm4SetIV(&sm4, i1);
  15203. if (ret != 0)
  15204. return WC_TEST_RET_ENC_EC(ret);
  15205. ret = wc_Sm4CtrEncrypt(&sm4, dec, enc, sizeof(c2_ctr));
  15206. if (ret != 0)
  15207. return WC_TEST_RET_ENC_EC(ret);
  15208. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15209. return WC_TEST_RET_ENC_NC;
  15210. for (chunk = 1; chunk <= SM4_BLOCK_SIZE + 1; chunk++) {
  15211. ret = wc_Sm4SetIV(&sm4, i1);
  15212. if (ret != 0)
  15213. return WC_TEST_RET_ENC_I(chunk);
  15214. XMEMSET(enc, 0, sizeof(enc));
  15215. for (i = 0; i + chunk <= (int)sizeof(p2); i += chunk) {
  15216. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, chunk);
  15217. if (ret != 0)
  15218. return WC_TEST_RET_ENC_I(i);
  15219. }
  15220. if (i < (int)sizeof(p2)) {
  15221. ret = wc_Sm4CtrEncrypt(&sm4, enc + i, p2 + i, sizeof(p2) - i);
  15222. if (ret != 0)
  15223. return WC_TEST_RET_ENC_I(chunk);
  15224. }
  15225. if (XMEMCMP(enc, c2_ctr, sizeof(c2_ctr)) != 0)
  15226. return WC_TEST_RET_ENC_I(chunk);
  15227. }
  15228. wc_Sm4Free(&sm4);
  15229. return 0;
  15230. }
  15231. #endif
  15232. #ifdef WOLFSSL_SM4_GCM
  15233. static int sm4_gcm_test(void)
  15234. {
  15235. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15236. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15237. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15238. };
  15239. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15240. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15241. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15242. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15243. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15244. };
  15245. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15246. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15247. 0x08, 0x09, 0x0A, 0x0B
  15248. };
  15249. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15250. 0xFF, 0xEE, 0xDD
  15251. };
  15252. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15253. 0x83, 0xb2, 0x91, 0xcf, 0x22, 0xc9, 0x5f, 0x89,
  15254. 0xde, 0x3d, 0x52, 0x8d, 0xd7, 0x13, 0x50, 0x89
  15255. };
  15256. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15257. 0xff, 0x8b, 0xb2, 0x3b, 0x0a, 0x0a, 0x12, 0xa4,
  15258. 0xa8, 0x4c, 0x4f, 0x67, 0x06, 0x81, 0xbb, 0x88,
  15259. 0x66, 0x17, 0xc7, 0x43, 0xbf, 0xae, 0x41, 0x40,
  15260. 0xec, 0x1e, 0x03, 0x85, 0x2b, 0x56, 0xa8, 0xc0
  15261. };
  15262. /* RFC8998 A.1. */
  15263. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15264. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15265. 0x00, 0x00, 0xAB, 0xCD
  15266. };
  15267. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15268. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15269. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15270. };
  15271. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15272. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15273. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15274. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15275. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15276. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15277. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15278. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15279. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15280. };
  15281. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15282. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15283. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15284. 0xAB, 0xAD, 0xDA, 0xD2
  15285. };
  15286. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15287. 0x17, 0xF3, 0x99, 0xF0, 0x8C, 0x67, 0xD5, 0xEE,
  15288. 0x19, 0xD0, 0xDC, 0x99, 0x69, 0xC4, 0xBB, 0x7D,
  15289. 0x5F, 0xD4, 0x6F, 0xD3, 0x75, 0x64, 0x89, 0x06,
  15290. 0x91, 0x57, 0xB2, 0x82, 0xBB, 0x20, 0x07, 0x35,
  15291. 0xD8, 0x27, 0x10, 0xCA, 0x5C, 0x22, 0xF0, 0xCC,
  15292. 0xFA, 0x7C, 0xBF, 0x93, 0xD4, 0x96, 0xAC, 0x15,
  15293. 0xA5, 0x68, 0x34, 0xCB, 0xCF, 0x98, 0xC3, 0x97,
  15294. 0xB4, 0x02, 0x4A, 0x26, 0x91, 0x23, 0x3B, 0x8D
  15295. };
  15296. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15297. 0x83, 0xDE, 0x35, 0x41, 0xE4, 0xC2, 0xB5, 0x81,
  15298. 0x77, 0xE0, 0x65, 0xA9, 0xBF, 0x7B, 0x62, 0xEC
  15299. };
  15300. wc_Sm4 sm4;
  15301. byte enc[SM4_BLOCK_SIZE * 4];
  15302. byte dec[SM4_BLOCK_SIZE * 4];
  15303. byte tag[SM4_BLOCK_SIZE];
  15304. int ret;
  15305. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15306. if (ret != 0)
  15307. return WC_TEST_RET_ENC_EC(ret);
  15308. /* Encrypt and decrypt using encrypt with GCM. */
  15309. ret = wc_Sm4GcmSetKey(&sm4, k1, sizeof(k1));
  15310. if (ret != 0)
  15311. return WC_TEST_RET_ENC_EC(ret);
  15312. ret = wc_Sm4GcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15313. sizeof(tag), a1, sizeof(a1));
  15314. if (ret != 0)
  15315. return WC_TEST_RET_ENC_EC(ret);
  15316. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15317. return WC_TEST_RET_ENC_NC;
  15318. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15319. return WC_TEST_RET_ENC_NC;
  15320. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15321. sizeof(tag), a1, sizeof(a1));
  15322. if (ret != 0)
  15323. return WC_TEST_RET_ENC_EC(ret);
  15324. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15325. return WC_TEST_RET_ENC_NC;
  15326. /* RFC8998 test vector. */
  15327. ret = wc_Sm4GcmSetKey(&sm4, k2, sizeof(k2));
  15328. if (ret != 0)
  15329. return WC_TEST_RET_ENC_EC(ret);
  15330. ret = wc_Sm4GcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15331. sizeof(tag), a2, sizeof(a2));
  15332. if (ret != 0)
  15333. return WC_TEST_RET_ENC_EC(ret);
  15334. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15335. return WC_TEST_RET_ENC_NC;
  15336. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15337. return WC_TEST_RET_ENC_NC;
  15338. ret = wc_Sm4GcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15339. sizeof(tag), a2, sizeof(a2));
  15340. if (ret != 0)
  15341. return WC_TEST_RET_ENC_EC(ret);
  15342. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15343. return WC_TEST_RET_ENC_NC;
  15344. wc_Sm4Free(&sm4);
  15345. return 0;
  15346. }
  15347. #endif
  15348. #ifdef WOLFSSL_SM4_CCM
  15349. static int sm4_ccm_test(void)
  15350. {
  15351. WOLFSSL_SMALL_STACK_STATIC const byte k1[] = {
  15352. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15353. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15354. };
  15355. WOLFSSL_SMALL_STACK_STATIC const byte p1[] = {
  15356. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
  15357. 0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD,
  15358. 0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
  15359. 0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB
  15360. };
  15361. WOLFSSL_SMALL_STACK_STATIC const byte i1[] = {
  15362. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  15363. 0x08, 0x09, 0x0A, 0x0B
  15364. };
  15365. WOLFSSL_SMALL_STACK_STATIC const byte a1[] = {
  15366. 0xFF, 0xEE, 0xDD
  15367. };
  15368. WOLFSSL_SMALL_STACK_STATIC const byte tag1[] = {
  15369. 0x9a, 0x98, 0x04, 0xb6, 0x0f, 0x19, 0x4a, 0x46,
  15370. 0xba, 0xed, 0xe6, 0x89, 0x69, 0x34, 0xad, 0x61
  15371. };
  15372. WOLFSSL_SMALL_STACK_STATIC const byte c1[] = {
  15373. 0xbd, 0xc0, 0x72, 0x60, 0xda, 0x2d, 0x11, 0xdc,
  15374. 0x66, 0x33, 0xcc, 0xec, 0xb2, 0xf4, 0x53, 0x59,
  15375. 0x9e, 0xb1, 0xb3, 0x6b, 0x1f, 0x1c, 0xfb, 0x29,
  15376. 0xf5, 0x37, 0xfc, 0x00, 0xf2, 0x4e, 0x70, 0x6f
  15377. };
  15378. /* RFC8998 A.1. */
  15379. WOLFSSL_SMALL_STACK_STATIC const byte i2[] = {
  15380. 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00,
  15381. 0x00, 0x00, 0xAB, 0xCD
  15382. };
  15383. WOLFSSL_SMALL_STACK_STATIC const byte k2[] = {
  15384. 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
  15385. 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10
  15386. };
  15387. WOLFSSL_SMALL_STACK_STATIC const byte p2[] = {
  15388. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
  15389. 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
  15390. 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC,
  15391. 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
  15392. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15393. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  15394. 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
  15395. 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA
  15396. };
  15397. WOLFSSL_SMALL_STACK_STATIC const byte a2[] = {
  15398. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15399. 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF,
  15400. 0xAB, 0xAD, 0xDA, 0xD2
  15401. };
  15402. WOLFSSL_SMALL_STACK_STATIC const byte c2[] = {
  15403. 0x48, 0xAF, 0x93, 0x50, 0x1F, 0xA6, 0x2A, 0xDB,
  15404. 0xCD, 0x41, 0x4C, 0xCE, 0x60, 0x34, 0xD8, 0x95,
  15405. 0xDD, 0xA1, 0xBF, 0x8F, 0x13, 0x2F, 0x04, 0x20,
  15406. 0x98, 0x66, 0x15, 0x72, 0xE7, 0x48, 0x30, 0x94,
  15407. 0xFD, 0x12, 0xE5, 0x18, 0xCE, 0x06, 0x2C, 0x98,
  15408. 0xAC, 0xEE, 0x28, 0xD9, 0x5D, 0xF4, 0x41, 0x6B,
  15409. 0xED, 0x31, 0xA2, 0xF0, 0x44, 0x76, 0xC1, 0x8B,
  15410. 0xB4, 0x0C, 0x84, 0xA7, 0x4B, 0x97, 0xDC, 0x5B
  15411. };
  15412. WOLFSSL_SMALL_STACK_STATIC const byte tag2[] = {
  15413. 0x16, 0x84, 0x2D, 0x4F, 0xA1, 0x86, 0xF5, 0x6A,
  15414. 0xB3, 0x32, 0x56, 0x97, 0x1F, 0xA1, 0x10, 0xF4
  15415. };
  15416. wc_Sm4 sm4;
  15417. byte enc[SM4_BLOCK_SIZE * 4];
  15418. byte dec[SM4_BLOCK_SIZE * 4];
  15419. byte tag[SM4_BLOCK_SIZE];
  15420. int ret;
  15421. ret = wc_Sm4Init(&sm4, NULL, INVALID_DEVID);
  15422. if (ret != 0)
  15423. return WC_TEST_RET_ENC_EC(ret);
  15424. /* Encrypt and decrypt using encrypt with CCM. */
  15425. ret = wc_Sm4SetKey(&sm4, k1, sizeof(k1));
  15426. if (ret != 0)
  15427. return WC_TEST_RET_ENC_EC(ret);
  15428. ret = wc_Sm4CcmEncrypt(&sm4, enc, p1, sizeof(p1), i1, sizeof(i1), tag,
  15429. sizeof(tag), a1, sizeof(a1));
  15430. if (ret != 0)
  15431. return WC_TEST_RET_ENC_EC(ret);
  15432. if (XMEMCMP(enc, c1, sizeof(c1)) != 0)
  15433. return WC_TEST_RET_ENC_NC;
  15434. if (XMEMCMP(tag, tag1, sizeof(tag1)) != 0)
  15435. return WC_TEST_RET_ENC_NC;
  15436. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c1), i1, sizeof(i1), tag,
  15437. sizeof(tag), a1, sizeof(a1));
  15438. if (ret != 0)
  15439. return WC_TEST_RET_ENC_EC(ret);
  15440. if (XMEMCMP(dec, p1, sizeof(p1)) != 0)
  15441. return WC_TEST_RET_ENC_NC;
  15442. /* RFC8998 test vector. */
  15443. ret = wc_Sm4SetKey(&sm4, k2, sizeof(k2));
  15444. if (ret != 0)
  15445. return WC_TEST_RET_ENC_EC(ret);
  15446. ret = wc_Sm4CcmEncrypt(&sm4, enc, p2, sizeof(p2), i2, sizeof(i2), tag,
  15447. sizeof(tag), a2, sizeof(a2));
  15448. if (ret != 0)
  15449. return WC_TEST_RET_ENC_EC(ret);
  15450. if (XMEMCMP(enc, c2, sizeof(c2)) != 0)
  15451. return WC_TEST_RET_ENC_NC;
  15452. if (XMEMCMP(tag, tag2, sizeof(tag2)) != 0)
  15453. return WC_TEST_RET_ENC_NC;
  15454. ret = wc_Sm4CcmDecrypt(&sm4, dec, enc, sizeof(c2), i2, sizeof(i2), tag,
  15455. sizeof(tag), a2, sizeof(a2));
  15456. if (ret != 0)
  15457. return WC_TEST_RET_ENC_EC(ret);
  15458. if (XMEMCMP(dec, p2, sizeof(p2)) != 0)
  15459. return WC_TEST_RET_ENC_NC;
  15460. wc_Sm4Free(&sm4);
  15461. return 0;
  15462. }
  15463. #endif
  15464. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sm4_test(void)
  15465. {
  15466. wc_test_ret_t ret;
  15467. WOLFSSL_ENTER("sm4_test");
  15468. #ifdef WOLFSSL_SM4_ECB
  15469. ret = sm4_ecb_test();
  15470. if (ret != 0)
  15471. return ret;
  15472. #endif
  15473. #ifdef WOLFSSL_SM4_CBC
  15474. ret = sm4_cbc_test();
  15475. if (ret != 0)
  15476. return ret;
  15477. #endif
  15478. #ifdef WOLFSSL_SM4_CTR
  15479. ret = sm4_ctr_test();
  15480. if (ret != 0)
  15481. return ret;
  15482. #endif
  15483. #ifdef WOLFSSL_SM4_GCM
  15484. ret = sm4_gcm_test();
  15485. if (ret != 0)
  15486. return ret;
  15487. #endif
  15488. #ifdef WOLFSSL_SM4_CCM
  15489. ret = sm4_ccm_test();
  15490. if (ret != 0)
  15491. return ret;
  15492. #endif
  15493. return 0;
  15494. }
  15495. #endif
  15496. #ifdef HAVE_XCHACHA
  15497. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha_test(void) {
  15498. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15499. 0x54, 0x68, 0x65, 0x20, 0x64, 0x68, 0x6f, 0x6c, 0x65, 0x20, 0x28, 0x70, 0x72, 0x6f, 0x6e, 0x6f, /* The dhole (prono */
  15500. 0x75, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x22, 0x64, 0x6f, 0x6c, 0x65, 0x22, 0x29, 0x20, 0x69, 0x73, /* unced "dole") is */
  15501. 0x20, 0x61, 0x6c, 0x73, 0x6f, 0x20, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x61, 0x73, 0x20, 0x74, /* also known as t */
  15502. 0x68, 0x65, 0x20, 0x41, 0x73, 0x69, 0x61, 0x74, 0x69, 0x63, 0x20, 0x77, 0x69, 0x6c, 0x64, 0x20, /* he Asiatic wild */
  15503. 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x72, 0x65, 0x64, 0x20, 0x64, 0x6f, 0x67, 0x2c, 0x20, 0x61, 0x6e, /* dog, red dog, an */
  15504. 0x64, 0x20, 0x77, 0x68, 0x69, 0x73, 0x74, 0x6c, 0x69, 0x6e, 0x67, 0x20, 0x64, 0x6f, 0x67, 0x2e, /* d whistling dog. */
  15505. 0x20, 0x49, 0x74, 0x20, 0x69, 0x73, 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x74, 0x68, 0x65, /* It is about the */
  15506. 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x61, 0x20, 0x47, 0x65, 0x72, 0x6d, 0x61, /* size of a Germa */
  15507. 0x6e, 0x20, 0x73, 0x68, 0x65, 0x70, 0x68, 0x65, 0x72, 0x64, 0x20, 0x62, 0x75, 0x74, 0x20, 0x6c, /* n shepherd but l */
  15508. 0x6f, 0x6f, 0x6b, 0x73, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x6c, 0x69, 0x6b, 0x65, 0x20, 0x61, /* ooks more like a */
  15509. 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x67, 0x67, 0x65, 0x64, 0x20, 0x66, 0x6f, 0x78, /* long-legged fox */
  15510. 0x2e, 0x20, 0x54, 0x68, 0x69, 0x73, 0x20, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x79, 0x20, 0x65, 0x6c, /* . This highly el */
  15511. 0x75, 0x73, 0x69, 0x76, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x73, 0x6b, 0x69, 0x6c, 0x6c, 0x65, /* usive and skille */
  15512. 0x64, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x63, 0x6c, 0x61, 0x73, /* d jumper is clas */
  15513. 0x73, 0x69, 0x66, 0x69, 0x65, 0x64, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x77, 0x6f, 0x6c, 0x76, /* sified with wolv */
  15514. 0x65, 0x73, 0x2c, 0x20, 0x63, 0x6f, 0x79, 0x6f, 0x74, 0x65, 0x73, 0x2c, 0x20, 0x6a, 0x61, 0x63, /* es, coyotes, jac */
  15515. 0x6b, 0x61, 0x6c, 0x73, 0x2c, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x66, 0x6f, 0x78, 0x65, 0x73, 0x20, /* kals, and foxes */
  15516. 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, 0x61, 0x78, 0x6f, 0x6e, 0x6f, 0x6d, 0x69, 0x63, /* in the taxonomic */
  15517. 0x20, 0x66, 0x61, 0x6d, 0x69, 0x6c, 0x79, 0x20, 0x43, 0x61, 0x6e, 0x69, 0x64, 0x61, 0x65, 0x2e /* family Canidae. */
  15518. };
  15519. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15520. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15521. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15522. };
  15523. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15524. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15525. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x58 }; /* PQRSTUVW */
  15526. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15527. 0x45, 0x59, 0xab, 0xba, 0x4e, 0x48, 0xc1, 0x61, 0x02, 0xe8, 0xbb, 0x2c, 0x05, 0xe6, 0x94, 0x7f,
  15528. 0x50, 0xa7, 0x86, 0xde, 0x16, 0x2f, 0x9b, 0x0b, 0x7e, 0x59, 0x2a, 0x9b, 0x53, 0xd0, 0xd4, 0xe9,
  15529. 0x8d, 0x8d, 0x64, 0x10, 0xd5, 0x40, 0xa1, 0xa6, 0x37, 0x5b, 0x26, 0xd8, 0x0d, 0xac, 0xe4, 0xfa,
  15530. 0xb5, 0x23, 0x84, 0xc7, 0x31, 0xac, 0xbf, 0x16, 0xa5, 0x92, 0x3c, 0x0c, 0x48, 0xd3, 0x57, 0x5d,
  15531. 0x4d, 0x0d, 0x2c, 0x67, 0x3b, 0x66, 0x6f, 0xaa, 0x73, 0x10, 0x61, 0x27, 0x77, 0x01, 0x09, 0x3a,
  15532. 0x6b, 0xf7, 0xa1, 0x58, 0xa8, 0x86, 0x42, 0x92, 0xa4, 0x1c, 0x48, 0xe3, 0xa9, 0xb4, 0xc0, 0xda,
  15533. 0xec, 0xe0, 0xf8, 0xd9, 0x8d, 0x0d, 0x7e, 0x05, 0xb3, 0x7a, 0x30, 0x7b, 0xbb, 0x66, 0x33, 0x31,
  15534. 0x64, 0xec, 0x9e, 0x1b, 0x24, 0xea, 0x0d, 0x6c, 0x3f, 0xfd, 0xdc, 0xec, 0x4f, 0x68, 0xe7, 0x44,
  15535. 0x30, 0x56, 0x19, 0x3a, 0x03, 0xc8, 0x10, 0xe1, 0x13, 0x44, 0xca, 0x06, 0xd8, 0xed, 0x8a, 0x2b,
  15536. 0xfb, 0x1e, 0x8d, 0x48, 0xcf, 0xa6, 0xbc, 0x0e, 0xb4, 0xe2, 0x46, 0x4b, 0x74, 0x81, 0x42, 0x40,
  15537. 0x7c, 0x9f, 0x43, 0x1a, 0xee, 0x76, 0x99, 0x60, 0xe1, 0x5b, 0xa8, 0xb9, 0x68, 0x90, 0x46, 0x6e,
  15538. 0xf2, 0x45, 0x75, 0x99, 0x85, 0x23, 0x85, 0xc6, 0x61, 0xf7, 0x52, 0xce, 0x20, 0xf9, 0xda, 0x0c,
  15539. 0x09, 0xab, 0x6b, 0x19, 0xdf, 0x74, 0xe7, 0x6a, 0x95, 0x96, 0x74, 0x46, 0xf8, 0xd0, 0xfd, 0x41,
  15540. 0x5e, 0x7b, 0xee, 0x2a, 0x12, 0xa1, 0x14, 0xc2, 0x0e, 0xb5, 0x29, 0x2a, 0xe7, 0xa3, 0x49, 0xae,
  15541. 0x57, 0x78, 0x20, 0xd5, 0x52, 0x0a, 0x1f, 0x3f, 0xb6, 0x2a, 0x17, 0xce, 0x6a, 0x7e, 0x68, 0xfa,
  15542. 0x7c, 0x79, 0x11, 0x1d, 0x88, 0x60, 0x92, 0x0b, 0xc0, 0x48, 0xef, 0x43, 0xfe, 0x84, 0x48, 0x6c,
  15543. 0xcb, 0x87, 0xc2, 0x5f, 0x0a, 0xe0, 0x45, 0xf0, 0xcc, 0xe1, 0xe7, 0x98, 0x9a, 0x9a, 0xa2, 0x20,
  15544. 0xa2, 0x8b, 0xdd, 0x48, 0x27, 0xe7, 0x51, 0xa2, 0x4a, 0x6d, 0x5c, 0x62, 0xd7, 0x90, 0xa6, 0x63,
  15545. 0x93, 0xb9, 0x31, 0x11, 0xc1, 0xa5, 0x5d, 0xd7, 0x42, 0x1a, 0x10, 0x18, 0x49, 0x74, 0xc7, 0xc5
  15546. };
  15547. wc_test_ret_t ret;
  15548. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15549. struct ChaCha *chacha = (struct ChaCha *)XMALLOC(sizeof *chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15550. byte *buf1 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15551. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15552. WOLFSSL_ENTER("XChaCha_test");
  15553. if ((chacha == NULL) || (buf1 == NULL) || (buf2 == NULL))
  15554. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15555. #else
  15556. struct ChaCha chacha[1];
  15557. byte buf1[sizeof Plaintext];
  15558. byte buf2[sizeof Plaintext];
  15559. WOLFSSL_ENTER("XChaCha_test");
  15560. #endif
  15561. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15562. if (ret < 0)
  15563. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15564. ret = wc_Chacha_Process(chacha, buf1, Plaintext, sizeof Plaintext);
  15565. if (ret < 0)
  15566. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15567. if (XMEMCMP(buf1, Ciphertext, sizeof Plaintext))
  15568. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15569. ret = wc_XChacha_SetKey(chacha, Key, sizeof Key, IV, sizeof IV, 0);
  15570. if (ret < 0)
  15571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15572. ret = wc_Chacha_Process(chacha, buf2, buf1, sizeof Plaintext);
  15573. if (ret < 0)
  15574. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15575. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15576. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15577. out:
  15578. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15579. XFREE(chacha, HEAP_HINT, DYNAMIC_TYPE_CIPHER);
  15580. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15581. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15582. #endif
  15583. return ret;
  15584. }
  15585. #endif /* HAVE_XCHACHA */
  15586. #if defined(HAVE_XCHACHA) && defined(HAVE_POLY1305)
  15587. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t XChaCha20Poly1305_test(void) {
  15588. WOLFSSL_SMALL_STACK_STATIC const byte Plaintext[] = {
  15589. 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, /* Ladies and Gentl */
  15590. 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, /* emen of the clas */
  15591. 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, /* s of '99: If I c */
  15592. 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, /* ould offer you o */
  15593. 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, /* nly one tip for */
  15594. 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, /* the future, suns */
  15595. 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, /* creen would be i */
  15596. 0x74, 0x2e }; /* t. */
  15597. WOLFSSL_SMALL_STACK_STATIC const byte AAD[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; /* PQRS........ */
  15598. WOLFSSL_SMALL_STACK_STATIC const byte Key[] = {
  15599. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  15600. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f
  15601. };
  15602. WOLFSSL_SMALL_STACK_STATIC const byte IV[] = {
  15603. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, /* @ABCDEFGHIJKLMNO */
  15604. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 }; /* PQRSTUVW */
  15605. WOLFSSL_SMALL_STACK_STATIC const byte Ciphertext[] = {
  15606. 0xbd, 0x6d, 0x17, 0x9d, 0x3e, 0x83, 0xd4, 0x3b, 0x95, 0x76, 0x57, 0x94, 0x93, 0xc0, 0xe9, 0x39,
  15607. 0x57, 0x2a, 0x17, 0x00, 0x25, 0x2b, 0xfa, 0xcc, 0xbe, 0xd2, 0x90, 0x2c, 0x21, 0x39, 0x6c, 0xbb,
  15608. 0x73, 0x1c, 0x7f, 0x1b, 0x0b, 0x4a, 0xa6, 0x44, 0x0b, 0xf3, 0xa8, 0x2f, 0x4e, 0xda, 0x7e, 0x39,
  15609. 0xae, 0x64, 0xc6, 0x70, 0x8c, 0x54, 0xc2, 0x16, 0xcb, 0x96, 0xb7, 0x2e, 0x12, 0x13, 0xb4, 0x52,
  15610. 0x2f, 0x8c, 0x9b, 0xa4, 0x0d, 0xb5, 0xd9, 0x45, 0xb1, 0x1b, 0x69, 0xb9, 0x82, 0xc1, 0xbb, 0x9e,
  15611. 0x3f, 0x3f, 0xac, 0x2b, 0xc3, 0x69, 0x48, 0x8f, 0x76, 0xb2, 0x38, 0x35, 0x65, 0xd3, 0xff, 0xf9,
  15612. 0x21, 0xf9, 0x66, 0x4c, 0x97, 0x63, 0x7d, 0xa9, 0x76, 0x88, 0x12, 0xf6, 0x15, 0xc6, 0x8b, 0x13,
  15613. 0xb5, 0x2e };
  15614. WOLFSSL_SMALL_STACK_STATIC const byte Tag[] = {
  15615. 0xc0, 0x87, 0x59, 0x24, 0xc1, 0xc7, 0x98, 0x79, 0x47, 0xde, 0xaf, 0xd8, 0x78, 0x0a, 0xcf, 0x49
  15616. };
  15617. wc_test_ret_t ret;
  15618. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15619. byte *buf1 = (byte *)XMALLOC(sizeof Ciphertext + sizeof Tag, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15620. byte *buf2 = (byte *)XMALLOC(sizeof Plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15621. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15622. if ((buf1 == NULL) || (buf2 == NULL))
  15623. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15624. #else
  15625. byte buf1[sizeof Ciphertext + sizeof Tag];
  15626. byte buf2[sizeof Plaintext];
  15627. WOLFSSL_ENTER("XChaCha20Poly1305_test");
  15628. #endif
  15629. ret = wc_XChaCha20Poly1305_Encrypt(buf1, sizeof Ciphertext + sizeof Tag,
  15630. Plaintext, sizeof Plaintext,
  15631. AAD, sizeof AAD,
  15632. IV, sizeof IV,
  15633. Key, sizeof Key);
  15634. if (ret < 0)
  15635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15636. if (XMEMCMP(buf1, Ciphertext, sizeof Ciphertext))
  15637. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15638. if (XMEMCMP(buf1 + sizeof Ciphertext, Tag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE))
  15639. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15640. ret = wc_XChaCha20Poly1305_Decrypt(buf2, sizeof Plaintext,
  15641. buf1, sizeof Ciphertext + sizeof Tag,
  15642. AAD, sizeof AAD,
  15643. IV, sizeof IV,
  15644. Key, sizeof Key);
  15645. if (ret < 0)
  15646. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15647. if (XMEMCMP(buf2, Plaintext, sizeof Plaintext))
  15648. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15649. out:
  15650. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  15651. XFREE(buf1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15652. XFREE(buf2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15653. #endif
  15654. return ret;
  15655. }
  15656. #endif /* defined(HAVE_XCHACHA) && defined(HAVE_POLY1305) */
  15657. #ifndef WC_NO_RNG
  15658. static wc_test_ret_t _rng_test(WC_RNG* rng)
  15659. {
  15660. byte block[32];
  15661. wc_test_ret_t ret;
  15662. int i;
  15663. XMEMSET(block, 0, sizeof(block));
  15664. ret = wc_RNG_GenerateBlock(rng, block, sizeof(block));
  15665. if (ret != 0) {
  15666. return WC_TEST_RET_ENC_EC(ret);
  15667. }
  15668. /* Check for 0's */
  15669. for (i=0; i<(int)sizeof(block); i++) {
  15670. if (block[i] == 0) {
  15671. ret++;
  15672. }
  15673. }
  15674. /* All zeros count check */
  15675. if (ret >= (int)sizeof(block)) {
  15676. return WC_TEST_RET_ENC_NC;
  15677. }
  15678. ret = wc_RNG_GenerateByte(rng, block);
  15679. if (ret != 0) {
  15680. return WC_TEST_RET_ENC_EC(ret);
  15681. }
  15682. /* Parameter validation testing. */
  15683. ret = wc_RNG_GenerateBlock(NULL, block, sizeof(block));
  15684. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15685. return WC_TEST_RET_ENC_EC(ret);
  15686. }
  15687. ret = wc_RNG_GenerateBlock(rng, NULL, sizeof(block));
  15688. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15689. return WC_TEST_RET_ENC_EC(ret);
  15690. }
  15691. ret = wc_RNG_GenerateByte(NULL, block);
  15692. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15693. return WC_TEST_RET_ENC_EC(ret);
  15694. }
  15695. ret = wc_RNG_GenerateByte(rng, NULL);
  15696. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  15697. return WC_TEST_RET_ENC_EC(ret);
  15698. }
  15699. return 0;
  15700. }
  15701. static wc_test_ret_t random_rng_test(void)
  15702. {
  15703. WC_RNG localRng;
  15704. WC_RNG* rng;
  15705. wc_test_ret_t ret;
  15706. rng = &localRng;
  15707. /* Test stack based RNG. */
  15708. #ifndef HAVE_FIPS
  15709. ret = wc_InitRng_ex(rng, HEAP_HINT, devId);
  15710. #else
  15711. ret = wc_InitRng(rng);
  15712. #endif
  15713. if (ret != 0)
  15714. return WC_TEST_RET_ENC_EC(ret);
  15715. ret = _rng_test(rng);
  15716. /* Make sure and free RNG */
  15717. wc_FreeRng(rng);
  15718. if (ret != 0)
  15719. return ret;
  15720. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC)
  15721. {
  15722. byte nonce[8] = { 0 };
  15723. /* Test dynamic RNG */
  15724. rng = wc_rng_new(nonce, (word32)sizeof(nonce), HEAP_HINT);
  15725. if (rng == NULL)
  15726. return WC_TEST_RET_ENC_ERRNO;
  15727. ret = _rng_test(rng);
  15728. wc_rng_free(rng);
  15729. rng = NULL;
  15730. if (ret != 0)
  15731. return ret;
  15732. /* Test dynamic RNG using extended API */
  15733. ret = wc_rng_new_ex(&rng, nonce, (word32)sizeof(nonce),
  15734. HEAP_HINT, devId);
  15735. if (ret != 0)
  15736. return WC_TEST_RET_ENC_EC(ret);
  15737. ret = _rng_test(rng);
  15738. wc_rng_free(rng);
  15739. if (ret != 0)
  15740. return ret;
  15741. }
  15742. #endif
  15743. return ret;
  15744. }
  15745. #if defined(HAVE_HASHDRBG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  15746. #ifdef WC_RNG_SEED_CB
  15747. static int seed_cb(OS_Seed* os, byte* output, word32 sz)
  15748. {
  15749. word32 i;
  15750. (void)os;
  15751. /* Known answer test. Set the seed to the same value every time. */
  15752. for (i = 0; i < sz; i++)
  15753. output[i] = (byte)i;
  15754. return 0;
  15755. }
  15756. static wc_test_ret_t rng_seed_test(void)
  15757. {
  15758. #ifndef HAVE_FIPS
  15759. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15760. {
  15761. 0x83, 0x46, 0x65, 0x2f, 0x5c, 0x44, 0x16, 0x5f,
  15762. 0xb3, 0x89, 0x26, 0xde, 0x0b, 0x6b, 0xa2, 0x06,
  15763. 0x7e, 0xa7, 0x9a, 0x55, 0x22, 0x01, 0xb0, 0x22,
  15764. 0xf4, 0x7e, 0xa2, 0x66, 0xc4, 0x08, 0x6f, 0xba
  15765. };
  15766. #else
  15767. /* FIPS uses a longer seed, so different check value. */
  15768. WOLFSSL_SMALL_STACK_STATIC const byte check[] =
  15769. {
  15770. 0xaf, 0x31, 0xcc, 0xef, 0xa9, 0x29, 0x4c, 0x24,
  15771. 0xbd, 0xa5, 0xa3, 0x52, 0x69, 0xf3, 0xb9, 0xb2,
  15772. 0x1e, 0xd4, 0x52, 0x3b, 0x9a, 0x96, 0x06, 0x20,
  15773. 0xc0, 0x5f, 0x44, 0x06, 0x1f, 0x80, 0xdf, 0xe0
  15774. };
  15775. #endif
  15776. byte output[WC_SHA256_DIGEST_SIZE];
  15777. WC_RNG rng;
  15778. wc_test_ret_t ret;
  15779. ret = wc_SetSeed_Cb(seed_cb);
  15780. if (ret != 0) {
  15781. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15782. }
  15783. ret = wc_InitRng(&rng);
  15784. if (ret != 0) {
  15785. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15786. }
  15787. ret = wc_RNG_GenerateBlock(&rng, output, sizeof(output));
  15788. if (ret != 0) {
  15789. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15790. }
  15791. ret = XMEMCMP(output, check, sizeof(output));
  15792. if (ret != 0) {
  15793. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  15794. }
  15795. ret = wc_FreeRng(&rng);
  15796. if (ret != 0) {
  15797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15798. }
  15799. ret = wc_SetSeed_Cb(wc_GenerateSeed);
  15800. if (ret != 0) {
  15801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  15802. }
  15803. out:
  15804. return ret;
  15805. }
  15806. #endif
  15807. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15808. {
  15809. WOLFSSL_SMALL_STACK_STATIC const byte test1Entropy[] =
  15810. {
  15811. 0xa6, 0x5a, 0xd0, 0xf3, 0x45, 0xdb, 0x4e, 0x0e, 0xff, 0xe8, 0x75, 0xc3,
  15812. 0xa2, 0xe7, 0x1f, 0x42, 0xc7, 0x12, 0x9d, 0x62, 0x0f, 0xf5, 0xc1, 0x19,
  15813. 0xa9, 0xef, 0x55, 0xf0, 0x51, 0x85, 0xe0, 0xfb, 0x85, 0x81, 0xf9, 0x31,
  15814. 0x75, 0x17, 0x27, 0x6e, 0x06, 0xe9, 0x60, 0x7d, 0xdb, 0xcb, 0xcc, 0x2e
  15815. };
  15816. WOLFSSL_SMALL_STACK_STATIC const byte test1Output[] =
  15817. {
  15818. 0xd3, 0xe1, 0x60, 0xc3, 0x5b, 0x99, 0xf3, 0x40, 0xb2, 0x62, 0x82, 0x64,
  15819. 0xd1, 0x75, 0x10, 0x60, 0xe0, 0x04, 0x5d, 0xa3, 0x83, 0xff, 0x57, 0xa5,
  15820. 0x7d, 0x73, 0xa6, 0x73, 0xd2, 0xb8, 0xd8, 0x0d, 0xaa, 0xf6, 0xa6, 0xc3,
  15821. 0x5a, 0x91, 0xbb, 0x45, 0x79, 0xd7, 0x3f, 0xd0, 0xc8, 0xfe, 0xd1, 0x11,
  15822. 0xb0, 0x39, 0x13, 0x06, 0x82, 0x8a, 0xdf, 0xed, 0x52, 0x8f, 0x01, 0x81,
  15823. 0x21, 0xb3, 0xfe, 0xbd, 0xc3, 0x43, 0xe7, 0x97, 0xb8, 0x7d, 0xbb, 0x63,
  15824. 0xdb, 0x13, 0x33, 0xde, 0xd9, 0xd1, 0xec, 0xe1, 0x77, 0xcf, 0xa6, 0xb7,
  15825. 0x1f, 0xe8, 0xab, 0x1d, 0xa4, 0x66, 0x24, 0xed, 0x64, 0x15, 0xe5, 0x1c,
  15826. 0xcd, 0xe2, 0xc7, 0xca, 0x86, 0xe2, 0x83, 0x99, 0x0e, 0xea, 0xeb, 0x91,
  15827. 0x12, 0x04, 0x15, 0x52, 0x8b, 0x22, 0x95, 0x91, 0x02, 0x81, 0xb0, 0x2d,
  15828. 0xd4, 0x31, 0xf4, 0xc9, 0xf7, 0x04, 0x27, 0xdf
  15829. };
  15830. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyA[] =
  15831. {
  15832. 0x63, 0x36, 0x33, 0x77, 0xe4, 0x1e, 0x86, 0x46, 0x8d, 0xeb, 0x0a, 0xb4,
  15833. 0xa8, 0xed, 0x68, 0x3f, 0x6a, 0x13, 0x4e, 0x47, 0xe0, 0x14, 0xc7, 0x00,
  15834. 0x45, 0x4e, 0x81, 0xe9, 0x53, 0x58, 0xa5, 0x69, 0x80, 0x8a, 0xa3, 0x8f,
  15835. 0x2a, 0x72, 0xa6, 0x23, 0x59, 0x91, 0x5a, 0x9f, 0x8a, 0x04, 0xca, 0x68
  15836. };
  15837. WOLFSSL_SMALL_STACK_STATIC const byte test2EntropyB[] =
  15838. {
  15839. 0xe6, 0x2b, 0x8a, 0x8e, 0xe8, 0xf1, 0x41, 0xb6, 0x98, 0x05, 0x66, 0xe3,
  15840. 0xbf, 0xe3, 0xc0, 0x49, 0x03, 0xda, 0xd4, 0xac, 0x2c, 0xdf, 0x9f, 0x22,
  15841. 0x80, 0x01, 0x0a, 0x67, 0x39, 0xbc, 0x83, 0xd3
  15842. };
  15843. WOLFSSL_SMALL_STACK_STATIC const byte test2Output[] =
  15844. {
  15845. 0x04, 0xee, 0xc6, 0x3b, 0xb2, 0x31, 0xdf, 0x2c, 0x63, 0x0a, 0x1a, 0xfb,
  15846. 0xe7, 0x24, 0x94, 0x9d, 0x00, 0x5a, 0x58, 0x78, 0x51, 0xe1, 0xaa, 0x79,
  15847. 0x5e, 0x47, 0x73, 0x47, 0xc8, 0xb0, 0x56, 0x62, 0x1c, 0x18, 0xbd, 0xdc,
  15848. 0xdd, 0x8d, 0x99, 0xfc, 0x5f, 0xc2, 0xb9, 0x20, 0x53, 0xd8, 0xcf, 0xac,
  15849. 0xfb, 0x0b, 0xb8, 0x83, 0x12, 0x05, 0xfa, 0xd1, 0xdd, 0xd6, 0xc0, 0x71,
  15850. 0x31, 0x8a, 0x60, 0x18, 0xf0, 0x3b, 0x73, 0xf5, 0xed, 0xe4, 0xd4, 0xd0,
  15851. 0x71, 0xf9, 0xde, 0x03, 0xfd, 0x7a, 0xea, 0x10, 0x5d, 0x92, 0x99, 0xb8,
  15852. 0xaf, 0x99, 0xaa, 0x07, 0x5b, 0xdb, 0x4d, 0xb9, 0xaa, 0x28, 0xc1, 0x8d,
  15853. 0x17, 0x4b, 0x56, 0xee, 0x2a, 0x01, 0x4d, 0x09, 0x88, 0x96, 0xff, 0x22,
  15854. 0x82, 0xc9, 0x55, 0xa8, 0x19, 0x69, 0xe0, 0x69, 0xfa, 0x8c, 0xe0, 0x07,
  15855. 0xa1, 0x80, 0x18, 0x3a, 0x07, 0xdf, 0xae, 0x17
  15856. };
  15857. byte output[WC_SHA256_DIGEST_SIZE * 4];
  15858. wc_test_ret_t ret;
  15859. WOLFSSL_ENTER("random_test");
  15860. ret = wc_RNG_HealthTest(0, test1Entropy, sizeof(test1Entropy), NULL, 0,
  15861. output, sizeof(output));
  15862. if (ret != 0)
  15863. return WC_TEST_RET_ENC_EC(ret);
  15864. if (XMEMCMP(test1Output, output, sizeof(output)) != 0)
  15865. return WC_TEST_RET_ENC_NC;
  15866. ret = wc_RNG_HealthTest(1, test2EntropyA, sizeof(test2EntropyA),
  15867. test2EntropyB, sizeof(test2EntropyB),
  15868. output, sizeof(output));
  15869. if (ret != 0)
  15870. return WC_TEST_RET_ENC_EC(ret);
  15871. if (XMEMCMP(test2Output, output, sizeof(output)) != 0)
  15872. return WC_TEST_RET_ENC_NC;
  15873. /* Basic RNG generate block test */
  15874. if ((ret = random_rng_test()) != 0)
  15875. return ret;
  15876. /* Test the seed check function. */
  15877. #if !(defined(HAVE_FIPS) || defined(HAVE_SELFTEST)) || \
  15878. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  15879. {
  15880. word32 i, outputSz;
  15881. /* Repeat the same byte over and over. Should fail. */
  15882. outputSz = sizeof(output);
  15883. XMEMSET(output, 1, outputSz);
  15884. ret = wc_RNG_TestSeed(output, outputSz);
  15885. if (ret == 0)
  15886. return WC_TEST_RET_ENC_NC;
  15887. /* Every byte of the entropy scratch is different,
  15888. * entropy is a single byte that shouldn't match. */
  15889. outputSz = (sizeof(output) / 2) + 1;
  15890. for (i = 0; i < outputSz; i++)
  15891. output[i] = (byte)i;
  15892. ret = wc_RNG_TestSeed(output, outputSz);
  15893. if (ret != 0)
  15894. return WC_TEST_RET_ENC_EC(ret);
  15895. outputSz = sizeof(output);
  15896. for (i = 0; i < outputSz; i++)
  15897. output[i] = (byte)i;
  15898. ret = wc_RNG_TestSeed(output, outputSz);
  15899. if (ret != 0)
  15900. return WC_TEST_RET_ENC_EC(ret);
  15901. }
  15902. #endif
  15903. /* Test the seed callback. */
  15904. #ifdef WC_RNG_SEED_CB
  15905. if ((ret = rng_seed_test()) != 0)
  15906. return ret;
  15907. #endif
  15908. return 0;
  15909. }
  15910. #else
  15911. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t random_test(void)
  15912. {
  15913. WOLFSSL_ENTER("random_test");
  15914. /* Basic RNG generate block test */
  15915. return random_rng_test();
  15916. }
  15917. #endif /* HAVE_HASHDRBG && !CUSTOM_RAND_GENERATE_BLOCK */
  15918. #endif /* WC_NO_RNG */
  15919. #ifndef MEM_TEST_SZ
  15920. #define MEM_TEST_SZ 1024
  15921. #endif
  15922. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  15923. static int simple_mem_test(size_t sz)
  15924. {
  15925. int ret = 0;
  15926. byte* b;
  15927. int i;
  15928. b = (byte*)XMALLOC(sz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15929. if (b == NULL) {
  15930. return WC_TEST_RET_ENC_NC;
  15931. }
  15932. /* utilize memory */
  15933. for (i = 0; i < (int)sz; i++) {
  15934. b[i] = (byte)i;
  15935. }
  15936. /* read back and verify */
  15937. for (i = 0; i < (int)sz; i++) {
  15938. if (b[i] != (byte)i) {
  15939. ret = WC_TEST_RET_ENC_NC;
  15940. break;
  15941. }
  15942. }
  15943. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  15944. return ret;
  15945. }
  15946. #endif
  15947. /* If successful, returns the first letter of the byte array `in`.
  15948. **
  15949. ** This is a deceptively simple test of a read-only embedded Linux file system.
  15950. ** (e.g CFLAGS `-mfdpic` and `-mforce-l32`) for Xtensa Linux ESP32. When the
  15951. ** `-mforce-l32` is missing, access to `in` will fail with Illegal Instruction.
  15952. ** Const is on read-only memory-mapped file system, *not* loaded in app memory.
  15953. **
  15954. ** Edit with caution. See PR #6523. */
  15955. static wc_test_ret_t const_byte_ptr_test(const byte* in, word32 *outJ)
  15956. {
  15957. wc_test_ret_t ret = 0;
  15958. volatile word32 j = (word32)-1; /* must be volatile to properly detect error */
  15959. ret = (wc_test_ret_t)*in; /* accessed *in value. */
  15960. (void)ret;
  15961. j = *outJ; /* Found index to use in const array. */
  15962. if (j == 0) {
  15963. #ifdef WOLFSSL_DEBUG
  15964. printf("Testing const byte ptr reference...\n");
  15965. #endif
  15966. /* although j is zero, in[0] does not detect the Illegal instruction */
  15967. ret = in[j]; /* The big test: can we actually access the `in` data? */
  15968. }
  15969. else {
  15970. ret = WC_TEST_RET_ENC_I(j);
  15971. }
  15972. return ret;
  15973. }
  15974. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memory_test(void)
  15975. {
  15976. wc_test_ret_t ret = 0;
  15977. word32 j = 0; /* used in embedded const pointer test */
  15978. WOLFSSL_ENTER("memory_test");
  15979. #if defined(COMPLEX_MEM_TEST) || defined(WOLFSSL_STATIC_MEMORY)
  15980. int i;
  15981. #endif
  15982. #ifdef WOLFSSL_STATIC_MEMORY
  15983. word32 size[] = { WOLFMEM_BUCKETS };
  15984. word32 dist[] = { WOLFMEM_DIST };
  15985. byte buffer[30000]; /* make large enough to involve many bucket sizes */
  15986. int pad = -(int)((wc_ptr_t)buffer) & (WOLFSSL_STATIC_ALIGN - 1);
  15987. /* pad to account for if head of buffer is not at set memory
  15988. * alignment when tests are ran */
  15989. #endif
  15990. #ifdef WOLFSSL_STATIC_MEMORY
  15991. /* check macro settings */
  15992. if (sizeof(size)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15993. return WC_TEST_RET_ENC_NC;
  15994. }
  15995. if (sizeof(dist)/sizeof(word32) != WOLFMEM_DEF_BUCKETS) {
  15996. return WC_TEST_RET_ENC_NC;
  15997. }
  15998. if (WOLFMEM_DEF_BUCKETS > WOLFMEM_MAX_BUCKETS) {
  15999. return WC_TEST_RET_ENC_NC;
  16000. }
  16001. for (i = 0; i < WOLFMEM_DEF_BUCKETS; i++) {
  16002. if ((size[i] % WOLFSSL_STATIC_ALIGN) != 0) {
  16003. /* each element in array should be divisible by alignment size */
  16004. return WC_TEST_RET_ENC_NC;
  16005. }
  16006. }
  16007. for (i = 1; i < WOLFMEM_DEF_BUCKETS; i++) {
  16008. if (size[i - 1] >= size[i]) {
  16009. return WC_TEST_RET_ENC_NC; /* sizes should be in increasing order */
  16010. }
  16011. }
  16012. #ifndef WOLFSSL_STATIC_MEMORY_LEAN
  16013. /* check that padding size returned is possible */
  16014. if (wolfSSL_MemoryPaddingSz() < WOLFSSL_STATIC_ALIGN) {
  16015. return WC_TEST_RET_ENC_NC; /* no room for wc_Memory struct */
  16016. }
  16017. ret = wolfSSL_MemoryPaddingSz();
  16018. if (ret < 0) {
  16019. return WC_TEST_RET_ENC_EC(ret);
  16020. }
  16021. if (wolfSSL_MemoryPaddingSz() % WOLFSSL_STATIC_ALIGN != 0) {
  16022. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16023. }
  16024. /* check function to return optimum buffer size (rounded down) */
  16025. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_GENERAL);
  16026. if (ret < 0) {
  16027. return WC_TEST_RET_ENC_EC(ret);
  16028. }
  16029. if ((ret - pad) % WOLFSSL_STATIC_ALIGN != 0) {
  16030. return WC_TEST_RET_ENC_NC; /* not aligned! */
  16031. }
  16032. if ((unsigned int)ret > sizeof(buffer)) {
  16033. return WC_TEST_RET_ENC_NC; /* did not round down as expected */
  16034. }
  16035. if (ret != wolfSSL_StaticBufferSz(buffer, ret, WOLFMEM_GENERAL)) {
  16036. return WC_TEST_RET_ENC_NC; /* return value changed when using suggested
  16037. * value
  16038. */
  16039. }
  16040. ret = wolfSSL_MemoryPaddingSz();
  16041. ret += pad; /* add space that is going to be needed if buffer not aligned */
  16042. if (wolfSSL_StaticBufferSz(buffer, size[0] + ret + 1, WOLFMEM_GENERAL) !=
  16043. (ret + (int)size[0])) {
  16044. return WC_TEST_RET_ENC_NC; /* did not round down to nearest bucket
  16045. * value
  16046. */
  16047. }
  16048. ret = wolfSSL_StaticBufferSz(buffer, sizeof(buffer), WOLFMEM_IO_POOL);
  16049. if ((ret - pad) < 0) {
  16050. return WC_TEST_RET_ENC_NC;
  16051. }
  16052. if (((ret - pad) % (WOLFMEM_IO_SZ + wolfSSL_MemoryPaddingSz())) != 0) {
  16053. return WC_TEST_RET_ENC_NC; /* not even chunks of memory for IO size */
  16054. }
  16055. if (((ret - pad) % WOLFSSL_STATIC_ALIGN) != 0) {
  16056. return WC_TEST_RET_ENC_NC; /* memory not aligned */
  16057. }
  16058. /* check for passing bad or unknown arguments to functions */
  16059. if (wolfSSL_StaticBufferSz(NULL, 1, WOLFMEM_GENERAL) > 0) {
  16060. return WC_TEST_RET_ENC_NC;
  16061. }
  16062. if (wolfSSL_StaticBufferSz(buffer, 1, WOLFMEM_GENERAL) != 0) {
  16063. return WC_TEST_RET_ENC_NC; /* should round to 0
  16064. since struct + bucket will not fit */
  16065. }
  16066. #endif
  16067. (void)pad;
  16068. (void)dist; /* avoid static analysis warning of variable not used */
  16069. #endif
  16070. #if defined(WOLFSSL_STATIC_MEMORY) || !defined(WOLFSSL_NO_MALLOC)
  16071. /* simple test */
  16072. ret = simple_mem_test((size_t)MEM_TEST_SZ);
  16073. if (ret != 0)
  16074. return ret;
  16075. #endif
  16076. #ifdef COMPLEX_MEM_TEST
  16077. /* test various size blocks */
  16078. for (i = 1; i < MEM_TEST_SZ; i*=2) {
  16079. ret = simple_mem_test((size_t)i);
  16080. if (ret != 0)
  16081. return ret;
  16082. }
  16083. #endif
  16084. #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_NO_MALLOC) && defined(XREALLOC)
  16085. /* realloc test */
  16086. {
  16087. byte *b = (byte*)XMALLOC(MEM_TEST_SZ, HEAP_HINT,
  16088. DYNAMIC_TYPE_TMP_BUFFER);
  16089. #ifndef WOLFSSL_NO_REALLOC
  16090. byte *c = NULL;
  16091. if (b) {
  16092. c = (byte*)XREALLOC(b, MEM_TEST_SZ+sizeof(word32), HEAP_HINT,
  16093. DYNAMIC_TYPE_TMP_BUFFER);
  16094. if (c)
  16095. b = c;
  16096. }
  16097. #endif
  16098. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16099. if (b == NULL
  16100. #ifndef WOLFSSL_NO_REALLOC
  16101. || c == NULL
  16102. #endif
  16103. ) {
  16104. return WC_TEST_RET_ENC_ERRNO;
  16105. }
  16106. }
  16107. #endif
  16108. if (ret == 0) {
  16109. /* This test is only interesting on embedded R/O Flash systems */
  16110. if (const_byte_ptr_test(const_byte_array, &j) != CBPTR_EXPECTED) {
  16111. ret = 1;
  16112. }
  16113. }
  16114. return ret;
  16115. }
  16116. #ifndef NO_FILESYSTEM
  16117. /* Cert Paths */
  16118. #ifdef FREESCALE_MQX
  16119. #define CERT_PREFIX "a:\\"
  16120. #define CERT_PATH_SEP "\\"
  16121. #elif defined(WOLFSSL_uTKERNEL2)
  16122. #define CERT_PREFIX "/uda/"
  16123. #define CERT_PATH_SEP "/"
  16124. #elif defined(_WIN32_WCE)
  16125. #define CERT_PREFIX "\\windows\\"
  16126. #define CERT_PATH_SEP "\\"
  16127. #elif defined(WOLFSSL_NDS)
  16128. #undef CERT_PREFIX
  16129. #ifndef WOLFSSL_MELONDS
  16130. #define CERT_PREFIX "fat:/_nds/"
  16131. #else
  16132. #define CERT_PREFIX "_nds/"
  16133. #endif
  16134. #define CERT_PATH_SEP "/"
  16135. #endif
  16136. #ifndef CERT_PREFIX
  16137. #define CERT_PREFIX "./"
  16138. #endif
  16139. #ifndef CERT_PATH_SEP
  16140. #define CERT_PATH_SEP "/"
  16141. #endif
  16142. #ifndef CERT_WRITE_TEMP_DIR
  16143. #define CERT_WRITE_TEMP_DIR CERT_PREFIX
  16144. #endif
  16145. #define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
  16146. /* Generated Test Certs */
  16147. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16148. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16149. #if !defined(NO_RSA) && !defined(NO_ASN)
  16150. static const char* clientKey = CERT_ROOT "client-key.der";
  16151. static const char* clientCert = CERT_ROOT "client-cert.der";
  16152. #ifdef WOLFSSL_CERT_EXT
  16153. static const char* clientKeyPub = CERT_ROOT "client-keyPub.der";
  16154. #endif
  16155. #endif /* !NO_RSA && !NO_ASN */
  16156. #endif
  16157. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16158. #if !defined(NO_RSA) && !defined(NO_ASN)
  16159. #if defined(WOLFSSL_CERT_GEN) || defined(HAVE_PKCS7)
  16160. static const char* rsaCaKeyFile = CERT_ROOT "ca-key.der";
  16161. #ifdef WOLFSSL_CERT_GEN
  16162. static const char* rsaCaCertFile = CERT_ROOT "ca-cert.pem";
  16163. #endif
  16164. #if (defined(WOLFSSL_ALT_NAMES) && !defined(WOLFSSL_NO_MALLOC)) || \
  16165. defined(HAVE_PKCS7)
  16166. static const char* rsaCaCertDerFile = CERT_ROOT "ca-cert.der";
  16167. #endif
  16168. #ifdef HAVE_PKCS7
  16169. static const char* rsaServerCertDerFile =
  16170. CERT_ROOT "server-cert.der";
  16171. static const char* rsaServerKeyDerFile =
  16172. CERT_ROOT "server-key.der";
  16173. #endif
  16174. #endif
  16175. #endif /* !NO_RSA && !NO_ASN */
  16176. #endif /* !USE_CERT_BUFFER_* */
  16177. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  16178. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  16179. #if !defined(NO_ASN) && !defined(NO_DH)
  16180. static const char* dhParamsFile = CERT_ROOT "dh2048.der";
  16181. #endif
  16182. #endif
  16183. #if !defined(NO_ASN) && !defined(NO_DH)
  16184. #if defined(WOLFSSL_DH_EXTRA) && (!defined(HAVE_FIPS) || \
  16185. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  16186. #if !defined(USE_CERT_BUFFERS_2048)
  16187. static const char* dhKeyFile = CERT_ROOT "statickeys/dh-ffdhe2048.der";
  16188. static const char* dhKeyPubFile = CERT_ROOT "statickeys/dh-ffdhe2048-pub.der";
  16189. #endif
  16190. #endif
  16191. #endif
  16192. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  16193. #ifndef NO_DSA
  16194. static const char* dsaKey = CERT_ROOT "dsa2048.der";
  16195. #endif
  16196. #endif /* !USE_CERT_BUFFER_* */
  16197. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ECC256)
  16198. #ifdef HAVE_ECC
  16199. /* cert files to be used in rsa cert gen test, check if RSA enabled */
  16200. #ifdef HAVE_ECC_KEY_IMPORT
  16201. static const char* eccKeyDerFile = CERT_ROOT "ecc-key.der";
  16202. #endif
  16203. #endif
  16204. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_ASN)
  16205. #if defined(HAVE_ECC) && defined(WOLFSSL_CERT_GEN) && \
  16206. !defined(NO_ECC_SECP)
  16207. #ifndef NO_RSA
  16208. static const char* eccKeyPubFileDer = CERT_ROOT "ecc-keyPub.der";
  16209. #endif
  16210. #if !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  16211. static const char* eccCaKeyFile = CERT_ROOT "ca-ecc-key.der";
  16212. static const char* eccCaCertFile = CERT_ROOT "ca-ecc-cert.pem";
  16213. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16214. static const char* eccCaKey384File =
  16215. CERT_ROOT "ca-ecc384-key.der";
  16216. static const char* eccCaCert384File =
  16217. CERT_ROOT "ca-ecc384-cert.pem";
  16218. #endif
  16219. #endif
  16220. #endif
  16221. #if defined(HAVE_PKCS7) && defined(HAVE_ECC)
  16222. static const char* eccClientKey = CERT_ROOT "ecc-client-key.der";
  16223. static const char* eccClientCert = CERT_ROOT "client-ecc-cert.der";
  16224. #endif
  16225. #endif /* HAVE_ECC */
  16226. #ifdef HAVE_ED25519
  16227. #ifdef WOLFSSL_TEST_CERT
  16228. static const char* serverEd25519Cert =
  16229. CERT_ROOT "ed25519/server-ed25519.der";
  16230. static const char* caEd25519Cert =
  16231. CERT_ROOT "ed25519/ca-ed25519.der";
  16232. #endif
  16233. #endif
  16234. #ifdef HAVE_ED448
  16235. #ifdef WOLFSSL_TEST_CERT
  16236. static const char* serverEd448Cert =
  16237. CERT_ROOT "ed448/server-ed448.der";
  16238. static const char* caEd448Cert = CERT_ROOT "ed448/ca-ed448.der";
  16239. #endif
  16240. #endif
  16241. #endif /* !USE_CERT_BUFFER_* */
  16242. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16243. !defined(NO_FILESYSTEM)
  16244. static const char* certExtNc =
  16245. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nc.der";
  16246. static const char* certExtIa =
  16247. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-ia.der";
  16248. static const char* certExtNct =
  16249. CERT_ROOT "test" CERT_PATH_SEP "cert-ext-nct.der";
  16250. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16251. static const char* certBadNegInt =
  16252. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-neg-int.der";
  16253. #endif
  16254. static const char* certBadOid =
  16255. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-oid.der";
  16256. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16257. static const char* certBadUtf8 =
  16258. CERT_ROOT "test" CERT_PATH_SEP "cert-bad-utf8.der";
  16259. #endif
  16260. #endif
  16261. #ifndef NO_WRITE_TEMP_FILES
  16262. #ifdef HAVE_ECC
  16263. #ifndef NO_ECC_SECP
  16264. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16265. !defined(WOLFSSL_NO_MALLOC)
  16266. static const char* certEccPemFile = CERT_WRITE_TEMP_DIR "certecc.pem";
  16267. static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
  16268. #endif
  16269. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
  16270. static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
  16271. static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
  16272. #endif
  16273. #endif
  16274. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  16275. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ASN_CRYPT)
  16276. static const char* eccCaKeyPemFile = CERT_WRITE_TEMP_DIR "ecc-key.pem";
  16277. static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
  16278. static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
  16279. #if defined(HAVE_PKCS8) && !defined(WC_NO_RNG) && \
  16280. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  16281. static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
  16282. #endif
  16283. #endif /* HAVE_ECC_KEY_EXPORT */
  16284. #endif /* HAVE_ECC */
  16285. #ifndef NO_RSA
  16286. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  16287. !defined(WOLFSSL_NO_MALLOC)
  16288. static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
  16289. static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
  16290. static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
  16291. static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
  16292. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  16293. static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
  16294. static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
  16295. #endif
  16296. #endif
  16297. #endif /* !NO_RSA */
  16298. #if !defined(NO_RSA) || !defined(NO_DSA)
  16299. #ifdef WOLFSSL_KEY_GEN
  16300. static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
  16301. static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
  16302. #endif
  16303. #endif
  16304. #endif /* !NO_WRITE_TEMP_FILES */
  16305. #endif /* !NO_FILESYSTEM */
  16306. #if defined(WOLFSSL_CERT_GEN) && (!defined(NO_RSA) || defined(HAVE_ECC)) || \
  16307. (defined(WOLFSSL_TEST_CERT) && (defined(HAVE_ED25519) || defined(HAVE_ED448)))
  16308. static CertName certDefaultName;
  16309. static void initDefaultName(void)
  16310. {
  16311. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16312. NameAttrib* n;
  16313. #endif
  16314. XMEMCPY(certDefaultName.country, "US", sizeof("US"));
  16315. certDefaultName.countryEnc = CTC_PRINTABLE;
  16316. XMEMCPY(certDefaultName.state, "Oregon", sizeof("Oregon"));
  16317. certDefaultName.stateEnc = CTC_UTF8;
  16318. XMEMCPY(certDefaultName.street, "Main St", sizeof("Main St"));
  16319. certDefaultName.streetEnc = CTC_UTF8;
  16320. XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
  16321. certDefaultName.localityEnc = CTC_UTF8;
  16322. XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
  16323. certDefaultName.surEnc = CTC_UTF8;
  16324. XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
  16325. certDefaultName.orgEnc = CTC_UTF8;
  16326. XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
  16327. certDefaultName.unitEnc = CTC_UTF8;
  16328. XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
  16329. certDefaultName.commonNameEnc = CTC_UTF8;
  16330. XMEMCPY(certDefaultName.serialDev, "wolfSSL12345", sizeof("wolfSSL12345"));
  16331. certDefaultName.serialDevEnc = CTC_PRINTABLE;
  16332. XMEMCPY(certDefaultName.postalCode, "12-456", sizeof("12-456"));
  16333. certDefaultName.postalCodeEnc = CTC_PRINTABLE;
  16334. #ifdef WOLFSSL_CERT_EXT
  16335. XMEMCPY(certDefaultName.busCat, "Private Organization", sizeof("Private Organization"));
  16336. certDefaultName.busCatEnc = CTC_UTF8;
  16337. XMEMCPY(certDefaultName.joiSt, "US", sizeof("US"));
  16338. certDefaultName.joiStEnc = CTC_PRINTABLE;
  16339. XMEMCPY(certDefaultName.joiC, "Oregon", sizeof("Oregon"));
  16340. certDefaultName.joiCEnc = CTC_PRINTABLE;
  16341. #endif
  16342. XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
  16343. XMEMCPY(certDefaultName.userId, "TestUserID", sizeof("TestUserID"));
  16344. certDefaultName.userIdEnc = CTC_PRINTABLE;
  16345. #if defined(WOLFSSL_MULTI_ATTRIB) && defined(WOLFSSL_TEST_CERT)
  16346. /* test having additional OUs and setting DC */
  16347. n = &certDefaultName.name[0];
  16348. n->id = ASN_ORGUNIT_NAME;
  16349. n->type = CTC_UTF8;
  16350. n->sz = XSTRLEN("Development-2");
  16351. XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
  16352. #if CTC_MAX_ATTRIB > 3
  16353. n = &certDefaultName.name[1];
  16354. n->id = ASN_DOMAIN_COMPONENT;
  16355. n->type = CTC_UTF8;
  16356. n->sz = XSTRLEN("com");
  16357. XMEMCPY(n->value, "com", sizeof("com"));
  16358. n = &certDefaultName.name[2];
  16359. n->id = ASN_DOMAIN_COMPONENT;
  16360. n->type = CTC_UTF8;
  16361. n->sz = XSTRLEN("wolfssl");
  16362. XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
  16363. #endif
  16364. #endif /* WOLFSSL_MULTI_ATTRIB && WOLFSSL_TEST_CERT */
  16365. #ifdef WOLFSSL_CUSTOM_OID
  16366. /* TODO: Add test case for custom OID's */
  16367. #endif
  16368. }
  16369. #ifdef WOLFSSL_CERT_EXT
  16370. #if ((defined(HAVE_ED25519) || defined(HAVE_ED448)) && \
  16371. defined(WOLFSSL_TEST_CERT)) || defined(HAVE_ECC)
  16372. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage[] =
  16373. "digitalSignature,nonRepudiation";
  16374. #endif
  16375. #if defined(WOLFSSL_CERT_REQ) && !defined(NO_RSA) && !defined(NO_ASN_TIME)
  16376. WOLFSSL_SMALL_STACK_STATIC const char certKeyUsage2[] =
  16377. "digitalSignature,nonRepudiation,keyEncipherment,keyAgreement";
  16378. #endif
  16379. #endif /* WOLFSSL_CERT_EXT */
  16380. #endif /* WOLFSSL_CERT_GEN */
  16381. #ifndef NO_RSA
  16382. #if !defined(NO_ASN_TIME) && !defined(NO_RSA) && defined(WOLFSSL_TEST_CERT) && \
  16383. !defined(NO_FILESYSTEM)
  16384. static const byte minSerial[] = { 0x02, 0x01, 0x01 };
  16385. static const byte minName[] = { 0x30, 0x00 };
  16386. static const byte nameBad[] = {
  16387. 0x30, 0x08,
  16388. 0x31, 0x06,
  16389. 0x30, 0x04,
  16390. 0x06, 0x02,
  16391. 0x55, 0x04,
  16392. };
  16393. static const byte minDates[] = {
  16394. 0x30, 0x1e,
  16395. 0x17, 0x0d,
  16396. 0x31, 0x38, 0x30, 0x34, 0x31, 0x33, 0x31, 0x35,
  16397. 0x32, 0x33, 0x31, 0x30, 0x5a,
  16398. 0x17, 0x0d,
  16399. 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x31, 0x35,
  16400. 0x32, 0x33, 0x31, 0x30, 0x5a
  16401. };
  16402. static const byte minPubKey[] = {
  16403. 0x30, 0x1c,
  16404. 0x30, 0x0d,
  16405. 0x06, 0x09,
  16406. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16407. 0x01,
  16408. 0x05, 0x00,
  16409. 0x03, 0x0b,
  16410. 0x00, 0x30, 0x08,
  16411. 0x02, 0x01,
  16412. 0x03,
  16413. 0x02, 0x03,
  16414. 0x01, 0x00, 0x01
  16415. };
  16416. static const byte minSigAlg[] = {
  16417. 0x30, 0x0d,
  16418. 0x06, 0x09,
  16419. 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
  16420. 0x0b,
  16421. 0x05, 0x00
  16422. };
  16423. static const byte minSig[] = {
  16424. 0x03, 0x01,
  16425. 0x00
  16426. };
  16427. static int add_seq(byte* certData, int offset, byte* data, byte length)
  16428. {
  16429. XMEMMOVE(certData + offset + 2, data, length);
  16430. certData[offset++] = 0x30;
  16431. certData[offset++] = length;
  16432. return offset + length;
  16433. }
  16434. static int add_data(byte* certData, int offset, const byte* data, byte length)
  16435. {
  16436. XMEMCPY(certData + offset, data, length);
  16437. return offset + length;
  16438. }
  16439. static wc_test_ret_t cert_asn1_test(void)
  16440. {
  16441. wc_test_ret_t ret;
  16442. int len[3];
  16443. DecodedCert cert;
  16444. byte certData[114];
  16445. byte* badCert = NULL;
  16446. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16447. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16448. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16449. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16450. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16451. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16452. len[1] = add_seq(certData, 0, certData, len[2]);
  16453. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16454. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16455. len[0] = add_seq(certData, 0, certData, len[1]);
  16456. /* Minimal good certificate */
  16457. InitDecodedCert(&cert, certData, len[0], 0);
  16458. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16459. FreeDecodedCert(&cert);
  16460. if (ret != 0)
  16461. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16462. /* Bad issuer name */
  16463. len[2] = add_data(certData, 0, minSerial, (byte)sizeof(minSerial));
  16464. len[2] = add_data(certData, len[2], minSigAlg, (byte)sizeof(minSigAlg));
  16465. len[2] = add_data(certData, len[2], nameBad, (byte)sizeof(nameBad));
  16466. len[2] = add_data(certData, len[2], minDates, (byte)sizeof(minDates));
  16467. len[2] = add_data(certData, len[2], minName, (byte)sizeof(minName));
  16468. len[2] = add_data(certData, len[2], minPubKey, (byte)sizeof(minPubKey));
  16469. len[1] = add_seq(certData, 0, certData, len[2]);
  16470. len[1] = add_data(certData, len[1], minSigAlg, (byte)sizeof(minSigAlg));
  16471. len[1] = add_data(certData, len[1], minSig, (byte)sizeof(minSig));
  16472. len[0] = add_seq(certData, 0, certData, len[1]);
  16473. /* Put data into allocated buffer to allow access error checking. */
  16474. badCert = (byte*)XMALLOC(len[0], HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16475. XMEMCPY(badCert, certData, len[0]);
  16476. InitDecodedCert(&cert, badCert, len[0], 0);
  16477. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16478. FreeDecodedCert(&cert);
  16479. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  16480. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16481. }
  16482. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16483. badCert = NULL;
  16484. ret = 0;
  16485. done:
  16486. XFREE(badCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16487. return ret;
  16488. }
  16489. static wc_test_ret_t cert_load_bad(const char* fname, byte* tmp, int err)
  16490. {
  16491. wc_test_ret_t ret;
  16492. DecodedCert cert;
  16493. XFILE file;
  16494. size_t bytes;
  16495. if ((fname == NULL) || (tmp == NULL)) {
  16496. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  16497. }
  16498. file = XFOPEN(fname, "rb");
  16499. if (!file) {
  16500. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16501. }
  16502. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16503. XFCLOSE(file);
  16504. if (bytes == 0) {
  16505. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16506. }
  16507. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16508. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16509. FreeDecodedCert(&cert);
  16510. if (ret != err) {
  16511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16512. }
  16513. ret = 0;
  16514. done:
  16515. return ret;
  16516. }
  16517. static wc_test_ret_t cert_bad_asn1_test(void)
  16518. {
  16519. wc_test_ret_t ret = 0;
  16520. byte* tmp;
  16521. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16522. if (tmp == NULL) {
  16523. ret = WC_TEST_RET_ENC_ERRNO;
  16524. }
  16525. #ifndef WOLFSSL_ASN_INT_LEAD_0_ANY
  16526. if (ret == 0) {
  16527. /* Serial number: 0xff 0xa8. 0xff and top bit set on next byte invalid.
  16528. */
  16529. ret = cert_load_bad(certBadNegInt, tmp, ASN_EXPECT_0_E);
  16530. }
  16531. #endif
  16532. if (ret == 0) {
  16533. /* Subject name OID: 55 04 f4. Last byte with top bit set invalid. */
  16534. ret = cert_load_bad(certBadOid, tmp, ASN_PARSE_E);
  16535. }
  16536. #if defined(WOLFSSL_ASN_TEMPLATE) && !defined(WOLFSSL_NO_ASN_STRICT)
  16537. if (ret == 0) {
  16538. /* Issuer name UTF8STRING: df 52 4e 44. Top bit of second byte not set.
  16539. */
  16540. ret = cert_load_bad(certBadUtf8, tmp, ASN_PARSE_E);
  16541. }
  16542. #endif
  16543. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16544. return ret;
  16545. }
  16546. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cert_test(void)
  16547. {
  16548. #if !defined(NO_FILESYSTEM)
  16549. DecodedCert cert;
  16550. byte* tmp;
  16551. size_t bytes;
  16552. XFILE file;
  16553. wc_test_ret_t ret;
  16554. WOLFSSL_ENTER("cert_test");
  16555. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16556. if (tmp == NULL)
  16557. return WC_TEST_RET_ENC_ERRNO;
  16558. /* Certificate with Name Constraints extension. */
  16559. file = XFOPEN(certExtNc, "rb");
  16560. if (!file) {
  16561. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16562. }
  16563. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16564. XFCLOSE(file);
  16565. if (bytes == 0)
  16566. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16567. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16568. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16569. if (ret != 0)
  16570. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16571. FreeDecodedCert(&cert);
  16572. /* Certificate with Inhibit Any Policy extension. */
  16573. file = XFOPEN(certExtIa, "rb");
  16574. if (!file) {
  16575. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16576. }
  16577. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16578. XFCLOSE(file);
  16579. if (bytes == 0)
  16580. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16581. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16582. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16583. if (ret != 0)
  16584. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16585. FreeDecodedCert(&cert);
  16586. /* Certificate with Netscape Certificate Type extension. */
  16587. file = XFOPEN(certExtNct, "rb");
  16588. if (!file) {
  16589. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16590. }
  16591. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16592. XFCLOSE(file);
  16593. if (bytes == 0)
  16594. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  16595. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16596. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, NULL);
  16597. #ifndef IGNORE_NETSCAPE_CERT_TYPE
  16598. if (ret != 0)
  16599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16600. #else
  16601. if (ret != WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
  16602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  16603. }
  16604. ret = 0;
  16605. #endif
  16606. done:
  16607. FreeDecodedCert(&cert);
  16608. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16609. #endif /* !NO_FILESYSTEM */
  16610. if (ret == 0)
  16611. ret = cert_asn1_test();
  16612. if (ret == 0)
  16613. ret = cert_bad_asn1_test();
  16614. return ret;
  16615. }
  16616. #endif /* WOLFSSL_TEST_CERT */
  16617. #if defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT) && \
  16618. !defined(NO_FILESYSTEM) && !defined(NO_RSA) && defined(WOLFSSL_GEN_CERT)
  16619. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certext_test(void)
  16620. {
  16621. DecodedCert cert;
  16622. byte* tmp;
  16623. size_t bytes;
  16624. XFILE file;
  16625. wc_test_ret_t ret;
  16626. /* created from rsa_test : othercert.der */
  16627. byte skid_rsa[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16628. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16629. /* created from rsa_test : othercert.der */
  16630. byte akid_rsa[] = "\x27\x8E\x67\x11\x74\xC3\x26\x1D\x3F\xED"
  16631. "\x33\x63\xB3\xA4\xD8\x1D\x30\xE5\xE8\xD5";
  16632. #ifdef HAVE_ECC
  16633. /* created from ecc_test_cert_gen : certecc.der */
  16634. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  16635. /* Authority key id from ./certs/ca-ecc384-cert.pem */
  16636. byte akid_ecc[] = "\xAB\xE0\xC3\x26\x4C\x18\xD4\x72\xBB\xD2"
  16637. "\x84\x8C\x9C\x0A\x05\x92\x80\x12\x53\x52";
  16638. #else
  16639. /* Authority key id from ./certs/ca-ecc-cert.pem */
  16640. byte akid_ecc[] = "\x56\x8E\x9A\xC3\xF0\x42\xDE\x18\xB9\x45"
  16641. "\x55\x6E\xF9\x93\xCF\xEA\xC3\xF3\xA5\x21";
  16642. #endif
  16643. #endif /* HAVE_ECC */
  16644. /* created from rsa_test : cert.der */
  16645. byte kid_ca[] = "\x33\xD8\x45\x66\xD7\x68\x87\x18\x7E\x54"
  16646. "\x0D\x70\x27\x91\xC7\x26\xD7\x85\x65\xC0";
  16647. WOLFSSL_ENTER("certext_test");
  16648. tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16649. if (tmp == NULL)
  16650. return WC_TEST_RET_ENC_ERRNO;
  16651. /* load othercert.der (Cert signed by an authority) */
  16652. file = XFOPEN(otherCertDerFile, "rb");
  16653. if (!file) {
  16654. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16655. return WC_TEST_RET_ENC_ERRNO;
  16656. }
  16657. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16658. XFCLOSE(file);
  16659. if (bytes == 0)
  16660. return WC_TEST_RET_ENC_ERRNO;
  16661. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16662. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16663. if (ret != 0)
  16664. return WC_TEST_RET_ENC_EC(ret);
  16665. /* check the SKID from a RSA certificate */
  16666. if ((sizeof(skid_rsa) - 1 != cert.extSubjKeyIdSz) ||
  16667. (XMEMCMP(skid_rsa, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16668. return WC_TEST_RET_ENC_NC;
  16669. /* check the AKID from an RSA certificate */
  16670. if ((sizeof(akid_rsa) - 1 != cert.extAuthKeyIdSz) ||
  16671. (XMEMCMP(akid_rsa, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16672. return WC_TEST_RET_ENC_NC;
  16673. /* check the Key Usage from an RSA certificate */
  16674. if (!cert.extKeyUsageSet)
  16675. return WC_TEST_RET_ENC_NC;
  16676. if (cert.extKeyUsage != (KEYUSE_KEY_ENCIPHER|KEYUSE_KEY_AGREE))
  16677. return WC_TEST_RET_ENC_NC;
  16678. /* check the CA Basic Constraints from an RSA certificate */
  16679. if (cert.isCA)
  16680. return WC_TEST_RET_ENC_NC;
  16681. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16682. /* check the Certificate Policies Id */
  16683. if (cert.extCertPoliciesNb != 1)
  16684. return WC_TEST_RET_ENC_NC;
  16685. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16686. return WC_TEST_RET_ENC_NC;
  16687. #endif
  16688. FreeDecodedCert(&cert);
  16689. #ifdef HAVE_ECC
  16690. /* load certecc.der (Cert signed by our ECC CA test in ecc_test_cert_gen) */
  16691. file = XFOPEN(certEccDerFile, "rb");
  16692. if (!file) {
  16693. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16694. return WC_TEST_RET_ENC_ERRNO;
  16695. }
  16696. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16697. XFCLOSE(file);
  16698. if (bytes == 0)
  16699. return WC_TEST_RET_ENC_ERRNO;
  16700. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16701. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16702. if (ret != 0)
  16703. return WC_TEST_RET_ENC_EC(ret);
  16704. /* check the SKID from a ECC certificate - generated dynamically */
  16705. /* check the AKID from an ECC certificate */
  16706. if ((sizeof(akid_ecc) - 1 != cert.extAuthKeyIdSz) ||
  16707. (XMEMCMP(akid_ecc, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16708. return WC_TEST_RET_ENC_NC;
  16709. /* check the Key Usage from an ECC certificate */
  16710. if (!cert.extKeyUsageSet)
  16711. return WC_TEST_RET_ENC_NC;
  16712. if (cert.extKeyUsage != (KEYUSE_DIGITAL_SIG|KEYUSE_CONTENT_COMMIT))
  16713. return WC_TEST_RET_ENC_NC;
  16714. /* check the CA Basic Constraints from an ECC certificate */
  16715. if (cert.isCA)
  16716. return WC_TEST_RET_ENC_NC;
  16717. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16718. /* check the Certificate Policies Id */
  16719. if (cert.extCertPoliciesNb != 2)
  16720. return WC_TEST_RET_ENC_NC;
  16721. if (strncmp(cert.extCertPolicies[0], "2.4.589440.587.101.2.1.9632587.1", 32))
  16722. return WC_TEST_RET_ENC_NC;
  16723. if (strncmp(cert.extCertPolicies[1], "1.2.13025.489.1.113549", 22))
  16724. return WC_TEST_RET_ENC_NC;
  16725. #endif
  16726. FreeDecodedCert(&cert);
  16727. #endif /* HAVE_ECC */
  16728. /* load cert.der (self signed certificate) */
  16729. file = XFOPEN(certDerFile, "rb");
  16730. if (!file) {
  16731. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16732. return WC_TEST_RET_ENC_ERRNO;
  16733. }
  16734. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  16735. XFCLOSE(file);
  16736. if (bytes == 0)
  16737. return WC_TEST_RET_ENC_ERRNO;
  16738. InitDecodedCert(&cert, tmp, (word32)bytes, 0);
  16739. ret = ParseCert(&cert, CERT_TYPE, NO_VERIFY, 0);
  16740. if (ret != 0)
  16741. return WC_TEST_RET_ENC_EC(ret);
  16742. /* check the SKID from a CA certificate */
  16743. if ((sizeof(kid_ca) - 1 != cert.extSubjKeyIdSz) ||
  16744. (XMEMCMP(kid_ca, cert.extSubjKeyId, cert.extSubjKeyIdSz)))
  16745. return WC_TEST_RET_ENC_NC;
  16746. /* check the AKID from an CA certificate */
  16747. if ((sizeof(kid_ca) - 1 != cert.extAuthKeyIdSz) ||
  16748. (XMEMCMP(kid_ca, cert.extAuthKeyId, cert.extAuthKeyIdSz)))
  16749. return WC_TEST_RET_ENC_NC;
  16750. /* check the Key Usage from CA certificate */
  16751. if (!cert.extKeyUsageSet)
  16752. return WC_TEST_RET_ENC_NC;
  16753. if (cert.extKeyUsage != (KEYUSE_KEY_CERT_SIGN|KEYUSE_CRL_SIGN))
  16754. return WC_TEST_RET_ENC_NC;
  16755. /* check the CA Basic Constraints CA certificate */
  16756. if (!cert.isCA)
  16757. return WC_TEST_RET_ENC_NC;
  16758. #ifndef WOLFSSL_SEP /* test only if not using SEP policies */
  16759. /* check the Certificate Policies Id */
  16760. if (cert.extCertPoliciesNb != 2)
  16761. return WC_TEST_RET_ENC_NC;
  16762. if (strncmp(cert.extCertPolicies[0], "2.16.840.1.101.3.4.1.42", 23))
  16763. return WC_TEST_RET_ENC_NC;
  16764. if (strncmp(cert.extCertPolicies[1], "1.2.840.113549.1.9.16.6.5", 25))
  16765. return WC_TEST_RET_ENC_NC;
  16766. #endif
  16767. FreeDecodedCert(&cert);
  16768. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16769. return 0;
  16770. }
  16771. #endif /* WOLFSSL_CERT_EXT && WOLFSSL_TEST_CERT &&
  16772. !NO_FILESYSTEM && !NO_RSA && WOLFSSL_CERT_GEN */
  16773. #if defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) && \
  16774. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN)
  16775. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t decodedCertCache_test(void)
  16776. {
  16777. wc_test_ret_t ret = 0;
  16778. Cert cert;
  16779. FILE* file;
  16780. byte* der;
  16781. word32 derSz;
  16782. WOLFSSL_ENTER("decodedCertCache_test");
  16783. derSz = FOURK_BUF;
  16784. der = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16785. if (der == NULL)
  16786. ret = WC_TEST_RET_ENC_NC;
  16787. if (ret == 0) {
  16788. /* load cert.der */
  16789. file = XFOPEN(certDerFile, "rb");
  16790. if (file != NULL) {
  16791. derSz = (word32)XFREAD(der, 1, FOURK_BUF, file);
  16792. XFCLOSE(file);
  16793. if (derSz == 0)
  16794. ret = WC_TEST_RET_ENC_ERRNO;
  16795. }
  16796. else
  16797. ret = WC_TEST_RET_ENC_ERRNO;
  16798. }
  16799. if (ret == 0) {
  16800. ret = wc_InitCert_ex(&cert, HEAP_HINT, devId);
  16801. if (ret != 0)
  16802. ret = WC_TEST_RET_ENC_EC(ret);
  16803. }
  16804. if (ret == 0) {
  16805. ret = wc_SetSubjectBuffer(&cert, der, derSz);
  16806. if (ret != 0)
  16807. ret = WC_TEST_RET_ENC_EC(ret);
  16808. }
  16809. if (ret == 0) {
  16810. ret = wc_SetSubjectBuffer(NULL, der, derSz);
  16811. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16812. ret = 0;
  16813. else
  16814. ret = WC_TEST_RET_ENC_EC(ret);
  16815. }
  16816. if (ret == 0) {
  16817. ret = wc_SetSubjectRaw(&cert, der, derSz);
  16818. if (ret != 0)
  16819. ret = WC_TEST_RET_ENC_EC(ret);
  16820. }
  16821. if (ret == 0) {
  16822. ret = wc_SetSubjectRaw(NULL, der, derSz);
  16823. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16824. ret = 0;
  16825. else
  16826. ret = WC_TEST_RET_ENC_EC(ret);
  16827. }
  16828. if (ret == 0) {
  16829. ret = wc_SetIssuerBuffer(&cert, der, derSz);
  16830. if (ret != 0)
  16831. ret = WC_TEST_RET_ENC_EC(ret);
  16832. }
  16833. if (ret == 0) {
  16834. ret = wc_SetIssuerBuffer(NULL, der, derSz);
  16835. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16836. ret = 0;
  16837. else
  16838. ret = WC_TEST_RET_ENC_EC(ret);
  16839. }
  16840. if (ret == 0) {
  16841. ret = wc_SetIssuerRaw(&cert, der, derSz);
  16842. if (ret != 0)
  16843. ret = WC_TEST_RET_ENC_EC(ret);
  16844. }
  16845. if (ret == 0) {
  16846. ret = wc_SetIssuerRaw(NULL, der, derSz);
  16847. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16848. ret = 0;
  16849. else
  16850. ret = WC_TEST_RET_ENC_EC(ret);
  16851. }
  16852. #ifdef WOLFSSL_ALT_NAMES
  16853. if (ret == 0) {
  16854. ret = wc_SetAltNamesBuffer(&cert, der, derSz);
  16855. if (ret != 0)
  16856. ret = WC_TEST_RET_ENC_EC(ret);
  16857. }
  16858. if (ret == 0) {
  16859. ret = wc_SetAltNamesBuffer(NULL, der, derSz);
  16860. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16861. ret = 0;
  16862. else
  16863. ret = WC_TEST_RET_ENC_EC(ret);
  16864. }
  16865. if (ret == 0) {
  16866. ret = wc_SetDatesBuffer(&cert, der, derSz);
  16867. if (ret != 0)
  16868. ret = WC_TEST_RET_ENC_EC(ret);
  16869. }
  16870. if (ret == 0) {
  16871. ret = wc_SetDatesBuffer(NULL, der, derSz);
  16872. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16873. ret = 0;
  16874. else
  16875. ret = WC_TEST_RET_ENC_EC(ret);
  16876. }
  16877. #endif
  16878. if (ret == 0) {
  16879. ret = wc_SetAuthKeyIdFromCert(&cert, der, derSz);
  16880. if (ret != 0)
  16881. ret = WC_TEST_RET_ENC_EC(ret);
  16882. }
  16883. if (ret == 0) {
  16884. ret = wc_SetAuthKeyIdFromCert(NULL, der, derSz);
  16885. if (ret == WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16886. ret = 0;
  16887. else
  16888. ret = WC_TEST_RET_ENC_NC;
  16889. }
  16890. wc_SetCert_Free(&cert);
  16891. if (ret == 0) {
  16892. if(cert.decodedCert != NULL)
  16893. ret = WC_TEST_RET_ENC_NC;
  16894. }
  16895. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  16896. return ret;
  16897. }
  16898. #endif /* defined(WOLFSSL_CERT_GEN_CACHE) && defined(WOLFSSL_TEST_CERT) &&
  16899. defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_CERT_GEN) */
  16900. #define RSA_TEST_BYTES 512 /* up to 4096-bit key */
  16901. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  16902. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16903. static wc_test_ret_t rsa_flatten_test(RsaKey* key)
  16904. {
  16905. wc_test_ret_t ret;
  16906. byte e[RSA_TEST_BYTES];
  16907. byte n[RSA_TEST_BYTES];
  16908. word32 eSz = sizeof(e);
  16909. word32 nSz = sizeof(n);
  16910. /* Parameter Validation testing. */
  16911. ret = wc_RsaFlattenPublicKey(NULL, e, &eSz, n, &nSz);
  16912. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16913. return WC_TEST_RET_ENC_EC(ret);
  16914. ret = wc_RsaFlattenPublicKey(key, NULL, &eSz, n, &nSz);
  16915. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16916. return WC_TEST_RET_ENC_EC(ret);
  16917. ret = wc_RsaFlattenPublicKey(key, e, NULL, n, &nSz);
  16918. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16919. return WC_TEST_RET_ENC_EC(ret);
  16920. ret = wc_RsaFlattenPublicKey(key, e, &eSz, NULL, &nSz);
  16921. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16922. return WC_TEST_RET_ENC_EC(ret);
  16923. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, NULL);
  16924. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16925. return WC_TEST_RET_ENC_EC(ret);
  16926. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16927. if (ret != 0)
  16928. return WC_TEST_RET_ENC_EC(ret);
  16929. eSz = 0;
  16930. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16931. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16932. return WC_TEST_RET_ENC_EC(ret);
  16933. eSz = sizeof(e);
  16934. nSz = 0;
  16935. ret = wc_RsaFlattenPublicKey(key, e, &eSz, n, &nSz);
  16936. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16937. return WC_TEST_RET_ENC_EC(ret);
  16938. return 0;
  16939. }
  16940. #endif /* NO_ASN */
  16941. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  16942. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  16943. static wc_test_ret_t rsa_export_key_test(RsaKey* key)
  16944. {
  16945. wc_test_ret_t ret;
  16946. byte e[3];
  16947. word32 eSz = sizeof(e);
  16948. byte n[RSA_TEST_BYTES];
  16949. word32 nSz = sizeof(n);
  16950. byte d[RSA_TEST_BYTES];
  16951. word32 dSz = sizeof(d);
  16952. byte p[RSA_TEST_BYTES/2];
  16953. word32 pSz = sizeof(p);
  16954. byte q[RSA_TEST_BYTES/2];
  16955. word32 qSz = sizeof(q);
  16956. word32 zero = 0;
  16957. ret = wc_RsaExportKey(NULL, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16958. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16959. return WC_TEST_RET_ENC_EC(ret);
  16960. ret = wc_RsaExportKey(key, NULL, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16961. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16962. return WC_TEST_RET_ENC_EC(ret);
  16963. ret = wc_RsaExportKey(key, e, NULL, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16964. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16965. return WC_TEST_RET_ENC_EC(ret);
  16966. ret = wc_RsaExportKey(key, e, &eSz, NULL, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16967. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16968. return WC_TEST_RET_ENC_EC(ret);
  16969. ret = wc_RsaExportKey(key, e, &eSz, n, NULL, d, &dSz, p, &pSz, q, &qSz);
  16970. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16971. return WC_TEST_RET_ENC_EC(ret);
  16972. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, NULL, &dSz, p, &pSz, q, &qSz);
  16973. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16974. return WC_TEST_RET_ENC_EC(ret);
  16975. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, NULL, p, &pSz, q, &qSz);
  16976. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16977. return WC_TEST_RET_ENC_EC(ret);
  16978. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, NULL, &pSz, q, &qSz);
  16979. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16980. return WC_TEST_RET_ENC_EC(ret);
  16981. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, NULL, q, &qSz);
  16982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16983. return WC_TEST_RET_ENC_EC(ret);
  16984. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, NULL, &qSz);
  16985. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16986. return WC_TEST_RET_ENC_EC(ret);
  16987. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, NULL);
  16988. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  16989. return WC_TEST_RET_ENC_EC(ret);
  16990. ret = wc_RsaExportKey(key, e, &zero, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  16991. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16992. return WC_TEST_RET_ENC_EC(ret);
  16993. ret = wc_RsaExportKey(key, e, &eSz, n, &zero, d, &dSz, p, &pSz, q, &qSz);
  16994. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16995. return WC_TEST_RET_ENC_EC(ret);
  16996. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  16997. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &zero, p, &pSz, q, &qSz);
  16998. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  16999. return WC_TEST_RET_ENC_EC(ret);
  17000. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &zero, q, &qSz);
  17001. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17002. return WC_TEST_RET_ENC_EC(ret);
  17003. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &zero);
  17004. if (ret != WC_NO_ERR_TRACE(RSA_BUFFER_E))
  17005. return WC_TEST_RET_ENC_EC(ret);
  17006. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  17007. ret = wc_RsaExportKey(key, e, &eSz, n, &nSz, d, &dSz, p, &pSz, q, &qSz);
  17008. if (ret != 0)
  17009. return WC_TEST_RET_ENC_EC(ret);
  17010. return 0;
  17011. }
  17012. #endif /* !HAVE_FIPS && !NO_ASN && !WOLFSSL_RSA_VERIFY_ONLY */
  17013. #ifndef NO_SIG_WRAPPER
  17014. static wc_test_ret_t rsa_sig_test(RsaKey* key, word32 keyLen, int modLen, WC_RNG* rng)
  17015. {
  17016. wc_test_ret_t ret;
  17017. word32 sigSz;
  17018. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  17019. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  17020. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17021. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17022. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17023. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17024. };
  17025. WOLFSSL_SMALL_STACK_STATIC const byte hashEnc[] = {
  17026. 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
  17027. 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
  17028. 0x00, 0x04, 0x20,
  17029. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  17030. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  17031. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  17032. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  17033. };
  17034. word32 inLen = (word32)XSTRLEN((char*)in);
  17035. byte out[RSA_TEST_BYTES];
  17036. /* Parameter Validation testing. */
  17037. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_NONE, key, keyLen);
  17038. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17039. return WC_TEST_RET_ENC_EC(ret);
  17040. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, 0);
  17041. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17042. return WC_TEST_RET_ENC_EC(ret);
  17043. sigSz = (word32)modLen;
  17044. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17045. inLen, out, &sigSz, key, keyLen, rng);
  17046. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17047. return WC_TEST_RET_ENC_EC(ret);
  17048. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17049. 0, out, &sigSz, key, keyLen, rng);
  17050. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17051. return WC_TEST_RET_ENC_EC(ret);
  17052. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17053. inLen, NULL, &sigSz, key, keyLen, rng);
  17054. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17055. return WC_TEST_RET_ENC_EC(ret);
  17056. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17057. inLen, out, NULL, key, keyLen, rng);
  17058. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17059. return WC_TEST_RET_ENC_EC(ret);
  17060. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17061. inLen, out, &sigSz, NULL, keyLen, rng);
  17062. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17063. return WC_TEST_RET_ENC_EC(ret);
  17064. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17065. inLen, out, &sigSz, key, 0, rng);
  17066. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17067. return WC_TEST_RET_ENC_EC(ret);
  17068. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17069. inLen, out, &sigSz, key, keyLen, NULL);
  17070. #if defined(WOLFSSL_AFALG_XILINX_RSA) || defined(WOLFSSL_XILINX_CRYPT)
  17071. /* blinding / rng handled with hardware acceleration */
  17072. if (ret != 0)
  17073. #elif defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
  17074. /* async may not require RNG */
  17075. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17076. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID))
  17077. #else
  17078. if (ret != 0 && ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17079. #endif
  17080. #elif defined(HAVE_FIPS) || !defined(WC_RSA_BLINDING)
  17081. /* FIPS140 implementation does not do blinding */
  17082. if (ret != 0)
  17083. #elif defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
  17084. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17085. #elif defined(WOLFSSL_CRYPTOCELL) || defined(WOLFSSL_SE050)
  17086. /* RNG is handled by hardware */
  17087. if (ret != 0)
  17088. #else
  17089. if (ret != WC_NO_ERR_TRACE(MISSING_RNG_E))
  17090. #endif
  17091. return WC_TEST_RET_ENC_EC(ret);
  17092. sigSz = 0;
  17093. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17094. inLen, out, &sigSz, key, keyLen, rng);
  17095. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17096. return WC_TEST_RET_ENC_EC(ret);
  17097. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, NULL,
  17098. inLen, out, (word32)modLen, key, keyLen);
  17099. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17100. return WC_TEST_RET_ENC_EC(ret);
  17101. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17102. 0, out, (word32)modLen, key, keyLen);
  17103. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17104. return WC_TEST_RET_ENC_EC(ret);
  17105. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17106. inLen, NULL, (word32)modLen, key, keyLen);
  17107. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17108. return WC_TEST_RET_ENC_EC(ret);
  17109. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17110. inLen, out, 0, key, keyLen);
  17111. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17112. return WC_TEST_RET_ENC_EC(ret);
  17113. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17114. inLen, out, (word32)modLen, NULL, keyLen);
  17115. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17116. return WC_TEST_RET_ENC_EC(ret);
  17117. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17118. inLen, out, (word32)modLen, key, 0);
  17119. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  17120. return WC_TEST_RET_ENC_EC(ret);
  17121. #ifndef HAVE_ECC
  17122. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, keyLen);
  17123. if (ret != WC_NO_ERR_TRACE(SIG_TYPE_E))
  17124. return WC_TEST_RET_ENC_EC(ret);
  17125. #endif
  17126. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17127. return 0;
  17128. #endif
  17129. /* Use APIs. */
  17130. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA, key, keyLen);
  17131. if (ret != modLen)
  17132. return WC_TEST_RET_ENC_EC(ret);
  17133. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_RSA_W_ENC, key, keyLen);
  17134. if (ret != modLen)
  17135. return WC_TEST_RET_ENC_EC(ret);
  17136. sigSz = (word32)ret;
  17137. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  17138. XMEMSET(out, 0, sizeof(out));
  17139. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17140. inLen, out, &sigSz, key, keyLen, rng);
  17141. if (ret != 0)
  17142. return WC_TEST_RET_ENC_EC(ret);
  17143. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17144. inLen, out, (word32)modLen, key, keyLen);
  17145. if (ret != 0)
  17146. return WC_TEST_RET_ENC_EC(ret);
  17147. sigSz = (word32)sizeof(out);
  17148. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17149. in, inLen, out, &sigSz, key, keyLen, rng);
  17150. if (ret != 0)
  17151. return WC_TEST_RET_ENC_EC(ret);
  17152. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17153. in, inLen, out, (word32)modLen, key, keyLen);
  17154. if (ret != 0)
  17155. return WC_TEST_RET_ENC_EC(ret);
  17156. /* Wrong signature type. */
  17157. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA, in,
  17158. inLen, out, (word32)modLen, key, keyLen);
  17159. if (ret == 0)
  17160. return WC_TEST_RET_ENC_EC(ret);
  17161. /* check hash functions */
  17162. sigSz = (word32)sizeof(out);
  17163. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17164. hash, (int)sizeof(hash), out, &sigSz, key, keyLen, rng);
  17165. if (ret != 0)
  17166. return WC_TEST_RET_ENC_EC(ret);
  17167. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  17168. hash, (int)sizeof(hash), out, (word32)modLen, key, keyLen);
  17169. if (ret != 0)
  17170. return WC_TEST_RET_ENC_EC(ret);
  17171. sigSz = (word32)sizeof(out);
  17172. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17173. hashEnc, (int)sizeof(hashEnc), out, &sigSz, key, keyLen, rng);
  17174. if (ret != 0)
  17175. return WC_TEST_RET_ENC_EC(ret);
  17176. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA_W_ENC,
  17177. hashEnc, (int)sizeof(hashEnc), out, (word32)modLen, key, keyLen);
  17178. if (ret != 0)
  17179. return WC_TEST_RET_ENC_EC(ret);
  17180. #else
  17181. (void)hash;
  17182. (void)hashEnc;
  17183. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  17184. return 0;
  17185. }
  17186. #endif /* !NO_SIG_WRAPPER */
  17187. #ifdef WC_RSA_NONBLOCK
  17188. static wc_test_ret_t rsa_nb_test(RsaKey* key, const byte* in, word32 inLen, byte* out,
  17189. word32 outSz, byte* plain, word32 plainSz, WC_RNG* rng)
  17190. {
  17191. wc_test_ret_t ret = 0;
  17192. int count;
  17193. int signSz = 0;
  17194. RsaNb nb;
  17195. byte* inlinePlain = NULL;
  17196. /* Enable non-blocking RSA mode - provide context */
  17197. ret = wc_RsaSetNonBlock(key, &nb);
  17198. if (ret != 0)
  17199. return ret;
  17200. #ifdef WC_RSA_NONBLOCK_TIME
  17201. /* Enable time based RSA blocking. 8 microseconds max (3.1GHz) */
  17202. ret = wc_RsaSetNonBlockTime(key, 8, 3100);
  17203. if (ret != 0)
  17204. return ret;
  17205. #endif
  17206. count = 0;
  17207. do {
  17208. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, rng);
  17209. count++; /* track number of would blocks */
  17210. if (ret == FP_WOULDBLOCK) {
  17211. /* do "other" work here */
  17212. }
  17213. } while (ret == FP_WOULDBLOCK);
  17214. if (ret < 0) {
  17215. return ret;
  17216. }
  17217. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17218. printf("RSA non-block sign: %d times\n", count);
  17219. #endif
  17220. signSz = ret;
  17221. /* Test non-blocking verify */
  17222. XMEMSET(plain, 0, plainSz);
  17223. count = 0;
  17224. do {
  17225. ret = wc_RsaSSL_Verify(out, (word32)signSz, plain, plainSz, key);
  17226. count++; /* track number of would blocks */
  17227. if (ret == FP_WOULDBLOCK) {
  17228. /* do "other" work here */
  17229. }
  17230. } while (ret == FP_WOULDBLOCK);
  17231. if (ret < 0) {
  17232. return ret;
  17233. }
  17234. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17235. printf("RSA non-block verify: %d times\n", count);
  17236. #endif
  17237. if (signSz == ret && XMEMCMP(plain, in, (size_t)ret)) {
  17238. return SIG_VERIFY_E;
  17239. }
  17240. /* Test inline non-blocking verify */
  17241. count = 0;
  17242. do {
  17243. ret = wc_RsaSSL_VerifyInline(out, (word32)signSz, &inlinePlain, key);
  17244. count++; /* track number of would blocks */
  17245. if (ret == FP_WOULDBLOCK) {
  17246. /* do "other" work here */
  17247. }
  17248. } while (ret == FP_WOULDBLOCK);
  17249. if (ret < 0) {
  17250. return ret;
  17251. }
  17252. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  17253. printf("RSA non-block inline verify: %d times\n", count);
  17254. #endif
  17255. if (signSz == ret && XMEMCMP(inlinePlain, in, (size_t)ret)) {
  17256. return SIG_VERIFY_E;
  17257. }
  17258. /* Disabling non-block RSA mode */
  17259. ret = wc_RsaSetNonBlock(key, NULL);
  17260. (void)count;
  17261. return 0;
  17262. }
  17263. #endif
  17264. #if !defined(NO_ASN)
  17265. static wc_test_ret_t rsa_decode_test(RsaKey* keyPub)
  17266. {
  17267. wc_test_ret_t ret;
  17268. word32 inSz;
  17269. word32 inOutIdx;
  17270. WOLFSSL_SMALL_STACK_STATIC const byte n[2] = { 0x00, 0x23 };
  17271. WOLFSSL_SMALL_STACK_STATIC const byte e[2] = { 0x00, 0x03 };
  17272. WOLFSSL_SMALL_STACK_STATIC const byte good[] = { 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1,
  17273. 0x03 };
  17274. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgId[] = {
  17275. 0x30, 0x18, 0x30, 0x16,
  17276. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17277. 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17278. WOLFSSL_SMALL_STACK_STATIC const byte goodAlgIdNull[] = {
  17279. 0x30, 0x1a, 0x30, 0x18,
  17280. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17281. 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17282. 0x02, 0x1, 0x03 };
  17283. WOLFSSL_SMALL_STACK_STATIC const byte badAlgIdNull[] = {
  17284. 0x30, 0x1b, 0x30, 0x19,
  17285. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17286. 0x05, 0x01, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23,
  17287. 0x02, 0x1, 0x03 };
  17288. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitString[] = {
  17289. 0x30, 0x18, 0x30, 0x16,
  17290. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17291. 0x04, 0x09, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17292. WOLFSSL_SMALL_STACK_STATIC const byte badBitStringLen[] = {
  17293. 0x30, 0x18, 0x30, 0x16,
  17294. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17295. 0x03, 0x0a, 0x00, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17296. WOLFSSL_SMALL_STACK_STATIC const byte badNoSeq[] = {
  17297. 0x30, 0x16, 0x30, 0x14,
  17298. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17299. 0x07, 0x00, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17300. WOLFSSL_SMALL_STACK_STATIC const byte badNoObj[] = {
  17301. 0x30, 0x0f, 0x30, 0x0d, 0x05, 0x00, 0x03, 0x09, 0x00, 0x30, 0x06,
  17302. 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17303. WOLFSSL_SMALL_STACK_STATIC const byte badIntN[] = {
  17304. 0x30, 0x06, 0x02, 0x05, 0x23, 0x02, 0x1, 0x03 };
  17305. WOLFSSL_SMALL_STACK_STATIC const byte badNotIntE[] = {
  17306. 0x30, 0x06, 0x02, 0x01, 0x23, 0x04, 0x1, 0x03 };
  17307. WOLFSSL_SMALL_STACK_STATIC const byte badLength[] = {
  17308. 0x30, 0x04, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17309. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrNoZero[] = {
  17310. 0x30, 0x17, 0x30, 0x15,
  17311. 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
  17312. 0x03, 0x08, 0x30, 0x06, 0x02, 0x01, 0x23, 0x02, 0x1, 0x03 };
  17313. ret = wc_InitRsaKey(keyPub, NULL);
  17314. if (ret != 0)
  17315. return WC_TEST_RET_ENC_EC(ret);
  17316. /* Parameter Validation testing. */
  17317. ret = wc_RsaPublicKeyDecodeRaw(NULL, sizeof(n), e, sizeof(e), keyPub);
  17318. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17319. ret = WC_TEST_RET_ENC_EC(ret);
  17320. goto done;
  17321. }
  17322. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), NULL, sizeof(e), keyPub);
  17323. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17324. ret = WC_TEST_RET_ENC_EC(ret);
  17325. goto done;
  17326. }
  17327. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), NULL);
  17328. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17329. ret = WC_TEST_RET_ENC_EC(ret);
  17330. goto done;
  17331. }
  17332. ret = wc_RsaPublicKeyDecodeRaw(n, (word32)-1, e, sizeof(e), keyPub);
  17333. #if defined(USE_INTEGER_HEAP_MATH)
  17334. if (ret != 0)
  17335. #else
  17336. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17337. #endif
  17338. {
  17339. ret = WC_TEST_RET_ENC_EC(ret);
  17340. goto done;
  17341. }
  17342. wc_FreeRsaKey(keyPub);
  17343. ret = wc_InitRsaKey(keyPub, NULL);
  17344. if (ret != 0)
  17345. return WC_TEST_RET_ENC_EC(ret);
  17346. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, (word32)-1, keyPub);
  17347. #if defined(USE_INTEGER_HEAP_MATH)
  17348. if (ret != 0)
  17349. #else
  17350. if (ret != WC_NO_ERR_TRACE(ASN_GETINT_E))
  17351. #endif
  17352. {
  17353. ret = WC_TEST_RET_ENC_EC(ret);
  17354. goto done;
  17355. }
  17356. wc_FreeRsaKey(keyPub);
  17357. ret = wc_InitRsaKey(keyPub, NULL);
  17358. if (ret != 0)
  17359. return WC_TEST_RET_ENC_EC(ret);
  17360. /* Use API. */
  17361. ret = wc_RsaPublicKeyDecodeRaw(n, sizeof(n), e, sizeof(e), keyPub);
  17362. if (ret != 0) {
  17363. ret = WC_TEST_RET_ENC_EC(ret);
  17364. goto done;
  17365. }
  17366. wc_FreeRsaKey(keyPub);
  17367. ret = wc_InitRsaKey(keyPub, NULL);
  17368. if (ret != 0)
  17369. return WC_TEST_RET_ENC_EC(ret);
  17370. /* Parameter Validation testing. */
  17371. inSz = sizeof(good);
  17372. ret = wc_RsaPublicKeyDecode(NULL, &inOutIdx, keyPub, inSz);
  17373. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17374. ret = WC_TEST_RET_ENC_EC(ret);
  17375. goto done;
  17376. }
  17377. ret = wc_RsaPublicKeyDecode(good, NULL, keyPub, inSz);
  17378. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17379. ret = WC_TEST_RET_ENC_EC(ret);
  17380. goto done;
  17381. }
  17382. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  17383. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  17384. ret = WC_TEST_RET_ENC_EC(ret);
  17385. goto done;
  17386. }
  17387. /* Use good data and offset to bad data. */
  17388. inOutIdx = 2;
  17389. inSz = sizeof(good) - inOutIdx;
  17390. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17391. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17392. ret = WC_TEST_RET_ENC_EC(ret);
  17393. goto done;
  17394. }
  17395. inOutIdx = 2;
  17396. inSz = sizeof(goodAlgId) - inOutIdx;
  17397. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17398. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17399. ret = WC_TEST_RET_ENC_EC(ret);
  17400. goto done;
  17401. }
  17402. inOutIdx = 2;
  17403. inSz = sizeof(goodAlgId);
  17404. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17405. #ifndef WOLFSSL_NO_DECODE_EXTRA
  17406. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17407. #else
  17408. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E))
  17409. #endif
  17410. {
  17411. ret = WC_TEST_RET_ENC_EC(ret);
  17412. goto done;
  17413. }
  17414. /* Try different bad data. */
  17415. inSz = sizeof(badAlgIdNull);
  17416. inOutIdx = 0;
  17417. ret = wc_RsaPublicKeyDecode(badAlgIdNull, &inOutIdx, keyPub, inSz);
  17418. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E)) {
  17419. ret = WC_TEST_RET_ENC_EC(ret);
  17420. goto done;
  17421. }
  17422. inSz = sizeof(badNotBitString);
  17423. inOutIdx = 0;
  17424. ret = wc_RsaPublicKeyDecode(badNotBitString, &inOutIdx, keyPub, inSz);
  17425. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E)) {
  17426. ret = WC_TEST_RET_ENC_EC(ret);
  17427. goto done;
  17428. }
  17429. inSz = sizeof(badBitStringLen);
  17430. inOutIdx = 0;
  17431. ret = wc_RsaPublicKeyDecode(badBitStringLen, &inOutIdx, keyPub, inSz);
  17432. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17433. ret = WC_TEST_RET_ENC_EC(ret);
  17434. goto done;
  17435. }
  17436. inSz = sizeof(badNoSeq);
  17437. inOutIdx = 0;
  17438. ret = wc_RsaPublicKeyDecode(badNoSeq, &inOutIdx, keyPub, inSz);
  17439. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  17440. ret = WC_TEST_RET_ENC_EC(ret);
  17441. goto done;
  17442. }
  17443. inSz = sizeof(badNoObj);
  17444. inOutIdx = 0;
  17445. ret = wc_RsaPublicKeyDecode(badNoObj, &inOutIdx, keyPub, inSz);
  17446. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E) &&
  17447. ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E))
  17448. {
  17449. ret = WC_TEST_RET_ENC_EC(ret);
  17450. goto done;
  17451. }
  17452. inSz = sizeof(badIntN);
  17453. inOutIdx = 0;
  17454. ret = wc_RsaPublicKeyDecode(badIntN, &inOutIdx, keyPub, inSz);
  17455. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17456. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17457. {
  17458. ret = WC_TEST_RET_ENC_EC(ret);
  17459. goto done;
  17460. }
  17461. inSz = sizeof(badNotIntE);
  17462. inOutIdx = 0;
  17463. ret = wc_RsaPublicKeyDecode(badNotIntE, &inOutIdx, keyPub, inSz);
  17464. if (ret != WC_NO_ERR_TRACE(ASN_RSA_KEY_E) &&
  17465. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17466. {
  17467. ret = WC_TEST_RET_ENC_EC(ret);
  17468. goto done;
  17469. }
  17470. /* TODO: Shouldn't pass as the sequence length is too small. */
  17471. inSz = sizeof(badLength);
  17472. inOutIdx = 0;
  17473. ret = wc_RsaPublicKeyDecode(badLength, &inOutIdx, keyPub, inSz);
  17474. #ifndef WOLFSSL_ASN_TEMPLATE
  17475. if (ret != 0)
  17476. #else
  17477. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17478. #endif
  17479. {
  17480. ret = WC_TEST_RET_ENC_EC(ret);
  17481. goto done;
  17482. }
  17483. /* TODO: Shouldn't ignore object id's data. */
  17484. wc_FreeRsaKey(keyPub);
  17485. ret = wc_InitRsaKey(keyPub, NULL);
  17486. if (ret != 0)
  17487. return WC_TEST_RET_ENC_EC(ret);
  17488. inSz = sizeof(badBitStrNoZero);
  17489. inOutIdx = 0;
  17490. ret = wc_RsaPublicKeyDecode(badBitStrNoZero, &inOutIdx, keyPub, inSz);
  17491. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  17492. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  17493. {
  17494. ret = WC_TEST_RET_ENC_EC(ret);
  17495. goto done;
  17496. }
  17497. wc_FreeRsaKey(keyPub);
  17498. ret = wc_InitRsaKey(keyPub, NULL);
  17499. if (ret != 0)
  17500. return WC_TEST_RET_ENC_EC(ret);
  17501. /* Valid data cases. */
  17502. inSz = sizeof(good);
  17503. inOutIdx = 0;
  17504. ret = wc_RsaPublicKeyDecode(good, &inOutIdx, keyPub, inSz);
  17505. if (ret != 0) {
  17506. ret = WC_TEST_RET_ENC_EC(ret);
  17507. goto done;
  17508. }
  17509. if (inOutIdx != inSz) {
  17510. ret = WC_TEST_RET_ENC_NC;
  17511. goto done;
  17512. }
  17513. wc_FreeRsaKey(keyPub);
  17514. ret = wc_InitRsaKey(keyPub, NULL);
  17515. if (ret != 0)
  17516. return WC_TEST_RET_ENC_EC(ret);
  17517. inSz = sizeof(goodAlgId);
  17518. inOutIdx = 0;
  17519. ret = wc_RsaPublicKeyDecode(goodAlgId, &inOutIdx, keyPub, inSz);
  17520. if (ret != 0) {
  17521. ret = WC_TEST_RET_ENC_EC(ret);
  17522. goto done;
  17523. }
  17524. if (inOutIdx != inSz) {
  17525. ret = WC_TEST_RET_ENC_NC;
  17526. goto done;
  17527. }
  17528. wc_FreeRsaKey(keyPub);
  17529. ret = wc_InitRsaKey(keyPub, NULL);
  17530. if (ret != 0)
  17531. return WC_TEST_RET_ENC_EC(ret);
  17532. inSz = sizeof(goodAlgIdNull);
  17533. inOutIdx = 0;
  17534. ret = wc_RsaPublicKeyDecode(goodAlgIdNull, &inOutIdx, keyPub, inSz);
  17535. if (ret != 0) {
  17536. ret = WC_TEST_RET_ENC_EC(ret);
  17537. goto done;
  17538. }
  17539. if (inOutIdx != inSz) {
  17540. ret = WC_TEST_RET_ENC_NC;
  17541. goto done;
  17542. }
  17543. done:
  17544. wc_FreeRsaKey(keyPub);
  17545. return ret;
  17546. }
  17547. #endif
  17548. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  17549. /* Need to create known good signatures to test with this. */
  17550. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  17551. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  17552. static wc_test_ret_t rsa_pss_test(WC_RNG* rng, RsaKey* key)
  17553. {
  17554. byte digest[WC_MAX_DIGEST_SIZE];
  17555. wc_test_ret_t ret = 0;
  17556. const char inStr[] = TEST_STRING;
  17557. word32 inLen = (word32)TEST_STRING_SZ;
  17558. word32 outSz;
  17559. word32 plainSz;
  17560. word32 digestSz;
  17561. int i, j;
  17562. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17563. int k, l;
  17564. #endif
  17565. #ifndef WOLFSSL_SE050
  17566. int len;
  17567. #endif
  17568. byte* plain;
  17569. int mgf[] = {
  17570. #ifndef NO_SHA
  17571. WC_MGF1SHA1,
  17572. #endif
  17573. #ifdef WOLFSSL_SHA224
  17574. WC_MGF1SHA224,
  17575. #endif
  17576. WC_MGF1SHA256,
  17577. #ifdef WOLFSSL_SHA384
  17578. WC_MGF1SHA384,
  17579. #endif
  17580. #ifdef WOLFSSL_SHA512
  17581. WC_MGF1SHA512
  17582. #endif
  17583. };
  17584. enum wc_HashType hash[] = {
  17585. #ifndef NO_SHA
  17586. WC_HASH_TYPE_SHA,
  17587. #endif
  17588. #ifdef WOLFSSL_SHA224
  17589. WC_HASH_TYPE_SHA224,
  17590. #endif
  17591. WC_HASH_TYPE_SHA256,
  17592. #ifdef WOLFSSL_SHA384
  17593. WC_HASH_TYPE_SHA384,
  17594. #endif
  17595. #ifdef WOLFSSL_SHA512
  17596. WC_HASH_TYPE_SHA512,
  17597. #endif
  17598. };
  17599. WC_DECLARE_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17600. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17601. WC_DECLARE_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17602. WC_ALLOC_VAR(in, byte, RSA_TEST_BYTES, HEAP_HINT);
  17603. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17604. WC_ALLOC_VAR(sig, byte, RSA_TEST_BYTES, HEAP_HINT);
  17605. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17606. if (in == NULL || out == NULL || sig == NULL)
  17607. ERROR_OUT(MEMORY_E, exit_rsa_pss);
  17608. #endif
  17609. XMEMCPY(in, inStr, inLen);
  17610. /* Test all combinations of hash and MGF. */
  17611. for (j = 0; j < (int)(sizeof(hash)/sizeof(*hash)); j++) {
  17612. /* Calculate hash of message. */
  17613. ret = wc_Hash(hash[j], in, inLen, digest, sizeof(digest));
  17614. if (ret != 0)
  17615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17616. digestSz = (word32)wc_HashGetDigestSize(hash[j]);
  17617. #ifdef WOLFSSL_SE050
  17618. /* SE050 only supports MGF matched to same hash type */
  17619. i = j;
  17620. #else
  17621. for (i = 0; i < (int)(sizeof(mgf)/sizeof(*mgf)); i++) {
  17622. #endif
  17623. outSz = RSA_TEST_BYTES;
  17624. do {
  17625. #if defined(WOLFSSL_ASYNC_CRYPT)
  17626. ret = wc_AsyncWait(ret, &key->asyncDev,
  17627. WC_ASYNC_FLAG_CALL_AGAIN);
  17628. #endif
  17629. if (ret >= 0) {
  17630. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz,
  17631. hash[j], mgf[i], -1, key, rng);
  17632. }
  17633. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17634. if (ret <= 0)
  17635. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17636. outSz = (word32)ret;
  17637. XMEMCPY(sig, out, outSz);
  17638. plain = NULL;
  17639. TEST_SLEEP();
  17640. do {
  17641. #if defined(WOLFSSL_ASYNC_CRYPT)
  17642. ret = wc_AsyncWait(ret, &key->asyncDev,
  17643. WC_ASYNC_FLAG_CALL_AGAIN);
  17644. #endif
  17645. if (ret >= 0) {
  17646. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[j],
  17647. mgf[i], -1, key);
  17648. }
  17649. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17650. if (ret <= 0)
  17651. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17652. plainSz = (word32)ret;
  17653. TEST_SLEEP();
  17654. #if defined(HAVE_SELFTEST) && \
  17655. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17656. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17657. hash[j], -1);
  17658. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17659. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17660. hash[j], -1, 0);
  17661. #else
  17662. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz,
  17663. hash[j], -1, wc_RsaEncryptSize(key)*8, HEAP_HINT);
  17664. #endif
  17665. if (ret != 0)
  17666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17667. #ifdef RSA_PSS_TEST_WRONG_PARAMS
  17668. for (k = 0; k < (int)(sizeof(mgf)/sizeof(*mgf)); k++) {
  17669. for (l = 0; l < (int)(sizeof(hash)/sizeof(*hash)); l++) {
  17670. if (i == k && j == l)
  17671. continue;
  17672. XMEMCPY(sig, out, outSz);
  17673. do {
  17674. #if defined(WOLFSSL_ASYNC_CRYPT)
  17675. ret = wc_AsyncWait(ret, &key->asyncDev,
  17676. WC_ASYNC_FLAG_CALL_AGAIN);
  17677. #endif
  17678. if (ret >= 0) {
  17679. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz,
  17680. (byte**)&plain, hash[l], mgf[k], -1, key);
  17681. }
  17682. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17683. if (ret >= 0)
  17684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17685. }
  17686. }
  17687. #endif
  17688. #ifndef WOLFSSL_SE050
  17689. } /* end mgf for loop */
  17690. #endif
  17691. }
  17692. /* SE050 generates salts internally only of hash length */
  17693. #ifndef WOLFSSL_SE050
  17694. /* Test that a salt length of zero works. */
  17695. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17696. outSz = RSA_TEST_BYTES;
  17697. do {
  17698. #if defined(WOLFSSL_ASYNC_CRYPT)
  17699. ret = wc_AsyncWait(ret, &key->asyncDev,
  17700. WC_ASYNC_FLAG_CALL_AGAIN);
  17701. #endif
  17702. if (ret >= 0) {
  17703. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17704. mgf[0], 0, key, rng);
  17705. }
  17706. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17707. if (ret <= 0)
  17708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17709. outSz = (word32)ret;
  17710. TEST_SLEEP();
  17711. do {
  17712. #if defined(WOLFSSL_ASYNC_CRYPT)
  17713. ret = wc_AsyncWait(ret, &key->asyncDev,
  17714. WC_ASYNC_FLAG_CALL_AGAIN);
  17715. #endif
  17716. if (ret >= 0) {
  17717. ret = wc_RsaPSS_Verify_ex(out, outSz, sig, outSz, hash[0], mgf[0],
  17718. 0, key);
  17719. }
  17720. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17721. if (ret <= 0)
  17722. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17723. plainSz = (word32)ret;
  17724. TEST_SLEEP();
  17725. do {
  17726. #if defined(WOLFSSL_ASYNC_CRYPT)
  17727. ret = wc_AsyncWait(ret, &key->asyncDev,
  17728. WC_ASYNC_FLAG_CALL_AGAIN);
  17729. #endif
  17730. if (ret >= 0) {
  17731. #if defined(HAVE_SELFTEST) && \
  17732. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17733. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17734. hash[0], 0);
  17735. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17736. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, sig, plainSz,
  17737. hash[0], 0, 0);
  17738. #else
  17739. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, sig, plainSz,
  17740. hash[0], 0, 0, HEAP_HINT);
  17741. #endif
  17742. }
  17743. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17744. if (ret != 0)
  17745. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17746. XMEMCPY(sig, out, outSz);
  17747. plain = NULL;
  17748. do {
  17749. #if defined(WOLFSSL_ASYNC_CRYPT)
  17750. ret = wc_AsyncWait(ret, &key->asyncDev,
  17751. WC_ASYNC_FLAG_CALL_AGAIN);
  17752. #endif
  17753. if (ret >= 0) {
  17754. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17755. 0, key);
  17756. }
  17757. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17758. if (ret <= 0)
  17759. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17760. plainSz = (word32)ret;
  17761. TEST_SLEEP();
  17762. #if defined(HAVE_SELFTEST) && \
  17763. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17764. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17765. hash[0], 0);
  17766. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17767. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17768. hash[0], 0, 0);
  17769. #else
  17770. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17771. 0, 0, HEAP_HINT);
  17772. #endif
  17773. if (ret != 0)
  17774. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17775. /* Test bad salt lengths in various APIs. */
  17776. digestSz = (word32)wc_HashGetDigestSize(hash[0]);
  17777. outSz = RSA_TEST_BYTES;
  17778. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17779. len = -2;
  17780. #else
  17781. len = -3;
  17782. #endif
  17783. do {
  17784. #if defined(WOLFSSL_ASYNC_CRYPT)
  17785. ret = wc_AsyncWait(ret, &key->asyncDev,
  17786. WC_ASYNC_FLAG_CALL_AGAIN);
  17787. #endif
  17788. if (ret >= 0) {
  17789. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17790. mgf[0], len, key, rng);
  17791. }
  17792. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17793. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17795. do {
  17796. #if defined(WOLFSSL_ASYNC_CRYPT)
  17797. ret = wc_AsyncWait(ret, &key->asyncDev,
  17798. WC_ASYNC_FLAG_CALL_AGAIN);
  17799. #endif
  17800. if (ret >= 0) {
  17801. ret = wc_RsaPSS_Sign_ex(digest, digestSz, out, outSz, hash[0],
  17802. mgf[0], (int)digestSz + 1, key, rng);
  17803. }
  17804. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17805. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17806. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17807. TEST_SLEEP();
  17808. do {
  17809. #if defined(WOLFSSL_ASYNC_CRYPT)
  17810. ret = wc_AsyncWait(ret, &key->asyncDev,
  17811. WC_ASYNC_FLAG_CALL_AGAIN);
  17812. #endif
  17813. if (ret >= 0) {
  17814. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0],
  17815. mgf[0], -2, key);
  17816. }
  17817. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17818. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17819. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17820. TEST_SLEEP();
  17821. do {
  17822. #if defined(WOLFSSL_ASYNC_CRYPT)
  17823. ret = wc_AsyncWait(ret, &key->asyncDev,
  17824. WC_ASYNC_FLAG_CALL_AGAIN);
  17825. #endif
  17826. if (ret >= 0) {
  17827. ret = wc_RsaPSS_VerifyInline_ex(sig, outSz, &plain, hash[0], mgf[0],
  17828. (int)digestSz + 1, key);
  17829. }
  17830. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17831. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17833. TEST_SLEEP();
  17834. #ifndef WOLFSSL_PSS_SALT_LEN_DISCOVER
  17835. len = -2;
  17836. #else
  17837. len = -3;
  17838. #endif
  17839. #if defined(HAVE_SELFTEST) && \
  17840. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17841. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17842. hash[0], len);
  17843. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17844. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17845. hash[0], len, 0);
  17846. #else
  17847. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17848. len, 0, HEAP_HINT);
  17849. #endif
  17850. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17851. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17852. #ifndef WOLFSSL_PSS_LONG_SALT
  17853. len = (int)(digestSz + 1);
  17854. #else
  17855. len = (int)(plainSz - digestSz - 1);
  17856. #endif
  17857. #if defined(HAVE_SELFTEST) && \
  17858. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2))
  17859. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17860. hash[0], len);
  17861. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17862. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17863. #elif defined(HAVE_SELFTEST) && (HAVE_SELFTEST_VERSION == 2)
  17864. ret = wc_RsaPSS_CheckPadding_ex(digest, digestSz, plain, plainSz,
  17865. hash[0], len, 0);
  17866. if (ret != WC_NO_ERR_TRACE(BAD_PADDING_E))
  17867. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17868. #else
  17869. ret = wc_RsaPSS_CheckPadding_ex2(digest, digestSz, plain, plainSz, hash[0],
  17870. len, 0, HEAP_HINT);
  17871. if (ret != WC_NO_ERR_TRACE(PSS_SALTLEN_E))
  17872. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_pss);
  17873. #endif
  17874. ret = 0;
  17875. #endif /* WOLFSSL_SE050 */
  17876. exit_rsa_pss:
  17877. WC_FREE_VAR(sig, HEAP_HINT);
  17878. WC_FREE_VAR(in, HEAP_HINT);
  17879. WC_FREE_VAR(out, HEAP_HINT);
  17880. return ret;
  17881. }
  17882. #endif /* !WOLFSSL_RSA_VERIFY_ONLY && !WOLFSSL_RSA_PUBLIC_ONLY */
  17883. #endif
  17884. #ifdef WC_RSA_NO_PADDING
  17885. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
  17886. {
  17887. WC_RNG rng;
  17888. byte* tmp = NULL;
  17889. size_t bytes;
  17890. wc_test_ret_t ret;
  17891. word32 inLen = 0;
  17892. word32 idx = 0;
  17893. word32 outSz = RSA_TEST_BYTES;
  17894. word32 plainSz = RSA_TEST_BYTES;
  17895. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  17896. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  17897. !defined(NO_FILESYSTEM)
  17898. XFILE file;
  17899. #endif
  17900. WC_DECLARE_VAR(key, RsaKey, 1, HEAP_HINT);
  17901. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17902. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17903. WC_ALLOC_VAR(key, RsaKey, 1, HEAP_HINT);
  17904. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  17905. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  17906. WOLFSSL_ENTER("rsa_no_pad_test");
  17907. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  17908. if (key == NULL || out == NULL || plain == NULL)
  17909. ERROR_OUT(MEMORY_E, exit_rsa_nopadding);
  17910. #endif
  17911. /* initialize stack structures */
  17912. XMEMSET(&rng, 0, sizeof(rng));
  17913. XMEMSET(key, 0, sizeof(RsaKey));
  17914. #ifdef USE_CERT_BUFFERS_1024
  17915. bytes = (size_t)sizeof_client_key_der_1024;
  17916. if (bytes < (size_t)sizeof_client_cert_der_1024)
  17917. bytes = (size_t)sizeof_client_cert_der_1024;
  17918. #elif defined(USE_CERT_BUFFERS_2048)
  17919. bytes = (size_t)sizeof_client_key_der_2048;
  17920. if (bytes < (size_t)sizeof_client_cert_der_2048)
  17921. bytes = (size_t)sizeof_client_cert_der_2048;
  17922. #else
  17923. bytes = FOURK_BUF;
  17924. #endif
  17925. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  17926. if (tmp == NULL
  17927. #ifdef WOLFSSL_ASYNC_CRYPT
  17928. || out == NULL || plain == NULL
  17929. #endif
  17930. ) {
  17931. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17932. }
  17933. #ifdef USE_CERT_BUFFERS_1024
  17934. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  17935. #elif defined(USE_CERT_BUFFERS_2048)
  17936. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  17937. #elif defined(USE_CERT_BUFFERS_3072)
  17938. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  17939. #elif defined(USE_CERT_BUFFERS_4096)
  17940. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  17941. #elif !defined(NO_FILESYSTEM)
  17942. file = XFOPEN(clientKey, "rb");
  17943. if (!file) {
  17944. err_sys("can't open clientKey, Please run from wolfSSL home dir",
  17945. WC_TEST_RET_ENC_ERRNO);
  17946. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17947. }
  17948. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  17949. XFCLOSE(file);
  17950. if (bytes == 0)
  17951. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_nopadding);
  17952. #else
  17953. /* No key to use. */
  17954. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17955. #endif /* USE_CERT_BUFFERS */
  17956. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  17957. if (ret != 0) {
  17958. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17959. }
  17960. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  17961. if (ret != 0) {
  17962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17963. }
  17964. /* after loading in key use tmp as the test buffer */
  17965. #ifndef HAVE_FIPS
  17966. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  17967. #else
  17968. ret = wc_InitRng(&rng);
  17969. #endif
  17970. if (ret != 0) {
  17971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17972. }
  17973. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  17974. inLen = (word32)wc_RsaEncryptSize(key);
  17975. outSz = inLen;
  17976. plainSz = inLen;
  17977. XMEMSET(tmp, 7, inLen);
  17978. do {
  17979. #if defined(WOLFSSL_ASYNC_CRYPT)
  17980. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17981. #endif
  17982. if (ret >= 0) {
  17983. ret = wc_RsaDirect(tmp, inLen, out, &outSz, key,
  17984. RSA_PRIVATE_ENCRYPT, &rng);
  17985. }
  17986. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  17987. if (ret <= 0) {
  17988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  17989. }
  17990. /* encrypted result should not be the same as input */
  17991. if (XMEMCMP(out, tmp, inLen) == 0) {
  17992. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  17993. }
  17994. TEST_SLEEP();
  17995. /* decrypt with public key and compare result */
  17996. do {
  17997. #if defined(WOLFSSL_ASYNC_CRYPT)
  17998. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  17999. #endif
  18000. if (ret >= 0) {
  18001. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key,
  18002. RSA_PUBLIC_DECRYPT, &rng);
  18003. }
  18004. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18005. if (ret <= 0) {
  18006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18007. }
  18008. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18009. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18010. }
  18011. TEST_SLEEP();
  18012. #endif
  18013. #ifdef WC_RSA_BLINDING
  18014. ret = wc_RsaSetRNG(NULL, &rng);
  18015. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18016. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18017. }
  18018. ret = wc_RsaSetRNG(key, &rng);
  18019. if (ret < 0) {
  18020. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18021. }
  18022. #endif
  18023. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18024. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18025. do {
  18026. #if defined(WOLFSSL_ASYNC_CRYPT)
  18027. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18028. #endif
  18029. if (ret >= 0) {
  18030. ret = wc_RsaPublicEncrypt_ex(tmp, inLen, out, outSz, key, &rng,
  18031. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18032. }
  18033. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18034. if (ret < 0) {
  18035. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18036. }
  18037. TEST_SLEEP();
  18038. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18039. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18040. do {
  18041. #if defined(WOLFSSL_ASYNC_CRYPT)
  18042. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18043. #endif
  18044. if (ret >= 0) {
  18045. ret = wc_RsaPrivateDecrypt_ex(out, outSz, plain, plainSz, key,
  18046. WC_RSA_NO_PAD, WC_HASH_TYPE_NONE, WC_MGF1NONE, NULL, 0);
  18047. }
  18048. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18049. if (ret < 0) {
  18050. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18051. }
  18052. if (XMEMCMP(plain, tmp, inLen) != 0) {
  18053. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
  18054. }
  18055. TEST_SLEEP();
  18056. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18057. /* test some bad arguments */
  18058. ret = wc_RsaDirect(out, outSz, plain, &plainSz, key, -1,
  18059. &rng);
  18060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18062. }
  18063. ret = wc_RsaDirect(out, outSz, plain, &plainSz, NULL, RSA_PUBLIC_DECRYPT,
  18064. &rng);
  18065. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18067. }
  18068. ret = wc_RsaDirect(out, outSz, NULL, &plainSz, key, RSA_PUBLIC_DECRYPT,
  18069. &rng);
  18070. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || plainSz != inLen) {
  18071. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18072. }
  18073. ret = wc_RsaDirect(out, outSz - 10, plain, &plainSz, key,
  18074. RSA_PUBLIC_DECRYPT, &rng);
  18075. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  18076. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_nopadding);
  18077. }
  18078. /* if making it to this point of code without hitting an ERROR_OUT then
  18079. * all tests have passed */
  18080. ret = 0;
  18081. exit_rsa_nopadding:
  18082. wc_FreeRsaKey(key);
  18083. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18084. WC_FREE_VAR(key, HEAP_HINT);
  18085. WC_FREE_VAR(out, HEAP_HINT);
  18086. WC_FREE_VAR(plain, HEAP_HINT);
  18087. wc_FreeRng(&rng);
  18088. return ret;
  18089. }
  18090. #endif /* WC_RSA_NO_PADDING */
  18091. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  18092. static wc_test_ret_t rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
  18093. {
  18094. byte* tmp = NULL;
  18095. size_t bytes;
  18096. wc_test_ret_t ret;
  18097. word32 inLen = 0;
  18098. #ifndef NO_ASN
  18099. word32 idx = 0;
  18100. #endif
  18101. word32 outSz = RSA_TEST_BYTES;
  18102. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18103. word32 plainSz = RSA_TEST_BYTES;
  18104. #endif
  18105. #if !defined(USE_CERT_BUFFERS_2048) && !defined(USE_CERT_BUFFERS_3072) && \
  18106. !defined(USE_CERT_BUFFERS_4096) && !defined(NO_FILESYSTEM)
  18107. XFILE file;
  18108. #endif
  18109. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18110. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18111. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18112. #endif
  18113. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18114. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18115. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18116. #endif
  18117. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18118. if (out == NULL
  18119. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18120. || plain == NULL
  18121. #endif
  18122. ) {
  18123. ERROR_OUT(MEMORY_E, exit_rsa_even_mod);
  18124. }
  18125. #endif
  18126. #if defined(USE_CERT_BUFFERS_2048)
  18127. bytes = (size_t)sizeof_client_key_der_2048;
  18128. if (bytes < (size_t)sizeof_client_cert_der_2048)
  18129. bytes = (size_t)sizeof_client_cert_der_2048;
  18130. #else
  18131. bytes = FOURK_BUF;
  18132. #endif
  18133. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18134. if (tmp == NULL
  18135. #ifdef WOLFSSL_ASYNC_CRYPT
  18136. || out == NULL || plain == NULL
  18137. #endif
  18138. ) {
  18139. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18140. }
  18141. #if defined(USE_CERT_BUFFERS_2048)
  18142. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  18143. #elif defined(USE_CERT_BUFFERS_3072)
  18144. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  18145. #elif defined(USE_CERT_BUFFERS_4096)
  18146. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  18147. #elif !defined(NO_FILESYSTEM)
  18148. file = XFOPEN(clientKey, "rb");
  18149. if (!file) {
  18150. err_sys("can't open ./certs/client-key.der, "
  18151. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  18152. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18153. }
  18154. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  18155. XFCLOSE(file);
  18156. if (bytes == 0)
  18157. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa_even_mod);
  18158. #else
  18159. /* No key to use. */
  18160. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_even_mod);
  18161. #endif /* USE_CERT_BUFFERS */
  18162. #ifndef NO_ASN
  18163. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  18164. if (ret != 0) {
  18165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18166. }
  18167. #else
  18168. #ifdef USE_CERT_BUFFERS_2048
  18169. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  18170. if (ret != 0) {
  18171. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18172. }
  18173. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  18174. if (ret != 0) {
  18175. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18176. }
  18177. #ifndef NO_SIG_WRAPPER
  18178. modLen = 2048;
  18179. #endif
  18180. #else
  18181. #error Not supported yet!
  18182. #endif
  18183. #endif
  18184. key->n.dp[0] &= (mp_digit)-2;
  18185. if (ret != 0) {
  18186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18187. }
  18188. /* after loading in key use tmp as the test buffer */
  18189. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  18190. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM))) && \
  18191. !defined(WOLFSSL_XILINX_CRYPT)
  18192. /* The ARM64_ASM code that was FIPS validated did not return these expected
  18193. * failure codes. These tests cases were added after the assembly was
  18194. * in-lined in the module and validated, these tests will be available in
  18195. * the 140-3 module */
  18196. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18197. inLen = 32;
  18198. outSz = wc_RsaEncryptSize(key);
  18199. XMEMSET(tmp, 7, plainSz);
  18200. ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
  18201. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18202. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18203. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18204. {
  18205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18206. }
  18207. ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
  18208. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18209. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18210. {
  18211. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18212. }
  18213. #endif
  18214. #ifdef WC_RSA_BLINDING
  18215. ret = wc_RsaSetRNG(key, rng);
  18216. if (ret < 0) {
  18217. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18218. }
  18219. #endif
  18220. /* test encrypt and decrypt using WC_RSA_NO_PAD */
  18221. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  18222. ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
  18223. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18224. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  18225. {
  18226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18227. }
  18228. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  18229. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18230. ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
  18231. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  18232. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  18233. ret != WC_NO_ERR_TRACE(MP_INVMOD_E))
  18234. {
  18235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa_even_mod);
  18236. }
  18237. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18238. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  18239. /* if making it to this point of code without hitting an ERROR_OUT then
  18240. * all tests have passed */
  18241. ret = 0;
  18242. exit_rsa_even_mod:
  18243. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18244. WC_FREE_VAR(out, HEAP_HINT);
  18245. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18246. WC_FREE_VAR(plain, HEAP_HINT);
  18247. #endif
  18248. (void)out;
  18249. (void)outSz;
  18250. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18251. (void)plain;
  18252. (void)plainSz;
  18253. #endif
  18254. (void)inLen;
  18255. (void)rng;
  18256. return ret;
  18257. }
  18258. #endif /* WOLFSSL_HAVE_SP_RSA */
  18259. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  18260. static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng, byte* tmp)
  18261. {
  18262. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18263. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18264. #ifdef WOLFSSL_TEST_CERT
  18265. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18266. #endif
  18267. #else
  18268. RsaKey caKey[1];
  18269. #ifdef WOLFSSL_TEST_CERT
  18270. DecodedCert decode[1];
  18271. #endif
  18272. #endif
  18273. byte* der = NULL;
  18274. wc_test_ret_t ret;
  18275. Cert* myCert = NULL;
  18276. int certSz;
  18277. size_t bytes3;
  18278. word32 idx3 = 0;
  18279. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  18280. XFILE file3;
  18281. #endif
  18282. #if defined(WOLFSSL_ALT_NAMES) && !defined(NO_ASN_TIME)
  18283. struct tm beforeTime;
  18284. struct tm afterTime;
  18285. #endif
  18286. const byte mySerial[8] = {1,2,3,4,5,6,7,8};
  18287. (void)keypub;
  18288. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18289. if (caKey == NULL)
  18290. ERROR_OUT(MEMORY_E, exit_rsa);
  18291. #ifdef WOLFSSL_TEST_CERT
  18292. if (decode == NULL)
  18293. ERROR_OUT(MEMORY_E, exit_rsa);
  18294. #endif
  18295. #endif
  18296. XMEMSET(caKey, 0, sizeof *caKey);
  18297. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18298. if (der == NULL) {
  18299. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18300. }
  18301. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18302. if (myCert == NULL) {
  18303. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18304. }
  18305. /* self signed */
  18306. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18307. if (ret != 0) {
  18308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18309. }
  18310. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18311. XMEMCPY(myCert->serial, mySerial, sizeof(mySerial));
  18312. myCert->serialSz = (int)sizeof(mySerial);
  18313. myCert->isCA = 1;
  18314. #ifndef NO_SHA256
  18315. myCert->sigType = CTC_SHA256wRSA;
  18316. #else
  18317. myCert->sigType = CTC_SHAwRSA;
  18318. #endif
  18319. #ifdef WOLFSSL_CERT_EXT
  18320. /* add Policies */
  18321. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18322. CTC_MAX_CERTPOL_SZ);
  18323. XSTRNCPY(myCert->certPolicies[1], "1.2.840.113549.1.9.16.6.5",
  18324. CTC_MAX_CERTPOL_SZ);
  18325. myCert->certPoliciesNb = 2;
  18326. /* add SKID from the Public Key */
  18327. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, keypub, NULL);
  18328. if (ret != 0) {
  18329. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18330. }
  18331. /* add AKID from the Public Key */
  18332. ret = wc_SetAuthKeyIdFromPublicKey(myCert, keypub, NULL);
  18333. if (ret != 0) {
  18334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18335. }
  18336. /* add Key Usage */
  18337. ret = wc_SetKeyUsage(myCert,"cRLSign,keyCertSign");
  18338. if (ret != 0) {
  18339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18340. }
  18341. #ifdef WOLFSSL_EKU_OID
  18342. {
  18343. const char unique[] = "2.16.840.1.111111.100.1.10.1";
  18344. ret = wc_SetExtKeyUsageOID(myCert, unique, sizeof(unique), 0,
  18345. HEAP_HINT);
  18346. if (ret != 0) {
  18347. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18348. }
  18349. }
  18350. #endif /* WOLFSSL_EKU_OID */
  18351. #endif /* WOLFSSL_CERT_EXT */
  18352. do {
  18353. #if defined(WOLFSSL_ASYNC_CRYPT)
  18354. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18355. #endif
  18356. if (ret >= 0) {
  18357. ret = wc_MakeSelfCert(myCert, der, FOURK_BUF, key, rng);
  18358. }
  18359. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18360. if (ret < 0) {
  18361. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18362. }
  18363. certSz = (int)ret;
  18364. #ifdef WOLFSSL_TEST_CERT
  18365. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18366. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18367. if (ret != 0) {
  18368. FreeDecodedCert(decode);
  18369. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18370. }
  18371. FreeDecodedCert(decode);
  18372. #endif
  18373. ret = SaveDerAndPem(der, certSz, certDerFile, certPemFile,
  18374. CERT_TYPE);
  18375. if (ret != 0) {
  18376. goto exit_rsa;
  18377. }
  18378. /* Setup Certificate */
  18379. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18380. if (ret < 0) {
  18381. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18382. }
  18383. #if defined(WOLFSSL_ALT_NAMES) || defined(HAVE_PKCS7)
  18384. /* Get CA Cert for testing */
  18385. #ifdef USE_CERT_BUFFERS_1024
  18386. XMEMCPY(tmp, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  18387. bytes3 = sizeof_ca_cert_der_1024;
  18388. #elif defined(USE_CERT_BUFFERS_2048)
  18389. XMEMCPY(tmp, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  18390. bytes3 = sizeof_ca_cert_der_2048;
  18391. #else
  18392. file3 = XFOPEN(rsaCaCertDerFile, "rb");
  18393. if (!file3) {
  18394. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18395. }
  18396. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18397. XFCLOSE(file3);
  18398. if (bytes3 == 0)
  18399. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18400. #endif /* USE_CERT_BUFFERS */
  18401. #if defined(WOLFSSL_ALT_NAMES)
  18402. #if !defined(NO_FILESYSTEM) && !defined(USE_CERT_BUFFERS_1024) && \
  18403. !defined(USE_CERT_BUFFERS_2048) && !defined(NO_ASN)
  18404. ret = wc_SetAltNames(myCert, rsaCaCertFile);
  18405. if (ret != 0)
  18406. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18407. #endif
  18408. /* get alt names from der */
  18409. ret = wc_SetAltNamesBuffer(myCert, tmp, (int)bytes3);
  18410. if (ret != 0)
  18411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18412. /* get dates from der */
  18413. ret = wc_SetDatesBuffer(myCert, tmp, (int)bytes3);
  18414. if (ret != 0)
  18415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18416. #ifndef NO_ASN_TIME
  18417. ret = wc_GetCertDates(myCert, &beforeTime, &afterTime);
  18418. if (ret < 0)
  18419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18420. #endif
  18421. #endif /* WOLFSSL_ALT_NAMES */
  18422. #endif /* WOLFSSL_ALT_NAMES || HAVE_PKCS7 */
  18423. /* Get CA Key */
  18424. #ifdef USE_CERT_BUFFERS_1024
  18425. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18426. bytes3 = sizeof_ca_key_der_1024;
  18427. #elif defined(USE_CERT_BUFFERS_2048)
  18428. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18429. bytes3 = sizeof_ca_key_der_2048;
  18430. #else
  18431. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18432. if (!file3) {
  18433. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18434. }
  18435. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18436. XFCLOSE(file3);
  18437. if (bytes3 == 0)
  18438. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18439. #endif /* USE_CERT_BUFFERS */
  18440. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18441. if (ret != 0)
  18442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18443. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18444. if (ret != 0)
  18445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18446. #ifndef NO_SHA256
  18447. myCert->sigType = CTC_SHA256wRSA;
  18448. #else
  18449. myCert->sigType = CTC_SHAwRSA;
  18450. #endif
  18451. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18452. #ifdef WOLFSSL_CERT_EXT
  18453. /* add Policies */
  18454. XSTRNCPY(myCert->certPolicies[0], "2.16.840.1.101.3.4.1.42",
  18455. CTC_MAX_CERTPOL_SZ);
  18456. myCert->certPoliciesNb =1;
  18457. /* add SKID from the Public Key */
  18458. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, key, NULL);
  18459. if (ret != 0)
  18460. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18461. /* add AKID from the CA certificate */
  18462. #if defined(USE_CERT_BUFFERS_2048)
  18463. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18464. sizeof_ca_cert_der_2048);
  18465. #elif defined(USE_CERT_BUFFERS_1024)
  18466. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18467. sizeof_ca_cert_der_1024);
  18468. #else
  18469. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18470. #endif
  18471. if (ret != 0)
  18472. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18473. /* add Key Usage */
  18474. ret = wc_SetKeyUsage(myCert,"keyEncipherment,keyAgreement");
  18475. if (ret != 0)
  18476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18477. #endif /* WOLFSSL_CERT_EXT */
  18478. #if defined(USE_CERT_BUFFERS_2048)
  18479. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18480. sizeof_ca_cert_der_2048);
  18481. #elif defined(USE_CERT_BUFFERS_1024)
  18482. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18483. sizeof_ca_cert_der_1024);
  18484. #else
  18485. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18486. #endif
  18487. if (ret < 0)
  18488. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18489. certSz = wc_MakeCert(myCert, der, FOURK_BUF, key, NULL, rng);
  18490. if (certSz < 0) {
  18491. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18492. }
  18493. ret = 0;
  18494. do {
  18495. #if defined(WOLFSSL_ASYNC_CRYPT)
  18496. ret = wc_AsyncWait(ret, &caKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18497. #endif
  18498. if (ret >= 0) {
  18499. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der, FOURK_BUF,
  18500. caKey, NULL, rng);
  18501. }
  18502. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18503. if (ret < 0)
  18504. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18505. certSz = (int)ret;
  18506. #ifdef WOLFSSL_TEST_CERT
  18507. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  18508. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18509. if (ret != 0) {
  18510. FreeDecodedCert(decode);
  18511. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18512. }
  18513. FreeDecodedCert(decode);
  18514. #endif
  18515. ret = SaveDerAndPem(der, certSz, otherCertDerFile, otherCertPemFile,
  18516. CERT_TYPE);
  18517. if (ret != 0) {
  18518. goto exit_rsa;
  18519. }
  18520. exit_rsa:
  18521. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18522. if (caKey != NULL) {
  18523. wc_FreeRsaKey(caKey);
  18524. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18525. }
  18526. #ifdef WOLFSSL_TEST_CERT
  18527. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18528. #endif
  18529. #else
  18530. wc_FreeRsaKey(caKey);
  18531. #endif
  18532. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18533. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18534. return ret;
  18535. }
  18536. #endif
  18537. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP) && \
  18538. defined(WOLFSSL_CERT_GEN)
  18539. /* Make Cert / Sign example for ECC cert and RSA CA */
  18540. static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
  18541. {
  18542. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18543. RsaKey *caKey = (RsaKey *)XMALLOC(sizeof *caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18544. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18545. ecc_key *caEccKeyPub = (ecc_key *)XMALLOC(sizeof *caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18546. #ifdef WOLFSSL_TEST_CERT
  18547. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18548. #endif
  18549. #else
  18550. RsaKey caKey[1];
  18551. ecc_key caEccKey[1];
  18552. ecc_key caEccKeyPub[1];
  18553. #ifdef WOLFSSL_TEST_CERT
  18554. DecodedCert decode[1];
  18555. #endif
  18556. #endif
  18557. byte* der = NULL;
  18558. Cert* myCert = NULL;
  18559. int certSz;
  18560. size_t bytes3;
  18561. word32 idx3 = 0;
  18562. #if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
  18563. || !defined(USE_CERT_BUFFERS_256)
  18564. #ifndef NO_FILESYSTEM
  18565. XFILE file3;
  18566. #endif
  18567. #endif
  18568. wc_test_ret_t ret;
  18569. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18570. if ((caKey == NULL) || (caEccKey == NULL) || (caEccKeyPub == NULL)
  18571. #ifdef WOLFSSL_TEST_CERT
  18572. || (decode == NULL)
  18573. #endif
  18574. )
  18575. ERROR_OUT(MEMORY_E, exit_rsa);
  18576. #endif
  18577. XMEMSET(caKey, 0, sizeof *caKey);
  18578. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  18579. XMEMSET(caEccKeyPub, 0, sizeof *caEccKeyPub);
  18580. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18581. if (der == NULL) {
  18582. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18583. }
  18584. myCert = (Cert*)XMALLOC(sizeof(Cert), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18585. if (myCert == NULL) {
  18586. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18587. }
  18588. /* Get CA Key */
  18589. #ifdef USE_CERT_BUFFERS_1024
  18590. XMEMCPY(tmp, ca_key_der_1024, sizeof_ca_key_der_1024);
  18591. bytes3 = sizeof_ca_key_der_1024;
  18592. #elif defined(USE_CERT_BUFFERS_2048)
  18593. XMEMCPY(tmp, ca_key_der_2048, sizeof_ca_key_der_2048);
  18594. bytes3 = sizeof_ca_key_der_2048;
  18595. #else
  18596. file3 = XFOPEN(rsaCaKeyFile, "rb");
  18597. if (!file3) {
  18598. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18599. }
  18600. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18601. XFCLOSE(file3);
  18602. if (bytes3 == 0)
  18603. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18604. #endif /* USE_CERT_BUFFERS */
  18605. ret = wc_InitRsaKey(caKey, HEAP_HINT);
  18606. if (ret != 0)
  18607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18608. ret = wc_RsaPrivateKeyDecode(tmp, &idx3, caKey, (word32)bytes3);
  18609. if (ret != 0)
  18610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18611. /* Get Cert Key */
  18612. #if defined(USE_CERT_BUFFERS_256)
  18613. {
  18614. XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
  18615. bytes3 = sizeof_ecc_key_pub_der_256;
  18616. }
  18617. #elif !defined(NO_FILESYSTEM)
  18618. {
  18619. file3 = XFOPEN(eccKeyPubFileDer, "rb");
  18620. if (!file3) {
  18621. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18622. }
  18623. bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
  18624. XFCLOSE(file3);
  18625. if (bytes3 == 0)
  18626. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18627. }
  18628. #else
  18629. {
  18630. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
  18631. ERROR_OUT(ASN_PARSE_E, exit_rsa);
  18632. }
  18633. #endif
  18634. ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
  18635. if (ret != 0)
  18636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18637. idx3 = 0;
  18638. ret = wc_EccPublicKeyDecode(tmp, &idx3, caEccKeyPub, (word32)bytes3);
  18639. if (ret != 0)
  18640. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18641. /* Setup Certificate */
  18642. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  18643. if (ret != 0)
  18644. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18645. #ifndef NO_SHA256
  18646. myCert->sigType = CTC_SHA256wRSA;
  18647. #else
  18648. myCert->sigType = CTC_SHAwRSA;
  18649. #endif
  18650. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  18651. #ifdef WOLFSSL_CERT_EXT
  18652. /* add Policies */
  18653. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  18654. CTC_MAX_CERTPOL_SZ);
  18655. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  18656. CTC_MAX_CERTPOL_SZ);
  18657. myCert->certPoliciesNb = 2;
  18658. /* add SKID from the Public Key */
  18659. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, caEccKeyPub);
  18660. if (ret != 0)
  18661. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18662. /* add AKID from the CA certificate */
  18663. #if defined(USE_CERT_BUFFERS_2048)
  18664. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_2048,
  18665. sizeof_ca_cert_der_2048);
  18666. #elif defined(USE_CERT_BUFFERS_1024)
  18667. ret = wc_SetAuthKeyIdFromCert(myCert, ca_cert_der_1024,
  18668. sizeof_ca_cert_der_1024);
  18669. #else
  18670. ret = wc_SetAuthKeyId(myCert, rsaCaCertFile);
  18671. #endif
  18672. if (ret != 0)
  18673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18674. /* add Key Usage */
  18675. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  18676. if (ret != 0)
  18677. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18678. #endif /* WOLFSSL_CERT_EXT */
  18679. #if defined(USE_CERT_BUFFERS_2048)
  18680. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_2048,
  18681. sizeof_ca_cert_der_2048);
  18682. #elif defined(USE_CERT_BUFFERS_1024)
  18683. ret = wc_SetIssuerBuffer(myCert, ca_cert_der_1024,
  18684. sizeof_ca_cert_der_1024);
  18685. #else
  18686. ret = wc_SetIssuer(myCert, rsaCaCertFile);
  18687. #endif
  18688. if (ret < 0)
  18689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18690. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, caEccKeyPub, rng);
  18691. if (certSz < 0) {
  18692. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit_rsa);
  18693. }
  18694. ret = 0;
  18695. do {
  18696. #if defined(WOLFSSL_ASYNC_CRYPT)
  18697. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18698. #endif
  18699. if (ret >= 0) {
  18700. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  18701. FOURK_BUF, caKey, NULL, rng);
  18702. }
  18703. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18704. if (ret < 0)
  18705. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18706. certSz = (int)ret;
  18707. #ifdef WOLFSSL_TEST_CERT
  18708. InitDecodedCert(decode, der, certSz, 0);
  18709. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  18710. if (ret != 0) {
  18711. FreeDecodedCert(decode);
  18712. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18713. }
  18714. FreeDecodedCert(decode);
  18715. #endif
  18716. ret = SaveDerAndPem(der, certSz, certEccRsaDerFile, certEccRsaPemFile,
  18717. CERT_TYPE);
  18718. if (ret != 0) {
  18719. goto exit_rsa;
  18720. }
  18721. exit_rsa:
  18722. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18723. if (caKey != NULL) {
  18724. wc_FreeRsaKey(caKey);
  18725. XFREE(caKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18726. }
  18727. if (caEccKey != NULL) {
  18728. wc_ecc_free(caEccKey);
  18729. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18730. }
  18731. if (caEccKeyPub != NULL) {
  18732. wc_ecc_free(caEccKeyPub);
  18733. XFREE(caEccKeyPub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18734. }
  18735. #ifdef WOLFSSL_TEST_CERT
  18736. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18737. #endif
  18738. #else
  18739. wc_FreeRsaKey(caKey);
  18740. wc_ecc_free(caEccKey);
  18741. wc_ecc_free(caEccKeyPub);
  18742. #endif
  18743. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18744. myCert = NULL;
  18745. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18746. der = NULL;
  18747. if (ret >= 0)
  18748. ret = 0;
  18749. return ret;
  18750. }
  18751. #endif /* !NO_RSA && HAVE_ECC && WOLFSSL_CERT_GEN */
  18752. #ifdef WOLFSSL_KEY_GEN
  18753. static wc_test_ret_t rsa_keygen_test(WC_RNG* rng)
  18754. {
  18755. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18756. RsaKey *genKey = (RsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18757. #else
  18758. RsaKey genKey[1];
  18759. #endif
  18760. wc_test_ret_t ret;
  18761. #ifndef WOLFSSL_NO_MALLOC
  18762. byte* der = NULL;
  18763. #else
  18764. byte der[1280];
  18765. #endif
  18766. #ifndef WOLFSSL_CRYPTOCELL
  18767. word32 idx = 0;
  18768. #endif
  18769. int derSz = 0;
  18770. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FIPS) && \
  18771. (defined(RSA_MIN_SIZE) && (RSA_MIN_SIZE <= 1024))
  18772. int keySz = 1024;
  18773. #else
  18774. int keySz = 2048;
  18775. #endif
  18776. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18777. if (! genKey)
  18778. ERROR_OUT(MEMORY_E, exit_rsa);
  18779. #endif
  18780. XMEMSET(genKey, 0, sizeof *genKey);
  18781. ret = wc_InitRsaKey_ex(genKey, HEAP_HINT, devId);
  18782. if (ret != 0)
  18783. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18784. #ifdef HAVE_FIPS
  18785. for (;;) {
  18786. #endif
  18787. ret = wc_MakeRsaKey(genKey, keySz, WC_RSA_EXPONENT, rng);
  18788. #if defined(WOLFSSL_ASYNC_CRYPT)
  18789. ret = wc_AsyncWait(ret, &genKey->asyncDev, WC_ASYNC_FLAG_NONE);
  18790. #endif
  18791. #ifdef HAVE_FIPS
  18792. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  18793. continue;
  18794. break;
  18795. }
  18796. #endif
  18797. if (ret != 0)
  18798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18799. TEST_SLEEP();
  18800. #ifdef WOLFSSL_RSA_KEY_CHECK
  18801. ret = wc_CheckRsaKey(genKey);
  18802. if (ret != 0)
  18803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18804. #endif
  18805. #ifndef WOLFSSL_NO_MALLOC
  18806. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18807. if (der == NULL) {
  18808. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  18809. }
  18810. derSz = FOURK_BUF;
  18811. #else
  18812. derSz = sizeof(der);
  18813. #endif
  18814. derSz = wc_RsaKeyToDer(genKey, der, derSz);
  18815. if (derSz < 0) {
  18816. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  18817. }
  18818. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  18819. PRIVATEKEY_TYPE);
  18820. if (ret != 0) {
  18821. goto exit_rsa;
  18822. }
  18823. wc_FreeRsaKey(genKey);
  18824. ret = wc_InitRsaKey(genKey, HEAP_HINT);
  18825. if (ret != 0)
  18826. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18827. #ifndef WOLFSSL_CRYPTOCELL
  18828. idx = 0;
  18829. /* The private key part of the key gen pairs from cryptocell can't be exported */
  18830. ret = wc_RsaPrivateKeyDecode(der, &idx, genKey, (word32)derSz);
  18831. if (ret != 0)
  18832. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18833. #endif /* WOLFSSL_CRYPTOCELL */
  18834. exit_rsa:
  18835. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  18836. if (genKey) {
  18837. wc_FreeRsaKey(genKey);
  18838. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18839. }
  18840. #else
  18841. wc_FreeRsaKey(genKey);
  18842. #endif
  18843. #ifndef WOLFSSL_NO_MALLOC
  18844. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  18845. der = NULL;
  18846. #endif
  18847. return ret;
  18848. }
  18849. #endif
  18850. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  18851. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG) && \
  18852. (!defined(HAVE_FIPS) || \
  18853. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  18854. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  18855. static wc_test_ret_t rsa_oaep_padding_test(RsaKey* key, WC_RNG* rng)
  18856. {
  18857. wc_test_ret_t ret = 0;
  18858. word32 idx = 0;
  18859. const char inStr[] = TEST_STRING;
  18860. const word32 inLen = (word32)TEST_STRING_SZ;
  18861. const word32 outSz = RSA_TEST_BYTES;
  18862. const word32 plainSz = RSA_TEST_BYTES;
  18863. byte* res = NULL;
  18864. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18865. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18866. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18867. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  18868. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  18869. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  18870. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  18871. if (in == NULL || out == NULL || plain == NULL)
  18872. ERROR_OUT(MEMORY_E, exit_rsa);
  18873. #endif
  18874. XMEMCPY(in, inStr, inLen);
  18875. #ifndef NO_SHA
  18876. do {
  18877. #if defined(WOLFSSL_ASYNC_CRYPT)
  18878. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18879. #endif
  18880. if (ret >= 0) {
  18881. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18882. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18883. }
  18884. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18885. if (ret < 0)
  18886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18887. TEST_SLEEP();
  18888. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18889. idx = (word32)ret;
  18890. do {
  18891. #if defined(WOLFSSL_ASYNC_CRYPT)
  18892. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18893. #endif
  18894. if (ret >= 0) {
  18895. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18896. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, NULL, 0);
  18897. }
  18898. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18899. if (ret < 0)
  18900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18901. if (XMEMCMP(plain, in, inLen)) {
  18902. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18903. }
  18904. TEST_SLEEP();
  18905. #endif /* NO_SHA */
  18906. #endif
  18907. #ifndef NO_SHA256
  18908. XMEMSET(plain, 0, plainSz);
  18909. do {
  18910. #if defined(WOLFSSL_ASYNC_CRYPT)
  18911. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18912. #endif
  18913. if (ret >= 0) {
  18914. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18915. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18916. }
  18917. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18918. if (ret < 0)
  18919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18920. TEST_SLEEP();
  18921. idx = (word32)ret;
  18922. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18923. do {
  18924. #if defined(WOLFSSL_ASYNC_CRYPT)
  18925. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18926. #endif
  18927. if (ret >= 0) {
  18928. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18929. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18930. }
  18931. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18932. if (ret < 0)
  18933. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18934. if (XMEMCMP(plain, in, inLen)) {
  18935. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18936. }
  18937. TEST_SLEEP();
  18938. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18939. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  18940. do {
  18941. #if defined(WOLFSSL_ASYNC_CRYPT)
  18942. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18943. #endif
  18944. if (ret >= 0) {
  18945. ret = wc_RsaPrivateDecryptInline_ex(out, idx, &res, key,
  18946. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18947. }
  18948. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18949. if (ret < 0)
  18950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18951. if (ret != (int)inLen) {
  18952. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18953. }
  18954. if (XMEMCMP(res, in, inLen)) {
  18955. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18956. }
  18957. TEST_SLEEP();
  18958. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  18959. /* check fails if not using the same optional label */
  18960. XMEMSET(plain, 0, plainSz);
  18961. do {
  18962. #if defined(WOLFSSL_ASYNC_CRYPT)
  18963. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18964. #endif
  18965. if (ret >= 0) {
  18966. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  18967. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, NULL, 0);
  18968. }
  18969. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18970. if (ret < 0)
  18971. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  18972. TEST_SLEEP();
  18973. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  18974. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  18975. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  18976. /* label is unused in cryptocell and SE050 so it won't detect decrypt error
  18977. * due to label */
  18978. idx = (word32)ret;
  18979. do {
  18980. #if defined(WOLFSSL_ASYNC_CRYPT)
  18981. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18982. #endif
  18983. if (ret >= 0) {
  18984. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  18985. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  18986. }
  18987. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  18988. if (ret > 0) { /* in this case decrypt should fail */
  18989. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  18990. }
  18991. ret = 0;
  18992. TEST_SLEEP();
  18993. #endif /* !HAVE_CAVIUM */
  18994. /* check using optional label with encrypt/decrypt */
  18995. XMEMSET(plain, 0, plainSz);
  18996. do {
  18997. #if defined(WOLFSSL_ASYNC_CRYPT)
  18998. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  18999. #endif
  19000. if (ret >= 0) {
  19001. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19002. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19003. }
  19004. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19005. if (ret < 0)
  19006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19007. TEST_SLEEP();
  19008. idx = (word32)ret;
  19009. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19010. do {
  19011. #if defined(WOLFSSL_ASYNC_CRYPT)
  19012. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19013. #endif
  19014. if (ret >= 0) {
  19015. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19016. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256, in, inLen);
  19017. }
  19018. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19019. if (ret < 0)
  19020. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19021. if (XMEMCMP(plain, in, inLen)) {
  19022. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19023. }
  19024. TEST_SLEEP();
  19025. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19026. #ifndef NO_SHA
  19027. /* check fail using mismatch hash algorithms */
  19028. XMEMSET(plain, 0, plainSz);
  19029. do {
  19030. #if defined(WOLFSSL_ASYNC_CRYPT)
  19031. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19032. #endif
  19033. if (ret >= 0) {
  19034. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19035. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA, WC_MGF1SHA1, in, inLen);
  19036. }
  19037. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19038. if (ret < 0)
  19039. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19040. TEST_SLEEP();
  19041. /* TODO: investigate why Cavium Nitrox doesn't detect decrypt error here */
  19042. #if !defined(HAVE_CAVIUM) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19043. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SE050)
  19044. idx = (word32)ret;
  19045. do {
  19046. #if defined(WOLFSSL_ASYNC_CRYPT)
  19047. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19048. #endif
  19049. if (ret >= 0) {
  19050. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19051. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA256, WC_MGF1SHA256,
  19052. in, inLen);
  19053. }
  19054. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19055. if (ret > 0) { /* should fail */
  19056. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19057. }
  19058. ret = 0;
  19059. TEST_SLEEP();
  19060. #endif /* !HAVE_CAVIUM */
  19061. #endif /* NO_SHA */
  19062. #endif /* NO_SHA256 */
  19063. #ifdef WOLFSSL_SHA512
  19064. /* Check valid RSA key size is used while using hash length of SHA512
  19065. If key size is less than (hash length * 2) + 2 then is invalid use
  19066. and test, since OAEP padding requires this.
  19067. BAD_FUNC_ARG is returned when this case is not met */
  19068. if (wc_RsaEncryptSize(key) > ((int)WC_SHA512_DIGEST_SIZE * 2) + 2) {
  19069. XMEMSET(plain, 0, plainSz);
  19070. do {
  19071. #if defined(WOLFSSL_ASYNC_CRYPT)
  19072. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19073. #endif
  19074. if (ret >= 0) {
  19075. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19076. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19077. }
  19078. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19079. if (ret < 0)
  19080. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19081. TEST_SLEEP();
  19082. idx = (word32)ret;
  19083. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19084. do {
  19085. #if defined(WOLFSSL_ASYNC_CRYPT)
  19086. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19087. #endif
  19088. if (ret >= 0) {
  19089. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19090. WC_RSA_OAEP_PAD, WC_HASH_TYPE_SHA512, WC_MGF1SHA512, NULL, 0);
  19091. }
  19092. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19093. if (ret < 0)
  19094. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19095. if (XMEMCMP(plain, in, inLen)) {
  19096. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19097. }
  19098. TEST_SLEEP();
  19099. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19100. }
  19101. #endif /* WOLFSSL_SHA512 */
  19102. /* check using pkcsv15 padding with _ex API */
  19103. XMEMSET(plain, 0, plainSz);
  19104. do {
  19105. #if defined(WOLFSSL_ASYNC_CRYPT)
  19106. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19107. #endif
  19108. if (ret >= 0) {
  19109. ret = wc_RsaPublicEncrypt_ex(in, inLen, out, outSz, key, rng,
  19110. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19111. }
  19112. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19113. if (ret < 0)
  19114. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19115. TEST_SLEEP();
  19116. idx = (word32)ret;
  19117. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  19118. do {
  19119. #if defined(WOLFSSL_ASYNC_CRYPT)
  19120. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19121. #endif
  19122. if (ret >= 0) {
  19123. ret = wc_RsaPrivateDecrypt_ex(out, idx, plain, plainSz, key,
  19124. WC_RSA_PKCSV15_PAD, WC_HASH_TYPE_NONE, 0, NULL, 0);
  19125. }
  19126. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19127. if (ret < 0)
  19128. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19129. if (XMEMCMP(plain, in, inLen)) {
  19130. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19131. }
  19132. TEST_SLEEP();
  19133. #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
  19134. exit_rsa:
  19135. WC_FREE_VAR(in, HEAP_HINT);
  19136. WC_FREE_VAR(out, HEAP_HINT);
  19137. WC_FREE_VAR(plain, HEAP_HINT);
  19138. (void)idx;
  19139. (void)inStr;
  19140. (void)res;
  19141. if (ret >= 0)
  19142. ret = 0;
  19143. return ret;
  19144. }
  19145. #endif
  19146. #endif
  19147. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
  19148. {
  19149. wc_test_ret_t ret;
  19150. size_t bytes = 0;
  19151. WC_RNG rng;
  19152. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19153. byte* tmp = NULL;
  19154. byte* der = NULL;
  19155. RsaKey *key = NULL;
  19156. #else
  19157. RsaKey key[1];
  19158. byte tmp[FOURK_BUF];
  19159. #endif
  19160. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19161. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19162. RsaKey *keypub = NULL;
  19163. #else
  19164. RsaKey keypub[1];
  19165. #endif
  19166. #endif
  19167. word32 idx = 0;
  19168. const char inStr[] = TEST_STRING;
  19169. const word32 inLen = (word32)TEST_STRING_SZ;
  19170. const word32 outSz = RSA_TEST_BYTES;
  19171. const word32 plainSz = RSA_TEST_BYTES;
  19172. byte* res = NULL;
  19173. #ifndef NO_SIG_WRAPPER
  19174. int modLen;
  19175. #endif
  19176. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19177. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  19178. !defined(NO_FILESYSTEM)
  19179. XFILE file;
  19180. #ifdef WOLFSSL_TEST_CERT
  19181. XFILE file2;
  19182. #endif
  19183. #endif
  19184. #ifdef WOLFSSL_TEST_CERT
  19185. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19186. DecodedCert *cert = (DecodedCert *)XMALLOC(sizeof *cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19187. #else
  19188. DecodedCert cert[1];
  19189. #endif
  19190. #ifndef NO_ASN_TIME
  19191. struct tm timearg;
  19192. const byte* date;
  19193. byte dateFormat;
  19194. int dateLength;
  19195. #endif
  19196. #endif
  19197. WC_DECLARE_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19198. WC_DECLARE_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19199. WC_DECLARE_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19200. WC_ALLOC_VAR(in, byte, TEST_STRING_SZ, HEAP_HINT);
  19201. WC_ALLOC_VAR(out, byte, RSA_TEST_BYTES, HEAP_HINT);
  19202. WC_ALLOC_VAR(plain, byte, RSA_TEST_BYTES, HEAP_HINT);
  19203. WOLFSSL_ENTER("rsa_test");
  19204. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  19205. if (in == NULL || out == NULL || plain == NULL)
  19206. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19207. #endif
  19208. XMEMCPY(in, inStr, inLen);
  19209. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19210. key = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19211. if (key == NULL)
  19212. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19213. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19214. keypub = wc_NewRsaKey(HEAP_HINT, devId, &ret);
  19215. if (keypub == NULL)
  19216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19217. #endif
  19218. #ifdef WOLFSSL_TEST_CERT
  19219. if (cert == NULL)
  19220. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit_rsa);
  19221. #endif
  19222. #else /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19223. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19224. if (ret != 0)
  19225. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19226. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19227. ret = wc_InitRsaKey_ex(keypub, HEAP_HINT, devId);
  19228. if (ret != 0)
  19229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19230. #endif
  19231. #endif /* ! (WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC) */
  19232. /* initialize stack structures */
  19233. XMEMSET(&rng, 0, sizeof(rng));
  19234. #if !defined(NO_ASN)
  19235. ret = rsa_decode_test(key);
  19236. if (ret != 0)
  19237. ERROR_OUT(ret, exit_rsa);
  19238. #endif
  19239. #ifdef USE_CERT_BUFFERS_1024
  19240. bytes = (size_t)sizeof_client_key_der_1024;
  19241. if (bytes < (size_t)sizeof_client_cert_der_1024)
  19242. bytes = (size_t)sizeof_client_cert_der_1024;
  19243. #elif defined(USE_CERT_BUFFERS_2048)
  19244. bytes = (size_t)sizeof_client_key_der_2048;
  19245. if (bytes < (size_t)sizeof_client_cert_der_2048)
  19246. bytes = (size_t)sizeof_client_cert_der_2048;
  19247. #elif defined(USE_CERT_BUFFERS_3072)
  19248. bytes = (size_t)sizeof_client_key_der_3072;
  19249. if (bytes < (size_t)sizeof_client_cert_der_3072)
  19250. bytes = (size_t)sizeof_client_cert_der_3072;
  19251. #elif defined(USE_CERT_BUFFERS_4096)
  19252. bytes = (size_t)sizeof_client_key_der_4096;
  19253. if (bytes < (size_t)sizeof_client_cert_der_4096)
  19254. bytes = (size_t)sizeof_client_cert_der_4096;
  19255. #else
  19256. bytes = FOURK_BUF;
  19257. #endif
  19258. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19259. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19260. if (tmp == NULL)
  19261. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19262. #endif
  19263. #ifdef USE_CERT_BUFFERS_1024
  19264. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  19265. #elif defined(USE_CERT_BUFFERS_2048)
  19266. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  19267. #elif defined(USE_CERT_BUFFERS_3072)
  19268. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  19269. #elif defined(USE_CERT_BUFFERS_4096)
  19270. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  19271. #elif !defined(NO_FILESYSTEM)
  19272. file = XFOPEN(clientKey, "rb");
  19273. if (!file) {
  19274. err_sys("can't open ./certs/client-key.der, "
  19275. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19276. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19277. }
  19278. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19279. XFCLOSE(file);
  19280. if (bytes == 0)
  19281. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19282. #else
  19283. /* No key to use. */
  19284. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19285. #endif /* USE_CERT_BUFFERS */
  19286. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  19287. if (ret != 0)
  19288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19289. #ifndef NO_ASN
  19290. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  19291. if (ret != 0)
  19292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19293. #ifndef NO_SIG_WRAPPER
  19294. modLen = wc_RsaEncryptSize(key);
  19295. #endif
  19296. #else
  19297. #ifdef USE_CERT_BUFFERS_2048
  19298. ret = mp_read_unsigned_bin(&key->n, &tmp[12], 256);
  19299. if (ret != 0)
  19300. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19301. ret = mp_set_int(&key->e, WC_RSA_EXPONENT);
  19302. if (ret != 0)
  19303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19304. #ifndef NO_SIG_WRAPPER
  19305. modLen = 2048;
  19306. #endif
  19307. #else
  19308. #error Not supported yet!
  19309. #endif
  19310. #endif
  19311. #ifndef WC_NO_RNG
  19312. #ifndef HAVE_FIPS
  19313. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  19314. #else
  19315. ret = wc_InitRng(&rng);
  19316. #endif
  19317. if (ret != 0)
  19318. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19319. #endif
  19320. #ifndef NO_SIG_WRAPPER
  19321. ret = rsa_sig_test(key, sizeof *key, modLen, &rng);
  19322. if (ret != 0)
  19323. goto exit_rsa;
  19324. #endif
  19325. #ifdef WC_RSA_NONBLOCK
  19326. ret = rsa_nb_test(key, in, inLen, out, outSz, plain, plainSz, &rng);
  19327. if (ret != 0)
  19328. goto exit_rsa;
  19329. #endif
  19330. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19331. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19332. do {
  19333. #if defined(WOLFSSL_ASYNC_CRYPT)
  19334. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19335. #endif
  19336. if (ret >= 0) {
  19337. ret = wc_RsaPublicEncrypt(in, inLen, out, outSz, key, &rng);
  19338. }
  19339. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19340. if (ret < 0)
  19341. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19342. TEST_SLEEP();
  19343. #ifdef WC_RSA_BLINDING
  19344. {
  19345. wc_test_ret_t tmpret = ret;
  19346. ret = wc_RsaSetRNG(key, &rng);
  19347. if (ret < 0)
  19348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19349. ret = tmpret;
  19350. }
  19351. #endif
  19352. idx = (word32)ret; /* save off encrypted length */
  19353. do {
  19354. #if defined(WOLFSSL_ASYNC_CRYPT)
  19355. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19356. #endif
  19357. if (ret >= 0) {
  19358. ret = wc_RsaPrivateDecrypt(out, idx, plain, plainSz, key);
  19359. }
  19360. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19361. if (ret < 0)
  19362. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19363. if (XMEMCMP(plain, in, inLen)) {
  19364. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19365. }
  19366. TEST_SLEEP();
  19367. do {
  19368. #if defined(WOLFSSL_ASYNC_CRYPT)
  19369. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19370. #endif
  19371. if (ret >= 0) {
  19372. ret = wc_RsaPrivateDecryptInline(out, idx, &res, key);
  19373. }
  19374. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19375. if (ret < 0)
  19376. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19377. if (ret != (int)inLen) {
  19378. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19379. }
  19380. if (XMEMCMP(res, in, inLen)) {
  19381. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19382. }
  19383. TEST_SLEEP();
  19384. do {
  19385. #if defined(WOLFSSL_ASYNC_CRYPT)
  19386. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19387. #endif
  19388. if (ret >= 0) {
  19389. ret = wc_RsaSSL_Sign(in, inLen, out, outSz, key, &rng);
  19390. }
  19391. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19392. if (ret < 0)
  19393. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19394. TEST_SLEEP();
  19395. #elif defined(WOLFSSL_PUBLIC_MP)
  19396. {
  19397. static const byte signature_2048[] = {
  19398. 0x07, 0x6f, 0xc9, 0x85, 0x73, 0x9e, 0x21, 0x79,
  19399. 0x47, 0xf1, 0xa3, 0xd7, 0xf4, 0x27, 0x29, 0xbe,
  19400. 0x99, 0x5d, 0xac, 0xb2, 0x10, 0x3f, 0x95, 0xda,
  19401. 0x89, 0x23, 0xb8, 0x96, 0x13, 0x57, 0x72, 0x30,
  19402. 0xa1, 0xfe, 0x5a, 0x68, 0x9c, 0x99, 0x9d, 0x1e,
  19403. 0x05, 0xa4, 0x80, 0xb0, 0xbb, 0xd9, 0xd9, 0xa1,
  19404. 0x69, 0x97, 0x74, 0xb3, 0x41, 0x21, 0x3b, 0x47,
  19405. 0xf5, 0x51, 0xb1, 0xfb, 0xc7, 0xaa, 0xcc, 0xdc,
  19406. 0xcd, 0x76, 0xa0, 0x28, 0x4d, 0x27, 0x14, 0xa4,
  19407. 0xb9, 0x41, 0x68, 0x7c, 0xb3, 0x66, 0xe6, 0x6f,
  19408. 0x40, 0x76, 0xe4, 0x12, 0xfd, 0xae, 0x29, 0xb5,
  19409. 0x63, 0x60, 0x87, 0xce, 0x49, 0x6b, 0xf3, 0x05,
  19410. 0x9a, 0x14, 0xb5, 0xcc, 0xcd, 0xf7, 0x30, 0x95,
  19411. 0xd2, 0x72, 0x52, 0x1d, 0x5b, 0x7e, 0xef, 0x4a,
  19412. 0x02, 0x96, 0x21, 0x6c, 0x55, 0xa5, 0x15, 0xb1,
  19413. 0x57, 0x63, 0x2c, 0xa3, 0x8e, 0x9d, 0x3d, 0x45,
  19414. 0xcc, 0xb8, 0xe6, 0xa1, 0xc8, 0x59, 0xcd, 0xf5,
  19415. 0xdc, 0x0a, 0x51, 0xb6, 0x9d, 0xfb, 0xf4, 0x6b,
  19416. 0xfd, 0x32, 0x71, 0x6e, 0xcf, 0xcb, 0xb3, 0xd9,
  19417. 0xe0, 0x4a, 0x77, 0x34, 0xd6, 0x61, 0xf5, 0x7c,
  19418. 0xf9, 0xa9, 0xa4, 0xb0, 0x8e, 0x3b, 0xd6, 0x04,
  19419. 0xe0, 0xde, 0x2b, 0x5b, 0x5a, 0xbf, 0xd9, 0xef,
  19420. 0x8d, 0xa3, 0xf5, 0xb1, 0x67, 0xf3, 0xb9, 0x72,
  19421. 0x0a, 0x37, 0x12, 0x35, 0x6c, 0x8e, 0x10, 0x8b,
  19422. 0x38, 0x06, 0x16, 0x4b, 0x20, 0x20, 0x13, 0x00,
  19423. 0x2e, 0x6d, 0xc2, 0x59, 0x23, 0x67, 0x4a, 0x6d,
  19424. 0xa1, 0x46, 0x8b, 0xee, 0xcf, 0x44, 0xb4, 0x3e,
  19425. 0x56, 0x75, 0x00, 0x68, 0xb5, 0x7d, 0x0f, 0x20,
  19426. 0x79, 0x5d, 0x7f, 0x12, 0x15, 0x32, 0x89, 0x61,
  19427. 0x6b, 0x29, 0xb7, 0x52, 0xf5, 0x25, 0xd8, 0x98,
  19428. 0xe8, 0x6f, 0xf9, 0x22, 0xb4, 0xbb, 0xe5, 0xff,
  19429. 0xd0, 0x92, 0x86, 0x9a, 0x88, 0xa2, 0xaf, 0x6b
  19430. };
  19431. ret = sizeof(signature_2048);
  19432. XMEMCPY(out, signature_2048, ret);
  19433. }
  19434. #endif
  19435. #if !defined(WC_NO_RNG) && !defined(WC_NO_RSA_OAEP) && \
  19436. ((!defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)) || \
  19437. defined(WOLFSSL_PUBLIC_MP)) && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19438. idx = (word32)ret;
  19439. XMEMSET(plain, 0, plainSz);
  19440. do {
  19441. #if defined(WOLFSSL_ASYNC_CRYPT)
  19442. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19443. #endif
  19444. if (ret >= 0) {
  19445. #ifndef WOLFSSL_RSA_VERIFY_INLINE
  19446. #if defined(WOLFSSL_CRYPTOCELL)
  19447. /*
  19448. Cryptocell requires the input data and signature byte array to verify.
  19449. first argument must be the input data
  19450. second argument must be the length of input data
  19451. third argument must be the signature byte array or the output from
  19452. wc_RsaSSL_Sign()
  19453. fourth argument must be the length of the signature byte array
  19454. */
  19455. ret = wc_RsaSSL_Verify(in, inLen, out, outSz, key);
  19456. #else
  19457. ret = wc_RsaSSL_Verify(out, idx, plain, plainSz, key);
  19458. #endif /* WOLFSSL_CRYPTOCELL */
  19459. #else
  19460. byte* dec = NULL;
  19461. ret = wc_RsaSSL_VerifyInline(out, idx, &dec, key);
  19462. if (ret > 0) {
  19463. XMEMCPY(plain, dec, ret);
  19464. }
  19465. #endif
  19466. }
  19467. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19468. if (ret < 0)
  19469. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19470. if (XMEMCMP(plain, in, (size_t)ret)) {
  19471. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19472. }
  19473. TEST_SLEEP();
  19474. #endif
  19475. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  19476. #if !defined(WC_NO_RSA_OAEP) && !defined(WC_NO_RNG)
  19477. #if (!defined(HAVE_FIPS) || \
  19478. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))) \
  19479. && !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19480. ret = rsa_oaep_padding_test(key, &rng);
  19481. if (ret != 0)
  19482. goto exit_rsa;
  19483. #endif /* !HAVE_FIPS */
  19484. #endif /* WC_NO_RSA_OAEP && !WC_NO_RNG */
  19485. #endif /* WOLFSSL_RSA_VERIFY_ONLY */
  19486. #if !defined(HAVE_FIPS) && !defined(NO_ASN) \
  19487. && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19488. ret = rsa_export_key_test(key);
  19489. if (ret != 0)
  19490. goto exit_rsa;
  19491. #endif
  19492. #if !defined(NO_ASN) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19493. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  19494. ret = rsa_flatten_test(key);
  19495. if (ret != 0)
  19496. goto exit_rsa;
  19497. #endif
  19498. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_ASN) && \
  19499. !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  19500. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  19501. (void)clientCert;
  19502. #endif
  19503. #ifdef WOLFSSL_TEST_CERT
  19504. #ifdef USE_CERT_BUFFERS_1024
  19505. XMEMCPY(tmp, client_cert_der_1024, (size_t)sizeof_client_cert_der_1024);
  19506. bytes = (size_t)sizeof_client_cert_der_1024;
  19507. #elif defined(USE_CERT_BUFFERS_2048)
  19508. XMEMCPY(tmp, client_cert_der_2048, (size_t)sizeof_client_cert_der_2048);
  19509. bytes = (size_t)sizeof_client_cert_der_2048;
  19510. #elif defined(USE_CERT_BUFFERS_3072)
  19511. XMEMCPY(tmp, client_cert_der_3072, (size_t)sizeof_client_cert_der_3072);
  19512. bytes = (size_t)sizeof_client_cert_der_3072;
  19513. #elif defined(USE_CERT_BUFFERS_4096)
  19514. XMEMCPY(tmp, client_cert_der_4096, (size_t)sizeof_client_cert_der_4096);
  19515. bytes = (size_t)sizeof_client_cert_der_4096;
  19516. #elif !defined(NO_FILESYSTEM)
  19517. file2 = XFOPEN(clientCert, "rb");
  19518. if (!file2) {
  19519. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19520. }
  19521. bytes = XFREAD(tmp, 1, FOURK_BUF, file2);
  19522. XFCLOSE(file2);
  19523. if (bytes == 0)
  19524. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19525. #else
  19526. /* No certificate to use. */
  19527. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa);
  19528. #endif
  19529. InitDecodedCert(cert, tmp, (word32)bytes, NULL);
  19530. ret = ParseCert(cert, CERT_TYPE, NO_VERIFY, NULL);
  19531. if (ret != 0) {
  19532. FreeDecodedCert(cert);
  19533. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19534. }
  19535. #ifndef NO_ASN_TIME
  19536. ret = wc_GetDateInfo(cert->afterDate, cert->afterDateLen, &date,
  19537. &dateFormat, &dateLength);
  19538. if (ret != 0) {
  19539. FreeDecodedCert(cert);
  19540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19541. }
  19542. ret = wc_GetDateAsCalendarTime(date, dateLength, dateFormat, &timearg);
  19543. if (ret != 0) {
  19544. FreeDecodedCert(cert);
  19545. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19546. }
  19547. #endif
  19548. FreeDecodedCert(cert);
  19549. #endif /* WOLFSSL_TEST_CERT */
  19550. #ifdef WOLFSSL_CERT_EXT
  19551. #ifdef USE_CERT_BUFFERS_1024
  19552. XMEMCPY(tmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  19553. bytes = sizeof_client_keypub_der_1024;
  19554. #elif defined(USE_CERT_BUFFERS_2048)
  19555. XMEMCPY(tmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  19556. bytes = sizeof_client_keypub_der_2048;
  19557. #elif defined(USE_CERT_BUFFERS_3072)
  19558. XMEMCPY(tmp, client_keypub_der_3072, sizeof_client_keypub_der_3072);
  19559. bytes = sizeof_client_keypub_der_3072;
  19560. #elif defined(USE_CERT_BUFFERS_4096)
  19561. XMEMCPY(tmp, client_keypub_der_4096, sizeof_client_keypub_der_4096);
  19562. bytes = sizeof_client_keypub_der_4096;
  19563. #else
  19564. file = XFOPEN(clientKeyPub, "rb");
  19565. if (!file) {
  19566. err_sys("can't open ./certs/client-keyPub.der, "
  19567. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  19568. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19569. }
  19570. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  19571. XFCLOSE(file);
  19572. if (bytes == 0)
  19573. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19574. #endif /* USE_CERT_BUFFERS */
  19575. ret = wc_InitRsaKey(keypub, HEAP_HINT);
  19576. if (ret != 0)
  19577. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19578. idx = 0;
  19579. ret = wc_RsaPublicKeyDecode(tmp, &idx, keypub, (word32)bytes);
  19580. if (ret != 0)
  19581. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19582. #endif /* WOLFSSL_CERT_EXT */
  19583. #ifdef WOLFSSL_KEY_GEN
  19584. ret = rsa_keygen_test(&rng);
  19585. if (ret != 0)
  19586. goto exit_rsa;
  19587. #endif
  19588. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ASN_TIME) && \
  19589. !defined(WOLFSSL_NO_MALLOC)
  19590. /* Make Cert / Sign example for RSA cert and RSA CA */
  19591. ret = rsa_certgen_test(key, keypub, &rng, tmp);
  19592. if (ret != 0)
  19593. goto exit_rsa;
  19594. #if !defined(NO_RSA) && defined(HAVE_ECC) && !defined(NO_ECC_SECP)
  19595. ret = rsa_ecc_certgen_test(&rng, tmp);
  19596. if (ret != 0)
  19597. goto exit_rsa;
  19598. #endif
  19599. #if defined(WOLFSSL_CERT_REQ) && !defined(WOLFSSL_NO_MALLOC)
  19600. {
  19601. Cert *req;
  19602. int derSz;
  19603. #ifndef WOLFSSL_SMALL_STACK
  19604. byte* der = NULL;
  19605. #endif
  19606. req = (Cert *)XMALLOC(sizeof *req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19607. if (! req)
  19608. ERROR_OUT(MEMORY_E, exit_rsa);
  19609. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,DYNAMIC_TYPE_TMP_BUFFER);
  19610. if (der == NULL) {
  19611. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
  19612. }
  19613. ret = wc_InitCert_ex(req, HEAP_HINT, devId);
  19614. if (ret != 0)
  19615. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19616. req->version = 0;
  19617. req->isCA = 1;
  19618. XSTRNCPY(req->challengePw, "wolf123", CTC_NAME_SIZE);
  19619. XMEMCPY(&req->subject, &certDefaultName, sizeof(CertName));
  19620. #ifndef NO_SHA256
  19621. req->sigType = CTC_SHA256wRSA;
  19622. #else
  19623. req->sigType = CTC_SHAwRSA;
  19624. #endif
  19625. #ifdef WOLFSSL_CERT_EXT
  19626. /* add SKID from the Public Key */
  19627. ret = wc_SetSubjectKeyIdFromPublicKey(req, keypub, NULL);
  19628. if (ret != 0)
  19629. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19630. /* add Key Usage */
  19631. ret = wc_SetKeyUsage(req, certKeyUsage2);
  19632. if (ret != 0)
  19633. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19634. /* add Extended Key Usage */
  19635. ret = wc_SetExtKeyUsage(req,
  19636. "serverAuth,clientAuth,codeSigning,"
  19637. "emailProtection,timeStamping,OCSPSigning");
  19638. if (ret != 0)
  19639. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19640. #ifdef WOLFSSL_EKU_OID
  19641. {
  19642. WOLFSSL_SMALL_STACK_STATIC const char unique[] =
  19643. "2.16.840.1.111111.100.1.10.1";
  19644. ret = wc_SetExtKeyUsageOID(req, unique, sizeof(unique), 0,
  19645. HEAP_HINT);
  19646. if (ret != 0)
  19647. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19648. }
  19649. #endif /* WOLFSSL_EKU_OID */
  19650. #endif /* WOLFSSL_CERT_EXT */
  19651. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19652. if (derSz < 0) {
  19653. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19654. }
  19655. #ifdef WOLFSSL_CERT_EXT
  19656. /* Try again with "any" flag set, will override all others */
  19657. ret = wc_SetExtKeyUsage(req, "any");
  19658. if (ret != 0)
  19659. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19660. derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
  19661. if (derSz < 0) {
  19662. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19663. }
  19664. #endif /* WOLFSSL_CERT_EXT */
  19665. ret = 0;
  19666. do {
  19667. #if defined(WOLFSSL_ASYNC_CRYPT)
  19668. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  19669. #endif
  19670. if (ret >= 0) {
  19671. ret = wc_SignCert(req->bodySz, req->sigType, der, FOURK_BUF,
  19672. key, NULL, &rng);
  19673. }
  19674. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  19675. if (ret < 0)
  19676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
  19677. derSz = (int)ret;
  19678. ret = SaveDerAndPem(der, derSz, certReqDerFile, certReqPemFile,
  19679. CERTREQ_TYPE);
  19680. if (ret != 0) {
  19681. goto exit_rsa;
  19682. }
  19683. derSz = wc_MakeCertReq_ex(req, der, FOURK_BUF, RSA_TYPE, key);
  19684. if (derSz < 0) {
  19685. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19686. }
  19687. /* Test getting the size of the buffer without providing the buffer.
  19688. * derSz is set to the "largest buffer" we are willing to allocate. */
  19689. derSz = wc_MakeCertReq(req, NULL, 10000, key, NULL);
  19690. if (derSz < 0) {
  19691. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
  19692. }
  19693. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19694. XFREE(req, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19695. der = NULL;
  19696. }
  19697. #endif /* WOLFSSL_CERT_REQ */
  19698. #endif /* WOLFSSL_CERT_GEN */
  19699. #if defined(WC_RSA_PSS) && !defined(HAVE_FIPS_VERSION) /* not supported with FIPSv1 */
  19700. /* Need to create known good signatures to test with this. */
  19701. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) && !defined(WOLFSSL_RSA_PUBLIC_ONLY) && \
  19702. !defined(WOLF_CRYPTO_CB_ONLY_RSA)
  19703. ret = rsa_pss_test(&rng, key);
  19704. if (ret != 0)
  19705. goto exit_rsa;
  19706. #endif
  19707. #endif
  19708. #if defined(WOLFSSL_HAVE_SP_RSA) && defined(USE_FAST_MATH)
  19709. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19710. /* New key to be loaded in rsa_even_mod_test(). */
  19711. if (key != NULL)
  19712. #endif
  19713. wc_FreeRsaKey(key);
  19714. /* New key to be loaded in rsa_even_mod_test(). */
  19715. ret = rsa_even_mod_test(&rng, key);
  19716. #endif
  19717. exit_rsa:
  19718. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19719. wc_DeleteRsaKey(key, &key);
  19720. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19721. wc_DeleteRsaKey(keypub, &keypub);
  19722. #endif
  19723. #ifdef WOLFSSL_TEST_CERT
  19724. XFREE(cert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19725. #endif
  19726. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19727. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19728. #else
  19729. wc_FreeRsaKey(key);
  19730. #if defined(WOLFSSL_CERT_EXT) || defined(WOLFSSL_CERT_GEN)
  19731. wc_FreeRsaKey(keypub);
  19732. #endif
  19733. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  19734. wc_FreeRng(&rng);
  19735. WC_FREE_VAR(in, HEAP_HINT);
  19736. WC_FREE_VAR(out, HEAP_HINT);
  19737. WC_FREE_VAR(plain, HEAP_HINT);
  19738. (void)res;
  19739. (void)bytes;
  19740. (void)idx;
  19741. (void)in;
  19742. (void)out;
  19743. (void)plain;
  19744. (void)idx;
  19745. (void)inStr;
  19746. (void)inLen;
  19747. (void)outSz;
  19748. (void)plainSz;
  19749. /* ret can be greater then 0 with certgen but all negative values should
  19750. * be returned and treated as an error */
  19751. if (ret >= 0) {
  19752. return 0;
  19753. }
  19754. else {
  19755. return ret;
  19756. }
  19757. }
  19758. #endif /* !NO_RSA */
  19759. #ifndef NO_DH
  19760. static wc_test_ret_t dh_fips_generate_test(WC_RNG *rng)
  19761. {
  19762. wc_test_ret_t ret = 0;
  19763. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19764. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19765. #else
  19766. DhKey key[1];
  19767. #endif
  19768. WOLFSSL_SMALL_STACK_STATIC const byte p[] = {
  19769. 0xc5, 0x7c, 0xa2, 0x4f, 0x4b, 0xd6, 0x8c, 0x3c,
  19770. 0xda, 0xc7, 0xba, 0xaa, 0xea, 0x2e, 0x5c, 0x1e,
  19771. 0x18, 0xb2, 0x7b, 0x8c, 0x55, 0x65, 0x9f, 0xea,
  19772. 0xe0, 0xa1, 0x36, 0x53, 0x2b, 0x36, 0xe0, 0x4e,
  19773. 0x3e, 0x64, 0xa9, 0xe4, 0xfc, 0x8f, 0x32, 0x62,
  19774. 0x97, 0xe4, 0xbe, 0xf7, 0xc1, 0xde, 0x07, 0x5a,
  19775. 0x89, 0x28, 0xf3, 0xfe, 0x4f, 0xfe, 0x68, 0xbc,
  19776. 0xfb, 0x0a, 0x7c, 0xa4, 0xb3, 0x14, 0x48, 0x89,
  19777. 0x9f, 0xaf, 0xb8, 0x43, 0xe2, 0xa0, 0x62, 0x5c,
  19778. 0xb4, 0x88, 0x3f, 0x06, 0x50, 0x11, 0xfe, 0x65,
  19779. 0x8d, 0x49, 0xd2, 0xf5, 0x4b, 0x74, 0x79, 0xdb,
  19780. 0x06, 0x62, 0x92, 0x89, 0xed, 0xda, 0xcb, 0x87,
  19781. 0x37, 0x16, 0xd2, 0xa1, 0x7a, 0xe8, 0xde, 0x92,
  19782. 0xee, 0x3e, 0x41, 0x4a, 0x91, 0x5e, 0xed, 0xf3,
  19783. 0x6c, 0x6b, 0x7e, 0xfd, 0x15, 0x92, 0x18, 0xfc,
  19784. 0xa7, 0xac, 0x42, 0x85, 0x57, 0xe9, 0xdc, 0xda,
  19785. 0x55, 0xc9, 0x8b, 0x28, 0x9e, 0xc1, 0xc4, 0x46,
  19786. 0x4d, 0x88, 0xed, 0x62, 0x8e, 0xdb, 0x3f, 0xb9,
  19787. 0xd7, 0xc8, 0xe3, 0xcf, 0xb8, 0x34, 0x2c, 0xd2,
  19788. 0x6f, 0x28, 0x06, 0x41, 0xe3, 0x66, 0x8c, 0xfc,
  19789. 0x72, 0xff, 0x26, 0x3b, 0x6b, 0x6c, 0x6f, 0x73,
  19790. 0xde, 0xf2, 0x90, 0x29, 0xe0, 0x61, 0x32, 0xc4,
  19791. 0x12, 0x74, 0x09, 0x52, 0xec, 0xf3, 0x1b, 0xa6,
  19792. 0x45, 0x98, 0xac, 0xf9, 0x1c, 0x65, 0x8e, 0x3a,
  19793. 0x91, 0x84, 0x4b, 0x23, 0x8a, 0xb2, 0x3c, 0xc9,
  19794. 0xfa, 0xea, 0xf1, 0x38, 0xce, 0xd8, 0x05, 0xe0,
  19795. 0xfa, 0x44, 0x68, 0x1f, 0xeb, 0xd9, 0x57, 0xb8,
  19796. 0x4a, 0x97, 0x5b, 0x88, 0xc5, 0xf1, 0xbb, 0xb0,
  19797. 0x49, 0xc3, 0x91, 0x7c, 0xd3, 0x13, 0xb9, 0x47,
  19798. 0xbb, 0x91, 0x8f, 0xe5, 0x26, 0x07, 0xab, 0xa9,
  19799. 0xc5, 0xd0, 0x3d, 0x95, 0x41, 0x26, 0x92, 0x9d,
  19800. 0x13, 0x67, 0xf2, 0x7e, 0x11, 0x88, 0xdc, 0x2d
  19801. };
  19802. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  19803. 0x4a, 0x1a, 0xf3, 0xa4, 0x92, 0xe9, 0xee, 0x74,
  19804. 0x6e, 0x57, 0xd5, 0x8c, 0x2c, 0x5b, 0x41, 0x41,
  19805. 0x5e, 0xd4, 0x55, 0x19, 0xdc, 0xd9, 0x32, 0x91,
  19806. 0xf7, 0xfd, 0xc2, 0x57, 0xff, 0x03, 0x14, 0xdb,
  19807. 0xf1, 0xb7, 0x60, 0x0c, 0x43, 0x59, 0x3f, 0xff,
  19808. 0xac, 0xf1, 0x80, 0x9a, 0x15, 0x6f, 0xd8, 0x6e,
  19809. 0xb7, 0x85, 0x18, 0xc8, 0xec, 0x4e, 0x59, 0x4a,
  19810. 0xe2, 0x91, 0x43, 0x4c, 0xeb, 0x95, 0xb6, 0x2e,
  19811. 0x9a, 0xea, 0x53, 0x68, 0x80, 0x64, 0x69, 0x40,
  19812. 0xf9, 0xec, 0xbd, 0x85, 0x89, 0x26, 0x97, 0x67,
  19813. 0xaf, 0xb0, 0xad, 0x00, 0x1b, 0xd4, 0xfd, 0x94,
  19814. 0xd3, 0xe9, 0x92, 0xb1, 0xb4, 0xbc, 0x5a, 0xaa,
  19815. 0x92, 0x80, 0x89, 0x3b, 0x39, 0x05, 0x6c, 0x22,
  19816. 0x26, 0xfe, 0x5a, 0x28, 0x6c, 0x37, 0x50, 0x5a,
  19817. 0x38, 0x99, 0xcf, 0xf3, 0xc1, 0x96, 0x45, 0xdc,
  19818. 0x01, 0xcb, 0x20, 0x87, 0xa5, 0x00, 0x8c, 0xf5,
  19819. 0x4d, 0xc2, 0xef, 0xb8, 0x9b, 0xd1, 0x87, 0xbe,
  19820. 0xed, 0xd5, 0x0a, 0x29, 0x15, 0x34, 0x59, 0x4c,
  19821. 0x3a, 0x05, 0x22, 0x05, 0x44, 0x4f, 0x9f, 0xc8,
  19822. 0x47, 0x12, 0x24, 0x8e, 0xa8, 0x79, 0xe4, 0x67,
  19823. 0xba, 0x4d, 0x5b, 0x75, 0x56, 0x95, 0xeb, 0xe8,
  19824. 0x8a, 0xfa, 0x8e, 0x01, 0x8c, 0x1b, 0x74, 0x63,
  19825. 0xd9, 0x2f, 0xf7, 0xd3, 0x44, 0x8f, 0xa8, 0xf5,
  19826. 0xaf, 0x6c, 0x4f, 0xdb, 0xe7, 0xc9, 0x6c, 0x71,
  19827. 0x22, 0xa3, 0x1d, 0xf1, 0x40, 0xb2, 0xe0, 0x9a,
  19828. 0xb6, 0x72, 0xc9, 0xc0, 0x13, 0x16, 0xa2, 0x4a,
  19829. 0xe1, 0x92, 0xc7, 0x54, 0x23, 0xab, 0x9d, 0xa1,
  19830. 0xa1, 0xe5, 0x0b, 0xed, 0xba, 0xe8, 0x84, 0x37,
  19831. 0xb2, 0xe7, 0xfe, 0x32, 0x8d, 0xfa, 0x1c, 0x53,
  19832. 0x77, 0x97, 0xc7, 0xf3, 0x48, 0xc9, 0xdb, 0x2d,
  19833. 0x75, 0x52, 0x9d, 0x42, 0x51, 0x78, 0x62, 0x68,
  19834. 0x05, 0x45, 0x15, 0xf8, 0xa2, 0x4e, 0xf3, 0x0b
  19835. };
  19836. WOLFSSL_SMALL_STACK_STATIC const byte q[] = {
  19837. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19838. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19839. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19840. 0x40, 0x52, 0xed, 0x41
  19841. };
  19842. WOLFSSL_SMALL_STACK_STATIC const byte q0[] = {
  19843. 0x00,
  19844. 0xe0, 0x35, 0x37, 0xaf, 0xb2, 0x50, 0x91, 0x8e,
  19845. 0xf2, 0x62, 0x2b, 0xd9, 0x9f, 0x6c, 0x11, 0x75,
  19846. 0xec, 0x24, 0x5d, 0x78, 0x59, 0xe7, 0x8d, 0xb5,
  19847. 0x40, 0x52, 0xed, 0x41
  19848. };
  19849. byte priv[256];
  19850. byte pub[256];
  19851. word32 privSz = sizeof(priv);
  19852. word32 pubSz = sizeof(pub);
  19853. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19854. if (key == NULL)
  19855. ERROR_OUT(MEMORY_E, exit_gen_test);
  19856. #endif
  19857. /* Parameter Validation testing. */
  19858. ret = wc_DhGenerateKeyPair(NULL, rng, priv, &privSz, pub, &pubSz);
  19859. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19860. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19861. ret = wc_DhGenerateKeyPair(key, NULL, priv, &privSz, pub, &pubSz);
  19862. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19863. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19864. ret = wc_DhGenerateKeyPair(key, rng, NULL, &privSz, pub, &pubSz);
  19865. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19866. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19867. ret = wc_DhGenerateKeyPair(key, rng, priv, NULL, pub, &pubSz);
  19868. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19870. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, NULL, &pubSz);
  19871. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19872. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19873. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, NULL);
  19874. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19875. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19876. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19877. if (ret != 0)
  19878. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19879. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q0, sizeof(q0));
  19880. if (ret != 0)
  19881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19882. wc_FreeDhKey(key);
  19883. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19884. if (ret != 0)
  19885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19886. ret = wc_DhSetKey_ex(key, p, sizeof(p), g, sizeof(g), q, sizeof(q));
  19887. if (ret != 0)
  19888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19889. /* Use API. */
  19890. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19891. #if defined(WOLFSSL_ASYNC_CRYPT)
  19892. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19893. #endif
  19894. if (ret != 0)
  19895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19896. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q0, sizeof(q0));
  19897. if (ret != 0)
  19898. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19899. wc_FreeDhKey(key);
  19900. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19901. if (ret != 0)
  19902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19903. ret = wc_DhSetKey(key, p, sizeof(p), g, sizeof(g));
  19904. if (ret != 0)
  19905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19906. ret = wc_DhCheckPubKey_ex(key, pub, pubSz, q, sizeof(q));
  19907. if (ret != 0)
  19908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19909. #ifndef HAVE_SELFTEST
  19910. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19911. if (ret != 0)
  19912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19913. /* Taint the public key so the check fails. */
  19914. pub[0]++;
  19915. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  19916. if (ret != WC_NO_ERR_TRACE(MP_CMP_E)) {
  19917. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19918. }
  19919. #ifdef WOLFSSL_KEY_GEN
  19920. wc_FreeDhKey(key);
  19921. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  19922. if (ret != 0)
  19923. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19924. ret = wc_DhGenerateParams(rng, 2048, key);
  19925. if (ret != 0)
  19926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19927. privSz = sizeof(priv);
  19928. pubSz = sizeof(pub);
  19929. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  19930. #if defined(WOLFSSL_ASYNC_CRYPT)
  19931. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  19932. #endif
  19933. if (ret != 0)
  19934. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19935. #endif /* WOLFSSL_KEY_GEN */
  19936. #endif /* HAVE_SELFTEST */
  19937. ret = 0;
  19938. exit_gen_test:
  19939. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19940. if (key) {
  19941. wc_FreeDhKey(key);
  19942. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  19943. }
  19944. #else
  19945. wc_FreeDhKey(key);
  19946. #endif
  19947. return ret;
  19948. }
  19949. static wc_test_ret_t dh_generate_test(WC_RNG *rng)
  19950. {
  19951. wc_test_ret_t ret = 0;
  19952. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19953. DhKey *smallKey = NULL;
  19954. #else
  19955. DhKey smallKey[1];
  19956. #endif
  19957. byte p[2] = { 1, 7 }; /* 263 in decimal */
  19958. byte g[2] = { 0, 2 };
  19959. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  19960. #ifdef WOLFSSL_DH_CONST
  19961. /* the table for constant DH lookup will round to the lowest byte size 21 */
  19962. byte priv[21];
  19963. byte pub[21];
  19964. #else
  19965. byte priv[2];
  19966. byte pub[2];
  19967. #endif
  19968. word32 privSz = sizeof(priv);
  19969. word32 pubSz = sizeof(pub);
  19970. #endif
  19971. int smallKey_inited = 0;
  19972. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  19973. if ((smallKey = (DhKey *)XMALLOC(sizeof(*smallKey), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  19974. return WC_TEST_RET_ENC_ERRNO;
  19975. #endif
  19976. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  19977. if (ret != 0)
  19978. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19979. smallKey_inited = 1;
  19980. /* Parameter Validation testing. */
  19981. ret = wc_InitDhKey_ex(NULL, HEAP_HINT, devId);
  19982. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  19983. return WC_TEST_RET_ENC_EC(ret);
  19984. wc_FreeDhKey(NULL);
  19985. ret = wc_DhSetKey(NULL, p, sizeof(p), g, sizeof(g));
  19986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  19987. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  19988. }
  19989. ret = wc_DhSetKey(smallKey, NULL, 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, p, 0, 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, sizeof(p), NULL, 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), g, 0);
  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, sizeof(g));
  20006. if (ret != 0)
  20007. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20008. #if !defined(WOLFSSL_SP_MATH) && !defined(HAVE_FFDHE)
  20009. /* Use API. */
  20010. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20011. #if defined(WOLFSSL_ASYNC_CRYPT)
  20012. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20013. #endif
  20014. if (ret != 0) {
  20015. ret = WC_TEST_RET_ENC_EC(ret);
  20016. }
  20017. #else
  20018. (void)rng;
  20019. #if defined(HAVE_FIPS) || !defined(WOLFSSL_NO_DH186)
  20020. ret = 0;
  20021. #endif
  20022. #endif
  20023. #if !defined(HAVE_FIPS) && defined(WOLFSSL_NO_DH186)
  20024. {
  20025. byte priv[260];
  20026. byte pub[260];
  20027. word32 privSz = sizeof(priv);
  20028. word32 pubSz = sizeof(pub);
  20029. /* test odd ball param generation with DH */
  20030. wc_FreeDhKey(smallKey);
  20031. ret = wc_InitDhKey_ex(smallKey, HEAP_HINT, devId);
  20032. if (ret != 0)
  20033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20034. /* should fail since modSz is 16 and group size is 20 */
  20035. ret = wc_DhGenerateParams(rng, 128, smallKey);
  20036. if (ret == 0)
  20037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20038. ret = wc_DhGenerateParams(rng, 2056, smallKey);
  20039. if (ret != 0)
  20040. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20041. privSz = sizeof(priv);
  20042. pubSz = sizeof(pub);
  20043. ret = wc_DhGenerateKeyPair(smallKey, rng, priv, &privSz, pub, &pubSz);
  20044. #if defined(WOLFSSL_ASYNC_CRYPT)
  20045. ret = wc_AsyncWait(ret, &smallKey->asyncDev, WC_ASYNC_FLAG_NONE);
  20046. #endif
  20047. if (ret != 0)
  20048. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_gen_test);
  20049. }
  20050. #endif /* !HAVE_FIPS and WOLFSSL_NO_DH186 */
  20051. exit_gen_test:
  20052. if (smallKey_inited)
  20053. wc_FreeDhKey(smallKey);
  20054. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20055. XFREE(smallKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20056. #endif
  20057. return ret;
  20058. }
  20059. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20060. typedef struct dh_pubvalue_test {
  20061. const byte* data;
  20062. word32 len;
  20063. } dh_pubvalue_test;
  20064. static wc_test_ret_t dh_test_check_pubvalue(void)
  20065. {
  20066. wc_test_ret_t ret;
  20067. word32 i;
  20068. WOLFSSL_SMALL_STACK_STATIC const byte prime[] = {0x01, 0x00, 0x01};
  20069. WOLFSSL_SMALL_STACK_STATIC const byte pubValZero[] = { 0x00 };
  20070. WOLFSSL_SMALL_STACK_STATIC const byte pubValZeroLong[] = { 0x00, 0x00, 0x00 };
  20071. WOLFSSL_SMALL_STACK_STATIC const byte pubValOne[] = { 0x01 };
  20072. WOLFSSL_SMALL_STACK_STATIC const byte pubValOneLong[] = { 0x00, 0x00, 0x01 };
  20073. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeMinusOne[] = { 0x01, 0x00, 0x00 };
  20074. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimeLong[] = {0x00, 0x01, 0x00, 0x01};
  20075. WOLFSSL_SMALL_STACK_STATIC const byte pubValPrimePlusOne[] = { 0x01, 0x00, 0x02 };
  20076. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig0[] = { 0x02, 0x00, 0x01 };
  20077. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooBig1[] = { 0x01, 0x01, 0x01 };
  20078. WOLFSSL_SMALL_STACK_STATIC const byte pubValTooLong[] = { 0x01, 0x00, 0x00, 0x01 };
  20079. const dh_pubvalue_test dh_pubval_fail[] = {
  20080. { prime, sizeof(prime) },
  20081. { pubValZero, sizeof(pubValZero) },
  20082. { pubValZeroLong, sizeof(pubValZeroLong) },
  20083. { pubValOne, sizeof(pubValOne) },
  20084. { pubValOneLong, sizeof(pubValOneLong) },
  20085. { pubValPrimeMinusOne, sizeof(pubValPrimeMinusOne) },
  20086. { pubValPrimeLong, sizeof(pubValPrimeLong) },
  20087. { pubValPrimePlusOne, sizeof(pubValPrimePlusOne) },
  20088. { pubValTooBig0, sizeof(pubValTooBig0) },
  20089. { pubValTooBig1, sizeof(pubValTooBig1) },
  20090. { pubValTooLong, sizeof(pubValTooLong) },
  20091. };
  20092. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwo[] = { 0x02 };
  20093. WOLFSSL_SMALL_STACK_STATIC const byte pubValTwoLong[] = { 0x00, 0x00, 0x02 };
  20094. WOLFSSL_SMALL_STACK_STATIC const byte pubValGood[] = { 0x12, 0x34 };
  20095. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLen[] = { 0x00, 0x12, 0x34 };
  20096. WOLFSSL_SMALL_STACK_STATIC const byte pubValGoodLong[] = { 0x00, 0x00, 0x12, 0x34 };
  20097. const dh_pubvalue_test dh_pubval_pass[] = {
  20098. { pubValTwo, sizeof(pubValTwo) },
  20099. { pubValTwoLong, sizeof(pubValTwoLong) },
  20100. { pubValGood, sizeof(pubValGood) },
  20101. { pubValGoodLen, sizeof(pubValGoodLen) },
  20102. { pubValGoodLong, sizeof(pubValGoodLong) },
  20103. };
  20104. for (i = 0; i < sizeof(dh_pubval_fail) / sizeof(*dh_pubval_fail); i++) {
  20105. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_fail[i].data,
  20106. dh_pubval_fail[i].len);
  20107. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  20108. return WC_TEST_RET_ENC_I(i);
  20109. }
  20110. for (i = 0; i < sizeof(dh_pubval_pass) / sizeof(*dh_pubval_pass); i++) {
  20111. ret = wc_DhCheckPubValue(prime, sizeof(prime), dh_pubval_pass[i].data,
  20112. dh_pubval_pass[i].len);
  20113. if (ret != 0)
  20114. return WC_TEST_RET_ENC_I(i);
  20115. }
  20116. return 0;
  20117. }
  20118. #endif
  20119. #if defined(HAVE_FFDHE)
  20120. #if defined(HAVE_FFDHE_4096)
  20121. #define MAX_DH_PRIV_SZ 39
  20122. #define MAX_DH_KEY_SZ 512
  20123. #elif defined(HAVE_FFDHE_3072)
  20124. #define MAX_DH_PRIV_SZ 34
  20125. #define MAX_DH_KEY_SZ 384
  20126. #else
  20127. #define MAX_DH_PRIV_SZ 29
  20128. #define MAX_DH_KEY_SZ 256
  20129. #endif
  20130. #ifndef WC_NO_RNG
  20131. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20132. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20133. #ifdef HAVE_PUBLIC_FFDHE
  20134. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
  20135. #else
  20136. static wc_test_ret_t dh_ffdhe_test(WC_RNG *rng, int name)
  20137. #endif
  20138. {
  20139. wc_test_ret_t ret;
  20140. word32 privSz, pubSz, privSz2, pubSz2;
  20141. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20142. byte *priv = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20143. byte *pub = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20144. byte *priv2 = (byte*)XMALLOC(MAX_DH_PRIV_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20145. byte *pub2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20146. byte *agree = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20147. byte *agree2 = (byte*)XMALLOC(MAX_DH_KEY_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20148. DhKey *key = (DhKey*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20149. DhKey *key2 = (DhKey*)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20150. #else
  20151. byte priv[MAX_DH_PRIV_SZ];
  20152. byte pub[MAX_DH_KEY_SZ];
  20153. byte priv2[MAX_DH_PRIV_SZ];
  20154. byte pub2[MAX_DH_KEY_SZ];
  20155. byte agree[MAX_DH_KEY_SZ];
  20156. byte agree2[MAX_DH_KEY_SZ];
  20157. DhKey key[1];
  20158. DhKey key2[1];
  20159. #endif
  20160. word32 agreeSz = MAX_DH_KEY_SZ;
  20161. word32 agreeSz2 = MAX_DH_KEY_SZ;
  20162. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20163. if ((priv == NULL) ||
  20164. (pub == NULL) ||
  20165. (priv2 == NULL) ||
  20166. (pub2 == NULL) ||
  20167. (agree == NULL) ||
  20168. (agree2 == NULL) ||
  20169. (key == NULL) ||
  20170. (key2 == NULL))
  20171. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20172. #endif
  20173. pubSz = MAX_DH_KEY_SZ;
  20174. pubSz2 = MAX_DH_KEY_SZ;
  20175. #ifdef HAVE_PUBLIC_FFDHE
  20176. privSz = MAX_DH_PRIV_SZ;
  20177. privSz2 = MAX_DH_PRIV_SZ;
  20178. #else
  20179. privSz = wc_DhGetNamedKeyMinSize(name);
  20180. privSz2 = privSz;
  20181. #endif
  20182. XMEMSET(key, 0, sizeof(*key));
  20183. XMEMSET(key2, 0, sizeof(*key2));
  20184. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20185. if (ret != 0)
  20186. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20187. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20188. if (ret != 0)
  20189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20190. #ifdef HAVE_PUBLIC_FFDHE
  20191. ret = wc_DhSetKey(key, params->p, params->p_len, params->g, params->g_len);
  20192. #else
  20193. ret = wc_DhSetNamedKey(key, name);
  20194. #endif
  20195. if (ret != 0)
  20196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20197. #ifdef HAVE_PUBLIC_FFDHE
  20198. ret = wc_DhSetKey(key2, params->p, params->p_len, params->g,
  20199. params->g_len);
  20200. #else
  20201. ret = wc_DhSetNamedKey(key2, name);
  20202. #endif
  20203. if (ret != 0)
  20204. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20205. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20206. #if defined(WOLFSSL_ASYNC_CRYPT)
  20207. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20208. #endif
  20209. if (ret != 0)
  20210. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20211. ret = wc_DhGenerateKeyPair(key2, rng, priv2, &privSz2, pub2, &pubSz2);
  20212. #if defined(WOLFSSL_ASYNC_CRYPT)
  20213. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20214. #endif
  20215. if (ret != 0)
  20216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20217. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20218. #if defined(WOLFSSL_ASYNC_CRYPT)
  20219. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20220. #endif
  20221. if (ret != 0)
  20222. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20223. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20224. #if defined(WOLFSSL_ASYNC_CRYPT)
  20225. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20226. #endif
  20227. if (ret != 0)
  20228. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20229. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20230. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20231. }
  20232. #if (defined(WOLFSSL_HAVE_SP_DH) || defined(USE_FAST_MATH)) && \
  20233. !defined(HAVE_INTEL_QA)
  20234. /* Make p even */
  20235. key->p.dp[0] &= (mp_digit)-2;
  20236. if (ret != 0)
  20237. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20238. ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
  20239. #if defined(WOLFSSL_ASYNC_CRYPT)
  20240. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20241. #endif
  20242. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20243. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E))
  20244. {
  20245. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20246. }
  20247. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20248. #if defined(WOLFSSL_ASYNC_CRYPT)
  20249. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20250. #endif
  20251. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20252. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20253. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20254. {
  20255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20256. }
  20257. #ifndef HAVE_SELFTEST
  20258. ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
  20259. if (ret != WC_NO_ERR_TRACE(MP_VAL) &&
  20260. ret != WC_NO_ERR_TRACE(MP_EXPTMOD_E) &&
  20261. ret != WC_NO_ERR_TRACE(MP_CMP_E) &&
  20262. ret != WC_NO_ERR_TRACE(ASYNC_OP_E))
  20263. {
  20264. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20265. }
  20266. #endif
  20267. /* Getting here means success - set ret to 0. */
  20268. ret = 0;
  20269. #endif /* (SP DH or Fast Math) and not Intel QuickAssist */
  20270. done:
  20271. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) && \
  20272. !defined(WC_NO_RNG)
  20273. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20274. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20275. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20276. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20277. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20278. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20279. if (key) {
  20280. wc_FreeDhKey(key);
  20281. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20282. }
  20283. if (key2) {
  20284. wc_FreeDhKey(key2);
  20285. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20286. }
  20287. #else
  20288. wc_FreeDhKey(key);
  20289. wc_FreeDhKey(key2);
  20290. #endif
  20291. return ret;
  20292. }
  20293. #endif /* !(HAVE_FIPS_VERSION == 2 && WOLFSSL_SP_ARMxx_ASM) */
  20294. #endif /* !WC_NO_RNG */
  20295. #endif /* HAVE_FFDHE */
  20296. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dh_test(void)
  20297. {
  20298. wc_test_ret_t ret;
  20299. word32 bytes;
  20300. word32 idx = 0;
  20301. word32 privSz = 0;
  20302. word32 pubSz = 0;
  20303. word32 privSz2 = 0;
  20304. word32 pubSz2 = 0;
  20305. #ifndef WC_NO_RNG
  20306. WC_RNG rng;
  20307. int rngInit = 0;
  20308. #endif
  20309. int keyInit = 0, key2Init = 0;
  20310. #define DH_TEST_TMP_SIZE 1024
  20311. #if !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  20312. #define DH_TEST_BUF_SIZE 256
  20313. #else
  20314. #define DH_TEST_BUF_SIZE 512
  20315. #endif
  20316. #ifndef WC_NO_RNG
  20317. word32 agreeSz = DH_TEST_BUF_SIZE;
  20318. word32 agreeSz2 = DH_TEST_BUF_SIZE;
  20319. #endif
  20320. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20321. DhKey *key = (DhKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20322. DhKey *key2 = (DhKey *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20323. byte *tmp = (byte *)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20324. #else
  20325. DhKey key[1];
  20326. DhKey key2[1];
  20327. byte tmp[DH_TEST_TMP_SIZE];
  20328. #endif
  20329. #ifndef WC_NO_RNG
  20330. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20331. byte *priv = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20332. byte *pub = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20333. byte *priv2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20334. byte *pub2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20335. byte *agree = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20336. byte *agree2 = (byte *)XMALLOC(DH_TEST_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20337. if (priv == NULL || pub == NULL || priv2 == NULL || pub2 == NULL ||
  20338. agree == NULL || agree2 == NULL) {
  20339. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20340. }
  20341. #else
  20342. byte priv[DH_TEST_BUF_SIZE];
  20343. byte pub[DH_TEST_BUF_SIZE];
  20344. byte priv2[DH_TEST_BUF_SIZE];
  20345. byte pub2[DH_TEST_BUF_SIZE];
  20346. byte agree[DH_TEST_BUF_SIZE];
  20347. byte agree2[DH_TEST_BUF_SIZE];
  20348. #endif
  20349. #endif /* !WC_NO_RNG */
  20350. WOLFSSL_ENTER("dh_test");
  20351. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20352. if (key == NULL || key2 == NULL || tmp == NULL) {
  20353. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20354. }
  20355. #endif
  20356. #ifdef USE_CERT_BUFFERS_1024
  20357. XMEMCPY(tmp, dh_key_der_1024, (size_t)sizeof_dh_key_der_1024);
  20358. bytes = (size_t)sizeof_dh_key_der_1024;
  20359. #elif defined(USE_CERT_BUFFERS_2048)
  20360. XMEMCPY(tmp, dh_key_der_2048, (size_t)sizeof_dh_key_der_2048);
  20361. bytes = (size_t)sizeof_dh_key_der_2048;
  20362. #elif defined(USE_CERT_BUFFERS_3072)
  20363. XMEMCPY(tmp, dh_key_der_3072, (size_t)sizeof_dh_key_der_3072);
  20364. bytes = (size_t)sizeof_dh_key_der_3072;
  20365. #elif defined(USE_CERT_BUFFERS_4096)
  20366. XMEMCPY(tmp, dh_key_der_4096, (size_t)sizeof_dh_key_der_4096);
  20367. bytes = (size_t)sizeof_dh_key_der_4096;
  20368. #elif defined(NO_ASN)
  20369. /* don't use file, no DER parsing */
  20370. #elif !defined(NO_FILESYSTEM)
  20371. {
  20372. XFILE file = XFOPEN(dhParamsFile, "rb");
  20373. if (! file)
  20374. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20375. bytes = (word32) XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20376. XFCLOSE(file);
  20377. if (bytes == 0)
  20378. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20379. }
  20380. #else
  20381. /* No DH key to use. */
  20382. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20383. #endif /* USE_CERT_BUFFERS */
  20384. (void)idx;
  20385. (void)tmp;
  20386. (void)bytes;
  20387. pubSz = DH_TEST_BUF_SIZE;
  20388. pubSz2 = DH_TEST_BUF_SIZE;
  20389. privSz = DH_TEST_BUF_SIZE;
  20390. privSz2 = DH_TEST_BUF_SIZE;
  20391. #ifndef WC_NO_RNG
  20392. XMEMSET(&rng, 0, sizeof(rng));
  20393. #endif
  20394. /* Use API for coverage. */
  20395. ret = wc_InitDhKey(key);
  20396. if (ret != 0)
  20397. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20398. wc_FreeDhKey(key);
  20399. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20400. if (ret != 0)
  20401. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20402. keyInit = 1;
  20403. ret = wc_InitDhKey_ex(key2, HEAP_HINT, devId);
  20404. if (ret != 0)
  20405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20406. key2Init = 1;
  20407. #ifdef NO_ASN
  20408. #ifndef WOLFSSL_SP_MATH
  20409. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20410. if (ret != 0)
  20411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20412. ret = wc_DhSetKey(key2, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20413. if (ret != 0)
  20414. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20415. #else
  20416. ret = wc_DhSetKey(key, dh2048_p, sizeof(dh2048_p), dh2048_g,
  20417. sizeof(dh2048_g));
  20418. if (ret != 0)
  20419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20420. ret = wc_DhSetKey(key2, 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. #endif
  20425. #else
  20426. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20427. if (ret != 0)
  20428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20429. idx = 0;
  20430. ret = wc_DhKeyDecode(tmp, &idx, key2, bytes);
  20431. if (ret != 0)
  20432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20433. #endif
  20434. #ifndef WC_NO_RNG
  20435. #ifndef HAVE_FIPS
  20436. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20437. #else
  20438. ret = wc_InitRng(&rng);
  20439. #endif
  20440. if (ret != 0)
  20441. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20442. rngInit = 1;
  20443. ret = wc_DhGenerateKeyPair(key, &rng, priv, &privSz, pub, &pubSz);
  20444. #if defined(WOLFSSL_ASYNC_CRYPT)
  20445. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20446. #endif
  20447. if (ret != 0)
  20448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20449. ret = wc_DhGenerateKeyPair(key2, &rng, priv2, &privSz2, pub2, &pubSz2);
  20450. #if defined(WOLFSSL_ASYNC_CRYPT)
  20451. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20452. #endif
  20453. if (ret != 0)
  20454. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20455. ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20456. #if defined(WOLFSSL_ASYNC_CRYPT)
  20457. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  20458. #endif
  20459. if (ret != 0)
  20460. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20461. ret = wc_DhAgree(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20462. #if defined(WOLFSSL_ASYNC_CRYPT)
  20463. ret = wc_AsyncWait(ret, &key2->asyncDev, WC_ASYNC_FLAG_NONE);
  20464. #endif
  20465. if (ret != 0)
  20466. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20467. if (agreeSz != agreeSz2 || XMEMCMP(agree, agree2, agreeSz)) {
  20468. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20469. }
  20470. #if (!defined(HAVE_FIPS) || FIPS_VERSION_GE(7,0)) && \
  20471. !defined(HAVE_SELFTEST)
  20472. agreeSz = DH_TEST_BUF_SIZE;
  20473. agreeSz2 = DH_TEST_BUF_SIZE;
  20474. ret = wc_DhAgree_ct(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
  20475. if (ret != 0)
  20476. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20477. ret = wc_DhAgree_ct(key2, agree2, &agreeSz2, priv2, privSz2, pub, pubSz);
  20478. if (ret != 0)
  20479. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20480. #ifdef WOLFSSL_PUBLIC_MP
  20481. if (agreeSz != (word32)mp_unsigned_bin_size(&key->p))
  20482. {
  20483. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20484. }
  20485. #endif
  20486. if (agreeSz != agreeSz2)
  20487. {
  20488. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20489. }
  20490. if (XMEMCMP(agree, agree2, agreeSz) != 0)
  20491. {
  20492. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20493. }
  20494. #endif /* (!HAVE_FIPS || FIPS_VERSION_GE(7,0)) && !HAVE_SELFTEST */
  20495. #endif /* !WC_NO_RNG */
  20496. #if defined(WOLFSSL_KEY_GEN) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20497. ret = wc_DhCheckPrivKey(NULL, NULL, 0);
  20498. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20500. ret = wc_DhCheckPrivKey(key, priv, privSz);
  20501. if (ret != 0)
  20502. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20503. ret = wc_DhExportParamsRaw(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  20504. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  20505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20506. {
  20507. word32 pSz, qSz, gSz;
  20508. ret = wc_DhExportParamsRaw(key, NULL, &pSz, NULL, &qSz, NULL, &gSz);
  20509. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  20510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20511. }
  20512. #endif
  20513. /* Test DH key import / export */
  20514. #if defined(WOLFSSL_DH_EXTRA) && !defined(NO_FILESYSTEM) && \
  20515. (!defined(HAVE_FIPS) || \
  20516. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  20517. wc_FreeDhKey(key);
  20518. ret = wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20519. if (ret != 0)
  20520. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20521. #ifndef NO_ASN
  20522. {
  20523. /* DH Private - Key Export / Import */
  20524. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20525. byte *tmp2;
  20526. #else
  20527. byte tmp2[DH_TEST_TMP_SIZE];
  20528. #endif
  20529. #if defined(USE_CERT_BUFFERS_2048)
  20530. XMEMCPY(tmp, dh_ffdhe_statickey_der_2048, sizeof_dh_ffdhe_statickey_der_2048);
  20531. bytes = sizeof_dh_ffdhe_statickey_der_2048;
  20532. #else
  20533. XFILE file = XFOPEN(dhKeyFile, "rb");
  20534. if (!file)
  20535. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20536. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20537. XFCLOSE(file);
  20538. if (bytes == 0)
  20539. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20540. #endif
  20541. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20542. tmp2 = (byte*)XMALLOC(DH_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20543. if (tmp2 == NULL)
  20544. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20545. #endif
  20546. idx = 0;
  20547. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20548. /* Import DH Private key as DER */
  20549. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20550. if (ret == 0) {
  20551. /* Export as DER */
  20552. idx = DH_TEST_TMP_SIZE;
  20553. ret = wc_DhPrivKeyToDer(key, tmp2, &idx);
  20554. }
  20555. /* Verify export matches original */
  20556. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20557. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20558. }
  20559. /* DH Public Key - Export / Import */
  20560. #if defined(USE_CERT_BUFFERS_2048)
  20561. XMEMCPY(tmp, dh_ffdhe_pub_statickey_der_2048, sizeof_dh_ffdhe_pub_statickey_der_2048);
  20562. bytes = sizeof_dh_ffdhe_pub_statickey_der_2048;
  20563. #else
  20564. file = XFOPEN(dhKeyPubFile, "rb");
  20565. if (!file)
  20566. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20567. bytes = (word32)XFREAD(tmp, 1, DH_TEST_TMP_SIZE, file);
  20568. XFCLOSE(file);
  20569. if (bytes == 0)
  20570. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  20571. #endif
  20572. /* for HAVE_WOLF_BIGINT prevent leak */
  20573. wc_FreeDhKey(key);
  20574. (void)wc_InitDhKey_ex(key, HEAP_HINT, devId);
  20575. idx = 0;
  20576. XMEMSET(tmp2, 0, DH_TEST_TMP_SIZE);
  20577. /* Import DH Public key as DER */
  20578. ret = wc_DhKeyDecode(tmp, &idx, key, bytes);
  20579. if (ret == 0) {
  20580. /* Export as DER */
  20581. idx = DH_TEST_TMP_SIZE;
  20582. ret = wc_DhPubKeyToDer(key, tmp2, &idx);
  20583. }
  20584. /* Verify export matches original */
  20585. if (ret <= 0 || bytes != idx || XMEMCMP(tmp, tmp2, bytes) != 0) {
  20586. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  20587. }
  20588. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20589. XFREE(tmp2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20590. #endif
  20591. }
  20592. #else
  20593. ret = wc_DhSetKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g));
  20594. if (ret != 0)
  20595. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20596. #endif /* !NO_ASN */
  20597. privSz = DH_TEST_BUF_SIZE;
  20598. pubSz = DH_TEST_BUF_SIZE;
  20599. ret = wc_DhExportKeyPair(key, priv, &privSz, pub, &pubSz);
  20600. if (ret != 0)
  20601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20602. ret = wc_DhImportKeyPair(key2, priv, privSz, pub, pubSz);
  20603. if (ret != 0)
  20604. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20605. #endif /* WOLFSSL_DH_EXTRA && !NO_FILESYSTEM && !FIPS <= 2 */
  20606. #ifndef WC_NO_RNG
  20607. ret = dh_generate_test(&rng);
  20608. if (ret != 0)
  20609. ERROR_OUT(ret, done);
  20610. ret = dh_fips_generate_test(&rng);
  20611. if (ret != 0)
  20612. ERROR_OUT(ret, done);
  20613. #endif /* !WC_NO_RNG */
  20614. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  20615. ret = dh_test_check_pubvalue();
  20616. if (ret != 0)
  20617. ERROR_OUT(ret, done);
  20618. #endif
  20619. #if !(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION == 2) && \
  20620. (defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM32_ASM)))
  20621. /* RNG with DH and SP_ASM code not supported in the in-lined FIPS ASM code,
  20622. * this will be available for testing in the 140-3 module */
  20623. #ifndef WC_NO_RNG
  20624. /* Specialized code for key gen when using FFDHE-2048, FFDHE-3072 and FFDHE-4096 */
  20625. #ifdef HAVE_FFDHE_2048
  20626. #ifdef HAVE_PUBLIC_FFDHE
  20627. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe2048_Get());
  20628. #else
  20629. ret = dh_ffdhe_test(&rng, WC_FFDHE_2048);
  20630. #endif
  20631. if (ret != 0)
  20632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20633. #endif
  20634. #ifdef HAVE_FFDHE_3072
  20635. #ifdef HAVE_PUBLIC_FFDHE
  20636. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe3072_Get());
  20637. #else
  20638. ret = dh_ffdhe_test(&rng, WC_FFDHE_3072);
  20639. #endif
  20640. if (ret != 0)
  20641. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20642. #endif
  20643. #ifdef HAVE_FFDHE_4096
  20644. #ifdef HAVE_PUBLIC_FFDHE
  20645. ret = dh_ffdhe_test(&rng, wc_Dh_ffdhe4096_Get());
  20646. #else
  20647. ret = dh_ffdhe_test(&rng, WC_FFDHE_4096);
  20648. #endif
  20649. if (ret != 0)
  20650. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20651. #endif
  20652. #endif /* !WC_NO_RNG */
  20653. #endif /* HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM64_ASM */
  20654. wc_FreeDhKey(key);
  20655. keyInit = 0;
  20656. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  20657. !defined(WOLFSSL_OLD_PRIME_CHECK) && !defined(WC_NO_RNG)
  20658. /* Test Check Key */
  20659. ret = wc_DhSetCheckKey(key, dh_p, sizeof(dh_p), dh_g, sizeof(dh_g),
  20660. NULL, 0, 0, &rng);
  20661. if (ret != 0)
  20662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  20663. keyInit = 1; /* DhSetCheckKey also initializes the key, free it */
  20664. #endif
  20665. done:
  20666. #ifndef WC_NO_RNG
  20667. if (rngInit)
  20668. wc_FreeRng(&rng);
  20669. #endif
  20670. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20671. if (key) {
  20672. if (keyInit)
  20673. wc_FreeDhKey(key);
  20674. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20675. }
  20676. if (key2) {
  20677. if (key2Init)
  20678. wc_FreeDhKey(key2);
  20679. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20680. }
  20681. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20682. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20683. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20684. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20685. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20686. XFREE(agree, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20687. XFREE(agree2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20688. #else
  20689. if (keyInit)
  20690. wc_FreeDhKey(key);
  20691. if (key2Init)
  20692. wc_FreeDhKey(key2);
  20693. #endif
  20694. (void)privSz;
  20695. (void)pubSz;
  20696. (void)pubSz2;
  20697. (void)privSz2;
  20698. return ret;
  20699. #undef DH_TEST_BUF_SIZE
  20700. #undef DH_TEST_TMP_SIZE
  20701. }
  20702. #endif /* NO_DH */
  20703. #ifndef NO_DSA
  20704. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dsa_test(void)
  20705. {
  20706. wc_test_ret_t ret = 0;
  20707. int answer;
  20708. word32 bytes;
  20709. word32 idx = 0;
  20710. WC_RNG rng;
  20711. int rng_inited = 0;
  20712. wc_Sha sha;
  20713. byte hash[WC_SHA_DIGEST_SIZE];
  20714. byte signature[40];
  20715. int key_inited = 0;
  20716. #ifdef WOLFSSL_KEY_GEN
  20717. byte* der = 0;
  20718. int derIn_inited = 0;
  20719. int genKey_inited = 0;
  20720. #endif
  20721. #define DSA_TEST_TMP_SIZE 1024
  20722. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20723. byte *tmp = (byte *)XMALLOC(DSA_TEST_TMP_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20724. DsaKey *key = (DsaKey *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20725. #ifdef WOLFSSL_KEY_GEN
  20726. DsaKey *derIn = (DsaKey *)XMALLOC(sizeof *derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20727. DsaKey *genKey = (DsaKey *)XMALLOC(sizeof *genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20728. #endif
  20729. WOLFSSL_ENTER("dsa_test");
  20730. if ((tmp == NULL) ||
  20731. (key == NULL)
  20732. #ifdef WOLFSSL_KEY_GEN
  20733. || (derIn == NULL)
  20734. || (genKey == NULL)
  20735. #endif
  20736. ) {
  20737. ret = WC_TEST_RET_ENC_NC;
  20738. goto out;
  20739. }
  20740. #else
  20741. byte tmp[1024];
  20742. DsaKey key[1];
  20743. #ifdef WOLFSSL_KEY_GEN
  20744. DsaKey derIn[1];
  20745. DsaKey genKey[1];
  20746. #endif
  20747. #endif
  20748. #ifdef USE_CERT_BUFFERS_1024
  20749. XMEMCPY(tmp, dsa_key_der_1024, sizeof_dsa_key_der_1024);
  20750. bytes = sizeof_dsa_key_der_1024;
  20751. #elif defined(USE_CERT_BUFFERS_2048)
  20752. XMEMCPY(tmp, dsa_key_der_2048, sizeof_dsa_key_der_2048);
  20753. bytes = sizeof_dsa_key_der_2048;
  20754. #else
  20755. {
  20756. XFILE file = XFOPEN(dsaKey, "rb");
  20757. if (!file)
  20758. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20759. bytes = (word32) XFREAD(tmp, 1, DSA_TEST_TMP_SIZE, file);
  20760. XFCLOSE(file);
  20761. if (bytes == 0)
  20762. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  20763. }
  20764. #endif /* USE_CERT_BUFFERS */
  20765. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  20766. if (ret != 0)
  20767. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20768. wc_ShaUpdate(&sha, tmp, bytes);
  20769. wc_ShaFinal(&sha, hash);
  20770. wc_ShaFree(&sha);
  20771. ret = wc_InitDsaKey(key);
  20772. if (ret != 0)
  20773. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20774. key_inited = 1;
  20775. ret = wc_DsaPrivateKeyDecode(tmp, &idx, key, bytes);
  20776. if (ret != 0)
  20777. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20778. #ifndef HAVE_FIPS
  20779. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  20780. #else
  20781. ret = wc_InitRng(&rng);
  20782. #endif
  20783. if (ret != 0)
  20784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20785. rng_inited = 1;
  20786. ret = wc_DsaSign(hash, signature, key, &rng);
  20787. if (ret != 0)
  20788. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20789. ret = wc_DsaVerify(hash, signature, key, &answer);
  20790. if (ret != 0)
  20791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20792. if (answer != 1)
  20793. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20794. wc_FreeDsaKey(key);
  20795. key_inited = 0;
  20796. ret = wc_InitDsaKey_h(key, NULL);
  20797. if (ret != 0)
  20798. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20799. key_inited = 1;
  20800. #ifdef WOLFSSL_KEY_GEN
  20801. {
  20802. int derSz = 0;
  20803. ret = wc_InitDsaKey(genKey);
  20804. if (ret != 0)
  20805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20806. genKey_inited = 1;
  20807. ret = wc_MakeDsaParameters(&rng, 1024, genKey);
  20808. if (ret != 0)
  20809. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20810. ret = wc_MakeDsaKey(&rng, genKey);
  20811. if (ret != 0)
  20812. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20813. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20814. if (der == NULL)
  20815. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  20816. derSz = wc_DsaKeyToDer(genKey, der, FOURK_BUF);
  20817. if (derSz < 0)
  20818. ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), out);
  20819. ret = SaveDerAndPem(der, derSz, keyDerFile, keyPemFile,
  20820. DSA_PRIVATEKEY_TYPE);
  20821. if (ret != 0)
  20822. goto out;
  20823. ret = wc_InitDsaKey(derIn);
  20824. if (ret != 0)
  20825. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20826. derIn_inited = 1;
  20827. idx = 0;
  20828. ret = wc_DsaPrivateKeyDecode(der, &idx, derIn, (word32)derSz);
  20829. if (ret != 0)
  20830. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  20831. }
  20832. #endif /* WOLFSSL_KEY_GEN */
  20833. out:
  20834. #ifdef WOLFSSL_KEY_GEN
  20835. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20836. #endif
  20837. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20838. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20839. if (key) {
  20840. if (key_inited)
  20841. wc_FreeDsaKey(key);
  20842. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20843. }
  20844. #ifdef WOLFSSL_KEY_GEN
  20845. if (derIn) {
  20846. if (derIn_inited)
  20847. wc_FreeDsaKey(derIn);
  20848. XFREE(derIn, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20849. }
  20850. if (genKey) {
  20851. if (genKey_inited)
  20852. wc_FreeDsaKey(genKey);
  20853. XFREE(genKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20854. }
  20855. #endif
  20856. #else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
  20857. if (key_inited)
  20858. wc_FreeDsaKey(key);
  20859. #ifdef WOLFSSL_KEY_GEN
  20860. if (derIn_inited)
  20861. wc_FreeDsaKey(derIn);
  20862. if (genKey_inited)
  20863. wc_FreeDsaKey(genKey);
  20864. #endif
  20865. #endif
  20866. if (rng_inited)
  20867. wc_FreeRng(&rng);
  20868. return ret;
  20869. }
  20870. #endif /* NO_DSA */
  20871. #ifdef WOLFCRYPT_HAVE_SRP
  20872. static wc_test_ret_t generate_random_salt(byte *buf, word32 size)
  20873. {
  20874. wc_test_ret_t ret = WC_TEST_RET_ENC_NC;
  20875. WC_RNG rng;
  20876. if(NULL == buf || !size)
  20877. return WC_TEST_RET_ENC_NC;
  20878. if (buf && size && wc_InitRng_ex(&rng, HEAP_HINT, devId) == 0) {
  20879. ret = wc_RNG_GenerateBlock(&rng, (byte *)buf, size);
  20880. wc_FreeRng(&rng);
  20881. }
  20882. return ret;
  20883. }
  20884. static wc_test_ret_t srp_test_digest(SrpType dgstType)
  20885. {
  20886. wc_test_ret_t r;
  20887. byte clientPubKey[192]; /* A */
  20888. byte serverPubKey[192]; /* B */
  20889. word32 clientPubKeySz = 192;
  20890. word32 serverPubKeySz = 192;
  20891. byte username[] = "user";
  20892. word32 usernameSz = 4;
  20893. byte password[] = "password";
  20894. word32 passwordSz = 8;
  20895. WOLFSSL_SMALL_STACK_STATIC const byte N[] = {
  20896. 0xfc, 0x58, 0x7a, 0x8a, 0x70, 0xfb, 0x5a, 0x9a,
  20897. 0x5d, 0x39, 0x48, 0xbf, 0x1c, 0x46, 0xd8, 0x3b,
  20898. 0x7a, 0xe9, 0x1f, 0x85, 0x36, 0x18, 0xc4, 0x35,
  20899. 0x3f, 0xf8, 0x8a, 0x8f, 0x8c, 0x10, 0x2e, 0x01,
  20900. 0x58, 0x1d, 0x41, 0xcb, 0xc4, 0x47, 0xa8, 0xaf,
  20901. 0x9a, 0x6f, 0x58, 0x14, 0xa4, 0x68, 0xf0, 0x9c,
  20902. 0xa6, 0xe7, 0xbf, 0x0d, 0xe9, 0x62, 0x0b, 0xd7,
  20903. 0x26, 0x46, 0x5b, 0x27, 0xcb, 0x4c, 0xf9, 0x7e,
  20904. 0x1e, 0x8b, 0xe6, 0xdd, 0x29, 0xb7, 0xb7, 0x15,
  20905. 0x2e, 0xcf, 0x23, 0xa6, 0x4b, 0x97, 0x9f, 0x89,
  20906. 0xd4, 0x86, 0xc4, 0x90, 0x63, 0x92, 0xf4, 0x30,
  20907. 0x26, 0x69, 0x48, 0x9d, 0x7a, 0x4f, 0xad, 0xb5,
  20908. 0x6a, 0x51, 0xad, 0xeb, 0xf9, 0x90, 0x31, 0x77,
  20909. 0x53, 0x30, 0x2a, 0x85, 0xf7, 0x11, 0x21, 0x0c,
  20910. 0xb8, 0x4b, 0x56, 0x03, 0x5e, 0xbb, 0x25, 0x33,
  20911. 0x7c, 0xd9, 0x5a, 0xd1, 0x5c, 0xb2, 0xd4, 0x53,
  20912. 0xc5, 0x16, 0x68, 0xf0, 0xdf, 0x48, 0x55, 0x3e,
  20913. 0xd4, 0x59, 0x87, 0x64, 0x59, 0xaa, 0x39, 0x01,
  20914. 0x45, 0x89, 0x9c, 0x72, 0xff, 0xdd, 0x8f, 0x6d,
  20915. 0xa0, 0x42, 0xbc, 0x6f, 0x6e, 0x62, 0x18, 0x2d,
  20916. 0x50, 0xe8, 0x18, 0x97, 0x87, 0xfc, 0xef, 0x1f,
  20917. 0xf5, 0x53, 0x68, 0xe8, 0x49, 0xd1, 0xa2, 0xe8,
  20918. 0xb9, 0x26, 0x03, 0xba, 0xb5, 0x58, 0x6f, 0x6c,
  20919. 0x8b, 0x08, 0xa1, 0x7b, 0x6f, 0x42, 0xc9, 0x53
  20920. };
  20921. WOLFSSL_SMALL_STACK_STATIC const byte g[] = {
  20922. 0x02
  20923. };
  20924. byte salt[10];
  20925. byte verifier[192];
  20926. word32 v_size = sizeof(verifier);
  20927. word32 clientProofSz = SRP_MAX_DIGEST_SIZE;
  20928. word32 serverProofSz = SRP_MAX_DIGEST_SIZE;
  20929. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20930. Srp *cli = (Srp *)XMALLOC(sizeof *cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20931. Srp *srv = (Srp *)XMALLOC(sizeof *srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20932. byte *clientProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20933. DYNAMIC_TYPE_TMP_BUFFER); /* M1 */
  20934. byte *serverProof = (byte *)XMALLOC(SRP_MAX_DIGEST_SIZE, HEAP_HINT,
  20935. DYNAMIC_TYPE_TMP_BUFFER); /* M2 */
  20936. if ((cli == NULL) ||
  20937. (srv == NULL) ||
  20938. (clientProof == NULL) ||
  20939. (serverProof == NULL)) {
  20940. r = WC_TEST_RET_ENC_NC;
  20941. goto out;
  20942. }
  20943. #else
  20944. Srp cli[1], srv[1];
  20945. byte clientProof[SRP_MAX_DIGEST_SIZE]; /* M1 */
  20946. byte serverProof[SRP_MAX_DIGEST_SIZE]; /* M2 */
  20947. #endif
  20948. /* set as 0's so if second init on srv not called SrpTerm is not on
  20949. * garbage values */
  20950. XMEMSET(srv, 0, sizeof *srv);
  20951. XMEMSET(cli, 0, sizeof *cli);
  20952. /* generating random salt */
  20953. r = generate_random_salt(salt, sizeof(salt));
  20954. /* client knows username and password. */
  20955. /* server knows N, g, salt and verifier. */
  20956. if (!r) r = wc_SrpInit_ex(cli, dgstType, SRP_CLIENT_SIDE, HEAP_HINT, devId);
  20957. if (!r) r = wc_SrpSetUsername(cli, username, usernameSz);
  20958. /* loading N, g and salt in advance to generate the verifier. */
  20959. if (!r) r = wc_SrpSetParams(cli, N, sizeof(N),
  20960. g, sizeof(g),
  20961. salt, sizeof(salt));
  20962. if (!r) r = wc_SrpSetPassword(cli, password, passwordSz);
  20963. if (!r) r = wc_SrpGetVerifier(cli, verifier, &v_size);
  20964. /* client sends username to server */
  20965. if (!r) r = wc_SrpInit_ex(srv, dgstType, SRP_SERVER_SIDE, HEAP_HINT, devId);
  20966. if (!r) r = wc_SrpSetUsername(srv, username, usernameSz);
  20967. if (!r) r = wc_SrpSetParams(srv, N, sizeof(N),
  20968. g, sizeof(g),
  20969. salt, sizeof(salt));
  20970. if (!r) r = wc_SrpSetVerifier(srv, verifier, v_size);
  20971. if (!r) r = wc_SrpGetPublic(srv, serverPubKey, &serverPubKeySz);
  20972. /* server sends N, g, salt and B to client */
  20973. if (!r) r = wc_SrpGetPublic(cli, clientPubKey, &clientPubKeySz);
  20974. if (!r) r = wc_SrpComputeKey(cli, clientPubKey, clientPubKeySz,
  20975. serverPubKey, serverPubKeySz);
  20976. if (!r) r = wc_SrpGetProof(cli, clientProof, &clientProofSz);
  20977. /* client sends A and M1 to server */
  20978. if (!r) r = wc_SrpComputeKey(srv, clientPubKey, clientPubKeySz,
  20979. serverPubKey, serverPubKeySz);
  20980. if (!r) r = wc_SrpVerifyPeersProof(srv, clientProof, clientProofSz);
  20981. if (!r) r = wc_SrpGetProof(srv, serverProof, &serverProofSz);
  20982. /* server sends M2 to client */
  20983. if (!r) r = wc_SrpVerifyPeersProof(cli, serverProof, serverProofSz);
  20984. wc_SrpTerm(cli);
  20985. wc_SrpTerm(srv);
  20986. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  20987. out:
  20988. XFREE(cli, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20989. XFREE(srv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20990. XFREE(clientProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20991. XFREE(serverProof, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  20992. #endif
  20993. return r;
  20994. }
  20995. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srp_test(void)
  20996. {
  20997. wc_test_ret_t ret;
  20998. WOLFSSL_ENTER("srp_test");
  20999. #ifndef NO_SHA
  21000. ret = srp_test_digest(SRP_TYPE_SHA);
  21001. if (ret != 0)
  21002. return ret;
  21003. #endif
  21004. #ifndef NO_SHA256
  21005. ret = srp_test_digest(SRP_TYPE_SHA256);
  21006. if (ret != 0)
  21007. return ret;
  21008. #endif
  21009. #ifdef WOLFSSL_SHA384
  21010. ret = srp_test_digest(SRP_TYPE_SHA384);
  21011. if (ret != 0)
  21012. return ret;
  21013. #endif
  21014. #ifdef WOLFSSL_SHA512
  21015. ret = srp_test_digest(SRP_TYPE_SHA512);
  21016. if (ret != 0)
  21017. return ret;
  21018. #endif
  21019. return ret;
  21020. }
  21021. #endif /* WOLFCRYPT_HAVE_SRP */
  21022. #if defined(OPENSSL_EXTRA) && !defined(WOLFCRYPT_ONLY)
  21023. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  21024. static wc_test_ret_t openssl_aes_test(void)
  21025. {
  21026. #ifdef HAVE_AES_CBC
  21027. #ifdef WOLFSSL_AES_128
  21028. {
  21029. /* EVP_CipherUpdate test */
  21030. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21031. {
  21032. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21033. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21034. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21035. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21036. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21037. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21038. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21039. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21040. };
  21041. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21042. "0123456789abcdef "; /* align */
  21043. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21044. "1234567890abcdef "; /* align */
  21045. byte cipher[AES_BLOCK_SIZE * 4];
  21046. byte plain [AES_BLOCK_SIZE * 4];
  21047. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21048. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21049. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21050. #else
  21051. WOLFSSL_EVP_CIPHER_CTX en[1];
  21052. WOLFSSL_EVP_CIPHER_CTX de[1];
  21053. #endif
  21054. int outlen ;
  21055. int total = 0;
  21056. int i;
  21057. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21058. if ((en == NULL) || (de == NULL))
  21059. return MEMORY_E;
  21060. #endif
  21061. wolfSSL_EVP_CIPHER_CTX_init(en);
  21062. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21063. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21064. return WC_TEST_RET_ENC_NC;
  21065. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21066. (byte*)cbcPlain, 9) == 0)
  21067. return WC_TEST_RET_ENC_NC;
  21068. if (outlen != 0)
  21069. return WC_TEST_RET_ENC_NC;
  21070. total += outlen;
  21071. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21072. (byte*)&cbcPlain[9] , 9) == 0)
  21073. return WC_TEST_RET_ENC_NC;
  21074. if (outlen != 16)
  21075. return WC_TEST_RET_ENC_NC;
  21076. total += outlen;
  21077. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21078. return WC_TEST_RET_ENC_NC;
  21079. if (outlen != 16)
  21080. return WC_TEST_RET_ENC_NC;
  21081. total += outlen;
  21082. if (total != 32)
  21083. return 3408;
  21084. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21085. total = 0;
  21086. wolfSSL_EVP_CIPHER_CTX_init(de);
  21087. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21088. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21089. return WC_TEST_RET_ENC_NC;
  21090. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  21091. return WC_TEST_RET_ENC_NC;
  21092. if (outlen != 0)
  21093. return WC_TEST_RET_ENC_NC;
  21094. total += outlen;
  21095. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21096. (byte*)&cipher[6], 12) == 0)
  21097. return WC_TEST_RET_ENC_NC;
  21098. if (outlen != 0)
  21099. total += outlen;
  21100. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21101. (byte*)&cipher[6+12], 14) == 0)
  21102. return WC_TEST_RET_ENC_NC;
  21103. if (outlen != 16)
  21104. return WC_TEST_RET_ENC_NC;
  21105. total += outlen;
  21106. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21107. return WC_TEST_RET_ENC_NC;
  21108. if (outlen != 2)
  21109. return WC_TEST_RET_ENC_NC;
  21110. total += outlen;
  21111. if (total != 18)
  21112. return 3427;
  21113. if (XMEMCMP(plain, cbcPlain, 18))
  21114. return WC_TEST_RET_ENC_NC;
  21115. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21116. /* test with encrypting/decrypting more than 16 bytes at once */
  21117. total = 0;
  21118. wolfSSL_EVP_CIPHER_CTX_init(en);
  21119. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21120. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21121. return WC_TEST_RET_ENC_NC;
  21122. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21123. (byte*)cbcPlain, 17) == 0)
  21124. return WC_TEST_RET_ENC_NC;
  21125. if (outlen != 16)
  21126. return WC_TEST_RET_ENC_NC;
  21127. total += outlen;
  21128. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  21129. (byte*)&cbcPlain[17] , 1) == 0)
  21130. return WC_TEST_RET_ENC_NC;
  21131. if (outlen != 0)
  21132. return WC_TEST_RET_ENC_NC;
  21133. total += outlen;
  21134. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21135. return WC_TEST_RET_ENC_NC;
  21136. if (outlen != 16)
  21137. return WC_TEST_RET_ENC_NC;
  21138. total += outlen;
  21139. if (total != 32)
  21140. return WC_TEST_RET_ENC_NC;
  21141. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21142. total = 0;
  21143. wolfSSL_EVP_CIPHER_CTX_init(de);
  21144. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21145. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21146. return WC_TEST_RET_ENC_NC;
  21147. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 17) == 0)
  21148. return WC_TEST_RET_ENC_NC;
  21149. if (outlen != 16)
  21150. return WC_TEST_RET_ENC_NC;
  21151. total += outlen;
  21152. /* final call on non block size should fail */
  21153. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21154. return WC_TEST_RET_ENC_NC;
  21155. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21156. (byte*)&cipher[17], 1) == 0)
  21157. return WC_TEST_RET_ENC_NC;
  21158. if (outlen != 0)
  21159. total += outlen;
  21160. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  21161. (byte*)&cipher[17+1], 14) == 0)
  21162. return WC_TEST_RET_ENC_NC;
  21163. if (outlen != 0)
  21164. return WC_TEST_RET_ENC_NC;
  21165. total += outlen;
  21166. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21167. return WC_TEST_RET_ENC_NC;
  21168. if (outlen != 2)
  21169. return WC_TEST_RET_ENC_NC;
  21170. total += outlen;
  21171. if (total != 18)
  21172. return WC_TEST_RET_ENC_NC;
  21173. if (XMEMCMP(plain, cbcPlain, 18))
  21174. return WC_TEST_RET_ENC_NC;
  21175. /* test byte by byte decrypt */
  21176. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21177. plain[i] = i;
  21178. }
  21179. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21180. total = 0;
  21181. wolfSSL_EVP_CIPHER_CTX_init(en);
  21182. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21183. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21184. return WC_TEST_RET_ENC_NC;
  21185. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21186. (byte*)plain, AES_BLOCK_SIZE * 3) == 0)
  21187. return WC_TEST_RET_ENC_NC;
  21188. if (outlen != AES_BLOCK_SIZE * 3)
  21189. return WC_TEST_RET_ENC_NC;
  21190. total += outlen;
  21191. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  21192. return WC_TEST_RET_ENC_NC;
  21193. if (outlen != AES_BLOCK_SIZE)
  21194. return WC_TEST_RET_ENC_NC;
  21195. total += outlen;
  21196. if (total != sizeof(plain))
  21197. return WC_TEST_RET_ENC_NC;
  21198. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21199. total = 0;
  21200. wolfSSL_EVP_CIPHER_CTX_init(de);
  21201. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21202. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21203. return WC_TEST_RET_ENC_NC;
  21204. for (i = 0; i < AES_BLOCK_SIZE * 4; i++) {
  21205. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain + total, &outlen,
  21206. (byte*)cipher + i, 1) == 0)
  21207. return WC_TEST_RET_ENC_NC;
  21208. if (outlen > 0) {
  21209. int j;
  21210. total += outlen;
  21211. for (j = 0; j < total; j++) {
  21212. if (plain[j] != j) {
  21213. return WC_TEST_RET_ENC_NC;
  21214. }
  21215. }
  21216. }
  21217. }
  21218. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  21219. return WC_TEST_RET_ENC_NC;
  21220. total += outlen;
  21221. if (total != AES_BLOCK_SIZE * 3) {
  21222. return WC_TEST_RET_ENC_NC;
  21223. }
  21224. for (i = 0; i < AES_BLOCK_SIZE * 3; i++) {
  21225. if (plain[i] != i) {
  21226. return WC_TEST_RET_ENC_NC;
  21227. }
  21228. }
  21229. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21230. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21231. wolfSSL_EVP_CIPHER_CTX_free(en);
  21232. wolfSSL_EVP_CIPHER_CTX_free(de);
  21233. #endif
  21234. }
  21235. /* set buffers to be exact size to catch potential over read/write */
  21236. {
  21237. /* EVP_CipherUpdate test */
  21238. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  21239. {
  21240. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21241. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21242. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21243. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21244. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21245. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21246. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21247. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21248. };
  21249. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21250. "0123456789abcdef "; /* align */
  21251. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21252. "1234567890abcdef "; /* align */
  21253. #define EVP_TEST_BUF_SZ 18
  21254. #define EVP_TEST_BUF_PAD 32
  21255. byte cipher[EVP_TEST_BUF_SZ];
  21256. byte plain [EVP_TEST_BUF_SZ];
  21257. byte padded[EVP_TEST_BUF_PAD];
  21258. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21259. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21260. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21261. #else
  21262. WOLFSSL_EVP_CIPHER_CTX en[1];
  21263. WOLFSSL_EVP_CIPHER_CTX de[1];
  21264. #endif
  21265. int outlen ;
  21266. int total = 0;
  21267. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21268. if ((en == NULL) || (de == NULL))
  21269. return MEMORY_E;
  21270. #endif
  21271. wolfSSL_EVP_CIPHER_CTX_init(en);
  21272. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21273. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21274. return WC_TEST_RET_ENC_NC;
  21275. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != 1)
  21276. return WC_TEST_RET_ENC_NC;
  21277. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  21278. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21279. return WC_TEST_RET_ENC_NC;
  21280. if (outlen != 16)
  21281. return WC_TEST_RET_ENC_NC;
  21282. total += outlen;
  21283. /* should fail here */
  21284. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) != 0)
  21285. return WC_TEST_RET_ENC_NC;
  21286. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21287. /* turn padding back on and do successful encrypt */
  21288. total = 0;
  21289. wolfSSL_EVP_CIPHER_CTX_init(en);
  21290. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  21291. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  21292. return WC_TEST_RET_ENC_NC;
  21293. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != 1)
  21294. return WC_TEST_RET_ENC_NC;
  21295. if (wolfSSL_EVP_CipherUpdate(en, (byte*)padded, &outlen,
  21296. (byte*)cbcPlain, EVP_TEST_BUF_SZ) == 0)
  21297. return WC_TEST_RET_ENC_NC;
  21298. if (outlen != 16)
  21299. return WC_TEST_RET_ENC_NC;
  21300. total += outlen;
  21301. if (wolfSSL_EVP_CipherFinal(en, (byte*)&padded[total], &outlen) == 0)
  21302. return WC_TEST_RET_ENC_NC;
  21303. total += outlen;
  21304. if (total != 32)
  21305. return WC_TEST_RET_ENC_NC;
  21306. XMEMCPY(cipher, padded, EVP_TEST_BUF_SZ);
  21307. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  21308. /* test out of bounds read on buffers w/o padding during decryption */
  21309. total = 0;
  21310. wolfSSL_EVP_CIPHER_CTX_init(de);
  21311. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21312. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21313. return WC_TEST_RET_ENC_NC;
  21314. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 0) != 1)
  21315. return WC_TEST_RET_ENC_NC;
  21316. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher,
  21317. EVP_TEST_BUF_SZ) == 0)
  21318. return WC_TEST_RET_ENC_NC;
  21319. if (outlen != 16)
  21320. return WC_TEST_RET_ENC_NC;
  21321. total += outlen;
  21322. /* should fail since not using padding */
  21323. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) != 0)
  21324. return WC_TEST_RET_ENC_NC;
  21325. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21326. total = 0;
  21327. wolfSSL_EVP_CIPHER_CTX_init(de);
  21328. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  21329. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  21330. return WC_TEST_RET_ENC_NC;
  21331. if (wolfSSL_EVP_CIPHER_CTX_set_padding(de, 1) != 1)
  21332. return WC_TEST_RET_ENC_NC;
  21333. if (wolfSSL_EVP_CipherUpdate(de, (byte*)padded, &outlen, (byte*)padded,
  21334. EVP_TEST_BUF_PAD) == 0)
  21335. return WC_TEST_RET_ENC_NC;
  21336. if (outlen != 16)
  21337. return WC_TEST_RET_ENC_NC;
  21338. total += outlen;
  21339. if (wolfSSL_EVP_CipherFinal(de, (byte*)&padded[total], &outlen) == 0)
  21340. return WC_TEST_RET_ENC_NC;
  21341. if (XMEMCMP(padded, cbcPlain, EVP_TEST_BUF_SZ))
  21342. return WC_TEST_RET_ENC_NC;
  21343. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  21344. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21345. wolfSSL_EVP_CIPHER_CTX_free(en);
  21346. wolfSSL_EVP_CIPHER_CTX_free(de);
  21347. #endif
  21348. }
  21349. { /* evp_cipher test: EVP_aes_128_cbc */
  21350. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21351. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21352. #else
  21353. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21354. #endif
  21355. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  21356. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  21357. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  21358. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  21359. };
  21360. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21361. {
  21362. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  21363. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb
  21364. };
  21365. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21366. "0123456789abcdef "; /* align */
  21367. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  21368. "1234567890abcdef "; /* align */
  21369. byte cipher[AES_BLOCK_SIZE * 4];
  21370. byte plain [AES_BLOCK_SIZE * 4];
  21371. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21372. if (ctx == NULL)
  21373. return MEMORY_E;
  21374. #endif
  21375. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21376. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1) == 0)
  21377. return WC_TEST_RET_ENC_NC;
  21378. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21379. return WC_TEST_RET_ENC_NC;
  21380. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21381. return WC_TEST_RET_ENC_NC;
  21382. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21383. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21384. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0) == 0)
  21385. return WC_TEST_RET_ENC_NC;
  21386. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21387. return WC_TEST_RET_ENC_NC;
  21388. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21389. return WC_TEST_RET_ENC_NC;
  21390. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  21391. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21392. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21393. #endif
  21394. } /* end evp_cipher test: EVP_aes_128_cbc*/
  21395. #endif /* WOLFSSL_AES_128 */
  21396. #endif /* HAVE_AES_CBC */
  21397. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21398. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  21399. { /* evp_cipher test: EVP_aes_256_ecb*/
  21400. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21401. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  21402. #else
  21403. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  21404. #endif
  21405. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21406. {
  21407. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21408. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21409. };
  21410. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21411. {
  21412. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21413. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21414. };
  21415. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21416. {
  21417. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21418. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21419. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21420. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21421. };
  21422. byte cipher[AES_BLOCK_SIZE * 4];
  21423. byte plain [AES_BLOCK_SIZE * 4];
  21424. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21425. if (ctx == NULL)
  21426. return MEMORY_E;
  21427. #endif
  21428. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21429. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1) == 0)
  21430. return WC_TEST_RET_ENC_NC;
  21431. if (wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16) != 16)
  21432. return WC_TEST_RET_ENC_NC;
  21433. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21434. return WC_TEST_RET_ENC_NC;
  21435. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  21436. if (wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0) == 0)
  21437. return WC_TEST_RET_ENC_NC;
  21438. if (wolfSSL_EVP_Cipher(ctx, plain, cipher, 16) != 16)
  21439. return WC_TEST_RET_ENC_NC;
  21440. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21441. return WC_TEST_RET_ENC_NC;
  21442. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21443. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  21444. #endif
  21445. } /* end evp_cipher test */
  21446. #endif /* HAVE_AES_ECB && WOLFSSL_AES_256 */
  21447. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  21448. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  21449. {
  21450. /* Test: AES_encrypt/decrypt/set Key */
  21451. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21452. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21453. #ifdef HAVE_AES_DECRYPT
  21454. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21455. #endif
  21456. #else
  21457. AES_KEY enc[1];
  21458. #ifdef HAVE_AES_DECRYPT
  21459. AES_KEY dec[1];
  21460. #endif
  21461. #endif
  21462. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21463. {
  21464. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21465. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21466. };
  21467. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  21468. {
  21469. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  21470. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  21471. };
  21472. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21473. {
  21474. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21475. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21476. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21477. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21478. };
  21479. byte plain[sizeof(msg)];
  21480. byte cipher[sizeof(msg)];
  21481. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21482. if (enc == NULL)
  21483. return MEMORY_E;
  21484. #ifdef HAVE_AES_DECRYPT
  21485. if (dec == NULL)
  21486. return MEMORY_E;
  21487. #endif
  21488. #endif
  21489. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  21490. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  21491. AES_encrypt(msg, cipher, enc);
  21492. #ifdef HAVE_AES_DECRYPT
  21493. AES_decrypt(cipher, plain, dec);
  21494. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  21495. return WC_TEST_RET_ENC_NC;
  21496. #endif /* HAVE_AES_DECRYPT */
  21497. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  21498. return WC_TEST_RET_ENC_NC;
  21499. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21500. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21501. #ifdef HAVE_AES_DECRYPT
  21502. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21503. #endif
  21504. #endif
  21505. }
  21506. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  21507. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21508. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  21509. #ifdef WOLFSSL_AES_COUNTER
  21510. {
  21511. byte plainBuff [64];
  21512. byte cipherBuff[64];
  21513. #ifdef WOLFSSL_AES_128
  21514. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  21515. {
  21516. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21517. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21518. };
  21519. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  21520. {
  21521. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21522. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21523. };
  21524. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  21525. {
  21526. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21527. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21528. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21529. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  21530. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  21531. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  21532. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  21533. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  21534. };
  21535. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  21536. {
  21537. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  21538. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  21539. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  21540. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  21541. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  21542. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  21543. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  21544. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  21545. };
  21546. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  21547. {
  21548. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  21549. 0xc2
  21550. };
  21551. #endif
  21552. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21553. * NIST Special Publication 800-38A */
  21554. #ifdef WOLFSSL_AES_192
  21555. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  21556. {
  21557. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  21558. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  21559. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  21560. };
  21561. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  21562. {
  21563. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21564. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21565. };
  21566. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  21567. {
  21568. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21569. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21570. };
  21571. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  21572. {
  21573. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  21574. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  21575. };
  21576. #endif /* WOLFSSL_AES_192 */
  21577. #ifdef WOLFSSL_AES_256
  21578. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  21579. * NIST Special Publication 800-38A */
  21580. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  21581. {
  21582. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  21583. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  21584. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  21585. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  21586. };
  21587. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  21588. {
  21589. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  21590. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  21591. };
  21592. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  21593. {
  21594. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21595. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  21596. };
  21597. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  21598. {
  21599. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  21600. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  21601. };
  21602. #endif /* WOLFSSL_AES_256 */
  21603. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21604. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  21605. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  21606. #else
  21607. WOLFSSL_EVP_CIPHER_CTX en[1];
  21608. WOLFSSL_EVP_CIPHER_CTX de[1];
  21609. #endif
  21610. #ifdef WOLFSSL_AES_128
  21611. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21612. WOLFSSL_EVP_CIPHER_CTX *p_en;
  21613. WOLFSSL_EVP_CIPHER_CTX *p_de;
  21614. #endif
  21615. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21616. if ((en == NULL) || (de == NULL))
  21617. return MEMORY_E;
  21618. #endif
  21619. wolfSSL_EVP_CIPHER_CTX_init(en);
  21620. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21621. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21622. return WC_TEST_RET_ENC_NC;
  21623. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  21624. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21625. return WC_TEST_RET_ENC_NC;
  21626. wolfSSL_EVP_CIPHER_CTX_init(de);
  21627. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21628. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21629. return WC_TEST_RET_ENC_NC;
  21630. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21631. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21632. return WC_TEST_RET_ENC_NC;
  21633. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21634. return WC_TEST_RET_ENC_NC;
  21635. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21636. return WC_TEST_RET_ENC_NC;
  21637. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21638. return WC_TEST_RET_ENC_NC;
  21639. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21640. return WC_TEST_RET_ENC_NC;
  21641. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21642. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  21643. if (p_en == NULL)
  21644. return WC_TEST_RET_ENC_ERRNO;
  21645. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  21646. if (p_de == NULL)
  21647. return WC_TEST_RET_ENC_ERRNO;
  21648. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  21649. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21650. return WC_TEST_RET_ENC_NC;
  21651. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  21652. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21653. return WC_TEST_RET_ENC_NC;
  21654. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  21655. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21656. return WC_TEST_RET_ENC_NC;
  21657. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  21658. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  21659. return WC_TEST_RET_ENC_NC;
  21660. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21661. return WC_TEST_RET_ENC_NC;
  21662. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21663. return WC_TEST_RET_ENC_NC;
  21664. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  21665. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  21666. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  21667. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  21668. return WC_TEST_RET_ENC_NC;
  21669. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  21670. return WC_TEST_RET_ENC_NC;
  21671. wolfSSL_EVP_CIPHER_CTX_init(en);
  21672. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  21673. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21674. return WC_TEST_RET_ENC_NC;
  21675. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21676. return WC_TEST_RET_ENC_NC;
  21677. wolfSSL_EVP_CIPHER_CTX_init(de);
  21678. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  21679. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  21680. return WC_TEST_RET_ENC_NC;
  21681. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21682. return WC_TEST_RET_ENC_NC;
  21683. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21684. return WC_TEST_RET_ENC_NC;
  21685. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  21686. return WC_TEST_RET_ENC_NC;
  21687. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  21688. return WC_TEST_RET_ENC_NC;
  21689. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  21690. return WC_TEST_RET_ENC_NC;
  21691. if (XMEMCMP(plainBuff, ctrPlain, 9))
  21692. return WC_TEST_RET_ENC_NC;
  21693. if (XMEMCMP(cipherBuff, oddCipher, 9))
  21694. return WC_TEST_RET_ENC_NC;
  21695. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21696. return WC_TEST_RET_ENC_NC;
  21697. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21698. return WC_TEST_RET_ENC_NC;
  21699. #endif /* WOLFSSL_AES_128 */
  21700. #ifdef WOLFSSL_AES_192
  21701. wolfSSL_EVP_CIPHER_CTX_init(en);
  21702. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  21703. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21704. return WC_TEST_RET_ENC_NC;
  21705. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  21706. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21707. return WC_TEST_RET_ENC_NC;
  21708. wolfSSL_EVP_CIPHER_CTX_init(de);
  21709. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  21710. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  21711. return WC_TEST_RET_ENC_NC;
  21712. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21713. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21714. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21715. return WC_TEST_RET_ENC_NC;
  21716. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  21717. return WC_TEST_RET_ENC_NC;
  21718. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  21719. return WC_TEST_RET_ENC_NC;
  21720. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21721. return WC_TEST_RET_ENC_NC;
  21722. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21723. return WC_TEST_RET_ENC_NC;
  21724. #endif /* WOLFSSL_AES_192 */
  21725. #ifdef WOLFSSL_AES_256
  21726. wolfSSL_EVP_CIPHER_CTX_init(en);
  21727. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  21728. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21729. return WC_TEST_RET_ENC_NC;
  21730. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  21731. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21732. return WC_TEST_RET_ENC_NC;
  21733. wolfSSL_EVP_CIPHER_CTX_init(de);
  21734. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  21735. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  21736. return WC_TEST_RET_ENC_NC;
  21737. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  21738. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  21739. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  21740. return WC_TEST_RET_ENC_NC;
  21741. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  21742. return WC_TEST_RET_ENC_NC;
  21743. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  21744. return WC_TEST_RET_ENC_NC;
  21745. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  21746. return WC_TEST_RET_ENC_NC;
  21747. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  21748. return WC_TEST_RET_ENC_NC;
  21749. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21750. wolfSSL_EVP_CIPHER_CTX_free(en);
  21751. wolfSSL_EVP_CIPHER_CTX_free(de);
  21752. #endif
  21753. #endif /* WOLFSSL_AES_256 */
  21754. }
  21755. #endif /* HAVE_AES_COUNTER */
  21756. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  21757. #if defined(WOLFSSL_AES_CFB) && defined(WOLFSSL_AES_128)
  21758. {
  21759. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21760. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21761. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21762. #else
  21763. AES_KEY enc[1];
  21764. AES_KEY dec[1];
  21765. #endif
  21766. WOLFSSL_SMALL_STACK_STATIC const byte setIv[] = {
  21767. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  21768. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
  21769. };
  21770. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  21771. {
  21772. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  21773. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  21774. };
  21775. WOLFSSL_SMALL_STACK_STATIC const byte cipher1[] =
  21776. {
  21777. 0x3b,0x3f,0xd9,0x2e,0xb7,0x2d,0xad,0x20,
  21778. 0x33,0x34,0x49,0xf8,0xe8,0x3c,0xfb,0x4a,
  21779. 0xc8,0xa6,0x45,0x37,0xa0,0xb3,0xa9,0x3f,
  21780. 0xcd,0xe3,0xcd,0xad,0x9f,0x1c,0xe5,0x8b
  21781. };
  21782. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  21783. {
  21784. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  21785. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  21786. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  21787. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51
  21788. };
  21789. byte cipher[AES_BLOCK_SIZE * 2];
  21790. byte iv[AES_BLOCK_SIZE]; /* iv buffer is updeated by API */
  21791. int num = 0;
  21792. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21793. if ((enc == NULL) || (dec == NULL))
  21794. return MEMORY_E;
  21795. #endif
  21796. XMEMCPY(iv, setIv, sizeof(setIv));
  21797. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, enc);
  21798. wolfSSL_AES_set_encrypt_key(key, sizeof(key) * 8, dec);
  21799. wolfSSL_AES_cfb128_encrypt(msg, cipher, AES_BLOCK_SIZE - 1, enc, iv,
  21800. &num, AES_ENCRYPT);
  21801. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE - 1))
  21802. return WC_TEST_RET_ENC_NC;
  21803. if (num != 15) /* should have used 15 of the 16 bytes */
  21804. return WC_TEST_RET_ENC_NC;
  21805. wolfSSL_AES_cfb128_encrypt(msg + AES_BLOCK_SIZE - 1,
  21806. cipher + AES_BLOCK_SIZE - 1, AES_BLOCK_SIZE + 1, enc, iv,
  21807. &num, AES_ENCRYPT);
  21808. if (XMEMCMP(cipher, cipher1, AES_BLOCK_SIZE * 2))
  21809. return WC_TEST_RET_ENC_NC;
  21810. if (num != 0)
  21811. return WC_TEST_RET_ENC_NC;
  21812. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  21813. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  21814. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  21815. #endif
  21816. }
  21817. #endif /* WOLFSSL_AES_CFB && WOLFSSL_AES_128 */
  21818. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  21819. return 0;
  21820. }
  21821. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  21822. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_test(void)
  21823. {
  21824. wc_test_ret_t ret;
  21825. #ifdef WOLFSSL_SMALL_STACK
  21826. WOLFSSL_EVP_MD_CTX *md_ctx = (WOLFSSL_EVP_MD_CTX *)XMALLOC(sizeof(WOLFSSL_EVP_MD_CTX), NULL, DYNAMIC_TYPE_OPENSSL);
  21827. #else
  21828. WOLFSSL_EVP_MD_CTX md_ctx[1];
  21829. #endif
  21830. testVector a, b, c, d, e, f;
  21831. byte hash[WC_SHA256_DIGEST_SIZE*2]; /* max size */
  21832. #ifdef WOLFSSL_SMALL_STACK
  21833. if (md_ctx == NULL)
  21834. return WC_TEST_RET_ENC_EC(MEMORY_E);
  21835. #endif
  21836. WOLFSSL_ENTER("openssl_test");
  21837. a.inLen = 0;
  21838. b.inLen = c.inLen = d.inLen = e.inLen = f.inLen = a.inLen;
  21839. (void)a;
  21840. (void)b;
  21841. (void)c;
  21842. (void)d;
  21843. (void)e;
  21844. (void)f;
  21845. /* test malloc / free , 10 is an arbitrary amount of memory chosen */
  21846. {
  21847. byte* p;
  21848. p = (byte*)wolfSSL_CRYPTO_malloc(10, "", 0);
  21849. if (p == NULL) {
  21850. return WC_TEST_RET_ENC_NC;
  21851. }
  21852. XMEMSET(p, 0, 10);
  21853. wolfSSL_CRYPTO_free(p, "", 0);
  21854. }
  21855. #ifndef NO_MD5
  21856. a.input = "1234567890123456789012345678901234567890123456789012345678"
  21857. "9012345678901234567890";
  21858. a.output = "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55\xac\x49\xda\x2e\x21\x07\xb6"
  21859. "\x7a";
  21860. a.inLen = XSTRLEN(a.input);
  21861. a.outLen = WC_MD5_DIGEST_SIZE;
  21862. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21863. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_md5());
  21864. if (ret == WOLFSSL_SUCCESS) {
  21865. ret = wolfSSL_EVP_DigestUpdate(md_ctx, a.input, (unsigned long)a.inLen);
  21866. }
  21867. if (ret == WOLFSSL_SUCCESS) {
  21868. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21869. }
  21870. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21871. if (ret != WOLFSSL_SUCCESS)
  21872. return WC_TEST_RET_ENC_NC;
  21873. if (XMEMCMP(hash, a.output, WC_MD5_DIGEST_SIZE) != 0)
  21874. return WC_TEST_RET_ENC_NC;
  21875. #endif /* NO_MD5 */
  21876. #ifndef NO_SHA
  21877. b.input = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21878. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  21879. "aaaaaaaaaa";
  21880. b.output = "\xAD\x5B\x3F\xDB\xCB\x52\x67\x78\xC2\x83\x9D\x2F\x15\x1E\xA7"
  21881. "\x53\x99\x5E\x26\xA0";
  21882. b.inLen = XSTRLEN(b.input);
  21883. b.outLen = WC_SHA_DIGEST_SIZE;
  21884. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21885. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha1());
  21886. if (ret == WOLFSSL_SUCCESS) {
  21887. ret = wolfSSL_EVP_DigestUpdate(md_ctx, b.input, (unsigned long)b.inLen);
  21888. if (ret == WOLFSSL_SUCCESS)
  21889. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21890. }
  21891. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21892. if (ret != WOLFSSL_SUCCESS)
  21893. return WC_TEST_RET_ENC_NC;
  21894. if (XMEMCMP(hash, b.output, b.outLen) != 0)
  21895. return WC_TEST_RET_ENC_NC;
  21896. #endif /* NO_SHA */
  21897. #ifdef WOLFSSL_SHA224
  21898. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21899. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21900. e.output = "\xc9\x7c\xa9\xa5\x59\x85\x0c\xe9\x7a\x04\xa9\x6d\xef\x6d\x99"
  21901. "\xa9\xe0\xe0\xe2\xab\x14\xe6\xb8\xdf\x26\x5f\xc0\xb3";
  21902. e.inLen = XSTRLEN(e.input);
  21903. e.outLen = WC_SHA224_DIGEST_SIZE;
  21904. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21905. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha224());
  21906. if (ret == WOLFSSL_SUCCESS) {
  21907. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21908. if (ret == WOLFSSL_SUCCESS)
  21909. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21910. }
  21911. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21912. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21913. return WC_TEST_RET_ENC_NC;
  21914. }
  21915. #endif /* WOLFSSL_SHA224 */
  21916. #ifndef NO_SHA256
  21917. d.input = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
  21918. d.output = "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60"
  21919. "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB"
  21920. "\x06\xC1";
  21921. d.inLen = XSTRLEN(d.input);
  21922. d.outLen = WC_SHA256_DIGEST_SIZE;
  21923. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21924. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha256());
  21925. if (ret == WOLFSSL_SUCCESS) {
  21926. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  21927. if (ret == WOLFSSL_SUCCESS)
  21928. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21929. }
  21930. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21931. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  21932. return WC_TEST_RET_ENC_NC;
  21933. }
  21934. #endif /* !NO_SHA256 */
  21935. #ifdef WOLFSSL_SHA384
  21936. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21937. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21938. e.output = "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b"
  21939. "\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0"
  21940. "\xf7\x12\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91"
  21941. "\x74\x60\x39";
  21942. e.inLen = XSTRLEN(e.input);
  21943. e.outLen = WC_SHA384_DIGEST_SIZE;
  21944. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21945. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha384());
  21946. if (ret == WOLFSSL_SUCCESS) {
  21947. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  21948. if (ret == WOLFSSL_SUCCESS)
  21949. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21950. }
  21951. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21952. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  21953. return WC_TEST_RET_ENC_NC;
  21954. }
  21955. #endif /* WOLFSSL_SHA384 */
  21956. #ifdef WOLFSSL_SHA512
  21957. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21958. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21959. f.output = "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14"
  21960. "\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88"
  21961. "\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4"
  21962. "\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b"
  21963. "\x87\x4b\xe9\x09";
  21964. f.inLen = XSTRLEN(f.input);
  21965. f.outLen = WC_SHA512_DIGEST_SIZE;
  21966. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21967. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512());
  21968. if (ret == WOLFSSL_SUCCESS) {
  21969. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21970. if (ret == WOLFSSL_SUCCESS)
  21971. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21972. }
  21973. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21974. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21975. return WC_TEST_RET_ENC_NC;
  21976. }
  21977. #if !defined(WOLFSSL_NOSHA512_224) && \
  21978. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21979. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  21980. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  21981. f.output = "\x23\xfe\xc5\xbb\x94\xd6\x0b\x23\x30\x81\x92\x64\x0b\x0c\x45"
  21982. "\x33\x35\xd6\x64\x73\x4f\xe4\x0e\x72\x68\x67\x4a\xf9";
  21983. f.inLen = XSTRLEN(f.input);
  21984. f.outLen = WC_SHA512_224_DIGEST_SIZE;
  21985. wolfSSL_EVP_MD_CTX_init(md_ctx);
  21986. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_224());
  21987. if (ret == WOLFSSL_SUCCESS) {
  21988. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  21989. if (ret == WOLFSSL_SUCCESS)
  21990. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  21991. }
  21992. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  21993. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  21994. return WC_TEST_RET_ENC_NC;
  21995. }
  21996. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  21997. #if !defined(WOLFSSL_NOSHA512_256) && \
  21998. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  21999. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22000. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22001. f.output = "\x39\x28\xe1\x84\xfb\x86\x90\xf8\x40\xda\x39\x88\x12\x1d\x31"
  22002. "\xbe\x65\xcb\x9d\x3e\xf8\x3e\xe6\x14\x6f\xea\xc8\x61\xe1\x9b"
  22003. "\x56\x3a";
  22004. f.inLen = XSTRLEN(f.input);
  22005. f.outLen = WC_SHA512_256_DIGEST_SIZE;
  22006. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22007. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha512_256());
  22008. if (ret == WOLFSSL_SUCCESS) {
  22009. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22010. if (ret == WOLFSSL_SUCCESS)
  22011. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22012. }
  22013. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22014. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, f.output, f.outLen) != 0) {
  22015. return WC_TEST_RET_ENC_NC;
  22016. }
  22017. #endif /* !WOLFSSL_NOSHA512_224 && !FIPS ... */
  22018. #endif /* WOLFSSL_SHA512 */
  22019. #ifdef WOLFSSL_SHA3
  22020. #ifndef WOLFSSL_NOSHA3_224
  22021. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22022. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22023. e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a"
  22024. "\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
  22025. e.inLen = XSTRLEN(e.input);
  22026. e.outLen = WC_SHA3_224_DIGEST_SIZE;
  22027. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22028. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_224());
  22029. if (ret == WOLFSSL_SUCCESS) {
  22030. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22031. if (ret == WOLFSSL_SUCCESS)
  22032. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22033. }
  22034. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22035. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22036. return WC_TEST_RET_ENC_NC;
  22037. }
  22038. #endif /* WOLFSSL_NOSHA3_224 */
  22039. #ifndef WOLFSSL_NOSHA3_256
  22040. d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22041. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22042. d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
  22043. "\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
  22044. "\x1d\x18";
  22045. d.inLen = XSTRLEN(d.input);
  22046. d.outLen = WC_SHA3_256_DIGEST_SIZE;
  22047. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22048. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_256());
  22049. if (ret == WOLFSSL_SUCCESS) {
  22050. ret = wolfSSL_EVP_DigestUpdate(md_ctx, d.input, (unsigned long)d.inLen);
  22051. if (ret == WOLFSSL_SUCCESS)
  22052. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22053. }
  22054. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22055. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, d.output, d.outLen) != 0) {
  22056. return WC_TEST_RET_ENC_NC;
  22057. }
  22058. #endif /* WOLFSSL_NOSHA3_256 */
  22059. e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22060. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22061. e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47"
  22062. "\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6"
  22063. "\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79"
  22064. "\xaa\x7f\xc7";
  22065. e.inLen = XSTRLEN(e.input);
  22066. e.outLen = WC_SHA3_384_DIGEST_SIZE;
  22067. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22068. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_384());
  22069. if (ret == WOLFSSL_SUCCESS) {
  22070. ret = wolfSSL_EVP_DigestUpdate(md_ctx, e.input, (unsigned long)e.inLen);
  22071. if (ret == WOLFSSL_SUCCESS)
  22072. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22073. }
  22074. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22075. if (ret != WOLFSSL_SUCCESS || XMEMCMP(hash, e.output, e.outLen) != 0) {
  22076. return WC_TEST_RET_ENC_NC;
  22077. }
  22078. #ifndef WOLFSSL_NOSHA3_512
  22079. f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
  22080. "jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
  22081. f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78"
  22082. "\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18"
  22083. "\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8"
  22084. "\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55"
  22085. "\xf2\x1d\xd1\x85";
  22086. f.inLen = XSTRLEN(f.input);
  22087. f.outLen = WC_SHA3_512_DIGEST_SIZE;
  22088. wolfSSL_EVP_MD_CTX_init(md_ctx);
  22089. ret = wolfSSL_EVP_DigestInit(md_ctx, wolfSSL_EVP_sha3_512());
  22090. if (ret == WOLFSSL_SUCCESS) {
  22091. ret = wolfSSL_EVP_DigestUpdate(md_ctx, f.input, (unsigned long)f.inLen);
  22092. if (ret == WOLFSSL_SUCCESS)
  22093. ret = wolfSSL_EVP_DigestFinal(md_ctx, hash, 0);
  22094. }
  22095. wolfSSL_EVP_MD_CTX_cleanup(md_ctx);
  22096. if (ret != WOLFSSL_SUCCESS ||
  22097. XMEMCMP(hash, f.output, f.outLen) != 0) {
  22098. return WC_TEST_RET_ENC_NC;
  22099. }
  22100. #endif /* WOLFSSL_NOSHA3_512 */
  22101. #endif /* WOLFSSL_SHA3 */
  22102. #ifdef WOLFSSL_SMALL_STACK
  22103. XFREE(md_ctx, NULL, DYNAMIC_TYPE_OPENSSL);
  22104. md_ctx = NULL;
  22105. #endif
  22106. #ifndef WC_NO_RNG
  22107. if (wolfSSL_RAND_bytes(hash, sizeof(hash)) != WOLFSSL_SUCCESS)
  22108. return WC_TEST_RET_ENC_NC;
  22109. #endif
  22110. #ifndef NO_MD5
  22111. c.input = "what do ya want for nothing?";
  22112. c.output = "\x55\x78\xe8\x48\x4b\xcc\x93\x80\x93\xec\x53\xaf\x22\xd6\x14"
  22113. "\x76";
  22114. c.inLen = XSTRLEN(c.input);
  22115. c.outLen = WC_MD5_DIGEST_SIZE;
  22116. #if defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)
  22117. /* Expect failure with MD5 + HMAC when using FIPS 140-3. */
  22118. if (HMAC(EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22119. hash, 0) != NULL)
  22120. #else
  22121. if (wolfSSL_HMAC(wolfSSL_EVP_md5(), "JefeJefeJefeJefe", 16, (byte*)c.input, (int)c.inLen,
  22122. hash, 0) == NULL ||
  22123. XMEMCMP(hash, c.output, c.outLen) != 0)
  22124. #endif
  22125. {
  22126. return WC_TEST_RET_ENC_NC;
  22127. }
  22128. #endif /* NO_MD5 */
  22129. #ifndef NO_DES3
  22130. { /* des test */
  22131. WOLFSSL_SMALL_STACK_STATIC const byte vector[] = { /* "now is the time for all " w/o trailing 0 */
  22132. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22133. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22134. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22135. };
  22136. byte plain[24];
  22137. byte cipher[24];
  22138. const_DES_cblock key = {
  22139. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  22140. };
  22141. DES_cblock iv = {
  22142. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef
  22143. };
  22144. DES_key_schedule sched;
  22145. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22146. 0x8b,0x7c,0x52,0xb0,0x01,0x2b,0x6c,0xb8,
  22147. 0x4f,0x0f,0xeb,0xf3,0xfb,0x5f,0x86,0x73,
  22148. 0x15,0x85,0xb3,0x22,0x4b,0x86,0x2b,0x4b
  22149. };
  22150. DES_key_sched(&key, &sched);
  22151. DES_cbc_encrypt(vector, cipher, sizeof(vector), &sched, &iv, DES_ENCRYPT);
  22152. DES_cbc_encrypt(cipher, plain, sizeof(vector), &sched, &iv, DES_DECRYPT);
  22153. if (XMEMCMP(plain, vector, sizeof(vector)) != 0)
  22154. return WC_TEST_RET_ENC_NC;
  22155. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22156. return WC_TEST_RET_ENC_NC;
  22157. /* test changing iv */
  22158. DES_ncbc_encrypt(vector, cipher, 8, &sched, &iv, DES_ENCRYPT);
  22159. DES_ncbc_encrypt(vector + 8, cipher + 8, 16, &sched, &iv, DES_ENCRYPT);
  22160. if (XMEMCMP(cipher, verify, sizeof(verify)) != 0)
  22161. return WC_TEST_RET_ENC_NC;
  22162. } /* end des test */
  22163. #endif /* NO_DES3 */
  22164. #if !defined(NO_AES) && !defined(WOLFCRYPT_ONLY)
  22165. if ((ret = openssl_aes_test()) != 0) {
  22166. return ret;
  22167. }
  22168. #if defined(WOLFSSL_AES_128) && defined(HAVE_AES_CBC)
  22169. { /* evp_cipher test: EVP_aes_128_cbc */
  22170. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22171. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22172. #else
  22173. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22174. #endif
  22175. int idx, cipherSz, plainSz;
  22176. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = { /* "Now is the time for all " w/o trailing 0 */
  22177. 0x6e,0x6f,0x77,0x20,0x69,0x73,0x20,0x74,
  22178. 0x68,0x65,0x20,0x74,0x69,0x6d,0x65,0x20,
  22179. 0x66,0x6f,0x72,0x20,0x61,0x6c,0x6c,0x20
  22180. };
  22181. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22182. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22183. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22184. 0x3b,0x5d,0x41,0x97,0x94,0x25,0xa4,0xb4,
  22185. 0xae,0x7b,0x34,0xd0,0x3f,0x0c,0xbc,0x06
  22186. };
  22187. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  22188. 0x95,0x94,0x92,0x57,0x5f,0x42,0x81,0x53,
  22189. 0x2c,0xcc,0x9d,0x46,0x77,0xa2,0x33,0xcb,
  22190. 0x7d,0x37,0x7b,0x0b,0x44,0xaa,0xb5,0xf0,
  22191. 0x5f,0x34,0xb4,0xde,0xb5,0xbd,0x2a,0xbb
  22192. };
  22193. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22194. "0123456789abcdef "; /* align */
  22195. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  22196. "1234567890abcdef "; /* align */
  22197. byte cipher[AES_BLOCK_SIZE * 4];
  22198. byte plain [AES_BLOCK_SIZE * 4];
  22199. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22200. if (ctx == NULL)
  22201. return MEMORY_E;
  22202. #endif
  22203. cipherSz = 0;
  22204. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22205. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22206. if (ret == WOLFSSL_SUCCESS) {
  22207. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, (byte*)msg, sizeof(msg));
  22208. if (ret == WOLFSSL_SUCCESS)
  22209. cipherSz += idx;
  22210. }
  22211. if (ret == WOLFSSL_SUCCESS) {
  22212. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22213. if (ret == WOLFSSL_SUCCESS)
  22214. cipherSz += idx;
  22215. }
  22216. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22217. if (ret != WOLFSSL_SUCCESS)
  22218. return WC_TEST_RET_ENC_NC;
  22219. if (cipherSz != (int)sizeof(verify) || XMEMCMP(cipher, verify, cipherSz))
  22220. return WC_TEST_RET_ENC_NC;
  22221. /* check partial decrypt (not enough padding for full block) */
  22222. plainSz = 0;
  22223. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22224. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22225. if (ret == WOLFSSL_SUCCESS) {
  22226. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, 1);
  22227. if (ret == WOLFSSL_SUCCESS)
  22228. plainSz += idx;
  22229. }
  22230. if (ret == WOLFSSL_SUCCESS) {
  22231. /* this test should fail... not enough padding for full block */
  22232. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22233. if (plainSz == 0 && ret != WOLFSSL_SUCCESS)
  22234. ret = WOLFSSL_SUCCESS;
  22235. else
  22236. ret = WC_TEST_RET_ENC_NC;
  22237. }
  22238. else
  22239. ret = WC_TEST_RET_ENC_NC;
  22240. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22241. if (ret != WOLFSSL_SUCCESS)
  22242. return ret;
  22243. plainSz = 0;
  22244. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22245. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 0);
  22246. if (ret == WOLFSSL_SUCCESS) {
  22247. ret = wolfSSL_EVP_CipherUpdate(ctx, plain, &idx, cipher, cipherSz);
  22248. if (ret == WOLFSSL_SUCCESS)
  22249. plainSz += idx;
  22250. }
  22251. if (ret == WOLFSSL_SUCCESS) {
  22252. ret = wolfSSL_EVP_CipherFinal(ctx, plain + plainSz, &idx);
  22253. if (ret == WOLFSSL_SUCCESS)
  22254. plainSz += idx;
  22255. }
  22256. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22257. if (ret != WOLFSSL_SUCCESS)
  22258. return WC_TEST_RET_ENC_NC;
  22259. if (plainSz != (int)sizeof(msg) || XMEMCMP(plain, msg, sizeof(msg)))
  22260. return WC_TEST_RET_ENC_NC;
  22261. cipherSz = 0;
  22262. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22263. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_128_cbc(), key, iv, 1);
  22264. if (ret == WOLFSSL_SUCCESS) {
  22265. ret = wolfSSL_EVP_CipherUpdate(ctx, cipher, &idx, msg, AES_BLOCK_SIZE);
  22266. if (ret == WOLFSSL_SUCCESS)
  22267. cipherSz += idx;
  22268. }
  22269. if (ret == WOLFSSL_SUCCESS) {
  22270. ret = wolfSSL_EVP_CipherFinal(ctx, cipher + cipherSz, &idx);
  22271. if (ret == WOLFSSL_SUCCESS)
  22272. cipherSz += idx;
  22273. }
  22274. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22275. if (ret != WOLFSSL_SUCCESS)
  22276. return WC_TEST_RET_ENC_NC;
  22277. if (cipherSz != (int)sizeof(verify2) || XMEMCMP(cipher, verify2, cipherSz))
  22278. return WC_TEST_RET_ENC_NC;
  22279. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22280. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22281. #endif
  22282. } /* end evp_cipher test: EVP_aes_128_cbc*/
  22283. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22284. #if defined(HAVE_AES_ECB) && defined(WOLFSSL_AES_256)
  22285. { /* evp_cipher test: EVP_aes_256_ecb*/
  22286. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22287. WOLFSSL_EVP_CIPHER_CTX *ctx = wolfSSL_EVP_CIPHER_CTX_new();
  22288. #else
  22289. WOLFSSL_EVP_CIPHER_CTX ctx[1];
  22290. #endif
  22291. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  22292. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22293. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22294. };
  22295. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  22296. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22297. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22298. };
  22299. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  22300. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22301. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22302. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22303. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22304. };
  22305. byte cipher[AES_BLOCK_SIZE * 4];
  22306. byte plain [AES_BLOCK_SIZE * 4];
  22307. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22308. if (ctx == NULL)
  22309. return MEMORY_E;
  22310. #endif
  22311. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22312. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 1);
  22313. if (ret == WOLFSSL_SUCCESS)
  22314. ret = wolfSSL_EVP_Cipher(ctx, cipher, (byte*)msg, 16);
  22315. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22316. if (ret != 16)
  22317. return WC_TEST_RET_ENC_NC;
  22318. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22319. return WC_TEST_RET_ENC_NC;
  22320. wolfSSL_EVP_CIPHER_CTX_init(ctx);
  22321. ret = wolfSSL_EVP_CipherInit(ctx, wolfSSL_EVP_aes_256_ecb(), (unsigned char*)key, NULL, 0);
  22322. if (ret == WOLFSSL_SUCCESS)
  22323. ret = wolfSSL_EVP_Cipher(ctx, plain, cipher, 16);
  22324. wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
  22325. if (ret != 16)
  22326. return WC_TEST_RET_ENC_NC;
  22327. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22328. return WC_TEST_RET_ENC_NC;
  22329. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22330. wolfSSL_EVP_CIPHER_CTX_free(ctx);
  22331. #endif
  22332. } /* end evp_cipher test */
  22333. #endif /* HAVE_AES_ECB && WOLFSSL_AES_128 */
  22334. #ifndef WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API
  22335. #if defined(WOLFSSL_AES_DIRECT) && defined(WOLFSSL_AES_256)
  22336. /* enable HAVE_AES_DECRYPT for AES_encrypt/decrypt */
  22337. {
  22338. /* Test: AES_encrypt/decrypt/set Key */
  22339. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22340. AES_KEY *enc = (AES_KEY *)XMALLOC(sizeof *enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22341. #ifdef HAVE_AES_DECRYPT
  22342. AES_KEY *dec = (AES_KEY *)XMALLOC(sizeof *dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22343. #endif
  22344. #else
  22345. AES_KEY enc[1];
  22346. #ifdef HAVE_AES_DECRYPT
  22347. AES_KEY dec[1];
  22348. #endif
  22349. #endif
  22350. WOLFSSL_SMALL_STACK_STATIC const byte msg[] =
  22351. {
  22352. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22353. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22354. };
  22355. WOLFSSL_SMALL_STACK_STATIC const byte verify[] =
  22356. {
  22357. 0xf3,0xee,0xd1,0xbd,0xb5,0xd2,0xa0,0x3c,
  22358. 0x06,0x4b,0x5a,0x7e,0x3d,0xb1,0x81,0xf8
  22359. };
  22360. WOLFSSL_SMALL_STACK_STATIC const byte key[] =
  22361. {
  22362. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22363. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22364. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22365. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22366. };
  22367. byte plain[sizeof(msg)];
  22368. byte cipher[sizeof(msg)];
  22369. printf("openSSL extra test\n") ;
  22370. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22371. if (enc == NULL)
  22372. return MEMORY_E;
  22373. #ifdef HAVE_AES_DECRYPT
  22374. if (dec == NULL)
  22375. return MEMORY_E;
  22376. #endif
  22377. #endif
  22378. AES_set_encrypt_key(key, sizeof(key)*8, enc);
  22379. AES_set_decrypt_key(key, sizeof(key)*8, dec);
  22380. AES_encrypt(msg, cipher, enc);
  22381. #ifdef HAVE_AES_DECRYPT
  22382. AES_decrypt(cipher, plain, dec);
  22383. if (XMEMCMP(plain, msg, AES_BLOCK_SIZE))
  22384. return WC_TEST_RET_ENC_NC;
  22385. #endif /* HAVE_AES_DECRYPT */
  22386. if (XMEMCMP(cipher, verify, AES_BLOCK_SIZE))
  22387. return WC_TEST_RET_ENC_NC;
  22388. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22389. XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
  22390. #ifdef HAVE_AES_DECRYPT
  22391. XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
  22392. #endif
  22393. #endif
  22394. }
  22395. #endif /* WOLFSSL_AES_DIRECT && WOLFSSL_AES_256 */
  22396. #endif /* !WOLFSSL_NO_OPENSSL_AES_LOW_LEVEL_API */
  22397. /* EVP_Cipher with EVP_aes_xxx_ctr() */
  22398. #ifdef WOLFSSL_AES_COUNTER
  22399. {
  22400. byte plainBuff [64];
  22401. byte cipherBuff[64];
  22402. #ifdef WOLFSSL_AES_128
  22403. WOLFSSL_SMALL_STACK_STATIC const byte ctrKey[] =
  22404. {
  22405. 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
  22406. 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
  22407. };
  22408. WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
  22409. {
  22410. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22411. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22412. };
  22413. WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
  22414. {
  22415. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22416. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22417. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22418. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22419. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22420. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22421. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22422. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22423. };
  22424. WOLFSSL_SMALL_STACK_STATIC const byte ctrCipher[] =
  22425. {
  22426. 0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
  22427. 0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
  22428. 0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
  22429. 0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
  22430. 0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
  22431. 0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
  22432. 0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
  22433. 0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
  22434. };
  22435. WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
  22436. {
  22437. 0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
  22438. 0xc2
  22439. };
  22440. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22441. WOLFSSL_EVP_CIPHER_CTX *p_en;
  22442. WOLFSSL_EVP_CIPHER_CTX *p_de;
  22443. #endif
  22444. #endif /* WOLFSSL_AES_128 */
  22445. #ifdef WOLFSSL_AES_192
  22446. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22447. * NIST Special Publication 800-38A */
  22448. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Key[] =
  22449. {
  22450. 0x8e,0x73,0xb0,0xf7,0xda,0x0e,0x64,0x52,
  22451. 0xc8,0x10,0xf3,0x2b,0x80,0x90,0x79,0xe5,
  22452. 0x62,0xf8,0xea,0xd2,0x52,0x2c,0x6b,0x7b
  22453. };
  22454. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Iv[] =
  22455. {
  22456. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22457. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22458. };
  22459. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Plain[] =
  22460. {
  22461. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22462. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22463. };
  22464. WOLFSSL_SMALL_STACK_STATIC const byte ctr192Cipher[] =
  22465. {
  22466. 0x1a,0xbc,0x93,0x24,0x17,0x52,0x1c,0xa2,
  22467. 0x4f,0x2b,0x04,0x59,0xfe,0x7e,0x6e,0x0b
  22468. };
  22469. #endif /* WOLFSSL_AES_192 */
  22470. #ifdef WOLFSSL_AES_256
  22471. /* test vector from "Recommendation for Block Cipher Modes of Operation"
  22472. * NIST Special Publication 800-38A */
  22473. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
  22474. {
  22475. 0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
  22476. 0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
  22477. 0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
  22478. 0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
  22479. };
  22480. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Iv[] =
  22481. {
  22482. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  22483. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  22484. };
  22485. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Plain[] =
  22486. {
  22487. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22488. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
  22489. };
  22490. WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
  22491. {
  22492. 0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
  22493. 0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28
  22494. };
  22495. #endif /* WOLFSSL_AES_256 */
  22496. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22497. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22498. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22499. if ((en == NULL) || (de == NULL))
  22500. return MEMORY_E;
  22501. #else
  22502. WOLFSSL_EVP_CIPHER_CTX en[1];
  22503. WOLFSSL_EVP_CIPHER_CTX de[1];
  22504. #endif
  22505. #ifdef WOLFSSL_AES_128
  22506. wolfSSL_EVP_CIPHER_CTX_init(en);
  22507. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22508. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22509. return WC_TEST_RET_ENC_NC;
  22510. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain,
  22511. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22512. return WC_TEST_RET_ENC_NC;
  22513. wolfSSL_EVP_CIPHER_CTX_init(de);
  22514. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22515. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22516. return WC_TEST_RET_ENC_NC;
  22517. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22518. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22519. return WC_TEST_RET_ENC_NC;
  22520. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22521. return WC_TEST_RET_ENC_NC;
  22522. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22523. return WC_TEST_RET_ENC_NC;
  22524. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22525. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22526. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22527. p_en = wolfSSL_EVP_CIPHER_CTX_new();
  22528. if (p_en == NULL)
  22529. return WC_TEST_RET_ENC_ERRNO;
  22530. p_de = wolfSSL_EVP_CIPHER_CTX_new();
  22531. if (p_de == NULL)
  22532. return WC_TEST_RET_ENC_ERRNO;
  22533. if (wolfSSL_EVP_CipherInit(p_en, wolfSSL_EVP_aes_128_ctr(),
  22534. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22535. return WC_TEST_RET_ENC_NC;
  22536. if (wolfSSL_EVP_Cipher(p_en, (byte*)cipherBuff, (byte*)ctrPlain,
  22537. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22538. return WC_TEST_RET_ENC_NC;
  22539. if (wolfSSL_EVP_CipherInit(p_de, wolfSSL_EVP_aes_128_ctr(),
  22540. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22541. return WC_TEST_RET_ENC_NC;
  22542. if (wolfSSL_EVP_Cipher(p_de, (byte*)plainBuff, (byte*)cipherBuff,
  22543. AES_BLOCK_SIZE*4) != AES_BLOCK_SIZE*4)
  22544. return WC_TEST_RET_ENC_NC;
  22545. wolfSSL_EVP_CIPHER_CTX_cleanup(p_en);
  22546. wolfSSL_EVP_CIPHER_CTX_cleanup(p_de);
  22547. wolfSSL_EVP_CIPHER_CTX_free(p_en);
  22548. wolfSSL_EVP_CIPHER_CTX_free(p_de);
  22549. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  22550. if (XMEMCMP(cipherBuff, ctrCipher, AES_BLOCK_SIZE*4))
  22551. return WC_TEST_RET_ENC_NC;
  22552. if (XMEMCMP(plainBuff, ctrPlain, AES_BLOCK_SIZE*4))
  22553. return WC_TEST_RET_ENC_NC;
  22554. wolfSSL_EVP_CIPHER_CTX_init(en);
  22555. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_ctr(),
  22556. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22557. return WC_TEST_RET_ENC_NC;
  22558. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22559. return WC_TEST_RET_ENC_NC;
  22560. wolfSSL_EVP_CIPHER_CTX_init(de);
  22561. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_ctr(),
  22562. (unsigned char*)ctrKey, (unsigned char*)ctrIv, 0) == 0)
  22563. return WC_TEST_RET_ENC_NC;
  22564. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22565. return WC_TEST_RET_ENC_NC;
  22566. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22567. return WC_TEST_RET_ENC_NC;
  22568. if (XMEMCMP(cipherBuff, ctrCipher, 9))
  22569. return WC_TEST_RET_ENC_NC;
  22570. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctrPlain, 9) != 9)
  22571. return WC_TEST_RET_ENC_NC;
  22572. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff, 9) != 9)
  22573. return WC_TEST_RET_ENC_NC;
  22574. if (XMEMCMP(plainBuff, ctrPlain, 9))
  22575. return WC_TEST_RET_ENC_NC;
  22576. if (XMEMCMP(cipherBuff, oddCipher, 9))
  22577. return WC_TEST_RET_ENC_NC;
  22578. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22579. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22580. #endif /* WOLFSSL_AES_128 */
  22581. #ifdef WOLFSSL_AES_192
  22582. wolfSSL_EVP_CIPHER_CTX_init(en);
  22583. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_192_ctr(),
  22584. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22585. return WC_TEST_RET_ENC_NC;
  22586. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr192Plain,
  22587. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22588. return WC_TEST_RET_ENC_NC;
  22589. wolfSSL_EVP_CIPHER_CTX_init(de);
  22590. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_192_ctr(),
  22591. (unsigned char*)ctr192Key, (unsigned char*)ctr192Iv, 0) == 0)
  22592. return WC_TEST_RET_ENC_NC;
  22593. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22594. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22595. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22596. return WC_TEST_RET_ENC_NC;
  22597. if (XMEMCMP(plainBuff, ctr192Plain, sizeof(ctr192Plain)))
  22598. return WC_TEST_RET_ENC_NC;
  22599. if (XMEMCMP(ctr192Cipher, cipherBuff, sizeof(ctr192Cipher)))
  22600. return WC_TEST_RET_ENC_NC;
  22601. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22602. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22603. #endif /* WOLFSSL_AES_192 */
  22604. #ifdef WOLFSSL_AES_256
  22605. wolfSSL_EVP_CIPHER_CTX_init(en);
  22606. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_256_ctr(),
  22607. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22608. return WC_TEST_RET_ENC_NC;
  22609. if (wolfSSL_EVP_Cipher(en, (byte*)cipherBuff, (byte*)ctr256Plain,
  22610. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22611. return WC_TEST_RET_ENC_NC;
  22612. wolfSSL_EVP_CIPHER_CTX_init(de);
  22613. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_256_ctr(),
  22614. (unsigned char*)ctr256Key, (unsigned char*)ctr256Iv, 0) == 0)
  22615. return WC_TEST_RET_ENC_NC;
  22616. XMEMSET(plainBuff, 0, sizeof(plainBuff));
  22617. if (wolfSSL_EVP_Cipher(de, (byte*)plainBuff, (byte*)cipherBuff,
  22618. AES_BLOCK_SIZE) != AES_BLOCK_SIZE)
  22619. return WC_TEST_RET_ENC_NC;
  22620. if (XMEMCMP(plainBuff, ctr256Plain, sizeof(ctr256Plain)))
  22621. return WC_TEST_RET_ENC_NC;
  22622. if (XMEMCMP(ctr256Cipher, cipherBuff, sizeof(ctr256Cipher)))
  22623. return WC_TEST_RET_ENC_NC;
  22624. wolfSSL_EVP_CIPHER_CTX_cleanup(en);
  22625. wolfSSL_EVP_CIPHER_CTX_cleanup(de);
  22626. #endif /* WOLFSSL_AES_256 */
  22627. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22628. wolfSSL_EVP_CIPHER_CTX_free(en);
  22629. wolfSSL_EVP_CIPHER_CTX_free(de);
  22630. #endif
  22631. }
  22632. #endif /* HAVE_AES_COUNTER */
  22633. #if defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  22634. {
  22635. /* EVP_CipherUpdate test */
  22636. WOLFSSL_SMALL_STACK_STATIC const byte cbcPlain[] =
  22637. {
  22638. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  22639. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  22640. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  22641. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  22642. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  22643. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  22644. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  22645. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  22646. };
  22647. byte key[] = "0123456789abcdef "; /* align */
  22648. byte iv[] = "1234567890abcdef "; /* align */
  22649. byte cipher[AES_BLOCK_SIZE * 4];
  22650. byte plain [AES_BLOCK_SIZE * 4];
  22651. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22652. WOLFSSL_EVP_CIPHER_CTX *en = wolfSSL_EVP_CIPHER_CTX_new();
  22653. WOLFSSL_EVP_CIPHER_CTX *de = wolfSSL_EVP_CIPHER_CTX_new();
  22654. #else
  22655. WOLFSSL_EVP_CIPHER_CTX en[1];
  22656. WOLFSSL_EVP_CIPHER_CTX de[1];
  22657. #endif
  22658. int outlen ;
  22659. int total = 0;
  22660. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22661. if ((en == NULL) || (de == NULL))
  22662. return MEMORY_E;
  22663. #endif
  22664. wolfSSL_EVP_CIPHER_CTX_init(en);
  22665. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22666. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22667. return WC_TEST_RET_ENC_NC;
  22668. /* openSSL compatibility, if(inlen == 0)return 1; */
  22669. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22670. (byte*)cbcPlain, 0) != 1)
  22671. return WC_TEST_RET_ENC_NC;
  22672. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22673. return WC_TEST_RET_ENC_NC;
  22674. wolfSSL_EVP_CIPHER_CTX_init(en);
  22675. if (wolfSSL_EVP_CipherInit(en, wolfSSL_EVP_aes_128_cbc(),
  22676. (unsigned char*)key, (unsigned char*)iv, 1) == 0)
  22677. return WC_TEST_RET_ENC_NC;
  22678. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen,
  22679. (byte*)cbcPlain, 9) == 0)
  22680. return WC_TEST_RET_ENC_NC;
  22681. if(outlen != 0)
  22682. return WC_TEST_RET_ENC_NC;
  22683. total += outlen;
  22684. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen,
  22685. (byte*)&cbcPlain[9] , 9) == 0)
  22686. return WC_TEST_RET_ENC_NC;
  22687. if(outlen != 16)
  22688. return WC_TEST_RET_ENC_NC;
  22689. total += outlen;
  22690. if (wolfSSL_EVP_CipherFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22691. return WC_TEST_RET_ENC_NC;
  22692. if(outlen != 16)
  22693. return WC_TEST_RET_ENC_NC;
  22694. total += outlen;
  22695. if(total != 32)
  22696. return WC_TEST_RET_ENC_NC;
  22697. total = 0;
  22698. wolfSSL_EVP_CIPHER_CTX_init(de);
  22699. if (wolfSSL_EVP_CipherInit(de, wolfSSL_EVP_aes_128_cbc(),
  22700. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22701. return WC_TEST_RET_ENC_NC;
  22702. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22703. return WC_TEST_RET_ENC_NC;
  22704. if(outlen != 0)
  22705. return WC_TEST_RET_ENC_NC;
  22706. total += outlen;
  22707. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22708. (byte*)&cipher[6], 12) == 0)
  22709. return WC_TEST_RET_ENC_NC;
  22710. if(outlen != 0)
  22711. total += outlen;
  22712. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen,
  22713. (byte*)&cipher[6+12], 14) == 0)
  22714. return WC_TEST_RET_ENC_NC;
  22715. if(outlen != 16)
  22716. return WC_TEST_RET_ENC_NC;
  22717. total += outlen;
  22718. if (wolfSSL_EVP_CipherFinal(de, (byte*)&plain[total], &outlen) == 0)
  22719. return WC_TEST_RET_ENC_NC;
  22720. if(outlen != 2)
  22721. return WC_TEST_RET_ENC_NC;
  22722. total += outlen;
  22723. if(total != 18)
  22724. return WC_TEST_RET_ENC_NC;
  22725. if (XMEMCMP(plain, cbcPlain, 18))
  22726. return WC_TEST_RET_ENC_NC;
  22727. total = 0;
  22728. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22729. return WC_TEST_RET_ENC_NC;
  22730. wolfSSL_EVP_CIPHER_CTX_init(en);
  22731. if (wolfSSL_EVP_EncryptInit(en, wolfSSL_EVP_aes_128_cbc(),
  22732. (unsigned char*)key, (unsigned char*)iv) == 0)
  22733. return WC_TEST_RET_ENC_NC;
  22734. if (wolfSSL_EVP_CipherUpdate(en, (byte*)cipher, &outlen, (byte*)cbcPlain, 9) == 0)
  22735. return WC_TEST_RET_ENC_NC;
  22736. if(outlen != 0)
  22737. return WC_TEST_RET_ENC_NC;
  22738. total += outlen;
  22739. if (wolfSSL_EVP_CipherUpdate(en, (byte*)&cipher[total], &outlen, (byte*)&cbcPlain[9] , 9) == 0)
  22740. return WC_TEST_RET_ENC_NC;
  22741. if(outlen != 16)
  22742. return WC_TEST_RET_ENC_NC;
  22743. total += outlen;
  22744. if (wolfSSL_EVP_EncryptFinal(en, (byte*)&cipher[total], &outlen) == 0)
  22745. return WC_TEST_RET_ENC_NC;
  22746. if(outlen != 16)
  22747. return WC_TEST_RET_ENC_NC;
  22748. total += outlen;
  22749. if(total != 32)
  22750. return 3438;
  22751. total = 0;
  22752. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22753. return WC_TEST_RET_ENC_NC;
  22754. wolfSSL_EVP_CIPHER_CTX_init(de);
  22755. if (wolfSSL_EVP_DecryptInit(de, wolfSSL_EVP_aes_128_cbc(),
  22756. (unsigned char*)key, (unsigned char*)iv) == 0)
  22757. return WC_TEST_RET_ENC_NC;
  22758. if (wolfSSL_EVP_CipherUpdate(de, (byte*)plain, &outlen, (byte*)cipher, 6) == 0)
  22759. return WC_TEST_RET_ENC_NC;
  22760. if(outlen != 0)
  22761. return WC_TEST_RET_ENC_NC;
  22762. total += outlen;
  22763. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6], 12) == 0)
  22764. return WC_TEST_RET_ENC_NC;
  22765. if(outlen != 0)
  22766. total += outlen;
  22767. if (wolfSSL_EVP_CipherUpdate(de, (byte*)&plain[total], &outlen, (byte*)&cipher[6+12], 14) == 0)
  22768. return WC_TEST_RET_ENC_NC;
  22769. if(outlen != 16)
  22770. return WC_TEST_RET_ENC_NC;
  22771. total += outlen;
  22772. if (wolfSSL_EVP_DecryptFinal(de, (byte*)&plain[total], &outlen) == 0)
  22773. return WC_TEST_RET_ENC_NC;
  22774. if(outlen != 2)
  22775. return WC_TEST_RET_ENC_NC;
  22776. total += outlen;
  22777. if(total != 18)
  22778. return 3447;
  22779. if (XMEMCMP(plain, cbcPlain, 18))
  22780. return WC_TEST_RET_ENC_NC;
  22781. if (wolfSSL_EVP_Cipher_key_length(NULL) != 0)
  22782. return WC_TEST_RET_ENC_NC;
  22783. if (wolfSSL_EVP_Cipher_key_length(wolfSSL_EVP_aes_128_cbc()) != 16)
  22784. return WC_TEST_RET_ENC_NC;
  22785. if (wolfSSL_EVP_CIPHER_CTX_mode(NULL) != 0)
  22786. return WC_TEST_RET_ENC_NC;
  22787. if (wolfSSL_EVP_CIPHER_CTX_mode(en) != (en->flags & WOLFSSL_EVP_CIPH_MODE))
  22788. return WC_TEST_RET_ENC_NC;
  22789. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22790. return WC_TEST_RET_ENC_NC;
  22791. wolfSSL_EVP_CIPHER_CTX_init(en);
  22792. if (wolfSSL_EVP_CipherInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22793. (unsigned char*)key, (unsigned char*)iv, 0) == 0)
  22794. return WC_TEST_RET_ENC_NC;
  22795. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22796. return WC_TEST_RET_ENC_NC;
  22797. wolfSSL_EVP_CIPHER_CTX_init(en);
  22798. if (wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22799. (unsigned char*)key, (unsigned char*)iv) == 0)
  22800. return WC_TEST_RET_ENC_NC;
  22801. if (wolfSSL_EVP_EncryptFinal_ex(NULL, NULL, NULL)
  22802. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22803. {
  22804. return WC_TEST_RET_ENC_NC;
  22805. }
  22806. if (wolfSSL_EVP_EncryptFinal(NULL, NULL, NULL)
  22807. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22808. {
  22809. return WC_TEST_RET_ENC_NC;
  22810. }
  22811. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22812. return WC_TEST_RET_ENC_NC;
  22813. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22814. return WC_TEST_RET_ENC_NC;
  22815. wolfSSL_EVP_CIPHER_CTX_init(de);
  22816. if (wolfSSL_EVP_DecryptInit_ex(de, wolfSSL_EVP_aes_128_cbc(), NULL,
  22817. (unsigned char*)key, (unsigned char*)iv) == 0)
  22818. return WC_TEST_RET_ENC_NC;
  22819. if (wolfSSL_EVP_DecryptFinal(NULL, NULL, NULL)
  22820. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22821. {
  22822. return WC_TEST_RET_ENC_NC;
  22823. }
  22824. if (wolfSSL_EVP_DecryptFinal_ex(NULL, NULL, NULL)
  22825. != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22826. {
  22827. return WC_TEST_RET_ENC_NC;
  22828. }
  22829. if (wolfSSL_EVP_CIPHER_CTX_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22830. return WC_TEST_RET_ENC_NC;
  22831. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22832. return WC_TEST_RET_ENC_NC;
  22833. wolfSSL_EVP_CIPHER_CTX_init(en);
  22834. wolfSSL_EVP_EncryptInit_ex(en, wolfSSL_EVP_aes_128_cbc(), NULL,
  22835. (unsigned char*)key, (unsigned char*)iv);
  22836. if (wolfSSL_EVP_CIPHER_CTX_block_size(en) != en->block_size)
  22837. return WC_TEST_RET_ENC_NC;
  22838. if (wolfSSL_EVP_CIPHER_block_size(NULL) != WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22839. return WC_TEST_RET_ENC_NC;
  22840. if (wolfSSL_EVP_CIPHER_block_size(wolfSSL_EVP_aes_128_cbc()) != AES_BLOCK_SIZE)
  22841. return WC_TEST_RET_ENC_NC;
  22842. if (WOLFSSL_EVP_CIPHER_mode(NULL) != 0)
  22843. return WC_TEST_RET_ENC_NC;
  22844. if (wolfSSL_EVP_CIPHER_flags(wolfSSL_EVP_aes_128_cbc()) != WOLFSSL_EVP_CIPH_CBC_MODE)
  22845. return WC_TEST_RET_ENC_NC;
  22846. wolfSSL_EVP_CIPHER_CTX_clear_flags(en, 0xFFFFFFFF);
  22847. wolfSSL_EVP_CIPHER_CTX_set_flags(en, 42);
  22848. if (en->flags != 42)
  22849. return WC_TEST_RET_ENC_NC;
  22850. if (wolfSSL_EVP_CIPHER_CTX_set_padding(NULL, 0) !=
  22851. WC_NO_ERR_TRACE(WOLFSSL_FAILURE))
  22852. return WC_TEST_RET_ENC_NC;
  22853. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 0) != WOLFSSL_SUCCESS)
  22854. return WC_TEST_RET_ENC_NC;
  22855. if (wolfSSL_EVP_CIPHER_CTX_set_padding(en, 1) != WOLFSSL_SUCCESS)
  22856. return WC_TEST_RET_ENC_NC;
  22857. if (wolfSSL_EVP_CIPHER_CTX_cleanup(en) != WOLFSSL_SUCCESS)
  22858. return WC_TEST_RET_ENC_NC;
  22859. if (wolfSSL_EVP_CIPHER_CTX_cleanup(de) != WOLFSSL_SUCCESS)
  22860. return WC_TEST_RET_ENC_NC;
  22861. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  22862. wolfSSL_EVP_CIPHER_CTX_free(en);
  22863. wolfSSL_EVP_CIPHER_CTX_free(de);
  22864. #endif
  22865. }
  22866. #endif /* WOLFSSL_AES_128 && HAVE_AES_CBC */
  22867. #endif /* !NO_AES && !WOLFCRYPT_ONLY */
  22868. return 0;
  22869. }
  22870. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openSSL_evpMD_test(void)
  22871. {
  22872. wc_test_ret_t ret = 0;
  22873. #if !defined(NO_SHA256) && !defined(NO_SHA)
  22874. WOLFSSL_EVP_MD_CTX* ctx;
  22875. WOLFSSL_EVP_MD_CTX* ctx2;
  22876. WOLFSSL_ENTER("openSSL_evpMD_test");
  22877. ctx = wolfSSL_EVP_MD_CTX_new();
  22878. ctx2 = wolfSSL_EVP_MD_CTX_new();
  22879. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha256());
  22880. if (ret != WOLFSSL_SUCCESS) {
  22881. ret = WC_TEST_RET_ENC_NC;
  22882. goto openSSL_evpMD_test_done;
  22883. }
  22884. ret = wolfSSL_EVP_MD_CTX_copy(ctx2, ctx);
  22885. if (ret != WOLFSSL_SUCCESS) {
  22886. ret = WC_TEST_RET_ENC_NC;
  22887. goto openSSL_evpMD_test_done;
  22888. }
  22889. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22890. ret = WC_TEST_RET_ENC_NC;
  22891. goto openSSL_evpMD_test_done;
  22892. }
  22893. ret = wolfSSL_EVP_DigestInit(ctx, wolfSSL_EVP_sha1());
  22894. if (ret != WOLFSSL_SUCCESS) {
  22895. ret = WC_TEST_RET_ENC_NC;
  22896. goto openSSL_evpMD_test_done;
  22897. }
  22898. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22899. ret = WC_TEST_RET_ENC_NC;
  22900. goto openSSL_evpMD_test_done;
  22901. }
  22902. ret = wolfSSL_EVP_MD_CTX_copy_ex(ctx2, ctx);
  22903. if (ret != WOLFSSL_SUCCESS) {
  22904. ret = WC_TEST_RET_ENC_NC;
  22905. goto openSSL_evpMD_test_done;
  22906. }
  22907. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha256()) == wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22908. ret = WC_TEST_RET_ENC_NC;
  22909. goto openSSL_evpMD_test_done;
  22910. }
  22911. if (wolfSSL_EVP_MD_type(wolfSSL_EVP_sha1()) != wolfSSL_EVP_MD_CTX_type(ctx2)) {
  22912. ret = WC_TEST_RET_ENC_NC;
  22913. goto openSSL_evpMD_test_done;
  22914. }
  22915. if (wolfSSL_EVP_DigestInit_ex(ctx, wolfSSL_EVP_sha1(), NULL) != WOLFSSL_SUCCESS) {
  22916. ret = WC_TEST_RET_ENC_NC;
  22917. goto openSSL_evpMD_test_done;
  22918. }
  22919. if (wolfSSL_EVP_add_digest(NULL) != 0) {
  22920. ret = WC_TEST_RET_ENC_NC;
  22921. goto openSSL_evpMD_test_done;
  22922. }
  22923. if (wolfSSL_EVP_add_cipher(NULL) != 0) {
  22924. ret = WC_TEST_RET_ENC_NC;
  22925. goto openSSL_evpMD_test_done;
  22926. }
  22927. ret = 0; /* got to success state without jumping to end with a fail */
  22928. openSSL_evpMD_test_done:
  22929. wolfSSL_EVP_MD_CTX_free(ctx);
  22930. wolfSSL_EVP_MD_CTX_free(ctx2);
  22931. #endif /* NO_SHA256 */
  22932. return ret;
  22933. }
  22934. #ifdef DEBUG_SIGN
  22935. static void show(const char *title, const char *p, unsigned int s) {
  22936. char* i;
  22937. printf("%s: ", title);
  22938. for (i = p;
  22939. i < p + s;
  22940. printf("%c", *i), i++);
  22941. printf("\n");
  22942. }
  22943. #else
  22944. #define show(a,b,c) WC_DO_NOTHING
  22945. #endif
  22946. #define FOURK_BUFF 4096
  22947. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey0_test(void)
  22948. {
  22949. wc_test_ret_t ret = 0;
  22950. #if !defined(NO_RSA) && !defined(NO_SHA)
  22951. byte* prvTmp;
  22952. byte* pubTmp;
  22953. int prvBytes;
  22954. int pubBytes;
  22955. WOLFSSL_RSA *prvRsa = NULL;
  22956. WOLFSSL_RSA *pubRsa = NULL;
  22957. WOLFSSL_EVP_PKEY *prvPkey = NULL;
  22958. WOLFSSL_EVP_PKEY *pubPkey = NULL;
  22959. WOLFSSL_EVP_PKEY_CTX *enc = NULL;
  22960. WOLFSSL_EVP_PKEY_CTX *dec = NULL;
  22961. byte in[] = TEST_STRING;
  22962. byte out[256];
  22963. size_t outlen;
  22964. size_t keySz;
  22965. byte plain[256];
  22966. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  22967. XFILE keyFile;
  22968. XFILE keypubFile;
  22969. char cliKey[] = "./certs/client-key.der";
  22970. char cliKeypub[] = "./certs/client-keyPub.der";
  22971. #endif
  22972. WOLFSSL_ENTER("openssl_pkey0_test");
  22973. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22974. if (prvTmp == NULL)
  22975. return WC_TEST_RET_ENC_ERRNO;
  22976. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22977. if (pubTmp == NULL) {
  22978. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22979. return WC_TEST_RET_ENC_NC;
  22980. }
  22981. #ifdef USE_CERT_BUFFERS_1024
  22982. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  22983. prvBytes = sizeof_client_key_der_1024;
  22984. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  22985. pubBytes = sizeof_client_keypub_der_1024;
  22986. #elif defined(USE_CERT_BUFFERS_2048)
  22987. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  22988. prvBytes = sizeof_client_key_der_2048;
  22989. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  22990. pubBytes = sizeof_client_keypub_der_2048;
  22991. #else
  22992. keyFile = XFOPEN(cliKey, "rb");
  22993. if (!keyFile) {
  22994. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22995. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  22996. err_sys("can't open ./certs/client-key.der, "
  22997. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  22998. return WC_TEST_RET_ENC_ERRNO;
  22999. }
  23000. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23001. XFCLOSE(keyFile);
  23002. if (prvBytes == 0) {
  23003. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23004. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23005. return WC_TEST_RET_ENC_ERRNO;
  23006. }
  23007. keypubFile = XFOPEN(cliKeypub, "rb");
  23008. if (!keypubFile) {
  23009. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23010. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23011. err_sys("can't open ./certs/client-cert.der, "
  23012. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23013. return WC_TEST_RET_ENC_ERRNO;
  23014. }
  23015. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23016. XFCLOSE(keypubFile);
  23017. if (pubBytes == 0) {
  23018. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23019. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23020. return WC_TEST_RET_ENC_ERRNO;
  23021. }
  23022. #endif /* USE_CERT_BUFFERS */
  23023. prvRsa = wolfSSL_RSA_new();
  23024. pubRsa = wolfSSL_RSA_new();
  23025. if((prvRsa == NULL) || (pubRsa == NULL)){
  23026. printf("error with RSA_new\n");
  23027. ret = WC_TEST_RET_ENC_ERRNO;
  23028. goto openssl_pkey0_test_done;
  23029. }
  23030. ret = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23031. if(ret != WOLFSSL_SUCCESS){
  23032. printf("error with RSA_LoadDer_ex\n");
  23033. ret = WC_TEST_RET_ENC_EC(ret);
  23034. goto openssl_pkey0_test_done;
  23035. }
  23036. ret = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23037. if(ret != WOLFSSL_SUCCESS){
  23038. printf("error with RSA_LoadDer_ex\n");
  23039. ret = WC_TEST_RET_ENC_EC(ret);
  23040. goto openssl_pkey0_test_done;
  23041. }
  23042. keySz = (size_t)wolfSSL_RSA_size(pubRsa);
  23043. prvPkey = wolfSSL_EVP_PKEY_new();
  23044. pubPkey = wolfSSL_EVP_PKEY_new();
  23045. if((prvPkey == NULL) || (pubPkey == NULL)){
  23046. printf("error with PKEY_new\n");
  23047. ret = WC_TEST_RET_ENC_NC;
  23048. goto openssl_pkey0_test_done;
  23049. }
  23050. ret = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23051. ret += wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23052. if(ret != 2){
  23053. printf("error with PKEY_set1_RSA\n");
  23054. ret = WC_TEST_RET_ENC_I(ret);
  23055. goto openssl_pkey0_test_done;
  23056. }
  23057. dec = wolfSSL_EVP_PKEY_CTX_new(prvPkey, NULL);
  23058. enc = wolfSSL_EVP_PKEY_CTX_new(pubPkey, NULL);
  23059. if((dec == NULL)||(enc==NULL)){
  23060. printf("error with EVP_PKEY_CTX_new\n");
  23061. ret = WC_TEST_RET_ENC_NC;
  23062. goto openssl_pkey0_test_done;
  23063. }
  23064. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23065. if (ret != 1) {
  23066. printf("error with decrypt init\n");
  23067. ret = WC_TEST_RET_ENC_NC;
  23068. goto openssl_pkey0_test_done;
  23069. }
  23070. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23071. if (ret != 1) {
  23072. printf("error with encrypt init\n");
  23073. ret = WC_TEST_RET_ENC_NC;
  23074. goto openssl_pkey0_test_done;
  23075. }
  23076. XMEMSET(out, 0, sizeof(out));
  23077. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23078. if (ret != 1) {
  23079. printf("error encrypting msg\n");
  23080. ret = WC_TEST_RET_ENC_NC;
  23081. goto openssl_pkey0_test_done;
  23082. }
  23083. show("encrypted msg", out, outlen);
  23084. XMEMSET(plain, 0, sizeof(plain));
  23085. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23086. if (ret != 1) {
  23087. printf("error decrypting msg\n");
  23088. ret = WC_TEST_RET_ENC_NC;
  23089. goto openssl_pkey0_test_done;
  23090. }
  23091. show("decrypted msg", plain, outlen);
  23092. /* RSA_PKCS1_OAEP_PADDING test */
  23093. ret = wolfSSL_EVP_PKEY_decrypt_init(dec);
  23094. if (ret != 1) {
  23095. printf("error with decrypt init\n");
  23096. ret = WC_TEST_RET_ENC_NC;
  23097. goto openssl_pkey0_test_done;
  23098. }
  23099. ret = wolfSSL_EVP_PKEY_encrypt_init(enc);
  23100. if (ret != 1) {
  23101. printf("error with encrypt init\n");
  23102. ret = WC_TEST_RET_ENC_NC;
  23103. goto openssl_pkey0_test_done;
  23104. }
  23105. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23106. printf("first set rsa padding error\n");
  23107. ret = WC_TEST_RET_ENC_EC(ret);
  23108. goto openssl_pkey0_test_done;
  23109. }
  23110. #ifndef HAVE_FIPS
  23111. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23112. printf("second set rsa padding error\n");
  23113. ret = WC_TEST_RET_ENC_EC(ret);
  23114. goto openssl_pkey0_test_done;
  23115. }
  23116. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23117. printf("third set rsa padding error\n");
  23118. ret = WC_TEST_RET_ENC_EC(ret);
  23119. goto openssl_pkey0_test_done;
  23120. }
  23121. #endif
  23122. XMEMSET(out, 0, sizeof(out));
  23123. ret = wolfSSL_EVP_PKEY_encrypt(enc, out, &outlen, in, sizeof(in));
  23124. if (ret != 1) {
  23125. printf("error encrypting msg\n");
  23126. ret = WC_TEST_RET_ENC_NC;
  23127. goto openssl_pkey0_test_done;
  23128. }
  23129. show("encrypted msg", out, outlen);
  23130. XMEMSET(plain, 0, sizeof(plain));
  23131. ret = wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, out, keySz);
  23132. if (ret != 1) {
  23133. printf("error decrypting msg\n");
  23134. ret = WC_TEST_RET_ENC_NC;
  23135. goto openssl_pkey0_test_done;
  23136. }
  23137. show("decrypted msg", plain, outlen);
  23138. ret = 0; /* made it to this point without error then set success */
  23139. openssl_pkey0_test_done:
  23140. wolfSSL_RSA_free(prvRsa);
  23141. wolfSSL_RSA_free(pubRsa);
  23142. wolfSSL_EVP_PKEY_free(pubPkey);
  23143. wolfSSL_EVP_PKEY_free(prvPkey);
  23144. wolfSSL_EVP_PKEY_CTX_free(dec);
  23145. wolfSSL_EVP_PKEY_CTX_free(enc);
  23146. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23147. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23148. #endif /* NO_RSA */
  23149. return ret;
  23150. }
  23151. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_pkey1_test(void)
  23152. {
  23153. wc_test_ret_t ret = 0;
  23154. #if !defined(NO_FILESYSTEM) && !defined(NO_RSA) && !defined(NO_SHA)
  23155. WOLFSSL_EVP_PKEY_CTX* dec = NULL;
  23156. WOLFSSL_EVP_PKEY_CTX* enc = NULL;
  23157. WOLFSSL_EVP_PKEY* pubKey = NULL;
  23158. WOLFSSL_EVP_PKEY* prvKey = NULL;
  23159. WOLFSSL_X509* x509 = NULL;
  23160. WOLFSSL_SMALL_STACK_STATIC const unsigned char msg[] = "sugar slapped";
  23161. const unsigned char* clikey;
  23162. long cliKeySz;
  23163. size_t outlen;
  23164. int keyLenBits = 2048;
  23165. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23166. unsigned char *tmp = (unsigned char *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23167. unsigned char *cipher = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23168. unsigned char *plain = (unsigned char *)XMALLOC(RSA_TEST_BYTES, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23169. if ((tmp == NULL) ||
  23170. (cipher == NULL) ||
  23171. (plain == NULL)) {
  23172. ret = WC_TEST_RET_ENC_NC;
  23173. goto openssl_pkey1_test_done;
  23174. }
  23175. #else
  23176. unsigned char tmp[FOURK_BUF];
  23177. unsigned char cipher[RSA_TEST_BYTES];
  23178. unsigned char plain[RSA_TEST_BYTES];
  23179. #endif
  23180. WOLFSSL_ENTER("openssl_pkey1_test");
  23181. #if defined(USE_CERT_BUFFERS_1024)
  23182. XMEMCPY(tmp, client_key_der_1024, sizeof_client_key_der_1024);
  23183. cliKeySz = (long)sizeof_client_key_der_1024;
  23184. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_1024,
  23185. sizeof_client_cert_der_1024, SSL_FILETYPE_ASN1);
  23186. keyLenBits = 1024;
  23187. #elif defined(USE_CERT_BUFFERS_2048)
  23188. XMEMCPY(tmp, client_key_der_2048, sizeof_client_key_der_2048);
  23189. cliKeySz = (long)sizeof_client_key_der_2048;
  23190. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_2048,
  23191. sizeof_client_cert_der_2048, SSL_FILETYPE_ASN1);
  23192. #elif defined(USE_CERT_BUFFERS_3072)
  23193. XMEMCPY(tmp, client_key_der_3072, sizeof_client_key_der_3072);
  23194. cliKeySz = (long)sizeof_client_key_der_3072;
  23195. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_3072,
  23196. sizeof_client_cert_der_3072, SSL_FILETYPE_ASN1);
  23197. keyLenBits = 3072;
  23198. #elif defined(USE_CERT_BUFFERS_4096)
  23199. XMEMCPY(tmp, client_key_der_4096, sizeof_client_key_der_4096);
  23200. cliKeySz = (long)sizeof_client_key_der_4096;
  23201. x509 = wolfSSL_X509_load_certificate_buffer(client_cert_der_4096,
  23202. sizeof_client_cert_der_4096, SSL_FILETYPE_ASN1);
  23203. keyLenBits = 4096;
  23204. #else
  23205. {
  23206. XFILE f;
  23207. f = XFOPEN(clientKey, "rb");
  23208. if (!f) {
  23209. err_sys("can't open ./certs/client-key.der, "
  23210. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23211. ret = WC_TEST_RET_ENC_ERRNO;
  23212. goto openssl_pkey1_test_done;
  23213. }
  23214. cliKeySz = (long)XFREAD(tmp, 1, FOURK_BUF, f);
  23215. XFCLOSE(f);
  23216. if (cliKeySz == 0)
  23217. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, openssl_pkey1_test_done);
  23218. }
  23219. /* using existing wolfSSL api to get public and private key */
  23220. x509 = wolfSSL_X509_load_certificate_file(clientCert, WOLFSSL_FILETYPE_ASN1);
  23221. #endif /* USE_CERT_BUFFERS */
  23222. clikey = tmp;
  23223. if ((prvKey = wolfSSL_EVP_PKEY_new()) == NULL) {
  23224. ret = WC_TEST_RET_ENC_ERRNO;
  23225. goto openssl_pkey1_test_done;
  23226. }
  23227. wolfSSL_EVP_PKEY_free(prvKey);
  23228. prvKey = NULL;
  23229. if (x509 == NULL) {
  23230. ret = WC_TEST_RET_ENC_NC;
  23231. goto openssl_pkey1_test_done;
  23232. }
  23233. pubKey = wolfSSL_X509_get_pubkey(x509);
  23234. if (pubKey == NULL) {
  23235. ret = WC_TEST_RET_ENC_NC;
  23236. goto openssl_pkey1_test_done;
  23237. }
  23238. prvKey = wolfSSL_d2i_PrivateKey(WC_EVP_PKEY_RSA, NULL, &clikey, cliKeySz);
  23239. if (prvKey == NULL) {
  23240. ret = WC_TEST_RET_ENC_NC;
  23241. goto openssl_pkey1_test_done;
  23242. }
  23243. /* phase 2 API to create WOLFSSL_EVP_PKEY_CTX and encrypt/decrypt */
  23244. if (wolfSSL_EVP_PKEY_bits(prvKey) != keyLenBits) {
  23245. ret = WC_TEST_RET_ENC_NC;
  23246. goto openssl_pkey1_test_done;
  23247. }
  23248. if (wolfSSL_EVP_PKEY_size(prvKey) != keyLenBits/8) {
  23249. ret = WC_TEST_RET_ENC_NC;
  23250. goto openssl_pkey1_test_done;
  23251. }
  23252. dec = wolfSSL_EVP_PKEY_CTX_new(prvKey, NULL);
  23253. enc = wolfSSL_EVP_PKEY_CTX_new(pubKey, NULL);
  23254. if (dec == NULL || enc == NULL) {
  23255. ret = WC_TEST_RET_ENC_ERRNO;
  23256. goto openssl_pkey1_test_done;
  23257. }
  23258. if (wolfSSL_EVP_PKEY_decrypt_init(dec) != 1) {
  23259. ret = WC_TEST_RET_ENC_NC;
  23260. goto openssl_pkey1_test_done;
  23261. }
  23262. if (wolfSSL_EVP_PKEY_encrypt_init(enc) != 1) {
  23263. ret = WC_TEST_RET_ENC_NC;
  23264. goto openssl_pkey1_test_done;
  23265. }
  23266. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_PADDING) <= 0) {
  23267. ret = WC_TEST_RET_ENC_NC;
  23268. goto openssl_pkey1_test_done;
  23269. }
  23270. #ifndef HAVE_FIPS
  23271. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(dec, WC_RSA_PKCS1_OAEP_PADDING) <= 0){
  23272. ret = WC_TEST_RET_ENC_EC(ret);
  23273. goto openssl_pkey1_test_done;
  23274. }
  23275. if (wolfSSL_EVP_PKEY_CTX_set_rsa_padding(enc, WC_RSA_PKCS1_OAEP_PADDING) <= 0) {
  23276. ret = WC_TEST_RET_ENC_EC(ret);
  23277. goto openssl_pkey1_test_done;
  23278. }
  23279. #endif
  23280. XMEMSET(cipher, 0, RSA_TEST_BYTES);
  23281. outlen = (size_t)(keyLenBits/8);
  23282. if (wolfSSL_EVP_PKEY_encrypt(enc, cipher, &outlen, msg, sizeof(msg)) < 0) {
  23283. ret = WC_TEST_RET_ENC_EC(ret);
  23284. goto openssl_pkey1_test_done;
  23285. }
  23286. XMEMSET(plain, 0, RSA_TEST_BYTES);
  23287. if (wolfSSL_EVP_PKEY_decrypt(dec, plain, &outlen, cipher, outlen) != 1) {
  23288. ret = WC_TEST_RET_ENC_NC;
  23289. goto openssl_pkey1_test_done;
  23290. }
  23291. openssl_pkey1_test_done:
  23292. if (pubKey != NULL) {
  23293. wolfSSL_EVP_PKEY_free(pubKey);
  23294. }
  23295. if (prvKey != NULL) {
  23296. wolfSSL_EVP_PKEY_free(prvKey);
  23297. }
  23298. if (dec != NULL) {
  23299. wolfSSL_EVP_PKEY_CTX_free(dec);
  23300. }
  23301. if (enc != NULL) {
  23302. wolfSSL_EVP_PKEY_CTX_free(enc);
  23303. }
  23304. if (x509 != NULL) {
  23305. wolfSSL_X509_free(x509);
  23306. }
  23307. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  23308. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23309. XFREE(cipher, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23310. XFREE(plain, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23311. #endif
  23312. #endif
  23313. return ret;
  23314. }
  23315. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t openssl_evpSig_test(void)
  23316. {
  23317. #if !defined(NO_RSA) && !defined(NO_SHA)
  23318. byte* prvTmp;
  23319. byte* pubTmp;
  23320. int prvBytes;
  23321. int pubBytes;
  23322. WOLFSSL_RSA *prvRsa;
  23323. WOLFSSL_RSA *pubRsa;
  23324. WOLFSSL_EVP_PKEY *prvPkey;
  23325. WOLFSSL_EVP_PKEY *pubPkey;
  23326. WOLFSSL_EVP_MD_CTX* sign;
  23327. WOLFSSL_EVP_MD_CTX* verf;
  23328. char msg[] = "see spot run";
  23329. unsigned char sig[256];
  23330. unsigned int sigSz;
  23331. const void* pt;
  23332. unsigned int count;
  23333. wc_test_ret_t ret, ret1, ret2;
  23334. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)
  23335. XFILE keyFile;
  23336. XFILE keypubFile;
  23337. char cliKey[] = "./certs/client-key.der";
  23338. char cliKeypub[] = "./certs/client-keyPub.der";
  23339. #endif
  23340. WOLFSSL_ENTER("openssl_evpSig_test");
  23341. prvTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23342. if (prvTmp == NULL)
  23343. return WC_TEST_RET_ENC_ERRNO;
  23344. pubTmp = (byte*)XMALLOC(FOURK_BUFF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23345. if (pubTmp == NULL) {
  23346. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23347. return WC_TEST_RET_ENC_NC;
  23348. }
  23349. #ifdef USE_CERT_BUFFERS_1024
  23350. XMEMCPY(prvTmp, client_key_der_1024, sizeof_client_key_der_1024);
  23351. prvBytes = sizeof_client_key_der_1024;
  23352. XMEMCPY(pubTmp, client_keypub_der_1024, sizeof_client_keypub_der_1024);
  23353. pubBytes = sizeof_client_keypub_der_1024;
  23354. #elif defined(USE_CERT_BUFFERS_2048)
  23355. XMEMCPY(prvTmp, client_key_der_2048, sizeof_client_key_der_2048);
  23356. prvBytes = sizeof_client_key_der_2048;
  23357. XMEMCPY(pubTmp, client_keypub_der_2048, sizeof_client_keypub_der_2048);
  23358. pubBytes = sizeof_client_keypub_der_2048;
  23359. #else
  23360. keyFile = XFOPEN(cliKey, "rb");
  23361. if (!keyFile) {
  23362. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23363. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23364. err_sys("can't open ./certs/client-key.der, "
  23365. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23366. return WC_TEST_RET_ENC_ERRNO;
  23367. }
  23368. prvBytes = (int)XFREAD(prvTmp, 1, (int)FOURK_BUFF, keyFile);
  23369. XFCLOSE(keyFile);
  23370. if (prvBytes == 0) {
  23371. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23372. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23373. return WC_TEST_RET_ENC_ERRNO;
  23374. }
  23375. keypubFile = XFOPEN(cliKeypub, "rb");
  23376. if (!keypubFile) {
  23377. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23378. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23379. err_sys("can't open ./certs/client-cert.der, "
  23380. "Please run from wolfSSL home dir", WC_TEST_RET_ENC_ERRNO);
  23381. return WC_TEST_RET_ENC_ERRNO;
  23382. }
  23383. pubBytes = (int)XFREAD(pubTmp, 1, (int)FOURK_BUFF, keypubFile);
  23384. XFCLOSE(keypubFile);
  23385. if (pubBytes == 0) {
  23386. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23387. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23388. return WC_TEST_RET_ENC_ERRNO;
  23389. }
  23390. #endif /* USE_CERT_BUFFERS */
  23391. prvRsa = wolfSSL_RSA_new();
  23392. pubRsa = wolfSSL_RSA_new();
  23393. if((prvRsa == NULL) || (pubRsa == NULL)){
  23394. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23395. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23396. err_sys("ERROR with RSA_new", WC_TEST_RET_ENC_NC);
  23397. return WC_TEST_RET_ENC_NC;
  23398. }
  23399. ret1 = wolfSSL_RSA_LoadDer_ex(prvRsa, prvTmp, prvBytes, WOLFSSL_RSA_LOAD_PRIVATE);
  23400. ret2 = wolfSSL_RSA_LoadDer_ex(pubRsa, pubTmp, pubBytes, WOLFSSL_RSA_LOAD_PUBLIC);
  23401. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23402. printf("error with RSA_LoadDer_ex\n");
  23403. return WC_TEST_RET_ENC_NC;
  23404. }
  23405. prvPkey = wolfSSL_EVP_PKEY_new();
  23406. pubPkey = wolfSSL_EVP_PKEY_new();
  23407. if((prvPkey == NULL) || (pubPkey == NULL)){
  23408. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23409. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23410. printf("error with KEY_new\n");
  23411. return WC_TEST_RET_ENC_NC;
  23412. }
  23413. ret1 = wolfSSL_EVP_PKEY_set1_RSA(prvPkey, prvRsa);
  23414. ret2 = wolfSSL_EVP_PKEY_set1_RSA(pubPkey, pubRsa);
  23415. if((ret1 != 1) || (ret2 != 1)){
  23416. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23417. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23418. printf("error with WOLFSSL_EVP_PKEY_set1_RSA\n");
  23419. return WC_TEST_RET_ENC_NC;
  23420. }
  23421. /****************** sign and verify *******************/
  23422. sign = wolfSSL_EVP_MD_CTX_new();
  23423. verf = wolfSSL_EVP_MD_CTX_new();
  23424. if((sign == NULL)||(verf == NULL)){
  23425. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23426. wolfSSL_EVP_MD_CTX_free(sign);
  23427. wolfSSL_EVP_MD_CTX_free(verf);
  23428. return WC_TEST_RET_ENC_NC;
  23429. }
  23430. ret = wolfSSL_EVP_SignInit(sign, wolfSSL_EVP_sha1());
  23431. if (ret != WOLFSSL_SUCCESS){
  23432. printf("error with EVP_SignInit\n");
  23433. wolfSSL_EVP_MD_CTX_free(sign);
  23434. wolfSSL_EVP_MD_CTX_free(verf);
  23435. return WC_TEST_RET_ENC_NC;
  23436. }
  23437. count = sizeof(msg);
  23438. show("message = ", (char *)msg, count);
  23439. /* sign */
  23440. XMEMSET(sig, 0, sizeof(sig));
  23441. pt = (const void*)msg;
  23442. ret1 = wolfSSL_EVP_SignUpdate(sign, pt, count);
  23443. ret2 = wolfSSL_EVP_SignFinal(sign, sig, &sigSz, prvPkey);
  23444. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23445. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23446. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23447. wolfSSL_EVP_MD_CTX_free(sign);
  23448. wolfSSL_EVP_MD_CTX_free(verf);
  23449. printf("error with WOLFSSL_EVP_MD_CTX_create\n");
  23450. return WC_TEST_RET_ENC_NC;
  23451. }
  23452. show("signature = ", (char *)sig, sigSz);
  23453. /* verify */
  23454. pt = (const void*)msg;
  23455. ret1 = wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23456. ret2 = wolfSSL_EVP_VerifyUpdate(verf, pt, count);
  23457. if((ret1 != WOLFSSL_SUCCESS) || (ret2 != WOLFSSL_SUCCESS)){
  23458. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23459. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23460. wolfSSL_EVP_MD_CTX_free(sign);
  23461. wolfSSL_EVP_MD_CTX_free(verf);
  23462. printf("error with EVP_Verify\n");
  23463. return WC_TEST_RET_ENC_NC;
  23464. }
  23465. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) != 1) {
  23466. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23467. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23468. wolfSSL_EVP_MD_CTX_free(sign);
  23469. wolfSSL_EVP_MD_CTX_free(verf);
  23470. printf("error with EVP_VerifyFinal\n");
  23471. return WC_TEST_RET_ENC_NC;
  23472. }
  23473. /* expect fail without update */
  23474. wolfSSL_EVP_VerifyInit(verf, wolfSSL_EVP_sha1());
  23475. if (wolfSSL_EVP_VerifyFinal(verf, sig, sigSz, pubPkey) == 1) {
  23476. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23477. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23478. wolfSSL_EVP_MD_CTX_free(sign);
  23479. wolfSSL_EVP_MD_CTX_free(verf);
  23480. printf("EVP_VerifyInit without update not detected\n");
  23481. return WC_TEST_RET_ENC_NC;
  23482. }
  23483. XFREE(pubTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23484. XFREE(prvTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  23485. wolfSSL_EVP_MD_CTX_free(sign);
  23486. wolfSSL_EVP_MD_CTX_free(verf);
  23487. wolfSSL_RSA_free(prvRsa);
  23488. wolfSSL_RSA_free(pubRsa);
  23489. wolfSSL_EVP_PKEY_free(pubPkey);
  23490. wolfSSL_EVP_PKEY_free(prvPkey);
  23491. #endif /* NO_RSA */
  23492. return 0;
  23493. }
  23494. #endif /* OPENSSL_EXTRA */
  23495. #ifndef NO_PWDBASED
  23496. #ifdef HAVE_SCRYPT
  23497. /* Test vectors taken from RFC 7914: scrypt PBKDF - Section 12. */
  23498. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t scrypt_test(void)
  23499. {
  23500. #ifdef HAVE_FIPS
  23501. /* RFC 7914 test vector keys are too short for FIPS. */
  23502. #else
  23503. wc_test_ret_t ret;
  23504. byte derived[64];
  23505. WOLFSSL_SMALL_STACK_STATIC const byte verify1[] = {
  23506. 0x77, 0xd6, 0x57, 0x62, 0x38, 0x65, 0x7b, 0x20,
  23507. 0x3b, 0x19, 0xca, 0x42, 0xc1, 0x8a, 0x04, 0x97,
  23508. 0xf1, 0x6b, 0x48, 0x44, 0xe3, 0x07, 0x4a, 0xe8,
  23509. 0xdf, 0xdf, 0xfa, 0x3f, 0xed, 0xe2, 0x14, 0x42,
  23510. 0xfc, 0xd0, 0x06, 0x9d, 0xed, 0x09, 0x48, 0xf8,
  23511. 0x32, 0x6a, 0x75, 0x3a, 0x0f, 0xc8, 0x1f, 0x17,
  23512. 0xe8, 0xd3, 0xe0, 0xfb, 0x2e, 0x0d, 0x36, 0x28,
  23513. 0xcf, 0x35, 0xe2, 0x0c, 0x38, 0xd1, 0x89, 0x06
  23514. };
  23515. #if !defined(BENCH_EMBEDDED)
  23516. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23517. 0xfd, 0xba, 0xbe, 0x1c, 0x9d, 0x34, 0x72, 0x00,
  23518. 0x78, 0x56, 0xe7, 0x19, 0x0d, 0x01, 0xe9, 0xfe,
  23519. 0x7c, 0x6a, 0xd7, 0xcb, 0xc8, 0x23, 0x78, 0x30,
  23520. 0xe7, 0x73, 0x76, 0x63, 0x4b, 0x37, 0x31, 0x62,
  23521. 0x2e, 0xaf, 0x30, 0xd9, 0x2e, 0x22, 0xa3, 0x88,
  23522. 0x6f, 0xf1, 0x09, 0x27, 0x9d, 0x98, 0x30, 0xda,
  23523. 0xc7, 0x27, 0xaf, 0xb9, 0x4a, 0x83, 0xee, 0x6d,
  23524. 0x83, 0x60, 0xcb, 0xdf, 0xa2, 0xcc, 0x06, 0x40
  23525. };
  23526. #endif
  23527. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23528. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  23529. 0x70, 0x23, 0xbd, 0xcb, 0x3a, 0xfd, 0x73, 0x48,
  23530. 0x46, 0x1c, 0x06, 0xcd, 0x81, 0xfd, 0x38, 0xeb,
  23531. 0xfd, 0xa8, 0xfb, 0xba, 0x90, 0x4f, 0x8e, 0x3e,
  23532. 0xa9, 0xb5, 0x43, 0xf6, 0x54, 0x5d, 0xa1, 0xf2,
  23533. 0xd5, 0x43, 0x29, 0x55, 0x61, 0x3f, 0x0f, 0xcf,
  23534. 0x62, 0xd4, 0x97, 0x05, 0x24, 0x2a, 0x9a, 0xf9,
  23535. 0xe6, 0x1e, 0x85, 0xdc, 0x0d, 0x65, 0x1e, 0x40,
  23536. 0xdf, 0xcf, 0x01, 0x7b, 0x45, 0x57, 0x58, 0x87
  23537. };
  23538. #endif
  23539. #ifdef SCRYPT_TEST_ALL
  23540. /* Test case is very slow.
  23541. * Use for confirmation after code change or new platform.
  23542. */
  23543. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  23544. 0x21, 0x01, 0xcb, 0x9b, 0x6a, 0x51, 0x1a, 0xae,
  23545. 0xad, 0xdb, 0xbe, 0x09, 0xcf, 0x70, 0xf8, 0x81,
  23546. 0xec, 0x56, 0x8d, 0x57, 0x4a, 0x2f, 0xfd, 0x4d,
  23547. 0xab, 0xe5, 0xee, 0x98, 0x20, 0xad, 0xaa, 0x47,
  23548. 0x8e, 0x56, 0xfd, 0x8f, 0x4b, 0xa5, 0xd0, 0x9f,
  23549. 0xfa, 0x1c, 0x6d, 0x92, 0x7c, 0x40, 0xf4, 0xc3,
  23550. 0x37, 0x30, 0x40, 0x49, 0xe8, 0xa9, 0x52, 0xfb,
  23551. 0xcb, 0xf4, 0x5c, 0x6f, 0xa7, 0x7a, 0x41, 0xa4
  23552. };
  23553. #endif
  23554. WOLFSSL_ENTER("scrypt_test");
  23555. ret = wc_scrypt(derived, NULL, 0, NULL, 0, 4, 1, 1, sizeof(verify1));
  23556. if (ret != 0)
  23557. return WC_TEST_RET_ENC_EC(ret);
  23558. if (XMEMCMP(derived, verify1, sizeof(verify1)) != 0)
  23559. return WC_TEST_RET_ENC_NC;
  23560. #if !defined(BENCH_EMBEDDED)
  23561. ret = wc_scrypt(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 10, 8, 16,
  23562. sizeof(verify2));
  23563. if (ret != 0)
  23564. return WC_TEST_RET_ENC_EC(ret);
  23565. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23566. return WC_TEST_RET_ENC_NC;
  23567. #endif
  23568. /* Test case with parallel overflowing */
  23569. ret = wc_scrypt(derived, (byte*)"password", 16, (byte*)"NaCl", 16, 2, 4, 8388608,
  23570. sizeof(verify1));
  23571. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  23572. return WC_TEST_RET_ENC_EC(ret);
  23573. /* Don't run these test on embedded, since they use large mallocs */
  23574. #if !defined(BENCH_EMBEDDED) && !defined(WOLFSSL_LINUXKM) && !defined(HAVE_INTEL_QA)
  23575. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23576. (byte*)"SodiumChloride", 14, 14, 8, 1, sizeof(verify3));
  23577. if (ret != 0)
  23578. return WC_TEST_RET_ENC_EC(ret);
  23579. if (XMEMCMP(derived, verify3, sizeof(verify3)) != 0)
  23580. return WC_TEST_RET_ENC_NC;
  23581. #ifdef SCRYPT_TEST_ALL
  23582. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  23583. (byte*)"SodiumChloride", 14, 20, 8, 1, sizeof(verify4));
  23584. if (ret != 0)
  23585. return WC_TEST_RET_ENC_EC(ret);
  23586. if (XMEMCMP(derived, verify4, sizeof(verify4)) != 0)
  23587. return WC_TEST_RET_ENC_NC;
  23588. #endif
  23589. #else
  23590. #ifdef SCRYPT_TEST_ALL
  23591. (void)verify4;
  23592. #endif
  23593. #endif /* !BENCH_EMBEDDED && !defined(WOLFSSL_LINUXKM) && !HAVE_INTEL_QA */
  23594. #if !defined(BENCH_EMBEDDED)
  23595. ret = wc_scrypt_ex(derived, (byte*)"password", 8, (byte*)"NaCl", 4, 1<<10,
  23596. 8, 16, sizeof(verify2));
  23597. if (ret != 0)
  23598. return WC_TEST_RET_ENC_EC(ret);
  23599. if (XMEMCMP(derived, verify2, sizeof(verify2)) != 0)
  23600. return WC_TEST_RET_ENC_NC;
  23601. #endif
  23602. #endif /* !HAVE_FIPS */
  23603. return 0;
  23604. }
  23605. #endif
  23606. #ifdef HAVE_PKCS12
  23607. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_pbkdf_test(void)
  23608. {
  23609. WOLFSSL_SMALL_STACK_STATIC const byte passwd[] = { 0x00, 0x73, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x67,
  23610. 0x00, 0x00 };
  23611. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x0a, 0x58, 0xCF, 0x64, 0x53, 0x0d, 0x82, 0x3f };
  23612. WOLFSSL_SMALL_STACK_STATIC const byte passwd2[] = { 0x00, 0x71, 0x00, 0x75, 0x00, 0x65, 0x00, 0x65,
  23613. 0x00, 0x67, 0x00, 0x00 };
  23614. WOLFSSL_SMALL_STACK_STATIC const byte salt2[] = { 0x16, 0x82, 0xC0, 0xfC, 0x5b, 0x3f, 0x7e, 0xc5 };
  23615. byte derived[64];
  23616. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23617. 0x27, 0xE9, 0x0D, 0x7E, 0xD5, 0xA1, 0xC4, 0x11,
  23618. 0xBA, 0x87, 0x8B, 0xC0, 0x90, 0xF5, 0xCE, 0xBE,
  23619. 0x5E, 0x9D, 0x5F, 0xE3, 0xD6, 0x2B, 0x73, 0xAA
  23620. };
  23621. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  23622. 0x90, 0x1B, 0x49, 0x70, 0xF0, 0x94, 0xF0, 0xF8,
  23623. 0x45, 0xC0, 0xF3, 0xF3, 0x13, 0x59, 0x18, 0x6A,
  23624. 0x35, 0xE3, 0x67, 0xFE, 0xD3, 0x21, 0xFD, 0x7C
  23625. };
  23626. int id = 1;
  23627. int kLen = 24;
  23628. int iterations = 1;
  23629. wc_test_ret_t ret;
  23630. WOLFSSL_ENTER("pkcs12_pbkdf_test");
  23631. ret = wc_PKCS12_PBKDF(derived, passwd, sizeof(passwd), salt, 8,
  23632. iterations, kLen, WC_SHA256, id);
  23633. if (ret < 0)
  23634. return WC_TEST_RET_ENC_EC(ret);
  23635. if (XMEMCMP(derived, verify, (unsigned long)kLen) != 0)
  23636. return WC_TEST_RET_ENC_NC;
  23637. iterations = 1000;
  23638. ret = wc_PKCS12_PBKDF(derived, passwd2, sizeof(passwd2), salt2, 8,
  23639. iterations, kLen, WC_SHA256, id);
  23640. if (ret < 0)
  23641. return WC_TEST_RET_ENC_EC(ret);
  23642. ret = wc_PKCS12_PBKDF_ex(derived, passwd2, sizeof(passwd2), salt2, 8,
  23643. iterations, kLen, WC_SHA256, id, HEAP_HINT);
  23644. if (ret < 0)
  23645. return WC_TEST_RET_ENC_EC(ret);
  23646. if (XMEMCMP(derived, verify2, 24) != 0)
  23647. return WC_TEST_RET_ENC_NC;
  23648. return 0;
  23649. }
  23650. #endif /* HAVE_PKCS12 */
  23651. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23652. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf2_test(void)
  23653. {
  23654. char passwd[] = "passwordpassword";
  23655. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a,
  23656. 0x5d, 0x63, 0xcb, 0x06 };
  23657. int iterations = 2048;
  23658. int kLen = 24;
  23659. byte derived[64];
  23660. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23661. 0x43, 0x6d, 0xb5, 0xe8, 0xd0, 0xfb, 0x3f, 0x35, 0x42, 0x48, 0x39, 0xbc,
  23662. 0x2d, 0xd4, 0xf9, 0x37, 0xd4, 0x95, 0x16, 0xa7, 0x2a, 0x9a, 0x21, 0xd1
  23663. };
  23664. wc_test_ret_t ret;
  23665. WOLFSSL_ENTER("pbkdf2_test");
  23666. ret = wc_PBKDF2_ex(derived, (byte*)passwd, (int)XSTRLEN(passwd),
  23667. salt, (int)sizeof(salt), iterations,
  23668. kLen, WC_SHA256, HEAP_HINT, devId);
  23669. if (ret != 0)
  23670. return WC_TEST_RET_ENC_EC(ret);
  23671. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23672. return WC_TEST_RET_ENC_NC;
  23673. return 0;
  23674. }
  23675. #endif /* HAVE_PBKDF2 && !NO_SHA256 && !NO_HMAC */
  23676. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23677. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pbkdf1_test(void)
  23678. {
  23679. char passwd[] = "password";
  23680. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = { 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  23681. int iterations = 1000;
  23682. int kLen = 16;
  23683. byte derived[16];
  23684. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  23685. 0xDC, 0x19, 0x84, 0x7E, 0x05, 0xC6, 0x4D, 0x2F,
  23686. 0xAF, 0x10, 0xEB, 0xFB, 0x4A, 0x3D, 0x2A, 0x20
  23687. };
  23688. wc_test_ret_t ret;
  23689. WOLFSSL_ENTER("pbkdf1_test");
  23690. ret = wc_PBKDF1_ex(derived, kLen, NULL, 0, (byte*)passwd,
  23691. (int)XSTRLEN(passwd), salt, (int)sizeof(salt), iterations, WC_SHA,
  23692. HEAP_HINT);
  23693. if (ret != 0)
  23694. return ret;
  23695. if (XMEMCMP(derived, verify, sizeof(verify)) != 0)
  23696. return WC_TEST_RET_ENC_NC;
  23697. return 0;
  23698. }
  23699. #endif /* HAVE_PBKDF2 && !NO_SHA */
  23700. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pwdbased_test(void)
  23701. {
  23702. wc_test_ret_t ret = 0;
  23703. WOLFSSL_ENTER("pwdbased_test");
  23704. #if defined(HAVE_PBKDF1) && !defined(NO_SHA)
  23705. ret = pbkdf1_test();
  23706. if (ret != 0)
  23707. return ret;
  23708. #endif
  23709. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  23710. ret = pbkdf2_test();
  23711. if (ret != 0)
  23712. return ret;
  23713. #endif
  23714. #ifdef HAVE_PKCS12
  23715. ret = pkcs12_pbkdf_test();
  23716. if (ret != 0)
  23717. return ret;
  23718. #endif
  23719. #ifdef HAVE_SCRYPT
  23720. ret = scrypt_test();
  23721. if (ret != 0)
  23722. return ret;
  23723. #endif
  23724. return ret;
  23725. }
  23726. #endif /* NO_PWDBASED */
  23727. #if defined(USE_CERT_BUFFERS_2048) && \
  23728. defined(HAVE_PKCS12) && \
  23729. !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_HMAC) && \
  23730. !defined(NO_CERTS) && !defined(NO_DES3)
  23731. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs12_test(void)
  23732. {
  23733. wc_test_ret_t ret = 0;
  23734. WC_PKCS12* pkcs12 = NULL;
  23735. /* Gen vars */
  23736. byte* pkcs12der = NULL;
  23737. int pkcs12derSz = 0;
  23738. WC_DerCertList derCaList = {
  23739. (byte*)ca_cert_der_2048, sizeof_ca_cert_der_2048, NULL
  23740. };
  23741. char* pass = (char*)"wolfSSL test";
  23742. /* Parsing vars */
  23743. WC_DerCertList* derCaListOut = NULL;
  23744. byte* keyDer = NULL;
  23745. byte* certDer = NULL;
  23746. word32 keySz;
  23747. word32 certSz;
  23748. WOLFSSL_ENTER("pkcs12_test");
  23749. pkcs12 = wc_PKCS12_create(pass, (word32)XSTRLEN(pass),
  23750. (char*)"friendlyName" /* not used currently */,
  23751. (byte*)server_key_der_2048, sizeof_server_key_der_2048,
  23752. (byte*)server_cert_der_2048, sizeof_server_cert_der_2048,
  23753. &derCaList, PBE_SHA1_DES3, PBE_SHA1_DES3, 100, 100,
  23754. 0 /* not used currently */, HEAP_HINT);
  23755. if (pkcs12 == NULL) {
  23756. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23757. goto out;
  23758. }
  23759. ret = wc_i2d_PKCS12(pkcs12, NULL, &pkcs12derSz);
  23760. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  23761. if (ret == 0)
  23762. ret = WC_TEST_RET_ENC_NC;
  23763. else
  23764. ret = WC_TEST_RET_ENC_I(ret);
  23765. goto out;
  23766. }
  23767. pkcs12der = (byte*)XMALLOC(pkcs12derSz, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23768. if (pkcs12der == NULL) {
  23769. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23770. goto out;
  23771. }
  23772. {
  23773. /* Use tmp pointer to avoid advancing pkcs12der */
  23774. byte* tmp = pkcs12der;
  23775. ret = wc_i2d_PKCS12(pkcs12, &tmp, &pkcs12derSz);
  23776. if (ret <= 0) {
  23777. if (ret == 0)
  23778. ret = WC_TEST_RET_ENC_NC;
  23779. else
  23780. ret = WC_TEST_RET_ENC_I(ret);
  23781. goto out;
  23782. }
  23783. }
  23784. wc_PKCS12_free(pkcs12);
  23785. pkcs12 = wc_PKCS12_new_ex(HEAP_HINT);
  23786. if (pkcs12 == NULL) {
  23787. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  23788. goto out;
  23789. }
  23790. /* convert the DER file into an internal structure */
  23791. ret = wc_d2i_PKCS12(pkcs12der, pkcs12derSz, pkcs12);
  23792. if (ret != 0) {
  23793. ret = WC_TEST_RET_ENC_EC(ret);
  23794. goto out;
  23795. }
  23796. /* parse the internal structure into its parts */
  23797. ret = wc_PKCS12_parse(pkcs12, "wolfSSL test", &keyDer, &keySz,
  23798. &certDer, &certSz, &derCaListOut);
  23799. if (ret != 0) {
  23800. ret = WC_TEST_RET_ENC_EC(ret);
  23801. goto out;
  23802. }
  23803. if (keyDer == NULL || certDer == NULL || derCaListOut == NULL) {
  23804. ret = WC_TEST_RET_ENC_NC;
  23805. goto out;
  23806. }
  23807. out:
  23808. if (derCaListOut)
  23809. wc_FreeCertList(derCaListOut, HEAP_HINT);
  23810. XFREE(keyDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23811. XFREE(certDer, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23812. if (pkcs12)
  23813. wc_PKCS12_free(pkcs12);
  23814. XFREE(pkcs12der, HEAP_HINT, DYNAMIC_TYPE_PKCS);
  23815. return ret;
  23816. }
  23817. #endif
  23818. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  23819. #if defined(WOLFSSL_AFALG_XILINX) || defined(WOLFSSL_AFALG_XILINX_AES) || \
  23820. defined(WOLFSSL_AFALG_XILINX_SHA3) || defined(WOLFSSL_AFALG_HASH_KEEP) || \
  23821. defined(WOLFSSL_AFALG_XILINX_RSA)
  23822. /* hkdf_test has issue with WOLFSSL_TEST_SUBROUTINE set on Xilinx with afalg */
  23823. static wc_test_ret_t hkdf_test(void)
  23824. #else
  23825. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hkdf_test(void)
  23826. #endif
  23827. {
  23828. wc_test_ret_t ret = 0;
  23829. #if !defined(NO_SHA) || !defined(NO_SHA256)
  23830. int L;
  23831. byte okm1[42];
  23832. byte ikm1[22] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23833. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  23834. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  23835. #ifndef HAVE_FIPS
  23836. byte salt1[13] ={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  23837. 0x08, 0x09, 0x0a, 0x0b, 0x0c };
  23838. byte info1[10] ={ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  23839. 0xf8, 0xf9 };
  23840. #endif
  23841. #ifndef NO_SHA
  23842. byte res1[42] = { 0x0a, 0xc1, 0xaf, 0x70, 0x02, 0xb3, 0xd7, 0x61,
  23843. 0xd1, 0xe5, 0x52, 0x98, 0xda, 0x9d, 0x05, 0x06,
  23844. 0xb9, 0xae, 0x52, 0x05, 0x72, 0x20, 0xa3, 0x06,
  23845. 0xe0, 0x7b, 0x6b, 0x87, 0xe8, 0xdf, 0x21, 0xd0,
  23846. 0xea, 0x00, 0x03, 0x3d, 0xe0, 0x39, 0x84, 0xd3,
  23847. 0x49, 0x18 };
  23848. #ifndef HAVE_FIPS
  23849. byte res2[42] = { 0x08, 0x5a, 0x01, 0xea, 0x1b, 0x10, 0xf3, 0x69,
  23850. 0x33, 0x06, 0x8b, 0x56, 0xef, 0xa5, 0xad, 0x81,
  23851. 0xa4, 0xf1, 0x4b, 0x82, 0x2f, 0x5b, 0x09, 0x15,
  23852. 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2,
  23853. 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3,
  23854. 0xf8, 0x96 };
  23855. #endif
  23856. #endif /* !NO_SHA */
  23857. #ifndef NO_SHA256
  23858. byte res3[42] = { 0x8d, 0xa4, 0xe7, 0x75, 0xa5, 0x63, 0xc1, 0x8f,
  23859. 0x71, 0x5f, 0x80, 0x2a, 0x06, 0x3c, 0x5a, 0x31,
  23860. 0xb8, 0xa1, 0x1f, 0x5c, 0x5e, 0xe1, 0x87, 0x9e,
  23861. 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d,
  23862. 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a,
  23863. 0x96, 0xc8 };
  23864. #ifndef HAVE_FIPS
  23865. byte res4[42] = { 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
  23866. 0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
  23867. 0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
  23868. 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
  23869. 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
  23870. 0x58, 0x65 };
  23871. #endif
  23872. #endif /* !NO_SHA256 */
  23873. WOLFSSL_ENTER("hkdf_test");
  23874. XMEMSET(okm1, 0, sizeof(okm1));
  23875. L = (int)sizeof(okm1);
  23876. #ifndef NO_SHA
  23877. ret = wc_HKDF(WC_SHA, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23878. okm1, (word32)L);
  23879. if (ret != 0)
  23880. return WC_TEST_RET_ENC_EC(ret);
  23881. if (XMEMCMP(okm1, res1, (unsigned long)L) != 0)
  23882. return WC_TEST_RET_ENC_NC;
  23883. #ifndef HAVE_FIPS
  23884. /* fips can't have key size under 14 bytes, salt is key too */
  23885. L = (int)sizeof(okm1);
  23886. ret = wc_HKDF(WC_SHA, ikm1, 11, salt1, (word32)sizeof(salt1),
  23887. info1, (word32)sizeof(info1), okm1, (word32)L);
  23888. if (ret != 0)
  23889. return WC_TEST_RET_ENC_EC(ret);
  23890. if (XMEMCMP(okm1, res2, (unsigned long)L) != 0)
  23891. return WC_TEST_RET_ENC_NC;
  23892. #endif /* HAVE_FIPS */
  23893. #endif /* !NO_SHA */
  23894. #ifndef NO_SHA256
  23895. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1), NULL, 0, NULL, 0,
  23896. okm1, (word32)L);
  23897. if (ret != 0)
  23898. return WC_TEST_RET_ENC_EC(ret);
  23899. if (XMEMCMP(okm1, res3, (unsigned long)L) != 0)
  23900. return WC_TEST_RET_ENC_NC;
  23901. #ifndef HAVE_FIPS
  23902. /* fips can't have key size under 14 bytes, salt is key too */
  23903. ret = wc_HKDF(WC_SHA256, ikm1, (word32)sizeof(ikm1),
  23904. salt1, (word32)sizeof(salt1), info1, (word32)sizeof(info1), okm1, (word32)L);
  23905. if (ret != 0)
  23906. return WC_TEST_RET_ENC_EC(ret);
  23907. if (XMEMCMP(okm1, res4, (unsigned long)L) != 0)
  23908. return WC_TEST_RET_ENC_NC;
  23909. #endif /* HAVE_FIPS */
  23910. #endif /* !NO_SHA256 */
  23911. #endif /* !NO_SHA || !NO_SHA256 */
  23912. return ret;
  23913. }
  23914. #endif /* HAVE_HKDF */
  23915. #ifdef WOLFSSL_WOLFSSH
  23916. typedef struct {
  23917. byte hashId;
  23918. byte keyId;
  23919. const byte* k;
  23920. word32 kSz;
  23921. const byte* h;
  23922. word32 hSz;
  23923. const byte* sessionId;
  23924. word32 sessionIdSz;
  23925. const byte* expectedKey;
  23926. word32 expectedKeySz;
  23927. } SshKdfTestVector;
  23928. /** Test Vector Set #3: SHA-256 **/
  23929. static const byte sshKdfTvSet3k[] = {
  23930. 0x6A, 0xC3, 0x82, 0xEA, 0xAC, 0xA0, 0x93, 0xE1,
  23931. 0x25, 0xE2, 0x5C, 0x24, 0xBE, 0xBC, 0x84, 0x64,
  23932. 0x0C, 0x11, 0x98, 0x75, 0x07, 0x34, 0x4B, 0x5C,
  23933. 0x73, 0x9C, 0xEB, 0x84, 0xA9, 0xE0, 0xB2, 0x22,
  23934. 0xB9, 0xA8, 0xB5, 0x1C, 0x83, 0x9E, 0x5E, 0xBE,
  23935. 0x49, 0xCF, 0xAD, 0xBF, 0xB3, 0x95, 0x99, 0x76,
  23936. 0x4E, 0xD5, 0x22, 0x09, 0x9D, 0xC9, 0x12, 0x75,
  23937. 0x19, 0x50, 0xDC, 0x7D, 0xC9, 0x7F, 0xBD, 0xC0,
  23938. 0x63, 0x28, 0xB6, 0x8F, 0x22, 0x78, 0x1F, 0xD3,
  23939. 0x15, 0xAF, 0x56, 0x80, 0x09, 0xA5, 0x50, 0x9E,
  23940. 0x5B, 0x87, 0xA1, 0x1B, 0xF5, 0x27, 0xC0, 0x56,
  23941. 0xDA, 0xFF, 0xD8, 0x2A, 0xB6, 0xCB, 0xC2, 0x5C,
  23942. 0xCA, 0x37, 0x14, 0x34, 0x59, 0xE7, 0xBC, 0x63,
  23943. 0xBC, 0xDE, 0x52, 0x75, 0x7A, 0xDE, 0xB7, 0xDF,
  23944. 0x01, 0xCF, 0x12, 0x17, 0x3F, 0x1F, 0xEF, 0x81,
  23945. 0x02, 0xEC, 0x5A, 0xB1, 0x42, 0xC2, 0x13, 0xDD,
  23946. 0x9D, 0x30, 0x69, 0x62, 0x78, 0xA8, 0xD8, 0xBC,
  23947. 0x32, 0xDD, 0xE9, 0x59, 0x2D, 0x28, 0xC0, 0x78,
  23948. 0xC6, 0xD9, 0x2B, 0x94, 0x7D, 0x82, 0x5A, 0xCA,
  23949. 0xAB, 0x64, 0x94, 0x84, 0x6A, 0x49, 0xDE, 0x24,
  23950. 0xB9, 0x62, 0x3F, 0x48, 0x89, 0xE8, 0xAD, 0xC3,
  23951. 0x8E, 0x8C, 0x66, 0x9E, 0xFF, 0xEF, 0x17, 0x60,
  23952. 0x40, 0xAD, 0x94, 0x5E, 0x90, 0xA7, 0xD3, 0xEE,
  23953. 0xC1, 0x5E, 0xFE, 0xEE, 0x78, 0xAE, 0x71, 0x04,
  23954. 0x3C, 0x96, 0x51, 0x11, 0x03, 0xA1, 0x6B, 0xA7,
  23955. 0xCA, 0xF0, 0xAC, 0xD0, 0x64, 0x2E, 0xFD, 0xBE,
  23956. 0x80, 0x99, 0x34, 0xFA, 0xA1, 0xA5, 0xF1, 0xBD,
  23957. 0x11, 0x04, 0x36, 0x49, 0xB2, 0x5C, 0xCD, 0x1F,
  23958. 0xEE, 0x2E, 0x38, 0x81, 0x5D, 0x4D, 0x5F, 0x5F,
  23959. 0xC6, 0xB4, 0x10, 0x29, 0x69, 0xF2, 0x1C, 0x22,
  23960. 0xAE, 0x1B, 0x0E, 0x7D, 0x36, 0x03, 0xA5, 0x56,
  23961. 0xA1, 0x32, 0x62, 0xFF, 0x62, 0x8D, 0xE2, 0x22
  23962. };
  23963. static const byte sshKdfTvSet3h[] = {
  23964. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23965. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23966. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23967. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23968. };
  23969. static const byte sshKdfTvSet3sid[] = {
  23970. 0x7B, 0x70, 0x01, 0x18, 0x5E, 0x25, 0x6D, 0x44,
  23971. 0x93, 0x44, 0x5F, 0x39, 0xA5, 0x5F, 0xB9, 0x05,
  23972. 0xE6, 0x32, 0x1F, 0x4B, 0x5D, 0xD8, 0xBB, 0xF3,
  23973. 0x10, 0x0D, 0x51, 0xBA, 0x0B, 0xDA, 0x3D, 0x2D
  23974. };
  23975. static const byte sshKdfTvSet3a[] = {
  23976. 0x81, 0xF0, 0x33, 0x0E, 0xF6, 0xF0, 0x53, 0x61,
  23977. 0xB3, 0x82, 0x3B, 0xFD, 0xED, 0x6E, 0x1D, 0xE9
  23978. };
  23979. static const byte sshKdfTvSet3b[] = {
  23980. 0x3F, 0x6F, 0xD2, 0x06, 0x5E, 0xEB, 0x2B, 0x0B,
  23981. 0x1D, 0x93, 0x19, 0x5A, 0x1F, 0xED, 0x48, 0xA5
  23982. };
  23983. static const byte sshKdfTvSet3c[] = {
  23984. 0xC3, 0x54, 0x71, 0x03, 0x4E, 0x6F, 0xD6, 0x54,
  23985. 0x76, 0x13, 0x17, 0x8E, 0x23, 0x43, 0x5F, 0x21
  23986. };
  23987. static const byte sshKdfTvSet3d[] = {
  23988. 0x7E, 0x9D, 0x79, 0x03, 0x20, 0x90, 0xD9, 0x9F,
  23989. 0x98, 0xB0, 0x15, 0x63, 0x4D, 0xD9, 0xF4, 0x62
  23990. };
  23991. static const byte sshKdfTvSet3e[] = {
  23992. 0x24, 0xEE, 0x55, 0x9A, 0xD7, 0xCE, 0x71, 0x2B,
  23993. 0x68, 0x5D, 0x0B, 0x22, 0x71, 0xE4, 0x43, 0xC1,
  23994. 0x7A, 0xB1, 0xD1, 0xDC, 0xEB, 0x5A, 0x36, 0x05,
  23995. 0x69, 0xD2, 0x5D, 0x5D, 0xC2, 0x43, 0x00, 0x2F
  23996. };
  23997. static const byte sshKdfTvSet3f[] = {
  23998. 0xC3, 0x41, 0x9C, 0x2B, 0x96, 0x62, 0x35, 0x86,
  23999. 0x9D, 0x71, 0x4B, 0xA5, 0xAC, 0x48, 0xDD, 0xB7,
  24000. 0xD9, 0xE3, 0x5C, 0x8C, 0x19, 0xAA, 0xC7, 0x34,
  24001. 0x22, 0x33, 0x7A, 0x37, 0x34, 0x53, 0x60, 0x7E
  24002. };
  24003. static const SshKdfTestVector sshKdfTestVectors[] = {
  24004. {WC_HASH_TYPE_SHA256, 'A',
  24005. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24006. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24007. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24008. sshKdfTvSet3a, sizeof(sshKdfTvSet3a)},
  24009. {WC_HASH_TYPE_SHA256, 'B',
  24010. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24011. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24012. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24013. sshKdfTvSet3b, sizeof(sshKdfTvSet3b)},
  24014. {WC_HASH_TYPE_SHA256, 'C',
  24015. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24016. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24017. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24018. sshKdfTvSet3c, sizeof(sshKdfTvSet3c)},
  24019. {WC_HASH_TYPE_SHA256, 'D',
  24020. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24021. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24022. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24023. sshKdfTvSet3d, sizeof(sshKdfTvSet3d)},
  24024. {WC_HASH_TYPE_SHA256, 'E',
  24025. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24026. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24027. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24028. sshKdfTvSet3e, sizeof(sshKdfTvSet3e)},
  24029. {WC_HASH_TYPE_SHA256, 'F',
  24030. sshKdfTvSet3k, sizeof(sshKdfTvSet3k),
  24031. sshKdfTvSet3h, sizeof(sshKdfTvSet3h),
  24032. sshKdfTvSet3sid, sizeof(sshKdfTvSet3sid),
  24033. sshKdfTvSet3f, sizeof(sshKdfTvSet3f)},
  24034. };
  24035. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sshkdf_test(void)
  24036. {
  24037. byte cKey[32]; /* Greater of SHA256_DIGEST_SIZE and AES_BLOCK_SIZE */
  24038. word32 i;
  24039. word32 tc = sizeof(sshKdfTestVectors)/sizeof(SshKdfTestVector);
  24040. const SshKdfTestVector* tv = NULL;
  24041. wc_test_ret_t result = 0;
  24042. WOLFSSL_ENTER("sshkdf_test");
  24043. /* sId - Session ID, eKey - Expected Key, cKey - Calculated Key */
  24044. for (i = 0, tv = sshKdfTestVectors; i < tc; i++, tv++) {
  24045. result = wc_SSH_KDF(tv->hashId, tv->keyId,
  24046. cKey, tv->expectedKeySz,
  24047. tv->k, tv->kSz, tv->h, tv->hSz,
  24048. tv->sessionId, tv->sessionIdSz);
  24049. if (result != 0) {
  24050. printf("KDF: Could not derive key.\n");
  24051. result = WC_TEST_RET_ENC_EC(result);
  24052. }
  24053. else {
  24054. if (XMEMCMP(cKey, tv->expectedKey, tv->expectedKeySz) != 0) {
  24055. printf("KDF: Calculated Key does not match Expected Key.\n");
  24056. result = WC_TEST_RET_ENC_EC(result);
  24057. }
  24058. }
  24059. if (result != 0) break;
  24060. }
  24061. return result;
  24062. }
  24063. #endif /* WOLFSSL_WOLFSSH */
  24064. #if defined(WOLFSSL_HAVE_PRF) && !defined(NO_HMAC) && defined(WOLFSSL_SHA384)
  24065. #define DIGL 12
  24066. #define SECL 48
  24067. #define LBSL 63
  24068. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prf_test(void)
  24069. {
  24070. int ret;
  24071. byte dig[DIGL] = {0};
  24072. byte secret[SECL] = {
  24073. 0x10, 0xbc, 0xb4, 0xa2, 0xe8, 0xdc, 0xf1, 0x9b, 0x4c,
  24074. 0x51, 0x9c, 0xed, 0x31, 0x1b, 0x51, 0x57, 0x02, 0x3f,
  24075. 0xa1, 0x7d, 0xfb, 0x0e, 0xf3, 0x4e, 0x8f, 0x6f, 0x71,
  24076. 0xa3, 0x67, 0x76, 0x6b, 0xfa, 0x5d, 0x46, 0x4a, 0xe8,
  24077. 0x61, 0x18, 0x81, 0xc4, 0x66, 0xcc, 0x6f, 0x09, 0x99,
  24078. 0x9d, 0xfc, 0x47
  24079. };
  24080. byte lablSd[LBSL] = {
  24081. 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x66, 0x69,
  24082. 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x0b, 0x46, 0xba,
  24083. 0x56, 0xbf, 0x1f, 0x5d, 0x99, 0xff, 0xe9, 0xbb, 0x43,
  24084. 0x01, 0xe7, 0xca, 0x2c, 0x00, 0xdf, 0x9a, 0x39, 0x6e,
  24085. 0xcf, 0x6d, 0x15, 0x27, 0x4d, 0xf2, 0x93, 0x96, 0x4a,
  24086. 0x91, 0xde, 0x5c, 0xc0, 0x47, 0x7c, 0xa8, 0xae, 0xcf,
  24087. 0x5d, 0x93, 0x5f, 0x4c, 0x92, 0xcc, 0x98, 0x5b, 0x43
  24088. };
  24089. byte expected[DIGL] = {
  24090. 0xee, 0xcb, 0xb1, 0x30, 0xf2, 0xcd, 0xb3, 0x4a,
  24091. 0xbe, 0xda, 0xc1, 0xf6
  24092. };
  24093. int digL = DIGL;
  24094. int secL = SECL;
  24095. int lblsdL = LBSL;
  24096. int hash_type = sha384_mac;
  24097. ret = wc_PRF(dig, (word32)digL, secret, (word32)secL, lablSd,
  24098. (word32)lblsdL, hash_type,
  24099. HEAP_HINT, INVALID_DEVID);
  24100. if (ret != 0) {
  24101. printf("Failed w/ code: %d\n", ret);
  24102. return WC_TEST_RET_ENC_EC(ret);
  24103. }
  24104. if (XMEMCMP(expected, dig, DIGL) != 0) {
  24105. printf("Got unexpected digest\n");
  24106. return WC_TEST_RET_ENC_NC;
  24107. }
  24108. return 0;
  24109. }
  24110. #endif /* WOLFSSL_HAVE_PRF && !NO_HMAC */
  24111. #ifdef WOLFSSL_HAVE_PRF
  24112. #if defined(HAVE_HKDF) && !defined(NO_HMAC)
  24113. #ifdef WOLFSSL_BASE16
  24114. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls12_kdf_test(void)
  24115. {
  24116. const char* preMasterSecret = "D06F9C19BFF49B1E91E4EFE97345D089"
  24117. "4E6C2E6C34A165B24540E2970875D641"
  24118. "2AA6515871B389B4C199BB8389C71CED";
  24119. const char* helloRandom = "162B81EDFBEAE4F25240320B87E7651C"
  24120. "865564191DD782DB0B9ECA275FBA1BB9"
  24121. "5A1DA3DF436D68DA86C5E7B4B4A36E46"
  24122. "B977C61767983A31BE270D74517BD0F6";
  24123. const char* masterSecret = "EB38B8D89B98B1C266DE44BB3CA14E83"
  24124. "C32F009F9955B1D994E61D3C51EE8760"
  24125. "90B4EF89CC7AF42F46E72201BFCC7977";
  24126. const char* label = "master secret";
  24127. byte pms[48] = {0};
  24128. byte seed[64] = {0};
  24129. byte ms[48] = {0};
  24130. byte result[48] = {0};
  24131. word32 pmsSz = (word32)sizeof(pms);
  24132. word32 seedSz = (word32)sizeof(seed);
  24133. word32 msSz = (word32)sizeof(ms);
  24134. int ret;
  24135. ret = Base16_Decode((const byte*)preMasterSecret,
  24136. (word32)XSTRLEN(preMasterSecret), pms, &pmsSz);
  24137. if (ret != 0)
  24138. return ret;
  24139. ret = Base16_Decode((const byte*)helloRandom,
  24140. (word32)XSTRLEN(helloRandom), seed, &seedSz);
  24141. if (ret != 0)
  24142. return ret;
  24143. ret = Base16_Decode((const byte*)masterSecret,
  24144. (word32)XSTRLEN(masterSecret), ms, &msSz);
  24145. if (ret != 0)
  24146. return ret;
  24147. ret = wc_PRF_TLS(result, msSz, pms, pmsSz,
  24148. (const byte*)label, (word32)XSTRLEN(label), seed, seedSz,
  24149. 1, sha256_mac, NULL, INVALID_DEVID);
  24150. if (ret != 0) {
  24151. if (ret == WC_NO_ERR_TRACE(FIPS_PRIVATE_KEY_LOCKED_E)) {
  24152. printf(" wc_PRF_TLSv12: Private key locked.\n");
  24153. }
  24154. return WC_TEST_RET_ENC_NC;
  24155. }
  24156. if (XMEMCMP(result, ms, msSz) != 0)
  24157. return WC_TEST_RET_ENC_NC;
  24158. return 0;
  24159. }
  24160. #endif /* WOLFSSL_BASE16 */
  24161. #endif /* WOLFSSL_HAVE_HKDF && !NO_HMAC */
  24162. #endif /* WOLFSSL_HAVE_PRF */
  24163. #ifdef WOLFSSL_TLS13
  24164. #define TLSV13_PSK_DHE_SZ 40
  24165. typedef struct {
  24166. enum wc_HashType hashAlg;
  24167. word32 pskSz;
  24168. word32 dheSz;
  24169. byte psk[TLSV13_PSK_DHE_SZ];
  24170. byte dhe[TLSV13_PSK_DHE_SZ];
  24171. byte hashHello1[WC_MAX_DIGEST_SIZE];
  24172. byte hashHello2[WC_MAX_DIGEST_SIZE];
  24173. byte hashFinished1[WC_MAX_DIGEST_SIZE];
  24174. byte hashFinished2[WC_MAX_DIGEST_SIZE];
  24175. /* Expected */
  24176. byte clientEarlyTrafficSecret[WC_MAX_DIGEST_SIZE];
  24177. byte earlyExporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24178. byte clientHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24179. byte serverHandshakeTrafficSecret[WC_MAX_DIGEST_SIZE];
  24180. byte clientApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24181. byte serverApplicationTrafficSecret[WC_MAX_DIGEST_SIZE];
  24182. byte exporterMasterSecret[WC_MAX_DIGEST_SIZE];
  24183. byte resumptionMasterSecret[WC_MAX_DIGEST_SIZE];
  24184. } Tls13KdfTestVector;
  24185. /* The following tests come from the CAVP test vectors we used for
  24186. * our FIPS validation. The hash values used are the components from
  24187. * the test hashed together. hashHello1 is the hash of the
  24188. * clientHelloRandom value of the test vector. hashHello2 is the hash
  24189. * of the clientHelloRandom and serverHelloRandom values from the test
  24190. * vector. hashFinished1 is clientHelloRandom, serverHelloRandom, and
  24191. * serverFinishedRandom. hashFinished2 is clientHelloRandom,
  24192. * serverHelloRandom, serverFinishedRandom, and clietnFinishedRandom
  24193. * hashed together. */
  24194. static const Tls13KdfTestVector tls13KdfTestVectors[] = {
  24195. { /* 1 */
  24196. WC_HASH_TYPE_SHA256, 35, 35,
  24197. { /* PSK */
  24198. 0x7b, 0xf1, 0x05, 0x31, 0x36, 0xfa, 0x03, 0xdc,
  24199. 0x31, 0x97, 0x88, 0x04, 0x9c, 0xbc, 0xee, 0xf7,
  24200. 0x8d, 0x84, 0x95, 0x26, 0xaf, 0x1d, 0x68, 0xb0,
  24201. 0x60, 0x7a, 0xcc, 0x4f, 0xc1, 0xd3, 0xa1, 0x68,
  24202. 0x7f, 0x6d, 0xbe
  24203. },
  24204. { /* DHE */
  24205. 0x6e, 0xa1, 0x77, 0xab, 0x2f, 0x43, 0xd2, 0x4b,
  24206. 0xe5, 0xa1, 0x09, 0xe0, 0x7a, 0xd0, 0x01, 0x35,
  24207. 0x8d, 0xf8, 0xf2, 0x5c, 0x91, 0x02, 0xb0, 0x6c,
  24208. 0x3f, 0xeb, 0xee, 0xa4, 0x42, 0x19, 0xce, 0xdc,
  24209. 0x81, 0x26, 0x40
  24210. },
  24211. { /* Hello 1 */
  24212. 0xd9, 0x4b, 0xe4, 0x17, 0xef, 0x58, 0x73, 0x7d,
  24213. 0x28, 0x3d, 0xf0, 0xcc, 0x05, 0x03, 0xaf, 0xac,
  24214. 0x3d, 0x92, 0x79, 0x48, 0xe8, 0x8c, 0xdb, 0xce,
  24215. 0x95, 0x82, 0x21, 0x31, 0x7b, 0x61, 0xd7, 0xc6
  24216. },
  24217. { /* Hello 2 */
  24218. 0xb7, 0x7f, 0x29, 0x91, 0xa4, 0x8b, 0x34, 0xdb,
  24219. 0xbd, 0xc7, 0x54, 0x1c, 0x3b, 0x86, 0xa3, 0x69,
  24220. 0xfe, 0x26, 0xe4, 0x7b, 0xac, 0x57, 0x71, 0xb3,
  24221. 0x32, 0x97, 0xed, 0xd2, 0x0e, 0x95, 0xb8, 0x63
  24222. },
  24223. { /* Finished 1 */
  24224. 0x65, 0xdb, 0x6d, 0x71, 0x71, 0xd0, 0xd8, 0x49,
  24225. 0xd0, 0x3c, 0x8e, 0x2b, 0x24, 0xdf, 0xc2, 0xe9,
  24226. 0xd6, 0xfd, 0xea, 0x04, 0x95, 0x7c, 0xf0, 0x7e,
  24227. 0x57, 0x74, 0x7c, 0xdd, 0xa3, 0x0b, 0x2b, 0x36
  24228. },
  24229. { /* Finished 2 */
  24230. 0x28, 0xf2, 0xf2, 0x79, 0xcf, 0x20, 0x52, 0x90,
  24231. 0x1d, 0x91, 0x05, 0xad, 0x44, 0x26, 0x23, 0x96,
  24232. 0x32, 0xce, 0xec, 0x61, 0xd1, 0xbf, 0x00, 0x48,
  24233. 0x4a, 0xa5, 0x60, 0xcc, 0x28, 0xb5, 0x8d, 0x98
  24234. },
  24235. { /* Client Early Traffic Secret */
  24236. 0x07, 0x14, 0x6a, 0x26, 0x5b, 0x6c, 0x7f, 0x4d, 0x6b, 0x47, 0x3f, 0xd5,
  24237. 0x03, 0x1d, 0xd2, 0x23, 0x3d, 0x89, 0x3e, 0xc6, 0x51, 0xd1, 0xac, 0xf8,
  24238. 0x28, 0xae, 0x4b, 0x76, 0xc8, 0x10, 0x7e, 0xdd
  24239. },
  24240. { /* Early Exporter Master Secret */
  24241. 0xb8, 0xd3, 0x25, 0x7e, 0x2d, 0x41, 0x7b, 0xcb, 0x5e, 0x82, 0x49, 0xf5,
  24242. 0x51, 0x3d, 0xb7, 0x59, 0x32, 0xb3, 0xdf, 0x99, 0x4e, 0x04, 0x69, 0xc6,
  24243. 0x96, 0x8e, 0xe6, 0x3d, 0x91, 0xe4, 0x81, 0x11
  24244. },
  24245. { /* Client Handshake Traffic Secret */
  24246. 0xd9, 0x3b, 0x54, 0xe2, 0xb0, 0xd1, 0x85, 0xf0, 0xfd, 0xf3, 0x48, 0x4a,
  24247. 0xf8, 0x0b, 0xa5, 0xdc, 0x4c, 0x37, 0xcb, 0xd4, 0x20, 0xaf, 0x60, 0xc7,
  24248. 0xd5, 0x50, 0x5d, 0x0c, 0x77, 0x3b, 0x6f, 0xd2
  24249. },
  24250. { /* Server Handshake Traffic Secret */
  24251. 0x4d, 0x40, 0x2b, 0xd2, 0x8c, 0x33, 0x90, 0x39, 0x67, 0x67, 0x05, 0xf7,
  24252. 0x5d, 0x37, 0x1e, 0xdc, 0x4a, 0x70, 0x6b, 0x9e, 0xf8, 0x06, 0x61, 0x89,
  24253. 0x70, 0xe1, 0x3d, 0x36, 0xad, 0x88, 0x7e, 0x5b
  24254. },
  24255. { /* Client Application Traffic Secret */
  24256. 0x74, 0x6e, 0xa0, 0x13, 0x18, 0x34, 0x48, 0x4d, 0x23, 0x31, 0xf1, 0xf9,
  24257. 0xee, 0x44, 0x6d, 0xad, 0xc1, 0xad, 0x92, 0x73, 0xca, 0x27, 0x16, 0x91,
  24258. 0xa2, 0x50, 0x9a, 0xfc, 0xec, 0xf0, 0x6b, 0x24
  24259. },
  24260. { /* Server Application Traffic Secret */
  24261. 0x89, 0x18, 0x7e, 0x34, 0x8d, 0xfc, 0x14, 0xb1, 0x4f, 0x21, 0xd8, 0x29,
  24262. 0xdb, 0x9b, 0xfb, 0x55, 0xcf, 0xa1, 0x4f, 0x95, 0xf8, 0xe0, 0xb0, 0x83,
  24263. 0xd5, 0x34, 0x9e, 0x0b, 0x83, 0x37, 0x42, 0x93
  24264. },
  24265. { /* Exporter Master Secret */
  24266. 0x7d, 0xc8, 0x88, 0x46, 0xd5, 0x57, 0x15, 0xb6, 0x24, 0x25, 0x92, 0x61,
  24267. 0xb1, 0x18, 0x86, 0x2a, 0x6d, 0xa5, 0x84, 0xeb, 0x59, 0xdf, 0x13, 0xbd,
  24268. 0x73, 0xaa, 0x5d, 0x65, 0xab, 0xd9, 0xb4, 0x56
  24269. },
  24270. { /* Resumption Master Secret */
  24271. 0x20, 0xb7, 0xd0, 0xe3, 0x82, 0x01, 0xa1, 0x04, 0xb8, 0x13, 0x29, 0xed,
  24272. 0x35, 0xe4, 0x2f, 0xbf, 0x58, 0x23, 0x7f, 0x21, 0xdb, 0x9f, 0xf8, 0xe0,
  24273. 0xe8, 0xe4, 0xab, 0xc4, 0xa1, 0x61, 0xb9, 0xbb
  24274. }
  24275. },
  24276. { /* 6 */
  24277. WC_HASH_TYPE_SHA256, 0, 33,
  24278. { 0 }, /* PSK */
  24279. { /* DHE */
  24280. 0x7a, 0x46, 0x8c, 0x5a, 0xd1, 0x8e, 0x95, 0xba,
  24281. 0x61, 0xe6, 0x6f, 0xe6, 0x76, 0x0c, 0x20, 0x43,
  24282. 0x16, 0x82, 0x15, 0xfe, 0x54, 0xa3, 0xc7, 0xfd,
  24283. 0x3b, 0x2c, 0x88, 0xb4, 0xd3, 0x42, 0x70, 0x12,
  24284. 0x18
  24285. },
  24286. { /* Hello 1 */
  24287. 0x63, 0x83, 0x58, 0xab, 0x36, 0xcd, 0x0c, 0xf3,
  24288. 0x26, 0x07, 0xb5, 0x5f, 0x0b, 0x8b, 0x45, 0xd6,
  24289. 0x7d, 0x5b, 0x42, 0xdc, 0xa8, 0xaa, 0x06, 0xfb,
  24290. 0x20, 0xa5, 0xbb, 0x85, 0xdb, 0x54, 0xd8, 0x8b
  24291. },
  24292. { /* Hello 2 */
  24293. 0xea, 0xfe, 0x9e, 0x8e, 0xff, 0x1f, 0x6f, 0x43,
  24294. 0xf9, 0x5d, 0xfd, 0xbf, 0xe2, 0x5f, 0x02, 0x2f,
  24295. 0x6d, 0x47, 0x60, 0x9a, 0x48, 0x9a, 0x75, 0xfb,
  24296. 0xb5, 0x4a, 0xbf, 0x9c, 0x4e, 0xff, 0xbf, 0x0b
  24297. },
  24298. { /* Finished 1 */
  24299. 0xca, 0x25, 0xb3, 0x53, 0x8e, 0x6d, 0xc3, 0x36,
  24300. 0x17, 0x30, 0x07, 0xdf, 0x0d, 0xd7, 0x79, 0xb0,
  24301. 0x7f, 0xcb, 0xbe, 0x7a, 0xbc, 0x2d, 0x9f, 0x2d,
  24302. 0x94, 0x44, 0x94, 0xe6, 0xa4, 0xf3, 0xe8, 0x53
  24303. },
  24304. { /* Finished 2 */
  24305. 0x2e, 0xa6, 0x5a, 0xaf, 0xb5, 0xba, 0x9f, 0x2f,
  24306. 0x74, 0x83, 0x5d, 0xbf, 0x86, 0xa4, 0xa6, 0xf6,
  24307. 0xb9, 0x89, 0xdf, 0x17, 0xe1, 0xa8, 0x14, 0xc0,
  24308. 0xe1, 0x50, 0xfa, 0xec, 0xfa, 0xae, 0x8b, 0x7b
  24309. },
  24310. {
  24311. 0x20, 0x18, 0x72, 0x7c, 0xde, 0x3a, 0x85, 0x17, 0x72, 0xdc, 0xd7, 0x72,
  24312. 0xb0, 0xfc, 0x45, 0xd0, 0x62, 0xb9, 0xbb, 0x38, 0x69, 0x05, 0x7b, 0xb4,
  24313. 0x5e, 0x58, 0x5d, 0xed, 0xcd, 0x0b, 0x96, 0xd3
  24314. },
  24315. {
  24316. 0x68, 0x10, 0x20, 0xd1, 0x5e, 0xfc, 0x0c, 0x53, 0x85, 0xbb, 0xdb, 0x18,
  24317. 0xa8, 0x78, 0xf1, 0x2b, 0x13, 0xba, 0x64, 0x1d, 0xe7, 0x09, 0xbe, 0x13,
  24318. 0x49, 0x26, 0xf9, 0x98, 0x56, 0xf1, 0x43, 0xfb
  24319. },
  24320. {
  24321. 0x24, 0x35, 0x3e, 0x10, 0x6f, 0x39, 0x50, 0xd6, 0xa2, 0x12, 0x99, 0xf2,
  24322. 0xd5, 0xf5, 0x19, 0xf5, 0x84, 0xed, 0xee, 0x78, 0x2a, 0xa6, 0xfa, 0x3d,
  24323. 0x06, 0xa8, 0xa7, 0x5d, 0x97, 0x78, 0xd6, 0x58
  24324. },
  24325. {
  24326. 0xf4, 0x57, 0xac, 0x24, 0x7a, 0xfb, 0x7c, 0x3b, 0xb6, 0x39, 0x17, 0x14,
  24327. 0xd9, 0xd4, 0x58, 0x4d, 0x46, 0xd5, 0x1b, 0xde, 0xf7, 0x9d, 0x06, 0xee,
  24328. 0x8d, 0x1a, 0x2c, 0x25, 0x6d, 0x64, 0xde, 0x89
  24329. },
  24330. {
  24331. 0xb6, 0x00, 0xce, 0x63, 0xed, 0x65, 0x8b, 0x66, 0x66, 0x42, 0xc6, 0xbd,
  24332. 0x89, 0xc4, 0x71, 0x6f, 0xce, 0x28, 0xb2, 0xac, 0x97, 0x07, 0x5b, 0xea,
  24333. 0xb8, 0x1d, 0x4c, 0xeb, 0x9e, 0x71, 0x07, 0x8f
  24334. },
  24335. {
  24336. 0xf8, 0x92, 0xc8, 0xba, 0xe7, 0x83, 0xfe, 0x68, 0xe4, 0xd6, 0x5e, 0xcb,
  24337. 0xb3, 0xef, 0x49, 0xd0, 0xe7, 0xb1, 0xac, 0xcb, 0x39, 0x19, 0xfd, 0xa7,
  24338. 0xf7, 0xca, 0xab, 0x1e, 0x42, 0x14, 0xd8, 0xe7
  24339. },
  24340. {
  24341. 0x32, 0x4a, 0x1a, 0xad, 0xe2, 0xbb, 0x55, 0x8a, 0xdd, 0xe9, 0xa5, 0x2a,
  24342. 0x46, 0x5e, 0x6c, 0x83, 0x66, 0x27, 0x27, 0x94, 0xdd, 0x68, 0x59, 0xa0,
  24343. 0xbb, 0xe8, 0x31, 0x7c, 0x39, 0xd7, 0xfd, 0x6d
  24344. },
  24345. {
  24346. 0x58, 0xbc, 0x6c, 0x5b, 0x24, 0xad, 0x82, 0xb3, 0xcc, 0xc7, 0xd1, 0xa1,
  24347. 0xaa, 0x2b, 0x98, 0x9f, 0x2f, 0x7e, 0xa9, 0x63, 0xc2, 0x8e, 0xb6, 0x06,
  24348. 0xc2, 0x2b, 0x74, 0x4b, 0x79, 0x19, 0x7e, 0x2e
  24349. }
  24350. },
  24351. { /* 11 */
  24352. WC_HASH_TYPE_SHA256, 33, 0,
  24353. { /* PSK */
  24354. 0x3d, 0x39, 0x49, 0x36, 0x98, 0xc5, 0xfd, 0xcd,
  24355. 0xa0, 0x17, 0xbd, 0x65, 0x0a, 0xdb, 0xd4, 0x07,
  24356. 0x56, 0xa2, 0x7b, 0xb8, 0x2a, 0x7e, 0xfb, 0x26,
  24357. 0x74, 0xe1, 0xbc, 0x08, 0x4b, 0xf0, 0x30, 0x14,
  24358. 0x12
  24359. },
  24360. { 0 }, /* DHE */
  24361. { /* Hello 1 */
  24362. 0xb7, 0x44, 0x74, 0x6c, 0x57, 0x1f, 0xf3, 0x84,
  24363. 0x8f, 0x63, 0xfb, 0x8c, 0x94, 0x6c, 0x16, 0x68,
  24364. 0x4b, 0xe1, 0xb5, 0xb5, 0x2a, 0x4e, 0x5f, 0xdf,
  24365. 0x4b, 0x53, 0xb2, 0x35, 0xfc, 0x30, 0xf1, 0x36
  24366. },
  24367. { /* Hello 2 */
  24368. 0xe6, 0x4f, 0x3a, 0x4f, 0xd7, 0xe0, 0x64, 0xd4,
  24369. 0x69, 0x50, 0xe4, 0x8b, 0xba, 0xbc, 0x47, 0x74,
  24370. 0xa7, 0x9b, 0x40, 0x91, 0x8f, 0xa8, 0x72, 0x22,
  24371. 0x97, 0xad, 0x43, 0xa7, 0x11, 0x86, 0xb5, 0x72
  24372. },
  24373. { /* Finished 1 */
  24374. 0x5f, 0xa6, 0x10, 0xe2, 0xa3, 0x99, 0x0b, 0x5e,
  24375. 0x57, 0xee, 0xc3, 0x3a, 0x8e, 0x04, 0xf3, 0x0e,
  24376. 0x58, 0x02, 0x09, 0xb2, 0x7e, 0x2d, 0xc6, 0xd2,
  24377. 0x08, 0xae, 0x68, 0x0a, 0x55, 0xa5, 0xda, 0x51
  24378. },
  24379. { /* Finished 2 */
  24380. 0xfc, 0x5b, 0xc0, 0x7e, 0x1b, 0xaa, 0xc0, 0xb4,
  24381. 0x34, 0x85, 0x49, 0x8e, 0x16, 0x31, 0x98, 0xdf,
  24382. 0x10, 0x54, 0x22, 0xda, 0x1e, 0x6b, 0x51, 0xf6,
  24383. 0x97, 0x57, 0xa0, 0x7a, 0x92, 0xe7, 0x47, 0x52
  24384. },
  24385. {
  24386. 0x80, 0xfa, 0x36, 0x30, 0xb8, 0x65, 0xb3, 0x2a, 0x1d, 0x68, 0x91, 0x06,
  24387. 0x98, 0xa0, 0x17, 0x8f, 0xee, 0xb7, 0x9e, 0x3d, 0xd8, 0x84, 0x99, 0x30,
  24388. 0xb9, 0xd6, 0x09, 0x25, 0x5e, 0xfb, 0x8f, 0xd3 },
  24389. {
  24390. 0xa9, 0x89, 0x29, 0x70, 0xe4, 0x55, 0xec, 0x97, 0xfb, 0x24, 0x5b, 0xf9,
  24391. 0xf1, 0xa3, 0x19, 0x3d, 0xf1, 0x31, 0x14, 0xcd, 0x2a, 0xed, 0x21, 0xc8,
  24392. 0xb1, 0x53, 0xad, 0x11, 0x0b, 0x9e, 0x5a, 0xee },
  24393. {
  24394. 0x72, 0xad, 0x8d, 0x7f, 0xfc, 0xb7, 0x68, 0xda, 0x27, 0x60, 0x37, 0xa3,
  24395. 0x4a, 0x63, 0xe8, 0xa5, 0xc8, 0xcd, 0x36, 0x6a, 0x77, 0x99, 0x0d, 0xa9,
  24396. 0xb1, 0x5b, 0x2f, 0x47, 0x2e, 0x22, 0xa7, 0x5e },
  24397. {
  24398. 0x95, 0x6e, 0x85, 0x09, 0xe5, 0x04, 0x88, 0x14, 0x28, 0x8d, 0xdf, 0xe6,
  24399. 0x0d, 0x0f, 0x0d, 0x6b, 0x4e, 0x66, 0x1c, 0x03, 0xb9, 0xaa, 0x2d, 0x45,
  24400. 0x56, 0x67, 0x5c, 0x55, 0x29, 0xd6, 0x89, 0xd0 },
  24401. {
  24402. 0xe8, 0xf2, 0x14, 0xf9, 0x9b, 0x2b, 0x9f, 0x24, 0x2b, 0x37, 0xbe, 0x86,
  24403. 0xdb, 0x23, 0x4b, 0xbe, 0x39, 0x57, 0xe8, 0xa9, 0xa5, 0xee, 0x08, 0xf2,
  24404. 0x75, 0x58, 0xdb, 0xd9, 0x51, 0xc1, 0x46, 0x02 },
  24405. {
  24406. 0x3d, 0x19, 0xaf, 0xa3, 0x0b, 0x21, 0xf7, 0x3d, 0xe7, 0x37, 0x6e, 0x32,
  24407. 0x13, 0x48, 0x9d, 0xea, 0xe0, 0x90, 0xbf, 0x64, 0x48, 0xf7, 0x1e, 0xcc,
  24408. 0xf0, 0xbc, 0x92, 0xd7, 0x8a, 0x4a, 0xa8, 0xc1 },
  24409. {
  24410. 0x16, 0x35, 0xb1, 0x66, 0x28, 0xa3, 0x3e, 0x19, 0xf5, 0x2d, 0x92, 0x22,
  24411. 0x95, 0x48, 0xe8, 0x34, 0x7b, 0x30, 0x50, 0xa2, 0xa0, 0xd9, 0xc2, 0x59,
  24412. 0x39, 0xf9, 0x8c, 0x69, 0xf2, 0x2a, 0xb9, 0xff },
  24413. {
  24414. 0x32, 0x71, 0xa6, 0x87, 0x0c, 0x97, 0x42, 0x07, 0xdd, 0x5f, 0xc9, 0x44,
  24415. 0xa5, 0x7c, 0x50, 0x14, 0xfd, 0xe7, 0x5f, 0x8b, 0xd3, 0x2f, 0xdc, 0x9b,
  24416. 0xa9, 0x93, 0x22, 0x19, 0xe6, 0xf2, 0x0c, 0xd8 }
  24417. },
  24418. #ifdef WOLFSSL_SHA384
  24419. { /* 26 */
  24420. WC_HASH_TYPE_SHA384, 35, 35,
  24421. { /* PSK */
  24422. 0x62, 0x83, 0x25, 0xc7, 0xcc, 0x08, 0x5e, 0x63,
  24423. 0x64, 0x56, 0xf0, 0xc6, 0x88, 0x27, 0x5a, 0x5b,
  24424. 0x68, 0x59, 0x0b, 0x14, 0x55, 0x13, 0x2e, 0xfd,
  24425. 0x8f, 0x28, 0x5b, 0x3d, 0xe3, 0xad, 0x67, 0xe4,
  24426. 0x68, 0xba, 0xf9
  24427. },
  24428. { /* DHE */
  24429. 0xa8, 0xb1, 0xab, 0xd8, 0xc8, 0x5b, 0x52, 0xdf,
  24430. 0x7f, 0x49, 0x10, 0xf4, 0xa1, 0x31, 0xd1, 0x91,
  24431. 0x36, 0xc1, 0x87, 0x5d, 0x42, 0x2a, 0xe7, 0x1d,
  24432. 0x2c, 0x29, 0x3d, 0x40, 0x64, 0x61, 0x63, 0x76,
  24433. 0xd8, 0x66, 0xac
  24434. },
  24435. { /* Hello 1 */
  24436. 0x6f, 0xc6, 0x4c, 0xe1, 0xc6, 0x68, 0x34, 0x8c,
  24437. 0x0a, 0xe1, 0xf8, 0xb8, 0x3e, 0xd4, 0xf8, 0x0b,
  24438. 0x54, 0x50, 0xe4, 0xc5, 0x4a, 0x33, 0x7d, 0xbd,
  24439. 0x90, 0xd2, 0xa2, 0xb9, 0xb7, 0x92, 0xed, 0xab,
  24440. 0x14, 0xf1, 0xe4, 0x86, 0x22, 0x67, 0xd7, 0x44,
  24441. 0x03, 0x21, 0xdc, 0x51, 0x52, 0x7f, 0x35, 0x80
  24442. },
  24443. { /* Hello 2 */
  24444. 0x3e, 0xcf, 0x2f, 0xc3, 0x87, 0xba, 0xc5, 0xbd,
  24445. 0x7c, 0xe8, 0x35, 0x5b, 0x95, 0x51, 0x30, 0x3b,
  24446. 0x08, 0xcc, 0x2a, 0x7d, 0xb5, 0x74, 0x7c, 0x16,
  24447. 0xb3, 0x0b, 0xe7, 0x61, 0xa3, 0x7c, 0x6c, 0xbd,
  24448. 0x39, 0x74, 0xfd, 0x1e, 0x4c, 0xff, 0xc8, 0xcc,
  24449. 0xa0, 0xef, 0x29, 0x4d, 0x94, 0xaa, 0x55, 0x6f,
  24450. },
  24451. { /* Finished 1 */
  24452. 0x06, 0xc1, 0x47, 0x78, 0x66, 0x53, 0x6f, 0x24,
  24453. 0x94, 0x61, 0x69, 0xec, 0xd8, 0x60, 0x31, 0x2f,
  24454. 0xbf, 0xd6, 0x8a, 0x29, 0x17, 0xff, 0xa3, 0x88,
  24455. 0x13, 0x09, 0x8c, 0x9d, 0x6c, 0x64, 0x84, 0x48,
  24456. 0x44, 0xdd, 0x2d, 0x29, 0x4d, 0xe6, 0x98, 0x2b,
  24457. 0x45, 0x3b, 0x84, 0x33, 0x79, 0xb2, 0x75, 0x68
  24458. },
  24459. { /* Finished 2 */
  24460. 0x28, 0x1e, 0x18, 0xf7, 0x9c, 0x32, 0xa9, 0xbf,
  24461. 0x0c, 0x24, 0x58, 0x21, 0xce, 0xbc, 0xf2, 0x44,
  24462. 0xb1, 0x18, 0xaf, 0x9d, 0xd9, 0x20, 0xf9, 0xf4,
  24463. 0xed, 0xcc, 0x53, 0x82, 0x66, 0x5c, 0x46, 0x94,
  24464. 0x8c, 0x36, 0x5e, 0xca, 0x9f, 0xd8, 0x9a, 0xd3,
  24465. 0xf0, 0xe1, 0x53, 0x71, 0xdd, 0x19, 0x1e, 0x59
  24466. },
  24467. {
  24468. 0xd0, 0xef, 0xa8, 0xcb, 0x5b, 0x14, 0x0f, 0x0a, 0x62, 0xba, 0x5a, 0xb1,
  24469. 0xc5, 0xb5, 0x3f, 0x11, 0xda, 0xa1, 0x0c, 0x9c, 0xb4, 0x32, 0x48, 0x4e,
  24470. 0xfa, 0x84, 0x4f, 0xe4, 0xe7, 0x91, 0x8f, 0x42, 0x3f, 0xc7, 0x4e, 0xd3,
  24471. 0x83, 0x3d, 0x7f, 0x70, 0x12, 0xee, 0x9a, 0x37, 0x01, 0xbb, 0x14, 0xd3
  24472. },
  24473. {
  24474. 0x48, 0x6f, 0x77, 0x1d, 0x39, 0x1b, 0xa5, 0x9a, 0x76, 0xd9, 0x1d, 0x7d,
  24475. 0xb3, 0xd9, 0xb9, 0x78, 0x35, 0x0f, 0xd0, 0xe1, 0x07, 0x1f, 0x8d, 0xe5,
  24476. 0x75, 0x00, 0xda, 0xc0, 0x19, 0x01, 0xfb, 0x08, 0x35, 0xe7, 0x18, 0x8f,
  24477. 0xf0, 0x19, 0xfb, 0x46, 0xf6, 0xa5, 0x77, 0x0e, 0x90, 0x38, 0x8b, 0x15
  24478. },
  24479. {
  24480. 0x80, 0x8c, 0xa7, 0x24, 0x97, 0xf9, 0xd3, 0x52, 0xb0, 0x69, 0x9d, 0x4b,
  24481. 0xa4, 0x19, 0x4a, 0xb1, 0x46, 0x53, 0x3a, 0xc8, 0xe4, 0x02, 0x69, 0xf2,
  24482. 0xe7, 0xb6, 0x1d, 0x33, 0x51, 0xcc, 0x14, 0x40, 0x4a, 0xb0, 0xe7, 0x58,
  24483. 0x84, 0xba, 0xc2, 0x14, 0x58, 0x6b, 0xb9, 0xdc, 0x50, 0x98, 0x67, 0x01
  24484. },
  24485. {
  24486. 0xb1, 0xa8, 0xc0, 0x06, 0xb3, 0x2e, 0xa7, 0x8a, 0x6a, 0x12, 0x88, 0x00,
  24487. 0x65, 0x88, 0x9c, 0x5d, 0x35, 0xee, 0xe5, 0x51, 0x0b, 0x62, 0xf8, 0x67,
  24488. 0xe5, 0xef, 0x15, 0x1f, 0x23, 0x02, 0x74, 0x08, 0x9c, 0xc8, 0xba, 0x27,
  24489. 0x5d, 0x32, 0x19, 0x6f, 0x6d, 0x5d, 0x72, 0x5e, 0x15, 0xde, 0x30, 0xc3
  24490. },
  24491. {
  24492. 0xfd, 0xce, 0xf5, 0x65, 0x45, 0x84, 0xfb, 0x8c, 0x79, 0xa4, 0x6c, 0x1b,
  24493. 0x0e, 0x1b, 0xfd, 0x26, 0xa2, 0x53, 0xf4, 0x4e, 0x00, 0x4d, 0x4b, 0x0b,
  24494. 0x24, 0x6d, 0x35, 0x35, 0xd9, 0x97, 0x70, 0xc5, 0xf4, 0xee, 0xe3, 0xba,
  24495. 0x31, 0x1e, 0x2a, 0x42, 0xcb, 0xdf, 0x40, 0xb1, 0x14, 0xb8, 0x53, 0xce
  24496. },
  24497. {
  24498. 0xbb, 0xb3, 0x26, 0x7c, 0x22, 0x21, 0x9b, 0x72, 0x32, 0xa1, 0x97, 0xfb,
  24499. 0x78, 0x8c, 0xbe, 0x3d, 0x71, 0x45, 0xb8, 0xf5, 0x24, 0x8f, 0x0f, 0xac,
  24500. 0x42, 0x5b, 0x81, 0xe8, 0xd0, 0x71, 0x4a, 0xcb, 0x32, 0x3f, 0x03, 0xfb,
  24501. 0xec, 0x6a, 0x1f, 0x76, 0x80, 0x65, 0x01, 0x7a, 0x3d, 0xce, 0xc4, 0xdf
  24502. },
  24503. {
  24504. 0x3f, 0xcf, 0x2f, 0x63, 0x94, 0x94, 0x99, 0xfd, 0x04, 0x3a, 0x89, 0x83,
  24505. 0xcf, 0x06, 0x05, 0xec, 0x20, 0x3e, 0x5f, 0x51, 0x9d, 0x6e, 0x4a, 0xc6,
  24506. 0xf1, 0x2b, 0x37, 0x17, 0x34, 0x72, 0x6e, 0x1d, 0x2a, 0xfd, 0xc7, 0x73,
  24507. 0xb5, 0x07, 0x22, 0x81, 0x32, 0x2e, 0x21, 0x85, 0xaf, 0x10, 0xb2, 0x73
  24508. },
  24509. {
  24510. 0x52, 0x0c, 0x3d, 0x2e, 0x2d, 0x4a, 0x11, 0xae, 0x96, 0x78, 0xe9, 0x5b,
  24511. 0xd8, 0x0f, 0x6c, 0xf4, 0xbd, 0x96, 0x13, 0x55, 0x88, 0xdd, 0xa3, 0x67,
  24512. 0x36, 0x86, 0x1e, 0x0b, 0x36, 0x41, 0xec, 0xf6, 0x04, 0xb2, 0xc4, 0x16,
  24513. 0xbc, 0x2c, 0xdb, 0x30, 0x02, 0x94, 0xd4, 0x42, 0xbf, 0x38, 0xee, 0x9d
  24514. }
  24515. },
  24516. { /* 36 */
  24517. WC_HASH_TYPE_SHA384, 0, 33,
  24518. { 0 }, /* PSK */
  24519. { /* DHE */
  24520. 0xd3, 0x00, 0x72, 0x9a, 0xa8, 0xc5, 0xf3, 0xc4,
  24521. 0xf1, 0xa0, 0x26, 0x89, 0x65, 0x70, 0xc7, 0x0b,
  24522. 0x77, 0xbb, 0xe1, 0x4b, 0x2b, 0xa8, 0x4f, 0xa6,
  24523. 0x09, 0x4b, 0xba, 0x45, 0x36, 0x15, 0xee, 0x68,
  24524. 0xfd
  24525. },
  24526. { /* Hello 1 */
  24527. 0x10, 0x9d, 0x8b, 0xa2, 0x93, 0xe7, 0xd3, 0xb9,
  24528. 0xb4, 0x0f, 0xeb, 0x6a, 0xb9, 0x69, 0xcb, 0x39,
  24529. 0x16, 0x29, 0xcc, 0xd3, 0xcc, 0x1a, 0x4c, 0x1b,
  24530. 0x53, 0x7c, 0x33, 0x88, 0x06, 0xbc, 0x0a, 0x02,
  24531. 0xa0, 0xbe, 0x62, 0xc0, 0xe6, 0x5e, 0x97, 0x5b,
  24532. 0x6a, 0xa1, 0x98, 0xf3, 0xd2, 0x1e, 0xcd, 0xc5
  24533. },
  24534. { /* Hello 2 */
  24535. 0x74, 0xc0, 0x07, 0x2c, 0xc1, 0x63, 0xcc, 0x11,
  24536. 0xad, 0x1a, 0x55, 0x63, 0xbc, 0x20, 0x77, 0x96,
  24537. 0x30, 0x1c, 0x68, 0x45, 0x1e, 0x9b, 0xa7, 0xb4,
  24538. 0xf3, 0x04, 0x45, 0x16, 0x76, 0x55, 0xf9, 0xdf,
  24539. 0x4b, 0x2f, 0x1a, 0xdf, 0x5a, 0xb0, 0x93, 0xc9,
  24540. 0xab, 0xf5, 0x32, 0x47, 0x79, 0x9c, 0x01, 0xeb
  24541. },
  24542. { /* Finished 1 */
  24543. 0x27, 0x08, 0x8e, 0xa5, 0xf1, 0x30, 0xe1, 0xd6,
  24544. 0x4f, 0xa2, 0x9e, 0x3b, 0x03, 0x2d, 0x2e, 0xa3,
  24545. 0x84, 0x75, 0x51, 0x3a, 0xc3, 0xf6, 0xee, 0x2e,
  24546. 0x37, 0x0c, 0xe3, 0x28, 0x46, 0xa5, 0x2d, 0xc7,
  24547. 0xf0, 0x64, 0x78, 0x53, 0x66, 0x43, 0x02, 0xa4,
  24548. 0x7a, 0x43, 0x66, 0x4b, 0xa7, 0xcb, 0x97, 0x16
  24549. },
  24550. { /* Finished 2 */
  24551. 0x1d, 0x0d, 0xf8, 0xe1, 0x81, 0xa5, 0xbd, 0xa8,
  24552. 0x6f, 0x9d, 0x01, 0xa4, 0x9a, 0x92, 0xe2, 0xef,
  24553. 0x08, 0xab, 0xef, 0x3e, 0x2d, 0xd4, 0x82, 0xac,
  24554. 0x68, 0x9d, 0xe0, 0x54, 0x17, 0xde, 0x1a, 0xed,
  24555. 0x57, 0xcb, 0xd9, 0x2d, 0xc8, 0xbc, 0x93, 0xe6,
  24556. 0xa3, 0xec, 0xde, 0xee, 0xa1, 0x1c, 0x41, 0x85
  24557. },
  24558. {
  24559. 0x7f, 0x1f, 0xe6, 0x7b, 0xd8, 0xf5, 0x2b, 0x37, 0xbe, 0xb7, 0xd0, 0x37,
  24560. 0xce, 0x46, 0xad, 0x04, 0x2f, 0xc7, 0xdb, 0xc9, 0x9a, 0xb6, 0x00, 0x3f,
  24561. 0xc1, 0x97, 0xe9, 0x5c, 0x5e, 0x14, 0xd1, 0x38, 0x4d, 0x55, 0xe1, 0x07,
  24562. 0xb5, 0x85, 0x6d, 0xfa, 0xa7, 0x66, 0xad, 0xfa, 0xb6, 0xad, 0x29, 0x44
  24563. },
  24564. {
  24565. 0x4e, 0x6b, 0x20, 0x99, 0x55, 0x1b, 0x21, 0x89, 0xb6, 0x70, 0xdb, 0xe8,
  24566. 0xa7, 0x16, 0x55, 0xf2, 0x93, 0x13, 0x90, 0x7d, 0xfa, 0x62, 0x65, 0x53,
  24567. 0xa0, 0x97, 0xe9, 0xb4, 0xc0, 0xf1, 0xc9, 0x1a, 0x67, 0xdd, 0xca, 0x57,
  24568. 0xbc, 0xca, 0x39, 0xe6, 0x39, 0x6b, 0x63, 0x47, 0x25, 0x08, 0x3a, 0xd7
  24569. },
  24570. {
  24571. 0x35, 0x0d, 0xac, 0xd8, 0x10, 0x6a, 0x46, 0x50, 0x66, 0xae, 0x02, 0xc9,
  24572. 0xde, 0x13, 0x48, 0xce, 0x53, 0xd4, 0x92, 0x62, 0xc5, 0x65, 0x10, 0x08,
  24573. 0xc2, 0xc2, 0x82, 0xed, 0x9d, 0xc9, 0x6f, 0xa8, 0xc3, 0xc1, 0x0b, 0x7c,
  24574. 0xe1, 0x97, 0x85, 0xd6, 0x46, 0x29, 0x0e, 0x42, 0x51, 0xc1, 0x35, 0xcf
  24575. },
  24576. {
  24577. 0x3d, 0x5d, 0x84, 0xbd, 0x16, 0x46, 0x34, 0xb3, 0xf6, 0x31, 0x49, 0x3e,
  24578. 0x8d, 0xdc, 0xcb, 0x8c, 0x6a, 0x42, 0xf4, 0x88, 0xfc, 0x19, 0xfa, 0xa2,
  24579. 0x25, 0xc7, 0xa0, 0xa4, 0xca, 0xf0, 0xea, 0x2d, 0xe8, 0xc4, 0x02, 0x14,
  24580. 0x63, 0xfb, 0xd3, 0x7b, 0x51, 0x1c, 0xce, 0xca, 0xa3, 0xc3, 0xe4, 0xa5
  24581. },
  24582. {
  24583. 0x7c, 0x3a, 0x55, 0x92, 0x2e, 0xdd, 0x75, 0xdd, 0x76, 0x54, 0x4a, 0x9f,
  24584. 0xd0, 0xa2, 0x88, 0x83, 0xe9, 0x27, 0xda, 0x30, 0xe9, 0x96, 0x58, 0xc5,
  24585. 0xb7, 0x56, 0xfc, 0x4b, 0xb8, 0x5d, 0xee, 0x46, 0x70, 0x4e, 0x1b, 0x06,
  24586. 0x86, 0xaf, 0x48, 0x5c, 0x17, 0x35, 0xfa, 0x69, 0xc2, 0x4d, 0xfb, 0x09
  24587. },
  24588. {
  24589. 0x00, 0x0e, 0x28, 0x51, 0xc1, 0x7f, 0x41, 0x89, 0x6f, 0x9a, 0xca, 0x15,
  24590. 0xee, 0xed, 0x43, 0xca, 0x6d, 0x65, 0x6f, 0x51, 0x18, 0x6c, 0x08, 0x4b,
  24591. 0x77, 0xca, 0x75, 0xc4, 0xc3, 0xde, 0x29, 0x41, 0x8b, 0xaf, 0xa7, 0x1c,
  24592. 0x28, 0x37, 0xa0, 0xa0, 0x74, 0x8e, 0x09, 0x42, 0x7a, 0x1b, 0x68, 0xdb
  24593. },
  24594. {
  24595. 0x14, 0x8f, 0xab, 0x28, 0x64, 0xea, 0x45, 0x88, 0xdb, 0xc1, 0xc6, 0xa0,
  24596. 0x48, 0xdf, 0x15, 0xd0, 0x28, 0x07, 0x2d, 0x6c, 0xb8, 0x42, 0xbb, 0x60,
  24597. 0x02, 0x08, 0x9e, 0x29, 0x9b, 0x8d, 0xd6, 0x1c, 0xaf, 0xf2, 0x1a, 0xdc,
  24598. 0xf0, 0x78, 0x0b, 0x4d, 0x90, 0xa1, 0x0c, 0xb3, 0x13, 0xde, 0xca, 0x5a
  24599. },
  24600. {
  24601. 0x4d, 0x80, 0x7d, 0x0b, 0xb9, 0x00, 0x6f, 0x65, 0x51, 0x65, 0x23, 0xde,
  24602. 0x72, 0xdc, 0x4f, 0x04, 0xa5, 0xa2, 0x90, 0x45, 0x51, 0x9e, 0xd0, 0x3a,
  24603. 0xe4, 0xd7, 0x78, 0xa3, 0x0f, 0x2d, 0x65, 0x12, 0xad, 0xc8, 0x92, 0x30,
  24604. 0x79, 0x9d, 0x9d, 0x08, 0x7a, 0x9c, 0x9f, 0x83, 0xb1, 0xca, 0x59, 0x56
  24605. }
  24606. },
  24607. { /* 41 */
  24608. WC_HASH_TYPE_SHA384, 33, 0,
  24609. { /* PSK */
  24610. 0xa4, 0x8b, 0x1b, 0x5f, 0xd0, 0xea, 0x75, 0x62,
  24611. 0x06, 0x4d, 0x68, 0x40, 0x85, 0x20, 0x45, 0x95,
  24612. 0x4a, 0x00, 0xca, 0x05, 0xeb, 0xd4, 0x1d, 0x48,
  24613. 0x81, 0x89, 0xe8, 0x86, 0x43, 0xfa, 0x28, 0x17,
  24614. 0x12
  24615. },
  24616. { 0 }, /* DHE */
  24617. { /* Hello 1 */
  24618. 0x03, 0x7c, 0x33, 0x75, 0xdc, 0xc5, 0x46, 0x3a,
  24619. 0x0d, 0x56, 0xc6, 0xfb, 0xab, 0x1e, 0x1d, 0xda,
  24620. 0x59, 0xc2, 0xb2, 0xb1, 0x7c, 0x48, 0x9b, 0x06,
  24621. 0x0a, 0x5a, 0xbb, 0xf8, 0x98, 0x53, 0x78, 0x2d,
  24622. 0xd2, 0xcc, 0x87, 0x68, 0x25, 0xdd, 0x88, 0x22,
  24623. 0xcd, 0xb7, 0x74, 0x55, 0x21, 0xf9, 0x34, 0x98
  24624. },
  24625. { /* Hello 2 */
  24626. 0x03, 0xb4, 0xfb, 0xcc, 0x28, 0x2c, 0xc1, 0x70,
  24627. 0x42, 0x73, 0x57, 0xac, 0xdb, 0x47, 0x71, 0xf6,
  24628. 0x2e, 0x11, 0x8a, 0x5b, 0x47, 0x2f, 0x02, 0x54,
  24629. 0x95, 0x34, 0xed, 0x5f, 0x19, 0xc1, 0x75, 0xe0,
  24630. 0x76, 0xad, 0xb0, 0x90, 0x57, 0xcd, 0xfd, 0xd7,
  24631. 0x58, 0x1f, 0x0d, 0x6b, 0x9e, 0x51, 0x3c, 0x08
  24632. },
  24633. { /* Finished 1 */
  24634. 0x2b, 0x50, 0xd9, 0xa7, 0x43, 0x24, 0xda, 0x2c,
  24635. 0x7a, 0xaa, 0x0e, 0x37, 0xd7, 0x6b, 0x2c, 0xab,
  24636. 0x8e, 0xb2, 0xfe, 0x31, 0x1b, 0xa8, 0x12, 0x59,
  24637. 0x5b, 0x7b, 0xdc, 0x3e, 0xa7, 0x86, 0xa5, 0x48,
  24638. 0xe4, 0x46, 0x2b, 0x4c, 0xc1, 0x66, 0x4b, 0xf3,
  24639. 0x2a, 0x99, 0x93, 0x08, 0xbc, 0x3d, 0x08, 0x76
  24640. },
  24641. { /* Finished 2 */
  24642. 0x7c, 0x34, 0xc8, 0x56, 0x17, 0xf1, 0x62, 0x1c,
  24643. 0x9f, 0x0b, 0xeb, 0xfd, 0x69, 0x72, 0x51, 0xc5,
  24644. 0xfa, 0x74, 0x87, 0xc9, 0xbd, 0x50, 0xe9, 0x48,
  24645. 0xa7, 0x3c, 0x94, 0x3e, 0x06, 0x7d, 0xe8, 0x8e,
  24646. 0xc1, 0xd1, 0x08, 0x1f, 0x5d, 0x48, 0x8a, 0x25,
  24647. 0xfc, 0xea, 0xe7, 0xd9, 0xd4, 0xd0, 0xf9, 0xad
  24648. },
  24649. {
  24650. 0x4b, 0x0b, 0xed, 0xb9, 0xc8, 0xb8, 0xa8, 0x1e, 0xb0, 0x81, 0x76, 0xd5,
  24651. 0x33, 0x22, 0x71, 0x33, 0x3a, 0x85, 0x19, 0x67, 0x7e, 0x91, 0x37, 0xf2,
  24652. 0xa6, 0x11, 0x22, 0xdf, 0x41, 0x04, 0x3d, 0xa9, 0x13, 0xb9, 0xb2, 0xb1,
  24653. 0xbb, 0xd8, 0xef, 0x23, 0x7c, 0xc2, 0xab, 0x70, 0x1b, 0x51, 0x9f, 0xc9
  24654. },
  24655. {
  24656. 0xeb, 0x96, 0x10, 0x8c, 0x7d, 0x92, 0xea, 0x80, 0x86, 0xb2, 0xf8, 0x27,
  24657. 0xf2, 0x9a, 0x09, 0xc1, 0x7c, 0x09, 0x43, 0xbc, 0xfe, 0xc8, 0x75, 0xe0,
  24658. 0x97, 0xe7, 0x6d, 0xd5, 0xb2, 0x3c, 0xed, 0x12, 0xb7, 0x74, 0x0e, 0xe3,
  24659. 0xb6, 0xe0, 0xba, 0xe1, 0x8d, 0x89, 0xcf, 0x4f, 0x57, 0xf6, 0x6d, 0x90
  24660. },
  24661. {
  24662. 0x22, 0xb0, 0x39, 0x34, 0xb6, 0x6c, 0x2d, 0x7a, 0x97, 0x1c, 0x5d, 0xcc,
  24663. 0x78, 0x84, 0x71, 0xbb, 0xc6, 0x7b, 0xb6, 0xbc, 0xcc, 0x0b, 0xf8, 0xac,
  24664. 0x8e, 0xd7, 0x20, 0xbd, 0xbe, 0x32, 0xf0, 0xd6, 0xe9, 0x69, 0x13, 0xf2,
  24665. 0x9a, 0xce, 0xfe, 0x86, 0xd3, 0xee, 0xba, 0x69, 0x51, 0xb6, 0x77, 0x56
  24666. },
  24667. {
  24668. 0x16, 0xfd, 0xda, 0xf3, 0x5e, 0xb9, 0xa6, 0x17, 0x24, 0xb2, 0x16, 0x9f,
  24669. 0xb6, 0x59, 0x13, 0x0f, 0x25, 0x5a, 0xf1, 0x5b, 0x5f, 0xe4, 0x54, 0x2a,
  24670. 0xa7, 0xbf, 0x29, 0xaf, 0x5a, 0x77, 0xf4, 0x4f, 0x25, 0xba, 0x94, 0xad,
  24671. 0x6b, 0x91, 0x3b, 0xe7, 0xd5, 0x73, 0x0d, 0xff, 0xaa, 0xe3, 0x72, 0x2c
  24672. },
  24673. {
  24674. 0x22, 0xb4, 0x94, 0xc0, 0x53, 0xd7, 0x82, 0x06, 0x38, 0x9d, 0x4a, 0xa0,
  24675. 0x3f, 0xf1, 0x5f, 0x6e, 0x23, 0x8d, 0x09, 0x62, 0xbf, 0x6f, 0x7c, 0x84,
  24676. 0xc6, 0x3e, 0x15, 0xad, 0x18, 0x37, 0x76, 0x29, 0xc7, 0xd6, 0x68, 0x0c,
  24677. 0x1e, 0xc6, 0x93, 0x31, 0xef, 0x85, 0x69, 0x30, 0x68, 0xf0, 0x1e, 0x37
  24678. },
  24679. {
  24680. 0x6d, 0x4d, 0x20, 0xaf, 0x47, 0xe8, 0x1b, 0xfa, 0xd0, 0xb6, 0xc8, 0x97,
  24681. 0xd1, 0x03, 0xfc, 0x9d, 0x59, 0xa0, 0x68, 0x9d, 0xe9, 0x17, 0x8b, 0xce,
  24682. 0x48, 0x2c, 0x77, 0x8a, 0x22, 0x4b, 0x5c, 0x54, 0x22, 0xa1, 0x15, 0x12,
  24683. 0xe1, 0x07, 0x8e, 0x15, 0xd8, 0x7b, 0x16, 0x65, 0x99, 0x6b, 0xcb, 0x71
  24684. },
  24685. {
  24686. 0x79, 0x64, 0x79, 0xdd, 0x75, 0x5c, 0x6f, 0x98, 0xac, 0x03, 0xe0, 0xcd,
  24687. 0x92, 0xba, 0x0e, 0x2d, 0xb4, 0xd1, 0x8b, 0x97, 0xd0, 0x85, 0xbb, 0x2e,
  24688. 0x4f, 0x26, 0x93, 0xf5, 0x1d, 0xf3, 0xd2, 0x43, 0x4f, 0xd2, 0x47, 0xaa,
  24689. 0x91, 0x1e, 0xf3, 0x67, 0x10, 0x18, 0x2c, 0xb9, 0x01, 0xba, 0x10, 0x9f
  24690. },
  24691. {
  24692. 0x79, 0xb6, 0x9c, 0xbe, 0xf1, 0x6a, 0xb0, 0x92, 0xa0, 0x29, 0x52, 0x61,
  24693. 0xf1, 0xcd, 0x3a, 0x67, 0xe1, 0x6b, 0xb8, 0x9d, 0x0d, 0x95, 0xb6, 0x03,
  24694. 0x80, 0x1f, 0xd5, 0x75, 0xb6, 0x1d, 0x79, 0x02, 0x93, 0x43, 0x77, 0xa7,
  24695. 0x9d, 0x2f, 0xc3, 0x84, 0xc6, 0x83, 0x76, 0x16, 0x06, 0x98, 0x7b, 0x79
  24696. }
  24697. },
  24698. #endif /* WOLFSSL_SHA384 */
  24699. };
  24700. static const char protocolLabel[] = "tls13 ";
  24701. static const char ceTrafficLabel[] = "c e traffic";
  24702. static const char eExpMasterLabel[] = "e exp master";
  24703. static const char cHsTrafficLabel[] = "c hs traffic";
  24704. static const char sHsTrafficLabel[] = "s hs traffic";
  24705. static const char cAppTrafficLabel[] = "c ap traffic";
  24706. static const char sAppTrafficLabel[] = "s ap traffic";
  24707. static const char expMasterLabel[] = "exp master";
  24708. static const char resMasterLabel[] = "res master";
  24709. static const char derivedLabel[] = "derived";
  24710. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t tls13_kdf_test(void)
  24711. {
  24712. wc_test_ret_t ret = 0;
  24713. word32 i;
  24714. word32 tc = sizeof(tls13KdfTestVectors)/sizeof(Tls13KdfTestVector);
  24715. const Tls13KdfTestVector* tv = NULL;
  24716. WOLFSSL_ENTER("tls13_kdf_test");
  24717. for (i = 0, tv = tls13KdfTestVectors; i < tc; i++, tv++) {
  24718. byte output[WC_MAX_DIGEST_SIZE];
  24719. byte secret[WC_MAX_DIGEST_SIZE];
  24720. byte salt[WC_MAX_DIGEST_SIZE];
  24721. byte zeroes[WC_MAX_DIGEST_SIZE];
  24722. byte hashZero[WC_MAX_DIGEST_SIZE];
  24723. int hashAlgSz;
  24724. XMEMSET(zeroes, 0, sizeof zeroes);
  24725. hashAlgSz = wc_HashGetDigestSize(tv->hashAlg);
  24726. if (hashAlgSz == WC_NO_ERR_TRACE(BAD_FUNC_ARG)) break;
  24727. ret = wc_Hash(tv->hashAlg, NULL, 0, hashZero, (word32)hashAlgSz);
  24728. if (ret != 0) break;
  24729. ret = wc_Tls13_HKDF_Extract(secret, NULL, 0,
  24730. (tv->pskSz == 0) ? zeroes : (byte*)tv->psk,
  24731. tv->pskSz, (int)tv->hashAlg);
  24732. if (ret != 0) break;
  24733. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24734. secret, (word32)hashAlgSz,
  24735. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24736. (byte*)ceTrafficLabel, (word32)XSTRLEN(ceTrafficLabel),
  24737. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24738. if (ret != 0) break;
  24739. ret = XMEMCMP(tv->clientEarlyTrafficSecret, output,
  24740. (unsigned long)hashAlgSz);
  24741. if (ret != 0) break;
  24742. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24743. secret, (word32)hashAlgSz,
  24744. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24745. (byte*)eExpMasterLabel, (word32)XSTRLEN(eExpMasterLabel),
  24746. tv->hashHello1, (word32)hashAlgSz, (int)tv->hashAlg);
  24747. if (ret != 0) break;
  24748. ret = XMEMCMP(tv->earlyExporterMasterSecret, output,
  24749. (unsigned long)hashAlgSz);
  24750. if (ret != 0) break;
  24751. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24752. secret, (word32)hashAlgSz,
  24753. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24754. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24755. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24756. if (ret != 0) break;
  24757. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24758. (tv->dheSz == 0) ? zeroes : (byte*)tv->dhe,
  24759. tv->dheSz, (int)tv->hashAlg);
  24760. if (ret != 0) break;
  24761. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24762. secret, (word32)hashAlgSz,
  24763. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24764. (byte*)cHsTrafficLabel, (word32)XSTRLEN(cHsTrafficLabel),
  24765. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24766. if (ret != 0) break;
  24767. ret = XMEMCMP(tv->clientHandshakeTrafficSecret,
  24768. output, (unsigned long)hashAlgSz);
  24769. if (ret != 0) break;
  24770. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24771. secret, (word32)hashAlgSz,
  24772. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24773. (byte*)sHsTrafficLabel, (word32)XSTRLEN(sHsTrafficLabel),
  24774. tv->hashHello2, (word32)hashAlgSz, (int)tv->hashAlg);
  24775. if (ret != 0) break;
  24776. ret = XMEMCMP(tv->serverHandshakeTrafficSecret, output,
  24777. (unsigned long)hashAlgSz);
  24778. if (ret != 0) break;
  24779. ret = wc_Tls13_HKDF_Expand_Label(salt, (word32)hashAlgSz,
  24780. secret, (word32)hashAlgSz,
  24781. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24782. (byte*)derivedLabel, (word32)XSTRLEN(derivedLabel),
  24783. hashZero, (word32)hashAlgSz, (int)tv->hashAlg);
  24784. if (ret != 0) break;
  24785. ret = wc_Tls13_HKDF_Extract(secret, salt, (word32)(word32)hashAlgSz,
  24786. zeroes, (word32)(word32)hashAlgSz, (int)tv->hashAlg);
  24787. if (ret != 0) break;
  24788. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24789. secret, (word32)hashAlgSz,
  24790. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24791. (byte*)cAppTrafficLabel, (word32)XSTRLEN(cAppTrafficLabel),
  24792. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24793. if (ret != 0) break;
  24794. ret = XMEMCMP(tv->clientApplicationTrafficSecret, output,
  24795. (unsigned long)hashAlgSz);
  24796. if (ret != 0) break;
  24797. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24798. secret, (word32)hashAlgSz,
  24799. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24800. (byte*)sAppTrafficLabel, (word32)XSTRLEN(sAppTrafficLabel),
  24801. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24802. if (ret != 0) break;
  24803. ret = XMEMCMP(tv->serverApplicationTrafficSecret, output,
  24804. (unsigned long)hashAlgSz);
  24805. if (ret != 0) break;
  24806. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24807. secret, (word32)hashAlgSz,
  24808. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24809. (byte*)expMasterLabel, (word32)XSTRLEN(expMasterLabel),
  24810. tv->hashFinished1, (word32)hashAlgSz, (int)tv->hashAlg);
  24811. if (ret != 0) break;
  24812. ret = XMEMCMP(tv->exporterMasterSecret, output, (unsigned long)hashAlgSz);
  24813. if (ret != 0) break;
  24814. ret = wc_Tls13_HKDF_Expand_Label(output, (word32)hashAlgSz,
  24815. secret, (word32)hashAlgSz,
  24816. (byte*)protocolLabel, (word32)XSTRLEN(protocolLabel),
  24817. (byte*)resMasterLabel, (word32)XSTRLEN(resMasterLabel),
  24818. tv->hashFinished2, (word32)hashAlgSz, (int)tv->hashAlg);
  24819. if (ret != 0) break;
  24820. ret = XMEMCMP(tv->resumptionMasterSecret, output,
  24821. (unsigned long)hashAlgSz);
  24822. if (ret != 0) break;
  24823. }
  24824. return ret;
  24825. }
  24826. #endif /* WOLFSSL_TLS13 */
  24827. static const int fiducial2 = WC_TEST_RET_LN; /* source code reference point --
  24828. * see print_fiducials() below.
  24829. */
  24830. #if defined(HAVE_ECC) && defined(HAVE_X963_KDF)
  24831. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t x963kdf_test(void)
  24832. {
  24833. wc_test_ret_t ret;
  24834. byte kek[128];
  24835. #ifndef NO_SHA
  24836. /* SHA-1, COUNT = 0
  24837. * shared secret length: 192
  24838. * SharedInfo length: 0
  24839. * key data length: 128
  24840. */
  24841. WOLFSSL_SMALL_STACK_STATIC const byte Z[] = {
  24842. 0x1c, 0x7d, 0x7b, 0x5f, 0x05, 0x97, 0xb0, 0x3d,
  24843. 0x06, 0xa0, 0x18, 0x46, 0x6e, 0xd1, 0xa9, 0x3e,
  24844. 0x30, 0xed, 0x4b, 0x04, 0xdc, 0x64, 0xcc, 0xdd
  24845. };
  24846. WOLFSSL_SMALL_STACK_STATIC const byte verify[] = {
  24847. 0xbf, 0x71, 0xdf, 0xfd, 0x8f, 0x4d, 0x99, 0x22,
  24848. 0x39, 0x36, 0xbe, 0xb4, 0x6f, 0xee, 0x8c, 0xcc
  24849. };
  24850. #endif
  24851. #ifndef NO_SHA256
  24852. /* SHA-256, COUNT = 3
  24853. * shared secret length: 192
  24854. * SharedInfo length: 0
  24855. * key data length: 128
  24856. */
  24857. WOLFSSL_SMALL_STACK_STATIC const byte Z2[] = {
  24858. 0xd3, 0x8b, 0xdb, 0xe5, 0xc4, 0xfc, 0x16, 0x4c,
  24859. 0xdd, 0x96, 0x7f, 0x63, 0xc0, 0x4f, 0xe0, 0x7b,
  24860. 0x60, 0xcd, 0xe8, 0x81, 0xc2, 0x46, 0x43, 0x8c
  24861. };
  24862. WOLFSSL_SMALL_STACK_STATIC const byte verify2[] = {
  24863. 0x5e, 0x67, 0x4d, 0xb9, 0x71, 0xba, 0xc2, 0x0a,
  24864. 0x80, 0xba, 0xd0, 0xd4, 0x51, 0x4d, 0xc4, 0x84
  24865. };
  24866. #endif
  24867. #ifdef WOLFSSL_SHA512
  24868. /* SHA-512, COUNT = 0
  24869. * shared secret length: 192
  24870. * SharedInfo length: 0
  24871. * key data length: 128
  24872. */
  24873. WOLFSSL_SMALL_STACK_STATIC const byte Z3[] = {
  24874. 0x87, 0xfc, 0x0d, 0x8c, 0x44, 0x77, 0x48, 0x5b,
  24875. 0xb5, 0x74, 0xf5, 0xfc, 0xea, 0x26, 0x4b, 0x30,
  24876. 0x88, 0x5d, 0xc8, 0xd9, 0x0a, 0xd8, 0x27, 0x82
  24877. };
  24878. WOLFSSL_SMALL_STACK_STATIC const byte verify3[] = {
  24879. 0x94, 0x76, 0x65, 0xfb, 0xb9, 0x15, 0x21, 0x53,
  24880. 0xef, 0x46, 0x02, 0x38, 0x50, 0x6a, 0x02, 0x45
  24881. };
  24882. /* SHA-512, COUNT = 0
  24883. * shared secret length: 521
  24884. * SharedInfo length: 128
  24885. * key data length: 1024
  24886. */
  24887. WOLFSSL_SMALL_STACK_STATIC const byte Z4[] = {
  24888. 0x00, 0xaa, 0x5b, 0xb7, 0x9b, 0x33, 0xe3, 0x89,
  24889. 0xfa, 0x58, 0xce, 0xad, 0xc0, 0x47, 0x19, 0x7f,
  24890. 0x14, 0xe7, 0x37, 0x12, 0xf4, 0x52, 0xca, 0xa9,
  24891. 0xfc, 0x4c, 0x9a, 0xdb, 0x36, 0x93, 0x48, 0xb8,
  24892. 0x15, 0x07, 0x39, 0x2f, 0x1a, 0x86, 0xdd, 0xfd,
  24893. 0xb7, 0xc4, 0xff, 0x82, 0x31, 0xc4, 0xbd, 0x0f,
  24894. 0x44, 0xe4, 0x4a, 0x1b, 0x55, 0xb1, 0x40, 0x47,
  24895. 0x47, 0xa9, 0xe2, 0xe7, 0x53, 0xf5, 0x5e, 0xf0,
  24896. 0x5a, 0x2d
  24897. };
  24898. WOLFSSL_SMALL_STACK_STATIC const byte info4[] = {
  24899. 0xe3, 0xb5, 0xb4, 0xc1, 0xb0, 0xd5, 0xcf, 0x1d,
  24900. 0x2b, 0x3a, 0x2f, 0x99, 0x37, 0x89, 0x5d, 0x31
  24901. };
  24902. WOLFSSL_SMALL_STACK_STATIC const byte verify4[] = {
  24903. 0x44, 0x63, 0xf8, 0x69, 0xf3, 0xcc, 0x18, 0x76,
  24904. 0x9b, 0x52, 0x26, 0x4b, 0x01, 0x12, 0xb5, 0x85,
  24905. 0x8f, 0x7a, 0xd3, 0x2a, 0x5a, 0x2d, 0x96, 0xd8,
  24906. 0xcf, 0xfa, 0xbf, 0x7f, 0xa7, 0x33, 0x63, 0x3d,
  24907. 0x6e, 0x4d, 0xd2, 0xa5, 0x99, 0xac, 0xce, 0xb3,
  24908. 0xea, 0x54, 0xa6, 0x21, 0x7c, 0xe0, 0xb5, 0x0e,
  24909. 0xef, 0x4f, 0x6b, 0x40, 0xa5, 0xc3, 0x02, 0x50,
  24910. 0xa5, 0xa8, 0xee, 0xee, 0x20, 0x80, 0x02, 0x26,
  24911. 0x70, 0x89, 0xdb, 0xf3, 0x51, 0xf3, 0xf5, 0x02,
  24912. 0x2a, 0xa9, 0x63, 0x8b, 0xf1, 0xee, 0x41, 0x9d,
  24913. 0xea, 0x9c, 0x4f, 0xf7, 0x45, 0xa2, 0x5a, 0xc2,
  24914. 0x7b, 0xda, 0x33, 0xca, 0x08, 0xbd, 0x56, 0xdd,
  24915. 0x1a, 0x59, 0xb4, 0x10, 0x6c, 0xf2, 0xdb, 0xbc,
  24916. 0x0a, 0xb2, 0xaa, 0x8e, 0x2e, 0xfa, 0x7b, 0x17,
  24917. 0x90, 0x2d, 0x34, 0x27, 0x69, 0x51, 0xce, 0xcc,
  24918. 0xab, 0x87, 0xf9, 0x66, 0x1c, 0x3e, 0x88, 0x16
  24919. };
  24920. #endif
  24921. WOLFSSL_ENTER("x963kdf_test");
  24922. #ifndef NO_SHA
  24923. ret = wc_X963_KDF(WC_HASH_TYPE_SHA, Z, sizeof(Z), NULL, 0,
  24924. kek, sizeof(verify));
  24925. if (ret != 0)
  24926. return WC_TEST_RET_ENC_EC(ret);
  24927. if (XMEMCMP(verify, kek, sizeof(verify)) != 0)
  24928. return WC_TEST_RET_ENC_NC;
  24929. #endif
  24930. #ifndef NO_SHA256
  24931. ret = wc_X963_KDF(WC_HASH_TYPE_SHA256, Z2, sizeof(Z2), NULL, 0,
  24932. kek, sizeof(verify2));
  24933. if (ret != 0)
  24934. return WC_TEST_RET_ENC_EC(ret);
  24935. if (XMEMCMP(verify2, kek, sizeof(verify2)) != 0)
  24936. return WC_TEST_RET_ENC_NC;
  24937. #endif
  24938. #ifdef WOLFSSL_SHA512
  24939. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z3, sizeof(Z3), NULL, 0,
  24940. kek, sizeof(verify3));
  24941. if (ret != 0)
  24942. return WC_TEST_RET_ENC_EC(ret);
  24943. if (XMEMCMP(verify3, kek, sizeof(verify3)) != 0)
  24944. return WC_TEST_RET_ENC_NC;
  24945. ret = wc_X963_KDF(WC_HASH_TYPE_SHA512, Z4, sizeof(Z4), info4,
  24946. sizeof(info4), kek, sizeof(verify4));
  24947. if (ret != 0)
  24948. return WC_TEST_RET_ENC_EC(ret);
  24949. if (XMEMCMP(verify4, kek, sizeof(verify4)) != 0)
  24950. return WC_TEST_RET_ENC_NC;
  24951. #endif
  24952. return 0;
  24953. }
  24954. #endif /* HAVE_X963_KDF */
  24955. #if defined(HAVE_HPKE) && \
  24956. (defined(HAVE_ECC) || defined(HAVE_CURVE25519) || defined(HAVE_CURVE448)) && \
  24957. defined(HAVE_AESGCM)
  24958. static wc_test_ret_t hpke_test_single(Hpke* hpke)
  24959. {
  24960. wc_test_ret_t ret = 0;
  24961. int rngRet = 0;
  24962. WC_RNG rng[1];
  24963. const char* start_text = "this is a test";
  24964. const char* info_text = "info";
  24965. const char* aad_text = "aad";
  24966. byte ciphertext[MAX_HPKE_LABEL_SZ];
  24967. byte plaintext[MAX_HPKE_LABEL_SZ];
  24968. void* receiverKey = NULL;
  24969. void* ephemeralKey = NULL;
  24970. #ifdef WOLFSSL_SMALL_STACK
  24971. byte *pubKey = NULL; /* public key */
  24972. word16 pubKeySz = (word16)HPKE_Npk_MAX;
  24973. #else
  24974. byte pubKey[HPKE_Npk_MAX]; /* public key */
  24975. word16 pubKeySz = (word16)sizeof(pubKey);
  24976. #endif
  24977. rngRet = ret = wc_InitRng(rng);
  24978. if (ret != 0)
  24979. return WC_TEST_RET_ENC_EC(ret);
  24980. #ifdef WOLFSSL_SMALL_STACK
  24981. if (ret == 0) {
  24982. pubKey = (byte *)XMALLOC(pubKeySz, HEAP_HINT,
  24983. DYNAMIC_TYPE_TMP_BUFFER);
  24984. if (pubKey == NULL)
  24985. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  24986. }
  24987. #endif
  24988. /* generate the keys */
  24989. if (ret == 0) {
  24990. ret = wc_HpkeGenerateKeyPair(hpke, &ephemeralKey, rng);
  24991. if (ret != 0)
  24992. ret = WC_TEST_RET_ENC_EC(ret);
  24993. }
  24994. if (ret == 0) {
  24995. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, rng);
  24996. if (ret != 0)
  24997. ret = WC_TEST_RET_ENC_EC(ret);
  24998. }
  24999. /* seal */
  25000. if (ret == 0) {
  25001. ret = wc_HpkeSealBase(hpke, ephemeralKey, receiverKey,
  25002. (byte*)info_text, (word32)XSTRLEN(info_text),
  25003. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25004. (byte*)start_text, (word32)XSTRLEN(start_text),
  25005. ciphertext);
  25006. if (ret != 0)
  25007. ret = WC_TEST_RET_ENC_EC(ret);
  25008. }
  25009. /* export ephemeral key */
  25010. if (ret == 0) {
  25011. ret = wc_HpkeSerializePublicKey(hpke, ephemeralKey, pubKey, &pubKeySz);
  25012. if (ret != 0)
  25013. ret = WC_TEST_RET_ENC_EC(ret);
  25014. }
  25015. /* open with exported ephemeral key */
  25016. if (ret == 0) {
  25017. ret = wc_HpkeOpenBase(hpke, receiverKey, pubKey, pubKeySz,
  25018. (byte*)info_text, (word32)XSTRLEN(info_text),
  25019. (byte*)aad_text, (word32)XSTRLEN(aad_text),
  25020. ciphertext, (word32)XSTRLEN(start_text),
  25021. plaintext);
  25022. if (ret != 0)
  25023. ret = WC_TEST_RET_ENC_EC(ret);
  25024. }
  25025. if (ret == 0) {
  25026. ret = XMEMCMP(plaintext, start_text, XSTRLEN(start_text));
  25027. if (ret != 0)
  25028. ret = WC_TEST_RET_ENC_NC;
  25029. }
  25030. /* Negative test case with NULL argument */
  25031. if (ret == 0) {
  25032. ret = wc_HpkeGenerateKeyPair(NULL, &receiverKey, rng);
  25033. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25034. ret = WC_TEST_RET_ENC_EC(ret);
  25035. else
  25036. ret = 0;
  25037. }
  25038. if (ret == 0) {
  25039. ret = wc_HpkeGenerateKeyPair(hpke, NULL, rng);
  25040. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25041. ret = WC_TEST_RET_ENC_EC(ret);
  25042. else
  25043. ret = 0;
  25044. }
  25045. if (ret == 0) {
  25046. ret = wc_HpkeGenerateKeyPair(hpke, &receiverKey, NULL);
  25047. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25048. ret = WC_TEST_RET_ENC_EC(ret);
  25049. else
  25050. ret = 0;
  25051. }
  25052. if (ephemeralKey != NULL)
  25053. wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
  25054. if (receiverKey != NULL)
  25055. wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
  25056. #ifdef WOLFSSL_SMALL_STACK
  25057. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25058. #endif
  25059. if (rngRet == 0)
  25060. wc_FreeRng(rng);
  25061. return ret;
  25062. }
  25063. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t hpke_test(void)
  25064. {
  25065. wc_test_ret_t ret = 0;
  25066. Hpke hpke[1];
  25067. WOLFSSL_ENTER("hpke_test");
  25068. #if defined(HAVE_ECC)
  25069. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
  25070. /* p256 */
  25071. ret = wc_HpkeInit(hpke, DHKEM_P256_HKDF_SHA256, HKDF_SHA256,
  25072. HPKE_AES_128_GCM, NULL);
  25073. if (ret != 0)
  25074. return WC_TEST_RET_ENC_EC(ret);
  25075. ret = hpke_test_single(hpke);
  25076. if (ret != 0)
  25077. return ret;
  25078. #endif
  25079. #if defined(WOLFSSL_SHA384) && \
  25080. (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES))
  25081. /* p384 */
  25082. ret = wc_HpkeInit(hpke, DHKEM_P384_HKDF_SHA384, HKDF_SHA384,
  25083. HPKE_AES_128_GCM, NULL);
  25084. if (ret != 0)
  25085. return WC_TEST_RET_ENC_EC(ret);
  25086. ret = hpke_test_single(hpke);
  25087. if (ret != 0)
  25088. return ret;
  25089. #endif
  25090. #if (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)) && \
  25091. (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25092. /* p521 */
  25093. ret = wc_HpkeInit(hpke, DHKEM_P521_HKDF_SHA512, HKDF_SHA512,
  25094. HPKE_AES_128_GCM, NULL);
  25095. if (ret != 0)
  25096. return WC_TEST_RET_ENC_EC(ret);
  25097. ret = hpke_test_single(hpke);
  25098. if (ret != 0)
  25099. return ret;
  25100. #endif
  25101. #endif
  25102. #if defined(HAVE_CURVE25519)
  25103. /* test with curve25519 and aes256 */
  25104. ret = wc_HpkeInit(hpke, DHKEM_X25519_HKDF_SHA256, HKDF_SHA256,
  25105. HPKE_AES_256_GCM, NULL);
  25106. if (ret != 0)
  25107. return WC_TEST_RET_ENC_EC(ret);
  25108. ret = hpke_test_single(hpke);
  25109. if (ret != 0)
  25110. return ret;
  25111. #endif
  25112. #if defined(HAVE_CURVE448) && \
  25113. (defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512))
  25114. /* test with curve448 and aes256 */
  25115. ret = wc_HpkeInit(hpke, DHKEM_X448_HKDF_SHA512, HKDF_SHA512,
  25116. HPKE_AES_256_GCM, NULL);
  25117. /* HPKE does not support X448 yet, so expect failure */
  25118. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25119. return WC_TEST_RET_ENC_EC(ret);
  25120. ret = hpke_test_single(hpke);
  25121. /* HPKE does not support X448 yet, so expect failure */
  25122. if (WC_TEST_RET_DEC_EC(ret) != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25123. return ret;
  25124. ret = 0; /* reset error code */
  25125. #endif
  25126. /* TODO: HPKE chacha20 is not implemented */
  25127. return ret;
  25128. }
  25129. #endif /* HAVE_HPKE && HAVE_ECC && HAVE_AESGCM */
  25130. #if defined(WC_SRTP_KDF)
  25131. typedef struct Srtp_Kdf_Tv {
  25132. const unsigned char* key;
  25133. word32 keySz;
  25134. const unsigned char* salt;
  25135. word32 saltSz;
  25136. int kdfIdx;
  25137. const unsigned char* index;
  25138. const unsigned char* ke;
  25139. const unsigned char* ka;
  25140. const unsigned char* ks;
  25141. const unsigned char* index_c;
  25142. const unsigned char* ke_c;
  25143. const unsigned char* ka_c;
  25144. const unsigned char* ks_c;
  25145. word32 keSz;
  25146. word32 kaSz;
  25147. word32 ksSz;
  25148. } Srtp_Kdf_Tv;
  25149. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t srtpkdf_test(void)
  25150. {
  25151. wc_test_ret_t ret = 0;
  25152. /* 128-bit key, kdrIdx = -1 */
  25153. WOLFSSL_SMALL_STACK_STATIC const byte key_0[] = {
  25154. 0xc4, 0x80, 0x9f, 0x6d, 0x36, 0x98, 0x88, 0x72,
  25155. 0x8e, 0x26, 0xad, 0xb5, 0x32, 0x12, 0x98, 0x90
  25156. };
  25157. WOLFSSL_SMALL_STACK_STATIC const byte salt_0[] = {
  25158. 0x0e, 0x23, 0x00, 0x6c, 0x6c, 0x04, 0x4f, 0x56,
  25159. 0x62, 0x40, 0x0e, 0x9d, 0x1b, 0xd6
  25160. };
  25161. WOLFSSL_SMALL_STACK_STATIC const byte index_0[] = {
  25162. 0x48, 0x71, 0x65, 0x64, 0x9c, 0xca
  25163. };
  25164. WOLFSSL_SMALL_STACK_STATIC const byte ke_0[] = {
  25165. 0xdc, 0x38, 0x21, 0x92, 0xab, 0x65, 0x10, 0x8a,
  25166. 0x86, 0xb2, 0x59, 0xb6, 0x1b, 0x3a, 0xf4, 0x6f
  25167. };
  25168. WOLFSSL_SMALL_STACK_STATIC const byte ka_0[] = {
  25169. 0xb8, 0x39, 0x37, 0xfb, 0x32, 0x17, 0x92, 0xee,
  25170. 0x87, 0xb7, 0x88, 0x19, 0x3b, 0xe5, 0xa4, 0xe3,
  25171. 0xbd, 0x32, 0x6e, 0xe4
  25172. };
  25173. WOLFSSL_SMALL_STACK_STATIC const byte ks_0[] = {
  25174. 0xf1, 0xc0, 0x35, 0xc0, 0x0b, 0x5a, 0x54, 0xa6,
  25175. 0x16, 0x92, 0xc0, 0x16, 0x27, 0x6c
  25176. };
  25177. WOLFSSL_SMALL_STACK_STATIC const byte index_c_0[] = {
  25178. 0x56, 0xf3, 0xf1, 0x97
  25179. };
  25180. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_0[] = {
  25181. 0xab, 0x5b, 0xe0, 0xb4, 0x56, 0x23, 0x5d, 0xcf,
  25182. 0x77, 0xd5, 0x08, 0x69, 0x29, 0xba, 0xfb, 0x38
  25183. };
  25184. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_0[] = {
  25185. 0xc5, 0x2f, 0xde, 0x0b, 0x80, 0xb0, 0xf0, 0xba,
  25186. 0xd8, 0xd1, 0x56, 0x45, 0xcb, 0x86, 0xe7, 0xc7,
  25187. 0xc3, 0xd8, 0x77, 0x0e
  25188. };
  25189. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_0[] = {
  25190. 0xde, 0xb5, 0xf8, 0x5f, 0x81, 0x33, 0x6a, 0x96,
  25191. 0x5e, 0xd3, 0x2b, 0xb7, 0xed, 0xe8
  25192. };
  25193. /* 192-bit key, kdrIdx = 0 */
  25194. WOLFSSL_SMALL_STACK_STATIC const byte key_1[] = {
  25195. 0xbb, 0x04, 0x5b, 0x1f, 0x53, 0xc6, 0x93, 0x2c,
  25196. 0x2b, 0xa6, 0x88, 0xf5, 0xe3, 0xf2, 0x24, 0x70,
  25197. 0xe1, 0x7d, 0x7d, 0xec, 0x8a, 0x93, 0x4d, 0xf2
  25198. };
  25199. WOLFSSL_SMALL_STACK_STATIC const byte salt_1[] = {
  25200. 0xe7, 0x22, 0xab, 0x92, 0xfc, 0x7c, 0x89, 0xb6,
  25201. 0x53, 0x8a, 0xf9, 0x3c, 0xb9, 0x52
  25202. };
  25203. WOLFSSL_SMALL_STACK_STATIC const byte index_1[] = {
  25204. 0xd7, 0x87, 0x8f, 0x33, 0xb1, 0x76
  25205. };
  25206. WOLFSSL_SMALL_STACK_STATIC const byte ke_1[] = {
  25207. 0x2c, 0xc8, 0x3e, 0x54, 0xb2, 0x33, 0x89, 0xb3,
  25208. 0x71, 0x65, 0x0f, 0x51, 0x61, 0x65, 0xe4, 0x93,
  25209. 0x07, 0x4e, 0xb3, 0x47, 0xba, 0x2d, 0x60, 0x60
  25210. };
  25211. WOLFSSL_SMALL_STACK_STATIC const byte ka_1[] = {
  25212. 0x2e, 0x80, 0xe4, 0x82, 0x55, 0xa2, 0xbe, 0x6d,
  25213. 0xe0, 0x46, 0xcc, 0xc1, 0x75, 0x78, 0x6e, 0x78,
  25214. 0xd1, 0xd1, 0x47, 0x08
  25215. };
  25216. WOLFSSL_SMALL_STACK_STATIC const byte ks_1[] = {
  25217. 0xe0, 0xc1, 0xe6, 0xaf, 0x1e, 0x8d, 0x8c, 0xfe,
  25218. 0xe5, 0x60, 0x70, 0xb5, 0xe6, 0xea
  25219. };
  25220. WOLFSSL_SMALL_STACK_STATIC const byte index_c_1[] = {
  25221. 0x40, 0xbf, 0xd4, 0xa9
  25222. };
  25223. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_1[] = {
  25224. 0x94, 0x0f, 0x55, 0xce, 0x58, 0xd8, 0x16, 0x65,
  25225. 0xf0, 0xfa, 0x46, 0x40, 0x0c, 0xda, 0xb1, 0x11,
  25226. 0x9e, 0x69, 0xa0, 0x93, 0x4e, 0xd7, 0xf2, 0x84
  25227. };
  25228. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_1[] = {
  25229. 0xf5, 0x41, 0x6f, 0xc2, 0x65, 0xc5, 0xb3, 0xef,
  25230. 0xbb, 0x22, 0xc8, 0xfc, 0x6b, 0x00, 0x14, 0xb2,
  25231. 0xf3, 0x3b, 0x8e, 0x29
  25232. };
  25233. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_1[] = {
  25234. 0x35, 0xb7, 0x42, 0x43, 0xf0, 0x01, 0x01, 0xb4,
  25235. 0x68, 0xa1, 0x28, 0x80, 0x37, 0xf0
  25236. };
  25237. /* 256-bit key, kdrIdx = 1 */
  25238. WOLFSSL_SMALL_STACK_STATIC const byte key_2[] = {
  25239. 0x10, 0x38, 0x0a, 0xcd, 0xd6, 0x47, 0xab, 0xee,
  25240. 0xc0, 0xd4, 0x44, 0xf4, 0x7e, 0x51, 0x36, 0x02,
  25241. 0x79, 0xa8, 0x94, 0x80, 0x35, 0x40, 0xed, 0x50,
  25242. 0xf4, 0x45, 0x30, 0x3d, 0xb5, 0xf0, 0x2b, 0xbb
  25243. };
  25244. WOLFSSL_SMALL_STACK_STATIC const byte salt_2[] = {
  25245. 0xc7, 0x31, 0xf2, 0xc8, 0x40, 0x43, 0xb8, 0x74,
  25246. 0x8a, 0x61, 0x84, 0x7a, 0x25, 0x8a
  25247. };
  25248. WOLFSSL_SMALL_STACK_STATIC const byte index_2[] = {
  25249. 0x82, 0xf1, 0x84, 0x8c, 0xac, 0x42
  25250. };
  25251. WOLFSSL_SMALL_STACK_STATIC const byte ke_2[] = {
  25252. 0xb2, 0x26, 0x60, 0xaf, 0x08, 0x23, 0x14, 0x98,
  25253. 0x91, 0xde, 0x5d, 0x87, 0x95, 0x61, 0xca, 0x8f,
  25254. 0x0e, 0xce, 0xfb, 0x68, 0x4d, 0xd6, 0x28, 0xcb,
  25255. 0x28, 0xe2, 0x27, 0x20, 0x2d, 0xff, 0x64, 0xbb
  25256. };
  25257. WOLFSSL_SMALL_STACK_STATIC const byte ka_2[] = {
  25258. 0x12, 0x6f, 0x52, 0xe8, 0x07, 0x7f, 0x07, 0x84,
  25259. 0xa0, 0x61, 0x96, 0xf8, 0xee, 0x4d, 0x05, 0x57,
  25260. 0x65, 0xc7, 0x50, 0xc1
  25261. };
  25262. WOLFSSL_SMALL_STACK_STATIC const byte ks_2[] = {
  25263. 0x18, 0x5a, 0x59, 0xe5, 0x91, 0x4d, 0xc9, 0x6c,
  25264. 0xfa, 0x5b, 0x36, 0x06, 0x8c, 0x9a
  25265. };
  25266. WOLFSSL_SMALL_STACK_STATIC const byte index_c_2[] = {
  25267. 0x31, 0x2d, 0x58, 0x15
  25268. };
  25269. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_2[] = {
  25270. 0x14, 0xf2, 0xc8, 0x25, 0x02, 0x79, 0x22, 0xa1,
  25271. 0x96, 0xb6, 0xf7, 0x07, 0x76, 0xa6, 0xa3, 0xc4,
  25272. 0x37, 0xdf, 0xa0, 0xf8, 0x78, 0x93, 0x2c, 0xfa,
  25273. 0xea, 0x35, 0xf0, 0xf3, 0x3f, 0x32, 0x6e, 0xfd
  25274. };
  25275. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_2[] = {
  25276. 0x6e, 0x3d, 0x4a, 0x99, 0xea, 0x2f, 0x9d, 0x13,
  25277. 0x4a, 0x1e, 0x71, 0x2e, 0x15, 0xc0, 0xca, 0xb6,
  25278. 0x35, 0x78, 0xdf, 0xa4
  25279. };
  25280. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_2[] = {
  25281. 0xae, 0xe4, 0xec, 0x18, 0x31, 0x70, 0x5d, 0x3f,
  25282. 0xdc, 0x97, 0x89, 0x88, 0xfd, 0xff
  25283. };
  25284. /* 128-bit key, kdrIdx = 8 */
  25285. WOLFSSL_SMALL_STACK_STATIC const byte key_3[] = {
  25286. 0x36, 0xb4, 0xde, 0xcb, 0x2e, 0x51, 0x23, 0x76,
  25287. 0xe0, 0x27, 0x7e, 0x3e, 0xc8, 0xf6, 0x54, 0x04
  25288. };
  25289. WOLFSSL_SMALL_STACK_STATIC const byte salt_3[] = {
  25290. 0x73, 0x26, 0xf4, 0x3f, 0xc0, 0xd9, 0xc6, 0xe3,
  25291. 0x2f, 0x92, 0x7d, 0x46, 0x12, 0x76
  25292. };
  25293. WOLFSSL_SMALL_STACK_STATIC const byte index_3[] = {
  25294. 0x44, 0x73, 0xb2, 0x2d, 0xb2, 0x60
  25295. };
  25296. WOLFSSL_SMALL_STACK_STATIC const byte ke_3[] = {
  25297. 0x79, 0x91, 0x3d, 0x7b, 0x20, 0x5d, 0xea, 0xe2,
  25298. 0xeb, 0x46, 0x89, 0x68, 0x5a, 0x06, 0x73, 0x74
  25299. };
  25300. WOLFSSL_SMALL_STACK_STATIC const byte ka_3[] = {
  25301. 0x2d, 0x2e, 0x97, 0x4e, 0x76, 0x8c, 0x62, 0xa6,
  25302. 0x57, 0x80, 0x13, 0x42, 0x0b, 0x51, 0xa7, 0x66,
  25303. 0xea, 0x31, 0x24, 0xe6
  25304. };
  25305. WOLFSSL_SMALL_STACK_STATIC const byte ks_3[] = {
  25306. 0xcc, 0xd7, 0x31, 0xf6, 0x3b, 0xf3, 0x89, 0x8a,
  25307. 0x5b, 0x7b, 0xb5, 0x8b, 0x4c, 0x3f
  25308. };
  25309. WOLFSSL_SMALL_STACK_STATIC const byte index_c_3[] = {
  25310. 0x4a, 0x7d, 0xaa, 0x85
  25311. };
  25312. WOLFSSL_SMALL_STACK_STATIC const byte ke_c_3[] = {
  25313. 0x34, 0x99, 0x71, 0xfe, 0x12, 0x93, 0xae, 0x8c,
  25314. 0x4a, 0xe9, 0x84, 0xe4, 0x93, 0x53, 0x63, 0x88
  25315. };
  25316. WOLFSSL_SMALL_STACK_STATIC const byte ka_c_3[] = {
  25317. 0xa4, 0x53, 0x5e, 0x0a, 0x9c, 0xf2, 0xce, 0x13,
  25318. 0xef, 0x7a, 0x13, 0xee, 0x0a, 0xef, 0xba, 0x17,
  25319. 0x05, 0x18, 0xe3, 0xed
  25320. };
  25321. WOLFSSL_SMALL_STACK_STATIC const byte ks_c_3[] = {
  25322. 0xe1, 0x29, 0x4f, 0x61, 0x30, 0x3c, 0x4d, 0x46,
  25323. 0x5f, 0x5c, 0x81, 0x3c, 0x38, 0xb6
  25324. };
  25325. /* SRTCP w/ 48-bit idx - KDR 0 (-1) */
  25326. WOLFSSL_SMALL_STACK_STATIC const byte mk48_1[] = {
  25327. 0xFF, 0xB6, 0xCB, 0x09, 0x71, 0x3F, 0x63, 0x4D,
  25328. 0x7F, 0x42, 0xED, 0xA8, 0x12, 0x81, 0x50, 0xE6
  25329. };
  25330. WOLFSSL_SMALL_STACK_STATIC const byte ms48_1[] = {
  25331. 0x1F, 0x04, 0x76, 0xC8, 0x7F, 0x58, 0x23, 0xEF,
  25332. 0xD3, 0x57, 0xB2, 0xBD, 0xF1, 0x32
  25333. };
  25334. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_1[] = {
  25335. 0x00, 0x00, 0x08, 0x56, 0xBC, 0x39
  25336. };
  25337. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_1[] = {
  25338. 0xD2, 0xC3, 0xF3, 0x49, 0x00, 0x1A, 0x18, 0x0F,
  25339. 0xB6, 0x05, 0x5A, 0x5A, 0x67, 0x8E, 0xE5, 0xB2
  25340. };
  25341. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_1[] = {
  25342. 0x8D, 0x54, 0xBE, 0xB5, 0x7B, 0x7F, 0x7A, 0xAB,
  25343. 0xF5, 0x46, 0xCE, 0x5B, 0x45, 0x69, 0x4A, 0x75,
  25344. 0x81, 0x2A, 0xE2, 0xCB
  25345. };
  25346. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_1[] = {
  25347. 0x76, 0x3C, 0x97, 0x6A, 0x45, 0x31, 0xA7, 0x79,
  25348. 0x3C, 0x28, 0x4A, 0xA6, 0x82, 0x03
  25349. };
  25350. /* SRTCP w/ 48-bit idx - KDR 19 */
  25351. WOLFSSL_SMALL_STACK_STATIC const byte mk48_2[] = {
  25352. 0xBD, 0x1D, 0x71, 0x6B, 0xDA, 0x28, 0xE3, 0xFC,
  25353. 0xA5, 0xA0, 0x66, 0x3F, 0x2E, 0x34, 0xA8, 0x58
  25354. };
  25355. WOLFSSL_SMALL_STACK_STATIC const byte ms48_2[] = {
  25356. 0x79, 0x06, 0xE5, 0xAB, 0x5C, 0x2B, 0x1B, 0x69,
  25357. 0xFA, 0xEE, 0xD2, 0x29, 0x57, 0x3C
  25358. };
  25359. WOLFSSL_SMALL_STACK_STATIC const byte srtcp48idx_2[] = {
  25360. 0x00, 0x00, 0x59, 0xD0, 0xC2, 0xE8
  25361. };
  25362. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKe_48_2[] = {
  25363. 0xB9, 0xD7, 0xAD, 0xD8, 0x90, 0x94, 0xC2, 0x92,
  25364. 0xA5, 0x04, 0x87, 0xC4, 0x8C, 0xEF, 0xE2, 0xA3
  25365. };
  25366. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKa_48_2[] = {
  25367. 0x07, 0xD5, 0xC4, 0xD2, 0x06, 0xFB, 0x63, 0x15,
  25368. 0xC2, 0x9C, 0x7F, 0x55, 0xD1, 0x16, 0x5C, 0xB5,
  25369. 0xB7, 0x44, 0x54, 0xBD
  25370. };
  25371. WOLFSSL_SMALL_STACK_STATIC const byte srtcpKs_48_2[] = {
  25372. 0x0C, 0x5E, 0x53, 0xC1, 0xD0, 0x75, 0xAD, 0x65,
  25373. 0xBF, 0x51, 0x74, 0x50, 0x89, 0xD7
  25374. };
  25375. int kdr_48_1 = -1;
  25376. int kdr_48_2 = 19;
  25377. #define SRTP_TV_CNT 4
  25378. Srtp_Kdf_Tv tv[SRTP_TV_CNT] = {
  25379. { key_0, (word32)sizeof(key_0), salt_0, (word32)sizeof(salt_0), -1,
  25380. index_0, ke_0, ka_0, ks_0, index_c_0, ke_c_0, ka_c_0, ks_c_0,
  25381. 16, 20, 14 },
  25382. { key_1, (word32)sizeof(key_1), salt_1, (word32)sizeof(salt_1), 0,
  25383. index_1, ke_1, ka_1, ks_1, index_c_1, ke_c_1, ka_c_1, ks_c_1,
  25384. 24, 20, 14 },
  25385. { key_2, (word32)sizeof(key_2), salt_2, (word32)sizeof(salt_2), 1,
  25386. index_2, ke_2, ka_2, ks_2, index_c_2, ke_c_2, ka_c_2, ks_c_2,
  25387. 32, 20, 14 },
  25388. { key_3, (word32)sizeof(key_3), salt_3, (word32)sizeof(salt_3), 8,
  25389. index_3, ke_3, ka_3, ks_3, index_c_3, ke_c_3, ka_c_3, ks_c_3,
  25390. 16, 20, 14 },
  25391. };
  25392. int i;
  25393. int idx;
  25394. unsigned char keyE[32];
  25395. unsigned char keyA[20];
  25396. unsigned char keyS[14];
  25397. WOLFSSL_ENTER("srtpkdf_test");
  25398. for (i = 0; (ret == 0) && (i < SRTP_TV_CNT); i++) {
  25399. #ifndef WOLFSSL_AES_128
  25400. if (tv[i].keySz == AES_128_KEY_SIZE) {
  25401. continue;
  25402. }
  25403. #endif
  25404. #ifndef WOLFSSL_AES_192
  25405. if (tv[i].keySz == AES_192_KEY_SIZE) {
  25406. continue;
  25407. }
  25408. #endif
  25409. #ifndef WOLFSSL_AES_256
  25410. if (tv[i].keySz == AES_256_KEY_SIZE) {
  25411. continue;
  25412. }
  25413. #endif
  25414. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25415. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25416. keyS, tv[i].ksSz);
  25417. if (ret != 0)
  25418. return WC_TEST_RET_ENC_EC(ret);
  25419. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25420. return WC_TEST_RET_ENC_NC;
  25421. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25422. return WC_TEST_RET_ENC_NC;
  25423. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25424. return WC_TEST_RET_ENC_NC;
  25425. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25426. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_ENCRYPTION,
  25427. keyE, tv[i].keSz);
  25428. if (ret != 0)
  25429. return WC_TEST_RET_ENC_EC(ret);
  25430. if (XMEMCMP(keyE, tv[i].ke, tv[i].keSz) != 0)
  25431. return WC_TEST_RET_ENC_NC;
  25432. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25433. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_MSG_AUTH,
  25434. keyA, tv[i].kaSz);
  25435. if (ret != 0)
  25436. return WC_TEST_RET_ENC_EC(ret);
  25437. if (XMEMCMP(keyA, tv[i].ka, tv[i].kaSz) != 0)
  25438. return WC_TEST_RET_ENC_NC;
  25439. ret = wc_SRTP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25440. tv[i].saltSz, tv[i].kdfIdx, tv[i].index, WC_SRTP_LABEL_SALT, keyS,
  25441. tv[i].ksSz);
  25442. if (ret != 0)
  25443. return WC_TEST_RET_ENC_EC(ret);
  25444. if (XMEMCMP(keyS, tv[i].ks, tv[i].ksSz) != 0)
  25445. return WC_TEST_RET_ENC_NC;
  25446. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25447. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25448. keyS, tv[i].ksSz);
  25449. if (ret != 0)
  25450. return WC_TEST_RET_ENC_EC(ret);
  25451. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25452. return WC_TEST_RET_ENC_NC;
  25453. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25454. return WC_TEST_RET_ENC_NC;
  25455. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25456. return WC_TEST_RET_ENC_NC;
  25457. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25458. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c,
  25459. WC_SRTCP_LABEL_ENCRYPTION, keyE, tv[i].keSz);
  25460. if (ret != 0)
  25461. return WC_TEST_RET_ENC_EC(ret);
  25462. if (XMEMCMP(keyE, tv[i].ke_c, tv[i].keSz) != 0)
  25463. return WC_TEST_RET_ENC_NC;
  25464. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25465. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_MSG_AUTH,
  25466. keyA, tv[i].kaSz);
  25467. if (ret != 0)
  25468. return WC_TEST_RET_ENC_EC(ret);
  25469. if (XMEMCMP(keyA, tv[i].ka_c, tv[i].kaSz) != 0)
  25470. return WC_TEST_RET_ENC_NC;
  25471. ret = wc_SRTCP_KDF_label(tv[i].key, tv[i].keySz, tv[i].salt,
  25472. tv[i].saltSz, tv[i].kdfIdx, tv[i].index_c, WC_SRTCP_LABEL_SALT,
  25473. keyS, tv[i].ksSz);
  25474. if (ret != 0)
  25475. return WC_TEST_RET_ENC_EC(ret);
  25476. if (XMEMCMP(keyS, tv[i].ks_c, tv[i].ksSz) != 0)
  25477. return WC_TEST_RET_ENC_NC;
  25478. }
  25479. #ifdef WOLFSSL_AES_128
  25480. i = 0;
  25481. #elif defined(WOLFSSL_AES_192)
  25482. i = 1;
  25483. #else
  25484. i = 2;
  25485. #endif
  25486. ret = wc_SRTP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25487. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25488. keyS, tv[i].ksSz);
  25489. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25490. return WC_TEST_RET_ENC_EC(ret);
  25491. ret = wc_SRTCP_KDF(tv[i].key, 33, tv[i].salt, tv[i].saltSz,
  25492. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25493. keyS, tv[i].ksSz);
  25494. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25495. return WC_TEST_RET_ENC_EC(ret);
  25496. ret = wc_SRTP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25497. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25498. keyS, tv[i].ksSz);
  25499. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25500. return WC_TEST_RET_ENC_EC(ret);
  25501. ret = wc_SRTCP_KDF(tv[i].key, 15, tv[i].salt, tv[i].saltSz,
  25502. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25503. keyS, tv[i].ksSz);
  25504. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25505. return WC_TEST_RET_ENC_EC(ret);
  25506. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25507. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25508. keyS, tv[i].ksSz);
  25509. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25510. return WC_TEST_RET_ENC_EC(ret);
  25511. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, 15,
  25512. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25513. keyS, tv[i].ksSz);
  25514. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25515. return WC_TEST_RET_ENC_EC(ret);
  25516. ret = wc_SRTP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25517. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25518. keyS, tv[i].ksSz);
  25519. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25520. return WC_TEST_RET_ENC_EC(ret);
  25521. ret = wc_SRTCP_KDF(NULL, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25522. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25523. keyS, tv[i].ksSz);
  25524. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25525. return WC_TEST_RET_ENC_EC(ret);
  25526. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25527. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25528. keyS, tv[i].ksSz);
  25529. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25530. return WC_TEST_RET_ENC_EC(ret);
  25531. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, NULL, tv[i].saltSz,
  25532. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25533. keyS, tv[i].ksSz);
  25534. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25535. return WC_TEST_RET_ENC_EC(ret);
  25536. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25537. 25, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25538. keyS, tv[i].ksSz);
  25539. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25540. return WC_TEST_RET_ENC_EC(ret);
  25541. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25542. 25, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25543. keyS, tv[i].ksSz);
  25544. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25545. return WC_TEST_RET_ENC_EC(ret);
  25546. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25547. -2, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25548. keyS, tv[i].ksSz);
  25549. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25550. return WC_TEST_RET_ENC_EC(ret);
  25551. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25552. -2, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25553. keyS, tv[i].ksSz);
  25554. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  25555. return WC_TEST_RET_ENC_EC(ret);
  25556. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25557. tv[i].kdfIdx, tv[i].index, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25558. keyS, tv[i].ksSz);
  25559. if (ret != 0)
  25560. return WC_TEST_RET_ENC_EC(ret);
  25561. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25562. tv[i].kdfIdx, tv[i].index_c, NULL, tv[i].keSz, keyA, tv[i].kaSz,
  25563. keyS, tv[i].ksSz);
  25564. if (ret != 0)
  25565. return WC_TEST_RET_ENC_EC(ret);
  25566. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25567. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25568. keyS, tv[i].ksSz);
  25569. if (ret != 0)
  25570. return WC_TEST_RET_ENC_EC(ret);
  25571. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25572. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, NULL, tv[i].kaSz,
  25573. keyS, tv[i].ksSz);
  25574. if (ret != 0)
  25575. return WC_TEST_RET_ENC_EC(ret);
  25576. ret = wc_SRTP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25577. tv[i].kdfIdx, tv[i].index, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25578. NULL, tv[i].ksSz);
  25579. if (ret != 0)
  25580. return WC_TEST_RET_ENC_EC(ret);
  25581. ret = wc_SRTCP_KDF(tv[i].key, tv[i].keySz, tv[i].salt, tv[i].saltSz,
  25582. tv[i].kdfIdx, tv[i].index_c, keyE, tv[i].keSz, keyA, tv[i].kaSz,
  25583. NULL, tv[i].ksSz);
  25584. if (ret != 0)
  25585. return WC_TEST_RET_ENC_EC(ret);
  25586. idx = wc_SRTP_KDF_kdr_to_idx(0);
  25587. if (idx != -1)
  25588. return WC_TEST_RET_ENC_NC;
  25589. for (i = 0; i < 32; i++) {
  25590. word32 kdr = 1U << i;
  25591. /* SRTCP w/ 48-bit IDX, 128-bit key test */
  25592. if (i == 0) {
  25593. ret = wc_SRTCP_KDF_ex(mk48_1, (word32)sizeof(mk48_1),
  25594. ms48_1, (word32)sizeof(ms48_1),
  25595. kdr_48_1, srtcp48idx_1, keyE, tv[i].keSz,
  25596. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25597. WC_SRTCP_48BIT_IDX);
  25598. if (ret != 0)
  25599. return WC_TEST_RET_ENC_EC(ret);
  25600. if (XMEMCMP(keyE, srtcpKe_48_1, tv[i].keSz) != 0)
  25601. return WC_TEST_RET_ENC_NC;
  25602. if (XMEMCMP(keyA, srtcpKa_48_1, tv[i].kaSz) != 0)
  25603. return WC_TEST_RET_ENC_NC;
  25604. if (XMEMCMP(keyS, srtcpKs_48_1, tv[i].ksSz) != 0)
  25605. return WC_TEST_RET_ENC_NC;
  25606. ret = wc_SRTCP_KDF_ex(mk48_2, (word32)sizeof(mk48_2),
  25607. ms48_2, (word32)sizeof(ms48_2),
  25608. kdr_48_2, srtcp48idx_2, keyE, tv[i].keSz,
  25609. keyA, tv[i].kaSz, keyS, tv[i].ksSz,
  25610. WC_SRTCP_48BIT_IDX);
  25611. if (ret != 0)
  25612. return WC_TEST_RET_ENC_EC(ret);
  25613. if (XMEMCMP(keyE, srtcpKe_48_2, tv[i].keSz) != 0)
  25614. return WC_TEST_RET_ENC_NC;
  25615. if (XMEMCMP(keyA, srtcpKa_48_2, tv[i].kaSz) != 0)
  25616. return WC_TEST_RET_ENC_NC;
  25617. if (XMEMCMP(keyS, srtcpKs_48_2, tv[i].ksSz) != 0)
  25618. return WC_TEST_RET_ENC_NC;
  25619. }
  25620. idx = wc_SRTP_KDF_kdr_to_idx(kdr);
  25621. if (idx != i)
  25622. return WC_TEST_RET_ENC_NC;
  25623. }
  25624. return 0;
  25625. }
  25626. #endif
  25627. #ifdef HAVE_ECC
  25628. /* size to use for ECC key gen tests */
  25629. #ifndef ECC_KEYGEN_SIZE
  25630. #if !defined(NO_ECC256) || defined(WOLFSSL_SM2)
  25631. #define ECC_KEYGEN_SIZE 32
  25632. #elif defined(HAVE_ECC384)
  25633. #define ECC_KEYGEN_SIZE 48
  25634. #elif defined(HAVE_ECC224)
  25635. #define ECC_KEYGEN_SIZE 28
  25636. #elif defined(HAVE_ECC521)
  25637. #define ECC_KEYGEN_SIZE 66
  25638. #else
  25639. #error No ECC keygen size defined for test
  25640. #endif
  25641. #endif
  25642. #ifdef BENCH_EMBEDDED
  25643. #define ECC_SHARED_SIZE 128
  25644. #else
  25645. #define ECC_SHARED_SIZE MAX_ECC_BYTES
  25646. #endif
  25647. #if defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  25648. #define HAVE_ECC_DETERMINISTIC_K
  25649. #define ECC_DIGEST_SIZE WC_SHA256_DIGEST_SIZE
  25650. #else
  25651. #define ECC_DIGEST_SIZE MAX_ECC_BYTES
  25652. #endif
  25653. #define ECC_SIG_SIZE ECC_MAX_SIG_SIZE
  25654. #ifdef NO_ECC_SECP
  25655. #define NO_ECC_VECTOR_TEST
  25656. #endif
  25657. #ifndef NO_ECC_VECTOR_TEST
  25658. #if (defined(HAVE_ECC192) || defined(HAVE_ECC224) ||\
  25659. !defined(NO_ECC256) || defined(HAVE_ECC384) ||\
  25660. defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES))
  25661. #define HAVE_ECC_VECTOR_TEST
  25662. #endif
  25663. #endif
  25664. #ifdef HAVE_ECC_VECTOR_TEST
  25665. typedef struct eccVector {
  25666. const char* msg; /* SHA-1 Encoded Message */
  25667. const char* Qx;
  25668. const char* Qy;
  25669. const char* d; /* Private Key */
  25670. const char* R;
  25671. const char* S;
  25672. const char* curveName;
  25673. word32 msgLen;
  25674. word32 keySize;
  25675. const byte* r;
  25676. word32 rSz;
  25677. const byte* s;
  25678. word32 sSz;
  25679. } eccVector;
  25680. #if !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  25681. static wc_test_ret_t ecc_test_vector_item(const eccVector* vector)
  25682. {
  25683. wc_test_ret_t ret = 0;
  25684. int verify = 0;
  25685. word32 sigSz;
  25686. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25687. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25688. #else
  25689. ecc_key userA[1];
  25690. #endif
  25691. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25692. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25693. word32 sigRawSz, rSz = MAX_ECC_BYTES, sSz = MAX_ECC_BYTES;
  25694. WC_DECLARE_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25695. WC_DECLARE_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25696. WC_DECLARE_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25697. #endif
  25698. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  25699. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25700. WC_ALLOC_VAR(sigRaw, byte, ECC_SIG_SIZE, HEAP_HINT);
  25701. WC_ALLOC_VAR(r, byte, MAX_ECC_BYTES, HEAP_HINT);
  25702. WC_ALLOC_VAR(s, byte, MAX_ECC_BYTES, HEAP_HINT);
  25703. #endif
  25704. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  25705. if (sig == NULL)
  25706. ERROR_OUT(MEMORY_E, done);
  25707. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25708. if (sigRaw == NULL || r == NULL || s == NULL)
  25709. ERROR_OUT(MEMORY_E, done);
  25710. #endif
  25711. #endif
  25712. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25713. if (userA == NULL)
  25714. ERROR_OUT(MEMORY_E, done);
  25715. #endif
  25716. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  25717. if (ret != 0)
  25718. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25719. ret = wc_ecc_import_raw(userA, vector->Qx, vector->Qy,
  25720. vector->d, vector->curveName);
  25721. if (ret != 0)
  25722. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25723. #if !defined(NO_ASN)
  25724. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25725. sigSz = ECC_SIG_SIZE;
  25726. ret = wc_ecc_rs_to_sig(vector->R, vector->S, sig, &sigSz);
  25727. if (ret != 0)
  25728. goto done;
  25729. #if !defined(HAVE_SELFTEST)
  25730. XMEMSET(sigRaw, 0, ECC_SIG_SIZE);
  25731. sigRawSz = ECC_SIG_SIZE;
  25732. ret = wc_ecc_rs_raw_to_sig(vector->r, vector->rSz, vector->s, vector->sSz,
  25733. sigRaw, &sigRawSz);
  25734. if (ret != 0)
  25735. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25736. if (sigSz != sigRawSz || XMEMCMP(sig, sigRaw, sigSz) != 0) {
  25737. ret = WC_TEST_RET_ENC_NC;
  25738. goto done;
  25739. }
  25740. ret = wc_ecc_sig_to_rs(sig, sigSz, r, &rSz, s, &sSz);
  25741. if (ret != 0)
  25742. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25743. if (rSz != vector->rSz || XMEMCMP(r, vector->r, rSz) != 0 ||
  25744. sSz != vector->sSz || XMEMCMP(s, vector->s, sSz) != 0) {
  25745. ret = WC_TEST_RET_ENC_NC;
  25746. goto done;
  25747. }
  25748. #endif /* !HAVE_SELFTEST */
  25749. #else
  25750. /* Signature will be R+S directly */
  25751. /* Make sure and zero pad if r or s is less than key size */
  25752. XMEMSET(sig, 0, ECC_SIG_SIZE);
  25753. sigSz = vector->keySize * 2;
  25754. XMEMCPY(sig + (vector->keySize - vector->rSz),
  25755. vector->r, vector->rSz);
  25756. XMEMCPY(sig + vector->keySize + (vector->keySize - vector->sSz),
  25757. vector->s, vector->sSz);
  25758. #endif /* !NO_ASN */
  25759. #ifdef HAVE_ECC_VERIFY
  25760. do {
  25761. #if defined(WOLFSSL_ASYNC_CRYPT)
  25762. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  25763. #endif
  25764. if (ret == 0)
  25765. ret = wc_ecc_verify_hash(sig, sigSz, (byte*)vector->msg,
  25766. vector->msgLen, &verify, userA);
  25767. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  25768. if (ret != 0)
  25769. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  25770. TEST_SLEEP();
  25771. if (verify != 1)
  25772. ret = WC_TEST_RET_ENC_NC;
  25773. #endif
  25774. done:
  25775. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  25776. if (userA != NULL) {
  25777. wc_ecc_free(userA);
  25778. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  25779. }
  25780. #else
  25781. wc_ecc_free(userA);
  25782. #endif
  25783. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST)
  25784. WC_FREE_VAR(sigRaw, HEAP_HINT);
  25785. WC_FREE_VAR(r, HEAP_HINT);
  25786. WC_FREE_VAR(s, HEAP_HINT);
  25787. #endif
  25788. WC_FREE_VAR(sig, HEAP_HINT);
  25789. return ret;
  25790. }
  25791. static wc_test_ret_t ecc_test_vector(int keySize)
  25792. {
  25793. wc_test_ret_t ret;
  25794. eccVector vec;
  25795. XMEMSET(&vec, 0, sizeof(vec));
  25796. vec.keySize = (word32)keySize;
  25797. switch(keySize) {
  25798. #if defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)
  25799. case 14:
  25800. return 0;
  25801. #endif /* HAVE_ECC112 */
  25802. #if defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)
  25803. case 16:
  25804. return 0;
  25805. #endif /* HAVE_ECC128 */
  25806. #if defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)
  25807. case 20:
  25808. return 0;
  25809. #endif /* HAVE_ECC160 */
  25810. #if defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)
  25811. case 24:
  25812. /* first [P-192,SHA-1] vector from FIPS 186-3 NIST vectors */
  25813. #if 1
  25814. vec.msg = "\x60\x80\x79\x42\x3f\x12\x42\x1d\xe6\x16\xb7\x49\x3e\xbe\x55\x1c\xf4\xd6\x5b\x92";
  25815. vec.msgLen = 20;
  25816. #else
  25817. /* This is the raw message prior to SHA-1 */
  25818. vec.msg =
  25819. "\xeb\xf7\x48\xd7\x48\xeb\xbc\xa7\xd2\x9f\xb4\x73\x69\x8a\x6e\x6b"
  25820. "\x4f\xb1\x0c\x86\x5d\x4a\xf0\x24\xcc\x39\xae\x3d\xf3\x46\x4b\xa4"
  25821. "\xf1\xd6\xd4\x0f\x32\xbf\x96\x18\xa9\x1b\xb5\x98\x6f\xa1\xa2\xaf"
  25822. "\x04\x8a\x0e\x14\xdc\x51\xe5\x26\x7e\xb0\x5e\x12\x7d\x68\x9d\x0a"
  25823. "\xc6\xf1\xa7\xf1\x56\xce\x06\x63\x16\xb9\x71\xcc\x7a\x11\xd0\xfd"
  25824. "\x7a\x20\x93\xe2\x7c\xf2\xd0\x87\x27\xa4\xe6\x74\x8c\xc3\x2f\xd5"
  25825. "\x9c\x78\x10\xc5\xb9\x01\x9d\xf2\x1c\xdc\xc0\xbc\xa4\x32\xc0\xa3"
  25826. "\xee\xd0\x78\x53\x87\x50\x88\x77\x11\x43\x59\xce\xe4\xa0\x71\xcf";
  25827. vec.msgLen = 128;
  25828. #endif
  25829. vec.Qx = "07008ea40b08dbe76432096e80a2494c94982d2d5bcf98e6";
  25830. vec.Qy = "76fab681d00b414ea636ba215de26d98c41bd7f2e4d65477";
  25831. vec.d = "e14f37b3d1374ff8b03f41b9b3fdd2f0ebccf275d660d7f3";
  25832. vec.R = "6994d962bdd0d793ffddf855ec5bf2f91a9698b46258a63e";
  25833. vec.S = "02ba6465a234903744ab02bc8521405b73cf5fc00e1a9f41";
  25834. vec.curveName = "SECP192R1";
  25835. vec.r = (byte*)"\x69\x94\xd9\x62\xbd\xd0\xd7\x93\xff\xdd\xf8\x55"
  25836. "\xec\x5b\xf2\xf9\x1a\x96\x98\xb4\x62\x58\xa6\x3e";
  25837. vec.rSz = 24;
  25838. vec.s = (byte*)"\x02\xba\x64\x65\xa2\x34\x90\x37\x44\xab\x02\xbc"
  25839. "\x85\x21\x40\x5b\x73\xcf\x5f\xc0\x0e\x1a\x9f\x41";
  25840. vec.sSz = 24;
  25841. break;
  25842. #endif /* HAVE_ECC192 */
  25843. #if defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)
  25844. case 28:
  25845. /* first [P-224,SHA-1] vector from FIPS 186-3 NIST vectors */
  25846. #if 1
  25847. vec.msg = "\xb9\xa3\xb8\x6d\xb0\xba\x99\xfd\xc6\xd2\x94\x6b\xfe\xbe\x9c\xe8\x3f\x10\x74\xfc";
  25848. vec.msgLen = 20;
  25849. #else
  25850. /* This is the raw message prior to SHA-1 */
  25851. vec.msg =
  25852. "\x36\xc8\xb2\x29\x86\x48\x7f\x67\x7c\x18\xd0\x97\x2a\x9e\x20\x47"
  25853. "\xb3\xaf\xa5\x9e\xc1\x62\x76\x4e\xc3\x0b\x5b\x69\xe0\x63\x0f\x99"
  25854. "\x0d\x4e\x05\xc2\x73\xb0\xe5\xa9\xd4\x28\x27\xb6\x95\xfc\x2d\x64"
  25855. "\xd9\x13\x8b\x1c\xf4\xc1\x21\x55\x89\x4c\x42\x13\x21\xa7\xbb\x97"
  25856. "\x0b\xdc\xe0\xfb\xf0\xd2\xae\x85\x61\xaa\xd8\x71\x7f\x2e\x46\xdf"
  25857. "\xe3\xff\x8d\xea\xb4\xd7\x93\x23\x56\x03\x2c\x15\x13\x0d\x59\x9e"
  25858. "\x26\xc1\x0f\x2f\xec\x96\x30\x31\xac\x69\x38\xa1\x8d\x66\x45\x38"
  25859. "\xb9\x4d\xac\x55\x34\xef\x7b\x59\x94\x24\xd6\x9b\xe1\xf7\x1c\x20";
  25860. vec.msgLen = 128;
  25861. #endif
  25862. vec.Qx = "8a4dca35136c4b70e588e23554637ae251077d1365a6ba5db9585de7";
  25863. vec.Qy = "ad3dee06de0be8279d4af435d7245f14f3b4f82eb578e519ee0057b1";
  25864. vec.d = "97c4b796e1639dd1035b708fc00dc7ba1682cec44a1002a1a820619f";
  25865. vec.R = "147b33758321e722a0360a4719738af848449e2c1d08defebc1671a7";
  25866. vec.S = "24fc7ed7f1352ca3872aa0916191289e2e04d454935d50fe6af3ad5b";
  25867. vec.curveName = "SECP224R1";
  25868. vec.r = (byte*)"\x14\x7b\x33\x75\x83\x21\xe7\x22\xa0\x36\x0a\x47"
  25869. "\x19\x73\x8a\xf8\x48\x44\x9e\x2c\x1d\x08\xde\xfe"
  25870. "\xbc\x16\x71\xa7";
  25871. vec.rSz = 28;
  25872. vec.s = (byte*)"\x24\xfc\x7e\xd7\xf1\x35\x2c\xa3\x87\x2a\xa0\x91"
  25873. "\x61\x91\x28\x9e\x2e\x04\xd4\x54\x93\x5d\x50\xfe"
  25874. "\x6a\xf3\xad\x5b";
  25875. vec.sSz = 28;
  25876. break;
  25877. #endif /* HAVE_ECC224 */
  25878. #if defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)
  25879. case 30:
  25880. return 0;
  25881. #endif /* HAVE_ECC239 */
  25882. #if !defined(NO_ECC256) || defined(HAVE_ALL_CURVES)
  25883. case 32:
  25884. /* first [P-256,SHA-1] vector from FIPS 186-3 NIST vectors */
  25885. #if 1
  25886. vec.msg = "\xa3\xf9\x1a\xe2\x1b\xa6\xb3\x03\x98\x64\x47\x2f\x18\x41\x44\xc6\xaf\x62\xcd\x0e";
  25887. vec.msgLen = 20;
  25888. #else
  25889. /* This is the raw message prior to SHA-1 */
  25890. vec.msg =
  25891. "\xa2\x4b\x21\x76\x2e\x6e\xdb\x15\x3c\xc1\x14\x38\xdb\x0e\x92\xcd"
  25892. "\xf5\x2b\x86\xb0\x6c\xa9\x70\x16\x06\x27\x59\xc7\x0d\x36\xd1\x56"
  25893. "\x2c\xc9\x63\x0d\x7f\xc7\xc7\x74\xb2\x8b\x54\xe3\x1e\xf5\x58\x72"
  25894. "\xb2\xa6\x5d\xf1\xd7\xec\x26\xde\xbb\x33\xe7\xd9\x27\xef\xcc\xf4"
  25895. "\x6b\x63\xde\x52\xa4\xf4\x31\xea\xca\x59\xb0\x5d\x2e\xde\xc4\x84"
  25896. "\x5f\xff\xc0\xee\x15\x03\x94\xd6\x1f\x3d\xfe\xcb\xcd\xbf\x6f\x5a"
  25897. "\x73\x38\xd0\xbe\x3f\x2a\x77\x34\x51\x98\x3e\xba\xeb\x48\xf6\x73"
  25898. "\x8f\xc8\x95\xdf\x35\x7e\x1a\x48\xa6\x53\xbb\x35\x5a\x31\xa1\xb4"
  25899. vec.msgLen = 128;
  25900. #endif
  25901. vec.Qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
  25902. vec.Qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
  25903. vec.d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
  25904. vec.R = "2b826f5d44e2d0b6de531ad96b51e8f0c56fdfead3c236892e4d84eacfc3b75c";
  25905. vec.S = "a2248b62c03db35a7cd63e8a120a3521a89d3d2f61ff99035a2148ae32e3a248";
  25906. vec.r = (byte*)"\x2b\x82\x6f\x5d\x44\xe2\xd0\xb6\xde\x53\x1a\xd9"
  25907. "\x6b\x51\xe8\xf0\xc5\x6f\xdf\xea\xd3\xc2\x36\x89"
  25908. "\x2e\x4d\x84\xea\xcf\xc3\xb7\x5c";
  25909. vec.rSz = 32;
  25910. vec.s = (byte*)"\xa2\x24\x8b\x62\xc0\x3d\xb3\x5a\x7c\xd6\x3e\x8a"
  25911. "\x12\x0a\x35\x21\xa8\x9d\x3d\x2f\x61\xff\x99\x03"
  25912. "\x5a\x21\x48\xae\x32\xe3\xa2\x48";
  25913. vec.sSz = 32;
  25914. vec.curveName = "SECP256R1";
  25915. break;
  25916. #endif /* !NO_ECC256 */
  25917. #if defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)
  25918. case 40:
  25919. return 0;
  25920. #endif /* HAVE_ECC320 */
  25921. #if defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)
  25922. case 48:
  25923. /* first [P-384,SHA-1] vector from FIPS 186-3 NIST vectors */
  25924. #if 1
  25925. vec.msg = "\x9b\x9f\x8c\x95\x35\xa5\xca\x26\x60\x5d\xb7\xf2\xfa\x57\x3b\xdf\xc3\x2e\xab\x8b";
  25926. vec.msgLen = 20;
  25927. #else
  25928. /* This is the raw message prior to SHA-1 */
  25929. vec.msg =
  25930. "\xab\xe1\x0a\xce\x13\xe7\xe1\xd9\x18\x6c\x48\xf7\x88\x9d\x51\x47"
  25931. "\x3d\x3a\x09\x61\x98\x4b\xc8\x72\xdf\x70\x8e\xcc\x3e\xd3\xb8\x16"
  25932. "\x9d\x01\xe3\xd9\x6f\xc4\xf1\xd5\xea\x00\xa0\x36\x92\xbc\xc5\xcf"
  25933. "\xfd\x53\x78\x7c\x88\xb9\x34\xaf\x40\x4c\x03\x9d\x32\x89\xb5\xba"
  25934. "\xc5\xae\x7d\xb1\x49\x68\x75\xb5\xdc\x73\xc3\x09\xf9\x25\xc1\x3d"
  25935. "\x1c\x01\xab\xda\xaf\xeb\xcd\xac\x2c\xee\x43\x39\x39\xce\x8d\x4a"
  25936. "\x0a\x5d\x57\xbb\x70\x5f\x3b\xf6\xec\x08\x47\x95\x11\xd4\xb4\xa3"
  25937. "\x21\x1f\x61\x64\x9a\xd6\x27\x43\x14\xbf\x0d\x43\x8a\x81\xe0\x60"
  25938. vec.msgLen = 128;
  25939. #endif
  25940. vec.Qx = "e55fee6c49d8d523f5ce7bf9c0425ce4ff650708b7de5cfb095901523979a7f042602db30854735369813b5c3f5ef868";
  25941. vec.Qy = "28f59cc5dc509892a988d38a8e2519de3d0c4fd0fbdb0993e38f18506c17606c5e24249246f1ce94983a5361c5be983e";
  25942. vec.d = "a492ce8fa90084c227e1a32f7974d39e9ff67a7e8705ec3419b35fb607582bebd461e0b1520ac76ec2dd4e9b63ebae71";
  25943. vec.R = "6820b8585204648aed63bdff47f6d9acebdea62944774a7d14f0e14aa0b9a5b99545b2daee6b3c74ebf606667a3f39b7";
  25944. vec.S = "491af1d0cccd56ddd520b233775d0bc6b40a6255cc55207d8e9356741f23c96c14714221078dbd5c17f4fdd89b32a907";
  25945. vec.curveName = "SECP384R1";
  25946. vec.r = (byte*)"\x68\x20\xb8\x58\x52\x04\x64\x8a\xed\x63\xbd\xff"
  25947. "\x47\xf6\xd9\xac\xeb\xde\xa6\x29\x44\x77\x4a\x7d"
  25948. "\x14\xf0\xe1\x4a\xa0\xb9\xa5\xb9\x95\x45\xb2\xda"
  25949. "\xee\x6b\x3c\x74\xeb\xf6\x06\x66\x7a\x3f\x39\xb7";
  25950. vec.rSz = 48;
  25951. vec.s = (byte*)"\x49\x1a\xf1\xd0\xcc\xcd\x56\xdd\xd5\x20\xb2\x33"
  25952. "\x77\x5d\x0b\xc6\xb4\x0a\x62\x55\xcc\x55\x20\x7d"
  25953. "\x8e\x93\x56\x74\x1f\x23\xc9\x6c\x14\x71\x42\x21"
  25954. "\x07\x8d\xbd\x5c\x17\xf4\xfd\xd8\x9b\x32\xa9\x07";
  25955. vec.sSz = 48;
  25956. break;
  25957. #endif /* HAVE_ECC384 */
  25958. #if defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)
  25959. case 64:
  25960. return 0;
  25961. #endif /* HAVE_ECC512 */
  25962. #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
  25963. case 66:
  25964. /* first [P-521,SHA-1] vector from FIPS 186-3 NIST vectors */
  25965. #if 1
  25966. vec.msg = "\x1b\xf7\x03\x9c\xca\x23\x94\x27\x3f\x11\xa1\xd4\x8d\xcc\xb4\x46\x6f\x31\x61\xdf";
  25967. vec.msgLen = 20;
  25968. #else
  25969. /* This is the raw message prior to SHA-1 */
  25970. vec.msg =
  25971. "\x50\x3f\x79\x39\x34\x0a\xc7\x23\xcd\x4a\x2f\x4e\x6c\xcc\x27\x33"
  25972. "\x38\x3a\xca\x2f\xba\x90\x02\x19\x9d\x9e\x1f\x94\x8b\xe0\x41\x21"
  25973. "\x07\xa3\xfd\xd5\x14\xd9\x0c\xd4\xf3\x7c\xc3\xac\x62\xef\x00\x3a"
  25974. "\x2d\xb1\xd9\x65\x7a\xb7\x7f\xe7\x55\xbf\x71\xfa\x59\xe4\xd9\x6e"
  25975. "\xa7\x2a\xe7\xbf\x9d\xe8\x7d\x79\x34\x3b\xc1\xa4\xbb\x14\x4d\x16"
  25976. "\x28\xd1\xe9\xe9\xc8\xed\x80\x8b\x96\x2c\x54\xe5\xf9\x6d\x53\xda"
  25977. "\x14\x7a\x96\x38\xf9\x4a\x91\x75\xd8\xed\x61\x05\x5f\x0b\xa5\x73"
  25978. "\xa8\x2b\xb7\xe0\x18\xee\xda\xc4\xea\x7b\x36\x2e\xc8\x9c\x38\x2b"
  25979. vec.msgLen = 128;
  25980. #endif
  25981. vec.Qx = "12fbcaeffa6a51f3ee4d3d2b51c5dec6d7c726ca353fc014ea2bf7cfbb9b910d32cbfa6a00fe39b6cdb8946f22775398b2e233c0cf144d78c8a7742b5c7a3bb5d23";
  25982. vec.Qy = "09cdef823dd7bf9a79e8cceacd2e4527c231d0ae5967af0958e931d7ddccf2805a3e618dc3039fec9febbd33052fe4c0fee98f033106064982d88f4e03549d4a64d";
  25983. vec.d = "1bd56bd106118eda246155bd43b42b8e13f0a6e25dd3bb376026fab4dc92b6157bc6dfec2d15dd3d0cf2a39aa68494042af48ba9601118da82c6f2108a3a203ad74";
  25984. vec.R = "0bd117b4807710898f9dd7778056485777668f0e78e6ddf5b000356121eb7a220e9493c7f9a57c077947f89ac45d5acb6661bbcd17abb3faea149ba0aa3bb1521be";
  25985. vec.S = "019cd2c5c3f9870ecdeb9b323abdf3a98cd5e231d85c6ddc5b71ab190739f7f226e6b134ba1d5889ddeb2751dabd97911dff90c34684cdbe7bb669b6c3d22f2480c";
  25986. vec.curveName = "SECP521R1";
  25987. vec.r = (byte*)"\xbd\x11\x7b\x48\x07\x71\x08\x98\xf9\xdd\x77\x78"
  25988. "\x05\x64\x85\x77\x76\x68\xf0\xe7\x8e\x6d\xdf\x5b"
  25989. "\x00\x03\x56\x12\x1e\xb7\xa2\x20\xe9\x49\x3c\x7f"
  25990. "\x9a\x57\xc0\x77\x94\x7f\x89\xac\x45\xd5\xac\xb6"
  25991. "\x66\x1b\xbc\xd1\x7a\xbb\x3f\xae\xa1\x49\xba\x0a"
  25992. "\xa3\xbb\x15\x21\xbe";
  25993. vec.rSz = 65;
  25994. vec.s = (byte*)"\x19\xcd\x2c\x5c\x3f\x98\x70\xec\xde\xb9\xb3\x23"
  25995. "\xab\xdf\x3a\x98\xcd\x5e\x23\x1d\x85\xc6\xdd\xc5"
  25996. "\xb7\x1a\xb1\x90\x73\x9f\x7f\x22\x6e\x6b\x13\x4b"
  25997. "\xa1\xd5\x88\x9d\xde\xb2\x75\x1d\xab\xd9\x79\x11"
  25998. "\xdf\xf9\x0c\x34\x68\x4c\xdb\xe7\xbb\x66\x9b\x6c"
  25999. "\x3d\x22\xf2\x48\x0c";
  26000. vec.sSz = 65;
  26001. break;
  26002. #endif /* HAVE_ECC521 */
  26003. default:
  26004. return WC_TEST_RET_ENC_EC(NOT_COMPILED_IN); /* Invalid key size /
  26005. * Not supported
  26006. */
  26007. }; /* Switch */
  26008. ret = ecc_test_vector_item(&vec);
  26009. if (ret < 0) {
  26010. return ret;
  26011. }
  26012. return 0;
  26013. }
  26014. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26015. #if defined(HAVE_ECC_SIGN) && \
  26016. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  26017. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  26018. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  26019. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  26020. static wc_test_ret_t ecdsa_test_deterministic_k_sig(ecc_key *key,
  26021. enum wc_HashType hashType, const char* msg, WC_RNG* rng, const byte* expSig,
  26022. size_t expSigSz)
  26023. {
  26024. wc_test_ret_t ret;
  26025. int verify;
  26026. byte sig[ECC_MAX_SIG_SIZE];
  26027. word32 sigSz;
  26028. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26029. ret = wc_Hash(hashType,
  26030. (byte*)msg, (word32)XSTRLEN(msg),
  26031. hash, sizeof(hash));
  26032. if (ret != 0)
  26033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26034. /* Sign test */
  26035. sigSz = sizeof(sig);
  26036. do {
  26037. #if defined(WOLFSSL_ASYNC_CRYPT)
  26038. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26039. #endif
  26040. if (ret == 0)
  26041. ret = wc_ecc_sign_hash(hash, wc_HashGetDigestSize(hashType),
  26042. sig, &sigSz, rng, key);
  26043. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26044. if (ret != 0)
  26045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26046. TEST_SLEEP();
  26047. /* Compare test vector */
  26048. if (sigSz != expSigSz) {
  26049. ret = WC_TEST_RET_ENC_NC;
  26050. goto done;
  26051. }
  26052. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26053. ret = WC_TEST_RET_ENC_NC;
  26054. goto done;
  26055. }
  26056. /* Verification */
  26057. verify = 0;
  26058. do {
  26059. #if defined(WOLFSSL_ASYNC_CRYPT)
  26060. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26061. #endif
  26062. if (ret == 0)
  26063. ret = wc_ecc_verify_hash(sig, sigSz,
  26064. hash, wc_HashGetDigestSize(hashType), &verify, key);
  26065. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26066. if (ret != 0)
  26067. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26068. if (verify != 1) {
  26069. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26070. }
  26071. done:
  26072. return ret;
  26073. }
  26074. static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
  26075. {
  26076. wc_test_ret_t ret;
  26077. #ifdef WOLFSSL_SMALL_STACK
  26078. ecc_key *key = NULL;
  26079. #else
  26080. ecc_key key[1];
  26081. #endif
  26082. int key_inited = 0;
  26083. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26084. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26085. "C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721";
  26086. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26087. "60FED4BA255A9D31C961EB74C6356D68C049B8923B61FA6CE669622E60F29FB6";
  26088. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26089. "7903FE1008B8BC99A41AE9E95628BC64F2F1B20C2D7E9F5177A3C294D4462299";
  26090. #ifndef NO_SHA256
  26091. WOLFSSL_SMALL_STACK_STATIC const byte expSig256[] = {
  26092. 0x30, 0x46, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26093. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26094. 0x00, 0xEF, 0xD4, 0x8B, 0x2A, 0xAC, 0xB6, 0xA8,
  26095. 0xFD, 0x11, 0x40, 0xDD, 0x9C, 0xD4, 0x5E, 0x81,
  26096. 0xD6, 0x9D, 0x2C, 0x87, 0x7B, 0x56, 0xAA, 0xF9,
  26097. 0x91, 0xC3, 0x4D, 0x0E, 0xA8, 0x4E, 0xAF, 0x37,
  26098. 0x16,
  26099. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26100. 0x00, 0xF7, 0xCB, 0x1C, 0x94, 0x2D, 0x65, 0x7C,
  26101. 0x41, 0xD4, 0x36, 0xC7, 0xA1, 0xB6, 0xE2, 0x9F,
  26102. 0x65, 0xF3, 0xE9, 0x00, 0xDB, 0xB9, 0xAF, 0xF4,
  26103. 0x06, 0x4D, 0xC4, 0xAB, 0x2F, 0x84, 0x3A, 0xCD,
  26104. 0xA8
  26105. };
  26106. #endif
  26107. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26108. WOLFSSL_SMALL_STACK_STATIC const byte expSig384[] = {
  26109. 0x30, 0x44, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26110. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26111. 0x0e, 0xaf, 0xea, 0x03, 0x9b, 0x20, 0xe9, 0xb4,
  26112. 0x23, 0x09, 0xfb, 0x1d, 0x89, 0xe2, 0x13, 0x05,
  26113. 0x7c, 0xbf, 0x97, 0x3d, 0xc0, 0xcf, 0xc8, 0xf1,
  26114. 0x29, 0xed, 0xdd, 0xc8, 0x00, 0xef, 0x77, 0x19,
  26115. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26116. 0x48, 0x61, 0xf0, 0x49, 0x1e, 0x69, 0x98, 0xb9,
  26117. 0x45, 0x51, 0x93, 0xe3, 0x4e, 0x7b, 0x0d, 0x28,
  26118. 0x4d, 0xdd, 0x71, 0x49, 0xa7, 0x4b, 0x95, 0xb9,
  26119. 0x26, 0x1f, 0x13, 0xab, 0xde, 0x94, 0x09, 0x54
  26120. };
  26121. #endif
  26122. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26123. WOLFSSL_SMALL_STACK_STATIC const byte expSig512[] = {
  26124. 0x30, 0x45, /* CONSTRUCTED SEQUENCE: (0x20 | 0x10) = 68 bytes */
  26125. 0x02, 0x21, /* ASN_INTEGER = 0x02 (32 bytes) - SIG R */
  26126. 0x00, 0x84, 0x96, 0xa6, 0x0b, 0x5e, 0x9b, 0x47,
  26127. 0xc8, 0x25, 0x48, 0x88, 0x27, 0xe0, 0x49, 0x5b,
  26128. 0x0e, 0x3f, 0xa1, 0x09, 0xec, 0x45, 0x68, 0xfd,
  26129. 0x3f, 0x8d, 0x10, 0x97, 0x67, 0x8e, 0xb9, 0x7f,
  26130. 0x00,
  26131. 0x02, 0x20, /* ASN_INTEGER = 0x02 (32 bytes) - SIG S */
  26132. 0x23, 0x62, 0xab, 0x1a, 0xdb, 0xe2, 0xb8, 0xad,
  26133. 0xf9, 0xcb, 0x9e, 0xda, 0xb7, 0x40, 0xea, 0x60,
  26134. 0x49, 0xc0, 0x28, 0x11, 0x4f, 0x24, 0x60, 0xf9,
  26135. 0x65, 0x54, 0xf6, 0x1f, 0xae, 0x33, 0x02, 0xfe
  26136. };
  26137. #endif
  26138. #ifdef WOLFSSL_SMALL_STACK
  26139. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26140. if (key == NULL)
  26141. return MEMORY_E;
  26142. #endif
  26143. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26144. if (ret != 0)
  26145. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26146. key_inited = 1;
  26147. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26148. if (ret != 0)
  26149. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26150. ret = wc_ecc_set_deterministic(key, 1);
  26151. if (ret != 0)
  26152. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26153. #ifndef NO_SHA256
  26154. /* Test for SHA2-256 */
  26155. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA256, msg, rng,
  26156. expSig256, sizeof(expSig256));
  26157. if (ret != 0)
  26158. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26159. #endif /* !NO_SHA256 */
  26160. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26161. /* Test for SHA2-384 */
  26162. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA384, msg, rng,
  26163. expSig384, sizeof(expSig384));
  26164. if (ret != 0)
  26165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26166. #endif /* WOLFSSL_SHA384 */
  26167. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26168. /* Test for SHA2-512 */
  26169. ret = ecdsa_test_deterministic_k_sig(key, WC_HASH_TYPE_SHA512, msg, rng,
  26170. expSig512, sizeof(expSig512));
  26171. if (ret != 0)
  26172. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26173. #endif /* WOLFSSL_SHA512 */
  26174. done:
  26175. if (key_inited)
  26176. wc_ecc_free(key);
  26177. #ifdef WOLFSSL_SMALL_STACK
  26178. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26179. #endif
  26180. return ret;
  26181. }
  26182. #endif /* NO_ECC256 || HAVE_ALL_CURVES */
  26183. #ifdef WOLFSSL_PUBLIC_MP
  26184. static wc_test_ret_t ecdsa_test_deterministic_k_rs(ecc_key *key,
  26185. enum wc_HashType hashType, const char* msg, WC_RNG* rng,
  26186. mp_int* r, mp_int* s,
  26187. mp_int* expR, mp_int* expS)
  26188. {
  26189. wc_test_ret_t ret;
  26190. unsigned char hash[WC_MAX_DIGEST_SIZE];
  26191. int verify;
  26192. ret = wc_Hash(hashType,
  26193. (byte*)msg, (word32)XSTRLEN(msg),
  26194. hash, sizeof(hash));
  26195. if (ret != 0)
  26196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26197. ret = wc_ecc_sign_hash_ex(hash, wc_HashGetDigestSize(hashType), rng, key,
  26198. r, s);
  26199. #if defined(WOLFSSL_ASYNC_CRYPT)
  26200. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26201. #endif
  26202. if (ret != 0)
  26203. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26204. TEST_SLEEP();
  26205. if (mp_cmp(r, expR) != MP_EQ && mp_cmp(s, expS) != MP_EQ) {
  26206. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26207. }
  26208. /* Verification */
  26209. verify = 0;
  26210. ret = wc_ecc_verify_hash_ex(r, s, hash, wc_HashGetDigestSize(hashType),
  26211. &verify, key);
  26212. #if defined(WOLFSSL_ASYNC_CRYPT)
  26213. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26214. #endif
  26215. if (ret != 0)
  26216. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26217. if (verify != 1) {
  26218. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26219. }
  26220. done:
  26221. return ret;
  26222. }
  26223. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  26224. /* KAT from RFC6979 */
  26225. static wc_test_ret_t ecc384_test_deterministic_k(WC_RNG* rng)
  26226. {
  26227. wc_test_ret_t ret;
  26228. #ifdef WOLFSSL_SMALL_STACK
  26229. ecc_key *key;
  26230. mp_int *r, *s, *expR, *expS;
  26231. #else
  26232. ecc_key key[1];
  26233. mp_int r[1], s[1], expR[1], expS[1];
  26234. #endif
  26235. int key_inited = 0,
  26236. tmp_mp_ints_inited = 0;
  26237. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26238. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26239. "6B9D3DAD2E1B8C1C05B19875B6659F4DE23C3B667BF297BA9AA47740787137D8"
  26240. "96D5724E4C70A825F872C9EA60D2EDF5";
  26241. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26242. "EC3A4E415B4E19A4568618029F427FA5DA9A8BC4AE92E02E06AAE5286B300C64"
  26243. "DEF8F0EA9055866064A254515480BC13";
  26244. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26245. "8015D9B72D7D57244EA8EF9AC0C621896708A59367F9DFB9F54CA84B3F1C9DB1"
  26246. "288B231C3AE0D4FE7344FD2533264720";
  26247. #ifndef NO_SHA256
  26248. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26249. "21B13D1E013C7FA1392D03C5F99AF8B30C570C6F98D4EA8E354B63A21D3DAA33"
  26250. "BDE1E888E63355D92FA2B3C36D8FB2CD";
  26251. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26252. "F3AA443FB107745BF4BD77CB3891674632068A10CA67E3D45DB2266FA7D1FEEB"
  26253. "EFDC63ECCD1AC42EC0CB8668A4FA0AB0";
  26254. #endif
  26255. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26256. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26257. "94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C"
  26258. "81A648152E44ACF96E36DD1E80FABE46";
  26259. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26260. "99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94F"
  26261. "A329C145786E679E7B82C71A38628AC8";
  26262. #endif
  26263. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26264. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26265. "ED0959D5880AB2D869AE7F6C2915C6D60F96507F9CB3E047C0046861DA4A799C"
  26266. "FE30F35CC900056D7C99CD7882433709";
  26267. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26268. "512C8CCEEE3890A84058CE1E22DBC2198F42323CE8ACA9135329F03C068E5112"
  26269. "DC7CC3EF3446DEFCEB01A45C2667FDD5";
  26270. #endif
  26271. #ifdef WOLFSSL_SMALL_STACK
  26272. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26273. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26274. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26275. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26276. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26277. if ((key == NULL) ||
  26278. (r == NULL) ||
  26279. (s == NULL) ||
  26280. (expR == NULL) ||
  26281. (expS == NULL))
  26282. {
  26283. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  26284. }
  26285. #endif
  26286. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26287. if (ret != MP_OKAY)
  26288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26289. tmp_mp_ints_inited = 1;
  26290. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26291. if (ret != 0)
  26292. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26293. key_inited = 1;
  26294. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP384R1");
  26295. if (ret != 0)
  26296. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26297. ret = wc_ecc_set_deterministic(key, 1);
  26298. if (ret != 0)
  26299. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26300. #ifndef NO_SHA256
  26301. /* Test for SHA2-256 */
  26302. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26303. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26304. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26305. r, s, expR, expS);
  26306. if (ret != 0)
  26307. ERROR_OUT(ret, done);
  26308. #endif /* NO_SHA256 */
  26309. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26310. /* Test for SHA2-384 */
  26311. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26312. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26313. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26314. r, s, expR, expS);
  26315. if (ret != 0)
  26316. ERROR_OUT(ret, done);
  26317. #endif /* WOLFSSL_SHA384 */
  26318. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26319. /* Test for SHA2-512 */
  26320. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26321. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26322. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26323. r, s, expR, expS);
  26324. if (ret != 0)
  26325. ERROR_OUT(ret, done);
  26326. #endif /* WOLFSSL_SHA512 */
  26327. done:
  26328. if (key_inited)
  26329. wc_ecc_free(key);
  26330. if (tmp_mp_ints_inited) {
  26331. mp_free(r);
  26332. mp_free(s);
  26333. mp_free(expR);
  26334. mp_free(expS);
  26335. }
  26336. #ifdef WOLFSSL_SMALL_STACK
  26337. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26338. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26339. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26340. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26341. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26342. #endif
  26343. return ret;
  26344. }
  26345. #endif /* HAVE_ECC384 */
  26346. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  26347. /* KAT from RFC6979 */
  26348. static wc_test_ret_t ecc521_test_deterministic_k(WC_RNG* rng)
  26349. {
  26350. wc_test_ret_t ret;
  26351. #ifdef WOLFSSL_SMALL_STACK
  26352. ecc_key *key;
  26353. mp_int *r, *s, *expR, *expS;
  26354. #else
  26355. ecc_key key[1];
  26356. mp_int r[1], s[1], expR[1], expS[1];
  26357. #endif
  26358. int key_inited = 0,
  26359. tmp_mp_ints_inited = 0;
  26360. WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
  26361. WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
  26362. "0FAD06DAA62BA3B25D2FB40133DA757205DE67F5BB0018FEE8C86E1B68C7E75C"
  26363. "AA896EB32F1F47C70855836A6D16FCC1466F6D8FBEC67DB89EC0C08B0E996B83"
  26364. "538";
  26365. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx =
  26366. "1894550D0785932E00EAA23B694F213F8C3121F86DC97A04E5A7167DB4E5BCD3"
  26367. "71123D46E45DB6B5D5370A7F20FB633155D38FFA16D2BD761DCAC474B9A2F502"
  26368. "3A4";
  26369. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy =
  26370. "0493101C962CD4D2FDDF782285E64584139C2F91B47F87FF82354D6630F746A2"
  26371. "8A0DB25741B5B34A828008B22ACC23F924FAAFBD4D33F81EA66956DFEAA2BFDF"
  26372. "CF5";
  26373. #ifndef NO_SHA256
  26374. WOLFSSL_SMALL_STACK_STATIC const char* expRstr256 =
  26375. "1511BB4D675114FE266FC4372B87682BAECC01D3CC62CF2303C92B3526012659"
  26376. "D16876E25C7C1E57648F23B73564D67F61C6F14D527D54972810421E7D87589E"
  26377. "1A7";
  26378. WOLFSSL_SMALL_STACK_STATIC const char* expSstr256 =
  26379. "04A171143A83163D6DF460AAF61522695F207A58B95C0644D87E52AA1A347916"
  26380. "E4F7A72930B1BC06DBE22CE3F58264AFD23704CBB63B29B931F7DE6C9D949A7E"
  26381. "CFC";
  26382. #endif
  26383. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26384. WOLFSSL_SMALL_STACK_STATIC const char* expRstr384 =
  26385. "1EA842A0E17D2DE4F92C15315C63DDF72685C18195C2BB95E572B9C5136CA4B4"
  26386. "B576AD712A52BE9730627D16054BA40CC0B8D3FF035B12AE75168397F5D50C67"
  26387. "451";
  26388. WOLFSSL_SMALL_STACK_STATIC const char* expSstr384 =
  26389. "1F21A3CEE066E1961025FB048BD5FE2B7924D0CD797BABE0A83B66F1E35EEAF5"
  26390. "FDE143FA85DC394A7DEE766523393784484BDF3E00114A1C857CDE1AA203DB65"
  26391. "D61";
  26392. #endif
  26393. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26394. WOLFSSL_SMALL_STACK_STATIC const char* expRstr512 =
  26395. "0C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F1"
  26396. "74E25A1EE9017B5D450606ADD152B534931D7D4E8455CC91F9B15BF05EC36E37"
  26397. "7FA";
  26398. WOLFSSL_SMALL_STACK_STATIC const char* expSstr512 =
  26399. "0617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF2"
  26400. "82623EAA63E5B5C0723D8B8C37FF0777B1A20F8CCB1DCCC43997F1EE0E44DA4A"
  26401. "67A";
  26402. #endif
  26403. #ifdef WOLFSSL_SMALL_STACK
  26404. key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26405. r = (mp_int *)XMALLOC(sizeof(*r), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26406. s = (mp_int *)XMALLOC(sizeof(*s), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26407. expR = (mp_int *)XMALLOC(sizeof(*expR), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26408. expS = (mp_int *)XMALLOC(sizeof(*expS), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26409. if ((key == NULL) ||
  26410. (r == NULL) ||
  26411. (s == NULL) ||
  26412. (expR == NULL) ||
  26413. (expS == NULL))
  26414. {
  26415. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26416. goto done;
  26417. }
  26418. #endif
  26419. ret = mp_init_multi(r, s, expR, expS, NULL, NULL);
  26420. if (ret != MP_OKAY)
  26421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26422. tmp_mp_ints_inited = 1;
  26423. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26424. if (ret != 0)
  26425. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26426. key_inited = 1;
  26427. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP521R1");
  26428. if (ret != 0)
  26429. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26430. ret = wc_ecc_set_deterministic(key, 1);
  26431. if (ret != 0)
  26432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26433. #ifndef NO_SHA256
  26434. /* Test for SHA2-256 */
  26435. mp_read_radix(expR, expRstr256, MP_RADIX_HEX);
  26436. mp_read_radix(expS, expSstr256, MP_RADIX_HEX);
  26437. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA256, msg, rng,
  26438. r, s, expR, expS);
  26439. if (ret != 0)
  26440. ERROR_OUT(ret, done);
  26441. #endif /* NO_SHA256 */
  26442. #if defined(WOLFSSL_SHA384) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26443. /* Test for SHA2-384 */
  26444. mp_read_radix(expR, expRstr384, MP_RADIX_HEX);
  26445. mp_read_radix(expS, expSstr384, MP_RADIX_HEX);
  26446. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA384, msg, rng,
  26447. r, s, expR, expS);
  26448. if (ret != 0)
  26449. ERROR_OUT(ret, done);
  26450. #endif /* WOLFSSL_SHA384 */
  26451. #if defined(WOLFSSL_SHA512) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6,0))
  26452. /* Test for SHA2-512 */
  26453. mp_read_radix(expR, expRstr512, MP_RADIX_HEX);
  26454. mp_read_radix(expS, expSstr512, MP_RADIX_HEX);
  26455. ret = ecdsa_test_deterministic_k_rs(key, WC_HASH_TYPE_SHA512, msg, rng,
  26456. r, s, expR, expS);
  26457. if (ret != 0)
  26458. ERROR_OUT(ret, done);
  26459. #endif /* WOLFSSL_SHA512 */
  26460. done:
  26461. if (key_inited)
  26462. wc_ecc_free(key);
  26463. if (tmp_mp_ints_inited) {
  26464. mp_free(r);
  26465. mp_free(s);
  26466. mp_free(expR);
  26467. mp_free(expS);
  26468. }
  26469. #ifdef WOLFSSL_SMALL_STACK
  26470. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26471. XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26472. XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26473. XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26474. XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26475. #endif
  26476. return ret;
  26477. }
  26478. #endif /* HAVE_ECC521 */
  26479. #endif /* WOLFSSL_PUBLIC_MP */
  26480. #endif /* HAVE_ECC_SIGN && (WOLFSSL_ECDSA_DETERMINISTIC_K ||
  26481. WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)
  26482. && (!HAVE_FIPS || FIPS_VERSION_GE(5,3)) */
  26483. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  26484. !defined(WOLFSSL_KCAPI_ECC)
  26485. static wc_test_ret_t ecc_test_sign_vectors(WC_RNG* rng)
  26486. {
  26487. wc_test_ret_t ret;
  26488. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26489. ecc_key *key = NULL;
  26490. #else
  26491. ecc_key key[1];
  26492. #endif
  26493. int key_inited = 0;
  26494. byte sig[72];
  26495. word32 sigSz;
  26496. WOLFSSL_SMALL_STACK_STATIC const unsigned char hash[32] = "test wolfSSL deterministic sign";
  26497. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26498. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26499. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26500. WOLFSSL_SMALL_STACK_STATIC const byte k[1] = { 0x02 };
  26501. WOLFSSL_SMALL_STACK_STATIC const byte expSig[71] = {
  26502. 0x30, 0x45, 0x02, 0x20, 0x7c, 0xf2, 0x7b, 0x18,
  26503. 0x8d, 0x03, 0x4f, 0x7e, 0x8a, 0x52, 0x38, 0x03,
  26504. 0x04, 0xb5, 0x1a, 0xc3, 0xc0, 0x89, 0x69, 0xe2,
  26505. 0x77, 0xf2, 0x1b, 0x35, 0xa6, 0x0b, 0x48, 0xfc,
  26506. 0x47, 0x66, 0x99, 0x78, 0x02, 0x21, 0x00, 0xa8,
  26507. 0x43, 0xa0, 0xce, 0x6c, 0x5e, 0x17, 0x8a, 0x53,
  26508. 0x4d, 0xaf, 0xd2, 0x95, 0x78, 0x9f, 0x84, 0x4f,
  26509. 0x94, 0xb8, 0x75, 0xa3, 0x19, 0xa5, 0xd4, 0xdf,
  26510. 0xe1, 0xd4, 0x5e, 0x9d, 0x97, 0xfe, 0x81
  26511. };
  26512. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26513. if ((key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  26514. return MEMORY_E;
  26515. #endif
  26516. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  26517. if (ret != 0)
  26518. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26519. key_inited = 1;
  26520. ret = wc_ecc_import_raw(key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26521. if (ret != 0)
  26522. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26523. #if (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) \
  26524. && (HAVE_FIPS_VERSION > 2)))
  26525. wc_ecc_set_flags(key, WC_ECC_FLAG_DEC_SIGN);
  26526. #endif
  26527. ret = wc_ecc_sign_set_k(k, sizeof(k), key);
  26528. if (ret != 0)
  26529. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26530. sigSz = sizeof(sig);
  26531. do {
  26532. #if defined(WOLFSSL_ASYNC_CRYPT)
  26533. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26534. #endif
  26535. if (ret == 0)
  26536. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26537. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26538. if (ret != 0)
  26539. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26540. TEST_SLEEP();
  26541. if (sigSz != sizeof(expSig)) {
  26542. ret = WC_TEST_RET_ENC_NC;
  26543. goto done;
  26544. }
  26545. if (XMEMCMP(sig, expSig, sigSz) != 0) {
  26546. ret = WC_TEST_RET_ENC_NC;
  26547. goto done;
  26548. }
  26549. sigSz = sizeof(sig);
  26550. do {
  26551. #if defined(WOLFSSL_ASYNC_CRYPT)
  26552. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26553. #endif
  26554. if (ret == 0)
  26555. ret = wc_ecc_sign_hash(hash, sizeof(hash), sig, &sigSz, rng, key);
  26556. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26557. if (ret != 0)
  26558. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26559. TEST_SLEEP();
  26560. done:
  26561. if (key_inited)
  26562. wc_ecc_free(key);
  26563. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26564. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26565. #endif
  26566. return ret;
  26567. }
  26568. #endif
  26569. #if defined(HAVE_ECC_CDH) && defined(HAVE_ECC_DHE)
  26570. static wc_test_ret_t ecc_test_cdh_vectors(WC_RNG* rng)
  26571. {
  26572. wc_test_ret_t ret;
  26573. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26574. ecc_key *pub_key = (ecc_key *)XMALLOC(sizeof *pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26575. ecc_key *priv_key = (ecc_key *)XMALLOC(sizeof *priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26576. #else
  26577. ecc_key pub_key[1], priv_key[1];
  26578. #endif
  26579. byte sharedA[32] = {0}, sharedB[32] = {0};
  26580. word32 x, z;
  26581. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
  26582. WOLFSSL_SMALL_STACK_STATIC const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
  26583. WOLFSSL_SMALL_STACK_STATIC const char* dIUT = "7d7dc5f71eb29ddaf80d6214632eeae03d9058af1fb6d22ed80badb62bc1a534";
  26584. WOLFSSL_SMALL_STACK_STATIC const char* QIUTx = "ead218590119e8876b29146ff89ca61770c4edbbf97d38ce385ed281d8a6b230";
  26585. WOLFSSL_SMALL_STACK_STATIC const char* QIUTy = "28af61281fd35e2fa7002523acc85a429cb06ee6648325389f59edfce1405141";
  26586. WOLFSSL_SMALL_STACK_STATIC const char* ZIUT = "46fc62106420ff012e54a434fbdd2d25ccc5852060561e68040dd7778997bd7b";
  26587. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26588. if ((pub_key == NULL) ||
  26589. (priv_key == NULL)) {
  26590. ret = WC_TEST_RET_ENC_EC(MEMORY_E);
  26591. goto done;
  26592. }
  26593. #endif
  26594. XMEMSET(pub_key, 0, sizeof *pub_key);
  26595. XMEMSET(priv_key, 0, sizeof *priv_key);
  26596. /* setup private and public keys */
  26597. ret = wc_ecc_init_ex(pub_key, HEAP_HINT, devId);
  26598. if (ret != 0)
  26599. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26600. ret = wc_ecc_init_ex(priv_key, HEAP_HINT, devId);
  26601. if (ret != 0)
  26602. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26603. wc_ecc_set_flags(pub_key, WC_ECC_FLAG_COFACTOR);
  26604. wc_ecc_set_flags(priv_key, WC_ECC_FLAG_COFACTOR);
  26605. ret = wc_ecc_import_raw(pub_key, QCAVSx, QCAVSy, NULL, "SECP256R1");
  26606. if (ret != 0)
  26607. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26608. ret = wc_ecc_import_raw(priv_key, QIUTx, QIUTy, dIUT, "SECP256R1");
  26609. if (ret != 0)
  26610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26611. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26612. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26613. !defined(HAVE_SELFTEST)
  26614. ret = wc_ecc_set_rng(priv_key, rng);
  26615. if (ret != 0)
  26616. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26617. #else
  26618. (void)rng;
  26619. #endif
  26620. /* compute ECC Cofactor shared secret */
  26621. x = sizeof(sharedA);
  26622. do {
  26623. #if defined(WOLFSSL_ASYNC_CRYPT)
  26624. ret = wc_AsyncWait(ret, &priv_key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26625. #endif
  26626. if (ret == 0)
  26627. ret = wc_ecc_shared_secret(priv_key, pub_key, sharedA, &x);
  26628. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26629. if (ret != 0)
  26630. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26631. TEST_SLEEP();
  26632. /* read in expected Z */
  26633. z = sizeof(sharedB);
  26634. ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
  26635. if (ret != 0)
  26636. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26637. /* compare results */
  26638. if (x != z || XMEMCMP(sharedA, sharedB, x)) {
  26639. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26640. }
  26641. done:
  26642. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26643. if (priv_key) {
  26644. wc_ecc_free(priv_key);
  26645. XFREE(priv_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26646. }
  26647. if (pub_key) {
  26648. wc_ecc_free(pub_key);
  26649. XFREE(pub_key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26650. }
  26651. #else
  26652. wc_ecc_free(priv_key);
  26653. wc_ecc_free(pub_key);
  26654. #endif
  26655. return ret;
  26656. }
  26657. #endif /* HAVE_ECC_CDH && HAVE_ECC_DHE */
  26658. #endif /* HAVE_ECC_VECTOR_TEST */
  26659. #ifdef HAVE_ECC_KEY_IMPORT
  26660. /* returns 0 on success */
  26661. static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
  26662. {
  26663. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26664. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26665. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26666. ecc_key *pub = (ecc_key *)XMALLOC(sizeof *pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26667. #endif
  26668. byte *exportBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26669. byte *tmp = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26670. #else
  26671. ecc_key key[1];
  26672. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  26673. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26674. ecc_key pub[1];
  26675. #endif
  26676. byte exportBuf[ECC_BUFSIZE];
  26677. byte tmp[ECC_BUFSIZE];
  26678. #endif
  26679. const byte* msg = (const byte*)"test wolfSSL ECC public gen";
  26680. word32 x;
  26681. word32 tmpSz;
  26682. wc_test_ret_t ret = 0;
  26683. ecc_point* pubPoint = NULL;
  26684. #ifdef HAVE_ECC_VERIFY
  26685. int verify = 0;
  26686. #endif
  26687. #ifdef NO_ASN
  26688. /* private d for eccKeyDerFile / ecc_key_der_256 */
  26689. const byte keyPriv[] = {
  26690. 0x45, 0xB6, 0x69, 0x02, 0x73, 0x9C, 0x6C, 0x85,
  26691. 0xA1, 0x38, 0x5B, 0x72, 0xE8, 0xE8, 0xC7, 0xAC,
  26692. 0xC4, 0x03, 0x8D, 0x53, 0x35, 0x04, 0xFA, 0x6C,
  26693. 0x28, 0xDC, 0x34, 0x8D, 0xE1, 0xA8, 0x09, 0x8C
  26694. };
  26695. #endif
  26696. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26697. if ((key == NULL) ||
  26698. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26699. (pub == NULL) ||
  26700. #endif
  26701. (exportBuf == NULL) ||
  26702. (tmp == NULL))
  26703. ERROR_OUT(MEMORY_E, done);
  26704. #endif
  26705. (void)msg;
  26706. (void)verify;
  26707. (void)exportBuf;
  26708. (void)rng;
  26709. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26710. #ifndef NO_ECC256
  26711. #if defined(USE_CERT_BUFFERS_256)
  26712. {
  26713. XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
  26714. tmpSz = (size_t)sizeof_ecc_key_der_256;
  26715. }
  26716. #elif !defined(NO_FILESYSTEM)
  26717. {
  26718. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  26719. if (!file) {
  26720. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26721. }
  26722. tmpSz = (word32)XFREAD(tmp, 1, ECC_BUFSIZE, file);
  26723. XFCLOSE(file);
  26724. if (tmpSz == 0)
  26725. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26726. }
  26727. #else
  26728. {
  26729. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
  26730. ERROR_OUT(ASN_PARSE_E, done);
  26731. }
  26732. #endif /* USE_CERT_BUFFERS_256 */
  26733. /* import private only then test with */
  26734. ret = wc_ecc_import_private_key(tmp, tmpSz, NULL, 0, NULL);
  26735. if (ret == 0) {
  26736. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26737. }
  26738. ret = wc_ecc_import_private_key(NULL, tmpSz, NULL, 0, key);
  26739. if (ret == 0) {
  26740. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26741. }
  26742. #ifndef NO_ASN
  26743. x = 0;
  26744. ret = wc_EccPrivateKeyDecode(tmp, &x, key, tmpSz);
  26745. if (ret != 0)
  26746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26747. #ifdef HAVE_ECC_KEY_EXPORT
  26748. x = ECC_BUFSIZE;
  26749. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26750. if (ret != 0)
  26751. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26752. /* make private only key */
  26753. wc_ecc_free(key);
  26754. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26755. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26756. if (ret != 0)
  26757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26758. x = ECC_BUFSIZE;
  26759. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26760. if (ret == 0) {
  26761. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26762. }
  26763. #endif /* HAVE_ECC_KEY_EXPORT */
  26764. #else
  26765. /* Load raw private d directly */
  26766. ret = wc_ecc_import_private_key(keyPriv, sizeof(keyPriv), NULL, 0, key);
  26767. #endif /* !NO_ASN */
  26768. ret = wc_ecc_make_pub(NULL, NULL);
  26769. if (ret == 0) {
  26770. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26771. }
  26772. TEST_SLEEP();
  26773. #ifndef WOLFSSL_NO_MALLOC
  26774. pubPoint = wc_ecc_new_point_h(HEAP_HINT);
  26775. if (pubPoint == NULL) {
  26776. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  26777. }
  26778. #if !defined(WOLFSSL_CRYPTOCELL)
  26779. ret = wc_ecc_make_pub(key, pubPoint);
  26780. #if defined(WOLFSSL_ASYNC_CRYPT)
  26781. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  26782. #endif
  26783. if (ret != 0)
  26784. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26785. #endif /* !WOLFSSL_CRYPTOCELL */
  26786. TEST_SLEEP();
  26787. #ifdef HAVE_ECC_KEY_EXPORT
  26788. /* export should still fail, is private only key */
  26789. x = ECC_BUFSIZE;
  26790. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26791. if (ret == 0) {
  26792. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26793. }
  26794. #endif /* HAVE_ECC_KEY_EXPORT */
  26795. #endif /* !WOLFSSL_NO_MALLOC */
  26796. #endif /* !NO_ECC256 */
  26797. /* create a new key since above test for loading key is not supported */
  26798. #if defined(WOLFSSL_CRYPTOCELL) || defined(NO_ECC256) || \
  26799. defined(WOLFSSL_QNX_CAAM) || defined(WOLFSSL_SE050) || \
  26800. defined(WOLFSSL_SECO_CAAM) || defined(WOLFSSL_IMXRT1170_CAAM)
  26801. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  26802. if (ret != 0)
  26803. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26804. #endif
  26805. #if defined(HAVE_ECC_SIGN) && (!defined(ECC_TIMING_RESISTANT) || \
  26806. (defined(ECC_TIMING_RESISTANT) && !defined(WC_NO_RNG))) && \
  26807. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(HAVE_ECC_DETERMINISTIC_K)
  26808. tmpSz = ECC_BUFSIZE;
  26809. ret = 0;
  26810. do {
  26811. #if defined(WOLFSSL_ASYNC_CRYPT)
  26812. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26813. #endif
  26814. if (ret == 0) {
  26815. ret = wc_ecc_sign_hash(msg, (word32)XSTRLEN((const char* )msg), tmp,
  26816. &tmpSz, rng, key);
  26817. }
  26818. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26819. if (ret != 0)
  26820. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26821. TEST_SLEEP();
  26822. #ifdef HAVE_ECC_VERIFY
  26823. /* try verify with private only key */
  26824. ret = 0;
  26825. do {
  26826. #if defined(WOLFSSL_ASYNC_CRYPT)
  26827. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26828. #endif
  26829. if (ret == 0) {
  26830. ret = wc_ecc_verify_hash(tmp, tmpSz, msg,
  26831. (word32)XSTRLEN((const char*)msg), &verify, key);
  26832. }
  26833. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26834. if (ret != 0)
  26835. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26836. if (verify != 1) {
  26837. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26838. }
  26839. TEST_SLEEP();
  26840. #ifdef HAVE_ECC_KEY_EXPORT
  26841. /* exporting the public part should now work */
  26842. x = ECC_BUFSIZE;
  26843. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26844. if (ret != 0)
  26845. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26846. #endif /* HAVE_ECC_KEY_EXPORT */
  26847. #endif /* HAVE_ECC_VERIFY */
  26848. #endif /* HAVE_ECC_SIGN */
  26849. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  26850. /* now test private only key with creating a shared secret */
  26851. x = ECC_BUFSIZE;
  26852. ret = wc_ecc_export_private_only(key, exportBuf, &x);
  26853. if (ret != 0)
  26854. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26855. #if !defined(WOLFSSL_QNX_CAAM) && !defined(WOLFSSL_SE050)
  26856. /* make private only key */
  26857. wc_ecc_free(key);
  26858. wc_ecc_init_ex(key, HEAP_HINT, devId);
  26859. ret = wc_ecc_import_private_key(exportBuf, x, NULL, 0, key);
  26860. if (ret != 0)
  26861. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26862. /* check that public export fails with private only key */
  26863. x = ECC_BUFSIZE;
  26864. ret = wc_ecc_export_x963_ex(key, exportBuf, &x, 0);
  26865. if (ret == 0) {
  26866. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  26867. }
  26868. #endif /* WOLFSSL_QNX_CAAM */
  26869. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  26870. /* make public key for shared secret */
  26871. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  26872. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, pub);
  26873. #ifdef HAVE_ECC_CDH
  26874. wc_ecc_set_flags(key, WC_ECC_FLAG_COFACTOR);
  26875. #endif
  26876. #if defined(WOLFSSL_ASYNC_CRYPT)
  26877. ret = wc_AsyncWait(ret, &pub->asyncDev, WC_ASYNC_FLAG_NONE);
  26878. #endif
  26879. if (ret != 0)
  26880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26881. TEST_SLEEP();
  26882. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  26883. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  26884. !defined(HAVE_SELFTEST)
  26885. ret = wc_ecc_set_rng(key, rng);
  26886. if (ret != 0)
  26887. goto done;
  26888. #endif
  26889. x = ECC_BUFSIZE;
  26890. do {
  26891. #if defined(WOLFSSL_ASYNC_CRYPT)
  26892. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  26893. #endif
  26894. if (ret == 0) {
  26895. ret = wc_ecc_shared_secret(key, pub, exportBuf, &x);
  26896. }
  26897. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  26898. wc_ecc_free(pub);
  26899. if (ret != 0)
  26900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  26901. TEST_SLEEP();
  26902. #endif /* HAVE_ECC_DHE && HAVE_ECC_KEY_EXPORT && !WC_NO_RNG */
  26903. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  26904. ret = 0;
  26905. done:
  26906. wc_ecc_del_point_h(pubPoint, HEAP_HINT);
  26907. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26908. if (key != NULL) {
  26909. wc_ecc_free(key);
  26910. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26911. }
  26912. #if defined(HAVE_ECC_DHE) && defined(HAVE_ECC_KEY_EXPORT)
  26913. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26914. #endif
  26915. XFREE(exportBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26916. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26917. #else
  26918. wc_ecc_free(key);
  26919. #endif
  26920. return ret;
  26921. }
  26922. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26923. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26924. static wc_test_ret_t ecc_test_key_decode(WC_RNG* rng, int keySize)
  26925. {
  26926. wc_test_ret_t ret;
  26927. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26928. ecc_key *eccKey = (ecc_key *)XMALLOC(sizeof *eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26929. byte *tmpBuf = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26930. #else
  26931. ecc_key eccKey[1];
  26932. byte tmpBuf[ECC_BUFSIZE];
  26933. #endif
  26934. word32 tmpSz;
  26935. word32 idx;
  26936. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26937. if ((eccKey == NULL) || (tmpBuf == NULL))
  26938. ERROR_OUT(MEMORY_E, done);
  26939. #endif
  26940. ret = wc_ecc_init(eccKey);
  26941. if (ret != 0) {
  26942. goto done;
  26943. }
  26944. ret = wc_ecc_make_key(rng, keySize, eccKey);
  26945. #if defined(WOLFSSL_ASYNC_CRYPT)
  26946. ret = wc_AsyncWait(ret, &eccKey->asyncDev, WC_ASYNC_FLAG_NONE);
  26947. #endif
  26948. if (ret != 0) {
  26949. goto done;
  26950. }
  26951. tmpSz = ECC_BUFSIZE;
  26952. ret = wc_EccKeyToDer(eccKey, tmpBuf, tmpSz);
  26953. wc_ecc_free(eccKey);
  26954. if (ret < 0) {
  26955. goto done;
  26956. }
  26957. tmpSz = (word32)ret;
  26958. ret = wc_ecc_init(eccKey);
  26959. if (ret != 0) {
  26960. goto done;
  26961. }
  26962. idx = 0;
  26963. ret = wc_EccPrivateKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26964. if (ret != 0) {
  26965. goto done;
  26966. }
  26967. wc_ecc_free(eccKey);
  26968. ret = wc_ecc_init(eccKey);
  26969. if (ret != 0) {
  26970. goto done;
  26971. }
  26972. idx = 0;
  26973. ret = wc_EccPublicKeyDecode(tmpBuf, &idx, eccKey, tmpSz);
  26974. if (ret != 0) {
  26975. goto done;
  26976. }
  26977. ret = 0;
  26978. done:
  26979. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  26980. if (eccKey != NULL) {
  26981. wc_ecc_free(eccKey);
  26982. XFREE(eccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26983. }
  26984. XFREE(tmpBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  26985. #else
  26986. wc_ecc_free(eccKey);
  26987. #endif
  26988. return ret;
  26989. }
  26990. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  26991. #endif /* HAVE_ECC_KEY_IMPORT */
  26992. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && \
  26993. !defined(WC_NO_RNG) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  26994. static wc_test_ret_t ecc_test_key_gen(WC_RNG* rng, int keySize)
  26995. {
  26996. wc_test_ret_t ret = 0;
  26997. int derSz;
  26998. #ifdef HAVE_PKCS8
  26999. word32 pkcs8Sz;
  27000. #endif
  27001. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27002. byte *der = (byte *)XMALLOC(ECC_BUFSIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27003. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27004. #else
  27005. byte der[ECC_BUFSIZE];
  27006. ecc_key userA[1];
  27007. #endif
  27008. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27009. if ((der == NULL) || (userA == NULL))
  27010. ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), done);
  27011. #endif
  27012. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27013. if (ret != 0)
  27014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27015. ret = wc_ecc_make_key(rng, keySize, userA);
  27016. #if defined(WOLFSSL_ASYNC_CRYPT)
  27017. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27018. #endif
  27019. if (ret != 0)
  27020. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27021. TEST_SLEEP();
  27022. ret = wc_ecc_check_key(userA);
  27023. if (ret != 0)
  27024. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27025. TEST_SLEEP();
  27026. derSz = wc_EccKeyToDer(userA, der, ECC_BUFSIZE);
  27027. if (derSz < 0) {
  27028. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27029. }
  27030. ret = SaveDerAndPem(der, derSz, eccCaKeyTempFile, eccCaKeyPemFile,
  27031. ECC_PRIVATEKEY_TYPE);
  27032. if (ret != 0)
  27033. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27034. /* test export of public key */
  27035. derSz = wc_EccPublicKeyToDer(userA, der, ECC_BUFSIZE, 1);
  27036. if (derSz < 0) {
  27037. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27038. }
  27039. if (derSz == 0) {
  27040. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27041. }
  27042. #ifdef HAVE_COMP_KEY
  27043. /* test export of compressed public key */
  27044. derSz = wc_EccPublicKeyToDer_ex(userA, der, ECC_BUFSIZE, 1, 1);
  27045. if (derSz < 0) {
  27046. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27047. }
  27048. if (derSz == 0) {
  27049. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27050. }
  27051. #endif
  27052. ret = SaveDerAndPem(der, derSz, eccPubKeyDerFile, NULL, 0);
  27053. if (ret != 0)
  27054. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27055. #ifdef HAVE_PKCS8
  27056. /* test export of PKCS#8 unencrypted private key */
  27057. pkcs8Sz = FOURK_BUF;
  27058. derSz = wc_EccPrivateKeyToPKCS8(userA, der, &pkcs8Sz);
  27059. if (derSz < 0) {
  27060. ERROR_OUT(WC_TEST_RET_ENC_I(derSz), done);
  27061. }
  27062. if (derSz == 0) {
  27063. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27064. }
  27065. ret = SaveDerAndPem(der, derSz, eccPkcs8KeyDerFile, NULL, 0);
  27066. if (ret != 0) {
  27067. goto done;
  27068. }
  27069. #endif /* HAVE_PKCS8 */
  27070. done:
  27071. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27072. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27073. if (userA != NULL) {
  27074. wc_ecc_free(userA);
  27075. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27076. }
  27077. #else
  27078. wc_ecc_free(userA);
  27079. #endif
  27080. return ret;
  27081. }
  27082. #endif /* HAVE_ECC_KEY_EXPORT && !NO_ASN_CRYPT */
  27083. static wc_test_ret_t ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount,
  27084. int curve_id, const ecc_set_type* dp)
  27085. {
  27086. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27087. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27088. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27089. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27090. word32 y;
  27091. #endif
  27092. #ifdef HAVE_ECC_KEY_EXPORT
  27093. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  27094. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27095. #endif
  27096. word32 x = 0;
  27097. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27098. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27099. defined(HAVE_ECC_SIGN)
  27100. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27101. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27102. int i;
  27103. #ifdef HAVE_ECC_VERIFY
  27104. int verify;
  27105. #endif /* HAVE_ECC_VERIFY */
  27106. #endif /* HAVE_ECC_SIGN */
  27107. wc_test_ret_t ret;
  27108. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27109. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27110. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27111. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27112. #else
  27113. ecc_key userA[1];
  27114. ecc_key userB[1];
  27115. ecc_key pubKey[1];
  27116. #endif
  27117. #ifndef WC_NO_RNG
  27118. int curveSize;
  27119. #endif
  27120. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27121. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27122. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27123. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  27124. #endif
  27125. #ifdef HAVE_ECC_KEY_EXPORT
  27126. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  27127. #endif
  27128. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27129. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27130. defined(HAVE_ECC_SIGN)
  27131. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  27132. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  27133. #endif
  27134. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  27135. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG) && \
  27136. !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27137. if (sharedA == NULL || sharedB == NULL)
  27138. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27139. #endif
  27140. #ifdef HAVE_ECC_KEY_EXPORT
  27141. if (exportBuf == NULL)
  27142. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27143. #endif
  27144. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27145. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC)) && \
  27146. defined(HAVE_ECC_SIGN)
  27147. if (sig == NULL || digest == NULL)
  27148. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27149. #endif
  27150. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  27151. (void)testVerifyCount;
  27152. (void)dp;
  27153. (void)x;
  27154. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27155. if ((userA == NULL) ||
  27156. (userB == NULL) ||
  27157. (pubKey == NULL))
  27158. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27159. #endif
  27160. XMEMSET(userA, 0, sizeof *userA);
  27161. XMEMSET(userB, 0, sizeof *userB);
  27162. XMEMSET(pubKey, 0, sizeof *pubKey);
  27163. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  27164. if (ret != 0)
  27165. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27166. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  27167. if (ret != 0)
  27168. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27169. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27170. if (ret != 0)
  27171. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27172. #ifdef WOLFSSL_CUSTOM_CURVES
  27173. if (dp != NULL) {
  27174. ret = wc_ecc_set_custom_curve(userA, dp);
  27175. if (ret != 0)
  27176. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27177. ret = wc_ecc_set_custom_curve(userB, dp);
  27178. if (ret != 0)
  27179. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27180. }
  27181. #endif
  27182. #ifndef WC_NO_RNG
  27183. ret = wc_ecc_make_key_ex(rng, keySize, userA, curve_id);
  27184. #if defined(WOLFSSL_ASYNC_CRYPT)
  27185. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  27186. #endif
  27187. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  27188. if (ret == WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  27189. ret = 0;
  27190. goto done; /* no software case */
  27191. }
  27192. #endif
  27193. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  27194. goto done; /* catch case, where curve is not supported */
  27195. if (ret != 0)
  27196. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27197. TEST_SLEEP();
  27198. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  27199. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  27200. if (curveSize != userA->dp->size)
  27201. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27202. }
  27203. ret = wc_ecc_check_key(userA);
  27204. if (ret != 0)
  27205. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27206. TEST_SLEEP();
  27207. /* ATECC508/608 configuration may not support more than one ECDH key */
  27208. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27209. ret = wc_ecc_make_key_ex(rng, keySize, userB, curve_id);
  27210. #if defined(WOLFSSL_ASYNC_CRYPT)
  27211. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  27212. #endif
  27213. if (ret != 0)
  27214. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27215. TEST_SLEEP();
  27216. /* only perform the below tests if the key size matches */
  27217. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  27218. /* Not an error, just not a key size match */
  27219. WARNING_OUT(ECC_CURVE_OID_E, done);
  27220. #ifdef HAVE_ECC_DHE
  27221. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  27222. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  27223. !defined(HAVE_SELFTEST)
  27224. ret = wc_ecc_set_rng(userA, rng);
  27225. if (ret != 0)
  27226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27227. ret = wc_ecc_set_rng(userB, rng);
  27228. if (ret != 0)
  27229. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27230. #endif
  27231. x = ECC_SHARED_SIZE;
  27232. do {
  27233. #if defined(WOLFSSL_ASYNC_CRYPT)
  27234. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27235. #endif
  27236. if (ret == 0)
  27237. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27238. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27239. if (ret != 0)
  27240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27241. TEST_SLEEP();
  27242. y = ECC_SHARED_SIZE;
  27243. do {
  27244. #if defined(WOLFSSL_ASYNC_CRYPT)
  27245. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27246. #endif
  27247. if (ret == 0)
  27248. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27249. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27250. if (ret != 0)
  27251. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27252. if (y != x)
  27253. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27254. if (XMEMCMP(sharedA, sharedB, x))
  27255. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27256. TEST_SLEEP();
  27257. #ifdef HAVE_ECC_CDH
  27258. /* add cofactor flag */
  27259. wc_ecc_set_flags(userA, WC_ECC_FLAG_COFACTOR);
  27260. wc_ecc_set_flags(userB, WC_ECC_FLAG_COFACTOR);
  27261. x = ECC_SHARED_SIZE;
  27262. do {
  27263. #if defined(WOLFSSL_ASYNC_CRYPT)
  27264. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27265. #endif
  27266. if (ret == 0)
  27267. ret = wc_ecc_shared_secret(userA, userB, sharedA, &x);
  27268. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27269. if (ret != 0)
  27270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27271. TEST_SLEEP();
  27272. y = ECC_SHARED_SIZE;
  27273. do {
  27274. #if defined(WOLFSSL_ASYNC_CRYPT)
  27275. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27276. #endif
  27277. if (ret == 0)
  27278. ret = wc_ecc_shared_secret(userB, userA, sharedB, &y);
  27279. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27280. if (ret != 0)
  27281. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27282. if (y != x)
  27283. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27284. if (XMEMCMP(sharedA, sharedB, x))
  27285. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27286. TEST_SLEEP();
  27287. /* remove cofactor flag */
  27288. wc_ecc_set_flags(userA, 0);
  27289. wc_ecc_set_flags(userB, 0);
  27290. #endif /* HAVE_ECC_CDH */
  27291. #endif /* HAVE_ECC_DHE */
  27292. #endif /* !WOLFSSL_ATECC508A && WOLFSSL_ATECC608A */
  27293. #ifdef HAVE_ECC_KEY_EXPORT
  27294. x = ECC_KEY_EXPORT_BUF_SIZE;
  27295. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  27296. if (ret != 0)
  27297. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27298. #ifdef HAVE_ECC_KEY_IMPORT
  27299. #ifdef WOLFSSL_CUSTOM_CURVES
  27300. if (dp != NULL) {
  27301. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27302. if (ret != 0)
  27303. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27304. }
  27305. #endif
  27306. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27307. if (ret != 0)
  27308. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27309. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
  27310. #ifdef HAVE_ECC_DHE
  27311. y = ECC_SHARED_SIZE;
  27312. do {
  27313. #if defined(WOLFSSL_ASYNC_CRYPT)
  27314. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27315. #endif
  27316. if (ret == 0)
  27317. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27318. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27319. if (ret != 0)
  27320. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27321. if (XMEMCMP(sharedA, sharedB, y))
  27322. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27323. TEST_SLEEP();
  27324. #endif /* HAVE_ECC_DHE */
  27325. #ifdef HAVE_COMP_KEY
  27326. /* try compressed export / import too */
  27327. x = ECC_KEY_EXPORT_BUF_SIZE;
  27328. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  27329. if (ret != 0)
  27330. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27331. wc_ecc_free(pubKey);
  27332. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  27333. if (ret != 0)
  27334. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27335. #ifdef WOLFSSL_CUSTOM_CURVES
  27336. if (dp != NULL) {
  27337. ret = wc_ecc_set_custom_curve(pubKey, dp);
  27338. if (ret != 0)
  27339. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27340. }
  27341. #endif
  27342. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  27343. if (ret != 0)
  27344. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27345. #ifdef HAVE_ECC_DHE
  27346. y = ECC_SHARED_SIZE;
  27347. do {
  27348. #if defined(WOLFSSL_ASYNC_CRYPT)
  27349. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27350. #endif
  27351. if (ret == 0)
  27352. ret = wc_ecc_shared_secret(userB, pubKey, sharedB, &y);
  27353. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27354. if (ret != 0)
  27355. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27356. if (XMEMCMP(sharedA, sharedB, y))
  27357. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27358. TEST_SLEEP();
  27359. #endif /* HAVE_ECC_DHE */
  27360. #endif /* HAVE_COMP_KEY */
  27361. #endif /* !WOLFSSL_ATECC508A && !WOLFSSL_ATECC608A */
  27362. #endif /* !WC_NO_RNG */
  27363. #endif /* HAVE_ECC_KEY_IMPORT */
  27364. #endif /* HAVE_ECC_KEY_EXPORT */
  27365. /* For KCAPI cannot sign using generated ECDH key */
  27366. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  27367. !defined(WC_NO_RNG) && !defined(WOLFSSL_KCAPI_ECC))
  27368. #ifdef HAVE_ECC_SIGN
  27369. /* some hardware doesn't support sign/verify of all zero digest */
  27370. #if !defined(WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST)
  27371. /* test DSA sign hash with zeros */
  27372. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27373. digest[i] = 0;
  27374. }
  27375. x = ECC_SIG_SIZE;
  27376. do {
  27377. #if defined(WOLFSSL_ASYNC_CRYPT)
  27378. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27379. #endif
  27380. if (ret == 0)
  27381. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng,
  27382. userA);
  27383. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27384. if (ret != 0)
  27385. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27386. TEST_SLEEP();
  27387. #ifdef HAVE_ECC_VERIFY
  27388. for (i=0; i<testVerifyCount; i++) {
  27389. verify = 0;
  27390. do {
  27391. #if defined(WOLFSSL_ASYNC_CRYPT)
  27392. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27393. #endif
  27394. if (ret == 0)
  27395. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE,
  27396. &verify, userA);
  27397. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27398. if (ret != 0)
  27399. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27400. if (verify != 1)
  27401. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27402. TEST_SLEEP();
  27403. }
  27404. #endif /* HAVE_ECC_VERIFY */
  27405. #endif /* !WC_TEST_NO_ECC_SIGN_VERIFY_ZERO_DIGEST */
  27406. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  27407. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  27408. digest[i] = (byte)i;
  27409. }
  27410. x = ECC_SIG_SIZE;
  27411. do {
  27412. #if defined(WOLFSSL_ASYNC_CRYPT)
  27413. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27414. #endif
  27415. if (ret == 0)
  27416. ret = wc_ecc_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  27417. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27418. if (ret != 0)
  27419. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27420. TEST_SLEEP();
  27421. #ifdef HAVE_ECC_VERIFY
  27422. for (i=0; i<testVerifyCount; i++) {
  27423. verify = 0;
  27424. do {
  27425. #if defined(WOLFSSL_ASYNC_CRYPT)
  27426. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  27427. #endif
  27428. if (ret == 0)
  27429. ret = wc_ecc_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify, userA);
  27430. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  27431. if (ret != 0)
  27432. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27433. if (verify != 1)
  27434. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  27435. TEST_SLEEP();
  27436. }
  27437. #endif /* HAVE_ECC_VERIFY */
  27438. #endif /* HAVE_ECC_SIGN */
  27439. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT &&
  27440. * !WC_NO_RNG && !WOLFSSL_KCAPI_ECC) */
  27441. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG) && \
  27442. !defined(WOLFSSL_ATECC508) && !defined(WOLFSSL_ATECC608A) && \
  27443. !defined(WOLFSSL_KCAPI_ECC)
  27444. x = ECC_KEY_EXPORT_BUF_SIZE;
  27445. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  27446. if (ret != 0)
  27447. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27448. #elif defined(HAVE_ECC_KEY_EXPORT)
  27449. (void)exportBuf;
  27450. #endif /* HAVE_ECC_KEY_EXPORT */
  27451. done:
  27452. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27453. if (userA != NULL) {
  27454. wc_ecc_free(userA);
  27455. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27456. }
  27457. if (userB != NULL) {
  27458. wc_ecc_free(userB);
  27459. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27460. }
  27461. if (pubKey != NULL) {
  27462. wc_ecc_free(pubKey);
  27463. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27464. }
  27465. #else
  27466. wc_ecc_free(pubKey);
  27467. wc_ecc_free(userB);
  27468. wc_ecc_free(userA);
  27469. #endif
  27470. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  27471. WC_FREE_VAR(sharedA, HEAP_HINT);
  27472. WC_FREE_VAR(sharedB, HEAP_HINT);
  27473. #endif
  27474. #ifdef HAVE_ECC_KEY_EXPORT
  27475. WC_FREE_VAR(exportBuf, HEAP_HINT);
  27476. #endif
  27477. #ifdef HAVE_ECC_SIGN
  27478. WC_FREE_VAR(sig, HEAP_HINT);
  27479. WC_FREE_VAR(digest, HEAP_HINT);
  27480. #endif
  27481. (void)keySize;
  27482. (void)curve_id;
  27483. (void)rng;
  27484. return ret;
  27485. }
  27486. #undef ECC_TEST_VERIFY_COUNT
  27487. #define ECC_TEST_VERIFY_COUNT 2
  27488. static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
  27489. {
  27490. wc_test_ret_t ret;
  27491. WOLFSSL_MSG_EX("ecc_test_curve keySize = %d", keySize);
  27492. #if FIPS_VERSION3_GE(6,0,0)
  27493. #ifdef DEBUG_WOLFSSL
  27494. printf("keySize is %d\n", keySize);
  27495. #endif
  27496. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27497. goto skip_A;
  27498. }
  27499. #endif
  27500. ret = ecc_test_curve_size(rng, keySize, ECC_TEST_VERIFY_COUNT, curve_id,
  27501. NULL);
  27502. if (ret < 0) {
  27503. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27504. /* ignore error for curves not found */
  27505. /* some curve sizes are only available with:
  27506. HAVE_ECC_SECPR2, HAVE_ECC_SECPR3, HAVE_ECC_BRAINPOOL
  27507. and HAVE_ECC_KOBLITZ */
  27508. }
  27509. else {
  27510. printf("ecc_test_curve_size %d failed!\n", keySize);
  27511. return ret;
  27512. }
  27513. }
  27514. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  27515. #if FIPS_VERSION3_GE(6,0,0)
  27516. skip_A:
  27517. #endif
  27518. #ifdef HAVE_ECC_VECTOR_TEST
  27519. ret = ecc_test_vector(keySize);
  27520. if (ret < 0) {
  27521. printf("ecc_test_vector %d failed!\n", keySize);
  27522. return ret;
  27523. }
  27524. #endif
  27525. #if FIPS_VERSION3_GE(6,0,0)
  27526. if (keySize < WC_ECC_FIPS_GEN_MIN) {
  27527. goto skip_B;
  27528. }
  27529. #endif
  27530. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27531. !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27532. ret = ecc_test_key_decode(rng, keySize);
  27533. if (ret < 0) {
  27534. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27535. /* ignore error for curves not found */
  27536. }
  27537. else {
  27538. printf("ecc_test_key_decode %d failed!\n", keySize);
  27539. return ret;
  27540. }
  27541. }
  27542. #endif
  27543. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
  27544. ret = ecc_test_key_gen(rng, keySize);
  27545. if (ret < 0) {
  27546. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
  27547. /* ignore error for curves not found */
  27548. }
  27549. else {
  27550. printf("ecc_test_key_gen %d failed!\n", keySize);
  27551. return ret;
  27552. }
  27553. }
  27554. #endif
  27555. #if FIPS_VERSION3_GE(6,0,0)
  27556. skip_B:
  27557. #endif
  27558. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  27559. return 0;
  27560. }
  27561. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  27562. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  27563. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27564. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27565. static wc_test_ret_t ecc_point_test(void)
  27566. {
  27567. wc_test_ret_t ret;
  27568. ecc_point* point;
  27569. ecc_point* point2;
  27570. #ifdef HAVE_COMP_KEY
  27571. ecc_point* point3;
  27572. ecc_point* point4;
  27573. #endif
  27574. word32 outLen;
  27575. byte out[65];
  27576. byte der[] = { 0x04, /* = Uncompressed */
  27577. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27578. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27579. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27580. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  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. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27586. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27587. byte derComp0[] = { 0x02, /* = Compressed, y even */
  27588. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27589. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27590. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  27591. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27592. byte derComp1[] = { 0x03, /* = Compressed, y odd */
  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. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
  27597. #endif
  27598. byte altDer[] = { 0x04, /* = Uncompressed */
  27599. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27600. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27601. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  27602. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  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. int curve_idx = wc_ecc_get_curve_idx(ECC_SECP256R1);
  27608. /* if curve P256 is not enabled then test should not fail */
  27609. if (curve_idx == ECC_CURVE_INVALID)
  27610. return 0;
  27611. outLen = sizeof(out);
  27612. point = wc_ecc_new_point();
  27613. if (point == NULL)
  27614. return WC_TEST_RET_ENC_ERRNO;
  27615. point2 = wc_ecc_new_point();
  27616. if (point2 == NULL) {
  27617. wc_ecc_del_point(point);
  27618. return WC_TEST_RET_ENC_NC;
  27619. }
  27620. #ifdef HAVE_COMP_KEY
  27621. point3 = wc_ecc_new_point();
  27622. if (point3 == NULL) {
  27623. wc_ecc_del_point(point2);
  27624. wc_ecc_del_point(point);
  27625. return WC_TEST_RET_ENC_NC;
  27626. }
  27627. point4 = wc_ecc_new_point();
  27628. if (point4 == NULL) {
  27629. wc_ecc_del_point(point3);
  27630. wc_ecc_del_point(point2);
  27631. wc_ecc_del_point(point);
  27632. return WC_TEST_RET_ENC_NC;
  27633. }
  27634. #endif
  27635. /* Parameter Validation testing. */
  27636. wc_ecc_del_point(NULL);
  27637. ret = wc_ecc_import_point_der(NULL, sizeof(der), curve_idx, point);
  27638. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27639. ret = WC_TEST_RET_ENC_EC(ret);
  27640. goto done;
  27641. }
  27642. ret = wc_ecc_import_point_der(der, sizeof(der), ECC_CURVE_INVALID, point);
  27643. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27644. ret = WC_TEST_RET_ENC_EC(ret);
  27645. goto done;
  27646. }
  27647. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, NULL);
  27648. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27649. ret = WC_TEST_RET_ENC_EC(ret);
  27650. goto done;
  27651. }
  27652. ret = wc_ecc_export_point_der(-1, point, out, &outLen);
  27653. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27654. ret = WC_TEST_RET_ENC_EC(ret);
  27655. goto done;
  27656. }
  27657. ret = wc_ecc_export_point_der(curve_idx, NULL, out, &outLen);
  27658. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27659. ret = WC_TEST_RET_ENC_EC(ret);
  27660. goto done;
  27661. }
  27662. ret = wc_ecc_export_point_der(curve_idx, point, NULL, &outLen);
  27663. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E) || outLen != sizeof(out)) {
  27664. ret = WC_TEST_RET_ENC_EC(ret);
  27665. goto done;
  27666. }
  27667. ret = wc_ecc_export_point_der(curve_idx, point, out, NULL);
  27668. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27669. ret = WC_TEST_RET_ENC_EC(ret);
  27670. goto done;
  27671. }
  27672. outLen = 0;
  27673. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27674. if (ret != WC_NO_ERR_TRACE(BUFFER_E)) {
  27675. ret = WC_TEST_RET_ENC_EC(ret);
  27676. goto done;
  27677. }
  27678. ret = wc_ecc_copy_point(NULL, NULL);
  27679. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27680. ret = WC_TEST_RET_ENC_EC(ret);
  27681. goto done;
  27682. }
  27683. ret = wc_ecc_copy_point(NULL, point2);
  27684. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27685. ret = WC_TEST_RET_ENC_EC(ret);
  27686. goto done;
  27687. }
  27688. ret = wc_ecc_copy_point(point, NULL);
  27689. if (ret != WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  27690. ret = WC_TEST_RET_ENC_EC(ret);
  27691. goto done;
  27692. }
  27693. ret = wc_ecc_cmp_point(NULL, NULL);
  27694. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27695. ret = WC_TEST_RET_ENC_EC(ret);
  27696. goto done;
  27697. }
  27698. ret = wc_ecc_cmp_point(NULL, point2);
  27699. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27700. ret = WC_TEST_RET_ENC_EC(ret);
  27701. goto done;
  27702. }
  27703. ret = wc_ecc_cmp_point(point, NULL);
  27704. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  27705. ret = WC_TEST_RET_ENC_EC(ret);
  27706. goto done;
  27707. }
  27708. /* Use API. */
  27709. ret = wc_ecc_import_point_der(der, sizeof(der), curve_idx, point);
  27710. if (ret != 0)
  27711. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27712. outLen = sizeof(out);
  27713. ret = wc_ecc_export_point_der(curve_idx, point, out, &outLen);
  27714. if (ret != 0)
  27715. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27716. if (outLen != sizeof(der)) {
  27717. ret = WC_TEST_RET_ENC_NC;
  27718. goto done;
  27719. }
  27720. if (XMEMCMP(out, der, outLen) != 0) {
  27721. ret = WC_TEST_RET_ENC_NC;
  27722. goto done;
  27723. }
  27724. ret = wc_ecc_copy_point(point2, point);
  27725. if (ret != MP_OKAY) {
  27726. ret = WC_TEST_RET_ENC_EC(ret);
  27727. goto done;
  27728. }
  27729. ret = wc_ecc_cmp_point(point2, point);
  27730. if (ret != MP_EQ) {
  27731. ret = WC_TEST_RET_ENC_EC(ret);
  27732. goto done;
  27733. }
  27734. ret = wc_ecc_import_point_der(altDer, sizeof(altDer), curve_idx, point2);
  27735. if (ret != 0)
  27736. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27737. ret = wc_ecc_cmp_point(point2, point);
  27738. if (ret != MP_GT) {
  27739. ret = WC_TEST_RET_ENC_EC(ret);
  27740. goto done;
  27741. }
  27742. #if defined(HAVE_COMP_KEY) && (!defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) || \
  27743. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2)))
  27744. ret = wc_ecc_import_point_der(derComp0, sizeof(derComp0)*2-1, curve_idx, point3);
  27745. if (ret != 0)
  27746. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27747. ret = wc_ecc_import_point_der_ex(derComp0, sizeof(derComp0), curve_idx, point4, 0);
  27748. if (ret != 0)
  27749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27750. ret = wc_ecc_cmp_point(point3, point4);
  27751. if (ret != MP_EQ) {
  27752. ret = WC_TEST_RET_ENC_EC(ret);
  27753. goto done;
  27754. }
  27755. ret = wc_ecc_import_point_der(derComp1, sizeof(derComp1)*2-1, curve_idx, point3);
  27756. if (ret != 0)
  27757. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27758. ret = wc_ecc_import_point_der_ex(derComp1, sizeof(derComp1), curve_idx, point4, 0);
  27759. if (ret != 0)
  27760. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27761. ret = wc_ecc_cmp_point(point3, point4);
  27762. if (ret != MP_EQ) {
  27763. ret = WC_TEST_RET_ENC_EC(ret);
  27764. goto done;
  27765. }
  27766. #endif
  27767. done:
  27768. #ifdef HAVE_COMP_KEY
  27769. wc_ecc_del_point(point4);
  27770. wc_ecc_del_point(point3);
  27771. #endif
  27772. wc_ecc_del_point(point2);
  27773. wc_ecc_del_point(point);
  27774. return ret;
  27775. }
  27776. #endif /* !WOLFSSL_ATECC508A && HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27777. #if !defined(NO_SIG_WRAPPER) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27778. static wc_test_ret_t ecc_sig_test(WC_RNG* rng, ecc_key* key)
  27779. {
  27780. wc_test_ret_t ret;
  27781. word32 sigSz;
  27782. int size;
  27783. byte out[ECC_MAX_SIG_SIZE];
  27784. byte in[] = TEST_STRING;
  27785. WOLFSSL_SMALL_STACK_STATIC const byte hash[] = {
  27786. 0xf2, 0x02, 0x95, 0x65, 0xcb, 0xf6, 0x2a, 0x59,
  27787. 0x39, 0x2c, 0x05, 0xff, 0x0e, 0x29, 0xaf, 0xfe,
  27788. 0x47, 0x33, 0x8c, 0x99, 0x8d, 0x58, 0x64, 0x83,
  27789. 0xa6, 0x58, 0x0a, 0x33, 0x0b, 0x84, 0x5f, 0x5f
  27790. };
  27791. word32 inLen = (word32)XSTRLEN((char*)in);
  27792. size = wc_ecc_sig_size(key);
  27793. ret = wc_SignatureGetSize(WC_SIGNATURE_TYPE_ECC, key, sizeof(*key));
  27794. if (ret != size)
  27795. return WC_TEST_RET_ENC_NC;
  27796. sigSz = (word32)ret;
  27797. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27798. inLen, out, &sigSz, key, sizeof(*key), rng);
  27799. if (ret != 0)
  27800. return WC_TEST_RET_ENC_EC(ret);
  27801. TEST_SLEEP();
  27802. ret = wc_SignatureVerify(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC, in,
  27803. inLen, out, sigSz, key, sizeof(*key));
  27804. if (ret != 0)
  27805. return WC_TEST_RET_ENC_EC(ret);
  27806. TEST_SLEEP();
  27807. sigSz = (word32)sizeof(out);
  27808. ret = wc_SignatureGenerateHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27809. hash, (int)sizeof(hash), out, &sigSz, key, sizeof(*key), rng);
  27810. if (ret != 0)
  27811. return WC_TEST_RET_ENC_EC(ret);
  27812. TEST_SLEEP();
  27813. ret = wc_SignatureVerifyHash(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_ECC,
  27814. hash, (int)sizeof(hash), out, sigSz, key, sizeof(*key));
  27815. if (ret != 0)
  27816. return WC_TEST_RET_ENC_EC(ret);
  27817. TEST_SLEEP();
  27818. return 0;
  27819. }
  27820. #endif
  27821. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  27822. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27823. static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
  27824. {
  27825. wc_test_ret_t ret;
  27826. int curve_id;
  27827. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27828. ecc_key *keyImp = (ecc_key *)XMALLOC(sizeof *keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27829. #else
  27830. ecc_key keyImp[1];
  27831. #endif
  27832. byte priv[32];
  27833. word32 privLen;
  27834. byte pub[65*2];
  27835. word32 pubLen, pubLenX, pubLenY;
  27836. const char qx[] = "7a4e287890a1a47ad3457e52f2f76a83"
  27837. "ce46cbc947616d0cbaa82323818a793d";
  27838. const char qy[] = "eec4084f5b29ebf29c44cce3b3059610"
  27839. "922f8b30ea6e8811742ac7238fe87308";
  27840. const char d[] = "8c14b793cb19137e323a6d2e2a870bca"
  27841. "2e7a493ec1153b3a95feb8a4873f8d08";
  27842. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27843. if (keyImp == NULL)
  27844. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  27845. #endif
  27846. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27847. privLen = sizeof(priv);
  27848. ret = wc_ecc_export_private_only(key, priv, &privLen);
  27849. if (ret != 0)
  27850. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27851. pubLen = sizeof(pub);
  27852. ret = wc_ecc_export_point_der(key->idx, &key->pubkey, pub, &pubLen);
  27853. if (ret != 0)
  27854. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27855. ret = wc_ecc_import_private_key(priv, privLen, pub, pubLen, keyImp);
  27856. if (ret != 0)
  27857. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27858. wc_ecc_free(keyImp);
  27859. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27860. ret = wc_ecc_import_raw_ex(keyImp, qx, qy, d, ECC_SECP256R1);
  27861. if (ret != 0)
  27862. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27863. wc_ecc_free(keyImp);
  27864. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27865. curve_id = wc_ecc_get_curve_id(key->idx);
  27866. if (curve_id < 0) {
  27867. ret = WC_TEST_RET_ENC_EC(curve_id);
  27868. goto done;
  27869. }
  27870. /* test import private only */
  27871. ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, keyImp,
  27872. curve_id);
  27873. if (ret != 0)
  27874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27875. wc_ecc_free(keyImp);
  27876. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27877. /* test export public raw */
  27878. pubLenX = pubLenY = 32;
  27879. ret = wc_ecc_export_public_raw(key, pub, &pubLenX, &pub[32], &pubLenY);
  27880. if (ret != 0)
  27881. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27882. #ifndef HAVE_SELFTEST
  27883. /* test import of public */
  27884. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], NULL, ECC_SECP256R1);
  27885. if (ret != 0)
  27886. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27887. #endif
  27888. wc_ecc_free(keyImp);
  27889. wc_ecc_init_ex(keyImp, HEAP_HINT, devId);
  27890. /* test export private and public raw */
  27891. pubLenX = pubLenY = privLen = 32;
  27892. ret = wc_ecc_export_private_raw(key, pub, &pubLenX, &pub[32], &pubLenY,
  27893. priv, &privLen);
  27894. if (ret != 0)
  27895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27896. #ifndef HAVE_SELFTEST
  27897. /* test import of private and public */
  27898. ret = wc_ecc_import_unsigned(keyImp, pub, &pub[32], priv, ECC_SECP256R1);
  27899. if (ret != 0)
  27900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27901. #endif
  27902. done:
  27903. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27904. if (keyImp != NULL) {
  27905. wc_ecc_free(keyImp);
  27906. XFREE(keyImp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27907. }
  27908. #else
  27909. wc_ecc_free(keyImp);
  27910. #endif
  27911. return ret;
  27912. }
  27913. #endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
  27914. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  27915. !defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  27916. static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
  27917. {
  27918. wc_test_ret_t ret;
  27919. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27920. ecc_key *key2 = (ecc_key *)XMALLOC(sizeof *key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27921. ecc_key *key3 = (ecc_key *)XMALLOC(sizeof *key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27922. #else
  27923. ecc_key key2[1];
  27924. ecc_key key3[1];
  27925. #endif
  27926. #ifdef WOLFSSL_PUBLIC_MP
  27927. mp_int* priv;
  27928. #endif
  27929. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27930. if ((key2 == NULL) || (key3 == NULL))
  27931. ERROR_OUT(MEMORY_E, done);
  27932. #endif
  27933. wc_ecc_init_ex(key2, HEAP_HINT, devId);
  27934. wc_ecc_init_ex(key3, HEAP_HINT, devId);
  27935. /* TODO: Use test data, test with WOLFSSL_VALIDATE_ECC_IMPORT. */
  27936. /* Need base point (Gx,Gy) and parameter A - load them as the public and
  27937. * private key in key2.
  27938. */
  27939. ret = wc_ecc_import_raw_ex(key2, key1->dp->Gx, key1->dp->Gy, key1->dp->Af,
  27940. ECC_SECP256R1);
  27941. if (ret != 0)
  27942. goto done;
  27943. /* Need a point (Gx,Gy) and prime - load them as the public and private key
  27944. * in key3.
  27945. */
  27946. ret = wc_ecc_import_raw_ex(key3, key1->dp->Gx, key1->dp->Gy,
  27947. key1->dp->prime, ECC_SECP256R1);
  27948. if (ret != 0)
  27949. goto done;
  27950. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27951. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27952. 1);
  27953. if (ret != 0)
  27954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27955. #ifdef WOLFSSL_PUBLIC_MP
  27956. priv = wc_ecc_key_get_priv(key1);
  27957. mp_zero(priv);
  27958. ret = wc_ecc_mulmod(wc_ecc_key_get_priv(key1), &key2->pubkey, &key3->pubkey,
  27959. wc_ecc_key_get_priv(key2), wc_ecc_key_get_priv(key3),
  27960. 1);
  27961. if (ret != 0)
  27962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  27963. if (!wc_ecc_point_is_at_infinity(&key3->pubkey)) {
  27964. ret = WC_TEST_RET_ENC_EC(ret);
  27965. goto done;
  27966. }
  27967. if (mp_cmp_d(key3->pubkey.z, 1) != MP_EQ) {
  27968. ret = WC_TEST_RET_ENC_EC(ret);
  27969. goto done;
  27970. }
  27971. #endif
  27972. done:
  27973. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  27974. if (key2 != NULL) {
  27975. wc_ecc_free(key2);
  27976. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27977. }
  27978. if (key3 != NULL) {
  27979. wc_ecc_free(key3);
  27980. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  27981. }
  27982. #else
  27983. wc_ecc_free(key3);
  27984. wc_ecc_free(key2);
  27985. #endif
  27986. return ret;
  27987. }
  27988. #endif
  27989. #if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
  27990. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
  27991. !defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
  27992. !defined(WOLFSSL_CRYPTOCELL)
  27993. static wc_test_ret_t ecc_ssh_test(ecc_key* key, WC_RNG* rng)
  27994. {
  27995. wc_test_ret_t ret;
  27996. byte out[128];
  27997. word32 outLen = sizeof(out);
  27998. /* Parameter Validation testing. */
  27999. ret = wc_ecc_shared_secret_ssh(NULL, &key->pubkey, out, &outLen);
  28000. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28001. return WC_TEST_RET_ENC_EC(ret);
  28002. ret = wc_ecc_shared_secret_ssh(key, NULL, out, &outLen);
  28003. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28004. return WC_TEST_RET_ENC_EC(ret);
  28005. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, NULL, &outLen);
  28006. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28007. return WC_TEST_RET_ENC_EC(ret);
  28008. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, NULL);
  28009. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  28010. return WC_TEST_RET_ENC_EC(ret);
  28011. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  28012. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  28013. !defined(HAVE_SELFTEST)
  28014. ret = wc_ecc_set_rng(key, rng);
  28015. if (ret != 0)
  28016. return WC_TEST_RET_ENC_EC(ret);
  28017. #else
  28018. (void)rng;
  28019. #endif
  28020. /* Use API. */
  28021. ret = 0;
  28022. do {
  28023. #if defined(WOLFSSL_ASYNC_CRYPT)
  28024. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  28025. #endif
  28026. if (ret == 0)
  28027. ret = wc_ecc_shared_secret_ssh(key, &key->pubkey, out, &outLen);
  28028. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  28029. if (ret != 0)
  28030. return WC_TEST_RET_ENC_EC(ret);
  28031. TEST_SLEEP();
  28032. return 0;
  28033. }
  28034. #endif /* HAVE_ECC_DHE && !WC_NO_RNG */
  28035. static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
  28036. {
  28037. wc_test_ret_t ret;
  28038. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28039. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28040. #else
  28041. ecc_key key[1];
  28042. #endif
  28043. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28044. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28045. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28046. word32 idx = 0;
  28047. #endif
  28048. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28049. if (key == NULL)
  28050. ERROR_OUT(MEMORY_E, done);
  28051. #endif
  28052. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28053. /* Use API */
  28054. ret = wc_ecc_set_flags(NULL, 0);
  28055. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28056. ret = WC_TEST_RET_ENC_EC(ret);
  28057. goto done;
  28058. }
  28059. ret = wc_ecc_set_flags(key, 0);
  28060. if (ret != 0)
  28061. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28062. #ifndef WOLF_CRYPTO_CB_ONLY_ECC
  28063. #ifndef WC_NO_RNG
  28064. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  28065. #if defined(WOLFSSL_ASYNC_CRYPT)
  28066. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  28067. #endif
  28068. if (ret != 0) {
  28069. goto done;
  28070. }
  28071. #ifndef NO_SIG_WRAPPER
  28072. ret = ecc_sig_test(rng, key);
  28073. if (ret < 0)
  28074. goto done;
  28075. #endif
  28076. TEST_SLEEP();
  28077. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
  28078. !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  28079. ret = ecc_ssh_test(key, rng);
  28080. if (ret < 0)
  28081. goto done;
  28082. #endif
  28083. wc_ecc_free(key);
  28084. #else
  28085. (void)rng;
  28086. #endif /* !WC_NO_RNG */
  28087. #if !defined(NO_ECC_SECP) && !defined(NO_ASN) && \
  28088. ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
  28089. (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
  28090. /* Use test ECC key - ensure real private "d" exists */
  28091. #if defined(USE_CERT_BUFFERS_256)
  28092. {
  28093. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  28094. sizeof_ecc_key_der_256);
  28095. }
  28096. #elif !defined(NO_FILESYSTEM)
  28097. {
  28098. XFILE file = XFOPEN(eccKeyDerFile, "rb");
  28099. byte der[128];
  28100. word32 derSz;
  28101. if (!file) {
  28102. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28103. }
  28104. derSz = (word32)XFREAD(der, 1, sizeof(der), file);
  28105. XFCLOSE(file);
  28106. if (derSz == 0)
  28107. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  28108. ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
  28109. }
  28110. #else
  28111. {
  28112. (void)idx;
  28113. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
  28114. ERROR_OUT(ASN_PARSE_E, done);
  28115. }
  28116. #endif
  28117. if (ret != 0) {
  28118. goto done;
  28119. }
  28120. #if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
  28121. ret = ecc_exp_imp_test(key);
  28122. if (ret < 0)
  28123. goto done;
  28124. #endif
  28125. #if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
  28126. !defined(WOLFSSL_CRYPTOCELL)
  28127. ret = ecc_mulmod_test(key);
  28128. if (ret < 0)
  28129. goto done;
  28130. #endif
  28131. #endif
  28132. #else
  28133. (void)rng;
  28134. (void)idx;
  28135. #endif /* WOLF_CRYPTO_CB_ONLY_ECC */
  28136. done:
  28137. wc_ecc_free(key);
  28138. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28139. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28140. #endif
  28141. return ret;
  28142. }
  28143. #endif /* !NO_ECC256 || HAVE_ALL_CURVES */
  28144. #if defined(WOLFSSL_CERT_EXT) && \
  28145. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  28146. static wc_test_ret_t ecc_decode_test(void)
  28147. {
  28148. wc_test_ret_t ret;
  28149. word32 inSz;
  28150. word32 inOutIdx;
  28151. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28152. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28153. #else
  28154. ecc_key key[1];
  28155. #endif
  28156. /* SECP256R1 OID: 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 */
  28157. /* This is ecc_clikeypub_der_256. */
  28158. WOLFSSL_SMALL_STACK_STATIC const byte good[] = {
  28159. 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce,
  28160. 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
  28161. 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x55, 0xbf, 0xf4,
  28162. 0x0f, 0x44, 0x50, 0x9a, 0x3d, 0xce, 0x9b, 0xb7, 0xf0, 0xc5,
  28163. 0x4d, 0xf5, 0x70, 0x7b, 0xd4, 0xec, 0x24, 0x8e, 0x19, 0x80,
  28164. 0xec, 0x5a, 0x4c, 0xa2, 0x24, 0x03, 0x62, 0x2c, 0x9b, 0xda,
  28165. 0xef, 0xa2, 0x35, 0x12, 0x43, 0x84, 0x76, 0x16, 0xc6, 0x56,
  28166. 0x95, 0x06, 0xcc, 0x01, 0xa9, 0xbd, 0xf6, 0x75, 0x1a, 0x42,
  28167. 0xf7, 0xbd, 0xa9, 0xb2, 0x36, 0x22, 0x5f, 0xc7, 0x5d, 0x7f,
  28168. 0xb4 };
  28169. WOLFSSL_SMALL_STACK_STATIC const byte badNoObjId[] = { 0x30, 0x08, 0x30, 0x06, 0x03, 0x04,
  28170. 0x00, 0x04, 0x01, 0x01 };
  28171. WOLFSSL_SMALL_STACK_STATIC const byte badOneObjId[] = { 0x30, 0x0a, 0x30, 0x08, 0x06, 0x00,
  28172. 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28173. WOLFSSL_SMALL_STACK_STATIC const byte badObjId1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x09,
  28174. 0x06, 0x00, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28175. WOLFSSL_SMALL_STACK_STATIC const byte badObj2d1Len[] = { 0x30, 0x0c, 0x30, 0x0a, 0x06, 0x00,
  28176. 0x06, 0x07, 0x03, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28177. WOLFSSL_SMALL_STACK_STATIC const byte badNotBitStr[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28178. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28179. 0x04, 0x04, 0x00, 0x04, 0x01, 0x01 };
  28180. WOLFSSL_SMALL_STACK_STATIC const byte badBitStrLen[] = { 0x30, 0x14, 0x30, 0x0b, 0x06, 0x00,
  28181. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28182. 0x03, 0x05, 0x00, 0x04, 0x01, 0x01 };
  28183. WOLFSSL_SMALL_STACK_STATIC const byte badNoBitStrZero[] = { 0x30, 0x13, 0x30, 0x0a, 0x06, 0x00,
  28184. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28185. 0x03, 0x03, 0x04, 0x01, 0x01 };
  28186. WOLFSSL_SMALL_STACK_STATIC const byte badPoint[] = { 0x30, 0x12, 0x30, 0x09, 0x06, 0x00,
  28187. 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07,
  28188. 0x03, 0x03, 0x00, 0x04, 0x01 };
  28189. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28190. if (key == NULL)
  28191. ERROR_OUT(MEMORY_E, done);
  28192. #endif
  28193. XMEMSET(key, 0, sizeof *key);
  28194. wc_ecc_init_ex(key, HEAP_HINT, devId);
  28195. inSz = sizeof(good);
  28196. ret = wc_EccPublicKeyDecode(NULL, &inOutIdx, key, inSz);
  28197. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28198. ret = WC_TEST_RET_ENC_EC(ret);
  28199. goto done;
  28200. }
  28201. ret = wc_EccPublicKeyDecode(good, NULL, key, inSz);
  28202. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28203. ret = WC_TEST_RET_ENC_EC(ret);
  28204. goto done;
  28205. }
  28206. ret = wc_EccPublicKeyDecode(good, &inOutIdx, NULL, inSz);
  28207. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28208. ret = WC_TEST_RET_ENC_EC(ret);
  28209. goto done;
  28210. }
  28211. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, 0);
  28212. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  28213. ret = WC_TEST_RET_ENC_EC(ret);
  28214. goto done;
  28215. }
  28216. /* Change offset to produce bad input data. */
  28217. inOutIdx = 2;
  28218. inSz = sizeof(good) - inOutIdx;
  28219. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28220. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28221. ret = WC_TEST_RET_ENC_EC(ret);
  28222. goto done;
  28223. }
  28224. inOutIdx = 4;
  28225. inSz = sizeof(good) - inOutIdx;
  28226. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28227. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28228. ret = WC_TEST_RET_ENC_EC(ret);
  28229. goto done;
  28230. }
  28231. /* Bad data. */
  28232. inSz = sizeof(badNoObjId);
  28233. inOutIdx = 0;
  28234. ret = wc_EccPublicKeyDecode(badNoObjId, &inOutIdx, key, inSz);
  28235. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28236. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28237. {
  28238. ret = WC_TEST_RET_ENC_EC(ret);
  28239. goto done;
  28240. }
  28241. inSz = sizeof(badOneObjId);
  28242. inOutIdx = 0;
  28243. ret = wc_EccPublicKeyDecode(badOneObjId, &inOutIdx, key, inSz);
  28244. if (ret != WC_NO_ERR_TRACE(ASN_OBJECT_ID_E) &&
  28245. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28246. {
  28247. ret = WC_TEST_RET_ENC_EC(ret);
  28248. goto done;
  28249. }
  28250. inSz = sizeof(badObjId1Len);
  28251. inOutIdx = 0;
  28252. ret = wc_EccPublicKeyDecode(badObjId1Len, &inOutIdx, key, inSz);
  28253. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28254. ret = WC_TEST_RET_ENC_EC(ret);
  28255. goto done;
  28256. }
  28257. inSz = sizeof(badObj2d1Len);
  28258. inOutIdx = 0;
  28259. ret = wc_EccPublicKeyDecode(badObj2d1Len, &inOutIdx, key, inSz);
  28260. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28261. ret = WC_TEST_RET_ENC_EC(ret);
  28262. goto done;
  28263. }
  28264. inSz = sizeof(badNotBitStr);
  28265. inOutIdx = 0;
  28266. ret = wc_EccPublicKeyDecode(badNotBitStr, &inOutIdx, key, inSz);
  28267. if (ret != WC_NO_ERR_TRACE(ASN_BITSTR_E) &&
  28268. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28269. {
  28270. ret = WC_TEST_RET_ENC_EC(ret);
  28271. goto done;
  28272. }
  28273. inSz = sizeof(badBitStrLen);
  28274. inOutIdx = 0;
  28275. ret = wc_EccPublicKeyDecode(badBitStrLen, &inOutIdx, key, inSz);
  28276. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E)) {
  28277. ret = WC_TEST_RET_ENC_EC(ret);
  28278. goto done;
  28279. }
  28280. inSz = sizeof(badNoBitStrZero);
  28281. inOutIdx = 0;
  28282. ret = wc_EccPublicKeyDecode(badNoBitStrZero, &inOutIdx, key, inSz);
  28283. if (ret != WC_NO_ERR_TRACE(ASN_EXPECT_0_E) &&
  28284. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28285. {
  28286. ret = WC_TEST_RET_ENC_EC(ret);
  28287. goto done;
  28288. }
  28289. inSz = sizeof(badPoint);
  28290. inOutIdx = 0;
  28291. ret = wc_EccPublicKeyDecode(badPoint, &inOutIdx, key, inSz);
  28292. if (ret != WC_NO_ERR_TRACE(ASN_ECC_KEY_E) &&
  28293. ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  28294. {
  28295. ret = WC_TEST_RET_ENC_EC(ret);
  28296. goto done;
  28297. }
  28298. inSz = sizeof(good);
  28299. inOutIdx = 0;
  28300. ret = wc_EccPublicKeyDecode(good, &inOutIdx, key, inSz);
  28301. if (ret != 0)
  28302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28303. done:
  28304. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28305. if (key != NULL) {
  28306. wc_ecc_free(key);
  28307. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28308. }
  28309. #else
  28310. wc_ecc_free(key);
  28311. #endif
  28312. return ret;
  28313. }
  28314. #endif /* WOLFSSL_CERT_EXT */
  28315. #ifdef WOLFSSL_CUSTOM_CURVES
  28316. static const byte eccKeyExplicitCurve[] = {
  28317. 0x30, 0x81, 0xf5, 0x30, 0x81, 0xae, 0x06, 0x07,
  28318. 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x30,
  28319. 0x81, 0xa2, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06,
  28320. 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01,
  28321. 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
  28322. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28323. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28324. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff,
  28325. 0xff, 0xfc, 0x2f, 0x30, 0x06, 0x04, 0x01, 0x00,
  28326. 0x04, 0x01, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe,
  28327. 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0,
  28328. 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b,
  28329. 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2,
  28330. 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a,
  28331. 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4,
  28332. 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17,
  28333. 0xb4, 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47,
  28334. 0xd0, 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21,
  28335. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28336. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  28337. 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0,
  28338. 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41,
  28339. 0x41, 0x02, 0x01, 0x01, 0x03, 0x42, 0x00, 0x04,
  28340. 0x3c, 0x4c, 0xc9, 0x5e, 0x2e, 0xa2, 0x3d, 0x49,
  28341. 0xcc, 0x5b, 0xff, 0x4f, 0xc9, 0x2e, 0x1d, 0x4a,
  28342. 0xc6, 0x21, 0xf6, 0xf3, 0xe6, 0x0b, 0x4f, 0xa9,
  28343. 0x9d, 0x74, 0x99, 0xdd, 0x97, 0xc7, 0x6e, 0xbe,
  28344. 0x14, 0x2b, 0x39, 0x9d, 0x63, 0xc7, 0x97, 0x0d,
  28345. 0x45, 0x25, 0x40, 0x30, 0x77, 0x05, 0x76, 0x88,
  28346. 0x38, 0x96, 0x29, 0x7d, 0x9c, 0xe1, 0x50, 0xbe,
  28347. 0xac, 0xf0, 0x1d, 0x86, 0xf4, 0x2f, 0x65, 0x0b
  28348. };
  28349. static wc_test_ret_t ecc_test_custom_curves(WC_RNG* rng)
  28350. {
  28351. wc_test_ret_t ret;
  28352. word32 inOutIdx;
  28353. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28354. ecc_key *key = (ecc_key *)XMALLOC(sizeof *key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28355. #else
  28356. ecc_key key[1];
  28357. #endif
  28358. /* test use of custom curve - using BRAINPOOLP256R1 for test */
  28359. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28360. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28361. WOLFSSL_SMALL_STACK_STATIC const ecc_oid_t ecc_oid_brainpoolp256r1[] = {
  28362. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07
  28363. };
  28364. #define ecc_oid_brainpoolp256r1_sz \
  28365. (sizeof(ecc_oid_brainpoolp256r1) / sizeof(ecc_oid_t))
  28366. #else
  28367. #define ecc_oid_brainpoolp256r1 { \
  28368. 0x2B,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07 \
  28369. }
  28370. #define ecc_oid_brainpoolp256r1_sz 9
  28371. #endif
  28372. #define ecc_oid_brainpoolp256r1_sum 104
  28373. WOLFSSL_SMALL_STACK_STATIC const ecc_set_type ecc_dp_brainpool256r1 = {
  28374. 32, /* size/bytes */
  28375. ECC_CURVE_CUSTOM, /* ID */
  28376. "BRAINPOOLP256R1", /* curve name */
  28377. "A9FB57DBA1EEA9BC3E660A909D838D726E3BF623D52620282013481D1F6E5377", /* prime */
  28378. "7D5A0975FC2C3057EEF67530417AFFE7FB8055C126DC5C6CE94A4B44F330B5D9", /* A */
  28379. "26DC5C6CE94A4B44F330B5D9BBD77CBF958416295CF7E1CE6BCCDC18FF8C07B6", /* B */
  28380. "A9FB57DBA1EEA9BC3E660A909D838D718C397AA3B561A6F7901E0E82974856A7", /* order */
  28381. "8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262", /* Gx */
  28382. "547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997", /* Gy */
  28383. ecc_oid_brainpoolp256r1, /* oid/oidSz */
  28384. ecc_oid_brainpoolp256r1_sz,
  28385. ecc_oid_brainpoolp256r1_sum, /* oid sum */
  28386. 1, /* cofactor */
  28387. };
  28388. #endif /* HAVE_ECC_BRAINPOOL */
  28389. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28390. if (! key) {
  28391. ret = MEMORY_E;
  28392. goto done;
  28393. }
  28394. #endif
  28395. XMEMSET(key, 0, sizeof *key);
  28396. #if defined(HAVE_ECC_BRAINPOOL) && !defined(HAVE_INTEL_QA)
  28397. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, ECC_CURVE_DEF,
  28398. &ecc_dp_brainpool256r1);
  28399. if (ret != 0) {
  28400. printf("ECC test for custom curve failed!\n");
  28401. goto done;
  28402. }
  28403. #endif
  28404. #if defined(HAVE_ECC_BRAINPOOL) || defined(HAVE_ECC_KOBLITZ)
  28405. {
  28406. int curve_id;
  28407. #ifdef HAVE_ECC_BRAINPOOL
  28408. curve_id = ECC_BRAINPOOLP256R1;
  28409. #else
  28410. curve_id = ECC_SECP256K1;
  28411. #endif
  28412. /* Test and demonstrate use of non-SECP curve */
  28413. ret = ecc_test_curve_size(rng, 0, ECC_TEST_VERIFY_COUNT, curve_id, NULL);
  28414. if (ret < 0) {
  28415. printf("ECC test for curve_id %d failed!\n", curve_id);
  28416. goto done;
  28417. }
  28418. }
  28419. #endif
  28420. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  28421. if (ret != 0)
  28422. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28423. inOutIdx = 0;
  28424. ret = wc_EccPublicKeyDecode(eccKeyExplicitCurve, &inOutIdx, key,
  28425. sizeof(eccKeyExplicitCurve));
  28426. if (ret != 0)
  28427. ret = WC_TEST_RET_ENC_EC(ret);
  28428. done:
  28429. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28430. if (key) {
  28431. wc_ecc_free(key);
  28432. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28433. }
  28434. #else
  28435. wc_ecc_free(key);
  28436. #endif
  28437. (void)rng;
  28438. return ret;
  28439. }
  28440. #endif /* WOLFSSL_CUSTOM_CURVES */
  28441. #ifdef WOLFSSL_SM2
  28442. #ifdef HAVE_ECC_VERIFY
  28443. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28444. #ifdef HAVE_OID_ENCODING
  28445. #define CODED_SM2P256V1 {1,2,156,10197,1,301}
  28446. #define CODED_SM2P256V1_SZ 6
  28447. #else
  28448. #define CODED_SM2P256V1 {0x06,0x08,0x2A,0x81,0x1C,0xCF,0x55,0x01,0x82,0x2D}
  28449. #define CODED_SM2P256V1_SZ 10
  28450. #endif
  28451. #ifndef WOLFSSL_ECC_CURVE_STATIC
  28452. static const ecc_oid_t ecc_oid_sm2p256v1[] = CODED_SM2P256V1;
  28453. #else
  28454. #define ecc_oid_sm2p256v1 CODED_SM2P256V1
  28455. #endif
  28456. #define ecc_oid_sm2p256v1_sz CODED_SM2P256V1_SZ
  28457. #define ECC_SM2P256V1_TEST 102
  28458. static int test_sm2_verify_caseA2(void)
  28459. {
  28460. ecc_key key;
  28461. int ret, res;
  28462. mp_int r,s;
  28463. /* test key values */
  28464. const char qx[] = "0AE4C7798AA0F119471BEE11825BE46202BB79E2A5844495E97C04FF4DF2548A";
  28465. const char qy[] = "7C0240F88F1CD4E16352A73C17B7F16F07353E53A176D684A9FE0C6BB798E857";
  28466. const char d[] = "128B2FA8BD433C6C068C8D803DFF79792A519A55171B1B650C23661D15897263";
  28467. const ecc_set_type ecc_sm2_A2 = {
  28468. 32, /* size/bytes */
  28469. ECC_SM2P256V1_TEST, /* ID */
  28470. "SM2P256V1_TEST", /* curve name */
  28471. /* from test case A.2 in draft-shen-sm2-ecdsa-02 */
  28472. "8542D69E4C044F18E8B92435BF6FF7DE457283915C45517D722EDB8B08F1DFC3", /* prime */
  28473. "787968B4FA32C3FD2417842E73BBFEFF2F3C848B6831D7E0EC65228B3937E498", /* A */
  28474. "63E4C6D3B23B0C849CF84241484BFE48F61D59A5B16BA06E6E12D1DA27C5249A", /* B */
  28475. "8542D69E4C044F18E8B92435BF6FF7DD297720630485628D5AE74EE7C32E79B7", /* order n */
  28476. "421DEBD61B62EAB6746434EBC3CC315E32220B3BADD50BDC4C4E6C147FEDD43D", /* Gx */
  28477. "0680512BCBB42C07D47349D2153B70C4E5D7FDFCBFA36EA1A85841B9E46E09A2", /* Gy */
  28478. ecc_oid_sm2p256v1, /* oid/oidSz */
  28479. ecc_oid_sm2p256v1_sz,
  28480. ECC_SM2P256V1_OID, /* oid sum */
  28481. 1, /* cofactor */
  28482. };
  28483. /* use canned hash value hash = H(ZA||M) */
  28484. const byte hash[] = {
  28485. 0xB5,0x24,0xF5,0x52,0xCD,0x82,0xB8,0xB0,
  28486. 0x28,0x47,0x6E,0x00,0x5C,0x37,0x7F,0xB1,
  28487. 0x9A,0x87,0xE6,0xFC,0x68,0x2D,0x48,0xBB,
  28488. 0x5D,0x42,0xE3,0xD9,0xB9,0xEF,0xFE,0x76
  28489. };
  28490. /* canned r and s */
  28491. const byte rCan[] = {
  28492. 0x40,0xF1,0xEC,0x59,0xF7,0x93,0xD9,0xF4,
  28493. 0x9E,0x09,0xDC,0xEF,0x49,0x13,0x0D,0x41,
  28494. 0x94,0xF7,0x9F,0xB1,0xEE,0xD2,0xCA,0xA5,
  28495. 0x5B,0xAC,0xDB,0x49,0xC4,0xE7,0x55,0xD1
  28496. };
  28497. const byte sCan[] = {
  28498. 0x6F,0xC6,0xDA,0xC3,0x2C,0x5D,0x5C,0xF1,
  28499. 0x0C,0x77,0xDF,0xB2,0x0F,0x7C,0x2E,0xB6,
  28500. 0x67,0xA4,0x57,0x87,0x2F,0xB0,0x9E,0xC5,
  28501. 0x63,0x27,0xA6,0x7E,0xC7,0xDE,0xEB,0xE7
  28502. };
  28503. mp_init(&r);
  28504. mp_init(&s);
  28505. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28506. if (ret != 0)
  28507. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28508. ret = wc_ecc_set_custom_curve(&key, &ecc_sm2_A2);
  28509. if (ret != 0)
  28510. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28511. ret = wc_ecc_import_raw_ex(&key, qx, qy, d, ECC_SM2P256V1_TEST);
  28512. if (ret != 0)
  28513. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28514. mp_read_unsigned_bin(&r, rCan, sizeof(rCan));
  28515. mp_read_unsigned_bin(&s, sCan, sizeof(sCan));
  28516. ret = wc_ecc_sm2_verify_hash_ex(&r, &s, hash, sizeof(hash), &res, &key);
  28517. if (ret != 0)
  28518. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28519. if (res != 1)
  28520. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28521. done:
  28522. mp_free(&r);
  28523. mp_free(&s);
  28524. wc_ecc_free(&key);
  28525. return ret;
  28526. }
  28527. #endif /* WOLFSSL_PUBLIC_MP && WOLFSSL_CUSTOM_CURVES */
  28528. static int test_sm2_verify_case(void)
  28529. {
  28530. ecc_key key;
  28531. int ret, res;
  28532. /* test key values */
  28533. const char qx[] = "637F1B135036C933DC3F7A8EBB1B7B2FD1DFBD268D4F894B5AD47DBDBECD558F";
  28534. const char qy[] = "E88101D08048E36CCBF61CA38DDF7ABA542B4486E99E49F3A7470A857A096433";
  28535. /* use canned hash value hash = H(ZA||M) */
  28536. const byte hash[] = {
  28537. 0x3B,0xFA,0x5F,0xFB,0xC4,0x27,0x8C,0x9D,
  28538. 0x02,0x3A,0x19,0xCB,0x1E,0xAA,0xD2,0xF1,
  28539. 0x50,0x69,0x5B,0x20
  28540. };
  28541. const byte sig[] = {
  28542. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28543. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28544. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28545. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28546. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28547. 0xB5,0xB5,0xD9,0xD8,0xF1,0x20,0xDD,0x97,
  28548. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28549. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28550. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28551. };
  28552. const byte badSig[] = {
  28553. 0x30,0x45,0x02,0x21,0x00,0xD2,0xFC,0xA3,
  28554. 0x88,0xE3,0xDF,0xA3,0x00,0x73,0x9B,0x3C,
  28555. 0x2A,0x0D,0xAD,0x44,0xA2,0xFC,0x62,0xD5,
  28556. 0x6B,0x84,0x54,0xD8,0x40,0x22,0x62,0x3D,
  28557. 0x5C,0xA6,0x61,0x9B,0xE7,0x02,0x20,0x1D,
  28558. 0xB5,0xB5,0xE9,0xD8,0xF1,0x20,0xDD,0x97,
  28559. 0x92,0xBF,0x7E,0x9B,0x3F,0xE6,0x3C,0x4B,
  28560. 0x03,0xD8,0x80,0xBD,0xB7,0x27,0x7E,0x6A,
  28561. 0x84,0x23,0xDE,0x61,0x7C,0x8D,0xDC
  28562. };
  28563. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28564. if (ret != 0)
  28565. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28566. ret = wc_ecc_import_raw(&key, qx, qy, NULL, "SM2P256V1");
  28567. if (ret != 0)
  28568. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28569. ret = wc_ecc_sm2_verify_hash(sig, sizeof(sig), hash, sizeof(hash), &res,
  28570. &key);
  28571. if (ret != 0)
  28572. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28573. if (res != 1)
  28574. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28575. /* now test a case that should fail */
  28576. ret = wc_ecc_sm2_verify_hash(badSig, sizeof(badSig), hash, sizeof(hash),
  28577. &res, &key);
  28578. if (ret != 0)
  28579. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28580. if (res == 1)
  28581. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28582. done:
  28583. wc_ecc_free(&key);
  28584. return ret;
  28585. }
  28586. static int ecc_sm2_test_curve(WC_RNG* rng, int testVerifyCount)
  28587. {
  28588. const ecc_set_type* dp = wc_ecc_get_curve_params(
  28589. wc_ecc_get_curve_idx(ECC_SM2P256V1));
  28590. int keySize = 32;
  28591. int curve_id = ECC_SM2P256V1;
  28592. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28593. WC_DECLARE_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28594. WC_DECLARE_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28595. #endif
  28596. #ifdef HAVE_ECC_KEY_EXPORT
  28597. #define ECC_KEY_EXPORT_BUF_SIZE (MAX_ECC_BYTES * 2 + 32)
  28598. WC_DECLARE_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28599. #endif
  28600. word32 x = 0;
  28601. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28602. word32 y;
  28603. #endif
  28604. #ifdef HAVE_ECC_SIGN
  28605. WC_DECLARE_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28606. WC_DECLARE_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28607. int i;
  28608. int verify;
  28609. #endif /* HAVE_ECC_SIGN */
  28610. int ret;
  28611. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28612. ecc_key *userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28613. ecc_key *userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28614. ecc_key *pubKey = (ecc_key *)XMALLOC(sizeof *pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28615. #else
  28616. ecc_key userA[1];
  28617. ecc_key userB[1];
  28618. ecc_key pubKey[1];
  28619. #endif
  28620. #ifndef WC_NO_RNG
  28621. int curveSize;
  28622. #endif
  28623. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28624. WC_ALLOC_VAR(sharedA, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28625. WC_ALLOC_VAR(sharedB, byte, ECC_SHARED_SIZE, HEAP_HINT);
  28626. #endif
  28627. #ifdef HAVE_ECC_KEY_EXPORT
  28628. WC_ALLOC_VAR(exportBuf, byte, ECC_KEY_EXPORT_BUF_SIZE, HEAP_HINT);
  28629. #endif
  28630. #ifdef HAVE_ECC_SIGN
  28631. WC_ALLOC_VAR(sig, byte, ECC_SIG_SIZE, HEAP_HINT);
  28632. WC_ALLOC_VAR(digest, byte, ECC_DIGEST_SIZE, HEAP_HINT);
  28633. #endif
  28634. #ifdef WC_DECLARE_VAR_IS_HEAP_ALLOC
  28635. #if (defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)) && !defined(WC_NO_RNG)
  28636. if (sharedA == NULL || sharedB == NULL)
  28637. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28638. #endif
  28639. #ifdef HAVE_ECC_KEY_EXPORT
  28640. if (exportBuf == NULL)
  28641. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28642. #endif
  28643. #ifdef HAVE_ECC_SIGN
  28644. if (sig == NULL || digest == NULL)
  28645. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28646. #endif
  28647. #endif /* WOLFSSL_SMALL_STACK && !WOLFSSL_NO_MALLOC */
  28648. (void)testVerifyCount;
  28649. (void)dp;
  28650. (void)x;
  28651. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28652. if ((userA == NULL) ||
  28653. (userB == NULL) ||
  28654. (pubKey == NULL))
  28655. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28656. #endif
  28657. XMEMSET(userA, 0, sizeof *userA);
  28658. XMEMSET(userB, 0, sizeof *userB);
  28659. XMEMSET(pubKey, 0, sizeof *pubKey);
  28660. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  28661. if (ret != 0)
  28662. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28663. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  28664. if (ret != 0)
  28665. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28666. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28667. if (ret != 0)
  28668. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28669. #ifndef WC_NO_RNG
  28670. ret = wc_ecc_sm2_make_key(rng, userA, WC_ECC_FLAG_NONE);
  28671. if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E))
  28672. goto done; /* catch case, where curve is not supported */
  28673. if (ret != 0)
  28674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28675. TEST_SLEEP();
  28676. if (wc_ecc_get_curve_idx(curve_id) != -1) {
  28677. curveSize = wc_ecc_get_curve_size_from_id(userA->dp->id);
  28678. if (curveSize != userA->dp->size) {
  28679. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28680. }
  28681. }
  28682. ret = wc_ecc_check_key(userA);
  28683. if (ret != 0)
  28684. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28685. TEST_SLEEP();
  28686. ret = wc_ecc_sm2_make_key(rng, userB, WC_ECC_FLAG_NONE);
  28687. if (ret != 0)
  28688. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28689. /* only perform the below tests if the key size matches */
  28690. if (dp == NULL && keySize > 0 && wc_ecc_size(userA) != keySize)
  28691. if (ret != 0) {
  28692. ret = ECC_CURVE_OID_E;
  28693. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28694. }
  28695. #ifdef HAVE_ECC_DHE
  28696. #if defined(ECC_TIMING_RESISTANT)
  28697. ret = wc_ecc_set_rng(userA, rng);
  28698. if (ret != 0)
  28699. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28700. ret = wc_ecc_set_rng(userB, rng);
  28701. if (ret != 0)
  28702. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28703. #endif
  28704. x = ECC_SHARED_SIZE;
  28705. ret = wc_ecc_sm2_shared_secret(userA, userB, sharedA, &x);
  28706. if (ret != 0)
  28707. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28708. y = ECC_SHARED_SIZE;
  28709. ret = wc_ecc_sm2_shared_secret(userB, userA, sharedB, &y);
  28710. if (ret != 0)
  28711. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28712. if (y != x)
  28713. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28714. if (XMEMCMP(sharedA, sharedB, x))
  28715. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28716. #endif /* HAVE_ECC_DHE */
  28717. #ifdef HAVE_ECC_KEY_EXPORT
  28718. x = ECC_KEY_EXPORT_BUF_SIZE;
  28719. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 0);
  28720. if (ret != 0)
  28721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28722. #ifdef HAVE_ECC_KEY_IMPORT
  28723. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28724. if (ret != 0)
  28725. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28726. #ifdef HAVE_ECC_DHE
  28727. y = ECC_SHARED_SIZE;
  28728. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28729. if (ret != 0)
  28730. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28731. if (XMEMCMP(sharedA, sharedB, y))
  28732. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28733. #endif /* HAVE_ECC_DHE */
  28734. #ifdef HAVE_COMP_KEY
  28735. /* try compressed export / import too */
  28736. x = ECC_KEY_EXPORT_BUF_SIZE;
  28737. ret = wc_ecc_export_x963_ex(userA, exportBuf, &x, 1);
  28738. if (ret != 0)
  28739. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28740. wc_ecc_free(pubKey);
  28741. ret = wc_ecc_init_ex(pubKey, HEAP_HINT, devId);
  28742. if (ret != 0)
  28743. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28744. #endif
  28745. ret = wc_ecc_import_x963_ex(exportBuf, x, pubKey, curve_id);
  28746. if (ret != 0)
  28747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28748. #ifdef HAVE_ECC_DHE
  28749. y = ECC_SHARED_SIZE;
  28750. ret = wc_ecc_sm2_shared_secret(userB, pubKey, sharedB, &y);
  28751. if (ret != 0)
  28752. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28753. if (XMEMCMP(sharedA, sharedB, y))
  28754. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28755. #endif /* HAVE_ECC_DHE */
  28756. #endif /* HAVE_ECC_KEY_IMPORT */
  28757. #endif /* HAVE_ECC_KEY_EXPORT */
  28758. #endif /* !WC_NO_RNG */
  28759. #if !defined(ECC_TIMING_RESISTANT) || (defined(ECC_TIMING_RESISTANT) && \
  28760. !defined(WC_NO_RNG))
  28761. #ifdef HAVE_ECC_SIGN
  28762. /* ECC w/out Shamir has issue with all 0 digest */
  28763. /* WC_BIGINT doesn't have 0 len well on hardware */
  28764. /* Cryptocell has issues with all 0 digest */
  28765. #if defined(ECC_SHAMIR)
  28766. /* test DSA sign hash with zeros */
  28767. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28768. digest[i] = 0;
  28769. }
  28770. x = ECC_SIG_SIZE;
  28771. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28772. if (ret != 0)
  28773. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28774. for (i = 0; i < testVerifyCount; i++) {
  28775. verify = 0;
  28776. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28777. userA);
  28778. if (ret != 0)
  28779. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28780. if (verify != 1)
  28781. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28782. }
  28783. #endif /* ECC_SHAMIR */
  28784. /* test DSA sign hash with sequence (0,1,2,3,4,...) */
  28785. for (i = 0; i < (int)ECC_DIGEST_SIZE; i++) {
  28786. digest[i] = (byte)i;
  28787. }
  28788. x = ECC_SIG_SIZE;
  28789. ret = wc_ecc_sm2_sign_hash(digest, ECC_DIGEST_SIZE, sig, &x, rng, userA);
  28790. if (ret != 0)
  28791. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28792. for (i = 0; i < testVerifyCount; i++) {
  28793. verify = 0;
  28794. ret = wc_ecc_sm2_verify_hash(sig, x, digest, ECC_DIGEST_SIZE, &verify,
  28795. userA);
  28796. if (ret != 0)
  28797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28798. if (verify != 1)
  28799. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28800. }
  28801. #endif /* HAVE_ECC_SIGN */
  28802. #endif /* !ECC_TIMING_RESISTANT || (ECC_TIMING_RESISTANT && !WC_NO_RNG) */
  28803. #if defined(HAVE_ECC_KEY_EXPORT) && !defined(WC_NO_RNG)
  28804. x = ECC_KEY_EXPORT_BUF_SIZE;
  28805. ret = wc_ecc_export_private_only(userA, exportBuf, &x);
  28806. if (ret != 0)
  28807. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28808. #elif defined(HAVE_ECC_KEY_EXPORT)
  28809. (void)exportBuf;
  28810. #endif /* HAVE_ECC_KEY_EXPORT */
  28811. done:
  28812. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28813. if (userA != NULL) {
  28814. wc_ecc_free(userA);
  28815. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28816. }
  28817. if (userB != NULL) {
  28818. wc_ecc_free(userB);
  28819. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28820. }
  28821. if (pubKey != NULL) {
  28822. wc_ecc_free(pubKey);
  28823. XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28824. }
  28825. #else
  28826. wc_ecc_free(pubKey);
  28827. wc_ecc_free(userB);
  28828. wc_ecc_free(userA);
  28829. #endif
  28830. #if defined(HAVE_ECC_DHE) || defined(HAVE_ECC_CDH)
  28831. WC_FREE_VAR(sharedA, HEAP_HINT);
  28832. WC_FREE_VAR(sharedB, HEAP_HINT);
  28833. #endif
  28834. #ifdef HAVE_ECC_KEY_EXPORT
  28835. WC_FREE_VAR(exportBuf, HEAP_HINT);
  28836. #endif
  28837. #ifdef HAVE_ECC_SIGN
  28838. WC_FREE_VAR(sig, HEAP_HINT);
  28839. WC_FREE_VAR(digest, HEAP_HINT);
  28840. #endif
  28841. (void)keySize;
  28842. (void)curve_id;
  28843. (void)rng;
  28844. return ret;
  28845. }
  28846. #endif /* HAVE_ECC_VERIFY */
  28847. static int test_sm2_create_digest(void)
  28848. {
  28849. #ifndef WOLFSSL_SM3
  28850. const byte msg[] = "message to sign";
  28851. const byte id[] = "0123456789";
  28852. const byte badId[] = "0123556789";
  28853. byte expected[] = {
  28854. 0xdd, 0x4d, 0x65, 0x49, 0xa3, 0x64, 0x76, 0xc0,
  28855. 0x73, 0x05, 0xdc, 0x05, 0x16, 0xb5, 0xee, 0x9f,
  28856. 0x82, 0xf9, 0xe9, 0x7d, 0x01, 0x1a, 0xdc, 0x88,
  28857. 0x5a, 0x59, 0x9c, 0x44, 0xcc, 0x47, 0xa4, 0x78
  28858. };
  28859. ecc_key key;
  28860. int ret;
  28861. /* test key values */
  28862. const char qx[] =
  28863. "af178b7b8740cc9d5b493fbd22049c12621bc27dcc5802e75ff4d045a4158baf";
  28864. const char qy[] =
  28865. "89933faf7a4798f48c5b9b4cd3a7693d54c9e05449946eb489c0dd50a5294805";
  28866. const char d[] =
  28867. "b3e66c2dbfb50c6ff6830c1fac4b51293a2562f9e667052b03df2d4b43c1f34a";
  28868. int hash_type = WC_HASH_TYPE_SHA256;
  28869. byte digest[WC_SHA256_DIGEST_SIZE];
  28870. #else
  28871. ecc_key key;
  28872. int ret;
  28873. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x20,
  28874. 0x64, 0x69, 0x67, 0x65, 0x73, 0x74, 0x00 };
  28875. const byte id[] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28876. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
  28877. 0x00 };
  28878. const byte badId[] = "0123556789";
  28879. const char qx[] =
  28880. "09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020";
  28881. const char qy[] =
  28882. "CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13";
  28883. const char d[] =
  28884. "3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8";
  28885. byte expected[] = {
  28886. 0xf0, 0xb4, 0x3e, 0x94, 0xba, 0x45, 0xac, 0xca,
  28887. 0xac, 0xe6, 0x92, 0xed, 0x53, 0x43, 0x82, 0xeb,
  28888. 0x17, 0xe6, 0xab, 0x5a, 0x19, 0xce, 0x7b, 0x31,
  28889. 0xf4, 0x48, 0x6f, 0xdf, 0xc0, 0xd2, 0x86, 0x40
  28890. };
  28891. int hash_type = WC_HASH_TYPE_SM3;
  28892. byte digest[WC_SM3_DIGEST_SIZE];
  28893. #endif
  28894. ret = wc_ecc_init_ex(&key, HEAP_HINT, devId);
  28895. if (ret != 0)
  28896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28897. ret = wc_ecc_import_raw(&key, qx, qy, d, "SM2P256V1");
  28898. if (ret != 0)
  28899. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28900. ret = wc_ecc_sm2_create_digest(id, (int)XSTRLEN((const char*)id),
  28901. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28902. &key);
  28903. if (ret != 0)
  28904. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  28905. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) != 0)
  28906. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28907. ret = wc_ecc_sm2_create_digest(badId, (int)XSTRLEN((const char*)badId),
  28908. msg, (int)XSTRLEN((const char*)msg), hash_type, digest, sizeof(digest),
  28909. &key);
  28910. if (ret != 0)
  28911. goto done;
  28912. /* should be different than the previous ID used */
  28913. if (XMEMCMP(digest, expected, WC_SHA256_DIGEST_SIZE) == 0)
  28914. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  28915. done:
  28916. wc_ecc_free(&key);
  28917. return ret;
  28918. }
  28919. static int test_sm2_verify(void)
  28920. {
  28921. int ret = 0;
  28922. #ifdef HAVE_ECC_VERIFY
  28923. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_CUSTOM_CURVES)
  28924. ret = test_sm2_verify_caseA2();
  28925. if (ret != 0)
  28926. return ret;
  28927. #endif
  28928. ret = test_sm2_verify_case();
  28929. if (ret != 0)
  28930. return ret;
  28931. #endif /* HAVE_ECC_VERIFY */
  28932. ret = test_sm2_create_digest();
  28933. return ret;
  28934. }
  28935. #endif /* WOLFSSL_SM2 */
  28936. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  28937. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  28938. /* Make Cert / Sign example for ECC cert and ECC CA */
  28939. static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
  28940. {
  28941. wc_test_ret_t ret;
  28942. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28943. Cert *myCert = (Cert *)XMALLOC(sizeof *myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28944. #ifdef WOLFSSL_TEST_CERT
  28945. DecodedCert *decode = (DecodedCert *)XMALLOC(sizeof *decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28946. #endif
  28947. ecc_key *caEccKey = (ecc_key *)XMALLOC(sizeof *caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28948. ecc_key *certPubKey = (ecc_key *)XMALLOC(sizeof *certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28949. #else
  28950. Cert myCert[1];
  28951. #ifdef WOLFSSL_TEST_CERT
  28952. DecodedCert decode[1];
  28953. #endif
  28954. ecc_key caEccKey[1];
  28955. ecc_key certPubKey[1];
  28956. #endif
  28957. int certSz;
  28958. size_t bytes = 0;
  28959. word32 idx = 0;
  28960. #if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
  28961. XFILE file;
  28962. #endif
  28963. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28964. byte* der = NULL;
  28965. #else
  28966. byte der[FOURK_BUF];
  28967. #endif
  28968. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28969. if ((myCert == NULL)
  28970. #ifdef WOLFSSL_TEST_CERT
  28971. || (decode == NULL)
  28972. #endif
  28973. || (caEccKey == NULL) || (certPubKey == NULL))
  28974. ERROR_OUT(MEMORY_E, exit);
  28975. #endif
  28976. XMEMSET(caEccKey, 0, sizeof *caEccKey);
  28977. XMEMSET(certPubKey, 0, sizeof *certPubKey);
  28978. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  28979. der = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  28980. if (der == NULL) {
  28981. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28982. }
  28983. #endif
  28984. /* Get cert private key */
  28985. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  28986. /* Get Cert Key 384 */
  28987. #ifdef USE_CERT_BUFFERS_256
  28988. XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
  28989. bytes = sizeof_ca_ecc_key_der_384;
  28990. #elif !defined(NO_FILESYSTEM)
  28991. file = XFOPEN(eccCaKey384File, "rb");
  28992. if (!file) {
  28993. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28994. }
  28995. bytes = XFREAD(der, 1, FOURK_BUF, file);
  28996. XFCLOSE(file);
  28997. if (bytes == 0)
  28998. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  28999. (void)eccCaKeyFile;
  29000. #else
  29001. WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
  29002. ERROR_OUT(ASN_PARSE_E, exit);
  29003. #endif /* USE_CERT_BUFFERS_256 */
  29004. /* end if ENABLE_ECC384_CERT_GEN_TEST */
  29005. #else
  29006. /* !ENABLE_ECC384_CERT_GEN_TEST */
  29007. #ifdef USE_CERT_BUFFERS_256
  29008. XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
  29009. bytes = sizeof_ca_ecc_key_der_256;
  29010. #else
  29011. file = XFOPEN(eccCaKeyFile, "rb");
  29012. if (!file) {
  29013. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29014. }
  29015. bytes = XFREAD(der, 1, FOURK_BUF, file);
  29016. XFCLOSE(file);
  29017. if (bytes == 0)
  29018. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29019. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29020. (void)eccCaKey384File;
  29021. #endif
  29022. #endif /* USE_CERT_BUFFERS_256 */
  29023. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29024. /* Get CA Key */
  29025. ret = wc_ecc_init_ex(caEccKey, HEAP_HINT, devId);
  29026. if (ret != 0)
  29027. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29028. ret = wc_EccPrivateKeyDecode(der, &idx, caEccKey, (word32)bytes);
  29029. if (ret != 0)
  29030. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29031. /* Make a public key */
  29032. ret = wc_ecc_init_ex(certPubKey, HEAP_HINT, devId);
  29033. if (ret != 0)
  29034. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29035. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, certPubKey);
  29036. #if defined(WOLFSSL_ASYNC_CRYPT)
  29037. ret = wc_AsyncWait(ret, &certPubKey->asyncDev, WC_ASYNC_FLAG_NONE);
  29038. #endif
  29039. if (ret != 0)
  29040. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29041. TEST_SLEEP();
  29042. /* Setup Certificate */
  29043. ret = wc_InitCert_ex(myCert, HEAP_HINT, devId);
  29044. if (ret != 0)
  29045. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29046. #ifndef NO_SHA256
  29047. myCert->sigType = CTC_SHA256wECDSA;
  29048. #else
  29049. myCert->sigType = CTC_SHAwECDSA;
  29050. #endif
  29051. XMEMCPY(&myCert->subject, &certDefaultName, sizeof(CertName));
  29052. #ifdef WOLFSSL_CERT_EXT
  29053. /* add Policies */
  29054. XSTRNCPY(myCert->certPolicies[0], "2.4.589440.587.101.2.1.9632587.1",
  29055. CTC_MAX_CERTPOL_SZ);
  29056. XSTRNCPY(myCert->certPolicies[1], "1.2.13025.489.1.113549",
  29057. CTC_MAX_CERTPOL_SZ);
  29058. myCert->certPoliciesNb = 2;
  29059. /* add SKID from the Public Key */
  29060. ret = wc_SetSubjectKeyIdFromPublicKey(myCert, NULL, certPubKey);
  29061. if (ret != 0)
  29062. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29063. /* add AKID from the Public Key */
  29064. ret = wc_SetAuthKeyIdFromPublicKey(myCert, NULL, caEccKey);
  29065. if (ret != 0)
  29066. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29067. /* add Key Usage */
  29068. ret = wc_SetKeyUsage(myCert, certKeyUsage);
  29069. if (ret != 0)
  29070. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29071. #endif /* WOLFSSL_CERT_EXT */
  29072. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29073. #if defined(USE_CERT_BUFFERS_256)
  29074. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
  29075. sizeof_ca_ecc_cert_der_384);
  29076. #elif !defined(NO_FILESYSTEM)
  29077. ret = wc_SetIssuer(myCert, eccCaCert384File);
  29078. (void)eccCaCertFile;
  29079. #else
  29080. /* not testing with embedded, no file system target */
  29081. ERROR_OUT(ASN_PARSE_E, exit);
  29082. #endif /* USE_CERT_BUFFERS_256 */
  29083. #else
  29084. /* not ENABLE_ECC384_CERT_GEN_TEST */
  29085. #if defined(USE_CERT_BUFFERS_256)
  29086. ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
  29087. sizeof_ca_ecc_cert_der_256);
  29088. #else
  29089. ret = wc_SetIssuer(myCert, eccCaCertFile);
  29090. #ifdef ENABLE_ECC384_CERT_GEN_TEST
  29091. (void)eccCaCert384File;
  29092. #endif
  29093. #endif
  29094. #endif /* ENABLE_ECC384_CERT_GEN_TEST */
  29095. if (ret < 0)
  29096. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29097. certSz = wc_MakeCert(myCert, der, FOURK_BUF, NULL, certPubKey, rng);
  29098. if (certSz < 0) {
  29099. ERROR_OUT(WC_TEST_RET_ENC_EC(certSz), exit);
  29100. }
  29101. ret = 0;
  29102. do {
  29103. #if defined(WOLFSSL_ASYNC_CRYPT)
  29104. ret = wc_AsyncWait(ret, &caEccKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  29105. #endif
  29106. if (ret >= 0) {
  29107. ret = wc_SignCert(myCert->bodySz, myCert->sigType, der,
  29108. FOURK_BUF, NULL, caEccKey, rng);
  29109. }
  29110. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  29111. if (ret < 0)
  29112. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29113. certSz = (int)ret;
  29114. TEST_SLEEP();
  29115. #ifdef WOLFSSL_TEST_CERT
  29116. InitDecodedCert(decode, der, certSz, HEAP_HINT);
  29117. ret = ParseCert(decode, CERT_TYPE, NO_VERIFY, 0);
  29118. if (ret != 0) {
  29119. FreeDecodedCert(decode);
  29120. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29121. }
  29122. FreeDecodedCert(decode);
  29123. #endif
  29124. ret = SaveDerAndPem(der, certSz, certEccDerFile, certEccPemFile,
  29125. CERT_TYPE);
  29126. if (ret != 0) {
  29127. goto exit;
  29128. }
  29129. exit:
  29130. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29131. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29132. #endif
  29133. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29134. XFREE(myCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29135. #ifdef WOLFSSL_TEST_CERT
  29136. XFREE(decode, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29137. #endif
  29138. if (caEccKey != NULL) {
  29139. wc_ecc_free(caEccKey);
  29140. XFREE(caEccKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29141. }
  29142. if (certPubKey != NULL) {
  29143. wc_ecc_free(certPubKey);
  29144. XFREE(certPubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29145. }
  29146. #else
  29147. wc_ecc_free(certPubKey);
  29148. wc_ecc_free(caEccKey);
  29149. #endif
  29150. return ret;
  29151. }
  29152. #endif /* WOLFSSL_CERT_GEN */
  29153. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && \
  29154. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
  29155. (!defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES))
  29156. /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */
  29157. static wc_test_ret_t ecc_test_allocator(WC_RNG* rng)
  29158. {
  29159. wc_test_ret_t ret = 0;
  29160. ecc_key* key;
  29161. #ifdef WC_NO_RNG
  29162. word32 idx = 0;
  29163. #endif
  29164. key = wc_ecc_key_new(HEAP_HINT);
  29165. if (key == NULL) {
  29166. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  29167. }
  29168. #ifndef WC_NO_RNG
  29169. ret = wc_ecc_make_key(rng, ECC_KEYGEN_SIZE, key);
  29170. #if defined(WOLFSSL_ASYNC_CRYPT)
  29171. ret = wc_AsyncWait(ret, &key->asyncDev, WC_ASYNC_FLAG_NONE);
  29172. #endif
  29173. if (ret != 0)
  29174. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  29175. #else
  29176. /* use test ECC key */
  29177. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
  29178. (word32)sizeof_ecc_key_der_256);
  29179. (void)rng;
  29180. #endif
  29181. exit:
  29182. wc_ecc_key_free(key);
  29183. return ret;
  29184. }
  29185. #endif
  29186. /* ECC Non-blocking tests for Sign and Verify */
  29187. /* Requires SP math and supports P384 or P256 */
  29188. /* ./configure --enable-ecc=nonblock --enable-sp=yes,nonblock CFLAGS="-DWOLFSSL_PUBLIC_MP" */
  29189. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_HAVE_SP_ECC) && \
  29190. defined(WOLFSSL_PUBLIC_MP)
  29191. /* ECC Private Key "d" */
  29192. static const byte p256PrivKey[] = {
  29193. /* SECP256R1 */
  29194. /* d */
  29195. 0x1e, 0xe7, 0x70, 0x07, 0xd3, 0x30, 0x94, 0x39,
  29196. 0x28, 0x90, 0xdf, 0x23, 0x88, 0x2c, 0x4a, 0x34,
  29197. 0x15, 0xdb, 0x4c, 0x43, 0xcd, 0xfa, 0xe5, 0x1f,
  29198. 0x3d, 0x4c, 0x37, 0xfe, 0x59, 0x3b, 0x96, 0xd8
  29199. };
  29200. #ifdef HAVE_ECC384
  29201. static const byte p384PrivKey[] = {
  29202. /* SECP384R1 */
  29203. /* d */
  29204. 0xa4, 0xe5, 0x06, 0xe8, 0x06, 0x16, 0x3e, 0xab,
  29205. 0x89, 0xf8, 0x60, 0x43, 0xc0, 0x60, 0x25, 0xdb,
  29206. 0xba, 0x7b, 0xfe, 0x19, 0x35, 0x08, 0x55, 0x65,
  29207. 0x76, 0xe2, 0xdc, 0xe0, 0x01, 0x8b, 0x6b, 0x68,
  29208. 0xdf, 0xcf, 0x6f, 0x80, 0x12, 0xce, 0x79, 0x37,
  29209. 0xeb, 0x2b, 0x9c, 0x7b, 0xc4, 0x68, 0x1c, 0x74
  29210. };
  29211. #endif /* HAVE_ECC384 */
  29212. #ifdef HAVE_ECC521
  29213. static const byte p521PrivKey[] = {
  29214. /* SECP521R1 */
  29215. /* d */
  29216. 0x01, 0x68, 0x91, 0x33, 0x53, 0xe2, 0x90, 0x68,
  29217. 0x11, 0x8f, 0xaa, 0xa8, 0x76, 0x0c, 0xf7, 0x2a,
  29218. 0x07, 0x1b, 0x92, 0x2a, 0xa7, 0x82, 0x3d, 0xfa,
  29219. 0x83, 0xce, 0x70, 0xc8, 0xc2, 0x60, 0x82, 0xfe,
  29220. 0x18, 0x88, 0x68, 0xda, 0x6a, 0x83, 0x46, 0x78,
  29221. 0xe4, 0xe9, 0xe9, 0xcc, 0x51, 0x7f, 0xed, 0x81,
  29222. 0x02, 0x32, 0xee, 0x26, 0x87, 0xcc, 0xed, 0x63,
  29223. 0x3f, 0x39, 0x27, 0xf0, 0xd7, 0x17, 0x77, 0xa1,
  29224. 0xa4, 0x36
  29225. };
  29226. #endif /* HAVE_ECC521 */
  29227. /* ECC public key Qx/Qy */
  29228. static const byte p256PubKey[] = {
  29229. /* SECP256R1 */
  29230. /* Qx */
  29231. 0x96, 0x93, 0x1c, 0x53, 0x0b, 0x43, 0x6c, 0x42,
  29232. 0x0c, 0x52, 0x90, 0xe4, 0xa7, 0xec, 0x98, 0xb1,
  29233. 0xaf, 0xd4, 0x14, 0x49, 0xd8, 0xc1, 0x42, 0x82,
  29234. 0x04, 0x78, 0xd1, 0x90, 0xae, 0xa0, 0x6c, 0x07,
  29235. /* Qy */
  29236. 0xf2, 0x3a, 0xb5, 0x10, 0x32, 0x8d, 0xce, 0x9e,
  29237. 0x76, 0xa0, 0xd2, 0x8c, 0xf3, 0xfc, 0xa9, 0x94,
  29238. 0x43, 0x24, 0xe6, 0x82, 0x00, 0x40, 0xc6, 0xdb,
  29239. 0x1c, 0x2f, 0xcd, 0x38, 0x4b, 0x60, 0xdd, 0x61
  29240. };
  29241. #ifdef HAVE_ECC384
  29242. static const byte p384PubKey[] = {
  29243. /* SECP384R1 */
  29244. /* Qx */
  29245. 0xea, 0xcf, 0x93, 0x4f, 0x2c, 0x09, 0xbb, 0x39,
  29246. 0x14, 0x0f, 0x56, 0x64, 0xc3, 0x40, 0xb4, 0xdf,
  29247. 0x0e, 0x63, 0xae, 0xe5, 0x71, 0x4b, 0x00, 0xcc,
  29248. 0x04, 0x97, 0xff, 0xe1, 0xe9, 0x38, 0x96, 0xbb,
  29249. 0x5f, 0x91, 0xb2, 0x6a, 0xcc, 0xb5, 0x39, 0x5f,
  29250. 0x8f, 0x70, 0x59, 0xf1, 0x01, 0xf6, 0x5a, 0x2b,
  29251. /* Qy */
  29252. 0x01, 0x6c, 0x68, 0x0b, 0xcf, 0x55, 0x25, 0xaf,
  29253. 0x6d, 0x98, 0x48, 0x0a, 0xa8, 0x74, 0xc9, 0xa9,
  29254. 0x17, 0xa0, 0x0c, 0xc3, 0xfb, 0xd3, 0x23, 0x68,
  29255. 0xfe, 0x04, 0x3c, 0x63, 0x50, 0x88, 0x3b, 0xb9,
  29256. 0x4f, 0x7c, 0x67, 0x34, 0xf7, 0x3b, 0xa9, 0x73,
  29257. 0xe7, 0x1b, 0xc3, 0x51, 0x5e, 0x22, 0x18, 0xec
  29258. };
  29259. #endif
  29260. #ifdef HAVE_ECC521
  29261. static const byte p521PubKey[] = {
  29262. /* SECP521R1 */
  29263. /* Qx */
  29264. 0x01, 0x62, 0x6e, 0xf1, 0x00, 0xec, 0xd8, 0x99,
  29265. 0x58, 0x9b, 0x80, 0x6b, 0xfe, 0x2c, 0xf1, 0xb2,
  29266. 0xf0, 0xc8, 0x48, 0xdf, 0xac, 0xd2, 0x3b, 0x71,
  29267. 0x29, 0xab, 0xf0, 0x66, 0x63, 0xd8, 0x8e, 0xb5,
  29268. 0xc8, 0xc2, 0xfc, 0x99, 0x44, 0xe2, 0x45, 0xb1,
  29269. 0x5a, 0x7b, 0xb9, 0x73, 0x01, 0xda, 0x79, 0xec,
  29270. 0x9c, 0x26, 0x27, 0x34, 0x45, 0x26, 0xd5, 0x89,
  29271. 0x4b, 0x44, 0xfe, 0x69, 0x4e, 0x72, 0x14, 0xe3,
  29272. 0x8b, 0xbc,
  29273. /* Qy */
  29274. 0x00, 0x0f, 0x09, 0xa2, 0x03, 0xc3, 0x5a, 0xdc,
  29275. 0x95, 0x82, 0xf6, 0xf9, 0xf6, 0x9c, 0xff, 0xb5,
  29276. 0x6b, 0x75, 0x95, 0x4b, 0xa4, 0x28, 0x5d, 0x9e,
  29277. 0x90, 0x04, 0xd1, 0xc0, 0x1e, 0xd5, 0xfd, 0x43,
  29278. 0x9e, 0x1e, 0x83, 0xc0, 0x11, 0x2b, 0x2b, 0x07,
  29279. 0x6d, 0xa9, 0x7a, 0x10, 0xd7, 0x67, 0xe7, 0x51,
  29280. 0x37, 0x24, 0xd8, 0xbf, 0x03, 0x0d, 0x8b, 0xb5,
  29281. 0x40, 0x5c, 0x4f, 0xd6, 0x13, 0x73, 0x42, 0xbc,
  29282. 0x91, 0xd9
  29283. };
  29284. /* perform verify of signature and hash using public key */
  29285. /* key is public Qx + public Qy */
  29286. /* sig is r + s */
  29287. static wc_test_ret_t crypto_ecc_verify(const byte *key, uint32_t keySz,
  29288. const byte *hash, uint32_t hashSz, const byte *sig, uint32_t sigSz,
  29289. uint32_t curveSz, int curveId)
  29290. {
  29291. wc_test_ret_t ret;
  29292. int verify_res = 0, count = 0;
  29293. mp_int r, s;
  29294. ecc_key ecc;
  29295. ecc_nb_ctx_t nb_ctx;
  29296. /* validate arguments */
  29297. if (key == NULL || hash == NULL || sig == NULL || curveSz == 0 ||
  29298. hashSz == 0 || keySz < (curveSz*2) || sigSz < (curveSz*2))
  29299. {
  29300. return WC_TEST_RET_ENC_NC;
  29301. }
  29302. /* Setup the ECC key */
  29303. ret = wc_ecc_init(&ecc);
  29304. if (ret < 0) {
  29305. return WC_TEST_RET_ENC_EC(ret);
  29306. }
  29307. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29308. if (ret != MP_OKAY) {
  29309. wc_ecc_free(&ecc);
  29310. return WC_TEST_RET_ENC_EC(ret);
  29311. }
  29312. /* Setup the signature r/s variables */
  29313. ret = mp_init(&r);
  29314. if (ret != MP_OKAY) {
  29315. wc_ecc_free(&ecc);
  29316. return WC_TEST_RET_ENC_EC(ret);
  29317. }
  29318. ret = mp_init(&s);
  29319. if (ret != MP_OKAY) {
  29320. mp_clear(&r);
  29321. wc_ecc_free(&ecc);
  29322. return WC_TEST_RET_ENC_EC(ret);
  29323. }
  29324. /* Import public key x/y */
  29325. ret = wc_ecc_import_unsigned(
  29326. &ecc,
  29327. (byte*)key, /* Public "x" Coordinate */
  29328. (byte*)(key + curveSz), /* Public "y" Coordinate */
  29329. NULL, /* Private "d" (optional) */
  29330. curveId /* ECC Curve Id */
  29331. );
  29332. /* Make sure it was a public key imported */
  29333. if (ret == 0 && ecc.type != ECC_PUBLICKEY) {
  29334. ret = WC_TEST_RET_ENC_NC; /* ECC_BAD_ARG_E */
  29335. }
  29336. /* Import signature r/s */
  29337. if (ret == 0) {
  29338. ret = mp_read_unsigned_bin(&r, sig, curveSz);
  29339. if (ret < 0)
  29340. ret = WC_TEST_RET_ENC_EC(ret);
  29341. }
  29342. if (ret == 0) {
  29343. ret = mp_read_unsigned_bin(&s, sig + curveSz, curveSz);
  29344. if (ret < 0)
  29345. ret = WC_TEST_RET_ENC_EC(ret);
  29346. }
  29347. /* Verify ECC Signature */
  29348. if (ret == 0) {
  29349. do {
  29350. ret = wc_ecc_verify_hash_ex(
  29351. &r, &s, /* r/s as mp_int */
  29352. hash, hashSz, /* computed hash digest */
  29353. &verify_res, /* verification result 1=success */
  29354. &ecc
  29355. );
  29356. count++;
  29357. /* This is where real-time work could be called */
  29358. } while (ret == FP_WOULDBLOCK);
  29359. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29360. printf("ECC non-block verify: %d times\n", count);
  29361. #endif
  29362. if (ret < 0)
  29363. ret = WC_TEST_RET_ENC_EC(ret);
  29364. }
  29365. /* check verify result */
  29366. if (ret == 0 && verify_res == 0) {
  29367. ret = WC_TEST_RET_ENC_NC /* SIG_VERIFY_E */;
  29368. }
  29369. mp_clear(&r);
  29370. mp_clear(&s);
  29371. wc_ecc_free(&ecc);
  29372. (void)count;
  29373. return ret;
  29374. }
  29375. /* perform signature operation against hash using private key */
  29376. static wc_test_ret_t crypto_ecc_sign(const byte *key, uint32_t keySz,
  29377. const byte *hash, uint32_t hashSz, byte *sig, uint32_t* sigSz,
  29378. uint32_t curveSz, int curveId, WC_RNG* rng)
  29379. {
  29380. wc_test_ret_t ret;
  29381. int count = 0;
  29382. mp_int r, s;
  29383. ecc_key ecc;
  29384. ecc_nb_ctx_t nb_ctx;
  29385. /* validate arguments */
  29386. if (key == NULL || hash == NULL || sig == NULL || sigSz == NULL ||
  29387. curveSz == 0 || hashSz == 0 || keySz < curveSz || *sigSz < (curveSz*2))
  29388. {
  29389. return WC_TEST_RET_ENC_NC /* BAD_FUNC_ARG */;
  29390. }
  29391. /* Initialize signature result */
  29392. memset(sig, 0, curveSz*2);
  29393. /* Setup the ECC key */
  29394. ret = wc_ecc_init(&ecc);
  29395. if (ret < 0) {
  29396. return WC_TEST_RET_ENC_EC(ret);
  29397. }
  29398. ret = wc_ecc_set_nonblock(&ecc, &nb_ctx);
  29399. if (ret != MP_OKAY) {
  29400. wc_ecc_free(&ecc);
  29401. return WC_TEST_RET_ENC_EC(ret);
  29402. }
  29403. /* Setup the signature r/s variables */
  29404. ret = mp_init(&r);
  29405. if (ret != MP_OKAY) {
  29406. wc_ecc_free(&ecc);
  29407. return WC_TEST_RET_ENC_EC(ret);
  29408. }
  29409. ret = mp_init(&s);
  29410. if (ret != MP_OKAY) {
  29411. mp_clear(&r);
  29412. wc_ecc_free(&ecc);
  29413. return WC_TEST_RET_ENC_EC(ret);
  29414. }
  29415. /* Import private key "k" */
  29416. ret = wc_ecc_import_private_key_ex(
  29417. key, keySz, /* private key "d" */
  29418. NULL, 0, /* public (optional) */
  29419. &ecc,
  29420. curveId /* ECC Curve Id */
  29421. );
  29422. if (ret < 0)
  29423. ret = WC_TEST_RET_ENC_EC(ret);
  29424. if (ret == 0) {
  29425. do {
  29426. /* Verify ECC Signature */
  29427. ret = wc_ecc_sign_hash_ex(
  29428. hash, hashSz, /* computed hash digest */
  29429. rng, &ecc, /* random and key context */
  29430. &r, &s /* r/s as mp_int */
  29431. );
  29432. count++;
  29433. /* This is where real-time work could be called */
  29434. } while (ret == FP_WOULDBLOCK);
  29435. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29436. printf("ECC non-block sign: %d times\n", count);
  29437. #endif
  29438. if (ret < 0)
  29439. ret = WC_TEST_RET_ENC_EC(ret);
  29440. }
  29441. if (ret == 0) {
  29442. /* export r/s */
  29443. mp_to_unsigned_bin_len(&r, sig, curveSz);
  29444. mp_to_unsigned_bin_len(&s, sig + curveSz, curveSz);
  29445. }
  29446. mp_clear(&r);
  29447. mp_clear(&s);
  29448. wc_ecc_free(&ecc);
  29449. (void)count;
  29450. return ret;
  29451. }
  29452. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29453. /*
  29454. * This test doesn't work with WOLFSSL_VALIDATE_ECC_KEYGEN defined because we
  29455. * don't have non-blocking versions of the key checking functions, yet.
  29456. */
  29457. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29458. static wc_test_ret_t ecc_test_nonblock_dhe(int curveId, word32 curveSz,
  29459. const byte* privKey, const byte* pubKey, WC_RNG* rng)
  29460. {
  29461. wc_test_ret_t ret;
  29462. ecc_key keyA;
  29463. ecc_key keyB;
  29464. ecc_nb_ctx_t nbCtxA;
  29465. ecc_nb_ctx_t nbCtxB;
  29466. byte secretA[ECC_SHARED_SIZE];
  29467. byte secretB[ECC_SHARED_SIZE];
  29468. word32 secretSzA = ECC_SHARED_SIZE;
  29469. word32 secretSzB = ECC_SHARED_SIZE;
  29470. int count = 0;
  29471. ret = wc_ecc_init(&keyA);
  29472. if (ret == 0) {
  29473. ret = wc_ecc_init(&keyB);
  29474. if (ret < 0)
  29475. ret = WC_TEST_RET_ENC_EC(ret);
  29476. }
  29477. if (ret == 0) {
  29478. ret = wc_ecc_set_nonblock(&keyA, &nbCtxA);
  29479. if (ret < 0)
  29480. ret = WC_TEST_RET_ENC_EC(ret);
  29481. }
  29482. if (ret == 0) {
  29483. ret = wc_ecc_set_nonblock(&keyB, &nbCtxB);
  29484. if (ret < 0)
  29485. ret = WC_TEST_RET_ENC_EC(ret);
  29486. }
  29487. if (ret == 0) {
  29488. do {
  29489. ret = wc_ecc_make_key_ex(rng, curveSz, &keyA, curveId);
  29490. count++;
  29491. } while (ret == FP_WOULDBLOCK);
  29492. if (ret < 0)
  29493. ret = WC_TEST_RET_ENC_EC(ret);
  29494. }
  29495. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29496. fprintf(stderr, "ECC non-block key gen: %d times\n", count);
  29497. #endif
  29498. if (ret == 0) {
  29499. ret = wc_ecc_check_key(&keyA);
  29500. if (ret < 0)
  29501. ret = WC_TEST_RET_ENC_EC(ret);
  29502. }
  29503. if (ret == 0) {
  29504. ret = wc_ecc_import_unsigned(&keyB, pubKey, pubKey + curveSz,
  29505. privKey, curveId);
  29506. if (ret < 0)
  29507. ret = WC_TEST_RET_ENC_EC(ret);
  29508. }
  29509. count = 0;
  29510. if (ret == 0) {
  29511. do {
  29512. ret = wc_ecc_shared_secret(&keyA, &keyB, secretA, &secretSzA);
  29513. count++;
  29514. } while (ret == FP_WOULDBLOCK);
  29515. if (ret < 0)
  29516. ret = WC_TEST_RET_ENC_EC(ret);
  29517. }
  29518. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  29519. fprintf(stderr, "ECC non-block shared secret: %d times\n", count);
  29520. #endif
  29521. if (ret == 0) {
  29522. do {
  29523. ret = wc_ecc_shared_secret(&keyB, &keyA, secretB, &secretSzB);
  29524. } while (ret == FP_WOULDBLOCK);
  29525. if (ret < 0)
  29526. ret = WC_TEST_RET_ENC_EC(ret);
  29527. }
  29528. if (ret == 0) {
  29529. if (secretSzA != secretSzB ||
  29530. XMEMCMP(secretA, secretB, secretSzA) != 0) {
  29531. ret = WC_TEST_RET_ENC_NC;
  29532. }
  29533. }
  29534. wc_ecc_free(&keyA);
  29535. wc_ecc_free(&keyB);
  29536. return ret;
  29537. }
  29538. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29539. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29540. static wc_test_ret_t ecc_test_nonblock_ecdsa(int curveId, word32 curveSz,
  29541. const byte* privKey, word32 privKeySz, const byte* pubKey, word32 pubKeySz,
  29542. WC_RNG* rng)
  29543. {
  29544. wc_test_ret_t ret = 0;
  29545. byte* sig = NULL;
  29546. word32 sigSz = curveSz * 2;
  29547. static const byte hash[] = {
  29548. 0x8d, 0x28, 0xa3, 0x8b, 0x0b, 0xa9, 0xfe, 0xd4, 0x0e, 0x54, 0xc4, 0x17,
  29549. 0x3d, 0x54, 0x66, 0x34, 0xbf, 0x5d, 0x6f, 0x46, 0xc2, 0x20, 0xcb, 0xc3,
  29550. 0x22, 0xe9, 0xb0, 0xdf, 0xe7, 0x64, 0x3f, 0xd9
  29551. };
  29552. sig = (byte*)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29553. if (sig == NULL) {
  29554. ret = WC_TEST_RET_ENC_ERRNO;
  29555. }
  29556. if (ret == 0) {
  29557. /* Sign hash using private key */
  29558. /* Note: result of an ECC sign varies for each call even with same
  29559. private key and hash. This is because a new random public key is
  29560. used for each operation. */
  29561. ret = crypto_ecc_sign(privKey, privKeySz, hash, sizeof(hash), sig,
  29562. &sigSz, curveSz, curveId, rng);
  29563. }
  29564. if (ret == 0) {
  29565. /* Verify generated signature is valid */
  29566. ret = crypto_ecc_verify(pubKey, pubKeySz, hash, sizeof(hash), sig,
  29567. sigSz, curveSz, curveId);
  29568. }
  29569. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_SIGNATURE);
  29570. return ret;
  29571. }
  29572. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29573. static wc_test_ret_t ecc_test_nonblock(WC_RNG* rng)
  29574. {
  29575. wc_test_ret_t ret = 0;
  29576. word32 i;
  29577. int curveIds[3] = {0, 0, 0};
  29578. word32 curveSzs[3] = {0, 0, 0};
  29579. const byte* privKeys[3] = {NULL, NULL, NULL};
  29580. word32 privKeySzs[3] = {0, 0, 0};
  29581. const byte* pubKeys[3] = {NULL, NULL, NULL};
  29582. word32 pubKeySzs[3] = {0, 0, 0};
  29583. curveIds[0] = ECC_SECP256R1;
  29584. curveSzs[0] = 32;
  29585. privKeys[0] = p256PrivKey;
  29586. privKeySzs[0] = sizeof(p256PrivKey);
  29587. pubKeys[0] = p256PubKey;
  29588. pubKeySzs[0] = sizeof(p256PubKey);
  29589. #ifdef HAVE_ECC384
  29590. curveIds[1] = ECC_SECP384R1;
  29591. curveSzs[1] = 48;
  29592. privKeys[1] = p384PrivKey;
  29593. privKeySzs[1] = sizeof(p384PrivKey);
  29594. pubKeys[1] = p384PubKey;
  29595. pubKeySzs[1] = sizeof(p384PubKey);
  29596. #endif
  29597. #ifdef HAVE_ECC521
  29598. curveIds[2] = ECC_SECP521R1;
  29599. curveSzs[2] = 66;
  29600. privKeys[2] = p521PrivKey;
  29601. privKeySzs[2] = sizeof(p521PrivKey);
  29602. pubKeys[2] = p521PubKey;
  29603. pubKeySzs[2] = sizeof(p521PubKey);
  29604. #endif
  29605. for (i = 0; ret == 0 && i < sizeof(curveIds) / sizeof(curveIds[0]); ++i) {
  29606. if (curveIds[i] == 0) {
  29607. continue;
  29608. }
  29609. #if defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29610. ret = ecc_test_nonblock_ecdsa(curveIds[i], curveSzs[i], privKeys[i],
  29611. privKeySzs[i], pubKeys[i], pubKeySzs[i], rng);
  29612. #endif /* HAVE_ECC_SIGN && HAVE_ECC_VERIFY */
  29613. #if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_VALIDATE_ECC_KEYGEN)
  29614. if (ret == 0) {
  29615. ret = ecc_test_nonblock_dhe(curveIds[i], curveSzs[i], privKeys[i],
  29616. pubKeys[i], rng);
  29617. }
  29618. #endif /* HAVE_ECC_DHE && !WOLFSSL_VALIDATE_ECC_KEYGEN */
  29619. }
  29620. return ret;
  29621. }
  29622. #endif /* WC_ECC_NONBLOCK && WOLFSSL_HAVE_SP_ECC && WOLFSSL_PUBLIC_MP */
  29623. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29624. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29625. (HAVE_FIPS_VERSION > 2)))
  29626. static int ecc_test_raw_enc_dec(void)
  29627. {
  29628. int ret;
  29629. unsigned char r[1];
  29630. word32 rSz;
  29631. unsigned char s[1];
  29632. word32 sSz;
  29633. unsigned char rZero[] = { 0, 0, 0, 0 };
  29634. unsigned char sOne[] = { 0, 0, 1 };
  29635. unsigned char sigRaw[32];
  29636. word32 sigRawSz;
  29637. unsigned char expSig[] = { 0x30, 0x06, 0x02, 0x01, 0x00, 0x02, 0x01, 0x01 };
  29638. sigRawSz = sizeof(sigRaw);
  29639. ret = wc_ecc_rs_raw_to_sig(rZero, sizeof(rZero), sOne, sizeof(sOne),
  29640. sigRaw, &sigRawSz);
  29641. if (ret != 0) {
  29642. return WC_TEST_RET_ENC_EC(ret);
  29643. }
  29644. if (sigRawSz != sizeof(expSig)) {
  29645. return WC_TEST_RET_ENC_EC((int)sigRawSz);
  29646. }
  29647. if (XMEMCMP(sigRaw, expSig, sizeof(expSig)) != 0) {
  29648. return WC_TEST_RET_ENC_NC;
  29649. }
  29650. rSz = sizeof(r);
  29651. sSz = sizeof(s);
  29652. ret = wc_ecc_sig_to_rs(sigRaw, sigRawSz, r, &rSz, s, &sSz);
  29653. if (ret != 0) {
  29654. return WC_TEST_RET_ENC_EC(ret);
  29655. }
  29656. if (rSz != 1) {
  29657. return WC_TEST_RET_ENC_EC((int)rSz);
  29658. }
  29659. if (sSz != 1) {
  29660. return WC_TEST_RET_ENC_EC((int)sSz);
  29661. }
  29662. if (r[0] != 0) {
  29663. return WC_TEST_RET_ENC_EC(r[0]);
  29664. }
  29665. if (s[0] != 1) {
  29666. return WC_TEST_RET_ENC_EC(s[0]);
  29667. }
  29668. return ret;
  29669. }
  29670. #endif
  29671. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test(void)
  29672. {
  29673. wc_test_ret_t ret;
  29674. WC_RNG rng;
  29675. WOLFSSL_ENTER("ecc_test");
  29676. #if defined(ECC_MIN_KEY_SZ)
  29677. WOLFSSL_MSG_EX("ecc_test ECC_MIN_KEY_SZ = %d\n", ECC_MIN_KEY_SZ);
  29678. #else
  29679. WOLFSSL_MSG("ecc_test ECC_MIN_KEY_SZ not defined.");
  29680. #endif
  29681. #if defined(WOLFSSL_CERT_EXT) && \
  29682. (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29683. ret = ecc_decode_test();
  29684. if (ret < 0)
  29685. return ret;
  29686. #endif
  29687. #ifndef HAVE_FIPS
  29688. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  29689. #else
  29690. ret = wc_InitRng(&rng);
  29691. #endif
  29692. #ifndef WC_NO_RNG
  29693. if (ret != 0)
  29694. return WC_TEST_RET_ENC_EC(ret);
  29695. #else
  29696. (void)ret;
  29697. #endif
  29698. #if (defined(HAVE_ECC112) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 112
  29699. ret = ecc_test_curve(&rng, 14, ECC_CURVE_DEF);
  29700. if (ret < 0) {
  29701. printf("keySize=14, Default\n");
  29702. goto done;
  29703. }
  29704. #endif /* HAVE_ECC112 */
  29705. #if (defined(HAVE_ECC128) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 128
  29706. ret = ecc_test_curve(&rng, 16, ECC_CURVE_DEF);
  29707. if (ret < 0) {
  29708. printf("keySize=16, Default\n");
  29709. goto done;
  29710. }
  29711. #endif /* HAVE_ECC128 */
  29712. #if (defined(HAVE_ECC160) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 160
  29713. ret = ecc_test_curve(&rng, 20, ECC_CURVE_DEF);
  29714. if (ret < 0) {
  29715. printf("keySize=20, Default\n");
  29716. goto done;
  29717. }
  29718. #endif /* HAVE_ECC160 */
  29719. #if (defined(HAVE_ECC192) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 192
  29720. #if !FIPS_VERSION3_GE(6,0,0)
  29721. ret = ecc_test_curve(&rng, 24, ECC_CURVE_DEF);
  29722. if (ret < 0) {
  29723. printf("keySize=24, Default\n");
  29724. goto done;
  29725. }
  29726. #endif
  29727. #endif /* HAVE_ECC192 */
  29728. #if (defined(HAVE_ECC224) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 224
  29729. ret = ecc_test_curve(&rng, 28, ECC_CURVE_DEF);
  29730. if (ret < 0) {
  29731. printf("keySize=28, Default\n");
  29732. goto done;
  29733. }
  29734. #endif /* HAVE_ECC224 */
  29735. #if (defined(HAVE_ECC239) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 239
  29736. ret = ecc_test_curve(&rng, 30, ECC_CURVE_DEF);
  29737. if (ret < 0) {
  29738. printf("keySize=30, Default\n");
  29739. goto done;
  29740. }
  29741. #endif /* HAVE_ECC239 */
  29742. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29743. ret = ecc_test_curve(&rng, 32, ECC_CURVE_DEF);
  29744. if (ret < 0) {
  29745. printf("keySize=32, Default\n");
  29746. goto done;
  29747. }
  29748. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29749. defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
  29750. !defined(WOLFSSL_NO_MALLOC) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
  29751. ret = ecc_point_test();
  29752. if (ret < 0) {
  29753. goto done;
  29754. }
  29755. #endif
  29756. #if !defined(NO_ECC_SECP) || defined(WOLFSSL_CUSTOM_CURVES)
  29757. ret = ecc_def_curve_test(&rng);
  29758. if (ret < 0) {
  29759. printf("Default\n");
  29760. goto done;
  29761. }
  29762. #endif
  29763. #endif /* !NO_ECC256 */
  29764. #if (defined(HAVE_ECC320) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 320
  29765. ret = ecc_test_curve(&rng, 40, ECC_CURVE_DEF);
  29766. if (ret < 0) {
  29767. printf("keySize=40, Default\n");
  29768. goto done;
  29769. }
  29770. #endif /* HAVE_ECC320 */
  29771. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 384
  29772. ret = ecc_test_curve(&rng, 48, ECC_CURVE_DEF);
  29773. if (ret < 0) {
  29774. printf("keySize=48, Default\n");
  29775. goto done;
  29776. }
  29777. #endif /* HAVE_ECC384 */
  29778. #if (defined(HAVE_ECC512) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 512
  29779. ret = ecc_test_curve(&rng, 64, ECC_CURVE_DEF);
  29780. if (ret < 0) {
  29781. printf("keySize=64, Default\n");
  29782. goto done;
  29783. }
  29784. #endif /* HAVE_ECC512 */
  29785. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 521
  29786. ret = ecc_test_curve(&rng, 66, ECC_CURVE_DEF);
  29787. if (ret < 0) {
  29788. printf("keySize=66, Default\n");
  29789. goto done;
  29790. }
  29791. #endif /* HAVE_ECC521 */
  29792. #ifdef WOLFSSL_SM2
  29793. ret = ecc_test_curve(&rng, 32, ECC_SM2P256V1);
  29794. if (ret < 0) {
  29795. printf("SM2\n");
  29796. goto done;
  29797. }
  29798. #endif
  29799. #if !defined(NO_ASN) && !defined(HAVE_SELFTEST) && \
  29800. (!defined(HAVE_FIPS) || (defined(HAVE_FIPS_VERSION) && \
  29801. (HAVE_FIPS_VERSION > 2)))
  29802. ret = ecc_test_raw_enc_dec();
  29803. if (ret != 0) {
  29804. printf("raw sig encode/decode\n");
  29805. goto done;
  29806. }
  29807. #endif
  29808. #if defined(WOLFSSL_CUSTOM_CURVES)
  29809. ret = ecc_test_custom_curves(&rng);
  29810. if (ret != 0) {
  29811. printf("Custom\n");
  29812. goto done;
  29813. }
  29814. #endif
  29815. #if defined(WOLFSSL_SM2)
  29816. ret = test_sm2_verify();
  29817. if (ret != 0) {
  29818. printf("SM2 Verify\n");
  29819. goto done;
  29820. }
  29821. ret = ecc_sm2_test_curve(&rng, ECC_TEST_VERIFY_COUNT);
  29822. if (ret != 0) {
  29823. printf("SM2 test\n");
  29824. goto done;
  29825. }
  29826. #endif
  29827. #if defined(HAVE_ECC_SIGN) && \
  29828. (defined(WOLFSSL_ECDSA_DETERMINISTIC_K) || \
  29829. defined(WOLFSSL_ECDSA_DETERMINISTIC_K_VARIANT)) && \
  29830. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5,3))
  29831. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && ECC_MIN_KEY_SZ <= 256
  29832. ret = ecc_test_deterministic_k(&rng);
  29833. if (ret != 0) {
  29834. printf("ecc_test_deterministic_k failed!\n");
  29835. goto done;
  29836. }
  29837. #endif
  29838. #ifdef WOLFSSL_PUBLIC_MP
  29839. #if (defined(HAVE_ECC384) || defined(HAVE_ALL_CURVES)) && \
  29840. ECC_MIN_KEY_SZ <= 384
  29841. ret = ecc384_test_deterministic_k(&rng);
  29842. if (ret != 0) {
  29843. printf("ecc384_test_deterministic_k failed!\n");
  29844. goto done;
  29845. }
  29846. #endif
  29847. #if (defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)) && \
  29848. ECC_MIN_KEY_SZ <= 521
  29849. ret = ecc521_test_deterministic_k(&rng);
  29850. if (ret != 0) {
  29851. printf("ecc512_test_deterministic_k failed!\n");
  29852. goto done;
  29853. }
  29854. #endif
  29855. #endif
  29856. #endif
  29857. #if defined(HAVE_ECC_SIGN) && defined(WOLFSSL_ECDSA_SET_K) && \
  29858. !defined(WOLFSSL_KCAPI_ECC)
  29859. ret = ecc_test_sign_vectors(&rng);
  29860. if (ret != 0) {
  29861. printf("ecc_test_sign_vectors failed!\n");
  29862. goto done;
  29863. }
  29864. #endif
  29865. #if defined(HAVE_ECC_VECTOR_TEST) && defined(HAVE_ECC_CDH) && \
  29866. defined(HAVE_ECC_DHE)
  29867. ret = ecc_test_cdh_vectors(&rng);
  29868. if (ret != 0) {
  29869. printf("ecc_test_cdh_vectors failed!\n");
  29870. goto done;
  29871. }
  29872. #endif
  29873. #if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
  29874. !defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
  29875. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  29876. ret = ecc_test_make_pub(&rng);
  29877. if (ret != 0) {
  29878. printf("ecc_test_make_pub failed!\n");
  29879. goto done;
  29880. }
  29881. #elif defined(HAVE_ECC_KEY_IMPORT)
  29882. (void)ecc_test_make_pub; /* for compiler warning */
  29883. #endif
  29884. #if defined(WOLFSSL_CERT_GEN) && !defined(NO_ECC_SECP) && \
  29885. !defined(NO_ASN_TIME) && !defined(WOLFSSL_NO_MALLOC)
  29886. ret = ecc_test_cert_gen(&rng);
  29887. if (ret != 0) {
  29888. printf("ecc_test_cert_gen failed!\n");
  29889. goto done;
  29890. }
  29891. #endif
  29892. #if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) && \
  29893. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && (!defined(NO_ECC_SECP) || \
  29894. defined(WOLFSSL_CUSTOM_CURVES))
  29895. ret = ecc_test_allocator(&rng);
  29896. if (ret != 0) {
  29897. printf("ecc_test_allocator failed!\n");
  29898. goto done;
  29899. }
  29900. #endif
  29901. #if defined(WC_ECC_NONBLOCK) && defined(WOLFSSL_PUBLIC_MP) && \
  29902. defined(HAVE_ECC_SIGN) && defined(HAVE_ECC_VERIFY)
  29903. ret = ecc_test_nonblock(&rng);
  29904. if (ret != 0) {
  29905. printf("ecc_test_nonblock failed!\n");
  29906. goto done;
  29907. }
  29908. #endif
  29909. done:
  29910. wc_FreeRng(&rng);
  29911. return ret;
  29912. }
  29913. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_AES_CBC) && \
  29914. (defined(WOLFSSL_AES_128) || defined(WOLFSSL_AES_256))
  29915. #if !defined(WOLFSSL_NO_MALLOC)
  29916. #if ((! defined(HAVE_FIPS)) || FIPS_VERSION_GE(5,3))
  29917. /* maximum encrypted message:
  29918. * msgSz (14) + pad (2) + pubKeySz(1+66*2) + ivSz(16) + digestSz(32) = 197 */
  29919. #define MAX_ECIES_TEST_SZ 200
  29920. static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
  29921. {
  29922. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29923. byte* plaintext;
  29924. byte* encrypted;
  29925. byte* decrypted;
  29926. #else
  29927. byte plaintext[MAX_ECIES_TEST_SZ];
  29928. byte encrypted[MAX_ECIES_TEST_SZ];
  29929. byte decrypted[MAX_ECIES_TEST_SZ];
  29930. #endif
  29931. ecEncCtx* aCtx = NULL;
  29932. ecEncCtx* bCtx = NULL;
  29933. static const byte salt[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  29934. 14, 15};
  29935. wc_test_ret_t ret = 0;
  29936. static const char message[] = "Hello wolfSSL!";
  29937. word32 plaintextLen;
  29938. word32 encryptLen = MAX_ECIES_TEST_SZ;
  29939. word32 decryptLen = MAX_ECIES_TEST_SZ;
  29940. int aInit = 0;
  29941. int bInit = 0;
  29942. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  29943. plaintext = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29944. encrypted = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29945. decrypted = (byte*)XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  29946. #endif
  29947. wc_ecc_free(a);
  29948. wc_ecc_free(b);
  29949. ret = wc_ecc_init(a);
  29950. if (ret != 0) {
  29951. ret = WC_TEST_RET_ENC_EC(ret);
  29952. }
  29953. else {
  29954. aInit = 1;
  29955. }
  29956. if (ret == 0) {
  29957. ret = wc_ecc_init(b);
  29958. if (ret != 0) {
  29959. ret = WC_TEST_RET_ENC_EC(ret);
  29960. }
  29961. else {
  29962. bInit = 1;
  29963. }
  29964. }
  29965. if (ret == 0)
  29966. ret = wc_ecc_make_key(rng, 32, a);
  29967. if (ret == 0)
  29968. ret = wc_ecc_make_key(rng, 32, b);
  29969. /* create context */
  29970. if (ret == 0) {
  29971. aCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  29972. if (aCtx == NULL)
  29973. ret = WC_TEST_RET_ENC_NC;
  29974. }
  29975. if (ret == 0) {
  29976. bCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  29977. if (bCtx == NULL)
  29978. ret = WC_TEST_RET_ENC_NC;
  29979. }
  29980. /* set salt */
  29981. if (ret == 0) {
  29982. ret = wc_ecc_ctx_set_kdf_salt(aCtx, salt, sizeof(salt));
  29983. if (ret != 0)
  29984. ret = 10472;
  29985. }
  29986. if (ret == 0) {
  29987. ret = wc_ecc_ctx_set_kdf_salt(bCtx, salt, sizeof(salt));
  29988. if (ret != 0)
  29989. ret = 10473;
  29990. }
  29991. XMEMSET(plaintext, 0, MAX_ECIES_TEST_SZ);
  29992. XSTRLCPY((char *)plaintext, message, sizeof plaintext);
  29993. plaintextLen = (((word32)XSTRLEN(message) + AES_BLOCK_SIZE - 1) /
  29994. AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
  29995. /* encrypt */
  29996. if (ret == 0) {
  29997. ret = wc_ecc_encrypt(a, b, plaintext, plaintextLen, encrypted,
  29998. &encryptLen, aCtx);
  29999. if (ret != 0)
  30000. ret = WC_TEST_RET_ENC_EC(ret);
  30001. }
  30002. /* decrypt */
  30003. if (ret == 0) {
  30004. ret = wc_ecc_decrypt(b, a, encrypted, encryptLen, decrypted,
  30005. &decryptLen, bCtx);
  30006. if (ret != 0)
  30007. ret = WC_TEST_RET_ENC_EC(ret);
  30008. }
  30009. /* compare */
  30010. if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
  30011. ret = WC_TEST_RET_ENC_NC;
  30012. if (aInit) {
  30013. wc_ecc_free(a);
  30014. }
  30015. if (bInit) {
  30016. wc_ecc_free(b);
  30017. }
  30018. wc_ecc_ctx_free(aCtx);
  30019. wc_ecc_ctx_free(bCtx);
  30020. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30021. XFREE(plaintext, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30022. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30023. XFREE(decrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30024. #endif
  30025. return ret;
  30026. }
  30027. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30028. #endif /* !WOLFSSL_NO_MALLOC */
  30029. /* ecc_encrypt_e2e_test() uses wc_ecc_ctx_set_algo(), which was added in
  30030. * wolfFIPS 5.3.
  30031. * ecc_encrypt_kat() is used only by ecc_encrypt_e2e_test().
  30032. */
  30033. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30034. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30035. ECC_MIN_KEY_SZ <= 256 && defined(WOLFSSL_AES_128)
  30036. static wc_test_ret_t ecc_encrypt_kat(WC_RNG *rng)
  30037. {
  30038. wc_test_ret_t ret = 0;
  30039. #ifdef WOLFSSL_ECIES_OLD
  30040. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30041. ecc_key* userA = NULL;
  30042. #else
  30043. ecc_key userA[1];
  30044. #endif
  30045. int userAInit = 0;
  30046. #endif
  30047. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30048. ecc_key* userB = NULL;
  30049. #else
  30050. ecc_key userB[1];
  30051. #endif
  30052. int userBInit = 0;
  30053. ecc_key* tmpKey;
  30054. byte plain[48];
  30055. word32 plainSz = sizeof(plain);
  30056. WOLFSSL_SMALL_STACK_STATIC const byte privKey[] = {
  30057. 0x04, 0x80, 0xef, 0x1d, 0xbe, 0x02, 0x0c, 0x20,
  30058. 0x5b, 0xab, 0x80, 0x35, 0x5b, 0x2a, 0x0f, 0x6d,
  30059. 0xd3, 0xb0, 0x7f, 0x7e, 0x7f, 0x86, 0x8a, 0x49,
  30060. 0xee, 0xb4, 0xaa, 0x09, 0x2d, 0x1e, 0x1d, 0x02
  30061. };
  30062. #if defined(WOLFSSL_ECIES_OLD) || defined(WOLFSSL_QNX_CAAM)
  30063. WOLFSSL_SMALL_STACK_STATIC const byte pubKey[] = {
  30064. 0x04,
  30065. /* X */
  30066. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30067. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30068. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30069. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30070. /* X */
  30071. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30072. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30073. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30074. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28
  30075. };
  30076. #endif
  30077. WOLFSSL_SMALL_STACK_STATIC const byte enc_msg[] = {
  30078. #ifdef WOLFSSL_ECIES_OLD
  30079. 0x42, 0x70, 0xbf, 0xf9, 0xf4, 0x7e, 0x4b, 0x9b,
  30080. 0xb5, 0x4c, 0xcc, 0xc5, 0x94, 0xa7, 0xef, 0xaa,
  30081. 0xc3, 0x7c, 0x85, 0xa6, 0x51, 0x6e, 0xd3, 0xfa,
  30082. 0x56, 0xc9, 0x10, 0x4d, 0x14, 0x32, 0x61, 0xb8,
  30083. 0xbb, 0x66, 0x7a, 0xb5, 0xbc, 0x95, 0xf8, 0xca,
  30084. 0xd1, 0x2a, 0x19, 0x51, 0x44, 0xd8, 0x0e, 0x57,
  30085. 0x34, 0xed, 0x45, 0x89, 0x2e, 0x57, 0xbe, 0xd5,
  30086. 0x06, 0x22, 0xd7, 0x13, 0x0a, 0x0e, 0x40, 0x36,
  30087. 0x0d, 0x05, 0x0d, 0xb6, 0xae, 0x61, 0x37, 0x18,
  30088. 0x83, 0x90, 0x0a, 0x27, 0x95, 0x41, 0x8c, 0x45
  30089. #elif defined(WOLFSSL_ECIES_ISO18033)
  30090. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30091. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30092. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30093. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30094. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30095. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30096. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30097. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30098. 0x28, 0xbb, 0x9f, 0xa8, 0x2d, 0xe1, 0xf1, 0x67,
  30099. 0x45, 0x02, 0x19, 0xdc, 0xc8, 0x24, 0x8b, 0x20,
  30100. 0x02, 0xa0, 0x8f, 0x95, 0x12, 0x55, 0x51, 0xf8,
  30101. 0x03, 0xc4, 0x54, 0x13, 0x98, 0x2d, 0xf0, 0x31,
  30102. 0x51, 0x80, 0x45, 0x24, 0xcb, 0x8b, 0x48, 0xa6,
  30103. 0x8b, 0x8e, 0x97, 0x9c, 0x56, 0x4d, 0x70, 0x00,
  30104. 0x53, 0xd3, 0x47, 0x00, 0x5a, 0x23, 0x8c, 0xf9,
  30105. 0xfd, 0xd2, 0x33, 0x2c, 0x43, 0x6e, 0x9e, 0xb2,
  30106. 0xf4, 0x95, 0xd4, 0xcf, 0x30, 0xd6, 0xa2, 0xc5,
  30107. 0x35, 0x96, 0x6a, 0xd4, 0x36, 0x15, 0xa9, 0xbd,
  30108. 0x7f
  30109. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30110. /* EC P-256 point */
  30111. 0x04,
  30112. /* X */
  30113. 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0, 0x5a,
  30114. 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c, 0x3a,
  30115. 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3, 0xc1,
  30116. 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63, 0xa0,
  30117. /* Y */
  30118. 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7, 0xcd,
  30119. 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75, 0xaa,
  30120. 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe, 0xe8,
  30121. 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3, 0x28,
  30122. /* IV */
  30123. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30124. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  30125. /* Encrypted Msg */
  30126. 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d, 0x50,
  30127. 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c, 0x1f,
  30128. 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc, 0x44,
  30129. 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca, 0x65,
  30130. 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61, 0xbd,
  30131. 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1, 0xde,
  30132. /* HMAC */
  30133. 0x5a, 0x22, 0xc1, 0x5d, 0x99, 0x66, 0x3f, 0x24,
  30134. 0x35, 0x96, 0xac, 0xf7, 0xf6, 0x28, 0x45, 0x16,
  30135. 0x52, 0x19, 0x0d, 0xe4, 0xb2, 0xca, 0x5b, 0x28,
  30136. 0x4e, 0xbb, 0xf3, 0x98, 0x57, 0xd7, 0x3b, 0xe2
  30137. #else
  30138. 0x04, 0x50, 0xf2, 0x93, 0xa2, 0x48, 0xa9, 0xc0,
  30139. 0x5a, 0x9a, 0xa7, 0x70, 0x34, 0xb7, 0x7f, 0x4c,
  30140. 0x3a, 0xad, 0xfc, 0xd8, 0xb6, 0x76, 0x0a, 0xe3,
  30141. 0xc1, 0x87, 0x17, 0x07, 0x2d, 0x8d, 0xa3, 0x63,
  30142. 0xa0, 0xc1, 0x27, 0xb2, 0x97, 0x9b, 0x84, 0xe7,
  30143. 0xcd, 0x20, 0x65, 0x8d, 0x2b, 0x6a, 0x93, 0x75,
  30144. 0xaa, 0x8b, 0xe1, 0x3a, 0x7b, 0x24, 0x1a, 0xbe,
  30145. 0xe8, 0x36, 0xd2, 0xe6, 0x34, 0x8a, 0x7a, 0xb3,
  30146. 0x28, 0xe5, 0x17, 0xaf, 0x0d, 0x65, 0x4d, 0x3d,
  30147. 0x50, 0x96, 0x05, 0xc9, 0x63, 0x2c, 0xef, 0x1c,
  30148. 0x1f, 0x78, 0xc9, 0x90, 0x7a, 0x14, 0x00, 0xfc,
  30149. 0x44, 0x71, 0x6d, 0x57, 0x8c, 0xdf, 0x23, 0xca,
  30150. 0x65, 0xcf, 0x93, 0x06, 0xb6, 0x9a, 0xf4, 0x61,
  30151. 0xbd, 0x44, 0x1a, 0xeb, 0x52, 0x68, 0x0f, 0xd1,
  30152. 0xde, 0xc7, 0x3f, 0x6f, 0xce, 0xbe, 0x49, 0x61,
  30153. 0x48, 0x01, 0x77, 0x41, 0xd0, 0xd8, 0x5b, 0x48,
  30154. 0xca, 0x4e, 0x47, 0x3e, 0x47, 0xbf, 0x1d, 0x28,
  30155. 0x4c, 0x18, 0x1a, 0xfb, 0x96, 0x95, 0xda, 0xde,
  30156. 0x55
  30157. #endif
  30158. };
  30159. WOLFSSL_SMALL_STACK_STATIC const byte msg[] = {
  30160. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  30161. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  30162. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  30163. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  30164. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  30165. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
  30166. };
  30167. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30168. userB = (ecc_key *)XMALLOC(sizeof(*userB), HEAP_HINT,
  30169. DYNAMIC_TYPE_TMP_BUFFER);
  30170. if (userB == NULL) {
  30171. ret = WC_TEST_RET_ENC_ERRNO;
  30172. }
  30173. #ifdef WOLFSSL_ECIES_OLD
  30174. if (ret == 0) {
  30175. userA = (ecc_key *)XMALLOC(sizeof(*userA), HEAP_HINT,
  30176. DYNAMIC_TYPE_TMP_BUFFER);
  30177. if (userA == NULL) {
  30178. ret = WC_TEST_RET_ENC_ERRNO;
  30179. }
  30180. }
  30181. #endif
  30182. #endif
  30183. if (ret == 0) {
  30184. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30185. if (ret != 0)
  30186. ret = WC_TEST_RET_ENC_EC(ret);
  30187. }
  30188. if (ret == 0) {
  30189. userBInit = 1;
  30190. #ifdef WOLFSSL_ECIES_OLD
  30191. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30192. if (ret != 0)
  30193. ret = WC_TEST_RET_ENC_EC(ret);
  30194. }
  30195. if (ret == 0) {
  30196. userAInit = 1;
  30197. tmpKey = userA;
  30198. #else
  30199. tmpKey = NULL;
  30200. #endif
  30201. }
  30202. if (ret == 0) {
  30203. #ifdef WOLFSSL_QNX_CAAM
  30204. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), pubKey,
  30205. sizeof(pubKey), userB, ECC_SECP256R1);
  30206. #else
  30207. ret = wc_ecc_import_private_key_ex(privKey, sizeof(privKey), NULL, 0,
  30208. userB, ECC_SECP256R1);
  30209. #endif
  30210. if (ret != 0)
  30211. ret = WC_TEST_RET_ENC_EC(ret);
  30212. }
  30213. #ifdef WOLFSSL_ECIES_OLD
  30214. if (ret == 0) {
  30215. ret = wc_ecc_import_x963_ex(pubKey, sizeof(pubKey), userA,
  30216. ECC_SECP256R1);
  30217. if (ret != 0)
  30218. ret = WC_TEST_RET_ENC_EC(ret);
  30219. }
  30220. #endif
  30221. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30222. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30223. !defined(HAVE_SELFTEST)
  30224. if (ret == 0) {
  30225. ret = wc_ecc_set_rng(userB, rng);
  30226. if (ret != 0) {
  30227. ret = WC_TEST_RET_ENC_EC(ret);
  30228. }
  30229. }
  30230. #else
  30231. (void)rng;
  30232. #endif
  30233. if (ret == 0) {
  30234. ret = wc_ecc_decrypt(userB, tmpKey, enc_msg, sizeof(enc_msg), plain,
  30235. &plainSz, NULL);
  30236. if (ret != 0)
  30237. ret = WC_TEST_RET_ENC_EC(ret);
  30238. }
  30239. if (ret == 0) {
  30240. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30241. ret = WC_TEST_RET_ENC_NC;
  30242. }
  30243. }
  30244. if (userBInit)
  30245. wc_ecc_free(userB);
  30246. #ifdef WOLFSSL_ECIES_OLD
  30247. if (userAInit)
  30248. wc_ecc_free(userA);
  30249. #endif
  30250. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30251. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30252. #ifdef WOLFSSL_ECIES_OLD
  30253. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30254. #endif
  30255. #endif
  30256. return ret;
  30257. }
  30258. #endif
  30259. #ifndef WOLFSSL_NO_MALLOC
  30260. static wc_test_ret_t ecc_encrypt_e2e_test(WC_RNG* rng, ecc_key* userA, ecc_key* userB,
  30261. byte encAlgo, byte kdfAlgo, byte macAlgo)
  30262. {
  30263. wc_test_ret_t ret = 0;
  30264. byte msg[48];
  30265. byte plain[48];
  30266. #ifdef WOLFSSL_ECIES_OLD
  30267. byte out[80];
  30268. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30269. byte out[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30270. #else
  30271. byte out[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30272. #endif
  30273. word32 outSz = sizeof(out);
  30274. word32 plainSz = sizeof(plain);
  30275. int i;
  30276. ecEncCtx* cliCtx = NULL;
  30277. ecEncCtx* srvCtx = NULL;
  30278. byte cliSalt[EXCHANGE_SALT_SZ];
  30279. byte srvSalt[EXCHANGE_SALT_SZ];
  30280. const byte* tmpSalt;
  30281. byte msg2[48];
  30282. byte plain2[48];
  30283. #ifdef WOLFSSL_ECIES_OLD
  30284. byte out2[80];
  30285. #elif defined(WOLFSSL_ECIES_GEN_IV)
  30286. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 16 + 80];
  30287. #else
  30288. byte out2[1 + ECC_KEYGEN_SIZE * 2 + 80];
  30289. #endif
  30290. word32 outSz2 = sizeof(out2);
  30291. word32 plainSz2 = sizeof(plain2);
  30292. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30293. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof(ecc_key), HEAP_HINT,
  30294. DYNAMIC_TYPE_TMP_BUFFER);
  30295. #else
  30296. ecc_key tmpKey[1];
  30297. #endif
  30298. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30299. if (tmpKey == NULL) {
  30300. ERROR_OUT(MEMORY_E, done);
  30301. }
  30302. #endif
  30303. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30304. if (ret != 0)
  30305. goto done;
  30306. /* set message to incrementing 0,1,2,etc... */
  30307. for (i = 0; i < (int)sizeof(msg); i++)
  30308. msg[i] = i;
  30309. /* encrypt msg to B */
  30310. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz, NULL);
  30311. if (ret != 0) {
  30312. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30313. }
  30314. #ifdef WOLFSSL_ECIES_OLD
  30315. tmpKey->dp = userA->dp;
  30316. ret = wc_ecc_copy_point(&userA->pubkey, &tmpKey->pubkey);
  30317. if (ret != 0) {
  30318. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30319. }
  30320. #endif
  30321. /* decrypt msg from A */
  30322. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, NULL);
  30323. if (ret != 0) {
  30324. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30325. }
  30326. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30327. ret = WC_TEST_RET_ENC_NC; goto done;
  30328. }
  30329. #ifndef WOLFSSL_ECIES_OLD
  30330. /* A decrypts msg (response) from B */
  30331. ret = wc_ecc_decrypt(userB, NULL, out, outSz, plain2, &plainSz2, NULL);
  30332. if (ret != 0)
  30333. goto done;
  30334. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30335. ret = WC_TEST_RET_ENC_NC; goto done;
  30336. }
  30337. #endif
  30338. /* let's verify message exchange works, A is client, B is server */
  30339. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30340. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30341. if (cliCtx == NULL || srvCtx == NULL) {
  30342. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30343. }
  30344. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30345. if (ret != 0)
  30346. goto done;
  30347. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30348. if (ret != 0)
  30349. goto done;
  30350. /* get salt to send to peer */
  30351. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30352. if (tmpSalt == NULL) {
  30353. ret = WC_TEST_RET_ENC_NC; goto done;
  30354. }
  30355. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30356. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30357. if (tmpSalt == NULL) {
  30358. ret = WC_TEST_RET_ENC_NC; goto done;
  30359. }
  30360. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30361. /* in actual use, we'd get the peer's salt over the transport */
  30362. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30363. if (ret != 0)
  30364. goto done;
  30365. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30366. if (ret != 0)
  30367. goto done;
  30368. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 11);
  30369. if (ret != 0)
  30370. goto done;
  30371. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 11);
  30372. if (ret != 0)
  30373. goto done;
  30374. /* get encrypted msg (request) to send to B */
  30375. outSz = sizeof(out);
  30376. ret = wc_ecc_encrypt(userA, userB, msg, sizeof(msg), out, &outSz,cliCtx);
  30377. if (ret != 0)
  30378. goto done;
  30379. #ifndef WOLFSSL_ECIES_OLD
  30380. wc_ecc_free(tmpKey);
  30381. #endif
  30382. /* B decrypts msg (request) from A */
  30383. plainSz = sizeof(plain);
  30384. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30385. if (ret != 0)
  30386. goto done;
  30387. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30388. ret = WC_TEST_RET_ENC_NC; goto done;
  30389. }
  30390. /* msg2 (response) from B to A */
  30391. for (i = 0; i < (int)sizeof(msg2); i++)
  30392. msg2[i] = i + sizeof(msg2);
  30393. /* get encrypted msg (response) to send to B */
  30394. ret = wc_ecc_encrypt(userB, userA, msg2, sizeof(msg2), out2,
  30395. &outSz2, srvCtx);
  30396. if (ret != 0)
  30397. goto done;
  30398. #ifdef WOLFSSL_ECIES_OLD
  30399. tmpKey->dp = userB->dp;
  30400. ret = wc_ecc_copy_point(&userB->pubkey, &tmpKey->pubkey);
  30401. if (ret != 0) {
  30402. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30403. }
  30404. #else
  30405. wc_ecc_free(tmpKey);
  30406. #endif
  30407. /* A decrypts msg (response) from B */
  30408. ret = wc_ecc_decrypt(userA, tmpKey, out2, outSz2, plain2, &plainSz2,
  30409. cliCtx);
  30410. if (ret != 0)
  30411. goto done;
  30412. if (XMEMCMP(plain2, msg2, sizeof(msg2)) != 0) {
  30413. ret = WC_TEST_RET_ENC_NC; goto done;
  30414. }
  30415. #if defined(HAVE_COMP_KEY) && \
  30416. (! defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
  30417. /* Create new client and server contexts. */
  30418. wc_ecc_ctx_free(srvCtx);
  30419. wc_ecc_ctx_free(cliCtx);
  30420. /* let's verify message exchange works, A is client, B is server */
  30421. cliCtx = wc_ecc_ctx_new(REQ_RESP_CLIENT, rng);
  30422. srvCtx = wc_ecc_ctx_new(REQ_RESP_SERVER, rng);
  30423. if (cliCtx == NULL || srvCtx == NULL) {
  30424. ret = WC_TEST_RET_ENC_ERRNO; goto done;
  30425. }
  30426. ret = wc_ecc_ctx_set_algo(cliCtx, encAlgo, kdfAlgo, macAlgo);
  30427. if (ret != 0)
  30428. goto done;
  30429. ret = wc_ecc_ctx_set_algo(srvCtx, encAlgo, kdfAlgo, macAlgo);
  30430. if (ret != 0)
  30431. goto done;
  30432. /* get salt to send to peer */
  30433. tmpSalt = wc_ecc_ctx_get_own_salt(cliCtx);
  30434. if (tmpSalt == NULL) {
  30435. ret = WC_TEST_RET_ENC_NC; goto done;
  30436. }
  30437. XMEMCPY(cliSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30438. tmpSalt = wc_ecc_ctx_get_own_salt(srvCtx);
  30439. if (tmpSalt == NULL) {
  30440. ret = WC_TEST_RET_ENC_NC; goto done;
  30441. }
  30442. XMEMCPY(srvSalt, tmpSalt, EXCHANGE_SALT_SZ);
  30443. /* in actual use, we'd get the peer's salt over the transport */
  30444. ret = wc_ecc_ctx_set_peer_salt(cliCtx, srvSalt);
  30445. if (ret != 0)
  30446. goto done;
  30447. ret = wc_ecc_ctx_set_peer_salt(srvCtx, cliSalt);
  30448. if (ret != 0)
  30449. goto done;
  30450. ret = wc_ecc_ctx_set_info(cliCtx, (byte*)"wolfSSL MSGE", 12);
  30451. if (ret != 0)
  30452. goto done;
  30453. ret = wc_ecc_ctx_set_info(srvCtx, (byte*)"wolfSSL MSGE", 12);
  30454. if (ret != 0)
  30455. goto done;
  30456. /* get encrypted msg (request) to send to B - compressed public key */
  30457. outSz = sizeof(out);
  30458. ret = wc_ecc_encrypt_ex(userA, userB, msg, sizeof(msg), out, &outSz, cliCtx,
  30459. 1);
  30460. if (ret != 0)
  30461. goto done;
  30462. #ifndef WOLFSSL_ECIES_OLD
  30463. wc_ecc_free(tmpKey);
  30464. #endif
  30465. /* B decrypts msg (request) from A - out has a compressed public key */
  30466. plainSz = sizeof(plain);
  30467. ret = wc_ecc_decrypt(userB, tmpKey, out, outSz, plain, &plainSz, srvCtx);
  30468. if (ret != 0)
  30469. goto done;
  30470. if (XMEMCMP(plain, msg, sizeof(msg)) != 0) {
  30471. ret = WC_TEST_RET_ENC_NC; goto done;
  30472. }
  30473. #endif /* HAVE_COMP_KEY && (!FIPS || FIPS>=5.3) */
  30474. #if (!defined(NO_ECC256) || defined(HAVE_ALL_CURVES)) && \
  30475. (ECC_MIN_KEY_SZ <= 256) && defined(WOLFSSL_AES_128)
  30476. ret = ecc_encrypt_kat(rng);
  30477. #endif
  30478. done:
  30479. /* cleanup */
  30480. wc_ecc_ctx_free(srvCtx);
  30481. wc_ecc_ctx_free(cliCtx);
  30482. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30483. if (tmpKey != NULL) {
  30484. wc_ecc_free(tmpKey);
  30485. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30486. }
  30487. #else
  30488. wc_ecc_free(tmpKey);
  30489. #endif
  30490. return ret;
  30491. }
  30492. #endif
  30493. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30494. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_encrypt_test(void)
  30495. {
  30496. WC_RNG rng;
  30497. wc_test_ret_t ret;
  30498. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30499. ecc_key *userA;
  30500. ecc_key *userB;
  30501. #else
  30502. ecc_key userA[1];
  30503. ecc_key userB[1];
  30504. #endif
  30505. WOLFSSL_ENTER("ecc_encrypt_test");
  30506. #ifndef HAVE_FIPS
  30507. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30508. #else
  30509. ret = wc_InitRng(&rng);
  30510. #endif
  30511. if (ret != 0)
  30512. return WC_TEST_RET_ENC_EC(ret);
  30513. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30514. userA = (ecc_key *)XMALLOC(sizeof *userA, HEAP_HINT,
  30515. DYNAMIC_TYPE_TMP_BUFFER);
  30516. userB = (ecc_key *)XMALLOC(sizeof *userB, HEAP_HINT,
  30517. DYNAMIC_TYPE_TMP_BUFFER);
  30518. if ((userA == NULL) || (userB == NULL)) {
  30519. ERROR_OUT(MEMORY_E, done);
  30520. }
  30521. #endif
  30522. XMEMSET(userA, 0, sizeof *userA);
  30523. XMEMSET(userB, 0, sizeof *userB);
  30524. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  30525. if (ret != 0)
  30526. goto done;
  30527. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  30528. if (ret != 0)
  30529. goto done;
  30530. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userA);
  30531. #if defined(WOLFSSL_ASYNC_CRYPT)
  30532. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  30533. #endif
  30534. if (ret != 0){
  30535. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30536. }
  30537. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, userB);
  30538. #if defined(WOLFSSL_ASYNC_CRYPT)
  30539. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  30540. #endif
  30541. if (ret != 0){
  30542. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30543. }
  30544. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30545. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30546. !defined(HAVE_SELFTEST)
  30547. ret = wc_ecc_set_rng(userA, &rng);
  30548. if (ret != 0) {
  30549. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30550. }
  30551. ret = wc_ecc_set_rng(userB, &rng);
  30552. if (ret != 0) {
  30553. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30554. }
  30555. #endif
  30556. #if !defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3))
  30557. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30558. #ifdef WOLFSSL_AES_128
  30559. if (ret == 0) {
  30560. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30561. ecHKDF_SHA256, ecHMAC_SHA256);
  30562. if (ret != 0) {
  30563. printf("ECIES: AES_128_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30564. }
  30565. }
  30566. #ifdef HAVE_X963_KDF
  30567. if (ret == 0) {
  30568. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30569. ecKDF_X963_SHA256, ecHMAC_SHA256);
  30570. if (ret != 0) {
  30571. printf("ECIES: AES_128_CBC, KDF_X963_SHA256, HMAC_SHA256\n");
  30572. }
  30573. }
  30574. if (ret == 0) {
  30575. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CBC,
  30576. ecKDF_SHA256, ecHMAC_SHA256);
  30577. if (ret != 0) {
  30578. printf("ECIES: AES_128_CBC, KDF_SHA256, HMAC_SHA256\n");
  30579. }
  30580. }
  30581. #endif
  30582. #endif
  30583. #ifdef WOLFSSL_AES_256
  30584. if (ret == 0) {
  30585. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CBC,
  30586. ecHKDF_SHA256, ecHMAC_SHA256);
  30587. if (ret != 0) {
  30588. printf("ECIES: AES_256_CBC, HKDF_SHA256, HMAC_SHA256\n");
  30589. }
  30590. }
  30591. #endif
  30592. #endif
  30593. #if !defined(NO_AES) && defined(WOLFSSL_AES_COUNTER) && !defined(WOLFSSL_NO_MALLOC)
  30594. #ifdef WOLFSSL_AES_128
  30595. if (ret == 0) {
  30596. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_128_CTR,
  30597. ecHKDF_SHA256, ecHMAC_SHA256);
  30598. if (ret != 0) {
  30599. printf("ECIES: AES_128_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30600. }
  30601. }
  30602. #endif
  30603. #ifdef WOLFSSL_AES_256
  30604. if (ret == 0) {
  30605. ret = ecc_encrypt_e2e_test(&rng, userA, userB, ecAES_256_CTR,
  30606. ecHKDF_SHA256, ecHMAC_SHA256);
  30607. if (ret != 0) {
  30608. printf("ECIES: AES_256_CTR, HKDF_SHA256, HMAC_SHA256\n");
  30609. }
  30610. }
  30611. #endif
  30612. #endif /* !NO_AES && WOLFSSL_AES_COUNTER */
  30613. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(WOLFSSL_NO_MALLOC)
  30614. if (ret == 0) {
  30615. ret = ecc_ctx_kdf_salt_test(&rng, userA, userB);
  30616. }
  30617. #endif
  30618. #endif /* !HAVE_FIPS || FIPS_VERSION_GE(5,3) */
  30619. done:
  30620. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30621. if (userA != NULL) {
  30622. wc_ecc_free(userA);
  30623. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30624. }
  30625. if (userB != NULL) {
  30626. wc_ecc_free(userB);
  30627. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30628. }
  30629. #else
  30630. wc_ecc_free(userB);
  30631. wc_ecc_free(userA);
  30632. #endif
  30633. wc_FreeRng(&rng);
  30634. return ret;
  30635. }
  30636. #endif /* HAVE_ECC_ENCRYPT && HAVE_AES_CBC && WOLFSSL_AES_128 */
  30637. #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \
  30638. !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \
  30639. defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) && \
  30640. !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(NO_ECC_SECP)
  30641. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ecc_test_buffers(void)
  30642. {
  30643. size_t bytes;
  30644. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30645. ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30646. ecc_key *servKey = (ecc_key *)XMALLOC(sizeof *servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30647. ecc_key *tmpKey = (ecc_key *)XMALLOC(sizeof *tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30648. #else
  30649. ecc_key cliKey[1];
  30650. ecc_key servKey[1];
  30651. ecc_key tmpKey[1];
  30652. #endif
  30653. WC_RNG rng;
  30654. word32 idx = 0;
  30655. wc_test_ret_t ret;
  30656. /* pad our test message to 32 bytes so evenly divisible by AES_BLOCK_SZ */
  30657. byte in[] = "Everyone gets Friday off. ecc p";
  30658. word32 inLen = (word32)XSTRLEN((char*)in);
  30659. byte out[256];
  30660. byte plain[256];
  30661. int verify = 0;
  30662. word32 x;
  30663. WOLFSSL_ENTER("ecc_test_buffers");
  30664. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30665. if ((cliKey == NULL) || (servKey == NULL) || (tmpKey == NULL))
  30666. ERROR_OUT(MEMORY_E, done);
  30667. #endif
  30668. ret = wc_ecc_init_ex(cliKey, HEAP_HINT, devId);
  30669. if (ret != 0)
  30670. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30671. ret = wc_ecc_init_ex(servKey, HEAP_HINT, devId);
  30672. if (ret != 0)
  30673. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30674. ret = wc_ecc_init_ex(tmpKey, HEAP_HINT, devId);
  30675. if (ret != 0)
  30676. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30677. bytes = (size_t)sizeof_ecc_clikey_der_256;
  30678. /* place client key into ecc_key struct cliKey */
  30679. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, cliKey,
  30680. (word32)bytes);
  30681. if (ret != 0)
  30682. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30683. idx = 0;
  30684. bytes = (size_t)sizeof_ecc_key_der_256;
  30685. /* place server key into ecc_key struct servKey */
  30686. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, servKey,
  30687. (word32)bytes);
  30688. if (ret != 0)
  30689. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30690. #ifndef WC_NO_RNG
  30691. #ifndef HAVE_FIPS
  30692. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  30693. #else
  30694. ret = wc_InitRng(&rng);
  30695. #endif
  30696. if (ret != 0)
  30697. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30698. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  30699. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  30700. !defined(HAVE_SELFTEST)
  30701. ret = wc_ecc_set_rng(cliKey, &rng);
  30702. if (ret != 0)
  30703. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30704. ret = wc_ecc_set_rng(servKey, &rng);
  30705. if (ret != 0)
  30706. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30707. #endif
  30708. #endif /* !WC_NO_RNG */
  30709. #if defined(HAVE_ECC_ENCRYPT) && defined(HAVE_HKDF) && \
  30710. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  30711. {
  30712. word32 y;
  30713. /* test encrypt and decrypt if they're available */
  30714. x = sizeof(out);
  30715. ret = wc_ecc_encrypt(cliKey, servKey, in, sizeof(in), out, &x, NULL);
  30716. if (ret < 0)
  30717. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30718. #ifdef WOLFSSL_ECIES_OLD
  30719. tmpKey->dp = cliKey->dp;
  30720. ret = wc_ecc_copy_point(&cliKey->pubkey, &tmpKey->pubkey);
  30721. if (ret != 0) {
  30722. ret = WC_TEST_RET_ENC_EC(ret); goto done;
  30723. }
  30724. #endif
  30725. y = sizeof(plain);
  30726. ret = wc_ecc_decrypt(servKey, tmpKey, out, x, plain, &y, NULL);
  30727. if (ret < 0)
  30728. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30729. if (XMEMCMP(plain, in, inLen))
  30730. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30731. }
  30732. #endif
  30733. x = sizeof(out);
  30734. do {
  30735. #if defined(WOLFSSL_ASYNC_CRYPT)
  30736. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30737. #endif
  30738. if (ret == 0)
  30739. ret = wc_ecc_sign_hash(in, inLen, out, &x, &rng, cliKey);
  30740. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30741. if (ret < 0)
  30742. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30743. TEST_SLEEP();
  30744. XMEMSET(plain, 0, sizeof(plain));
  30745. do {
  30746. #if defined(WOLFSSL_ASYNC_CRYPT)
  30747. ret = wc_AsyncWait(ret, &cliKey->asyncDev, WC_ASYNC_FLAG_CALL_AGAIN);
  30748. #endif
  30749. if (ret == 0)
  30750. ret = wc_ecc_verify_hash(out, x, in, inLen, &verify,
  30751. cliKey);
  30752. } while (ret == WC_NO_ERR_TRACE(WC_PENDING_E));
  30753. if (ret < 0)
  30754. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30755. if (verify != 1)
  30756. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  30757. TEST_SLEEP();
  30758. #ifdef WOLFSSL_CERT_EXT
  30759. idx = 0;
  30760. bytes = sizeof_ecc_clikeypub_der_256;
  30761. ret = wc_EccPublicKeyDecode(ecc_clikeypub_der_256, &idx, cliKey,
  30762. (word32) bytes);
  30763. if (ret != 0)
  30764. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  30765. #endif
  30766. ret = 0;
  30767. done:
  30768. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  30769. if (cliKey != NULL) {
  30770. wc_ecc_free(cliKey);
  30771. XFREE(cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30772. }
  30773. if (servKey != NULL) {
  30774. wc_ecc_free(servKey);
  30775. XFREE(servKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30776. }
  30777. if (tmpKey != NULL) {
  30778. wc_ecc_free(tmpKey);
  30779. XFREE(tmpKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  30780. }
  30781. #else
  30782. wc_ecc_free(cliKey);
  30783. wc_ecc_free(servKey);
  30784. wc_ecc_free(tmpKey);
  30785. #endif
  30786. wc_FreeRng(&rng);
  30787. return ret;
  30788. }
  30789. #endif /* USE_CERT_BUFFERS_256 && !WOLFSSL_ATECCX08A && !NO_ECC256 */
  30790. #endif /* HAVE_ECC */
  30791. #ifdef HAVE_CURVE25519
  30792. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  30793. defined(HAVE_CURVE25519_KEY_IMPORT)
  30794. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30795. #define X25519_TEST_CNT 5
  30796. #else
  30797. #define X25519_TEST_CNT 1
  30798. #endif
  30799. static wc_test_ret_t curve25519_overflow_test(void)
  30800. {
  30801. /* secret key for party a */
  30802. byte sa[X25519_TEST_CNT][32] = {
  30803. {
  30804. 0x8d,0xaf,0x6e,0x7a,0xc1,0xeb,0x8d,0x30,
  30805. 0x99,0x86,0xd3,0x90,0x47,0x96,0x21,0x3c,
  30806. 0x3a,0x75,0xc0,0x7b,0x75,0x01,0x75,0xa3,
  30807. 0x81,0x4b,0xff,0x5a,0xbc,0x96,0x87,0x28
  30808. },
  30809. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30810. {
  30811. 0x9d,0x63,0x5f,0xce,0xe2,0xe8,0xd7,0xfb,
  30812. 0x68,0x77,0x0e,0x44,0xd1,0xad,0x87,0x2b,
  30813. 0xf4,0x65,0x06,0xb7,0xbb,0xdb,0xbe,0x6e,
  30814. 0x02,0x43,0x24,0xc7,0x3d,0x7b,0x88,0x60
  30815. },
  30816. {
  30817. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30818. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30819. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30820. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30821. },
  30822. {
  30823. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30824. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30825. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30826. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30827. },
  30828. {
  30829. 0x63,0xbf,0x76,0xa9,0x73,0xa0,0x09,0xb9,
  30830. 0xcc,0xc9,0x4d,0x47,0x2d,0x14,0x0e,0x52,
  30831. 0xa3,0x84,0x55,0xb8,0x7c,0xdb,0xce,0xb1,
  30832. 0xe4,0x5b,0x8a,0xb9,0x30,0xf1,0xa4,0xa0
  30833. }
  30834. #endif
  30835. };
  30836. /* public key for party b */
  30837. byte pb[X25519_TEST_CNT][32] = {
  30838. {
  30839. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30840. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30841. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30842. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30843. },
  30844. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30845. {
  30846. /* 0xff first byte in original - invalid! */
  30847. 0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30848. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30849. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30850. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0
  30851. },
  30852. {
  30853. 0x36,0x1a,0x74,0x87,0x28,0x59,0xe0,0xb6,
  30854. 0xe4,0x2b,0x17,0x9b,0x16,0xb0,0x3b,0xf8,
  30855. 0xb8,0x9f,0x2a,0x8f,0xc5,0x33,0x68,0x4f,
  30856. 0xde,0x4d,0xd8,0x80,0x63,0xe7,0xb4,0x0a
  30857. },
  30858. {
  30859. 0x00,0x80,0x38,0x59,0x19,0x3a,0x66,0x12,
  30860. 0xfd,0xa1,0xec,0x1c,0x40,0x84,0x40,0xbd,
  30861. 0x64,0x10,0x8b,0x53,0x81,0x21,0x03,0x2d,
  30862. 0x7d,0x33,0xb4,0x01,0x57,0x0d,0xe1,0x89
  30863. },
  30864. {
  30865. 0x1d,0xf8,0xf8,0x33,0x89,0x6c,0xb7,0xba,
  30866. 0x94,0x73,0xfa,0xc2,0x36,0xac,0xbe,0x49,
  30867. 0xaf,0x85,0x3e,0x93,0x5f,0xae,0xb2,0xc0,
  30868. 0xc8,0x80,0x8f,0x4a,0xaa,0xd3,0x55,0x2b
  30869. }
  30870. #endif
  30871. };
  30872. /* expected shared key */
  30873. byte ss[X25519_TEST_CNT][32] = {
  30874. {
  30875. 0x5c,0x4c,0x85,0x5f,0xfb,0x20,0x38,0xcc,
  30876. 0x55,0x16,0x5b,0x8a,0xa7,0xed,0x57,0x6e,
  30877. 0x35,0xaa,0x71,0x67,0x85,0x1f,0xb6,0x28,
  30878. 0x17,0x07,0x7b,0xda,0x76,0xdd,0xe0,0xb4
  30879. },
  30880. #ifdef CURVE25519_OVERFLOW_ALL_TESTS
  30881. {
  30882. 0x33,0xf6,0xc1,0x34,0x62,0x92,0x06,0x02,
  30883. 0x95,0xdb,0x91,0x4c,0x5d,0x52,0x54,0xc7,
  30884. 0xd2,0x5b,0x24,0xb5,0x4f,0x33,0x59,0x79,
  30885. 0x9f,0x6d,0x7e,0x4a,0x4c,0x30,0xd6,0x38
  30886. },
  30887. {
  30888. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30889. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30890. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30891. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02
  30892. },
  30893. {
  30894. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30895. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30896. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30897. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09
  30898. },
  30899. {
  30900. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30901. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30902. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30903. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10
  30904. }
  30905. #endif
  30906. };
  30907. wc_test_ret_t ret = 0;
  30908. int i;
  30909. word32 y;
  30910. byte shared[32];
  30911. curve25519_key userA;
  30912. wc_curve25519_init_ex(&userA, HEAP_HINT, devId);
  30913. for (i = 0; i < X25519_TEST_CNT; i++) {
  30914. if (wc_curve25519_import_private_raw(sa[i], sizeof(sa[i]), pb[i],
  30915. sizeof(pb[i]), &userA) != 0) {
  30916. ret = WC_TEST_RET_ENC_I(i); break;
  30917. }
  30918. /* test against known test vector */
  30919. XMEMSET(shared, 0, sizeof(shared));
  30920. y = sizeof(shared);
  30921. if (wc_curve25519_shared_secret(&userA, &userA, shared, &y) != 0) {
  30922. ret = WC_TEST_RET_ENC_I(i); break;
  30923. }
  30924. if (XMEMCMP(ss[i], shared, y)) {
  30925. ret = WC_TEST_RET_ENC_I(i); break;
  30926. }
  30927. }
  30928. wc_curve25519_free(&userA);
  30929. return ret;
  30930. }
  30931. /* Test the wc_curve25519_check_public API.
  30932. *
  30933. * returns 0 on success and -ve on failure.
  30934. */
  30935. static wc_test_ret_t curve25519_check_public_test(void)
  30936. {
  30937. wc_test_ret_t ret;
  30938. /* Little-endian values that will fail */
  30939. byte fail_le[][CURVE25519_KEYSIZE] = {
  30940. {
  30941. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30942. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30943. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30944. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30945. },
  30946. {
  30947. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30948. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30949. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30950. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30951. },
  30952. {
  30953. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30954. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30955. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30956. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x81
  30957. },
  30958. };
  30959. /* Big-endian values that will fail */
  30960. byte fail_be[][CURVE25519_KEYSIZE] = {
  30961. {
  30962. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30963. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30964. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30965. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  30966. },
  30967. {
  30968. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30969. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30970. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30971. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30972. },
  30973. {
  30974. 0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30975. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30976. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30977. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30978. },
  30979. };
  30980. /* Good or valid public value */
  30981. byte good[CURVE25519_KEYSIZE] = {
  30982. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30983. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30984. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30985. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  30986. };
  30987. int i;
  30988. /* Parameter checks */
  30989. /* NULL pointer */
  30990. ret = wc_curve25519_check_public(NULL, 0, EC25519_LITTLE_ENDIAN);
  30991. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30992. return WC_TEST_RET_ENC_EC(ret);
  30993. }
  30994. ret = wc_curve25519_check_public(NULL, 0, EC25519_BIG_ENDIAN);
  30995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
  30996. return WC_TEST_RET_ENC_EC(ret);
  30997. }
  30998. /* Length of 0 treated differently to other invalid lengths for TLS */
  30999. ret = wc_curve25519_check_public(good, 0, EC25519_LITTLE_ENDIAN);
  31000. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31001. return WC_TEST_RET_ENC_EC(ret);
  31002. ret = wc_curve25519_check_public(good, 0, EC25519_BIG_ENDIAN);
  31003. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  31004. return WC_TEST_RET_ENC_EC(ret);
  31005. /* Length not CURVE25519_KEYSIZE */
  31006. for (i = 1; i < CURVE25519_KEYSIZE + 2; i++) {
  31007. if (i == CURVE25519_KEYSIZE)
  31008. continue;
  31009. if (wc_curve25519_check_public(good, (word32)i, EC25519_LITTLE_ENDIAN) !=
  31010. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31011. return WC_TEST_RET_ENC_I(i);
  31012. }
  31013. if (wc_curve25519_check_public(good, (word32)i, EC25519_BIG_ENDIAN) !=
  31014. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  31015. return WC_TEST_RET_ENC_I(i);
  31016. }
  31017. }
  31018. /* Little-endian fail cases */
  31019. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  31020. if (wc_curve25519_check_public(fail_le[i], CURVE25519_KEYSIZE,
  31021. EC25519_LITTLE_ENDIAN) == 0) {
  31022. return WC_TEST_RET_ENC_I(i);
  31023. }
  31024. }
  31025. /* Big-endian fail cases */
  31026. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  31027. if (wc_curve25519_check_public(fail_be[i], CURVE25519_KEYSIZE,
  31028. EC25519_BIG_ENDIAN) == 0) {
  31029. return WC_TEST_RET_ENC_I(i);
  31030. }
  31031. }
  31032. /* Check a valid public value works! */
  31033. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31034. EC25519_LITTLE_ENDIAN);
  31035. if (ret != 0) {
  31036. return WC_TEST_RET_ENC_EC(ret);
  31037. }
  31038. ret = wc_curve25519_check_public(good, CURVE25519_KEYSIZE,
  31039. EC25519_BIG_ENDIAN);
  31040. if (ret != 0) {
  31041. return WC_TEST_RET_ENC_EC(ret);
  31042. }
  31043. return 0;
  31044. }
  31045. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31046. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31047. defined(HAVE_CURVE25519_KEY_IMPORT)
  31048. static wc_test_ret_t curve255519_der_test(void)
  31049. {
  31050. wc_test_ret_t ret = 0;
  31051. /* certs/statickeys/x25519.der */
  31052. const byte kCurve25519PrivDer[] = {
  31053. 0x30, 0x2E, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E,
  31054. 0x04, 0x22, 0x04, 0x20, 0x78, 0x8E, 0x31, 0x5C, 0x33, 0xA9, 0x19, 0xC0,
  31055. 0x5E, 0x36, 0x70, 0x1B, 0xA4, 0xE8, 0xEF, 0xC1, 0x89, 0x8C, 0xB3, 0x15,
  31056. 0xC6, 0x79, 0xD3, 0xAC, 0x22, 0x00, 0xAE, 0xFA, 0xB3, 0xB7, 0x0F, 0x78
  31057. };
  31058. /* certs/statickeys/x25519-pub.der */
  31059. const byte kCurve25519PubDer[] = {
  31060. 0x30, 0x2A, 0x30, 0x05, 0x06, 0x03, 0x2B, 0x65, 0x6E, 0x03, 0x21, 0x00,
  31061. 0x09, 0xBC, 0x8C, 0xC7, 0x45, 0x0D, 0xC1, 0xC2, 0x02, 0x57, 0x9A, 0x68,
  31062. 0x3A, 0xFD, 0x7A, 0xA8, 0xA5, 0x2F, 0xF0, 0x99, 0x39, 0x98, 0xEA, 0x26,
  31063. 0xA2, 0x5B, 0x38, 0xFD, 0x96, 0xDB, 0x2A, 0x26
  31064. };
  31065. curve25519_key key;
  31066. byte output[128];
  31067. word32 outputSz = 128;
  31068. word32 idx;
  31069. ret = wc_curve25519_init_ex(&key, HEAP_HINT, devId);
  31070. if (ret != 0)
  31071. return WC_TEST_RET_ENC_EC(ret);
  31072. /* Test decode / encode of Curve25519 private key only */
  31073. if (ret == 0) {
  31074. idx = 0;
  31075. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx, &key,
  31076. (word32)sizeof(kCurve25519PrivDer));
  31077. if (ret < 0)
  31078. ret = WC_TEST_RET_ENC_EC(ret);
  31079. }
  31080. if (ret == 0) {
  31081. outputSz = (word32)sizeof(output);
  31082. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31083. if (ret >= 0) {
  31084. outputSz = (word32)ret;
  31085. ret = 0;
  31086. }
  31087. else {
  31088. ret = WC_TEST_RET_ENC_EC(ret);
  31089. }
  31090. }
  31091. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31092. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31093. ret = WC_TEST_RET_ENC_NC;
  31094. }
  31095. /* Test decode / encode of Curve25519 public key only */
  31096. if (ret == 0) {
  31097. idx = 0;
  31098. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx, &key,
  31099. (word32)sizeof(kCurve25519PubDer));
  31100. if (ret < 0)
  31101. ret = WC_TEST_RET_ENC_EC(ret);
  31102. }
  31103. if (ret == 0) {
  31104. outputSz = (word32)sizeof(output);
  31105. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31106. if (ret >= 0) {
  31107. outputSz = (word32)ret;
  31108. ret = 0;
  31109. }
  31110. else {
  31111. ret = WC_TEST_RET_ENC_EC(ret);
  31112. }
  31113. }
  31114. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31115. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31116. ret = WC_TEST_RET_ENC_NC;
  31117. }
  31118. /* Test decode/encode of Curve25519 private key (only) using generic API */
  31119. if (ret == 0) {
  31120. /* clear key, since generic API will try to decode all fields */
  31121. XMEMSET(&key, 0, sizeof(key));
  31122. idx = 0;
  31123. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31124. (word32)sizeof(kCurve25519PrivDer));
  31125. if (ret < 0) {
  31126. ret = WC_TEST_RET_ENC_EC(ret);
  31127. }
  31128. }
  31129. if (ret == 0) {
  31130. outputSz = (word32)sizeof(output);
  31131. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31132. if (ret >= 0) {
  31133. outputSz = (word32)ret;
  31134. ret = 0;
  31135. }
  31136. else {
  31137. ret = WC_TEST_RET_ENC_EC(ret);
  31138. }
  31139. }
  31140. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31141. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31142. ret = WC_TEST_RET_ENC_NC;
  31143. }
  31144. /* Test decode/encode of Curve25519 public key (only) using generic API */
  31145. if (ret == 0) {
  31146. /* clear key, since generic API will try to decode all fields */
  31147. XMEMSET(&key, 0, sizeof(key));
  31148. idx = 0;
  31149. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31150. (word32)sizeof(kCurve25519PubDer));
  31151. if (ret < 0) {
  31152. ret = WC_TEST_RET_ENC_EC(ret);
  31153. }
  31154. }
  31155. if (ret == 0) {
  31156. outputSz = (word32)sizeof(output);
  31157. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31158. if (ret >= 0) {
  31159. outputSz = (word32)ret;
  31160. ret = 0;
  31161. }
  31162. else {
  31163. ret = WC_TEST_RET_ENC_EC(ret);
  31164. }
  31165. }
  31166. if (ret == 0 && (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31167. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31168. ret = WC_TEST_RET_ENC_NC;
  31169. }
  31170. /* Test decode/encode key data containing both public and private fields */
  31171. if (ret == 0) {
  31172. XMEMSET(&key, 0 , sizeof(key));
  31173. /* Decode public key */
  31174. idx = 0;
  31175. ret = wc_Curve25519KeyDecode(kCurve25519PubDer, &idx, &key,
  31176. (word32)sizeof(kCurve25519PubDer));
  31177. if (ret < 0) {
  31178. ret = WC_TEST_RET_ENC_EC(ret);
  31179. }
  31180. if (ret == 0) {
  31181. /* Decode private key */
  31182. idx = 0;
  31183. ret = wc_Curve25519KeyDecode(kCurve25519PrivDer, &idx, &key,
  31184. (word32)sizeof(kCurve25519PrivDer));
  31185. if (ret < 0) {
  31186. ret = WC_TEST_RET_ENC_EC(ret);
  31187. }
  31188. }
  31189. /* Both public and private flags should be set */
  31190. if ((ret == 0) && (!key.pubSet && !key.privSet)) {
  31191. ret = WC_TEST_RET_ENC_NC;
  31192. }
  31193. if (ret == 0) {
  31194. /* Export key to temporary DER */
  31195. outputSz = (word32)sizeof(output);
  31196. ret = wc_Curve25519KeyToDer(&key, output, outputSz, 1);
  31197. if (ret >= 0) {
  31198. outputSz = (word32)ret;
  31199. ret = 0;
  31200. }
  31201. else {
  31202. ret = WC_TEST_RET_ENC_EC(ret);
  31203. }
  31204. /* Re-import temporary DER */
  31205. if (ret == 0) {
  31206. idx = 0;
  31207. ret = wc_Curve25519KeyDecode(output, &idx, &key, sizeof(output));
  31208. if (ret < 0) {
  31209. ret = WC_TEST_RET_ENC_EC(ret);
  31210. }
  31211. }
  31212. /* Ensure public and private keys survived combined keypair
  31213. * export/import by re-exporting DER for private and public keys,
  31214. * individually, and re-checking output against known good vectors.
  31215. * This is slightly circuitous but does test the functionality
  31216. * without requiring the addition of new test keys */
  31217. if (ret == 0) {
  31218. idx = 0;
  31219. ret = wc_Curve25519PrivateKeyDecode(kCurve25519PrivDer, &idx,
  31220. &key, (word32)sizeof(kCurve25519PrivDer));
  31221. if (ret < 0)
  31222. ret = WC_TEST_RET_ENC_EC(ret);
  31223. }
  31224. if (ret == 0) {
  31225. outputSz = (word32)sizeof(output);
  31226. ret = wc_Curve25519PrivateKeyToDer(&key, output, outputSz);
  31227. if (ret >= 0) {
  31228. outputSz = (word32)ret;
  31229. ret = 0;
  31230. }
  31231. else {
  31232. ret = WC_TEST_RET_ENC_EC(ret);
  31233. }
  31234. }
  31235. if ((ret == 0) &&
  31236. (outputSz != (word32)sizeof(kCurve25519PrivDer) ||
  31237. XMEMCMP(output, kCurve25519PrivDer, outputSz) != 0)) {
  31238. ret = WC_TEST_RET_ENC_NC;
  31239. }
  31240. if (ret == 0) {
  31241. idx = 0;
  31242. ret = wc_Curve25519PublicKeyDecode(kCurve25519PubDer, &idx,
  31243. &key, (word32)sizeof(kCurve25519PubDer));
  31244. if (ret < 0)
  31245. ret = WC_TEST_RET_ENC_EC(ret);
  31246. }
  31247. if (ret == 0) {
  31248. outputSz = (word32)sizeof(output);
  31249. ret = wc_Curve25519PublicKeyToDer(&key, output, outputSz, 1);
  31250. if (ret >= 0) {
  31251. outputSz = (word32)ret;
  31252. ret = 0;
  31253. }
  31254. else {
  31255. ret = WC_TEST_RET_ENC_EC(ret);
  31256. }
  31257. }
  31258. if ((ret == 0) &&
  31259. (outputSz != (word32)sizeof(kCurve25519PubDer) ||
  31260. XMEMCMP(output, kCurve25519PubDer, outputSz) != 0)) {
  31261. ret = WC_TEST_RET_ENC_NC;
  31262. }
  31263. }
  31264. }
  31265. wc_curve25519_free(&key);
  31266. return ret;
  31267. }
  31268. #endif /* !NO_ASN && HAVE_CURVE25519_KEY_EXPORT && HAVE_CURVE25519_KEY_IMPORT */
  31269. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve25519_test(void)
  31270. {
  31271. WC_RNG rng;
  31272. wc_test_ret_t ret;
  31273. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31274. byte sharedA[32];
  31275. byte sharedB[32];
  31276. word32 y;
  31277. #endif
  31278. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31279. byte exportBuf[32];
  31280. #endif
  31281. word32 x = 0;
  31282. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31283. curve25519_key *userA = NULL, *userB = NULL, *pubKey = NULL;
  31284. #else
  31285. curve25519_key userA[1], userB[1], pubKey[1];
  31286. #endif
  31287. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31288. defined(HAVE_CURVE25519_KEY_IMPORT)
  31289. /* test vectors from
  31290. https://tools.ietf.org/html/draft-josefsson-tls-curve25519-03
  31291. */
  31292. /* secret key for party a */
  31293. byte sa[] = {
  31294. 0x5A,0xC9,0x9F,0x33,0x63,0x2E,0x5A,0x76,
  31295. 0x8D,0xE7,0xE8,0x1B,0xF8,0x54,0xC2,0x7C,
  31296. 0x46,0xE3,0xFB,0xF2,0xAB,0xBA,0xCD,0x29,
  31297. 0xEC,0x4A,0xFF,0x51,0x73,0x69,0xC6,0x60
  31298. };
  31299. /* public key for party a */
  31300. byte pa[] = {
  31301. 0x05,0x7E,0x23,0xEA,0x9F,0x1C,0xBE,0x8A,
  31302. 0x27,0x16,0x8F,0x6E,0x69,0x6A,0x79,0x1D,
  31303. 0xE6,0x1D,0xD3,0xAF,0x7A,0xCD,0x4E,0xEA,
  31304. 0xCC,0x6E,0x7B,0xA5,0x14,0xFD,0xA8,0x63
  31305. };
  31306. /* secret key for party b */
  31307. byte sb[] = {
  31308. 0x47,0xDC,0x3D,0x21,0x41,0x74,0x82,0x0E,
  31309. 0x11,0x54,0xB4,0x9B,0xC6,0xCD,0xB2,0xAB,
  31310. 0xD4,0x5E,0xE9,0x58,0x17,0x05,0x5D,0x25,
  31311. 0x5A,0xA3,0x58,0x31,0xB7,0x0D,0x32,0x60
  31312. };
  31313. /* public key for party b */
  31314. byte pb[] = {
  31315. 0x6E,0xB8,0x9D,0xA9,0x19,0x89,0xAE,0x37,
  31316. 0xC7,0xEA,0xC7,0x61,0x8D,0x9E,0x5C,0x49,
  31317. 0x51,0xDB,0xA1,0xD7,0x3C,0x28,0x5A,0xE1,
  31318. 0xCD,0x26,0xA8,0x55,0x02,0x0E,0xEF,0x04
  31319. };
  31320. /* expected shared key */
  31321. byte ss[] = {
  31322. 0x61,0x45,0x0C,0xD9,0x8E,0x36,0x01,0x6B,
  31323. 0x58,0x77,0x6A,0x89,0x7A,0x9F,0x0A,0xEF,
  31324. 0x73,0x8B,0x99,0xF0,0x94,0x68,0xB8,0xD6,
  31325. 0xB8,0x51,0x11,0x84,0xD5,0x34,0x94,0xAB
  31326. };
  31327. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  31328. (void)x;
  31329. WOLFSSL_ENTER("curve25519_test");
  31330. /* wc_FreeRng is always called on exit. Therefore wc_InitRng should be
  31331. * called before any exit goto's */
  31332. #ifndef HAVE_FIPS
  31333. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31334. #else
  31335. ret = wc_InitRng(&rng);
  31336. #endif
  31337. if (ret != 0)
  31338. return WC_TEST_RET_ENC_EC(ret);
  31339. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31340. userA = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31341. if (ret != 0)
  31342. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31343. userB = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31344. if (ret != 0)
  31345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31346. pubKey = wc_curve25519_new(HEAP_HINT, devId, &ret);
  31347. if (ret != 0)
  31348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31349. #else
  31350. wc_curve25519_init_ex(userA, HEAP_HINT, devId);
  31351. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31352. wc_curve25519_init_ex(pubKey, HEAP_HINT, devId);
  31353. #endif
  31354. /* make curve25519 keys */
  31355. ret = wc_curve25519_make_key(&rng, 32, userA);
  31356. if (ret != 0)
  31357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31358. ret = wc_curve25519_make_key(&rng, 32, userB);
  31359. if (ret != 0)
  31360. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31361. #ifdef HAVE_CURVE25519_SHARED_SECRET
  31362. /* find shared secret key */
  31363. x = sizeof(sharedA);
  31364. if ((ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x)) != 0) {
  31365. printf("wc_curve25519_shared_secret 1 failed\n");
  31366. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31367. }
  31368. y = sizeof(sharedB);
  31369. if ((ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y)) != 0) {
  31370. printf("wc_curve25519_shared_secret 2 failed\n");
  31371. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31372. }
  31373. /* compare shared secret keys to test they are the same */
  31374. if (y != x)
  31375. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31376. if (XMEMCMP(sharedA, sharedB, x))
  31377. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31378. #endif
  31379. #ifdef HAVE_CURVE25519_KEY_EXPORT
  31380. /* export a public key and import it for another user */
  31381. x = sizeof(exportBuf);
  31382. ret = wc_curve25519_export_public(userA, exportBuf, &x);
  31383. if (ret != 0)
  31384. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31385. #ifdef HAVE_CURVE25519_KEY_IMPORT
  31386. ret = wc_curve25519_import_public(exportBuf, x, pubKey);
  31387. if (ret != 0)
  31388. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31389. #endif
  31390. #endif
  31391. #if defined(HAVE_CURVE25519_SHARED_SECRET) && \
  31392. defined(HAVE_CURVE25519_KEY_IMPORT)
  31393. /* test shared key after importing a public key */
  31394. XMEMSET(sharedB, 0, sizeof(sharedB));
  31395. y = sizeof(sharedB);
  31396. if (wc_curve25519_shared_secret(userB, pubKey, sharedB, &y) != 0) {
  31397. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31398. }
  31399. if (XMEMCMP(sharedA, sharedB, y))
  31400. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31401. /* import RFC test vectors and compare shared key */
  31402. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31403. userA);
  31404. if (ret != 0)
  31405. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31406. ret = wc_curve25519_import_private_raw(sb, sizeof(sb), pb, sizeof(pb),
  31407. userB);
  31408. if (ret != 0)
  31409. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31410. /* test against known test vector */
  31411. XMEMSET(sharedB, 0, sizeof(sharedB));
  31412. y = sizeof(sharedB);
  31413. ret = wc_curve25519_shared_secret(userA, userB, sharedB, &y);
  31414. if (ret != 0)
  31415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31416. if (XMEMCMP(ss, sharedB, y))
  31417. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31418. /* test swapping roles of keys and generating same shared key */
  31419. XMEMSET(sharedB, 0, sizeof(sharedB));
  31420. y = sizeof(sharedB);
  31421. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31422. if (ret != 0)
  31423. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31424. if (XMEMCMP(ss, sharedB, y))
  31425. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31426. /* test with 1 generated key and 1 from known test vector */
  31427. ret = wc_curve25519_import_private_raw(sa, sizeof(sa), pa, sizeof(pa),
  31428. userA);
  31429. if (ret != 0)
  31430. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31431. wc_curve25519_free(userB);
  31432. wc_curve25519_init_ex(userB, HEAP_HINT, devId);
  31433. ret = wc_curve25519_make_key(&rng, 32, userB);
  31434. if (ret != 0)
  31435. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31436. x = sizeof(sharedA);
  31437. ret = wc_curve25519_shared_secret(userA, userB, sharedA, &x);
  31438. if (ret != 0)
  31439. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31440. y = sizeof(sharedB);
  31441. ret = wc_curve25519_shared_secret(userB, userA, sharedB, &y);
  31442. if (ret != 0)
  31443. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  31444. /* compare shared secret keys to test they are the same */
  31445. if (y != x)
  31446. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31447. if (XMEMCMP(sharedA, sharedB, x))
  31448. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  31449. ret = curve25519_overflow_test();
  31450. if (ret != 0)
  31451. goto cleanup;
  31452. ret = curve25519_check_public_test();
  31453. if (ret != 0)
  31454. goto cleanup;
  31455. #endif /* HAVE_CURVE25519_SHARED_SECRET && HAVE_CURVE25519_KEY_IMPORT */
  31456. #if !defined(NO_ASN) && defined(HAVE_CURVE25519_KEY_EXPORT) && \
  31457. defined(HAVE_CURVE25519_KEY_IMPORT)
  31458. ret = curve255519_der_test();
  31459. if (ret != 0)
  31460. goto cleanup;
  31461. #endif
  31462. cleanup:
  31463. /* clean up keys when done */
  31464. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31465. wc_curve25519_delete(pubKey, &pubKey);
  31466. wc_curve25519_delete(userB, &userB);
  31467. wc_curve25519_delete(userA, &userA);
  31468. #else
  31469. wc_curve25519_free(pubKey);
  31470. wc_curve25519_free(userB);
  31471. wc_curve25519_free(userA);
  31472. #endif
  31473. wc_FreeRng(&rng);
  31474. return ret;
  31475. }
  31476. #endif /* HAVE_CURVE25519 */
  31477. #ifdef HAVE_ED25519
  31478. #ifdef WOLFSSL_TEST_CERT
  31479. static wc_test_ret_t ed25519_test_cert(void)
  31480. {
  31481. DecodedCert cert[2];
  31482. DecodedCert* serverCert = NULL;
  31483. DecodedCert* caCert = NULL;
  31484. #ifdef HAVE_ED25519_VERIFY
  31485. ed25519_key key;
  31486. ed25519_key* pubKey = NULL;
  31487. int verify;
  31488. #endif /* HAVE_ED25519_VERIFY */
  31489. wc_test_ret_t ret;
  31490. byte* tmp;
  31491. size_t bytes;
  31492. XFILE file;
  31493. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31494. if (tmp == NULL) {
  31495. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31496. }
  31497. #ifdef USE_CERT_BUFFERS_256
  31498. XMEMCPY(tmp, ca_ed25519_cert, sizeof_ca_ed25519_cert);
  31499. bytes = sizeof_ca_ed25519_cert;
  31500. #elif !defined(NO_FILESYSTEM)
  31501. file = XFOPEN(caEd25519Cert, "rb");
  31502. if (file == NULL) {
  31503. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31504. }
  31505. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31506. XFCLOSE(file);
  31507. if (bytes == 0)
  31508. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31509. #else
  31510. /* No certificate to use. */
  31511. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31512. #endif
  31513. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  31514. caCert = &cert[0];
  31515. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  31516. if (ret != 0)
  31517. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31518. #ifdef USE_CERT_BUFFERS_256
  31519. XMEMCPY(tmp, server_ed25519_cert, sizeof_server_ed25519_cert);
  31520. bytes = sizeof_server_ed25519_cert;
  31521. #elif !defined(NO_FILESYSTEM)
  31522. file = XFOPEN(serverEd25519Cert, "rb");
  31523. if (file == NULL) {
  31524. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31525. }
  31526. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  31527. XFCLOSE(file);
  31528. if (bytes == 0)
  31529. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31530. #else
  31531. /* No certificate to use. */
  31532. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  31533. #endif
  31534. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  31535. serverCert = &cert[1];
  31536. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  31537. if (ret != 0)
  31538. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31539. #ifdef HAVE_ED25519_VERIFY
  31540. ret = wc_ed25519_init(&key);
  31541. if (ret < 0)
  31542. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31543. pubKey = &key;
  31544. ret = wc_ed25519_import_public(caCert->publicKey, caCert->pubKeySize,
  31545. pubKey);
  31546. if (ret < 0)
  31547. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31548. ret = wc_ed25519_verify_msg(serverCert->signature, serverCert->sigLength,
  31549. serverCert->source + serverCert->certBegin,
  31550. serverCert->sigIndex - serverCert->certBegin,
  31551. &verify, pubKey);
  31552. if (ret < 0 || verify != 1)
  31553. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31554. #endif /* HAVE_ED25519_VERIFY */
  31555. done:
  31556. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31557. #ifdef HAVE_ED25519_VERIFY
  31558. wc_ed25519_free(pubKey);
  31559. #endif /* HAVE_ED25519_VERIFY */
  31560. if (caCert != NULL)
  31561. FreeDecodedCert(caCert);
  31562. if (serverCert != NULL)
  31563. FreeDecodedCert(serverCert);
  31564. return ret;
  31565. }
  31566. static wc_test_ret_t ed25519_test_make_cert(void)
  31567. {
  31568. WC_RNG rng;
  31569. Cert cert;
  31570. DecodedCert decode;
  31571. ed25519_key key;
  31572. ed25519_key* privKey = NULL;
  31573. wc_test_ret_t ret = 0;
  31574. byte* tmp = NULL;
  31575. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  31576. #ifndef HAVE_FIPS
  31577. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  31578. #else
  31579. ret = wc_InitRng(&rng);
  31580. #endif
  31581. if (ret != 0)
  31582. return WC_TEST_RET_ENC_EC(ret);
  31583. wc_ed25519_init(&key);
  31584. privKey = &key;
  31585. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, privKey);
  31586. cert.daysValid = 365 * 2;
  31587. cert.selfSigned = 1;
  31588. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  31589. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  31590. cert.isCA = 0;
  31591. #ifdef WOLFSSL_CERT_EXT
  31592. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  31593. if (ret < 0)
  31594. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31595. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31596. if (ret < 0)
  31597. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31598. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED25519_TYPE, privKey);
  31599. if (ret < 0)
  31600. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31601. #endif
  31602. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31603. if (tmp == NULL) {
  31604. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  31605. }
  31606. cert.sigType = CTC_ED25519;
  31607. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED25519_TYPE, privKey, &rng);
  31608. if (ret < 0)
  31609. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31610. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF,
  31611. ED25519_TYPE, privKey, &rng);
  31612. if (ret < 0)
  31613. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31614. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  31615. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  31616. FreeDecodedCert(&decode);
  31617. if (ret != 0)
  31618. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  31619. done:
  31620. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  31621. wc_ed25519_free(privKey);
  31622. wc_FreeRng(&rng);
  31623. return ret;
  31624. }
  31625. #endif /* WOLFSSL_TEST_CERT */
  31626. #if defined(HAVE_ED25519_KEY_IMPORT)
  31627. static wc_test_ret_t ed25519_test_check_key(void)
  31628. {
  31629. /* Fails to find x-ordinate from this y-ordinate. */
  31630. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  31631. 0x40,
  31632. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31633. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31634. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31635. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31636. };
  31637. /* Y-ordinate value larger than prime. */
  31638. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  31639. 0x40,
  31640. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31641. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31642. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31643. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31644. };
  31645. /* Y-ordinate value equal to prime. */
  31646. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  31647. 0x40,
  31648. 0xed,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31649. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31650. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31651. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31652. };
  31653. /* Y-ordinate value equal to prime - 1. */
  31654. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  31655. 0x40,
  31656. 0xec,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31657. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31658. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31659. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
  31660. };
  31661. ed25519_key key;
  31662. int ret;
  31663. int res = 0;
  31664. /* Initialize key for use. */
  31665. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31666. if (ret != 0) {
  31667. return WC_TEST_RET_ENC_NC;
  31668. }
  31669. /* Load bad public key only and perform checks. */
  31670. ret = wc_ed25519_import_public(key_bad_y, ED25519_PUB_KEY_SIZE + 1, &key);
  31671. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31672. res = WC_TEST_RET_ENC_NC;
  31673. }
  31674. if (res == 0) {
  31675. /* Load bad public key only and perform checks. */
  31676. ret = wc_ed25519_import_public(key_bad_y_max, ED25519_PUB_KEY_SIZE + 1,
  31677. &key);
  31678. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31679. res = WC_TEST_RET_ENC_NC;
  31680. }
  31681. }
  31682. if (res == 0) {
  31683. /* Load bad public key only and perform checks. */
  31684. ret = wc_ed25519_import_public(key_bad_y_is_p, ED25519_PUB_KEY_SIZE + 1,
  31685. &key);
  31686. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  31687. res = WC_TEST_RET_ENC_NC;
  31688. }
  31689. }
  31690. if (res == 0) {
  31691. /* Load good public key only and perform checks. */
  31692. ret = wc_ed25519_import_public(key_y_is_p_minus_1,
  31693. ED25519_PUB_KEY_SIZE + 1, &key);
  31694. if (ret != 0) {
  31695. res = WC_TEST_RET_ENC_NC;
  31696. }
  31697. }
  31698. /* Dispose of key. */
  31699. wc_ed25519_free(&key);
  31700. return res;
  31701. }
  31702. #endif
  31703. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31704. defined(HAVE_ED25519_KEY_IMPORT)
  31705. static wc_test_ret_t ed25519ctx_test(void)
  31706. {
  31707. wc_test_ret_t ret;
  31708. byte out[ED25519_SIG_SIZE];
  31709. word32 outlen;
  31710. #ifdef HAVE_ED25519_VERIFY
  31711. int verify = 0;
  31712. #endif /* HAVE_ED25519_VERIFY */
  31713. ed25519_key key;
  31714. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  31715. 0x03,0x05,0x33,0x4e,0x38,0x1a,0xf7,0x8f,
  31716. 0x14,0x1c,0xb6,0x66,0xf6,0x19,0x9f,0x57,
  31717. 0xbc,0x34,0x95,0x33,0x5a,0x25,0x6a,0x95,
  31718. 0xbd,0x2a,0x55,0xbf,0x54,0x66,0x63,0xf6
  31719. };
  31720. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  31721. 0xdf,0xc9,0x42,0x5e,0x4f,0x96,0x8f,0x7f,
  31722. 0x0c,0x29,0xf0,0x25,0x9c,0xf5,0xf9,0xae,
  31723. 0xd6,0x85,0x1c,0x2b,0xb4,0xad,0x8b,0xfb,
  31724. 0x86,0x0c,0xfe,0xe0,0xab,0x24,0x82,0x92
  31725. };
  31726. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx1[] = {
  31727. 0x55,0xa4,0xcc,0x2f,0x70,0xa5,0x4e,0x04,
  31728. 0x28,0x8c,0x5f,0x4c,0xd1,0xe4,0x5a,0x7b,
  31729. 0xb5,0x20,0xb3,0x62,0x92,0x91,0x18,0x76,
  31730. 0xca,0xda,0x73,0x23,0x19,0x8d,0xd8,0x7a,
  31731. 0x8b,0x36,0x95,0x0b,0x95,0x13,0x00,0x22,
  31732. 0x90,0x7a,0x7f,0xb7,0xc4,0xe9,0xb2,0xd5,
  31733. 0xf6,0xcc,0xa6,0x85,0xa5,0x87,0xb4,0xb2,
  31734. 0x1f,0x4b,0x88,0x8e,0x4e,0x7e,0xdb,0x0d
  31735. };
  31736. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx2[] = {
  31737. 0xcc,0x5e,0x63,0xa2,0x7e,0x94,0xaf,0xd3,
  31738. 0x41,0x83,0x38,0xd2,0x48,0x6f,0xa9,0x2a,
  31739. 0xf9,0x91,0x7c,0x2d,0x98,0x9e,0x06,0xe5,
  31740. 0x02,0x77,0x72,0x1c,0x34,0x38,0x18,0xb4,
  31741. 0x21,0x96,0xbc,0x29,0x2e,0x68,0xf3,0x4d,
  31742. 0x85,0x9b,0xbe,0xad,0x17,0x9f,0x54,0x54,
  31743. 0x2d,0x4b,0x04,0xdc,0xfb,0xfa,0x4a,0x68,
  31744. 0x4e,0x39,0x50,0xfb,0x1c,0xcd,0x8d,0x0d
  31745. };
  31746. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  31747. 0xf7,0x26,0x93,0x6d,0x19,0xc8,0x00,0x49,
  31748. 0x4e,0x3f,0xda,0xff,0x20,0xb2,0x76,0xa8
  31749. };
  31750. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  31751. 0x66,0x6f,0x6f
  31752. };
  31753. outlen = sizeof(out);
  31754. XMEMSET(out, 0, sizeof(out));
  31755. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31756. if (ret != 0)
  31757. return 10800;
  31758. ret = wc_ed25519_import_private_key(sKeyCtx, ED25519_KEY_SIZE, pKeyCtx,
  31759. sizeof(pKeyCtx), &key);
  31760. if (ret == 0)
  31761. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31762. contextCtx, sizeof(contextCtx));
  31763. if (ret == 0 && XMEMCMP(out, sigCtx1, 64) != 0)
  31764. ret = WC_TEST_RET_ENC_NC;
  31765. #if defined(HAVE_ED25519_VERIFY)
  31766. /* test verify on good msg */
  31767. if (ret == 0)
  31768. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31769. &verify, &key, contextCtx, sizeof(contextCtx));
  31770. if (ret == 0 && verify != 1)
  31771. ret = WC_TEST_RET_ENC_NC;
  31772. #endif
  31773. if (ret == 0)
  31774. ret = wc_ed25519ctx_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  31775. NULL, 0);
  31776. if (ret == 0 && XMEMCMP(out, sigCtx2, 64) != 0)
  31777. ret = WC_TEST_RET_ENC_NC;
  31778. #if defined(HAVE_ED25519_VERIFY)
  31779. /* test verify on good msg */
  31780. if (ret == 0)
  31781. ret = wc_ed25519ctx_verify_msg(out, outlen, msgCtx, sizeof(msgCtx),
  31782. &verify, &key, NULL, 0);
  31783. if (ret == 0 && verify != 1)
  31784. ret = WC_TEST_RET_ENC_NC;
  31785. #endif
  31786. wc_ed25519_free(&key);
  31787. return ret;
  31788. }
  31789. static wc_test_ret_t ed25519ph_test(void)
  31790. {
  31791. wc_test_ret_t ret = 0;
  31792. byte out[ED25519_SIG_SIZE];
  31793. word32 outlen;
  31794. #ifdef HAVE_ED25519_VERIFY
  31795. int verify = 0;
  31796. #endif /* HAVE_ED25519_VERIFY */
  31797. ed25519_key key;
  31798. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  31799. 0x83,0x3f,0xe6,0x24,0x09,0x23,0x7b,0x9d,
  31800. 0x62,0xec,0x77,0x58,0x75,0x20,0x91,0x1e,
  31801. 0x9a,0x75,0x9c,0xec,0x1d,0x19,0x75,0x5b,
  31802. 0x7d,0xa9,0x01,0xb9,0x6d,0xca,0x3d,0x42
  31803. };
  31804. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  31805. 0xec,0x17,0x2b,0x93,0xad,0x5e,0x56,0x3b,
  31806. 0xf4,0x93,0x2c,0x70,0xe1,0x24,0x50,0x34,
  31807. 0xc3,0x54,0x67,0xef,0x2e,0xfd,0x4d,0x64,
  31808. 0xeb,0xf8,0x19,0x68,0x34,0x67,0xe2,0xbf
  31809. };
  31810. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  31811. 0x98,0xa7,0x02,0x22,0xf0,0xb8,0x12,0x1a,
  31812. 0xa9,0xd3,0x0f,0x81,0x3d,0x68,0x3f,0x80,
  31813. 0x9e,0x46,0x2b,0x46,0x9c,0x7f,0xf8,0x76,
  31814. 0x39,0x49,0x9b,0xb9,0x4e,0x6d,0xae,0x41,
  31815. 0x31,0xf8,0x50,0x42,0x46,0x3c,0x2a,0x35,
  31816. 0x5a,0x20,0x03,0xd0,0x62,0xad,0xf5,0xaa,
  31817. 0xa1,0x0b,0x8c,0x61,0xe6,0x36,0x06,0x2a,
  31818. 0xaa,0xd1,0x1c,0x2a,0x26,0x08,0x34,0x06
  31819. };
  31820. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  31821. 0xe0,0x39,0x70,0x2b,0x4c,0x25,0x95,0xa6,
  31822. 0xa5,0x41,0xac,0x85,0x09,0x23,0x6e,0x29,
  31823. 0x90,0x47,0x47,0x95,0x33,0x0c,0x9b,0x34,
  31824. 0xa7,0x5f,0x58,0xa6,0x60,0x12,0x9e,0x08,
  31825. 0xfd,0x73,0x69,0x43,0xfb,0x19,0x43,0xa5,
  31826. 0x57,0x20,0xb9,0xe0,0x95,0x7b,0x1e,0xd6,
  31827. 0x73,0x48,0x16,0x61,0x9f,0x13,0x88,0xf4,
  31828. 0x3f,0x73,0xe6,0xe3,0xba,0xa8,0x1c,0x0e
  31829. };
  31830. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  31831. 0x61,0x62,0x63
  31832. };
  31833. /* SHA-512 hash of msgPh */
  31834. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  31835. 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
  31836. 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
  31837. 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
  31838. 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
  31839. 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
  31840. 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
  31841. 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
  31842. 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f
  31843. };
  31844. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  31845. 0x66,0x6f,0x6f
  31846. };
  31847. outlen = sizeof(out);
  31848. XMEMSET(out, 0, sizeof(out));
  31849. ret = wc_ed25519_init_ex(&key, HEAP_HINT, devId);
  31850. if (ret != 0)
  31851. return WC_TEST_RET_ENC_EC(ret);
  31852. ret = wc_ed25519_import_private_key(sKeyPh, ED25519_KEY_SIZE, pKeyPh,
  31853. sizeof(pKeyPh), &key);
  31854. if (ret == 0)
  31855. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31856. NULL, 0);
  31857. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31858. ret = WC_TEST_RET_ENC_NC;
  31859. #if defined(HAVE_ED25519_VERIFY)
  31860. /* test verify on good msg */
  31861. if (ret == 0)
  31862. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh),
  31863. &verify, &key, NULL, 0);
  31864. if (ret == 0 && verify != 1)
  31865. ret = WC_TEST_RET_ENC_NC;
  31866. #endif
  31867. if (ret == 0)
  31868. ret = wc_ed25519ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  31869. contextPh2, sizeof(contextPh2));
  31870. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31871. ret = WC_TEST_RET_ENC_NC;
  31872. #if defined(HAVE_ED25519_VERIFY)
  31873. /* test verify on good msg */
  31874. if (ret == 0)
  31875. ret = wc_ed25519ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify,
  31876. &key, contextPh2, sizeof(contextPh2));
  31877. if (ret == 0 && verify != 1)
  31878. ret = WC_TEST_RET_ENC_NC;
  31879. #endif
  31880. if (ret == 0)
  31881. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31882. NULL, 0);
  31883. if (ret == 0 && XMEMCMP(out, sigPh1, 64) != 0)
  31884. ret = WC_TEST_RET_ENC_NC;
  31885. #if defined(HAVE_ED25519_VERIFY)
  31886. if (ret == 0)
  31887. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh),
  31888. &verify, &key, NULL, 0);
  31889. if (ret == 0 && verify != 1)
  31890. ret = WC_TEST_RET_ENC_NC;
  31891. #endif
  31892. if (ret == 0)
  31893. ret = wc_ed25519ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  31894. contextPh2, sizeof(contextPh2));
  31895. if (ret == 0 && XMEMCMP(out, sigPh2, 64) != 0)
  31896. ret = WC_TEST_RET_ENC_NC;
  31897. #if defined(HAVE_ED25519_VERIFY)
  31898. if (ret == 0)
  31899. ret = wc_ed25519ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  31900. &key, contextPh2, sizeof(contextPh2));
  31901. if (ret == 0 && verify != 1)
  31902. ret = WC_TEST_RET_ENC_NC;
  31903. #endif
  31904. wc_ed25519_free(&key);
  31905. return ret;
  31906. }
  31907. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31908. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed25519_test(void)
  31909. {
  31910. wc_test_ret_t ret;
  31911. WC_RNG rng;
  31912. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  31913. defined(HAVE_ED25519_KEY_IMPORT)
  31914. byte out[ED25519_SIG_SIZE];
  31915. byte exportPKey[ED25519_KEY_SIZE];
  31916. byte exportSKey[ED25519_KEY_SIZE];
  31917. word32 exportPSz;
  31918. word32 exportSSz;
  31919. int i;
  31920. word32 outlen;
  31921. #ifdef HAVE_ED25519_VERIFY
  31922. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  31923. int j;
  31924. #endif
  31925. int verify;
  31926. #endif /* HAVE_ED25519_VERIFY */
  31927. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  31928. word32 keySz, sigSz;
  31929. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  31930. ed25519_key* key = NULL;
  31931. ed25519_key* key2 = NULL;
  31932. #else
  31933. ed25519_key key[1];
  31934. ed25519_key key2[1];
  31935. #endif
  31936. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) && \
  31937. defined(HAVE_ED25519_KEY_IMPORT)
  31938. /* test vectors from
  31939. https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-02
  31940. */
  31941. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  31942. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31943. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31944. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31945. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31946. };
  31947. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  31948. 0x4c,0xcd,0x08,0x9b,0x28,0xff,0x96,0xda,
  31949. 0x9d,0xb6,0xc3,0x46,0xec,0x11,0x4e,0x0f,
  31950. 0x5b,0x8a,0x31,0x9f,0x35,0xab,0xa6,0x24,
  31951. 0xda,0x8c,0xf6,0xed,0x4f,0xb8,0xa6,0xfb
  31952. };
  31953. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  31954. 0xc5,0xaa,0x8d,0xf4,0x3f,0x9f,0x83,0x7b,
  31955. 0xed,0xb7,0x44,0x2f,0x31,0xdc,0xb7,0xb1,
  31956. 0x66,0xd3,0x85,0x35,0x07,0x6f,0x09,0x4b,
  31957. 0x85,0xce,0x3a,0x2e,0x0b,0x44,0x58,0xf7
  31958. };
  31959. /* uncompressed test */
  31960. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  31961. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31962. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31963. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31964. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31965. };
  31966. /* compressed prefix test */
  31967. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  31968. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  31969. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  31970. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  31971. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  31972. };
  31973. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  31974. 0xf5,0xe5,0x76,0x7c,0xf1,0x53,0x31,0x95,
  31975. 0x17,0x63,0x0f,0x22,0x68,0x76,0xb8,0x6c,
  31976. 0x81,0x60,0xcc,0x58,0x3b,0xc0,0x13,0x74,
  31977. 0x4c,0x6b,0xf2,0x55,0xf5,0xcc,0x0e,0xe5
  31978. };
  31979. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  31980. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  31981. 0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  31982. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  31983. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  31984. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  31985. };
  31986. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  31987. 0x3d,0x40,0x17,0xc3,0xe8,0x43,0x89,0x5a,
  31988. 0x92,0xb7,0x0a,0xa7,0x4d,0x1b,0x7e,0xbc,
  31989. 0x9c,0x98,0x2c,0xcf,0x2e,0xc4,0x96,0x8c,
  31990. 0xc0,0xcd,0x55,0xf1,0x2a,0xf4,0x66,0x0c
  31991. };
  31992. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  31993. 0xfc,0x51,0xcd,0x8e,0x62,0x18,0xa1,0xa3,
  31994. 0x8d,0xa4,0x7e,0xd0,0x02,0x30,0xf0,0x58,
  31995. 0x08,0x16,0xed,0x13,0xba,0x33,0x03,0xac,
  31996. 0x5d,0xeb,0x91,0x15,0x48,0x90,0x80,0x25
  31997. };
  31998. /* uncompressed test */
  31999. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  32000. 0x04,0x55,0xd0,0xe0,0x9a,0x2b,0x9d,0x34,
  32001. 0x29,0x22,0x97,0xe0,0x8d,0x60,0xd0,0xf6,
  32002. 0x20,0xc5,0x13,0xd4,0x72,0x53,0x18,0x7c,
  32003. 0x24,0xb1,0x27,0x86,0xbd,0x77,0x76,0x45,
  32004. 0xce,0x1a,0x51,0x07,0xf7,0x68,0x1a,0x02,
  32005. 0xaf,0x25,0x23,0xa6,0xda,0xf3,0x72,0xe1,
  32006. 0x0e,0x3a,0x07,0x64,0xc9,0xd3,0xfe,0x4b,
  32007. 0xd5,0xb7,0x0a,0xb1,0x82,0x01,0x98,0x5a,
  32008. 0xd7
  32009. };
  32010. /* compressed prefix */
  32011. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  32012. 0x40,0xd7,0x5a,0x98,0x01,0x82,0xb1,0x0a,0xb7,
  32013. 0xd5,0x4b,0xfe,0xd3,0xc9,0x64,0x07,0x3a,
  32014. 0x0e,0xe1,0x72,0xf3,0xda,0xa6,0x23,0x25,
  32015. 0xaf,0x02,0x1a,0x68,0xf7,0x07,0x51,0x1a
  32016. };
  32017. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  32018. 0x27,0x81,0x17,0xfc,0x14,0x4c,0x72,0x34,
  32019. 0x0f,0x67,0xd0,0xf2,0x31,0x6e,0x83,0x86,
  32020. 0xce,0xff,0xbf,0x2b,0x24,0x28,0xc9,0xc5,
  32021. 0x1f,0xef,0x7c,0x59,0x7f,0x1d,0x42,0x6e
  32022. };
  32023. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  32024. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  32025. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  32026. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  32027. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32028. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32029. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32030. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32031. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32032. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32033. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32034. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32035. };
  32036. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  32037. 0x92,0xa0,0x09,0xa9,0xf0,0xd4,0xca,0xb8,
  32038. 0x72,0x0e,0x82,0x0b,0x5f,0x64,0x25,0x40,
  32039. 0xa2,0xb2,0x7b,0x54,0x16,0x50,0x3f,0x8f,
  32040. 0xb3,0x76,0x22,0x23,0xeb,0xdb,0x69,0xda,
  32041. 0x08,0x5a,0xc1,0xe4,0x3e,0x15,0x99,0x6e,
  32042. 0x45,0x8f,0x36,0x13,0xd0,0xf1,0x1d,0x8c,
  32043. 0x38,0x7b,0x2e,0xae,0xb4,0x30,0x2a,0xee,
  32044. 0xb0,0x0d,0x29,0x16,0x12,0xbb,0x0c,0x00
  32045. };
  32046. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  32047. 0x62,0x91,0xd6,0x57,0xde,0xec,0x24,0x02,
  32048. 0x48,0x27,0xe6,0x9c,0x3a,0xbe,0x01,0xa3,
  32049. 0x0c,0xe5,0x48,0xa2,0x84,0x74,0x3a,0x44,
  32050. 0x5e,0x36,0x80,0xd7,0xdb,0x5a,0xc3,0xac,
  32051. 0x18,0xff,0x9b,0x53,0x8d,0x16,0xf2,0x90,
  32052. 0xae,0x67,0xf7,0x60,0x98,0x4d,0xc6,0x59,
  32053. 0x4a,0x7c,0x15,0xe9,0x71,0x6e,0xd2,0x8d,
  32054. 0xc0,0x27,0xbe,0xce,0xea,0x1e,0xc4,0x0a
  32055. };
  32056. /* uncompressed test */
  32057. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  32058. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32059. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32060. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32061. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32062. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32063. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32064. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32065. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32066. };
  32067. /* compressed prefix */
  32068. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  32069. 0xe5,0x56,0x43,0x00,0xc3,0x60,0xac,0x72,
  32070. 0x90,0x86,0xe2,0xcc,0x80,0x6e,0x82,0x8a,
  32071. 0x84,0x87,0x7f,0x1e,0xb8,0xe5,0xd9,0x74,
  32072. 0xd8,0x73,0xe0,0x65,0x22,0x49,0x01,0x55,
  32073. 0x5f,0xb8,0x82,0x15,0x90,0xa3,0x3b,0xac,
  32074. 0xc6,0x1e,0x39,0x70,0x1c,0xf9,0xb4,0x6b,
  32075. 0xd2,0x5b,0xf5,0xf0,0x59,0x5b,0xbe,0x24,
  32076. 0x65,0x51,0x41,0x43,0x8e,0x7a,0x10,0x0b
  32077. };
  32078. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  32079. 0x0a,0xab,0x4c,0x90,0x05,0x01,0xb3,0xe2,
  32080. 0x4d,0x7c,0xdf,0x46,0x63,0x32,0x6a,0x3a,
  32081. 0x87,0xdf,0x5e,0x48,0x43,0xb2,0xcb,0xdb,
  32082. 0x67,0xcb,0xf6,0xe4,0x60,0xfe,0xc3,0x50,
  32083. 0xaa,0x53,0x71,0xb1,0x50,0x8f,0x9f,0x45,
  32084. 0x28,0xec,0xea,0x23,0xc4,0x36,0xd9,0x4b,
  32085. 0x5e,0x8f,0xcd,0x4f,0x68,0x1e,0x30,0xa6,
  32086. 0xac,0x00,0xa9,0x70,0x4a,0x18,0x8a,0x03
  32087. };
  32088. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  32089. WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = {0x0 };
  32090. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = {0x72};
  32091. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = {0xAF,0x82};
  32092. /* test of a 1024 byte long message */
  32093. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  32094. 0x08,0xb8,0xb2,0xb7,0x33,0x42,0x42,0x43,
  32095. 0x76,0x0f,0xe4,0x26,0xa4,0xb5,0x49,0x08,
  32096. 0x63,0x21,0x10,0xa6,0x6c,0x2f,0x65,0x91,
  32097. 0xea,0xbd,0x33,0x45,0xe3,0xe4,0xeb,0x98,
  32098. 0xfa,0x6e,0x26,0x4b,0xf0,0x9e,0xfe,0x12,
  32099. 0xee,0x50,0xf8,0xf5,0x4e,0x9f,0x77,0xb1,
  32100. 0xe3,0x55,0xf6,0xc5,0x05,0x44,0xe2,0x3f,
  32101. 0xb1,0x43,0x3d,0xdf,0x73,0xbe,0x84,0xd8,
  32102. 0x79,0xde,0x7c,0x00,0x46,0xdc,0x49,0x96,
  32103. 0xd9,0xe7,0x73,0xf4,0xbc,0x9e,0xfe,0x57,
  32104. 0x38,0x82,0x9a,0xdb,0x26,0xc8,0x1b,0x37,
  32105. 0xc9,0x3a,0x1b,0x27,0x0b,0x20,0x32,0x9d,
  32106. 0x65,0x86,0x75,0xfc,0x6e,0xa5,0x34,0xe0,
  32107. 0x81,0x0a,0x44,0x32,0x82,0x6b,0xf5,0x8c,
  32108. 0x94,0x1e,0xfb,0x65,0xd5,0x7a,0x33,0x8b,
  32109. 0xbd,0x2e,0x26,0x64,0x0f,0x89,0xff,0xbc,
  32110. 0x1a,0x85,0x8e,0xfc,0xb8,0x55,0x0e,0xe3,
  32111. 0xa5,0xe1,0x99,0x8b,0xd1,0x77,0xe9,0x3a,
  32112. 0x73,0x63,0xc3,0x44,0xfe,0x6b,0x19,0x9e,
  32113. 0xe5,0xd0,0x2e,0x82,0xd5,0x22,0xc4,0xfe,
  32114. 0xba,0x15,0x45,0x2f,0x80,0x28,0x8a,0x82,
  32115. 0x1a,0x57,0x91,0x16,0xec,0x6d,0xad,0x2b,
  32116. 0x3b,0x31,0x0d,0xa9,0x03,0x40,0x1a,0xa6,
  32117. 0x21,0x00,0xab,0x5d,0x1a,0x36,0x55,0x3e,
  32118. 0x06,0x20,0x3b,0x33,0x89,0x0c,0xc9,0xb8,
  32119. 0x32,0xf7,0x9e,0xf8,0x05,0x60,0xcc,0xb9,
  32120. 0xa3,0x9c,0xe7,0x67,0x96,0x7e,0xd6,0x28,
  32121. 0xc6,0xad,0x57,0x3c,0xb1,0x16,0xdb,0xef,
  32122. 0xef,0xd7,0x54,0x99,0xda,0x96,0xbd,0x68,
  32123. 0xa8,0xa9,0x7b,0x92,0x8a,0x8b,0xbc,0x10,
  32124. 0x3b,0x66,0x21,0xfc,0xde,0x2b,0xec,0xa1,
  32125. 0x23,0x1d,0x20,0x6b,0xe6,0xcd,0x9e,0xc7,
  32126. 0xaf,0xf6,0xf6,0xc9,0x4f,0xcd,0x72,0x04,
  32127. 0xed,0x34,0x55,0xc6,0x8c,0x83,0xf4,0xa4,
  32128. 0x1d,0xa4,0xaf,0x2b,0x74,0xef,0x5c,0x53,
  32129. 0xf1,0xd8,0xac,0x70,0xbd,0xcb,0x7e,0xd1,
  32130. 0x85,0xce,0x81,0xbd,0x84,0x35,0x9d,0x44,
  32131. 0x25,0x4d,0x95,0x62,0x9e,0x98,0x55,0xa9,
  32132. 0x4a,0x7c,0x19,0x58,0xd1,0xf8,0xad,0xa5,
  32133. 0xd0,0x53,0x2e,0xd8,0xa5,0xaa,0x3f,0xb2,
  32134. 0xd1,0x7b,0xa7,0x0e,0xb6,0x24,0x8e,0x59,
  32135. 0x4e,0x1a,0x22,0x97,0xac,0xbb,0xb3,0x9d,
  32136. 0x50,0x2f,0x1a,0x8c,0x6e,0xb6,0xf1,0xce,
  32137. 0x22,0xb3,0xde,0x1a,0x1f,0x40,0xcc,0x24,
  32138. 0x55,0x41,0x19,0xa8,0x31,0xa9,0xaa,0xd6,
  32139. 0x07,0x9c,0xad,0x88,0x42,0x5d,0xe6,0xbd,
  32140. 0xe1,0xa9,0x18,0x7e,0xbb,0x60,0x92,0xcf,
  32141. 0x67,0xbf,0x2b,0x13,0xfd,0x65,0xf2,0x70,
  32142. 0x88,0xd7,0x8b,0x7e,0x88,0x3c,0x87,0x59,
  32143. 0xd2,0xc4,0xf5,0xc6,0x5a,0xdb,0x75,0x53,
  32144. 0x87,0x8a,0xd5,0x75,0xf9,0xfa,0xd8,0x78,
  32145. 0xe8,0x0a,0x0c,0x9b,0xa6,0x3b,0xcb,0xcc,
  32146. 0x27,0x32,0xe6,0x94,0x85,0xbb,0xc9,0xc9,
  32147. 0x0b,0xfb,0xd6,0x24,0x81,0xd9,0x08,0x9b,
  32148. 0xec,0xcf,0x80,0xcf,0xe2,0xdf,0x16,0xa2,
  32149. 0xcf,0x65,0xbd,0x92,0xdd,0x59,0x7b,0x07,
  32150. 0x07,0xe0,0x91,0x7a,0xf4,0x8b,0xbb,0x75,
  32151. 0xfe,0xd4,0x13,0xd2,0x38,0xf5,0x55,0x5a,
  32152. 0x7a,0x56,0x9d,0x80,0xc3,0x41,0x4a,0x8d,
  32153. 0x08,0x59,0xdc,0x65,0xa4,0x61,0x28,0xba,
  32154. 0xb2,0x7a,0xf8,0x7a,0x71,0x31,0x4f,0x31,
  32155. 0x8c,0x78,0x2b,0x23,0xeb,0xfe,0x80,0x8b,
  32156. 0x82,0xb0,0xce,0x26,0x40,0x1d,0x2e,0x22,
  32157. 0xf0,0x4d,0x83,0xd1,0x25,0x5d,0xc5,0x1a,
  32158. 0xdd,0xd3,0xb7,0x5a,0x2b,0x1a,0xe0,0x78,
  32159. 0x45,0x04,0xdf,0x54,0x3a,0xf8,0x96,0x9b,
  32160. 0xe3,0xea,0x70,0x82,0xff,0x7f,0xc9,0x88,
  32161. 0x8c,0x14,0x4d,0xa2,0xaf,0x58,0x42,0x9e,
  32162. 0xc9,0x60,0x31,0xdb,0xca,0xd3,0xda,0xd9,
  32163. 0xaf,0x0d,0xcb,0xaa,0xaf,0x26,0x8c,0xb8,
  32164. 0xfc,0xff,0xea,0xd9,0x4f,0x3c,0x7c,0xa4,
  32165. 0x95,0xe0,0x56,0xa9,0xb4,0x7a,0xcd,0xb7,
  32166. 0x51,0xfb,0x73,0xe6,0x66,0xc6,0xc6,0x55,
  32167. 0xad,0xe8,0x29,0x72,0x97,0xd0,0x7a,0xd1,
  32168. 0xba,0x5e,0x43,0xf1,0xbc,0xa3,0x23,0x01,
  32169. 0x65,0x13,0x39,0xe2,0x29,0x04,0xcc,0x8c,
  32170. 0x42,0xf5,0x8c,0x30,0xc0,0x4a,0xaf,0xdb,
  32171. 0x03,0x8d,0xda,0x08,0x47,0xdd,0x98,0x8d,
  32172. 0xcd,0xa6,0xf3,0xbf,0xd1,0x5c,0x4b,0x4c,
  32173. 0x45,0x25,0x00,0x4a,0xa0,0x6e,0xef,0xf8,
  32174. 0xca,0x61,0x78,0x3a,0xac,0xec,0x57,0xfb,
  32175. 0x3d,0x1f,0x92,0xb0,0xfe,0x2f,0xd1,0xa8,
  32176. 0x5f,0x67,0x24,0x51,0x7b,0x65,0xe6,0x14,
  32177. 0xad,0x68,0x08,0xd6,0xf6,0xee,0x34,0xdf,
  32178. 0xf7,0x31,0x0f,0xdc,0x82,0xae,0xbf,0xd9,
  32179. 0x04,0xb0,0x1e,0x1d,0xc5,0x4b,0x29,0x27,
  32180. 0x09,0x4b,0x2d,0xb6,0x8d,0x6f,0x90,0x3b,
  32181. 0x68,0x40,0x1a,0xde,0xbf,0x5a,0x7e,0x08,
  32182. 0xd7,0x8f,0xf4,0xef,0x5d,0x63,0x65,0x3a,
  32183. 0x65,0x04,0x0c,0xf9,0xbf,0xd4,0xac,0xa7,
  32184. 0x98,0x4a,0x74,0xd3,0x71,0x45,0x98,0x67,
  32185. 0x80,0xfc,0x0b,0x16,0xac,0x45,0x16,0x49,
  32186. 0xde,0x61,0x88,0xa7,0xdb,0xdf,0x19,0x1f,
  32187. 0x64,0xb5,0xfc,0x5e,0x2a,0xb4,0x7b,0x57,
  32188. 0xf7,0xf7,0x27,0x6c,0xd4,0x19,0xc1,0x7a,
  32189. 0x3c,0xa8,0xe1,0xb9,0x39,0xae,0x49,0xe4,
  32190. 0x88,0xac,0xba,0x6b,0x96,0x56,0x10,0xb5,
  32191. 0x48,0x01,0x09,0xc8,0xb1,0x7b,0x80,0xe1,
  32192. 0xb7,0xb7,0x50,0xdf,0xc7,0x59,0x8d,0x5d,
  32193. 0x50,0x11,0xfd,0x2d,0xcc,0x56,0x00,0xa3,
  32194. 0x2e,0xf5,0xb5,0x2a,0x1e,0xcc,0x82,0x0e,
  32195. 0x30,0x8a,0xa3,0x42,0x72,0x1a,0xac,0x09,
  32196. 0x43,0xbf,0x66,0x86,0xb6,0x4b,0x25,0x79,
  32197. 0x37,0x65,0x04,0xcc,0xc4,0x93,0xd9,0x7e,
  32198. 0x6a,0xed,0x3f,0xb0,0xf9,0xcd,0x71,0xa4,
  32199. 0x3d,0xd4,0x97,0xf0,0x1f,0x17,0xc0,0xe2,
  32200. 0xcb,0x37,0x97,0xaa,0x2a,0x2f,0x25,0x66,
  32201. 0x56,0x16,0x8e,0x6c,0x49,0x6a,0xfc,0x5f,
  32202. 0xb9,0x32,0x46,0xf6,0xb1,0x11,0x63,0x98,
  32203. 0xa3,0x46,0xf1,0xa6,0x41,0xf3,0xb0,0x41,
  32204. 0xe9,0x89,0xf7,0x91,0x4f,0x90,0xcc,0x2c,
  32205. 0x7f,0xff,0x35,0x78,0x76,0xe5,0x06,0xb5,
  32206. 0x0d,0x33,0x4b,0xa7,0x7c,0x22,0x5b,0xc3,
  32207. 0x07,0xba,0x53,0x71,0x52,0xf3,0xf1,0x61,
  32208. 0x0e,0x4e,0xaf,0xe5,0x95,0xf6,0xd9,0xd9,
  32209. 0x0d,0x11,0xfa,0xa9,0x33,0xa1,0x5e,0xf1,
  32210. 0x36,0x95,0x46,0x86,0x8a,0x7f,0x3a,0x45,
  32211. 0xa9,0x67,0x68,0xd4,0x0f,0xd9,0xd0,0x34,
  32212. 0x12,0xc0,0x91,0xc6,0x31,0x5c,0xf4,0xfd,
  32213. 0xe7,0xcb,0x68,0x60,0x69,0x37,0x38,0x0d,
  32214. 0xb2,0xea,0xaa,0x70,0x7b,0x4c,0x41,0x85,
  32215. 0xc3,0x2e,0xdd,0xcd,0xd3,0x06,0x70,0x5e,
  32216. 0x4d,0xc1,0xff,0xc8,0x72,0xee,0xee,0x47,
  32217. 0x5a,0x64,0xdf,0xac,0x86,0xab,0xa4,0x1c,
  32218. 0x06,0x18,0x98,0x3f,0x87,0x41,0xc5,0xef,
  32219. 0x68,0xd3,0xa1,0x01,0xe8,0xa3,0xb8,0xca,
  32220. 0xc6,0x0c,0x90,0x5c,0x15,0xfc,0x91,0x08,
  32221. 0x40,0xb9,0x4c,0x00,0xa0,0xb9,0xd0
  32222. };
  32223. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  32224. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  32225. sizeof(msg2),
  32226. sizeof(msg3),
  32227. 0 /*sizeof(msg1)*/,
  32228. 0 /*sizeof(msg1)*/,
  32229. sizeof(msg4)
  32230. };
  32231. #ifndef NO_ASN
  32232. static const byte privateEd25519[] = {
  32233. 0x30,0x2e,0x02,0x01,0x00,0x30,0x05,0x06,
  32234. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32235. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32236. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32237. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32238. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60
  32239. };
  32240. static const byte badPrivateEd25519[] = {
  32241. 0x30,0x52,0x02,0x01,0x00,0x30,0x05,0x06,
  32242. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32243. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32244. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32245. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32246. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32247. 0xa1,0x22,0x04,0x21,0xd7,0x5a,0x98,0x01, /* octet len 0x20 -> 0x21 */
  32248. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32249. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32250. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32251. 0xf7,0x07,0x51,0x1a,
  32252. 0x00 /* add additional bytes to make the pubkey bigger */
  32253. };
  32254. static const byte publicEd25519[] = {
  32255. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32256. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32257. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32258. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32259. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32260. 0xf7,0x07,0x51,0x1a
  32261. };
  32262. /* size has been altered to catch if sanity check is done */
  32263. static const byte badPublicEd25519[] = {
  32264. 0x30,0x2a,0x30,0x05,0x06,0x03,0x2b,0x65,
  32265. 0x70,0x03,0x21,0x00,0xd7,0x5a,0x98,0x01,
  32266. 0x82,0xb1,0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,
  32267. 0xc9,0x64,0x07,0x3a,0x0e,0xe1,0x72,0xf3,
  32268. 0xda,0xa6,0x23,0x25,0xaf,0x02,0x1a,0x68,
  32269. 0xf7,0x07,0x51,0x1a,
  32270. 0x00 /* add an additional byte to make the pubkey appear bigger */
  32271. };
  32272. static const byte privPubEd25519[] = {
  32273. 0x30,0x50,0x02,0x01,0x00,0x30,0x05,0x06,
  32274. 0x03,0x2b,0x65,0x70,0x04,0x22,0x04,0x20,
  32275. 0x9d,0x61,0xb1,0x9d,0xef,0xfd,0x5a,0x60,
  32276. 0xba,0x84,0x4a,0xf4,0x92,0xec,0x2c,0xc4,
  32277. 0x44,0x49,0xc5,0x69,0x7b,0x32,0x69,0x19,
  32278. 0x70,0x3b,0xac,0x03,0x1c,0xae,0x7f,0x60,
  32279. 0x81,0x20,0xd7,0x5a,0x98,0x01,0x82,0xb1,
  32280. 0x0a,0xb7,0xd5,0x4b,0xfe,0xd3,0xc9,0x64,
  32281. 0x07,0x3a,0x0e,0xe1,0x72,0xf3,0xda,0xa6,
  32282. 0x23,0x25,0xaf,0x02,0x1a,0x68,0xf7,0x07,
  32283. 0x51,0x1a
  32284. };
  32285. word32 idx;
  32286. #endif /* NO_ASN */
  32287. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32288. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32289. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32290. ed25519_key* key3 = NULL;
  32291. #else
  32292. ed25519_key key3[1];
  32293. #endif
  32294. #endif
  32295. WOLFSSL_ENTER("ed25519_test");
  32296. /* create ed25519 keys */
  32297. #ifndef HAVE_FIPS
  32298. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32299. #else
  32300. ret = wc_InitRng(&rng);
  32301. #endif
  32302. if (ret != 0)
  32303. return WC_TEST_RET_ENC_EC(ret);
  32304. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32305. key = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32306. if (ret != 0)
  32307. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32308. key2 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32309. if (ret != 0)
  32310. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32311. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32312. key3 = wc_ed25519_new(HEAP_HINT, devId, &ret);
  32313. if (ret != 0)
  32314. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32315. #endif
  32316. #else
  32317. wc_ed25519_init_ex(key, HEAP_HINT, devId);
  32318. wc_ed25519_init_ex(key2, HEAP_HINT, devId);
  32319. #if !defined(NO_ASN) && defined(HAVE_ED25519_SIGN)
  32320. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32321. #endif
  32322. #endif
  32323. #ifdef HAVE_ED25519_MAKE_KEY
  32324. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key);
  32325. wc_ed25519_make_key(&rng, ED25519_KEY_SIZE, key2);
  32326. #endif
  32327. /* helper functions for signature and key size */
  32328. keySz = (word32)wc_ed25519_size(key);
  32329. sigSz = (word32)wc_ed25519_sig_size(key);
  32330. #if defined(HAVE_ED25519_SIGN) && defined(HAVE_ED25519_KEY_EXPORT) &&\
  32331. defined(HAVE_ED25519_KEY_IMPORT)
  32332. for (i = 0; i < 6; i++) {
  32333. outlen = sizeof(out);
  32334. XMEMSET(out, 0, sizeof(out));
  32335. if (wc_ed25519_import_private_key(sKeys[i], ED25519_KEY_SIZE, pKeys[i],
  32336. pKeySz[i], key) != 0)
  32337. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32338. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key) != 0)
  32339. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32340. if (XMEMCMP(out, sigs[i], 64))
  32341. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32342. #if defined(HAVE_ED25519_VERIFY)
  32343. /* test verify on good msg */
  32344. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32345. key) != 0 || verify != 1)
  32346. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32347. #ifdef WOLFSSL_ED25519_STREAMING_VERIFY
  32348. /* test verify on good msg using streaming interface directly */
  32349. if (wc_ed25519_verify_msg_init(out, outlen,
  32350. key, (byte)Ed25519, NULL, 0) != 0)
  32351. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32352. for (j = 0; j < msgSz[i]; j += i) {
  32353. if (wc_ed25519_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  32354. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32355. }
  32356. if (wc_ed25519_verify_msg_final(out, outlen, &verify,
  32357. key) != 0 || verify != 1)
  32358. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32359. #endif /* WOLFSSL_ED25519_STREAMING_VERIFY */
  32360. /* test verify on bad msg */
  32361. out[outlen-1] = out[outlen-1] + 1;
  32362. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32363. key) == 0 || verify == 1)
  32364. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32365. #endif /* HAVE_ED25519_VERIFY */
  32366. /* test api for import/exporting keys */
  32367. exportPSz = sizeof(exportPKey);
  32368. exportSSz = sizeof(exportSKey);
  32369. if (wc_ed25519_export_public(key, exportPKey, &exportPSz) != 0)
  32370. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32371. if (wc_ed25519_import_public_ex(exportPKey, exportPSz, key2, 1) != 0)
  32372. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32373. if (wc_ed25519_export_private_only(key, exportSKey, &exportSSz) != 0)
  32374. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32375. if (wc_ed25519_import_private_key(exportSKey, exportSSz,
  32376. exportPKey, exportPSz, key2) != 0)
  32377. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32378. /* clear "out" buffer and test sign with imported keys */
  32379. outlen = sizeof(out);
  32380. XMEMSET(out, 0, sizeof(out));
  32381. if (wc_ed25519_sign_msg(msgs[i], msgSz[i], out, &outlen, key2) != 0)
  32382. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32383. #if defined(HAVE_ED25519_VERIFY)
  32384. if (wc_ed25519_verify_msg(out, outlen, msgs[i], msgSz[i], &verify,
  32385. key2) != 0 || verify != 1)
  32386. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32387. if (XMEMCMP(out, sigs[i], 64))
  32388. ERROR_OUT(WC_TEST_RET_ENC_I(i), cleanup);
  32389. #endif /* HAVE_ED25519_VERIFY */
  32390. }
  32391. {
  32392. /* Run tests for some rare code paths */
  32393. /* sig is exactly equal to the order */
  32394. static const byte rareEd1[] = {
  32395. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32396. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32397. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32398. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32399. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32400. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32401. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32402. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32403. };
  32404. /* sig is larger than the order before we get to the low part */
  32405. static const byte rareEd2[] = {
  32406. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32407. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32408. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32409. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32410. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32411. 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32412. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32413. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10
  32414. };
  32415. /* sig is larger than the order in the low part */
  32416. static const byte rareEd3[] = {
  32417. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32418. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32419. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32420. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32421. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32422. 0xd6, 0x9c, 0xf9, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32423. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32424. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32425. };
  32426. /* sig is smaller than the order */
  32427. static const byte rareEd4[] = {
  32428. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32429. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32430. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32431. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32432. 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58,
  32433. 0xd6, 0x9c, 0xf1, 0xa2, 0xde, 0xf9, 0xde, 0x14,
  32434. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  32435. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
  32436. };
  32437. ret = wc_ed25519_import_private_key(sKeys[0], ED25519_KEY_SIZE,
  32438. pKeys[0], pKeySz[0], key);
  32439. if (ret != 0)
  32440. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32441. ret = wc_ed25519_verify_msg(rareEd1, sizeof(rareEd1), msgs[0], msgSz[0],
  32442. &verify, key);
  32443. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32444. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32445. ret = wc_ed25519_verify_msg(rareEd2, sizeof(rareEd2), 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(rareEd3, sizeof(rareEd3), 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(rareEd4, sizeof(rareEd4), msgs[0], msgSz[0],
  32454. &verify, key);
  32455. if (ret != WC_NO_ERR_TRACE(SIG_VERIFY_E))
  32456. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32457. }
  32458. ret = ed25519ctx_test();
  32459. if (ret != 0)
  32460. goto cleanup;
  32461. ret = ed25519ph_test();
  32462. if (ret != 0)
  32463. goto cleanup;
  32464. #ifndef NO_ASN
  32465. /* Try ASN.1 encoded private-only key and public key. */
  32466. idx = 0;
  32467. ret = wc_Ed25519PrivateKeyDecode(privateEd25519, &idx, key3,
  32468. sizeof(privateEd25519));
  32469. if (ret != 0)
  32470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32471. idx = 0;
  32472. if (wc_Ed25519PrivateKeyDecode(badPrivateEd25519, &idx, key3,
  32473. sizeof(badPrivateEd25519)) == 0)
  32474. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32475. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32476. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32477. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32478. /* try with a buffer size that is too large */
  32479. idx = 0;
  32480. if (wc_Ed25519PublicKeyDecode(badPublicEd25519, &idx, key3,
  32481. sizeof(badPublicEd25519)) == 0)
  32482. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32483. idx = 0;
  32484. ret = wc_Ed25519PublicKeyDecode(publicEd25519, &idx, key3,
  32485. sizeof(publicEd25519));
  32486. if (ret != 0)
  32487. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32488. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32489. if (ret != 0)
  32490. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32491. if (XMEMCMP(out, sigs[0], 64))
  32492. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32493. #if defined(HAVE_ED25519_VERIFY)
  32494. /* test verify on good msg */
  32495. ret = wc_ed25519_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3);
  32496. if (ret != 0 || verify != 1)
  32497. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32498. #endif /* HAVE_ED25519_VERIFY */
  32499. wc_ed25519_free(key3);
  32500. wc_ed25519_init_ex(key3, HEAP_HINT, devId);
  32501. idx = 0;
  32502. ret = wc_Ed25519PrivateKeyDecode(privPubEd25519, &idx, key3,
  32503. sizeof(privPubEd25519));
  32504. if (ret != 0)
  32505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32506. ret = wc_ed25519_sign_msg(msgs[0], msgSz[0], out, &outlen, key3);
  32507. if (ret != 0)
  32508. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), cleanup);
  32509. if (XMEMCMP(out, sigs[0], 64))
  32510. ERROR_OUT(WC_TEST_RET_ENC_NC, cleanup);
  32511. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32512. wc_ed25519_delete(key3, &key3);
  32513. #else
  32514. wc_ed25519_free(key3);
  32515. #endif
  32516. #endif /* NO_ASN */
  32517. #endif /* HAVE_ED25519_SIGN && HAVE_ED25519_KEY_EXPORT && HAVE_ED25519_KEY_IMPORT */
  32518. ret = ed25519_test_check_key();
  32519. if (ret < 0)
  32520. goto cleanup;
  32521. #ifdef WOLFSSL_TEST_CERT
  32522. ret = ed25519_test_cert();
  32523. if (ret < 0)
  32524. goto cleanup;
  32525. #if defined(WOLFSSL_CERT_GEN) && defined(HAVE_ED25519_MAKE_KEY)
  32526. ret = ed25519_test_make_cert();
  32527. if (ret < 0)
  32528. goto cleanup;
  32529. #endif /* WOLFSSL_CERT_GEN */
  32530. #endif /* WOLFSSL_TEST_CERT */
  32531. cleanup:
  32532. /* clean up keys when done */
  32533. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  32534. wc_ed25519_delete(key, &key);
  32535. wc_ed25519_delete(key2, &key2);
  32536. #else
  32537. wc_ed25519_free(key);
  32538. wc_ed25519_free(key2);
  32539. #endif
  32540. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  32541. wc_FreeRng(&rng);
  32542. #endif
  32543. /* hush warnings of unused keySz and sigSz */
  32544. (void)keySz;
  32545. (void)sigSz;
  32546. return ret;
  32547. }
  32548. #endif /* HAVE_ED25519 */
  32549. #ifdef HAVE_CURVE448
  32550. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32551. defined(HAVE_CURVE448_KEY_IMPORT)
  32552. /* Test the wc_curve448_check_public API.
  32553. *
  32554. * returns 0 on success and -ve on failure.
  32555. */
  32556. static wc_test_ret_t curve448_check_public_test(void)
  32557. {
  32558. /* Little-endian values that will fail */
  32559. byte fail_le[][CURVE448_KEY_SIZE] = {
  32560. {
  32561. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32562. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32563. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32564. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  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. },
  32569. {
  32570. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32571. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32572. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32573. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32574. 0x00,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. },
  32578. };
  32579. /* Big-endian values that will fail */
  32580. byte fail_be[][CURVE448_KEY_SIZE] = {
  32581. {
  32582. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32583. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32584. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32585. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  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. },
  32590. {
  32591. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32592. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32593. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32594. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  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,0x01
  32598. },
  32599. };
  32600. /* Good or valid public value */
  32601. byte good[CURVE448_KEY_SIZE] = {
  32602. 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32603. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32604. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32605. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32606. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32607. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32608. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
  32609. };
  32610. int i;
  32611. wc_test_ret_t ret;
  32612. /* Parameter checks */
  32613. /* NULL pointer */
  32614. ret = wc_curve448_check_public(NULL, 0, EC448_LITTLE_ENDIAN);
  32615. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32616. return WC_TEST_RET_ENC_EC(ret);
  32617. ret = wc_curve448_check_public(NULL, 0, EC448_BIG_ENDIAN);
  32618. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  32619. return WC_TEST_RET_ENC_EC(ret);
  32620. /* Length of 0 treated differently to other invalid lengths for TLS */
  32621. ret = wc_curve448_check_public(good, 0, EC448_LITTLE_ENDIAN);
  32622. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32623. return WC_TEST_RET_ENC_EC(ret);
  32624. ret = wc_curve448_check_public(good, 0, EC448_BIG_ENDIAN);
  32625. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  32626. return WC_TEST_RET_ENC_EC(ret);
  32627. /* Length not CURVE448_KEY_SIZE */
  32628. for (i = 1; i < CURVE448_KEY_SIZE + 2; i++) {
  32629. if (i == CURVE448_KEY_SIZE)
  32630. continue;
  32631. if (wc_curve448_check_public(good, (word32)i, EC448_LITTLE_ENDIAN) !=
  32632. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32633. return WC_TEST_RET_ENC_I(i);
  32634. }
  32635. if (wc_curve448_check_public(good, (word32)i, EC448_BIG_ENDIAN) !=
  32636. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  32637. return WC_TEST_RET_ENC_I(i);
  32638. }
  32639. }
  32640. /* Little-endian fail cases */
  32641. for (i = 0; i < (int)(sizeof(fail_le) / sizeof(*fail_le)); i++) {
  32642. if (wc_curve448_check_public(fail_le[i], CURVE448_KEY_SIZE,
  32643. EC448_LITTLE_ENDIAN) == 0) {
  32644. return WC_TEST_RET_ENC_I(i);
  32645. }
  32646. }
  32647. /* Big-endian fail cases */
  32648. for (i = 0; i < (int)(sizeof(fail_be) / sizeof(*fail_be)); i++) {
  32649. if (wc_curve448_check_public(fail_be[i], CURVE448_KEY_SIZE,
  32650. EC448_BIG_ENDIAN) == 0) {
  32651. return WC_TEST_RET_ENC_I(i);
  32652. }
  32653. }
  32654. /* Check a valid public value works! */
  32655. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE,
  32656. EC448_LITTLE_ENDIAN);
  32657. if (ret != 0)
  32658. return WC_TEST_RET_ENC_EC(ret);
  32659. ret = wc_curve448_check_public(good, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN);
  32660. if (ret != 0)
  32661. return WC_TEST_RET_ENC_EC(ret);
  32662. return 0;
  32663. }
  32664. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32665. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t curve448_test(void)
  32666. {
  32667. WC_RNG rng;
  32668. wc_test_ret_t ret;
  32669. #ifdef HAVE_CURVE448_SHARED_SECRET
  32670. byte sharedA[CURVE448_KEY_SIZE];
  32671. byte sharedB[CURVE448_KEY_SIZE];
  32672. word32 y;
  32673. #endif
  32674. #ifdef HAVE_CURVE448_KEY_EXPORT
  32675. byte exportBuf[CURVE448_KEY_SIZE];
  32676. #endif
  32677. word32 x = 0;
  32678. curve448_key userA, userB, pubKey;
  32679. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32680. defined(HAVE_CURVE448_KEY_IMPORT)
  32681. /* test vectors from
  32682. https://www.rfc-editor.org/rfc/rfc7748.html
  32683. */
  32684. /* secret key for party a */
  32685. byte sa[] = {
  32686. 0x6b, 0x72, 0x98, 0xa5, 0xc0, 0xd8, 0xc2, 0x9a,
  32687. 0x1d, 0xab, 0x27, 0xf1, 0xa6, 0x82, 0x63, 0x00,
  32688. 0x91, 0x73, 0x89, 0x44, 0x97, 0x41, 0xa9, 0x74,
  32689. 0xf5, 0xba, 0xc9, 0xd9, 0x8d, 0xc2, 0x98, 0xd4,
  32690. 0x65, 0x55, 0xbc, 0xe8, 0xba, 0xe8, 0x9e, 0xee,
  32691. 0xd4, 0x00, 0x58, 0x4b, 0xb0, 0x46, 0xcf, 0x75,
  32692. 0x57, 0x9f, 0x51, 0xd1, 0x25, 0x49, 0x8f, 0x9a,
  32693. };
  32694. /* public key for party a */
  32695. byte pa[] = {
  32696. 0xa0, 0x1f, 0xc4, 0x32, 0xe5, 0x80, 0x7f, 0x17,
  32697. 0x53, 0x0d, 0x12, 0x88, 0xda, 0x12, 0x5b, 0x0c,
  32698. 0xd4, 0x53, 0xd9, 0x41, 0x72, 0x64, 0x36, 0xc8,
  32699. 0xbb, 0xd9, 0xc5, 0x22, 0x2c, 0x3d, 0xa7, 0xfa,
  32700. 0x63, 0x9c, 0xe0, 0x3d, 0xb8, 0xd2, 0x3b, 0x27,
  32701. 0x4a, 0x07, 0x21, 0xa1, 0xae, 0xd5, 0x22, 0x7d,
  32702. 0xe6, 0xe3, 0xb7, 0x31, 0xcc, 0xf7, 0x08, 0x9b,
  32703. };
  32704. /* secret key for party b */
  32705. byte sb[] = {
  32706. 0x2d, 0x99, 0x73, 0x51, 0xb6, 0x10, 0x6f, 0x36,
  32707. 0xb0, 0xd1, 0x09, 0x1b, 0x92, 0x9c, 0x4c, 0x37,
  32708. 0x21, 0x3e, 0x0d, 0x2b, 0x97, 0xe8, 0x5e, 0xbb,
  32709. 0x20, 0xc1, 0x27, 0x69, 0x1d, 0x0d, 0xad, 0x8f,
  32710. 0x1d, 0x81, 0x75, 0xb0, 0x72, 0x37, 0x45, 0xe6,
  32711. 0x39, 0xa3, 0xcb, 0x70, 0x44, 0x29, 0x0b, 0x99,
  32712. 0xe0, 0xe2, 0xa0, 0xc2, 0x7a, 0x6a, 0x30, 0x1c,
  32713. };
  32714. /* public key for party b */
  32715. byte pb[] = {
  32716. 0x09, 0x36, 0xf3, 0x7b, 0xc6, 0xc1, 0xbd, 0x07,
  32717. 0xae, 0x3d, 0xec, 0x7a, 0xb5, 0xdc, 0x06, 0xa7,
  32718. 0x3c, 0xa1, 0x32, 0x42, 0xfb, 0x34, 0x3e, 0xfc,
  32719. 0x72, 0xb9, 0xd8, 0x27, 0x30, 0xb4, 0x45, 0xf3,
  32720. 0xd4, 0xb0, 0xbd, 0x07, 0x71, 0x62, 0xa4, 0x6d,
  32721. 0xcf, 0xec, 0x6f, 0x9b, 0x59, 0x0b, 0xfc, 0xbc,
  32722. 0xf5, 0x20, 0xcd, 0xb0, 0x29, 0xa8, 0xb7, 0x3e,
  32723. };
  32724. /* expected shared key */
  32725. byte ss[] = {
  32726. 0x9d, 0x87, 0x4a, 0x51, 0x37, 0x50, 0x9a, 0x44,
  32727. 0x9a, 0xd5, 0x85, 0x30, 0x40, 0x24, 0x1c, 0x52,
  32728. 0x36, 0x39, 0x54, 0x35, 0xc3, 0x64, 0x24, 0xfd,
  32729. 0x56, 0x0b, 0x0c, 0xb6, 0x2b, 0x28, 0x1d, 0x28,
  32730. 0x52, 0x75, 0xa7, 0x40, 0xce, 0x32, 0xa2, 0x2d,
  32731. 0xd1, 0x74, 0x0f, 0x4a, 0xa9, 0x16, 0x1c, 0xec,
  32732. 0x95, 0xcc, 0xc6, 0x1a, 0x18, 0xf4, 0xff, 0x07,
  32733. };
  32734. #endif /* HAVE_CURVE448_SHARED_SECRET */
  32735. (void)x;
  32736. WOLFSSL_ENTER("curve448_test");
  32737. #ifndef HAVE_FIPS
  32738. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32739. #else
  32740. ret = wc_InitRng(&rng);
  32741. #endif
  32742. if (ret != 0)
  32743. return WC_TEST_RET_ENC_EC(ret);
  32744. wc_curve448_init(&userA);
  32745. wc_curve448_init(&userB);
  32746. wc_curve448_init(&pubKey);
  32747. /* make curve448 keys */
  32748. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userA);
  32749. if (ret != 0)
  32750. return WC_TEST_RET_ENC_EC(ret);
  32751. ret = wc_curve448_make_key(&rng, CURVE448_KEY_SIZE, &userB);
  32752. if (ret != 0)
  32753. return WC_TEST_RET_ENC_EC(ret);
  32754. #ifdef HAVE_CURVE448_SHARED_SECRET
  32755. /* find shared secret key */
  32756. x = sizeof(sharedA);
  32757. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32758. if (ret != 0)
  32759. return WC_TEST_RET_ENC_EC(ret);
  32760. y = sizeof(sharedB);
  32761. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32762. if (ret != 0)
  32763. return WC_TEST_RET_ENC_EC(ret);
  32764. /* compare shared secret keys to test they are the same */
  32765. if (y != x)
  32766. return WC_TEST_RET_ENC_NC;
  32767. if (XMEMCMP(sharedA, sharedB, x))
  32768. return WC_TEST_RET_ENC_NC;
  32769. #endif
  32770. #ifdef HAVE_CURVE448_KEY_EXPORT
  32771. /* export a public key and import it for another user */
  32772. x = sizeof(exportBuf);
  32773. ret = wc_curve448_export_public(&userA, exportBuf, &x);
  32774. if (ret != 0)
  32775. return WC_TEST_RET_ENC_EC(ret);
  32776. #ifdef HAVE_CURVE448_KEY_IMPORT
  32777. ret = wc_curve448_import_public(exportBuf, x, &pubKey);
  32778. if (ret != 0)
  32779. return WC_TEST_RET_ENC_EC(ret);
  32780. #endif
  32781. #endif
  32782. #if defined(HAVE_CURVE448_SHARED_SECRET) && \
  32783. defined(HAVE_CURVE448_KEY_IMPORT)
  32784. /* test shared key after importing a public key */
  32785. XMEMSET(sharedB, 0, sizeof(sharedB));
  32786. y = sizeof(sharedB);
  32787. ret = wc_curve448_shared_secret(&userB, &pubKey, sharedB, &y);
  32788. if (ret != 0)
  32789. return WC_TEST_RET_ENC_EC(ret);
  32790. if (XMEMCMP(sharedA, sharedB, y))
  32791. return WC_TEST_RET_ENC_NC;
  32792. /* import RFC test vectors and compare shared key */
  32793. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32794. if (ret != 0)
  32795. return WC_TEST_RET_ENC_EC(ret);
  32796. ret = wc_curve448_import_private_raw(sb, sizeof(sb), pb, sizeof(pb), &userB);
  32797. if (ret != 0)
  32798. return WC_TEST_RET_ENC_EC(ret);
  32799. /* test against known test vector */
  32800. XMEMSET(sharedB, 0, sizeof(sharedB));
  32801. y = sizeof(sharedB);
  32802. ret = wc_curve448_shared_secret(&userA, &userB, sharedB, &y);
  32803. if (ret != 0)
  32804. return WC_TEST_RET_ENC_EC(ret);
  32805. if (XMEMCMP(ss, sharedB, y))
  32806. return WC_TEST_RET_ENC_NC;
  32807. /* test swapping roles of keys and generating same shared key */
  32808. XMEMSET(sharedB, 0, sizeof(sharedB));
  32809. y = sizeof(sharedB);
  32810. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32811. if (ret != 0)
  32812. return WC_TEST_RET_ENC_EC(ret);
  32813. if (XMEMCMP(ss, sharedB, y))
  32814. return WC_TEST_RET_ENC_NC;
  32815. /* test with 1 generated key and 1 from known test vector */
  32816. ret = wc_curve448_import_private_raw(sa, sizeof(sa), pa, sizeof(pa), &userA);
  32817. if (ret != 0)
  32818. return WC_TEST_RET_ENC_EC(ret);
  32819. ret = wc_curve448_make_key(&rng, 56, &userB);
  32820. if (ret != 0)
  32821. return WC_TEST_RET_ENC_EC(ret);
  32822. x = sizeof(sharedA);
  32823. ret = wc_curve448_shared_secret(&userA, &userB, sharedA, &x);
  32824. if (ret != 0)
  32825. return WC_TEST_RET_ENC_EC(ret);
  32826. y = sizeof(sharedB);
  32827. ret = wc_curve448_shared_secret(&userB, &userA, sharedB, &y);
  32828. if (ret != 0)
  32829. return WC_TEST_RET_ENC_EC(ret);
  32830. /* compare shared secret keys to test they are the same */
  32831. if (y != x)
  32832. return WC_TEST_RET_ENC_NC;
  32833. if (XMEMCMP(sharedA, sharedB, x))
  32834. return WC_TEST_RET_ENC_NC;
  32835. ret = curve448_check_public_test();
  32836. if (ret != 0)
  32837. return ret;
  32838. #endif /* HAVE_CURVE448_SHARED_SECRET && HAVE_CURVE448_KEY_IMPORT */
  32839. /* clean up keys when done */
  32840. wc_curve448_free(&pubKey);
  32841. wc_curve448_free(&userB);
  32842. wc_curve448_free(&userA);
  32843. wc_FreeRng(&rng);
  32844. return 0;
  32845. }
  32846. #endif /* HAVE_CURVE448 */
  32847. #ifdef HAVE_ED448
  32848. #ifdef WOLFSSL_TEST_CERT
  32849. static wc_test_ret_t ed448_test_cert(void)
  32850. {
  32851. DecodedCert cert[2];
  32852. DecodedCert* serverCert = NULL;
  32853. DecodedCert* caCert = NULL;
  32854. #ifdef HAVE_ED448_VERIFY
  32855. ed448_key key;
  32856. ed448_key* pubKey = NULL;
  32857. int verify;
  32858. #endif /* HAVE_ED448_VERIFY */
  32859. wc_test_ret_t ret;
  32860. byte* tmp;
  32861. size_t bytes;
  32862. XFILE file;
  32863. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32864. if (tmp == NULL) {
  32865. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32866. }
  32867. #ifdef USE_CERT_BUFFERS_256
  32868. XMEMCPY(tmp, ca_ed448_cert, sizeof_ca_ed448_cert);
  32869. bytes = sizeof_ca_ed448_cert;
  32870. #elif !defined(NO_FILESYSTEM)
  32871. file = XFOPEN(caEd448Cert, "rb");
  32872. if (file == NULL) {
  32873. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32874. }
  32875. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32876. XFCLOSE(file);
  32877. if (bytes == 0)
  32878. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32879. #else
  32880. /* No certificate to use. */
  32881. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32882. #endif
  32883. InitDecodedCert(&cert[0], tmp, (word32)bytes, 0);
  32884. caCert = &cert[0];
  32885. ret = ParseCert(caCert, CERT_TYPE, NO_VERIFY, NULL);
  32886. if (ret != 0)
  32887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32888. #ifdef USE_CERT_BUFFERS_256
  32889. XMEMCPY(tmp, server_ed448_cert, sizeof_server_ed448_cert);
  32890. bytes = sizeof_server_ed448_cert;
  32891. #elif !defined(NO_FILESYSTEM)
  32892. file = XFOPEN(serverEd448Cert, "rb");
  32893. if (file == NULL) {
  32894. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32895. }
  32896. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  32897. XFCLOSE(file);
  32898. if (bytes == 0)
  32899. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32900. #else
  32901. /* No certificate to use. */
  32902. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  32903. #endif
  32904. InitDecodedCert(&cert[1], tmp, (word32)bytes, 0);
  32905. serverCert = &cert[1];
  32906. ret = ParseCert(serverCert, CERT_TYPE, NO_VERIFY, NULL);
  32907. if (ret != 0)
  32908. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32909. #ifdef HAVE_ED448_VERIFY
  32910. ret = wc_ed448_init(&key);
  32911. if (ret < 0)
  32912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32913. pubKey = &key;
  32914. ret = wc_ed448_import_public(caCert->publicKey, caCert->pubKeySize, pubKey);
  32915. if (ret < 0)
  32916. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32917. ret = wc_ed448_verify_msg(serverCert->signature, serverCert->sigLength,
  32918. serverCert->source + serverCert->certBegin,
  32919. serverCert->sigIndex - serverCert->certBegin,
  32920. &verify, pubKey, NULL, 0);
  32921. if (ret < 0 || verify != 1) {
  32922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32923. }
  32924. #endif /* HAVE_ED448_VERIFY */
  32925. done:
  32926. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32927. #ifdef HAVE_ED448_VERIFY
  32928. wc_ed448_free(pubKey);
  32929. #endif /* HAVE_ED448_VERIFY */
  32930. if (caCert != NULL)
  32931. FreeDecodedCert(caCert);
  32932. if (serverCert != NULL)
  32933. FreeDecodedCert(serverCert);
  32934. return ret;
  32935. }
  32936. static wc_test_ret_t ed448_test_make_cert(void)
  32937. {
  32938. WC_RNG rng;
  32939. Cert cert;
  32940. DecodedCert decode;
  32941. ed448_key key;
  32942. ed448_key* privKey = NULL;
  32943. wc_test_ret_t ret = 0;
  32944. byte* tmp = NULL;
  32945. wc_InitCert_ex(&cert, HEAP_HINT, devId);
  32946. #ifndef HAVE_FIPS
  32947. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  32948. #else
  32949. ret = wc_InitRng(&rng);
  32950. #endif
  32951. if (ret != 0)
  32952. return WC_TEST_RET_ENC_EC(ret);
  32953. wc_ed448_init(&key);
  32954. privKey = &key;
  32955. wc_ed448_make_key(&rng, ED448_KEY_SIZE, privKey);
  32956. cert.daysValid = 365 * 2;
  32957. cert.selfSigned = 1;
  32958. XMEMCPY(&cert.issuer, &certDefaultName, sizeof(CertName));
  32959. XMEMCPY(&cert.subject, &certDefaultName, sizeof(CertName));
  32960. cert.isCA = 0;
  32961. #ifdef WOLFSSL_CERT_EXT
  32962. ret = wc_SetKeyUsage(&cert, certKeyUsage);
  32963. if (ret < 0)
  32964. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32965. ret = wc_SetSubjectKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32966. if (ret < 0)
  32967. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32968. ret = wc_SetAuthKeyIdFromPublicKey_ex(&cert, ED448_TYPE, privKey);
  32969. if (ret < 0)
  32970. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32971. #endif
  32972. tmp = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32973. if (tmp == NULL) {
  32974. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  32975. }
  32976. cert.sigType = CTC_ED448;
  32977. ret = wc_MakeCert_ex(&cert, tmp, FOURK_BUF, ED448_TYPE, privKey, &rng);
  32978. if (ret < 0)
  32979. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32980. ret = wc_SignCert_ex(cert.bodySz, cert.sigType, tmp, FOURK_BUF, ED448_TYPE,
  32981. privKey, &rng);
  32982. if (ret < 0)
  32983. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32984. InitDecodedCert(&decode, tmp, (word32)ret, HEAP_HINT);
  32985. ret = ParseCert(&decode, CERT_TYPE, NO_VERIFY, 0);
  32986. FreeDecodedCert(&decode);
  32987. if (ret != 0)
  32988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  32989. done:
  32990. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  32991. wc_ed448_free(privKey);
  32992. wc_FreeRng(&rng);
  32993. return ret;
  32994. }
  32995. #endif /* WOLFSSL_TEST_CERT */
  32996. #if defined(HAVE_ED448_KEY_IMPORT)
  32997. static wc_test_ret_t ed448_test_check_key(void)
  32998. {
  32999. /* Fails to find x-ordinate from this y-ordinate. */
  33000. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y[] = {
  33001. 0x40,
  33002. 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33003. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33004. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33005. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33006. 0x00,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
  33010. };
  33011. /* Y-ordinate value larger than prime. */
  33012. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_max[] = {
  33013. 0x40,
  33014. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33015. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33016. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33017. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  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
  33022. };
  33023. /* Y-ordinate value equal to prime. */
  33024. WOLFSSL_SMALL_STACK_STATIC const byte key_bad_y_is_p[] = {
  33025. 0x40,
  33026. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33027. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33028. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33029. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  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
  33034. };
  33035. /* Y-ordinate value equal to prime - 1. */
  33036. WOLFSSL_SMALL_STACK_STATIC const byte key_y_is_p_minus_1[] = {
  33037. 0x40,
  33038. 0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33039. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33040. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33041. 0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,
  33042. 0xff,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
  33046. };
  33047. ed448_key key;
  33048. int ret;
  33049. int res = 0;
  33050. /* Initialize key for use. */
  33051. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33052. if (ret != 0) {
  33053. return WC_TEST_RET_ENC_NC;
  33054. }
  33055. /* Load bad public key only and perform checks. */
  33056. ret = wc_ed448_import_public(key_bad_y, ED448_PUB_KEY_SIZE + 1, &key);
  33057. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33058. res = WC_TEST_RET_ENC_NC;
  33059. }
  33060. if (ret == 0) {
  33061. /* Load bad public key only and perform checks. */
  33062. ret = wc_ed448_import_public(key_bad_y_max, ED448_PUB_KEY_SIZE + 1,
  33063. &key);
  33064. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33065. res = WC_TEST_RET_ENC_NC;
  33066. }
  33067. }
  33068. if (res == 0) {
  33069. /* Load bad public key only and perform checks. */
  33070. ret = wc_ed448_import_public(key_bad_y_is_p, ED448_PUB_KEY_SIZE + 1,
  33071. &key);
  33072. if (ret != WC_NO_ERR_TRACE(PUBLIC_KEY_E)) {
  33073. res = WC_TEST_RET_ENC_NC;
  33074. }
  33075. }
  33076. if (res == 0) {
  33077. /* Load good public key only and perform checks. */
  33078. ret = wc_ed448_import_public(key_y_is_p_minus_1, ED448_PUB_KEY_SIZE + 1,
  33079. &key);
  33080. if (ret != 0) {
  33081. res = WC_TEST_RET_ENC_NC;
  33082. }
  33083. }
  33084. /* Dispose of key. */
  33085. wc_ed448_free(&key);
  33086. return res;
  33087. }
  33088. #endif
  33089. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33090. defined(HAVE_ED448_KEY_IMPORT)
  33091. static wc_test_ret_t ed448_ctx_test(void)
  33092. {
  33093. wc_test_ret_t ret;
  33094. byte out[ED448_SIG_SIZE];
  33095. word32 outlen;
  33096. #ifdef HAVE_ED448_VERIFY
  33097. int verify;
  33098. #endif /* HAVE_ED448_VERIFY */
  33099. ed448_key key;
  33100. WOLFSSL_SMALL_STACK_STATIC const byte sKeyCtx[] = {
  33101. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33102. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33103. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33104. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33105. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33106. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33107. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33108. 0x4e
  33109. };
  33110. WOLFSSL_SMALL_STACK_STATIC const byte pKeyCtx[] = {
  33111. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33112. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33113. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33114. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33115. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33116. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33117. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33118. 0x80
  33119. };
  33120. WOLFSSL_SMALL_STACK_STATIC const byte sigCtx[] = {
  33121. 0xd4, 0xf8, 0xf6, 0x13, 0x17, 0x70, 0xdd, 0x46,
  33122. 0xf4, 0x08, 0x67, 0xd6, 0xfd, 0x5d, 0x50, 0x55,
  33123. 0xde, 0x43, 0x54, 0x1f, 0x8c, 0x5e, 0x35, 0xab,
  33124. 0xbc, 0xd0, 0x01, 0xb3, 0x2a, 0x89, 0xf7, 0xd2,
  33125. 0x15, 0x1f, 0x76, 0x47, 0xf1, 0x1d, 0x8c, 0xa2,
  33126. 0xae, 0x27, 0x9f, 0xb8, 0x42, 0xd6, 0x07, 0x21,
  33127. 0x7f, 0xce, 0x6e, 0x04, 0x2f, 0x68, 0x15, 0xea,
  33128. 0x00, 0x0c, 0x85, 0x74, 0x1d, 0xe5, 0xc8, 0xda,
  33129. 0x11, 0x44, 0xa6, 0xa1, 0xab, 0xa7, 0xf9, 0x6d,
  33130. 0xe4, 0x25, 0x05, 0xd7, 0xa7, 0x29, 0x85, 0x24,
  33131. 0xfd, 0xa5, 0x38, 0xfc, 0xcb, 0xbb, 0x75, 0x4f,
  33132. 0x57, 0x8c, 0x1c, 0xad, 0x10, 0xd5, 0x4d, 0x0d,
  33133. 0x54, 0x28, 0x40, 0x7e, 0x85, 0xdc, 0xbc, 0x98,
  33134. 0xa4, 0x91, 0x55, 0xc1, 0x37, 0x64, 0xe6, 0x6c,
  33135. 0x3c, 0x00
  33136. };
  33137. WOLFSSL_SMALL_STACK_STATIC const byte msgCtx[] = {
  33138. 0x03
  33139. };
  33140. WOLFSSL_SMALL_STACK_STATIC const byte contextCtx[] = {
  33141. 0x66,0x6f,0x6f
  33142. };
  33143. outlen = sizeof(out);
  33144. XMEMSET(out, 0, sizeof(out));
  33145. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33146. if (ret != 0)
  33147. return WC_TEST_RET_ENC_EC(ret);
  33148. ret = wc_ed448_import_private_key(sKeyCtx, ED448_KEY_SIZE, pKeyCtx,
  33149. sizeof(pKeyCtx), &key);
  33150. if (ret != 0)
  33151. return WC_TEST_RET_ENC_EC(ret);
  33152. ret = wc_ed448_sign_msg(msgCtx, sizeof(msgCtx), out, &outlen, &key,
  33153. contextCtx, sizeof(contextCtx));
  33154. if (ret != 0)
  33155. return WC_TEST_RET_ENC_EC(ret);
  33156. if (XMEMCMP(out, sigCtx, sizeof(sigCtx)))
  33157. return WC_TEST_RET_ENC_NC;
  33158. #if defined(HAVE_ED448_VERIFY)
  33159. /* test verify on good msg */
  33160. ret = wc_ed448_verify_msg(out, outlen, msgCtx, sizeof(msgCtx), &verify, &key,
  33161. contextCtx, sizeof(contextCtx));
  33162. if (ret != 0 || verify != 1)
  33163. return WC_TEST_RET_ENC_EC(ret);
  33164. #endif
  33165. wc_ed448_free(&key);
  33166. return 0;
  33167. }
  33168. static wc_test_ret_t ed448ph_test(void)
  33169. {
  33170. wc_test_ret_t ret;
  33171. byte out[ED448_SIG_SIZE];
  33172. word32 outlen;
  33173. #ifdef HAVE_ED448_VERIFY
  33174. int verify;
  33175. #endif /* HAVE_ED448_VERIFY */
  33176. ed448_key key;
  33177. WOLFSSL_SMALL_STACK_STATIC const byte sKeyPh[] = {
  33178. 0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
  33179. 0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
  33180. 0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
  33181. 0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42,
  33182. 0xef, 0x78, 0x22, 0xe0, 0xd5, 0x10, 0x41, 0x27,
  33183. 0xdc, 0x05, 0xd6, 0xdb, 0xef, 0xde, 0x69, 0xe3,
  33184. 0xab, 0x2c, 0xec, 0x7c, 0x86, 0x7c, 0x6e, 0x2c,
  33185. 0x49
  33186. };
  33187. WOLFSSL_SMALL_STACK_STATIC const byte pKeyPh[] = {
  33188. 0x25, 0x9b, 0x71, 0xc1, 0x9f, 0x83, 0xef, 0x77,
  33189. 0xa7, 0xab, 0xd2, 0x65, 0x24, 0xcb, 0xdb, 0x31,
  33190. 0x61, 0xb5, 0x90, 0xa4, 0x8f, 0x7d, 0x17, 0xde,
  33191. 0x3e, 0xe0, 0xba, 0x9c, 0x52, 0xbe, 0xb7, 0x43,
  33192. 0xc0, 0x94, 0x28, 0xa1, 0x31, 0xd6, 0xb1, 0xb5,
  33193. 0x73, 0x03, 0xd9, 0x0d, 0x81, 0x32, 0xc2, 0x76,
  33194. 0xd5, 0xed, 0x3d, 0x5d, 0x01, 0xc0, 0xf5, 0x38,
  33195. 0x80
  33196. };
  33197. WOLFSSL_SMALL_STACK_STATIC const byte sigPh1[] = {
  33198. 0x82, 0x2f, 0x69, 0x01, 0xf7, 0x48, 0x0f, 0x3d,
  33199. 0x5f, 0x56, 0x2c, 0x59, 0x29, 0x94, 0xd9, 0x69,
  33200. 0x36, 0x02, 0x87, 0x56, 0x14, 0x48, 0x32, 0x56,
  33201. 0x50, 0x56, 0x00, 0xbb, 0xc2, 0x81, 0xae, 0x38,
  33202. 0x1f, 0x54, 0xd6, 0xbc, 0xe2, 0xea, 0x91, 0x15,
  33203. 0x74, 0x93, 0x2f, 0x52, 0xa4, 0xe6, 0xca, 0xdd,
  33204. 0x78, 0x76, 0x93, 0x75, 0xec, 0x3f, 0xfd, 0x1b,
  33205. 0x80, 0x1a, 0x0d, 0x9b, 0x3f, 0x40, 0x30, 0xcd,
  33206. 0x43, 0x39, 0x64, 0xb6, 0x45, 0x7e, 0xa3, 0x94,
  33207. 0x76, 0x51, 0x12, 0x14, 0xf9, 0x74, 0x69, 0xb5,
  33208. 0x7d, 0xd3, 0x2d, 0xbc, 0x56, 0x0a, 0x9a, 0x94,
  33209. 0xd0, 0x0b, 0xff, 0x07, 0x62, 0x04, 0x64, 0xa3,
  33210. 0xad, 0x20, 0x3d, 0xf7, 0xdc, 0x7c, 0xe3, 0x60,
  33211. 0xc3, 0xcd, 0x36, 0x96, 0xd9, 0xd9, 0xfa, 0xb9,
  33212. 0x0f, 0x00
  33213. };
  33214. WOLFSSL_SMALL_STACK_STATIC const byte sigPh2[] = {
  33215. 0xc3, 0x22, 0x99, 0xd4, 0x6e, 0xc8, 0xff, 0x02,
  33216. 0xb5, 0x45, 0x40, 0x98, 0x28, 0x14, 0xdc, 0xe9,
  33217. 0xa0, 0x58, 0x12, 0xf8, 0x19, 0x62, 0xb6, 0x49,
  33218. 0xd5, 0x28, 0x09, 0x59, 0x16, 0xa2, 0xaa, 0x48,
  33219. 0x10, 0x65, 0xb1, 0x58, 0x04, 0x23, 0xef, 0x92,
  33220. 0x7e, 0xcf, 0x0a, 0xf5, 0x88, 0x8f, 0x90, 0xda,
  33221. 0x0f, 0x6a, 0x9a, 0x85, 0xad, 0x5d, 0xc3, 0xf2,
  33222. 0x80, 0xd9, 0x12, 0x24, 0xba, 0x99, 0x11, 0xa3,
  33223. 0x65, 0x3d, 0x00, 0xe4, 0x84, 0xe2, 0xce, 0x23,
  33224. 0x25, 0x21, 0x48, 0x1c, 0x86, 0x58, 0xdf, 0x30,
  33225. 0x4b, 0xb7, 0x74, 0x5a, 0x73, 0x51, 0x4c, 0xdb,
  33226. 0x9b, 0xf3, 0xe1, 0x57, 0x84, 0xab, 0x71, 0x28,
  33227. 0x4f, 0x8d, 0x07, 0x04, 0xa6, 0x08, 0xc5, 0x4a,
  33228. 0x6b, 0x62, 0xd9, 0x7b, 0xeb, 0x51, 0x1d, 0x13,
  33229. 0x21, 0x00
  33230. };
  33231. WOLFSSL_SMALL_STACK_STATIC const byte msgPh[] = {
  33232. 0x61,0x62,0x63
  33233. };
  33234. /* SHA-512 hash of msgPh */
  33235. WOLFSSL_SMALL_STACK_STATIC const byte hashPh[] = {
  33236. 0x48, 0x33, 0x66, 0x60, 0x13, 0x60, 0xa8, 0x77,
  33237. 0x1c, 0x68, 0x63, 0x08, 0x0c, 0xc4, 0x11, 0x4d,
  33238. 0x8d, 0xb4, 0x45, 0x30, 0xf8, 0xf1, 0xe1, 0xee,
  33239. 0x4f, 0x94, 0xea, 0x37, 0xe7, 0x8b, 0x57, 0x39,
  33240. 0xd5, 0xa1, 0x5b, 0xef, 0x18, 0x6a, 0x53, 0x86,
  33241. 0xc7, 0x57, 0x44, 0xc0, 0x52, 0x7e, 0x1f, 0xaa,
  33242. 0x9f, 0x87, 0x26, 0xe4, 0x62, 0xa1, 0x2a, 0x4f,
  33243. 0xeb, 0x06, 0xbd, 0x88, 0x01, 0xe7, 0x51, 0xe4
  33244. };
  33245. WOLFSSL_SMALL_STACK_STATIC const byte contextPh2[] = {
  33246. 0x66,0x6f,0x6f
  33247. };
  33248. outlen = sizeof(out);
  33249. XMEMSET(out, 0, sizeof(out));
  33250. ret = wc_ed448_init_ex(&key, HEAP_HINT, devId);
  33251. if (ret != 0)
  33252. return WC_TEST_RET_ENC_EC(ret);
  33253. ret = wc_ed448_import_private_key(sKeyPh, ED448_KEY_SIZE, pKeyPh,
  33254. sizeof(pKeyPh), &key);
  33255. if (ret != 0)
  33256. return WC_TEST_RET_ENC_EC(ret);
  33257. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key, NULL,
  33258. 0);
  33259. if (ret != 0)
  33260. return WC_TEST_RET_ENC_EC(ret);
  33261. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33262. return WC_TEST_RET_ENC_NC;
  33263. #if defined(HAVE_ED448_VERIFY)
  33264. /* test verify on good msg */
  33265. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33266. NULL, 0);
  33267. if (ret != 0 || verify != 1) {
  33268. return WC_TEST_RET_ENC_EC(ret);
  33269. }
  33270. #endif
  33271. ret = wc_ed448ph_sign_msg(msgPh, sizeof(msgPh), out, &outlen, &key,
  33272. contextPh2, sizeof(contextPh2));
  33273. if (ret != 0)
  33274. return WC_TEST_RET_ENC_EC(ret);
  33275. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33276. return WC_TEST_RET_ENC_NC;
  33277. #if defined(HAVE_ED448_VERIFY)
  33278. /* test verify on good msg */
  33279. ret = wc_ed448ph_verify_msg(out, outlen, msgPh, sizeof(msgPh), &verify, &key,
  33280. contextPh2, sizeof(contextPh2));
  33281. if (ret != 0 || verify != 1) {
  33282. return WC_TEST_RET_ENC_EC(ret);
  33283. }
  33284. #endif
  33285. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key, NULL,
  33286. 0);
  33287. if (ret != 0)
  33288. return WC_TEST_RET_ENC_EC(ret);
  33289. if (XMEMCMP(out, sigPh1, sizeof(sigPh1)))
  33290. return WC_TEST_RET_ENC_NC;
  33291. #if defined(HAVE_ED448_VERIFY)
  33292. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33293. &key, NULL, 0);
  33294. if (ret != 0 || verify != 1) {
  33295. return WC_TEST_RET_ENC_EC(ret);
  33296. }
  33297. #endif
  33298. ret = wc_ed448ph_sign_hash(hashPh, sizeof(hashPh), out, &outlen, &key,
  33299. contextPh2, sizeof(contextPh2));
  33300. if (ret != 0)
  33301. return WC_TEST_RET_ENC_EC(ret);
  33302. if (XMEMCMP(out, sigPh2, sizeof(sigPh2)))
  33303. return WC_TEST_RET_ENC_NC;
  33304. #if defined(HAVE_ED448_VERIFY)
  33305. ret = wc_ed448ph_verify_hash(out, outlen, hashPh, sizeof(hashPh), &verify,
  33306. &key, contextPh2, sizeof(contextPh2));
  33307. if (ret != 0 || verify != 1) {
  33308. return WC_TEST_RET_ENC_EC(ret);
  33309. }
  33310. #endif
  33311. wc_ed448_free(&key);
  33312. return 0;
  33313. }
  33314. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33315. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t ed448_test(void)
  33316. {
  33317. wc_test_ret_t ret;
  33318. WC_RNG rng;
  33319. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33320. defined(HAVE_ED448_KEY_IMPORT)
  33321. byte out[ED448_SIG_SIZE];
  33322. int i;
  33323. word32 outlen;
  33324. #ifdef HAVE_ED448_VERIFY
  33325. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33326. int j;
  33327. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33328. int verify;
  33329. #endif /* HAVE_ED448_VERIFY */
  33330. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33331. word32 keySz, sigSz;
  33332. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33333. ed448_key *key = NULL;
  33334. ed448_key *key2 = NULL;
  33335. #else
  33336. ed448_key key[1];
  33337. ed448_key key2[1];
  33338. #endif
  33339. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) && \
  33340. defined(HAVE_ED448_KEY_IMPORT)
  33341. /* test vectors from
  33342. https://tools.ietf.org/html/rfc8032
  33343. */
  33344. WOLFSSL_SMALL_STACK_STATIC const byte sKey1[] = {
  33345. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33346. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33347. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33348. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33349. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33350. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33351. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33352. 0x5b
  33353. };
  33354. WOLFSSL_SMALL_STACK_STATIC const byte sKey2[] = {
  33355. 0xc4, 0xea, 0xb0, 0x5d, 0x35, 0x70, 0x07, 0xc6,
  33356. 0x32, 0xf3, 0xdb, 0xb4, 0x84, 0x89, 0x92, 0x4d,
  33357. 0x55, 0x2b, 0x08, 0xfe, 0x0c, 0x35, 0x3a, 0x0d,
  33358. 0x4a, 0x1f, 0x00, 0xac, 0xda, 0x2c, 0x46, 0x3a,
  33359. 0xfb, 0xea, 0x67, 0xc5, 0xe8, 0xd2, 0x87, 0x7c,
  33360. 0x5e, 0x3b, 0xc3, 0x97, 0xa6, 0x59, 0x94, 0x9e,
  33361. 0xf8, 0x02, 0x1e, 0x95, 0x4e, 0x0a, 0x12, 0x27,
  33362. 0x4e
  33363. };
  33364. WOLFSSL_SMALL_STACK_STATIC const byte sKey3[] = {
  33365. 0x25, 0x8c, 0xdd, 0x4a, 0xda, 0x32, 0xed, 0x9c,
  33366. 0x9f, 0xf5, 0x4e, 0x63, 0x75, 0x6a, 0xe5, 0x82,
  33367. 0xfb, 0x8f, 0xab, 0x2a, 0xc7, 0x21, 0xf2, 0xc8,
  33368. 0xe6, 0x76, 0xa7, 0x27, 0x68, 0x51, 0x3d, 0x93,
  33369. 0x9f, 0x63, 0xdd, 0xdb, 0x55, 0x60, 0x91, 0x33,
  33370. 0xf2, 0x9a, 0xdf, 0x86, 0xec, 0x99, 0x29, 0xdc,
  33371. 0xcb, 0x52, 0xc1, 0xc5, 0xfd, 0x2f, 0xf7, 0xe2,
  33372. 0x1b
  33373. };
  33374. /* uncompressed test */
  33375. WOLFSSL_SMALL_STACK_STATIC const byte sKey4[] = {
  33376. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33377. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33378. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33379. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33380. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33381. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33382. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33383. 0x5b
  33384. };
  33385. /* compressed prefix test */
  33386. WOLFSSL_SMALL_STACK_STATIC const byte sKey5[] = {
  33387. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33388. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33389. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33390. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33391. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33392. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33393. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33394. 0x5b
  33395. };
  33396. WOLFSSL_SMALL_STACK_STATIC const byte sKey6[] = {
  33397. 0x87, 0x2d, 0x09, 0x37, 0x80, 0xf5, 0xd3, 0x73,
  33398. 0x0d, 0xf7, 0xc2, 0x12, 0x66, 0x4b, 0x37, 0xb8,
  33399. 0xa0, 0xf2, 0x4f, 0x56, 0x81, 0x0d, 0xaa, 0x83,
  33400. 0x82, 0xcd, 0x4f, 0xa3, 0xf7, 0x76, 0x34, 0xec,
  33401. 0x44, 0xdc, 0x54, 0xf1, 0xc2, 0xed, 0x9b, 0xea,
  33402. 0x86, 0xfa, 0xfb, 0x76, 0x32, 0xd8, 0xbe, 0x19,
  33403. 0x9e, 0xa1, 0x65, 0xf5, 0xad, 0x55, 0xdd, 0x9c,
  33404. 0xe8
  33405. };
  33406. WOLFSSL_SMALL_STACK_STATIC const byte* sKeys[] = {sKey1, sKey2, sKey3, sKey4, sKey5, sKey6};
  33407. WOLFSSL_SMALL_STACK_STATIC const byte pKey1[] = {
  33408. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33409. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33410. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33411. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33412. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33413. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33414. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33415. 0x80
  33416. };
  33417. WOLFSSL_SMALL_STACK_STATIC const byte pKey2[] = {
  33418. 0x43, 0xba, 0x28, 0xf4, 0x30, 0xcd, 0xff, 0x45,
  33419. 0x6a, 0xe5, 0x31, 0x54, 0x5f, 0x7e, 0xcd, 0x0a,
  33420. 0xc8, 0x34, 0xa5, 0x5d, 0x93, 0x58, 0xc0, 0x37,
  33421. 0x2b, 0xfa, 0x0c, 0x6c, 0x67, 0x98, 0xc0, 0x86,
  33422. 0x6a, 0xea, 0x01, 0xeb, 0x00, 0x74, 0x28, 0x02,
  33423. 0xb8, 0x43, 0x8e, 0xa4, 0xcb, 0x82, 0x16, 0x9c,
  33424. 0x23, 0x51, 0x60, 0x62, 0x7b, 0x4c, 0x3a, 0x94,
  33425. 0x80
  33426. };
  33427. WOLFSSL_SMALL_STACK_STATIC const byte pKey3[] = {
  33428. 0x3b, 0xa1, 0x6d, 0xa0, 0xc6, 0xf2, 0xcc, 0x1f,
  33429. 0x30, 0x18, 0x77, 0x40, 0x75, 0x6f, 0x5e, 0x79,
  33430. 0x8d, 0x6b, 0xc5, 0xfc, 0x01, 0x5d, 0x7c, 0x63,
  33431. 0xcc, 0x95, 0x10, 0xee, 0x3f, 0xd4, 0x4a, 0xdc,
  33432. 0x24, 0xd8, 0xe9, 0x68, 0xb6, 0xe4, 0x6e, 0x6f,
  33433. 0x94, 0xd1, 0x9b, 0x94, 0x53, 0x61, 0x72, 0x6b,
  33434. 0xd7, 0x5e, 0x14, 0x9e, 0xf0, 0x98, 0x17, 0xf5,
  33435. 0x80
  33436. };
  33437. /* uncompressed test */
  33438. WOLFSSL_SMALL_STACK_STATIC const byte pKey4[] = {
  33439. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33440. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33441. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33442. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33443. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33444. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33445. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33446. 0x80
  33447. };
  33448. /* compressed prefix */
  33449. WOLFSSL_SMALL_STACK_STATIC const byte pKey5[] = {
  33450. 0x5f, 0xd7, 0x44, 0x9b, 0x59, 0xb4, 0x61, 0xfd,
  33451. 0x2c, 0xe7, 0x87, 0xec, 0x61, 0x6a, 0xd4, 0x6a,
  33452. 0x1d, 0xa1, 0x34, 0x24, 0x85, 0xa7, 0x0e, 0x1f,
  33453. 0x8a, 0x0e, 0xa7, 0x5d, 0x80, 0xe9, 0x67, 0x78,
  33454. 0xed, 0xf1, 0x24, 0x76, 0x9b, 0x46, 0xc7, 0x06,
  33455. 0x1b, 0xd6, 0x78, 0x3d, 0xf1, 0xe5, 0x0f, 0x6c,
  33456. 0xd1, 0xfa, 0x1a, 0xbe, 0xaf, 0xe8, 0x25, 0x61,
  33457. 0x80
  33458. };
  33459. WOLFSSL_SMALL_STACK_STATIC const byte pKey6[] = {
  33460. 0xa8, 0x1b, 0x2e, 0x8a, 0x70, 0xa5, 0xac, 0x94,
  33461. 0xff, 0xdb, 0xcc, 0x9b, 0xad, 0xfc, 0x3f, 0xeb,
  33462. 0x08, 0x01, 0xf2, 0x58, 0x57, 0x8b, 0xb1, 0x14,
  33463. 0xad, 0x44, 0xec, 0xe1, 0xec, 0x0e, 0x79, 0x9d,
  33464. 0xa0, 0x8e, 0xff, 0xb8, 0x1c, 0x5d, 0x68, 0x5c,
  33465. 0x0c, 0x56, 0xf6, 0x4e, 0xec, 0xae, 0xf8, 0xcd,
  33466. 0xf1, 0x1c, 0xc3, 0x87, 0x37, 0x83, 0x8c, 0xf4,
  33467. 0x00
  33468. };
  33469. WOLFSSL_SMALL_STACK_STATIC const byte* pKeys[] = {pKey1, pKey2, pKey3, pKey4, pKey5, pKey6};
  33470. WOLFSSL_SMALL_STACK_STATIC const byte pKeySz[] = {sizeof(pKey1), sizeof(pKey2), sizeof(pKey3),
  33471. sizeof(pKey4), sizeof(pKey5), sizeof(pKey6)};
  33472. WOLFSSL_SMALL_STACK_STATIC const byte sig1[] = {
  33473. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33474. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33475. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33476. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33477. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33478. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33479. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33480. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33481. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33482. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33483. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33484. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33485. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33486. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33487. 0x26, 0x00
  33488. };
  33489. WOLFSSL_SMALL_STACK_STATIC const byte sig2[] = {
  33490. 0x26, 0xb8, 0xf9, 0x17, 0x27, 0xbd, 0x62, 0x89,
  33491. 0x7a, 0xf1, 0x5e, 0x41, 0xeb, 0x43, 0xc3, 0x77,
  33492. 0xef, 0xb9, 0xc6, 0x10, 0xd4, 0x8f, 0x23, 0x35,
  33493. 0xcb, 0x0b, 0xd0, 0x08, 0x78, 0x10, 0xf4, 0x35,
  33494. 0x25, 0x41, 0xb1, 0x43, 0xc4, 0xb9, 0x81, 0xb7,
  33495. 0xe1, 0x8f, 0x62, 0xde, 0x8c, 0xcd, 0xf6, 0x33,
  33496. 0xfc, 0x1b, 0xf0, 0x37, 0xab, 0x7c, 0xd7, 0x79,
  33497. 0x80, 0x5e, 0x0d, 0xbc, 0xc0, 0xaa, 0xe1, 0xcb,
  33498. 0xce, 0xe1, 0xaf, 0xb2, 0xe0, 0x27, 0xdf, 0x36,
  33499. 0xbc, 0x04, 0xdc, 0xec, 0xbf, 0x15, 0x43, 0x36,
  33500. 0xc1, 0x9f, 0x0a, 0xf7, 0xe0, 0xa6, 0x47, 0x29,
  33501. 0x05, 0xe7, 0x99, 0xf1, 0x95, 0x3d, 0x2a, 0x0f,
  33502. 0xf3, 0x34, 0x8a, 0xb2, 0x1a, 0xa4, 0xad, 0xaf,
  33503. 0xd1, 0xd2, 0x34, 0x44, 0x1c, 0xf8, 0x07, 0xc0,
  33504. 0x3a, 0x00
  33505. };
  33506. WOLFSSL_SMALL_STACK_STATIC const byte sig3[] = {
  33507. 0x7e, 0xee, 0xab, 0x7c, 0x4e, 0x50, 0xfb, 0x79,
  33508. 0x9b, 0x41, 0x8e, 0xe5, 0xe3, 0x19, 0x7f, 0xf6,
  33509. 0xbf, 0x15, 0xd4, 0x3a, 0x14, 0xc3, 0x43, 0x89,
  33510. 0xb5, 0x9d, 0xd1, 0xa7, 0xb1, 0xb8, 0x5b, 0x4a,
  33511. 0xe9, 0x04, 0x38, 0xac, 0xa6, 0x34, 0xbe, 0xa4,
  33512. 0x5e, 0x3a, 0x26, 0x95, 0xf1, 0x27, 0x0f, 0x07,
  33513. 0xfd, 0xcd, 0xf7, 0xc6, 0x2b, 0x8e, 0xfe, 0xaf,
  33514. 0x00, 0xb4, 0x5c, 0x2c, 0x96, 0xba, 0x45, 0x7e,
  33515. 0xb1, 0xa8, 0xbf, 0x07, 0x5a, 0x3d, 0xb2, 0x8e,
  33516. 0x5c, 0x24, 0xf6, 0xb9, 0x23, 0xed, 0x4a, 0xd7,
  33517. 0x47, 0xc3, 0xc9, 0xe0, 0x3c, 0x70, 0x79, 0xef,
  33518. 0xb8, 0x7c, 0xb1, 0x10, 0xd3, 0xa9, 0x98, 0x61,
  33519. 0xe7, 0x20, 0x03, 0xcb, 0xae, 0x6d, 0x6b, 0x8b,
  33520. 0x82, 0x7e, 0x4e, 0x6c, 0x14, 0x30, 0x64, 0xff,
  33521. 0x3c, 0x00
  33522. };
  33523. /* uncompressed test */
  33524. WOLFSSL_SMALL_STACK_STATIC const byte sig4[] = {
  33525. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33526. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33527. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33528. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33529. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33530. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33531. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33532. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33533. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33534. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33535. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33536. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33537. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33538. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33539. 0x26, 0x00
  33540. };
  33541. /* compressed prefix */
  33542. WOLFSSL_SMALL_STACK_STATIC const byte sig5[] = {
  33543. 0x53, 0x3a, 0x37, 0xf6, 0xbb, 0xe4, 0x57, 0x25,
  33544. 0x1f, 0x02, 0x3c, 0x0d, 0x88, 0xf9, 0x76, 0xae,
  33545. 0x2d, 0xfb, 0x50, 0x4a, 0x84, 0x3e, 0x34, 0xd2,
  33546. 0x07, 0x4f, 0xd8, 0x23, 0xd4, 0x1a, 0x59, 0x1f,
  33547. 0x2b, 0x23, 0x3f, 0x03, 0x4f, 0x62, 0x82, 0x81,
  33548. 0xf2, 0xfd, 0x7a, 0x22, 0xdd, 0xd4, 0x7d, 0x78,
  33549. 0x28, 0xc5, 0x9b, 0xd0, 0xa2, 0x1b, 0xfd, 0x39,
  33550. 0x80, 0xff, 0x0d, 0x20, 0x28, 0xd4, 0xb1, 0x8a,
  33551. 0x9d, 0xf6, 0x3e, 0x00, 0x6c, 0x5d, 0x1c, 0x2d,
  33552. 0x34, 0x5b, 0x92, 0x5d, 0x8d, 0xc0, 0x0b, 0x41,
  33553. 0x04, 0x85, 0x2d, 0xb9, 0x9a, 0xc5, 0xc7, 0xcd,
  33554. 0xda, 0x85, 0x30, 0xa1, 0x13, 0xa0, 0xf4, 0xdb,
  33555. 0xb6, 0x11, 0x49, 0xf0, 0x5a, 0x73, 0x63, 0x26,
  33556. 0x8c, 0x71, 0xd9, 0x58, 0x08, 0xff, 0x2e, 0x65,
  33557. 0x26, 0x00
  33558. };
  33559. WOLFSSL_SMALL_STACK_STATIC const byte sig6[] = {
  33560. 0xe3, 0x01, 0x34, 0x5a, 0x41, 0xa3, 0x9a, 0x4d,
  33561. 0x72, 0xff, 0xf8, 0xdf, 0x69, 0xc9, 0x80, 0x75,
  33562. 0xa0, 0xcc, 0x08, 0x2b, 0x80, 0x2f, 0xc9, 0xb2,
  33563. 0xb6, 0xbc, 0x50, 0x3f, 0x92, 0x6b, 0x65, 0xbd,
  33564. 0xdf, 0x7f, 0x4c, 0x8f, 0x1c, 0xb4, 0x9f, 0x63,
  33565. 0x96, 0xaf, 0xc8, 0xa7, 0x0a, 0xbe, 0x6d, 0x8a,
  33566. 0xef, 0x0d, 0xb4, 0x78, 0xd4, 0xc6, 0xb2, 0x97,
  33567. 0x00, 0x76, 0xc6, 0xa0, 0x48, 0x4f, 0xe7, 0x6d,
  33568. 0x76, 0xb3, 0xa9, 0x76, 0x25, 0xd7, 0x9f, 0x1c,
  33569. 0xe2, 0x40, 0xe7, 0xc5, 0x76, 0x75, 0x0d, 0x29,
  33570. 0x55, 0x28, 0x28, 0x6f, 0x71, 0x9b, 0x41, 0x3d,
  33571. 0xe9, 0xad, 0xa3, 0xe8, 0xeb, 0x78, 0xed, 0x57,
  33572. 0x36, 0x03, 0xce, 0x30, 0xd8, 0xbb, 0x76, 0x17,
  33573. 0x85, 0xdc, 0x30, 0xdb, 0xc3, 0x20, 0x86, 0x9e,
  33574. 0x1a, 0x00
  33575. };
  33576. WOLFSSL_SMALL_STACK_STATIC const byte* sigs[] = {sig1, sig2, sig3, sig4, sig5, sig6};
  33577. #define SIGSZ sizeof(sig1)
  33578. PEDANTIC_EXTENSION WOLFSSL_SMALL_STACK_STATIC const byte msg1[] = { 0 };
  33579. WOLFSSL_SMALL_STACK_STATIC const byte msg2[] = { 0x03 };
  33580. WOLFSSL_SMALL_STACK_STATIC const byte msg3[] = { 0x64, 0xa6, 0x5f, 0x3c, 0xde, 0xdc, 0xdd,
  33581. 0x66, 0x81, 0x1e, 0x29, 0x15 };
  33582. /* test of a 1023 byte long message */
  33583. WOLFSSL_SMALL_STACK_STATIC const byte msg4[] = {
  33584. 0x6d, 0xdf, 0x80, 0x2e, 0x1a, 0xae, 0x49, 0x86,
  33585. 0x93, 0x5f, 0x7f, 0x98, 0x1b, 0xa3, 0xf0, 0x35,
  33586. 0x1d, 0x62, 0x73, 0xc0, 0xa0, 0xc2, 0x2c, 0x9c,
  33587. 0x0e, 0x83, 0x39, 0x16, 0x8e, 0x67, 0x54, 0x12,
  33588. 0xa3, 0xde, 0xbf, 0xaf, 0x43, 0x5e, 0xd6, 0x51,
  33589. 0x55, 0x80, 0x07, 0xdb, 0x43, 0x84, 0xb6, 0x50,
  33590. 0xfc, 0xc0, 0x7e, 0x3b, 0x58, 0x6a, 0x27, 0xa4,
  33591. 0xf7, 0xa0, 0x0a, 0xc8, 0xa6, 0xfe, 0xc2, 0xcd,
  33592. 0x86, 0xae, 0x4b, 0xf1, 0x57, 0x0c, 0x41, 0xe6,
  33593. 0xa4, 0x0c, 0x93, 0x1d, 0xb2, 0x7b, 0x2f, 0xaa,
  33594. 0x15, 0xa8, 0xce, 0xdd, 0x52, 0xcf, 0xf7, 0x36,
  33595. 0x2c, 0x4e, 0x6e, 0x23, 0xda, 0xec, 0x0f, 0xbc,
  33596. 0x3a, 0x79, 0xb6, 0x80, 0x6e, 0x31, 0x6e, 0xfc,
  33597. 0xc7, 0xb6, 0x81, 0x19, 0xbf, 0x46, 0xbc, 0x76,
  33598. 0xa2, 0x60, 0x67, 0xa5, 0x3f, 0x29, 0x6d, 0xaf,
  33599. 0xdb, 0xdc, 0x11, 0xc7, 0x7f, 0x77, 0x77, 0xe9,
  33600. 0x72, 0x66, 0x0c, 0xf4, 0xb6, 0xa9, 0xb3, 0x69,
  33601. 0xa6, 0x66, 0x5f, 0x02, 0xe0, 0xcc, 0x9b, 0x6e,
  33602. 0xdf, 0xad, 0x13, 0x6b, 0x4f, 0xab, 0xe7, 0x23,
  33603. 0xd2, 0x81, 0x3d, 0xb3, 0x13, 0x6c, 0xfd, 0xe9,
  33604. 0xb6, 0xd0, 0x44, 0x32, 0x2f, 0xee, 0x29, 0x47,
  33605. 0x95, 0x2e, 0x03, 0x1b, 0x73, 0xab, 0x5c, 0x60,
  33606. 0x33, 0x49, 0xb3, 0x07, 0xbd, 0xc2, 0x7b, 0xc6,
  33607. 0xcb, 0x8b, 0x8b, 0xbd, 0x7b, 0xd3, 0x23, 0x21,
  33608. 0x9b, 0x80, 0x33, 0xa5, 0x81, 0xb5, 0x9e, 0xad,
  33609. 0xeb, 0xb0, 0x9b, 0x3c, 0x4f, 0x3d, 0x22, 0x77,
  33610. 0xd4, 0xf0, 0x34, 0x36, 0x24, 0xac, 0xc8, 0x17,
  33611. 0x80, 0x47, 0x28, 0xb2, 0x5a, 0xb7, 0x97, 0x17,
  33612. 0x2b, 0x4c, 0x5c, 0x21, 0xa2, 0x2f, 0x9c, 0x78,
  33613. 0x39, 0xd6, 0x43, 0x00, 0x23, 0x2e, 0xb6, 0x6e,
  33614. 0x53, 0xf3, 0x1c, 0x72, 0x3f, 0xa3, 0x7f, 0xe3,
  33615. 0x87, 0xc7, 0xd3, 0xe5, 0x0b, 0xdf, 0x98, 0x13,
  33616. 0xa3, 0x0e, 0x5b, 0xb1, 0x2c, 0xf4, 0xcd, 0x93,
  33617. 0x0c, 0x40, 0xcf, 0xb4, 0xe1, 0xfc, 0x62, 0x25,
  33618. 0x92, 0xa4, 0x95, 0x88, 0x79, 0x44, 0x94, 0xd5,
  33619. 0x6d, 0x24, 0xea, 0x4b, 0x40, 0xc8, 0x9f, 0xc0,
  33620. 0x59, 0x6c, 0xc9, 0xeb, 0xb9, 0x61, 0xc8, 0xcb,
  33621. 0x10, 0xad, 0xde, 0x97, 0x6a, 0x5d, 0x60, 0x2b,
  33622. 0x1c, 0x3f, 0x85, 0xb9, 0xb9, 0xa0, 0x01, 0xed,
  33623. 0x3c, 0x6a, 0x4d, 0x3b, 0x14, 0x37, 0xf5, 0x20,
  33624. 0x96, 0xcd, 0x19, 0x56, 0xd0, 0x42, 0xa5, 0x97,
  33625. 0xd5, 0x61, 0xa5, 0x96, 0xec, 0xd3, 0xd1, 0x73,
  33626. 0x5a, 0x8d, 0x57, 0x0e, 0xa0, 0xec, 0x27, 0x22,
  33627. 0x5a, 0x2c, 0x4a, 0xaf, 0xf2, 0x63, 0x06, 0xd1,
  33628. 0x52, 0x6c, 0x1a, 0xf3, 0xca, 0x6d, 0x9c, 0xf5,
  33629. 0xa2, 0xc9, 0x8f, 0x47, 0xe1, 0xc4, 0x6d, 0xb9,
  33630. 0xa3, 0x32, 0x34, 0xcf, 0xd4, 0xd8, 0x1f, 0x2c,
  33631. 0x98, 0x53, 0x8a, 0x09, 0xeb, 0xe7, 0x69, 0x98,
  33632. 0xd0, 0xd8, 0xfd, 0x25, 0x99, 0x7c, 0x7d, 0x25,
  33633. 0x5c, 0x6d, 0x66, 0xec, 0xe6, 0xfa, 0x56, 0xf1,
  33634. 0x11, 0x44, 0x95, 0x0f, 0x02, 0x77, 0x95, 0xe6,
  33635. 0x53, 0x00, 0x8f, 0x4b, 0xd7, 0xca, 0x2d, 0xee,
  33636. 0x85, 0xd8, 0xe9, 0x0f, 0x3d, 0xc3, 0x15, 0x13,
  33637. 0x0c, 0xe2, 0xa0, 0x03, 0x75, 0xa3, 0x18, 0xc7,
  33638. 0xc3, 0xd9, 0x7b, 0xe2, 0xc8, 0xce, 0x5b, 0x6d,
  33639. 0xb4, 0x1a, 0x62, 0x54, 0xff, 0x26, 0x4f, 0xa6,
  33640. 0x15, 0x5b, 0xae, 0xe3, 0xb0, 0x77, 0x3c, 0x0f,
  33641. 0x49, 0x7c, 0x57, 0x3f, 0x19, 0xbb, 0x4f, 0x42,
  33642. 0x40, 0x28, 0x1f, 0x0b, 0x1f, 0x4f, 0x7b, 0xe8,
  33643. 0x57, 0xa4, 0xe5, 0x9d, 0x41, 0x6c, 0x06, 0xb4,
  33644. 0xc5, 0x0f, 0xa0, 0x9e, 0x18, 0x10, 0xdd, 0xc6,
  33645. 0xb1, 0x46, 0x7b, 0xae, 0xac, 0x5a, 0x36, 0x68,
  33646. 0xd1, 0x1b, 0x6e, 0xca, 0xa9, 0x01, 0x44, 0x00,
  33647. 0x16, 0xf3, 0x89, 0xf8, 0x0a, 0xcc, 0x4d, 0xb9,
  33648. 0x77, 0x02, 0x5e, 0x7f, 0x59, 0x24, 0x38, 0x8c,
  33649. 0x7e, 0x34, 0x0a, 0x73, 0x2e, 0x55, 0x44, 0x40,
  33650. 0xe7, 0x65, 0x70, 0xf8, 0xdd, 0x71, 0xb7, 0xd6,
  33651. 0x40, 0xb3, 0x45, 0x0d, 0x1f, 0xd5, 0xf0, 0x41,
  33652. 0x0a, 0x18, 0xf9, 0xa3, 0x49, 0x4f, 0x70, 0x7c,
  33653. 0x71, 0x7b, 0x79, 0xb4, 0xbf, 0x75, 0xc9, 0x84,
  33654. 0x00, 0xb0, 0x96, 0xb2, 0x16, 0x53, 0xb5, 0xd2,
  33655. 0x17, 0xcf, 0x35, 0x65, 0xc9, 0x59, 0x74, 0x56,
  33656. 0xf7, 0x07, 0x03, 0x49, 0x7a, 0x07, 0x87, 0x63,
  33657. 0x82, 0x9b, 0xc0, 0x1b, 0xb1, 0xcb, 0xc8, 0xfa,
  33658. 0x04, 0xea, 0xdc, 0x9a, 0x6e, 0x3f, 0x66, 0x99,
  33659. 0x58, 0x7a, 0x9e, 0x75, 0xc9, 0x4e, 0x5b, 0xab,
  33660. 0x00, 0x36, 0xe0, 0xb2, 0xe7, 0x11, 0x39, 0x2c,
  33661. 0xff, 0x00, 0x47, 0xd0, 0xd6, 0xb0, 0x5b, 0xd2,
  33662. 0xa5, 0x88, 0xbc, 0x10, 0x97, 0x18, 0x95, 0x42,
  33663. 0x59, 0xf1, 0xd8, 0x66, 0x78, 0xa5, 0x79, 0xa3,
  33664. 0x12, 0x0f, 0x19, 0xcf, 0xb2, 0x96, 0x3f, 0x17,
  33665. 0x7a, 0xeb, 0x70, 0xf2, 0xd4, 0x84, 0x48, 0x26,
  33666. 0x26, 0x2e, 0x51, 0xb8, 0x02, 0x71, 0x27, 0x20,
  33667. 0x68, 0xef, 0x5b, 0x38, 0x56, 0xfa, 0x85, 0x35,
  33668. 0xaa, 0x2a, 0x88, 0xb2, 0xd4, 0x1f, 0x2a, 0x0e,
  33669. 0x2f, 0xda, 0x76, 0x24, 0xc2, 0x85, 0x02, 0x72,
  33670. 0xac, 0x4a, 0x2f, 0x56, 0x1f, 0x8f, 0x2f, 0x7a,
  33671. 0x31, 0x8b, 0xfd, 0x5c, 0xaf, 0x96, 0x96, 0x14,
  33672. 0x9e, 0x4a, 0xc8, 0x24, 0xad, 0x34, 0x60, 0x53,
  33673. 0x8f, 0xdc, 0x25, 0x42, 0x1b, 0xee, 0xc2, 0xcc,
  33674. 0x68, 0x18, 0x16, 0x2d, 0x06, 0xbb, 0xed, 0x0c,
  33675. 0x40, 0xa3, 0x87, 0x19, 0x23, 0x49, 0xdb, 0x67,
  33676. 0xa1, 0x18, 0xba, 0xda, 0x6c, 0xd5, 0xab, 0x01,
  33677. 0x40, 0xee, 0x27, 0x32, 0x04, 0xf6, 0x28, 0xaa,
  33678. 0xd1, 0xc1, 0x35, 0xf7, 0x70, 0x27, 0x9a, 0x65,
  33679. 0x1e, 0x24, 0xd8, 0xc1, 0x4d, 0x75, 0xa6, 0x05,
  33680. 0x9d, 0x76, 0xb9, 0x6a, 0x6f, 0xd8, 0x57, 0xde,
  33681. 0xf5, 0xe0, 0xb3, 0x54, 0xb2, 0x7a, 0xb9, 0x37,
  33682. 0xa5, 0x81, 0x5d, 0x16, 0xb5, 0xfa, 0xe4, 0x07,
  33683. 0xff, 0x18, 0x22, 0x2c, 0x6d, 0x1e, 0xd2, 0x63,
  33684. 0xbe, 0x68, 0xc9, 0x5f, 0x32, 0xd9, 0x08, 0xbd,
  33685. 0x89, 0x5c, 0xd7, 0x62, 0x07, 0xae, 0x72, 0x64,
  33686. 0x87, 0x56, 0x7f, 0x9a, 0x67, 0xda, 0xd7, 0x9a,
  33687. 0xbe, 0xc3, 0x16, 0xf6, 0x83, 0xb1, 0x7f, 0x2d,
  33688. 0x02, 0xbf, 0x07, 0xe0, 0xac, 0x8b, 0x5b, 0xc6,
  33689. 0x16, 0x2c, 0xf9, 0x46, 0x97, 0xb3, 0xc2, 0x7c,
  33690. 0xd1, 0xfe, 0xa4, 0x9b, 0x27, 0xf2, 0x3b, 0xa2,
  33691. 0x90, 0x18, 0x71, 0x96, 0x25, 0x06, 0x52, 0x0c,
  33692. 0x39, 0x2d, 0xa8, 0xb6, 0xad, 0x0d, 0x99, 0xf7,
  33693. 0x01, 0x3f, 0xbc, 0x06, 0xc2, 0xc1, 0x7a, 0x56,
  33694. 0x95, 0x00, 0xc8, 0xa7, 0x69, 0x64, 0x81, 0xc1,
  33695. 0xcd, 0x33, 0xe9, 0xb1, 0x4e, 0x40, 0xb8, 0x2e,
  33696. 0x79, 0xa5, 0xf5, 0xdb, 0x82, 0x57, 0x1b, 0xa9,
  33697. 0x7b, 0xae, 0x3a, 0xd3, 0xe0, 0x47, 0x95, 0x15,
  33698. 0xbb, 0x0e, 0x2b, 0x0f, 0x3b, 0xfc, 0xd1, 0xfd,
  33699. 0x33, 0x03, 0x4e, 0xfc, 0x62, 0x45, 0xed, 0xdd,
  33700. 0x7e, 0xe2, 0x08, 0x6d, 0xda, 0xe2, 0x60, 0x0d,
  33701. 0x8c, 0xa7, 0x3e, 0x21, 0x4e, 0x8c, 0x2b, 0x0b,
  33702. 0xdb, 0x2b, 0x04, 0x7c, 0x6a, 0x46, 0x4a, 0x56,
  33703. 0x2e, 0xd7, 0x7b, 0x73, 0xd2, 0xd8, 0x41, 0xc4,
  33704. 0xb3, 0x49, 0x73, 0x55, 0x12, 0x57, 0x71, 0x3b,
  33705. 0x75, 0x36, 0x32, 0xef, 0xba, 0x34, 0x81, 0x69,
  33706. 0xab, 0xc9, 0x0a, 0x68, 0xf4, 0x26, 0x11, 0xa4,
  33707. 0x01, 0x26, 0xd7, 0xcb, 0x21, 0xb5, 0x86, 0x95,
  33708. 0x56, 0x81, 0x86, 0xf7, 0xe5, 0x69, 0xd2, 0xff,
  33709. 0x0f, 0x9e, 0x74, 0x5d, 0x04, 0x87, 0xdd, 0x2e,
  33710. 0xb9, 0x97, 0xca, 0xfc, 0x5a, 0xbf, 0x9d, 0xd1,
  33711. 0x02, 0xe6, 0x2f, 0xf6, 0x6c, 0xba, 0x87
  33712. };
  33713. WOLFSSL_SMALL_STACK_STATIC const byte* msgs[] = {msg1, msg2, msg3, msg1, msg1, msg4};
  33714. WOLFSSL_SMALL_STACK_STATIC const word16 msgSz[] = {0 /*sizeof(msg1)*/,
  33715. sizeof(msg2),
  33716. sizeof(msg3),
  33717. 0 /*sizeof(msg1)*/,
  33718. 0 /*sizeof(msg1)*/,
  33719. sizeof(msg4)
  33720. };
  33721. #ifndef NO_ASN
  33722. static const byte privateEd448[] = {
  33723. 0x30, 0x47, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06,
  33724. 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04, 0x39,
  33725. 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d, 0x10,
  33726. 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e, 0xbf,
  33727. 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c, 0x9f,
  33728. 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48, 0xa3,
  33729. 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04, 0x4e,
  33730. 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f, 0x8f,
  33731. 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98, 0xf9,
  33732. 0x5b
  33733. };
  33734. static const byte publicEd448[] = {
  33735. 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
  33736. 0x71, 0x03, 0x3a, 0x00, 0x5f, 0xd7, 0x44, 0x9b,
  33737. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33738. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33739. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33740. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33741. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33742. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33743. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33744. };
  33745. static const byte privPubEd448[] = {
  33746. 0x30, 0x81, 0x82, 0x02, 0x01, 0x00, 0x30, 0x05,
  33747. 0x06, 0x03, 0x2b, 0x65, 0x71, 0x04, 0x3b, 0x04,
  33748. 0x39, 0x6c, 0x82, 0xa5, 0x62, 0xcb, 0x80, 0x8d,
  33749. 0x10, 0xd6, 0x32, 0xbe, 0x89, 0xc8, 0x51, 0x3e,
  33750. 0xbf, 0x6c, 0x92, 0x9f, 0x34, 0xdd, 0xfa, 0x8c,
  33751. 0x9f, 0x63, 0xc9, 0x96, 0x0e, 0xf6, 0xe3, 0x48,
  33752. 0xa3, 0x52, 0x8c, 0x8a, 0x3f, 0xcc, 0x2f, 0x04,
  33753. 0x4e, 0x39, 0xa3, 0xfc, 0x5b, 0x94, 0x49, 0x2f,
  33754. 0x8f, 0x03, 0x2e, 0x75, 0x49, 0xa2, 0x00, 0x98,
  33755. 0xf9, 0x5b, 0x81, 0x39, 0x5f, 0xd7, 0x44, 0x9b,
  33756. 0x59, 0xb4, 0x61, 0xfd, 0x2c, 0xe7, 0x87, 0xec,
  33757. 0x61, 0x6a, 0xd4, 0x6a, 0x1d, 0xa1, 0x34, 0x24,
  33758. 0x85, 0xa7, 0x0e, 0x1f, 0x8a, 0x0e, 0xa7, 0x5d,
  33759. 0x80, 0xe9, 0x67, 0x78, 0xed, 0xf1, 0x24, 0x76,
  33760. 0x9b, 0x46, 0xc7, 0x06, 0x1b, 0xd6, 0x78, 0x3d,
  33761. 0xf1, 0xe5, 0x0f, 0x6c, 0xd1, 0xfa, 0x1a, 0xbe,
  33762. 0xaf, 0xe8, 0x25, 0x61, 0x80
  33763. };
  33764. word32 idx;
  33765. #endif /* NO_ASN */
  33766. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33767. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33768. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33769. ed448_key *key3 = NULL;
  33770. #else
  33771. ed448_key key3[1];
  33772. #endif
  33773. #endif
  33774. WOLFSSL_ENTER("ed448_test");
  33775. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33776. key = (ed448_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33777. key2 = (ed448_key *)XMALLOC(sizeof(*key2), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33778. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33779. key3 = (ed448_key *)XMALLOC(sizeof(*key3), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33780. #endif
  33781. #endif
  33782. /* create ed448 keys */
  33783. #ifndef HAVE_FIPS
  33784. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  33785. #else
  33786. ret = wc_InitRng(&rng);
  33787. #endif
  33788. if (ret != 0) {
  33789. XMEMSET(&rng, 0, sizeof(rng));
  33790. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33791. }
  33792. ret = wc_ed448_init(key);
  33793. if (ret < 0)
  33794. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33795. ret = wc_ed448_init(key2);
  33796. if (ret < 0)
  33797. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33798. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33799. ret = wc_ed448_init(key3);
  33800. if (ret < 0)
  33801. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33802. #endif
  33803. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key);
  33804. if (ret < 0)
  33805. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33806. ret = wc_ed448_make_key(&rng, ED448_KEY_SIZE, key2);
  33807. if (ret < 0)
  33808. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33809. /* helper functions for signature and key size */
  33810. keySz = (word32)wc_ed448_size(key);
  33811. sigSz = (word32)wc_ed448_sig_size(key);
  33812. #if defined(HAVE_ED448_SIGN) && defined(HAVE_ED448_KEY_EXPORT) &&\
  33813. defined(HAVE_ED448_KEY_IMPORT)
  33814. for (i = 0; i < 6; i++) {
  33815. outlen = sizeof(out);
  33816. XMEMSET(out, 0, sizeof(out));
  33817. if (wc_ed448_import_private_key(sKeys[i], ED448_KEY_SIZE, pKeys[i],
  33818. pKeySz[i], key) != 0)
  33819. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33820. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key, NULL,
  33821. 0) != 0)
  33822. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33823. if (XMEMCMP(out, sigs[i], 114))
  33824. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33825. #if defined(HAVE_ED448_VERIFY)
  33826. /* test verify on good msg */
  33827. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33828. NULL, 0) != 0 || verify != 1)
  33829. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33830. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  33831. /* test verify on good msg using streaming interface directly */
  33832. if (wc_ed448_verify_msg_init(out, outlen,
  33833. key, (byte)Ed448, NULL, 0) != 0)
  33834. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33835. for (j = 0; j < msgSz[i]; j += i) {
  33836. if (wc_ed448_verify_msg_update(msgs[i] + j, MIN(i, msgSz[i] - j), key) != 0)
  33837. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33838. }
  33839. if (wc_ed448_verify_msg_final(out, outlen, &verify,
  33840. key) != 0 || verify != 1)
  33841. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33842. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  33843. /* test verify on bad msg */
  33844. out[outlen-2] = out[outlen-2] + 1;
  33845. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key,
  33846. NULL, 0) == 0 || verify == 1)
  33847. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33848. #endif /* HAVE_ED448_VERIFY */
  33849. /* test api for import/exporting keys */
  33850. {
  33851. word32 exportPSz = ED448_KEY_SIZE;
  33852. word32 exportSSz = ED448_KEY_SIZE;
  33853. #ifdef WOLFSSL_NO_MALLOC
  33854. byte exportPKey[exportPSz];
  33855. byte exportSKey[exportSSz];
  33856. #else
  33857. byte *exportPKey = NULL;
  33858. byte *exportSKey = NULL;
  33859. exportPKey = (byte *)XMALLOC(exportPSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33860. exportSKey = (byte *)XMALLOC(exportSSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33861. if ((exportPKey == NULL) || (exportSKey == NULL))
  33862. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33863. #endif
  33864. ret = 0;
  33865. do {
  33866. if (wc_ed448_export_public(key, exportPKey, &exportPSz) != 0) {
  33867. ret = WC_TEST_RET_ENC_I(i);
  33868. break;
  33869. }
  33870. if (wc_ed448_import_public_ex(exportPKey, exportPSz, key2, 1) != 0) {
  33871. ret = WC_TEST_RET_ENC_I(i);
  33872. break;
  33873. }
  33874. if (wc_ed448_export_private_only(key, exportSKey, &exportSSz) != 0) {
  33875. ret = WC_TEST_RET_ENC_I(i);
  33876. break;
  33877. }
  33878. if (wc_ed448_import_private_key(exportSKey, exportSSz,
  33879. exportPKey, exportPSz, key2) != 0) {
  33880. ret = WC_TEST_RET_ENC_I(i);
  33881. break;
  33882. }
  33883. /* clear "out" buffer and test sign with imported keys */
  33884. outlen = sizeof(out);
  33885. XMEMSET(out, 0, sizeof(out));
  33886. if (wc_ed448_sign_msg(msgs[i], msgSz[i], out, &outlen, key2, NULL,
  33887. 0) != 0) {
  33888. ret = WC_TEST_RET_ENC_I(i);
  33889. break;
  33890. }
  33891. } while(0);
  33892. #ifndef WOLFSSL_NO_MALLOC
  33893. XFREE(exportPKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33894. XFREE(exportSKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33895. #endif
  33896. if (ret != 0)
  33897. goto out;
  33898. }
  33899. #if defined(HAVE_ED448_VERIFY)
  33900. if (wc_ed448_verify_msg(out, outlen, msgs[i], msgSz[i], &verify, key2,
  33901. NULL, 0) != 0 || verify != 1)
  33902. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33903. if (XMEMCMP(out, sigs[i], SIGSZ))
  33904. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  33905. #endif /* HAVE_ED448_VERIFY */
  33906. }
  33907. ret = ed448_ctx_test();
  33908. if (ret != 0)
  33909. goto out;
  33910. ret = ed448ph_test();
  33911. if (ret != 0)
  33912. goto out;
  33913. #ifndef NO_ASN
  33914. /* Try ASN.1 encoded private-only key and public key. */
  33915. idx = 0;
  33916. ret = wc_Ed448PrivateKeyDecode(privateEd448, &idx, key3,
  33917. sizeof(privateEd448));
  33918. if (ret != 0)
  33919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33920. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33921. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  33922. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33923. idx = 0;
  33924. ret = wc_Ed448PublicKeyDecode(publicEd448, &idx, key3, sizeof(publicEd448));
  33925. if (ret != 0)
  33926. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33927. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33928. if (ret != 0)
  33929. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33930. if (XMEMCMP(out, sigs[0], SIGSZ))
  33931. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33932. #if defined(HAVE_ED448_VERIFY)
  33933. /* test verify on good msg */
  33934. ret = wc_ed448_verify_msg(out, outlen, msgs[0], msgSz[0], &verify, key3,
  33935. NULL, 0);
  33936. if (ret != 0 || verify != 1)
  33937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33938. #endif /* HAVE_ED448_VERIFY */
  33939. wc_ed448_free(key3);
  33940. ret = wc_ed448_init(key3);
  33941. if (ret < 0)
  33942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33943. idx = 0;
  33944. ret = wc_Ed448PrivateKeyDecode(privPubEd448, &idx, key3,
  33945. sizeof(privPubEd448));
  33946. if (ret != 0)
  33947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33948. ret = wc_ed448_sign_msg(msgs[0], msgSz[0], out, &outlen, key3, NULL, 0);
  33949. if (ret != 0)
  33950. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  33951. if (XMEMCMP(out, sigs[0], SIGSZ))
  33952. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  33953. #endif /* NO_ASN */
  33954. #endif /* HAVE_ED448_SIGN && HAVE_ED448_KEY_EXPORT && HAVE_ED448_KEY_IMPORT */
  33955. ret = 0;
  33956. out:
  33957. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  33958. if (key) {
  33959. wc_ed448_free(key);
  33960. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33961. }
  33962. if (key2) {
  33963. wc_ed448_free(key2);
  33964. XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33965. }
  33966. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33967. if (key3) {
  33968. wc_ed448_free(key3);
  33969. XFREE(key3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  33970. }
  33971. #endif
  33972. #else
  33973. wc_ed448_free(key);
  33974. wc_ed448_free(key2);
  33975. #if !defined(NO_ASN) && defined(HAVE_ED448_SIGN)
  33976. wc_ed448_free(key3);
  33977. #endif
  33978. #endif
  33979. #if defined(HAVE_HASHDRBG) || defined(NO_RC4)
  33980. wc_FreeRng(&rng);
  33981. #endif
  33982. if (ret < 0)
  33983. return ret;
  33984. /* hush warnings of unused keySz and sigSz */
  33985. (void)keySz;
  33986. (void)sigSz;
  33987. ret = ed448_test_check_key();
  33988. if (ret < 0)
  33989. return ret;
  33990. #ifdef WOLFSSL_TEST_CERT
  33991. ret = ed448_test_cert();
  33992. if (ret < 0)
  33993. return ret;
  33994. #ifdef WOLFSSL_CERT_GEN
  33995. ret = ed448_test_make_cert();
  33996. if (ret < 0)
  33997. return ret;
  33998. #endif /* WOLFSSL_CERT_GEN */
  33999. #endif /* WOLFSSL_TEST_CERT */
  34000. return 0;
  34001. }
  34002. #endif /* HAVE_ED448 */
  34003. #ifdef WOLFSSL_HAVE_KYBER
  34004. #ifdef WOLFSSL_WC_KYBER /* OQS does not support KATs */
  34005. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  34006. static wc_test_ret_t kyber512_kat(void)
  34007. {
  34008. wc_test_ret_t ret;
  34009. #ifdef WOLFSSL_SMALL_STACK
  34010. KyberKey *key = NULL;
  34011. byte *priv = NULL;
  34012. byte *pub = NULL;
  34013. byte *ct = NULL;
  34014. byte *ss = NULL;
  34015. byte *ss_dec = NULL;
  34016. #else
  34017. KyberKey key[1];
  34018. byte priv[KYBER512_PRIVATE_KEY_SIZE];
  34019. byte pub[KYBER512_PUBLIC_KEY_SIZE];
  34020. byte ct[KYBER512_CIPHER_TEXT_SIZE];
  34021. byte ss[KYBER_SS_SZ];
  34022. byte ss_dec[KYBER_SS_SZ];
  34023. #endif
  34024. int key_inited = 0;
  34025. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_rand[] = {
  34026. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  34027. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  34028. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  34029. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  34030. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34031. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34032. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34033. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34034. };
  34035. WOLFSSL_SMALL_STACK_STATIC const byte kyber512enc_rand[] = {
  34036. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  34037. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  34038. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  34039. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  34040. };
  34041. #ifdef WOLFSSL_KYBER_ORIGINAL
  34042. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_pk[] = {
  34043. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34044. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34045. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34046. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34047. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34048. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34049. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34050. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34051. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34052. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34053. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34054. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34055. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34056. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34057. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34058. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34059. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34060. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34061. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34062. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34063. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34064. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34065. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34066. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34067. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34068. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34069. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34070. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34071. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34072. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34073. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34074. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34075. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34076. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34077. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34078. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34079. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34080. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34081. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34082. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34083. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34084. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34085. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34086. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34087. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34088. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34089. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34090. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34091. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34092. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34093. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34094. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34095. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34096. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34097. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34098. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34099. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34100. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34101. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34102. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34103. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34104. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34105. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34106. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34107. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34108. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34109. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34110. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34111. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34112. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34113. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34114. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34115. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34116. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34117. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34118. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34119. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34120. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34121. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34122. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34123. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34124. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34125. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34126. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34127. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34128. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34129. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34130. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34131. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34132. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34133. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34134. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34135. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34136. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34137. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34138. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34139. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34140. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34141. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34142. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  34143. };
  34144. #endif
  34145. #ifndef WOLFSSL_NO_ML_KEM
  34146. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_pk[] = {
  34147. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34148. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34149. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34150. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34151. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34152. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34153. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34154. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34155. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34156. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34157. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34158. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34159. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34160. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34161. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34162. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34163. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34164. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34165. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34166. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34167. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34168. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34169. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34170. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34171. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34172. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34173. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34174. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34175. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34176. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34177. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34178. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34179. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34180. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34181. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34182. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34183. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34184. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34185. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34186. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34187. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34188. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34189. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34190. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34191. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34192. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34193. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34194. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34195. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34196. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34197. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34198. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34199. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34200. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34201. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34202. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34203. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34204. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34205. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34206. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34207. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34208. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34209. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34210. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34211. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34212. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34213. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34214. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34215. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34216. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34217. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34218. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34219. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34220. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34221. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34222. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34223. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34224. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34225. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34226. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34227. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34228. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34229. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34230. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34231. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34232. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34233. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34234. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34235. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34236. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34237. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34238. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34239. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34240. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34241. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34242. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34243. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34244. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34245. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34246. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39
  34247. };
  34248. #endif
  34249. #ifdef WOLFSSL_KYBER_ORIGINAL
  34250. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_sk[] = {
  34251. 0x6C, 0x89, 0x2B, 0x02, 0x97, 0xA9, 0xC7, 0x64,
  34252. 0x14, 0x93, 0xF8, 0x7D, 0xAF, 0x35, 0x33, 0xEE,
  34253. 0xD6, 0x1F, 0x07, 0xF4, 0x65, 0x20, 0x66, 0x33,
  34254. 0x7E, 0xD7, 0x40, 0x46, 0xDC, 0xC7, 0x1B, 0xA0,
  34255. 0x3F, 0x30, 0x96, 0x01, 0x03, 0x16, 0x1F, 0x7D,
  34256. 0xEB, 0x53, 0xA7, 0x1B, 0x11, 0x61, 0x72, 0x63,
  34257. 0xFE, 0x2A, 0x80, 0x97, 0x69, 0xCE, 0x6D, 0x70,
  34258. 0xA8, 0x5F, 0xE6, 0x00, 0xEC, 0xE2, 0x9D, 0x7F,
  34259. 0x36, 0xA1, 0x6D, 0x33, 0x1B, 0x8B, 0x2A, 0x9E,
  34260. 0x1D, 0xB8, 0xC0, 0x90, 0x74, 0x2D, 0xF0, 0x73,
  34261. 0x9F, 0xF0, 0x60, 0xCE, 0xB4, 0xEC, 0xC5, 0xAB,
  34262. 0x1C, 0x5E, 0x55, 0xAC, 0x97, 0xBB, 0x66, 0xA7,
  34263. 0xF8, 0x95, 0x10, 0x5D, 0x57, 0x78, 0x2B, 0x22,
  34264. 0x95, 0x38, 0xE3, 0x42, 0x15, 0x44, 0xA3, 0x42,
  34265. 0x14, 0x08, 0xDB, 0xF4, 0x49, 0x10, 0x93, 0x4C,
  34266. 0xC4, 0x23, 0x77, 0x4F, 0x16, 0x76, 0xFF, 0x1C,
  34267. 0x30, 0x6F, 0x97, 0x55, 0x5F, 0x57, 0xB4, 0xAE,
  34268. 0xD7, 0xA6, 0xBA, 0xB9, 0x50, 0xA8, 0x16, 0x3C,
  34269. 0x8D, 0x31, 0x8D, 0xEA, 0x62, 0x75, 0x1B, 0xD6,
  34270. 0xAB, 0xC5, 0x06, 0x9C, 0x06, 0xC8, 0x8F, 0x33,
  34271. 0x00, 0x26, 0xA1, 0x98, 0x06, 0xA0, 0x3B, 0x97,
  34272. 0xA7, 0x69, 0x6B, 0x56, 0xDA, 0x21, 0x82, 0x7B,
  34273. 0xB4, 0xE8, 0xDC, 0x03, 0x11, 0x52, 0xB4, 0x1B,
  34274. 0x89, 0x2A, 0x9E, 0x99, 0xAD, 0xF6, 0xE1, 0x96,
  34275. 0x3E, 0x96, 0x57, 0x88, 0x28, 0x15, 0x4F, 0x46,
  34276. 0x70, 0x33, 0x84, 0x69, 0x20, 0xFB, 0xB4, 0xB8,
  34277. 0x05, 0x44, 0xE7, 0xE8, 0xA8, 0x1A, 0xE9, 0x63,
  34278. 0xCF, 0x36, 0x8C, 0x9B, 0xA0, 0x37, 0xA8, 0xC2,
  34279. 0xAD, 0x62, 0xE3, 0x2B, 0x6E, 0x61, 0xC9, 0x1D,
  34280. 0x75, 0xCE, 0x00, 0x5A, 0xB3, 0x0F, 0x80, 0x99,
  34281. 0xA1, 0xF2, 0x9D, 0x7B, 0x63, 0x05, 0xB4, 0xDC,
  34282. 0x06, 0xE2, 0x56, 0x80, 0xBB, 0x00, 0x99, 0x2F,
  34283. 0x71, 0x7F, 0xE6, 0xC1, 0x15, 0xA8, 0x08, 0x42,
  34284. 0x31, 0xCC, 0x79, 0xDD, 0x70, 0x0E, 0xA6, 0x91,
  34285. 0x2A, 0xC7, 0xFA, 0x0D, 0x93, 0x7B, 0xB6, 0xA7,
  34286. 0x56, 0x66, 0x22, 0x30, 0x47, 0x0C, 0x18, 0x9B,
  34287. 0x5A, 0xA1, 0x65, 0x3D, 0xEB, 0x93, 0x7D, 0x5A,
  34288. 0x9C, 0x25, 0xA2, 0x1D, 0x93, 0xB1, 0x90, 0x74,
  34289. 0xFC, 0x23, 0x9D, 0x81, 0x53, 0x53, 0x97, 0x97,
  34290. 0xC7, 0xD4, 0xAB, 0x62, 0x64, 0x9D, 0x76, 0xAA,
  34291. 0x55, 0x37, 0x36, 0xA9, 0x49, 0x02, 0x2C, 0x22,
  34292. 0xC5, 0x2B, 0xAE, 0xEC, 0x60, 0x5B, 0x32, 0xCE,
  34293. 0x9E, 0x5B, 0x93, 0x84, 0x90, 0x35, 0x58, 0xCA,
  34294. 0x9D, 0x6A, 0x3A, 0xBA, 0x90, 0x42, 0x3E, 0xED,
  34295. 0xA0, 0x1C, 0x94, 0x19, 0x8B, 0x19, 0x2A, 0x8B,
  34296. 0xA9, 0x06, 0x34, 0x97, 0xA0, 0xC5, 0x01, 0x33,
  34297. 0x07, 0xDD, 0xD8, 0x63, 0x52, 0x64, 0x71, 0xA4,
  34298. 0xD9, 0x95, 0x23, 0xEB, 0x41, 0x7F, 0x29, 0x1A,
  34299. 0xAC, 0x0C, 0x3A, 0x58, 0x1B, 0x6D, 0xA0, 0x07,
  34300. 0x32, 0xE5, 0xE8, 0x1B, 0x1F, 0x7C, 0x87, 0x9B,
  34301. 0x16, 0x93, 0xC1, 0x3B, 0x6F, 0x9F, 0x79, 0x31,
  34302. 0x62, 0x24, 0x29, 0xE5, 0x42, 0xAF, 0x40, 0x69,
  34303. 0x22, 0x2F, 0x04, 0x55, 0x44, 0xE0, 0xCC, 0x4F,
  34304. 0xB2, 0x4D, 0x44, 0x48, 0xCF, 0x2C, 0x65, 0x96,
  34305. 0xF5, 0xCB, 0x08, 0x62, 0x4B, 0x11, 0x85, 0x01,
  34306. 0x3B, 0x6B, 0x02, 0x08, 0x92, 0xF9, 0x6B, 0xDF,
  34307. 0xD4, 0xAD, 0xA9, 0x17, 0x9D, 0xE7, 0x27, 0xB8,
  34308. 0xD9, 0x42, 0x6E, 0x09, 0x96, 0xB5, 0xD3, 0x49,
  34309. 0x48, 0xCE, 0x02, 0xD0, 0xC3, 0x69, 0xB3, 0x7C,
  34310. 0xBB, 0x54, 0xD3, 0x47, 0x9E, 0xD8, 0xB5, 0x82,
  34311. 0xE9, 0xE7, 0x28, 0x92, 0x9B, 0x4C, 0x71, 0xC9,
  34312. 0xBE, 0x11, 0xD4, 0x5B, 0x20, 0xC4, 0xBD, 0xC3,
  34313. 0xC7, 0x43, 0x13, 0x22, 0x3F, 0x58, 0x27, 0x4E,
  34314. 0x8B, 0xA5, 0x24, 0x44, 0x47, 0xC4, 0x95, 0x95,
  34315. 0x0B, 0x84, 0xCB, 0x0C, 0x3C, 0x27, 0x36, 0x40,
  34316. 0x10, 0x8A, 0x33, 0x97, 0x94, 0x45, 0x73, 0x27,
  34317. 0x93, 0x28, 0x99, 0x6C, 0xDC, 0x0C, 0x91, 0x3C,
  34318. 0x95, 0x8A, 0xD6, 0x20, 0xBA, 0x8B, 0x5E, 0x5E,
  34319. 0xCB, 0xBB, 0x7E, 0x13, 0xCB, 0x9C, 0x70, 0xBD,
  34320. 0x5A, 0xB3, 0x0E, 0xB7, 0x48, 0x8C, 0x97, 0x00,
  34321. 0x1C, 0x20, 0x49, 0x8F, 0x1D, 0x7C, 0xC0, 0x6D,
  34322. 0xA7, 0x6B, 0xF5, 0x20, 0xC6, 0x58, 0xCC, 0xAD,
  34323. 0xFA, 0x29, 0x56, 0x42, 0x45, 0x57, 0xAB, 0xEA,
  34324. 0x8A, 0xB8, 0x92, 0x39, 0xC1, 0x78, 0x33, 0xDC,
  34325. 0x3A, 0x49, 0xB3, 0x6A, 0x9A, 0xE9, 0xA4, 0x86,
  34326. 0x94, 0x05, 0x40, 0xEB, 0x44, 0x4F, 0x97, 0x15,
  34327. 0x23, 0x57, 0xE0, 0x20, 0x35, 0x93, 0x9D, 0x75,
  34328. 0xA3, 0xC0, 0x25, 0xF4, 0x1A, 0x40, 0x08, 0x23,
  34329. 0x82, 0xA0, 0x73, 0x3C, 0x39, 0xB0, 0x62, 0x2B,
  34330. 0x74, 0x0E, 0x40, 0x75, 0x92, 0xC6, 0x2E, 0xCA,
  34331. 0xEB, 0x14, 0x32, 0xC4, 0x45, 0xB3, 0x70, 0x3A,
  34332. 0x86, 0xF6, 0x98, 0x1A, 0x27, 0x81, 0x57, 0xEA,
  34333. 0x95, 0xA6, 0xE9, 0x2D, 0x55, 0xE4, 0xB9, 0x72,
  34334. 0xF9, 0x36, 0xC2, 0xF0, 0xA6, 0x58, 0x28, 0x0E,
  34335. 0xA2, 0xB0, 0x7A, 0x48, 0x99, 0x2D, 0xF8, 0x93,
  34336. 0x7E, 0x0A, 0x2A, 0xC1, 0xDC, 0xC9, 0x74, 0xFE,
  34337. 0x00, 0xAA, 0xE1, 0xF5, 0x61, 0xFA, 0x25, 0x8E,
  34338. 0x2D, 0x25, 0x9C, 0x3E, 0x86, 0x1D, 0xCE, 0x23,
  34339. 0x60, 0x39, 0x12, 0x76, 0x06, 0xFC, 0x1C, 0xE0,
  34340. 0x09, 0x00, 0x3A, 0x7B, 0xAC, 0x94, 0x21, 0x01,
  34341. 0xDC, 0xB8, 0x22, 0xB1, 0xF3, 0xC1, 0x2B, 0xF7,
  34342. 0x32, 0x38, 0xF5, 0x46, 0xE0, 0x1C, 0x36, 0xB5,
  34343. 0xA6, 0x93, 0x61, 0x92, 0x99, 0x5C, 0xC6, 0x9C,
  34344. 0x63, 0x23, 0x74, 0x09, 0xCB, 0x53, 0xC2, 0xE3,
  34345. 0x5D, 0x74, 0x89, 0x0D, 0x18, 0x88, 0x53, 0x76,
  34346. 0xFA, 0x55, 0x03, 0xB1, 0x07, 0xA2, 0xA3, 0x92,
  34347. 0x11, 0x5A, 0xCE, 0x0E, 0x64, 0x67, 0x7C, 0xBB,
  34348. 0x7D, 0xCF, 0xC9, 0x3C, 0x16, 0xD3, 0xA3, 0x05,
  34349. 0xF6, 0x76, 0x15, 0xA4, 0x88, 0xD7, 0x11, 0xAA,
  34350. 0x56, 0x69, 0x8C, 0x56, 0x63, 0xAB, 0x7A, 0xC9,
  34351. 0xCE, 0x66, 0xD5, 0x47, 0xC0, 0x59, 0x5F, 0x98,
  34352. 0xA4, 0x3F, 0x46, 0x50, 0xBB, 0xE0, 0x8C, 0x36,
  34353. 0x4D, 0x97, 0x67, 0x89, 0x11, 0x7D, 0x34, 0xF6,
  34354. 0xAE, 0x51, 0xAC, 0x06, 0x3C, 0xB5, 0x5C, 0x6C,
  34355. 0xA3, 0x25, 0x58, 0x22, 0x7D, 0xFE, 0xF8, 0x07,
  34356. 0xD1, 0x9C, 0x30, 0xDE, 0x41, 0x44, 0x24, 0x09,
  34357. 0x7F, 0x6A, 0xA2, 0x36, 0xA1, 0x05, 0x3B, 0x4A,
  34358. 0x07, 0xA7, 0x6B, 0xE3, 0x72, 0xA5, 0xC6, 0xB6,
  34359. 0x00, 0x27, 0x91, 0xEB, 0xE0, 0xAF, 0xDA, 0xF5,
  34360. 0x4E, 0x1C, 0xA2, 0x37, 0xFF, 0x54, 0x5B, 0xA6,
  34361. 0x83, 0x43, 0xE7, 0x45, 0xC0, 0x4A, 0xD1, 0x63,
  34362. 0x9D, 0xBC, 0x59, 0x03, 0x46, 0xB6, 0xB9, 0x56,
  34363. 0x9B, 0x56, 0xDB, 0xBF, 0xE5, 0x31, 0x51, 0x91,
  34364. 0x30, 0x66, 0xE5, 0xC8, 0x55, 0x27, 0xDC, 0x94,
  34365. 0x68, 0x11, 0x0A, 0x13, 0x6A, 0x41, 0x14, 0x97,
  34366. 0xC2, 0x27, 0xDC, 0xB8, 0xC9, 0xB2, 0x55, 0x70,
  34367. 0xB7, 0xA0, 0xE4, 0x2A, 0xAD, 0xA6, 0x70, 0x9F,
  34368. 0x23, 0x20, 0x8F, 0x5D, 0x49, 0x6E, 0xBA, 0xB7,
  34369. 0x84, 0x3F, 0x64, 0x83, 0xBF, 0x0C, 0x0C, 0x73,
  34370. 0xA4, 0x02, 0x96, 0xEC, 0x2C, 0x64, 0x40, 0x00,
  34371. 0x13, 0x94, 0xC9, 0x9C, 0xA1, 0x73, 0xD5, 0xC7,
  34372. 0x75, 0xB7, 0xF4, 0x15, 0xD0, 0x2A, 0x5A, 0x26,
  34373. 0xA0, 0x74, 0x07, 0x91, 0x85, 0x87, 0xC4, 0x11,
  34374. 0x69, 0xF2, 0xB7, 0x17, 0x87, 0x55, 0xAC, 0xC2,
  34375. 0x7F, 0xC8, 0xB1, 0x9C, 0x4C, 0x4B, 0x3F, 0xCD,
  34376. 0x41, 0x05, 0x3F, 0x2C, 0x74, 0xC8, 0xA1, 0x0A,
  34377. 0x83, 0x21, 0x24, 0x1B, 0x28, 0x02, 0x43, 0x28,
  34378. 0x75, 0xAE, 0x80, 0x8B, 0x9E, 0xF1, 0x36, 0x5C,
  34379. 0x7B, 0x8A, 0x52, 0x90, 0x2F, 0x13, 0x17, 0xBA,
  34380. 0x2F, 0xB0, 0x26, 0x9F, 0x47, 0x93, 0x06, 0x72,
  34381. 0x10, 0x7B, 0x47, 0x26, 0xFE, 0xF6, 0x45, 0x47,
  34382. 0x39, 0x4D, 0x33, 0x20, 0xC8, 0xF1, 0x20, 0xB3,
  34383. 0xC2, 0xF4, 0x72, 0x5B, 0x03, 0x05, 0xFA, 0xB8,
  34384. 0x8C, 0xC7, 0x98, 0x1F, 0xCB, 0x09, 0xA7, 0x6A,
  34385. 0x1C, 0xBF, 0x7F, 0x17, 0x9F, 0x43, 0xBB, 0x0A,
  34386. 0x4C, 0x8B, 0x05, 0x90, 0x85, 0x7F, 0x1E, 0x69,
  34387. 0x70, 0x84, 0x66, 0xC7, 0xF8, 0x60, 0x73, 0x91,
  34388. 0xE7, 0xBC, 0x52, 0x68, 0xBF, 0xD3, 0xD7, 0xA1,
  34389. 0xDF, 0xFC, 0xB4, 0xEC, 0xA2, 0xA1, 0xC9, 0xB5,
  34390. 0x97, 0x59, 0x30, 0x13, 0xD5, 0xFC, 0x42, 0x02,
  34391. 0xEC, 0x2B, 0x74, 0xE5, 0x7A, 0xB7, 0x6B, 0xBC,
  34392. 0xF3, 0x63, 0x2B, 0xBA, 0xF9, 0x7C, 0xDC, 0x41,
  34393. 0x8A, 0x6F, 0x16, 0x39, 0x28, 0x38, 0xCA, 0x9B,
  34394. 0xF4, 0x5D, 0xDF, 0x02, 0x37, 0x77, 0xB7, 0x56,
  34395. 0x18, 0x33, 0xC1, 0x05, 0x19, 0x0F, 0x94, 0xF3,
  34396. 0x02, 0xC5, 0x9B, 0x53, 0x19, 0x00, 0xBB, 0xC8,
  34397. 0x16, 0x36, 0x1F, 0xAA, 0x5B, 0x33, 0x80, 0xCA,
  34398. 0x3A, 0x89, 0x31, 0x04, 0xCA, 0x73, 0x88, 0xB1,
  34399. 0x85, 0x67, 0x1B, 0x3E, 0x5F, 0xE3, 0x79, 0x0E,
  34400. 0x9A, 0x62, 0x6E, 0xC4, 0x6D, 0x9B, 0x0B, 0x33,
  34401. 0xC7, 0xA4, 0x19, 0xAF, 0x7B, 0x32, 0xB6, 0x85,
  34402. 0x98, 0x94, 0xF5, 0x75, 0xD8, 0x2A, 0xC5, 0x45,
  34403. 0x6B, 0x54, 0x90, 0xA7, 0xAF, 0x8F, 0xE6, 0x10,
  34404. 0x46, 0x36, 0x05, 0x89, 0xEC, 0xBA, 0x72, 0x44,
  34405. 0x23, 0x6F, 0x41, 0x23, 0x11, 0x6B, 0x61, 0x74,
  34406. 0xAA, 0x17, 0x92, 0x49, 0xA4, 0x91, 0x95, 0xB3,
  34407. 0x56, 0xC7, 0x2F, 0xC6, 0x64, 0x1F, 0x02, 0x51,
  34408. 0x81, 0x2E, 0xAA, 0x98, 0x57, 0x0B, 0x04, 0x66,
  34409. 0x99, 0x07, 0x0E, 0x08, 0x19, 0xDC, 0x27, 0x13,
  34410. 0xF4, 0x69, 0x13, 0x7D, 0xFC, 0x6A, 0x3D, 0x7B,
  34411. 0x92, 0xB2, 0x98, 0x99, 0x5E, 0xE7, 0x80, 0x36,
  34412. 0x91, 0x53, 0xAC, 0x36, 0x6B, 0x06, 0xD7, 0x24,
  34413. 0x9C, 0xD0, 0x9E, 0x1B, 0x33, 0x78, 0xFB, 0x04,
  34414. 0x39, 0x9C, 0xEC, 0xB8, 0x65, 0x05, 0x81, 0xD6,
  34415. 0x37, 0xC7, 0x9A, 0xE6, 0x7D, 0x6F, 0x2C, 0xAF,
  34416. 0x6A, 0xBA, 0xCF, 0x59, 0x81, 0x59, 0xA7, 0x79,
  34417. 0x2C, 0xB3, 0xC9, 0x71, 0xD1, 0x49, 0x9D, 0x23,
  34418. 0x73, 0xAD, 0x20, 0xF6, 0x3F, 0x03, 0xBB, 0x59,
  34419. 0xED, 0x13, 0x73, 0x84, 0xAC, 0x61, 0xA7, 0x15,
  34420. 0x51, 0x43, 0xB8, 0xCA, 0x49, 0x32, 0x61, 0x2E,
  34421. 0xC9, 0x15, 0xE4, 0xCA, 0x34, 0x6A, 0x9B, 0xCE,
  34422. 0x5D, 0xD6, 0x04, 0x17, 0xC6, 0xB2, 0xA8, 0x9B,
  34423. 0x1C, 0xC4, 0x35, 0x64, 0x3F, 0x87, 0x5B, 0xDC,
  34424. 0x5A, 0x7E, 0x5B, 0x34, 0x81, 0xCF, 0x91, 0x9E,
  34425. 0xA0, 0x91, 0x72, 0xFE, 0xBC, 0x46, 0xD4, 0xFC,
  34426. 0x3F, 0xB0, 0xCB, 0x95, 0x91, 0x70, 0x4E, 0xE2,
  34427. 0xDB, 0xB6, 0x18, 0x44, 0xB2, 0xF3, 0x31, 0x4A,
  34428. 0x06, 0xBB, 0x6C, 0x6D, 0x34, 0x00, 0x5E, 0x48,
  34429. 0x5C, 0xE6, 0x67, 0xBD, 0xC7, 0xD0, 0x98, 0x58,
  34430. 0x69, 0x28, 0xD2, 0xD9, 0x13, 0x40, 0xF0, 0x04,
  34431. 0x19, 0xEA, 0x40, 0x13, 0x51, 0xA2, 0x40, 0xA0,
  34432. 0xB0, 0x41, 0x05, 0x8B, 0xEF, 0xB0, 0xC2, 0xFD,
  34433. 0x32, 0x64, 0x5B, 0x7A, 0x2D, 0xF8, 0xF5, 0xCB,
  34434. 0xFD, 0x87, 0x33, 0x27, 0xC9, 0x78, 0xD7, 0xB3,
  34435. 0x51, 0xA2, 0x80, 0x88, 0x43, 0x88, 0x37, 0x02,
  34436. 0x4C, 0x52, 0xB9, 0xC2, 0x95, 0xCD, 0x71, 0x36,
  34437. 0x46, 0xFB, 0x5D, 0x6C, 0x0C, 0xCF, 0xB4, 0x70,
  34438. 0x73, 0x4A, 0xC2, 0xB2, 0xBC, 0x81, 0x23, 0xC2,
  34439. 0xC1, 0x3D, 0xF6, 0x93, 0x8E, 0x92, 0x45, 0x5A,
  34440. 0x86, 0x26, 0x39, 0xFE, 0xB8, 0xA6, 0x4B, 0x85,
  34441. 0x16, 0x3E, 0x32, 0x70, 0x7E, 0x03, 0x7B, 0x38,
  34442. 0xD8, 0xAC, 0x39, 0x22, 0xB4, 0x51, 0x87, 0xBB,
  34443. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  34444. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  34445. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  34446. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  34447. 0x7F, 0xFA, 0xD1, 0xBC, 0x8A, 0xF7, 0x3B, 0x7E,
  34448. 0x87, 0x49, 0x56, 0xB8, 0x1C, 0x2A, 0x2E, 0xF0,
  34449. 0xBF, 0xAB, 0xE8, 0xDC, 0x93, 0xD7, 0x7B, 0x2F,
  34450. 0xBC, 0x9E, 0x0C, 0x64, 0xEF, 0xA0, 0x1E, 0x84,
  34451. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  34452. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  34453. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  34454. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  34455. };
  34456. #endif
  34457. #ifndef WOLFSSL_NO_ML_KEM
  34458. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_sk[] = {
  34459. 0x9c, 0xda, 0x16, 0x86, 0xa3, 0x39, 0x6a, 0x7c,
  34460. 0x10, 0x9b, 0x41, 0x52, 0x89, 0xf5, 0x6a, 0x9e,
  34461. 0xc4, 0x4c, 0xd5, 0xb9, 0xb6, 0x74, 0xc3, 0x8a,
  34462. 0x3b, 0xba, 0xb3, 0x0a, 0x2c, 0x90, 0xf0, 0x04,
  34463. 0x37, 0xa2, 0x64, 0xb0, 0xbe, 0x9a, 0x1e, 0x8b,
  34464. 0xa8, 0x87, 0xd3, 0xc3, 0xb1, 0x00, 0x89, 0x80,
  34465. 0x54, 0x27, 0x2f, 0x94, 0x1c, 0x88, 0xa1, 0xf2,
  34466. 0x08, 0xf1, 0xc9, 0x14, 0xf9, 0x64, 0xc1, 0xaa,
  34467. 0xd6, 0x13, 0xa6, 0xa8, 0x4f, 0x88, 0xe4, 0x2d,
  34468. 0x35, 0x56, 0x83, 0x5f, 0xb1, 0x61, 0xfd, 0xc5,
  34469. 0xcd, 0x15, 0xa3, 0xbc, 0x7e, 0x74, 0xb6, 0xf2,
  34470. 0x61, 0x2f, 0xa8, 0x27, 0x1c, 0x7e, 0xa1, 0x12,
  34471. 0xb0, 0x5c, 0x2a, 0x36, 0xcc, 0x70, 0x7c, 0xe3,
  34472. 0x8d, 0x5d, 0x1a, 0xcc, 0x51, 0x15, 0x46, 0x2a,
  34473. 0x8c, 0x1a, 0xab, 0xf0, 0x72, 0x76, 0xc7, 0x23,
  34474. 0x18, 0x33, 0x7f, 0x74, 0xb5, 0xcb, 0xef, 0xea,
  34475. 0x7a, 0x80, 0x37, 0x90, 0xbc, 0x03, 0x93, 0xf3,
  34476. 0xa5, 0x4c, 0x72, 0x4a, 0x57, 0x65, 0xa4, 0x8f,
  34477. 0x29, 0x6b, 0x03, 0xf4, 0x84, 0x37, 0x60, 0x23,
  34478. 0x62, 0x69, 0x30, 0x22, 0x27, 0x04, 0xc0, 0x8f,
  34479. 0xd3, 0xbc, 0x72, 0x93, 0x15, 0xd1, 0xfc, 0x70,
  34480. 0xeb, 0x79, 0x75, 0xa9, 0x7b, 0x9d, 0xee, 0xd1,
  34481. 0x62, 0xf4, 0x86, 0xbb, 0xc6, 0x4a, 0x09, 0x71,
  34482. 0x11, 0x95, 0x2d, 0x89, 0xb5, 0x7d, 0x76, 0x5e,
  34483. 0x8a, 0x99, 0x1a, 0x2e, 0x56, 0x42, 0x06, 0xea,
  34484. 0x7b, 0xf5, 0xe4, 0x00, 0x7a, 0x66, 0x35, 0x88,
  34485. 0x31, 0xca, 0x0e, 0x34, 0xb2, 0xf6, 0xa8, 0x4d,
  34486. 0x10, 0xf7, 0x9c, 0x47, 0x7c, 0xb6, 0x6a, 0x8a,
  34487. 0x95, 0x25, 0x69, 0x36, 0x73, 0x88, 0x13, 0x0d,
  34488. 0x7b, 0x97, 0x4a, 0x63, 0xaa, 0x51, 0x99, 0x6c,
  34489. 0x97, 0x70, 0x9b, 0xb8, 0xea, 0xbc, 0x94, 0xe6,
  34490. 0xa5, 0x35, 0xd7, 0x92, 0xd2, 0x90, 0x54, 0x74,
  34491. 0x95, 0x2d, 0x6b, 0x8c, 0x22, 0x22, 0xb2, 0xae,
  34492. 0x56, 0xdc, 0x66, 0xfb, 0x04, 0x61, 0x19, 0x20,
  34493. 0x66, 0xcd, 0xdb, 0x43, 0xec, 0x05, 0x98, 0x4f,
  34494. 0xb4, 0x98, 0x26, 0x49, 0x77, 0x13, 0x97, 0xc6,
  34495. 0xa8, 0x37, 0x9f, 0x3b, 0x56, 0x43, 0x06, 0x98,
  34496. 0x48, 0x87, 0x59, 0x19, 0xe8, 0x9c, 0xc4, 0x39,
  34497. 0xa3, 0xbe, 0x2f, 0x08, 0x14, 0x90, 0xf3, 0x41,
  34498. 0xbd, 0x12, 0x40, 0xad, 0xd8, 0x0d, 0xdb, 0x8c,
  34499. 0x99, 0x63, 0xb4, 0x7a, 0x2a, 0x09, 0x92, 0x29,
  34500. 0x03, 0x38, 0xda, 0x9c, 0x3b, 0x72, 0x5c, 0x6d,
  34501. 0xa4, 0x47, 0x18, 0xc0, 0x10, 0x46, 0x81, 0x25,
  34502. 0x62, 0xaf, 0xb0, 0x84, 0x83, 0x7a, 0xcb, 0x3c,
  34503. 0x57, 0x5e, 0x4f, 0x93, 0x93, 0x6c, 0x35, 0x2a,
  34504. 0xc0, 0xe7, 0x0a, 0xa3, 0x84, 0x5e, 0xe4, 0x85,
  34505. 0x29, 0x6e, 0x6b, 0x02, 0xde, 0x0b, 0x47, 0xb5,
  34506. 0xc4, 0xc9, 0x6b, 0x0b, 0x7c, 0xf9, 0x4c, 0x4a,
  34507. 0xbe, 0x95, 0x48, 0x61, 0x53, 0x11, 0x8e, 0x43,
  34508. 0xc2, 0xb9, 0xc8, 0x4d, 0x9d, 0xa9, 0x1c, 0x6c,
  34509. 0x5a, 0xcd, 0x5a, 0x57, 0x00, 0x2d, 0x05, 0x84,
  34510. 0x97, 0x99, 0x27, 0x99, 0xe5, 0xba, 0x1c, 0xe6,
  34511. 0xc2, 0x5e, 0xb2, 0x98, 0x44, 0xd8, 0x58, 0xba,
  34512. 0x1c, 0x37, 0x85, 0x0c, 0x0c, 0x2f, 0x57, 0xc6,
  34513. 0x0d, 0xe3, 0x7f, 0x77, 0xc0, 0x82, 0xec, 0x14,
  34514. 0x49, 0x4e, 0xba, 0x28, 0x8a, 0x65, 0x91, 0x51,
  34515. 0x16, 0xc2, 0x0a, 0x32, 0x5d, 0xe3, 0x1a, 0xaa,
  34516. 0xdd, 0x68, 0x0d, 0xb1, 0x9c, 0x0c, 0xfc, 0xc3,
  34517. 0x46, 0x0f, 0x0a, 0xa0, 0x1a, 0x87, 0xa6, 0xa5,
  34518. 0x80, 0xc6, 0xca, 0x29, 0x1f, 0xae, 0xf0, 0xcc,
  34519. 0xc4, 0x9b, 0x76, 0xa8, 0xda, 0xc4, 0xf9, 0xd4,
  34520. 0x16, 0x40, 0x50, 0x9d, 0xbd, 0x0b, 0x40, 0x45,
  34521. 0xc1, 0x53, 0x0e, 0xd3, 0x47, 0x55, 0xd4, 0x74,
  34522. 0x62, 0x70, 0x0f, 0x2a, 0x8c, 0xaf, 0x96, 0x80,
  34523. 0xa6, 0xd7, 0xe3, 0x8a, 0x7e, 0x2a, 0x63, 0xe9,
  34524. 0x37, 0x65, 0x0a, 0x23, 0x30, 0x6d, 0x85, 0x5d,
  34525. 0xa2, 0xa2, 0xb7, 0xef, 0x50, 0x5c, 0xa5, 0x96,
  34526. 0xab, 0x04, 0x85, 0x01, 0x3e, 0xa9, 0x27, 0xc7,
  34527. 0x34, 0x23, 0x43, 0x61, 0x36, 0x43, 0xba, 0x40,
  34528. 0x07, 0xd6, 0xc8, 0x74, 0xb9, 0x80, 0xc7, 0x9c,
  34529. 0x3a, 0xa1, 0xc7, 0x4f, 0x85, 0x81, 0xc3, 0x48,
  34530. 0x49, 0xb3, 0x6e, 0xa7, 0x98, 0x15, 0xfb, 0xb4,
  34531. 0xcc, 0xf9, 0x61, 0x05, 0x83, 0x08, 0x1d, 0x7c,
  34532. 0x5b, 0x44, 0x09, 0xb8, 0xd0, 0x53, 0x1c, 0x04,
  34533. 0xbc, 0xaf, 0x7c, 0xc7, 0x51, 0x10, 0x3a, 0x5f,
  34534. 0xd1, 0xba, 0x44, 0x70, 0x83, 0x3e, 0x89, 0x77,
  34535. 0x5a, 0xde, 0xd9, 0x70, 0xb5, 0x47, 0x18, 0x59,
  34536. 0x25, 0x0f, 0xe7, 0x26, 0x71, 0x05, 0x83, 0x5f,
  34537. 0x39, 0x00, 0x30, 0xc5, 0xe7, 0xcd, 0x3f, 0x96,
  34538. 0x10, 0x19, 0xea, 0xae, 0xa2, 0x37, 0x77, 0xd3,
  34539. 0x47, 0xbb, 0x2a, 0xdc, 0xb6, 0x73, 0xc0, 0x20,
  34540. 0x34, 0xf3, 0x94, 0x34, 0x22, 0x71, 0xbc, 0xea,
  34541. 0x64, 0x14, 0xe5, 0x46, 0xc3, 0xb2, 0x0b, 0xd5,
  34542. 0x74, 0x81, 0xc7, 0xea, 0x14, 0xc7, 0x7c, 0x38,
  34543. 0x8c, 0xc8, 0x62, 0x51, 0xc1, 0x25, 0x58, 0xb1,
  34544. 0x00, 0xf8, 0xc5, 0xb3, 0xd0, 0x3c, 0xa2, 0xc7,
  34545. 0x07, 0x13, 0x90, 0x96, 0x59, 0xc8, 0xba, 0x26,
  34546. 0xd0, 0xd1, 0x76, 0x5e, 0x0b, 0xc8, 0x23, 0xd6,
  34547. 0x8c, 0xa5, 0x57, 0x0d, 0xe6, 0x00, 0xcd, 0x09,
  34548. 0x41, 0x72, 0x5d, 0x38, 0x6e, 0x14, 0xc1, 0x01,
  34549. 0x2d, 0xf5, 0x95, 0x1b, 0xeb, 0x8d, 0x82, 0x81,
  34550. 0xa4, 0xf6, 0x81, 0x5d, 0x37, 0x60, 0xb7, 0x64,
  34551. 0x29, 0x5a, 0xd0, 0x40, 0x6c, 0x2b, 0xf7, 0x92,
  34552. 0x8a, 0xd6, 0x50, 0x32, 0xb6, 0x5f, 0x14, 0xb7,
  34553. 0x7c, 0xcb, 0x89, 0x17, 0xc9, 0x3a, 0x29, 0xd6,
  34554. 0x28, 0x7d, 0x8a, 0x60, 0x62, 0x39, 0x9c, 0xb6,
  34555. 0x40, 0x08, 0x65, 0xed, 0x10, 0xb6, 0x19, 0xaa,
  34556. 0x58, 0x11, 0x13, 0x9b, 0xc0, 0x86, 0x82, 0x57,
  34557. 0x82, 0xb2, 0xb7, 0x12, 0x4f, 0x75, 0x7c, 0x83,
  34558. 0xae, 0x79, 0x44, 0x44, 0xbc, 0x78, 0xa4, 0x78,
  34559. 0x96, 0xac, 0xf1, 0x26, 0x2c, 0x81, 0x35, 0x10,
  34560. 0x77, 0x89, 0x3b, 0xfc, 0x56, 0xf9, 0x04, 0x49,
  34561. 0xc2, 0xfa, 0x5f, 0x6e, 0x58, 0x6d, 0xd3, 0x7c,
  34562. 0x0b, 0x9b, 0x58, 0x19, 0x92, 0x63, 0x8c, 0xb7,
  34563. 0xe7, 0xbc, 0xbb, 0xb9, 0x9a, 0xfe, 0x47, 0x81,
  34564. 0xd8, 0x0a, 0x50, 0xe6, 0x94, 0x63, 0xfb, 0xd9,
  34565. 0x88, 0x72, 0x2c, 0x36, 0x35, 0x42, 0x3e, 0x27,
  34566. 0x46, 0x6c, 0x71, 0xdc, 0xc6, 0x74, 0x52, 0x7c,
  34567. 0xcd, 0x72, 0x89, 0x68, 0xcb, 0xcd, 0xc0, 0x0c,
  34568. 0x5c, 0x90, 0x35, 0xbb, 0x0a, 0xf2, 0xc9, 0x92,
  34569. 0x2c, 0x78, 0x81, 0xa4, 0x1d, 0xd2, 0x87, 0x52,
  34570. 0x73, 0x92, 0x51, 0x31, 0x23, 0x0f, 0x6c, 0xa5,
  34571. 0x9e, 0x91, 0x36, 0xb3, 0x9f, 0x95, 0x6c, 0x93,
  34572. 0xb3, 0xb2, 0xd1, 0x4c, 0x64, 0x1b, 0x08, 0x9e,
  34573. 0x07, 0xd0, 0xa8, 0x40, 0xc8, 0x93, 0xec, 0xd7,
  34574. 0x6b, 0xbf, 0x92, 0xc8, 0x05, 0x45, 0x66, 0x68,
  34575. 0xd0, 0x7c, 0x62, 0x14, 0x91, 0xc5, 0xc0, 0x54,
  34576. 0x99, 0x1a, 0x65, 0x6f, 0x51, 0x16, 0x19, 0x55,
  34577. 0x6e, 0xb9, 0x77, 0x82, 0xe2, 0x7a, 0x3c, 0x78,
  34578. 0x51, 0x24, 0xc7, 0x0b, 0x0d, 0xab, 0xa6, 0xc6,
  34579. 0x24, 0xd1, 0x8e, 0x0f, 0x97, 0x93, 0xf9, 0x6b,
  34580. 0xa9, 0xe1, 0x59, 0x9b, 0x17, 0xb3, 0x0d, 0xcc,
  34581. 0xc0, 0xb4, 0xf3, 0x76, 0x6a, 0x07, 0xb2, 0x3b,
  34582. 0x25, 0x73, 0x09, 0xcd, 0x76, 0xab, 0xa0, 0x72,
  34583. 0xc2, 0xb9, 0xc9, 0x74, 0x43, 0x94, 0xc6, 0xab,
  34584. 0x9c, 0xb6, 0xc5, 0x4a, 0x97, 0xb5, 0xc5, 0x78,
  34585. 0x61, 0xa5, 0x8d, 0xc0, 0xa0, 0x35, 0x19, 0x83,
  34586. 0x2e, 0xe3, 0x2a, 0x07, 0x65, 0x4a, 0x07, 0x0c,
  34587. 0x0c, 0x8c, 0x4e, 0x86, 0x48, 0xad, 0xdc, 0x35,
  34588. 0x5f, 0x27, 0x4f, 0xc6, 0xb9, 0x2a, 0x08, 0x7b,
  34589. 0x3f, 0x97, 0x51, 0x92, 0x3e, 0x44, 0x27, 0x4f,
  34590. 0x85, 0x8c, 0x49, 0xca, 0xba, 0x72, 0xb6, 0x58,
  34591. 0x51, 0xb3, 0xad, 0xc4, 0x89, 0x36, 0x95, 0x50,
  34592. 0x97, 0xca, 0xd9, 0x55, 0x3f, 0x5a, 0x26, 0x3f,
  34593. 0x18, 0x44, 0xb5, 0x2a, 0x02, 0x0f, 0xf7, 0xca,
  34594. 0x89, 0xe8, 0x81, 0xa0, 0x1b, 0x95, 0xd9, 0x57,
  34595. 0xa3, 0x15, 0x3c, 0x0a, 0x5e, 0x0a, 0x1c, 0xcd,
  34596. 0x66, 0xb1, 0x82, 0x1a, 0x2b, 0x86, 0x32, 0x54,
  34597. 0x6e, 0x24, 0xc7, 0xcb, 0xbc, 0x4c, 0xb0, 0x88,
  34598. 0x08, 0xca, 0xc3, 0x7f, 0x7d, 0xa6, 0xb1, 0x6f,
  34599. 0x8a, 0xce, 0xd0, 0x52, 0xcd, 0xb2, 0x56, 0x49,
  34600. 0x48, 0xf1, 0xab, 0x0f, 0x76, 0x8a, 0x0d, 0x32,
  34601. 0x86, 0xcc, 0xc7, 0xc3, 0x74, 0x9c, 0x63, 0xc7,
  34602. 0x81, 0x53, 0x0f, 0xa1, 0xae, 0x67, 0x05, 0x42,
  34603. 0x85, 0x50, 0x04, 0xa6, 0x45, 0xb5, 0x22, 0x88,
  34604. 0x1e, 0xc1, 0x41, 0x2b, 0xda, 0xe3, 0x42, 0x08,
  34605. 0x5a, 0x9d, 0xd5, 0xf8, 0x12, 0x6a, 0xf9, 0x6b,
  34606. 0xbd, 0xb0, 0xc1, 0xaf, 0x69, 0xa1, 0x55, 0x62,
  34607. 0xcb, 0x2a, 0x15, 0x5a, 0x10, 0x03, 0x09, 0xd1,
  34608. 0xb6, 0x41, 0xd0, 0x8b, 0x2d, 0x4e, 0xd1, 0x7b,
  34609. 0xfb, 0xf0, 0xbc, 0x04, 0x26, 0x5f, 0x9b, 0x10,
  34610. 0xc1, 0x08, 0xf8, 0x50, 0x30, 0x95, 0x04, 0xd7,
  34611. 0x72, 0x81, 0x1b, 0xba, 0x8e, 0x2b, 0xe1, 0x62,
  34612. 0x49, 0xaa, 0x73, 0x7d, 0x87, 0x9f, 0xc7, 0xfb,
  34613. 0x25, 0x5e, 0xe7, 0xa6, 0xa0, 0xa7, 0x53, 0xbd,
  34614. 0x93, 0x74, 0x1c, 0x61, 0x65, 0x8e, 0xc0, 0x74,
  34615. 0xf6, 0xe0, 0x02, 0xb0, 0x19, 0x34, 0x57, 0x69,
  34616. 0x11, 0x3c, 0xc0, 0x13, 0xff, 0x74, 0x94, 0xba,
  34617. 0x83, 0x78, 0xb1, 0x1a, 0x17, 0x22, 0x60, 0xaa,
  34618. 0xa5, 0x34, 0x21, 0xbd, 0xe0, 0x3a, 0x35, 0x58,
  34619. 0x9d, 0x57, 0xe3, 0x22, 0xfe, 0xfa, 0x41, 0x00,
  34620. 0xa4, 0x74, 0x39, 0x26, 0xab, 0x7d, 0x62, 0x25,
  34621. 0x8b, 0x87, 0xb3, 0x1c, 0xcb, 0xb5, 0xe6, 0xb8,
  34622. 0x9c, 0xb1, 0x0b, 0x27, 0x1a, 0xa0, 0x5d, 0x99,
  34623. 0x4b, 0xb5, 0x70, 0x8b, 0x23, 0xab, 0x32, 0x7e,
  34624. 0xcb, 0x93, 0xc0, 0xf3, 0x15, 0x68, 0x69, 0xf0,
  34625. 0x88, 0x3d, 0xa2, 0x06, 0x4f, 0x79, 0x5e, 0x0e,
  34626. 0x2a, 0xb7, 0xd3, 0xc6, 0x4d, 0x61, 0xd2, 0x30,
  34627. 0x3f, 0xc3, 0xa2, 0x9e, 0x16, 0x19, 0x92, 0x3c,
  34628. 0xa8, 0x01, 0xe5, 0x9f, 0xd7, 0x52, 0xca, 0x6e,
  34629. 0x76, 0x49, 0xd3, 0x03, 0xc9, 0xd2, 0x07, 0x88,
  34630. 0xe1, 0x21, 0x46, 0x51, 0xb0, 0x69, 0x95, 0xeb,
  34631. 0x26, 0x0c, 0x92, 0x9a, 0x13, 0x44, 0xa8, 0x49,
  34632. 0xb2, 0x5c, 0xa0, 0xa0, 0x1f, 0x1e, 0xb5, 0x29,
  34633. 0x13, 0x68, 0x6b, 0xba, 0x61, 0x9e, 0x23, 0x71,
  34634. 0x44, 0x64, 0x03, 0x1a, 0x78, 0x43, 0x92, 0x87,
  34635. 0xfc, 0xa7, 0x8f, 0x4c, 0x04, 0x76, 0x22, 0x3e,
  34636. 0xea, 0x61, 0xb7, 0xf2, 0x5a, 0x7c, 0xe4, 0x2c,
  34637. 0xca, 0x90, 0x1b, 0x2a, 0xea, 0x12, 0x98, 0x17,
  34638. 0x89, 0x4b, 0xa3, 0x47, 0x08, 0x23, 0x85, 0x4f,
  34639. 0x3e, 0x5b, 0x28, 0xd8, 0x6b, 0xa9, 0x79, 0xe5,
  34640. 0x46, 0x71, 0x86, 0x2d, 0x90, 0x47, 0x0b, 0x1e,
  34641. 0x78, 0x38, 0x97, 0x2a, 0x81, 0xa4, 0x81, 0x07,
  34642. 0xd6, 0xac, 0x06, 0x11, 0x40, 0x6b, 0x21, 0xfb,
  34643. 0xcc, 0xe1, 0xdb, 0x77, 0x02, 0xea, 0x9d, 0xd6,
  34644. 0xba, 0x6e, 0x40, 0x52, 0x7b, 0x9d, 0xc6, 0x63,
  34645. 0xf3, 0xc9, 0x3b, 0xad, 0x05, 0x6d, 0xc2, 0x85,
  34646. 0x11, 0xf6, 0x6c, 0x3e, 0x0b, 0x92, 0x8d, 0xb8,
  34647. 0x87, 0x9d, 0x22, 0xc5, 0x92, 0x68, 0x5c, 0xc7,
  34648. 0x75, 0xa6, 0xcd, 0x57, 0x4a, 0xc3, 0xbc, 0xe3,
  34649. 0xb2, 0x75, 0x91, 0xc8, 0x21, 0x92, 0x90, 0x76,
  34650. 0x35, 0x8a, 0x22, 0x00, 0xb3, 0x77, 0x36, 0x5f,
  34651. 0x7e, 0xfb, 0x9e, 0x40, 0xc3, 0xbf, 0x0f, 0xf0,
  34652. 0x43, 0x29, 0x86, 0xae, 0x4b, 0xc1, 0xa2, 0x42,
  34653. 0xce, 0x99, 0x21, 0xaa, 0x9e, 0x22, 0x44, 0x88,
  34654. 0x19, 0x58, 0x5d, 0xea, 0x30, 0x8e, 0xb0, 0x39,
  34655. 0x50, 0xc8, 0xdd, 0x15, 0x2a, 0x45, 0x31, 0xaa,
  34656. 0xb5, 0x60, 0xd2, 0xfc, 0x7c, 0xa9, 0xa4, 0x0a,
  34657. 0xd8, 0xaf, 0x25, 0xad, 0x1d, 0xd0, 0x8c, 0x6d,
  34658. 0x79, 0xaf, 0xe4, 0xdd, 0x4d, 0x1e, 0xee, 0x5a,
  34659. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  34660. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  34661. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  34662. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  34663. };
  34664. #endif
  34665. #ifdef WOLFSSL_KYBER_ORIGINAL
  34666. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ct[] = {
  34667. 0xED, 0xF2, 0x41, 0x45, 0xE4, 0x3B, 0x4F, 0x6D,
  34668. 0xC6, 0xBF, 0x83, 0x32, 0xF5, 0x4E, 0x02, 0xCA,
  34669. 0xB0, 0x2D, 0xBF, 0x3B, 0x56, 0x05, 0xDD, 0xC9,
  34670. 0x0A, 0x15, 0xC8, 0x86, 0xAD, 0x3E, 0xD4, 0x89,
  34671. 0x46, 0x26, 0x99, 0xE4, 0xAB, 0xED, 0x44, 0x35,
  34672. 0x0B, 0xC3, 0x75, 0x7E, 0x26, 0x96, 0xFB, 0xFB,
  34673. 0x25, 0x34, 0x41, 0x2E, 0x8D, 0xD2, 0x01, 0xF1,
  34674. 0xE4, 0x54, 0x0A, 0x39, 0x70, 0xB0, 0x55, 0xFE,
  34675. 0x3B, 0x0B, 0xEC, 0x3A, 0x71, 0xF9, 0xE1, 0x15,
  34676. 0xB3, 0xF9, 0xF3, 0x91, 0x02, 0x06, 0x5B, 0x1C,
  34677. 0xCA, 0x83, 0x14, 0xDC, 0xC7, 0x95, 0xE3, 0xC0,
  34678. 0xE8, 0xFA, 0x98, 0xEE, 0x83, 0xCA, 0x66, 0x28,
  34679. 0x45, 0x70, 0x28, 0xA4, 0xD0, 0x9E, 0x83, 0x9E,
  34680. 0x55, 0x48, 0x62, 0xCF, 0x0B, 0x7B, 0xF5, 0x6C,
  34681. 0x5C, 0x0A, 0x82, 0x9E, 0x86, 0x57, 0x94, 0x79,
  34682. 0x45, 0xFE, 0x9C, 0x22, 0x56, 0x4F, 0xBA, 0xEB,
  34683. 0xC1, 0xB3, 0xAF, 0x35, 0x0D, 0x79, 0x55, 0x50,
  34684. 0x8A, 0x26, 0xD8, 0xA8, 0xEB, 0x54, 0x7B, 0x8B,
  34685. 0x1A, 0x2C, 0xF0, 0x3C, 0xCA, 0x1A, 0xAB, 0xCE,
  34686. 0x6C, 0x34, 0x97, 0x78, 0x3B, 0x64, 0x65, 0xBA,
  34687. 0x0B, 0x6E, 0x7A, 0xCB, 0xA8, 0x21, 0x19, 0x51,
  34688. 0x24, 0xAE, 0xF0, 0x9E, 0x62, 0x83, 0x82, 0xA1,
  34689. 0xF9, 0x14, 0x04, 0x3B, 0xE7, 0x09, 0x6E, 0x95,
  34690. 0x2C, 0xBC, 0x4F, 0xB4, 0xAF, 0xED, 0x13, 0x60,
  34691. 0x90, 0x46, 0x11, 0x7C, 0x01, 0x1F, 0xD7, 0x41,
  34692. 0xEE, 0x28, 0x6C, 0x83, 0x77, 0x16, 0x90, 0xF0,
  34693. 0xAE, 0xB5, 0x0D, 0xA0, 0xD7, 0x12, 0x85, 0xA1,
  34694. 0x79, 0xB2, 0x15, 0xC6, 0x03, 0x6D, 0xEB, 0x78,
  34695. 0x0F, 0x4D, 0x16, 0x76, 0x9F, 0x72, 0xDE, 0x16,
  34696. 0xFD, 0xAD, 0xAC, 0x73, 0xBE, 0xFA, 0x5B, 0xEF,
  34697. 0x89, 0x43, 0x19, 0x7F, 0x44, 0xC5, 0x95, 0x89,
  34698. 0xDC, 0x9F, 0x49, 0x73, 0xDE, 0x14, 0x50, 0xBA,
  34699. 0x1D, 0x0C, 0x32, 0x90, 0xD6, 0xB1, 0xD6, 0x83,
  34700. 0xF2, 0x94, 0xE7, 0x59, 0xC9, 0x54, 0xAB, 0xE8,
  34701. 0xA7, 0xDA, 0x5B, 0x10, 0x54, 0xFD, 0x6D, 0x21,
  34702. 0x32, 0x9B, 0x8E, 0x73, 0xD3, 0x75, 0x6A, 0xFD,
  34703. 0xA0, 0xDC, 0xB1, 0xFC, 0x8B, 0x15, 0x82, 0xD1,
  34704. 0xF9, 0x0C, 0xF2, 0x75, 0xA1, 0x02, 0xAB, 0xC6,
  34705. 0xAC, 0x69, 0x9D, 0xF0, 0xC5, 0x87, 0x0E, 0x50,
  34706. 0xA1, 0xF9, 0x89, 0xE4, 0xE6, 0x24, 0x1B, 0x60,
  34707. 0xAA, 0xA2, 0xEC, 0xF9, 0xE8, 0xE3, 0x3E, 0x0F,
  34708. 0xFC, 0xF4, 0x0F, 0xE8, 0x31, 0xE8, 0xFD, 0xC2,
  34709. 0xE8, 0x3B, 0x52, 0xCA, 0x7A, 0xB6, 0xD9, 0x3F,
  34710. 0x14, 0x6D, 0x29, 0xDC, 0xA5, 0x3C, 0x7D, 0xA1,
  34711. 0xDB, 0x4A, 0xC4, 0xF2, 0xDB, 0x39, 0xEA, 0x12,
  34712. 0x0D, 0x90, 0xFA, 0x60, 0xF4, 0xD4, 0x37, 0xC6,
  34713. 0xD0, 0x0E, 0xF4, 0x83, 0xBC, 0x94, 0xA3, 0x17,
  34714. 0x5C, 0xDA, 0x16, 0x3F, 0xC1, 0xC2, 0x82, 0x8B,
  34715. 0xE4, 0xDB, 0xD6, 0x43, 0x05, 0x07, 0xB5, 0x84,
  34716. 0xBB, 0x51, 0x77, 0xE1, 0x71, 0xB8, 0xDD, 0xA9,
  34717. 0xA4, 0x29, 0x3C, 0x32, 0x00, 0x29, 0x5C, 0x80,
  34718. 0x3A, 0x86, 0x5D, 0x6D, 0x21, 0x66, 0xF6, 0x6B,
  34719. 0xA5, 0x40, 0x1F, 0xB7, 0xA0, 0xE8, 0x53, 0x16,
  34720. 0x86, 0x00, 0xA2, 0x94, 0x84, 0x37, 0xE0, 0x36,
  34721. 0xE3, 0xBF, 0x19, 0xE1, 0x2F, 0xD3, 0xF2, 0xA2,
  34722. 0xB8, 0xB3, 0x43, 0xF7, 0x84, 0x24, 0x8E, 0x8D,
  34723. 0x68, 0x5E, 0xB0, 0xAF, 0xDE, 0x63, 0x15, 0x33,
  34724. 0x87, 0x30, 0xE7, 0xA1, 0x00, 0x1C, 0x27, 0xD8,
  34725. 0xD2, 0xA7, 0x6F, 0xA6, 0x9D, 0x15, 0x7B, 0xA1,
  34726. 0xAC, 0x7A, 0xD5, 0x6D, 0xA5, 0xA8, 0xC7, 0x0F,
  34727. 0xE4, 0xB5, 0xB8, 0xD7, 0x86, 0xDC, 0x6F, 0xC0,
  34728. 0x56, 0x6B, 0xA8, 0xE1, 0xB8, 0x81, 0x63, 0x34,
  34729. 0xD3, 0x2A, 0x3F, 0xB1, 0xCE, 0x7D, 0x4D, 0x5E,
  34730. 0x4C, 0x33, 0x2A, 0xF7, 0xB0, 0x03, 0xD0, 0x91,
  34731. 0x74, 0x1A, 0x3D, 0x5C, 0x96, 0x52, 0x92, 0x25,
  34732. 0x5D, 0xFF, 0x8E, 0xD2, 0xBB, 0xF1, 0xF9, 0x11,
  34733. 0x6B, 0xE5, 0x0C, 0x17, 0xB8, 0xE5, 0x48, 0x74,
  34734. 0x8A, 0xD4, 0xB2, 0xE9, 0x57, 0xBB, 0xD1, 0x95,
  34735. 0x34, 0x82, 0xA2, 0xE1, 0x71, 0x8C, 0xEC, 0x66,
  34736. 0xCD, 0x2C, 0x81, 0xF5, 0x72, 0xD5, 0x52, 0xB7,
  34737. 0x18, 0x78, 0x85, 0xE6, 0xB8, 0x94, 0x3D, 0x64,
  34738. 0x31, 0x41, 0x3C, 0x59, 0xEB, 0xB7, 0xE0, 0x36,
  34739. 0x04, 0x84, 0x90, 0xBE, 0x52, 0x89, 0xE9, 0x5B,
  34740. 0x20, 0xA8, 0x9E, 0x8B, 0x15, 0x9F, 0x61, 0xA9,
  34741. 0xA9, 0x88, 0x6E, 0x14, 0x75, 0x68, 0xF4, 0xC9,
  34742. 0x02, 0x1F, 0x36, 0x2F, 0x02, 0x68, 0x8A, 0x1C,
  34743. 0x8C, 0x3B, 0xB0, 0xD2, 0x40, 0x86, 0x88, 0x0E,
  34744. 0x55, 0xB6, 0xED, 0xB4, 0x3F, 0x37, 0x45, 0xD2,
  34745. 0xC1, 0x66, 0xDC, 0x1C, 0xB7, 0x43, 0xC7, 0x6F,
  34746. 0xE6, 0xBE, 0x52, 0x3A, 0x89, 0x3C, 0xC7, 0x64,
  34747. 0xD1, 0x64, 0x35, 0xC3, 0x78, 0x51, 0x25, 0x2A,
  34748. 0x81, 0xE2, 0xFF, 0xBA, 0x0F, 0x18, 0x97, 0x1A,
  34749. 0x3D, 0xEE, 0x37, 0xD4, 0x87, 0x7C, 0xB9, 0x28,
  34750. 0xE3, 0x6E, 0x52, 0x35, 0x03, 0x7A, 0x6B, 0x20,
  34751. 0x57, 0x89, 0x7D, 0x51, 0x8A, 0x5F, 0x0E, 0x34,
  34752. 0x8E, 0x3A, 0xB6, 0xD5, 0xB5, 0x2D, 0xFC, 0x60,
  34753. 0x75, 0x7F, 0x3B, 0x41, 0xA4, 0xFE, 0xC7, 0x82,
  34754. 0x8F, 0x1D, 0xEE, 0xAF, 0x45, 0x87, 0xCC, 0xC8,
  34755. 0xEA, 0xDF, 0x64, 0x7F, 0x4D, 0x20, 0x3B, 0x2F,
  34756. 0xAA, 0x05, 0xA6, 0x49, 0xB5, 0x82, 0x34, 0x0C,
  34757. 0xB4, 0xCA, 0xCE, 0x57, 0xA3, 0x07, 0x11, 0xBE,
  34758. 0x75, 0x2F, 0xAC, 0xF0, 0x22, 0x7D, 0x0A, 0x80,
  34759. 0xC4, 0x12, 0x84, 0x42, 0xDD, 0xC5, 0x44, 0xBE,
  34760. 0x80, 0x5B, 0x9C, 0xFE, 0x8F, 0xE9, 0xB1, 0x23,
  34761. 0x7C, 0x80, 0xF9, 0x67, 0x87, 0xCD, 0x92, 0x81,
  34762. 0xCC, 0xF2, 0x70, 0xC1, 0xAF, 0xC0, 0x67, 0x0D
  34763. };
  34764. #endif
  34765. #ifndef WOLFSSL_NO_ML_KEM
  34766. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ct[] = {
  34767. 0x11, 0x3d, 0xb2, 0xdd, 0x06, 0x87, 0x12, 0x35,
  34768. 0xe7, 0xbc, 0x36, 0xc9, 0xdc, 0xaa, 0x52, 0x8f,
  34769. 0xc2, 0x6c, 0xe5, 0xdb, 0x9e, 0xcc, 0x1d, 0xc3,
  34770. 0x2e, 0x95, 0x7d, 0x7f, 0xfb, 0x3c, 0x74, 0x29,
  34771. 0xd5, 0x0c, 0x3c, 0x35, 0x77, 0xa5, 0x15, 0xd3,
  34772. 0x18, 0x3a, 0x1b, 0x9d, 0x26, 0x7b, 0x93, 0x6b,
  34773. 0x7e, 0xb8, 0xf5, 0x43, 0xa3, 0xaf, 0xb7, 0x77,
  34774. 0x65, 0xca, 0x79, 0x38, 0xf7, 0x8a, 0xa6, 0x43,
  34775. 0x8c, 0xe8, 0x0a, 0x06, 0xa6, 0x96, 0x6d, 0x0d,
  34776. 0x06, 0xaf, 0x75, 0xba, 0x3e, 0x0d, 0x4f, 0x37,
  34777. 0xba, 0xc7, 0x33, 0x69, 0xf5, 0xa7, 0x29, 0xf7,
  34778. 0x3e, 0x85, 0x72, 0x9e, 0xdd, 0x97, 0xc8, 0xc2,
  34779. 0xa8, 0xcc, 0x26, 0x19, 0xe4, 0xcf, 0x7b, 0x60,
  34780. 0x91, 0x86, 0x9e, 0x90, 0x9f, 0xd4, 0x7d, 0x97,
  34781. 0x09, 0x14, 0x92, 0x04, 0xb0, 0x83, 0x7d, 0x8d,
  34782. 0x6f, 0x25, 0xd2, 0x67, 0x97, 0x2b, 0xe6, 0x3b,
  34783. 0xad, 0x34, 0xb5, 0x44, 0x52, 0x3c, 0x01, 0xc0,
  34784. 0x9d, 0xe3, 0xb1, 0xfa, 0x1d, 0x6b, 0x7b, 0x05,
  34785. 0x9e, 0xee, 0x9e, 0x65, 0x20, 0x62, 0xfe, 0x87,
  34786. 0x0f, 0x68, 0xc6, 0x80, 0x05, 0x33, 0x9e, 0xa1,
  34787. 0x81, 0xe1, 0xd0, 0x76, 0x7c, 0x15, 0x2a, 0xeb,
  34788. 0x38, 0xfa, 0xf0, 0xf9, 0x24, 0x5a, 0xe5, 0x9d,
  34789. 0x5c, 0xb0, 0xd2, 0xb7, 0xf2, 0x01, 0x22, 0x9e,
  34790. 0xd9, 0x70, 0x20, 0xd0, 0x62, 0x3a, 0x46, 0x10,
  34791. 0x0d, 0x09, 0x7b, 0x0c, 0xe1, 0x15, 0x4e, 0x02,
  34792. 0x8a, 0xe6, 0x19, 0x4d, 0xe0, 0x5d, 0xe9, 0x7d,
  34793. 0xd9, 0xae, 0x2e, 0x85, 0xff, 0xd2, 0x5d, 0x95,
  34794. 0xeb, 0x22, 0xef, 0xfe, 0x5b, 0xa1, 0x9c, 0xd8,
  34795. 0x07, 0xc5, 0x30, 0xeb, 0xaa, 0x9f, 0xe9, 0xf6,
  34796. 0x42, 0xcc, 0xac, 0xff, 0x47, 0xed, 0x15, 0xc2,
  34797. 0x2b, 0xfe, 0x30, 0x36, 0xeb, 0xf8, 0xad, 0x9c,
  34798. 0x8e, 0xd2, 0x32, 0x40, 0xae, 0xeb, 0xaa, 0x24,
  34799. 0xd1, 0x35, 0x75, 0x51, 0x00, 0xb8, 0x5e, 0xce,
  34800. 0xe3, 0x17, 0x49, 0x06, 0xe4, 0x63, 0x12, 0x06,
  34801. 0x2c, 0xee, 0xca, 0xc7, 0x5d, 0xe5, 0x27, 0x52,
  34802. 0x56, 0xc2, 0xc1, 0xa6, 0x53, 0xfd, 0x69, 0x15,
  34803. 0xb1, 0xb3, 0x0c, 0x8e, 0xcb, 0xb6, 0xfd, 0x42,
  34804. 0x80, 0x43, 0x74, 0x53, 0x17, 0x3a, 0x96, 0x23,
  34805. 0x8b, 0xc7, 0xd1, 0x08, 0x89, 0x23, 0x43, 0xe0,
  34806. 0x33, 0xbc, 0xd9, 0x8e, 0x43, 0x7e, 0x78, 0x9f,
  34807. 0xc5, 0xbe, 0xba, 0xa1, 0x2b, 0x26, 0x34, 0xb5,
  34808. 0x1e, 0xd0, 0xd5, 0x89, 0xf1, 0x11, 0x43, 0xa0,
  34809. 0x21, 0xd8, 0xec, 0xce, 0x59, 0x4f, 0xdd, 0x48,
  34810. 0xda, 0xe8, 0x4c, 0x80, 0x63, 0xef, 0x35, 0x81,
  34811. 0xbc, 0x37, 0x8a, 0x48, 0xda, 0x4e, 0x51, 0xbb,
  34812. 0x17, 0x5b, 0x0d, 0xb4, 0x7f, 0x9d, 0xcf, 0x99,
  34813. 0x31, 0x8c, 0x30, 0x22, 0x5c, 0xa7, 0xfa, 0x79,
  34814. 0xc8, 0x79, 0xbf, 0x1c, 0x93, 0x97, 0xb5, 0xcc,
  34815. 0xc5, 0xef, 0xad, 0x94, 0xc5, 0x00, 0xed, 0x7f,
  34816. 0x9f, 0x38, 0x5d, 0x08, 0x8e, 0x34, 0x93, 0x22,
  34817. 0x21, 0xfc, 0x0f, 0xc9, 0xaf, 0xe5, 0x1f, 0x68,
  34818. 0x75, 0x54, 0x81, 0x31, 0x69, 0x76, 0x95, 0x47,
  34819. 0x8a, 0xbd, 0xc8, 0x73, 0x6f, 0x10, 0x09, 0x5a,
  34820. 0x6b, 0x92, 0xec, 0x67, 0x9f, 0xe0, 0xe2, 0xae,
  34821. 0x5d, 0x8b, 0x33, 0x53, 0x55, 0xd5, 0x8d, 0xae,
  34822. 0x4d, 0x4f, 0x0b, 0x17, 0xaa, 0x5d, 0x1e, 0x52,
  34823. 0xf1, 0xd4, 0x55, 0x84, 0xa8, 0x92, 0xc3, 0x4c,
  34824. 0xe4, 0xb0, 0x4f, 0xcd, 0x00, 0x98, 0x1d, 0x51,
  34825. 0xca, 0xa1, 0x60, 0x64, 0xba, 0xd9, 0x2d, 0x01,
  34826. 0x9d, 0xc3, 0xad, 0xed, 0x91, 0x96, 0x84, 0x11,
  34827. 0x2b, 0x29, 0xda, 0xa2, 0x8b, 0x9d, 0xae, 0x09,
  34828. 0xb8, 0x6b, 0x21, 0xa9, 0x33, 0x10, 0xd5, 0xfb,
  34829. 0xc6, 0x52, 0x7b, 0x22, 0x4b, 0x9c, 0xe8, 0x7d,
  34830. 0x27, 0x82, 0xbb, 0x29, 0x46, 0x73, 0xf0, 0xec,
  34831. 0x06, 0xf2, 0x6b, 0x08, 0x76, 0x52, 0xa1, 0x8d,
  34832. 0x6a, 0xd7, 0xb1, 0xc9, 0x33, 0x03, 0xef, 0x05,
  34833. 0x61, 0xc0, 0xfc, 0x9c, 0xd4, 0xf6, 0x78, 0xf6,
  34834. 0x06, 0xf1, 0x92, 0xcf, 0x5d, 0xf9, 0x2b, 0x15,
  34835. 0x48, 0xf5, 0xdd, 0x26, 0x87, 0xed, 0xbe, 0xcc,
  34836. 0xfc, 0x6d, 0x4e, 0x9d, 0xe4, 0xbd, 0x50, 0xd3,
  34837. 0xc7, 0x4f, 0xb2, 0x75, 0xab, 0xd9, 0xb3, 0xe9,
  34838. 0x02, 0x77, 0xdb, 0x4a, 0x00, 0x69, 0xc0, 0xa2,
  34839. 0xa7, 0x13, 0x6f, 0x50, 0xce, 0xad, 0x4b, 0x2f,
  34840. 0x19, 0x95, 0xfa, 0xaf, 0x16, 0x80, 0x40, 0xe9,
  34841. 0xe4, 0xbe, 0xb7, 0xc5, 0x72, 0x20, 0x49, 0xd6,
  34842. 0xda, 0x64, 0x02, 0x99, 0x2f, 0xce, 0xa4, 0x50,
  34843. 0x97, 0xdf, 0x7c, 0x1c, 0x20, 0xfb, 0x06, 0x82,
  34844. 0x22, 0x00, 0x05, 0x76, 0x93, 0x5a, 0x08, 0x06,
  34845. 0x77, 0x34, 0x51, 0x92, 0x1f, 0x54, 0xc5, 0x5f,
  34846. 0xbf, 0x59, 0x3a, 0x4f, 0x14, 0x7c, 0x1f, 0xef,
  34847. 0x3a, 0xca, 0xf0, 0xcf, 0xa9, 0x07, 0xae, 0x48,
  34848. 0xc8, 0xc0, 0x63, 0x12, 0xcf, 0xdf, 0x51, 0x86,
  34849. 0x90, 0x4b, 0xec, 0x7f, 0xed, 0x4e, 0xd9, 0x33,
  34850. 0xc9, 0x25, 0x6a, 0xb0, 0x4c, 0xbf, 0xa0, 0x3a,
  34851. 0x96, 0x7c, 0x1f, 0x7e, 0xad, 0x4a, 0xb4, 0x0d,
  34852. 0xf1, 0x16, 0xbe, 0x66, 0x0e, 0x27, 0xca, 0x2b,
  34853. 0x54, 0x35, 0x26, 0xd4, 0xb9, 0x68, 0x4c, 0x31,
  34854. 0xe1, 0xe4, 0x23, 0x83, 0xb9, 0x69, 0xf8, 0x96,
  34855. 0x29, 0x9d, 0x71, 0x39, 0x0c, 0xc8, 0x5b, 0x70,
  34856. 0x32, 0x02, 0xac, 0xad, 0xec, 0xfa, 0x8c, 0x40,
  34857. 0x96, 0x5c, 0x08, 0xc5, 0x3b, 0x56, 0x71, 0xe0,
  34858. 0xd5, 0x94, 0x55, 0xbc, 0x5a, 0x85, 0x86, 0xc6,
  34859. 0x55, 0xdb, 0x8c, 0x2a, 0xde, 0x4b, 0xa8, 0x87,
  34860. 0x7f, 0x19, 0xb6, 0x00, 0x0e, 0x18, 0xf8, 0xfe,
  34861. 0xad, 0xda, 0x7e, 0xde, 0x8f, 0xe8, 0x0a, 0xa6,
  34862. 0x62, 0xd6, 0x94, 0xc6, 0xd8, 0xc3, 0x3b, 0x52
  34863. };
  34864. #endif
  34865. #ifdef WOLFSSL_KYBER_ORIGINAL
  34866. WOLFSSL_SMALL_STACK_STATIC const byte kyber512_ss[] = {
  34867. 0x0A, 0x69, 0x25, 0x67, 0x6F, 0x24, 0xB2, 0x2C,
  34868. 0x28, 0x6F, 0x4C, 0x81, 0xA4, 0x22, 0x4C, 0xEC,
  34869. 0x50, 0x6C, 0x9B, 0x25, 0x7D, 0x48, 0x0E, 0x02,
  34870. 0xE3, 0xB4, 0x9F, 0x44, 0xCA, 0xA3, 0x23, 0x7F
  34871. };
  34872. #endif
  34873. #ifndef WOLFSSL_NO_ML_KEM
  34874. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_512_ss[] = {
  34875. 0x31, 0x98, 0x39, 0xe8, 0x2a, 0xb6, 0xb2, 0x22,
  34876. 0xde, 0x7b, 0x61, 0x9e, 0x80, 0xda, 0x83, 0x91,
  34877. 0x52, 0x2b, 0xbb, 0x37, 0x67, 0x70, 0x18, 0x49,
  34878. 0x4a, 0x47, 0x42, 0xc5, 0x3f, 0x9a, 0xbf, 0xdf
  34879. };
  34880. #endif
  34881. #ifdef WOLFSSL_SMALL_STACK
  34882. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  34883. DYNAMIC_TYPE_TMP_BUFFER);
  34884. priv = (byte *)XMALLOC(KYBER512_PRIVATE_KEY_SIZE, HEAP_HINT,
  34885. DYNAMIC_TYPE_TMP_BUFFER);
  34886. pub = (byte *)XMALLOC(KYBER512_PUBLIC_KEY_SIZE, HEAP_HINT,
  34887. DYNAMIC_TYPE_TMP_BUFFER);
  34888. ct = (byte *)XMALLOC(KYBER512_CIPHER_TEXT_SIZE, HEAP_HINT,
  34889. DYNAMIC_TYPE_TMP_BUFFER);
  34890. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34891. DYNAMIC_TYPE_TMP_BUFFER);
  34892. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  34893. DYNAMIC_TYPE_TMP_BUFFER);
  34894. if (! (key && priv && pub && ct && ss && ss_dec))
  34895. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  34896. #endif
  34897. #ifdef WOLFSSL_KYBER_ORIGINAL
  34898. ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
  34899. if (ret != 0)
  34900. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34901. else
  34902. key_inited = 1;
  34903. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34904. sizeof(kyber512_rand));
  34905. if (ret != 0)
  34906. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34907. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
  34908. if (ret != 0)
  34909. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34910. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
  34911. if (ret != 0)
  34912. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34913. if (XMEMCMP(pub, kyber512_pk, sizeof(kyber512_pk)) != 0)
  34914. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34915. if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
  34916. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34917. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34918. sizeof(kyber512enc_rand));
  34919. if (ret != 0)
  34920. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34921. if (XMEMCMP(ct, kyber512_ct, sizeof(kyber512_ct)) != 0)
  34922. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34923. if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34924. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34925. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
  34926. if (ret != 0)
  34927. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34928. if (XMEMCMP(ss_dec, kyber512_ss, sizeof(kyber512_ss)) != 0)
  34929. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34930. #endif
  34931. #ifndef WOLFSSL_NO_ML_KEM
  34932. ret = wc_KyberKey_Init(WC_ML_KEM_512, key, HEAP_HINT, INVALID_DEVID);
  34933. if (ret != 0)
  34934. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34935. else
  34936. key_inited = 1;
  34937. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
  34938. sizeof(kyber512_rand));
  34939. if (ret != 0)
  34940. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34941. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_512_PUBLIC_KEY_SIZE);
  34942. if (ret != 0)
  34943. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34944. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  34945. WC_ML_KEM_512_PRIVATE_KEY_SIZE);
  34946. if (ret != 0)
  34947. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34948. if (XMEMCMP(pub, ml_kem_512_pk, sizeof(ml_kem_512_pk)) != 0)
  34949. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34950. if (XMEMCMP(priv, ml_kem_512_sk, sizeof(ml_kem_512_sk)) != 0)
  34951. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34952. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
  34953. sizeof(kyber512enc_rand));
  34954. if (ret != 0)
  34955. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34956. if (XMEMCMP(ct, ml_kem_512_ct, sizeof(ml_kem_512_ct)) != 0)
  34957. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34958. if (XMEMCMP(ss, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34959. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34960. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_512_ct));
  34961. if (ret != 0)
  34962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  34963. if (XMEMCMP(ss_dec, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
  34964. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  34965. #endif
  34966. out:
  34967. if (key_inited)
  34968. wc_KyberKey_Free(key);
  34969. #ifdef WOLFSSL_SMALL_STACK
  34970. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34971. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34972. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34973. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34974. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34975. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  34976. #endif
  34977. return ret;
  34978. }
  34979. #endif /* WOLFSSL_KYBER512 */
  34980. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  34981. static wc_test_ret_t kyber768_kat(void)
  34982. {
  34983. wc_test_ret_t ret;
  34984. #ifdef WOLFSSL_SMALL_STACK
  34985. KyberKey *key = NULL;
  34986. byte *priv = NULL;
  34987. byte *pub = NULL;
  34988. byte *ct = NULL;
  34989. byte *ss = NULL;
  34990. byte *ss_dec = NULL;
  34991. #else
  34992. KyberKey key[1];
  34993. byte priv[KYBER768_PRIVATE_KEY_SIZE];
  34994. byte pub[KYBER768_PUBLIC_KEY_SIZE];
  34995. byte ct[KYBER768_CIPHER_TEXT_SIZE];
  34996. byte ss[KYBER_SS_SZ];
  34997. byte ss_dec[KYBER_SS_SZ];
  34998. #endif
  34999. int key_inited = 0;
  35000. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_rand[] = {
  35001. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  35002. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  35003. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  35004. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  35005. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35006. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35007. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35008. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35009. };
  35010. WOLFSSL_SMALL_STACK_STATIC const byte kyber768enc_rand[] = {
  35011. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  35012. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  35013. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  35014. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  35015. };
  35016. #ifdef WOLFSSL_KYBER_ORIGINAL
  35017. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_pk[] = {
  35018. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35019. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35020. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35021. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35022. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35023. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35024. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35025. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35026. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35027. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35028. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35029. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35030. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35031. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35032. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35033. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35034. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35035. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35036. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35037. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35038. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35039. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35040. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35041. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35042. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35043. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35044. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35045. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35046. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35047. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35048. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35049. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35050. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35051. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35052. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35053. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35054. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35055. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35056. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35057. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35058. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35059. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35060. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35061. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35062. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35063. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35064. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35065. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35066. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35067. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35068. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35069. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35070. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35071. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35072. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35073. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35074. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35075. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35076. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35077. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35078. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35079. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35080. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35081. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35082. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35083. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35084. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35085. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35086. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35087. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35088. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35089. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35090. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35091. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35092. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35093. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35094. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35095. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35096. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35097. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35098. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35099. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35100. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35101. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35102. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35103. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35104. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35105. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35106. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35107. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35108. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35109. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35110. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35111. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35112. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35113. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35114. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35115. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35116. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35117. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35118. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35119. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35120. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35121. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35122. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35123. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35124. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35125. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35126. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35127. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35128. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35129. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35130. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35131. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35132. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35133. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35134. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35135. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35136. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35137. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35138. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35139. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35140. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35141. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35142. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35143. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35144. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35145. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35146. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35147. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35148. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35149. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35150. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35151. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35152. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35153. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35154. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35155. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35156. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35157. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35158. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35159. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35160. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35161. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35162. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35163. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35164. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35165. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  35166. };
  35167. #endif
  35168. #ifndef WOLFSSL_NO_ML_KEM
  35169. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_pk[] = {
  35170. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35171. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35172. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35173. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35174. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35175. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35176. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35177. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35178. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35179. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35180. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35181. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35182. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35183. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35184. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35185. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35186. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35187. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35188. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35189. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35190. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35191. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35192. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35193. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35194. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35195. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35196. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35197. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35198. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35199. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35200. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35201. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35202. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35203. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35204. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35205. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35206. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35207. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35208. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35209. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35210. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35211. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35212. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35213. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35214. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35215. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35216. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35217. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35218. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35219. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35220. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35221. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35222. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35223. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35224. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35225. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35226. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35227. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35228. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35229. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35230. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35231. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35232. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35233. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35234. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35235. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35236. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35237. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35238. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35239. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35240. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35241. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35242. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35243. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35244. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35245. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35246. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35247. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35248. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35249. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35250. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35251. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35252. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35253. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35254. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35255. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35256. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35257. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35258. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35259. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35260. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35261. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35262. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35263. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35264. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35265. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35266. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35267. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35268. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35269. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35270. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35271. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35272. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35273. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35274. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35275. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35276. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35277. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35278. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35279. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35280. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35281. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35282. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35283. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35284. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35285. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35286. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35287. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35288. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35289. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35290. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35291. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35292. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35293. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35294. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35295. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35296. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35297. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35298. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35299. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35300. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35301. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35302. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35303. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35304. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35305. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35306. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35307. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35308. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35309. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35310. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35311. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35312. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35313. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35314. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35315. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35316. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35317. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28
  35318. };
  35319. #endif
  35320. #ifdef WOLFSSL_KYBER_ORIGINAL
  35321. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_sk[] = {
  35322. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  35323. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  35324. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  35325. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  35326. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  35327. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  35328. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  35329. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  35330. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  35331. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  35332. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  35333. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  35334. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  35335. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  35336. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  35337. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  35338. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  35339. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  35340. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  35341. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  35342. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  35343. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  35344. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  35345. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  35346. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  35347. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  35348. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  35349. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  35350. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  35351. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  35352. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  35353. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  35354. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  35355. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  35356. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  35357. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  35358. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  35359. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  35360. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  35361. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  35362. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  35363. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  35364. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  35365. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  35366. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  35367. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  35368. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  35369. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  35370. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  35371. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  35372. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  35373. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  35374. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  35375. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  35376. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  35377. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  35378. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  35379. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  35380. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  35381. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  35382. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  35383. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  35384. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  35385. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  35386. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  35387. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  35388. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  35389. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  35390. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  35391. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  35392. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  35393. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  35394. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  35395. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  35396. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  35397. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  35398. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  35399. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  35400. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  35401. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  35402. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  35403. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  35404. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  35405. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  35406. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  35407. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  35408. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  35409. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  35410. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  35411. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  35412. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  35413. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  35414. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  35415. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  35416. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  35417. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  35418. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  35419. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  35420. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  35421. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  35422. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  35423. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  35424. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  35425. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  35426. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  35427. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  35428. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  35429. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  35430. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  35431. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  35432. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  35433. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  35434. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  35435. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  35436. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  35437. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  35438. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  35439. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  35440. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  35441. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  35442. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  35443. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  35444. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  35445. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  35446. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  35447. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  35448. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  35449. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  35450. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  35451. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  35452. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  35453. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  35454. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  35455. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  35456. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  35457. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  35458. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  35459. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  35460. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  35461. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  35462. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  35463. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  35464. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  35465. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  35466. 0xA7, 0x2C, 0x2D, 0x9C, 0x84, 0x3E, 0xE9, 0xF8,
  35467. 0x31, 0x3E, 0xCC, 0x7F, 0x86, 0xD6, 0x29, 0x4D,
  35468. 0x59, 0x15, 0x9D, 0x9A, 0x87, 0x9A, 0x54, 0x2E,
  35469. 0x26, 0x09, 0x22, 0xAD, 0xF9, 0x99, 0x05, 0x1C,
  35470. 0xC4, 0x52, 0x00, 0xC9, 0xFF, 0xDB, 0x60, 0x44,
  35471. 0x9C, 0x49, 0x46, 0x59, 0x79, 0x27, 0x23, 0x67,
  35472. 0xC0, 0x83, 0xA7, 0xD6, 0x26, 0x7A, 0x3E, 0xD7,
  35473. 0xA7, 0xFD, 0x47, 0x95, 0x7C, 0x21, 0x93, 0x27,
  35474. 0xF7, 0xCA, 0x73, 0xA4, 0x00, 0x7E, 0x16, 0x27,
  35475. 0xF0, 0x0B, 0x11, 0xCC, 0x80, 0x57, 0x3C, 0x15,
  35476. 0xAE, 0xE6, 0x64, 0x0F, 0xB8, 0x56, 0x2D, 0xFA,
  35477. 0x6B, 0x24, 0x0C, 0xA0, 0xAD, 0x35, 0x1A, 0xC4,
  35478. 0xAC, 0x15, 0x5B, 0x96, 0xC1, 0x4C, 0x8A, 0xB1,
  35479. 0x3D, 0xD2, 0x62, 0xCD, 0xFD, 0x51, 0xC4, 0xBB,
  35480. 0x55, 0x72, 0xFD, 0x61, 0x65, 0x53, 0xD1, 0x7B,
  35481. 0xDD, 0x43, 0x0A, 0xCB, 0xEA, 0x3E, 0x95, 0xF0,
  35482. 0xB6, 0x98, 0xD6, 0x69, 0x90, 0xAB, 0x51, 0xE5,
  35483. 0xD0, 0x37, 0x83, 0xA8, 0xB3, 0xD2, 0x78, 0xA5,
  35484. 0x72, 0x04, 0x54, 0xCF, 0x96, 0x95, 0xCF, 0xDC,
  35485. 0xA0, 0x84, 0x85, 0xBA, 0x09, 0x9C, 0x51, 0xCD,
  35486. 0x92, 0xA7, 0xEA, 0x75, 0x87, 0xC1, 0xD1, 0x5C,
  35487. 0x28, 0xE6, 0x09, 0xA8, 0x18, 0x52, 0x60, 0x1B,
  35488. 0x06, 0x04, 0x01, 0x06, 0x79, 0xAA, 0x48, 0x2D,
  35489. 0x51, 0x26, 0x1E, 0xC3, 0x6E, 0x36, 0xB8, 0x71,
  35490. 0x96, 0x76, 0x21, 0x7F, 0xD7, 0x4C, 0x54, 0x78,
  35491. 0x64, 0x88, 0xF4, 0xB4, 0x96, 0x9C, 0x05, 0xA8,
  35492. 0xBA, 0x27, 0xCA, 0x3A, 0x77, 0xCC, 0xE7, 0x3B,
  35493. 0x96, 0x59, 0x23, 0xCA, 0x55, 0x4E, 0x42, 0x2B,
  35494. 0x9B, 0x61, 0xF4, 0x75, 0x46, 0x41, 0x60, 0x8A,
  35495. 0xC1, 0x6C, 0x9B, 0x85, 0x87, 0xA3, 0x2C, 0x1C,
  35496. 0x5D, 0xD7, 0x88, 0xF8, 0x8B, 0x36, 0xB7, 0x17,
  35497. 0xA4, 0x69, 0x65, 0x63, 0x5D, 0xEB, 0x67, 0xF4,
  35498. 0x5B, 0x12, 0x9B, 0x99, 0x07, 0x09, 0x09, 0xC9,
  35499. 0x3E, 0xB8, 0x0B, 0x42, 0xC2, 0xB3, 0xF3, 0xF7,
  35500. 0x03, 0x43, 0xA7, 0xCF, 0x37, 0xE8, 0x52, 0x0E,
  35501. 0x7B, 0xCF, 0xC4, 0x16, 0xAC, 0xA4, 0xF1, 0x8C,
  35502. 0x79, 0x81, 0x26, 0x2B, 0xA2, 0xBF, 0xC7, 0x56,
  35503. 0xAE, 0x03, 0x27, 0x8F, 0x0E, 0xC6, 0x6D, 0xC2,
  35504. 0x05, 0x76, 0x96, 0x82, 0x4B, 0xA6, 0x76, 0x98,
  35505. 0x65, 0xA6, 0x01, 0xD7, 0x14, 0x8E, 0xF6, 0xF5,
  35506. 0x4E, 0x5A, 0xF5, 0x68, 0x6A, 0xA2, 0x90, 0x6F,
  35507. 0x99, 0x4C, 0xE3, 0x8A, 0x5E, 0x0B, 0x93, 0x8F,
  35508. 0x23, 0x90, 0x07, 0x00, 0x30, 0x22, 0xC0, 0x33,
  35509. 0x92, 0xDF, 0x34, 0x01, 0xB1, 0xE4, 0xA3, 0xA7,
  35510. 0xEB, 0xC6, 0x16, 0x14, 0x49, 0xF7, 0x33, 0x74,
  35511. 0xC8, 0xB0, 0x14, 0x03, 0x69, 0x34, 0x3D, 0x92,
  35512. 0x95, 0xFD, 0xF5, 0x11, 0x84, 0x5C, 0x4A, 0x46,
  35513. 0xEB, 0xAA, 0xB6, 0xCA, 0x54, 0x92, 0xF6, 0x80,
  35514. 0x0B, 0x98, 0xC0, 0xCC, 0x80, 0x36, 0x53, 0xA4,
  35515. 0xB1, 0xD6, 0xE6, 0xAA, 0xED, 0x19, 0x32, 0xBA,
  35516. 0xCC, 0x5F, 0xEF, 0xAA, 0x81, 0x8B, 0xA5, 0x02,
  35517. 0x85, 0x9B, 0xA5, 0x49, 0x4C, 0x5F, 0x54, 0x02,
  35518. 0xC8, 0x53, 0x6A, 0x9C, 0x4C, 0x18, 0x88, 0x15,
  35519. 0x06, 0x17, 0xF8, 0x00, 0x98, 0xF6, 0xB2, 0xA9,
  35520. 0x9C, 0x39, 0xBC, 0x5D, 0xC7, 0xCF, 0x3B, 0x59,
  35521. 0x00, 0xA2, 0x13, 0x29, 0xAB, 0x59, 0x05, 0x3A,
  35522. 0xBA, 0xA6, 0x4E, 0xD1, 0x63, 0xE8, 0x59, 0xA8,
  35523. 0xB3, 0xB3, 0xCA, 0x33, 0x59, 0xB7, 0x50, 0xCC,
  35524. 0xC3, 0xE7, 0x10, 0xC7, 0xAC, 0x43, 0xC8, 0x19,
  35525. 0x1C, 0xB5, 0xD6, 0x88, 0x70, 0xC0, 0x63, 0x91,
  35526. 0xC0, 0xCB, 0x8A, 0xEC, 0x72, 0xB8, 0x97, 0xAC,
  35527. 0x6B, 0xE7, 0xFB, 0xAA, 0xCC, 0x67, 0x6E, 0xD6,
  35528. 0x63, 0x14, 0xC8, 0x36, 0x30, 0xE8, 0x94, 0x48,
  35529. 0xC8, 0x8A, 0x1D, 0xF0, 0x4A, 0xCE, 0xB2, 0x3A,
  35530. 0xBF, 0x2E, 0x40, 0x9E, 0xF3, 0x33, 0xC6, 0x22,
  35531. 0x28, 0x9C, 0x18, 0xA2, 0x13, 0x4E, 0x65, 0x0C,
  35532. 0x45, 0x25, 0x7E, 0x47, 0x47, 0x5F, 0xA3, 0x3A,
  35533. 0xA5, 0x37, 0xA5, 0xA8, 0xF7, 0x68, 0x02, 0x14,
  35534. 0x71, 0x6C, 0x50, 0xD4, 0x70, 0xE3, 0x28, 0x49,
  35535. 0x63, 0xCA, 0x64, 0xF5, 0x46, 0x77, 0xAE, 0xC5,
  35536. 0x4B, 0x52, 0x72, 0x16, 0x2B, 0xF5, 0x2B, 0xC8,
  35537. 0x14, 0x2E, 0x1D, 0x41, 0x83, 0xFC, 0x01, 0x74,
  35538. 0x54, 0xA6, 0xB5, 0xA4, 0x96, 0x83, 0x17, 0x59,
  35539. 0x06, 0x40, 0x24, 0x74, 0x59, 0x78, 0xCB, 0xD5,
  35540. 0x1A, 0x6C, 0xED, 0xC8, 0x95, 0x5D, 0xE4, 0xCC,
  35541. 0x6D, 0x36, 0x36, 0x70, 0xA4, 0x74, 0x66, 0xE8,
  35542. 0x2B, 0xE5, 0xC2, 0x36, 0x03, 0xA1, 0x7B, 0xF2,
  35543. 0x2A, 0xCD, 0xB7, 0xCC, 0x98, 0x4A, 0xF0, 0x8C,
  35544. 0x87, 0xE1, 0x4E, 0x27, 0x75, 0x3C, 0xF5, 0x87,
  35545. 0xA8, 0xEC, 0x34, 0x47, 0xE6, 0x2C, 0x64, 0x9E,
  35546. 0x88, 0x7A, 0x67, 0xC3, 0x6C, 0x9C, 0xE9, 0x87,
  35547. 0x21, 0xB6, 0x97, 0x21, 0x32, 0x75, 0x64, 0x6B,
  35548. 0x19, 0x4F, 0x36, 0x75, 0x86, 0x73, 0xA8, 0xED,
  35549. 0x11, 0x28, 0x44, 0x55, 0xAF, 0xC7, 0xA8, 0x52,
  35550. 0x9F, 0x69, 0xC9, 0x7A, 0x3C, 0x2D, 0x7B, 0x8C,
  35551. 0x63, 0x6C, 0x0B, 0xA5, 0x56, 0x14, 0xB7, 0x68,
  35552. 0xE6, 0x24, 0xE7, 0x12, 0x93, 0x0F, 0x77, 0x61,
  35553. 0x69, 0xB0, 0x17, 0x15, 0x72, 0x53, 0x51, 0xBC,
  35554. 0x74, 0xB4, 0x73, 0x95, 0xED, 0x52, 0xB2, 0x5A,
  35555. 0x13, 0x13, 0xC9, 0x51, 0x64, 0x81, 0x4C, 0x34,
  35556. 0xC9, 0x79, 0xCB, 0xDF, 0xAB, 0x85, 0x95, 0x46,
  35557. 0x62, 0xCA, 0xB4, 0x85, 0xE7, 0x50, 0x87, 0xA9,
  35558. 0x8C, 0xC7, 0x4B, 0xB8, 0x2C, 0xA2, 0xD1, 0xB5,
  35559. 0xBF, 0x28, 0x03, 0x23, 0x84, 0x80, 0x63, 0x8C,
  35560. 0x40, 0xE9, 0x0B, 0x43, 0xC7, 0x46, 0x0E, 0x7A,
  35561. 0xA9, 0x17, 0xF0, 0x10, 0x15, 0x1F, 0xAB, 0x11,
  35562. 0x69, 0x98, 0x7B, 0x37, 0x2A, 0xBB, 0x59, 0x27,
  35563. 0x1F, 0x70, 0x06, 0xC2, 0x4E, 0x60, 0x23, 0x6B,
  35564. 0x84, 0xB9, 0xDD, 0xD6, 0x00, 0x62, 0x37, 0x04,
  35565. 0x25, 0x46, 0x17, 0xFB, 0x49, 0x8D, 0x89, 0xE5,
  35566. 0x8B, 0x03, 0x68, 0xBC, 0xB2, 0x10, 0x3E, 0x79,
  35567. 0x35, 0x3E, 0xB5, 0x87, 0x86, 0x0C, 0x14, 0x22,
  35568. 0xE4, 0x76, 0x16, 0x2E, 0x42, 0x5B, 0xC2, 0x38,
  35569. 0x1D, 0xB8, 0x2C, 0x65, 0x92, 0x73, 0x7E, 0x1D,
  35570. 0xD6, 0x02, 0x86, 0x4B, 0x01, 0x67, 0xA7, 0x1E,
  35571. 0xC1, 0xF2, 0x23, 0x30, 0x5C, 0x02, 0xFE, 0x25,
  35572. 0x05, 0x2A, 0xF2, 0xB3, 0xB5, 0xA5, 0x5A, 0x0D,
  35573. 0x7A, 0x20, 0x22, 0xD9, 0xA7, 0x98, 0xDC, 0x0C,
  35574. 0x58, 0x74, 0xA9, 0x87, 0x02, 0xAA, 0xF4, 0x05,
  35575. 0x4C, 0x5D, 0x80, 0x33, 0x8A, 0x52, 0x48, 0xB5,
  35576. 0xB7, 0xBD, 0x09, 0xC5, 0x3B, 0x5E, 0x2A, 0x08,
  35577. 0x4B, 0x04, 0x7D, 0x27, 0x7A, 0x86, 0x1B, 0x1A,
  35578. 0x73, 0xBB, 0x51, 0x48, 0x8D, 0xE0, 0x4E, 0xF5,
  35579. 0x73, 0xC8, 0x52, 0x30, 0xA0, 0x47, 0x0B, 0x73,
  35580. 0x17, 0x5C, 0x9F, 0xA5, 0x05, 0x94, 0xF6, 0x6A,
  35581. 0x5F, 0x50, 0xB4, 0x15, 0x00, 0x54, 0xC9, 0x3B,
  35582. 0x68, 0x18, 0x6F, 0x8B, 0x5C, 0xBC, 0x49, 0x31,
  35583. 0x6C, 0x85, 0x48, 0xA6, 0x42, 0xB2, 0xB3, 0x6A,
  35584. 0x1D, 0x45, 0x4C, 0x74, 0x89, 0xAC, 0x33, 0xB2,
  35585. 0xD2, 0xCE, 0x66, 0x68, 0x09, 0x67, 0x82, 0xA2,
  35586. 0xC1, 0xE0, 0x86, 0x6D, 0x21, 0xA6, 0x5E, 0x16,
  35587. 0xB5, 0x85, 0xE7, 0xAF, 0x86, 0x18, 0xBD, 0xF3,
  35588. 0x18, 0x4C, 0x19, 0x86, 0x87, 0x85, 0x08, 0x91,
  35589. 0x72, 0x77, 0xB9, 0x3E, 0x10, 0x70, 0x6B, 0x16,
  35590. 0x14, 0x97, 0x2B, 0x2A, 0x94, 0xC7, 0x31, 0x0F,
  35591. 0xE9, 0xC7, 0x08, 0xC2, 0x31, 0xA1, 0xA8, 0xAC,
  35592. 0x8D, 0x93, 0x14, 0xA5, 0x29, 0xA9, 0x7F, 0x46,
  35593. 0x9B, 0xF6, 0x49, 0x62, 0xD8, 0x20, 0x64, 0x84,
  35594. 0x43, 0x09, 0x9A, 0x07, 0x6D, 0x55, 0xD4, 0xCE,
  35595. 0xA8, 0x24, 0xA5, 0x83, 0x04, 0x84, 0x4F, 0x99,
  35596. 0x49, 0x7C, 0x10, 0xA2, 0x51, 0x48, 0x61, 0x8A,
  35597. 0x31, 0x5D, 0x72, 0xCA, 0x85, 0x7D, 0x1B, 0x04,
  35598. 0xD5, 0x75, 0xB9, 0x4F, 0x85, 0xC0, 0x1D, 0x19,
  35599. 0xBE, 0xF2, 0x11, 0xBF, 0x0A, 0xA3, 0x36, 0x2E,
  35600. 0x70, 0x41, 0xFD, 0x16, 0x59, 0x6D, 0x80, 0x8E,
  35601. 0x86, 0x7B, 0x44, 0xC4, 0xC0, 0x0D, 0x1C, 0xDA,
  35602. 0x34, 0x18, 0x96, 0x77, 0x17, 0xF1, 0x47, 0xD0,
  35603. 0xEB, 0x21, 0xB4, 0x2A, 0xAE, 0xE7, 0x4A, 0xC3,
  35604. 0x5D, 0x0B, 0x92, 0x41, 0x4B, 0x95, 0x85, 0x31,
  35605. 0xAA, 0xDF, 0x46, 0x3E, 0xC6, 0x30, 0x5A, 0xE5,
  35606. 0xEC, 0xAF, 0x79, 0x17, 0x40, 0x02, 0xF2, 0x6D,
  35607. 0xDE, 0xCC, 0x81, 0x3B, 0xF3, 0x26, 0x72, 0xE8,
  35608. 0x52, 0x9D, 0x95, 0xA4, 0xE7, 0x30, 0xA7, 0xAB,
  35609. 0x4A, 0x3E, 0x8F, 0x8A, 0x8A, 0xF9, 0x79, 0xA6,
  35610. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  35611. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  35612. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  35613. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  35614. 0xD4, 0xEC, 0x14, 0x3B, 0x50, 0xF0, 0x14, 0x23,
  35615. 0xB1, 0x77, 0x89, 0x5E, 0xDE, 0xE2, 0x2B, 0xB7,
  35616. 0x39, 0xF6, 0x47, 0xEC, 0xF8, 0x5F, 0x50, 0xBC,
  35617. 0x25, 0xEF, 0x7B, 0x5A, 0x72, 0x5D, 0xEE, 0x86,
  35618. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  35619. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  35620. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  35621. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  35622. };
  35623. #endif
  35624. #ifndef WOLFSSL_NO_ML_KEM
  35625. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_sk[] = {
  35626. 0xda, 0x0a, 0xc7, 0xb6, 0x60, 0x40, 0x4e, 0x61,
  35627. 0x3a, 0xa1, 0xf9, 0x80, 0x38, 0x0c, 0xb3, 0x6d,
  35628. 0xba, 0x18, 0xd2, 0x32, 0x56, 0xc7, 0x26, 0x7a,
  35629. 0x00, 0xa6, 0x7b, 0xa6, 0xc2, 0xa2, 0xb1, 0x4c,
  35630. 0x41, 0x42, 0x39, 0x66, 0x2f, 0x68, 0xbd, 0x44,
  35631. 0x6c, 0x8e, 0xfd, 0xf3, 0x66, 0x56, 0xa0, 0x89,
  35632. 0x1a, 0x3c, 0xc6, 0x23, 0xfc, 0x68, 0xb6, 0x57,
  35633. 0x2f, 0x7b, 0x29, 0xa6, 0xde, 0x12, 0x80, 0x14,
  35634. 0x41, 0x1e, 0xe4, 0x19, 0x06, 0xd0, 0x80, 0x71,
  35635. 0xf9, 0x48, 0x56, 0xe3, 0x6a, 0x83, 0x2b, 0x40,
  35636. 0x33, 0x8d, 0x74, 0x35, 0x16, 0x65, 0x9b, 0xd2,
  35637. 0x58, 0x79, 0xc0, 0x07, 0xa5, 0x2b, 0xc9, 0x58,
  35638. 0x6f, 0x79, 0x87, 0x6a, 0xfa, 0xc6, 0xc9, 0xa3,
  35639. 0x0d, 0x8f, 0xac, 0x24, 0x3b, 0xd2, 0x24, 0x25,
  35640. 0xd6, 0xad, 0xce, 0x42, 0xab, 0x7e, 0xd3, 0x90,
  35641. 0x14, 0x75, 0x7a, 0x95, 0x8b, 0xc8, 0xa7, 0x45,
  35642. 0x65, 0xf0, 0x19, 0x23, 0x4f, 0xf0, 0x4b, 0x34,
  35643. 0x89, 0x3e, 0xd6, 0xd0, 0x55, 0x01, 0xc3, 0x72,
  35644. 0x55, 0x23, 0x9a, 0xae, 0x2a, 0xc1, 0x9f, 0x8c,
  35645. 0x75, 0xac, 0x59, 0x00, 0xda, 0xe8, 0x30, 0x0d,
  35646. 0xbb, 0xa7, 0x10, 0xdc, 0x2c, 0xaa, 0xe1, 0xbc,
  35647. 0xa3, 0xa3, 0x8c, 0x58, 0x34, 0x2b, 0x28, 0x6b,
  35648. 0x85, 0x18, 0xf1, 0x36, 0xad, 0x15, 0xb9, 0xf7,
  35649. 0xbc, 0xbb, 0x06, 0xa5, 0x60, 0x7d, 0xb3, 0x75,
  35650. 0xdb, 0xe9, 0x76, 0x45, 0x7c, 0x26, 0xc6, 0x59,
  35651. 0x82, 0x57, 0x53, 0x1b, 0x2c, 0xfb, 0x6e, 0xe7,
  35652. 0xf5, 0x15, 0x91, 0x84, 0x08, 0x04, 0xc3, 0x83,
  35653. 0x88, 0x37, 0x6c, 0x27, 0x14, 0x84, 0x13, 0xda,
  35654. 0x9e, 0x92, 0x92, 0x0b, 0xfd, 0x9a, 0x06, 0x9e,
  35655. 0x01, 0x8b, 0xd2, 0x72, 0x05, 0x3d, 0xa8, 0x77,
  35656. 0x5c, 0x0b, 0x73, 0x9f, 0x76, 0x1d, 0xb2, 0x10,
  35657. 0x7c, 0xf3, 0x5a, 0x43, 0x4d, 0x69, 0xb0, 0x7e,
  35658. 0x5b, 0xcd, 0xb8, 0x74, 0x34, 0x13, 0x8b, 0x0c,
  35659. 0xb5, 0x56, 0x76, 0x1b, 0xa5, 0x22, 0xa5, 0x74,
  35660. 0x7b, 0x28, 0x74, 0x7d, 0x80, 0xeb, 0x9d, 0x6c,
  35661. 0xc6, 0x73, 0xbe, 0xe5, 0x76, 0x93, 0x77, 0xb9,
  35662. 0x96, 0xd3, 0x6c, 0xeb, 0x0c, 0x0c, 0x7e, 0xd9,
  35663. 0xa6, 0x58, 0x53, 0x33, 0x24, 0x86, 0x9c, 0x18,
  35664. 0xa1, 0xa3, 0x6f, 0x31, 0x47, 0x0f, 0x14, 0xc5,
  35665. 0xae, 0x49, 0xab, 0x07, 0x05, 0x07, 0xf8, 0x24,
  35666. 0x9c, 0xe4, 0x04, 0xb4, 0x9c, 0x0a, 0x8c, 0x3e,
  35667. 0xe4, 0x2f, 0xea, 0x96, 0x31, 0xfa, 0x1a, 0x0d,
  35668. 0x10, 0xd8, 0x6b, 0x93, 0xf9, 0x86, 0xe0, 0xe3,
  35669. 0xa8, 0x2e, 0x70, 0x3b, 0x74, 0xe5, 0xae, 0x61,
  35670. 0x01, 0x24, 0x24, 0x21, 0xa8, 0x9a, 0xa0, 0x7f,
  35671. 0xe6, 0x85, 0x88, 0x46, 0x0b, 0xaa, 0x36, 0x87,
  35672. 0x86, 0x48, 0x6a, 0x72, 0xe4, 0xf2, 0x4d, 0x2d,
  35673. 0xd7, 0x6c, 0xfc, 0x03, 0xb6, 0x94, 0xa5, 0xba,
  35674. 0x91, 0xa7, 0x55, 0xa0, 0xb9, 0x8f, 0x3b, 0xf9,
  35675. 0x33, 0x07, 0xc0, 0xab, 0x64, 0x63, 0x9a, 0xea,
  35676. 0x7a, 0x64, 0x98, 0xa3, 0xc3, 0xdd, 0xc5, 0x71,
  35677. 0x14, 0x1a, 0xbc, 0xa4, 0x67, 0x8c, 0xd2, 0xe2,
  35678. 0xb8, 0x57, 0xfb, 0x88, 0xf6, 0x00, 0xca, 0xa5,
  35679. 0x96, 0xb4, 0x4b, 0xc4, 0x22, 0x25, 0x0b, 0x28,
  35680. 0x19, 0xe0, 0x51, 0x5f, 0x04, 0x72, 0x39, 0x18,
  35681. 0x53, 0x70, 0x0b, 0x01, 0xef, 0xf9, 0x45, 0x3f,
  35682. 0xd1, 0x18, 0x76, 0xb7, 0xc7, 0x59, 0xa0, 0x7d,
  35683. 0xd8, 0x45, 0xca, 0xba, 0x45, 0x55, 0x26, 0x4a,
  35684. 0x82, 0x76, 0x51, 0x93, 0xfd, 0xf8, 0x1b, 0x62,
  35685. 0x0a, 0x1e, 0x1f, 0x92, 0x3f, 0xb2, 0x44, 0x42,
  35686. 0xcd, 0x1c, 0xbe, 0x94, 0x17, 0x50, 0x03, 0xec,
  35687. 0x06, 0xce, 0x77, 0xa3, 0xc6, 0x44, 0x93, 0xc1,
  35688. 0x99, 0x98, 0x7a, 0x30, 0x0c, 0x95, 0xc5, 0x3c,
  35689. 0x00, 0x89, 0xb5, 0xd6, 0x5c, 0x92, 0xea, 0x97,
  35690. 0x1b, 0x2f, 0xfa, 0x93, 0xb5, 0x2a, 0x46, 0x1e,
  35691. 0xa2, 0xac, 0x8c, 0x19, 0x9c, 0x2f, 0x4c, 0x2b,
  35692. 0x70, 0x42, 0x97, 0xce, 0x3c, 0x39, 0x49, 0xe0,
  35693. 0x73, 0x5e, 0xa8, 0xa1, 0x4a, 0xa5, 0x9e, 0x8d,
  35694. 0xec, 0x0c, 0x87, 0x83, 0x99, 0xff, 0x70, 0x74,
  35695. 0x7a, 0xb2, 0x44, 0xce, 0x46, 0xb5, 0xf2, 0x23,
  35696. 0x04, 0x73, 0x32, 0x3d, 0x25, 0xc6, 0x6f, 0xe6,
  35697. 0xb4, 0x19, 0xb1, 0xf4, 0xa1, 0x12, 0xe5, 0x21,
  35698. 0x40, 0x35, 0x25, 0x6b, 0xc4, 0x3f, 0xfd, 0x2b,
  35699. 0x6b, 0x7b, 0x37, 0x87, 0x69, 0xa6, 0xb4, 0x70,
  35700. 0x00, 0xbf, 0xb6, 0x35, 0x7d, 0x45, 0x81, 0x4b,
  35701. 0xae, 0xf3, 0x85, 0x7d, 0x37, 0x9e, 0x2f, 0xb8,
  35702. 0xb5, 0xe5, 0x20, 0x1a, 0xb2, 0x62, 0x74, 0xbb,
  35703. 0x1b, 0x70, 0xad, 0x32, 0x2c, 0xd0, 0x43, 0x9b,
  35704. 0x2d, 0xb1, 0x09, 0xcf, 0xf0, 0xa2, 0xf8, 0xe6,
  35705. 0x00, 0x99, 0x55, 0x71, 0xff, 0xc3, 0x8c, 0x59,
  35706. 0x0b, 0xc4, 0xc7, 0x61, 0x5c, 0x69, 0xd0, 0xc9,
  35707. 0x8e, 0xf4, 0x30, 0xf3, 0x08, 0x61, 0xa7, 0x72,
  35708. 0x38, 0xff, 0xc0, 0x70, 0x61, 0xe4, 0x75, 0xd6,
  35709. 0xa3, 0x0a, 0xd1, 0xb4, 0x7f, 0xd0, 0x39, 0xc3,
  35710. 0xa4, 0x47, 0x76, 0x2d, 0xb2, 0x21, 0x1d, 0xc3,
  35711. 0x1d, 0x0a, 0xca, 0xcf, 0xd5, 0x58, 0x90, 0xa5,
  35712. 0x82, 0x47, 0x98, 0xf9, 0xae, 0xad, 0x74, 0x13,
  35713. 0xdf, 0xe0, 0x28, 0xb1, 0x01, 0x2b, 0xe8, 0xb6,
  35714. 0xca, 0x10, 0x26, 0x66, 0x6a, 0xc6, 0xbc, 0x94,
  35715. 0x40, 0xa4, 0x49, 0xb5, 0x1a, 0xd8, 0xbb, 0xa7,
  35716. 0xb0, 0x92, 0x1d, 0xd4, 0xd8, 0xb4, 0xa5, 0x78,
  35717. 0x13, 0x6d, 0x1a, 0x05, 0xdb, 0x38, 0xcc, 0x85,
  35718. 0x84, 0x37, 0xb2, 0x51, 0x61, 0xd1, 0xc3, 0xc2,
  35719. 0x8e, 0xe0, 0x7b, 0xbc, 0xf2, 0xb2, 0x49, 0x11,
  35720. 0x0d, 0x22, 0x78, 0x1d, 0xc3, 0x05, 0x0d, 0x8c,
  35721. 0xc0, 0x09, 0x00, 0x96, 0xb3, 0x8a, 0x85, 0x06,
  35722. 0x96, 0xf8, 0x6e, 0x9e, 0x6b, 0xab, 0x32, 0x52,
  35723. 0x71, 0xb2, 0x24, 0x86, 0x75, 0x01, 0x19, 0x68,
  35724. 0x50, 0x28, 0x81, 0x09, 0x04, 0x97, 0xfa, 0xc0,
  35725. 0xaf, 0x84, 0x3c, 0x1a, 0xea, 0x76, 0xdd, 0x81,
  35726. 0xcf, 0x29, 0xc0, 0x12, 0xc6, 0x62, 0x27, 0xb7,
  35727. 0xf0, 0x6d, 0x99, 0x61, 0x30, 0x9b, 0x02, 0x62,
  35728. 0xf7, 0x32, 0xc9, 0xa4, 0xd0, 0xbb, 0xd0, 0x67,
  35729. 0x27, 0xab, 0xb8, 0x37, 0x1f, 0xf2, 0xc1, 0x18,
  35730. 0x99, 0xa0, 0x98, 0x37, 0x5c, 0x46, 0x05, 0x16,
  35731. 0xb2, 0xcc, 0x88, 0xbc, 0xf6, 0x28, 0xed, 0xe3,
  35732. 0x7d, 0x8f, 0x3b, 0x33, 0x42, 0xe4, 0x49, 0x0a,
  35733. 0x85, 0x60, 0x6e, 0xc0, 0x3d, 0xa2, 0x9b, 0x02,
  35734. 0x56, 0x27, 0x53, 0x82, 0xa3, 0x31, 0x3d, 0xc0,
  35735. 0x41, 0x11, 0x48, 0x01, 0x03, 0x2c, 0x51, 0x9f,
  35736. 0x35, 0x0c, 0x3e, 0x6a, 0xba, 0xc3, 0xe3, 0x3b,
  35737. 0x93, 0xb4, 0xa1, 0x9f, 0x7c, 0x54, 0x66, 0xe5,
  35738. 0x8c, 0xb1, 0xdc, 0x14, 0xb4, 0xa9, 0x6c, 0x47,
  35739. 0x57, 0x29, 0xf9, 0x71, 0xbd, 0xf1, 0x73, 0xcd,
  35740. 0xf3, 0x54, 0x82, 0x4d, 0x01, 0x94, 0x27, 0xf9,
  35741. 0x5b, 0x3b, 0x4a, 0x4a, 0x4a, 0x95, 0x8e, 0x47,
  35742. 0x6a, 0x6e, 0x69, 0x91, 0xce, 0x6f, 0x06, 0xcb,
  35743. 0x5d, 0xfc, 0xa7, 0xd4, 0x38, 0x0c, 0x3d, 0x92,
  35744. 0x0b, 0x57, 0x11, 0xac, 0x1f, 0xcb, 0xaf, 0x4b,
  35745. 0x9a, 0xc8, 0x00, 0xb9, 0x76, 0xd1, 0xec, 0x76,
  35746. 0x6a, 0x62, 0x6c, 0xc1, 0x90, 0x0b, 0x66, 0xb3,
  35747. 0xa9, 0xdc, 0x62, 0xc5, 0xc1, 0x44, 0x52, 0x7a,
  35748. 0x29, 0x6b, 0xaf, 0x70, 0x43, 0x3b, 0xf6, 0x57,
  35749. 0xc0, 0x43, 0x7f, 0x87, 0x59, 0x7b, 0xd7, 0xc8,
  35750. 0xbb, 0xbe, 0x9a, 0xbc, 0x37, 0x05, 0x09, 0x31,
  35751. 0xa4, 0xa8, 0x69, 0x82, 0xa2, 0x02, 0x8a, 0x74,
  35752. 0x45, 0x4c, 0x9b, 0x81, 0x0c, 0x88, 0xd1, 0x70,
  35753. 0x1c, 0x8c, 0xc9, 0x8a, 0x1d, 0x4c, 0xa1, 0x07,
  35754. 0xa6, 0xb2, 0x5e, 0x96, 0x2f, 0xe4, 0xb6, 0xb0,
  35755. 0x3c, 0x95, 0x45, 0x32, 0x60, 0xb8, 0x07, 0x22,
  35756. 0x86, 0x37, 0xcc, 0x9e, 0xb1, 0x2a, 0xcc, 0x09,
  35757. 0x54, 0x95, 0x9a, 0x52, 0xae, 0x54, 0xd1, 0x97,
  35758. 0x73, 0x00, 0xab, 0xa0, 0xba, 0x2c, 0x14, 0x60,
  35759. 0x9b, 0xb2, 0x8c, 0x11, 0xd5, 0xfa, 0xc5, 0xca,
  35760. 0xc8, 0x82, 0x97, 0x60, 0x32, 0x83, 0xe8, 0x67,
  35761. 0xa3, 0x64, 0x83, 0x66, 0xc7, 0x24, 0xd9, 0x35,
  35762. 0x4c, 0xd7, 0xa1, 0x96, 0xdb, 0xd9, 0x80, 0x2f,
  35763. 0x7b, 0x88, 0xd3, 0xfa, 0x00, 0x1f, 0x9c, 0x97,
  35764. 0x73, 0x22, 0x54, 0x62, 0x23, 0x5e, 0x91, 0x35,
  35765. 0x2a, 0x20, 0x79, 0x1f, 0xd8, 0xb8, 0x7f, 0xe3,
  35766. 0x37, 0x7e, 0xc6, 0xa3, 0x94, 0x0b, 0x11, 0x30,
  35767. 0xa0, 0xbb, 0x04, 0xe7, 0x41, 0x0a, 0x34, 0xe2,
  35768. 0x58, 0x0d, 0x07, 0x1d, 0x6c, 0x56, 0x20, 0x20,
  35769. 0x86, 0x78, 0x7a, 0x65, 0x90, 0xf8, 0x43, 0x93,
  35770. 0xa8, 0xe6, 0x51, 0xa1, 0xe6, 0x85, 0xf2, 0x24,
  35771. 0x78, 0xa8, 0x95, 0x4f, 0x00, 0x7b, 0xc7, 0x71,
  35772. 0x1b, 0x93, 0x07, 0x72, 0xc7, 0x8f, 0x09, 0x2e,
  35773. 0x82, 0x87, 0x8e, 0x3e, 0x93, 0x7f, 0x36, 0x79,
  35774. 0x67, 0x53, 0x29, 0x13, 0xa8, 0xd5, 0x3d, 0xfd,
  35775. 0xf4, 0xbf, 0xb1, 0xf8, 0x84, 0x67, 0x46, 0x59,
  35776. 0x67, 0x05, 0xcf, 0x34, 0x51, 0x42, 0xb9, 0x72,
  35777. 0xa3, 0xf1, 0x63, 0x25, 0xc4, 0x0c, 0x29, 0x52,
  35778. 0xa3, 0x7b, 0x25, 0x89, 0x7e, 0x5e, 0xf3, 0x5f,
  35779. 0xba, 0xeb, 0x73, 0xa4, 0xac, 0xbe, 0xb6, 0xa0,
  35780. 0xb8, 0x99, 0x42, 0xce, 0xb1, 0x95, 0x53, 0x1c,
  35781. 0xfc, 0x0a, 0x07, 0x99, 0x39, 0x54, 0x48, 0x3e,
  35782. 0x6c, 0xbc, 0x87, 0xc0, 0x6a, 0xa7, 0x4f, 0xf0,
  35783. 0xca, 0xc5, 0x20, 0x7e, 0x53, 0x5b, 0x26, 0x0a,
  35784. 0xa9, 0x8d, 0x11, 0x98, 0xc0, 0x7d, 0xa6, 0x05,
  35785. 0xc4, 0xd1, 0x10, 0x20, 0xf6, 0xc9, 0xf7, 0xbb,
  35786. 0x68, 0xbb, 0x34, 0x56, 0xc7, 0x3a, 0x01, 0xb7,
  35787. 0x10, 0xbc, 0x99, 0xd1, 0x77, 0x39, 0xa5, 0x17,
  35788. 0x16, 0xaa, 0x01, 0x66, 0x0c, 0x8b, 0x62, 0x8b,
  35789. 0x2f, 0x56, 0x02, 0xba, 0x65, 0xf0, 0x7e, 0xa9,
  35790. 0x93, 0x33, 0x6e, 0x89, 0x6e, 0x83, 0xf2, 0xc5,
  35791. 0x73, 0x1b, 0xbf, 0x03, 0x46, 0x0c, 0x5b, 0x6c,
  35792. 0x8a, 0xfe, 0xcb, 0x74, 0x8e, 0xe3, 0x91, 0xe9,
  35793. 0x89, 0x34, 0xa2, 0xc5, 0x7d, 0x4d, 0x06, 0x9f,
  35794. 0x50, 0xd8, 0x8b, 0x30, 0xd6, 0x96, 0x6f, 0x38,
  35795. 0xc3, 0x7b, 0xc6, 0x49, 0xb8, 0x26, 0x34, 0xce,
  35796. 0x77, 0x22, 0x64, 0x5c, 0xcd, 0x62, 0x50, 0x63,
  35797. 0x36, 0x46, 0x46, 0xd6, 0xd6, 0x99, 0xdb, 0x57,
  35798. 0xb4, 0x5e, 0xb6, 0x74, 0x65, 0xe1, 0x6d, 0xe4,
  35799. 0xd4, 0x06, 0xa8, 0x18, 0xb9, 0xea, 0xe1, 0xca,
  35800. 0x91, 0x6a, 0x25, 0x94, 0x48, 0x97, 0x08, 0xa4,
  35801. 0x3c, 0xea, 0x88, 0xb0, 0x2a, 0x4c, 0x03, 0xd0,
  35802. 0x9b, 0x44, 0x81, 0x5c, 0x97, 0x10, 0x1c, 0xaf,
  35803. 0x50, 0x48, 0xbb, 0xcb, 0x24, 0x7a, 0xe2, 0x36,
  35804. 0x6c, 0xdc, 0x25, 0x4b, 0xa2, 0x21, 0x29, 0xf4,
  35805. 0x5b, 0x3b, 0x0e, 0xb3, 0x99, 0xca, 0x91, 0xa3,
  35806. 0x03, 0x40, 0x28, 0x30, 0xec, 0x01, 0xdb, 0x7b,
  35807. 0x2c, 0xa4, 0x80, 0xcf, 0x35, 0x04, 0x09, 0xb2,
  35808. 0x16, 0x09, 0x4b, 0x7b, 0x0c, 0x3a, 0xe3, 0x3c,
  35809. 0xe1, 0x0a, 0x91, 0x24, 0xe8, 0x96, 0x51, 0xab,
  35810. 0x90, 0x1e, 0xa2, 0x53, 0xc8, 0x41, 0x5b, 0xd7,
  35811. 0x82, 0x5f, 0x02, 0xbb, 0x22, 0x93, 0x69, 0xaf,
  35812. 0x97, 0x20, 0x28, 0xf2, 0x28, 0x75, 0xea, 0x55,
  35813. 0xaf, 0x16, 0xd3, 0xbc, 0x69, 0xf7, 0x0c, 0x2e,
  35814. 0xe8, 0xb7, 0x5f, 0x28, 0xb4, 0x7d, 0xd3, 0x91,
  35815. 0xf9, 0x89, 0xad, 0xe3, 0x14, 0x72, 0x9c, 0x33,
  35816. 0x1f, 0xa0, 0x4c, 0x19, 0x17, 0xb2, 0x78, 0xc3,
  35817. 0xeb, 0x60, 0x28, 0x68, 0x51, 0x28, 0x21, 0xad,
  35818. 0xc8, 0x25, 0xc6, 0x45, 0x77, 0xce, 0x1e, 0x63,
  35819. 0xb1, 0xd9, 0x64, 0x4a, 0x61, 0x29, 0x48, 0xa3,
  35820. 0x48, 0x3c, 0x7f, 0x1b, 0x9a, 0x25, 0x80, 0x00,
  35821. 0xe3, 0x01, 0x96, 0x94, 0x4a, 0x40, 0x36, 0x27,
  35822. 0x60, 0x9c, 0x76, 0xc7, 0xea, 0x6b, 0x5d, 0xe0,
  35823. 0x17, 0x64, 0xd2, 0x43, 0x79, 0x11, 0x7b, 0x9e,
  35824. 0xa2, 0x98, 0x48, 0xdc, 0x55, 0x5c, 0x45, 0x4b,
  35825. 0xce, 0xae, 0x1b, 0xa5, 0xcc, 0x72, 0xc7, 0x4a,
  35826. 0xb9, 0x6b, 0x9c, 0x91, 0xb9, 0x10, 0xd2, 0x6b,
  35827. 0x88, 0xb2, 0x56, 0x39, 0xd4, 0x77, 0x8a, 0xe2,
  35828. 0x6c, 0x7c, 0x61, 0x51, 0xa1, 0x9c, 0x6c, 0xd7,
  35829. 0x93, 0x84, 0x54, 0x37, 0x24, 0x65, 0xe4, 0xc5,
  35830. 0xec, 0x29, 0x24, 0x5a, 0xcb, 0x3d, 0xb5, 0x37,
  35831. 0x9d, 0xe3, 0xda, 0xbf, 0xa6, 0x29, 0xa7, 0xc0,
  35832. 0x4a, 0x83, 0x53, 0xa8, 0x53, 0x0c, 0x95, 0xac,
  35833. 0xb7, 0x32, 0xbb, 0x4b, 0xb8, 0x19, 0x32, 0xbb,
  35834. 0x2c, 0xa7, 0xa8, 0x48, 0xcd, 0x36, 0x68, 0x01,
  35835. 0x44, 0x4a, 0xbe, 0x23, 0xc8, 0x3b, 0x36, 0x6a,
  35836. 0x87, 0xd6, 0xa3, 0xcf, 0x36, 0x09, 0x24, 0xc0,
  35837. 0x02, 0xba, 0xe9, 0x0a, 0xf6, 0x5c, 0x48, 0x06,
  35838. 0x0b, 0x37, 0x52, 0xf2, 0xba, 0xdf, 0x1a, 0xb2,
  35839. 0x72, 0x20, 0x72, 0x55, 0x4a, 0x50, 0x59, 0x75,
  35840. 0x35, 0x94, 0xe6, 0xa7, 0x02, 0x76, 0x1f, 0xc9,
  35841. 0x76, 0x84, 0xc8, 0xc4, 0xa7, 0x54, 0x0a, 0x6b,
  35842. 0x07, 0xfb, 0xc9, 0xde, 0x87, 0xc9, 0x74, 0xaa,
  35843. 0x88, 0x09, 0xd9, 0x28, 0xc7, 0xf4, 0xcb, 0xbf,
  35844. 0x80, 0x45, 0xae, 0xa5, 0xbc, 0x66, 0x78, 0x25,
  35845. 0xfd, 0x05, 0xa5, 0x21, 0xf1, 0xa4, 0xbf, 0x53,
  35846. 0x92, 0x10, 0xc7, 0x11, 0x3b, 0xc3, 0x7b, 0x3e,
  35847. 0x58, 0xb0, 0xcb, 0xfc, 0x53, 0xc8, 0x41, 0xcb,
  35848. 0xb0, 0x37, 0x1d, 0xe2, 0xe5, 0x11, 0xb9, 0x89,
  35849. 0xcb, 0x7c, 0x70, 0xc0, 0x23, 0x36, 0x6d, 0x78,
  35850. 0xf9, 0xc3, 0x7e, 0xf0, 0x47, 0xf8, 0x72, 0x0b,
  35851. 0xe1, 0xc7, 0x59, 0xa8, 0xd9, 0x6b, 0x93, 0xf6,
  35852. 0x5a, 0x94, 0x11, 0x4f, 0xfa, 0xf6, 0x0d, 0x9a,
  35853. 0x81, 0x79, 0x5e, 0x99, 0x5c, 0x71, 0x15, 0x2a,
  35854. 0x46, 0x91, 0xa5, 0xa6, 0x02, 0xa9, 0xe1, 0xf3,
  35855. 0x59, 0x9e, 0x37, 0xc7, 0x68, 0xc7, 0xbc, 0x10,
  35856. 0x89, 0x94, 0xc0, 0x66, 0x9f, 0x3a, 0xdc, 0x95,
  35857. 0x7d, 0x46, 0xb4, 0xb6, 0x25, 0x69, 0x68, 0xe2,
  35858. 0x90, 0xd7, 0x89, 0x2e, 0xa8, 0x54, 0x64, 0xee,
  35859. 0x7a, 0x75, 0x0f, 0x39, 0xc5, 0xe3, 0x15, 0x2c,
  35860. 0x2d, 0xfc, 0x56, 0xd8, 0xb0, 0xc9, 0x24, 0xba,
  35861. 0x8a, 0x95, 0x9a, 0x68, 0x09, 0x65, 0x47, 0xf6,
  35862. 0x64, 0x23, 0xc8, 0x38, 0x98, 0x2a, 0x57, 0x94,
  35863. 0xb9, 0xe1, 0x53, 0x37, 0x71, 0x33, 0x1a, 0x9a,
  35864. 0x65, 0x6c, 0x28, 0x82, 0x8b, 0xeb, 0x91, 0x26,
  35865. 0xa6, 0x0e, 0x95, 0xe8, 0xc5, 0xd9, 0x06, 0x83,
  35866. 0x2c, 0x77, 0x10, 0x70, 0x55, 0x76, 0xb1, 0xfb,
  35867. 0x95, 0x07, 0x26, 0x9d, 0xda, 0xf8, 0xc9, 0x5c,
  35868. 0xe9, 0x71, 0x9b, 0x2c, 0xa8, 0xdd, 0x11, 0x2b,
  35869. 0xe1, 0x0b, 0xcc, 0x9f, 0x4a, 0x37, 0xbd, 0x1b,
  35870. 0x1e, 0xee, 0xb3, 0x3e, 0xcd, 0xa7, 0x6a, 0xe9,
  35871. 0xf6, 0x9a, 0x5d, 0x4b, 0x29, 0x23, 0xa8, 0x69,
  35872. 0x57, 0x67, 0x1d, 0x61, 0x93, 0x35, 0xbe, 0x1c,
  35873. 0x4c, 0x2c, 0x77, 0xce, 0x87, 0xc4, 0x1f, 0x98,
  35874. 0xa8, 0xcc, 0x46, 0x64, 0x60, 0xfa, 0x30, 0x0a,
  35875. 0xaf, 0x5b, 0x30, 0x1f, 0x0a, 0x1d, 0x09, 0xc8,
  35876. 0x8e, 0x65, 0xda, 0x4d, 0x8e, 0xe6, 0x4f, 0x68,
  35877. 0xc0, 0x21, 0x89, 0xbb, 0xb3, 0x58, 0x4b, 0xaf,
  35878. 0xf7, 0x16, 0xc8, 0x5d, 0xb6, 0x54, 0x04, 0x8a,
  35879. 0x00, 0x43, 0x33, 0x48, 0x93, 0x93, 0xa0, 0x74,
  35880. 0x27, 0xcd, 0x3e, 0x21, 0x7e, 0x6a, 0x34, 0x5f,
  35881. 0x6c, 0x2c, 0x2b, 0x13, 0xc2, 0x7b, 0x33, 0x72,
  35882. 0x71, 0xc0, 0xb2, 0x7b, 0x2d, 0xba, 0xa0, 0x0d,
  35883. 0x23, 0x76, 0x00, 0xb5, 0xb5, 0x94, 0xe8, 0xcf,
  35884. 0x2d, 0xd6, 0x25, 0xea, 0x76, 0xcf, 0x0e, 0xd8,
  35885. 0x99, 0x12, 0x2c, 0x97, 0x96, 0xb4, 0xb0, 0x18,
  35886. 0x70, 0x04, 0x25, 0x80, 0x49, 0xa4, 0x77, 0xcd,
  35887. 0x11, 0xd6, 0x8c, 0x49, 0xb9, 0xa0, 0xe7, 0xb0,
  35888. 0x0b, 0xce, 0x8c, 0xac, 0x78, 0x64, 0xcb, 0xb3,
  35889. 0x75, 0x14, 0x00, 0x84, 0x74, 0x4c, 0x93, 0x06,
  35890. 0x26, 0x94, 0xca, 0x79, 0x5c, 0x4f, 0x40, 0xe7,
  35891. 0xac, 0xc9, 0xc5, 0xa1, 0x88, 0x40, 0x72, 0xd8,
  35892. 0xc3, 0x8d, 0xaf, 0xb5, 0x01, 0xee, 0x41, 0x84,
  35893. 0xdd, 0x5a, 0x81, 0x9e, 0xc2, 0x4e, 0xc1, 0x65,
  35894. 0x12, 0x61, 0xf9, 0x62, 0xb1, 0x7a, 0x72, 0x15,
  35895. 0xaa, 0x4a, 0x74, 0x8c, 0x15, 0x83, 0x6c, 0x38,
  35896. 0x91, 0x37, 0x67, 0x82, 0x04, 0x83, 0x8d, 0x71,
  35897. 0x95, 0xa8, 0x5b, 0x4f, 0x98, 0xa1, 0xb5, 0x74,
  35898. 0xc4, 0xcd, 0x79, 0x09, 0xcd, 0x1f, 0x83, 0x3e,
  35899. 0xff, 0xd1, 0x48, 0x55, 0x43, 0x22, 0x9d, 0x37,
  35900. 0x48, 0xd9, 0xb5, 0xcd, 0x6c, 0x17, 0xb9, 0xb3,
  35901. 0xb8, 0x4a, 0xef, 0x8b, 0xce, 0x13, 0xe6, 0x83,
  35902. 0x73, 0x36, 0x59, 0xc7, 0x95, 0x42, 0xd6, 0x15,
  35903. 0x78, 0x2a, 0x71, 0xcd, 0xee, 0xe7, 0x92, 0xba,
  35904. 0xb5, 0x1b, 0xdc, 0x4b, 0xbf, 0xe8, 0x30, 0x8e,
  35905. 0x66, 0x31, 0x44, 0xed, 0xe8, 0x49, 0x18, 0x30,
  35906. 0xad, 0x98, 0xb4, 0x63, 0x4f, 0x64, 0xab, 0xa8,
  35907. 0xb9, 0xc0, 0x42, 0x27, 0x26, 0x53, 0x92, 0x0f,
  35908. 0x38, 0x0c, 0x1a, 0x17, 0xca, 0x87, 0xce, 0xd7,
  35909. 0xaa, 0xc4, 0x1c, 0x82, 0x88, 0x87, 0x93, 0x18,
  35910. 0x1a, 0x6f, 0x76, 0xe1, 0x97, 0xb7, 0xb9, 0x0e,
  35911. 0xf9, 0x09, 0x43, 0xbb, 0x38, 0x44, 0x91, 0x29,
  35912. 0x11, 0xd8, 0x55, 0x1e, 0x54, 0x66, 0xc5, 0x76,
  35913. 0x7a, 0xb0, 0xbc, 0x61, 0xa1, 0xa3, 0xf7, 0x36,
  35914. 0x16, 0x2e, 0xc0, 0x98, 0xa9, 0x00, 0xb1, 0x2d,
  35915. 0xd8, 0xfa, 0xbb, 0xfb, 0x3f, 0xe8, 0xcb, 0x1d,
  35916. 0xc4, 0xe8, 0x31, 0x5f, 0x2a, 0xf0, 0xd3, 0x2f,
  35917. 0x00, 0x17, 0xae, 0x13, 0x6e, 0x19, 0xf0, 0x28,
  35918. 0xf5, 0x72, 0x62, 0x66, 0x13, 0x58, 0xcd, 0xe8,
  35919. 0xd3, 0xeb, 0xf9, 0x90, 0xe5, 0xfd, 0x1d, 0x5b,
  35920. 0x89, 0x6c, 0x99, 0x2c, 0xcf, 0xaa, 0xdb, 0x52,
  35921. 0x56, 0xb6, 0x8b, 0xbf, 0x59, 0x43, 0xb1, 0x32,
  35922. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  35923. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  35924. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  35925. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  35926. };
  35927. #endif
  35928. #ifdef WOLFSSL_KYBER_ORIGINAL
  35929. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ct[] = {
  35930. 0xB5, 0x2C, 0x56, 0xB9, 0x2A, 0x4B, 0x7C, 0xE9,
  35931. 0xE4, 0xCB, 0x7C, 0x5B, 0x1B, 0x16, 0x31, 0x67,
  35932. 0xA8, 0xA1, 0x67, 0x5B, 0x2F, 0xDE, 0xF8, 0x4A,
  35933. 0x5B, 0x67, 0xCA, 0x15, 0xDB, 0x69, 0x4C, 0x9F,
  35934. 0x11, 0xBD, 0x02, 0x7C, 0x30, 0xAE, 0x22, 0xEC,
  35935. 0x92, 0x1A, 0x1D, 0x91, 0x15, 0x99, 0xAF, 0x05,
  35936. 0x85, 0xE4, 0x8D, 0x20, 0xDA, 0x70, 0xDF, 0x9F,
  35937. 0x39, 0xE3, 0x2E, 0xF9, 0x5D, 0x4C, 0x8F, 0x44,
  35938. 0xBF, 0xEF, 0xDA, 0xA5, 0xDA, 0x64, 0xF1, 0x05,
  35939. 0x46, 0x31, 0xD0, 0x4D, 0x6D, 0x3C, 0xFD, 0x0A,
  35940. 0x54, 0x0D, 0xD7, 0xBA, 0x38, 0x86, 0xE4, 0xB5,
  35941. 0xF1, 0x3E, 0x87, 0x87, 0x88, 0x60, 0x4C, 0x95,
  35942. 0xC0, 0x96, 0xEA, 0xB3, 0x91, 0x9F, 0x42, 0x75,
  35943. 0x21, 0x41, 0x9A, 0x94, 0x6C, 0x26, 0xCC, 0x04,
  35944. 0x14, 0x75, 0xD7, 0x12, 0x4C, 0xDC, 0x01, 0xD0,
  35945. 0x37, 0x3E, 0x5B, 0x09, 0xC7, 0xA7, 0x06, 0x03,
  35946. 0xCF, 0xDB, 0x4F, 0xB3, 0x40, 0x50, 0x23, 0xF2,
  35947. 0x26, 0x4D, 0xC3, 0xF9, 0x83, 0xC4, 0xFC, 0x02,
  35948. 0xA2, 0xD1, 0xB2, 0x68, 0xF2, 0x20, 0x8A, 0x1F,
  35949. 0x6E, 0x2A, 0x62, 0x09, 0xBF, 0xF1, 0x2F, 0x6F,
  35950. 0x46, 0x5F, 0x0B, 0x06, 0x9C, 0x3A, 0x7F, 0x84,
  35951. 0xF6, 0x06, 0xD8, 0xA9, 0x40, 0x64, 0x00, 0x3D,
  35952. 0x6E, 0xC1, 0x14, 0xC8, 0xE8, 0x08, 0xD3, 0x05,
  35953. 0x38, 0x84, 0xC1, 0xD5, 0xA1, 0x42, 0xFB, 0xF2,
  35954. 0x01, 0x12, 0xEB, 0x36, 0x0F, 0xDA, 0x3F, 0x0F,
  35955. 0x28, 0xB1, 0x72, 0xAE, 0x50, 0xF5, 0xE7, 0xD8,
  35956. 0x38, 0x01, 0xFB, 0x3F, 0x00, 0x64, 0xB6, 0x87,
  35957. 0x18, 0x70, 0x74, 0xBD, 0x7F, 0xE3, 0x0E, 0xDD,
  35958. 0xAA, 0x33, 0x4C, 0xF8, 0xFC, 0x04, 0xFA, 0x8C,
  35959. 0xED, 0x89, 0x9C, 0xEA, 0xDE, 0x4B, 0x4F, 0x28,
  35960. 0xB6, 0x83, 0x72, 0xBA, 0xF9, 0x8F, 0xF4, 0x82,
  35961. 0xA4, 0x15, 0xB7, 0x31, 0x15, 0x5B, 0x75, 0xCE,
  35962. 0xB9, 0x76, 0xBE, 0x0E, 0xA0, 0x28, 0x5B, 0xA0,
  35963. 0x1A, 0x27, 0xF1, 0x85, 0x7A, 0x8F, 0xB3, 0x77,
  35964. 0xA3, 0xAE, 0x0C, 0x23, 0xB2, 0xAA, 0x9A, 0x07,
  35965. 0x9B, 0xFA, 0xBF, 0xF0, 0xD5, 0xB2, 0xF1, 0xCD,
  35966. 0x9B, 0x71, 0x8B, 0xEA, 0x03, 0xC4, 0x2F, 0x34,
  35967. 0x3A, 0x39, 0xB4, 0xF1, 0x42, 0xD0, 0x1A, 0xD8,
  35968. 0xAC, 0xBB, 0x50, 0xE3, 0x88, 0x53, 0xCF, 0x9A,
  35969. 0x50, 0xC8, 0xB4, 0x4C, 0x3C, 0xF6, 0x71, 0xA4,
  35970. 0xA9, 0x04, 0x3B, 0x26, 0xDD, 0xBB, 0x24, 0x95,
  35971. 0x9A, 0xD6, 0x71, 0x5C, 0x08, 0x52, 0x18, 0x55,
  35972. 0xC7, 0x9A, 0x23, 0xB9, 0xC3, 0xD6, 0x47, 0x17,
  35973. 0x49, 0xC4, 0x07, 0x25, 0xBD, 0xD5, 0xC2, 0x77,
  35974. 0x6D, 0x43, 0xAE, 0xD2, 0x02, 0x04, 0xBA, 0xA1,
  35975. 0x41, 0xEF, 0xB3, 0x30, 0x49, 0x17, 0x47, 0x4B,
  35976. 0x7F, 0x9F, 0x7A, 0x4B, 0x08, 0xB1, 0xA9, 0x3D,
  35977. 0xAE, 0xD9, 0x8C, 0x67, 0x49, 0x53, 0x59, 0xD3,
  35978. 0x7D, 0x67, 0xF7, 0x43, 0x8B, 0xEE, 0x5E, 0x43,
  35979. 0x58, 0x56, 0x34, 0xB2, 0x6C, 0x6B, 0x38, 0x10,
  35980. 0xD7, 0xCD, 0xCB, 0xC0, 0xF6, 0xEB, 0x87, 0x7A,
  35981. 0x60, 0x87, 0xE6, 0x8A, 0xCB, 0x84, 0x80, 0xD3,
  35982. 0xA8, 0xCF, 0x69, 0x00, 0x44, 0x7E, 0x49, 0xB4,
  35983. 0x17, 0xF1, 0x5A, 0x53, 0xB6, 0x07, 0xA0, 0xE2,
  35984. 0x16, 0xB8, 0x55, 0x97, 0x0D, 0x37, 0x40, 0x68,
  35985. 0x70, 0xB4, 0x56, 0x87, 0x22, 0xDA, 0x77, 0xA4,
  35986. 0x08, 0x47, 0x03, 0x81, 0x67, 0x84, 0xE2, 0xF1,
  35987. 0x6B, 0xED, 0x18, 0x99, 0x65, 0x32, 0xC5, 0xD8,
  35988. 0xB7, 0xF5, 0xD2, 0x14, 0x46, 0x4E, 0x5F, 0x3F,
  35989. 0x6E, 0x90, 0x58, 0x67, 0xB0, 0xCE, 0x11, 0x9E,
  35990. 0x25, 0x2A, 0x66, 0x71, 0x32, 0x53, 0x54, 0x46,
  35991. 0x85, 0xD2, 0x08, 0xE1, 0x72, 0x39, 0x08, 0xA0,
  35992. 0xCE, 0x97, 0x83, 0x46, 0x52, 0xE0, 0x8A, 0xE7,
  35993. 0xBD, 0xC8, 0x81, 0xA1, 0x31, 0xB7, 0x3C, 0x71,
  35994. 0xE8, 0x4D, 0x20, 0xD6, 0x8F, 0xDE, 0xFF, 0x4F,
  35995. 0x5D, 0x70, 0xCD, 0x1A, 0xF5, 0x7B, 0x78, 0xE3,
  35996. 0x49, 0x1A, 0x98, 0x65, 0x94, 0x23, 0x21, 0x80,
  35997. 0x0A, 0x20, 0x3C, 0x05, 0xED, 0x1F, 0xEE, 0xB5,
  35998. 0xA2, 0x8E, 0x58, 0x4E, 0x19, 0xF6, 0x53, 0x5E,
  35999. 0x7F, 0x84, 0xE4, 0xA2, 0x4F, 0x84, 0xA7, 0x2D,
  36000. 0xCA, 0xF5, 0x64, 0x8B, 0x4A, 0x42, 0x35, 0xDD,
  36001. 0x66, 0x44, 0x64, 0x48, 0x2F, 0x03, 0x17, 0x6E,
  36002. 0x88, 0x8C, 0x28, 0xBF, 0xC6, 0xC1, 0xCB, 0x23,
  36003. 0x8C, 0xFF, 0xA3, 0x5A, 0x32, 0x1E, 0x71, 0x79,
  36004. 0x1D, 0x9E, 0xA8, 0xED, 0x08, 0x78, 0xC6, 0x11,
  36005. 0x21, 0xBF, 0x8D, 0x2A, 0x4A, 0xB2, 0xC1, 0xA5,
  36006. 0xE1, 0x20, 0xBC, 0x40, 0xAB, 0xB1, 0x89, 0x2D,
  36007. 0x17, 0x15, 0x09, 0x0A, 0x0E, 0xE4, 0x82, 0x52,
  36008. 0xCA, 0x29, 0x7A, 0x99, 0xAA, 0x0E, 0x51, 0x0C,
  36009. 0xF2, 0x6B, 0x1A, 0xDD, 0x06, 0xCA, 0x54, 0x3E,
  36010. 0x1C, 0x5D, 0x6B, 0xDC, 0xD3, 0xB9, 0xC5, 0x85,
  36011. 0xC8, 0x53, 0x80, 0x45, 0xDB, 0x5C, 0x25, 0x2E,
  36012. 0xC3, 0xC8, 0xC3, 0xC9, 0x54, 0xD9, 0xBE, 0x59,
  36013. 0x07, 0x09, 0x4A, 0x89, 0x4E, 0x60, 0xEA, 0xB4,
  36014. 0x35, 0x38, 0xCF, 0xEE, 0x82, 0xE8, 0xFF, 0xC0,
  36015. 0x79, 0x1B, 0x0D, 0x0F, 0x43, 0xAC, 0x16, 0x27,
  36016. 0x83, 0x0A, 0x61, 0xD5, 0x6D, 0xAD, 0x96, 0xC6,
  36017. 0x29, 0x58, 0xB0, 0xDE, 0x78, 0x0B, 0x78, 0xBD,
  36018. 0x47, 0xA6, 0x04, 0x55, 0x0D, 0xAB, 0x83, 0xFF,
  36019. 0xF2, 0x27, 0xC3, 0x24, 0x04, 0x94, 0x71, 0xF3,
  36020. 0x52, 0x48, 0xCF, 0xB8, 0x49, 0xB2, 0x57, 0x24,
  36021. 0xFF, 0x70, 0x4D, 0x52, 0x77, 0xAA, 0x35, 0x2D,
  36022. 0x55, 0x09, 0x58, 0xBE, 0x3B, 0x23, 0x7D, 0xFF,
  36023. 0x47, 0x3E, 0xC2, 0xAD, 0xBA, 0xEA, 0x48, 0xCA,
  36024. 0x26, 0x58, 0xAE, 0xFC, 0xC7, 0x7B, 0xBD, 0x42,
  36025. 0x64, 0xAB, 0x37, 0x4D, 0x70, 0xEA, 0xE5, 0xB9,
  36026. 0x64, 0x41, 0x6C, 0xE8, 0x22, 0x6A, 0x7E, 0x32,
  36027. 0x55, 0xA0, 0xF8, 0xD7, 0xE2, 0xAD, 0xCA, 0x06,
  36028. 0x2B, 0xCD, 0x6D, 0x78, 0xD6, 0x0D, 0x1B, 0x32,
  36029. 0xE1, 0x14, 0x05, 0xBE, 0x54, 0xB6, 0x6E, 0xF0,
  36030. 0xFD, 0xDD, 0x56, 0x77, 0x02, 0xA3, 0xBC, 0xCF,
  36031. 0xED, 0xE3, 0xC5, 0x84, 0x70, 0x12, 0x69, 0xED,
  36032. 0x14, 0x80, 0x9F, 0x06, 0xF8, 0x96, 0x83, 0x56,
  36033. 0xBB, 0x92, 0x67, 0xFE, 0x86, 0xE5, 0x14, 0x25,
  36034. 0x2E, 0x88, 0xBB, 0x5C, 0x30, 0xA7, 0xEC, 0xB3,
  36035. 0xD0, 0xE6, 0x21, 0x02, 0x1E, 0xE0, 0xFB, 0xF7,
  36036. 0x87, 0x1B, 0x09, 0x34, 0x2B, 0xF8, 0x4F, 0x55,
  36037. 0xC9, 0x7E, 0xAF, 0x86, 0xC4, 0x81, 0x89, 0xC7,
  36038. 0xFF, 0x4D, 0xF3, 0x89, 0xF0, 0x77, 0xE2, 0x80,
  36039. 0x6E, 0x5F, 0xA7, 0x3B, 0x3E, 0x94, 0x58, 0xA1,
  36040. 0x6C, 0x7E, 0x27, 0x5F, 0x4F, 0x60, 0x22, 0x75,
  36041. 0x58, 0x0E, 0xB7, 0xB7, 0x13, 0x5F, 0xB5, 0x37,
  36042. 0xFA, 0x0C, 0xD9, 0x5D, 0x6E, 0xA5, 0x8C, 0x10,
  36043. 0x8C, 0xD8, 0x94, 0x3D, 0x70, 0xC1, 0x64, 0x31,
  36044. 0x11, 0xF4, 0xF0, 0x1C, 0xA8, 0xA8, 0x27, 0x6A,
  36045. 0x90, 0x26, 0x66, 0xED, 0x81, 0xB7, 0x8D, 0x16,
  36046. 0x8B, 0x00, 0x6F, 0x16, 0xAA, 0xA3, 0xD8, 0xE4,
  36047. 0xCE, 0x4F, 0x4D, 0x0F, 0xB0, 0x99, 0x7E, 0x41,
  36048. 0xAE, 0xFF, 0xB5, 0xB3, 0xDA, 0xA8, 0x38, 0x73,
  36049. 0x2F, 0x35, 0x73, 0x49, 0x44, 0x7F, 0x38, 0x77,
  36050. 0x76, 0xC7, 0x93, 0xC0, 0x47, 0x9D, 0xE9, 0xE9,
  36051. 0x94, 0x98, 0xCC, 0x35, 0x6F, 0xDB, 0x00, 0x75,
  36052. 0xA7, 0x03, 0xF2, 0x3C, 0x55, 0xD4, 0x7B, 0x55,
  36053. 0x0E, 0xC8, 0x9B, 0x02, 0xAD, 0xE8, 0x93, 0x29,
  36054. 0x08, 0x6A, 0x50, 0x84, 0x34, 0x56, 0xFE, 0xDC,
  36055. 0x37, 0x88, 0xAC, 0x8D, 0x97, 0x23, 0x3C, 0x54,
  36056. 0x56, 0x04, 0x67, 0xEE, 0x1D, 0x0F, 0x02, 0x4B,
  36057. 0x18, 0x42, 0x8F, 0x0D, 0x73, 0xB3, 0x0E, 0x19,
  36058. 0xF5, 0xC6, 0x3B, 0x9A, 0xBF, 0x11, 0x41, 0x5B,
  36059. 0xEA, 0x4D, 0x01, 0x70, 0x13, 0x0B, 0xAA, 0xBD,
  36060. 0x33, 0xC0, 0x5E, 0x65, 0x24, 0xE5, 0xFB, 0x55,
  36061. 0x81, 0xB2, 0x2B, 0x04, 0x33, 0x34, 0x22, 0x48,
  36062. 0x26, 0x6D, 0x0F, 0x10, 0x53, 0xB2, 0x45, 0xCC,
  36063. 0x24, 0x62, 0xDC, 0x44, 0xD3, 0x49, 0x65, 0x10,
  36064. 0x24, 0x82, 0xA8, 0xED, 0x9E, 0x4E, 0x96, 0x4D,
  36065. 0x56, 0x83, 0xE5, 0xD4, 0x5D, 0x0C, 0x82, 0x69
  36066. };
  36067. #endif
  36068. #ifndef WOLFSSL_NO_ML_KEM
  36069. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ct[] = {
  36070. 0xc8, 0x39, 0x10, 0x85, 0xb8, 0xd3, 0xea, 0x97,
  36071. 0x94, 0x21, 0x25, 0x41, 0xb2, 0x91, 0x4f, 0x08,
  36072. 0x96, 0x4d, 0x33, 0x52, 0x1d, 0x3f, 0x67, 0xad,
  36073. 0x66, 0x09, 0x6e, 0xbf, 0xb1, 0xf7, 0x06, 0x42,
  36074. 0x4b, 0x49, 0x55, 0x8f, 0x75, 0x5b, 0x56, 0x25,
  36075. 0xba, 0xe2, 0x36, 0xf2, 0xe0, 0x07, 0x96, 0x01,
  36076. 0xc7, 0x66, 0xf7, 0xd9, 0x60, 0x80, 0x8f, 0x7e,
  36077. 0x2b, 0xb0, 0xc7, 0xa5, 0xe0, 0x66, 0xed, 0x34,
  36078. 0x6d, 0xe6, 0x28, 0xf8, 0xc5, 0x7e, 0xeb, 0xab,
  36079. 0xbb, 0x0c, 0x22, 0xd9, 0x11, 0x54, 0x84, 0x63,
  36080. 0x69, 0x3e, 0xf3, 0xce, 0x52, 0xa5, 0x3f, 0x7f,
  36081. 0xf4, 0x15, 0xf0, 0x0e, 0x65, 0x7a, 0xe1, 0xc5,
  36082. 0xa4, 0x8f, 0xa5, 0xec, 0x6e, 0x4b, 0xe5, 0xcf,
  36083. 0x46, 0x2d, 0xaf, 0xfc, 0x84, 0xd2, 0xf6, 0xd5,
  36084. 0xff, 0x55, 0xdc, 0x9b, 0xbe, 0x8b, 0xb0, 0xd7,
  36085. 0x25, 0xec, 0x64, 0xfd, 0x4c, 0xd4, 0xbd, 0x8d,
  36086. 0xba, 0x0a, 0x84, 0x4e, 0x8b, 0x5c, 0xe4, 0xb6,
  36087. 0xa2, 0x89, 0x34, 0xd7, 0xf7, 0xa0, 0x50, 0x99,
  36088. 0x1f, 0xe1, 0x85, 0xb5, 0x06, 0xb4, 0x51, 0xda,
  36089. 0xbf, 0xad, 0x52, 0xd5, 0x2c, 0xb2, 0x11, 0x4c,
  36090. 0xa7, 0xd9, 0xa5, 0xcf, 0x98, 0x6c, 0x8f, 0xdc,
  36091. 0x1b, 0xc1, 0x0e, 0xc0, 0xc1, 0x86, 0x9e, 0x50,
  36092. 0xc0, 0x3c, 0x55, 0xa7, 0x61, 0x92, 0xa1, 0x04,
  36093. 0x9a, 0xca, 0x63, 0x6b, 0xa9, 0x02, 0x0b, 0xda,
  36094. 0xa8, 0xd0, 0xf5, 0x8c, 0x76, 0x3b, 0x0b, 0x89,
  36095. 0x84, 0x5c, 0xa0, 0x6d, 0x4c, 0x4d, 0xdc, 0x21,
  36096. 0x43, 0x3e, 0x16, 0xb9, 0xc6, 0x2e, 0x44, 0x87,
  36097. 0x1f, 0xdb, 0xc0, 0x5b, 0xa2, 0x18, 0xaf, 0x87,
  36098. 0x1f, 0xdd, 0x7d, 0xcf, 0xa4, 0x64, 0xe6, 0x0f,
  36099. 0xaa, 0x52, 0x65, 0x26, 0x4c, 0xe1, 0x39, 0x1b,
  36100. 0xd9, 0xa8, 0xc5, 0xfa, 0xa7, 0x62, 0x6d, 0x5f,
  36101. 0x15, 0x9b, 0x98, 0x05, 0xb9, 0x75, 0x71, 0x0a,
  36102. 0x35, 0x03, 0xa0, 0xb8, 0x58, 0xa1, 0x1c, 0x6a,
  36103. 0x64, 0x7c, 0xc0, 0xe1, 0x9a, 0xc8, 0x8b, 0x1b,
  36104. 0xe9, 0x05, 0x6c, 0x95, 0xb4, 0xd2, 0x08, 0x7d,
  36105. 0x09, 0x51, 0xd1, 0xd2, 0xf4, 0x99, 0x24, 0x91,
  36106. 0x11, 0x7e, 0x63, 0x47, 0x79, 0x4b, 0xa5, 0x45,
  36107. 0x71, 0xec, 0x49, 0xbb, 0xa7, 0x1a, 0xf3, 0x41,
  36108. 0x3d, 0x38, 0xa3, 0x0b, 0xf5, 0x87, 0x22, 0x48,
  36109. 0xd1, 0xf6, 0xd0, 0x7c, 0x86, 0xba, 0xf7, 0x82,
  36110. 0xe7, 0x3d, 0x26, 0x37, 0xf0, 0x43, 0xd3, 0x41,
  36111. 0xa0, 0x09, 0x21, 0x85, 0x7d, 0x8b, 0x21, 0xdd,
  36112. 0xf3, 0xe1, 0xd6, 0x31, 0x00, 0x36, 0xed, 0x27,
  36113. 0xaf, 0x49, 0xe5, 0xde, 0x1b, 0x90, 0x0f, 0xe4,
  36114. 0xde, 0x79, 0x80, 0x8f, 0xf2, 0x9f, 0x95, 0x70,
  36115. 0x85, 0x96, 0x12, 0xb1, 0x5a, 0xdc, 0x01, 0xfb,
  36116. 0xb2, 0x65, 0xb3, 0x05, 0xb1, 0xe3, 0xa1, 0x2a,
  36117. 0xe4, 0x19, 0xda, 0x5b, 0x74, 0x26, 0x1f, 0xa2,
  36118. 0x84, 0xc1, 0x01, 0xda, 0x3d, 0x8d, 0xca, 0x8b,
  36119. 0x2e, 0x45, 0x21, 0xac, 0xa5, 0x71, 0xef, 0x44,
  36120. 0xa0, 0x58, 0xe8, 0x44, 0xff, 0x32, 0xb1, 0x6d,
  36121. 0x5a, 0xae, 0xa0, 0x5f, 0x7f, 0x3a, 0xf8, 0xe2,
  36122. 0xab, 0x16, 0x22, 0x2e, 0x34, 0x76, 0x62, 0xed,
  36123. 0xdf, 0xb8, 0x91, 0xd0, 0xec, 0xc2, 0xa5, 0x5c,
  36124. 0x56, 0x38, 0xf9, 0xdd, 0xe9, 0x2d, 0x9a, 0x3d,
  36125. 0x54, 0x4a, 0x5f, 0x90, 0x1a, 0xc5, 0x01, 0xac,
  36126. 0xd1, 0xea, 0x6a, 0x01, 0x02, 0x01, 0xfc, 0xb1,
  36127. 0x0a, 0xd7, 0x02, 0xc4, 0x25, 0xa9, 0x4b, 0xdf,
  36128. 0x58, 0x90, 0xd5, 0x00, 0xa2, 0xa1, 0x47, 0xee,
  36129. 0xe1, 0xd1, 0xfc, 0xba, 0x8c, 0x3a, 0xbe, 0x7c,
  36130. 0x2d, 0xfe, 0x70, 0xf3, 0x46, 0xf0, 0x33, 0xd8,
  36131. 0x16, 0xa0, 0xb2, 0x79, 0x1b, 0x4f, 0x0b, 0x2d,
  36132. 0x95, 0x6d, 0x9e, 0xe5, 0x97, 0x17, 0x15, 0x39,
  36133. 0x9a, 0x56, 0x88, 0x30, 0x24, 0x95, 0xe2, 0xe0,
  36134. 0x7c, 0x1c, 0x8c, 0x01, 0x52, 0x71, 0x84, 0xbc,
  36135. 0xd0, 0xc2, 0x08, 0xbc, 0x15, 0x9f, 0x2e, 0x13,
  36136. 0x31, 0x8c, 0x0b, 0xb3, 0xdd, 0x24, 0xa6, 0xa7,
  36137. 0xfc, 0x84, 0x9f, 0x83, 0x38, 0x5e, 0xd4, 0xdb,
  36138. 0xa0, 0x7f, 0xe1, 0xd7, 0xbd, 0x56, 0x40, 0xcc,
  36139. 0x9e, 0xd5, 0xcc, 0xfd, 0xd6, 0x87, 0x63, 0xcb,
  36140. 0x0d, 0x0e, 0xdf, 0x61, 0xb2, 0x92, 0x17, 0x7f,
  36141. 0xc1, 0xd2, 0xd3, 0xc1, 0x1d, 0xd0, 0x49, 0x50,
  36142. 0x56, 0xbc, 0xb1, 0x25, 0x58, 0xae, 0xbc, 0xfd,
  36143. 0xde, 0xf9, 0xfe, 0xb4, 0xae, 0xbc, 0x57, 0xaf,
  36144. 0xd9, 0x02, 0x3c, 0x65, 0xcf, 0xe6, 0x5a, 0x24,
  36145. 0xe3, 0x3f, 0x1b, 0x00, 0x11, 0x1e, 0x92, 0xe6,
  36146. 0x3e, 0x01, 0x1e, 0xaf, 0x0b, 0x21, 0x2c, 0xf9,
  36147. 0x57, 0x43, 0xcd, 0x07, 0xf5, 0x18, 0x9e, 0xce,
  36148. 0x1f, 0x20, 0x5b, 0x7f, 0x6f, 0xcb, 0x2e, 0x6b,
  36149. 0x19, 0x61, 0xb5, 0x40, 0x4c, 0xeb, 0xe4, 0x7c,
  36150. 0x8c, 0xd1, 0x3b, 0x85, 0x99, 0xd5, 0xb4, 0x9e,
  36151. 0x6d, 0x87, 0xee, 0xda, 0x36, 0xe9, 0xb8, 0xfc,
  36152. 0x4c, 0x00, 0x63, 0x58, 0x96, 0xaa, 0x2b, 0x75,
  36153. 0x89, 0x6e, 0x33, 0x6d, 0x1b, 0x61, 0x2e, 0xe1,
  36154. 0x3d, 0xb8, 0x11, 0xe1, 0xf0, 0x7e, 0x61, 0x74,
  36155. 0x8d, 0x92, 0x0f, 0x48, 0x65, 0xf3, 0xf1, 0x17,
  36156. 0x41, 0x39, 0x9d, 0xc6, 0x16, 0x2c, 0x91, 0xca,
  36157. 0x16, 0x8a, 0x02, 0x32, 0x9d, 0xff, 0x82, 0x1d,
  36158. 0x58, 0x19, 0x87, 0x12, 0xdd, 0x55, 0x8a, 0xbb,
  36159. 0x09, 0x9b, 0x3a, 0x0b, 0xaf, 0x9d, 0xa1, 0xb7,
  36160. 0x30, 0xb2, 0xaa, 0x73, 0xbc, 0xf5, 0x8d, 0x74,
  36161. 0xf3, 0x57, 0xb0, 0x6f, 0x72, 0x11, 0xc8, 0x04,
  36162. 0xb6, 0xc8, 0xaf, 0x16, 0xff, 0x35, 0x09, 0xfa,
  36163. 0xd1, 0xd3, 0x5b, 0x14, 0xbf, 0xdc, 0xed, 0x7d,
  36164. 0xb8, 0xa6, 0xa2, 0x5c, 0x48, 0xe5, 0x95, 0x64,
  36165. 0x80, 0x72, 0x4d, 0xaa, 0x05, 0x7c, 0xd6, 0x60,
  36166. 0xb6, 0x7e, 0xe3, 0xe4, 0x72, 0x57, 0x41, 0x82,
  36167. 0x67, 0x9d, 0x48, 0x58, 0x38, 0xa6, 0x47, 0x6e,
  36168. 0xac, 0x02, 0x14, 0x10, 0x75, 0xc8, 0x12, 0xaf,
  36169. 0x79, 0x67, 0xba, 0x7c, 0x91, 0x85, 0xcc, 0x2a,
  36170. 0xbd, 0x2a, 0x45, 0x45, 0xb8, 0x0f, 0x3d, 0x31,
  36171. 0x04, 0xd5, 0x8d, 0x65, 0x4a, 0x57, 0x79, 0x2d,
  36172. 0xcf, 0xab, 0xbe, 0x9c, 0x07, 0x15, 0xe8, 0xde,
  36173. 0x2e, 0xf8, 0x1e, 0xf4, 0x04, 0xc8, 0x16, 0x8f,
  36174. 0xd7, 0xa4, 0x3e, 0xfa, 0xb3, 0xd4, 0x48, 0xe6,
  36175. 0x86, 0xa0, 0x88, 0xef, 0xd2, 0x6a, 0x26, 0x15,
  36176. 0x99, 0x48, 0x92, 0x67, 0x23, 0xd7, 0xec, 0xcc,
  36177. 0x39, 0xe3, 0xc1, 0xb7, 0x19, 0xcf, 0x8b, 0xec,
  36178. 0xb7, 0xbe, 0x7e, 0x96, 0x4f, 0x22, 0xcd, 0x8c,
  36179. 0xb1, 0xb7, 0xe2, 0x5e, 0x80, 0x0e, 0xa9, 0x7d,
  36180. 0x60, 0xa6, 0x4c, 0xc0, 0xbb, 0xd9, 0xcb, 0x40,
  36181. 0x7a, 0x3a, 0xb9, 0xf8, 0x8f, 0x5e, 0x29, 0x16,
  36182. 0x9e, 0xea, 0xfd, 0x4e, 0x03, 0x22, 0xfd, 0xe6,
  36183. 0x59, 0x0a, 0xe0, 0x93, 0xce, 0x8f, 0xee, 0xae,
  36184. 0x98, 0xb6, 0x22, 0xca, 0xa7, 0x55, 0x6f, 0xf4,
  36185. 0x26, 0xc9, 0xe7, 0xa4, 0x04, 0xce, 0x69, 0x35,
  36186. 0x58, 0x30, 0xa7, 0xa6, 0x77, 0x67, 0xa7, 0x6c,
  36187. 0x7d, 0x9a, 0x97, 0xb8, 0x4b, 0xfc, 0xf5, 0x0a,
  36188. 0x02, 0xf7, 0x5c, 0x23, 0x5d, 0x2f, 0x9c, 0x67,
  36189. 0x11, 0x38, 0x04, 0x9f, 0xfc, 0x7c, 0x80, 0x55,
  36190. 0x92, 0x6c, 0x03, 0xeb, 0x3f, 0xb8, 0x7f, 0x96,
  36191. 0x95, 0x18, 0x5a, 0x42, 0xec, 0xa9, 0xa4, 0x16,
  36192. 0x55, 0x87, 0x3d, 0x30, 0xa6, 0xb3, 0xbf, 0x42,
  36193. 0x8b, 0x24, 0x62, 0x23, 0x48, 0x4a, 0x8f, 0xf6,
  36194. 0x1e, 0xe3, 0xee, 0xaf, 0xff, 0x10, 0xe9, 0x9c,
  36195. 0x2c, 0x13, 0xa7, 0x62, 0x84, 0xd0, 0x63, 0xe5,
  36196. 0x6a, 0xb7, 0x11, 0xa3, 0x5a, 0x85, 0xb5, 0x38,
  36197. 0x3d, 0xf8, 0x1d, 0xa2, 0x34, 0x90, 0xf6, 0x6e,
  36198. 0x8e, 0xa3, 0xfc, 0xba, 0x06, 0x7f, 0x55, 0x30,
  36199. 0xc6, 0x54, 0x1c, 0x2b, 0x8f, 0x74, 0x71, 0x7c,
  36200. 0x35, 0x02, 0x3e, 0x7b, 0x9b, 0x39, 0x56, 0xc3,
  36201. 0xee, 0x2f, 0xf8, 0x4b, 0xa0, 0x3c, 0xcf, 0x4b,
  36202. 0x4b, 0x53, 0x21, 0xb9, 0x24, 0x08, 0x95, 0x48,
  36203. 0x1b, 0xc6, 0xd6, 0x3c, 0x16, 0x93, 0xc1, 0x84,
  36204. 0x78, 0x52, 0xf8, 0xe9, 0x7f, 0x50, 0xa1, 0x33,
  36205. 0x53, 0x2a, 0xc3, 0xee, 0x1e, 0x52, 0xd4, 0x64
  36206. };
  36207. #endif
  36208. #ifdef WOLFSSL_KYBER_ORIGINAL
  36209. WOLFSSL_SMALL_STACK_STATIC const byte kyber768_ss[] = {
  36210. 0x91, 0x4C, 0xB6, 0x7F, 0xE5, 0xC3, 0x8E, 0x73,
  36211. 0xBF, 0x74, 0x18, 0x1C, 0x0A, 0xC5, 0x04, 0x28,
  36212. 0xDE, 0xDF, 0x77, 0x50, 0xA9, 0x80, 0x58, 0xF7,
  36213. 0xD5, 0x36, 0x70, 0x87, 0x74, 0x53, 0x5B, 0x29
  36214. };
  36215. #endif
  36216. #ifndef WOLFSSL_NO_ML_KEM
  36217. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_768_ss[] = {
  36218. 0xe7, 0x18, 0x4a, 0x09, 0x75, 0xee, 0x34, 0x70,
  36219. 0x87, 0x8d, 0x2d, 0x15, 0x9e, 0xc8, 0x31, 0x29,
  36220. 0xc8, 0xae, 0xc2, 0x53, 0xd4, 0xee, 0x17, 0xb4,
  36221. 0x81, 0x03, 0x11, 0xd1, 0x98, 0xcd, 0x03, 0x68
  36222. };
  36223. #endif
  36224. #ifdef WOLFSSL_SMALL_STACK
  36225. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  36226. DYNAMIC_TYPE_TMP_BUFFER);
  36227. priv = (byte *)XMALLOC(KYBER768_PRIVATE_KEY_SIZE, HEAP_HINT,
  36228. DYNAMIC_TYPE_TMP_BUFFER);
  36229. pub = (byte *)XMALLOC(KYBER768_PUBLIC_KEY_SIZE, HEAP_HINT,
  36230. DYNAMIC_TYPE_TMP_BUFFER);
  36231. ct = (byte *)XMALLOC(KYBER768_CIPHER_TEXT_SIZE, HEAP_HINT,
  36232. DYNAMIC_TYPE_TMP_BUFFER);
  36233. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36234. DYNAMIC_TYPE_TMP_BUFFER);
  36235. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  36236. DYNAMIC_TYPE_TMP_BUFFER);
  36237. if (! (key && priv && pub && ct && ss && ss_dec))
  36238. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  36239. #endif
  36240. #ifdef WOLFSSL_KYBER_ORIGINAL
  36241. ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
  36242. if (ret != 0)
  36243. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36244. else
  36245. key_inited = 1;
  36246. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36247. sizeof(kyber768_rand));
  36248. if (ret != 0)
  36249. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36250. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
  36251. if (ret != 0)
  36252. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36253. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
  36254. if (ret != 0)
  36255. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36256. if (XMEMCMP(pub, kyber768_pk, sizeof(kyber768_pk)) != 0)
  36257. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36258. if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
  36259. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36260. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36261. sizeof(kyber768enc_rand));
  36262. if (ret != 0)
  36263. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36264. if (XMEMCMP(ct, kyber768_ct, sizeof(kyber768_ct)) != 0)
  36265. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36266. if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36267. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36268. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
  36269. if (ret != 0)
  36270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36271. if (XMEMCMP(ss_dec, kyber768_ss, sizeof(kyber768_ss)) != 0)
  36272. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36273. #endif
  36274. #ifndef WOLFSSL_NO_ML_KEM
  36275. ret = wc_KyberKey_Init(WC_ML_KEM_768, key, HEAP_HINT, INVALID_DEVID);
  36276. if (ret != 0)
  36277. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36278. else
  36279. key_inited = 1;
  36280. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
  36281. sizeof(kyber768_rand));
  36282. if (ret != 0)
  36283. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36284. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_768_PUBLIC_KEY_SIZE);
  36285. if (ret != 0)
  36286. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36287. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  36288. WC_ML_KEM_768_PRIVATE_KEY_SIZE);
  36289. if (ret != 0)
  36290. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36291. if (XMEMCMP(pub, ml_kem_768_pk, sizeof(ml_kem_768_pk)) != 0)
  36292. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36293. if (XMEMCMP(priv, ml_kem_768_sk, sizeof(ml_kem_768_sk)) != 0)
  36294. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36295. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
  36296. sizeof(kyber768enc_rand));
  36297. if (ret != 0)
  36298. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36299. if (XMEMCMP(ct, ml_kem_768_ct, sizeof(ml_kem_768_ct)) != 0)
  36300. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36301. if (XMEMCMP(ss, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36302. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36303. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_768_ct));
  36304. if (ret != 0)
  36305. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  36306. if (XMEMCMP(ss_dec, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
  36307. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  36308. #endif
  36309. out:
  36310. if (key_inited)
  36311. wc_KyberKey_Free(key);
  36312. #ifdef WOLFSSL_SMALL_STACK
  36313. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36314. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36315. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36316. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36317. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36318. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  36319. #endif
  36320. return ret;
  36321. }
  36322. #endif /* WOLFSSL_KYBER768 */
  36323. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  36324. static wc_test_ret_t kyber1024_kat(void)
  36325. {
  36326. wc_test_ret_t ret;
  36327. #ifdef WOLFSSL_SMALL_STACK
  36328. KyberKey *key = NULL;
  36329. byte *priv = NULL;
  36330. byte *pub = NULL;
  36331. byte *ct = NULL;
  36332. byte *ss = NULL;
  36333. byte *ss_dec = NULL;
  36334. #else
  36335. KyberKey key[1];
  36336. byte priv[KYBER1024_PRIVATE_KEY_SIZE];
  36337. byte pub[KYBER1024_PUBLIC_KEY_SIZE];
  36338. byte ct[KYBER1024_CIPHER_TEXT_SIZE];
  36339. byte ss[KYBER_SS_SZ];
  36340. byte ss_dec[KYBER_SS_SZ];
  36341. #endif
  36342. int key_inited = 0;
  36343. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_rand[] = {
  36344. 0x7c, 0x99, 0x35, 0xa0, 0xb0, 0x76, 0x94, 0xaa,
  36345. 0x0c, 0x6d, 0x10, 0xe4, 0xdb, 0x6b, 0x1a, 0xdd,
  36346. 0x2f, 0xd8, 0x1a, 0x25, 0xcc, 0xb1, 0x48, 0x03,
  36347. 0x2d, 0xcd, 0x73, 0x99, 0x36, 0x73, 0x7f, 0x2d,
  36348. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  36349. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  36350. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  36351. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  36352. };
  36353. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024enc_rand[] = {
  36354. 0x14, 0x7c, 0x03, 0xf7, 0xa5, 0xbe, 0xbb, 0xa4,
  36355. 0x06, 0xc8, 0xfa, 0xe1, 0x87, 0x4d, 0x7f, 0x13,
  36356. 0xc8, 0x0e, 0xfe, 0x79, 0xa3, 0xa9, 0xa8, 0x74,
  36357. 0xcc, 0x09, 0xfe, 0x76, 0xf6, 0x99, 0x76, 0x15
  36358. };
  36359. #ifdef WOLFSSL_KYBER_ORIGINAL
  36360. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_pk[] = {
  36361. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36362. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36363. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36364. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36365. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36366. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36367. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36368. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36369. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36370. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36371. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36372. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36373. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36374. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36375. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36376. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36377. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36378. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36379. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36380. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36381. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36382. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36383. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36384. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36385. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36386. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36387. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36388. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36389. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36390. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36391. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36392. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36393. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36394. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36395. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36396. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36397. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36398. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36399. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36400. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36401. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36402. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36403. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36404. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36405. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36406. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36407. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  36408. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  36409. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  36410. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  36411. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  36412. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  36413. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  36414. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  36415. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  36416. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  36417. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  36418. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  36419. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  36420. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  36421. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  36422. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  36423. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  36424. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  36425. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  36426. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  36427. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  36428. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  36429. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  36430. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  36431. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  36432. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  36433. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  36434. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  36435. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  36436. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  36437. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  36438. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  36439. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  36440. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  36441. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  36442. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  36443. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  36444. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  36445. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  36446. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  36447. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  36448. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  36449. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  36450. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  36451. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  36452. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  36453. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  36454. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  36455. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  36456. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  36457. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  36458. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  36459. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  36460. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  36461. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  36462. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  36463. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  36464. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  36465. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  36466. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  36467. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  36468. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  36469. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  36470. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  36471. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  36472. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  36473. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  36474. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  36475. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  36476. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  36477. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  36478. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  36479. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  36480. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  36481. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  36482. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  36483. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  36484. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  36485. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  36486. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  36487. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  36488. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  36489. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  36490. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  36491. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  36492. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  36493. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  36494. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  36495. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  36496. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  36497. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  36498. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  36499. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  36500. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  36501. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  36502. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  36503. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  36504. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  36505. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  36506. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  36507. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  36508. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  36509. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  36510. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  36511. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  36512. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  36513. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  36514. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  36515. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  36516. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  36517. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  36518. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  36519. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  36520. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  36521. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  36522. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  36523. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  36524. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  36525. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  36526. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  36527. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  36528. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  36529. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  36530. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  36531. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  36532. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  36533. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  36534. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  36535. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  36536. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  36537. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  36538. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  36539. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  36540. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  36541. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  36542. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  36543. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  36544. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  36545. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  36546. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  36547. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  36548. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  36549. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  36550. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  36551. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  36552. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  36553. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  36554. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  36555. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  36556. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22
  36557. };
  36558. #endif
  36559. #ifndef WOLFSSL_NO_ML_KEM
  36560. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_pk[] = {
  36561. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  36562. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  36563. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  36564. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  36565. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  36566. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  36567. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  36568. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  36569. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  36570. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  36571. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  36572. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  36573. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  36574. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  36575. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  36576. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  36577. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  36578. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  36579. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  36580. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  36581. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  36582. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  36583. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  36584. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  36585. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  36586. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  36587. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  36588. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  36589. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  36590. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  36591. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  36592. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  36593. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  36594. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  36595. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  36596. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  36597. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  36598. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  36599. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  36600. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  36601. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  36602. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  36603. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  36604. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  36605. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  36606. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  36607. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  36608. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  36609. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  36610. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  36611. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  36612. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  36613. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  36614. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  36615. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  36616. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  36617. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  36618. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  36619. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  36620. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  36621. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  36622. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  36623. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  36624. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  36625. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  36626. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  36627. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  36628. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  36629. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  36630. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  36631. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  36632. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  36633. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  36634. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  36635. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  36636. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  36637. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  36638. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  36639. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  36640. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  36641. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  36642. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  36643. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  36644. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  36645. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  36646. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  36647. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  36648. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  36649. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  36650. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  36651. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  36652. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  36653. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  36654. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  36655. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  36656. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  36657. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  36658. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  36659. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  36660. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  36661. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  36662. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  36663. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  36664. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  36665. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  36666. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  36667. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  36668. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  36669. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  36670. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  36671. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  36672. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  36673. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  36674. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  36675. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  36676. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  36677. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  36678. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  36679. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  36680. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  36681. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  36682. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  36683. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  36684. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  36685. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  36686. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  36687. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  36688. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  36689. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  36690. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  36691. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  36692. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  36693. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  36694. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  36695. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  36696. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  36697. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  36698. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  36699. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  36700. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  36701. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  36702. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  36703. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  36704. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  36705. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  36706. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  36707. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  36708. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  36709. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  36710. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  36711. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  36712. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  36713. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  36714. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  36715. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  36716. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  36717. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  36718. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  36719. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  36720. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  36721. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  36722. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  36723. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  36724. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  36725. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  36726. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  36727. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  36728. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  36729. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  36730. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  36731. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  36732. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  36733. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  36734. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  36735. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  36736. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  36737. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  36738. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  36739. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  36740. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  36741. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  36742. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  36743. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  36744. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  36745. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  36746. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  36747. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  36748. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  36749. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  36750. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  36751. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  36752. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  36753. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  36754. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  36755. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  36756. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb
  36757. };
  36758. #endif
  36759. #ifdef WOLFSSL_KYBER_ORIGINAL
  36760. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_sk[] = {
  36761. 0x07, 0x63, 0x8F, 0xB6, 0x98, 0x68, 0xF3, 0xD3,
  36762. 0x20, 0xE5, 0x86, 0x2B, 0xD9, 0x69, 0x33, 0xFE,
  36763. 0xB3, 0x11, 0xB3, 0x62, 0x09, 0x3C, 0x9B, 0x5D,
  36764. 0x50, 0x17, 0x0B, 0xCE, 0xD4, 0x3F, 0x1B, 0x53,
  36765. 0x6D, 0x9A, 0x20, 0x4B, 0xB1, 0xF2, 0x26, 0x95,
  36766. 0x95, 0x0B, 0xA1, 0xF2, 0xA9, 0xE8, 0xEB, 0x82,
  36767. 0x8B, 0x28, 0x44, 0x88, 0x76, 0x0B, 0x3F, 0xC8,
  36768. 0x4F, 0xAB, 0xA0, 0x42, 0x75, 0xD5, 0x62, 0x8E,
  36769. 0x39, 0xC5, 0xB2, 0x47, 0x13, 0x74, 0x28, 0x3C,
  36770. 0x50, 0x32, 0x99, 0xC0, 0xAB, 0x49, 0xB6, 0x6B,
  36771. 0x8B, 0xBB, 0x56, 0xA4, 0x18, 0x66, 0x24, 0xF9,
  36772. 0x19, 0xA2, 0xBA, 0x59, 0xBB, 0x08, 0xD8, 0x55,
  36773. 0x18, 0x80, 0xC2, 0xBE, 0xFC, 0x4F, 0x87, 0xF2,
  36774. 0x5F, 0x59, 0xAB, 0x58, 0x7A, 0x79, 0xC3, 0x27,
  36775. 0xD7, 0x92, 0xD5, 0x4C, 0x97, 0x4A, 0x69, 0x26,
  36776. 0x2F, 0xF8, 0xA7, 0x89, 0x38, 0x28, 0x9E, 0x9A,
  36777. 0x87, 0xB6, 0x88, 0xB0, 0x83, 0xE0, 0x59, 0x5F,
  36778. 0xE2, 0x18, 0xB6, 0xBB, 0x15, 0x05, 0x94, 0x1C,
  36779. 0xE2, 0xE8, 0x1A, 0x5A, 0x64, 0xC5, 0xAA, 0xC6,
  36780. 0x04, 0x17, 0x25, 0x69, 0x85, 0x34, 0x9E, 0xE4,
  36781. 0x7A, 0x52, 0x42, 0x0A, 0x5F, 0x97, 0x47, 0x7B,
  36782. 0x72, 0x36, 0xAC, 0x76, 0xBC, 0x70, 0xE8, 0x28,
  36783. 0x87, 0x29, 0x28, 0x7E, 0xE3, 0xE3, 0x4A, 0x3D,
  36784. 0xBC, 0x36, 0x83, 0xC0, 0xB7, 0xB1, 0x00, 0x29,
  36785. 0xFC, 0x20, 0x34, 0x18, 0x53, 0x7E, 0x74, 0x66,
  36786. 0xBA, 0x63, 0x85, 0xA8, 0xFF, 0x30, 0x1E, 0xE1,
  36787. 0x27, 0x08, 0xF8, 0x2A, 0xAA, 0x1E, 0x38, 0x0F,
  36788. 0xC7, 0xA8, 0x8F, 0x8F, 0x20, 0x5A, 0xB7, 0xE8,
  36789. 0x8D, 0x7E, 0x95, 0x95, 0x2A, 0x55, 0xBA, 0x20,
  36790. 0xD0, 0x9B, 0x79, 0xA4, 0x71, 0x41, 0xD6, 0x2B,
  36791. 0xF6, 0xEB, 0x7D, 0xD3, 0x07, 0xB0, 0x8E, 0xCA,
  36792. 0x13, 0xA5, 0xBC, 0x5F, 0x6B, 0x68, 0x58, 0x1C,
  36793. 0x68, 0x65, 0xB2, 0x7B, 0xBC, 0xDD, 0xAB, 0x14,
  36794. 0x2F, 0x4B, 0x2C, 0xBF, 0xF4, 0x88, 0xC8, 0xA2,
  36795. 0x27, 0x05, 0xFA, 0xA9, 0x8A, 0x2B, 0x9E, 0xEA,
  36796. 0x35, 0x30, 0xC7, 0x66, 0x62, 0x33, 0x5C, 0xC7,
  36797. 0xEA, 0x3A, 0x00, 0x77, 0x77, 0x25, 0xEB, 0xCC,
  36798. 0xCD, 0x2A, 0x46, 0x36, 0xB2, 0xD9, 0x12, 0x2F,
  36799. 0xF3, 0xAB, 0x77, 0x12, 0x3C, 0xE0, 0x88, 0x3C,
  36800. 0x19, 0x11, 0x11, 0x5E, 0x50, 0xC9, 0xE8, 0xA9,
  36801. 0x41, 0x94, 0xE4, 0x8D, 0xD0, 0xD0, 0x9C, 0xFF,
  36802. 0xB3, 0xAD, 0xCD, 0x2C, 0x1E, 0x92, 0x43, 0x09,
  36803. 0x03, 0xD0, 0x7A, 0xDB, 0xF0, 0x05, 0x32, 0x03,
  36804. 0x15, 0x75, 0xAA, 0x7F, 0x9E, 0x7B, 0x5A, 0x1F,
  36805. 0x33, 0x62, 0xDE, 0xC9, 0x36, 0xD4, 0x04, 0x3C,
  36806. 0x05, 0xF2, 0x47, 0x6C, 0x07, 0x57, 0x8B, 0xC9,
  36807. 0xCB, 0xAF, 0x2A, 0xB4, 0xE3, 0x82, 0x72, 0x7A,
  36808. 0xD4, 0x16, 0x86, 0xA9, 0x6B, 0x25, 0x48, 0x82,
  36809. 0x0B, 0xB0, 0x3B, 0x32, 0xF1, 0x1B, 0x28, 0x11,
  36810. 0xAD, 0x62, 0xF4, 0x89, 0xE9, 0x51, 0x63, 0x2A,
  36811. 0xBA, 0x0D, 0x1D, 0xF8, 0x96, 0x80, 0xCC, 0x8A,
  36812. 0x8B, 0x53, 0xB4, 0x81, 0xD9, 0x2A, 0x68, 0xD7,
  36813. 0x0B, 0x4E, 0xA1, 0xC3, 0xA6, 0xA5, 0x61, 0xC0,
  36814. 0x69, 0x28, 0x82, 0xB5, 0xCA, 0x8C, 0xC9, 0x42,
  36815. 0xA8, 0xD4, 0x95, 0xAF, 0xCB, 0x06, 0xDE, 0x89,
  36816. 0x49, 0x8F, 0xB9, 0x35, 0xB7, 0x75, 0x90, 0x8F,
  36817. 0xE7, 0xA0, 0x3E, 0x32, 0x4D, 0x54, 0xCC, 0x19,
  36818. 0xD4, 0xE1, 0xAA, 0xBD, 0x35, 0x93, 0xB3, 0x8B,
  36819. 0x19, 0xEE, 0x13, 0x88, 0xFE, 0x49, 0x2B, 0x43,
  36820. 0x12, 0x7E, 0x5A, 0x50, 0x42, 0x53, 0x78, 0x6A,
  36821. 0x0D, 0x69, 0xAD, 0x32, 0x60, 0x1C, 0x28, 0xE2,
  36822. 0xC8, 0x85, 0x04, 0xA5, 0xBA, 0x59, 0x97, 0x06,
  36823. 0x02, 0x3A, 0x61, 0x36, 0x3E, 0x17, 0xC6, 0xB9,
  36824. 0xBB, 0x59, 0xBD, 0xC6, 0x97, 0x45, 0x2C, 0xD0,
  36825. 0x59, 0x45, 0x19, 0x83, 0xD7, 0x38, 0xCA, 0x3F,
  36826. 0xD0, 0x34, 0xE3, 0xF5, 0x98, 0x88, 0x54, 0xCA,
  36827. 0x05, 0x03, 0x1D, 0xB0, 0x96, 0x11, 0x49, 0x89,
  36828. 0x88, 0x19, 0x7C, 0x6B, 0x30, 0xD2, 0x58, 0xDF,
  36829. 0xE2, 0x62, 0x65, 0x54, 0x1C, 0x89, 0xA4, 0xB3,
  36830. 0x1D, 0x68, 0x64, 0xE9, 0x38, 0x9B, 0x03, 0xCB,
  36831. 0x74, 0xF7, 0xEC, 0x43, 0x23, 0xFB, 0x94, 0x21,
  36832. 0xA4, 0xB9, 0x79, 0x0A, 0x26, 0xD1, 0x7B, 0x03,
  36833. 0x98, 0xA2, 0x67, 0x67, 0x35, 0x09, 0x09, 0xF8,
  36834. 0x4D, 0x57, 0xB6, 0x69, 0x4D, 0xF8, 0x30, 0x66,
  36835. 0x4C, 0xA8, 0xB3, 0xC3, 0xC0, 0x3E, 0xD2, 0xAE,
  36836. 0x67, 0xB8, 0x90, 0x06, 0x86, 0x8A, 0x68, 0x52,
  36837. 0x7C, 0xCD, 0x66, 0x64, 0x59, 0xAB, 0x7F, 0x05,
  36838. 0x66, 0x71, 0x00, 0x0C, 0x61, 0x64, 0xD3, 0xA7,
  36839. 0xF2, 0x66, 0xA1, 0x4D, 0x97, 0xCB, 0xD7, 0x00,
  36840. 0x4D, 0x6C, 0x92, 0xCA, 0xCA, 0x77, 0x0B, 0x84,
  36841. 0x4A, 0x4F, 0xA9, 0xB1, 0x82, 0xE7, 0xB1, 0x8C,
  36842. 0xA8, 0x85, 0x08, 0x2A, 0xC5, 0x64, 0x6F, 0xCB,
  36843. 0x4A, 0x14, 0xE1, 0x68, 0x5F, 0xEB, 0x0C, 0x9C,
  36844. 0xE3, 0x37, 0x2A, 0xB9, 0x53, 0x65, 0xC0, 0x4F,
  36845. 0xD8, 0x30, 0x84, 0xF8, 0x0A, 0x23, 0xFF, 0x10,
  36846. 0xA0, 0x5B, 0xF1, 0x5F, 0x7F, 0xA5, 0xAC, 0xC6,
  36847. 0xC0, 0xCB, 0x46, 0x2C, 0x33, 0xCA, 0x52, 0x4F,
  36848. 0xA6, 0xB8, 0xBB, 0x35, 0x90, 0x43, 0xBA, 0x68,
  36849. 0x60, 0x9E, 0xAA, 0x25, 0x36, 0xE8, 0x1D, 0x08,
  36850. 0x46, 0x3B, 0x19, 0x65, 0x3B, 0x54, 0x35, 0xBA,
  36851. 0x94, 0x6C, 0x9A, 0xDD, 0xEB, 0x20, 0x2B, 0x04,
  36852. 0xB0, 0x31, 0xCC, 0x96, 0x0D, 0xCC, 0x12, 0xE4,
  36853. 0x51, 0x8D, 0x42, 0x8B, 0x32, 0xB2, 0x57, 0xA4,
  36854. 0xFC, 0x73, 0x13, 0xD3, 0xA7, 0x98, 0x0D, 0x80,
  36855. 0x08, 0x2E, 0x93, 0x4F, 0x9D, 0x95, 0xC3, 0x2B,
  36856. 0x0A, 0x01, 0x91, 0xA2, 0x36, 0x04, 0x38, 0x4D,
  36857. 0xD9, 0xE0, 0x79, 0xBB, 0xBA, 0xA2, 0x66, 0xD1,
  36858. 0x4C, 0x3F, 0x75, 0x6B, 0x9F, 0x21, 0x33, 0x10,
  36859. 0x74, 0x33, 0xA4, 0xE8, 0x3F, 0xA7, 0x18, 0x72,
  36860. 0x82, 0xA8, 0x09, 0x20, 0x3A, 0x4F, 0xAF, 0x84,
  36861. 0x18, 0x51, 0x83, 0x3D, 0x12, 0x1A, 0xC3, 0x83,
  36862. 0x84, 0x3A, 0x5E, 0x55, 0xBC, 0x23, 0x81, 0x42,
  36863. 0x5E, 0x16, 0xC7, 0xDB, 0x4C, 0xC9, 0xAB, 0x5C,
  36864. 0x1B, 0x0D, 0x91, 0xA4, 0x7E, 0x2B, 0x8D, 0xE0,
  36865. 0xE5, 0x82, 0xC8, 0x6B, 0x6B, 0x0D, 0x90, 0x7B,
  36866. 0xB3, 0x60, 0xB9, 0x7F, 0x40, 0xAB, 0x5D, 0x03,
  36867. 0x8F, 0x6B, 0x75, 0xC8, 0x14, 0xB2, 0x7D, 0x9B,
  36868. 0x96, 0x8D, 0x41, 0x98, 0x32, 0xBC, 0x8C, 0x2B,
  36869. 0xEE, 0x60, 0x5E, 0xF6, 0xE5, 0x05, 0x9D, 0x33,
  36870. 0x10, 0x0D, 0x90, 0x48, 0x5D, 0x37, 0x84, 0x50,
  36871. 0x01, 0x42, 0x21, 0x73, 0x6C, 0x07, 0x40, 0x7C,
  36872. 0xAC, 0x26, 0x04, 0x08, 0xAA, 0x64, 0x92, 0x66,
  36873. 0x19, 0x78, 0x8B, 0x86, 0x01, 0xC2, 0xA7, 0x52,
  36874. 0xD1, 0xA6, 0xCB, 0xF8, 0x20, 0xD7, 0xC7, 0xA0,
  36875. 0x47, 0x16, 0x20, 0x32, 0x25, 0xB3, 0x89, 0x5B,
  36876. 0x93, 0x42, 0xD1, 0x47, 0xA8, 0x18, 0x5C, 0xFC,
  36877. 0x1B, 0xB6, 0x5B, 0xA0, 0x6B, 0x41, 0x42, 0x33,
  36878. 0x99, 0x03, 0xC0, 0xAC, 0x46, 0x51, 0x38, 0x5B,
  36879. 0x45, 0xD9, 0x8A, 0x8B, 0x19, 0xD2, 0x8C, 0xD6,
  36880. 0xBA, 0xB0, 0x88, 0x78, 0x7F, 0x7E, 0xE1, 0xB1,
  36881. 0x24, 0x61, 0x76, 0x6B, 0x43, 0xCB, 0xCC, 0xB9,
  36882. 0x64, 0x34, 0x42, 0x7D, 0x93, 0xC0, 0x65, 0x55,
  36883. 0x06, 0x88, 0xF6, 0x94, 0x8E, 0xD1, 0xB5, 0x47,
  36884. 0x5A, 0x42, 0x5F, 0x1B, 0x85, 0x20, 0x9D, 0x06,
  36885. 0x1C, 0x08, 0xB5, 0x6C, 0x1C, 0xC0, 0x69, 0xF6,
  36886. 0xC0, 0xA7, 0xC6, 0xF2, 0x93, 0x58, 0xCA, 0xB9,
  36887. 0x11, 0x08, 0x77, 0x32, 0xA6, 0x49, 0xD2, 0x7C,
  36888. 0x9B, 0x98, 0xF9, 0xA4, 0x88, 0x79, 0x38, 0x7D,
  36889. 0x9B, 0x00, 0xC2, 0x59, 0x59, 0xA7, 0x16, 0x54,
  36890. 0xD6, 0xF6, 0xA9, 0x46, 0x16, 0x45, 0x13, 0xE4,
  36891. 0x7A, 0x75, 0xD0, 0x05, 0x98, 0x6C, 0x23, 0x63,
  36892. 0xC0, 0x9F, 0x6B, 0x53, 0x7E, 0xCA, 0x78, 0xB9,
  36893. 0x30, 0x3A, 0x5F, 0xA4, 0x57, 0x60, 0x8A, 0x58,
  36894. 0x6A, 0x65, 0x3A, 0x34, 0x7D, 0xB0, 0x4D, 0xFC,
  36895. 0xC1, 0x91, 0x75, 0xB3, 0xA3, 0x01, 0x17, 0x25,
  36896. 0x36, 0x06, 0x2A, 0x65, 0x8A, 0x95, 0x27, 0x75,
  36897. 0x70, 0xC8, 0x85, 0x2C, 0xA8, 0x97, 0x3F, 0x4A,
  36898. 0xE1, 0x23, 0xA3, 0x34, 0x04, 0x7D, 0xD7, 0x11,
  36899. 0xC8, 0x92, 0x7A, 0x63, 0x4A, 0x03, 0x38, 0x8A,
  36900. 0x52, 0x7B, 0x03, 0x4B, 0xF7, 0xA8, 0x17, 0x0F,
  36901. 0xA7, 0x02, 0xC1, 0xF7, 0xC2, 0x3E, 0xC3, 0x2D,
  36902. 0x18, 0xA2, 0x37, 0x48, 0x90, 0xBE, 0x9C, 0x78,
  36903. 0x7A, 0x94, 0x09, 0xC8, 0x2D, 0x19, 0x2C, 0x4B,
  36904. 0xB7, 0x05, 0xA2, 0xF9, 0x96, 0xCE, 0x40, 0x5D,
  36905. 0x85, 0xA4, 0xC1, 0xA1, 0xAB, 0x9B, 0x6A, 0xEB,
  36906. 0x49, 0xCC, 0xE1, 0xC2, 0xF8, 0xA9, 0x7C, 0x35,
  36907. 0x16, 0xC7, 0x2A, 0x00, 0xA4, 0x62, 0x63, 0xBA,
  36908. 0xA6, 0x96, 0xBF, 0x25, 0x72, 0x77, 0x19, 0xC3,
  36909. 0x21, 0x64, 0x23, 0x61, 0x8F, 0xF3, 0x33, 0x80,
  36910. 0x93, 0x4A, 0x6C, 0x10, 0x54, 0x5C, 0x4C, 0x5C,
  36911. 0x51, 0x55, 0xB1, 0x24, 0x86, 0x18, 0x1F, 0xC7,
  36912. 0xA2, 0x31, 0x98, 0x73, 0x97, 0x8B, 0x6A, 0x2A,
  36913. 0x67, 0x49, 0x0F, 0x82, 0x56, 0xBD, 0x21, 0x96,
  36914. 0xFE, 0x17, 0x92, 0xA4, 0xC0, 0x00, 0x77, 0xB8,
  36915. 0x12, 0xEA, 0xE8, 0xBE, 0xD3, 0x57, 0x24, 0x99,
  36916. 0x68, 0x4A, 0xB3, 0x37, 0x18, 0x76, 0x76, 0x1E,
  36917. 0x45, 0x0C, 0x9F, 0x9D, 0x27, 0x68, 0xA3, 0x68,
  36918. 0x06, 0xD7, 0xAB, 0x20, 0x46, 0xC9, 0x1F, 0x17,
  36919. 0x59, 0x9E, 0x9A, 0xC5, 0x92, 0x99, 0x08, 0x08,
  36920. 0xDC, 0xD7, 0xB4, 0xD0, 0x91, 0x90, 0x72, 0xF1,
  36921. 0x4E, 0xC3, 0x61, 0x77, 0x3B, 0x72, 0x52, 0x44,
  36922. 0x4C, 0x32, 0x3C, 0x30, 0x83, 0x26, 0xF4, 0xA3,
  36923. 0x0F, 0x86, 0x80, 0xD2, 0xF7, 0x48, 0xF5, 0x6A,
  36924. 0x13, 0x2B, 0x82, 0x67, 0x4E, 0xD0, 0x18, 0x46,
  36925. 0x20, 0xB8, 0x2A, 0xD2, 0xCB, 0x18, 0x2C, 0x97,
  36926. 0xB4, 0x81, 0x62, 0x66, 0x47, 0x49, 0x12, 0x90,
  36927. 0xA0, 0x11, 0xCC, 0x73, 0x82, 0x86, 0x85, 0xA8,
  36928. 0xC3, 0x67, 0xA5, 0xB9, 0xCF, 0x8D, 0x62, 0x1B,
  36929. 0x0D, 0x5C, 0x1E, 0xFF, 0x03, 0x17, 0x27, 0x58,
  36930. 0xBD, 0x00, 0x49, 0x78, 0xC2, 0x51, 0xCD, 0x51,
  36931. 0x34, 0x22, 0x28, 0x98, 0x9C, 0xAE, 0x63, 0x32,
  36932. 0xAC, 0x48, 0x64, 0x37, 0xCB, 0x5C, 0x57, 0xD4,
  36933. 0x30, 0x74, 0x62, 0x86, 0x52, 0x53, 0xBE, 0x21,
  36934. 0x7B, 0x35, 0x15, 0xC7, 0x3D, 0xF4, 0x05, 0xB7,
  36935. 0xF2, 0x82, 0x17, 0xAD, 0x0B, 0x8C, 0xF6, 0x0C,
  36936. 0x2F, 0xFF, 0xAA, 0x0A, 0x00, 0x48, 0xB1, 0xFB,
  36937. 0x4A, 0xCD, 0xCD, 0xC3, 0x8B, 0x52, 0x50, 0xCF,
  36938. 0xEC, 0x35, 0x6A, 0x6D, 0xE2, 0x6C, 0xFA, 0x7A,
  36939. 0x58, 0x8F, 0xDC, 0x86, 0xF9, 0x8C, 0x85, 0x4A,
  36940. 0xC6, 0x4C, 0x7B, 0xFA, 0xA9, 0x6F, 0x5A, 0x32,
  36941. 0xCC, 0x06, 0x10, 0x93, 0x4B, 0xAA, 0x6A, 0x58,
  36942. 0x6B, 0x9A, 0x20, 0x54, 0xF1, 0x3B, 0xA2, 0x74,
  36943. 0x17, 0x4A, 0xA0, 0xD2, 0xB3, 0xA8, 0x1B, 0x96,
  36944. 0xA9, 0x40, 0x66, 0x6F, 0x78, 0x9B, 0x5A, 0x6B,
  36945. 0xCD, 0xC0, 0xA6, 0xA0, 0x17, 0x8A, 0x0C, 0x9A,
  36946. 0x02, 0x57, 0x8A, 0x49, 0x3F, 0x6E, 0xEA, 0x0D,
  36947. 0x2E, 0x6C, 0x13, 0x95, 0x1C, 0x9F, 0x24, 0x9A,
  36948. 0x5E, 0x8D, 0xD7, 0x1D, 0xD4, 0x9A, 0x74, 0x2D,
  36949. 0x45, 0x1F, 0x1A, 0xBB, 0xA1, 0x9A, 0xF8, 0xC5,
  36950. 0x47, 0x85, 0x5E, 0x0A, 0xFC, 0x72, 0x8E, 0x90,
  36951. 0xAB, 0xB4, 0x99, 0xC9, 0xBE, 0xEB, 0x76, 0x6F,
  36952. 0x47, 0x29, 0xCD, 0xA2, 0x22, 0x63, 0xE3, 0x24,
  36953. 0xD2, 0x23, 0x02, 0xCB, 0xD3, 0x39, 0x9F, 0xAC,
  36954. 0xC6, 0x30, 0x99, 0x1F, 0xC8, 0xF2, 0x8B, 0xDB,
  36955. 0x43, 0x54, 0x76, 0x25, 0x41, 0x52, 0x76, 0x78,
  36956. 0xBC, 0xF6, 0x1F, 0x65, 0xC2, 0x41, 0x14, 0x6C,
  36957. 0x42, 0x6D, 0x23, 0xB9, 0xBF, 0xAA, 0x6B, 0x7D,
  36958. 0xF1, 0x8C, 0x97, 0xF2, 0x0C, 0x1B, 0x61, 0x25,
  36959. 0xBF, 0x87, 0x4B, 0x1D, 0x89, 0x47, 0x58, 0x52,
  36960. 0xC4, 0x48, 0x21, 0x5D, 0xB0, 0xEB, 0x77, 0x37,
  36961. 0xF9, 0x14, 0x80, 0xE8, 0xCE, 0xBD, 0x9A, 0x08,
  36962. 0x71, 0x57, 0x4F, 0x5A, 0xB6, 0x2D, 0x90, 0x20,
  36963. 0x17, 0x5E, 0xC6, 0x92, 0x7C, 0xA0, 0xB5, 0x4C,
  36964. 0x09, 0x81, 0x8E, 0x42, 0xCF, 0x92, 0xA3, 0x83,
  36965. 0x17, 0x24, 0x22, 0xC7, 0xDC, 0x18, 0x31, 0xD6,
  36966. 0x3B, 0x0C, 0x29, 0x5D, 0xE7, 0x51, 0x59, 0xDB,
  36967. 0x80, 0x34, 0xE9, 0xE0, 0x7F, 0x7B, 0x0B, 0x91,
  36968. 0x0C, 0x3C, 0x1E, 0x5F, 0xB6, 0x6B, 0x3D, 0xC5,
  36969. 0x23, 0xF1, 0xFA, 0x6E, 0xB4, 0x91, 0x0C, 0xB8,
  36970. 0x9A, 0x6C, 0x17, 0x56, 0x2C, 0x83, 0xAB, 0x4C,
  36971. 0x18, 0xD0, 0xCD, 0x7E, 0x07, 0x96, 0x59, 0x2A,
  36972. 0x37, 0x2A, 0xA4, 0x09, 0xB1, 0xC5, 0x57, 0x34,
  36973. 0x7C, 0xCA, 0xCD, 0xC4, 0x64, 0x4A, 0x11, 0x90,
  36974. 0x64, 0xD0, 0x6D, 0xD4, 0x74, 0x92, 0x9D, 0x1C,
  36975. 0x6F, 0xB4, 0xD6, 0x86, 0xE5, 0x49, 0x1C, 0xE4,
  36976. 0xBC, 0x89, 0xA3, 0x0B, 0xB4, 0xB8, 0xC4, 0x1B,
  36977. 0xCE, 0x51, 0x57, 0xDF, 0xC1, 0x36, 0x08, 0x23,
  36978. 0xB1, 0xAB, 0x61, 0x8C, 0x14, 0xB1, 0x0F, 0x98,
  36979. 0xC2, 0x50, 0x67, 0x39, 0x8E, 0xA7, 0x01, 0x8C,
  36980. 0x27, 0x8A, 0x4B, 0x3D, 0xF3, 0x13, 0x34, 0xD6,
  36981. 0x03, 0xB2, 0x04, 0x4E, 0xF1, 0x87, 0xCD, 0x9B,
  36982. 0xC6, 0xCE, 0x42, 0x72, 0x5B, 0xD9, 0x62, 0xC2,
  36983. 0x64, 0x98, 0x3E, 0x9E, 0x18, 0x15, 0x5A, 0x8B,
  36984. 0x9C, 0x47, 0x14, 0x3D, 0x70, 0x46, 0x0A, 0x26,
  36985. 0xA5, 0x6F, 0xE7, 0x65, 0x8C, 0x1F, 0x15, 0x03,
  36986. 0x48, 0xC6, 0x08, 0x7E, 0xF7, 0x58, 0xAD, 0x16,
  36987. 0x78, 0x87, 0x86, 0x0A, 0x00, 0x7A, 0x5F, 0xC3,
  36988. 0x73, 0x58, 0xD4, 0x3B, 0x5E, 0xBE, 0xE8, 0x20,
  36989. 0xAC, 0xEA, 0x47, 0x4F, 0x0A, 0xC0, 0x7B, 0x76,
  36990. 0x80, 0x28, 0x66, 0x19, 0x9C, 0x61, 0x23, 0x1D,
  36991. 0x5C, 0x74, 0x7C, 0x93, 0x77, 0x4D, 0x2C, 0x1E,
  36992. 0x0C, 0x1C, 0x67, 0xE6, 0xC8, 0x1B, 0x82, 0x75,
  36993. 0x21, 0x73, 0xE1, 0x25, 0xBA, 0xF3, 0x9B, 0x4F,
  36994. 0xD1, 0x9A, 0x4F, 0x45, 0x3D, 0xC5, 0x79, 0x76,
  36995. 0xB1, 0xD9, 0x7F, 0xE6, 0x99, 0x69, 0x92, 0xBB,
  36996. 0xB6, 0x5B, 0x7C, 0xB2, 0x5D, 0x07, 0x7B, 0xBA,
  36997. 0xA6, 0xA1, 0x33, 0x22, 0x89, 0x9A, 0xF6, 0x59,
  36998. 0xCF, 0x1B, 0x35, 0x58, 0xC1, 0xB5, 0x00, 0x11,
  36999. 0x54, 0xB6, 0x25, 0x80, 0x9E, 0xD8, 0x9A, 0xEE,
  37000. 0xBB, 0x89, 0xE6, 0xEA, 0x7D, 0x67, 0xF7, 0x23,
  37001. 0xD0, 0x45, 0xAB, 0x05, 0x71, 0x5C, 0x42, 0x35,
  37002. 0x5D, 0xA6, 0xA5, 0xC8, 0xDD, 0x39, 0xC8, 0xAB,
  37003. 0xE3, 0x03, 0x77, 0x51, 0xA0, 0x1E, 0xD1, 0xC7,
  37004. 0x37, 0x49, 0x19, 0xF3, 0x12, 0x1B, 0x5A, 0x52,
  37005. 0xC5, 0x3D, 0x14, 0x87, 0x31, 0x67, 0x69, 0xF8,
  37006. 0x07, 0x21, 0xDE, 0xEA, 0xAA, 0xD3, 0xC9, 0x0F,
  37007. 0x76, 0xE7, 0xAE, 0x9E, 0x12, 0xBA, 0x92, 0xB3,
  37008. 0x2B, 0x5F, 0xD4, 0x57, 0xE3, 0xC7, 0x52, 0xC2,
  37009. 0x65, 0x0D, 0xFB, 0x88, 0x57, 0x71, 0xCB, 0x77,
  37010. 0xAC, 0x3C, 0x78, 0x5A, 0x8C, 0x56, 0x2E, 0x6A,
  37011. 0x1C, 0x63, 0xC2, 0xA5, 0x5E, 0xA4, 0x7C, 0xF8,
  37012. 0xB9, 0x0E, 0xB8, 0x22, 0x5C, 0x12, 0x3C, 0x34,
  37013. 0x64, 0x52, 0x56, 0x62, 0x35, 0xB2, 0xF3, 0x18,
  37014. 0x23, 0xA3, 0x35, 0x21, 0xE0, 0x87, 0x93, 0x7A,
  37015. 0x34, 0x5D, 0x8D, 0x66, 0x3E, 0xEA, 0xA0, 0x56,
  37016. 0x58, 0x91, 0x7B, 0xBA, 0xA0, 0x08, 0xC2, 0xE3,
  37017. 0x35, 0xF8, 0x85, 0x0A, 0x90, 0xA3, 0x26, 0xD0,
  37018. 0xE6, 0x64, 0x32, 0xF4, 0x4C, 0xEB, 0x82, 0x89,
  37019. 0xE4, 0xEC, 0xB2, 0xD1, 0x29, 0x58, 0xE9, 0x84,
  37020. 0x07, 0x2E, 0xCA, 0xCB, 0x88, 0xE1, 0x34, 0x8F,
  37021. 0xF0, 0xB5, 0x56, 0x54, 0xAC, 0xBA, 0x5B, 0x54,
  37022. 0x97, 0x1C, 0xBA, 0xEB, 0xA8, 0x8E, 0xC4, 0xB9,
  37023. 0x1A, 0x94, 0xC3, 0x71, 0x92, 0xFA, 0x98, 0x2B,
  37024. 0xEC, 0xB9, 0xF3, 0xDA, 0x42, 0x16, 0x03, 0xB6,
  37025. 0x1A, 0x51, 0xBC, 0x8E, 0x36, 0xCB, 0xD0, 0x53,
  37026. 0x85, 0x1C, 0x77, 0xB1, 0xB9, 0x26, 0xB1, 0x7A,
  37027. 0x27, 0x2A, 0xA9, 0x02, 0x32, 0x46, 0xB0, 0x2B,
  37028. 0x3E, 0xD4, 0x7F, 0x66, 0xA0, 0x0B, 0xD5, 0x68,
  37029. 0x48, 0x23, 0x63, 0x4E, 0x7C, 0xE5, 0x8C, 0xF8,
  37030. 0xF3, 0x06, 0xE3, 0x5B, 0x1E, 0x53, 0x22, 0x82,
  37031. 0x4D, 0x90, 0x48, 0x01, 0xF0, 0xA2, 0xFA, 0x7C,
  37032. 0x2B, 0xC9, 0xC2, 0x52, 0xB0, 0xA5, 0x6B, 0x7B,
  37033. 0xA2, 0xAB, 0x0F, 0x63, 0x60, 0x21, 0x74, 0x5A,
  37034. 0x70, 0xA9, 0xA4, 0x3E, 0x2B, 0x0A, 0x8D, 0x61,
  37035. 0x59, 0x70, 0xB6, 0x53, 0x09, 0x62, 0x4B, 0x51,
  37036. 0x84, 0xBC, 0xC3, 0x0B, 0x91, 0x16, 0x79, 0xAE,
  37037. 0xDD, 0x76, 0x02, 0x5F, 0xE3, 0x90, 0x8F, 0xD6,
  37038. 0x78, 0x97, 0xB0, 0xCF, 0x4B, 0xE5, 0xA6, 0xF5,
  37039. 0x41, 0x3D, 0x7D, 0xD9, 0x85, 0x64, 0xB2, 0x3E,
  37040. 0x42, 0xA9, 0x3E, 0x4A, 0xA8, 0x82, 0x1C, 0xD4,
  37041. 0x50, 0x54, 0xC6, 0x43, 0xED, 0xC1, 0x15, 0x8D,
  37042. 0xB6, 0xB3, 0xDE, 0xB1, 0x3F, 0xB5, 0xA5, 0x1E,
  37043. 0xBD, 0x1A, 0x8A, 0x78, 0xB8, 0x72, 0x25, 0xA7,
  37044. 0x33, 0x8E, 0x10, 0x11, 0x04, 0xC4, 0xA2, 0x20,
  37045. 0xD9, 0xBD, 0xED, 0xD4, 0x8C, 0x85, 0xA1, 0xC2,
  37046. 0xDA, 0xE7, 0x81, 0xA8, 0x0C, 0x40, 0xE1, 0x3B,
  37047. 0x87, 0xEA, 0xC7, 0x3A, 0x76, 0x42, 0x01, 0xC9,
  37048. 0xB7, 0x60, 0xCC, 0xFB, 0x1A, 0xE3, 0x92, 0x69,
  37049. 0x9C, 0x70, 0x39, 0xD2, 0x7C, 0x39, 0x36, 0x2B,
  37050. 0x27, 0xB8, 0xFC, 0x6F, 0x07, 0xA8, 0xA3, 0xD4,
  37051. 0x41, 0x0F, 0x15, 0x47, 0xC4, 0x8A, 0x99, 0x97,
  37052. 0xF6, 0x2C, 0x61, 0x07, 0x44, 0x52, 0xEF, 0x15,
  37053. 0x15, 0xF8, 0xA6, 0x49, 0xEB, 0xCA, 0x94, 0x37,
  37054. 0x20, 0x5A, 0x4E, 0x8A, 0x61, 0x60, 0x6B, 0x41,
  37055. 0xDA, 0xF6, 0x83, 0x4D, 0x67, 0x1F, 0x4D, 0x85,
  37056. 0x2C, 0x0C, 0x9C, 0x40, 0x96, 0x61, 0x16, 0x48,
  37057. 0xC6, 0xA3, 0x17, 0x06, 0x78, 0xB1, 0x53, 0x7C,
  37058. 0xC1, 0x82, 0x8D, 0x93, 0x58, 0x0C, 0x9E, 0x58,
  37059. 0x49, 0xA9, 0x65, 0x31, 0x75, 0xAC, 0xB7, 0x53,
  37060. 0xF2, 0xBE, 0x74, 0x37, 0xBE, 0x45, 0xF6, 0xC6,
  37061. 0x03, 0xE4, 0x85, 0xF2, 0xEC, 0x30, 0x1B, 0xB4,
  37062. 0x2B, 0x6C, 0x37, 0xC2, 0x25, 0xD7, 0x49, 0x5A,
  37063. 0x58, 0x4A, 0xE2, 0x31, 0x89, 0x0A, 0xB5, 0xC8,
  37064. 0xC3, 0x5C, 0x26, 0x8C, 0xF4, 0xBB, 0xB0, 0x21,
  37065. 0x3C, 0x09, 0x60, 0x19, 0x31, 0x95, 0x61, 0xA8,
  37066. 0xA6, 0x94, 0x76, 0x37, 0xAA, 0x40, 0xD0, 0x06,
  37067. 0xB4, 0x15, 0xBB, 0x2C, 0xFA, 0x22, 0x37, 0xE0,
  37068. 0x89, 0x0B, 0x6A, 0x3B, 0xC1, 0x34, 0xAB, 0xF8,
  37069. 0xF6, 0x58, 0x5E, 0x10, 0x8D, 0x15, 0x94, 0x0F,
  37070. 0x91, 0xF4, 0xBF, 0x5B, 0x0C, 0x81, 0x80, 0x55,
  37071. 0xB2, 0x1D, 0xEA, 0x6E, 0x63, 0xB5, 0x53, 0x98,
  37072. 0x8C, 0x47, 0xF4, 0xB9, 0x4E, 0x7C, 0xF8, 0x00,
  37073. 0xA4, 0x93, 0xB4, 0x73, 0x47, 0x05, 0xED, 0xC5,
  37074. 0x6A, 0x4B, 0x60, 0x21, 0xC6, 0x29, 0x50, 0x06,
  37075. 0x75, 0x87, 0x68, 0x04, 0xCF, 0x0B, 0x95, 0x1F,
  37076. 0x03, 0x8A, 0x5C, 0x7F, 0xE5, 0x8E, 0x89, 0x77,
  37077. 0x4E, 0xF2, 0x99, 0x2F, 0xD7, 0xC6, 0x30, 0x99,
  37078. 0xD3, 0x52, 0xA7, 0xD2, 0x15, 0x60, 0xB7, 0x88,
  37079. 0xB4, 0x05, 0x70, 0x98, 0x61, 0x81, 0x7E, 0x59,
  37080. 0xA9, 0x6B, 0x3A, 0x3A, 0x83, 0xCB, 0xA8, 0x03,
  37081. 0xB1, 0x69, 0x34, 0x33, 0x10, 0x71, 0x90, 0x5B,
  37082. 0xBE, 0xC6, 0x53, 0x29, 0x00, 0x15, 0x5D, 0x8A,
  37083. 0xC8, 0x8C, 0xB3, 0x2E, 0x4E, 0x21, 0xA3, 0xBD,
  37084. 0x3A, 0x03, 0xFD, 0xEC, 0x32, 0x5A, 0x51, 0xCD,
  37085. 0x27, 0x73, 0x96, 0x4E, 0x67, 0x84, 0xFC, 0xF1,
  37086. 0x85, 0x37, 0x37, 0xAA, 0x64, 0xEB, 0x67, 0x56,
  37087. 0x47, 0x27, 0x27, 0x26, 0x61, 0xAB, 0xF8, 0x43,
  37088. 0x13, 0xA5, 0x7A, 0x44, 0xB1, 0x23, 0xC6, 0x55,
  37089. 0x09, 0xCF, 0xB7, 0xA6, 0xF6, 0x64, 0x1C, 0xDC,
  37090. 0xC3, 0xB5, 0x7F, 0xE6, 0x28, 0xC7, 0xB8, 0x19,
  37091. 0x2D, 0xB4, 0x4F, 0xFB, 0xF5, 0x79, 0x6A, 0x86,
  37092. 0x13, 0xB1, 0xFA, 0x12, 0x6F, 0x60, 0x76, 0x88,
  37093. 0x3C, 0x78, 0x3D, 0xC2, 0x4E, 0x2A, 0x44, 0x64,
  37094. 0xC4, 0x0B, 0x3A, 0x41, 0xCA, 0x70, 0xAE, 0x87,
  37095. 0x62, 0x08, 0x66, 0xCF, 0x4F, 0xCB, 0x2B, 0xD2,
  37096. 0x04, 0xBF, 0x5C, 0x28, 0x38, 0x12, 0xBA, 0x05,
  37097. 0x6A, 0xC0, 0xC3, 0x45, 0xE3, 0x79, 0xC4, 0xBA,
  37098. 0x24, 0xD7, 0x50, 0x90, 0x12, 0x79, 0xBB, 0x2F,
  37099. 0x3A, 0x16, 0xF6, 0x12, 0xBF, 0xAD, 0xB3, 0x57,
  37100. 0x03, 0x33, 0x2C, 0x7C, 0x13, 0x6F, 0x68, 0xEA,
  37101. 0xB6, 0x75, 0x5C, 0x66, 0xB6, 0xA4, 0xAD, 0x1A,
  37102. 0xAB, 0xA7, 0xB7, 0x68, 0xA5, 0x8A, 0xCA, 0xAC,
  37103. 0xC1, 0x0A, 0x45, 0x9A, 0x1C, 0xC8, 0xEF, 0x29,
  37104. 0x37, 0x7B, 0xC2, 0x00, 0xE4, 0xD3, 0x15, 0xA3,
  37105. 0x0A, 0x6B, 0xCC, 0x32, 0x56, 0xF9, 0x73, 0x4D,
  37106. 0x06, 0xE9, 0x77, 0x9C, 0xAA, 0x54, 0x42, 0xA9,
  37107. 0xA1, 0x60, 0x69, 0x08, 0x13, 0x77, 0xC7, 0x6E,
  37108. 0x75, 0x15, 0x43, 0x68, 0x07, 0x2D, 0xC4, 0x46,
  37109. 0xED, 0x6C, 0x8B, 0x8E, 0x62, 0x2A, 0x21, 0xE3,
  37110. 0x83, 0xCF, 0x9B, 0xA1, 0xFB, 0x43, 0x4E, 0x2E,
  37111. 0xCC, 0x81, 0xE7, 0xB7, 0x8C, 0xEE, 0x98, 0x6B,
  37112. 0x8F, 0xF7, 0x98, 0xAB, 0x18, 0xCF, 0x96, 0x34,
  37113. 0x54, 0x35, 0x46, 0x28, 0x4E, 0xDA, 0x2A, 0x26,
  37114. 0xB4, 0x7F, 0x05, 0xB7, 0x35, 0xBC, 0xDB, 0x12,
  37115. 0x02, 0x22, 0x00, 0x76, 0xDC, 0x8B, 0x4E, 0x4B,
  37116. 0x9F, 0x85, 0x35, 0x33, 0xC8, 0xF6, 0xC7, 0xFF,
  37117. 0x38, 0x81, 0x7B, 0xA4, 0x97, 0x12, 0x83, 0x57,
  37118. 0x85, 0xF1, 0x7F, 0x14, 0xCA, 0x01, 0xD0, 0xC1,
  37119. 0xC1, 0xE9, 0x88, 0x10, 0xFE, 0x0B, 0x36, 0xE5,
  37120. 0xB4, 0x27, 0x15, 0x7B, 0x94, 0x18, 0x44, 0x9C,
  37121. 0xED, 0xD6, 0x41, 0xA4, 0x29, 0x3C, 0x85, 0xC3,
  37122. 0x27, 0x00, 0x10, 0x2A, 0xCE, 0xC2, 0x2E, 0xBA,
  37123. 0xD9, 0x8E, 0xD1, 0x60, 0xA5, 0xF0, 0x27, 0xBD,
  37124. 0x4C, 0xDA, 0x57, 0xF1, 0xF3, 0x72, 0x0A, 0x12,
  37125. 0xC1, 0x34, 0x65, 0x4D, 0xD5, 0xE7, 0x3F, 0x82,
  37126. 0x96, 0x76, 0x49, 0x53, 0x90, 0xD0, 0xE7, 0x92,
  37127. 0x9D, 0x60, 0x34, 0xE9, 0xC5, 0x5F, 0x7D, 0x55,
  37128. 0xBA, 0x65, 0x8B, 0xC5, 0x87, 0x98, 0x8E, 0x8A,
  37129. 0xF9, 0x49, 0x60, 0xF6, 0xCF, 0xB8, 0xD5, 0xAF,
  37130. 0x7A, 0x00, 0x21, 0x53, 0x5A, 0x6E, 0x25, 0xE4,
  37131. 0x37, 0xD4, 0x9A, 0x78, 0x06, 0x98, 0xBE, 0x22,
  37132. 0xAC, 0x99, 0x53, 0x94, 0x9F, 0x57, 0x1B, 0x85,
  37133. 0xA6, 0x85, 0x72, 0x5F, 0x82, 0x07, 0xA2, 0xB0,
  37134. 0xAE, 0x84, 0x9B, 0x60, 0x1A, 0xB9, 0x1B, 0x15,
  37135. 0x9B, 0x3D, 0xF4, 0xA1, 0x54, 0xC2, 0x04, 0x1E,
  37136. 0x77, 0x60, 0x70, 0xAF, 0xC4, 0x29, 0x69, 0x32,
  37137. 0x23, 0x80, 0x91, 0x7C, 0x97, 0x51, 0x07, 0x99,
  37138. 0xF3, 0x14, 0x91, 0x31, 0x47, 0x7E, 0x16, 0x66,
  37139. 0x3D, 0x31, 0x74, 0xC7, 0xC1, 0xCA, 0xEA, 0x78,
  37140. 0x85, 0x35, 0xC6, 0xC0, 0x05, 0xA6, 0x4F, 0x28,
  37141. 0x68, 0x63, 0x1B, 0x31, 0xB6, 0x6E, 0x20, 0x5F,
  37142. 0xD3, 0x8C, 0x1D, 0x84, 0x54, 0x2D, 0x0F, 0x1B,
  37143. 0x57, 0x8F, 0x58, 0xC9, 0xBF, 0x5A, 0x0F, 0xAE,
  37144. 0xAB, 0x6A, 0xB6, 0x49, 0x48, 0x93, 0x05, 0x31,
  37145. 0x65, 0xEA, 0xFD, 0x46, 0x5F, 0xC6, 0x4A, 0x0C,
  37146. 0x5F, 0x8F, 0x3F, 0x90, 0x03, 0x48, 0x94, 0x15,
  37147. 0x89, 0x9D, 0x59, 0xA5, 0x43, 0xD8, 0x20, 0x8C,
  37148. 0x54, 0xA3, 0x16, 0x65, 0x29, 0xB5, 0x39, 0x22,
  37149. 0x8A, 0x39, 0xE8, 0x7D, 0x53, 0x1F, 0x35, 0x27,
  37150. 0xC2, 0x07, 0xED, 0xCC, 0x1D, 0xB7, 0xFA, 0xDD,
  37151. 0xCF, 0x96, 0x28, 0x39, 0x18, 0x79, 0xB3, 0x35,
  37152. 0xC7, 0x07, 0x83, 0x9A, 0x0D, 0xB0, 0x51, 0xA8,
  37153. 0x86, 0x26, 0xED, 0x79, 0xD4, 0x51, 0x14, 0x08,
  37154. 0x00, 0xE0, 0x3B, 0x59, 0xB9, 0x56, 0xF8, 0x21,
  37155. 0x0E, 0x55, 0x60, 0x67, 0x40, 0x7D, 0x13, 0xDC,
  37156. 0x90, 0xFA, 0x9E, 0x8B, 0x87, 0x2B, 0xFB, 0x8F
  37157. };
  37158. #endif
  37159. #ifndef WOLFSSL_NO_ML_KEM
  37160. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_sk[] = {
  37161. 0x43, 0x3a, 0x70, 0xee, 0x69, 0x50, 0xf9, 0x88,
  37162. 0x2a, 0xcd, 0xd5, 0xa4, 0x78, 0x20, 0xa6, 0xa8,
  37163. 0x16, 0x37, 0x08, 0xf0, 0x4d, 0x45, 0x7c, 0x77,
  37164. 0x99, 0x79, 0xb8, 0x3f, 0xe1, 0x17, 0x22, 0x47,
  37165. 0x01, 0x49, 0x08, 0x30, 0x38, 0x66, 0x37, 0xda,
  37166. 0x33, 0x2e, 0x74, 0xb1, 0xae, 0xda, 0x0b, 0x2f,
  37167. 0x81, 0xca, 0x4f, 0x9b, 0xb2, 0xc2, 0xb0, 0x2b,
  37168. 0x0c, 0xfd, 0x68, 0x0c, 0x11, 0x48, 0x2f, 0x33,
  37169. 0x5a, 0xcf, 0x7b, 0x91, 0x39, 0xb5, 0xb8, 0x8a,
  37170. 0x34, 0xe3, 0x54, 0x2c, 0x68, 0x61, 0x37, 0x75,
  37171. 0x45, 0x98, 0x33, 0x43, 0xcd, 0x82, 0x94, 0x14,
  37172. 0xe4, 0x78, 0x64, 0x21, 0x2e, 0x78, 0xf8, 0x55,
  37173. 0xf5, 0x23, 0x90, 0x37, 0x9a, 0xcc, 0x3a, 0x62,
  37174. 0x95, 0x31, 0x31, 0xb6, 0x3e, 0xe8, 0x32, 0xad,
  37175. 0xb3, 0xbf, 0x4b, 0xf5, 0x8e, 0x24, 0x73, 0x49,
  37176. 0xb5, 0xe0, 0x97, 0xe5, 0x5a, 0xbe, 0x49, 0x7b,
  37177. 0x15, 0x98, 0x23, 0x73, 0xae, 0x73, 0x2e, 0x04,
  37178. 0x39, 0xac, 0x67, 0xd0, 0x5c, 0x7f, 0x03, 0x7c,
  37179. 0x8a, 0x73, 0x9b, 0x18, 0x14, 0x0e, 0x14, 0x4c,
  37180. 0x85, 0x1d, 0xc9, 0x61, 0x1f, 0x4b, 0xcf, 0x04,
  37181. 0xf3, 0xa2, 0x09, 0x3c, 0x19, 0x7b, 0xd6, 0x3b,
  37182. 0xb5, 0xe6, 0x19, 0x01, 0x00, 0x54, 0x5f, 0xf8,
  37183. 0x1d, 0xb7, 0xfc, 0xcd, 0xdd, 0x9a, 0x32, 0x4b,
  37184. 0x0b, 0xac, 0x3c, 0x2c, 0x23, 0x82, 0x28, 0x40,
  37185. 0x58, 0xf0, 0x8b, 0x96, 0x19, 0x52, 0xc0, 0x94,
  37186. 0x01, 0x9c, 0x10, 0xbe, 0x37, 0xa5, 0x3d, 0x5a,
  37187. 0xc7, 0x94, 0xc0, 0x10, 0xa9, 0xd0, 0x82, 0x1f,
  37188. 0x15, 0x02, 0x7a, 0x1c, 0x41, 0x9c, 0x3c, 0x71,
  37189. 0xc9, 0xa1, 0xd2, 0x8a, 0xed, 0x02, 0x59, 0x7a,
  37190. 0xb7, 0x9b, 0x87, 0x53, 0x94, 0x62, 0x6b, 0xa3,
  37191. 0x9a, 0xdc, 0x09, 0x0c, 0x3a, 0x90, 0xcf, 0x75,
  37192. 0x87, 0x1a, 0x65, 0x27, 0x5e, 0xb1, 0xc5, 0xb0,
  37193. 0x33, 0x72, 0xe1, 0x3a, 0x1a, 0x23, 0xd0, 0xcf,
  37194. 0x93, 0x74, 0x11, 0x1f, 0x80, 0xcc, 0x83, 0xa9,
  37195. 0x05, 0x62, 0x2b, 0x83, 0xfc, 0x51, 0x39, 0x71,
  37196. 0xec, 0x84, 0x19, 0xf0, 0x88, 0x0c, 0x30, 0x67,
  37197. 0x63, 0x36, 0x71, 0xb0, 0x9b, 0x54, 0x56, 0xab,
  37198. 0x60, 0x57, 0x93, 0x6d, 0x19, 0xa4, 0xa2, 0xa2,
  37199. 0x67, 0x91, 0x1b, 0x00, 0x0a, 0x13, 0x95, 0x6f,
  37200. 0xbd, 0x49, 0x38, 0x21, 0xda, 0x07, 0x2c, 0x04,
  37201. 0x64, 0x2b, 0x0c, 0x20, 0xda, 0x6c, 0xc0, 0xd9,
  37202. 0xd8, 0x64, 0xa3, 0x93, 0x65, 0xdf, 0xd6, 0x4f,
  37203. 0x10, 0x18, 0x78, 0x25, 0xfa, 0x33, 0x25, 0x07,
  37204. 0x49, 0xcb, 0xc0, 0xc9, 0x05, 0xd7, 0xb1, 0xff,
  37205. 0x3c, 0xae, 0x24, 0x12, 0xbf, 0x86, 0xb8, 0x1a,
  37206. 0x81, 0x7b, 0x86, 0xba, 0xa3, 0x0e, 0xdf, 0x78,
  37207. 0x62, 0xe5, 0xf6, 0xba, 0xc9, 0x87, 0x26, 0xe5,
  37208. 0x6b, 0x3c, 0xec, 0x60, 0x66, 0x4c, 0xaa, 0x2a,
  37209. 0x7d, 0xf6, 0x70, 0xc5, 0xe2, 0x07, 0xdf, 0xac,
  37210. 0x03, 0x82, 0x4c, 0x89, 0x89, 0x7c, 0xb4, 0x90,
  37211. 0xea, 0xa7, 0x65, 0x21, 0x22, 0x2c, 0x86, 0x20,
  37212. 0x51, 0x69, 0xc9, 0x1c, 0x32, 0x9c, 0x4a, 0x18,
  37213. 0x4d, 0x78, 0x72, 0x1a, 0xf8, 0x36, 0xad, 0x4d,
  37214. 0xb0, 0xca, 0x78, 0x46, 0x4d, 0x41, 0x71, 0x47,
  37215. 0x30, 0x12, 0xb7, 0xd1, 0x83, 0xba, 0xfa, 0x62,
  37216. 0x75, 0x85, 0xc6, 0x4b, 0xe3, 0x80, 0x9d, 0x7e,
  37217. 0x60, 0x04, 0xcb, 0xdc, 0x79, 0xa5, 0x46, 0x0f,
  37218. 0x0a, 0xd6, 0x77, 0xcb, 0x71, 0x65, 0x12, 0x40,
  37219. 0x7d, 0x3a, 0x61, 0x9a, 0xd0, 0x95, 0x43, 0xb7,
  37220. 0x39, 0x54, 0x74, 0x72, 0xa7, 0x06, 0xb3, 0x17,
  37221. 0xa5, 0x09, 0xbe, 0x5d, 0x86, 0x1f, 0xd6, 0x6c,
  37222. 0x7d, 0x0e, 0xd9, 0x4c, 0xd5, 0x00, 0x47, 0x95,
  37223. 0xc1, 0x81, 0x59, 0xe3, 0xa3, 0x3d, 0x79, 0x87,
  37224. 0x11, 0x52, 0x5f, 0x16, 0x35, 0xa6, 0x84, 0x28,
  37225. 0x17, 0x29, 0x23, 0x24, 0x96, 0x35, 0xaa, 0xd0,
  37226. 0x32, 0xb9, 0xe5, 0x66, 0x64, 0xbd, 0xd4, 0x8e,
  37227. 0xd2, 0x4a, 0xc7, 0x5c, 0x64, 0x68, 0xd1, 0x90,
  37228. 0x3e, 0x47, 0x10, 0x86, 0xc5, 0xf1, 0x56, 0x7e,
  37229. 0x83, 0x1a, 0x05, 0x08, 0xc5, 0x39, 0x63, 0x25,
  37230. 0x91, 0xab, 0x57, 0x7d, 0x32, 0x4a, 0x82, 0x42,
  37231. 0x97, 0x25, 0x80, 0x99, 0x50, 0x76, 0x1d, 0x84,
  37232. 0x34, 0x28, 0x8c, 0x14, 0x03, 0x4f, 0x1c, 0x06,
  37233. 0xc1, 0xd0, 0xaa, 0xe0, 0x9a, 0x71, 0xc7, 0x40,
  37234. 0xa5, 0x57, 0x01, 0xc2, 0x8f, 0xf8, 0x44, 0x99,
  37235. 0xf2, 0xbb, 0x18, 0xb6, 0x62, 0x8c, 0xaa, 0xa3,
  37236. 0xfe, 0x75, 0xac, 0x4d, 0xe0, 0x4c, 0x6f, 0x91,
  37237. 0x39, 0x00, 0xd8, 0x6c, 0x88, 0x12, 0x62, 0x52,
  37238. 0xa1, 0x7c, 0x4d, 0x30, 0x39, 0x91, 0xdb, 0x02,
  37239. 0x87, 0x12, 0x08, 0x81, 0xbb, 0x88, 0x47, 0x8a,
  37240. 0xaa, 0x9a, 0xf9, 0xbc, 0x53, 0xd3, 0x72, 0x98,
  37241. 0x43, 0x85, 0x8f, 0xdb, 0x46, 0x48, 0x05, 0x9c,
  37242. 0xac, 0x82, 0xc1, 0xa1, 0x08, 0x78, 0xba, 0x39,
  37243. 0x82, 0x3b, 0x04, 0x1b, 0xd0, 0xe2, 0x58, 0x48,
  37244. 0x7b, 0x56, 0xcc, 0x8a, 0x32, 0x20, 0xc1, 0xa5,
  37245. 0x8b, 0xf6, 0x6a, 0x17, 0x2b, 0x5b, 0x9a, 0x0c,
  37246. 0x63, 0x2d, 0x67, 0x4e, 0xae, 0x88, 0x5a, 0x01,
  37247. 0x5c, 0x4e, 0x37, 0xba, 0x07, 0x36, 0x80, 0xbe,
  37248. 0xde, 0x75, 0x34, 0xf3, 0xe3, 0x4b, 0x60, 0x50,
  37249. 0xc8, 0x6b, 0x21, 0xc3, 0xc0, 0x90, 0x94, 0x1f,
  37250. 0x23, 0xb7, 0xf6, 0x73, 0x1e, 0x2b, 0xda, 0x0e,
  37251. 0x6e, 0xa4, 0x64, 0x67, 0x71, 0xce, 0xc5, 0x72,
  37252. 0xb9, 0x8c, 0xa0, 0xa1, 0x58, 0x91, 0x9a, 0xdb,
  37253. 0xeb, 0x84, 0xce, 0x58, 0x5f, 0xf9, 0xf2, 0x5e,
  37254. 0xbd, 0xda, 0x6c, 0xb6, 0xf0, 0x7a, 0x8f, 0x81,
  37255. 0x12, 0x32, 0x60, 0x7e, 0x72, 0x17, 0xbb, 0x03,
  37256. 0x9b, 0xab, 0xd0, 0xd9, 0x19, 0x34, 0xa8, 0x59,
  37257. 0x40, 0x59, 0xc9, 0x68, 0x77, 0x23, 0xc0, 0x43,
  37258. 0x81, 0xbf, 0xd6, 0x27, 0xa1, 0x05, 0x17, 0xf5,
  37259. 0xf4, 0xbf, 0xc7, 0x77, 0x77, 0xaa, 0x26, 0x71,
  37260. 0xae, 0x12, 0x4f, 0x2b, 0x7a, 0x5f, 0x4d, 0x56,
  37261. 0x14, 0x02, 0x91, 0x97, 0xe6, 0x58, 0x6f, 0xa8,
  37262. 0xc1, 0x7e, 0x0a, 0xd9, 0x07, 0x81, 0xbc, 0x7b,
  37263. 0xb1, 0x9a, 0x77, 0x2d, 0x5a, 0x4e, 0xfe, 0x32,
  37264. 0xca, 0xc8, 0x9b, 0x76, 0xc4, 0x2a, 0x5e, 0xde,
  37265. 0x9b, 0xcc, 0x20, 0xc1, 0x89, 0x8c, 0x08, 0xa5,
  37266. 0xb0, 0xc0, 0x7e, 0x47, 0x8b, 0x1b, 0xbc, 0x22,
  37267. 0x6e, 0xfa, 0xd1, 0x5f, 0x2a, 0xc7, 0x37, 0x51,
  37268. 0x4b, 0x8c, 0x61, 0x49, 0x81, 0x07, 0x79, 0x22,
  37269. 0x24, 0x16, 0x53, 0x7e, 0xd0, 0x0d, 0xae, 0xab,
  37270. 0x17, 0x7e, 0x90, 0x3e, 0xad, 0x6b, 0x4a, 0xc4,
  37271. 0x23, 0x70, 0xaf, 0x1b, 0x1f, 0x50, 0xeb, 0xaf,
  37272. 0xaa, 0x1c, 0x6e, 0x64, 0x7b, 0xba, 0xcc, 0xe7,
  37273. 0x2c, 0x7d, 0x0b, 0x88, 0xae, 0xb0, 0xb0, 0x6f,
  37274. 0xc1, 0xa4, 0x54, 0x57, 0xa9, 0xc1, 0x87, 0x57,
  37275. 0x9b, 0xf1, 0x84, 0x57, 0x9c, 0xc3, 0x51, 0xc4,
  37276. 0x3d, 0xff, 0x94, 0x26, 0x05, 0xaa, 0x56, 0x04,
  37277. 0xfc, 0x85, 0xfc, 0x55, 0x83, 0xf6, 0xf1, 0x49,
  37278. 0x6f, 0xe6, 0x1d, 0x70, 0xd6, 0xcd, 0xe2, 0x32,
  37279. 0x7f, 0xee, 0x71, 0x3d, 0x86, 0xf2, 0x9b, 0x3a,
  37280. 0xfc, 0xbb, 0x54, 0xe9, 0xa9, 0x2a, 0x33, 0xa6,
  37281. 0xc1, 0xea, 0x6f, 0xfa, 0x30, 0x95, 0x66, 0xb0,
  37282. 0x68, 0x62, 0x33, 0xc0, 0xf3, 0xb1, 0xc3, 0x14,
  37283. 0x48, 0x90, 0xe4, 0xf0, 0x82, 0x9a, 0x60, 0x99,
  37284. 0xc5, 0x74, 0x9c, 0xde, 0xc8, 0x43, 0x28, 0xec,
  37285. 0x2c, 0xb6, 0x4a, 0x73, 0x85, 0xa7, 0x61, 0xd6,
  37286. 0x4b, 0x3a, 0x23, 0xc4, 0x89, 0x34, 0x33, 0x43,
  37287. 0xb9, 0x77, 0x23, 0xae, 0x78, 0xc7, 0xd8, 0x05,
  37288. 0x45, 0x8e, 0x16, 0x20, 0xf0, 0x29, 0x28, 0x97,
  37289. 0x69, 0x17, 0x04, 0xcb, 0x76, 0xe3, 0xb0, 0xb2,
  37290. 0x81, 0xa8, 0x3c, 0xf6, 0x44, 0x90, 0x49, 0x8c,
  37291. 0xbc, 0xaf, 0x04, 0x80, 0x24, 0x16, 0xb3, 0x3c,
  37292. 0x56, 0x51, 0x71, 0xd7, 0x72, 0xd3, 0xb9, 0x35,
  37293. 0x40, 0x37, 0x58, 0x76, 0x29, 0xae, 0x14, 0xa5,
  37294. 0xc5, 0x03, 0x1a, 0xc3, 0x66, 0x71, 0xa0, 0xd0,
  37295. 0xc9, 0x1c, 0xc0, 0xb4, 0xcd, 0x69, 0xd8, 0x40,
  37296. 0x2e, 0x33, 0xb9, 0xbc, 0xc2, 0xbb, 0xaf, 0x6b,
  37297. 0x97, 0x1e, 0x30, 0x3f, 0xa1, 0x37, 0xbe, 0x23,
  37298. 0x25, 0x98, 0xa4, 0x99, 0x9b, 0xc0, 0x12, 0x57,
  37299. 0x4c, 0x81, 0x65, 0x1b, 0x38, 0xb3, 0x83, 0x96,
  37300. 0xc1, 0xc3, 0x65, 0x30, 0x3a, 0xd2, 0x5d, 0x49,
  37301. 0xfc, 0x6b, 0x68, 0x99, 0x51, 0xa1, 0xcc, 0x4c,
  37302. 0x60, 0x07, 0x61, 0x30, 0x65, 0x49, 0x5f, 0x97,
  37303. 0x91, 0x0f, 0x97, 0x35, 0xd4, 0xea, 0x4e, 0x44,
  37304. 0x2a, 0xcb, 0x2f, 0xab, 0xae, 0xcf, 0xe1, 0xad,
  37305. 0xef, 0x06, 0x67, 0xba, 0x42, 0x2c, 0x95, 0x4a,
  37306. 0x05, 0xd1, 0xb6, 0x16, 0x7a, 0x26, 0x3e, 0x12,
  37307. 0x75, 0xc6, 0xad, 0xa8, 0x38, 0x59, 0x65, 0x30,
  37308. 0x4b, 0x30, 0x32, 0x40, 0x40, 0x54, 0x2c, 0xf5,
  37309. 0xa4, 0x51, 0xbc, 0xaf, 0xc7, 0x47, 0x88, 0xbe,
  37310. 0x3b, 0x9b, 0x9f, 0xcc, 0x45, 0xd4, 0x79, 0x0e,
  37311. 0x2d, 0x73, 0x35, 0xc6, 0x0a, 0x14, 0xf0, 0xa4,
  37312. 0x9d, 0x13, 0x05, 0x3f, 0x26, 0x26, 0xa6, 0x27,
  37313. 0xca, 0x19, 0x55, 0x3c, 0xb3, 0x36, 0xa2, 0xcb,
  37314. 0x4a, 0x45, 0x5d, 0x8e, 0xf3, 0x98, 0x94, 0x91,
  37315. 0x47, 0x2b, 0xa0, 0x05, 0x1e, 0xf7, 0x41, 0x6e,
  37316. 0x0b, 0xbf, 0x1a, 0x61, 0x08, 0xfa, 0x07, 0xc1,
  37317. 0x61, 0x54, 0x8e, 0x7c, 0x62, 0x33, 0x1a, 0xe5,
  37318. 0xa2, 0xb4, 0xe4, 0xa1, 0x08, 0xa5, 0x10, 0x93,
  37319. 0xd3, 0x15, 0x08, 0x21, 0xa2, 0xfb, 0x54, 0x71,
  37320. 0x70, 0xa1, 0xb7, 0x3c, 0x43, 0xc5, 0x50, 0xc6,
  37321. 0x55, 0x7a, 0x40, 0x48, 0xa5, 0x8a, 0x2c, 0xd7,
  37322. 0x7a, 0x24, 0x42, 0x34, 0xb2, 0x23, 0x51, 0x75,
  37323. 0xa0, 0x89, 0x7d, 0x50, 0x61, 0xb4, 0x61, 0x34,
  37324. 0x82, 0xdc, 0x13, 0x64, 0x14, 0x04, 0x8c, 0x11,
  37325. 0xdb, 0x37, 0xea, 0xe0, 0xa5, 0xdf, 0x87, 0xc1,
  37326. 0x93, 0x14, 0xb0, 0xe8, 0x23, 0x97, 0xa0, 0xd3,
  37327. 0x38, 0xdc, 0x21, 0x53, 0x8a, 0xf3, 0x61, 0x49,
  37328. 0xd9, 0x3f, 0x8b, 0x1a, 0x11, 0xc5, 0x3b, 0xb5,
  37329. 0xde, 0xf8, 0xb7, 0xa2, 0xcc, 0xa3, 0x36, 0x2b,
  37330. 0x7f, 0xe3, 0xa1, 0x40, 0x8a, 0x25, 0x47, 0xe2,
  37331. 0x09, 0x05, 0x8c, 0x67, 0x3a, 0x75, 0x66, 0xc2,
  37332. 0x61, 0x23, 0xa6, 0xd8, 0xb6, 0x92, 0xa5, 0xf3,
  37333. 0x3e, 0xbd, 0xcb, 0x26, 0x24, 0xb7, 0x9d, 0x87,
  37334. 0x7b, 0xce, 0x5f, 0xa1, 0x4e, 0x42, 0xe8, 0x3f,
  37335. 0xaa, 0xd8, 0x2e, 0x99, 0x00, 0x55, 0x3a, 0x3c,
  37336. 0x60, 0x45, 0xca, 0x32, 0x9f, 0xea, 0x4a, 0x50,
  37337. 0x65, 0x58, 0xc4, 0x91, 0xb6, 0xa6, 0x16, 0xc6,
  37338. 0xfd, 0x40, 0x0b, 0x42, 0x13, 0x6f, 0x44, 0xcb,
  37339. 0x0d, 0x02, 0x57, 0x65, 0x08, 0x19, 0x01, 0x8d,
  37340. 0x3c, 0x56, 0x8e, 0xf6, 0xc6, 0x0c, 0x6c, 0x40,
  37341. 0x9e, 0x70, 0xa8, 0x29, 0x28, 0x71, 0x08, 0xc1,
  37342. 0xb6, 0xa4, 0xd3, 0x2f, 0x76, 0xe5, 0xcc, 0x4d,
  37343. 0x10, 0x4b, 0x02, 0x43, 0x8e, 0xf7, 0xa4, 0x67,
  37344. 0x91, 0x23, 0x98, 0xea, 0x9c, 0x7c, 0xbd, 0x99,
  37345. 0x81, 0x58, 0x9a, 0x34, 0x18, 0x97, 0x68, 0x7b,
  37346. 0x51, 0x6a, 0x13, 0x30, 0x7d, 0x66, 0xc0, 0x68,
  37347. 0xc4, 0x44, 0xb4, 0xb9, 0x49, 0xa1, 0x74, 0x12,
  37348. 0x41, 0x33, 0x15, 0xcc, 0xf4, 0x9b, 0x99, 0x98,
  37349. 0x00, 0x34, 0xb5, 0xb8, 0xcf, 0xde, 0xc4, 0xa6,
  37350. 0x0b, 0x9c, 0x1e, 0x74, 0x55, 0xaa, 0xfb, 0xf3,
  37351. 0xa7, 0x57, 0x34, 0x69, 0x90, 0xcc, 0x32, 0xb0,
  37352. 0x59, 0x9b, 0xa2, 0x17, 0xa6, 0xc5, 0xfc, 0x39,
  37353. 0x53, 0x79, 0x11, 0x95, 0x7c, 0x12, 0x51, 0x48,
  37354. 0xa8, 0x7f, 0x41, 0x58, 0x9c, 0xb2, 0x22, 0xd0,
  37355. 0xd1, 0x92, 0x29, 0xe2, 0xcb, 0x55, 0xe1, 0xa0,
  37356. 0x44, 0x79, 0x1e, 0x7c, 0xa6, 0x11, 0x92, 0xa4,
  37357. 0x64, 0x60, 0xc3, 0x18, 0x3d, 0x2b, 0xcd, 0x6d,
  37358. 0xe0, 0x8a, 0x5e, 0x76, 0x51, 0x60, 0x3a, 0xcc,
  37359. 0x34, 0x9c, 0xa1, 0x6c, 0xba, 0x18, 0xab, 0xb2,
  37360. 0x3a, 0x3e, 0x8c, 0x33, 0x0d, 0x74, 0x21, 0x59,
  37361. 0x8a, 0x62, 0x78, 0xec, 0x7e, 0xbf, 0xab, 0xca,
  37362. 0x0e, 0xf4, 0x88, 0xb2, 0x29, 0x05, 0x54, 0x75,
  37363. 0x34, 0x99, 0xc0, 0x45, 0x2e, 0x45, 0x38, 0x15,
  37364. 0x30, 0x99, 0x55, 0xb8, 0x15, 0x0f, 0xa1, 0xa1,
  37365. 0xe3, 0x93, 0x38, 0x6d, 0xc1, 0x2f, 0xdb, 0x27,
  37366. 0xb3, 0x8c, 0x67, 0x45, 0xf2, 0x94, 0x40, 0x16,
  37367. 0xec, 0x45, 0x7f, 0x39, 0xb1, 0x8d, 0x60, 0x4a,
  37368. 0x07, 0xa1, 0xab, 0xe0, 0x7b, 0xc8, 0x44, 0x05,
  37369. 0x0f, 0xfa, 0x8a, 0x06, 0xfa, 0x15, 0x4a, 0x49,
  37370. 0xd8, 0x8f, 0xac, 0x77, 0x54, 0x52, 0xd6, 0xa7,
  37371. 0xc0, 0xe5, 0x89, 0xbf, 0xb5, 0xc3, 0x70, 0xc2,
  37372. 0xc4, 0xb6, 0x20, 0x1d, 0xda, 0x80, 0xc9, 0xab,
  37373. 0x20, 0x76, 0xec, 0xc0, 0x8b, 0x44, 0x52, 0x2f,
  37374. 0xda, 0x33, 0x26, 0xf0, 0x33, 0x80, 0x6d, 0xd2,
  37375. 0x69, 0x3f, 0x31, 0x97, 0x39, 0xf4, 0x0c, 0x4f,
  37376. 0x42, 0xb2, 0x4a, 0xca, 0x70, 0x98, 0xfb, 0x8f,
  37377. 0xf5, 0xf9, 0xac, 0x20, 0x29, 0x2d, 0x02, 0xb5,
  37378. 0x6a, 0xc7, 0x46, 0x80, 0x1a, 0xcc, 0xcc, 0x84,
  37379. 0x86, 0x3d, 0xee, 0x32, 0x87, 0x84, 0x97, 0xb6,
  37380. 0x94, 0x38, 0xbf, 0x99, 0x17, 0x76, 0x28, 0x66,
  37381. 0x50, 0x48, 0x2c, 0x8d, 0x9d, 0x95, 0x87, 0xbc,
  37382. 0x6a, 0x55, 0xb8, 0x5c, 0x4d, 0x7f, 0xa7, 0x4d,
  37383. 0x02, 0x65, 0x6b, 0x42, 0x1c, 0x9e, 0x23, 0xe0,
  37384. 0x3a, 0x48, 0xd4, 0xb7, 0x44, 0x25, 0xc2, 0x6e,
  37385. 0x4a, 0x20, 0xdd, 0x95, 0x62, 0xa4, 0xda, 0x07,
  37386. 0x93, 0xf3, 0xa3, 0x52, 0xcc, 0xc0, 0xf1, 0x82,
  37387. 0x17, 0xd8, 0x68, 0xc7, 0xf5, 0x00, 0x2a, 0xbe,
  37388. 0x76, 0x8b, 0x1f, 0xc7, 0x3f, 0x05, 0x74, 0x4e,
  37389. 0x7c, 0xc2, 0x8f, 0x10, 0x34, 0x40, 0x62, 0xc1,
  37390. 0x0e, 0x08, 0xec, 0xcc, 0xed, 0x3c, 0x1f, 0x7d,
  37391. 0x39, 0x2c, 0x01, 0xd9, 0x79, 0xdd, 0x71, 0x8d,
  37392. 0x83, 0x98, 0x37, 0x46, 0x65, 0xa1, 0x6a, 0x98,
  37393. 0x70, 0x58, 0x5c, 0x39, 0xd5, 0x58, 0x9a, 0x50,
  37394. 0xe1, 0x33, 0x38, 0x9c, 0x9b, 0x9a, 0x27, 0x6c,
  37395. 0x02, 0x42, 0x60, 0xd9, 0xfc, 0x77, 0x11, 0xc8,
  37396. 0x1b, 0x63, 0x37, 0xb5, 0x7d, 0xa3, 0xc3, 0x76,
  37397. 0xd0, 0xcd, 0x74, 0xe1, 0x4c, 0x73, 0x72, 0x7b,
  37398. 0x27, 0x66, 0x56, 0xb9, 0xd8, 0xa4, 0xeb, 0x71,
  37399. 0x89, 0x6f, 0xf5, 0x89, 0xd4, 0xb8, 0x93, 0xe7,
  37400. 0x11, 0x0f, 0x3b, 0xb9, 0x48, 0xec, 0xe2, 0x91,
  37401. 0xdd, 0x86, 0xc0, 0xb7, 0x46, 0x8a, 0x67, 0x8c,
  37402. 0x74, 0x69, 0x80, 0xc1, 0x2a, 0xa6, 0xb9, 0x5e,
  37403. 0x2b, 0x0c, 0xbe, 0x43, 0x31, 0xbb, 0x24, 0xa3,
  37404. 0x3a, 0x27, 0x01, 0x53, 0xaa, 0x47, 0x2c, 0x47,
  37405. 0x31, 0x23, 0x82, 0xca, 0x36, 0x5c, 0x5f, 0x35,
  37406. 0x25, 0x9d, 0x02, 0x57, 0x46, 0xfc, 0x65, 0x95,
  37407. 0xfe, 0x63, 0x6c, 0x76, 0x75, 0x10, 0xa6, 0x9c,
  37408. 0x1e, 0x8a, 0x17, 0x6b, 0x79, 0x49, 0x95, 0x8f,
  37409. 0x26, 0x97, 0x39, 0x94, 0x97, 0xa2, 0xfc, 0x73,
  37410. 0x64, 0xa1, 0x2c, 0x81, 0x98, 0x29, 0x52, 0x39,
  37411. 0xc8, 0x26, 0xcb, 0x50, 0x82, 0x08, 0x60, 0x77,
  37412. 0x28, 0x2e, 0xd6, 0x28, 0x65, 0x1f, 0xc0, 0x4c,
  37413. 0x63, 0x9b, 0x43, 0x85, 0x22, 0xa9, 0xde, 0x30,
  37414. 0x9b, 0x14, 0xb0, 0x86, 0xd6, 0xe9, 0x23, 0xc5,
  37415. 0x51, 0x62, 0x3b, 0xd7, 0x2a, 0x73, 0x3c, 0xb0,
  37416. 0xda, 0xbc, 0x54, 0xa9, 0x41, 0x6a, 0x99, 0xe7,
  37417. 0x2c, 0x9f, 0xda, 0x1c, 0xb3, 0xfb, 0x9b, 0xa0,
  37418. 0x6b, 0x8a, 0xdb, 0x24, 0x22, 0xd6, 0x8c, 0xad,
  37419. 0xc5, 0x53, 0xc9, 0x82, 0x02, 0xa1, 0x76, 0x56,
  37420. 0x47, 0x8a, 0xc0, 0x44, 0xef, 0x34, 0x56, 0x37,
  37421. 0x8a, 0xbc, 0xe9, 0x99, 0x1e, 0x01, 0x41, 0xba,
  37422. 0x79, 0x09, 0x4f, 0xa8, 0xf7, 0x7a, 0x30, 0x08,
  37423. 0x05, 0xd2, 0xd3, 0x2f, 0xfc, 0x62, 0xbf, 0x0c,
  37424. 0xa4, 0x55, 0x4c, 0x33, 0x0c, 0x2b, 0xb7, 0x04,
  37425. 0x2d, 0xb3, 0x51, 0x02, 0xf6, 0x8b, 0x1a, 0x00,
  37426. 0x62, 0x58, 0x38, 0x65, 0x38, 0x1c, 0x74, 0xdd,
  37427. 0x91, 0x3a, 0xf7, 0x0b, 0x26, 0xcf, 0x09, 0x23,
  37428. 0xd0, 0xc4, 0xcb, 0x97, 0x16, 0x92, 0x22, 0x25,
  37429. 0x52, 0xa8, 0xf4, 0xb7, 0x88, 0xb4, 0xaf, 0xd1,
  37430. 0x34, 0x1a, 0x9d, 0xf4, 0x15, 0xcf, 0x20, 0x39,
  37431. 0x00, 0xf5, 0xcc, 0xf7, 0xf6, 0x59, 0x88, 0x94,
  37432. 0x9a, 0x75, 0x58, 0x0d, 0x04, 0x96, 0x39, 0x85,
  37433. 0x31, 0x00, 0x85, 0x4b, 0x21, 0xf4, 0x01, 0x80,
  37434. 0x03, 0x50, 0x2b, 0xb1, 0xba, 0x95, 0xf5, 0x56,
  37435. 0xa5, 0xd6, 0x7c, 0x7e, 0xb5, 0x24, 0x10, 0xeb,
  37436. 0xa2, 0x88, 0xa6, 0xd0, 0x63, 0x5c, 0xa8, 0xa4,
  37437. 0xf6, 0xd6, 0x96, 0xd0, 0xa0, 0x20, 0xc8, 0x26,
  37438. 0x93, 0x8d, 0x34, 0x94, 0x3c, 0x38, 0x08, 0xc7,
  37439. 0x9c, 0xc0, 0x07, 0x76, 0x85, 0x33, 0x21, 0x6b,
  37440. 0xc1, 0xb2, 0x9d, 0xa6, 0xc8, 0x12, 0xef, 0xf3,
  37441. 0x34, 0x0b, 0xaa, 0x8d, 0x2e, 0x65, 0x34, 0x4f,
  37442. 0x09, 0xbd, 0x47, 0x89, 0x4f, 0x5a, 0x3a, 0x41,
  37443. 0x18, 0x71, 0x5b, 0x3c, 0x50, 0x20, 0x67, 0x93,
  37444. 0x27, 0xf9, 0x18, 0x9f, 0x7e, 0x10, 0x85, 0x6b,
  37445. 0x23, 0x8b, 0xb9, 0xb0, 0xab, 0x4c, 0xa8, 0x5a,
  37446. 0xbf, 0x4b, 0x21, 0xf5, 0xc7, 0x6b, 0xcc, 0xd7,
  37447. 0x18, 0x50, 0xb2, 0x2e, 0x04, 0x59, 0x28, 0x27,
  37448. 0x6a, 0x0f, 0x2e, 0x95, 0x1d, 0xb0, 0x70, 0x7c,
  37449. 0x6a, 0x11, 0x6d, 0xc1, 0x91, 0x13, 0xfa, 0x76,
  37450. 0x2d, 0xc5, 0xf2, 0x0b, 0xd5, 0xd2, 0xab, 0x5b,
  37451. 0xe7, 0x17, 0x44, 0xdc, 0x9c, 0xbd, 0xb5, 0x1e,
  37452. 0xa7, 0x57, 0x96, 0x3a, 0xac, 0x56, 0xa9, 0x0a,
  37453. 0x0d, 0x80, 0x23, 0xbe, 0xd1, 0xf5, 0xca, 0xe8,
  37454. 0xa6, 0x4d, 0xa0, 0x47, 0x27, 0x9b, 0x35, 0x3a,
  37455. 0x09, 0x6a, 0x83, 0x5b, 0x0b, 0x2b, 0x02, 0x3b,
  37456. 0x6a, 0xa0, 0x48, 0x98, 0x92, 0x33, 0x07, 0x9a,
  37457. 0xeb, 0x46, 0x7e, 0x52, 0x2f, 0xa2, 0x7a, 0x58,
  37458. 0x22, 0x92, 0x1e, 0x5c, 0x55, 0x1b, 0x4f, 0x53,
  37459. 0x75, 0x36, 0xe4, 0x6f, 0x3a, 0x6a, 0x97, 0xe7,
  37460. 0x2c, 0x3b, 0x06, 0x31, 0x04, 0xe0, 0x9a, 0x04,
  37461. 0x05, 0x98, 0x94, 0x0d, 0x87, 0x2f, 0x6d, 0x87,
  37462. 0x1f, 0x5e, 0xf9, 0xb4, 0x35, 0x50, 0x73, 0xb5,
  37463. 0x47, 0x69, 0xe4, 0x54, 0x54, 0xe6, 0xa0, 0x81,
  37464. 0x95, 0x99, 0x40, 0x86, 0x21, 0xab, 0x44, 0x13,
  37465. 0xb3, 0x55, 0x07, 0xb0, 0xdf, 0x57, 0x8c, 0xe2,
  37466. 0xd5, 0x11, 0xd5, 0x20, 0x58, 0xd5, 0x74, 0x9d,
  37467. 0xf3, 0x8b, 0x29, 0xd6, 0xcc, 0x58, 0x87, 0x0c,
  37468. 0xaf, 0x92, 0xf6, 0x9a, 0x75, 0x16, 0x14, 0x06,
  37469. 0xe7, 0x1c, 0x5f, 0xf9, 0x24, 0x51, 0xa7, 0x75,
  37470. 0x22, 0xb8, 0xb2, 0x96, 0x7a, 0x2d, 0x58, 0xa4,
  37471. 0x9a, 0x81, 0x66, 0x1a, 0xa6, 0x5a, 0xc0, 0x9b,
  37472. 0x08, 0xc9, 0xfe, 0x45, 0xab, 0xc3, 0x85, 0x1f,
  37473. 0x99, 0xc7, 0x30, 0xc4, 0x50, 0x03, 0xac, 0xa2,
  37474. 0xbf, 0x0f, 0x84, 0x24, 0xa1, 0x9b, 0x74, 0x08,
  37475. 0xa5, 0x37, 0xd5, 0x41, 0xc1, 0x6f, 0x56, 0x82,
  37476. 0xbf, 0xe3, 0xa7, 0xfa, 0xea, 0x56, 0x4f, 0x12,
  37477. 0x98, 0x61, 0x1a, 0x7f, 0x5f, 0x60, 0x92, 0x2b,
  37478. 0xa1, 0x9d, 0xe7, 0x3b, 0x19, 0x17, 0xf1, 0x85,
  37479. 0x32, 0x73, 0x55, 0x51, 0x99, 0xa6, 0x49, 0x31,
  37480. 0x8b, 0x50, 0x77, 0x33, 0x45, 0xc9, 0x97, 0x46,
  37481. 0x08, 0x56, 0x97, 0x2a, 0xcb, 0x43, 0xfc, 0x81,
  37482. 0xab, 0x63, 0x21, 0xb1, 0xc3, 0x3c, 0x2b, 0xb5,
  37483. 0x09, 0x8b, 0xd4, 0x89, 0xd6, 0x96, 0xa0, 0xf7,
  37484. 0x06, 0x79, 0xc1, 0x21, 0x38, 0x73, 0xd0, 0x8b,
  37485. 0xda, 0xd4, 0x28, 0x44, 0x92, 0x72, 0x16, 0x04,
  37486. 0x72, 0x05, 0x63, 0x32, 0x12, 0x31, 0x0e, 0xe9,
  37487. 0xa0, 0x6c, 0xb1, 0x00, 0x16, 0xc8, 0x05, 0x50,
  37488. 0x3c, 0x34, 0x1a, 0x36, 0xd8, 0x7e, 0x56, 0x07,
  37489. 0x2e, 0xab, 0xe2, 0x37, 0x31, 0xe3, 0x4a, 0xf7,
  37490. 0xe2, 0x32, 0x8f, 0x85, 0xcd, 0xb3, 0x70, 0xcc,
  37491. 0xaf, 0x00, 0x51, 0x5b, 0x64, 0xc9, 0xc5, 0x4b,
  37492. 0xc8, 0x37, 0x57, 0x84, 0x47, 0xaa, 0xcf, 0xae,
  37493. 0xd5, 0x96, 0x9a, 0xa3, 0x51, 0xe7, 0xda, 0x4e,
  37494. 0xfa, 0x7b, 0x11, 0x5c, 0x4c, 0x51, 0xf4, 0xa6,
  37495. 0x99, 0x77, 0x98, 0x50, 0x29, 0x5c, 0xa7, 0x2d,
  37496. 0x78, 0x1a, 0xd4, 0x1b, 0xc6, 0x80, 0x53, 0x2b,
  37497. 0x89, 0xe7, 0x10, 0xe2, 0x18, 0x9e, 0xb3, 0xc5,
  37498. 0x08, 0x17, 0xba, 0x25, 0x5c, 0x74, 0x74, 0xc9,
  37499. 0x5c, 0xa9, 0x11, 0x0c, 0xc4, 0x3b, 0x8b, 0xa8,
  37500. 0xe6, 0x82, 0xc7, 0xfb, 0x7b, 0x0f, 0xdc, 0x26,
  37501. 0x5c, 0x04, 0x83, 0xa6, 0x5c, 0xa4, 0x51, 0x4e,
  37502. 0xe4, 0xb8, 0x32, 0xaa, 0xc5, 0x80, 0x0c, 0x3b,
  37503. 0x08, 0xe7, 0x4f, 0x56, 0x39, 0x51, 0xc1, 0xfb,
  37504. 0xb2, 0x10, 0x35, 0x3e, 0xfa, 0x1a, 0xa8, 0x66,
  37505. 0x85, 0x6b, 0xc1, 0xe0, 0x34, 0x73, 0x3b, 0x04,
  37506. 0x85, 0xda, 0xb1, 0xd0, 0x20, 0xc6, 0xbf, 0x76,
  37507. 0x5f, 0xf6, 0x0b, 0x3b, 0x80, 0x19, 0x84, 0xa9,
  37508. 0x0c, 0x2f, 0xe9, 0x70, 0xbf, 0x1d, 0xe9, 0x70,
  37509. 0x04, 0xa6, 0xcf, 0x44, 0xb4, 0x98, 0x4a, 0xb5,
  37510. 0x82, 0x58, 0xb4, 0xaf, 0x71, 0x22, 0x1c, 0xd1,
  37511. 0x75, 0x30, 0xa7, 0x00, 0xc3, 0x29, 0x59, 0xc9,
  37512. 0x43, 0x63, 0x44, 0xb5, 0x31, 0x6f, 0x09, 0xcc,
  37513. 0xca, 0x70, 0x29, 0xa2, 0x30, 0xd6, 0x39, 0xdc,
  37514. 0xb0, 0x22, 0xd8, 0xba, 0x79, 0xba, 0x91, 0xcd,
  37515. 0x6a, 0xb1, 0x2a, 0xe1, 0x57, 0x9c, 0x50, 0xc7,
  37516. 0xbb, 0x10, 0xe3, 0x03, 0x01, 0xa6, 0x5c, 0xae,
  37517. 0x31, 0x01, 0xd4, 0x0c, 0x7b, 0xa9, 0x27, 0xbb,
  37518. 0x55, 0x31, 0x48, 0xd1, 0x64, 0x70, 0x24, 0xd4,
  37519. 0xa0, 0x6c, 0x81, 0x66, 0xd0, 0xb0, 0xb8, 0x12,
  37520. 0x69, 0xb7, 0xd5, 0xf4, 0xb3, 0x4f, 0xb0, 0x22,
  37521. 0xf6, 0x91, 0x52, 0xf5, 0x14, 0x00, 0x4a, 0x7c,
  37522. 0x68, 0x53, 0x68, 0x55, 0x23, 0x43, 0xbb, 0x60,
  37523. 0x36, 0x0f, 0xbb, 0x99, 0x45, 0xed, 0xf4, 0x46,
  37524. 0xd3, 0x45, 0xbd, 0xca, 0xa7, 0x45, 0x5c, 0x74,
  37525. 0xba, 0x0a, 0x55, 0x1e, 0x18, 0x46, 0x20, 0xfe,
  37526. 0xf9, 0x76, 0x88, 0x77, 0x3d, 0x50, 0xb6, 0x43,
  37527. 0x3c, 0xa7, 0xa7, 0xac, 0x5c, 0xb6, 0xb7, 0xf6,
  37528. 0x71, 0xa1, 0x53, 0x76, 0xe5, 0xa6, 0x74, 0x7a,
  37529. 0x62, 0x3f, 0xa7, 0xbc, 0x66, 0x30, 0x37, 0x3f,
  37530. 0x5b, 0x1b, 0x51, 0x26, 0x90, 0xa6, 0x61, 0x37,
  37531. 0x78, 0x70, 0xa6, 0x0a, 0x7a, 0x18, 0x96, 0x83,
  37532. 0xf9, 0xb0, 0xcf, 0x04, 0x66, 0xe1, 0xf7, 0x50,
  37533. 0x76, 0x26, 0x31, 0xc4, 0xab, 0x09, 0xf5, 0x05,
  37534. 0xc4, 0x2d, 0xd2, 0x86, 0x33, 0x56, 0x94, 0x72,
  37535. 0x73, 0x54, 0x42, 0x85, 0x1e, 0x32, 0x16, 0x16,
  37536. 0xd4, 0x00, 0x98, 0x10, 0x77, 0x7b, 0x6b, 0xd4,
  37537. 0x6f, 0xa7, 0x22, 0x44, 0x61, 0xa5, 0xcc, 0x27,
  37538. 0x40, 0x5d, 0xfb, 0xac, 0x0d, 0x39, 0xb0, 0x02,
  37539. 0xca, 0xb3, 0x34, 0x33, 0xf2, 0xa8, 0x6e, 0xb8,
  37540. 0xce, 0x91, 0xc1, 0x34, 0xa6, 0x38, 0x6f, 0x86,
  37541. 0x0a, 0x19, 0x94, 0xeb, 0x4b, 0x68, 0x75, 0xa4,
  37542. 0x6d, 0x19, 0x55, 0x81, 0xd1, 0x73, 0x85, 0x4b,
  37543. 0x53, 0xd2, 0x29, 0x3d, 0xf3, 0xe9, 0xa8, 0x22,
  37544. 0x75, 0x6c, 0xd8, 0xf2, 0x12, 0xb3, 0x25, 0xca,
  37545. 0x29, 0xb4, 0xf9, 0xf8, 0xcf, 0xba, 0xdf, 0x2e,
  37546. 0x41, 0x86, 0x9a, 0xbf, 0xba, 0xd1, 0x07, 0x38,
  37547. 0xad, 0x04, 0xcc, 0x75, 0x2b, 0xc2, 0x0c, 0x39,
  37548. 0x47, 0x46, 0x85, 0x0e, 0x0c, 0x48, 0x47, 0xdb,
  37549. 0xeb, 0xbe, 0x41, 0xcd, 0x4d, 0xea, 0x48, 0x9d,
  37550. 0xed, 0xd0, 0x0e, 0x76, 0xae, 0x0b, 0xcf, 0x54,
  37551. 0xaa, 0x85, 0x50, 0x20, 0x29, 0x20, 0xeb, 0x64,
  37552. 0xd5, 0x89, 0x2a, 0xd0, 0x2b, 0x13, 0xf2, 0xe5,
  37553. 0x86, 0x26, 0xed, 0x79, 0xd4, 0x51, 0x14, 0x08,
  37554. 0x00, 0xe0, 0x3b, 0x59, 0xb9, 0x56, 0xf8, 0x21,
  37555. 0x0e, 0x55, 0x60, 0x67, 0x40, 0x7d, 0x13, 0xdc,
  37556. 0x90, 0xfa, 0x9e, 0x8b, 0x87, 0x2b, 0xfb, 0x8f
  37557. };
  37558. #endif
  37559. #ifdef WOLFSSL_KYBER_ORIGINAL
  37560. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ct[] = {
  37561. 0xA6, 0xAF, 0x29, 0xD5, 0xF5, 0xB8, 0x0B, 0xD1,
  37562. 0x30, 0xF5, 0x18, 0xBA, 0xDD, 0xD6, 0xC8, 0xF1,
  37563. 0x75, 0x45, 0x41, 0x3D, 0x86, 0x0F, 0xB3, 0xDE,
  37564. 0x45, 0x19, 0x79, 0xEB, 0xFA, 0x5E, 0x4E, 0x31,
  37565. 0x12, 0xC7, 0xC0, 0xAD, 0xF9, 0x98, 0x24, 0xBB,
  37566. 0x52, 0x6F, 0x2C, 0x35, 0x50, 0x74, 0x8E, 0xD0,
  37567. 0xE1, 0x34, 0xF0, 0x45, 0x7A, 0x7C, 0x61, 0xF9,
  37568. 0xF5, 0x26, 0xF0, 0x02, 0xBA, 0xAD, 0xC0, 0x3F,
  37569. 0xC1, 0x3E, 0x38, 0x13, 0x12, 0x19, 0x51, 0x3C,
  37570. 0x3E, 0xDE, 0x06, 0x16, 0x61, 0xE7, 0x4F, 0x60,
  37571. 0x3C, 0x4F, 0xCF, 0x79, 0x51, 0xC8, 0xE5, 0x2C,
  37572. 0x9C, 0x21, 0x3B, 0x0D, 0x22, 0xD9, 0x29, 0x36,
  37573. 0x63, 0xD6, 0x69, 0xA6, 0xB5, 0x8E, 0xD8, 0xFC,
  37574. 0xEF, 0xCF, 0x82, 0x49, 0xD7, 0xBB, 0x52, 0x98,
  37575. 0xF5, 0x57, 0x61, 0x44, 0x5B, 0x2B, 0x83, 0xCE,
  37576. 0x7F, 0x00, 0x5C, 0xB0, 0x42, 0x48, 0xAE, 0xC8,
  37577. 0xBD, 0xA2, 0x2F, 0xD2, 0xD4, 0x2A, 0xA7, 0x66,
  37578. 0x32, 0x20, 0x14, 0xEA, 0x03, 0x8C, 0xC3, 0x2C,
  37579. 0x55, 0xC8, 0xE4, 0xB9, 0xE2, 0x8E, 0xC9, 0x11,
  37580. 0x9F, 0x52, 0x73, 0x41, 0xE4, 0xF6, 0x6A, 0x03,
  37581. 0x51, 0x21, 0x07, 0x3B, 0x85, 0xDE, 0x67, 0x06,
  37582. 0xDA, 0x19, 0xE0, 0x83, 0x8A, 0x9F, 0x33, 0xB7,
  37583. 0x19, 0xA6, 0x8F, 0x03, 0x9B, 0x66, 0x4D, 0xC0,
  37584. 0x02, 0x65, 0x9E, 0xAB, 0xFC, 0x39, 0x86, 0x79,
  37585. 0xAA, 0x70, 0x09, 0xCE, 0x0C, 0xD0, 0x1C, 0xDA,
  37586. 0xFB, 0x6C, 0xD2, 0xA2, 0x6F, 0xE4, 0x10, 0x16,
  37587. 0x72, 0xC9, 0x8F, 0xF5, 0x8F, 0x7C, 0x47, 0xD5,
  37588. 0xBD, 0xA2, 0x90, 0x66, 0x53, 0xB3, 0xA6, 0xF9,
  37589. 0x65, 0x1F, 0x7A, 0x12, 0x1E, 0xA7, 0x7E, 0xA7,
  37590. 0x47, 0x23, 0xFA, 0xE5, 0xB8, 0x73, 0xF9, 0xBB,
  37591. 0x7B, 0x66, 0x4F, 0x0C, 0x8A, 0x93, 0x83, 0x1E,
  37592. 0xF9, 0xD5, 0x1C, 0x7C, 0xC1, 0xEF, 0x44, 0xAC,
  37593. 0x0E, 0x55, 0xA5, 0x5C, 0xA7, 0x6D, 0x13, 0x7F,
  37594. 0xE9, 0xB7, 0x5F, 0x40, 0x50, 0x9C, 0xEF, 0x15,
  37595. 0x6E, 0x5A, 0xD1, 0x8F, 0x9F, 0xB9, 0x99, 0x68,
  37596. 0x00, 0x08, 0xE5, 0x47, 0xD5, 0x5E, 0xEC, 0xD5,
  37597. 0xB4, 0xD1, 0xCB, 0x1D, 0x9F, 0x07, 0x6C, 0xEC,
  37598. 0x21, 0x50, 0x1C, 0x74, 0x02, 0x50, 0x9E, 0xCB,
  37599. 0x77, 0xAF, 0xB2, 0xCB, 0x9A, 0x61, 0x34, 0x0A,
  37600. 0x8B, 0xD1, 0x51, 0x4C, 0x6E, 0x71, 0xB4, 0xAA,
  37601. 0x45, 0xE4, 0x7E, 0xC3, 0x75, 0x12, 0x27, 0x1B,
  37602. 0x91, 0x1F, 0x8F, 0xB4, 0x6C, 0x90, 0x82, 0xC9,
  37603. 0xDF, 0x07, 0x20, 0x4A, 0xBB, 0x5A, 0x50, 0xE6,
  37604. 0xE3, 0x64, 0x7A, 0x8A, 0xD4, 0xD8, 0xD5, 0xD7,
  37605. 0xBF, 0xF1, 0x9C, 0x8A, 0x50, 0x93, 0x08, 0xBC,
  37606. 0xFB, 0x89, 0x55, 0x36, 0xD0, 0x45, 0xCA, 0x2B,
  37607. 0x97, 0xCB, 0x16, 0xA2, 0x9B, 0xB7, 0x18, 0x1C,
  37608. 0xAD, 0x05, 0x09, 0xDD, 0xB9, 0x17, 0x35, 0x02,
  37609. 0x8E, 0xBA, 0x8C, 0x31, 0xD7, 0x4B, 0xD2, 0x75,
  37610. 0xEA, 0xA6, 0x5B, 0x53, 0x40, 0xB3, 0xA4, 0x3F,
  37611. 0xBF, 0xE0, 0xB3, 0x06, 0x1D, 0x6B, 0xAE, 0x7E,
  37612. 0x75, 0xB7, 0x09, 0x8C, 0xDA, 0xBE, 0x91, 0xD4,
  37613. 0xB3, 0x1E, 0x36, 0xC9, 0xAA, 0x7A, 0x82, 0x98,
  37614. 0x86, 0x2A, 0xD6, 0x3C, 0x8F, 0xD2, 0x82, 0xE0,
  37615. 0x3B, 0x46, 0x0B, 0x3A, 0xB4, 0x64, 0xCE, 0x0F,
  37616. 0x27, 0xB1, 0xC3, 0xD1, 0x11, 0x55, 0xAC, 0xAA,
  37617. 0x01, 0x1E, 0xB9, 0xE2, 0xAE, 0x3E, 0x6D, 0xDA,
  37618. 0x07, 0xD6, 0xF4, 0x91, 0x73, 0x7C, 0xBC, 0xE9,
  37619. 0xB0, 0x5F, 0x9B, 0xC5, 0x6B, 0xE2, 0x0E, 0x8D,
  37620. 0x32, 0x6B, 0xA1, 0x32, 0xC5, 0x7F, 0xB2, 0x35,
  37621. 0x16, 0x11, 0x44, 0x51, 0x9C, 0xDF, 0x40, 0x56,
  37622. 0x0F, 0xBE, 0x27, 0x9B, 0xDE, 0x41, 0x1E, 0x11,
  37623. 0x25, 0x31, 0xF8, 0x26, 0xD6, 0xAB, 0x10, 0xD4,
  37624. 0x54, 0x73, 0x50, 0xAD, 0xD2, 0xA9, 0xDE, 0x8D,
  37625. 0x62, 0xC2, 0xAC, 0x82, 0xCA, 0xBE, 0x68, 0x15,
  37626. 0x64, 0x6F, 0x4D, 0xC9, 0x74, 0x2B, 0xB0, 0xC2,
  37627. 0xA3, 0xF7, 0x7E, 0xC7, 0xB4, 0x6C, 0x6B, 0x53,
  37628. 0x76, 0x05, 0xFA, 0x31, 0x79, 0x8C, 0xD8, 0x92,
  37629. 0x81, 0x22, 0x1A, 0x33, 0xDF, 0xB9, 0x79, 0x6E,
  37630. 0x64, 0x43, 0x05, 0x63, 0x03, 0x32, 0xC2, 0xCB,
  37631. 0x93, 0x14, 0x08, 0xAB, 0x48, 0x1A, 0x16, 0xD9,
  37632. 0x53, 0xF6, 0xBE, 0xAE, 0x38, 0x91, 0xD6, 0xD9,
  37633. 0xAC, 0x1F, 0xAB, 0x38, 0x22, 0x2D, 0x92, 0x71,
  37634. 0x87, 0x2D, 0x9D, 0x0C, 0xAD, 0xB9, 0x1A, 0xBE,
  37635. 0x9B, 0x4E, 0x26, 0x5F, 0x75, 0xC6, 0xE5, 0xE8,
  37636. 0x29, 0xE1, 0x46, 0xC3, 0xD8, 0xCE, 0x1E, 0x9D,
  37637. 0x12, 0xE0, 0xD1, 0x29, 0x80, 0x19, 0x57, 0xF4,
  37638. 0x6B, 0x0D, 0x2D, 0xBE, 0x1F, 0x74, 0x9B, 0x1D,
  37639. 0x08, 0xE2, 0x34, 0x5F, 0x62, 0x39, 0xA7, 0x31,
  37640. 0x34, 0x2E, 0xB7, 0x5B, 0x0C, 0xF1, 0xBF, 0x41,
  37641. 0x17, 0x49, 0xBC, 0x2C, 0xAF, 0x28, 0x10, 0xB7,
  37642. 0x88, 0xC6, 0xB7, 0x23, 0x8B, 0x4D, 0x3D, 0xA2,
  37643. 0xD6, 0x31, 0x5C, 0xE9, 0x54, 0x2E, 0x24, 0x40,
  37644. 0x4F, 0x14, 0x57, 0x55, 0xA3, 0x0A, 0xB8, 0x51,
  37645. 0xE4, 0x44, 0x58, 0x41, 0xBD, 0x33, 0xF7, 0x16,
  37646. 0xA5, 0x86, 0x88, 0x48, 0x88, 0xEC, 0xC6, 0xBC,
  37647. 0x64, 0x98, 0xAA, 0x32, 0x91, 0x9A, 0xE8, 0x1D,
  37648. 0x20, 0xC2, 0x69, 0x73, 0xC2, 0xBD, 0x54, 0x58,
  37649. 0x2A, 0x0F, 0x6A, 0xD9, 0x8A, 0xBF, 0xD2, 0x62,
  37650. 0x7E, 0x15, 0x69, 0x0A, 0x72, 0x7E, 0x69, 0xF5,
  37651. 0x81, 0xDD, 0x2A, 0x71, 0x27, 0x98, 0x2A, 0x90,
  37652. 0xE3, 0x3E, 0x2D, 0x4A, 0x03, 0xFE, 0x33, 0x91,
  37653. 0x42, 0xC7, 0xE4, 0x4C, 0x32, 0x6A, 0xC4, 0x6E,
  37654. 0xD3, 0x95, 0xA2, 0x25, 0xD3, 0x03, 0x33, 0x89,
  37655. 0x91, 0x73, 0x28, 0xB4, 0x53, 0x16, 0xB1, 0x58,
  37656. 0x5A, 0x01, 0xB2, 0xC3, 0x04, 0xB2, 0x94, 0x4E,
  37657. 0x90, 0x3A, 0xBB, 0xB3, 0xEC, 0x56, 0x19, 0x44,
  37658. 0x1C, 0xFC, 0x89, 0x65, 0xA4, 0x46, 0xDF, 0x75,
  37659. 0xDE, 0xFA, 0x80, 0xC6, 0xE1, 0x5A, 0xDB, 0xD5,
  37660. 0x06, 0xB7, 0xAB, 0x2D, 0xE1, 0x2D, 0xDA, 0x9B,
  37661. 0xC8, 0x14, 0x41, 0xCF, 0xC8, 0x90, 0x52, 0xE2,
  37662. 0xE5, 0x80, 0x8F, 0x71, 0x26, 0xC6, 0xFD, 0x3A,
  37663. 0xC6, 0xAC, 0x80, 0x81, 0x25, 0x8A, 0x84, 0xA0,
  37664. 0x9A, 0xE5, 0x0F, 0x6C, 0xD7, 0xCC, 0x0F, 0x4A,
  37665. 0xF3, 0x36, 0xFD, 0x1D, 0x64, 0x3E, 0x99, 0x07,
  37666. 0x99, 0x96, 0x26, 0x8C, 0x2D, 0x32, 0xD9, 0x09,
  37667. 0xF2, 0x2E, 0x35, 0x04, 0xF0, 0x7F, 0xBB, 0x56,
  37668. 0x31, 0x96, 0xD4, 0x31, 0x2F, 0xDD, 0xB9, 0x33,
  37669. 0x5D, 0x5C, 0x1D, 0x36, 0xE8, 0xC5, 0xEE, 0xA2,
  37670. 0x27, 0x8D, 0xBA, 0x23, 0xB9, 0x4D, 0x19, 0x3C,
  37671. 0x94, 0x7C, 0xC4, 0x1C, 0xA9, 0x93, 0xDC, 0x7D,
  37672. 0xB1, 0x39, 0x63, 0x40, 0xAD, 0x9C, 0x4F, 0xE6,
  37673. 0x87, 0xDD, 0x7B, 0x8D, 0x0C, 0x7A, 0x51, 0x20,
  37674. 0xAE, 0x02, 0x04, 0xF2, 0xC6, 0x65, 0xBD, 0x5F,
  37675. 0x47, 0x3D, 0x64, 0x4C, 0x7F, 0xF2, 0x6B, 0xFF,
  37676. 0xBA, 0x7A, 0x36, 0x98, 0x08, 0x30, 0x70, 0x21,
  37677. 0x28, 0xA7, 0xE6, 0x61, 0xD6, 0x77, 0xA0, 0x92,
  37678. 0xA3, 0x6E, 0x74, 0x28, 0xA4, 0x13, 0x9F, 0xB2,
  37679. 0x9B, 0x00, 0x95, 0xCC, 0x11, 0x08, 0x6F, 0x44,
  37680. 0x7D, 0x2A, 0x9E, 0xF6, 0xC9, 0xB1, 0x61, 0xF1,
  37681. 0x89, 0xC6, 0x29, 0x9E, 0x08, 0x4C, 0xB7, 0xAA,
  37682. 0x00, 0xFA, 0xF7, 0x87, 0x79, 0x7B, 0xFB, 0x06,
  37683. 0x9F, 0xBC, 0x08, 0x7F, 0xDE, 0x26, 0x25, 0x2A,
  37684. 0x16, 0x64, 0xF1, 0x9C, 0x5A, 0x8A, 0x22, 0xEC,
  37685. 0x5E, 0xE1, 0xAE, 0xB0, 0x76, 0x35, 0x7B, 0x7D,
  37686. 0xC3, 0x7E, 0x6B, 0x0F, 0x15, 0x20, 0xF9, 0x58,
  37687. 0xF7, 0x85, 0x1B, 0xAC, 0xB9, 0x2C, 0x89, 0xFD,
  37688. 0x11, 0x4A, 0x72, 0xFE, 0xAC, 0x54, 0x65, 0x2D,
  37689. 0x45, 0xB0, 0x9E, 0x1A, 0xE7, 0x65, 0x1A, 0xBD,
  37690. 0x16, 0x4B, 0xCD, 0x53, 0x7D, 0x58, 0xFA, 0x39,
  37691. 0xD3, 0xEC, 0x8A, 0xCD, 0xCD, 0xF9, 0x84, 0x25,
  37692. 0x00, 0x58, 0x62, 0xFA, 0x59, 0x69, 0x2D, 0xE1,
  37693. 0x62, 0xB7, 0x7E, 0x62, 0x97, 0xC6, 0x62, 0x33,
  37694. 0x34, 0x84, 0x08, 0xA8, 0xAB, 0x69, 0x5C, 0xE2,
  37695. 0xF2, 0x72, 0x8D, 0xB9, 0xFB, 0xE2, 0x7E, 0x95,
  37696. 0x89, 0x67, 0xEC, 0x59, 0x74, 0x76, 0x7C, 0x5A,
  37697. 0x66, 0x02, 0x30, 0x74, 0xB4, 0xA7, 0x1A, 0xFD,
  37698. 0x26, 0x4A, 0xD2, 0x89, 0x0E, 0x97, 0x0A, 0x1F,
  37699. 0x31, 0xD6, 0xE3, 0x31, 0x1B, 0x73, 0x6F, 0x9F,
  37700. 0x94, 0x88, 0x79, 0x3D, 0xDC, 0x88, 0xF2, 0x34,
  37701. 0x58, 0x06, 0x42, 0x54, 0xC8, 0x2A, 0x1D, 0x9E,
  37702. 0x59, 0xEA, 0xD2, 0xFC, 0xEC, 0x40, 0xB4, 0x30,
  37703. 0x68, 0x7C, 0x4B, 0x7E, 0x28, 0x96, 0x09, 0x26,
  37704. 0xAF, 0xCA, 0xCC, 0x9B, 0xD7, 0x56, 0xA7, 0x10,
  37705. 0x88, 0xC7, 0x84, 0x50, 0xE2, 0x0A, 0x2E, 0x98,
  37706. 0x0A, 0xED, 0xE9, 0xEB, 0xED, 0xFE, 0x7F, 0xAB,
  37707. 0xD6, 0xAB, 0xFE, 0x96, 0xF9, 0x34, 0xC4, 0xB0,
  37708. 0x2C, 0x01, 0xCA, 0x19, 0x4D, 0x01, 0xB7, 0x3C,
  37709. 0x25, 0xD5, 0x99, 0x70, 0x39, 0xD3, 0xFC, 0xD0,
  37710. 0xF0, 0x99, 0x52, 0x1F, 0x70, 0xCA, 0xEE, 0x69,
  37711. 0x11, 0x0A, 0xC1, 0xFC, 0x5A, 0x99, 0x91, 0x7A,
  37712. 0xD7, 0x52, 0xFC, 0x96, 0xAD, 0xFA, 0xD7, 0x18,
  37713. 0x6D, 0x0A, 0x7C, 0x9C, 0xFE, 0x56, 0x01, 0xC0,
  37714. 0x75, 0x14, 0xEA, 0x64, 0x48, 0xD6, 0x61, 0xC5,
  37715. 0x7A, 0xA2, 0x02, 0x42, 0x10, 0x3C, 0x42, 0x76,
  37716. 0xA0, 0x70, 0xA4, 0x89, 0xA4, 0xCB, 0x6B, 0xCA,
  37717. 0x0F, 0x9E, 0xCC, 0x43, 0x79, 0xFB, 0x22, 0x02,
  37718. 0x15, 0xFD, 0x91, 0xF8, 0x10, 0x19, 0xD5, 0xB0,
  37719. 0xAE, 0x61, 0x93, 0x58, 0xB5, 0x24, 0x68, 0xF2,
  37720. 0x72, 0xC1, 0x78, 0xE3, 0xA7, 0x4C, 0xF6, 0x77,
  37721. 0x5A, 0xA9, 0x24, 0xFE, 0x32, 0x9C, 0x31, 0x75,
  37722. 0xD9, 0xE4, 0xC3, 0xE2, 0x1A, 0xB9, 0xEC, 0x83,
  37723. 0x6E, 0xDC, 0x3A, 0xCA, 0xB2, 0xE3, 0x89, 0x1E,
  37724. 0xE8, 0xDE, 0xDA, 0x51, 0x5D, 0x39, 0xAF, 0x9B,
  37725. 0x8D, 0xDD, 0x0E, 0xE7, 0xB0, 0x16, 0x4F, 0x80,
  37726. 0x5C, 0x38, 0x35, 0xF6, 0xD2, 0xBA, 0xBD, 0xB3,
  37727. 0x0E, 0xAB, 0x47, 0x56, 0xE7, 0xEC, 0x7F, 0x82,
  37728. 0x9E, 0xCE, 0x01, 0xE8, 0xEA, 0xDF, 0xBB, 0xED,
  37729. 0x12, 0xFC, 0x28, 0x3B, 0x3D, 0x4C, 0x69, 0xF5,
  37730. 0x75, 0xE7, 0xF8, 0x04, 0x17, 0x68, 0x9F, 0xDF,
  37731. 0xCF, 0xC7, 0xBE, 0x27, 0xEE, 0x3B, 0x8C, 0xDF,
  37732. 0x57, 0xAA, 0xEB, 0xEC, 0x4A, 0x95, 0xB7, 0xE5,
  37733. 0xBB, 0x58, 0x5B, 0x85, 0x22, 0x7F, 0x7C, 0x32,
  37734. 0xBE, 0x30, 0xDB, 0x3E, 0x65, 0xE4, 0x2E, 0x30,
  37735. 0xDC, 0xF5, 0xA5, 0xFA, 0x07, 0x3D, 0xBA, 0x39,
  37736. 0x9D, 0x94, 0x2F, 0x22, 0x22, 0xAD, 0xB9, 0xB9,
  37737. 0x89, 0x81, 0x02, 0xAF, 0xE5, 0x43, 0x2E, 0xDC,
  37738. 0x7F, 0x04, 0xAE, 0x34, 0xA8, 0xFE, 0xC2, 0xD8,
  37739. 0x1C, 0xB4, 0x9A, 0x9A, 0x9B, 0x43, 0x81, 0x4C,
  37740. 0xE7, 0x1D, 0x97, 0xF7, 0x26, 0xE2, 0xB1, 0xE8,
  37741. 0xF6, 0x4B, 0x50, 0xE6, 0x5D, 0xFB, 0x48, 0x16,
  37742. 0xE1, 0x2E, 0x82, 0xA3, 0x19, 0x74, 0x84, 0xA4,
  37743. 0xE9, 0xBB, 0xA4, 0xD2, 0xD6, 0x9E, 0x3F, 0x19,
  37744. 0xD0, 0xB7, 0x5C, 0x21, 0xE2, 0xBF, 0xFE, 0x9F,
  37745. 0xC0, 0xC9, 0x8C, 0xF4, 0x8A, 0x3A, 0xAF, 0x08,
  37746. 0xD4, 0x67, 0xF7, 0x26, 0x87, 0xDF, 0x01, 0x78,
  37747. 0x17, 0x4B, 0x78, 0x97, 0xF7, 0x34, 0x34, 0x9B,
  37748. 0x18, 0x1E, 0xCA, 0x86, 0xA5, 0x98, 0xA0, 0xC5,
  37749. 0xE8, 0xC2, 0x59, 0x46, 0xF2, 0x4D, 0xC5, 0x57,
  37750. 0x2B, 0xD3, 0x24, 0xA4, 0x04, 0x58, 0xA7, 0x88,
  37751. 0xE5, 0x13, 0x7F, 0x3C, 0x7A, 0x7C, 0x97, 0xFC,
  37752. 0x9F, 0x12, 0xA3, 0xC4, 0x63, 0xA8, 0xFE, 0x94,
  37753. 0x49, 0x10, 0x1C, 0xCE, 0x96, 0x6D, 0x7C, 0x00,
  37754. 0x93, 0x23, 0x93, 0x29, 0x98, 0xD5, 0x6E, 0xF4,
  37755. 0x30, 0xC7, 0x3B, 0xC2, 0x4F, 0x5D, 0x95, 0xF7,
  37756. 0x37, 0x85, 0x8D, 0xDC, 0x4F, 0x32, 0xC0, 0x13
  37757. };
  37758. #endif
  37759. #ifndef WOLFSSL_NO_ML_KEM
  37760. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ct[] = {
  37761. 0xc9, 0xbe, 0xad, 0x6b, 0x0c, 0x11, 0x14, 0x38,
  37762. 0x9b, 0xd4, 0x76, 0x1c, 0x73, 0xab, 0x90, 0x95,
  37763. 0xb5, 0x80, 0x9d, 0xaa, 0xc9, 0xf6, 0x59, 0xbb,
  37764. 0x56, 0x4a, 0xf2, 0x26, 0x17, 0x30, 0x52, 0xa4,
  37765. 0xa3, 0xe7, 0xf2, 0xe5, 0xfd, 0x47, 0xd2, 0xb0,
  37766. 0x2a, 0xae, 0xb5, 0x18, 0x9e, 0x06, 0xb9, 0xf4,
  37767. 0xae, 0x98, 0xb6, 0x19, 0xcb, 0x63, 0xef, 0xbd,
  37768. 0xf3, 0x98, 0x9a, 0x94, 0xb3, 0x6e, 0x8e, 0xa0,
  37769. 0xd7, 0x00, 0x63, 0x3b, 0x95, 0x0a, 0x0a, 0xe2,
  37770. 0xa7, 0x8e, 0xd9, 0x2e, 0x85, 0xc8, 0x5c, 0x70,
  37771. 0xe1, 0x3e, 0x62, 0x6f, 0xb2, 0x63, 0xfa, 0xc9,
  37772. 0x68, 0x15, 0x21, 0xc3, 0xab, 0x22, 0xfd, 0xab,
  37773. 0x29, 0x17, 0x3c, 0x96, 0x16, 0xa2, 0xb0, 0x37,
  37774. 0x08, 0x3f, 0xf7, 0xb2, 0xe0, 0x19, 0xb5, 0xbc,
  37775. 0xde, 0x06, 0x8f, 0xac, 0x25, 0x7e, 0xf8, 0xf1,
  37776. 0x27, 0x98, 0x41, 0x16, 0x93, 0xc1, 0xbd, 0xcc,
  37777. 0x65, 0x42, 0x09, 0x97, 0xa5, 0x13, 0xa8, 0xa6,
  37778. 0x95, 0x02, 0x62, 0x0b, 0xe8, 0xe4, 0xce, 0x73,
  37779. 0x62, 0xe4, 0x12, 0xa7, 0x6c, 0xf5, 0x1c, 0x1f,
  37780. 0x24, 0x33, 0xf1, 0xab, 0x64, 0xce, 0x0e, 0x5d,
  37781. 0x2f, 0x56, 0xd7, 0xc9, 0xad, 0xe9, 0x94, 0xd0,
  37782. 0xe3, 0x5d, 0x0a, 0xee, 0xf3, 0xac, 0x51, 0x5b,
  37783. 0x48, 0x24, 0x37, 0x66, 0x4d, 0x8c, 0x1d, 0x25,
  37784. 0xe5, 0xa5, 0x50, 0x7c, 0xf8, 0x0f, 0x97, 0x0d,
  37785. 0x3e, 0xa7, 0x22, 0x6a, 0xac, 0xdc, 0x45, 0x7c,
  37786. 0xbf, 0x88, 0xa0, 0x56, 0x0a, 0xa3, 0x5b, 0xb2,
  37787. 0xc5, 0xc4, 0x55, 0x86, 0x7e, 0x21, 0x59, 0x91,
  37788. 0x0a, 0x35, 0x81, 0x0b, 0xef, 0xe3, 0xaa, 0x10,
  37789. 0xeb, 0x04, 0xd8, 0xd5, 0x71, 0x47, 0xcb, 0x8f,
  37790. 0x66, 0xd2, 0xb0, 0x70, 0xba, 0xc4, 0x3d, 0x1f,
  37791. 0x1f, 0xfd, 0xd5, 0x7a, 0x93, 0x99, 0x95, 0x1f,
  37792. 0x64, 0x96, 0x57, 0x27, 0xbc, 0xb9, 0xf6, 0x6a,
  37793. 0xd4, 0x23, 0x09, 0xda, 0xfc, 0x79, 0x9c, 0x1c,
  37794. 0x54, 0x0a, 0xf1, 0xaf, 0x93, 0xef, 0xf6, 0x8a,
  37795. 0x86, 0xd6, 0x1f, 0x51, 0x15, 0xdb, 0x66, 0x2d,
  37796. 0xee, 0x7a, 0xc9, 0xa3, 0x62, 0x67, 0x77, 0x62,
  37797. 0xb6, 0xa1, 0x64, 0xa0, 0xfa, 0x0a, 0x4d, 0x85,
  37798. 0x9e, 0x4b, 0x8c, 0x8d, 0xbd, 0xb4, 0xe1, 0x83,
  37799. 0xf5, 0xe6, 0x80, 0x8f, 0xc5, 0x22, 0x29, 0x65,
  37800. 0x0c, 0xaf, 0x7c, 0xf3, 0xe1, 0x6d, 0xe3, 0xd8,
  37801. 0x95, 0xd1, 0x48, 0xc3, 0x54, 0x48, 0xab, 0x8c,
  37802. 0x27, 0x53, 0xc9, 0x83, 0x1b, 0x24, 0xbd, 0x49,
  37803. 0x21, 0x49, 0x7e, 0xaa, 0x19, 0x25, 0x65, 0xca,
  37804. 0xbf, 0xd8, 0x3c, 0x0c, 0x68, 0xdf, 0xe7, 0xd3,
  37805. 0x92, 0xab, 0xf5, 0xe5, 0xe6, 0xf8, 0x4b, 0xb9,
  37806. 0xf5, 0xaf, 0x4b, 0x71, 0x18, 0xc0, 0xb5, 0x58,
  37807. 0x10, 0x5f, 0x9c, 0x10, 0xc9, 0xb6, 0xd7, 0x06,
  37808. 0x82, 0xe1, 0xde, 0x6e, 0x06, 0x89, 0xd7, 0x10,
  37809. 0x6a, 0x63, 0x74, 0xbd, 0x34, 0xae, 0xd7, 0x22,
  37810. 0x9e, 0x6c, 0xb3, 0x56, 0xf2, 0xea, 0x65, 0xe6,
  37811. 0x80, 0xce, 0x7b, 0x1e, 0x2c, 0x37, 0x04, 0xe1,
  37812. 0x16, 0xa3, 0x85, 0x42, 0x82, 0x6e, 0x8a, 0x00,
  37813. 0x11, 0x41, 0xba, 0xf2, 0xe3, 0x4d, 0xe3, 0x7a,
  37814. 0x03, 0x04, 0x09, 0x86, 0xd4, 0xc0, 0xcd, 0x5d,
  37815. 0x57, 0xf0, 0x70, 0x1c, 0xe9, 0x30, 0x98, 0x6f,
  37816. 0xd9, 0x52, 0x5b, 0x58, 0xe2, 0xe5, 0x9f, 0x45,
  37817. 0xb8, 0xdd, 0x04, 0xc0, 0xf3, 0x5b, 0x0f, 0x47,
  37818. 0x97, 0x0c, 0xc6, 0x70, 0x79, 0x61, 0x8e, 0xb9,
  37819. 0xe6, 0xd9, 0x1e, 0x9b, 0x0f, 0x8c, 0x6d, 0x2e,
  37820. 0x16, 0x5c, 0xf4, 0x48, 0xa2, 0xc1, 0xeb, 0xf7,
  37821. 0x1b, 0x65, 0x37, 0xe0, 0xf3, 0x75, 0x18, 0x5d,
  37822. 0xfa, 0xfe, 0xf6, 0x98, 0xb6, 0x23, 0x9b, 0xb3,
  37823. 0x55, 0x80, 0xb3, 0x15, 0xbc, 0xb5, 0xed, 0x40,
  37824. 0x8c, 0x35, 0x7f, 0x19, 0x2d, 0xef, 0x89, 0xbc,
  37825. 0x1b, 0x75, 0xcd, 0xd6, 0xaa, 0xe8, 0xb5, 0xfa,
  37826. 0xf0, 0xc3, 0xe1, 0x38, 0x03, 0xf6, 0xbd, 0xfa,
  37827. 0x76, 0xfb, 0x40, 0x7f, 0xcb, 0xda, 0x79, 0x0c,
  37828. 0x32, 0x9b, 0x3e, 0xe4, 0x2f, 0xd3, 0xd3, 0xb0,
  37829. 0x3b, 0xd5, 0x00, 0x3f, 0x0b, 0xc4, 0x32, 0xf7,
  37830. 0xba, 0x39, 0x63, 0x11, 0x12, 0x45, 0x2d, 0xfd,
  37831. 0x12, 0x14, 0x04, 0x33, 0xff, 0x89, 0x80, 0xeb,
  37832. 0x6a, 0x52, 0x6b, 0xa8, 0x5e, 0xf9, 0x94, 0x77,
  37833. 0x37, 0x8b, 0x4d, 0xc7, 0x66, 0x35, 0xa5, 0xcd,
  37834. 0x50, 0x40, 0xe4, 0x3b, 0x8c, 0x1f, 0xe4, 0xee,
  37835. 0x5e, 0x15, 0x8e, 0x42, 0x3b, 0xfc, 0x0c, 0x89,
  37836. 0x3c, 0x1d, 0x56, 0x13, 0xbe, 0xd0, 0x8d, 0xa7,
  37837. 0x19, 0xc9, 0x07, 0x31, 0x84, 0xee, 0xb3, 0x6f,
  37838. 0xd3, 0x57, 0x38, 0x0f, 0xb1, 0x87, 0x3d, 0x8c,
  37839. 0xbd, 0x36, 0xe2, 0x25, 0x5e, 0x98, 0x5b, 0x1b,
  37840. 0x76, 0x81, 0x97, 0x43, 0xa6, 0x58, 0x4a, 0x9b,
  37841. 0x3a, 0x58, 0x09, 0x96, 0xc9, 0xc2, 0xee, 0xd9,
  37842. 0xbb, 0xbf, 0xff, 0x78, 0xa6, 0x20, 0x4b, 0x5e,
  37843. 0x5e, 0xea, 0xe5, 0xf4, 0xef, 0xd2, 0x66, 0x00,
  37844. 0x78, 0xb3, 0x7f, 0x07, 0x54, 0xab, 0x5d, 0xa8,
  37845. 0x62, 0xe6, 0x66, 0xb1, 0x45, 0xb5, 0xf2, 0x3f,
  37846. 0x3d, 0x09, 0x77, 0x79, 0x99, 0x29, 0xdf, 0xa2,
  37847. 0xae, 0xdd, 0xa5, 0x3d, 0x15, 0x2e, 0xda, 0x1d,
  37848. 0x0d, 0x0e, 0x4e, 0xa4, 0x3f, 0x6e, 0xd8, 0x89,
  37849. 0xbb, 0x96, 0x5e, 0xef, 0xe0, 0xa7, 0xc6, 0x85,
  37850. 0xbb, 0x36, 0x77, 0x0e, 0xaa, 0x87, 0x42, 0x42,
  37851. 0xc0, 0xe2, 0x29, 0xcf, 0x6c, 0xe5, 0x6d, 0xef,
  37852. 0xa5, 0xae, 0xae, 0x64, 0xd0, 0xc4, 0x0d, 0xda,
  37853. 0x8a, 0xa2, 0x6e, 0xae, 0xb3, 0x14, 0x58, 0xf0,
  37854. 0x70, 0xa3, 0xbc, 0x72, 0xe1, 0x61, 0x9e, 0xe9,
  37855. 0xb5, 0xf6, 0x42, 0x29, 0x1c, 0x56, 0xdf, 0x5b,
  37856. 0x7e, 0x43, 0xdb, 0x6c, 0x80, 0x2f, 0xc7, 0x4f,
  37857. 0x4f, 0x3f, 0x9b, 0x5c, 0x0d, 0x35, 0x5c, 0x3a,
  37858. 0xae, 0x52, 0x0a, 0xa3, 0x12, 0x29, 0xd1, 0x2f,
  37859. 0x3e, 0x7c, 0xc5, 0xd4, 0x8e, 0x69, 0x11, 0x91,
  37860. 0xa3, 0x6b, 0x28, 0x37, 0x65, 0xf4, 0x13, 0x3f,
  37861. 0x0f, 0xf1, 0xfe, 0x2f, 0x01, 0xc6, 0x64, 0x8b,
  37862. 0x27, 0x98, 0xa7, 0x4e, 0xb5, 0xd8, 0x42, 0xa2,
  37863. 0x48, 0xf5, 0x24, 0xa7, 0xe7, 0xf8, 0x97, 0x42,
  37864. 0x11, 0x29, 0x7b, 0x44, 0xf0, 0xdd, 0x19, 0xf3,
  37865. 0x86, 0xe8, 0x6b, 0xe6, 0xba, 0x78, 0x2d, 0xe7,
  37866. 0x7f, 0xde, 0x88, 0x72, 0x26, 0xf3, 0x7a, 0x1c,
  37867. 0x77, 0xbc, 0x5e, 0xdd, 0xee, 0xe5, 0xbf, 0x46,
  37868. 0xb6, 0x7f, 0xb7, 0x47, 0x8d, 0x55, 0x98, 0x65,
  37869. 0xf2, 0x62, 0xca, 0xa8, 0x4d, 0x64, 0xa8, 0xce,
  37870. 0x59, 0xe4, 0xdf, 0x08, 0x18, 0xe1, 0x48, 0x61,
  37871. 0x52, 0x6a, 0xcd, 0x34, 0x83, 0x60, 0x0f, 0x3d,
  37872. 0xae, 0x79, 0x59, 0xd3, 0x5d, 0x81, 0x81, 0xca,
  37873. 0x6a, 0x81, 0xce, 0x79, 0x1b, 0xe0, 0x07, 0x52,
  37874. 0xda, 0x77, 0x59, 0x44, 0x6a, 0x2c, 0xfb, 0xe0,
  37875. 0x0b, 0x82, 0x48, 0xb9, 0x34, 0x91, 0xde, 0xbd,
  37876. 0x52, 0x02, 0x20, 0xb7, 0x55, 0x41, 0x6d, 0x2f,
  37877. 0xc6, 0xb7, 0xc8, 0xaf, 0x2f, 0xf7, 0x5e, 0x5b,
  37878. 0xcb, 0xb8, 0xe7, 0x53, 0x73, 0x80, 0xa5, 0x72,
  37879. 0x1c, 0x77, 0x48, 0x49, 0x57, 0xa6, 0x92, 0x71,
  37880. 0xd8, 0xba, 0xfc, 0xe0, 0xf1, 0x66, 0x73, 0x5f,
  37881. 0xf8, 0x69, 0x23, 0x2d, 0xe5, 0xd3, 0x81, 0xaf,
  37882. 0xbf, 0x0e, 0x44, 0xd6, 0x91, 0x72, 0xb7, 0x9a,
  37883. 0x35, 0x19, 0x19, 0x49, 0xde, 0x09, 0x70, 0x3b,
  37884. 0x94, 0x22, 0x2b, 0x13, 0xc3, 0x85, 0xc6, 0x08,
  37885. 0x1e, 0x6d, 0x2e, 0xde, 0x1e, 0x57, 0xfe, 0x18,
  37886. 0x4e, 0xf8, 0xf6, 0x01, 0x96, 0xb9, 0xa3, 0xa7,
  37887. 0xb7, 0xef, 0xf7, 0x49, 0x71, 0x91, 0xca, 0x87,
  37888. 0x41, 0xb5, 0xa0, 0x1e, 0x79, 0xcb, 0x69, 0xa6,
  37889. 0x11, 0x42, 0xe6, 0xf5, 0xd0, 0x80, 0xfb, 0xb3,
  37890. 0xe5, 0x66, 0xf7, 0x9e, 0x14, 0x6f, 0x75, 0xc8,
  37891. 0xa1, 0x09, 0x78, 0x60, 0x84, 0x1b, 0x47, 0x47,
  37892. 0xdf, 0x60, 0x4d, 0xba, 0x95, 0x4e, 0x4a, 0x8d,
  37893. 0x9e, 0x0d, 0xcc, 0xc1, 0xf6, 0x09, 0xd0, 0x5c,
  37894. 0xf8, 0xd3, 0x12, 0x19, 0xec, 0xd6, 0x0c, 0x31,
  37895. 0x2d, 0xe6, 0x84, 0x55, 0x2f, 0x09, 0x22, 0x7c,
  37896. 0xb8, 0x29, 0x29, 0x1c, 0x64, 0x57, 0x32, 0xc5,
  37897. 0xf5, 0xd4, 0xd7, 0x11, 0x63, 0x9f, 0x42, 0xa2,
  37898. 0x30, 0x80, 0xaa, 0x34, 0xfe, 0x14, 0x20, 0xf2,
  37899. 0x19, 0xbd, 0x6b, 0xcf, 0x4e, 0x3b, 0x29, 0xb9,
  37900. 0xd0, 0x22, 0x93, 0xb2, 0xda, 0x81, 0x38, 0x3e,
  37901. 0x0a, 0x51, 0xd2, 0xbb, 0x18, 0x6c, 0x7b, 0x0a,
  37902. 0x21, 0x1a, 0x0c, 0xd6, 0x3a, 0xcb, 0xfc, 0x02,
  37903. 0x10, 0x40, 0x1e, 0x98, 0x5d, 0x43, 0x6b, 0x38,
  37904. 0x03, 0xd5, 0x60, 0x1c, 0x24, 0x13, 0x6a, 0xfd,
  37905. 0x15, 0x62, 0x52, 0x2e, 0x45, 0xb4, 0x57, 0xcb,
  37906. 0x43, 0x91, 0x78, 0xbe, 0x4a, 0x87, 0xcc, 0xe4,
  37907. 0x03, 0x46, 0xd3, 0x4a, 0xe0, 0xf3, 0xc3, 0x91,
  37908. 0x03, 0xc8, 0xa3, 0xeb, 0xc9, 0xc8, 0x6c, 0x8d,
  37909. 0xb8, 0xfc, 0x55, 0x61, 0xeb, 0x0f, 0x3a, 0x14,
  37910. 0x3d, 0x4e, 0x9f, 0xe9, 0x3a, 0x5c, 0xba, 0x6f,
  37911. 0x6f, 0xca, 0xe5, 0x65, 0x0d, 0x3f, 0x43, 0xd2,
  37912. 0x66, 0x8a, 0x59, 0x56, 0xc9, 0x22, 0x89, 0x3b,
  37913. 0x81, 0x66, 0x47, 0xde, 0xd0, 0xaf, 0xc0, 0x52,
  37914. 0xa6, 0xc3, 0xd9, 0xd0, 0x1a, 0x3d, 0x3a, 0xf0,
  37915. 0xf1, 0xba, 0x80, 0x7f, 0xf1, 0x04, 0x91, 0xe1,
  37916. 0x31, 0xdc, 0x15, 0xe1, 0x65, 0xcf, 0xd0, 0x65,
  37917. 0x0a, 0x1f, 0x2c, 0x31, 0x3d, 0x79, 0x56, 0x14,
  37918. 0x1e, 0xdc, 0xc6, 0x1c, 0xb9, 0x0e, 0x9e, 0x7a,
  37919. 0xbf, 0x2f, 0xe3, 0x5f, 0xc9, 0xdc, 0x1b, 0xde,
  37920. 0x88, 0x93, 0x9f, 0xa1, 0x1f, 0x7b, 0xbe, 0x3e,
  37921. 0xb4, 0xd8, 0xff, 0xa6, 0x43, 0xb0, 0x74, 0xd7,
  37922. 0x4f, 0x45, 0x11, 0x35, 0x86, 0xe9, 0xbb, 0x12,
  37923. 0x06, 0x00, 0x03, 0xd7, 0x19, 0x41, 0xf2, 0xda,
  37924. 0x09, 0x8d, 0xc0, 0xe9, 0x6c, 0xad, 0x32, 0x55,
  37925. 0xcf, 0x32, 0x8e, 0xa2, 0xd3, 0x30, 0x8c, 0x1f,
  37926. 0x45, 0x85, 0xe8, 0x9c, 0x61, 0x3c, 0x42, 0x6b,
  37927. 0x7e, 0x79, 0x8e, 0x1e, 0xc4, 0xe9, 0x8f, 0xe6,
  37928. 0xc7, 0x1e, 0x74, 0x91, 0xf5, 0xec, 0xa0, 0xcd,
  37929. 0x05, 0x11, 0x58, 0x61, 0xbd, 0x16, 0x0e, 0x3f,
  37930. 0xe7, 0x3a, 0x58, 0xa0, 0x26, 0xba, 0x53, 0x8e,
  37931. 0x0e, 0x25, 0x6b, 0x92, 0xf1, 0xd7, 0xa2, 0x49,
  37932. 0x75, 0x70, 0x59, 0x48, 0x56, 0x86, 0x0f, 0xfd,
  37933. 0x06, 0xb6, 0x01, 0xac, 0x57, 0x55, 0x92, 0xf4,
  37934. 0xac, 0x61, 0x2b, 0x5d, 0xe7, 0x86, 0x60, 0x42,
  37935. 0x12, 0x3e, 0xbc, 0x60, 0xc5, 0x57, 0x68, 0xe3,
  37936. 0xa7, 0x60, 0x0a, 0x32, 0x60, 0x55, 0x1f, 0x2b,
  37937. 0xea, 0x22, 0xbb, 0xf6, 0xb6, 0xc8, 0x24, 0x6e,
  37938. 0x80, 0xf9, 0x12, 0x5c, 0x4b, 0xb9, 0xdb, 0x35,
  37939. 0x4d, 0xd6, 0x4a, 0xe6, 0x95, 0xc1, 0x5f, 0x50,
  37940. 0x71, 0xf4, 0xab, 0xb9, 0x63, 0x92, 0x07, 0xca,
  37941. 0xc7, 0x33, 0x1b, 0x31, 0x0f, 0x69, 0xa0, 0x5f,
  37942. 0x54, 0xb9, 0x95, 0xde, 0x52, 0x9a, 0x02, 0x3f,
  37943. 0x03, 0x3b, 0x05, 0x5d, 0xb9, 0x52, 0x87, 0xa1,
  37944. 0x4b, 0xa3, 0x0a, 0x7c, 0xc5, 0x26, 0xbb, 0x72,
  37945. 0x4c, 0x41, 0x7f, 0xba, 0x29, 0x06, 0x36, 0xa9,
  37946. 0x96, 0xf2, 0x86, 0xe3, 0xe9, 0xe9, 0x39, 0xe4,
  37947. 0xfe, 0x1c, 0x39, 0x8b, 0x5c, 0x65, 0x99, 0x95,
  37948. 0x9d, 0x0b, 0x44, 0x45, 0xa3, 0x27, 0xec, 0x46,
  37949. 0x9a, 0x16, 0x53, 0xcf, 0xae, 0xa7, 0x55, 0x2c,
  37950. 0xec, 0xec, 0x08, 0x5c, 0xca, 0xa6, 0x89, 0x38,
  37951. 0xae, 0x4a, 0xc3, 0xc4, 0x24, 0xf7, 0xe4, 0x80,
  37952. 0x43, 0x9e, 0xbd, 0x2c, 0x99, 0x2b, 0x5f, 0x6f,
  37953. 0x95, 0xec, 0x24, 0x4b, 0x65, 0x7d, 0xbd, 0xea,
  37954. 0xa9, 0xae, 0x11, 0x0a, 0xaf, 0x4d, 0x68, 0xbf,
  37955. 0x4e, 0x27, 0x41, 0x0d, 0x43, 0xce, 0xef, 0x3e,
  37956. 0x88, 0xe9, 0xc7, 0x17, 0xdd, 0x44, 0xc9, 0xee
  37957. };
  37958. #endif
  37959. #ifdef WOLFSSL_KYBER_ORIGINAL
  37960. WOLFSSL_SMALL_STACK_STATIC const byte kyber1024_ss[] = {
  37961. 0xB1, 0x0F, 0x73, 0x94, 0x92, 0x6A, 0xD3, 0xB4,
  37962. 0x9C, 0x5D, 0x62, 0xD5, 0xAE, 0xB5, 0x31, 0xD5,
  37963. 0x75, 0x75, 0x38, 0xBC, 0xC0, 0xDA, 0x9E, 0x55,
  37964. 0x0D, 0x43, 0x8F, 0x1B, 0x61, 0xBD, 0x74, 0x19
  37965. };
  37966. #endif
  37967. #ifndef WOLFSSL_NO_ML_KEM
  37968. WOLFSSL_SMALL_STACK_STATIC const byte ml_kem_1024_ss[] = {
  37969. 0x48, 0x9d, 0xd1, 0xe9, 0xc2, 0xbe, 0x4a, 0xf3,
  37970. 0x48, 0x2b, 0xdb, 0x35, 0xbb, 0x26, 0xce, 0x76,
  37971. 0x0e, 0x6e, 0x41, 0x4d, 0xa6, 0xec, 0xbe, 0x48,
  37972. 0x99, 0x85, 0x74, 0x8a, 0x82, 0x5f, 0x1c, 0xd6
  37973. };
  37974. #endif
  37975. #ifdef WOLFSSL_SMALL_STACK
  37976. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  37977. DYNAMIC_TYPE_TMP_BUFFER);
  37978. priv = (byte *)XMALLOC(KYBER1024_PRIVATE_KEY_SIZE, HEAP_HINT,
  37979. DYNAMIC_TYPE_TMP_BUFFER);
  37980. pub = (byte *)XMALLOC(KYBER1024_PUBLIC_KEY_SIZE, HEAP_HINT,
  37981. DYNAMIC_TYPE_TMP_BUFFER);
  37982. ct = (byte *)XMALLOC(KYBER1024_CIPHER_TEXT_SIZE, HEAP_HINT,
  37983. DYNAMIC_TYPE_TMP_BUFFER);
  37984. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37985. DYNAMIC_TYPE_TMP_BUFFER);
  37986. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  37987. DYNAMIC_TYPE_TMP_BUFFER);
  37988. if (! (key && priv && pub && ct && ss && ss_dec))
  37989. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  37990. #endif
  37991. #ifdef WOLFSSL_KYBER_ORIGINAL
  37992. ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
  37993. if (ret != 0)
  37994. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  37995. else
  37996. key_inited = 1;
  37997. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  37998. sizeof(kyber1024_rand));
  37999. if (ret != 0)
  38000. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38001. ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
  38002. if (ret != 0)
  38003. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38004. ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
  38005. if (ret != 0)
  38006. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38007. if (XMEMCMP(pub, kyber1024_pk, sizeof(kyber1024_pk)) != 0)
  38008. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38009. if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
  38010. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38011. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38012. sizeof(kyber1024enc_rand));
  38013. if (ret != 0)
  38014. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38015. if (XMEMCMP(ct, kyber1024_ct, sizeof(kyber1024_ct)) != 0)
  38016. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38017. if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38018. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38019. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
  38020. if (ret != 0)
  38021. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38022. if (XMEMCMP(ss_dec, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
  38023. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38024. #endif
  38025. #ifndef WOLFSSL_NO_ML_KEM
  38026. ret = wc_KyberKey_Init(WC_ML_KEM_1024, key, HEAP_HINT, INVALID_DEVID);
  38027. if (ret != 0)
  38028. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38029. else
  38030. key_inited = 1;
  38031. ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
  38032. sizeof(kyber1024_rand));
  38033. if (ret != 0)
  38034. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38035. ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE);
  38036. if (ret != 0)
  38037. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38038. ret = wc_KyberKey_EncodePrivateKey(key, priv,
  38039. WC_ML_KEM_MAX_PRIVATE_KEY_SIZE);
  38040. if (ret != 0)
  38041. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38042. if (XMEMCMP(pub, ml_kem_1024_pk, sizeof(ml_kem_1024_pk)) != 0)
  38043. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38044. if (XMEMCMP(priv, ml_kem_1024_sk, sizeof(ml_kem_1024_sk)) != 0)
  38045. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38046. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
  38047. sizeof(kyber1024enc_rand));
  38048. if (ret != 0)
  38049. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38050. if (XMEMCMP(ct, ml_kem_1024_ct, sizeof(ml_kem_1024_ct)) != 0)
  38051. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38052. if (XMEMCMP(ss, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38053. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38054. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_1024_ct));
  38055. if (ret != 0)
  38056. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38057. if (XMEMCMP(ss_dec, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
  38058. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  38059. #endif
  38060. out:
  38061. if (key_inited)
  38062. wc_KyberKey_Free(key);
  38063. #ifdef WOLFSSL_SMALL_STACK
  38064. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38065. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38066. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38067. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38068. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38069. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38070. #endif
  38071. return ret;
  38072. }
  38073. #endif /* WOLFSSL_KYBER1024 */
  38074. #endif /* WOLFSSL_WC_KYBER */
  38075. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
  38076. {
  38077. wc_test_ret_t ret;
  38078. WC_RNG rng;
  38079. int i;
  38080. #ifdef WOLFSSL_SMALL_STACK
  38081. KyberKey *key = NULL;
  38082. byte *priv = NULL;
  38083. byte *pub = NULL;
  38084. byte *priv2 = NULL;
  38085. byte *pub2 = NULL;
  38086. byte *ct = NULL;
  38087. byte *ss = NULL;
  38088. byte *ss_dec = NULL;
  38089. #else
  38090. KyberKey key[1];
  38091. byte priv[KYBER_MAX_PRIVATE_KEY_SIZE];
  38092. byte pub[KYBER_MAX_PUBLIC_KEY_SIZE];
  38093. byte priv2[KYBER_MAX_PRIVATE_KEY_SIZE];
  38094. byte pub2[KYBER_MAX_PUBLIC_KEY_SIZE];
  38095. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  38096. byte ss[KYBER_SS_SZ];
  38097. byte ss_dec[KYBER_SS_SZ];
  38098. #endif
  38099. int key_inited = 0;
  38100. static const int testData[][4] = {
  38101. #ifndef WOLFSSL_NO_ML_KEM
  38102. #ifdef WOLFSSL_WC_ML_KEM_512
  38103. { WC_ML_KEM_512, WC_ML_KEM_512_PRIVATE_KEY_SIZE,
  38104. WC_ML_KEM_512_PUBLIC_KEY_SIZE, WC_ML_KEM_512_CIPHER_TEXT_SIZE },
  38105. #endif
  38106. #ifdef WOLFSSL_WC_ML_KEM_768
  38107. { WC_ML_KEM_768, WC_ML_KEM_768_PRIVATE_KEY_SIZE,
  38108. WC_ML_KEM_768_PUBLIC_KEY_SIZE, WC_ML_KEM_768_CIPHER_TEXT_SIZE },
  38109. #endif
  38110. #ifdef WOLFSSL_WC_ML_KEM_1024
  38111. { WC_ML_KEM_1024, WC_ML_KEM_1024_PRIVATE_KEY_SIZE,
  38112. WC_ML_KEM_1024_PUBLIC_KEY_SIZE, WC_ML_KEM_1024_CIPHER_TEXT_SIZE },
  38113. #endif
  38114. #endif
  38115. #ifdef WOLFSSL_KYBER_ORIGINAL
  38116. #ifdef WOLFSSL_KYBER512
  38117. { KYBER512, KYBER512_PRIVATE_KEY_SIZE, KYBER512_PUBLIC_KEY_SIZE,
  38118. KYBER512_CIPHER_TEXT_SIZE },
  38119. #endif
  38120. #ifdef WOLFSSL_KYBER768
  38121. { KYBER768, KYBER768_PRIVATE_KEY_SIZE, KYBER768_PUBLIC_KEY_SIZE,
  38122. KYBER768_CIPHER_TEXT_SIZE },
  38123. #endif
  38124. #ifdef WOLFSSL_KYBER1024
  38125. { KYBER1024, KYBER1024_PRIVATE_KEY_SIZE, KYBER1024_PUBLIC_KEY_SIZE,
  38126. KYBER1024_CIPHER_TEXT_SIZE },
  38127. #endif
  38128. #endif
  38129. };
  38130. WOLFSSL_ENTER("kyber_test");
  38131. #ifdef WOLFSSL_SMALL_STACK
  38132. key = (KyberKey *)XMALLOC(sizeof(KyberKey), HEAP_HINT,
  38133. DYNAMIC_TYPE_TMP_BUFFER);
  38134. priv = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38135. DYNAMIC_TYPE_TMP_BUFFER);
  38136. pub = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38137. DYNAMIC_TYPE_TMP_BUFFER);
  38138. priv2 = (byte *)XMALLOC(KYBER_MAX_PRIVATE_KEY_SIZE, HEAP_HINT,
  38139. DYNAMIC_TYPE_TMP_BUFFER);
  38140. pub2 = (byte *)XMALLOC(KYBER_MAX_PUBLIC_KEY_SIZE, HEAP_HINT,
  38141. DYNAMIC_TYPE_TMP_BUFFER);
  38142. ct = (byte *)XMALLOC(KYBER_MAX_CIPHER_TEXT_SIZE, HEAP_HINT,
  38143. DYNAMIC_TYPE_TMP_BUFFER);
  38144. ss = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38145. DYNAMIC_TYPE_TMP_BUFFER);
  38146. ss_dec = (byte *)XMALLOC(KYBER_SS_SZ, HEAP_HINT,
  38147. DYNAMIC_TYPE_TMP_BUFFER);
  38148. if (! (key && priv && pub && priv2 && pub2 && ct && ss && ss_dec))
  38149. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38150. #endif
  38151. #ifndef HAVE_FIPS
  38152. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  38153. #else
  38154. ret = wc_InitRng(&rng);
  38155. #endif
  38156. if (ret != 0)
  38157. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38158. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  38159. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38160. if (ret != 0)
  38161. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38162. else
  38163. key_inited = 1;
  38164. ret = wc_KyberKey_MakeKey(key, &rng);
  38165. if (ret != 0)
  38166. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38167. ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
  38168. if (ret != 0)
  38169. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38170. ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
  38171. if (ret != 0)
  38172. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38173. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38174. if (ret != 0)
  38175. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38176. ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
  38177. if (ret != 0)
  38178. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38179. ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
  38180. if (ret != 0)
  38181. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38182. ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
  38183. if (ret != 0)
  38184. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38185. if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
  38186. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38187. ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
  38188. if (ret != 0)
  38189. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38190. ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
  38191. if (ret != 0)
  38192. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38193. ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
  38194. if (ret != 0)
  38195. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38196. if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
  38197. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38198. ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
  38199. if (ret != 0)
  38200. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38201. if (XMEMCMP(priv, priv2, testData[i][2]) != 0)
  38202. ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
  38203. }
  38204. wc_FreeRng(&rng);
  38205. #ifdef WOLFSSL_WC_KYBER
  38206. #if !defined(WOLFSSL_NO_KYBER512) && !defined(WOLFSSL_NO_ML_KEM_512)
  38207. ret = kyber512_kat();
  38208. if (ret != 0)
  38209. goto out;
  38210. #endif
  38211. #if !defined(WOLFSSL_NO_KYBER768) && !defined(WOLFSSL_NO_ML_KEM_768)
  38212. ret = kyber768_kat();
  38213. if (ret != 0)
  38214. goto out;
  38215. #endif
  38216. #if !defined(WOLFSSL_NO_KYBER1024) && !defined(WOLFSSL_NO_ML_KEM_1024)
  38217. ret = kyber1024_kat();
  38218. if (ret != 0)
  38219. goto out;
  38220. #endif
  38221. #endif /* WOLFSSL_WC_KYBER */
  38222. out:
  38223. if (key_inited)
  38224. wc_KyberKey_Free(key);
  38225. #ifdef WOLFSSL_SMALL_STACK
  38226. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38227. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38228. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38229. XFREE(priv2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38230. XFREE(pub2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38231. XFREE(ct, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38232. XFREE(ss, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38233. XFREE(ss_dec, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38234. #endif
  38235. return ret;
  38236. }
  38237. #endif /* WOLFSSL_HAVE_KYBER */
  38238. #ifdef HAVE_DILITHIUM
  38239. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  38240. static wc_test_ret_t dilithium_param_vfy_test(int param, const byte* pubKey,
  38241. word32 pubKeyLen, const byte* sig, word32 sigLen)
  38242. {
  38243. byte msg[512];
  38244. dilithium_key* key;
  38245. byte * pubExported = NULL;
  38246. wc_test_ret_t ret;
  38247. int i;
  38248. int res = 0;
  38249. word32 lenExported = pubKeyLen;
  38250. int n_diff = 0;
  38251. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  38252. DYNAMIC_TYPE_TMP_BUFFER);
  38253. if (key == NULL) {
  38254. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38255. }
  38256. pubExported = (byte*)XMALLOC(pubKeyLen, HEAP_HINT,
  38257. DYNAMIC_TYPE_TMP_BUFFER);
  38258. if (pubExported == NULL) {
  38259. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  38260. }
  38261. /* make dummy msg */
  38262. for (i = 0; i < (int)sizeof(msg); i++) {
  38263. msg[i] = (byte)i;
  38264. }
  38265. ret = wc_dilithium_init(key);
  38266. if (ret != 0) {
  38267. ret = WC_TEST_RET_ENC_EC(ret);
  38268. return ret;
  38269. }
  38270. ret = wc_dilithium_set_level(key, param);
  38271. if (ret != 0)
  38272. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38273. ret = wc_dilithium_import_public(pubKey, pubKeyLen, key);
  38274. if (ret != 0)
  38275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38276. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38277. if (param >= WC_ML_DSA_DRAFT) {
  38278. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg),
  38279. &res, key);
  38280. }
  38281. else
  38282. #endif
  38283. {
  38284. ret = wc_dilithium_verify_ctx_msg(sig, sigLen, NULL, 0, msg,
  38285. (word32)sizeof(msg), &res, key);
  38286. }
  38287. if (ret != 0)
  38288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38289. if (res != 1)
  38290. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  38291. /* Now test the export pub raw API, verify we recover the original pub. */
  38292. ret = wc_dilithium_export_public(key, pubExported, &lenExported);
  38293. if (ret != 0) {
  38294. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  38295. }
  38296. if (lenExported <= 0 || lenExported != pubKeyLen) {
  38297. ERROR_OUT(WC_TEST_RET_ENC_EC(lenExported), out);
  38298. }
  38299. n_diff = XMEMCMP(pubExported, pubKey, pubKeyLen);
  38300. if (n_diff) {
  38301. ERROR_OUT(WC_TEST_RET_ENC_EC(n_diff), out);
  38302. }
  38303. out:
  38304. wc_dilithium_free(key);
  38305. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38306. XFREE(pubExported, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  38307. return ret;
  38308. }
  38309. #ifndef WOLFSSL_NO_ML_DSA_44
  38310. static wc_test_ret_t dilithium_param_44_vfy_test(void)
  38311. {
  38312. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_pub_key[] = {
  38313. 0xd8, 0xac, 0xaf, 0xd8, 0x2e, 0x14, 0x23, 0x78, 0xf7, 0x0d, 0x9a, 0x04,
  38314. 0x2b, 0x92, 0x48, 0x67, 0x60, 0x55, 0x34, 0xd9, 0xac, 0x0b, 0xc4, 0x1f,
  38315. 0x46, 0xe8, 0x85, 0xb9, 0x2e, 0x1b, 0x10, 0x3a, 0x75, 0x7a, 0xc2, 0xbc,
  38316. 0x76, 0xf0, 0x6d, 0x05, 0xa4, 0x78, 0x48, 0x84, 0x26, 0x69, 0xbd, 0x26,
  38317. 0x1d, 0x73, 0x60, 0xaa, 0x57, 0x9d, 0x8c, 0x66, 0xb1, 0x19, 0xea, 0x11,
  38318. 0xff, 0xbb, 0xf6, 0xeb, 0x26, 0x26, 0xac, 0x78, 0x74, 0x46, 0x6d, 0x51,
  38319. 0x6e, 0x92, 0xdf, 0x6a, 0x98, 0x41, 0xe9, 0x10, 0xf2, 0xcc, 0xa8, 0x7a,
  38320. 0x50, 0xdb, 0x1f, 0x4c, 0x42, 0x19, 0xd5, 0xbc, 0x76, 0x20, 0x6f, 0x2f,
  38321. 0xbf, 0xc2, 0xc9, 0x1b, 0x02, 0xb5, 0xb1, 0x09, 0x46, 0x06, 0x87, 0x02,
  38322. 0xac, 0x3d, 0xcf, 0xc3, 0xa5, 0x1b, 0xf0, 0xce, 0xd4, 0x9e, 0x84, 0x34,
  38323. 0x3c, 0x24, 0x7d, 0x89, 0xf3, 0xbf, 0x9c, 0x18, 0x9d, 0x1b, 0x1d, 0xd4,
  38324. 0xf6, 0xda, 0xc9, 0xa4, 0x14, 0xc4, 0x6b, 0xd7, 0x05, 0x6d, 0xed, 0x54,
  38325. 0x42, 0x6b, 0x5f, 0x6d, 0x1e, 0xda, 0x6b, 0x47, 0x70, 0xe5, 0x4e, 0xe7,
  38326. 0x25, 0x06, 0xf8, 0x28, 0x24, 0x34, 0xd6, 0xe5, 0xbe, 0xc5, 0x4f, 0x9e,
  38327. 0x5d, 0x33, 0xfc, 0xef, 0xe4, 0xe9, 0x55, 0x67, 0x93, 0x1f, 0x2e, 0x11,
  38328. 0x3a, 0x2e, 0xf2, 0xbb, 0x82, 0x09, 0x8d, 0xb2, 0x09, 0xf3, 0x2f, 0xef,
  38329. 0x6f, 0x38, 0xc6, 0x56, 0xf2, 0x23, 0x08, 0x63, 0x99, 0x7f, 0x4e, 0xc0,
  38330. 0x9d, 0x08, 0x9d, 0xa1, 0x59, 0x6e, 0xe1, 0x00, 0x2c, 0x99, 0xec, 0x83,
  38331. 0x2f, 0x12, 0x97, 0x2f, 0x75, 0x04, 0x67, 0x44, 0xb5, 0x95, 0xce, 0xc6,
  38332. 0x3e, 0x7a, 0x10, 0x77, 0x5e, 0xbe, 0x9c, 0x0f, 0xb3, 0xc7, 0x38, 0xbf,
  38333. 0x9e, 0x35, 0x8f, 0xe4, 0x8d, 0x19, 0xc3, 0x41, 0xb1, 0x0b, 0x8c, 0x10,
  38334. 0x9a, 0x58, 0xec, 0x4f, 0xb3, 0xe9, 0x5b, 0x72, 0x4b, 0xb8, 0x99, 0x34,
  38335. 0x9a, 0xcd, 0xb0, 0x69, 0xd0, 0x67, 0xef, 0x96, 0xb9, 0xe5, 0x54, 0x92,
  38336. 0xb7, 0x1a, 0x52, 0xf6, 0x0a, 0xc2, 0x23, 0x8d, 0x4f, 0xad, 0x00, 0xae,
  38337. 0x0f, 0x97, 0xfa, 0xce, 0x96, 0xba, 0xe7, 0x74, 0x55, 0xd4, 0xaf, 0xbf,
  38338. 0xa1, 0x32, 0x91, 0x2d, 0x03, 0x9f, 0xe3, 0x10, 0x8c, 0x77, 0x5d, 0x26,
  38339. 0x76, 0xf1, 0x87, 0x90, 0xf0, 0x20, 0xd1, 0xea, 0xf7, 0xa4, 0xe8, 0x2c,
  38340. 0x32, 0x1c, 0x55, 0xc0, 0x5d, 0xc9, 0xcd, 0x4e, 0x8f, 0x0d, 0xef, 0x0a,
  38341. 0x27, 0xb6, 0x4f, 0xa4, 0xd3, 0xa4, 0xed, 0x33, 0x22, 0xa1, 0xd3, 0x15,
  38342. 0xac, 0x1a, 0x20, 0x4e, 0x28, 0x8c, 0x8c, 0xd0, 0x71, 0xd1, 0xf2, 0xdb,
  38343. 0x33, 0x63, 0xb6, 0xa4, 0xf2, 0x17, 0x3c, 0x12, 0xb0, 0xad, 0xef, 0x31,
  38344. 0x91, 0xfe, 0xe5, 0x53, 0x99, 0xb6, 0x85, 0x63, 0xfa, 0xe6, 0xcd, 0xf6,
  38345. 0xb9, 0xce, 0x4a, 0x7d, 0x4a, 0x49, 0x29, 0xd2, 0xd9, 0xc9, 0x47, 0x4a,
  38346. 0x8a, 0x5c, 0x14, 0x5e, 0x0f, 0x7c, 0xc3, 0x91, 0xb0, 0xab, 0x37, 0xf5,
  38347. 0x26, 0x8d, 0x46, 0x74, 0x49, 0xad, 0x51, 0xc3, 0x11, 0xfa, 0x85, 0x15,
  38348. 0xa5, 0x84, 0xc1, 0xe0, 0x3c, 0x13, 0x6d, 0x13, 0xa3, 0xe6, 0xa8, 0x3c,
  38349. 0x22, 0xac, 0x17, 0x48, 0x57, 0x7c, 0x81, 0xe2, 0x4e, 0xd8, 0x33, 0x5d,
  38350. 0x4d, 0x65, 0xf7, 0xe1, 0xb8, 0x00, 0x78, 0x09, 0x16, 0xb0, 0x0b, 0xca,
  38351. 0x15, 0x0d, 0xcd, 0x9a, 0xd8, 0x47, 0x4c, 0x9b, 0x69, 0xb2, 0xa0, 0x9d,
  38352. 0x96, 0x96, 0x52, 0x6d, 0x89, 0xad, 0xff, 0x55, 0xde, 0x7b, 0xd6, 0x3d,
  38353. 0x1d, 0x5e, 0x8d, 0xf1, 0xfc, 0x48, 0x1c, 0x50, 0x59, 0x55, 0xb9, 0x07,
  38354. 0xfd, 0x6b, 0xcb, 0x95, 0xa6, 0x14, 0x73, 0xdb, 0x40, 0x40, 0x1c, 0x44,
  38355. 0xe6, 0x79, 0x30, 0x88, 0xbd, 0xa0, 0xde, 0x9b, 0xb8, 0x76, 0xf8, 0x98,
  38356. 0x56, 0x4b, 0xb9, 0x7a, 0xf6, 0xd4, 0x73, 0x89, 0x6b, 0xf7, 0x7d, 0x05,
  38357. 0x33, 0xbe, 0xb6, 0x1c, 0x4d, 0xa7, 0x12, 0x3b, 0x3f, 0xed, 0x4a, 0x0f,
  38358. 0xae, 0xa7, 0x6a, 0x26, 0x0d, 0x01, 0x84, 0x84, 0xa8, 0x0e, 0xc1, 0xc1,
  38359. 0xfd, 0xe4, 0xa9, 0xe2, 0x3f, 0xab, 0xce, 0x20, 0x90, 0x86, 0x79, 0xa2,
  38360. 0x40, 0xd0, 0xef, 0x79, 0x34, 0x2b, 0xe8, 0xc9, 0x54, 0xa7, 0x19, 0x62,
  38361. 0xcc, 0x20, 0x79, 0x3f, 0x5b, 0x9c, 0x61, 0xc2, 0xc1, 0xd2, 0x36, 0x7c,
  38362. 0x8e, 0xe3, 0x01, 0xbe, 0xc4, 0xb2, 0xb8, 0x07, 0x51, 0x23, 0x5b, 0x5d,
  38363. 0x00, 0xe6, 0x7f, 0xd6, 0xbb, 0x32, 0xa9, 0x7e, 0xb4, 0x30, 0xeb, 0x5e,
  38364. 0x6d, 0xed, 0xb2, 0xc3, 0x88, 0x81, 0xa3, 0x3b, 0x1f, 0x1e, 0xf9, 0x48,
  38365. 0x10, 0xd6, 0x01, 0x65, 0x5f, 0x6d, 0xc5, 0xeb, 0x76, 0x5f, 0x10, 0x79,
  38366. 0xaa, 0xc0, 0x86, 0xe7, 0x44, 0x95, 0x44, 0x4b, 0x54, 0x0c, 0x46, 0x2a,
  38367. 0x98, 0x01, 0x6e, 0xc0, 0xb9, 0x59, 0x2a, 0xff, 0x8f, 0xb3, 0x80, 0x15,
  38368. 0xec, 0xcd, 0x39, 0x36, 0xd7, 0x2f, 0x20, 0x9e, 0x3a, 0xc1, 0x90, 0xe5,
  38369. 0x99, 0x27, 0x16, 0xd7, 0x6c, 0x30, 0x10, 0x12, 0x03, 0x3e, 0xdc, 0xb9,
  38370. 0x03, 0x25, 0xb0, 0x8a, 0x27, 0x4d, 0x1a, 0x32, 0x36, 0x54, 0xc0, 0xba,
  38371. 0x22, 0xb2, 0xe2, 0xf6, 0x39, 0x23, 0x03, 0xc4, 0xc9, 0xe4, 0x0d, 0x99,
  38372. 0xfb, 0x98, 0xa5, 0x9b, 0x12, 0x9b, 0x58, 0x44, 0x74, 0x9f, 0x65, 0x61,
  38373. 0x51, 0xba, 0x31, 0x60, 0x9c, 0xec, 0xf8, 0x4d, 0x36, 0x61, 0xd1, 0x33,
  38374. 0x6d, 0xa6, 0x28, 0x75, 0xba, 0x7c, 0x82, 0xcb, 0x7e, 0xbe, 0x8f, 0x2d,
  38375. 0x21, 0x84, 0xb9, 0xf2, 0x4e, 0x7b, 0x95, 0x99, 0x11, 0xf3, 0xe1, 0xc0,
  38376. 0x6a, 0x44, 0xae, 0x11, 0xcb, 0x04, 0xa0, 0xf2, 0x3e, 0x17, 0xdf, 0xb2,
  38377. 0x6a, 0xdf, 0x5c, 0xf3, 0x8a, 0xf8, 0x90, 0x86, 0x64, 0xea, 0x0a, 0x32,
  38378. 0x7f, 0x9f, 0x90, 0xa8, 0x9d, 0x33, 0x12, 0xa6, 0xa4, 0xe7, 0x74, 0xa0,
  38379. 0x75, 0xa9, 0x65, 0xf8, 0x39, 0xae, 0x14, 0x32, 0x79, 0xcc, 0xaa, 0x34,
  38380. 0x86, 0x55, 0xcc, 0x99, 0xb7, 0x00, 0x05, 0x8b, 0xe3, 0x76, 0x28, 0x12,
  38381. 0xb6, 0x2a, 0x3e, 0x44, 0x8d, 0xf4, 0xba, 0xef, 0xf6, 0xdc, 0x29, 0x08,
  38382. 0x29, 0x7d, 0xd1, 0x1d, 0x17, 0x15, 0xb6, 0xb6, 0x58, 0x67, 0xd5, 0xd3,
  38383. 0x12, 0x05, 0x4e, 0xb0, 0xc3, 0x83, 0xe0, 0x35, 0x30, 0x60, 0x59, 0xa0,
  38384. 0xc5, 0x97, 0x5b, 0x81, 0xd3, 0x68, 0x6c, 0x8c, 0x17, 0x28, 0xa9, 0x24,
  38385. 0x4f, 0x80, 0x20, 0xa5, 0x21, 0x9f, 0x8f, 0x15, 0x89, 0x2d, 0x87, 0xae,
  38386. 0x2e, 0xcc, 0x73, 0x3e, 0x06, 0x43, 0xbc, 0xb3, 0x1b, 0xa6, 0x72, 0xaa,
  38387. 0xa3, 0xaa, 0xbb, 0x6f, 0x2d, 0x68, 0x60, 0xcf, 0x05, 0x94, 0x25, 0x3e,
  38388. 0x59, 0xf3, 0x64, 0x61, 0x5e, 0x78, 0x9a, 0x7e, 0x0d, 0x50, 0x45, 0x78,
  38389. 0x51, 0xab, 0x11, 0xb1, 0xc6, 0x95, 0xfc, 0x29, 0x28, 0x10, 0x9c, 0x1a,
  38390. 0x8c, 0x37, 0xb5, 0x4f, 0x0e, 0xed, 0x4a, 0x28, 0x6c, 0xaa, 0xb7, 0x0d,
  38391. 0x12, 0xfa, 0x87, 0x5d, 0xd4, 0x9a, 0xb7, 0x2b, 0x46, 0x90, 0x58, 0x4e,
  38392. 0xd7, 0x8b, 0x41, 0x1b, 0xf8, 0xc4, 0xc2, 0xde, 0xda, 0xec, 0x61, 0xe7,
  38393. 0xbf, 0x11, 0xdd, 0x6e, 0x4e, 0x6a, 0xd4, 0x87, 0x01, 0xe4, 0xac, 0xe8,
  38394. 0xaf, 0x2b, 0x01, 0xe1, 0x09, 0x20, 0xe0, 0xbd, 0x7d, 0x03, 0x73, 0x23,
  38395. 0xdf, 0x77, 0x71, 0xa4, 0x25, 0x8b, 0x0a, 0x93, 0x49, 0x32, 0x45, 0x1a,
  38396. 0xa4, 0x94, 0x31, 0x61, 0x2e, 0x17, 0x39, 0x8a, 0x66, 0xc9, 0xf9, 0x20,
  38397. 0x2d, 0x6a, 0x97, 0x2f, 0xe7, 0x26, 0xd8, 0x01, 0x42, 0x65, 0xcf, 0xce,
  38398. 0xd4, 0x24, 0x41, 0xfb, 0x9b, 0x6f, 0xf1, 0xc2, 0x9e, 0xd5, 0x08, 0x0c,
  38399. 0xdc, 0x4d, 0x8e, 0xae, 0xcb, 0x5f, 0xd4, 0xcd, 0x7c, 0xf6, 0x82, 0xc6,
  38400. 0xee, 0xf9, 0x88, 0x3a, 0x34, 0x07, 0x04, 0xb4, 0x84, 0x69, 0xb3, 0xa4,
  38401. 0x67, 0xab, 0x09, 0xc0, 0x83, 0xfe, 0x59, 0xaf, 0x18, 0x2c, 0xc8, 0x09,
  38402. 0xc1, 0xbb, 0x13, 0x7c, 0xce, 0x01, 0x5d, 0x85, 0xaa, 0x10, 0x28, 0xa2,
  38403. 0x96, 0x98, 0x69, 0x23, 0xa3, 0xe7, 0x67, 0xbc, 0x7c, 0x7e, 0xde, 0x4b,
  38404. 0x36, 0xab, 0x94, 0xd2, 0xb8, 0xf9, 0xdf, 0xee, 0xa1, 0x69, 0xa1, 0xc8,
  38405. 0xe9, 0x83, 0x21, 0xac, 0x1b, 0x39, 0xf7, 0x6d, 0xbf, 0x8c, 0xdb, 0xd6,
  38406. 0x2f, 0xc9, 0x3c, 0x3d, 0x50, 0xcf, 0x7f, 0xbe, 0x4a, 0x8d, 0xd8, 0x14,
  38407. 0xad, 0x69, 0xb0, 0x3e, 0x8a, 0xaf, 0xeb, 0xd9, 0x1a, 0x15, 0x4a, 0xe4,
  38408. 0xdd, 0xd9, 0xb2, 0xf8, 0x6b, 0xe2, 0x42, 0x9e, 0x29, 0x16, 0xfc, 0x85,
  38409. 0x9c, 0x47, 0x4b, 0x1f, 0x3d, 0x7b, 0x8c, 0xe1, 0x6d, 0xa3, 0xb8, 0x0a,
  38410. 0xe6, 0xfa, 0x27, 0xfe, 0x52, 0x72, 0xab, 0x3a, 0xa6, 0x58, 0xd7, 0x53,
  38411. 0xaf, 0x9f, 0xee, 0x03, 0x85, 0xfc, 0xa4, 0x7a, 0x72, 0x29, 0x7e, 0x62,
  38412. 0x28, 0x08, 0x79, 0xa8, 0xb8, 0xc7, 0x51, 0x8d, 0xaa, 0x40, 0x2d, 0x4a,
  38413. 0xd9, 0x47, 0xb4, 0xa8, 0xa2, 0x0a, 0x43, 0xd0, 0xe0, 0x4a, 0x39, 0xa3,
  38414. 0x06, 0x08, 0x9a, 0xe2, 0xf3, 0xf2, 0xf8, 0xb9, 0x9f, 0x63, 0x32, 0xa0,
  38415. 0x65, 0x0b, 0xb0, 0x50, 0x96, 0xa6, 0xa8, 0x7a, 0x18, 0xdd, 0x6c, 0xd1,
  38416. 0x9b, 0xd9, 0x4e, 0x76, 0x8f, 0xfb, 0x22, 0xa6, 0x1d, 0x29, 0xfc, 0xb8,
  38417. 0x47, 0x29, 0xb6, 0xd1, 0xb1, 0x63, 0x4a, 0x36, 0x1b, 0x10, 0xe6, 0x4c,
  38418. 0x65, 0x68, 0x1f, 0xad, 0x4f, 0x7d, 0x6b, 0x01, 0x41, 0x18, 0x5f, 0xba,
  38419. 0x3d, 0xa6, 0x54, 0x28, 0x58, 0xd5, 0x81, 0x60, 0xdf, 0x84, 0x76, 0x00,
  38420. 0x21, 0x53, 0xeb, 0xd3, 0xa6, 0xec, 0x7d, 0x3c, 0xb8, 0xcd, 0x91, 0x4c,
  38421. 0x2f, 0x4b, 0x2e, 0x23, 0x4c, 0x0f, 0x0f, 0xe0, 0x14, 0xa5, 0xe7, 0xe5,
  38422. 0x70, 0x8d, 0x8b, 0x9c
  38423. };
  38424. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38425. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_pub_key[] = {
  38426. 0xea, 0x05, 0x24, 0x0d, 0x80, 0x72, 0x25, 0x55, 0xf4, 0x5b,
  38427. 0xc2, 0x13, 0x8b, 0x87, 0x5d, 0x31, 0x99, 0x2f, 0x1d, 0xa9,
  38428. 0x41, 0x09, 0x05, 0x76, 0xa7, 0xb7, 0x5e, 0x8c, 0x44, 0xe2,
  38429. 0x64, 0x79, 0xa0, 0xec, 0x1f, 0x24, 0xb6, 0xc8, 0x05, 0x5b,
  38430. 0xc1, 0x18, 0xb0, 0xb7, 0xcf, 0x8c, 0x60, 0x67, 0x6b, 0x81,
  38431. 0x44, 0x27, 0xb6, 0x0e, 0xfd, 0x9b, 0xc3, 0xcb, 0x52, 0x31,
  38432. 0xfa, 0xc9, 0x34, 0x8d, 0x22, 0x1e, 0x07, 0x9d, 0x96, 0x6a,
  38433. 0x63, 0x83, 0x5c, 0xd7, 0x83, 0x2d, 0x7f, 0x48, 0x64, 0x79,
  38434. 0xca, 0xb4, 0x9f, 0xa2, 0x02, 0xb7, 0x86, 0x1d, 0x0e, 0xc7,
  38435. 0xf9, 0x6c, 0x07, 0xc0, 0x35, 0x6a, 0x34, 0x79, 0x7c, 0xb8,
  38436. 0x0f, 0xed, 0x98, 0x50, 0xfb, 0x51, 0xe0, 0x36, 0x44, 0x4c,
  38437. 0xc6, 0x35, 0xa2, 0xbb, 0x55, 0xb0, 0x5c, 0x39, 0x08, 0x02,
  38438. 0x20, 0x35, 0x5c, 0x56, 0x6d, 0x2e, 0xb9, 0xef, 0x21, 0x26,
  38439. 0x87, 0x87, 0x85, 0x8a, 0x32, 0xb5, 0xa7, 0x68, 0x70, 0x3a,
  38440. 0xfd, 0x0d, 0x21, 0x48, 0x91, 0xa3, 0x29, 0xc1, 0x2a, 0x38,
  38441. 0xe5, 0x26, 0x31, 0x1f, 0x42, 0xde, 0x0b, 0x25, 0xff, 0x1d,
  38442. 0x6b, 0xb4, 0xe0, 0x5d, 0x2d, 0xcf, 0x44, 0xd5, 0x7d, 0xc4,
  38443. 0xf6, 0x95, 0xf2, 0x06, 0x4f, 0x83, 0x88, 0x9d, 0x1e, 0xeb,
  38444. 0x1c, 0x09, 0x45, 0x62, 0x67, 0x3d, 0xff, 0x51, 0x47, 0xe8,
  38445. 0xbc, 0x9b, 0x03, 0x1f, 0xc7, 0x72, 0x65, 0xce, 0xa8, 0x8c,
  38446. 0xc2, 0xa0, 0xc2, 0xbd, 0x5b, 0x7c, 0x17, 0x16, 0x8b, 0x72,
  38447. 0xfa, 0xb1, 0xbd, 0xdf, 0x49, 0xd6, 0xa1, 0x00, 0x65, 0xbe,
  38448. 0x82, 0xe7, 0x68, 0xc7, 0xe7, 0xbc, 0xc2, 0xa4, 0xdb, 0xaa,
  38449. 0xcc, 0xea, 0x41, 0x52, 0x7f, 0x56, 0xb4, 0x68, 0x1f, 0x92,
  38450. 0x96, 0x0f, 0xce, 0xd4, 0xd0, 0x87, 0x4c, 0x4a, 0x73, 0xb5,
  38451. 0x6c, 0xd4, 0x69, 0x55, 0x15, 0x47, 0xdc, 0x94, 0x7f, 0xd2,
  38452. 0x54, 0x5e, 0xb2, 0x90, 0xc2, 0x47, 0xe4, 0xf5, 0xde, 0x8b,
  38453. 0x9b, 0xc6, 0x5d, 0x50, 0x95, 0x60, 0xe0, 0xf0, 0xa7, 0x4e,
  38454. 0xe0, 0xcd, 0x41, 0x09, 0xef, 0xb3, 0x3d, 0x90, 0x5c, 0x77,
  38455. 0x54, 0xec, 0x9e, 0x5d, 0x8a, 0xe7, 0x09, 0x5c, 0xc9, 0x58,
  38456. 0x0c, 0xd0, 0x42, 0x35, 0xd2, 0x14, 0x59, 0x38, 0x69, 0xad,
  38457. 0xf9, 0xb5, 0xbf, 0x8a, 0x8e, 0x33, 0xd8, 0x5e, 0x7a, 0x55,
  38458. 0xd0, 0x53, 0x15, 0x40, 0x4e, 0xc5, 0x86, 0xd7, 0x8f, 0x5f,
  38459. 0x2f, 0x55, 0x82, 0xc2, 0x4f, 0x16, 0xe5, 0xea, 0x1c, 0xbc,
  38460. 0xff, 0x5e, 0x1f, 0x39, 0x46, 0x70, 0x54, 0x7a, 0x3a, 0x27,
  38461. 0x16, 0x1a, 0x2b, 0x6c, 0xd2, 0xb7, 0x80, 0xd3, 0xd1, 0x9d,
  38462. 0x25, 0x59, 0xed, 0xe6, 0x51, 0xb1, 0xf2, 0xad, 0x7e, 0x51,
  38463. 0x78, 0x14, 0x2b, 0x19, 0xae, 0x64, 0x72, 0x0f, 0xd8, 0x18,
  38464. 0x79, 0x8e, 0x66, 0x88, 0xd3, 0xa4, 0xa3, 0xc3, 0x76, 0x21,
  38465. 0xcb, 0xe4, 0x79, 0x5e, 0x95, 0x74, 0xe3, 0x31, 0x18, 0x79,
  38466. 0xed, 0xc7, 0xe7, 0xfb, 0x86, 0x48, 0x1b, 0x7b, 0x75, 0x5b,
  38467. 0x7f, 0x7c, 0x82, 0xc5, 0xab, 0x11, 0xb4, 0x5d, 0x59, 0x6f,
  38468. 0x78, 0xb2, 0xa5, 0x39, 0xc6, 0x63, 0x38, 0x6c, 0xeb, 0x50,
  38469. 0x06, 0x14, 0x76, 0xf0, 0xe8, 0xfb, 0x11, 0x95, 0x1f, 0x9d,
  38470. 0x9c, 0xa6, 0xe1, 0xe2, 0x0d, 0xa3, 0x66, 0xfc, 0x20, 0x83,
  38471. 0x50, 0x0e, 0x53, 0x75, 0xb5, 0x12, 0xf4, 0xdf, 0x31, 0x46,
  38472. 0x83, 0xac, 0x5b, 0xf3, 0x99, 0xa6, 0xd1, 0x7b, 0x2b, 0xc5,
  38473. 0xdc, 0x71, 0x07, 0x27, 0x33, 0x35, 0x34, 0xf5, 0x30, 0x19,
  38474. 0xc1, 0x3b, 0xba, 0x8a, 0xaf, 0x7e, 0x49, 0x93, 0x48, 0x5b,
  38475. 0x38, 0xc0, 0xbc, 0x2e, 0xc7, 0x59, 0x1b, 0xd9, 0xf5, 0xcc,
  38476. 0x86, 0xf5, 0x7b, 0x4d, 0xd7, 0x39, 0xa7, 0xa2, 0x56, 0x20,
  38477. 0x48, 0x98, 0x7d, 0x4f, 0x75, 0x56, 0x9b, 0xb8, 0x95, 0x45,
  38478. 0x17, 0xf3, 0x86, 0x3d, 0x97, 0x0a, 0x49, 0x1b, 0xca, 0xff,
  38479. 0x20, 0xc0, 0x24, 0x2c, 0x51, 0xc2, 0x0a, 0x3c, 0xbf, 0x07,
  38480. 0x60, 0x1c, 0x88, 0x85, 0x9b, 0x85, 0x2d, 0x4a, 0xfe, 0x5a,
  38481. 0x1c, 0x90, 0xf5, 0x90, 0x12, 0xd3, 0x03, 0x3c, 0x8c, 0x2e,
  38482. 0x95, 0x4a, 0x47, 0x76, 0x0f, 0x1f, 0x5d, 0x9e, 0xed, 0xc5,
  38483. 0x64, 0xc4, 0x9b, 0xbf, 0x86, 0xc5, 0x63, 0x84, 0x33, 0x00,
  38484. 0xf1, 0x26, 0x18, 0x21, 0xf3, 0x88, 0x1a, 0x08, 0x18, 0x6d,
  38485. 0x2f, 0xef, 0xd5, 0xeb, 0x2f, 0x69, 0xc8, 0x6e, 0x92, 0x34,
  38486. 0xfc, 0x72, 0x3d, 0x9a, 0xa7, 0x9e, 0x51, 0xfb, 0x56, 0xe3,
  38487. 0xdc, 0xf4, 0x8f, 0x9b, 0x6d, 0x0d, 0x2a, 0xec, 0x66, 0x12,
  38488. 0x26, 0x35, 0xbd, 0x61, 0xc2, 0x67, 0x19, 0xf5, 0x7e, 0xa1,
  38489. 0x67, 0xa2, 0x9c, 0x3b, 0x67, 0xb0, 0xc2, 0x51, 0x6a, 0x37,
  38490. 0x7c, 0x48, 0xe9, 0x4b, 0xb9, 0xa3, 0x38, 0x2f, 0xfc, 0xde,
  38491. 0xb4, 0x7c, 0xda, 0x52, 0x84, 0x0b, 0xb0, 0xd9, 0x08, 0xe9,
  38492. 0x7a, 0x4a, 0x6f, 0x79, 0x29, 0x3d, 0xc4, 0x5c, 0x78, 0xee,
  38493. 0x63, 0xb6, 0x96, 0x68, 0xd9, 0x82, 0x4e, 0xc1, 0x1b, 0x6f,
  38494. 0x52, 0xf5, 0xb3, 0xfb, 0xe8, 0xc4, 0x2a, 0x07, 0xc6, 0x3b,
  38495. 0x85, 0x0d, 0xf4, 0xbf, 0xb0, 0x6b, 0xfb, 0xce, 0x1d, 0xb4,
  38496. 0xbf, 0x63, 0x0b, 0x91, 0x67, 0xc4, 0xa3, 0x06, 0xa4, 0xaf,
  38497. 0x6c, 0xd3, 0xe5, 0x8b, 0x87, 0x4e, 0x64, 0x9c, 0xb1, 0xf3,
  38498. 0x70, 0x7c, 0x68, 0x43, 0x46, 0x13, 0x46, 0xee, 0x27, 0x75,
  38499. 0x12, 0x45, 0x42, 0xde, 0xa5, 0x8d, 0xcf, 0xf7, 0x09, 0x87,
  38500. 0xa8, 0x80, 0x3d, 0xb6, 0x45, 0xee, 0x41, 0x2d, 0x7c, 0x45,
  38501. 0x01, 0x9d, 0xaa, 0x78, 0xa8, 0x10, 0xa4, 0xfd, 0xb5, 0x5f,
  38502. 0xee, 0x0f, 0x77, 0xba, 0x73, 0xff, 0x49, 0xdc, 0xfa, 0x39,
  38503. 0xd6, 0xa3, 0x6f, 0x25, 0xb9, 0x63, 0x2c, 0x92, 0xc5, 0xdf,
  38504. 0xfb, 0xba, 0x89, 0xf9, 0xfa, 0x94, 0x5b, 0x6f, 0x5a, 0x4d,
  38505. 0x1c, 0xe4, 0xc9, 0x10, 0xf9, 0xa0, 0xe8, 0xc4, 0xcb, 0x55,
  38506. 0x1a, 0xdb, 0x56, 0x5f, 0x8e, 0x91, 0x03, 0x23, 0xca, 0xb0,
  38507. 0x1f, 0xef, 0xb8, 0x6c, 0x13, 0x5a, 0x99, 0x25, 0xf0, 0x49,
  38508. 0xa9, 0x5a, 0x45, 0xf7, 0xfd, 0x1a, 0xc2, 0x71, 0x06, 0xe3,
  38509. 0x2d, 0x25, 0x64, 0xb0, 0x52, 0x12, 0x03, 0x62, 0xc7, 0xb6,
  38510. 0xf9, 0xdc, 0x1f, 0x78, 0xff, 0x8b, 0xfa, 0xde, 0x7f, 0x71,
  38511. 0xa6, 0x35, 0x3e, 0xac, 0x20, 0x54, 0x94, 0xa7, 0x2e, 0x9d,
  38512. 0x47, 0x17, 0x4b, 0xad, 0x92, 0xb3, 0x14, 0x26, 0x8c, 0x5a,
  38513. 0xd0, 0x16, 0x4b, 0x22, 0xe9, 0x0c, 0x79, 0x6b, 0x8e, 0xac,
  38514. 0x0d, 0x12, 0xf5, 0x66, 0x8e, 0x82, 0x1a, 0x44, 0xf3, 0xe9,
  38515. 0x56, 0x5a, 0xcd, 0x1c, 0x1b, 0x81, 0x7b, 0x63, 0x59, 0xfe,
  38516. 0xc8, 0xc0, 0xe3, 0xda, 0x16, 0x6b, 0x6f, 0x0d, 0xba, 0x0e,
  38517. 0x47, 0x12, 0x86, 0x9e, 0xf0, 0x3b, 0x4d, 0x87, 0x3b, 0xf2,
  38518. 0x75, 0x73, 0x2d, 0xdf, 0xca, 0x76, 0x0b, 0xbd, 0xe7, 0xb7,
  38519. 0x74, 0x24, 0xf3, 0xc6, 0xe6, 0x75, 0x3f, 0x8b, 0x6a, 0xd9,
  38520. 0xad, 0xed, 0xc0, 0x70, 0x04, 0x1e, 0x0b, 0x8e, 0x8b, 0x7f,
  38521. 0xea, 0xbc, 0x39, 0x6b, 0x8a, 0x44, 0xa6, 0x9a, 0x2d, 0x0d,
  38522. 0x8c, 0x21, 0x60, 0x09, 0xd2, 0x4a, 0xe0, 0x62, 0xcf, 0xfa,
  38523. 0xe8, 0x9b, 0x35, 0x6f, 0x23, 0x2f, 0xb5, 0x65, 0x08, 0x60,
  38524. 0x92, 0x15, 0xd0, 0x5b, 0x63, 0xcc, 0x65, 0x05, 0xd1, 0xef,
  38525. 0x0f, 0x7e, 0x1b, 0xb3, 0x8e, 0xc6, 0x12, 0x85, 0xc9, 0x82,
  38526. 0x53, 0x79, 0x2e, 0x80, 0x5f, 0x0c, 0x7b, 0xc7, 0x1c, 0x83,
  38527. 0x41, 0x06, 0xd8, 0x41, 0xc9, 0xe7, 0xb9, 0x4b, 0xa1, 0x61,
  38528. 0xc6, 0x86, 0x67, 0xf5, 0x10, 0xf7, 0x34, 0x0d, 0x39, 0x9e,
  38529. 0x2b, 0x5f, 0x19, 0x06, 0x02, 0xa5, 0x02, 0x23, 0x71, 0xc2,
  38530. 0x12, 0x65, 0xcc, 0x81, 0x06, 0xfd, 0x8d, 0x09, 0x68, 0x37,
  38531. 0x06, 0x3b, 0xff, 0xc4, 0x24, 0xb3, 0x1f, 0xd6, 0xe6, 0x8f,
  38532. 0x9c, 0x74, 0x2c, 0x5e, 0xc5, 0xf4, 0xe9, 0xeb, 0xca, 0xd3,
  38533. 0x04, 0x5b, 0x92, 0x9e, 0x5c, 0x1a, 0x1d, 0xa1, 0xa7, 0x34,
  38534. 0xd2, 0x05, 0xae, 0xdb, 0x3d, 0x71, 0x10, 0x6e, 0x30, 0xd9,
  38535. 0xa3, 0x44, 0xa0, 0xbd, 0x9e, 0x7b, 0xb5, 0x12, 0x8a, 0x12,
  38536. 0x07, 0x60, 0xd7, 0x1f, 0x92, 0xe6, 0xfe, 0x04, 0xa9, 0x3e,
  38537. 0x62, 0x64, 0x00, 0x5f, 0x7c, 0x7b, 0x34, 0x09, 0xeb, 0x4a,
  38538. 0x18, 0x9e, 0x77, 0x72, 0x3a, 0x31, 0x1a, 0x62, 0x2a, 0xb5,
  38539. 0xcb, 0x4e, 0x53, 0xce, 0xad, 0x8b, 0x5a, 0x20, 0x4f, 0xd7,
  38540. 0x3e, 0x16, 0xf8, 0x10, 0xe2, 0xae, 0xbd, 0x3f, 0x02, 0xa9,
  38541. 0x18, 0xa0, 0x01, 0x18, 0x84, 0x95, 0x22, 0x2e, 0x93, 0x76,
  38542. 0x44, 0x4e, 0x11, 0x7b, 0x03, 0x51, 0x50, 0x19, 0x79, 0xe7,
  38543. 0xbb, 0x5c, 0x7b, 0xca, 0x74, 0xb4, 0x25, 0x26, 0xdb, 0x66,
  38544. 0xaa, 0x0b, 0x21, 0x07, 0xfb, 0x7a, 0x96, 0x10, 0x7d, 0x99,
  38545. 0xa9, 0x16, 0xcb, 0x0e, 0xba, 0x63, 0xab, 0x95, 0xfc, 0x5a,
  38546. 0xbe, 0xa6, 0x7f, 0xd8, 0xb4, 0xcd, 0x7c, 0xc5, 0xd0, 0xb1,
  38547. 0x1b, 0x48, 0x40, 0xfb, 0xe6, 0x2f, 0x2b, 0x94, 0xfe, 0x68,
  38548. 0xa2, 0xc4, 0x36, 0xd9, 0xcd, 0xc1, 0x93, 0x6d, 0xef, 0x39,
  38549. 0x5e, 0x43, 0x30, 0x5a, 0x2e, 0x66, 0xb6, 0xf2, 0xed, 0x9a,
  38550. 0x8d, 0x12, 0xdf, 0x5c, 0xae, 0xad, 0x16, 0x12, 0x7e, 0x81,
  38551. 0x82, 0x91, 0x7d, 0x2b, 0x12, 0xe9, 0x96, 0xb8, 0xb7, 0x42,
  38552. 0xcb, 0x1f, 0xf8, 0xd1, 0xfd, 0x83, 0x7a, 0xe4, 0x36, 0x1d,
  38553. 0x04, 0x27, 0x4c, 0xe5, 0xbd, 0x75, 0x24, 0xf7, 0xbd, 0xb6,
  38554. 0x6a, 0x68, 0x4e, 0x2c, 0x1b, 0x56, 0x3e, 0x60, 0xa4, 0x42,
  38555. 0xca, 0x7a, 0x54, 0xe5, 0x06, 0xe3, 0xda, 0x05, 0xf7, 0x77,
  38556. 0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
  38557. 0xfe, 0x4b
  38558. };
  38559. #endif
  38560. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_sig[] = {
  38561. 0x27, 0x3b, 0x58, 0xa0, 0xcf, 0x00, 0x29, 0x5e, 0x1a, 0x63, 0xbf, 0xb4,
  38562. 0x97, 0x16, 0xa1, 0x9c, 0x78, 0xd1, 0x33, 0xdc, 0x72, 0xde, 0xa3, 0xfc,
  38563. 0xf4, 0x09, 0xb1, 0x09, 0x16, 0x3f, 0x80, 0x72, 0x22, 0x68, 0x65, 0x68,
  38564. 0xb9, 0x80, 0x5a, 0x4a, 0x0d, 0x73, 0x49, 0xe1, 0xc6, 0xde, 0xca, 0x08,
  38565. 0x4f, 0xca, 0xf8, 0xb2, 0xf8, 0x45, 0x3b, 0x6b, 0x8c, 0x6c, 0xfd, 0x3a,
  38566. 0xf4, 0xde, 0xde, 0x82, 0xd8, 0x04, 0xbe, 0x4f, 0x4a, 0xdb, 0x92, 0x47,
  38567. 0x83, 0x2d, 0xc4, 0x55, 0xed, 0x20, 0x4f, 0x71, 0xb1, 0x58, 0xd9, 0x70,
  38568. 0x73, 0xbd, 0xb0, 0x3a, 0xb4, 0x8f, 0xd6, 0x9e, 0x32, 0x98, 0x2b, 0x9e,
  38569. 0xff, 0x2a, 0x7c, 0xcb, 0x05, 0x1b, 0x8e, 0xe6, 0x3a, 0x45, 0xc6, 0x7a,
  38570. 0xc8, 0xaf, 0x62, 0xd3, 0x04, 0xfa, 0x69, 0x4f, 0xda, 0x1b, 0x74, 0x16,
  38571. 0x0d, 0xb3, 0x1a, 0xee, 0x71, 0xd7, 0xb0, 0xef, 0x69, 0xf5, 0xe2, 0xe9,
  38572. 0xc2, 0xcc, 0x15, 0x66, 0x28, 0x0a, 0xac, 0xe2, 0x63, 0x06, 0xb7, 0x21,
  38573. 0x0d, 0xd8, 0x5c, 0x94, 0x63, 0xfd, 0x51, 0x18, 0x9f, 0x07, 0x19, 0x3d,
  38574. 0xa2, 0x50, 0x40, 0xd3, 0xe9, 0x05, 0xd4, 0x11, 0x13, 0x15, 0xaa, 0x46,
  38575. 0xda, 0x3e, 0x5f, 0xcd, 0x3c, 0xfa, 0x42, 0xba, 0x79, 0x4a, 0xb7, 0x43,
  38576. 0x91, 0xa5, 0xcb, 0xbc, 0xeb, 0x37, 0x94, 0xf1, 0x9c, 0xb9, 0xdb, 0x41,
  38577. 0x06, 0xd8, 0x7b, 0x5e, 0x90, 0xe3, 0x3c, 0x8a, 0x10, 0x62, 0x9a, 0x15,
  38578. 0x27, 0x78, 0xed, 0x69, 0x11, 0x2c, 0xb5, 0xb4, 0xdb, 0xc8, 0x70, 0x50,
  38579. 0x62, 0x47, 0x96, 0xcb, 0xd9, 0xb2, 0x3e, 0x59, 0x2f, 0x1c, 0xac, 0xcb,
  38580. 0xcf, 0x22, 0xc2, 0x9b, 0xc7, 0x92, 0xe9, 0x4d, 0x8d, 0x5d, 0xcf, 0x06,
  38581. 0x53, 0x7e, 0xf4, 0x4e, 0xfe, 0x9e, 0x41, 0x5d, 0x00, 0x8c, 0x08, 0xf4,
  38582. 0x02, 0x79, 0x33, 0x1c, 0x27, 0x1d, 0xe3, 0x94, 0xac, 0xe6, 0x87, 0xa0,
  38583. 0x08, 0xb4, 0x60, 0x0c, 0xff, 0x47, 0xdc, 0x16, 0x3a, 0x1d, 0x89, 0xc0,
  38584. 0x6a, 0xa4, 0x3d, 0x71, 0x33, 0xdd, 0x1e, 0x70, 0xfe, 0xd4, 0x8b, 0xed,
  38585. 0x7c, 0x91, 0xe4, 0xe2, 0x15, 0x06, 0xc1, 0x83, 0x24, 0x55, 0xa7, 0x2a,
  38586. 0x9f, 0x4e, 0xd9, 0x56, 0x7a, 0x95, 0xa8, 0xdd, 0xc4, 0xf0, 0x71, 0x3a,
  38587. 0x99, 0x65, 0x31, 0x4b, 0xb7, 0x96, 0x2c, 0x53, 0x54, 0x83, 0xec, 0xc9,
  38588. 0x97, 0x2f, 0x0c, 0xa4, 0x8f, 0xbb, 0x93, 0x9d, 0xea, 0xae, 0xf9, 0xcb,
  38589. 0xb2, 0xb9, 0xa3, 0x61, 0x5f, 0x77, 0x8c, 0xb6, 0x5a, 0x56, 0xbe, 0x5f,
  38590. 0x85, 0xd1, 0xb5, 0x0a, 0x53, 0xe2, 0xc7, 0xbf, 0x76, 0x8b, 0x97, 0x6f,
  38591. 0x10, 0xdd, 0x1f, 0x44, 0x69, 0x66, 0x03, 0xc4, 0x6b, 0x59, 0xf7, 0xb4,
  38592. 0xc1, 0x12, 0xcc, 0x00, 0x70, 0xe8, 0xbd, 0x44, 0x28, 0xf5, 0xfa, 0x96,
  38593. 0xf3, 0x59, 0xed, 0x81, 0x67, 0xe0, 0xbe, 0x47, 0x75, 0xb3, 0xa8, 0x9f,
  38594. 0x21, 0x70, 0x2e, 0x6f, 0xef, 0x54, 0x11, 0x3f, 0x34, 0xaf, 0x0d, 0x73,
  38595. 0x5b, 0x9e, 0x6d, 0x86, 0x58, 0xb7, 0x34, 0xc2, 0xc2, 0xb3, 0x64, 0xd5,
  38596. 0x9b, 0x6e, 0xb9, 0x99, 0x6a, 0xe4, 0xfd, 0xc3, 0x17, 0xf3, 0x10, 0xfc,
  38597. 0x6e, 0xf5, 0x65, 0xe1, 0x9c, 0x59, 0x15, 0x11, 0x00, 0xea, 0x96, 0x81,
  38598. 0x69, 0x9b, 0x05, 0x4d, 0xf3, 0xce, 0xf3, 0xf0, 0xa9, 0x01, 0x3f, 0x13,
  38599. 0xbb, 0xb0, 0xac, 0xc3, 0x92, 0x1c, 0x2b, 0x61, 0xe3, 0x01, 0x22, 0x45,
  38600. 0x4a, 0x23, 0x19, 0x80, 0xca, 0xb9, 0xef, 0x4e, 0x76, 0x52, 0xc5, 0x9d,
  38601. 0x91, 0x33, 0x17, 0xc4, 0x28, 0x83, 0x55, 0x61, 0x49, 0x72, 0x04, 0xaa,
  38602. 0xf8, 0xe3, 0x4b, 0x20, 0xf7, 0x6a, 0x74, 0x56, 0x64, 0xf9, 0xb3, 0xc9,
  38603. 0x67, 0x5b, 0x55, 0x29, 0x9a, 0x89, 0xa5, 0x14, 0x67, 0xea, 0x6d, 0x6a,
  38604. 0xde, 0x98, 0x58, 0x73, 0x25, 0xa3, 0xdb, 0xed, 0x3d, 0x62, 0xaa, 0xe0,
  38605. 0x79, 0x7f, 0xa3, 0xd9, 0xb5, 0x4c, 0xe9, 0xa8, 0xdf, 0xfd, 0x59, 0x31,
  38606. 0x42, 0x81, 0x9e, 0xb7, 0x81, 0x3f, 0x0e, 0xfb, 0xef, 0x80, 0x71, 0x9d,
  38607. 0xb7, 0xa5, 0xfc, 0xb1, 0x80, 0xc9, 0x7e, 0x31, 0xd9, 0x47, 0xe2, 0xca,
  38608. 0x10, 0x7b, 0xd1, 0xa1, 0x1c, 0x28, 0xc7, 0x7f, 0x51, 0x26, 0xb1, 0x4e,
  38609. 0x57, 0xdd, 0x7d, 0x76, 0x5c, 0x5a, 0x85, 0xa7, 0x7b, 0x8c, 0xc5, 0x6e,
  38610. 0xac, 0x20, 0xf8, 0x49, 0x16, 0xd6, 0x64, 0xf5, 0xf4, 0x2c, 0x32, 0xa1,
  38611. 0x5d, 0xfb, 0x87, 0xb6, 0x14, 0xfe, 0x68, 0x7c, 0x4d, 0xce, 0xd7, 0x94,
  38612. 0xf9, 0x8b, 0xf0, 0x61, 0xfd, 0xe0, 0x83, 0x7f, 0x13, 0xec, 0x7a, 0xb7,
  38613. 0x41, 0x04, 0x51, 0x6e, 0x30, 0xa2, 0x01, 0xf7, 0x30, 0x12, 0xec, 0xd2,
  38614. 0x8f, 0x73, 0xe7, 0x8e, 0x12, 0xb4, 0xe5, 0xc1, 0xff, 0xdf, 0x67, 0x14,
  38615. 0xb1, 0xe9, 0xba, 0x36, 0x19, 0x18, 0xf4, 0xaa, 0xe0, 0xe4, 0x9d, 0xcd,
  38616. 0xe8, 0xe7, 0x2b, 0x33, 0xb3, 0xdc, 0xb9, 0x19, 0xd7, 0xad, 0xa4, 0x68,
  38617. 0xcd, 0x83, 0x77, 0x98, 0x36, 0x49, 0xd9, 0x32, 0x20, 0xfd, 0xfc, 0x34,
  38618. 0xe7, 0x54, 0xd9, 0xb5, 0x05, 0xab, 0x0e, 0x08, 0x0e, 0x16, 0x8a, 0x7d,
  38619. 0x91, 0x4c, 0xaa, 0x19, 0x04, 0x37, 0x35, 0xa5, 0xab, 0x6c, 0xee, 0xc4,
  38620. 0x90, 0xf0, 0x5f, 0xc7, 0xae, 0x82, 0xfd, 0x59, 0x53, 0xe5, 0x36, 0x5a,
  38621. 0x56, 0x37, 0x61, 0x69, 0xda, 0xe5, 0x8f, 0xfd, 0x2e, 0xd4, 0x9c, 0x7f,
  38622. 0xb6, 0x39, 0xa4, 0x8d, 0x0a, 0xab, 0x82, 0x0f, 0xfe, 0x84, 0x69, 0x44,
  38623. 0x8a, 0xa6, 0xd0, 0x39, 0xf9, 0x72, 0x68, 0xe7, 0x97, 0xd8, 0x6c, 0x7b,
  38624. 0xec, 0x85, 0x8c, 0x52, 0xc9, 0x97, 0xbb, 0xc4, 0x7a, 0x67, 0x22, 0x60,
  38625. 0x46, 0x9f, 0x16, 0xf1, 0x67, 0x0e, 0x1b, 0x50, 0x7c, 0xc4, 0x29, 0x15,
  38626. 0xbc, 0x55, 0x6a, 0x67, 0xf6, 0xa8, 0x85, 0x66, 0x89, 0x9f, 0xff, 0x38,
  38627. 0x28, 0xaa, 0x87, 0x91, 0xce, 0xde, 0x8d, 0x45, 0x5c, 0xa1, 0x25, 0x95,
  38628. 0xe2, 0x86, 0xdd, 0xa1, 0x87, 0x6a, 0x0a, 0xa8, 0x3e, 0x63, 0x0e, 0x21,
  38629. 0xa5, 0x6e, 0x08, 0x4d, 0x07, 0xb6, 0x26, 0xa8, 0x92, 0xdb, 0xed, 0x13,
  38630. 0x01, 0xc3, 0xba, 0xcf, 0xad, 0x01, 0xbc, 0xe5, 0xc0, 0xba, 0xbe, 0x7c,
  38631. 0x75, 0xf1, 0xb9, 0xfe, 0xd3, 0xf0, 0xa5, 0x2c, 0x8e, 0x10, 0xff, 0x99,
  38632. 0xcb, 0xe2, 0x2d, 0xdc, 0x2f, 0x76, 0x00, 0xf8, 0x51, 0x7c, 0xcc, 0x52,
  38633. 0x16, 0x0f, 0x18, 0x98, 0xea, 0x34, 0x06, 0x7f, 0xb7, 0x2e, 0xe9, 0x40,
  38634. 0xf0, 0x2d, 0x30, 0x3d, 0xc0, 0x67, 0x4c, 0xe6, 0x63, 0x40, 0x41, 0x42,
  38635. 0x96, 0xbb, 0x0b, 0xd6, 0xc9, 0x1c, 0x22, 0x7a, 0xa9, 0x4d, 0xcc, 0x5b,
  38636. 0xaa, 0x03, 0xc6, 0x3b, 0x1e, 0x2f, 0x11, 0xae, 0x34, 0x6f, 0x0c, 0xe9,
  38637. 0x16, 0x9c, 0x82, 0x3b, 0x90, 0x4c, 0x0e, 0xf0, 0xf9, 0x7f, 0x02, 0xca,
  38638. 0xb9, 0xa9, 0x49, 0x6d, 0x27, 0x73, 0xd0, 0xbf, 0x15, 0x61, 0x52, 0xbc,
  38639. 0xd6, 0x31, 0x59, 0x2b, 0x52, 0x5b, 0xaf, 0x3c, 0xc0, 0x8f, 0xdc, 0xd5,
  38640. 0x2c, 0x1d, 0xe4, 0xe9, 0x41, 0xe8, 0xd3, 0x35, 0xd6, 0xb1, 0xf3, 0x32,
  38641. 0xe0, 0x52, 0x08, 0x73, 0x99, 0xb6, 0x6b, 0xbc, 0x26, 0xfb, 0x2e, 0xa7,
  38642. 0xb7, 0xcd, 0x14, 0xf0, 0xf9, 0xe5, 0x3a, 0xd0, 0x05, 0x5b, 0x2b, 0x38,
  38643. 0xbd, 0x7c, 0xda, 0xd4, 0x15, 0x45, 0xfa, 0x3b, 0x6f, 0x94, 0x8e, 0x22,
  38644. 0xce, 0xfa, 0x53, 0xe0, 0x5f, 0xa6, 0x9d, 0x1c, 0x26, 0x91, 0x8a, 0xab,
  38645. 0x72, 0x5b, 0x18, 0x78, 0x69, 0x98, 0x3f, 0x8d, 0x33, 0x7c, 0x21, 0x93,
  38646. 0x9e, 0xf0, 0xaf, 0xb7, 0x30, 0xc8, 0xac, 0xbc, 0xdb, 0x9c, 0x29, 0x17,
  38647. 0x6b, 0x9d, 0x0f, 0x16, 0xd6, 0xc0, 0xcc, 0x3b, 0xce, 0x11, 0xe9, 0x64,
  38648. 0xc8, 0xd4, 0x4c, 0x98, 0x7c, 0x8f, 0xf1, 0x5e, 0x84, 0xe4, 0x72, 0xf9,
  38649. 0x69, 0xf5, 0x9d, 0xad, 0x95, 0x3b, 0xfb, 0x6d, 0x30, 0x7e, 0x0a, 0x47,
  38650. 0x5b, 0x26, 0xb2, 0x4e, 0xeb, 0x1a, 0xc3, 0x37, 0x16, 0x28, 0x79, 0x62,
  38651. 0xb4, 0x36, 0x85, 0x4a, 0x15, 0x5a, 0xc3, 0x6e, 0xbe, 0x7e, 0x00, 0xe9,
  38652. 0x4a, 0xa5, 0xd7, 0x90, 0xcf, 0x59, 0x63, 0x2d, 0x2b, 0xc2, 0xc6, 0x47,
  38653. 0xe6, 0x77, 0xb7, 0x6e, 0x9b, 0xc8, 0x0d, 0x18, 0x2b, 0x45, 0x2b, 0xc9,
  38654. 0x5a, 0x6e, 0xb4, 0x50, 0xa5, 0x23, 0x7d, 0x17, 0xcc, 0x49, 0xe2, 0xb3,
  38655. 0xf4, 0x6d, 0xb4, 0xb7, 0xbb, 0x9e, 0xdd, 0x20, 0x99, 0x19, 0xf5, 0x53,
  38656. 0x1f, 0xd0, 0xff, 0x67, 0xf3, 0x8e, 0x6a, 0xcd, 0x2a, 0x6e, 0x2b, 0x0a,
  38657. 0x90, 0xd7, 0xdb, 0xe1, 0xff, 0x1c, 0x40, 0xa1, 0xb0, 0x5d, 0x94, 0x4d,
  38658. 0x20, 0x14, 0x01, 0xa1, 0xa8, 0xd1, 0x15, 0xd2, 0xd9, 0x1b, 0xbf, 0xc2,
  38659. 0x8a, 0xd0, 0x02, 0xf6, 0x16, 0xa1, 0xb7, 0x40, 0xe0, 0x36, 0x88, 0xc8,
  38660. 0x17, 0x0a, 0xf0, 0xb6, 0x0d, 0x3c, 0x53, 0xb9, 0x51, 0xed, 0xef, 0x20,
  38661. 0x6f, 0xf3, 0x0c, 0xb5, 0xce, 0x0e, 0x9e, 0xfd, 0x0f, 0x5e, 0x3f, 0x8f,
  38662. 0x3c, 0xb7, 0x2a, 0xdb, 0xc6, 0xa7, 0xf2, 0x11, 0x6e, 0xdc, 0x05, 0x33,
  38663. 0xd4, 0xd8, 0xb0, 0x2d, 0x8a, 0xe5, 0x39, 0x82, 0x00, 0x49, 0x7d, 0xfd,
  38664. 0x32, 0x29, 0xbb, 0x79, 0x5d, 0xcb, 0x21, 0x7b, 0x2d, 0x36, 0x58, 0x73,
  38665. 0x52, 0x57, 0x52, 0x96, 0x4d, 0x89, 0x61, 0xf4, 0xad, 0x1f, 0x48, 0xd5,
  38666. 0x7a, 0x4a, 0xaa, 0x1c, 0xa1, 0xf4, 0xb4, 0x9c, 0x43, 0x3b, 0x95, 0x72,
  38667. 0xd0, 0x0e, 0x35, 0x82, 0x26, 0xd4, 0x2e, 0xe3, 0x83, 0x96, 0x97, 0x5a,
  38668. 0x7b, 0xfc, 0x48, 0x17, 0x3c, 0xba, 0x9e, 0x5f, 0x46, 0x1a, 0x53, 0xe3,
  38669. 0x2e, 0x78, 0x79, 0x80, 0xf6, 0x2d, 0x24, 0xcf, 0x62, 0xb6, 0x86, 0xeb,
  38670. 0xee, 0xec, 0xf2, 0x1d, 0x00, 0xc8, 0x28, 0x9d, 0x93, 0x16, 0xa7, 0xd9,
  38671. 0x11, 0x47, 0xe3, 0xc4, 0xb6, 0xc4, 0xa0, 0x99, 0x83, 0xc1, 0x17, 0xd8,
  38672. 0x8e, 0xde, 0x69, 0x1d, 0xcb, 0xdd, 0xe7, 0x86, 0x6f, 0xf2, 0x36, 0x07,
  38673. 0x23, 0x86, 0x0d, 0xe9, 0xad, 0x87, 0xae, 0x76, 0x98, 0x95, 0x51, 0xf2,
  38674. 0xb3, 0x11, 0xc5, 0x34, 0xf0, 0x0c, 0xf8, 0x29, 0x9c, 0x84, 0x4f, 0x81,
  38675. 0x49, 0x85, 0x63, 0x25, 0x16, 0xb0, 0xc3, 0xaa, 0xd7, 0x8a, 0x2e, 0x4b,
  38676. 0x97, 0x60, 0x74, 0xf8, 0xa7, 0x39, 0xec, 0x6c, 0x2c, 0x9b, 0x33, 0x3a,
  38677. 0x11, 0xbd, 0xa6, 0x90, 0x48, 0x65, 0xb1, 0xe7, 0x38, 0x53, 0x47, 0x1b,
  38678. 0x62, 0xd5, 0xb7, 0xa8, 0xd4, 0xae, 0xf5, 0x12, 0x06, 0x12, 0x54, 0xa2,
  38679. 0xce, 0xf1, 0x6b, 0x3a, 0xda, 0x63, 0x2e, 0x37, 0x2a, 0x25, 0x89, 0x30,
  38680. 0x98, 0x77, 0x1d, 0x4b, 0x5a, 0x1e, 0xb7, 0x3d, 0xed, 0x19, 0xec, 0x9f,
  38681. 0x64, 0x46, 0xa8, 0x2a, 0x79, 0xf3, 0x70, 0x39, 0x9f, 0x8c, 0xc3, 0x28,
  38682. 0xcc, 0x2a, 0xc0, 0xd0, 0xe6, 0x80, 0xf5, 0x01, 0x78, 0x72, 0x7f, 0xe7,
  38683. 0x2e, 0x7b, 0x5f, 0x05, 0xc3, 0x41, 0x33, 0x07, 0xdb, 0x9c, 0xa8, 0x96,
  38684. 0xa7, 0x21, 0x20, 0x23, 0xd0, 0x59, 0x39, 0x06, 0x19, 0xa4, 0x29, 0xe5,
  38685. 0x72, 0x39, 0x69, 0x23, 0xe3, 0xfa, 0x28, 0x63, 0xf5, 0x42, 0x3b, 0xca,
  38686. 0x88, 0x5d, 0x7e, 0x47, 0x93, 0xa8, 0x8c, 0x75, 0xf2, 0x19, 0x44, 0x43,
  38687. 0x15, 0x39, 0x03, 0x42, 0xd8, 0x1d, 0x81, 0x30, 0x8e, 0x84, 0x31, 0x24,
  38688. 0x75, 0x67, 0x4e, 0xbe, 0xfe, 0x0a, 0xd8, 0xc3, 0xe7, 0x5b, 0xe1, 0xd5,
  38689. 0x12, 0x6a, 0x69, 0x99, 0xcd, 0x35, 0xca, 0x22, 0x02, 0x65, 0xb3, 0x0f,
  38690. 0x50, 0xb6, 0xaa, 0xc6, 0x91, 0x5c, 0x4d, 0xd4, 0x07, 0x93, 0x46, 0xf0,
  38691. 0xcc, 0xe1, 0x92, 0x14, 0x91, 0x21, 0x43, 0xc4, 0xba, 0x45, 0x1c, 0x47,
  38692. 0x29, 0xdf, 0xff, 0x89, 0x60, 0xee, 0x89, 0x1e, 0xc3, 0xb4, 0xb9, 0x0b,
  38693. 0xc9, 0x7e, 0xd9, 0x15, 0xb0, 0x80, 0x91, 0xbe, 0xb9, 0x43, 0x48, 0x12,
  38694. 0x86, 0x8e, 0x79, 0x38, 0x4d, 0xce, 0x36, 0x7f, 0xc3, 0xe8, 0xb7, 0xb9,
  38695. 0x92, 0xbf, 0x27, 0x20, 0x54, 0xc8, 0x05, 0x63, 0x3b, 0xf5, 0x48, 0x1a,
  38696. 0xa9, 0x04, 0x6c, 0xb6, 0x0e, 0x11, 0xea, 0xf3, 0x59, 0xb9, 0xa6, 0xf6,
  38697. 0xf8, 0x0b, 0x15, 0xed, 0x30, 0xf9, 0xe4, 0xe5, 0x26, 0x2d, 0xbb, 0xc6,
  38698. 0x5b, 0x36, 0xbb, 0x73, 0xa6, 0x4f, 0xf5, 0x43, 0x9f, 0xd7, 0xb9, 0x0f,
  38699. 0xbc, 0x4f, 0x8d, 0xb8, 0xec, 0x1d, 0x42, 0x19, 0x56, 0x37, 0xc4, 0xcb,
  38700. 0xd0, 0x16, 0x85, 0xff, 0xd3, 0x9b, 0xef, 0xc8, 0x75, 0x37, 0xd1, 0x92,
  38701. 0xad, 0x21, 0x94, 0x1e, 0x9a, 0xf6, 0x2f, 0x6d, 0x30, 0xba, 0x37, 0xc3,
  38702. 0xdc, 0x11, 0xe0, 0x79, 0xa4, 0x92, 0x1f, 0xe4, 0xaa, 0x7a, 0x6b, 0x2a,
  38703. 0xe4, 0x04, 0xb7, 0xf9, 0x86, 0x95, 0xdb, 0xa8, 0xfc, 0x8a, 0x53, 0x21,
  38704. 0x31, 0x14, 0xf7, 0x40, 0x01, 0x78, 0x4e, 0x73, 0x18, 0xb3, 0x54, 0xd7,
  38705. 0xa6, 0x93, 0xf0, 0x70, 0x04, 0x1c, 0xe0, 0x2b, 0xef, 0xee, 0xd4, 0x64,
  38706. 0xa7, 0xd9, 0x9f, 0x81, 0x4f, 0xe5, 0x1e, 0xbe, 0x6e, 0xd2, 0xf6, 0x3a,
  38707. 0xba, 0xcf, 0x8c, 0x96, 0x2a, 0x3d, 0xf7, 0xe5, 0x5c, 0x59, 0x40, 0x9c,
  38708. 0xe3, 0xf9, 0x2b, 0x6d, 0x3d, 0xf2, 0x6f, 0x81, 0xd6, 0xab, 0x9c, 0xab,
  38709. 0xc6, 0xf7, 0x8f, 0xaa, 0xe5, 0x71, 0xe3, 0xc9, 0x8c, 0x1a, 0xeb, 0xc5,
  38710. 0x87, 0xe7, 0xb0, 0xde, 0x18, 0xba, 0xaa, 0x1e, 0xda, 0x12, 0x32, 0x16,
  38711. 0x94, 0x3a, 0x6e, 0x4f, 0x84, 0x06, 0x8e, 0x33, 0xf7, 0xfa, 0x35, 0xb8,
  38712. 0x45, 0xe4, 0x5e, 0x9e, 0x46, 0x05, 0x7a, 0xf7, 0xf4, 0x99, 0xad, 0xb9,
  38713. 0xdd, 0x55, 0xd9, 0x52, 0x3b, 0x93, 0xe3, 0x9b, 0x54, 0x1b, 0xe6, 0xa9,
  38714. 0x70, 0xd3, 0x48, 0xf9, 0x3d, 0xdb, 0x88, 0x63, 0x66, 0xa0, 0xab, 0x72,
  38715. 0x83, 0x6e, 0x8f, 0x78, 0x9d, 0x55, 0x46, 0x21, 0xca, 0x7c, 0xb7, 0x5d,
  38716. 0x16, 0xe8, 0x66, 0x3b, 0x7b, 0xaa, 0xfe, 0x9c, 0x9c, 0x33, 0xc9, 0xc2,
  38717. 0xa4, 0x3c, 0x78, 0x97, 0xf3, 0x5b, 0xc2, 0x29, 0x36, 0x98, 0x68, 0x28,
  38718. 0xfe, 0x0a, 0xae, 0x6f, 0xe5, 0xf7, 0xfb, 0x9d, 0xf8, 0x8c, 0xd9, 0xd0,
  38719. 0x4d, 0xfe, 0xc7, 0xd0, 0xb0, 0xe3, 0x9c, 0xdb, 0xac, 0x9e, 0x1b, 0x55,
  38720. 0x7e, 0x24, 0xfe, 0xc4, 0x12, 0xcb, 0xc2, 0xdd, 0x0a, 0xda, 0x31, 0x40,
  38721. 0x41, 0xb7, 0xfc, 0x3f, 0x6d, 0xe2, 0xd3, 0x8a, 0x0f, 0x21, 0x33, 0x3a,
  38722. 0xbc, 0xa7, 0x62, 0x18, 0xb3, 0xaf, 0x48, 0xc6, 0xe2, 0xa3, 0xdd, 0x1d,
  38723. 0x20, 0x62, 0xe4, 0x4b, 0x81, 0x6b, 0x3a, 0xc5, 0xb1, 0x07, 0xe1, 0xf1,
  38724. 0xe1, 0xba, 0xf6, 0x01, 0xc6, 0xf2, 0xea, 0xc0, 0x97, 0x73, 0x79, 0x19,
  38725. 0x06, 0xaa, 0x62, 0x42, 0xcb, 0x21, 0x5f, 0x08, 0x97, 0x7d, 0x72, 0xb5,
  38726. 0x39, 0x4d, 0x99, 0xe3, 0xa2, 0x3f, 0xb9, 0xb4, 0xed, 0xf4, 0x61, 0x35,
  38727. 0xe1, 0x50, 0xfb, 0x56, 0x7c, 0x35, 0xfd, 0x44, 0x8a, 0x57, 0x22, 0xed,
  38728. 0x30, 0x33, 0xc3, 0x0b, 0xf1, 0x88, 0xe4, 0x44, 0x46, 0xf5, 0x73, 0x6d,
  38729. 0x9b, 0x98, 0x88, 0x92, 0xf5, 0x34, 0x85, 0x18, 0x66, 0xef, 0x70, 0xbe,
  38730. 0x7b, 0xc1, 0x0f, 0x1c, 0x78, 0x2d, 0x42, 0x13, 0x2d, 0x2f, 0x4d, 0x40,
  38731. 0x8e, 0xe2, 0x6f, 0xe0, 0x04, 0xdb, 0x58, 0xbc, 0x65, 0x80, 0xba, 0xfc,
  38732. 0x89, 0xee, 0xf3, 0x78, 0xb2, 0xd9, 0x78, 0x93, 0x6d, 0xbf, 0xd4, 0x74,
  38733. 0x24, 0xf4, 0x5c, 0x37, 0x89, 0x0c, 0x14, 0xd5, 0xbd, 0xc5, 0xfc, 0x37,
  38734. 0xe8, 0x8b, 0xe0, 0xc5, 0x89, 0xc9, 0x70, 0xb3, 0x76, 0x46, 0xce, 0x0d,
  38735. 0x7c, 0x3d, 0xa4, 0x5d, 0x02, 0x95, 0x03, 0xba, 0x24, 0xaa, 0xf7, 0xd0,
  38736. 0x75, 0x35, 0x78, 0x27, 0x9c, 0x6d, 0x2a, 0xef, 0xaa, 0xac, 0x85, 0xef,
  38737. 0x8d, 0xfc, 0xc0, 0xfc, 0x72, 0x02, 0xf4, 0xa3, 0xd3, 0x87, 0xfc, 0x4d,
  38738. 0xce, 0x3d, 0xcb, 0xc2, 0x74, 0x5b, 0xb0, 0x83, 0xc5, 0x72, 0x72, 0xd6,
  38739. 0xa1, 0x67, 0x4d, 0xa1, 0xd6, 0xaa, 0xe7, 0x9b, 0xe7, 0xc0, 0xfd, 0x86,
  38740. 0x91, 0x08, 0xfa, 0x48, 0x2f, 0x50, 0xce, 0x17, 0xea, 0x1c, 0xe3, 0x90,
  38741. 0x35, 0xe6, 0x6c, 0xc9, 0x66, 0x7d, 0x51, 0x32, 0x20, 0x0c, 0x2d, 0x4b,
  38742. 0xa1, 0xbf, 0x78, 0x87, 0xe1, 0x5a, 0x28, 0x0e, 0x9a, 0x85, 0xf6, 0x7e,
  38743. 0x39, 0x60, 0xbc, 0x64, 0x42, 0x5d, 0xf0, 0x0a, 0xd7, 0x3e, 0xbb, 0xa0,
  38744. 0x6d, 0x7c, 0xfa, 0x75, 0xee, 0x34, 0x39, 0x23, 0x0e, 0xbd, 0x50, 0x19,
  38745. 0x7a, 0x2a, 0xb7, 0x17, 0x3a, 0x8b, 0xb7, 0xb6, 0xf4, 0xd8, 0x47, 0x71,
  38746. 0x6b, 0x21, 0x1b, 0x56, 0xcc, 0xfb, 0x7b, 0x81, 0x99, 0x46, 0x88, 0x23,
  38747. 0x40, 0x49, 0x66, 0x8b, 0xac, 0x84, 0x16, 0x8a, 0x86, 0xae, 0x38, 0xc4,
  38748. 0x5b, 0x1f, 0x2b, 0xfa, 0xf2, 0x8b, 0x81, 0xc1, 0x22, 0x61, 0x61, 0x6c,
  38749. 0x43, 0x16, 0x8c, 0x1d, 0x37, 0xb2, 0xaf, 0x3c, 0x3a, 0x90, 0x33, 0xed,
  38750. 0xf5, 0x08, 0x78, 0xfd, 0x5a, 0xde, 0xd3, 0x38, 0x6d, 0xd7, 0x1c, 0x23,
  38751. 0xeb, 0xb4, 0x9b, 0x8e, 0xc2, 0x48, 0x47, 0x8e, 0x84, 0xbb, 0xc4, 0xd0,
  38752. 0xcc, 0xf9, 0x55, 0x5a, 0x57, 0xb9, 0x99, 0x52, 0x82, 0x21, 0x3b, 0x83,
  38753. 0xda, 0x8f, 0xa3, 0x88, 0x9c, 0x57, 0xe0, 0x4b, 0xc1, 0xce, 0xbe, 0xd3,
  38754. 0xea, 0xdd, 0xf2, 0x07, 0xc1, 0x73, 0x6f, 0xc0, 0x5e, 0x8e, 0x85, 0x72,
  38755. 0xab, 0x2f, 0xa9, 0xac, 0x39, 0xee, 0x05, 0x34, 0x13, 0x16, 0x1b, 0x1c,
  38756. 0x21, 0x24, 0x41, 0x49, 0x78, 0x87, 0x8b, 0x97, 0x9c, 0x9f, 0xa3, 0xa8,
  38757. 0xb9, 0xbc, 0xc6, 0xcc, 0xf2, 0xfd, 0x18, 0x2a, 0x46, 0x58, 0x5a, 0x88,
  38758. 0xa2, 0xb5, 0xcc, 0xd2, 0xda, 0xe1, 0xe3, 0x0d, 0x20, 0x23, 0x2b, 0x2f,
  38759. 0x47, 0x57, 0x5e, 0x64, 0x87, 0x97, 0x9c, 0xa7, 0xaa, 0xbc, 0xc1, 0xe4,
  38760. 0xe5, 0xea, 0x0b, 0x16, 0x3b, 0x3c, 0x3e, 0x45, 0x58, 0x63, 0x6a, 0x6f,
  38761. 0x7c, 0x8c, 0x8d, 0x92, 0x99, 0x9c, 0xad, 0xb5, 0xb7, 0xce, 0x00, 0x00,
  38762. 0x00, 0x00, 0x00, 0x00, 0x16, 0x23, 0x36, 0x4a
  38763. };
  38764. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  38765. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_44_draft_sig[] = {
  38766. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  38767. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  38768. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  38769. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  38770. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  38771. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  38772. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  38773. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  38774. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  38775. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  38776. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  38777. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  38778. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  38779. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  38780. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  38781. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  38782. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  38783. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  38784. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  38785. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  38786. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  38787. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  38788. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  38789. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  38790. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  38791. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  38792. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  38793. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  38794. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  38795. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  38796. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  38797. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  38798. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  38799. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  38800. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  38801. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  38802. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  38803. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  38804. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  38805. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  38806. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  38807. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  38808. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  38809. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  38810. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  38811. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  38812. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  38813. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  38814. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  38815. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  38816. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  38817. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  38818. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  38819. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  38820. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  38821. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  38822. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  38823. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  38824. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  38825. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  38826. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  38827. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  38828. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  38829. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  38830. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  38831. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  38832. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  38833. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  38834. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  38835. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  38836. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  38837. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  38838. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  38839. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  38840. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  38841. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  38842. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  38843. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  38844. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  38845. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  38846. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  38847. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  38848. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  38849. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  38850. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  38851. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  38852. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  38853. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  38854. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  38855. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  38856. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  38857. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  38858. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  38859. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  38860. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  38861. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  38862. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  38863. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  38864. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  38865. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  38866. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  38867. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  38868. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  38869. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  38870. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  38871. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  38872. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  38873. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  38874. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  38875. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  38876. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  38877. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  38878. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  38879. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  38880. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  38881. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  38882. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  38883. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  38884. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  38885. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  38886. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  38887. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  38888. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  38889. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  38890. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  38891. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  38892. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  38893. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  38894. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  38895. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  38896. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  38897. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  38898. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  38899. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  38900. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  38901. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  38902. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  38903. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  38904. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  38905. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  38906. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  38907. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  38908. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  38909. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  38910. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  38911. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  38912. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  38913. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  38914. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  38915. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  38916. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  38917. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  38918. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  38919. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  38920. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  38921. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  38922. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  38923. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  38924. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  38925. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  38926. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  38927. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  38928. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  38929. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  38930. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  38931. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  38932. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  38933. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  38934. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  38935. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  38936. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  38937. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  38938. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  38939. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  38940. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  38941. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  38942. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  38943. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  38944. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  38945. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  38946. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  38947. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  38948. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  38949. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  38950. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  38951. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  38952. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  38953. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  38954. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  38955. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  38956. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  38957. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  38958. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  38959. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  38960. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  38961. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  38962. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  38963. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  38964. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  38965. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  38966. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  38967. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  38968. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  38969. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  38970. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  38971. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  38972. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  38973. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  38974. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  38975. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  38976. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  38977. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  38978. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  38979. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  38980. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  38981. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  38982. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  38983. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  38984. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  38985. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  38986. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  38987. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  38988. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  38989. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  38990. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  38991. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  38992. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  38993. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  38994. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  38995. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  38996. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  38997. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  38998. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  38999. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  39000. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  39001. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  39002. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  39003. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  39004. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  39005. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  39006. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  39007. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46
  39008. };
  39009. #endif
  39010. wc_test_ret_t ret;
  39011. ret = dilithium_param_vfy_test(WC_ML_DSA_44, ml_dsa_44_pub_key,
  39012. (word32)sizeof(ml_dsa_44_pub_key), ml_dsa_44_sig,
  39013. (word32)sizeof(ml_dsa_44_sig));
  39014. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39015. if (ret == 0) {
  39016. ret = dilithium_param_vfy_test(WC_ML_DSA_44_DRAFT,
  39017. ml_dsa_44_draft_pub_key, (word32)sizeof(ml_dsa_44_draft_pub_key),
  39018. ml_dsa_44_draft_sig, (word32)sizeof(ml_dsa_44_draft_sig));
  39019. }
  39020. #endif
  39021. return ret;
  39022. }
  39023. #endif
  39024. #ifndef WOLFSSL_NO_ML_DSA_65
  39025. static wc_test_ret_t dilithium_param_65_vfy_test(void)
  39026. {
  39027. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_pub_key[] = {
  39028. 0x2c, 0x32, 0xfa, 0x59, 0x71, 0x16, 0x4a, 0x0e, 0x45, 0x0f, 0x21, 0xfd,
  39029. 0x65, 0xee, 0x50, 0xb0, 0xbf, 0xea, 0x8e, 0x4e, 0xa2, 0x55, 0x71, 0xa6,
  39030. 0x65, 0x48, 0x56, 0x20, 0x8a, 0x48, 0x9d, 0xd7, 0xc9, 0x2c, 0x80, 0x62,
  39031. 0x88, 0x68, 0x4d, 0x5f, 0xbe, 0x5f, 0xe5, 0xf5, 0xa4, 0x75, 0xb6, 0x88,
  39032. 0x26, 0xae, 0x7d, 0x11, 0x43, 0x89, 0xcd, 0xe9, 0x67, 0x0c, 0x91, 0x0b,
  39033. 0xd1, 0xd8, 0x8b, 0x7b, 0x73, 0x75, 0x94, 0xc1, 0xc9, 0x61, 0xc7, 0x35,
  39034. 0x21, 0x99, 0x2e, 0xab, 0xe0, 0xdf, 0x4d, 0xac, 0x0d, 0xd0, 0xa2, 0x61,
  39035. 0x5f, 0x04, 0x08, 0x83, 0x66, 0x5c, 0x67, 0x47, 0x0c, 0xab, 0x2c, 0xb7,
  39036. 0x6d, 0x0e, 0x32, 0x4c, 0x8c, 0x25, 0x80, 0xf5, 0xe5, 0x7e, 0x3b, 0xa1,
  39037. 0xc6, 0xc5, 0x87, 0xd8, 0x68, 0xb2, 0xd5, 0x67, 0xf9, 0x5a, 0x8b, 0x88,
  39038. 0xf8, 0xcd, 0x0c, 0xda, 0x4f, 0xfc, 0xd2, 0xaf, 0xb2, 0xa2, 0x38, 0x21,
  39039. 0xf9, 0xd8, 0xf1, 0x1c, 0x8d, 0xb4, 0xe8, 0xfb, 0x76, 0x36, 0x87, 0xf4,
  39040. 0x7d, 0x03, 0xc4, 0x06, 0xab, 0x87, 0xac, 0x52, 0xe8, 0xd5, 0xf7, 0x63,
  39041. 0xf0, 0xa8, 0x0b, 0x95, 0xbd, 0x07, 0xf1, 0x1d, 0x33, 0x7b, 0x8a, 0x2c,
  39042. 0xef, 0x85, 0xbe, 0xf8, 0xc1, 0x4b, 0xa2, 0xb0, 0xe0, 0x7a, 0x85, 0xfa,
  39043. 0x52, 0x36, 0x05, 0xa7, 0x65, 0x4a, 0x0c, 0x21, 0x5c, 0xc0, 0x4f, 0x18,
  39044. 0xb8, 0x66, 0x02, 0xe6, 0xd0, 0x45, 0x60, 0x56, 0xfc, 0x40, 0x94, 0xb5,
  39045. 0xa5, 0x2b, 0xc7, 0x57, 0xc3, 0xc5, 0x30, 0x72, 0x1c, 0x4c, 0x2a, 0xd5,
  39046. 0x75, 0xae, 0x43, 0x9f, 0x01, 0x71, 0xac, 0x5c, 0xdf, 0x9c, 0x0a, 0x3c,
  39047. 0xb5, 0x89, 0x07, 0x9b, 0x28, 0x25, 0x31, 0x31, 0xc5, 0xb7, 0x24, 0x53,
  39048. 0x2c, 0x3c, 0x2a, 0x96, 0xe5, 0x0d, 0xa2, 0x97, 0xa7, 0x08, 0x9d, 0x31,
  39049. 0xc0, 0xcd, 0x53, 0xd5, 0xa8, 0x58, 0xa6, 0xac, 0x43, 0x2d, 0xac, 0x39,
  39050. 0x01, 0x2c, 0x60, 0xf6, 0x82, 0x86, 0xd0, 0xaf, 0xad, 0x61, 0x3f, 0x82,
  39051. 0x80, 0xa1, 0xe1, 0x12, 0x83, 0x6e, 0x1d, 0x5e, 0xfe, 0xc6, 0x1e, 0x2a,
  39052. 0x7a, 0x44, 0xcd, 0xc2, 0x0a, 0xf5, 0xc8, 0x72, 0x3e, 0x29, 0xc7, 0x0a,
  39053. 0xd1, 0x4c, 0x17, 0xdd, 0x1f, 0xb6, 0x95, 0x34, 0xc2, 0x6c, 0xdc, 0x63,
  39054. 0xd1, 0x7e, 0xb0, 0x52, 0x06, 0x18, 0x6c, 0xb1, 0x99, 0x6a, 0xbe, 0x42,
  39055. 0xa9, 0xc0, 0x22, 0xcc, 0x09, 0x11, 0x84, 0x1f, 0x16, 0x9a, 0x0e, 0xdd,
  39056. 0x18, 0x7a, 0x39, 0x34, 0xb0, 0x49, 0x44, 0xcb, 0x88, 0x1f, 0x91, 0x93,
  39057. 0x49, 0x3f, 0xcc, 0x62, 0x56, 0x33, 0x15, 0xcb, 0x02, 0x9b, 0x33, 0xe8,
  39058. 0xd7, 0xab, 0x51, 0xc0, 0x91, 0xe0, 0x9c, 0xd2, 0xf9, 0x52, 0x05, 0x0c,
  39059. 0xbf, 0xf1, 0x97, 0x42, 0xfe, 0xd0, 0x32, 0x27, 0x34, 0xf8, 0x82, 0x2d,
  39060. 0x65, 0x3a, 0x36, 0xce, 0xd1, 0x07, 0x82, 0x3a, 0x6a, 0xaa, 0x56, 0xf1,
  39061. 0x9b, 0x98, 0xca, 0x8e, 0x55, 0xff, 0xa0, 0x74, 0xd6, 0x6a, 0x42, 0xaa,
  39062. 0x0a, 0xd4, 0x59, 0x74, 0xfb, 0xd4, 0xdb, 0x14, 0x10, 0xee, 0xca, 0x78,
  39063. 0x83, 0x83, 0x95, 0x9b, 0x77, 0xf1, 0x9a, 0x48, 0xe0, 0x8f, 0xa4, 0x5a,
  39064. 0x4d, 0xa9, 0x3f, 0x32, 0x78, 0x4a, 0x25, 0x96, 0x9c, 0x20, 0x0a, 0xcc,
  39065. 0x5b, 0xd8, 0xca, 0x19, 0x47, 0x77, 0xb8, 0x7c, 0x51, 0x3e, 0xd6, 0x30,
  39066. 0xdb, 0x45, 0xb0, 0xe6, 0x9d, 0x6f, 0xc5, 0x0a, 0x5d, 0x5f, 0x55, 0xcd,
  39067. 0x0f, 0x20, 0x22, 0x7e, 0x09, 0x99, 0xac, 0xb8, 0x9c, 0x9d, 0xf7, 0x3e,
  39068. 0x7e, 0x07, 0xd7, 0xbc, 0x21, 0x76, 0x8c, 0x27, 0x81, 0x94, 0xab, 0x57,
  39069. 0x4a, 0xe2, 0x91, 0x1c, 0xa4, 0x77, 0x4a, 0xd2, 0x96, 0x52, 0x9d, 0x33,
  39070. 0xb5, 0x58, 0x70, 0xd7, 0xff, 0x22, 0xe8, 0x14, 0xea, 0xd0, 0x8c, 0xd4,
  39071. 0x06, 0x08, 0xd8, 0x73, 0x66, 0x4b, 0x93, 0x41, 0xc9, 0x73, 0x5b, 0x07,
  39072. 0x5f, 0x31, 0xc5, 0x25, 0x98, 0x7b, 0x7b, 0xa5, 0x26, 0x83, 0x94, 0x22,
  39073. 0x42, 0x1c, 0x51, 0xe6, 0x80, 0x48, 0xca, 0xd4, 0x53, 0x40, 0x3a, 0xee,
  39074. 0x2c, 0x29, 0x07, 0xed, 0xdf, 0x97, 0x44, 0x19, 0xe5, 0xe5, 0x35, 0x66,
  39075. 0x1f, 0xbd, 0x29, 0x77, 0x0c, 0x15, 0x6c, 0x95, 0x08, 0x81, 0xe0, 0x76,
  39076. 0x86, 0x5e, 0x6d, 0x77, 0x78, 0x76, 0x07, 0xdd, 0x21, 0x97, 0x59, 0xdb,
  39077. 0xd4, 0xbd, 0xb6, 0x4c, 0x3f, 0x07, 0x93, 0xb6, 0x4a, 0xce, 0xf7, 0x08,
  39078. 0x86, 0xfd, 0x9c, 0x03, 0x08, 0x94, 0x00, 0xea, 0x4b, 0xd6, 0x1e, 0x17,
  39079. 0xfb, 0xb5, 0xba, 0xde, 0x25, 0x95, 0xe7, 0xf8, 0x97, 0x9e, 0x99, 0xae,
  39080. 0x5d, 0xdd, 0xf6, 0x32, 0x1a, 0xf2, 0x4f, 0xcf, 0x0c, 0x17, 0x55, 0xb8,
  39081. 0xfb, 0xae, 0xc8, 0x46, 0xb0, 0x3e, 0x86, 0x2b, 0x5e, 0xef, 0x36, 0xca,
  39082. 0x24, 0xed, 0x32, 0x5b, 0xc8, 0xfb, 0x88, 0x35, 0x6a, 0x26, 0xfe, 0x06,
  39083. 0x54, 0x0c, 0x3e, 0x2c, 0x71, 0xdf, 0x98, 0xf0, 0xbb, 0xb2, 0xe0, 0x9d,
  39084. 0xf7, 0xeb, 0xce, 0x07, 0xfa, 0xc4, 0xab, 0x88, 0xc3, 0x14, 0x33, 0x60,
  39085. 0x48, 0xcf, 0x39, 0x26, 0x90, 0xac, 0xfa, 0x39, 0x6f, 0x2d, 0x9d, 0x6d,
  39086. 0x15, 0x7f, 0x84, 0x6b, 0x0a, 0x1c, 0xf4, 0x6c, 0x78, 0x62, 0x52, 0x93,
  39087. 0x2c, 0x7e, 0x9f, 0x4a, 0x51, 0x7a, 0x2e, 0xad, 0xea, 0xe4, 0xe5, 0x9c,
  39088. 0x15, 0x15, 0x28, 0x4d, 0x3e, 0x5e, 0xb4, 0x3b, 0xff, 0x81, 0xe0, 0x56,
  39089. 0x44, 0x33, 0x33, 0xd9, 0x4b, 0xb2, 0x23, 0x60, 0xed, 0x0d, 0xa5, 0x4e,
  39090. 0x9f, 0x7d, 0xbc, 0x6e, 0x3a, 0xf9, 0x7e, 0x16, 0x47, 0x66, 0xb1, 0x6c,
  39091. 0xc7, 0x26, 0x62, 0x9b, 0x3c, 0x53, 0xb3, 0xa1, 0x16, 0x62, 0x31, 0x64,
  39092. 0xd2, 0xbb, 0x28, 0x5c, 0xe8, 0x21, 0xc3, 0xfc, 0xc3, 0x6d, 0xa7, 0x35,
  39093. 0x4d, 0x57, 0xe0, 0xbd, 0x54, 0x1a, 0x84, 0xf7, 0x9c, 0x8a, 0x54, 0x3d,
  39094. 0x59, 0xb3, 0xa2, 0x46, 0x3b, 0x16, 0x48, 0x3b, 0x3a, 0x3c, 0x5e, 0x88,
  39095. 0xc3, 0x60, 0x63, 0x7e, 0xca, 0x68, 0xb7, 0x2f, 0x2b, 0xb5, 0x62, 0x2e,
  39096. 0x51, 0x89, 0xbe, 0x78, 0xf7, 0xfa, 0x19, 0xcc, 0xca, 0x87, 0x9a, 0xf5,
  39097. 0xef, 0x0d, 0x21, 0x08, 0x3b, 0xd6, 0x9a, 0x94, 0xc5, 0xd1, 0x1b, 0xa9,
  39098. 0x7c, 0xc8, 0x9f, 0x9a, 0xb0, 0xb8, 0xf7, 0x02, 0x12, 0x31, 0x70, 0x52,
  39099. 0x52, 0xda, 0xb5, 0x9a, 0x08, 0x20, 0xc3, 0xc4, 0x0c, 0x6a, 0x34, 0x58,
  39100. 0x75, 0x9b, 0xdc, 0x1a, 0x6a, 0x37, 0x42, 0x9f, 0x16, 0x70, 0xbb, 0x39,
  39101. 0x86, 0xbd, 0x09, 0x9c, 0x04, 0x44, 0xbe, 0x1a, 0xe5, 0xe9, 0x50, 0x9b,
  39102. 0x14, 0x50, 0x4f, 0x00, 0xba, 0xb0, 0xf6, 0x36, 0x4d, 0x69, 0x16, 0x11,
  39103. 0x40, 0x5a, 0x4e, 0x8b, 0x39, 0xb4, 0xf1, 0xb2, 0x11, 0x36, 0x2f, 0x02,
  39104. 0x15, 0xca, 0x78, 0xde, 0x75, 0x07, 0x64, 0x72, 0xfd, 0xd4, 0x48, 0xdd,
  39105. 0xfb, 0xf5, 0x8a, 0x3d, 0xa8, 0x8e, 0x14, 0xd1, 0x69, 0xe3, 0x21, 0x50,
  39106. 0x39, 0xfd, 0xd0, 0x3b, 0xa0, 0x22, 0x61, 0x5c, 0x7e, 0x88, 0x91, 0xe1,
  39107. 0xf0, 0xf6, 0x16, 0x23, 0xdb, 0xdb, 0x50, 0x0e, 0x39, 0xcc, 0x86, 0xf1,
  39108. 0xab, 0x89, 0x60, 0xb0, 0xac, 0x28, 0xc6, 0x57, 0xe4, 0xee, 0xa9, 0x1b,
  39109. 0xae, 0x78, 0xc5, 0x67, 0x1a, 0xeb, 0xb3, 0x43, 0xbc, 0xea, 0x11, 0x0c,
  39110. 0x64, 0xf6, 0xd2, 0x52, 0xa0, 0x7e, 0xcd, 0x6d, 0x84, 0x8c, 0xf8, 0x80,
  39111. 0xb7, 0xdb, 0x26, 0x91, 0x4a, 0xa0, 0x61, 0x69, 0x2f, 0x6f, 0x1c, 0x9d,
  39112. 0x2a, 0x20, 0x44, 0xdc, 0x58, 0xaf, 0x7d, 0xfe, 0x4d, 0xa2, 0x10, 0x21,
  39113. 0x88, 0xef, 0x42, 0x2e, 0x8e, 0xfb, 0x63, 0xbc, 0xc8, 0x26, 0xe7, 0x80,
  39114. 0xa5, 0xbf, 0xe0, 0x7a, 0xcb, 0xf3, 0x31, 0x1c, 0xd9, 0xa3, 0x12, 0x00,
  39115. 0x2f, 0x20, 0xc6, 0xc1, 0x15, 0xfd, 0x5b, 0x0d, 0x8a, 0x4d, 0xfb, 0x84,
  39116. 0x4d, 0xb4, 0x64, 0xeb, 0x12, 0xf3, 0x78, 0x6b, 0x4d, 0xc6, 0x98, 0x46,
  39117. 0x4c, 0xb3, 0xb4, 0x59, 0xdc, 0xb7, 0xdc, 0xbb, 0x56, 0x0f, 0x09, 0x14,
  39118. 0x28, 0x43, 0x9f, 0xb8, 0x75, 0xed, 0xcb, 0x97, 0x25, 0xaf, 0xa5, 0xeb,
  39119. 0x46, 0x14, 0xa6, 0x38, 0x68, 0x06, 0xe0, 0x6e, 0x55, 0x68, 0x6b, 0xf3,
  39120. 0xd8, 0x6d, 0x59, 0x65, 0x65, 0xff, 0x48, 0xfd, 0xdb, 0x3d, 0xe2, 0x21,
  39121. 0xb4, 0x7b, 0x78, 0x6a, 0x2e, 0x28, 0xb8, 0x21, 0xc4, 0x72, 0xf4, 0xef,
  39122. 0xfb, 0x74, 0x43, 0x29, 0xf2, 0x30, 0xc9, 0xca, 0x78, 0x93, 0x72, 0xfd,
  39123. 0x84, 0xa4, 0x95, 0xe0, 0xcd, 0xb1, 0x48, 0x29, 0xe7, 0xd1, 0x27, 0xf7,
  39124. 0xdc, 0x31, 0x6e, 0x00, 0x04, 0xd7, 0x7c, 0xfd, 0x2d, 0x25, 0xe9, 0xdb,
  39125. 0xc2, 0xb8, 0x14, 0x26, 0xed, 0x63, 0xb1, 0x50, 0x0a, 0x3c, 0xb2, 0x79,
  39126. 0x98, 0x79, 0x81, 0x2d, 0xdb, 0x60, 0x97, 0x99, 0xc0, 0x0a, 0x89, 0x9f,
  39127. 0x90, 0x19, 0x0b, 0xb3, 0x97, 0xd2, 0xf7, 0x50, 0xa5, 0x1d, 0x7d, 0x71,
  39128. 0x75, 0xe6, 0x58, 0x62, 0x53, 0x95, 0x40, 0x9e, 0xc7, 0xd3, 0x72, 0xa1,
  39129. 0xae, 0x07, 0xb3, 0x8a, 0x56, 0x61, 0x99, 0x81, 0x3e, 0xe4, 0x5e, 0x78,
  39130. 0x57, 0xd1, 0x8a, 0xc4, 0x04, 0x38, 0x13, 0xa0, 0x5d, 0x68, 0x6d, 0x22,
  39131. 0xae, 0xda, 0xfc, 0x67, 0xbb, 0xfb, 0x8e, 0x1a, 0xdc, 0x24, 0xf7, 0xc8,
  39132. 0xf9, 0x92, 0x6f, 0x4e, 0xb5, 0xe7, 0x6d, 0x13, 0x88, 0x05, 0x5c, 0xbb,
  39133. 0xe0, 0x24, 0x2a, 0x96, 0xc6, 0x70, 0x52, 0x14, 0xd0, 0xd9, 0xd8, 0xb2,
  39134. 0x5b, 0xdc, 0x85, 0xcf, 0x62, 0xb4, 0xcf, 0x77, 0xf1, 0xe5, 0x51, 0xeb,
  39135. 0xef, 0xe9, 0x3e, 0xf0, 0x16, 0xd2, 0xcc, 0x38, 0x0a, 0x47, 0x91, 0xc0,
  39136. 0xe0, 0x14, 0x1a, 0xf9, 0x74, 0xd1, 0x32, 0x8b, 0x02, 0x36, 0x05, 0x55,
  39137. 0x62, 0xa7, 0xae, 0x77, 0xb0, 0x01, 0x3d, 0x2c, 0x91, 0xbe, 0xfa, 0xdd,
  39138. 0x9c, 0x17, 0x42, 0xc1, 0x01, 0x4d, 0xd8, 0x27, 0x3c, 0x10, 0x82, 0x66,
  39139. 0x11, 0x91, 0x8b, 0xc8, 0x52, 0xd5, 0xc1, 0x1d, 0xee, 0xb2, 0x90, 0x17,
  39140. 0xed, 0xf3, 0xad, 0xa5, 0xd5, 0xeb, 0xf2, 0x9b, 0x78, 0xbf, 0x2d, 0x5a,
  39141. 0xad, 0xe5, 0x53, 0xe6, 0xc1, 0x3b, 0xd8, 0xf3, 0x6b, 0xc5, 0x4c, 0x87,
  39142. 0x0a, 0xe3, 0xc8, 0xc7, 0xe5, 0x42, 0x2c, 0xe2, 0x13, 0x1a, 0xe7, 0x27,
  39143. 0x20, 0x3e, 0x95, 0x13, 0x1e, 0xbb, 0x03, 0xae, 0xc0, 0x84, 0x14, 0x6d,
  39144. 0x7b, 0xf7, 0x98, 0x08, 0x18, 0x12, 0xb4, 0x4f, 0x99, 0x4a, 0xcf, 0xd0,
  39145. 0x4a, 0x5d, 0x21, 0x16, 0xf6, 0xdf, 0x10, 0xc7, 0xbe, 0xe6, 0x79, 0x3b,
  39146. 0x35, 0x2a, 0xa6, 0xd6, 0x19, 0x9c, 0xde, 0xbd, 0xaf, 0x72, 0xd2, 0x25,
  39147. 0xe0, 0xa4, 0xde, 0x99, 0x44, 0x18, 0x66, 0x41, 0xc7, 0x56, 0xf7, 0xdc,
  39148. 0x32, 0x56, 0x57, 0x39, 0x18, 0x31, 0xc8, 0x75, 0x01, 0xc3, 0xf3, 0x46,
  39149. 0xcf, 0xbf, 0xc6, 0x10, 0xb5, 0x1c, 0x38, 0xf9, 0xa4, 0xa5, 0x44, 0xa1,
  39150. 0x0b, 0x25, 0x48, 0x9c, 0xd3, 0x1c, 0x55, 0x54, 0x15, 0x9f, 0xe3, 0x74,
  39151. 0x5b, 0xb1, 0x92, 0xb6, 0x52, 0x61, 0xba, 0x2f, 0x53, 0x91, 0x17, 0x44,
  39152. 0x94, 0x00, 0xe4, 0x43, 0xa0, 0xe7, 0x0d, 0xaa, 0x8a, 0x5b, 0x81, 0x43,
  39153. 0xad, 0xfb, 0x50, 0xfe, 0xcf, 0x85, 0x2d, 0xfa, 0xc8, 0x1d, 0xad, 0xc8,
  39154. 0x7a, 0x7c, 0x5e, 0xf3, 0x90, 0x35, 0x5e, 0x67, 0xce, 0x57, 0x4d, 0xa0,
  39155. 0x22, 0x9e, 0x07, 0x4a, 0xf5, 0x9e, 0x5f, 0x91, 0x45, 0xd8, 0x62, 0xe0,
  39156. 0xf3, 0x87, 0x3b, 0xb7, 0x89, 0x2f, 0xdf, 0x8b, 0x82, 0xb1, 0x86, 0xc3,
  39157. 0xa4, 0xa3, 0x68, 0xc7, 0x73, 0x9e, 0x68, 0x8d, 0x24, 0x6a, 0x29, 0x94,
  39158. 0x58, 0x57, 0x4b, 0x81, 0x00, 0xe2, 0x2b, 0x94, 0x0a, 0xf5, 0x96, 0xa3,
  39159. 0x23, 0x9a, 0x7b, 0xd0, 0x2d, 0xcb, 0x6a, 0x8e, 0xae, 0x1b, 0x1c, 0x34,
  39160. 0xed, 0x30, 0x4e, 0xca, 0x29, 0x21, 0xfc, 0x3d, 0x70, 0x11, 0xc1, 0x5f,
  39161. 0x3e, 0xc2, 0x9e, 0x88, 0x71, 0x29, 0xa3, 0x8f, 0x92, 0xf5, 0x46, 0x77,
  39162. 0xd5, 0x47, 0x2d, 0x2b, 0x66, 0x1c, 0x07, 0xf0, 0xfc, 0x7b, 0xa0, 0x13,
  39163. 0x00, 0xae, 0xa5, 0x61, 0x92, 0x36, 0xeb, 0x7e, 0x43, 0x91, 0x20, 0x72,
  39164. 0xe5, 0xba, 0x7f, 0x79, 0x23, 0x12, 0x3e, 0xb2, 0x4b, 0x13, 0xa1, 0x8c,
  39165. 0x84, 0x72, 0x3b, 0x45, 0x62, 0xcf, 0x2e, 0x78, 0xc4, 0x9c, 0x22, 0x09,
  39166. 0xfa, 0x59, 0x9d, 0xdf, 0x13, 0x54, 0x66, 0xe2, 0x6f, 0xfa, 0xb5, 0x2a,
  39167. 0x27, 0x3e, 0x17, 0x82, 0xf3, 0x2a, 0x4d, 0x36, 0xd3, 0xf0, 0x8d, 0x43,
  39168. 0x40, 0x2c, 0x84, 0x68, 0xbe, 0x40, 0x50, 0x7d, 0xa3, 0x27, 0x5e, 0xde,
  39169. 0x4d, 0x04, 0x6f, 0xe8, 0x96, 0x9c, 0x7a, 0x1d, 0xb8, 0x2b, 0x8a, 0xb1,
  39170. 0x6e, 0xe2, 0x36, 0x07, 0x22, 0x50, 0xd9, 0x71, 0x93, 0x48, 0xb5, 0x51,
  39171. 0xce, 0x2a, 0x64, 0x6b, 0x11, 0xa6, 0xb9, 0x40, 0x2d, 0x6c, 0xd2, 0x76,
  39172. 0x52, 0xc6, 0xe3, 0xa6, 0x6b, 0xd2, 0x3f, 0x39, 0xd2, 0x13, 0x28, 0xa4,
  39173. 0xa9, 0x58, 0x99, 0xe8, 0x3d, 0x08, 0xfa, 0x3c, 0x34, 0x39, 0x4d, 0x7d,
  39174. 0x5e, 0x10, 0x72, 0x51, 0x96, 0x1d, 0x4b, 0xd9, 0x3e, 0xc9, 0x22, 0x4c,
  39175. 0x72, 0x63, 0xf8, 0x87, 0x4b, 0xe7, 0x41, 0xac, 0xcd, 0xd6, 0x34, 0xa2,
  39176. 0xe1, 0xe8, 0x66, 0x81, 0x04, 0x7d, 0x70, 0x95, 0xba, 0x37, 0x86, 0x9e,
  39177. 0x1f, 0x9a, 0x1b, 0xe4, 0x35, 0xac, 0xe6, 0xcf, 0x48, 0x55, 0x6e, 0xbb,
  39178. 0x9d, 0x40, 0x79, 0x96, 0xdd, 0xac, 0xf8, 0xf5, 0x99, 0xad, 0x43, 0x0d,
  39179. 0xad, 0xa9, 0x62, 0xc0, 0x70, 0x8b, 0x50, 0x9b, 0xca, 0x0d, 0x3e, 0x54,
  39180. 0x9c, 0x27, 0xd5, 0x9e, 0x20, 0xe2, 0xe0, 0xb0, 0xb0, 0xbe, 0x8e, 0x56,
  39181. 0x43, 0x95, 0x9b, 0x34, 0xd1, 0x05, 0x28, 0xa0, 0xee, 0xd9, 0xab, 0x6a,
  39182. 0xa7, 0xbb, 0xb7, 0x1b, 0x3a, 0x5d, 0x33, 0x97, 0x25, 0x54, 0xe4, 0x0e,
  39183. 0x64, 0x79, 0xed, 0x16, 0x62, 0x89, 0x70, 0x4a, 0xa6, 0x47, 0x40, 0xd7,
  39184. 0xa3, 0xd2, 0x6f, 0x28, 0xdd, 0xc5, 0x04, 0xab, 0x7e, 0x7e, 0x1e, 0xb0,
  39185. 0x19, 0x02, 0x48, 0xb5, 0x88, 0x82, 0x75, 0xaf, 0x66, 0x74, 0xca, 0xf6,
  39186. 0xd7, 0xe8, 0x6d, 0xfa, 0x5e, 0xfa, 0xaf, 0xa8, 0x04, 0xaa, 0x2c, 0x09,
  39187. 0xf1, 0x4c, 0x36, 0x75, 0xb5, 0xdc, 0xe8, 0x04, 0x80, 0xd3, 0x14, 0x78,
  39188. 0x09, 0x5b, 0xfd, 0x52, 0x6f, 0xd9, 0x3c, 0x1c, 0x02, 0x3b, 0x77, 0xb8,
  39189. 0xa1, 0xe9, 0xa4, 0xb7, 0x42, 0x62, 0xee, 0xea, 0x43, 0xf3, 0xd8, 0xd0,
  39190. 0x7a, 0x53, 0x91, 0x34, 0x7f, 0xe7, 0x9a, 0xc6
  39191. };
  39192. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39193. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_pub_key[] = {
  39194. 0x15, 0xc9, 0xe5, 0x53, 0x2f, 0xd8, 0x1f, 0xb4, 0xa3, 0x9f,
  39195. 0xae, 0xad, 0xb3, 0x10, 0xd0, 0x72, 0x69, 0xd3, 0x02, 0xf3,
  39196. 0xdf, 0x67, 0x5a, 0x31, 0x52, 0x19, 0xca, 0x39, 0x27, 0x77,
  39197. 0x61, 0x6d, 0x0f, 0xc1, 0x33, 0x26, 0x09, 0xf0, 0xf9, 0x4d,
  39198. 0x12, 0x7a, 0xef, 0xf7, 0x21, 0x26, 0x2c, 0xe0, 0xe2, 0x92,
  39199. 0x1f, 0x9d, 0xd1, 0xaa, 0xaf, 0x08, 0x14, 0xf2, 0xaa, 0x24,
  39200. 0x99, 0x0f, 0x20, 0x57, 0x35, 0x04, 0x32, 0x96, 0x8e, 0x6e,
  39201. 0x10, 0x64, 0xe3, 0xe3, 0x57, 0x26, 0x33, 0x32, 0x7b, 0xe4,
  39202. 0x18, 0x41, 0x77, 0xd3, 0x24, 0x63, 0x3d, 0x11, 0xea, 0xdc,
  39203. 0xbe, 0x59, 0xff, 0x8d, 0xc2, 0xe4, 0xc7, 0x04, 0xf3, 0xd4,
  39204. 0xe0, 0x1d, 0x5e, 0x09, 0x46, 0xbf, 0x02, 0x05, 0xc7, 0xa6,
  39205. 0xb7, 0x82, 0x40, 0x1f, 0x55, 0xe9, 0x77, 0x82, 0xc0, 0xcc,
  39206. 0x86, 0x99, 0x19, 0x99, 0xa2, 0xc9, 0x1b, 0x4f, 0xdd, 0x49,
  39207. 0x4c, 0x78, 0x0a, 0x58, 0xb8, 0xf0, 0x23, 0xac, 0x1a, 0x71,
  39208. 0x57, 0x6d, 0xd6, 0x3a, 0x3a, 0x6f, 0x93, 0xb3, 0x2b, 0x09,
  39209. 0xbe, 0xec, 0x7b, 0x5b, 0xf7, 0x3a, 0xed, 0xf9, 0xd0, 0xb1,
  39210. 0xfe, 0x9f, 0x9b, 0xec, 0x11, 0xb6, 0x6b, 0xd1, 0xb6, 0x00,
  39211. 0x72, 0x7f, 0x68, 0x9a, 0x61, 0xa5, 0xf5, 0x6e, 0xe9, 0x46,
  39212. 0xa4, 0x82, 0x08, 0x9f, 0x50, 0x4c, 0x75, 0xc3, 0x48, 0x85,
  39213. 0x76, 0x39, 0xea, 0x0c, 0xf2, 0xe8, 0x7e, 0x48, 0x69, 0xd9,
  39214. 0x6f, 0x9a, 0x89, 0x7d, 0x98, 0xc1, 0x16, 0xdc, 0x2f, 0xc7,
  39215. 0x0a, 0x11, 0xa8, 0xbb, 0xe7, 0x91, 0xb1, 0x0f, 0x0e, 0xf0,
  39216. 0xb4, 0xc8, 0x41, 0x7e, 0x62, 0x9e, 0x3c, 0x30, 0x4c, 0xbc,
  39217. 0x4c, 0xeb, 0x37, 0xaf, 0x48, 0x72, 0x59, 0x64, 0x8e, 0xfb,
  39218. 0x77, 0x11, 0x28, 0xdd, 0x30, 0x52, 0x8e, 0x69, 0x8c, 0x9f,
  39219. 0x3d, 0xec, 0xdf, 0xa7, 0x5f, 0x42, 0x18, 0xda, 0xba, 0x1a,
  39220. 0x96, 0x91, 0x7d, 0x62, 0xd5, 0x52, 0xff, 0x44, 0xc9, 0x1d,
  39221. 0x29, 0xa6, 0xb9, 0x03, 0x9a, 0x26, 0x26, 0xcf, 0x57, 0x40,
  39222. 0x70, 0x7e, 0x2b, 0xbd, 0xf0, 0x81, 0x71, 0x0f, 0x0b, 0x2e,
  39223. 0x9b, 0x03, 0xba, 0x31, 0x41, 0x68, 0x37, 0xc8, 0xff, 0xea,
  39224. 0xc4, 0x73, 0xa5, 0xf9, 0xc2, 0x92, 0x78, 0x0c, 0xe7, 0xfd,
  39225. 0x5d, 0xb2, 0x01, 0xb5, 0x8d, 0xeb, 0x64, 0xd4, 0x14, 0xea,
  39226. 0x7a, 0xd1, 0x42, 0xc8, 0x99, 0xe4, 0x7d, 0x5b, 0x7e, 0x3b,
  39227. 0x8f, 0xab, 0x82, 0x12, 0xdf, 0xbb, 0xa1, 0x45, 0x30, 0xc9,
  39228. 0x0f, 0xb9, 0xe5, 0xba, 0xe6, 0x8a, 0xf3, 0x78, 0x61, 0xcc,
  39229. 0x9f, 0xe1, 0x46, 0x2a, 0x9a, 0x18, 0x0e, 0x2a, 0x57, 0xf3,
  39230. 0xe5, 0x56, 0xd1, 0x42, 0x48, 0xe1, 0x5a, 0x8e, 0x33, 0xce,
  39231. 0x19, 0xe5, 0x3e, 0x7f, 0x00, 0x70, 0x9c, 0x4c, 0xd3, 0xe1,
  39232. 0x0c, 0xa1, 0x7e, 0xd4, 0xa9, 0x9e, 0x8b, 0xe2, 0xf0, 0xac,
  39233. 0xdb, 0xa6, 0x72, 0x75, 0x67, 0xa6, 0x57, 0xed, 0x79, 0x2e,
  39234. 0xca, 0x8d, 0xeb, 0x9b, 0x9e, 0xb7, 0xbf, 0x30, 0x02, 0x2b,
  39235. 0xb3, 0x43, 0x89, 0x9b, 0xa8, 0x88, 0xa5, 0xbb, 0x33, 0xd9,
  39236. 0x99, 0x30, 0x7c, 0xc7, 0xd4, 0x28, 0x5e, 0x5e, 0x3f, 0x9d,
  39237. 0x6d, 0x35, 0x75, 0x33, 0x8e, 0xff, 0x84, 0x2e, 0x2d, 0xda,
  39238. 0xf0, 0xff, 0x70, 0xe5, 0xb5, 0x62, 0x96, 0x33, 0x3a, 0xd9,
  39239. 0xb5, 0x82, 0x25, 0x81, 0x81, 0x40, 0x5d, 0x4f, 0x11, 0x86,
  39240. 0x63, 0x1a, 0x06, 0xc1, 0x67, 0xc7, 0x49, 0x03, 0xc7, 0xe4,
  39241. 0x6f, 0xb4, 0x13, 0x3e, 0x57, 0x62, 0xfd, 0x8a, 0xc6, 0x2b,
  39242. 0x65, 0x5b, 0xa4, 0x29, 0x57, 0x8d, 0xde, 0xa5, 0xee, 0x32,
  39243. 0xc2, 0x76, 0x03, 0xca, 0xce, 0xc1, 0x48, 0xec, 0x45, 0xcf,
  39244. 0x30, 0x21, 0x28, 0x7f, 0x10, 0x47, 0xd2, 0xdb, 0xee, 0xca,
  39245. 0x5b, 0x0f, 0xd5, 0x39, 0x3a, 0xc3, 0xa6, 0x78, 0xb2, 0x15,
  39246. 0xaf, 0x82, 0x3c, 0x2f, 0xc4, 0x51, 0x5c, 0x52, 0xad, 0xf2,
  39247. 0x89, 0x92, 0x8e, 0xf3, 0x50, 0x38, 0xed, 0xf8, 0xc9, 0x14,
  39248. 0x4c, 0xe4, 0xa3, 0x9a, 0xaf, 0xc4, 0x5c, 0xf3, 0x9f, 0xc3,
  39249. 0xa3, 0xc0, 0xbe, 0x45, 0x1b, 0x21, 0x63, 0xfa, 0xe0, 0xe0,
  39250. 0x91, 0x2b, 0x42, 0xca, 0x91, 0xfb, 0x5e, 0x97, 0x9a, 0x0a,
  39251. 0xd4, 0x88, 0xba, 0xb8, 0x22, 0xc6, 0xbf, 0x56, 0x58, 0x1e,
  39252. 0x92, 0xa9, 0x9d, 0xa7, 0xed, 0xc9, 0xab, 0x54, 0x4f, 0x75,
  39253. 0x8d, 0x42, 0xc1, 0xe1, 0x61, 0xd0, 0x91, 0x9a, 0x3a, 0x40,
  39254. 0x9a, 0xa3, 0xfb, 0x7b, 0x4e, 0xf0, 0x85, 0xf0, 0xdc, 0x40,
  39255. 0x72, 0x9f, 0x05, 0xa8, 0xbe, 0x95, 0x5a, 0x7f, 0xba, 0x75,
  39256. 0x00, 0x6e, 0x95, 0x76, 0xbd, 0xb2, 0x40, 0xf5, 0xb0, 0x64,
  39257. 0x0a, 0x2f, 0x06, 0x3d, 0x9f, 0xac, 0x6a, 0xa5, 0x46, 0x5a,
  39258. 0x85, 0xa4, 0x6f, 0xee, 0x27, 0xa0, 0xeb, 0x5f, 0x1f, 0x91,
  39259. 0xbd, 0x2b, 0x02, 0x16, 0xdf, 0x74, 0x97, 0x2c, 0xd0, 0xa8,
  39260. 0x9f, 0x3a, 0x7b, 0xdf, 0x3e, 0x98, 0x4a, 0x91, 0xdc, 0x19,
  39261. 0x96, 0x88, 0x75, 0x21, 0x1a, 0x6a, 0xa8, 0x4b, 0x1f, 0x35,
  39262. 0xd1, 0x92, 0xf5, 0x76, 0xf4, 0x72, 0x55, 0x13, 0xdb, 0x5d,
  39263. 0x07, 0x8d, 0xd9, 0x72, 0xe4, 0x75, 0xde, 0x80, 0xbc, 0xe9,
  39264. 0x9c, 0xf0, 0x5c, 0x6a, 0x8a, 0x0e, 0x34, 0xf6, 0x3f, 0x5c,
  39265. 0xef, 0x0e, 0xcc, 0x52, 0x38, 0x2d, 0x7b, 0xc2, 0x1b, 0x69,
  39266. 0x9f, 0xe5, 0xed, 0x14, 0xb0, 0x91, 0x0b, 0xe9, 0x4d, 0x34,
  39267. 0xd5, 0xaa, 0xd4, 0xd2, 0x46, 0x39, 0x45, 0x7e, 0x85, 0x2f,
  39268. 0xdb, 0x89, 0xf4, 0xff, 0x05, 0x74, 0x51, 0xba, 0xdd, 0xee,
  39269. 0xf6, 0xc2, 0xc1, 0x0a, 0x8f, 0xd9, 0xeb, 0xc7, 0x61, 0x30,
  39270. 0x8f, 0x86, 0x8b, 0x1f, 0x82, 0xc1, 0x22, 0xfd, 0x83, 0xf4,
  39271. 0x5d, 0xc5, 0x94, 0xf5, 0xd7, 0x17, 0xc7, 0x7b, 0x71, 0xf5,
  39272. 0x5e, 0x15, 0x49, 0x70, 0xb2, 0x57, 0xa0, 0xc0, 0x57, 0x63,
  39273. 0x53, 0x35, 0xb6, 0x52, 0x20, 0x7b, 0x83, 0xd4, 0x57, 0x63,
  39274. 0x25, 0x8e, 0x83, 0xb3, 0x8e, 0x26, 0x1f, 0x09, 0xde, 0x14,
  39275. 0xd6, 0xa6, 0xfc, 0xe5, 0x93, 0x3c, 0x88, 0x8e, 0xf5, 0x10,
  39276. 0x57, 0xb9, 0xc9, 0x9b, 0xff, 0x72, 0x9d, 0x3d, 0x3f, 0x97,
  39277. 0xd9, 0x3c, 0x20, 0xe2, 0x57, 0xfd, 0x2a, 0x5c, 0x17, 0x12,
  39278. 0xe6, 0x08, 0xaf, 0xe4, 0x26, 0x96, 0xb9, 0x6d, 0xc3, 0xac,
  39279. 0x22, 0xf3, 0x8b, 0x89, 0xde, 0xc7, 0x8a, 0x93, 0x06, 0xf7,
  39280. 0x1d, 0x08, 0x21, 0x36, 0x16, 0x74, 0x2b, 0x97, 0x23, 0xe4,
  39281. 0x79, 0x31, 0x08, 0x23, 0x62, 0x30, 0x67, 0xe2, 0xed, 0x30,
  39282. 0x9b, 0x0c, 0xf9, 0x08, 0x7a, 0x29, 0x73, 0xc6, 0x77, 0x8a,
  39283. 0xbb, 0x2a, 0x1c, 0x66, 0xd0, 0xdd, 0x9e, 0xa3, 0xe9, 0x62,
  39284. 0xcc, 0xb7, 0x88, 0x25, 0x4a, 0x5f, 0xbc, 0xaa, 0xe3, 0xe4,
  39285. 0x4f, 0xec, 0xa6, 0x8e, 0xa6, 0xa4, 0x1b, 0x22, 0x2b, 0x2c,
  39286. 0x8f, 0x57, 0x7f, 0xb7, 0x33, 0xfe, 0x16, 0x43, 0x85, 0xc5,
  39287. 0xd2, 0x95, 0xe6, 0xb9, 0x21, 0x68, 0x88, 0x98, 0x33, 0x8c,
  39288. 0x1d, 0x15, 0x9c, 0x4d, 0x62, 0x1f, 0x6b, 0xe8, 0x7a, 0x2d,
  39289. 0x6b, 0x0e, 0xc3, 0xde, 0x1a, 0xa8, 0xed, 0x67, 0xb3, 0xb3,
  39290. 0x36, 0x5b, 0x4b, 0xcb, 0xe8, 0xa8, 0x5c, 0x0b, 0x2f, 0xca,
  39291. 0xd7, 0x71, 0xe8, 0x85, 0xe7, 0x4d, 0xe5, 0x7b, 0x45, 0xed,
  39292. 0xb2, 0x4c, 0x69, 0x04, 0x7e, 0x4f, 0xc0, 0xef, 0x1a, 0xca,
  39293. 0x0d, 0xa6, 0xc4, 0x79, 0x15, 0x78, 0x9c, 0xd2, 0x91, 0x3c,
  39294. 0x32, 0x55, 0x40, 0xe7, 0xcb, 0x7e, 0xde, 0x07, 0xa6, 0x97,
  39295. 0x00, 0x2d, 0x70, 0xf6, 0x3d, 0x15, 0xdf, 0x29, 0x8e, 0xa3,
  39296. 0x96, 0x6d, 0xf2, 0xbb, 0xa5, 0x1b, 0x7b, 0x58, 0x30, 0xf6,
  39297. 0x17, 0xbd, 0xda, 0x13, 0xf7, 0x33, 0xc2, 0x62, 0x32, 0xd4,
  39298. 0x1c, 0x2e, 0x31, 0x74, 0x92, 0xad, 0x99, 0x8c, 0x0e, 0x7c,
  39299. 0x50, 0x21, 0xcd, 0xff, 0x41, 0xeb, 0xd1, 0xca, 0x14, 0xb7,
  39300. 0xb2, 0x31, 0x2f, 0xbe, 0x16, 0xce, 0x4f, 0x26, 0x16, 0x04,
  39301. 0xc2, 0xaf, 0xbe, 0x0d, 0x24, 0xab, 0x9a, 0x21, 0x37, 0x06,
  39302. 0xac, 0x50, 0x23, 0xf1, 0xbe, 0x5c, 0xbb, 0x64, 0xf3, 0xd3,
  39303. 0x66, 0xa3, 0xb8, 0xbe, 0x8b, 0x49, 0x8d, 0xf6, 0xc7, 0xb9,
  39304. 0x8f, 0x4e, 0x31, 0x06, 0x51, 0xe5, 0xf3, 0x0e, 0x56, 0xc4,
  39305. 0x24, 0x30, 0xf5, 0xe9, 0x36, 0x71, 0xbc, 0xc9, 0x70, 0x2c,
  39306. 0x6c, 0x4c, 0x15, 0x43, 0x44, 0xa4, 0xfc, 0xf1, 0xd2, 0x71,
  39307. 0x6c, 0x4c, 0xce, 0x30, 0x6c, 0x05, 0x7d, 0x2e, 0xb7, 0xbc,
  39308. 0xe4, 0x65, 0x76, 0x24, 0x75, 0x36, 0xdf, 0x28, 0xfc, 0xcd,
  39309. 0x9a, 0xba, 0xc2, 0xcd, 0xb0, 0x30, 0xdb, 0xe7, 0x2e, 0x3c,
  39310. 0x92, 0x63, 0x1d, 0x30, 0x23, 0x74, 0xb1, 0xb8, 0xcc, 0xd7,
  39311. 0xb6, 0x90, 0x65, 0x73, 0xa2, 0x2a, 0x6e, 0x49, 0x95, 0x0d,
  39312. 0xab, 0x24, 0xdf, 0x2d, 0xbf, 0x76, 0x46, 0x01, 0x44, 0xe4,
  39313. 0x18, 0x8e, 0xd5, 0x9a, 0x76, 0xc9, 0xc6, 0xbc, 0xdb, 0x7f,
  39314. 0x80, 0x52, 0xc6, 0x40, 0x41, 0x12, 0x36, 0x7c, 0x80, 0x69,
  39315. 0xce, 0x7b, 0xe1, 0xa0, 0x53, 0xa2, 0xd6, 0x8f, 0x3f, 0xf7,
  39316. 0xd7, 0x61, 0x09, 0x70, 0xa2, 0xa0, 0xc6, 0xaf, 0xa0, 0xd0,
  39317. 0xfa, 0x13, 0xbf, 0xc0, 0x69, 0x15, 0xce, 0x15, 0xec, 0x24,
  39318. 0x4b, 0x6b, 0xdc, 0x93, 0x51, 0xc6, 0x82, 0x19, 0x92, 0x84,
  39319. 0x5d, 0x99, 0xb0, 0x90, 0x2c, 0xcc, 0x2a, 0x81, 0x6b, 0x22,
  39320. 0x64, 0x0a, 0xcb, 0x51, 0x25, 0x82, 0x50, 0x02, 0x2d, 0x3e,
  39321. 0xd4, 0x72, 0xb3, 0x0c, 0x15, 0x77, 0xd2, 0xca, 0x98, 0x2f,
  39322. 0x41, 0x93, 0x14, 0xb2, 0x7f, 0xa1, 0x97, 0xa3, 0xb8, 0x8a,
  39323. 0x56, 0x24, 0x38, 0xa7, 0x36, 0xc5, 0x01, 0xc0, 0x9f, 0x3f,
  39324. 0x3e, 0x9a, 0xf6, 0xe9, 0x16, 0x82, 0x01, 0x58, 0x70, 0x0e,
  39325. 0x0d, 0xbc, 0xfa, 0x03, 0x57, 0x65, 0xa8, 0x5a, 0x3d, 0x57,
  39326. 0x81, 0x23, 0xbe, 0x6e, 0xa9, 0xe8, 0x22, 0xdf, 0x2f, 0x70,
  39327. 0xeb, 0x0a, 0x03, 0x96, 0x6b, 0xef, 0x20, 0x9f, 0xf2, 0x62,
  39328. 0xe7, 0xb2, 0x6e, 0x3a, 0x1e, 0x40, 0x1f, 0xd2, 0x97, 0x48,
  39329. 0xd1, 0x18, 0xf0, 0xeb, 0x52, 0x58, 0x02, 0x26, 0xce, 0x75,
  39330. 0xb1, 0x3a, 0x9d, 0x5b, 0x52, 0x94, 0xb2, 0x6e, 0x0e, 0x3f,
  39331. 0x39, 0xb6, 0xd9, 0x8a, 0x9d, 0xe8, 0x7c, 0x83, 0x32, 0xcc,
  39332. 0x43, 0x35, 0x9b, 0x7a, 0xed, 0xb2, 0x1e, 0x51, 0x37, 0x6c,
  39333. 0x14, 0xd8, 0xb8, 0x55, 0xb3, 0x91, 0xef, 0x0c, 0x3a, 0xe5,
  39334. 0x77, 0xd0, 0xbd, 0xb0, 0x7d, 0x38, 0x84, 0x2a, 0x47, 0xb2,
  39335. 0xb6, 0xda, 0xd7, 0x75, 0xd6, 0x2e, 0x60, 0xc7, 0x10, 0x52,
  39336. 0xf7, 0xdd, 0x09, 0x15, 0x6f, 0x04, 0x31, 0xc3, 0x5a, 0x6b,
  39337. 0x0c, 0x60, 0x10, 0xa8, 0x6e, 0x20, 0xa9, 0xdd, 0xb7, 0x72,
  39338. 0xc3, 0x9e, 0x85, 0xd2, 0x8f, 0x16, 0x7e, 0x3d, 0xe0, 0x63,
  39339. 0x81, 0x32, 0xfd, 0xca, 0xbc, 0x0f, 0xef, 0x3e, 0x74, 0x6a,
  39340. 0xb1, 0x60, 0xc1, 0x10, 0x50, 0x7c, 0x67, 0xa4, 0x19, 0xa7,
  39341. 0xb8, 0xed, 0xe6, 0xf5, 0x4e, 0x41, 0x53, 0xa6, 0x72, 0x1b,
  39342. 0x2c, 0x33, 0x6a, 0x37, 0xf1, 0xb5, 0x1c, 0x01, 0x7d, 0xa2,
  39343. 0x1f, 0x2c, 0x4e, 0x0a, 0xbf, 0xd4, 0x2c, 0x24, 0x91, 0x58,
  39344. 0x62, 0xfb, 0xf8, 0x63, 0xd9, 0xf8, 0x78, 0xf5, 0xc7, 0x78,
  39345. 0x32, 0xda, 0x99, 0xeb, 0x58, 0x20, 0x25, 0x19, 0xb1, 0x06,
  39346. 0x7f, 0x6a, 0x29, 0x20, 0xdb, 0xc8, 0x22, 0x48, 0xa9, 0x7f,
  39347. 0x24, 0x54, 0x8d, 0x7d, 0x8d, 0xb1, 0x69, 0xb2, 0xa3, 0x98,
  39348. 0x14, 0x0f, 0xba, 0xfa, 0xb6, 0x15, 0xe8, 0x28, 0x99, 0x3f,
  39349. 0x30, 0x04, 0x50, 0xab, 0x5a, 0x3c, 0xf1, 0x97, 0xe1, 0xc8,
  39350. 0x0f, 0x0e, 0xb4, 0x11, 0x63, 0x5a, 0x79, 0x08, 0x48, 0x75,
  39351. 0xaf, 0x9b, 0xca, 0xd9, 0x13, 0x18, 0xcc, 0xb1, 0xb3, 0xee,
  39352. 0xdd, 0x63, 0xdd, 0xf4, 0x21, 0x98, 0x76, 0xe2, 0x3e, 0xd5,
  39353. 0x86, 0x23, 0x33, 0x7e, 0xc7, 0xb4, 0x35, 0x4b, 0xc2, 0x2d,
  39354. 0xe1, 0xe2, 0xb0, 0x6c, 0x8b, 0x9b, 0x20, 0x3d, 0x48, 0x24,
  39355. 0x7c, 0xea, 0xa1, 0x75, 0x27, 0xe5, 0xf4, 0x70, 0xeb, 0x3b,
  39356. 0xc7, 0x26, 0x37, 0x04, 0xff, 0x8a, 0x7a, 0xd0, 0xc2, 0xb7,
  39357. 0x84, 0xb7, 0x29, 0xfb, 0x0e, 0xa3, 0xa8, 0x71, 0xcd, 0x58,
  39358. 0x06, 0x36, 0xe2, 0xf2, 0x77, 0xcc, 0x0f, 0x78, 0x08, 0x2b,
  39359. 0xbb, 0xe3, 0x53, 0x05, 0x71, 0xdc, 0x6c, 0x37, 0x32, 0x91,
  39360. 0x46, 0x42, 0x4f, 0x21, 0xe0, 0x34, 0xad, 0x3f, 0x30, 0x5a,
  39361. 0xc7, 0x0d, 0x17, 0x19, 0x39, 0x31, 0x58, 0x69, 0x3c, 0x8c,
  39362. 0xbe, 0xe7, 0xa6, 0x3b, 0xad, 0xfb, 0x46, 0x89, 0x06, 0xc1,
  39363. 0x8c, 0x16, 0x9a, 0x06, 0x3a, 0xd0, 0x7e, 0xd6, 0xb0, 0x7b,
  39364. 0x7d, 0xf8, 0x91, 0x7c, 0xfa, 0xd9, 0x66, 0x39, 0xfa, 0xbc,
  39365. 0x57, 0xa7, 0x78, 0x8b, 0x36, 0x78, 0xc0, 0x1c, 0x0e, 0x23,
  39366. 0x05, 0x0e, 0x04, 0x61, 0x16, 0x34, 0xf9, 0xc6, 0x63, 0x58,
  39367. 0xdf, 0xf4, 0x52, 0xce, 0xd0, 0x0f, 0x0c, 0xec, 0xb1, 0x82,
  39368. 0xf4, 0x72, 0x73, 0x72, 0x3f, 0x02, 0xbe, 0xe3, 0x9c, 0x63,
  39369. 0x73, 0xc8, 0x21, 0x65, 0xba, 0x57, 0x52, 0xa9, 0x19, 0xac,
  39370. 0x68, 0x50, 0xbd, 0x2d, 0x72, 0x5b, 0x93, 0x0f, 0x1c, 0x81,
  39371. 0x77, 0xd7, 0x2e, 0xc3, 0x93, 0x52, 0x6e, 0xdc, 0x79, 0x52,
  39372. 0x9f, 0xe3, 0xde, 0xe1, 0xba, 0x58, 0x55, 0xab, 0x8a, 0xf2,
  39373. 0x35, 0x6a, 0xcf, 0x94, 0x1f, 0x17, 0xa4, 0x23, 0x2e, 0x8e,
  39374. 0x18, 0x21, 0xbe, 0x14, 0xfa, 0xe7, 0x59, 0xc5, 0x44, 0x34,
  39375. 0xce, 0x03, 0xf4, 0xb7, 0x75, 0xd3, 0x51, 0x55, 0xdf, 0xff,
  39376. 0xcf, 0x4f, 0x44, 0xee, 0x13, 0x9b, 0xcb, 0x12, 0xae, 0xe5,
  39377. 0x5b, 0x44, 0x65, 0x28, 0xcb, 0x6a, 0x9c, 0x24, 0x1d, 0xea,
  39378. 0x2d, 0x5e, 0xa5, 0xc3, 0x78, 0xad, 0xed, 0x0c, 0x05, 0xa6,
  39379. 0xaf, 0x95, 0x04, 0xd2, 0xb5, 0x91, 0x0e, 0xa0, 0x06, 0x77,
  39380. 0xc5, 0x82, 0xf6, 0xdd, 0x72, 0x83, 0x04, 0xcc, 0xb0, 0xab,
  39381. 0x7a, 0xf0, 0xb4, 0x4d, 0x36, 0x71, 0x72, 0x1a, 0x9a, 0x0d,
  39382. 0xcd, 0xa3, 0x11, 0xa8, 0x0d, 0x7d, 0x49, 0xce, 0x9c, 0x09,
  39383. 0x1d, 0x08, 0xa4, 0x39, 0x2e, 0x03, 0xdf, 0x3a, 0xc8, 0xfe,
  39384. 0x6a, 0x2b, 0x0b, 0x07, 0x80, 0x55, 0x8a, 0xa8, 0xe6, 0x0e,
  39385. 0xc9, 0x7e, 0x83, 0xce, 0x3a, 0x98, 0x98, 0x4e, 0x3e, 0x08,
  39386. 0x20, 0x8f, 0x10, 0xfc, 0xc1, 0xc4, 0xcf, 0x37, 0x8d, 0x69,
  39387. 0xd8, 0x57, 0x9d, 0x48, 0x80, 0x6a, 0xef, 0x0c, 0xdd, 0x27,
  39388. 0x99, 0xf9, 0xe7, 0xd0, 0xd2, 0x36, 0xd8, 0xed, 0x41, 0x14,
  39389. 0x1b, 0x10
  39390. };
  39391. #endif
  39392. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_sig[] = {
  39393. 0xb1, 0xd1, 0x8e, 0x83, 0x0b, 0x0d, 0xd2, 0x71, 0xb2, 0xaa, 0x31, 0x38,
  39394. 0x16, 0xf0, 0xb4, 0xbc, 0x64, 0x2b, 0x97, 0xa1, 0x08, 0x19, 0x4f, 0x52,
  39395. 0xfe, 0x99, 0x1a, 0xa9, 0xd4, 0x08, 0x93, 0x99, 0x88, 0xfd, 0x6a, 0xd6,
  39396. 0xd8, 0xdb, 0xf0, 0x71, 0x2a, 0xc9, 0x04, 0x83, 0xc9, 0x45, 0x59, 0x5d,
  39397. 0xe0, 0x36, 0x59, 0x53, 0x1b, 0xb8, 0x5a, 0xa6, 0x1f, 0xb4, 0x1b, 0x0a,
  39398. 0xfb, 0x3a, 0xba, 0xe3, 0xb7, 0x5e, 0x04, 0x14, 0x59, 0x09, 0x9a, 0x8e,
  39399. 0xc2, 0x77, 0x5a, 0x3d, 0xf1, 0x43, 0x67, 0x74, 0x78, 0xfc, 0xcd, 0x34,
  39400. 0xed, 0x35, 0x16, 0x38, 0x04, 0xe6, 0xe7, 0xd6, 0xd2, 0x90, 0x1b, 0x28,
  39401. 0xb6, 0x66, 0x1b, 0x57, 0x85, 0x5e, 0xa7, 0x9f, 0x86, 0x1a, 0x0d, 0xc3,
  39402. 0x7e, 0xed, 0xbd, 0x32, 0x8a, 0x35, 0xe1, 0xb3, 0x01, 0xdc, 0x9b, 0x44,
  39403. 0x88, 0xa1, 0x0b, 0x87, 0x6e, 0x55, 0x31, 0xb1, 0x27, 0xcb, 0x85, 0xa4,
  39404. 0x27, 0x56, 0x33, 0xb0, 0x39, 0x0d, 0xd3, 0x4b, 0xd1, 0xa2, 0x47, 0x07,
  39405. 0xc6, 0xf4, 0xe6, 0x1f, 0x88, 0x70, 0x70, 0x13, 0x7e, 0x2e, 0x17, 0x32,
  39406. 0x0a, 0x6b, 0x38, 0x34, 0xcf, 0x2f, 0x00, 0x36, 0x58, 0x8d, 0xe1, 0xdd,
  39407. 0xa7, 0x94, 0x2a, 0x8f, 0x87, 0x99, 0x67, 0x02, 0x4d, 0x5b, 0x56, 0xaf,
  39408. 0xef, 0xc4, 0x3c, 0xff, 0x72, 0x53, 0x95, 0x27, 0x03, 0x49, 0x94, 0x4f,
  39409. 0x94, 0x87, 0x1f, 0x52, 0x33, 0xed, 0xb9, 0x14, 0x7b, 0xe5, 0x6c, 0xef,
  39410. 0x7a, 0x17, 0x5a, 0xa4, 0x89, 0x2a, 0xfe, 0x68, 0xda, 0xdd, 0x48, 0xc2,
  39411. 0xf0, 0x92, 0xf4, 0xe4, 0xd6, 0xa6, 0x48, 0x08, 0x2c, 0xe8, 0xcd, 0x72,
  39412. 0xf6, 0x94, 0x3e, 0xc1, 0x82, 0xb8, 0x01, 0x58, 0xb2, 0xef, 0xef, 0xf4,
  39413. 0xcb, 0x93, 0x63, 0x2e, 0x33, 0x5b, 0xc9, 0xd6, 0x6a, 0xde, 0xad, 0xe8,
  39414. 0x1e, 0x3f, 0xa3, 0xf2, 0x35, 0x87, 0xc1, 0xc9, 0x48, 0x2f, 0x1b, 0x00,
  39415. 0xea, 0x3d, 0x04, 0x29, 0xd5, 0xc0, 0xe9, 0x1a, 0xc5, 0xce, 0x5e, 0xdb,
  39416. 0xd1, 0xee, 0x16, 0x9c, 0x05, 0x40, 0xf9, 0x21, 0x13, 0x72, 0x08, 0x39,
  39417. 0x6b, 0x63, 0x19, 0xcd, 0x6f, 0x64, 0xa0, 0xc3, 0x77, 0xb7, 0x50, 0xed,
  39418. 0xe9, 0x2d, 0xd5, 0x72, 0xea, 0xa6, 0xc1, 0x97, 0xb9, 0x6b, 0xe5, 0x81,
  39419. 0x91, 0x8e, 0xd1, 0x36, 0x11, 0xee, 0xfb, 0x2b, 0x66, 0xba, 0xe4, 0x3e,
  39420. 0xd0, 0xdd, 0x17, 0xc5, 0x24, 0x3b, 0xc3, 0x5b, 0x75, 0xfc, 0xd5, 0xb6,
  39421. 0x8c, 0xba, 0x8c, 0x66, 0xb2, 0xee, 0x40, 0x45, 0x8c, 0x23, 0xbb, 0xe0,
  39422. 0xc8, 0xd6, 0x05, 0xfd, 0x71, 0x5b, 0x24, 0xbb, 0x37, 0x65, 0x5f, 0x57,
  39423. 0x92, 0x22, 0x13, 0xb2, 0x9a, 0x70, 0x22, 0x4b, 0xbe, 0x03, 0xd1, 0x54,
  39424. 0xb0, 0x3a, 0x30, 0x50, 0x71, 0x24, 0xf7, 0x81, 0x8c, 0x20, 0x67, 0x74,
  39425. 0x5a, 0xef, 0xa1, 0x6a, 0xe3, 0xd0, 0x04, 0xd6, 0xa5, 0x6e, 0xad, 0xa7,
  39426. 0x15, 0x41, 0xf3, 0x21, 0xe8, 0xd9, 0xe6, 0xe5, 0x97, 0xbd, 0xc2, 0x1b,
  39427. 0xbb, 0xd1, 0x4e, 0x7e, 0x5a, 0xd6, 0xe4, 0x19, 0xa5, 0xe4, 0x76, 0xf4,
  39428. 0xce, 0x00, 0x94, 0x76, 0xef, 0x1b, 0xb3, 0x47, 0xb9, 0xa3, 0x32, 0xf7,
  39429. 0x45, 0x6d, 0x32, 0x73, 0x06, 0xc0, 0xb9, 0xaf, 0x9c, 0x46, 0x99, 0xbe,
  39430. 0x14, 0x06, 0xcd, 0x35, 0x7c, 0x90, 0x7c, 0xe7, 0x97, 0x0a, 0x9f, 0xb4,
  39431. 0x21, 0xff, 0xf0, 0xea, 0x83, 0xc0, 0x86, 0x68, 0x9f, 0x36, 0xb0, 0xad,
  39432. 0xe1, 0x8d, 0xc5, 0x76, 0x55, 0xb5, 0xb6, 0x7e, 0x1f, 0xa7, 0x5b, 0x26,
  39433. 0x6c, 0xb5, 0xf9, 0x54, 0x1f, 0x76, 0xc1, 0x9c, 0xfc, 0x57, 0xc8, 0x86,
  39434. 0xc1, 0x7d, 0x59, 0x55, 0x92, 0xa5, 0xb8, 0x03, 0xfa, 0xa5, 0x72, 0xd1,
  39435. 0x5c, 0x8d, 0x9b, 0x2e, 0x84, 0x07, 0x18, 0xee, 0x49, 0xc5, 0x99, 0x8e,
  39436. 0x15, 0x7c, 0xbf, 0xad, 0x8b, 0x13, 0xcd, 0x97, 0xf9, 0x3c, 0xa2, 0x89,
  39437. 0x9c, 0x9c, 0x89, 0xc9, 0x7a, 0x46, 0xb3, 0x42, 0x7b, 0xd4, 0x28, 0x0d,
  39438. 0x55, 0x63, 0x28, 0xd6, 0xc1, 0x65, 0xf5, 0x34, 0x6e, 0x38, 0x2a, 0xb4,
  39439. 0x35, 0x40, 0xed, 0x7e, 0x80, 0x61, 0x9d, 0x8f, 0x68, 0x4f, 0x74, 0x0c,
  39440. 0x30, 0x35, 0x0e, 0xb3, 0x07, 0xf4, 0x92, 0xed, 0x9c, 0x7f, 0xf5, 0xed,
  39441. 0x3e, 0x17, 0x5b, 0x6e, 0x91, 0x46, 0xa1, 0x25, 0x1d, 0x83, 0x50, 0x93,
  39442. 0x35, 0x06, 0x6c, 0x2f, 0x99, 0x8b, 0x21, 0x4c, 0x5c, 0x34, 0xb1, 0xa7,
  39443. 0x82, 0xbc, 0x70, 0x28, 0x56, 0x61, 0x29, 0x35, 0x89, 0x0b, 0x41, 0x21,
  39444. 0xf0, 0xf7, 0xff, 0x69, 0x3d, 0xa4, 0x28, 0x1e, 0x0d, 0x5d, 0xa7, 0x0e,
  39445. 0xaa, 0xd3, 0x4a, 0x95, 0x49, 0xfe, 0x35, 0x5f, 0xa9, 0xc0, 0xe4, 0xe1,
  39446. 0x9a, 0x03, 0xd4, 0xac, 0x96, 0xe3, 0xea, 0x7e, 0xa6, 0x85, 0x7e, 0xb0,
  39447. 0xb8, 0xc2, 0xe8, 0x07, 0xd6, 0xd3, 0x1a, 0x84, 0x90, 0x24, 0x04, 0xef,
  39448. 0x7c, 0x93, 0x15, 0x83, 0xea, 0xe2, 0x42, 0xc6, 0xe7, 0x13, 0x45, 0xbf,
  39449. 0x35, 0xae, 0x5d, 0x50, 0x79, 0x16, 0xbb, 0x11, 0x17, 0x1b, 0xf4, 0x08,
  39450. 0x88, 0x9d, 0x66, 0x14, 0x6a, 0xa0, 0x71, 0x76, 0x80, 0x51, 0x73, 0x7c,
  39451. 0x1d, 0xb0, 0xc1, 0xad, 0x58, 0xfb, 0xbe, 0xcf, 0x73, 0xe0, 0xd9, 0xf8,
  39452. 0xd5, 0xac, 0xd7, 0x49, 0xd9, 0xc9, 0x59, 0xbf, 0xfa, 0xf5, 0xb1, 0xd2,
  39453. 0x5a, 0x01, 0xcd, 0x8b, 0x07, 0x8b, 0x59, 0x37, 0xc0, 0x8c, 0x7d, 0xa9,
  39454. 0x71, 0x83, 0xf9, 0x7c, 0x58, 0xa9, 0x77, 0x01, 0x3d, 0x39, 0x56, 0x5c,
  39455. 0x93, 0xfe, 0x40, 0x87, 0x5a, 0x31, 0x81, 0x53, 0x8e, 0x0d, 0x99, 0x7e,
  39456. 0xdf, 0x37, 0xd9, 0xe3, 0x91, 0xb8, 0x60, 0x3a, 0x5b, 0xca, 0xe8, 0x91,
  39457. 0x56, 0x89, 0x59, 0x61, 0xc6, 0x31, 0xe2, 0x6c, 0x81, 0xda, 0xc7, 0x5c,
  39458. 0x04, 0x9d, 0xe4, 0x23, 0x12, 0x73, 0xfc, 0x48, 0xfb, 0xa5, 0xce, 0x87,
  39459. 0x37, 0x47, 0x71, 0x5c, 0xd1, 0x2a, 0x63, 0x89, 0xdc, 0x07, 0xe7, 0x7f,
  39460. 0x5d, 0x48, 0xe6, 0xd2, 0x96, 0xc6, 0x6f, 0xed, 0xee, 0x8c, 0xed, 0x5e,
  39461. 0x41, 0x38, 0xbd, 0xdf, 0x21, 0xaa, 0x9e, 0x51, 0x16, 0x22, 0x4a, 0xdc,
  39462. 0xd8, 0x12, 0xdf, 0x5a, 0x83, 0xd6, 0xd0, 0x07, 0xa4, 0x42, 0x41, 0x13,
  39463. 0xe1, 0x08, 0xc9, 0x00, 0x0f, 0x37, 0xc0, 0x7d, 0xda, 0xb2, 0x25, 0xfc,
  39464. 0xc9, 0xbc, 0xa8, 0x86, 0xcc, 0x38, 0x0e, 0x06, 0x51, 0x1b, 0x37, 0xc1,
  39465. 0x0e, 0x2a, 0x58, 0x49, 0xbc, 0x7c, 0xa7, 0xf0, 0xda, 0xd7, 0x74, 0x34,
  39466. 0xf5, 0xd8, 0x99, 0x8c, 0x94, 0x86, 0xe3, 0x1e, 0x6b, 0xf5, 0x68, 0xfa,
  39467. 0xa6, 0x69, 0x63, 0x22, 0x5a, 0x3c, 0x6f, 0x29, 0xc9, 0x40, 0xc0, 0xbe,
  39468. 0x8d, 0xb5, 0xcc, 0x82, 0x6e, 0x9d, 0xd1, 0x1f, 0x13, 0x63, 0xd8, 0x24,
  39469. 0x63, 0x38, 0x59, 0xf0, 0x4a, 0x8c, 0x0f, 0x28, 0x8a, 0x77, 0x81, 0xa2,
  39470. 0xa0, 0x23, 0x11, 0x59, 0xa9, 0x5a, 0x2d, 0x71, 0x8f, 0x82, 0xa7, 0xbd,
  39471. 0x85, 0x26, 0x4d, 0xc2, 0x2f, 0x11, 0xe8, 0xff, 0x96, 0xa1, 0x2d, 0xf2,
  39472. 0xd5, 0xf3, 0x1d, 0x54, 0xd0, 0x5f, 0x71, 0x07, 0xaf, 0x22, 0xa0, 0xcd,
  39473. 0x78, 0xb3, 0x47, 0xb1, 0x40, 0x3d, 0x6b, 0xfd, 0x10, 0x1b, 0xc6, 0x60,
  39474. 0xef, 0x5c, 0x24, 0xa3, 0x1f, 0xee, 0xc0, 0x0b, 0xed, 0x1d, 0x38, 0xc8,
  39475. 0xf2, 0x8c, 0xec, 0x5e, 0xd9, 0x70, 0x1a, 0x2b, 0x25, 0xe6, 0xed, 0xa9,
  39476. 0x0c, 0xb3, 0x78, 0xe1, 0x91, 0x01, 0x41, 0x2e, 0xfe, 0x7d, 0xbd, 0xfe,
  39477. 0xcf, 0x48, 0x6d, 0x2e, 0x05, 0x31, 0x89, 0x24, 0xc4, 0xd7, 0xc4, 0x26,
  39478. 0x2f, 0x64, 0x43, 0xa3, 0xdd, 0x56, 0x11, 0x5c, 0x65, 0x76, 0x96, 0xcc,
  39479. 0x3c, 0x12, 0x42, 0xf2, 0x6b, 0x20, 0xc2, 0xe6, 0xc3, 0x5c, 0xfa, 0x91,
  39480. 0xb1, 0xbd, 0x3b, 0xd3, 0x99, 0xde, 0x59, 0x7a, 0x34, 0x40, 0x56, 0xb0,
  39481. 0x88, 0x02, 0x19, 0xc8, 0xf9, 0xf9, 0x8f, 0xe7, 0x60, 0xfb, 0x42, 0x87,
  39482. 0x57, 0xb4, 0x42, 0xb4, 0x65, 0x94, 0x0a, 0x5f, 0xdb, 0xf5, 0x32, 0xe9,
  39483. 0x49, 0x28, 0xbe, 0xa6, 0x64, 0x0d, 0x6d, 0x08, 0x43, 0x91, 0x16, 0x7a,
  39484. 0x6c, 0xa9, 0x02, 0xe4, 0x84, 0x03, 0x39, 0x48, 0x08, 0xcc, 0xcb, 0x56,
  39485. 0xad, 0x52, 0x95, 0x9e, 0x9a, 0x2b, 0xf1, 0x6d, 0x3f, 0x4b, 0x02, 0xc6,
  39486. 0x52, 0xc7, 0x09, 0x6b, 0x3f, 0xa9, 0x60, 0xe2, 0x19, 0x5d, 0x0a, 0x61,
  39487. 0xcd, 0xc8, 0x36, 0xdb, 0x8e, 0x57, 0xd2, 0x11, 0x49, 0x1c, 0x26, 0x58,
  39488. 0x04, 0x07, 0x32, 0x2a, 0x34, 0xf0, 0x6a, 0x88, 0xcf, 0x63, 0xb7, 0xef,
  39489. 0x7e, 0x93, 0xcc, 0x64, 0x07, 0x14, 0xfa, 0x63, 0x38, 0xdd, 0xc0, 0xf0,
  39490. 0xaa, 0x56, 0xa1, 0xed, 0x16, 0xaa, 0x53, 0x8c, 0x99, 0xc0, 0xd4, 0xda,
  39491. 0x94, 0x58, 0x13, 0xd9, 0x5f, 0x98, 0x9a, 0xa1, 0x57, 0xbd, 0x89, 0xca,
  39492. 0x9d, 0x3e, 0xdf, 0x75, 0x26, 0x29, 0x0f, 0xb2, 0x33, 0x4b, 0x83, 0xb3,
  39493. 0x99, 0x1f, 0x06, 0x5d, 0x10, 0xf5, 0x1c, 0x75, 0x97, 0xec, 0x5b, 0x87,
  39494. 0xc7, 0xf1, 0xd8, 0xbd, 0x0e, 0x4c, 0x1a, 0xb0, 0x59, 0x3b, 0x27, 0x73,
  39495. 0xdc, 0xde, 0xca, 0x0c, 0x2e, 0x1f, 0x42, 0x7f, 0xd8, 0x0f, 0x9b, 0x3f,
  39496. 0x49, 0x3f, 0x63, 0x7d, 0x71, 0xe3, 0x77, 0x79, 0xcc, 0x9c, 0xbf, 0xff,
  39497. 0x23, 0xa9, 0x74, 0xa2, 0xda, 0xb7, 0xca, 0x86, 0x7f, 0x12, 0xc1, 0x1b,
  39498. 0x41, 0x35, 0xb5, 0xc7, 0x10, 0x09, 0xc0, 0xa2, 0x1b, 0x41, 0x31, 0x5e,
  39499. 0x6c, 0x35, 0xb5, 0x63, 0x13, 0x19, 0x61, 0x8e, 0xbd, 0x89, 0xf6, 0x0a,
  39500. 0xbd, 0x16, 0x15, 0xd8, 0xfa, 0xcc, 0x9f, 0x97, 0x02, 0x8f, 0x1b, 0x34,
  39501. 0x40, 0xbc, 0x4a, 0xb1, 0x39, 0x12, 0xf8, 0x66, 0xda, 0x34, 0x03, 0xf2,
  39502. 0x5c, 0x33, 0x9c, 0x63, 0x0b, 0xb6, 0x8f, 0xca, 0x81, 0xa2, 0x4a, 0x43,
  39503. 0xe7, 0xe7, 0x66, 0x41, 0x45, 0x6b, 0x7c, 0xd1, 0x1d, 0xbc, 0x4f, 0x91,
  39504. 0xab, 0x24, 0x0b, 0x9f, 0x60, 0x47, 0x36, 0x04, 0x8b, 0x72, 0xb6, 0x65,
  39505. 0x35, 0xfc, 0xbf, 0xc9, 0x26, 0xaf, 0x84, 0x04, 0x30, 0x32, 0x02, 0xc0,
  39506. 0x94, 0x98, 0xbc, 0x17, 0x33, 0x99, 0xac, 0xb1, 0x4e, 0xdd, 0xf0, 0x46,
  39507. 0x68, 0x6a, 0xac, 0x6d, 0xdb, 0x85, 0xfd, 0xc6, 0x3b, 0xc8, 0x93, 0x89,
  39508. 0xbf, 0xd7, 0xd9, 0x94, 0xe4, 0xa4, 0x37, 0xb9, 0x67, 0x52, 0x84, 0xcf,
  39509. 0x88, 0xba, 0x01, 0x8b, 0xe4, 0xd4, 0x3e, 0xde, 0x94, 0xa1, 0xa9, 0xd8,
  39510. 0x15, 0xb5, 0x6e, 0xa0, 0x62, 0x92, 0x5c, 0xb1, 0x1b, 0xbf, 0x4f, 0xaf,
  39511. 0xf5, 0x99, 0x35, 0xce, 0x7d, 0xa9, 0x4b, 0xa8, 0x60, 0x31, 0xf5, 0x0a,
  39512. 0x83, 0x58, 0xf5, 0x83, 0xde, 0xb2, 0xfe, 0xf3, 0x12, 0x08, 0x3d, 0xe3,
  39513. 0x14, 0x89, 0x17, 0x93, 0x5c, 0x87, 0xe4, 0x89, 0xcb, 0xb7, 0x67, 0x3e,
  39514. 0xea, 0x0e, 0x08, 0x57, 0xf1, 0xca, 0xe0, 0x18, 0xd7, 0xae, 0x5f, 0x9e,
  39515. 0x62, 0x5c, 0xd7, 0x6a, 0x2f, 0xd6, 0x30, 0x67, 0xfb, 0x5e, 0xed, 0xcf,
  39516. 0xa9, 0x88, 0x04, 0x0a, 0xf2, 0x62, 0x50, 0xc5, 0x39, 0xc6, 0xa1, 0x3c,
  39517. 0xe4, 0x9a, 0x81, 0x55, 0x96, 0xca, 0x60, 0xb2, 0x53, 0x62, 0xee, 0xa1,
  39518. 0x1d, 0xfc, 0xd9, 0x5c, 0x51, 0xbf, 0x55, 0x65, 0x1d, 0x13, 0x2a, 0x13,
  39519. 0x58, 0xa3, 0x18, 0x52, 0x6b, 0xb4, 0xae, 0x60, 0x1c, 0x26, 0x3e, 0xb1,
  39520. 0x4c, 0xb1, 0x72, 0x1b, 0x8a, 0x4c, 0xaa, 0xb5, 0x5b, 0x8a, 0x3b, 0x2f,
  39521. 0x1f, 0xc3, 0x29, 0x41, 0xe6, 0x6d, 0xd7, 0x96, 0x26, 0xdd, 0x37, 0x67,
  39522. 0x4f, 0x9d, 0x31, 0xc6, 0x54, 0x51, 0xaa, 0xba, 0x73, 0xae, 0xd2, 0x00,
  39523. 0x0b, 0x05, 0x98, 0x73, 0xd6, 0x9c, 0xb4, 0x2e, 0x23, 0xd0, 0xc3, 0xac,
  39524. 0x46, 0x6f, 0x3e, 0x05, 0x43, 0xf8, 0x96, 0xa0, 0xe0, 0xfe, 0x17, 0x3f,
  39525. 0xfa, 0xc2, 0xc3, 0xf6, 0x1a, 0x46, 0xd0, 0x05, 0x53, 0x0e, 0xea, 0xd8,
  39526. 0xba, 0xa3, 0xab, 0xb6, 0x58, 0xd1, 0x40, 0x1c, 0x97, 0x38, 0xd4, 0x77,
  39527. 0x58, 0x03, 0xf5, 0x8a, 0xc7, 0x48, 0x19, 0x71, 0x71, 0xb5, 0x4b, 0x08,
  39528. 0x85, 0x35, 0x1c, 0xdf, 0xbd, 0xa9, 0xc9, 0xd1, 0x40, 0x62, 0xa3, 0xd6,
  39529. 0x3b, 0xa1, 0xf7, 0x4e, 0xc6, 0xfe, 0xc4, 0x07, 0x2f, 0xf5, 0xc9, 0x0c,
  39530. 0xb6, 0xa0, 0xb3, 0x25, 0x3e, 0x2a, 0x07, 0xe3, 0x63, 0xe3, 0x9e, 0x8d,
  39531. 0x0d, 0x7a, 0x70, 0x1e, 0x65, 0x95, 0x47, 0x37, 0xa8, 0xd2, 0x35, 0x09,
  39532. 0x09, 0x70, 0xf5, 0xc9, 0xc9, 0x30, 0x95, 0xd9, 0xf2, 0x5d, 0x10, 0x3c,
  39533. 0xc3, 0x66, 0x66, 0xb6, 0xdc, 0x14, 0xf6, 0x91, 0xc2, 0x7b, 0x4b, 0x71,
  39534. 0x42, 0xf9, 0x35, 0xe7, 0x08, 0x1e, 0xb6, 0x9a, 0x5c, 0x0e, 0x8b, 0x41,
  39535. 0x44, 0x7f, 0xad, 0xca, 0x8a, 0x4b, 0x6a, 0x02, 0x81, 0x96, 0xe7, 0xe1,
  39536. 0xb0, 0x5b, 0xaf, 0xf2, 0x17, 0x44, 0x7f, 0xd1, 0x49, 0x77, 0xfd, 0x07,
  39537. 0x59, 0x53, 0x8e, 0x51, 0xac, 0x0f, 0x0c, 0xb4, 0xa3, 0xf6, 0x24, 0x16,
  39538. 0x47, 0xf3, 0xa4, 0x36, 0x17, 0x3e, 0x01, 0x1e, 0xf1, 0xec, 0x78, 0x4a,
  39539. 0xcb, 0xbd, 0x2a, 0xfd, 0x01, 0xdd, 0xa5, 0xad, 0x7b, 0xef, 0x5e, 0x56,
  39540. 0xb2, 0x60, 0xb4, 0xf2, 0x27, 0xc8, 0x9b, 0x5b, 0x31, 0x49, 0x54, 0xbc,
  39541. 0x69, 0x9b, 0xc6, 0x1a, 0x79, 0xe7, 0xd4, 0x46, 0xc8, 0x50, 0xc3, 0xaa,
  39542. 0xfc, 0xb5, 0x28, 0x87, 0x1e, 0xa0, 0x0c, 0xc6, 0x1a, 0xa7, 0x34, 0xd6,
  39543. 0xbb, 0x9d, 0x9c, 0x0d, 0x90, 0x6f, 0x1a, 0x3c, 0xdc, 0x3b, 0x95, 0xc4,
  39544. 0x38, 0x25, 0x7a, 0xc6, 0x46, 0x82, 0x9f, 0x68, 0xca, 0x6a, 0x63, 0xa7,
  39545. 0x99, 0xfe, 0x64, 0xe6, 0x6f, 0x11, 0xcd, 0x2c, 0x76, 0x1e, 0xe6, 0x08,
  39546. 0xb8, 0x33, 0x64, 0x43, 0x51, 0xbd, 0x52, 0xf7, 0x05, 0x06, 0xd5, 0xcc,
  39547. 0x6a, 0xde, 0x1a, 0xa2, 0xbe, 0xf8, 0x8c, 0x44, 0x5e, 0x2d, 0xc2, 0x28,
  39548. 0xcd, 0x9a, 0x53, 0x04, 0x96, 0xcc, 0x1e, 0xbb, 0x96, 0x07, 0xc9, 0x17,
  39549. 0x04, 0xf8, 0xd8, 0xd9, 0xdd, 0x35, 0x35, 0x3d, 0x53, 0x30, 0x60, 0xb3,
  39550. 0x87, 0x5d, 0xf3, 0xe5, 0xa7, 0x20, 0x30, 0x9d, 0xb0, 0x5b, 0xc4, 0x36,
  39551. 0xf7, 0xd7, 0xb6, 0x3e, 0x44, 0x98, 0x99, 0xe7, 0xc3, 0x29, 0xcb, 0x70,
  39552. 0xc4, 0x91, 0x8b, 0xfc, 0x63, 0x60, 0x29, 0x95, 0xeb, 0x61, 0x7f, 0xdf,
  39553. 0xf7, 0x3a, 0x69, 0x3a, 0xeb, 0xa1, 0x73, 0x1d, 0x13, 0x18, 0x29, 0x2c,
  39554. 0x89, 0x82, 0x56, 0x42, 0xe7, 0xa3, 0xba, 0xe9, 0x59, 0x2e, 0xfd, 0xff,
  39555. 0xb6, 0xf7, 0xbd, 0x2a, 0xc9, 0xff, 0x4c, 0x63, 0xef, 0x54, 0x63, 0x82,
  39556. 0x7c, 0xa5, 0x11, 0x44, 0xc7, 0x68, 0xf5, 0x7b, 0x44, 0x2c, 0xee, 0xab,
  39557. 0xa3, 0x84, 0x5a, 0x99, 0x28, 0x98, 0x97, 0x2e, 0x8b, 0x07, 0x09, 0x6c,
  39558. 0xea, 0xc1, 0x81, 0x0b, 0xe0, 0xc4, 0xb7, 0xc2, 0x73, 0xbe, 0x8b, 0x72,
  39559. 0xf8, 0xc9, 0x8d, 0x50, 0x28, 0xf2, 0x95, 0x54, 0x8a, 0x3b, 0x23, 0x86,
  39560. 0xc4, 0xe8, 0xe8, 0xe5, 0x45, 0x0d, 0xdf, 0xa3, 0xe6, 0x00, 0x71, 0xe8,
  39561. 0x20, 0xd2, 0x6d, 0x22, 0x23, 0xaf, 0x37, 0x04, 0x55, 0x05, 0x8d, 0xc9,
  39562. 0x38, 0x38, 0x12, 0x4c, 0x9f, 0x28, 0x56, 0x14, 0x76, 0xe5, 0x10, 0x54,
  39563. 0xd9, 0x68, 0xca, 0xc3, 0x97, 0x9f, 0xd2, 0x25, 0x2c, 0x0d, 0xa0, 0xff,
  39564. 0xea, 0xab, 0x61, 0xd2, 0xb2, 0x06, 0xc2, 0x93, 0xfd, 0x5a, 0xfe, 0xe3,
  39565. 0x98, 0xbf, 0x37, 0x2e, 0xa5, 0x74, 0x56, 0xd0, 0x7a, 0x5a, 0x23, 0x3b,
  39566. 0xd2, 0xa0, 0x1f, 0x4b, 0xeb, 0x7f, 0x5a, 0xc5, 0x51, 0x79, 0xf6, 0x95,
  39567. 0x19, 0x50, 0xb1, 0x6a, 0x80, 0xcb, 0xcf, 0x19, 0xa4, 0x67, 0xf4, 0x08,
  39568. 0x0f, 0x6a, 0xd9, 0x3f, 0x15, 0x96, 0x2c, 0x6d, 0xd5, 0x69, 0x7a, 0x56,
  39569. 0x4d, 0x17, 0xc8, 0xcb, 0xba, 0x9b, 0x6e, 0x65, 0xa2, 0x3d, 0x66, 0xed,
  39570. 0xea, 0xe2, 0x54, 0x88, 0x6c, 0xc1, 0x1a, 0x11, 0xde, 0x4e, 0x0c, 0x8a,
  39571. 0x42, 0x04, 0xe1, 0x77, 0xc3, 0x0c, 0xff, 0x10, 0x7d, 0x4a, 0x45, 0x3f,
  39572. 0xb8, 0x40, 0xf9, 0x75, 0x76, 0x9f, 0x65, 0x42, 0x2f, 0x78, 0x5b, 0x0b,
  39573. 0x32, 0xbc, 0x45, 0xfc, 0xd4, 0x29, 0x49, 0x34, 0x76, 0xda, 0x5f, 0xe8,
  39574. 0x39, 0x35, 0x9e, 0xba, 0x7f, 0x19, 0x7e, 0x14, 0xe6, 0x71, 0x9c, 0x72,
  39575. 0x6a, 0xce, 0xcc, 0xa6, 0x72, 0x73, 0x3f, 0x4e, 0x9b, 0x9e, 0x94, 0x0c,
  39576. 0xce, 0x00, 0x15, 0xb4, 0x50, 0xff, 0xcf, 0xcd, 0x78, 0xd3, 0x08, 0x0e,
  39577. 0x95, 0x48, 0x24, 0x13, 0x16, 0x54, 0xb4, 0xe0, 0xa9, 0x29, 0xa3, 0x05,
  39578. 0x77, 0x2f, 0x5d, 0x47, 0x6a, 0xa5, 0xb0, 0x4e, 0xf3, 0xa9, 0x4a, 0x82,
  39579. 0xb9, 0x2c, 0x26, 0x07, 0x9c, 0x33, 0xc6, 0x68, 0xc2, 0xe0, 0xc0, 0x7d,
  39580. 0x70, 0x48, 0x74, 0xb9, 0xf5, 0x1e, 0x6c, 0x15, 0x7f, 0xba, 0xe5, 0xa1,
  39581. 0xb4, 0x36, 0x41, 0x20, 0xf4, 0x2d, 0x97, 0x27, 0x0b, 0x10, 0x30, 0x57,
  39582. 0x7f, 0x38, 0x66, 0xe1, 0xc4, 0xf6, 0xa4, 0xc9, 0x8d, 0xbc, 0x2b, 0x4f,
  39583. 0x14, 0xb3, 0xf0, 0x1e, 0x80, 0x70, 0xc0, 0x0f, 0x69, 0x06, 0xe7, 0x95,
  39584. 0xd1, 0x53, 0x65, 0x49, 0x1c, 0xa8, 0xfa, 0x9e, 0x2b, 0xcc, 0x33, 0x71,
  39585. 0x76, 0xa4, 0x0b, 0x4a, 0xc7, 0xea, 0xa0, 0xfa, 0x1b, 0x2b, 0xfb, 0xa5,
  39586. 0x59, 0x06, 0x2a, 0xef, 0x4b, 0xbf, 0x05, 0x4b, 0x87, 0x70, 0x3c, 0xde,
  39587. 0xc7, 0xb2, 0x4f, 0xf2, 0x5b, 0x1a, 0xbe, 0xda, 0x04, 0x31, 0x57, 0xff,
  39588. 0xf2, 0xa5, 0x43, 0x12, 0xff, 0x8d, 0xf4, 0x99, 0x05, 0xe1, 0x34, 0xa9,
  39589. 0xb9, 0x0a, 0xb3, 0x1f, 0x3d, 0x6d, 0x0d, 0xb7, 0xd3, 0x35, 0x0b, 0x04,
  39590. 0x44, 0x77, 0x60, 0xc0, 0x96, 0x99, 0x7b, 0xa8, 0x8e, 0x79, 0x4a, 0x96,
  39591. 0x24, 0xef, 0xb1, 0xf4, 0x8a, 0x2f, 0x3e, 0x08, 0xf3, 0x3d, 0xf2, 0xfe,
  39592. 0x5f, 0x0a, 0xf7, 0x0a, 0xf5, 0xd8, 0xf2, 0xa0, 0x1b, 0xe7, 0x9e, 0xc9,
  39593. 0x0b, 0xcf, 0x58, 0x97, 0x92, 0x90, 0xad, 0x3d, 0xfc, 0x42, 0xc1, 0x7f,
  39594. 0x39, 0xe8, 0xd1, 0x35, 0x14, 0x8a, 0xb3, 0x77, 0xb1, 0xa9, 0xdb, 0xb4,
  39595. 0x3a, 0x3d, 0xeb, 0x59, 0x0b, 0x5b, 0x3a, 0x63, 0x54, 0x70, 0xda, 0xf0,
  39596. 0xf0, 0xb9, 0xe6, 0x07, 0x69, 0x27, 0x9d, 0xc6, 0xb6, 0x00, 0x2d, 0xd6,
  39597. 0xc7, 0xd7, 0x2e, 0xf8, 0x9c, 0xfe, 0x4c, 0xfb, 0xc0, 0x7b, 0xbf, 0xa2,
  39598. 0x25, 0xb8, 0x2a, 0x5c, 0x06, 0xca, 0x12, 0x2c, 0x96, 0xa4, 0x27, 0xa6,
  39599. 0x73, 0x0b, 0xb8, 0x42, 0x93, 0x51, 0x87, 0xfe, 0xe6, 0x8f, 0xca, 0x00,
  39600. 0x53, 0xdc, 0xc0, 0x38, 0x03, 0x9e, 0x66, 0x13, 0x84, 0x68, 0xe7, 0x04,
  39601. 0x93, 0x79, 0x0c, 0x3e, 0x4c, 0x90, 0xe2, 0xf7, 0x81, 0x15, 0x49, 0x05,
  39602. 0xe1, 0x8f, 0xe6, 0xfc, 0xc8, 0x40, 0xae, 0x3d, 0x7a, 0x16, 0xec, 0xc6,
  39603. 0x39, 0xa5, 0x04, 0x95, 0x35, 0xac, 0xdd, 0x0d, 0x19, 0xd6, 0xa9, 0xd9,
  39604. 0xd2, 0x53, 0x71, 0x31, 0x38, 0xa2, 0xf1, 0x9c, 0x13, 0x2c, 0x8c, 0x21,
  39605. 0x9c, 0x3a, 0x1b, 0xf2, 0xd8, 0x4c, 0xeb, 0xe9, 0x8b, 0x27, 0x52, 0xd3,
  39606. 0x6c, 0x01, 0xc0, 0x60, 0x32, 0x8c, 0x6e, 0xfb, 0xd6, 0xd6, 0x1b, 0xc6,
  39607. 0x93, 0xff, 0xdc, 0xdb, 0x38, 0xf5, 0x0e, 0xd5, 0x15, 0xcd, 0x65, 0x76,
  39608. 0x78, 0x42, 0x13, 0x37, 0x6b, 0x2e, 0xe8, 0xe2, 0x54, 0x4d, 0x45, 0x34,
  39609. 0x73, 0x1b, 0x61, 0x35, 0x2c, 0xf7, 0x20, 0x3e, 0xe9, 0x7c, 0xf0, 0xf3,
  39610. 0xba, 0x41, 0xfc, 0x49, 0xe4, 0x5d, 0xd4, 0xb8, 0x07, 0x15, 0x7b, 0x16,
  39611. 0xc7, 0x7f, 0x78, 0xef, 0xd6, 0x53, 0x3f, 0xe4, 0xa6, 0x33, 0xcf, 0xcc,
  39612. 0x78, 0x53, 0x0c, 0x59, 0xf7, 0x28, 0xa5, 0x83, 0x2b, 0x5a, 0xd3, 0xd6,
  39613. 0xb7, 0xb2, 0xd1, 0x73, 0x63, 0xa9, 0xad, 0x16, 0xf2, 0xed, 0x48, 0x6e,
  39614. 0x88, 0x22, 0xbd, 0x16, 0x9d, 0x6a, 0xc2, 0x48, 0x83, 0xdf, 0x40, 0xb7,
  39615. 0x0a, 0x50, 0x23, 0x3d, 0x58, 0x50, 0x00, 0x02, 0x04, 0xd2, 0x31, 0x72,
  39616. 0x28, 0x7b, 0x10, 0x96, 0xe0, 0xe7, 0x3f, 0xe0, 0xd0, 0x61, 0x70, 0x5c,
  39617. 0x0a, 0xdb, 0xc0, 0x7b, 0xea, 0xef, 0xba, 0xc0, 0x90, 0xe0, 0xf9, 0x0e,
  39618. 0x83, 0x8c, 0x3b, 0x05, 0x2b, 0xb6, 0xcb, 0xbb, 0x37, 0xa1, 0xd3, 0x28,
  39619. 0x02, 0x40, 0xe3, 0x76, 0xbf, 0x27, 0x0b, 0x4f, 0x82, 0xb9, 0x22, 0xee,
  39620. 0x0b, 0x3a, 0xcb, 0xcc, 0x56, 0x13, 0x51, 0xb8, 0xb6, 0x2d, 0xd3, 0x6c,
  39621. 0x96, 0x10, 0xd9, 0x51, 0x24, 0x7b, 0x2b, 0xb8, 0x7b, 0xbd, 0x8d, 0xd9,
  39622. 0xf2, 0x50, 0x61, 0xbb, 0x0c, 0xb7, 0x71, 0x65, 0x3a, 0x25, 0x18, 0x09,
  39623. 0x1a, 0x9d, 0x41, 0xf4, 0xdb, 0x5a, 0x1c, 0x61, 0x0a, 0xbb, 0x43, 0x27,
  39624. 0x8a, 0xa8, 0x83, 0x60, 0x8c, 0x5d, 0x4c, 0x9b, 0xa9, 0xe5, 0xa7, 0x67,
  39625. 0x99, 0x98, 0xdc, 0x7a, 0x3a, 0x55, 0x0d, 0x25, 0x69, 0x47, 0x21, 0xb1,
  39626. 0xd7, 0x0c, 0x0c, 0x43, 0x58, 0xc9, 0xbf, 0x74, 0x91, 0x1b, 0x2b, 0xf3,
  39627. 0x29, 0x8d, 0x10, 0x41, 0xaf, 0xdd, 0x42, 0x0a, 0x71, 0xe3, 0xb8, 0x4d,
  39628. 0x3a, 0xf3, 0x9c, 0x5a, 0x46, 0x4e, 0x70, 0xbe, 0xdb, 0x0d, 0x03, 0xee,
  39629. 0xcb, 0xfb, 0x61, 0x45, 0xbd, 0x25, 0xb4, 0x72, 0xd1, 0x51, 0x03, 0x19,
  39630. 0x82, 0x53, 0x83, 0x18, 0xab, 0xa3, 0x6c, 0x9e, 0xa2, 0xe9, 0x15, 0xb1,
  39631. 0x74, 0x61, 0xa1, 0xaf, 0x09, 0x4b, 0x4a, 0x34, 0x9b, 0xd0, 0xd2, 0x80,
  39632. 0x43, 0xd9, 0x90, 0x53, 0x71, 0x38, 0xb9, 0x80, 0x58, 0x1b, 0x9f, 0x9e,
  39633. 0xfe, 0x07, 0x1b, 0x33, 0x24, 0xb2, 0x58, 0x7f, 0x01, 0xbe, 0xe8, 0x25,
  39634. 0x53, 0x08, 0x06, 0x77, 0x7d, 0x5a, 0x16, 0x83, 0x67, 0x91, 0x0b, 0xa2,
  39635. 0xd2, 0x1e, 0x5f, 0x9c, 0x39, 0xda, 0x57, 0xbc, 0x67, 0xc5, 0x39, 0xbe,
  39636. 0xb9, 0x73, 0x03, 0x19, 0x97, 0x34, 0x4f, 0x1e, 0x6b, 0x4d, 0x87, 0xef,
  39637. 0x79, 0x4f, 0xd1, 0xdd, 0x80, 0x13, 0xbe, 0x3b, 0x0f, 0xea, 0x77, 0x9a,
  39638. 0x1a, 0x46, 0x63, 0xc5, 0x2f, 0x93, 0xfe, 0x18, 0x71, 0xfb, 0x70, 0xbf,
  39639. 0x85, 0x3b, 0x3e, 0x54, 0xe6, 0xf8, 0xe0, 0xb9, 0xd0, 0x9d, 0xf5, 0x2b,
  39640. 0x12, 0x22, 0x39, 0x6a, 0x8d, 0x13, 0xa1, 0x3a, 0x95, 0xd0, 0xe7, 0x07,
  39641. 0xa4, 0x2c, 0x33, 0xba, 0x43, 0x1d, 0xd8, 0xb5, 0xd0, 0x8e, 0x6c, 0x85,
  39642. 0x6f, 0xf8, 0x8f, 0xd3, 0x72, 0x65, 0xc1, 0xff, 0x8f, 0xf6, 0xb5, 0x19,
  39643. 0x59, 0x34, 0xf9, 0xe8, 0xdb, 0xf3, 0x10, 0x68, 0xbd, 0xd5, 0x59, 0xf7,
  39644. 0xe5, 0xf2, 0x84, 0x98, 0x8d, 0xd6, 0x6f, 0xcc, 0xde, 0xc5, 0xee, 0xf7,
  39645. 0x16, 0xca, 0xec, 0xc4, 0x00, 0x89, 0x2e, 0x0d, 0x0d, 0xb6, 0xa8, 0xe0,
  39646. 0x9a, 0xb0, 0xe5, 0x8e, 0xb6, 0x64, 0x47, 0x7d, 0x01, 0x59, 0x8a, 0x90,
  39647. 0xa6, 0x9b, 0x2b, 0x63, 0xad, 0x70, 0xc8, 0x07, 0x36, 0x3e, 0xa9, 0x8f,
  39648. 0xd9, 0xc2, 0xf7, 0x4b, 0xec, 0x95, 0x53, 0xec, 0x6b, 0x2d, 0x1f, 0xb5,
  39649. 0x91, 0xbf, 0x9f, 0xc5, 0x85, 0x61, 0x3a, 0xc7, 0x5c, 0x15, 0x2a, 0x0b,
  39650. 0x4b, 0x3c, 0x38, 0x6d, 0xc9, 0x2c, 0x91, 0x11, 0xc6, 0x6b, 0x44, 0x71,
  39651. 0x9f, 0x89, 0xd5, 0xde, 0x27, 0x99, 0x81, 0xa2, 0x59, 0x8b, 0x57, 0x97,
  39652. 0x83, 0x46, 0x33, 0xe1, 0x8c, 0xdf, 0xcf, 0x5b, 0x6b, 0xb3, 0x0e, 0x17,
  39653. 0x1a, 0xb8, 0x7d, 0x6e, 0x71, 0xe5, 0xc8, 0x4c, 0xa9, 0xe2, 0x52, 0x81,
  39654. 0xf6, 0x2f, 0x3a, 0xef, 0x5a, 0x1b, 0x6b, 0x7b, 0x61, 0x51, 0xcb, 0xd5,
  39655. 0x7b, 0x5f, 0xf0, 0x1c, 0xb8, 0xeb, 0x9a, 0xe4, 0x0a, 0x6e, 0x53, 0x59,
  39656. 0x2e, 0x2d, 0x78, 0x27, 0xb7, 0x47, 0x35, 0x1a, 0x01, 0x25, 0x0a, 0xcc,
  39657. 0x67, 0xae, 0xda, 0xaf, 0xfe, 0x22, 0x63, 0xe8, 0xa2, 0x1c, 0x34, 0xe6,
  39658. 0x6b, 0x73, 0xcf, 0x6f, 0x3e, 0x0a, 0x4a, 0x36, 0xbc, 0xda, 0x43, 0xbc,
  39659. 0x5e, 0x9c, 0x91, 0xe4, 0x8b, 0x34, 0x2e, 0x09, 0x87, 0x69, 0x96, 0x93,
  39660. 0xb4, 0xff, 0x97, 0xbc, 0x4e, 0xd6, 0xa2, 0xb4, 0x16, 0x78, 0x7c, 0x62,
  39661. 0xd0, 0x78, 0x3f, 0x37, 0xdb, 0xf2, 0x92, 0xad, 0x9b, 0x51, 0x77, 0x08,
  39662. 0x19, 0xd2, 0x09, 0x12, 0xf7, 0x52, 0xe8, 0xc8, 0xb2, 0xfb, 0x6f, 0xcd,
  39663. 0x05, 0x5b, 0xd2, 0x8e, 0x0d, 0x6e, 0x0c, 0x16, 0x5b, 0x8a, 0xc2, 0x09,
  39664. 0x13, 0x3b, 0x69, 0x85, 0xbd, 0xc0, 0xcc, 0x2b, 0x48, 0x65, 0xa7, 0xc1,
  39665. 0xc3, 0xe0, 0xea, 0x14, 0x67, 0x6f, 0xa4, 0xb8, 0xc6, 0xf0, 0x12, 0x3e,
  39666. 0x96, 0x0d, 0x23, 0x2b, 0x37, 0x87, 0x8d, 0xc8, 0xf7, 0x00, 0x00, 0x00,
  39667. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  39668. 0x00, 0x00, 0x00, 0x03, 0x0b, 0x13, 0x1a, 0x1d, 0x25
  39669. };
  39670. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  39671. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_65_draft_sig[] = {
  39672. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  39673. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  39674. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  39675. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  39676. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  39677. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  39678. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  39679. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  39680. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  39681. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  39682. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  39683. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  39684. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  39685. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  39686. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  39687. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  39688. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  39689. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  39690. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  39691. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  39692. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  39693. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  39694. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  39695. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  39696. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  39697. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  39698. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  39699. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  39700. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  39701. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  39702. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  39703. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  39704. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  39705. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  39706. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  39707. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  39708. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  39709. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  39710. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  39711. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  39712. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  39713. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  39714. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  39715. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  39716. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  39717. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  39718. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  39719. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  39720. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  39721. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  39722. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  39723. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  39724. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  39725. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  39726. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  39727. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  39728. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  39729. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  39730. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  39731. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  39732. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  39733. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  39734. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  39735. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  39736. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  39737. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  39738. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  39739. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  39740. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  39741. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  39742. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  39743. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  39744. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  39745. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  39746. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  39747. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  39748. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  39749. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  39750. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  39751. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  39752. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  39753. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  39754. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  39755. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  39756. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  39757. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  39758. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  39759. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  39760. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  39761. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  39762. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  39763. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  39764. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  39765. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  39766. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  39767. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  39768. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  39769. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  39770. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  39771. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  39772. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  39773. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  39774. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  39775. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  39776. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  39777. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  39778. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  39779. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  39780. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  39781. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  39782. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  39783. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  39784. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  39785. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  39786. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  39787. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  39788. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  39789. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  39790. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  39791. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  39792. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  39793. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  39794. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  39795. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  39796. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  39797. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  39798. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  39799. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  39800. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  39801. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  39802. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  39803. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  39804. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  39805. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  39806. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  39807. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  39808. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  39809. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  39810. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  39811. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  39812. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  39813. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  39814. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  39815. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  39816. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  39817. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  39818. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  39819. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  39820. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  39821. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  39822. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  39823. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  39824. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  39825. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  39826. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  39827. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  39828. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  39829. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  39830. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  39831. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  39832. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  39833. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  39834. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  39835. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  39836. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  39837. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  39838. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  39839. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  39840. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  39841. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  39842. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  39843. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  39844. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  39845. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  39846. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  39847. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  39848. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  39849. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  39850. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  39851. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  39852. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  39853. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  39854. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  39855. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  39856. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  39857. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  39858. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  39859. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  39860. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  39861. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  39862. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  39863. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  39864. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  39865. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  39866. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  39867. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  39868. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  39869. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  39870. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  39871. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  39872. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  39873. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  39874. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  39875. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  39876. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  39877. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  39878. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  39879. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  39880. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  39881. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  39882. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  39883. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  39884. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  39885. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  39886. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  39887. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  39888. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  39889. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  39890. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  39891. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  39892. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  39893. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  39894. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  39895. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  39896. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  39897. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  39898. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  39899. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  39900. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  39901. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  39902. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  39903. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  39904. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  39905. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  39906. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  39907. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  39908. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  39909. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  39910. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  39911. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  39912. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  39913. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  39914. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  39915. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  39916. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  39917. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  39918. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  39919. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  39920. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  39921. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  39922. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  39923. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  39924. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  39925. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  39926. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  39927. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  39928. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  39929. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  39930. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  39931. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  39932. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  39933. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  39934. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  39935. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  39936. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  39937. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  39938. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  39939. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  39940. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  39941. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  39942. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  39943. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  39944. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  39945. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  39946. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  39947. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  39948. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  39949. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  39950. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  39951. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  39952. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  39953. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  39954. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  39955. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  39956. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  39957. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  39958. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  39959. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  39960. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  39961. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  39962. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  39963. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  39964. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  39965. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  39966. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  39967. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  39968. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  39969. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  39970. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  39971. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  39972. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  39973. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  39974. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  39975. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  39976. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  39977. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  39978. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  39979. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  39980. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  39981. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  39982. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  39983. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  39984. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  39985. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  39986. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  39987. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  39988. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  39989. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  39990. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  39991. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  39992. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  39993. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  39994. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  39995. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  39996. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  39997. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  39998. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  39999. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  40000. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  40001. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  40002. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28
  40003. };
  40004. #endif
  40005. wc_test_ret_t ret;
  40006. ret = dilithium_param_vfy_test(WC_ML_DSA_65, ml_dsa_65_pub_key,
  40007. (word32)sizeof(ml_dsa_65_pub_key), ml_dsa_65_sig,
  40008. (word32)sizeof(ml_dsa_65_sig));
  40009. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40010. if (ret == 0) {
  40011. ret = dilithium_param_vfy_test(WC_ML_DSA_65_DRAFT,
  40012. ml_dsa_65_draft_pub_key, (word32)sizeof(ml_dsa_65_draft_pub_key),
  40013. ml_dsa_65_draft_sig, (word32)sizeof(ml_dsa_65_draft_sig));
  40014. }
  40015. #endif
  40016. return ret;
  40017. }
  40018. #endif
  40019. #ifndef WOLFSSL_NO_ML_DSA_87
  40020. static wc_test_ret_t dilithium_param_87_vfy_test(void)
  40021. {
  40022. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_pub_key[] = {
  40023. 0x8a, 0x66, 0xe3, 0x6e, 0x3c, 0x11, 0x70, 0x9f, 0x82, 0xdd, 0xeb, 0x9e,
  40024. 0xc0, 0xd7, 0x25, 0x87, 0x0c, 0x65, 0x07, 0x9d, 0x47, 0x39, 0x5d, 0x04,
  40025. 0x42, 0x5c, 0xd6, 0x0a, 0xdc, 0x39, 0x44, 0x04, 0xd9, 0x79, 0x43, 0x87,
  40026. 0x98, 0x64, 0x88, 0x82, 0x3a, 0x31, 0xbd, 0xec, 0x66, 0xcb, 0x01, 0x90,
  40027. 0xf9, 0x85, 0xcc, 0xde, 0x54, 0x69, 0x7d, 0x84, 0xb3, 0x84, 0x3c, 0x42,
  40028. 0x0d, 0x09, 0x63, 0xdb, 0xe6, 0x5d, 0xc2, 0x8a, 0xcf, 0xe1, 0xf4, 0x86,
  40029. 0x13, 0x05, 0x09, 0x9a, 0x4d, 0x05, 0xd4, 0x31, 0xe7, 0x27, 0x39, 0xfd,
  40030. 0x3a, 0xdb, 0x63, 0x9f, 0x1c, 0x67, 0x0b, 0x01, 0xec, 0xf9, 0xff, 0xf3,
  40031. 0xda, 0xa9, 0xf4, 0x9a, 0x59, 0x52, 0x76, 0xc2, 0xd2, 0xd5, 0xdd, 0x8d,
  40032. 0xb1, 0xa2, 0xef, 0xb3, 0x73, 0x99, 0xe3, 0xcd, 0x1c, 0xf5, 0xca, 0x6e,
  40033. 0x39, 0xfa, 0x26, 0x83, 0x45, 0xe7, 0xd0, 0x9c, 0x1b, 0xf7, 0xb2, 0x64,
  40034. 0xf1, 0x70, 0x00, 0x10, 0xc0, 0x7c, 0x7f, 0xb2, 0x32, 0xce, 0x6d, 0x71,
  40035. 0xa5, 0x43, 0x7c, 0x40, 0x71, 0x09, 0x54, 0x74, 0xac, 0xb5, 0xeb, 0xe0,
  40036. 0x04, 0x02, 0xe5, 0x82, 0x4d, 0x5a, 0x85, 0x1e, 0x19, 0x86, 0x39, 0x33,
  40037. 0x92, 0x2f, 0xa9, 0xa8, 0x10, 0xd2, 0x31, 0x60, 0x16, 0x08, 0x99, 0xe3,
  40038. 0x2c, 0x93, 0x13, 0xc4, 0x4b, 0x10, 0xe0, 0x42, 0xca, 0x3f, 0x32, 0xa7,
  40039. 0xa4, 0xd2, 0xfc, 0x9c, 0x93, 0xb6, 0x5f, 0xe2, 0x5b, 0x6e, 0x40, 0x0c,
  40040. 0x63, 0xf8, 0xf8, 0xe1, 0x2d, 0xcd, 0x86, 0x07, 0x79, 0xdb, 0x61, 0xad,
  40041. 0x24, 0xfd, 0x1e, 0x66, 0x3e, 0x8d, 0x76, 0xba, 0x98, 0x8e, 0x94, 0xc7,
  40042. 0x57, 0xb1, 0x65, 0xce, 0x4f, 0x97, 0xfa, 0x34, 0x7c, 0x97, 0x6b, 0xcd,
  40043. 0x3c, 0x42, 0x81, 0xa4, 0xd1, 0x75, 0xeb, 0x6d, 0x0c, 0x31, 0x0e, 0x6f,
  40044. 0xd5, 0x75, 0xe7, 0xff, 0x83, 0xdd, 0x7a, 0x4d, 0x83, 0x67, 0xa7, 0x4b,
  40045. 0xc1, 0x74, 0xad, 0x37, 0x38, 0x99, 0xe0, 0xf5, 0x5a, 0x44, 0x36, 0xa2,
  40046. 0x20, 0x2b, 0xfc, 0xc9, 0xfa, 0x68, 0xcb, 0xf0, 0x6f, 0x0a, 0x46, 0x1d,
  40047. 0xb5, 0xca, 0x5b, 0x96, 0x1b, 0x3a, 0xaf, 0x7d, 0x01, 0x7a, 0xd2, 0x09,
  40048. 0xcc, 0xd4, 0xe4, 0xb1, 0x49, 0x34, 0x56, 0x68, 0x9c, 0x0f, 0x23, 0xe9,
  40049. 0xb3, 0x4b, 0xed, 0x3d, 0xe7, 0x8d, 0x19, 0x6e, 0xe6, 0xfa, 0x06, 0x55,
  40050. 0xb8, 0x06, 0x4d, 0xa8, 0x45, 0x20, 0x91, 0xf7, 0xfa, 0x0b, 0x6b, 0xce,
  40051. 0x55, 0xa7, 0x14, 0x1b, 0xf9, 0xea, 0xc5, 0x79, 0x78, 0xf7, 0x3a, 0xd9,
  40052. 0xfc, 0x07, 0x43, 0x06, 0x90, 0x94, 0x5e, 0xc9, 0x48, 0x51, 0xe5, 0x96,
  40053. 0x68, 0x78, 0xc8, 0xcb, 0xd1, 0xf3, 0x65, 0xef, 0x14, 0x91, 0xa3, 0xca,
  40054. 0x8b, 0x77, 0x40, 0x84, 0xf4, 0x2e, 0xe7, 0x56, 0xe3, 0xab, 0xa0, 0xa8,
  40055. 0x61, 0x93, 0x17, 0x95, 0x9e, 0xff, 0x3a, 0xd4, 0x12, 0xea, 0x13, 0xe6,
  40056. 0x82, 0x16, 0xed, 0x14, 0x70, 0x91, 0xcc, 0x72, 0x58, 0x99, 0xa1, 0x7f,
  40057. 0xf3, 0x84, 0x10, 0xf4, 0x01, 0x0d, 0x05, 0x45, 0x4d, 0xca, 0x05, 0x03,
  40058. 0x75, 0x7e, 0xbb, 0x44, 0x2e, 0xf5, 0xee, 0xed, 0x64, 0x9b, 0xd3, 0xde,
  40059. 0x3e, 0xfc, 0x31, 0x8c, 0xca, 0x23, 0x66, 0x25, 0xac, 0x5f, 0x0f, 0x33,
  40060. 0x0f, 0xd2, 0xe9, 0xc9, 0x96, 0x2a, 0xe2, 0xb8, 0xed, 0x93, 0xd3, 0x78,
  40061. 0xd8, 0x81, 0xe4, 0x52, 0x9a, 0xc6, 0x64, 0x1d, 0x2d, 0x5f, 0x93, 0x9a,
  40062. 0x2e, 0x73, 0xc4, 0x17, 0xae, 0xc6, 0x08, 0x0d, 0x2d, 0xe9, 0x4b, 0x10,
  40063. 0x29, 0xa8, 0x4e, 0x8c, 0x08, 0x59, 0x87, 0x10, 0x0d, 0x5d, 0xfa, 0xec,
  40064. 0xd6, 0x42, 0xf6, 0x5c, 0xa4, 0x0d, 0xaa, 0x64, 0x8e, 0x20, 0xa5, 0x50,
  40065. 0x9f, 0x0b, 0x85, 0x37, 0x57, 0x15, 0x7c, 0xb1, 0xe4, 0xdd, 0xd5, 0x19,
  40066. 0x3b, 0x10, 0x7d, 0x22, 0xdb, 0x53, 0x8b, 0x7b, 0x32, 0xf7, 0xf2, 0x24,
  40067. 0x92, 0xb2, 0x05, 0xd1, 0xfd, 0xfc, 0x11, 0xd6, 0xfd, 0x3c, 0x8d, 0xd7,
  40068. 0xb0, 0x58, 0x50, 0x06, 0x84, 0x61, 0xa6, 0x78, 0x04, 0x1d, 0x7f, 0x92,
  40069. 0x0e, 0x8b, 0xb3, 0x63, 0x43, 0xc5, 0x30, 0x4c, 0xce, 0x2b, 0x44, 0x70,
  40070. 0x53, 0x7c, 0xb5, 0xbd, 0x30, 0xcb, 0x41, 0x19, 0x27, 0x69, 0xfe, 0x41,
  40071. 0x92, 0xae, 0xf0, 0x37, 0x33, 0xf0, 0x95, 0xe4, 0xe8, 0x4f, 0x75, 0x41,
  40072. 0x64, 0x87, 0xc5, 0x68, 0xd3, 0xce, 0xfa, 0xaa, 0xe8, 0x59, 0x88, 0xfe,
  40073. 0x24, 0x46, 0x27, 0x60, 0x71, 0x36, 0x78, 0x66, 0x3c, 0x36, 0x8e, 0xdb,
  40074. 0x90, 0x67, 0xa5, 0x6a, 0xfe, 0xd3, 0x23, 0x28, 0x91, 0x34, 0x24, 0x67,
  40075. 0x4b, 0x01, 0x6a, 0x0e, 0x02, 0xb7, 0xf0, 0xa8, 0xd4, 0x76, 0xd5, 0xa8,
  40076. 0x1c, 0xd3, 0xb3, 0x7d, 0x74, 0xc6, 0x17, 0x96, 0xa7, 0xf9, 0xad, 0x24,
  40077. 0x36, 0xd2, 0xeb, 0x34, 0x5a, 0xcc, 0x9c, 0x01, 0x99, 0xbe, 0x21, 0x4f,
  40078. 0x27, 0x9d, 0x6b, 0xca, 0x27, 0x1b, 0x60, 0x51, 0x41, 0x23, 0xe1, 0xcb,
  40079. 0xfc, 0x17, 0x2e, 0x1a, 0x4d, 0x3d, 0x51, 0xb3, 0x91, 0x8c, 0x53, 0x4d,
  40080. 0xd7, 0xbc, 0xa4, 0x07, 0xd7, 0x17, 0x19, 0x18, 0x61, 0x38, 0x4e, 0x05,
  40081. 0x81, 0x3f, 0x43, 0x8a, 0x00, 0x60, 0xdc, 0x30, 0xf4, 0x38, 0x3f, 0x93,
  40082. 0x82, 0x10, 0x29, 0x73, 0xa9, 0xbd, 0x63, 0x15, 0x7d, 0xac, 0x2e, 0xc9,
  40083. 0x05, 0xc1, 0x01, 0x41, 0x18, 0x5a, 0xc0, 0xc8, 0xc7, 0x81, 0x69, 0xe7,
  40084. 0x24, 0x21, 0x57, 0xaf, 0x88, 0x73, 0x7c, 0x53, 0x29, 0xae, 0x5a, 0xdf,
  40085. 0x76, 0x37, 0x56, 0x4f, 0x1f, 0x6b, 0xfd, 0x71, 0xbb, 0x80, 0x4a, 0xd7,
  40086. 0x53, 0x50, 0x10, 0x2d, 0xfc, 0x1a, 0xaf, 0x7c, 0x1f, 0xe8, 0xd0, 0x6c,
  40087. 0xa6, 0x45, 0x3d, 0xb5, 0x3d, 0xb2, 0xfc, 0x97, 0xa9, 0xbf, 0x7c, 0x0f,
  40088. 0x32, 0x7a, 0xcc, 0xa9, 0x2f, 0xd0, 0xc6, 0xe6, 0xcd, 0x04, 0x1d, 0x71,
  40089. 0x91, 0xb9, 0x59, 0x4b, 0xad, 0xa0, 0xde, 0x9e, 0xdc, 0x9c, 0x10, 0xeb,
  40090. 0x8d, 0xd6, 0x65, 0x57, 0xbc, 0x96, 0xfd, 0x0f, 0xcc, 0x73, 0xbe, 0x39,
  40091. 0x27, 0x99, 0x94, 0xf5, 0xe1, 0xbb, 0x32, 0xcd, 0x27, 0x7e, 0x08, 0xa0,
  40092. 0xd2, 0x92, 0x39, 0xeb, 0x71, 0xc8, 0xe8, 0x34, 0x57, 0x34, 0x4b, 0x20,
  40093. 0x3f, 0xe2, 0x68, 0xec, 0xc0, 0x8a, 0x71, 0xa3, 0x16, 0xa2, 0x91, 0x77,
  40094. 0xde, 0x41, 0x12, 0xa5, 0xf5, 0x2a, 0x63, 0x60, 0x55, 0xd0, 0x33, 0xa4,
  40095. 0xa7, 0x2e, 0xcb, 0x80, 0x08, 0xe5, 0x76, 0x16, 0x75, 0x04, 0x57, 0xe3,
  40096. 0x14, 0x71, 0x4e, 0x57, 0x29, 0x23, 0x0e, 0xc0, 0xcc, 0xad, 0xba, 0xdc,
  40097. 0x96, 0x5d, 0x23, 0x49, 0x42, 0xd8, 0x91, 0x08, 0x0d, 0x52, 0xf4, 0x5f,
  40098. 0xcd, 0xb7, 0x03, 0xaa, 0x73, 0x26, 0xa8, 0xd5, 0x5b, 0x0c, 0x85, 0xc8,
  40099. 0x84, 0x50, 0x9e, 0x70, 0x18, 0x45, 0x27, 0x82, 0x20, 0x75, 0xad, 0x52,
  40100. 0x5c, 0x80, 0x4b, 0xb1, 0x0b, 0x3b, 0x30, 0x39, 0x02, 0x54, 0x18, 0x5d,
  40101. 0x02, 0x9e, 0x85, 0x31, 0x4a, 0x07, 0x9c, 0x59, 0x5d, 0xab, 0x13, 0x4f,
  40102. 0x8f, 0x6e, 0x39, 0x20, 0xb2, 0xc5, 0x31, 0x93, 0xc6, 0xcc, 0xfb, 0xdc,
  40103. 0x15, 0xba, 0x3d, 0xcc, 0xbb, 0xd2, 0x6f, 0x04, 0x21, 0xdf, 0x0b, 0x27,
  40104. 0x5c, 0xd2, 0x6e, 0xfa, 0xda, 0x86, 0x5d, 0xe4, 0xca, 0xa4, 0x90, 0x22,
  40105. 0xa2, 0x80, 0xb5, 0x33, 0x17, 0xdb, 0x9b, 0x7b, 0x0a, 0xcc, 0x0f, 0x9b,
  40106. 0x38, 0x06, 0xdf, 0x10, 0x11, 0xa1, 0xd7, 0x2c, 0x24, 0xf0, 0xa8, 0x34,
  40107. 0x24, 0xfb, 0x99, 0xba, 0x0a, 0xb5, 0xa1, 0x94, 0x6c, 0x2d, 0xf8, 0xda,
  40108. 0x74, 0xaf, 0x19, 0x59, 0x84, 0xb2, 0x68, 0x1c, 0xef, 0xa1, 0xf5, 0x18,
  40109. 0x8f, 0x10, 0xf6, 0xb3, 0x6d, 0x33, 0x87, 0xe0, 0x25, 0xc8, 0x65, 0x5c,
  40110. 0x2f, 0x51, 0x07, 0x83, 0x69, 0x1b, 0xce, 0xa8, 0xe6, 0xe4, 0x27, 0x62,
  40111. 0x5d, 0x9b, 0x7f, 0xa7, 0x07, 0xc8, 0x54, 0x86, 0x90, 0xa5, 0x06, 0x6a,
  40112. 0x94, 0x80, 0x84, 0x97, 0xaa, 0x2a, 0xb9, 0x79, 0xe5, 0x19, 0x7a, 0x91,
  40113. 0xef, 0x8b, 0x58, 0xdc, 0xf9, 0x90, 0x94, 0xa2, 0x25, 0x4c, 0x69, 0xd8,
  40114. 0x6e, 0x9e, 0xad, 0xf8, 0x82, 0x17, 0x37, 0xc9, 0x20, 0x15, 0x24, 0x40,
  40115. 0xe5, 0xc6, 0xc1, 0xc7, 0xbd, 0xd4, 0x62, 0xff, 0x16, 0x6d, 0xa5, 0xec,
  40116. 0xe9, 0x67, 0x41, 0x9d, 0x3e, 0xfb, 0x22, 0x81, 0x80, 0x61, 0x37, 0x45,
  40117. 0xa5, 0x9f, 0x70, 0xff, 0xd4, 0x99, 0x3d, 0x79, 0x45, 0xd0, 0x27, 0xc2,
  40118. 0x32, 0xbe, 0xd4, 0xe2, 0x53, 0xa8, 0x8c, 0x94, 0x8b, 0xbe, 0x8a, 0x43,
  40119. 0xf7, 0x2a, 0x28, 0x49, 0xf4, 0xce, 0x2e, 0x0b, 0x98, 0xc7, 0xaf, 0x7d,
  40120. 0x51, 0x2e, 0xda, 0xd0, 0x7a, 0xfa, 0x91, 0x3a, 0xe6, 0xe7, 0x64, 0xd6,
  40121. 0x09, 0xd8, 0x5d, 0x6a, 0x97, 0xcf, 0x89, 0x96, 0x72, 0x21, 0x97, 0x61,
  40122. 0xc5, 0x1b, 0xd8, 0xa1, 0xf0, 0xcd, 0x9d, 0xe4, 0xe9, 0x13, 0xd0, 0x16,
  40123. 0x41, 0x20, 0xa4, 0x2c, 0x33, 0xf5, 0x3d, 0xfe, 0x80, 0xe8, 0xb2, 0x52,
  40124. 0x0e, 0x18, 0x31, 0x19, 0x50, 0xeb, 0xc6, 0x99, 0x43, 0xab, 0x9a, 0x59,
  40125. 0x5d, 0x6c, 0x84, 0x00, 0x88, 0x45, 0x7c, 0x73, 0xdf, 0x56, 0x61, 0x3a,
  40126. 0xe1, 0x55, 0xb8, 0x59, 0x13, 0xcc, 0x0e, 0x53, 0xe9, 0xf4, 0x74, 0xa0,
  40127. 0xf2, 0x15, 0xd2, 0xa8, 0xf9, 0xd4, 0x0d, 0x3d, 0xe7, 0x3d, 0x7d, 0x5b,
  40128. 0x19, 0x89, 0x8b, 0x2c, 0x4d, 0x8a, 0xeb, 0xc3, 0x43, 0x31, 0x9a, 0x45,
  40129. 0x72, 0x5b, 0x25, 0xb6, 0xa2, 0xc1, 0x98, 0xe3, 0x8a, 0xd4, 0x90, 0xd0,
  40130. 0x3e, 0x13, 0xf0, 0xd7, 0x90, 0x34, 0x94, 0xcc, 0xf1, 0x0a, 0xa9, 0x30,
  40131. 0xd1, 0x95, 0x43, 0x07, 0xcd, 0xd2, 0xca, 0xb0, 0xe5, 0xd4, 0xf1, 0xa1,
  40132. 0xc5, 0x9b, 0xf4, 0x98, 0x28, 0xba, 0xde, 0x40, 0xd6, 0x98, 0x98, 0x20,
  40133. 0x9c, 0x84, 0x9e, 0xc6, 0x57, 0xd8, 0x84, 0xc4, 0xa2, 0x9b, 0x53, 0x50,
  40134. 0xa5, 0xa6, 0x0b, 0x47, 0xe8, 0x08, 0x7d, 0xd7, 0x09, 0xa4, 0x0c, 0x2b,
  40135. 0x27, 0xde, 0xf9, 0x78, 0xbc, 0xa4, 0xb6, 0xc6, 0x1b, 0xda, 0xce, 0x6a,
  40136. 0xf8, 0x1a, 0xf5, 0xfe, 0x7b, 0xab, 0x58, 0x7c, 0xdc, 0x72, 0x02, 0x94,
  40137. 0x99, 0xf0, 0x3c, 0x37, 0x87, 0x5b, 0xd2, 0x4b, 0x5a, 0x80, 0x83, 0xd7,
  40138. 0xfc, 0x9d, 0xa7, 0x51, 0x81, 0xb8, 0x62, 0xff, 0x4b, 0xb3, 0x9f, 0x07,
  40139. 0xc3, 0x54, 0xfb, 0x41, 0x85, 0x42, 0x9d, 0xac, 0x27, 0x81, 0x2e, 0xaf,
  40140. 0x98, 0x67, 0x8c, 0x23, 0xad, 0x45, 0xfe, 0x6a, 0x57, 0x9f, 0x18, 0xc5,
  40141. 0x71, 0x8c, 0xad, 0x3f, 0x30, 0x3c, 0xaa, 0x47, 0x8d, 0xba, 0xc8, 0x7f,
  40142. 0x03, 0x1c, 0x86, 0xee, 0xba, 0x3f, 0x59, 0x45, 0xd4, 0xd0, 0xf5, 0x54,
  40143. 0x9e, 0xcb, 0x08, 0xcf, 0xca, 0x40, 0x0a, 0x06, 0xc0, 0x1e, 0x60, 0x1f,
  40144. 0x33, 0xbf, 0x2c, 0xa8, 0x5f, 0xce, 0x23, 0xa0, 0xe2, 0x1c, 0x2d, 0x56,
  40145. 0x2a, 0x44, 0x61, 0x58, 0xf1, 0x84, 0x63, 0x4f, 0x0d, 0x5e, 0xfb, 0x83,
  40146. 0x0f, 0x36, 0x1b, 0xf4, 0x8f, 0x17, 0x82, 0x2e, 0x04, 0x2c, 0x77, 0x9d,
  40147. 0x32, 0x58, 0xb8, 0xb0, 0xf9, 0x44, 0xd2, 0xf6, 0x84, 0xa4, 0x8b, 0x28,
  40148. 0x53, 0xd6, 0x99, 0x81, 0x84, 0x43, 0xf0, 0xc1, 0x15, 0xc6, 0x74, 0x4f,
  40149. 0xab, 0x05, 0xcc, 0x80, 0xdf, 0xef, 0xcf, 0xaf, 0x14, 0x82, 0xdf, 0x51,
  40150. 0x7c, 0x28, 0x5e, 0x5b, 0x27, 0x5e, 0x91, 0x8b, 0x54, 0x3d, 0x54, 0x26,
  40151. 0xb0, 0x3f, 0xd7, 0xc5, 0xce, 0xf3, 0x6d, 0x2c, 0x12, 0xc6, 0xb4, 0x48,
  40152. 0x60, 0x11, 0x9c, 0xef, 0x29, 0x98, 0x9c, 0x76, 0x4e, 0x73, 0x2b, 0xd2,
  40153. 0x23, 0x53, 0x7d, 0x03, 0xc2, 0x2f, 0x8a, 0xa1, 0xe2, 0x84, 0x54, 0x2d,
  40154. 0xd8, 0xc6, 0x55, 0x77, 0x9d, 0x07, 0x67, 0x1f, 0x1a, 0xd3, 0x57, 0x4c,
  40155. 0x25, 0x79, 0x8f, 0xd8, 0x82, 0xc2, 0x4d, 0x87, 0x84, 0x33, 0xdc, 0x47,
  40156. 0xed, 0x9e, 0xfb, 0xd2, 0x62, 0xc8, 0x50, 0x76, 0xda, 0x3c, 0x3c, 0x05,
  40157. 0x0e, 0x2d, 0x30, 0x56, 0xca, 0x4d, 0x6a, 0xe2, 0x17, 0x24, 0x26, 0x9c,
  40158. 0xff, 0x09, 0xec, 0xb3, 0x94, 0xec, 0xab, 0x69, 0xb2, 0xf0, 0xa5, 0x66,
  40159. 0x18, 0x92, 0x49, 0x6b, 0x90, 0xf5, 0x77, 0x5a, 0x18, 0xe5, 0x51, 0x36,
  40160. 0x4a, 0x35, 0x54, 0x98, 0x48, 0x04, 0xa9, 0x0f, 0xcb, 0x55, 0xf1, 0x71,
  40161. 0xad, 0x1a, 0x4a, 0x2c, 0x0e, 0x5d, 0x5e, 0x77, 0x47, 0xf5, 0x46, 0x17,
  40162. 0x6b, 0x94, 0x2a, 0xbc, 0x40, 0xe5, 0xa7, 0xa6, 0x88, 0x41, 0x76, 0x22,
  40163. 0x47, 0xd1, 0xe8, 0x2b, 0x18, 0x48, 0x21, 0xc0, 0xe8, 0x4f, 0xe2, 0xb2,
  40164. 0x7e, 0x03, 0xbb, 0x25, 0x9c, 0xc8, 0x68, 0x66, 0x48, 0x25, 0x6a, 0xf2,
  40165. 0x64, 0x29, 0xec, 0x79, 0xba, 0xdb, 0x34, 0xe1, 0xd4, 0xf9, 0x52, 0x0e,
  40166. 0xfd, 0x8d, 0x86, 0x94, 0x71, 0xd8, 0xe0, 0x86, 0x02, 0x9b, 0xd4, 0x65,
  40167. 0x69, 0x5e, 0x01, 0x32, 0x87, 0x59, 0xd8, 0x6c, 0xbc, 0x8a, 0x9f, 0x58,
  40168. 0x28, 0x8c, 0x97, 0xef, 0x33, 0xb2, 0xda, 0x45, 0xa0, 0xec, 0xe5, 0x5b,
  40169. 0xac, 0xc6, 0x65, 0xc1, 0xb6, 0xcb, 0xf7, 0x85, 0x0e, 0xfa, 0x78, 0x36,
  40170. 0x30, 0x84, 0x90, 0xa8, 0xf8, 0x42, 0x25, 0xa5, 0xdd, 0xdc, 0xdc, 0x89,
  40171. 0xd3, 0xf0, 0x73, 0x9a, 0xd8, 0x95, 0x8f, 0x04, 0xbf, 0xc1, 0xfd, 0x94,
  40172. 0xff, 0xe6, 0xf8, 0x4e, 0xc6, 0x43, 0xc9, 0x60, 0x30, 0xe9, 0x68, 0xa8,
  40173. 0x76, 0xfb, 0xfa, 0xdf, 0xc0, 0x9b, 0xbc, 0xbc, 0x34, 0xe4, 0x38, 0xfd,
  40174. 0x93, 0xb0, 0x47, 0xb2, 0x3e, 0x83, 0x6c, 0xef, 0xe1, 0xaf, 0x35, 0xb4,
  40175. 0x90, 0x2a, 0x32, 0xaf, 0x25, 0x3f, 0x3e, 0x72, 0x61, 0xc0, 0x0f, 0x29,
  40176. 0xbb, 0x46, 0x6e, 0x2e, 0x94, 0x7d, 0xdd, 0xb7, 0x67, 0x1f, 0x7b, 0x64,
  40177. 0xcb, 0xa5, 0x9a, 0x58, 0x63, 0x20, 0xa7, 0xc0, 0x94, 0xa9, 0xad, 0x90,
  40178. 0x7d, 0xf3, 0x2b, 0x61, 0x2b, 0x64, 0x3d, 0x8a, 0xc3, 0xd1, 0xcb, 0xad,
  40179. 0x36, 0x44, 0xe6, 0x29, 0x8b, 0x3d, 0x95, 0x7c, 0xa7, 0xa2, 0xfa, 0x1b,
  40180. 0x16, 0x8d, 0x9e, 0xc4, 0xf8, 0x4c, 0x76, 0x20, 0x00, 0x68, 0x07, 0x99,
  40181. 0x9c, 0x60, 0xe6, 0x16, 0x6a, 0x6f, 0x8a, 0xbe, 0x71, 0x95, 0xa1, 0xcb,
  40182. 0xfe, 0x7c, 0x41, 0x59, 0x61, 0x20, 0xf9, 0x54, 0x3c, 0xb1, 0x19, 0x5c,
  40183. 0x42, 0x67, 0x3f, 0xff, 0xf3, 0x32, 0x21, 0x9c, 0x9e, 0x88, 0xf9, 0x97,
  40184. 0x00, 0x43, 0x73, 0x4a, 0xfc, 0x54, 0xeb, 0x27, 0x79, 0x14, 0x85, 0xd3,
  40185. 0xdc, 0x47, 0xb3, 0x6d, 0x24, 0xd3, 0xf7, 0x7a, 0xfb, 0x90, 0x7c, 0x6e,
  40186. 0xcd, 0x4e, 0xbf, 0x26, 0x76, 0xd2, 0xe8, 0xcc, 0x67, 0xd1, 0x23, 0x3c,
  40187. 0x94, 0x16, 0x1e, 0x07, 0x36, 0x7c, 0x96, 0xf6, 0xe8, 0x50, 0x72, 0x26,
  40188. 0x56, 0x67, 0x89, 0xa9, 0x11, 0xfb, 0x1d, 0xb8, 0xb9, 0x2a, 0x55, 0xb7,
  40189. 0x85, 0xf7, 0x40, 0xa2, 0xfc, 0x9f, 0x30, 0xec, 0x8f, 0x9a, 0x1c, 0xc8,
  40190. 0xe4, 0xc5, 0x1f, 0xcb, 0x0a, 0x60, 0x80, 0x41, 0xec, 0x88, 0x8a, 0xda,
  40191. 0x7c, 0x7a, 0xa1, 0x96, 0x51, 0x62, 0x16, 0x63, 0x75, 0x36, 0x28, 0x7c,
  40192. 0xc9, 0xd0, 0x27, 0x0c, 0x9e, 0x18, 0x4a, 0x82, 0xf7, 0x02, 0xb9, 0x40,
  40193. 0x8f, 0xd5, 0x97, 0x7a, 0x35, 0xa9, 0x3a, 0xb3, 0x8b, 0x6b, 0xf1, 0x9a,
  40194. 0xd1, 0xe7, 0x14, 0x38, 0x5e, 0xba, 0x8c, 0xbf, 0x32, 0xaa, 0x34, 0x30,
  40195. 0x7c, 0x1e, 0x11, 0xcd, 0x1f, 0x9f, 0xcf, 0x4d, 0x14, 0xce, 0x67, 0xf9,
  40196. 0x9c, 0x89, 0x07, 0x92, 0x44, 0x6e, 0x9a, 0x16, 0xe4, 0xfb, 0x67, 0x01,
  40197. 0x3f, 0x4c, 0x14, 0x89, 0x33, 0x87, 0x46, 0xc6, 0xe4, 0x66, 0x94, 0xd4,
  40198. 0x87, 0x4f, 0x2c, 0x92, 0x1b, 0xae, 0x82, 0xe7, 0x99, 0xaa, 0xb4, 0x99,
  40199. 0x81, 0x26, 0xa6, 0x6f, 0x1d, 0xc1, 0x95, 0x80, 0xe9, 0xea, 0xe3, 0x44,
  40200. 0x6a, 0x2b, 0xd2, 0xe0, 0x0d, 0x69, 0x42, 0xf7, 0x27, 0x6b, 0x4f, 0x02,
  40201. 0x7a, 0x33, 0x7b, 0x43, 0x3d, 0xef, 0x10, 0xaa, 0xab, 0xc5, 0xa2, 0xf0,
  40202. 0xbb, 0x07, 0x4b, 0x26, 0x0c, 0x58, 0xcd, 0x3b, 0xd2, 0x6d, 0xa5, 0x32,
  40203. 0x37, 0x88, 0x4e, 0x8b, 0xe3, 0x75, 0xb0, 0xbb, 0x87, 0xea, 0xa4, 0x53,
  40204. 0xf3, 0xff, 0x39, 0x92, 0x44, 0xab, 0x7b, 0x71, 0x62, 0x31, 0x6b, 0x31,
  40205. 0xca, 0x97, 0xba, 0xd7, 0x41, 0xe0, 0x47, 0x47, 0x4f, 0x77, 0xa2, 0x35,
  40206. 0x62, 0x7a, 0xc1, 0xb6, 0x69, 0x10, 0x09, 0xce, 0xfc, 0x92, 0xcc, 0xc5,
  40207. 0x7a, 0x11, 0xf1, 0xc1, 0xa0, 0x80, 0xe5, 0x42, 0x17, 0xb6, 0x3f, 0xab,
  40208. 0xc1, 0xa2, 0x41, 0xfb, 0xe3, 0x98, 0x2d, 0x7a, 0xe4, 0x1b, 0x1f, 0x7e,
  40209. 0x71, 0x3c, 0x3e, 0x90, 0x8c, 0x60, 0x30, 0xb7, 0x73, 0x06, 0x1f, 0x8a,
  40210. 0xce, 0x50, 0x20, 0x7c, 0xfa, 0x8c, 0xf2, 0x14, 0xd9, 0x00, 0xa2, 0x21,
  40211. 0xea, 0x10, 0x36, 0x21, 0x6f, 0x7f, 0x13, 0xe3, 0x6c, 0xb2, 0xd6, 0xa5,
  40212. 0xa6, 0x6e, 0xa9, 0xe7, 0x1d, 0xdf, 0xc9, 0x97, 0x60, 0x75, 0xa3, 0x55,
  40213. 0xa1, 0x2c, 0x94, 0xd7, 0x85, 0x4b, 0x44, 0xc6, 0x9c, 0x17, 0xc2, 0xad,
  40214. 0xe6, 0x56, 0x72, 0x1d, 0xb9, 0x13, 0x54, 0xfe, 0x8c, 0xec, 0xf4, 0xa3,
  40215. 0x54, 0x6b, 0x31, 0xbc, 0x55, 0x9e, 0x01, 0xd4, 0x9b, 0x24, 0x9e, 0x51,
  40216. 0xaf, 0x67, 0x76, 0x02, 0xf7, 0x34, 0x6a, 0xaa, 0xb0, 0x3c, 0x70, 0x2e,
  40217. 0xc8, 0x86, 0xfa, 0x40, 0x89, 0x12, 0xb7, 0x49, 0x38, 0x0b, 0xf7, 0x66,
  40218. 0xd2, 0x2e, 0x58, 0xf1, 0x22, 0x3b, 0xb3, 0x40, 0x6b, 0x7a, 0x68, 0x4d,
  40219. 0x42, 0xfd, 0xbf, 0xa0, 0xf7, 0x2f, 0x63, 0x4a, 0x87, 0xe7, 0x99, 0x52,
  40220. 0x6e, 0xe7, 0xdd, 0xca, 0x19, 0x71, 0xee, 0x92, 0xe2, 0x68, 0x0e, 0xe1,
  40221. 0xb7, 0x90, 0x1f, 0xc4, 0xef, 0xf8, 0xf6, 0x85, 0x53, 0x18, 0x33, 0x86,
  40222. 0x15, 0xc8, 0x29, 0x58, 0x6f, 0xf0, 0x1c, 0x14, 0x73, 0xa9, 0x8e, 0x88,
  40223. 0x74, 0xd4, 0x21, 0xf5, 0xc6, 0x7c, 0xd8, 0x96, 0x0f, 0xb0, 0xa6, 0x7b,
  40224. 0xf7, 0x72, 0x15, 0xd7, 0x30, 0x6b, 0x15, 0x1d, 0x3f, 0xb7, 0x4e, 0xaa,
  40225. 0xc0, 0x52, 0x1d, 0x84, 0xbf, 0x98, 0xbd, 0x33, 0x02, 0xab, 0x8b, 0xd0,
  40226. 0x9c, 0x85, 0x2f, 0xa3, 0xfb, 0x46, 0x8d, 0x4d, 0x97, 0x1a, 0x8a, 0x3c,
  40227. 0x73, 0x5b, 0x3b, 0x58, 0x26, 0xba, 0x6b, 0x45, 0x2e, 0x24, 0x66, 0x79,
  40228. 0x7d, 0xc4, 0xf8, 0x8c, 0x05, 0x7d, 0x5c, 0x23, 0xb9, 0xe8, 0x5d, 0xfe,
  40229. 0xc9, 0x84, 0xe5, 0x58, 0x40, 0xa4, 0xb7, 0x55, 0x74, 0x69, 0x92, 0x9c,
  40230. 0x3e, 0x19, 0xb1, 0xb6, 0x51, 0xe9, 0x71, 0xcc, 0x96, 0x2b, 0x01, 0x71,
  40231. 0xf5, 0xb9, 0xde, 0x77, 0xfe, 0x2e, 0x74, 0x9c, 0x6a, 0x52, 0x17, 0x1e,
  40232. 0xea, 0xd9, 0xc8, 0x14, 0xbe, 0x61, 0xdf, 0xe9, 0x96, 0x24, 0x5a, 0x9a,
  40233. 0xd8, 0xd7, 0xad, 0x71, 0xe0, 0xf4, 0xbb, 0x9e, 0xae, 0x95, 0xcd, 0x58,
  40234. 0x94, 0x81, 0xee, 0x46, 0x84, 0x65, 0x39, 0xb1, 0x1b, 0x1e, 0xf5, 0x50,
  40235. 0xad, 0x56, 0x58, 0xb7, 0x53, 0x9b, 0x2a, 0x2f, 0x09, 0x61, 0x57, 0xda,
  40236. 0xf5, 0xdc, 0x9f, 0x3c, 0x6c, 0x69, 0x0d, 0x61, 0x49, 0xb2, 0xe0, 0xb2,
  40237. 0xe5, 0xef, 0x19, 0xbe, 0x04, 0xf6, 0x6b, 0xad, 0x41, 0x4c, 0x5a, 0x50,
  40238. 0xf6, 0xac, 0x1b, 0x25, 0x8a, 0xdd, 0xe3, 0x57, 0xab, 0x7c, 0x92, 0xe4
  40239. };
  40240. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40241. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_pub_key[] = {
  40242. 0xef, 0x49, 0x79, 0x47, 0x15, 0xc4, 0x8a, 0xa9, 0x74, 0x2a,
  40243. 0xf0, 0x36, 0x94, 0x5c, 0x91, 0x1c, 0x5d, 0xff, 0x2c, 0x83,
  40244. 0xf2, 0x8b, 0x04, 0xfc, 0x5d, 0x64, 0xbd, 0x49, 0x73, 0xcd,
  40245. 0xcc, 0x99, 0x50, 0x5f, 0x2b, 0x16, 0x3a, 0xbb, 0x98, 0xc0,
  40246. 0xa7, 0x69, 0x0e, 0x95, 0x99, 0x0b, 0xa2, 0x6c, 0xfe, 0x6c,
  40247. 0xdb, 0xc8, 0xa7, 0x09, 0x46, 0x6c, 0x90, 0x50, 0xa4, 0x75,
  40248. 0x30, 0xf7, 0x90, 0xac, 0x31, 0xb6, 0xdd, 0x21, 0xaf, 0xc6,
  40249. 0xf9, 0xfe, 0xee, 0xc6, 0x5b, 0xa8, 0x8f, 0x0a, 0x2e, 0xd0,
  40250. 0x42, 0xab, 0xa8, 0x3c, 0x8d, 0xbf, 0xf7, 0x44, 0xbd, 0x0d,
  40251. 0xcf, 0xf4, 0x68, 0xfc, 0x16, 0x67, 0xf7, 0x39, 0x48, 0x5f,
  40252. 0x56, 0xd1, 0xe7, 0x1f, 0x49, 0x80, 0x50, 0xbe, 0x54, 0xd1,
  40253. 0xb7, 0xc9, 0xd2, 0x32, 0xc7, 0x08, 0x8c, 0xde, 0x2c, 0x31,
  40254. 0xf6, 0x1d, 0xc7, 0xac, 0xb3, 0x79, 0xd7, 0x4b, 0x1b, 0x23,
  40255. 0x89, 0x0a, 0xdc, 0x8e, 0x44, 0x41, 0x14, 0x28, 0x99, 0x13,
  40256. 0xb3, 0x26, 0xa6, 0x0e, 0x83, 0x60, 0xaa, 0x8d, 0x7c, 0x23,
  40257. 0x13, 0xba, 0x6c, 0x28, 0x90, 0x56, 0x84, 0xa1, 0x23, 0x8b,
  40258. 0x81, 0x20, 0x97, 0x7c, 0x66, 0x3f, 0xed, 0x5d, 0xd0, 0xe4,
  40259. 0x5d, 0xee, 0x46, 0xbc, 0x4b, 0x3c, 0x03, 0xb5, 0xbc, 0x4d,
  40260. 0x8d, 0x37, 0xa3, 0x56, 0x4b, 0x33, 0xad, 0xef, 0xd4, 0xb6,
  40261. 0xec, 0xdb, 0x04, 0x9a, 0x19, 0x58, 0x57, 0xd8, 0x00, 0x3a,
  40262. 0x92, 0x61, 0x0c, 0x0b, 0xc8, 0x52, 0xe5, 0x04, 0x02, 0x9a,
  40263. 0x00, 0x7e, 0xec, 0x7e, 0x94, 0xaa, 0xef, 0x2d, 0x7f, 0xb6,
  40264. 0x2e, 0x7c, 0xb0, 0x73, 0xa2, 0x20, 0xc0, 0x07, 0x30, 0x41,
  40265. 0x50, 0x20, 0x14, 0x18, 0x21, 0x5e, 0x2a, 0x6f, 0x70, 0x21,
  40266. 0xd6, 0x97, 0x13, 0xb9, 0xc1, 0x9e, 0x90, 0x67, 0xcc, 0x55,
  40267. 0x8a, 0xec, 0xec, 0x0a, 0x1e, 0x90, 0xdc, 0x3f, 0xb0, 0x4d,
  40268. 0xd1, 0x18, 0xea, 0x4f, 0xcb, 0x5d, 0x15, 0x4c, 0xb8, 0x35,
  40269. 0x9b, 0x34, 0x24, 0x30, 0x06, 0x53, 0x17, 0xf0, 0xbe, 0x27,
  40270. 0x36, 0xb3, 0x04, 0x6a, 0xbd, 0xbf, 0xa7, 0x39, 0xee, 0xa9,
  40271. 0x8f, 0x0e, 0x98, 0xc5, 0xf5, 0x9f, 0x46, 0x25, 0x93, 0xc9,
  40272. 0xf2, 0xf6, 0x2b, 0x8e, 0x92, 0x06, 0x01, 0x3d, 0x81, 0x18,
  40273. 0xf2, 0xec, 0xf1, 0x05, 0x4c, 0xad, 0x4b, 0xcb, 0x98, 0xa4,
  40274. 0xb5, 0x61, 0x20, 0xda, 0x81, 0xa1, 0xfb, 0x92, 0x4c, 0xaf,
  40275. 0x87, 0x6f, 0x6e, 0xd2, 0x57, 0xec, 0xcd, 0x94, 0xb3, 0x79,
  40276. 0xbf, 0x59, 0x88, 0x17, 0x81, 0xce, 0x8a, 0x57, 0xce, 0x57,
  40277. 0xae, 0x3e, 0x82, 0x81, 0x2f, 0x83, 0x61, 0xd8, 0xf9, 0x68,
  40278. 0x21, 0xe7, 0x72, 0x5b, 0xd6, 0x80, 0x55, 0x68, 0x5d, 0x67,
  40279. 0x15, 0x0c, 0x8b, 0xdc, 0x4f, 0xc3, 0x89, 0x36, 0x3c, 0xac,
  40280. 0xaf, 0x16, 0x5e, 0x1c, 0xfa, 0x68, 0x74, 0x6a, 0xab, 0x68,
  40281. 0xd8, 0x59, 0x96, 0x2d, 0x33, 0x62, 0xe4, 0xbd, 0xb3, 0xb7,
  40282. 0x4d, 0x88, 0x35, 0xb8, 0xed, 0xb2, 0x16, 0x85, 0x97, 0x08,
  40283. 0x71, 0x71, 0x39, 0x7e, 0x0c, 0x53, 0x16, 0xda, 0x38, 0xe5,
  40284. 0x28, 0x09, 0x9c, 0xd9, 0x46, 0xec, 0x68, 0xda, 0x8d, 0xd0,
  40285. 0xad, 0xb2, 0x79, 0x28, 0x3b, 0x1e, 0x12, 0xc9, 0xdf, 0xa9,
  40286. 0x6d, 0x3d, 0x29, 0x99, 0x2f, 0x53, 0xc2, 0xd0, 0xf9, 0x88,
  40287. 0x26, 0x94, 0x47, 0xaf, 0xf6, 0x96, 0xf3, 0xe1, 0x11, 0xa6,
  40288. 0x82, 0x3d, 0x43, 0x3f, 0x1f, 0xbc, 0xf6, 0x98, 0xbe, 0xff,
  40289. 0x06, 0x86, 0x61, 0x27, 0xdc, 0x91, 0x54, 0xd4, 0xfc, 0x68,
  40290. 0x83, 0xe8, 0x35, 0x3e, 0xee, 0x94, 0x59, 0x28, 0x2f, 0xde,
  40291. 0xdd, 0x03, 0x60, 0x66, 0xc1, 0x49, 0x57, 0xdd, 0xbc, 0xd5,
  40292. 0x0a, 0x67, 0x34, 0xf1, 0xa6, 0x0a, 0x57, 0x94, 0x65, 0x02,
  40293. 0x2c, 0x52, 0x43, 0x70, 0x3b, 0xc1, 0x9a, 0xff, 0xda, 0x6f,
  40294. 0xb9, 0x54, 0x47, 0x01, 0xda, 0x27, 0xe4, 0x48, 0x4a, 0x90,
  40295. 0x9f, 0xb5, 0xc3, 0xee, 0x0e, 0x09, 0x57, 0xfe, 0x48, 0x51,
  40296. 0x08, 0x34, 0x5e, 0x8f, 0x16, 0xc9, 0x0b, 0x74, 0xd9, 0x7d,
  40297. 0x22, 0x3f, 0xd6, 0xb7, 0x5d, 0xd6, 0x76, 0x00, 0x8d, 0x4e,
  40298. 0x78, 0x73, 0x86, 0xd6, 0xdb, 0x2a, 0x65, 0xab, 0xdf, 0xb0,
  40299. 0xea, 0x11, 0xad, 0xdf, 0xba, 0x43, 0xdb, 0xa8, 0x0a, 0xfb,
  40300. 0x04, 0x38, 0x81, 0x2b, 0xa3, 0x29, 0xfc, 0x95, 0x73, 0x9a,
  40301. 0x0c, 0x6c, 0x9e, 0xcd, 0xdc, 0xcf, 0x0a, 0x0c, 0x18, 0x41,
  40302. 0x6f, 0x1d, 0xa3, 0xf6, 0x12, 0x4c, 0x13, 0xf2, 0x02, 0xc6,
  40303. 0x50, 0x99, 0x86, 0x73, 0xa7, 0xf9, 0x7e, 0x84, 0x7f, 0x4c,
  40304. 0x00, 0xce, 0x2e, 0x21, 0x76, 0x8e, 0x17, 0x7a, 0x87, 0x6f,
  40305. 0x81, 0xe6, 0xc0, 0x52, 0xa5, 0xa0, 0x3c, 0x54, 0x3c, 0xec,
  40306. 0xb0, 0x9d, 0x1c, 0x3b, 0xec, 0xe5, 0x4e, 0x4a, 0x37, 0xe7,
  40307. 0xd5, 0xa9, 0x07, 0x87, 0x23, 0x28, 0x5d, 0x3d, 0x22, 0x02,
  40308. 0x79, 0x40, 0x3f, 0x2d, 0x40, 0xc9, 0xe5, 0xa6, 0x9b, 0xa8,
  40309. 0xb8, 0x76, 0xf6, 0x77, 0x5b, 0x8d, 0x72, 0x96, 0x3e, 0x13,
  40310. 0xbf, 0x76, 0xfa, 0x7b, 0xb7, 0x82, 0x5f, 0xe7, 0x9d, 0x54,
  40311. 0x0e, 0x05, 0x1a, 0x9f, 0xa4, 0x42, 0xa5, 0xb4, 0x93, 0x23,
  40312. 0x06, 0x59, 0x43, 0xa8, 0xe8, 0x5c, 0xfc, 0x18, 0x97, 0xdb,
  40313. 0xad, 0x9a, 0x80, 0x0a, 0xf2, 0x20, 0x50, 0xac, 0xc1, 0x13,
  40314. 0x3e, 0x98, 0x09, 0xde, 0xf2, 0x70, 0x9e, 0x14, 0xc2, 0x5c,
  40315. 0xec, 0x65, 0x07, 0x0b, 0xfa, 0x02, 0x5c, 0xf8, 0x71, 0xaa,
  40316. 0x9b, 0x45, 0x62, 0xe2, 0x27, 0xaf, 0x77, 0xf8, 0xe3, 0xeb,
  40317. 0x7b, 0x24, 0x7b, 0x3c, 0x67, 0xc2, 0x6d, 0x6e, 0x17, 0xae,
  40318. 0x6e, 0x86, 0x6f, 0x98, 0xc9, 0xac, 0x13, 0x9f, 0x87, 0x64,
  40319. 0x3d, 0x4d, 0x6f, 0xa0, 0xb3, 0x39, 0xc6, 0x68, 0x1b, 0xa7,
  40320. 0xeb, 0x3e, 0x0f, 0x6b, 0xc7, 0xa4, 0xe2, 0x20, 0x27, 0x75,
  40321. 0x3f, 0x09, 0x16, 0xff, 0x1a, 0xcc, 0xa7, 0xc4, 0x6d, 0xc2,
  40322. 0xfc, 0xc3, 0x0b, 0x37, 0x63, 0xff, 0x9b, 0x10, 0xe6, 0x00,
  40323. 0xf7, 0x18, 0x43, 0x9f, 0x07, 0x50, 0x31, 0x51, 0xd4, 0xfd,
  40324. 0xad, 0xa2, 0x0f, 0x77, 0xda, 0x41, 0xc1, 0x0a, 0x6f, 0x86,
  40325. 0xd7, 0xdc, 0x8a, 0x52, 0xd6, 0xa1, 0x27, 0xdb, 0x14, 0x67,
  40326. 0x26, 0x91, 0xb3, 0xcd, 0x01, 0x5f, 0x60, 0xa1, 0x7f, 0x43,
  40327. 0x15, 0x1a, 0x82, 0x0f, 0xd3, 0x66, 0x5f, 0x60, 0x57, 0x2f,
  40328. 0xb2, 0x8c, 0x27, 0x2a, 0x9d, 0x1b, 0xf9, 0xf2, 0x59, 0x20,
  40329. 0x39, 0xd9, 0xc5, 0xaf, 0xf2, 0x36, 0x8c, 0x58, 0x00, 0x1b,
  40330. 0xd0, 0xc5, 0x8e, 0x1a, 0x49, 0xa8, 0x60, 0xbe, 0xd1, 0xd7,
  40331. 0x2a, 0xb0, 0xc2, 0xab, 0x58, 0x8a, 0x7a, 0xa9, 0x41, 0x68,
  40332. 0x70, 0xbd, 0xea, 0x73, 0xa5, 0x03, 0x11, 0xb2, 0x27, 0xd9,
  40333. 0xcd, 0xf5, 0x09, 0xe8, 0x1c, 0xe2, 0x4f, 0x50, 0x6a, 0x84,
  40334. 0x34, 0x62, 0x2e, 0x36, 0xaa, 0x4c, 0xc1, 0x83, 0x78, 0x98,
  40335. 0x35, 0x7a, 0x27, 0x7e, 0xfe, 0xf1, 0x6f, 0x59, 0x27, 0x35,
  40336. 0x73, 0xce, 0x74, 0xaa, 0xb4, 0x72, 0x82, 0xa8, 0xe2, 0x81,
  40337. 0x7a, 0x6b, 0xca, 0x33, 0xa5, 0xda, 0xa2, 0x63, 0xca, 0x2e,
  40338. 0x90, 0x03, 0x32, 0xec, 0x63, 0xdb, 0x52, 0x7b, 0x16, 0xfc,
  40339. 0x01, 0x2d, 0x30, 0x12, 0x1e, 0xf9, 0xa3, 0x72, 0x21, 0x3c,
  40340. 0x75, 0x0c, 0x61, 0x9c, 0x7e, 0x73, 0x04, 0x71, 0x41, 0x45,
  40341. 0x5d, 0x7f, 0x49, 0x1c, 0x09, 0x08, 0xa4, 0xec, 0x2f, 0xfd,
  40342. 0xc4, 0xfb, 0x59, 0x6a, 0x27, 0x7a, 0xd4, 0xfc, 0x5f, 0x20,
  40343. 0x04, 0x34, 0x7d, 0x08, 0xed, 0x82, 0x5a, 0x90, 0xe1, 0xab,
  40344. 0xfd, 0x35, 0x3a, 0x8d, 0xbb, 0x0a, 0x9d, 0x73, 0xff, 0x69,
  40345. 0xe5, 0xe9, 0x09, 0x55, 0x14, 0xd9, 0x7b, 0x6f, 0x0d, 0x99,
  40346. 0xd2, 0x7e, 0x71, 0xf8, 0x4f, 0x72, 0x2f, 0xbb, 0xc6, 0xc4,
  40347. 0x36, 0xc9, 0x01, 0xd3, 0x9b, 0x94, 0xab, 0x41, 0x0f, 0x4a,
  40348. 0x61, 0x5c, 0x68, 0xe5, 0xd7, 0x0d, 0x94, 0xaa, 0xee, 0xba,
  40349. 0x95, 0xcb, 0x8c, 0x0e, 0x85, 0x3a, 0x02, 0x6b, 0x95, 0x50,
  40350. 0xfd, 0x02, 0xfd, 0xa4, 0x58, 0x29, 0x78, 0x4f, 0xd0, 0xae,
  40351. 0x66, 0xd6, 0x5c, 0xe7, 0x45, 0xfe, 0x98, 0xb0, 0xa3, 0xe2,
  40352. 0x87, 0xc0, 0xd2, 0x81, 0x08, 0xf1, 0xf1, 0xe7, 0xda, 0x62,
  40353. 0x9e, 0xa0, 0x34, 0x86, 0xeb, 0xa1, 0x6e, 0x4a, 0x26, 0x8e,
  40354. 0x39, 0x0c, 0x51, 0x10, 0x33, 0x11, 0x87, 0xf8, 0x79, 0x3c,
  40355. 0x49, 0x7a, 0x8b, 0xce, 0xc1, 0x0a, 0x0e, 0xe1, 0xd5, 0x2a,
  40356. 0xac, 0xf0, 0x3a, 0x1d, 0x6a, 0x6a, 0xe5, 0xe1, 0x81, 0x70,
  40357. 0xad, 0xaf, 0x15, 0x4c, 0x2a, 0x70, 0x2a, 0x6b, 0x22, 0x0d,
  40358. 0x30, 0xe7, 0x56, 0xed, 0x2d, 0x4b, 0x85, 0x17, 0x49, 0x72,
  40359. 0x3a, 0x1b, 0x6f, 0x57, 0x1c, 0xf7, 0x72, 0x9e, 0x20, 0xdb,
  40360. 0x57, 0x1c, 0xfb, 0x36, 0x50, 0x52, 0xec, 0x5b, 0xd6, 0x6a,
  40361. 0x1b, 0xf8, 0x74, 0xad, 0xe6, 0x00, 0x74, 0x04, 0xc5, 0x99,
  40362. 0x83, 0xe4, 0x5a, 0x0c, 0xc3, 0xe8, 0x6d, 0x3a, 0xd7, 0x3c,
  40363. 0x3c, 0xc0, 0x1a, 0x28, 0xb3, 0x29, 0x7a, 0x10, 0x9e, 0x39,
  40364. 0x66, 0x5b, 0xc1, 0x38, 0xac, 0x21, 0x4e, 0xcd, 0x01, 0xf2,
  40365. 0xf6, 0x30, 0x2c, 0x2b, 0xb6, 0xbf, 0xf5, 0xea, 0x61, 0xaf,
  40366. 0x0c, 0xa6, 0x01, 0x11, 0x15, 0x19, 0x09, 0x8c, 0x7e, 0x69,
  40367. 0xdf, 0x3b, 0xea, 0xd3, 0x0a, 0x3a, 0xd7, 0xbd, 0xe1, 0x17,
  40368. 0xaf, 0x92, 0x3c, 0xf5, 0xfe, 0x35, 0xd6, 0xcf, 0x07, 0xa6,
  40369. 0xf7, 0xe9, 0xc1, 0x99, 0xed, 0x80, 0xe3, 0x12, 0xd5, 0x4b,
  40370. 0xb9, 0xdf, 0xaf, 0x4e, 0x52, 0xad, 0x8e, 0x66, 0x87, 0xe5,
  40371. 0x2c, 0xd0, 0x45, 0x70, 0xd9, 0x78, 0x8f, 0x4b, 0xf4, 0xe1,
  40372. 0xf1, 0x22, 0xf2, 0xe3, 0xed, 0x1f, 0xeb, 0xe9, 0x70, 0x31,
  40373. 0x4c, 0x65, 0x5f, 0x55, 0xee, 0x5d, 0xaa, 0x83, 0x87, 0x76,
  40374. 0xbe, 0x11, 0xae, 0xd7, 0xf2, 0xfb, 0x43, 0xe7, 0x17, 0x81,
  40375. 0x33, 0x15, 0x47, 0xa0, 0xf3, 0x8e, 0x84, 0x57, 0xff, 0x35,
  40376. 0x9e, 0x4a, 0x8a, 0xab, 0x50, 0x3a, 0x45, 0xe0, 0xc3, 0x73,
  40377. 0xca, 0x77, 0x61, 0x68, 0x38, 0xd0, 0xa3, 0x5f, 0x03, 0x8d,
  40378. 0x41, 0xc2, 0xd3, 0x4a, 0x17, 0xe0, 0xa8, 0xaa, 0x00, 0xf3,
  40379. 0xf2, 0x5b, 0xa8, 0xe1, 0x06, 0xa6, 0x2b, 0xdb, 0xe1, 0x74,
  40380. 0xbd, 0xc4, 0xd2, 0x2b, 0x55, 0x9a, 0xb0, 0xf8, 0x35, 0xd8,
  40381. 0x6b, 0xec, 0xdb, 0xc5, 0xf4, 0x6c, 0x40, 0x90, 0x6a, 0x68,
  40382. 0xc9, 0xb5, 0xcb, 0xbb, 0xd0, 0xb0, 0xbc, 0x9f, 0xb9, 0xaa,
  40383. 0x50, 0x14, 0x93, 0x3b, 0x9f, 0x25, 0xcb, 0x40, 0xb8, 0x08,
  40384. 0xcc, 0x13, 0xe5, 0xdc, 0x3f, 0x84, 0x96, 0xe0, 0x73, 0x7b,
  40385. 0x7d, 0x9e, 0x41, 0x92, 0x5d, 0xcc, 0xa4, 0xea, 0x4f, 0x93,
  40386. 0x0c, 0x40, 0x2e, 0x42, 0x8a, 0xe9, 0xb9, 0x12, 0x74, 0xbb,
  40387. 0x79, 0x7c, 0xb0, 0x37, 0x20, 0xb6, 0xaf, 0x43, 0x3a, 0x88,
  40388. 0x59, 0x7c, 0x68, 0x28, 0x5f, 0x98, 0xc2, 0xf0, 0x2a, 0xbc,
  40389. 0xa1, 0x61, 0x88, 0x1f, 0x43, 0xbc, 0x42, 0x8f, 0x43, 0xf3,
  40390. 0x7e, 0x16, 0x96, 0xfa, 0x92, 0x70, 0xaf, 0x3c, 0x9f, 0x4b,
  40391. 0xd9, 0x60, 0xe9, 0xf6, 0x2e, 0x84, 0xda, 0x88, 0x31, 0x34,
  40392. 0xa6, 0x85, 0x10, 0x05, 0xef, 0x40, 0xa8, 0xa5, 0x4f, 0x92,
  40393. 0x59, 0xf7, 0xe0, 0xc4, 0x2b, 0x12, 0x17, 0x71, 0xbe, 0x8c,
  40394. 0x4a, 0x02, 0xfe, 0x12, 0xb6, 0x3b, 0x85, 0x75, 0x37, 0xf3,
  40395. 0x73, 0x2d, 0x9c, 0x00, 0x5d, 0x80, 0xad, 0x20, 0x2f, 0x5a,
  40396. 0x0b, 0x17, 0x7e, 0x67, 0x72, 0x24, 0x5a, 0xb9, 0xf3, 0xb1,
  40397. 0x33, 0xa4, 0x57, 0x1d, 0x49, 0x72, 0x2c, 0x7f, 0x47, 0x15,
  40398. 0x07, 0xe0, 0x45, 0x14, 0xdd, 0x77, 0x86, 0x6d, 0x03, 0xbe,
  40399. 0x57, 0xd0, 0xaa, 0x18, 0xa6, 0xdd, 0x94, 0x18, 0x3f, 0x8a,
  40400. 0xf3, 0xb5, 0xd7, 0x5a, 0xec, 0xc8, 0x79, 0x7f, 0x51, 0x61,
  40401. 0x3c, 0x9b, 0xb2, 0x9b, 0xf3, 0xb4, 0x35, 0xd1, 0x38, 0xbf,
  40402. 0x37, 0xce, 0x54, 0xd1, 0xf8, 0xb6, 0x45, 0xeb, 0x52, 0x0d,
  40403. 0x9a, 0x09, 0x58, 0x0d, 0x2c, 0x0b, 0xb1, 0xf2, 0x30, 0x3a,
  40404. 0x95, 0xc1, 0x13, 0x91, 0xd2, 0x9f, 0x8d, 0x8d, 0xd0, 0x38,
  40405. 0x3e, 0x4c, 0xae, 0x4a, 0x55, 0xa7, 0x42, 0x11, 0x83, 0xc4,
  40406. 0x70, 0xf0, 0x2b, 0x68, 0x9e, 0x07, 0xad, 0xb7, 0x83, 0xc6,
  40407. 0x53, 0x3c, 0xfb, 0x0a, 0x5d, 0x24, 0xdc, 0xe1, 0x55, 0x72,
  40408. 0xcf, 0xce, 0x3e, 0xc8, 0xd0, 0x57, 0x8a, 0x82, 0x5e, 0x78,
  40409. 0x2b, 0x80, 0xc5, 0xb9, 0x09, 0x46, 0xf8, 0x90, 0x39, 0x52,
  40410. 0xa9, 0xce, 0x3f, 0x3d, 0x41, 0x3b, 0x28, 0x45, 0xa3, 0xb3,
  40411. 0x21, 0xc2, 0xcd, 0x14, 0x49, 0x41, 0x6c, 0x38, 0xda, 0x1b,
  40412. 0x5f, 0x16, 0x49, 0xf9, 0x65, 0x00, 0x4e, 0xb4, 0x20, 0x55,
  40413. 0x70, 0xe8, 0x58, 0x1a, 0x18, 0xbf, 0x41, 0xef, 0x31, 0xb1,
  40414. 0xe7, 0x8d, 0x89, 0xc1, 0x48, 0xe8, 0xf5, 0x57, 0x35, 0xfa,
  40415. 0xc1, 0x79, 0xee, 0x2c, 0xe8, 0x7d, 0xb6, 0x03, 0xcc, 0x66,
  40416. 0x09, 0x6f, 0x52, 0x84, 0x0a, 0x34, 0x18, 0x2c, 0x01, 0x45,
  40417. 0x81, 0x00, 0xe5, 0x5e, 0x8d, 0xae, 0x1c, 0x96, 0x8b, 0x45,
  40418. 0x73, 0x00, 0x0a, 0xb5, 0xcf, 0x8d, 0x0e, 0x35, 0x5d, 0x1a,
  40419. 0x0e, 0xbf, 0x64, 0x9a, 0x52, 0x20, 0x48, 0xc6, 0xb9, 0x40,
  40420. 0xd3, 0x2c, 0x52, 0xca, 0x93, 0xcf, 0xbb, 0x94, 0x06, 0xf3,
  40421. 0x97, 0xee, 0xcc, 0x5d, 0xa3, 0xea, 0xf8, 0x5a, 0x39, 0x77,
  40422. 0x34, 0xd7, 0xf6, 0x4e, 0xbe, 0x8a, 0x07, 0x5f, 0x51, 0x53,
  40423. 0xc5, 0x1b, 0x8c, 0x47, 0x8f, 0x34, 0x0e, 0x60, 0x0a, 0x90,
  40424. 0xe2, 0xda, 0x7b, 0xef, 0xd6, 0xf5, 0x5d, 0xe5, 0x32, 0x37,
  40425. 0x75, 0x99, 0x81, 0x4a, 0x2a, 0x78, 0x71, 0xdc, 0xf4, 0xe5,
  40426. 0xca, 0xd8, 0x6b, 0x3b, 0x90, 0x68, 0x2e, 0x93, 0xc5, 0x10,
  40427. 0x42, 0x5d, 0x38, 0x90, 0x32, 0x46, 0xea, 0x87, 0xe0, 0xbc,
  40428. 0xb8, 0x9a, 0x18, 0x20, 0x68, 0x85, 0x6d, 0x9b, 0xc9, 0x8f,
  40429. 0x9b, 0xd2, 0xbe, 0x15, 0x12, 0x68, 0xd0, 0xb0, 0x16, 0x5f,
  40430. 0xe2, 0x69, 0x1d, 0x04, 0x00, 0xfc, 0x63, 0x33, 0xcd, 0x1f,
  40431. 0x89, 0xcd, 0x52, 0xff, 0xec, 0x19, 0x69, 0x74, 0xa3, 0xce,
  40432. 0x4d, 0xab, 0x93, 0xe4, 0xc6, 0x13, 0x56, 0x27, 0xc9, 0x25,
  40433. 0x5a, 0x01, 0xb2, 0x36, 0x8b, 0x61, 0xe5, 0x8b, 0x98, 0xac,
  40434. 0xe4, 0x2a, 0xb6, 0x40, 0x9f, 0x42, 0xe4, 0x1b, 0x52, 0xf7,
  40435. 0xfd, 0xd8, 0x30, 0x07, 0x33, 0xf9, 0x47, 0xcb, 0x3c, 0xad,
  40436. 0x12, 0xc1, 0xcc, 0x29, 0x62, 0x49, 0x04, 0x0c, 0x23, 0x97,
  40437. 0x5a, 0xa4, 0x84, 0x67, 0xde, 0x5a, 0xe5, 0x36, 0xd2, 0x88,
  40438. 0xf1, 0xd4, 0xeb, 0x13, 0x81, 0x54, 0x51, 0x11, 0xe3, 0xba,
  40439. 0xbc, 0xee, 0xdd, 0x6c, 0xcd, 0xe6, 0xb4, 0xa1, 0x8b, 0x0b,
  40440. 0x66, 0xfb, 0x8e, 0x50, 0xa0, 0xda, 0x69, 0x8d, 0xcc, 0x2d,
  40441. 0xe4, 0x2c, 0xc4, 0x37, 0xdf, 0x61, 0xc0, 0x03, 0xbd, 0x8b,
  40442. 0x28, 0xca, 0xd2, 0x8c, 0x1c, 0xf1, 0xa4, 0x26, 0x69, 0xe5,
  40443. 0xcf, 0x45, 0xdb, 0x5a, 0x47, 0x79, 0xed, 0x9f, 0xf7, 0xd2,
  40444. 0xdb, 0xba, 0x46, 0x53, 0x4f, 0xce, 0xa8, 0xbe, 0x8f, 0x4a,
  40445. 0xd6, 0xdf, 0x2e, 0x06, 0xe6, 0x4c, 0x9a, 0xc1, 0xb6, 0x49,
  40446. 0xed, 0xc4, 0xeb, 0xaa, 0xa4, 0x29, 0x6d, 0xd4, 0xcc, 0x8c,
  40447. 0xb6, 0x40, 0x11, 0x39, 0x69, 0xf7, 0x75, 0xcd, 0xb1, 0x99,
  40448. 0x46, 0x4e, 0xde, 0xcb, 0xf6, 0x9d, 0x32, 0xf3, 0xc9, 0x47,
  40449. 0x47, 0x7a, 0xcb, 0xfb, 0xa3, 0x0c, 0x3b, 0xdf, 0xb7, 0xde,
  40450. 0xec, 0x99, 0xde, 0xb0, 0x26, 0x04, 0x34, 0xae, 0x6b, 0xfc,
  40451. 0x99, 0xbc, 0xde, 0xd5, 0xbe, 0xe7, 0xeb, 0xf9, 0xe7, 0xa6,
  40452. 0x01, 0x9a, 0x0c, 0x5e, 0x66, 0xe6, 0x53, 0xe4, 0xd1, 0x58,
  40453. 0xac, 0xda, 0x69, 0x77, 0x7b, 0x68, 0xd6, 0x30, 0x2a, 0x9c,
  40454. 0x6b, 0xbe, 0x9f, 0x3d, 0x71, 0xd6, 0x54, 0xcd, 0x59, 0x4e,
  40455. 0x1f, 0xe3, 0x83, 0x4e, 0xd1, 0x8e, 0xaf, 0x97, 0xa8, 0xe5,
  40456. 0xb6, 0x59, 0x77, 0xa8, 0x02, 0x20, 0xe4, 0xeb, 0x44, 0x71,
  40457. 0xbc, 0x07, 0x14, 0x79, 0x4f, 0x0c, 0x27, 0x06, 0x39, 0xcf,
  40458. 0x7c, 0xef, 0x2b, 0x9b, 0x5e, 0xc4, 0x6d, 0x79, 0x13, 0x00,
  40459. 0x43, 0x6f, 0x51, 0x77, 0xb5, 0xc3, 0x72, 0xad, 0x13, 0xa9,
  40460. 0xe5, 0x9a, 0x5b, 0x1a, 0x99, 0x74, 0xc0, 0x7a, 0xf9, 0xc5,
  40461. 0xb0, 0x58, 0x35, 0x1c, 0xa5, 0x51, 0xdb, 0xa1, 0x14, 0xcd,
  40462. 0x26, 0x71, 0xb1, 0xe7, 0xaa, 0x14, 0xa7, 0x46, 0x93, 0xd3,
  40463. 0x5c, 0x8c, 0x1a, 0x91, 0x77, 0x46, 0x2e, 0x15, 0xaa, 0x9e,
  40464. 0xf7, 0x2b, 0x79, 0x41, 0x76, 0xf7, 0x22, 0x53, 0x7d, 0x51,
  40465. 0xdb, 0x98, 0x3d, 0x5b, 0x78, 0x5f, 0xc3, 0xc9, 0x29, 0xa3,
  40466. 0xff, 0x75, 0x82, 0x06, 0x9a, 0x16, 0x5e, 0xa4, 0x79, 0x0d,
  40467. 0xd1, 0x6d, 0x08, 0xff, 0x43, 0xef, 0x9c, 0xf3, 0x1b, 0x7a,
  40468. 0x3f, 0x34, 0xbe, 0x19, 0x15, 0x06, 0x33, 0xdb, 0xa5, 0x71,
  40469. 0xcb, 0x5f, 0x6b, 0x8d, 0xbd, 0x5b, 0x32, 0x91, 0xb2, 0x37,
  40470. 0x3d, 0xb4, 0x40, 0x9e, 0x02, 0x9b, 0xb7, 0x68, 0x20, 0x58,
  40471. 0x5c, 0xab, 0xcb, 0xc8, 0x23, 0x2d, 0x77, 0xcc, 0x0b, 0xf6,
  40472. 0x78, 0x6b, 0x80, 0x06, 0x91, 0xa9, 0xfd, 0x7e, 0xfa, 0x25,
  40473. 0x98, 0x9f, 0xcc, 0x79, 0x0a, 0x1a, 0x54, 0x83, 0xac, 0x64,
  40474. 0x16, 0x90, 0xe5, 0xd9, 0xa7, 0xd7, 0x1b, 0x86, 0x0d, 0xe6,
  40475. 0xe6, 0x22, 0x2b, 0x1f, 0x44, 0x49, 0x98, 0x9c, 0x51, 0x6f,
  40476. 0xcf, 0x58, 0x4a, 0xfa, 0xfa, 0x84, 0x12, 0xa5, 0x10, 0xf4,
  40477. 0xca, 0xf0, 0x98, 0x2b, 0xc9, 0x03, 0x71, 0x37, 0xe7, 0xdc,
  40478. 0xc2, 0xb1, 0x4e, 0x64, 0xde, 0x4f, 0x46, 0x0d, 0x6b, 0x25,
  40479. 0x88, 0x5d, 0xd6, 0xff, 0x23, 0x46, 0x57, 0x36, 0x14, 0x18,
  40480. 0xa7, 0xcb, 0xb8, 0xbd, 0xf0, 0xc5, 0x37, 0x36, 0xee, 0xe1,
  40481. 0xed, 0x9f, 0x4d, 0xd4, 0x39, 0xe5, 0x92, 0xcf, 0x95, 0x4d,
  40482. 0x66, 0x36, 0x5d, 0xd0, 0xcc, 0x07, 0xcf, 0x15, 0x5a, 0xce,
  40483. 0x14, 0xb8, 0xda, 0x0d, 0x3d, 0x1b, 0x45, 0xc5, 0x2e, 0x34,
  40484. 0x43, 0x25, 0x02, 0x3a, 0xcd, 0x14, 0x45, 0xfb, 0x3e, 0xf9,
  40485. 0x88, 0x5d, 0x0d, 0x29, 0x31, 0xb9, 0xa1, 0xe6, 0x31, 0x18,
  40486. 0x52, 0x46, 0x3f, 0x22, 0x4f, 0x9f, 0x7a, 0x65, 0x36, 0x88,
  40487. 0xa3, 0x1c, 0x3e, 0x6f, 0x50, 0x7a, 0x36, 0xbe, 0x56, 0x7e,
  40488. 0x50, 0xcb, 0x7a, 0x10, 0xa0, 0xec, 0xf6, 0x82, 0xd6, 0x30,
  40489. 0x1c, 0xe8, 0x4c, 0x50, 0xf9, 0x3e, 0xdb, 0xac, 0xbe, 0x4f,
  40490. 0x90, 0xb1, 0xd5, 0x1b, 0x12, 0x95, 0xfb, 0xe8, 0x08, 0x64,
  40491. 0x56, 0x7c, 0x96, 0xcc, 0x90, 0xb1, 0xbc, 0xa0, 0xf5, 0x32,
  40492. 0x69, 0xb3, 0x5f, 0x27, 0x0f, 0xbe, 0xc9, 0xbd, 0xeb, 0xfa,
  40493. 0x4b, 0x5c, 0xc5, 0x99, 0x9e, 0x5a, 0x04, 0xcc, 0xd0, 0x4d,
  40494. 0x29, 0xe8, 0x84, 0x55, 0x8c, 0xd7, 0xc4, 0x06, 0x13, 0x4d,
  40495. 0x92, 0xe5, 0x98, 0x9c, 0x4c, 0xc1, 0xf7, 0xaf, 0x7b, 0xd5,
  40496. 0x2b, 0x92, 0x68, 0x68, 0x19, 0x70, 0x4c, 0x9e, 0x46, 0xb8,
  40497. 0x34, 0xeb, 0x01, 0x47, 0xbe, 0x59, 0xab, 0x0b, 0x22, 0x25,
  40498. 0xe7, 0x56, 0xa8, 0xb4, 0x93, 0x3c, 0xd5, 0x98, 0x9f, 0x61,
  40499. 0x2e, 0xfa, 0xcb, 0x5f, 0x5b, 0xd8, 0x09, 0x83, 0xe9, 0x40,
  40500. 0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
  40501. 0x0a, 0x93
  40502. };
  40503. #endif
  40504. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_sig[] = {
  40505. 0x20, 0xff, 0x12, 0xe1, 0x87, 0xf6, 0x11, 0x38, 0xff, 0x41, 0xd0, 0x8f,
  40506. 0xcd, 0x7e, 0xd1, 0xf6, 0x21, 0x17, 0xd0, 0x46, 0xe9, 0x86, 0x83, 0x1b,
  40507. 0xaf, 0xe5, 0x2b, 0x59, 0x21, 0xd1, 0x6b, 0xc9, 0xdb, 0x34, 0xdc, 0xba,
  40508. 0xfd, 0xd3, 0xf8, 0x71, 0x49, 0xd8, 0x31, 0xbc, 0x48, 0x83, 0x22, 0x7b,
  40509. 0xfd, 0x6a, 0x93, 0xa6, 0x39, 0x4c, 0xda, 0xdb, 0x15, 0xe7, 0x41, 0x14,
  40510. 0xb4, 0xb8, 0xfe, 0xb0, 0x1f, 0xf9, 0x0a, 0x2c, 0x0b, 0xc0, 0xac, 0x09,
  40511. 0x84, 0x69, 0x5e, 0x64, 0x8c, 0xa8, 0xee, 0xa1, 0x52, 0x22, 0xde, 0x0d,
  40512. 0xc7, 0x25, 0xef, 0xa8, 0xfd, 0x8c, 0xb9, 0x45, 0x4f, 0xa4, 0x9c, 0xbc,
  40513. 0x70, 0xf2, 0x88, 0xea, 0x79, 0x13, 0xb0, 0xfc, 0xe6, 0x41, 0x48, 0x1c,
  40514. 0x33, 0x48, 0xa2, 0x77, 0x75, 0x37, 0x9f, 0xc1, 0x86, 0x94, 0xcd, 0x69,
  40515. 0x98, 0x87, 0x47, 0x49, 0x75, 0x93, 0xf1, 0xa4, 0x2d, 0x8e, 0xa8, 0x7e,
  40516. 0x0f, 0x95, 0xf5, 0x3e, 0x5d, 0x31, 0x2d, 0xc9, 0x58, 0x1c, 0x42, 0xfd,
  40517. 0x79, 0x6a, 0x49, 0xa3, 0x84, 0xc5, 0x2e, 0x8d, 0x96, 0x9c, 0xc8, 0x05,
  40518. 0x93, 0xdb, 0x6d, 0xbf, 0x83, 0x34, 0xc2, 0x81, 0x47, 0x90, 0xc9, 0xa9,
  40519. 0x82, 0xbd, 0xe1, 0xc8, 0x89, 0xa2, 0x36, 0x47, 0xed, 0xfb, 0x47, 0x57,
  40520. 0x01, 0x1a, 0x75, 0x8c, 0x6b, 0x83, 0xcf, 0x56, 0xae, 0x52, 0x66, 0x8b,
  40521. 0xab, 0x7f, 0x0c, 0xec, 0xde, 0x5c, 0x13, 0xbe, 0xbd, 0x5b, 0x74, 0x28,
  40522. 0xb5, 0xd7, 0x68, 0xd5, 0xd2, 0xe9, 0x96, 0x3b, 0x55, 0xda, 0x3a, 0x93,
  40523. 0x3c, 0xd9, 0x9f, 0x53, 0x2a, 0x31, 0x84, 0x45, 0x3f, 0xee, 0x2b, 0xfc,
  40524. 0x92, 0xb0, 0x9c, 0xc6, 0x16, 0x16, 0x4f, 0x33, 0x41, 0x17, 0x58, 0xbe,
  40525. 0x5d, 0x57, 0x4b, 0x04, 0x82, 0xe3, 0xb3, 0x68, 0xdf, 0x7c, 0x93, 0xce,
  40526. 0x9d, 0xf6, 0x7e, 0x21, 0x3d, 0x28, 0x1c, 0xf0, 0x37, 0x46, 0xf2, 0xc2,
  40527. 0x73, 0x7c, 0xbe, 0x98, 0x0e, 0x09, 0x75, 0xa7, 0x21, 0x11, 0xa9, 0xd6,
  40528. 0xd1, 0x47, 0xac, 0xd0, 0x19, 0x48, 0x3b, 0x74, 0xc1, 0x3c, 0x37, 0x43,
  40529. 0x49, 0x12, 0x62, 0xee, 0xaf, 0x5c, 0x38, 0xf7, 0x8a, 0xce, 0xb3, 0x7a,
  40530. 0x05, 0x16, 0xd4, 0x71, 0x8b, 0xbe, 0x1a, 0xe0, 0x1e, 0xbc, 0x4b, 0x54,
  40531. 0x0f, 0xb5, 0x73, 0x2b, 0xb8, 0x3a, 0x75, 0xf0, 0x26, 0xcd, 0xf9, 0xca,
  40532. 0x32, 0xf9, 0x7e, 0x15, 0x38, 0x75, 0x9c, 0x4d, 0xbc, 0x11, 0xf8, 0xea,
  40533. 0x8e, 0xe8, 0x38, 0x17, 0xc5, 0x62, 0xf4, 0x34, 0xfb, 0xd6, 0xf5, 0x76,
  40534. 0xfc, 0xa3, 0xf3, 0x44, 0xf9, 0xab, 0x2e, 0x9a, 0x68, 0xcd, 0xa1, 0x29,
  40535. 0xff, 0xda, 0xe8, 0xb5, 0xb0, 0x20, 0x5d, 0x02, 0x01, 0x62, 0x26, 0x44,
  40536. 0x32, 0xc8, 0x94, 0xf8, 0xf1, 0xaa, 0xf9, 0xc2, 0x86, 0xcb, 0x55, 0x7f,
  40537. 0x8d, 0xb3, 0xf6, 0x63, 0xb1, 0xa4, 0x95, 0x57, 0xb8, 0x1d, 0xc3, 0x42,
  40538. 0xd2, 0x4b, 0x69, 0xcd, 0x7a, 0x10, 0x5b, 0x6a, 0x13, 0xd1, 0x02, 0x98,
  40539. 0x38, 0x87, 0x9b, 0x9a, 0x5a, 0x66, 0x73, 0xcb, 0x75, 0xd0, 0x7a, 0x4b,
  40540. 0xad, 0x23, 0x06, 0x1c, 0xc8, 0x6b, 0x0c, 0xa8, 0xfe, 0x7b, 0x8f, 0x65,
  40541. 0x50, 0xd7, 0xf7, 0x76, 0x88, 0x42, 0xe0, 0x5e, 0x18, 0x91, 0x8b, 0x99,
  40542. 0x37, 0x56, 0x08, 0x91, 0xe7, 0x01, 0xe7, 0x05, 0xd5, 0xed, 0x43, 0x25,
  40543. 0x71, 0x7e, 0x3e, 0xfc, 0xc4, 0xfd, 0xed, 0x8b, 0x85, 0x16, 0x8c, 0xe3,
  40544. 0x05, 0xee, 0x51, 0x02, 0xa4, 0x4b, 0xd8, 0x3c, 0xcf, 0x4d, 0x2f, 0x2d,
  40545. 0x68, 0x6e, 0xc1, 0xd5, 0xfa, 0x91, 0xfd, 0x6a, 0xe0, 0x64, 0x85, 0x35,
  40546. 0x9c, 0x75, 0xe6, 0x0d, 0xb8, 0xec, 0x97, 0x88, 0x62, 0x98, 0x78, 0x75,
  40547. 0xc7, 0x1e, 0x68, 0xa7, 0xb9, 0x7b, 0xab, 0x75, 0x7a, 0x72, 0x3c, 0x7b,
  40548. 0xab, 0x60, 0x03, 0xb7, 0x38, 0x13, 0xe4, 0x96, 0x6e, 0xcb, 0x95, 0xcc,
  40549. 0xdc, 0x6a, 0x47, 0x67, 0x77, 0xd7, 0x95, 0xc4, 0x87, 0x66, 0xc2, 0x7e,
  40550. 0x42, 0x90, 0x59, 0x4f, 0xd6, 0xf3, 0xf4, 0xa7, 0xd0, 0x29, 0xf9, 0x5d,
  40551. 0x4b, 0x06, 0x06, 0xf7, 0x6e, 0xb2, 0xab, 0xb0, 0x8e, 0x21, 0xa6, 0xff,
  40552. 0x5e, 0x7b, 0x47, 0xb6, 0x3a, 0xa6, 0x9e, 0x19, 0xf6, 0xdf, 0x9b, 0x3b,
  40553. 0x3d, 0x07, 0x37, 0xd1, 0x0b, 0xa8, 0xf3, 0x9c, 0x43, 0x89, 0xee, 0xba,
  40554. 0x03, 0xee, 0x38, 0x74, 0x13, 0x09, 0x8e, 0x47, 0x4e, 0xa9, 0x14, 0xf5,
  40555. 0xb0, 0x55, 0xe0, 0x03, 0xe5, 0xb9, 0x53, 0xef, 0x03, 0x15, 0x60, 0xb3,
  40556. 0x4a, 0x71, 0x31, 0x4b, 0xf1, 0xc8, 0xe4, 0x63, 0x9b, 0x8b, 0x78, 0x3c,
  40557. 0x1f, 0xac, 0x27, 0x20, 0xa8, 0x53, 0x7d, 0xdd, 0x72, 0xd3, 0x90, 0x8f,
  40558. 0x71, 0xa6, 0xa7, 0xeb, 0xb0, 0xeb, 0x42, 0x96, 0xa4, 0xc3, 0xba, 0xc6,
  40559. 0x3c, 0xe7, 0x7b, 0x15, 0x1e, 0xfa, 0x15, 0x23, 0x37, 0xf3, 0xc8, 0xb2,
  40560. 0xf9, 0x46, 0x04, 0xd1, 0x5e, 0x44, 0xd7, 0x8f, 0x70, 0xb1, 0x0a, 0xde,
  40561. 0x6a, 0xe3, 0xaf, 0x9e, 0x49, 0x55, 0x78, 0x79, 0x11, 0x22, 0x87, 0xa9,
  40562. 0x54, 0x7c, 0xb4, 0x83, 0xe1, 0x25, 0xcd, 0x89, 0xa6, 0x91, 0x21, 0x7b,
  40563. 0xbe, 0x3d, 0x2f, 0x46, 0xb5, 0x5b, 0x50, 0x1a, 0xc8, 0x8d, 0x32, 0xf3,
  40564. 0x62, 0x1f, 0x24, 0x64, 0xe8, 0xb6, 0x02, 0x4f, 0x1f, 0x52, 0x3c, 0x40,
  40565. 0xfc, 0x72, 0x38, 0xd4, 0xba, 0x40, 0x8e, 0xb7, 0xc0, 0x97, 0x06, 0x16,
  40566. 0xd5, 0xe3, 0x39, 0x45, 0xd7, 0x7c, 0x0e, 0xed, 0x6b, 0x19, 0x19, 0x0a,
  40567. 0x8e, 0xcb, 0x2b, 0xee, 0x4d, 0xa1, 0x5e, 0x84, 0x22, 0x66, 0xcd, 0x4f,
  40568. 0xb9, 0x1a, 0x25, 0x85, 0x02, 0xc0, 0x67, 0xc4, 0xd5, 0x1a, 0xcb, 0xbb,
  40569. 0xde, 0x4d, 0x3c, 0x3c, 0x62, 0x9f, 0x76, 0x8f, 0x15, 0x29, 0xa5, 0xbb,
  40570. 0x5a, 0x48, 0x38, 0x66, 0xfa, 0x56, 0x0a, 0x09, 0xbd, 0xdf, 0xdf, 0x4a,
  40571. 0xe7, 0x0e, 0xa6, 0xb1, 0xb5, 0x7c, 0xe1, 0xed, 0x8d, 0x63, 0x07, 0x42,
  40572. 0xf3, 0xf8, 0x15, 0x28, 0x7c, 0x09, 0xf5, 0x02, 0x69, 0x1b, 0x88, 0x1e,
  40573. 0x3d, 0xad, 0x5f, 0x46, 0xed, 0xab, 0x2b, 0x11, 0x96, 0x73, 0xa8, 0xe8,
  40574. 0xe6, 0x64, 0x7d, 0xae, 0x13, 0xa1, 0x7d, 0x54, 0xae, 0xc0, 0x82, 0xeb,
  40575. 0x2a, 0xd1, 0x76, 0xb7, 0x9f, 0xbd, 0x33, 0x8f, 0xe7, 0xe6, 0x79, 0x92,
  40576. 0xa6, 0xaf, 0x61, 0x91, 0x49, 0xbc, 0xd2, 0x3c, 0x6f, 0x8b, 0xbe, 0x8f,
  40577. 0x5f, 0x1f, 0x00, 0x2c, 0x2e, 0x2c, 0xa0, 0x14, 0xcf, 0x34, 0x42, 0x44,
  40578. 0x41, 0x11, 0xd7, 0x37, 0xd3, 0x99, 0x44, 0x36, 0x43, 0x03, 0xb9, 0x50,
  40579. 0x4f, 0xab, 0xfe, 0x48, 0xe2, 0x4b, 0xed, 0x51, 0x8b, 0xe0, 0x04, 0x3c,
  40580. 0x93, 0x28, 0x55, 0xc8, 0x5a, 0xb3, 0x52, 0x2c, 0x56, 0xbd, 0x43, 0xb9,
  40581. 0x4a, 0x6c, 0x4c, 0xcc, 0xda, 0xba, 0x9c, 0xe6, 0x3e, 0x50, 0x8b, 0x1a,
  40582. 0xe5, 0x83, 0xc1, 0x60, 0x55, 0xb2, 0x02, 0x16, 0x54, 0x33, 0x62, 0x69,
  40583. 0x7c, 0x7d, 0x94, 0xf2, 0xb0, 0x3a, 0x22, 0xf0, 0x21, 0x46, 0xd7, 0x94,
  40584. 0x53, 0xec, 0x63, 0x4c, 0x3e, 0xc3, 0x71, 0xd1, 0xb9, 0x2e, 0x16, 0xe8,
  40585. 0x17, 0x63, 0x7e, 0x0c, 0x83, 0x05, 0x72, 0xe6, 0x20, 0x60, 0x34, 0xae,
  40586. 0x0e, 0x54, 0xa0, 0x57, 0x75, 0x93, 0x2e, 0xb8, 0x6c, 0xec, 0xda, 0x44,
  40587. 0x1b, 0xac, 0xd6, 0x75, 0xc5, 0x79, 0x3c, 0xc2, 0xa6, 0xa2, 0x7f, 0x3a,
  40588. 0xb0, 0xec, 0xeb, 0xc1, 0xe6, 0xd6, 0xae, 0xac, 0x2e, 0x55, 0x30, 0x1c,
  40589. 0x81, 0xa4, 0x4c, 0x35, 0x0e, 0xd8, 0xa6, 0x4e, 0xea, 0x0e, 0xbf, 0x79,
  40590. 0xf7, 0xdf, 0x55, 0xfc, 0xf9, 0x24, 0xb0, 0xa6, 0xba, 0xc3, 0x72, 0x42,
  40591. 0x60, 0x06, 0x44, 0x03, 0xe3, 0x40, 0x3c, 0x2a, 0x13, 0xf7, 0xdf, 0x3d,
  40592. 0xb7, 0x0d, 0x86, 0x6c, 0xb0, 0x0f, 0x2e, 0x72, 0x91, 0x16, 0x4f, 0x5f,
  40593. 0xd0, 0x3e, 0x8c, 0x36, 0xed, 0xa8, 0x6f, 0xbc, 0x65, 0xb0, 0x65, 0x99,
  40594. 0x47, 0x50, 0xa5, 0x9c, 0xea, 0xee, 0x8a, 0x44, 0x70, 0xf5, 0x31, 0x1a,
  40595. 0xe9, 0x11, 0xc1, 0xce, 0xe0, 0x21, 0x52, 0x70, 0x89, 0xf7, 0xc3, 0x35,
  40596. 0xfa, 0x55, 0x5a, 0xc5, 0x10, 0x02, 0xc4, 0xc7, 0xf7, 0xe1, 0xaf, 0x49,
  40597. 0x48, 0x61, 0xe7, 0x0d, 0xa1, 0x2d, 0x7d, 0x03, 0x00, 0x38, 0xa7, 0xd5,
  40598. 0xd3, 0xbf, 0x95, 0x29, 0xed, 0xcc, 0x70, 0x3e, 0xbe, 0x95, 0x8a, 0xdf,
  40599. 0xaf, 0xbf, 0xec, 0xf8, 0x6a, 0x4f, 0x9e, 0x69, 0xee, 0x4e, 0x3d, 0x8b,
  40600. 0x58, 0xa0, 0x2e, 0xb5, 0x83, 0x6a, 0x0e, 0x04, 0xa4, 0xa9, 0x74, 0xcb,
  40601. 0x4f, 0xb0, 0x39, 0x37, 0x8f, 0xcf, 0xbf, 0x77, 0xe4, 0x1a, 0x74, 0xcf,
  40602. 0x0e, 0x0d, 0x2d, 0x6e, 0x1d, 0xba, 0xc1, 0xf5, 0x7c, 0x54, 0x6e, 0x92,
  40603. 0xec, 0x4b, 0x03, 0xc3, 0xa4, 0x44, 0xad, 0x3e, 0x4f, 0xa4, 0xd9, 0xe9,
  40604. 0x71, 0x3c, 0xe6, 0xb6, 0xbe, 0xe7, 0xfc, 0x72, 0x76, 0x86, 0x9a, 0x73,
  40605. 0xb1, 0xb3, 0xf3, 0x84, 0xb6, 0x2a, 0x40, 0x0b, 0x8c, 0xae, 0xb3, 0xc4,
  40606. 0xdc, 0xb5, 0x21, 0x85, 0x87, 0xdc, 0x19, 0x18, 0xd5, 0xba, 0xa4, 0x5e,
  40607. 0x88, 0x89, 0xa4, 0xf4, 0x88, 0x75, 0xc2, 0x7a, 0xb4, 0xee, 0x9d, 0x54,
  40608. 0x66, 0x97, 0x70, 0x08, 0x8f, 0x99, 0x84, 0x5d, 0x5e, 0xa7, 0x6f, 0x92,
  40609. 0xe8, 0xa3, 0x65, 0xfa, 0x0e, 0x87, 0xfb, 0x3c, 0xe9, 0x17, 0x2d, 0xc7,
  40610. 0x2d, 0x30, 0x8f, 0x41, 0x82, 0x68, 0x2b, 0xf1, 0x67, 0x8e, 0xf7, 0x05,
  40611. 0x78, 0xfa, 0xc3, 0x61, 0xba, 0x35, 0xe7, 0x2f, 0x19, 0xef, 0x71, 0x36,
  40612. 0xac, 0x5b, 0xf0, 0x45, 0x30, 0x70, 0xdc, 0xc7, 0xab, 0x7b, 0x62, 0x17,
  40613. 0x9d, 0xc4, 0x43, 0x6f, 0xfc, 0x02, 0x56, 0x5f, 0x65, 0xaa, 0x68, 0x3b,
  40614. 0x5c, 0xfa, 0x71, 0x28, 0x89, 0xe9, 0x28, 0x2f, 0x95, 0x4b, 0xfc, 0xe6,
  40615. 0xe7, 0xc8, 0x44, 0x28, 0x5c, 0x3c, 0x08, 0x5f, 0x9c, 0xbc, 0x41, 0x68,
  40616. 0x91, 0x98, 0x7a, 0x00, 0x63, 0xc9, 0x5c, 0x75, 0x8f, 0xcc, 0x33, 0x77,
  40617. 0x7b, 0xd0, 0x2d, 0xe8, 0xa2, 0x98, 0xa4, 0x1b, 0xfa, 0x09, 0x67, 0x7b,
  40618. 0x25, 0x96, 0x19, 0xf4, 0x77, 0x33, 0x20, 0x4f, 0x19, 0xf6, 0x9c, 0x6c,
  40619. 0x2e, 0xd9, 0x68, 0x95, 0xb0, 0xe2, 0x18, 0x06, 0xe5, 0x84, 0x8e, 0xf7,
  40620. 0xbf, 0x6c, 0x96, 0xa8, 0x9d, 0x37, 0xc7, 0x28, 0xa1, 0x3d, 0x90, 0x8c,
  40621. 0x40, 0x3d, 0xe2, 0x51, 0xfd, 0x55, 0x09, 0xf8, 0x83, 0x43, 0x44, 0x4d,
  40622. 0x1c, 0x8a, 0x8d, 0x36, 0x84, 0x64, 0xc4, 0xfa, 0x1d, 0x72, 0x04, 0x0b,
  40623. 0x1d, 0x49, 0x13, 0x88, 0x78, 0x5f, 0x07, 0x9b, 0xc8, 0x01, 0x9c, 0x3c,
  40624. 0xfc, 0xff, 0x0f, 0xd5, 0x13, 0xcd, 0x15, 0x98, 0xcc, 0xe6, 0x59, 0x1e,
  40625. 0x83, 0x38, 0x8f, 0x6c, 0x75, 0xbe, 0xdf, 0xe9, 0x1b, 0xc5, 0xb9, 0x6b,
  40626. 0xa4, 0x5a, 0x0c, 0xae, 0x98, 0x8d, 0x93, 0xfa, 0x76, 0x7f, 0x0d, 0x0b,
  40627. 0xe8, 0xa0, 0x3b, 0x9e, 0x5e, 0xc8, 0xa8, 0xcc, 0x02, 0xc9, 0x86, 0x9c,
  40628. 0x78, 0xaf, 0x6e, 0x6a, 0xf4, 0xfe, 0x49, 0xad, 0xc5, 0x93, 0xae, 0x62,
  40629. 0xbd, 0xe3, 0x3a, 0xa8, 0xf2, 0x60, 0xb5, 0x29, 0xde, 0x5f, 0x12, 0x02,
  40630. 0x2d, 0x43, 0x90, 0xf5, 0x9d, 0x9d, 0x97, 0x29, 0xfa, 0xdd, 0x60, 0x41,
  40631. 0x64, 0xb7, 0xa5, 0x03, 0x72, 0x10, 0x2b, 0xdd, 0x5b, 0x60, 0xe6, 0xf0,
  40632. 0xe1, 0xd7, 0xa5, 0x97, 0xec, 0xb4, 0x9a, 0x4c, 0x3e, 0x16, 0xa2, 0x82,
  40633. 0xb3, 0xc3, 0x3f, 0x3e, 0x5d, 0x32, 0xac, 0x5a, 0x40, 0xb4, 0x00, 0xfa,
  40634. 0xd9, 0x47, 0xe8, 0x77, 0xa8, 0x96, 0x5c, 0x60, 0x04, 0x9c, 0x5c, 0xdf,
  40635. 0x24, 0x3b, 0xa7, 0x4a, 0x58, 0x25, 0x12, 0x9a, 0xa8, 0x7b, 0x3e, 0x14,
  40636. 0xc8, 0x06, 0x79, 0x23, 0xea, 0x91, 0x7f, 0xe1, 0x78, 0x41, 0x6c, 0xdb,
  40637. 0x8c, 0xeb, 0x66, 0x35, 0x87, 0x87, 0x81, 0x65, 0x2c, 0xef, 0x3a, 0x6e,
  40638. 0xae, 0xb3, 0x6c, 0xe9, 0x86, 0x50, 0x6d, 0x89, 0xd6, 0x27, 0x0a, 0xdb,
  40639. 0xf8, 0xd4, 0xb8, 0x85, 0x8e, 0x37, 0xa6, 0x56, 0xf7, 0x58, 0x18, 0x4c,
  40640. 0x44, 0xcf, 0xeb, 0xc4, 0x79, 0x19, 0xfc, 0x2e, 0x53, 0x18, 0x0e, 0x7b,
  40641. 0x51, 0x86, 0xf3, 0x59, 0x13, 0xb2, 0xaf, 0xd3, 0xee, 0xf4, 0xd5, 0xbf,
  40642. 0x2c, 0xb8, 0x6d, 0x71, 0x74, 0x7c, 0x67, 0x54, 0xa7, 0x4b, 0x03, 0xa9,
  40643. 0x1b, 0x62, 0x95, 0x9f, 0xc3, 0xf0, 0x71, 0x39, 0x2d, 0x26, 0xaf, 0xaf,
  40644. 0xa7, 0xa5, 0x58, 0xf8, 0xf8, 0x8a, 0xe0, 0x62, 0x90, 0x3f, 0x72, 0x9d,
  40645. 0x21, 0x82, 0x76, 0x3e, 0x4c, 0x5d, 0xe0, 0xb5, 0x67, 0x23, 0xe3, 0x13,
  40646. 0x1a, 0x29, 0xa3, 0xda, 0xa4, 0xb4, 0x5c, 0x1d, 0x47, 0xdf, 0xdf, 0xc9,
  40647. 0x93, 0x6c, 0xb2, 0xb5, 0x22, 0xb3, 0x47, 0x2b, 0xcf, 0xf0, 0x36, 0x87,
  40648. 0x51, 0x3c, 0x79, 0x41, 0x70, 0xbd, 0xea, 0x70, 0xa2, 0x29, 0x90, 0x55,
  40649. 0x30, 0x6f, 0x3e, 0x50, 0xc8, 0x38, 0xd6, 0xfa, 0x6f, 0xe3, 0x39, 0x67,
  40650. 0x88, 0x52, 0x1f, 0xd3, 0x52, 0xbf, 0x3e, 0x7b, 0x2a, 0xe5, 0x1e, 0xcd,
  40651. 0xf9, 0xf1, 0x91, 0x1d, 0x04, 0x61, 0x25, 0xbb, 0xe1, 0x33, 0xe3, 0x66,
  40652. 0x46, 0xed, 0x06, 0x8d, 0xc3, 0x4f, 0x20, 0xc6, 0x24, 0xa7, 0xb5, 0x49,
  40653. 0x3b, 0xc7, 0xe6, 0xa0, 0x77, 0x58, 0xd9, 0x70, 0xb1, 0xf5, 0xec, 0x94,
  40654. 0x19, 0xf3, 0x5b, 0x0f, 0x9a, 0xe4, 0xad, 0x37, 0x81, 0xaf, 0x68, 0x7b,
  40655. 0xe5, 0x67, 0xb5, 0xae, 0x7f, 0x2d, 0x64, 0x78, 0x68, 0x5a, 0xd1, 0x8f,
  40656. 0x1c, 0xc0, 0xc3, 0x5b, 0x21, 0x77, 0xe4, 0xa8, 0x5d, 0x05, 0x50, 0xc1,
  40657. 0x92, 0xee, 0x36, 0x2d, 0xd2, 0xff, 0xee, 0xc2, 0x11, 0x99, 0xee, 0xd7,
  40658. 0x48, 0xfb, 0x6a, 0xa3, 0xc9, 0xb7, 0x0c, 0xc1, 0xe5, 0x12, 0xbf, 0x6f,
  40659. 0x58, 0x66, 0x35, 0x34, 0x26, 0xaa, 0xbe, 0xc3, 0x33, 0x86, 0xfd, 0xc0,
  40660. 0x1c, 0xa5, 0xe4, 0x1e, 0x91, 0xc4, 0x55, 0x4e, 0xf1, 0xcb, 0xd2, 0x0b,
  40661. 0xe8, 0x0d, 0x89, 0x6a, 0x00, 0xbd, 0x7b, 0xf5, 0x3d, 0x1a, 0x4a, 0x48,
  40662. 0xfc, 0xf0, 0x5b, 0xcd, 0xdb, 0xb2, 0xa0, 0x27, 0x4b, 0x8f, 0xf7, 0x87,
  40663. 0x78, 0x13, 0xdb, 0x3f, 0xfb, 0x0b, 0xda, 0x22, 0xb3, 0x2b, 0x3a, 0x38,
  40664. 0xd2, 0x29, 0x73, 0x77, 0xb8, 0xd6, 0xec, 0xab, 0xb4, 0xfe, 0xbe, 0xbb,
  40665. 0x6e, 0xe2, 0xc8, 0x45, 0x7b, 0x0d, 0x36, 0x28, 0x0f, 0x45, 0x72, 0xea,
  40666. 0x6d, 0x38, 0x02, 0x5e, 0x48, 0x89, 0x12, 0x24, 0x1b, 0x33, 0x0f, 0xe9,
  40667. 0xf4, 0xce, 0xf8, 0x27, 0x16, 0x37, 0x29, 0xae, 0xe8, 0x22, 0x03, 0x31,
  40668. 0xa9, 0xa0, 0x73, 0x0c, 0x40, 0xe4, 0xfc, 0x6b, 0xe2, 0x1c, 0x8d, 0x7c,
  40669. 0x40, 0x82, 0x72, 0x28, 0xd0, 0x7d, 0xe5, 0xef, 0x05, 0x14, 0x80, 0x28,
  40670. 0x11, 0x32, 0x0d, 0x63, 0x8a, 0xc3, 0x7c, 0xfe, 0xf5, 0x06, 0x0e, 0xb0,
  40671. 0x78, 0x5c, 0x3a, 0xb6, 0x54, 0x37, 0x46, 0xa7, 0x43, 0x4f, 0x05, 0xec,
  40672. 0xe4, 0x9f, 0xd8, 0x55, 0x1f, 0x70, 0xb3, 0xe6, 0xbc, 0x46, 0x34, 0x9e,
  40673. 0xfc, 0xa4, 0x57, 0x8f, 0x0f, 0x25, 0x6f, 0x9f, 0xb3, 0x80, 0x21, 0x0b,
  40674. 0xa1, 0xca, 0x59, 0xcd, 0x37, 0xf7, 0xc9, 0xcb, 0xbe, 0x91, 0xad, 0x07,
  40675. 0x4f, 0xc7, 0x4e, 0x04, 0xbd, 0x38, 0x8b, 0x63, 0xb5, 0x51, 0xac, 0xc8,
  40676. 0x83, 0x3a, 0xa7, 0xe1, 0x77, 0xbc, 0xa4, 0x0c, 0x6c, 0x50, 0xeb, 0x46,
  40677. 0xe1, 0x45, 0x9a, 0x7b, 0x01, 0xca, 0x54, 0xf0, 0x0f, 0xa0, 0x1f, 0x43,
  40678. 0x9a, 0x19, 0x70, 0x2e, 0x70, 0x5a, 0xcf, 0x3b, 0x1b, 0x41, 0xfd, 0xd3,
  40679. 0x9a, 0xa2, 0x36, 0x14, 0xf0, 0xdd, 0xb0, 0x12, 0x6d, 0xcf, 0x55, 0x3f,
  40680. 0xef, 0x0a, 0xc1, 0x80, 0xa9, 0x68, 0xc3, 0x98, 0x03, 0x46, 0x34, 0xce,
  40681. 0x91, 0xb2, 0x7a, 0x94, 0xd2, 0xe7, 0xb9, 0x9c, 0x56, 0xb8, 0xf8, 0xd6,
  40682. 0xff, 0xbf, 0x8b, 0x39, 0x45, 0x04, 0x45, 0xc9, 0xa2, 0xe2, 0xbb, 0x50,
  40683. 0x68, 0x13, 0x32, 0x1e, 0x09, 0x51, 0xb7, 0xb9, 0xcf, 0x5f, 0xcc, 0x54,
  40684. 0xd2, 0xf3, 0xc1, 0x9d, 0xa0, 0x8d, 0x22, 0xc8, 0x7e, 0x1b, 0xc6, 0x14,
  40685. 0xde, 0x5f, 0x52, 0xb4, 0x69, 0x71, 0xca, 0x58, 0x1d, 0x1e, 0x89, 0xcb,
  40686. 0x56, 0x78, 0x7a, 0x85, 0xee, 0xfd, 0xf6, 0x7e, 0xbe, 0x49, 0x9b, 0xb1,
  40687. 0x05, 0x95, 0x12, 0xe9, 0x63, 0xbd, 0x61, 0x9a, 0x26, 0xf9, 0x0b, 0x9f,
  40688. 0x23, 0x0a, 0x59, 0x55, 0x93, 0xd3, 0x2d, 0xca, 0x66, 0x45, 0x03, 0xb7,
  40689. 0xf0, 0x88, 0x9e, 0xc1, 0x11, 0xbb, 0x62, 0x2c, 0x6f, 0xac, 0x3e, 0x87,
  40690. 0xd7, 0xe6, 0x4a, 0x44, 0x83, 0x04, 0x5d, 0x5d, 0xbc, 0x3c, 0xce, 0x83,
  40691. 0x2b, 0x11, 0x42, 0x02, 0x73, 0x1c, 0x24, 0x90, 0xd9, 0x1a, 0x7d, 0x96,
  40692. 0x82, 0x33, 0x75, 0x1e, 0x59, 0xea, 0xa7, 0x99, 0xe1, 0x5b, 0xdc, 0xe4,
  40693. 0x07, 0xc5, 0x48, 0x07, 0xb4, 0xbc, 0x80, 0x0e, 0xbd, 0x63, 0x6e, 0x66,
  40694. 0xf1, 0x12, 0xb6, 0x67, 0xe0, 0x14, 0x74, 0x9f, 0xbb, 0xb3, 0xb8, 0x16,
  40695. 0xd0, 0x25, 0xe9, 0x21, 0x80, 0x1a, 0x32, 0xb0, 0x58, 0x9a, 0x62, 0x17,
  40696. 0x18, 0x9d, 0x64, 0x2d, 0x47, 0x89, 0x82, 0x3b, 0x8c, 0x5d, 0x60, 0xc4,
  40697. 0x54, 0x69, 0xaa, 0xb4, 0x6a, 0x1d, 0x16, 0xb0, 0xe2, 0x5d, 0x7d, 0xeb,
  40698. 0xb9, 0x80, 0x37, 0xcd, 0x5b, 0xf0, 0xa1, 0xa8, 0x39, 0xb2, 0xd6, 0x3a,
  40699. 0xc8, 0xcd, 0xca, 0xaf, 0xcb, 0x3b, 0x54, 0xc2, 0x67, 0x49, 0xf3, 0xf1,
  40700. 0x11, 0x4d, 0x53, 0x7c, 0x46, 0x8d, 0x22, 0xf6, 0x9a, 0x0d, 0x9e, 0xda,
  40701. 0x37, 0xc6, 0x06, 0x00, 0xca, 0xb6, 0xb6, 0x99, 0xc5, 0xb6, 0x81, 0x7e,
  40702. 0x87, 0x62, 0xcf, 0x07, 0x76, 0xc1, 0x5f, 0xfe, 0x86, 0xfc, 0x5b, 0xa0,
  40703. 0xac, 0xca, 0xcb, 0x7d, 0xf5, 0x5a, 0xc2, 0x5e, 0x41, 0x48, 0x35, 0xc4,
  40704. 0x71, 0x9d, 0xc4, 0x0a, 0x79, 0x6f, 0xe3, 0x6d, 0x47, 0xd4, 0xaa, 0xfd,
  40705. 0x97, 0xe7, 0xb0, 0x7e, 0x61, 0xf1, 0x7d, 0x7e, 0xf8, 0x78, 0x4c, 0x2e,
  40706. 0x65, 0x51, 0xeb, 0x99, 0xd0, 0x3e, 0x24, 0x4c, 0xe0, 0x40, 0x7e, 0x2d,
  40707. 0xf7, 0x00, 0x9d, 0x50, 0x87, 0xce, 0x1f, 0x9a, 0xd2, 0x76, 0x00, 0x09,
  40708. 0xeb, 0x10, 0x1b, 0x4c, 0xf1, 0x43, 0x0e, 0x35, 0xbb, 0x23, 0x2e, 0x26,
  40709. 0x3d, 0x66, 0xa3, 0x0f, 0xf6, 0x10, 0x8b, 0x67, 0xce, 0x66, 0xfd, 0xb5,
  40710. 0x07, 0xdc, 0x04, 0x69, 0xad, 0xe0, 0x4d, 0xdf, 0xdb, 0x2f, 0x87, 0xf7,
  40711. 0xde, 0xc3, 0x77, 0x89, 0x71, 0xfd, 0x70, 0x38, 0xed, 0xe6, 0x27, 0xb1,
  40712. 0xbd, 0x94, 0x5f, 0x39, 0x20, 0x72, 0x59, 0xc4, 0x39, 0xd0, 0x20, 0x5d,
  40713. 0xe2, 0xe7, 0xe0, 0x00, 0x61, 0xc7, 0x65, 0xbd, 0xef, 0x05, 0xb3, 0xc7,
  40714. 0x7e, 0xae, 0xc5, 0x83, 0x7f, 0xc1, 0x32, 0x4e, 0x2a, 0x17, 0x64, 0x4e,
  40715. 0x2a, 0x9a, 0x2d, 0x26, 0x99, 0xa2, 0xd7, 0x37, 0x3a, 0x10, 0x6a, 0x89,
  40716. 0x72, 0x43, 0x0e, 0x3a, 0x03, 0x4c, 0xf9, 0xfe, 0xe8, 0xfc, 0x87, 0x71,
  40717. 0x37, 0x71, 0x5a, 0x05, 0xbc, 0x4e, 0x20, 0x4c, 0xd7, 0xf9, 0x8d, 0x4e,
  40718. 0xb8, 0xb8, 0x56, 0x07, 0xc8, 0x6e, 0x34, 0x6d, 0x45, 0x83, 0x34, 0xf0,
  40719. 0x77, 0xfb, 0x18, 0xec, 0x72, 0xf6, 0x4c, 0xfb, 0xba, 0x84, 0xe9, 0x89,
  40720. 0x3d, 0xfd, 0xb7, 0x0d, 0x70, 0xae, 0xa4, 0x48, 0x6b, 0x39, 0xf8, 0x62,
  40721. 0xc0, 0x7f, 0x0c, 0xf2, 0xa3, 0xfa, 0x7a, 0x64, 0x83, 0x57, 0x7d, 0x4c,
  40722. 0x04, 0x96, 0xd7, 0x9d, 0x10, 0x8b, 0x34, 0x48, 0x17, 0xff, 0x74, 0x5c,
  40723. 0x9c, 0xbe, 0xeb, 0xe5, 0x52, 0x94, 0x6a, 0x34, 0x6f, 0xf7, 0x95, 0x32,
  40724. 0x38, 0x5a, 0x9b, 0x08, 0xf6, 0xda, 0x8c, 0x0f, 0x9c, 0x5d, 0x04, 0x45,
  40725. 0xd4, 0xe9, 0xa4, 0x7a, 0xc4, 0xfd, 0x70, 0xfe, 0xa1, 0x3d, 0x21, 0xa0,
  40726. 0x01, 0xe5, 0x21, 0xca, 0xa7, 0xd9, 0xf1, 0x9f, 0x45, 0xe1, 0xe8, 0x2d,
  40727. 0x27, 0xe6, 0x87, 0xc8, 0x0d, 0xad, 0x13, 0xdb, 0xfe, 0x2f, 0xaa, 0x2b,
  40728. 0xdc, 0xa6, 0x1a, 0xc9, 0x19, 0x78, 0x1a, 0x1f, 0x10, 0xcf, 0x31, 0xe1,
  40729. 0x06, 0x28, 0x66, 0xb3, 0xa7, 0xa2, 0xa6, 0xf1, 0x3b, 0x2d, 0xd3, 0x81,
  40730. 0xaf, 0x6f, 0xc9, 0x88, 0x76, 0xe9, 0x83, 0x6c, 0x52, 0xb9, 0x70, 0x51,
  40731. 0x87, 0x6b, 0x8b, 0xbd, 0x5b, 0x9c, 0xa9, 0xf3, 0xcb, 0x55, 0xd1, 0x76,
  40732. 0x40, 0xe1, 0x90, 0xb9, 0x4c, 0xbd, 0xab, 0x1d, 0xa0, 0x5b, 0x5b, 0x34,
  40733. 0x14, 0x2f, 0x87, 0x8f, 0x63, 0xa0, 0x2d, 0x29, 0x4e, 0x50, 0x4b, 0x18,
  40734. 0x5f, 0x86, 0xac, 0x1b, 0x93, 0xe9, 0x59, 0x38, 0xa1, 0x2a, 0x36, 0x21,
  40735. 0xb2, 0xa4, 0xc0, 0x79, 0xc1, 0x60, 0xfc, 0x0f, 0xbf, 0x99, 0x04, 0x9d,
  40736. 0x4b, 0x17, 0x60, 0x5b, 0xcd, 0x78, 0x03, 0xd7, 0x7c, 0x4b, 0x9b, 0x17,
  40737. 0x58, 0x24, 0x60, 0xb8, 0x08, 0x92, 0x48, 0x4f, 0x66, 0x42, 0x9a, 0x98,
  40738. 0x2a, 0x99, 0x9a, 0x8f, 0xdd, 0xd7, 0x09, 0xf3, 0x22, 0x66, 0x62, 0xef,
  40739. 0xe5, 0x64, 0xd3, 0xdf, 0x31, 0xaa, 0x84, 0x4c, 0xa5, 0x3f, 0x4e, 0x27,
  40740. 0x48, 0x37, 0x96, 0x63, 0xbf, 0x8d, 0xe1, 0xf0, 0xd1, 0xef, 0x95, 0x1a,
  40741. 0xe6, 0xf4, 0x02, 0x61, 0xbf, 0xe3, 0xbc, 0x8b, 0x3d, 0x0b, 0x77, 0x91,
  40742. 0xc0, 0x5d, 0xfb, 0xe6, 0x7e, 0xab, 0x5e, 0xc5, 0x1c, 0x5b, 0x16, 0xfd,
  40743. 0x88, 0xa4, 0x78, 0x4c, 0x06, 0x77, 0xc3, 0x6e, 0x84, 0x0c, 0xda, 0xbf,
  40744. 0xf3, 0x8e, 0xd3, 0x61, 0x65, 0xac, 0xf2, 0x18, 0x70, 0x68, 0x84, 0x6f,
  40745. 0x9f, 0x3a, 0x94, 0x81, 0xa6, 0xc7, 0xc3, 0x92, 0xee, 0x4b, 0x20, 0x15,
  40746. 0x4e, 0x03, 0x76, 0x51, 0x5b, 0x4e, 0xe1, 0x5c, 0x51, 0x5e, 0x1b, 0x9c,
  40747. 0x30, 0x25, 0x79, 0xdd, 0x70, 0x12, 0xec, 0xdc, 0x45, 0x95, 0x45, 0x43,
  40748. 0xcd, 0xbb, 0xae, 0xa0, 0x0d, 0x43, 0xb4, 0xc9, 0x8c, 0x62, 0xfd, 0x7b,
  40749. 0xed, 0x50, 0x78, 0xb7, 0xa6, 0x94, 0xcb, 0x98, 0xb0, 0xbe, 0x09, 0xd9,
  40750. 0x0c, 0xb2, 0xc4, 0x8b, 0x96, 0x93, 0xd9, 0x26, 0xc6, 0x6d, 0x26, 0x93,
  40751. 0x32, 0x4e, 0x86, 0x72, 0x74, 0x92, 0x00, 0x72, 0x0b, 0x20, 0xa3, 0x2b,
  40752. 0x94, 0xe6, 0x10, 0x56, 0x5a, 0x41, 0x71, 0x92, 0x08, 0xce, 0x6c, 0xc4,
  40753. 0x1d, 0x9e, 0x71, 0x82, 0x64, 0x23, 0xe5, 0x15, 0xef, 0x4a, 0x7c, 0x4d,
  40754. 0xe3, 0x92, 0xbc, 0xa3, 0xa2, 0x29, 0xb7, 0x46, 0xfa, 0x8f, 0x9f, 0xc2,
  40755. 0x5d, 0xe4, 0xc0, 0x9c, 0x3f, 0x40, 0x17, 0xae, 0x44, 0xf3, 0x28, 0x10,
  40756. 0x29, 0x24, 0xa9, 0x1c, 0x9e, 0xd2, 0x55, 0x4c, 0xee, 0x45, 0xfe, 0x4a,
  40757. 0x45, 0x12, 0xf5, 0xde, 0xc7, 0x64, 0x15, 0xc3, 0x4a, 0x77, 0x63, 0x05,
  40758. 0x8d, 0xa6, 0x31, 0xa0, 0xad, 0x64, 0xaf, 0x3c, 0x69, 0x2c, 0x25, 0x78,
  40759. 0xae, 0xa0, 0x88, 0x96, 0x8a, 0xc2, 0x9b, 0x8d, 0xee, 0x6f, 0x2e, 0x79,
  40760. 0x1f, 0xec, 0x32, 0x35, 0x75, 0x83, 0x19, 0x8b, 0xda, 0xca, 0xd0, 0xaf,
  40761. 0x6a, 0x6c, 0x42, 0xe8, 0x81, 0xb5, 0x69, 0x31, 0x0b, 0x7d, 0xbc, 0xd8,
  40762. 0xd2, 0xb7, 0x7a, 0x8f, 0xfa, 0xcf, 0x91, 0x07, 0x1f, 0xda, 0xa9, 0x1f,
  40763. 0xb7, 0x2d, 0xff, 0x50, 0x15, 0x2a, 0xef, 0x8c, 0xa1, 0xe3, 0x7f, 0x08,
  40764. 0x95, 0xf2, 0x99, 0x83, 0x1f, 0x97, 0x71, 0x3e, 0x35, 0x3c, 0x8c, 0xe7,
  40765. 0x08, 0xd8, 0xa6, 0x1f, 0x0c, 0xa6, 0x52, 0xdc, 0x73, 0xa0, 0xfc, 0xd2,
  40766. 0x73, 0xe9, 0x27, 0x9d, 0xfd, 0x7a, 0x4a, 0x29, 0xd3, 0x12, 0x26, 0x13,
  40767. 0x0f, 0xce, 0xea, 0x56, 0x99, 0x61, 0x78, 0x47, 0x2c, 0xa0, 0x16, 0xa0,
  40768. 0xe2, 0x64, 0x97, 0x57, 0x31, 0xf0, 0x32, 0x5b, 0x44, 0x93, 0x76, 0x8b,
  40769. 0x59, 0x63, 0x5c, 0x5b, 0x0f, 0xe1, 0xe7, 0x74, 0x98, 0x11, 0x2d, 0x90,
  40770. 0xe4, 0xde, 0xd4, 0x3a, 0xc2, 0xfd, 0x24, 0xe3, 0x1f, 0x7a, 0xf4, 0x40,
  40771. 0xbb, 0x51, 0x92, 0x8f, 0x68, 0x9c, 0x51, 0xab, 0xdc, 0xf6, 0x1e, 0x96,
  40772. 0xca, 0x56, 0x5c, 0x92, 0xca, 0xb2, 0x1b, 0x2e, 0x6d, 0x20, 0x28, 0xb3,
  40773. 0x0a, 0x8e, 0xfd, 0xa9, 0xa2, 0x38, 0x74, 0x60, 0x37, 0xa6, 0x96, 0x02,
  40774. 0x20, 0x8a, 0x9a, 0x2b, 0x8c, 0xb9, 0x6d, 0xec, 0xff, 0xbf, 0x88, 0xbd,
  40775. 0x6c, 0xb4, 0x10, 0xbd, 0xfa, 0x5a, 0xeb, 0xb2, 0x6b, 0x74, 0x13, 0x2d,
  40776. 0xa5, 0xdb, 0x60, 0x93, 0xc6, 0xed, 0x39, 0x4f, 0xc5, 0x63, 0xe1, 0x9e,
  40777. 0x57, 0x1f, 0xe7, 0x47, 0xa4, 0xfb, 0x7f, 0xfa, 0x3a, 0x46, 0x50, 0x3a,
  40778. 0xd8, 0xd3, 0x83, 0xf5, 0xe6, 0x5e, 0xf8, 0x09, 0x0d, 0xfa, 0x33, 0xe1,
  40779. 0x50, 0xe4, 0x36, 0x3e, 0x0a, 0x5d, 0xe6, 0xf8, 0x2e, 0x17, 0x87, 0x8f,
  40780. 0xe1, 0x8c, 0x82, 0x73, 0xbd, 0xdd, 0x3b, 0x77, 0x47, 0x9f, 0x42, 0xd7,
  40781. 0xf4, 0x2d, 0x6c, 0xef, 0xcc, 0x22, 0x15, 0x3c, 0xe9, 0x26, 0xea, 0xbc,
  40782. 0xee, 0x09, 0xd3, 0xea, 0x84, 0x0f, 0x46, 0xa8, 0xe0, 0xda, 0xc5, 0x57,
  40783. 0x02, 0x54, 0xb6, 0x88, 0x2b, 0x37, 0xe5, 0x96, 0xc5, 0x33, 0xb7, 0x45,
  40784. 0x5d, 0xb7, 0xc7, 0xfd, 0xa0, 0xfa, 0x85, 0x1b, 0x2f, 0xe1, 0xec, 0x89,
  40785. 0xc6, 0xb2, 0x51, 0x71, 0xcb, 0x08, 0x82, 0x3e, 0xc9, 0xed, 0x80, 0x9d,
  40786. 0x37, 0x31, 0x9d, 0x15, 0xde, 0x24, 0x6f, 0xbd, 0x0e, 0x73, 0xa2, 0xb8,
  40787. 0x7e, 0x29, 0x7e, 0x96, 0xe4, 0xbb, 0xd6, 0x23, 0x17, 0xff, 0x33, 0x97,
  40788. 0x9c, 0x87, 0xe0, 0xe5, 0x0f, 0xb9, 0xb6, 0x31, 0x33, 0xad, 0xf8, 0xd8,
  40789. 0xdb, 0xa0, 0x71, 0x13, 0xe4, 0x1c, 0xce, 0xd0, 0x7e, 0x65, 0x7b, 0xa0,
  40790. 0x38, 0x17, 0x53, 0x4f, 0x71, 0x75, 0x6d, 0x02, 0x61, 0xc4, 0x52, 0xf8,
  40791. 0xe4, 0x2e, 0xbc, 0x52, 0xc1, 0xb1, 0x7e, 0x83, 0x0a, 0xa1, 0xd1, 0xcd,
  40792. 0x2f, 0xa0, 0x30, 0xfd, 0x41, 0x86, 0x7f, 0x26, 0xd1, 0xe7, 0xfc, 0xd7,
  40793. 0xc7, 0x37, 0xe5, 0x11, 0xa6, 0xc0, 0x9a, 0x75, 0x18, 0x04, 0x36, 0xca,
  40794. 0x8e, 0x26, 0x7d, 0xcf, 0xa2, 0x6a, 0x94, 0x9b, 0xc4, 0xf7, 0xc7, 0xeb,
  40795. 0x51, 0x13, 0xa3, 0x6f, 0x8c, 0x80, 0x5f, 0xae, 0xf0, 0x18, 0xa0, 0x88,
  40796. 0xe0, 0x8d, 0xb7, 0x80, 0x4e, 0x8c, 0xec, 0xc8, 0x7b, 0xeb, 0xac, 0x29,
  40797. 0xb7, 0x4a, 0x0f, 0x33, 0xdd, 0x9d, 0x89, 0x0a, 0x10, 0xb0, 0xce, 0x74,
  40798. 0x59, 0xa2, 0x62, 0x91, 0xc9, 0xac, 0x56, 0xcd, 0x69, 0xd3, 0x01, 0x6d,
  40799. 0x51, 0xe7, 0x04, 0xc3, 0xfb, 0xe9, 0x79, 0x1b, 0x72, 0x72, 0x1a, 0x90,
  40800. 0x0a, 0x20, 0x55, 0x85, 0xc1, 0x8b, 0xeb, 0x1e, 0x9f, 0x9f, 0x4a, 0x81,
  40801. 0x47, 0x97, 0x96, 0xbc, 0xc2, 0xe4, 0xc2, 0xfe, 0xa0, 0x20, 0xda, 0x70,
  40802. 0x0c, 0x2b, 0xe2, 0xd4, 0xc8, 0xcb, 0x46, 0x00, 0xb6, 0x7c, 0xfb, 0xbd,
  40803. 0x56, 0x94, 0x3d, 0x7f, 0x64, 0xf7, 0x88, 0xb5, 0xa7, 0xfe, 0xbe, 0x64,
  40804. 0x8a, 0xe4, 0x00, 0x08, 0x82, 0x5b, 0x8f, 0x98, 0x77, 0x87, 0xda, 0xaf,
  40805. 0x16, 0x25, 0x4a, 0x9a, 0xed, 0xfb, 0x50, 0x18, 0x45, 0x46, 0x2b, 0x73,
  40806. 0xff, 0xb9, 0xb9, 0xab, 0xa2, 0x8f, 0x3a, 0xaf, 0xc5, 0x0a, 0x14, 0x91,
  40807. 0xb2, 0x3f, 0xa6, 0x93, 0xf4, 0x81, 0x20, 0x77, 0xfa, 0x51, 0x79, 0x62,
  40808. 0xe8, 0xe6, 0x89, 0x52, 0x39, 0xd5, 0x01, 0xa2, 0x87, 0xa3, 0x53, 0x74,
  40809. 0x3c, 0x36, 0x8a, 0xc3, 0xb4, 0x44, 0x3b, 0x15, 0x21, 0xf6, 0xdc, 0x18,
  40810. 0x02, 0xd2, 0x57, 0xe5, 0x10, 0xf0, 0x3d, 0x61, 0xa7, 0x16, 0x85, 0x6f,
  40811. 0x71, 0x07, 0x75, 0x50, 0x4b, 0x21, 0x53, 0x47, 0x38, 0x35, 0x9e, 0xa7,
  40812. 0xd8, 0xfd, 0x74, 0x59, 0x15, 0x32, 0x7b, 0x89, 0xd0, 0x2c, 0xd9, 0xf6,
  40813. 0x40, 0x49, 0x79, 0xdc, 0xfb, 0x0a, 0x64, 0x59, 0x9b, 0x17, 0x47, 0x36,
  40814. 0xcb, 0xf0, 0xc3, 0xcc, 0x14, 0x8e, 0x1f, 0xa8, 0x12, 0xaa, 0xb7, 0x6a,
  40815. 0xba, 0x45, 0xf9, 0xc4, 0x44, 0xe7, 0xb5, 0x7c, 0xdd, 0xbe, 0x16, 0x76,
  40816. 0x52, 0x92, 0x3d, 0x78, 0xb7, 0xec, 0x81, 0x96, 0xd8, 0x7f, 0x34, 0x2a,
  40817. 0xa2, 0x64, 0x5f, 0xfd, 0xb1, 0x42, 0x4c, 0x79, 0x98, 0xc9, 0x17, 0x48,
  40818. 0x74, 0x12, 0x72, 0x2c, 0xde, 0x91, 0x7e, 0xa9, 0x49, 0x2a, 0xcc, 0x5c,
  40819. 0x60, 0x05, 0x25, 0x09, 0x72, 0x20, 0x80, 0x42, 0x7b, 0x18, 0xc2, 0xfc,
  40820. 0x2a, 0x5e, 0x3e, 0x2d, 0x61, 0xa6, 0xf6, 0x82, 0x42, 0x83, 0x81, 0x66,
  40821. 0x4d, 0xa6, 0xe1, 0xf9, 0xf6, 0x48, 0xd4, 0xc8, 0x69, 0xed, 0xee, 0xb5,
  40822. 0x7a, 0xcb, 0xf6, 0x0a, 0x76, 0x0e, 0x61, 0x8b, 0xf2, 0x1a, 0x8a, 0xa7,
  40823. 0x88, 0xb0, 0x90, 0xd5, 0x23, 0xaa, 0xe0, 0x2b, 0xd6, 0xd0, 0xef, 0x49,
  40824. 0x13, 0x88, 0xc7, 0x50, 0xf0, 0x9e, 0xd5, 0x28, 0xe1, 0xaa, 0x1d, 0xaf,
  40825. 0xd9, 0x73, 0xb3, 0x9e, 0xa7, 0xd8, 0xfc, 0xb9, 0x22, 0x97, 0x0e, 0x21,
  40826. 0xa0, 0xb9, 0xf9, 0xea, 0x1e, 0x95, 0x88, 0xda, 0x85, 0x7c, 0x32, 0x7c,
  40827. 0xbd, 0xef, 0xf8, 0x44, 0x25, 0x5f, 0x23, 0xfd, 0x14, 0x78, 0xc6, 0xdb,
  40828. 0x86, 0xee, 0xf8, 0xda, 0xc0, 0xae, 0x92, 0x6a, 0x03, 0xa9, 0x0a, 0xee,
  40829. 0x4a, 0x22, 0x5a, 0x6c, 0x39, 0xd3, 0x91, 0x7d, 0x91, 0x43, 0xac, 0x79,
  40830. 0xad, 0xab, 0xb7, 0x91, 0xb1, 0x20, 0x84, 0x7f, 0x0a, 0xd7, 0xa8, 0x62,
  40831. 0x95, 0xab, 0x04, 0xb6, 0xb2, 0xf1, 0xd4, 0xb0, 0xac, 0x52, 0x89, 0xb0,
  40832. 0x93, 0xdf, 0xdf, 0x80, 0x26, 0x0c, 0x32, 0x31, 0xb3, 0xba, 0xa1, 0xba,
  40833. 0x6f, 0xa3, 0x14, 0x5c, 0xfa, 0x37, 0x3b, 0x6a, 0xf2, 0xc4, 0x34, 0x27,
  40834. 0x08, 0x1a, 0xe4, 0xfc, 0x89, 0x58, 0x79, 0x34, 0x36, 0xe4, 0xad, 0x4b,
  40835. 0x3f, 0x57, 0x7b, 0xc1, 0x59, 0x2d, 0xb6, 0x54, 0x44, 0xbe, 0x4e, 0x5d,
  40836. 0x0d, 0x6a, 0xf3, 0xcd, 0xbf, 0xcd, 0x4d, 0x9f, 0x9a, 0x50, 0x09, 0xa4,
  40837. 0x6b, 0x8b, 0xb3, 0x01, 0x69, 0x6c, 0x69, 0x5d, 0x28, 0x73, 0x9e, 0xb5,
  40838. 0xc2, 0xc7, 0x6e, 0xff, 0x4c, 0x5c, 0x6b, 0x93, 0x22, 0xc1, 0x9f, 0xa6,
  40839. 0x71, 0xbf, 0x4d, 0x2d, 0x4e, 0x4e, 0x98, 0xa3, 0x6d, 0xab, 0x05, 0xa0,
  40840. 0xde, 0x34, 0x41, 0x28, 0xa4, 0x38, 0x75, 0x4e, 0xdf, 0x7f, 0xc9, 0xdd,
  40841. 0xbf, 0x5a, 0xd4, 0xcd, 0x38, 0x0c, 0x89, 0xe7, 0x0e, 0xfc, 0x0f, 0x27,
  40842. 0x39, 0x21, 0xa4, 0xa6, 0x07, 0x7b, 0x2a, 0x13, 0x56, 0xe7, 0x4e, 0x55,
  40843. 0x57, 0x71, 0x98, 0xb9, 0x3d, 0x59, 0xb5, 0xa8, 0x24, 0x18, 0x08, 0xa2,
  40844. 0x6e, 0x9a, 0xe5, 0x97, 0xa7, 0x38, 0xd9, 0x43, 0x9b, 0x19, 0x17, 0x34,
  40845. 0x03, 0xd6, 0xba, 0xe9, 0x71, 0x38, 0x26, 0x90, 0x78, 0x9e, 0x1c, 0x41,
  40846. 0x8d, 0x60, 0xdd, 0x0e, 0x12, 0x46, 0x37, 0xb4, 0x79, 0x87, 0x33, 0x12,
  40847. 0x24, 0xc4, 0x5a, 0x6c, 0x70, 0xa2, 0xb2, 0x58, 0xbb, 0xe7, 0xd6, 0x88,
  40848. 0x42, 0x2d, 0x49, 0xc8, 0x67, 0x1e, 0xc5, 0xed, 0x16, 0xa8, 0x1f, 0x36,
  40849. 0x2b, 0xfb, 0x0d, 0x51, 0x96, 0xc8, 0x78, 0xf2, 0xab, 0x82, 0xa1, 0xe2,
  40850. 0xaf, 0x8c, 0xa4, 0x13, 0x54, 0x90, 0xf1, 0xe7, 0xbb, 0xd1, 0x09, 0x23,
  40851. 0x76, 0x0e, 0x50, 0x32, 0xc5, 0x54, 0xbb, 0x1e, 0x12, 0x5d, 0x59, 0xf3,
  40852. 0xe9, 0xc9, 0xa4, 0xaa, 0xbc, 0x13, 0x1d, 0xf0, 0x79, 0x54, 0xae, 0x70,
  40853. 0xc0, 0xea, 0xcb, 0x21, 0x32, 0xe6, 0xe6, 0x8e, 0xaa, 0x51, 0x46, 0x25,
  40854. 0x1e, 0xf1, 0x3f, 0x9f, 0xf6, 0xff, 0x19, 0x53, 0x97, 0xbc, 0xa2, 0xb6,
  40855. 0x91, 0x59, 0x27, 0x1e, 0x39, 0x76, 0x76, 0x02, 0x0b, 0x03, 0x25, 0x6b,
  40856. 0x00, 0x02, 0xfa, 0x7d, 0x69, 0x5e, 0xde, 0x64, 0x33, 0xbf, 0xab, 0x3e,
  40857. 0x3f, 0x24, 0x32, 0x68, 0xbf, 0x90, 0x8f, 0x0f, 0xc5, 0x36, 0x58, 0x9e,
  40858. 0x9b, 0x11, 0xd1, 0x2a, 0x8a, 0x0d, 0xac, 0x3a, 0x23, 0xe2, 0x8e, 0xd6,
  40859. 0x0d, 0x4a, 0x8b, 0x45, 0x04, 0x47, 0xd9, 0x5a, 0x46, 0x6c, 0x70, 0x82,
  40860. 0xc7, 0x81, 0x67, 0xdc, 0xa6, 0xfa, 0x6a, 0x86, 0xfd, 0x01, 0xed, 0x90,
  40861. 0xf6, 0xe6, 0x26, 0x6d, 0xac, 0x52, 0x03, 0x4a, 0x91, 0x08, 0x7b, 0xa5,
  40862. 0x9c, 0xca, 0xd3, 0x2d, 0x79, 0xf1, 0xed, 0xcb, 0xaa, 0x8f, 0x77, 0xc8,
  40863. 0x17, 0xa8, 0xfb, 0x6c, 0x15, 0x62, 0xab, 0x34, 0xd1, 0xdd, 0x94, 0x3e,
  40864. 0xd4, 0x0c, 0x47, 0xed, 0x04, 0x91, 0xd2, 0xd7, 0x98, 0xb4, 0x43, 0x57,
  40865. 0xd1, 0x54, 0xef, 0x63, 0xba, 0xe3, 0x8a, 0x72, 0xc5, 0xb9, 0xf4, 0x30,
  40866. 0xfa, 0x16, 0x3c, 0xe1, 0xbb, 0xbe, 0x57, 0x90, 0xb9, 0xa1, 0xa0, 0x23,
  40867. 0xfa, 0xdd, 0xbe, 0x2f, 0xb3, 0xec, 0x41, 0x8b, 0x64, 0xeb, 0xc5, 0x41,
  40868. 0xea, 0xa8, 0x16, 0x76, 0x6f, 0x28, 0xda, 0x2b, 0x5f, 0x03, 0x0b, 0xe8,
  40869. 0x1c, 0x29, 0x71, 0xd8, 0x4e, 0x41, 0xdf, 0x39, 0x8e, 0x6a, 0x95, 0x79,
  40870. 0x85, 0x9c, 0xa9, 0x79, 0xd9, 0x8f, 0x33, 0xaf, 0x15, 0x3b, 0x5a, 0x82,
  40871. 0x56, 0x32, 0x98, 0x0c, 0xf6, 0xf6, 0x64, 0x42, 0xd4, 0x6a, 0x15, 0x0f,
  40872. 0xb9, 0x75, 0x22, 0xbd, 0x9a, 0x58, 0xa6, 0x01, 0x3a, 0x63, 0xf0, 0x80,
  40873. 0x78, 0x22, 0x80, 0xa0, 0x14, 0xe1, 0x37, 0x6b, 0xd4, 0x99, 0x3f, 0xc2,
  40874. 0xba, 0x2b, 0x8f, 0xf3, 0x56, 0xc8, 0x1b, 0xe4, 0x7a, 0x5e, 0x96, 0x60,
  40875. 0xee, 0x74, 0x54, 0xb6, 0x6d, 0x5c, 0x3d, 0x3e, 0x05, 0xf0, 0x9a, 0xf6,
  40876. 0xcd, 0xdd, 0x06, 0xdb, 0x8c, 0x21, 0xb9, 0xf5, 0x28, 0x57, 0x9c, 0x4f,
  40877. 0xb4, 0x08, 0xcf, 0xac, 0x6c, 0xfe, 0x30, 0xaf, 0xa2, 0xef, 0xcf, 0x93,
  40878. 0x15, 0xdd, 0x12, 0x16, 0x19, 0x7d, 0xbc, 0x57, 0xd9, 0xce, 0xbe, 0x0e,
  40879. 0xfc, 0xe1, 0xf0, 0x4a, 0x7c, 0xaa, 0xbf, 0x20, 0x64, 0x00, 0x34, 0x59,
  40880. 0xed, 0xea, 0x12, 0x58, 0x46, 0x4c, 0xc6, 0x2f, 0x77, 0x62, 0x1d, 0x82,
  40881. 0x5c, 0xe8, 0x98, 0x0d, 0xef, 0x5c, 0x0e, 0xec, 0x5d, 0x2e, 0x5f, 0xd2,
  40882. 0x22, 0x43, 0x2d, 0xe1, 0x02, 0xd5, 0x4a, 0x0a, 0x79, 0x6f, 0xa5, 0xec,
  40883. 0x48, 0xaa, 0xee, 0xf8, 0xe3, 0x5f, 0xdd, 0xe7, 0x26, 0x87, 0xb5, 0xc4,
  40884. 0xcf, 0xd9, 0x7f, 0xa8, 0xaa, 0xb6, 0xbe, 0xe9, 0x02, 0x49, 0x5d, 0x5f,
  40885. 0x81, 0x8b, 0xb9, 0xbd, 0xc0, 0xc9, 0xd5, 0xfe, 0x36, 0x3e, 0x49, 0x56,
  40886. 0x63, 0x8b, 0xce, 0xef, 0x48, 0x6e, 0xc0, 0xd4, 0x04, 0x0c, 0x33, 0x45,
  40887. 0x6e, 0x97, 0x9e, 0xa3, 0xae, 0xbc, 0xc2, 0xce, 0xdc, 0xe3, 0xff, 0x48,
  40888. 0x51, 0x68, 0x89, 0xad, 0xae, 0xc7, 0xd1, 0xde, 0xe2, 0xf9, 0xfe, 0x00,
  40889. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
  40890. 0x0c, 0x18, 0x20, 0x24, 0x2f, 0x33, 0x3f
  40891. };
  40892. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  40893. WOLFSSL_SMALL_STACK_STATIC const byte ml_dsa_87_draft_sig[] = {
  40894. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  40895. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  40896. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  40897. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  40898. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  40899. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  40900. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  40901. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  40902. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  40903. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  40904. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  40905. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  40906. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  40907. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  40908. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  40909. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  40910. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  40911. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  40912. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  40913. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  40914. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  40915. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  40916. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  40917. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  40918. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  40919. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  40920. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  40921. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  40922. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  40923. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  40924. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  40925. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  40926. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  40927. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  40928. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  40929. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  40930. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  40931. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  40932. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  40933. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  40934. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  40935. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  40936. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  40937. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  40938. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  40939. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  40940. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  40941. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  40942. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  40943. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  40944. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  40945. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  40946. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  40947. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  40948. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  40949. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  40950. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  40951. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  40952. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  40953. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  40954. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  40955. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  40956. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  40957. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  40958. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  40959. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  40960. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  40961. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  40962. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  40963. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  40964. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  40965. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  40966. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  40967. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  40968. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  40969. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  40970. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  40971. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  40972. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  40973. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  40974. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  40975. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  40976. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  40977. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  40978. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  40979. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  40980. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  40981. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  40982. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  40983. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  40984. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  40985. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  40986. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  40987. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  40988. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  40989. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  40990. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  40991. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  40992. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  40993. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  40994. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  40995. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  40996. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  40997. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  40998. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  40999. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  41000. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  41001. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  41002. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  41003. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  41004. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  41005. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  41006. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  41007. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  41008. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  41009. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  41010. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  41011. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  41012. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  41013. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  41014. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  41015. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  41016. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  41017. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  41018. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  41019. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  41020. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  41021. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  41022. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  41023. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  41024. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  41025. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  41026. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  41027. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  41028. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  41029. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  41030. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  41031. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  41032. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  41033. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  41034. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  41035. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  41036. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  41037. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  41038. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  41039. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  41040. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  41041. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  41042. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  41043. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  41044. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  41045. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  41046. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  41047. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  41048. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  41049. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  41050. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  41051. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  41052. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  41053. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  41054. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  41055. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  41056. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  41057. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  41058. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  41059. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  41060. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  41061. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  41062. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  41063. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  41064. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  41065. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  41066. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  41067. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  41068. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  41069. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  41070. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  41071. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  41072. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  41073. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  41074. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  41075. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  41076. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  41077. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  41078. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  41079. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  41080. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  41081. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  41082. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  41083. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  41084. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  41085. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  41086. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  41087. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  41088. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  41089. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  41090. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  41091. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  41092. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  41093. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  41094. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  41095. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  41096. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  41097. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  41098. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  41099. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  41100. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  41101. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  41102. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  41103. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  41104. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  41105. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  41106. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  41107. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  41108. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  41109. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  41110. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  41111. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  41112. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  41113. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  41114. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  41115. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  41116. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  41117. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  41118. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  41119. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  41120. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  41121. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  41122. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  41123. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  41124. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  41125. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  41126. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  41127. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  41128. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  41129. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  41130. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  41131. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  41132. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  41133. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  41134. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  41135. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  41136. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  41137. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  41138. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  41139. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  41140. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  41141. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  41142. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  41143. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  41144. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  41145. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  41146. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  41147. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  41148. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  41149. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  41150. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  41151. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  41152. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  41153. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  41154. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  41155. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  41156. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  41157. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  41158. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  41159. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  41160. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  41161. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  41162. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  41163. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  41164. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  41165. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  41166. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  41167. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  41168. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  41169. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  41170. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  41171. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  41172. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  41173. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  41174. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  41175. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  41176. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  41177. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  41178. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  41179. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  41180. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  41181. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  41182. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  41183. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  41184. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  41185. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  41186. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  41187. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  41188. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  41189. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  41190. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  41191. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  41192. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  41193. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  41194. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  41195. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  41196. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  41197. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  41198. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  41199. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  41200. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  41201. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  41202. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  41203. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  41204. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  41205. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  41206. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  41207. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  41208. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  41209. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  41210. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  41211. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  41212. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  41213. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  41214. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  41215. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  41216. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  41217. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  41218. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  41219. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  41220. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  41221. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  41222. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  41223. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  41224. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  41225. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  41226. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  41227. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  41228. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  41229. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  41230. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  41231. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  41232. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  41233. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  41234. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  41235. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  41236. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  41237. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  41238. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  41239. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  41240. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  41241. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  41242. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  41243. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  41244. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  41245. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  41246. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  41247. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  41248. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  41249. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  41250. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  41251. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  41252. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  41253. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  41254. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  41255. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  41256. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  41257. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  41258. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  41259. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  41260. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  41261. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  41262. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  41263. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  41264. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  41265. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  41266. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  41267. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  41268. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  41269. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  41270. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  41271. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  41272. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  41273. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  41274. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  41275. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  41276. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  41277. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  41278. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  41279. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  41280. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  41281. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  41282. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  41283. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  41284. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  41285. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  41286. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  41287. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  41288. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  41289. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  41290. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  41291. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  41292. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  41293. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  41294. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  41295. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  41296. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  41297. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  41298. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  41299. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  41300. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  41301. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  41302. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  41303. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  41304. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  41305. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  41306. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  41307. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  41308. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  41309. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  41310. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  41311. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  41312. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  41313. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  41314. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  41315. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  41316. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  41317. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  41318. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  41319. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  41320. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  41321. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  41322. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  41323. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  41324. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  41325. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  41326. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  41327. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  41328. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  41329. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  41330. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  41331. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  41332. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  41333. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  41334. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  41335. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  41336. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  41337. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  41338. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  41339. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  41340. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  41341. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  41342. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  41343. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  41344. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  41345. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  41346. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  41347. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  41348. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  41349. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  41350. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  41351. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  41352. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  41353. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  41354. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  41355. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  41356. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f
  41357. };
  41358. #endif
  41359. wc_test_ret_t ret;
  41360. ret = dilithium_param_vfy_test(WC_ML_DSA_87, ml_dsa_87_pub_key,
  41361. (word32)sizeof(ml_dsa_87_pub_key), ml_dsa_87_sig,
  41362. (word32)sizeof(ml_dsa_87_sig));
  41363. #ifdef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41364. if (ret == 0) {
  41365. ret = dilithium_param_vfy_test(WC_ML_DSA_87_DRAFT,
  41366. ml_dsa_87_draft_pub_key, (word32)sizeof(ml_dsa_87_draft_pub_key),
  41367. ml_dsa_87_draft_sig, (word32)sizeof(ml_dsa_87_draft_sig));
  41368. }
  41369. #endif
  41370. return ret;
  41371. }
  41372. #endif
  41373. #endif
  41374. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41375. static wc_test_ret_t dilithium_param_test(int param, WC_RNG* rng)
  41376. {
  41377. wc_test_ret_t ret;
  41378. dilithium_key* key;
  41379. byte* sig = NULL;
  41380. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41381. word32 sigLen;
  41382. byte msg[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
  41383. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41384. int res = 0;
  41385. #endif
  41386. #endif
  41387. key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT,
  41388. DYNAMIC_TYPE_TMP_BUFFER);
  41389. if (key == NULL) {
  41390. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41391. }
  41392. sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT,
  41393. DYNAMIC_TYPE_TMP_BUFFER);
  41394. if (sig == NULL) {
  41395. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  41396. }
  41397. ret = wc_dilithium_init(key);
  41398. if (ret != 0) {
  41399. ret = WC_TEST_RET_ENC_EC(ret);
  41400. return ret;
  41401. }
  41402. ret = wc_dilithium_set_level(key, param);
  41403. if (ret != 0)
  41404. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41405. ret = wc_dilithium_make_key(key, rng);
  41406. if (ret != 0)
  41407. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41408. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  41409. sigLen = wc_dilithium_sig_size(key);
  41410. if (sigLen <= 0)
  41411. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41412. ret = wc_dilithium_sign_msg(msg, (word32)sizeof(msg), sig, &sigLen, key,
  41413. rng);
  41414. if (ret != 0)
  41415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41416. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41417. ret = wc_dilithium_verify_msg(sig, sigLen, msg, (word32)sizeof(msg), &res,
  41418. key);
  41419. if (ret != 0)
  41420. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41421. if (res != 1)
  41422. ERROR_OUT(WC_TEST_RET_ENC_EC(res), out);
  41423. #endif
  41424. #endif
  41425. out:
  41426. wc_dilithium_free(key);
  41427. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41428. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41429. return ret;
  41430. }
  41431. #endif
  41432. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41433. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41434. /* Tests decoding a key from DER without the security level specified */
  41435. static wc_test_ret_t test_dilithium_decode_level(const byte* rawKey,
  41436. word32 rawKeySz,
  41437. int expectedLevel,
  41438. int isPublicOnlyKey)
  41439. {
  41440. int ret = 0;
  41441. #ifdef WOLFSSL_SMALL_STACK
  41442. dilithium_key *key = NULL;
  41443. #else
  41444. dilithium_key key[1];
  41445. #endif
  41446. word32 idx;
  41447. byte* der;
  41448. word32 derSz;
  41449. /* Size the buffer to accommodate the largest encoded key size */
  41450. const word32 maxDerSz = DILITHIUM_MAX_PRV_KEY_DER_SIZE;
  41451. /* Allocate DER buffer */
  41452. der = (byte*)XMALLOC(maxDerSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41453. if (der == NULL) {
  41454. return MEMORY_E;
  41455. }
  41456. #ifdef WOLFSSL_SMALL_STACK
  41457. key = (dilithium_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41458. if (key == NULL)
  41459. ret = MEMORY_E;
  41460. #endif
  41461. /* Initialize key */
  41462. if (ret == 0) {
  41463. ret = wc_dilithium_init(key);
  41464. }
  41465. /* Import raw key, setting the security level */
  41466. if (ret == 0) {
  41467. ret = wc_dilithium_set_level(key, expectedLevel);
  41468. }
  41469. if (ret == 0) {
  41470. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41471. if (isPublicOnlyKey) {
  41472. ret = wc_dilithium_import_public(rawKey, rawKeySz, key);
  41473. }
  41474. #endif
  41475. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41476. if (!isPublicOnlyKey) {
  41477. ret = wc_dilithium_import_private(rawKey, rawKeySz, key);
  41478. }
  41479. #endif
  41480. }
  41481. /* Export raw key as DER */
  41482. if (ret == 0) {
  41483. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41484. if (isPublicOnlyKey) {
  41485. ret = wc_Dilithium_PublicKeyToDer(key, der, maxDerSz, 1);
  41486. }
  41487. #endif
  41488. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41489. if (!isPublicOnlyKey) {
  41490. ret = wc_Dilithium_PrivateKeyToDer(key, der, maxDerSz);
  41491. }
  41492. #endif
  41493. if (ret >= 0) {
  41494. derSz = ret;
  41495. ret = 0;
  41496. }
  41497. }
  41498. /* Free and reinit key to test fresh decode */
  41499. if (ret == 0) {
  41500. wc_dilithium_free(key);
  41501. ret = wc_dilithium_init(key);
  41502. }
  41503. /* First test decoding when security level is set externally */
  41504. if (ret == 0) {
  41505. ret = wc_dilithium_set_level(key, expectedLevel);
  41506. }
  41507. if (ret == 0) {
  41508. idx = 0;
  41509. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41510. if (isPublicOnlyKey) {
  41511. ret = wc_Dilithium_PublicKeyDecode(der, &idx, key, derSz);
  41512. }
  41513. #endif
  41514. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41515. if (!isPublicOnlyKey) {
  41516. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, key, derSz);
  41517. }
  41518. #endif
  41519. }
  41520. /* Free and reinit key to test fresh decode */
  41521. if (ret == 0) {
  41522. wc_dilithium_free(key);
  41523. ret = wc_dilithium_init(key);
  41524. }
  41525. #ifndef WOLFSSL_DILITHIUM_FIPS204_DRAFT
  41526. /* Test decoding without setting security level - should auto-detect */
  41527. if (ret == 0) {
  41528. idx = 0;
  41529. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41530. if (isPublicOnlyKey) {
  41531. ret = wc_Dilithium_PublicKeyDecode(der, &idx, key, derSz);
  41532. }
  41533. #endif
  41534. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41535. if (!isPublicOnlyKey) {
  41536. ret = wc_Dilithium_PrivateKeyDecode(der, &idx, key, derSz);
  41537. }
  41538. #endif
  41539. }
  41540. /* Verify auto-detected security level */
  41541. if (ret == 0 && key->level != expectedLevel) {
  41542. printf("Dilithium key decode failed to detect level.\n"
  41543. "\tExpected level=%d\n\tGot level=%d\n",
  41544. expectedLevel, key->level);
  41545. ret = WC_TEST_RET_ENC_NC;
  41546. }
  41547. #endif /* !WOLFSSL_DILITHIUM_FIPS204_DRAFT */
  41548. /* Cleanup */
  41549. XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41550. wc_dilithium_free(key);
  41551. #ifdef WOLFSSL_SMALL_STACK
  41552. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41553. #endif
  41554. return ret;
  41555. }
  41556. /* Test Dilithium key decoding and security level detection */
  41557. static wc_test_ret_t dilithium_decode_test(void)
  41558. {
  41559. wc_test_ret_t ret;
  41560. const byte* key;
  41561. word32 keySz;
  41562. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41563. const int isPrvKey = 0;
  41564. #endif
  41565. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41566. const int isPubKey = 1;
  41567. #endif
  41568. #ifndef WOLFSSL_NO_ML_DSA_44
  41569. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41570. /* Test ML-DSA-44 */
  41571. key = bench_dilithium_level2_key;
  41572. keySz = sizeof_bench_dilithium_level2_key;
  41573. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPrvKey);
  41574. if (ret != 0) {
  41575. return ret;
  41576. }
  41577. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41578. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41579. key = bench_dilithium_level2_pubkey;
  41580. keySz = sizeof_bench_dilithium_level2_pubkey;
  41581. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_44, isPubKey);
  41582. if (ret != 0) {
  41583. return ret;
  41584. }
  41585. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41586. #endif /* WOLFSSL_NO_ML_DSA_44 */
  41587. #ifndef WOLFSSL_NO_ML_DSA_65
  41588. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41589. /* Test ML-DSA-65 */
  41590. key = bench_dilithium_level3_key;
  41591. keySz = sizeof_bench_dilithium_level3_key;
  41592. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPrvKey);
  41593. if (ret != 0) {
  41594. return ret;
  41595. }
  41596. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41597. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41598. key = bench_dilithium_level3_pubkey;
  41599. keySz = sizeof_bench_dilithium_level3_pubkey;
  41600. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_65, isPubKey);
  41601. if (ret != 0) {
  41602. return ret;
  41603. }
  41604. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41605. #endif /* WOLFSSL_NO_ML_DSA_65 */
  41606. #ifndef WOLFSSL_NO_ML_DSA_87
  41607. #ifdef WOLFSSL_DILITHIUM_PRIVATE_KEY
  41608. /* Test ML-DSA-87 */
  41609. key = bench_dilithium_level5_key;
  41610. keySz = sizeof_bench_dilithium_level5_key;
  41611. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPrvKey);
  41612. if (ret != 0) {
  41613. return ret;
  41614. }
  41615. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41616. #ifdef WOLFSSL_DILITHIUM_PUBLIC_KEY
  41617. key = bench_dilithium_level5_pubkey;
  41618. keySz = sizeof_bench_dilithium_level5_pubkey;
  41619. ret = test_dilithium_decode_level(key, keySz, WC_ML_DSA_87, isPubKey);
  41620. if (ret != 0) {
  41621. return ret;
  41622. }
  41623. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41624. #endif /* WOLFSSL_NO_ML_DSA_87 */
  41625. return ret;
  41626. }
  41627. #endif /* WOLFSSL_DILITHIUM_PUBLIC_KEY || WOLFSSL_DILITHIUM_PRIVATE_KEY */
  41628. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t dilithium_test(void)
  41629. {
  41630. wc_test_ret_t ret;
  41631. WC_RNG rng;
  41632. #ifndef HAVE_FIPS
  41633. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41634. #else
  41635. ret = wc_InitRng(&rng);
  41636. #endif
  41637. if (ret != 0) {
  41638. ret = WC_TEST_RET_ENC_EC(ret);
  41639. return ret;
  41640. }
  41641. #ifndef WOLFSSL_NO_ML_DSA_44
  41642. #ifdef WOLFSSL_WC_DILITHIUM
  41643. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41644. ret = dilithium_param_44_vfy_test();
  41645. if (ret != 0)
  41646. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41647. #endif
  41648. #endif
  41649. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41650. ret = dilithium_param_test(WC_ML_DSA_44, &rng);
  41651. if (ret != 0)
  41652. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41653. #endif
  41654. #endif
  41655. #ifndef WOLFSSL_NO_ML_DSA_65
  41656. #ifdef WOLFSSL_WC_DILITHIUM
  41657. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41658. ret = dilithium_param_65_vfy_test();
  41659. if (ret != 0)
  41660. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41661. #endif
  41662. #endif
  41663. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41664. ret = dilithium_param_test(WC_ML_DSA_65, &rng);
  41665. if (ret != 0)
  41666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41667. #endif
  41668. #endif
  41669. #ifndef WOLFSSL_NO_ML_DSA_87
  41670. #ifdef WOLFSSL_WC_DILITHIUM
  41671. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  41672. ret = dilithium_param_87_vfy_test();
  41673. if (ret != 0)
  41674. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41675. #endif
  41676. #endif
  41677. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  41678. ret = dilithium_param_test(WC_ML_DSA_87, &rng);
  41679. if (ret != 0)
  41680. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41681. #endif
  41682. #endif
  41683. #if defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41684. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41685. ret = dilithium_decode_test();
  41686. if (ret != 0) {
  41687. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  41688. }
  41689. #endif /* WOLFSSL_DILITHIUM_PRIVATE_KEY || WOLFSSL_DILITHIUM_PUBLIC_KEY */
  41690. #if !defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY) || \
  41691. !defined(WOLFSSL_DILITHIUM_NO_VERIFY) || \
  41692. defined(WOLFSSL_DILITHIUM_PRIVATE_KEY) || \
  41693. defined(WOLFSSL_DILITHIUM_PUBLIC_KEY)
  41694. out:
  41695. #endif
  41696. wc_FreeRng(&rng);
  41697. return ret;
  41698. }
  41699. #endif /* HAVE_DILITHIUM */
  41700. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  41701. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  41702. void *context)
  41703. {
  41704. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  41705. * BE USED FOR TESTING PURPOSES! Production applications should
  41706. * write only to non-volatile storage. */
  41707. XMEMCPY(context, priv, privSz);
  41708. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  41709. }
  41710. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  41711. void *context)
  41712. {
  41713. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  41714. * BE USED FOR TESTING PURPOSES! */
  41715. XMEMCPY(priv, context, privSz);
  41716. return WC_XMSS_RC_READ_TO_MEMORY;
  41717. }
  41718. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test(void)
  41719. {
  41720. int i = 0;
  41721. int j = 0;
  41722. XmssKey signingKey;
  41723. XmssKey verifyKey;
  41724. WC_RNG rng;
  41725. word32 pkSz = 0;
  41726. word32 skSz = 0;
  41727. word32 sigSz = 0;
  41728. word32 bufSz = 0;
  41729. unsigned char * sk = NULL;
  41730. unsigned char * old_sk = NULL;
  41731. const char * msg = "XMSS post quantum signature test";
  41732. word32 msgSz = (word32) XSTRLEN(msg);
  41733. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41734. const char * param = "XMSS-SHA2_10_256";
  41735. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 20
  41736. const char * param = "XMSSMT-SHA2_20/4_256";
  41737. #elif WOLFSSL_XMSS_MIN_HEIGHT <= 40
  41738. const char * param = "XMSSMT-SHA2_40/8_256";
  41739. #else
  41740. const char * param = "XMSSMT-SHA2_60/12_256";
  41741. #endif
  41742. byte * sig = NULL;
  41743. int ret2 = -1;
  41744. int ret = WC_TEST_RET_ENC_NC;
  41745. WOLFSSL_ENTER("xmss_test");
  41746. #ifndef HAVE_FIPS
  41747. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  41748. #else
  41749. ret = wc_InitRng(&rng);
  41750. #endif
  41751. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41752. ret = wc_XmssKey_Init(&signingKey, NULL, INVALID_DEVID);
  41753. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41754. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  41755. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41756. /* Set the parameter string to the signing key, and
  41757. * get sizes for secret key, pub key, and signature. */
  41758. ret = wc_XmssKey_SetParamStr(&signingKey, param);
  41759. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41760. ret = wc_XmssKey_GetPubLen(&signingKey, &pkSz);
  41761. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41762. if (pkSz != XMSS_SHA256_PUBLEN) {
  41763. return WC_TEST_RET_ENC_EC(pkSz);
  41764. }
  41765. ret = wc_XmssKey_GetPrivLen(&signingKey, &skSz);
  41766. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41767. ret = wc_XmssKey_GetSigLen(&signingKey, &sigSz);
  41768. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41769. /* Allocate signature array. */
  41770. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41771. if (sig == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41772. bufSz = sigSz;
  41773. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  41774. fprintf(stderr, "param: %s\n", param);
  41775. fprintf(stderr, "pkSz: %d\n", pkSz);
  41776. fprintf(stderr, "skSz: %d\n", skSz);
  41777. fprintf(stderr, "sigSz: %d\n", sigSz);
  41778. #endif
  41779. /* Allocate current and old secret keys.*/
  41780. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41781. if (sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41782. old_sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41783. if (old_sk == NULL) { return WC_TEST_RET_ENC_ERRNO; }
  41784. XMEMSET(sk, 0, skSz);
  41785. XMEMSET(old_sk, 0, skSz);
  41786. XMEMSET(sig, 0, sigSz);
  41787. ret = wc_XmssKey_SetWriteCb(&signingKey, xmss_write_key_mem);
  41788. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41789. ret = wc_XmssKey_SetReadCb(&signingKey, xmss_read_key_mem);
  41790. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41791. ret = wc_XmssKey_SetContext(&signingKey, (void *) sk);
  41792. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41793. ret = wc_XmssKey_MakeKey(&signingKey, &rng);
  41794. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41795. /* Export the pub to a verify key. */
  41796. ret = wc_XmssKey_ExportPub(&verifyKey, &signingKey);
  41797. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  41798. /* Repeat a few times to check that:
  41799. * 1. The secret key is mutated on each sign.
  41800. * 2. We can verify each new signature.
  41801. * Only do a few times, because the full signature space
  41802. * for this parameter set is huge. */
  41803. for (i = 0; i < 10; ++i) {
  41804. XMEMCPY(old_sk, sk, skSz);
  41805. ret = wc_XmssKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  41806. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41807. if (sigSz != bufSz) { return WC_TEST_RET_ENC_I(i); }
  41808. /* Old secret key and current secret key should not match. */
  41809. ret = XMEMCMP(old_sk, sk, skSz);
  41810. if (ret == 0) { return WC_TEST_RET_ENC_I(i); }
  41811. ret = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  41812. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  41813. /* Flip bits in a few places throughout the signature, stepping in multiple
  41814. * of hash size. These should all fail with -1. */
  41815. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  41816. sig[j] ^= 1;
  41817. ret2 = wc_XmssKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  41818. msgSz);
  41819. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  41820. /* Verify passed when it should have failed. */
  41821. return WC_TEST_RET_ENC_I(j);
  41822. }
  41823. /* Flip this spot back. */
  41824. sig[j] ^= 1;
  41825. }
  41826. }
  41827. /* Cleanup everything. */
  41828. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41829. sig = NULL;
  41830. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41831. sk = NULL;
  41832. XFREE(old_sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  41833. old_sk = NULL;
  41834. wc_XmssKey_Free(&signingKey);
  41835. wc_FreeRng(&rng);
  41836. return ret;
  41837. }
  41838. #endif /*if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)*/
  41839. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_SMALL_STACK) && \
  41840. WOLFSSL_XMSS_MIN_HEIGHT <= 10
  41841. /* A simple xmss verify only test using:
  41842. * XMSS-SHA2_10_256
  41843. * pub len: 68
  41844. * msg len: 32
  41845. * sig len: 2500
  41846. *
  41847. * These were generated with the test xmss_fast, from the unpatched
  41848. * xmss-reference repository:
  41849. * https://github.com/XMSS/xmss-reference
  41850. * */
  41851. static const byte xmss_pub[XMSS_SHA256_PUBLEN] =
  41852. {
  41853. 0x00,0x00,0x00,0x01,0xA5,0x41,0x31,0x96,
  41854. 0x0A,0xF9,0xF3,0xB2,0x4B,0x2E,0x5B,0x3E,
  41855. 0xCA,0x74,0xAD,0x6C,0xA5,0x89,0xAD,0x2C,
  41856. 0x0E,0x96,0xB3,0x54,0xFB,0x5B,0x63,0x50,
  41857. 0x96,0x81,0xE2,0x59,0x72,0x10,0x09,0x54,
  41858. 0xBB,0x39,0xAC,0xEE,0x78,0xEF,0x95,0xEC,
  41859. 0x01,0x1D,0xF0,0x36,0x68,0xE2,0xC4,0xA5,
  41860. 0x2F,0x60,0x42,0x7E,0xD3,0x8E,0xAA,0x27,
  41861. 0xC9,0xB7,0x39,0x4E
  41862. };
  41863. static /* not const */ byte xmss_msg[32] =
  41864. {
  41865. 0x07,0x9F,0x80,0x86,0xDB,0x76,0x27,0xDF,
  41866. 0xED,0x5B,0x2A,0x81,0x60,0x60,0x7D,0xB4,
  41867. 0xE8,0x7A,0x69,0x45,0x20,0x6B,0xA2,0x96,
  41868. 0xC0,0x21,0xA5,0x46,0x29,0x63,0x9B,0x37
  41869. };
  41870. /* This was actually the 5th signature produced from
  41871. * xmss_fast test in xmss-reference. */
  41872. static /* not const */ byte xmss_sig[2500] =
  41873. {
  41874. 0x00,0x00,0x00,0x05,0xF0,0x15,0x34,0xBA,
  41875. 0x92,0x03,0x6A,0xB9,0xA5,0x23,0x86,0x11,
  41876. 0xAE,0x65,0x0A,0x5C,0x78,0x2C,0xC9,0xBE,
  41877. 0x7E,0xA6,0xDC,0xA2,0x8B,0xA9,0x9C,0x50,
  41878. 0xF6,0x61,0x8D,0x9D,0xD7,0xE9,0xC0,0xF8,
  41879. 0x67,0xCD,0x8A,0xC4,0x9B,0x74,0x96,0x07,
  41880. 0x5D,0xF2,0xC9,0xCC,0x28,0x05,0xB1,0xBE,
  41881. 0x5E,0xA4,0xBA,0xBE,0xAB,0xD8,0x21,0x6B,
  41882. 0x21,0x5F,0xAB,0xB7,0x6C,0xEC,0x2F,0xC8,
  41883. 0xC6,0x74,0x3E,0x97,0x1B,0xC3,0x45,0x57,
  41884. 0xAF,0xAA,0x1E,0xA8,0xF2,0x86,0xA8,0xAA,
  41885. 0x43,0x6D,0x66,0xE9,0x81,0x14,0xDE,0x09,
  41886. 0x39,0xD2,0xAF,0xD1,0x4C,0xE7,0x75,0x18,
  41887. 0x0D,0xAA,0x29,0xA1,0x92,0x53,0xCC,0xE9,
  41888. 0xF3,0x0B,0x1E,0x3B,0xE2,0xAE,0x80,0x0C,
  41889. 0xE7,0x7A,0x7C,0x13,0x8A,0x28,0xC6,0x5F,
  41890. 0x0A,0xA4,0xA3,0x73,0x0A,0x3A,0xC2,0xA6,
  41891. 0x3B,0xB4,0x30,0x67,0xC0,0x36,0x18,0xA1,
  41892. 0x58,0xCD,0xAD,0x54,0x36,0x64,0xCE,0xFD,
  41893. 0x52,0xFF,0x70,0x7E,0x09,0xFB,0x13,0xA2,
  41894. 0xEA,0xDF,0x67,0x8D,0x6C,0x42,0xB2,0x78,
  41895. 0xF5,0x7D,0x5C,0x4B,0xF7,0x8E,0xCF,0x3E,
  41896. 0xB7,0xC6,0xC1,0x23,0xFA,0x65,0xDE,0xD2,
  41897. 0xFA,0x40,0x51,0x97,0x0D,0x52,0x32,0x76,
  41898. 0x7E,0x82,0x8D,0xD0,0xB9,0x1E,0x62,0xD9,
  41899. 0x1E,0xC1,0xDB,0x40,0x43,0x37,0x4A,0x23,
  41900. 0x8A,0x1D,0x35,0xFA,0xF4,0x53,0x11,0x5A,
  41901. 0xB5,0x6D,0x1E,0x8B,0x22,0xC8,0x7D,0x2A,
  41902. 0xE4,0x94,0xAA,0x25,0x20,0x40,0x96,0xDB,
  41903. 0x82,0x62,0xBA,0x8F,0x8B,0x45,0xCB,0x4F,
  41904. 0x35,0x88,0x33,0xEB,0xEF,0xB3,0xBA,0xA7,
  41905. 0x09,0x72,0xB3,0x4C,0xEC,0xF2,0xC3,0xC7,
  41906. 0x5E,0x02,0x6C,0x41,0x93,0xCB,0x3C,0x89,
  41907. 0x12,0x09,0x68,0x54,0x8E,0xEC,0x6A,0x7E,
  41908. 0x20,0xE1,0x70,0x3D,0x8C,0xEB,0xB4,0x36,
  41909. 0xBE,0x91,0xBE,0x97,0xB5,0xA6,0x34,0x16,
  41910. 0x95,0x0F,0x10,0x26,0xA9,0x13,0x80,0x88,
  41911. 0x9C,0xAA,0x68,0xEC,0x34,0x70,0x4A,0x15,
  41912. 0x9B,0x5E,0x57,0x05,0x87,0x1C,0xF8,0x35,
  41913. 0x45,0x29,0xE9,0x6E,0xF2,0x70,0x13,0x42,
  41914. 0x89,0x4E,0x77,0xC0,0x18,0xC7,0x55,0x6D,
  41915. 0xE7,0xFA,0x0D,0x63,0x83,0x16,0x19,0x01,
  41916. 0x2D,0xFD,0x31,0x14,0x94,0xCA,0x3E,0x0E,
  41917. 0xD6,0x11,0x34,0x81,0x57,0x58,0xEC,0x24,
  41918. 0xA4,0x17,0x63,0xD3,0x25,0x00,0xBF,0x7D,
  41919. 0x78,0x5D,0xC5,0xD8,0xC6,0xC1,0xBD,0x8C,
  41920. 0xD0,0x94,0x0A,0xB1,0x33,0xA5,0x4B,0x31,
  41921. 0x25,0xF5,0xAF,0xE7,0x84,0x26,0xAA,0x05,
  41922. 0xBB,0xF3,0x9A,0xAF,0x58,0x36,0x40,0xEF,
  41923. 0x3D,0xA2,0xBD,0xCA,0xA1,0x8D,0x2F,0x6D,
  41924. 0x54,0xD2,0x62,0x33,0x09,0xAE,0xE6,0x73,
  41925. 0xD6,0x44,0xE8,0x7C,0x5C,0x39,0x2B,0x78,
  41926. 0x94,0x14,0xC7,0xC9,0xAF,0xEC,0x77,0x36,
  41927. 0xA1,0x61,0x61,0xF1,0xD0,0x09,0xA2,0xEE,
  41928. 0xE7,0x55,0xD7,0x35,0x89,0x89,0x9B,0xCF,
  41929. 0xFA,0xA6,0x09,0x1E,0x3B,0xBD,0x5D,0xD9,
  41930. 0x25,0xE7,0xED,0xDD,0x7C,0xF0,0x1C,0x57,
  41931. 0xE0,0x06,0xBB,0x08,0x39,0x59,0xDF,0xD7,
  41932. 0xAF,0x4B,0x88,0x0D,0x87,0x8F,0x4A,0xF3,
  41933. 0x1C,0xD4,0x4B,0xB3,0xE2,0xF3,0x1B,0x86,
  41934. 0x4F,0xCD,0x35,0x75,0xE2,0x03,0xF9,0x1D,
  41935. 0xBF,0x3E,0xD1,0x7B,0xC7,0x23,0x11,0x75,
  41936. 0x5F,0x92,0x0D,0x98,0xEE,0x14,0xE1,0xDA,
  41937. 0x7A,0x02,0x17,0x47,0x6B,0x41,0xEA,0x47,
  41938. 0xA1,0xAF,0x06,0x79,0x1A,0x52,0x6F,0x19,
  41939. 0x31,0x70,0x71,0xBD,0xC2,0x61,0x8D,0xB7,
  41940. 0xEE,0x6B,0x69,0x2A,0xE8,0x21,0x7A,0x95,
  41941. 0xBE,0x86,0x2A,0xA1,0xF4,0xE2,0x2F,0x17,
  41942. 0x02,0xFD,0xAD,0x17,0x9F,0x0A,0x0A,0x78,
  41943. 0xA9,0x92,0x30,0x21,0x72,0x2B,0x28,0xF8,
  41944. 0xF2,0x3E,0x05,0xD5,0xAC,0xC0,0x82,0xF8,
  41945. 0xD2,0xDA,0xD0,0xA3,0xBC,0x93,0xDB,0xA5,
  41946. 0x46,0xDE,0x14,0x1E,0xD4,0x3A,0x5D,0x79,
  41947. 0x3D,0x31,0x4B,0x06,0xCE,0x22,0x29,0x3C,
  41948. 0x98,0xB6,0x18,0x8A,0xAE,0xF7,0xBA,0x22,
  41949. 0x88,0xA1,0xEE,0xC0,0x14,0x4C,0x4A,0xA0,
  41950. 0x57,0x0A,0xD3,0x18,0xA2,0x3D,0xDD,0xC7,
  41951. 0x83,0x73,0xFC,0x38,0x9B,0x31,0xA3,0xE1,
  41952. 0x17,0x76,0xA1,0xA2,0x69,0xFC,0xAB,0x08,
  41953. 0x80,0x72,0x8D,0xF5,0xE4,0x14,0xB7,0x6B,
  41954. 0x03,0xFF,0xE8,0x11,0x4B,0x06,0x55,0x7E,
  41955. 0x36,0x21,0x2F,0xD7,0x54,0x82,0xC9,0x31,
  41956. 0xB4,0x85,0x68,0x41,0xEF,0x75,0xB0,0x3A,
  41957. 0xEA,0x4F,0xE0,0xEC,0x72,0xCC,0x33,0x96,
  41958. 0xCE,0x7D,0xAD,0xDD,0x0D,0x27,0x05,0x6E,
  41959. 0xA2,0xD4,0x11,0x07,0xD8,0x7D,0x27,0xD4,
  41960. 0x80,0x8F,0x00,0x22,0xE4,0xFC,0x2C,0x9D,
  41961. 0xD5,0xD8,0x18,0x7F,0x4E,0xF4,0xB9,0x7F,
  41962. 0xEF,0xD6,0x00,0x08,0x5C,0x05,0x04,0x1E,
  41963. 0x9A,0xC6,0x8D,0xCC,0x19,0xD9,0x0B,0x06,
  41964. 0xCC,0x6A,0x17,0xE2,0x03,0x23,0xDB,0x1C,
  41965. 0xBC,0xA2,0xB9,0xA2,0x95,0x3C,0x73,0xD8,
  41966. 0xFF,0xE6,0x0E,0xAE,0x04,0xB2,0xFC,0x91,
  41967. 0x4F,0xEF,0x8A,0x58,0xB7,0x31,0x68,0x4C,
  41968. 0x1E,0xD0,0x5B,0x85,0xCC,0x03,0xDC,0xF4,
  41969. 0xAC,0xDB,0x03,0x9B,0x35,0x33,0x08,0x71,
  41970. 0xD0,0x50,0x8D,0xDC,0xE3,0x3A,0x98,0x40,
  41971. 0x41,0x80,0xDD,0x35,0xE1,0xA2,0xAF,0x14,
  41972. 0x9A,0xDB,0xD3,0x68,0x14,0xE2,0x50,0x7A,
  41973. 0x76,0x3F,0xE4,0xA4,0x1B,0xAA,0xC1,0x06,
  41974. 0x87,0x9A,0x92,0xF9,0xBE,0x9E,0x86,0x8C,
  41975. 0x92,0x1D,0x74,0xB1,0x7F,0x27,0x43,0xC0,
  41976. 0xEE,0x2E,0xC2,0x6C,0x6D,0xAA,0x0C,0x0E,
  41977. 0x71,0xC9,0x56,0xD6,0x3A,0x56,0xCB,0x90,
  41978. 0xD1,0x7E,0x6E,0x1C,0x6A,0x00,0x2D,0x02,
  41979. 0x2C,0x96,0xF0,0x2A,0x37,0x37,0x18,0x07,
  41980. 0x0B,0xF4,0xB4,0x8C,0x30,0xF2,0xA4,0xAB,
  41981. 0x66,0xFB,0x8B,0x22,0xC0,0x00,0x7E,0x05,
  41982. 0xB6,0xF9,0x95,0x49,0x33,0xA1,0xDC,0x97,
  41983. 0x0C,0x5C,0x61,0x46,0xE2,0xD7,0x87,0x4B,
  41984. 0xC4,0xC7,0x5F,0x26,0x06,0x84,0xD7,0x47,
  41985. 0x05,0xF1,0x33,0xFF,0x85,0x85,0xB2,0xBD,
  41986. 0x1F,0x44,0xC6,0xC2,0x7D,0x51,0xBE,0x0E,
  41987. 0xB5,0xC4,0x44,0x2F,0xFE,0x73,0x5F,0xF4,
  41988. 0xA4,0xEF,0xE2,0xF1,0x73,0x0B,0xEF,0x3E,
  41989. 0x2B,0xD7,0xCC,0x9F,0xDA,0x1A,0x7E,0x92,
  41990. 0x39,0xA1,0x55,0xBF,0x60,0x0A,0xDB,0x23,
  41991. 0x74,0xFE,0xE7,0x05,0x63,0xA9,0x85,0x52,
  41992. 0x9F,0xCC,0xC3,0xFF,0xF6,0x6C,0x1B,0x4E,
  41993. 0x4F,0x01,0xBD,0xC3,0xEB,0x37,0xEC,0x29,
  41994. 0x21,0x3B,0x2C,0xC9,0x2E,0x93,0x20,0x3E,
  41995. 0x19,0xC0,0x8B,0xE8,0x33,0xCD,0xC6,0x6A,
  41996. 0x6E,0x72,0x13,0x15,0xA1,0x90,0x20,0x0C,
  41997. 0x14,0x66,0xED,0xCC,0xA4,0xDD,0x7F,0x58,
  41998. 0x53,0xBC,0x4A,0x68,0xFC,0x86,0x3E,0xAA,
  41999. 0xF1,0x17,0x0F,0x3E,0x20,0x54,0x93,0xF4,
  42000. 0x98,0xBF,0xB4,0x07,0x05,0xBD,0x70,0xE7,
  42001. 0xD7,0x34,0xFD,0xE3,0x69,0xDF,0xCD,0xF5,
  42002. 0x1A,0x73,0x6E,0xC9,0x2B,0x21,0xFB,0xB8,
  42003. 0x7E,0x44,0x10,0x83,0x56,0xCE,0xD5,0x15,
  42004. 0x9A,0x75,0xFC,0x91,0x8E,0x6B,0x9E,0x1A,
  42005. 0x3A,0x33,0x39,0x35,0xB4,0x0D,0x74,0xF4,
  42006. 0xFB,0x4C,0x0E,0x37,0xFE,0x82,0x95,0x46,
  42007. 0x6B,0xD2,0x6E,0xEE,0xCD,0x4D,0x38,0xAF,
  42008. 0x0A,0xAA,0xF1,0xD5,0xA4,0x7C,0x04,0xD8,
  42009. 0xB9,0xDB,0x11,0x68,0x88,0x35,0x41,0xDE,
  42010. 0x31,0x33,0x0C,0xDC,0x2D,0x4C,0xA8,0x20,
  42011. 0xCC,0x2C,0x4C,0x63,0xAB,0xBA,0xDF,0x48,
  42012. 0x84,0xD5,0x25,0xBC,0x70,0xE3,0x49,0xAA,
  42013. 0x43,0xCA,0x8B,0xE7,0x9F,0xDD,0x20,0x76,
  42014. 0x9B,0x38,0xF4,0xBA,0x4D,0x4E,0x34,0x4A,
  42015. 0xAF,0x81,0xE7,0x0B,0xEC,0xE9,0x59,0xC1,
  42016. 0x35,0x22,0x7F,0x69,0x46,0x62,0xD2,0x18,
  42017. 0x6E,0x1F,0x79,0xD1,0xAD,0xC3,0x84,0x95,
  42018. 0x96,0xB2,0x18,0x58,0x5E,0x7E,0x0C,0x25,
  42019. 0x0A,0x0F,0x69,0xA3,0x1D,0xEC,0x29,0xCB,
  42020. 0xDA,0xA2,0xD1,0x1A,0x10,0xA5,0x52,0xC3,
  42021. 0x62,0x1E,0xC5,0x83,0xFF,0xA3,0x56,0xC2,
  42022. 0xFD,0x87,0x3B,0x57,0x52,0x98,0x36,0x95,
  42023. 0x77,0x6B,0xE5,0x49,0x10,0x8E,0x39,0xDD,
  42024. 0xCA,0x4B,0xB3,0x9F,0x4C,0x0C,0x11,0x62,
  42025. 0xF3,0x22,0x78,0xDB,0x48,0xEB,0x68,0xFE,
  42026. 0xE4,0x2A,0xE9,0xAA,0x8F,0x7A,0x2F,0x69,
  42027. 0xA5,0xC5,0x03,0x2D,0xEF,0x62,0xA8,0x71,
  42028. 0x65,0x06,0x40,0x84,0x10,0x0F,0xF2,0xED,
  42029. 0xBC,0x70,0x71,0x69,0x24,0xA2,0xBF,0x83,
  42030. 0x39,0xDD,0xFA,0xA2,0x7B,0xE5,0xEC,0x3D,
  42031. 0xFE,0x3B,0x52,0x6E,0x3D,0x82,0xA6,0x2A,
  42032. 0x86,0x01,0x61,0x51,0x63,0xBF,0xF9,0x0A,
  42033. 0x06,0x72,0xF1,0xD5,0x39,0x0C,0xBA,0xC9,
  42034. 0x78,0xC6,0x77,0x22,0xE4,0x96,0x6E,0xB1,
  42035. 0x48,0x62,0x84,0x62,0x2D,0xEA,0x49,0x56,
  42036. 0x50,0x86,0x3F,0x90,0xC3,0x01,0x42,0x45,
  42037. 0xED,0xE6,0x9A,0x65,0x19,0x93,0x7F,0x48,
  42038. 0x16,0xF2,0x50,0xA7,0x70,0xB3,0xF5,0xDB,
  42039. 0x0E,0x5E,0x22,0x9E,0x64,0x04,0x26,0x69,
  42040. 0xC1,0x16,0xEE,0x65,0x08,0x82,0x27,0x65,
  42041. 0xEC,0x3D,0xDF,0x51,0x5E,0x2D,0xE8,0x76,
  42042. 0xF2,0xE3,0xE4,0x24,0x04,0x88,0x06,0x0F,
  42043. 0xB2,0x7B,0x9B,0x72,0x3D,0x4C,0x7D,0x6A,
  42044. 0x1F,0xB2,0xA2,0xD2,0x35,0xD6,0x40,0x25,
  42045. 0xC2,0x0B,0x25,0xF9,0xDF,0x26,0xE4,0xDC,
  42046. 0xFB,0xB1,0x84,0x84,0x77,0x1B,0x45,0x51,
  42047. 0x60,0xD5,0xF0,0xB6,0x09,0xE6,0xBC,0xE3,
  42048. 0x1C,0x70,0x96,0x2C,0xD3,0x9D,0x7D,0x7F,
  42049. 0xB1,0x70,0xDA,0x79,0xB8,0x74,0x99,0xBF,
  42050. 0x84,0x95,0xCC,0x93,0xD7,0x51,0xDD,0x66,
  42051. 0xD3,0x70,0x0C,0x75,0x86,0x09,0x06,0xFD,
  42052. 0x66,0x14,0x80,0xCD,0xF3,0x59,0xB4,0x92,
  42053. 0x5F,0xE4,0xEE,0x00,0xA8,0xB0,0x8B,0x5C,
  42054. 0x3E,0xDB,0x8A,0x9C,0x0B,0xB5,0x99,0xC2,
  42055. 0x0D,0x81,0x09,0x06,0x6C,0x28,0xC0,0x7E,
  42056. 0xA5,0x07,0x70,0x64,0xD7,0x41,0xF4,0xC3,
  42057. 0x66,0x61,0x1C,0xA8,0x51,0xF6,0x3C,0xBA,
  42058. 0xE0,0x94,0xA3,0x11,0x8C,0x2E,0xBA,0x13,
  42059. 0xB2,0x47,0x48,0x93,0xB4,0x1A,0x2C,0x9A,
  42060. 0x6E,0x8E,0x30,0x66,0x7B,0xD3,0xBB,0x3B,
  42061. 0x5D,0x97,0x0D,0xE4,0xEA,0x24,0x28,0x9E,
  42062. 0xB4,0x88,0xCE,0x1D,0x7D,0x6F,0x39,0xB3,
  42063. 0x87,0x21,0xE5,0x08,0x93,0xF0,0xD4,0x9D,
  42064. 0x2D,0x91,0xC9,0xFD,0x0C,0x74,0x34,0xB4,
  42065. 0x1F,0xFE,0xDA,0xDC,0x10,0x5B,0x8D,0x2B,
  42066. 0x87,0xD3,0x42,0xB4,0xAE,0x32,0x9C,0xAE,
  42067. 0x4C,0x99,0xD8,0xED,0x44,0x41,0x07,0xE0,
  42068. 0x8F,0xBD,0xA5,0x7C,0x5A,0xDF,0x91,0x29,
  42069. 0x00,0xB5,0x4B,0xC3,0x3A,0x40,0x6C,0x48,
  42070. 0xAB,0x2A,0xF3,0x02,0xCB,0xB3,0x69,0xDA,
  42071. 0x06,0x0C,0x4D,0x5C,0x45,0xC3,0x28,0xAC,
  42072. 0x7A,0x01,0xD4,0xF8,0xCB,0x07,0x63,0x89,
  42073. 0x09,0x34,0x78,0xA7,0x14,0x39,0xCF,0x2D,
  42074. 0x94,0x8D,0x7A,0x4E,0x4E,0xBD,0xC4,0x32,
  42075. 0xAB,0x21,0xC9,0xDA,0x3F,0x5F,0x04,0x6B,
  42076. 0x14,0x40,0x18,0x18,0x2F,0xF9,0x46,0x17,
  42077. 0x57,0x54,0x9B,0x28,0x7B,0xBD,0xF9,0xA2,
  42078. 0x13,0xAC,0x69,0x24,0xB1,0x31,0x39,0xBF,
  42079. 0x8D,0x75,0xC3,0xFD,0x03,0x54,0x5A,0xFD,
  42080. 0xD4,0x7A,0xB7,0x56,0x4F,0x66,0x43,0x57,
  42081. 0x1B,0xFB,0xF9,0x92,0x7A,0x83,0xE6,0xFF,
  42082. 0xB4,0xBA,0x83,0xD2,0x61,0x8E,0x4A,0x82,
  42083. 0x82,0xA8,0xF5,0x0C,0xD2,0x43,0x53,0xA8,
  42084. 0x85,0x0A,0xD4,0x69,0x7B,0x04,0x71,0x3B,
  42085. 0x80,0x49,0x27,0x47,0x12,0xB6,0xB0,0xEA,
  42086. 0x90,0x0A,0xFA,0xA8,0xC8,0x78,0x61,0xDE,
  42087. 0x30,0x12,0xBB,0xDC,0xA6,0x57,0x56,0x30,
  42088. 0x6E,0xF1,0xA8,0x3B,0xF6,0x09,0x07,0xEA,
  42089. 0x31,0xE2,0x08,0x23,0x31,0x0F,0xD4,0x34,
  42090. 0xE3,0x60,0xC2,0x2B,0xDB,0x5A,0x99,0xCF,
  42091. 0xD4,0x6B,0x4E,0x75,0x65,0x35,0xE8,0x8B,
  42092. 0x93,0x7D,0xCA,0x11,0x47,0xF0,0x3E,0x11,
  42093. 0x5C,0xD1,0xEE,0x4B,0x11,0xB4,0x65,0x2B,
  42094. 0x6B,0x79,0xC0,0x86,0x60,0xA4,0x4B,0x24,
  42095. 0xA0,0x5C,0x70,0x34,0xC3,0x7C,0xE7,0x4F,
  42096. 0x97,0x89,0x4D,0xFE,0x22,0x89,0x3A,0xE9,
  42097. 0x07,0xB9,0x1A,0x86,0xB8,0x7A,0x12,0x38,
  42098. 0xE1,0x24,0x46,0xBC,0x9B,0x21,0xCD,0xAC,
  42099. 0x30,0xAB,0x98,0x21,0x31,0xC5,0x17,0x3F,
  42100. 0x1E,0x56,0xC3,0x18,0xCE,0xF0,0xA1,0xCC,
  42101. 0xFF,0x9D,0xA8,0x53,0xAF,0x74,0x77,0x54,
  42102. 0x02,0x9A,0x8F,0xA4,0xD4,0xBD,0xB2,0x1A,
  42103. 0xBA,0x52,0x2E,0x19,0xBE,0x49,0x11,0x45,
  42104. 0x02,0x01,0x7A,0xBF,0x28,0xD6,0x18,0xED,
  42105. 0xBD,0xCE,0xE4,0xDE,0xB5,0xF1,0x53,0x5D,
  42106. 0x65,0xF9,0x5F,0x83,0x8F,0x2D,0xF2,0x82,
  42107. 0xA0,0x2D,0x28,0xD3,0x0A,0x9E,0x0F,0x7F,
  42108. 0xC7,0xC4,0x43,0x7F,0xC3,0x0E,0x06,0xEB,
  42109. 0x4E,0xB4,0x2D,0xFA,0xDD,0x48,0xAB,0xF4,
  42110. 0x7D,0x41,0x48,0x33,0x5A,0xE6,0x70,0x02,
  42111. 0xE7,0x71,0x8D,0xD9,0x6B,0x0C,0x5A,0x8F,
  42112. 0xA4,0xC1,0xB7,0x4E,0x96,0x83,0xD6,0xA7,
  42113. 0x1D,0xF1,0x88,0xB3,0x6E,0xF4,0x12,0xA9,
  42114. 0xF6,0x31,0x69,0x66,0xFE,0xFE,0x02,0xF2,
  42115. 0x86,0x6D,0xBB,0x57,0x51,0x8C,0x4C,0xE9,
  42116. 0x7C,0x92,0x3E,0x3A,0xD3,0x2D,0xA8,0x82,
  42117. 0x53,0x84,0x26,0x89,0xBB,0xCC,0x13,0x12,
  42118. 0x3D,0x94,0xBB,0xDF,0x3D,0x4C,0xDF,0x27,
  42119. 0x9B,0x1F,0xB8,0xB6,0xE4,0xEA,0xA2,0x07,
  42120. 0xF8,0x4D,0x42,0x8F,0x29,0x90,0xFE,0x21,
  42121. 0x20,0xE9,0x55,0x02,0xAD,0x90,0xA7,0x77,
  42122. 0x4E,0x29,0xB6,0xD9,0x14,0x94,0xB2,0x25,
  42123. 0xA4,0xB2,0x0E,0x96,0x31,0xAB,0x9E,0x93,
  42124. 0x49,0xAC,0xA9,0xCB,0x68,0x22,0xBA,0xB8,
  42125. 0x57,0x5C,0x9D,0x65,0xC1,0xF1,0xFC,0x99,
  42126. 0x7C,0x3C,0xE9,0xEA,0x4B,0x29,0x22,0x2F,
  42127. 0xDB,0x17,0x21,0x8D,0xB0,0x13,0xBF,0xEE,
  42128. 0x7D,0xE4,0x8B,0x6D,0x17,0xE0,0x53,0x92,
  42129. 0x0B,0x32,0x6B,0xB1,0x65,0x2E,0xA7,0x83,
  42130. 0xFD,0x62,0x62,0xE3,0xAA,0x81,0xE8,0xD6,
  42131. 0xF7,0xB1,0x30,0x65,0x80,0x9F,0x77,0x1E,
  42132. 0x4A,0xEA,0xE8,0x45,0x32,0x12,0x3A,0xFB,
  42133. 0x22,0xE9,0xA9,0xF6,0xCB,0xAB,0xA8,0x0C,
  42134. 0x20,0xA8,0x7C,0xF9,0xF7,0x53,0xC1,0xB4,
  42135. 0xC0,0x5D,0x06,0x45,0xDD,0x7E,0xA7,0x34,
  42136. 0xA1,0x21,0xC2,0x62,0xAB,0x22,0x45,0x3D,
  42137. 0x73,0x4C,0x26,0xD1,0x1A,0xB2,0xF0,0xB2,
  42138. 0x6D,0x11,0x70,0x58,0xAA,0xF5,0xA4,0xF5,
  42139. 0xF8,0x0B,0x3D,0xC1,0xF6,0x17,0x70,0x15,
  42140. 0xCD,0x72,0x02,0x7E,0x4E,0x94,0x96,0x0A,
  42141. 0x56,0xCC,0xA5,0xA3,0xB3,0x7E,0xDD,0x5A,
  42142. 0x72,0xD2,0xFB,0xAC,0x3D,0x0E,0x66,0x65,
  42143. 0xE9,0x08,0x6C,0xB0,0x1C,0xE2,0x1A,0x82,
  42144. 0xF6,0xF3,0x34,0x89,0x73,0x02,0x5B,0x42,
  42145. 0x6D,0x40,0x61,0xB6,0xE0,0xE6,0x53,0x32,
  42146. 0xA5,0x72,0x17,0x4F,0x3B,0x51,0x4F,0xBC,
  42147. 0x00,0xE0,0x69,0x26,0xA9,0xAE,0x83,0xE3,
  42148. 0x73,0x7F,0x71,0x97,0xE0,0xDC,0x7C,0x63,
  42149. 0x9C,0x85,0x5F,0xDF,0x7D,0xE4,0x6C,0xD8,
  42150. 0xA9,0x3A,0x6F,0x5E,0x4A,0x2E,0xB0,0xE7,
  42151. 0x8B,0x45,0xE2,0x90,0x05,0x37,0xE8,0xAB,
  42152. 0x49,0x48,0x4C,0xC0,0x59,0x1D,0x8C,0x46,
  42153. 0x5B,0x84,0xE0,0x83,0xCE,0xEA,0x4B,0xF9,
  42154. 0xD4,0xDC,0x63,0xDF,0x79,0xB7,0x5C,0x11,
  42155. 0x25,0x7F,0x90,0x2E,0x0A,0x38,0x03,0xEA,
  42156. 0xEA,0xA1,0x26,0x52,0x20,0x19,0xA3,0xBE,
  42157. 0xFC,0x9D,0xB7,0x6E,0xA6,0x58,0x8E,0x6D,
  42158. 0xC5,0x58,0xE9,0xED,0x2F,0x55,0x43,0x8B,
  42159. 0x03,0x8B,0xE6,0xA4,0xC2,0x25,0x4B,0x36,
  42160. 0xBA,0xD3,0x27,0x48,0x40,0x2E,0x87,0xA2,
  42161. 0xD4,0x12,0xC6,0x05,0x36,0x03,0x11,0x51,
  42162. 0xD1,0xF2,0xAC,0x71,0x2C,0xB6,0xC3,0xA5,
  42163. 0x57,0x0F,0xAF,0x4B,0xBD,0xCD,0x47,0x4C,
  42164. 0x3A,0x52,0x6F,0x47,0xE7,0x0B,0xB7,0xD5,
  42165. 0xF7,0xA6,0x39,0x63,0x82,0x08,0x4C,0x41,
  42166. 0x0E,0x2A,0x52,0x42,0x5A,0xEA,0x59,0xC7,
  42167. 0x94,0xFB,0xD0,0x88,0x47,0x27,0xF6,0x97,
  42168. 0x03,0x9E,0x29,0xB8,0x3A,0x67,0xE6,0xF3,
  42169. 0x95,0xA7,0x42,0xC1,0x96,0xD1,0x9A,0xA6,
  42170. 0xF0,0x09,0x0C,0xEA,0xE0,0xAB,0x0F,0x15,
  42171. 0xE9,0xC3,0xEB,0xA5,0x89,0x86,0x98,0x32,
  42172. 0x83,0xAB,0x30,0x33,0xAE,0x90,0x8D,0x2E,
  42173. 0xB3,0xAA,0x91,0xA6,0xD9,0xA4,0x4A,0x54,
  42174. 0xE0,0xD3,0x08,0xCC,0x79,0xCE,0xE4,0x15,
  42175. 0x31,0xA6,0xCE,0x61,0xCF,0x03,0x06,0xEE,
  42176. 0x8E,0xE2,0x64,0x29,0xD1,0x54,0x9B,0xD0,
  42177. 0x5F,0x09,0x2B,0x8B,0xD5,0xF8,0xD4,0x7D,
  42178. 0xF1,0x97,0x32,0xD9,0xEA,0x5A,0x0E,0x10,
  42179. 0x8C,0x4D,0xFB,0x55,0xE6,0x27,0x0C,0xBA,
  42180. 0xC1,0x73,0xC1,0x73,0xE3,0x1C,0x09,0xB3,
  42181. 0x6F,0xB4,0x12,0xFA,0xF3,0x29,0xDC,0x23,
  42182. 0x32,0xED,0x80,0x87,0x83,0xC2,0xF6,0x07,
  42183. 0xB5,0xA9,0x22,0xDE,0x66,0x1A,0xA7,0x4A,
  42184. 0x86,0xF1,0x39,0x9B,0xF4,0xE7,0x50,0x15,
  42185. 0x4A,0x55,0x3C,0x93,0xB9,0xF9,0xFD,0xDC,
  42186. 0xB3,0x5D,0x73,0x52
  42187. };
  42188. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t xmss_test_verify_only(void)
  42189. {
  42190. XmssKey verifyKey;
  42191. unsigned char pub_raw[XMSS_SHA256_PUBLEN];
  42192. word32 pub_len = sizeof(pub_raw);
  42193. word32 pkSz = 0;
  42194. word32 sigSz = 0;
  42195. const char * param = "XMSS-SHA2_10_256";
  42196. int j = 0;
  42197. int ret2 = WC_TEST_RET_ENC_NC;
  42198. int ret = WC_TEST_RET_ENC_NC;
  42199. int n_diff = 0;
  42200. WOLFSSL_ENTER("xmss_test_verify_only");
  42201. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42202. ret = wc_XmssKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42203. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42204. ret = wc_XmssKey_SetParamStr(&verifyKey, param);
  42205. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42206. ret = wc_XmssKey_GetPubLen(&verifyKey, &pkSz);
  42207. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42208. if (pkSz != XMSS_SHA256_PUBLEN) {
  42209. return WC_TEST_RET_ENC_EC(pkSz);
  42210. }
  42211. ret = wc_XmssKey_GetSigLen(&verifyKey, &sigSz);
  42212. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42213. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  42214. fprintf(stderr, "param: %s\n", param);
  42215. fprintf(stderr, "pkSz: %d\n", pkSz);
  42216. fprintf(stderr, "sigSz: %d\n", sigSz);
  42217. #endif
  42218. if (sigSz != sizeof(xmss_sig)) {
  42219. return WC_TEST_RET_ENC_EC(sigSz);
  42220. }
  42221. ret = wc_XmssKey_ImportPubRaw(&verifyKey, xmss_pub, XMSS_SHA256_PUBLEN);
  42222. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42223. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42224. (byte *) xmss_msg, sizeof(xmss_msg));
  42225. if (ret != 0) {
  42226. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42227. return WC_TEST_RET_ENC_EC(ret);
  42228. }
  42229. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42230. ret = wc_XmssKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42231. if (ret != 0) {
  42232. printf("error: wc_XmssKey_ExportPubRaw returned %d, expected 0\n", ret);
  42233. return WC_TEST_RET_ENC_EC(ret);
  42234. }
  42235. if (pub_len != XMSS_SHA256_PUBLEN) {
  42236. printf("error: xmss pub len %u, expected %d\n", pub_len,
  42237. XMSS_SHA256_PUBLEN);
  42238. return WC_TEST_RET_ENC_EC(pub_len);
  42239. }
  42240. n_diff = XMEMCMP(pub_raw, xmss_pub, sizeof(xmss_pub));
  42241. if (n_diff != 0) {
  42242. printf("error: exported and imported pub raw do not match: %d\n",
  42243. n_diff);
  42244. return WC_TEST_RET_ENC_EC(n_diff);
  42245. }
  42246. /* Flip bits in message. This should fail. */
  42247. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42248. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42249. (byte *) xmss_msg, sizeof(xmss_msg));
  42250. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42251. printf("error: wc_XmssKey_Verify returned %d, expected -1\n", ret2);
  42252. return WC_TEST_RET_ENC_EC(ret2);
  42253. }
  42254. /* Flip it back. This should pass again. */
  42255. xmss_msg[sizeof(xmss_msg) / 2] ^= 1;
  42256. ret = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42257. (byte *) xmss_msg, sizeof(xmss_msg));
  42258. if (ret != 0) {
  42259. printf("error: wc_XmssKey_Verify returned %d, expected 0\n", ret);
  42260. return WC_TEST_RET_ENC_EC(ret);
  42261. }
  42262. /* Flip bits in a few places throughout the signature, stepping in multiple
  42263. * of hash size. These should all fail with -1. */
  42264. for (j = 0; j < (int) sizeof(xmss_sig); j+= 4 * 32) {
  42265. xmss_sig[j] ^= 1;
  42266. ret2 = wc_XmssKey_Verify(&verifyKey, xmss_sig, sizeof(xmss_sig),
  42267. (byte *) xmss_msg, sizeof(xmss_msg));
  42268. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42269. /* Verify passed when it should have failed. */
  42270. return WC_TEST_RET_ENC_I(j);
  42271. }
  42272. /* Flip this spot back. */
  42273. xmss_sig[j] ^= 1;
  42274. }
  42275. /* Cleanup everything. */
  42276. wc_XmssKey_Free(&verifyKey);
  42277. return ret;
  42278. }
  42279. #endif /* WOLFSSL_HAVE_XMSS && !WOLFSSL_SMALL_STACK &&
  42280. * WOLFSSL_XMSS_MIN_HEIGHT <= 10 */
  42281. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  42282. static int lms_write_key_mem(const byte * priv, word32 privSz, void *context)
  42283. {
  42284. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  42285. * BE USED FOR TESTING PURPOSES! Production applications should
  42286. * write only to non-volatile storage. */
  42287. XMEMCPY(context, priv, privSz);
  42288. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  42289. }
  42290. static int lms_read_key_mem(byte * priv, word32 privSz, void *context)
  42291. {
  42292. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  42293. * BE USED FOR TESTING PURPOSES! */
  42294. XMEMCPY(priv, context, privSz);
  42295. return WC_LMS_RC_READ_TO_MEMORY;
  42296. }
  42297. /* LMS signature sizes are a function of their parameters. This
  42298. * test has a signature of 8688 bytes. */
  42299. #ifndef WOLFSSL_NO_LMS_SHA256_256
  42300. #define WC_TEST_LMS_SIG_LEN (8688)
  42301. #else
  42302. #define WC_TEST_LMS_SIG_LEN (4984)
  42303. #endif
  42304. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test(void)
  42305. {
  42306. int i = 0;
  42307. int j = 0;
  42308. int ret = WC_TEST_RET_ENC_NC;
  42309. int ret2 = WC_TEST_RET_ENC_NC;
  42310. int sigsLeft = 0;
  42311. LmsKey signingKey;
  42312. LmsKey verifyKey;
  42313. WC_RNG rng;
  42314. word32 sigSz = 0;
  42315. const char * msg = "LMS HSS post quantum signature test";
  42316. word32 msgSz = (word32) XSTRLEN(msg);
  42317. unsigned char priv[HSS_MAX_PRIVATE_KEY_LEN];
  42318. unsigned char old_priv[HSS_MAX_PRIVATE_KEY_LEN];
  42319. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42320. byte * sig = (byte*)XMALLOC(WC_TEST_LMS_SIG_LEN, HEAP_HINT,
  42321. DYNAMIC_TYPE_TMP_BUFFER);
  42322. if (sig == NULL) {
  42323. return WC_TEST_RET_ENC_ERRNO;
  42324. }
  42325. #else
  42326. byte sig[WC_TEST_LMS_SIG_LEN];
  42327. #endif
  42328. WOLFSSL_ENTER("lms_test");
  42329. XMEMSET(priv, 0, sizeof(priv));
  42330. XMEMSET(old_priv, 0, sizeof(old_priv));
  42331. XMEMSET(sig, 0, WC_TEST_LMS_SIG_LEN);
  42332. #ifndef HAVE_FIPS
  42333. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  42334. #else
  42335. ret = wc_InitRng(&rng);
  42336. #endif
  42337. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42338. /* This test:
  42339. * levels: 1
  42340. * height: 5
  42341. * winternitz: 1
  42342. *
  42343. * max sigs: 2 ** (1 * 5) = 32
  42344. * signature length: 8688
  42345. */
  42346. ret = wc_LmsKey_Init(&signingKey, NULL, INVALID_DEVID);
  42347. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42348. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42349. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42350. ret = wc_LmsKey_SetParameters(&signingKey, 1, 5, 1);
  42351. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42352. ret = wc_LmsKey_SetWriteCb(&signingKey, lms_write_key_mem);
  42353. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42354. ret = wc_LmsKey_SetReadCb(&signingKey, lms_read_key_mem);
  42355. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42356. ret = wc_LmsKey_SetContext(&signingKey, (void *) priv);
  42357. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42358. ret = wc_LmsKey_MakeKey(&signingKey, &rng);
  42359. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42360. XMEMCPY(old_priv, priv, sizeof(priv));
  42361. ret = wc_LmsKey_ExportPub(&verifyKey, &signingKey);
  42362. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42363. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42364. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42365. if (sigSz != WC_TEST_LMS_SIG_LEN) {
  42366. printf("error: got %u, expected %d\n", sigSz, WC_TEST_LMS_SIG_LEN);
  42367. return WC_TEST_RET_ENC_EC(sigSz);
  42368. }
  42369. /* 2 ** 5 should be the max number of signatures */
  42370. for (i = 0; i < 32; ++i) {
  42371. /* We should have remaining signstures. */
  42372. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42373. if (sigsLeft == 0) {
  42374. return WC_TEST_RET_ENC_EC(sigsLeft);
  42375. }
  42376. /* Sign with key. The private key will be updated on every signature. */
  42377. ret = wc_LmsKey_Sign(&signingKey, sig, &sigSz, (byte *) msg, msgSz);
  42378. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42379. /* The updated private key should not match the old one. */
  42380. if (XMEMCMP(old_priv, priv, sizeof(priv)) == 0) {
  42381. printf("error: current priv key should not match old: %d\n", i);
  42382. return WC_TEST_RET_ENC_I(i);
  42383. }
  42384. XMEMCPY(old_priv, priv, sizeof(priv));
  42385. ret = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg, msgSz);
  42386. if (ret != 0) { return WC_TEST_RET_ENC_I(i); }
  42387. /* Flip bits in a few places throughout the signature, stepping in multiple
  42388. * of hash size. These should all fail with -1. */
  42389. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42390. sig[j] ^= 1;
  42391. ret2 = wc_LmsKey_Verify(&verifyKey, sig, sigSz, (byte *) msg,
  42392. msgSz);
  42393. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42394. /* Verify passed when it should have failed. */
  42395. return WC_TEST_RET_ENC_I(j);
  42396. }
  42397. /* Flip this spot back. */
  42398. sig[j] ^= 1;
  42399. }
  42400. }
  42401. /* This should be the last signature. */
  42402. sigsLeft = wc_LmsKey_SigsLeft(&signingKey);
  42403. if (sigsLeft != 0) {
  42404. return WC_TEST_RET_ENC_EC(sigsLeft);
  42405. }
  42406. wc_LmsKey_Free(&signingKey);
  42407. wc_LmsKey_Free(&verifyKey);
  42408. wc_FreeRng(&rng);
  42409. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  42410. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  42411. #endif
  42412. return ret;
  42413. }
  42414. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  42415. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK)
  42416. #if (defined(WOLFSSL_WC_LMS) && (LMS_MAX_HEIGHT >= 10) && \
  42417. !defined(WOLFSSL_NO_LMS_SHA256_256)) || defined(HAVE_LIBLMS)
  42418. /* A simple LMS verify only test.
  42419. *
  42420. * Note: LMS signature sizes are a function of their parameters. This
  42421. * test has a signature of 1456 bytes:
  42422. * levels: 1
  42423. * height: 10
  42424. * winternitz: 8
  42425. * max sigs: 2 ** (1 * 10) = 1024
  42426. * signature length: 1456
  42427. * */
  42428. /* "wolfSSL LMS example message!" without null terminator. */
  42429. static byte lms_msg[28] =
  42430. {
  42431. 0x77,0x6F,0x6C,0x66,0x53,0x53,0x4C,0x20,
  42432. 0x4C,0x4D,0x53,0x20,0x65,0x78,0x61,0x6D,
  42433. 0x70,0x6C,0x65,0x20,0x6D,0x65,0x73,0x73,
  42434. 0x61,0x67,0x65,0x21
  42435. };
  42436. static const byte lms_L1H10W8_pub[HSS_MAX_PUBLIC_KEY_LEN] =
  42437. {
  42438. 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,
  42439. 0x00,0x00,0x00,0x04,0xA1,0x26,0x76,0xF8,
  42440. 0xBB,0x0B,0xC0,0x82,0x21,0x71,0x0B,0x2E,
  42441. 0x8C,0xA6,0xEF,0x12,0xED,0x41,0x0E,0x8C,
  42442. 0xAF,0x11,0x93,0x34,0x7B,0x49,0x79,0xB7,
  42443. 0xDE,0x63,0x1C,0xFE,0x1F,0xD1,0x17,0x49,
  42444. 0xCD,0x5C,0xD4,0x26,0xA0,0x53,0x26,0x1A,
  42445. 0xC5,0xB4,0x8F,0x23
  42446. };
  42447. #define LMS_L1H10W8_SIGLEN (1456)
  42448. static byte lms_L1H10W8_sig[LMS_L1H10W8_SIGLEN] =
  42449. {
  42450. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  42451. 0x00,0x00,0x00,0x04,0x18,0x70,0x09,0x2E,
  42452. 0x21,0xC9,0x6A,0xC9,0x5C,0xB6,0xB0,0xAA,
  42453. 0xC3,0xED,0x6E,0x66,0x2F,0xCC,0x45,0x81,
  42454. 0xBC,0xBA,0x44,0x96,0x1C,0xBF,0x4E,0xFB,
  42455. 0x7A,0x46,0xFB,0xBE,0x9A,0x0C,0xE4,0x50,
  42456. 0x90,0xC7,0x92,0xAC,0x53,0xAE,0x53,0x76,
  42457. 0x29,0xA6,0x65,0xF1,0x09,0xED,0x1A,0x8E,
  42458. 0x03,0x2E,0x5A,0x06,0x51,0xE3,0x1E,0xE6,
  42459. 0xF6,0xFE,0x3A,0x6E,0xD1,0x92,0x31,0x1D,
  42460. 0xA1,0x6A,0x5C,0x30,0x3A,0xC7,0xFD,0x5B,
  42461. 0xFE,0x71,0x2C,0x5C,0x2F,0x5B,0x5B,0xCF,
  42462. 0xBC,0x7F,0xBF,0x6C,0xAF,0x44,0x8A,0xAE,
  42463. 0x14,0x60,0xAB,0x88,0xED,0x0E,0x4F,0xF8,
  42464. 0xC7,0x1B,0x74,0x28,0x72,0xB3,0x96,0xA6,
  42465. 0xE6,0x46,0x22,0x82,0xCF,0x1F,0x4D,0xA6,
  42466. 0xEA,0x22,0x06,0x07,0x52,0xF5,0x26,0x16,
  42467. 0x0B,0x90,0xE3,0xFF,0x64,0xA9,0xE4,0x61,
  42468. 0x1E,0x9C,0x12,0x9C,0xF6,0xD4,0x63,0x29,
  42469. 0xEA,0x02,0xF7,0x18,0x52,0x79,0x6C,0x43,
  42470. 0xDC,0xCF,0x43,0x23,0xB9,0xCC,0x4A,0x25,
  42471. 0x9D,0x10,0xAF,0xA3,0xE6,0x47,0x5A,0x1C,
  42472. 0xFE,0x68,0x89,0xAF,0x1B,0x2D,0x88,0x3E,
  42473. 0xCA,0xDC,0x70,0xEA,0xAC,0x11,0x00,0x8A,
  42474. 0x6E,0xE0,0xC7,0xD0,0xD2,0x1A,0x36,0x18,
  42475. 0x97,0xB3,0x5F,0x0E,0x75,0x48,0x28,0xF8,
  42476. 0xA8,0xF5,0x90,0xD1,0xA1,0x84,0xFB,0xA4,
  42477. 0xAD,0x50,0xBE,0xE9,0x39,0x8C,0xC5,0xA1,
  42478. 0x67,0x51,0xA1,0x8C,0xD6,0x6B,0x97,0x1F,
  42479. 0x47,0x99,0xEE,0xE0,0x70,0x01,0xC7,0x07,
  42480. 0x50,0xF3,0x5E,0x3F,0xE7,0x06,0xD6,0x8D,
  42481. 0x26,0xD6,0x5A,0x59,0x18,0x72,0x6B,0x12,
  42482. 0xD2,0xAF,0x9B,0xB4,0x2B,0xD0,0xB2,0xF2,
  42483. 0x96,0x2F,0x40,0xEA,0xBE,0xE6,0xAC,0x1F,
  42484. 0xB8,0x33,0xC2,0x76,0xDC,0x8C,0xAC,0xC1,
  42485. 0x46,0x5E,0x04,0x84,0x1B,0xC8,0xB9,0x65,
  42486. 0x8D,0xAD,0x96,0xB5,0xB1,0xF6,0x17,0x4A,
  42487. 0x19,0x87,0xE7,0xBF,0x29,0xC7,0x9B,0xB9,
  42488. 0xD6,0x11,0x2C,0x92,0x2F,0xB7,0x24,0xD5,
  42489. 0x01,0x1D,0x80,0x37,0x54,0xED,0x33,0x32,
  42490. 0xAB,0x7A,0x12,0xD4,0x02,0x1D,0x27,0x52,
  42491. 0x89,0xDB,0x32,0xBF,0x61,0xD4,0xBB,0xB4,
  42492. 0x46,0x78,0x1B,0x64,0x17,0x84,0x4B,0x8A,
  42493. 0xBA,0xC6,0xC1,0xCF,0xC7,0x5D,0x8F,0x93,
  42494. 0xC5,0x9A,0x27,0x90,0xAC,0x17,0x98,0xFF,
  42495. 0xC8,0x22,0x59,0x55,0x90,0xB2,0x29,0x39,
  42496. 0xA0,0xBE,0x00,0x23,0x55,0x6B,0xDA,0x83,
  42497. 0xD8,0x5B,0x57,0x7C,0x67,0x1B,0xC3,0x6B,
  42498. 0x6D,0xC7,0x9B,0x2B,0x9E,0xB7,0x95,0xB3,
  42499. 0xF0,0x1B,0x89,0x5A,0xD7,0x4B,0x67,0xAF,
  42500. 0xDC,0x9E,0xCF,0x7E,0x1A,0xBA,0x1B,0xB9,
  42501. 0x3B,0x7A,0xDD,0x3F,0x0D,0xEE,0x4C,0x0B,
  42502. 0xD1,0x4F,0x34,0xF2,0x93,0xF7,0x21,0x64,
  42503. 0x2C,0x07,0x00,0x15,0x4F,0xE3,0x6A,0x9F,
  42504. 0x08,0x52,0xC2,0x65,0x47,0x1F,0x34,0x64,
  42505. 0x66,0x07,0xBC,0xEA,0xAF,0x9B,0xAA,0x39,
  42506. 0x15,0x8B,0x08,0x8C,0x24,0x41,0x9B,0x46,
  42507. 0x1B,0x5B,0x91,0x11,0xC4,0xFD,0xA9,0x88,
  42508. 0x35,0x0E,0x7D,0xAF,0xFD,0xB7,0x90,0x7E,
  42509. 0xD7,0x29,0x02,0x0A,0xDC,0xC8,0x3F,0xC0,
  42510. 0xFD,0x97,0xAF,0x50,0x49,0xA6,0x5E,0x12,
  42511. 0xC1,0xCD,0xEC,0x52,0xC5,0x51,0xF2,0x80,
  42512. 0x17,0x61,0xC7,0x7E,0xBE,0xD1,0x1B,0x65,
  42513. 0xA4,0xAB,0x92,0x8D,0x89,0xB2,0xC5,0x8F,
  42514. 0xFF,0xA5,0x6F,0xFA,0x62,0x75,0xE4,0xA1,
  42515. 0xD4,0x22,0xA8,0x9E,0x40,0x04,0x27,0x1F,
  42516. 0xCC,0x81,0xBA,0x28,0x67,0xA0,0x1C,0x80,
  42517. 0xEB,0xCA,0xB0,0x61,0xA5,0x48,0xD0,0x8A,
  42518. 0x25,0xEB,0x9E,0x67,0x8C,0x8E,0x9B,0xD1,
  42519. 0xAD,0xBB,0xC3,0xEA,0xD3,0xD4,0xC5,0x12,
  42520. 0x7B,0xDD,0x00,0x57,0x7F,0xF6,0xF7,0xF6,
  42521. 0x3C,0x05,0xCF,0xFC,0x12,0xE1,0x93,0x05,
  42522. 0xE5,0x9B,0x79,0x87,0x69,0xD8,0x82,0xD9,
  42523. 0xD7,0x1D,0x41,0x73,0xE4,0x52,0x1D,0x3E,
  42524. 0xE5,0x8C,0x8D,0x34,0xE1,0x75,0xA9,0xF1,
  42525. 0x9D,0x09,0xA2,0x5B,0xEF,0xDA,0x96,0x6E,
  42526. 0x76,0x3D,0xEA,0x50,0xD9,0xCF,0x4F,0xAC,
  42527. 0xAD,0x1D,0x35,0x72,0x1B,0x88,0x8B,0xCD,
  42528. 0x8C,0x8A,0x8A,0xE0,0x96,0x04,0xD8,0xBB,
  42529. 0x28,0x43,0x16,0x77,0x60,0x98,0x63,0xF9,
  42530. 0xB9,0x71,0x46,0xB7,0xE1,0xA7,0xA9,0x84,
  42531. 0xC3,0x65,0x82,0xE1,0x1B,0x67,0x04,0x2D,
  42532. 0x55,0x6B,0xF9,0xC0,0x79,0x09,0x09,0xE7,
  42533. 0xFD,0x06,0x4D,0x09,0x9B,0x1A,0xCE,0x35,
  42534. 0xFA,0x27,0x6F,0x2F,0x01,0x65,0x0D,0xA0,
  42535. 0x97,0x59,0x11,0xF0,0x48,0xD2,0xE7,0x46,
  42536. 0xBE,0xB4,0x0A,0xA3,0xE2,0x75,0x0E,0x09,
  42537. 0x94,0xD9,0x69,0x28,0xD4,0xDA,0x64,0xBA,
  42538. 0xFE,0xA4,0xB9,0xF0,0xBA,0xEB,0xBA,0xAC,
  42539. 0xA8,0xF9,0xD3,0x82,0x4C,0x36,0x80,0xFA,
  42540. 0xE5,0xF6,0x76,0xC3,0x80,0xFA,0x90,0x29,
  42541. 0xF4,0x85,0xA4,0xC6,0x25,0x22,0x79,0x7E,
  42542. 0x39,0x1E,0x30,0xB8,0x65,0x72,0xCF,0xE1,
  42543. 0x99,0xF0,0x75,0xE8,0x09,0xB4,0x92,0x96,
  42544. 0x1B,0x68,0x50,0x88,0xF1,0x2C,0x97,0xE3,
  42545. 0x2D,0x26,0x8F,0xC5,0x30,0xCF,0x24,0xCB,
  42546. 0xB2,0x60,0x77,0xDC,0x02,0x72,0x0D,0xD9,
  42547. 0x2E,0xF2,0x52,0xEA,0x00,0xF6,0x32,0x65,
  42548. 0xA5,0xC6,0x43,0x29,0x29,0x69,0xAB,0x27,
  42549. 0x0C,0x39,0xDF,0x76,0x3E,0x93,0x95,0xB1,
  42550. 0x2C,0xA2,0x0D,0x18,0xCE,0xA0,0x97,0x10,
  42551. 0x3C,0x90,0xC0,0xEF,0x0E,0x04,0xA6,0xC8,
  42552. 0xA0,0x21,0x3C,0x0B,0x22,0x77,0x7A,0x66,
  42553. 0xA5,0x90,0x25,0xA4,0x09,0x3E,0xD5,0x27,
  42554. 0x1F,0x6C,0x99,0x85,0x5C,0xA2,0x99,0x7A,
  42555. 0x25,0xEE,0x8D,0x32,0x3D,0xD3,0xDC,0xF5,
  42556. 0x00,0x5A,0x34,0x61,0xB6,0xCD,0x4E,0xBC,
  42557. 0x26,0x36,0xFB,0x44,0x97,0x35,0xBD,0x06,
  42558. 0x7D,0x2E,0x4A,0xA2,0xDC,0x24,0xFE,0x70,
  42559. 0x0A,0xF9,0x57,0xE3,0xEE,0xAB,0xD1,0x17,
  42560. 0xF3,0x7C,0xD6,0x37,0x26,0xFA,0x83,0x9F,
  42561. 0xDD,0xB2,0xE1,0xD7,0xF9,0xC7,0x0E,0x15,
  42562. 0x01,0xA6,0x58,0x32,0x98,0x04,0x32,0xD4,
  42563. 0xDE,0xB9,0xEF,0x09,0xFA,0xE4,0x5A,0xD7,
  42564. 0xDD,0x09,0x1C,0xC9,0xAC,0xB8,0x6A,0xF5,
  42565. 0x00,0x5D,0x6B,0x95,0x12,0x8C,0x2F,0xCC,
  42566. 0xD8,0xB9,0x50,0x3A,0xEB,0x74,0x86,0xD2,
  42567. 0x3F,0xA1,0x05,0x8F,0x6E,0xEF,0xF5,0xA4,
  42568. 0xD6,0x6E,0x53,0xFA,0x9E,0xFA,0xCE,0xDB,
  42569. 0x99,0x46,0xE7,0xC5,0xDA,0x92,0x51,0x4F,
  42570. 0x22,0x07,0xF3,0xA5,0x38,0x26,0xD3,0xEC,
  42571. 0xD6,0x01,0xDD,0x31,0x3A,0x48,0x93,0xF6,
  42572. 0x69,0x4F,0xD8,0xF6,0xC2,0x91,0xA5,0x7C,
  42573. 0xDF,0x51,0x64,0xF1,0x3B,0x79,0xBC,0x0A,
  42574. 0x2C,0xDC,0x33,0x5A,0x29,0xF6,0xB2,0x09,
  42575. 0x66,0xCA,0x24,0x9F,0x1A,0x18,0xF3,0x76,
  42576. 0x4C,0x5E,0x0B,0x81,0x7F,0x29,0x84,0xD8,
  42577. 0x7A,0xA8,0xD6,0x11,0xAC,0xEC,0xD9,0x07,
  42578. 0x91,0xEC,0xB6,0x6D,0xEC,0xDB,0xBE,0x6F,
  42579. 0x9F,0xC5,0x19,0x5E,0x56,0x87,0x20,0x80,
  42580. 0x75,0xD5,0x64,0xE9,0x80,0xBF,0x2D,0xD5,
  42581. 0x94,0x9F,0x8C,0xA4,0x54,0x41,0xAB,0xB1,
  42582. 0x8E,0xAD,0x51,0xE4,0x3C,0x24,0xF7,0x1D,
  42583. 0xFE,0x02,0x48,0x7C,0x6D,0xED,0xF1,0xAC,
  42584. 0xD9,0x79,0x42,0xE5,0x3A,0xCF,0x6A,0x4C,
  42585. 0x6D,0xE2,0x13,0xD2,0x2B,0x9D,0xAB,0x1F,
  42586. 0x70,0xD3,0xC0,0x6F,0x81,0xE9,0x9A,0x86,
  42587. 0x33,0x39,0x60,0xE7,0x6A,0x00,0x1F,0x97,
  42588. 0xEB,0xE5,0x1D,0x0D,0x66,0x15,0xC9,0xA2,
  42589. 0xB1,0xC0,0xF0,0x2E,0xF4,0x07,0xA2,0x2E,
  42590. 0x49,0x92,0x95,0x13,0xA3,0x18,0x46,0x25,
  42591. 0xB9,0x3C,0xA1,0x4B,0x00,0x00,0x00,0x06,
  42592. 0xAB,0xAA,0xF9,0x3F,0x7E,0x21,0xF4,0x0E,
  42593. 0xCE,0xFD,0xE0,0x44,0xAC,0xC7,0x1A,0x30,
  42594. 0x22,0x9D,0x0A,0xD7,0x96,0x2D,0x8F,0x9A,
  42595. 0x99,0x1F,0x40,0x75,0x7F,0x62,0xF9,0xC1,
  42596. 0x81,0x7B,0x4A,0x1B,0xFA,0xD6,0x87,0xB9,
  42597. 0xEF,0x58,0x48,0xE4,0x5C,0x79,0xE5,0xB1,
  42598. 0x2C,0x59,0xA4,0x42,0xDB,0xA6,0x53,0x70,
  42599. 0x80,0x61,0x17,0xD4,0xD3,0x77,0xBD,0x53,
  42600. 0x26,0x7C,0x0E,0x0E,0xFF,0x30,0x4B,0xD0,
  42601. 0x86,0xFC,0x02,0x20,0x24,0x46,0x5B,0xF5,
  42602. 0xE3,0x99,0x73,0x85,0x60,0x00,0x36,0x47,
  42603. 0x17,0xEE,0x0C,0xD2,0x80,0x71,0x46,0x0E,
  42604. 0x2B,0xB0,0xEF,0x7F,0xFE,0x3B,0xE5,0xE1,
  42605. 0x87,0xC2,0xAF,0x1A,0x6F,0x63,0xF4,0x5A,
  42606. 0xC4,0x16,0xF7,0xAD,0x07,0x70,0x71,0x85,
  42607. 0x7D,0x3D,0x67,0x08,0xB8,0xD8,0xE2,0xF0,
  42608. 0xA1,0xAC,0xD2,0x94,0x7D,0x93,0x03,0xDD,
  42609. 0x54,0xF9,0x64,0x19,0xB3,0xED,0x24,0x22,
  42610. 0x01,0xD7,0x12,0x5E,0xC1,0x2B,0x39,0x10,
  42611. 0x13,0xE2,0x56,0x1C,0xEE,0xF4,0x2A,0x49,
  42612. 0x7B,0xFB,0x36,0x8D,0xF8,0xAF,0x60,0xDF,
  42613. 0x10,0xF0,0x72,0xA2,0xED,0xB6,0x53,0x88,
  42614. 0xA9,0x0C,0xED,0x9C,0x18,0x33,0x7D,0x65,
  42615. 0x9B,0xB2,0x9C,0x3E,0xE9,0x1E,0x43,0x51,
  42616. 0x7E,0xBE,0x01,0x95,0xF6,0x60,0x65,0xBE,
  42617. 0xD1,0xF4,0xE2,0x83,0x6B,0xCA,0x7A,0x70,
  42618. 0x41,0x83,0x72,0xC0,0x23,0x51,0x13,0x11,
  42619. 0x2D,0xF9,0xC0,0x0D,0x7D,0x73,0x76,0xA5,
  42620. 0x30,0x83,0x68,0x10,0x35,0xA2,0x18,0x22,
  42621. 0x4E,0x21,0x93,0x27,0x6A,0x19,0x28,0x83,
  42622. 0x7F,0xDD,0xDD,0xFF,0xC3,0x8A,0x64,0x00,
  42623. 0x5F,0x1C,0x0D,0xF8,0xBB,0xD7,0x15,0xB9,
  42624. 0xEF,0xE0,0x07,0x62,0x05,0x9E,0xCF,0xFC,
  42625. 0x08,0x52,0x1E,0x65,0x41,0x56,0x6A,0xEB,
  42626. 0x81,0x53,0x30,0x7B,0xF2,0xFD,0x65,0xFF,
  42627. 0xA2,0x14,0xF5,0x62,0x1E,0x24,0x48,0x47,
  42628. 0xA5,0x41,0x80,0xB4,0xC5,0xDC,0xB2,0xB4,
  42629. 0x2D,0x17,0xE7,0xBE,0x49,0x53,0x7A,0x25,
  42630. 0xC5,0x0D,0x19,0x59,0xF4,0x88,0x59,0xED,
  42631. 0x92,0x13,0xEE,0x7A,0x4F,0x12,0x98,0x4C
  42632. };
  42633. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t lms_test_verify_only(void)
  42634. {
  42635. LmsKey verifyKey;
  42636. unsigned char pub_raw[HSS_MAX_PUBLIC_KEY_LEN];
  42637. word32 pub_len = sizeof(pub_raw);
  42638. word32 sigSz = 0;
  42639. word32 msgSz = sizeof(lms_msg);
  42640. word32 pubSz = 0;
  42641. int levels = 0;
  42642. int height = 0;
  42643. int winternitz = 0;
  42644. int ret = WC_TEST_RET_ENC_NC;
  42645. int ret2 = WC_TEST_RET_ENC_NC;
  42646. int j = 0;
  42647. int n_diff = 0;
  42648. WOLFSSL_ENTER("lms_test_verify_only");
  42649. XMEMSET(pub_raw, 0, sizeof(pub_raw));
  42650. ret = wc_LmsKey_Init(&verifyKey, NULL, INVALID_DEVID);
  42651. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42652. ret = wc_LmsKey_SetParameters(&verifyKey, 1, 10, 8);
  42653. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42654. ret = wc_LmsKey_ImportPubRaw(&verifyKey, lms_L1H10W8_pub,
  42655. HSS_MAX_PUBLIC_KEY_LEN);
  42656. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42657. /* Verify parameters, pub length, and sig length are correct. */
  42658. ret = wc_LmsKey_GetParameters(&verifyKey, &levels, &height, &winternitz);
  42659. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42660. if (levels != 1 || height != 10 || winternitz != 8) {
  42661. printf("error: invalid LMS parameters: L%d-H%d-W%d\n", levels, height,
  42662. winternitz);
  42663. return WC_TEST_RET_ENC_NC;
  42664. }
  42665. ret = wc_LmsKey_GetPubLen(&verifyKey, &pubSz);
  42666. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42667. if (pubSz != HSS_MAX_PUBLIC_KEY_LEN) {
  42668. printf("error: got %u, expected %d\n", pubSz, HSS_MAX_PUBLIC_KEY_LEN);
  42669. return WC_TEST_RET_ENC_EC(pubSz);
  42670. }
  42671. ret = wc_LmsKey_GetSigLen(&verifyKey, &sigSz);
  42672. if (ret != 0) { return WC_TEST_RET_ENC_EC(ret); }
  42673. if (sigSz != LMS_L1H10W8_SIGLEN) {
  42674. printf("error: got %u, expected %d\n", sigSz, LMS_L1H10W8_SIGLEN);
  42675. return WC_TEST_RET_ENC_EC(sigSz);
  42676. }
  42677. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42678. (byte *) lms_msg, msgSz);
  42679. if (ret != 0) {
  42680. printf("error: wc_LmsKey_Verify returned %d\n", ret);
  42681. return WC_TEST_RET_ENC_EC(ret);
  42682. }
  42683. /* Now test the ExportPubRaw API, verify we recover the original pub. */
  42684. ret = wc_LmsKey_ExportPubRaw(&verifyKey, pub_raw, &pub_len);
  42685. if (ret != 0) {
  42686. printf("error: wc_LmsKey_ExportPubRaw returned %d, expected 0\n", ret);
  42687. return WC_TEST_RET_ENC_EC(ret);
  42688. }
  42689. if (pub_len != HSS_MAX_PUBLIC_KEY_LEN) {
  42690. printf("error: LMS pub len %u, expected %d\n", pub_len,
  42691. HSS_MAX_PUBLIC_KEY_LEN);
  42692. return WC_TEST_RET_ENC_EC(pub_len);
  42693. }
  42694. n_diff = XMEMCMP(pub_raw, lms_L1H10W8_pub, sizeof(lms_L1H10W8_pub));
  42695. if (n_diff != 0) {
  42696. printf("error: exported and imported pub raw do not match: %d\n",
  42697. n_diff);
  42698. return WC_TEST_RET_ENC_EC(n_diff);
  42699. }
  42700. /* Flip bits in message. This should fail. */
  42701. lms_msg[msgSz / 2] ^= 1;
  42702. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42703. (byte *) lms_msg, msgSz);
  42704. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42705. printf("error: wc_LmsKey_Verify returned %d, expected -1\n", ret2);
  42706. return WC_TEST_RET_ENC_EC(ret);
  42707. }
  42708. /* Flip it back. This should pass again. */
  42709. lms_msg[msgSz / 2] ^= 1;
  42710. ret = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig, LMS_L1H10W8_SIGLEN,
  42711. (byte *) lms_msg, msgSz);
  42712. if (ret != 0) {
  42713. printf("error: wc_LmsKey_Verify returned %d, expected 0\n", ret);
  42714. return WC_TEST_RET_ENC_EC(ret);
  42715. }
  42716. /* Flip bits in a few places throughout the signature, stepping in multiple
  42717. * of hash size. These should all fail with -1. */
  42718. for (j = 0; j < (int) sigSz; j+= 4 * 32) {
  42719. lms_L1H10W8_sig[j] ^= 1;
  42720. ret2 = wc_LmsKey_Verify(&verifyKey, lms_L1H10W8_sig,
  42721. LMS_L1H10W8_SIGLEN,
  42722. (byte *) lms_msg, msgSz);
  42723. if ((ret2 != -1) && (ret2 != WC_NO_ERR_TRACE(SIG_VERIFY_E))) {
  42724. /* Verify passed when it should have failed. */
  42725. return WC_TEST_RET_ENC_I(j);
  42726. }
  42727. /* Flip this spot back. */
  42728. lms_L1H10W8_sig[j] ^= 1;
  42729. }
  42730. wc_LmsKey_Free(&verifyKey);
  42731. return ret;
  42732. }
  42733. #endif
  42734. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_SMALL_STACK) */
  42735. static const int fiducial3 = WC_TEST_RET_LN; /* source code reference point --
  42736. * see print_fiducials() below.
  42737. */
  42738. #ifdef WOLFCRYPT_HAVE_ECCSI
  42739. static wc_test_ret_t eccsi_api_test(WC_RNG* rng, EccsiKey* key, mp_int* ssk,
  42740. ecc_point* pvt)
  42741. {
  42742. wc_test_ret_t ret;
  42743. byte id[1] = { 0x00 };
  42744. int valid;
  42745. word32 sz;
  42746. byte data[256];
  42747. byte hash[WC_MAX_DIGEST_SIZE];
  42748. byte hashSz;
  42749. byte sig[257];
  42750. word32 sigSz;
  42751. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42752. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42753. return WC_TEST_RET_ENC_EC(ret);
  42754. ret = wc_InitEccsiKey_ex(NULL, 32, ECC_SECP256R1, HEAP_HINT, INVALID_DEVID);
  42755. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42756. return WC_TEST_RET_ENC_EC(ret);
  42757. ret = wc_InitEccsiKey(NULL, NULL, INVALID_DEVID);
  42758. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42759. return WC_TEST_RET_ENC_EC(ret);
  42760. ret = wc_InitEccsiKey(NULL, HEAP_HINT, INVALID_DEVID);
  42761. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42762. return WC_TEST_RET_ENC_EC(ret);
  42763. wc_FreeEccsiKey(NULL);
  42764. /* Create a valid key. */
  42765. ret = wc_InitEccsiKey(key, NULL, INVALID_DEVID);
  42766. if (ret != 0)
  42767. return WC_TEST_RET_ENC_EC(ret);
  42768. ret = wc_MakeEccsiKey(NULL, NULL);
  42769. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42770. return WC_TEST_RET_ENC_EC(ret);
  42771. ret = wc_MakeEccsiKey(key, NULL);
  42772. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42773. return WC_TEST_RET_ENC_EC(ret);
  42774. ret = wc_MakeEccsiKey(NULL, rng);
  42775. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42776. return WC_TEST_RET_ENC_EC(ret);
  42777. ret = wc_MakeEccsiPair(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL,
  42778. NULL);
  42779. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42780. return WC_TEST_RET_ENC_EC(ret);
  42781. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL);
  42782. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42783. return WC_TEST_RET_ENC_EC(ret);
  42784. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt);
  42785. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42786. return WC_TEST_RET_ENC_EC(ret);
  42787. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt);
  42788. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42789. return WC_TEST_RET_ENC_EC(ret);
  42790. ret = wc_MakeEccsiPair(key, NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42791. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42792. return WC_TEST_RET_ENC_EC(ret);
  42793. ret = wc_MakeEccsiPair(NULL, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42794. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42795. return WC_TEST_RET_ENC_EC(ret);
  42796. /* No key set */
  42797. ret = wc_MakeEccsiPair(key, rng, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt);
  42798. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42799. return WC_TEST_RET_ENC_EC(ret);
  42800. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL,
  42801. NULL);
  42802. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42803. return WC_TEST_RET_ENC_EC(ret);
  42804. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42805. NULL);
  42806. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42807. return WC_TEST_RET_ENC_EC(ret);
  42808. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, NULL,
  42809. &valid);
  42810. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42811. return WC_TEST_RET_ENC_EC(ret);
  42812. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, NULL, pvt,
  42813. &valid);
  42814. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42815. return WC_TEST_RET_ENC_EC(ret);
  42816. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, NULL, 1, ssk, pvt,
  42817. &valid);
  42818. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42819. return WC_TEST_RET_ENC_EC(ret);
  42820. ret = wc_ValidateEccsiPair(NULL, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42821. &valid);
  42822. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42823. return WC_TEST_RET_ENC_EC(ret);
  42824. /* No key set */
  42825. ret = wc_ValidateEccsiPair(key, WC_HASH_TYPE_SHA256, id, 1, ssk, pvt,
  42826. &valid);
  42827. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42828. return WC_TEST_RET_ENC_EC(ret);
  42829. ret = wc_ValidateEccsiPvt(NULL, NULL, NULL);
  42830. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42831. return WC_TEST_RET_ENC_EC(ret);
  42832. ret = wc_ValidateEccsiPvt(key, NULL, NULL);
  42833. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42834. return WC_TEST_RET_ENC_EC(ret);
  42835. ret = wc_ValidateEccsiPvt(NULL, pvt, NULL);
  42836. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42837. return WC_TEST_RET_ENC_EC(ret);
  42838. ret = wc_ValidateEccsiPvt(NULL, NULL, &valid);
  42839. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42840. return WC_TEST_RET_ENC_EC(ret);
  42841. ret = wc_ValidateEccsiPvt(key, pvt, NULL);
  42842. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42843. return WC_TEST_RET_ENC_EC(ret);
  42844. ret = wc_ValidateEccsiPvt(key, NULL, &valid);
  42845. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42846. return WC_TEST_RET_ENC_EC(ret);
  42847. ret = wc_ValidateEccsiPvt(NULL, pvt, &valid);
  42848. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42849. return WC_TEST_RET_ENC_EC(ret);
  42850. ret = wc_EncodeEccsiPair(NULL, NULL, NULL, data, NULL);
  42851. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42852. return WC_TEST_RET_ENC_EC(ret);
  42853. ret = wc_EncodeEccsiPair(key, ssk, pvt, data, NULL);
  42854. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42855. return WC_TEST_RET_ENC_EC(ret);
  42856. ret = wc_EncodeEccsiPair(key, ssk, NULL, data, &sz);
  42857. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42858. return WC_TEST_RET_ENC_EC(ret);
  42859. ret = wc_EncodeEccsiPair(key, NULL, pvt, data, &sz);
  42860. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42861. return WC_TEST_RET_ENC_EC(ret);
  42862. ret = wc_EncodeEccsiPair(NULL, ssk, pvt, data, &sz);
  42863. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42864. return WC_TEST_RET_ENC_EC(ret);
  42865. /* No key created so no curve information. */
  42866. ret = wc_EncodeEccsiPair(key, ssk, pvt, NULL, &sz);
  42867. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  42868. return WC_TEST_RET_ENC_EC(ret);
  42869. ret = wc_EncodeEccsiSsk(NULL, NULL, data, NULL);
  42870. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42871. return WC_TEST_RET_ENC_EC(ret);
  42872. ret = wc_EncodeEccsiSsk(key, ssk, data, NULL);
  42873. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42874. return WC_TEST_RET_ENC_EC(ret);
  42875. ret = wc_EncodeEccsiSsk(key, NULL, data, &sz);
  42876. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42877. return WC_TEST_RET_ENC_EC(ret);
  42878. ret = wc_EncodeEccsiSsk(NULL, ssk, data, &sz);
  42879. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42880. return WC_TEST_RET_ENC_EC(ret);
  42881. ret = wc_EncodeEccsiPvt(NULL, NULL, data, NULL, 1);
  42882. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42883. return WC_TEST_RET_ENC_EC(ret);
  42884. ret = wc_EncodeEccsiPvt(key, pvt, data, NULL, 1);
  42885. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42886. return WC_TEST_RET_ENC_EC(ret);
  42887. ret = wc_EncodeEccsiPvt(key, NULL, data, &sz, 1);
  42888. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42889. return WC_TEST_RET_ENC_EC(ret);
  42890. ret = wc_EncodeEccsiPvt(NULL, pvt, data, &sz, 1);
  42891. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42892. return WC_TEST_RET_ENC_EC(ret);
  42893. ret = wc_DecodeEccsiPair(NULL, NULL, 0, NULL, NULL);
  42894. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42895. return WC_TEST_RET_ENC_EC(ret);
  42896. ret = wc_DecodeEccsiPair(key, data, 0, ssk, NULL);
  42897. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42898. return WC_TEST_RET_ENC_EC(ret);
  42899. ret = wc_DecodeEccsiPair(key, data, 0, NULL, pvt);
  42900. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42901. return WC_TEST_RET_ENC_EC(ret);
  42902. ret = wc_DecodeEccsiPair(key, NULL, 0, ssk, pvt);
  42903. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42904. return WC_TEST_RET_ENC_EC(ret);
  42905. ret = wc_DecodeEccsiPair(NULL, data, 0, ssk, pvt);
  42906. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42907. return WC_TEST_RET_ENC_EC(ret);
  42908. ret = wc_DecodeEccsiSsk(NULL, NULL, 0, NULL);
  42909. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42910. return WC_TEST_RET_ENC_EC(ret);
  42911. ret = wc_DecodeEccsiSsk(key, data, 0, NULL);
  42912. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42913. return WC_TEST_RET_ENC_EC(ret);
  42914. ret = wc_DecodeEccsiSsk(key, NULL, 0, ssk);
  42915. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42916. return WC_TEST_RET_ENC_EC(ret);
  42917. ret = wc_DecodeEccsiSsk(NULL, data, 0, ssk);
  42918. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42919. return WC_TEST_RET_ENC_EC(ret);
  42920. ret = wc_DecodeEccsiPvt(NULL, NULL, 0, NULL);
  42921. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42922. return WC_TEST_RET_ENC_EC(ret);
  42923. ret = wc_DecodeEccsiPvt(key, data, 0, NULL);
  42924. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42925. return WC_TEST_RET_ENC_EC(ret);
  42926. ret = wc_DecodeEccsiPvt(key, NULL, 0, pvt);
  42927. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42928. return WC_TEST_RET_ENC_EC(ret);
  42929. ret = wc_DecodeEccsiPvt(NULL, data, 0, pvt);
  42930. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42931. return WC_TEST_RET_ENC_EC(ret);
  42932. ret = wc_DecodeEccsiPvtFromSig(NULL, NULL, 0, NULL);
  42933. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42934. return WC_TEST_RET_ENC_EC(ret);
  42935. ret = wc_DecodeEccsiPvtFromSig(key, data, 0, NULL);
  42936. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42937. return WC_TEST_RET_ENC_EC(ret);
  42938. ret = wc_DecodeEccsiPvtFromSig(key, NULL, 0, pvt);
  42939. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42940. return WC_TEST_RET_ENC_EC(ret);
  42941. ret = wc_DecodeEccsiPvtFromSig(NULL, data, 0, pvt);
  42942. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42943. return WC_TEST_RET_ENC_EC(ret);
  42944. ret = wc_ExportEccsiKey(NULL, data, NULL);
  42945. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42946. return WC_TEST_RET_ENC_EC(ret);
  42947. ret = wc_ExportEccsiKey(key, data, NULL);
  42948. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42949. return WC_TEST_RET_ENC_EC(ret);
  42950. ret = wc_ExportEccsiKey(NULL, data, &sz);
  42951. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42952. return WC_TEST_RET_ENC_EC(ret);
  42953. /* No key to export */
  42954. ret = wc_ExportEccsiKey(key, NULL, &sz);
  42955. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42956. return WC_TEST_RET_ENC_EC(ret);
  42957. ret = wc_ImportEccsiKey(NULL, NULL, 0);
  42958. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42959. return WC_TEST_RET_ENC_EC(ret);
  42960. ret = wc_ImportEccsiKey(key, NULL, 0);
  42961. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42962. return WC_TEST_RET_ENC_EC(ret);
  42963. ret = wc_ImportEccsiKey(NULL, data, 0);
  42964. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42965. return WC_TEST_RET_ENC_EC(ret);
  42966. ret = wc_ExportEccsiPrivateKey(NULL, data, NULL);
  42967. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42968. return WC_TEST_RET_ENC_EC(ret);
  42969. ret = wc_ExportEccsiPrivateKey(key, data, NULL);
  42970. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42971. return WC_TEST_RET_ENC_EC(ret);
  42972. ret = wc_ExportEccsiPrivateKey(NULL, data, &sz);
  42973. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42974. return WC_TEST_RET_ENC_EC(ret);
  42975. /* No key to export */
  42976. ret = wc_ExportEccsiPrivateKey(key, NULL, &sz);
  42977. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  42978. return WC_TEST_RET_ENC_EC(ret);
  42979. ret = wc_ImportEccsiPrivateKey(NULL, NULL, 0);
  42980. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42981. return WC_TEST_RET_ENC_EC(ret);
  42982. ret = wc_ImportEccsiPrivateKey(key, NULL, 0);
  42983. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42984. return WC_TEST_RET_ENC_EC(ret);
  42985. ret = wc_ImportEccsiPrivateKey(NULL, data, 0);
  42986. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42987. return WC_TEST_RET_ENC_EC(ret);
  42988. ret = wc_ExportEccsiPublicKey(NULL, data, NULL, 1);
  42989. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42990. return WC_TEST_RET_ENC_EC(ret);
  42991. ret = wc_ExportEccsiPublicKey(key, data, NULL, 1);
  42992. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42993. return WC_TEST_RET_ENC_EC(ret);
  42994. ret = wc_ExportEccsiPublicKey(NULL, data, &sz, 1);
  42995. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  42996. return WC_TEST_RET_ENC_EC(ret);
  42997. /* No key to export */
  42998. ret = wc_ExportEccsiPublicKey(key, data, &sz, 1);
  42999. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43000. return WC_TEST_RET_ENC_EC(ret);
  43001. ret = wc_ImportEccsiPublicKey(NULL, NULL, 0, 1);
  43002. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43003. return WC_TEST_RET_ENC_EC(ret);
  43004. ret = wc_ImportEccsiPublicKey(key, NULL, 0, 1);
  43005. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43006. return WC_TEST_RET_ENC_EC(ret);
  43007. ret = wc_ImportEccsiPublicKey(NULL, data, 0, 1);
  43008. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43009. return WC_TEST_RET_ENC_EC(ret);
  43010. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, NULL, 1, NULL, NULL, NULL);
  43011. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43012. return WC_TEST_RET_ENC_EC(ret);
  43013. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, NULL);
  43014. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43015. return WC_TEST_RET_ENC_EC(ret);
  43016. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, NULL, &hashSz);
  43017. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43018. return WC_TEST_RET_ENC_EC(ret);
  43019. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, NULL, hash, &hashSz);
  43020. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43021. return WC_TEST_RET_ENC_EC(ret);
  43022. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, NULL, 1, pvt, hash,
  43023. &hashSz);
  43024. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43025. return WC_TEST_RET_ENC_EC(ret);
  43026. ret = wc_HashEccsiId(NULL, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43027. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43028. return WC_TEST_RET_ENC_EC(ret);
  43029. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, 1, pvt, hash, &hashSz);
  43030. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43031. return WC_TEST_RET_ENC_EC(ret);
  43032. ret = wc_SetEccsiHash(NULL, NULL, 1);
  43033. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43034. return WC_TEST_RET_ENC_EC(ret);
  43035. ret = wc_SetEccsiHash(key, NULL, 1);
  43036. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43037. return WC_TEST_RET_ENC_EC(ret);
  43038. ret = wc_SetEccsiHash(NULL, hash, 1);
  43039. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43040. return WC_TEST_RET_ENC_EC(ret);
  43041. ret = wc_SetEccsiPair(NULL, NULL, NULL);
  43042. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43043. return WC_TEST_RET_ENC_EC(ret);
  43044. ret = wc_SetEccsiPair(key, NULL, NULL);
  43045. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43046. return WC_TEST_RET_ENC_EC(ret);
  43047. ret = wc_SetEccsiPair(NULL, ssk, NULL);
  43048. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43049. return WC_TEST_RET_ENC_EC(ret);
  43050. ret = wc_SetEccsiPair(NULL, NULL, pvt);
  43051. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43052. return WC_TEST_RET_ENC_EC(ret);
  43053. ret = wc_SetEccsiPair(key, ssk, NULL);
  43054. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43055. return WC_TEST_RET_ENC_EC(ret);
  43056. ret = wc_SetEccsiPair(key, NULL, pvt);
  43057. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43058. return WC_TEST_RET_ENC_EC(ret);
  43059. ret = wc_SetEccsiPair(NULL, ssk, pvt);
  43060. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43061. return WC_TEST_RET_ENC_EC(ret);
  43062. ret = wc_SignEccsiHash(NULL, NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, NULL);
  43063. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43064. return WC_TEST_RET_ENC_EC(ret);
  43065. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, sig, NULL);
  43066. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43067. return WC_TEST_RET_ENC_EC(ret);
  43068. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, NULL, 0, sig,
  43069. &sigSz);
  43070. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43071. return WC_TEST_RET_ENC_EC(ret);
  43072. ret = wc_SignEccsiHash(key, NULL, WC_HASH_TYPE_SHA256, data, 0, sig,
  43073. &sigSz);
  43074. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43075. return WC_TEST_RET_ENC_EC(ret);
  43076. ret = wc_SignEccsiHash(NULL, rng, WC_HASH_TYPE_SHA256, data, 0, sig,
  43077. &sigSz);
  43078. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43079. return WC_TEST_RET_ENC_EC(ret);
  43080. /* Key not set. */
  43081. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43082. &sigSz);
  43083. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43084. return WC_TEST_RET_ENC_EC(ret);
  43085. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  43086. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43087. return WC_TEST_RET_ENC_EC(ret);
  43088. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0, NULL);
  43089. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43090. return WC_TEST_RET_ENC_EC(ret);
  43091. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, NULL, 0, NULL);
  43092. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43093. return WC_TEST_RET_ENC_EC(ret);
  43094. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0, NULL);
  43095. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43096. return WC_TEST_RET_ENC_EC(ret);
  43097. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, NULL, 0, NULL, 0,
  43098. &valid);
  43099. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43100. return WC_TEST_RET_ENC_EC(ret);
  43101. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0, NULL);
  43102. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43103. return WC_TEST_RET_ENC_EC(ret);
  43104. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, NULL, 0,
  43105. &valid);
  43106. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43107. return WC_TEST_RET_ENC_EC(ret);
  43108. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, NULL, 0, sig, 0,
  43109. &valid);
  43110. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43111. return WC_TEST_RET_ENC_EC(ret);
  43112. ret = wc_VerifyEccsiHash(NULL, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43113. &valid);
  43114. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43115. return WC_TEST_RET_ENC_EC(ret);
  43116. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, data, 0, sig, 0,
  43117. &valid);
  43118. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43119. return WC_TEST_RET_ENC_EC(ret);
  43120. ret = wc_SetEccsiPair(key, ssk, pvt);
  43121. if (ret != 0)
  43122. return WC_TEST_RET_ENC_EC(ret);
  43123. /* Identity hash not set. */
  43124. ret = wc_SignEccsiHash(key, rng, WC_HASH_TYPE_SHA256, data, 0, NULL,
  43125. &sigSz);
  43126. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43127. return WC_TEST_RET_ENC_EC(ret);
  43128. wc_FreeEccsiKey(key);
  43129. return 0;
  43130. }
  43131. /* RFC 6507: Appendix A */
  43132. static wc_test_ret_t eccsi_kat_verify_test(EccsiKey* key, ecc_point* pvt)
  43133. {
  43134. wc_test_ret_t ret;
  43135. int verified;
  43136. const byte msg[] = { 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00 };
  43137. word32 msgSz = sizeof(msg);
  43138. byte hash[WC_SHA256_DIGEST_SIZE];
  43139. byte hashSz = WC_SHA256_DIGEST_SIZE;
  43140. static const byte id[] = {
  43141. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  43142. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  43143. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  43144. 0x33, 0x00
  43145. };
  43146. word32 idSz = sizeof(id);
  43147. static const byte sig[] = {
  43148. 0x26, 0x9D, 0x4C, 0x8F, 0xDE, 0xB6, 0x6A, 0x74,
  43149. 0xE4, 0xEF, 0x8C, 0x0D, 0x5D, 0xCC, 0x59, 0x7D,
  43150. 0xDF, 0xE6, 0x02, 0x9C, 0x2A, 0xFF, 0xC4, 0x93,
  43151. 0x60, 0x08, 0xCD, 0x2C, 0xC1, 0x04, 0x5D, 0x81,
  43152. 0xE0, 0x9B, 0x52, 0x8D, 0x0E, 0xF8, 0xD6, 0xDF,
  43153. 0x1A, 0xA3, 0xEC, 0xBF, 0x80, 0x11, 0x0C, 0xFC,
  43154. 0xEC, 0x9F, 0xC6, 0x82, 0x52, 0xCE, 0xBB, 0x67,
  43155. 0x9F, 0x41, 0x34, 0x84, 0x69, 0x40, 0xCC, 0xFD,
  43156. 0x04,
  43157. 0x75, 0x8A, 0x14, 0x27, 0x79, 0xBE, 0x89, 0xE8,
  43158. 0x29, 0xE7, 0x19, 0x84, 0xCB, 0x40, 0xEF, 0x75,
  43159. 0x8C, 0xC4, 0xAD, 0x77, 0x5F, 0xC5, 0xB9, 0xA3,
  43160. 0xE1, 0xC8, 0xED, 0x52, 0xF6, 0xFA, 0x36, 0xD9,
  43161. 0xA7, 0x9D, 0x24, 0x76, 0x92, 0xF4, 0xED, 0xA3,
  43162. 0xA6, 0xBD, 0xAB, 0x77, 0xD6, 0xAA, 0x64, 0x74,
  43163. 0xA4, 0x64, 0xAE, 0x49, 0x34, 0x66, 0x3C, 0x52,
  43164. 0x65, 0xBA, 0x70, 0x18, 0xBA, 0x09, 0x1F, 0x79
  43165. };
  43166. word32 sigSz = sizeof(sig);
  43167. static const byte pubData[] = {
  43168. 0x50, 0xD4, 0x67, 0x0B, 0xDE, 0x75, 0x24, 0x4F,
  43169. 0x28, 0xD2, 0x83, 0x8A, 0x0D, 0x25, 0x55, 0x8A,
  43170. 0x7A, 0x72, 0x68, 0x6D, 0x45, 0x22, 0xD4, 0xC8,
  43171. 0x27, 0x3F, 0xB6, 0x44, 0x2A, 0xEB, 0xFA, 0x93,
  43172. 0xDB, 0xDD, 0x37, 0x55, 0x1A, 0xFD, 0x26, 0x3B,
  43173. 0x5D, 0xFD, 0x61, 0x7F, 0x39, 0x60, 0xC6, 0x5A,
  43174. 0x8C, 0x29, 0x88, 0x50, 0xFF, 0x99, 0xF2, 0x03,
  43175. 0x66, 0xDC, 0xE7, 0xD4, 0x36, 0x72, 0x17, 0xF4
  43176. };
  43177. static const byte expHash[] = {
  43178. 0x49, 0x0f, 0x3f, 0xeb, 0xbc, 0x1c, 0x90, 0x2f,
  43179. 0x62, 0x89, 0x72, 0x3d, 0x7f, 0x8c, 0xbf, 0x79,
  43180. 0xdb, 0x88, 0x93, 0x08, 0x49, 0xd1, 0x9f, 0x38,
  43181. 0xf0, 0x29, 0x5b, 0x5c, 0x27, 0x6c, 0x14, 0xd1
  43182. };
  43183. ret = wc_ImportEccsiPublicKey(key, pubData, sizeof(pubData), 0);
  43184. if (ret != 0)
  43185. return WC_TEST_RET_ENC_EC(ret);
  43186. ret = wc_DecodeEccsiPvtFromSig(key, sig, sigSz, pvt);
  43187. if (ret != 0)
  43188. return WC_TEST_RET_ENC_EC(ret);
  43189. ret = wc_HashEccsiId(key, WC_HASH_TYPE_SHA256, id, idSz, pvt, hash,
  43190. &hashSz);
  43191. if (ret != 0)
  43192. return WC_TEST_RET_ENC_EC(ret);
  43193. if (hashSz != sizeof(expHash))
  43194. return WC_TEST_RET_ENC_NC;
  43195. if (XMEMCMP(hash, expHash, hashSz) != 0)
  43196. return WC_TEST_RET_ENC_NC;
  43197. ret = wc_SetEccsiHash(key, hash, hashSz);
  43198. if (ret != 0)
  43199. return WC_TEST_RET_ENC_EC(ret);
  43200. ret = wc_VerifyEccsiHash(key, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43201. &verified);
  43202. if (ret != 0)
  43203. return WC_TEST_RET_ENC_EC(ret);
  43204. if (!verified)
  43205. return WC_TEST_RET_ENC_NC;
  43206. return 0;
  43207. }
  43208. static wc_test_ret_t eccsi_enc_dec_pair_test(EccsiKey* priv, mp_int* ssk, ecc_point* pvt)
  43209. {
  43210. wc_test_ret_t ret;
  43211. byte data[32 * 3];
  43212. word32 sz;
  43213. ecc_point* decPvt = NULL;
  43214. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43215. mp_int *decSsk = (mp_int *)XMALLOC(sizeof(*decSsk), HEAP_HINT,
  43216. DYNAMIC_TYPE_TMP_BUFFER);
  43217. if (decSsk == NULL)
  43218. return WC_TEST_RET_ENC_ERRNO;
  43219. #else
  43220. mp_int decSsk[1];
  43221. #endif
  43222. ret = mp_init(decSsk);
  43223. if (ret != 0)
  43224. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43225. decPvt = wc_ecc_new_point();
  43226. if (decPvt == NULL)
  43227. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  43228. ret = wc_EncodeEccsiPair(priv, ssk, pvt, NULL, &sz);
  43229. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43230. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43231. if (sz != 32 * 3)
  43232. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43233. ret = wc_EncodeEccsiPair(priv, ssk, pvt, data, &sz);
  43234. if (ret != 0)
  43235. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43236. if (sz != 32* 3)
  43237. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43238. ret = wc_DecodeEccsiPair(priv, data, sz, decSsk, decPvt);
  43239. if (ret != 0)
  43240. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43241. ret = mp_cmp(ssk, decSsk);
  43242. if (ret != MP_EQ)
  43243. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43244. ret = wc_ecc_cmp_point(pvt, decPvt);
  43245. if (ret != MP_EQ)
  43246. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43247. ret = wc_EncodeEccsiSsk(priv, ssk, NULL, &sz);
  43248. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43249. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43250. if (sz != 32)
  43251. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43252. ret = wc_EncodeEccsiSsk(priv, ssk, data, &sz);
  43253. if (ret != 0)
  43254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43255. if (sz != 32)
  43256. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43257. ret = wc_DecodeEccsiSsk(priv, data, sz, decSsk);
  43258. if (ret != 0)
  43259. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43260. ret = mp_cmp(ssk, decSsk);
  43261. if (ret != MP_EQ)
  43262. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43263. ret = wc_EncodeEccsiPvt(priv, pvt, NULL, &sz, 1);
  43264. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43265. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43266. if (sz != 32 * 2)
  43267. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43268. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 1);
  43269. if (ret != 0)
  43270. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43271. if (sz != 32 * 2)
  43272. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43273. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43274. if (ret != 0)
  43275. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43276. ret = wc_ecc_cmp_point(pvt, decPvt);
  43277. if (ret != MP_EQ)
  43278. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43279. sz = sizeof(data);
  43280. ret = wc_EncodeEccsiPvt(priv, pvt, data, &sz, 0);
  43281. if (ret != 0)
  43282. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43283. if (sz != 32 * 2 + 1)
  43284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43285. ret = wc_DecodeEccsiPvt(priv, data, sz, decPvt);
  43286. if (ret != 0)
  43287. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  43288. ret = wc_ecc_cmp_point(pvt, decPvt);
  43289. if (ret != MP_EQ)
  43290. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  43291. wc_ecc_del_point(decPvt);
  43292. out:
  43293. mp_free(decSsk);
  43294. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  43295. XFREE(decSsk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43296. #endif
  43297. return ret;
  43298. }
  43299. static wc_test_ret_t eccsi_imp_exp_key_test(EccsiKey* priv)
  43300. {
  43301. wc_test_ret_t ret;
  43302. byte data[32 * 3];
  43303. byte out[32 * 3];
  43304. word32 sz;
  43305. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43306. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43307. return WC_TEST_RET_ENC_EC(ret);
  43308. if (sz != 32 * 3)
  43309. return WC_TEST_RET_ENC_NC;
  43310. ret = wc_ExportEccsiKey(priv, data, &sz);
  43311. if (ret != 0)
  43312. return WC_TEST_RET_ENC_EC(ret);
  43313. ret = wc_ImportEccsiKey(priv, data, sz);
  43314. if (ret != 0)
  43315. return WC_TEST_RET_ENC_EC(ret);
  43316. ret = wc_ExportEccsiKey(priv, NULL, &sz);
  43317. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43318. return WC_TEST_RET_ENC_EC(ret);
  43319. if (sz != 32 * 3)
  43320. return WC_TEST_RET_ENC_NC;
  43321. ret = wc_ExportEccsiKey(priv, out, &sz);
  43322. if (ret != 0)
  43323. return WC_TEST_RET_ENC_EC(ret);
  43324. if (sz != 32 * 3)
  43325. return WC_TEST_RET_ENC_NC;
  43326. if (XMEMCMP(data, out, sz) != 0)
  43327. return WC_TEST_RET_ENC_NC;
  43328. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43329. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43330. return WC_TEST_RET_ENC_EC(ret);
  43331. if (sz != 32)
  43332. return WC_TEST_RET_ENC_NC;
  43333. ret = wc_ExportEccsiPrivateKey(priv, data, &sz);
  43334. if (ret != 0)
  43335. return WC_TEST_RET_ENC_EC(ret);
  43336. ret = wc_ImportEccsiPrivateKey(priv, data, sz);
  43337. if (ret != 0)
  43338. return WC_TEST_RET_ENC_EC(ret);
  43339. ret = wc_ExportEccsiPrivateKey(priv, NULL, &sz);
  43340. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43341. return WC_TEST_RET_ENC_EC(ret);
  43342. if (sz != 32)
  43343. return WC_TEST_RET_ENC_NC;
  43344. ret = wc_ExportEccsiPrivateKey(priv, out, &sz);
  43345. if (ret != 0)
  43346. return WC_TEST_RET_ENC_EC(ret);
  43347. if (sz != 32)
  43348. return WC_TEST_RET_ENC_NC;
  43349. if (XMEMCMP(data, out, sz) != 0)
  43350. return WC_TEST_RET_ENC_NC;
  43351. return 0;
  43352. }
  43353. static wc_test_ret_t eccsi_imp_exp_pubkey_test(EccsiKey* key1, EccsiKey* key2)
  43354. {
  43355. wc_test_ret_t ret;
  43356. byte data[32 * 2 + 1];
  43357. byte pubData[32 * 2 + 1];
  43358. word32 sz;
  43359. ret = wc_ExportEccsiPublicKey(key1, NULL, &sz, 1);
  43360. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43361. return WC_TEST_RET_ENC_EC(ret);
  43362. if (sz != 32 * 2)
  43363. return WC_TEST_RET_ENC_NC;
  43364. ret = wc_ExportEccsiPublicKey(key1, data, &sz, 1);
  43365. if (ret != 0)
  43366. return WC_TEST_RET_ENC_EC(ret);
  43367. ret = wc_ImportEccsiPublicKey(key2, data, sz, 1);
  43368. if (ret != 0)
  43369. return WC_TEST_RET_ENC_EC(ret);
  43370. sz = sizeof(pubData);
  43371. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 1);
  43372. if (ret != 0)
  43373. return WC_TEST_RET_ENC_EC(ret);
  43374. if (sz != 32 * 2)
  43375. return WC_TEST_RET_ENC_NC;
  43376. if (XMEMCMP(data, pubData, sz) != 0)
  43377. return WC_TEST_RET_ENC_NC;
  43378. sz = sizeof(pubData);
  43379. ret = wc_ExportEccsiPublicKey(key2, pubData, &sz, 0);
  43380. if (ret != 0)
  43381. return WC_TEST_RET_ENC_EC(ret);
  43382. if (sz != 32 * 2 + 1)
  43383. return WC_TEST_RET_ENC_NC;
  43384. if (pubData[0] != 0x04)
  43385. return WC_TEST_RET_ENC_NC;
  43386. if (XMEMCMP(pubData + 1, data, sz - 1) != 0)
  43387. return WC_TEST_RET_ENC_NC;
  43388. ret = wc_ImportEccsiPublicKey(key2, pubData, sz, 0);
  43389. if (ret != 0)
  43390. return WC_TEST_RET_ENC_EC(ret);
  43391. return 0;
  43392. }
  43393. static wc_test_ret_t eccsi_make_key_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43394. mp_int* ssk, ecc_point* pvt)
  43395. {
  43396. wc_test_ret_t ret;
  43397. char mail[] = "test@wolfssl.com";
  43398. byte* id = (byte*)mail;
  43399. word32 idSz = (word32) XSTRLEN(mail);
  43400. int valid;
  43401. ret = wc_MakeEccsiKey(priv, rng);
  43402. if (ret != 0)
  43403. return WC_TEST_RET_ENC_EC(ret);
  43404. ret = eccsi_imp_exp_key_test(priv);
  43405. if (ret < 0)
  43406. return ret;
  43407. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43408. if (ret < 0)
  43409. return ret;
  43410. ret = wc_MakeEccsiPair(priv, rng, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt);
  43411. if (ret != 0)
  43412. return WC_TEST_RET_ENC_EC(ret);
  43413. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43414. &valid);
  43415. if (ret != 0)
  43416. return WC_TEST_RET_ENC_EC(ret);
  43417. if (!valid)
  43418. return WC_TEST_RET_ENC_NC;
  43419. ret = eccsi_enc_dec_pair_test(priv, ssk, pvt);
  43420. if (ret != 0)
  43421. return ret;
  43422. return 0;
  43423. }
  43424. static wc_test_ret_t eccsi_sign_verify_test(EccsiKey* priv, EccsiKey* pub, WC_RNG* rng,
  43425. mp_int* ssk, ecc_point* pvt)
  43426. {
  43427. wc_test_ret_t ret;
  43428. byte hashPriv[WC_MAX_DIGEST_SIZE];
  43429. byte hashPub[WC_MAX_DIGEST_SIZE];
  43430. byte hashSz;
  43431. byte sig[144];
  43432. word32 sigSz;
  43433. int verified, valid;
  43434. char mail[] = "test@wolfssl.com";
  43435. byte* id = (byte*)mail;
  43436. word32 idSz = (word32) XSTRLEN(mail);
  43437. byte msg[] = { 0x00 };
  43438. word32 msgSz = sizeof(msg);
  43439. #ifdef WOLFSSL_SHA384
  43440. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA384, id, idSz, pvt, hashPriv,
  43441. &hashSz);
  43442. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43443. return WC_TEST_RET_ENC_EC(ret);
  43444. #endif
  43445. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPriv,
  43446. &hashSz);
  43447. if (ret != 0)
  43448. return WC_TEST_RET_ENC_EC(ret);
  43449. if (hashSz != 32)
  43450. return WC_TEST_RET_ENC_NC;
  43451. ret = wc_HashEccsiId(priv, WC_HASH_TYPE_SHA256, id, idSz, pvt, hashPub,
  43452. &hashSz);
  43453. if (ret != 0)
  43454. return WC_TEST_RET_ENC_EC(ret);
  43455. if (hashSz != 32)
  43456. return WC_TEST_RET_ENC_NC;
  43457. if (XMEMCMP(hashPriv, hashPub, hashSz) != 0)
  43458. return WC_TEST_RET_ENC_NC;
  43459. ret = wc_SetEccsiHash(priv, hashPriv, hashSz);
  43460. if (ret != 0)
  43461. return WC_TEST_RET_ENC_EC(ret);
  43462. ret = wc_SetEccsiPair(priv, ssk, pvt);
  43463. if (ret != 0)
  43464. return WC_TEST_RET_ENC_EC(ret);
  43465. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, NULL,
  43466. &sigSz);
  43467. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43468. return WC_TEST_RET_ENC_EC(ret);
  43469. if (sigSz != 129)
  43470. return WC_TEST_RET_ENC_NC;
  43471. ret = wc_SignEccsiHash(priv, rng, WC_HASH_TYPE_SHA256, msg, msgSz, sig,
  43472. &sigSz);
  43473. if (ret != 0)
  43474. return WC_TEST_RET_ENC_EC(ret);
  43475. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43476. if (ret != 0)
  43477. return WC_TEST_RET_ENC_EC(ret);
  43478. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43479. &verified);
  43480. if (ret != 0)
  43481. return WC_TEST_RET_ENC_EC(ret);
  43482. if (!verified)
  43483. return WC_TEST_RET_ENC_NC;
  43484. /* Check that changing HS results in verification failure. */
  43485. hashPub[0] ^= 0x80;
  43486. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43487. if (ret != 0)
  43488. return WC_TEST_RET_ENC_EC(ret);
  43489. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43490. &verified);
  43491. if (ret != 0)
  43492. return WC_TEST_RET_ENC_EC(ret);
  43493. if (verified)
  43494. return WC_TEST_RET_ENC_NC;
  43495. hashPub[0] ^= 0x80;
  43496. ret = wc_SetEccsiHash(pub, hashPub, hashSz);
  43497. if (ret != 0)
  43498. return WC_TEST_RET_ENC_EC(ret);
  43499. /* Check that changing msg results in verification failure. */
  43500. msg[0] ^= 0x80;
  43501. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43502. &verified);
  43503. if (ret != 0)
  43504. return WC_TEST_RET_ENC_EC(ret);
  43505. if (verified)
  43506. return WC_TEST_RET_ENC_NC;
  43507. msg[0] ^= 0x80;
  43508. /* Check that changing signature results in verification failure. */
  43509. sig[0] ^= 0x80;
  43510. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43511. &verified);
  43512. if (ret != 0)
  43513. return WC_TEST_RET_ENC_EC(ret);
  43514. if (verified)
  43515. return WC_TEST_RET_ENC_NC;
  43516. sig[0] ^= 0x80;
  43517. /* Check that key state hasn't been invalidated. */
  43518. ret = wc_VerifyEccsiHash(pub, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43519. &verified);
  43520. if (ret != 0)
  43521. return WC_TEST_RET_ENC_EC(ret);
  43522. if (!verified)
  43523. return WC_TEST_RET_ENC_NC;
  43524. /* Check that verifying with the private key works. */
  43525. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43526. &verified);
  43527. if (ret != 0)
  43528. return WC_TEST_RET_ENC_EC(ret);
  43529. if (!verified)
  43530. return WC_TEST_RET_ENC_NC;
  43531. /* Check that the KPAK is converted from montgomery form. */
  43532. ret = eccsi_imp_exp_key_test(priv);
  43533. if (ret != 0)
  43534. return ret;
  43535. /* Check that KPAK can converted to Montgomery form again. */
  43536. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43537. &verified);
  43538. if (ret != 0)
  43539. return WC_TEST_RET_ENC_EC(ret);
  43540. if (!verified)
  43541. return WC_TEST_RET_ENC_NC;
  43542. /* Check that the KPAK is converted from montgomery form. */
  43543. ret = wc_ValidateEccsiPair(pub, WC_HASH_TYPE_SHA256, id, idSz, ssk, pvt,
  43544. &valid);
  43545. if (ret != 0)
  43546. return WC_TEST_RET_ENC_EC(ret);
  43547. if (!valid)
  43548. return WC_TEST_RET_ENC_NC;
  43549. /* Check that KPAK can converted to Montgomery form again. */
  43550. ret = wc_VerifyEccsiHash(priv, WC_HASH_TYPE_SHA256, msg, msgSz, sig, sigSz,
  43551. &verified);
  43552. if (ret != 0)
  43553. return WC_TEST_RET_ENC_EC(ret);
  43554. if (!verified)
  43555. return WC_TEST_RET_ENC_NC;
  43556. /* Check that the KPAK is converted from montgomery form. */
  43557. ret = eccsi_imp_exp_pubkey_test(priv, pub);
  43558. if (ret != 0)
  43559. return ret;
  43560. return 0;
  43561. }
  43562. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t eccsi_test(void)
  43563. {
  43564. wc_test_ret_t ret = 0;
  43565. WC_RNG rng;
  43566. int rng_inited = 0;
  43567. EccsiKey* priv = NULL;
  43568. EccsiKey* pub = NULL;
  43569. mp_int* ssk = NULL;
  43570. ecc_point* pvt = NULL;
  43571. WOLFSSL_ENTER("eccsi_test");
  43572. priv = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43573. DYNAMIC_TYPE_TMP_BUFFER);
  43574. if (priv == NULL)
  43575. ret = WC_TEST_RET_ENC_NC;
  43576. else
  43577. XMEMSET(priv, 0, sizeof(*priv));
  43578. if (ret == 0) {
  43579. pub = (EccsiKey*)XMALLOC(sizeof(EccsiKey), HEAP_HINT,
  43580. DYNAMIC_TYPE_TMP_BUFFER);
  43581. if (pub == NULL)
  43582. ret = WC_TEST_RET_ENC_NC;
  43583. else
  43584. XMEMSET(pub, 0, sizeof(*pub));
  43585. }
  43586. if (ret == 0) {
  43587. ssk = (mp_int*)XMALLOC(sizeof(mp_int), HEAP_HINT,
  43588. DYNAMIC_TYPE_TMP_BUFFER);
  43589. if (ssk == NULL)
  43590. ret = WC_TEST_RET_ENC_NC;
  43591. else
  43592. XMEMSET(ssk, 0, sizeof(*ssk));
  43593. }
  43594. if (ret == 0) {
  43595. #ifndef HAVE_FIPS
  43596. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  43597. #else
  43598. ret = wc_InitRng(&rng);
  43599. #endif
  43600. if (ret != 0)
  43601. ret = WC_TEST_RET_ENC_EC(ret);
  43602. else
  43603. rng_inited = 1;
  43604. }
  43605. if (ret == 0) {
  43606. pvt = wc_ecc_new_point();
  43607. if (pvt == NULL)
  43608. ret = WC_TEST_RET_ENC_NC;
  43609. }
  43610. if (ret == 0) {
  43611. ret = mp_init(ssk);
  43612. if (ret != 0)
  43613. ret = WC_TEST_RET_ENC_EC(ret);
  43614. }
  43615. if (ret == 0) {
  43616. ret = eccsi_api_test(&rng, priv, ssk, pvt);
  43617. }
  43618. if (ret == 0) {
  43619. ret = wc_InitEccsiKey(pub, HEAP_HINT, INVALID_DEVID);
  43620. if (ret != 0)
  43621. ret = WC_TEST_RET_ENC_EC(ret);
  43622. }
  43623. if (ret == 0) {
  43624. ret = wc_InitEccsiKey(priv, HEAP_HINT, INVALID_DEVID);
  43625. if (ret != 0)
  43626. ret = WC_TEST_RET_ENC_EC(ret);
  43627. }
  43628. if (ret == 0) {
  43629. ret = eccsi_kat_verify_test(pub, pvt);
  43630. }
  43631. if (ret == 0) {
  43632. ret = eccsi_make_key_test(priv, pub, &rng, ssk, pvt);
  43633. }
  43634. if (ret == 0) {
  43635. ret = eccsi_sign_verify_test(priv, pub, &rng, ssk, pvt);
  43636. }
  43637. if (pvt != NULL)
  43638. wc_ecc_del_point(pvt);
  43639. if (rng_inited)
  43640. wc_FreeRng(&rng);
  43641. if (ssk != NULL) {
  43642. mp_free(ssk);
  43643. XFREE(ssk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43644. }
  43645. if (pub != NULL) {
  43646. wc_FreeEccsiKey(pub);
  43647. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43648. }
  43649. if (priv != NULL) {
  43650. wc_FreeEccsiKey(priv);
  43651. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  43652. }
  43653. return ret;
  43654. }
  43655. #endif /* WOLFCRYPT_HAVE_ECCSI */
  43656. #ifdef WOLFCRYPT_HAVE_SAKKE
  43657. static wc_test_ret_t sakke_api_test(WC_RNG* rng, SakkeKey* key, ecc_point* rsk)
  43658. {
  43659. wc_test_ret_t ret;
  43660. byte id[1] = { 0x00 };
  43661. int valid;
  43662. byte data[256];
  43663. word32 sz;
  43664. byte auth[257];
  43665. word16 authSz;
  43666. byte ssv[256];
  43667. word16 ssvSz;
  43668. word32 len;
  43669. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  43670. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43671. return WC_TEST_RET_ENC_EC(ret);
  43672. ret = wc_InitSakkeKey_ex(NULL, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43673. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43674. return WC_TEST_RET_ENC_EC(ret);
  43675. wc_FreeSakkeKey(NULL);
  43676. XMEMSET(key, 0, sizeof(*key));
  43677. wc_FreeSakkeKey(key);
  43678. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, HEAP_HINT, INVALID_DEVID);
  43679. if (ret != 0)
  43680. return WC_TEST_RET_ENC_EC(ret);
  43681. ret = wc_MakeSakkeKey(NULL, NULL);
  43682. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43683. return WC_TEST_RET_ENC_EC(ret);
  43684. ret = wc_MakeSakkeKey(key, NULL);
  43685. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43686. return WC_TEST_RET_ENC_EC(ret);
  43687. ret = wc_MakeSakkeKey(NULL, rng);
  43688. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43689. return WC_TEST_RET_ENC_EC(ret);
  43690. ret = wc_MakeSakkePublicKey(NULL, NULL);
  43691. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43692. return WC_TEST_RET_ENC_EC(ret);
  43693. ret = wc_MakeSakkePublicKey(key, NULL);
  43694. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43695. return WC_TEST_RET_ENC_EC(ret);
  43696. ret = wc_MakeSakkePublicKey(NULL, rsk);
  43697. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43698. return WC_TEST_RET_ENC_EC(ret);
  43699. ret = wc_MakeSakkeRsk(NULL, NULL, 1, NULL);
  43700. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43701. return WC_TEST_RET_ENC_EC(ret);
  43702. ret = wc_MakeSakkeRsk(key, id, 1, NULL);
  43703. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43704. return WC_TEST_RET_ENC_EC(ret);
  43705. ret = wc_MakeSakkeRsk(key, NULL, 1, rsk);
  43706. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43707. return WC_TEST_RET_ENC_EC(ret);
  43708. ret = wc_MakeSakkeRsk(NULL, id, 1, rsk);
  43709. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43710. return WC_TEST_RET_ENC_EC(ret);
  43711. ret = wc_ValidateSakkeRsk(NULL, NULL, 1, NULL, NULL);
  43712. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43713. return WC_TEST_RET_ENC_EC(ret);
  43714. ret = wc_ValidateSakkeRsk(key, id, 1, rsk, NULL);
  43715. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43716. return WC_TEST_RET_ENC_EC(ret);
  43717. ret = wc_ValidateSakkeRsk(NULL, id, 1, rsk, &valid);
  43718. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43719. return WC_TEST_RET_ENC_EC(ret);
  43720. ret = wc_ExportSakkeKey(NULL, NULL, NULL);
  43721. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43722. return WC_TEST_RET_ENC_EC(ret);
  43723. ret = wc_ExportSakkeKey(key, data, NULL);
  43724. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43725. return WC_TEST_RET_ENC_EC(ret);
  43726. ret = wc_ExportSakkeKey(NULL, data, &sz);
  43727. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43728. return WC_TEST_RET_ENC_EC(ret);
  43729. ret = wc_ImportSakkeKey(NULL, NULL, 1);
  43730. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43731. return WC_TEST_RET_ENC_EC(ret);
  43732. ret = wc_ImportSakkeKey(key, NULL, 1);
  43733. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43734. return WC_TEST_RET_ENC_EC(ret);
  43735. ret = wc_ImportSakkeKey(NULL, data, 1);
  43736. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43737. return WC_TEST_RET_ENC_EC(ret);
  43738. ret = wc_ExportSakkePrivateKey(NULL, NULL, NULL);
  43739. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43740. return WC_TEST_RET_ENC_EC(ret);
  43741. ret = wc_ExportSakkePrivateKey(key, data, NULL);
  43742. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43743. return WC_TEST_RET_ENC_EC(ret);
  43744. ret = wc_ExportSakkePrivateKey(NULL, data, &sz);
  43745. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43746. return WC_TEST_RET_ENC_EC(ret);
  43747. ret = wc_ImportSakkePrivateKey(NULL, NULL, 1);
  43748. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43749. return WC_TEST_RET_ENC_EC(ret);
  43750. ret = wc_ImportSakkePrivateKey(key, NULL, 1);
  43751. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43752. return WC_TEST_RET_ENC_EC(ret);
  43753. ret = wc_ImportSakkePrivateKey(NULL, data, 1);
  43754. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43755. return WC_TEST_RET_ENC_EC(ret);
  43756. sz = sizeof(data);
  43757. ret = wc_EncodeSakkeRsk(NULL, NULL, data, NULL, 1);
  43758. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43759. return WC_TEST_RET_ENC_EC(ret);
  43760. ret = wc_EncodeSakkeRsk(key, rsk, data, NULL, 1);
  43761. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43762. return WC_TEST_RET_ENC_EC(ret);
  43763. ret = wc_EncodeSakkeRsk(key, NULL, data, &sz, 1);
  43764. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43765. return WC_TEST_RET_ENC_EC(ret);
  43766. ret = wc_EncodeSakkeRsk(NULL, rsk, data, &sz, 1);
  43767. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43768. return WC_TEST_RET_ENC_EC(ret);
  43769. ret = wc_DecodeSakkeRsk(NULL, NULL, sz, NULL);
  43770. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43771. return WC_TEST_RET_ENC_EC(ret);
  43772. ret = wc_DecodeSakkeRsk(key, data, sz, NULL);
  43773. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43774. return WC_TEST_RET_ENC_EC(ret);
  43775. ret = wc_DecodeSakkeRsk(key, NULL, sz, rsk);
  43776. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43777. return WC_TEST_RET_ENC_EC(ret);
  43778. ret = wc_DecodeSakkeRsk(NULL, data, sz, rsk);
  43779. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43780. return WC_TEST_RET_ENC_EC(ret);
  43781. ret = wc_ImportSakkeRsk(NULL, NULL, sz);
  43782. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43783. return WC_TEST_RET_ENC_EC(ret);
  43784. ret = wc_ImportSakkeRsk(key, NULL, sz);
  43785. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43786. return WC_TEST_RET_ENC_EC(ret);
  43787. ret = wc_ImportSakkeRsk(NULL, data, sz);
  43788. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43789. return WC_TEST_RET_ENC_EC(ret);
  43790. ret = wc_ImportSakkeRsk(key, data, 1);
  43791. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43792. return WC_TEST_RET_ENC_EC(ret);
  43793. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, NULL);
  43794. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43795. return WC_TEST_RET_ENC_EC(ret);
  43796. ret = wc_GenerateSakkeRskTable(key, NULL, data, NULL);
  43797. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43798. return WC_TEST_RET_ENC_EC(ret);
  43799. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, NULL);
  43800. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43801. return WC_TEST_RET_ENC_EC(ret);
  43802. ret = wc_GenerateSakkeRskTable(NULL, NULL, data, &len);
  43803. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43804. return WC_TEST_RET_ENC_EC(ret);
  43805. ret = wc_GenerateSakkeRskTable(key, rsk, data, NULL);
  43806. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43807. return WC_TEST_RET_ENC_EC(ret);
  43808. ret = wc_GenerateSakkeRskTable(key, NULL, data, &len);
  43809. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43810. return WC_TEST_RET_ENC_EC(ret);
  43811. ret = wc_GenerateSakkeRskTable(NULL, rsk, data, &len);
  43812. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43813. return WC_TEST_RET_ENC_EC(ret);
  43814. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  43815. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43816. return WC_TEST_RET_ENC_EC(ret);
  43817. len--;
  43818. ret = wc_GenerateSakkeRskTable(key, rsk, data, &len);
  43819. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43820. return WC_TEST_RET_ENC_EC(ret);
  43821. ret = wc_ExportSakkePublicKey(NULL, data, NULL, 1);
  43822. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43823. return WC_TEST_RET_ENC_EC(ret);
  43824. ret = wc_ExportSakkePublicKey(key, data, NULL, 1);
  43825. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43826. return WC_TEST_RET_ENC_EC(ret);
  43827. ret = wc_ExportSakkePublicKey(NULL, data, &sz, 1);
  43828. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43829. return WC_TEST_RET_ENC_EC(ret);
  43830. ret = wc_ImportSakkePublicKey(NULL, NULL, sz, 1);
  43831. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43832. return WC_TEST_RET_ENC_EC(ret);
  43833. ret = wc_ImportSakkePublicKey(key, NULL, sz, 1);
  43834. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43835. return WC_TEST_RET_ENC_EC(ret);
  43836. ret = wc_ImportSakkePublicKey(NULL, data, sz, 1);
  43837. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43838. return WC_TEST_RET_ENC_EC(ret);
  43839. ret = wc_GetSakkeAuthSize(NULL, NULL);
  43840. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43841. return WC_TEST_RET_ENC_EC(ret);
  43842. ret = wc_GetSakkeAuthSize(key, NULL);
  43843. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43844. return WC_TEST_RET_ENC_EC(ret);
  43845. ret = wc_GetSakkeAuthSize(NULL, &authSz);
  43846. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43847. return WC_TEST_RET_ENC_EC(ret);
  43848. ret = wc_MakeSakkePointI(NULL, NULL, SAKKE_ID_MAX_SIZE + 1);
  43849. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43850. return WC_TEST_RET_ENC_EC(ret);
  43851. ret = wc_MakeSakkePointI(key, NULL, SAKKE_ID_MAX_SIZE + 1);
  43852. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43853. return WC_TEST_RET_ENC_EC(ret);
  43854. ret = wc_MakeSakkePointI(NULL, id, 1);
  43855. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43856. return WC_TEST_RET_ENC_EC(ret);
  43857. ret = wc_MakeSakkePointI(NULL, NULL, 1);
  43858. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43859. return WC_TEST_RET_ENC_EC(ret);
  43860. ret = wc_MakeSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1);
  43861. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43862. return WC_TEST_RET_ENC_EC(ret);
  43863. ret = wc_MakeSakkePointI(key, NULL, 1);
  43864. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43865. return WC_TEST_RET_ENC_EC(ret);
  43866. ret = wc_MakeSakkePointI(NULL, id, 1);
  43867. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43868. return WC_TEST_RET_ENC_EC(ret);
  43869. ret = wc_GenerateSakkePointITable(NULL, data, NULL);
  43870. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43871. return WC_TEST_RET_ENC_EC(ret);
  43872. ret = wc_GenerateSakkePointITable(key, data, NULL);
  43873. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43874. return WC_TEST_RET_ENC_EC(ret);
  43875. ret = wc_GenerateSakkePointITable(NULL, data, &len);
  43876. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43877. return WC_TEST_RET_ENC_EC(ret);
  43878. ret = wc_GenerateSakkePointITable(key, NULL, &len);
  43879. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  43880. return WC_TEST_RET_ENC_EC(ret);
  43881. len--;
  43882. ret = wc_GenerateSakkePointITable(key, data, &len);
  43883. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43884. return WC_TEST_RET_ENC_EC(ret);
  43885. ret = wc_SetSakkePointITable(NULL, NULL, 1);
  43886. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43887. return WC_TEST_RET_ENC_EC(ret);
  43888. ret = wc_SetSakkePointITable(key, NULL, 1);
  43889. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43890. return WC_TEST_RET_ENC_EC(ret);
  43891. ret = wc_SetSakkePointITable(NULL, data, 1);
  43892. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43893. return WC_TEST_RET_ENC_EC(ret);
  43894. ret = wc_SetSakkePointITable(key, data, 1);
  43895. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43896. return WC_TEST_RET_ENC_EC(ret);
  43897. ret = wc_ClearSakkePointITable(NULL);
  43898. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43899. return WC_TEST_RET_ENC_EC(ret);
  43900. ret = wc_GetSakkePointI(NULL, data, NULL);
  43901. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43902. return WC_TEST_RET_ENC_EC(ret);
  43903. ret = wc_GetSakkePointI(key, data, NULL);
  43904. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43905. return WC_TEST_RET_ENC_EC(ret);
  43906. ret = wc_GetSakkePointI(NULL, data, &sz);
  43907. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43908. return WC_TEST_RET_ENC_EC(ret);
  43909. sz = 1;
  43910. ret = wc_GetSakkePointI(key, data, &sz);
  43911. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43912. return WC_TEST_RET_ENC_EC(ret);
  43913. sz = 256;
  43914. ret = wc_SetSakkePointI(NULL, NULL, 1, NULL, sz);
  43915. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43916. return WC_TEST_RET_ENC_EC(ret);
  43917. ret = wc_SetSakkePointI(key, NULL, 1, NULL, sz);
  43918. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43919. return WC_TEST_RET_ENC_EC(ret);
  43920. ret = wc_SetSakkePointI(NULL, id, 1, NULL, sz);
  43921. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43922. return WC_TEST_RET_ENC_EC(ret);
  43923. ret = wc_SetSakkePointI(NULL, NULL, 1, data, sz);
  43924. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43925. return WC_TEST_RET_ENC_EC(ret);
  43926. ret = wc_SetSakkePointI(key, id, 1, NULL, sz);
  43927. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43928. return WC_TEST_RET_ENC_EC(ret);
  43929. ret = wc_SetSakkePointI(key, NULL, 1, data, sz);
  43930. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43931. return WC_TEST_RET_ENC_EC(ret);
  43932. ret = wc_SetSakkePointI(NULL, id, 1, data, sz);
  43933. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43934. return WC_TEST_RET_ENC_EC(ret);
  43935. ret = wc_SetSakkePointI(key, id, SAKKE_ID_MAX_SIZE + 1, data, sz);
  43936. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43937. return WC_TEST_RET_ENC_EC(ret);
  43938. ret = wc_SetSakkePointI(key, id, 1, data, sz - 1);
  43939. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  43940. return WC_TEST_RET_ENC_EC(ret);
  43941. ret = wc_SetSakkeIdentity(NULL, NULL, 1);
  43942. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43943. return WC_TEST_RET_ENC_EC(ret);
  43944. ret = wc_SetSakkeIdentity(key, NULL, 1);
  43945. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43946. return WC_TEST_RET_ENC_EC(ret);
  43947. ret = wc_SetSakkeIdentity(NULL, id, 1);
  43948. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43949. return WC_TEST_RET_ENC_EC(ret);
  43950. ssvSz = sizeof(ssv);
  43951. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43952. auth, NULL);
  43953. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43954. return WC_TEST_RET_ENC_EC(ret);
  43955. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43956. auth, NULL);
  43957. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43958. return WC_TEST_RET_ENC_EC(ret);
  43959. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43960. auth, NULL);
  43961. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43962. return WC_TEST_RET_ENC_EC(ret);
  43963. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43964. auth, &authSz);
  43965. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43966. return WC_TEST_RET_ENC_EC(ret);
  43967. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43968. auth, NULL);
  43969. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43970. return WC_TEST_RET_ENC_EC(ret);
  43971. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz,
  43972. auth, &authSz);
  43973. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43974. return WC_TEST_RET_ENC_EC(ret);
  43975. ret = wc_MakeSakkeEncapsulatedSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43976. auth, &authSz);
  43977. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43978. return WC_TEST_RET_ENC_EC(ret);
  43979. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  43980. auth, &authSz);
  43981. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  43982. return WC_TEST_RET_ENC_EC(ret);
  43983. ret = wc_GenerateSakkeSSV(NULL, NULL, data, NULL);
  43984. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43985. return WC_TEST_RET_ENC_EC(ret);
  43986. ret = wc_GenerateSakkeSSV(key, rng, data, NULL);
  43987. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43988. return WC_TEST_RET_ENC_EC(ret);
  43989. ret = wc_GenerateSakkeSSV(key, NULL, data, &ssvSz);
  43990. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43991. return WC_TEST_RET_ENC_EC(ret);
  43992. ret = wc_GenerateSakkeSSV(NULL, rng, data, &ssvSz);
  43993. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43994. return WC_TEST_RET_ENC_EC(ret);
  43995. ret = wc_SetSakkeRsk(NULL, NULL, data, 1);
  43996. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  43997. return WC_TEST_RET_ENC_EC(ret);
  43998. ret = wc_SetSakkeRsk(key, NULL, data, 1);
  43999. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44000. return WC_TEST_RET_ENC_EC(ret);
  44001. ret = wc_SetSakkeRsk(NULL, rsk, data, 1);
  44002. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44003. return WC_TEST_RET_ENC_EC(ret);
  44004. ssvSz = sizeof(ssv);
  44005. authSz = sizeof(auth);
  44006. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  44007. authSz);
  44008. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44009. return WC_TEST_RET_ENC_EC(ret);
  44010. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, NULL,
  44011. authSz);
  44012. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44013. return WC_TEST_RET_ENC_EC(ret);
  44014. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  44015. authSz);
  44016. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44017. return WC_TEST_RET_ENC_EC(ret);
  44018. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44019. authSz);
  44020. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44021. return WC_TEST_RET_ENC_EC(ret);
  44022. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, NULL,
  44023. authSz);
  44024. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44025. return WC_TEST_RET_ENC_EC(ret);
  44026. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, NULL, ssvSz, auth,
  44027. authSz);
  44028. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44029. return WC_TEST_RET_ENC_EC(ret);
  44030. ret = wc_DeriveSakkeSSV(NULL, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44031. authSz);
  44032. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  44033. return WC_TEST_RET_ENC_EC(ret);
  44034. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44035. authSz);
  44036. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44037. return WC_TEST_RET_ENC_EC(ret);
  44038. ret = wc_SetSakkeIdentity(key, id, 1);
  44039. if (ret != 0)
  44040. return WC_TEST_RET_ENC_EC(ret);
  44041. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44042. authSz);
  44043. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44044. return WC_TEST_RET_ENC_EC(ret);
  44045. ret = wc_SetSakkeIdentity(key, id, 0);
  44046. if (ret != 0)
  44047. return WC_TEST_RET_ENC_EC(ret);
  44048. ret = wc_SetSakkeRsk(key, rsk, data, 1);
  44049. if (ret != 0)
  44050. return WC_TEST_RET_ENC_EC(ret);
  44051. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44052. authSz);
  44053. if (ret != WC_NO_ERR_TRACE(BAD_STATE_E))
  44054. return WC_TEST_RET_ENC_EC(ret);
  44055. wc_FreeSakkeKey(key);
  44056. return 0;
  44057. }
  44058. static wc_test_ret_t sakke_kat_derive_test(SakkeKey* key, ecc_point* rsk)
  44059. {
  44060. WOLFSSL_SMALL_STACK_STATIC const byte pubData[] = {
  44061. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44062. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44063. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44064. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44065. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44066. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44067. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44068. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44069. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44070. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44071. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44072. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44073. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44074. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44075. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44076. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44077. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44078. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44079. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44080. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44081. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44082. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44083. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44084. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44085. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44086. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44087. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44088. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44089. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44090. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44091. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44092. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44093. };
  44094. WOLFSSL_SMALL_STACK_STATIC const byte rskData[] = {
  44095. 0x93, 0xAF, 0x67, 0xE5, 0x00, 0x7B, 0xA6, 0xE6,
  44096. 0xA8, 0x0D, 0xA7, 0x93, 0xDA, 0x30, 0x0F, 0xA4,
  44097. 0xB5, 0x2D, 0x0A, 0x74, 0xE2, 0x5E, 0x6E, 0x7B,
  44098. 0x2B, 0x3D, 0x6E, 0xE9, 0xD1, 0x8A, 0x9B, 0x5C,
  44099. 0x50, 0x23, 0x59, 0x7B, 0xD8, 0x2D, 0x80, 0x62,
  44100. 0xD3, 0x40, 0x19, 0x56, 0x3B, 0xA1, 0xD2, 0x5C,
  44101. 0x0D, 0xC5, 0x6B, 0x7B, 0x97, 0x9D, 0x74, 0xAA,
  44102. 0x50, 0xF2, 0x9F, 0xBF, 0x11, 0xCC, 0x2C, 0x93,
  44103. 0xF5, 0xDF, 0xCA, 0x61, 0x5E, 0x60, 0x92, 0x79,
  44104. 0xF6, 0x17, 0x5C, 0xEA, 0xDB, 0x00, 0xB5, 0x8C,
  44105. 0x6B, 0xEE, 0x1E, 0x7A, 0x2A, 0x47, 0xC4, 0xF0,
  44106. 0xC4, 0x56, 0xF0, 0x52, 0x59, 0xA6, 0xFA, 0x94,
  44107. 0xA6, 0x34, 0xA4, 0x0D, 0xAE, 0x1D, 0xF5, 0x93,
  44108. 0xD4, 0xFE, 0xCF, 0x68, 0x8D, 0x5F, 0xC6, 0x78,
  44109. 0xBE, 0x7E, 0xFC, 0x6D, 0xF3, 0xD6, 0x83, 0x53,
  44110. 0x25, 0xB8, 0x3B, 0x2C, 0x6E, 0x69, 0x03, 0x6B,
  44111. 0x15, 0x5F, 0x0A, 0x27, 0x24, 0x10, 0x94, 0xB0,
  44112. 0x4B, 0xFB, 0x0B, 0xDF, 0xAC, 0x6C, 0x67, 0x0A,
  44113. 0x65, 0xC3, 0x25, 0xD3, 0x9A, 0x06, 0x9F, 0x03,
  44114. 0x65, 0x9D, 0x44, 0xCA, 0x27, 0xD3, 0xBE, 0x8D,
  44115. 0xF3, 0x11, 0x17, 0x2B, 0x55, 0x41, 0x60, 0x18,
  44116. 0x1C, 0xBE, 0x94, 0xA2, 0xA7, 0x83, 0x32, 0x0C,
  44117. 0xED, 0x59, 0x0B, 0xC4, 0x26, 0x44, 0x70, 0x2C,
  44118. 0xF3, 0x71, 0x27, 0x1E, 0x49, 0x6B, 0xF2, 0x0F,
  44119. 0x58, 0x8B, 0x78, 0xA1, 0xBC, 0x01, 0xEC, 0xBB,
  44120. 0x65, 0x59, 0x93, 0x4B, 0xDD, 0x2F, 0xB6, 0x5D,
  44121. 0x28, 0x84, 0x31, 0x8A, 0x33, 0xD1, 0xA4, 0x2A,
  44122. 0xDF, 0x5E, 0x33, 0xCC, 0x58, 0x00, 0x28, 0x0B,
  44123. 0x28, 0x35, 0x64, 0x97, 0xF8, 0x71, 0x35, 0xBA,
  44124. 0xB9, 0x61, 0x2A, 0x17, 0x26, 0x04, 0x24, 0x40,
  44125. 0x9A, 0xC1, 0x5F, 0xEE, 0x99, 0x6B, 0x74, 0x4C,
  44126. 0x33, 0x21, 0x51, 0x23, 0x5D, 0xEC, 0xB0, 0xF5
  44127. };
  44128. WOLFSSL_SMALL_STACK_STATIC const byte id[] = {
  44129. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44130. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44131. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44132. 0x33, 0x00
  44133. };
  44134. WOLFSSL_SMALL_STACK_STATIC const byte ssv[] = {
  44135. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44136. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44137. };
  44138. WOLFSSL_SMALL_STACK_STATIC const byte auth[] = {
  44139. 0x04,
  44140. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44141. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44142. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44143. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44144. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44145. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44146. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44147. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44148. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44149. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44150. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44151. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44152. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44153. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44154. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44155. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44156. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44157. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44158. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44159. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44160. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44161. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44162. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44163. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44164. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44165. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44166. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44167. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44168. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44169. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44170. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44171. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44172. };
  44173. WOLFSSL_SMALL_STACK_STATIC const byte encSsv[] = {
  44174. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44175. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44176. };
  44177. wc_test_ret_t ret;
  44178. int valid;
  44179. byte pubKey[sizeof(pubData) + 1];
  44180. word32 sz = sizeof(pubKey);
  44181. byte tmpSsv[sizeof(encSsv)];
  44182. byte* iTable = NULL;
  44183. word32 iTableLen;
  44184. byte* table = NULL;
  44185. word32 len;
  44186. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44187. if (ret != 0)
  44188. return WC_TEST_RET_ENC_EC(ret);
  44189. ret = wc_DecodeSakkeRsk(key, rskData, sizeof(rskData), rsk);
  44190. if (ret != 0)
  44191. return WC_TEST_RET_ENC_EC(ret);
  44192. ret = wc_ValidateSakkeRsk(key, id, sizeof(id), rsk, &valid);
  44193. if (ret != 0)
  44194. return WC_TEST_RET_ENC_EC(ret);
  44195. if (valid != 1)
  44196. return WC_TEST_RET_ENC_NC;
  44197. ret = wc_SetSakkeRsk(key, rsk, NULL, 0);
  44198. if (ret != 0)
  44199. return WC_TEST_RET_ENC_EC(ret);
  44200. ret = wc_SetSakkeIdentity(key, id, sizeof(id));
  44201. if (ret != 0)
  44202. return WC_TEST_RET_ENC_EC(ret);
  44203. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44204. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44205. auth, sizeof(auth));
  44206. if (ret != 0)
  44207. return WC_TEST_RET_ENC_EC(ret);
  44208. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44209. return WC_TEST_RET_ENC_NC;
  44210. ret = wc_MakeSakkePointI(key, id, sizeof(id));
  44211. if (ret != 0)
  44212. return WC_TEST_RET_ENC_EC(ret);
  44213. iTableLen = 0;
  44214. ret = wc_GenerateSakkePointITable(key, NULL, &iTableLen);
  44215. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44216. return WC_TEST_RET_ENC_EC(ret);
  44217. if (iTableLen != 0) {
  44218. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44219. if (iTable == NULL)
  44220. return WC_TEST_RET_ENC_ERRNO;
  44221. ret = wc_GenerateSakkePointITable(key, iTable, &iTableLen);
  44222. if (ret != 0)
  44223. return WC_TEST_RET_ENC_EC(ret);
  44224. }
  44225. len = 0;
  44226. ret = wc_GenerateSakkeRskTable(key, rsk, NULL, &len);
  44227. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44228. return WC_TEST_RET_ENC_EC(ret);
  44229. if (len > 0) {
  44230. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44231. if (table == NULL)
  44232. return WC_TEST_RET_ENC_ERRNO;
  44233. ret = wc_GenerateSakkeRskTable(key, rsk, table, &len);
  44234. if (ret != 0)
  44235. return WC_TEST_RET_ENC_EC(ret);
  44236. }
  44237. ret = wc_SetSakkeRsk(key, rsk, table, len);
  44238. if (ret != 0)
  44239. return WC_TEST_RET_ENC_EC(ret);
  44240. XMEMCPY(tmpSsv, encSsv, sizeof(encSsv));
  44241. ret = wc_DeriveSakkeSSV(key, WC_HASH_TYPE_SHA256, tmpSsv, sizeof(tmpSsv),
  44242. auth, sizeof(auth));
  44243. if (ret != 0)
  44244. return WC_TEST_RET_ENC_EC(ret);
  44245. if (XMEMCMP(tmpSsv, ssv, sizeof(ssv)) != 0)
  44246. return WC_TEST_RET_ENC_NC;
  44247. /* Don't reference table that is about to be freed. */
  44248. ret = wc_ClearSakkePointITable(key);
  44249. if (ret != 0)
  44250. return WC_TEST_RET_ENC_EC(ret);
  44251. /* Dispose of tables */
  44252. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44253. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44254. /* Make sure the key public key is exportable - convert to Montgomery form
  44255. * in Validation.
  44256. */
  44257. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 1);
  44258. if (ret != 0)
  44259. return WC_TEST_RET_ENC_EC(ret);
  44260. if (sz != sizeof(pubData))
  44261. return WC_TEST_RET_ENC_NC;
  44262. if (XMEMCMP(pubKey, pubData, sizeof(pubData)) != 0)
  44263. return WC_TEST_RET_ENC_NC;
  44264. sz = sizeof(pubData) + 1;
  44265. ret = wc_ExportSakkePublicKey(key, pubKey, &sz, 0);
  44266. if (ret != 0)
  44267. return WC_TEST_RET_ENC_EC(ret);
  44268. if (sz != sizeof(pubData) + 1)
  44269. return WC_TEST_RET_ENC_NC;
  44270. if (pubKey[0] != 0x04)
  44271. return WC_TEST_RET_ENC_NC;
  44272. if (XMEMCMP(pubKey + 1, pubData, sizeof(pubData)) != 0)
  44273. return WC_TEST_RET_ENC_NC;
  44274. return 0;
  44275. }
  44276. static wc_test_ret_t sakke_kat_encapsulate_test(SakkeKey* key)
  44277. {
  44278. static const byte pubData[] = {
  44279. 0x59, 0x58, 0xEF, 0x1B, 0x16, 0x79, 0xBF, 0x09,
  44280. 0x9B, 0x3A, 0x03, 0x0D, 0xF2, 0x55, 0xAA, 0x6A,
  44281. 0x23, 0xC1, 0xD8, 0xF1, 0x43, 0xD4, 0xD2, 0x3F,
  44282. 0x75, 0x3E, 0x69, 0xBD, 0x27, 0xA8, 0x32, 0xF3,
  44283. 0x8C, 0xB4, 0xAD, 0x53, 0xDD, 0xEF, 0x42, 0x60,
  44284. 0xB0, 0xFE, 0x8B, 0xB4, 0x5C, 0x4C, 0x1F, 0xF5,
  44285. 0x10, 0xEF, 0xFE, 0x30, 0x03, 0x67, 0xA3, 0x7B,
  44286. 0x61, 0xF7, 0x01, 0xD9, 0x14, 0xAE, 0xF0, 0x97,
  44287. 0x24, 0x82, 0x5F, 0xA0, 0x70, 0x7D, 0x61, 0xA6,
  44288. 0xDF, 0xF4, 0xFB, 0xD7, 0x27, 0x35, 0x66, 0xCD,
  44289. 0xDE, 0x35, 0x2A, 0x0B, 0x04, 0xB7, 0xC1, 0x6A,
  44290. 0x78, 0x30, 0x9B, 0xE6, 0x40, 0x69, 0x7D, 0xE7,
  44291. 0x47, 0x61, 0x3A, 0x5F, 0xC1, 0x95, 0xE8, 0xB9,
  44292. 0xF3, 0x28, 0x85, 0x2A, 0x57, 0x9D, 0xB8, 0xF9,
  44293. 0x9B, 0x1D, 0x00, 0x34, 0x47, 0x9E, 0xA9, 0xC5,
  44294. 0x59, 0x5F, 0x47, 0xC4, 0xB2, 0xF5, 0x4F, 0xF2,
  44295. 0x15, 0x08, 0xD3, 0x75, 0x14, 0xDC, 0xF7, 0xA8,
  44296. 0xE1, 0x43, 0xA6, 0x05, 0x8C, 0x09, 0xA6, 0xBF,
  44297. 0x2C, 0x98, 0x58, 0xCA, 0x37, 0xC2, 0x58, 0x06,
  44298. 0x5A, 0xE6, 0xBF, 0x75, 0x32, 0xBC, 0x8B, 0x5B,
  44299. 0x63, 0x38, 0x38, 0x66, 0xE0, 0x75, 0x3C, 0x5A,
  44300. 0xC0, 0xE7, 0x27, 0x09, 0xF8, 0x44, 0x5F, 0x2E,
  44301. 0x61, 0x78, 0xE0, 0x65, 0x85, 0x7E, 0x0E, 0xDA,
  44302. 0x10, 0xF6, 0x82, 0x06, 0xB6, 0x35, 0x05, 0xED,
  44303. 0x87, 0xE5, 0x34, 0xFB, 0x28, 0x31, 0xFF, 0x95,
  44304. 0x7F, 0xB7, 0xDC, 0x61, 0x9D, 0xAE, 0x61, 0x30,
  44305. 0x1E, 0xEA, 0xCC, 0x2F, 0xDA, 0x36, 0x80, 0xEA,
  44306. 0x49, 0x99, 0x25, 0x8A, 0x83, 0x3C, 0xEA, 0x8F,
  44307. 0xC6, 0x7C, 0x6D, 0x19, 0x48, 0x7F, 0xB4, 0x49,
  44308. 0x05, 0x9F, 0x26, 0xCC, 0x8A, 0xAB, 0x65, 0x5A,
  44309. 0xB5, 0x8B, 0x7C, 0xC7, 0x96, 0xE2, 0x4E, 0x9A,
  44310. 0x39, 0x40, 0x95, 0x75, 0x4F, 0x5F, 0x8B, 0xAE
  44311. };
  44312. static const byte id[] = {
  44313. 0x32, 0x30, 0x31, 0x31, 0x2D, 0x30, 0x32, 0x00,
  44314. 0x74, 0x65, 0x6C, 0x3A, 0x2B, 0x34, 0x34, 0x37,
  44315. 0x37, 0x30, 0x30, 0x39, 0x30, 0x30, 0x31, 0x32,
  44316. 0x33, 0x00
  44317. };
  44318. static const word32 idSz = sizeof(id);
  44319. byte ssv[] = {
  44320. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
  44321. 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0
  44322. };
  44323. static const word16 ssvSz = sizeof(ssv);
  44324. static const byte expAuth[] = {
  44325. 0x04,
  44326. 0x44, 0xE8, 0xAD, 0x44, 0xAB, 0x85, 0x92, 0xA6,
  44327. 0xA5, 0xA3, 0xDD, 0xCA, 0x5C, 0xF8, 0x96, 0xC7,
  44328. 0x18, 0x04, 0x36, 0x06, 0xA0, 0x1D, 0x65, 0x0D,
  44329. 0xEF, 0x37, 0xA0, 0x1F, 0x37, 0xC2, 0x28, 0xC3,
  44330. 0x32, 0xFC, 0x31, 0x73, 0x54, 0xE2, 0xC2, 0x74,
  44331. 0xD4, 0xDA, 0xF8, 0xAD, 0x00, 0x10, 0x54, 0xC7,
  44332. 0x6C, 0xE5, 0x79, 0x71, 0xC6, 0xF4, 0x48, 0x6D,
  44333. 0x57, 0x23, 0x04, 0x32, 0x61, 0xC5, 0x06, 0xEB,
  44334. 0xF5, 0xBE, 0x43, 0x8F, 0x53, 0xDE, 0x04, 0xF0,
  44335. 0x67, 0xC7, 0x76, 0xE0, 0xDD, 0x3B, 0x71, 0xA6,
  44336. 0x29, 0x01, 0x33, 0x28, 0x37, 0x25, 0xA5, 0x32,
  44337. 0xF2, 0x1A, 0xF1, 0x45, 0x12, 0x6D, 0xC1, 0xD7,
  44338. 0x77, 0xEC, 0xC2, 0x7B, 0xE5, 0x08, 0x35, 0xBD,
  44339. 0x28, 0x09, 0x8B, 0x8A, 0x73, 0xD9, 0xF8, 0x01,
  44340. 0xD8, 0x93, 0x79, 0x3A, 0x41, 0xFF, 0x5C, 0x49,
  44341. 0xB8, 0x7E, 0x79, 0xF2, 0xBE, 0x4D, 0x56, 0xCE,
  44342. 0x55, 0x7E, 0x13, 0x4A, 0xD8, 0x5B, 0xB1, 0xD4,
  44343. 0xB9, 0xCE, 0x4F, 0x8B, 0xE4, 0xB0, 0x8A, 0x12,
  44344. 0xBA, 0xBF, 0x55, 0xB1, 0xD6, 0xF1, 0xD7, 0xA6,
  44345. 0x38, 0x01, 0x9E, 0xA2, 0x8E, 0x15, 0xAB, 0x1C,
  44346. 0x9F, 0x76, 0x37, 0x5F, 0xDD, 0x12, 0x10, 0xD4,
  44347. 0xF4, 0x35, 0x1B, 0x9A, 0x00, 0x94, 0x86, 0xB7,
  44348. 0xF3, 0xED, 0x46, 0xC9, 0x65, 0xDE, 0xD2, 0xD8,
  44349. 0x0D, 0xAD, 0xE4, 0xF3, 0x8C, 0x67, 0x21, 0xD5,
  44350. 0x2C, 0x3A, 0xD1, 0x03, 0xA1, 0x0E, 0xBD, 0x29,
  44351. 0x59, 0x24, 0x8B, 0x4E, 0xF0, 0x06, 0x83, 0x6B,
  44352. 0xF0, 0x97, 0x44, 0x8E, 0x61, 0x07, 0xC9, 0xED,
  44353. 0xEE, 0x9F, 0xB7, 0x04, 0x82, 0x3D, 0xF1, 0x99,
  44354. 0xF8, 0x32, 0xC9, 0x05, 0xAE, 0x45, 0xF8, 0xA2,
  44355. 0x47, 0xA0, 0x72, 0xD8, 0xEF, 0x72, 0x9E, 0xAB,
  44356. 0xC5, 0xE2, 0x75, 0x74, 0xB0, 0x77, 0x39, 0xB3,
  44357. 0x4B, 0xE7, 0x4A, 0x53, 0x2F, 0x74, 0x7B, 0x86
  44358. };
  44359. static const byte encSsv[] = {
  44360. 0x89, 0xE0, 0xBC, 0x66, 0x1A, 0xA1, 0xE9, 0x16,
  44361. 0x38, 0xE6, 0xAC, 0xC8, 0x4E, 0x49, 0x65, 0x07
  44362. };
  44363. wc_test_ret_t ret;
  44364. byte auth[257];
  44365. word16 authSz = sizeof(auth);
  44366. ret = wc_ImportSakkePublicKey(key, pubData, sizeof(pubData), 0);
  44367. if (ret != 0)
  44368. return WC_TEST_RET_ENC_EC(ret);
  44369. ret = wc_SetSakkeIdentity(key, id, idSz);
  44370. if (ret != 0)
  44371. return WC_TEST_RET_ENC_EC(ret);
  44372. ret = wc_MakeSakkeEncapsulatedSSV(key, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44373. auth, &authSz);
  44374. if (ret != 0)
  44375. return WC_TEST_RET_ENC_EC(ret);
  44376. if (authSz != 257)
  44377. return WC_TEST_RET_ENC_NC;
  44378. if (XMEMCMP(ssv, encSsv, ssvSz) != 0)
  44379. return WC_TEST_RET_ENC_NC;
  44380. if (XMEMCMP(auth, expAuth, authSz) != 0)
  44381. return WC_TEST_RET_ENC_NC;
  44382. return 0;
  44383. }
  44384. static wc_test_ret_t sakke_make_key_test(SakkeKey* priv, SakkeKey* pub, SakkeKey* key,
  44385. WC_RNG* rng, ecc_point* rsk)
  44386. {
  44387. wc_test_ret_t ret;
  44388. byte data[440];
  44389. byte pubData[257];
  44390. word32 sz;
  44391. char mail[] = "test@wolfssl.com";
  44392. byte* id = (byte*)mail;
  44393. word32 idSz = (word32)XSTRLEN(mail);
  44394. int valid;
  44395. ecc_point* pubKey = rsk;
  44396. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44397. if (ret != 0)
  44398. return WC_TEST_RET_ENC_EC(ret);
  44399. ret = wc_MakeSakkeKey(priv, rng);
  44400. if (ret != 0)
  44401. return WC_TEST_RET_ENC_EC(ret);
  44402. ret = wc_ExportSakkeKey(priv, NULL, &sz);
  44403. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44404. return WC_TEST_RET_ENC_EC(ret);
  44405. if (sz != 384)
  44406. return WC_TEST_RET_ENC_NC;
  44407. sz--;
  44408. ret = wc_ExportSakkeKey(priv, data, &sz);
  44409. if (ret == 0)
  44410. return WC_TEST_RET_ENC_NC;
  44411. sz++;
  44412. ret = wc_ExportSakkeKey(priv, data, &sz);
  44413. if (ret != 0)
  44414. return WC_TEST_RET_ENC_EC(ret);
  44415. if (sz != 384)
  44416. return WC_TEST_RET_ENC_NC;
  44417. ret = wc_ImportSakkeKey(key, data, sz - 1);
  44418. if (ret == 0)
  44419. return WC_TEST_RET_ENC_NC;
  44420. ret = wc_ImportSakkeKey(key, data, sz);
  44421. if (ret != 0)
  44422. return WC_TEST_RET_ENC_EC(ret);
  44423. wc_FreeSakkeKey(key);
  44424. ret = wc_InitSakkeKey_ex(key, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  44425. if (ret != 0)
  44426. return WC_TEST_RET_ENC_EC(ret);
  44427. ret = wc_ExportSakkePrivateKey(priv, NULL, &sz);
  44428. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44429. return WC_TEST_RET_ENC_EC(ret);
  44430. if (sz != 128)
  44431. return WC_TEST_RET_ENC_NC;
  44432. sz--;
  44433. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44434. if (ret == 0)
  44435. return WC_TEST_RET_ENC_NC;
  44436. sz++;
  44437. ret = wc_ExportSakkePrivateKey(priv, data, &sz);
  44438. if (ret != 0)
  44439. return WC_TEST_RET_ENC_EC(ret);
  44440. if (sz != 128)
  44441. return WC_TEST_RET_ENC_NC;
  44442. ret = wc_ImportSakkePrivateKey(key, data, sz - 1);
  44443. if (ret == 0)
  44444. return WC_TEST_RET_ENC_NC;
  44445. ret = wc_ImportSakkePrivateKey(key, data, sz);
  44446. if (ret != 0)
  44447. return WC_TEST_RET_ENC_EC(ret);
  44448. ret = wc_MakeSakkePublicKey(key, pubKey);
  44449. if (ret != 0)
  44450. return WC_TEST_RET_ENC_EC(ret);
  44451. ret = wc_ExportSakkePublicKey(priv, NULL, &sz, 1);
  44452. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44453. return WC_TEST_RET_ENC_EC(ret);
  44454. if (sz != 256)
  44455. return WC_TEST_RET_ENC_NC;
  44456. sz--;
  44457. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44458. if (ret == 0)
  44459. return WC_TEST_RET_ENC_NC;
  44460. sz++;
  44461. ret = wc_ExportSakkePublicKey(priv, data, &sz, 1);
  44462. if (ret != 0)
  44463. return WC_TEST_RET_ENC_EC(ret);
  44464. if (sz != 256)
  44465. return WC_TEST_RET_ENC_NC;
  44466. ret = wc_ImportSakkePublicKey(pub, data, sz - 1, 1);
  44467. if (ret == 0)
  44468. return WC_TEST_RET_ENC_NC;
  44469. ret = wc_ImportSakkePublicKey(pub, data, sz, 1);
  44470. if (ret != 0)
  44471. return WC_TEST_RET_ENC_EC(ret);
  44472. ret = wc_ExportSakkePublicKey(pub, pubData, &sz, 1);
  44473. if (ret != 0)
  44474. return WC_TEST_RET_ENC_EC(ret);
  44475. if (sz != 256)
  44476. return WC_TEST_RET_ENC_NC;
  44477. if (XMEMCMP(data, pubData, sz) != 0)
  44478. return WC_TEST_RET_ENC_NC;
  44479. ret = wc_MakeSakkeRsk(priv, id, idSz, rsk);
  44480. if (ret != 0)
  44481. return WC_TEST_RET_ENC_EC(ret);
  44482. ret = wc_ValidateSakkeRsk(priv, id, idSz, rsk, &valid);
  44483. if (ret != 0)
  44484. return WC_TEST_RET_ENC_EC(ret);
  44485. if (valid != 1)
  44486. return WC_TEST_RET_ENC_NC;
  44487. ret = wc_ValidateSakkeRsk(pub, id, idSz, rsk, &valid);
  44488. if (ret != 0)
  44489. return WC_TEST_RET_ENC_EC(ret);
  44490. if (valid != 1)
  44491. return WC_TEST_RET_ENC_NC;
  44492. sz = sizeof(data);
  44493. ret = wc_EncodeSakkeRsk(priv, rsk, data, &sz, 1);
  44494. if (ret != 0)
  44495. return WC_TEST_RET_ENC_EC(ret);
  44496. if (sz != 256)
  44497. return WC_TEST_RET_ENC_NC;
  44498. ret = wc_DecodeSakkeRsk(priv, data, sz, rsk);
  44499. if (ret != 0)
  44500. return WC_TEST_RET_ENC_EC(ret);
  44501. sz = sizeof(pubData);
  44502. ret = wc_EncodeSakkeRsk(priv, rsk, pubData, &sz, 0);
  44503. if (ret != 0)
  44504. return WC_TEST_RET_ENC_EC(ret);
  44505. if (sz != sizeof(pubData))
  44506. return WC_TEST_RET_ENC_NC;
  44507. ret = wc_DecodeSakkeRsk(priv, pubData, sz, rsk);
  44508. if (ret != 0)
  44509. return WC_TEST_RET_ENC_EC(ret);
  44510. wc_FreeSakkeKey(key);
  44511. return 0;
  44512. }
  44513. static wc_test_ret_t sakke_op_test(SakkeKey* priv, SakkeKey* pub, WC_RNG* rng,
  44514. ecc_point* rsk)
  44515. {
  44516. wc_test_ret_t ret;
  44517. byte ssv[16];
  44518. word16 ssvSz;
  44519. byte auth[257];
  44520. word16 authSz;
  44521. char mail[] = "test@wolfssl.com";
  44522. byte* id = (byte*)mail;
  44523. word32 idSz = (word32)XSTRLEN(mail);
  44524. byte pointI[256];
  44525. word32 sz;
  44526. ret = wc_GenerateSakkeSSV(pub, rng, NULL, &ssvSz);
  44527. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44528. return WC_TEST_RET_ENC_EC(ret);
  44529. if (ssvSz != 16)
  44530. return WC_TEST_RET_ENC_NC;
  44531. ssvSz += 128;
  44532. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44533. if (ret == 0)
  44534. return WC_TEST_RET_ENC_NC;
  44535. ssvSz -= 128;
  44536. ret = wc_GenerateSakkeSSV(pub, rng, ssv, &ssvSz);
  44537. if (ret != 0)
  44538. return WC_TEST_RET_ENC_EC(ret);
  44539. if (ssvSz != 16)
  44540. return WC_TEST_RET_ENC_NC;
  44541. ret = wc_GetSakkeAuthSize(pub, &authSz);
  44542. if (ret != 0)
  44543. return WC_TEST_RET_ENC_EC(ret);
  44544. ret = wc_SetSakkeIdentity(pub, id, idSz);
  44545. if (ret != 0)
  44546. return WC_TEST_RET_ENC_EC(ret);
  44547. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44548. NULL, &authSz);
  44549. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44550. return WC_TEST_RET_ENC_EC(ret);
  44551. if (authSz != 257)
  44552. return WC_TEST_RET_ENC_NC;
  44553. authSz--;
  44554. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44555. auth, &authSz);
  44556. if (ret == 0)
  44557. return WC_TEST_RET_ENC_NC;
  44558. authSz++;
  44559. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44560. auth, &authSz);
  44561. if (ret != 0)
  44562. return WC_TEST_RET_ENC_EC(ret);
  44563. if (authSz != 257)
  44564. return WC_TEST_RET_ENC_NC;
  44565. ret = wc_GetSakkePointI(pub, NULL, &sz);
  44566. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  44567. return WC_TEST_RET_ENC_EC(ret);
  44568. if (sz != 256)
  44569. return WC_TEST_RET_ENC_NC;
  44570. ret = wc_GetSakkePointI(pub, pointI, &sz);
  44571. if (ret != 0)
  44572. return WC_TEST_RET_ENC_EC(ret);
  44573. if (sz != 256)
  44574. return WC_TEST_RET_ENC_NC;
  44575. /* Bogus identity - make it check and regenerate I. */
  44576. ret = wc_MakeSakkePointI(pub, ssv, ssvSz);
  44577. if (ret != 0)
  44578. return WC_TEST_RET_ENC_EC(ret);
  44579. ret = wc_MakeSakkeEncapsulatedSSV(pub, WC_HASH_TYPE_SHA256, ssv, ssvSz,
  44580. auth, &authSz);
  44581. if (ret != 0)
  44582. return WC_TEST_RET_ENC_EC(ret);
  44583. if (authSz != 257)
  44584. return WC_TEST_RET_ENC_NC;
  44585. ret = wc_SetSakkeRsk(priv, rsk, NULL, 0);
  44586. if (ret != 0)
  44587. return WC_TEST_RET_ENC_EC(ret);
  44588. ret = wc_SetSakkeIdentity(priv, id, idSz);
  44589. if (ret != 0)
  44590. return WC_TEST_RET_ENC_EC(ret);
  44591. authSz--;
  44592. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44593. authSz);
  44594. if (ret == 0)
  44595. return WC_TEST_RET_ENC_NC;
  44596. authSz++;
  44597. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44598. authSz);
  44599. if (ret != 0)
  44600. return WC_TEST_RET_ENC_EC(ret);
  44601. ssv[0] ^= 0x80;
  44602. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44603. authSz);
  44604. if (ret != WC_NO_ERR_TRACE(SAKKE_VERIFY_FAIL_E))
  44605. return WC_TEST_RET_ENC_EC(ret);
  44606. ssv[0] ^= 0x80;
  44607. /* Bogus identity - make it check and regenerate I. */
  44608. ret = wc_MakeSakkePointI(pub, ssv, idSz);
  44609. if (ret != 0)
  44610. return WC_TEST_RET_ENC_EC(ret);
  44611. ret = wc_DeriveSakkeSSV(priv, WC_HASH_TYPE_SHA256, ssv, ssvSz, auth,
  44612. authSz);
  44613. if (ret != 0)
  44614. return WC_TEST_RET_ENC_EC(ret);
  44615. return 0;
  44616. }
  44617. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sakke_test(void)
  44618. {
  44619. wc_test_ret_t ret = 0;
  44620. WC_RNG rng;
  44621. int rng_inited = 0;
  44622. SakkeKey* priv = NULL;
  44623. SakkeKey* pub = NULL;
  44624. SakkeKey* key = NULL;
  44625. ecc_point* rsk = NULL;
  44626. WOLFSSL_ENTER("sakke_test");
  44627. priv = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44628. DYNAMIC_TYPE_TMP_BUFFER);
  44629. if (priv == NULL)
  44630. ret = WC_TEST_RET_ENC_NC;
  44631. else
  44632. XMEMSET(priv, 0, sizeof(*priv));
  44633. if (ret == 0) {
  44634. pub = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44635. DYNAMIC_TYPE_TMP_BUFFER);
  44636. if (pub == NULL)
  44637. ret = WC_TEST_RET_ENC_NC;
  44638. else
  44639. XMEMSET(pub, 0, sizeof(*pub));
  44640. }
  44641. if (ret == 0) {
  44642. key = (SakkeKey*)XMALLOC(sizeof(SakkeKey), HEAP_HINT,
  44643. DYNAMIC_TYPE_TMP_BUFFER);
  44644. if (key == NULL)
  44645. ret = WC_TEST_RET_ENC_NC;
  44646. else
  44647. XMEMSET(key, 0, sizeof(*key));
  44648. }
  44649. if (ret == 0) {
  44650. #ifndef HAVE_FIPS
  44651. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  44652. #else
  44653. ret = wc_InitRng(&rng);
  44654. #endif
  44655. if (ret == 0)
  44656. rng_inited = 1;
  44657. else
  44658. ret = WC_TEST_RET_ENC_EC(ret);
  44659. }
  44660. if (ret == 0) {
  44661. rsk = wc_ecc_new_point();
  44662. if (rsk == NULL)
  44663. ret = WC_TEST_RET_ENC_NC;
  44664. }
  44665. if (ret == 0) {
  44666. ret = wc_InitSakkeKey(pub, HEAP_HINT, INVALID_DEVID);
  44667. if (ret != 0)
  44668. ret = WC_TEST_RET_ENC_EC(ret);
  44669. }
  44670. if (ret == 0) {
  44671. ret = wc_InitSakkeKey(priv, HEAP_HINT, INVALID_DEVID);
  44672. if (ret != 0)
  44673. ret = WC_TEST_RET_ENC_EC(ret);
  44674. }
  44675. if (ret == 0) {
  44676. ret = sakke_api_test(&rng, key, rsk);
  44677. }
  44678. if (ret == 0) {
  44679. ret = sakke_kat_derive_test(pub, rsk);
  44680. }
  44681. if (ret == 0) {
  44682. ret = sakke_kat_encapsulate_test(pub);
  44683. }
  44684. if (ret == 0) {
  44685. ret = sakke_make_key_test(priv, pub, key, &rng, rsk);
  44686. }
  44687. if (ret == 0) {
  44688. ret = sakke_op_test(priv, pub, &rng, rsk);
  44689. }
  44690. if (rsk != NULL) {
  44691. wc_ecc_forcezero_point(rsk);
  44692. wc_ecc_del_point(rsk);
  44693. }
  44694. if (rng_inited)
  44695. wc_FreeRng(&rng);
  44696. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44697. if (pub != NULL) {
  44698. wc_FreeSakkeKey(pub);
  44699. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44700. }
  44701. if (priv != NULL) {
  44702. wc_FreeSakkeKey(priv);
  44703. XFREE(priv, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  44704. }
  44705. return ret;
  44706. }
  44707. #endif /* WOLFCRYPT_HAVE_SAKKE */
  44708. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  44709. typedef struct CMAC_Test_Case {
  44710. int type;
  44711. int partial;
  44712. const byte* m;
  44713. word32 mSz;
  44714. const byte* k;
  44715. word32 kSz;
  44716. const byte* t;
  44717. word32 tSz;
  44718. } CMAC_Test_Case;
  44719. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cmac_test(void)
  44720. {
  44721. #ifdef WOLFSSL_AES_128
  44722. WOLFSSL_SMALL_STACK_STATIC const byte k128[] =
  44723. {
  44724. 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
  44725. 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
  44726. };
  44727. #define KLEN_128 (sizeof(k128))
  44728. #endif
  44729. #ifdef WOLFSSL_AES_192
  44730. WOLFSSL_SMALL_STACK_STATIC const byte k192[] =
  44731. {
  44732. 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
  44733. 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
  44734. 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
  44735. };
  44736. #define KLEN_192 (sizeof(k192))
  44737. #endif
  44738. #ifdef WOLFSSL_AES_256
  44739. WOLFSSL_SMALL_STACK_STATIC const byte k256[] =
  44740. {
  44741. 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
  44742. 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
  44743. 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
  44744. 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
  44745. };
  44746. #define KLEN_256 (sizeof(k256))
  44747. #endif
  44748. WOLFSSL_SMALL_STACK_STATIC const byte m[] =
  44749. {
  44750. 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
  44751. 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
  44752. 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
  44753. 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
  44754. 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
  44755. 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
  44756. 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
  44757. 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
  44758. };
  44759. #define MLEN_0 (0)
  44760. #define MLEN_128 (128/8)
  44761. #define MLEN_320 (320/8)
  44762. #define MLEN_319 (MLEN_320 - 1)
  44763. #define MLEN_512 (512/8)
  44764. #ifdef WOLFSSL_AES_128
  44765. WOLFSSL_SMALL_STACK_STATIC const byte t128_0[] =
  44766. {
  44767. 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
  44768. 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
  44769. };
  44770. WOLFSSL_SMALL_STACK_STATIC const byte t128_128[] =
  44771. {
  44772. 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
  44773. 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
  44774. };
  44775. WOLFSSL_SMALL_STACK_STATIC const byte t128_319[] =
  44776. {
  44777. 0x2c, 0x17, 0x84, 0x4c, 0x93, 0x1c, 0x07, 0x95,
  44778. 0x15, 0x92, 0x73, 0x0a, 0x34, 0xd0, 0xd9, 0xd2
  44779. };
  44780. WOLFSSL_SMALL_STACK_STATIC const byte t128_320[] =
  44781. {
  44782. 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
  44783. 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
  44784. };
  44785. WOLFSSL_SMALL_STACK_STATIC const byte t128_512[] =
  44786. {
  44787. 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
  44788. 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
  44789. };
  44790. #endif
  44791. #ifdef WOLFSSL_AES_192
  44792. WOLFSSL_SMALL_STACK_STATIC const byte t192_0[] =
  44793. {
  44794. 0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
  44795. 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
  44796. };
  44797. WOLFSSL_SMALL_STACK_STATIC const byte t192_128[] =
  44798. {
  44799. 0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
  44800. 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
  44801. };
  44802. WOLFSSL_SMALL_STACK_STATIC const byte t192_320[] =
  44803. {
  44804. 0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
  44805. 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
  44806. };
  44807. WOLFSSL_SMALL_STACK_STATIC const byte t192_512[] =
  44808. {
  44809. 0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
  44810. 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
  44811. };
  44812. #endif
  44813. #ifdef WOLFSSL_AES_256
  44814. WOLFSSL_SMALL_STACK_STATIC const byte t256_0[] =
  44815. {
  44816. 0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
  44817. 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
  44818. };
  44819. WOLFSSL_SMALL_STACK_STATIC const byte t256_128[] =
  44820. {
  44821. 0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
  44822. 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
  44823. };
  44824. WOLFSSL_SMALL_STACK_STATIC const byte t256_320[] =
  44825. {
  44826. 0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
  44827. 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
  44828. };
  44829. WOLFSSL_SMALL_STACK_STATIC const byte t256_512[] =
  44830. {
  44831. 0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
  44832. 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
  44833. };
  44834. #endif
  44835. const CMAC_Test_Case testCases[] =
  44836. {
  44837. #ifdef WOLFSSL_AES_128
  44838. {WC_CMAC_AES, 0, m, MLEN_0, k128, KLEN_128, t128_0, AES_BLOCK_SIZE},
  44839. {WC_CMAC_AES, 0, m, MLEN_128, k128, KLEN_128, t128_128, AES_BLOCK_SIZE},
  44840. {WC_CMAC_AES, 0, m, MLEN_320, k128, KLEN_128, t128_320, AES_BLOCK_SIZE},
  44841. {WC_CMAC_AES, 0, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44842. {WC_CMAC_AES, 5, m, MLEN_512, k128, KLEN_128, t128_512, AES_BLOCK_SIZE},
  44843. #endif
  44844. #ifdef WOLFSSL_AES_192
  44845. {WC_CMAC_AES, 0, m, MLEN_0, k192, KLEN_192, t192_0, AES_BLOCK_SIZE},
  44846. {WC_CMAC_AES, 0, m, MLEN_128, k192, KLEN_192, t192_128, AES_BLOCK_SIZE},
  44847. {WC_CMAC_AES, 0, m, MLEN_320, k192, KLEN_192, t192_320, AES_BLOCK_SIZE},
  44848. {WC_CMAC_AES, 0, m, MLEN_512, k192, KLEN_192, t192_512, AES_BLOCK_SIZE},
  44849. #endif
  44850. #ifdef WOLFSSL_AES_256
  44851. {WC_CMAC_AES, 0, m, MLEN_0, k256, KLEN_256, t256_0, AES_BLOCK_SIZE},
  44852. {WC_CMAC_AES, 0, m, MLEN_128, k256, KLEN_256, t256_128, AES_BLOCK_SIZE},
  44853. {WC_CMAC_AES, 0, m, MLEN_320, k256, KLEN_256, t256_320, AES_BLOCK_SIZE},
  44854. {WC_CMAC_AES, 0, m, MLEN_512, k256, KLEN_256, t256_512, AES_BLOCK_SIZE},
  44855. #endif
  44856. #ifdef WOLFSSL_AES_128
  44857. {WC_CMAC_AES, 0, m, MLEN_319, k128, KLEN_128, t128_319, AES_BLOCK_SIZE}
  44858. #endif
  44859. };
  44860. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44861. Cmac *cmac;
  44862. #else
  44863. Cmac cmac[1];
  44864. #endif
  44865. byte tag[AES_BLOCK_SIZE];
  44866. const CMAC_Test_Case* tc;
  44867. word32 i, tagSz;
  44868. wc_test_ret_t ret;
  44869. WOLFSSL_ENTER("cmac_test");
  44870. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44871. if ((cmac = (Cmac *)XMALLOC(sizeof *cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC)) == NULL)
  44872. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  44873. #endif
  44874. for (i = 0, tc = testCases;
  44875. i < sizeof(testCases)/sizeof(CMAC_Test_Case);
  44876. i++, tc++) {
  44877. XMEMSET(tag, 0, sizeof(tag));
  44878. tagSz = AES_BLOCK_SIZE;
  44879. #if !defined(HAVE_FIPS) || \
  44880. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 3)
  44881. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44882. #else
  44883. ret = wc_InitCmac(cmac, tc->k, tc->kSz, tc->type, NULL);
  44884. #endif
  44885. if (ret != 0)
  44886. {
  44887. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44888. }
  44889. if (tc->partial) {
  44890. ret = wc_CmacUpdate(cmac, tc->m,
  44891. tc->mSz/2 - tc->partial);
  44892. if (ret != 0)
  44893. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44894. ret = wc_CmacUpdate(cmac, tc->m + tc->mSz/2 - tc->partial,
  44895. tc->mSz/2 + tc->partial);
  44896. if (ret != 0)
  44897. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44898. }
  44899. else {
  44900. ret = wc_CmacUpdate(cmac, tc->m, tc->mSz);
  44901. if (ret != 0)
  44902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44903. }
  44904. ret = wc_CmacFinal(cmac, tag, &tagSz);
  44905. if (ret != 0)
  44906. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44907. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44908. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44909. XMEMSET(tag, 0, sizeof(tag));
  44910. tagSz = sizeof(tag);
  44911. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44912. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44913. tc->k, tc->kSz, NULL, devId);
  44914. #else
  44915. ret = wc_AesCmacGenerate(tag, &tagSz, tc->m, tc->mSz,
  44916. tc->k, tc->kSz);
  44917. #endif
  44918. if (ret != 0)
  44919. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44920. if (XMEMCMP(tag, tc->t, AES_BLOCK_SIZE) != 0)
  44921. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  44922. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44923. ret = wc_AesCmacVerify_ex(cmac, tc->t, tc->tSz, tc->m, tc->mSz,
  44924. tc->k, tc->kSz, HEAP_HINT, devId);
  44925. #else
  44926. ret = wc_AesCmacVerify(tc->t, tc->tSz, tc->m, tc->mSz,
  44927. tc->k, tc->kSz);
  44928. #endif
  44929. if (ret != 0)
  44930. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44931. #if !defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0)
  44932. /* Test that keyless generate with init is the same */
  44933. XMEMSET(tag, 0, sizeof(tag));
  44934. tagSz = sizeof(tag);
  44935. ret = wc_InitCmac_ex(cmac, tc->k, tc->kSz, tc->type, NULL, HEAP_HINT, devId);
  44936. if (ret != 0) {
  44937. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44938. }
  44939. ret = wc_AesCmacGenerate_ex(cmac, tag, &tagSz, tc->m, tc->mSz,
  44940. NULL, 0, HEAP_HINT, devId);
  44941. if (ret != 0) {
  44942. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  44943. }
  44944. #endif
  44945. }
  44946. ret = 0;
  44947. out:
  44948. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  44949. XFREE(cmac, HEAP_HINT, DYNAMIC_TYPE_CMAC);
  44950. #endif
  44951. return ret;
  44952. }
  44953. #endif /* !NO_AES && WOLFSSL_CMAC */
  44954. #if defined(WOLFSSL_SIPHASH)
  44955. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  44956. /* Test vectors from:
  44957. * https://github.com/veorq/SipHash/blob/master/vectors.h
  44958. */
  44959. static const unsigned char siphash_key[SIPHASH_KEY_SIZE] = {
  44960. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44961. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  44962. };
  44963. static const unsigned char siphash_msg[64] = {
  44964. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  44965. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  44966. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  44967. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  44968. 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
  44969. 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
  44970. 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
  44971. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  44972. };
  44973. static const unsigned char siphash_r8[64][SIPHASH_MAC_SIZE_8] = {
  44974. { 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, },
  44975. { 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, },
  44976. { 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, },
  44977. { 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, },
  44978. { 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, },
  44979. { 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, },
  44980. { 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, },
  44981. { 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, },
  44982. { 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, },
  44983. { 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, },
  44984. { 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, },
  44985. { 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, },
  44986. { 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, },
  44987. { 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, },
  44988. { 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, },
  44989. { 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, },
  44990. { 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, },
  44991. { 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, },
  44992. { 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, },
  44993. { 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, },
  44994. { 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, },
  44995. { 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, },
  44996. { 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, },
  44997. { 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, },
  44998. { 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, },
  44999. { 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, },
  45000. { 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, },
  45001. { 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, },
  45002. { 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, },
  45003. { 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, },
  45004. { 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, },
  45005. { 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, },
  45006. { 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, },
  45007. { 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, },
  45008. { 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, },
  45009. { 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, },
  45010. { 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, },
  45011. { 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, },
  45012. { 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, },
  45013. { 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, },
  45014. { 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, },
  45015. { 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, },
  45016. { 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, },
  45017. { 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, },
  45018. { 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, },
  45019. { 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, },
  45020. { 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, },
  45021. { 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, },
  45022. { 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, },
  45023. { 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, },
  45024. { 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, },
  45025. { 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, },
  45026. { 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, },
  45027. { 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, },
  45028. { 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, },
  45029. { 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, },
  45030. { 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, },
  45031. { 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, },
  45032. { 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, },
  45033. { 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, },
  45034. { 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, },
  45035. { 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, },
  45036. { 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, },
  45037. { 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, },
  45038. };
  45039. static const unsigned char siphash_r16[64][SIPHASH_MAC_SIZE_16] = {
  45040. { 0xa3, 0x81, 0x7f, 0x04, 0xba, 0x25, 0xa8, 0xe6,
  45041. 0x6d, 0xf6, 0x72, 0x14, 0xc7, 0x55, 0x02, 0x93, },
  45042. { 0xda, 0x87, 0xc1, 0xd8, 0x6b, 0x99, 0xaf, 0x44,
  45043. 0x34, 0x76, 0x59, 0x11, 0x9b, 0x22, 0xfc, 0x45, },
  45044. { 0x81, 0x77, 0x22, 0x8d, 0xa4, 0xa4, 0x5d, 0xc7,
  45045. 0xfc, 0xa3, 0x8b, 0xde, 0xf6, 0x0a, 0xff, 0xe4, },
  45046. { 0x9c, 0x70, 0xb6, 0x0c, 0x52, 0x67, 0xa9, 0x4e,
  45047. 0x5f, 0x33, 0xb6, 0xb0, 0x29, 0x85, 0xed, 0x51, },
  45048. { 0xf8, 0x81, 0x64, 0xc1, 0x2d, 0x9c, 0x8f, 0xaf,
  45049. 0x7d, 0x0f, 0x6e, 0x7c, 0x7b, 0xcd, 0x55, 0x79, },
  45050. { 0x13, 0x68, 0x87, 0x59, 0x80, 0x77, 0x6f, 0x88,
  45051. 0x54, 0x52, 0x7a, 0x07, 0x69, 0x0e, 0x96, 0x27, },
  45052. { 0x14, 0xee, 0xca, 0x33, 0x8b, 0x20, 0x86, 0x13,
  45053. 0x48, 0x5e, 0xa0, 0x30, 0x8f, 0xd7, 0xa1, 0x5e, },
  45054. { 0xa1, 0xf1, 0xeb, 0xbe, 0xd8, 0xdb, 0xc1, 0x53,
  45055. 0xc0, 0xb8, 0x4a, 0xa6, 0x1f, 0xf0, 0x82, 0x39, },
  45056. { 0x3b, 0x62, 0xa9, 0xba, 0x62, 0x58, 0xf5, 0x61,
  45057. 0x0f, 0x83, 0xe2, 0x64, 0xf3, 0x14, 0x97, 0xb4, },
  45058. { 0x26, 0x44, 0x99, 0x06, 0x0a, 0xd9, 0xba, 0xab,
  45059. 0xc4, 0x7f, 0x8b, 0x02, 0xbb, 0x6d, 0x71, 0xed, },
  45060. { 0x00, 0x11, 0x0d, 0xc3, 0x78, 0x14, 0x69, 0x56,
  45061. 0xc9, 0x54, 0x47, 0xd3, 0xf3, 0xd0, 0xfb, 0xba, },
  45062. { 0x01, 0x51, 0xc5, 0x68, 0x38, 0x6b, 0x66, 0x77,
  45063. 0xa2, 0xb4, 0xdc, 0x6f, 0x81, 0xe5, 0xdc, 0x18, },
  45064. { 0xd6, 0x26, 0xb2, 0x66, 0x90, 0x5e, 0xf3, 0x58,
  45065. 0x82, 0x63, 0x4d, 0xf6, 0x85, 0x32, 0xc1, 0x25, },
  45066. { 0x98, 0x69, 0xe2, 0x47, 0xe9, 0xc0, 0x8b, 0x10,
  45067. 0xd0, 0x29, 0x93, 0x4f, 0xc4, 0xb9, 0x52, 0xf7, },
  45068. { 0x31, 0xfc, 0xef, 0xac, 0x66, 0xd7, 0xde, 0x9c,
  45069. 0x7e, 0xc7, 0x48, 0x5f, 0xe4, 0x49, 0x49, 0x02, },
  45070. { 0x54, 0x93, 0xe9, 0x99, 0x33, 0xb0, 0xa8, 0x11,
  45071. 0x7e, 0x08, 0xec, 0x0f, 0x97, 0xcf, 0xc3, 0xd9, },
  45072. { 0x6e, 0xe2, 0xa4, 0xca, 0x67, 0xb0, 0x54, 0xbb,
  45073. 0xfd, 0x33, 0x15, 0xbf, 0x85, 0x23, 0x05, 0x77, },
  45074. { 0x47, 0x3d, 0x06, 0xe8, 0x73, 0x8d, 0xb8, 0x98,
  45075. 0x54, 0xc0, 0x66, 0xc4, 0x7a, 0xe4, 0x77, 0x40, },
  45076. { 0xa4, 0x26, 0xe5, 0xe4, 0x23, 0xbf, 0x48, 0x85,
  45077. 0x29, 0x4d, 0xa4, 0x81, 0xfe, 0xae, 0xf7, 0x23, },
  45078. { 0x78, 0x01, 0x77, 0x31, 0xcf, 0x65, 0xfa, 0xb0,
  45079. 0x74, 0xd5, 0x20, 0x89, 0x52, 0x51, 0x2e, 0xb1, },
  45080. { 0x9e, 0x25, 0xfc, 0x83, 0x3f, 0x22, 0x90, 0x73,
  45081. 0x3e, 0x93, 0x44, 0xa5, 0xe8, 0x38, 0x39, 0xeb, },
  45082. { 0x56, 0x8e, 0x49, 0x5a, 0xbe, 0x52, 0x5a, 0x21,
  45083. 0x8a, 0x22, 0x14, 0xcd, 0x3e, 0x07, 0x1d, 0x12, },
  45084. { 0x4a, 0x29, 0xb5, 0x45, 0x52, 0xd1, 0x6b, 0x9a,
  45085. 0x46, 0x9c, 0x10, 0x52, 0x8e, 0xff, 0x0a, 0xae, },
  45086. { 0xc9, 0xd1, 0x84, 0xdd, 0xd5, 0xa9, 0xf5, 0xe0,
  45087. 0xcf, 0x8c, 0xe2, 0x9a, 0x9a, 0xbf, 0x69, 0x1c, },
  45088. { 0x2d, 0xb4, 0x79, 0xae, 0x78, 0xbd, 0x50, 0xd8,
  45089. 0x88, 0x2a, 0x8a, 0x17, 0x8a, 0x61, 0x32, 0xad, },
  45090. { 0x8e, 0xce, 0x5f, 0x04, 0x2d, 0x5e, 0x44, 0x7b,
  45091. 0x50, 0x51, 0xb9, 0xea, 0xcb, 0x8d, 0x8f, 0x6f, },
  45092. { 0x9c, 0x0b, 0x53, 0xb4, 0xb3, 0xc3, 0x07, 0xe8,
  45093. 0x7e, 0xae, 0xe0, 0x86, 0x78, 0x14, 0x1f, 0x66, },
  45094. { 0xab, 0xf2, 0x48, 0xaf, 0x69, 0xa6, 0xea, 0xe4,
  45095. 0xbf, 0xd3, 0xeb, 0x2f, 0x12, 0x9e, 0xeb, 0x94, },
  45096. { 0x06, 0x64, 0xda, 0x16, 0x68, 0x57, 0x4b, 0x88,
  45097. 0xb9, 0x35, 0xf3, 0x02, 0x73, 0x58, 0xae, 0xf4, },
  45098. { 0xaa, 0x4b, 0x9d, 0xc4, 0xbf, 0x33, 0x7d, 0xe9,
  45099. 0x0c, 0xd4, 0xfd, 0x3c, 0x46, 0x7c, 0x6a, 0xb7, },
  45100. { 0xea, 0x5c, 0x7f, 0x47, 0x1f, 0xaf, 0x6b, 0xde,
  45101. 0x2b, 0x1a, 0xd7, 0xd4, 0x68, 0x6d, 0x22, 0x87, },
  45102. { 0x29, 0x39, 0xb0, 0x18, 0x32, 0x23, 0xfa, 0xfc,
  45103. 0x17, 0x23, 0xde, 0x4f, 0x52, 0xc4, 0x3d, 0x35, },
  45104. { 0x7c, 0x39, 0x56, 0xca, 0x5e, 0xea, 0xfc, 0x3e,
  45105. 0x36, 0x3e, 0x9d, 0x55, 0x65, 0x46, 0xeb, 0x68, },
  45106. { 0x77, 0xc6, 0x07, 0x71, 0x46, 0xf0, 0x1c, 0x32,
  45107. 0xb6, 0xb6, 0x9d, 0x5f, 0x4e, 0xa9, 0xff, 0xcf, },
  45108. { 0x37, 0xa6, 0x98, 0x6c, 0xb8, 0x84, 0x7e, 0xdf,
  45109. 0x09, 0x25, 0xf0, 0xf1, 0x30, 0x9b, 0x54, 0xde, },
  45110. { 0xa7, 0x05, 0xf0, 0xe6, 0x9d, 0xa9, 0xa8, 0xf9,
  45111. 0x07, 0x24, 0x1a, 0x2e, 0x92, 0x3c, 0x8c, 0xc8, },
  45112. { 0x3d, 0xc4, 0x7d, 0x1f, 0x29, 0xc4, 0x48, 0x46,
  45113. 0x1e, 0x9e, 0x76, 0xed, 0x90, 0x4f, 0x67, 0x11, },
  45114. { 0x0d, 0x62, 0xbf, 0x01, 0xe6, 0xfc, 0x0e, 0x1a,
  45115. 0x0d, 0x3c, 0x47, 0x51, 0xc5, 0xd3, 0x69, 0x2b, },
  45116. { 0x8c, 0x03, 0x46, 0x8b, 0xca, 0x7c, 0x66, 0x9e,
  45117. 0xe4, 0xfd, 0x5e, 0x08, 0x4b, 0xbe, 0xe7, 0xb5, },
  45118. { 0x52, 0x8a, 0x5b, 0xb9, 0x3b, 0xaf, 0x2c, 0x9c,
  45119. 0x44, 0x73, 0xcc, 0xe5, 0xd0, 0xd2, 0x2b, 0xd9, },
  45120. { 0xdf, 0x6a, 0x30, 0x1e, 0x95, 0xc9, 0x5d, 0xad,
  45121. 0x97, 0xae, 0x0c, 0xc8, 0xc6, 0x91, 0x3b, 0xd8, },
  45122. { 0x80, 0x11, 0x89, 0x90, 0x2c, 0x85, 0x7f, 0x39,
  45123. 0xe7, 0x35, 0x91, 0x28, 0x5e, 0x70, 0xb6, 0xdb, },
  45124. { 0xe6, 0x17, 0x34, 0x6a, 0xc9, 0xc2, 0x31, 0xbb,
  45125. 0x36, 0x50, 0xae, 0x34, 0xcc, 0xca, 0x0c, 0x5b, },
  45126. { 0x27, 0xd9, 0x34, 0x37, 0xef, 0xb7, 0x21, 0xaa,
  45127. 0x40, 0x18, 0x21, 0xdc, 0xec, 0x5a, 0xdf, 0x89, },
  45128. { 0x89, 0x23, 0x7d, 0x9d, 0xed, 0x9c, 0x5e, 0x78,
  45129. 0xd8, 0xb1, 0xc9, 0xb1, 0x66, 0xcc, 0x73, 0x42, },
  45130. { 0x4a, 0x6d, 0x80, 0x91, 0xbf, 0x5e, 0x7d, 0x65,
  45131. 0x11, 0x89, 0xfa, 0x94, 0xa2, 0x50, 0xb1, 0x4c, },
  45132. { 0x0e, 0x33, 0xf9, 0x60, 0x55, 0xe7, 0xae, 0x89,
  45133. 0x3f, 0xfc, 0x0e, 0x3d, 0xcf, 0x49, 0x29, 0x02, },
  45134. { 0xe6, 0x1c, 0x43, 0x2b, 0x72, 0x0b, 0x19, 0xd1,
  45135. 0x8e, 0xc8, 0xd8, 0x4b, 0xdc, 0x63, 0x15, 0x1b, },
  45136. { 0xf7, 0xe5, 0xae, 0xf5, 0x49, 0xf7, 0x82, 0xcf,
  45137. 0x37, 0x90, 0x55, 0xa6, 0x08, 0x26, 0x9b, 0x16, },
  45138. { 0x43, 0x8d, 0x03, 0x0f, 0xd0, 0xb7, 0xa5, 0x4f,
  45139. 0xa8, 0x37, 0xf2, 0xad, 0x20, 0x1a, 0x64, 0x03, },
  45140. { 0xa5, 0x90, 0xd3, 0xee, 0x4f, 0xbf, 0x04, 0xe3,
  45141. 0x24, 0x7e, 0x0d, 0x27, 0xf2, 0x86, 0x42, 0x3f, },
  45142. { 0x5f, 0xe2, 0xc1, 0xa1, 0x72, 0xfe, 0x93, 0xc4,
  45143. 0xb1, 0x5c, 0xd3, 0x7c, 0xae, 0xf9, 0xf5, 0x38, },
  45144. { 0x2c, 0x97, 0x32, 0x5c, 0xbd, 0x06, 0xb3, 0x6e,
  45145. 0xb2, 0x13, 0x3d, 0xd0, 0x8b, 0x3a, 0x01, 0x7c, },
  45146. { 0x92, 0xc8, 0x14, 0x22, 0x7a, 0x6b, 0xca, 0x94,
  45147. 0x9f, 0xf0, 0x65, 0x9f, 0x00, 0x2a, 0xd3, 0x9e, },
  45148. { 0xdc, 0xe8, 0x50, 0x11, 0x0b, 0xd8, 0x32, 0x8c,
  45149. 0xfb, 0xd5, 0x08, 0x41, 0xd6, 0x91, 0x1d, 0x87, },
  45150. { 0x67, 0xf1, 0x49, 0x84, 0xc7, 0xda, 0x79, 0x12,
  45151. 0x48, 0xe3, 0x2b, 0xb5, 0x92, 0x25, 0x83, 0xda, },
  45152. { 0x19, 0x38, 0xf2, 0xcf, 0x72, 0xd5, 0x4e, 0xe9,
  45153. 0x7e, 0x94, 0x16, 0x6f, 0xa9, 0x1d, 0x2a, 0x36, },
  45154. { 0x74, 0x48, 0x1e, 0x96, 0x46, 0xed, 0x49, 0xfe,
  45155. 0x0f, 0x62, 0x24, 0x30, 0x16, 0x04, 0x69, 0x8e, },
  45156. { 0x57, 0xfc, 0xa5, 0xde, 0x98, 0xa9, 0xd6, 0xd8,
  45157. 0x00, 0x64, 0x38, 0xd0, 0x58, 0x3d, 0x8a, 0x1d, },
  45158. { 0x9f, 0xec, 0xde, 0x1c, 0xef, 0xdc, 0x1c, 0xbe,
  45159. 0xd4, 0x76, 0x36, 0x74, 0xd9, 0x57, 0x53, 0x59, },
  45160. { 0xe3, 0x04, 0x0c, 0x00, 0xeb, 0x28, 0xf1, 0x53,
  45161. 0x66, 0xca, 0x73, 0xcb, 0xd8, 0x72, 0xe7, 0x40, },
  45162. { 0x76, 0x97, 0x00, 0x9a, 0x6a, 0x83, 0x1d, 0xfe,
  45163. 0xcc, 0xa9, 0x1c, 0x59, 0x93, 0x67, 0x0f, 0x7a, },
  45164. { 0x58, 0x53, 0x54, 0x23, 0x21, 0xf5, 0x67, 0xa0,
  45165. 0x05, 0xd5, 0x47, 0xa4, 0xf0, 0x47, 0x59, 0xbd, },
  45166. { 0x51, 0x50, 0xd1, 0x77, 0x2f, 0x50, 0x83, 0x4a,
  45167. 0x50, 0x3e, 0x06, 0x9a, 0x97, 0x3f, 0xbd, 0x7c, },
  45168. };
  45169. #endif
  45170. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t siphash_test(void)
  45171. {
  45172. wc_test_ret_t ret = 0;
  45173. int i;
  45174. #if WOLFSSL_SIPHASH_CROUNDS == 2 && WOLFSSL_SIPHASH_DROUNDS == 4
  45175. unsigned char res[SIPHASH_MAC_SIZE_16];
  45176. unsigned char tmp[SIPHASH_MAC_SIZE_8];
  45177. SipHash siphash;
  45178. WOLFSSL_ENTER("siphash_test (1)");
  45179. for (i = 0; i < 64; i++) {
  45180. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45181. if (ret != 0)
  45182. return WC_TEST_RET_ENC_I(i);
  45183. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45184. if (ret != 0)
  45185. return WC_TEST_RET_ENC_I(i);
  45186. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45187. if (ret != 0)
  45188. return WC_TEST_RET_ENC_I(i);
  45189. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45190. return WC_TEST_RET_ENC_I(i);
  45191. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_8);
  45192. if (ret != 0)
  45193. return WC_TEST_RET_ENC_I(i);
  45194. if (XMEMCMP(res, siphash_r8[i], SIPHASH_MAC_SIZE_8) != 0)
  45195. return WC_TEST_RET_ENC_I(i);
  45196. }
  45197. for (i = 0; i < 64; i++) {
  45198. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_16);
  45199. if (ret != 0)
  45200. return WC_TEST_RET_ENC_I(i);
  45201. ret = wc_SipHashUpdate(&siphash, siphash_msg, (word32)i);
  45202. if (ret != 0)
  45203. return WC_TEST_RET_ENC_I(i);
  45204. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  45205. if (ret != 0)
  45206. return WC_TEST_RET_ENC_I(i);
  45207. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45208. return WC_TEST_RET_ENC_I(i);
  45209. ret = wc_SipHash(siphash_key, siphash_msg, (word32)i, res, SIPHASH_MAC_SIZE_16);
  45210. if (ret != 0)
  45211. return WC_TEST_RET_ENC_I(i);
  45212. if (XMEMCMP(res, siphash_r16[i], SIPHASH_MAC_SIZE_16) != 0)
  45213. return WC_TEST_RET_ENC_I(i);
  45214. }
  45215. #else
  45216. WOLFSSL_ENTER("siphash_test (1)");
  45217. #endif
  45218. /* Testing bad parameters. */
  45219. ret = wc_InitSipHash(NULL, NULL, SIPHASH_MAC_SIZE_8);
  45220. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45221. return WC_TEST_RET_ENC_EC(ret);
  45222. ret = wc_InitSipHash(NULL, siphash_key, SIPHASH_MAC_SIZE_8);
  45223. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45224. return WC_TEST_RET_ENC_EC(ret);
  45225. ret = wc_InitSipHash(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  45226. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45227. return WC_TEST_RET_ENC_EC(ret);
  45228. ret = wc_InitSipHash(&siphash, siphash_key, 7);
  45229. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45230. return WC_TEST_RET_ENC_EC(ret);
  45231. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45232. if (ret != 0)
  45233. return WC_TEST_RET_ENC_EC(ret);
  45234. ret = wc_SipHashUpdate(NULL, NULL, 0);
  45235. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45236. return WC_TEST_RET_ENC_EC(ret);
  45237. ret = wc_SipHashUpdate(&siphash, NULL, 1);
  45238. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45239. return WC_TEST_RET_ENC_EC(ret);
  45240. ret = wc_SipHashFinal(NULL, NULL, SIPHASH_MAC_SIZE_8);
  45241. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45242. return WC_TEST_RET_ENC_EC(ret);
  45243. ret = wc_SipHashFinal(&siphash, NULL, SIPHASH_MAC_SIZE_8);
  45244. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45245. return WC_TEST_RET_ENC_EC(ret);
  45246. ret = wc_SipHashFinal(NULL, res, SIPHASH_MAC_SIZE_8);
  45247. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45248. return WC_TEST_RET_ENC_EC(ret);
  45249. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_16);
  45250. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45251. return WC_TEST_RET_ENC_EC(ret);
  45252. ret = wc_SipHash(NULL, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  45253. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45254. return WC_TEST_RET_ENC_EC(ret);
  45255. ret = wc_SipHash(siphash_key, NULL, 0, NULL, SIPHASH_MAC_SIZE_16);
  45256. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45257. return WC_TEST_RET_ENC_EC(ret);
  45258. ret = wc_SipHash(NULL, NULL, 0, res, SIPHASH_MAC_SIZE_16);
  45259. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45260. return WC_TEST_RET_ENC_EC(ret);
  45261. ret = wc_SipHash(siphash_key, NULL, 0, res, 15);
  45262. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45263. return WC_TEST_RET_ENC_EC(ret);
  45264. ret = wc_SipHash(siphash_key, NULL, 1, res, SIPHASH_MAC_SIZE_16);
  45265. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  45266. return WC_TEST_RET_ENC_EC(ret);
  45267. /* Test cache with multiple non blocksize bytes */
  45268. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45269. if (ret != 0)
  45270. return WC_TEST_RET_ENC_EC(ret);
  45271. ret = wc_SipHashUpdate(&siphash, siphash_msg, 5);
  45272. if (ret != 0)
  45273. return WC_TEST_RET_ENC_EC(ret);
  45274. ret = wc_SipHashUpdate(&siphash, siphash_msg + 5, 4);
  45275. if (ret != 0)
  45276. return WC_TEST_RET_ENC_EC(ret);
  45277. ret = wc_SipHashFinal(&siphash, res, SIPHASH_MAC_SIZE_8);
  45278. if (ret != 0)
  45279. return WC_TEST_RET_ENC_EC(ret);
  45280. ret = wc_InitSipHash(&siphash, siphash_key, SIPHASH_MAC_SIZE_8);
  45281. if (ret != 0)
  45282. return WC_TEST_RET_ENC_EC(ret);
  45283. ret = wc_SipHashUpdate(&siphash, siphash_msg, 9);
  45284. if (ret != 0)
  45285. return WC_TEST_RET_ENC_EC(ret);
  45286. ret = wc_SipHashFinal(&siphash, tmp, SIPHASH_MAC_SIZE_8);
  45287. if (ret != 0)
  45288. return WC_TEST_RET_ENC_EC(ret);
  45289. if (XMEMCMP(res, tmp, SIPHASH_MAC_SIZE_8) != 0)
  45290. return WC_TEST_RET_ENC_NC;
  45291. return 0;
  45292. }
  45293. #endif /* WOLFSSL_SIPHASH */
  45294. #ifdef HAVE_LIBZ
  45295. static const byte sample_text[] =
  45296. "Biodiesel cupidatat marfa, cliche aute put a bird on it incididunt elit\n"
  45297. "polaroid. Sunt tattooed bespoke reprehenderit. Sint twee organic id\n"
  45298. "marfa. Commodo veniam ad esse gastropub. 3 wolf moon sartorial vero,\n"
  45299. "plaid delectus biodiesel squid +1 vice. Post-ironic keffiyeh leggings\n"
  45300. "selfies cray fap hoodie, forage anim. Carles cupidatat shoreditch, VHS\n"
  45301. "small batch meggings kogi dolore food truck bespoke gastropub.\n"
  45302. "\n"
  45303. "Terry richardson adipisicing actually typewriter tumblr, twee whatever\n"
  45304. "four loko you probably haven't heard of them high life. Messenger bag\n"
  45305. "whatever tattooed deep v mlkshk. Brooklyn pinterest assumenda chillwave\n"
  45306. "et, banksy ullamco messenger bag umami pariatur direct trade forage.\n"
  45307. "Typewriter culpa try-hard, pariatur sint brooklyn meggings. Gentrify\n"
  45308. "food truck next level, tousled irony non semiotics PBR ethical anim cred\n"
  45309. "readymade. Mumblecore brunch lomo odd future, portland organic terry\n"
  45310. "richardson elit leggings adipisicing ennui raw denim banjo hella. Godard\n"
  45311. "mixtape polaroid, pork belly readymade organic cray typewriter helvetica\n"
  45312. "four loko whatever street art yr farm-to-table.\n"
  45313. "\n"
  45314. "Vinyl keytar vice tofu. Locavore you probably haven't heard of them pug\n"
  45315. "pickled, hella tonx labore truffaut DIY mlkshk elit cosby sweater sint\n"
  45316. "et mumblecore. Elit swag semiotics, reprehenderit DIY sartorial nisi ugh\n"
  45317. "nesciunt pug pork belly wayfarers selfies delectus. Ethical hoodie\n"
  45318. "seitan fingerstache kale chips. Terry richardson artisan williamsburg,\n"
  45319. "eiusmod fanny pack irony tonx ennui lo-fi incididunt tofu YOLO\n"
  45320. "readymade. 8-bit sed ethnic beard officia. Pour-over iphone DIY butcher,\n"
  45321. "ethnic art party qui letterpress nisi proident jean shorts mlkshk\n"
  45322. "locavore.\n"
  45323. "\n"
  45324. "Narwhal flexitarian letterpress, do gluten-free voluptate next level\n"
  45325. "banh mi tonx incididunt carles DIY. Odd future nulla 8-bit beard ut\n"
  45326. "cillum pickled velit, YOLO officia you probably haven't heard of them\n"
  45327. "trust fund gastropub. Nisi adipisicing tattooed, Austin mlkshk 90's\n"
  45328. "small batch american apparel. Put a bird on it cosby sweater before they\n"
  45329. "sold out pork belly kogi hella. Street art mollit sustainable polaroid,\n"
  45330. "DIY ethnic ea pug beard dreamcatcher cosby sweater magna scenester nisi.\n"
  45331. "Sed pork belly skateboard mollit, labore proident eiusmod. Sriracha\n"
  45332. "excepteur cosby sweater, anim deserunt laborum eu aliquip ethical et\n"
  45333. "neutra PBR selvage.\n"
  45334. "\n"
  45335. "Raw denim pork belly truffaut, irony plaid sustainable put a bird on it\n"
  45336. "next level jean shorts exercitation. Hashtag keytar whatever, nihil\n"
  45337. "authentic aliquip disrupt laborum. Tattooed selfies deserunt trust fund\n"
  45338. "wayfarers. 3 wolf moon synth church-key sartorial, gastropub leggings\n"
  45339. "tattooed. Labore high life commodo, meggings raw denim fingerstache pug\n"
  45340. "trust fund leggings seitan forage. Nostrud ullamco duis, reprehenderit\n"
  45341. "incididunt flannel sustainable helvetica pork belly pug banksy you\n"
  45342. "probably haven't heard of them nesciunt farm-to-table. Disrupt nostrud\n"
  45343. "mollit magna, sriracha sartorial helvetica.\n"
  45344. "\n"
  45345. "Nulla kogi reprehenderit, skateboard sustainable duis adipisicing viral\n"
  45346. "ad fanny pack salvia. Fanny pack trust fund you probably haven't heard\n"
  45347. "of them YOLO vice nihil. Keffiyeh cray lo-fi pinterest cardigan aliqua,\n"
  45348. "reprehenderit aute. Culpa tousled williamsburg, marfa lomo actually anim\n"
  45349. "skateboard. Iphone aliqua ugh, semiotics pariatur vero readymade\n"
  45350. "organic. Marfa squid nulla, in laborum disrupt laboris irure gastropub.\n"
  45351. "Veniam sunt food truck leggings, sint vinyl fap.\n"
  45352. "\n"
  45353. "Hella dolore pork belly, truffaut carles you probably haven't heard of\n"
  45354. "them PBR helvetica in sapiente. Fashion axe ugh bushwick american\n"
  45355. "apparel. Fingerstache sed iphone, jean shorts blue bottle nisi bushwick\n"
  45356. "flexitarian officia veniam plaid bespoke fap YOLO lo-fi. Blog\n"
  45357. "letterpress mumblecore, food truck id cray brooklyn cillum ad sed.\n"
  45358. "Assumenda chambray wayfarers vinyl mixtape sustainable. VHS vinyl\n"
  45359. "delectus, culpa williamsburg polaroid cliche swag church-key synth kogi\n"
  45360. "magna pop-up literally. Swag thundercats ennui shoreditch vegan\n"
  45361. "pitchfork neutra truffaut etsy, sed single-origin coffee craft beer.\n"
  45362. "\n"
  45363. "Odio letterpress brooklyn elit. Nulla single-origin coffee in occaecat\n"
  45364. "meggings. Irony meggings 8-bit, chillwave lo-fi adipisicing cred\n"
  45365. "dreamcatcher veniam. Put a bird on it irony umami, trust fund bushwick\n"
  45366. "locavore kale chips. Sriracha swag thundercats, chillwave disrupt\n"
  45367. "tousled beard mollit mustache leggings portland next level. Nihil esse\n"
  45368. "est, skateboard art party etsy thundercats sed dreamcatcher ut iphone\n"
  45369. "swag consectetur et. Irure skateboard banjo, nulla deserunt messenger\n"
  45370. "bag dolor terry richardson sapiente.\n";
  45371. static const byte sample_text_gz[] = {
  45372. 0x1F, 0x8B, 0x08, 0x08, 0xC5, 0x49, 0xB5, 0x5B, 0x00, 0x03, 0x63, 0x69, 0x70,
  45373. 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x2E, 0x74, 0x78, 0x74, 0x00, 0x8D,
  45374. 0x58, 0xCB, 0x92, 0xE4, 0xB6, 0x11, 0xBC, 0xE3, 0x2B, 0xEA, 0xA6, 0x83, 0xD9,
  45375. 0x1D, 0x72, 0xF8, 0x22, 0x1F, 0xB5, 0x96, 0xA5, 0xDD, 0x90, 0xBC, 0xAB, 0xD0,
  45376. 0x28, 0x36, 0x42, 0x47, 0x90, 0x2C, 0x36, 0xA1, 0x06, 0x09, 0x0A, 0x8F, 0xEE,
  45377. 0xE1, 0xDF, 0x3B, 0x0B, 0xE0, 0x73, 0x2C, 0x4B, 0xBA, 0xCD, 0xCE, 0x80, 0x78,
  45378. 0x64, 0x65, 0x65, 0x66, 0xED, 0x3B, 0xE3, 0x5A, 0xC3, 0x81, 0x2D, 0x35, 0x69,
  45379. 0x32, 0xAD, 0x8E, 0x3A, 0xD2, 0xA0, 0x7D, 0xA7, 0x2B, 0x6A, 0xAC, 0x69, 0x7A,
  45380. 0x26, 0x9D, 0x22, 0xD3, 0x94, 0x22, 0x69, 0xAA, 0x8D, 0x6F, 0xC9, 0x8D, 0x64,
  45381. 0x22, 0x99, 0xB1, 0x31, 0xAD, 0x69, 0xD3, 0x18, 0x89, 0xAD, 0x89, 0x6A, 0x72,
  45382. 0x56, 0x7B, 0x67, 0xDA, 0x2B, 0xBD, 0xC8, 0xEF, 0xB0, 0x4D, 0x74, 0x8E, 0x5B,
  45383. 0xAA, 0x39, 0x4C, 0xEE, 0xCE, 0xE4, 0x79, 0xF2, 0xDC, 0xF3, 0xD8, 0xB2, 0x37,
  45384. 0x11, 0x8B, 0x8C, 0x2C, 0x7A, 0x32, 0x93, 0xF3, 0x37, 0x3D, 0x9A, 0x86, 0x4C,
  45385. 0xAB, 0xF2, 0xB9, 0x57, 0xFA, 0x97, 0x1B, 0x06, 0xD7, 0x3A, 0x7A, 0xF0, 0x68,
  45386. 0xF4, 0x40, 0xBA, 0x25, 0x0E, 0x81, 0xE9, 0xA6, 0x43, 0xF4, 0x6E, 0x4A, 0xF5,
  45387. 0x95, 0xFE, 0x41, 0x4F, 0x67, 0x3B, 0x1A, 0x1C, 0xEE, 0x12, 0xB4, 0x8F, 0xCE,
  45388. 0x1B, 0x6D, 0xB1, 0xDE, 0xBB, 0x4A, 0x4D, 0x56, 0x9B, 0x96, 0x5A, 0xB6, 0xDC,
  45389. 0xC4, 0x14, 0x70, 0xE5, 0xF5, 0x7D, 0xE1, 0xB7, 0x84, 0x3F, 0xFC, 0xED, 0xEF,
  45390. 0xF4, 0x30, 0x0D, 0x5F, 0xE9, 0x47, 0x17, 0xE2, 0xC5, 0x78, 0x27, 0x67, 0xDF,
  45391. 0xB9, 0xEB, 0xCC, 0xCC, 0x3D, 0x59, 0xBE, 0xDD, 0xCC, 0x78, 0x0B, 0x0A, 0x1F,
  45392. 0x74, 0xF8, 0x8C, 0x1A, 0xAF, 0x67, 0xEA, 0xF4, 0x44, 0xBD, 0x93, 0x7D, 0x2A,
  45393. 0xEA, 0x9C, 0xD7, 0x37, 0x80, 0x32, 0x9A, 0x01, 0x37, 0xD5, 0xDE, 0xCA, 0xA2,
  45394. 0x0D, 0xB9, 0xD0, 0x3B, 0xCF, 0xAD, 0x89, 0x4D, 0x5F, 0xD1, 0xE7, 0xF7, 0x2F,
  45395. 0x2A, 0x0C, 0xDA, 0x5A, 0xAA, 0x35, 0x7E, 0x41, 0xC3, 0xB2, 0x37, 0xDD, 0xDD,
  45396. 0xCD, 0x50, 0xEB, 0x2C, 0x96, 0x62, 0x3B, 0xD7, 0x52, 0xF4, 0xA9, 0xB9, 0x6F,
  45397. 0x48, 0xED, 0xEF, 0x54, 0xEA, 0x67, 0xF6, 0x7E, 0x26, 0x8F, 0x3A, 0x68, 0xDF,
  45398. 0x06, 0xBC, 0x56, 0xB7, 0x66, 0x32, 0xC1, 0x34, 0xD8, 0x88, 0x34, 0x1E, 0x88,
  45399. 0xED, 0x67, 0x8A, 0xF3, 0xC4, 0x4F, 0xC0, 0xCA, 0x9E, 0x62, 0x1A, 0x6A, 0xEB,
  45400. 0xAB, 0x02, 0xED, 0xB3, 0xD7, 0x91, 0x81, 0x8A, 0xEA, 0x5C, 0xF2, 0x64, 0xDD,
  45401. 0xDD, 0xD1, 0xEC, 0x12, 0x4D, 0xDE, 0xD5, 0xBA, 0xC6, 0x77, 0xBD, 0x06, 0xC4,
  45402. 0x5F, 0x44, 0xEA, 0x59, 0x4B, 0x5D, 0x3B, 0x8A, 0x3D, 0x0F, 0xD4, 0x9B, 0x1B,
  45403. 0x80, 0x30, 0x1D, 0x30, 0xFA, 0x8F, 0x00, 0x3F, 0xDE, 0xB0, 0x6F, 0xAD, 0x6F,
  45404. 0x6A, 0xDD, 0x6E, 0x2F, 0x6E, 0xCB, 0x3C, 0xD1, 0x83, 0x06, 0x7B, 0x0F, 0xFD,
  45405. 0xFD, 0x4A, 0xEF, 0xBC, 0x73, 0x77, 0x3B, 0x8F, 0x34, 0xA1, 0xBA, 0xEC, 0x39,
  45406. 0x80, 0x33, 0x21, 0xA4, 0x01, 0x55, 0xD7, 0xD4, 0xF4, 0xC6, 0xDA, 0x27, 0x4E,
  45407. 0x54, 0x1C, 0x2B, 0xEC, 0x37, 0xDE, 0xC3, 0x4C, 0xC9, 0x5A, 0x3D, 0x34, 0x0E,
  45408. 0xD8, 0x1C, 0x0E, 0xA2, 0x34, 0xE8, 0xC1, 0xD0, 0xA4, 0x51, 0xD5, 0x88, 0x8B,
  45409. 0xB7, 0xC6, 0xA3, 0x96, 0x40, 0x49, 0xB7, 0xBC, 0xE0, 0x7F, 0x55, 0x3F, 0xEF,
  45410. 0x6F, 0x6E, 0x92, 0x9D, 0x34, 0xFE, 0x3C, 0x5F, 0x04, 0xA5, 0x6A, 0xFF, 0x30,
  45411. 0x08, 0xC9, 0xEA, 0xF5, 0x52, 0x2B, 0xFE, 0x57, 0xFA, 0x8E, 0xC7, 0xE8, 0x4D,
  45412. 0x37, 0xAB, 0x03, 0xFA, 0x23, 0xBF, 0x46, 0x94, 0xFF, 0xC1, 0x16, 0xE0, 0xB9,
  45413. 0x14, 0x2C, 0x9E, 0x27, 0xEC, 0x98, 0x69, 0x14, 0x92, 0xF1, 0x60, 0x5C, 0x34,
  45414. 0x4D, 0xA0, 0x1F, 0xDF, 0xFD, 0x44, 0x1C, 0x7B, 0xD3, 0x80, 0x70, 0x42, 0x02,
  45415. 0x30, 0x84, 0x5B, 0xE5, 0x59, 0xB7, 0xF3, 0x80, 0xFB, 0x01, 0x33, 0xA9, 0x00,
  45416. 0x37, 0x52, 0xDC, 0xDA, 0xA7, 0x11, 0x85, 0xB7, 0x6E, 0x70, 0xE4, 0xDA, 0x96,
  45417. 0xBA, 0x84, 0x5B, 0x81, 0x43, 0x93, 0xF3, 0xD1, 0xEA, 0xB1, 0xDD, 0xB8, 0x1F,
  45418. 0xA5, 0xCC, 0xEA, 0x50, 0x66, 0x69, 0xA9, 0x8D, 0x8C, 0xA7, 0xA2, 0xF3, 0x38,
  45419. 0x26, 0x43, 0x5E, 0x3F, 0x01, 0xBE, 0x1C, 0x0F, 0x20, 0x7F, 0x75, 0xA8, 0x20,
  45420. 0x80, 0xC4, 0xC3, 0x5C, 0x8B, 0x0D, 0xD4, 0x60, 0x5E, 0xA3, 0x9E, 0xD0, 0xB4,
  45421. 0x4B, 0x4F, 0xE6, 0x13, 0x85, 0x60, 0x42, 0x96, 0xED, 0xAA, 0xDB, 0xE9, 0x99,
  45422. 0xE3, 0x07, 0x0E, 0x61, 0xB3, 0x07, 0xE3, 0xB1, 0xFA, 0xC0, 0x9B, 0xAD, 0xF6,
  45423. 0xE0, 0x26, 0x33, 0xEA, 0xEA, 0x23, 0xCD, 0x1E, 0x9D, 0xE1, 0x87, 0x4B, 0x74,
  45424. 0x97, 0x08, 0x3E, 0xA1, 0x28, 0xEA, 0xB3, 0x19, 0x67, 0x8B, 0x76, 0x9A, 0xA3,
  45425. 0xF6, 0xB9, 0xCF, 0x80, 0x65, 0x97, 0xAE, 0xF4, 0x83, 0x6B, 0xF4, 0x43, 0x20,
  45426. 0xF9, 0x0B, 0xFC, 0x9B, 0xD2, 0x4D, 0x4D, 0xA6, 0xB9, 0xA3, 0x02, 0x55, 0x79,
  45427. 0x18, 0x36, 0x19, 0x5F, 0xC9, 0xEA, 0x5A, 0x76, 0x40, 0xB9, 0xBA, 0x0E, 0x9A,
  45428. 0x44, 0xDF, 0x7C, 0xF8, 0x65, 0x61, 0x5E, 0x81, 0xAB, 0x71, 0xA1, 0x9E, 0x29,
  45429. 0x3C, 0x59, 0xCB, 0x23, 0xA4, 0xF6, 0x60, 0x1A, 0x0D, 0x5B, 0x39, 0xAE, 0xF4,
  45430. 0x6F, 0x59, 0x16, 0x9E, 0x60, 0xD8, 0x56, 0xCF, 0xEA, 0x2C, 0x4C, 0x79, 0xD3,
  45431. 0x5D, 0x51, 0x46, 0xA0, 0x4E, 0xE9, 0xD6, 0xAB, 0x91, 0x43, 0x63, 0x44, 0xD7,
  45432. 0x70, 0xB9, 0x23, 0x98, 0x4F, 0x3D, 0x03, 0x02, 0xF6, 0x81, 0x56, 0xC1, 0x58,
  45433. 0x85, 0x07, 0xA7, 0x2D, 0x2C, 0x29, 0xCA, 0x01, 0x45, 0x31, 0x51, 0x8F, 0xD4,
  45434. 0x19, 0xA1, 0x79, 0x88, 0x5A, 0xA4, 0xF5, 0xAE, 0x2D, 0x4B, 0x63, 0x4C, 0x58,
  45435. 0xFE, 0xBF, 0xAD, 0xEE, 0xA3, 0x09, 0xF8, 0xE2, 0x89, 0xBE, 0x81, 0x0E, 0x86,
  45436. 0x3A, 0xF9, 0x5B, 0xA5, 0xD8, 0xA4, 0x00, 0x75, 0x04, 0xF2, 0x23, 0xB8, 0x39,
  45437. 0x69, 0x50, 0xB7, 0xD0, 0x34, 0x63, 0x54, 0xD8, 0x61, 0xDD, 0xA5, 0x33, 0x47,
  45438. 0x85, 0x96, 0x22, 0xD0, 0x2F, 0x9F, 0x7E, 0xF8, 0x74, 0x24, 0xEA, 0x57, 0x97,
  45439. 0x5A, 0xE0, 0x00, 0xCF, 0xC1, 0x67, 0xE1, 0x41, 0xBD, 0x94, 0xA1, 0x03, 0xD3,
  45440. 0xB4, 0x08, 0x64, 0xF2, 0x17, 0x27, 0x35, 0x37, 0x53, 0xEF, 0x46, 0xCE, 0xD8,
  45441. 0xD4, 0x09, 0x52, 0xC6, 0x1E, 0xF7, 0x28, 0xDF, 0x08, 0x0F, 0xD0, 0x6F, 0x71,
  45442. 0xA6, 0xDF, 0xE4, 0x60, 0x8E, 0xC0, 0x1E, 0x78, 0x86, 0x50, 0xB0, 0x9B, 0x84,
  45443. 0x7E, 0xE8, 0x36, 0xFA, 0x95, 0xF1, 0x12, 0x51, 0xC7, 0x18, 0x96, 0xA2, 0x29,
  45444. 0xBB, 0x70, 0x02, 0xB4, 0xF9, 0xA8, 0x3D, 0x08, 0x66, 0xA9, 0xB3, 0xFC, 0x0A,
  45445. 0x94, 0x80, 0xFD, 0x78, 0xDC, 0xAB, 0x82, 0x5A, 0xD2, 0xCD, 0xC2, 0x87, 0xC6,
  45446. 0x4B, 0x07, 0xFA, 0xD1, 0xC3, 0xD9, 0x34, 0x41, 0x85, 0xF8, 0xD0, 0xB6, 0x0A,
  45447. 0x9D, 0x00, 0x91, 0x35, 0x05, 0x88, 0xC3, 0xE3, 0x9B, 0x22, 0xD2, 0xB8, 0xFD,
  45448. 0x95, 0x3E, 0x6D, 0x5D, 0x48, 0xA3, 0x68, 0xCF, 0x02, 0x42, 0x79, 0x79, 0x8A,
  45449. 0xAA, 0x01, 0xD6, 0x09, 0x14, 0x2C, 0xF4, 0x83, 0xA3, 0x80, 0x31, 0x55, 0x46,
  45450. 0x6E, 0xC5, 0xE5, 0x2F, 0x30, 0x58, 0x81, 0xA2, 0x90, 0xBE, 0x2E, 0xA1, 0xC3,
  45451. 0x0F, 0xA6, 0xF5, 0x51, 0x00, 0x39, 0xB6, 0xF2, 0x2A, 0xA3, 0x15, 0x7D, 0x8D,
  45452. 0xF5, 0x66, 0x5C, 0xD9, 0xFC, 0xCF, 0x2F, 0xBF, 0x08, 0x27, 0xE7, 0xD0, 0x03,
  45453. 0xB8, 0xD9, 0x00, 0x13, 0x3D, 0x01, 0x6B, 0xB6, 0xA8, 0xCD, 0x5B, 0x3B, 0x3E,
  45454. 0x93, 0xBF, 0xE6, 0x2E, 0xB7, 0x4A, 0xCF, 0xB3, 0x0A, 0xCE, 0x62, 0x11, 0xD6,
  45455. 0x1F, 0x68, 0x9B, 0x1D, 0x68, 0xD1, 0x8C, 0x97, 0xBD, 0xA1, 0x07, 0x67, 0x73,
  45456. 0x87, 0xE0, 0x36, 0xDA, 0x8C, 0xD2, 0xD2, 0xBB, 0x84, 0x28, 0xA9, 0xFE, 0x52,
  45457. 0x74, 0xD6, 0xB9, 0x0F, 0x0A, 0x6A, 0x2D, 0x28, 0x35, 0x34, 0x3A, 0xD3, 0xE2,
  45458. 0xCD, 0x35, 0x06, 0x7D, 0x1B, 0x35, 0x85, 0x86, 0xD1, 0x3E, 0xF2, 0x6F, 0xA1,
  45459. 0xC4, 0x55, 0xBD, 0x00, 0xD8, 0xC3, 0x5D, 0xC2, 0x1D, 0x6B, 0x6B, 0x27, 0x5B,
  45460. 0x95, 0xF3, 0xAB, 0xB5, 0xD3, 0x37, 0xF2, 0x2C, 0x9C, 0xC7, 0x5D, 0xBD, 0xF1,
  45461. 0x68, 0x1C, 0xAD, 0xF8, 0xB5, 0xE1, 0x29, 0x72, 0x7A, 0x73, 0x62, 0x55, 0x24,
  45462. 0xB9, 0x85, 0xDF, 0x7B, 0x29, 0x7D, 0xDE, 0x08, 0xF5, 0xE4, 0x44, 0xDA, 0x1A,
  45463. 0x30, 0x74, 0xDA, 0xB4, 0x9B, 0x23, 0x9A, 0x3A, 0xC1, 0x53, 0xB2, 0xA2, 0xA3,
  45464. 0x7B, 0x1F, 0xD9, 0x56, 0xD4, 0x4F, 0x9B, 0xB2, 0x1E, 0xEE, 0xB8, 0x6A, 0x4E,
  45465. 0xB5, 0xF4, 0x5A, 0xC9, 0x18, 0x27, 0x9C, 0xDE, 0x14, 0x44, 0xED, 0xC4, 0x3C,
  45466. 0x71, 0x9F, 0x5F, 0xD9, 0x37, 0xA0, 0x78, 0x34, 0x6E, 0xBC, 0xD2, 0x7B, 0x1D,
  45467. 0xFA, 0x08, 0x39, 0x5A, 0x04, 0x73, 0x15, 0xD9, 0x0A, 0x48, 0xC1, 0x2D, 0x15,
  45468. 0x4E, 0x84, 0x30, 0x45, 0x69, 0xB3, 0xE5, 0xF6, 0xAD, 0x09, 0x1E, 0xCC, 0x5F,
  45469. 0x1F, 0x06, 0xD5, 0x58, 0xAD, 0x78, 0xD7, 0x9F, 0xE5, 0xED, 0x3B, 0x09, 0xD5,
  45470. 0xA6, 0x52, 0x6F, 0x92, 0xD3, 0x3C, 0xC6, 0x1E, 0xF2, 0x93, 0x7C, 0xD3, 0x5F,
  45471. 0x70, 0x85, 0x5D, 0xF8, 0xAA, 0x9D, 0xB7, 0x7B, 0x24, 0x5A, 0xE9, 0x0A, 0x35,
  45472. 0x2F, 0xF5, 0xD9, 0x82, 0x02, 0x8A, 0x90, 0x13, 0x5B, 0xB5, 0x67, 0x9C, 0xDD,
  45473. 0xA0, 0x4E, 0x82, 0x27, 0xDA, 0x7E, 0xE8, 0x8E, 0xCD, 0xE1, 0x56, 0x71, 0x2C,
  45474. 0xE6, 0x4E, 0x1F, 0x91, 0xCD, 0x7C, 0x6A, 0xB7, 0x78, 0xD0, 0x26, 0xF3, 0x56,
  45475. 0xA9, 0xD5, 0xA1, 0xC3, 0x3B, 0x98, 0xE9, 0x28, 0x09, 0xEF, 0x50, 0x90, 0xCD,
  45476. 0xC4, 0x8E, 0x75, 0xCC, 0xAC, 0x2D, 0xC9, 0x03, 0x6D, 0xAC, 0xFE, 0xC4, 0x88,
  45477. 0x36, 0xD1, 0x3F, 0xBB, 0x1C, 0x7D, 0xB3, 0x14, 0x61, 0x2C, 0xB7, 0x54, 0x4B,
  45478. 0xDB, 0x64, 0xB6, 0x57, 0x14, 0x16, 0x8E, 0x1E, 0x6C, 0x64, 0xBB, 0x8B, 0x48,
  45479. 0x5D, 0x96, 0x9D, 0xDC, 0x80, 0xA7, 0xF7, 0x54, 0xC7, 0x46, 0x38, 0x3E, 0x44,
  45480. 0xDE, 0x7E, 0x92, 0x8D, 0x07, 0xF6, 0x07, 0x37, 0x4E, 0x16, 0x10, 0xB4, 0x7D,
  45481. 0x88, 0x66, 0x7F, 0xBB, 0xFF, 0xEA, 0x00, 0xF3, 0xFF, 0x97, 0x2C, 0xB5, 0xBE,
  45482. 0x35, 0x4B, 0x5C, 0x36, 0xEC, 0x4C, 0xBD, 0x2B, 0x7D, 0xBF, 0x46, 0xE2, 0x9C,
  45483. 0x0E, 0x8A, 0xA3, 0xEC, 0xB1, 0x0E, 0x9A, 0xDA, 0x9A, 0x9B, 0x28, 0x92, 0x10,
  45484. 0x53, 0x57, 0xEA, 0xEC, 0xA2, 0x32, 0x32, 0x20, 0x1D, 0x97, 0x5C, 0xB6, 0x84,
  45485. 0xA9, 0x93, 0x8D, 0x95, 0x11, 0xA3, 0x24, 0xA3, 0x2D, 0xC6, 0x4A, 0xEF, 0xAA,
  45486. 0x1D, 0x85, 0x2B, 0x7D, 0x28, 0xBE, 0x53, 0xCE, 0x10, 0x1F, 0xAE, 0x0E, 0x41,
  45487. 0x6C, 0x4B, 0x79, 0x12, 0xFB, 0xF7, 0x54, 0xA3, 0x96, 0x54, 0x83, 0x20, 0x96,
  45488. 0x8F, 0x28, 0xA9, 0x3F, 0x8B, 0x3D, 0xBA, 0x77, 0xDC, 0x24, 0xE1, 0xD4, 0x49,
  45489. 0x40, 0xD8, 0x78, 0x31, 0x85, 0x43, 0xF6, 0xFE, 0x5C, 0xA6, 0x8F, 0x90, 0x09,
  45490. 0xB0, 0xE7, 0xC4, 0x95, 0xB2, 0x55, 0x49, 0x97, 0x8F, 0x1C, 0x78, 0x30, 0x20,
  45491. 0xA0, 0xB4, 0xEF, 0x73, 0x56, 0x59, 0x82, 0xFD, 0xCE, 0xBA, 0x6A, 0x8F, 0x2C,
  45492. 0x8B, 0x15, 0xFD, 0xA1, 0x85, 0xA8, 0x5C, 0x0F, 0x11, 0xA5, 0x9D, 0xC2, 0x46,
  45493. 0xC6, 0x9C, 0xC9, 0x40, 0x0B, 0x58, 0x6A, 0x1C, 0x7A, 0x23, 0xF9, 0xE0, 0x95,
  45494. 0x05, 0x13, 0x58, 0x72, 0xE8, 0x9F, 0x30, 0xAC, 0xCD, 0x26, 0xD4, 0x66, 0x13,
  45495. 0xDF, 0x1E, 0x7B, 0x4F, 0x9C, 0xBE, 0x38, 0x79, 0x75, 0x92, 0xA4, 0xDA, 0x26,
  45496. 0x44, 0x55, 0x17, 0xA3, 0xE5, 0x62, 0xDA, 0xEB, 0x86, 0xEA, 0x68, 0xC7, 0xAB,
  45497. 0xFD, 0x2D, 0x43, 0x59, 0x51, 0xC0, 0x75, 0x64, 0x91, 0x01, 0x29, 0x33, 0x28,
  45498. 0xF3, 0x04, 0x83, 0x80, 0x75, 0x37, 0x75, 0x0C, 0x03, 0x7B, 0x0A, 0xAB, 0x8E,
  45499. 0x60, 0x62, 0x8B, 0x4C, 0xAF, 0x2D, 0xA3, 0x2F, 0xFE, 0xAB, 0x45, 0xCF, 0xDA,
  45500. 0xAB, 0xFA, 0xFA, 0x30, 0x3D, 0xE8, 0xA1, 0x96, 0xA5, 0x7B, 0xE2, 0x2A, 0xD0,
  45501. 0xAF, 0x59, 0xF7, 0xD0, 0x32, 0x57, 0x19, 0xBD, 0xCA, 0x9F, 0xD5, 0x1A, 0xC7,
  45502. 0xAA, 0x65, 0x4A, 0x38, 0xB2, 0x70, 0x33, 0xB7, 0x75, 0xD2, 0xCD, 0xD1, 0xF0,
  45503. 0xA8, 0x87, 0x59, 0x20, 0xA5, 0x57, 0x55, 0xB1, 0xB2, 0xC9, 0x4D, 0x97, 0x34,
  45504. 0x41, 0xF3, 0xF0, 0x30, 0xA1, 0x2C, 0x1C, 0x49, 0x3E, 0x89, 0x7D, 0x12, 0xE2,
  45505. 0xC3, 0x04, 0xC3, 0x92, 0xC0, 0xF6, 0x39, 0x10, 0x80, 0x81, 0x8F, 0x08, 0xB4,
  45506. 0xF8, 0xB9, 0x13, 0x4E, 0x2C, 0xAE, 0xB3, 0x71, 0x82, 0x63, 0x98, 0xAB, 0x5C,
  45507. 0x1C, 0x10, 0xEA, 0x66, 0xF9, 0x02, 0x3A, 0x82, 0x61, 0xD0, 0xD4, 0xAE, 0x43,
  45508. 0xD4, 0x01, 0x3E, 0x9D, 0x04, 0x14, 0xF6, 0x60, 0xD8, 0xA7, 0xD6, 0xB8, 0x53,
  45509. 0xC8, 0xDA, 0x80, 0x93, 0xA0, 0x02, 0xDD, 0xCC, 0xE2, 0xF2, 0xBB, 0xFB, 0xE0,
  45510. 0x27, 0xD7, 0x34, 0x9A, 0x71, 0x49, 0xB5, 0x4F, 0x42, 0x1F, 0xB2, 0x9D, 0x6D,
  45511. 0xAA, 0x9D, 0xD3, 0x50, 0xB5, 0x8F, 0x6A, 0x4B, 0xDF, 0x1F, 0xD5, 0x27, 0x8F,
  45512. 0x3B, 0x27, 0xCF, 0x2F, 0x8C, 0xF8, 0x9D, 0x4C, 0x52, 0xBC, 0x32, 0x0F, 0x73,
  45513. 0xD5, 0x51, 0x8E, 0x36, 0x7E, 0xAD, 0x09, 0xF0, 0x94, 0x83, 0x5F, 0x36, 0xFD,
  45514. 0x7C, 0x03, 0xED, 0xF1, 0x5E, 0x4B, 0xF7, 0xAA, 0x55, 0x5C, 0x4A, 0x14, 0x59,
  45515. 0x85, 0x38, 0x2D, 0x8C, 0xDF, 0xEC, 0x65, 0x1B, 0xB8, 0x76, 0x57, 0x96, 0x3C,
  45516. 0x86, 0xED, 0xF2, 0x7F, 0x2D, 0x28, 0x48, 0xDA, 0x49, 0x7F, 0xF7, 0x54, 0x2B,
  45517. 0xD5, 0x39, 0xD5, 0x57, 0x0A, 0x75, 0x7A, 0x3E, 0x5E, 0x5D, 0xBA, 0x4A, 0x15,
  45518. 0xFA, 0xB8, 0x31, 0x80, 0x71, 0x2C, 0xCA, 0xC4, 0x51, 0x10, 0x16, 0x5D, 0x39,
  45519. 0xEC, 0x9D, 0x07, 0xB6, 0x6A, 0x89, 0x9F, 0x9B, 0x5B, 0x6F, 0x03, 0xB0, 0x92,
  45520. 0x01, 0x38, 0x6B, 0x48, 0x99, 0x0A, 0x8F, 0x13, 0xC1, 0xA6, 0x01, 0xEA, 0xBF,
  45521. 0x6F, 0x86, 0x43, 0x51, 0xB6, 0x11, 0x00, 0x00
  45522. };
  45523. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t compress_test(void)
  45524. {
  45525. wc_test_ret_t ret = 0;
  45526. word32 dSz = sizeof(sample_text);
  45527. word32 cSz = (dSz + (word32)(dSz * 0.001) + 12);
  45528. byte *c;
  45529. byte *d;
  45530. WOLFSSL_ENTER("compress_test");
  45531. c = (byte *)XMALLOC(cSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45532. d = (byte *)XMALLOC(dSz * sizeof(byte), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45533. if (c == NULL || d == NULL) {
  45534. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
  45535. }
  45536. /* follow calloc and initialize to 0 */
  45537. XMEMSET(c, 0, cSz);
  45538. XMEMSET(d, 0, dSz);
  45539. if ((ret = wc_Compress(c, cSz, sample_text, dSz, 0)) < 0) {
  45540. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45541. }
  45542. cSz = (word32)ret;
  45543. if ((ret = wc_DeCompress(d, dSz, c, cSz)) != (int)dSz) {
  45544. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45545. }
  45546. dSz = (word32)ret;
  45547. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45548. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45549. }
  45550. /* GZIP tests */
  45551. cSz = (dSz + (word32)(dSz * 0.001) + 12); /* reset cSz */
  45552. XMEMSET(c, 0, cSz);
  45553. XMEMSET(d, 0, dSz);
  45554. ret = wc_Compress_ex(c, cSz, sample_text, dSz, 0, LIBZ_WINBITS_GZIP);
  45555. if (ret < 0)
  45556. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45557. cSz = (word32)ret;
  45558. ret = wc_DeCompress_ex(d, dSz, c, cSz, LIBZ_WINBITS_GZIP);
  45559. if (ret < 0)
  45560. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45561. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45562. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45563. }
  45564. /* Try with gzip generated output */
  45565. XMEMSET(d, 0, dSz);
  45566. ret = wc_DeCompress_ex(d, dSz, sample_text_gz, sizeof(sample_text_gz),
  45567. LIBZ_WINBITS_GZIP);
  45568. if (ret < 0)
  45569. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
  45570. dSz = (word32)ret;
  45571. if (XMEMCMP(d, sample_text, dSz) != 0) {
  45572. ERROR_OUT(WC_TEST_RET_ENC_NC, exit);
  45573. }
  45574. ret = 0; /* success */
  45575. exit:
  45576. XFREE(c, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45577. XFREE(d, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  45578. return ret;
  45579. }
  45580. #endif /* HAVE_LIBZ */
  45581. #ifdef HAVE_PKCS7
  45582. /* External Debugging/Testing Note:
  45583. *
  45584. * PKCS#7 test functions can output generated PKCS#7/CMS bundles for
  45585. * additional testing. To dump bundles to files DER encoded files, please
  45586. * define:
  45587. *
  45588. * #define PKCS7_OUTPUT_TEST_BUNDLES
  45589. */
  45590. /* Loads certs and keys for use with PKCS7 tests, from either files
  45591. * or buffers.
  45592. *
  45593. * rsaClientCertBuf - output buffer for RSA client cert
  45594. * rsaClientCertBufSz - IN/OUT size of output buffer, size of RSA client cert
  45595. * rsaClientPrivKeyBuf - output buffer for RSA client private key
  45596. * rsaClientPrivKeyBufSz - IN/OUT size of output buffer, size of RSA client key
  45597. *
  45598. * rsaServerCertBuf - output buffer for RSA server cert
  45599. * rsaServerCertBufSz - IN/OUT size of output buffer, size of RSA server cert
  45600. * rsaServerPrivKeyBuf - output buffer for RSA server private key
  45601. * rsaServerPrivKeyBufSz - IN/OUT size of output buffer, size of RSA server key
  45602. *
  45603. * rsaCaCertBuf - output buffer for RSA CA cert
  45604. * rsaCaCertBufSz - IN/OUT size of output buffer, size of RSA ca cert
  45605. * rsaCaPrivKeyBuf - output buffer for RSA CA private key
  45606. * rsaCaPrivKeyBufSz - IN/OUT size of output buffer, size of RSA CA key
  45607. *
  45608. * eccClientCertBuf - output buffer for ECC cert
  45609. * eccClientCertBufSz - IN/OUT size of output buffer, size of ECC cert
  45610. * eccClientPrivKeyBuf - output buffer for ECC private key
  45611. * eccClientPrivKeyBufSz - IN/OUT size of output buffer, size of ECC private key
  45612. *
  45613. * Returns 0 on success, negative on error
  45614. */
  45615. static wc_test_ret_t pkcs7_load_certs_keys(
  45616. byte* rsaClientCertBuf, word32* rsaClientCertBufSz,
  45617. byte* rsaClientPrivKeyBuf, word32* rsaClientPrivKeyBufSz,
  45618. byte* rsaServerCertBuf, word32* rsaServerCertBufSz,
  45619. byte* rsaServerPrivKeyBuf, word32* rsaServerPrivKeyBufSz,
  45620. byte* rsaCaCertBuf, word32* rsaCaCertBufSz,
  45621. byte* rsaCaPrivKeyBuf, word32* rsaCaPrivKeyBufSz,
  45622. byte* eccClientCertBuf, word32* eccClientCertBufSz,
  45623. byte* eccClientPrivKeyBuf, word32* eccClientPrivKeyBufSz)
  45624. {
  45625. #ifndef NO_FILESYSTEM
  45626. XFILE certFile;
  45627. XFILE keyFile;
  45628. (void)certFile;
  45629. (void)keyFile;
  45630. #endif
  45631. #ifndef NO_RSA
  45632. if (rsaClientCertBuf == NULL || rsaClientCertBufSz == NULL ||
  45633. rsaClientPrivKeyBuf == NULL || rsaClientPrivKeyBufSz == NULL)
  45634. return BAD_FUNC_ARG;
  45635. #endif
  45636. #ifdef HAVE_ECC
  45637. if (eccClientCertBuf == NULL || eccClientCertBufSz == NULL ||
  45638. eccClientPrivKeyBuf == NULL || eccClientPrivKeyBufSz == NULL)
  45639. return BAD_FUNC_ARG;
  45640. #endif
  45641. /* RSA */
  45642. #ifndef NO_RSA
  45643. #ifdef USE_CERT_BUFFERS_1024
  45644. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_1024)
  45645. return WC_TEST_RET_ENC_NC;
  45646. XMEMCPY(rsaClientCertBuf, client_cert_der_1024,
  45647. sizeof_client_cert_der_1024);
  45648. *rsaClientCertBufSz = sizeof_client_cert_der_1024;
  45649. if (rsaServerCertBuf != NULL) {
  45650. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_1024)
  45651. return WC_TEST_RET_ENC_NC;
  45652. XMEMCPY(rsaServerCertBuf, server_cert_der_1024,
  45653. sizeof_server_cert_der_1024);
  45654. *rsaServerCertBufSz = sizeof_server_cert_der_1024;
  45655. }
  45656. if (rsaCaCertBuf != NULL) {
  45657. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_1024)
  45658. return WC_TEST_RET_ENC_NC;
  45659. XMEMCPY(rsaCaCertBuf, ca_cert_der_1024, sizeof_ca_cert_der_1024);
  45660. *rsaCaCertBufSz = sizeof_ca_cert_der_1024;
  45661. }
  45662. #elif defined(USE_CERT_BUFFERS_2048)
  45663. if (*rsaClientCertBufSz < (word32)sizeof_client_cert_der_2048)
  45664. return WC_TEST_RET_ENC_NC;
  45665. XMEMCPY(rsaClientCertBuf, client_cert_der_2048,
  45666. sizeof_client_cert_der_2048);
  45667. *rsaClientCertBufSz = sizeof_client_cert_der_2048;
  45668. if (rsaServerCertBuf != NULL) {
  45669. if (*rsaServerCertBufSz < (word32)sizeof_server_cert_der_2048)
  45670. return WC_TEST_RET_ENC_NC;
  45671. XMEMCPY(rsaServerCertBuf, server_cert_der_2048,
  45672. sizeof_server_cert_der_2048);
  45673. *rsaServerCertBufSz = sizeof_server_cert_der_2048;
  45674. }
  45675. if (rsaCaCertBuf != NULL) {
  45676. if (*rsaCaCertBufSz < (word32)sizeof_ca_cert_der_2048)
  45677. return WC_TEST_RET_ENC_NC;
  45678. XMEMCPY(rsaCaCertBuf, ca_cert_der_2048, sizeof_ca_cert_der_2048);
  45679. *rsaCaCertBufSz = sizeof_ca_cert_der_2048;
  45680. }
  45681. #else
  45682. certFile = XFOPEN(clientCert, "rb");
  45683. if (!certFile)
  45684. return WC_TEST_RET_ENC_ERRNO;
  45685. *rsaClientCertBufSz = (word32)XFREAD(rsaClientCertBuf, 1,
  45686. *rsaClientCertBufSz, certFile);
  45687. XFCLOSE(certFile);
  45688. if (*rsaClientCertBufSz == 0)
  45689. return WC_TEST_RET_ENC_ERRNO;
  45690. if (rsaServerCertBuf != NULL) {
  45691. certFile = XFOPEN(rsaServerCertDerFile, "rb");
  45692. if (!certFile)
  45693. return WC_TEST_RET_ENC_ERRNO;
  45694. *rsaServerCertBufSz = (word32)XFREAD(rsaServerCertBuf, 1,
  45695. *rsaServerCertBufSz, certFile);
  45696. XFCLOSE(certFile);
  45697. if (*rsaServerCertBufSz == 0)
  45698. return WC_TEST_RET_ENC_ERRNO;
  45699. }
  45700. if (rsaCaCertBuf != NULL) {
  45701. certFile = XFOPEN(rsaCaCertDerFile, "rb");
  45702. if (!certFile)
  45703. return WC_TEST_RET_ENC_ERRNO;
  45704. *rsaCaCertBufSz = (word32)XFREAD(rsaCaCertBuf, 1, *rsaCaCertBufSz,
  45705. certFile);
  45706. XFCLOSE(certFile);
  45707. if (*rsaCaCertBufSz == 0)
  45708. return WC_TEST_RET_ENC_ERRNO;
  45709. }
  45710. #endif
  45711. #ifdef USE_CERT_BUFFERS_1024
  45712. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_1024)
  45713. return WC_TEST_RET_ENC_NC;
  45714. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_1024,
  45715. sizeof_client_key_der_1024);
  45716. *rsaClientPrivKeyBufSz = sizeof_client_key_der_1024;
  45717. if (rsaServerPrivKeyBuf != NULL) {
  45718. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_1024)
  45719. return WC_TEST_RET_ENC_NC;
  45720. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_1024,
  45721. sizeof_server_key_der_1024);
  45722. *rsaServerPrivKeyBufSz = sizeof_server_key_der_1024;
  45723. }
  45724. if (rsaCaPrivKeyBuf != NULL) {
  45725. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_1024)
  45726. return WC_TEST_RET_ENC_NC;
  45727. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_1024, sizeof_ca_key_der_1024);
  45728. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_1024;
  45729. }
  45730. #elif defined(USE_CERT_BUFFERS_2048)
  45731. if (*rsaClientPrivKeyBufSz < (word32)sizeof_client_key_der_2048)
  45732. return WC_TEST_RET_ENC_NC;
  45733. XMEMCPY(rsaClientPrivKeyBuf, client_key_der_2048,
  45734. sizeof_client_key_der_2048);
  45735. *rsaClientPrivKeyBufSz = sizeof_client_key_der_2048;
  45736. if (rsaServerPrivKeyBuf != NULL) {
  45737. if (*rsaServerPrivKeyBufSz < (word32)sizeof_server_key_der_2048)
  45738. return WC_TEST_RET_ENC_NC;
  45739. XMEMCPY(rsaServerPrivKeyBuf, server_key_der_2048,
  45740. sizeof_server_key_der_2048);
  45741. *rsaServerPrivKeyBufSz = sizeof_server_key_der_2048;
  45742. }
  45743. if (rsaCaPrivKeyBuf != NULL) {
  45744. if (*rsaCaPrivKeyBufSz < (word32)sizeof_ca_key_der_2048)
  45745. return WC_TEST_RET_ENC_NC;
  45746. XMEMCPY(rsaCaPrivKeyBuf, ca_key_der_2048, sizeof_ca_key_der_2048);
  45747. *rsaCaPrivKeyBufSz = sizeof_ca_key_der_2048;
  45748. }
  45749. #else
  45750. keyFile = XFOPEN(clientKey, "rb");
  45751. if (!keyFile)
  45752. return WC_TEST_RET_ENC_ERRNO;
  45753. *rsaClientPrivKeyBufSz = (word32)XFREAD(rsaClientPrivKeyBuf, 1,
  45754. *rsaClientPrivKeyBufSz, keyFile);
  45755. XFCLOSE(keyFile);
  45756. if (*rsaClientPrivKeyBufSz == 0)
  45757. return WC_TEST_RET_ENC_ERRNO;
  45758. if (rsaServerPrivKeyBuf != NULL) {
  45759. keyFile = XFOPEN(rsaServerKeyDerFile, "rb");
  45760. if (!keyFile)
  45761. return WC_TEST_RET_ENC_ERRNO;
  45762. *rsaServerPrivKeyBufSz = (word32)XFREAD(rsaServerPrivKeyBuf, 1,
  45763. *rsaServerPrivKeyBufSz, keyFile);
  45764. XFCLOSE(keyFile);
  45765. if (*rsaServerPrivKeyBufSz == 0)
  45766. return WC_TEST_RET_ENC_ERRNO;
  45767. }
  45768. if (rsaCaPrivKeyBuf != NULL) {
  45769. keyFile = XFOPEN(rsaCaKeyFile, "rb");
  45770. if (!keyFile)
  45771. return WC_TEST_RET_ENC_ERRNO;
  45772. *rsaCaPrivKeyBufSz = (word32)XFREAD(rsaCaPrivKeyBuf, 1,
  45773. *rsaCaPrivKeyBufSz, keyFile);
  45774. XFCLOSE(keyFile);
  45775. if (*rsaCaPrivKeyBufSz == 0)
  45776. return WC_TEST_RET_ENC_ERRNO;
  45777. }
  45778. #endif /* USE_CERT_BUFFERS */
  45779. #endif /* NO_RSA */
  45780. /* ECC */
  45781. #ifdef HAVE_ECC
  45782. #ifdef USE_CERT_BUFFERS_256
  45783. if (*eccClientCertBufSz < (word32)sizeof_cliecc_cert_der_256)
  45784. return WC_TEST_RET_ENC_NC;
  45785. XMEMCPY(eccClientCertBuf, cliecc_cert_der_256, sizeof_cliecc_cert_der_256);
  45786. *eccClientCertBufSz = sizeof_cliecc_cert_der_256;
  45787. #else
  45788. certFile = XFOPEN(eccClientCert, "rb");
  45789. if (!certFile)
  45790. return WC_TEST_RET_ENC_ERRNO;
  45791. *eccClientCertBufSz = (word32)XFREAD(eccClientCertBuf, 1,
  45792. *eccClientCertBufSz, certFile);
  45793. XFCLOSE(certFile);
  45794. if (*eccClientCertBufSz == 0)
  45795. return WC_TEST_RET_ENC_ERRNO;
  45796. #endif /* USE_CERT_BUFFERS_256 */
  45797. #ifdef USE_CERT_BUFFERS_256
  45798. if (*eccClientPrivKeyBufSz < (word32)sizeof_ecc_clikey_der_256)
  45799. return WC_TEST_RET_ENC_NC;
  45800. XMEMCPY(eccClientPrivKeyBuf, ecc_clikey_der_256, sizeof_ecc_clikey_der_256);
  45801. *eccClientPrivKeyBufSz = sizeof_ecc_clikey_der_256;
  45802. #else
  45803. keyFile = XFOPEN(eccClientKey, "rb");
  45804. if (!keyFile)
  45805. return WC_TEST_RET_ENC_ERRNO;
  45806. *eccClientPrivKeyBufSz = (word32)XFREAD(eccClientPrivKeyBuf, 1,
  45807. *eccClientPrivKeyBufSz, keyFile);
  45808. XFCLOSE(keyFile);
  45809. if (*eccClientPrivKeyBufSz == 0)
  45810. return WC_TEST_RET_ENC_ERRNO;
  45811. #endif /* USE_CERT_BUFFERS_256 */
  45812. #endif /* HAVE_ECC */
  45813. #ifdef NO_RSA
  45814. (void)rsaClientCertBuf;
  45815. (void)rsaClientCertBufSz;
  45816. (void)rsaClientPrivKeyBuf;
  45817. (void)rsaClientPrivKeyBufSz;
  45818. (void)rsaServerCertBuf;
  45819. (void)rsaServerCertBufSz;
  45820. (void)rsaServerPrivKeyBuf;
  45821. (void)rsaServerPrivKeyBufSz;
  45822. (void)rsaCaCertBuf;
  45823. (void)rsaCaCertBufSz;
  45824. (void)rsaCaPrivKeyBuf;
  45825. (void)rsaCaPrivKeyBufSz;
  45826. #endif
  45827. #ifndef HAVE_ECC
  45828. (void)eccClientCertBuf;
  45829. (void)eccClientCertBufSz;
  45830. (void)eccClientPrivKeyBuf;
  45831. (void)eccClientPrivKeyBufSz;
  45832. #endif
  45833. #ifndef NO_FILESYSTEM
  45834. (void)certFile;
  45835. (void)keyFile;
  45836. #endif
  45837. return 0;
  45838. }
  45839. typedef struct {
  45840. const byte* content;
  45841. word32 contentSz;
  45842. int contentOID;
  45843. int encryptOID;
  45844. int keyWrapOID;
  45845. int keyAgreeOID;
  45846. byte* cert;
  45847. size_t certSz;
  45848. byte* privateKey;
  45849. word32 privateKeySz;
  45850. byte* optionalUkm;
  45851. word32 optionalUkmSz;
  45852. int ktriOptions; /* KTRI options flags */
  45853. int kariOptions; /* KARI options flags */
  45854. /* KEKRI specific */
  45855. const byte* secretKey; /* key, only for kekri RecipientInfo types */
  45856. word32 secretKeySz; /* size of secretKey, bytes */
  45857. const byte* secretKeyId; /* key identifier */
  45858. word32 secretKeyIdSz; /* size of key identifier, bytes */
  45859. void* timePtr; /* time_t pointer */
  45860. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  45861. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  45862. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  45863. word32 otherAttrSz; /* size of otherAttr, bytes */
  45864. int kekriOptions; /* KEKRI options flags */
  45865. /* PWRI specific */
  45866. const char* password;
  45867. word32 passwordSz;
  45868. const byte* salt;
  45869. word32 saltSz;
  45870. int kdfOID;
  45871. int hashOID;
  45872. int kdfIterations;
  45873. int pwriOptions; /* PWRI options flags */
  45874. /* ORI specific */
  45875. int isOri;
  45876. int oriOptions; /* ORI options flags */
  45877. const char* outFileName;
  45878. } pkcs7EnvelopedVector;
  45879. static const byte asnDataOid[] = {
  45880. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
  45881. };
  45882. /* ORI encrypt callback, responsible for encrypting content-encryption key (CEK)
  45883. * and giving wolfCrypt the value for oriOID and oriValue to place in
  45884. * OtherRecipientInfo.
  45885. *
  45886. * Returns 0 on success, negative upon error. */
  45887. static int myOriEncryptCb(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* oriType,
  45888. word32* oriTypeSz, byte* oriValue, word32* oriValueSz,
  45889. void* ctx)
  45890. {
  45891. int i;
  45892. /* make sure buffers are large enough */
  45893. if (*oriValueSz < (2 + cekSz))
  45894. return WC_TEST_RET_ENC_NC;
  45895. if (*oriTypeSz < sizeof(asnDataOid))
  45896. return WC_TEST_RET_ENC_NC;
  45897. /* our simple encryption algorithm will be take the bitwise complement */
  45898. oriValue[0] = 0x04; /*ASN OCTET STRING */
  45899. oriValue[1] = (byte)cekSz; /* length */
  45900. for (i = 0; i < (int)cekSz; i++) {
  45901. oriValue[2 + i] = ~cek[i];
  45902. }
  45903. *oriValueSz = 2 + cekSz;
  45904. /* set oriType to ASN.1 encoded data OID */
  45905. XMEMCPY(oriType, asnDataOid, sizeof(asnDataOid));
  45906. *oriTypeSz = sizeof(asnDataOid);
  45907. (void)pkcs7;
  45908. (void)ctx;
  45909. return 0;
  45910. }
  45911. /* ORI decrypt callback, responsible for providing a decrypted content
  45912. * encryption key (CEK) placed into decryptedKey and size placed into
  45913. * decryptedKeySz. oriOID and oriValue are given to the callback to help
  45914. * in decrypting the encrypted CEK.
  45915. *
  45916. * Returns 0 on success, negative upon error. */
  45917. static int myOriDecryptCb(wc_PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  45918. byte* oriValue, word32 oriValueSz, byte* decryptedKey,
  45919. word32* decryptedKeySz, void* ctx)
  45920. {
  45921. int i;
  45922. /* make sure oriType matches what we expect */
  45923. if (oriTypeSz != sizeof(asnDataOid))
  45924. return WC_TEST_RET_ENC_NC;
  45925. if (XMEMCMP(oriType, asnDataOid, sizeof(asnDataOid)) != 0)
  45926. return WC_TEST_RET_ENC_NC;
  45927. /* make sure decrypted buffer is large enough */
  45928. if (*decryptedKeySz < oriValueSz)
  45929. return WC_TEST_RET_ENC_NC;
  45930. /* decrypt encrypted CEK using simple bitwise complement,
  45931. only for example */
  45932. for (i = 0; i < (int)oriValueSz - 2; i++) {
  45933. decryptedKey[i] = ~oriValue[2 + i];
  45934. }
  45935. *decryptedKeySz = oriValueSz - 2;
  45936. (void)pkcs7;
  45937. (void)ctx;
  45938. return 0;
  45939. }
  45940. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  45941. /* returns 0 on success */
  45942. static int myDecryptionFunc(wc_PKCS7* pkcs7, int encryptOID, byte* iv, int ivSz,
  45943. byte* aad, word32 aadSz, byte* authTag, word32 authTagSz,
  45944. byte* in, int inSz, byte* out, void* usrCtx)
  45945. {
  45946. wc_test_ret_t ret;
  45947. int keyId = -1, keySz;
  45948. word32 keyIdSz = 8;
  45949. const byte* key;
  45950. byte keyIdRaw[8];
  45951. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45952. Aes *aes;
  45953. #else
  45954. Aes aes[1];
  45955. #endif
  45956. /* looking for KEY ID
  45957. * fwDecryptKeyID OID "1.2.840.113549.1.9.16.2.37
  45958. */
  45959. WOLFSSL_SMALL_STACK_STATIC const unsigned char OID[] = {
  45960. /* 0x06, 0x0B do not pass in tag and length */
  45961. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  45962. 0x01, 0x09, 0x10, 0x02, 0x25
  45963. };
  45964. WOLFSSL_SMALL_STACK_STATIC const byte defKey[] = {
  45965. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45966. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45967. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45968. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45969. };
  45970. WOLFSSL_SMALL_STACK_STATIC const byte altKey[] = {
  45971. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  45972. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  45973. };
  45974. /* test user context passed in */
  45975. if (usrCtx == NULL || *(int*)usrCtx != 1) {
  45976. return WC_TEST_RET_ENC_NC;
  45977. }
  45978. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  45979. if ((aes = (Aes *)XMALLOC(sizeof *aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)
  45980. return WC_TEST_RET_ENC_ERRNO;
  45981. #endif
  45982. /* if needing to find keyIdSz can call with NULL */
  45983. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), NULL,
  45984. &keyIdSz);
  45985. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  45986. printf("Unexpected error %d when getting keyIdSz\n", ret);
  45987. printf("Possibly no KEY ID attribute set\n");
  45988. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45989. }
  45990. else {
  45991. XMEMSET(keyIdRaw, 0, sizeof(keyIdRaw));
  45992. ret = wc_PKCS7_GetAttributeValue(pkcs7, OID, sizeof(OID), keyIdRaw,
  45993. &keyIdSz);
  45994. if (ret < 0) {
  45995. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  45996. }
  45997. if (keyIdSz < 3) {
  45998. printf("keyIdSz is smaller than expected\n");
  45999. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46000. }
  46001. if (keyIdSz > 2 + sizeof(int)) {
  46002. printf("example case was only expecting a keyId of int size\n");
  46003. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46004. }
  46005. /* keyIdRaw[0] OCTET TAG */
  46006. /* keyIdRaw[1] Length */
  46007. #ifdef BIG_ENDIAN_ORDER
  46008. if (keyIdRaw[1] == 0x01) {
  46009. keyId = 1;
  46010. }
  46011. #else
  46012. XMEMCPY(&keyId, keyIdRaw + 2, sizeof(keyId));
  46013. #endif
  46014. }
  46015. /* Use keyID here if found to select key and decrypt in HSM or in this
  46016. * example just select key and do software decryption */
  46017. if (keyId == 1) {
  46018. key = altKey;
  46019. keySz = sizeof(altKey);
  46020. }
  46021. else {
  46022. key = defKey;
  46023. keySz = sizeof(defKey);
  46024. }
  46025. switch (encryptOID) {
  46026. #ifdef WOLFSSL_AES_256
  46027. case AES256CBCb:
  46028. if ((keySz != 32 ) || (ivSz != AES_BLOCK_SIZE))
  46029. WARNING_OUT(BAD_FUNC_ARG, out);
  46030. break;
  46031. #endif
  46032. #ifdef WOLFSSL_AES_128
  46033. case AES128CBCb:
  46034. if ((keySz != 16 ) || (ivSz != AES_BLOCK_SIZE))
  46035. ERROR_OUT(BAD_FUNC_ARG, out);
  46036. break;
  46037. #endif
  46038. default:
  46039. printf("Unsupported content cipher type for example");
  46040. ERROR_OUT(ALGO_ID_E, out);
  46041. };
  46042. ret = wc_AesInit(aes, HEAP_HINT, INVALID_DEVID);
  46043. if (ret == 0) {
  46044. ret = wc_AesSetKey(aes, key, (word32)keySz, iv, AES_DECRYPTION);
  46045. if (ret == 0)
  46046. ret = wc_AesCbcDecrypt(aes, out, in, (word32)inSz);
  46047. wc_AesFree(aes);
  46048. }
  46049. out:
  46050. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  46051. XFREE(aes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46052. #endif
  46053. (void)aad;
  46054. (void)aadSz;
  46055. (void)authTag;
  46056. (void)authTagSz;
  46057. return (int)ret;
  46058. }
  46059. #endif /* !NO_AES && HAVE_AES_CBC */
  46060. #define PKCS7_BUF_SIZE 2048
  46061. static wc_test_ret_t pkcs7enveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46062. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46063. byte* eccCert, word32 eccCertSz,
  46064. byte* eccPrivKey, word32 eccPrivKeySz)
  46065. {
  46066. wc_test_ret_t ret = 0;
  46067. int testSz = 0, i;
  46068. int envelopedSz, decodedSz;
  46069. byte *enveloped = NULL;
  46070. byte *decoded = NULL;
  46071. wc_PKCS7* pkcs7 = NULL;
  46072. #ifdef ECC_TIMING_RESISTANT
  46073. WC_RNG rng;
  46074. #endif
  46075. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46076. XFILE pkcs7File;
  46077. #endif
  46078. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46079. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46080. 0x72,0x6c,0x64
  46081. };
  46082. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256) && \
  46083. defined(HAVE_ECC) && defined(WOLFSSL_SHA512)
  46084. byte optionalUkm[] = {
  46085. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46086. };
  46087. #endif /* !NO_AES */
  46088. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128) && \
  46089. !defined(NO_SHA)
  46090. /* encryption key for kekri recipient types */
  46091. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46092. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46093. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46094. };
  46095. /* encryption key identifier */
  46096. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46097. 0x02,0x02,0x03,0x04
  46098. };
  46099. #endif
  46100. #if !defined(NO_PWDBASED) && !defined(NO_SHA) && \
  46101. !defined(NO_AES) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46102. #ifndef HAVE_FIPS
  46103. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password"; /* NOTE: Password is too short for FIPS */
  46104. #else
  46105. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46106. #endif
  46107. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46108. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46109. };
  46110. #endif
  46111. #define MAX_TESTVECTORS_LEN 13
  46112. #define ADD_PKCS7ENVELOPEDVECTOR(...) { \
  46113. pkcs7EnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46114. if (testSz == MAX_TESTVECTORS_LEN) { \
  46115. ret = WC_TEST_RET_ENC_NC; \
  46116. goto out; \
  46117. } \
  46118. XMEMCPY(&testVectors[testSz++], &_this_vector, sizeof _this_vector);\
  46119. }
  46120. pkcs7EnvelopedVector *testVectors = NULL;
  46121. #ifdef ECC_TIMING_RESISTANT
  46122. XMEMSET(&rng, 0, sizeof(rng));
  46123. #endif
  46124. testVectors = (pkcs7EnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46125. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46126. if (testVectors == NULL) {
  46127. ret = WC_TEST_RET_ENC_ERRNO;
  46128. goto out;
  46129. }
  46130. {
  46131. /* key transport key encryption technique */
  46132. #ifndef NO_RSA
  46133. #ifndef NO_DES3
  46134. ADD_PKCS7ENVELOPEDVECTOR(
  46135. data, (word32)sizeof(data), DATA, DES3b, 0, 0, rsaCert, rsaCertSz,
  46136. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46137. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46138. "pkcs7envelopedDataDES3.der");
  46139. #endif
  46140. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46141. #ifdef WOLFSSL_AES_128
  46142. ADD_PKCS7ENVELOPEDVECTOR(
  46143. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, rsaCert, rsaCertSz,
  46144. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46145. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46146. "pkcs7envelopedDataAES128CBC.der");
  46147. #endif
  46148. #ifdef WOLFSSL_AES_192
  46149. ADD_PKCS7ENVELOPEDVECTOR(
  46150. data, (word32)sizeof(data), DATA, AES192CBCb, 0, 0, rsaCert, rsaCertSz,
  46151. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46152. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46153. "pkcs7envelopedDataAES192CBC.der");
  46154. #endif
  46155. #ifdef WOLFSSL_AES_256
  46156. ADD_PKCS7ENVELOPEDVECTOR(
  46157. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46158. rsaPrivKey, rsaPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL,
  46159. 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46160. "pkcs7envelopedDataAES256CBC.der");
  46161. /* explicitly using SKID for SubjectKeyIdentifier */
  46162. ADD_PKCS7ENVELOPEDVECTOR(
  46163. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46164. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_SKID, 0, NULL, 0, NULL, 0, NULL,
  46165. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46166. "pkcs7envelopedDataAES256CBC_SKID.der");
  46167. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46168. ADD_PKCS7ENVELOPEDVECTOR(
  46169. data, (word32)sizeof(data), DATA, AES256CBCb, 0, 0, rsaCert, rsaCertSz,
  46170. rsaPrivKey, rsaPrivKeySz, NULL, 0, CMS_ISSUER_AND_SERIAL_NUMBER, 0,
  46171. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46172. 0, 0, 0, 0, "pkcs7envelopedDataAES256CBC_IANDS.der");
  46173. #endif
  46174. #endif /* !NO_AES && HAVE_AES_CBC */
  46175. #endif
  46176. /* key agreement key encryption technique*/
  46177. #ifdef HAVE_ECC
  46178. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46179. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46180. ADD_PKCS7ENVELOPEDVECTOR(
  46181. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP,
  46182. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46183. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46184. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46185. "pkcs7envelopedDataAES128CBC_ECDH_SHA1KDF.der");
  46186. #endif
  46187. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46188. ADD_PKCS7ENVELOPEDVECTOR(
  46189. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46190. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46191. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46192. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46193. "pkcs7envelopedDataAES256CBC_ECDH_SHA256KDF.der");
  46194. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46195. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46196. ADD_PKCS7ENVELOPEDVECTOR(
  46197. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46198. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46199. eccPrivKeySz, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0,
  46200. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46201. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF.der");
  46202. /* with optional user keying material (ukm) */
  46203. ADD_PKCS7ENVELOPEDVECTOR(
  46204. data, (word32)sizeof(data), DATA, AES256CBCb, AES256_WRAP,
  46205. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46206. eccPrivKeySz, optionalUkm, sizeof(optionalUkm), 0, 0, NULL, 0,
  46207. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46208. "pkcs7envelopedDataAES256CBC_ECDH_SHA512KDF_ukm.der");
  46209. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46210. #endif /* !NO_AES && HAVE_AES_CBC */
  46211. #endif
  46212. /* kekri (KEKRecipientInfo) recipient types */
  46213. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  46214. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46215. ADD_PKCS7ENVELOPEDVECTOR(
  46216. data, (word32)sizeof(data), DATA, AES128CBCb, AES128_WRAP, 0,
  46217. NULL, 0, NULL, 0, NULL, 0, 0, 0, secretKey, sizeof(secretKey),
  46218. secretKeyId, sizeof(secretKeyId), NULL, NULL, 0, NULL, 0,
  46219. 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0,
  46220. "pkcs7envelopedDataAES128CBC_KEKRI.der");
  46221. #endif
  46222. #endif /* !NO_AES && HAVE_AES_CBC */
  46223. /* pwri (PasswordRecipientInfo) recipient types */
  46224. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  46225. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46226. ADD_PKCS7ENVELOPEDVECTOR(
  46227. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0,
  46228. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46229. NULL, 0, NULL, NULL, 0, NULL, 0, 0, password,
  46230. (word32)XSTRLEN(password), salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46231. 0, 0, 0, "pkcs7envelopedDataAES128CBC_PWRI.der");
  46232. #endif
  46233. #endif
  46234. #if !defined(NO_AES) && defined(HAVE_AES_CBC) && !defined(NO_AES_128)
  46235. /* ori (OtherRecipientInfo) recipient types */
  46236. ADD_PKCS7ENVELOPEDVECTOR(
  46237. data, (word32)sizeof(data), DATA, AES128CBCb, 0, 0, NULL, 0, NULL, 0,
  46238. NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0,
  46239. NULL, 0, 0, 0, 0, 0, 1, 0, "pkcs7envelopedDataAES128CBC_ORI.der");
  46240. #endif
  46241. };
  46242. #undef MAX_TESTVECTORS_LEN
  46243. #undef ADD_PKCS7ENVELOPEDVECTOR
  46244. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46245. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46246. if ((! enveloped) || (! decoded)) {
  46247. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46248. }
  46249. #ifdef ECC_TIMING_RESISTANT
  46250. #ifndef HAVE_FIPS
  46251. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46252. #else
  46253. ret = wc_InitRng(&rng);
  46254. #endif
  46255. if (ret != 0)
  46256. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46257. #endif
  46258. for (i = 0; i < testSz; i++) {
  46259. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46260. #ifdef WOLFSSL_ASYNC_CRYPT
  46261. INVALID_DEVID /* async PKCS7 is not supported */
  46262. #else
  46263. devId
  46264. #endif
  46265. );
  46266. if (pkcs7 == NULL) {
  46267. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46268. }
  46269. if (testVectors[i].secretKey != NULL) {
  46270. /* KEKRI recipient type */
  46271. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46272. if (ret != 0)
  46273. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46274. pkcs7->content = (byte*)testVectors[i].content;
  46275. pkcs7->contentSz = testVectors[i].contentSz;
  46276. pkcs7->contentOID = testVectors[i].contentOID;
  46277. pkcs7->encryptOID = testVectors[i].encryptOID;
  46278. pkcs7->ukm = testVectors[i].optionalUkm;
  46279. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46280. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46281. (byte *)testVectors[i].secretKey, testVectors[i].secretKeySz,
  46282. (byte *)testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46283. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46284. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46285. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46286. if (ret < 0) {
  46287. wc_PKCS7_Free(pkcs7);
  46288. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46289. }
  46290. /* set key, for decryption */
  46291. ret = wc_PKCS7_SetKey(pkcs7, (byte *)testVectors[i].secretKey,
  46292. testVectors[i].secretKeySz);
  46293. if (ret != 0) {
  46294. wc_PKCS7_Free(pkcs7);
  46295. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46296. }
  46297. } else if (testVectors[i].password != NULL) {
  46298. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46299. /* PWRI recipient type */
  46300. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46301. if (ret != 0)
  46302. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46303. pkcs7->content = (byte*)testVectors[i].content;
  46304. pkcs7->contentSz = testVectors[i].contentSz;
  46305. pkcs7->contentOID = testVectors[i].contentOID;
  46306. pkcs7->encryptOID = testVectors[i].encryptOID;
  46307. pkcs7->ukm = testVectors[i].optionalUkm;
  46308. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46309. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46310. (byte *)testVectors[i].password, testVectors[i].passwordSz,
  46311. (byte *)testVectors[i].salt, testVectors[i].saltSz,
  46312. testVectors[i].kdfOID,
  46313. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46314. testVectors[i].encryptOID, testVectors[i].pwriOptions);
  46315. if (ret < 0) {
  46316. wc_PKCS7_Free(pkcs7);
  46317. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46318. }
  46319. /* set password, for decryption */
  46320. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46321. testVectors[i].passwordSz);
  46322. if (ret < 0) {
  46323. wc_PKCS7_Free(pkcs7);
  46324. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46325. }
  46326. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46327. } else if (testVectors[i].isOri == 1) {
  46328. /* ORI recipient type */
  46329. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46330. if (ret != 0)
  46331. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46332. pkcs7->content = (byte*)testVectors[i].content;
  46333. pkcs7->contentSz = testVectors[i].contentSz;
  46334. pkcs7->contentOID = testVectors[i].contentOID;
  46335. pkcs7->encryptOID = testVectors[i].encryptOID;
  46336. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46337. testVectors[i].oriOptions);
  46338. if (ret < 0) {
  46339. wc_PKCS7_Free(pkcs7);
  46340. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46341. }
  46342. /* set decrypt callback for decryption */
  46343. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46344. if (ret < 0) {
  46345. wc_PKCS7_Free(pkcs7);
  46346. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46347. }
  46348. } else {
  46349. /* KTRI or KARI recipient types */
  46350. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46351. if (ret != 0)
  46352. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46353. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46354. (word32)testVectors[i].certSz);
  46355. if (ret != 0) {
  46356. wc_PKCS7_Free(pkcs7);
  46357. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46358. }
  46359. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46360. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46361. pkcs7->privateKey = testVectors[i].privateKey;
  46362. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46363. pkcs7->content = (byte*)testVectors[i].content;
  46364. pkcs7->contentSz = testVectors[i].contentSz;
  46365. pkcs7->contentOID = testVectors[i].contentOID;
  46366. pkcs7->encryptOID = testVectors[i].encryptOID;
  46367. pkcs7->ukm = testVectors[i].optionalUkm;
  46368. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46369. /* set SubjectIdentifier type for KTRI types */
  46370. if (testVectors[i].ktriOptions & CMS_SKID) {
  46371. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46372. if (ret != 0) {
  46373. wc_PKCS7_Free(pkcs7);
  46374. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46375. }
  46376. } else if (testVectors[i].ktriOptions &
  46377. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46378. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46379. CMS_ISSUER_AND_SERIAL_NUMBER);
  46380. if (ret != 0) {
  46381. wc_PKCS7_Free(pkcs7);
  46382. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46383. }
  46384. }
  46385. }
  46386. #ifdef ECC_TIMING_RESISTANT
  46387. pkcs7->rng = &rng;
  46388. #endif
  46389. /* encode envelopedData */
  46390. envelopedSz = wc_PKCS7_EncodeEnvelopedData(pkcs7, enveloped,
  46391. PKCS7_BUF_SIZE);
  46392. if (envelopedSz <= 0) {
  46393. wc_PKCS7_Free(pkcs7);
  46394. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  46395. }
  46396. /* decode envelopedData */
  46397. pkcs7->contentOID = 0;
  46398. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped, (word32)envelopedSz,
  46399. decoded, PKCS7_BUF_SIZE);
  46400. if (pkcs7->contentOID != testVectors[i].contentOID ||
  46401. decodedSz <= 0) {
  46402. wc_PKCS7_Free(pkcs7);
  46403. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46404. }
  46405. /* test decode result */
  46406. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  46407. wc_PKCS7_Free(pkcs7);
  46408. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46409. }
  46410. #ifndef NO_PKCS7_STREAM
  46411. { /* test reading byte by byte */
  46412. int z;
  46413. for (z = 0; z < envelopedSz; z++) {
  46414. decodedSz = wc_PKCS7_DecodeEnvelopedData(pkcs7, enveloped + z, 1,
  46415. decoded, PKCS7_BUF_SIZE);
  46416. if (decodedSz <= 0 &&
  46417. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  46418. {
  46419. printf("unexpected error %d\n", decodedSz);
  46420. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  46421. }
  46422. }
  46423. /* test decode result */
  46424. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  46425. printf("stream read compare failed\n");
  46426. wc_PKCS7_Free(pkcs7);
  46427. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46428. }
  46429. }
  46430. #endif
  46431. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46432. /* output pkcs7 envelopedData for external testing */
  46433. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  46434. if (!pkcs7File) {
  46435. wc_PKCS7_Free(pkcs7);
  46436. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46437. }
  46438. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  46439. XFCLOSE(pkcs7File);
  46440. if (ret != envelopedSz) {
  46441. wc_PKCS7_Free(pkcs7);
  46442. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46443. } else {
  46444. /* reset ret to 0 for success */
  46445. ret = 0;
  46446. }
  46447. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  46448. wc_PKCS7_Free(pkcs7);
  46449. pkcs7 = NULL;
  46450. }
  46451. #ifdef ECC_TIMING_RESISTANT
  46452. wc_FreeRng(&rng);
  46453. #endif
  46454. (void)eccCert;
  46455. (void)eccCertSz;
  46456. (void)eccPrivKey;
  46457. (void)eccPrivKeySz;
  46458. (void)rsaCert;
  46459. (void)rsaCertSz;
  46460. (void)rsaPrivKey;
  46461. (void)rsaPrivKeySz;
  46462. out:
  46463. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46464. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46465. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46466. return ret;
  46467. }
  46468. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7enveloped_test(void)
  46469. {
  46470. wc_test_ret_t ret = 0;
  46471. byte* rsaCert = NULL;
  46472. byte* rsaPrivKey = NULL;
  46473. word32 rsaCertSz = 0;
  46474. word32 rsaPrivKeySz = 0;
  46475. byte* eccCert = NULL;
  46476. byte* eccPrivKey = NULL;
  46477. word32 eccCertSz = 0;
  46478. word32 eccPrivKeySz = 0;
  46479. WOLFSSL_ENTER("pkcs7enveloped_test");
  46480. #ifndef NO_RSA
  46481. /* read client RSA cert and key in DER format */
  46482. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46483. if (rsaCert == NULL)
  46484. return WC_TEST_RET_ENC_ERRNO;
  46485. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46486. if (rsaPrivKey == NULL) {
  46487. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46488. return WC_TEST_RET_ENC_NC;
  46489. }
  46490. rsaCertSz = FOURK_BUF;
  46491. rsaPrivKeySz = FOURK_BUF;
  46492. #endif /* NO_RSA */
  46493. #ifdef HAVE_ECC
  46494. /* read client ECC cert and key in DER format */
  46495. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46496. if (eccCert == NULL) {
  46497. #ifndef NO_RSA
  46498. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46499. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46500. #endif
  46501. return WC_TEST_RET_ENC_NC;
  46502. }
  46503. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46504. if (eccPrivKey == NULL) {
  46505. #ifndef NO_RSA
  46506. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46507. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46508. #endif
  46509. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46510. return WC_TEST_RET_ENC_NC;
  46511. }
  46512. eccCertSz = FOURK_BUF;
  46513. eccPrivKeySz = FOURK_BUF;
  46514. #endif /* HAVE_ECC */
  46515. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  46516. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  46517. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  46518. eccPrivKey, &eccPrivKeySz);
  46519. if (ret < 0) {
  46520. #ifndef NO_RSA
  46521. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46522. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46523. #endif
  46524. #ifdef HAVE_ECC
  46525. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46526. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46527. #endif
  46528. return WC_TEST_RET_ENC_EC(ret);
  46529. }
  46530. ret = pkcs7enveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  46531. rsaPrivKey, (word32)rsaPrivKeySz,
  46532. eccCert, (word32)eccCertSz,
  46533. eccPrivKey, (word32)eccPrivKeySz);
  46534. #ifndef NO_RSA
  46535. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46536. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46537. #endif
  46538. #ifdef HAVE_ECC
  46539. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46540. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46541. #endif
  46542. return ret;
  46543. }
  46544. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  46545. typedef struct {
  46546. const byte* content;
  46547. word32 contentSz;
  46548. int contentOID;
  46549. int encryptOID;
  46550. int keyWrapOID;
  46551. int keyAgreeOID;
  46552. byte* cert;
  46553. size_t certSz;
  46554. byte* privateKey;
  46555. word32 privateKeySz;
  46556. PKCS7Attrib* authAttribs;
  46557. word32 authAttribsSz;
  46558. PKCS7Attrib* unauthAttribs;
  46559. word32 unauthAttribsSz;
  46560. /* KARI / KTRI specific */
  46561. byte* optionalUkm;
  46562. word32 optionalUkmSz;
  46563. int ktriOptions; /* KTRI options flags */
  46564. int kariOptions; /* KARI options flags */
  46565. /* KEKRI specific */
  46566. byte* secretKey; /* key, only for kekri RecipientInfo types */
  46567. word32 secretKeySz; /* size of secretKey, bytes */
  46568. byte* secretKeyId; /* key identifier */
  46569. word32 secretKeyIdSz; /* size of key identifier, bytes */
  46570. void* timePtr; /* time_t pointer */
  46571. byte* otherAttrOID; /* OPTIONAL, other attribute OID */
  46572. word32 otherAttrOIDSz; /* size of otherAttrOID, bytes */
  46573. byte* otherAttr; /* OPTIONAL, other attribute, ASN.1 encoded */
  46574. word32 otherAttrSz; /* size of otherAttr, bytes */
  46575. int kekriOptions; /* KEKRI options flags */
  46576. /* PWRI specific */
  46577. char* password; /* password */
  46578. word32 passwordSz; /* password size, bytes */
  46579. byte* salt; /* KDF salt */
  46580. word32 saltSz; /* KDF salt size, bytes */
  46581. int kdfOID; /* KDF OID */
  46582. int hashOID; /* KDF hash algorithm OID */
  46583. int kdfIterations; /* KDF iterations */
  46584. int kekEncryptOID; /* KEK encryption algorithm OID */
  46585. int pwriOptions; /* PWRI options flags */
  46586. /* ORI specific */
  46587. int isOri;
  46588. int oriOptions; /* ORI options flags */
  46589. const char* outFileName;
  46590. } pkcs7AuthEnvelopedVector;
  46591. static wc_test_ret_t pkcs7authenveloped_run_vectors(byte* rsaCert, word32 rsaCertSz,
  46592. byte* rsaPrivKey, word32 rsaPrivKeySz,
  46593. byte* eccCert, word32 eccCertSz,
  46594. byte* eccPrivKey, word32 eccPrivKeySz)
  46595. {
  46596. wc_test_ret_t ret = 0;
  46597. int testSz = 0, i;
  46598. int envelopedSz, decodedSz;
  46599. byte *enveloped = NULL;
  46600. byte *decoded = NULL;
  46601. WC_RNG rng;
  46602. wc_PKCS7* pkcs7;
  46603. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  46604. XFILE pkcs7File;
  46605. #endif
  46606. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  46607. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  46608. 0x72,0x6c,0x64
  46609. };
  46610. byte senderNonce[PKCS7_NONCE_SZ + 2];
  46611. #ifdef HAVE_ECC
  46612. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46613. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46614. WOLFSSL_SMALL_STACK_STATIC const byte senderNonceOid[] =
  46615. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  46616. 0x09, 0x05 };
  46617. PKCS7Attrib attribs[] =
  46618. {
  46619. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  46620. sizeof(senderNonce) }
  46621. };
  46622. #endif
  46623. #endif
  46624. #endif
  46625. #if !defined(NO_AES) && defined(WOLFSSL_AES_256) && defined(HAVE_ECC) && \
  46626. defined(WOLFSSL_SHA512) && defined(HAVE_AESGCM)
  46627. WOLFSSL_SMALL_STACK_STATIC const byte optionalUkm[] = {
  46628. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46629. };
  46630. #endif /* !NO_AES */
  46631. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46632. /* encryption key for kekri recipient types */
  46633. WOLFSSL_SMALL_STACK_STATIC const byte secretKey[] = {
  46634. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  46635. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07
  46636. };
  46637. /* encryption key identifier */
  46638. WOLFSSL_SMALL_STACK_STATIC const byte secretKeyId[] = {
  46639. 0x02,0x02,0x03,0x04
  46640. };
  46641. #endif
  46642. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM) && \
  46643. !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46644. #ifndef HAVE_FIPS
  46645. WOLFSSL_SMALL_STACK_STATIC const char password[] = "password";
  46646. #else
  46647. WOLFSSL_SMALL_STACK_STATIC const char password[] = "passwordFIPS_MODE";
  46648. #endif
  46649. WOLFSSL_SMALL_STACK_STATIC const byte salt[] = {
  46650. 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12
  46651. };
  46652. #endif
  46653. #define MAX_TESTVECTORS_LEN 20
  46654. #define ADD_PKCS7AUTHENVELOPEDVECTOR(...) { \
  46655. pkcs7AuthEnvelopedVector _this_vector = { __VA_ARGS__ }; \
  46656. if (testSz == MAX_TESTVECTORS_LEN) { \
  46657. ret = WC_TEST_RET_ENC_NC; \
  46658. goto out; \
  46659. } \
  46660. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  46661. sizeof _this_vector); \
  46662. }
  46663. pkcs7AuthEnvelopedVector *testVectors = NULL;
  46664. XMEMSET(&rng, 0, sizeof(rng));
  46665. testVectors = (pkcs7AuthEnvelopedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  46666. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46667. if (testVectors == NULL) {
  46668. ret = WC_TEST_RET_ENC_ERRNO;
  46669. goto out;
  46670. }
  46671. {
  46672. /* key transport key encryption technique */
  46673. #ifndef NO_RSA
  46674. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46675. #ifdef WOLFSSL_AES_128
  46676. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46677. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, rsaCert, rsaCertSz,
  46678. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46679. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46680. 0, 0, "pkcs7authEnvelopedDataAES128GCM.der");
  46681. #endif
  46682. #ifdef WOLFSSL_AES_192
  46683. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46684. data, (word32)sizeof(data), DATA, AES192GCMb, 0, 0, rsaCert, rsaCertSz,
  46685. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46686. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46687. 0, 0, "pkcs7authEnvelopedDataAES192GCM.der");
  46688. #endif
  46689. #ifdef WOLFSSL_AES_256
  46690. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46691. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46692. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46693. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0,
  46694. 0, 0, "pkcs7authEnvelopedDataAES256GCM.der");
  46695. /* test with contentType set to FirmwarePkgData */
  46696. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46697. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, 0, 0,
  46698. rsaCert, rsaCertSz, rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL,
  46699. 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL,
  46700. 0, 0, 0, 0, 0, 0, 0, 0,
  46701. "pkcs7authEnvelopedDataAES256GCM_firmwarePkgData.der");
  46702. /* explicitly using SKID for SubjectKeyIdentifier */
  46703. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46704. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46705. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0, CMS_SKID, 0,
  46706. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0,
  46707. 0, 0, 0, 0, 0, "pkcs7authEnvelopedDataAES256GCM_SKID.der");
  46708. /* explicitly using IssuerAndSerialNumber for SubjectKeyIdentifier */
  46709. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46710. data, (word32)sizeof(data), DATA, AES256GCMb, 0, 0, rsaCert, rsaCertSz,
  46711. rsaPrivKey, rsaPrivKeySz, NULL, 0, NULL, 0, NULL, 0,
  46712. CMS_ISSUER_AND_SERIAL_NUMBER, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46713. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46714. "pkcs7authEnvelopedDataAES256GCM_IANDS.der");
  46715. #endif
  46716. #else
  46717. (void)rsaCert;
  46718. (void)rsaCertSz;
  46719. (void)rsaPrivKey;
  46720. (void)rsaPrivKeySz;
  46721. #endif /* !NO_AES && !HAVE_AESGCM */
  46722. #endif
  46723. /* key agreement key encryption technique*/
  46724. #ifdef HAVE_ECC
  46725. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46726. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46727. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46728. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP,
  46729. dhSinglePass_stdDH_sha1kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46730. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46731. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46732. "pkcs7authEnvelopedDataAES128GCM_ECDH_SHA1KDF.der");
  46733. #endif
  46734. #if !defined(NO_SHA256) && defined(WOLFSSL_AES_256)
  46735. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46736. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46737. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46738. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0,
  46739. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46740. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF.der");
  46741. /* with authenticated attributes */
  46742. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46743. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46744. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46745. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46746. NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46747. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46748. 0, 0, 0,
  46749. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_authAttribs.der");
  46750. /* with unauthenticated attributes */
  46751. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46752. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46753. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46754. eccPrivKeySz, NULL, 0, attribs,
  46755. (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0, NULL, 0,
  46756. NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0,
  46757. 0, 0, 0,
  46758. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_unauthAttribs.der");
  46759. /* with authenticated AND unauthenticated attributes */
  46760. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46761. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46762. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46763. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46764. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46765. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46766. 0, 0, 0, 0, 0, 0,
  46767. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_bothAttribs.der");
  46768. /* with authenticated AND unauthenticated attributes AND
  46769. * contentType of FirmwarePkgData */
  46770. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46771. data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256GCMb, AES256_WRAP,
  46772. dhSinglePass_stdDH_sha256kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46773. eccPrivKeySz, attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)),
  46774. attribs, (sizeof(attribs) / sizeof(PKCS7Attrib)), NULL, 0, 0, 0,
  46775. NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46776. 0, 0, 0, 0, 0, 0,
  46777. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA256KDF_fw_bothAttribs.der");
  46778. #endif /* NO_SHA256 && WOLFSSL_AES_256 */
  46779. #if defined(WOLFSSL_SHA512) && defined(WOLFSSL_AES_256)
  46780. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46781. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46782. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46783. eccPrivKeySz, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL,
  46784. NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46785. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF.der");
  46786. /* with optional user keying material (ukm) */
  46787. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46788. data, (word32)sizeof(data), DATA, AES256GCMb, AES256_WRAP,
  46789. dhSinglePass_stdDH_sha512kdf_scheme, eccCert, eccCertSz, eccPrivKey,
  46790. eccPrivKeySz, NULL, 0, NULL, 0, (byte *)optionalUkm, sizeof(optionalUkm), 0,
  46791. 0, NULL, 0, NULL, 0, NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0,
  46792. 0, 0, 0, 0, 0, 0,
  46793. "pkcs7authEnvelopedDataAES256GCM_ECDH_SHA512KDF_ukm.der");
  46794. #endif /* WOLFSSL_SHA512 && WOLFSSL_AES_256 */
  46795. #endif /* !NO_AES && HAVE_AESGCM */
  46796. #endif
  46797. /* kekri (KEKRecipientInfo) recipient types */
  46798. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46799. #if !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  46800. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46801. data, (word32)sizeof(data), DATA, AES128GCMb, AES128_WRAP, 0,
  46802. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0,
  46803. (byte *)secretKey, sizeof(secretKey), (byte *)secretKeyId, sizeof(secretKeyId),
  46804. NULL, NULL, 0, NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0,
  46805. "pkcs7authEnvelopedDataAES128GCM_KEKRI.der");
  46806. #endif
  46807. #endif
  46808. /* pwri (PasswordRecipientInfo) recipient types */
  46809. #if !defined(NO_PWDBASED) && !defined(NO_AES) && defined(HAVE_AESGCM)
  46810. #if !defined(NO_SHA) && defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_128)
  46811. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46812. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0,
  46813. NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0,
  46814. NULL, 0, NULL, NULL, 0, NULL, 0, 0, (char *)password,
  46815. (word32)XSTRLEN(password), (byte *)salt, sizeof(salt), PBKDF2_OID, WC_SHA, 5,
  46816. AES128CBCb, 0, 0, 0, "pkcs7authEnvelopedDataAES128GCM_PWRI.der");
  46817. #endif
  46818. #endif
  46819. #if !defined(NO_AES) && defined(HAVE_AESGCM)
  46820. #ifdef WOLFSSL_AES_128
  46821. /* ori (OtherRecipientInfo) recipient types */
  46822. ADD_PKCS7AUTHENVELOPEDVECTOR(
  46823. data, (word32)sizeof(data), DATA, AES128GCMb, 0, 0, NULL, 0, NULL, 0,
  46824. NULL, 0, NULL, 0, NULL, 0, 0, 0, NULL, 0, NULL, 0, NULL, NULL, 0,
  46825. NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0, 0, 0, 1, 0,
  46826. "pkcs7authEnvelopedDataAES128GCM_ORI.der");
  46827. #endif
  46828. #endif
  46829. }
  46830. #undef MAX_TESTVECTORS_LEN
  46831. #undef ADD_PKCS7AUTHENVELOPEDVECTOR
  46832. enveloped = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46833. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  46834. if ((! enveloped) || (! decoded)) {
  46835. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  46836. }
  46837. /* generate senderNonce */
  46838. {
  46839. #ifndef HAVE_FIPS
  46840. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  46841. #else
  46842. ret = wc_InitRng(&rng);
  46843. #endif
  46844. if (ret != 0)
  46845. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46846. senderNonce[0] = 0x04;
  46847. senderNonce[1] = PKCS7_NONCE_SZ;
  46848. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  46849. if (ret != 0) {
  46850. wc_FreeRng(&rng);
  46851. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46852. }
  46853. }
  46854. for (i = 0; i < testSz; i++) {
  46855. pkcs7 = wc_PKCS7_New(HEAP_HINT,
  46856. #ifdef WOLFSSL_ASYNC_CRYPT
  46857. INVALID_DEVID /* async PKCS7 is not supported */
  46858. #else
  46859. devId
  46860. #endif
  46861. );
  46862. if (pkcs7 == NULL) {
  46863. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  46864. }
  46865. if (testVectors[i].secretKey != NULL) {
  46866. /* KEKRI recipient type */
  46867. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46868. if (ret != 0)
  46869. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46870. pkcs7->content = (byte*)testVectors[i].content;
  46871. pkcs7->contentSz = testVectors[i].contentSz;
  46872. pkcs7->contentOID = testVectors[i].contentOID;
  46873. pkcs7->encryptOID = testVectors[i].encryptOID;
  46874. pkcs7->ukm = testVectors[i].optionalUkm;
  46875. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46876. pkcs7->authAttribs = testVectors[i].authAttribs;
  46877. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46878. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46879. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46880. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, testVectors[i].keyWrapOID,
  46881. testVectors[i].secretKey, testVectors[i].secretKeySz,
  46882. testVectors[i].secretKeyId, testVectors[i].secretKeyIdSz,
  46883. testVectors[i].timePtr, testVectors[i].otherAttrOID,
  46884. testVectors[i].otherAttrOIDSz, testVectors[i].otherAttr,
  46885. testVectors[i].otherAttrSz, testVectors[i].kekriOptions);
  46886. if (ret < 0) {
  46887. wc_PKCS7_Free(pkcs7);
  46888. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46889. }
  46890. /* set key, for decryption */
  46891. ret = wc_PKCS7_SetKey(pkcs7, testVectors[i].secretKey,
  46892. testVectors[i].secretKeySz);
  46893. if (ret != 0) {
  46894. wc_PKCS7_Free(pkcs7);
  46895. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46896. }
  46897. } else if (testVectors[i].password != NULL) {
  46898. #if !defined(NO_PWDBASED) && !defined(NO_SHA)
  46899. /* PWRI recipient type */
  46900. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46901. if (ret != 0)
  46902. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46903. pkcs7->content = (byte*)testVectors[i].content;
  46904. pkcs7->contentSz = testVectors[i].contentSz;
  46905. pkcs7->contentOID = testVectors[i].contentOID;
  46906. pkcs7->encryptOID = testVectors[i].encryptOID;
  46907. pkcs7->ukm = testVectors[i].optionalUkm;
  46908. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46909. pkcs7->authAttribs = testVectors[i].authAttribs;
  46910. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46911. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46912. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46913. ret = wc_PKCS7_AddRecipient_PWRI(pkcs7,
  46914. (byte*)testVectors[i].password,
  46915. testVectors[i].passwordSz, testVectors[i].salt,
  46916. testVectors[i].saltSz, testVectors[i].kdfOID,
  46917. testVectors[i].hashOID, testVectors[i].kdfIterations,
  46918. testVectors[i].kekEncryptOID, testVectors[i].pwriOptions);
  46919. if (ret < 0) {
  46920. wc_PKCS7_Free(pkcs7);
  46921. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46922. }
  46923. /* set password, for decryption */
  46924. ret = wc_PKCS7_SetPassword(pkcs7, (byte*)testVectors[i].password,
  46925. testVectors[i].passwordSz);
  46926. if (ret < 0) {
  46927. wc_PKCS7_Free(pkcs7);
  46928. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46929. }
  46930. #endif /* ! NO_PWDBASED && ! NO_SHA */
  46931. } else if (testVectors[i].isOri == 1) {
  46932. /* ORI recipient type */
  46933. ret = wc_PKCS7_Init(pkcs7, pkcs7->heap, pkcs7->devId);
  46934. if (ret != 0)
  46935. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46936. pkcs7->content = (byte*)testVectors[i].content;
  46937. pkcs7->contentSz = testVectors[i].contentSz;
  46938. pkcs7->contentOID = testVectors[i].contentOID;
  46939. pkcs7->encryptOID = testVectors[i].encryptOID;
  46940. pkcs7->authAttribs = testVectors[i].authAttribs;
  46941. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46942. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46943. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46944. ret = wc_PKCS7_AddRecipient_ORI(pkcs7, myOriEncryptCb,
  46945. testVectors[i].oriOptions);
  46946. if (ret < 0) {
  46947. wc_PKCS7_Free(pkcs7);
  46948. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46949. }
  46950. /* set decrypt callback for decryption */
  46951. ret = wc_PKCS7_SetOriDecryptCb(pkcs7, myOriDecryptCb);
  46952. if (ret < 0) {
  46953. wc_PKCS7_Free(pkcs7);
  46954. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46955. }
  46956. } else {
  46957. /* KTRI or KARI recipient types */
  46958. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  46959. (word32)testVectors[i].certSz);
  46960. if (ret != 0) {
  46961. wc_PKCS7_Free(pkcs7);
  46962. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46963. }
  46964. pkcs7->keyWrapOID = testVectors[i].keyWrapOID;
  46965. pkcs7->keyAgreeOID = testVectors[i].keyAgreeOID;
  46966. pkcs7->privateKey = testVectors[i].privateKey;
  46967. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  46968. pkcs7->content = (byte*)testVectors[i].content;
  46969. pkcs7->contentSz = testVectors[i].contentSz;
  46970. pkcs7->contentOID = testVectors[i].contentOID;
  46971. pkcs7->encryptOID = testVectors[i].encryptOID;
  46972. pkcs7->ukm = testVectors[i].optionalUkm;
  46973. pkcs7->ukmSz = testVectors[i].optionalUkmSz;
  46974. pkcs7->authAttribs = testVectors[i].authAttribs;
  46975. pkcs7->authAttribsSz = testVectors[i].authAttribsSz;
  46976. pkcs7->unauthAttribs = testVectors[i].unauthAttribs;
  46977. pkcs7->unauthAttribsSz = testVectors[i].unauthAttribsSz;
  46978. /* set SubjectIdentifier type for KTRI types */
  46979. if (testVectors[i].ktriOptions & CMS_SKID) {
  46980. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  46981. if (ret != 0) {
  46982. wc_PKCS7_Free(pkcs7);
  46983. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46984. }
  46985. } else if (testVectors[i].ktriOptions &
  46986. CMS_ISSUER_AND_SERIAL_NUMBER) {
  46987. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7,
  46988. CMS_ISSUER_AND_SERIAL_NUMBER);
  46989. if (ret != 0) {
  46990. wc_PKCS7_Free(pkcs7);
  46991. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  46992. }
  46993. }
  46994. }
  46995. #ifdef ECC_TIMING_RESISTANT
  46996. pkcs7->rng = &rng;
  46997. #endif
  46998. /* encode envelopedData */
  46999. envelopedSz = wc_PKCS7_EncodeAuthEnvelopedData(pkcs7, enveloped,
  47000. PKCS7_BUF_SIZE);
  47001. if (envelopedSz <= 0) {
  47002. wc_PKCS7_Free(pkcs7);
  47003. ERROR_OUT(WC_TEST_RET_ENC_EC(envelopedSz), out);
  47004. }
  47005. #ifndef NO_PKCS7_STREAM
  47006. { /* test reading byte by byte */
  47007. int z;
  47008. for (z = 0; z < envelopedSz; z++) {
  47009. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7,
  47010. enveloped + z, 1, decoded, PKCS7_BUF_SIZE);
  47011. if (decodedSz <= 0 &&
  47012. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47013. {
  47014. printf("unexpected error %d\n", decodedSz);
  47015. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47016. }
  47017. }
  47018. /* test decode result */
  47019. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47020. printf("stream read compare failed\n");
  47021. wc_PKCS7_Free(pkcs7);
  47022. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47023. }
  47024. }
  47025. #endif
  47026. /* decode envelopedData */
  47027. decodedSz = wc_PKCS7_DecodeAuthEnvelopedData(pkcs7, enveloped,
  47028. (word32)envelopedSz, decoded,
  47029. PKCS7_BUF_SIZE);
  47030. if (decodedSz <= 0) {
  47031. wc_PKCS7_Free(pkcs7);
  47032. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47033. }
  47034. /* test decode result */
  47035. if (XMEMCMP(decoded, data, sizeof(data)) != 0){
  47036. wc_PKCS7_Free(pkcs7);
  47037. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47038. }
  47039. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47040. /* output pkcs7 envelopedData for external testing */
  47041. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47042. if (!pkcs7File) {
  47043. wc_PKCS7_Free(pkcs7);
  47044. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47045. }
  47046. ret = (int)XFWRITE(enveloped, 1, envelopedSz, pkcs7File);
  47047. XFCLOSE(pkcs7File);
  47048. if (ret != envelopedSz) {
  47049. wc_PKCS7_Free(pkcs7);
  47050. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47051. } else {
  47052. /* reset ret to 0 for success */
  47053. ret = 0;
  47054. }
  47055. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  47056. wc_PKCS7_Free(pkcs7);
  47057. pkcs7 = NULL;
  47058. }
  47059. wc_FreeRng(&rng);
  47060. (void)eccCert;
  47061. (void)eccCertSz;
  47062. (void)eccPrivKey;
  47063. (void)eccPrivKeySz;
  47064. #if !defined(NO_AES) && !defined(NO_SHA) && defined(WOLFSSL_AES_128)
  47065. (void)secretKey;
  47066. (void)secretKeyId;
  47067. #endif
  47068. #ifdef NO_RSA
  47069. (void)rsaCert;
  47070. (void)rsaCertSz;
  47071. (void)rsaPrivKey;
  47072. (void)rsaPrivKeySz;
  47073. #endif
  47074. out:
  47075. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47076. XFREE(enveloped, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47077. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47078. return ret;
  47079. }
  47080. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7authenveloped_test(void)
  47081. {
  47082. wc_test_ret_t ret = 0;
  47083. byte* rsaCert = NULL;
  47084. byte* rsaPrivKey = NULL;
  47085. word32 rsaCertSz = 0;
  47086. word32 rsaPrivKeySz = 0;
  47087. byte* eccCert = NULL;
  47088. byte* eccPrivKey = NULL;
  47089. word32 eccCertSz = 0;
  47090. word32 eccPrivKeySz = 0;
  47091. WOLFSSL_ENTER("pkcs7authenveloped_test");
  47092. #ifndef NO_RSA
  47093. /* read client RSA cert and key in DER format */
  47094. rsaCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47095. if (rsaCert == NULL)
  47096. return WC_TEST_RET_ENC_ERRNO;
  47097. rsaPrivKey = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47098. if (rsaPrivKey == NULL) {
  47099. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47100. return WC_TEST_RET_ENC_NC;
  47101. }
  47102. rsaCertSz = FOURK_BUF;
  47103. rsaPrivKeySz = FOURK_BUF;
  47104. #endif /* NO_RSA */
  47105. #ifdef HAVE_ECC
  47106. /* read client ECC cert and key in DER format */
  47107. eccCert = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47108. if (eccCert == NULL) {
  47109. #ifndef NO_RSA
  47110. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47111. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47112. #endif
  47113. return WC_TEST_RET_ENC_NC;
  47114. }
  47115. eccPrivKey =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47116. if (eccPrivKey == NULL) {
  47117. #ifndef NO_RSA
  47118. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47119. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47120. #endif
  47121. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47122. return WC_TEST_RET_ENC_NC;
  47123. }
  47124. eccCertSz = FOURK_BUF;
  47125. eccPrivKeySz = FOURK_BUF;
  47126. #endif /* HAVE_ECC */
  47127. ret = pkcs7_load_certs_keys(rsaCert, &rsaCertSz, rsaPrivKey,
  47128. &rsaPrivKeySz, NULL, NULL, NULL, NULL,
  47129. NULL, NULL, NULL, NULL, eccCert, &eccCertSz,
  47130. eccPrivKey, &eccPrivKeySz);
  47131. if (ret < 0) {
  47132. #ifndef NO_RSA
  47133. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47134. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47135. #endif
  47136. #ifdef HAVE_ECC
  47137. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47138. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47139. #endif
  47140. return WC_TEST_RET_ENC_EC(ret);
  47141. }
  47142. ret = pkcs7authenveloped_run_vectors(rsaCert, (word32)rsaCertSz,
  47143. rsaPrivKey, (word32)rsaPrivKeySz,
  47144. eccCert, (word32)eccCertSz,
  47145. eccPrivKey, (word32)eccPrivKeySz);
  47146. #ifndef NO_RSA
  47147. XFREE(rsaCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47148. XFREE(rsaPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47149. #endif
  47150. #ifdef HAVE_ECC
  47151. XFREE(eccCert, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47152. XFREE(eccPrivKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47153. #endif
  47154. return ret;
  47155. }
  47156. #endif /* HAVE_AESGCM || HAVE_AESCCM */
  47157. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47158. static const byte p7DefKey[] = {
  47159. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47160. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47161. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47162. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47163. };
  47164. static const byte p7AltKey[] = {
  47165. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47166. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47167. };
  47168. static int myCEKwrapFunc(wc_PKCS7* pkcs7, byte* cek, word32 cekSz, byte* keyId,
  47169. word32 keyIdSz, byte* orginKey, word32 orginKeySz,
  47170. byte* out, word32 outSz, int keyWrapAlgo, int type, int direction)
  47171. {
  47172. wc_test_ret_t ret;
  47173. if (cek == NULL || out == NULL)
  47174. return BAD_FUNC_ARG;
  47175. /* test case sanity checks */
  47176. if (keyIdSz != 1) {
  47177. return WC_TEST_RET_ENC_NC;
  47178. }
  47179. if (keyId[0] != 0x00) {
  47180. return WC_TEST_RET_ENC_NC;
  47181. }
  47182. if (type != (int)PKCS7_KEKRI) {
  47183. return WC_TEST_RET_ENC_NC;
  47184. }
  47185. switch (keyWrapAlgo) {
  47186. case AES256_WRAP:
  47187. ret = wc_AesKeyUnWrap(p7DefKey, sizeof(p7DefKey), cek, cekSz,
  47188. out, outSz, NULL);
  47189. if (ret <= 0)
  47190. return (int)ret;
  47191. break;
  47192. default:
  47193. WOLFSSL_MSG("Unsupported key wrap algorithm in example");
  47194. return BAD_KEYWRAP_ALG_E;
  47195. };
  47196. (void)pkcs7;
  47197. (void)direction;
  47198. (void)orginKey; /* used with KAKRI */
  47199. (void)orginKeySz;
  47200. return (int)ret;
  47201. }
  47202. /* returns key size on success */
  47203. static wc_test_ret_t getFirmwareKey(wc_PKCS7* pkcs7, byte* key, word32 keySz)
  47204. {
  47205. wc_test_ret_t ret;
  47206. word32 atrSz;
  47207. byte atr[256];
  47208. /* Additionally can look for fwWrappedFirmwareKey
  47209. * 1.2.840.113529.1.9.16.1.16 */
  47210. const unsigned char fwWrappedFirmwareKey[] = {
  47211. /* 0x06, 0x0B */
  47212. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47213. 0x01, 0x09, 0x10, 0x02, 0x27
  47214. };
  47215. /* find keyID in fwWrappedFirmwareKey */
  47216. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47217. sizeof(fwWrappedFirmwareKey), NULL, &atrSz);
  47218. if (ret == WC_NO_ERR_TRACE(LENGTH_ONLY_E)) {
  47219. XMEMSET(atr, 0, sizeof(atr));
  47220. ret = wc_PKCS7_GetAttributeValue(pkcs7, fwWrappedFirmwareKey,
  47221. sizeof(fwWrappedFirmwareKey), atr, &atrSz);
  47222. /* keyIdRaw[0] OCTET TAG */
  47223. /* keyIdRaw[1] Length */
  47224. if (ret > 0) {
  47225. wc_PKCS7* envPkcs7;
  47226. envPkcs7 = wc_PKCS7_New(NULL, 0);
  47227. if (envPkcs7 == NULL) {
  47228. return MEMORY_E;
  47229. }
  47230. wc_PKCS7_Init(envPkcs7, NULL, 0);
  47231. ret = wc_PKCS7_SetWrapCEKCb(envPkcs7, myCEKwrapFunc);
  47232. if (ret == 0) {
  47233. /* expecting FIRMWARE_PKG_DATA content */
  47234. envPkcs7->contentOID = FIRMWARE_PKG_DATA;
  47235. ret = wc_PKCS7_DecodeEnvelopedData(envPkcs7, atr, atrSz,
  47236. key, keySz);
  47237. if (envPkcs7->contentOID != FIRMWARE_PKG_DATA) {
  47238. /* the contentOID should have been set to the inner
  47239. * FIRMWARE_PKG_DATA content */
  47240. ret = BAD_STATE_E;
  47241. }
  47242. }
  47243. wc_PKCS7_Free(envPkcs7);
  47244. }
  47245. }
  47246. return ret;
  47247. }
  47248. /* create a KEKRI enveloped data
  47249. * return size on success */
  47250. static wc_test_ret_t envelopedData_encrypt(byte* in, word32 inSz, byte* out,
  47251. word32 outSz)
  47252. {
  47253. wc_test_ret_t ret;
  47254. wc_PKCS7* pkcs7;
  47255. WOLFSSL_SMALL_STACK_STATIC const byte keyId[] = { 0x00 };
  47256. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47257. if (pkcs7 == NULL)
  47258. return WC_TEST_RET_ENC_ERRNO;
  47259. pkcs7->content = in;
  47260. pkcs7->contentSz = inSz;
  47261. pkcs7->contentOID = FIRMWARE_PKG_DATA;
  47262. pkcs7->encryptOID = AES256CBCb;
  47263. pkcs7->ukm = NULL;
  47264. pkcs7->ukmSz = 0;
  47265. /* add recipient (KEKRI type) */
  47266. ret = wc_PKCS7_AddRecipient_KEKRI(pkcs7, AES256_WRAP, (byte*)p7DefKey,
  47267. sizeof(p7DefKey), (byte*)keyId,
  47268. sizeof(keyId), NULL, NULL, 0, NULL, 0, 0);
  47269. if (ret < 0) {
  47270. printf("wc_PKCS7_AddRecipient_KEKRI() failed\n");
  47271. wc_PKCS7_Free(pkcs7);
  47272. return WC_TEST_RET_ENC_EC(ret);
  47273. }
  47274. /* encode envelopedData, returns size */
  47275. ret = wc_PKCS7_EncodeEnvelopedData(pkcs7, out, outSz);
  47276. if (ret <= 0) {
  47277. printf("wc_PKCS7_EncodeEnvelopedData() failed\n");
  47278. wc_PKCS7_Free(pkcs7);
  47279. return WC_TEST_RET_ENC_EC(ret);
  47280. }
  47281. wc_PKCS7_Free(pkcs7);
  47282. return ret;
  47283. }
  47284. /*
  47285. * keyHint is the KeyID to be set in the fwDecryptKeyID attribute
  47286. * returns size of buffer output on success
  47287. */
  47288. static wc_test_ret_t generateBundle(byte* out, word32 *outSz, const byte* encryptKey,
  47289. word32 encryptKeySz, byte keyHint, byte* cert, word32 certSz,
  47290. byte* key, word32 keySz)
  47291. {
  47292. wc_test_ret_t ret;
  47293. int attribNum = 1;
  47294. wc_PKCS7* pkcs7;
  47295. /* KEY ID
  47296. * fwDecryptKeyID OID 1.2.840.113549.1.9.16.2.37
  47297. */
  47298. const unsigned char fwDecryptKeyID[] = {
  47299. 0x06, 0x0B,
  47300. 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47301. 0x01, 0x09, 0x10, 0x02, 0x25
  47302. };
  47303. /* fwWrappedFirmwareKey 1.2.840.113529.1.9.16.1.16 */
  47304. const unsigned char fwWrappedFirmwareKey[] = {
  47305. 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D,
  47306. 0x01, 0x09, 0x10, 0x02, 0x27
  47307. };
  47308. byte keyID[] = { 0x04, 0x01, 0x00 };
  47309. byte env[256];
  47310. char data[] = "Test of wolfSSL PKCS7 decrypt callback";
  47311. PKCS7Attrib attribs[] =
  47312. {
  47313. { fwDecryptKeyID, sizeof(fwDecryptKeyID), keyID, sizeof(keyID) },
  47314. { fwWrappedFirmwareKey, sizeof(fwWrappedFirmwareKey), env, 0 }
  47315. };
  47316. keyID[2] = keyHint;
  47317. /* If using keyHint 0 then create a bundle with fwWrappedFirmwareKey */
  47318. if (keyHint == 0) {
  47319. ret = envelopedData_encrypt((byte*)p7DefKey, sizeof(p7DefKey), env,
  47320. sizeof(env));
  47321. if (ret <= 0) {
  47322. return ret;
  47323. }
  47324. attribs[1].valueSz = (word32)ret;
  47325. attribNum++;
  47326. }
  47327. /* init PKCS7 */
  47328. pkcs7 = wc_PKCS7_New(NULL, INVALID_DEVID);
  47329. if (pkcs7 == NULL)
  47330. return WC_TEST_RET_ENC_ERRNO;
  47331. ret = wc_PKCS7_InitWithCert(pkcs7, cert, certSz);
  47332. if (ret != 0) {
  47333. printf("ERROR: wc_PKCS7_InitWithCert() failed, ret = %d\n", ret);
  47334. wc_PKCS7_Free(pkcs7);
  47335. return WC_TEST_RET_ENC_EC(ret);
  47336. }
  47337. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  47338. if (ret != 0) {
  47339. wc_PKCS7_Free(pkcs7);
  47340. return WC_TEST_RET_ENC_EC(ret);
  47341. }
  47342. /* encode Signed Encrypted FirmwarePkgData */
  47343. if (encryptKeySz == 16) {
  47344. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47345. encryptKeySz, key, keySz, AES128CBCb, RSAk, SHA256h,
  47346. (byte*)data, sizeof(data), NULL, 0,
  47347. attribs, (word32)attribNum, out, *outSz);
  47348. }
  47349. else {
  47350. ret = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7, (byte*)encryptKey,
  47351. encryptKeySz, key, keySz, AES256CBCb, RSAk, SHA256h,
  47352. (byte*)data, sizeof(data), NULL, 0,
  47353. attribs, (word32)attribNum, out, *outSz);
  47354. }
  47355. if (ret <= 0) {
  47356. printf("ERROR: wc_PKCS7_EncodeSignedEncryptedFPD() failed, "
  47357. "ret = %d\n", ret);
  47358. wc_PKCS7_Free(pkcs7);
  47359. return WC_TEST_RET_ENC_EC(ret);
  47360. } else {
  47361. *outSz = (word32)ret;
  47362. }
  47363. wc_PKCS7_Free(pkcs7);
  47364. return ret;
  47365. }
  47366. /* test verification and decryption of PKCS7 bundle
  47367. * return 0 on success
  47368. */
  47369. static wc_test_ret_t verifyBundle(byte* derBuf, word32 derSz, int keyHint)
  47370. {
  47371. wc_test_ret_t ret = 0;
  47372. int usrCtx = 1; /* test value to pass as user context to callback */
  47373. wc_PKCS7* pkcs7 = NULL;
  47374. byte* sid = NULL;
  47375. word32 sidSz;
  47376. byte key[256];
  47377. word32 keySz = sizeof(key);
  47378. byte *decoded = NULL;
  47379. int decodedSz = FOURK_BUF/2;
  47380. WOLFSSL_SMALL_STACK_STATIC const byte expectedSid[] = {
  47381. #ifdef NO_SHA
  47382. #ifdef USE_CERT_BUFFERS_1024
  47383. 0x70, 0xe7, 0x79, 0x60, 0x8f, 0x41, 0xdc, 0xe9,
  47384. 0xad, 0x8b, 0x3d, 0x0c, 0x20, 0xf4, 0xc3, 0xf2,
  47385. 0x8e, 0x05, 0xe8, 0xa1, 0xb6, 0x68, 0x74, 0x06,
  47386. 0xbc, 0xe7, 0xc5, 0x3c, 0x13, 0x99, 0x79, 0xb9
  47387. #else
  47388. 0xce, 0x06, 0x07, 0xbe, 0xf1, 0xa6, 0x1e, 0x36,
  47389. 0xef, 0xfa, 0xbc, 0x89, 0x71, 0xf3, 0x23, 0x9e,
  47390. 0x34, 0x6d, 0xae, 0x86, 0xae, 0x2b, 0xdc, 0xf4,
  47391. 0x4a, 0x27, 0xd5, 0x63, 0x59, 0x4f, 0x4a, 0x71
  47392. #endif
  47393. #else /* !NO_SHA */
  47394. #ifdef USE_CERT_BUFFERS_1024
  47395. 0x81, 0x69, 0x0f, 0xf8, 0xdf, 0xdd, 0xcf, 0x34,
  47396. 0x29, 0xd5, 0x67, 0x75, 0x71, 0x85, 0xc7, 0x75,
  47397. 0x10, 0x69, 0x59, 0xec,
  47398. #else
  47399. 0x33, 0xD8, 0x45, 0x66, 0xD7, 0x68, 0x87, 0x18,
  47400. 0x7E, 0x54, 0x0D, 0x70, 0x27, 0x91, 0xC7, 0x26,
  47401. 0xD7, 0x85, 0x65, 0xC0
  47402. #endif
  47403. #endif /* !NO_SHA */
  47404. };
  47405. decoded = (byte *)XMALLOC(decodedSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47406. if (decoded == NULL) {
  47407. ret = MEMORY_E;
  47408. goto out;
  47409. }
  47410. pkcs7 = wc_PKCS7_New(HEAP_HINT, INVALID_DEVID);
  47411. if (pkcs7 == NULL) {
  47412. ret = MEMORY_E;
  47413. goto out;
  47414. }
  47415. /* Test verify */
  47416. ret = wc_PKCS7_Init(pkcs7, HEAP_HINT, INVALID_DEVID);
  47417. if (ret != 0)
  47418. goto out;
  47419. ret = wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  47420. if (ret != 0)
  47421. goto out;
  47422. ret = wc_PKCS7_VerifySignedData(pkcs7, derBuf, derSz);
  47423. if (ret != 0)
  47424. goto out;
  47425. /* Get size of SID and print it out */
  47426. ret = wc_PKCS7_GetSignerSID(pkcs7, NULL, &sidSz);
  47427. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  47428. goto out;
  47429. sid = (byte*)XMALLOC(sidSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47430. if (sid == NULL) {
  47431. ret = MEMORY_E;
  47432. goto out;
  47433. }
  47434. ret = wc_PKCS7_GetSignerSID(pkcs7, sid, &sidSz);
  47435. if (ret != 0)
  47436. goto out;
  47437. ret = XMEMCMP(sid, expectedSid, sidSz);
  47438. if (ret != 0) {
  47439. ret = PKCS7_NO_SIGNER_E; /* close enough */
  47440. goto out;
  47441. }
  47442. /* get expected fwWrappedFirmwareKey */
  47443. if (keyHint == 0) {
  47444. ret = getFirmwareKey(pkcs7, key, keySz);
  47445. if (ret < 0)
  47446. goto out;
  47447. pkcs7->encryptionKey = key;
  47448. pkcs7->encryptionKeySz = (word32)ret;
  47449. }
  47450. else {
  47451. decodedSz = PKCS7_BUF_SIZE;
  47452. ret = wc_PKCS7_SetDecodeEncryptedCb(pkcs7, myDecryptionFunc);
  47453. if (ret != 0)
  47454. goto out;
  47455. ret = wc_PKCS7_SetDecodeEncryptedCtx(pkcs7, (void*)&usrCtx);
  47456. if (ret != 0)
  47457. goto out;
  47458. }
  47459. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  47460. pkcs7->contentSz, decoded, (word32)decodedSz);
  47461. if (decodedSz < 0) {
  47462. ret = decodedSz;
  47463. goto out;
  47464. }
  47465. ret = 0;
  47466. out:
  47467. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47468. if (pkcs7)
  47469. wc_PKCS7_Free(pkcs7);
  47470. XFREE(sid, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47471. return ret;
  47472. }
  47473. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7callback_test(byte* cert, word32 certSz, byte* key, word32 keySz)
  47474. {
  47475. wc_test_ret_t ret = 0;
  47476. word32 derSz;
  47477. byte *derBuf = (byte *)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47478. WOLFSSL_ENTER("pkcs7callback_test");
  47479. if (! derBuf)
  47480. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47481. /* Doing default generation and verify */
  47482. derSz = FOURK_BUF;
  47483. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 0, cert,
  47484. certSz, key, keySz);
  47485. if (ret <= 0) {
  47486. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  47487. }
  47488. ret = verifyBundle(derBuf, derSz, 0);
  47489. if (ret != 0)
  47490. ERROR_OUT(ret, out);
  47491. /* test choosing other key with keyID */
  47492. derSz = FOURK_BUF;
  47493. ret = generateBundle(derBuf, &derSz, p7AltKey, sizeof(p7AltKey), 1,
  47494. cert, certSz, key, keySz);
  47495. if (ret <= 0) {
  47496. ERROR_OUT(ret, out);
  47497. }
  47498. ret = verifyBundle(derBuf, derSz, 1);
  47499. if (ret != 0)
  47500. ERROR_OUT(ret, out);
  47501. /* test fail case with wrong keyID */
  47502. derSz = FOURK_BUF;
  47503. ret = generateBundle(derBuf, &derSz, p7DefKey, sizeof(p7DefKey), 1,
  47504. cert, certSz, key, keySz);
  47505. if (ret <= 0) {
  47506. ERROR_OUT(ret, out);
  47507. }
  47508. ret = verifyBundle(derBuf, derSz, 1);
  47509. if (ret == 0) {
  47510. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47511. }
  47512. ret = 0;
  47513. out:
  47514. XFREE(derBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47515. return ret;
  47516. }
  47517. #endif /* !NO_AES && HAVE_AES_CBC */
  47518. #ifndef NO_PKCS7_ENCRYPTED_DATA
  47519. typedef struct {
  47520. const byte* content;
  47521. word32 contentSz;
  47522. int contentOID;
  47523. int encryptOID;
  47524. byte* encryptionKey;
  47525. word32 encryptionKeySz;
  47526. PKCS7Attrib* attribs;
  47527. word32 attribsSz;
  47528. const char* outFileName;
  47529. } pkcs7EncryptedVector;
  47530. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7encrypted_test(void)
  47531. {
  47532. wc_test_ret_t ret = 0;
  47533. int i, testSz;
  47534. int encryptedSz, decodedSz, attribIdx;
  47535. wc_PKCS7* pkcs7;
  47536. byte *encrypted;
  47537. byte *decoded;
  47538. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47539. XFILE pkcs7File;
  47540. #endif
  47541. PKCS7Attrib* expectedAttrib;
  47542. PKCS7DecodedAttrib* decodedAttrib;
  47543. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47544. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47545. 0x72,0x6c,0x64
  47546. };
  47547. #ifndef NO_DES3
  47548. byte desKey[] = {
  47549. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef
  47550. };
  47551. byte des3Key[] = {
  47552. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  47553. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  47554. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67
  47555. };
  47556. #endif
  47557. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47558. #ifdef WOLFSSL_AES_128
  47559. byte aes128Key[] = {
  47560. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47561. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47562. };
  47563. #endif
  47564. #ifdef WOLFSSL_AES_192
  47565. byte aes192Key[] = {
  47566. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47567. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47568. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47569. };
  47570. #endif
  47571. #ifdef WOLFSSL_AES_256
  47572. byte aes256Key[] = {
  47573. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47574. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47575. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  47576. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  47577. };
  47578. #endif
  47579. #ifdef WOLFSSL_AES_256
  47580. /* Attribute example from RFC 4134, Section 7.2
  47581. * OID = 1.2.5555
  47582. * OCTET STRING = 'This is a test General ASN Attribute, number 1.' */
  47583. static const byte genAttrOid[] = { 0x06, 0x03, 0x2a, 0xab, 0x33 };
  47584. static const byte genAttr[] = { 0x04, 47,
  47585. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47586. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47587. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47588. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47589. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47590. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x31, 0x2e };
  47591. static const byte genAttrOid2[] = { 0x06, 0x03, 0x2a, 0xab, 0x34 };
  47592. static const byte genAttr2[] = { 0x04, 47,
  47593. 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
  47594. 0x61, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x47,
  47595. 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x41,
  47596. 0x53, 0x4e, 0x20, 0x41, 0x74, 0x74, 0x72, 0x69,
  47597. 0x62, 0x75, 0x74, 0x65, 0x2c, 0x20, 0x6e, 0x75,
  47598. 0x6d, 0x62, 0x65, 0x72, 0x20, 0x32, 0x2e };
  47599. PKCS7Attrib attribs[] =
  47600. {
  47601. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) }
  47602. };
  47603. PKCS7Attrib multiAttribs[] =
  47604. {
  47605. { genAttrOid, sizeof(genAttrOid), genAttr, sizeof(genAttr) },
  47606. { genAttrOid2, sizeof(genAttrOid2), genAttr2, sizeof(genAttr2) }
  47607. };
  47608. #endif
  47609. #endif /* NO_AES */
  47610. const pkcs7EncryptedVector testVectors[] =
  47611. {
  47612. #ifndef NO_DES3
  47613. {data, (word32)sizeof(data), DATA, DES3b, des3Key, sizeof(des3Key),
  47614. NULL, 0, "pkcs7encryptedDataDES3.der"},
  47615. {data, (word32)sizeof(data), DATA, DESb, desKey, sizeof(desKey),
  47616. NULL, 0, "pkcs7encryptedDataDES.der"},
  47617. #endif /* NO_DES3 */
  47618. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  47619. #ifdef WOLFSSL_AES_128
  47620. {data, (word32)sizeof(data), DATA, AES128CBCb, aes128Key,
  47621. sizeof(aes128Key), NULL, 0, "pkcs7encryptedDataAES128CBC.der"},
  47622. #endif
  47623. #ifdef WOLFSSL_AES_192
  47624. {data, (word32)sizeof(data), DATA, AES192CBCb, aes192Key,
  47625. sizeof(aes192Key), NULL, 0, "pkcs7encryptedDataAES192CBC.der"},
  47626. #endif
  47627. #ifdef WOLFSSL_AES_256
  47628. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47629. sizeof(aes256Key), NULL, 0, "pkcs7encryptedDataAES256CBC.der"},
  47630. /* test with optional unprotected attributes */
  47631. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47632. sizeof(aes256Key), attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47633. "pkcs7encryptedDataAES256CBC_attribs.der"},
  47634. /* test with multiple optional unprotected attributes */
  47635. {data, (word32)sizeof(data), DATA, AES256CBCb, aes256Key,
  47636. sizeof(aes256Key), multiAttribs,
  47637. (sizeof(multiAttribs)/sizeof(PKCS7Attrib)),
  47638. "pkcs7encryptedDataAES256CBC_multi_attribs.der"},
  47639. /* test with contentType set to FirmwarePkgData */
  47640. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA, AES256CBCb, aes256Key,
  47641. sizeof(aes256Key), NULL, 0,
  47642. "pkcs7encryptedDataAES256CBC_firmwarePkgData.der"},
  47643. #endif
  47644. #endif /* !NO_AES && HAVE_AES_CBC */
  47645. };
  47646. WOLFSSL_ENTER("pkcs7encrypted_test");
  47647. encrypted = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47648. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47649. if ((! encrypted) || (! decoded)) {
  47650. ERROR_OUT(MEMORY_E, out);
  47651. }
  47652. testSz = sizeof(testVectors) / sizeof(pkcs7EncryptedVector);
  47653. for (i = 0; i < testSz; i++) {
  47654. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47655. if (pkcs7 == NULL) {
  47656. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47657. }
  47658. pkcs7->content = (byte*)testVectors[i].content;
  47659. pkcs7->contentSz = testVectors[i].contentSz;
  47660. pkcs7->contentOID = testVectors[i].contentOID;
  47661. pkcs7->encryptOID = testVectors[i].encryptOID;
  47662. pkcs7->encryptionKey = testVectors[i].encryptionKey;
  47663. pkcs7->encryptionKeySz = testVectors[i].encryptionKeySz;
  47664. pkcs7->unprotectedAttribs = testVectors[i].attribs;
  47665. pkcs7->unprotectedAttribsSz = testVectors[i].attribsSz;
  47666. /* encode encryptedData */
  47667. encryptedSz = wc_PKCS7_EncodeEncryptedData(pkcs7, encrypted,
  47668. PKCS7_BUF_SIZE);
  47669. if (encryptedSz <= 0) {
  47670. wc_PKCS7_Free(pkcs7);
  47671. ERROR_OUT(WC_TEST_RET_ENC_EC(encryptedSz), out);
  47672. }
  47673. /* decode encryptedData */
  47674. #ifndef NO_PKCS7_STREAM
  47675. { /* test reading byte by byte */
  47676. int z;
  47677. for (z = 0; z < encryptedSz; z++) {
  47678. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted + z, 1,
  47679. decoded, PKCS7_BUF_SIZE);
  47680. if (decodedSz <= 0 &&
  47681. decodedSz != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E))
  47682. {
  47683. printf("unexpected error %d\n", decodedSz);
  47684. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47685. }
  47686. }
  47687. /* test decode result */
  47688. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47689. printf("stream read failed\n");
  47690. wc_PKCS7_Free(pkcs7);
  47691. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47692. }
  47693. }
  47694. #endif
  47695. decodedSz = wc_PKCS7_DecodeEncryptedData(pkcs7, encrypted, (word32)encryptedSz,
  47696. decoded, PKCS7_BUF_SIZE);
  47697. if (decodedSz <= 0){
  47698. wc_PKCS7_Free(pkcs7);
  47699. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47700. }
  47701. /* test decode result */
  47702. if (XMEMCMP(decoded, data, sizeof(data)) != 0) {
  47703. wc_PKCS7_Free(pkcs7);
  47704. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47705. }
  47706. /* verify decoded unprotected attributes */
  47707. if (pkcs7->decodedAttrib != NULL) {
  47708. decodedAttrib = pkcs7->decodedAttrib;
  47709. attribIdx = 1;
  47710. while (decodedAttrib != NULL) {
  47711. /* expected attribute, stored list is reversed */
  47712. expectedAttrib = &(pkcs7->unprotectedAttribs
  47713. [pkcs7->unprotectedAttribsSz - attribIdx]);
  47714. /* verify oid */
  47715. if (XMEMCMP(decodedAttrib->oid, expectedAttrib->oid,
  47716. decodedAttrib->oidSz) != 0) {
  47717. wc_PKCS7_Free(pkcs7);
  47718. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47719. }
  47720. /* verify value */
  47721. if (XMEMCMP(decodedAttrib->value, expectedAttrib->value,
  47722. decodedAttrib->valueSz) != 0) {
  47723. wc_PKCS7_Free(pkcs7);
  47724. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47725. }
  47726. decodedAttrib = decodedAttrib->next;
  47727. attribIdx++;
  47728. }
  47729. }
  47730. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47731. /* output pkcs7 envelopedData for external testing */
  47732. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47733. if (!pkcs7File) {
  47734. wc_PKCS7_Free(pkcs7);
  47735. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47736. }
  47737. ret = (int)XFWRITE(encrypted, encryptedSz, 1, pkcs7File);
  47738. if (ret < 0)
  47739. ret = WC_TEST_RET_ENC_ERRNO;
  47740. else
  47741. ret = 0;
  47742. XFCLOSE(pkcs7File);
  47743. #endif
  47744. wc_PKCS7_Free(pkcs7);
  47745. }
  47746. out:
  47747. XFREE(encrypted, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47748. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47749. return ret;
  47750. }
  47751. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  47752. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  47753. typedef struct {
  47754. const byte* content;
  47755. word32 contentSz;
  47756. int contentOID;
  47757. const char* outFileName;
  47758. } pkcs7CompressedVector;
  47759. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7compressed_test(void)
  47760. {
  47761. wc_test_ret_t ret = 0;
  47762. int i, testSz;
  47763. int compressedSz, decodedSz;
  47764. wc_PKCS7* pkcs7;
  47765. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47766. byte *compressed;
  47767. byte *decoded;
  47768. #else
  47769. byte compressed[PKCS7_BUF_SIZE];
  47770. byte decoded[PKCS7_BUF_SIZE];
  47771. #endif
  47772. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47773. XFILE pkcs7File;
  47774. #endif
  47775. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47776. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47777. 0x72,0x6c,0x64
  47778. };
  47779. const pkcs7CompressedVector testVectors[] =
  47780. {
  47781. {data, (word32)sizeof(data), DATA,
  47782. "pkcs7compressedData_data_zlib.der"},
  47783. {data, (word32)sizeof(data), FIRMWARE_PKG_DATA,
  47784. "pkcs7compressedData_firmwarePkgData_zlib.der"},
  47785. };
  47786. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47787. compressed = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47788. decoded = (byte *)XMALLOC(PKCS7_BUF_SIZE, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47789. if ((! compressed) || (! decoded)) {
  47790. ERROR_OUT(MEMORY_E, out);
  47791. }
  47792. #endif
  47793. WOLFSSL_ENTER("pkcs7compressed_test");
  47794. testSz = sizeof(testVectors) / sizeof(pkcs7CompressedVector);
  47795. for (i = 0; i < testSz; i++) {
  47796. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  47797. if (pkcs7 == NULL) {
  47798. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47799. }
  47800. pkcs7->content = (byte*)testVectors[i].content;
  47801. pkcs7->contentSz = testVectors[i].contentSz;
  47802. pkcs7->contentOID = testVectors[i].contentOID;
  47803. /* encode compressedData */
  47804. compressedSz = wc_PKCS7_EncodeCompressedData(pkcs7, compressed,
  47805. PKCS7_BUF_SIZE);
  47806. if (compressedSz <= 0) {
  47807. wc_PKCS7_Free(pkcs7);
  47808. ERROR_OUT(WC_TEST_RET_ENC_EC(compressedSz), out);
  47809. }
  47810. /* decode compressedData */
  47811. decodedSz = wc_PKCS7_DecodeCompressedData(pkcs7, compressed,
  47812. compressedSz, decoded,
  47813. PKCS7_BUF_SIZE);
  47814. if (decodedSz <= 0){
  47815. wc_PKCS7_Free(pkcs7);
  47816. ERROR_OUT(WC_TEST_RET_ENC_EC(decodedSz), out);
  47817. }
  47818. /* test decode result */
  47819. if (XMEMCMP(decoded, testVectors[i].content,
  47820. testVectors[i].contentSz) != 0) {
  47821. wc_PKCS7_Free(pkcs7);
  47822. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47823. }
  47824. /* make sure content type is the same */
  47825. if (testVectors[i].contentOID != pkcs7->contentOID) {
  47826. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  47827. }
  47828. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47829. /* output pkcs7 compressedData for external testing */
  47830. pkcs7File = XFOPEN(testVectors[i].outFileName, "wb");
  47831. if (!pkcs7File) {
  47832. wc_PKCS7_Free(pkcs7);
  47833. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  47834. }
  47835. ret = (int)XFWRITE(compressed, compressedSz, 1, pkcs7File);
  47836. if (ret < 0)
  47837. ret = WC_TEST_RET_ENC_ERRNO;
  47838. else
  47839. ret = 0;
  47840. XFCLOSE(pkcs7File);
  47841. #endif
  47842. wc_PKCS7_Free(pkcs7);
  47843. }
  47844. out:
  47845. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  47846. XFREE(compressed, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47847. XFREE(decoded, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47848. #endif
  47849. return ret;
  47850. } /* pkcs7compressed_test() */
  47851. #undef PKCS7_BUF_SIZE
  47852. #endif /* HAVE_LIBZ */
  47853. typedef struct {
  47854. const byte* content;
  47855. word32 contentSz;
  47856. int hashOID;
  47857. int signOID;
  47858. byte* privateKey;
  47859. word32 privateKeySz;
  47860. byte* cert;
  47861. size_t certSz;
  47862. byte* caCert;
  47863. size_t caCertSz;
  47864. PKCS7Attrib* signedAttribs;
  47865. word32 signedAttribsSz;
  47866. const char* outFileName;
  47867. int contentOID;
  47868. const byte* contentType;
  47869. word32 contentTypeSz;
  47870. int sidType;
  47871. int encryptOID; /* for single-shot encrypt alg OID */
  47872. int encCompFlag; /* for single-shot. 1 = enc, 2 = comp, 3 = both*/
  47873. const byte* encryptKey; /* for single-shot, encryptedData */
  47874. word32 encryptKeySz; /* for single-shot, encryptedData */
  47875. PKCS7Attrib* unprotectedAttribs; /* for single-shot, encryptedData */
  47876. word32 unprotectedAttribsSz; /* for single-shot, encryptedData */
  47877. word16 detachedSignature; /* generate detached signature (0:1) */
  47878. } pkcs7SignedVector;
  47879. static wc_test_ret_t pkcs7signed_run_vectors(
  47880. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  47881. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  47882. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  47883. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  47884. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  47885. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  47886. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  47887. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  47888. {
  47889. wc_test_ret_t ret;
  47890. int testSz = 0, i;
  47891. int encodedSz;
  47892. byte* out = NULL;
  47893. word32 outSz;
  47894. WC_RNG rng;
  47895. wc_PKCS7* pkcs7 = NULL;
  47896. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  47897. XFILE file;
  47898. #endif
  47899. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  47900. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  47901. 0x72,0x6c,0x64
  47902. };
  47903. static const byte transIdOid[] =
  47904. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47905. 0x09, 0x07 };
  47906. static const byte messageTypeOid[] =
  47907. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47908. 0x09, 0x02 };
  47909. static const byte senderNonceOid[] =
  47910. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  47911. 0x09, 0x05 };
  47912. #ifndef NO_SHA
  47913. byte transId[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  47914. #else
  47915. byte transId[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  47916. #endif
  47917. static const byte messageType[] = { 0x13, 2, '1', '9' };
  47918. byte senderNonce[PKCS7_NONCE_SZ + 2];
  47919. PKCS7Attrib attribs[] =
  47920. {
  47921. { transIdOid, sizeof(transIdOid), transId,
  47922. sizeof(transId) - 1 }, /* take off the null */
  47923. { messageTypeOid, sizeof(messageTypeOid), messageType,
  47924. sizeof(messageType) },
  47925. { senderNonceOid, sizeof(senderNonceOid), senderNonce,
  47926. sizeof(senderNonce) }
  47927. };
  47928. /* for testing custom contentType, FirmwarePkgData */
  47929. static const byte customContentType[] = { 0x06, 0x0B, 0x2A, 0x86,
  47930. 0x48, 0x86, 0xF7, 0x0D,
  47931. 0x01, 0x09, 0x10, 0x01, 0x10 };
  47932. #define MAX_TESTVECTORS_LEN 20
  47933. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  47934. const pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  47935. if (testSz == MAX_TESTVECTORS_LEN) { \
  47936. ret = WC_TEST_RET_ENC_NC; \
  47937. goto out; \
  47938. } \
  47939. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  47940. sizeof _this_vector); \
  47941. }
  47942. pkcs7SignedVector *testVectors = NULL;
  47943. XMEMSET(&rng, 0, sizeof(rng));
  47944. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  47945. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  47946. if (testVectors == NULL) {
  47947. ret = WC_TEST_RET_ENC_ERRNO;
  47948. goto out;
  47949. }
  47950. {
  47951. #ifndef NO_RSA
  47952. #ifndef NO_SHA
  47953. /* RSA with SHA */
  47954. ADD_PKCS7SIGNEDVECTOR(
  47955. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47956. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47957. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47958. "pkcs7signedData_RSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0, NULL,
  47959. 0, 0);
  47960. /* RSA with SHA, no signed attributes */
  47961. ADD_PKCS7SIGNEDVECTOR(
  47962. data, (word32)sizeof(data), SHAh, RSAk, rsaClientPrivKeyBuf,
  47963. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz,
  47964. NULL, 0, NULL, 0,
  47965. "pkcs7signedData_RSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47966. NULL, 0, 0);
  47967. #endif
  47968. #ifdef WOLFSSL_SHA224
  47969. /* RSA with SHA224 */
  47970. ADD_PKCS7SIGNEDVECTOR(
  47971. data, (word32)sizeof(data), SHA224h, RSAk, rsaClientPrivKeyBuf,
  47972. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47973. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47974. "pkcs7signedData_RSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47975. NULL, 0, 0);
  47976. #endif
  47977. #ifndef NO_SHA256
  47978. /* RSA with SHA256 */
  47979. ADD_PKCS7SIGNEDVECTOR(
  47980. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47981. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47982. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47983. "pkcs7signedData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  47984. NULL, 0, 0);
  47985. /* RSA with SHA256, detached signature */
  47986. ADD_PKCS7SIGNEDVECTOR(
  47987. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47988. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47989. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47990. "pkcs7signedData_RSA_SHA256_detachedSig.der", 0, NULL, 0, 0, 0, 0,
  47991. NULL, 0, NULL, 0, 1);
  47992. /* RSA with SHA256 and SubjectKeyIdentifier in SignerIdentifier */
  47993. ADD_PKCS7SIGNEDVECTOR(
  47994. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  47995. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  47996. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  47997. "pkcs7signedData_RSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  47998. NULL, 0, NULL, 0, 0);
  47999. /* RSA with SHA256 and custom contentType */
  48000. ADD_PKCS7SIGNEDVECTOR(
  48001. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48002. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48003. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48004. "pkcs7signedData_RSA_SHA256_custom_contentType.der", 0,
  48005. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  48006. NULL, 0, 0);
  48007. /* RSA with SHA256 and FirmwarePkgData contentType */
  48008. ADD_PKCS7SIGNEDVECTOR(
  48009. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48010. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48011. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48012. "pkcs7signedData_RSA_SHA256_firmwarePkgData.der",
  48013. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48014. /* RSA with SHA256 using server cert and ca cert */
  48015. ADD_PKCS7SIGNEDVECTOR(
  48016. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48017. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48018. rsaCaCertBuf, rsaCaCertBufSz,
  48019. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48020. "pkcs7signedData_RSA_SHA256_with_ca_cert.der", 0, NULL, 0, 0, 0, 0,
  48021. NULL, 0, NULL, 0, 0);
  48022. #endif
  48023. #if defined(WOLFSSL_SHA384)
  48024. /* RSA with SHA384 */
  48025. ADD_PKCS7SIGNEDVECTOR(
  48026. data, (word32)sizeof(data), SHA384h, RSAk, rsaClientPrivKeyBuf,
  48027. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48028. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48029. "pkcs7signedData_RSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48030. NULL, 0, 0);
  48031. #endif
  48032. #if defined(WOLFSSL_SHA512)
  48033. /* RSA with SHA512 */
  48034. ADD_PKCS7SIGNEDVECTOR(
  48035. data, (word32)sizeof(data), SHA512h, RSAk, rsaClientPrivKeyBuf,
  48036. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48037. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48038. "pkcs7signedData_RSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48039. NULL, 0, 0);
  48040. #endif
  48041. #endif /* NO_RSA */
  48042. #ifdef HAVE_ECC
  48043. #ifndef NO_SHA
  48044. /* ECDSA with SHA */
  48045. ADD_PKCS7SIGNEDVECTOR(
  48046. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48047. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48048. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48049. "pkcs7signedData_ECDSA_SHA.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48050. NULL, 0, 0);
  48051. /* ECDSA with SHA, no signed attributes */
  48052. ADD_PKCS7SIGNEDVECTOR(
  48053. data, (word32)sizeof(data), SHAh, ECDSAk, eccClientPrivKeyBuf,
  48054. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz,
  48055. NULL, 0, NULL, 0,
  48056. "pkcs7signedData_ECDSA_SHA_noattr.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48057. NULL, 0, 0);
  48058. #endif
  48059. #ifdef WOLFSSL_SHA224
  48060. /* ECDSA with SHA224 */
  48061. ADD_PKCS7SIGNEDVECTOR(
  48062. data, (word32)sizeof(data), SHA224h, ECDSAk, eccClientPrivKeyBuf,
  48063. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48064. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48065. "pkcs7signedData_ECDSA_SHA224.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48066. NULL, 0, 0);
  48067. #endif
  48068. #ifndef NO_SHA256
  48069. /* ECDSA with SHA256 */
  48070. ADD_PKCS7SIGNEDVECTOR(
  48071. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48072. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48073. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48074. "pkcs7signedData_ECDSA_SHA256.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48075. NULL, 0, 0);
  48076. /* ECDSA with SHA256 and SubjectKeyIdentifier in SigherIdentifier */
  48077. ADD_PKCS7SIGNEDVECTOR(
  48078. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48079. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48080. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48081. "pkcs7signedData_ECDSA_SHA256_SKID.der", 0, NULL, 0, CMS_SKID, 0, 0,
  48082. NULL, 0, NULL, 0, 0);
  48083. /* ECDSA with SHA256 and custom contentType */
  48084. ADD_PKCS7SIGNEDVECTOR(
  48085. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48086. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48087. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48088. "pkcs7signedData_ECDSA_SHA256_custom_contentType.der", 0,
  48089. customContentType, sizeof(customContentType), 0, 0, 0, NULL, 0,
  48090. NULL, 0, 0);
  48091. /* ECDSA with SHA256 and FirmwarePkgData contentType */
  48092. ADD_PKCS7SIGNEDVECTOR(
  48093. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48094. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48095. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48096. "pkcs7signedData_ECDSA_SHA256_firmwarePkgData.der",
  48097. FIRMWARE_PKG_DATA, NULL, 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48098. #endif
  48099. #ifdef WOLFSSL_SHA384
  48100. /* ECDSA with SHA384 */
  48101. ADD_PKCS7SIGNEDVECTOR(
  48102. data, (word32)sizeof(data), SHA384h, ECDSAk, eccClientPrivKeyBuf,
  48103. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48104. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48105. "pkcs7signedData_ECDSA_SHA384.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48106. NULL, 0, 0);
  48107. #endif
  48108. #ifdef WOLFSSL_SHA512
  48109. /* ECDSA with SHA512 */
  48110. ADD_PKCS7SIGNEDVECTOR(
  48111. data, (word32)sizeof(data), SHA512h, ECDSAk, eccClientPrivKeyBuf,
  48112. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48113. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48114. "pkcs7signedData_ECDSA_SHA512.der", 0, NULL, 0, 0, 0, 0, NULL, 0,
  48115. NULL, 0, 0);
  48116. #endif
  48117. #endif /* HAVE_ECC */
  48118. };
  48119. #undef MAX_TESTVECTORS_LEN
  48120. #undef ADD_PKCS7SIGNEDVECTOR
  48121. outSz = FOURK_BUF;
  48122. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48123. if (out == NULL)
  48124. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48125. XMEMSET(out, 0, outSz);
  48126. /* test inner pad size error with block size being 0 */
  48127. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 0);
  48128. if (ret > 0)
  48129. ERROR_OUT(-1, out);
  48130. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48131. if (ret < 0)
  48132. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48133. #ifndef HAVE_FIPS
  48134. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48135. #else
  48136. ret = wc_InitRng(&rng);
  48137. #endif
  48138. if (ret != 0)
  48139. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48140. for (i = 0; i < testSz; i++) {
  48141. if (pkcs7)
  48142. wc_PKCS7_Free(pkcs7);
  48143. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48144. if (pkcs7 == NULL)
  48145. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48146. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48147. (word32)testVectors[i].certSz);
  48148. if (ret != 0)
  48149. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48150. /* load CA certificate, if present */
  48151. if (testVectors[i].caCert != NULL) {
  48152. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48153. (word32)testVectors[i].caCertSz);
  48154. if (ret != 0)
  48155. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48156. }
  48157. pkcs7->rng = &rng;
  48158. pkcs7->content = (byte*)testVectors[i].content;
  48159. pkcs7->contentSz = testVectors[i].contentSz;
  48160. pkcs7->contentOID = testVectors[i].contentOID;
  48161. pkcs7->hashOID = testVectors[i].hashOID;
  48162. pkcs7->encryptOID = testVectors[i].signOID;
  48163. pkcs7->privateKey = testVectors[i].privateKey;
  48164. pkcs7->privateKeySz = testVectors[i].privateKeySz;
  48165. pkcs7->signedAttribs = testVectors[i].signedAttribs;
  48166. pkcs7->signedAttribsSz = testVectors[i].signedAttribsSz;
  48167. /* optional custom contentType, default is DATA,
  48168. overrides contentOID if set */
  48169. if (testVectors[i].contentType != NULL) {
  48170. ret = wc_PKCS7_SetContentType(pkcs7,
  48171. (byte *)testVectors[i].contentType,
  48172. testVectors[i].contentTypeSz);
  48173. if (ret != 0)
  48174. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48175. }
  48176. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48177. default is IssuerAndSerialNumber */
  48178. if (testVectors[i].sidType == CMS_SKID) {
  48179. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48180. if (ret != 0)
  48181. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48182. }
  48183. /* generate senderNonce */
  48184. {
  48185. senderNonce[0] = 0x04;
  48186. senderNonce[1] = PKCS7_NONCE_SZ;
  48187. ret = wc_RNG_GenerateBlock(&rng, &senderNonce[2], PKCS7_NONCE_SZ);
  48188. if (ret != 0)
  48189. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48190. }
  48191. /* generate transactionID (used with SCEP) */
  48192. {
  48193. #ifndef NO_SHA
  48194. wc_Sha sha;
  48195. byte digest[WC_SHA_DIGEST_SIZE];
  48196. #else
  48197. wc_Sha256 sha;
  48198. byte digest[WC_SHA256_DIGEST_SIZE];
  48199. #endif
  48200. int j,k;
  48201. transId[0] = 0x13;
  48202. transId[1] = sizeof(digest) * 2;
  48203. #ifndef NO_SHA
  48204. ret = wc_InitSha_ex(&sha, HEAP_HINT, devId);
  48205. if (ret != 0)
  48206. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48207. wc_ShaUpdate(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48208. wc_ShaFinal(&sha, digest);
  48209. wc_ShaFree(&sha);
  48210. #else
  48211. ret = wc_InitSha256_ex(&sha, HEAP_HINT, devId);
  48212. if (ret != 0)
  48213. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48214. wc_Sha256Update(&sha, pkcs7->publicKey, pkcs7->publicKeySz);
  48215. wc_Sha256Final(&sha, digest);
  48216. wc_Sha256Free(&sha);
  48217. #endif
  48218. for (j = 0, k = 2; j < (int)sizeof(digest); j++, k += 2) {
  48219. (void)XSNPRINTF((char*)&transId[k], 3, "%02x", digest[j]);
  48220. }
  48221. }
  48222. /* enable detached signature generation, if set */
  48223. if (testVectors[i].detachedSignature == 1) {
  48224. ret = wc_PKCS7_SetDetached(pkcs7, 1);
  48225. if (ret != 0)
  48226. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48227. }
  48228. encodedSz = wc_PKCS7_EncodeSignedData(pkcs7, out, outSz);
  48229. if (encodedSz < 0)
  48230. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48231. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48232. /* write PKCS#7 to output file for more testing */
  48233. file = XFOPEN(testVectors[i].outFileName, "wb");
  48234. if (!file) {
  48235. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48236. }
  48237. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48238. XFCLOSE(file);
  48239. if (ret != (int)encodedSz)
  48240. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48241. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48242. wc_PKCS7_Free(pkcs7);
  48243. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48244. if (pkcs7 == NULL)
  48245. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48246. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48247. if (testVectors[i].detachedSignature == 1) {
  48248. /* set content for verifying detached signatures */
  48249. pkcs7->content = (byte*)testVectors[i].content;
  48250. pkcs7->contentSz = testVectors[i].contentSz;
  48251. }
  48252. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48253. if (ret < 0)
  48254. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48255. /* verify contentType extracted successfully for custom content types */
  48256. if (testVectors[i].contentTypeSz > 0) {
  48257. if (pkcs7->contentTypeSz != testVectors[i].contentTypeSz) {
  48258. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48259. } else if (XMEMCMP(pkcs7->contentType, testVectors[i].contentType,
  48260. pkcs7->contentTypeSz) != 0) {
  48261. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48262. }
  48263. }
  48264. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48265. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48266. {
  48267. /* check getting signed attributes */
  48268. #ifndef NO_SHA
  48269. byte buf[(WC_SHA_DIGEST_SIZE + 1) * 2 + 1];
  48270. #else
  48271. byte buf[(WC_SHA256_DIGEST_SIZE + 1) * 2 + 1];
  48272. #endif
  48273. const byte* oidPt = transIdOid + 2; /* skip object id tag and size */
  48274. int oidSz = (int)sizeof(transIdOid) - 2;
  48275. int bufSz = 0;
  48276. if (testVectors[i].signedAttribs != NULL) {
  48277. ret = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48278. NULL, (word32*)&bufSz);
  48279. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  48280. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48281. ret = 0;
  48282. }
  48283. if (bufSz > (int)sizeof(buf))
  48284. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48285. bufSz = wc_PKCS7_GetAttributeValue(pkcs7, oidPt, (word32)oidSz,
  48286. buf, (word32*)&bufSz);
  48287. if ((testVectors[i].signedAttribs != NULL && bufSz < 0) ||
  48288. (testVectors[i].signedAttribs == NULL && bufSz > 0))
  48289. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48290. }
  48291. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48292. file = XFOPEN("./pkcs7cert.der", "wb");
  48293. if (!file)
  48294. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48295. ret = (int)XFWRITE(pkcs7->singleCert, 1, pkcs7->singleCertSz, file);
  48296. if (ret < 0)
  48297. ret = WC_TEST_RET_ENC_ERRNO;
  48298. else
  48299. ret = 0;
  48300. XFCLOSE(file);
  48301. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48302. }
  48303. out:
  48304. if (pkcs7 != NULL)
  48305. wc_PKCS7_Free(pkcs7);
  48306. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48307. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48308. wc_FreeRng(&rng);
  48309. if (ret > 0)
  48310. return 0;
  48311. (void)rsaClientCertBuf;
  48312. (void)rsaClientCertBufSz;
  48313. (void)rsaClientPrivKeyBuf;
  48314. (void)rsaClientPrivKeyBufSz;
  48315. (void)rsaServerCertBuf;
  48316. (void)rsaServerCertBufSz;
  48317. (void)rsaServerPrivKeyBuf;
  48318. (void)rsaServerPrivKeyBufSz;
  48319. (void)rsaCaCertBuf;
  48320. (void)rsaCaCertBufSz;
  48321. (void)rsaCaPrivKeyBuf;
  48322. (void)rsaCaPrivKeyBufSz;
  48323. (void)eccClientCertBuf;
  48324. (void)eccClientCertBufSz;
  48325. (void)eccClientPrivKeyBuf;
  48326. (void)eccClientPrivKeyBufSz;
  48327. return ret;
  48328. }
  48329. static wc_test_ret_t pkcs7signed_run_SingleShotVectors(
  48330. byte* rsaClientCertBuf, word32 rsaClientCertBufSz,
  48331. byte* rsaClientPrivKeyBuf, word32 rsaClientPrivKeyBufSz,
  48332. byte* rsaServerCertBuf, word32 rsaServerCertBufSz,
  48333. byte* rsaServerPrivKeyBuf, word32 rsaServerPrivKeyBufSz,
  48334. byte* rsaCaCertBuf, word32 rsaCaCertBufSz,
  48335. byte* rsaCaPrivKeyBuf, word32 rsaCaPrivKeyBufSz,
  48336. byte* eccClientCertBuf, word32 eccClientCertBufSz,
  48337. byte* eccClientPrivKeyBuf, word32 eccClientPrivKeyBufSz)
  48338. {
  48339. wc_test_ret_t ret;
  48340. int testSz = 0, i;
  48341. int encodedSz;
  48342. byte* out = NULL;
  48343. word32 outSz;
  48344. WC_RNG rng;
  48345. wc_PKCS7* pkcs7 = NULL;
  48346. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48347. XFILE file;
  48348. #endif
  48349. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48350. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48351. byte* encryptedTmp = NULL;
  48352. int encryptedTmpSz;
  48353. #endif
  48354. WOLFSSL_SMALL_STACK_STATIC const byte data[] = { /* Hello World */
  48355. 0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,
  48356. 0x72,0x6c,0x64
  48357. };
  48358. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48359. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48360. static const byte aes256Key[] = {
  48361. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48362. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48363. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
  48364. 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
  48365. };
  48366. #endif
  48367. static const byte messageTypeOid[] =
  48368. { 0x06, 0x0a, 0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01,
  48369. 0x09, 0x02 };
  48370. static const byte messageType[] = { 0x13, 2, '1', '9' };
  48371. PKCS7Attrib attribs[] =
  48372. {
  48373. { messageTypeOid, sizeof(messageTypeOid), messageType,
  48374. sizeof(messageType) },
  48375. };
  48376. #define MAX_TESTVECTORS_LEN 19
  48377. #define ADD_PKCS7SIGNEDVECTOR(...) { \
  48378. pkcs7SignedVector _this_vector = { __VA_ARGS__ }; \
  48379. if (testSz == MAX_TESTVECTORS_LEN) { \
  48380. ret = WC_TEST_RET_ENC_NC; \
  48381. goto out; \
  48382. } \
  48383. XMEMCPY(&testVectors[testSz++], &_this_vector, \
  48384. sizeof _this_vector); \
  48385. }
  48386. pkcs7SignedVector *testVectors = NULL;
  48387. XMEMSET(&rng, 0, sizeof(rng));
  48388. testVectors = (pkcs7SignedVector *)XMALLOC(MAX_TESTVECTORS_LEN * sizeof(*testVectors),
  48389. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48390. if (testVectors == NULL) {
  48391. ret = WC_TEST_RET_ENC_ERRNO;
  48392. goto out;
  48393. }
  48394. {
  48395. #ifndef NO_RSA
  48396. #ifndef NO_SHA256
  48397. /* Signed FirmwarePkgData, RSA, SHA256, no attribs */
  48398. ADD_PKCS7SIGNEDVECTOR(
  48399. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48400. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48401. NULL, 0,
  48402. "pkcs7signedFirmwarePkgData_RSA_SHA256_noattr.der", 0, NULL, 0, 0,
  48403. 0, 0, NULL, 0, NULL, 0, 0);
  48404. /* Signed FirmwarePkgData, RSA, SHA256, attrs */
  48405. ADD_PKCS7SIGNEDVECTOR(
  48406. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48407. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48408. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48409. "pkcs7signedFirmwarePkgData_RSA_SHA256.der", 0, NULL, 0, 0, 0, 0,
  48410. NULL, 0, NULL, 0, 0);
  48411. /* Signed FirmwarePkgData, RSA, SHA256, SubjectKeyIdentifier, attrs */
  48412. ADD_PKCS7SIGNEDVECTOR(
  48413. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48414. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48415. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48416. "pkcs7signedFirmwarePkgData_RSA_SHA256_SKID.der", 0, NULL,
  48417. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48418. /* Signed FirmwraePkgData, RSA, SHA256, server cert and ca cert, attr */
  48419. ADD_PKCS7SIGNEDVECTOR(
  48420. data, (word32)sizeof(data), SHA256h, RSAk, rsaServerPrivKeyBuf,
  48421. rsaServerPrivKeyBufSz, rsaServerCertBuf, rsaServerCertBufSz,
  48422. rsaCaCertBuf, rsaCaCertBufSz,
  48423. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48424. "pkcs7signedFirmwarePkgData_RSA_SHA256_with_ca_cert.der", 0, NULL,
  48425. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48426. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48427. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48428. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, no attribs */
  48429. ADD_PKCS7SIGNEDVECTOR(
  48430. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48431. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48432. NULL, 0,
  48433. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48434. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48435. /* Signed Encrypted FirmwarePkgData, RSA, SHA256, attribs */
  48436. ADD_PKCS7SIGNEDVECTOR(
  48437. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48438. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48439. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48440. "pkcs7signedEncryptedFirmwarePkgData_RSA_SHA256.der", 0,
  48441. NULL, 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48442. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48443. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48444. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48445. /* Signed Compressed FirmwarePkgData, RSA, SHA256, no attribs */
  48446. ADD_PKCS7SIGNEDVECTOR(
  48447. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48448. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48449. NULL, 0,
  48450. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256_noattr.der", 0,
  48451. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48452. /* Signed Compressed FirmwarePkgData, RSA, SHA256, attribs */
  48453. ADD_PKCS7SIGNEDVECTOR(
  48454. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48455. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48456. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48457. "pkcs7signedCompressedFirmwarePkgData_RSA_SHA256.der", 0,
  48458. NULL, 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48459. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48460. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48461. no attribs */
  48462. ADD_PKCS7SIGNEDVECTOR(
  48463. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48464. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48465. NULL, 0,
  48466. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256_noattr.der",
  48467. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48468. 0, 0);
  48469. /* Signed Encrypted Compressed FirmwarePkgData, RSA, SHA256,
  48470. attribs */
  48471. ADD_PKCS7SIGNEDVECTOR(
  48472. data, (word32)sizeof(data), SHA256h, RSAk, rsaClientPrivKeyBuf,
  48473. rsaClientPrivKeyBufSz, rsaClientCertBuf, rsaClientCertBufSz, NULL, 0,
  48474. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48475. "pkcs7signedEncryptedCompressedFirmwarePkgData_RSA_SHA256.der",
  48476. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48477. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48478. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48479. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48480. #endif /* NO_SHA256 */
  48481. #endif /* NO_RSA */
  48482. #ifdef HAVE_ECC
  48483. #ifndef NO_SHA256
  48484. /* Signed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48485. ADD_PKCS7SIGNEDVECTOR(
  48486. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48487. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48488. NULL, 0,
  48489. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48490. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48491. /* Signed FirmwarePkgData, ECDSA, SHA256, attribs */
  48492. ADD_PKCS7SIGNEDVECTOR(
  48493. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48494. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48495. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48496. "pkcs7signedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48497. 0, 0, 0, 0, NULL, 0, NULL, 0, 0);
  48498. /* Signed FirmwarePkgData, ECDSA, SHA256, SubjectKeyIdentifier, attr */
  48499. ADD_PKCS7SIGNEDVECTOR(
  48500. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48501. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48502. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48503. "pkcs7signedFirmwarePkgData_ECDSA_SHA256_SKID.der", 0, NULL,
  48504. 0, CMS_SKID, 0, 0, NULL, 0, NULL, 0, 0);
  48505. #if !defined(NO_PKCS7_ENCRYPTED_DATA) && \
  48506. defined(HAVE_AES_CBC) && defined(WOLFSSL_AES_256)
  48507. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, no attribs */
  48508. ADD_PKCS7SIGNEDVECTOR(
  48509. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48510. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48511. NULL, 0,
  48512. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48513. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key), NULL, 0, 0);
  48514. /* Signed Encrypted FirmwarePkgData, ECDSA, SHA256, attribs */
  48515. ADD_PKCS7SIGNEDVECTOR(
  48516. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48517. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48518. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48519. "pkcs7signedEncryptedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48520. 0, 0, AES256CBCb, 1, aes256Key, sizeof(aes256Key),
  48521. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48522. #endif /* WOLFSSL_AES_256 && !NO_PKCS7_ENCRYPTED_DATA */
  48523. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48524. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, no attribs */
  48525. ADD_PKCS7SIGNEDVECTOR(
  48526. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48527. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48528. NULL, 0,
  48529. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der", 0, NULL,
  48530. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48531. /* Signed Compressed FirmwarePkgData, ECDSA, SHA256, attrib */
  48532. ADD_PKCS7SIGNEDVECTOR(
  48533. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48534. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48535. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48536. "pkcs7signedCompressedFirmwarePkgData_ECDSA_SHA256.der", 0, NULL,
  48537. 0, 0, 0, 2, NULL, 0, NULL, 0, 0);
  48538. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48539. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48540. no attribs */
  48541. ADD_PKCS7SIGNEDVECTOR(
  48542. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48543. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48544. NULL, 0,
  48545. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256_noattr.der",
  48546. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key), NULL,
  48547. 0, 0);
  48548. /* Signed Encrypted Compressed FirmwarePkgData, ECDSA, SHA256,
  48549. attribs */
  48550. ADD_PKCS7SIGNEDVECTOR(
  48551. data, (word32)sizeof(data), SHA256h, ECDSAk, eccClientPrivKeyBuf,
  48552. eccClientPrivKeyBufSz, eccClientCertBuf, eccClientCertBufSz, NULL, 0,
  48553. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)),
  48554. "pkcs7signedEncryptedCompressedFirmwarePkgData_ECDSA_SHA256.der",
  48555. 0, NULL, 0, 0, AES256CBCb, 3, aes256Key, sizeof(aes256Key),
  48556. attribs, (sizeof(attribs)/sizeof(PKCS7Attrib)), 0);
  48557. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  48558. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48559. #endif /* NO_SHA256 */
  48560. #endif /* HAVE_ECC */
  48561. };
  48562. #undef MAX_TESTVECTORS_LEN
  48563. #undef ADD_PKCS7SIGNEDVECTOR
  48564. outSz = FOURK_BUF;
  48565. out = (byte*)XMALLOC(outSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48566. if (out == NULL)
  48567. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48568. XMEMSET(out, 0, outSz);
  48569. ret = wc_PKCS7_PadData((byte*)data, sizeof(data), out, outSz, 16);
  48570. if (ret < 0)
  48571. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48572. #ifndef HAVE_FIPS
  48573. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  48574. #else
  48575. ret = wc_InitRng(&rng);
  48576. #endif
  48577. if (ret != 0)
  48578. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48579. for (i = 0; i < testSz; i++) {
  48580. if (pkcs7)
  48581. wc_PKCS7_Free(pkcs7);
  48582. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48583. if (pkcs7 == NULL)
  48584. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48585. ret = wc_PKCS7_InitWithCert(pkcs7, testVectors[i].cert,
  48586. (word32)testVectors[i].certSz);
  48587. if (ret != 0)
  48588. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48589. /* load CA certificate, if present */
  48590. if (testVectors[i].caCert != NULL) {
  48591. ret = wc_PKCS7_AddCertificate(pkcs7, testVectors[i].caCert,
  48592. (word32)testVectors[i].caCertSz);
  48593. if (ret != 0)
  48594. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48595. }
  48596. /* set SignerIdentifier to use SubjectKeyIdentifier if desired,
  48597. default is IssuerAndSerialNumber */
  48598. if (testVectors[i].sidType == CMS_SKID) {
  48599. ret = wc_PKCS7_SetSignerIdentifierType(pkcs7, CMS_SKID);
  48600. if (ret != 0)
  48601. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48602. }
  48603. if (testVectors[i].encCompFlag == 0) {
  48604. /* encode Signed FirmwarePkgData */
  48605. encodedSz = wc_PKCS7_EncodeSignedFPD(pkcs7,
  48606. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48607. testVectors[i].signOID, testVectors[i].hashOID,
  48608. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48609. testVectors[i].signedAttribs,
  48610. testVectors[i].signedAttribsSz, out, outSz);
  48611. if (encodedSz < 0)
  48612. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48613. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48614. } else if (testVectors[i].encCompFlag == 1) {
  48615. /* encode Signed Encrypted FirmwarePkgData */
  48616. encodedSz = wc_PKCS7_EncodeSignedEncryptedFPD(pkcs7,
  48617. (byte *)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48618. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48619. testVectors[i].encryptOID, testVectors[i].signOID,
  48620. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48621. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48622. testVectors[i].unprotectedAttribsSz,
  48623. testVectors[i].signedAttribs,
  48624. testVectors[i].signedAttribsSz, out, outSz);
  48625. if (encodedSz <= 0)
  48626. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48627. #endif
  48628. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48629. } else if (testVectors[i].encCompFlag == 2) {
  48630. /* encode Signed Compressed FirmwarePkgData */
  48631. encodedSz = wc_PKCS7_EncodeSignedCompressedFPD(pkcs7,
  48632. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48633. testVectors[i].signOID, testVectors[i].hashOID,
  48634. (byte*)testVectors[i].content, testVectors[i].contentSz,
  48635. testVectors[i].signedAttribs,
  48636. testVectors[i].signedAttribsSz, out, outSz);
  48637. if (encodedSz <= 0)
  48638. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48639. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48640. } else if (testVectors[i].encCompFlag == 3) {
  48641. /* encode Signed Encrypted Compressed FirmwarePkgData */
  48642. encodedSz = wc_PKCS7_EncodeSignedEncryptedCompressedFPD(pkcs7,
  48643. (byte*)testVectors[i].encryptKey, testVectors[i].encryptKeySz,
  48644. testVectors[i].privateKey, testVectors[i].privateKeySz,
  48645. testVectors[i].encryptOID, testVectors[i].signOID,
  48646. testVectors[i].hashOID, (byte*)testVectors[i].content,
  48647. testVectors[i].contentSz, testVectors[i].unprotectedAttribs,
  48648. testVectors[i].unprotectedAttribsSz,
  48649. testVectors[i].signedAttribs,
  48650. testVectors[i].signedAttribsSz, out, outSz);
  48651. if (encodedSz <= 0)
  48652. ERROR_OUT(WC_TEST_RET_ENC_EC(encodedSz), out);
  48653. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48654. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48655. } else {
  48656. /* unsupported SignedData single-shot combination */
  48657. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48658. }
  48659. #ifdef PKCS7_OUTPUT_TEST_BUNDLES
  48660. /* write PKCS#7 to output file for more testing */
  48661. file = XFOPEN(testVectors[i].outFileName, "wb");
  48662. if (!file)
  48663. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48664. ret = (int)XFWRITE(out, 1, encodedSz, file);
  48665. XFCLOSE(file);
  48666. file = NULL;
  48667. if (ret != (int)encodedSz)
  48668. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48669. #endif /* PKCS7_OUTPUT_TEST_BUNDLES */
  48670. wc_PKCS7_Free(pkcs7);
  48671. pkcs7 = wc_PKCS7_New(HEAP_HINT, devId);
  48672. if (pkcs7 == NULL)
  48673. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48674. wc_PKCS7_InitWithCert(pkcs7, NULL, 0);
  48675. ret = wc_PKCS7_VerifySignedData(pkcs7, out, outSz);
  48676. if (ret < 0)
  48677. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48678. #ifndef NO_PKCS7_STREAM
  48679. {
  48680. word32 z;
  48681. for (z = 0; z < outSz && ret != 0; z++) {
  48682. ret = wc_PKCS7_VerifySignedData(pkcs7, out + z, 1);
  48683. if (ret < 0 && ret != WC_NO_ERR_TRACE(WC_PKCS7_WANT_READ_E)) {
  48684. printf("unexpected error %d\n", ret);
  48685. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48686. }
  48687. }
  48688. }
  48689. #endif
  48690. if (pkcs7->singleCert == NULL || pkcs7->singleCertSz == 0)
  48691. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48692. if (testVectors[i].encCompFlag == 0) {
  48693. /* verify decoded content matches expected */
  48694. if ((pkcs7->contentSz != testVectors[i].contentSz) ||
  48695. XMEMCMP(pkcs7->content, testVectors[i].content,
  48696. pkcs7->contentSz)) {
  48697. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48698. }
  48699. }
  48700. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48701. else if (testVectors[i].encCompFlag == 1) {
  48702. /* decrypt inner encryptedData */
  48703. pkcs7->encryptionKey = (byte *)testVectors[i].encryptKey;
  48704. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48705. ret = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48706. pkcs7->contentSz, out, outSz);
  48707. if (ret < 0)
  48708. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48709. /* compare decrypted to expected */
  48710. if (((word32)ret != testVectors[i].contentSz) ||
  48711. XMEMCMP(out, testVectors[i].content, ret))
  48712. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48713. }
  48714. #endif
  48715. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  48716. else if (testVectors[i].encCompFlag == 2) {
  48717. /* decompress inner compressedData */
  48718. ret = wc_PKCS7_DecodeCompressedData(pkcs7, pkcs7->content,
  48719. pkcs7->contentSz, out, outSz);
  48720. if (ret < 0)
  48721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48722. /* compare decompressed to expected */
  48723. if (((word32)ret != testVectors[i].contentSz) ||
  48724. XMEMCMP(out, testVectors[i].content, ret))
  48725. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48726. }
  48727. #ifndef NO_PKCS7_ENCRYPTED_DATA
  48728. else if (testVectors[i].encCompFlag == 3) {
  48729. encryptedTmpSz = FOURK_BUF;
  48730. encryptedTmp = (byte*)XMALLOC(encryptedTmpSz, HEAP_HINT,
  48731. DYNAMIC_TYPE_TMP_BUFFER);
  48732. if (encryptedTmp == NULL)
  48733. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out);
  48734. XMEMSET(encryptedTmp, 0, encryptedTmpSz);
  48735. /* decrypt inner encryptedData */
  48736. pkcs7->encryptionKey = (byte*)testVectors[i].encryptKey;
  48737. pkcs7->encryptionKeySz = testVectors[i].encryptKeySz;
  48738. encryptedTmpSz = wc_PKCS7_DecodeEncryptedData(pkcs7, pkcs7->content,
  48739. pkcs7->contentSz, encryptedTmp,
  48740. encryptedTmpSz);
  48741. if (encryptedTmpSz < 0 || pkcs7->contentOID != COMPRESSED_DATA)
  48742. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48743. /* decompress inner compressedData */
  48744. ret = wc_PKCS7_DecodeCompressedData(pkcs7, encryptedTmp,
  48745. encryptedTmpSz, out, outSz);
  48746. if (ret < 0)
  48747. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  48748. /* compare decompressed to expected */
  48749. if (((word32)ret != testVectors[i].contentSz) ||
  48750. XMEMCMP(out, testVectors[i].content, ret))
  48751. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  48752. }
  48753. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  48754. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  48755. }
  48756. out:
  48757. if (pkcs7 != NULL)
  48758. wc_PKCS7_Free(pkcs7);
  48759. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48760. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA) && \
  48761. !defined(NO_PKCS7_ENCRYPTED_DATA)
  48762. XFREE(encryptedTmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48763. #endif
  48764. XFREE(testVectors, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48765. wc_FreeRng(&rng);
  48766. if (ret > 0)
  48767. return 0;
  48768. (void)eccClientCertBuf;
  48769. (void)eccClientCertBufSz;
  48770. (void)eccClientPrivKeyBuf;
  48771. (void)eccClientPrivKeyBufSz;
  48772. (void)rsaClientCertBuf;
  48773. (void)rsaClientCertBufSz;
  48774. (void)rsaClientPrivKeyBuf;
  48775. (void)rsaClientPrivKeyBufSz;
  48776. (void)rsaServerCertBuf;
  48777. (void)rsaServerCertBufSz;
  48778. (void)rsaServerPrivKeyBuf;
  48779. (void)rsaServerPrivKeyBufSz;
  48780. (void)rsaCaCertBuf;
  48781. (void)rsaCaCertBufSz;
  48782. (void)rsaCaPrivKeyBuf;
  48783. (void)rsaCaPrivKeyBufSz;
  48784. return ret;
  48785. }
  48786. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t pkcs7signed_test(void)
  48787. {
  48788. wc_test_ret_t ret = 0;
  48789. byte* rsaClientCertBuf = NULL;
  48790. byte* rsaServerCertBuf = NULL;
  48791. byte* rsaCaCertBuf = NULL;
  48792. byte* eccClientCertBuf = NULL;
  48793. byte* rsaClientPrivKeyBuf = NULL;
  48794. byte* rsaServerPrivKeyBuf = NULL;
  48795. byte* rsaCaPrivKeyBuf = NULL;
  48796. byte* eccClientPrivKeyBuf = NULL;
  48797. word32 rsaClientCertBufSz = 0;
  48798. word32 rsaServerCertBufSz = 0;
  48799. word32 rsaCaCertBufSz = 0;
  48800. word32 eccClientCertBufSz = 0;
  48801. word32 rsaClientPrivKeyBufSz = 0;
  48802. word32 rsaServerPrivKeyBufSz = 0;
  48803. word32 rsaCaPrivKeyBufSz = 0;
  48804. word32 eccClientPrivKeyBufSz = 0;
  48805. WOLFSSL_ENTER("pkcs7signed_test");
  48806. #ifndef NO_RSA
  48807. /* read client RSA cert and key in DER format */
  48808. rsaClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48809. DYNAMIC_TYPE_TMP_BUFFER);
  48810. if (rsaClientCertBuf == NULL)
  48811. ret = WC_TEST_RET_ENC_NC;
  48812. rsaClientPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48813. DYNAMIC_TYPE_TMP_BUFFER);
  48814. if (ret == 0 && rsaClientPrivKeyBuf == NULL) {
  48815. ret = WC_TEST_RET_ENC_ERRNO;
  48816. }
  48817. rsaClientCertBufSz = FOURK_BUF;
  48818. rsaClientPrivKeyBufSz = FOURK_BUF;
  48819. /* read server RSA cert and key in DER format */
  48820. rsaServerCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48821. DYNAMIC_TYPE_TMP_BUFFER);
  48822. if (ret == 0 && rsaServerCertBuf == NULL)
  48823. ret = WC_TEST_RET_ENC_NC;
  48824. rsaServerPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48825. DYNAMIC_TYPE_TMP_BUFFER);
  48826. if (ret == 0 && rsaServerPrivKeyBuf == NULL) {
  48827. ret = WC_TEST_RET_ENC_ERRNO;
  48828. }
  48829. rsaServerCertBufSz = FOURK_BUF;
  48830. rsaServerPrivKeyBufSz = FOURK_BUF;
  48831. /* read CA RSA cert and key in DER format, for use with server cert */
  48832. rsaCaCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48833. DYNAMIC_TYPE_TMP_BUFFER);
  48834. if (ret == 0 && rsaCaCertBuf == NULL)
  48835. ret = WC_TEST_RET_ENC_NC;
  48836. rsaCaPrivKeyBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48837. DYNAMIC_TYPE_TMP_BUFFER);
  48838. if (ret == 0 && rsaCaPrivKeyBuf == NULL) {
  48839. ret = WC_TEST_RET_ENC_ERRNO;
  48840. }
  48841. rsaCaCertBufSz = FOURK_BUF;
  48842. rsaCaPrivKeyBufSz = FOURK_BUF;
  48843. #endif /* NO_RSA */
  48844. #ifdef HAVE_ECC
  48845. /* read client ECC cert and key in DER format */
  48846. eccClientCertBuf = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48847. DYNAMIC_TYPE_TMP_BUFFER);
  48848. if (ret == 0 && eccClientCertBuf == NULL) {
  48849. ret = WC_TEST_RET_ENC_ERRNO;
  48850. }
  48851. eccClientPrivKeyBuf =(byte*)XMALLOC(FOURK_BUF, HEAP_HINT,
  48852. DYNAMIC_TYPE_TMP_BUFFER);
  48853. if (ret == 0 && eccClientPrivKeyBuf == NULL) {
  48854. ret = WC_TEST_RET_ENC_ERRNO;
  48855. }
  48856. eccClientCertBufSz = FOURK_BUF;
  48857. eccClientPrivKeyBufSz = FOURK_BUF;
  48858. #endif /* HAVE_ECC */
  48859. if (ret >= 0)
  48860. ret = pkcs7_load_certs_keys(rsaClientCertBuf, &rsaClientCertBufSz,
  48861. rsaClientPrivKeyBuf, &rsaClientPrivKeyBufSz,
  48862. rsaServerCertBuf, &rsaServerCertBufSz,
  48863. rsaServerPrivKeyBuf, &rsaServerPrivKeyBufSz,
  48864. rsaCaCertBuf, &rsaCaCertBufSz,
  48865. rsaCaPrivKeyBuf, &rsaCaPrivKeyBufSz,
  48866. eccClientCertBuf, &eccClientCertBufSz,
  48867. eccClientPrivKeyBuf, &eccClientPrivKeyBufSz);
  48868. if (ret < 0) {
  48869. ret = WC_TEST_RET_ENC_EC(ret);
  48870. }
  48871. if (ret >= 0)
  48872. ret = pkcs7signed_run_vectors(rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48873. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48874. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48875. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48876. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48877. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48878. eccClientCertBuf, (word32)eccClientCertBufSz,
  48879. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48880. if (ret >= 0)
  48881. ret = pkcs7signed_run_SingleShotVectors(
  48882. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48883. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz,
  48884. rsaServerCertBuf, (word32)rsaServerCertBufSz,
  48885. rsaServerPrivKeyBuf, (word32)rsaServerPrivKeyBufSz,
  48886. rsaCaCertBuf, (word32)rsaCaCertBufSz,
  48887. rsaCaPrivKeyBuf, (word32)rsaCaPrivKeyBufSz,
  48888. eccClientCertBuf, (word32)eccClientCertBufSz,
  48889. eccClientPrivKeyBuf, (word32)eccClientPrivKeyBufSz);
  48890. #if !defined(NO_RSA) && !defined(NO_AES) && defined(HAVE_AES_CBC)
  48891. if (ret >= 0)
  48892. ret = pkcs7callback_test(
  48893. rsaClientCertBuf, (word32)rsaClientCertBufSz,
  48894. rsaClientPrivKeyBuf, (word32)rsaClientPrivKeyBufSz);
  48895. #endif
  48896. XFREE(rsaClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48897. XFREE(rsaClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48898. XFREE(rsaServerCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48899. XFREE(rsaServerPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48900. XFREE(rsaCaCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48901. XFREE(rsaCaPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48902. XFREE(eccClientCertBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48903. XFREE(eccClientPrivKeyBuf, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  48904. return ret;
  48905. }
  48906. #endif /* HAVE_PKCS7 */
  48907. #if defined(WOLFSSL_PUBLIC_MP) && \
  48908. ((defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48909. defined(USE_FAST_MATH))
  48910. /* Maximum number of bytes in a number to test. */
  48911. #define MP_MAX_TEST_BYTE_LEN 32
  48912. static wc_test_ret_t randNum(mp_int* n, int len, WC_RNG* rng, void* heap)
  48913. {
  48914. byte d[MP_MAX_TEST_BYTE_LEN];
  48915. wc_test_ret_t ret;
  48916. (void)heap;
  48917. do {
  48918. ret = wc_RNG_GenerateBlock(rng, d, (word32)len);
  48919. if (ret != 0)
  48920. return ret;
  48921. ret = mp_read_unsigned_bin(n, d, (word32)len);
  48922. if (ret != 0)
  48923. return ret;
  48924. } while (mp_iszero(n));
  48925. return 0;
  48926. }
  48927. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  48928. static wc_test_ret_t mp_test_div_3(mp_int* a, mp_int* r, WC_RNG* rng)
  48929. {
  48930. int i, j;
  48931. mp_digit rem;
  48932. mp_digit rem2;
  48933. wc_test_ret_t ret;
  48934. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  48935. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  48936. for (i = 0; i < 10; i++) {
  48937. for (j = 1; j < 10; j++) {
  48938. ret = randNum(a, j, rng, NULL);
  48939. if (ret != 0)
  48940. return WC_TEST_RET_ENC_EC(ret);
  48941. ret = mp_div_3(a, r, &rem);
  48942. if (ret != 0)
  48943. return WC_TEST_RET_ENC_EC(ret);
  48944. ret = mp_mul_d(r, 3, r);
  48945. if (ret != 0)
  48946. return WC_TEST_RET_ENC_EC(ret);
  48947. ret = mp_add_d(r, rem, r);
  48948. if (ret != 0)
  48949. return WC_TEST_RET_ENC_EC(ret);
  48950. ret = mp_cmp(r, a);
  48951. if (ret != MP_EQ)
  48952. return WC_TEST_RET_ENC_NC;
  48953. }
  48954. }
  48955. ret = mp_div_3(a, r, &rem);
  48956. if (ret != 0)
  48957. return WC_TEST_RET_ENC_NC;
  48958. ret = mp_div_3(a, a, NULL);
  48959. if (ret != 0)
  48960. return WC_TEST_RET_ENC_NC;
  48961. ret = mp_cmp(r, a);
  48962. if (ret != MP_EQ)
  48963. return WC_TEST_RET_ENC_NC;
  48964. #endif
  48965. #if defined(WOLFSSL_SP_MATH_ALL)
  48966. ret = mp_div_d(a, 10, r, &rem);
  48967. if (ret != 0)
  48968. return WC_TEST_RET_ENC_EC(ret);
  48969. ret = mp_div_d(a, 10, a, NULL);
  48970. if (ret != 0)
  48971. return WC_TEST_RET_ENC_EC(ret);
  48972. ret = mp_cmp(r, a);
  48973. if (ret != MP_EQ)
  48974. return WC_TEST_RET_ENC_NC;
  48975. ret = mp_div_d(a, 12, r, &rem);
  48976. if (ret != 0)
  48977. return WC_TEST_RET_ENC_EC(ret);
  48978. ret = mp_div_d(a, 12, a, NULL);
  48979. if (ret != 0)
  48980. return WC_TEST_RET_ENC_EC(ret);
  48981. ret = mp_cmp(r, a);
  48982. if (ret != MP_EQ)
  48983. return WC_TEST_RET_ENC_NC;
  48984. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), r, &rem);
  48985. if (ret != 0)
  48986. return WC_TEST_RET_ENC_EC(ret);
  48987. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), NULL, &rem2);
  48988. if (ret != 0)
  48989. return WC_TEST_RET_ENC_EC(ret);
  48990. ret = mp_div_d(a, (mp_digit)1 << (DIGIT_BIT / 2), a, NULL);
  48991. if (ret != 0)
  48992. return WC_TEST_RET_ENC_EC(ret);
  48993. ret = mp_cmp(r, a);
  48994. if (ret != MP_EQ)
  48995. return WC_TEST_RET_ENC_NC;
  48996. if (rem != rem2)
  48997. return WC_TEST_RET_ENC_NC;
  48998. #endif
  48999. (void)a;
  49000. (void)r;
  49001. (void)rng;
  49002. (void)i;
  49003. (void)j;
  49004. (void)rem;
  49005. (void)rem2;
  49006. (void)ret;
  49007. return 0;
  49008. }
  49009. #endif /* WOLFSSL_SP_MATH || !USE_FAST_MATH */
  49010. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49011. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49012. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  49013. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  49014. static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
  49015. {
  49016. wc_test_ret_t ret;
  49017. int i, j;
  49018. int size;
  49019. char str[30];
  49020. WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
  49021. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
  49022. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49023. WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
  49024. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49025. for (i = 0; i < 10; i++) {
  49026. for (j = 2; j < 12; j++) {
  49027. ret = randNum(a, j, rng, NULL);
  49028. if (ret != 0)
  49029. return WC_TEST_RET_ENC_EC(ret);
  49030. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49031. if (ret != MP_OKAY)
  49032. return WC_TEST_RET_ENC_EC(ret);
  49033. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49034. if (ret != MP_OKAY)
  49035. return WC_TEST_RET_ENC_EC(ret);
  49036. if ((int)XSTRLEN(str) != size - 1)
  49037. return WC_TEST_RET_ENC_NC;
  49038. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49039. if (ret != MP_OKAY)
  49040. return WC_TEST_RET_ENC_EC(ret);
  49041. ret = mp_cmp(a, r);
  49042. if (ret != MP_EQ)
  49043. return WC_TEST_RET_ENC_NC;
  49044. }
  49045. }
  49046. ret = mp_read_radix(r, badStr1, MP_RADIX_DEC);
  49047. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49048. return WC_TEST_RET_ENC_EC(ret);
  49049. ret = mp_read_radix(r, badStr2, MP_RADIX_DEC);
  49050. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49051. return WC_TEST_RET_ENC_EC(ret);
  49052. ret = mp_read_radix(r, empty2, MP_RADIX_DEC);
  49053. if (ret != MP_OKAY)
  49054. return WC_TEST_RET_ENC_EC(ret);
  49055. ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
  49056. if (ret != MP_OKAY)
  49057. return WC_TEST_RET_ENC_EC(ret);
  49058. if (!mp_iszero(r))
  49059. return WC_TEST_RET_ENC_NC;
  49060. mp_set(r, 1);
  49061. ret = mp_read_radix(r, empty, MP_RADIX_DEC);
  49062. if (ret != MP_OKAY)
  49063. return WC_TEST_RET_ENC_EC(ret);
  49064. if (!mp_iszero(r))
  49065. return WC_TEST_RET_ENC_NC;
  49066. mp_zero(a);
  49067. ret = mp_radix_size(a, MP_RADIX_DEC, &size);
  49068. if (ret != 0)
  49069. return WC_TEST_RET_ENC_EC(ret);
  49070. if (size != 2)
  49071. return WC_TEST_RET_ENC_NC;
  49072. ret = mp_toradix(a, str, MP_RADIX_DEC);
  49073. if (ret != 0)
  49074. return WC_TEST_RET_ENC_EC(ret);
  49075. if ((int)XSTRLEN(str) != size - 1)
  49076. return WC_TEST_RET_ENC_NC;
  49077. ret = mp_read_radix(r, str, MP_RADIX_DEC);
  49078. if (ret != 0)
  49079. return WC_TEST_RET_ENC_EC(ret);
  49080. if (!mp_iszero(r))
  49081. return WC_TEST_RET_ENC_NC;
  49082. return 0;
  49083. }
  49084. #endif
  49085. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  49086. defined(HAVE_ECC))
  49087. static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
  49088. {
  49089. wc_test_ret_t ret;
  49090. int i, j;
  49091. int size;
  49092. char str[30];
  49093. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49094. static char longStr[2 * sizeof(a->dp) + 2];
  49095. #endif
  49096. WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
  49097. WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
  49098. WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
  49099. for (i = 0; i < 10; i++) {
  49100. for (j = 2; j < 12; j++) {
  49101. ret = randNum(a, j, rng, NULL);
  49102. if (ret != 0)
  49103. return WC_TEST_RET_ENC_EC(ret);
  49104. mp_radix_size(a, MP_RADIX_HEX, &size);
  49105. mp_toradix(a, str, MP_RADIX_HEX);
  49106. if ((int)XSTRLEN(str) != size - 1)
  49107. return WC_TEST_RET_ENC_NC;
  49108. mp_read_radix(r, str, MP_RADIX_HEX);
  49109. ret = mp_cmp(a, r);
  49110. if (ret != MP_EQ)
  49111. return WC_TEST_RET_ENC_NC;
  49112. }
  49113. }
  49114. ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
  49115. if (ret != MP_OKAY)
  49116. return WC_TEST_RET_ENC_EC(ret);
  49117. ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
  49118. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49119. return WC_TEST_RET_ENC_EC(ret);
  49120. mp_set(r, 1);
  49121. ret = mp_read_radix(r, empty, MP_RADIX_HEX);
  49122. if (ret != MP_OKAY)
  49123. return WC_TEST_RET_ENC_EC(ret);
  49124. if (!mp_iszero(r))
  49125. return WC_TEST_RET_ENC_NC;
  49126. #if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
  49127. /* Fixed MP data size - string can be too long. */
  49128. longStr[0] = '8';
  49129. XMEMSET(longStr+1, '0', sizeof(longStr) - 2);
  49130. longStr[sizeof(longStr)-1] = '\0';
  49131. ret = mp_read_radix(r, longStr, MP_RADIX_HEX);
  49132. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49133. return WC_TEST_RET_ENC_EC(ret);
  49134. #endif
  49135. mp_zero(a);
  49136. ret = mp_radix_size(a, MP_RADIX_HEX, &size);
  49137. if (ret != 0)
  49138. return WC_TEST_RET_ENC_EC(ret);
  49139. #ifndef WC_DISABLE_RADIX_ZERO_PAD
  49140. if (size != 3)
  49141. #else
  49142. if (size != 2)
  49143. #endif
  49144. return WC_TEST_RET_ENC_NC;
  49145. ret = mp_toradix(a, str, MP_RADIX_HEX);
  49146. if (ret != 0)
  49147. return WC_TEST_RET_ENC_EC(ret);
  49148. if ((int)XSTRLEN(str) != size - 1)
  49149. return WC_TEST_RET_ENC_NC;
  49150. ret = mp_read_radix(r, str, MP_RADIX_HEX);
  49151. if (ret != 0)
  49152. return WC_TEST_RET_ENC_EC(ret);
  49153. if (!mp_iszero(r))
  49154. return WC_TEST_RET_ENC_NC;
  49155. #ifdef WOLFSSL_SP_MATH
  49156. ret = mp_toradix(a, str, 8);
  49157. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49158. return WC_TEST_RET_ENC_EC(ret);
  49159. ret = mp_radix_size(a, 8, &size);
  49160. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49161. return WC_TEST_RET_ENC_EC(ret);
  49162. #endif
  49163. return 0;
  49164. }
  49165. #endif
  49166. static wc_test_ret_t mp_test_shift(mp_int* a, mp_int* r1, WC_RNG* rng)
  49167. {
  49168. int i;
  49169. wc_test_ret_t ret;
  49170. ret = randNum(a, 4, rng, NULL);
  49171. if (ret != 0)
  49172. return WC_TEST_RET_ENC_EC(ret);
  49173. for (i = 0; i < 4; i++) {
  49174. mp_copy(r1, a);
  49175. ret = mp_lshd(r1, i);
  49176. if (ret != MP_OKAY)
  49177. return WC_TEST_RET_ENC_EC(ret);
  49178. #ifndef WOLFSSL_SP_MATH
  49179. mp_rshd(r1, i);
  49180. #else
  49181. mp_rshb(r1, i * SP_WORD_SIZE);
  49182. #endif
  49183. ret = mp_cmp(a, r1);
  49184. if (ret != MP_EQ)
  49185. return WC_TEST_RET_ENC_NC;
  49186. }
  49187. #ifndef WOLFSSL_SP_MATH
  49188. for (i = 0; i < DIGIT_BIT+1; i++) {
  49189. ret = mp_mul_2d(a, i, r1);
  49190. if (ret != MP_OKAY)
  49191. return WC_TEST_RET_ENC_EC(ret);
  49192. mp_rshb(r1, i);
  49193. ret = mp_cmp(a, r1);
  49194. if (ret != MP_EQ)
  49195. return WC_TEST_RET_ENC_NC;
  49196. }
  49197. #endif
  49198. return 0;
  49199. }
  49200. static wc_test_ret_t mp_test_add_sub_d(mp_int* a, mp_int* r1)
  49201. {
  49202. int i, j;
  49203. wc_test_ret_t ret;
  49204. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  49205. mp_zero(a);
  49206. mp_set_bit(a, i);
  49207. if ((int)a->used != (i + DIGIT_BIT) / DIGIT_BIT)
  49208. return WC_TEST_RET_ENC_NC;
  49209. for (j = 0; j < i && j < DIGIT_BIT; j++) {
  49210. mp_zero(r1);
  49211. mp_set_bit(r1, i);
  49212. ret = mp_sub_d(r1, (mp_digit)1 << j, r1);
  49213. if (ret != MP_OKAY)
  49214. return WC_TEST_RET_ENC_EC(ret);
  49215. ret = mp_add_d(r1, (mp_digit)1 << j, r1);
  49216. if (ret != MP_OKAY)
  49217. return WC_TEST_RET_ENC_EC(ret);
  49218. ret = mp_cmp(a, r1);
  49219. if (ret != MP_EQ)
  49220. return WC_TEST_RET_ENC_NC;
  49221. }
  49222. }
  49223. mp_zero(r1);
  49224. ret = mp_add_d(r1, 1, r1);
  49225. if (ret != MP_OKAY)
  49226. return WC_TEST_RET_ENC_EC(ret);
  49227. if (r1->used != 1)
  49228. return WC_TEST_RET_ENC_NC;
  49229. ret = mp_sub_d(r1, 1, r1);
  49230. if (ret != MP_OKAY)
  49231. return WC_TEST_RET_ENC_EC(ret);
  49232. if (r1->used != 0)
  49233. return WC_TEST_RET_ENC_NC;
  49234. return 0;
  49235. }
  49236. static wc_test_ret_t mp_test_read_to_bin(mp_int* a)
  49237. {
  49238. WOLFSSL_SMALL_STACK_STATIC const byte in[16] = {
  49239. 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe6, 0xf7, 0x08,
  49240. 0x93, 0xa4, 0xb4, 0xc5, 0xd6, 0xe7, 0xf8, 0x09
  49241. };
  49242. byte out[24];
  49243. int i, j, k;
  49244. const byte* p;
  49245. wc_test_ret_t ret;
  49246. for (i = 0; i < (int)sizeof(in); i++) {
  49247. p = in + sizeof(in) - i;
  49248. ret = mp_read_unsigned_bin(a, p, (word32)i);
  49249. if (ret != 0)
  49250. return WC_TEST_RET_ENC_EC(ret);
  49251. for (j = i; j < (int)sizeof(out); j++) {
  49252. XMEMSET(out, 0xff, sizeof(out));
  49253. ret = mp_to_unsigned_bin_len(a, out, j);
  49254. if (ret != 0)
  49255. return WC_TEST_RET_ENC_EC(ret);
  49256. for (k = 0; k < j - i; k++) {
  49257. if (out[k] != 0)
  49258. return WC_TEST_RET_ENC_NC;
  49259. }
  49260. for (; k < j; k++) {
  49261. if (out[k] != p[k - (j - i)])
  49262. return WC_TEST_RET_ENC_NC;
  49263. }
  49264. }
  49265. }
  49266. /* Length too small. */
  49267. ret = mp_to_unsigned_bin_len(a, out, 1);
  49268. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49269. return WC_TEST_RET_ENC_EC(ret);
  49270. ret = mp_read_unsigned_bin(a, NULL, 0);
  49271. if (ret != 0)
  49272. return WC_TEST_RET_ENC_EC(ret);
  49273. if (!mp_iszero(a))
  49274. return WC_TEST_RET_ENC_NC;
  49275. return 0;
  49276. }
  49277. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49278. static wc_test_ret_t mp_test_set_int(mp_int* a)
  49279. {
  49280. #if SP_ULONG_BITS == 64
  49281. unsigned long n = 0xfedcba9876543210UL;
  49282. byte exp[8] = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
  49283. byte out[8] = { 0 };
  49284. #elif SP_ULONG_BITS == 32
  49285. unsigned long n = 0xfedcba98UL;
  49286. byte exp[4] = { 0xfe, 0xdc, 0xba, 0x98 };
  49287. byte out[4] = { 0 };
  49288. #elif SP_ULONG_BITS == 16
  49289. unsigned long n = 0xfedc;
  49290. byte exp[2] = { 0xfe, 0xdc };
  49291. byte out[2] = { 0 };
  49292. #elif SP_ULONG_BITS == 8
  49293. unsigned long n = 0xfe;
  49294. byte exp[1] = { 0xfe };
  49295. byte out[1] = { 0 };
  49296. #endif
  49297. wc_test_ret_t ret;
  49298. ret = mp_set_int(a, n);
  49299. if (ret != 0)
  49300. return WC_TEST_RET_ENC_EC(ret);
  49301. ret = mp_unsigned_bin_size(a);
  49302. if (ret != sizeof(exp))
  49303. return WC_TEST_RET_ENC_NC;
  49304. ret = mp_to_unsigned_bin(a, out);
  49305. if (ret != 0)
  49306. return WC_TEST_RET_ENC_EC(ret);
  49307. if (XMEMCMP(exp, out, sizeof(exp)) != 0)
  49308. return WC_TEST_RET_ENC_NC;
  49309. return 0;
  49310. }
  49311. #endif
  49312. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  49313. static wc_test_ret_t mp_test_param(mp_int* a, mp_int* b, mp_int* r, WC_RNG* rng)
  49314. {
  49315. byte buffer[16];
  49316. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49317. char hexStr[] = "abcdef0123456789";
  49318. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49319. char negStr[] = "-1234";
  49320. #endif
  49321. #endif
  49322. #if !defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_KEY_GEN) || \
  49323. defined(HAVE_COMP_KEY)
  49324. char decStr[] = "0987654321";
  49325. #endif
  49326. wc_test_ret_t ret;
  49327. #ifdef WOLFSSL_SP_MATH_ALL
  49328. mp_digit rho;
  49329. int size;
  49330. #endif
  49331. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49332. int result;
  49333. #endif
  49334. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49335. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49336. mp_digit rd;
  49337. #endif
  49338. (void)rng;
  49339. (void)r;
  49340. ret = mp_init(NULL);
  49341. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49342. return WC_TEST_RET_ENC_EC(ret);
  49343. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49344. ret = mp_init_multi(NULL, NULL, NULL, NULL, NULL, NULL);
  49345. if (ret != MP_OKAY)
  49346. return WC_TEST_RET_ENC_EC(ret);
  49347. #endif
  49348. mp_free(NULL);
  49349. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || !defined(NO_DH) || defined(HAVE_ECC)
  49350. ret = mp_grow(NULL, 1);
  49351. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49352. return WC_TEST_RET_ENC_EC(ret);
  49353. #ifdef WOLFSSL_SP_MATH
  49354. ret = mp_grow(a, SP_INT_DIGITS + 1);
  49355. if (ret != WC_NO_ERR_TRACE(MP_MEM))
  49356. return WC_TEST_RET_ENC_EC(ret);
  49357. #endif
  49358. #endif
  49359. mp_clear(NULL);
  49360. ret = mp_abs(NULL, NULL);
  49361. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49362. return WC_TEST_RET_ENC_EC(ret);
  49363. ret = mp_abs(a, NULL);
  49364. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49365. return WC_TEST_RET_ENC_EC(ret);
  49366. ret = mp_abs(NULL, b);
  49367. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49368. return WC_TEST_RET_ENC_EC(ret);
  49369. ret = mp_unsigned_bin_size(NULL);
  49370. if (ret != 0)
  49371. return WC_TEST_RET_ENC_EC(ret);
  49372. /* clear buffer to avoid provoking uninitvar errors. */
  49373. XMEMSET(buffer, 0, sizeof(buffer));
  49374. ret = mp_read_unsigned_bin(NULL, NULL, sizeof(buffer));
  49375. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49376. return WC_TEST_RET_ENC_EC(ret);
  49377. ret = mp_read_unsigned_bin(NULL, buffer, sizeof(buffer));
  49378. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49379. return WC_TEST_RET_ENC_EC(ret);
  49380. ret = mp_read_unsigned_bin(a, NULL, sizeof(buffer));
  49381. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49382. return WC_TEST_RET_ENC_EC(ret);
  49383. ret = mp_read_unsigned_bin(a, buffer, SP_INT_DIGITS * SP_WORD_SIZEOF + 1);
  49384. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49385. return WC_TEST_RET_ENC_EC(ret);
  49386. #if defined(HAVE_ECC) || defined(WOLFSSL_SP_MATH_ALL)
  49387. ret = mp_read_radix(NULL, NULL, 16);
  49388. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49389. return WC_TEST_RET_ENC_EC(ret);
  49390. ret = mp_read_radix(a, NULL, 16);
  49391. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49392. return WC_TEST_RET_ENC_EC(ret);
  49393. ret = mp_read_radix(NULL, hexStr, 16);
  49394. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49395. return WC_TEST_RET_ENC_EC(ret);
  49396. #ifndef WOLFSSL_SP_INT_NEGATIVE
  49397. ret = mp_read_radix(a, negStr, 16);
  49398. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49399. return WC_TEST_RET_ENC_EC(ret);
  49400. #ifdef WOLFSSL_SP_MATH_ALL
  49401. ret = mp_read_radix(a, negStr, 10);
  49402. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49403. return WC_TEST_RET_ENC_EC(ret);
  49404. #endif /* WOLFSSL_SP_MATH_ALL */
  49405. #endif /* WOLFSSL_SP_INT_NEGATIVE */
  49406. #endif
  49407. #ifndef WOLFSSL_SP_MATH_ALL
  49408. /* Radix 10 only supported with ALL. */
  49409. ret = mp_read_radix(a, decStr, 10);
  49410. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49411. return WC_TEST_RET_ENC_EC(ret);
  49412. #endif
  49413. /* Radix 8 not supported SP_INT. */
  49414. ret = mp_read_radix(a, "0123", 8);
  49415. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49416. return WC_TEST_RET_ENC_EC(ret);
  49417. ret = mp_count_bits(NULL);
  49418. if (ret != 0)
  49419. return WC_TEST_RET_ENC_EC(ret);
  49420. ret = mp_is_bit_set(NULL, 0);
  49421. if (ret != 0)
  49422. return WC_TEST_RET_ENC_EC(ret);
  49423. ret = mp_leading_bit(NULL);
  49424. if (ret != 0)
  49425. return WC_TEST_RET_ENC_EC(ret);
  49426. mp_zero(a);
  49427. ret = mp_leading_bit(a);
  49428. if (ret != 0)
  49429. return WC_TEST_RET_ENC_EC(ret);
  49430. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49431. defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN) || defined(OPENSSL_EXTRA) || \
  49432. !defined(NO_RSA)
  49433. ret = mp_set_bit(NULL, 1);
  49434. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49435. return WC_TEST_RET_ENC_EC(ret);
  49436. #endif
  49437. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49438. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49439. ret = mp_to_unsigned_bin(NULL, NULL);
  49440. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49441. return WC_TEST_RET_ENC_EC(ret);
  49442. ret = mp_to_unsigned_bin(a, NULL);
  49443. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49444. return WC_TEST_RET_ENC_EC(ret);
  49445. ret = mp_to_unsigned_bin(NULL, buffer);
  49446. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49447. return WC_TEST_RET_ENC_EC(ret);
  49448. #endif
  49449. ret = mp_to_unsigned_bin_len(NULL, NULL, 1);
  49450. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49451. return WC_TEST_RET_ENC_EC(ret);
  49452. ret = mp_to_unsigned_bin_len(a, NULL, 1);
  49453. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49454. return WC_TEST_RET_ENC_EC(ret);
  49455. ret = mp_to_unsigned_bin_len(NULL, buffer, 1);
  49456. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49457. return WC_TEST_RET_ENC_EC(ret);
  49458. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  49459. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49460. ret = mp_to_unsigned_bin_at_pos(0, NULL, NULL);
  49461. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49462. return WC_TEST_RET_ENC_EC(ret);
  49463. ret = mp_to_unsigned_bin_at_pos(0, a, NULL);
  49464. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49465. return WC_TEST_RET_ENC_EC(ret);
  49466. ret = mp_to_unsigned_bin_at_pos(0, NULL, buffer);
  49467. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49468. return WC_TEST_RET_ENC_EC(ret);
  49469. ret = mp_to_unsigned_bin_at_pos(0, a, buffer);
  49470. if (ret != MP_OKAY)
  49471. return WC_TEST_RET_ENC_EC(ret);
  49472. #endif
  49473. #if !defined(WOLFSSL_RSA_VERIFY_ONLY) || (!defined(NO_DH) || defined(HAVE_ECC))
  49474. ret = mp_copy(NULL, NULL);
  49475. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49476. return WC_TEST_RET_ENC_EC(ret);
  49477. ret = mp_copy(a, NULL);
  49478. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49479. return WC_TEST_RET_ENC_EC(ret);
  49480. ret = mp_copy(NULL, b);
  49481. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49482. return WC_TEST_RET_ENC_EC(ret);
  49483. #endif
  49484. #if defined(WOLFSSL_KEY_GEN) || !defined(NO_DH)
  49485. ret = sp_2expt(NULL, 1);
  49486. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49487. return WC_TEST_RET_ENC_EC(ret);
  49488. #endif
  49489. ret = mp_set(NULL, 0);
  49490. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49491. return WC_TEST_RET_ENC_EC(ret);
  49492. ret = mp_cmp_d(NULL, 0);
  49493. if (ret != MP_LT)
  49494. return WC_TEST_RET_ENC_EC(ret);
  49495. ret = mp_cmp(NULL, NULL);
  49496. if (ret != MP_EQ)
  49497. return WC_TEST_RET_ENC_NC;
  49498. ret = mp_cmp(a, NULL);
  49499. if (ret != MP_GT)
  49500. return WC_TEST_RET_ENC_NC;
  49501. ret = mp_cmp(NULL, b);
  49502. if (ret != MP_LT)
  49503. return WC_TEST_RET_ENC_NC;
  49504. #ifdef WOLFSSL_SP_MATH_ALL
  49505. mp_rshd(NULL, 1);
  49506. #endif
  49507. mp_zero(NULL);
  49508. #if !defined(NO_DH) || defined(HAVE_ECC) || defined(WC_RSA_BLINDING) || \
  49509. !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49510. ret = mp_lshd(NULL, 0);
  49511. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49512. return WC_TEST_RET_ENC_EC(ret);
  49513. ret = mp_lshd(a, SP_INT_DIGITS + 1);
  49514. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49515. return WC_TEST_RET_ENC_EC(ret);
  49516. #endif
  49517. #if defined(WOLFSSL_SP_MATH_ALL)
  49518. ret = mp_div(NULL, NULL, a, b);
  49519. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49520. return WC_TEST_RET_ENC_EC(ret);
  49521. ret = mp_div(a, NULL, a, b);
  49522. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49523. return WC_TEST_RET_ENC_EC(ret);
  49524. ret = mp_div(NULL, b, a, b);
  49525. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49526. return WC_TEST_RET_ENC_EC(ret);
  49527. ret = mp_div(a, b, NULL, NULL);
  49528. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49529. return WC_TEST_RET_ENC_EC(ret);
  49530. #endif
  49531. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  49532. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49533. ret = mp_mod(NULL, NULL, NULL);
  49534. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49535. return WC_TEST_RET_ENC_EC(ret);
  49536. ret = mp_mod(a, NULL, NULL);
  49537. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49538. return WC_TEST_RET_ENC_EC(ret);
  49539. ret = mp_mod(NULL, b, NULL);
  49540. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49541. return WC_TEST_RET_ENC_EC(ret);
  49542. ret = mp_mod(NULL, NULL, r);
  49543. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49544. return WC_TEST_RET_ENC_EC(ret);
  49545. ret = mp_mod(a, b, NULL);
  49546. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49547. return WC_TEST_RET_ENC_EC(ret);
  49548. ret = mp_mod(a, NULL, r);
  49549. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49550. return WC_TEST_RET_ENC_EC(ret);
  49551. ret = mp_mod(NULL, b, r);
  49552. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49553. return WC_TEST_RET_ENC_EC(ret);
  49554. #endif
  49555. #if !defined(NO_RSA) || defined(WOLFSSL_SP_MATH_ALL)
  49556. ret = mp_set_int(NULL, 0);
  49557. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49558. return WC_TEST_RET_ENC_EC(ret);
  49559. #endif
  49560. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  49561. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  49562. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49563. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49564. return WC_TEST_RET_ENC_EC(ret);
  49565. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49566. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49567. return WC_TEST_RET_ENC_EC(ret);
  49568. ret = mp_exptmod_ex(NULL, a, 1, NULL, NULL);
  49569. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49570. return WC_TEST_RET_ENC_EC(ret);
  49571. ret = mp_exptmod_ex(NULL, NULL, 1, a, NULL);
  49572. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49573. return WC_TEST_RET_ENC_EC(ret);
  49574. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49575. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49576. return WC_TEST_RET_ENC_EC(ret);
  49577. ret = mp_exptmod_ex(a, a, 1, a, NULL);
  49578. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49579. return WC_TEST_RET_ENC_EC(ret);
  49580. ret = mp_exptmod_ex(a, a, 1, NULL, a);
  49581. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49582. return WC_TEST_RET_ENC_EC(ret);
  49583. ret = mp_exptmod_ex(a, NULL, 1, a, a);
  49584. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49585. return WC_TEST_RET_ENC_EC(ret);
  49586. ret = mp_exptmod_ex(NULL, a, 1, a, a);
  49587. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49588. return WC_TEST_RET_ENC_EC(ret);
  49589. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49590. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49591. return WC_TEST_RET_ENC_EC(ret);
  49592. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49593. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49594. return WC_TEST_RET_ENC_EC(ret);
  49595. ret = mp_exptmod_nct(NULL, a, NULL, NULL);
  49596. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49597. return WC_TEST_RET_ENC_EC(ret);
  49598. ret = mp_exptmod_nct(NULL, NULL, a, NULL);
  49599. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49600. return WC_TEST_RET_ENC_EC(ret);
  49601. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49602. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49603. return WC_TEST_RET_ENC_EC(ret);
  49604. ret = mp_exptmod_nct(a, a, a, NULL);
  49605. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49606. return WC_TEST_RET_ENC_EC(ret);
  49607. ret = mp_exptmod_nct(a, a, NULL, a);
  49608. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49609. return WC_TEST_RET_ENC_EC(ret);
  49610. ret = mp_exptmod_nct(a, NULL, a, a);
  49611. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49612. return WC_TEST_RET_ENC_EC(ret);
  49613. ret = mp_exptmod_nct(NULL, a, a, a);
  49614. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49615. return WC_TEST_RET_ENC_EC(ret);
  49616. #endif
  49617. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  49618. !defined(WC_NO_RNG)
  49619. ret = mp_rand_prime(NULL, 32, NULL, NULL);
  49620. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49621. return WC_TEST_RET_ENC_EC(ret);
  49622. ret = mp_rand_prime(a, 32, NULL, NULL);
  49623. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49624. return WC_TEST_RET_ENC_EC(ret);
  49625. ret = mp_rand_prime(NULL, 32, rng, NULL);
  49626. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49627. return WC_TEST_RET_ENC_EC(ret);
  49628. ret = mp_rand_prime(a, 0, rng, NULL);
  49629. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49630. return WC_TEST_RET_ENC_EC(ret);
  49631. #endif
  49632. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49633. ret = mp_mul(NULL, NULL, NULL);
  49634. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49635. return WC_TEST_RET_ENC_EC(ret);
  49636. ret = mp_mul(a, NULL, NULL);
  49637. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49638. return WC_TEST_RET_ENC_EC(ret);
  49639. ret = mp_mul(NULL, b, NULL);
  49640. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49641. return WC_TEST_RET_ENC_EC(ret);
  49642. ret = mp_mul(NULL, NULL, r);
  49643. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49644. return WC_TEST_RET_ENC_EC(ret);
  49645. ret = mp_mul(a, b, NULL);
  49646. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49647. return WC_TEST_RET_ENC_EC(ret);
  49648. ret = mp_mul(a, NULL, r);
  49649. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49650. return WC_TEST_RET_ENC_EC(ret);
  49651. ret = mp_mul(NULL, b, r);
  49652. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49653. return WC_TEST_RET_ENC_EC(ret);
  49654. #endif
  49655. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  49656. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  49657. ret = mp_sqr(NULL, NULL);
  49658. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49659. return WC_TEST_RET_ENC_EC(ret);
  49660. ret = mp_sqr(a, NULL);
  49661. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49662. return WC_TEST_RET_ENC_EC(ret);
  49663. ret = mp_sqr(NULL, r);
  49664. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49665. return WC_TEST_RET_ENC_EC(ret);
  49666. #endif
  49667. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  49668. ret = mp_sqrmod(NULL, NULL, NULL);
  49669. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49670. return WC_TEST_RET_ENC_EC(ret);
  49671. ret = mp_sqrmod(a, NULL, NULL);
  49672. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49673. return WC_TEST_RET_ENC_EC(ret);
  49674. ret = mp_sqrmod(NULL, a, NULL);
  49675. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49676. return WC_TEST_RET_ENC_EC(ret);
  49677. ret = mp_sqrmod(NULL, NULL, a);
  49678. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49679. return WC_TEST_RET_ENC_EC(ret);
  49680. ret = mp_sqrmod(a, b, NULL);
  49681. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49682. return WC_TEST_RET_ENC_EC(ret);
  49683. ret = mp_sqrmod(a, NULL, b);
  49684. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49685. return WC_TEST_RET_ENC_EC(ret);
  49686. ret = mp_sqrmod(NULL, a, b);
  49687. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49688. return WC_TEST_RET_ENC_EC(ret);
  49689. ret = mp_mulmod(NULL, NULL, NULL, NULL);
  49690. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49691. return WC_TEST_RET_ENC_EC(ret);
  49692. ret = mp_mulmod(a, NULL, NULL, NULL);
  49693. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49694. return WC_TEST_RET_ENC_EC(ret);
  49695. ret = mp_mulmod(NULL, a, NULL, NULL);
  49696. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49697. return WC_TEST_RET_ENC_EC(ret);
  49698. ret = mp_mulmod(NULL, NULL, a, NULL);
  49699. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49700. return WC_TEST_RET_ENC_EC(ret);
  49701. ret = mp_mulmod(NULL, NULL, NULL, a);
  49702. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49703. return WC_TEST_RET_ENC_EC(ret);
  49704. ret = mp_mulmod(a, b, b, NULL);
  49705. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49706. return WC_TEST_RET_ENC_EC(ret);
  49707. ret = mp_mulmod(a, b, NULL, a);
  49708. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49709. return WC_TEST_RET_ENC_EC(ret);
  49710. ret = mp_mulmod(a, NULL, b, a);
  49711. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49712. return WC_TEST_RET_ENC_EC(ret);
  49713. ret = mp_mulmod(NULL, b, b, a);
  49714. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49715. return WC_TEST_RET_ENC_EC(ret);
  49716. #endif
  49717. #if !defined(NO_PWDBASED) || defined(WOLFSSL_KEY_GEN) || !defined(NO_DH) || \
  49718. !defined(NO_RSA) || !defined(NO_DSA)
  49719. ret = mp_add_d(NULL, 1, NULL);
  49720. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49721. return WC_TEST_RET_ENC_EC(ret);
  49722. ret = mp_add_d(a, 1, NULL);
  49723. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49724. return WC_TEST_RET_ENC_EC(ret);
  49725. ret = mp_add_d(NULL, 1, b);
  49726. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49727. return WC_TEST_RET_ENC_EC(ret);
  49728. #endif
  49729. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49730. !defined(NO_DH) || defined(HAVE_ECC) || !defined(NO_DSA)
  49731. ret = mp_sub_d(NULL, 1, NULL);
  49732. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49733. return WC_TEST_RET_ENC_EC(ret);
  49734. ret = mp_sub_d(a, 1, NULL);
  49735. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49736. return WC_TEST_RET_ENC_EC(ret);
  49737. ret = mp_sub_d(NULL, 1, b);
  49738. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49739. return WC_TEST_RET_ENC_EC(ret);
  49740. #endif
  49741. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49742. defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  49743. ret = mp_div_d(NULL, 0, NULL, NULL);
  49744. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49745. return WC_TEST_RET_ENC_EC(ret);
  49746. ret = mp_div_d(a, 0, NULL, NULL);
  49747. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49748. return WC_TEST_RET_ENC_EC(ret);
  49749. ret = mp_div_d(NULL, 1, NULL, NULL);
  49750. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49751. return WC_TEST_RET_ENC_EC(ret);
  49752. #endif
  49753. #if (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || \
  49754. (defined(OPENSSL_EXTRA) && defined(WOLFSSL_KEY_GEN))
  49755. ret = mp_mod_d(NULL, 0, NULL);
  49756. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49757. return WC_TEST_RET_ENC_EC(ret);
  49758. ret = mp_mod_d(a, 0, NULL);
  49759. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49760. return WC_TEST_RET_ENC_EC(ret);
  49761. ret = mp_mod_d(NULL, 0, &rd);
  49762. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49763. return WC_TEST_RET_ENC_EC(ret);
  49764. #endif
  49765. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
  49766. ret = mp_gcd(NULL, NULL, NULL);
  49767. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49768. return WC_TEST_RET_ENC_EC(ret);
  49769. ret = mp_gcd(a, NULL, NULL);
  49770. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49771. return WC_TEST_RET_ENC_EC(ret);
  49772. ret = mp_gcd(NULL, a, NULL);
  49773. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49774. return WC_TEST_RET_ENC_EC(ret);
  49775. ret = mp_gcd(NULL, NULL, a);
  49776. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49777. return WC_TEST_RET_ENC_EC(ret);
  49778. ret = mp_gcd(a, b, NULL);
  49779. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49780. return WC_TEST_RET_ENC_EC(ret);
  49781. ret = mp_gcd(a, NULL, b);
  49782. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49783. return WC_TEST_RET_ENC_EC(ret);
  49784. ret = mp_gcd(NULL, a, b);
  49785. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49786. return WC_TEST_RET_ENC_EC(ret);
  49787. #endif
  49788. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49789. ret = mp_div_2_mod_ct(NULL, NULL, NULL);
  49790. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49791. return WC_TEST_RET_ENC_EC(ret);
  49792. ret = mp_div_2_mod_ct(a, NULL, NULL);
  49793. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49794. return WC_TEST_RET_ENC_EC(ret);
  49795. ret = mp_div_2_mod_ct(NULL, b, NULL);
  49796. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49797. return WC_TEST_RET_ENC_EC(ret);
  49798. ret = mp_div_2_mod_ct(NULL, NULL, a);
  49799. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49800. return WC_TEST_RET_ENC_EC(ret);
  49801. ret = mp_div_2_mod_ct(a, b, NULL);
  49802. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49803. return WC_TEST_RET_ENC_EC(ret);
  49804. ret = mp_div_2_mod_ct(a, b, NULL);
  49805. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49806. return WC_TEST_RET_ENC_EC(ret);
  49807. ret = mp_div_2_mod_ct(NULL, b, a);
  49808. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49809. return WC_TEST_RET_ENC_EC(ret);
  49810. ret = mp_div_2(NULL, NULL);
  49811. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49812. return WC_TEST_RET_ENC_EC(ret);
  49813. ret = mp_div_2(a, NULL);
  49814. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49815. return WC_TEST_RET_ENC_EC(ret);
  49816. ret = mp_div_2(NULL, a);
  49817. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49818. return WC_TEST_RET_ENC_EC(ret);
  49819. #endif
  49820. #if (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  49821. defined(HAVE_ECC) || !defined(NO_DSA) || defined(OPENSSL_EXTRA)
  49822. ret = mp_invmod(NULL, NULL, NULL);
  49823. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49824. return WC_TEST_RET_ENC_EC(ret);
  49825. ret = mp_invmod(a, NULL, NULL);
  49826. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49827. return WC_TEST_RET_ENC_EC(ret);
  49828. ret = mp_invmod(NULL, b, NULL);
  49829. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49830. return WC_TEST_RET_ENC_EC(ret);
  49831. ret = mp_invmod(NULL, NULL, a);
  49832. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49833. return WC_TEST_RET_ENC_EC(ret);
  49834. ret = mp_invmod(a, b, NULL);
  49835. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49836. return WC_TEST_RET_ENC_EC(ret);
  49837. ret = mp_invmod(a, NULL, a);
  49838. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49839. return WC_TEST_RET_ENC_EC(ret);
  49840. ret = mp_invmod(NULL, b, a);
  49841. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49842. return WC_TEST_RET_ENC_EC(ret);
  49843. #endif
  49844. #if !defined(WOLFSSL_SP_MATH) && defined(HAVE_ECC)
  49845. ret = mp_invmod_mont_ct(NULL, NULL, NULL, 1);
  49846. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49847. return WC_TEST_RET_ENC_EC(ret);
  49848. ret = mp_invmod_mont_ct(a, NULL, NULL, 1);
  49849. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49850. return WC_TEST_RET_ENC_EC(ret);
  49851. ret = mp_invmod_mont_ct(NULL, b, NULL, 1);
  49852. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49853. return WC_TEST_RET_ENC_EC(ret);
  49854. ret = mp_invmod_mont_ct(NULL, NULL, a, 1);
  49855. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49856. return WC_TEST_RET_ENC_EC(ret);
  49857. ret = mp_invmod_mont_ct(a, b, NULL, 1);
  49858. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49859. return WC_TEST_RET_ENC_EC(ret);
  49860. ret = mp_invmod_mont_ct(a, NULL, a, 1);
  49861. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49862. return WC_TEST_RET_ENC_EC(ret);
  49863. ret = mp_invmod_mont_ct(NULL, b, a, 1);
  49864. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49865. return WC_TEST_RET_ENC_EC(ret);
  49866. #endif
  49867. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  49868. ret = mp_lcm(NULL, NULL, NULL);
  49869. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49870. return WC_TEST_RET_ENC_EC(ret);
  49871. ret = mp_lcm(a, NULL, NULL);
  49872. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49873. return WC_TEST_RET_ENC_EC(ret);
  49874. ret = mp_lcm(NULL, b, NULL);
  49875. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49876. return WC_TEST_RET_ENC_EC(ret);
  49877. ret = mp_lcm(NULL, NULL, a);
  49878. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49879. return WC_TEST_RET_ENC_EC(ret);
  49880. ret = mp_lcm(a, b, NULL);
  49881. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49882. return WC_TEST_RET_ENC_EC(ret);
  49883. ret = mp_lcm(a, NULL, a);
  49884. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49885. return WC_TEST_RET_ENC_EC(ret);
  49886. ret = mp_lcm(NULL, b, a);
  49887. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49888. return WC_TEST_RET_ENC_EC(ret);
  49889. #endif
  49890. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49891. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, NULL);
  49892. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49893. return WC_TEST_RET_ENC_EC(ret);
  49894. ret = mp_exptmod_ex(a, NULL, 1, NULL, NULL);
  49895. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49896. return WC_TEST_RET_ENC_EC(ret);
  49897. ret = mp_exptmod_ex(NULL, b, 1, NULL, NULL);
  49898. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49899. return WC_TEST_RET_ENC_EC(ret);
  49900. ret = mp_exptmod_ex(NULL, NULL, 1, b, NULL);
  49901. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49902. return WC_TEST_RET_ENC_EC(ret);
  49903. ret = mp_exptmod_ex(NULL, NULL, 1, NULL, a);
  49904. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49905. return WC_TEST_RET_ENC_EC(ret);
  49906. ret = mp_exptmod_ex(a, b, 1, b, NULL);
  49907. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49908. return WC_TEST_RET_ENC_EC(ret);
  49909. ret = mp_exptmod_ex(a, b, 1, NULL, a);
  49910. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49911. return WC_TEST_RET_ENC_EC(ret);
  49912. ret = mp_exptmod_ex(a, NULL, 1, b, a);
  49913. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49914. return WC_TEST_RET_ENC_EC(ret);
  49915. ret = mp_exptmod_ex(NULL, b, 1, b, a);
  49916. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49917. return WC_TEST_RET_ENC_EC(ret);
  49918. ret = mp_exptmod(NULL, NULL, NULL, NULL);
  49919. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49920. return WC_TEST_RET_ENC_EC(ret);
  49921. ret = mp_exptmod(a, NULL, NULL, NULL);
  49922. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49923. return WC_TEST_RET_ENC_EC(ret);
  49924. ret = mp_exptmod(NULL, b, NULL, NULL);
  49925. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49926. return WC_TEST_RET_ENC_EC(ret);
  49927. ret = mp_exptmod(NULL, NULL, b, NULL);
  49928. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49929. return WC_TEST_RET_ENC_EC(ret);
  49930. ret = mp_exptmod(NULL, NULL, NULL, a);
  49931. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49932. return WC_TEST_RET_ENC_EC(ret);
  49933. ret = mp_exptmod(a, b, b, NULL);
  49934. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49935. return WC_TEST_RET_ENC_EC(ret);
  49936. ret = mp_exptmod(a, b, NULL, a);
  49937. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49938. return WC_TEST_RET_ENC_EC(ret);
  49939. ret = mp_exptmod(a, NULL, b, a);
  49940. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49941. return WC_TEST_RET_ENC_EC(ret);
  49942. ret = mp_exptmod(NULL, b, b, a);
  49943. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49944. return WC_TEST_RET_ENC_EC(ret);
  49945. ret = mp_exptmod_nct(NULL, NULL, NULL, NULL);
  49946. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49947. return WC_TEST_RET_ENC_EC(ret);
  49948. ret = mp_exptmod_nct(a, NULL, NULL, NULL);
  49949. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49950. return WC_TEST_RET_ENC_EC(ret);
  49951. ret = mp_exptmod_nct(NULL, b, NULL, NULL);
  49952. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49953. return WC_TEST_RET_ENC_EC(ret);
  49954. ret = mp_exptmod_nct(NULL, NULL, b, NULL);
  49955. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49956. return WC_TEST_RET_ENC_EC(ret);
  49957. ret = mp_exptmod_nct(NULL, NULL, NULL, a);
  49958. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49959. return WC_TEST_RET_ENC_EC(ret);
  49960. ret = mp_exptmod_nct(a, b, b, NULL);
  49961. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49962. return WC_TEST_RET_ENC_EC(ret);
  49963. ret = mp_exptmod_nct(a, b, NULL, a);
  49964. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49965. return WC_TEST_RET_ENC_EC(ret);
  49966. ret = mp_exptmod_nct(a, NULL, b, a);
  49967. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49968. return WC_TEST_RET_ENC_EC(ret);
  49969. ret = mp_exptmod_nct(NULL, b, b, a);
  49970. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49971. return WC_TEST_RET_ENC_EC(ret);
  49972. #endif
  49973. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  49974. ret = mp_cnt_lsb(NULL);
  49975. if (ret != 0)
  49976. return WC_TEST_RET_ENC_EC(ret);
  49977. #endif
  49978. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH)
  49979. ret = mp_prime_is_prime(NULL, 1, NULL);
  49980. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49981. return WC_TEST_RET_ENC_EC(ret);
  49982. ret = mp_prime_is_prime(a, 1, NULL);
  49983. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49984. return WC_TEST_RET_ENC_EC(ret);
  49985. ret = mp_prime_is_prime(NULL, 1, &result);
  49986. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49987. return WC_TEST_RET_ENC_EC(ret);
  49988. ret = mp_prime_is_prime(a, 0, &result);
  49989. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49990. return WC_TEST_RET_ENC_EC(ret);
  49991. ret = mp_prime_is_prime(a, 1024, &result);
  49992. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49993. return WC_TEST_RET_ENC_EC(ret);
  49994. ret = mp_prime_is_prime_ex(NULL, 1, NULL, NULL);
  49995. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49996. return WC_TEST_RET_ENC_EC(ret);
  49997. ret = mp_prime_is_prime_ex(a, 1, NULL, NULL);
  49998. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  49999. return WC_TEST_RET_ENC_EC(ret);
  50000. ret = mp_prime_is_prime_ex(NULL, 1, &result, NULL);
  50001. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50002. return WC_TEST_RET_ENC_EC(ret);
  50003. ret = mp_prime_is_prime_ex(NULL, 1, NULL, rng);
  50004. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50005. return WC_TEST_RET_ENC_EC(ret);
  50006. ret = mp_prime_is_prime_ex(a, 1, &result, NULL);
  50007. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50008. return WC_TEST_RET_ENC_EC(ret);
  50009. ret = mp_prime_is_prime_ex(a, 1, NULL, rng);
  50010. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50011. return WC_TEST_RET_ENC_EC(ret);
  50012. ret = mp_prime_is_prime_ex(NULL, 1, &result, rng);
  50013. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50014. return WC_TEST_RET_ENC_EC(ret);
  50015. #endif
  50016. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || !defined(NO_DSA)
  50017. ret = mp_exch(NULL, NULL);
  50018. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50019. return WC_TEST_RET_ENC_EC(ret);
  50020. ret = mp_exch(a, NULL);
  50021. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50022. return WC_TEST_RET_ENC_EC(ret);
  50023. ret = mp_exch(NULL, b);
  50024. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50025. return WC_TEST_RET_ENC_EC(ret);
  50026. #endif
  50027. #if (defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)) || \
  50028. defined(WOLFSSL_SP_MATH_ALL)
  50029. ret = mp_mul_d(NULL, 1, NULL);
  50030. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50031. return WC_TEST_RET_ENC_EC(ret);
  50032. ret = mp_mul_d(a, 1, NULL);
  50033. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50034. return WC_TEST_RET_ENC_EC(ret);
  50035. ret = mp_mul_d(NULL, 1, b);
  50036. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50037. return WC_TEST_RET_ENC_EC(ret);
  50038. #endif
  50039. #if !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50040. ret = mp_add(NULL, NULL, NULL);
  50041. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50042. return WC_TEST_RET_ENC_EC(ret);
  50043. ret = mp_add(a, NULL, NULL);
  50044. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50045. return WC_TEST_RET_ENC_EC(ret);
  50046. ret = mp_add(NULL, b, NULL);
  50047. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50048. return WC_TEST_RET_ENC_EC(ret);
  50049. ret = mp_add(NULL, NULL, r);
  50050. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50051. return WC_TEST_RET_ENC_EC(ret);
  50052. ret = mp_add(a, b, NULL);
  50053. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50054. return WC_TEST_RET_ENC_EC(ret);
  50055. ret = mp_add(a, NULL, r);
  50056. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50057. return WC_TEST_RET_ENC_EC(ret);
  50058. ret = mp_add(NULL, b, r);
  50059. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50060. return WC_TEST_RET_ENC_EC(ret);
  50061. #endif
  50062. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50063. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50064. ret = mp_sub(NULL, NULL, NULL);
  50065. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50066. return WC_TEST_RET_ENC_EC(ret);
  50067. ret = mp_sub(a, NULL, NULL);
  50068. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50069. return WC_TEST_RET_ENC_EC(ret);
  50070. ret = mp_sub(NULL, b, NULL);
  50071. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50072. return WC_TEST_RET_ENC_EC(ret);
  50073. ret = mp_sub(NULL, NULL, r);
  50074. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50075. return WC_TEST_RET_ENC_EC(ret);
  50076. ret = mp_sub(a, b, NULL);
  50077. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50078. return WC_TEST_RET_ENC_EC(ret);
  50079. ret = mp_sub(a, NULL, r);
  50080. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50081. return WC_TEST_RET_ENC_EC(ret);
  50082. ret = mp_sub(NULL, b, r);
  50083. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50084. return WC_TEST_RET_ENC_EC(ret);
  50085. #endif
  50086. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined(WOLFSSL_SP_MATH) && \
  50087. defined(WOLFSSL_CUSTOM_CURVES))
  50088. ret = mp_addmod(NULL, NULL, NULL, NULL);
  50089. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50090. return WC_TEST_RET_ENC_EC(ret);
  50091. ret = mp_addmod(a, NULL, NULL, NULL);
  50092. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50093. return WC_TEST_RET_ENC_EC(ret);
  50094. ret = mp_addmod(NULL, b, NULL, NULL);
  50095. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50096. return WC_TEST_RET_ENC_EC(ret);
  50097. ret = mp_addmod(NULL, NULL, b, NULL);
  50098. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50099. return WC_TEST_RET_ENC_EC(ret);
  50100. ret = mp_addmod(NULL, NULL, NULL, a);
  50101. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50102. return WC_TEST_RET_ENC_EC(ret);
  50103. ret = mp_addmod(a, b, b, NULL);
  50104. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50105. return WC_TEST_RET_ENC_EC(ret);
  50106. ret = mp_addmod(a, b, NULL, a);
  50107. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50108. return WC_TEST_RET_ENC_EC(ret);
  50109. ret = mp_addmod(a, NULL, b, a);
  50110. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50111. return WC_TEST_RET_ENC_EC(ret);
  50112. ret = mp_addmod(NULL, b, b, a);
  50113. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50114. return WC_TEST_RET_ENC_EC(ret);
  50115. #endif
  50116. #ifdef WOLFSSL_SP_MATH_ALL
  50117. ret = mp_submod(NULL, NULL, NULL, NULL);
  50118. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50119. return WC_TEST_RET_ENC_EC(ret);
  50120. ret = mp_submod(a, NULL, NULL, NULL);
  50121. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50122. return WC_TEST_RET_ENC_EC(ret);
  50123. ret = mp_submod(NULL, b, NULL, NULL);
  50124. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50125. return WC_TEST_RET_ENC_EC(ret);
  50126. ret = mp_submod(NULL, NULL, b, NULL);
  50127. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50128. return WC_TEST_RET_ENC_EC(ret);
  50129. ret = mp_submod(NULL, NULL, NULL, a);
  50130. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50131. return WC_TEST_RET_ENC_EC(ret);
  50132. ret = mp_submod(a, b, b, NULL);
  50133. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50134. return WC_TEST_RET_ENC_EC(ret);
  50135. ret = mp_submod(a, b, NULL, a);
  50136. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50137. return WC_TEST_RET_ENC_EC(ret);
  50138. ret = mp_submod(a, NULL, b, a);
  50139. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50140. return WC_TEST_RET_ENC_EC(ret);
  50141. ret = mp_submod(NULL, b, b, a);
  50142. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50143. return WC_TEST_RET_ENC_EC(ret);
  50144. #endif
  50145. #ifdef WOLFSSL_SP_MATH_ALL
  50146. ret = mp_div_2d(NULL, 1, a, b);
  50147. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50148. return WC_TEST_RET_ENC_EC(ret);
  50149. ret = mp_mod_2d(NULL, 1, NULL);
  50150. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50151. return WC_TEST_RET_ENC_EC(ret);
  50152. ret = mp_mod_2d(a, 1, NULL);
  50153. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50154. return WC_TEST_RET_ENC_EC(ret);
  50155. ret = mp_mod_2d(NULL, 1, b);
  50156. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50157. return WC_TEST_RET_ENC_EC(ret);
  50158. ret = mp_mul_2d(NULL, 1, NULL);
  50159. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50160. return WC_TEST_RET_ENC_EC(ret);
  50161. ret = mp_mul_2d(a, 1, NULL);
  50162. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50163. return WC_TEST_RET_ENC_EC(ret);
  50164. ret = mp_mul_2d(NULL, 1, b);
  50165. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50166. return WC_TEST_RET_ENC_EC(ret);
  50167. #endif
  50168. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  50169. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  50170. ret = mp_montgomery_reduce(NULL, NULL, 1);
  50171. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50172. return WC_TEST_RET_ENC_EC(ret);
  50173. ret = mp_montgomery_reduce(a, NULL, 1);
  50174. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50175. return WC_TEST_RET_ENC_EC(ret);
  50176. ret = mp_montgomery_reduce(NULL, b, 1);
  50177. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50178. return WC_TEST_RET_ENC_EC(ret);
  50179. mp_zero(b);
  50180. ret = mp_montgomery_reduce(a, b, 1);
  50181. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50182. return WC_TEST_RET_ENC_EC(ret);
  50183. #endif
  50184. #ifdef WOLFSSL_SP_MATH_ALL
  50185. ret = mp_montgomery_setup(NULL, NULL);
  50186. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50187. return WC_TEST_RET_ENC_EC(ret);
  50188. ret = mp_montgomery_setup(a, NULL);
  50189. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50190. return WC_TEST_RET_ENC_EC(ret);
  50191. ret = mp_montgomery_setup(NULL, &rho);
  50192. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50193. return WC_TEST_RET_ENC_EC(ret);
  50194. ret = mp_montgomery_calc_normalization(NULL, NULL);
  50195. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50196. return WC_TEST_RET_ENC_EC(ret);
  50197. ret = mp_montgomery_calc_normalization(a, NULL);
  50198. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50199. return WC_TEST_RET_ENC_EC(ret);
  50200. ret = mp_montgomery_calc_normalization(NULL, b);
  50201. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50202. return WC_TEST_RET_ENC_EC(ret);
  50203. #endif
  50204. ret = mp_unsigned_bin_size(NULL);
  50205. if (ret != 0)
  50206. return WC_TEST_RET_ENC_EC(ret);
  50207. #if defined(WC_MP_TO_RADIX) || defined(WOLFSSL_SP_MATH_ALL)
  50208. ret = mp_tohex(NULL, NULL);
  50209. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50210. return WC_TEST_RET_ENC_EC(ret);
  50211. ret = mp_tohex(a, NULL);
  50212. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50213. return WC_TEST_RET_ENC_EC(ret);
  50214. ret = mp_tohex(NULL, hexStr);
  50215. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50216. return WC_TEST_RET_ENC_EC(ret);
  50217. #endif
  50218. #if defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)
  50219. ret = mp_todecimal(NULL, NULL);
  50220. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50221. return WC_TEST_RET_ENC_EC(ret);
  50222. ret = mp_todecimal(a, NULL);
  50223. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50224. return WC_TEST_RET_ENC_EC(ret);
  50225. ret = mp_todecimal(NULL, decStr);
  50226. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50227. return WC_TEST_RET_ENC_EC(ret);
  50228. #endif
  50229. #ifdef WOLFSSL_SP_MATH_ALL
  50230. ret = mp_toradix(NULL, NULL, MP_RADIX_HEX);
  50231. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50232. return WC_TEST_RET_ENC_EC(ret);
  50233. ret = mp_toradix(a, NULL, MP_RADIX_HEX);
  50234. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50235. return WC_TEST_RET_ENC_EC(ret);
  50236. ret = mp_toradix(NULL, hexStr, MP_RADIX_HEX);
  50237. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50238. return WC_TEST_RET_ENC_EC(ret);
  50239. ret = mp_toradix(a, hexStr, 3);
  50240. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50241. return WC_TEST_RET_ENC_EC(ret);
  50242. ret = mp_radix_size(NULL, MP_RADIX_HEX, NULL);
  50243. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50244. return WC_TEST_RET_ENC_EC(ret);
  50245. ret = mp_radix_size(a, MP_RADIX_HEX, NULL);
  50246. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50247. return WC_TEST_RET_ENC_EC(ret);
  50248. ret = mp_radix_size(NULL, MP_RADIX_HEX, &size);
  50249. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50250. return WC_TEST_RET_ENC_EC(ret);
  50251. ret = mp_radix_size(a, 3, &size);
  50252. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50253. return WC_TEST_RET_ENC_EC(ret);
  50254. #endif
  50255. return 0;
  50256. }
  50257. #endif
  50258. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  50259. static wc_test_ret_t mp_test_set_is_bit(mp_int* a)
  50260. {
  50261. int i, j;
  50262. wc_test_ret_t ret;
  50263. mp_zero(a);
  50264. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50265. if (mp_is_bit_set(a, i))
  50266. return WC_TEST_RET_ENC_NC;
  50267. for (j = 0; j < i; j++) {
  50268. if (!mp_is_bit_set(a, j))
  50269. return WC_TEST_RET_ENC_NC;
  50270. }
  50271. if (mp_set_bit(a, i) != 0)
  50272. return WC_TEST_RET_ENC_NC;
  50273. if (!mp_is_bit_set(a, i))
  50274. return WC_TEST_RET_ENC_NC;
  50275. }
  50276. mp_zero(a);
  50277. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50278. if (mp_is_bit_set(a, i))
  50279. return WC_TEST_RET_ENC_NC;
  50280. }
  50281. for (i = 0; i <= DIGIT_BIT * 2; i++) {
  50282. mp_zero(a);
  50283. if (mp_set_bit(a, i) != 0)
  50284. return WC_TEST_RET_ENC_NC;
  50285. for (j = 0; j < i; j++) {
  50286. if (mp_is_bit_set(a, j))
  50287. return WC_TEST_RET_ENC_NC;
  50288. }
  50289. if (!mp_is_bit_set(a, i))
  50290. return WC_TEST_RET_ENC_NC;
  50291. }
  50292. #ifdef WOLFSSL_KEY_GEN
  50293. for (i = 0; i < DIGIT_BIT * 2; i++) {
  50294. mp_set(a, 1);
  50295. ret = mp_2expt(a, i);
  50296. if (ret != 0)
  50297. return WC_TEST_RET_ENC_EC(ret);
  50298. for (j = 0; j < i; j++) {
  50299. if (mp_is_bit_set(a, j))
  50300. return WC_TEST_RET_ENC_NC;
  50301. }
  50302. if (!mp_is_bit_set(a, i))
  50303. return WC_TEST_RET_ENC_NC;
  50304. }
  50305. #endif
  50306. #ifdef WOLFSSL_SP_MATH
  50307. mp_zero(a);
  50308. for (j = 1; j <= 3; j++) {
  50309. i = SP_INT_MAX_BITS - j;
  50310. if (mp_is_bit_set(a, i))
  50311. return WC_TEST_RET_ENC_NC;
  50312. if (mp_set_bit(a, i) != 0)
  50313. return WC_TEST_RET_ENC_NC;
  50314. if (!mp_is_bit_set(a, i))
  50315. return WC_TEST_RET_ENC_NC;
  50316. #ifdef WOLFSSL_KEY_GEN
  50317. ret = mp_2expt(a, i);
  50318. if (ret != 0)
  50319. return WC_TEST_RET_ENC_EC(ret);
  50320. if (!mp_is_bit_set(a, i))
  50321. return WC_TEST_RET_ENC_NC;
  50322. #endif
  50323. }
  50324. mp_zero(a);
  50325. for (j = 0; j <= 3; j++) {
  50326. i = SP_INT_MAX_BITS + j;
  50327. if (mp_is_bit_set(a, i))
  50328. return WC_TEST_RET_ENC_NC;
  50329. if (mp_set_bit(a, i) != WC_NO_ERR_TRACE(MP_VAL))
  50330. return WC_TEST_RET_ENC_NC;
  50331. #ifdef WOLFSSL_KEY_GEN
  50332. ret = mp_2expt(a, i);
  50333. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50334. return WC_TEST_RET_ENC_EC(ret);
  50335. #endif
  50336. }
  50337. #endif
  50338. (void)ret;
  50339. return 0;
  50340. }
  50341. #endif /* !WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */
  50342. static wc_test_ret_t mp_test_cmp(mp_int* a, mp_int* b)
  50343. {
  50344. wc_test_ret_t ret;
  50345. mp_zero(a);
  50346. mp_zero(b);
  50347. ret = mp_cmp_d(a, 0);
  50348. if (ret != MP_EQ)
  50349. return WC_TEST_RET_ENC_EC(ret);
  50350. ret = mp_cmp_d(a, 1);
  50351. if (ret != MP_LT)
  50352. return WC_TEST_RET_ENC_EC(ret);
  50353. ret = mp_cmp(a, b);
  50354. if (ret != MP_EQ)
  50355. return WC_TEST_RET_ENC_NC;
  50356. mp_set(a, 1);
  50357. ret = mp_cmp_d(a, 0);
  50358. if (ret != MP_GT)
  50359. return WC_TEST_RET_ENC_EC(ret);
  50360. ret = mp_cmp_d(a, 1);
  50361. if (ret != MP_EQ)
  50362. return WC_TEST_RET_ENC_EC(ret);
  50363. ret = mp_cmp_d(a, 2);
  50364. if (ret != MP_LT)
  50365. return WC_TEST_RET_ENC_EC(ret);
  50366. ret = mp_cmp(a, b);
  50367. if (ret != MP_GT)
  50368. return WC_TEST_RET_ENC_NC;
  50369. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50370. mp_read_radix(b, "1234567890123456789", MP_RADIX_HEX);
  50371. ret = mp_cmp_d(b, -1);
  50372. if (ret != MP_GT)
  50373. return WC_TEST_RET_ENC_EC(ret);
  50374. ret = mp_cmp(a, b);
  50375. if (ret != MP_LT)
  50376. return WC_TEST_RET_ENC_NC;
  50377. ret = mp_cmp(b, a);
  50378. if (ret != MP_GT)
  50379. return WC_TEST_RET_ENC_NC;
  50380. ret = mp_cmp(b, b);
  50381. if (ret != MP_EQ)
  50382. return WC_TEST_RET_ENC_NC;
  50383. #endif
  50384. #if (!defined(WOLFSSL_SP_MATH) && !defined(WOLFSSL_SP_MATH_ALL)) || \
  50385. defined(WOLFSSL_SP_INT_NEGATIVE)
  50386. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50387. mp_read_radix(a, "-1", MP_RADIX_HEX);
  50388. mp_read_radix(a, "1", MP_RADIX_HEX);
  50389. ret = mp_cmp(a, b);
  50390. if (ret != MP_LT)
  50391. return WC_TEST_RET_ENC_NC;
  50392. ret = mp_cmp(b, a);
  50393. if (ret != MP_GT)
  50394. return WC_TEST_RET_ENC_NC;
  50395. mp_read_radix(b, "-2", MP_RADIX_HEX);
  50396. ret = mp_cmp(a, b);
  50397. if (ret != MP_GT)
  50398. return WC_TEST_RET_ENC_NC;
  50399. ret = mp_cmp(b, a);
  50400. if (ret != MP_LT)
  50401. return WC_TEST_RET_ENC_NC;
  50402. #endif
  50403. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  50404. mp_read_radix(a, "-2", MP_RADIX_HEX);
  50405. ret = mp_cmp(a, b);
  50406. if (ret != MP_EQ)
  50407. return WC_TEST_RET_ENC_NC;
  50408. #endif
  50409. #endif
  50410. #if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
  50411. defined(WOLFSSL_ECC_GEN_REJECT_SAMPLING)
  50412. mp_zero(a);
  50413. mp_zero(b);
  50414. ret = mp_cmp_ct(a, b, 1);
  50415. if (ret != MP_EQ)
  50416. return WC_TEST_RET_ENC_EC(ret);
  50417. ret = mp_cmp_ct(a, a, a->used);
  50418. if (ret != MP_EQ)
  50419. return WC_TEST_RET_ENC_EC(ret);
  50420. #ifdef WOLFSSL_SP_MATH_ALL
  50421. ret = mp_cmp_ct(a, NULL, a->used);
  50422. if (ret != MP_GT)
  50423. return WC_TEST_RET_ENC_EC(ret);
  50424. ret = mp_cmp_ct(NULL, a, a->used);
  50425. if (ret != MP_LT)
  50426. return WC_TEST_RET_ENC_EC(ret);
  50427. #endif
  50428. mp_read_radix(a, "1", MP_RADIX_HEX);
  50429. ret = mp_cmp_ct(a, b, 1);
  50430. if (ret != MP_GT)
  50431. return WC_TEST_RET_ENC_EC(ret);
  50432. ret = mp_cmp_ct(b, a, 1);
  50433. if (ret != MP_LT)
  50434. return WC_TEST_RET_ENC_EC(ret);
  50435. mp_read_radix(a, "0123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50436. ret = mp_cmp_ct(a, b, a->used);
  50437. if (ret != MP_GT)
  50438. return WC_TEST_RET_ENC_EC(ret);
  50439. ret = mp_cmp_ct(b, a, a->used);
  50440. if (ret != MP_LT)
  50441. return WC_TEST_RET_ENC_EC(ret);
  50442. mp_read_radix(b, "1123456789abcdef0123456789abcdef", MP_RADIX_HEX);
  50443. ret = mp_cmp_ct(b, a, a->used);
  50444. if (ret != MP_GT)
  50445. return WC_TEST_RET_ENC_EC(ret);
  50446. ret = mp_cmp_ct(a, b, a->used);
  50447. if (ret != MP_LT)
  50448. return WC_TEST_RET_ENC_EC(ret);
  50449. mp_read_radix(b, "0123456789abcdef0123456789abcdf0", MP_RADIX_HEX);
  50450. ret = mp_cmp_ct(b, a, a->used);
  50451. if (ret != MP_GT)
  50452. return WC_TEST_RET_ENC_EC(ret);
  50453. ret = mp_cmp_ct(a, b, a->used);
  50454. if (ret != MP_LT)
  50455. return WC_TEST_RET_ENC_EC(ret);
  50456. mp_read_radix(b, "0123456789abcdf0", MP_RADIX_HEX);
  50457. ret = mp_cmp_ct(a, b, a->used);
  50458. if (ret != MP_GT)
  50459. return WC_TEST_RET_ENC_EC(ret);
  50460. ret = mp_cmp_ct(b, a, a->used);
  50461. if (ret != MP_LT)
  50462. return WC_TEST_RET_ENC_EC(ret);
  50463. #endif
  50464. return 0;
  50465. }
  50466. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  50467. static wc_test_ret_t mp_test_shbd(mp_int* a, mp_int* b, WC_RNG* rng)
  50468. {
  50469. wc_test_ret_t ret;
  50470. int i, j, k;
  50471. #ifndef WOLFSSL_SP_MATH
  50472. for (i = 0; i < 10; i++) {
  50473. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50474. ret = randNum(a, j, rng, NULL);
  50475. if (ret != MP_OKAY)
  50476. return WC_TEST_RET_ENC_EC(ret);
  50477. mp_copy(a, b);
  50478. for (k = 0; k <= DIGIT_BIT * 2; k++) {
  50479. ret = mp_mul_2d(a, k, a);
  50480. if (ret != MP_OKAY)
  50481. return WC_TEST_RET_ENC_EC(ret);
  50482. mp_rshb(a, k);
  50483. ret = mp_cmp(a, b);
  50484. if (ret != MP_EQ)
  50485. return WC_TEST_RET_ENC_NC;
  50486. }
  50487. }
  50488. }
  50489. #endif
  50490. for (i = 0; i < 10; i++) {
  50491. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 3; j++) {
  50492. ret = randNum(a, j, rng, NULL);
  50493. if (ret != MP_OKAY)
  50494. return WC_TEST_RET_ENC_EC(ret);
  50495. mp_copy(a, b);
  50496. for (k = 0; k < 10; k++) {
  50497. ret = mp_lshd(a, k);
  50498. if (ret != MP_OKAY)
  50499. return WC_TEST_RET_ENC_EC(ret);
  50500. #ifndef WOLFSSL_SP_MATH
  50501. mp_rshd(a, k);
  50502. #else
  50503. mp_rshb(a, k * SP_WORD_SIZE);
  50504. #endif
  50505. ret = mp_cmp(a, b);
  50506. if (ret != MP_EQ)
  50507. return WC_TEST_RET_ENC_NC;
  50508. }
  50509. }
  50510. }
  50511. #ifndef WOLFSSL_SP_MATH
  50512. mp_zero(a);
  50513. mp_rshd(a, 1);
  50514. if (!mp_iszero(a))
  50515. return WC_TEST_RET_ENC_NC;
  50516. mp_set(a, 1);
  50517. mp_rshd(a, 1);
  50518. if (!mp_iszero(a))
  50519. return WC_TEST_RET_ENC_NC;
  50520. mp_set(a, 1);
  50521. mp_rshd(a, 2);
  50522. if (!mp_iszero(a))
  50523. return WC_TEST_RET_ENC_NC;
  50524. #endif
  50525. return 0;
  50526. }
  50527. #endif
  50528. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  50529. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  50530. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  50531. static wc_test_ret_t mp_test_div(mp_int* a, mp_int* d, mp_int* r, mp_int* rem,
  50532. WC_RNG* rng)
  50533. {
  50534. wc_test_ret_t ret;
  50535. int i, j, k;
  50536. mp_zero(a);
  50537. mp_zero(d);
  50538. ret = mp_div(a, d, r, rem);
  50539. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50540. return WC_TEST_RET_ENC_EC(ret);
  50541. mp_set(d, 1);
  50542. ret = mp_div(a, d, r, rem);
  50543. if (ret != MP_OKAY)
  50544. return WC_TEST_RET_ENC_EC(ret);
  50545. if (!mp_iszero(r))
  50546. return WC_TEST_RET_ENC_EC(ret);
  50547. if (!mp_iszero(rem))
  50548. return WC_TEST_RET_ENC_EC(ret);
  50549. mp_set(a, 1);
  50550. ret = mp_div(a, d, r, rem);
  50551. if (ret != MP_OKAY)
  50552. return WC_TEST_RET_ENC_EC(ret);
  50553. if (!mp_isone(r))
  50554. return WC_TEST_RET_ENC_EC(ret);
  50555. if (!mp_iszero(rem))
  50556. return WC_TEST_RET_ENC_EC(ret);
  50557. for (i = 0; i < 100; i++) {
  50558. for (j = 1; j < (DIGIT_BIT + 7) / 8 * 2; j++) {
  50559. ret = randNum(d, j, rng, NULL);
  50560. if (ret != MP_OKAY)
  50561. return WC_TEST_RET_ENC_EC(ret);
  50562. for (k = 1; k < (DIGIT_BIT + 7) / 8 * 2 + 1; k++) {
  50563. ret = randNum(a, k, rng, NULL);
  50564. if (ret != MP_OKAY)
  50565. return WC_TEST_RET_ENC_EC(ret);
  50566. ret = mp_div(a, d, NULL, rem);
  50567. if (ret != MP_OKAY)
  50568. return WC_TEST_RET_ENC_EC(ret);
  50569. ret = mp_div(a, d, r, NULL);
  50570. if (ret != MP_OKAY)
  50571. return WC_TEST_RET_ENC_EC(ret);
  50572. ret = mp_div(a, d, r, rem);
  50573. if (ret != MP_OKAY)
  50574. return WC_TEST_RET_ENC_EC(ret);
  50575. mp_mul(r, d, r);
  50576. mp_add(r, rem, r);
  50577. if (mp_cmp(r, a) != MP_EQ)
  50578. return WC_TEST_RET_ENC_NC;
  50579. }
  50580. }
  50581. }
  50582. ret = randNum(d, (DIGIT_BIT + 7) / 8 * 2, rng, NULL);
  50583. if (ret != MP_OKAY)
  50584. return WC_TEST_RET_ENC_EC(ret);
  50585. mp_add(d, d, a);
  50586. mp_set(rem, 1);
  50587. mp_div(a, d, NULL, rem);
  50588. if (ret != MP_OKAY)
  50589. return WC_TEST_RET_ENC_EC(ret);
  50590. if (!mp_iszero(rem))
  50591. return WC_TEST_RET_ENC_EC(ret);
  50592. mp_set(r, 1);
  50593. mp_div(a, d, r, NULL);
  50594. if (ret != MP_OKAY)
  50595. return WC_TEST_RET_ENC_EC(ret);
  50596. if (mp_cmp_d(r, 2) != MP_EQ)
  50597. return WC_TEST_RET_ENC_EC(ret);
  50598. mp_set(r, 1);
  50599. mp_set(rem, 1);
  50600. mp_div(a, d, r, rem);
  50601. if (ret != MP_OKAY)
  50602. return WC_TEST_RET_ENC_EC(ret);
  50603. if (mp_cmp_d(r, 2) != MP_EQ)
  50604. return WC_TEST_RET_ENC_EC(ret);
  50605. if (!mp_iszero(rem))
  50606. return WC_TEST_RET_ENC_EC(ret);
  50607. mp_set(a, 0xfe);
  50608. mp_lshd(a, 3);
  50609. mp_add_d(a, 0xff, a);
  50610. mp_set(d, 0xfe);
  50611. mp_lshd(d, 2);
  50612. ret = mp_div(a, d, r, rem);
  50613. if (ret != MP_OKAY)
  50614. return WC_TEST_RET_ENC_EC(ret);
  50615. mp_mul(r, d, d);
  50616. mp_add(rem, d, d);
  50617. if (mp_cmp(a, d) != MP_EQ)
  50618. return WC_TEST_RET_ENC_NC;
  50619. /* Force (hi | lo) / d to be (d | 0) / d which will would not fit in
  50620. * a digit. So mp_div must detect and handle.
  50621. * For example: 0x800000 / 0x8001, DIGIT_BIT = 8
  50622. */
  50623. mp_zero(a);
  50624. mp_set_bit(a, DIGIT_BIT * 3 - 1);
  50625. mp_zero(d);
  50626. mp_set_bit(d, DIGIT_BIT * 2 - 1);
  50627. mp_add_d(d, 1, d);
  50628. ret = mp_div(a, d, r, rem);
  50629. if (ret != MP_OKAY)
  50630. return WC_TEST_RET_ENC_EC(ret);
  50631. /* Make sure [d | d] / d is handled. */
  50632. mp_zero(a);
  50633. mp_set_bit(a, DIGIT_BIT * 2 - 1);
  50634. mp_set_bit(a, DIGIT_BIT * 1 - 1);
  50635. mp_zero(d);
  50636. mp_set_bit(d, DIGIT_BIT - 1);
  50637. ret = mp_div(a, d, r, rem);
  50638. if (ret != MP_OKAY)
  50639. return WC_TEST_RET_ENC_EC(ret);
  50640. mp_zero(a);
  50641. mp_set_bit(a, DIGIT_BIT);
  50642. mp_set_bit(a, 0);
  50643. mp_zero(d);
  50644. if (mp_cmp(r, a) != MP_EQ)
  50645. return WC_TEST_RET_ENC_NC;
  50646. if (mp_cmp(rem, d) != MP_EQ)
  50647. return WC_TEST_RET_ENC_NC;
  50648. return 0;
  50649. }
  50650. #endif
  50651. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50652. !defined(WC_NO_RNG)
  50653. static wc_test_ret_t mp_test_prime(mp_int* a, WC_RNG* rng)
  50654. {
  50655. wc_test_ret_t ret;
  50656. int res;
  50657. ret = mp_rand_prime(a, 1, rng, NULL);
  50658. #if defined(WOLFSSL_SP_MATH_ALL)
  50659. if (ret != 0)
  50660. return WC_TEST_RET_ENC_EC(ret);
  50661. #else
  50662. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50663. return WC_TEST_RET_ENC_NC;
  50664. #endif
  50665. #ifndef WOLFSSL_SP_MATH
  50666. ret = mp_rand_prime(a, -5, rng, NULL);
  50667. if (ret != 0 || (a->dp[0] & 3) != 3)
  50668. return WC_TEST_RET_ENC_NC;
  50669. #endif
  50670. ret = mp_prime_is_prime(a, 1, &res);
  50671. if (ret != MP_OKAY)
  50672. return WC_TEST_RET_ENC_EC(ret);
  50673. #ifndef WOLFSSL_SP_MATH
  50674. if (res != MP_YES)
  50675. return WC_TEST_RET_ENC_EC(res);
  50676. #else
  50677. if (res != MP_NO)
  50678. return WC_TEST_RET_ENC_EC(res);
  50679. #endif
  50680. ret = mp_prime_is_prime(a, 0, &res);
  50681. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50682. return WC_TEST_RET_ENC_EC(ret);
  50683. ret = mp_prime_is_prime(a, -1, &res);
  50684. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50685. return WC_TEST_RET_ENC_EC(ret);
  50686. ret = mp_prime_is_prime(a, 257, &res);
  50687. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50688. return WC_TEST_RET_ENC_EC(ret);
  50689. mp_set(a, 1);
  50690. ret = mp_prime_is_prime(a, 1, &res);
  50691. if (ret != MP_OKAY)
  50692. return WC_TEST_RET_ENC_EC(ret);
  50693. if (res != MP_NO)
  50694. return WC_TEST_RET_ENC_EC(res);
  50695. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50696. if (ret != MP_OKAY)
  50697. return WC_TEST_RET_ENC_EC(ret);
  50698. if (res != MP_NO)
  50699. return WC_TEST_RET_ENC_EC(res);
  50700. mp_set(a, 2);
  50701. ret = mp_prime_is_prime(a, 1, &res);
  50702. if (ret != MP_OKAY)
  50703. return WC_TEST_RET_ENC_EC(ret);
  50704. if (res != MP_YES)
  50705. return WC_TEST_RET_ENC_EC(res);
  50706. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50707. if (ret != MP_OKAY)
  50708. return WC_TEST_RET_ENC_EC(ret);
  50709. if (res != MP_YES)
  50710. return WC_TEST_RET_ENC_EC(res);
  50711. mp_set(a, 0xfb);
  50712. ret = mp_prime_is_prime(a, 1, &res);
  50713. if (ret != MP_OKAY)
  50714. return WC_TEST_RET_ENC_EC(ret);
  50715. if (res != MP_YES)
  50716. return WC_TEST_RET_ENC_EC(res);
  50717. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50718. if (ret != MP_OKAY)
  50719. return WC_TEST_RET_ENC_EC(ret);
  50720. if (res != MP_YES)
  50721. return WC_TEST_RET_ENC_EC(res);
  50722. mp_set(a, 0x6);
  50723. ret = mp_prime_is_prime(a, 1, &res);
  50724. if (ret != MP_OKAY)
  50725. return WC_TEST_RET_ENC_EC(ret);
  50726. if (res != MP_NO)
  50727. return WC_TEST_RET_ENC_EC(res);
  50728. ret = mp_prime_is_prime_ex(a, 1, &res, rng);
  50729. if (ret != MP_OKAY)
  50730. return WC_TEST_RET_ENC_EC(ret);
  50731. if (res != MP_NO)
  50732. return WC_TEST_RET_ENC_EC(res);
  50733. mp_set_int(a, 0x655 * 0x65b);
  50734. ret = mp_prime_is_prime(a, 10, &res);
  50735. if (ret != MP_OKAY)
  50736. return WC_TEST_RET_ENC_EC(ret);
  50737. if (res != MP_NO)
  50738. return WC_TEST_RET_ENC_EC(res);
  50739. ret = mp_prime_is_prime_ex(a, 10, &res, rng);
  50740. if (ret != MP_OKAY)
  50741. return WC_TEST_RET_ENC_EC(ret);
  50742. if (res != MP_NO)
  50743. return WC_TEST_RET_ENC_EC(res);
  50744. return 0;
  50745. }
  50746. #endif
  50747. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  50748. static wc_test_ret_t mp_test_lcm_gcd(mp_int* a, mp_int* b, mp_int* r, mp_int* exp,
  50749. WC_RNG* rng)
  50750. {
  50751. wc_test_ret_t ret;
  50752. int i;
  50753. WOLFSSL_SMALL_STACK_STATIC const int kat[][3] = {
  50754. { 1, 1, 1 }, { 2, 1, 2 }, { 1, 2, 2 }, { 2, 4, 4 }, { 4, 2, 4 },
  50755. { 12, 56, 168 }, { 56, 12, 168 }
  50756. };
  50757. (void)exp;
  50758. mp_set(a, 0);
  50759. mp_set(b, 1);
  50760. ret = mp_lcm(a, a, r);
  50761. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50762. return WC_TEST_RET_ENC_EC(ret);
  50763. ret = mp_lcm(a, b, r);
  50764. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50765. return WC_TEST_RET_ENC_EC(ret);
  50766. ret = mp_lcm(b, a, r);
  50767. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50768. return WC_TEST_RET_ENC_EC(ret);
  50769. for (i = 0; i < (int)(sizeof(kat) / sizeof(*kat)); i++) {
  50770. mp_set(a, kat[i][0]);
  50771. mp_set(b, kat[i][1]);
  50772. ret = mp_lcm(a, b, r);
  50773. if (ret != MP_OKAY)
  50774. return WC_TEST_RET_ENC_EC(ret);
  50775. mp_set(exp, kat[i][2]);
  50776. ret = mp_cmp(r, exp);
  50777. if (ret != MP_EQ)
  50778. return WC_TEST_RET_ENC_NC;
  50779. }
  50780. (void)rng;
  50781. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  50782. !defined(WC_NO_RNG)
  50783. ret = mp_rand_prime(a, 20, rng, NULL);
  50784. if (ret != MP_OKAY)
  50785. return WC_TEST_RET_ENC_EC(ret);
  50786. ret = mp_rand_prime(b, 20, rng, NULL);
  50787. if (ret != MP_OKAY)
  50788. return WC_TEST_RET_ENC_EC(ret);
  50789. ret = mp_mul(a, b, exp);
  50790. if (ret != MP_OKAY)
  50791. return WC_TEST_RET_ENC_EC(ret);
  50792. ret = mp_lcm(a, b, r);
  50793. if (ret != MP_OKAY)
  50794. return WC_TEST_RET_ENC_EC(ret);
  50795. ret = mp_cmp(r, exp);
  50796. if (ret != MP_EQ)
  50797. return WC_TEST_RET_ENC_NC;
  50798. ret = mp_lcm(b, a, r);
  50799. if (ret != MP_OKAY)
  50800. return WC_TEST_RET_ENC_EC(ret);
  50801. ret = mp_cmp(r, exp);
  50802. if (ret != MP_EQ)
  50803. return WC_TEST_RET_ENC_NC;
  50804. #endif
  50805. mp_set(a, 11);
  50806. mp_zero(b);
  50807. ret = mp_gcd(a, b, r);
  50808. if (ret != MP_OKAY)
  50809. return WC_TEST_RET_ENC_EC(ret);
  50810. ret = mp_cmp_d(r, 11);
  50811. if (ret != MP_EQ)
  50812. return WC_TEST_RET_ENC_EC(ret);
  50813. ret = mp_gcd(b, a, r);
  50814. if (ret != MP_OKAY)
  50815. return WC_TEST_RET_ENC_EC(ret);
  50816. ret = mp_cmp_d(r, 11);
  50817. if (ret != MP_EQ)
  50818. return WC_TEST_RET_ENC_EC(ret);
  50819. ret = mp_gcd(b, b, r);
  50820. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50821. return WC_TEST_RET_ENC_EC(ret);
  50822. return 0;
  50823. }
  50824. #endif
  50825. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  50826. defined(WOLFSSL_SP_MATH_ALL)
  50827. static wc_test_ret_t mp_test_mod_2d(mp_int* a, mp_int* r, mp_int* t, WC_RNG* rng)
  50828. {
  50829. wc_test_ret_t ret;
  50830. int i;
  50831. int j;
  50832. mp_set(a, 10);
  50833. ret = mp_mod_2d(a, 0, r);
  50834. if (ret != MP_OKAY)
  50835. return WC_TEST_RET_ENC_EC(ret);
  50836. if (!mp_iszero(r))
  50837. return WC_TEST_RET_ENC_NC;
  50838. ret = mp_mod_2d(a, 1, r);
  50839. if (ret != MP_OKAY)
  50840. return WC_TEST_RET_ENC_EC(ret);
  50841. if (!mp_iszero(r))
  50842. return WC_TEST_RET_ENC_NC;
  50843. ret = mp_mod_2d(a, 2, r);
  50844. if (ret != MP_OKAY)
  50845. return WC_TEST_RET_ENC_EC(ret);
  50846. ret = mp_cmp_d(r, 2);
  50847. if (ret != 0)
  50848. return WC_TEST_RET_ENC_EC(ret);
  50849. for (i = 2; i < 20; i++) {
  50850. ret = randNum(a, i, rng, NULL);
  50851. if (ret != 0)
  50852. return WC_TEST_RET_ENC_EC(ret);
  50853. for (j = 1; j <= mp_count_bits(a); j++) {
  50854. /* Get top part */
  50855. ret = mp_div_2d(a, j, t, NULL);
  50856. if (ret != 0)
  50857. return WC_TEST_RET_ENC_EC(ret);
  50858. ret = mp_mul_2d(t, j, t);
  50859. if (ret != 0)
  50860. return WC_TEST_RET_ENC_EC(ret);
  50861. /* Get bottom part */
  50862. ret = mp_mod_2d(a, j, r);
  50863. if (ret != 0)
  50864. return WC_TEST_RET_ENC_EC(ret);
  50865. /* Reassemble */
  50866. ret = mp_add(t, r, r);
  50867. if (ret != 0)
  50868. return WC_TEST_RET_ENC_EC(ret);
  50869. ret = mp_cmp(a, r);
  50870. if (ret != MP_EQ)
  50871. return WC_TEST_RET_ENC_NC;
  50872. }
  50873. }
  50874. #if !defined(WOLFSSL_SP_MATH) && defined(WOLFSSL_SP_INT_NEGATIVE)
  50875. /* Test negative value being moded. */
  50876. for (j = 0; j < 20; j++) {
  50877. ret = randNum(a, 2, rng, NULL);
  50878. if (ret != 0)
  50879. return WC_TEST_RET_ENC_EC(ret);
  50880. a->sign = MP_NEG;
  50881. for (i = 1; i < DIGIT_BIT * 3 + 1; i++) {
  50882. ret = mp_mod_2d(a, i, r);
  50883. if (ret != 0)
  50884. return WC_TEST_RET_ENC_EC(ret);
  50885. mp_zero(t);
  50886. ret = mp_set_bit(t, i);
  50887. if (ret != 0)
  50888. return WC_TEST_RET_ENC_EC(ret);
  50889. ret = mp_mod(a, t, t);
  50890. if (ret != 0)
  50891. return WC_TEST_RET_ENC_EC(ret);
  50892. ret = mp_cmp(r, t);
  50893. if (ret != MP_EQ)
  50894. return WC_TEST_RET_ENC_NC;
  50895. }
  50896. }
  50897. #endif
  50898. return 0;
  50899. }
  50900. #endif
  50901. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  50902. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  50903. static wc_test_ret_t mp_test_mod_d(mp_int* a, WC_RNG* rng)
  50904. {
  50905. wc_test_ret_t ret;
  50906. mp_digit r;
  50907. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50908. mp_digit rem;
  50909. int i;
  50910. #endif
  50911. (void)rng;
  50912. ret = mp_set(a, 1);
  50913. if (ret != MP_OKAY)
  50914. return WC_TEST_RET_ENC_EC(ret);
  50915. ret = mp_mod_d(a, 0, &r);
  50916. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  50917. return WC_TEST_RET_ENC_EC(ret);
  50918. mp_zero(a);
  50919. ret = mp_mod_d(a, 1, &r);
  50920. if (ret != MP_OKAY)
  50921. return WC_TEST_RET_ENC_EC(ret);
  50922. ret = mp_mod_d(a, 3, &r);
  50923. if (ret != MP_OKAY)
  50924. return WC_TEST_RET_ENC_EC(ret);
  50925. ret = mp_mod_d(a, 5, &r);
  50926. if (ret != MP_OKAY)
  50927. return WC_TEST_RET_ENC_EC(ret);
  50928. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_SP_MATH)
  50929. for (i = MP_MAX_TEST_BYTE_LEN - 16; i <= MP_MAX_TEST_BYTE_LEN; i++) {
  50930. ret = randNum(a, i, rng, NULL);
  50931. if (ret != MP_OKAY)
  50932. return WC_TEST_RET_ENC_EC(ret);
  50933. ret = mp_mod_d(a, 3, &r);
  50934. if (ret != MP_OKAY)
  50935. return WC_TEST_RET_ENC_EC(ret);
  50936. ret = mp_div_d(a, 3, a, &rem);
  50937. if (ret != MP_OKAY)
  50938. return WC_TEST_RET_ENC_EC(ret);
  50939. if (r != rem)
  50940. return WC_TEST_RET_ENC_NC;
  50941. }
  50942. #endif
  50943. return 0;
  50944. }
  50945. #endif
  50946. static wc_test_ret_t mp_test_mul_sqr(mp_int* a, mp_int* b, mp_int* r1, mp_int* r2,
  50947. WC_RNG* rng)
  50948. {
  50949. wc_test_ret_t ret;
  50950. int i;
  50951. for (i = 1; i < 16; i++) {
  50952. ret = randNum(a, i, rng, NULL);
  50953. if (ret != 0)
  50954. return WC_TEST_RET_ENC_EC(ret);
  50955. ret = mp_mul(a, a, r1);
  50956. if (ret != 0)
  50957. return WC_TEST_RET_ENC_EC(ret);
  50958. ret = mp_sqr(a, r2);
  50959. if (ret != 0)
  50960. return WC_TEST_RET_ENC_EC(ret);
  50961. ret = mp_cmp(r1, r2);
  50962. if (ret != MP_EQ)
  50963. return WC_TEST_RET_ENC_NC;
  50964. }
  50965. ret = mp_set(b, 0);
  50966. if (ret != MP_OKAY)
  50967. return WC_TEST_RET_ENC_EC(ret);
  50968. ret = mp_mul(a, b, r1);
  50969. if (ret != MP_OKAY)
  50970. return WC_TEST_RET_ENC_EC(ret);
  50971. if (!mp_iszero(r1))
  50972. return WC_TEST_RET_ENC_EC(ret);
  50973. ret = mp_sqr(b, r1);
  50974. if (ret != MP_OKAY)
  50975. return WC_TEST_RET_ENC_EC(ret);
  50976. if (!mp_iszero(r1))
  50977. return WC_TEST_RET_ENC_NC;
  50978. #ifdef WOLFSSL_SP_MATH_ALL
  50979. ret = mp_set(a, 1);
  50980. if (ret != MP_OKAY)
  50981. return WC_TEST_RET_ENC_EC(ret);
  50982. i = (SP_INT_DIGITS / 2) + 1;
  50983. ret = mp_mul_2d(a, i * SP_WORD_SIZE - 1, a);
  50984. if (ret != MP_OKAY)
  50985. return WC_TEST_RET_ENC_EC(ret);
  50986. ret = mp_set(b, 1);
  50987. if (ret != MP_OKAY)
  50988. return WC_TEST_RET_ENC_EC(ret);
  50989. ret = mp_mul_2d(b, (SP_INT_DIGITS - 1 - i) * SP_WORD_SIZE - 1, b);
  50990. if (ret != MP_OKAY)
  50991. return WC_TEST_RET_ENC_EC(ret);
  50992. ret = mp_mul(a, b, r1);
  50993. if (ret != MP_OKAY)
  50994. return WC_TEST_RET_ENC_EC(ret);
  50995. ret = mp_mul(a, a, r1);
  50996. if (ret == MP_OKAY)
  50997. return WC_TEST_RET_ENC_NC;
  50998. ret = mp_sqr(a, r1);
  50999. if (ret == MP_OKAY)
  51000. return WC_TEST_RET_ENC_NC;
  51001. ret = mp_sqr(b, r1);
  51002. if (ret != MP_OKAY)
  51003. return WC_TEST_RET_ENC_EC(ret);
  51004. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51005. (defined(HAVE_ECC) && defined(FP_ECC))
  51006. ret = mp_mulmod(a, b, b, r1);
  51007. if (ret != MP_OKAY)
  51008. return WC_TEST_RET_ENC_EC(ret);
  51009. ret = mp_mulmod(a, a, b, r1);
  51010. if (ret == MP_OKAY)
  51011. return WC_TEST_RET_ENC_NC;
  51012. #if defined(HAVE_ECC) && (defined(ECC_SHAMIR) || defined(FP_ECC))
  51013. ret = mp_sqrmod(a, b, r1);
  51014. if (ret == MP_OKAY)
  51015. return WC_TEST_RET_ENC_NC;
  51016. ret = mp_sqrmod(b, a, r1);
  51017. if (ret != MP_OKAY)
  51018. return WC_TEST_RET_ENC_EC(ret);
  51019. #endif /* HAVE_ECC && (ECC_SHAMIR || FP_ECC) */
  51020. #endif /* WOLFSSL_SP_MATH_ALL || WOLFSSL_HAVE_SP_DH || (HAVE_ECC && FP_ECC) */
  51021. #endif /* WOLFSSL_SP_MATH_ALL */
  51022. return 0;
  51023. }
  51024. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  51025. defined(OPENSSL_EXTRA)
  51026. static wc_test_ret_t mp_test_invmod(mp_int* a, mp_int* m, mp_int* r)
  51027. {
  51028. wc_test_ret_t ret;
  51029. mp_set(a, 0);
  51030. mp_set(m, 1);
  51031. ret = mp_invmod(a, m, r);
  51032. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51033. return WC_TEST_RET_ENC_EC(ret);
  51034. ret = mp_invmod(m, a, r);
  51035. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51036. return WC_TEST_RET_ENC_EC(ret);
  51037. mp_set(a, 2);
  51038. mp_set(m, 4);
  51039. ret = mp_invmod(a, m, r);
  51040. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51041. return WC_TEST_RET_ENC_EC(ret);
  51042. mp_set(a, 3);
  51043. mp_set(m, 6);
  51044. ret = mp_invmod(a, m, r);
  51045. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51046. return WC_TEST_RET_ENC_EC(ret);
  51047. mp_set(a, 5*9);
  51048. mp_set(m, 6*9);
  51049. ret = mp_invmod(a, m, r);
  51050. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51051. return WC_TEST_RET_ENC_EC(ret);
  51052. mp_set(a, 1);
  51053. mp_set(m, 4);
  51054. ret = mp_invmod(a, m, r);
  51055. if (ret != MP_OKAY)
  51056. return WC_TEST_RET_ENC_EC(ret);
  51057. if (!mp_isone(r))
  51058. return WC_TEST_RET_ENC_NC;
  51059. mp_set(a, 3);
  51060. mp_set(m, 4);
  51061. ret = mp_invmod(a, m, r);
  51062. if (ret != MP_OKAY)
  51063. return WC_TEST_RET_ENC_EC(ret);
  51064. ret = mp_cmp_d(r, 3);
  51065. if (ret != 0)
  51066. return WC_TEST_RET_ENC_EC(ret);
  51067. mp_set(a, 3);
  51068. mp_set(m, 5);
  51069. ret = mp_invmod(a, m, r);
  51070. if (ret != MP_OKAY)
  51071. return WC_TEST_RET_ENC_EC(ret);
  51072. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51073. /* Maximum 'a' */
  51074. mp_set(a, 0);
  51075. mp_set_bit(a, (r->size / 2)* SP_WORD_SIZE - 1);
  51076. mp_sub_d(a, 1, a);
  51077. /* Modulus too big. */
  51078. mp_set(m, 0);
  51079. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE);
  51080. ret = mp_invmod(a, m, r);
  51081. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51082. return WC_TEST_RET_ENC_EC(ret);
  51083. /* Maximum modulus - even. */
  51084. mp_set(m, 0);
  51085. mp_set_bit(m, (r->size / 2) * SP_WORD_SIZE - 1);
  51086. ret = mp_invmod(a, m, r);
  51087. if (ret != MP_OKAY)
  51088. return WC_TEST_RET_ENC_EC(ret);
  51089. #endif
  51090. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_INT_NEGATIVE)
  51091. #if defined(OPENSSL_EXTRA) || !defined(NO_DSA) || defined(HAVE_ECC)
  51092. mp_read_radix(a, "-3", 16);
  51093. ret = mp_invmod(a, m, r);
  51094. if (ret != MP_OKAY)
  51095. return WC_TEST_RET_ENC_EC(ret);
  51096. #endif
  51097. #endif
  51098. #if defined(WOLFSSL_SP_MATH_ALL) && defined(HAVE_ECC)
  51099. mp_set(a, 0);
  51100. mp_set(m, 3);
  51101. ret = mp_invmod_mont_ct(a, m, r, 1);
  51102. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51103. return WC_TEST_RET_ENC_EC(ret);
  51104. mp_set(a, 1);
  51105. mp_set(m, 0);
  51106. ret = mp_invmod_mont_ct(a, m, r, 1);
  51107. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51108. return WC_TEST_RET_ENC_EC(ret);
  51109. mp_set(a, 1);
  51110. mp_set(m, 1);
  51111. ret = mp_invmod_mont_ct(a, m, r, 1);
  51112. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51113. return WC_TEST_RET_ENC_EC(ret);
  51114. mp_set(a, 1);
  51115. mp_set(m, 2);
  51116. ret = mp_invmod_mont_ct(a, m, r, 1);
  51117. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51118. return WC_TEST_RET_ENC_EC(ret);
  51119. mp_set(a, 1);
  51120. mp_set(m, 3);
  51121. ret = mp_invmod_mont_ct(a, m, r, 1);
  51122. if (ret != MP_OKAY)
  51123. return WC_TEST_RET_ENC_EC(ret);
  51124. #endif
  51125. return 0;
  51126. }
  51127. #endif /* !NO_RSA || HAVE_ECC || !NO_DSA || OPENSSL_EXTRA */
  51128. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51129. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51130. static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r)
  51131. {
  51132. wc_test_ret_t ret;
  51133. mp_set(b, 0x2);
  51134. mp_set(e, 0x3);
  51135. mp_set(m, 0x0);
  51136. ret = mp_exptmod_ex(b, e, 1, m, r);
  51137. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51138. return WC_TEST_RET_ENC_EC(ret);
  51139. ret = mp_exptmod_nct(b, e, m, r);
  51140. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51141. return WC_TEST_RET_ENC_EC(ret);
  51142. mp_set(b, 0x2);
  51143. mp_set(e, 0x3);
  51144. mp_set(m, 0x1);
  51145. ret = mp_exptmod_ex(b, e, 1, m, r);
  51146. if (ret != MP_OKAY)
  51147. return WC_TEST_RET_ENC_EC(ret);
  51148. if (!mp_iszero(r))
  51149. return WC_TEST_RET_ENC_NC;
  51150. ret = mp_exptmod_nct(b, e, m, r);
  51151. if (ret != MP_OKAY)
  51152. return WC_TEST_RET_ENC_EC(ret);
  51153. if (!mp_iszero(r))
  51154. return WC_TEST_RET_ENC_NC;
  51155. mp_set(b, 0x2);
  51156. mp_set(e, 0x0);
  51157. mp_set(m, 0x7);
  51158. ret = mp_exptmod_ex(b, e, 1, m, r);
  51159. if (ret != MP_OKAY)
  51160. return WC_TEST_RET_ENC_EC(ret);
  51161. if (!mp_isone(r))
  51162. return WC_TEST_RET_ENC_NC;
  51163. ret = mp_exptmod_nct(b, e, m, r);
  51164. if (ret != MP_OKAY)
  51165. return WC_TEST_RET_ENC_EC(ret);
  51166. if (!mp_isone(r))
  51167. return WC_TEST_RET_ENC_NC;
  51168. mp_set(b, 0x0);
  51169. mp_set(e, 0x3);
  51170. mp_set(m, 0x7);
  51171. ret = mp_exptmod_ex(b, e, 1, m, r);
  51172. if (ret != MP_OKAY)
  51173. return WC_TEST_RET_ENC_EC(ret);
  51174. if (!mp_iszero(r))
  51175. return WC_TEST_RET_ENC_NC;
  51176. ret = mp_exptmod_nct(b, e, m, r);
  51177. if (ret != MP_OKAY)
  51178. return WC_TEST_RET_ENC_EC(ret);
  51179. if (!mp_iszero(r))
  51180. return WC_TEST_RET_ENC_NC;
  51181. mp_set(b, 0x10);
  51182. mp_set(e, 0x3);
  51183. mp_set(m, 0x7);
  51184. ret = mp_exptmod_ex(b, e, 1, m, r);
  51185. if (ret != MP_OKAY)
  51186. return WC_TEST_RET_ENC_EC(ret);
  51187. ret = mp_exptmod_nct(b, e, m, r);
  51188. if (ret != MP_OKAY)
  51189. return WC_TEST_RET_ENC_EC(ret);
  51190. mp_set(b, 0x7);
  51191. mp_set(e, 0x3);
  51192. mp_set(m, 0x7);
  51193. ret = mp_exptmod_ex(b, e, 1, m, r);
  51194. if (ret != MP_OKAY)
  51195. return WC_TEST_RET_ENC_EC(ret);
  51196. if (!mp_iszero(r))
  51197. return WC_TEST_RET_ENC_NC;
  51198. ret = mp_exptmod_nct(b, e, m, r);
  51199. if (ret != MP_OKAY)
  51200. return WC_TEST_RET_ENC_EC(ret);
  51201. if (!mp_iszero(r))
  51202. return WC_TEST_RET_ENC_NC;
  51203. #ifndef WOLFSSL_SP_MATH
  51204. mp_set(b, 0x01);
  51205. mp_mul_2d(b, DIGIT_BIT, b);
  51206. mp_add_d(b, 1, b);
  51207. mp_set(e, 0x3);
  51208. mp_copy(b, m);
  51209. ret = mp_exptmod_ex(b, e, 1, m, r);
  51210. if (ret != MP_OKAY)
  51211. return WC_TEST_RET_ENC_EC(ret);
  51212. if (!mp_iszero(r))
  51213. return WC_TEST_RET_ENC_NC;
  51214. ret = mp_exptmod_nct(b, e, m, r);
  51215. if (ret != MP_OKAY)
  51216. return WC_TEST_RET_ENC_EC(ret);
  51217. if (!mp_iszero(r))
  51218. return WC_TEST_RET_ENC_NC;
  51219. #endif
  51220. mp_set(b, 0x2);
  51221. mp_set(e, 0x3);
  51222. mp_set(m, 0x7);
  51223. ret = mp_exptmod_ex(b, e, 1, m, r);
  51224. if (ret != MP_OKAY)
  51225. return WC_TEST_RET_ENC_EC(ret);
  51226. ret = mp_exptmod_nct(b, e, m, r);
  51227. if (ret != MP_OKAY)
  51228. return WC_TEST_RET_ENC_EC(ret);
  51229. #ifdef WOLFSSL_SP_MATH_ALL
  51230. mp_set(b, 0x2);
  51231. mp_set(e, 0x3);
  51232. mp_set(m, 0x01);
  51233. mp_mul_2d(m, SP_WORD_SIZE * SP_INT_DIGITS / 2, m);
  51234. mp_add_d(m, 0x01, m);
  51235. ret = mp_exptmod_ex(b, e, 1, m, r);
  51236. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51237. return WC_TEST_RET_ENC_EC(ret);
  51238. ret = mp_exptmod_nct(b, e, m, r);
  51239. if (ret != WC_NO_ERR_TRACE(MP_VAL))
  51240. return WC_TEST_RET_ENC_EC(ret);
  51241. #endif
  51242. return 0;
  51243. }
  51244. #endif /* !NO_RSA || !NO_DSA || !NO_DH || (HAVE_ECC && HAVE_COMP_KEY) ||
  51245. * OPENSSL_EXTRA */
  51246. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51247. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51248. static wc_test_ret_t mp_test_mont(mp_int* a, mp_int* m, mp_int* n, mp_int* r, WC_RNG* rng)
  51249. {
  51250. wc_test_ret_t ret;
  51251. mp_digit mp;
  51252. static int exp[] = { 7, 8, 16, 27, 32, 64,
  51253. 127, 128, 255, 256,
  51254. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51255. 383, 384, 2033, 2048
  51256. #endif
  51257. };
  51258. static mp_digit sub[] = { 0x01, 0x05, 0x0f, 0x27, 0x05, 0x3b,
  51259. 0x01, 0x9f, 0x13, 0xbd,
  51260. #if defined(SP_WORD_SIZE) && SP_WORD_SIZE > 8
  51261. 0x1f, 0x13d, 0x45, 0x615
  51262. #endif
  51263. };
  51264. int bits[] = { 256, 384,
  51265. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 4096
  51266. 2048,
  51267. #endif
  51268. #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS > 6144
  51269. 3072
  51270. #endif
  51271. };
  51272. int i;
  51273. int j;
  51274. for (i = 0; i < (int)(sizeof(exp) / sizeof(*exp)); i++) {
  51275. if (exp[i] >= DIGIT_BIT)
  51276. continue;
  51277. mp_zero(m);
  51278. ret = mp_set_bit(m, exp[i]);
  51279. if (ret != MP_OKAY)
  51280. return WC_TEST_RET_ENC_EC(ret);
  51281. ret = mp_sub_d(m, sub[i], m);
  51282. if (ret != MP_OKAY)
  51283. return WC_TEST_RET_ENC_EC(ret);
  51284. ret = mp_montgomery_setup(m, &mp);
  51285. if (ret != MP_OKAY)
  51286. return WC_TEST_RET_ENC_EC(ret);
  51287. ret = mp_montgomery_calc_normalization(n, m);
  51288. if (ret != MP_OKAY)
  51289. return WC_TEST_RET_ENC_EC(ret);
  51290. for (j = 0; j < 10; j++) {
  51291. ret = randNum(a, (exp[i] + DIGIT_BIT - 1) / DIGIT_BIT, rng, NULL);
  51292. if (ret != 0)
  51293. return WC_TEST_RET_ENC_EC(ret);
  51294. ret = mp_mod(a, m, a);
  51295. if (ret != 0)
  51296. return WC_TEST_RET_ENC_EC(ret);
  51297. /* r = a * a */
  51298. ret = mp_sqrmod(a, m, r);
  51299. if (ret != MP_OKAY)
  51300. return WC_TEST_RET_ENC_EC(ret);
  51301. /* Convert to Montgomery form = a*n */
  51302. ret = mp_mulmod(a, n, m, a);
  51303. if (ret != MP_OKAY)
  51304. return WC_TEST_RET_ENC_EC(ret);
  51305. /* a*a mod m == ((a*n) * (a*n)) / n / n */
  51306. ret = mp_sqr(a, a);
  51307. if (ret != MP_OKAY)
  51308. return WC_TEST_RET_ENC_EC(ret);
  51309. ret = mp_montgomery_reduce(a, m, mp);
  51310. if (ret != MP_OKAY)
  51311. return WC_TEST_RET_ENC_EC(ret);
  51312. ret = mp_montgomery_reduce(a, m, mp);
  51313. if (ret != MP_OKAY)
  51314. return WC_TEST_RET_ENC_EC(ret);
  51315. if (mp_cmp(a, r) != MP_EQ)
  51316. return WC_TEST_RET_ENC_NC;
  51317. }
  51318. }
  51319. /* Force carries. */
  51320. for (i = 0; i < (int)(sizeof(bits) / sizeof(*bits)); i++) {
  51321. /* a = 2^(bits*2) - 1 */
  51322. mp_zero(a);
  51323. mp_set_bit(a, bits[i] * 2);
  51324. ret = mp_sub_d(a, 1, a);
  51325. if (ret != MP_OKAY)
  51326. return WC_TEST_RET_ENC_EC(ret);
  51327. /* m = 2^(bits) - 1 */
  51328. mp_zero(m);
  51329. mp_set_bit(m, bits[i]);
  51330. ret = mp_sub_d(m, 1, m);
  51331. if (ret != MP_OKAY)
  51332. return WC_TEST_RET_ENC_EC(ret);
  51333. mp = 1;
  51334. /* result = r = 2^(bits) - 1 */
  51335. mp_zero(r);
  51336. mp_set_bit(r, bits[i]);
  51337. ret = mp_sub_d(r, 1, r);
  51338. if (ret != MP_OKAY)
  51339. return WC_TEST_RET_ENC_EC(ret);
  51340. ret = mp_montgomery_reduce(a, m, mp);
  51341. if (ret != MP_OKAY)
  51342. return WC_TEST_RET_ENC_EC(ret);
  51343. /* Result is m or 0 if reduced to range of modulus. */
  51344. if (mp_cmp(a, r) != MP_EQ && mp_iszero(a) != MP_YES)
  51345. return WC_TEST_RET_ENC_NC;
  51346. }
  51347. return 0;
  51348. }
  51349. #endif
  51350. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mp_test(void)
  51351. {
  51352. WC_RNG rng;
  51353. int rng_inited = 0;
  51354. wc_test_ret_t ret;
  51355. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51356. int i, j;
  51357. #ifndef WOLFSSL_SP_MATH
  51358. int k;
  51359. #endif
  51360. mp_digit d = 0;
  51361. #endif
  51362. #ifdef WOLFSSL_SMALL_STACK
  51363. mp_int *a = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51364. DYNAMIC_TYPE_TMP_BUFFER),
  51365. *b = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51366. DYNAMIC_TYPE_TMP_BUFFER),
  51367. *r1 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51368. DYNAMIC_TYPE_TMP_BUFFER),
  51369. *r2 = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51370. DYNAMIC_TYPE_TMP_BUFFER),
  51371. *p = (mp_int *)XMALLOC(sizeof(mp_int), HEAP_HINT,
  51372. DYNAMIC_TYPE_TMP_BUFFER);
  51373. if ((a == NULL) ||
  51374. (b == NULL) ||
  51375. (r1 == NULL) ||
  51376. (r2 == NULL) ||
  51377. (p == NULL))
  51378. {
  51379. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
  51380. }
  51381. #else
  51382. mp_int a[1], b[1], r1[1], r2[1], p[1];
  51383. #endif
  51384. WOLFSSL_ENTER("mp_test");
  51385. ret = mp_init_multi(a, b, r1, r2, NULL, NULL);
  51386. if (ret != 0)
  51387. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51388. #ifdef WOLFSSL_SP_MATH_ALL
  51389. mp_init_copy(p, a);
  51390. #else
  51391. ret = mp_init(p);
  51392. if (ret != 0)
  51393. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51394. #endif
  51395. #ifndef HAVE_FIPS
  51396. ret = wc_InitRng_ex(&rng, HEAP_HINT, devId);
  51397. #else
  51398. ret = wc_InitRng(&rng);
  51399. #endif
  51400. if (ret != 0)
  51401. goto done;
  51402. rng_inited = 1;
  51403. #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
  51404. mp_set_int(a, 0);
  51405. if (a->used != 0 || a->dp[0] != 0)
  51406. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51407. for (j = 1; j <= MP_MAX_TEST_BYTE_LEN; j++) {
  51408. for (i = 0; i < 4 * j; i++) {
  51409. /* New values to use. */
  51410. ret = randNum(p, j, &rng, NULL);
  51411. if (ret != 0)
  51412. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51413. ret = randNum(a, j, &rng, NULL);
  51414. if (ret != 0)
  51415. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51416. ret = randNum(b, j, &rng, NULL);
  51417. if (ret != 0)
  51418. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51419. ret = wc_RNG_GenerateBlock(&rng, (byte*)&d, sizeof(d));
  51420. if (ret != 0)
  51421. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51422. d &= MP_MASK;
  51423. #if !defined(WOLFSSL_SP_MATH) || (defined(HAVE_ECC) && \
  51424. (defined(ECC_SHAMIR) || defined(FP_ECC)))
  51425. /* Ensure sqrmod produce same result as mulmod. */
  51426. ret = mp_sqrmod(a, p, r1);
  51427. if (ret != 0)
  51428. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51429. ret = mp_mulmod(a, a, p, r2);
  51430. if (ret != 0)
  51431. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51432. if (mp_cmp(r1, r2) != 0) {
  51433. WOLFSSL_MSG("Fail: mp_mulmod result does not match mp_sqrmod!");
  51434. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51435. }
  51436. #endif
  51437. #if defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51438. #if defined(WOLFSSL_SP_MATH) || (defined(WOLFSSL_SP_MATH_ALL) && \
  51439. !defined(WOLFSSL_SP_INT_NEGATIVE))
  51440. ret = mp_addmod(a, b, p, r1);
  51441. if (ret != 0)
  51442. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51443. ret = mp_submod(r1, b, p, r2);
  51444. if (ret != 0)
  51445. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51446. ret = mp_mod(a, p, r1);
  51447. if (ret != 0)
  51448. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51449. if (mp_cmp(r1, r2) != MP_EQ)
  51450. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51451. #else
  51452. /* Ensure add with mod produce same result as sub with mod. */
  51453. ret = mp_addmod(a, b, p, r1);
  51454. if (ret != 0)
  51455. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51456. b->sign ^= 1;
  51457. ret = mp_submod(a, b, p, r2);
  51458. if (ret != 0)
  51459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51460. if (mp_cmp(r1, r2) != 0)
  51461. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51462. #endif
  51463. #endif
  51464. /* Ensure add digit produce same result as sub digit. */
  51465. ret = mp_add_d(a, d, r1);
  51466. if (ret != 0)
  51467. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51468. ret = mp_sub_d(r1, d, r2);
  51469. if (ret != 0)
  51470. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51471. if (mp_cmp(a, r2) != 0)
  51472. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51473. /* Invert - if p is even it will use the slow impl.
  51474. * - if p and a are even it will fail.
  51475. */
  51476. ret = mp_invmod(a, p, r1);
  51477. if (ret != 0 && ret != WC_NO_ERR_TRACE(MP_VAL))
  51478. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51479. #ifndef WOLFSSL_SP_MATH
  51480. /* Shift up and down number all bits in a digit. */
  51481. for (k = 0; k < DIGIT_BIT; k++) {
  51482. mp_mul_2d(a, k, r1);
  51483. mp_div_2d(r1, k, r2, p);
  51484. if (mp_cmp(a, r2) != 0)
  51485. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51486. if (!mp_iszero(p))
  51487. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51488. mp_rshb(r1, k);
  51489. if (mp_cmp(a, r1) != 0)
  51490. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51491. }
  51492. #endif
  51493. }
  51494. }
  51495. /* Test adding and subtracting zero from zero. */
  51496. mp_zero(a);
  51497. ret = mp_add_d(a, 0, r1);
  51498. if (ret != 0)
  51499. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51500. if (!mp_iszero(r1)) {
  51501. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51502. }
  51503. ret = mp_sub_d(a, 0, r2);
  51504. if (ret != 0)
  51505. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), done);
  51506. if (!mp_iszero(r2)) {
  51507. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51508. }
  51509. #if DIGIT_BIT >= 32
  51510. /* Check that setting a 32-bit digit works. */
  51511. d &= 0xffffffffU;
  51512. mp_set_int(a, d);
  51513. if (a->used != 1 || a->dp[0] != d)
  51514. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51515. #endif
  51516. /* Check setting a bit and testing a bit works. */
  51517. for (i = 0; i < MP_MAX_TEST_BYTE_LEN * 8; i++) {
  51518. mp_zero(a);
  51519. mp_set_bit(a, i);
  51520. if (!mp_is_bit_set(a, i))
  51521. ERROR_OUT(WC_TEST_RET_ENC_NC, done);
  51522. }
  51523. #endif
  51524. #if defined(HAVE_ECC) && defined(HAVE_COMP_KEY)
  51525. mp_zero(a);
  51526. i = mp_cnt_lsb(a);
  51527. if (i != 0)
  51528. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51529. mp_set(a, 1);
  51530. i = mp_cnt_lsb(a);
  51531. if (i != 0)
  51532. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51533. mp_set(a, 32);
  51534. i = mp_cnt_lsb(a);
  51535. if (i != 5)
  51536. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51537. mp_zero(a);
  51538. mp_set_bit(a, 129);
  51539. i = mp_cnt_lsb(a);
  51540. if (i != 129)
  51541. ERROR_OUT(WC_TEST_RET_ENC_I(i), done);
  51542. #endif
  51543. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51544. if ((ret = mp_test_param(a, b, r1, &rng)) != 0)
  51545. goto done;
  51546. #endif
  51547. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(USE_FAST_MATH)
  51548. if ((ret = mp_test_div_3(a, r1, &rng)) != 0)
  51549. goto done;
  51550. #endif
  51551. #if (defined(WOLFSSL_SP_MATH_ALL) && !defined(NO_RSA) && \
  51552. !defined(WOLFSSL_RSA_VERIFY_ONLY)) || \
  51553. (!defined WOLFSSL_SP_MATH && !defined(WOLFSSL_SP_MATH_ALL) && \
  51554. (defined(WOLFSSL_KEY_GEN) || defined(HAVE_COMP_KEY)))
  51555. if ((ret = mp_test_radix_10(a, r1, &rng)) != 0)
  51556. goto done;
  51557. #endif
  51558. #if defined(WOLFSSL_SP_MATH_ALL) || (!defined WOLFSSL_SP_MATH && \
  51559. defined(HAVE_ECC))
  51560. if ((ret = mp_test_radix_16(a, r1, &rng)) != 0)
  51561. goto done;
  51562. #endif
  51563. if ((ret = mp_test_shift(a, r1, &rng)) != 0)
  51564. goto done;
  51565. if ((ret = mp_test_add_sub_d(a, r1)) != 0)
  51566. goto done;
  51567. if ((ret = mp_test_read_to_bin(a)) != 0)
  51568. goto done;
  51569. #if defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51570. if ((ret = mp_test_set_int(a)) != 0)
  51571. goto done;
  51572. #endif
  51573. if ((ret = mp_test_cmp(a, r1)) != 0)
  51574. goto done;
  51575. #if !defined(NO_DH) || defined(HAVE_ECC) || !defined(WOLFSSL_RSA_VERIFY_ONLY)
  51576. if ((ret = mp_test_shbd(a, b, &rng)) != 0)
  51577. goto done;
  51578. #endif
  51579. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)
  51580. if ((ret = mp_test_set_is_bit(a)) != 0)
  51581. goto done;
  51582. #endif
  51583. #if defined(WOLFSSL_SP_MATH_ALL) || !defined(NO_DH) || defined(HAVE_ECC) || \
  51584. (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
  51585. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  51586. if ((ret = mp_test_div(a, b, r1, r2, &rng)) != 0)
  51587. goto done;
  51588. #endif
  51589. #if defined(WOLFSSL_KEY_GEN) && (!defined(NO_DH) || !defined(NO_DSA)) && \
  51590. !defined(WC_NO_RNG)
  51591. if ((ret = mp_test_prime(a, &rng)) != 0)
  51592. goto done;
  51593. #endif
  51594. #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN) && !defined(WC_RSA_BLINDING)
  51595. if ((ret = mp_test_lcm_gcd(a, b, r1, r2, &rng)) != 0)
  51596. goto done;
  51597. #endif
  51598. #if (!defined(WOLFSSL_SP_MATH) && !defined(USE_FAST_MATH)) || \
  51599. defined(WOLFSSL_SP_MATH_ALL)
  51600. if ((ret = mp_test_mod_2d(a, r1, p, &rng)) != 0)
  51601. goto done;
  51602. #endif
  51603. #if defined(WOLFSSL_SP_MATH_ALL) || defined(OPENSSL_EXTRA) || \
  51604. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY))
  51605. if ((ret = mp_test_mod_d(a, &rng)) != 0)
  51606. goto done;
  51607. #endif
  51608. if ((ret = mp_test_mul_sqr(a, b, r1, r2, &rng)) != 0)
  51609. goto done;
  51610. #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DSA) || \
  51611. defined(OPENSSL_EXTRA)
  51612. if ((ret = mp_test_invmod(a, b, r1)) != 0)
  51613. goto done;
  51614. #endif
  51615. #if !defined(NO_RSA) || !defined(NO_DSA) || !defined(NO_DH) || \
  51616. (defined(HAVE_ECC) && defined(HAVE_COMP_KEY)) || defined(OPENSSL_EXTRA)
  51617. if ((ret = mp_test_exptmod(a, b, r1, r2)) != 0)
  51618. goto done;
  51619. #endif
  51620. #if defined(WOLFSSL_SP_MATH_ALL) || defined(WOLFSSL_HAVE_SP_DH) || \
  51621. defined(HAVE_ECC) || (!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY))
  51622. if ((ret = mp_test_mont(a, b, r1, r2, &rng)) != 0)
  51623. goto done;
  51624. #endif
  51625. done:
  51626. #ifdef WOLFSSL_SMALL_STACK
  51627. if (p) {
  51628. mp_clear(p);
  51629. XFREE(p, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51630. }
  51631. if (r2) {
  51632. mp_clear(r2);
  51633. XFREE(r2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51634. }
  51635. if (r1) {
  51636. mp_clear(r1);
  51637. XFREE(r1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51638. }
  51639. if (b) {
  51640. mp_clear(b);
  51641. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51642. }
  51643. if (a) {
  51644. mp_clear(a);
  51645. XFREE(a, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51646. }
  51647. #else
  51648. mp_clear(p);
  51649. mp_clear(r2);
  51650. mp_clear(r1);
  51651. mp_clear(b);
  51652. mp_clear(a);
  51653. #endif
  51654. if (rng_inited)
  51655. wc_FreeRng(&rng);
  51656. return ret;
  51657. }
  51658. #endif /* WOLFSSL_PUBLIC_MP && ((WOLFSSL_SP_MATH_ALL &&
  51659. * !WOLFSSL_RSA_VERIFY_ONLY) || USE_FAST_MATH) */
  51660. #if defined(WOLFSSL_PUBLIC_MP) && defined(WOLFSSL_KEY_GEN)
  51661. typedef struct pairs_t {
  51662. const unsigned char* coeff;
  51663. int coeffSz;
  51664. int exp;
  51665. } pairs_t;
  51666. /*
  51667. n =p1p2p3, where pi = ki(p1-1)+1 with (k2,k3) = (173,293)
  51668. p1 = 2^192 * 0x000000000000e24fd4f6d6363200bf2323ec46285cac1d3a
  51669. + 2^0 * 0x0b2488b0c29d96c5e67f8bec15b54b189ae5636efe89b45b
  51670. */
  51671. static const unsigned char c192a[] =
  51672. {
  51673. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x4f,
  51674. 0xd4, 0xf6, 0xd6, 0x36, 0x32, 0x00, 0xbf, 0x23,
  51675. 0x23, 0xec, 0x46, 0x28, 0x5c, 0xac, 0x1d, 0x3a
  51676. };
  51677. static const unsigned char c0a[] =
  51678. {
  51679. 0x0b, 0x24, 0x88, 0xb0, 0xc2, 0x9d, 0x96, 0xc5,
  51680. 0xe6, 0x7f, 0x8b, 0xec, 0x15, 0xb5, 0x4b, 0x18,
  51681. 0x9a, 0xe5, 0x63, 0x6e, 0xfe, 0x89, 0xb4, 0x5b
  51682. };
  51683. static const pairs_t ecPairsA[] =
  51684. {
  51685. {c192a, sizeof(c192a), 192},
  51686. {c0a, sizeof(c0a), 0}
  51687. };
  51688. static const int kA[] = {173, 293};
  51689. static const unsigned char controlPrime[] = {
  51690. 0xe1, 0x76, 0x45, 0x80, 0x59, 0xb6, 0xd3, 0x49,
  51691. 0xdf, 0x0a, 0xef, 0x12, 0xd6, 0x0f, 0xf0, 0xb7,
  51692. 0xcb, 0x2a, 0x37, 0xbf, 0xa7, 0xf8, 0xb5, 0x4d,
  51693. 0xf5, 0x31, 0x35, 0xad, 0xe4, 0xa3, 0x94, 0xa1,
  51694. 0xdb, 0xf1, 0x96, 0xad, 0xb5, 0x05, 0x64, 0x85,
  51695. 0x83, 0xfc, 0x1b, 0x5b, 0x29, 0xaa, 0xbe, 0xf8,
  51696. 0x26, 0x3f, 0x76, 0x7e, 0xad, 0x1c, 0xf0, 0xcb,
  51697. 0xd7, 0x26, 0xb4, 0x1b, 0x05, 0x8e, 0x56, 0x86,
  51698. 0x7e, 0x08, 0x62, 0x21, 0xc1, 0x86, 0xd6, 0x47,
  51699. 0x79, 0x3e, 0xb7, 0x5d, 0xa4, 0xc6, 0x3a, 0xd7,
  51700. 0xb1, 0x74, 0x20, 0xf6, 0x50, 0x97, 0x41, 0x04,
  51701. 0x53, 0xed, 0x3f, 0x26, 0xd6, 0x6f, 0x91, 0xfa,
  51702. 0x68, 0x26, 0xec, 0x2a, 0xdc, 0x9a, 0xf1, 0xe7,
  51703. 0xdc, 0xfb, 0x73, 0xf0, 0x79, 0x43, 0x1b, 0x21,
  51704. 0xa3, 0x59, 0x04, 0x63, 0x52, 0x07, 0xc9, 0xd7,
  51705. 0xe6, 0xd1, 0x1b, 0x5d, 0x5e, 0x96, 0xfa, 0x53
  51706. };
  51707. static const unsigned char testOne[] = { 1 };
  51708. static wc_test_ret_t GenerateNextP(mp_int* p1, mp_int* p2, int k)
  51709. {
  51710. wc_test_ret_t ret;
  51711. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51712. mp_int *ki = (mp_int *)XMALLOC(sizeof(*ki), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51713. if (ki == NULL)
  51714. return MEMORY_E;
  51715. #else
  51716. mp_int ki[1];
  51717. #endif
  51718. ret = mp_init(ki);
  51719. if (ret != 0)
  51720. ret = WC_TEST_RET_ENC_EC(ret);
  51721. if (ret == 0) {
  51722. ret = mp_set(ki, (mp_digit)k);
  51723. if (ret != 0)
  51724. ret = WC_TEST_RET_ENC_EC(ret);
  51725. }
  51726. if (ret == 0) {
  51727. ret = mp_sub_d(p1, 1, p2);
  51728. if (ret != 0)
  51729. ret = WC_TEST_RET_ENC_EC(ret);
  51730. }
  51731. if (ret == 0) {
  51732. ret = mp_mul(p2, ki, p2);
  51733. if (ret != 0)
  51734. ret = WC_TEST_RET_ENC_EC(ret);
  51735. }
  51736. if (ret == 0) {
  51737. ret = mp_add_d(p2, 1, p2);
  51738. if (ret != 0)
  51739. ret = WC_TEST_RET_ENC_EC(ret);
  51740. }
  51741. mp_clear(ki);
  51742. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51743. XFREE(ki, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51744. #endif
  51745. return ret;
  51746. }
  51747. static wc_test_ret_t GenerateP(mp_int* p1, mp_int* p2, mp_int* p3,
  51748. const pairs_t* ecPairs, int ecPairsSz,
  51749. const int* k)
  51750. {
  51751. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51752. mp_int *x = NULL, *y = NULL;
  51753. #else
  51754. mp_int x[1], y[1];
  51755. #endif
  51756. wc_test_ret_t ret;
  51757. int i;
  51758. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51759. if (((x = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL) ||
  51760. ((y = (mp_int *)XMALLOC(sizeof(*x), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER)) == NULL)) {
  51761. ret = MEMORY_E;
  51762. goto out;
  51763. }
  51764. #endif
  51765. ret = mp_init_multi(x, y, NULL, NULL, NULL, NULL);
  51766. if (ret != 0) {
  51767. ret = WC_TEST_RET_ENC_EC(ret);
  51768. goto out;
  51769. }
  51770. for (i = 0; ret == 0 && i < ecPairsSz; i++) {
  51771. ret = mp_read_unsigned_bin(x, ecPairs[i].coeff, (word32)ecPairs[i].coeffSz);
  51772. if (ret != 0) {
  51773. ret = WC_TEST_RET_ENC_EC(ret);
  51774. break;
  51775. }
  51776. /* p1 = 2^exp */
  51777. ret = mp_2expt(y, ecPairs[i].exp);
  51778. if (ret != 0) {
  51779. ret = WC_TEST_RET_ENC_EC(ret);
  51780. break;
  51781. }
  51782. /* p1 = p1 * m */
  51783. ret = mp_mul(x, y, x);
  51784. if (ret != 0) {
  51785. ret = WC_TEST_RET_ENC_EC(ret);
  51786. break;
  51787. }
  51788. /* p1 += */
  51789. ret = mp_add(p1, x, p1);
  51790. if (ret != 0) {
  51791. ret = WC_TEST_RET_ENC_EC(ret);
  51792. break;
  51793. }
  51794. mp_zero(x);
  51795. mp_zero(y);
  51796. }
  51797. if (ret == 0)
  51798. ret = GenerateNextP(p1, p2, k[0]);
  51799. if (ret == 0)
  51800. ret = GenerateNextP(p1, p3, k[1]);
  51801. out:
  51802. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51803. if (x != NULL) {
  51804. mp_clear(x);
  51805. XFREE(x, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51806. }
  51807. if (y != NULL) {
  51808. mp_clear(y);
  51809. XFREE(y, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51810. }
  51811. #else
  51812. mp_clear(x);
  51813. mp_clear(y);
  51814. #endif
  51815. return ret;
  51816. }
  51817. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t prime_test(void)
  51818. {
  51819. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51820. mp_int *n = (mp_int *)XMALLOC(sizeof *n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51821. *p1 = (mp_int *)XMALLOC(sizeof *p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51822. *p2 = (mp_int *)XMALLOC(sizeof *p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER),
  51823. *p3 = (mp_int *)XMALLOC(sizeof *p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51824. #else
  51825. mp_int n[1],
  51826. p1[1],
  51827. p2[1],
  51828. p3[1];
  51829. #endif
  51830. wc_test_ret_t ret;
  51831. int isPrime = 0;
  51832. WC_RNG rng;
  51833. WOLFSSL_ENTER("prime_test");
  51834. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51835. if ((n == NULL) ||
  51836. (p1 == NULL) ||
  51837. (p2 == NULL) ||
  51838. (p3 == NULL))
  51839. ERROR_OUT(MEMORY_E, out);
  51840. #endif
  51841. ret = wc_InitRng(&rng);
  51842. if (ret != 0)
  51843. ret = WC_TEST_RET_ENC_EC(ret);
  51844. if (ret == 0) {
  51845. ret = mp_init_multi(n, p1, p2, p3, NULL, NULL);
  51846. if (ret != 0)
  51847. ret = WC_TEST_RET_ENC_EC(ret);
  51848. }
  51849. if (ret == 0)
  51850. ret = GenerateP(p1, p2, p3,
  51851. ecPairsA, sizeof(ecPairsA) / sizeof(ecPairsA[0]), kA);
  51852. if (ret == 0) {
  51853. ret = mp_mul(p1, p2, n);
  51854. if (ret != 0)
  51855. ret = WC_TEST_RET_ENC_EC(ret);
  51856. }
  51857. if (ret == 0) {
  51858. ret = mp_mul(n, p3, n);
  51859. if (ret != 0)
  51860. ret = WC_TEST_RET_ENC_EC(ret);
  51861. }
  51862. if (ret != 0)
  51863. ERROR_OUT(ret, out);
  51864. /* Check the old prime test using the number that false positives.
  51865. * This test result should indicate as not prime. */
  51866. ret = mp_prime_is_prime(n, 40, &isPrime);
  51867. if (ret != 0)
  51868. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51869. if (isPrime)
  51870. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51871. /* This test result should fail. It should indicate the value as prime. */
  51872. ret = mp_prime_is_prime(n, 8, &isPrime);
  51873. if (ret != 0)
  51874. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51875. if (!isPrime)
  51876. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51877. /* This test result should indicate the value as not prime. */
  51878. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51879. if (ret != 0)
  51880. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51881. if (isPrime)
  51882. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51883. ret = mp_read_unsigned_bin(n, controlPrime, sizeof(controlPrime));
  51884. if (ret != 0)
  51885. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51886. /* This test result should indicate the value as prime. */
  51887. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51888. if (ret != 0)
  51889. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51890. if (!isPrime)
  51891. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51892. /* This test result should indicate the value as prime. */
  51893. isPrime = -1;
  51894. ret = mp_prime_is_prime(n, 8, &isPrime);
  51895. if (ret != 0)
  51896. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51897. if (!isPrime)
  51898. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51899. ret = mp_read_unsigned_bin(n, testOne, sizeof(testOne));
  51900. if (ret != 0)
  51901. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51902. /* This test result should indicate the value as not prime. */
  51903. ret = mp_prime_is_prime_ex(n, 8, &isPrime, &rng);
  51904. if (ret != 0)
  51905. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51906. if (isPrime)
  51907. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51908. ret = mp_prime_is_prime(n, 8, &isPrime);
  51909. if (ret != 0)
  51910. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
  51911. if (isPrime)
  51912. ERROR_OUT(WC_TEST_RET_ENC_NC, out);
  51913. ret = 0;
  51914. out:
  51915. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  51916. if (n != NULL) {
  51917. mp_clear(n);
  51918. XFREE(n, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51919. }
  51920. if (p1 != NULL) {
  51921. mp_clear(p1);
  51922. XFREE(p1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51923. }
  51924. if (p2 != NULL) {
  51925. mp_clear(p2);
  51926. XFREE(p2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51927. }
  51928. if (p3 != NULL) {
  51929. mp_clear(p3);
  51930. XFREE(p3, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  51931. }
  51932. #else
  51933. mp_clear(p3);
  51934. mp_clear(p2);
  51935. mp_clear(p1);
  51936. mp_clear(n);
  51937. #endif
  51938. wc_FreeRng(&rng);
  51939. return ret;
  51940. }
  51941. #endif /* WOLFSSL_PUBLIC_MP */
  51942. #if defined(ASN_BER_TO_DER) && \
  51943. (defined(WOLFSSL_TEST_CERT) || defined(OPENSSL_EXTRA) || \
  51944. defined(OPENSSL_EXTRA_X509_SMALL))
  51945. /* wc_BerToDer is only public facing in the case of test cert or opensslextra */
  51946. typedef struct berDerTestData {
  51947. const byte *in;
  51948. word32 inSz;
  51949. const byte *out;
  51950. word32 outSz;
  51951. } berDerTestData;
  51952. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t berder_test(void)
  51953. {
  51954. wc_test_ret_t ret;
  51955. int i;
  51956. word32 len = 0, l;
  51957. byte out[32];
  51958. WOLFSSL_SMALL_STACK_STATIC const byte good1_in[] = { 0x30, 0x80, 0x00, 0x00 };
  51959. WOLFSSL_SMALL_STACK_STATIC const byte good1_out[] = { 0x30, 0x00 };
  51960. WOLFSSL_SMALL_STACK_STATIC const byte good2_in[] = { 0x30, 0x80, 0x02, 0x01, 0x01, 0x00, 0x00 };
  51961. WOLFSSL_SMALL_STACK_STATIC const byte good2_out[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51962. WOLFSSL_SMALL_STACK_STATIC const byte good3_in[] = {
  51963. 0x24, 0x80, 0x04, 0x01, 0x01, 0x00, 0x00
  51964. };
  51965. WOLFSSL_SMALL_STACK_STATIC const byte good3_out[] = { 0x04, 0x1, 0x01 };
  51966. WOLFSSL_SMALL_STACK_STATIC const byte good4_in[] = {
  51967. 0x30, 0x80,
  51968. 0x02, 0x01, 0x01,
  51969. 0x30, 0x80,
  51970. 0x24, 0x80,
  51971. 0x04, 0x01, 0x01,
  51972. 0x04, 0x02, 0x02, 0x03,
  51973. 0x00, 0x00,
  51974. 0x06, 0x01, 0x01,
  51975. 0x00, 0x00,
  51976. 0x31, 0x80,
  51977. 0x06, 0x01, 0x01,
  51978. 0x00, 0x00,
  51979. 0x00, 0x00,
  51980. };
  51981. WOLFSSL_SMALL_STACK_STATIC const byte good4_out[] = {
  51982. 0x30, 0x12,
  51983. 0x02, 0x01, 0x01,
  51984. 0x30, 0x08,
  51985. 0x04, 0x03, 0x01, 0x02, 0x03,
  51986. 0x06, 0x01, 0x01,
  51987. 0x31, 0x03,
  51988. 0x06, 0x01, 0x01
  51989. };
  51990. WOLFSSL_SMALL_STACK_STATIC const byte good5_in[] = { 0x30, 0x03, 0x02, 0x01, 0x01 };
  51991. berDerTestData testData[] = {
  51992. { good1_in, sizeof(good1_in), good1_out, sizeof(good1_out) },
  51993. { good2_in, sizeof(good2_in), good2_out, sizeof(good2_out) },
  51994. { good3_in, sizeof(good3_in), good3_out, sizeof(good3_out) },
  51995. { good4_in, sizeof(good4_in), good4_out, sizeof(good4_out) },
  51996. { good5_in, sizeof(good5_in), good5_in , sizeof(good5_in ) },
  51997. };
  51998. WOLFSSL_ENTER("berder_test");
  51999. for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
  52000. ret = wc_BerToDer(testData[i].in, testData[i].inSz, NULL, &len);
  52001. if (ret != WC_NO_ERR_TRACE(LENGTH_ONLY_E))
  52002. return WC_TEST_RET_ENC_I(i);
  52003. if (len != testData[i].outSz)
  52004. return WC_TEST_RET_ENC_I(i);
  52005. len = testData[i].outSz;
  52006. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &len);
  52007. if (ret != 0)
  52008. return WC_TEST_RET_ENC_I(i);
  52009. if (XMEMCMP(out, testData[i].out, len) != 0)
  52010. return WC_TEST_RET_ENC_I(i);
  52011. for (l = 1; l < testData[i].inSz; l++) {
  52012. ret = wc_BerToDer(testData[i].in, l, NULL, &len);
  52013. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  52014. return WC_TEST_RET_ENC_EC(ret);
  52015. len = testData[i].outSz;
  52016. ret = wc_BerToDer(testData[i].in, l, out, &len);
  52017. if (ret != WC_NO_ERR_TRACE(ASN_PARSE_E))
  52018. return WC_TEST_RET_ENC_EC(ret);
  52019. }
  52020. for (l = 0; l < testData[i].outSz-1; l++) {
  52021. ret = wc_BerToDer(testData[i].in, testData[i].inSz, out, &l);
  52022. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52023. return WC_TEST_RET_ENC_EC(ret);
  52024. }
  52025. }
  52026. ret = wc_BerToDer(NULL, 4, NULL, NULL);
  52027. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52028. return WC_TEST_RET_ENC_EC(ret);
  52029. ret = wc_BerToDer(out, 4, NULL, NULL);
  52030. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52031. return WC_TEST_RET_ENC_EC(ret);
  52032. ret = wc_BerToDer(NULL, 4, NULL, &len);
  52033. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52034. return WC_TEST_RET_ENC_EC(ret);
  52035. ret = wc_BerToDer(NULL, 4, out, NULL);
  52036. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52037. return WC_TEST_RET_ENC_EC(ret);
  52038. ret = wc_BerToDer(out, 4, out, NULL);
  52039. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52040. return WC_TEST_RET_ENC_EC(ret);
  52041. ret = wc_BerToDer(NULL, 4, out, &len);
  52042. if (ret != WC_NO_ERR_TRACE(BAD_FUNC_ARG))
  52043. return WC_TEST_RET_ENC_EC(ret);
  52044. for (l = 1; l < sizeof(good4_out); l++) {
  52045. len = l;
  52046. ret = wc_BerToDer(good4_in, sizeof(good4_in), out, &len);
  52047. if (ret != WC_NO_ERR_TRACE(BUFFER_E))
  52048. return WC_TEST_RET_ENC_EC(ret);
  52049. }
  52050. return 0;
  52051. }
  52052. #endif /* ASN_BER_TO_DER && (WOLFSSL_TEST_CERT || OPENSSL_EXTRA ||
  52053. OPENSSL_EXTRA_X509_SMALL */
  52054. #ifdef DEBUG_WOLFSSL
  52055. static THREAD_LS_T int log_cnt = 0;
  52056. static void my_Logging_cb(const int logLevel, const char *const logMessage)
  52057. {
  52058. (void)logLevel;
  52059. (void)logMessage;
  52060. log_cnt++;
  52061. }
  52062. #endif /* DEBUG_WOLFSSL */
  52063. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t logging_test(void)
  52064. {
  52065. wc_test_ret_t ret;
  52066. #ifdef DEBUG_WOLFSSL
  52067. const char* msg = "Testing, testing. 1, 2, 3, 4 ...";
  52068. byte a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  52069. byte b[256];
  52070. int i;
  52071. WOLFSSL_ENTER("logging_test (debug)");
  52072. for (i = 0; i < (int)sizeof(b); i++)
  52073. b[i] = i;
  52074. ret = wolfSSL_Debugging_ON();
  52075. if (ret != 0)
  52076. return WC_TEST_RET_ENC_EC(ret);
  52077. ret = wolfSSL_SetLoggingCb(my_Logging_cb);
  52078. if (ret != 0)
  52079. return WC_TEST_RET_ENC_EC(ret);
  52080. WOLFSSL_MSG(msg);
  52081. WOLFSSL_BUFFER(a, sizeof(a));
  52082. WOLFSSL_BUFFER(b, sizeof(b));
  52083. WOLFSSL_BUFFER(NULL, 0);
  52084. WOLFSSL_ERROR(MEMORY_E);
  52085. WOLFSSL_ERROR_MSG(msg);
  52086. /* turn off logs */
  52087. wolfSSL_Debugging_OFF();
  52088. /* capture log count */
  52089. i = log_cnt;
  52090. /* validate no logs are output when disabled */
  52091. WOLFSSL_MSG(msg);
  52092. WOLFSSL_BUFFER(a, sizeof(a));
  52093. WOLFSSL_BUFFER(b, sizeof(b));
  52094. WOLFSSL_BUFFER(NULL, 0);
  52095. WOLFSSL_ERROR(MEMORY_E);
  52096. WOLFSSL_ERROR_MSG(msg);
  52097. /* check the logs were disabled */
  52098. if (i != log_cnt)
  52099. return WC_TEST_RET_ENC_NC;
  52100. /* restore callback and leave logging enabled */
  52101. wolfSSL_SetLoggingCb(NULL);
  52102. wolfSSL_Debugging_ON();
  52103. /* suppress unused args */
  52104. (void)a;
  52105. (void)b;
  52106. #else
  52107. WOLFSSL_ENTER("logging_test");
  52108. ret = wolfSSL_Debugging_ON();
  52109. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52110. return WC_TEST_RET_ENC_EC(ret);
  52111. wolfSSL_Debugging_OFF();
  52112. ret = wolfSSL_SetLoggingCb(NULL);
  52113. if (ret != WC_NO_ERR_TRACE(NOT_COMPILED_IN))
  52114. return WC_TEST_RET_ENC_EC(ret);
  52115. #endif /* DEBUG_WOLFSSL */
  52116. return 0;
  52117. }
  52118. #if defined(__INCLUDE_NUTTX_CONFIG_H)
  52119. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t wolfcrypt_mutex_test(void)
  52120. #else
  52121. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t mutex_test(void)
  52122. #endif
  52123. {
  52124. #ifdef WOLFSSL_PTHREADS
  52125. wolfSSL_Mutex m;
  52126. #endif
  52127. #if defined(WOLFSSL_PTHREADS) || (!defined(WOLFSSL_NO_MALLOC) && \
  52128. !defined(WOLFSSL_USER_MUTEX) && defined(WOLFSSL_STATIC_MEMORY))
  52129. wc_test_ret_t ret;
  52130. #endif
  52131. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_USER_MUTEX)
  52132. #ifndef WOLFSSL_STATIC_MEMORY
  52133. wolfSSL_Mutex *mm = wc_InitAndAllocMutex();
  52134. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (1)");
  52135. #else
  52136. wolfSSL_Mutex *mm = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex),
  52137. HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52138. WOLFSSL_ENTER("[wolfcrypt_]mutex_test (2)");
  52139. if (mm != NULL) {
  52140. ret = wc_InitMutex(mm);
  52141. if (ret != 0) {
  52142. WOLFSSL_MSG("Init Mutex failed");
  52143. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52144. return WC_TEST_RET_ENC_EC(ret);
  52145. }
  52146. }
  52147. #endif
  52148. if (mm == NULL)
  52149. return WC_TEST_RET_ENC_ERRNO;
  52150. wc_FreeMutex(mm);
  52151. XFREE(mm, HEAP_HINT, DYNAMIC_TYPE_MUTEX);
  52152. #endif
  52153. /* Can optionally enable advanced pthread tests using "ENABLE_PTHREAD_LOCKFREE_TESTS" */
  52154. #ifdef WOLFSSL_PTHREADS
  52155. ret = wc_InitMutex(&m);
  52156. if (ret != 0)
  52157. return WC_TEST_RET_ENC_EC(ret);
  52158. ret = wc_LockMutex(&m);
  52159. if (ret != 0)
  52160. return WC_TEST_RET_ENC_EC(ret);
  52161. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52162. /* trying to free a locked mutex is not portable behavior with pthread */
  52163. /* Attempting to destroy a locked mutex results in undefined behavior */
  52164. ret = wc_FreeMutex(&m);
  52165. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52166. return WC_TEST_RET_ENC_EC(ret);
  52167. #endif
  52168. ret = wc_UnLockMutex(&m);
  52169. if (ret != 0)
  52170. return WC_TEST_RET_ENC_EC(ret);
  52171. ret = wc_FreeMutex(&m);
  52172. if (ret != 0)
  52173. return WC_TEST_RET_ENC_EC(ret);
  52174. #if !defined(WOLFSSL_SOLARIS) && defined(ENABLE_PTHREAD_LOCKFREE_TESTS)
  52175. /* Trying to use a pthread after free'ing is not portable behavior */
  52176. ret = wc_LockMutex(&m);
  52177. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52178. return WC_TEST_RET_ENC_EC(ret);
  52179. ret = wc_UnLockMutex(&m);
  52180. if (ret != WC_NO_ERR_TRACE(BAD_MUTEX_E))
  52181. return WC_TEST_RET_ENC_EC(ret);
  52182. #endif
  52183. #endif
  52184. return 0;
  52185. }
  52186. #if defined(USE_WOLFSSL_MEMORY) && !defined(FREERTOS)
  52187. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_LINUXKM) && \
  52188. !defined(WOLFSSL_STATIC_MEMORY)
  52189. static wc_test_ret_t malloc_cnt = 0;
  52190. static wc_test_ret_t realloc_cnt = 0;
  52191. static wc_test_ret_t free_cnt = 0;
  52192. #ifdef WOLFSSL_DEBUG_MEMORY
  52193. static void *my_Malloc_cb(size_t size, const char* func, unsigned int line)
  52194. {
  52195. (void) func;
  52196. (void) line;
  52197. #else
  52198. static void *my_Malloc_cb(size_t size)
  52199. {
  52200. #endif
  52201. malloc_cnt++;
  52202. #ifndef WOLFSSL_NO_MALLOC
  52203. return malloc(size); /* native heap */
  52204. #else
  52205. WOLFSSL_MSG("No malloc available");
  52206. (void)size;
  52207. return NULL;
  52208. #endif
  52209. }
  52210. #ifdef WOLFSSL_DEBUG_MEMORY
  52211. static void my_Free_cb(void *ptr, const char* func, unsigned int line)
  52212. {
  52213. (void) func;
  52214. (void) line;
  52215. #else
  52216. static void my_Free_cb(void *ptr)
  52217. {
  52218. #endif
  52219. free_cnt++;
  52220. #ifndef WOLFSSL_NO_MALLOC
  52221. free(ptr); /* native heap */
  52222. #else
  52223. WOLFSSL_MSG("No free available");
  52224. (void)ptr;
  52225. #endif
  52226. }
  52227. #ifdef WOLFSSL_DEBUG_MEMORY
  52228. static void *my_Realloc_cb(void *ptr, size_t size, const char* func, unsigned int line)
  52229. {
  52230. (void) func;
  52231. (void) line;
  52232. #else
  52233. static void *my_Realloc_cb(void *ptr, size_t size)
  52234. {
  52235. #endif
  52236. realloc_cnt++;
  52237. #ifndef WOLFSSL_NO_MALLOC
  52238. return realloc(ptr, size); /* native heap */
  52239. #else
  52240. WOLFSSL_MSG("No realloc available");
  52241. (void)ptr;
  52242. (void)size;
  52243. return NULL;
  52244. #endif
  52245. }
  52246. #endif /* !WOLFSSL_NO_MALLOC */
  52247. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t memcb_test(void)
  52248. {
  52249. wc_test_ret_t ret = 0;
  52250. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52251. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52252. byte* b = NULL;
  52253. #endif
  52254. wolfSSL_Malloc_cb mc;
  52255. wolfSSL_Free_cb fc;
  52256. wolfSSL_Realloc_cb rc;
  52257. WOLFSSL_ENTER("memcb_test");
  52258. /* Save existing memory callbacks */
  52259. ret = wolfSSL_GetAllocators(&mc, &fc, &rc);
  52260. if (ret != 0)
  52261. return WC_TEST_RET_ENC_EC(ret);
  52262. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52263. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52264. /* test realloc */
  52265. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52266. if (b == NULL) {
  52267. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_memcb);
  52268. }
  52269. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52270. b = NULL;
  52271. /* Use API. */
  52272. ret = wolfSSL_SetAllocators((wolfSSL_Malloc_cb)my_Malloc_cb,
  52273. (wolfSSL_Free_cb)my_Free_cb,
  52274. (wolfSSL_Realloc_cb)my_Realloc_cb);
  52275. if (ret != 0) {
  52276. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_memcb);
  52277. }
  52278. b = (byte*)XMALLOC(1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52279. b = (byte*)XREALLOC(b, 1024, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52280. XFREE(b, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52281. #ifndef WOLFSSL_STATIC_MEMORY
  52282. #ifndef WOLFSSL_CHECK_MEM_ZERO
  52283. if (malloc_cnt != 1 || free_cnt != 1 || realloc_cnt != 1)
  52284. #else
  52285. /* Checking zeroized memory means realloc is a malloc and free. */
  52286. if (malloc_cnt != 2 || free_cnt != 2 || realloc_cnt != 0)
  52287. #endif
  52288. #else
  52289. if (malloc_cnt != 0 || free_cnt != 0 || realloc_cnt != 0)
  52290. #endif
  52291. ret = WC_TEST_RET_ENC_NC;
  52292. #endif /* !WOLFSSL_NO_MALLOC */
  52293. #if !defined(WOLFSSL_NO_MALLOC) && !defined(WOLFSSL_NO_REALLOC) && \
  52294. !defined(WOLFSSL_LINUXKM) && !defined(WOLFSSL_STATIC_MEMORY)
  52295. exit_memcb:
  52296. /* reset malloc/free/realloc counts */
  52297. malloc_cnt = 0;
  52298. free_cnt = 0;
  52299. realloc_cnt = 0;
  52300. #endif
  52301. /* restore memory callbacks */
  52302. wolfSSL_SetAllocators(mc, fc, rc);
  52303. return ret;
  52304. }
  52305. #endif /* USE_WOLFSSL_MEMORY && !WOLFSSL_NO_MALLOC */
  52306. #if defined(WOLFSSL_CAAM_BLOB)
  52307. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t blob_test(void)
  52308. {
  52309. wc_test_ret_t ret = 0;
  52310. byte out[112];
  52311. byte blob[112];
  52312. word32 outSz;
  52313. WOLFSSL_SMALL_STACK_STATIC const byte iv[] =
  52314. {
  52315. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  52316. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
  52317. };
  52318. WOLFSSL_SMALL_STACK_STATIC const byte text[] =
  52319. {
  52320. 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
  52321. 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
  52322. 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
  52323. 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
  52324. 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
  52325. 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
  52326. 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
  52327. 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
  52328. };
  52329. WOLFSSL_ENTER("blob_test");
  52330. XMEMSET(blob, 0, sizeof(blob));
  52331. XMEMSET(out, 0, sizeof(out));
  52332. outSz = sizeof(blob);
  52333. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52334. if (ret != 0)
  52335. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52336. blob[outSz - 2] += 1;
  52337. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52338. if (ret == 0) { /* should fail with altered blob */
  52339. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52340. }
  52341. XMEMSET(blob, 0, sizeof(blob));
  52342. outSz = sizeof(blob);
  52343. ret = wc_caamCreateBlob((byte*)iv, sizeof(iv), blob, &outSz);
  52344. if (ret != 0)
  52345. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52346. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52347. if (ret != 0)
  52348. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52349. if (XMEMCMP(out, iv, sizeof(iv))) {
  52350. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52351. }
  52352. XMEMSET(blob, 0, sizeof(blob));
  52353. outSz = sizeof(blob);
  52354. ret = wc_caamCreateBlob((byte*)text, sizeof(text), blob, &outSz);
  52355. if (ret != 0)
  52356. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52357. ret = wc_caamOpenBlob(blob, outSz, out, &outSz);
  52358. if (ret != 0)
  52359. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_blob);
  52360. if (XMEMCMP(out, text, sizeof(text))) {
  52361. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_blob);
  52362. }
  52363. exit_blob:
  52364. return ret;
  52365. }
  52366. #endif /* WOLFSSL_CAAM_BLOB */
  52367. #ifdef WOLF_CRYPTO_CB
  52368. /* Example custom context for crypto callback */
  52369. typedef struct {
  52370. int exampleVar; /* flag for testing if only crypt is enabled. */
  52371. } myCryptoDevCtx;
  52372. #ifdef WOLF_CRYPTO_CB_ONLY_RSA
  52373. /* Testing rsa cb when CB_ONLY_RSA is enabled
  52374. * When CB_ONLY_RSA is enabled, software imple. is not available.
  52375. *
  52376. * ctx callback ctx
  52377. * returen 0 on success, otherwise return negative
  52378. */
  52379. static wc_test_ret_t rsa_onlycb_test(myCryptoDevCtx *ctx)
  52380. {
  52381. wc_test_ret_t ret = 0;
  52382. #if !defined(NO_RSA)
  52383. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52384. RsaKey *key = (RsaKey *)XMALLOC(sizeof *key,
  52385. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52386. byte* tmp = NULL;
  52387. #else
  52388. RsaKey key[1];
  52389. byte tmp[FOURK_BUF];
  52390. #endif
  52391. size_t bytes;
  52392. const word32 inLen = (word32)TEST_STRING_SZ;
  52393. word32 idx = 0;
  52394. word32 sigSz;
  52395. WOLFSSL_SMALL_STACK_STATIC const byte in[] = TEST_STRING;
  52396. byte out[RSA_TEST_BYTES];
  52397. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  52398. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096) && \
  52399. !defined(NO_FILESYSTEM)
  52400. XFILE file;
  52401. #endif
  52402. #ifdef WOLFSSL_KEY_GEN
  52403. WC_RNG rng;
  52404. #endif
  52405. #ifdef USE_CERT_BUFFERS_1024
  52406. bytes = (size_t)sizeof_client_key_der_1024;
  52407. if (bytes < (size_t)sizeof_client_cert_der_1024)
  52408. bytes = (size_t)sizeof_client_cert_der_1024;
  52409. #elif defined(USE_CERT_BUFFERS_2048)
  52410. bytes = (size_t)sizeof_client_key_der_2048;
  52411. if (bytes < (size_t)sizeof_client_cert_der_2048)
  52412. bytes = (size_t)sizeof_client_cert_der_2048;
  52413. #elif defined(USE_CERT_BUFFERS_3072)
  52414. bytes = (size_t)sizeof_client_key_der_3072;
  52415. if (bytes < (size_t)sizeof_client_cert_der_3072)
  52416. bytes = (size_t)sizeof_client_cert_der_3072;
  52417. #elif defined(USE_CERT_BUFFERS_4096)
  52418. bytes = (size_t)sizeof_client_key_der_4096;
  52419. if (bytes < (size_t)sizeof_client_cert_der_4096)
  52420. bytes = (size_t)sizeof_client_cert_der_4096;
  52421. #else
  52422. bytes = FOURK_BUF;
  52423. #endif
  52424. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52425. tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52426. if (tmp == NULL)
  52427. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52428. #endif
  52429. #ifdef USE_CERT_BUFFERS_1024
  52430. XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_der_1024);
  52431. #elif defined(USE_CERT_BUFFERS_2048)
  52432. XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
  52433. #elif defined(USE_CERT_BUFFERS_3072)
  52434. XMEMCPY(tmp, client_key_der_3072, (size_t)sizeof_client_key_der_3072);
  52435. #elif defined(USE_CERT_BUFFERS_4096)
  52436. XMEMCPY(tmp, client_key_der_4096, (size_t)sizeof_client_key_der_4096);
  52437. #elif !defined(NO_FILESYSTEM)
  52438. file = XFOPEN(clientKey, "rb");
  52439. if (!file) {
  52440. ret = WC_TEST_RET_ENC_ERRNO;
  52441. err_sys("can't open ./certs/client-key.der, "
  52442. "Please run from wolfSSL home dir", ret);
  52443. ERROR_OUT(ret, exit_onlycb);
  52444. }
  52445. bytes = XFREAD(tmp, 1, FOURK_BUF, file);
  52446. XFCLOSE(file);
  52447. if (bytes == 0)
  52448. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52449. #endif
  52450. #ifdef WOLFSSL_KEY_GEN
  52451. /* wc_CryptoCb_MakeRsaKey cb test, no actual making key
  52452. * wc_MakeRsaKey() -> rsa cb ->
  52453. * myCryptoDevCb -> wc_MakeRsaKey(CBONLY_TEST_DEVID)
  52454. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return 0(success)
  52455. */
  52456. ctx->exampleVar = 99;
  52457. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52458. if (ret != 0)
  52459. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52460. /* wc_MakeRsaKey() -> rsa cb ->
  52461. * myCryptoDevCb -> wc_MakeRsaKey(INVALID_DEVID)
  52462. * wc_MakeRsaKey(CBONLY_TEST_DEVID) expects to return NO_VALID_DEVID(failure)
  52463. */
  52464. ctx->exampleVar = 1;
  52465. ret = wc_MakeRsaKey(key, keySz, WC_RSA_EXPONENT, rng);
  52466. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52467. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52468. } else
  52469. /* reset return code */
  52470. ret = 0;
  52471. #endif
  52472. ret = wc_InitRsaKey_ex(key, HEAP_HINT, devId);
  52473. if (ret != 0)
  52474. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52475. ret = wc_RsaPrivateKeyDecode(tmp, &idx, key, (word32)bytes);
  52476. if (ret != 0)
  52477. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52478. sigSz = (word32)wc_RsaEncryptSize(key);
  52479. /* wc_CryptoCb_Rsa cb test, no actual rsa operation */
  52480. if (ret == 0) {
  52481. /* wc_SignatureGenerate() -> rsa cb ->
  52482. * myCryptoDevCb -> wc_RsaFunction(CBONLY_TEST_DEVID)
  52483. * wc_RsaFunction(CBONLY_TEST_DEVID) expects to return 0(success)
  52484. */
  52485. ctx->exampleVar = 99;
  52486. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52487. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52488. if (ret != 0)
  52489. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52490. }
  52491. if (ret == 0) {
  52492. /* wc_SignatureGenerate() -> rsa cb ->
  52493. * myCryptoDevCb -> wc_RsaFunction(INVALID_DEVID)
  52494. * wc_SignatureGenerate(INVALID_DEVID) expects to
  52495. * return NO_VALID_DEVID(failure)
  52496. */
  52497. ctx->exampleVar = 1;
  52498. ret = wc_SignatureGenerate(WC_HASH_TYPE_SHA256, WC_SIGNATURE_TYPE_RSA,
  52499. in, inLen, out, &sigSz, key, sizeof(*key), NULL);
  52500. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52501. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52502. } else
  52503. /* reset return code */
  52504. ret = 0;
  52505. }
  52506. exit_onlycb:
  52507. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52508. if (key != NULL) {
  52509. wc_FreeRsaKey(key);
  52510. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52511. }
  52512. XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52513. #else
  52514. wc_FreeRsaKey(key);
  52515. #endif
  52516. #endif
  52517. return ret;
  52518. }
  52519. #endif
  52520. #ifdef WOLF_CRYPTO_CB_ONLY_ECC
  52521. /* Testing rsa cb when CB_ONLY_ECC is enabled
  52522. * When CB_ONLY_ECC is enabled, software imple. is not available.
  52523. *
  52524. * ctx callback ctx
  52525. * returen 0 on success, otherwise return negative
  52526. */
  52527. static wc_test_ret_t ecc_onlycb_test(myCryptoDevCtx *ctx)
  52528. {
  52529. wc_test_ret_t ret = 0;
  52530. #if defined(HAVE_ECC)
  52531. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52532. ecc_key* key = (ecc_key *)XMALLOC(sizeof *key,
  52533. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52534. ecc_key* pub = (ecc_key *)XMALLOC(sizeof *pub,
  52535. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52536. byte* out = (byte*)XMALLOC(sizeof(byte),
  52537. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52538. #ifdef OPENSSL_EXTRA
  52539. byte* check = (byte*)XMALLOC(sizeof(byte)*(256), HEAP_HINT,
  52540. DYNAMIC_TYPE_TMP_BUFFER);
  52541. #endif
  52542. #else
  52543. ecc_key key[1];
  52544. ecc_key pub[1];
  52545. byte out[256];
  52546. #ifdef OPENSSL_EXTRA
  52547. unsigned char check[256];
  52548. #endif
  52549. #endif
  52550. #ifdef OPENSSL_EXTRA
  52551. WOLFSSL_EVP_PKEY* privKey = NULL;
  52552. WOLFSSL_EVP_PKEY* pubKey = NULL;
  52553. #ifdef USE_CERT_BUFFERS_256
  52554. ecc_key* pkey;
  52555. const unsigned char* cp;
  52556. #endif
  52557. WOLFSSL_EVP_MD_CTX mdCtx;
  52558. const char testData[] = "Hi There";
  52559. size_t checkSz = -1;
  52560. const unsigned char* p;
  52561. const unsigned char check_v[256] = {
  52562. 0x30,0x45,0x02,0x20,0x1b,0x5c,0x2a,0xf0,0x18,0x09,
  52563. 0x74,0x65,0xa1,0x04,0x76,0x3a,0xce,0xcc,0xe5,0x34,
  52564. 0x5e,0x89,0xed,0x40,0x1e,0x5a,0xb1,0x53,0xb4,0xff,
  52565. 0xc7,0x18,0xfe,0x0f,0xc7,0xa6,0x02,0x21,0x00,0xe5,
  52566. 0x70,0x21,0xfc,0xf9,0x63,0x36,0xfd,0x16,0x18,0x08,
  52567. 0x9a,0x63,0x61,0x0f,0xe7,0x7c,0xa3,0xc9,0x14,0xa3,
  52568. 0x30,0x87,0xf7,0xf5,0x70,0x19,0xaf,0x56,0x96,0x9b,
  52569. 0xd8,0x64,0xcd,0xd9,0xff,0x7b,0x2a,0x55,0x52,0xca,
  52570. 0x41,0xb2,0xa6,0xa4,0x8a,0x3b,0x02,0x20,0x8c,0xc5,
  52571. 0xf9,0xc1,0x7d,0x2a,0x65,0x6c,0xe6,0x5a,0xe3,0x76,
  52572. 0x9b,0xab,0x0b,0x9f,0xaf,0x62,0x5d,0xb2,0x60,0xd7,
  52573. 0xeb,0xb4,0x1b,0x73,0xdc,0x01,0x7d,0x7b,0xab,0xc1,
  52574. 0x0c,0x74,0x96,0x41,0xe6,0x3f,0xc5,0x86,0xe6,0x7d,
  52575. 0x2b,0x9d,0x54,0x6b,0xcd,0x31,0x35,0x1f,0xdb,0x49,
  52576. 0x1f,0x32,0x34,0xf8,0x57,0x12,0x86,0x5c,0x0e,0x80,
  52577. 0x55,0x8d,0xff,0xd8,0xbd,0xdf,0x32,0x26,0x62,0x42,
  52578. 0x09,0xda,0xf7,0x74,0xf2,0x3f,0xe6,0xf1,0x77,0x82,
  52579. 0xce,0xe4,0xbb,0x61,0xa6,0xc0,0x17,0x0c,0x6c,0x47,
  52580. 0x2a,0x40,0x1c,0x2b,0xe0,0x98,0x3b,0xbf,0xc6,0xf8,
  52581. 0x6d,0xfd,0xd0,0xfa,0xc1,0x02,0xfb,0x5f,0xfb,0xb0,
  52582. 0xcb,0xd9,0xa3,0x59,0x94,0xe9,0x0f,0x74,0xbb,0x3f,
  52583. 0x64,0xa3,0x83,0xc4,0x2b,0xf7,0xd2,0x97,0xbf,0x3b,
  52584. 0xcf,0xbb,0x60,0x81,0x33,0x94,0xfa,0x0d,0x35,0xd2,
  52585. 0x3d,0xb9,0x99,0xe3,0x12,0xf8,0xf4,0xa3,0x74,0xf4,
  52586. 0x94,0x1d,0x7a,0x66,0xf8,0xd1,0x1d,0xcf,0xb0,0x48,
  52587. 0xef,0x8c,0x94,0x6f,0xdd,0x62,
  52588. };
  52589. #endif
  52590. WC_RNG rng;
  52591. EncryptedInfo encInfo;
  52592. int keyFormat = 0;
  52593. word32 keyIdx = 0;
  52594. byte in[] = "Everyone gets Friday off. ecc p";
  52595. word32 inLen = (word32)XSTRLEN((char*)in);
  52596. word32 outLen;
  52597. int verify;
  52598. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52599. if (key == NULL || pub == NULL) {
  52600. ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_onlycb);
  52601. }
  52602. #endif
  52603. ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
  52604. if (ret != 0)
  52605. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52606. /* wc_CryptoCb_MakeEccKey cb test, , no actual testing */
  52607. ctx->exampleVar = 99;
  52608. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52609. if (ret != 0)
  52610. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52611. ctx->exampleVar = 1;
  52612. ret = wc_ecc_make_key(&rng, ECC_KEYGEN_SIZE, key);
  52613. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52614. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52615. } else
  52616. /* reset return code */
  52617. ret = 0;
  52618. #ifdef USE_CERT_BUFFERS_256
  52619. if (ret == 0) {
  52620. /* load ECC private key and perform private transform */
  52621. ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &keyIdx,
  52622. key, sizeof_ecc_key_der_256);
  52623. }
  52624. if (ret != 0)
  52625. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52626. /* wc_CryptoCb_EccSign cb test, no actual testing */
  52627. ctx->exampleVar = 99;
  52628. if (ret == 0) {
  52629. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52630. }
  52631. if (ret != 0)
  52632. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52633. ctx->exampleVar = 1;
  52634. if (ret == 0) {
  52635. ret = wc_ecc_sign_hash(in, inLen, out, &outLen, &rng, key);
  52636. }
  52637. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52638. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52639. }
  52640. else
  52641. ret = 0;
  52642. /* wc_CryptoCb_EccVerify cb test, no actual testing */
  52643. ctx->exampleVar = 99;
  52644. if (ret == 0) {
  52645. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52646. }
  52647. if (ret != 0)
  52648. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52649. ctx->exampleVar = 1;
  52650. if (ret == 0) {
  52651. ret = wc_ecc_verify_hash(in, inLen, out, outLen, &verify, key);
  52652. }
  52653. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52654. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52655. }
  52656. else
  52657. ret = 0;
  52658. /* wc_CryptoCb_Ecdh cb test, no actual testing */
  52659. /* make public key for shared secret */
  52660. wc_ecc_init_ex(pub, HEAP_HINT, devId);
  52661. ctx->exampleVar = 99;
  52662. if (ret == 0) {
  52663. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52664. }
  52665. if (ret != 0)
  52666. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52667. ctx->exampleVar = 1;
  52668. if (ret == 0) {
  52669. ret = wc_ecc_shared_secret(key, pub, out, &outLen);
  52670. }
  52671. if (ret != WC_NO_ERR_TRACE(NO_VALID_DEVID)) {
  52672. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52673. }
  52674. else
  52675. ret = 0;
  52676. #ifdef OPENSSL_EXTRA
  52677. (void)pkey;
  52678. cp = ecc_clikey_der_256;
  52679. privKey = d2i_PrivateKey(WC_EVP_PKEY_EC, NULL, &cp,
  52680. sizeof_ecc_clikey_der_256);
  52681. if (privKey == NULL) {
  52682. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52683. }
  52684. pkey = (ecc_key*)privKey->ecc->internal;
  52685. pkey->devId = devId;
  52686. p = ecc_clikeypub_der_256;
  52687. pubKey = d2i_PUBKEY(NULL, &p, sizeof_ecc_clikeypub_der_256);
  52688. if (pubKey == NULL) {
  52689. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52690. }
  52691. pkey = (ecc_key*)pubKey->ecc->internal;
  52692. pkey->devId = devId;
  52693. /* sign */
  52694. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52695. ret = EVP_DigestSignInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, privKey);
  52696. if (ret != WOLFSSL_SUCCESS) {
  52697. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52698. }
  52699. ret = EVP_DigestSignUpdate(&mdCtx, testData,
  52700. (unsigned int)XSTRLEN(testData));
  52701. if (ret != WOLFSSL_SUCCESS) {
  52702. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52703. }
  52704. ret = EVP_DigestSignFinal(&mdCtx, NULL, &checkSz);
  52705. if (ret != WOLFSSL_SUCCESS) {
  52706. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52707. }
  52708. ctx->exampleVar = 99;
  52709. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52710. /* just called crypt callback as dummy
  52711. * EVP_DigestSignFinal returns 0 internally.
  52712. */
  52713. if (ret != 0)
  52714. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52715. ctx->exampleVar = 1;
  52716. ret = EVP_DigestSignFinal(&mdCtx, check, &checkSz);
  52717. /* just called crypt callback as dummy
  52718. * EVP_DigestSignFinal returns 0 internally.
  52719. */
  52720. if (ret != 0)
  52721. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52722. /* restore checkSz for verify */
  52723. checkSz = 71;
  52724. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52725. if (ret != WOLFSSL_SUCCESS) {
  52726. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52727. }
  52728. /* verify */
  52729. wolfSSL_EVP_MD_CTX_init(&mdCtx);
  52730. if (ret == WOLFSSL_SUCCESS) {
  52731. ret = EVP_DigestVerifyInit(&mdCtx, NULL, wolfSSL_EVP_sha256(), NULL, pubKey);
  52732. }
  52733. if (ret != WOLFSSL_SUCCESS) {
  52734. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52735. }
  52736. if (ret == WOLFSSL_SUCCESS) {
  52737. ret = EVP_DigestVerifyUpdate(&mdCtx, testData,
  52738. (unsigned int)XSTRLEN(testData));
  52739. }
  52740. if (ret != WOLFSSL_SUCCESS) {
  52741. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52742. }
  52743. ctx->exampleVar = 99;
  52744. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52745. /* just called crypt callback as dummy
  52746. * EVP_DigestSignFinal returns 0 internally.
  52747. */
  52748. if (ret != 0)
  52749. ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_onlycb);
  52750. ctx->exampleVar = 1;
  52751. ret = EVP_DigestVerifyFinal(&mdCtx, check_v, checkSz);
  52752. /* just called crypt callback as dummy
  52753. * EVP_DigestVerifyFinal returns -1 internally rather than NO_VALID_DEVID.
  52754. */
  52755. if (ret != -1) {
  52756. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52757. }
  52758. ret = wolfSSL_EVP_MD_CTX_cleanup(&mdCtx);
  52759. if (ret != WOLFSSL_SUCCESS) {
  52760. ERROR_OUT(WC_TEST_RET_ENC_NC, exit_onlycb);
  52761. } else
  52762. ret = 0;
  52763. #endif
  52764. #else
  52765. (void)verify;
  52766. (void)outLen;
  52767. (void)inLen;
  52768. (void)out;
  52769. (void)pub;
  52770. #ifdef OPENSSL_EXTRA
  52771. (void)privKey;
  52772. (void)pubKey;
  52773. (void)mdCtx;
  52774. (void)check;
  52775. (void)checkSz;
  52776. (void)p;
  52777. #endif
  52778. #endif
  52779. (void)keyFormat;
  52780. (void)encInfo;
  52781. exit_onlycb:
  52782. #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
  52783. if (key != NULL) {
  52784. wc_ecc_free(key);
  52785. XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52786. }
  52787. XFREE(pub, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52788. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52789. #ifdef OPENSSL_EXTRA
  52790. if (check) {
  52791. FREE(check, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  52792. }
  52793. #endif
  52794. #else
  52795. wc_ecc_free(key);
  52796. #ifdef OPENSSL_EXTRA
  52797. if (privKey)
  52798. wolfSSL_EVP_PKEY_free(privKey);
  52799. if (pubKey)
  52800. wolfSSL_EVP_PKEY_free(pubKey);
  52801. #endif
  52802. #endif
  52803. #endif /* HAVE_ECC */
  52804. return ret;
  52805. }
  52806. #endif
  52807. /* Example crypto dev callback function that calls software version */
  52808. static int myCryptoDevCb(int devIdArg, wc_CryptoInfo* info, void* ctx)
  52809. {
  52810. int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN); /* return this to bypass HW and
  52811. use SW */
  52812. myCryptoDevCtx* myCtx = (myCryptoDevCtx*)ctx;
  52813. if (info == NULL)
  52814. return BAD_FUNC_ARG;
  52815. #ifdef DEBUG_WOLFSSL
  52816. WOLFSSL_MSG_EX("CryptoDevCb: Algo Type %d\n", info->algo_type);
  52817. #endif
  52818. if (info->algo_type == WC_ALGO_TYPE_RNG) {
  52819. #if defined(WOLF_CRYPTO_CB) && !defined(HAVE_HASHDRBG) && \
  52820. !defined(WC_NO_RNG) && !defined(CUSTOM_RAND_GENERATE_BLOCK)
  52821. /* if RNG only supports crypto callback, just use seed */
  52822. ret = wc_GenerateSeed(&info->rng.rng->seed,
  52823. info->rng.out, info->rng.sz);
  52824. #elif !defined(WC_NO_RNG)
  52825. /* set devId to invalid, so software is used */
  52826. info->rng.rng->devId = INVALID_DEVID;
  52827. ret = wc_RNG_GenerateBlock(info->rng.rng,
  52828. info->rng.out, info->rng.sz);
  52829. /* reset devId */
  52830. info->rng.rng->devId = devIdArg;
  52831. #endif
  52832. }
  52833. else if (info->algo_type == WC_ALGO_TYPE_SEED) {
  52834. #ifndef WC_NO_RNG
  52835. ALIGN32 static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 };
  52836. word32* seedWord32 = (word32*)seed;
  52837. word32 len;
  52838. /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */
  52839. while (info->seed.sz > 0) {
  52840. len = (word32)sizeof(seed);
  52841. if (info->seed.sz < len)
  52842. len = info->seed.sz;
  52843. XMEMCPY(info->seed.seed, seed, sizeof(seed));
  52844. info->seed.seed += len;
  52845. info->seed.sz -= len;
  52846. (*seedWord32)++;
  52847. }
  52848. ret = 0;
  52849. #endif
  52850. }
  52851. else if (info->algo_type == WC_ALGO_TYPE_PK) {
  52852. #ifdef DEBUG_WOLFSSL
  52853. WOLFSSL_MSG_EX("CryptoDevCb: Pk Type %d\n", info->pk.type);
  52854. #endif
  52855. #ifndef NO_RSA
  52856. if (info->pk.type == WC_PK_TYPE_RSA) {
  52857. /* set devId to invalid, so software is used */
  52858. info->pk.rsa.key->devId = INVALID_DEVID;
  52859. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52860. #ifdef DEBUG_WOLFSSL
  52861. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52862. #endif
  52863. if (myCtx->exampleVar == 99) {
  52864. info->pk.rsa.key->devId = devIdArg;
  52865. return 0;
  52866. }
  52867. #endif
  52868. switch (info->pk.rsa.type) {
  52869. case RSA_PUBLIC_ENCRYPT:
  52870. case RSA_PUBLIC_DECRYPT:
  52871. /* perform software based RSA public op */
  52872. ret = wc_RsaFunction(
  52873. info->pk.rsa.in, info->pk.rsa.inLen,
  52874. info->pk.rsa.out, info->pk.rsa.outLen,
  52875. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52876. break;
  52877. case RSA_PRIVATE_ENCRYPT:
  52878. case RSA_PRIVATE_DECRYPT:
  52879. /* perform software based RSA private op */
  52880. ret = wc_RsaFunction(
  52881. info->pk.rsa.in, info->pk.rsa.inLen,
  52882. info->pk.rsa.out, info->pk.rsa.outLen,
  52883. info->pk.rsa.type, info->pk.rsa.key, info->pk.rsa.rng);
  52884. break;
  52885. }
  52886. /* reset devId */
  52887. info->pk.rsa.key->devId = devIdArg;
  52888. }
  52889. #ifdef WOLFSSL_KEY_GEN
  52890. else if (info->pk.type == WC_PK_TYPE_RSA_KEYGEN) {
  52891. info->pk.rsakg.key->devId = INVALID_DEVID;
  52892. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  52893. #ifdef DEBUG_WOLFSSL
  52894. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52895. #endif
  52896. if (myCtx->exampleVar == 99) {
  52897. info->pk.rsakg.key->devId = devIdArg;
  52898. return 0;
  52899. }
  52900. #endif
  52901. #ifdef HAVE_FIPS
  52902. for (;;) {
  52903. #endif
  52904. ret = wc_MakeRsaKey(info->pk.rsakg.key, info->pk.rsakg.size,
  52905. info->pk.rsakg.e, info->pk.rsakg.rng);
  52906. #ifdef HAVE_FIPS
  52907. if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E))
  52908. continue;
  52909. break;
  52910. }
  52911. #endif
  52912. /* reset devId */
  52913. info->pk.rsakg.key->devId = devIdArg;
  52914. }
  52915. #endif
  52916. #endif /* !NO_RSA */
  52917. #ifdef HAVE_ECC
  52918. if (info->pk.type == WC_PK_TYPE_EC_KEYGEN) {
  52919. /* set devId to invalid, so software is used */
  52920. info->pk.eckg.key->devId = INVALID_DEVID;
  52921. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52922. #ifdef DEBUG_WOLFSSL
  52923. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52924. #endif
  52925. if (myCtx->exampleVar == 99) {
  52926. info->pk.eckg.key->devId = devIdArg;
  52927. return 0;
  52928. }
  52929. #endif
  52930. ret = wc_ecc_make_key_ex(info->pk.eckg.rng, info->pk.eckg.size,
  52931. info->pk.eckg.key, info->pk.eckg.curveId);
  52932. /* reset devId */
  52933. info->pk.eckg.key->devId = devIdArg;
  52934. }
  52935. else if (info->pk.type == WC_PK_TYPE_ECDSA_SIGN) {
  52936. /* set devId to invalid, so software is used */
  52937. info->pk.eccsign.key->devId = INVALID_DEVID;
  52938. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52939. #ifdef DEBUG_WOLFSSL
  52940. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52941. #endif
  52942. if (myCtx->exampleVar == 99) {
  52943. info->pk.eccsign.key->devId = devIdArg;
  52944. return 0;
  52945. }
  52946. #endif
  52947. ret = wc_ecc_sign_hash(
  52948. info->pk.eccsign.in, info->pk.eccsign.inlen,
  52949. info->pk.eccsign.out, info->pk.eccsign.outlen,
  52950. info->pk.eccsign.rng, info->pk.eccsign.key);
  52951. /* reset devId */
  52952. info->pk.eccsign.key->devId = devIdArg;
  52953. }
  52954. else if (info->pk.type == WC_PK_TYPE_ECDSA_VERIFY) {
  52955. /* set devId to invalid, so software is used */
  52956. info->pk.eccverify.key->devId = INVALID_DEVID;
  52957. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52958. #ifdef DEBUG_WOLFSSL
  52959. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52960. #endif
  52961. if (myCtx->exampleVar == 99) {
  52962. info->pk.eccverify.key->devId = devIdArg;
  52963. return 0;
  52964. }
  52965. #endif
  52966. ret = wc_ecc_verify_hash(
  52967. info->pk.eccverify.sig, info->pk.eccverify.siglen,
  52968. info->pk.eccverify.hash, info->pk.eccverify.hashlen,
  52969. info->pk.eccverify.res, info->pk.eccverify.key);
  52970. /* reset devId */
  52971. info->pk.eccverify.key->devId = devIdArg;
  52972. }
  52973. else if (info->pk.type == WC_PK_TYPE_ECDH) {
  52974. /* set devId to invalid, so software is used */
  52975. info->pk.ecdh.private_key->devId = INVALID_DEVID;
  52976. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  52977. #ifdef DEBUG_WOLFSSL
  52978. printf("CryptoDevCb: exampleVar %d\n", myCtx->exampleVar);
  52979. #endif
  52980. if (myCtx->exampleVar == 99) {
  52981. info->pk.ecdh.private_key->devId = devIdArg;
  52982. return 0;
  52983. }
  52984. #endif
  52985. ret = wc_ecc_shared_secret(
  52986. info->pk.ecdh.private_key, info->pk.ecdh.public_key,
  52987. info->pk.ecdh.out, info->pk.ecdh.outlen);
  52988. /* reset devId */
  52989. info->pk.ecdh.private_key->devId = devIdArg;
  52990. }
  52991. #endif /* HAVE_ECC */
  52992. #ifdef HAVE_CURVE25519
  52993. if (info->pk.type == WC_PK_TYPE_CURVE25519_KEYGEN) {
  52994. /* set devId to invalid, so software is used */
  52995. info->pk.curve25519kg.key->devId = INVALID_DEVID;
  52996. ret = wc_curve25519_make_key(info->pk.curve25519kg.rng,
  52997. info->pk.curve25519kg.size, info->pk.curve25519kg.key);
  52998. /* reset devId */
  52999. info->pk.curve25519kg.key->devId = devIdArg;
  53000. }
  53001. else if (info->pk.type == WC_PK_TYPE_CURVE25519) {
  53002. /* set devId to invalid, so software is used */
  53003. info->pk.curve25519.private_key->devId = INVALID_DEVID;
  53004. ret = wc_curve25519_shared_secret_ex(
  53005. info->pk.curve25519.private_key, info->pk.curve25519.public_key,
  53006. info->pk.curve25519.out, info->pk.curve25519.outlen,
  53007. info->pk.curve25519.endian);
  53008. /* reset devId */
  53009. info->pk.curve25519.private_key->devId = devIdArg;
  53010. }
  53011. #endif /* HAVE_CURVE25519 */
  53012. #if defined(HAVE_ED25519) && defined(HAVE_ED25519_MAKE_KEY)
  53013. if (info->pk.type == WC_PK_TYPE_ED25519_KEYGEN) {
  53014. /* set devId to invalid, so software is used */
  53015. info->pk.ed25519kg.key->devId = INVALID_DEVID;
  53016. ret = wc_ed25519_make_key(info->pk.ed25519kg.rng,
  53017. info->pk.ed25519kg.size, info->pk.ed25519kg.key);
  53018. /* reset devId */
  53019. info->pk.ed25519kg.key->devId = devIdArg;
  53020. }
  53021. #ifdef HAVE_ED25519_SIGN
  53022. else if (info->pk.type == WC_PK_TYPE_ED25519_SIGN) {
  53023. /* set devId to invalid, so software is used */
  53024. info->pk.ed25519sign.key->devId = INVALID_DEVID;
  53025. ret = wc_ed25519_sign_msg_ex(
  53026. info->pk.ed25519sign.in, info->pk.ed25519sign.inLen,
  53027. info->pk.ed25519sign.out, info->pk.ed25519sign.outLen,
  53028. info->pk.ed25519sign.key, info->pk.ed25519sign.type,
  53029. info->pk.ed25519sign.context, info->pk.ed25519sign.contextLen);
  53030. /* reset devId */
  53031. info->pk.ed25519sign.key->devId = devIdArg;
  53032. }
  53033. #endif
  53034. #ifdef HAVE_ED25519_VERIFY
  53035. else if (info->pk.type == WC_PK_TYPE_ED25519_VERIFY) {
  53036. /* set devId to invalid, so software is used */
  53037. info->pk.ed25519verify.key->devId = INVALID_DEVID;
  53038. ret = wc_ed25519_verify_msg_ex(
  53039. info->pk.ed25519verify.sig, info->pk.ed25519verify.sigLen,
  53040. info->pk.ed25519verify.msg, info->pk.ed25519verify.msgLen,
  53041. info->pk.ed25519verify.res, info->pk.ed25519verify.key,
  53042. info->pk.ed25519verify.type, info->pk.ed25519verify.context,
  53043. info->pk.ed25519verify.contextLen);
  53044. /* reset devId */
  53045. info->pk.ed25519verify.key->devId = devIdArg;
  53046. }
  53047. #endif
  53048. #endif /* HAVE_ED25519 */
  53049. }
  53050. else if (info->algo_type == WC_ALGO_TYPE_CIPHER) {
  53051. #if !defined(NO_AES) || !defined(NO_DES3)
  53052. #ifdef HAVE_AESGCM
  53053. if (info->cipher.type == WC_CIPHER_AES_GCM) {
  53054. if (info->cipher.enc) {
  53055. /* set devId to invalid, so software is used */
  53056. info->cipher.aesgcm_enc.aes->devId = INVALID_DEVID;
  53057. ret = wc_AesGcmEncrypt(
  53058. info->cipher.aesgcm_enc.aes,
  53059. info->cipher.aesgcm_enc.out,
  53060. info->cipher.aesgcm_enc.in,
  53061. info->cipher.aesgcm_enc.sz,
  53062. info->cipher.aesgcm_enc.iv,
  53063. info->cipher.aesgcm_enc.ivSz,
  53064. info->cipher.aesgcm_enc.authTag,
  53065. info->cipher.aesgcm_enc.authTagSz,
  53066. info->cipher.aesgcm_enc.authIn,
  53067. info->cipher.aesgcm_enc.authInSz);
  53068. /* reset devId */
  53069. info->cipher.aesgcm_enc.aes->devId = devIdArg;
  53070. }
  53071. else {
  53072. /* set devId to invalid, so software is used */
  53073. info->cipher.aesgcm_dec.aes->devId = INVALID_DEVID;
  53074. ret = wc_AesGcmDecrypt(
  53075. info->cipher.aesgcm_dec.aes,
  53076. info->cipher.aesgcm_dec.out,
  53077. info->cipher.aesgcm_dec.in,
  53078. info->cipher.aesgcm_dec.sz,
  53079. info->cipher.aesgcm_dec.iv,
  53080. info->cipher.aesgcm_dec.ivSz,
  53081. info->cipher.aesgcm_dec.authTag,
  53082. info->cipher.aesgcm_dec.authTagSz,
  53083. info->cipher.aesgcm_dec.authIn,
  53084. info->cipher.aesgcm_dec.authInSz);
  53085. /* reset devId */
  53086. info->cipher.aesgcm_dec.aes->devId = devIdArg;
  53087. }
  53088. }
  53089. #endif /* HAVE_AESGCM */
  53090. #ifdef HAVE_AES_CBC
  53091. if (info->cipher.type == WC_CIPHER_AES_CBC) {
  53092. if (info->cipher.enc) {
  53093. /* set devId to invalid, so software is used */
  53094. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53095. ret = wc_AesCbcEncrypt(
  53096. info->cipher.aescbc.aes,
  53097. info->cipher.aescbc.out,
  53098. info->cipher.aescbc.in,
  53099. info->cipher.aescbc.sz);
  53100. /* reset devId */
  53101. info->cipher.aescbc.aes->devId = devIdArg;
  53102. }
  53103. else {
  53104. /* set devId to invalid, so software is used */
  53105. info->cipher.aescbc.aes->devId = INVALID_DEVID;
  53106. ret = wc_AesCbcDecrypt(
  53107. info->cipher.aescbc.aes,
  53108. info->cipher.aescbc.out,
  53109. info->cipher.aescbc.in,
  53110. info->cipher.aescbc.sz);
  53111. /* reset devId */
  53112. info->cipher.aescbc.aes->devId = devIdArg;
  53113. }
  53114. }
  53115. #endif /* HAVE_AES_CBC */
  53116. #if defined(HAVE_AES_ECB) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
  53117. if (info->cipher.type == WC_CIPHER_AES_ECB) {
  53118. if (info->cipher.enc) {
  53119. /* set devId to invalid, so software is used */
  53120. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53121. ret = wc_AesEcbEncrypt(
  53122. info->cipher.aesecb.aes,
  53123. info->cipher.aesecb.out,
  53124. info->cipher.aesecb.in,
  53125. info->cipher.aesecb.sz);
  53126. /* reset devId */
  53127. info->cipher.aesecb.aes->devId = devIdArg;
  53128. }
  53129. else {
  53130. /* set devId to invalid, so software is used */
  53131. info->cipher.aesecb.aes->devId = INVALID_DEVID;
  53132. ret = wc_AesEcbDecrypt(
  53133. info->cipher.aesecb.aes,
  53134. info->cipher.aesecb.out,
  53135. info->cipher.aesecb.in,
  53136. info->cipher.aesecb.sz);
  53137. /* reset devId */
  53138. info->cipher.aesecb.aes->devId = devIdArg;
  53139. }
  53140. }
  53141. #endif /* HAVE_AES_ECB */
  53142. #if defined(WOLFSSL_AES_COUNTER) && !defined(HAVE_FIPS) && \
  53143. !defined(HAVE_SELFTEST)
  53144. if (info->cipher.type == WC_CIPHER_AES_CTR) {
  53145. /* set devId to invalid, so software is used */
  53146. info->cipher.aesctr.aes->devId = INVALID_DEVID;
  53147. ret = wc_AesCtrEncrypt(
  53148. info->cipher.aesctr.aes,
  53149. info->cipher.aesctr.out,
  53150. info->cipher.aesctr.in,
  53151. info->cipher.aesctr.sz);
  53152. /* reset devId */
  53153. info->cipher.aesctr.aes->devId = devIdArg;
  53154. }
  53155. #endif /* WOLFSSL_AES_COUNTER */
  53156. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53157. if (info->cipher.type == WC_CIPHER_AES_CCM) {
  53158. if (info->cipher.enc) {
  53159. /* set devId to invalid, so software is used */
  53160. info->cipher.aesccm_enc.aes->devId = INVALID_DEVID;
  53161. ret = wc_AesCcmEncrypt(
  53162. info->cipher.aesccm_enc.aes,
  53163. info->cipher.aesccm_enc.out,
  53164. info->cipher.aesccm_enc.in,
  53165. info->cipher.aesccm_enc.sz,
  53166. info->cipher.aesccm_enc.nonce,
  53167. info->cipher.aesccm_enc.nonceSz,
  53168. info->cipher.aesccm_enc.authTag,
  53169. info->cipher.aesccm_enc.authTagSz,
  53170. info->cipher.aesccm_enc.authIn,
  53171. info->cipher.aesccm_enc.authInSz);
  53172. /* reset devId */
  53173. info->cipher.aesccm_enc.aes->devId = devIdArg;
  53174. }
  53175. else {
  53176. /* set devId to invalid, so software is used */
  53177. info->cipher.aesccm_dec.aes->devId = INVALID_DEVID;
  53178. ret = wc_AesCcmDecrypt(
  53179. info->cipher.aesccm_dec.aes,
  53180. info->cipher.aesccm_dec.out,
  53181. info->cipher.aesccm_dec.in,
  53182. info->cipher.aesccm_dec.sz,
  53183. info->cipher.aesccm_dec.nonce,
  53184. info->cipher.aesccm_dec.nonceSz,
  53185. info->cipher.aesccm_dec.authTag,
  53186. info->cipher.aesccm_dec.authTagSz,
  53187. info->cipher.aesccm_dec.authIn,
  53188. info->cipher.aesccm_dec.authInSz);
  53189. /* reset devId */
  53190. info->cipher.aesccm_dec.aes->devId = devIdArg;
  53191. }
  53192. }
  53193. #endif
  53194. #ifndef NO_DES3
  53195. if (info->cipher.type == WC_CIPHER_DES3) {
  53196. if (info->cipher.enc) {
  53197. /* set devId to invalid, so software is used */
  53198. info->cipher.des3.des->devId = INVALID_DEVID;
  53199. ret = wc_Des3_CbcEncrypt(
  53200. info->cipher.des3.des,
  53201. info->cipher.des3.out,
  53202. info->cipher.des3.in,
  53203. info->cipher.des3.sz);
  53204. /* reset devId */
  53205. info->cipher.des3.des->devId = devIdArg;
  53206. }
  53207. else {
  53208. /* set devId to invalid, so software is used */
  53209. info->cipher.des3.des->devId = INVALID_DEVID;
  53210. ret = wc_Des3_CbcDecrypt(
  53211. info->cipher.des3.des,
  53212. info->cipher.des3.out,
  53213. info->cipher.des3.in,
  53214. info->cipher.des3.sz);
  53215. /* reset devId */
  53216. info->cipher.des3.des->devId = devIdArg;
  53217. }
  53218. }
  53219. #endif /* !NO_DES3 */
  53220. #endif /* !NO_AES || !NO_DES3 */
  53221. }
  53222. #if !defined(NO_SHA) || !defined(NO_SHA256) || \
  53223. defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
  53224. else if (info->algo_type == WC_ALGO_TYPE_HASH) {
  53225. #if !defined(NO_SHA)
  53226. if (info->hash.type == WC_HASH_TYPE_SHA) {
  53227. if (info->hash.sha1 == NULL)
  53228. return NOT_COMPILED_IN;
  53229. /* set devId to invalid, so software is used */
  53230. info->hash.sha1->devId = INVALID_DEVID;
  53231. if (info->hash.in != NULL) {
  53232. ret = wc_ShaUpdate(
  53233. info->hash.sha1,
  53234. info->hash.in,
  53235. info->hash.inSz);
  53236. }
  53237. if (info->hash.digest != NULL) {
  53238. ret = wc_ShaFinal(
  53239. info->hash.sha1,
  53240. info->hash.digest);
  53241. }
  53242. /* reset devId */
  53243. info->hash.sha1->devId = devIdArg;
  53244. }
  53245. else
  53246. #endif
  53247. #if !defined(NO_SHA256)
  53248. if (info->hash.type == WC_HASH_TYPE_SHA256) {
  53249. if (info->hash.sha256 == NULL)
  53250. return NOT_COMPILED_IN;
  53251. /* set devId to invalid, so software is used */
  53252. info->hash.sha256->devId = INVALID_DEVID;
  53253. if (info->hash.in != NULL) {
  53254. ret = wc_Sha256Update(
  53255. info->hash.sha256,
  53256. info->hash.in,
  53257. info->hash.inSz);
  53258. }
  53259. if (info->hash.digest != NULL) {
  53260. ret = wc_Sha256Final(
  53261. info->hash.sha256,
  53262. info->hash.digest);
  53263. }
  53264. /* reset devId */
  53265. info->hash.sha256->devId = devIdArg;
  53266. }
  53267. else
  53268. #endif
  53269. #ifdef WOLFSSL_SHA384
  53270. if (info->hash.type == WC_HASH_TYPE_SHA384) {
  53271. if (info->hash.sha384 == NULL)
  53272. return NOT_COMPILED_IN;
  53273. #ifndef NO_SHA2_CRYPTO_CB
  53274. /* set devId to invalid, so software is used */
  53275. info->hash.sha384->devId = INVALID_DEVID;
  53276. #endif
  53277. if (info->hash.in != NULL) {
  53278. ret = wc_Sha384Update(
  53279. info->hash.sha384,
  53280. info->hash.in,
  53281. info->hash.inSz);
  53282. }
  53283. if (info->hash.digest != NULL) {
  53284. ret = wc_Sha384Final(
  53285. info->hash.sha384,
  53286. info->hash.digest);
  53287. }
  53288. #ifndef NO_SHA2_CRYPTO_CB
  53289. /* reset devId */
  53290. info->hash.sha384->devId = devIdArg;
  53291. #endif
  53292. }
  53293. else
  53294. #endif
  53295. #ifdef WOLFSSL_SHA512
  53296. if (info->hash.type == WC_HASH_TYPE_SHA512) {
  53297. if (info->hash.sha512 == NULL)
  53298. return NOT_COMPILED_IN;
  53299. #ifndef NO_SHA2_CRYPTO_CB
  53300. /* set devId to invalid, so software is used */
  53301. info->hash.sha512->devId = INVALID_DEVID;
  53302. #endif
  53303. if (info->hash.in != NULL) {
  53304. ret = wc_Sha512Update(
  53305. info->hash.sha512,
  53306. info->hash.in,
  53307. info->hash.inSz);
  53308. }
  53309. if (info->hash.digest != NULL) {
  53310. ret = wc_Sha512Final(
  53311. info->hash.sha512,
  53312. info->hash.digest);
  53313. }
  53314. #ifndef NO_SHA2_CRYPTO_CB
  53315. /* reset devId */
  53316. info->hash.sha512->devId = devIdArg;
  53317. #endif
  53318. }
  53319. else
  53320. #endif
  53321. #if defined(WOLFSSL_SHA3) && (!defined(HAVE_FIPS) || FIPS_VERSION_GE(6, 0))
  53322. if (info->hash.type == WC_HASH_TYPE_SHA3_224) {
  53323. if (info->hash.sha3 == NULL)
  53324. return NOT_COMPILED_IN;
  53325. /* set devId to invalid, so software is used */
  53326. info->hash.sha3->devId = INVALID_DEVID;
  53327. if (info->hash.in != NULL) {
  53328. ret = wc_Sha3_224_Update(
  53329. info->hash.sha3,
  53330. info->hash.in,
  53331. info->hash.inSz);
  53332. }
  53333. if (info->hash.digest != NULL) {
  53334. ret = wc_Sha3_224_Final(
  53335. info->hash.sha3,
  53336. info->hash.digest);
  53337. }
  53338. /* reset devId */
  53339. info->hash.sha3->devId = devIdArg;
  53340. }
  53341. else if (info->hash.type == WC_HASH_TYPE_SHA3_256) {
  53342. if (info->hash.sha3 == NULL)
  53343. return NOT_COMPILED_IN;
  53344. /* set devId to invalid, so software is used */
  53345. info->hash.sha3->devId = INVALID_DEVID;
  53346. if (info->hash.in != NULL) {
  53347. ret = wc_Sha3_256_Update(
  53348. info->hash.sha3,
  53349. info->hash.in,
  53350. info->hash.inSz);
  53351. }
  53352. if (info->hash.digest != NULL) {
  53353. ret = wc_Sha3_256_Final(
  53354. info->hash.sha3,
  53355. info->hash.digest);
  53356. }
  53357. /* reset devId */
  53358. info->hash.sha3->devId = devIdArg;
  53359. }
  53360. else if (info->hash.type == WC_HASH_TYPE_SHA3_384) {
  53361. if (info->hash.sha3 == NULL)
  53362. return NOT_COMPILED_IN;
  53363. /* set devId to invalid, so software is used */
  53364. info->hash.sha3->devId = INVALID_DEVID;
  53365. if (info->hash.in != NULL) {
  53366. ret = wc_Sha3_384_Update(
  53367. info->hash.sha3,
  53368. info->hash.in,
  53369. info->hash.inSz);
  53370. }
  53371. if (info->hash.digest != NULL) {
  53372. ret = wc_Sha3_384_Final(
  53373. info->hash.sha3,
  53374. info->hash.digest);
  53375. }
  53376. /* reset devId */
  53377. info->hash.sha3->devId = devIdArg;
  53378. }
  53379. else if (info->hash.type == WC_HASH_TYPE_SHA3_512) {
  53380. if (info->hash.sha3 == NULL)
  53381. return NOT_COMPILED_IN;
  53382. /* set devId to invalid, so software is used */
  53383. info->hash.sha3->devId = INVALID_DEVID;
  53384. if (info->hash.in != NULL) {
  53385. ret = wc_Sha3_512_Update(
  53386. info->hash.sha3,
  53387. info->hash.in,
  53388. info->hash.inSz);
  53389. }
  53390. if (info->hash.digest != NULL) {
  53391. ret = wc_Sha3_512_Final(
  53392. info->hash.sha3,
  53393. info->hash.digest);
  53394. }
  53395. /* reset devId */
  53396. info->hash.sha3->devId = devIdArg;
  53397. }
  53398. else
  53399. #endif
  53400. {
  53401. }
  53402. }
  53403. #endif /* !NO_SHA || !NO_SHA256 */
  53404. #ifndef NO_HMAC
  53405. else if (info->algo_type == WC_ALGO_TYPE_HMAC) {
  53406. if (info->hmac.hmac == NULL)
  53407. return NOT_COMPILED_IN;
  53408. /* set devId to invalid, so software is used */
  53409. info->hmac.hmac->devId = INVALID_DEVID;
  53410. if (info->hmac.in != NULL) {
  53411. ret = wc_HmacUpdate(
  53412. info->hmac.hmac,
  53413. info->hmac.in,
  53414. info->hmac.inSz);
  53415. }
  53416. else if (info->hmac.digest != NULL) {
  53417. ret = wc_HmacFinal(
  53418. info->hmac.hmac,
  53419. info->hmac.digest);
  53420. }
  53421. /* reset devId */
  53422. info->hmac.hmac->devId = devIdArg;
  53423. }
  53424. #endif
  53425. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53426. else if (info->algo_type == WC_ALGO_TYPE_CMAC) {
  53427. if (info->cmac.cmac == NULL) {
  53428. return NOT_COMPILED_IN;
  53429. }
  53430. /* set devId to invalid so software is used */
  53431. info->cmac.cmac->devId = INVALID_DEVID;
  53432. /* Handle one-shot cases */
  53433. if (info->cmac.key != NULL && info->cmac.in != NULL
  53434. && info->cmac.out != NULL) {
  53435. ret = wc_AesCmacGenerate(info->cmac.out,
  53436. info->cmac.outSz,
  53437. info->cmac.in,
  53438. info->cmac.inSz,
  53439. info->cmac.key,
  53440. info->cmac.keySz);
  53441. /* Sequentially handle incremental cases */
  53442. } else {
  53443. if (info->cmac.key != NULL) {
  53444. ret = wc_InitCmac(info->cmac.cmac,
  53445. info->cmac.key,
  53446. info->cmac.keySz,
  53447. info->cmac.type,
  53448. NULL);
  53449. }
  53450. if ((ret == 0) && (info->cmac.in != NULL)) {
  53451. ret = wc_CmacUpdate(info->cmac.cmac,
  53452. info->cmac.in,
  53453. info->cmac.inSz);
  53454. }
  53455. if ((ret ==0) && (info->cmac.out != NULL)) {
  53456. ret = wc_CmacFinal(info->cmac.cmac,
  53457. info->cmac.out,
  53458. info->cmac.outSz);
  53459. }
  53460. }
  53461. /* reset devId */
  53462. info->cmac.cmac->devId = devIdArg;
  53463. }
  53464. #endif /* WOLFSSL_CMAC && !(NO_AES) && WOLFSSL_AES_DIRECT */
  53465. (void)devIdArg;
  53466. (void)myCtx;
  53467. return ret;
  53468. }
  53469. #ifdef WOLF_CRYPTO_CB_FIND
  53470. static int myCryptoCbFind(int currentId, int algoType)
  53471. {
  53472. /* can have algo specific overrides here
  53473. switch (algoType) {
  53474. i.e.
  53475. WC_ALGO_TYPE_CMAC
  53476. WC_ALGO_TYPE_SEED
  53477. WC_ALGO_TYPE_HMAC
  53478. WC_ALGO_TYPE_HASH
  53479. WC_ALGO_TYPE_CIPHER
  53480. WC_ALGO_TYPE_PK
  53481. }
  53482. */
  53483. (void)algoType;
  53484. if (currentId == INVALID_DEVID) {
  53485. /* can override invalid devid found with 1 */
  53486. }
  53487. return currentId;
  53488. }
  53489. #endif /* WOLF_CRYPTO_CB_FIND */
  53490. #if !defined(WC_TEST_NO_CRYPTOCB_SW_TEST)
  53491. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t cryptocb_test(void)
  53492. {
  53493. wc_test_ret_t ret = 0;
  53494. int origDevId = devId;
  53495. myCryptoDevCtx myCtx;
  53496. WOLFSSL_ENTER("cryptocb_test");
  53497. /* example data for callback */
  53498. myCtx.exampleVar = 1;
  53499. /* set devId to something other than INVALID_DEVID */
  53500. devId = 1;
  53501. ret = wc_CryptoCb_RegisterDevice(devId, myCryptoDevCb, &myCtx);
  53502. #ifdef WOLF_CRYPTO_CB_FIND
  53503. wc_CryptoCb_SetDeviceFindCb(myCryptoCbFind);
  53504. #endif /* WOLF_CRYPTO_CB_FIND */
  53505. #ifndef WC_NO_RNG
  53506. if (ret == 0)
  53507. ret = random_test();
  53508. #endif /* WC_NO_RNG */
  53509. #if !defined(NO_RSA)
  53510. PRIVATE_KEY_UNLOCK();
  53511. if (ret == 0)
  53512. ret = rsa_test();
  53513. PRIVATE_KEY_LOCK();
  53514. #endif
  53515. #if defined(WOLF_CRYPTO_CB_ONLY_RSA)
  53516. PRIVATE_KEY_UNLOCK();
  53517. if (ret == 0)
  53518. ret = rsa_onlycb_test(&myCtx);
  53519. PRIVATE_KEY_LOCK();
  53520. #endif
  53521. #if defined(HAVE_ECC)
  53522. PRIVATE_KEY_UNLOCK();
  53523. if (ret == 0)
  53524. ret = ecc_test();
  53525. PRIVATE_KEY_LOCK();
  53526. #endif
  53527. #if defined(WOLF_CRYPTO_CB_ONLY_ECC)
  53528. PRIVATE_KEY_UNLOCK();
  53529. if (ret == 0)
  53530. ret = ecc_onlycb_test(&myCtx);
  53531. PRIVATE_KEY_LOCK();
  53532. #endif
  53533. #ifdef HAVE_ED25519
  53534. PRIVATE_KEY_UNLOCK();
  53535. if (ret == 0)
  53536. ret = ed25519_test();
  53537. PRIVATE_KEY_LOCK();
  53538. #endif
  53539. #ifdef HAVE_CURVE25519
  53540. if (ret == 0)
  53541. ret = curve25519_test();
  53542. #endif
  53543. #ifndef NO_AES
  53544. #ifdef HAVE_AESGCM
  53545. if (ret == 0)
  53546. ret = aesgcm_test();
  53547. #endif
  53548. #ifdef HAVE_AES_CBC
  53549. if (ret == 0)
  53550. ret = aes_test();
  53551. #endif
  53552. #ifdef WOLFSSL_AES_XTS
  53553. if (ret == 0)
  53554. ret = aes_xts_test();
  53555. #endif
  53556. #if defined(HAVE_AESCCM) && defined(WOLFSSL_AES_128)
  53557. if (ret == 0)
  53558. ret = aesccm_test();
  53559. #endif
  53560. #endif /* !NO_AES */
  53561. #ifndef NO_DES3
  53562. if (ret == 0)
  53563. ret = des3_test();
  53564. #endif /* !NO_DES3 */
  53565. #ifndef NO_SHA
  53566. if (ret == 0)
  53567. ret = sha_test();
  53568. #endif
  53569. #ifndef NO_SHA256
  53570. if (ret == 0)
  53571. ret = sha256_test();
  53572. #endif
  53573. #ifdef WOLFSSL_SHA384
  53574. if (ret == 0)
  53575. ret = sha384_test();
  53576. #endif
  53577. #ifdef WOLFSSL_SHA512
  53578. if (ret == 0)
  53579. ret = sha512_test();
  53580. #ifdef WOLFSSL_SHA3
  53581. if (ret == 0)
  53582. ret = sha3_test();
  53583. #endif
  53584. #endif
  53585. #ifndef NO_HMAC
  53586. #ifndef NO_SHA
  53587. if (ret == 0)
  53588. ret = hmac_sha_test();
  53589. #endif
  53590. #ifndef NO_SHA256
  53591. if (ret == 0)
  53592. ret = hmac_sha256_test();
  53593. #endif
  53594. #ifdef WOLFSSL_SHA3
  53595. if (ret == 0)
  53596. ret = hmac_sha3_test();
  53597. #endif
  53598. #endif
  53599. #ifndef NO_PWDBASED
  53600. #if defined(HAVE_PBKDF2) && !defined(NO_SHA256) && !defined(NO_HMAC)
  53601. PRIVATE_KEY_UNLOCK();
  53602. if (ret == 0)
  53603. ret = pbkdf2_test();
  53604. PRIVATE_KEY_LOCK();
  53605. #endif
  53606. #endif
  53607. #if defined(WOLFSSL_CMAC) && !defined(NO_AES)
  53608. if (ret == 0)
  53609. ret = cmac_test();
  53610. #endif
  53611. /* restore devId */
  53612. devId = origDevId;
  53613. return ret;
  53614. }
  53615. #endif /* ! WC_TEST_NO_CRYPTOCB_SW_TEST */
  53616. #endif /* WOLF_CRYPTO_CB */
  53617. #ifdef WOLFSSL_CERT_PIV
  53618. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t certpiv_test(void)
  53619. {
  53620. wc_test_ret_t ret;
  53621. wc_CertPIV piv;
  53622. /* Template for Identiv PIV cert, nonce and signature */
  53623. WOLFSSL_SMALL_STACK_STATIC const byte pivCertIdentiv[] = {
  53624. 0x0A, 0x0B,
  53625. 0x53, 0x09, /* NIST PIV Cert */
  53626. 0x70, 0x02, /* Certificate */
  53627. 0x30, 0x00,
  53628. 0x71, 0x01, 0x05, /* Cert Info */
  53629. 0xFE, 0x00, /* Error Detection */
  53630. 0x0B, 0x01, 0x00, /* Nonce */
  53631. 0x0C, 0x01, 0x00, /* Signed Nonce */
  53632. };
  53633. /* PIV certificate data including certificate, info and error detection. */
  53634. WOLFSSL_SMALL_STACK_STATIC const byte pivCert[] = {
  53635. 0x53, 0x09, /* NIST PIV Cert */
  53636. 0x70, 0x02, /* Certificate */
  53637. 0x30, 0x00,
  53638. 0x71, 0x01, 0x04, /* Cert Info */
  53639. 0xFE, 0x00, /* Error Detection */
  53640. };
  53641. WOLFSSL_ENTER("certpiv_test");
  53642. XMEMSET(&piv, 0, sizeof(piv));
  53643. /* Test with Identiv 0x0A, 0x0B and 0x0C markers */
  53644. ret = wc_ParseCertPIV(&piv, pivCertIdentiv, sizeof(pivCertIdentiv));
  53645. if (ret != 0) {
  53646. return WC_TEST_RET_ENC_EC(ret);
  53647. }
  53648. if (!piv.isIdentiv) {
  53649. return WC_TEST_RET_ENC_NC;
  53650. }
  53651. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53652. return WC_TEST_RET_ENC_NC;
  53653. }
  53654. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53655. return WC_TEST_RET_ENC_NC;
  53656. }
  53657. if ((piv.compression != ASN_PIV_CERT_INFO_GZIP)) {
  53658. return WC_TEST_RET_ENC_NC;
  53659. }
  53660. if (!piv.isX509) {
  53661. return WC_TEST_RET_ENC_NC;
  53662. }
  53663. if ((piv.nonce == NULL) || (piv.nonceSz != 1)) {
  53664. return WC_TEST_RET_ENC_NC;
  53665. }
  53666. if ((piv.signedNonce == NULL) || (piv.signedNonceSz != 1)) {
  53667. return WC_TEST_RET_ENC_NC;
  53668. }
  53669. XMEMSET(&piv, 0, sizeof(piv));
  53670. /* Test with NIST PIV format */
  53671. ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
  53672. if (ret != 0) {
  53673. return WC_TEST_RET_ENC_EC(ret);
  53674. }
  53675. if (piv.isIdentiv) {
  53676. return WC_TEST_RET_ENC_NC;
  53677. }
  53678. if ((piv.cert == NULL) || (piv.certSz != 2)) {
  53679. return WC_TEST_RET_ENC_NC;
  53680. }
  53681. if ((piv.certErrDet == NULL) || (piv.certErrDetSz != 0)) {
  53682. return WC_TEST_RET_ENC_NC;
  53683. }
  53684. if ((piv.compression != 0)) {
  53685. return WC_TEST_RET_ENC_NC;
  53686. }
  53687. if (!piv.isX509) {
  53688. return WC_TEST_RET_ENC_NC;
  53689. }
  53690. return ret;
  53691. }
  53692. #endif /* WOLFSSL_CERT_PIV */
  53693. #if !defined(NO_ASN) && !defined(NO_ASN_TIME)
  53694. static time_t time_cb(time_t* t)
  53695. {
  53696. if (t != NULL) {
  53697. *t = 99;
  53698. }
  53699. return 99;
  53700. }
  53701. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t time_test(void)
  53702. {
  53703. time_t t;
  53704. wc_test_ret_t ret;
  53705. WOLFSSL_ENTER("time_test");
  53706. ret = wc_SetTimeCb(time_cb);
  53707. if (ret != 0)
  53708. return WC_TEST_RET_ENC_EC(ret);
  53709. t = wc_Time(NULL);
  53710. if (t != 99)
  53711. return WC_TEST_RET_ENC_NC;
  53712. ret = wc_GetTime(&t, sizeof(time_t));
  53713. if (ret != 0)
  53714. return WC_TEST_RET_ENC_EC(ret);
  53715. if (t != 99)
  53716. return WC_TEST_RET_ENC_NC;
  53717. ret = wc_SetTimeCb(NULL);
  53718. if (ret != 0)
  53719. return WC_TEST_RET_ENC_EC(ret);
  53720. return 0;
  53721. }
  53722. #endif
  53723. #ifdef WOLFSSL_AES_SIV
  53724. typedef struct {
  53725. const byte key[33];
  53726. word32 keySz;
  53727. const byte nonce[49];
  53728. word32 nonceSz;
  53729. byte numAssoc;
  53730. const byte assoc1[81];
  53731. word32 assoc1Sz;
  53732. const byte assoc2[11];
  53733. word32 assoc2Sz;
  53734. const byte plaintext[83];
  53735. word32 plaintextSz;
  53736. const byte siv[AES_BLOCK_SIZE+1];
  53737. const byte ciphertext[82];
  53738. word32 ciphertextSz;
  53739. } AesSivTestVector;
  53740. #define AES_SIV_TEST_VECTORS 9
  53741. WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes_siv_test(void)
  53742. {
  53743. WOLFSSL_SMALL_STACK_STATIC const AesSivTestVector testVectors[AES_SIV_TEST_VECTORS] = {
  53744. /* These test vectors come from chrony 4.1's SIV unit tests. */
  53745. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53746. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53747. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53748. 1,
  53749. "", 0,
  53750. "", 0,
  53751. "", 0,
  53752. "\x22\x3e\xb5\x94\xe0\xe0\x25\x4b\x00\x25\x8e\x21\x9a\x1c\xa4\x21",
  53753. "", 0
  53754. },
  53755. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53756. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53757. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53758. 1,
  53759. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53760. "", 0,
  53761. "", 0,
  53762. "\xd7\x20\x19\x89\xc6\xdb\xc6\xd6\x61\xfc\x62\xbc\x86\x5e\xee\xef",
  53763. "", 0
  53764. },
  53765. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53766. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53767. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53768. 1,
  53769. "", 0,
  53770. "", 0,
  53771. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53772. "\xb6\xc1\x60\xe9\xc2\xfd\x2a\xe8\xde\xc5\x36\x8b\x2a\x33\xed\xe1",
  53773. "\x14\xff\xb3\x97\x34\x5c\xcb\xe4\x4a\xa4\xde\xac\xd9\x36\x90\x46", 16
  53774. },
  53775. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53776. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53777. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e", 15,
  53778. 1,
  53779. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c", 15,
  53780. "", 0,
  53781. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4", 15,
  53782. "\x03\x8c\x41\x51\xba\x7a\x8f\x77\x6e\x56\x31\x99\x42\x0b\xc7\x03",
  53783. "\xe7\x6c\x67\xc9\xda\xb7\x0d\x5b\x44\x06\x26\x5a\xd0\xd2\x3b", 15
  53784. },
  53785. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53786. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53787. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 16,
  53788. 1,
  53789. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b", 16,
  53790. "", 0,
  53791. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7", 16,
  53792. "\x5c\x05\x23\x65\xf4\x57\x0a\xa0\xfb\x38\x3e\xce\x9b\x75\x85\xeb",
  53793. "\x68\x85\x19\x36\x0c\x7c\x48\x11\x40\xcb\x9b\x57\x9a\x0e\x65\x32", 16
  53794. },
  53795. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53796. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53797. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53798. "\xd5", 17,
  53799. 1,
  53800. "\x4c\x9d\x4f\xca\xed\x8a\xe2\xba\xad\x3f\x3e\xa6\xe9\x3c\x8c\x8b"
  53801. "\xa0", 17,
  53802. "", 0,
  53803. "\xba\x99\x79\x31\x23\x7e\x3c\x53\x58\x7e\xd4\x93\x02\xab\xe4\xa7"
  53804. "\x08", 17,
  53805. "\xaf\x58\x4b\xe7\x82\x1e\x96\x19\x29\x91\x25\xe0\xdd\x80\x3b\x49",
  53806. "\xa5\x11\xcd\xb6\x08\xf3\x76\xa0\xb6\xfa\x15\x82\xf3\x95\xe1\xeb"
  53807. "\xbd", 17
  53808. },
  53809. { "\x01\x23\x45\x67\x89\xab\xcd\xef\xf0\x12\x34\x56\x78\x9a\xbc\xde"
  53810. "\xef\x01\x23\x45\x67\x89\xab\xcd\xde\xf0\x12\x34\x56\x78\x9a\xbc", 32,
  53811. "\xb0\x5a\x1b\xc7\x56\xe7\xb6\x2c\xb4\x85\xe5\x56\xa5\x28\xc0\x6c"
  53812. "\x2f\x3b\x0b\x9d\x1a\x0c\xdf\x69\x47\xe0\xcc\xc0\x87\xaa\x5c\x09"
  53813. "\x98\x48\x8d\x6a\x8e\x1e\x05\xd7\x8b\x68\x74\x83\xb5\x1d\xf1\x2c", 48,
  53814. 1,
  53815. "\xe5\x8b\xd2\x6a\x30\xc5\xc5\x61\xcc\xbd\x7c\x27\xbf\xfe\xf9\x06"
  53816. "\x00\x5b\xd7\xfc\x11\x0b\xcf\x16\x61\xef\xac\x05\xa7\xaf\xec\x27"
  53817. "\x41\xc8\x5e\x9e\x0d\xf9\x2f\xaf\x20\x79\x17\xe5\x17\x91\x2a\x27"
  53818. "\x34\x1c\xbc\xaf\xeb\xef\x7f\x52\xe7\x1e\x4c\x2a\xca\xbd\x2b\xbe"
  53819. "\x34\xd6\xfb\x69\xd3\x3e\x49\x59\x60\xb4\x26\xc9\xb8\xce\xba", 79,
  53820. "", 0,
  53821. "\x6c\xe7\xcf\x7e\xab\x7b\xa0\xe1\xa7\x22\xcb\x88\xde\x5e\x42\xd2"
  53822. "\xec\x79\xe0\xa2\xcf\x5f\x0f\x6f\x6b\x89\x57\xcd\xae\x17\xd4\xc2"
  53823. "\xf3\x1b\xa2\xa8\x13\x78\x23\x2f\x83\xa8\xd4\x0c\xc0\xd2\xf3\x99"
  53824. "\xae\x81\xa1\xca\x5b\x5f\x45\xa6\x6f\x0c\x8a\xf3\xd4\x67\x40\x81"
  53825. "\x26\xe2\x01\x86\xe8\x5a\xd5\xf8\x58\x80\x9f\x56\xaa\x76\x96\xbf"
  53826. "\x31", 81,
  53827. "\x9a\x06\x33\xe0\xee\x00\x6a\x9b\xc8\x20\xd5\xe2\xc2\xed\xb5\x75",
  53828. "\xfa\x9e\x42\x2a\x31\x6b\xda\xca\xaa\x7d\x31\x8b\x84\x7a\xb8\xd7"
  53829. "\x8a\x81\x25\x64\xed\x41\x9b\xa9\x77\x10\xbd\x05\x0c\x4e\xc5\x31"
  53830. "\x0c\xa2\x86\xec\x8a\x94\xc8\x24\x23\x3c\x13\xee\xa5\x51\xc9\xdf"
  53831. "\x48\xc9\x55\xc5\x2f\x40\x73\x3f\x98\xbb\x8d\x69\x78\x46\x64\x17"
  53832. "\x8d\x49\x2f\x14\x62\xa4\x7c\x2a\x57\x38\x87\xce\xc6\x72\xd3\x5c"
  53833. "\xa1", 81
  53834. },
  53835. /* Example A.1 from RFC5297 */
  53836. {
  53837. "\xff\xfe\xfd\xfc\xfb\xfa\xf9\xf8\xf7\xf6\xf5\xf4\xf3\xf2\xf1\xf0"
  53838. "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", 32,
  53839. "", 0,
  53840. 1,
  53841. "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
  53842. "\x20\x21\x22\x23\x24\x25\x26\x27", 24,
  53843. "", 0,
  53844. "\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee", 14,
  53845. "\x85\x63\x2d\x07\xc6\xe8\xf3\x7f\x95\x0a\xcd\x32\x0a\x2e\xcc\x93",
  53846. "\x40\xc0\x2b\x96\x90\xc4\xdc\x04\xda\xef\x7f\x6a\xfe\x5c", 14
  53847. },
  53848. /* Example A.2 from RFC5297 */
  53849. {
  53850. "\x7f\x7e\x7d\x7c\x7b\x7a\x79\x78\x77\x76\x75\x74\x73\x72\x71\x70"
  53851. "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f", 32,
  53852. "\x09\xf9\x11\x02\x9d\x74\xe3\x5b\xd8\x41\x56\xc5\x63\x56\x88\xc0", 16,
  53853. 2,
  53854. "\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"
  53855. "\xde\xad\xda\xda\xde\xad\xda\xda\xff\xee\xdd\xcc\xbb\xaa\x99\x88"
  53856. "\x77\x66\x55\x44\x33\x22\x11\x00", 40,
  53857. "\x10\x20\x30\x40\x50\x60\x70\x80\x90\xa0", 10,
  53858. "\x74\x68\x69\x73\x20\x69\x73\x20\x73\x6f\x6d\x65\x20\x70\x6c\x61"
  53859. "\x69\x6e\x74\x65\x78\x74\x20\x74\x6f\x20\x65\x6e\x63\x72\x79\x70"
  53860. "\x74\x20\x75\x73\x69\x6e\x67\x20\x53\x49\x56\x2d\x41\x45\x53", 47,
  53861. "\x7b\xdb\x6e\x3b\x43\x26\x67\xeb\x06\xf4\xd1\x4b\xff\x2f\xbd\x0f",
  53862. "\xcb\x90\x0f\x2f\xdd\xbe\x40\x43\x26\x60\x19\x65\xc8\x89\xbf\x17"
  53863. "\xdb\xa7\x7c\xeb\x09\x4f\xa6\x63\xb7\xa3\xf7\x48\xba\x8a\xf8\x29"
  53864. "\xea\x64\xad\x54\x4a\x27\x2e\x9c\x48\x5b\x62\xa3\xfd\x5c\x0d", 47
  53865. }
  53866. };
  53867. int i;
  53868. byte computedCiphertext[82];
  53869. byte computedPlaintext[82];
  53870. byte siv[AES_BLOCK_SIZE];
  53871. wc_test_ret_t ret = 0;
  53872. WOLFSSL_ENTER("aes_siv_test");
  53873. /* First test legacy "exactly one Assoc" interface. */
  53874. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53875. if (testVectors[i].numAssoc != 1)
  53876. continue;
  53877. ret = wc_AesSivEncrypt(testVectors[i].key, testVectors[i].keySz,
  53878. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53879. testVectors[i].nonce, testVectors[i].nonceSz,
  53880. testVectors[i].plaintext,
  53881. testVectors[i].plaintextSz, siv,
  53882. computedCiphertext);
  53883. if (ret != 0) {
  53884. return WC_TEST_RET_ENC_EC(ret);
  53885. }
  53886. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53887. if (ret != 0) {
  53888. return WC_TEST_RET_ENC_NC;
  53889. }
  53890. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53891. testVectors[i].ciphertextSz);
  53892. if (ret != 0) {
  53893. return WC_TEST_RET_ENC_NC;
  53894. }
  53895. ret = wc_AesSivDecrypt(testVectors[i].key, testVectors[i].keySz,
  53896. testVectors[i].assoc1, testVectors[i].assoc1Sz,
  53897. testVectors[i].nonce, testVectors[i].nonceSz,
  53898. computedCiphertext, testVectors[i].plaintextSz,
  53899. siv, computedPlaintext);
  53900. if (ret != 0) {
  53901. return WC_TEST_RET_ENC_EC(ret);
  53902. }
  53903. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53904. testVectors[i].plaintextSz);
  53905. if (ret != 0) {
  53906. return WC_TEST_RET_ENC_NC;
  53907. }
  53908. }
  53909. /* Then test "multiple Assoc" interface. */
  53910. for (i = 0; i < AES_SIV_TEST_VECTORS; ++i) {
  53911. const struct AesSivAssoc assoc[2] = {
  53912. { testVectors[i].assoc1, testVectors[i].assoc1Sz },
  53913. { testVectors[i].assoc2, testVectors[i].assoc2Sz }
  53914. };
  53915. ret = wc_AesSivEncrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53916. assoc, testVectors[i].numAssoc,
  53917. testVectors[i].nonce, testVectors[i].nonceSz,
  53918. testVectors[i].plaintext,
  53919. testVectors[i].plaintextSz, siv,
  53920. computedCiphertext);
  53921. if (ret != 0) {
  53922. return WC_TEST_RET_ENC_EC(ret);
  53923. }
  53924. ret = XMEMCMP(siv, testVectors[i].siv, AES_BLOCK_SIZE);
  53925. if (ret != 0) {
  53926. return WC_TEST_RET_ENC_NC;
  53927. }
  53928. ret = XMEMCMP(computedCiphertext, testVectors[i].ciphertext,
  53929. testVectors[i].ciphertextSz);
  53930. if (ret != 0) {
  53931. return WC_TEST_RET_ENC_NC;
  53932. }
  53933. ret = wc_AesSivDecrypt_ex(testVectors[i].key, testVectors[i].keySz,
  53934. assoc, testVectors[i].numAssoc,
  53935. testVectors[i].nonce, testVectors[i].nonceSz,
  53936. computedCiphertext,
  53937. testVectors[i].plaintextSz, siv,
  53938. computedPlaintext);
  53939. if (ret != 0) {
  53940. return WC_TEST_RET_ENC_EC(ret);
  53941. }
  53942. ret = XMEMCMP(computedPlaintext, testVectors[i].plaintext,
  53943. testVectors[i].plaintextSz);
  53944. if (ret != 0) {
  53945. return WC_TEST_RET_ENC_NC;
  53946. }
  53947. }
  53948. return 0;
  53949. }
  53950. #endif
  53951. #undef ERROR_OUT
  53952. static const int fiducial4 = WC_TEST_RET_LN;
  53953. /* print the fiducial line numbers assigned above, allowing confirmation of
  53954. * source code version match when in doubt.
  53955. */
  53956. static void print_fiducials(void) {
  53957. printf(" [fiducial line numbers: %d %d %d %d]\n",
  53958. fiducial1, fiducial2, fiducial3, fiducial4);
  53959. }
  53960. #else
  53961. #ifndef NO_MAIN_DRIVER
  53962. int main(void) { return 0; }
  53963. #endif
  53964. #endif /* NO_CRYPT_TEST */