benchmark.c 507 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971
  1. /* benchmark.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. /* wolfCrypt benchmark */
  22. /* Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. * make the binary always use CSV format:
  26. * WOLFSSL_BENCHMARK_FIXED_CSV
  27. *
  28. * choose to use the same units, regardless of scale. pick 1:
  29. * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
  30. * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
  31. * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  32. * WOLFSSL_BENCHMARK_FIXED_UNITS_B
  33. *
  34. * when the output should be in machine-parseable format:
  35. * GENERATE_MACHINE_PARSEABLE_REPORT
  36. *
  37. * use microseconds as the unit of time:
  38. * BENCH_MICROSECOND
  39. *
  40. * display mean, max, min and sd of operation durations:
  41. * MULTI_VALUE_STATISTICS
  42. *
  43. * Enable tracking of the stats into an allocated linked list:
  44. * (use -print to display results):
  45. * WC_BENCH_TRACK_STATS
  46. *
  47. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  48. * WC_USE_DEVID=0x1234
  49. *
  50. * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  51. * DEBUG_WOLFSSL_BENCHMARK_TIMING
  52. *
  53. * Turn on timer debugging (used when CPU cycles not available)
  54. * WOLFSSL_BENCHMARK_TIMER_DEBUG
  55. */
  56. #ifdef HAVE_CONFIG_H
  57. #include <config.h>
  58. #endif
  59. #ifndef WOLFSSL_USER_SETTINGS
  60. #include <wolfssl/options.h>
  61. #endif
  62. #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
  63. /* Macro to disable benchmark */
  64. #ifndef NO_CRYPT_BENCHMARK
  65. #define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
  66. #include <wolfssl/wolfcrypt/types.h>
  67. #include <wolfssl/wolfcrypt/wc_port.h>
  68. #include <wolfssl/wolfcrypt/wolfmath.h>
  69. #include <wolfssl/wolfcrypt/memory.h>
  70. #include <wolfssl/wolfcrypt/random.h>
  71. #include <wolfssl/wolfcrypt/error-crypt.h>
  72. #include <wolfssl/wolfcrypt/asn.h>
  73. #include <wolfssl/version.h>
  74. #ifdef WOLFSSL_LINUXKM
  75. /* remap current_time() -- collides with a function in kernel linux/fs.h */
  76. #define current_time benchmark_current_time
  77. #endif /* WOLFSSL_LINUXKM */
  78. #ifdef HAVE_CHACHA
  79. #include <wolfssl/wolfcrypt/chacha.h>
  80. #endif
  81. #ifdef HAVE_POLY1305
  82. #include <wolfssl/wolfcrypt/poly1305.h>
  83. #endif
  84. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  86. #endif
  87. #ifndef NO_AES
  88. #include <wolfssl/wolfcrypt/aes.h>
  89. #endif
  90. #ifdef HAVE_CAMELLIA
  91. #include <wolfssl/wolfcrypt/camellia.h>
  92. #endif
  93. #ifdef WOLFSSL_SM4
  94. #include <wolfssl/wolfcrypt/sm4.h>
  95. #endif
  96. #ifndef NO_MD5
  97. #include <wolfssl/wolfcrypt/md5.h>
  98. #endif
  99. #ifndef NO_SHA
  100. #include <wolfssl/wolfcrypt/sha.h>
  101. #endif
  102. #ifndef NO_SHA256
  103. #include <wolfssl/wolfcrypt/sha256.h>
  104. #endif
  105. #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
  106. #include <wolfssl/wolfcrypt/sha512.h>
  107. #endif
  108. #ifdef WOLFSSL_SHA3
  109. #include <wolfssl/wolfcrypt/sha3.h>
  110. #endif
  111. #ifdef WOLFSSL_SM3
  112. #include <wolfssl/wolfcrypt/sm3.h>
  113. #endif
  114. #ifndef NO_RSA
  115. #include <wolfssl/wolfcrypt/rsa.h>
  116. #endif
  117. #ifdef WOLFSSL_RIPEMD
  118. #include <wolfssl/wolfcrypt/ripemd.h>
  119. #endif
  120. #ifdef WOLFSSL_CMAC
  121. #include <wolfssl/wolfcrypt/cmac.h>
  122. #endif
  123. #ifndef NO_DH
  124. #include <wolfssl/wolfcrypt/dh.h>
  125. #endif
  126. #ifndef NO_DES3
  127. #include <wolfssl/wolfcrypt/des3.h>
  128. #endif
  129. #ifndef NO_RC4
  130. #include <wolfssl/wolfcrypt/arc4.h>
  131. #endif
  132. #ifndef NO_HMAC
  133. #include <wolfssl/wolfcrypt/hmac.h>
  134. #endif
  135. #ifdef WOLFSSL_SIPHASH
  136. #include <wolfssl/wolfcrypt/siphash.h>
  137. #endif
  138. #include <wolfssl/wolfcrypt/kdf.h>
  139. #ifndef NO_PWDBASED
  140. #include <wolfssl/wolfcrypt/pwdbased.h>
  141. #endif
  142. #ifdef HAVE_ECC
  143. #include <wolfssl/wolfcrypt/ecc.h>
  144. #endif
  145. #ifdef WOLFSSL_SM2
  146. #include <wolfssl/wolfcrypt/sm2.h>
  147. #endif
  148. #ifdef HAVE_CURVE25519
  149. #include <wolfssl/wolfcrypt/curve25519.h>
  150. #endif
  151. #ifdef HAVE_ED25519
  152. #include <wolfssl/wolfcrypt/ed25519.h>
  153. #endif
  154. #ifdef HAVE_CURVE448
  155. #include <wolfssl/wolfcrypt/curve448.h>
  156. #endif
  157. #ifdef HAVE_ED448
  158. #include <wolfssl/wolfcrypt/ed448.h>
  159. #endif
  160. #ifdef WOLFSSL_HAVE_KYBER
  161. #include <wolfssl/wolfcrypt/kyber.h>
  162. #ifdef WOLFSSL_WC_KYBER
  163. #include <wolfssl/wolfcrypt/wc_kyber.h>
  164. #endif
  165. #if defined(HAVE_LIBOQS)
  166. #include <wolfssl/wolfcrypt/ext_kyber.h>
  167. #endif
  168. #endif
  169. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  170. #include <wolfssl/wolfcrypt/lms.h>
  171. #ifdef HAVE_LIBLMS
  172. #include <wolfssl/wolfcrypt/ext_lms.h>
  173. #else
  174. #include <wolfssl/wolfcrypt/wc_lms.h>
  175. #endif
  176. #endif
  177. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  178. #include <wolfssl/wolfcrypt/xmss.h>
  179. #ifdef HAVE_LIBXMSS
  180. #include <wolfssl/wolfcrypt/ext_xmss.h>
  181. #else
  182. #include <wolfssl/wolfcrypt/wc_xmss.h>
  183. #endif
  184. #endif
  185. #ifdef WOLFCRYPT_HAVE_ECCSI
  186. #include <wolfssl/wolfcrypt/eccsi.h>
  187. #endif
  188. #ifdef WOLFCRYPT_HAVE_SAKKE
  189. #include <wolfssl/wolfcrypt/sakke.h>
  190. #endif
  191. #if defined(HAVE_FALCON)
  192. #include <wolfssl/wolfcrypt/falcon.h>
  193. #endif
  194. #if defined(HAVE_DILITHIUM)
  195. #include <wolfssl/wolfcrypt/dilithium.h>
  196. #endif
  197. #if defined(HAVE_SPHINCS)
  198. #include <wolfssl/wolfcrypt/sphincs.h>
  199. #endif
  200. #ifdef WOLF_CRYPTO_CB
  201. #include <wolfssl/wolfcrypt/cryptocb.h>
  202. #ifdef HAVE_INTEL_QA_SYNC
  203. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  204. #endif
  205. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  206. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  207. #endif
  208. #ifdef HAVE_RENESAS_SYNC
  209. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  210. #endif
  211. #endif
  212. #ifdef WOLFSSL_ASYNC_CRYPT
  213. #include <wolfssl/wolfcrypt/async.h>
  214. #endif
  215. #ifdef USE_FLAT_BENCHMARK_H
  216. #include "benchmark.h"
  217. #else
  218. #include "wolfcrypt/benchmark/benchmark.h"
  219. #endif
  220. /* define the max length for each string of metric reported */
  221. #ifndef WC_BENCH_MAX_LINE_LEN
  222. #define WC_BENCH_MAX_LINE_LEN 150
  223. #endif
  224. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  225. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  226. #define MILLION_VALUE 1000000.0
  227. #ifdef BENCH_MICROSECOND
  228. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  229. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  230. #else
  231. #define WOLFSSL_FIXED_TIME_UNIT "s"
  232. #endif
  233. #ifdef MULTI_VALUE_STATISTICS
  234. #define STATS_CLAUSE_SEPARATOR ""
  235. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  236. squareSum = 0, prev = 0, delta;\
  237. int runs = 0;
  238. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  239. delta = current_time(0) - start;\
  240. min = delta;\
  241. max = delta;\
  242. }\
  243. else {\
  244. delta = current_time(0) - prev;\
  245. }\
  246. if (max < delta)\
  247. max = delta;\
  248. else if (min > delta)\
  249. min = delta;\
  250. sum += delta;\
  251. squareSum += delta * delta;\
  252. runs++;\
  253. prev = current_time(0)
  254. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  255. runs = 0;\
  256. sum = 0;\
  257. squareSum = 0
  258. #else
  259. #define STATS_CLAUSE_SEPARATOR "\n"
  260. #define DECLARE_MULTI_VALUE_STATS_VARS()
  261. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  262. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  263. #endif
  264. #ifdef WOLFSSL_NO_FLOAT_FMT
  265. #define FLT_FMT "%0ld,%09lu"
  266. #define FLT_FMT_PREC "%0ld.%0*lu"
  267. #define FLT_FMT_PREC2 FLT_FMT_PREC
  268. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  269. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  270. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  271. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  272. 10000.0, 100000.0, 1000000.0, \
  273. 10000000.0, 100000000.0, \
  274. 1000000000.0 };
  275. #define FLT_FMT_PREC_ARGS(p, x) \
  276. (long)(x), \
  277. p, \
  278. (x) >= 0.0 ? \
  279. (unsigned long int)((((x) - (double)(long)(x)) * \
  280. pow_10_array[(p)+1]) + 0.5) : \
  281. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  282. pow_10_array[(p)+1]) + 0.5)
  283. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  284. #else
  285. #define FLT_FMT "%f"
  286. #define FLT_FMT_PREC "%.*f"
  287. #define FLT_FMT_PREC2 "%*.*f"
  288. #define FLT_FMT_ARGS(x) x
  289. #define FLT_FMT_PREC_ARGS(p, x) p, x
  290. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  291. #endif /* WOLFSSL_NO_FLOAT_FMT */
  292. #ifdef WOLFSSL_ESPIDF
  293. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  294. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  295. * enabled, all if the values in report are blank. */
  296. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  297. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  298. #error "Nano newlib formatting must not be enabled for benchmark"
  299. #endif
  300. #endif
  301. #ifdef configTICK_RATE_HZ
  302. /* Define CPU clock cycles per tick of FreeRTOS clock
  303. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  304. * configTICK_RATE_HZ is typically 100 or 1000.
  305. **/
  306. #if defined(CONFIG_IDF_TARGET_ESP8266)
  307. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  308. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  309. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  310. #endif
  311. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  312. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  313. #endif
  314. #endif
  315. #define CPU_TICK_CYCLES ( \
  316. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  317. / configTICK_RATE_HZ \
  318. )
  319. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  320. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  321. #include "driver/gptimer.h"
  322. static gptimer_handle_t esp_gptimer = NULL;
  323. static gptimer_config_t esp_timer_config = {
  324. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  325. .direction = GPTIMER_COUNT_UP,
  326. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  327. };
  328. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  329. defined(CONFIG_IDF_TARGET_ESP32C6)
  330. #include <esp_cpu.h>
  331. #include "driver/gptimer.h"
  332. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  333. #define RESOLUTION_SCALE 100
  334. static gptimer_handle_t esp_gptimer = NULL;
  335. static gptimer_config_t esp_timer_config = {
  336. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  337. .direction = GPTIMER_COUNT_UP,
  338. /* CONFIG_XTAL_FREQ = 40,
  339. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  340. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  341. (MILLION_VALUE / RESOLUTION_SCALE),
  342. };
  343. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  344. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  345. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  346. defined(CONFIG_IDF_TARGET_ESP32S3)
  347. #include <xtensa/hal.h>
  348. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  349. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  350. #include <FreeRTOS.h>
  351. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  352. /* TODO add ESP32-H2 benchmark support */
  353. #else
  354. /* Other platform */
  355. #endif
  356. #include <esp_log.h>
  357. #endif /* WOLFSSL_ESPIDF */
  358. #if defined(HAVE_PTHREAD) || \
  359. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  360. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  361. !defined(BENCH_EMBEDDED))
  362. #include <errno.h>
  363. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  364. #include <unistd.h>
  365. #endif
  366. #endif
  367. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  368. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  369. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  370. #undef XFFLUSH
  371. #define XFFLUSH(...) WC_DO_NOTHING
  372. #endif
  373. /* only for stack size check */
  374. #include <wolfssl/wolfcrypt/mem_track.h>
  375. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  376. #define WC_ENABLE_BENCH_THREADING
  377. #endif
  378. /* enable tracking of stats for threaded benchmark */
  379. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  380. #define WC_BENCH_TRACK_STATS
  381. #endif
  382. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  383. static const char info_prefix[] = "###, ";
  384. static const char err_prefix[] = "!!!, ";
  385. #else
  386. static const char info_prefix[] = "";
  387. static const char err_prefix[] = "";
  388. #endif
  389. /* printf mappings */
  390. #ifdef FREESCALE_MQX
  391. #include <mqx.h>
  392. /* see wc_port.h for fio.h and nio.h includes */
  393. #elif defined(FREESCALE_KSDK_1_3)
  394. #include "fsl_debug_console.h"
  395. #include "fsl_os_abstraction.h"
  396. #undef printf
  397. #define printf PRINTF
  398. #elif defined(WOLFSSL_DEOS)
  399. #include <deos.h>
  400. #include <printx.h>
  401. #undef printf
  402. #define printf printx
  403. #elif defined(MICRIUM)
  404. #if (OS_VERSION < 50000)
  405. #include <bsp_ser.h>
  406. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  407. #undef printf
  408. #define printf BSP_Ser_Printf
  409. #endif
  410. #elif defined(WOLFSSL_ZEPHYR)
  411. #include <stdio.h>
  412. #define BENCH_EMBEDDED
  413. #define printf printfk
  414. static int printfk(const char *fmt, ...)
  415. {
  416. int ret;
  417. char line[WC_BENCH_MAX_LINE_LEN];
  418. va_list ap;
  419. va_start(ap, fmt);
  420. ret = vsnprintf(line, sizeof(line), fmt, ap);
  421. line[sizeof(line)-1] = '\0';
  422. printk("%s", line);
  423. va_end(ap);
  424. return ret;
  425. }
  426. #elif defined(WOLFSSL_TELIT_M2MB)
  427. #include <stdarg.h>
  428. #include <stdio.h>
  429. #include <string.h>
  430. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  431. /* remap printf */
  432. #undef printf
  433. #define printf M2M_LOG_INFO
  434. /* OS requires occasional sleep() */
  435. #ifndef TEST_SLEEP_MS
  436. #define TEST_SLEEP_MS 50
  437. #endif
  438. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  439. /* don't use file system for these tests, since ./certs dir isn't loaded */
  440. #undef NO_FILESYSTEM
  441. #define NO_FILESYSTEM
  442. /* ANDROID_V454 (for android studio) displays information in a textview
  443. * and redirects printf to the textview output instead of using
  444. * __android_log_print() */
  445. #elif defined(ANDROID) && !defined(ANDROID_V454)
  446. #ifdef XMALLOC_USER
  447. #include <stdlib.h> /* we're using malloc / free direct here */
  448. #endif
  449. #ifndef STRING_USER
  450. #include <stdio.h>
  451. #endif
  452. #include <android/log.h>
  453. #define printf(...) \
  454. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  455. #define fprintf(fp, ...) \
  456. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  457. #else
  458. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  459. /* MQX classic needs for EXIT_FAILURE */
  460. #include <stdlib.h> /* we're using malloc / free direct here */
  461. #endif
  462. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  463. #include <string.h>
  464. #include <stdio.h>
  465. #endif
  466. /* enable way for customer to override test/bench printf */
  467. #ifdef XPRINTF
  468. #undef printf
  469. #define printf XPRINTF
  470. #elif defined(NETOS)
  471. #undef printf
  472. #define printf dc_log_printf
  473. #endif
  474. #endif
  475. #ifdef HAVE_FIPS
  476. #include <wolfssl/wolfcrypt/fips_test.h>
  477. static void myFipsCb(int ok, int err, const char* hash)
  478. {
  479. printf("%sin my Fips callback, ok = %d, err = %d\n",
  480. ok ? info_prefix : err_prefix, ok, err);
  481. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  482. wc_GetErrorString(err));
  483. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  484. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  485. printf("%sIn core integrity hash check failure, copy above hash\n",
  486. err_prefix);
  487. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  488. err_prefix);
  489. }
  490. }
  491. #endif
  492. #ifdef WOLFSSL_STATIC_MEMORY
  493. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  494. #else
  495. #define HEAP_HINT NULL
  496. #endif /* WOLFSSL_STATIC_MEMORY */
  497. #ifndef EXIT_FAILURE
  498. #define EXIT_FAILURE 1
  499. #endif
  500. #undef LIBCALL_CHECK_RET
  501. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  502. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  503. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  504. #else
  505. #define LIBCALL_CHECK_RET(...) do { \
  506. int _libcall_ret = (__VA_ARGS__); \
  507. if (_libcall_ret < 0) { \
  508. printf("%s%s L%d error %d for \"%s\"\n", \
  509. err_prefix, __FILE__, __LINE__, \
  510. errno, #__VA_ARGS__); \
  511. XFFLUSH(stdout); \
  512. _exit(1); \
  513. } \
  514. } while(0)
  515. #endif
  516. #undef THREAD_CHECK_RET
  517. #define THREAD_CHECK_RET(...) do { \
  518. int _thread_ret = (__VA_ARGS__); \
  519. if (_thread_ret != 0) { \
  520. errno = _thread_ret; \
  521. printf("%s%s L%d error %d for \"%s\"\n", \
  522. err_prefix, __FILE__, __LINE__, \
  523. _thread_ret, #__VA_ARGS__); \
  524. XFFLUSH(stdout); \
  525. _exit(1); \
  526. } \
  527. } while(0)
  528. /* optional macro to add sleep between tests */
  529. #ifndef TEST_SLEEP
  530. /* stub the sleep macro */
  531. #define TEST_SLEEP() WC_DO_NOTHING
  532. #endif
  533. #define TEST_STRING "Everyone gets Friday off."
  534. #define TEST_STRING_SZ 25
  535. /* Bit values for each algorithm that is able to be benchmarked.
  536. * Common grouping of algorithms also.
  537. * Each algorithm has a unique value for its type e.g. cipher.
  538. */
  539. /* Cipher algorithms. */
  540. #define BENCH_AES_CBC 0x00000001
  541. #define BENCH_AES_GCM 0x00000002
  542. #define BENCH_AES_ECB 0x00000004
  543. #define BENCH_AES_XTS 0x00000008
  544. #define BENCH_AES_CTR 0x00000010
  545. #define BENCH_AES_CCM 0x00000020
  546. #define BENCH_CAMELLIA 0x00000100
  547. #define BENCH_ARC4 0x00000200
  548. #define BENCH_CHACHA20 0x00001000
  549. #define BENCH_CHACHA20_POLY1305 0x00002000
  550. #define BENCH_DES 0x00004000
  551. #define BENCH_AES_CFB 0x00010000
  552. #define BENCH_AES_OFB 0x00020000
  553. #define BENCH_AES_SIV 0x00040000
  554. #define BENCH_SM4_CBC 0x00080000
  555. #define BENCH_SM4_GCM 0x00100000
  556. #define BENCH_SM4_CCM 0x00200000
  557. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  558. /* Digest algorithms. */
  559. #define BENCH_MD5 0x00000001
  560. #define BENCH_POLY1305 0x00000002
  561. #define BENCH_SHA 0x00000004
  562. #define BENCH_SHA224 0x00000010
  563. #define BENCH_SHA256 0x00000020
  564. #define BENCH_SHA384 0x00000040
  565. #define BENCH_SHA512 0x00000080
  566. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  567. BENCH_SHA384 | BENCH_SHA512)
  568. #define BENCH_SHA3_224 0x00000100
  569. #define BENCH_SHA3_256 0x00000200
  570. #define BENCH_SHA3_384 0x00000400
  571. #define BENCH_SHA3_512 0x00000800
  572. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  573. BENCH_SHA3_384 | BENCH_SHA3_512)
  574. #define BENCH_SHAKE128 0x00001000
  575. #define BENCH_SHAKE256 0x00002000
  576. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  577. #define BENCH_RIPEMD 0x00004000
  578. #define BENCH_BLAKE2B 0x00008000
  579. #define BENCH_BLAKE2S 0x00010000
  580. #define BENCH_SM3 0x00020000
  581. /* MAC algorithms. */
  582. #define BENCH_CMAC 0x00000001
  583. #define BENCH_HMAC_MD5 0x00000002
  584. #define BENCH_HMAC_SHA 0x00000004
  585. #define BENCH_HMAC_SHA224 0x00000010
  586. #define BENCH_HMAC_SHA256 0x00000020
  587. #define BENCH_HMAC_SHA384 0x00000040
  588. #define BENCH_HMAC_SHA512 0x00000080
  589. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  590. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  591. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  592. #define BENCH_PBKDF2 0x00000100
  593. #define BENCH_SIPHASH 0x00000200
  594. /* KDF algorithms */
  595. #define BENCH_SRTP_KDF 0x00000001
  596. /* Asymmetric algorithms. */
  597. #define BENCH_RSA_KEYGEN 0x00000001
  598. #define BENCH_RSA 0x00000002
  599. #define BENCH_RSA_SZ 0x00000004
  600. #define BENCH_DH 0x00000010
  601. #define BENCH_ECC_MAKEKEY 0x00001000
  602. #define BENCH_ECC 0x00002000
  603. #define BENCH_ECC_ENCRYPT 0x00004000
  604. #define BENCH_ECC_ALL 0x00008000
  605. #define BENCH_CURVE25519_KEYGEN 0x00010000
  606. #define BENCH_CURVE25519_KA 0x00020000
  607. #define BENCH_ED25519_KEYGEN 0x00040000
  608. #define BENCH_ED25519_SIGN 0x00080000
  609. #define BENCH_CURVE448_KEYGEN 0x00100000
  610. #define BENCH_CURVE448_KA 0x00200000
  611. #define BENCH_ED448_KEYGEN 0x00400000
  612. #define BENCH_ED448_SIGN 0x00800000
  613. #define BENCH_ECC_P256 0x01000000
  614. #define BENCH_ECC_P384 0x02000000
  615. #define BENCH_ECC_P521 0x04000000
  616. #define BENCH_SM2 0x08000000
  617. #define BENCH_ECCSI_KEYGEN 0x00000020
  618. #define BENCH_ECCSI_PAIRGEN 0x00000040
  619. #define BENCH_ECCSI_VALIDATE 0x00000080
  620. #define BENCH_ECCSI 0x00000400
  621. #define BENCH_SAKKE_KEYGEN 0x10000000
  622. #define BENCH_SAKKE_RSKGEN 0x20000000
  623. #define BENCH_SAKKE_VALIDATE 0x40000000
  624. #define BENCH_SAKKE 0x80000000
  625. /* Post-Quantum Asymmetric algorithms. */
  626. #define BENCH_KYBER512 0x00000020
  627. #define BENCH_KYBER768 0x00000040
  628. #define BENCH_KYBER1024 0x00000080
  629. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  630. BENCH_KYBER1024)
  631. #define BENCH_ML_KEM_512 0x00000020
  632. #define BENCH_ML_KEM_768 0x00000040
  633. #define BENCH_ML_KEM_1024 0x00000080
  634. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  635. BENCH_ML_KEM_1024)
  636. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  637. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  638. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  639. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  640. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  641. #define BENCH_ML_DSA_44_SIGN 0x04000000
  642. #define BENCH_ML_DSA_65_SIGN 0x08000000
  643. #define BENCH_ML_DSA_87_SIGN 0x10000000
  644. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  645. BENCH_ML_DSA_65_SIGN | \
  646. BENCH_ML_DSA_87_SIGN)
  647. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  648. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  649. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  650. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  651. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  652. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  653. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  654. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  655. #define BENCH_LMS_HSS 0x00000001
  656. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  657. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  658. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  659. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  660. #ifndef NO_SHA256
  661. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  662. #elif defined(WOLFSSL_SHA512)
  663. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  664. #elif defined(WOLFSSL_SHAKE128)
  665. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  666. #elif defined(WOLFSSL_SHAKE256)
  667. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  668. #else
  669. #define BENCH_XMSS_XMSSMT 0x00000000
  670. #endif
  671. /* Other */
  672. #define BENCH_RNG 0x00000001
  673. #define BENCH_SCRYPT 0x00000002
  674. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  675. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  676. * static declaration of `bench_Usage_msg1`. */
  677. #if !defined(AES_AUTH_ADD_SZ) && \
  678. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  679. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  680. /* For STM32 use multiple of 4 to leverage crypto hardware
  681. * Xilinx Versal requires to use multiples of 16 bytes */
  682. #define AES_AUTH_ADD_SZ 16
  683. #endif
  684. #ifndef AES_AUTH_ADD_SZ
  685. #define AES_AUTH_ADD_SZ 13
  686. #endif
  687. #endif
  688. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  689. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  690. #define BENCH_PQ_STATEFUL_HBS
  691. #endif
  692. /* Benchmark all compiled in algorithms.
  693. * When 1, ignore other benchmark algorithm values.
  694. * 0, only benchmark algorithm values set.
  695. */
  696. static int bench_all = 1;
  697. /* Cipher algorithms to benchmark. */
  698. static word32 bench_cipher_algs = 0;
  699. /* Digest algorithms to benchmark. */
  700. static word32 bench_digest_algs = 0;
  701. /* MAC algorithms to benchmark. */
  702. static word32 bench_mac_algs = 0;
  703. /* KDF algorithms to benchmark. */
  704. static word32 bench_kdf_algs = 0;
  705. /* Asymmetric algorithms to benchmark. */
  706. static word32 bench_asym_algs = 0;
  707. /* Post-Quantum Asymmetric algorithms to benchmark. */
  708. static word32 bench_pq_asym_algs = 0;
  709. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  710. static word32 bench_pq_asym_algs2 = 0;
  711. /* Other cryptographic algorithms to benchmark. */
  712. static word32 bench_other_algs = 0;
  713. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  714. static word32 bench_pq_hash_sig_algs = 0;
  715. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  716. /* The mapping of command line option to bit values. */
  717. typedef struct bench_alg {
  718. /* Command line option string. */
  719. const char* str;
  720. /* Bit values to set. */
  721. word32 val;
  722. } bench_alg;
  723. #ifndef MAIN_NO_ARGS
  724. /* All recognized cipher algorithm choosing command line options. */
  725. static const bench_alg bench_cipher_opt[] = {
  726. { "-cipher", 0xffffffff },
  727. #ifdef HAVE_AES_CBC
  728. { "-aes-cbc", BENCH_AES_CBC },
  729. #endif
  730. #ifdef HAVE_AESGCM
  731. { "-aes-gcm", BENCH_AES_GCM },
  732. #endif
  733. #ifdef WOLFSSL_AES_DIRECT
  734. { "-aes-ecb", BENCH_AES_ECB },
  735. #endif
  736. #ifdef WOLFSSL_AES_XTS
  737. { "-aes-xts", BENCH_AES_XTS },
  738. #endif
  739. #ifdef WOLFSSL_AES_CFB
  740. { "-aes-cfb", BENCH_AES_CFB },
  741. #endif
  742. #ifdef WOLFSSL_AES_OFB
  743. { "-aes-ofb", BENCH_AES_OFB },
  744. #endif
  745. #ifdef WOLFSSL_AES_COUNTER
  746. { "-aes-ctr", BENCH_AES_CTR },
  747. #endif
  748. #ifdef HAVE_AESCCM
  749. { "-aes-ccm", BENCH_AES_CCM },
  750. #endif
  751. #ifdef WOLFSSL_AES_SIV
  752. { "-aes-siv", BENCH_AES_SIV },
  753. #endif
  754. #ifdef HAVE_CAMELLIA
  755. { "-camellia", BENCH_CAMELLIA },
  756. #endif
  757. #ifndef NO_RC4
  758. { "-arc4", BENCH_ARC4 },
  759. #endif
  760. #ifdef HAVE_CHACHA
  761. { "-chacha20", BENCH_CHACHA20 },
  762. #endif
  763. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  764. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  765. #endif
  766. #ifdef WOLFSSL_SM4_CBC
  767. { "-sm4-cbc", BENCH_SM4_CBC },
  768. #endif
  769. #ifdef WOLFSSL_SM4_GCM
  770. { "-sm4-gcm", BENCH_SM4_GCM },
  771. #endif
  772. #ifdef WOLFSSL_SM4_CCM
  773. { "-sm4-ccm", BENCH_SM4_CCM },
  774. #endif
  775. #ifdef WOLFSSL_SM4
  776. { "-sm4", BENCH_SM4 },
  777. #endif
  778. #ifndef NO_DES3
  779. { "-des", BENCH_DES },
  780. #endif
  781. { NULL, 0 }
  782. };
  783. /* All recognized digest algorithm choosing command line options. */
  784. static const bench_alg bench_digest_opt[] = {
  785. { "-digest", 0xffffffff },
  786. #ifndef NO_MD5
  787. { "-md5", BENCH_MD5 },
  788. #endif
  789. #ifdef HAVE_POLY1305
  790. { "-poly1305", BENCH_POLY1305 },
  791. #endif
  792. #ifndef NO_SHA
  793. { "-sha", BENCH_SHA },
  794. #endif
  795. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  796. || defined(WOLFSSL_SHA512)
  797. { "-sha2", BENCH_SHA2 },
  798. #endif
  799. #ifdef WOLFSSL_SHA224
  800. { "-sha224", BENCH_SHA224 },
  801. #endif
  802. #ifndef NO_SHA256
  803. { "-sha256", BENCH_SHA256 },
  804. #endif
  805. #ifdef WOLFSSL_SHA384
  806. { "-sha384", BENCH_SHA384 },
  807. #endif
  808. #ifdef WOLFSSL_SHA512
  809. { "-sha512", BENCH_SHA512 },
  810. #endif
  811. #ifdef WOLFSSL_SHA3
  812. { "-sha3", BENCH_SHA3 },
  813. #ifndef WOLFSSL_NOSHA3_224
  814. { "-sha3-224", BENCH_SHA3_224 },
  815. #endif
  816. #ifndef WOLFSSL_NOSHA3_256
  817. { "-sha3-256", BENCH_SHA3_256 },
  818. #endif
  819. #ifndef WOLFSSL_NOSHA3_384
  820. { "-sha3-384", BENCH_SHA3_384 },
  821. #endif
  822. #ifndef WOLFSSL_NOSHA3_512
  823. { "-sha3-512", BENCH_SHA3_512 },
  824. #endif
  825. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  826. { "-shake", BENCH_SHAKE },
  827. #endif
  828. #ifdef WOLFSSL_SHAKE128
  829. { "-shake128", BENCH_SHAKE128 },
  830. #endif
  831. #ifdef WOLFSSL_SHAKE256
  832. { "-shake256", BENCH_SHAKE256 },
  833. #endif
  834. #endif
  835. #ifdef WOLFSSL_SM3
  836. { "-sm3", BENCH_SM3 },
  837. #endif
  838. #ifdef WOLFSSL_RIPEMD
  839. { "-ripemd", BENCH_RIPEMD },
  840. #endif
  841. #ifdef HAVE_BLAKE2
  842. { "-blake2b", BENCH_BLAKE2B },
  843. #endif
  844. #ifdef HAVE_BLAKE2S
  845. { "-blake2s", BENCH_BLAKE2S },
  846. #endif
  847. { NULL, 0 }
  848. };
  849. /* All recognized MAC algorithm choosing command line options. */
  850. static const bench_alg bench_mac_opt[] = {
  851. { "-mac", 0xffffffff },
  852. #ifdef WOLFSSL_CMAC
  853. { "-cmac", BENCH_CMAC },
  854. #endif
  855. #ifndef NO_HMAC
  856. { "-hmac", BENCH_HMAC },
  857. #ifndef NO_MD5
  858. { "-hmac-md5", BENCH_HMAC_MD5 },
  859. #endif
  860. #ifndef NO_SHA
  861. { "-hmac-sha", BENCH_HMAC_SHA },
  862. #endif
  863. #ifdef WOLFSSL_SHA224
  864. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  865. #endif
  866. #ifndef NO_SHA256
  867. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  868. #endif
  869. #ifdef WOLFSSL_SHA384
  870. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  871. #endif
  872. #ifdef WOLFSSL_SHA512
  873. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  874. #endif
  875. #ifndef NO_PWDBASED
  876. { "-pbkdf2", BENCH_PBKDF2 },
  877. #endif
  878. #endif
  879. #ifdef WOLFSSL_SIPHASH
  880. { "-siphash", BENCH_SIPHASH },
  881. #endif
  882. { NULL, 0 }
  883. };
  884. /* All recognized KDF algorithm choosing command line options. */
  885. static const bench_alg bench_kdf_opt[] = {
  886. { "-kdf", 0xffffffff },
  887. #ifdef WC_SRTP_KDF
  888. { "-srtp-kdf", BENCH_SRTP_KDF },
  889. #endif
  890. { NULL, 0 }
  891. };
  892. /* All recognized asymmetric algorithm choosing command line options. */
  893. static const bench_alg bench_asym_opt[] = {
  894. { "-asym", 0xffffffff },
  895. #ifndef NO_RSA
  896. #ifdef WOLFSSL_KEY_GEN
  897. { "-rsa-kg", BENCH_RSA_KEYGEN },
  898. #endif
  899. { "-rsa", BENCH_RSA },
  900. #ifdef WOLFSSL_KEY_GEN
  901. { "-rsa-sz", BENCH_RSA_SZ },
  902. #endif
  903. #endif
  904. #ifndef NO_DH
  905. { "-dh", BENCH_DH },
  906. #endif
  907. #ifdef HAVE_ECC
  908. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  909. { "-ecc", BENCH_ECC },
  910. #ifdef HAVE_ECC_ENCRYPT
  911. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  912. #endif
  913. { "-ecc-all", BENCH_ECC_ALL },
  914. #endif
  915. #ifdef WOLFSSL_SM2
  916. { "-sm2", BENCH_SM2 },
  917. #endif
  918. #ifdef HAVE_CURVE25519
  919. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  920. #ifdef HAVE_CURVE25519_SHARED_SECRET
  921. { "-x25519", BENCH_CURVE25519_KA },
  922. #endif
  923. #endif
  924. #ifdef HAVE_ED25519
  925. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  926. { "-ed25519", BENCH_ED25519_SIGN },
  927. #endif
  928. #ifdef HAVE_CURVE448
  929. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  930. #ifdef HAVE_CURVE448_SHARED_SECRET
  931. { "-x448", BENCH_CURVE448_KA },
  932. #endif
  933. #endif
  934. #ifdef HAVE_ED448
  935. { "-ed448-kg", BENCH_ED448_KEYGEN },
  936. { "-ed448", BENCH_ED448_SIGN },
  937. #endif
  938. #ifdef WOLFCRYPT_HAVE_ECCSI
  939. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  940. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  941. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  942. { "-eccsi", BENCH_ECCSI },
  943. #endif
  944. #ifdef WOLFCRYPT_HAVE_SAKKE
  945. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  946. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  947. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  948. { "-sakke", BENCH_SAKKE },
  949. #endif
  950. { NULL, 0 }
  951. };
  952. /* All recognized other cryptographic algorithm choosing command line options.
  953. */
  954. static const bench_alg bench_other_opt[] = {
  955. { "-other", 0xffffffff },
  956. #ifndef WC_NO_RNG
  957. { "-rng", BENCH_RNG },
  958. #endif
  959. #ifdef HAVE_SCRYPT
  960. { "-scrypt", BENCH_SCRYPT },
  961. #endif
  962. { NULL, 0}
  963. };
  964. #endif /* MAIN_NO_ARGS */
  965. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  966. #if defined(BENCH_PQ_STATEFUL_HBS)
  967. typedef struct bench_pq_hash_sig_alg {
  968. /* Command line option string. */
  969. const char* str;
  970. /* Bit values to set. */
  971. word32 val;
  972. } bench_pq_hash_sig_alg;
  973. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  974. { "-pq_hash_sig", 0xffffffff},
  975. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  976. { "-lms_hss", BENCH_LMS_HSS},
  977. #endif
  978. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  979. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  980. #ifdef WC_XMSS_SHA256
  981. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  982. #endif
  983. #ifdef WC_XMSS_SHA512
  984. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  985. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  986. #endif
  987. #endif
  988. #ifdef WC_XMSS_SHAKE128
  989. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  990. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  991. #endif
  992. #endif
  993. #ifdef WC_XMSS_SHAKE256
  994. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  995. #endif
  996. #endif
  997. { NULL, 0}
  998. };
  999. #endif /* BENCH_PQ_STATEFUL_HBS */
  1000. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1001. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1002. /* The post-quantum-specific mapping of command line option to bit values and
  1003. * OQS name. */
  1004. typedef struct bench_pq_alg {
  1005. /* Command line option string. */
  1006. const char* str;
  1007. /* Bit values to set. */
  1008. word32 val;
  1009. } bench_pq_alg;
  1010. /* All recognized post-quantum asymmetric algorithm choosing command line
  1011. * options. */
  1012. static const bench_pq_alg bench_pq_asym_opt[] = {
  1013. { "-pq", 0xffffffff },
  1014. #ifdef WOLFSSL_HAVE_KYBER
  1015. { "-kyber", BENCH_KYBER },
  1016. { "-kyber512", BENCH_KYBER512 },
  1017. { "-kyber768", BENCH_KYBER768 },
  1018. { "-kyber1024", BENCH_KYBER1024 },
  1019. { "-ml-kem", BENCH_ML_KEM },
  1020. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1021. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1022. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1023. #endif
  1024. #if defined(HAVE_FALCON)
  1025. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1026. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1027. #endif
  1028. #if defined(HAVE_DILITHIUM)
  1029. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1030. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1031. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1032. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1033. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1034. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1035. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1036. #endif
  1037. { NULL, 0 }
  1038. };
  1039. #if defined(HAVE_SPHINCS)
  1040. /* All recognized post-quantum asymmetric algorithm choosing command line
  1041. * options. (Part 2) */
  1042. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1043. { "-pq", 0xffffffff },
  1044. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1045. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1046. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1047. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1048. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1049. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1050. { NULL, 0, }
  1051. };
  1052. #endif /* HAVE_SPHINCS */
  1053. #endif
  1054. #ifdef HAVE_WNR
  1055. const char* wnrConfigFile = "wnr-example.conf";
  1056. #endif
  1057. #if defined(WOLFSSL_MDK_ARM)
  1058. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1059. #define fopen wolfSSL_fopen
  1060. #endif
  1061. static int lng_index = 0;
  1062. #ifndef NO_MAIN_DRIVER
  1063. #ifndef MAIN_NO_ARGS
  1064. static const char* bench_Usage_msg1[][25] = {
  1065. /* 0 English */
  1066. { "-? <num> Help, print this usage\n",
  1067. " 0: English, 1: Japanese\n",
  1068. "-csv Print terminal output in csv format\n",
  1069. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1070. "-no_aad No additional authentication data passed.\n",
  1071. "-aad_size <num> With <num> bytes of AAD.\n",
  1072. ("-all_aad With AAD length of 0, "
  1073. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1074. " and\n"
  1075. " (if set via -aad_size) <aad_size> bytes.\n"
  1076. ),
  1077. "-dgst_full Full digest operation performed.\n",
  1078. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1079. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1080. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1081. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1082. "-p256 Measure ECC using P-256 curve.\n",
  1083. "-p384 Measure ECC using P-384 curve.\n",
  1084. "-p521 Measure ECC using P-521 curve.\n",
  1085. "-ecc-all Bench all enabled ECC curves.\n",
  1086. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1087. ("-lng <num> Display benchmark result by specified language.\n"
  1088. " 0: English, 1: Japanese\n"
  1089. ),
  1090. "<num> Size of block in bytes\n",
  1091. ("-blocks <num> Number of blocks. Can be used together with the "
  1092. "'Size of block'\n"
  1093. " option, but must be used after that one.\n"
  1094. ),
  1095. "-threads <num> Number of threads to run\n",
  1096. "-print Show benchmark stats summary\n",
  1097. "-hash_input <file> Input data to use for hash benchmarking\n",
  1098. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1099. "-min_runs <num> Specify minimum number of operation runs\n"
  1100. },
  1101. #ifndef NO_MULTIBYTE_PRINT
  1102. /* 1 Japanese */
  1103. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1104. " 0: 英語、 1: 日本語\n",
  1105. "-csv csv 形式で端末に出力します。\n",
  1106. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1107. "-no_aad 追加の認証データを使用しません.\n",
  1108. "-aad_size <num> TBD.\n",
  1109. "-all_aad TBD.\n",
  1110. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1111. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1112. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1113. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1114. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1115. "-p256 Measure ECC using P-256 curve.\n",
  1116. "-p384 Measure ECC using P-384 curve.\n",
  1117. "-p521 Measure ECC using P-521 curve.\n",
  1118. "-ecc-all Bench all enabled ECC curves.\n",
  1119. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1120. " 利用可能なアルゴリズムは下記を含みます:\n"
  1121. ),
  1122. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1123. " 0: 英語、 1: 日本語\n"
  1124. ),
  1125. "<num> ブロックサイズをバイト単位で指定します。\n",
  1126. "-blocks <num> TBD.\n",
  1127. "-threads <num> 実行するスレッド数\n",
  1128. "-print ベンチマーク統計の要約を表示する\n",
  1129. /* TODO: translate below */
  1130. "-hash_input <file> Input data to use for hash benchmarking\n",
  1131. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1132. "-min_runs <num> Specify minimum number of operation runs\n"
  1133. },
  1134. #endif
  1135. };
  1136. #endif /* MAIN_NO_ARGS */
  1137. #endif
  1138. static const char* bench_result_words1[][4] = {
  1139. { "took",
  1140. #ifdef BENCH_MICROSECOND
  1141. "microseconds"
  1142. #else
  1143. "seconds"
  1144. #endif
  1145. , "Cycles per byte", NULL }, /* 0 English */
  1146. #ifndef NO_MULTIBYTE_PRINT
  1147. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1148. #endif
  1149. };
  1150. #if !defined(NO_RSA) || \
  1151. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1152. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1153. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1154. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1155. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1156. static const char* bench_desc_words[][15] = {
  1157. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1158. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1159. #ifndef NO_MULTIBYTE_PRINT
  1160. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1161. #endif
  1162. };
  1163. #endif
  1164. #ifdef MULTI_VALUE_STATISTICS
  1165. static const char* bench_result_words3[][5] = {
  1166. /* 0 English */
  1167. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1168. /* TODO: Add japenese version */
  1169. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1170. };
  1171. #endif
  1172. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1173. #define HAVE_GET_CYCLES
  1174. static WC_INLINE word64 get_intel_cycles(void);
  1175. static THREAD_LS_T word64 total_cycles;
  1176. #define INIT_CYCLE_COUNTER
  1177. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1178. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1179. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1180. #define SHOW_INTEL_CYCLES(b, n, s) \
  1181. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1182. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1183. bench_result_words1[lng_index][2], \
  1184. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1185. (double)total_cycles / ((word64)count*(s))))
  1186. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1187. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1188. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1189. (double)total_cycles / ((word64)count*(s))))
  1190. #elif defined(LINUX_CYCLE_COUNT)
  1191. #include <linux/perf_event.h>
  1192. #include <sys/syscall.h>
  1193. #include <unistd.h>
  1194. static THREAD_LS_T word64 begin_cycles;
  1195. static THREAD_LS_T word64 total_cycles;
  1196. static THREAD_LS_T int cycles = -1;
  1197. static THREAD_LS_T struct perf_event_attr atr;
  1198. #define INIT_CYCLE_COUNTER do { \
  1199. atr.type = PERF_TYPE_HARDWARE; \
  1200. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1201. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1202. } while (0);
  1203. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1204. #define END_INTEL_CYCLES do { \
  1205. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1206. total_cycles = total_cycles - begin_cycles; \
  1207. } while (0);
  1208. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1209. #define SHOW_INTEL_CYCLES(b, n, s) \
  1210. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1211. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1212. bench_result_words1[lng_index][2], \
  1213. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1214. (count*s)))
  1215. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1216. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1217. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1218. / (count*s)))
  1219. #elif defined(SYNERGY_CYCLE_COUNT)
  1220. #include "hal_data.h"
  1221. static THREAD_LS_T word64 begin_cycles;
  1222. static THREAD_LS_T word64 total_cycles;
  1223. #define INIT_CYCLE_COUNTER
  1224. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1225. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1226. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1227. #define SHOW_INTEL_CYCLES(b, n, s) \
  1228. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1229. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1230. bench_result_words1[lng_index][2], \
  1231. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1232. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1233. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1234. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1235. #elif defined(WOLFSSL_ESPIDF)
  1236. /* TAG for ESP_LOGx() */
  1237. static const char* TAG = "wolfssl_benchmark";
  1238. static THREAD_LS_T word64 begin_cycles = 0;
  1239. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1240. static THREAD_LS_T word64 end_cycles = 0;
  1241. static THREAD_LS_T word64 total_cycles = 0;
  1242. /* the return value, as a global var */
  1243. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1244. /* the last value seen, adjusted for an overflow, as a global var */
  1245. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1246. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1247. /* esp_get_cpu_benchmark_cycles(void):
  1248. *
  1249. * Architecture-independant CPU clock counter.
  1250. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1251. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1252. /* Some vars for debugging, compare ticks to cycles */
  1253. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1254. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1255. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1256. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1257. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1258. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1259. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1260. #if ESP_IDF_VERSION_MAJOR >= 5
  1261. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1262. #define HAVE_GET_CYCLES
  1263. #define INIT_CYCLE_COUNTER do { \
  1264. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1265. esp_cpu_set_cycle_count(0); \
  1266. } while (0);
  1267. #else
  1268. #define HAVE_GET_CYCLES
  1269. #define INIT_CYCLE_COUNTER do { \
  1270. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1271. } while (0);
  1272. #endif
  1273. #define BEGIN_ESP_CYCLES do { \
  1274. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1275. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1276. begin_cycles_ticks = xTaskGetTickCount(); \
  1277. } while (0);
  1278. /* since it rolls over, we have something that will tolerate one */
  1279. #define END_ESP_CYCLES \
  1280. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1281. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1282. end_cycles, \
  1283. begin_cycles \
  1284. ); \
  1285. total_cycles = (end_cycles - begin_cycles);
  1286. #define SHOW_ESP_CYCLES(b, n, s) \
  1287. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1288. " %s = " FLT_FMT_PREC2 "\n", \
  1289. bench_result_words1[lng_index][2], \
  1290. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1291. )
  1292. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1293. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1294. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1295. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1296. /* 64 bit, unisgned, absolute difference
  1297. * used in CPU cycle counter debug calcs. */
  1298. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1299. {
  1300. uint64_t ret;
  1301. ret = (x > y) ? (x - y) : (y - x);
  1302. return ret;
  1303. }
  1304. #endif
  1305. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1306. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1307. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1308. ** at least once during full benchmark tests.
  1309. **
  1310. ** To test timing overflow, add a delay longer than max cycles:
  1311. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1312. */
  1313. uint64_t esp_get_cycle_count_ex()
  1314. {
  1315. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1316. /* unsigned int max = 4,294,967,295 */
  1317. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1318. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1319. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1320. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1321. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1322. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1323. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1324. #endif
  1325. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1326. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1327. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1328. * (current - last) */
  1329. #endif
  1330. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1331. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1332. defined(CONFIG_IDF_TARGET_ESP32C6)
  1333. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1334. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1335. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1336. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1337. thisVal = esp_cpu_get_cycle_count();
  1338. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1339. thisVal = esp_cpu_get_cycle_count();
  1340. #else
  1341. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1342. * Calling current_time(1) to reset time causes thisVal overflow,
  1343. * on Xtensa, but not on RISC-V architecture. See also, below */
  1344. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1345. #ifndef configCPU_CLOCK_HZ
  1346. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1347. #define configCPU_CLOCK_HZ \
  1348. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1349. #endif
  1350. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1351. thisVal = (uint64_t)xTaskGetTickCount() *
  1352. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1353. #elif defined(__XTENSA__)
  1354. thisVal = esp_cpu_get_cycle_count();
  1355. #else
  1356. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1357. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1358. #endif
  1359. #endif
  1360. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1361. {
  1362. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1363. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1364. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1365. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1366. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1367. ESP_LOGV(TAG, "last_tickCount = %u", last_tickCount);
  1368. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1369. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1370. }
  1371. #endif
  1372. /* If either thisVal is smaller than last (overflow), and/or the
  1373. * expected value calculated from FreeRTOS tick difference that would
  1374. * have never fit into an unsigned 32 bit integer anyhow... then we
  1375. * need to adjust thisVal to save. */
  1376. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1377. {
  1378. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1379. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1380. **
  1381. ** NOTE for long duration between calls with multiple overflows:
  1382. **
  1383. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1384. **
  1385. ** At this time no single test overflows. This is currently only a
  1386. ** concern for cumulative counts over multiple tests. As long
  1387. ** as well call xthal_get_ccount_ex() with no more than one
  1388. ** overflow CPU tick count, all will be well.
  1389. */
  1390. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1391. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1392. "(%llu < %llu) adding UINT_MAX = %llu.",
  1393. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1394. #endif
  1395. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1396. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1397. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1398. #endif
  1399. /* double check expected diff calc */
  1400. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1401. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1402. * tickDiff / configTICK_RATE_HZ;
  1403. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1404. #endif
  1405. if (expected_diff > UINT_MAX) {
  1406. /* The number of cycles expected from FreeRTOS ticks is
  1407. * greater than the maximum size of an unsigned 32-bit
  1408. * integer, meaning multiple overflows occurred. */
  1409. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1410. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1411. #endif
  1412. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1413. }
  1414. else {
  1415. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1416. }
  1417. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1418. {
  1419. tickBeginDiff = tickCount - begin_cycles_ticks;
  1420. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1421. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1422. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1423. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1424. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1425. }
  1426. #endif
  1427. }
  1428. else {
  1429. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1430. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1431. #endif
  1432. } /* if thisVal adjustment check */
  1433. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1434. if (thisTimerVal < _esp_cpu_timer_last)
  1435. {
  1436. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1437. "adding %ull", UINT_MAX);
  1438. thisTimerVal += (word64)UINT_MAX;
  1439. }
  1440. /* Check an alternate counter using a timer */
  1441. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1442. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1443. /* Adjust our actual returned value that takes into account overflow,
  1444. * increment 64 bit extended total by this 32 bit differential: */
  1445. thisIncrement = (thisVal - _esp_cpu_count_last);
  1446. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1447. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1448. #endif
  1449. /* Add our adjustment, taking into account overflows (see above) */
  1450. _esp_get_cycle_count_ex += thisIncrement;
  1451. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1452. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1453. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1454. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1455. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1456. /* all of this took some time, so reset the "last seen" value
  1457. * for the next measurement. */
  1458. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1459. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1460. defined(CONFIG_IDF_TARGET_ESP32C6)
  1461. {
  1462. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1463. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1464. &_esp_cpu_timer_last));
  1465. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1466. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1467. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1468. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1469. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1470. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1471. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1472. }
  1473. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1474. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1475. #else
  1476. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1477. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1478. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1479. * or thisVal = xthal_get_ccount(); */
  1480. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1481. /* There's no CPU counter on the ESP8266, so we'll estimate
  1482. * cycles based on defined CPU frequency from sdkconfig and
  1483. * the RTOS tick frequency */
  1484. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1485. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1486. #elif ESP_IDF_VERSION_MAJOR < 5
  1487. _esp_cpu_count_last = xthal_get_ccount();
  1488. #else
  1489. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1490. #endif
  1491. #endif
  1492. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1493. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1494. #endif
  1495. /* Return the 64 bit extended total from 32 bit counter. */
  1496. return _esp_get_cycle_count_ex;
  1497. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1498. /* implement other architecture cycle counters here */
  1499. #else
  1500. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1501. #undef HAVE_GET_CYCLES
  1502. #define INIT_CYCLE_COUNTER
  1503. #define BEGIN_INTEL_CYCLES
  1504. #define END_INTEL_CYCLES
  1505. #ifdef MULTI_VALUE_STATISTICS
  1506. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1507. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1508. #else
  1509. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1510. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1511. #endif
  1512. #endif
  1513. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1514. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1515. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1516. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1517. #endif
  1518. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1519. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1520. !defined(NO_DH)
  1521. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1522. #include <wolfssl/certs_test.h>
  1523. #endif
  1524. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1525. #include <wolfssl/wolfcrypt/blake2.h>
  1526. #endif
  1527. #ifdef _MSC_VER
  1528. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1529. #pragma warning(disable: 4996)
  1530. #endif
  1531. #ifdef WOLFSSL_CURRTIME_REMAP
  1532. #define current_time WOLFSSL_CURRTIME_REMAP
  1533. #else
  1534. double current_time(int reset);
  1535. #endif
  1536. #ifdef LINUX_RUSAGE_UTIME
  1537. static void check_for_excessive_stime(const char *desc,
  1538. const char *desc_extra);
  1539. #endif
  1540. #if !defined(WC_NO_RNG) && \
  1541. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1542. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1543. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1544. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1545. || defined(WOLFSSL_HAVE_KYBER))
  1546. #define HAVE_LOCAL_RNG
  1547. static THREAD_LS_T WC_RNG gRng;
  1548. #define GLOBAL_RNG &gRng
  1549. #else
  1550. #define GLOBAL_RNG NULL
  1551. #endif
  1552. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1553. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1554. defined(HAVE_ECC) || !defined(NO_DH) || \
  1555. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1556. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1557. #define BENCH_ASYM
  1558. #endif
  1559. #if defined(BENCH_ASYM)
  1560. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1561. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1562. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1563. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1564. static const char* bench_result_words2[][5] = {
  1565. #ifdef BENCH_MICROSECOND
  1566. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1567. for μsec */
  1568. #else
  1569. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1570. #endif
  1571. #ifndef NO_MULTIBYTE_PRINT
  1572. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1573. #endif
  1574. };
  1575. #endif
  1576. #endif
  1577. #ifdef WOLFSSL_CAAM
  1578. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1579. #ifdef WOLFSSL_SECO_CAAM
  1580. #define SECO_MAX_UPDATES 10000
  1581. #define SECO_BENCHMARK_NONCE 0x7777
  1582. #define SECO_KEY_STORE_ID 1
  1583. #endif
  1584. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1585. #else
  1586. #ifdef WC_USE_DEVID
  1587. static THREAD_LS_T int devId = WC_USE_DEVID;
  1588. #else
  1589. static THREAD_LS_T int devId = INVALID_DEVID;
  1590. #endif
  1591. #endif
  1592. /* Asynchronous helper macros */
  1593. #ifdef WC_ENABLE_BENCH_THREADING
  1594. typedef struct ThreadData {
  1595. pthread_t thread_id;
  1596. } ThreadData;
  1597. static ThreadData* g_threadData;
  1598. static volatile int g_threadCount;
  1599. #endif
  1600. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1601. #ifndef NO_HW_BENCH
  1602. #define BENCH_DEVID
  1603. #endif
  1604. #ifndef HAVE_RENESAS_SYNC
  1605. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1606. #else
  1607. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1608. #endif
  1609. #else
  1610. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1611. #endif
  1612. #ifdef WOLFSSL_ASYNC_CRYPT
  1613. static WOLF_EVENT_QUEUE eventQueue;
  1614. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1615. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1616. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1617. int callAgain, int* times, int limit, int* pending)
  1618. {
  1619. int allowNext = 0;
  1620. /* this state can be set from a different thread */
  1621. WOLF_EVENT_STATE state = asyncDev->event.state;
  1622. /* if algo doesn't require calling again then use this flow */
  1623. if (state == WOLF_EVENT_STATE_DONE) {
  1624. if (callAgain) {
  1625. /* needs called again, so allow it and handle completion in
  1626. * bench_async_handle */
  1627. allowNext = 1;
  1628. }
  1629. else {
  1630. *ret = asyncDev->event.ret;
  1631. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1632. (*times)++;
  1633. if (*pending > 0) /* to support case where async blocks */
  1634. (*pending)--;
  1635. if ((*times + *pending) < limit)
  1636. allowNext = 1;
  1637. }
  1638. }
  1639. /* if slot is available and we haven't reached limit, start another */
  1640. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1641. allowNext = 1;
  1642. }
  1643. return allowNext;
  1644. }
  1645. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1646. int callAgain, int* times, int* pending)
  1647. {
  1648. WOLF_EVENT_STATE state = asyncDev->event.state;
  1649. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1650. if (state == WOLF_EVENT_STATE_DONE) {
  1651. *ret = asyncDev->event.ret;
  1652. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1653. (*times)++;
  1654. (*pending)--;
  1655. }
  1656. else {
  1657. (*pending)++;
  1658. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1659. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1660. }
  1661. }
  1662. else if (*ret >= 0) {
  1663. *ret = asyncDev->event.ret;
  1664. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1665. (*times)++;
  1666. if (*pending > 0) /* to support case where async blocks */
  1667. (*pending)--;
  1668. }
  1669. return (*ret >= 0) ? 1 : 0;
  1670. }
  1671. static WC_INLINE int bench_async_poll(int* pending)
  1672. {
  1673. int ret, asyncDone = 0;
  1674. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1675. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1676. if (ret != 0) {
  1677. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1678. return ret;
  1679. }
  1680. if (asyncDone == 0) {
  1681. #ifndef WC_NO_ASYNC_THREADING
  1682. /* give time to other threads */
  1683. wc_AsyncThreadYield();
  1684. #endif
  1685. }
  1686. (void)pending;
  1687. return asyncDone;
  1688. }
  1689. #else
  1690. #define BENCH_MAX_PENDING 1
  1691. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1692. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1693. int callAgain, int* times, int limit, int* pending)
  1694. {
  1695. (void)ret;
  1696. (void)asyncDev;
  1697. (void)callAgain;
  1698. (void)times;
  1699. (void)limit;
  1700. (void)pending;
  1701. return 1;
  1702. }
  1703. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1704. int callAgain, int* times, int* pending)
  1705. {
  1706. (void)asyncDev;
  1707. (void)callAgain;
  1708. (void)pending;
  1709. if (*ret >= 0) {
  1710. /* operation completed */
  1711. (*times)++;
  1712. return 1;
  1713. }
  1714. return 0;
  1715. }
  1716. #define bench_async_poll(p) WC_DO_NOTHING
  1717. #endif /* WOLFSSL_ASYNC_CRYPT */
  1718. /* maximum runtime for each benchmark */
  1719. #ifndef BENCH_MIN_RUNTIME_SEC
  1720. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1721. #endif
  1722. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1723. #define AES_AUTH_TAG_SZ 16
  1724. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1725. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1726. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1727. #if !defined(NO_MAIN_DRIVER)
  1728. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1729. #else
  1730. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1731. #endif
  1732. #endif
  1733. #define AES_AAD_STRING(s) \
  1734. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1735. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1736. enum en_aad_options {
  1737. AAD_SIZE_DEFAULT = 0x1U,
  1738. AAD_SIZE_ZERO = 0x2U,
  1739. AAD_SIZE_CUSTOM = 0x4U,
  1740. };
  1741. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1742. static word32 aes_aad_size = 0;
  1743. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1744. {
  1745. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1746. word32 options = aes_aad_options;
  1747. while(options) {
  1748. if (options & AAD_SIZE_DEFAULT) {
  1749. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1750. options &= ~(word32)AAD_SIZE_DEFAULT;
  1751. }
  1752. else if (options & AAD_SIZE_ZERO) {
  1753. aesAuthAddSz = 0;
  1754. options &= ~(word32)AAD_SIZE_ZERO;
  1755. }
  1756. else if (options & AAD_SIZE_CUSTOM) {
  1757. aesAuthAddSz = aes_aad_size;
  1758. options &= ~(word32)AAD_SIZE_CUSTOM;
  1759. }
  1760. fn(i);
  1761. aesAuthAddSz = aesAuthAddSz_orig;
  1762. }
  1763. }
  1764. #endif
  1765. #ifndef BENCH_CIPHER_ADD
  1766. #define BENCH_CIPHER_ADD 0
  1767. #endif
  1768. /* use kB instead of mB for embedded benchmarking */
  1769. #ifdef BENCH_EMBEDDED
  1770. #ifndef BENCH_NTIMES
  1771. #define BENCH_NTIMES 2
  1772. #endif
  1773. #ifndef BENCH_AGREETIMES
  1774. #define BENCH_AGREETIMES 2
  1775. #endif
  1776. enum BenchmarkBounds {
  1777. scryptCnt = 1,
  1778. ntimes = BENCH_NTIMES,
  1779. genTimes = BENCH_MAX_PENDING,
  1780. agreeTimes = BENCH_AGREETIMES
  1781. };
  1782. /* how many kB to test (en/de)cryption */
  1783. #define NUM_BLOCKS 25
  1784. #define BENCH_SIZE (1024uL)
  1785. #else
  1786. #ifndef BENCH_NTIMES
  1787. #define BENCH_NTIMES 100
  1788. #endif
  1789. #ifndef BENCH_AGREETIMES
  1790. #define BENCH_AGREETIMES 100
  1791. #endif
  1792. enum BenchmarkBounds {
  1793. scryptCnt = 10,
  1794. ntimes = BENCH_NTIMES,
  1795. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1796. agreeTimes = BENCH_AGREETIMES
  1797. };
  1798. /* how many megs to test (en/de)cryption */
  1799. #define NUM_BLOCKS 5
  1800. #define BENCH_SIZE (1024*1024uL)
  1801. #endif
  1802. static int numBlocks = NUM_BLOCKS;
  1803. static word32 bench_size = BENCH_SIZE;
  1804. static int base2 = 1;
  1805. static int digest_stream = 1;
  1806. #ifdef HAVE_CHACHA
  1807. static int encrypt_only = 0;
  1808. #endif
  1809. #ifdef HAVE_AES_CBC
  1810. static int cipher_same_buffer = 0;
  1811. #endif
  1812. #ifdef MULTI_VALUE_STATISTICS
  1813. static int minimum_runs = 0;
  1814. #endif
  1815. #ifndef NO_RSA
  1816. /* Don't measure RSA sign/verify by default */
  1817. static int rsa_sign_verify = 0;
  1818. #endif
  1819. #ifndef NO_DH
  1820. /* Use the FFDHE parameters */
  1821. static int use_ffdhe = 0;
  1822. #endif
  1823. /* Don't print out in CSV format by default */
  1824. static int csv_format = 0;
  1825. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1826. /* Versal PLM maybe prints an error message to the same console.
  1827. * In order to not mix those outputs up, sleep a little while
  1828. * before erroring out.
  1829. */
  1830. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1831. #else
  1832. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1833. #endif
  1834. /* globals for cipher tests */
  1835. static THREAD_LS_T byte* bench_plain = NULL;
  1836. static THREAD_LS_T byte* bench_cipher = NULL;
  1837. #ifndef NO_FILESYSTEM
  1838. static THREAD_LS_T char* hash_input = NULL;
  1839. static THREAD_LS_T char* cipher_input = NULL;
  1840. #endif
  1841. static const XGEN_ALIGN byte bench_key_buf[] =
  1842. {
  1843. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1844. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1845. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1846. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1847. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1848. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1849. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1850. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1851. };
  1852. static const XGEN_ALIGN byte bench_iv_buf[] =
  1853. {
  1854. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1855. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1856. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1857. };
  1858. static THREAD_LS_T byte* bench_key = NULL;
  1859. static THREAD_LS_T byte* bench_iv = NULL;
  1860. #ifdef HAVE_RENESAS_SYNC
  1861. static THREAD_LS_T byte* bench_key1 = NULL;
  1862. static THREAD_LS_T byte* bench_key2 = NULL;
  1863. #endif
  1864. #ifdef WOLFSSL_STATIC_MEMORY
  1865. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1866. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1867. #elif defined(BENCH_EMBEDDED)
  1868. static byte gBenchMemory[50000];
  1869. #else
  1870. static byte gBenchMemory[400000];
  1871. #endif
  1872. #endif
  1873. /* This code handles cases with systems where static (non cost) ram variables
  1874. aren't properly initialized with data */
  1875. static void benchmark_static_init(int force)
  1876. {
  1877. static int gBenchStaticInit = 0;
  1878. if (gBenchStaticInit == 0 || force) {
  1879. gBenchStaticInit = 1;
  1880. /* Init static variables */
  1881. numBlocks = NUM_BLOCKS;
  1882. bench_size = BENCH_SIZE;
  1883. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1884. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1885. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1886. aes_aad_size = 0;
  1887. #endif
  1888. base2 = 1;
  1889. digest_stream = 1;
  1890. #ifdef MULTI_VALUE_STATISTICS
  1891. minimum_runs = 0;
  1892. #endif
  1893. bench_all = 1;
  1894. bench_cipher_algs = 0;
  1895. bench_digest_algs = 0;
  1896. bench_mac_algs = 0;
  1897. bench_kdf_algs = 0;
  1898. bench_asym_algs = 0;
  1899. bench_pq_asym_algs = 0;
  1900. bench_other_algs = 0;
  1901. bench_pq_hash_sig_algs = 0;
  1902. csv_format = 0;
  1903. }
  1904. }
  1905. /*****************************************************************************/
  1906. /* Begin Stats Functions */
  1907. /*****************************************************************************/
  1908. typedef enum bench_stat_type {
  1909. BENCH_STAT_ASYM,
  1910. BENCH_STAT_SYM,
  1911. BENCH_STAT_IGNORE,
  1912. } bench_stat_type_t;
  1913. #ifdef WC_BENCH_TRACK_STATS
  1914. static int gPrintStats = 0;
  1915. #ifdef WC_ENABLE_BENCH_THREADING
  1916. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1917. #endif
  1918. #ifndef BENCH_MAX_NAME_SZ
  1919. #define BENCH_MAX_NAME_SZ 24
  1920. #endif
  1921. typedef struct bench_stats {
  1922. struct bench_stats* next;
  1923. struct bench_stats* prev;
  1924. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1925. const char* desc;
  1926. double perfsec;
  1927. int strength;
  1928. int useDeviceID;
  1929. int finishCount;
  1930. bench_stat_type_t type;
  1931. int lastRet;
  1932. const char* perftype;
  1933. } bench_stats_t;
  1934. static bench_stats_t* bench_stats_head;
  1935. static bench_stats_t* bench_stats_tail;
  1936. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1937. const char* algo, int strength, const char* desc, int useDeviceID,
  1938. double perfsec, const char* perftype, int ret)
  1939. {
  1940. bench_stats_t* bstat = NULL;
  1941. #ifdef WC_ENABLE_BENCH_THREADING
  1942. /* protect bench_stats_head and bench_stats_tail access */
  1943. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  1944. #endif
  1945. if (algo != NULL) {
  1946. /* locate existing in list */
  1947. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  1948. /* match based on algo, strength and desc */
  1949. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  1950. bstat->strength == strength &&
  1951. bstat->desc == desc &&
  1952. bstat->useDeviceID == useDeviceID) {
  1953. break;
  1954. }
  1955. }
  1956. }
  1957. if (bstat == NULL) {
  1958. /* allocate new and put on list */
  1959. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  1960. DYNAMIC_TYPE_INFO);
  1961. if (bstat) {
  1962. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  1963. /* add to list */
  1964. bstat->next = NULL;
  1965. if (bench_stats_tail == NULL) {
  1966. bench_stats_head = bstat;
  1967. }
  1968. else {
  1969. bench_stats_tail->next = bstat;
  1970. bstat->prev = bench_stats_tail;
  1971. }
  1972. bench_stats_tail = bstat; /* add to the end either way */
  1973. }
  1974. }
  1975. if (bstat) {
  1976. bstat->type = type;
  1977. if (algo != NULL)
  1978. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  1979. bstat->strength = strength;
  1980. bstat->desc = desc;
  1981. bstat->useDeviceID = useDeviceID;
  1982. bstat->perfsec += perfsec;
  1983. bstat->finishCount++;
  1984. bstat->perftype = perftype;
  1985. if (bstat->lastRet > ret)
  1986. bstat->lastRet = ret; /* track last error */
  1987. }
  1988. #ifdef WC_ENABLE_BENCH_THREADING
  1989. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  1990. #endif
  1991. return bstat;
  1992. }
  1993. void bench_stats_print(void)
  1994. {
  1995. bench_stats_t* bstat;
  1996. int digits;
  1997. #ifdef WC_ENABLE_BENCH_THREADING
  1998. /* protect bench_stats_head and bench_stats_tail access */
  1999. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2000. #endif
  2001. #ifdef BENCH_MICROSECOND
  2002. digits = 5;
  2003. #else
  2004. digits = 3;
  2005. #endif
  2006. for (bstat = bench_stats_head; bstat != NULL; ) {
  2007. if (bstat->type == BENCH_STAT_SYM) {
  2008. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2009. "\n", bstat->desc,
  2010. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2011. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2012. base2 ? "MB" : "mB");
  2013. }
  2014. else {
  2015. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2016. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2017. bstat->algo, bstat->strength, bstat->desc,
  2018. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2019. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2020. }
  2021. bstat = bstat->next;
  2022. }
  2023. #ifdef WC_ENABLE_BENCH_THREADING
  2024. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2025. #endif
  2026. }
  2027. #endif /* WC_BENCH_TRACK_STATS */
  2028. static WC_INLINE void bench_stats_init(void)
  2029. {
  2030. #ifdef WC_BENCH_TRACK_STATS
  2031. bench_stats_head = NULL;
  2032. bench_stats_tail = NULL;
  2033. #endif
  2034. INIT_CYCLE_COUNTER
  2035. }
  2036. static WC_INLINE void bench_stats_start(int* count, double* start)
  2037. {
  2038. *count = 0;
  2039. *start = current_time(1);
  2040. #ifdef WOLFSSL_ESPIDF
  2041. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2042. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu, start=" FLT_FMT,
  2043. total_cycles, FLT_FMT_ARGS(*start) );
  2044. #endif
  2045. BEGIN_ESP_CYCLES
  2046. #else
  2047. BEGIN_INTEL_CYCLES
  2048. #endif
  2049. }
  2050. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2051. #define bench_stats_start(count, start) do { \
  2052. SAVE_VECTOR_REGISTERS(pr_err( \
  2053. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2054. return; ); \
  2055. bench_stats_start(count, start); \
  2056. } while (0)
  2057. #endif
  2058. static WC_INLINE int bench_stats_check(double start)
  2059. {
  2060. int ret = 0;
  2061. double this_current_time;
  2062. this_current_time = current_time(0); /* get the timestamp, no reset */
  2063. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2064. ESP_LOGV(TAG, "bench_stats_check: Current time %f, start %f",
  2065. this_current_time, start );
  2066. #endif
  2067. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2068. #ifdef BENCH_MICROSECOND
  2069. * 1000000
  2070. #endif
  2071. );
  2072. return ret;
  2073. }
  2074. /* return text for units and scale the value of blocks as needed */
  2075. static const char* get_blocktype(double* blocks)
  2076. {
  2077. const char* rt;
  2078. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2079. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2080. #undef WOLFSSL_FIXED_UNIT
  2081. #define WOLFSSL_FIXED_UNIT "GB"
  2082. *blocks /= (1024UL * 1024UL * 1024UL);
  2083. rt = "GiB";
  2084. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2085. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2086. #undef WOLFSSL_FIXED_UNIT
  2087. #define WOLFSSL_FIXED_UNIT "MB"
  2088. *blocks /= (1024UL * 1024UL);
  2089. rt = "MiB";
  2090. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2091. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2092. #undef WOLFSSL_FIXED_UNIT
  2093. #define WOLFSSL_FIXED_UNIT "KB"
  2094. *blocks /= 1024;
  2095. rt = "KiB";
  2096. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2097. #undef WOLFSSL_FIXED_UNIT
  2098. #define WOLFSSL_FIXED_UNIT "bytes"
  2099. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2100. rt = "bytes";
  2101. #else
  2102. /* If no user-specified, auto-scale each metric (results vary).
  2103. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2104. if (*blocks > (1024UL * 1024UL)) {
  2105. *blocks /= (1024UL * 1024UL);
  2106. rt = "MiB";
  2107. }
  2108. else if (*blocks > 1024) {
  2109. *blocks /= 1024;
  2110. rt = "KiB";
  2111. }
  2112. else {
  2113. rt = "bytes";
  2114. }
  2115. #endif
  2116. return rt;
  2117. }
  2118. /* return text for units and scale the value of blocks as needed for base2 */
  2119. static const char* get_blocktype_base10(double* blocks)
  2120. {
  2121. const char* rt;
  2122. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2123. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2124. *blocks /= (1000UL * 1000UL * 1000UL);
  2125. rt = "GB";
  2126. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2127. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2128. *blocks /= (1000UL * 1000UL);
  2129. rt = "MB";
  2130. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2131. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2132. *blocks /= (1000UL);
  2133. rt = "KB";
  2134. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2135. (void)(*blocks); /* no adjustment, just appease compiler */
  2136. rt = "bytes";
  2137. #else
  2138. /* If not user-specified, auto-scale each metric (results vary).
  2139. * Determine if we should show as KB or MB or bytes */
  2140. if (*blocks > (1000UL * 1000UL)) {
  2141. *blocks /= (1000UL * 1000UL);
  2142. rt = "MB";
  2143. }
  2144. else if (*blocks > 1000) {
  2145. *blocks /= 1000; /* make KB */
  2146. rt = "KB";
  2147. }
  2148. else {
  2149. rt = "bytes";
  2150. }
  2151. #endif
  2152. return rt;
  2153. }
  2154. #ifdef MULTI_VALUE_STATISTICS
  2155. static double wc_sqroot(double in)
  2156. {
  2157. /* do 32 iterations for the sqroot */
  2158. int iter = 32;
  2159. double root = in/3.0;
  2160. if (in < 0.0)
  2161. return -1;
  2162. for (int i=0; i < iter; i++)
  2163. root = (root + in / root) / 2.0;
  2164. return root;
  2165. }
  2166. static void bench_multi_value_stats(double max, double min, double sum,
  2167. double squareSum, int runs)
  2168. {
  2169. double mean = 0;
  2170. double sd = 0;
  2171. char msg[WC_BENCH_MAX_LINE_LEN];
  2172. const char** word = bench_result_words3[lng_index];
  2173. XMEMSET(msg, 0, sizeof(msg));
  2174. mean = sum / runs;
  2175. /* Calculating standard deviation */
  2176. sd = (squareSum / runs) - (mean * mean);
  2177. sd = wc_sqroot(sd);
  2178. if (csv_format == 1) {
  2179. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2180. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2181. FLT_FMT_PREC2_ARGS(3, 3, max),
  2182. FLT_FMT_PREC2_ARGS(3, 3, min),
  2183. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2184. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2185. }
  2186. else{
  2187. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2188. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2189. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2190. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2191. WOLFSSL_FIXED_TIME_UNIT "\n",
  2192. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2193. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2194. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2195. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2196. }
  2197. printf("%s", msg);
  2198. #ifndef WOLFSSL_SGX
  2199. XFFLUSH(stdout);
  2200. #endif
  2201. }
  2202. #endif
  2203. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2204. * except for AES direct that operates on AES_BLOCK_SIZE blocks */
  2205. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2206. int count, word32 countSz,
  2207. double start, int ret)
  2208. {
  2209. double total, persec = 0, blocks = (double)count;
  2210. const char* blockType;
  2211. char msg[WC_BENCH_MAX_LINE_LEN];
  2212. const char** word = bench_result_words1[lng_index];
  2213. static int sym_header_printed = 0;
  2214. XMEMSET(msg, 0, sizeof(msg));
  2215. #ifdef WOLFSSL_ESPIDF
  2216. END_ESP_CYCLES
  2217. #else
  2218. END_INTEL_CYCLES
  2219. #endif
  2220. total = current_time(0) - start;
  2221. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2222. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2223. #endif
  2224. #ifdef LINUX_RUSAGE_UTIME
  2225. check_for_excessive_stime(desc, "");
  2226. #endif
  2227. /* calculate actual bytes */
  2228. blocks *= countSz;
  2229. if (csv_format == 1) {
  2230. /* only print out header once */
  2231. if (sym_header_printed == 0) {
  2232. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2233. /* machine parseable CSV */
  2234. #ifdef HAVE_GET_CYCLES
  2235. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2236. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2237. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2238. ",cycles_total,Cycles per byte,");
  2239. #else
  2240. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2241. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2242. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2243. ",cycles_total,");
  2244. #endif
  2245. #else
  2246. /* normal CSV */
  2247. #ifdef BENCH_DEVID
  2248. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2249. #else
  2250. #define BENCH_DEVID_COLUMN_HEADER
  2251. #endif
  2252. #ifdef HAVE_GET_CYCLES
  2253. printf("\n\nSymmetric Ciphers:\n\n");
  2254. printf("Algorithm,"
  2255. BENCH_DEVID_COLUMN_HEADER
  2256. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2257. ",Cycles per byte,");
  2258. #else
  2259. printf("\n\nSymmetric Ciphers:\n\n");
  2260. printf("Algorithm,"
  2261. BENCH_DEVID_COLUMN_HEADER
  2262. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2263. #endif
  2264. #endif
  2265. #ifdef MULTI_VALUE_STATISTICS
  2266. printf("max duration,min duration,mean duration,sd,\n");
  2267. #else
  2268. printf("\n");
  2269. #endif
  2270. sym_header_printed = 1;
  2271. }
  2272. }
  2273. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2274. * note that the blockType text is assigned AND the blocks param is scaled.
  2275. */
  2276. if (base2) {
  2277. blockType = get_blocktype(&blocks);
  2278. }
  2279. else {
  2280. blockType = get_blocktype_base10(&blocks);
  2281. }
  2282. /* calculate blocks per second */
  2283. if (total > 0) {
  2284. persec = (1 / total) * blocks;
  2285. }
  2286. SLEEP_ON_ERROR(ret);
  2287. /* format and print to terminal */
  2288. if (csv_format == 1) {
  2289. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2290. #ifdef WOLFSSL_ESPIDF
  2291. unsigned long bytes_processed =
  2292. (unsigned long)count * (unsigned long)countSz;
  2293. #else
  2294. word64 bytes_processed = (word64)count * (word64)countSz;
  2295. #endif
  2296. /* note this codepath brings in all the fields from the non-CSV case. */
  2297. #ifdef WOLFSSL_ESPIDF
  2298. #ifdef HAVE_GET_CYCLES
  2299. (void)XSNPRINTF(msg, sizeof(msg),
  2300. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2301. BENCH_DEVID_GET_NAME(useDeviceID),
  2302. bytes_processed, FLT_FMT_ARGS(total),
  2303. FLT_FMT_ARGS(persec),
  2304. (long unsigned int) total_cycles);
  2305. #else
  2306. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2307. #endif
  2308. /* implement other architectures here */
  2309. #else
  2310. #ifdef HAVE_GET_CYCLES
  2311. (void)XSNPRINTF(msg, sizeof(msg),
  2312. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2313. BENCH_DEVID_GET_NAME(useDeviceID),
  2314. bytes_processed, FLT_FMT_ARGS(total),
  2315. FLT_FMT_ARGS(persec), total_cycles);
  2316. #else
  2317. (void)XSNPRINTF(msg, sizeof(msg),
  2318. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2319. BENCH_DEVID_GET_NAME(useDeviceID),
  2320. bytes_processed, FLT_FMT_ARGS(total),
  2321. FLT_FMT_ARGS(persec));
  2322. #endif
  2323. #endif
  2324. #elif defined(BENCH_DEVID)
  2325. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2326. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2327. #else
  2328. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2329. FLT_FMT_ARGS(persec));
  2330. #endif
  2331. #ifdef WOLFSSL_ESPIDF
  2332. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2333. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2334. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2335. total_cycles);
  2336. #endif
  2337. /* implement other cycle counters here */
  2338. #else
  2339. /* the default cycle counter is Intel */
  2340. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2341. #endif
  2342. } /* if (csv_format == 1) */
  2343. else {
  2344. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2345. #ifdef HAVE_GET_CYCLES
  2346. (void)XSNPRINTF(msg, sizeof(msg),
  2347. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2348. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2349. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2350. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2351. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2352. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2353. (unsigned long) total_cycles);
  2354. #else
  2355. (void)XSNPRINTF(msg, sizeof(msg),
  2356. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2357. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2358. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2359. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2360. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2361. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2362. #endif /* HAVE_GET_CYCLES */
  2363. #else
  2364. (void)XSNPRINTF(msg, sizeof(msg),
  2365. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2366. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2367. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2368. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2369. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2370. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2371. #endif
  2372. #ifdef WOLFSSL_ESPIDF
  2373. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2374. /* implement other architecture cycle counters here */
  2375. #else
  2376. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2377. #endif
  2378. } /* not CSV format */
  2379. printf("%s", msg);
  2380. /* show errors */
  2381. if (ret < 0) {
  2382. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2383. }
  2384. #ifndef WOLFSSL_SGX
  2385. XFFLUSH(stdout);
  2386. #endif
  2387. #ifdef WC_BENCH_TRACK_STATS
  2388. /* Add to thread stats */
  2389. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2390. blockType, ret);
  2391. #endif
  2392. (void)useDeviceID;
  2393. (void)ret;
  2394. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2395. RESTORE_VECTOR_REGISTERS();
  2396. #endif
  2397. TEST_SLEEP();
  2398. } /* bench_stats_sym_finish */
  2399. #ifdef BENCH_ASYM
  2400. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2401. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2402. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2403. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  2404. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2405. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2406. double start, int ret)
  2407. {
  2408. double total, each = 0, opsSec, milliEach;
  2409. const char **word = bench_result_words2[lng_index];
  2410. #ifdef WC_BENCH_TRACK_STATS
  2411. const char* kOpsSec = "Ops/Sec";
  2412. #endif
  2413. char msg[256];
  2414. static int asym_header_printed = 0;
  2415. #ifdef BENCH_MICROSECOND
  2416. const int digits = 5;
  2417. #else
  2418. const int digits = 3;
  2419. #endif
  2420. XMEMSET(msg, 0, sizeof(msg));
  2421. total = current_time(0) - start;
  2422. #ifdef LINUX_RUSAGE_UTIME
  2423. check_for_excessive_stime(desc, desc_extra);
  2424. #endif
  2425. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2426. #ifdef WOLFSSL_ESPIDF
  2427. END_ESP_CYCLES
  2428. #else
  2429. END_INTEL_CYCLES
  2430. #endif
  2431. #endif
  2432. /* some sanity checks on the final numbers */
  2433. if (count > 0) {
  2434. each = total / count; /* per second */
  2435. }
  2436. else {
  2437. count = 0;
  2438. each = 0;
  2439. }
  2440. if (total > 0) {
  2441. opsSec = count / total; /* ops second */
  2442. }
  2443. else {
  2444. opsSec = 0;
  2445. }
  2446. #ifdef BENCH_MICROSECOND
  2447. milliEach = each / 1000; /* milliseconds */
  2448. #else
  2449. milliEach = each * 1000; /* milliseconds */
  2450. #endif
  2451. SLEEP_ON_ERROR(ret);
  2452. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2453. (void)milliEach;
  2454. /* format and print to terminal */
  2455. if (csv_format == 1) {
  2456. /* only print out header once */
  2457. if (asym_header_printed == 0) {
  2458. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2459. #ifdef HAVE_GET_CYCLES
  2460. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2461. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2462. "ecs,cycles,cycles/op,");
  2463. #else
  2464. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2465. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2466. "ecs,");
  2467. #endif
  2468. #else
  2469. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2470. printf("%sAlgorithm,key size,operation,ops/"
  2471. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2472. #endif
  2473. printf("max duration,min duration,mean duration,sd,\n");
  2474. asym_header_printed = 1;
  2475. }
  2476. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2477. #ifdef HAVE_GET_CYCLES
  2478. (void)XSNPRINTF(msg, sizeof(msg),
  2479. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2480. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2481. algo, strength, desc, desc_extra,
  2482. FLT_FMT_PREC_ARGS(digits, opsSec),
  2483. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2484. FLT_FMT_PREC_ARGS(6,
  2485. (double)total_cycles / (double)count));
  2486. #else
  2487. (void)XSNPRINTF(msg, sizeof(msg),
  2488. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2489. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2490. algo, strength, desc, desc_extra,
  2491. FLT_FMT_PREC_ARGS(digits, opsSec),
  2492. count, FLT_FMT_ARGS(total));
  2493. #endif
  2494. #else
  2495. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2496. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2497. algo, strength, desc, desc_extra,
  2498. FLT_FMT_PREC_ARGS(digits, opsSec));
  2499. #endif
  2500. } /* if (csv_format == 1) */
  2501. else {
  2502. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2503. #ifdef HAVE_GET_CYCLES
  2504. (void)XSNPRINTF(msg, sizeof(msg),
  2505. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2506. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2507. algo, strength, desc, desc_extra,
  2508. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2509. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2510. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2511. (unsigned long)total_cycles);
  2512. #else
  2513. (void)XSNPRINTF(msg, sizeof(msg),
  2514. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2515. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2516. algo, strength, desc, desc_extra,
  2517. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2518. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2519. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2520. #endif /* HAVE_GET_CYCLES */
  2521. #else
  2522. (void)XSNPRINTF(msg, sizeof(msg),
  2523. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2524. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2525. algo, strength, desc, desc_extra,
  2526. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2527. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2528. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2529. #endif
  2530. }
  2531. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2532. /* format and print to terminal */
  2533. if (csv_format == 1) {
  2534. /* only print out header once */
  2535. if (asym_header_printed == 0) {
  2536. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2537. #ifdef HAVE_GET_CYCLES
  2538. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2539. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2540. "ecs,cycles,cycles/op,");
  2541. #else
  2542. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2543. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2544. "ecs,");
  2545. #endif
  2546. #else
  2547. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2548. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2549. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2550. #endif
  2551. printf("\n");
  2552. asym_header_printed = 1;
  2553. }
  2554. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2555. #ifdef HAVE_GET_CYCLES
  2556. (void)XSNPRINTF(msg, sizeof(msg),
  2557. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2558. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2559. algo, strength, desc, desc_extra,
  2560. FLT_FMT_PREC_ARGS(3, milliEach),
  2561. FLT_FMT_PREC_ARGS(digits, opsSec),
  2562. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2563. FLT_FMT_PREC_ARGS(6,
  2564. (double)total_cycles / (double)count));
  2565. #else
  2566. (void)XSNPRINTF(msg, sizeof(msg),
  2567. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2568. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2569. algo, strength, desc, desc_extra,
  2570. FLT_FMT_PREC_ARGS(3, milliEach),
  2571. FLT_FMT_PREC_ARGS(digits, opsSec),
  2572. count, FLT_FMT_ARGS(total));
  2573. #endif
  2574. #else
  2575. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2576. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2577. algo, strength, desc, desc_extra,
  2578. FLT_FMT_PREC_ARGS(3, milliEach),
  2579. FLT_FMT_PREC_ARGS(digits, opsSec));
  2580. #endif
  2581. } /* if (csv_format == 1) */
  2582. else {
  2583. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2584. #ifdef HAVE_GET_CYCLES
  2585. (void)XSNPRINTF(msg, sizeof(msg),
  2586. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2587. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2588. STATS_CLAUSE_SEPARATOR,
  2589. algo, strength, desc, desc_extra,
  2590. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2591. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2592. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2593. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2594. (unsigned long)total_cycles);
  2595. #else
  2596. (void)XSNPRINTF(msg, sizeof(msg),
  2597. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2598. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2599. STATS_CLAUSE_SEPARATOR,
  2600. algo, strength, desc, desc_extra,
  2601. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2602. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2603. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2604. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2605. #endif /* HAVE_GET_CYCLES */
  2606. #else
  2607. (void)XSNPRINTF(msg, sizeof(msg),
  2608. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2609. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2610. STATS_CLAUSE_SEPARATOR,
  2611. algo, strength, desc, desc_extra,
  2612. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2613. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2614. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2615. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2616. #endif
  2617. }
  2618. #endif /* MULTI_VALUE_STATISTICS */
  2619. printf("%s", msg);
  2620. /* show errors */
  2621. if (ret < 0) {
  2622. printf("%sBenchmark %s %s %d failed: %d\n",
  2623. err_prefix, algo, desc, strength, ret);
  2624. }
  2625. #ifndef WOLFSSL_SGX
  2626. XFFLUSH(stdout);
  2627. #endif
  2628. #ifdef WC_BENCH_TRACK_STATS
  2629. /* Add to thread stats */
  2630. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2631. kOpsSec, ret);
  2632. #endif
  2633. (void)useDeviceID;
  2634. (void)ret;
  2635. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2636. RESTORE_VECTOR_REGISTERS();
  2637. #endif
  2638. TEST_SLEEP();
  2639. } /* bench_stats_asym_finish_ex */
  2640. static void bench_stats_asym_finish(const char* algo, int strength,
  2641. const char* desc, int useDeviceID, int count, double start, int ret)
  2642. {
  2643. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2644. start, ret);
  2645. }
  2646. #endif
  2647. #endif /* BENCH_ASYM */
  2648. static WC_INLINE void bench_stats_free(void)
  2649. {
  2650. #ifdef WC_BENCH_TRACK_STATS
  2651. bench_stats_t* bstat;
  2652. for (bstat = bench_stats_head; bstat != NULL; ) {
  2653. bench_stats_t* next = bstat->next;
  2654. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2655. bstat = next;
  2656. }
  2657. bench_stats_head = NULL;
  2658. bench_stats_tail = NULL;
  2659. #endif
  2660. }
  2661. /*****************************************************************************/
  2662. /* End Stats Functions */
  2663. /*****************************************************************************/
  2664. static void* benchmarks_do(void* args)
  2665. {
  2666. long bench_buf_size;
  2667. #ifdef WOLFSSL_ASYNC_CRYPT
  2668. #ifndef WC_NO_ASYNC_THREADING
  2669. ThreadData* threadData = (ThreadData*)args;
  2670. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2671. #else
  2672. if (wolfAsync_DevOpen(&devId) < 0)
  2673. #endif
  2674. {
  2675. printf("%sAsync device open failed\n%sRunning without async\n",
  2676. err_prefix, err_prefix);
  2677. }
  2678. #endif /* WOLFSSL_ASYNC_CRYPT */
  2679. (void)args;
  2680. #ifdef WOLFSSL_ASYNC_CRYPT
  2681. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2682. printf("%sAsync event queue init failure!\n", err_prefix);
  2683. }
  2684. #endif
  2685. #ifdef WOLF_CRYPTO_CB
  2686. #ifdef HAVE_INTEL_QA_SYNC
  2687. devId = wc_CryptoCb_InitIntelQa();
  2688. if (devId == INVALID_DEVID) {
  2689. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2690. }
  2691. #endif
  2692. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2693. devId = wc_CryptoCb_InitOcteon();
  2694. if (devId == INVALID_DEVID) {
  2695. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2696. }
  2697. #endif
  2698. #ifdef HAVE_RENESAS_SYNC
  2699. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2700. if (devId == INVALID_DEVID) {
  2701. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2702. }
  2703. #endif
  2704. #endif
  2705. #if defined(HAVE_LOCAL_RNG)
  2706. {
  2707. int rngRet;
  2708. #ifndef HAVE_FIPS
  2709. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2710. #else
  2711. rngRet = wc_InitRng(&gRng);
  2712. #endif
  2713. if (rngRet < 0) {
  2714. printf("%sInitRNG failed\n", err_prefix);
  2715. return NULL;
  2716. }
  2717. }
  2718. #endif
  2719. /* setup bench plain, cipher, key and iv globals */
  2720. /* make sure bench buffer is multiple of 16 (AES block size) */
  2721. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2722. if (bench_buf_size % 16)
  2723. bench_buf_size += 16 - (bench_buf_size % 16);
  2724. #ifdef WOLFSSL_AFALG_XILINX_AES
  2725. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2726. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2727. #else
  2728. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2729. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2730. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2731. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2732. #endif
  2733. if (bench_plain == NULL || bench_cipher == NULL) {
  2734. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2735. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2736. bench_plain = bench_cipher = NULL;
  2737. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2738. goto exit;
  2739. }
  2740. #ifndef NO_FILESYSTEM
  2741. if (hash_input) {
  2742. size_t rawSz;
  2743. XFILE file;
  2744. file = XFOPEN(hash_input, "rb");
  2745. if (file == XBADFILE)
  2746. goto exit;
  2747. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2748. XFCLOSE(file);
  2749. goto exit;
  2750. }
  2751. bench_buf_size = XFTELL(file);
  2752. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2753. XFCLOSE(file);
  2754. goto exit;
  2755. }
  2756. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2757. rawSz = (size_t)bench_buf_size;
  2758. if (bench_buf_size % 16)
  2759. bench_buf_size += 16 - (bench_buf_size % 16);
  2760. bench_size = (word32)bench_buf_size;
  2761. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2762. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2763. if (bench_plain == NULL) {
  2764. XFCLOSE(file);
  2765. goto exit;
  2766. }
  2767. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2768. != rawSz) {
  2769. XFCLOSE(file);
  2770. goto exit;
  2771. }
  2772. XFCLOSE(file);
  2773. }
  2774. else {
  2775. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2776. }
  2777. if (cipher_input) {
  2778. size_t rawSz;
  2779. XFILE file;
  2780. file = XFOPEN(cipher_input, "rb");
  2781. if (file == XBADFILE)
  2782. goto exit;
  2783. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2784. XFCLOSE(file);
  2785. goto exit;
  2786. }
  2787. bench_buf_size = XFTELL(file);
  2788. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2789. XFCLOSE(file);
  2790. goto exit;
  2791. }
  2792. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2793. rawSz = (size_t)bench_buf_size;
  2794. if (bench_buf_size % 16)
  2795. bench_buf_size += 16 - (bench_buf_size % 16);
  2796. if (bench_size > (word32)bench_buf_size)
  2797. bench_size = (word32)bench_buf_size;
  2798. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2799. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2800. if (bench_cipher == NULL) {
  2801. XFCLOSE(file);
  2802. goto exit;
  2803. }
  2804. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2805. != rawSz) {
  2806. XFCLOSE(file);
  2807. goto exit;
  2808. }
  2809. XFCLOSE(file);
  2810. }
  2811. else {
  2812. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2813. }
  2814. #endif
  2815. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2816. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2817. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2818. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2819. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2820. if (bench_key == NULL || bench_iv == NULL) {
  2821. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2822. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2823. bench_key = bench_iv = NULL;
  2824. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2825. goto exit;
  2826. }
  2827. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2828. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2829. #elif defined(HAVE_RENESAS_SYNC)
  2830. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2831. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2832. bench_key = (byte*)bench_key_buf;
  2833. bench_iv = (byte*)bench_iv_buf;
  2834. #else
  2835. bench_key = (byte*)bench_key_buf;
  2836. bench_iv = (byte*)bench_iv_buf;
  2837. #endif
  2838. #ifndef WC_NO_RNG
  2839. if (bench_all || (bench_other_algs & BENCH_RNG))
  2840. bench_rng();
  2841. #endif /* WC_NO_RNG */
  2842. #ifndef NO_AES
  2843. #ifdef HAVE_AES_CBC
  2844. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2845. #ifndef NO_SW_BENCH
  2846. bench_aescbc(0);
  2847. #endif
  2848. #if defined(BENCH_DEVID)
  2849. bench_aescbc(1);
  2850. #endif
  2851. }
  2852. #endif
  2853. #ifdef HAVE_AESGCM
  2854. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2855. #ifndef NO_SW_BENCH
  2856. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2857. #endif
  2858. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2859. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2860. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) && \
  2861. !defined(NO_HW_BENCH)
  2862. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2863. #endif
  2864. #ifndef NO_SW_BENCH
  2865. bench_gmac(0);
  2866. #endif
  2867. #if defined(BENCH_DEVID)
  2868. bench_gmac(1);
  2869. #endif
  2870. }
  2871. #endif
  2872. #ifdef HAVE_AES_ECB
  2873. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2874. #ifndef NO_SW_BENCH
  2875. bench_aesecb(0);
  2876. #endif
  2877. #ifdef BENCH_DEVID
  2878. bench_aesecb(1);
  2879. #endif
  2880. }
  2881. #endif
  2882. #ifdef WOLFSSL_AES_XTS
  2883. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2884. bench_aesxts();
  2885. #endif
  2886. #ifdef WOLFSSL_AES_CFB
  2887. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2888. bench_aescfb();
  2889. #endif
  2890. #ifdef WOLFSSL_AES_OFB
  2891. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2892. bench_aesofb();
  2893. #endif
  2894. #ifdef WOLFSSL_AES_COUNTER
  2895. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2896. bench_aesctr(0);
  2897. #ifdef BENCH_DEVID
  2898. bench_aesctr(1);
  2899. #endif
  2900. }
  2901. #endif
  2902. #ifdef HAVE_AESCCM
  2903. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2904. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2905. #ifdef BENCH_DEVID
  2906. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2907. #endif
  2908. }
  2909. #endif
  2910. #ifdef WOLFSSL_AES_SIV
  2911. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2912. bench_aessiv();
  2913. #endif
  2914. #endif /* !NO_AES */
  2915. #ifdef HAVE_CAMELLIA
  2916. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2917. bench_camellia();
  2918. #endif
  2919. #ifdef WOLFSSL_SM4_CBC
  2920. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2921. bench_sm4_cbc();
  2922. #endif
  2923. #ifdef WOLFSSL_SM4_GCM
  2924. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2925. bench_sm4_gcm();
  2926. #endif
  2927. #ifdef WOLFSSL_SM4_CCM
  2928. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2929. bench_sm4_ccm();
  2930. #endif
  2931. #ifndef NO_RC4
  2932. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2933. #ifndef NO_SW_BENCH
  2934. bench_arc4(0);
  2935. #endif
  2936. #ifdef BENCH_DEVID
  2937. bench_arc4(1);
  2938. #endif
  2939. }
  2940. #endif
  2941. #ifdef HAVE_CHACHA
  2942. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  2943. bench_chacha();
  2944. #endif
  2945. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  2946. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  2947. bench_chacha20_poly1305_aead();
  2948. #endif
  2949. #ifndef NO_DES3
  2950. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  2951. #ifndef NO_SW_BENCH
  2952. bench_des(0);
  2953. #endif
  2954. #ifdef BENCH_DEVID
  2955. bench_des(1);
  2956. #endif
  2957. }
  2958. #endif
  2959. #ifndef NO_MD5
  2960. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  2961. #ifndef NO_SW_BENCH
  2962. bench_md5(0);
  2963. #endif
  2964. #ifdef BENCH_DEVID
  2965. bench_md5(1);
  2966. #endif
  2967. }
  2968. #endif
  2969. #ifdef HAVE_POLY1305
  2970. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  2971. bench_poly1305();
  2972. #endif
  2973. #ifndef NO_SHA
  2974. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  2975. #ifndef NO_SW_BENCH
  2976. bench_sha(0);
  2977. #endif
  2978. #ifdef BENCH_DEVID
  2979. bench_sha(1);
  2980. #endif
  2981. }
  2982. #endif
  2983. #ifdef WOLFSSL_SHA224
  2984. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  2985. #ifndef NO_SW_BENCH
  2986. bench_sha224(0);
  2987. #endif
  2988. #ifdef BENCH_DEVID
  2989. bench_sha224(1);
  2990. #endif
  2991. }
  2992. #endif
  2993. #ifndef NO_SHA256
  2994. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  2995. #ifndef NO_SW_BENCH
  2996. bench_sha256(0);
  2997. #endif
  2998. #ifdef BENCH_DEVID
  2999. bench_sha256(1);
  3000. #endif
  3001. }
  3002. #endif
  3003. #ifdef WOLFSSL_SHA384
  3004. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3005. #ifndef NO_SW_BENCH
  3006. bench_sha384(0);
  3007. #endif
  3008. #ifdef BENCH_DEVID
  3009. bench_sha384(1);
  3010. #endif
  3011. }
  3012. #endif
  3013. #ifdef WOLFSSL_SHA512
  3014. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3015. #ifndef NO_SW_BENCH
  3016. bench_sha512(0);
  3017. #endif
  3018. #ifdef BENCH_DEVID
  3019. bench_sha512(1);
  3020. #endif
  3021. }
  3022. #if !defined(WOLFSSL_NOSHA512_224) && \
  3023. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3024. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3025. #ifndef NO_SW_BENCH
  3026. bench_sha512_224(0);
  3027. #endif
  3028. #ifdef BENCH_DEVID
  3029. bench_sha512_224(1);
  3030. #endif
  3031. }
  3032. #endif /* WOLFSSL_NOSHA512_224 */
  3033. #if !defined(WOLFSSL_NOSHA512_256) && \
  3034. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3035. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3036. #ifndef NO_SW_BENCH
  3037. bench_sha512_256(0);
  3038. #endif
  3039. #ifdef BENCH_DEVID
  3040. bench_sha512_256(1);
  3041. #endif
  3042. }
  3043. #endif /* WOLFSSL_NOSHA512_256 */
  3044. #endif /* WOLFSSL_SHA512 */
  3045. #ifdef WOLFSSL_SHA3
  3046. #ifndef WOLFSSL_NOSHA3_224
  3047. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3048. #ifndef NO_SW_BENCH
  3049. bench_sha3_224(0);
  3050. #endif
  3051. #ifdef BENCH_DEVID
  3052. bench_sha3_224(1);
  3053. #endif
  3054. }
  3055. #endif /* WOLFSSL_NOSHA3_224 */
  3056. #ifndef WOLFSSL_NOSHA3_256
  3057. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3058. #ifndef NO_SW_BENCH
  3059. bench_sha3_256(0);
  3060. #endif
  3061. #ifdef BENCH_DEVID
  3062. bench_sha3_256(1);
  3063. #endif
  3064. }
  3065. #endif /* WOLFSSL_NOSHA3_256 */
  3066. #ifndef WOLFSSL_NOSHA3_384
  3067. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3068. #ifndef NO_SW_BENCH
  3069. bench_sha3_384(0);
  3070. #endif
  3071. #ifdef BENCH_DEVID
  3072. bench_sha3_384(1);
  3073. #endif
  3074. }
  3075. #endif /* WOLFSSL_NOSHA3_384 */
  3076. #ifndef WOLFSSL_NOSHA3_512
  3077. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3078. #ifndef NO_SW_BENCH
  3079. bench_sha3_512(0);
  3080. #endif
  3081. #ifdef BENCH_DEVID
  3082. bench_sha3_512(1);
  3083. #endif
  3084. }
  3085. #endif /* WOLFSSL_NOSHA3_512 */
  3086. #ifdef WOLFSSL_SHAKE128
  3087. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3088. #ifndef NO_SW_BENCH
  3089. bench_shake128(0);
  3090. #endif
  3091. #ifdef BENCH_DEVID
  3092. bench_shake128(1);
  3093. #endif
  3094. }
  3095. #endif /* WOLFSSL_SHAKE128 */
  3096. #ifdef WOLFSSL_SHAKE256
  3097. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3098. #ifndef NO_SW_BENCH
  3099. bench_shake256(0);
  3100. #endif
  3101. #ifdef BENCH_DEVID
  3102. bench_shake256(1);
  3103. #endif
  3104. }
  3105. #endif /* WOLFSSL_SHAKE256 */
  3106. #endif
  3107. #ifdef WOLFSSL_SM3
  3108. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3109. #ifndef NO_SW_BENCH
  3110. bench_sm3(0);
  3111. #endif
  3112. #ifdef BENCH_DEVID
  3113. bench_sm3(1);
  3114. #endif
  3115. }
  3116. #endif
  3117. #ifdef WOLFSSL_RIPEMD
  3118. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3119. bench_ripemd();
  3120. #endif
  3121. #ifdef HAVE_BLAKE2
  3122. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3123. bench_blake2b();
  3124. #endif
  3125. #ifdef HAVE_BLAKE2S
  3126. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3127. bench_blake2s();
  3128. #endif
  3129. #ifdef WOLFSSL_CMAC
  3130. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3131. bench_cmac(0);
  3132. #ifdef BENCH_DEVID
  3133. bench_cmac(1);
  3134. #endif
  3135. }
  3136. #endif
  3137. #ifndef NO_HMAC
  3138. #ifndef NO_MD5
  3139. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3140. #ifndef NO_SW_BENCH
  3141. bench_hmac_md5(0);
  3142. #endif
  3143. #ifdef BENCH_DEVID
  3144. bench_hmac_md5(1);
  3145. #endif
  3146. }
  3147. #endif
  3148. #ifndef NO_SHA
  3149. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3150. #ifndef NO_SW_BENCH
  3151. bench_hmac_sha(0);
  3152. #endif
  3153. #ifdef BENCH_DEVID
  3154. bench_hmac_sha(1);
  3155. #endif
  3156. }
  3157. #endif
  3158. #ifdef WOLFSSL_SHA224
  3159. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3160. #ifndef NO_SW_BENCH
  3161. bench_hmac_sha224(0);
  3162. #endif
  3163. #ifdef BENCH_DEVID
  3164. bench_hmac_sha224(1);
  3165. #endif
  3166. }
  3167. #endif
  3168. #ifndef NO_SHA256
  3169. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3170. #ifndef NO_SW_BENCH
  3171. bench_hmac_sha256(0);
  3172. #endif
  3173. #ifdef BENCH_DEVID
  3174. bench_hmac_sha256(1);
  3175. #endif
  3176. }
  3177. #endif
  3178. #ifdef WOLFSSL_SHA384
  3179. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3180. #ifndef NO_SW_BENCH
  3181. bench_hmac_sha384(0);
  3182. #endif
  3183. #ifdef BENCH_DEVID
  3184. bench_hmac_sha384(1);
  3185. #endif
  3186. }
  3187. #endif
  3188. #ifdef WOLFSSL_SHA512
  3189. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3190. #ifndef NO_SW_BENCH
  3191. bench_hmac_sha512(0);
  3192. #endif
  3193. #ifdef BENCH_DEVID
  3194. bench_hmac_sha512(1);
  3195. #endif
  3196. }
  3197. #endif
  3198. #ifndef NO_PWDBASED
  3199. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3200. bench_pbkdf2();
  3201. }
  3202. #endif
  3203. #endif /* NO_HMAC */
  3204. #ifdef WOLFSSL_SIPHASH
  3205. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3206. bench_siphash();
  3207. }
  3208. #endif
  3209. #ifdef WC_SRTP_KDF
  3210. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3211. bench_srtpkdf();
  3212. }
  3213. #endif
  3214. #ifdef HAVE_SCRYPT
  3215. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3216. bench_scrypt();
  3217. #endif
  3218. #ifndef NO_RSA
  3219. #ifndef HAVE_RENESAS_SYNC
  3220. #ifdef WOLFSSL_KEY_GEN
  3221. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3222. #ifndef NO_SW_BENCH
  3223. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3224. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3225. bench_rsaKeyGen(0);
  3226. }
  3227. else {
  3228. bench_rsaKeyGen_size(0, bench_size);
  3229. }
  3230. #endif
  3231. #ifdef BENCH_DEVID
  3232. if (bench_asym_algs & BENCH_RSA_SZ) {
  3233. bench_rsaKeyGen_size(1, bench_size);
  3234. }
  3235. else {
  3236. bench_rsaKeyGen(1);
  3237. }
  3238. #endif
  3239. }
  3240. #endif
  3241. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3242. #ifndef NO_SW_BENCH
  3243. bench_rsa(0);
  3244. #endif
  3245. #ifdef BENCH_DEVID
  3246. bench_rsa(1);
  3247. #endif
  3248. }
  3249. #ifdef WOLFSSL_KEY_GEN
  3250. if (bench_asym_algs & BENCH_RSA_SZ) {
  3251. #ifndef NO_SW_BENCH
  3252. bench_rsa_key(0, bench_size);
  3253. #endif
  3254. #ifdef BENCH_DEVID
  3255. bench_rsa_key(1, bench_size);
  3256. #endif
  3257. }
  3258. #endif
  3259. #endif
  3260. #endif
  3261. #ifndef NO_DH
  3262. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3263. #ifndef NO_SW_BENCH
  3264. bench_dh(0);
  3265. #endif
  3266. #ifdef BENCH_DEVID
  3267. bench_dh(1);
  3268. #endif
  3269. }
  3270. #endif
  3271. #ifdef WOLFSSL_HAVE_KYBER
  3272. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3273. #ifdef WOLFSSL_KYBER512
  3274. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3275. bench_kyber(KYBER512);
  3276. }
  3277. #endif
  3278. #ifdef WOLFSSL_KYBER768
  3279. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3280. bench_kyber(KYBER768);
  3281. }
  3282. #endif
  3283. #ifdef WOLFSSL_KYBER1024
  3284. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3285. bench_kyber(KYBER1024);
  3286. }
  3287. #endif
  3288. }
  3289. #endif
  3290. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3291. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3292. bench_lms();
  3293. }
  3294. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3295. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3296. if (bench_all) {
  3297. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3298. }
  3299. #ifndef NO_SHA256
  3300. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3301. bench_xmss(WC_HASH_TYPE_SHA256);
  3302. }
  3303. #endif
  3304. #ifdef WOLFSSL_SHA512
  3305. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3306. bench_xmss(WC_HASH_TYPE_SHA512);
  3307. }
  3308. #endif
  3309. #ifdef WOLFSSL_SHAKE128
  3310. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3311. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3312. }
  3313. #endif
  3314. #ifdef WOLFSSL_SHAKE256
  3315. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3316. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3317. }
  3318. #endif
  3319. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3320. #ifdef HAVE_ECC
  3321. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3322. (bench_asym_algs & BENCH_ECC) ||
  3323. (bench_asym_algs & BENCH_ECC_ALL) ||
  3324. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3325. if (bench_asym_algs & BENCH_ECC_ALL) {
  3326. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3327. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3328. err_prefix);
  3329. #else
  3330. int curveId = (int)ECC_SECP192R1;
  3331. /* set make key and encrypt */
  3332. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3333. BENCH_ECC_ENCRYPT;
  3334. if (csv_format != 1) {
  3335. printf("\n%sECC Benchmarks:\n", info_prefix);
  3336. }
  3337. do {
  3338. #ifdef WOLFCRYPT_HAVE_SAKKE
  3339. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3340. if (curveId == ECC_SAKKE_1) {
  3341. curveId++;
  3342. continue;
  3343. }
  3344. #endif
  3345. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3346. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3347. bench_ecc_curve(curveId);
  3348. if (csv_format != 1) {
  3349. printf("\n");
  3350. }
  3351. }
  3352. curveId++;
  3353. } while (curveId != (int)ECC_CURVE_MAX);
  3354. #endif
  3355. }
  3356. else if (bench_asym_algs & BENCH_ECC_P256) {
  3357. bench_ecc_curve((int)ECC_SECP256R1);
  3358. }
  3359. else if (bench_asym_algs & BENCH_ECC_P384) {
  3360. bench_ecc_curve((int)ECC_SECP384R1);
  3361. }
  3362. else if (bench_asym_algs & BENCH_ECC_P521) {
  3363. bench_ecc_curve((int)ECC_SECP521R1);
  3364. }
  3365. else {
  3366. #ifndef NO_ECC256
  3367. bench_ecc_curve((int)ECC_SECP256R1);
  3368. #elif defined(HAVE_ECC384)
  3369. bench_ecc_curve((int)ECC_SECP384R1);
  3370. #elif defined(HAVE_ECC521)
  3371. bench_ecc_curve((int)ECC_SECP521R1);
  3372. #endif
  3373. #ifdef HAVE_ECC_BRAINPOOL
  3374. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3375. #endif
  3376. }
  3377. }
  3378. #endif
  3379. #ifdef WOLFSSL_SM2
  3380. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3381. bench_sm2(0);
  3382. }
  3383. #endif
  3384. #ifdef HAVE_CURVE25519
  3385. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3386. bench_curve25519KeyGen(0);
  3387. #ifdef BENCH_DEVID
  3388. bench_curve25519KeyGen(1);
  3389. #endif
  3390. }
  3391. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3392. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3393. bench_curve25519KeyAgree(0);
  3394. #ifdef BENCH_DEVID
  3395. bench_curve25519KeyAgree(1);
  3396. #endif
  3397. }
  3398. #endif
  3399. #endif
  3400. #ifdef HAVE_ED25519
  3401. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3402. bench_ed25519KeyGen();
  3403. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3404. bench_ed25519KeySign();
  3405. #endif
  3406. #ifdef HAVE_CURVE448
  3407. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3408. bench_curve448KeyGen();
  3409. #ifdef HAVE_CURVE448_SHARED_SECRET
  3410. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3411. bench_curve448KeyAgree();
  3412. #endif
  3413. #endif
  3414. #ifdef HAVE_ED448
  3415. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3416. bench_ed448KeyGen();
  3417. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3418. bench_ed448KeySign();
  3419. #endif
  3420. #ifdef WOLFCRYPT_HAVE_ECCSI
  3421. #ifdef WOLFCRYPT_ECCSI_KMS
  3422. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3423. bench_eccsiKeyGen();
  3424. }
  3425. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3426. bench_eccsiPairGen();
  3427. }
  3428. #endif
  3429. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3430. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3431. bench_eccsiValidate();
  3432. }
  3433. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3434. bench_eccsi();
  3435. }
  3436. #endif
  3437. #endif
  3438. #ifdef WOLFCRYPT_HAVE_SAKKE
  3439. #ifdef WOLFCRYPT_SAKKE_KMS
  3440. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3441. bench_sakkeKeyGen();
  3442. }
  3443. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3444. bench_sakkeRskGen();
  3445. }
  3446. #endif
  3447. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3448. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3449. bench_sakkeValidate();
  3450. }
  3451. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3452. bench_sakke();
  3453. }
  3454. #endif
  3455. #endif
  3456. #ifdef HAVE_FALCON
  3457. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3458. bench_falconKeySign(1);
  3459. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3460. bench_falconKeySign(5);
  3461. #endif
  3462. #ifdef HAVE_DILITHIUM
  3463. #ifndef WOLFSSL_NO_ML_DSA_44
  3464. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3465. bench_dilithiumKeySign(2);
  3466. #endif
  3467. #ifndef WOLFSSL_NO_ML_DSA_65
  3468. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3469. bench_dilithiumKeySign(3);
  3470. #endif
  3471. #ifndef WOLFSSL_NO_ML_DSA_87
  3472. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3473. bench_dilithiumKeySign(5);
  3474. #endif
  3475. #endif
  3476. #ifdef HAVE_SPHINCS
  3477. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3478. bench_sphincsKeySign(1, FAST_VARIANT);
  3479. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3480. bench_sphincsKeySign(3, FAST_VARIANT);
  3481. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3482. bench_sphincsKeySign(5, FAST_VARIANT);
  3483. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3484. bench_sphincsKeySign(1, SMALL_VARIANT);
  3485. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3486. bench_sphincsKeySign(3, SMALL_VARIANT);
  3487. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3488. bench_sphincsKeySign(5, SMALL_VARIANT);
  3489. #endif
  3490. exit:
  3491. /* free benchmark buffers */
  3492. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3493. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3494. #ifdef WOLFSSL_ASYNC_CRYPT
  3495. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3496. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3497. #endif
  3498. #if defined(HAVE_LOCAL_RNG)
  3499. wc_FreeRng(&gRng);
  3500. #endif
  3501. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3502. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3503. wc_ecc_fp_free();
  3504. #endif
  3505. (void)bench_cipher_algs;
  3506. (void)bench_digest_algs;
  3507. (void)bench_mac_algs;
  3508. (void)bench_asym_algs;
  3509. (void)bench_other_algs;
  3510. (void)bench_pq_asym_algs;
  3511. (void)bench_pq_asym_algs2;
  3512. return NULL;
  3513. }
  3514. int benchmark_init(void)
  3515. {
  3516. int ret = 0;
  3517. benchmark_static_init(0);
  3518. #ifdef WOLFSSL_STATIC_MEMORY
  3519. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3520. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3521. if (ret != 0) {
  3522. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3523. }
  3524. #endif /* WOLFSSL_STATIC_MEMORY */
  3525. if ((ret = wolfCrypt_Init()) != 0) {
  3526. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3527. return EXIT_FAILURE;
  3528. }
  3529. #ifdef HAVE_WC_INTROSPECTION
  3530. printf("Math: %s\n", wc_GetMathInfo());
  3531. #endif
  3532. #ifdef WOLFSSL_SECO_CAAM
  3533. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3534. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3535. != 0) {
  3536. printf("%sunable to open HSM\n", err_prefix);
  3537. wolfCrypt_Cleanup();
  3538. return EXIT_FAILURE;
  3539. }
  3540. #endif
  3541. #ifdef WC_RNG_SEED_CB
  3542. wc_SetSeed_Cb(wc_GenerateSeed);
  3543. #endif
  3544. bench_stats_init();
  3545. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3546. wolfSSL_Debugging_ON();
  3547. #endif
  3548. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3549. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3550. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3551. if (csv_format == 1) {
  3552. printf("This format allows you to easily copy "
  3553. "the output to a csv file.");
  3554. }
  3555. #endif
  3556. #ifdef HAVE_WNR
  3557. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3558. if (ret != 0) {
  3559. printf("%sWhitewood netRandom config init failed %d\n",
  3560. err_prefix, ret);
  3561. }
  3562. #endif /* HAVE_WNR */
  3563. return ret;
  3564. }
  3565. int benchmark_free(void)
  3566. {
  3567. int ret;
  3568. #ifdef WC_BENCH_TRACK_STATS
  3569. if (gPrintStats || devId != INVALID_DEVID) {
  3570. bench_stats_print();
  3571. }
  3572. #endif
  3573. bench_stats_free();
  3574. #ifdef WOLF_CRYPTO_CB
  3575. #ifdef HAVE_INTEL_QA_SYNC
  3576. wc_CryptoCb_CleanupIntelQa(&devId);
  3577. #endif
  3578. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3579. wc_CryptoCb_CleanupOcteon(&devId);
  3580. #endif
  3581. #ifdef HAVE_RENESAS_SYNC
  3582. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3583. #endif
  3584. #endif
  3585. #ifdef WOLFSSL_ASYNC_CRYPT
  3586. /* free event queue */
  3587. wolfEventQueue_Free(&eventQueue);
  3588. /* close device */
  3589. wolfAsync_DevClose(&devId);
  3590. #endif
  3591. #ifdef HAVE_WNR
  3592. ret = wc_FreeNetRandom();
  3593. if (ret < 0) {
  3594. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3595. }
  3596. #endif
  3597. #ifdef WOLFSSL_SECO_CAAM
  3598. if (wc_SECO_CloseHSM() != 0) {
  3599. printf("%sError closing down the key store\n", err_prefix);
  3600. }
  3601. #endif
  3602. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3603. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3604. }
  3605. return ret;
  3606. }
  3607. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3608. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3609. {
  3610. benchmark_test(args);
  3611. EXIT_TEST(0);
  3612. }
  3613. static int benchmark_test_threaded(void* args)
  3614. {
  3615. int i;
  3616. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3617. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3618. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3619. if (g_threadData == NULL) {
  3620. printf("%sThread data alloc failed!\n", err_prefix);
  3621. return EXIT_FAILURE;
  3622. }
  3623. for (i = 0; i < g_threadCount; i++) {
  3624. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3625. NULL, run_bench, args));
  3626. }
  3627. for (i = 0; i < g_threadCount; i++) {
  3628. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3629. }
  3630. printf("\n");
  3631. bench_stats_print();
  3632. return 0;
  3633. }
  3634. #endif
  3635. /* so embedded projects can pull in tests on their own */
  3636. #ifdef HAVE_STACK_SIZE
  3637. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3638. #else
  3639. int benchmark_test(void *args)
  3640. #endif
  3641. {
  3642. int ret;
  3643. (void)args;
  3644. #ifdef HAVE_FIPS
  3645. wolfCrypt_SetCb_fips(myFipsCb);
  3646. #endif
  3647. ret = benchmark_init();
  3648. if (ret != 0)
  3649. EXIT_TEST(ret);
  3650. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3651. {
  3652. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3653. **
  3654. ** Chapter Two, Build Options:
  3655. **
  3656. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3657. **
  3658. ** asynchronous cryptography using hardware based adapters such as
  3659. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3660. */
  3661. int i;
  3662. if (g_threadCount == 0) {
  3663. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3664. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3665. #else
  3666. g_threadCount = wc_AsyncGetNumberOfCpus();
  3667. if (g_threadCount > 0) {
  3668. g_threadCount /= 2; /* use physical core count */
  3669. }
  3670. #endif
  3671. }
  3672. if (g_threadCount <= 0) {
  3673. g_threadCount = 1;
  3674. }
  3675. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3676. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3677. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3678. if (g_threadData == NULL) {
  3679. printf("%sThread data alloc failed!\n", err_prefix);
  3680. EXIT_TEST(EXIT_FAILURE);
  3681. }
  3682. /* Create threads */
  3683. for (i = 0; i < g_threadCount; i++) {
  3684. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3685. benchmarks_do, &g_threadData[i]);
  3686. if (ret != 0) {
  3687. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3688. EXIT_TEST(EXIT_FAILURE);
  3689. }
  3690. }
  3691. /* Start threads */
  3692. for (i = 0; i < g_threadCount; i++) {
  3693. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3694. }
  3695. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3696. }
  3697. #else
  3698. benchmarks_do(NULL);
  3699. #endif
  3700. SLEEP_ON_ERROR(1);
  3701. printf("%sBenchmark complete\n", info_prefix);
  3702. ret = benchmark_free();
  3703. EXIT_TEST(ret);
  3704. }
  3705. #ifndef WC_NO_RNG
  3706. void bench_rng(void)
  3707. {
  3708. int ret, i, count;
  3709. double start;
  3710. long pos, len, remain;
  3711. WC_RNG myrng;
  3712. DECLARE_MULTI_VALUE_STATS_VARS()
  3713. #ifndef HAVE_FIPS
  3714. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3715. #else
  3716. ret = wc_InitRng(&myrng);
  3717. #endif
  3718. if (ret < 0) {
  3719. printf("InitRNG failed %d\n", ret);
  3720. return;
  3721. }
  3722. bench_stats_start(&count, &start);
  3723. do {
  3724. for (i = 0; i < numBlocks; i++) {
  3725. /* Split request to handle large RNG request */
  3726. pos = 0;
  3727. remain = (int)bench_size;
  3728. while (remain > 0) {
  3729. len = remain;
  3730. if (len > RNG_MAX_BLOCK_LEN)
  3731. len = RNG_MAX_BLOCK_LEN;
  3732. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3733. (word32)len);
  3734. if (ret < 0)
  3735. goto exit_rng;
  3736. remain -= len;
  3737. pos += len;
  3738. }
  3739. RECORD_MULTI_VALUE_STATS();
  3740. }
  3741. count += i;
  3742. } while (bench_stats_check(start)
  3743. #ifdef MULTI_VALUE_STATISTICS
  3744. || runs < minimum_runs
  3745. #endif
  3746. );
  3747. exit_rng:
  3748. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3749. #ifdef MULTI_VALUE_STATISTICS
  3750. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3751. #endif
  3752. wc_FreeRng(&myrng);
  3753. }
  3754. #endif /* WC_NO_RNG */
  3755. #ifndef NO_AES
  3756. #ifdef HAVE_AES_CBC
  3757. static void bench_aescbc_internal(int useDeviceID,
  3758. const byte* key, word32 keySz,
  3759. const byte* iv, const char* encLabel,
  3760. const char* decLabel)
  3761. {
  3762. const byte* in = bench_cipher;
  3763. byte* out = bench_plain;
  3764. int ret = 0, i, count = 0, times, pending = 0;
  3765. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3766. sizeof(Aes), HEAP_HINT);
  3767. double start;
  3768. DECLARE_MULTI_VALUE_STATS_VARS()
  3769. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3770. sizeof(Aes), HEAP_HINT);
  3771. /* init keys */
  3772. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3773. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3774. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3775. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3776. goto exit;
  3777. }
  3778. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3779. if (ret != 0) {
  3780. printf("AesSetKey failed, ret = %d\n", ret);
  3781. goto exit;
  3782. }
  3783. }
  3784. if (cipher_same_buffer) {
  3785. in = bench_plain;
  3786. }
  3787. bench_stats_start(&count, &start);
  3788. do {
  3789. for (times = 0; times < numBlocks || pending > 0; ) {
  3790. bench_async_poll(&pending);
  3791. /* while free pending slots in queue, submit ops */
  3792. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3793. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3794. &times, numBlocks, &pending)) {
  3795. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3796. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3797. 0, &times, &pending)) {
  3798. goto exit_aes_enc;
  3799. }
  3800. }
  3801. } /* for i */
  3802. RECORD_MULTI_VALUE_STATS();
  3803. } /* for times */
  3804. count += times;
  3805. } while (bench_stats_check(start)
  3806. #ifdef MULTI_VALUE_STATISTICS
  3807. || runs < minimum_runs
  3808. #endif
  3809. );
  3810. exit_aes_enc:
  3811. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3812. bench_size, start, ret);
  3813. #ifdef MULTI_VALUE_STATISTICS
  3814. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3815. #endif
  3816. if (ret < 0) {
  3817. goto exit;
  3818. }
  3819. #ifdef HAVE_AES_DECRYPT
  3820. /* init keys */
  3821. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3822. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3823. if (ret != 0) {
  3824. printf("AesSetKey failed, ret = %d\n", ret);
  3825. goto exit;
  3826. }
  3827. }
  3828. RESET_MULTI_VALUE_STATS_VARS();
  3829. bench_stats_start(&count, &start);
  3830. do {
  3831. for (times = 0; times < numBlocks || pending > 0; ) {
  3832. bench_async_poll(&pending);
  3833. /* while free pending slots in queue, submit ops */
  3834. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3835. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3836. &times, numBlocks, &pending)) {
  3837. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3838. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3839. 0, &times, &pending)) {
  3840. goto exit_aes_dec;
  3841. }
  3842. }
  3843. } /* for i */
  3844. RECORD_MULTI_VALUE_STATS();
  3845. } /* for times */
  3846. count += times;
  3847. } while (bench_stats_check(start)
  3848. #ifdef MULTI_VALUE_STATISTICS
  3849. || runs < minimum_runs
  3850. #endif
  3851. );
  3852. exit_aes_dec:
  3853. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3854. start, ret);
  3855. #ifdef MULTI_VALUE_STATISTICS
  3856. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3857. #endif
  3858. #endif /* HAVE_AES_DECRYPT */
  3859. (void)decLabel;
  3860. exit:
  3861. if (WC_ARRAY_OK(enc)) {
  3862. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3863. wc_AesFree(enc[i]);
  3864. }
  3865. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3866. }
  3867. }
  3868. void bench_aescbc(int useDeviceID)
  3869. {
  3870. #ifdef WOLFSSL_AES_128
  3871. #ifdef HAVE_RENESAS_SYNC
  3872. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3873. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3874. #else
  3875. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3876. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3877. #endif
  3878. #endif
  3879. #ifdef WOLFSSL_AES_192
  3880. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3881. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3882. #endif
  3883. #ifdef WOLFSSL_AES_256
  3884. #ifdef HAVE_RENESAS_SYNC
  3885. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3886. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3887. #else
  3888. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3889. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3890. #endif
  3891. #endif
  3892. }
  3893. #endif /* HAVE_AES_CBC */
  3894. #ifdef HAVE_AESGCM
  3895. static void bench_aesgcm_internal(int useDeviceID,
  3896. const byte* key, word32 keySz,
  3897. const byte* iv, word32 ivSz,
  3898. const char* encLabel, const char* decLabel)
  3899. {
  3900. int ret = 0, i, count = 0, times, pending = 0;
  3901. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3902. sizeof(Aes), HEAP_HINT);
  3903. #ifdef HAVE_AES_DECRYPT
  3904. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3905. sizeof(Aes), HEAP_HINT);
  3906. #endif
  3907. double start;
  3908. DECLARE_MULTI_VALUE_STATS_VARS()
  3909. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3910. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3911. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3912. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3913. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3914. sizeof(Aes), HEAP_HINT);
  3915. #ifdef HAVE_AES_DECRYPT
  3916. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3917. sizeof(Aes), HEAP_HINT);
  3918. #endif
  3919. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  3920. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  3921. /* init keys */
  3922. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3923. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3924. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3925. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3926. goto exit;
  3927. }
  3928. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  3929. if (ret != 0) {
  3930. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3931. goto exit;
  3932. }
  3933. }
  3934. /* GCM uses same routine in backend for both encrypt and decrypt */
  3935. bench_stats_start(&count, &start);
  3936. do {
  3937. for (times = 0; times < numBlocks || pending > 0; ) {
  3938. bench_async_poll(&pending);
  3939. /* while free pending slots in queue, submit ops */
  3940. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3941. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3942. &times, numBlocks, &pending)) {
  3943. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  3944. bench_plain, bench_size,
  3945. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  3946. bench_additional, aesAuthAddSz);
  3947. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3948. 0, &times, &pending)) {
  3949. goto exit_aes_gcm;
  3950. }
  3951. }
  3952. } /* for i */
  3953. RECORD_MULTI_VALUE_STATS();
  3954. } /* for times */
  3955. count += times;
  3956. } while (bench_stats_check(start)
  3957. #ifdef MULTI_VALUE_STATISTICS
  3958. || runs < minimum_runs
  3959. #endif
  3960. );
  3961. exit_aes_gcm:
  3962. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  3963. start, ret);
  3964. #ifdef MULTI_VALUE_STATISTICS
  3965. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3966. #endif
  3967. #ifdef HAVE_AES_DECRYPT
  3968. RESET_MULTI_VALUE_STATS_VARS();
  3969. /* init keys */
  3970. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3971. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  3972. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3973. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3974. goto exit;
  3975. }
  3976. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  3977. if (ret != 0) {
  3978. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3979. goto exit;
  3980. }
  3981. }
  3982. bench_stats_start(&count, &start);
  3983. do {
  3984. for (times = 0; times < numBlocks || pending > 0; ) {
  3985. bench_async_poll(&pending);
  3986. /* while free pending slots in queue, submit ops */
  3987. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3988. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  3989. &times, numBlocks, &pending)) {
  3990. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  3991. bench_cipher, bench_size,
  3992. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  3993. bench_additional, aesAuthAddSz);
  3994. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  3995. 0, &times, &pending)) {
  3996. goto exit_aes_gcm_dec;
  3997. }
  3998. }
  3999. } /* for i */
  4000. RECORD_MULTI_VALUE_STATS();
  4001. } /* for times */
  4002. count += times;
  4003. } while (bench_stats_check(start)
  4004. #ifdef MULTI_VALUE_STATISTICS
  4005. || runs < minimum_runs
  4006. #endif
  4007. );
  4008. exit_aes_gcm_dec:
  4009. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4010. start, ret);
  4011. #ifdef MULTI_VALUE_STATISTICS
  4012. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4013. #endif
  4014. #endif /* HAVE_AES_DECRYPT */
  4015. (void)decLabel;
  4016. exit:
  4017. if (ret < 0) {
  4018. printf("bench_aesgcm failed: %d\n", ret);
  4019. }
  4020. #ifdef HAVE_AES_DECRYPT
  4021. if (WC_ARRAY_OK(dec)) {
  4022. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4023. wc_AesFree(dec[i]);
  4024. }
  4025. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4026. }
  4027. #endif
  4028. if (WC_ARRAY_OK(enc)) {
  4029. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4030. wc_AesFree(enc[i]);
  4031. }
  4032. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4033. }
  4034. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4035. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4036. }
  4037. #ifdef WOLFSSL_AESGCM_STREAM
  4038. static void bench_aesgcm_stream_internal(int useDeviceID,
  4039. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4040. const char* encLabel, const char* decLabel)
  4041. {
  4042. int ret = 0, i, count = 0, times, pending = 0;
  4043. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4044. sizeof(Aes), HEAP_HINT);
  4045. #ifdef HAVE_AES_DECRYPT
  4046. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4047. sizeof(Aes), HEAP_HINT);
  4048. #endif
  4049. double start;
  4050. DECLARE_MULTI_VALUE_STATS_VARS()
  4051. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4052. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4053. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4054. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4055. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4056. sizeof(Aes), HEAP_HINT);
  4057. #ifdef HAVE_AES_DECRYPT
  4058. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4059. sizeof(Aes), HEAP_HINT);
  4060. #endif
  4061. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4062. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4063. /* init keys */
  4064. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4065. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4066. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4067. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4068. goto exit;
  4069. }
  4070. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4071. if (ret != 0) {
  4072. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4073. goto exit;
  4074. }
  4075. }
  4076. /* GCM uses same routine in backend for both encrypt and decrypt */
  4077. bench_stats_start(&count, &start);
  4078. do {
  4079. for (times = 0; times < numBlocks || pending > 0; ) {
  4080. bench_async_poll(&pending);
  4081. /* while free pending slots in queue, submit ops */
  4082. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4083. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4084. &times, numBlocks, &pending)) {
  4085. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4086. if (ret == 0) {
  4087. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4088. bench_plain, bench_size, bench_additional,
  4089. aesAuthAddSz);
  4090. }
  4091. if (ret == 0) {
  4092. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4093. AES_AUTH_TAG_SZ);
  4094. }
  4095. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4096. 0, &times, &pending)) {
  4097. goto exit_aes_gcm;
  4098. }
  4099. }
  4100. } /* for i */
  4101. RECORD_MULTI_VALUE_STATS();
  4102. } /* for times */
  4103. count += times;
  4104. } while (bench_stats_check(start)
  4105. #ifdef MULTI_VALUE_STATISTICS
  4106. || runs < minimum_runs
  4107. #endif
  4108. );
  4109. exit_aes_gcm:
  4110. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4111. start, ret);
  4112. #ifdef MULTI_VALUE_STATISTICS
  4113. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4114. #endif
  4115. #ifdef HAVE_AES_DECRYPT
  4116. /* init keys */
  4117. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4118. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4119. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4120. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4121. goto exit;
  4122. }
  4123. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4124. if (ret != 0) {
  4125. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4126. goto exit;
  4127. }
  4128. }
  4129. RESET_MULTI_VALUE_STATS_VARS();
  4130. bench_stats_start(&count, &start);
  4131. do {
  4132. for (times = 0; times < numBlocks || pending > 0; ) {
  4133. bench_async_poll(&pending);
  4134. /* while free pending slots in queue, submit ops */
  4135. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4136. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4137. &times, numBlocks, &pending)) {
  4138. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4139. if (ret == 0) {
  4140. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4141. bench_cipher, bench_size, bench_additional,
  4142. aesAuthAddSz);
  4143. }
  4144. if (ret == 0) {
  4145. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4146. AES_AUTH_TAG_SZ);
  4147. }
  4148. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4149. 0, &times, &pending)) {
  4150. goto exit_aes_gcm_dec;
  4151. }
  4152. }
  4153. } /* for i */
  4154. RECORD_MULTI_VALUE_STATS();
  4155. } /* for times */
  4156. count += times;
  4157. } while (bench_stats_check(start)
  4158. #ifdef MULTI_VALUE_STATISTICS
  4159. || runs < minimum_runs
  4160. #endif
  4161. );
  4162. exit_aes_gcm_dec:
  4163. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4164. start, ret);
  4165. #ifdef MULTI_VALUE_STATISTICS
  4166. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4167. #endif
  4168. #endif /* HAVE_AES_DECRYPT */
  4169. (void)decLabel;
  4170. exit:
  4171. if (ret < 0) {
  4172. printf("bench_aesgcm failed: %d\n", ret);
  4173. }
  4174. #ifdef HAVE_AES_DECRYPT
  4175. if (WC_ARRAY_OK(dec)) {
  4176. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4177. wc_AesFree(dec[i]);
  4178. }
  4179. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4180. }
  4181. #endif
  4182. if (WC_ARRAY_OK(enc)) {
  4183. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4184. wc_AesFree(enc[i]);
  4185. }
  4186. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4187. }
  4188. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4189. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4190. }
  4191. #endif
  4192. void bench_aesgcm(int useDeviceID)
  4193. {
  4194. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4195. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4196. && !defined(WOLFSSL_XILINX_CRYPT) \
  4197. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4198. #ifdef HAVE_RENESAS_SYNC
  4199. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4200. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4201. #else
  4202. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4203. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4204. #endif
  4205. #endif
  4206. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4207. && !defined(WOLFSSL_XILINX_CRYPT)
  4208. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4209. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4210. #endif
  4211. #ifdef WOLFSSL_AES_256
  4212. #ifdef HAVE_RENESAS_SYNC
  4213. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4214. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4215. #else
  4216. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4217. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4218. #endif
  4219. #endif
  4220. #ifdef WOLFSSL_AESGCM_STREAM
  4221. #undef AES_GCM_STRING
  4222. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4223. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4224. && !defined(WOLFSSL_XILINX_CRYPT) \
  4225. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4226. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4227. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4228. #endif
  4229. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4230. && !defined(WOLFSSL_XILINX_CRYPT)
  4231. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4232. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4233. #endif
  4234. #ifdef WOLFSSL_AES_256
  4235. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4236. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4237. #endif
  4238. #endif /* WOLFSSL_AESGCM_STREAM */
  4239. #undef AES_GCM_STRING
  4240. }
  4241. /* GMAC */
  4242. void bench_gmac(int useDeviceID)
  4243. {
  4244. int ret, count = 0;
  4245. Gmac gmac;
  4246. double start;
  4247. byte tag[AES_AUTH_TAG_SZ];
  4248. DECLARE_MULTI_VALUE_STATS_VARS()
  4249. /* determine GCM GHASH method */
  4250. #ifdef GCM_SMALL
  4251. const char* gmacStr = "GMAC Small";
  4252. #elif defined(GCM_TABLE)
  4253. const char* gmacStr = "GMAC Table";
  4254. #elif defined(GCM_TABLE_4BIT)
  4255. const char* gmacStr = "GMAC Table 4-bit";
  4256. #elif defined(GCM_WORD32)
  4257. const char* gmacStr = "GMAC Word32";
  4258. #else
  4259. const char* gmacStr = "GMAC Default";
  4260. #endif
  4261. /* init keys */
  4262. XMEMSET(bench_plain, 0, bench_size);
  4263. XMEMSET(tag, 0, sizeof(tag));
  4264. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4265. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4266. useDeviceID ? devId: INVALID_DEVID);
  4267. #ifdef HAVE_RENESAS_SYNC
  4268. wc_GmacSetKey(&gmac, bench_key1, 16);
  4269. #else
  4270. wc_GmacSetKey(&gmac, bench_key, 16);
  4271. #endif
  4272. bench_stats_start(&count, &start);
  4273. do {
  4274. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4275. tag, sizeof(tag));
  4276. count++;
  4277. RECORD_MULTI_VALUE_STATS();
  4278. } while (bench_stats_check(start)
  4279. #ifdef MULTI_VALUE_STATISTICS
  4280. || runs < minimum_runs
  4281. #endif
  4282. );
  4283. wc_AesFree((Aes*)&gmac);
  4284. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4285. #ifdef MULTI_VALUE_STATISTICS
  4286. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4287. #endif
  4288. }
  4289. #endif /* HAVE_AESGCM */
  4290. #ifdef HAVE_AES_ECB
  4291. static void bench_aesecb_internal(int useDeviceID,
  4292. const byte* key, word32 keySz,
  4293. const char* encLabel, const char* decLabel)
  4294. {
  4295. int ret = 0, i, count = 0, times, pending = 0;
  4296. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4297. sizeof(Aes), HEAP_HINT);
  4298. double start;
  4299. DECLARE_MULTI_VALUE_STATS_VARS()
  4300. #ifdef HAVE_FIPS
  4301. const word32 benchSz = AES_BLOCK_SIZE;
  4302. #else
  4303. const word32 benchSz = bench_size;
  4304. #endif
  4305. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4306. sizeof(Aes), HEAP_HINT);
  4307. /* init keys */
  4308. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4309. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4310. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4311. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4312. goto exit;
  4313. }
  4314. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4315. if (ret != 0) {
  4316. printf("AesSetKey failed, ret = %d\n", ret);
  4317. goto exit;
  4318. }
  4319. }
  4320. bench_stats_start(&count, &start);
  4321. do {
  4322. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4323. for (times = 0;
  4324. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4325. ) {
  4326. bench_async_poll(&pending);
  4327. /* while free pending slots in queue, submit ops */
  4328. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4329. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4330. &times, outer_loop_limit, &pending)) {
  4331. #ifdef HAVE_FIPS
  4332. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4333. #else
  4334. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4335. benchSz);
  4336. #endif
  4337. ret = 0;
  4338. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4339. 0, &times, &pending)) {
  4340. goto exit_aes_enc;
  4341. }
  4342. }
  4343. } /* for i */
  4344. RECORD_MULTI_VALUE_STATS();
  4345. } /* for times */
  4346. count += times;
  4347. } while (bench_stats_check(start)
  4348. #ifdef MULTI_VALUE_STATISTICS
  4349. || runs < minimum_runs
  4350. #endif
  4351. );
  4352. exit_aes_enc:
  4353. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4354. start, ret);
  4355. #ifdef MULTI_VALUE_STATISTICS
  4356. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4357. #endif
  4358. #ifdef HAVE_AES_DECRYPT
  4359. /* init keys */
  4360. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4361. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4362. if (ret != 0) {
  4363. printf("AesSetKey failed, ret = %d\n", ret);
  4364. goto exit;
  4365. }
  4366. }
  4367. RESET_MULTI_VALUE_STATS_VARS();
  4368. bench_stats_start(&count, &start);
  4369. do {
  4370. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4371. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4372. bench_async_poll(&pending);
  4373. /* while free pending slots in queue, submit ops */
  4374. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4375. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4376. &times, outer_loop_limit, &pending)) {
  4377. #ifdef HAVE_FIPS
  4378. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4379. #else
  4380. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4381. benchSz);
  4382. #endif
  4383. ret = 0;
  4384. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4385. 0, &times, &pending)) {
  4386. goto exit_aes_dec;
  4387. }
  4388. }
  4389. } /* for i */
  4390. RECORD_MULTI_VALUE_STATS();
  4391. } /* for times */
  4392. count += times;
  4393. } while (bench_stats_check(start)
  4394. #ifdef MULTI_VALUE_STATISTICS
  4395. || runs < minimum_runs
  4396. #endif
  4397. );
  4398. exit_aes_dec:
  4399. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4400. start, ret);
  4401. #ifdef MULTI_VALUE_STATISTICS
  4402. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4403. #endif
  4404. #endif /* HAVE_AES_DECRYPT */
  4405. (void)decLabel;
  4406. exit:
  4407. if (WC_ARRAY_OK(enc)) {
  4408. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4409. wc_AesFree(enc[i]);
  4410. }
  4411. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4412. }
  4413. }
  4414. void bench_aesecb(int useDeviceID)
  4415. {
  4416. #ifdef WOLFSSL_AES_128
  4417. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4418. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4419. #endif
  4420. #ifdef WOLFSSL_AES_192
  4421. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4422. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4423. #endif
  4424. #ifdef WOLFSSL_AES_256
  4425. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4426. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4427. #endif
  4428. }
  4429. #endif /* HAVE_AES_ECB */
  4430. #ifdef WOLFSSL_AES_CFB
  4431. static void bench_aescfb_internal(const byte* key,
  4432. word32 keySz, const byte* iv,
  4433. const char* label)
  4434. {
  4435. Aes enc;
  4436. double start;
  4437. int i, ret, count;
  4438. DECLARE_MULTI_VALUE_STATS_VARS()
  4439. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4440. if (ret != 0) {
  4441. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4442. return;
  4443. }
  4444. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4445. if (ret != 0) {
  4446. printf("AesSetKey failed, ret = %d\n", ret);
  4447. goto out;
  4448. }
  4449. bench_stats_start(&count, &start);
  4450. do {
  4451. for (i = 0; i < numBlocks; i++) {
  4452. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4453. bench_size)) != 0) {
  4454. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4455. goto out;
  4456. }
  4457. RECORD_MULTI_VALUE_STATS();
  4458. }
  4459. count += i;
  4460. } while (bench_stats_check(start)
  4461. #ifdef MULTI_VALUE_STATISTICS
  4462. || runs < minimum_runs
  4463. #endif
  4464. );
  4465. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4466. #ifdef MULTI_VALUE_STATISTICS
  4467. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4468. #endif
  4469. out:
  4470. wc_AesFree(&enc);
  4471. return;
  4472. }
  4473. void bench_aescfb(void)
  4474. {
  4475. #ifdef WOLFSSL_AES_128
  4476. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4477. #endif
  4478. #ifdef WOLFSSL_AES_192
  4479. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4480. #endif
  4481. #ifdef WOLFSSL_AES_256
  4482. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4483. #endif
  4484. }
  4485. #endif /* WOLFSSL_AES_CFB */
  4486. #ifdef WOLFSSL_AES_OFB
  4487. static void bench_aesofb_internal(const byte* key,
  4488. word32 keySz, const byte* iv,
  4489. const char* label)
  4490. {
  4491. Aes enc;
  4492. double start;
  4493. int i, ret, count;
  4494. DECLARE_MULTI_VALUE_STATS_VARS()
  4495. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4496. if (ret != 0) {
  4497. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4498. return;
  4499. }
  4500. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4501. if (ret != 0) {
  4502. printf("AesSetKey failed, ret = %d\n", ret);
  4503. return;
  4504. }
  4505. bench_stats_start(&count, &start);
  4506. do {
  4507. for (i = 0; i < numBlocks; i++) {
  4508. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4509. bench_size)) != 0) {
  4510. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4511. return;
  4512. }
  4513. RECORD_MULTI_VALUE_STATS();
  4514. }
  4515. count += i;
  4516. } while (bench_stats_check(start)
  4517. #ifdef MULTI_VALUE_STATISTICS
  4518. || runs < minimum_runs
  4519. #endif
  4520. );
  4521. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4522. #ifdef MULTI_VALUE_STATISTICS
  4523. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4524. #endif
  4525. wc_AesFree(&enc);
  4526. }
  4527. void bench_aesofb(void)
  4528. {
  4529. #ifdef WOLFSSL_AES_128
  4530. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4531. #endif
  4532. #ifdef WOLFSSL_AES_192
  4533. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4534. #endif
  4535. #ifdef WOLFSSL_AES_256
  4536. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4537. #endif
  4538. }
  4539. #endif /* WOLFSSL_AES_CFB */
  4540. #ifdef WOLFSSL_AES_XTS
  4541. void bench_aesxts(void)
  4542. {
  4543. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4544. double start;
  4545. int i, count, ret;
  4546. DECLARE_MULTI_VALUE_STATS_VARS()
  4547. static const unsigned char k1[] = {
  4548. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4549. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4550. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4551. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4552. };
  4553. static const unsigned char i1[] = {
  4554. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4555. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4556. };
  4557. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4558. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4559. HEAP_HINT, devId);
  4560. if (ret != 0) {
  4561. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4562. goto exit;
  4563. }
  4564. bench_stats_start(&count, &start);
  4565. do {
  4566. for (i = 0; i < numBlocks; i++) {
  4567. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4568. bench_size, i1, sizeof(i1))) != 0) {
  4569. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4570. goto exit;
  4571. }
  4572. RECORD_MULTI_VALUE_STATS();
  4573. }
  4574. count += i;
  4575. } while (bench_stats_check(start)
  4576. #ifdef MULTI_VALUE_STATISTICS
  4577. || runs < minimum_runs
  4578. #endif
  4579. );
  4580. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4581. #ifdef MULTI_VALUE_STATISTICS
  4582. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4583. #endif
  4584. wc_AesXtsFree(aes);
  4585. /* decryption benchmark */
  4586. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4587. HEAP_HINT, devId);
  4588. if (ret != 0) {
  4589. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4590. goto exit;
  4591. }
  4592. RESET_MULTI_VALUE_STATS_VARS();
  4593. bench_stats_start(&count, &start);
  4594. do {
  4595. for (i = 0; i < numBlocks; i++) {
  4596. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4597. bench_size, i1, sizeof(i1))) != 0) {
  4598. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4599. goto exit;
  4600. }
  4601. RECORD_MULTI_VALUE_STATS();
  4602. }
  4603. count += i;
  4604. } while (bench_stats_check(start)
  4605. #ifdef MULTI_VALUE_STATISTICS
  4606. || runs < minimum_runs
  4607. #endif
  4608. );
  4609. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4610. #ifdef MULTI_VALUE_STATISTICS
  4611. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4612. #endif
  4613. exit:
  4614. wc_AesXtsFree(aes);
  4615. WC_FREE_VAR(aes, HEAP_HINT);
  4616. }
  4617. #endif /* WOLFSSL_AES_XTS */
  4618. #ifdef WOLFSSL_AES_COUNTER
  4619. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4620. const byte* iv, const char* label,
  4621. int useDeviceID)
  4622. {
  4623. Aes enc;
  4624. double start;
  4625. int i, count, ret = 0;
  4626. DECLARE_MULTI_VALUE_STATS_VARS()
  4627. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4628. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4629. printf("wc_AesInit failed, ret = %d\n", ret);
  4630. }
  4631. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4632. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4633. return;
  4634. }
  4635. bench_stats_start(&count, &start);
  4636. do {
  4637. for (i = 0; i < numBlocks; i++) {
  4638. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4639. bench_size)) != 0) {
  4640. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4641. return;
  4642. }
  4643. RECORD_MULTI_VALUE_STATS();
  4644. }
  4645. count += i;
  4646. } while (bench_stats_check(start)
  4647. #ifdef MULTI_VALUE_STATISTICS
  4648. || runs < minimum_runs
  4649. #endif
  4650. );
  4651. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4652. #ifdef MULTI_VALUE_STATISTICS
  4653. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4654. #endif
  4655. wc_AesFree(&enc);
  4656. }
  4657. void bench_aesctr(int useDeviceID)
  4658. {
  4659. #ifdef WOLFSSL_AES_128
  4660. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4661. #endif
  4662. #ifdef WOLFSSL_AES_192
  4663. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4664. #endif
  4665. #ifdef WOLFSSL_AES_256
  4666. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4667. #endif
  4668. }
  4669. #endif /* WOLFSSL_AES_COUNTER */
  4670. #ifdef HAVE_AESCCM
  4671. void bench_aesccm(int useDeviceID)
  4672. {
  4673. Aes enc;
  4674. int enc_inited = 0;
  4675. double start;
  4676. int ret, i, count;
  4677. DECLARE_MULTI_VALUE_STATS_VARS()
  4678. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4679. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4680. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4681. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4682. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4683. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4684. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4685. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4686. {
  4687. printf("wc_AesInit failed, ret = %d\n", ret);
  4688. goto exit;
  4689. }
  4690. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4691. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4692. goto exit;
  4693. }
  4694. enc_inited = 1;
  4695. bench_stats_start(&count, &start);
  4696. do {
  4697. for (i = 0; i < numBlocks; i++) {
  4698. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4699. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4700. bench_additional, 0);
  4701. RECORD_MULTI_VALUE_STATS();
  4702. }
  4703. count += i;
  4704. } while (bench_stats_check(start)
  4705. #ifdef MULTI_VALUE_STATISTICS
  4706. || runs < minimum_runs
  4707. #endif
  4708. );
  4709. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4710. bench_size, start, ret);
  4711. #ifdef MULTI_VALUE_STATISTICS
  4712. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4713. #endif
  4714. if (ret != 0) {
  4715. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4716. goto exit;
  4717. }
  4718. #ifdef HAVE_AES_DECRYPT
  4719. RESET_MULTI_VALUE_STATS_VARS();
  4720. bench_stats_start(&count, &start);
  4721. do {
  4722. for (i = 0; i < numBlocks; i++) {
  4723. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4724. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4725. bench_additional, 0);
  4726. RECORD_MULTI_VALUE_STATS();
  4727. }
  4728. count += i;
  4729. } while (bench_stats_check(start)
  4730. #ifdef MULTI_VALUE_STATISTICS
  4731. || runs < minimum_runs
  4732. #endif
  4733. );
  4734. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4735. bench_size, start, ret);
  4736. #ifdef MULTI_VALUE_STATISTICS
  4737. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4738. #endif
  4739. if (ret != 0) {
  4740. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4741. goto exit;
  4742. }
  4743. #endif
  4744. exit:
  4745. if (enc_inited)
  4746. wc_AesFree(&enc);
  4747. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4748. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4749. }
  4750. #endif /* HAVE_AESCCM */
  4751. #ifdef WOLFSSL_AES_SIV
  4752. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4753. encLabel, const char* decLabel)
  4754. {
  4755. int i;
  4756. int ret = 0;
  4757. byte assoc[AES_BLOCK_SIZE];
  4758. byte nonce[AES_BLOCK_SIZE];
  4759. byte siv[AES_BLOCK_SIZE];
  4760. int count = 0;
  4761. double start;
  4762. DECLARE_MULTI_VALUE_STATS_VARS()
  4763. bench_stats_start(&count, &start);
  4764. do {
  4765. for (i = 0; i < numBlocks; i++) {
  4766. ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4767. AES_BLOCK_SIZE, bench_plain, bench_size,
  4768. siv, bench_cipher);
  4769. if (ret != 0) {
  4770. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4771. return;
  4772. }
  4773. RECORD_MULTI_VALUE_STATS();
  4774. }
  4775. count += i;
  4776. } while (bench_stats_check(start)
  4777. #ifdef MULTI_VALUE_STATISTICS
  4778. || runs < minimum_runs
  4779. #endif
  4780. );
  4781. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4782. #ifdef MULTI_VALUE_STATISTICS
  4783. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4784. #endif
  4785. RESET_MULTI_VALUE_STATS_VARS();
  4786. bench_stats_start(&count, &start);
  4787. do {
  4788. for (i = 0; i < numBlocks; i++) {
  4789. ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4790. AES_BLOCK_SIZE, bench_cipher, bench_size,
  4791. siv, bench_plain);
  4792. if (ret != 0) {
  4793. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4794. return;
  4795. }
  4796. RECORD_MULTI_VALUE_STATS();
  4797. }
  4798. count += i;
  4799. } while (bench_stats_check(start)
  4800. #ifdef MULTI_VALUE_STATISTICS
  4801. || runs < minimum_runs
  4802. #endif
  4803. );
  4804. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4805. #ifdef MULTI_VALUE_STATISTICS
  4806. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4807. #endif
  4808. }
  4809. void bench_aessiv(void)
  4810. {
  4811. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4812. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4813. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4814. }
  4815. #endif /* WOLFSSL_AES_SIV */
  4816. #endif /* !NO_AES */
  4817. #ifdef HAVE_POLY1305
  4818. void bench_poly1305(void)
  4819. {
  4820. Poly1305 enc;
  4821. byte mac[16];
  4822. double start;
  4823. int ret = 0, i, count;
  4824. DECLARE_MULTI_VALUE_STATS_VARS()
  4825. if (digest_stream) {
  4826. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4827. if (ret != 0) {
  4828. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4829. return;
  4830. }
  4831. bench_stats_start(&count, &start);
  4832. do {
  4833. for (i = 0; i < numBlocks; i++) {
  4834. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4835. if (ret != 0) {
  4836. printf("Poly1305Update failed: %d\n", ret);
  4837. break;
  4838. }
  4839. RECORD_MULTI_VALUE_STATS();
  4840. }
  4841. wc_Poly1305Final(&enc, mac);
  4842. count += i;
  4843. } while (bench_stats_check(start)
  4844. #ifdef MULTI_VALUE_STATISTICS
  4845. || runs < minimum_runs
  4846. #endif
  4847. );
  4848. }
  4849. else {
  4850. bench_stats_start(&count, &start);
  4851. do {
  4852. for (i = 0; i < numBlocks; i++) {
  4853. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4854. if (ret != 0) {
  4855. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4856. return;
  4857. }
  4858. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4859. if (ret != 0) {
  4860. printf("Poly1305Update failed: %d\n", ret);
  4861. break;
  4862. }
  4863. wc_Poly1305Final(&enc, mac);
  4864. RECORD_MULTI_VALUE_STATS();
  4865. }
  4866. count += i;
  4867. } while (bench_stats_check(start)
  4868. #ifdef MULTI_VALUE_STATISTICS
  4869. || runs < minimum_runs
  4870. #endif
  4871. );
  4872. }
  4873. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4874. #ifdef MULTI_VALUE_STATISTICS
  4875. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4876. #endif
  4877. }
  4878. #endif /* HAVE_POLY1305 */
  4879. #ifdef HAVE_CAMELLIA
  4880. void bench_camellia(void)
  4881. {
  4882. Camellia cam;
  4883. double start;
  4884. int ret, i, count;
  4885. DECLARE_MULTI_VALUE_STATS_VARS()
  4886. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4887. if (ret != 0) {
  4888. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4889. return;
  4890. }
  4891. bench_stats_start(&count, &start);
  4892. do {
  4893. for (i = 0; i < numBlocks; i++) {
  4894. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4895. bench_size);
  4896. if (ret < 0) {
  4897. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4898. return;
  4899. }
  4900. RECORD_MULTI_VALUE_STATS();
  4901. }
  4902. count += i;
  4903. } while (bench_stats_check(start)
  4904. #ifdef MULTI_VALUE_STATISTICS
  4905. || runs < minimum_runs
  4906. #endif
  4907. );
  4908. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  4909. #ifdef MULTI_VALUE_STATISTICS
  4910. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4911. #endif
  4912. }
  4913. #endif
  4914. #ifdef WOLFSSL_SM4_CBC
  4915. void bench_sm4_cbc(void)
  4916. {
  4917. wc_Sm4 sm4;
  4918. double start;
  4919. int ret;
  4920. int i;
  4921. int count;
  4922. DECLARE_MULTI_VALUE_STATS_VARS()
  4923. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4924. if (ret != 0) {
  4925. printf("Sm4SetKey failed, ret = %d\n", ret);
  4926. return;
  4927. }
  4928. ret = wc_Sm4SetIV(&sm4, bench_iv);
  4929. if (ret != 0) {
  4930. printf("Sm4SetIV failed, ret = %d\n", ret);
  4931. return;
  4932. }
  4933. bench_stats_start(&count, &start);
  4934. do {
  4935. for (i = 0; i < numBlocks; i++) {
  4936. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  4937. if (ret < 0) {
  4938. printf("Sm4CbcEncrypt failed: %d\n", ret);
  4939. return;
  4940. }
  4941. RECORD_MULTI_VALUE_STATS();
  4942. }
  4943. count += i;
  4944. } while (bench_stats_check(start)
  4945. #ifdef MULTI_VALUE_STATISTICS
  4946. || runs < minimum_runs
  4947. #endif
  4948. );
  4949. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  4950. #ifdef MULTI_VALUE_STATISTICS
  4951. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4952. #endif
  4953. RESET_MULTI_VALUE_STATS_VARS();
  4954. bench_stats_start(&count, &start);
  4955. do {
  4956. for (i = 0; i < numBlocks; i++) {
  4957. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  4958. if (ret < 0) {
  4959. printf("Sm4CbcDecrypt failed: %d\n", ret);
  4960. return;
  4961. }
  4962. RECORD_MULTI_VALUE_STATS();
  4963. }
  4964. count += i;
  4965. } while (bench_stats_check(start)
  4966. #ifdef MULTI_VALUE_STATISTICS
  4967. || runs < minimum_runs
  4968. #endif
  4969. );
  4970. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  4971. #ifdef MULTI_VALUE_STATISTICS
  4972. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4973. #endif
  4974. }
  4975. #endif
  4976. #ifdef WOLFSSL_SM4_GCM
  4977. void bench_sm4_gcm(void)
  4978. {
  4979. wc_Sm4 sm4;
  4980. double start;
  4981. int ret;
  4982. int i;
  4983. int count;
  4984. DECLARE_MULTI_VALUE_STATS_VARS()
  4985. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4986. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4987. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4988. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4989. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4990. if (ret != 0) {
  4991. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  4992. goto exit;
  4993. }
  4994. bench_stats_start(&count, &start);
  4995. do {
  4996. for (i = 0; i < numBlocks; i++) {
  4997. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  4998. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  4999. bench_additional, aesAuthAddSz);
  5000. if (ret < 0) {
  5001. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5002. goto exit;
  5003. }
  5004. RECORD_MULTI_VALUE_STATS();
  5005. }
  5006. count += i;
  5007. } while (bench_stats_check(start)
  5008. #ifdef MULTI_VALUE_STATISTICS
  5009. || runs < minimum_runs
  5010. #endif
  5011. );
  5012. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5013. #ifdef MULTI_VALUE_STATISTICS
  5014. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5015. #endif
  5016. RESET_MULTI_VALUE_STATS_VARS();
  5017. bench_stats_start(&count, &start);
  5018. do {
  5019. for (i = 0; i < numBlocks; i++) {
  5020. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5021. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5022. bench_additional, aesAuthAddSz);
  5023. if (ret < 0) {
  5024. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5025. goto exit;
  5026. }
  5027. RECORD_MULTI_VALUE_STATS();
  5028. }
  5029. count += i;
  5030. } while (bench_stats_check(start)
  5031. #ifdef MULTI_VALUE_STATISTICS
  5032. || runs < minimum_runs
  5033. #endif
  5034. );
  5035. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5036. #ifdef MULTI_VALUE_STATISTICS
  5037. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5038. #endif
  5039. exit:
  5040. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5041. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5042. }
  5043. #endif
  5044. #ifdef WOLFSSL_SM4_CCM
  5045. void bench_sm4_ccm(void)
  5046. {
  5047. wc_Sm4 enc;
  5048. double start;
  5049. int ret, i, count;
  5050. DECLARE_MULTI_VALUE_STATS_VARS()
  5051. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5052. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5053. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5054. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5055. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5056. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5057. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5058. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5059. goto exit;
  5060. }
  5061. bench_stats_start(&count, &start);
  5062. do {
  5063. for (i = 0; i < numBlocks; i++) {
  5064. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5065. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5066. bench_additional, 0);
  5067. RECORD_MULTI_VALUE_STATS();
  5068. }
  5069. count += i;
  5070. } while (bench_stats_check(start)
  5071. #ifdef MULTI_VALUE_STATISTICS
  5072. || runs < minimum_runs
  5073. #endif
  5074. );
  5075. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5076. #ifdef MULTI_VALUE_STATISTICS
  5077. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5078. #endif
  5079. if (ret != 0) {
  5080. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5081. goto exit;
  5082. }
  5083. RESET_MULTI_VALUE_STATS_VARS();
  5084. bench_stats_start(&count, &start);
  5085. do {
  5086. for (i = 0; i < numBlocks; i++) {
  5087. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5088. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5089. bench_additional, 0);
  5090. RECORD_MULTI_VALUE_STATS();
  5091. }
  5092. count += i;
  5093. } while (bench_stats_check(start)
  5094. #ifdef MULTI_VALUE_STATISTICS
  5095. || runs < minimum_runs
  5096. #endif
  5097. );
  5098. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5099. #ifdef MULTI_VALUE_STATISTICS
  5100. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5101. #endif
  5102. if (ret != 0) {
  5103. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5104. goto exit;
  5105. }
  5106. exit:
  5107. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5108. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5109. }
  5110. #endif /* HAVE_AESCCM */
  5111. #ifndef NO_DES3
  5112. void bench_des(int useDeviceID)
  5113. {
  5114. int ret = 0, i, count = 0, times, pending = 0;
  5115. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5116. sizeof(Des3), HEAP_HINT);
  5117. double start;
  5118. DECLARE_MULTI_VALUE_STATS_VARS()
  5119. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5120. sizeof(Des3), HEAP_HINT);
  5121. /* init keys */
  5122. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5123. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5124. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5125. printf("Des3Init failed, ret = %d\n", ret);
  5126. goto exit;
  5127. }
  5128. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5129. if (ret != 0) {
  5130. printf("Des3_SetKey failed, ret = %d\n", ret);
  5131. goto exit;
  5132. }
  5133. }
  5134. bench_stats_start(&count, &start);
  5135. do {
  5136. for (times = 0; times < numBlocks || pending > 0; ) {
  5137. bench_async_poll(&pending);
  5138. /* while free pending slots in queue, submit ops */
  5139. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5140. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5141. &times, numBlocks, &pending)) {
  5142. ret = wc_Des3_CbcEncrypt(enc[i],
  5143. bench_cipher,
  5144. bench_plain, bench_size);
  5145. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5146. 0, &times, &pending)) {
  5147. goto exit_3des;
  5148. }
  5149. }
  5150. } /* for i */
  5151. RECORD_MULTI_VALUE_STATS();
  5152. } /* for times */
  5153. count += times;
  5154. } while (bench_stats_check(start)
  5155. #ifdef MULTI_VALUE_STATISTICS
  5156. || runs < minimum_runs
  5157. #endif
  5158. );
  5159. exit_3des:
  5160. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5161. #ifdef MULTI_VALUE_STATISTICS
  5162. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5163. #endif
  5164. exit:
  5165. if (WC_ARRAY_OK(enc)) {
  5166. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5167. wc_Des3Free(enc[i]);
  5168. }
  5169. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5170. }
  5171. }
  5172. #endif /* !NO_DES3 */
  5173. #ifndef NO_RC4
  5174. void bench_arc4(int useDeviceID)
  5175. {
  5176. int ret = 0, i, count = 0, times, pending = 0;
  5177. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5178. sizeof(Arc4), HEAP_HINT);
  5179. double start;
  5180. DECLARE_MULTI_VALUE_STATS_VARS()
  5181. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5182. sizeof(Arc4), HEAP_HINT);
  5183. /* init keys */
  5184. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5185. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5186. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5187. printf("Arc4Init failed, ret = %d\n", ret);
  5188. goto exit;
  5189. }
  5190. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5191. if (ret != 0) {
  5192. printf("Arc4SetKey failed, ret = %d\n", ret);
  5193. goto exit;
  5194. }
  5195. }
  5196. bench_stats_start(&count, &start);
  5197. do {
  5198. for (times = 0; times < numBlocks || pending > 0; ) {
  5199. bench_async_poll(&pending);
  5200. /* while free pending slots in queue, submit ops */
  5201. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5202. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5203. &times, numBlocks, &pending)) {
  5204. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5205. bench_size);
  5206. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5207. 0, &times, &pending)) {
  5208. goto exit_arc4;
  5209. }
  5210. }
  5211. } /* for i */
  5212. RECORD_MULTI_VALUE_STATS();
  5213. } /* for times */
  5214. count += times;
  5215. } while (bench_stats_check(start)
  5216. #ifdef MULTI_VALUE_STATISTICS
  5217. || runs < minimum_runs
  5218. #endif
  5219. );
  5220. exit_arc4:
  5221. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5222. #ifdef MULTI_VALUE_STATISTICS
  5223. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5224. #endif
  5225. exit:
  5226. if (WC_ARRAY_OK(enc)) {
  5227. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5228. wc_Arc4Free(enc[i]);
  5229. }
  5230. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5231. }
  5232. }
  5233. #endif /* !NO_RC4 */
  5234. #ifdef HAVE_CHACHA
  5235. void bench_chacha(void)
  5236. {
  5237. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5238. double start;
  5239. int ret, i, count;
  5240. DECLARE_MULTI_VALUE_STATS_VARS()
  5241. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5242. XMEMSET(enc, 0, sizeof(ChaCha));
  5243. wc_Chacha_SetKey(enc, bench_key, 16);
  5244. if (encrypt_only) {
  5245. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5246. if (ret < 0) {
  5247. printf("wc_Chacha_SetIV error: %d\n", ret);
  5248. goto exit;
  5249. }
  5250. bench_stats_start(&count, &start);
  5251. do {
  5252. for (i = 0; i < numBlocks; i++) {
  5253. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5254. bench_size);
  5255. if (ret < 0) {
  5256. printf("wc_Chacha_Process error: %d\n", ret);
  5257. goto exit;
  5258. }
  5259. RECORD_MULTI_VALUE_STATS();
  5260. }
  5261. count += i;
  5262. } while (bench_stats_check(start)
  5263. #ifdef MULTI_VALUE_STATISTICS
  5264. || runs < minimum_runs
  5265. #endif
  5266. );
  5267. }
  5268. else {
  5269. bench_stats_start(&count, &start);
  5270. do {
  5271. for (i = 0; i < numBlocks; i++) {
  5272. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5273. if (ret < 0) {
  5274. printf("wc_Chacha_SetIV error: %d\n", ret);
  5275. goto exit;
  5276. }
  5277. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5278. bench_size);
  5279. if (ret < 0) {
  5280. printf("wc_Chacha_Process error: %d\n", ret);
  5281. goto exit;
  5282. }
  5283. RECORD_MULTI_VALUE_STATS();
  5284. }
  5285. count += i;
  5286. } while (bench_stats_check(start)
  5287. #ifdef MULTI_VALUE_STATISTICS
  5288. || runs < minimum_runs
  5289. #endif
  5290. );
  5291. }
  5292. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5293. #ifdef MULTI_VALUE_STATISTICS
  5294. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5295. #endif
  5296. exit:
  5297. WC_FREE_VAR(enc, HEAP_HINT);
  5298. }
  5299. #endif /* HAVE_CHACHA*/
  5300. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5301. void bench_chacha20_poly1305_aead(void)
  5302. {
  5303. double start;
  5304. int ret = 0, i, count;
  5305. DECLARE_MULTI_VALUE_STATS_VARS()
  5306. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5307. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5308. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5309. bench_stats_start(&count, &start);
  5310. do {
  5311. for (i = 0; i < numBlocks; i++) {
  5312. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5313. bench_plain, bench_size, bench_cipher, authTag);
  5314. if (ret < 0) {
  5315. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5316. goto exit;
  5317. }
  5318. RECORD_MULTI_VALUE_STATS();
  5319. }
  5320. count += i;
  5321. } while (bench_stats_check(start)
  5322. #ifdef MULTI_VALUE_STATISTICS
  5323. || runs < minimum_runs
  5324. #endif
  5325. );
  5326. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5327. #ifdef MULTI_VALUE_STATISTICS
  5328. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5329. #endif
  5330. exit:
  5331. WC_FREE_VAR(authTag, HEAP_HINT);
  5332. }
  5333. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5334. #ifndef NO_MD5
  5335. void bench_md5(int useDeviceID)
  5336. {
  5337. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5338. sizeof(wc_Md5), HEAP_HINT);
  5339. double start = 0;
  5340. int ret = 0, i, count = 0, times, pending = 0;
  5341. DECLARE_MULTI_VALUE_STATS_VARS()
  5342. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5343. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5344. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5345. sizeof(wc_Md5), HEAP_HINT);
  5346. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5347. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5348. if (digest_stream) {
  5349. /* init keys */
  5350. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5351. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5352. useDeviceID ? devId : INVALID_DEVID);
  5353. if (ret != 0) {
  5354. printf("InitMd5_ex failed, ret = %d\n", ret);
  5355. goto exit;
  5356. }
  5357. #ifdef WOLFSSL_PIC32MZ_HASH
  5358. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5359. #endif
  5360. }
  5361. bench_stats_start(&count, &start);
  5362. do {
  5363. for (times = 0; times < numBlocks || pending > 0; ) {
  5364. bench_async_poll(&pending);
  5365. /* while free pending slots in queue, submit ops */
  5366. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5367. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5368. 0, &times, numBlocks, &pending)) {
  5369. ret = wc_Md5Update(hash[i], bench_plain,
  5370. bench_size);
  5371. if (!bench_async_handle(&ret,
  5372. BENCH_ASYNC_GET_DEV(hash[i]),
  5373. 0, &times, &pending)) {
  5374. goto exit_md5;
  5375. }
  5376. }
  5377. } /* for i */
  5378. RECORD_MULTI_VALUE_STATS();
  5379. } /* for times */
  5380. count += times;
  5381. times = 0;
  5382. do {
  5383. bench_async_poll(&pending);
  5384. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5385. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5386. 0, &times, numBlocks, &pending)) {
  5387. ret = wc_Md5Final(hash[i], digest[i]);
  5388. if (!bench_async_handle(&ret,
  5389. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5390. &times, &pending)) {
  5391. goto exit_md5;
  5392. }
  5393. }
  5394. } /* for i */
  5395. } while (pending > 0);
  5396. } while (bench_stats_check(start)
  5397. #ifdef MULTI_VALUE_STATISTICS
  5398. || runs < minimum_runs
  5399. #endif
  5400. );
  5401. }
  5402. else {
  5403. bench_stats_start(&count, &start);
  5404. do {
  5405. for (times = 0; times < numBlocks; times++) {
  5406. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5407. if (ret == 0)
  5408. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5409. if (ret == 0)
  5410. ret = wc_Md5Final(hash[0], digest[0]);
  5411. if (ret != 0)
  5412. goto exit_md5;
  5413. RECORD_MULTI_VALUE_STATS();
  5414. } /* for times */
  5415. count += times;
  5416. } while (bench_stats_check(start)
  5417. #ifdef MULTI_VALUE_STATISTICS
  5418. || runs < minimum_runs
  5419. #endif
  5420. );
  5421. }
  5422. exit_md5:
  5423. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5424. #ifdef MULTI_VALUE_STATISTICS
  5425. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5426. #endif
  5427. exit:
  5428. #ifdef WOLFSSL_ASYNC_CRYPT
  5429. if (WC_ARRAY_OK(hash)) {
  5430. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5431. wc_Md5Free(hash[i]);
  5432. }
  5433. }
  5434. #endif
  5435. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5436. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5437. }
  5438. #endif /* !NO_MD5 */
  5439. #ifndef NO_SHA
  5440. void bench_sha(int useDeviceID)
  5441. {
  5442. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5443. sizeof(wc_Sha), HEAP_HINT);
  5444. double start;
  5445. int ret = 0, i, count = 0, times, pending = 0;
  5446. DECLARE_MULTI_VALUE_STATS_VARS()
  5447. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5448. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5449. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5450. sizeof(wc_Sha), HEAP_HINT);
  5451. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5452. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5453. if (digest_stream) {
  5454. /* init keys */
  5455. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5456. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5457. useDeviceID ? devId : INVALID_DEVID);
  5458. if (ret != 0) {
  5459. printf("InitSha failed, ret = %d\n", ret);
  5460. goto exit;
  5461. }
  5462. #ifdef WOLFSSL_PIC32MZ_HASH
  5463. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5464. #endif
  5465. }
  5466. bench_stats_start(&count, &start);
  5467. do {
  5468. for (times = 0; times < numBlocks || pending > 0; ) {
  5469. bench_async_poll(&pending);
  5470. /* while free pending slots in queue, submit ops */
  5471. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5472. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5473. 0, &times, numBlocks, &pending)) {
  5474. ret = wc_ShaUpdate(hash[i], bench_plain,
  5475. bench_size);
  5476. if (!bench_async_handle(&ret,
  5477. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5478. &times, &pending)) {
  5479. goto exit_sha;
  5480. }
  5481. }
  5482. } /* for i */
  5483. RECORD_MULTI_VALUE_STATS();
  5484. } /* for times */
  5485. count += times;
  5486. times = 0;
  5487. do {
  5488. bench_async_poll(&pending);
  5489. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5490. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5491. 0, &times, numBlocks, &pending)) {
  5492. ret = wc_ShaFinal(hash[i], digest[i]);
  5493. if (!bench_async_handle(&ret,
  5494. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5495. &times, &pending)) {
  5496. goto exit_sha;
  5497. }
  5498. }
  5499. } /* for i */
  5500. } while (pending > 0);
  5501. } while (bench_stats_check(start)
  5502. #ifdef MULTI_VALUE_STATISTICS
  5503. || runs < minimum_runs
  5504. #endif
  5505. );
  5506. }
  5507. else {
  5508. bench_stats_start(&count, &start);
  5509. do {
  5510. for (times = 0; times < numBlocks; times++) {
  5511. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5512. useDeviceID ? devId : INVALID_DEVID);
  5513. if (ret == 0)
  5514. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5515. if (ret == 0)
  5516. ret = wc_ShaFinal(hash[0], digest[0]);
  5517. if (ret != 0)
  5518. goto exit_sha;
  5519. RECORD_MULTI_VALUE_STATS();
  5520. } /* for times */
  5521. count += times;
  5522. } while (bench_stats_check(start)
  5523. #ifdef MULTI_VALUE_STATISTICS
  5524. || runs < minimum_runs
  5525. #endif
  5526. );
  5527. }
  5528. exit_sha:
  5529. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5530. #ifdef MULTI_VALUE_STATISTICS
  5531. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5532. #endif
  5533. exit:
  5534. if (WC_ARRAY_OK(hash)) {
  5535. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5536. wc_ShaFree(hash[i]);
  5537. }
  5538. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5539. }
  5540. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5541. }
  5542. #endif /* NO_SHA */
  5543. #ifdef WOLFSSL_SHA224
  5544. void bench_sha224(int useDeviceID)
  5545. {
  5546. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5547. sizeof(wc_Sha224), HEAP_HINT);
  5548. double start;
  5549. int ret = 0, i, count = 0, times, pending = 0;
  5550. DECLARE_MULTI_VALUE_STATS_VARS()
  5551. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5552. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5553. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5554. sizeof(wc_Sha224), HEAP_HINT);
  5555. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5556. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5557. if (digest_stream) {
  5558. /* init keys */
  5559. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5560. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5561. useDeviceID ? devId : INVALID_DEVID);
  5562. if (ret != 0) {
  5563. printf("InitSha224_ex failed, ret = %d\n", ret);
  5564. goto exit;
  5565. }
  5566. }
  5567. bench_stats_start(&count, &start);
  5568. do {
  5569. for (times = 0; times < numBlocks || pending > 0; ) {
  5570. bench_async_poll(&pending);
  5571. /* while free pending slots in queue, submit ops */
  5572. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5573. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5574. 0, &times, numBlocks, &pending)) {
  5575. ret = wc_Sha224Update(hash[i], bench_plain,
  5576. bench_size);
  5577. if (!bench_async_handle(&ret,
  5578. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5579. &times, &pending)) {
  5580. goto exit_sha224;
  5581. }
  5582. }
  5583. } /* for i */
  5584. RECORD_MULTI_VALUE_STATS();
  5585. } /* for times */
  5586. count += times;
  5587. times = 0;
  5588. do {
  5589. bench_async_poll(&pending);
  5590. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5591. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5592. 0, &times, numBlocks, &pending)) {
  5593. ret = wc_Sha224Final(hash[i], digest[i]);
  5594. if (!bench_async_handle(&ret,
  5595. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5596. &times, &pending)) {
  5597. goto exit_sha224;
  5598. }
  5599. }
  5600. } /* for i */
  5601. } while (pending > 0);
  5602. } while (bench_stats_check(start)
  5603. #ifdef MULTI_VALUE_STATISTICS
  5604. || runs < minimum_runs
  5605. #endif
  5606. );
  5607. }
  5608. else {
  5609. bench_stats_start(&count, &start);
  5610. do {
  5611. for (times = 0; times < numBlocks; times++) {
  5612. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5613. useDeviceID ? devId : INVALID_DEVID);
  5614. if (ret == 0)
  5615. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5616. if (ret == 0)
  5617. ret = wc_Sha224Final(hash[0], digest[0]);
  5618. if (ret != 0)
  5619. goto exit_sha224;
  5620. } /* for times */
  5621. count += times;
  5622. } while (bench_stats_check(start)
  5623. #ifdef MULTI_VALUE_STATISTICS
  5624. || runs < minimum_runs
  5625. #endif
  5626. );
  5627. }
  5628. exit_sha224:
  5629. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5630. bench_size, start, ret);
  5631. #ifdef MULTI_VALUE_STATISTICS
  5632. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5633. #endif
  5634. exit:
  5635. if (WC_ARRAY_OK(hash)) {
  5636. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5637. wc_Sha224Free(hash[i]);
  5638. }
  5639. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5640. }
  5641. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5642. }
  5643. #endif
  5644. #ifndef NO_SHA256
  5645. void bench_sha256(int useDeviceID)
  5646. {
  5647. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5648. sizeof(wc_Sha256), HEAP_HINT);
  5649. double start;
  5650. int ret = 0, i, count = 0, times, pending = 0;
  5651. DECLARE_MULTI_VALUE_STATS_VARS()
  5652. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5653. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5654. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5655. sizeof(wc_Sha256), HEAP_HINT);
  5656. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5657. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5658. if (digest_stream) {
  5659. /* init keys */
  5660. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5661. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5662. useDeviceID ? devId: INVALID_DEVID);
  5663. if (ret != 0) {
  5664. printf("InitSha256_ex failed, ret = %d\n", ret);
  5665. goto exit;
  5666. }
  5667. #ifdef WOLFSSL_PIC32MZ_HASH
  5668. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5669. #endif
  5670. }
  5671. bench_stats_start(&count, &start);
  5672. do {
  5673. for (times = 0; times < numBlocks || pending > 0; ) {
  5674. bench_async_poll(&pending);
  5675. /* while free pending slots in queue, submit ops */
  5676. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5677. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5678. 0, &times, numBlocks, &pending)) {
  5679. ret = wc_Sha256Update(hash[i], bench_plain,
  5680. bench_size);
  5681. if (!bench_async_handle(&ret,
  5682. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5683. &times, &pending)) {
  5684. goto exit_sha256;
  5685. }
  5686. }
  5687. } /* for i */
  5688. RECORD_MULTI_VALUE_STATS();
  5689. } /* for times */
  5690. count += times;
  5691. times = 0;
  5692. do {
  5693. bench_async_poll(&pending);
  5694. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5695. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5696. 0, &times, numBlocks, &pending)) {
  5697. ret = wc_Sha256Final(hash[i], digest[i]);
  5698. if (!bench_async_handle(&ret,
  5699. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5700. &times, &pending)) {
  5701. goto exit_sha256;
  5702. }
  5703. }
  5704. } /* for i */
  5705. } while (pending > 0);
  5706. } while (bench_stats_check(start)
  5707. #ifdef MULTI_VALUE_STATISTICS
  5708. || runs < minimum_runs
  5709. #endif
  5710. );
  5711. }
  5712. else {
  5713. bench_stats_start(&count, &start);
  5714. do {
  5715. for (times = 0; times < numBlocks; times++) {
  5716. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5717. useDeviceID ? devId: INVALID_DEVID);
  5718. if (ret == 0)
  5719. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5720. if (ret == 0)
  5721. ret = wc_Sha256Final(hash[0], digest[0]);
  5722. if (ret != 0)
  5723. goto exit_sha256;
  5724. RECORD_MULTI_VALUE_STATS();
  5725. } /* for times */
  5726. count += times;
  5727. } while (bench_stats_check(start)
  5728. #ifdef MULTI_VALUE_STATISTICS
  5729. || runs < minimum_runs
  5730. #endif
  5731. );
  5732. }
  5733. exit_sha256:
  5734. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5735. start, ret);
  5736. #ifdef MULTI_VALUE_STATISTICS
  5737. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5738. #endif
  5739. exit:
  5740. if (WC_ARRAY_OK(hash)) {
  5741. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5742. wc_Sha256Free(hash[i]);
  5743. }
  5744. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5745. }
  5746. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5747. }
  5748. #endif
  5749. #ifdef WOLFSSL_SHA384
  5750. void bench_sha384(int useDeviceID)
  5751. {
  5752. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5753. sizeof(wc_Sha384), HEAP_HINT);
  5754. double start;
  5755. int ret = 0, i, count = 0, times, pending = 0;
  5756. DECLARE_MULTI_VALUE_STATS_VARS()
  5757. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5758. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5759. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5760. sizeof(wc_Sha384), HEAP_HINT);
  5761. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5762. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5763. if (digest_stream) {
  5764. /* init keys */
  5765. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5766. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5767. useDeviceID ? devId : INVALID_DEVID);
  5768. if (ret != 0) {
  5769. printf("InitSha384_ex failed, ret = %d\n", ret);
  5770. goto exit;
  5771. }
  5772. }
  5773. bench_stats_start(&count, &start);
  5774. do {
  5775. for (times = 0; times < numBlocks || pending > 0; ) {
  5776. bench_async_poll(&pending);
  5777. /* while free pending slots in queue, submit ops */
  5778. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5779. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5780. 0, &times, numBlocks, &pending)) {
  5781. ret = wc_Sha384Update(hash[i], bench_plain,
  5782. bench_size);
  5783. if (!bench_async_handle(&ret,
  5784. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5785. &times, &pending)) {
  5786. goto exit_sha384;
  5787. }
  5788. }
  5789. } /* for i */
  5790. RECORD_MULTI_VALUE_STATS();
  5791. } /* for times */
  5792. count += times;
  5793. times = 0;
  5794. do {
  5795. bench_async_poll(&pending);
  5796. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5797. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5798. 0, &times, numBlocks, &pending)) {
  5799. ret = wc_Sha384Final(hash[i], digest[i]);
  5800. if (!bench_async_handle(&ret,
  5801. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5802. &times, &pending)) {
  5803. goto exit_sha384;
  5804. }
  5805. }
  5806. } /* for i */
  5807. } while (pending > 0);
  5808. } while (bench_stats_check(start)
  5809. #ifdef MULTI_VALUE_STATISTICS
  5810. || runs < minimum_runs
  5811. #endif
  5812. );
  5813. }
  5814. else {
  5815. bench_stats_start(&count, &start);
  5816. do {
  5817. for (times = 0; times < numBlocks; times++) {
  5818. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5819. useDeviceID ? devId : INVALID_DEVID);
  5820. if (ret == 0)
  5821. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5822. if (ret == 0)
  5823. ret = wc_Sha384Final(hash[0], digest[0]);
  5824. if (ret != 0)
  5825. goto exit_sha384;
  5826. RECORD_MULTI_VALUE_STATS();
  5827. } /* for times */
  5828. count += times;
  5829. } while (bench_stats_check(start)
  5830. #ifdef MULTI_VALUE_STATISTICS
  5831. || runs < minimum_runs
  5832. #endif
  5833. );
  5834. }
  5835. exit_sha384:
  5836. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5837. start, ret);
  5838. #ifdef MULTI_VALUE_STATISTICS
  5839. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5840. #endif
  5841. exit:
  5842. if (WC_ARRAY_OK(hash)) {
  5843. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5844. wc_Sha384Free(hash[i]);
  5845. }
  5846. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5847. }
  5848. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5849. }
  5850. #endif
  5851. #ifdef WOLFSSL_SHA512
  5852. void bench_sha512(int useDeviceID)
  5853. {
  5854. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5855. sizeof(wc_Sha512), HEAP_HINT);
  5856. double start;
  5857. int ret = 0, i, count = 0, times, pending = 0;
  5858. DECLARE_MULTI_VALUE_STATS_VARS()
  5859. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5860. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5861. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5862. sizeof(wc_Sha512), HEAP_HINT);
  5863. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5864. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5865. if (digest_stream) {
  5866. /* init keys */
  5867. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5868. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5869. useDeviceID ? devId : INVALID_DEVID);
  5870. if (ret != 0) {
  5871. printf("InitSha512_ex failed, ret = %d\n", ret);
  5872. goto exit;
  5873. }
  5874. }
  5875. bench_stats_start(&count, &start);
  5876. do {
  5877. for (times = 0; times < numBlocks || pending > 0; ) {
  5878. bench_async_poll(&pending);
  5879. /* while free pending slots in queue, submit ops */
  5880. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5881. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5882. 0, &times, numBlocks, &pending)) {
  5883. ret = wc_Sha512Update(hash[i], bench_plain,
  5884. bench_size);
  5885. if (!bench_async_handle(&ret,
  5886. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5887. &times, &pending)) {
  5888. goto exit_sha512;
  5889. }
  5890. }
  5891. } /* for i */
  5892. RECORD_MULTI_VALUE_STATS();
  5893. } /* for times */
  5894. count += times;
  5895. times = 0;
  5896. do {
  5897. bench_async_poll(&pending);
  5898. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5899. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5900. 0, &times, numBlocks, &pending)) {
  5901. ret = wc_Sha512Final(hash[i], digest[i]);
  5902. if (!bench_async_handle(&ret,
  5903. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5904. &times, &pending)) {
  5905. goto exit_sha512;
  5906. }
  5907. }
  5908. } /* for i */
  5909. } while (pending > 0);
  5910. } while (bench_stats_check(start)
  5911. #ifdef MULTI_VALUE_STATISTICS
  5912. || runs < minimum_runs
  5913. #endif
  5914. );
  5915. }
  5916. else {
  5917. bench_stats_start(&count, &start);
  5918. do {
  5919. for (times = 0; times < numBlocks; times++) {
  5920. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  5921. useDeviceID ? devId : INVALID_DEVID);
  5922. if (ret == 0)
  5923. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  5924. if (ret == 0)
  5925. ret = wc_Sha512Final(hash[0], digest[0]);
  5926. if (ret != 0)
  5927. goto exit_sha512;
  5928. RECORD_MULTI_VALUE_STATS();
  5929. } /* for times */
  5930. count += times;
  5931. } while (bench_stats_check(start)
  5932. #ifdef MULTI_VALUE_STATISTICS
  5933. || runs < minimum_runs
  5934. #endif
  5935. );
  5936. }
  5937. exit_sha512:
  5938. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  5939. start, ret);
  5940. #ifdef MULTI_VALUE_STATISTICS
  5941. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5942. #endif
  5943. exit:
  5944. if (WC_ARRAY_OK(hash)) {
  5945. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5946. wc_Sha512Free(hash[i]);
  5947. }
  5948. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5949. }
  5950. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5951. }
  5952. #if !defined(WOLFSSL_NOSHA512_224) && \
  5953. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  5954. void bench_sha512_224(int useDeviceID)
  5955. {
  5956. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  5957. sizeof(wc_Sha512_224), HEAP_HINT);
  5958. double start;
  5959. int ret = 0, i, count = 0, times, pending = 0;
  5960. DECLARE_MULTI_VALUE_STATS_VARS()
  5961. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5962. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  5963. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  5964. sizeof(wc_Sha512_224), HEAP_HINT);
  5965. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5966. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  5967. if (digest_stream) {
  5968. /* init keys */
  5969. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5970. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  5971. useDeviceID ? devId : INVALID_DEVID);
  5972. if (ret != 0) {
  5973. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  5974. goto exit;
  5975. }
  5976. }
  5977. bench_stats_start(&count, &start);
  5978. do {
  5979. for (times = 0; times < numBlocks || pending > 0; ) {
  5980. bench_async_poll(&pending);
  5981. /* while free pending slots in queue, submit ops */
  5982. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5983. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5984. 0, &times, numBlocks, &pending)) {
  5985. ret = wc_Sha512_224Update(hash[i], bench_plain,
  5986. bench_size);
  5987. if (!bench_async_handle(&ret,
  5988. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5989. &times, &pending)) {
  5990. goto exit_sha512_224;
  5991. }
  5992. }
  5993. } /* for i */
  5994. RECORD_MULTI_VALUE_STATS();
  5995. } /* for times */
  5996. count += times;
  5997. times = 0;
  5998. do {
  5999. bench_async_poll(&pending);
  6000. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6001. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6002. 0, &times, numBlocks, &pending)) {
  6003. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6004. if (!bench_async_handle(&ret,
  6005. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6006. &times, &pending)) {
  6007. goto exit_sha512_224;
  6008. }
  6009. }
  6010. } /* for i */
  6011. } while (pending > 0);
  6012. } while (bench_stats_check(start)
  6013. #ifdef MULTI_VALUE_STATISTICS
  6014. || runs < minimum_runs
  6015. #endif
  6016. );
  6017. }
  6018. else {
  6019. bench_stats_start(&count, &start);
  6020. do {
  6021. for (times = 0; times < numBlocks; times++) {
  6022. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6023. useDeviceID ? devId : INVALID_DEVID);
  6024. if (ret == 0)
  6025. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6026. if (ret == 0)
  6027. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6028. if (ret != 0)
  6029. goto exit_sha512_224;
  6030. RECORD_MULTI_VALUE_STATS();
  6031. } /* for times */
  6032. count += times;
  6033. } while (bench_stats_check(start)
  6034. #ifdef MULTI_VALUE_STATISTICS
  6035. || runs < minimum_runs
  6036. #endif
  6037. );
  6038. }
  6039. exit_sha512_224:
  6040. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6041. start, ret);
  6042. #ifdef MULTI_VALUE_STATISTICS
  6043. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6044. #endif
  6045. exit:
  6046. if (WC_ARRAY_OK(hash)) {
  6047. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6048. wc_Sha512_224Free(hash[i]);
  6049. }
  6050. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6051. }
  6052. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6053. }
  6054. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6055. #if !defined(WOLFSSL_NOSHA512_256) && \
  6056. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6057. void bench_sha512_256(int useDeviceID)
  6058. {
  6059. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6060. sizeof(wc_Sha512_256), HEAP_HINT);
  6061. double start;
  6062. int ret = 0, i, count = 0, times, pending = 0;
  6063. DECLARE_MULTI_VALUE_STATS_VARS()
  6064. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6065. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6066. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6067. sizeof(wc_Sha512_256), HEAP_HINT);
  6068. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6069. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6070. if (digest_stream) {
  6071. /* init keys */
  6072. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6073. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6074. useDeviceID ? devId : INVALID_DEVID);
  6075. if (ret != 0) {
  6076. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6077. goto exit;
  6078. }
  6079. }
  6080. bench_stats_start(&count, &start);
  6081. do {
  6082. for (times = 0; times < numBlocks || pending > 0; ) {
  6083. bench_async_poll(&pending);
  6084. /* while free pending slots in queue, submit ops */
  6085. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6086. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6087. 0, &times, numBlocks, &pending)) {
  6088. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6089. bench_size);
  6090. if (!bench_async_handle(&ret,
  6091. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6092. &times, &pending)) {
  6093. goto exit_sha512_256;
  6094. }
  6095. }
  6096. } /* for i */
  6097. RECORD_MULTI_VALUE_STATS();
  6098. } /* for times */
  6099. count += times;
  6100. times = 0;
  6101. do {
  6102. bench_async_poll(&pending);
  6103. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6104. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6105. 0, &times, numBlocks, &pending)) {
  6106. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6107. if (!bench_async_handle(&ret,
  6108. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6109. &times, &pending)) {
  6110. goto exit_sha512_256;
  6111. }
  6112. }
  6113. } /* for i */
  6114. } while (pending > 0);
  6115. } while (bench_stats_check(start)
  6116. #ifdef MULTI_VALUE_STATISTICS
  6117. || runs < minimum_runs
  6118. #endif
  6119. );
  6120. }
  6121. else {
  6122. bench_stats_start(&count, &start);
  6123. do {
  6124. for (times = 0; times < numBlocks; times++) {
  6125. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6126. useDeviceID ? devId : INVALID_DEVID);
  6127. if (ret == 0)
  6128. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6129. if (ret == 0)
  6130. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6131. if (ret != 0)
  6132. goto exit_sha512_256;
  6133. RECORD_MULTI_VALUE_STATS();
  6134. } /* for times */
  6135. count += times;
  6136. } while (bench_stats_check(start)
  6137. #ifdef MULTI_VALUE_STATISTICS
  6138. || runs < minimum_runs
  6139. #endif
  6140. );
  6141. }
  6142. exit_sha512_256:
  6143. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6144. start, ret);
  6145. #ifdef MULTI_VALUE_STATISTICS
  6146. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6147. #endif
  6148. exit:
  6149. if (WC_ARRAY_OK(hash)) {
  6150. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6151. wc_Sha512_256Free(hash[i]);
  6152. }
  6153. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6154. }
  6155. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6156. }
  6157. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6158. #endif /* WOLFSSL_SHA512 */
  6159. #ifdef WOLFSSL_SHA3
  6160. #ifndef WOLFSSL_NOSHA3_224
  6161. void bench_sha3_224(int useDeviceID)
  6162. {
  6163. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6164. sizeof(wc_Sha3), HEAP_HINT);
  6165. double start;
  6166. int ret = 0, i, count = 0, times, pending = 0;
  6167. DECLARE_MULTI_VALUE_STATS_VARS()
  6168. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6169. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6170. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6171. sizeof(wc_Sha3), HEAP_HINT);
  6172. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6173. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6174. if (digest_stream) {
  6175. /* init keys */
  6176. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6177. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6178. useDeviceID ? devId : INVALID_DEVID);
  6179. if (ret != 0) {
  6180. printf("InitSha3_224 failed, ret = %d\n", ret);
  6181. goto exit;
  6182. }
  6183. }
  6184. bench_stats_start(&count, &start);
  6185. do {
  6186. for (times = 0; times < numBlocks || pending > 0; ) {
  6187. bench_async_poll(&pending);
  6188. /* while free pending slots in queue, submit ops */
  6189. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6190. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6191. 0, &times, numBlocks, &pending)) {
  6192. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6193. bench_size);
  6194. if (!bench_async_handle(&ret,
  6195. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6196. &times, &pending)) {
  6197. goto exit_sha3_224;
  6198. }
  6199. }
  6200. } /* for i */
  6201. RECORD_MULTI_VALUE_STATS();
  6202. } /* for times */
  6203. count += times;
  6204. times = 0;
  6205. do {
  6206. bench_async_poll(&pending);
  6207. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6208. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6209. 0, &times, numBlocks, &pending)) {
  6210. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6211. if (!bench_async_handle(&ret,
  6212. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6213. &times, &pending)) {
  6214. goto exit_sha3_224;
  6215. }
  6216. }
  6217. } /* for i */
  6218. } while (pending > 0);
  6219. } while (bench_stats_check(start)
  6220. #ifdef MULTI_VALUE_STATISTICS
  6221. || runs < minimum_runs
  6222. #endif
  6223. );
  6224. }
  6225. else {
  6226. bench_stats_start(&count, &start);
  6227. do {
  6228. for (times = 0; times < numBlocks; times++) {
  6229. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6230. useDeviceID ? devId : INVALID_DEVID);
  6231. if (ret == 0)
  6232. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6233. if (ret == 0)
  6234. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6235. if (ret != 0)
  6236. goto exit_sha3_224;
  6237. RECORD_MULTI_VALUE_STATS();
  6238. } /* for times */
  6239. count += times;
  6240. } while (bench_stats_check(start)
  6241. #ifdef MULTI_VALUE_STATISTICS
  6242. || runs < minimum_runs
  6243. #endif
  6244. );
  6245. }
  6246. exit_sha3_224:
  6247. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6248. start, ret);
  6249. #ifdef MULTI_VALUE_STATISTICS
  6250. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6251. #endif
  6252. exit:
  6253. if (WC_ARRAY_OK(hash)) {
  6254. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6255. wc_Sha3_224_Free(hash[i]);
  6256. }
  6257. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6258. }
  6259. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6260. }
  6261. #endif /* WOLFSSL_NOSHA3_224 */
  6262. #ifndef WOLFSSL_NOSHA3_256
  6263. void bench_sha3_256(int useDeviceID)
  6264. {
  6265. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6266. sizeof(wc_Sha3), HEAP_HINT);
  6267. double start;
  6268. DECLARE_MULTI_VALUE_STATS_VARS()
  6269. int ret = 0, i, count = 0, times, pending = 0;
  6270. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6271. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6272. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6273. sizeof(wc_Sha3), HEAP_HINT);
  6274. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6275. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6276. if (digest_stream) {
  6277. /* init keys */
  6278. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6279. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6280. useDeviceID ? devId : INVALID_DEVID);
  6281. if (ret != 0) {
  6282. printf("InitSha3_256 failed, ret = %d\n", ret);
  6283. goto exit;
  6284. }
  6285. }
  6286. bench_stats_start(&count, &start);
  6287. do {
  6288. for (times = 0; times < numBlocks || pending > 0; ) {
  6289. bench_async_poll(&pending);
  6290. /* while free pending slots in queue, submit ops */
  6291. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6292. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6293. 0, &times, numBlocks, &pending)) {
  6294. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6295. bench_size);
  6296. if (!bench_async_handle(&ret,
  6297. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6298. &times, &pending)) {
  6299. goto exit_sha3_256;
  6300. }
  6301. }
  6302. } /* for i */
  6303. RECORD_MULTI_VALUE_STATS();
  6304. } /* for times */
  6305. count += times;
  6306. times = 0;
  6307. do {
  6308. bench_async_poll(&pending);
  6309. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6310. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6311. 0, &times, numBlocks, &pending)) {
  6312. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6313. if (!bench_async_handle(&ret,
  6314. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6315. &times, &pending)) {
  6316. goto exit_sha3_256;
  6317. }
  6318. }
  6319. } /* for i */
  6320. } while (pending > 0);
  6321. } while (bench_stats_check(start)
  6322. #ifdef MULTI_VALUE_STATISTICS
  6323. || runs < minimum_runs
  6324. #endif
  6325. );
  6326. }
  6327. else {
  6328. bench_stats_start(&count, &start);
  6329. do {
  6330. for (times = 0; times < numBlocks; times++) {
  6331. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6332. useDeviceID ? devId : INVALID_DEVID);
  6333. if (ret == 0)
  6334. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6335. if (ret == 0)
  6336. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6337. if (ret != 0)
  6338. goto exit_sha3_256;
  6339. RECORD_MULTI_VALUE_STATS();
  6340. } /* for times */
  6341. count += times;
  6342. } while (bench_stats_check(start)
  6343. #ifdef MULTI_VALUE_STATISTICS
  6344. || runs < minimum_runs
  6345. #endif
  6346. );
  6347. }
  6348. exit_sha3_256:
  6349. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6350. start, ret);
  6351. #ifdef MULTI_VALUE_STATISTICS
  6352. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6353. #endif
  6354. exit:
  6355. if (WC_ARRAY_OK(hash)) {
  6356. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6357. wc_Sha3_256_Free(hash[i]);
  6358. }
  6359. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6360. }
  6361. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6362. }
  6363. #endif /* WOLFSSL_NOSHA3_256 */
  6364. #ifndef WOLFSSL_NOSHA3_384
  6365. void bench_sha3_384(int useDeviceID)
  6366. {
  6367. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6368. sizeof(wc_Sha3), HEAP_HINT);
  6369. double start;
  6370. int ret = 0, i, count = 0, times, pending = 0;
  6371. DECLARE_MULTI_VALUE_STATS_VARS()
  6372. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6373. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6374. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6375. sizeof(wc_Sha3), HEAP_HINT);
  6376. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6377. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6378. if (digest_stream) {
  6379. /* init keys */
  6380. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6381. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6382. useDeviceID ? devId : INVALID_DEVID);
  6383. if (ret != 0) {
  6384. printf("InitSha3_384 failed, ret = %d\n", ret);
  6385. goto exit;
  6386. }
  6387. }
  6388. bench_stats_start(&count, &start);
  6389. do {
  6390. for (times = 0; times < numBlocks || pending > 0; ) {
  6391. bench_async_poll(&pending);
  6392. /* while free pending slots in queue, submit ops */
  6393. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6394. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6395. 0, &times, numBlocks, &pending)) {
  6396. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6397. bench_size);
  6398. if (!bench_async_handle(&ret,
  6399. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6400. &times, &pending)) {
  6401. goto exit_sha3_384;
  6402. }
  6403. }
  6404. } /* for i */
  6405. RECORD_MULTI_VALUE_STATS();
  6406. } /* for times */
  6407. count += times;
  6408. times = 0;
  6409. do {
  6410. bench_async_poll(&pending);
  6411. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6412. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6413. 0, &times, numBlocks, &pending)) {
  6414. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6415. if (!bench_async_handle(&ret,
  6416. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6417. &times, &pending)) {
  6418. goto exit_sha3_384;
  6419. }
  6420. }
  6421. } /* for i */
  6422. } while (pending > 0);
  6423. } while (bench_stats_check(start)
  6424. #ifdef MULTI_VALUE_STATISTICS
  6425. || runs < minimum_runs
  6426. #endif
  6427. );
  6428. }
  6429. else {
  6430. bench_stats_start(&count, &start);
  6431. do {
  6432. for (times = 0; times < numBlocks; times++) {
  6433. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6434. useDeviceID ? devId : INVALID_DEVID);
  6435. if (ret == 0)
  6436. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6437. if (ret == 0)
  6438. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6439. if (ret != 0)
  6440. goto exit_sha3_384;
  6441. RECORD_MULTI_VALUE_STATS();
  6442. } /* for times */
  6443. count += times;
  6444. } while (bench_stats_check(start)
  6445. #ifdef MULTI_VALUE_STATISTICS
  6446. || runs < minimum_runs
  6447. #endif
  6448. );
  6449. }
  6450. exit_sha3_384:
  6451. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6452. start, ret);
  6453. #ifdef MULTI_VALUE_STATISTICS
  6454. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6455. #endif
  6456. exit:
  6457. if (WC_ARRAY_OK(hash)) {
  6458. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6459. wc_Sha3_384_Free(hash[i]);
  6460. }
  6461. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6462. }
  6463. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6464. }
  6465. #endif /* WOLFSSL_NOSHA3_384 */
  6466. #ifndef WOLFSSL_NOSHA3_512
  6467. void bench_sha3_512(int useDeviceID)
  6468. {
  6469. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6470. sizeof(wc_Sha3), HEAP_HINT);
  6471. double start;
  6472. int ret = 0, i, count = 0, times, pending = 0;
  6473. DECLARE_MULTI_VALUE_STATS_VARS()
  6474. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6475. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6476. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6477. sizeof(wc_Sha3), HEAP_HINT);
  6478. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6479. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6480. if (digest_stream) {
  6481. /* init keys */
  6482. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6483. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6484. useDeviceID ? devId : INVALID_DEVID);
  6485. if (ret != 0) {
  6486. printf("InitSha3_512 failed, ret = %d\n", ret);
  6487. goto exit;
  6488. }
  6489. }
  6490. bench_stats_start(&count, &start);
  6491. do {
  6492. for (times = 0; times < numBlocks || pending > 0; ) {
  6493. bench_async_poll(&pending);
  6494. /* while free pending slots in queue, submit ops */
  6495. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6496. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6497. 0, &times, numBlocks, &pending)) {
  6498. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6499. bench_size);
  6500. if (!bench_async_handle(&ret,
  6501. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6502. &times, &pending)) {
  6503. goto exit_sha3_512;
  6504. }
  6505. }
  6506. } /* for i */
  6507. RECORD_MULTI_VALUE_STATS();
  6508. } /* for times */
  6509. count += times;
  6510. times = 0;
  6511. do {
  6512. bench_async_poll(&pending);
  6513. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6514. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6515. 0, &times, numBlocks, &pending)) {
  6516. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6517. if (!bench_async_handle(&ret,
  6518. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6519. &times, &pending)) {
  6520. goto exit_sha3_512;
  6521. }
  6522. }
  6523. } /* for i */
  6524. } while (pending > 0);
  6525. } while (bench_stats_check(start)
  6526. #ifdef MULTI_VALUE_STATISTICS
  6527. || runs < minimum_runs
  6528. #endif
  6529. );
  6530. }
  6531. else {
  6532. bench_stats_start(&count, &start);
  6533. do {
  6534. for (times = 0; times < numBlocks; times++) {
  6535. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6536. useDeviceID ? devId : INVALID_DEVID);
  6537. if (ret == 0)
  6538. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6539. if (ret == 0)
  6540. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6541. if (ret != 0)
  6542. goto exit_sha3_512;
  6543. RECORD_MULTI_VALUE_STATS();
  6544. } /* for times */
  6545. count += times;
  6546. } while (bench_stats_check(start)
  6547. #ifdef MULTI_VALUE_STATISTICS
  6548. || runs < minimum_runs
  6549. #endif
  6550. );
  6551. }
  6552. exit_sha3_512:
  6553. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6554. start, ret);
  6555. #ifdef MULTI_VALUE_STATISTICS
  6556. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6557. #endif
  6558. exit:
  6559. if (WC_ARRAY_OK(hash)) {
  6560. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6561. wc_Sha3_512_Free(hash[i]);
  6562. }
  6563. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6564. }
  6565. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6566. }
  6567. #endif /* WOLFSSL_NOSHA3_512 */
  6568. #ifdef WOLFSSL_SHAKE128
  6569. void bench_shake128(int useDeviceID)
  6570. {
  6571. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6572. sizeof(wc_Shake), HEAP_HINT);
  6573. double start;
  6574. int ret = 0, i, count = 0, times, pending = 0;
  6575. DECLARE_MULTI_VALUE_STATS_VARS()
  6576. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6577. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6578. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6579. sizeof(wc_Shake), HEAP_HINT);
  6580. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6581. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6582. if (digest_stream) {
  6583. /* init keys */
  6584. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6585. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6586. useDeviceID ? devId : INVALID_DEVID);
  6587. if (ret != 0) {
  6588. printf("InitShake128 failed, ret = %d\n", ret);
  6589. goto exit;
  6590. }
  6591. }
  6592. bench_stats_start(&count, &start);
  6593. do {
  6594. for (times = 0; times < numBlocks || pending > 0; ) {
  6595. bench_async_poll(&pending);
  6596. /* while free pending slots in queue, submit ops */
  6597. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6598. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6599. 0, &times, numBlocks, &pending)) {
  6600. ret = wc_Shake128_Update(hash[i], bench_plain,
  6601. bench_size);
  6602. if (!bench_async_handle(&ret,
  6603. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6604. &times, &pending)) {
  6605. goto exit_shake128;
  6606. }
  6607. }
  6608. } /* for i */
  6609. RECORD_MULTI_VALUE_STATS();
  6610. } /* for times */
  6611. count += times;
  6612. times = 0;
  6613. do {
  6614. bench_async_poll(&pending);
  6615. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6616. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6617. 0, &times, numBlocks, &pending)) {
  6618. ret = wc_Shake128_Final(hash[i], digest[i],
  6619. WC_SHA3_128_BLOCK_SIZE);
  6620. if (!bench_async_handle(&ret,
  6621. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6622. &times, &pending)) {
  6623. goto exit_shake128;
  6624. }
  6625. }
  6626. } /* for i */
  6627. } while (pending > 0);
  6628. } while (bench_stats_check(start)
  6629. #ifdef MULTI_VALUE_STATISTICS
  6630. || runs < minimum_runs
  6631. #endif
  6632. );
  6633. }
  6634. else {
  6635. bench_stats_start(&count, &start);
  6636. do {
  6637. for (times = 0; times < numBlocks; times++) {
  6638. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6639. useDeviceID ? devId : INVALID_DEVID);
  6640. if (ret == 0)
  6641. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6642. if (ret == 0)
  6643. ret = wc_Shake128_Final(hash[0], digest[0],
  6644. WC_SHA3_128_BLOCK_SIZE);
  6645. if (ret != 0)
  6646. goto exit_shake128;
  6647. RECORD_MULTI_VALUE_STATS();
  6648. } /* for times */
  6649. count += times;
  6650. } while (bench_stats_check(start)
  6651. #ifdef MULTI_VALUE_STATISTICS
  6652. || runs < minimum_runs
  6653. #endif
  6654. );
  6655. }
  6656. exit_shake128:
  6657. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6658. start, ret);
  6659. #ifdef MULTI_VALUE_STATISTICS
  6660. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6661. #endif
  6662. exit:
  6663. if (WC_ARRAY_OK(hash)) {
  6664. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6665. wc_Shake128_Free(hash[i]);
  6666. }
  6667. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6668. }
  6669. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6670. }
  6671. #endif /* WOLFSSL_SHAKE128 */
  6672. #ifdef WOLFSSL_SHAKE256
  6673. void bench_shake256(int useDeviceID)
  6674. {
  6675. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6676. sizeof(wc_Shake), HEAP_HINT);
  6677. double start;
  6678. int ret = 0, i, count = 0, times, pending = 0;
  6679. DECLARE_MULTI_VALUE_STATS_VARS()
  6680. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6681. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6682. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6683. sizeof(wc_Shake), HEAP_HINT);
  6684. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6685. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6686. if (digest_stream) {
  6687. /* init keys */
  6688. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6689. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6690. useDeviceID ? devId : INVALID_DEVID);
  6691. if (ret != 0) {
  6692. printf("InitShake256 failed, ret = %d\n", ret);
  6693. goto exit;
  6694. }
  6695. }
  6696. bench_stats_start(&count, &start);
  6697. do {
  6698. for (times = 0; times < numBlocks || pending > 0; ) {
  6699. bench_async_poll(&pending);
  6700. /* while free pending slots in queue, submit ops */
  6701. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6702. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6703. 0, &times, numBlocks, &pending)) {
  6704. ret = wc_Shake256_Update(hash[i], bench_plain,
  6705. bench_size);
  6706. if (!bench_async_handle(&ret,
  6707. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6708. &times, &pending)) {
  6709. goto exit_shake256;
  6710. }
  6711. }
  6712. } /* for i */
  6713. RECORD_MULTI_VALUE_STATS();
  6714. } /* for times */
  6715. count += times;
  6716. times = 0;
  6717. do {
  6718. bench_async_poll(&pending);
  6719. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6720. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6721. 0, &times, numBlocks, &pending)) {
  6722. ret = wc_Shake256_Final(hash[i], digest[i],
  6723. WC_SHA3_256_BLOCK_SIZE);
  6724. if (!bench_async_handle(&ret,
  6725. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6726. &times, &pending)) {
  6727. goto exit_shake256;
  6728. }
  6729. }
  6730. } /* for i */
  6731. } while (pending > 0);
  6732. } while (bench_stats_check(start)
  6733. #ifdef MULTI_VALUE_STATISTICS
  6734. || runs < minimum_runs
  6735. #endif
  6736. );
  6737. }
  6738. else {
  6739. bench_stats_start(&count, &start);
  6740. do {
  6741. for (times = 0; times < numBlocks; times++) {
  6742. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6743. useDeviceID ? devId : INVALID_DEVID);
  6744. if (ret == 0)
  6745. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6746. if (ret == 0)
  6747. ret = wc_Shake256_Final(hash[0], digest[0],
  6748. WC_SHA3_256_BLOCK_SIZE);
  6749. if (ret != 0)
  6750. goto exit_shake256;
  6751. RECORD_MULTI_VALUE_STATS();
  6752. } /* for times */
  6753. count += times;
  6754. } while (bench_stats_check(start)
  6755. #ifdef MULTI_VALUE_STATISTICS
  6756. || runs < minimum_runs
  6757. #endif
  6758. );
  6759. }
  6760. exit_shake256:
  6761. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6762. start, ret);
  6763. #ifdef MULTI_VALUE_STATISTICS
  6764. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6765. #endif
  6766. exit:
  6767. if (WC_ARRAY_OK(hash)) {
  6768. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6769. wc_Shake256_Free(hash[i]);
  6770. }
  6771. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6772. }
  6773. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6774. }
  6775. #endif /* WOLFSSL_SHAKE256 */
  6776. #endif
  6777. #ifdef WOLFSSL_SM3
  6778. void bench_sm3(int useDeviceID)
  6779. {
  6780. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6781. sizeof(wc_Sm3), HEAP_HINT);
  6782. double start;
  6783. int ret = 0, i, count = 0, times, pending = 0;
  6784. DECLARE_MULTI_VALUE_STATS_VARS()
  6785. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6786. HEAP_HINT);
  6787. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6788. sizeof(wc_Sm3), HEAP_HINT);
  6789. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6790. HEAP_HINT);
  6791. if (digest_stream) {
  6792. /* init keys */
  6793. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6794. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6795. useDeviceID ? devId: INVALID_DEVID);
  6796. if (ret != 0) {
  6797. printf("InitSm3 failed, ret = %d\n", ret);
  6798. goto exit;
  6799. }
  6800. }
  6801. bench_stats_start(&count, &start);
  6802. do {
  6803. for (times = 0; times < numBlocks || pending > 0; ) {
  6804. bench_async_poll(&pending);
  6805. /* while free pending slots in queue, submit ops */
  6806. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6807. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6808. 0, &times, numBlocks, &pending)) {
  6809. ret = wc_Sm3Update(hash[i], bench_plain,
  6810. bench_size);
  6811. if (!bench_async_handle(&ret,
  6812. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6813. goto exit_sm3;
  6814. }
  6815. }
  6816. } /* for i */
  6817. RECORD_MULTI_VALUE_STATS();
  6818. } /* for times */
  6819. count += times;
  6820. times = 0;
  6821. do {
  6822. bench_async_poll(&pending);
  6823. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6824. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6825. 0, &times, numBlocks, &pending)) {
  6826. ret = wc_Sm3Final(hash[i], digest[i]);
  6827. if (!bench_async_handle(&ret,
  6828. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6829. goto exit_sm3;
  6830. }
  6831. }
  6832. } /* for i */
  6833. } while (pending > 0);
  6834. } while (bench_stats_check(start)
  6835. #ifdef MULTI_VALUE_STATISTICS
  6836. || runs < minimum_runs
  6837. #endif
  6838. );
  6839. }
  6840. else {
  6841. bench_stats_start(&count, &start);
  6842. do {
  6843. for (times = 0; times < numBlocks; times++) {
  6844. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6845. useDeviceID ? devId: INVALID_DEVID);
  6846. if (ret == 0)
  6847. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6848. if (ret == 0)
  6849. ret = wc_Sm3Final(hash[0], digest[0]);
  6850. if (ret != 0)
  6851. goto exit_sm3;
  6852. RECORD_MULTI_VALUE_STATS();
  6853. } /* for times */
  6854. count += times;
  6855. } while (bench_stats_check(start)
  6856. #ifdef MULTI_VALUE_STATISTICS
  6857. || runs < minimum_runs
  6858. #endif
  6859. );
  6860. }
  6861. exit_sm3:
  6862. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6863. #ifdef MULTI_VALUE_STATISTICS
  6864. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6865. #endif
  6866. exit:
  6867. if (WC_ARRAY_OK(hash)) {
  6868. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6869. wc_Sm3Free(hash[i]);
  6870. }
  6871. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6872. }
  6873. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6874. }
  6875. #endif
  6876. #ifdef WOLFSSL_RIPEMD
  6877. void bench_ripemd(void)
  6878. {
  6879. RipeMd hash;
  6880. byte digest[RIPEMD_DIGEST_SIZE];
  6881. double start;
  6882. int i, count, ret = 0;
  6883. DECLARE_MULTI_VALUE_STATS_VARS()
  6884. if (digest_stream) {
  6885. ret = wc_InitRipeMd(&hash);
  6886. if (ret != 0) {
  6887. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6888. return;
  6889. }
  6890. bench_stats_start(&count, &start);
  6891. do {
  6892. for (i = 0; i < numBlocks; i++) {
  6893. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6894. if (ret != 0) {
  6895. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6896. return;
  6897. }
  6898. RECORD_MULTI_VALUE_STATS();
  6899. }
  6900. ret = wc_RipeMdFinal(&hash, digest);
  6901. if (ret != 0) {
  6902. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6903. return;
  6904. }
  6905. count += i;
  6906. } while (bench_stats_check(start)
  6907. #ifdef MULTI_VALUE_STATISTICS
  6908. || runs < minimum_runs
  6909. #endif
  6910. );
  6911. }
  6912. else {
  6913. bench_stats_start(&count, &start);
  6914. do {
  6915. for (i = 0; i < numBlocks; i++) {
  6916. ret = wc_InitRipeMd(&hash);
  6917. if (ret != 0) {
  6918. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6919. return;
  6920. }
  6921. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6922. if (ret != 0) {
  6923. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6924. return;
  6925. }
  6926. ret = wc_RipeMdFinal(&hash, digest);
  6927. if (ret != 0) {
  6928. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6929. return;
  6930. }
  6931. RECORD_MULTI_VALUE_STATS();
  6932. }
  6933. count += i;
  6934. } while (bench_stats_check(start)
  6935. #ifdef MULTI_VALUE_STATISTICS
  6936. || runs < minimum_runs
  6937. #endif
  6938. );
  6939. }
  6940. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  6941. #ifdef MULTI_VALUE_STATISTICS
  6942. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6943. #endif
  6944. return;
  6945. }
  6946. #endif
  6947. #ifdef HAVE_BLAKE2
  6948. void bench_blake2b(void)
  6949. {
  6950. Blake2b b2b;
  6951. byte digest[64];
  6952. double start;
  6953. int ret = 0, i, count;
  6954. DECLARE_MULTI_VALUE_STATS_VARS()
  6955. if (digest_stream) {
  6956. ret = wc_InitBlake2b(&b2b, 64);
  6957. if (ret != 0) {
  6958. printf("InitBlake2b failed, ret = %d\n", ret);
  6959. return;
  6960. }
  6961. bench_stats_start(&count, &start);
  6962. do {
  6963. for (i = 0; i < numBlocks; i++) {
  6964. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  6965. if (ret != 0) {
  6966. printf("Blake2bUpdate failed, ret = %d\n", ret);
  6967. return;
  6968. }
  6969. RECORD_MULTI_VALUE_STATS();
  6970. }
  6971. ret = wc_Blake2bFinal(&b2b, digest, 64);
  6972. if (ret != 0) {
  6973. printf("Blake2bFinal failed, ret = %d\n", ret);
  6974. return;
  6975. }
  6976. count += i;
  6977. } while (bench_stats_check(start)
  6978. #ifdef MULTI_VALUE_STATISTICS
  6979. || runs < minimum_runs
  6980. #endif
  6981. );
  6982. }
  6983. else {
  6984. bench_stats_start(&count, &start);
  6985. do {
  6986. for (i = 0; i < numBlocks; i++) {
  6987. ret = wc_InitBlake2b(&b2b, 64);
  6988. if (ret != 0) {
  6989. printf("InitBlake2b failed, ret = %d\n", ret);
  6990. return;
  6991. }
  6992. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  6993. if (ret != 0) {
  6994. printf("Blake2bUpdate failed, ret = %d\n", ret);
  6995. return;
  6996. }
  6997. ret = wc_Blake2bFinal(&b2b, digest, 64);
  6998. if (ret != 0) {
  6999. printf("Blake2bFinal failed, ret = %d\n", ret);
  7000. return;
  7001. }
  7002. RECORD_MULTI_VALUE_STATS();
  7003. }
  7004. count += i;
  7005. } while (bench_stats_check(start)
  7006. #ifdef MULTI_VALUE_STATISTICS
  7007. || runs < minimum_runs
  7008. #endif
  7009. );
  7010. }
  7011. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7012. #ifdef MULTI_VALUE_STATISTICS
  7013. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7014. #endif
  7015. }
  7016. #endif
  7017. #if defined(HAVE_BLAKE2S)
  7018. void bench_blake2s(void)
  7019. {
  7020. Blake2s b2s;
  7021. byte digest[32];
  7022. double start;
  7023. int ret = 0, i, count;
  7024. DECLARE_MULTI_VALUE_STATS_VARS()
  7025. if (digest_stream) {
  7026. ret = wc_InitBlake2s(&b2s, 32);
  7027. if (ret != 0) {
  7028. printf("InitBlake2s failed, ret = %d\n", ret);
  7029. return;
  7030. }
  7031. bench_stats_start(&count, &start);
  7032. do {
  7033. for (i = 0; i < numBlocks; i++) {
  7034. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7035. if (ret != 0) {
  7036. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7037. return;
  7038. }
  7039. RECORD_MULTI_VALUE_STATS();
  7040. }
  7041. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7042. if (ret != 0) {
  7043. printf("Blake2sFinal failed, ret = %d\n", ret);
  7044. return;
  7045. }
  7046. count += i;
  7047. } while (bench_stats_check(start)
  7048. #ifdef MULTI_VALUE_STATISTICS
  7049. || runs < minimum_runs
  7050. #endif
  7051. );
  7052. }
  7053. else {
  7054. bench_stats_start(&count, &start);
  7055. do {
  7056. for (i = 0; i < numBlocks; i++) {
  7057. ret = wc_InitBlake2s(&b2s, 32);
  7058. if (ret != 0) {
  7059. printf("InitBlake2b failed, ret = %d\n", ret);
  7060. return;
  7061. }
  7062. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7063. if (ret != 0) {
  7064. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7065. return;
  7066. }
  7067. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7068. if (ret != 0) {
  7069. printf("Blake2sFinal failed, ret = %d\n", ret);
  7070. return;
  7071. }
  7072. RECORD_MULTI_VALUE_STATS();
  7073. }
  7074. count += i;
  7075. } while (bench_stats_check(start)
  7076. #ifdef MULTI_VALUE_STATISTICS
  7077. || runs < minimum_runs
  7078. #endif
  7079. );
  7080. }
  7081. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7082. #ifdef MULTI_VALUE_STATISTICS
  7083. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7084. #endif
  7085. }
  7086. #endif
  7087. #ifdef WOLFSSL_CMAC
  7088. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7089. {
  7090. Cmac cmac;
  7091. byte digest[AES_BLOCK_SIZE];
  7092. word32 digestSz = sizeof(digest);
  7093. double start;
  7094. int ret, i, count;
  7095. DECLARE_MULTI_VALUE_STATS_VARS()
  7096. #ifdef WOLFSSL_SECO_CAAM
  7097. unsigned int keyID;
  7098. int keyGroup = 1; /* group one was chosen arbitrarily */
  7099. int keyInfo = CAAM_KEY_TRANSIENT;
  7100. int keyType = CAAM_KEYTYPE_AES128;
  7101. byte pubKey[AES_256_KEY_SIZE];
  7102. if (keySz == AES_256_KEY_SIZE) {
  7103. keyType = CAAM_KEYTYPE_AES256;
  7104. }
  7105. if (useDeviceID &&
  7106. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7107. keyInfo, &keyID) != 0) {
  7108. printf("Error generating key in hsm\n");
  7109. return;
  7110. }
  7111. #endif
  7112. (void)useDeviceID;
  7113. bench_stats_start(&count, &start);
  7114. do {
  7115. #ifdef HAVE_FIPS
  7116. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7117. #else
  7118. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7119. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7120. #endif
  7121. if (ret != 0) {
  7122. printf("InitCmac failed, ret = %d\n", ret);
  7123. return;
  7124. }
  7125. #ifdef WOLFSSL_SECO_CAAM
  7126. if (useDeviceID) {
  7127. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7128. }
  7129. #endif
  7130. for (i = 0; i < numBlocks; i++) {
  7131. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7132. if (ret != 0) {
  7133. printf("CmacUpdate failed, ret = %d\n", ret);
  7134. return;
  7135. }
  7136. RECORD_MULTI_VALUE_STATS();
  7137. }
  7138. /* Note: final force zero's the Cmac struct */
  7139. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7140. if (ret != 0) {
  7141. printf("CmacFinal failed, ret = %d\n", ret);
  7142. return;
  7143. }
  7144. count += i;
  7145. } while (bench_stats_check(start)
  7146. #ifdef MULTI_VALUE_STATISTICS
  7147. || runs < minimum_runs
  7148. #endif
  7149. );
  7150. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7151. #ifdef MULTI_VALUE_STATISTICS
  7152. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7153. #endif
  7154. }
  7155. void bench_cmac(int useDeviceID)
  7156. {
  7157. #ifdef WOLFSSL_AES_128
  7158. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7159. #endif
  7160. #ifdef WOLFSSL_AES_256
  7161. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7162. #endif
  7163. }
  7164. #endif /* WOLFSSL_CMAC */
  7165. #ifdef HAVE_SCRYPT
  7166. void bench_scrypt(void)
  7167. {
  7168. byte derived[64];
  7169. double start;
  7170. int ret, i, count;
  7171. DECLARE_MULTI_VALUE_STATS_VARS()
  7172. bench_stats_start(&count, &start);
  7173. do {
  7174. for (i = 0; i < scryptCnt; i++) {
  7175. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7176. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7177. sizeof(derived));
  7178. if (ret != 0) {
  7179. printf("scrypt failed, ret = %d\n", ret);
  7180. goto exit;
  7181. }
  7182. RECORD_MULTI_VALUE_STATS();
  7183. }
  7184. count += i;
  7185. } while (bench_stats_check(start)
  7186. #ifdef MULTI_VALUE_STATISTICS
  7187. || runs < minimum_runs
  7188. #endif
  7189. );
  7190. exit:
  7191. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7192. #ifdef MULTI_VALUE_STATISTICS
  7193. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7194. #endif
  7195. }
  7196. #endif /* HAVE_SCRYPT */
  7197. #ifndef NO_HMAC
  7198. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7199. const byte* key, word32 keySz, const char* label)
  7200. {
  7201. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7202. sizeof(Hmac), HEAP_HINT);
  7203. double start;
  7204. int ret = 0, i, count = 0, times, pending = 0;
  7205. DECLARE_MULTI_VALUE_STATS_VARS()
  7206. #ifdef WOLFSSL_ASYNC_CRYPT
  7207. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7208. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7209. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7210. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7211. #else
  7212. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7213. #endif
  7214. (void)digestSz;
  7215. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7216. sizeof(Hmac), HEAP_HINT);
  7217. /* init keys */
  7218. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7219. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7220. useDeviceID ? devId : INVALID_DEVID);
  7221. if (ret != 0) {
  7222. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7223. goto exit;
  7224. }
  7225. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7226. if (ret != 0) {
  7227. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7228. goto exit;
  7229. }
  7230. }
  7231. bench_stats_start(&count, &start);
  7232. do {
  7233. for (times = 0; times < numBlocks || pending > 0; ) {
  7234. bench_async_poll(&pending);
  7235. /* while free pending slots in queue, submit ops */
  7236. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7237. if (bench_async_check(&ret,
  7238. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7239. &times, numBlocks, &pending)) {
  7240. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7241. if (!bench_async_handle(&ret,
  7242. BENCH_ASYNC_GET_DEV(hmac[i]),
  7243. 0, &times, &pending)) {
  7244. goto exit_hmac;
  7245. }
  7246. }
  7247. } /* for i */
  7248. } /* for times */
  7249. count += times;
  7250. times = 0;
  7251. do {
  7252. bench_async_poll(&pending);
  7253. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7254. if (bench_async_check(&ret,
  7255. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7256. &times, numBlocks, &pending)) {
  7257. ret = wc_HmacFinal(hmac[i], digest[i]);
  7258. if (!bench_async_handle(&ret,
  7259. BENCH_ASYNC_GET_DEV(hmac[i]),
  7260. 0, &times, &pending)) {
  7261. goto exit_hmac;
  7262. }
  7263. }
  7264. RECORD_MULTI_VALUE_STATS();
  7265. } /* for i */
  7266. } while (pending > 0);
  7267. } while (bench_stats_check(start)
  7268. #ifdef MULTI_VALUE_STATISTICS
  7269. || runs < minimum_runs
  7270. #endif
  7271. );
  7272. exit_hmac:
  7273. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7274. #ifdef MULTI_VALUE_STATISTICS
  7275. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7276. #endif
  7277. exit:
  7278. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7279. wc_HmacFree(hmac[i]);
  7280. }
  7281. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7282. #ifdef WOLFSSL_ASYNC_CRYPT
  7283. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7284. #endif
  7285. }
  7286. #ifndef NO_MD5
  7287. void bench_hmac_md5(int useDeviceID)
  7288. {
  7289. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7290. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7291. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7292. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7293. "HMAC-MD5");
  7294. }
  7295. #endif /* NO_MD5 */
  7296. #ifndef NO_SHA
  7297. void bench_hmac_sha(int useDeviceID)
  7298. {
  7299. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7300. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7301. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7302. 0x0b, 0x0b, 0x0b, 0x0b };
  7303. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7304. "HMAC-SHA");
  7305. }
  7306. #endif /* NO_SHA */
  7307. #ifdef WOLFSSL_SHA224
  7308. void bench_hmac_sha224(int useDeviceID)
  7309. {
  7310. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7311. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7312. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7313. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7314. 0x0b, 0x0b, 0x0b, 0x0b };
  7315. bench_hmac(useDeviceID, WC_SHA224,
  7316. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7317. "HMAC-SHA224");
  7318. }
  7319. #endif /* WOLFSSL_SHA224 */
  7320. #ifndef NO_SHA256
  7321. void bench_hmac_sha256(int useDeviceID)
  7322. {
  7323. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7324. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7325. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7326. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7327. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7328. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7329. "HMAC-SHA256");
  7330. }
  7331. #endif /* NO_SHA256 */
  7332. #ifdef WOLFSSL_SHA384
  7333. void bench_hmac_sha384(int useDeviceID)
  7334. {
  7335. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7336. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7337. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7338. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7339. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7340. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7341. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7342. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7343. "HMAC-SHA384");
  7344. }
  7345. #endif /* WOLFSSL_SHA384 */
  7346. #ifdef WOLFSSL_SHA512
  7347. void bench_hmac_sha512(int useDeviceID)
  7348. {
  7349. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7350. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7351. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7352. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7353. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7354. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7355. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7356. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7357. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7358. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7359. "HMAC-SHA512");
  7360. }
  7361. #endif /* WOLFSSL_SHA512 */
  7362. #ifndef NO_PWDBASED
  7363. void bench_pbkdf2(void)
  7364. {
  7365. double start;
  7366. int ret = 0, count = 0;
  7367. const char* passwd32 = "passwordpasswordpasswordpassword";
  7368. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7369. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7370. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7371. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7372. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7373. byte derived[32];
  7374. DECLARE_MULTI_VALUE_STATS_VARS()
  7375. bench_stats_start(&count, &start);
  7376. PRIVATE_KEY_UNLOCK();
  7377. do {
  7378. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7379. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7380. count++;
  7381. RECORD_MULTI_VALUE_STATS();
  7382. } while (bench_stats_check(start)
  7383. #ifdef MULTI_VALUE_STATISTICS
  7384. || runs < minimum_runs
  7385. #endif
  7386. );
  7387. PRIVATE_KEY_LOCK();
  7388. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7389. #ifdef MULTI_VALUE_STATISTICS
  7390. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7391. #endif
  7392. }
  7393. #endif /* !NO_PWDBASED */
  7394. #endif /* NO_HMAC */
  7395. #ifdef WOLFSSL_SIPHASH
  7396. void bench_siphash(void)
  7397. {
  7398. double start;
  7399. int ret = 0, count;
  7400. const char* passwd16 = "passwordpassword";
  7401. byte out[16];
  7402. int i;
  7403. DECLARE_MULTI_VALUE_STATS_VARS()
  7404. bench_stats_start(&count, &start);
  7405. do {
  7406. for (i = 0; i < numBlocks; i++) {
  7407. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7408. out, 8);
  7409. RECORD_MULTI_VALUE_STATS();
  7410. }
  7411. count += i;
  7412. } while (bench_stats_check(start)
  7413. #ifdef MULTI_VALUE_STATISTICS
  7414. || runs < minimum_runs
  7415. #endif
  7416. );
  7417. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7418. #ifdef MULTI_VALUE_STATISTICS
  7419. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7420. #endif
  7421. RESET_MULTI_VALUE_STATS_VARS();
  7422. bench_stats_start(&count, &start);
  7423. do {
  7424. for (i = 0; i < numBlocks; i++) {
  7425. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7426. out, 16);
  7427. RECORD_MULTI_VALUE_STATS();
  7428. }
  7429. count += i;
  7430. } while (bench_stats_check(start)
  7431. #ifdef MULTI_VALUE_STATISTICS
  7432. || runs < minimum_runs
  7433. #endif
  7434. );
  7435. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7436. #ifdef MULTI_VALUE_STATISTICS
  7437. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7438. #endif
  7439. }
  7440. #endif
  7441. #ifdef WC_SRTP_KDF
  7442. void bench_srtpkdf(void)
  7443. {
  7444. double start;
  7445. int count;
  7446. int ret = 0;
  7447. byte keyE[32];
  7448. byte keyA[20];
  7449. byte keyS[14];
  7450. const byte *key = bench_key_buf;
  7451. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7452. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7453. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7454. int kdrIdx = 0;
  7455. int i;
  7456. DECLARE_MULTI_VALUE_STATS_VARS()
  7457. bench_stats_start(&count, &start);
  7458. PRIVATE_KEY_UNLOCK();
  7459. do {
  7460. for (i = 0; i < numBlocks; i++) {
  7461. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7462. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7463. keyS, sizeof(keyS));
  7464. RECORD_MULTI_VALUE_STATS();
  7465. }
  7466. count += i;
  7467. } while (bench_stats_check(start)
  7468. #ifdef MULTI_VALUE_STATISTICS
  7469. || runs < minimum_runs
  7470. #endif
  7471. );
  7472. PRIVATE_KEY_LOCK();
  7473. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7474. #ifdef MULTI_VALUE_STATISTICS
  7475. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7476. #endif
  7477. RESET_MULTI_VALUE_STATS_VARS();
  7478. bench_stats_start(&count, &start);
  7479. PRIVATE_KEY_UNLOCK();
  7480. do {
  7481. for (i = 0; i < numBlocks; i++) {
  7482. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7483. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7484. keyS, sizeof(keyS));
  7485. RECORD_MULTI_VALUE_STATS();
  7486. }
  7487. count += i;
  7488. } while (bench_stats_check(start)
  7489. #ifdef MULTI_VALUE_STATISTICS
  7490. || runs < minimum_runs
  7491. #endif
  7492. );
  7493. PRIVATE_KEY_LOCK();
  7494. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7495. #ifdef MULTI_VALUE_STATISTICS
  7496. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7497. #endif
  7498. RESET_MULTI_VALUE_STATS_VARS();
  7499. bench_stats_start(&count, &start);
  7500. PRIVATE_KEY_UNLOCK();
  7501. do {
  7502. for (i = 0; i < numBlocks; i++) {
  7503. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7504. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7505. keyS, sizeof(keyS));
  7506. RECORD_MULTI_VALUE_STATS();
  7507. }
  7508. count += i;
  7509. } while (bench_stats_check(start)
  7510. #ifdef MULTI_VALUE_STATISTICS
  7511. || runs < minimum_runs
  7512. #endif
  7513. );
  7514. PRIVATE_KEY_LOCK();
  7515. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7516. #ifdef MULTI_VALUE_STATISTICS
  7517. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7518. #endif
  7519. RESET_MULTI_VALUE_STATS_VARS();
  7520. bench_stats_start(&count, &start);
  7521. PRIVATE_KEY_UNLOCK();
  7522. do {
  7523. for (i = 0; i < numBlocks; i++) {
  7524. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7525. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7526. keyS, sizeof(keyS));
  7527. RECORD_MULTI_VALUE_STATS();
  7528. }
  7529. count += i;
  7530. } while (bench_stats_check(start)
  7531. #ifdef MULTI_VALUE_STATISTICS
  7532. || runs < minimum_runs
  7533. #endif
  7534. );
  7535. PRIVATE_KEY_LOCK();
  7536. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7537. #ifdef MULTI_VALUE_STATISTICS
  7538. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7539. #endif
  7540. }
  7541. #endif
  7542. #ifndef NO_RSA
  7543. #if defined(WOLFSSL_KEY_GEN)
  7544. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7545. {
  7546. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7547. sizeof(RsaKey), HEAP_HINT);
  7548. double start = 0;
  7549. int ret = 0, i, count = 0, times, pending = 0;
  7550. const long rsa_e_val = WC_RSA_EXPONENT;
  7551. const char**desc = bench_desc_words[lng_index];
  7552. DECLARE_MULTI_VALUE_STATS_VARS()
  7553. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7554. sizeof(RsaKey), HEAP_HINT);
  7555. bench_stats_start(&count, &start);
  7556. do {
  7557. /* while free pending slots in queue, submit ops */
  7558. for (times = 0; times < genTimes || pending > 0; ) {
  7559. bench_async_poll(&pending);
  7560. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7561. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7562. 0, &times, genTimes, &pending)) {
  7563. wc_FreeRsaKey(genKey[i]);
  7564. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7565. if (ret < 0) {
  7566. goto exit;
  7567. }
  7568. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7569. &gRng);
  7570. if (!bench_async_handle(&ret,
  7571. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7572. &times, &pending)) {
  7573. goto exit;
  7574. }
  7575. }
  7576. } /* for i */
  7577. RECORD_MULTI_VALUE_STATS();
  7578. } /* for times */
  7579. count += times;
  7580. } while (bench_stats_check(start)
  7581. #ifdef MULTI_VALUE_STATISTICS
  7582. || runs < minimum_runs
  7583. #endif
  7584. );
  7585. exit:
  7586. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7587. start, ret);
  7588. #ifdef MULTI_VALUE_STATISTICS
  7589. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7590. #endif
  7591. /* cleanup */
  7592. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7593. wc_FreeRsaKey(genKey[i]);
  7594. }
  7595. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7596. }
  7597. void bench_rsaKeyGen(int useDeviceID)
  7598. {
  7599. int k;
  7600. #if !defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL) && \
  7601. (RSA_MIN_SIZE <= 1024)
  7602. static const word32 keySizes[2] = {1024, 2048};
  7603. #else
  7604. static const word32 keySizes[1] = {2048};
  7605. #endif
  7606. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7607. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7608. }
  7609. }
  7610. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7611. {
  7612. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7613. }
  7614. #endif /* WOLFSSL_KEY_GEN */
  7615. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7616. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7617. #if defined(WOLFSSL_MDK_SHELL)
  7618. static char *certRSAname = "certs/rsa2048.der";
  7619. /* set by shell command */
  7620. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7621. #elif defined(FREESCALE_MQX)
  7622. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7623. #else
  7624. static const char *certRSAname = "certs/rsa2048.der";
  7625. #endif
  7626. #endif
  7627. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7628. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7629. #if defined(USE_CERT_BUFFERS_2048)
  7630. static const unsigned char rsa_2048_sig[] = {
  7631. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7632. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7633. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7634. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7635. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7636. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7637. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7638. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7639. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7640. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7641. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7642. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7643. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7644. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7645. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7646. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7647. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7648. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7649. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7650. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7651. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7652. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7653. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7654. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7655. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7656. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7657. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7658. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7659. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7660. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7661. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7662. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7663. };
  7664. #elif defined(USE_CERT_BUFFERS_3072)
  7665. static const unsigned char rsa_3072_sig[] = {
  7666. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7667. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7668. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7669. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7670. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7671. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7672. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7673. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7674. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7675. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7676. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7677. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7678. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7679. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7680. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7681. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7682. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7683. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7684. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7685. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7686. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7687. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7688. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7689. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7690. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7691. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7692. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7693. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7694. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7695. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7696. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7697. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7698. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7699. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7700. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7701. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7702. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7703. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7704. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7705. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7706. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7707. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7708. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7709. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7710. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7711. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7712. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7713. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7714. };
  7715. #else
  7716. #error Not Supported Yet!
  7717. #endif
  7718. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7719. static void bench_rsa_helper(int useDeviceID,
  7720. WC_ARRAY_ARG(rsaKey,
  7721. RsaKey,
  7722. BENCH_MAX_PENDING,
  7723. sizeof(RsaKey)),
  7724. word32 rsaKeySz)
  7725. {
  7726. int ret = 0, i, times, count = 0, pending = 0;
  7727. word32 idx = 0;
  7728. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7729. const char* messageStr = TEST_STRING;
  7730. const int len = (int)TEST_STRING_SZ;
  7731. #endif
  7732. double start = 0.0F;
  7733. const char**desc = bench_desc_words[lng_index];
  7734. DECLARE_MULTI_VALUE_STATS_VARS()
  7735. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7736. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7737. #endif
  7738. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7739. rsaKeySz, HEAP_HINT);
  7740. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7741. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7742. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7743. rsaKeySz, HEAP_HINT);
  7744. #else
  7745. byte* out[BENCH_MAX_PENDING];
  7746. #endif
  7747. XMEMSET(out, 0, sizeof(out));
  7748. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7749. rsaKeySz, HEAP_HINT);
  7750. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7751. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7752. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7753. rsaKeySz, HEAP_HINT);
  7754. if (out[0] == NULL) {
  7755. ret = MEMORY_E;
  7756. goto exit;
  7757. }
  7758. #endif
  7759. if (enc[0] == NULL) {
  7760. ret = MEMORY_E;
  7761. goto exit;
  7762. }
  7763. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7764. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7765. XMEMCPY(message, messageStr, len);
  7766. #endif
  7767. if (!rsa_sign_verify) {
  7768. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7769. /* begin public RSA */
  7770. bench_stats_start(&count, &start);
  7771. do {
  7772. for (times = 0; times < ntimes || pending > 0; ) {
  7773. bench_async_poll(&pending);
  7774. /* while free pending slots in queue, submit ops */
  7775. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7776. if (bench_async_check(&ret,
  7777. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7778. 1, &times, ntimes, &pending)) {
  7779. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7780. rsaKeySz/8, rsaKey[i],
  7781. GLOBAL_RNG);
  7782. if (!bench_async_handle(&ret,
  7783. BENCH_ASYNC_GET_DEV(
  7784. rsaKey[i]), 1, &times,
  7785. &pending)) {
  7786. goto exit_rsa_verify;
  7787. }
  7788. }
  7789. } /* for i */
  7790. RECORD_MULTI_VALUE_STATS();
  7791. } /* for times */
  7792. count += times;
  7793. } while (bench_stats_check(start)
  7794. #ifdef MULTI_VALUE_STATISTICS
  7795. || runs < minimum_runs
  7796. #endif
  7797. );
  7798. exit_rsa_verify:
  7799. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7800. useDeviceID, count, start, ret);
  7801. #ifdef MULTI_VALUE_STATISTICS
  7802. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7803. #endif
  7804. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7805. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7806. if (ret < 0) {
  7807. goto exit;
  7808. }
  7809. RESET_MULTI_VALUE_STATS_VARS();
  7810. /* capture resulting encrypt length */
  7811. idx = (word32)(rsaKeySz/8);
  7812. /* begin private async RSA */
  7813. bench_stats_start(&count, &start);
  7814. do {
  7815. for (times = 0; times < ntimes || pending > 0; ) {
  7816. bench_async_poll(&pending);
  7817. /* while free pending slots in queue, submit ops */
  7818. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7819. if (bench_async_check(&ret,
  7820. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7821. 1, &times, ntimes, &pending)) {
  7822. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7823. rsaKeySz/8, rsaKey[i]);
  7824. if (!bench_async_handle(&ret,
  7825. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7826. 1, &times, &pending)) {
  7827. goto exit_rsa_pub;
  7828. }
  7829. }
  7830. } /* for i */
  7831. RECORD_MULTI_VALUE_STATS();
  7832. } /* for times */
  7833. count += times;
  7834. } while (bench_stats_check(start)
  7835. #ifdef MULTI_VALUE_STATISTICS
  7836. || runs < minimum_runs
  7837. #endif
  7838. );
  7839. exit_rsa_pub:
  7840. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7841. useDeviceID, count, start, ret);
  7842. #ifdef MULTI_VALUE_STATISTICS
  7843. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7844. #endif
  7845. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7846. }
  7847. else {
  7848. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7849. /* begin RSA sign */
  7850. bench_stats_start(&count, &start);
  7851. do {
  7852. for (times = 0; times < ntimes || pending > 0; ) {
  7853. bench_async_poll(&pending);
  7854. /* while free pending slots in queue, submit ops */
  7855. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7856. if (bench_async_check(&ret,
  7857. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7858. 1, &times, ntimes, &pending)) {
  7859. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7860. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7861. if (!bench_async_handle(&ret,
  7862. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7863. 1, &times, &pending)) {
  7864. goto exit_rsa_sign;
  7865. }
  7866. }
  7867. } /* for i */
  7868. RECORD_MULTI_VALUE_STATS();
  7869. } /* for times */
  7870. count += times;
  7871. } while (bench_stats_check(start)
  7872. #ifdef MULTI_VALUE_STATISTICS
  7873. || runs < minimum_runs
  7874. #endif
  7875. );
  7876. exit_rsa_sign:
  7877. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7878. count, start, ret);
  7879. #ifdef MULTI_VALUE_STATISTICS
  7880. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7881. #endif
  7882. if (ret < 0) {
  7883. goto exit;
  7884. }
  7885. RESET_MULTI_VALUE_STATS_VARS();
  7886. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  7887. /* capture resulting encrypt length */
  7888. idx = rsaKeySz/8;
  7889. /* begin RSA verify */
  7890. bench_stats_start(&count, &start);
  7891. do {
  7892. for (times = 0; times < ntimes || pending > 0; ) {
  7893. bench_async_poll(&pending);
  7894. /* while free pending slots in queue, submit ops */
  7895. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7896. if (bench_async_check(&ret,
  7897. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7898. 1, &times, ntimes, &pending)) {
  7899. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7900. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7901. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  7902. rsaKeySz/8, rsaKey[i]);
  7903. #elif defined(USE_CERT_BUFFERS_2048)
  7904. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  7905. idx = sizeof(rsa_2048_sig);
  7906. out[i] = NULL;
  7907. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7908. &out[i], rsaKey[i]);
  7909. if (ret > 0) {
  7910. ret = 0;
  7911. }
  7912. #elif defined(USE_CERT_BUFFERS_3072)
  7913. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  7914. idx = sizeof(rsa_3072_sig);
  7915. out[i] = NULL;
  7916. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7917. &out[i], rsaKey[i]);
  7918. if (ret > 0)
  7919. ret = 0;
  7920. #endif
  7921. if (!bench_async_handle(&ret,
  7922. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7923. 1, &times, &pending)) {
  7924. goto exit_rsa_verifyinline;
  7925. }
  7926. }
  7927. } /* for i */
  7928. RECORD_MULTI_VALUE_STATS();
  7929. } /* for times */
  7930. count += times;
  7931. } while (bench_stats_check(start)
  7932. #ifdef MULTI_VALUE_STATISTICS
  7933. || runs < minimum_runs
  7934. #endif
  7935. );
  7936. exit_rsa_verifyinline:
  7937. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  7938. useDeviceID, count, start, ret);
  7939. #ifdef MULTI_VALUE_STATISTICS
  7940. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7941. #endif
  7942. }
  7943. exit:
  7944. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  7945. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7946. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  7947. #endif
  7948. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7949. WC_FREE_VAR(message, HEAP_HINT);
  7950. #endif
  7951. }
  7952. void bench_rsa(int useDeviceID)
  7953. {
  7954. int i;
  7955. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  7956. sizeof(RsaKey), HEAP_HINT);
  7957. int ret = 0;
  7958. word32 rsaKeySz = 0;
  7959. const byte* tmp;
  7960. size_t bytes;
  7961. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7962. word32 idx;
  7963. #endif
  7964. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  7965. sizeof(RsaKey), HEAP_HINT);
  7966. #ifdef USE_CERT_BUFFERS_1024
  7967. tmp = rsa_key_der_1024;
  7968. bytes = (size_t)sizeof_rsa_key_der_1024;
  7969. rsaKeySz = 1024;
  7970. #elif defined(USE_CERT_BUFFERS_2048)
  7971. tmp = rsa_key_der_2048;
  7972. bytes = (size_t)sizeof_rsa_key_der_2048;
  7973. rsaKeySz = 2048;
  7974. #elif defined(USE_CERT_BUFFERS_3072)
  7975. tmp = rsa_key_der_3072;
  7976. bytes = (size_t)sizeof_rsa_key_der_3072;
  7977. rsaKeySz = 3072;
  7978. #elif defined(USE_CERT_BUFFERS_4096)
  7979. tmp = client_key_der_4096;
  7980. bytes = (size_t)sizeof_client_key_der_4096;
  7981. rsaKeySz = 4096;
  7982. #else
  7983. #error "need a cert buffer size"
  7984. #endif /* USE_CERT_BUFFERS */
  7985. /* init keys */
  7986. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7987. /* setup an async context for each key */
  7988. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  7989. useDeviceID ? devId : INVALID_DEVID);
  7990. if (ret < 0) {
  7991. goto exit;
  7992. }
  7993. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7994. #ifdef WC_RSA_BLINDING
  7995. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  7996. if (ret != 0)
  7997. goto exit;
  7998. #endif
  7999. #endif
  8000. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8001. /* decode the private key */
  8002. idx = 0;
  8003. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8004. rsaKey[i], (word32)bytes)) != 0) {
  8005. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8006. goto exit;
  8007. }
  8008. #elif defined(WOLFSSL_PUBLIC_MP)
  8009. /* get offset to public portion of the RSA key */
  8010. #ifdef USE_CERT_BUFFERS_1024
  8011. bytes = 11;
  8012. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8013. bytes = 12;
  8014. #endif
  8015. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8016. if (ret != 0) {
  8017. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8018. goto exit;
  8019. }
  8020. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8021. if (ret != 0) {
  8022. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8023. goto exit;
  8024. }
  8025. #else
  8026. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8027. rsaKeySz = 0;
  8028. #endif
  8029. }
  8030. if (rsaKeySz > 0) {
  8031. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8032. }
  8033. (void)bytes;
  8034. (void)tmp;
  8035. exit:
  8036. /* cleanup */
  8037. if (WC_ARRAY_OK(rsaKey)) {
  8038. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8039. wc_FreeRsaKey(rsaKey[i]);
  8040. }
  8041. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8042. }
  8043. }
  8044. #ifdef WOLFSSL_KEY_GEN
  8045. /* bench any size of RSA key */
  8046. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8047. {
  8048. int ret = 0, i, pending = 0;
  8049. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8050. sizeof(RsaKey), HEAP_HINT);
  8051. int isPending[BENCH_MAX_PENDING];
  8052. long exp = 65537L;
  8053. /* clear for done cleanup */
  8054. XMEMSET(isPending, 0, sizeof(isPending));
  8055. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8056. sizeof(RsaKey), HEAP_HINT);
  8057. /* init keys */
  8058. do {
  8059. pending = 0;
  8060. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8061. if (!isPending[i]) { /* if making the key is pending then just call
  8062. * wc_MakeRsaKey again */
  8063. /* setup an async context for each key */
  8064. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8065. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8066. goto exit;
  8067. }
  8068. #ifdef WC_RSA_BLINDING
  8069. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8070. if (ret != 0)
  8071. goto exit;
  8072. #endif
  8073. }
  8074. /* create the RSA key */
  8075. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8076. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8077. isPending[i] = 1;
  8078. pending = 1;
  8079. }
  8080. else if (ret != 0) {
  8081. printf("wc_MakeRsaKey failed! %d\n", ret);
  8082. goto exit;
  8083. }
  8084. } /* for i */
  8085. } while (pending > 0);
  8086. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8087. exit:
  8088. /* cleanup */
  8089. if (WC_ARRAY_OK(rsaKey)) {
  8090. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8091. wc_FreeRsaKey(rsaKey[i]);
  8092. }
  8093. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8094. }
  8095. }
  8096. #endif /* WOLFSSL_KEY_GEN */
  8097. #endif /* !NO_RSA */
  8098. #ifndef NO_DH
  8099. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8100. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8101. #if defined(WOLFSSL_MDK_SHELL)
  8102. static char *certDHname = "certs/dh2048.der";
  8103. /* set by shell command */
  8104. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8105. #elif defined(FREESCALE_MQX)
  8106. static char *certDHname = "a:\\certs\\dh2048.der";
  8107. #elif defined(NO_ASN)
  8108. /* do nothing, but don't need a file */
  8109. #else
  8110. static const char *certDHname = "certs/dh2048.der";
  8111. #endif
  8112. #endif
  8113. #ifdef HAVE_FFDHE_4096
  8114. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8115. #else
  8116. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8117. #endif
  8118. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8119. void bench_dh(int useDeviceID)
  8120. {
  8121. int ret = 0, i;
  8122. int count = 0, times, pending = 0;
  8123. const byte* tmp = NULL;
  8124. double start = 0.0F;
  8125. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8126. sizeof(DhKey), HEAP_HINT);
  8127. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8128. const char**desc = bench_desc_words[lng_index];
  8129. #ifndef NO_ASN
  8130. size_t bytes = 0;
  8131. word32 idx;
  8132. #endif
  8133. word32 pubSz[BENCH_MAX_PENDING];
  8134. word32 privSz[BENCH_MAX_PENDING];
  8135. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8136. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8137. word32 agreeSz[BENCH_MAX_PENDING];
  8138. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8139. #ifdef HAVE_PUBLIC_FFDHE
  8140. const DhParams *params = NULL;
  8141. #else
  8142. int paramName = 0;
  8143. #endif
  8144. #endif
  8145. DECLARE_MULTI_VALUE_STATS_VARS()
  8146. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8147. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8148. WC_DECLARE_VAR(pub2, byte,
  8149. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8150. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8151. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8152. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8153. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8154. WC_DECLARE_VAR(priv2, byte,
  8155. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8156. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8157. XMEMSET(pub, 0, sizeof(pub));
  8158. XMEMSET(agree, 0, sizeof(agree));
  8159. XMEMSET(priv, 0, sizeof(priv));
  8160. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8161. sizeof(DhKey), HEAP_HINT);
  8162. WC_ALLOC_ARRAY(pub, byte,
  8163. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8164. WC_ALLOC_ARRAY(agree, byte,
  8165. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8166. WC_ALLOC_ARRAY(priv, byte,
  8167. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8168. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8169. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8170. (void)tmp;
  8171. if (!use_ffdhe) {
  8172. #if defined(NO_ASN)
  8173. dhKeySz = 1024;
  8174. /* do nothing, but don't use default FILE */
  8175. #elif defined(USE_CERT_BUFFERS_1024)
  8176. tmp = dh_key_der_1024;
  8177. bytes = (size_t)sizeof_dh_key_der_1024;
  8178. dhKeySz = 1024;
  8179. #elif defined(USE_CERT_BUFFERS_2048)
  8180. tmp = dh_key_der_2048;
  8181. bytes = (size_t)sizeof_dh_key_der_2048;
  8182. dhKeySz = 2048;
  8183. #elif defined(USE_CERT_BUFFERS_3072)
  8184. tmp = dh_key_der_3072;
  8185. bytes = (size_t)sizeof_dh_key_der_3072;
  8186. dhKeySz = 3072;
  8187. #elif defined(USE_CERT_BUFFERS_4096)
  8188. tmp = dh_key_der_4096;
  8189. bytes = (size_t)sizeof_dh_key_der_4096;
  8190. dhKeySz = 4096;
  8191. #else
  8192. #error "need to define a cert buffer size"
  8193. #endif /* USE_CERT_BUFFERS */
  8194. }
  8195. #ifdef HAVE_FFDHE_2048
  8196. else if (use_ffdhe == 2048) {
  8197. #ifdef HAVE_PUBLIC_FFDHE
  8198. params = wc_Dh_ffdhe2048_Get();
  8199. #else
  8200. paramName = WC_FFDHE_2048;
  8201. #endif
  8202. dhKeySz = 2048;
  8203. }
  8204. #endif
  8205. #ifdef HAVE_FFDHE_3072
  8206. else if (use_ffdhe == 3072) {
  8207. #ifdef HAVE_PUBLIC_FFDHE
  8208. params = wc_Dh_ffdhe3072_Get();
  8209. #else
  8210. paramName = WC_FFDHE_3072;
  8211. #endif
  8212. dhKeySz = 3072;
  8213. }
  8214. #endif
  8215. #ifdef HAVE_FFDHE_4096
  8216. else if (use_ffdhe == 4096) {
  8217. #ifdef HAVE_PUBLIC_FFDHE
  8218. params = wc_Dh_ffdhe4096_Get();
  8219. #else
  8220. paramName = WC_FFDHE_4096;
  8221. #endif
  8222. dhKeySz = 4096;
  8223. }
  8224. #endif
  8225. /* init keys */
  8226. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8227. /* setup an async context for each key */
  8228. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8229. useDeviceID ? devId : INVALID_DEVID);
  8230. if (ret != 0)
  8231. goto exit;
  8232. /* setup key */
  8233. if (!use_ffdhe) {
  8234. #ifdef NO_ASN
  8235. ret = wc_DhSetKey(dhKey[i], dh_p,
  8236. sizeof(dh_p), dh_g, sizeof(dh_g));
  8237. #else
  8238. idx = 0;
  8239. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8240. #endif
  8241. }
  8242. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8243. #ifdef HAVE_PUBLIC_FFDHE
  8244. else if (params != NULL) {
  8245. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8246. params->g, params->g_len);
  8247. }
  8248. #else
  8249. else if (paramName != 0) {
  8250. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8251. }
  8252. #endif
  8253. #endif
  8254. if (ret != 0) {
  8255. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8256. goto exit;
  8257. }
  8258. }
  8259. /* Key Gen */
  8260. bench_stats_start(&count, &start);
  8261. PRIVATE_KEY_UNLOCK();
  8262. do {
  8263. /* while free pending slots in queue, submit ops */
  8264. for (times = 0; times < genTimes || pending > 0; ) {
  8265. bench_async_poll(&pending);
  8266. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8267. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8268. 0, &times, genTimes, &pending)) {
  8269. privSz[i] = BENCH_DH_PRIV_SIZE;
  8270. pubSz[i] = BENCH_DH_KEY_SIZE;
  8271. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8272. priv[i], &privSz[i],
  8273. pub[i], &pubSz[i]);
  8274. if (!bench_async_handle(&ret,
  8275. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8276. 0, &times, &pending)) {
  8277. goto exit_dh_gen;
  8278. }
  8279. }
  8280. } /* for i */
  8281. RECORD_MULTI_VALUE_STATS();
  8282. } /* for times */
  8283. count += times;
  8284. } while (bench_stats_check(start)
  8285. #ifdef MULTI_VALUE_STATISTICS
  8286. || runs < minimum_runs
  8287. #endif
  8288. );
  8289. PRIVATE_KEY_LOCK();
  8290. exit_dh_gen:
  8291. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8292. useDeviceID, count, start, ret);
  8293. #ifdef MULTI_VALUE_STATISTICS
  8294. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8295. #endif
  8296. if (ret < 0) {
  8297. goto exit;
  8298. }
  8299. RESET_MULTI_VALUE_STATS_VARS();
  8300. /* Generate key to use as other public */
  8301. PRIVATE_KEY_UNLOCK();
  8302. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8303. priv2, &privSz2, pub2, &pubSz2);
  8304. PRIVATE_KEY_LOCK();
  8305. #ifdef WOLFSSL_ASYNC_CRYPT
  8306. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8307. #endif
  8308. /* Key Agree */
  8309. bench_stats_start(&count, &start);
  8310. PRIVATE_KEY_UNLOCK();
  8311. do {
  8312. for (times = 0; times < agreeTimes || pending > 0; ) {
  8313. bench_async_poll(&pending);
  8314. /* while free pending slots in queue, submit ops */
  8315. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8316. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8317. 0, &times, agreeTimes, &pending)) {
  8318. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8319. privSz[i], pub2, pubSz2);
  8320. if (!bench_async_handle(&ret,
  8321. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8322. goto exit;
  8323. }
  8324. }
  8325. } /* for i */
  8326. RECORD_MULTI_VALUE_STATS();
  8327. } /* for times */
  8328. count += times;
  8329. } while (bench_stats_check(start)
  8330. #ifdef MULTI_VALUE_STATISTICS
  8331. || runs < minimum_runs
  8332. #endif
  8333. );
  8334. PRIVATE_KEY_LOCK();
  8335. exit:
  8336. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8337. useDeviceID, count, start, ret);
  8338. #ifdef MULTI_VALUE_STATISTICS
  8339. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8340. #endif
  8341. /* cleanup */
  8342. if (WC_ARRAY_OK(dhKey)) {
  8343. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8344. wc_FreeDhKey(dhKey[i]);
  8345. }
  8346. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8347. }
  8348. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8349. WC_FREE_VAR(pub2, HEAP_HINT);
  8350. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8351. WC_FREE_VAR(priv2, HEAP_HINT);
  8352. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8353. }
  8354. #endif /* !NO_DH */
  8355. #ifdef WOLFSSL_HAVE_KYBER
  8356. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8357. KyberKey* key)
  8358. {
  8359. int ret = 0, times, count, pending = 0;
  8360. double start;
  8361. const char**desc = bench_desc_words[lng_index];
  8362. DECLARE_MULTI_VALUE_STATS_VARS()
  8363. /* KYBER Make Key */
  8364. bench_stats_start(&count, &start);
  8365. do {
  8366. /* while free pending slots in queue, submit ops */
  8367. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8368. wc_KyberKey_Free(key);
  8369. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8370. if (ret != 0)
  8371. goto exit;
  8372. #ifdef KYBER_NONDETERMINISTIC
  8373. ret = wc_KyberKey_MakeKey(key, &gRng);
  8374. #else
  8375. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8376. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8377. #endif
  8378. if (ret != 0)
  8379. goto exit;
  8380. RECORD_MULTI_VALUE_STATS();
  8381. } /* for times */
  8382. count += times;
  8383. } while (bench_stats_check(start)
  8384. #ifdef MULTI_VALUE_STATISTICS
  8385. || runs < minimum_runs
  8386. #endif
  8387. );
  8388. exit:
  8389. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8390. #ifdef MULTI_VALUE_STATISTICS
  8391. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8392. #endif
  8393. }
  8394. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8395. {
  8396. int ret = 0, times, count, pending = 0;
  8397. double start;
  8398. const char**desc = bench_desc_words[lng_index];
  8399. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8400. byte ss[KYBER_SS_SZ];
  8401. word32 ctSz;
  8402. DECLARE_MULTI_VALUE_STATS_VARS()
  8403. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8404. if (ret != 0) {
  8405. return;
  8406. }
  8407. /* KYBER Encapsulate */
  8408. bench_stats_start(&count, &start);
  8409. do {
  8410. /* while free pending slots in queue, submit ops */
  8411. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8412. #ifdef KYBER_NONDETERMINISTIC
  8413. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8414. #else
  8415. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8416. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8417. sizeof(rand));
  8418. #endif
  8419. if (ret != 0)
  8420. goto exit_encap;
  8421. RECORD_MULTI_VALUE_STATS();
  8422. } /* for times */
  8423. count += times;
  8424. } while (bench_stats_check(start)
  8425. #ifdef MULTI_VALUE_STATISTICS
  8426. || runs < minimum_runs
  8427. #endif
  8428. );
  8429. exit_encap:
  8430. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8431. #ifdef MULTI_VALUE_STATISTICS
  8432. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8433. #endif
  8434. RESET_MULTI_VALUE_STATS_VARS();
  8435. /* KYBER Decapsulate */
  8436. bench_stats_start(&count, &start);
  8437. do {
  8438. /* while free pending slots in queue, submit ops */
  8439. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8440. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8441. if (ret != 0)
  8442. goto exit_decap;
  8443. RECORD_MULTI_VALUE_STATS();
  8444. } /* for times */
  8445. count += times;
  8446. } while (bench_stats_check(start)
  8447. #ifdef MULTI_VALUE_STATISTICS
  8448. || runs < minimum_runs
  8449. #endif
  8450. );
  8451. exit_decap:
  8452. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8453. #ifdef MULTI_VALUE_STATISTICS
  8454. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8455. #endif
  8456. }
  8457. void bench_kyber(int type)
  8458. {
  8459. KyberKey key;
  8460. const char* name = NULL;
  8461. int keySize = 0;
  8462. switch (type) {
  8463. #ifdef WOLFSSL_KYBER512
  8464. case KYBER512:
  8465. name = "KYBER512 ";
  8466. keySize = 128;
  8467. break;
  8468. #endif
  8469. #ifdef WOLFSSL_KYBER768
  8470. case KYBER768:
  8471. name = "KYBER768 ";
  8472. keySize = 192;
  8473. break;
  8474. #endif
  8475. #ifdef WOLFSSL_KYBER1024
  8476. case KYBER1024:
  8477. name = "KYBER1024";
  8478. keySize = 256;
  8479. break;
  8480. #endif
  8481. }
  8482. bench_kyber_keygen(type, name, keySize, &key);
  8483. bench_kyber_encap(name, keySize, &key);
  8484. wc_KyberKey_Free(&key);
  8485. }
  8486. #endif
  8487. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8488. /* WC_LMS_PARM_L2_H10_W2
  8489. * signature length: 9300 */
  8490. static const byte lms_priv_L2_H10_W2[64] =
  8491. {
  8492. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8493. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8494. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8495. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8496. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8497. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8498. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8499. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8500. };
  8501. static const byte lms_pub_L2_H10_W2[60] =
  8502. {
  8503. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8504. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8505. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8506. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8507. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8508. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8509. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8510. 0x7F,0xC8,0x91,0xB0
  8511. };
  8512. /* WC_LMS_PARM_L2_H10_W4
  8513. * signature length: 5076 */
  8514. static const byte lms_priv_L2_H10_W4[64] =
  8515. {
  8516. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8517. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8518. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8519. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8520. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8521. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8522. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8523. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8524. };
  8525. static const byte lms_pub_L2_H10_W4[60] =
  8526. {
  8527. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8528. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8529. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8530. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8531. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8532. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8533. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8534. 0x6B,0x9A,0xD3,0x14
  8535. };
  8536. /* WC_LMS_PARM_L3_H5_W4
  8537. * signature length: 7160 */
  8538. static const byte lms_priv_L3_H5_W4[64] =
  8539. {
  8540. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8541. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8542. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8543. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8544. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8545. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8546. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8547. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8548. };
  8549. static const byte lms_pub_L3_H5_W4[60] =
  8550. {
  8551. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8552. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8553. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8554. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8555. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8556. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8557. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8558. 0xAB,0x4B,0x51,0x39
  8559. };
  8560. /* WC_LMS_PARM_L3_H5_W8
  8561. * signature length: 3992 */
  8562. static const byte lms_priv_L3_H5_W8[64] =
  8563. {
  8564. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8565. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8566. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8567. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8568. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8569. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8570. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8571. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8572. };
  8573. static const byte lms_pub_L3_H5_W8[60] =
  8574. {
  8575. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8576. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8577. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8578. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8579. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8580. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8581. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8582. 0x83,0xAB,0x43,0xAF
  8583. };
  8584. /* WC_LMS_PARM_L3_H10_W4
  8585. * signature length: 7640 */
  8586. static const byte lms_priv_L3_H10_W4[64] =
  8587. {
  8588. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8589. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8590. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8591. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8592. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8593. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8594. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8595. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8596. };
  8597. static const byte lms_pub_L3_H10_W4[60] =
  8598. {
  8599. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8600. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8601. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8602. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8603. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8604. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8605. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8606. 0x8D,0x78,0xD5,0xA8
  8607. };
  8608. /* WC_LMS_PARM_L4_H5_W8
  8609. * signature length: 5340 */
  8610. static const byte lms_priv_L4_H5_W8[64] =
  8611. {
  8612. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8613. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8614. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8615. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8616. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8617. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8618. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8619. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8620. };
  8621. static const byte lms_pub_L4_H5_W8[60] =
  8622. {
  8623. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8624. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8625. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8626. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8627. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8628. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8629. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8630. 0x74,0x24,0x12,0xC8
  8631. };
  8632. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8633. {
  8634. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8635. * BE USED FOR TESTING PURPOSES! Production applications should
  8636. * write only to non-volatile storage. */
  8637. XMEMCPY(context, priv, privSz);
  8638. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8639. }
  8640. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8641. {
  8642. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8643. * BE USED FOR TESTING PURPOSES! */
  8644. XMEMCPY(priv, context, privSz);
  8645. return WC_LMS_RC_READ_TO_MEMORY;
  8646. }
  8647. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8648. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8649. {
  8650. WC_RNG rng;
  8651. LmsKey key;
  8652. int ret;
  8653. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8654. int times = 0;
  8655. int count = 0;
  8656. double start = 0.0F;
  8657. int levels;
  8658. int height;
  8659. int winternitz;
  8660. const char* str = wc_LmsKey_ParmToStr(parm);
  8661. DECLARE_MULTI_VALUE_STATS_VARS()
  8662. #ifndef HAVE_FIPS
  8663. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8664. #else
  8665. ret = wc_InitRng(&rng);
  8666. #endif
  8667. if (ret != 0) {
  8668. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8669. return;
  8670. }
  8671. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8672. if (ret) {
  8673. printf("wc_LmsKey_Init failed: %d\n", ret);
  8674. wc_FreeRng(&rng);
  8675. return;
  8676. }
  8677. count = 0;
  8678. bench_stats_start(&count, &start);
  8679. do {
  8680. /* LMS is stateful. Async queuing not practical. */
  8681. for (times = 0; times < 1; ++times) {
  8682. wc_LmsKey_Free(&key);
  8683. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8684. if (ret) {
  8685. printf("wc_LmsKey_Init failed: %d\n", ret);
  8686. goto exit_lms_keygen;
  8687. }
  8688. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8689. if (ret) {
  8690. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8691. goto exit_lms_keygen;
  8692. }
  8693. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8694. if (ret) {
  8695. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8696. ret);
  8697. goto exit_lms_keygen;
  8698. }
  8699. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8700. if (ret) {
  8701. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8702. ret);
  8703. goto exit_lms_keygen;
  8704. }
  8705. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8706. if (ret) {
  8707. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8708. goto exit_lms_keygen;
  8709. }
  8710. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8711. if (ret) {
  8712. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8713. ret);
  8714. goto exit_lms_keygen;
  8715. }
  8716. ret = wc_LmsKey_MakeKey(&key, &rng);
  8717. if (ret) {
  8718. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8719. goto exit_lms_keygen;
  8720. }
  8721. RECORD_MULTI_VALUE_STATS();
  8722. }
  8723. count += times;
  8724. } while (bench_stats_check(start)
  8725. #ifdef MULTI_VALUE_STATISTICS
  8726. || runs < minimum_runs
  8727. #endif
  8728. );
  8729. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8730. count, start, ret);
  8731. #ifdef MULTI_VALUE_STATISTICS
  8732. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8733. #endif
  8734. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8735. if (ret) {
  8736. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8737. }
  8738. exit_lms_keygen:
  8739. wc_LmsKey_Free(&key);
  8740. wc_FreeRng(&rng);
  8741. }
  8742. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8743. {
  8744. LmsKey key;
  8745. int ret = 0;
  8746. const char * msg = TEST_STRING;
  8747. word32 msgSz = TEST_STRING_SZ;
  8748. byte * sig = NULL;
  8749. word32 sigSz = 0;
  8750. word32 privLen = 0;
  8751. int loaded = 0;
  8752. int times = 0;
  8753. int count = 0;
  8754. double start = 0.0F;
  8755. const char * str = wc_LmsKey_ParmToStr(parm);
  8756. DECLARE_MULTI_VALUE_STATS_VARS()
  8757. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8758. if (ret) {
  8759. printf("wc_LmsKey_Init failed: %d\n", ret);
  8760. goto exit_lms_sign_verify;
  8761. }
  8762. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8763. if (ret) {
  8764. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8765. goto exit_lms_sign_verify;
  8766. }
  8767. switch (parm) {
  8768. case WC_LMS_PARM_L2_H10_W2:
  8769. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8770. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8771. break;
  8772. case WC_LMS_PARM_L2_H10_W4:
  8773. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8774. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8775. break;
  8776. case WC_LMS_PARM_L3_H5_W4:
  8777. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8778. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8779. break;
  8780. case WC_LMS_PARM_L3_H5_W8:
  8781. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8782. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8783. break;
  8784. case WC_LMS_PARM_L3_H10_W4:
  8785. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8786. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8787. break;
  8788. case WC_LMS_PARM_L4_H5_W8:
  8789. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8790. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8791. break;
  8792. case WC_LMS_PARM_NONE:
  8793. case WC_LMS_PARM_L1_H15_W2:
  8794. case WC_LMS_PARM_L1_H15_W4:
  8795. case WC_LMS_PARM_L2_H10_W8:
  8796. case WC_LMS_PARM_L3_H5_W2:
  8797. case WC_LMS_PARM_L1_H5_W1:
  8798. case WC_LMS_PARM_L1_H5_W2:
  8799. case WC_LMS_PARM_L1_H5_W4:
  8800. case WC_LMS_PARM_L1_H5_W8:
  8801. case WC_LMS_PARM_L1_H10_W2:
  8802. case WC_LMS_PARM_L1_H10_W4:
  8803. case WC_LMS_PARM_L1_H10_W8:
  8804. case WC_LMS_PARM_L1_H15_W8:
  8805. case WC_LMS_PARM_L1_H20_W2:
  8806. case WC_LMS_PARM_L1_H20_W4:
  8807. case WC_LMS_PARM_L1_H20_W8:
  8808. case WC_LMS_PARM_L2_H5_W2:
  8809. case WC_LMS_PARM_L2_H5_W4:
  8810. case WC_LMS_PARM_L2_H5_W8:
  8811. case WC_LMS_PARM_L2_H15_W2:
  8812. case WC_LMS_PARM_L2_H15_W4:
  8813. case WC_LMS_PARM_L2_H15_W8:
  8814. case WC_LMS_PARM_L2_H20_W2:
  8815. case WC_LMS_PARM_L2_H20_W4:
  8816. case WC_LMS_PARM_L2_H20_W8:
  8817. case WC_LMS_PARM_L3_H10_W8:
  8818. case WC_LMS_PARM_L4_H5_W2:
  8819. case WC_LMS_PARM_L4_H5_W4:
  8820. case WC_LMS_PARM_L4_H10_W4:
  8821. case WC_LMS_PARM_L4_H10_W8:
  8822. default:
  8823. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8824. break;
  8825. }
  8826. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8827. if (ret) {
  8828. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8829. goto exit_lms_sign_verify;
  8830. }
  8831. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8832. if (ret) {
  8833. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8834. goto exit_lms_sign_verify;
  8835. }
  8836. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8837. if (ret) {
  8838. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  8839. goto exit_lms_sign_verify;
  8840. }
  8841. /* Even with saved priv/pub keys, we must still reload the private
  8842. * key before using it. Reloading the private key is the bottleneck
  8843. * for larger heights. Only print load time in debug builds. */
  8844. count = 0;
  8845. bench_stats_start(&count, &start);
  8846. #ifndef WOLFSSL_WC_LMS_SMALL
  8847. do {
  8848. #ifdef WOLFSSL_WC_LMS
  8849. key.priv.inited = 0;
  8850. key.state = WC_LMS_STATE_PARMSET;
  8851. #endif
  8852. ret = wc_LmsKey_Reload(&key);
  8853. if (ret) {
  8854. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8855. goto exit_lms_sign_verify;
  8856. }
  8857. RECORD_MULTI_VALUE_STATS();
  8858. count++;
  8859. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8860. if (ret) {
  8861. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8862. goto exit_lms_sign_verify;
  8863. }
  8864. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8865. if (ret) {
  8866. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8867. goto exit_lms_sign_verify;
  8868. }
  8869. #ifdef HAVE_LIBLMS
  8870. break;
  8871. #endif
  8872. } while (bench_stats_check(start)
  8873. #ifdef MULTI_VALUE_STATISTICS
  8874. || runs < minimum_runs
  8875. #endif
  8876. );
  8877. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  8878. count, start, ret);
  8879. #ifdef MULTI_VALUE_STATISTICS
  8880. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8881. #endif
  8882. RESET_MULTI_VALUE_STATS_VARS();
  8883. #else
  8884. ret = wc_LmsKey_Reload(&key);
  8885. if (ret) {
  8886. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8887. goto exit_lms_sign_verify;
  8888. }
  8889. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8890. if (ret) {
  8891. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8892. goto exit_lms_sign_verify;
  8893. }
  8894. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8895. if (ret) {
  8896. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8897. goto exit_lms_sign_verify;
  8898. }
  8899. #endif
  8900. loaded = 1;
  8901. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8902. if (sig == NULL) {
  8903. printf("bench_lms_sign_verify malloc failed\n");
  8904. goto exit_lms_sign_verify;
  8905. }
  8906. count = 0;
  8907. bench_stats_start(&count, &start);
  8908. do {
  8909. /* LMS is stateful. Async queuing not practical. */
  8910. #ifndef WOLFSSL_WC_LMS_SMALL
  8911. for (times = 0; times < ntimes; ++times)
  8912. #else
  8913. for (times = 0; times < 1; ++times)
  8914. #endif
  8915. {
  8916. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  8917. if (ret) {
  8918. printf("wc_LmsKey_Sign failed: %d\n", ret);
  8919. goto exit_lms_sign_verify;
  8920. }
  8921. RECORD_MULTI_VALUE_STATS();
  8922. if (!wc_LmsKey_SigsLeft(&key)) {
  8923. break;
  8924. }
  8925. }
  8926. count += times;
  8927. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  8928. #ifdef MULTI_VALUE_STATISTICS
  8929. || runs < minimum_runs
  8930. #endif
  8931. ));
  8932. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  8933. count, start, ret);
  8934. #ifdef MULTI_VALUE_STATISTICS
  8935. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8936. #endif
  8937. RESET_MULTI_VALUE_STATS_VARS();
  8938. count = 0;
  8939. bench_stats_start(&count, &start);
  8940. do {
  8941. /* LMS is stateful. Async queuing not practical. */
  8942. for (times = 0; times < ntimes; ++times) {
  8943. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  8944. if (ret) {
  8945. printf("wc_LmsKey_Verify failed: %d\n", ret);
  8946. goto exit_lms_sign_verify;
  8947. }
  8948. RECORD_MULTI_VALUE_STATS();
  8949. }
  8950. count += times;
  8951. } while (bench_stats_check(start)
  8952. #ifdef MULTI_VALUE_STATISTICS
  8953. || runs < minimum_runs
  8954. #endif
  8955. );
  8956. exit_lms_sign_verify:
  8957. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  8958. count, start, ret);
  8959. #ifdef MULTI_VALUE_STATISTICS
  8960. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8961. #endif
  8962. if (loaded) {
  8963. wc_LmsKey_Free(&key);
  8964. }
  8965. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8966. return;
  8967. }
  8968. void bench_lms(void)
  8969. {
  8970. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  8971. #ifdef BENCH_LMS_SLOW_KEYGEN
  8972. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  8973. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  8974. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  8975. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  8976. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  8977. #undef LMS_PARAMS_BENCHED
  8978. #define LMS_PARAMS_BENCHED
  8979. #endif
  8980. #endif
  8981. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  8982. (LMS_MAX_HEIGHT >= 10))
  8983. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  8984. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  8985. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  8986. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  8987. #undef LMS_PARAMS_BENCHED
  8988. #define LMS_PARAMS_BENCHED
  8989. #ifdef BENCH_LMS_SLOW_KEYGEN
  8990. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  8991. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  8992. #endif
  8993. #endif
  8994. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  8995. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  8996. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  8997. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  8998. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  8999. #undef LMS_PARAMS_BENCHED
  9000. #define LMS_PARAMS_BENCHED
  9001. #endif
  9002. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9003. (LMS_MAX_HEIGHT >= 10))
  9004. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9005. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9006. #endif
  9007. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9008. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9009. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9010. #endif
  9011. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9012. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9013. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9014. #endif
  9015. return;
  9016. }
  9017. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9018. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9019. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9020. void *context)
  9021. {
  9022. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9023. * BE USED FOR TESTING PURPOSES! Production applications should
  9024. * write only to non-volatile storage. */
  9025. XMEMCPY(context, priv, privSz);
  9026. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9027. }
  9028. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9029. void *context)
  9030. {
  9031. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9032. * BE USED FOR TESTING PURPOSES! */
  9033. XMEMCPY(priv, context, privSz);
  9034. return WC_XMSS_RC_READ_TO_MEMORY;
  9035. }
  9036. static void bench_xmss_sign_verify(const char * params)
  9037. {
  9038. WC_RNG rng;
  9039. XmssKey key;
  9040. word32 pkSz = 0;
  9041. word32 skSz = 0;
  9042. int freeRng = 0;
  9043. int freeKey = 0;
  9044. unsigned char * sk = NULL;
  9045. const char * msg = "XMSS post quantum signature test";
  9046. word32 msgSz = (word32) XSTRLEN(msg);
  9047. int ret = 0;
  9048. byte * sig = NULL;
  9049. word32 sigSz = 0;
  9050. int times = 0;
  9051. int count = 0;
  9052. double start = 0.0F;
  9053. #ifndef HAVE_FIPS
  9054. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9055. #else
  9056. ret = wc_InitRng(&rng);
  9057. #endif
  9058. if (ret != 0) {
  9059. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9060. goto exit_xmss_sign_verify;
  9061. }
  9062. freeRng = 1;
  9063. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9064. if (ret != 0) {
  9065. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9066. goto exit_xmss_sign_verify;
  9067. }
  9068. ret = wc_XmssKey_SetParamStr(&key, params);
  9069. if (ret != 0) {
  9070. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9071. goto exit_xmss_sign_verify;
  9072. }
  9073. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9074. if (ret != 0) {
  9075. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9076. goto exit_xmss_sign_verify;
  9077. }
  9078. #ifndef WOLFSSL_WC_XMSS
  9079. if (pkSz != XMSS_SHA256_PUBLEN) {
  9080. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9081. XMSS_SHA256_PUBLEN);
  9082. goto exit_xmss_sign_verify;
  9083. }
  9084. #endif
  9085. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9086. if (ret != 0 || skSz <= 0) {
  9087. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9088. goto exit_xmss_sign_verify;
  9089. }
  9090. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9091. if (ret != 0 || sigSz <= 0) {
  9092. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9093. goto exit_xmss_sign_verify;
  9094. }
  9095. /* Allocate secret keys.*/
  9096. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9097. if (sk == NULL) {
  9098. fprintf(stderr, "error: allocate xmss sk failed\n");
  9099. goto exit_xmss_sign_verify;
  9100. }
  9101. /* Allocate signature array. */
  9102. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9103. if (sig == NULL) {
  9104. fprintf(stderr, "error: allocate xmss sig failed\n");
  9105. goto exit_xmss_sign_verify;
  9106. }
  9107. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9108. if (ret != 0) {
  9109. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9110. goto exit_xmss_sign_verify;
  9111. }
  9112. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9113. if (ret != 0) {
  9114. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9115. goto exit_xmss_sign_verify;
  9116. }
  9117. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9118. if (ret != 0) {
  9119. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9120. goto exit_xmss_sign_verify;
  9121. }
  9122. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9123. fprintf(stderr, "params: %s\n", params);
  9124. fprintf(stderr, "pkSz: %d\n", pkSz);
  9125. fprintf(stderr, "skSz: %d\n", skSz);
  9126. fprintf(stderr, "sigSz: %d\n", sigSz);
  9127. #endif
  9128. /* Making the private key is the bottleneck for larger heights. */
  9129. count = 0;
  9130. bench_stats_start(&count, &start);
  9131. ret = wc_XmssKey_MakeKey(&key, &rng);
  9132. if (ret != 0) {
  9133. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9134. goto exit_xmss_sign_verify;
  9135. }
  9136. /* Can only do one at a time - state changes after make key. */
  9137. count +=1;
  9138. bench_stats_check(start);
  9139. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9140. freeKey = 1;
  9141. count = 0;
  9142. bench_stats_start(&count, &start);
  9143. do {
  9144. /* XMSS is stateful. Async queuing not practical. */
  9145. #ifndef WOLFSSL_WC_XMSS_SMALL
  9146. for (times = 0; times < ntimes; ++times)
  9147. #else
  9148. for (times = 0; times < 1; ++times)
  9149. #endif
  9150. {
  9151. if (!wc_XmssKey_SigsLeft(&key))
  9152. break;
  9153. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9154. if (ret) {
  9155. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9156. goto exit_xmss_sign_verify;
  9157. }
  9158. }
  9159. count += times;
  9160. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9161. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9162. count = 0;
  9163. bench_stats_start(&count, &start);
  9164. do {
  9165. /* XMSS is stateful. Async queuing not practical. */
  9166. for (times = 0; times < ntimes; ++times) {
  9167. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9168. if (ret) {
  9169. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9170. goto exit_xmss_sign_verify;
  9171. }
  9172. }
  9173. count += times;
  9174. } while (bench_stats_check(start));
  9175. exit_xmss_sign_verify:
  9176. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9177. /* Cleanup everything. */
  9178. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9179. sig = NULL;
  9180. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9181. sk = NULL;
  9182. if (freeRng) {
  9183. wc_FreeRng(&rng);
  9184. }
  9185. if (freeKey) {
  9186. wc_XmssKey_Free(&key);
  9187. }
  9188. return;
  9189. }
  9190. void bench_xmss(int hash)
  9191. {
  9192. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9193. * sets.
  9194. *
  9195. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9196. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9197. * very slow, their signatures and private keys quite large,
  9198. * and xmss private keys are not portable across different
  9199. * XMSS/XMSS^MT implementations.
  9200. *
  9201. * The bottleneck in key generation is the height of the first
  9202. * level tree (or h/d).
  9203. *
  9204. * h is the total height of the hyper tree, and d the number of
  9205. * trees.
  9206. */
  9207. /* h/d h d */
  9208. #ifdef WC_XMSS_SHA256
  9209. if (hash == WC_HASH_TYPE_SHA256) {
  9210. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9211. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9212. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9213. #endif
  9214. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9215. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9216. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9217. #endif
  9218. #endif
  9219. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9220. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9221. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9222. #endif
  9223. #endif
  9224. #endif /* HASH_SIZE 256 */
  9225. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9226. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9227. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9228. #endif
  9229. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9230. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9231. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9232. #endif
  9233. #endif
  9234. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9235. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9236. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9237. #endif
  9238. #endif
  9239. #endif /* HASH_SIZE 192 */
  9240. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9241. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9242. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9243. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9244. #endif
  9245. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9246. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9247. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9248. #endif
  9249. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9250. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9251. #endif
  9252. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9253. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9254. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9255. #endif
  9256. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9257. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9258. #endif
  9259. #endif /* HASH_SIZE 256 */
  9260. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9261. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9262. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9263. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9264. #endif
  9265. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9266. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9267. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9268. #endif
  9269. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9270. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9271. #endif
  9272. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9273. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9274. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9275. #endif
  9276. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9277. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9278. #endif
  9279. #endif /* HASH_SIZE 192 */
  9280. }
  9281. #endif
  9282. #ifdef WC_XMSS_SHA512
  9283. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9284. if (hash == WC_HASH_TYPE_SHA512) {
  9285. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9286. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9287. #endif
  9288. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9289. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9290. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9291. #endif
  9292. #endif
  9293. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9294. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9295. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9296. #endif
  9297. #endif
  9298. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9299. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9300. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9301. #endif
  9302. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9303. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9304. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9305. #endif
  9306. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9307. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9308. #endif
  9309. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9310. #endif
  9311. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9312. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9313. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9314. #endif
  9315. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9316. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9317. #endif
  9318. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9319. #endif
  9320. }
  9321. #endif /* HASH_SIZE 512 */
  9322. #endif
  9323. #ifdef WC_XMSS_SHAKE128
  9324. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9325. if (hash == WC_HASH_TYPE_SHAKE128) {
  9326. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9327. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9328. #endif
  9329. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9330. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9331. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9332. #endif
  9333. #endif
  9334. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9335. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9336. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9337. #endif
  9338. #endif
  9339. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9340. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9341. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9342. #endif
  9343. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9344. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9345. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9346. #endif
  9347. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9348. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9349. #endif
  9350. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9351. #endif
  9352. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9353. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9354. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9355. #endif
  9356. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9357. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9358. #endif
  9359. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9360. #endif
  9361. }
  9362. #endif /* HASH_SIZE 256 */
  9363. #endif
  9364. #ifdef WC_XMSS_SHAKE256
  9365. if (hash == WC_HASH_TYPE_SHAKE256) {
  9366. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9367. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9368. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9369. #endif
  9370. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9371. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9372. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9373. #endif
  9374. #endif
  9375. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9376. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9377. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9378. #endif
  9379. #endif
  9380. #endif /* HASH_SIZE 512 */
  9381. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9382. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9383. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9384. #endif
  9385. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9386. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9387. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9388. #endif
  9389. #endif
  9390. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9391. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9392. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9393. #endif
  9394. #endif
  9395. #endif /* HASH_SIZE 256 */
  9396. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9397. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9398. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9399. #endif
  9400. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9401. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9402. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9403. #endif
  9404. #endif
  9405. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9406. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9407. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9408. #endif
  9409. #endif
  9410. #endif /* HASH_SIZE 192 */
  9411. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9412. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9413. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9414. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9415. #endif
  9416. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9417. #endif
  9418. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9419. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9420. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9421. #endif
  9422. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9423. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9424. #endif
  9425. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9426. #endif
  9427. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9428. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9429. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9430. #endif
  9431. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9432. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9433. #endif
  9434. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9435. #endif
  9436. #endif /* HASH_SIZE 512 */
  9437. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9438. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9439. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9440. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9441. #endif
  9442. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9443. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9444. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9445. #endif
  9446. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9447. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9448. #endif
  9449. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9450. #endif
  9451. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9452. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9453. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9454. #endif
  9455. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9456. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9457. #endif
  9458. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9459. #endif
  9460. #endif /* HASH_SIZE 256 */
  9461. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9462. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9463. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9464. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9465. #endif
  9466. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9467. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9468. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9469. #endif
  9470. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9471. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9472. #endif
  9473. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9474. #endif
  9475. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9476. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9477. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9478. #endif
  9479. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9480. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9481. #endif
  9482. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9483. #endif
  9484. #endif /* HASH_SIZE 192 */
  9485. }
  9486. #endif
  9487. return;
  9488. }
  9489. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9490. #ifdef HAVE_ECC
  9491. /* Maximum ECC name plus null terminator:
  9492. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9493. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9494. /* run all benchmarks on a curve */
  9495. void bench_ecc_curve(int curveId)
  9496. {
  9497. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9498. #ifndef NO_SW_BENCH
  9499. bench_eccMakeKey(0, curveId);
  9500. #endif
  9501. #if defined(BENCH_DEVID)
  9502. bench_eccMakeKey(1, curveId);
  9503. #endif
  9504. }
  9505. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9506. #ifndef NO_SW_BENCH
  9507. bench_ecc(0, curveId);
  9508. #endif
  9509. #if defined(BENCH_DEVID)
  9510. bench_ecc(1, curveId);
  9511. #endif
  9512. }
  9513. #ifdef HAVE_ECC_ENCRYPT
  9514. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9515. bench_eccEncrypt(curveId);
  9516. #endif
  9517. }
  9518. void bench_eccMakeKey(int useDeviceID, int curveId)
  9519. {
  9520. int ret = 0, i, times, count = 0, pending = 0;
  9521. int deviceID;
  9522. int keySize = 0;
  9523. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9524. sizeof(ecc_key), HEAP_HINT);
  9525. char name[BENCH_ECC_NAME_SZ];
  9526. double start = 0;
  9527. const char**desc = bench_desc_words[lng_index];
  9528. DECLARE_MULTI_VALUE_STATS_VARS()
  9529. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9530. sizeof(ecc_key), HEAP_HINT);
  9531. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9532. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9533. /* ECC Make Key */
  9534. bench_stats_start(&count, &start);
  9535. do {
  9536. /* while free pending slots in queue, submit ops */
  9537. for (times = 0; times < agreeTimes || pending > 0; ) {
  9538. bench_async_poll(&pending);
  9539. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9540. if (bench_async_check(&ret,
  9541. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9542. &times, agreeTimes, &pending)) {
  9543. wc_ecc_free(genKey[i]);
  9544. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9545. if (ret < 0) {
  9546. goto exit;
  9547. }
  9548. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9549. curveId);
  9550. if (!bench_async_handle(&ret,
  9551. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9552. &pending)) {
  9553. goto exit;
  9554. }
  9555. }
  9556. } /* for i */
  9557. RECORD_MULTI_VALUE_STATS();
  9558. } /* for times */
  9559. count += times;
  9560. } while (bench_stats_check(start)
  9561. #ifdef MULTI_VALUE_STATISTICS
  9562. || runs < minimum_runs
  9563. #endif
  9564. );
  9565. exit:
  9566. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9567. wc_ecc_get_name(curveId));
  9568. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9569. useDeviceID, count, start, ret);
  9570. #ifdef MULTI_VALUE_STATISTICS
  9571. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9572. #endif
  9573. /* cleanup */
  9574. if (WC_ARRAY_OK(genKey)) {
  9575. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9576. wc_ecc_free(genKey[i]);
  9577. }
  9578. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9579. }
  9580. }
  9581. void bench_ecc(int useDeviceID, int curveId)
  9582. {
  9583. int ret = 0, i, times, count, pending = 0;
  9584. int deviceID;
  9585. int keySize;
  9586. char name[BENCH_ECC_NAME_SZ];
  9587. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9588. sizeof(ecc_key), HEAP_HINT);
  9589. #ifdef HAVE_ECC_DHE
  9590. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9591. sizeof(ecc_key), HEAP_HINT);
  9592. #endif
  9593. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9594. #ifdef HAVE_ECC_VERIFY
  9595. int verify[BENCH_MAX_PENDING];
  9596. #endif
  9597. #endif
  9598. word32 x[BENCH_MAX_PENDING];
  9599. double start = 0;
  9600. const char**desc = bench_desc_words[lng_index];
  9601. DECLARE_MULTI_VALUE_STATS_VARS()
  9602. #ifdef HAVE_ECC_DHE
  9603. WC_DECLARE_ARRAY(shared, byte,
  9604. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9605. #endif
  9606. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9607. WC_DECLARE_ARRAY(sig, byte,
  9608. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9609. WC_DECLARE_ARRAY(digest, byte,
  9610. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9611. #endif
  9612. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9613. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9614. XMEMSET(sig, 0, sizeof(sig));
  9615. XMEMSET(digest, 0, sizeof(digest));
  9616. #endif
  9617. #ifdef HAVE_ECC_DHE
  9618. XMEMSET(shared, 0, sizeof(shared));
  9619. #endif
  9620. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9621. sizeof(ecc_key), HEAP_HINT);
  9622. #ifdef HAVE_ECC_DHE
  9623. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9624. sizeof(ecc_key), HEAP_HINT);
  9625. WC_ALLOC_ARRAY(shared, byte,
  9626. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9627. #endif
  9628. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9629. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9630. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9631. #endif
  9632. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9633. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9634. /* init keys */
  9635. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9636. /* setup an context for each key */
  9637. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9638. goto exit;
  9639. }
  9640. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9641. #ifdef WOLFSSL_ASYNC_CRYPT
  9642. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9643. #endif
  9644. if (ret < 0) {
  9645. goto exit;
  9646. }
  9647. #ifdef HAVE_ECC_DHE
  9648. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9649. goto exit;
  9650. }
  9651. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9652. curveId)) > 0) {
  9653. goto exit;
  9654. }
  9655. #endif
  9656. }
  9657. #ifdef HAVE_ECC_DHE
  9658. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9659. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9660. !defined(HAVE_SELFTEST)
  9661. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9662. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9663. }
  9664. #endif
  9665. /* ECC Shared Secret */
  9666. bench_stats_start(&count, &start);
  9667. PRIVATE_KEY_UNLOCK();
  9668. do {
  9669. for (times = 0; times < agreeTimes || pending > 0; ) {
  9670. bench_async_poll(&pending);
  9671. /* while free pending slots in queue, submit ops */
  9672. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9673. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9674. &times, agreeTimes, &pending)) {
  9675. x[i] = (word32)keySize;
  9676. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9677. shared[i], &x[i]);
  9678. if (!bench_async_handle(&ret,
  9679. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9680. &pending)) {
  9681. goto exit_ecdhe;
  9682. }
  9683. }
  9684. } /* for i */
  9685. RECORD_MULTI_VALUE_STATS();
  9686. } /* for times */
  9687. count += times;
  9688. } while (bench_stats_check(start)
  9689. #ifdef MULTI_VALUE_STATISTICS
  9690. || runs < minimum_runs
  9691. #endif
  9692. );
  9693. PRIVATE_KEY_UNLOCK();
  9694. exit_ecdhe:
  9695. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9696. wc_ecc_get_name(curveId));
  9697. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9698. useDeviceID, count, start, ret);
  9699. #ifdef MULTI_VALUE_STATISTICS
  9700. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9701. #endif
  9702. RESET_MULTI_VALUE_STATS_VARS();
  9703. if (ret < 0) {
  9704. goto exit;
  9705. }
  9706. #endif /* HAVE_ECC_DHE */
  9707. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9708. /* Init digest to sign */
  9709. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9710. for (count = 0; count < keySize; count++) {
  9711. digest[i][count] = (byte)count;
  9712. }
  9713. }
  9714. /* ECC Sign */
  9715. bench_stats_start(&count, &start);
  9716. do {
  9717. for (times = 0; times < agreeTimes || pending > 0; ) {
  9718. bench_async_poll(&pending);
  9719. /* while free pending slots in queue, submit ops */
  9720. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9721. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9722. &times, agreeTimes, &pending)) {
  9723. if (genKey[i]->state == 0) {
  9724. x[i] = ECC_MAX_SIG_SIZE;
  9725. }
  9726. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9727. &x[i], GLOBAL_RNG, genKey[i]);
  9728. if (!bench_async_handle(&ret,
  9729. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9730. &pending)) {
  9731. goto exit_ecdsa_sign;
  9732. }
  9733. } /* bench_async_check */
  9734. } /* for i */
  9735. RECORD_MULTI_VALUE_STATS();
  9736. } /* for times */
  9737. count += times;
  9738. } while (bench_stats_check(start)
  9739. #ifdef MULTI_VALUE_STATISTICS
  9740. || runs < minimum_runs
  9741. #endif
  9742. );
  9743. exit_ecdsa_sign:
  9744. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9745. wc_ecc_get_name(curveId));
  9746. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9747. useDeviceID, count, start, ret);
  9748. #ifdef MULTI_VALUE_STATISTICS
  9749. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9750. #endif
  9751. RESET_MULTI_VALUE_STATS_VARS();
  9752. if (ret < 0) {
  9753. goto exit;
  9754. }
  9755. #ifdef HAVE_ECC_VERIFY
  9756. /* ECC Verify */
  9757. bench_stats_start(&count, &start);
  9758. do {
  9759. for (times = 0; times < agreeTimes || pending > 0; ) {
  9760. bench_async_poll(&pending);
  9761. /* while free pending slots in queue, submit ops */
  9762. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9763. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9764. &times, agreeTimes, &pending)) {
  9765. if (genKey[i]->state == 0) {
  9766. verify[i] = 0;
  9767. }
  9768. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9769. (word32)keySize, &verify[i],
  9770. genKey[i]);
  9771. if (!bench_async_handle(&ret,
  9772. BENCH_ASYNC_GET_DEV(genKey[i]),
  9773. 1, &times,
  9774. &pending)) {
  9775. goto exit_ecdsa_verify;
  9776. }
  9777. } /* if bench_async_check */
  9778. } /* for i */
  9779. RECORD_MULTI_VALUE_STATS();
  9780. } /* for times */
  9781. count += times;
  9782. } while (bench_stats_check(start)
  9783. #ifdef MULTI_VALUE_STATISTICS
  9784. || runs < minimum_runs
  9785. #endif
  9786. );
  9787. exit_ecdsa_verify:
  9788. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9789. wc_ecc_get_name(curveId));
  9790. bench_stats_asym_finish(name, keySize * 8, desc[5],
  9791. useDeviceID, count, start, ret);
  9792. #ifdef MULTI_VALUE_STATISTICS
  9793. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9794. #endif
  9795. #endif /* HAVE_ECC_VERIFY */
  9796. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  9797. exit:
  9798. /* cleanup */
  9799. if (WC_ARRAY_OK(genKey)) {
  9800. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9801. wc_ecc_free(genKey[i]);
  9802. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9803. }
  9804. #ifdef HAVE_ECC_DHE
  9805. if (WC_ARRAY_OK(genKey2)) {
  9806. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9807. wc_ecc_free(genKey2[i]);
  9808. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  9809. }
  9810. #endif
  9811. #ifdef HAVE_ECC_DHE
  9812. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  9813. #endif
  9814. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9815. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  9816. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  9817. #endif
  9818. (void)useDeviceID;
  9819. (void)pending;
  9820. (void)x;
  9821. (void)count;
  9822. (void)times;
  9823. (void)desc;
  9824. (void)start;
  9825. (void)name;
  9826. }
  9827. #ifdef HAVE_ECC_ENCRYPT
  9828. void bench_eccEncrypt(int curveId)
  9829. {
  9830. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  9831. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  9832. WC_SHA256_DIGEST_SIZE + \
  9833. (MAX_ECC_BITS+3)/4 + 2)
  9834. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  9835. #ifdef WOLFSSL_SMALL_STACK
  9836. ecc_key *userA = NULL, *userB = NULL;
  9837. byte *msg = NULL;
  9838. byte *out = NULL;
  9839. #else
  9840. ecc_key userA[1], userB[1];
  9841. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  9842. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  9843. #endif
  9844. char name[BENCH_ECC_NAME_SZ];
  9845. int keySize;
  9846. word32 bench_plainSz = bench_size;
  9847. int ret, i, count;
  9848. double start;
  9849. const char**desc = bench_desc_words[lng_index];
  9850. DECLARE_MULTI_VALUE_STATS_VARS()
  9851. #ifdef WOLFSSL_SMALL_STACK
  9852. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  9853. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9854. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  9855. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9856. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  9857. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9858. out = (byte *)XMALLOC(outSz,
  9859. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9860. if ((! userA) || (! userB) || (! msg) || (! out)) {
  9861. printf("bench_eccEncrypt malloc failed\n");
  9862. goto exit;
  9863. }
  9864. #endif
  9865. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9866. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  9867. if (ret != 0) {
  9868. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  9869. goto exit;
  9870. }
  9871. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  9872. if (ret != 0) {
  9873. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  9874. goto exit;
  9875. }
  9876. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9877. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9878. !defined(HAVE_SELFTEST)
  9879. ret = wc_ecc_set_rng(userA, &gRng);
  9880. if (ret != 0) {
  9881. goto exit;
  9882. }
  9883. ret = wc_ecc_set_rng(userB, &gRng);
  9884. if (ret != 0) {
  9885. goto exit;
  9886. }
  9887. #endif
  9888. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  9889. #ifdef WOLFSSL_ASYNC_CRYPT
  9890. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  9891. #endif
  9892. if (ret != 0)
  9893. goto exit;
  9894. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  9895. #ifdef WOLFSSL_ASYNC_CRYPT
  9896. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  9897. #endif
  9898. if (ret != 0)
  9899. goto exit;
  9900. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  9901. msg[i] = (byte)i;
  9902. }
  9903. bench_stats_start(&count, &start);
  9904. do {
  9905. for (i = 0; i < ntimes; i++) {
  9906. /* encrypt msg to B */
  9907. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  9908. out, &outSz, NULL);
  9909. if (ret != 0) {
  9910. printf("wc_ecc_encrypt failed! %d\n", ret);
  9911. goto exit_enc;
  9912. }
  9913. RECORD_MULTI_VALUE_STATS();
  9914. }
  9915. count += i;
  9916. } while (bench_stats_check(start)
  9917. #ifdef MULTI_VALUE_STATISTICS
  9918. || runs < minimum_runs
  9919. #endif
  9920. );
  9921. exit_enc:
  9922. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9923. wc_ecc_get_name(curveId));
  9924. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  9925. #ifdef MULTI_VALUE_STATISTICS
  9926. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9927. #endif
  9928. RESET_MULTI_VALUE_STATS_VARS();
  9929. if (ret != 0)
  9930. goto exit;
  9931. bench_stats_start(&count, &start);
  9932. do {
  9933. for (i = 0; i < ntimes; i++) {
  9934. /* decrypt msg from A */
  9935. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  9936. &bench_plainSz, NULL);
  9937. if (ret != 0) {
  9938. printf("wc_ecc_decrypt failed! %d\n", ret);
  9939. goto exit_dec;
  9940. }
  9941. RECORD_MULTI_VALUE_STATS();
  9942. }
  9943. count += i;
  9944. } while (bench_stats_check(start)
  9945. #ifdef MULTI_VALUE_STATISTICS
  9946. || runs < minimum_runs
  9947. #endif
  9948. );
  9949. exit_dec:
  9950. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  9951. #ifdef MULTI_VALUE_STATISTICS
  9952. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9953. #endif
  9954. exit:
  9955. /* cleanup */
  9956. #ifdef WOLFSSL_SMALL_STACK
  9957. if (userA) {
  9958. wc_ecc_free(userA);
  9959. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9960. }
  9961. if (userB) {
  9962. wc_ecc_free(userB);
  9963. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9964. }
  9965. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9966. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9967. #else
  9968. wc_ecc_free(userB);
  9969. wc_ecc_free(userA);
  9970. #endif
  9971. }
  9972. #endif
  9973. #ifdef WOLFSSL_SM2
  9974. static void bench_sm2_MakeKey(int useDeviceID)
  9975. {
  9976. int ret = 0, i, times, count = 0, pending = 0;
  9977. int deviceID;
  9978. int keySize;
  9979. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9980. sizeof(ecc_key), HEAP_HINT);
  9981. char name[BENCH_ECC_NAME_SZ];
  9982. double start = 0;
  9983. const char**desc = bench_desc_words[lng_index];
  9984. DECLARE_MULTI_VALUE_STATS_VARS()
  9985. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9986. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  9987. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9988. sizeof(ecc_key), HEAP_HINT);
  9989. /* ECC Make Key */
  9990. bench_stats_start(&count, &start);
  9991. do {
  9992. /* while free pending slots in queue, submit ops */
  9993. for (times = 0; times < agreeTimes || pending > 0; ) {
  9994. bench_async_poll(&pending);
  9995. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9996. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9997. &times, agreeTimes, &pending)) {
  9998. wc_ecc_free(genKey[i]);
  9999. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10000. if (ret < 0) {
  10001. goto exit;
  10002. }
  10003. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10004. WC_ECC_FLAG_NONE);
  10005. if (!bench_async_handle(&ret,
  10006. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10007. &pending)) {
  10008. goto exit;
  10009. }
  10010. }
  10011. } /* for i */
  10012. RECORD_MULTI_VALUE_STATS();
  10013. } /* for times */
  10014. count += times;
  10015. } while (bench_stats_check(start)
  10016. #ifdef MULTI_VALUE_STATISTICS
  10017. || runs < minimum_runs
  10018. #endif
  10019. );
  10020. exit:
  10021. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10022. wc_ecc_get_name(ECC_SM2P256V1));
  10023. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10024. start, ret);
  10025. #ifdef MULTI_VALUE_STATISTICS
  10026. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10027. #endif
  10028. /* cleanup */
  10029. if (WC_ARRAY_OK(genKey)) {
  10030. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10031. wc_ecc_free(genKey[i]);
  10032. }
  10033. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10034. }
  10035. }
  10036. void bench_sm2(int useDeviceID)
  10037. {
  10038. int ret = 0, i, times, count, pending = 0;
  10039. int deviceID;
  10040. int keySize;
  10041. char name[BENCH_ECC_NAME_SZ];
  10042. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10043. sizeof(ecc_key), HEAP_HINT);
  10044. #ifdef HAVE_ECC_DHE
  10045. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10046. sizeof(ecc_key), HEAP_HINT);
  10047. #endif
  10048. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10049. #ifdef HAVE_ECC_VERIFY
  10050. int verify[BENCH_MAX_PENDING];
  10051. #endif
  10052. #endif
  10053. word32 x[BENCH_MAX_PENDING];
  10054. double start = 0;
  10055. const char**desc = bench_desc_words[lng_index];
  10056. DECLARE_MULTI_VALUE_STATS_VARS()
  10057. #ifdef HAVE_ECC_DHE
  10058. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10059. #endif
  10060. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10061. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10062. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10063. #endif
  10064. #ifdef HAVE_ECC_DHE
  10065. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10066. #endif
  10067. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10068. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10069. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10070. #endif
  10071. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10072. bench_sm2_MakeKey(useDeviceID);
  10073. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10074. sizeof(ecc_key), HEAP_HINT);
  10075. #ifdef HAVE_ECC_DHE
  10076. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10077. sizeof(ecc_key), HEAP_HINT);
  10078. #endif
  10079. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10080. /* init keys */
  10081. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10082. /* setup an context for each key */
  10083. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10084. goto exit;
  10085. }
  10086. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10087. #ifdef WOLFSSL_ASYNC_CRYPT
  10088. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10089. #endif
  10090. if (ret < 0) {
  10091. goto exit;
  10092. }
  10093. #ifdef HAVE_ECC_DHE
  10094. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10095. goto exit;
  10096. }
  10097. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10098. WC_ECC_FLAG_NONE)) > 0) {
  10099. goto exit;
  10100. }
  10101. #endif
  10102. }
  10103. #ifdef HAVE_ECC_DHE
  10104. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10105. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10106. !defined(HAVE_SELFTEST)
  10107. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10108. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10109. }
  10110. #endif
  10111. /* ECC Shared Secret */
  10112. bench_stats_start(&count, &start);
  10113. PRIVATE_KEY_UNLOCK();
  10114. do {
  10115. for (times = 0; times < agreeTimes || pending > 0; ) {
  10116. bench_async_poll(&pending);
  10117. /* while free pending slots in queue, submit ops */
  10118. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10119. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10120. &times, agreeTimes, &pending)) {
  10121. x[i] = (word32)keySize;
  10122. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10123. shared[i], &x[i]);
  10124. if (!bench_async_handle(&ret,
  10125. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10126. &pending)) {
  10127. goto exit_ecdhe;
  10128. }
  10129. }
  10130. } /* for i */
  10131. RECORD_MULTI_VALUE_STATS();
  10132. } /* for times */
  10133. count += times;
  10134. } while (bench_stats_check(start)
  10135. #ifdef MULTI_VALUE_STATISTICS
  10136. || runs < minimum_runs
  10137. #endif
  10138. );
  10139. PRIVATE_KEY_UNLOCK();
  10140. exit_ecdhe:
  10141. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10142. wc_ecc_get_name(ECC_SM2P256V1));
  10143. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10144. start, ret);
  10145. #ifdef MULTI_VALUE_STATISTICS
  10146. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10147. #endif
  10148. if (ret < 0) {
  10149. goto exit;
  10150. }
  10151. #endif /* HAVE_ECC_DHE */
  10152. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10153. /* Init digest to sign */
  10154. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10155. for (count = 0; count < keySize; count++) {
  10156. digest[i][count] = (byte)count;
  10157. }
  10158. }
  10159. RESET_MULTI_VALUE_STATS_VARS();
  10160. /* ECC Sign */
  10161. bench_stats_start(&count, &start);
  10162. do {
  10163. for (times = 0; times < agreeTimes || pending > 0; ) {
  10164. bench_async_poll(&pending);
  10165. /* while free pending slots in queue, submit ops */
  10166. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10167. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10168. &times, agreeTimes, &pending)) {
  10169. if (genKey[i]->state == 0)
  10170. x[i] = ECC_MAX_SIG_SIZE;
  10171. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10172. sig[i], &x[i], &gRng, genKey[i]);
  10173. if (!bench_async_handle(&ret,
  10174. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10175. &pending)) {
  10176. goto exit_ecdsa_sign;
  10177. }
  10178. }
  10179. } /* for i */
  10180. RECORD_MULTI_VALUE_STATS();
  10181. } /* for times */
  10182. count += times;
  10183. } while (bench_stats_check(start)
  10184. #ifdef MULTI_VALUE_STATISTICS
  10185. || runs < minimum_runs
  10186. #endif
  10187. );
  10188. exit_ecdsa_sign:
  10189. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10190. wc_ecc_get_name(ECC_SM2P256V1));
  10191. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10192. start, ret);
  10193. #ifdef MULTI_VALUE_STATISTICS
  10194. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10195. #endif
  10196. if (ret < 0) {
  10197. goto exit;
  10198. }
  10199. #ifdef HAVE_ECC_VERIFY
  10200. /* ECC Verify */
  10201. bench_stats_start(&count, &start);
  10202. do {
  10203. for (times = 0; times < agreeTimes || pending > 0; ) {
  10204. bench_async_poll(&pending);
  10205. /* while free pending slots in queue, submit ops */
  10206. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10207. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10208. &times, agreeTimes, &pending)) {
  10209. if (genKey[i]->state == 0)
  10210. verify[i] = 0;
  10211. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10212. (word32)keySize, &verify[i], genKey[i]);
  10213. if (!bench_async_handle(&ret,
  10214. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10215. &pending)) {
  10216. goto exit_ecdsa_verify;
  10217. }
  10218. }
  10219. } /* for i */
  10220. RECORD_MULTI_VALUE_STATS();
  10221. } /* for times */
  10222. count += times;
  10223. } while (bench_stats_check(start)
  10224. #ifdef MULTI_VALUE_STATISTICS
  10225. || runs < minimum_runs
  10226. #endif
  10227. );
  10228. exit_ecdsa_verify:
  10229. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10230. wc_ecc_get_name(ECC_SM2P256V1));
  10231. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10232. start, ret);
  10233. #ifdef MULTI_VALUE_STATISTICS
  10234. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10235. #endif
  10236. #endif /* HAVE_ECC_VERIFY */
  10237. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10238. exit:
  10239. /* cleanup */
  10240. if (WC_ARRAY_OK(genKey)) {
  10241. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10242. wc_ecc_free(genKey[i]);
  10243. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10244. }
  10245. #ifdef HAVE_ECC_DHE
  10246. if (WC_ARRAY_OK(genKey2)) {
  10247. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10248. wc_ecc_free(genKey2[i]);
  10249. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10250. }
  10251. #endif
  10252. #ifdef HAVE_ECC_DHE
  10253. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10254. #endif
  10255. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10256. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10257. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10258. #endif
  10259. (void)useDeviceID;
  10260. (void)pending;
  10261. (void)x;
  10262. (void)count;
  10263. (void)times;
  10264. (void)desc;
  10265. (void)start;
  10266. (void)name;
  10267. }
  10268. #endif /* WOLFSSL_SM2 */
  10269. #endif /* HAVE_ECC */
  10270. #ifdef HAVE_CURVE25519
  10271. void bench_curve25519KeyGen(int useDeviceID)
  10272. {
  10273. curve25519_key genKey;
  10274. double start;
  10275. int ret = 0, i, count;
  10276. const char**desc = bench_desc_words[lng_index];
  10277. DECLARE_MULTI_VALUE_STATS_VARS()
  10278. /* Key Gen */
  10279. bench_stats_start(&count, &start);
  10280. do {
  10281. for (i = 0; i < genTimes; i++) {
  10282. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10283. useDeviceID ? devId : INVALID_DEVID);
  10284. if (ret != 0) {
  10285. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10286. break;
  10287. }
  10288. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10289. wc_curve25519_free(&genKey);
  10290. if (ret != 0) {
  10291. printf("wc_curve25519_make_key failed: %d\n", ret);
  10292. break;
  10293. }
  10294. RECORD_MULTI_VALUE_STATS();
  10295. }
  10296. count += i;
  10297. } while (bench_stats_check(start)
  10298. #ifdef MULTI_VALUE_STATISTICS
  10299. || runs < minimum_runs
  10300. #endif
  10301. );
  10302. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10303. ret);
  10304. #ifdef MULTI_VALUE_STATISTICS
  10305. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10306. #endif
  10307. }
  10308. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10309. void bench_curve25519KeyAgree(int useDeviceID)
  10310. {
  10311. curve25519_key genKey, genKey2;
  10312. double start;
  10313. int ret, i, count;
  10314. byte shared[32];
  10315. const char**desc = bench_desc_words[lng_index];
  10316. word32 x = 0;
  10317. DECLARE_MULTI_VALUE_STATS_VARS()
  10318. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10319. useDeviceID ? devId : INVALID_DEVID);
  10320. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10321. useDeviceID ? devId : INVALID_DEVID);
  10322. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10323. if (ret != 0) {
  10324. printf("curve25519_make_key failed\n");
  10325. return;
  10326. }
  10327. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10328. if (ret != 0) {
  10329. printf("curve25519_make_key failed: %d\n", ret);
  10330. wc_curve25519_free(&genKey);
  10331. return;
  10332. }
  10333. /* Shared secret */
  10334. bench_stats_start(&count, &start);
  10335. do {
  10336. for (i = 0; i < agreeTimes; i++) {
  10337. x = sizeof(shared);
  10338. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10339. if (ret != 0) {
  10340. printf("curve25519_shared_secret failed: %d\n", ret);
  10341. goto exit;
  10342. }
  10343. RECORD_MULTI_VALUE_STATS();
  10344. }
  10345. count += i;
  10346. } while (bench_stats_check(start)
  10347. #ifdef MULTI_VALUE_STATISTICS
  10348. || runs < minimum_runs
  10349. #endif
  10350. );
  10351. exit:
  10352. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10353. ret);
  10354. #ifdef MULTI_VALUE_STATISTICS
  10355. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10356. #endif
  10357. wc_curve25519_free(&genKey2);
  10358. wc_curve25519_free(&genKey);
  10359. }
  10360. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10361. #endif /* HAVE_CURVE25519 */
  10362. #ifdef HAVE_ED25519
  10363. void bench_ed25519KeyGen(void)
  10364. {
  10365. #ifdef HAVE_ED25519_MAKE_KEY
  10366. ed25519_key genKey;
  10367. double start;
  10368. int i, count;
  10369. const char**desc = bench_desc_words[lng_index];
  10370. DECLARE_MULTI_VALUE_STATS_VARS()
  10371. /* Key Gen */
  10372. bench_stats_start(&count, &start);
  10373. do {
  10374. for (i = 0; i < genTimes; i++) {
  10375. wc_ed25519_init(&genKey);
  10376. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10377. wc_ed25519_free(&genKey);
  10378. RECORD_MULTI_VALUE_STATS();
  10379. }
  10380. count += i;
  10381. } while (bench_stats_check(start)
  10382. #ifdef MULTI_VALUE_STATISTICS
  10383. || runs < minimum_runs
  10384. #endif
  10385. );
  10386. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10387. #ifdef MULTI_VALUE_STATISTICS
  10388. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10389. #endif
  10390. #endif /* HAVE_ED25519_MAKE_KEY */
  10391. }
  10392. void bench_ed25519KeySign(void)
  10393. {
  10394. #ifdef HAVE_ED25519_MAKE_KEY
  10395. int ret;
  10396. #endif
  10397. ed25519_key genKey;
  10398. #ifdef HAVE_ED25519_SIGN
  10399. double start;
  10400. int i, count;
  10401. byte sig[ED25519_SIG_SIZE];
  10402. byte msg[512];
  10403. word32 x = 0;
  10404. const char**desc = bench_desc_words[lng_index];
  10405. DECLARE_MULTI_VALUE_STATS_VARS()
  10406. #endif
  10407. wc_ed25519_init(&genKey);
  10408. #ifdef HAVE_ED25519_MAKE_KEY
  10409. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10410. if (ret != 0) {
  10411. printf("ed25519_make_key failed\n");
  10412. return;
  10413. }
  10414. #endif
  10415. #ifdef HAVE_ED25519_SIGN
  10416. /* make dummy msg */
  10417. for (i = 0; i < (int)sizeof(msg); i++)
  10418. msg[i] = (byte)i;
  10419. bench_stats_start(&count, &start);
  10420. do {
  10421. for (i = 0; i < agreeTimes; i++) {
  10422. x = sizeof(sig);
  10423. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10424. if (ret != 0) {
  10425. printf("ed25519_sign_msg failed\n");
  10426. goto exit_ed_sign;
  10427. }
  10428. RECORD_MULTI_VALUE_STATS();
  10429. }
  10430. count += i;
  10431. } while (bench_stats_check(start)
  10432. #ifdef MULTI_VALUE_STATISTICS
  10433. || runs < minimum_runs
  10434. #endif
  10435. );
  10436. exit_ed_sign:
  10437. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10438. #ifdef MULTI_VALUE_STATISTICS
  10439. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10440. #endif
  10441. RESET_MULTI_VALUE_STATS_VARS();
  10442. #ifdef HAVE_ED25519_VERIFY
  10443. bench_stats_start(&count, &start);
  10444. do {
  10445. for (i = 0; i < agreeTimes; i++) {
  10446. int verify = 0;
  10447. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10448. &genKey);
  10449. if (ret != 0 || verify != 1) {
  10450. printf("ed25519_verify_msg failed\n");
  10451. goto exit_ed_verify;
  10452. }
  10453. RECORD_MULTI_VALUE_STATS();
  10454. }
  10455. count += i;
  10456. } while (bench_stats_check(start)
  10457. #ifdef MULTI_VALUE_STATISTICS
  10458. || runs < minimum_runs
  10459. #endif
  10460. );
  10461. exit_ed_verify:
  10462. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10463. #ifdef MULTI_VALUE_STATISTICS
  10464. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10465. #endif
  10466. #endif /* HAVE_ED25519_VERIFY */
  10467. #endif /* HAVE_ED25519_SIGN */
  10468. wc_ed25519_free(&genKey);
  10469. }
  10470. #endif /* HAVE_ED25519 */
  10471. #ifdef HAVE_CURVE448
  10472. void bench_curve448KeyGen(void)
  10473. {
  10474. curve448_key genKey;
  10475. double start;
  10476. int ret = 0, i, count;
  10477. const char**desc = bench_desc_words[lng_index];
  10478. DECLARE_MULTI_VALUE_STATS_VARS()
  10479. /* Key Gen */
  10480. bench_stats_start(&count, &start);
  10481. do {
  10482. for (i = 0; i < genTimes; i++) {
  10483. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10484. wc_curve448_free(&genKey);
  10485. if (ret != 0) {
  10486. printf("wc_curve448_make_key failed: %d\n", ret);
  10487. break;
  10488. }
  10489. RECORD_MULTI_VALUE_STATS();
  10490. }
  10491. count += i;
  10492. } while (bench_stats_check(start)
  10493. #ifdef MULTI_VALUE_STATISTICS
  10494. || runs < minimum_runs
  10495. #endif
  10496. );
  10497. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10498. #ifdef MULTI_VALUE_STATISTICS
  10499. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10500. #endif
  10501. }
  10502. #ifdef HAVE_CURVE448_SHARED_SECRET
  10503. void bench_curve448KeyAgree(void)
  10504. {
  10505. curve448_key genKey, genKey2;
  10506. double start;
  10507. int ret, i, count;
  10508. byte shared[56];
  10509. const char**desc = bench_desc_words[lng_index];
  10510. word32 x = 0;
  10511. DECLARE_MULTI_VALUE_STATS_VARS()
  10512. wc_curve448_init(&genKey);
  10513. wc_curve448_init(&genKey2);
  10514. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10515. if (ret != 0) {
  10516. printf("curve448_make_key failed\n");
  10517. return;
  10518. }
  10519. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10520. if (ret != 0) {
  10521. printf("curve448_make_key failed: %d\n", ret);
  10522. wc_curve448_free(&genKey);
  10523. return;
  10524. }
  10525. /* Shared secret */
  10526. bench_stats_start(&count, &start);
  10527. do {
  10528. for (i = 0; i < agreeTimes; i++) {
  10529. x = sizeof(shared);
  10530. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10531. if (ret != 0) {
  10532. printf("curve448_shared_secret failed: %d\n", ret);
  10533. goto exit;
  10534. }
  10535. RECORD_MULTI_VALUE_STATS();
  10536. }
  10537. count += i;
  10538. } while (bench_stats_check(start)
  10539. #ifdef MULTI_VALUE_STATISTICS
  10540. || runs < minimum_runs
  10541. #endif
  10542. );
  10543. exit:
  10544. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10545. #ifdef MULTI_VALUE_STATISTICS
  10546. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10547. #endif
  10548. wc_curve448_free(&genKey2);
  10549. wc_curve448_free(&genKey);
  10550. }
  10551. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10552. #endif /* HAVE_CURVE448 */
  10553. #ifdef HAVE_ED448
  10554. void bench_ed448KeyGen(void)
  10555. {
  10556. ed448_key genKey;
  10557. double start;
  10558. int i, count;
  10559. const char**desc = bench_desc_words[lng_index];
  10560. DECLARE_MULTI_VALUE_STATS_VARS()
  10561. /* Key Gen */
  10562. bench_stats_start(&count, &start);
  10563. do {
  10564. for (i = 0; i < genTimes; i++) {
  10565. wc_ed448_init(&genKey);
  10566. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10567. wc_ed448_free(&genKey);
  10568. RECORD_MULTI_VALUE_STATS();
  10569. }
  10570. count += i;
  10571. } while (bench_stats_check(start)
  10572. #ifdef MULTI_VALUE_STATISTICS
  10573. || runs < minimum_runs
  10574. #endif
  10575. );
  10576. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10577. #ifdef MULTI_VALUE_STATISTICS
  10578. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10579. #endif
  10580. }
  10581. void bench_ed448KeySign(void)
  10582. {
  10583. int ret;
  10584. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10585. #ifdef HAVE_ED448_SIGN
  10586. double start;
  10587. int i, count;
  10588. byte sig[ED448_SIG_SIZE];
  10589. byte msg[512];
  10590. word32 x = 0;
  10591. const char**desc = bench_desc_words[lng_index];
  10592. DECLARE_MULTI_VALUE_STATS_VARS()
  10593. #endif
  10594. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10595. wc_ed448_init(genKey);
  10596. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10597. if (ret != 0) {
  10598. printf("ed448_make_key failed\n");
  10599. goto exit;
  10600. }
  10601. #ifdef HAVE_ED448_SIGN
  10602. /* make dummy msg */
  10603. for (i = 0; i < (int)sizeof(msg); i++)
  10604. msg[i] = (byte)i;
  10605. bench_stats_start(&count, &start);
  10606. do {
  10607. for (i = 0; i < agreeTimes; i++) {
  10608. x = sizeof(sig);
  10609. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10610. NULL, 0);
  10611. if (ret != 0) {
  10612. printf("ed448_sign_msg failed\n");
  10613. goto exit;
  10614. }
  10615. RECORD_MULTI_VALUE_STATS();
  10616. }
  10617. count += i;
  10618. } while (bench_stats_check(start)
  10619. #ifdef MULTI_VALUE_STATISTICS
  10620. || runs < minimum_runs
  10621. #endif
  10622. );
  10623. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10624. #ifdef MULTI_VALUE_STATISTICS
  10625. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10626. #endif
  10627. RESET_MULTI_VALUE_STATS_VARS();
  10628. #ifdef HAVE_ED448_VERIFY
  10629. bench_stats_start(&count, &start);
  10630. do {
  10631. for (i = 0; i < agreeTimes; i++) {
  10632. int verify = 0;
  10633. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10634. genKey, NULL, 0);
  10635. if (ret != 0 || verify != 1) {
  10636. printf("ed448_verify_msg failed\n");
  10637. goto exit;
  10638. }
  10639. RECORD_MULTI_VALUE_STATS();
  10640. }
  10641. count += i;
  10642. } while (bench_stats_check(start)
  10643. #ifdef MULTI_VALUE_STATISTICS
  10644. || runs < minimum_runs
  10645. #endif
  10646. );
  10647. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10648. #ifdef MULTI_VALUE_STATISTICS
  10649. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10650. #endif
  10651. #endif /* HAVE_ED448_VERIFY */
  10652. #endif /* HAVE_ED448_SIGN */
  10653. exit:
  10654. wc_ed448_free(genKey);
  10655. WC_FREE_VAR(genKey, HEAP_HINT);
  10656. }
  10657. #endif /* HAVE_ED448 */
  10658. #ifdef WOLFCRYPT_HAVE_ECCSI
  10659. #ifdef WOLFCRYPT_ECCSI_KMS
  10660. void bench_eccsiKeyGen(void)
  10661. {
  10662. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10663. double start;
  10664. int i, count;
  10665. const char**desc = bench_desc_words[lng_index];
  10666. int ret;
  10667. DECLARE_MULTI_VALUE_STATS_VARS()
  10668. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10669. /* Key Gen */
  10670. bench_stats_start(&count, &start);
  10671. do {
  10672. for (i = 0; i < genTimes; i++) {
  10673. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10674. ret = wc_MakeEccsiKey(genKey, &gRng);
  10675. wc_FreeEccsiKey(genKey);
  10676. if (ret != 0) {
  10677. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10678. goto exit;
  10679. }
  10680. RECORD_MULTI_VALUE_STATS();
  10681. }
  10682. count += i;
  10683. } while (bench_stats_check(start)
  10684. #ifdef MULTI_VALUE_STATISTICS
  10685. || runs < minimum_runs
  10686. #endif
  10687. );
  10688. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10689. #ifdef MULTI_VALUE_STATISTICS
  10690. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10691. #endif
  10692. exit:
  10693. WC_FREE_VAR(genKey, HEAP_HINT);
  10694. }
  10695. void bench_eccsiPairGen(void)
  10696. {
  10697. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10698. double start;
  10699. int i, count;
  10700. const char**desc = bench_desc_words[lng_index];
  10701. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10702. ecc_point* pvt;
  10703. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10704. int ret;
  10705. DECLARE_MULTI_VALUE_STATS_VARS()
  10706. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10707. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10708. (void)mp_init(ssk);
  10709. pvt = wc_ecc_new_point();
  10710. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10711. (void)wc_MakeEccsiKey(genKey, &gRng);
  10712. /* RSK Gen */
  10713. bench_stats_start(&count, &start);
  10714. do {
  10715. for (i = 0; i < genTimes; i++) {
  10716. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10717. sizeof(id), ssk, pvt);
  10718. if (ret != 0) {
  10719. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10720. goto exit;
  10721. }
  10722. RECORD_MULTI_VALUE_STATS();
  10723. }
  10724. count += i;
  10725. } while (bench_stats_check(start)
  10726. #ifdef MULTI_VALUE_STATISTICS
  10727. || runs < minimum_runs
  10728. #endif
  10729. );
  10730. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10731. #ifdef MULTI_VALUE_STATISTICS
  10732. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10733. #endif
  10734. wc_FreeEccsiKey(genKey);
  10735. wc_ecc_del_point(pvt);
  10736. mp_free(ssk);
  10737. exit:
  10738. WC_FREE_VAR(genKey, HEAP_HINT);
  10739. WC_FREE_VAR(ssk, HEAP_HINT);
  10740. }
  10741. #endif
  10742. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10743. void bench_eccsiValidate(void)
  10744. {
  10745. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10746. double start;
  10747. int i, count;
  10748. const char**desc = bench_desc_words[lng_index];
  10749. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10750. ecc_point* pvt;
  10751. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10752. int valid;
  10753. int ret;
  10754. DECLARE_MULTI_VALUE_STATS_VARS()
  10755. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10756. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10757. (void)mp_init(ssk);
  10758. pvt = wc_ecc_new_point();
  10759. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10760. (void)wc_MakeEccsiKey(genKey, &gRng);
  10761. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10762. ssk, pvt);
  10763. /* Validation of RSK */
  10764. bench_stats_start(&count, &start);
  10765. do {
  10766. for (i = 0; i < genTimes; i++) {
  10767. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10768. sizeof(id), ssk, pvt, &valid);
  10769. if (ret != 0 || !valid) {
  10770. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10771. valid);
  10772. goto exit;
  10773. }
  10774. RECORD_MULTI_VALUE_STATS();
  10775. }
  10776. count += i;
  10777. } while (bench_stats_check(start)
  10778. #ifdef MULTI_VALUE_STATISTICS
  10779. || runs < minimum_runs
  10780. #endif
  10781. );
  10782. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10783. #ifdef MULTI_VALUE_STATISTICS
  10784. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10785. #endif
  10786. wc_FreeEccsiKey(genKey);
  10787. wc_ecc_del_point(pvt);
  10788. mp_free(ssk);
  10789. exit:
  10790. WC_FREE_VAR(genKey, HEAP_HINT);
  10791. WC_FREE_VAR(ssk, HEAP_HINT);
  10792. }
  10793. void bench_eccsi(void)
  10794. {
  10795. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10796. double start;
  10797. int i, count;
  10798. const char**desc = bench_desc_words[lng_index];
  10799. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10800. ecc_point* pvt;
  10801. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10802. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  10803. byte hash[WC_SHA256_DIGEST_SIZE];
  10804. byte hashSz = (byte)sizeof(hash);
  10805. byte sig[257];
  10806. word32 sigSz = sizeof(sig);
  10807. int ret;
  10808. int verified;
  10809. DECLARE_MULTI_VALUE_STATS_VARS()
  10810. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10811. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10812. (void)mp_init(ssk);
  10813. pvt = wc_ecc_new_point();
  10814. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10815. (void)wc_MakeEccsiKey(genKey, &gRng);
  10816. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10817. ssk, pvt);
  10818. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  10819. hash, &hashSz);
  10820. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  10821. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  10822. /* Encapsulate */
  10823. bench_stats_start(&count, &start);
  10824. do {
  10825. for (i = 0; i < genTimes; i++) {
  10826. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  10827. sizeof(msg), sig, &sigSz);
  10828. if (ret != 0) {
  10829. printf("wc_SignEccsiHash failed: %d\n", ret);
  10830. break;
  10831. }
  10832. RECORD_MULTI_VALUE_STATS();
  10833. }
  10834. count += i;
  10835. } while (bench_stats_check(start)
  10836. #ifdef MULTI_VALUE_STATISTICS
  10837. || runs < minimum_runs
  10838. #endif
  10839. );
  10840. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  10841. #ifdef MULTI_VALUE_STATISTICS
  10842. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10843. #endif
  10844. RESET_MULTI_VALUE_STATS_VARS();
  10845. /* Derive */
  10846. bench_stats_start(&count, &start);
  10847. do {
  10848. for (i = 0; i < genTimes; i++) {
  10849. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  10850. sizeof(msg), sig, sigSz, &verified);
  10851. if (ret != 0 || !verified) {
  10852. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  10853. verified);
  10854. goto exit;
  10855. }
  10856. RECORD_MULTI_VALUE_STATS();
  10857. }
  10858. count += i;
  10859. } while (bench_stats_check(start)
  10860. #ifdef MULTI_VALUE_STATISTICS
  10861. || runs < minimum_runs
  10862. #endif
  10863. );
  10864. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  10865. #ifdef MULTI_VALUE_STATISTICS
  10866. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10867. #endif
  10868. wc_FreeEccsiKey(genKey);
  10869. wc_ecc_del_point(pvt);
  10870. exit:
  10871. WC_FREE_VAR(genKey, HEAP_HINT);
  10872. WC_FREE_VAR(ssk, HEAP_HINT);
  10873. }
  10874. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  10875. #endif /* WOLFCRYPT_HAVE_ECCSI */
  10876. #ifdef WOLFCRYPT_HAVE_SAKKE
  10877. #ifdef WOLFCRYPT_SAKKE_KMS
  10878. void bench_sakkeKeyGen(void)
  10879. {
  10880. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10881. double start;
  10882. int i, count;
  10883. const char**desc = bench_desc_words[lng_index];
  10884. int ret;
  10885. DECLARE_MULTI_VALUE_STATS_VARS()
  10886. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10887. /* Key Gen */
  10888. bench_stats_start(&count, &start);
  10889. do {
  10890. for (i = 0; i < genTimes; i++) {
  10891. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10892. ret = wc_MakeSakkeKey(genKey, &gRng);
  10893. if (ret != 0) {
  10894. printf("wc_MakeSakkeKey failed: %d\n", ret);
  10895. goto exit;
  10896. }
  10897. wc_FreeSakkeKey(genKey);
  10898. RECORD_MULTI_VALUE_STATS();
  10899. }
  10900. count += i;
  10901. } while (bench_stats_check(start)
  10902. #ifdef MULTI_VALUE_STATISTICS
  10903. || runs < minimum_runs
  10904. #endif
  10905. );
  10906. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  10907. #ifdef MULTI_VALUE_STATISTICS
  10908. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10909. #endif
  10910. exit:
  10911. WC_FREE_VAR(genKey, HEAP_HINT);
  10912. }
  10913. void bench_sakkeRskGen(void)
  10914. {
  10915. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10916. double start;
  10917. int i, count;
  10918. const char**desc = bench_desc_words[lng_index];
  10919. ecc_point* rsk;
  10920. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10921. int ret;
  10922. DECLARE_MULTI_VALUE_STATS_VARS()
  10923. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10924. rsk = wc_ecc_new_point();
  10925. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10926. (void)wc_MakeSakkeKey(genKey, &gRng);
  10927. /* RSK Gen */
  10928. bench_stats_start(&count, &start);
  10929. do {
  10930. for (i = 0; i < genTimes; i++) {
  10931. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  10932. if (ret != 0) {
  10933. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  10934. goto exit;
  10935. }
  10936. RECORD_MULTI_VALUE_STATS();
  10937. }
  10938. count += i;
  10939. } while (bench_stats_check(start)
  10940. #ifdef MULTI_VALUE_STATISTICS
  10941. || runs < minimum_runs
  10942. #endif
  10943. );
  10944. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  10945. #ifdef MULTI_VALUE_STATISTICS
  10946. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10947. #endif
  10948. wc_FreeSakkeKey(genKey);
  10949. wc_ecc_del_point(rsk);
  10950. exit:
  10951. WC_FREE_VAR(genKey, HEAP_HINT);
  10952. }
  10953. #endif
  10954. #ifdef WOLFCRYPT_SAKKE_CLIENT
  10955. void bench_sakkeValidate(void)
  10956. {
  10957. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10958. double start;
  10959. int i, count;
  10960. const char**desc = bench_desc_words[lng_index];
  10961. ecc_point* rsk;
  10962. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10963. int valid;
  10964. int ret;
  10965. DECLARE_MULTI_VALUE_STATS_VARS()
  10966. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10967. rsk = wc_ecc_new_point();
  10968. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10969. (void)wc_MakeSakkeKey(genKey, &gRng);
  10970. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  10971. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  10972. /* Validation of RSK */
  10973. bench_stats_start(&count, &start);
  10974. do {
  10975. for (i = 0; i < genTimes; i++) {
  10976. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  10977. if (ret != 0 || !valid) {
  10978. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  10979. valid);
  10980. goto exit;
  10981. }
  10982. RECORD_MULTI_VALUE_STATS();
  10983. }
  10984. count += i;
  10985. } while (bench_stats_check(start)
  10986. #ifdef MULTI_VALUE_STATISTICS
  10987. || runs < minimum_runs
  10988. #endif
  10989. );
  10990. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  10991. #ifdef MULTI_VALUE_STATISTICS
  10992. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10993. #endif
  10994. wc_FreeSakkeKey(genKey);
  10995. wc_ecc_del_point(rsk);
  10996. exit:
  10997. WC_FREE_VAR(genKey, HEAP_HINT);
  10998. }
  10999. void bench_sakke(void)
  11000. {
  11001. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11002. double start;
  11003. int i, count;
  11004. const char**desc = bench_desc_words[lng_index];
  11005. ecc_point* rsk;
  11006. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11007. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11008. byte ssv[sizeof(ssv_init)];
  11009. byte derSSV[sizeof(ssv)];
  11010. byte auth[257];
  11011. word16 authSz = sizeof(auth);
  11012. int ret = 0;
  11013. byte* table = NULL;
  11014. word32 len = 0;
  11015. byte* iTable = NULL;
  11016. word32 iTableLen = 0;
  11017. DECLARE_MULTI_VALUE_STATS_VARS()
  11018. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11019. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11020. rsk = wc_ecc_new_point();
  11021. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11022. (void)wc_MakeSakkeKey(genKey, &gRng);
  11023. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11024. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11025. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11026. /* Encapsulate */
  11027. bench_stats_start(&count, &start);
  11028. do {
  11029. for (i = 0; i < genTimes; i++) {
  11030. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11031. WC_HASH_TYPE_SHA256,
  11032. ssv, sizeof(ssv), auth, &authSz);
  11033. if (ret != 0) {
  11034. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11035. break;
  11036. }
  11037. RECORD_MULTI_VALUE_STATS();
  11038. } /* for */
  11039. count += i;
  11040. } while (bench_stats_check(start)
  11041. #ifdef MULTI_VALUE_STATISTICS
  11042. || runs < minimum_runs
  11043. #endif
  11044. );
  11045. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11046. 0, count, start, 0);
  11047. #ifdef MULTI_VALUE_STATISTICS
  11048. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11049. #endif
  11050. RESET_MULTI_VALUE_STATS_VARS();
  11051. /* Derive */
  11052. bench_stats_start(&count, &start);
  11053. do {
  11054. for (i = 0; i < genTimes; i++) {
  11055. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11056. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11057. sizeof(derSSV), auth, authSz);
  11058. if (ret != 0) {
  11059. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11060. break;
  11061. }
  11062. RECORD_MULTI_VALUE_STATS();
  11063. }
  11064. if (ret != 0) break;
  11065. count += i;
  11066. } while (bench_stats_check(start)
  11067. #ifdef MULTI_VALUE_STATISTICS
  11068. || runs < minimum_runs
  11069. #endif
  11070. );
  11071. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11072. 0, count, start, 0);
  11073. #ifdef MULTI_VALUE_STATISTICS
  11074. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11075. #endif
  11076. /* Calculate Point I and generate table. */
  11077. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11078. iTableLen = 0;
  11079. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11080. if (iTableLen != 0) {
  11081. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11082. if (iTable == NULL)
  11083. WC_ALLOC_DO_ON_FAILURE();
  11084. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11085. }
  11086. /* Encapsulate with Point I table */
  11087. bench_stats_start(&count, &start);
  11088. do {
  11089. for (i = 0; i < genTimes; i++) {
  11090. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11091. WC_HASH_TYPE_SHA256, ssv,
  11092. sizeof(ssv), auth, &authSz);
  11093. if (ret != 0) {
  11094. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11095. break;
  11096. }
  11097. RECORD_MULTI_VALUE_STATS();
  11098. }
  11099. count += i;
  11100. } while (bench_stats_check(start)
  11101. #ifdef MULTI_VALUE_STATISTICS
  11102. || runs < minimum_runs
  11103. #endif
  11104. );
  11105. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11106. count, start, 0);
  11107. #ifdef MULTI_VALUE_STATISTICS
  11108. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11109. #endif
  11110. RESET_MULTI_VALUE_STATS_VARS();
  11111. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11112. /* Derive with Point I table */
  11113. bench_stats_start(&count, &start);
  11114. do {
  11115. for (i = 0; i < genTimes; i++) {
  11116. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11117. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11118. sizeof(derSSV), auth, authSz);
  11119. if (ret != 0) {
  11120. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11121. break;
  11122. }
  11123. RECORD_MULTI_VALUE_STATS();
  11124. }
  11125. if (ret != 0) break;
  11126. count += i;
  11127. } while (bench_stats_check(start)
  11128. #ifdef MULTI_VALUE_STATISTICS
  11129. || runs < minimum_runs
  11130. #endif
  11131. );
  11132. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11133. count, start, 0);
  11134. #ifdef MULTI_VALUE_STATISTICS
  11135. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11136. #endif
  11137. RESET_MULTI_VALUE_STATS_VARS();
  11138. len = 0;
  11139. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11140. if (len > 0) {
  11141. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11142. if (table == NULL)
  11143. WC_ALLOC_DO_ON_FAILURE();
  11144. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11145. }
  11146. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11147. /* Derive with Point I table and RSK table */
  11148. bench_stats_start(&count, &start);
  11149. do {
  11150. for (i = 0; i < genTimes; i++) {
  11151. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11152. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11153. sizeof(derSSV), auth, authSz);
  11154. if (ret != 0) {
  11155. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11156. break;
  11157. }
  11158. RECORD_MULTI_VALUE_STATS();
  11159. }
  11160. if (ret != 0) break;
  11161. count += i;
  11162. } while (bench_stats_check(start)
  11163. #ifdef MULTI_VALUE_STATISTICS
  11164. || runs < minimum_runs
  11165. #endif
  11166. );
  11167. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11168. 0, count, start, 0);
  11169. #ifdef MULTI_VALUE_STATISTICS
  11170. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11171. #endif
  11172. RESET_MULTI_VALUE_STATS_VARS();
  11173. wc_ClearSakkePointITable(genKey);
  11174. /* Derive with RSK table */
  11175. bench_stats_start(&count, &start);
  11176. do {
  11177. for (i = 0; i < genTimes; i++) {
  11178. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11179. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11180. sizeof(derSSV), auth, authSz);
  11181. if (ret != 0) {
  11182. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11183. break;
  11184. }
  11185. RECORD_MULTI_VALUE_STATS();
  11186. }
  11187. if (ret != 0) break;
  11188. count += i;
  11189. } while (bench_stats_check(start)
  11190. #ifdef MULTI_VALUE_STATISTICS
  11191. || runs < minimum_runs
  11192. #endif
  11193. );
  11194. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11195. count, start, 0);
  11196. #ifdef MULTI_VALUE_STATISTICS
  11197. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11198. #endif
  11199. wc_FreeSakkeKey(genKey);
  11200. wc_ecc_del_point(rsk);
  11201. exit:
  11202. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11203. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11204. WC_FREE_VAR(genKey, HEAP_HINT);
  11205. }
  11206. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11207. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11208. #ifdef HAVE_FALCON
  11209. void bench_falconKeySign(byte level)
  11210. {
  11211. int ret = 0;
  11212. falcon_key key;
  11213. double start;
  11214. int i, count;
  11215. byte sig[FALCON_MAX_SIG_SIZE];
  11216. byte msg[512];
  11217. word32 x = 0;
  11218. const char**desc = bench_desc_words[lng_index];
  11219. DECLARE_MULTI_VALUE_STATS_VARS()
  11220. ret = wc_falcon_init(&key);
  11221. if (ret != 0) {
  11222. printf("wc_falcon_init failed %d\n", ret);
  11223. return;
  11224. }
  11225. ret = wc_falcon_set_level(&key, level);
  11226. if (ret != 0) {
  11227. printf("wc_falcon_set_level failed %d\n", ret);
  11228. }
  11229. if (ret == 0) {
  11230. if (level == 1) {
  11231. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11232. sizeof_bench_falcon_level1_key,
  11233. NULL, 0, &key);
  11234. }
  11235. else {
  11236. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11237. sizeof_bench_falcon_level5_key,
  11238. NULL, 0, &key);
  11239. }
  11240. if (ret != 0) {
  11241. printf("wc_falcon_import_private_key failed %d\n", ret);
  11242. }
  11243. }
  11244. /* make dummy msg */
  11245. for (i = 0; i < (int)sizeof(msg); i++) {
  11246. msg[i] = (byte)i;
  11247. }
  11248. bench_stats_start(&count, &start);
  11249. do {
  11250. for (i = 0; i < agreeTimes; i++) {
  11251. if (ret == 0) {
  11252. if (level == 1) {
  11253. x = FALCON_LEVEL1_SIG_SIZE;
  11254. }
  11255. else {
  11256. x = FALCON_LEVEL5_SIG_SIZE;
  11257. }
  11258. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11259. if (ret != 0) {
  11260. printf("wc_falcon_sign_msg failed\n");
  11261. }
  11262. }
  11263. RECORD_MULTI_VALUE_STATS();
  11264. }
  11265. count += i;
  11266. } while (bench_stats_check(start)
  11267. #ifdef MULTI_VALUE_STATISTICS
  11268. || runs < minimum_runs
  11269. #endif
  11270. );
  11271. if (ret == 0) {
  11272. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11273. count, start, ret);
  11274. #ifdef MULTI_VALUE_STATISTICS
  11275. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11276. #endif
  11277. }
  11278. RESET_MULTI_VALUE_STATS_VARS();
  11279. bench_stats_start(&count, &start);
  11280. do {
  11281. for (i = 0; i < agreeTimes; i++) {
  11282. if (ret == 0) {
  11283. int verify = 0;
  11284. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11285. &key);
  11286. if (ret != 0 || verify != 1) {
  11287. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11288. ret, verify);
  11289. ret = -1;
  11290. }
  11291. }
  11292. RECORD_MULTI_VALUE_STATS();
  11293. }
  11294. count += i;
  11295. } while (bench_stats_check(start)
  11296. #ifdef MULTI_VALUE_STATISTICS
  11297. || runs < minimum_runs
  11298. #endif
  11299. );
  11300. if (ret == 0) {
  11301. bench_stats_asym_finish("FALCON", level, desc[5],
  11302. 0, count, start, ret);
  11303. #ifdef MULTI_VALUE_STATISTICS
  11304. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11305. #endif
  11306. }
  11307. wc_falcon_free(&key);
  11308. }
  11309. #endif /* HAVE_FALCON */
  11310. #ifdef HAVE_DILITHIUM
  11311. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11312. #ifndef WOLFSSL_NO_ML_DSA_44
  11313. static const unsigned char bench_dilithium_level2_sig[] = {
  11314. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11315. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11316. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11317. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11318. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11319. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11320. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11321. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11322. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11323. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11324. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11325. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11326. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11327. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11328. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11329. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11330. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11331. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11332. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11333. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11334. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11335. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11336. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11337. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11338. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11339. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11340. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11341. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11342. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11343. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11344. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11345. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11346. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11347. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11348. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11349. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11350. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11351. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11352. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11353. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11354. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11355. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11356. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11357. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11358. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11359. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11360. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11361. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11362. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11363. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11364. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11365. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11366. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11367. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11368. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11369. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11370. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11371. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11372. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11373. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11374. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11375. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11376. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11377. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11378. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11379. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11380. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11381. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11382. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11383. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11384. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11385. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11386. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11387. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11388. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11389. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11390. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11391. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11392. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11393. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11394. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11395. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11396. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11397. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11398. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11399. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11400. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11401. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11402. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11403. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11404. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11405. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11406. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11407. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11408. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11409. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11410. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11411. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11412. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11413. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11414. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11415. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11416. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11417. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11418. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11419. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11420. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11421. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11422. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11423. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11424. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11425. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11426. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11427. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11428. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11429. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11430. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11431. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11432. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11433. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11434. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11435. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11436. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11437. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11438. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11439. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11440. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11441. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11442. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11443. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11444. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11445. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11446. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11447. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11448. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11449. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11450. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11451. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11452. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11453. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11454. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11455. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11456. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11457. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11458. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11459. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11460. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11461. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11462. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11463. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11464. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11465. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11466. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11467. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11468. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11469. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11470. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11471. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11472. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11473. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11474. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11475. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11476. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11477. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11478. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11479. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11480. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11481. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11482. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11483. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11484. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11485. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11486. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11487. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11488. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11489. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11490. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11491. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11492. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11493. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11494. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11495. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11496. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11497. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11498. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11499. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11500. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11501. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11502. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11503. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11504. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11505. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11506. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11507. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11508. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11509. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11510. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11511. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11512. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11513. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11514. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11515. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11516. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11517. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11518. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11519. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11520. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11521. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11522. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11523. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11524. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11525. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11526. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11527. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11528. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11529. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11530. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11531. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11532. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11533. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11534. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11535. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11536. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11537. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11538. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11539. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11540. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11541. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11542. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11543. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11544. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11545. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11546. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11547. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11548. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11549. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11550. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11551. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11552. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11553. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11554. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11555. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11556. };
  11557. static const int sizeof_bench_dilithium_level2_sig =
  11558. sizeof(bench_dilithium_level2_sig);
  11559. #endif
  11560. #ifndef WOLFSSL_NO_ML_DSA_65
  11561. static const unsigned char bench_dilithium_level3_sig[] = {
  11562. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11563. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11564. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11565. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11566. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11567. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11568. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11569. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11570. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11571. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11572. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11573. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11574. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11575. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11576. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11577. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11578. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11579. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11580. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11581. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11582. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11583. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11584. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11585. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11586. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11587. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11588. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11589. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11590. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11591. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11592. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11593. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11594. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11595. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11596. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11597. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11598. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11599. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11600. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11601. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11602. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11603. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11604. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11605. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11606. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11607. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11608. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11609. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11610. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11611. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11612. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11613. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11614. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11615. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11616. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11617. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11618. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11619. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11620. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11621. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11622. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11623. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11624. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11625. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11626. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11627. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11628. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11629. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11630. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11631. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11632. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11633. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11634. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11635. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11636. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11637. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11638. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11639. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11640. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11641. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11642. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11643. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11644. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11645. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11646. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11647. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11648. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11649. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11650. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11651. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11652. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11653. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11654. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11655. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11656. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11657. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11658. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11659. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11660. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11661. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11662. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11663. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11664. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11665. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11666. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11667. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11668. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11669. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11670. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11671. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11672. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11673. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11674. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11675. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11676. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11677. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11678. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11679. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11680. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11681. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11682. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11683. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11684. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11685. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11686. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11687. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11688. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11689. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11690. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11691. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11692. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11693. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11694. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11695. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11696. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11697. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11698. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11699. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11700. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11701. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11702. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11703. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11704. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11705. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11706. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11707. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11708. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11709. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11710. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11711. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11712. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11713. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11714. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11715. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11716. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11717. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11718. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11719. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11720. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11721. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11722. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11723. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11724. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11725. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11726. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11727. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11728. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11729. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11730. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11731. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11732. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11733. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11734. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11735. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11736. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11737. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11738. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11739. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11740. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11741. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11742. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11743. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11744. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11745. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11746. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11747. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11748. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11749. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11750. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11751. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11752. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11753. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11754. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11755. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11756. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11757. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11758. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11759. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11760. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11761. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11762. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11763. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11764. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11765. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11766. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11767. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11768. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11769. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11770. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11771. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11772. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11773. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11774. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11775. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11776. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11777. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11778. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11779. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11780. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11781. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11782. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11783. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11784. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11785. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11786. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  11787. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  11788. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  11789. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  11790. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  11791. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  11792. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  11793. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  11794. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  11795. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  11796. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  11797. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  11798. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  11799. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  11800. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  11801. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  11802. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  11803. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  11804. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  11805. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  11806. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  11807. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  11808. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  11809. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  11810. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  11811. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  11812. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  11813. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  11814. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  11815. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  11816. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  11817. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  11818. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  11819. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  11820. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  11821. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  11822. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  11823. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  11824. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  11825. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  11826. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  11827. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  11828. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  11829. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  11830. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  11831. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  11832. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  11833. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  11834. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  11835. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  11836. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  11837. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  11838. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  11839. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  11840. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  11841. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  11842. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  11843. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  11844. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  11845. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  11846. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  11847. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  11848. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  11849. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  11850. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  11851. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  11852. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  11853. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  11854. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  11855. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  11856. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  11857. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  11858. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  11859. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  11860. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  11861. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  11862. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  11863. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  11864. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  11865. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  11866. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  11867. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  11868. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  11869. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  11870. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  11871. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  11872. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  11873. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  11874. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  11875. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  11876. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  11877. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  11878. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  11879. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  11880. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  11881. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  11882. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  11883. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  11884. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  11885. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  11886. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  11887. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  11888. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  11889. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  11890. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  11891. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11892. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  11893. };
  11894. static const int sizeof_bench_dilithium_level3_sig =
  11895. sizeof(bench_dilithium_level3_sig);
  11896. #endif
  11897. #ifndef WOLFSSL_NO_ML_DSA_87
  11898. static const unsigned char bench_dilithium_level5_sig[] = {
  11899. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  11900. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  11901. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  11902. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  11903. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  11904. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  11905. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  11906. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  11907. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  11908. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  11909. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  11910. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  11911. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  11912. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  11913. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  11914. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  11915. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  11916. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  11917. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  11918. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  11919. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  11920. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  11921. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  11922. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  11923. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  11924. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  11925. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  11926. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  11927. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  11928. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  11929. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  11930. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  11931. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  11932. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  11933. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  11934. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  11935. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  11936. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  11937. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  11938. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  11939. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  11940. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  11941. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  11942. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  11943. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  11944. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  11945. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  11946. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  11947. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  11948. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  11949. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  11950. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  11951. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  11952. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  11953. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  11954. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  11955. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  11956. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  11957. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  11958. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  11959. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  11960. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  11961. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  11962. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  11963. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  11964. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  11965. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  11966. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  11967. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  11968. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  11969. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  11970. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  11971. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  11972. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  11973. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  11974. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  11975. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  11976. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  11977. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  11978. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  11979. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  11980. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  11981. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  11982. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  11983. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  11984. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  11985. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  11986. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  11987. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  11988. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  11989. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  11990. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  11991. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  11992. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  11993. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  11994. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  11995. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  11996. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  11997. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  11998. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  11999. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12000. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12001. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12002. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12003. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12004. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12005. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12006. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12007. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12008. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12009. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12010. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12011. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12012. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12013. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12014. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12015. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12016. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12017. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12018. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12019. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12020. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12021. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12022. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12023. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12024. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12025. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12026. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12027. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12028. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12029. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12030. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12031. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12032. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12033. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12034. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12035. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12036. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12037. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12038. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12039. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12040. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12041. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12042. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12043. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12044. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12045. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12046. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12047. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12048. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12049. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12050. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12051. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12052. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12053. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12054. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12055. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12056. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12057. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12058. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12059. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12060. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12061. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12062. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12063. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12064. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12065. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12066. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12067. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12068. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12069. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12070. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12071. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12072. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12073. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12074. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12075. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12076. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12077. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12078. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12079. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12080. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12081. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12082. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12083. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12084. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12085. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12086. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12087. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12088. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12089. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12090. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12091. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12092. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12093. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12094. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12095. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12096. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12097. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12098. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12099. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12100. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12101. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12102. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12103. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12104. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12105. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12106. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12107. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12108. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12109. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12110. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12111. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12112. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12113. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12114. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12115. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12116. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12117. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12118. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12119. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12120. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12121. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12122. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12123. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12124. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12125. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12126. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12127. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12128. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12129. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12130. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12131. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12132. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12133. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12134. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12135. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12136. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12137. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12138. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12139. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12140. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12141. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12142. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12143. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12144. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12145. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12146. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12147. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12148. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12149. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12150. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12151. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12152. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12153. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12154. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12155. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12156. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12157. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12158. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12159. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12160. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12161. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12162. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12163. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12164. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12165. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12166. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12167. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12168. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12169. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12170. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12171. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12172. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12173. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12174. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12175. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12176. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12177. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12178. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12179. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12180. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12181. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12182. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12183. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12184. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12185. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12186. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12187. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12188. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12189. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12190. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12191. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12192. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12193. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12194. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12195. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12196. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12197. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12198. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12199. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12200. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12201. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12202. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12203. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12204. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12205. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12206. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12207. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12208. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12209. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12210. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12211. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12212. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12213. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12214. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12215. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12216. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12217. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12218. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12219. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12220. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12221. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12222. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12223. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12224. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12225. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12226. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12227. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12228. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12229. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12230. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12231. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12232. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12233. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12234. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12235. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12236. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12237. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12238. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12239. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12240. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12241. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12242. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12243. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12244. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12245. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12246. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12247. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12248. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12249. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12250. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12251. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12252. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12253. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12254. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12255. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12256. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12257. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12258. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12259. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12260. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12261. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12262. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12263. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12264. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12265. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12266. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12267. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12268. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12269. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12270. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12271. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12272. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12273. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12274. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12275. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12276. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12277. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12278. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12279. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12280. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12281. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12282. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12283. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12284. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12285. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12286. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12287. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12288. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12289. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12290. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12291. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12292. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12293. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12294. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12295. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12296. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12297. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12298. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12299. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12300. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12301. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12302. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12303. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12304. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12305. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12306. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12307. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12308. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12309. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12310. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12311. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12312. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12313. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12314. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12315. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12316. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12317. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12318. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12319. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12320. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12321. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12322. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12323. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12324. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12325. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12326. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12327. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12328. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12329. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12330. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12331. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12332. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12333. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12334. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12335. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12336. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12337. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12338. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12339. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12340. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12341. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12342. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12343. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12344. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12345. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12346. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12347. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12348. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12349. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12350. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12351. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12352. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12353. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12354. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12355. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12356. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12357. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12358. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12359. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12360. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12361. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12362. };
  12363. static const int sizeof_bench_dilithium_level5_sig =
  12364. sizeof(bench_dilithium_level5_sig);
  12365. #endif
  12366. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12367. void bench_dilithiumKeySign(byte level)
  12368. {
  12369. int ret = 0;
  12370. dilithium_key key;
  12371. double start;
  12372. int i, count;
  12373. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12374. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12375. byte msg[512];
  12376. word32 x = 0;
  12377. #endif
  12378. const char**desc = bench_desc_words[lng_index];
  12379. DECLARE_MULTI_VALUE_STATS_VARS()
  12380. byte params = 0;
  12381. if (level == 2) {
  12382. params = 44;
  12383. }
  12384. else if (level == 3) {
  12385. params = 65;
  12386. }
  12387. else if (level == 5) {
  12388. params = 87;
  12389. }
  12390. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12391. /* make dummy msg */
  12392. for (i = 0; i < (int)sizeof(msg); i++) {
  12393. msg[i] = (byte)i;
  12394. }
  12395. #endif
  12396. ret = wc_dilithium_init(&key);
  12397. if (ret != 0) {
  12398. printf("wc_dilithium_init failed %d\n", ret);
  12399. return;
  12400. }
  12401. ret = wc_dilithium_set_level(&key, level);
  12402. if (ret != 0) {
  12403. printf("wc_dilithium_set_level() failed %d\n", ret);
  12404. }
  12405. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12406. bench_stats_start(&count, &start);
  12407. do {
  12408. for (i = 0; i < agreeTimes; i++) {
  12409. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12410. if (ret != 0) {
  12411. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12412. return;
  12413. }
  12414. }
  12415. count += i;
  12416. } while (bench_stats_check(start)
  12417. #ifdef MULTI_VALUE_STATISTICS
  12418. || runs < minimum_runs
  12419. #endif
  12420. );
  12421. if (ret == 0) {
  12422. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12423. start, ret);
  12424. #ifdef MULTI_VALUE_STATISTICS
  12425. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12426. #endif
  12427. }
  12428. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12429. #ifndef WOLFSSL_NO_ML_DSA_44
  12430. if (level == 2) {
  12431. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12432. sizeof_bench_dilithium_level2_key, &key);
  12433. }
  12434. #endif
  12435. #ifndef WOLFSSL_NO_ML_DSA_65
  12436. if (level == 3) {
  12437. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12438. sizeof_bench_dilithium_level3_key, &key);
  12439. }
  12440. #endif
  12441. #ifndef WOLFSSL_NO_ML_DSA_87
  12442. if (level == 5) {
  12443. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12444. sizeof_bench_dilithium_level5_key, &key);
  12445. }
  12446. #endif
  12447. if (ret != 0) {
  12448. printf("Failed to load private key\n");
  12449. return;
  12450. }
  12451. #endif
  12452. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12453. if (level == 2) {
  12454. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12455. }
  12456. else if (level == 3) {
  12457. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12458. }
  12459. else {
  12460. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12461. }
  12462. RESET_MULTI_VALUE_STATS_VARS();
  12463. bench_stats_start(&count, &start);
  12464. do {
  12465. for (i = 0; i < agreeTimes; i++) {
  12466. if (ret == 0) {
  12467. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12468. GLOBAL_RNG);
  12469. if (ret != 0) {
  12470. printf("wc_dilithium_sign_msg failed\n");
  12471. }
  12472. }
  12473. RECORD_MULTI_VALUE_STATS();
  12474. }
  12475. count += i;
  12476. } while (bench_stats_check(start)
  12477. #ifdef MULTI_VALUE_STATISTICS
  12478. || runs < minimum_runs
  12479. #endif
  12480. );
  12481. if (ret == 0) {
  12482. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12483. ret);
  12484. #ifdef MULTI_VALUE_STATISTICS
  12485. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12486. #endif
  12487. }
  12488. #endif
  12489. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12490. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12491. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12492. #ifndef WOLFSSL_NO_ML_DSA_44
  12493. if (level == 2) {
  12494. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12495. x = sizeof_bench_dilithium_level2_sig;
  12496. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12497. #endif
  12498. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12499. sizeof_bench_dilithium_level2_pubkey, &key);
  12500. }
  12501. #endif
  12502. #ifndef WOLFSSL_NO_ML_DSA_65
  12503. if (level == 3) {
  12504. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12505. x = sizeof_bench_dilithium_level3_sig;
  12506. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12507. #endif
  12508. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12509. sizeof_bench_dilithium_level3_pubkey, &key);
  12510. }
  12511. #endif
  12512. #ifndef WOLFSSL_NO_ML_DSA_87
  12513. if (level == 5) {
  12514. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12515. x = sizeof_bench_dilithium_level5_sig;
  12516. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12517. #endif
  12518. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12519. sizeof_bench_dilithium_level5_pubkey, &key);
  12520. }
  12521. #endif
  12522. if (ret != 0) {
  12523. printf("Failed to load public key\n");
  12524. return;
  12525. }
  12526. #endif
  12527. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12528. RESET_MULTI_VALUE_STATS_VARS();
  12529. bench_stats_start(&count, &start);
  12530. do {
  12531. for (i = 0; i < agreeTimes; i++) {
  12532. if (ret == 0) {
  12533. int verify = 0;
  12534. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12535. &verify, &key);
  12536. if (ret != 0 || verify != 1) {
  12537. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12538. ret, verify);
  12539. ret = -1;
  12540. }
  12541. }
  12542. RECORD_MULTI_VALUE_STATS();
  12543. }
  12544. count += i;
  12545. } while (bench_stats_check(start)
  12546. #ifdef MULTI_VALUE_STATISTICS
  12547. || runs < minimum_runs
  12548. #endif
  12549. );
  12550. if (ret == 0) {
  12551. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12552. ret);
  12553. #ifdef MULTI_VALUE_STATISTICS
  12554. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12555. #endif
  12556. }
  12557. #endif
  12558. wc_dilithium_free(&key);
  12559. }
  12560. #endif /* HAVE_DILITHIUM */
  12561. #ifdef HAVE_SPHINCS
  12562. void bench_sphincsKeySign(byte level, byte optim)
  12563. {
  12564. int ret = 0;
  12565. sphincs_key key;
  12566. double start;
  12567. int i, count;
  12568. byte sig[SPHINCS_MAX_SIG_SIZE];
  12569. byte msg[512];
  12570. word32 x = 0;
  12571. const char**desc = bench_desc_words[lng_index];
  12572. DECLARE_MULTI_VALUE_STATS_VARS()
  12573. ret = wc_sphincs_init(&key);
  12574. if (ret != 0) {
  12575. printf("wc_sphincs_init failed %d\n", ret);
  12576. return;
  12577. }
  12578. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12579. if (ret != 0) {
  12580. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12581. }
  12582. if (ret == 0) {
  12583. ret = -1;
  12584. if ((level == 1) && (optim == FAST_VARIANT)) {
  12585. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12586. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12587. }
  12588. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12589. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12590. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12591. }
  12592. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12593. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12594. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12595. }
  12596. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12597. ret = wc_sphincs_import_private_key(
  12598. bench_sphincs_small_level1_key,
  12599. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12600. }
  12601. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12602. ret = wc_sphincs_import_private_key(
  12603. bench_sphincs_small_level3_key,
  12604. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12605. }
  12606. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12607. ret = wc_sphincs_import_private_key(
  12608. bench_sphincs_small_level5_key,
  12609. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12610. }
  12611. if (ret != 0) {
  12612. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12613. }
  12614. }
  12615. /* make dummy msg */
  12616. for (i = 0; i < (int)sizeof(msg); i++) {
  12617. msg[i] = (byte)i;
  12618. }
  12619. bench_stats_start(&count, &start);
  12620. do {
  12621. for (i = 0; i < agreeTimes; i++) {
  12622. if (ret == 0) {
  12623. if ((level == 1) && (optim == FAST_VARIANT)) {
  12624. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12625. }
  12626. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12627. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12628. }
  12629. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12630. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12631. }
  12632. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12633. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12634. }
  12635. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12636. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12637. }
  12638. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12639. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12640. }
  12641. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12642. if (ret != 0) {
  12643. printf("wc_sphincs_sign_msg failed\n");
  12644. }
  12645. }
  12646. RECORD_MULTI_VALUE_STATS();
  12647. }
  12648. count += i;
  12649. } while (bench_stats_check(start)
  12650. #ifdef MULTI_VALUE_STATISTICS
  12651. || runs < minimum_runs
  12652. #endif
  12653. );
  12654. if (ret == 0) {
  12655. if (optim == FAST_VARIANT) {
  12656. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12657. start, ret);
  12658. }
  12659. else {
  12660. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12661. start, ret);
  12662. }
  12663. #ifdef MULTI_VALUE_STATISTICS
  12664. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12665. #endif
  12666. }
  12667. RESET_MULTI_VALUE_STATS_VARS();
  12668. bench_stats_start(&count, &start);
  12669. do {
  12670. for (i = 0; i < agreeTimes; i++) {
  12671. if (ret == 0) {
  12672. int verify = 0;
  12673. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12674. &key);
  12675. if (ret != 0 || verify != 1) {
  12676. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12677. ret, verify);
  12678. ret = -1;
  12679. }
  12680. }
  12681. RECORD_MULTI_VALUE_STATS();
  12682. }
  12683. count += i;
  12684. } while (bench_stats_check(start)
  12685. #ifdef MULTI_VALUE_STATISTICS
  12686. || runs < minimum_runs
  12687. #endif
  12688. );
  12689. if (ret == 0) {
  12690. if (optim == FAST_VARIANT) {
  12691. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12692. start, ret);
  12693. }
  12694. else {
  12695. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12696. start, ret);
  12697. }
  12698. #ifdef MULTI_VALUE_STATISTICS
  12699. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12700. #endif
  12701. }
  12702. wc_sphincs_free(&key);
  12703. }
  12704. #endif /* HAVE_SPHINCS */
  12705. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12706. #define WIN32_LEAN_AND_MEAN
  12707. #include <windows.h>
  12708. double current_time(int reset)
  12709. {
  12710. static int init = 0;
  12711. static LARGE_INTEGER freq;
  12712. LARGE_INTEGER count;
  12713. (void)reset;
  12714. if (!init) {
  12715. QueryPerformanceFrequency(&freq);
  12716. init = 1;
  12717. }
  12718. QueryPerformanceCounter(&count);
  12719. #ifdef BENCH_MICROSECOND
  12720. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12721. #else
  12722. return (double)count.QuadPart / freq.QuadPart;
  12723. #endif
  12724. }
  12725. #elif defined MICROCHIP_PIC32
  12726. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12727. #define CLOCK 80000000.0
  12728. #else
  12729. #define CLOCK 40000000.0
  12730. #endif
  12731. extern void WriteCoreTimer(word32 t);
  12732. extern word32 ReadCoreTimer(void);
  12733. double current_time(int reset)
  12734. {
  12735. unsigned int ns;
  12736. if (reset) {
  12737. WriteCoreTimer(0);
  12738. }
  12739. /* get timer in ns */
  12740. ns = ReadCoreTimer();
  12741. /* return seconds as a double */
  12742. return ( ns / CLOCK * 2.0);
  12743. }
  12744. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12745. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12746. /* declared above at line 239 */
  12747. /* extern double current_time(int reset); */
  12748. #elif defined(FREERTOS)
  12749. #ifdef PLATFORMIO
  12750. #include <freertos/FreeRTOS.h>
  12751. #include <freertos/task.h>
  12752. #else
  12753. #include "task.h"
  12754. #endif
  12755. #if defined(WOLFSSL_ESPIDF)
  12756. /* prototype definition */
  12757. int construct_argv();
  12758. extern char* __argv[22];
  12759. /* current_time(reset)
  12760. *
  12761. * Benchmark passage of time, in fractional seconds.
  12762. * [reset] is non zero to adjust timer or counter to zero
  12763. *
  12764. * Use care when repeatedly calling calling. See implementation. */
  12765. double current_time(int reset)
  12766. {
  12767. double ret;
  12768. #if ESP_IDF_VERSION_MAJOR >= 4
  12769. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12770. #else
  12771. portTickType tickCount;
  12772. #endif
  12773. #if defined(__XTENSA__)
  12774. (void)reset;
  12775. if (reset) {
  12776. /* TODO: Determine a mechanism for reset that does not interfere
  12777. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12778. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12779. ESP_LOGW(TAG, "Current_time() reset!");
  12780. portTICK_TYPE_ENTER_CRITICAL();
  12781. {
  12782. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12783. _esp_cpu_count_last = xthal_get_ccount();
  12784. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12785. }
  12786. portTICK_TYPE_EXIT_CRITICAL();
  12787. */
  12788. }
  12789. #else
  12790. /* Only reset the CPU counter for RISC-V */
  12791. if (reset) {
  12792. ESP_LOGV(TAG, "current_time() reset!");
  12793. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  12794. * unexpected rollovers in return values for Xtensa but not RISC-V?
  12795. * See also esp_get_cycle_count_ex() */
  12796. #ifdef __XTENSA__
  12797. _esp_cpu_count_last = xthal_get_ccount();
  12798. #else
  12799. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12800. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12801. #endif
  12802. }
  12803. #endif
  12804. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  12805. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  12806. The count of ticks since vTaskStartScheduler was called,
  12807. typiclly in app_startup.c */
  12808. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12809. ESP_LOGV(TAG, "tickCount = %d", tickCount);
  12810. if (tickCount == last_tickCount) {
  12811. ESP_LOGW(TAG, "last_tickCount unchanged? %d", tickCount);
  12812. }
  12813. if (tickCount < last_tickCount) {
  12814. ESP_LOGW(TAG, "last_tickCount overflow?");
  12815. }
  12816. #endif
  12817. if (reset) {
  12818. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12819. ESP_LOGW(TAG, "Assign last_tickCount = %d", tickCount);
  12820. #endif
  12821. last_tickCount = tickCount;
  12822. }
  12823. else {
  12824. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12825. ESP_LOGV(TAG, "No Reset last_tickCount = %d", tickCount);
  12826. #endif
  12827. }
  12828. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  12829. ret = (double)tickCount / configTICK_RATE_HZ;
  12830. #else
  12831. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  12832. "assuming 1000 Hz.");
  12833. ret = (double)(tickCount / 1000.0);
  12834. #endif /* configTICK_RATE_HZ */
  12835. return ret;
  12836. } /* current_time */
  12837. #else
  12838. /* current_time(reset)
  12839. *
  12840. * Benchmark passage of time, in fractional seconds.
  12841. * [reset] is non zero to adjust timer or counter to zero
  12842. *
  12843. * Use care when repeatedly calling calling. See implementation. */
  12844. double current_time(int reset)
  12845. {
  12846. portTickType tickCount = xTaskGetTickCount();
  12847. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  12848. #ifdef configTICK_RATE_HZ
  12849. return (double)tickCount / configTICK_RATE_HZ;
  12850. #else
  12851. return (double)tickCount / 1000;
  12852. #endif
  12853. }
  12854. #endif
  12855. #elif defined (WOLFSSL_TIRTOS)
  12856. extern double current_time(int reset);
  12857. #elif defined(FREESCALE_MQX)
  12858. double current_time(int reset)
  12859. {
  12860. TIME_STRUCT tv;
  12861. _time_get(&tv);
  12862. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  12863. }
  12864. #elif defined(FREESCALE_KSDK_BM)
  12865. double current_time(int reset)
  12866. {
  12867. return (double)OSA_TimeGetMsec() / 1000;
  12868. }
  12869. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  12870. double current_time(int reset)
  12871. {
  12872. (void)reset;
  12873. return (double)osKernelGetTickCount() / 1000.0;
  12874. }
  12875. #elif defined(WOLFSSL_EMBOS)
  12876. #include "RTOS.h"
  12877. double current_time(int reset)
  12878. {
  12879. double time_now;
  12880. double current_s = OS_GetTime() / 1000.0;
  12881. double current_us = OS_GetTime_us() / MILLION_VALUE;
  12882. time_now = (double)( current_s + current_us);
  12883. (void) reset;
  12884. return time_now;
  12885. }
  12886. #elif defined(WOLFSSL_SGX)
  12887. double current_time(int reset);
  12888. #elif defined(WOLFSSL_DEOS)
  12889. double current_time(int reset)
  12890. {
  12891. const uint32_t systemTickTimeInHz
  12892. = 1000000 / systemTickInMicroseconds();
  12893. const volatile uint32_t *systemTickPtr = systemTickPointer();
  12894. (void)reset;
  12895. return (double) *systemTickPtr/systemTickTimeInHz;
  12896. }
  12897. #elif defined(MICRIUM)
  12898. double current_time(int reset)
  12899. {
  12900. #if (OS_VERSION < 50000)
  12901. CPU_ERR err;
  12902. (void)reset;
  12903. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  12904. #else
  12905. RTOS_ERR err;
  12906. double ret = 0;
  12907. OS_TICK tick = OSTimeGet(&err);
  12908. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  12909. (void)reset;
  12910. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  12911. ret = ((double)tick)/rate;
  12912. }
  12913. return ret;
  12914. #endif
  12915. }
  12916. #elif defined(WOLFSSL_ZEPHYR)
  12917. #include <time.h>
  12918. double current_time(int reset)
  12919. {
  12920. int64_t t;
  12921. (void)reset;
  12922. #if defined(CONFIG_ARCH_POSIX)
  12923. k_cpu_idle();
  12924. #endif
  12925. t = k_uptime_get(); /* returns current uptime in milliseconds */
  12926. return (double)(t / 1000);
  12927. }
  12928. #elif defined(WOLFSSL_NETBURNER)
  12929. #include <predef.h>
  12930. #include <utils.h>
  12931. #include <constants.h>
  12932. double current_time(int reset)
  12933. {
  12934. DWORD ticks = TimeTick; /* ticks since system start */
  12935. (void)reset;
  12936. return (double) ticks/TICKS_PER_SECOND;
  12937. }
  12938. #elif defined(THREADX)
  12939. #include "tx_api.h"
  12940. double current_time(int reset)
  12941. {
  12942. (void)reset;
  12943. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  12944. }
  12945. #elif defined(WOLFSSL_XILINX)
  12946. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  12947. #define COUNTS_PER_SECOND \
  12948. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  12949. #else
  12950. #define COUNTS_PER_SECOND \
  12951. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  12952. #endif
  12953. double current_time(int reset)
  12954. {
  12955. double timer;
  12956. uint64_t cntPct = 0;
  12957. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  12958. /* Convert to milliseconds */
  12959. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  12960. /* Convert to seconds.millisecond */
  12961. timer /= 1000;
  12962. return timer;
  12963. }
  12964. #elif defined(LINUX_RUSAGE_UTIME)
  12965. #include <sys/time.h>
  12966. #include <sys/resource.h>
  12967. static struct rusage base_rusage;
  12968. static struct rusage cur_rusage;
  12969. double current_time(int reset)
  12970. {
  12971. struct rusage rusage;
  12972. (void)reset;
  12973. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  12974. if (reset)
  12975. base_rusage = rusage;
  12976. else
  12977. cur_rusage = rusage;
  12978. /* only consider user time, as system time is host-related overhead
  12979. * outside wolfcrypt.
  12980. */
  12981. return (double)rusage.ru_utime.tv_sec +
  12982. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  12983. }
  12984. static void check_for_excessive_stime(const char *desc,
  12985. const char *desc_extra)
  12986. {
  12987. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  12988. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  12989. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  12990. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  12991. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  12992. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  12993. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  12994. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  12995. double stime_utime_ratio =
  12996. (cur_stime - start_stime) / (cur_utime - start_utime);
  12997. if (stime_utime_ratio > .1)
  12998. printf("%swarning, "
  12999. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13000. err_prefix, desc, desc_extra,
  13001. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13002. }
  13003. #elif defined(WOLFSSL_LINUXKM)
  13004. double current_time(int reset)
  13005. {
  13006. (void)reset;
  13007. u64 ns = ktime_get_ns();
  13008. return (double)ns / 1000000000.0;
  13009. }
  13010. #else
  13011. #include <sys/time.h>
  13012. double current_time(int reset)
  13013. {
  13014. struct timespec tv;
  13015. (void)reset;
  13016. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13017. #ifdef BENCH_MICROSECOND
  13018. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13019. #else
  13020. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13021. #endif
  13022. }
  13023. #endif /* _WIN32 */
  13024. #if defined(HAVE_GET_CYCLES)
  13025. #if defined(WOLFSSL_ESPIDF)
  13026. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13027. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13028. {
  13029. /* Reminder for long duration between calls with
  13030. * multiple overflows will not be detected. */
  13031. return esp_get_cycle_count_ex();
  13032. }
  13033. /* implement other architectures here */
  13034. #else
  13035. static WC_INLINE word64 get_intel_cycles(void)
  13036. {
  13037. unsigned int lo_c, hi_c;
  13038. __asm__ __volatile__ (
  13039. "cpuid\n\t"
  13040. "rdtsc"
  13041. : "=a"(lo_c), "=d"(hi_c) /* out */
  13042. : "a"(0) /* in */
  13043. : "%ebx", "%ecx"); /* clobber */
  13044. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13045. }
  13046. #endif
  13047. #endif /* HAVE_GET_CYCLES */
  13048. void benchmark_configure(word32 block_size)
  13049. {
  13050. /* must be greater than 0 */
  13051. if (block_size > 0) {
  13052. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13053. bench_size = block_size;
  13054. }
  13055. }
  13056. #ifndef NO_MAIN_DRIVER
  13057. #ifndef MAIN_NO_ARGS
  13058. #ifndef WOLFSSL_BENCHMARK_ALL
  13059. /* Display the algorithm string and keep to 80 characters per line.
  13060. *
  13061. * str Algorithm string to print.
  13062. * line Length of line used so far.
  13063. */
  13064. #ifndef BENCH_MAX_LINE
  13065. #define BENCH_MAX_LINE 80
  13066. #endif
  13067. static void print_alg(const char* str, int* line)
  13068. {
  13069. const char* const ident = " ";
  13070. if (*line == 0) {
  13071. printf("%s", ident);
  13072. *line = (int)XSTRLEN(ident);
  13073. }
  13074. printf(" %s", str);
  13075. *line += (int)XSTRLEN(str) + 1;
  13076. if (*line > BENCH_MAX_LINE) {
  13077. printf("\n");
  13078. *line = 0;
  13079. }
  13080. }
  13081. #endif /* WOLFSSL_BENCHMARK_ALL */
  13082. /* Display the usage options of the benchmark program. */
  13083. static void Usage(void)
  13084. {
  13085. int e = 0;
  13086. #ifndef WOLFSSL_BENCHMARK_ALL
  13087. int i;
  13088. int line;
  13089. #endif
  13090. printf("benchmark\n");
  13091. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13092. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13093. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13094. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13095. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13096. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13097. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13098. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13099. #else
  13100. e += 3;
  13101. #endif
  13102. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13103. #ifndef NO_RSA
  13104. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13105. #ifdef WOLFSSL_KEY_GEN
  13106. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13107. #endif
  13108. e++;
  13109. #else
  13110. e += 2;
  13111. #endif
  13112. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13113. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13114. #endif
  13115. e++;
  13116. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13117. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13118. #endif
  13119. e++;
  13120. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13121. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13122. #endif
  13123. e++;
  13124. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13125. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13126. #endif
  13127. e++;
  13128. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13129. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13130. #endif
  13131. e++;
  13132. #if defined(HAVE_ECC)
  13133. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13134. #endif
  13135. e++;
  13136. #ifndef WOLFSSL_BENCHMARK_ALL
  13137. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13138. line = 0;
  13139. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13140. print_alg(bench_cipher_opt[i].str, &line);
  13141. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13142. print_alg(bench_digest_opt[i].str, &line);
  13143. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13144. print_alg(bench_mac_opt[i].str, &line);
  13145. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13146. print_alg(bench_kdf_opt[i].str, &line);
  13147. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13148. print_alg(bench_asym_opt[i].str, &line);
  13149. for (i=0; bench_other_opt[i].str != NULL; i++)
  13150. print_alg(bench_other_opt[i].str, &line);
  13151. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13152. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13153. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13154. print_alg(bench_pq_asym_opt[i].str, &line);
  13155. #if defined(HAVE_SPHINCS)
  13156. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13157. print_alg(bench_pq_asym_opt2[i].str, &line);
  13158. #endif /* HAVE_SPHINCS */
  13159. #endif
  13160. #if defined(BENCH_PQ_STATEFUL_HBS)
  13161. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13162. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13163. #endif /* BENCH_PQ_STATEFUL_HBS */
  13164. printf("\n");
  13165. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13166. e++;
  13167. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13168. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13169. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13170. #ifdef WC_ENABLE_BENCH_THREADING
  13171. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13172. #endif
  13173. e++;
  13174. #ifdef WC_BENCH_TRACK_STATS
  13175. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13176. #endif
  13177. e++;
  13178. #ifndef NO_FILESYSTEM
  13179. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13180. #endif
  13181. e++;
  13182. #ifndef NO_FILESYSTEM
  13183. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13184. #endif
  13185. #ifdef MULTI_VALUE_STATISTICS
  13186. e++;
  13187. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13188. #endif
  13189. }
  13190. /* Match the command line argument with the string.
  13191. *
  13192. * arg Command line argument.
  13193. * str String to check for.
  13194. * return 1 if the command line argument matches the string, 0 otherwise.
  13195. */
  13196. static int string_matches(const char* arg, const char* str)
  13197. {
  13198. return XSTRCMP(arg, str) == 0;
  13199. }
  13200. #endif /* MAIN_NO_ARGS */
  13201. /*
  13202. ** ----------------------------------------------------------------------------
  13203. ** determine how the benchmarks are called, the function name varies:
  13204. ** ----------------------------------------------------------------------------
  13205. */
  13206. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13207. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13208. /* for some environments, we'll call a function wolf_benchmark_task: */
  13209. int wolf_benchmark_task(void)
  13210. #elif defined(MAIN_NO_ARGS)
  13211. /* otherwise we'll use main() with no arguments as desired: */
  13212. int main()
  13213. #else
  13214. /* else we'll be calling main with default arg parameters */
  13215. int main(int argc, char** argv)
  13216. #endif
  13217. {
  13218. /* Code for main() or wolf_benchmark_task() */
  13219. #ifdef WOLFSSL_ESPIDF
  13220. int argc = construct_argv();
  13221. char** argv = (char**)__argv;
  13222. #elif defined(MAIN_NO_ARGS)
  13223. int argc = 0;
  13224. char** argv = NULL;
  13225. #endif
  13226. return wolfcrypt_benchmark_main(argc, argv);
  13227. }
  13228. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13229. int wolfcrypt_benchmark_main(int argc, char** argv)
  13230. {
  13231. int ret = 0;
  13232. #ifndef MAIN_NO_ARGS
  13233. int optMatched;
  13234. #ifndef WOLFSSL_BENCHMARK_ALL
  13235. int i;
  13236. #endif
  13237. #endif
  13238. benchmark_static_init(1);
  13239. printf("%s------------------------------------------------------------------------------\n",
  13240. info_prefix);
  13241. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13242. printf("%s------------------------------------------------------------------------------\n",
  13243. info_prefix);
  13244. #ifndef MAIN_NO_ARGS
  13245. while (argc > 1) {
  13246. if (string_matches(argv[1], "-?")) {
  13247. if (--argc > 1) {
  13248. lng_index = XATOI((++argv)[1]);
  13249. if (lng_index<0 || lng_index>1) {
  13250. lng_index = 0;
  13251. }
  13252. }
  13253. Usage();
  13254. return 0;
  13255. }
  13256. else if (string_matches(argv[1], "-lng")) {
  13257. argc--;
  13258. argv++;
  13259. if (argc > 1) {
  13260. lng_index = XATOI(argv[1]);
  13261. if (lng_index<0 || lng_index>1) {
  13262. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13263. lng_index);
  13264. lng_index = 0;
  13265. }
  13266. }
  13267. }
  13268. else if (string_matches(argv[1], "-base10"))
  13269. base2 = 0;
  13270. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13271. else if (string_matches(argv[1], "-no_aad"))
  13272. aes_aad_options = AAD_SIZE_ZERO;
  13273. else if (string_matches(argv[1], "-all_aad"))
  13274. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13275. else if (string_matches(argv[1], "-aad_size")) {
  13276. argc--;
  13277. argv++;
  13278. if (argc > 1) {
  13279. aes_aad_size = (word32)XATOI(argv[1]);
  13280. aes_aad_options |= AAD_SIZE_CUSTOM;
  13281. }
  13282. }
  13283. #endif
  13284. else if (string_matches(argv[1], "-dgst_full"))
  13285. digest_stream = 0;
  13286. #ifdef HAVE_CHACHA
  13287. else if (string_matches(argv[1], "-enc_only"))
  13288. encrypt_only = 1;
  13289. #endif
  13290. #ifndef NO_RSA
  13291. else if (string_matches(argv[1], "-rsa_sign"))
  13292. rsa_sign_verify = 1;
  13293. #endif
  13294. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13295. else if (string_matches(argv[1], "-ffdhe2048"))
  13296. use_ffdhe = 2048;
  13297. #endif
  13298. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13299. else if (string_matches(argv[1], "-ffdhe3072"))
  13300. use_ffdhe = 3072;
  13301. #endif
  13302. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13303. else if (string_matches(argv[1], "-ffdhe4096"))
  13304. use_ffdhe = 4096;
  13305. #endif
  13306. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13307. else if (string_matches(argv[1], "-p256"))
  13308. bench_asym_algs |= BENCH_ECC_P256;
  13309. #endif
  13310. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13311. else if (string_matches(argv[1], "-p384"))
  13312. bench_asym_algs |= BENCH_ECC_P384;
  13313. #endif
  13314. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13315. else if (string_matches(argv[1], "-p521"))
  13316. bench_asym_algs |= BENCH_ECC_P521;
  13317. #endif
  13318. #ifdef BENCH_ASYM
  13319. else if (string_matches(argv[1], "-csv")) {
  13320. csv_format = 1;
  13321. }
  13322. #endif
  13323. #ifdef WC_ENABLE_BENCH_THREADING
  13324. else if (string_matches(argv[1], "-threads")) {
  13325. argc--;
  13326. argv++;
  13327. if (argc > 1) {
  13328. g_threadCount = XATOI(argv[1]);
  13329. if (g_threadCount < 1 || lng_index > 128){
  13330. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13331. g_threadCount);
  13332. g_threadCount = 0;
  13333. }
  13334. }
  13335. }
  13336. #endif
  13337. #ifdef WC_BENCH_TRACK_STATS
  13338. else if (string_matches(argv[1], "-print")) {
  13339. gPrintStats = 1;
  13340. }
  13341. #endif
  13342. else if (string_matches(argv[1], "-blocks")) {
  13343. argc--;
  13344. argv++;
  13345. if (argc > 1)
  13346. numBlocks = XATOI(argv[1]);
  13347. }
  13348. #ifndef NO_FILESYSTEM
  13349. else if (string_matches(argv[1], "-hash_input")) {
  13350. argc--;
  13351. argv++;
  13352. if (argc > 1)
  13353. hash_input = argv[1];
  13354. }
  13355. else if (string_matches(argv[1], "-cipher_input")) {
  13356. argc--;
  13357. argv++;
  13358. if (argc > 1)
  13359. cipher_input = argv[1];
  13360. }
  13361. #endif
  13362. #ifdef MULTI_VALUE_STATISTICS
  13363. else if (string_matches(argv[1], "-min_runs")) {
  13364. argc--;
  13365. argv++;
  13366. if (argc > 1) {
  13367. minimum_runs = XATOI(argv[1]);
  13368. }
  13369. }
  13370. #endif
  13371. else if (argv[1][0] == '-') {
  13372. optMatched = 0;
  13373. #ifndef WOLFSSL_BENCHMARK_ALL
  13374. /* Check known algorithm choosing command line options. */
  13375. /* Known cipher algorithms */
  13376. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13377. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13378. bench_cipher_algs |= bench_cipher_opt[i].val;
  13379. bench_all = 0;
  13380. optMatched = 1;
  13381. }
  13382. }
  13383. /* Known digest algorithms */
  13384. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13385. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13386. bench_digest_algs |= bench_digest_opt[i].val;
  13387. bench_all = 0;
  13388. optMatched = 1;
  13389. }
  13390. }
  13391. /* Known MAC algorithms */
  13392. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13393. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13394. bench_mac_algs |= bench_mac_opt[i].val;
  13395. bench_all = 0;
  13396. optMatched = 1;
  13397. }
  13398. }
  13399. /* Known KDF algorithms */
  13400. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13401. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13402. bench_kdf_algs |= bench_kdf_opt[i].val;
  13403. bench_all = 0;
  13404. optMatched = 1;
  13405. }
  13406. }
  13407. /* Known asymmetric algorithms */
  13408. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13409. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13410. bench_asym_algs |= bench_asym_opt[i].val;
  13411. bench_all = 0;
  13412. optMatched = 1;
  13413. }
  13414. }
  13415. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13416. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13417. /* Known asymmetric post-quantum algorithms */
  13418. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13419. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13420. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13421. bench_all = 0;
  13422. optMatched = 1;
  13423. }
  13424. }
  13425. #ifdef HAVE_SPHINCS
  13426. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13427. * -pq, so we need to do a special case for -pq since optMatched
  13428. * was set to 1 just above. */
  13429. if ((bench_pq_asym_opt[0].str != NULL) &&
  13430. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13431. {
  13432. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13433. bench_all = 0;
  13434. optMatched = 1;
  13435. }
  13436. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13437. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13438. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13439. bench_all = 0;
  13440. optMatched = 1;
  13441. }
  13442. }
  13443. #endif
  13444. #endif
  13445. /* Other known cryptographic algorithms */
  13446. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13447. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13448. bench_other_algs |= bench_other_opt[i].val;
  13449. bench_all = 0;
  13450. optMatched = 1;
  13451. }
  13452. }
  13453. #if defined(BENCH_PQ_STATEFUL_HBS)
  13454. /* post-quantum stateful hash-based signatures */
  13455. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13456. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13457. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13458. bench_all = 0;
  13459. optMatched = 1;
  13460. }
  13461. }
  13462. #endif /* BENCH_PQ_STATEFUL_HBS */
  13463. #endif
  13464. if (!optMatched) {
  13465. printf("Option not recognized: %s\n", argv[1]);
  13466. Usage();
  13467. return 1;
  13468. }
  13469. }
  13470. else {
  13471. /* parse for block size */
  13472. benchmark_configure((word32)XATOI(argv[1]));
  13473. }
  13474. argc--;
  13475. argv++;
  13476. }
  13477. #endif /* MAIN_NO_ARGS */
  13478. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13479. /* when defined, we'll always output CSV regardless of params.
  13480. ** this is typically convenient in embedded environments.
  13481. */
  13482. csv_format = 1;
  13483. #endif
  13484. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13485. if (g_threadCount > 1) {
  13486. ret = benchmark_test_threaded(NULL);
  13487. }
  13488. else
  13489. #endif
  13490. {
  13491. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13492. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13493. defined(CONFIG_IDF_TARGET_ESP32C6)
  13494. {
  13495. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13496. if (esp_gptimer == NULL) {
  13497. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13498. &esp_gptimer) );
  13499. }
  13500. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13501. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13502. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13503. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13504. }
  13505. #endif
  13506. #ifdef HAVE_STACK_SIZE
  13507. ret = StackSizeCheck(NULL, benchmark_test);
  13508. #else
  13509. ret = benchmark_test(NULL);
  13510. #endif
  13511. }
  13512. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13513. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13514. defined(CONFIG_IDF_TARGET_ESP32C6)
  13515. {
  13516. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13517. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13518. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13519. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13520. }
  13521. #endif
  13522. return ret;
  13523. }
  13524. #endif /* !NO_MAIN_DRIVER */
  13525. #else
  13526. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13527. int main(void) { return 0; }
  13528. #endif
  13529. #endif /* !NO_CRYPT_BENCHMARK */