benchmark.c 515 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197
  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. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  212. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  213. #endif
  214. #endif
  215. #ifdef WOLFSSL_ASYNC_CRYPT
  216. #include <wolfssl/wolfcrypt/async.h>
  217. #endif
  218. #ifdef USE_FLAT_BENCHMARK_H
  219. #include "benchmark.h"
  220. #else
  221. #include "wolfcrypt/benchmark/benchmark.h"
  222. #endif
  223. /* define the max length for each string of metric reported */
  224. #ifndef WC_BENCH_MAX_LINE_LEN
  225. #define WC_BENCH_MAX_LINE_LEN 150
  226. #endif
  227. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  228. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  229. #define MILLION_VALUE 1000000.0
  230. #ifdef BENCH_MICROSECOND
  231. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  232. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  233. #else
  234. #define WOLFSSL_FIXED_TIME_UNIT "s"
  235. #endif
  236. #ifdef MULTI_VALUE_STATISTICS
  237. #define STATS_CLAUSE_SEPARATOR ""
  238. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  239. squareSum = 0, prev = 0, delta;\
  240. int runs = 0;
  241. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  242. delta = current_time(0) - start;\
  243. min = delta;\
  244. max = delta;\
  245. }\
  246. else {\
  247. delta = current_time(0) - prev;\
  248. }\
  249. if (max < delta)\
  250. max = delta;\
  251. else if (min > delta)\
  252. min = delta;\
  253. sum += delta;\
  254. squareSum += delta * delta;\
  255. runs++;\
  256. prev = current_time(0)
  257. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  258. runs = 0;\
  259. sum = 0;\
  260. squareSum = 0
  261. #else
  262. #define STATS_CLAUSE_SEPARATOR "\n"
  263. #define DECLARE_MULTI_VALUE_STATS_VARS()
  264. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  265. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  266. #endif
  267. #ifdef WOLFSSL_NO_FLOAT_FMT
  268. #define FLT_FMT "%0ld,%09lu"
  269. #define FLT_FMT_PREC "%0ld.%0*lu"
  270. #define FLT_FMT_PREC2 FLT_FMT_PREC
  271. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  272. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  273. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  274. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  275. 10000.0, 100000.0, 1000000.0, \
  276. 10000000.0, 100000000.0, \
  277. 1000000000.0 };
  278. #define FLT_FMT_PREC_ARGS(p, x) \
  279. (long)(x), \
  280. p, \
  281. (x) >= 0.0 ? \
  282. (unsigned long int)((((x) - (double)(long)(x)) * \
  283. pow_10_array[(p)+1]) + 0.5) : \
  284. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  285. pow_10_array[(p)+1]) + 0.5)
  286. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  287. #else
  288. #define FLT_FMT "%f"
  289. #define FLT_FMT_PREC "%.*f"
  290. #define FLT_FMT_PREC2 "%*.*f"
  291. #define FLT_FMT_ARGS(x) x
  292. #define FLT_FMT_PREC_ARGS(p, x) p, x
  293. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  294. #endif /* WOLFSSL_NO_FLOAT_FMT */
  295. #ifdef WOLFSSL_ESPIDF
  296. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  297. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  298. * enabled, all if the values in report are blank. */
  299. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  300. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  301. #error "Nano newlib formatting must not be enabled for benchmark"
  302. #endif
  303. #endif
  304. #if ESP_IDF_VERSION_MAJOR >= 5
  305. #define TFMT "%lu"
  306. #else
  307. #define TFMT "%d"
  308. #endif
  309. #ifdef configTICK_RATE_HZ
  310. /* Define CPU clock cycles per tick of FreeRTOS clock
  311. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  312. * configTICK_RATE_HZ is typically 100 or 1000.
  313. **/
  314. #if defined(CONFIG_IDF_TARGET_ESP8266)
  315. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  316. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  317. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  318. #endif
  319. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  320. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  321. #endif
  322. #endif
  323. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  324. /* This section is for pre-v5 ESP-IDF */
  325. #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  326. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  327. CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
  328. #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
  329. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  330. CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
  331. #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
  332. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  333. CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
  334. #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
  335. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  336. CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
  337. #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
  338. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  339. CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
  340. #else
  341. /* TODO unsupported */
  342. #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
  343. #endif
  344. #define CPU_TICK_CYCLES ( \
  345. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  346. / configTICK_RATE_HZ \
  347. )
  348. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  349. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  350. #include "driver/gptimer.h"
  351. static gptimer_handle_t esp_gptimer = NULL;
  352. static gptimer_config_t esp_timer_config = {
  353. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  354. .direction = GPTIMER_COUNT_UP,
  355. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  356. };
  357. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  358. defined(CONFIG_IDF_TARGET_ESP32C6)
  359. #include <esp_cpu.h>
  360. #if ESP_IDF_VERSION_MAJOR >= 5
  361. #include <driver/gptimer.h>
  362. #endif
  363. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  364. #define RESOLUTION_SCALE 100
  365. /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  366. static gptimer_handle_t esp_gptimer = NULL;
  367. static gptimer_config_t esp_timer_config = {
  368. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  369. .direction = GPTIMER_COUNT_UP,
  370. /* CONFIG_XTAL_FREQ = 40,
  371. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  372. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  373. (MILLION_VALUE / RESOLUTION_SCALE),
  374. };
  375. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  376. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  377. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  378. defined(CONFIG_IDF_TARGET_ESP32S3)
  379. #include <xtensa/hal.h>
  380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  381. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  382. #include <FreeRTOS.h>
  383. #include <esp_system.h>
  384. #include <esp_timer.h>
  385. #include <xtensa/hal.h>
  386. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  387. /* TODO add ESP32-H2 benchmark support */
  388. #else
  389. /* Other platform */
  390. #endif
  391. #include <esp_log.h>
  392. #endif /* WOLFSSL_ESPIDF */
  393. #if defined(HAVE_PTHREAD) || \
  394. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  395. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  396. !defined(BENCH_EMBEDDED))
  397. #include <errno.h>
  398. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  399. #include <unistd.h>
  400. #endif
  401. #endif
  402. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  403. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  404. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  405. #undef XFFLUSH
  406. #define XFFLUSH(...) WC_DO_NOTHING
  407. #endif
  408. /* only for stack size check */
  409. #include <wolfssl/wolfcrypt/mem_track.h>
  410. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  411. #define WC_ENABLE_BENCH_THREADING
  412. #endif
  413. /* enable tracking of stats for threaded benchmark */
  414. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  415. #define WC_BENCH_TRACK_STATS
  416. #endif
  417. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  418. static const char info_prefix[] = "###, ";
  419. static const char err_prefix[] = "!!!, ";
  420. #else
  421. static const char info_prefix[] = "";
  422. static const char err_prefix[] = "";
  423. #endif
  424. /* printf mappings */
  425. #ifdef FREESCALE_MQX
  426. #include <mqx.h>
  427. /* see wc_port.h for fio.h and nio.h includes */
  428. #elif defined(FREESCALE_KSDK_1_3)
  429. #include "fsl_debug_console.h"
  430. #include "fsl_os_abstraction.h"
  431. #undef printf
  432. #define printf PRINTF
  433. #elif defined(WOLFSSL_DEOS)
  434. #include <deos.h>
  435. #include <printx.h>
  436. #undef printf
  437. #define printf printx
  438. #elif defined(MICRIUM)
  439. #if (OS_VERSION < 50000)
  440. #include <bsp_ser.h>
  441. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  442. #undef printf
  443. #define printf BSP_Ser_Printf
  444. #endif
  445. #elif defined(WOLFSSL_ZEPHYR)
  446. #include <stdio.h>
  447. #include <stdarg.h>
  448. #define BENCH_EMBEDDED
  449. #define printf printfk
  450. static int printfk(const char *fmt, ...)
  451. {
  452. int ret;
  453. char line[WC_BENCH_MAX_LINE_LEN];
  454. va_list ap;
  455. va_start(ap, fmt);
  456. ret = vsnprintf(line, sizeof(line), fmt, ap);
  457. line[sizeof(line)-1] = '\0';
  458. printk("%s", line);
  459. va_end(ap);
  460. return ret;
  461. }
  462. #elif defined(WOLFSSL_TELIT_M2MB)
  463. #include <stdarg.h>
  464. #include <stdio.h>
  465. #include <string.h>
  466. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  467. /* remap printf */
  468. #undef printf
  469. #define printf M2M_LOG_INFO
  470. /* OS requires occasional sleep() */
  471. #ifndef TEST_SLEEP_MS
  472. #define TEST_SLEEP_MS 50
  473. #endif
  474. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  475. /* don't use file system for these tests, since ./certs dir isn't loaded */
  476. #undef NO_FILESYSTEM
  477. #define NO_FILESYSTEM
  478. /* ANDROID_V454 (for android studio) displays information in a textview
  479. * and redirects printf to the textview output instead of using
  480. * __android_log_print() */
  481. #elif defined(ANDROID) && !defined(ANDROID_V454)
  482. #ifdef XMALLOC_USER
  483. #include <stdlib.h> /* we're using malloc / free direct here */
  484. #endif
  485. #ifndef STRING_USER
  486. #include <stdio.h>
  487. #endif
  488. #include <android/log.h>
  489. #define printf(...) \
  490. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  491. #define fprintf(fp, ...) \
  492. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  493. #else
  494. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  495. /* MQX classic needs for EXIT_FAILURE */
  496. #include <stdlib.h> /* we're using malloc / free direct here */
  497. #endif
  498. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  499. #include <string.h>
  500. #include <stdio.h>
  501. #endif
  502. /* enable way for customer to override test/bench printf */
  503. #ifdef XPRINTF
  504. #undef printf
  505. #define printf XPRINTF
  506. #elif defined(NETOS)
  507. #undef printf
  508. #define printf dc_log_printf
  509. #endif
  510. #endif
  511. #ifdef HAVE_FIPS
  512. #include <wolfssl/wolfcrypt/fips_test.h>
  513. static void myFipsCb(int ok, int err, const char* hash)
  514. {
  515. printf("%sin my Fips callback, ok = %d, err = %d\n",
  516. ok ? info_prefix : err_prefix, ok, err);
  517. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  518. wc_GetErrorString(err));
  519. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  520. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  521. printf("%sIn core integrity hash check failure, copy above hash\n",
  522. err_prefix);
  523. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  524. err_prefix);
  525. }
  526. }
  527. #endif
  528. #ifdef WOLFSSL_STATIC_MEMORY
  529. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  530. #else
  531. #define HEAP_HINT NULL
  532. #endif /* WOLFSSL_STATIC_MEMORY */
  533. #ifndef EXIT_FAILURE
  534. #define EXIT_FAILURE 1
  535. #endif
  536. #undef LIBCALL_CHECK_RET
  537. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  538. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  539. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  540. #else
  541. #define LIBCALL_CHECK_RET(...) do { \
  542. int _libcall_ret = (__VA_ARGS__); \
  543. if (_libcall_ret < 0) { \
  544. printf("%s%s L%d error %d for \"%s\"\n", \
  545. err_prefix, __FILE__, __LINE__, \
  546. errno, #__VA_ARGS__); \
  547. XFFLUSH(stdout); \
  548. _exit(1); \
  549. } \
  550. } while(0)
  551. #endif
  552. #undef THREAD_CHECK_RET
  553. #define THREAD_CHECK_RET(...) do { \
  554. int _thread_ret = (__VA_ARGS__); \
  555. if (_thread_ret != 0) { \
  556. errno = _thread_ret; \
  557. printf("%s%s L%d error %d for \"%s\"\n", \
  558. err_prefix, __FILE__, __LINE__, \
  559. _thread_ret, #__VA_ARGS__); \
  560. XFFLUSH(stdout); \
  561. _exit(1); \
  562. } \
  563. } while(0)
  564. /* optional macro to add sleep between tests */
  565. #ifndef TEST_SLEEP
  566. /* stub the sleep macro */
  567. #define TEST_SLEEP() WC_DO_NOTHING
  568. #endif
  569. #define TEST_STRING "Everyone gets Friday off."
  570. #define TEST_STRING_SZ 25
  571. /* Bit values for each algorithm that is able to be benchmarked.
  572. * Common grouping of algorithms also.
  573. * Each algorithm has a unique value for its type e.g. cipher.
  574. */
  575. /* Cipher algorithms. */
  576. #define BENCH_AES_CBC 0x00000001
  577. #define BENCH_AES_GCM 0x00000002
  578. #define BENCH_AES_ECB 0x00000004
  579. #define BENCH_AES_XTS 0x00000008
  580. #define BENCH_AES_CTR 0x00000010
  581. #define BENCH_AES_CCM 0x00000020
  582. #define BENCH_CAMELLIA 0x00000100
  583. #define BENCH_ARC4 0x00000200
  584. #define BENCH_CHACHA20 0x00001000
  585. #define BENCH_CHACHA20_POLY1305 0x00002000
  586. #define BENCH_DES 0x00004000
  587. #define BENCH_AES_CFB 0x00010000
  588. #define BENCH_AES_OFB 0x00020000
  589. #define BENCH_AES_SIV 0x00040000
  590. #define BENCH_SM4_CBC 0x00080000
  591. #define BENCH_SM4_GCM 0x00100000
  592. #define BENCH_SM4_CCM 0x00200000
  593. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  594. /* Digest algorithms. */
  595. #define BENCH_MD5 0x00000001
  596. #define BENCH_POLY1305 0x00000002
  597. #define BENCH_SHA 0x00000004
  598. #define BENCH_SHA224 0x00000010
  599. #define BENCH_SHA256 0x00000020
  600. #define BENCH_SHA384 0x00000040
  601. #define BENCH_SHA512 0x00000080
  602. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  603. BENCH_SHA384 | BENCH_SHA512)
  604. #define BENCH_SHA3_224 0x00000100
  605. #define BENCH_SHA3_256 0x00000200
  606. #define BENCH_SHA3_384 0x00000400
  607. #define BENCH_SHA3_512 0x00000800
  608. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  609. BENCH_SHA3_384 | BENCH_SHA3_512)
  610. #define BENCH_SHAKE128 0x00001000
  611. #define BENCH_SHAKE256 0x00002000
  612. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  613. #define BENCH_RIPEMD 0x00004000
  614. #define BENCH_BLAKE2B 0x00008000
  615. #define BENCH_BLAKE2S 0x00010000
  616. #define BENCH_SM3 0x00020000
  617. /* MAC algorithms. */
  618. #define BENCH_CMAC 0x00000001
  619. #define BENCH_HMAC_MD5 0x00000002
  620. #define BENCH_HMAC_SHA 0x00000004
  621. #define BENCH_HMAC_SHA224 0x00000010
  622. #define BENCH_HMAC_SHA256 0x00000020
  623. #define BENCH_HMAC_SHA384 0x00000040
  624. #define BENCH_HMAC_SHA512 0x00000080
  625. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  626. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  627. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  628. #define BENCH_PBKDF2 0x00000100
  629. #define BENCH_SIPHASH 0x00000200
  630. /* KDF algorithms */
  631. #define BENCH_SRTP_KDF 0x00000001
  632. /* Asymmetric algorithms. */
  633. #define BENCH_RSA_KEYGEN 0x00000001
  634. #define BENCH_RSA 0x00000002
  635. #define BENCH_RSA_SZ 0x00000004
  636. #define BENCH_DH 0x00000010
  637. #define BENCH_ECC_MAKEKEY 0x00001000
  638. #define BENCH_ECC 0x00002000
  639. #define BENCH_ECC_ENCRYPT 0x00004000
  640. #define BENCH_ECC_ALL 0x00008000
  641. #define BENCH_CURVE25519_KEYGEN 0x00010000
  642. #define BENCH_CURVE25519_KA 0x00020000
  643. #define BENCH_ED25519_KEYGEN 0x00040000
  644. #define BENCH_ED25519_SIGN 0x00080000
  645. #define BENCH_CURVE448_KEYGEN 0x00100000
  646. #define BENCH_CURVE448_KA 0x00200000
  647. #define BENCH_ED448_KEYGEN 0x00400000
  648. #define BENCH_ED448_SIGN 0x00800000
  649. #define BENCH_ECC_P256 0x01000000
  650. #define BENCH_ECC_P384 0x02000000
  651. #define BENCH_ECC_P521 0x04000000
  652. #define BENCH_SM2 0x08000000
  653. #define BENCH_ECCSI_KEYGEN 0x00000020
  654. #define BENCH_ECCSI_PAIRGEN 0x00000040
  655. #define BENCH_ECCSI_VALIDATE 0x00000080
  656. #define BENCH_ECCSI 0x00000400
  657. #define BENCH_SAKKE_KEYGEN 0x10000000
  658. #define BENCH_SAKKE_RSKGEN 0x20000000
  659. #define BENCH_SAKKE_VALIDATE 0x40000000
  660. #define BENCH_SAKKE 0x80000000
  661. /* Post-Quantum Asymmetric algorithms. */
  662. #define BENCH_KYBER512 0x00000020
  663. #define BENCH_KYBER768 0x00000040
  664. #define BENCH_KYBER1024 0x00000080
  665. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  666. BENCH_KYBER1024)
  667. #define BENCH_ML_KEM_512 0x00000020
  668. #define BENCH_ML_KEM_768 0x00000040
  669. #define BENCH_ML_KEM_1024 0x00000080
  670. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  671. BENCH_ML_KEM_1024)
  672. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  673. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  674. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  675. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  676. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  677. #define BENCH_ML_DSA_44_SIGN 0x04000000
  678. #define BENCH_ML_DSA_65_SIGN 0x08000000
  679. #define BENCH_ML_DSA_87_SIGN 0x10000000
  680. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  681. BENCH_ML_DSA_65_SIGN | \
  682. BENCH_ML_DSA_87_SIGN)
  683. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  684. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  685. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  686. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  687. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  688. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  689. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  690. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  691. #define BENCH_LMS_HSS 0x00000001
  692. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  693. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  694. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  695. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  696. #ifndef NO_SHA256
  697. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  698. #elif defined(WOLFSSL_SHA512)
  699. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  700. #elif defined(WOLFSSL_SHAKE128)
  701. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  702. #elif defined(WOLFSSL_SHAKE256)
  703. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  704. #else
  705. #define BENCH_XMSS_XMSSMT 0x00000000
  706. #endif
  707. /* Other */
  708. #define BENCH_RNG 0x00000001
  709. #define BENCH_SCRYPT 0x00000002
  710. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  711. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  712. * static declaration of `bench_Usage_msg1`. */
  713. #if !defined(AES_AUTH_ADD_SZ) && \
  714. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  715. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  716. /* For STM32 use multiple of 4 to leverage crypto hardware
  717. * Xilinx Versal requires to use multiples of 16 bytes */
  718. #define AES_AUTH_ADD_SZ 16
  719. #endif
  720. #ifndef AES_AUTH_ADD_SZ
  721. #define AES_AUTH_ADD_SZ 13
  722. #endif
  723. #endif
  724. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  725. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  726. #define BENCH_PQ_STATEFUL_HBS
  727. #endif
  728. /* Benchmark all compiled in algorithms.
  729. * When 1, ignore other benchmark algorithm values.
  730. * 0, only benchmark algorithm values set.
  731. */
  732. static int bench_all = 1;
  733. /* Cipher algorithms to benchmark. */
  734. static word32 bench_cipher_algs = 0;
  735. /* Digest algorithms to benchmark. */
  736. static word32 bench_digest_algs = 0;
  737. /* MAC algorithms to benchmark. */
  738. static word32 bench_mac_algs = 0;
  739. /* KDF algorithms to benchmark. */
  740. static word32 bench_kdf_algs = 0;
  741. /* Asymmetric algorithms to benchmark. */
  742. static word32 bench_asym_algs = 0;
  743. /* Post-Quantum Asymmetric algorithms to benchmark. */
  744. static word32 bench_pq_asym_algs = 0;
  745. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  746. static word32 bench_pq_asym_algs2 = 0;
  747. /* Other cryptographic algorithms to benchmark. */
  748. static word32 bench_other_algs = 0;
  749. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  750. static word32 bench_pq_hash_sig_algs = 0;
  751. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  752. /* The mapping of command line option to bit values. */
  753. typedef struct bench_alg {
  754. /* Command line option string. */
  755. const char* str;
  756. /* Bit values to set. */
  757. word32 val;
  758. } bench_alg;
  759. #ifndef MAIN_NO_ARGS
  760. /* All recognized cipher algorithm choosing command line options. */
  761. static const bench_alg bench_cipher_opt[] = {
  762. { "-cipher", 0xffffffff },
  763. #ifdef HAVE_AES_CBC
  764. { "-aes-cbc", BENCH_AES_CBC },
  765. #endif
  766. #ifdef HAVE_AESGCM
  767. { "-aes-gcm", BENCH_AES_GCM },
  768. #endif
  769. #ifdef WOLFSSL_AES_DIRECT
  770. { "-aes-ecb", BENCH_AES_ECB },
  771. #endif
  772. #ifdef WOLFSSL_AES_XTS
  773. { "-aes-xts", BENCH_AES_XTS },
  774. #endif
  775. #ifdef WOLFSSL_AES_CFB
  776. { "-aes-cfb", BENCH_AES_CFB },
  777. #endif
  778. #ifdef WOLFSSL_AES_OFB
  779. { "-aes-ofb", BENCH_AES_OFB },
  780. #endif
  781. #ifdef WOLFSSL_AES_COUNTER
  782. { "-aes-ctr", BENCH_AES_CTR },
  783. #endif
  784. #ifdef HAVE_AESCCM
  785. { "-aes-ccm", BENCH_AES_CCM },
  786. #endif
  787. #ifdef WOLFSSL_AES_SIV
  788. { "-aes-siv", BENCH_AES_SIV },
  789. #endif
  790. #ifdef HAVE_CAMELLIA
  791. { "-camellia", BENCH_CAMELLIA },
  792. #endif
  793. #ifndef NO_RC4
  794. { "-arc4", BENCH_ARC4 },
  795. #endif
  796. #ifdef HAVE_CHACHA
  797. { "-chacha20", BENCH_CHACHA20 },
  798. #endif
  799. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  800. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  801. #endif
  802. #ifdef WOLFSSL_SM4_CBC
  803. { "-sm4-cbc", BENCH_SM4_CBC },
  804. #endif
  805. #ifdef WOLFSSL_SM4_GCM
  806. { "-sm4-gcm", BENCH_SM4_GCM },
  807. #endif
  808. #ifdef WOLFSSL_SM4_CCM
  809. { "-sm4-ccm", BENCH_SM4_CCM },
  810. #endif
  811. #ifdef WOLFSSL_SM4
  812. { "-sm4", BENCH_SM4 },
  813. #endif
  814. #ifndef NO_DES3
  815. { "-des", BENCH_DES },
  816. #endif
  817. { NULL, 0 }
  818. };
  819. /* All recognized digest algorithm choosing command line options. */
  820. static const bench_alg bench_digest_opt[] = {
  821. { "-digest", 0xffffffff },
  822. #ifndef NO_MD5
  823. { "-md5", BENCH_MD5 },
  824. #endif
  825. #ifdef HAVE_POLY1305
  826. { "-poly1305", BENCH_POLY1305 },
  827. #endif
  828. #ifndef NO_SHA
  829. { "-sha", BENCH_SHA },
  830. #endif
  831. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  832. || defined(WOLFSSL_SHA512)
  833. { "-sha2", BENCH_SHA2 },
  834. #endif
  835. #ifdef WOLFSSL_SHA224
  836. { "-sha224", BENCH_SHA224 },
  837. #endif
  838. #ifndef NO_SHA256
  839. { "-sha256", BENCH_SHA256 },
  840. #endif
  841. #ifdef WOLFSSL_SHA384
  842. { "-sha384", BENCH_SHA384 },
  843. #endif
  844. #ifdef WOLFSSL_SHA512
  845. { "-sha512", BENCH_SHA512 },
  846. #endif
  847. #ifdef WOLFSSL_SHA3
  848. { "-sha3", BENCH_SHA3 },
  849. #ifndef WOLFSSL_NOSHA3_224
  850. { "-sha3-224", BENCH_SHA3_224 },
  851. #endif
  852. #ifndef WOLFSSL_NOSHA3_256
  853. { "-sha3-256", BENCH_SHA3_256 },
  854. #endif
  855. #ifndef WOLFSSL_NOSHA3_384
  856. { "-sha3-384", BENCH_SHA3_384 },
  857. #endif
  858. #ifndef WOLFSSL_NOSHA3_512
  859. { "-sha3-512", BENCH_SHA3_512 },
  860. #endif
  861. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  862. { "-shake", BENCH_SHAKE },
  863. #endif
  864. #ifdef WOLFSSL_SHAKE128
  865. { "-shake128", BENCH_SHAKE128 },
  866. #endif
  867. #ifdef WOLFSSL_SHAKE256
  868. { "-shake256", BENCH_SHAKE256 },
  869. #endif
  870. #endif
  871. #ifdef WOLFSSL_SM3
  872. { "-sm3", BENCH_SM3 },
  873. #endif
  874. #ifdef WOLFSSL_RIPEMD
  875. { "-ripemd", BENCH_RIPEMD },
  876. #endif
  877. #ifdef HAVE_BLAKE2
  878. { "-blake2b", BENCH_BLAKE2B },
  879. #endif
  880. #ifdef HAVE_BLAKE2S
  881. { "-blake2s", BENCH_BLAKE2S },
  882. #endif
  883. { NULL, 0 }
  884. };
  885. /* All recognized MAC algorithm choosing command line options. */
  886. static const bench_alg bench_mac_opt[] = {
  887. { "-mac", 0xffffffff },
  888. #ifdef WOLFSSL_CMAC
  889. { "-cmac", BENCH_CMAC },
  890. #endif
  891. #ifndef NO_HMAC
  892. { "-hmac", BENCH_HMAC },
  893. #ifndef NO_MD5
  894. { "-hmac-md5", BENCH_HMAC_MD5 },
  895. #endif
  896. #ifndef NO_SHA
  897. { "-hmac-sha", BENCH_HMAC_SHA },
  898. #endif
  899. #ifdef WOLFSSL_SHA224
  900. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  901. #endif
  902. #ifndef NO_SHA256
  903. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  904. #endif
  905. #ifdef WOLFSSL_SHA384
  906. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  907. #endif
  908. #ifdef WOLFSSL_SHA512
  909. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  910. #endif
  911. #ifndef NO_PWDBASED
  912. { "-pbkdf2", BENCH_PBKDF2 },
  913. #endif
  914. #endif
  915. #ifdef WOLFSSL_SIPHASH
  916. { "-siphash", BENCH_SIPHASH },
  917. #endif
  918. { NULL, 0 }
  919. };
  920. /* All recognized KDF algorithm choosing command line options. */
  921. static const bench_alg bench_kdf_opt[] = {
  922. { "-kdf", 0xffffffff },
  923. #ifdef WC_SRTP_KDF
  924. { "-srtp-kdf", BENCH_SRTP_KDF },
  925. #endif
  926. { NULL, 0 }
  927. };
  928. /* All recognized asymmetric algorithm choosing command line options. */
  929. static const bench_alg bench_asym_opt[] = {
  930. { "-asym", 0xffffffff },
  931. #ifndef NO_RSA
  932. #ifdef WOLFSSL_KEY_GEN
  933. { "-rsa-kg", BENCH_RSA_KEYGEN },
  934. #endif
  935. { "-rsa", BENCH_RSA },
  936. #ifdef WOLFSSL_KEY_GEN
  937. { "-rsa-sz", BENCH_RSA_SZ },
  938. #endif
  939. #endif
  940. #ifndef NO_DH
  941. { "-dh", BENCH_DH },
  942. #endif
  943. #ifdef HAVE_ECC
  944. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  945. { "-ecc", BENCH_ECC },
  946. #ifdef HAVE_ECC_ENCRYPT
  947. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  948. #endif
  949. { "-ecc-all", BENCH_ECC_ALL },
  950. #endif
  951. #ifdef WOLFSSL_SM2
  952. { "-sm2", BENCH_SM2 },
  953. #endif
  954. #ifdef HAVE_CURVE25519
  955. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  956. #ifdef HAVE_CURVE25519_SHARED_SECRET
  957. { "-x25519", BENCH_CURVE25519_KA },
  958. #endif
  959. #endif
  960. #ifdef HAVE_ED25519
  961. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  962. { "-ed25519", BENCH_ED25519_SIGN },
  963. #endif
  964. #ifdef HAVE_CURVE448
  965. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  966. #ifdef HAVE_CURVE448_SHARED_SECRET
  967. { "-x448", BENCH_CURVE448_KA },
  968. #endif
  969. #endif
  970. #ifdef HAVE_ED448
  971. { "-ed448-kg", BENCH_ED448_KEYGEN },
  972. { "-ed448", BENCH_ED448_SIGN },
  973. #endif
  974. #ifdef WOLFCRYPT_HAVE_ECCSI
  975. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  976. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  977. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  978. { "-eccsi", BENCH_ECCSI },
  979. #endif
  980. #ifdef WOLFCRYPT_HAVE_SAKKE
  981. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  982. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  983. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  984. { "-sakke", BENCH_SAKKE },
  985. #endif
  986. { NULL, 0 }
  987. };
  988. /* All recognized other cryptographic algorithm choosing command line options.
  989. */
  990. static const bench_alg bench_other_opt[] = {
  991. { "-other", 0xffffffff },
  992. #ifndef WC_NO_RNG
  993. { "-rng", BENCH_RNG },
  994. #endif
  995. #ifdef HAVE_SCRYPT
  996. { "-scrypt", BENCH_SCRYPT },
  997. #endif
  998. { NULL, 0}
  999. };
  1000. #endif /* MAIN_NO_ARGS */
  1001. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  1002. #if defined(BENCH_PQ_STATEFUL_HBS)
  1003. typedef struct bench_pq_hash_sig_alg {
  1004. /* Command line option string. */
  1005. const char* str;
  1006. /* Bit values to set. */
  1007. word32 val;
  1008. } bench_pq_hash_sig_alg;
  1009. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  1010. { "-pq_hash_sig", 0xffffffff},
  1011. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  1012. { "-lms_hss", BENCH_LMS_HSS},
  1013. #endif
  1014. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  1015. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  1016. #ifdef WC_XMSS_SHA256
  1017. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  1018. #endif
  1019. #ifdef WC_XMSS_SHA512
  1020. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  1021. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  1022. #endif
  1023. #endif
  1024. #ifdef WC_XMSS_SHAKE128
  1025. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  1026. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  1027. #endif
  1028. #endif
  1029. #ifdef WC_XMSS_SHAKE256
  1030. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  1031. #endif
  1032. #endif
  1033. { NULL, 0}
  1034. };
  1035. #endif /* BENCH_PQ_STATEFUL_HBS */
  1036. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1037. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1038. /* The post-quantum-specific mapping of command line option to bit values and
  1039. * OQS name. */
  1040. typedef struct bench_pq_alg {
  1041. /* Command line option string. */
  1042. const char* str;
  1043. /* Bit values to set. */
  1044. word32 val;
  1045. } bench_pq_alg;
  1046. /* All recognized post-quantum asymmetric algorithm choosing command line
  1047. * options. */
  1048. static const bench_pq_alg bench_pq_asym_opt[] = {
  1049. { "-pq", 0xffffffff },
  1050. #ifdef WOLFSSL_HAVE_KYBER
  1051. { "-kyber", BENCH_KYBER },
  1052. { "-kyber512", BENCH_KYBER512 },
  1053. { "-kyber768", BENCH_KYBER768 },
  1054. { "-kyber1024", BENCH_KYBER1024 },
  1055. { "-ml-kem", BENCH_ML_KEM },
  1056. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1057. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1058. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1059. #endif
  1060. #if defined(HAVE_FALCON)
  1061. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1062. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1063. #endif
  1064. #if defined(HAVE_DILITHIUM)
  1065. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1066. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1067. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1068. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1069. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1070. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1071. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1072. #endif
  1073. { NULL, 0 }
  1074. };
  1075. #if defined(HAVE_SPHINCS)
  1076. /* All recognized post-quantum asymmetric algorithm choosing command line
  1077. * options. (Part 2) */
  1078. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1079. { "-pq", 0xffffffff },
  1080. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1081. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1082. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1083. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1084. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1085. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1086. { NULL, 0, }
  1087. };
  1088. #endif /* HAVE_SPHINCS */
  1089. #endif
  1090. #ifdef HAVE_WNR
  1091. const char* wnrConfigFile = "wnr-example.conf";
  1092. #endif
  1093. #if defined(WOLFSSL_MDK_ARM)
  1094. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1095. #define fopen wolfSSL_fopen
  1096. #endif
  1097. static int lng_index = 0;
  1098. #ifndef NO_MAIN_DRIVER
  1099. #ifndef MAIN_NO_ARGS
  1100. static const char* bench_Usage_msg1[][25] = {
  1101. /* 0 English */
  1102. { "-? <num> Help, print this usage\n",
  1103. " 0: English, 1: Japanese\n",
  1104. "-csv Print terminal output in csv format\n",
  1105. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1106. "-no_aad No additional authentication data passed.\n",
  1107. "-aad_size <num> With <num> bytes of AAD.\n",
  1108. ("-all_aad With AAD length of 0, "
  1109. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1110. " and\n"
  1111. " (if set via -aad_size) <aad_size> bytes.\n"
  1112. ),
  1113. "-dgst_full Full digest operation performed.\n",
  1114. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1115. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1116. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1117. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1118. "-p256 Measure ECC using P-256 curve.\n",
  1119. "-p384 Measure ECC using P-384 curve.\n",
  1120. "-p521 Measure ECC using P-521 curve.\n",
  1121. "-ecc-all Bench all enabled ECC curves.\n",
  1122. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1123. ("-lng <num> Display benchmark result by specified language.\n"
  1124. " 0: English, 1: Japanese\n"
  1125. ),
  1126. "<num> Size of block in bytes\n",
  1127. ("-blocks <num> Number of blocks. Can be used together with the "
  1128. "'Size of block'\n"
  1129. " option, but must be used after that one.\n"
  1130. ),
  1131. "-threads <num> Number of threads to run\n",
  1132. "-print Show benchmark stats summary\n",
  1133. "-hash_input <file> Input data to use for hash benchmarking\n",
  1134. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1135. "-min_runs <num> Specify minimum number of operation runs\n"
  1136. },
  1137. #ifndef NO_MULTIBYTE_PRINT
  1138. /* 1 Japanese */
  1139. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1140. " 0: 英語、 1: 日本語\n",
  1141. "-csv csv 形式で端末に出力します。\n",
  1142. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1143. "-no_aad 追加の認証データを使用しません.\n",
  1144. "-aad_size <num> TBD.\n",
  1145. "-all_aad TBD.\n",
  1146. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1147. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1148. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1149. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1150. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1151. "-p256 Measure ECC using P-256 curve.\n",
  1152. "-p384 Measure ECC using P-384 curve.\n",
  1153. "-p521 Measure ECC using P-521 curve.\n",
  1154. "-ecc-all Bench all enabled ECC curves.\n",
  1155. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1156. " 利用可能なアルゴリズムは下記を含みます:\n"
  1157. ),
  1158. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1159. " 0: 英語、 1: 日本語\n"
  1160. ),
  1161. "<num> ブロックサイズをバイト単位で指定します。\n",
  1162. "-blocks <num> TBD.\n",
  1163. "-threads <num> 実行するスレッド数\n",
  1164. "-print ベンチマーク統計の要約を表示する\n",
  1165. /* TODO: translate below */
  1166. "-hash_input <file> Input data to use for hash benchmarking\n",
  1167. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1168. "-min_runs <num> Specify minimum number of operation runs\n"
  1169. },
  1170. #endif
  1171. };
  1172. #endif /* MAIN_NO_ARGS */
  1173. #endif
  1174. static const char* bench_result_words1[][4] = {
  1175. { "took",
  1176. #ifdef BENCH_MICROSECOND
  1177. "microseconds"
  1178. #else
  1179. "seconds"
  1180. #endif
  1181. , "Cycles per byte", NULL }, /* 0 English */
  1182. #ifndef NO_MULTIBYTE_PRINT
  1183. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1184. #endif
  1185. };
  1186. #if !defined(NO_RSA) || \
  1187. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1188. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1189. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1190. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1191. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1192. static const char* bench_desc_words[][15] = {
  1193. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1194. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1195. #ifndef NO_MULTIBYTE_PRINT
  1196. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1197. #endif
  1198. };
  1199. #endif
  1200. #ifdef MULTI_VALUE_STATISTICS
  1201. static const char* bench_result_words3[][5] = {
  1202. /* 0 English */
  1203. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1204. /* TODO: Add japenese version */
  1205. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1206. };
  1207. #endif
  1208. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1209. #define HAVE_GET_CYCLES
  1210. static WC_INLINE word64 get_intel_cycles(void);
  1211. static THREAD_LS_T word64 total_cycles;
  1212. #define INIT_CYCLE_COUNTER
  1213. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1214. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1215. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1216. #define SHOW_INTEL_CYCLES(b, n, s) \
  1217. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1218. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1219. bench_result_words1[lng_index][2], \
  1220. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1221. (double)total_cycles / ((word64)count*(s))))
  1222. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1223. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1224. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1225. (double)total_cycles / ((word64)count*(s))))
  1226. #elif defined(LINUX_CYCLE_COUNT)
  1227. #include <linux/perf_event.h>
  1228. #include <sys/syscall.h>
  1229. #include <unistd.h>
  1230. static THREAD_LS_T word64 begin_cycles;
  1231. static THREAD_LS_T word64 total_cycles;
  1232. static THREAD_LS_T int cycles = -1;
  1233. static THREAD_LS_T struct perf_event_attr atr;
  1234. #define INIT_CYCLE_COUNTER do { \
  1235. atr.type = PERF_TYPE_HARDWARE; \
  1236. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1237. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1238. } while (0);
  1239. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1240. #define END_INTEL_CYCLES do { \
  1241. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1242. total_cycles = total_cycles - begin_cycles; \
  1243. } while (0);
  1244. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1245. #define SHOW_INTEL_CYCLES(b, n, s) \
  1246. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1247. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1248. bench_result_words1[lng_index][2], \
  1249. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1250. (count*s)))
  1251. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1252. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1253. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1254. / (count*s)))
  1255. #elif defined(SYNERGY_CYCLE_COUNT)
  1256. #include "hal_data.h"
  1257. static THREAD_LS_T word64 begin_cycles;
  1258. static THREAD_LS_T word64 total_cycles;
  1259. #define INIT_CYCLE_COUNTER
  1260. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1261. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1262. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1263. #define SHOW_INTEL_CYCLES(b, n, s) \
  1264. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1265. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1266. bench_result_words1[lng_index][2], \
  1267. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1268. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1269. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1270. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1271. #elif defined(WOLFSSL_ESPIDF)
  1272. /* TAG for ESP_LOGx() */
  1273. static const char* TAG = "wolfssl_benchmark";
  1274. static THREAD_LS_T word64 begin_cycles = 0;
  1275. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1276. static THREAD_LS_T word64 end_cycles = 0;
  1277. static THREAD_LS_T word64 total_cycles = 0;
  1278. /* the return value, as a global var */
  1279. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1280. /* the last value seen, adjusted for an overflow, as a global var */
  1281. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1282. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1283. /* esp_get_cpu_benchmark_cycles(void):
  1284. *
  1285. * Architecture-independant CPU clock counter.
  1286. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1287. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1288. /* Some vars for debugging, compare ticks to cycles */
  1289. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1290. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1291. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1292. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1293. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1294. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1295. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1296. #if ESP_IDF_VERSION_MAJOR >= 5
  1297. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1298. #define HAVE_GET_CYCLES
  1299. #define INIT_CYCLE_COUNTER do { \
  1300. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1301. esp_cpu_set_cycle_count(0); \
  1302. } while (0);
  1303. #else
  1304. #define HAVE_GET_CYCLES
  1305. #define INIT_CYCLE_COUNTER do { \
  1306. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1307. } while (0);
  1308. #endif
  1309. #define BEGIN_ESP_CYCLES do { \
  1310. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1311. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1312. begin_cycles_ticks = xTaskGetTickCount(); \
  1313. } while (0);
  1314. /* since it rolls over, we have something that will tolerate one */
  1315. #define END_ESP_CYCLES \
  1316. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1317. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1318. end_cycles, \
  1319. begin_cycles \
  1320. ); \
  1321. total_cycles = (end_cycles - begin_cycles);
  1322. #define SHOW_ESP_CYCLES(b, n, s) \
  1323. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1324. " %s = " FLT_FMT_PREC2 "\n", \
  1325. bench_result_words1[lng_index][2], \
  1326. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1327. )
  1328. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1329. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1330. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1331. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1332. /* 64 bit, unisgned, absolute difference
  1333. * used in CPU cycle counter debug calcs. */
  1334. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1335. {
  1336. uint64_t ret;
  1337. ret = (x > y) ? (x - y) : (y - x);
  1338. return ret;
  1339. }
  1340. #endif
  1341. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1342. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1343. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1344. ** at least once during full benchmark tests.
  1345. **
  1346. ** To test timing overflow, add a delay longer than max cycles:
  1347. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1348. */
  1349. uint64_t esp_get_cycle_count_ex()
  1350. {
  1351. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1352. /* unsigned int max = 4,294,967,295 */
  1353. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1354. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1355. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1356. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1357. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1358. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1359. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1360. #endif
  1361. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1362. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1363. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1364. * (current - last) */
  1365. #endif
  1366. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1367. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1368. defined(CONFIG_IDF_TARGET_ESP32C6)
  1369. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1370. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1371. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1372. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1373. #if ESP_IDF_VERSION_MAJOR >= 5
  1374. thisVal = esp_cpu_get_cycle_count();
  1375. #else
  1376. thisVal = cpu_hal_get_cycle_count();
  1377. #endif
  1378. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1379. thisVal = esp_cpu_get_cycle_count();
  1380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  1381. thisVal = esp_timer_get_time();
  1382. #else
  1383. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1384. * Calling current_time(1) to reset time causes thisVal overflow,
  1385. * on Xtensa, but not on RISC-V architecture. See also, below */
  1386. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1387. #ifndef configCPU_CLOCK_HZ
  1388. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1389. #define configCPU_CLOCK_HZ \
  1390. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1391. #endif
  1392. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1393. thisVal = (uint64_t)xTaskGetTickCount() *
  1394. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1395. #elif defined(__XTENSA__)
  1396. thisVal = esp_cpu_get_cycle_count();
  1397. #else
  1398. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1399. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1400. #endif
  1401. #endif
  1402. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1403. {
  1404. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1405. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1406. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1407. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1408. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1409. ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
  1410. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1411. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1412. }
  1413. #endif
  1414. /* If either thisVal is smaller than last (overflow), and/or the
  1415. * expected value calculated from FreeRTOS tick difference that would
  1416. * have never fit into an unsigned 32 bit integer anyhow... then we
  1417. * need to adjust thisVal to save. */
  1418. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1419. {
  1420. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1421. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1422. **
  1423. ** NOTE for long duration between calls with multiple overflows:
  1424. **
  1425. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1426. **
  1427. ** At this time no single test overflows. This is currently only a
  1428. ** concern for cumulative counts over multiple tests. As long
  1429. ** as well call xthal_get_ccount_ex() with no more than one
  1430. ** overflow CPU tick count, all will be well.
  1431. */
  1432. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1433. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1434. "(%llu < %llu) adding UINT_MAX = %llu.",
  1435. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1436. #endif
  1437. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1438. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1439. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1440. #endif
  1441. /* double check expected diff calc */
  1442. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1443. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1444. expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  1445. * MILLION_VALUE)
  1446. * tickDiff / configTICK_RATE_HZ;
  1447. #else
  1448. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1449. * tickDiff / configTICK_RATE_HZ;
  1450. #endif
  1451. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1452. #endif
  1453. if (expected_diff > UINT_MAX) {
  1454. /* The number of cycles expected from FreeRTOS ticks is
  1455. * greater than the maximum size of an unsigned 32-bit
  1456. * integer, meaning multiple overflows occurred. */
  1457. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1458. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1459. #endif
  1460. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1461. }
  1462. else {
  1463. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1464. }
  1465. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1466. {
  1467. tickBeginDiff = tickCount - begin_cycles_ticks;
  1468. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1469. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1470. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1471. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1472. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1473. }
  1474. #endif
  1475. }
  1476. else {
  1477. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1478. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1479. #endif
  1480. } /* if thisVal adjustment check */
  1481. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1482. if (thisTimerVal < _esp_cpu_timer_last)
  1483. {
  1484. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1485. "adding %ull", UINT_MAX);
  1486. thisTimerVal += (word64)UINT_MAX;
  1487. }
  1488. /* Check an alternate counter using a timer */
  1489. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1490. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1491. /* Adjust our actual returned value that takes into account overflow,
  1492. * increment 64 bit extended total by this 32 bit differential: */
  1493. thisIncrement = (thisVal - _esp_cpu_count_last);
  1494. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1495. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1496. #endif
  1497. /* Add our adjustment, taking into account overflows (see above) */
  1498. _esp_get_cycle_count_ex += thisIncrement;
  1499. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1500. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1501. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1502. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1503. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1504. /* all of this took some time, so reset the "last seen" value
  1505. * for the next measurement. */
  1506. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1507. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1508. defined(CONFIG_IDF_TARGET_ESP32C6)
  1509. {
  1510. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1511. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1512. &_esp_cpu_timer_last));
  1513. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1514. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1515. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1516. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1517. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1518. #if ESP_IDF_VERSION_MAJOR >= 5
  1519. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1520. #else
  1521. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  1522. #endif
  1523. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1524. }
  1525. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1526. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1527. #else
  1528. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1529. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1530. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1531. * or thisVal = xthal_get_ccount(); */
  1532. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1533. /* There's no CPU counter on the ESP8266, so we'll estimate
  1534. * cycles based on defined CPU frequency from sdkconfig and
  1535. * the RTOS tick frequency */
  1536. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1537. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1538. #elif ESP_IDF_VERSION_MAJOR < 5
  1539. _esp_cpu_count_last = xthal_get_ccount();
  1540. #else
  1541. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1542. #endif
  1543. #endif
  1544. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1545. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1546. #endif
  1547. /* Return the 64 bit extended total from 32 bit counter. */
  1548. return _esp_get_cycle_count_ex;
  1549. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1550. /* implement other architecture cycle counters here */
  1551. #else
  1552. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1553. #undef HAVE_GET_CYCLES
  1554. #define INIT_CYCLE_COUNTER
  1555. #define BEGIN_INTEL_CYCLES
  1556. #define END_INTEL_CYCLES
  1557. #ifdef MULTI_VALUE_STATISTICS
  1558. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1559. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1560. #else
  1561. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1562. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1563. #endif
  1564. #endif
  1565. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1566. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1567. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1568. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1569. #endif
  1570. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1571. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1572. !defined(NO_DH)
  1573. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1574. #include <wolfssl/certs_test.h>
  1575. #endif
  1576. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1577. #include <wolfssl/wolfcrypt/blake2.h>
  1578. #endif
  1579. #ifdef _MSC_VER
  1580. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1581. #pragma warning(disable: 4996)
  1582. #endif
  1583. #ifdef WOLFSSL_CURRTIME_REMAP
  1584. #define current_time WOLFSSL_CURRTIME_REMAP
  1585. #else
  1586. double current_time(int reset);
  1587. #endif
  1588. #ifdef LINUX_RUSAGE_UTIME
  1589. static void check_for_excessive_stime(const char *desc,
  1590. const char *desc_extra);
  1591. #endif
  1592. #if !defined(WC_NO_RNG) && \
  1593. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1594. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1595. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1596. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1597. || defined(WOLFSSL_HAVE_KYBER))
  1598. #define HAVE_LOCAL_RNG
  1599. static THREAD_LS_T WC_RNG gRng;
  1600. #define GLOBAL_RNG &gRng
  1601. #else
  1602. #define GLOBAL_RNG NULL
  1603. #endif
  1604. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1605. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1606. defined(HAVE_ECC) || !defined(NO_DH) || \
  1607. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1608. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1609. defined(WOLFSSL_HAVE_LMS)
  1610. #define BENCH_ASYM
  1611. #endif
  1612. #if defined(BENCH_ASYM)
  1613. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1614. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1615. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1616. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1617. defined(WOLFSSL_HAVE_LMS)
  1618. static const char* bench_result_words2[][5] = {
  1619. #ifdef BENCH_MICROSECOND
  1620. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1621. for μsec */
  1622. #else
  1623. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1624. #endif
  1625. #ifndef NO_MULTIBYTE_PRINT
  1626. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1627. #endif
  1628. };
  1629. #endif
  1630. #endif
  1631. #ifdef WOLFSSL_CAAM
  1632. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1633. #ifdef WOLFSSL_SECO_CAAM
  1634. #define SECO_MAX_UPDATES 10000
  1635. #define SECO_BENCHMARK_NONCE 0x7777
  1636. #define SECO_KEY_STORE_ID 1
  1637. #endif
  1638. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1639. #else
  1640. #ifdef WC_USE_DEVID
  1641. static THREAD_LS_T int devId = WC_USE_DEVID;
  1642. #else
  1643. static THREAD_LS_T int devId = INVALID_DEVID;
  1644. #endif
  1645. #endif
  1646. /* Asynchronous helper macros */
  1647. #ifdef WC_ENABLE_BENCH_THREADING
  1648. typedef struct ThreadData {
  1649. pthread_t thread_id;
  1650. } ThreadData;
  1651. static ThreadData* g_threadData;
  1652. static volatile int g_threadCount;
  1653. #endif
  1654. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1655. #ifndef NO_HW_BENCH
  1656. #define BENCH_DEVID
  1657. #endif
  1658. #ifndef HAVE_RENESAS_SYNC
  1659. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1660. #else
  1661. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1662. #endif
  1663. #else
  1664. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1665. #endif
  1666. #ifdef WOLFSSL_ASYNC_CRYPT
  1667. static WOLF_EVENT_QUEUE eventQueue;
  1668. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1669. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1670. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1671. int callAgain, int* times, int limit, int* pending)
  1672. {
  1673. int allowNext = 0;
  1674. /* this state can be set from a different thread */
  1675. WOLF_EVENT_STATE state = asyncDev->event.state;
  1676. /* if algo doesn't require calling again then use this flow */
  1677. if (state == WOLF_EVENT_STATE_DONE) {
  1678. if (callAgain) {
  1679. /* needs called again, so allow it and handle completion in
  1680. * bench_async_handle */
  1681. allowNext = 1;
  1682. }
  1683. else {
  1684. *ret = asyncDev->event.ret;
  1685. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1686. (*times)++;
  1687. if (*pending > 0) /* to support case where async blocks */
  1688. (*pending)--;
  1689. if ((*times + *pending) < limit)
  1690. allowNext = 1;
  1691. }
  1692. }
  1693. /* if slot is available and we haven't reached limit, start another */
  1694. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1695. allowNext = 1;
  1696. }
  1697. return allowNext;
  1698. }
  1699. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1700. int callAgain, int* times, int* pending)
  1701. {
  1702. WOLF_EVENT_STATE state = asyncDev->event.state;
  1703. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1704. if (state == WOLF_EVENT_STATE_DONE) {
  1705. *ret = asyncDev->event.ret;
  1706. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1707. (*times)++;
  1708. (*pending)--;
  1709. }
  1710. else {
  1711. (*pending)++;
  1712. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1713. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1714. }
  1715. }
  1716. else if (*ret >= 0) {
  1717. *ret = asyncDev->event.ret;
  1718. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1719. (*times)++;
  1720. if (*pending > 0) /* to support case where async blocks */
  1721. (*pending)--;
  1722. }
  1723. return (*ret >= 0) ? 1 : 0;
  1724. }
  1725. static WC_INLINE int bench_async_poll(int* pending)
  1726. {
  1727. int ret, asyncDone = 0;
  1728. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1729. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1730. if (ret != 0) {
  1731. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1732. return ret;
  1733. }
  1734. if (asyncDone == 0) {
  1735. #ifndef WC_NO_ASYNC_THREADING
  1736. /* give time to other threads */
  1737. wc_AsyncThreadYield();
  1738. #endif
  1739. }
  1740. (void)pending;
  1741. return asyncDone;
  1742. }
  1743. #else
  1744. #define BENCH_MAX_PENDING 1
  1745. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1746. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1747. int callAgain, int* times, int limit, int* pending)
  1748. {
  1749. (void)ret;
  1750. (void)asyncDev;
  1751. (void)callAgain;
  1752. (void)times;
  1753. (void)limit;
  1754. (void)pending;
  1755. return 1;
  1756. }
  1757. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1758. int callAgain, int* times, int* pending)
  1759. {
  1760. (void)asyncDev;
  1761. (void)callAgain;
  1762. (void)pending;
  1763. if (*ret >= 0) {
  1764. /* operation completed */
  1765. (*times)++;
  1766. return 1;
  1767. }
  1768. return 0;
  1769. }
  1770. #define bench_async_poll(p) WC_DO_NOTHING
  1771. #endif /* WOLFSSL_ASYNC_CRYPT */
  1772. /* maximum runtime for each benchmark */
  1773. #ifndef BENCH_MIN_RUNTIME_SEC
  1774. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1775. #endif
  1776. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1777. #define AES_AUTH_TAG_SZ 16
  1778. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1779. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1780. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1781. #if !defined(NO_MAIN_DRIVER)
  1782. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1783. #else
  1784. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1785. #endif
  1786. #endif
  1787. #define AES_AAD_STRING(s) \
  1788. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1789. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1790. enum en_aad_options {
  1791. AAD_SIZE_DEFAULT = 0x1U,
  1792. AAD_SIZE_ZERO = 0x2U,
  1793. AAD_SIZE_CUSTOM = 0x4U,
  1794. };
  1795. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1796. static word32 aes_aad_size = 0;
  1797. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1798. {
  1799. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1800. word32 options = aes_aad_options;
  1801. while(options) {
  1802. if (options & AAD_SIZE_DEFAULT) {
  1803. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1804. options &= ~(word32)AAD_SIZE_DEFAULT;
  1805. }
  1806. else if (options & AAD_SIZE_ZERO) {
  1807. aesAuthAddSz = 0;
  1808. options &= ~(word32)AAD_SIZE_ZERO;
  1809. }
  1810. else if (options & AAD_SIZE_CUSTOM) {
  1811. aesAuthAddSz = aes_aad_size;
  1812. options &= ~(word32)AAD_SIZE_CUSTOM;
  1813. }
  1814. fn(i);
  1815. aesAuthAddSz = aesAuthAddSz_orig;
  1816. }
  1817. }
  1818. #endif
  1819. #ifndef BENCH_CIPHER_ADD
  1820. #define BENCH_CIPHER_ADD 0
  1821. #endif
  1822. /* use kB instead of mB for embedded benchmarking */
  1823. #ifdef BENCH_EMBEDDED
  1824. #ifndef BENCH_NTIMES
  1825. #define BENCH_NTIMES 2
  1826. #endif
  1827. #ifndef BENCH_AGREETIMES
  1828. #define BENCH_AGREETIMES 2
  1829. #endif
  1830. enum BenchmarkBounds {
  1831. scryptCnt = 1,
  1832. ntimes = BENCH_NTIMES,
  1833. genTimes = BENCH_MAX_PENDING,
  1834. agreeTimes = BENCH_AGREETIMES
  1835. };
  1836. /* how many kB to test (en/de)cryption */
  1837. #define NUM_BLOCKS 25
  1838. #define BENCH_SIZE (1024uL)
  1839. #else
  1840. #ifndef BENCH_NTIMES
  1841. #define BENCH_NTIMES 100
  1842. #endif
  1843. #ifndef BENCH_AGREETIMES
  1844. #define BENCH_AGREETIMES 100
  1845. #endif
  1846. enum BenchmarkBounds {
  1847. scryptCnt = 10,
  1848. ntimes = BENCH_NTIMES,
  1849. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1850. agreeTimes = BENCH_AGREETIMES
  1851. };
  1852. /* how many megs to test (en/de)cryption */
  1853. #define NUM_BLOCKS 5
  1854. #define BENCH_SIZE (1024*1024uL)
  1855. #endif
  1856. static int numBlocks = NUM_BLOCKS;
  1857. static word32 bench_size = BENCH_SIZE;
  1858. static int base2 = 1;
  1859. static int digest_stream = 1;
  1860. #ifdef HAVE_CHACHA
  1861. static int encrypt_only = 0;
  1862. #endif
  1863. #ifdef HAVE_AES_CBC
  1864. static int cipher_same_buffer = 0;
  1865. #endif
  1866. #ifdef MULTI_VALUE_STATISTICS
  1867. static int minimum_runs = 0;
  1868. #endif
  1869. #ifndef NO_RSA
  1870. /* Don't measure RSA sign/verify by default */
  1871. static int rsa_sign_verify = 0;
  1872. #endif
  1873. #ifndef NO_DH
  1874. /* Use the FFDHE parameters */
  1875. static int use_ffdhe = 0;
  1876. #endif
  1877. /* Don't print out in CSV format by default */
  1878. static int csv_format = 0;
  1879. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1880. /* Versal PLM maybe prints an error message to the same console.
  1881. * In order to not mix those outputs up, sleep a little while
  1882. * before erroring out.
  1883. */
  1884. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1885. #else
  1886. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1887. #endif
  1888. /* globals for cipher tests */
  1889. static THREAD_LS_T byte* bench_plain = NULL;
  1890. static THREAD_LS_T byte* bench_cipher = NULL;
  1891. #ifndef NO_FILESYSTEM
  1892. static THREAD_LS_T char* hash_input = NULL;
  1893. static THREAD_LS_T char* cipher_input = NULL;
  1894. #endif
  1895. static const XGEN_ALIGN byte bench_key_buf[] =
  1896. {
  1897. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1898. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1899. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1900. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1901. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1902. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1903. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1904. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1905. };
  1906. static const XGEN_ALIGN byte bench_iv_buf[] =
  1907. {
  1908. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1909. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1910. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1911. };
  1912. static THREAD_LS_T byte* bench_key = NULL;
  1913. static THREAD_LS_T byte* bench_iv = NULL;
  1914. #ifdef HAVE_RENESAS_SYNC
  1915. static THREAD_LS_T byte* bench_key1 = NULL;
  1916. static THREAD_LS_T byte* bench_key2 = NULL;
  1917. #endif
  1918. #ifdef WOLFSSL_STATIC_MEMORY
  1919. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1920. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1921. #elif defined(BENCH_EMBEDDED)
  1922. static byte gBenchMemory[50000];
  1923. #else
  1924. static byte gBenchMemory[400000];
  1925. #endif
  1926. #endif
  1927. /* This code handles cases with systems where static (non cost) ram variables
  1928. aren't properly initialized with data */
  1929. static void benchmark_static_init(int force)
  1930. {
  1931. static int gBenchStaticInit = 0;
  1932. if (gBenchStaticInit == 0 || force) {
  1933. gBenchStaticInit = 1;
  1934. /* Init static variables */
  1935. numBlocks = NUM_BLOCKS;
  1936. bench_size = BENCH_SIZE;
  1937. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1938. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1939. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1940. aes_aad_size = 0;
  1941. #endif
  1942. base2 = 1;
  1943. digest_stream = 1;
  1944. #ifdef MULTI_VALUE_STATISTICS
  1945. minimum_runs = 0;
  1946. #endif
  1947. bench_all = 1;
  1948. bench_cipher_algs = 0;
  1949. bench_digest_algs = 0;
  1950. bench_mac_algs = 0;
  1951. bench_kdf_algs = 0;
  1952. bench_asym_algs = 0;
  1953. bench_pq_asym_algs = 0;
  1954. bench_other_algs = 0;
  1955. bench_pq_hash_sig_algs = 0;
  1956. csv_format = 0;
  1957. }
  1958. }
  1959. /*****************************************************************************/
  1960. /* Begin Stats Functions */
  1961. /*****************************************************************************/
  1962. typedef enum bench_stat_type {
  1963. BENCH_STAT_ASYM,
  1964. BENCH_STAT_SYM,
  1965. BENCH_STAT_IGNORE,
  1966. } bench_stat_type_t;
  1967. #ifdef WC_BENCH_TRACK_STATS
  1968. static int gPrintStats = 0;
  1969. #ifdef WC_ENABLE_BENCH_THREADING
  1970. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1971. #endif
  1972. #ifndef BENCH_MAX_NAME_SZ
  1973. #define BENCH_MAX_NAME_SZ 24
  1974. #endif
  1975. typedef struct bench_stats {
  1976. struct bench_stats* next;
  1977. struct bench_stats* prev;
  1978. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1979. const char* desc;
  1980. double perfsec;
  1981. int strength;
  1982. int useDeviceID;
  1983. int finishCount;
  1984. bench_stat_type_t type;
  1985. int lastRet;
  1986. const char* perftype;
  1987. } bench_stats_t;
  1988. static bench_stats_t* bench_stats_head;
  1989. static bench_stats_t* bench_stats_tail;
  1990. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1991. const char* algo, int strength, const char* desc, int useDeviceID,
  1992. double perfsec, const char* perftype, int ret)
  1993. {
  1994. bench_stats_t* bstat = NULL;
  1995. #ifdef WC_ENABLE_BENCH_THREADING
  1996. /* protect bench_stats_head and bench_stats_tail access */
  1997. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  1998. #endif
  1999. if (algo != NULL) {
  2000. /* locate existing in list */
  2001. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  2002. /* match based on algo, strength and desc */
  2003. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  2004. bstat->strength == strength &&
  2005. bstat->desc == desc &&
  2006. bstat->useDeviceID == useDeviceID) {
  2007. break;
  2008. }
  2009. }
  2010. }
  2011. if (bstat == NULL) {
  2012. /* allocate new and put on list */
  2013. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  2014. DYNAMIC_TYPE_INFO);
  2015. if (bstat) {
  2016. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  2017. /* add to list */
  2018. bstat->next = NULL;
  2019. if (bench_stats_tail == NULL) {
  2020. bench_stats_head = bstat;
  2021. }
  2022. else {
  2023. bench_stats_tail->next = bstat;
  2024. bstat->prev = bench_stats_tail;
  2025. }
  2026. bench_stats_tail = bstat; /* add to the end either way */
  2027. }
  2028. }
  2029. if (bstat) {
  2030. bstat->type = type;
  2031. if (algo != NULL)
  2032. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  2033. bstat->strength = strength;
  2034. bstat->desc = desc;
  2035. bstat->useDeviceID = useDeviceID;
  2036. bstat->perfsec += perfsec;
  2037. bstat->finishCount++;
  2038. bstat->perftype = perftype;
  2039. if (bstat->lastRet > ret)
  2040. bstat->lastRet = ret; /* track last error */
  2041. }
  2042. #ifdef WC_ENABLE_BENCH_THREADING
  2043. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2044. #endif
  2045. return bstat;
  2046. }
  2047. void bench_stats_print(void)
  2048. {
  2049. bench_stats_t* bstat;
  2050. int digits;
  2051. #ifdef WC_ENABLE_BENCH_THREADING
  2052. /* protect bench_stats_head and bench_stats_tail access */
  2053. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2054. #endif
  2055. #ifdef BENCH_MICROSECOND
  2056. digits = 5;
  2057. #else
  2058. digits = 3;
  2059. #endif
  2060. for (bstat = bench_stats_head; bstat != NULL; ) {
  2061. if (bstat->type == BENCH_STAT_SYM) {
  2062. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2063. "\n", bstat->desc,
  2064. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2065. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2066. base2 ? "MB" : "mB");
  2067. }
  2068. else {
  2069. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2070. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2071. bstat->algo, bstat->strength, bstat->desc,
  2072. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2073. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2074. }
  2075. bstat = bstat->next;
  2076. }
  2077. #ifdef WC_ENABLE_BENCH_THREADING
  2078. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2079. #endif
  2080. }
  2081. #endif /* WC_BENCH_TRACK_STATS */
  2082. static WC_INLINE void bench_stats_init(void)
  2083. {
  2084. #ifdef WC_BENCH_TRACK_STATS
  2085. bench_stats_head = NULL;
  2086. bench_stats_tail = NULL;
  2087. #endif
  2088. INIT_CYCLE_COUNTER
  2089. }
  2090. static WC_INLINE void bench_stats_start(int* count, double* start)
  2091. {
  2092. *count = 0;
  2093. *start = current_time(1);
  2094. #ifdef WOLFSSL_ESPIDF
  2095. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2096. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
  2097. ", start=" FLT_FMT,
  2098. total_cycles, FLT_FMT_ARGS(*start) );
  2099. #endif
  2100. BEGIN_ESP_CYCLES
  2101. #else
  2102. BEGIN_INTEL_CYCLES
  2103. #endif
  2104. }
  2105. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2106. #define bench_stats_start(count, start) do { \
  2107. SAVE_VECTOR_REGISTERS(pr_err( \
  2108. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2109. return; ); \
  2110. bench_stats_start(count, start); \
  2111. } while (0)
  2112. #endif
  2113. static WC_INLINE int bench_stats_check(double start)
  2114. {
  2115. int ret = 0;
  2116. double this_current_time = 0.0;
  2117. this_current_time = current_time(0); /* get the timestamp, no reset */
  2118. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2119. #if defined(WOLFSSL_ESPIDF)
  2120. ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
  2121. this_current_time, start );
  2122. #endif
  2123. #endif
  2124. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2125. #ifdef BENCH_MICROSECOND
  2126. * 1000000
  2127. #endif
  2128. );
  2129. return ret;
  2130. }
  2131. /* return text for units and scale the value of blocks as needed */
  2132. static const char* get_blocktype(double* blocks)
  2133. {
  2134. const char* rt;
  2135. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2136. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2137. #undef WOLFSSL_FIXED_UNIT
  2138. #define WOLFSSL_FIXED_UNIT "GB"
  2139. *blocks /= (1024UL * 1024UL * 1024UL);
  2140. rt = "GiB";
  2141. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2142. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2143. #undef WOLFSSL_FIXED_UNIT
  2144. #define WOLFSSL_FIXED_UNIT "MB"
  2145. *blocks /= (1024UL * 1024UL);
  2146. rt = "MiB";
  2147. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2148. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2149. #undef WOLFSSL_FIXED_UNIT
  2150. #define WOLFSSL_FIXED_UNIT "KB"
  2151. *blocks /= 1024;
  2152. rt = "KiB";
  2153. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2154. #undef WOLFSSL_FIXED_UNIT
  2155. #define WOLFSSL_FIXED_UNIT "bytes"
  2156. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2157. rt = "bytes";
  2158. #else
  2159. /* If no user-specified, auto-scale each metric (results vary).
  2160. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2161. if (*blocks > (1024UL * 1024UL)) {
  2162. *blocks /= (1024UL * 1024UL);
  2163. rt = "MiB";
  2164. }
  2165. else if (*blocks > 1024) {
  2166. *blocks /= 1024;
  2167. rt = "KiB";
  2168. }
  2169. else {
  2170. rt = "bytes";
  2171. }
  2172. #endif
  2173. return rt;
  2174. }
  2175. /* return text for units and scale the value of blocks as needed for base2 */
  2176. static const char* get_blocktype_base10(double* blocks)
  2177. {
  2178. const char* rt;
  2179. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2180. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2181. *blocks /= (1000UL * 1000UL * 1000UL);
  2182. rt = "GB";
  2183. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2184. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2185. *blocks /= (1000UL * 1000UL);
  2186. rt = "MB";
  2187. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2188. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2189. *blocks /= (1000UL);
  2190. rt = "KB";
  2191. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2192. (void)(*blocks); /* no adjustment, just appease compiler */
  2193. rt = "bytes";
  2194. #else
  2195. /* If not user-specified, auto-scale each metric (results vary).
  2196. * Determine if we should show as KB or MB or bytes */
  2197. if (*blocks > (1000UL * 1000UL)) {
  2198. *blocks /= (1000UL * 1000UL);
  2199. rt = "MB";
  2200. }
  2201. else if (*blocks > 1000) {
  2202. *blocks /= 1000; /* make KB */
  2203. rt = "KB";
  2204. }
  2205. else {
  2206. rt = "bytes";
  2207. }
  2208. #endif
  2209. return rt;
  2210. }
  2211. #ifdef MULTI_VALUE_STATISTICS
  2212. static double wc_sqroot(double in)
  2213. {
  2214. /* do 32 iterations for the sqroot */
  2215. int iter = 32;
  2216. double root = in/3.0;
  2217. if (in < 0.0)
  2218. return -1;
  2219. for (int i=0; i < iter; i++)
  2220. root = (root + in / root) / 2.0;
  2221. return root;
  2222. }
  2223. static void bench_multi_value_stats(double max, double min, double sum,
  2224. double squareSum, int runs)
  2225. {
  2226. double mean = 0;
  2227. double sd = 0;
  2228. char msg[WC_BENCH_MAX_LINE_LEN];
  2229. const char** word = bench_result_words3[lng_index];
  2230. XMEMSET(msg, 0, sizeof(msg));
  2231. mean = sum / runs;
  2232. /* Calculating standard deviation */
  2233. sd = (squareSum / runs) - (mean * mean);
  2234. sd = wc_sqroot(sd);
  2235. if (csv_format == 1) {
  2236. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2237. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2238. FLT_FMT_PREC2_ARGS(3, 3, max),
  2239. FLT_FMT_PREC2_ARGS(3, 3, min),
  2240. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2241. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2242. }
  2243. else{
  2244. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2245. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2246. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2247. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2248. WOLFSSL_FIXED_TIME_UNIT "\n",
  2249. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2250. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2251. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2252. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2253. }
  2254. printf("%s", msg);
  2255. #ifndef WOLFSSL_SGX
  2256. XFFLUSH(stdout);
  2257. #endif
  2258. }
  2259. #endif
  2260. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2261. * except for AES direct that operates on AES_BLOCK_SIZE blocks */
  2262. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2263. int count, word32 countSz,
  2264. double start, int ret)
  2265. {
  2266. double total, persec = 0, blocks = (double)count;
  2267. const char* blockType;
  2268. char msg[WC_BENCH_MAX_LINE_LEN];
  2269. const char** word = bench_result_words1[lng_index];
  2270. static int sym_header_printed = 0;
  2271. XMEMSET(msg, 0, sizeof(msg));
  2272. #ifdef WOLFSSL_ESPIDF
  2273. END_ESP_CYCLES
  2274. #else
  2275. END_INTEL_CYCLES
  2276. #endif
  2277. total = current_time(0) - start;
  2278. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2279. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2280. #endif
  2281. #ifdef LINUX_RUSAGE_UTIME
  2282. check_for_excessive_stime(desc, "");
  2283. #endif
  2284. /* calculate actual bytes */
  2285. blocks *= countSz;
  2286. if (csv_format == 1) {
  2287. /* only print out header once */
  2288. if (sym_header_printed == 0) {
  2289. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2290. /* machine parseable CSV */
  2291. #ifdef HAVE_GET_CYCLES
  2292. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2293. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2294. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2295. ",cycles_total,Cycles per byte,");
  2296. #else
  2297. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2298. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2299. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2300. ",cycles_total,");
  2301. #endif
  2302. #else
  2303. /* normal CSV */
  2304. #ifdef BENCH_DEVID
  2305. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2306. #else
  2307. #define BENCH_DEVID_COLUMN_HEADER
  2308. #endif
  2309. #ifdef HAVE_GET_CYCLES
  2310. printf("\n\nSymmetric Ciphers:\n\n");
  2311. printf("Algorithm,"
  2312. BENCH_DEVID_COLUMN_HEADER
  2313. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2314. ",Cycles per byte,");
  2315. #else
  2316. printf("\n\nSymmetric Ciphers:\n\n");
  2317. printf("Algorithm,"
  2318. BENCH_DEVID_COLUMN_HEADER
  2319. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2320. #endif
  2321. #endif
  2322. #ifdef MULTI_VALUE_STATISTICS
  2323. printf("max duration,min duration,mean duration,sd,\n");
  2324. #else
  2325. printf("\n");
  2326. #endif
  2327. sym_header_printed = 1;
  2328. }
  2329. }
  2330. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2331. * note that the blockType text is assigned AND the blocks param is scaled.
  2332. */
  2333. if (base2) {
  2334. blockType = get_blocktype(&blocks);
  2335. }
  2336. else {
  2337. blockType = get_blocktype_base10(&blocks);
  2338. }
  2339. /* calculate blocks per second */
  2340. if (total > 0) {
  2341. persec = (1 / total) * blocks;
  2342. }
  2343. SLEEP_ON_ERROR(ret);
  2344. /* format and print to terminal */
  2345. if (csv_format == 1) {
  2346. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2347. #ifdef WOLFSSL_ESPIDF
  2348. unsigned long bytes_processed =
  2349. (unsigned long)count * (unsigned long)countSz;
  2350. #else
  2351. word64 bytes_processed = (word64)count * (word64)countSz;
  2352. #endif
  2353. /* note this codepath brings in all the fields from the non-CSV case. */
  2354. #ifdef WOLFSSL_ESPIDF
  2355. #ifdef HAVE_GET_CYCLES
  2356. (void)XSNPRINTF(msg, sizeof(msg),
  2357. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2358. BENCH_DEVID_GET_NAME(useDeviceID),
  2359. bytes_processed, FLT_FMT_ARGS(total),
  2360. FLT_FMT_ARGS(persec),
  2361. (long unsigned int) total_cycles);
  2362. #else
  2363. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2364. #endif
  2365. /* implement other architectures here */
  2366. #else
  2367. #ifdef HAVE_GET_CYCLES
  2368. (void)XSNPRINTF(msg, sizeof(msg),
  2369. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2370. BENCH_DEVID_GET_NAME(useDeviceID),
  2371. bytes_processed, FLT_FMT_ARGS(total),
  2372. FLT_FMT_ARGS(persec), total_cycles);
  2373. #else
  2374. (void)XSNPRINTF(msg, sizeof(msg),
  2375. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2376. BENCH_DEVID_GET_NAME(useDeviceID),
  2377. bytes_processed, FLT_FMT_ARGS(total),
  2378. FLT_FMT_ARGS(persec));
  2379. #endif
  2380. #endif
  2381. #elif defined(BENCH_DEVID)
  2382. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2383. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2384. #else
  2385. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2386. FLT_FMT_ARGS(persec));
  2387. #endif
  2388. #ifdef WOLFSSL_ESPIDF
  2389. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2390. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2391. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2392. total_cycles);
  2393. #endif
  2394. /* implement other cycle counters here */
  2395. #else
  2396. /* the default cycle counter is Intel */
  2397. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2398. #endif
  2399. } /* if (csv_format == 1) */
  2400. else {
  2401. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2402. #ifdef HAVE_GET_CYCLES
  2403. (void)XSNPRINTF(msg, sizeof(msg),
  2404. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2405. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2406. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2407. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2408. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2409. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2410. (unsigned long) total_cycles);
  2411. #else
  2412. (void)XSNPRINTF(msg, sizeof(msg),
  2413. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2414. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2415. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2416. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2417. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2418. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2419. #endif /* HAVE_GET_CYCLES */
  2420. #else
  2421. (void)XSNPRINTF(msg, sizeof(msg),
  2422. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2423. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2424. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2425. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2426. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2427. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2428. #endif
  2429. #ifdef WOLFSSL_ESPIDF
  2430. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2431. /* implement other architecture cycle counters here */
  2432. #else
  2433. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2434. #endif
  2435. } /* not CSV format */
  2436. printf("%s", msg);
  2437. /* show errors */
  2438. if (ret < 0) {
  2439. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2440. }
  2441. #ifndef WOLFSSL_SGX
  2442. XFFLUSH(stdout);
  2443. #endif
  2444. #ifdef WC_BENCH_TRACK_STATS
  2445. /* Add to thread stats */
  2446. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2447. blockType, ret);
  2448. #endif
  2449. (void)useDeviceID;
  2450. (void)ret;
  2451. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2452. RESTORE_VECTOR_REGISTERS();
  2453. #endif
  2454. TEST_SLEEP();
  2455. } /* bench_stats_sym_finish */
  2456. #ifdef BENCH_ASYM
  2457. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2458. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2459. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2460. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  2461. defined(WOLFSSL_HAVE_LMS)
  2462. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2463. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2464. double start, int ret)
  2465. {
  2466. double total, each = 0, opsSec, milliEach;
  2467. const char **word = bench_result_words2[lng_index];
  2468. #ifdef WC_BENCH_TRACK_STATS
  2469. const char* kOpsSec = "Ops/Sec";
  2470. #endif
  2471. char msg[256];
  2472. static int asym_header_printed = 0;
  2473. #ifdef BENCH_MICROSECOND
  2474. const int digits = 5;
  2475. #else
  2476. const int digits = 3;
  2477. #endif
  2478. XMEMSET(msg, 0, sizeof(msg));
  2479. total = current_time(0) - start;
  2480. #ifdef LINUX_RUSAGE_UTIME
  2481. check_for_excessive_stime(desc, desc_extra);
  2482. #endif
  2483. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2484. #ifdef WOLFSSL_ESPIDF
  2485. END_ESP_CYCLES
  2486. #else
  2487. END_INTEL_CYCLES
  2488. #endif
  2489. #endif
  2490. /* some sanity checks on the final numbers */
  2491. if (count > 0) {
  2492. each = total / count; /* per second */
  2493. }
  2494. else {
  2495. count = 0;
  2496. each = 0;
  2497. }
  2498. if (total > 0) {
  2499. opsSec = count / total; /* ops second */
  2500. }
  2501. else {
  2502. opsSec = 0;
  2503. }
  2504. #ifdef BENCH_MICROSECOND
  2505. milliEach = each / 1000; /* milliseconds */
  2506. #else
  2507. milliEach = each * 1000; /* milliseconds */
  2508. #endif
  2509. SLEEP_ON_ERROR(ret);
  2510. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2511. (void)milliEach;
  2512. /* format and print to terminal */
  2513. if (csv_format == 1) {
  2514. /* only print out header once */
  2515. if (asym_header_printed == 0) {
  2516. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2517. #ifdef HAVE_GET_CYCLES
  2518. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2519. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2520. "ecs,cycles,cycles/op,");
  2521. #else
  2522. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2523. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2524. "ecs,");
  2525. #endif
  2526. #else
  2527. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2528. printf("%sAlgorithm,key size,operation,ops/"
  2529. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2530. #endif
  2531. printf("max duration,min duration,mean duration,sd,\n");
  2532. asym_header_printed = 1;
  2533. }
  2534. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2535. #ifdef HAVE_GET_CYCLES
  2536. (void)XSNPRINTF(msg, sizeof(msg),
  2537. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2538. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2539. algo, strength, desc, desc_extra,
  2540. FLT_FMT_PREC_ARGS(digits, opsSec),
  2541. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2542. FLT_FMT_PREC_ARGS(6,
  2543. (double)total_cycles / (double)count));
  2544. #else
  2545. (void)XSNPRINTF(msg, sizeof(msg),
  2546. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2547. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2548. algo, strength, desc, desc_extra,
  2549. FLT_FMT_PREC_ARGS(digits, opsSec),
  2550. count, FLT_FMT_ARGS(total));
  2551. #endif
  2552. #else
  2553. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2554. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2555. algo, strength, desc, desc_extra,
  2556. FLT_FMT_PREC_ARGS(digits, opsSec));
  2557. #endif
  2558. } /* if (csv_format == 1) */
  2559. else {
  2560. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2561. #ifdef HAVE_GET_CYCLES
  2562. (void)XSNPRINTF(msg, sizeof(msg),
  2563. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2564. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2565. algo, strength, desc, desc_extra,
  2566. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2567. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2568. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2569. (unsigned long)total_cycles);
  2570. #else
  2571. (void)XSNPRINTF(msg, sizeof(msg),
  2572. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2573. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2574. algo, strength, desc, desc_extra,
  2575. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2576. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2577. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2578. #endif /* HAVE_GET_CYCLES */
  2579. #else
  2580. (void)XSNPRINTF(msg, sizeof(msg),
  2581. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2582. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2583. algo, strength, desc, desc_extra,
  2584. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2585. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2586. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2587. #endif
  2588. }
  2589. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2590. /* format and print to terminal */
  2591. if (csv_format == 1) {
  2592. /* only print out header once */
  2593. if (asym_header_printed == 0) {
  2594. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2595. #ifdef HAVE_GET_CYCLES
  2596. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2597. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2598. "ecs,cycles,cycles/op,");
  2599. #else
  2600. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2601. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2602. "ecs,");
  2603. #endif
  2604. #else
  2605. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2606. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2607. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2608. #endif
  2609. printf("\n");
  2610. asym_header_printed = 1;
  2611. }
  2612. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2613. #ifdef HAVE_GET_CYCLES
  2614. (void)XSNPRINTF(msg, sizeof(msg),
  2615. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2616. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2617. algo, strength, desc, desc_extra,
  2618. FLT_FMT_PREC_ARGS(3, milliEach),
  2619. FLT_FMT_PREC_ARGS(digits, opsSec),
  2620. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2621. FLT_FMT_PREC_ARGS(6,
  2622. (double)total_cycles / (double)count));
  2623. #else
  2624. (void)XSNPRINTF(msg, sizeof(msg),
  2625. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2626. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2627. algo, strength, desc, desc_extra,
  2628. FLT_FMT_PREC_ARGS(3, milliEach),
  2629. FLT_FMT_PREC_ARGS(digits, opsSec),
  2630. count, FLT_FMT_ARGS(total));
  2631. #endif
  2632. #else
  2633. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2634. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2635. algo, strength, desc, desc_extra,
  2636. FLT_FMT_PREC_ARGS(3, milliEach),
  2637. FLT_FMT_PREC_ARGS(digits, opsSec));
  2638. #endif
  2639. } /* if (csv_format == 1) */
  2640. else {
  2641. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2642. #ifdef HAVE_GET_CYCLES
  2643. (void)XSNPRINTF(msg, sizeof(msg),
  2644. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2645. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2646. STATS_CLAUSE_SEPARATOR,
  2647. algo, strength, desc, desc_extra,
  2648. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2649. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2650. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2651. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2652. (unsigned long)total_cycles);
  2653. #else
  2654. (void)XSNPRINTF(msg, sizeof(msg),
  2655. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2656. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2657. STATS_CLAUSE_SEPARATOR,
  2658. algo, strength, desc, desc_extra,
  2659. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2660. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2661. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2662. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2663. #endif /* HAVE_GET_CYCLES */
  2664. #else
  2665. (void)XSNPRINTF(msg, sizeof(msg),
  2666. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2667. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2668. STATS_CLAUSE_SEPARATOR,
  2669. algo, strength, desc, desc_extra,
  2670. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2671. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2672. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2673. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2674. #endif
  2675. }
  2676. #endif /* MULTI_VALUE_STATISTICS */
  2677. printf("%s", msg);
  2678. /* show errors */
  2679. if (ret < 0) {
  2680. printf("%sBenchmark %s %s %d failed: %d\n",
  2681. err_prefix, algo, desc, strength, ret);
  2682. }
  2683. #ifndef WOLFSSL_SGX
  2684. XFFLUSH(stdout);
  2685. #endif
  2686. #ifdef WC_BENCH_TRACK_STATS
  2687. /* Add to thread stats */
  2688. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2689. kOpsSec, ret);
  2690. #endif
  2691. (void)useDeviceID;
  2692. (void)ret;
  2693. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2694. RESTORE_VECTOR_REGISTERS();
  2695. #endif
  2696. TEST_SLEEP();
  2697. } /* bench_stats_asym_finish_ex */
  2698. static void bench_stats_asym_finish(const char* algo, int strength,
  2699. const char* desc, int useDeviceID, int count, double start, int ret)
  2700. {
  2701. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2702. start, ret);
  2703. }
  2704. #endif
  2705. #endif /* BENCH_ASYM */
  2706. static WC_INLINE void bench_stats_free(void)
  2707. {
  2708. #ifdef WC_BENCH_TRACK_STATS
  2709. bench_stats_t* bstat;
  2710. for (bstat = bench_stats_head; bstat != NULL; ) {
  2711. bench_stats_t* next = bstat->next;
  2712. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2713. bstat = next;
  2714. }
  2715. bench_stats_head = NULL;
  2716. bench_stats_tail = NULL;
  2717. #endif
  2718. }
  2719. /*****************************************************************************/
  2720. /* End Stats Functions */
  2721. /*****************************************************************************/
  2722. static void* benchmarks_do(void* args)
  2723. {
  2724. long bench_buf_size;
  2725. #ifdef WOLFSSL_ASYNC_CRYPT
  2726. #ifndef WC_NO_ASYNC_THREADING
  2727. ThreadData* threadData = (ThreadData*)args;
  2728. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2729. #else
  2730. if (wolfAsync_DevOpen(&devId) < 0)
  2731. #endif
  2732. {
  2733. printf("%sAsync device open failed\n%sRunning without async\n",
  2734. err_prefix, err_prefix);
  2735. }
  2736. #endif /* WOLFSSL_ASYNC_CRYPT */
  2737. (void)args;
  2738. #ifdef WOLFSSL_ASYNC_CRYPT
  2739. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2740. printf("%sAsync event queue init failure!\n", err_prefix);
  2741. }
  2742. #endif
  2743. #ifdef WOLF_CRYPTO_CB
  2744. #ifdef HAVE_INTEL_QA_SYNC
  2745. devId = wc_CryptoCb_InitIntelQa();
  2746. if (devId == INVALID_DEVID) {
  2747. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2748. }
  2749. #endif
  2750. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2751. devId = wc_CryptoCb_InitOcteon();
  2752. if (devId == INVALID_DEVID) {
  2753. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2754. }
  2755. #endif
  2756. #ifdef HAVE_RENESAS_SYNC
  2757. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2758. if (devId == INVALID_DEVID) {
  2759. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2760. }
  2761. #endif
  2762. #endif
  2763. #if defined(HAVE_LOCAL_RNG)
  2764. {
  2765. int rngRet;
  2766. #ifndef HAVE_FIPS
  2767. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2768. #else
  2769. rngRet = wc_InitRng(&gRng);
  2770. #endif
  2771. if (rngRet < 0) {
  2772. printf("%sInitRNG failed\n", err_prefix);
  2773. return NULL;
  2774. }
  2775. }
  2776. #endif
  2777. /* setup bench plain, cipher, key and iv globals */
  2778. /* make sure bench buffer is multiple of 16 (AES block size) */
  2779. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2780. if (bench_buf_size % 16)
  2781. bench_buf_size += 16 - (bench_buf_size % 16);
  2782. #ifdef WOLFSSL_AFALG_XILINX_AES
  2783. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2784. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2785. #else
  2786. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2787. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2788. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2789. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2790. #endif
  2791. if (bench_plain == NULL || bench_cipher == NULL) {
  2792. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2793. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2794. bench_plain = bench_cipher = NULL;
  2795. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2796. goto exit;
  2797. }
  2798. #ifndef NO_FILESYSTEM
  2799. if (hash_input) {
  2800. size_t rawSz;
  2801. XFILE file;
  2802. file = XFOPEN(hash_input, "rb");
  2803. if (file == XBADFILE)
  2804. goto exit;
  2805. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2806. XFCLOSE(file);
  2807. goto exit;
  2808. }
  2809. bench_buf_size = XFTELL(file);
  2810. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2811. XFCLOSE(file);
  2812. goto exit;
  2813. }
  2814. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2815. rawSz = (size_t)bench_buf_size;
  2816. if (bench_buf_size % 16)
  2817. bench_buf_size += 16 - (bench_buf_size % 16);
  2818. bench_size = (word32)bench_buf_size;
  2819. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2820. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2821. if (bench_plain == NULL) {
  2822. XFCLOSE(file);
  2823. goto exit;
  2824. }
  2825. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2826. != rawSz) {
  2827. XFCLOSE(file);
  2828. goto exit;
  2829. }
  2830. XFCLOSE(file);
  2831. }
  2832. else {
  2833. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2834. }
  2835. if (cipher_input) {
  2836. size_t rawSz;
  2837. XFILE file;
  2838. file = XFOPEN(cipher_input, "rb");
  2839. if (file == XBADFILE)
  2840. goto exit;
  2841. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2842. XFCLOSE(file);
  2843. goto exit;
  2844. }
  2845. bench_buf_size = XFTELL(file);
  2846. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2847. XFCLOSE(file);
  2848. goto exit;
  2849. }
  2850. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2851. rawSz = (size_t)bench_buf_size;
  2852. if (bench_buf_size % 16)
  2853. bench_buf_size += 16 - (bench_buf_size % 16);
  2854. if (bench_size > (word32)bench_buf_size)
  2855. bench_size = (word32)bench_buf_size;
  2856. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2857. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2858. if (bench_cipher == NULL) {
  2859. XFCLOSE(file);
  2860. goto exit;
  2861. }
  2862. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2863. != rawSz) {
  2864. XFCLOSE(file);
  2865. goto exit;
  2866. }
  2867. XFCLOSE(file);
  2868. }
  2869. else {
  2870. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2871. }
  2872. #endif
  2873. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2874. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2875. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2876. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2877. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2878. if (bench_key == NULL || bench_iv == NULL) {
  2879. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2880. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2881. bench_key = bench_iv = NULL;
  2882. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2883. goto exit;
  2884. }
  2885. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2886. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2887. #elif defined(HAVE_RENESAS_SYNC)
  2888. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2889. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2890. bench_key = (byte*)bench_key_buf;
  2891. bench_iv = (byte*)bench_iv_buf;
  2892. #else
  2893. bench_key = (byte*)bench_key_buf;
  2894. bench_iv = (byte*)bench_iv_buf;
  2895. #endif
  2896. #ifndef WC_NO_RNG
  2897. if (bench_all || (bench_other_algs & BENCH_RNG))
  2898. bench_rng();
  2899. #endif /* WC_NO_RNG */
  2900. #ifndef NO_AES
  2901. #ifdef HAVE_AES_CBC
  2902. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2903. #ifndef NO_SW_BENCH
  2904. bench_aescbc(0);
  2905. #endif
  2906. #if defined(BENCH_DEVID)
  2907. bench_aescbc(1);
  2908. #endif
  2909. }
  2910. #endif
  2911. #ifdef HAVE_AESGCM
  2912. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2913. #ifndef NO_SW_BENCH
  2914. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2915. #endif
  2916. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2917. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2918. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2919. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2920. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2921. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2922. #endif
  2923. #ifndef NO_SW_BENCH
  2924. bench_gmac(0);
  2925. #endif
  2926. #if defined(BENCH_DEVID)
  2927. bench_gmac(1);
  2928. #endif
  2929. }
  2930. #endif
  2931. #ifdef HAVE_AES_ECB
  2932. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2933. #ifndef NO_SW_BENCH
  2934. bench_aesecb(0);
  2935. #endif
  2936. #ifdef BENCH_DEVID
  2937. bench_aesecb(1);
  2938. #endif
  2939. }
  2940. #endif
  2941. #ifdef WOLFSSL_AES_XTS
  2942. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2943. bench_aesxts();
  2944. #endif
  2945. #ifdef WOLFSSL_AES_CFB
  2946. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2947. bench_aescfb();
  2948. #endif
  2949. #ifdef WOLFSSL_AES_OFB
  2950. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2951. bench_aesofb();
  2952. #endif
  2953. #ifdef WOLFSSL_AES_COUNTER
  2954. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2955. bench_aesctr(0);
  2956. #ifdef BENCH_DEVID
  2957. bench_aesctr(1);
  2958. #endif
  2959. }
  2960. #endif
  2961. #ifdef HAVE_AESCCM
  2962. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2963. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2964. #ifdef BENCH_DEVID
  2965. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2966. #endif
  2967. }
  2968. #endif
  2969. #ifdef WOLFSSL_AES_SIV
  2970. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2971. bench_aessiv();
  2972. #endif
  2973. #endif /* !NO_AES */
  2974. #ifdef HAVE_CAMELLIA
  2975. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2976. bench_camellia();
  2977. #endif
  2978. #ifdef WOLFSSL_SM4_CBC
  2979. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2980. bench_sm4_cbc();
  2981. #endif
  2982. #ifdef WOLFSSL_SM4_GCM
  2983. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2984. bench_sm4_gcm();
  2985. #endif
  2986. #ifdef WOLFSSL_SM4_CCM
  2987. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2988. bench_sm4_ccm();
  2989. #endif
  2990. #ifndef NO_RC4
  2991. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2992. #ifndef NO_SW_BENCH
  2993. bench_arc4(0);
  2994. #endif
  2995. #ifdef BENCH_DEVID
  2996. bench_arc4(1);
  2997. #endif
  2998. }
  2999. #endif
  3000. #ifdef HAVE_CHACHA
  3001. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  3002. bench_chacha();
  3003. #endif
  3004. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  3005. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  3006. bench_chacha20_poly1305_aead();
  3007. #endif
  3008. #ifndef NO_DES3
  3009. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  3010. #ifndef NO_SW_BENCH
  3011. bench_des(0);
  3012. #endif
  3013. #ifdef BENCH_DEVID
  3014. bench_des(1);
  3015. #endif
  3016. }
  3017. #endif
  3018. #ifndef NO_MD5
  3019. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  3020. #ifndef NO_SW_BENCH
  3021. bench_md5(0);
  3022. #endif
  3023. #ifdef BENCH_DEVID
  3024. bench_md5(1);
  3025. #endif
  3026. }
  3027. #endif
  3028. #ifdef HAVE_POLY1305
  3029. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  3030. bench_poly1305();
  3031. #endif
  3032. #ifndef NO_SHA
  3033. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  3034. #ifndef NO_SW_BENCH
  3035. bench_sha(0);
  3036. #endif
  3037. #ifdef BENCH_DEVID
  3038. bench_sha(1);
  3039. #endif
  3040. }
  3041. #endif
  3042. #ifdef WOLFSSL_SHA224
  3043. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  3044. #ifndef NO_SW_BENCH
  3045. bench_sha224(0);
  3046. #endif
  3047. #ifdef BENCH_DEVID
  3048. bench_sha224(1);
  3049. #endif
  3050. }
  3051. #endif
  3052. #ifndef NO_SHA256
  3053. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  3054. #ifndef NO_SW_BENCH
  3055. bench_sha256(0);
  3056. #endif
  3057. #ifdef BENCH_DEVID
  3058. bench_sha256(1);
  3059. #endif
  3060. }
  3061. #endif
  3062. #ifdef WOLFSSL_SHA384
  3063. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3064. #ifndef NO_SW_BENCH
  3065. bench_sha384(0);
  3066. #endif
  3067. #ifdef BENCH_DEVID
  3068. bench_sha384(1);
  3069. #endif
  3070. }
  3071. #endif
  3072. #ifdef WOLFSSL_SHA512
  3073. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3074. #ifndef NO_SW_BENCH
  3075. bench_sha512(0);
  3076. #endif
  3077. #ifdef BENCH_DEVID
  3078. bench_sha512(1);
  3079. #endif
  3080. }
  3081. #if !defined(WOLFSSL_NOSHA512_224) && \
  3082. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3083. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3084. #ifndef NO_SW_BENCH
  3085. bench_sha512_224(0);
  3086. #endif
  3087. #ifdef BENCH_DEVID
  3088. bench_sha512_224(1);
  3089. #endif
  3090. }
  3091. #endif /* WOLFSSL_NOSHA512_224 */
  3092. #if !defined(WOLFSSL_NOSHA512_256) && \
  3093. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3094. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3095. #ifndef NO_SW_BENCH
  3096. bench_sha512_256(0);
  3097. #endif
  3098. #ifdef BENCH_DEVID
  3099. bench_sha512_256(1);
  3100. #endif
  3101. }
  3102. #endif /* WOLFSSL_NOSHA512_256 */
  3103. #endif /* WOLFSSL_SHA512 */
  3104. #ifdef WOLFSSL_SHA3
  3105. #ifndef WOLFSSL_NOSHA3_224
  3106. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3107. #ifndef NO_SW_BENCH
  3108. bench_sha3_224(0);
  3109. #endif
  3110. #ifdef BENCH_DEVID
  3111. bench_sha3_224(1);
  3112. #endif
  3113. }
  3114. #endif /* WOLFSSL_NOSHA3_224 */
  3115. #ifndef WOLFSSL_NOSHA3_256
  3116. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3117. #ifndef NO_SW_BENCH
  3118. bench_sha3_256(0);
  3119. #endif
  3120. #ifdef BENCH_DEVID
  3121. bench_sha3_256(1);
  3122. #endif
  3123. }
  3124. #endif /* WOLFSSL_NOSHA3_256 */
  3125. #ifndef WOLFSSL_NOSHA3_384
  3126. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3127. #ifndef NO_SW_BENCH
  3128. bench_sha3_384(0);
  3129. #endif
  3130. #ifdef BENCH_DEVID
  3131. bench_sha3_384(1);
  3132. #endif
  3133. }
  3134. #endif /* WOLFSSL_NOSHA3_384 */
  3135. #ifndef WOLFSSL_NOSHA3_512
  3136. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3137. #ifndef NO_SW_BENCH
  3138. bench_sha3_512(0);
  3139. #endif
  3140. #ifdef BENCH_DEVID
  3141. bench_sha3_512(1);
  3142. #endif
  3143. }
  3144. #endif /* WOLFSSL_NOSHA3_512 */
  3145. #ifdef WOLFSSL_SHAKE128
  3146. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3147. #ifndef NO_SW_BENCH
  3148. bench_shake128(0);
  3149. #endif
  3150. #ifdef BENCH_DEVID
  3151. bench_shake128(1);
  3152. #endif
  3153. }
  3154. #endif /* WOLFSSL_SHAKE128 */
  3155. #ifdef WOLFSSL_SHAKE256
  3156. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3157. #ifndef NO_SW_BENCH
  3158. bench_shake256(0);
  3159. #endif
  3160. #ifdef BENCH_DEVID
  3161. bench_shake256(1);
  3162. #endif
  3163. }
  3164. #endif /* WOLFSSL_SHAKE256 */
  3165. #endif
  3166. #ifdef WOLFSSL_SM3
  3167. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3168. #ifndef NO_SW_BENCH
  3169. bench_sm3(0);
  3170. #endif
  3171. #ifdef BENCH_DEVID
  3172. bench_sm3(1);
  3173. #endif
  3174. }
  3175. #endif
  3176. #ifdef WOLFSSL_RIPEMD
  3177. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3178. bench_ripemd();
  3179. #endif
  3180. #ifdef HAVE_BLAKE2
  3181. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3182. bench_blake2b();
  3183. #endif
  3184. #ifdef HAVE_BLAKE2S
  3185. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3186. bench_blake2s();
  3187. #endif
  3188. #ifdef WOLFSSL_CMAC
  3189. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3190. bench_cmac(0);
  3191. #ifdef BENCH_DEVID
  3192. bench_cmac(1);
  3193. #endif
  3194. }
  3195. #endif
  3196. #ifndef NO_HMAC
  3197. #ifndef NO_MD5
  3198. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3199. #ifndef NO_SW_BENCH
  3200. bench_hmac_md5(0);
  3201. #endif
  3202. #ifdef BENCH_DEVID
  3203. bench_hmac_md5(1);
  3204. #endif
  3205. }
  3206. #endif
  3207. #ifndef NO_SHA
  3208. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3209. #ifndef NO_SW_BENCH
  3210. bench_hmac_sha(0);
  3211. #endif
  3212. #ifdef BENCH_DEVID
  3213. bench_hmac_sha(1);
  3214. #endif
  3215. }
  3216. #endif
  3217. #ifdef WOLFSSL_SHA224
  3218. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3219. #ifndef NO_SW_BENCH
  3220. bench_hmac_sha224(0);
  3221. #endif
  3222. #ifdef BENCH_DEVID
  3223. bench_hmac_sha224(1);
  3224. #endif
  3225. }
  3226. #endif
  3227. #ifndef NO_SHA256
  3228. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3229. #ifndef NO_SW_BENCH
  3230. bench_hmac_sha256(0);
  3231. #endif
  3232. #ifdef BENCH_DEVID
  3233. bench_hmac_sha256(1);
  3234. #endif
  3235. }
  3236. #endif
  3237. #ifdef WOLFSSL_SHA384
  3238. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3239. #ifndef NO_SW_BENCH
  3240. bench_hmac_sha384(0);
  3241. #endif
  3242. #ifdef BENCH_DEVID
  3243. bench_hmac_sha384(1);
  3244. #endif
  3245. }
  3246. #endif
  3247. #ifdef WOLFSSL_SHA512
  3248. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3249. #ifndef NO_SW_BENCH
  3250. bench_hmac_sha512(0);
  3251. #endif
  3252. #ifdef BENCH_DEVID
  3253. bench_hmac_sha512(1);
  3254. #endif
  3255. }
  3256. #endif
  3257. #ifndef NO_PWDBASED
  3258. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3259. bench_pbkdf2();
  3260. }
  3261. #endif
  3262. #endif /* NO_HMAC */
  3263. #ifdef WOLFSSL_SIPHASH
  3264. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3265. bench_siphash();
  3266. }
  3267. #endif
  3268. #ifdef WC_SRTP_KDF
  3269. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3270. bench_srtpkdf();
  3271. }
  3272. #endif
  3273. #ifdef HAVE_SCRYPT
  3274. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3275. bench_scrypt();
  3276. #endif
  3277. #ifndef NO_RSA
  3278. #ifndef HAVE_RENESAS_SYNC
  3279. #ifdef WOLFSSL_KEY_GEN
  3280. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3281. #ifndef NO_SW_BENCH
  3282. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3283. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3284. bench_rsaKeyGen(0);
  3285. }
  3286. else {
  3287. bench_rsaKeyGen_size(0, bench_size);
  3288. }
  3289. #endif
  3290. #ifdef BENCH_DEVID
  3291. if (bench_asym_algs & BENCH_RSA_SZ) {
  3292. bench_rsaKeyGen_size(1, bench_size);
  3293. }
  3294. else {
  3295. bench_rsaKeyGen(1);
  3296. }
  3297. #endif
  3298. }
  3299. #endif
  3300. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3301. #ifndef NO_SW_BENCH
  3302. bench_rsa(0);
  3303. #endif
  3304. #ifdef BENCH_DEVID
  3305. bench_rsa(1);
  3306. #endif
  3307. }
  3308. #ifdef WOLFSSL_KEY_GEN
  3309. if (bench_asym_algs & BENCH_RSA_SZ) {
  3310. #ifndef NO_SW_BENCH
  3311. bench_rsa_key(0, bench_size);
  3312. #endif
  3313. #ifdef BENCH_DEVID
  3314. bench_rsa_key(1, bench_size);
  3315. #endif
  3316. }
  3317. #endif
  3318. #endif
  3319. #endif
  3320. #ifndef NO_DH
  3321. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3322. #ifndef NO_SW_BENCH
  3323. bench_dh(0);
  3324. #endif
  3325. #ifdef BENCH_DEVID
  3326. bench_dh(1);
  3327. #endif
  3328. }
  3329. #endif
  3330. #ifdef WOLFSSL_HAVE_KYBER
  3331. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3332. #ifndef WOLFSSL_NO_ML_KEM
  3333. #ifdef WOLFSSL_KYBER512
  3334. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3335. bench_kyber(WC_ML_KEM_512);
  3336. }
  3337. #endif
  3338. #ifdef WOLFSSL_KYBER768
  3339. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3340. bench_kyber(WC_ML_KEM_768);
  3341. }
  3342. #endif
  3343. #ifdef WOLFSSL_KYBER1024
  3344. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3345. bench_kyber(WC_ML_KEM_1024);
  3346. }
  3347. #endif
  3348. #endif
  3349. #ifdef WOLFSSL_KYBER_ORIGINAL
  3350. #ifdef WOLFSSL_KYBER512
  3351. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3352. bench_kyber(KYBER512);
  3353. }
  3354. #endif
  3355. #ifdef WOLFSSL_KYBER768
  3356. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3357. bench_kyber(KYBER768);
  3358. }
  3359. #endif
  3360. #ifdef WOLFSSL_KYBER1024
  3361. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3362. bench_kyber(KYBER1024);
  3363. }
  3364. #endif
  3365. #endif
  3366. }
  3367. #endif
  3368. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3369. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3370. bench_lms();
  3371. }
  3372. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3373. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3374. if (bench_all) {
  3375. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3376. }
  3377. #ifndef NO_SHA256
  3378. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3379. bench_xmss(WC_HASH_TYPE_SHA256);
  3380. }
  3381. #endif
  3382. #ifdef WOLFSSL_SHA512
  3383. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3384. bench_xmss(WC_HASH_TYPE_SHA512);
  3385. }
  3386. #endif
  3387. #ifdef WOLFSSL_SHAKE128
  3388. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3389. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3390. }
  3391. #endif
  3392. #ifdef WOLFSSL_SHAKE256
  3393. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3394. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3395. }
  3396. #endif
  3397. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3398. #ifdef HAVE_ECC
  3399. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3400. (bench_asym_algs & BENCH_ECC) ||
  3401. (bench_asym_algs & BENCH_ECC_ALL) ||
  3402. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3403. if (bench_asym_algs & BENCH_ECC_ALL) {
  3404. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3405. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3406. err_prefix);
  3407. #else
  3408. int curveId = (int)ECC_SECP192R1;
  3409. /* set make key and encrypt */
  3410. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3411. BENCH_ECC_ENCRYPT;
  3412. if (csv_format != 1) {
  3413. printf("\n%sECC Benchmarks:\n", info_prefix);
  3414. }
  3415. do {
  3416. #ifdef WOLFCRYPT_HAVE_SAKKE
  3417. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3418. if (curveId == ECC_SAKKE_1) {
  3419. curveId++;
  3420. continue;
  3421. }
  3422. #endif
  3423. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3424. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3425. bench_ecc_curve(curveId);
  3426. if (csv_format != 1) {
  3427. printf("\n");
  3428. }
  3429. }
  3430. curveId++;
  3431. } while (curveId != (int)ECC_CURVE_MAX);
  3432. #endif
  3433. }
  3434. else if (bench_asym_algs & BENCH_ECC_P256) {
  3435. bench_ecc_curve((int)ECC_SECP256R1);
  3436. }
  3437. else if (bench_asym_algs & BENCH_ECC_P384) {
  3438. bench_ecc_curve((int)ECC_SECP384R1);
  3439. }
  3440. else if (bench_asym_algs & BENCH_ECC_P521) {
  3441. bench_ecc_curve((int)ECC_SECP521R1);
  3442. }
  3443. else {
  3444. #ifndef NO_ECC256
  3445. bench_ecc_curve((int)ECC_SECP256R1);
  3446. #elif defined(HAVE_ECC384)
  3447. bench_ecc_curve((int)ECC_SECP384R1);
  3448. #elif defined(HAVE_ECC521)
  3449. bench_ecc_curve((int)ECC_SECP521R1);
  3450. #endif
  3451. #ifdef HAVE_ECC_BRAINPOOL
  3452. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3453. #endif
  3454. }
  3455. }
  3456. #endif
  3457. #ifdef WOLFSSL_SM2
  3458. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3459. bench_sm2(0);
  3460. }
  3461. #endif
  3462. #ifdef HAVE_CURVE25519
  3463. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3464. bench_curve25519KeyGen(0);
  3465. #ifdef BENCH_DEVID
  3466. bench_curve25519KeyGen(1);
  3467. #endif
  3468. }
  3469. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3470. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3471. bench_curve25519KeyAgree(0);
  3472. #ifdef BENCH_DEVID
  3473. bench_curve25519KeyAgree(1);
  3474. #endif
  3475. }
  3476. #endif
  3477. #endif
  3478. #ifdef HAVE_ED25519
  3479. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3480. bench_ed25519KeyGen();
  3481. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3482. bench_ed25519KeySign();
  3483. #endif
  3484. #ifdef HAVE_CURVE448
  3485. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3486. bench_curve448KeyGen();
  3487. #ifdef HAVE_CURVE448_SHARED_SECRET
  3488. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3489. bench_curve448KeyAgree();
  3490. #endif
  3491. #endif
  3492. #ifdef HAVE_ED448
  3493. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3494. bench_ed448KeyGen();
  3495. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3496. bench_ed448KeySign();
  3497. #endif
  3498. #ifdef WOLFCRYPT_HAVE_ECCSI
  3499. #ifdef WOLFCRYPT_ECCSI_KMS
  3500. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3501. bench_eccsiKeyGen();
  3502. }
  3503. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3504. bench_eccsiPairGen();
  3505. }
  3506. #endif
  3507. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3508. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3509. bench_eccsiValidate();
  3510. }
  3511. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3512. bench_eccsi();
  3513. }
  3514. #endif
  3515. #endif
  3516. #ifdef WOLFCRYPT_HAVE_SAKKE
  3517. #ifdef WOLFCRYPT_SAKKE_KMS
  3518. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3519. bench_sakkeKeyGen();
  3520. }
  3521. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3522. bench_sakkeRskGen();
  3523. }
  3524. #endif
  3525. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3526. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3527. bench_sakkeValidate();
  3528. }
  3529. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3530. bench_sakke();
  3531. }
  3532. #endif
  3533. #endif
  3534. #ifdef HAVE_FALCON
  3535. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3536. bench_falconKeySign(1);
  3537. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3538. bench_falconKeySign(5);
  3539. #endif
  3540. #ifdef HAVE_DILITHIUM
  3541. #ifndef WOLFSSL_NO_ML_DSA_44
  3542. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3543. bench_dilithiumKeySign(2);
  3544. #endif
  3545. #ifndef WOLFSSL_NO_ML_DSA_65
  3546. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3547. bench_dilithiumKeySign(3);
  3548. #endif
  3549. #ifndef WOLFSSL_NO_ML_DSA_87
  3550. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3551. bench_dilithiumKeySign(5);
  3552. #endif
  3553. #endif
  3554. #ifdef HAVE_SPHINCS
  3555. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3556. bench_sphincsKeySign(1, FAST_VARIANT);
  3557. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3558. bench_sphincsKeySign(3, FAST_VARIANT);
  3559. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3560. bench_sphincsKeySign(5, FAST_VARIANT);
  3561. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3562. bench_sphincsKeySign(1, SMALL_VARIANT);
  3563. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3564. bench_sphincsKeySign(3, SMALL_VARIANT);
  3565. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3566. bench_sphincsKeySign(5, SMALL_VARIANT);
  3567. #endif
  3568. exit:
  3569. /* free benchmark buffers */
  3570. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3571. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3572. #ifdef WOLFSSL_ASYNC_CRYPT
  3573. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3574. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3575. #endif
  3576. #if defined(HAVE_LOCAL_RNG)
  3577. wc_FreeRng(&gRng);
  3578. #endif
  3579. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3580. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3581. wc_ecc_fp_free();
  3582. #endif
  3583. (void)bench_cipher_algs;
  3584. (void)bench_digest_algs;
  3585. (void)bench_mac_algs;
  3586. (void)bench_asym_algs;
  3587. (void)bench_other_algs;
  3588. (void)bench_pq_asym_algs;
  3589. (void)bench_pq_asym_algs2;
  3590. return NULL;
  3591. }
  3592. int benchmark_init(void)
  3593. {
  3594. int ret = 0;
  3595. benchmark_static_init(0);
  3596. #ifdef WOLFSSL_STATIC_MEMORY
  3597. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3598. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3599. if (ret != 0) {
  3600. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3601. }
  3602. #endif /* WOLFSSL_STATIC_MEMORY */
  3603. if ((ret = wolfCrypt_Init()) != 0) {
  3604. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3605. return EXIT_FAILURE;
  3606. }
  3607. #ifdef HAVE_WC_INTROSPECTION
  3608. printf("Math: %s\n", wc_GetMathInfo());
  3609. #endif
  3610. #ifdef WOLFSSL_SECO_CAAM
  3611. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3612. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3613. != 0) {
  3614. printf("%sunable to open HSM\n", err_prefix);
  3615. wolfCrypt_Cleanup();
  3616. return EXIT_FAILURE;
  3617. }
  3618. #endif
  3619. #ifdef WC_RNG_SEED_CB
  3620. wc_SetSeed_Cb(wc_GenerateSeed);
  3621. #endif
  3622. bench_stats_init();
  3623. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3624. wolfSSL_Debugging_ON();
  3625. #endif
  3626. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3627. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3628. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3629. if (csv_format == 1) {
  3630. printf("This format allows you to easily copy "
  3631. "the output to a csv file.");
  3632. }
  3633. #endif
  3634. #ifdef HAVE_WNR
  3635. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3636. if (ret != 0) {
  3637. printf("%sWhitewood netRandom config init failed %d\n",
  3638. err_prefix, ret);
  3639. }
  3640. #endif /* HAVE_WNR */
  3641. return ret;
  3642. }
  3643. int benchmark_free(void)
  3644. {
  3645. int ret;
  3646. #ifdef WC_BENCH_TRACK_STATS
  3647. if (gPrintStats || devId != INVALID_DEVID) {
  3648. bench_stats_print();
  3649. }
  3650. #endif
  3651. bench_stats_free();
  3652. #ifdef WOLF_CRYPTO_CB
  3653. #ifdef HAVE_INTEL_QA_SYNC
  3654. wc_CryptoCb_CleanupIntelQa(&devId);
  3655. #endif
  3656. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3657. wc_CryptoCb_CleanupOcteon(&devId);
  3658. #endif
  3659. #ifdef HAVE_RENESAS_SYNC
  3660. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3661. #endif
  3662. #endif
  3663. #ifdef WOLFSSL_ASYNC_CRYPT
  3664. /* free event queue */
  3665. wolfEventQueue_Free(&eventQueue);
  3666. /* close device */
  3667. wolfAsync_DevClose(&devId);
  3668. #endif
  3669. #ifdef HAVE_WNR
  3670. ret = wc_FreeNetRandom();
  3671. if (ret < 0) {
  3672. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3673. }
  3674. #endif
  3675. #ifdef WOLFSSL_SECO_CAAM
  3676. if (wc_SECO_CloseHSM() != 0) {
  3677. printf("%sError closing down the key store\n", err_prefix);
  3678. }
  3679. #endif
  3680. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3681. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3682. }
  3683. return ret;
  3684. }
  3685. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3686. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3687. {
  3688. benchmark_test(args);
  3689. EXIT_TEST(0);
  3690. }
  3691. static int benchmark_test_threaded(void* args)
  3692. {
  3693. int i;
  3694. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3695. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3696. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3697. if (g_threadData == NULL) {
  3698. printf("%sThread data alloc failed!\n", err_prefix);
  3699. return EXIT_FAILURE;
  3700. }
  3701. for (i = 0; i < g_threadCount; i++) {
  3702. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3703. NULL, run_bench, args));
  3704. }
  3705. for (i = 0; i < g_threadCount; i++) {
  3706. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3707. }
  3708. printf("\n");
  3709. bench_stats_print();
  3710. return 0;
  3711. }
  3712. #endif
  3713. /* so embedded projects can pull in tests on their own */
  3714. #ifdef HAVE_STACK_SIZE
  3715. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3716. #else
  3717. int benchmark_test(void *args)
  3718. #endif
  3719. {
  3720. int ret;
  3721. (void)args;
  3722. #ifdef HAVE_FIPS
  3723. wolfCrypt_SetCb_fips(myFipsCb);
  3724. #endif
  3725. ret = benchmark_init();
  3726. if (ret != 0)
  3727. EXIT_TEST(ret);
  3728. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3729. {
  3730. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3731. **
  3732. ** Chapter Two, Build Options:
  3733. **
  3734. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3735. **
  3736. ** asynchronous cryptography using hardware based adapters such as
  3737. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3738. */
  3739. int i;
  3740. if (g_threadCount == 0) {
  3741. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3742. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3743. #else
  3744. g_threadCount = wc_AsyncGetNumberOfCpus();
  3745. if (g_threadCount > 0) {
  3746. g_threadCount /= 2; /* use physical core count */
  3747. }
  3748. #endif
  3749. }
  3750. if (g_threadCount <= 0) {
  3751. g_threadCount = 1;
  3752. }
  3753. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3754. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3755. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3756. if (g_threadData == NULL) {
  3757. printf("%sThread data alloc failed!\n", err_prefix);
  3758. EXIT_TEST(EXIT_FAILURE);
  3759. }
  3760. /* Create threads */
  3761. for (i = 0; i < g_threadCount; i++) {
  3762. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3763. benchmarks_do, &g_threadData[i]);
  3764. if (ret != 0) {
  3765. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3766. EXIT_TEST(EXIT_FAILURE);
  3767. }
  3768. }
  3769. /* Start threads */
  3770. for (i = 0; i < g_threadCount; i++) {
  3771. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3772. }
  3773. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3774. }
  3775. #else
  3776. benchmarks_do(NULL);
  3777. #endif
  3778. SLEEP_ON_ERROR(1);
  3779. printf("%sBenchmark complete\n", info_prefix);
  3780. ret = benchmark_free();
  3781. EXIT_TEST(ret);
  3782. }
  3783. #ifndef WC_NO_RNG
  3784. void bench_rng(void)
  3785. {
  3786. int ret, i, count;
  3787. double start;
  3788. long pos, len, remain;
  3789. WC_RNG myrng;
  3790. DECLARE_MULTI_VALUE_STATS_VARS()
  3791. #ifndef HAVE_FIPS
  3792. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3793. #else
  3794. ret = wc_InitRng(&myrng);
  3795. #endif
  3796. if (ret < 0) {
  3797. printf("InitRNG failed %d\n", ret);
  3798. return;
  3799. }
  3800. bench_stats_start(&count, &start);
  3801. do {
  3802. for (i = 0; i < numBlocks; i++) {
  3803. /* Split request to handle large RNG request */
  3804. pos = 0;
  3805. remain = (int)bench_size;
  3806. while (remain > 0) {
  3807. len = remain;
  3808. if (len > RNG_MAX_BLOCK_LEN)
  3809. len = RNG_MAX_BLOCK_LEN;
  3810. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3811. (word32)len);
  3812. if (ret < 0)
  3813. goto exit_rng;
  3814. remain -= len;
  3815. pos += len;
  3816. }
  3817. RECORD_MULTI_VALUE_STATS();
  3818. }
  3819. count += i;
  3820. } while (bench_stats_check(start)
  3821. #ifdef MULTI_VALUE_STATISTICS
  3822. || runs < minimum_runs
  3823. #endif
  3824. );
  3825. exit_rng:
  3826. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3827. #ifdef MULTI_VALUE_STATISTICS
  3828. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3829. #endif
  3830. wc_FreeRng(&myrng);
  3831. }
  3832. #endif /* WC_NO_RNG */
  3833. #ifndef NO_AES
  3834. #ifdef HAVE_AES_CBC
  3835. static void bench_aescbc_internal(int useDeviceID,
  3836. const byte* key, word32 keySz,
  3837. const byte* iv, const char* encLabel,
  3838. const char* decLabel)
  3839. {
  3840. const byte* in = bench_cipher;
  3841. byte* out = bench_plain;
  3842. int ret = 0, i, count = 0, times, pending = 0;
  3843. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3844. sizeof(Aes), HEAP_HINT);
  3845. double start;
  3846. DECLARE_MULTI_VALUE_STATS_VARS()
  3847. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3848. sizeof(Aes), HEAP_HINT);
  3849. /* init keys */
  3850. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3851. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3852. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3853. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3854. goto exit;
  3855. }
  3856. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3857. if (ret != 0) {
  3858. printf("AesSetKey failed, ret = %d\n", ret);
  3859. goto exit;
  3860. }
  3861. }
  3862. if (cipher_same_buffer) {
  3863. in = bench_plain;
  3864. }
  3865. bench_stats_start(&count, &start);
  3866. do {
  3867. for (times = 0; times < numBlocks || pending > 0; ) {
  3868. bench_async_poll(&pending);
  3869. /* while free pending slots in queue, submit ops */
  3870. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3871. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3872. &times, numBlocks, &pending)) {
  3873. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3874. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3875. 0, &times, &pending)) {
  3876. goto exit_aes_enc;
  3877. }
  3878. }
  3879. } /* for i */
  3880. RECORD_MULTI_VALUE_STATS();
  3881. } /* for times */
  3882. count += times;
  3883. } while (bench_stats_check(start)
  3884. #ifdef MULTI_VALUE_STATISTICS
  3885. || runs < minimum_runs
  3886. #endif
  3887. );
  3888. exit_aes_enc:
  3889. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3890. bench_size, start, ret);
  3891. #ifdef MULTI_VALUE_STATISTICS
  3892. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3893. #endif
  3894. if (ret < 0) {
  3895. goto exit;
  3896. }
  3897. #ifdef HAVE_AES_DECRYPT
  3898. /* init keys */
  3899. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3900. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3901. if (ret != 0) {
  3902. printf("AesSetKey failed, ret = %d\n", ret);
  3903. goto exit;
  3904. }
  3905. }
  3906. RESET_MULTI_VALUE_STATS_VARS();
  3907. bench_stats_start(&count, &start);
  3908. do {
  3909. for (times = 0; times < numBlocks || pending > 0; ) {
  3910. bench_async_poll(&pending);
  3911. /* while free pending slots in queue, submit ops */
  3912. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3913. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3914. &times, numBlocks, &pending)) {
  3915. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3916. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3917. 0, &times, &pending)) {
  3918. goto exit_aes_dec;
  3919. }
  3920. }
  3921. } /* for i */
  3922. RECORD_MULTI_VALUE_STATS();
  3923. } /* for times */
  3924. count += times;
  3925. } while (bench_stats_check(start)
  3926. #ifdef MULTI_VALUE_STATISTICS
  3927. || runs < minimum_runs
  3928. #endif
  3929. );
  3930. exit_aes_dec:
  3931. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3932. start, ret);
  3933. #ifdef MULTI_VALUE_STATISTICS
  3934. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3935. #endif
  3936. #endif /* HAVE_AES_DECRYPT */
  3937. (void)decLabel;
  3938. exit:
  3939. if (WC_ARRAY_OK(enc)) {
  3940. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3941. wc_AesFree(enc[i]);
  3942. }
  3943. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3944. }
  3945. }
  3946. void bench_aescbc(int useDeviceID)
  3947. {
  3948. #ifdef WOLFSSL_AES_128
  3949. #ifdef HAVE_RENESAS_SYNC
  3950. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3951. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3952. #else
  3953. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3954. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3955. #endif
  3956. #endif
  3957. #ifdef WOLFSSL_AES_192
  3958. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3959. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3960. #endif
  3961. #ifdef WOLFSSL_AES_256
  3962. #ifdef HAVE_RENESAS_SYNC
  3963. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3964. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3965. #else
  3966. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3967. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3968. #endif
  3969. #endif
  3970. }
  3971. #endif /* HAVE_AES_CBC */
  3972. #ifdef HAVE_AESGCM
  3973. static void bench_aesgcm_internal(int useDeviceID,
  3974. const byte* key, word32 keySz,
  3975. const byte* iv, word32 ivSz,
  3976. const char* encLabel, const char* decLabel)
  3977. {
  3978. int ret = 0, i, count = 0, times, pending = 0;
  3979. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3980. sizeof(Aes), HEAP_HINT);
  3981. #ifdef HAVE_AES_DECRYPT
  3982. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3983. sizeof(Aes), HEAP_HINT);
  3984. #endif
  3985. double start;
  3986. DECLARE_MULTI_VALUE_STATS_VARS()
  3987. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3988. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3989. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3990. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3991. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3992. sizeof(Aes), HEAP_HINT);
  3993. #ifdef HAVE_AES_DECRYPT
  3994. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3995. sizeof(Aes), HEAP_HINT);
  3996. #endif
  3997. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  3998. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  3999. /* init keys */
  4000. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4001. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4002. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4003. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4004. goto exit;
  4005. }
  4006. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4007. if (ret != 0) {
  4008. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4009. goto exit;
  4010. }
  4011. }
  4012. /* GCM uses same routine in backend for both encrypt and decrypt */
  4013. bench_stats_start(&count, &start);
  4014. do {
  4015. for (times = 0; times < numBlocks || pending > 0; ) {
  4016. bench_async_poll(&pending);
  4017. /* while free pending slots in queue, submit ops */
  4018. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4019. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4020. &times, numBlocks, &pending)) {
  4021. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  4022. bench_plain, bench_size,
  4023. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4024. bench_additional, aesAuthAddSz);
  4025. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4026. 0, &times, &pending)) {
  4027. goto exit_aes_gcm;
  4028. }
  4029. }
  4030. } /* for i */
  4031. RECORD_MULTI_VALUE_STATS();
  4032. } /* for times */
  4033. count += times;
  4034. } while (bench_stats_check(start)
  4035. #ifdef MULTI_VALUE_STATISTICS
  4036. || runs < minimum_runs
  4037. #endif
  4038. );
  4039. exit_aes_gcm:
  4040. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4041. start, ret);
  4042. #ifdef MULTI_VALUE_STATISTICS
  4043. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4044. #endif
  4045. #ifdef HAVE_AES_DECRYPT
  4046. RESET_MULTI_VALUE_STATS_VARS();
  4047. /* init keys */
  4048. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4049. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4050. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4051. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4052. goto exit;
  4053. }
  4054. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4055. if (ret != 0) {
  4056. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4057. goto exit;
  4058. }
  4059. }
  4060. bench_stats_start(&count, &start);
  4061. do {
  4062. for (times = 0; times < numBlocks || pending > 0; ) {
  4063. bench_async_poll(&pending);
  4064. /* while free pending slots in queue, submit ops */
  4065. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4066. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4067. &times, numBlocks, &pending)) {
  4068. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4069. bench_cipher, bench_size,
  4070. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4071. bench_additional, aesAuthAddSz);
  4072. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4073. 0, &times, &pending)) {
  4074. goto exit_aes_gcm_dec;
  4075. }
  4076. }
  4077. } /* for i */
  4078. RECORD_MULTI_VALUE_STATS();
  4079. } /* for times */
  4080. count += times;
  4081. } while (bench_stats_check(start)
  4082. #ifdef MULTI_VALUE_STATISTICS
  4083. || runs < minimum_runs
  4084. #endif
  4085. );
  4086. exit_aes_gcm_dec:
  4087. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4088. start, ret);
  4089. #ifdef MULTI_VALUE_STATISTICS
  4090. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4091. #endif
  4092. #endif /* HAVE_AES_DECRYPT */
  4093. (void)decLabel;
  4094. exit:
  4095. if (ret < 0) {
  4096. printf("bench_aesgcm failed: %d\n", ret);
  4097. }
  4098. #ifdef HAVE_AES_DECRYPT
  4099. if (WC_ARRAY_OK(dec)) {
  4100. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4101. wc_AesFree(dec[i]);
  4102. }
  4103. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4104. }
  4105. #endif
  4106. if (WC_ARRAY_OK(enc)) {
  4107. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4108. wc_AesFree(enc[i]);
  4109. }
  4110. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4111. }
  4112. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4113. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4114. }
  4115. #ifdef WOLFSSL_AESGCM_STREAM
  4116. static void bench_aesgcm_stream_internal(int useDeviceID,
  4117. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4118. const char* encLabel, const char* decLabel)
  4119. {
  4120. int ret = 0, i, count = 0, times, pending = 0;
  4121. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4122. sizeof(Aes), HEAP_HINT);
  4123. #ifdef HAVE_AES_DECRYPT
  4124. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4125. sizeof(Aes), HEAP_HINT);
  4126. #endif
  4127. double start;
  4128. DECLARE_MULTI_VALUE_STATS_VARS()
  4129. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4130. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4131. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4132. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4133. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4134. sizeof(Aes), HEAP_HINT);
  4135. #ifdef HAVE_AES_DECRYPT
  4136. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4137. sizeof(Aes), HEAP_HINT);
  4138. #endif
  4139. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4140. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4141. /* init keys */
  4142. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4143. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4144. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4145. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4146. goto exit;
  4147. }
  4148. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4149. if (ret != 0) {
  4150. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4151. goto exit;
  4152. }
  4153. }
  4154. /* GCM uses same routine in backend for both encrypt and decrypt */
  4155. bench_stats_start(&count, &start);
  4156. do {
  4157. for (times = 0; times < numBlocks || pending > 0; ) {
  4158. bench_async_poll(&pending);
  4159. /* while free pending slots in queue, submit ops */
  4160. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4161. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4162. &times, numBlocks, &pending)) {
  4163. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4164. if (ret == 0) {
  4165. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4166. bench_plain, bench_size, bench_additional,
  4167. aesAuthAddSz);
  4168. }
  4169. if (ret == 0) {
  4170. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4171. AES_AUTH_TAG_SZ);
  4172. }
  4173. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4174. 0, &times, &pending)) {
  4175. goto exit_aes_gcm;
  4176. }
  4177. }
  4178. } /* for i */
  4179. RECORD_MULTI_VALUE_STATS();
  4180. } /* for times */
  4181. count += times;
  4182. } while (bench_stats_check(start)
  4183. #ifdef MULTI_VALUE_STATISTICS
  4184. || runs < minimum_runs
  4185. #endif
  4186. );
  4187. exit_aes_gcm:
  4188. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4189. start, ret);
  4190. #ifdef MULTI_VALUE_STATISTICS
  4191. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4192. #endif
  4193. #ifdef HAVE_AES_DECRYPT
  4194. /* init keys */
  4195. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4196. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4197. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4198. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4199. goto exit;
  4200. }
  4201. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4202. if (ret != 0) {
  4203. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4204. goto exit;
  4205. }
  4206. }
  4207. RESET_MULTI_VALUE_STATS_VARS();
  4208. bench_stats_start(&count, &start);
  4209. do {
  4210. for (times = 0; times < numBlocks || pending > 0; ) {
  4211. bench_async_poll(&pending);
  4212. /* while free pending slots in queue, submit ops */
  4213. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4214. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4215. &times, numBlocks, &pending)) {
  4216. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4217. if (ret == 0) {
  4218. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4219. bench_cipher, bench_size, bench_additional,
  4220. aesAuthAddSz);
  4221. }
  4222. if (ret == 0) {
  4223. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4224. AES_AUTH_TAG_SZ);
  4225. }
  4226. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4227. 0, &times, &pending)) {
  4228. goto exit_aes_gcm_dec;
  4229. }
  4230. }
  4231. } /* for i */
  4232. RECORD_MULTI_VALUE_STATS();
  4233. } /* for times */
  4234. count += times;
  4235. } while (bench_stats_check(start)
  4236. #ifdef MULTI_VALUE_STATISTICS
  4237. || runs < minimum_runs
  4238. #endif
  4239. );
  4240. exit_aes_gcm_dec:
  4241. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4242. start, ret);
  4243. #ifdef MULTI_VALUE_STATISTICS
  4244. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4245. #endif
  4246. #endif /* HAVE_AES_DECRYPT */
  4247. (void)decLabel;
  4248. exit:
  4249. if (ret < 0) {
  4250. printf("bench_aesgcm failed: %d\n", ret);
  4251. }
  4252. #ifdef HAVE_AES_DECRYPT
  4253. if (WC_ARRAY_OK(dec)) {
  4254. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4255. wc_AesFree(dec[i]);
  4256. }
  4257. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4258. }
  4259. #endif
  4260. if (WC_ARRAY_OK(enc)) {
  4261. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4262. wc_AesFree(enc[i]);
  4263. }
  4264. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4265. }
  4266. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4267. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4268. }
  4269. #endif
  4270. void bench_aesgcm(int useDeviceID)
  4271. {
  4272. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4273. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4274. && !defined(WOLFSSL_XILINX_CRYPT) \
  4275. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4276. #ifdef HAVE_RENESAS_SYNC
  4277. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4278. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4279. #else
  4280. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4281. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4282. #endif
  4283. #endif
  4284. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4285. && !defined(WOLFSSL_XILINX_CRYPT)
  4286. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4287. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4288. #endif
  4289. #ifdef WOLFSSL_AES_256
  4290. #ifdef HAVE_RENESAS_SYNC
  4291. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4292. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4293. #else
  4294. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4295. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4296. #endif
  4297. #endif
  4298. #ifdef WOLFSSL_AESGCM_STREAM
  4299. #undef AES_GCM_STRING
  4300. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4301. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4302. && !defined(WOLFSSL_XILINX_CRYPT) \
  4303. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4304. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4305. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4306. #endif
  4307. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4308. && !defined(WOLFSSL_XILINX_CRYPT)
  4309. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4310. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4311. #endif
  4312. #ifdef WOLFSSL_AES_256
  4313. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4314. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4315. #endif
  4316. #endif /* WOLFSSL_AESGCM_STREAM */
  4317. #undef AES_GCM_STRING
  4318. }
  4319. /* GMAC */
  4320. void bench_gmac(int useDeviceID)
  4321. {
  4322. int ret, count = 0;
  4323. Gmac gmac;
  4324. double start;
  4325. byte tag[AES_AUTH_TAG_SZ];
  4326. DECLARE_MULTI_VALUE_STATS_VARS()
  4327. /* determine GCM GHASH method */
  4328. #ifdef GCM_SMALL
  4329. const char* gmacStr = "GMAC Small";
  4330. #elif defined(GCM_TABLE)
  4331. const char* gmacStr = "GMAC Table";
  4332. #elif defined(GCM_TABLE_4BIT)
  4333. const char* gmacStr = "GMAC Table 4-bit";
  4334. #elif defined(GCM_WORD32)
  4335. const char* gmacStr = "GMAC Word32";
  4336. #else
  4337. const char* gmacStr = "GMAC Default";
  4338. #endif
  4339. /* init keys */
  4340. XMEMSET(bench_plain, 0, bench_size);
  4341. XMEMSET(tag, 0, sizeof(tag));
  4342. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4343. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4344. useDeviceID ? devId: INVALID_DEVID);
  4345. #ifdef HAVE_RENESAS_SYNC
  4346. wc_GmacSetKey(&gmac, bench_key1, 16);
  4347. #else
  4348. wc_GmacSetKey(&gmac, bench_key, 16);
  4349. #endif
  4350. bench_stats_start(&count, &start);
  4351. do {
  4352. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4353. tag, sizeof(tag));
  4354. count++;
  4355. RECORD_MULTI_VALUE_STATS();
  4356. } while (bench_stats_check(start)
  4357. #ifdef MULTI_VALUE_STATISTICS
  4358. || runs < minimum_runs
  4359. #endif
  4360. );
  4361. wc_AesFree((Aes*)&gmac);
  4362. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4363. #ifdef MULTI_VALUE_STATISTICS
  4364. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4365. #endif
  4366. }
  4367. #endif /* HAVE_AESGCM */
  4368. #ifdef HAVE_AES_ECB
  4369. static void bench_aesecb_internal(int useDeviceID,
  4370. const byte* key, word32 keySz,
  4371. const char* encLabel, const char* decLabel)
  4372. {
  4373. int ret = 0, i, count = 0, times, pending = 0;
  4374. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4375. sizeof(Aes), HEAP_HINT);
  4376. double start;
  4377. DECLARE_MULTI_VALUE_STATS_VARS()
  4378. #ifdef HAVE_FIPS
  4379. const word32 benchSz = AES_BLOCK_SIZE;
  4380. #else
  4381. const word32 benchSz = bench_size;
  4382. #endif
  4383. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4384. sizeof(Aes), HEAP_HINT);
  4385. /* init keys */
  4386. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4387. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4388. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4389. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4390. goto exit;
  4391. }
  4392. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4393. if (ret != 0) {
  4394. printf("AesSetKey failed, ret = %d\n", ret);
  4395. goto exit;
  4396. }
  4397. }
  4398. bench_stats_start(&count, &start);
  4399. do {
  4400. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4401. for (times = 0;
  4402. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4403. ) {
  4404. bench_async_poll(&pending);
  4405. /* while free pending slots in queue, submit ops */
  4406. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4407. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4408. &times, outer_loop_limit, &pending)) {
  4409. #ifdef HAVE_FIPS
  4410. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4411. #else
  4412. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4413. benchSz);
  4414. #endif
  4415. ret = 0;
  4416. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4417. 0, &times, &pending)) {
  4418. goto exit_aes_enc;
  4419. }
  4420. }
  4421. } /* for i */
  4422. RECORD_MULTI_VALUE_STATS();
  4423. } /* for times */
  4424. count += times;
  4425. } while (bench_stats_check(start)
  4426. #ifdef MULTI_VALUE_STATISTICS
  4427. || runs < minimum_runs
  4428. #endif
  4429. );
  4430. exit_aes_enc:
  4431. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4432. start, ret);
  4433. #ifdef MULTI_VALUE_STATISTICS
  4434. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4435. #endif
  4436. #ifdef HAVE_AES_DECRYPT
  4437. /* init keys */
  4438. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4439. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4440. if (ret != 0) {
  4441. printf("AesSetKey failed, ret = %d\n", ret);
  4442. goto exit;
  4443. }
  4444. }
  4445. RESET_MULTI_VALUE_STATS_VARS();
  4446. bench_stats_start(&count, &start);
  4447. do {
  4448. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4449. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4450. bench_async_poll(&pending);
  4451. /* while free pending slots in queue, submit ops */
  4452. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4453. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4454. &times, outer_loop_limit, &pending)) {
  4455. #ifdef HAVE_FIPS
  4456. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4457. #else
  4458. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4459. benchSz);
  4460. #endif
  4461. ret = 0;
  4462. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4463. 0, &times, &pending)) {
  4464. goto exit_aes_dec;
  4465. }
  4466. }
  4467. } /* for i */
  4468. RECORD_MULTI_VALUE_STATS();
  4469. } /* for times */
  4470. count += times;
  4471. } while (bench_stats_check(start)
  4472. #ifdef MULTI_VALUE_STATISTICS
  4473. || runs < minimum_runs
  4474. #endif
  4475. );
  4476. exit_aes_dec:
  4477. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4478. start, ret);
  4479. #ifdef MULTI_VALUE_STATISTICS
  4480. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4481. #endif
  4482. #endif /* HAVE_AES_DECRYPT */
  4483. (void)decLabel;
  4484. exit:
  4485. if (WC_ARRAY_OK(enc)) {
  4486. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4487. wc_AesFree(enc[i]);
  4488. }
  4489. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4490. }
  4491. }
  4492. void bench_aesecb(int useDeviceID)
  4493. {
  4494. #ifdef WOLFSSL_AES_128
  4495. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4496. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4497. #endif
  4498. #ifdef WOLFSSL_AES_192
  4499. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4500. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4501. #endif
  4502. #ifdef WOLFSSL_AES_256
  4503. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4504. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4505. #endif
  4506. }
  4507. #endif /* HAVE_AES_ECB */
  4508. #ifdef WOLFSSL_AES_CFB
  4509. static void bench_aescfb_internal(const byte* key,
  4510. word32 keySz, const byte* iv,
  4511. const char* label)
  4512. {
  4513. Aes enc;
  4514. double start;
  4515. int i, ret, count;
  4516. DECLARE_MULTI_VALUE_STATS_VARS()
  4517. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4518. if (ret != 0) {
  4519. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4520. return;
  4521. }
  4522. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4523. if (ret != 0) {
  4524. printf("AesSetKey failed, ret = %d\n", ret);
  4525. goto out;
  4526. }
  4527. bench_stats_start(&count, &start);
  4528. do {
  4529. for (i = 0; i < numBlocks; i++) {
  4530. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4531. bench_size)) != 0) {
  4532. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4533. goto out;
  4534. }
  4535. RECORD_MULTI_VALUE_STATS();
  4536. }
  4537. count += i;
  4538. } while (bench_stats_check(start)
  4539. #ifdef MULTI_VALUE_STATISTICS
  4540. || runs < minimum_runs
  4541. #endif
  4542. );
  4543. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4544. #ifdef MULTI_VALUE_STATISTICS
  4545. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4546. #endif
  4547. out:
  4548. wc_AesFree(&enc);
  4549. return;
  4550. }
  4551. void bench_aescfb(void)
  4552. {
  4553. #ifdef WOLFSSL_AES_128
  4554. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4555. #endif
  4556. #ifdef WOLFSSL_AES_192
  4557. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4558. #endif
  4559. #ifdef WOLFSSL_AES_256
  4560. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4561. #endif
  4562. }
  4563. #endif /* WOLFSSL_AES_CFB */
  4564. #ifdef WOLFSSL_AES_OFB
  4565. static void bench_aesofb_internal(const byte* key,
  4566. word32 keySz, const byte* iv,
  4567. const char* label)
  4568. {
  4569. Aes enc;
  4570. double start;
  4571. int i, ret, count;
  4572. DECLARE_MULTI_VALUE_STATS_VARS()
  4573. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4574. if (ret != 0) {
  4575. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4576. return;
  4577. }
  4578. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4579. if (ret != 0) {
  4580. printf("AesSetKey failed, ret = %d\n", ret);
  4581. return;
  4582. }
  4583. bench_stats_start(&count, &start);
  4584. do {
  4585. for (i = 0; i < numBlocks; i++) {
  4586. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4587. bench_size)) != 0) {
  4588. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4589. return;
  4590. }
  4591. RECORD_MULTI_VALUE_STATS();
  4592. }
  4593. count += i;
  4594. } while (bench_stats_check(start)
  4595. #ifdef MULTI_VALUE_STATISTICS
  4596. || runs < minimum_runs
  4597. #endif
  4598. );
  4599. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4600. #ifdef MULTI_VALUE_STATISTICS
  4601. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4602. #endif
  4603. wc_AesFree(&enc);
  4604. }
  4605. void bench_aesofb(void)
  4606. {
  4607. #ifdef WOLFSSL_AES_128
  4608. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4609. #endif
  4610. #ifdef WOLFSSL_AES_192
  4611. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4612. #endif
  4613. #ifdef WOLFSSL_AES_256
  4614. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4615. #endif
  4616. }
  4617. #endif /* WOLFSSL_AES_CFB */
  4618. #ifdef WOLFSSL_AES_XTS
  4619. void bench_aesxts(void)
  4620. {
  4621. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4622. double start;
  4623. int i, count, ret;
  4624. DECLARE_MULTI_VALUE_STATS_VARS()
  4625. static const unsigned char k1[] = {
  4626. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4627. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4628. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4629. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4630. };
  4631. static const unsigned char i1[] = {
  4632. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4633. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4634. };
  4635. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4636. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4637. HEAP_HINT, devId);
  4638. if (ret != 0) {
  4639. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4640. goto exit;
  4641. }
  4642. bench_stats_start(&count, &start);
  4643. do {
  4644. for (i = 0; i < numBlocks; i++) {
  4645. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4646. bench_size, i1, sizeof(i1))) != 0) {
  4647. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4648. goto exit;
  4649. }
  4650. RECORD_MULTI_VALUE_STATS();
  4651. }
  4652. count += i;
  4653. } while (bench_stats_check(start)
  4654. #ifdef MULTI_VALUE_STATISTICS
  4655. || runs < minimum_runs
  4656. #endif
  4657. );
  4658. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4659. #ifdef MULTI_VALUE_STATISTICS
  4660. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4661. #endif
  4662. wc_AesXtsFree(aes);
  4663. /* decryption benchmark */
  4664. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4665. HEAP_HINT, devId);
  4666. if (ret != 0) {
  4667. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4668. goto exit;
  4669. }
  4670. RESET_MULTI_VALUE_STATS_VARS();
  4671. bench_stats_start(&count, &start);
  4672. do {
  4673. for (i = 0; i < numBlocks; i++) {
  4674. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4675. bench_size, i1, sizeof(i1))) != 0) {
  4676. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4677. goto exit;
  4678. }
  4679. RECORD_MULTI_VALUE_STATS();
  4680. }
  4681. count += i;
  4682. } while (bench_stats_check(start)
  4683. #ifdef MULTI_VALUE_STATISTICS
  4684. || runs < minimum_runs
  4685. #endif
  4686. );
  4687. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4688. #ifdef MULTI_VALUE_STATISTICS
  4689. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4690. #endif
  4691. exit:
  4692. wc_AesXtsFree(aes);
  4693. WC_FREE_VAR(aes, HEAP_HINT);
  4694. }
  4695. #endif /* WOLFSSL_AES_XTS */
  4696. #ifdef WOLFSSL_AES_COUNTER
  4697. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4698. const byte* iv, const char* label,
  4699. int useDeviceID)
  4700. {
  4701. Aes enc;
  4702. double start;
  4703. int i, count, ret = 0;
  4704. DECLARE_MULTI_VALUE_STATS_VARS()
  4705. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4706. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4707. printf("wc_AesInit failed, ret = %d\n", ret);
  4708. }
  4709. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4710. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4711. return;
  4712. }
  4713. bench_stats_start(&count, &start);
  4714. do {
  4715. for (i = 0; i < numBlocks; i++) {
  4716. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4717. bench_size)) != 0) {
  4718. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4719. return;
  4720. }
  4721. RECORD_MULTI_VALUE_STATS();
  4722. }
  4723. count += i;
  4724. } while (bench_stats_check(start)
  4725. #ifdef MULTI_VALUE_STATISTICS
  4726. || runs < minimum_runs
  4727. #endif
  4728. );
  4729. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4730. #ifdef MULTI_VALUE_STATISTICS
  4731. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4732. #endif
  4733. wc_AesFree(&enc);
  4734. }
  4735. void bench_aesctr(int useDeviceID)
  4736. {
  4737. #ifdef WOLFSSL_AES_128
  4738. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4739. #endif
  4740. #ifdef WOLFSSL_AES_192
  4741. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4742. #endif
  4743. #ifdef WOLFSSL_AES_256
  4744. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4745. #endif
  4746. }
  4747. #endif /* WOLFSSL_AES_COUNTER */
  4748. #ifdef HAVE_AESCCM
  4749. void bench_aesccm(int useDeviceID)
  4750. {
  4751. Aes enc;
  4752. int enc_inited = 0;
  4753. double start;
  4754. int ret, i, count;
  4755. DECLARE_MULTI_VALUE_STATS_VARS()
  4756. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4757. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4758. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4759. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4760. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4761. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4762. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4763. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4764. {
  4765. printf("wc_AesInit failed, ret = %d\n", ret);
  4766. goto exit;
  4767. }
  4768. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4769. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4770. goto exit;
  4771. }
  4772. enc_inited = 1;
  4773. bench_stats_start(&count, &start);
  4774. do {
  4775. for (i = 0; i < numBlocks; i++) {
  4776. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4777. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4778. bench_additional, 0);
  4779. RECORD_MULTI_VALUE_STATS();
  4780. }
  4781. count += i;
  4782. } while (bench_stats_check(start)
  4783. #ifdef MULTI_VALUE_STATISTICS
  4784. || runs < minimum_runs
  4785. #endif
  4786. );
  4787. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4788. bench_size, start, ret);
  4789. #ifdef MULTI_VALUE_STATISTICS
  4790. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4791. #endif
  4792. if (ret != 0) {
  4793. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4794. goto exit;
  4795. }
  4796. #ifdef HAVE_AES_DECRYPT
  4797. RESET_MULTI_VALUE_STATS_VARS();
  4798. bench_stats_start(&count, &start);
  4799. do {
  4800. for (i = 0; i < numBlocks; i++) {
  4801. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4802. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4803. bench_additional, 0);
  4804. RECORD_MULTI_VALUE_STATS();
  4805. }
  4806. count += i;
  4807. } while (bench_stats_check(start)
  4808. #ifdef MULTI_VALUE_STATISTICS
  4809. || runs < minimum_runs
  4810. #endif
  4811. );
  4812. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4813. bench_size, start, ret);
  4814. #ifdef MULTI_VALUE_STATISTICS
  4815. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4816. #endif
  4817. if (ret != 0) {
  4818. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4819. goto exit;
  4820. }
  4821. #endif
  4822. exit:
  4823. if (enc_inited)
  4824. wc_AesFree(&enc);
  4825. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4826. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4827. }
  4828. #endif /* HAVE_AESCCM */
  4829. #ifdef WOLFSSL_AES_SIV
  4830. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4831. encLabel, const char* decLabel)
  4832. {
  4833. int i;
  4834. int ret = 0;
  4835. byte assoc[AES_BLOCK_SIZE];
  4836. byte nonce[AES_BLOCK_SIZE];
  4837. byte siv[AES_BLOCK_SIZE];
  4838. int count = 0;
  4839. double start;
  4840. DECLARE_MULTI_VALUE_STATS_VARS()
  4841. bench_stats_start(&count, &start);
  4842. do {
  4843. for (i = 0; i < numBlocks; i++) {
  4844. ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4845. AES_BLOCK_SIZE, bench_plain, bench_size,
  4846. siv, bench_cipher);
  4847. if (ret != 0) {
  4848. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4849. return;
  4850. }
  4851. RECORD_MULTI_VALUE_STATS();
  4852. }
  4853. count += i;
  4854. } while (bench_stats_check(start)
  4855. #ifdef MULTI_VALUE_STATISTICS
  4856. || runs < minimum_runs
  4857. #endif
  4858. );
  4859. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4860. #ifdef MULTI_VALUE_STATISTICS
  4861. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4862. #endif
  4863. RESET_MULTI_VALUE_STATS_VARS();
  4864. bench_stats_start(&count, &start);
  4865. do {
  4866. for (i = 0; i < numBlocks; i++) {
  4867. ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4868. AES_BLOCK_SIZE, bench_cipher, bench_size,
  4869. siv, bench_plain);
  4870. if (ret != 0) {
  4871. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4872. return;
  4873. }
  4874. RECORD_MULTI_VALUE_STATS();
  4875. }
  4876. count += i;
  4877. } while (bench_stats_check(start)
  4878. #ifdef MULTI_VALUE_STATISTICS
  4879. || runs < minimum_runs
  4880. #endif
  4881. );
  4882. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4883. #ifdef MULTI_VALUE_STATISTICS
  4884. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4885. #endif
  4886. }
  4887. void bench_aessiv(void)
  4888. {
  4889. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4890. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4891. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4892. }
  4893. #endif /* WOLFSSL_AES_SIV */
  4894. #endif /* !NO_AES */
  4895. #ifdef HAVE_POLY1305
  4896. void bench_poly1305(void)
  4897. {
  4898. Poly1305 enc;
  4899. byte mac[16];
  4900. double start;
  4901. int ret = 0, i, count;
  4902. DECLARE_MULTI_VALUE_STATS_VARS()
  4903. if (digest_stream) {
  4904. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4905. if (ret != 0) {
  4906. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4907. return;
  4908. }
  4909. bench_stats_start(&count, &start);
  4910. do {
  4911. for (i = 0; i < numBlocks; i++) {
  4912. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4913. if (ret != 0) {
  4914. printf("Poly1305Update failed: %d\n", ret);
  4915. break;
  4916. }
  4917. RECORD_MULTI_VALUE_STATS();
  4918. }
  4919. wc_Poly1305Final(&enc, mac);
  4920. count += i;
  4921. } while (bench_stats_check(start)
  4922. #ifdef MULTI_VALUE_STATISTICS
  4923. || runs < minimum_runs
  4924. #endif
  4925. );
  4926. }
  4927. else {
  4928. bench_stats_start(&count, &start);
  4929. do {
  4930. for (i = 0; i < numBlocks; i++) {
  4931. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4932. if (ret != 0) {
  4933. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4934. return;
  4935. }
  4936. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4937. if (ret != 0) {
  4938. printf("Poly1305Update failed: %d\n", ret);
  4939. break;
  4940. }
  4941. wc_Poly1305Final(&enc, mac);
  4942. RECORD_MULTI_VALUE_STATS();
  4943. }
  4944. count += i;
  4945. } while (bench_stats_check(start)
  4946. #ifdef MULTI_VALUE_STATISTICS
  4947. || runs < minimum_runs
  4948. #endif
  4949. );
  4950. }
  4951. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4952. #ifdef MULTI_VALUE_STATISTICS
  4953. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4954. #endif
  4955. }
  4956. #endif /* HAVE_POLY1305 */
  4957. #ifdef HAVE_CAMELLIA
  4958. void bench_camellia(void)
  4959. {
  4960. Camellia cam;
  4961. double start;
  4962. int ret, i, count;
  4963. DECLARE_MULTI_VALUE_STATS_VARS()
  4964. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4965. if (ret != 0) {
  4966. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4967. return;
  4968. }
  4969. bench_stats_start(&count, &start);
  4970. do {
  4971. for (i = 0; i < numBlocks; i++) {
  4972. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4973. bench_size);
  4974. if (ret < 0) {
  4975. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4976. return;
  4977. }
  4978. RECORD_MULTI_VALUE_STATS();
  4979. }
  4980. count += i;
  4981. } while (bench_stats_check(start)
  4982. #ifdef MULTI_VALUE_STATISTICS
  4983. || runs < minimum_runs
  4984. #endif
  4985. );
  4986. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  4987. #ifdef MULTI_VALUE_STATISTICS
  4988. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4989. #endif
  4990. }
  4991. #endif
  4992. #ifdef WOLFSSL_SM4_CBC
  4993. void bench_sm4_cbc(void)
  4994. {
  4995. wc_Sm4 sm4;
  4996. double start;
  4997. int ret;
  4998. int i;
  4999. int count;
  5000. DECLARE_MULTI_VALUE_STATS_VARS()
  5001. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5002. if (ret != 0) {
  5003. printf("Sm4SetKey failed, ret = %d\n", ret);
  5004. return;
  5005. }
  5006. ret = wc_Sm4SetIV(&sm4, bench_iv);
  5007. if (ret != 0) {
  5008. printf("Sm4SetIV failed, ret = %d\n", ret);
  5009. return;
  5010. }
  5011. bench_stats_start(&count, &start);
  5012. do {
  5013. for (i = 0; i < numBlocks; i++) {
  5014. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  5015. if (ret < 0) {
  5016. printf("Sm4CbcEncrypt failed: %d\n", ret);
  5017. return;
  5018. }
  5019. RECORD_MULTI_VALUE_STATS();
  5020. }
  5021. count += i;
  5022. } while (bench_stats_check(start)
  5023. #ifdef MULTI_VALUE_STATISTICS
  5024. || runs < minimum_runs
  5025. #endif
  5026. );
  5027. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5028. #ifdef MULTI_VALUE_STATISTICS
  5029. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5030. #endif
  5031. RESET_MULTI_VALUE_STATS_VARS();
  5032. bench_stats_start(&count, &start);
  5033. do {
  5034. for (i = 0; i < numBlocks; i++) {
  5035. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5036. if (ret < 0) {
  5037. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5038. return;
  5039. }
  5040. RECORD_MULTI_VALUE_STATS();
  5041. }
  5042. count += i;
  5043. } while (bench_stats_check(start)
  5044. #ifdef MULTI_VALUE_STATISTICS
  5045. || runs < minimum_runs
  5046. #endif
  5047. );
  5048. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5049. #ifdef MULTI_VALUE_STATISTICS
  5050. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5051. #endif
  5052. }
  5053. #endif
  5054. #ifdef WOLFSSL_SM4_GCM
  5055. void bench_sm4_gcm(void)
  5056. {
  5057. wc_Sm4 sm4;
  5058. double start;
  5059. int ret;
  5060. int i;
  5061. int count;
  5062. DECLARE_MULTI_VALUE_STATS_VARS()
  5063. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5064. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5065. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5066. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5067. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5068. if (ret != 0) {
  5069. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5070. goto exit;
  5071. }
  5072. bench_stats_start(&count, &start);
  5073. do {
  5074. for (i = 0; i < numBlocks; i++) {
  5075. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5076. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5077. bench_additional, aesAuthAddSz);
  5078. if (ret < 0) {
  5079. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5080. goto exit;
  5081. }
  5082. RECORD_MULTI_VALUE_STATS();
  5083. }
  5084. count += i;
  5085. } while (bench_stats_check(start)
  5086. #ifdef MULTI_VALUE_STATISTICS
  5087. || runs < minimum_runs
  5088. #endif
  5089. );
  5090. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5091. #ifdef MULTI_VALUE_STATISTICS
  5092. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5093. #endif
  5094. RESET_MULTI_VALUE_STATS_VARS();
  5095. bench_stats_start(&count, &start);
  5096. do {
  5097. for (i = 0; i < numBlocks; i++) {
  5098. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5099. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5100. bench_additional, aesAuthAddSz);
  5101. if (ret < 0) {
  5102. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5103. goto exit;
  5104. }
  5105. RECORD_MULTI_VALUE_STATS();
  5106. }
  5107. count += i;
  5108. } while (bench_stats_check(start)
  5109. #ifdef MULTI_VALUE_STATISTICS
  5110. || runs < minimum_runs
  5111. #endif
  5112. );
  5113. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5114. #ifdef MULTI_VALUE_STATISTICS
  5115. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5116. #endif
  5117. exit:
  5118. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5119. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5120. }
  5121. #endif
  5122. #ifdef WOLFSSL_SM4_CCM
  5123. void bench_sm4_ccm(void)
  5124. {
  5125. wc_Sm4 enc;
  5126. double start;
  5127. int ret, i, count;
  5128. DECLARE_MULTI_VALUE_STATS_VARS()
  5129. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5130. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5131. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5132. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5133. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5134. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5135. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5136. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5137. goto exit;
  5138. }
  5139. bench_stats_start(&count, &start);
  5140. do {
  5141. for (i = 0; i < numBlocks; i++) {
  5142. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5143. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5144. bench_additional, 0);
  5145. RECORD_MULTI_VALUE_STATS();
  5146. }
  5147. count += i;
  5148. } while (bench_stats_check(start)
  5149. #ifdef MULTI_VALUE_STATISTICS
  5150. || runs < minimum_runs
  5151. #endif
  5152. );
  5153. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5154. #ifdef MULTI_VALUE_STATISTICS
  5155. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5156. #endif
  5157. if (ret != 0) {
  5158. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5159. goto exit;
  5160. }
  5161. RESET_MULTI_VALUE_STATS_VARS();
  5162. bench_stats_start(&count, &start);
  5163. do {
  5164. for (i = 0; i < numBlocks; i++) {
  5165. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5166. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5167. bench_additional, 0);
  5168. RECORD_MULTI_VALUE_STATS();
  5169. }
  5170. count += i;
  5171. } while (bench_stats_check(start)
  5172. #ifdef MULTI_VALUE_STATISTICS
  5173. || runs < minimum_runs
  5174. #endif
  5175. );
  5176. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5177. #ifdef MULTI_VALUE_STATISTICS
  5178. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5179. #endif
  5180. if (ret != 0) {
  5181. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5182. goto exit;
  5183. }
  5184. exit:
  5185. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5186. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5187. }
  5188. #endif /* HAVE_AESCCM */
  5189. #ifndef NO_DES3
  5190. void bench_des(int useDeviceID)
  5191. {
  5192. int ret = 0, i, count = 0, times, pending = 0;
  5193. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5194. sizeof(Des3), HEAP_HINT);
  5195. double start;
  5196. DECLARE_MULTI_VALUE_STATS_VARS()
  5197. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5198. sizeof(Des3), HEAP_HINT);
  5199. /* init keys */
  5200. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5201. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5202. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5203. printf("Des3Init failed, ret = %d\n", ret);
  5204. goto exit;
  5205. }
  5206. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5207. if (ret != 0) {
  5208. printf("Des3_SetKey failed, ret = %d\n", ret);
  5209. goto exit;
  5210. }
  5211. }
  5212. bench_stats_start(&count, &start);
  5213. do {
  5214. for (times = 0; times < numBlocks || pending > 0; ) {
  5215. bench_async_poll(&pending);
  5216. /* while free pending slots in queue, submit ops */
  5217. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5218. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5219. &times, numBlocks, &pending)) {
  5220. ret = wc_Des3_CbcEncrypt(enc[i],
  5221. bench_cipher,
  5222. bench_plain, bench_size);
  5223. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5224. 0, &times, &pending)) {
  5225. goto exit_3des;
  5226. }
  5227. }
  5228. } /* for i */
  5229. RECORD_MULTI_VALUE_STATS();
  5230. } /* for times */
  5231. count += times;
  5232. } while (bench_stats_check(start)
  5233. #ifdef MULTI_VALUE_STATISTICS
  5234. || runs < minimum_runs
  5235. #endif
  5236. );
  5237. exit_3des:
  5238. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5239. #ifdef MULTI_VALUE_STATISTICS
  5240. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5241. #endif
  5242. exit:
  5243. if (WC_ARRAY_OK(enc)) {
  5244. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5245. wc_Des3Free(enc[i]);
  5246. }
  5247. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5248. }
  5249. }
  5250. #endif /* !NO_DES3 */
  5251. #ifndef NO_RC4
  5252. void bench_arc4(int useDeviceID)
  5253. {
  5254. int ret = 0, i, count = 0, times, pending = 0;
  5255. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5256. sizeof(Arc4), HEAP_HINT);
  5257. double start;
  5258. DECLARE_MULTI_VALUE_STATS_VARS()
  5259. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5260. sizeof(Arc4), HEAP_HINT);
  5261. /* init keys */
  5262. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5263. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5264. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5265. printf("Arc4Init failed, ret = %d\n", ret);
  5266. goto exit;
  5267. }
  5268. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5269. if (ret != 0) {
  5270. printf("Arc4SetKey failed, ret = %d\n", ret);
  5271. goto exit;
  5272. }
  5273. }
  5274. bench_stats_start(&count, &start);
  5275. do {
  5276. for (times = 0; times < numBlocks || pending > 0; ) {
  5277. bench_async_poll(&pending);
  5278. /* while free pending slots in queue, submit ops */
  5279. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5280. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5281. &times, numBlocks, &pending)) {
  5282. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5283. bench_size);
  5284. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5285. 0, &times, &pending)) {
  5286. goto exit_arc4;
  5287. }
  5288. }
  5289. } /* for i */
  5290. RECORD_MULTI_VALUE_STATS();
  5291. } /* for times */
  5292. count += times;
  5293. } while (bench_stats_check(start)
  5294. #ifdef MULTI_VALUE_STATISTICS
  5295. || runs < minimum_runs
  5296. #endif
  5297. );
  5298. exit_arc4:
  5299. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5300. #ifdef MULTI_VALUE_STATISTICS
  5301. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5302. #endif
  5303. exit:
  5304. if (WC_ARRAY_OK(enc)) {
  5305. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5306. wc_Arc4Free(enc[i]);
  5307. }
  5308. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5309. }
  5310. }
  5311. #endif /* !NO_RC4 */
  5312. #ifdef HAVE_CHACHA
  5313. void bench_chacha(void)
  5314. {
  5315. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5316. double start;
  5317. int ret, i, count;
  5318. DECLARE_MULTI_VALUE_STATS_VARS()
  5319. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5320. XMEMSET(enc, 0, sizeof(ChaCha));
  5321. wc_Chacha_SetKey(enc, bench_key, 16);
  5322. if (encrypt_only) {
  5323. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5324. if (ret < 0) {
  5325. printf("wc_Chacha_SetIV error: %d\n", ret);
  5326. goto exit;
  5327. }
  5328. bench_stats_start(&count, &start);
  5329. do {
  5330. for (i = 0; i < numBlocks; i++) {
  5331. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5332. bench_size);
  5333. if (ret < 0) {
  5334. printf("wc_Chacha_Process error: %d\n", ret);
  5335. goto exit;
  5336. }
  5337. RECORD_MULTI_VALUE_STATS();
  5338. }
  5339. count += i;
  5340. } while (bench_stats_check(start)
  5341. #ifdef MULTI_VALUE_STATISTICS
  5342. || runs < minimum_runs
  5343. #endif
  5344. );
  5345. }
  5346. else {
  5347. bench_stats_start(&count, &start);
  5348. do {
  5349. for (i = 0; i < numBlocks; i++) {
  5350. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5351. if (ret < 0) {
  5352. printf("wc_Chacha_SetIV error: %d\n", ret);
  5353. goto exit;
  5354. }
  5355. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5356. bench_size);
  5357. if (ret < 0) {
  5358. printf("wc_Chacha_Process error: %d\n", ret);
  5359. goto exit;
  5360. }
  5361. RECORD_MULTI_VALUE_STATS();
  5362. }
  5363. count += i;
  5364. } while (bench_stats_check(start)
  5365. #ifdef MULTI_VALUE_STATISTICS
  5366. || runs < minimum_runs
  5367. #endif
  5368. );
  5369. }
  5370. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5371. #ifdef MULTI_VALUE_STATISTICS
  5372. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5373. #endif
  5374. exit:
  5375. WC_FREE_VAR(enc, HEAP_HINT);
  5376. }
  5377. #endif /* HAVE_CHACHA*/
  5378. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5379. void bench_chacha20_poly1305_aead(void)
  5380. {
  5381. double start;
  5382. int ret = 0, i, count;
  5383. DECLARE_MULTI_VALUE_STATS_VARS()
  5384. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5385. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5386. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5387. bench_stats_start(&count, &start);
  5388. do {
  5389. for (i = 0; i < numBlocks; i++) {
  5390. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5391. bench_plain, bench_size, bench_cipher, authTag);
  5392. if (ret < 0) {
  5393. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5394. goto exit;
  5395. }
  5396. RECORD_MULTI_VALUE_STATS();
  5397. }
  5398. count += i;
  5399. } while (bench_stats_check(start)
  5400. #ifdef MULTI_VALUE_STATISTICS
  5401. || runs < minimum_runs
  5402. #endif
  5403. );
  5404. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5405. #ifdef MULTI_VALUE_STATISTICS
  5406. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5407. #endif
  5408. exit:
  5409. WC_FREE_VAR(authTag, HEAP_HINT);
  5410. }
  5411. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5412. #ifndef NO_MD5
  5413. void bench_md5(int useDeviceID)
  5414. {
  5415. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5416. sizeof(wc_Md5), HEAP_HINT);
  5417. double start = 0;
  5418. int ret = 0, i, count = 0, times, pending = 0;
  5419. DECLARE_MULTI_VALUE_STATS_VARS()
  5420. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5421. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5422. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5423. sizeof(wc_Md5), HEAP_HINT);
  5424. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5425. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5426. if (digest_stream) {
  5427. /* init keys */
  5428. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5429. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5430. useDeviceID ? devId : INVALID_DEVID);
  5431. if (ret != 0) {
  5432. printf("InitMd5_ex failed, ret = %d\n", ret);
  5433. goto exit;
  5434. }
  5435. #ifdef WOLFSSL_PIC32MZ_HASH
  5436. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5437. #endif
  5438. }
  5439. bench_stats_start(&count, &start);
  5440. do {
  5441. for (times = 0; times < numBlocks || pending > 0; ) {
  5442. bench_async_poll(&pending);
  5443. /* while free pending slots in queue, submit ops */
  5444. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5445. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5446. 0, &times, numBlocks, &pending)) {
  5447. ret = wc_Md5Update(hash[i], bench_plain,
  5448. bench_size);
  5449. if (!bench_async_handle(&ret,
  5450. BENCH_ASYNC_GET_DEV(hash[i]),
  5451. 0, &times, &pending)) {
  5452. goto exit_md5;
  5453. }
  5454. }
  5455. } /* for i */
  5456. RECORD_MULTI_VALUE_STATS();
  5457. } /* for times */
  5458. count += times;
  5459. times = 0;
  5460. do {
  5461. bench_async_poll(&pending);
  5462. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5463. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5464. 0, &times, numBlocks, &pending)) {
  5465. ret = wc_Md5Final(hash[i], digest[i]);
  5466. if (!bench_async_handle(&ret,
  5467. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5468. &times, &pending)) {
  5469. goto exit_md5;
  5470. }
  5471. }
  5472. } /* for i */
  5473. } while (pending > 0);
  5474. } while (bench_stats_check(start)
  5475. #ifdef MULTI_VALUE_STATISTICS
  5476. || runs < minimum_runs
  5477. #endif
  5478. );
  5479. }
  5480. else {
  5481. bench_stats_start(&count, &start);
  5482. do {
  5483. for (times = 0; times < numBlocks; times++) {
  5484. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5485. if (ret == 0)
  5486. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5487. if (ret == 0)
  5488. ret = wc_Md5Final(hash[0], digest[0]);
  5489. if (ret != 0)
  5490. goto exit_md5;
  5491. RECORD_MULTI_VALUE_STATS();
  5492. } /* for times */
  5493. count += times;
  5494. } while (bench_stats_check(start)
  5495. #ifdef MULTI_VALUE_STATISTICS
  5496. || runs < minimum_runs
  5497. #endif
  5498. );
  5499. }
  5500. exit_md5:
  5501. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5502. #ifdef MULTI_VALUE_STATISTICS
  5503. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5504. #endif
  5505. exit:
  5506. #ifdef WOLFSSL_ASYNC_CRYPT
  5507. if (WC_ARRAY_OK(hash)) {
  5508. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5509. wc_Md5Free(hash[i]);
  5510. }
  5511. }
  5512. #endif
  5513. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5514. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5515. }
  5516. #endif /* !NO_MD5 */
  5517. #ifndef NO_SHA
  5518. void bench_sha(int useDeviceID)
  5519. {
  5520. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5521. sizeof(wc_Sha), HEAP_HINT);
  5522. double start;
  5523. int ret = 0, i, count = 0, times, pending = 0;
  5524. DECLARE_MULTI_VALUE_STATS_VARS()
  5525. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5526. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5527. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5528. sizeof(wc_Sha), HEAP_HINT);
  5529. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5530. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5531. if (digest_stream) {
  5532. /* init keys */
  5533. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5534. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5535. useDeviceID ? devId : INVALID_DEVID);
  5536. if (ret != 0) {
  5537. printf("InitSha failed, ret = %d\n", ret);
  5538. goto exit;
  5539. }
  5540. #ifdef WOLFSSL_PIC32MZ_HASH
  5541. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5542. #endif
  5543. }
  5544. bench_stats_start(&count, &start);
  5545. do {
  5546. for (times = 0; times < numBlocks || pending > 0; ) {
  5547. bench_async_poll(&pending);
  5548. /* while free pending slots in queue, submit ops */
  5549. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5550. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5551. 0, &times, numBlocks, &pending)) {
  5552. ret = wc_ShaUpdate(hash[i], bench_plain,
  5553. bench_size);
  5554. if (!bench_async_handle(&ret,
  5555. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5556. &times, &pending)) {
  5557. goto exit_sha;
  5558. }
  5559. }
  5560. } /* for i */
  5561. RECORD_MULTI_VALUE_STATS();
  5562. } /* for times */
  5563. count += times;
  5564. times = 0;
  5565. do {
  5566. bench_async_poll(&pending);
  5567. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5568. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5569. 0, &times, numBlocks, &pending)) {
  5570. ret = wc_ShaFinal(hash[i], digest[i]);
  5571. if (!bench_async_handle(&ret,
  5572. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5573. &times, &pending)) {
  5574. goto exit_sha;
  5575. }
  5576. }
  5577. } /* for i */
  5578. } while (pending > 0);
  5579. } while (bench_stats_check(start)
  5580. #ifdef MULTI_VALUE_STATISTICS
  5581. || runs < minimum_runs
  5582. #endif
  5583. );
  5584. }
  5585. else {
  5586. bench_stats_start(&count, &start);
  5587. do {
  5588. for (times = 0; times < numBlocks; times++) {
  5589. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5590. useDeviceID ? devId : INVALID_DEVID);
  5591. if (ret == 0)
  5592. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5593. if (ret == 0)
  5594. ret = wc_ShaFinal(hash[0], digest[0]);
  5595. if (ret != 0)
  5596. goto exit_sha;
  5597. RECORD_MULTI_VALUE_STATS();
  5598. } /* for times */
  5599. count += times;
  5600. } while (bench_stats_check(start)
  5601. #ifdef MULTI_VALUE_STATISTICS
  5602. || runs < minimum_runs
  5603. #endif
  5604. );
  5605. }
  5606. exit_sha:
  5607. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5608. #ifdef MULTI_VALUE_STATISTICS
  5609. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5610. #endif
  5611. exit:
  5612. if (WC_ARRAY_OK(hash)) {
  5613. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5614. wc_ShaFree(hash[i]);
  5615. }
  5616. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5617. }
  5618. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5619. }
  5620. #endif /* NO_SHA */
  5621. #ifdef WOLFSSL_SHA224
  5622. void bench_sha224(int useDeviceID)
  5623. {
  5624. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5625. sizeof(wc_Sha224), HEAP_HINT);
  5626. double start;
  5627. int ret = 0, i, count = 0, times, pending = 0;
  5628. DECLARE_MULTI_VALUE_STATS_VARS()
  5629. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5630. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5631. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5632. sizeof(wc_Sha224), HEAP_HINT);
  5633. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5634. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5635. if (digest_stream) {
  5636. /* init keys */
  5637. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5638. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5639. useDeviceID ? devId : INVALID_DEVID);
  5640. if (ret != 0) {
  5641. printf("InitSha224_ex failed, ret = %d\n", ret);
  5642. goto exit;
  5643. }
  5644. }
  5645. bench_stats_start(&count, &start);
  5646. do {
  5647. for (times = 0; times < numBlocks || pending > 0; ) {
  5648. bench_async_poll(&pending);
  5649. /* while free pending slots in queue, submit ops */
  5650. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5651. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5652. 0, &times, numBlocks, &pending)) {
  5653. ret = wc_Sha224Update(hash[i], bench_plain,
  5654. bench_size);
  5655. if (!bench_async_handle(&ret,
  5656. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5657. &times, &pending)) {
  5658. goto exit_sha224;
  5659. }
  5660. }
  5661. } /* for i */
  5662. RECORD_MULTI_VALUE_STATS();
  5663. } /* for times */
  5664. count += times;
  5665. times = 0;
  5666. do {
  5667. bench_async_poll(&pending);
  5668. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5669. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5670. 0, &times, numBlocks, &pending)) {
  5671. ret = wc_Sha224Final(hash[i], digest[i]);
  5672. if (!bench_async_handle(&ret,
  5673. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5674. &times, &pending)) {
  5675. goto exit_sha224;
  5676. }
  5677. }
  5678. } /* for i */
  5679. } while (pending > 0);
  5680. } while (bench_stats_check(start)
  5681. #ifdef MULTI_VALUE_STATISTICS
  5682. || runs < minimum_runs
  5683. #endif
  5684. );
  5685. }
  5686. else {
  5687. bench_stats_start(&count, &start);
  5688. do {
  5689. for (times = 0; times < numBlocks; times++) {
  5690. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5691. useDeviceID ? devId : INVALID_DEVID);
  5692. if (ret == 0)
  5693. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5694. if (ret == 0)
  5695. ret = wc_Sha224Final(hash[0], digest[0]);
  5696. if (ret != 0)
  5697. goto exit_sha224;
  5698. } /* for times */
  5699. count += times;
  5700. } while (bench_stats_check(start)
  5701. #ifdef MULTI_VALUE_STATISTICS
  5702. || runs < minimum_runs
  5703. #endif
  5704. );
  5705. }
  5706. exit_sha224:
  5707. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5708. bench_size, start, ret);
  5709. #ifdef MULTI_VALUE_STATISTICS
  5710. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5711. #endif
  5712. exit:
  5713. if (WC_ARRAY_OK(hash)) {
  5714. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5715. wc_Sha224Free(hash[i]);
  5716. }
  5717. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5718. }
  5719. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5720. }
  5721. #endif
  5722. #ifndef NO_SHA256
  5723. void bench_sha256(int useDeviceID)
  5724. {
  5725. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5726. sizeof(wc_Sha256), HEAP_HINT);
  5727. double start;
  5728. int ret = 0, i, count = 0, times, pending = 0;
  5729. DECLARE_MULTI_VALUE_STATS_VARS()
  5730. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5731. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5732. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5733. sizeof(wc_Sha256), HEAP_HINT);
  5734. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5735. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5736. if (digest_stream) {
  5737. /* init keys */
  5738. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5739. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5740. useDeviceID ? devId: INVALID_DEVID);
  5741. if (ret != 0) {
  5742. printf("InitSha256_ex failed, ret = %d\n", ret);
  5743. goto exit;
  5744. }
  5745. #ifdef WOLFSSL_PIC32MZ_HASH
  5746. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5747. #endif
  5748. }
  5749. bench_stats_start(&count, &start);
  5750. do {
  5751. for (times = 0; times < numBlocks || pending > 0; ) {
  5752. bench_async_poll(&pending);
  5753. /* while free pending slots in queue, submit ops */
  5754. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5755. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5756. 0, &times, numBlocks, &pending)) {
  5757. ret = wc_Sha256Update(hash[i], bench_plain,
  5758. bench_size);
  5759. if (!bench_async_handle(&ret,
  5760. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5761. &times, &pending)) {
  5762. goto exit_sha256;
  5763. }
  5764. }
  5765. } /* for i */
  5766. RECORD_MULTI_VALUE_STATS();
  5767. } /* for times */
  5768. count += times;
  5769. times = 0;
  5770. do {
  5771. bench_async_poll(&pending);
  5772. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5773. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5774. 0, &times, numBlocks, &pending)) {
  5775. ret = wc_Sha256Final(hash[i], digest[i]);
  5776. if (!bench_async_handle(&ret,
  5777. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5778. &times, &pending)) {
  5779. goto exit_sha256;
  5780. }
  5781. }
  5782. } /* for i */
  5783. } while (pending > 0);
  5784. } while (bench_stats_check(start)
  5785. #ifdef MULTI_VALUE_STATISTICS
  5786. || runs < minimum_runs
  5787. #endif
  5788. );
  5789. }
  5790. else {
  5791. bench_stats_start(&count, &start);
  5792. do {
  5793. for (times = 0; times < numBlocks; times++) {
  5794. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5795. useDeviceID ? devId: INVALID_DEVID);
  5796. if (ret == 0)
  5797. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5798. if (ret == 0)
  5799. ret = wc_Sha256Final(hash[0], digest[0]);
  5800. if (ret != 0)
  5801. goto exit_sha256;
  5802. RECORD_MULTI_VALUE_STATS();
  5803. } /* for times */
  5804. count += times;
  5805. } while (bench_stats_check(start)
  5806. #ifdef MULTI_VALUE_STATISTICS
  5807. || runs < minimum_runs
  5808. #endif
  5809. );
  5810. }
  5811. exit_sha256:
  5812. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5813. start, ret);
  5814. #ifdef MULTI_VALUE_STATISTICS
  5815. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5816. #endif
  5817. exit:
  5818. if (WC_ARRAY_OK(hash)) {
  5819. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5820. wc_Sha256Free(hash[i]);
  5821. }
  5822. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5823. }
  5824. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5825. }
  5826. #endif
  5827. #ifdef WOLFSSL_SHA384
  5828. void bench_sha384(int useDeviceID)
  5829. {
  5830. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5831. sizeof(wc_Sha384), HEAP_HINT);
  5832. double start;
  5833. int ret = 0, i, count = 0, times, pending = 0;
  5834. DECLARE_MULTI_VALUE_STATS_VARS()
  5835. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5836. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5837. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5838. sizeof(wc_Sha384), HEAP_HINT);
  5839. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5840. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5841. if (digest_stream) {
  5842. /* init keys */
  5843. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5844. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5845. useDeviceID ? devId : INVALID_DEVID);
  5846. if (ret != 0) {
  5847. printf("InitSha384_ex failed, ret = %d\n", ret);
  5848. goto exit;
  5849. }
  5850. }
  5851. bench_stats_start(&count, &start);
  5852. do {
  5853. for (times = 0; times < numBlocks || pending > 0; ) {
  5854. bench_async_poll(&pending);
  5855. /* while free pending slots in queue, submit ops */
  5856. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5857. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5858. 0, &times, numBlocks, &pending)) {
  5859. ret = wc_Sha384Update(hash[i], bench_plain,
  5860. bench_size);
  5861. if (!bench_async_handle(&ret,
  5862. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5863. &times, &pending)) {
  5864. goto exit_sha384;
  5865. }
  5866. }
  5867. } /* for i */
  5868. RECORD_MULTI_VALUE_STATS();
  5869. } /* for times */
  5870. count += times;
  5871. times = 0;
  5872. do {
  5873. bench_async_poll(&pending);
  5874. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5875. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5876. 0, &times, numBlocks, &pending)) {
  5877. ret = wc_Sha384Final(hash[i], digest[i]);
  5878. if (!bench_async_handle(&ret,
  5879. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5880. &times, &pending)) {
  5881. goto exit_sha384;
  5882. }
  5883. }
  5884. } /* for i */
  5885. } while (pending > 0);
  5886. } while (bench_stats_check(start)
  5887. #ifdef MULTI_VALUE_STATISTICS
  5888. || runs < minimum_runs
  5889. #endif
  5890. );
  5891. }
  5892. else {
  5893. bench_stats_start(&count, &start);
  5894. do {
  5895. for (times = 0; times < numBlocks; times++) {
  5896. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5897. useDeviceID ? devId : INVALID_DEVID);
  5898. if (ret == 0)
  5899. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5900. if (ret == 0)
  5901. ret = wc_Sha384Final(hash[0], digest[0]);
  5902. if (ret != 0)
  5903. goto exit_sha384;
  5904. RECORD_MULTI_VALUE_STATS();
  5905. } /* for times */
  5906. count += times;
  5907. } while (bench_stats_check(start)
  5908. #ifdef MULTI_VALUE_STATISTICS
  5909. || runs < minimum_runs
  5910. #endif
  5911. );
  5912. }
  5913. exit_sha384:
  5914. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5915. start, ret);
  5916. #ifdef MULTI_VALUE_STATISTICS
  5917. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5918. #endif
  5919. exit:
  5920. if (WC_ARRAY_OK(hash)) {
  5921. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5922. wc_Sha384Free(hash[i]);
  5923. }
  5924. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5925. }
  5926. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5927. }
  5928. #endif
  5929. #ifdef WOLFSSL_SHA512
  5930. void bench_sha512(int useDeviceID)
  5931. {
  5932. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5933. sizeof(wc_Sha512), HEAP_HINT);
  5934. double start;
  5935. int ret = 0, i, count = 0, times, pending = 0;
  5936. DECLARE_MULTI_VALUE_STATS_VARS()
  5937. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5938. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5939. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5940. sizeof(wc_Sha512), HEAP_HINT);
  5941. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5942. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5943. if (digest_stream) {
  5944. /* init keys */
  5945. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5946. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5947. useDeviceID ? devId : INVALID_DEVID);
  5948. if (ret != 0) {
  5949. printf("InitSha512_ex failed, ret = %d\n", ret);
  5950. goto exit;
  5951. }
  5952. }
  5953. bench_stats_start(&count, &start);
  5954. do {
  5955. for (times = 0; times < numBlocks || pending > 0; ) {
  5956. bench_async_poll(&pending);
  5957. /* while free pending slots in queue, submit ops */
  5958. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5959. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5960. 0, &times, numBlocks, &pending)) {
  5961. ret = wc_Sha512Update(hash[i], bench_plain,
  5962. bench_size);
  5963. if (!bench_async_handle(&ret,
  5964. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5965. &times, &pending)) {
  5966. goto exit_sha512;
  5967. }
  5968. }
  5969. } /* for i */
  5970. RECORD_MULTI_VALUE_STATS();
  5971. } /* for times */
  5972. count += times;
  5973. times = 0;
  5974. do {
  5975. bench_async_poll(&pending);
  5976. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5977. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5978. 0, &times, numBlocks, &pending)) {
  5979. ret = wc_Sha512Final(hash[i], digest[i]);
  5980. if (!bench_async_handle(&ret,
  5981. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5982. &times, &pending)) {
  5983. goto exit_sha512;
  5984. }
  5985. }
  5986. } /* for i */
  5987. } while (pending > 0);
  5988. } while (bench_stats_check(start)
  5989. #ifdef MULTI_VALUE_STATISTICS
  5990. || runs < minimum_runs
  5991. #endif
  5992. );
  5993. }
  5994. else {
  5995. bench_stats_start(&count, &start);
  5996. do {
  5997. for (times = 0; times < numBlocks; times++) {
  5998. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  5999. useDeviceID ? devId : INVALID_DEVID);
  6000. if (ret == 0)
  6001. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  6002. if (ret == 0)
  6003. ret = wc_Sha512Final(hash[0], digest[0]);
  6004. if (ret != 0)
  6005. goto exit_sha512;
  6006. RECORD_MULTI_VALUE_STATS();
  6007. } /* for times */
  6008. count += times;
  6009. } while (bench_stats_check(start)
  6010. #ifdef MULTI_VALUE_STATISTICS
  6011. || runs < minimum_runs
  6012. #endif
  6013. );
  6014. }
  6015. exit_sha512:
  6016. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  6017. start, ret);
  6018. #ifdef MULTI_VALUE_STATISTICS
  6019. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6020. #endif
  6021. exit:
  6022. if (WC_ARRAY_OK(hash)) {
  6023. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6024. wc_Sha512Free(hash[i]);
  6025. }
  6026. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6027. }
  6028. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6029. }
  6030. #if !defined(WOLFSSL_NOSHA512_224) && \
  6031. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6032. void bench_sha512_224(int useDeviceID)
  6033. {
  6034. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6035. sizeof(wc_Sha512_224), HEAP_HINT);
  6036. double start;
  6037. int ret = 0, i, count = 0, times, pending = 0;
  6038. DECLARE_MULTI_VALUE_STATS_VARS()
  6039. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6040. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6041. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6042. sizeof(wc_Sha512_224), HEAP_HINT);
  6043. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6044. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6045. if (digest_stream) {
  6046. /* init keys */
  6047. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6048. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6049. useDeviceID ? devId : INVALID_DEVID);
  6050. if (ret != 0) {
  6051. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6052. goto exit;
  6053. }
  6054. }
  6055. bench_stats_start(&count, &start);
  6056. do {
  6057. for (times = 0; times < numBlocks || pending > 0; ) {
  6058. bench_async_poll(&pending);
  6059. /* while free pending slots in queue, submit ops */
  6060. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6061. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6062. 0, &times, numBlocks, &pending)) {
  6063. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6064. bench_size);
  6065. if (!bench_async_handle(&ret,
  6066. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6067. &times, &pending)) {
  6068. goto exit_sha512_224;
  6069. }
  6070. }
  6071. } /* for i */
  6072. RECORD_MULTI_VALUE_STATS();
  6073. } /* for times */
  6074. count += times;
  6075. times = 0;
  6076. do {
  6077. bench_async_poll(&pending);
  6078. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6079. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6080. 0, &times, numBlocks, &pending)) {
  6081. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6082. if (!bench_async_handle(&ret,
  6083. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6084. &times, &pending)) {
  6085. goto exit_sha512_224;
  6086. }
  6087. }
  6088. } /* for i */
  6089. } while (pending > 0);
  6090. } while (bench_stats_check(start)
  6091. #ifdef MULTI_VALUE_STATISTICS
  6092. || runs < minimum_runs
  6093. #endif
  6094. );
  6095. }
  6096. else {
  6097. bench_stats_start(&count, &start);
  6098. do {
  6099. for (times = 0; times < numBlocks; times++) {
  6100. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6101. useDeviceID ? devId : INVALID_DEVID);
  6102. if (ret == 0)
  6103. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6104. if (ret == 0)
  6105. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6106. if (ret != 0)
  6107. goto exit_sha512_224;
  6108. RECORD_MULTI_VALUE_STATS();
  6109. } /* for times */
  6110. count += times;
  6111. } while (bench_stats_check(start)
  6112. #ifdef MULTI_VALUE_STATISTICS
  6113. || runs < minimum_runs
  6114. #endif
  6115. );
  6116. }
  6117. exit_sha512_224:
  6118. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6119. start, ret);
  6120. #ifdef MULTI_VALUE_STATISTICS
  6121. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6122. #endif
  6123. exit:
  6124. if (WC_ARRAY_OK(hash)) {
  6125. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6126. wc_Sha512_224Free(hash[i]);
  6127. }
  6128. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6129. }
  6130. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6131. }
  6132. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6133. #if !defined(WOLFSSL_NOSHA512_256) && \
  6134. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6135. void bench_sha512_256(int useDeviceID)
  6136. {
  6137. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6138. sizeof(wc_Sha512_256), HEAP_HINT);
  6139. double start;
  6140. int ret = 0, i, count = 0, times, pending = 0;
  6141. DECLARE_MULTI_VALUE_STATS_VARS()
  6142. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6143. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6144. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6145. sizeof(wc_Sha512_256), HEAP_HINT);
  6146. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6147. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6148. if (digest_stream) {
  6149. /* init keys */
  6150. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6151. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6152. useDeviceID ? devId : INVALID_DEVID);
  6153. if (ret != 0) {
  6154. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6155. goto exit;
  6156. }
  6157. }
  6158. bench_stats_start(&count, &start);
  6159. do {
  6160. for (times = 0; times < numBlocks || pending > 0; ) {
  6161. bench_async_poll(&pending);
  6162. /* while free pending slots in queue, submit ops */
  6163. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6164. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6165. 0, &times, numBlocks, &pending)) {
  6166. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6167. bench_size);
  6168. if (!bench_async_handle(&ret,
  6169. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6170. &times, &pending)) {
  6171. goto exit_sha512_256;
  6172. }
  6173. }
  6174. } /* for i */
  6175. RECORD_MULTI_VALUE_STATS();
  6176. } /* for times */
  6177. count += times;
  6178. times = 0;
  6179. do {
  6180. bench_async_poll(&pending);
  6181. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6182. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6183. 0, &times, numBlocks, &pending)) {
  6184. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6185. if (!bench_async_handle(&ret,
  6186. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6187. &times, &pending)) {
  6188. goto exit_sha512_256;
  6189. }
  6190. }
  6191. } /* for i */
  6192. } while (pending > 0);
  6193. } while (bench_stats_check(start)
  6194. #ifdef MULTI_VALUE_STATISTICS
  6195. || runs < minimum_runs
  6196. #endif
  6197. );
  6198. }
  6199. else {
  6200. bench_stats_start(&count, &start);
  6201. do {
  6202. for (times = 0; times < numBlocks; times++) {
  6203. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6204. useDeviceID ? devId : INVALID_DEVID);
  6205. if (ret == 0)
  6206. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6207. if (ret == 0)
  6208. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6209. if (ret != 0)
  6210. goto exit_sha512_256;
  6211. RECORD_MULTI_VALUE_STATS();
  6212. } /* for times */
  6213. count += times;
  6214. } while (bench_stats_check(start)
  6215. #ifdef MULTI_VALUE_STATISTICS
  6216. || runs < minimum_runs
  6217. #endif
  6218. );
  6219. }
  6220. exit_sha512_256:
  6221. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6222. start, ret);
  6223. #ifdef MULTI_VALUE_STATISTICS
  6224. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6225. #endif
  6226. exit:
  6227. if (WC_ARRAY_OK(hash)) {
  6228. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6229. wc_Sha512_256Free(hash[i]);
  6230. }
  6231. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6232. }
  6233. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6234. }
  6235. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6236. #endif /* WOLFSSL_SHA512 */
  6237. #ifdef WOLFSSL_SHA3
  6238. #ifndef WOLFSSL_NOSHA3_224
  6239. void bench_sha3_224(int useDeviceID)
  6240. {
  6241. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6242. sizeof(wc_Sha3), HEAP_HINT);
  6243. double start;
  6244. int ret = 0, i, count = 0, times, pending = 0;
  6245. DECLARE_MULTI_VALUE_STATS_VARS()
  6246. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6247. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6248. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6249. sizeof(wc_Sha3), HEAP_HINT);
  6250. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6251. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6252. if (digest_stream) {
  6253. /* init keys */
  6254. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6255. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6256. useDeviceID ? devId : INVALID_DEVID);
  6257. if (ret != 0) {
  6258. printf("InitSha3_224 failed, ret = %d\n", ret);
  6259. goto exit;
  6260. }
  6261. }
  6262. bench_stats_start(&count, &start);
  6263. do {
  6264. for (times = 0; times < numBlocks || pending > 0; ) {
  6265. bench_async_poll(&pending);
  6266. /* while free pending slots in queue, submit ops */
  6267. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6268. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6269. 0, &times, numBlocks, &pending)) {
  6270. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6271. bench_size);
  6272. if (!bench_async_handle(&ret,
  6273. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6274. &times, &pending)) {
  6275. goto exit_sha3_224;
  6276. }
  6277. }
  6278. } /* for i */
  6279. RECORD_MULTI_VALUE_STATS();
  6280. } /* for times */
  6281. count += times;
  6282. times = 0;
  6283. do {
  6284. bench_async_poll(&pending);
  6285. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6286. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6287. 0, &times, numBlocks, &pending)) {
  6288. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6289. if (!bench_async_handle(&ret,
  6290. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6291. &times, &pending)) {
  6292. goto exit_sha3_224;
  6293. }
  6294. }
  6295. } /* for i */
  6296. } while (pending > 0);
  6297. } while (bench_stats_check(start)
  6298. #ifdef MULTI_VALUE_STATISTICS
  6299. || runs < minimum_runs
  6300. #endif
  6301. );
  6302. }
  6303. else {
  6304. bench_stats_start(&count, &start);
  6305. do {
  6306. for (times = 0; times < numBlocks; times++) {
  6307. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6308. useDeviceID ? devId : INVALID_DEVID);
  6309. if (ret == 0)
  6310. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6311. if (ret == 0)
  6312. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6313. if (ret != 0)
  6314. goto exit_sha3_224;
  6315. RECORD_MULTI_VALUE_STATS();
  6316. } /* for times */
  6317. count += times;
  6318. } while (bench_stats_check(start)
  6319. #ifdef MULTI_VALUE_STATISTICS
  6320. || runs < minimum_runs
  6321. #endif
  6322. );
  6323. }
  6324. exit_sha3_224:
  6325. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6326. start, ret);
  6327. #ifdef MULTI_VALUE_STATISTICS
  6328. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6329. #endif
  6330. exit:
  6331. if (WC_ARRAY_OK(hash)) {
  6332. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6333. wc_Sha3_224_Free(hash[i]);
  6334. }
  6335. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6336. }
  6337. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6338. }
  6339. #endif /* WOLFSSL_NOSHA3_224 */
  6340. #ifndef WOLFSSL_NOSHA3_256
  6341. void bench_sha3_256(int useDeviceID)
  6342. {
  6343. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6344. sizeof(wc_Sha3), HEAP_HINT);
  6345. double start;
  6346. DECLARE_MULTI_VALUE_STATS_VARS()
  6347. int ret = 0, i, count = 0, times, pending = 0;
  6348. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6349. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6350. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6351. sizeof(wc_Sha3), HEAP_HINT);
  6352. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6353. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6354. if (digest_stream) {
  6355. /* init keys */
  6356. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6357. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6358. useDeviceID ? devId : INVALID_DEVID);
  6359. if (ret != 0) {
  6360. printf("InitSha3_256 failed, ret = %d\n", ret);
  6361. goto exit;
  6362. }
  6363. }
  6364. bench_stats_start(&count, &start);
  6365. do {
  6366. for (times = 0; times < numBlocks || pending > 0; ) {
  6367. bench_async_poll(&pending);
  6368. /* while free pending slots in queue, submit ops */
  6369. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6370. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6371. 0, &times, numBlocks, &pending)) {
  6372. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6373. bench_size);
  6374. if (!bench_async_handle(&ret,
  6375. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6376. &times, &pending)) {
  6377. goto exit_sha3_256;
  6378. }
  6379. }
  6380. } /* for i */
  6381. RECORD_MULTI_VALUE_STATS();
  6382. } /* for times */
  6383. count += times;
  6384. times = 0;
  6385. do {
  6386. bench_async_poll(&pending);
  6387. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6388. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6389. 0, &times, numBlocks, &pending)) {
  6390. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6391. if (!bench_async_handle(&ret,
  6392. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6393. &times, &pending)) {
  6394. goto exit_sha3_256;
  6395. }
  6396. }
  6397. } /* for i */
  6398. } while (pending > 0);
  6399. } while (bench_stats_check(start)
  6400. #ifdef MULTI_VALUE_STATISTICS
  6401. || runs < minimum_runs
  6402. #endif
  6403. );
  6404. }
  6405. else {
  6406. bench_stats_start(&count, &start);
  6407. do {
  6408. for (times = 0; times < numBlocks; times++) {
  6409. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6410. useDeviceID ? devId : INVALID_DEVID);
  6411. if (ret == 0)
  6412. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6413. if (ret == 0)
  6414. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6415. if (ret != 0)
  6416. goto exit_sha3_256;
  6417. RECORD_MULTI_VALUE_STATS();
  6418. } /* for times */
  6419. count += times;
  6420. } while (bench_stats_check(start)
  6421. #ifdef MULTI_VALUE_STATISTICS
  6422. || runs < minimum_runs
  6423. #endif
  6424. );
  6425. }
  6426. exit_sha3_256:
  6427. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6428. start, ret);
  6429. #ifdef MULTI_VALUE_STATISTICS
  6430. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6431. #endif
  6432. exit:
  6433. if (WC_ARRAY_OK(hash)) {
  6434. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6435. wc_Sha3_256_Free(hash[i]);
  6436. }
  6437. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6438. }
  6439. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6440. }
  6441. #endif /* WOLFSSL_NOSHA3_256 */
  6442. #ifndef WOLFSSL_NOSHA3_384
  6443. void bench_sha3_384(int useDeviceID)
  6444. {
  6445. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6446. sizeof(wc_Sha3), HEAP_HINT);
  6447. double start;
  6448. int ret = 0, i, count = 0, times, pending = 0;
  6449. DECLARE_MULTI_VALUE_STATS_VARS()
  6450. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6451. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6452. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6453. sizeof(wc_Sha3), HEAP_HINT);
  6454. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6455. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6456. if (digest_stream) {
  6457. /* init keys */
  6458. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6459. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6460. useDeviceID ? devId : INVALID_DEVID);
  6461. if (ret != 0) {
  6462. printf("InitSha3_384 failed, ret = %d\n", ret);
  6463. goto exit;
  6464. }
  6465. }
  6466. bench_stats_start(&count, &start);
  6467. do {
  6468. for (times = 0; times < numBlocks || pending > 0; ) {
  6469. bench_async_poll(&pending);
  6470. /* while free pending slots in queue, submit ops */
  6471. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6472. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6473. 0, &times, numBlocks, &pending)) {
  6474. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6475. bench_size);
  6476. if (!bench_async_handle(&ret,
  6477. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6478. &times, &pending)) {
  6479. goto exit_sha3_384;
  6480. }
  6481. }
  6482. } /* for i */
  6483. RECORD_MULTI_VALUE_STATS();
  6484. } /* for times */
  6485. count += times;
  6486. times = 0;
  6487. do {
  6488. bench_async_poll(&pending);
  6489. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6490. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6491. 0, &times, numBlocks, &pending)) {
  6492. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6493. if (!bench_async_handle(&ret,
  6494. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6495. &times, &pending)) {
  6496. goto exit_sha3_384;
  6497. }
  6498. }
  6499. } /* for i */
  6500. } while (pending > 0);
  6501. } while (bench_stats_check(start)
  6502. #ifdef MULTI_VALUE_STATISTICS
  6503. || runs < minimum_runs
  6504. #endif
  6505. );
  6506. }
  6507. else {
  6508. bench_stats_start(&count, &start);
  6509. do {
  6510. for (times = 0; times < numBlocks; times++) {
  6511. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6512. useDeviceID ? devId : INVALID_DEVID);
  6513. if (ret == 0)
  6514. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6515. if (ret == 0)
  6516. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6517. if (ret != 0)
  6518. goto exit_sha3_384;
  6519. RECORD_MULTI_VALUE_STATS();
  6520. } /* for times */
  6521. count += times;
  6522. } while (bench_stats_check(start)
  6523. #ifdef MULTI_VALUE_STATISTICS
  6524. || runs < minimum_runs
  6525. #endif
  6526. );
  6527. }
  6528. exit_sha3_384:
  6529. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6530. start, ret);
  6531. #ifdef MULTI_VALUE_STATISTICS
  6532. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6533. #endif
  6534. exit:
  6535. if (WC_ARRAY_OK(hash)) {
  6536. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6537. wc_Sha3_384_Free(hash[i]);
  6538. }
  6539. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6540. }
  6541. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6542. }
  6543. #endif /* WOLFSSL_NOSHA3_384 */
  6544. #ifndef WOLFSSL_NOSHA3_512
  6545. void bench_sha3_512(int useDeviceID)
  6546. {
  6547. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6548. sizeof(wc_Sha3), HEAP_HINT);
  6549. double start;
  6550. int ret = 0, i, count = 0, times, pending = 0;
  6551. DECLARE_MULTI_VALUE_STATS_VARS()
  6552. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6553. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6554. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6555. sizeof(wc_Sha3), HEAP_HINT);
  6556. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6557. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6558. if (digest_stream) {
  6559. /* init keys */
  6560. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6561. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6562. useDeviceID ? devId : INVALID_DEVID);
  6563. if (ret != 0) {
  6564. printf("InitSha3_512 failed, ret = %d\n", ret);
  6565. goto exit;
  6566. }
  6567. }
  6568. bench_stats_start(&count, &start);
  6569. do {
  6570. for (times = 0; times < numBlocks || pending > 0; ) {
  6571. bench_async_poll(&pending);
  6572. /* while free pending slots in queue, submit ops */
  6573. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6574. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6575. 0, &times, numBlocks, &pending)) {
  6576. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6577. bench_size);
  6578. if (!bench_async_handle(&ret,
  6579. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6580. &times, &pending)) {
  6581. goto exit_sha3_512;
  6582. }
  6583. }
  6584. } /* for i */
  6585. RECORD_MULTI_VALUE_STATS();
  6586. } /* for times */
  6587. count += times;
  6588. times = 0;
  6589. do {
  6590. bench_async_poll(&pending);
  6591. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6592. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6593. 0, &times, numBlocks, &pending)) {
  6594. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6595. if (!bench_async_handle(&ret,
  6596. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6597. &times, &pending)) {
  6598. goto exit_sha3_512;
  6599. }
  6600. }
  6601. } /* for i */
  6602. } while (pending > 0);
  6603. } while (bench_stats_check(start)
  6604. #ifdef MULTI_VALUE_STATISTICS
  6605. || runs < minimum_runs
  6606. #endif
  6607. );
  6608. }
  6609. else {
  6610. bench_stats_start(&count, &start);
  6611. do {
  6612. for (times = 0; times < numBlocks; times++) {
  6613. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6614. useDeviceID ? devId : INVALID_DEVID);
  6615. if (ret == 0)
  6616. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6617. if (ret == 0)
  6618. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6619. if (ret != 0)
  6620. goto exit_sha3_512;
  6621. RECORD_MULTI_VALUE_STATS();
  6622. } /* for times */
  6623. count += times;
  6624. } while (bench_stats_check(start)
  6625. #ifdef MULTI_VALUE_STATISTICS
  6626. || runs < minimum_runs
  6627. #endif
  6628. );
  6629. }
  6630. exit_sha3_512:
  6631. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6632. start, ret);
  6633. #ifdef MULTI_VALUE_STATISTICS
  6634. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6635. #endif
  6636. exit:
  6637. if (WC_ARRAY_OK(hash)) {
  6638. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6639. wc_Sha3_512_Free(hash[i]);
  6640. }
  6641. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6642. }
  6643. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6644. }
  6645. #endif /* WOLFSSL_NOSHA3_512 */
  6646. #ifdef WOLFSSL_SHAKE128
  6647. void bench_shake128(int useDeviceID)
  6648. {
  6649. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6650. sizeof(wc_Shake), HEAP_HINT);
  6651. double start;
  6652. int ret = 0, i, count = 0, times, pending = 0;
  6653. DECLARE_MULTI_VALUE_STATS_VARS()
  6654. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6655. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6656. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6657. sizeof(wc_Shake), HEAP_HINT);
  6658. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6659. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6660. if (digest_stream) {
  6661. /* init keys */
  6662. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6663. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6664. useDeviceID ? devId : INVALID_DEVID);
  6665. if (ret != 0) {
  6666. printf("InitShake128 failed, ret = %d\n", ret);
  6667. goto exit;
  6668. }
  6669. }
  6670. bench_stats_start(&count, &start);
  6671. do {
  6672. for (times = 0; times < numBlocks || pending > 0; ) {
  6673. bench_async_poll(&pending);
  6674. /* while free pending slots in queue, submit ops */
  6675. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6676. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6677. 0, &times, numBlocks, &pending)) {
  6678. ret = wc_Shake128_Update(hash[i], bench_plain,
  6679. bench_size);
  6680. if (!bench_async_handle(&ret,
  6681. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6682. &times, &pending)) {
  6683. goto exit_shake128;
  6684. }
  6685. }
  6686. } /* for i */
  6687. RECORD_MULTI_VALUE_STATS();
  6688. } /* for times */
  6689. count += times;
  6690. times = 0;
  6691. do {
  6692. bench_async_poll(&pending);
  6693. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6694. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6695. 0, &times, numBlocks, &pending)) {
  6696. ret = wc_Shake128_Final(hash[i], digest[i],
  6697. WC_SHA3_128_BLOCK_SIZE);
  6698. if (!bench_async_handle(&ret,
  6699. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6700. &times, &pending)) {
  6701. goto exit_shake128;
  6702. }
  6703. }
  6704. } /* for i */
  6705. } while (pending > 0);
  6706. } while (bench_stats_check(start)
  6707. #ifdef MULTI_VALUE_STATISTICS
  6708. || runs < minimum_runs
  6709. #endif
  6710. );
  6711. }
  6712. else {
  6713. bench_stats_start(&count, &start);
  6714. do {
  6715. for (times = 0; times < numBlocks; times++) {
  6716. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6717. useDeviceID ? devId : INVALID_DEVID);
  6718. if (ret == 0)
  6719. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6720. if (ret == 0)
  6721. ret = wc_Shake128_Final(hash[0], digest[0],
  6722. WC_SHA3_128_BLOCK_SIZE);
  6723. if (ret != 0)
  6724. goto exit_shake128;
  6725. RECORD_MULTI_VALUE_STATS();
  6726. } /* for times */
  6727. count += times;
  6728. } while (bench_stats_check(start)
  6729. #ifdef MULTI_VALUE_STATISTICS
  6730. || runs < minimum_runs
  6731. #endif
  6732. );
  6733. }
  6734. exit_shake128:
  6735. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6736. start, ret);
  6737. #ifdef MULTI_VALUE_STATISTICS
  6738. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6739. #endif
  6740. exit:
  6741. if (WC_ARRAY_OK(hash)) {
  6742. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6743. wc_Shake128_Free(hash[i]);
  6744. }
  6745. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6746. }
  6747. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6748. }
  6749. #endif /* WOLFSSL_SHAKE128 */
  6750. #ifdef WOLFSSL_SHAKE256
  6751. void bench_shake256(int useDeviceID)
  6752. {
  6753. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6754. sizeof(wc_Shake), HEAP_HINT);
  6755. double start;
  6756. int ret = 0, i, count = 0, times, pending = 0;
  6757. DECLARE_MULTI_VALUE_STATS_VARS()
  6758. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6759. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6760. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6761. sizeof(wc_Shake), HEAP_HINT);
  6762. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6763. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6764. if (digest_stream) {
  6765. /* init keys */
  6766. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6767. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6768. useDeviceID ? devId : INVALID_DEVID);
  6769. if (ret != 0) {
  6770. printf("InitShake256 failed, ret = %d\n", ret);
  6771. goto exit;
  6772. }
  6773. }
  6774. bench_stats_start(&count, &start);
  6775. do {
  6776. for (times = 0; times < numBlocks || pending > 0; ) {
  6777. bench_async_poll(&pending);
  6778. /* while free pending slots in queue, submit ops */
  6779. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6780. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6781. 0, &times, numBlocks, &pending)) {
  6782. ret = wc_Shake256_Update(hash[i], bench_plain,
  6783. bench_size);
  6784. if (!bench_async_handle(&ret,
  6785. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6786. &times, &pending)) {
  6787. goto exit_shake256;
  6788. }
  6789. }
  6790. } /* for i */
  6791. RECORD_MULTI_VALUE_STATS();
  6792. } /* for times */
  6793. count += times;
  6794. times = 0;
  6795. do {
  6796. bench_async_poll(&pending);
  6797. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6798. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6799. 0, &times, numBlocks, &pending)) {
  6800. ret = wc_Shake256_Final(hash[i], digest[i],
  6801. WC_SHA3_256_BLOCK_SIZE);
  6802. if (!bench_async_handle(&ret,
  6803. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6804. &times, &pending)) {
  6805. goto exit_shake256;
  6806. }
  6807. }
  6808. } /* for i */
  6809. } while (pending > 0);
  6810. } while (bench_stats_check(start)
  6811. #ifdef MULTI_VALUE_STATISTICS
  6812. || runs < minimum_runs
  6813. #endif
  6814. );
  6815. }
  6816. else {
  6817. bench_stats_start(&count, &start);
  6818. do {
  6819. for (times = 0; times < numBlocks; times++) {
  6820. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6821. useDeviceID ? devId : INVALID_DEVID);
  6822. if (ret == 0)
  6823. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6824. if (ret == 0)
  6825. ret = wc_Shake256_Final(hash[0], digest[0],
  6826. WC_SHA3_256_BLOCK_SIZE);
  6827. if (ret != 0)
  6828. goto exit_shake256;
  6829. RECORD_MULTI_VALUE_STATS();
  6830. } /* for times */
  6831. count += times;
  6832. } while (bench_stats_check(start)
  6833. #ifdef MULTI_VALUE_STATISTICS
  6834. || runs < minimum_runs
  6835. #endif
  6836. );
  6837. }
  6838. exit_shake256:
  6839. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6840. start, ret);
  6841. #ifdef MULTI_VALUE_STATISTICS
  6842. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6843. #endif
  6844. exit:
  6845. if (WC_ARRAY_OK(hash)) {
  6846. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6847. wc_Shake256_Free(hash[i]);
  6848. }
  6849. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6850. }
  6851. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6852. }
  6853. #endif /* WOLFSSL_SHAKE256 */
  6854. #endif
  6855. #ifdef WOLFSSL_SM3
  6856. void bench_sm3(int useDeviceID)
  6857. {
  6858. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6859. sizeof(wc_Sm3), HEAP_HINT);
  6860. double start;
  6861. int ret = 0, i, count = 0, times, pending = 0;
  6862. DECLARE_MULTI_VALUE_STATS_VARS()
  6863. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6864. HEAP_HINT);
  6865. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6866. sizeof(wc_Sm3), HEAP_HINT);
  6867. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6868. HEAP_HINT);
  6869. if (digest_stream) {
  6870. /* init keys */
  6871. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6872. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6873. useDeviceID ? devId: INVALID_DEVID);
  6874. if (ret != 0) {
  6875. printf("InitSm3 failed, ret = %d\n", ret);
  6876. goto exit;
  6877. }
  6878. }
  6879. bench_stats_start(&count, &start);
  6880. do {
  6881. for (times = 0; times < numBlocks || pending > 0; ) {
  6882. bench_async_poll(&pending);
  6883. /* while free pending slots in queue, submit ops */
  6884. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6885. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6886. 0, &times, numBlocks, &pending)) {
  6887. ret = wc_Sm3Update(hash[i], bench_plain,
  6888. bench_size);
  6889. if (!bench_async_handle(&ret,
  6890. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6891. goto exit_sm3;
  6892. }
  6893. }
  6894. } /* for i */
  6895. RECORD_MULTI_VALUE_STATS();
  6896. } /* for times */
  6897. count += times;
  6898. times = 0;
  6899. do {
  6900. bench_async_poll(&pending);
  6901. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6902. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6903. 0, &times, numBlocks, &pending)) {
  6904. ret = wc_Sm3Final(hash[i], digest[i]);
  6905. if (!bench_async_handle(&ret,
  6906. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6907. goto exit_sm3;
  6908. }
  6909. }
  6910. } /* for i */
  6911. } while (pending > 0);
  6912. } while (bench_stats_check(start)
  6913. #ifdef MULTI_VALUE_STATISTICS
  6914. || runs < minimum_runs
  6915. #endif
  6916. );
  6917. }
  6918. else {
  6919. bench_stats_start(&count, &start);
  6920. do {
  6921. for (times = 0; times < numBlocks; times++) {
  6922. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6923. useDeviceID ? devId: INVALID_DEVID);
  6924. if (ret == 0)
  6925. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6926. if (ret == 0)
  6927. ret = wc_Sm3Final(hash[0], digest[0]);
  6928. if (ret != 0)
  6929. goto exit_sm3;
  6930. RECORD_MULTI_VALUE_STATS();
  6931. } /* for times */
  6932. count += times;
  6933. } while (bench_stats_check(start)
  6934. #ifdef MULTI_VALUE_STATISTICS
  6935. || runs < minimum_runs
  6936. #endif
  6937. );
  6938. }
  6939. exit_sm3:
  6940. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6941. #ifdef MULTI_VALUE_STATISTICS
  6942. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6943. #endif
  6944. exit:
  6945. if (WC_ARRAY_OK(hash)) {
  6946. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6947. wc_Sm3Free(hash[i]);
  6948. }
  6949. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6950. }
  6951. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6952. }
  6953. #endif
  6954. #ifdef WOLFSSL_RIPEMD
  6955. void bench_ripemd(void)
  6956. {
  6957. RipeMd hash;
  6958. byte digest[RIPEMD_DIGEST_SIZE];
  6959. double start;
  6960. int i, count, ret = 0;
  6961. DECLARE_MULTI_VALUE_STATS_VARS()
  6962. if (digest_stream) {
  6963. ret = wc_InitRipeMd(&hash);
  6964. if (ret != 0) {
  6965. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6966. return;
  6967. }
  6968. bench_stats_start(&count, &start);
  6969. do {
  6970. for (i = 0; i < numBlocks; i++) {
  6971. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6972. if (ret != 0) {
  6973. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6974. return;
  6975. }
  6976. RECORD_MULTI_VALUE_STATS();
  6977. }
  6978. ret = wc_RipeMdFinal(&hash, digest);
  6979. if (ret != 0) {
  6980. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6981. return;
  6982. }
  6983. count += i;
  6984. } while (bench_stats_check(start)
  6985. #ifdef MULTI_VALUE_STATISTICS
  6986. || runs < minimum_runs
  6987. #endif
  6988. );
  6989. }
  6990. else {
  6991. bench_stats_start(&count, &start);
  6992. do {
  6993. for (i = 0; i < numBlocks; i++) {
  6994. ret = wc_InitRipeMd(&hash);
  6995. if (ret != 0) {
  6996. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6997. return;
  6998. }
  6999. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  7000. if (ret != 0) {
  7001. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7002. return;
  7003. }
  7004. ret = wc_RipeMdFinal(&hash, digest);
  7005. if (ret != 0) {
  7006. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7007. return;
  7008. }
  7009. RECORD_MULTI_VALUE_STATS();
  7010. }
  7011. count += i;
  7012. } while (bench_stats_check(start)
  7013. #ifdef MULTI_VALUE_STATISTICS
  7014. || runs < minimum_runs
  7015. #endif
  7016. );
  7017. }
  7018. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  7019. #ifdef MULTI_VALUE_STATISTICS
  7020. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7021. #endif
  7022. return;
  7023. }
  7024. #endif
  7025. #ifdef HAVE_BLAKE2
  7026. void bench_blake2b(void)
  7027. {
  7028. Blake2b b2b;
  7029. byte digest[64];
  7030. double start;
  7031. int ret = 0, i, count;
  7032. DECLARE_MULTI_VALUE_STATS_VARS()
  7033. if (digest_stream) {
  7034. ret = wc_InitBlake2b(&b2b, 64);
  7035. if (ret != 0) {
  7036. printf("InitBlake2b failed, ret = %d\n", ret);
  7037. return;
  7038. }
  7039. bench_stats_start(&count, &start);
  7040. do {
  7041. for (i = 0; i < numBlocks; i++) {
  7042. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7043. if (ret != 0) {
  7044. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7045. return;
  7046. }
  7047. RECORD_MULTI_VALUE_STATS();
  7048. }
  7049. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7050. if (ret != 0) {
  7051. printf("Blake2bFinal failed, ret = %d\n", ret);
  7052. return;
  7053. }
  7054. count += i;
  7055. } while (bench_stats_check(start)
  7056. #ifdef MULTI_VALUE_STATISTICS
  7057. || runs < minimum_runs
  7058. #endif
  7059. );
  7060. }
  7061. else {
  7062. bench_stats_start(&count, &start);
  7063. do {
  7064. for (i = 0; i < numBlocks; i++) {
  7065. ret = wc_InitBlake2b(&b2b, 64);
  7066. if (ret != 0) {
  7067. printf("InitBlake2b failed, ret = %d\n", ret);
  7068. return;
  7069. }
  7070. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7071. if (ret != 0) {
  7072. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7073. return;
  7074. }
  7075. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7076. if (ret != 0) {
  7077. printf("Blake2bFinal failed, ret = %d\n", ret);
  7078. return;
  7079. }
  7080. RECORD_MULTI_VALUE_STATS();
  7081. }
  7082. count += i;
  7083. } while (bench_stats_check(start)
  7084. #ifdef MULTI_VALUE_STATISTICS
  7085. || runs < minimum_runs
  7086. #endif
  7087. );
  7088. }
  7089. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7090. #ifdef MULTI_VALUE_STATISTICS
  7091. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7092. #endif
  7093. }
  7094. #endif
  7095. #if defined(HAVE_BLAKE2S)
  7096. void bench_blake2s(void)
  7097. {
  7098. Blake2s b2s;
  7099. byte digest[32];
  7100. double start;
  7101. int ret = 0, i, count;
  7102. DECLARE_MULTI_VALUE_STATS_VARS()
  7103. if (digest_stream) {
  7104. ret = wc_InitBlake2s(&b2s, 32);
  7105. if (ret != 0) {
  7106. printf("InitBlake2s failed, ret = %d\n", ret);
  7107. return;
  7108. }
  7109. bench_stats_start(&count, &start);
  7110. do {
  7111. for (i = 0; i < numBlocks; i++) {
  7112. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7113. if (ret != 0) {
  7114. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7115. return;
  7116. }
  7117. RECORD_MULTI_VALUE_STATS();
  7118. }
  7119. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7120. if (ret != 0) {
  7121. printf("Blake2sFinal failed, ret = %d\n", ret);
  7122. return;
  7123. }
  7124. count += i;
  7125. } while (bench_stats_check(start)
  7126. #ifdef MULTI_VALUE_STATISTICS
  7127. || runs < minimum_runs
  7128. #endif
  7129. );
  7130. }
  7131. else {
  7132. bench_stats_start(&count, &start);
  7133. do {
  7134. for (i = 0; i < numBlocks; i++) {
  7135. ret = wc_InitBlake2s(&b2s, 32);
  7136. if (ret != 0) {
  7137. printf("InitBlake2b failed, ret = %d\n", ret);
  7138. return;
  7139. }
  7140. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7141. if (ret != 0) {
  7142. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7143. return;
  7144. }
  7145. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7146. if (ret != 0) {
  7147. printf("Blake2sFinal failed, ret = %d\n", ret);
  7148. return;
  7149. }
  7150. RECORD_MULTI_VALUE_STATS();
  7151. }
  7152. count += i;
  7153. } while (bench_stats_check(start)
  7154. #ifdef MULTI_VALUE_STATISTICS
  7155. || runs < minimum_runs
  7156. #endif
  7157. );
  7158. }
  7159. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7160. #ifdef MULTI_VALUE_STATISTICS
  7161. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7162. #endif
  7163. }
  7164. #endif
  7165. #ifdef WOLFSSL_CMAC
  7166. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7167. {
  7168. Cmac cmac;
  7169. byte digest[AES_BLOCK_SIZE];
  7170. word32 digestSz = sizeof(digest);
  7171. double start;
  7172. int ret, i, count;
  7173. DECLARE_MULTI_VALUE_STATS_VARS()
  7174. #ifdef WOLFSSL_SECO_CAAM
  7175. unsigned int keyID;
  7176. int keyGroup = 1; /* group one was chosen arbitrarily */
  7177. int keyInfo = CAAM_KEY_TRANSIENT;
  7178. int keyType = CAAM_KEYTYPE_AES128;
  7179. byte pubKey[AES_256_KEY_SIZE];
  7180. if (keySz == AES_256_KEY_SIZE) {
  7181. keyType = CAAM_KEYTYPE_AES256;
  7182. }
  7183. if (useDeviceID &&
  7184. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7185. keyInfo, &keyID) != 0) {
  7186. printf("Error generating key in hsm\n");
  7187. return;
  7188. }
  7189. #endif
  7190. (void)useDeviceID;
  7191. bench_stats_start(&count, &start);
  7192. do {
  7193. #ifdef HAVE_FIPS
  7194. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7195. #else
  7196. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7197. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7198. #endif
  7199. if (ret != 0) {
  7200. printf("InitCmac failed, ret = %d\n", ret);
  7201. return;
  7202. }
  7203. #ifdef WOLFSSL_SECO_CAAM
  7204. if (useDeviceID) {
  7205. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7206. }
  7207. #endif
  7208. for (i = 0; i < numBlocks; i++) {
  7209. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7210. if (ret != 0) {
  7211. printf("CmacUpdate failed, ret = %d\n", ret);
  7212. return;
  7213. }
  7214. RECORD_MULTI_VALUE_STATS();
  7215. }
  7216. /* Note: final force zero's the Cmac struct */
  7217. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7218. if (ret != 0) {
  7219. printf("CmacFinal failed, ret = %d\n", ret);
  7220. return;
  7221. }
  7222. count += i;
  7223. } while (bench_stats_check(start)
  7224. #ifdef MULTI_VALUE_STATISTICS
  7225. || runs < minimum_runs
  7226. #endif
  7227. );
  7228. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7229. #ifdef MULTI_VALUE_STATISTICS
  7230. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7231. #endif
  7232. }
  7233. void bench_cmac(int useDeviceID)
  7234. {
  7235. #ifdef WOLFSSL_AES_128
  7236. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7237. #endif
  7238. #ifdef WOLFSSL_AES_256
  7239. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7240. #endif
  7241. }
  7242. #endif /* WOLFSSL_CMAC */
  7243. #ifdef HAVE_SCRYPT
  7244. void bench_scrypt(void)
  7245. {
  7246. byte derived[64];
  7247. double start;
  7248. int ret, i, count;
  7249. DECLARE_MULTI_VALUE_STATS_VARS()
  7250. bench_stats_start(&count, &start);
  7251. do {
  7252. for (i = 0; i < scryptCnt; i++) {
  7253. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7254. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7255. sizeof(derived));
  7256. if (ret != 0) {
  7257. printf("scrypt failed, ret = %d\n", ret);
  7258. goto exit;
  7259. }
  7260. RECORD_MULTI_VALUE_STATS();
  7261. }
  7262. count += i;
  7263. } while (bench_stats_check(start)
  7264. #ifdef MULTI_VALUE_STATISTICS
  7265. || runs < minimum_runs
  7266. #endif
  7267. );
  7268. exit:
  7269. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7270. #ifdef MULTI_VALUE_STATISTICS
  7271. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7272. #endif
  7273. }
  7274. #endif /* HAVE_SCRYPT */
  7275. #ifndef NO_HMAC
  7276. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7277. const byte* key, word32 keySz, const char* label)
  7278. {
  7279. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7280. sizeof(Hmac), HEAP_HINT);
  7281. double start;
  7282. int ret = 0, i, count = 0, times, pending = 0;
  7283. DECLARE_MULTI_VALUE_STATS_VARS()
  7284. #ifdef WOLFSSL_ASYNC_CRYPT
  7285. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7286. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7287. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7288. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7289. #else
  7290. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7291. #endif
  7292. (void)digestSz;
  7293. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7294. sizeof(Hmac), HEAP_HINT);
  7295. /* init keys */
  7296. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7297. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7298. useDeviceID ? devId : INVALID_DEVID);
  7299. if (ret != 0) {
  7300. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7301. goto exit;
  7302. }
  7303. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7304. if (ret != 0) {
  7305. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7306. goto exit;
  7307. }
  7308. }
  7309. bench_stats_start(&count, &start);
  7310. do {
  7311. for (times = 0; times < numBlocks || pending > 0; ) {
  7312. bench_async_poll(&pending);
  7313. /* while free pending slots in queue, submit ops */
  7314. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7315. if (bench_async_check(&ret,
  7316. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7317. &times, numBlocks, &pending)) {
  7318. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7319. if (!bench_async_handle(&ret,
  7320. BENCH_ASYNC_GET_DEV(hmac[i]),
  7321. 0, &times, &pending)) {
  7322. goto exit_hmac;
  7323. }
  7324. }
  7325. } /* for i */
  7326. } /* for times */
  7327. count += times;
  7328. times = 0;
  7329. do {
  7330. bench_async_poll(&pending);
  7331. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7332. if (bench_async_check(&ret,
  7333. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7334. &times, numBlocks, &pending)) {
  7335. ret = wc_HmacFinal(hmac[i], digest[i]);
  7336. if (!bench_async_handle(&ret,
  7337. BENCH_ASYNC_GET_DEV(hmac[i]),
  7338. 0, &times, &pending)) {
  7339. goto exit_hmac;
  7340. }
  7341. }
  7342. RECORD_MULTI_VALUE_STATS();
  7343. } /* for i */
  7344. } while (pending > 0);
  7345. } while (bench_stats_check(start)
  7346. #ifdef MULTI_VALUE_STATISTICS
  7347. || runs < minimum_runs
  7348. #endif
  7349. );
  7350. exit_hmac:
  7351. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7352. #ifdef MULTI_VALUE_STATISTICS
  7353. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7354. #endif
  7355. exit:
  7356. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7357. wc_HmacFree(hmac[i]);
  7358. }
  7359. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7360. #ifdef WOLFSSL_ASYNC_CRYPT
  7361. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7362. #endif
  7363. }
  7364. #ifndef NO_MD5
  7365. void bench_hmac_md5(int useDeviceID)
  7366. {
  7367. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7368. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7369. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7370. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7371. "HMAC-MD5");
  7372. }
  7373. #endif /* NO_MD5 */
  7374. #ifndef NO_SHA
  7375. void bench_hmac_sha(int useDeviceID)
  7376. {
  7377. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7378. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7379. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7380. 0x0b, 0x0b, 0x0b, 0x0b };
  7381. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7382. "HMAC-SHA");
  7383. }
  7384. #endif /* NO_SHA */
  7385. #ifdef WOLFSSL_SHA224
  7386. void bench_hmac_sha224(int useDeviceID)
  7387. {
  7388. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7389. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7390. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7391. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7392. 0x0b, 0x0b, 0x0b, 0x0b };
  7393. bench_hmac(useDeviceID, WC_SHA224,
  7394. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7395. "HMAC-SHA224");
  7396. }
  7397. #endif /* WOLFSSL_SHA224 */
  7398. #ifndef NO_SHA256
  7399. void bench_hmac_sha256(int useDeviceID)
  7400. {
  7401. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7402. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7403. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7404. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7405. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7406. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7407. "HMAC-SHA256");
  7408. }
  7409. #endif /* NO_SHA256 */
  7410. #ifdef WOLFSSL_SHA384
  7411. void bench_hmac_sha384(int useDeviceID)
  7412. {
  7413. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7414. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7415. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7416. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7417. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7418. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7419. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7420. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7421. "HMAC-SHA384");
  7422. }
  7423. #endif /* WOLFSSL_SHA384 */
  7424. #ifdef WOLFSSL_SHA512
  7425. void bench_hmac_sha512(int useDeviceID)
  7426. {
  7427. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7428. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7429. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7430. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7431. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7432. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7433. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7434. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7435. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7436. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7437. "HMAC-SHA512");
  7438. }
  7439. #endif /* WOLFSSL_SHA512 */
  7440. #ifndef NO_PWDBASED
  7441. void bench_pbkdf2(void)
  7442. {
  7443. double start;
  7444. int ret = 0, count = 0;
  7445. const char* passwd32 = "passwordpasswordpasswordpassword";
  7446. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7447. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7448. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7449. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7450. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7451. byte derived[32];
  7452. DECLARE_MULTI_VALUE_STATS_VARS()
  7453. bench_stats_start(&count, &start);
  7454. PRIVATE_KEY_UNLOCK();
  7455. do {
  7456. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7457. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7458. count++;
  7459. RECORD_MULTI_VALUE_STATS();
  7460. } while (bench_stats_check(start)
  7461. #ifdef MULTI_VALUE_STATISTICS
  7462. || runs < minimum_runs
  7463. #endif
  7464. );
  7465. PRIVATE_KEY_LOCK();
  7466. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7467. #ifdef MULTI_VALUE_STATISTICS
  7468. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7469. #endif
  7470. }
  7471. #endif /* !NO_PWDBASED */
  7472. #endif /* NO_HMAC */
  7473. #ifdef WOLFSSL_SIPHASH
  7474. void bench_siphash(void)
  7475. {
  7476. double start;
  7477. int ret = 0, count;
  7478. const char* passwd16 = "passwordpassword";
  7479. byte out[16];
  7480. int i;
  7481. DECLARE_MULTI_VALUE_STATS_VARS()
  7482. bench_stats_start(&count, &start);
  7483. do {
  7484. for (i = 0; i < numBlocks; i++) {
  7485. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7486. out, 8);
  7487. RECORD_MULTI_VALUE_STATS();
  7488. }
  7489. count += i;
  7490. } while (bench_stats_check(start)
  7491. #ifdef MULTI_VALUE_STATISTICS
  7492. || runs < minimum_runs
  7493. #endif
  7494. );
  7495. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7496. #ifdef MULTI_VALUE_STATISTICS
  7497. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7498. #endif
  7499. RESET_MULTI_VALUE_STATS_VARS();
  7500. bench_stats_start(&count, &start);
  7501. do {
  7502. for (i = 0; i < numBlocks; i++) {
  7503. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7504. out, 16);
  7505. RECORD_MULTI_VALUE_STATS();
  7506. }
  7507. count += i;
  7508. } while (bench_stats_check(start)
  7509. #ifdef MULTI_VALUE_STATISTICS
  7510. || runs < minimum_runs
  7511. #endif
  7512. );
  7513. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7514. #ifdef MULTI_VALUE_STATISTICS
  7515. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7516. #endif
  7517. }
  7518. #endif
  7519. #ifdef WC_SRTP_KDF
  7520. void bench_srtpkdf(void)
  7521. {
  7522. double start;
  7523. int count;
  7524. int ret = 0;
  7525. byte keyE[32];
  7526. byte keyA[20];
  7527. byte keyS[14];
  7528. const byte *key = bench_key_buf;
  7529. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7530. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7531. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7532. int kdrIdx = 0;
  7533. int i;
  7534. DECLARE_MULTI_VALUE_STATS_VARS()
  7535. bench_stats_start(&count, &start);
  7536. PRIVATE_KEY_UNLOCK();
  7537. do {
  7538. for (i = 0; i < numBlocks; i++) {
  7539. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7540. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7541. keyS, sizeof(keyS));
  7542. RECORD_MULTI_VALUE_STATS();
  7543. }
  7544. count += i;
  7545. } while (bench_stats_check(start)
  7546. #ifdef MULTI_VALUE_STATISTICS
  7547. || runs < minimum_runs
  7548. #endif
  7549. );
  7550. PRIVATE_KEY_LOCK();
  7551. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7552. #ifdef MULTI_VALUE_STATISTICS
  7553. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7554. #endif
  7555. RESET_MULTI_VALUE_STATS_VARS();
  7556. bench_stats_start(&count, &start);
  7557. PRIVATE_KEY_UNLOCK();
  7558. do {
  7559. for (i = 0; i < numBlocks; i++) {
  7560. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7561. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7562. keyS, sizeof(keyS));
  7563. RECORD_MULTI_VALUE_STATS();
  7564. }
  7565. count += i;
  7566. } while (bench_stats_check(start)
  7567. #ifdef MULTI_VALUE_STATISTICS
  7568. || runs < minimum_runs
  7569. #endif
  7570. );
  7571. PRIVATE_KEY_LOCK();
  7572. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7573. #ifdef MULTI_VALUE_STATISTICS
  7574. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7575. #endif
  7576. RESET_MULTI_VALUE_STATS_VARS();
  7577. bench_stats_start(&count, &start);
  7578. PRIVATE_KEY_UNLOCK();
  7579. do {
  7580. for (i = 0; i < numBlocks; i++) {
  7581. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7582. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7583. keyS, sizeof(keyS));
  7584. RECORD_MULTI_VALUE_STATS();
  7585. }
  7586. count += i;
  7587. } while (bench_stats_check(start)
  7588. #ifdef MULTI_VALUE_STATISTICS
  7589. || runs < minimum_runs
  7590. #endif
  7591. );
  7592. PRIVATE_KEY_LOCK();
  7593. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7594. #ifdef MULTI_VALUE_STATISTICS
  7595. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7596. #endif
  7597. RESET_MULTI_VALUE_STATS_VARS();
  7598. bench_stats_start(&count, &start);
  7599. PRIVATE_KEY_UNLOCK();
  7600. do {
  7601. for (i = 0; i < numBlocks; i++) {
  7602. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7603. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7604. keyS, sizeof(keyS));
  7605. RECORD_MULTI_VALUE_STATS();
  7606. }
  7607. count += i;
  7608. } while (bench_stats_check(start)
  7609. #ifdef MULTI_VALUE_STATISTICS
  7610. || runs < minimum_runs
  7611. #endif
  7612. );
  7613. PRIVATE_KEY_LOCK();
  7614. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7615. #ifdef MULTI_VALUE_STATISTICS
  7616. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7617. #endif
  7618. }
  7619. #endif
  7620. #ifndef NO_RSA
  7621. #if defined(WOLFSSL_KEY_GEN)
  7622. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7623. {
  7624. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7625. sizeof(RsaKey), HEAP_HINT);
  7626. double start = 0;
  7627. int ret = 0, i, count = 0, times, pending = 0;
  7628. const long rsa_e_val = WC_RSA_EXPONENT;
  7629. const char**desc = bench_desc_words[lng_index];
  7630. DECLARE_MULTI_VALUE_STATS_VARS()
  7631. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7632. sizeof(RsaKey), HEAP_HINT);
  7633. bench_stats_start(&count, &start);
  7634. do {
  7635. /* while free pending slots in queue, submit ops */
  7636. for (times = 0; times < genTimes || pending > 0; ) {
  7637. bench_async_poll(&pending);
  7638. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7639. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7640. 0, &times, genTimes, &pending)) {
  7641. wc_FreeRsaKey(genKey[i]);
  7642. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7643. if (ret < 0) {
  7644. goto exit;
  7645. }
  7646. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7647. &gRng);
  7648. if (!bench_async_handle(&ret,
  7649. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7650. &times, &pending)) {
  7651. goto exit;
  7652. }
  7653. }
  7654. } /* for i */
  7655. RECORD_MULTI_VALUE_STATS();
  7656. } /* for times */
  7657. count += times;
  7658. } while (bench_stats_check(start)
  7659. #ifdef MULTI_VALUE_STATISTICS
  7660. || runs < minimum_runs
  7661. #endif
  7662. );
  7663. exit:
  7664. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7665. start, ret);
  7666. #ifdef MULTI_VALUE_STATISTICS
  7667. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7668. #endif
  7669. /* cleanup */
  7670. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7671. wc_FreeRsaKey(genKey[i]);
  7672. }
  7673. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7674. }
  7675. void bench_rsaKeyGen(int useDeviceID)
  7676. {
  7677. int k;
  7678. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7679. static const word32 keySizes[2] = {1024, 2048 };
  7680. #elif RSA_MAX_SIZE >= 4096
  7681. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7682. (RSA_MIN_SIZE <= 1024)
  7683. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7684. #else
  7685. static const word32 keySizes[3] = {2048, 3072, 4096};
  7686. #endif
  7687. #elif RSA_MAX_SIZE >= 3072
  7688. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7689. (RSA_MIN_SIZE <= 1024)
  7690. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7691. #else
  7692. static const word32 keySizes[2] = {2048, 3072 };
  7693. #endif
  7694. #elif RSA_MAX_SIZE >= 2048
  7695. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7696. (RSA_MIN_SIZE <= 1024)
  7697. static const word32 keySizes[2] = {1024, 2048 };
  7698. #else
  7699. static const word32 keySizes[1] = {2048};
  7700. #endif
  7701. #else
  7702. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7703. (RSA_MIN_SIZE <= 1024)
  7704. static const word32 keySizes[1] = {1024 };
  7705. #else
  7706. #error No candidate RSA key sizes to benchmark.
  7707. #endif
  7708. #endif
  7709. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7710. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7711. }
  7712. }
  7713. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7714. {
  7715. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7716. }
  7717. #endif /* WOLFSSL_KEY_GEN */
  7718. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7719. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7720. #if defined(WOLFSSL_MDK_SHELL)
  7721. static char *certRSAname = "certs/rsa2048.der";
  7722. /* set by shell command */
  7723. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7724. #elif defined(FREESCALE_MQX)
  7725. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7726. #else
  7727. static const char *certRSAname = "certs/rsa2048.der";
  7728. #endif
  7729. #endif
  7730. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7731. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7732. #if defined(USE_CERT_BUFFERS_2048)
  7733. static const unsigned char rsa_2048_sig[] = {
  7734. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7735. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7736. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7737. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7738. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7739. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7740. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7741. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7742. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7743. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7744. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7745. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7746. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7747. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7748. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7749. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7750. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7751. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7752. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7753. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7754. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7755. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7756. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7757. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7758. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7759. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7760. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7761. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7762. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7763. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7764. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7765. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7766. };
  7767. #elif defined(USE_CERT_BUFFERS_3072)
  7768. static const unsigned char rsa_3072_sig[] = {
  7769. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7770. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7771. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7772. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7773. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7774. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7775. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7776. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7777. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7778. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7779. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7780. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7781. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7782. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7783. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7784. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7785. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7786. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7787. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7788. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7789. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7790. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7791. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7792. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7793. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7794. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7795. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7796. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7797. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7798. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7799. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7800. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7801. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7802. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7803. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7804. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7805. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7806. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7807. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7808. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7809. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7810. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7811. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7812. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7813. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7814. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7815. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7816. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7817. };
  7818. #else
  7819. #error Not Supported Yet!
  7820. #endif
  7821. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7822. static void bench_rsa_helper(int useDeviceID,
  7823. WC_ARRAY_ARG(rsaKey,
  7824. RsaKey,
  7825. BENCH_MAX_PENDING,
  7826. sizeof(RsaKey)),
  7827. word32 rsaKeySz)
  7828. {
  7829. int ret = 0, i, times, count = 0, pending = 0;
  7830. word32 idx = 0;
  7831. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7832. const char* messageStr = TEST_STRING;
  7833. const int len = (int)TEST_STRING_SZ;
  7834. #endif
  7835. double start = 0.0F;
  7836. const char**desc = bench_desc_words[lng_index];
  7837. DECLARE_MULTI_VALUE_STATS_VARS()
  7838. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7839. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7840. #endif
  7841. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7842. rsaKeySz, HEAP_HINT);
  7843. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7844. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7845. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7846. rsaKeySz, HEAP_HINT);
  7847. #else
  7848. byte* out[BENCH_MAX_PENDING];
  7849. #endif
  7850. XMEMSET(out, 0, sizeof(out));
  7851. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7852. rsaKeySz, HEAP_HINT);
  7853. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7854. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7855. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7856. rsaKeySz, HEAP_HINT);
  7857. if (out[0] == NULL) {
  7858. ret = MEMORY_E;
  7859. goto exit;
  7860. }
  7861. #endif
  7862. if (enc[0] == NULL) {
  7863. ret = MEMORY_E;
  7864. goto exit;
  7865. }
  7866. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7867. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7868. XMEMCPY(message, messageStr, len);
  7869. #endif
  7870. if (!rsa_sign_verify) {
  7871. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7872. /* begin public RSA */
  7873. bench_stats_start(&count, &start);
  7874. do {
  7875. for (times = 0; times < ntimes || pending > 0; ) {
  7876. bench_async_poll(&pending);
  7877. /* while free pending slots in queue, submit ops */
  7878. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7879. if (bench_async_check(&ret,
  7880. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7881. 1, &times, ntimes, &pending)) {
  7882. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7883. rsaKeySz/8, rsaKey[i],
  7884. GLOBAL_RNG);
  7885. if (!bench_async_handle(&ret,
  7886. BENCH_ASYNC_GET_DEV(
  7887. rsaKey[i]), 1, &times,
  7888. &pending)) {
  7889. goto exit_rsa_verify;
  7890. }
  7891. }
  7892. } /* for i */
  7893. RECORD_MULTI_VALUE_STATS();
  7894. } /* for times */
  7895. count += times;
  7896. } while (bench_stats_check(start)
  7897. #ifdef MULTI_VALUE_STATISTICS
  7898. || runs < minimum_runs
  7899. #endif
  7900. );
  7901. exit_rsa_verify:
  7902. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7903. useDeviceID, count, start, ret);
  7904. #ifdef MULTI_VALUE_STATISTICS
  7905. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7906. #endif
  7907. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7908. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7909. if (ret < 0) {
  7910. goto exit;
  7911. }
  7912. RESET_MULTI_VALUE_STATS_VARS();
  7913. /* capture resulting encrypt length */
  7914. idx = (word32)(rsaKeySz/8);
  7915. /* begin private async RSA */
  7916. bench_stats_start(&count, &start);
  7917. do {
  7918. for (times = 0; times < ntimes || pending > 0; ) {
  7919. bench_async_poll(&pending);
  7920. /* while free pending slots in queue, submit ops */
  7921. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7922. if (bench_async_check(&ret,
  7923. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7924. 1, &times, ntimes, &pending)) {
  7925. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7926. rsaKeySz/8, rsaKey[i]);
  7927. if (!bench_async_handle(&ret,
  7928. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7929. 1, &times, &pending)) {
  7930. goto exit_rsa_pub;
  7931. }
  7932. }
  7933. } /* for i */
  7934. RECORD_MULTI_VALUE_STATS();
  7935. } /* for times */
  7936. count += times;
  7937. } while (bench_stats_check(start)
  7938. #ifdef MULTI_VALUE_STATISTICS
  7939. || runs < minimum_runs
  7940. #endif
  7941. );
  7942. exit_rsa_pub:
  7943. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7944. useDeviceID, count, start, ret);
  7945. #ifdef MULTI_VALUE_STATISTICS
  7946. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7947. #endif
  7948. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7949. }
  7950. else {
  7951. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7952. /* begin RSA sign */
  7953. bench_stats_start(&count, &start);
  7954. do {
  7955. for (times = 0; times < ntimes || pending > 0; ) {
  7956. bench_async_poll(&pending);
  7957. /* while free pending slots in queue, submit ops */
  7958. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7959. if (bench_async_check(&ret,
  7960. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7961. 1, &times, ntimes, &pending)) {
  7962. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7963. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7964. if (!bench_async_handle(&ret,
  7965. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7966. 1, &times, &pending)) {
  7967. goto exit_rsa_sign;
  7968. }
  7969. }
  7970. } /* for i */
  7971. RECORD_MULTI_VALUE_STATS();
  7972. } /* for times */
  7973. count += times;
  7974. } while (bench_stats_check(start)
  7975. #ifdef MULTI_VALUE_STATISTICS
  7976. || runs < minimum_runs
  7977. #endif
  7978. );
  7979. exit_rsa_sign:
  7980. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7981. count, start, ret);
  7982. #ifdef MULTI_VALUE_STATISTICS
  7983. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7984. #endif
  7985. if (ret < 0) {
  7986. goto exit;
  7987. }
  7988. RESET_MULTI_VALUE_STATS_VARS();
  7989. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  7990. /* capture resulting encrypt length */
  7991. idx = rsaKeySz/8;
  7992. /* begin RSA verify */
  7993. bench_stats_start(&count, &start);
  7994. do {
  7995. for (times = 0; times < ntimes || pending > 0; ) {
  7996. bench_async_poll(&pending);
  7997. /* while free pending slots in queue, submit ops */
  7998. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7999. if (bench_async_check(&ret,
  8000. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8001. 1, &times, ntimes, &pending)) {
  8002. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  8003. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8004. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  8005. rsaKeySz/8, rsaKey[i]);
  8006. #elif defined(USE_CERT_BUFFERS_2048)
  8007. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  8008. idx = sizeof(rsa_2048_sig);
  8009. out[i] = NULL;
  8010. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8011. &out[i], rsaKey[i]);
  8012. if (ret > 0) {
  8013. ret = 0;
  8014. }
  8015. #elif defined(USE_CERT_BUFFERS_3072)
  8016. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  8017. idx = sizeof(rsa_3072_sig);
  8018. out[i] = NULL;
  8019. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8020. &out[i], rsaKey[i]);
  8021. if (ret > 0)
  8022. ret = 0;
  8023. #endif
  8024. if (!bench_async_handle(&ret,
  8025. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8026. 1, &times, &pending)) {
  8027. goto exit_rsa_verifyinline;
  8028. }
  8029. }
  8030. } /* for i */
  8031. RECORD_MULTI_VALUE_STATS();
  8032. } /* for times */
  8033. count += times;
  8034. } while (bench_stats_check(start)
  8035. #ifdef MULTI_VALUE_STATISTICS
  8036. || runs < minimum_runs
  8037. #endif
  8038. );
  8039. exit_rsa_verifyinline:
  8040. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8041. useDeviceID, count, start, ret);
  8042. #ifdef MULTI_VALUE_STATISTICS
  8043. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8044. #endif
  8045. }
  8046. exit:
  8047. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8048. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8049. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8050. #endif
  8051. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8052. WC_FREE_VAR(message, HEAP_HINT);
  8053. #endif
  8054. }
  8055. void bench_rsa(int useDeviceID)
  8056. {
  8057. int i;
  8058. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8059. sizeof(RsaKey), HEAP_HINT);
  8060. int ret = 0;
  8061. word32 rsaKeySz = 0;
  8062. const byte* tmp;
  8063. size_t bytes;
  8064. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8065. word32 idx;
  8066. #endif
  8067. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8068. sizeof(RsaKey), HEAP_HINT);
  8069. #ifdef USE_CERT_BUFFERS_1024
  8070. tmp = rsa_key_der_1024;
  8071. bytes = (size_t)sizeof_rsa_key_der_1024;
  8072. rsaKeySz = 1024;
  8073. #elif defined(USE_CERT_BUFFERS_2048)
  8074. tmp = rsa_key_der_2048;
  8075. bytes = (size_t)sizeof_rsa_key_der_2048;
  8076. rsaKeySz = 2048;
  8077. #elif defined(USE_CERT_BUFFERS_3072)
  8078. tmp = rsa_key_der_3072;
  8079. bytes = (size_t)sizeof_rsa_key_der_3072;
  8080. rsaKeySz = 3072;
  8081. #elif defined(USE_CERT_BUFFERS_4096)
  8082. tmp = client_key_der_4096;
  8083. bytes = (size_t)sizeof_client_key_der_4096;
  8084. rsaKeySz = 4096;
  8085. #else
  8086. #error "need a cert buffer size"
  8087. #endif /* USE_CERT_BUFFERS */
  8088. /* init keys */
  8089. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8090. /* setup an async context for each key */
  8091. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8092. useDeviceID ? devId : INVALID_DEVID);
  8093. if (ret < 0) {
  8094. goto exit;
  8095. }
  8096. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8097. #ifdef WC_RSA_BLINDING
  8098. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8099. if (ret != 0)
  8100. goto exit;
  8101. #endif
  8102. #endif
  8103. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8104. /* decode the private key */
  8105. idx = 0;
  8106. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8107. rsaKey[i], (word32)bytes)) != 0) {
  8108. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8109. goto exit;
  8110. }
  8111. #elif defined(WOLFSSL_PUBLIC_MP)
  8112. /* get offset to public portion of the RSA key */
  8113. #ifdef USE_CERT_BUFFERS_1024
  8114. bytes = 11;
  8115. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8116. bytes = 12;
  8117. #endif
  8118. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8119. if (ret != 0) {
  8120. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8121. goto exit;
  8122. }
  8123. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8124. if (ret != 0) {
  8125. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8126. goto exit;
  8127. }
  8128. #else
  8129. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8130. rsaKeySz = 0;
  8131. #endif
  8132. }
  8133. if (rsaKeySz > 0) {
  8134. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8135. }
  8136. (void)bytes;
  8137. (void)tmp;
  8138. exit:
  8139. /* cleanup */
  8140. if (WC_ARRAY_OK(rsaKey)) {
  8141. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8142. wc_FreeRsaKey(rsaKey[i]);
  8143. }
  8144. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8145. }
  8146. }
  8147. #ifdef WOLFSSL_KEY_GEN
  8148. /* bench any size of RSA key */
  8149. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8150. {
  8151. int ret = 0, i, pending = 0;
  8152. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8153. sizeof(RsaKey), HEAP_HINT);
  8154. int isPending[BENCH_MAX_PENDING];
  8155. long exp = 65537L;
  8156. /* clear for done cleanup */
  8157. XMEMSET(isPending, 0, sizeof(isPending));
  8158. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8159. sizeof(RsaKey), HEAP_HINT);
  8160. /* init keys */
  8161. do {
  8162. pending = 0;
  8163. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8164. if (!isPending[i]) { /* if making the key is pending then just call
  8165. * wc_MakeRsaKey again */
  8166. /* setup an async context for each key */
  8167. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8168. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8169. goto exit;
  8170. }
  8171. #ifdef WC_RSA_BLINDING
  8172. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8173. if (ret != 0)
  8174. goto exit;
  8175. #endif
  8176. }
  8177. /* create the RSA key */
  8178. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8179. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8180. isPending[i] = 1;
  8181. pending = 1;
  8182. }
  8183. else if (ret != 0) {
  8184. printf("wc_MakeRsaKey failed! %d\n", ret);
  8185. goto exit;
  8186. }
  8187. } /* for i */
  8188. } while (pending > 0);
  8189. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8190. exit:
  8191. /* cleanup */
  8192. if (WC_ARRAY_OK(rsaKey)) {
  8193. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8194. wc_FreeRsaKey(rsaKey[i]);
  8195. }
  8196. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8197. }
  8198. }
  8199. #endif /* WOLFSSL_KEY_GEN */
  8200. #endif /* !NO_RSA */
  8201. #ifndef NO_DH
  8202. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8203. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8204. #if defined(WOLFSSL_MDK_SHELL)
  8205. static char *certDHname = "certs/dh2048.der";
  8206. /* set by shell command */
  8207. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8208. #elif defined(FREESCALE_MQX)
  8209. static char *certDHname = "a:\\certs\\dh2048.der";
  8210. #elif defined(NO_ASN)
  8211. /* do nothing, but don't need a file */
  8212. #else
  8213. static const char *certDHname = "certs/dh2048.der";
  8214. #endif
  8215. #endif
  8216. #ifdef HAVE_FFDHE_4096
  8217. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8218. #else
  8219. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8220. #endif
  8221. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8222. void bench_dh(int useDeviceID)
  8223. {
  8224. int ret = 0, i;
  8225. int count = 0, times, pending = 0;
  8226. const byte* tmp = NULL;
  8227. double start = 0.0F;
  8228. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8229. sizeof(DhKey), HEAP_HINT);
  8230. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8231. const char**desc = bench_desc_words[lng_index];
  8232. #ifndef NO_ASN
  8233. size_t bytes = 0;
  8234. word32 idx;
  8235. #endif
  8236. word32 pubSz[BENCH_MAX_PENDING];
  8237. word32 privSz[BENCH_MAX_PENDING];
  8238. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8239. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8240. word32 agreeSz[BENCH_MAX_PENDING];
  8241. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8242. #ifdef HAVE_PUBLIC_FFDHE
  8243. const DhParams *params = NULL;
  8244. #else
  8245. int paramName = 0;
  8246. #endif
  8247. #endif
  8248. DECLARE_MULTI_VALUE_STATS_VARS()
  8249. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8250. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8251. WC_DECLARE_VAR(pub2, byte,
  8252. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8253. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8254. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8255. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8256. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8257. WC_DECLARE_VAR(priv2, byte,
  8258. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8259. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8260. XMEMSET(pub, 0, sizeof(pub));
  8261. XMEMSET(agree, 0, sizeof(agree));
  8262. XMEMSET(priv, 0, sizeof(priv));
  8263. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8264. sizeof(DhKey), HEAP_HINT);
  8265. WC_ALLOC_ARRAY(pub, byte,
  8266. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8267. WC_ALLOC_ARRAY(agree, byte,
  8268. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8269. WC_ALLOC_ARRAY(priv, byte,
  8270. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8271. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8272. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8273. (void)tmp;
  8274. if (!use_ffdhe) {
  8275. #if defined(NO_ASN)
  8276. dhKeySz = 1024;
  8277. /* do nothing, but don't use default FILE */
  8278. #elif defined(USE_CERT_BUFFERS_1024)
  8279. tmp = dh_key_der_1024;
  8280. bytes = (size_t)sizeof_dh_key_der_1024;
  8281. dhKeySz = 1024;
  8282. #elif defined(USE_CERT_BUFFERS_2048)
  8283. tmp = dh_key_der_2048;
  8284. bytes = (size_t)sizeof_dh_key_der_2048;
  8285. dhKeySz = 2048;
  8286. #elif defined(USE_CERT_BUFFERS_3072)
  8287. tmp = dh_key_der_3072;
  8288. bytes = (size_t)sizeof_dh_key_der_3072;
  8289. dhKeySz = 3072;
  8290. #elif defined(USE_CERT_BUFFERS_4096)
  8291. tmp = dh_key_der_4096;
  8292. bytes = (size_t)sizeof_dh_key_der_4096;
  8293. dhKeySz = 4096;
  8294. #else
  8295. #error "need to define a cert buffer size"
  8296. #endif /* USE_CERT_BUFFERS */
  8297. }
  8298. #ifdef HAVE_FFDHE_2048
  8299. else if (use_ffdhe == 2048) {
  8300. #ifdef HAVE_PUBLIC_FFDHE
  8301. params = wc_Dh_ffdhe2048_Get();
  8302. #else
  8303. paramName = WC_FFDHE_2048;
  8304. #endif
  8305. dhKeySz = 2048;
  8306. }
  8307. #endif
  8308. #ifdef HAVE_FFDHE_3072
  8309. else if (use_ffdhe == 3072) {
  8310. #ifdef HAVE_PUBLIC_FFDHE
  8311. params = wc_Dh_ffdhe3072_Get();
  8312. #else
  8313. paramName = WC_FFDHE_3072;
  8314. #endif
  8315. dhKeySz = 3072;
  8316. }
  8317. #endif
  8318. #ifdef HAVE_FFDHE_4096
  8319. else if (use_ffdhe == 4096) {
  8320. #ifdef HAVE_PUBLIC_FFDHE
  8321. params = wc_Dh_ffdhe4096_Get();
  8322. #else
  8323. paramName = WC_FFDHE_4096;
  8324. #endif
  8325. dhKeySz = 4096;
  8326. }
  8327. #endif
  8328. /* init keys */
  8329. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8330. /* setup an async context for each key */
  8331. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8332. useDeviceID ? devId : INVALID_DEVID);
  8333. if (ret != 0)
  8334. goto exit;
  8335. /* setup key */
  8336. if (!use_ffdhe) {
  8337. #ifdef NO_ASN
  8338. ret = wc_DhSetKey(dhKey[i], dh_p,
  8339. sizeof(dh_p), dh_g, sizeof(dh_g));
  8340. #else
  8341. idx = 0;
  8342. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8343. #endif
  8344. }
  8345. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8346. #ifdef HAVE_PUBLIC_FFDHE
  8347. else if (params != NULL) {
  8348. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8349. params->g, params->g_len);
  8350. }
  8351. #else
  8352. else if (paramName != 0) {
  8353. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8354. }
  8355. #endif
  8356. #endif
  8357. if (ret != 0) {
  8358. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8359. goto exit;
  8360. }
  8361. }
  8362. /* Key Gen */
  8363. bench_stats_start(&count, &start);
  8364. PRIVATE_KEY_UNLOCK();
  8365. do {
  8366. /* while free pending slots in queue, submit ops */
  8367. for (times = 0; times < genTimes || pending > 0; ) {
  8368. bench_async_poll(&pending);
  8369. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8370. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8371. 0, &times, genTimes, &pending)) {
  8372. privSz[i] = BENCH_DH_PRIV_SIZE;
  8373. pubSz[i] = BENCH_DH_KEY_SIZE;
  8374. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8375. priv[i], &privSz[i],
  8376. pub[i], &pubSz[i]);
  8377. if (!bench_async_handle(&ret,
  8378. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8379. 0, &times, &pending)) {
  8380. goto exit_dh_gen;
  8381. }
  8382. }
  8383. } /* for i */
  8384. RECORD_MULTI_VALUE_STATS();
  8385. } /* for times */
  8386. count += times;
  8387. } while (bench_stats_check(start)
  8388. #ifdef MULTI_VALUE_STATISTICS
  8389. || runs < minimum_runs
  8390. #endif
  8391. );
  8392. PRIVATE_KEY_LOCK();
  8393. exit_dh_gen:
  8394. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8395. useDeviceID, count, start, ret);
  8396. #ifdef MULTI_VALUE_STATISTICS
  8397. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8398. #endif
  8399. if (ret < 0) {
  8400. goto exit;
  8401. }
  8402. RESET_MULTI_VALUE_STATS_VARS();
  8403. /* Generate key to use as other public */
  8404. PRIVATE_KEY_UNLOCK();
  8405. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8406. priv2, &privSz2, pub2, &pubSz2);
  8407. PRIVATE_KEY_LOCK();
  8408. #ifdef WOLFSSL_ASYNC_CRYPT
  8409. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8410. #endif
  8411. /* Key Agree */
  8412. bench_stats_start(&count, &start);
  8413. PRIVATE_KEY_UNLOCK();
  8414. do {
  8415. for (times = 0; times < agreeTimes || pending > 0; ) {
  8416. bench_async_poll(&pending);
  8417. /* while free pending slots in queue, submit ops */
  8418. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8419. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8420. 0, &times, agreeTimes, &pending)) {
  8421. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8422. privSz[i], pub2, pubSz2);
  8423. if (!bench_async_handle(&ret,
  8424. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8425. goto exit;
  8426. }
  8427. }
  8428. } /* for i */
  8429. RECORD_MULTI_VALUE_STATS();
  8430. } /* for times */
  8431. count += times;
  8432. } while (bench_stats_check(start)
  8433. #ifdef MULTI_VALUE_STATISTICS
  8434. || runs < minimum_runs
  8435. #endif
  8436. );
  8437. PRIVATE_KEY_LOCK();
  8438. exit:
  8439. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8440. useDeviceID, count, start, ret);
  8441. #ifdef MULTI_VALUE_STATISTICS
  8442. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8443. #endif
  8444. /* cleanup */
  8445. if (WC_ARRAY_OK(dhKey)) {
  8446. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8447. wc_FreeDhKey(dhKey[i]);
  8448. }
  8449. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8450. }
  8451. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8452. WC_FREE_VAR(pub2, HEAP_HINT);
  8453. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8454. WC_FREE_VAR(priv2, HEAP_HINT);
  8455. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8456. }
  8457. #endif /* !NO_DH */
  8458. #ifdef WOLFSSL_HAVE_KYBER
  8459. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8460. KyberKey* key)
  8461. {
  8462. int ret = 0, times, count, pending = 0;
  8463. double start;
  8464. const char**desc = bench_desc_words[lng_index];
  8465. DECLARE_MULTI_VALUE_STATS_VARS()
  8466. /* KYBER Make Key */
  8467. bench_stats_start(&count, &start);
  8468. do {
  8469. /* while free pending slots in queue, submit ops */
  8470. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8471. wc_KyberKey_Free(key);
  8472. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8473. if (ret != 0)
  8474. goto exit;
  8475. #ifdef KYBER_NONDETERMINISTIC
  8476. ret = wc_KyberKey_MakeKey(key, &gRng);
  8477. #else
  8478. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8479. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8480. #endif
  8481. if (ret != 0)
  8482. goto exit;
  8483. RECORD_MULTI_VALUE_STATS();
  8484. } /* for times */
  8485. count += times;
  8486. } while (bench_stats_check(start)
  8487. #ifdef MULTI_VALUE_STATISTICS
  8488. || runs < minimum_runs
  8489. #endif
  8490. );
  8491. exit:
  8492. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8493. #ifdef MULTI_VALUE_STATISTICS
  8494. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8495. #endif
  8496. }
  8497. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8498. {
  8499. int ret = 0, times, count, pending = 0;
  8500. double start;
  8501. const char**desc = bench_desc_words[lng_index];
  8502. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8503. byte ss[KYBER_SS_SZ];
  8504. word32 ctSz;
  8505. DECLARE_MULTI_VALUE_STATS_VARS()
  8506. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8507. if (ret != 0) {
  8508. return;
  8509. }
  8510. /* KYBER Encapsulate */
  8511. bench_stats_start(&count, &start);
  8512. do {
  8513. /* while free pending slots in queue, submit ops */
  8514. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8515. #ifdef KYBER_NONDETERMINISTIC
  8516. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8517. #else
  8518. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8519. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8520. sizeof(rand));
  8521. #endif
  8522. if (ret != 0)
  8523. goto exit_encap;
  8524. RECORD_MULTI_VALUE_STATS();
  8525. } /* for times */
  8526. count += times;
  8527. } while (bench_stats_check(start)
  8528. #ifdef MULTI_VALUE_STATISTICS
  8529. || runs < minimum_runs
  8530. #endif
  8531. );
  8532. exit_encap:
  8533. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8534. #ifdef MULTI_VALUE_STATISTICS
  8535. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8536. #endif
  8537. RESET_MULTI_VALUE_STATS_VARS();
  8538. /* KYBER Decapsulate */
  8539. bench_stats_start(&count, &start);
  8540. do {
  8541. /* while free pending slots in queue, submit ops */
  8542. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8543. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8544. if (ret != 0)
  8545. goto exit_decap;
  8546. RECORD_MULTI_VALUE_STATS();
  8547. } /* for times */
  8548. count += times;
  8549. } while (bench_stats_check(start)
  8550. #ifdef MULTI_VALUE_STATISTICS
  8551. || runs < minimum_runs
  8552. #endif
  8553. );
  8554. exit_decap:
  8555. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8556. #ifdef MULTI_VALUE_STATISTICS
  8557. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8558. #endif
  8559. }
  8560. void bench_kyber(int type)
  8561. {
  8562. KyberKey key;
  8563. const char* name = NULL;
  8564. int keySize = 0;
  8565. switch (type) {
  8566. #ifndef WOLFSSL_NO_ML_KEM
  8567. #ifdef WOLFSSL_WC_ML_KEM_512
  8568. case WC_ML_KEM_512:
  8569. name = "ML-KEM 512 ";
  8570. keySize = 128;
  8571. break;
  8572. #endif
  8573. #ifdef WOLFSSL_WC_ML_KEM_768
  8574. case WC_ML_KEM_768:
  8575. name = "ML-KEM 768 ";
  8576. keySize = 192;
  8577. break;
  8578. #endif
  8579. #ifdef WOLFSSL_WC_ML_KEM_1024
  8580. case WC_ML_KEM_1024:
  8581. name = "ML-KEM 1024 ";
  8582. keySize = 256;
  8583. break;
  8584. #endif
  8585. #endif
  8586. #ifdef WOLFSSL_KYBER_ORIGINAL
  8587. #ifdef WOLFSSL_KYBER512
  8588. case KYBER512:
  8589. name = "KYBER512 ";
  8590. keySize = 128;
  8591. break;
  8592. #endif
  8593. #ifdef WOLFSSL_KYBER768
  8594. case KYBER768:
  8595. name = "KYBER768 ";
  8596. keySize = 192;
  8597. break;
  8598. #endif
  8599. #ifdef WOLFSSL_KYBER1024
  8600. case KYBER1024:
  8601. name = "KYBER1024";
  8602. keySize = 256;
  8603. break;
  8604. #endif
  8605. #endif
  8606. }
  8607. bench_kyber_keygen(type, name, keySize, &key);
  8608. bench_kyber_encap(name, keySize, &key);
  8609. wc_KyberKey_Free(&key);
  8610. }
  8611. #endif
  8612. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8613. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8614. /* WC_LMS_PARM_L2_H10_W2
  8615. * signature length: 9300 */
  8616. static const byte lms_priv_L2_H10_W2[64] =
  8617. {
  8618. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8619. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8620. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8621. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8622. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8623. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8624. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8625. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8626. };
  8627. static const byte lms_pub_L2_H10_W2[60] =
  8628. {
  8629. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8630. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8631. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8632. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8633. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8634. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8635. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8636. 0x7F,0xC8,0x91,0xB0
  8637. };
  8638. /* WC_LMS_PARM_L2_H10_W4
  8639. * signature length: 5076 */
  8640. static const byte lms_priv_L2_H10_W4[64] =
  8641. {
  8642. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8643. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8644. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8645. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8646. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8647. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8648. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8649. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8650. };
  8651. static const byte lms_pub_L2_H10_W4[60] =
  8652. {
  8653. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8654. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8655. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8656. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8657. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8658. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8659. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8660. 0x6B,0x9A,0xD3,0x14
  8661. };
  8662. /* WC_LMS_PARM_L3_H5_W4
  8663. * signature length: 7160 */
  8664. static const byte lms_priv_L3_H5_W4[64] =
  8665. {
  8666. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8667. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8668. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8669. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8670. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8671. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8672. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8673. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8674. };
  8675. static const byte lms_pub_L3_H5_W4[60] =
  8676. {
  8677. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8678. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8679. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8680. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8681. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8682. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8683. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8684. 0xAB,0x4B,0x51,0x39
  8685. };
  8686. /* WC_LMS_PARM_L3_H5_W8
  8687. * signature length: 3992 */
  8688. static const byte lms_priv_L3_H5_W8[64] =
  8689. {
  8690. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8691. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8692. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8693. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8694. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8695. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8696. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8697. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8698. };
  8699. static const byte lms_pub_L3_H5_W8[60] =
  8700. {
  8701. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8702. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8703. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8704. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8705. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8706. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8707. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8708. 0x83,0xAB,0x43,0xAF
  8709. };
  8710. /* WC_LMS_PARM_L3_H10_W4
  8711. * signature length: 7640 */
  8712. static const byte lms_priv_L3_H10_W4[64] =
  8713. {
  8714. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8715. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8716. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8717. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8718. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8719. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8720. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8721. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8722. };
  8723. static const byte lms_pub_L3_H10_W4[60] =
  8724. {
  8725. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8726. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8727. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8728. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8729. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8730. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8731. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8732. 0x8D,0x78,0xD5,0xA8
  8733. };
  8734. /* WC_LMS_PARM_L4_H5_W8
  8735. * signature length: 5340 */
  8736. static const byte lms_priv_L4_H5_W8[64] =
  8737. {
  8738. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8739. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8740. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8741. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8742. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8743. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8744. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8745. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8746. };
  8747. static const byte lms_pub_L4_H5_W8[60] =
  8748. {
  8749. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8750. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8751. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8752. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8753. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8754. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8755. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8756. 0x74,0x24,0x12,0xC8
  8757. };
  8758. #endif
  8759. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8760. {
  8761. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8762. * BE USED FOR TESTING PURPOSES! Production applications should
  8763. * write only to non-volatile storage. */
  8764. XMEMCPY(context, priv, privSz);
  8765. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8766. }
  8767. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8768. {
  8769. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8770. * BE USED FOR TESTING PURPOSES! */
  8771. XMEMCPY(priv, context, privSz);
  8772. return WC_LMS_RC_READ_TO_MEMORY;
  8773. }
  8774. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8775. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8776. {
  8777. WC_RNG rng;
  8778. LmsKey key;
  8779. int ret;
  8780. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8781. int times = 0;
  8782. int count = 0;
  8783. double start = 0.0F;
  8784. int levels;
  8785. int height;
  8786. int winternitz;
  8787. const char* str = wc_LmsKey_ParmToStr(parm);
  8788. DECLARE_MULTI_VALUE_STATS_VARS()
  8789. #ifndef HAVE_FIPS
  8790. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8791. #else
  8792. ret = wc_InitRng(&rng);
  8793. #endif
  8794. if (ret != 0) {
  8795. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8796. return;
  8797. }
  8798. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8799. if (ret) {
  8800. printf("wc_LmsKey_Init failed: %d\n", ret);
  8801. wc_FreeRng(&rng);
  8802. return;
  8803. }
  8804. count = 0;
  8805. bench_stats_start(&count, &start);
  8806. do {
  8807. /* LMS is stateful. Async queuing not practical. */
  8808. for (times = 0; times < 1; ++times) {
  8809. wc_LmsKey_Free(&key);
  8810. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8811. if (ret) {
  8812. printf("wc_LmsKey_Init failed: %d\n", ret);
  8813. goto exit_lms_keygen;
  8814. }
  8815. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8816. if (ret) {
  8817. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8818. goto exit_lms_keygen;
  8819. }
  8820. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8821. if (ret) {
  8822. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8823. ret);
  8824. goto exit_lms_keygen;
  8825. }
  8826. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8827. if (ret) {
  8828. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8829. ret);
  8830. goto exit_lms_keygen;
  8831. }
  8832. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8833. if (ret) {
  8834. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8835. goto exit_lms_keygen;
  8836. }
  8837. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8838. if (ret) {
  8839. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8840. ret);
  8841. goto exit_lms_keygen;
  8842. }
  8843. ret = wc_LmsKey_MakeKey(&key, &rng);
  8844. if (ret) {
  8845. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8846. goto exit_lms_keygen;
  8847. }
  8848. RECORD_MULTI_VALUE_STATS();
  8849. }
  8850. count += times;
  8851. } while (bench_stats_check(start)
  8852. #ifdef MULTI_VALUE_STATISTICS
  8853. || runs < minimum_runs
  8854. #endif
  8855. );
  8856. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8857. count, start, ret);
  8858. #ifdef MULTI_VALUE_STATISTICS
  8859. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8860. #endif
  8861. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8862. if (ret) {
  8863. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8864. }
  8865. exit_lms_keygen:
  8866. wc_LmsKey_Free(&key);
  8867. wc_FreeRng(&rng);
  8868. }
  8869. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8870. {
  8871. LmsKey key;
  8872. int ret = 0;
  8873. const char * msg = TEST_STRING;
  8874. word32 msgSz = TEST_STRING_SZ;
  8875. byte * sig = NULL;
  8876. word32 sigSz = 0;
  8877. word32 privLen = 0;
  8878. int loaded = 0;
  8879. int times = 0;
  8880. int count = 0;
  8881. double start = 0.0F;
  8882. const char * str = wc_LmsKey_ParmToStr(parm);
  8883. DECLARE_MULTI_VALUE_STATS_VARS()
  8884. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8885. if (ret) {
  8886. printf("wc_LmsKey_Init failed: %d\n", ret);
  8887. goto exit_lms_sign_verify;
  8888. }
  8889. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8890. if (ret) {
  8891. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8892. goto exit_lms_sign_verify;
  8893. }
  8894. switch (parm) {
  8895. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8896. case WC_LMS_PARM_L2_H10_W2:
  8897. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8898. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8899. break;
  8900. case WC_LMS_PARM_L2_H10_W4:
  8901. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8902. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8903. break;
  8904. case WC_LMS_PARM_L3_H5_W4:
  8905. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8906. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8907. break;
  8908. case WC_LMS_PARM_L3_H5_W8:
  8909. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8910. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8911. break;
  8912. case WC_LMS_PARM_L3_H10_W4:
  8913. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8914. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8915. break;
  8916. case WC_LMS_PARM_L4_H5_W8:
  8917. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8918. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8919. break;
  8920. case WC_LMS_PARM_NONE:
  8921. case WC_LMS_PARM_L1_H15_W2:
  8922. case WC_LMS_PARM_L1_H15_W4:
  8923. case WC_LMS_PARM_L2_H10_W8:
  8924. case WC_LMS_PARM_L3_H5_W2:
  8925. case WC_LMS_PARM_L1_H5_W1:
  8926. case WC_LMS_PARM_L1_H5_W2:
  8927. case WC_LMS_PARM_L1_H5_W4:
  8928. case WC_LMS_PARM_L1_H5_W8:
  8929. case WC_LMS_PARM_L1_H10_W2:
  8930. case WC_LMS_PARM_L1_H10_W4:
  8931. case WC_LMS_PARM_L1_H10_W8:
  8932. case WC_LMS_PARM_L1_H15_W8:
  8933. case WC_LMS_PARM_L1_H20_W2:
  8934. case WC_LMS_PARM_L1_H20_W4:
  8935. case WC_LMS_PARM_L1_H20_W8:
  8936. case WC_LMS_PARM_L2_H5_W2:
  8937. case WC_LMS_PARM_L2_H5_W4:
  8938. case WC_LMS_PARM_L2_H5_W8:
  8939. case WC_LMS_PARM_L2_H15_W2:
  8940. case WC_LMS_PARM_L2_H15_W4:
  8941. case WC_LMS_PARM_L2_H15_W8:
  8942. case WC_LMS_PARM_L2_H20_W2:
  8943. case WC_LMS_PARM_L2_H20_W4:
  8944. case WC_LMS_PARM_L2_H20_W8:
  8945. case WC_LMS_PARM_L3_H10_W8:
  8946. case WC_LMS_PARM_L4_H5_W2:
  8947. case WC_LMS_PARM_L4_H5_W4:
  8948. case WC_LMS_PARM_L4_H10_W4:
  8949. case WC_LMS_PARM_L4_H10_W8:
  8950. #endif
  8951. #ifdef WOLFSSL_LMS_SHA256_192
  8952. case WC_LMS_PARM_SHA256_192_L1_H5_W1:
  8953. case WC_LMS_PARM_SHA256_192_L1_H5_W2:
  8954. case WC_LMS_PARM_SHA256_192_L1_H5_W4:
  8955. case WC_LMS_PARM_SHA256_192_L1_H5_W8:
  8956. case WC_LMS_PARM_SHA256_192_L1_H10_W2:
  8957. case WC_LMS_PARM_SHA256_192_L1_H10_W4:
  8958. case WC_LMS_PARM_SHA256_192_L1_H10_W8:
  8959. case WC_LMS_PARM_SHA256_192_L1_H15_W2:
  8960. case WC_LMS_PARM_SHA256_192_L1_H15_W4:
  8961. case WC_LMS_PARM_SHA256_192_L2_H10_W2:
  8962. case WC_LMS_PARM_SHA256_192_L2_H10_W4:
  8963. case WC_LMS_PARM_SHA256_192_L2_H10_W8:
  8964. case WC_LMS_PARM_SHA256_192_L3_H5_W2:
  8965. case WC_LMS_PARM_SHA256_192_L3_H5_W4:
  8966. case WC_LMS_PARM_SHA256_192_L3_H5_W8:
  8967. case WC_LMS_PARM_SHA256_192_L3_H10_W4:
  8968. case WC_LMS_PARM_SHA256_192_L4_H5_W8:
  8969. #endif
  8970. default:
  8971. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8972. break;
  8973. }
  8974. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8975. if (ret) {
  8976. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8977. goto exit_lms_sign_verify;
  8978. }
  8979. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8980. if (ret) {
  8981. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8982. goto exit_lms_sign_verify;
  8983. }
  8984. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8985. if (ret) {
  8986. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  8987. goto exit_lms_sign_verify;
  8988. }
  8989. /* Even with saved priv/pub keys, we must still reload the private
  8990. * key before using it. Reloading the private key is the bottleneck
  8991. * for larger heights. Only print load time in debug builds. */
  8992. count = 0;
  8993. bench_stats_start(&count, &start);
  8994. #ifndef WOLFSSL_WC_LMS_SMALL
  8995. do {
  8996. #ifdef WOLFSSL_WC_LMS
  8997. key.priv.inited = 0;
  8998. key.state = WC_LMS_STATE_PARMSET;
  8999. #endif
  9000. ret = wc_LmsKey_Reload(&key);
  9001. if (ret) {
  9002. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9003. goto exit_lms_sign_verify;
  9004. }
  9005. RECORD_MULTI_VALUE_STATS();
  9006. count++;
  9007. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9008. if (ret) {
  9009. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9010. goto exit_lms_sign_verify;
  9011. }
  9012. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9013. if (ret) {
  9014. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9015. goto exit_lms_sign_verify;
  9016. }
  9017. #ifdef HAVE_LIBLMS
  9018. break;
  9019. #endif
  9020. } while (bench_stats_check(start)
  9021. #ifdef MULTI_VALUE_STATISTICS
  9022. || runs < minimum_runs
  9023. #endif
  9024. );
  9025. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  9026. count, start, ret);
  9027. #ifdef MULTI_VALUE_STATISTICS
  9028. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9029. #endif
  9030. RESET_MULTI_VALUE_STATS_VARS();
  9031. #else
  9032. ret = wc_LmsKey_Reload(&key);
  9033. if (ret) {
  9034. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9035. goto exit_lms_sign_verify;
  9036. }
  9037. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9038. if (ret) {
  9039. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9040. goto exit_lms_sign_verify;
  9041. }
  9042. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9043. if (ret) {
  9044. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9045. goto exit_lms_sign_verify;
  9046. }
  9047. #endif
  9048. loaded = 1;
  9049. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9050. if (sig == NULL) {
  9051. printf("bench_lms_sign_verify malloc failed\n");
  9052. goto exit_lms_sign_verify;
  9053. }
  9054. count = 0;
  9055. bench_stats_start(&count, &start);
  9056. do {
  9057. /* LMS is stateful. Async queuing not practical. */
  9058. #ifndef WOLFSSL_WC_LMS_SMALL
  9059. for (times = 0; times < ntimes; ++times)
  9060. #else
  9061. for (times = 0; times < 1; ++times)
  9062. #endif
  9063. {
  9064. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9065. if (ret) {
  9066. printf("wc_LmsKey_Sign failed: %d\n", ret);
  9067. goto exit_lms_sign_verify;
  9068. }
  9069. RECORD_MULTI_VALUE_STATS();
  9070. if (!wc_LmsKey_SigsLeft(&key)) {
  9071. break;
  9072. }
  9073. }
  9074. count += times;
  9075. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9076. #ifdef MULTI_VALUE_STATISTICS
  9077. || runs < minimum_runs
  9078. #endif
  9079. ));
  9080. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9081. count, start, ret);
  9082. #ifdef MULTI_VALUE_STATISTICS
  9083. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9084. #endif
  9085. RESET_MULTI_VALUE_STATS_VARS();
  9086. count = 0;
  9087. bench_stats_start(&count, &start);
  9088. do {
  9089. /* LMS is stateful. Async queuing not practical. */
  9090. for (times = 0; times < ntimes; ++times) {
  9091. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9092. if (ret) {
  9093. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9094. goto exit_lms_sign_verify;
  9095. }
  9096. RECORD_MULTI_VALUE_STATS();
  9097. }
  9098. count += times;
  9099. } while (bench_stats_check(start)
  9100. #ifdef MULTI_VALUE_STATISTICS
  9101. || runs < minimum_runs
  9102. #endif
  9103. );
  9104. exit_lms_sign_verify:
  9105. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9106. count, start, ret);
  9107. #ifdef MULTI_VALUE_STATISTICS
  9108. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9109. #endif
  9110. if (loaded) {
  9111. wc_LmsKey_Free(&key);
  9112. }
  9113. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9114. return;
  9115. }
  9116. void bench_lms(void)
  9117. {
  9118. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9119. #ifndef WOLFSSL_NO_LMS_SHA256_256
  9120. #ifdef BENCH_LMS_SLOW_KEYGEN
  9121. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9122. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9123. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9124. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9125. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9126. #undef LMS_PARAMS_BENCHED
  9127. #define LMS_PARAMS_BENCHED
  9128. #endif
  9129. #endif
  9130. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9131. (LMS_MAX_HEIGHT >= 10))
  9132. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9133. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9134. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9135. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9136. #undef LMS_PARAMS_BENCHED
  9137. #define LMS_PARAMS_BENCHED
  9138. #ifdef BENCH_LMS_SLOW_KEYGEN
  9139. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9140. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9141. #endif
  9142. #endif
  9143. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9144. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9145. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9146. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9147. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9148. #undef LMS_PARAMS_BENCHED
  9149. #define LMS_PARAMS_BENCHED
  9150. #endif
  9151. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9152. (LMS_MAX_HEIGHT >= 10))
  9153. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9154. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9155. #endif
  9156. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9157. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9158. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9159. #endif
  9160. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9161. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9162. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9163. #endif
  9164. #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
  9165. #ifdef WOLFSSL_LMS_SHA256_192
  9166. #ifdef BENCH_LMS_SLOW_KEYGEN
  9167. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9168. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9169. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9170. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9171. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9172. #undef LMS_PARAMS_BENCHED
  9173. #define LMS_PARAMS_BENCHED
  9174. #endif
  9175. #endif
  9176. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9177. (LMS_MAX_HEIGHT >= 10))
  9178. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9179. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9180. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9181. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9182. #undef LMS_PARAMS_BENCHED
  9183. #define LMS_PARAMS_BENCHED
  9184. #ifdef BENCH_LMS_SLOW_KEYGEN
  9185. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9186. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9187. #endif
  9188. #endif
  9189. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9190. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9191. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9192. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9193. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9194. #undef LMS_PARAMS_BENCHED
  9195. #define LMS_PARAMS_BENCHED
  9196. #endif
  9197. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9198. (LMS_MAX_HEIGHT >= 10))
  9199. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9200. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9201. #endif
  9202. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9203. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9204. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9205. #endif
  9206. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9207. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9208. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9209. #endif
  9210. #endif /* WOLFSSL_LMS_SHA256_192 */
  9211. return;
  9212. }
  9213. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9214. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9215. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9216. void *context)
  9217. {
  9218. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9219. * BE USED FOR TESTING PURPOSES! Production applications should
  9220. * write only to non-volatile storage. */
  9221. XMEMCPY(context, priv, privSz);
  9222. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9223. }
  9224. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9225. void *context)
  9226. {
  9227. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9228. * BE USED FOR TESTING PURPOSES! */
  9229. XMEMCPY(priv, context, privSz);
  9230. return WC_XMSS_RC_READ_TO_MEMORY;
  9231. }
  9232. static void bench_xmss_sign_verify(const char * params)
  9233. {
  9234. WC_RNG rng;
  9235. XmssKey key;
  9236. word32 pkSz = 0;
  9237. word32 skSz = 0;
  9238. int freeRng = 0;
  9239. int freeKey = 0;
  9240. unsigned char * sk = NULL;
  9241. const char * msg = "XMSS post quantum signature test";
  9242. word32 msgSz = (word32) XSTRLEN(msg);
  9243. int ret = 0;
  9244. byte * sig = NULL;
  9245. word32 sigSz = 0;
  9246. int times = 0;
  9247. int count = 0;
  9248. double start = 0.0F;
  9249. #ifndef HAVE_FIPS
  9250. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9251. #else
  9252. ret = wc_InitRng(&rng);
  9253. #endif
  9254. if (ret != 0) {
  9255. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9256. goto exit_xmss_sign_verify;
  9257. }
  9258. freeRng = 1;
  9259. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9260. if (ret != 0) {
  9261. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9262. goto exit_xmss_sign_verify;
  9263. }
  9264. ret = wc_XmssKey_SetParamStr(&key, params);
  9265. if (ret != 0) {
  9266. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9267. goto exit_xmss_sign_verify;
  9268. }
  9269. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9270. if (ret != 0) {
  9271. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9272. goto exit_xmss_sign_verify;
  9273. }
  9274. #ifndef WOLFSSL_WC_XMSS
  9275. if (pkSz != XMSS_SHA256_PUBLEN) {
  9276. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9277. XMSS_SHA256_PUBLEN);
  9278. goto exit_xmss_sign_verify;
  9279. }
  9280. #endif
  9281. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9282. if (ret != 0 || skSz <= 0) {
  9283. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9284. goto exit_xmss_sign_verify;
  9285. }
  9286. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9287. if (ret != 0 || sigSz <= 0) {
  9288. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9289. goto exit_xmss_sign_verify;
  9290. }
  9291. /* Allocate secret keys.*/
  9292. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9293. if (sk == NULL) {
  9294. fprintf(stderr, "error: allocate xmss sk failed\n");
  9295. goto exit_xmss_sign_verify;
  9296. }
  9297. /* Allocate signature array. */
  9298. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9299. if (sig == NULL) {
  9300. fprintf(stderr, "error: allocate xmss sig failed\n");
  9301. goto exit_xmss_sign_verify;
  9302. }
  9303. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9304. if (ret != 0) {
  9305. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9306. goto exit_xmss_sign_verify;
  9307. }
  9308. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9309. if (ret != 0) {
  9310. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9311. goto exit_xmss_sign_verify;
  9312. }
  9313. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9314. if (ret != 0) {
  9315. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9316. goto exit_xmss_sign_verify;
  9317. }
  9318. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9319. fprintf(stderr, "params: %s\n", params);
  9320. fprintf(stderr, "pkSz: %d\n", pkSz);
  9321. fprintf(stderr, "skSz: %d\n", skSz);
  9322. fprintf(stderr, "sigSz: %d\n", sigSz);
  9323. #endif
  9324. /* Making the private key is the bottleneck for larger heights. */
  9325. count = 0;
  9326. bench_stats_start(&count, &start);
  9327. ret = wc_XmssKey_MakeKey(&key, &rng);
  9328. if (ret != 0) {
  9329. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9330. goto exit_xmss_sign_verify;
  9331. }
  9332. /* Can only do one at a time - state changes after make key. */
  9333. count +=1;
  9334. bench_stats_check(start);
  9335. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9336. freeKey = 1;
  9337. count = 0;
  9338. bench_stats_start(&count, &start);
  9339. do {
  9340. /* XMSS is stateful. Async queuing not practical. */
  9341. #ifndef WOLFSSL_WC_XMSS_SMALL
  9342. for (times = 0; times < ntimes; ++times)
  9343. #else
  9344. for (times = 0; times < 1; ++times)
  9345. #endif
  9346. {
  9347. if (!wc_XmssKey_SigsLeft(&key))
  9348. break;
  9349. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9350. if (ret) {
  9351. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9352. goto exit_xmss_sign_verify;
  9353. }
  9354. }
  9355. count += times;
  9356. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9357. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9358. count = 0;
  9359. bench_stats_start(&count, &start);
  9360. do {
  9361. /* XMSS is stateful. Async queuing not practical. */
  9362. for (times = 0; times < ntimes; ++times) {
  9363. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9364. if (ret) {
  9365. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9366. goto exit_xmss_sign_verify;
  9367. }
  9368. }
  9369. count += times;
  9370. } while (bench_stats_check(start));
  9371. exit_xmss_sign_verify:
  9372. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9373. /* Cleanup everything. */
  9374. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9375. sig = NULL;
  9376. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9377. sk = NULL;
  9378. if (freeRng) {
  9379. wc_FreeRng(&rng);
  9380. }
  9381. if (freeKey) {
  9382. wc_XmssKey_Free(&key);
  9383. }
  9384. return;
  9385. }
  9386. void bench_xmss(int hash)
  9387. {
  9388. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9389. * sets.
  9390. *
  9391. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9392. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9393. * very slow, their signatures and private keys quite large,
  9394. * and xmss private keys are not portable across different
  9395. * XMSS/XMSS^MT implementations.
  9396. *
  9397. * The bottleneck in key generation is the height of the first
  9398. * level tree (or h/d).
  9399. *
  9400. * h is the total height of the hyper tree, and d the number of
  9401. * trees.
  9402. */
  9403. /* h/d h d */
  9404. #ifdef WC_XMSS_SHA256
  9405. if (hash == WC_HASH_TYPE_SHA256) {
  9406. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9407. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9408. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9409. #endif
  9410. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9411. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9412. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9413. #endif
  9414. #endif
  9415. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9416. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9417. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9418. #endif
  9419. #endif
  9420. #endif /* HASH_SIZE 256 */
  9421. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9422. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9423. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9424. #endif
  9425. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9426. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9427. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9428. #endif
  9429. #endif
  9430. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9431. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9432. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9433. #endif
  9434. #endif
  9435. #endif /* HASH_SIZE 192 */
  9436. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9437. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9438. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9439. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9440. #endif
  9441. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9442. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9443. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9444. #endif
  9445. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9446. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9447. #endif
  9448. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9449. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9450. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9451. #endif
  9452. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9453. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9454. #endif
  9455. #endif /* HASH_SIZE 256 */
  9456. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9457. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9458. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9459. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9460. #endif
  9461. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9462. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9463. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9464. #endif
  9465. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9466. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9467. #endif
  9468. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9469. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9470. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9471. #endif
  9472. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9473. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9474. #endif
  9475. #endif /* HASH_SIZE 192 */
  9476. }
  9477. #endif
  9478. #ifdef WC_XMSS_SHA512
  9479. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9480. if (hash == WC_HASH_TYPE_SHA512) {
  9481. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9482. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9483. #endif
  9484. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9485. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9486. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9487. #endif
  9488. #endif
  9489. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9490. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9491. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9492. #endif
  9493. #endif
  9494. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9495. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9496. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9497. #endif
  9498. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9499. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9500. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9501. #endif
  9502. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9503. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9504. #endif
  9505. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9506. #endif
  9507. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9508. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9509. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9510. #endif
  9511. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9512. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9513. #endif
  9514. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9515. #endif
  9516. }
  9517. #endif /* HASH_SIZE 512 */
  9518. #endif
  9519. #ifdef WC_XMSS_SHAKE128
  9520. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9521. if (hash == WC_HASH_TYPE_SHAKE128) {
  9522. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9523. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9524. #endif
  9525. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9526. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9527. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9528. #endif
  9529. #endif
  9530. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9531. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9532. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9533. #endif
  9534. #endif
  9535. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9536. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9537. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9538. #endif
  9539. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9540. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9541. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9542. #endif
  9543. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9544. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9545. #endif
  9546. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9547. #endif
  9548. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9549. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9550. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9551. #endif
  9552. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9553. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9554. #endif
  9555. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9556. #endif
  9557. }
  9558. #endif /* HASH_SIZE 256 */
  9559. #endif
  9560. #ifdef WC_XMSS_SHAKE256
  9561. if (hash == WC_HASH_TYPE_SHAKE256) {
  9562. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9563. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9564. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9565. #endif
  9566. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9567. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9568. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9569. #endif
  9570. #endif
  9571. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9572. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9573. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9574. #endif
  9575. #endif
  9576. #endif /* HASH_SIZE 512 */
  9577. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9578. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9579. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9580. #endif
  9581. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9582. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9583. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9584. #endif
  9585. #endif
  9586. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9587. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9588. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9589. #endif
  9590. #endif
  9591. #endif /* HASH_SIZE 256 */
  9592. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9593. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9594. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9595. #endif
  9596. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9597. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9598. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9599. #endif
  9600. #endif
  9601. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9602. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9603. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9604. #endif
  9605. #endif
  9606. #endif /* HASH_SIZE 192 */
  9607. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9608. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9609. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9610. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9611. #endif
  9612. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9613. #endif
  9614. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9615. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9616. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9617. #endif
  9618. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9619. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9620. #endif
  9621. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9622. #endif
  9623. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9624. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9625. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9626. #endif
  9627. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9628. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9629. #endif
  9630. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9631. #endif
  9632. #endif /* HASH_SIZE 512 */
  9633. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9634. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9635. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9636. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9637. #endif
  9638. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9639. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9640. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9641. #endif
  9642. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9643. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9644. #endif
  9645. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9646. #endif
  9647. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9648. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9649. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9650. #endif
  9651. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9652. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9653. #endif
  9654. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9655. #endif
  9656. #endif /* HASH_SIZE 256 */
  9657. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9658. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9659. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9660. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9661. #endif
  9662. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9663. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9664. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9665. #endif
  9666. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9667. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9668. #endif
  9669. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9670. #endif
  9671. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9672. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9673. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9674. #endif
  9675. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9676. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9677. #endif
  9678. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9679. #endif
  9680. #endif /* HASH_SIZE 192 */
  9681. }
  9682. #endif
  9683. return;
  9684. }
  9685. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9686. #ifdef HAVE_ECC
  9687. /* Maximum ECC name plus null terminator:
  9688. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9689. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9690. /* run all benchmarks on a curve */
  9691. void bench_ecc_curve(int curveId)
  9692. {
  9693. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9694. #ifndef NO_SW_BENCH
  9695. bench_eccMakeKey(0, curveId);
  9696. #endif
  9697. #if defined(BENCH_DEVID)
  9698. bench_eccMakeKey(1, curveId);
  9699. #endif
  9700. }
  9701. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9702. #ifndef NO_SW_BENCH
  9703. bench_ecc(0, curveId);
  9704. #endif
  9705. #if defined(BENCH_DEVID)
  9706. bench_ecc(1, curveId);
  9707. #endif
  9708. }
  9709. #ifdef HAVE_ECC_ENCRYPT
  9710. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9711. bench_eccEncrypt(curveId);
  9712. #endif
  9713. }
  9714. void bench_eccMakeKey(int useDeviceID, int curveId)
  9715. {
  9716. int ret = 0, i, times, count = 0, pending = 0;
  9717. int deviceID;
  9718. int keySize = 0;
  9719. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9720. sizeof(ecc_key), HEAP_HINT);
  9721. char name[BENCH_ECC_NAME_SZ];
  9722. double start = 0;
  9723. const char**desc = bench_desc_words[lng_index];
  9724. DECLARE_MULTI_VALUE_STATS_VARS()
  9725. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9726. sizeof(ecc_key), HEAP_HINT);
  9727. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9728. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9729. /* ECC Make Key */
  9730. bench_stats_start(&count, &start);
  9731. do {
  9732. /* while free pending slots in queue, submit ops */
  9733. for (times = 0; times < agreeTimes || pending > 0; ) {
  9734. bench_async_poll(&pending);
  9735. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9736. if (bench_async_check(&ret,
  9737. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9738. &times, agreeTimes, &pending)) {
  9739. wc_ecc_free(genKey[i]);
  9740. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9741. if (ret < 0) {
  9742. goto exit;
  9743. }
  9744. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9745. curveId);
  9746. if (!bench_async_handle(&ret,
  9747. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9748. &pending)) {
  9749. goto exit;
  9750. }
  9751. }
  9752. } /* for i */
  9753. RECORD_MULTI_VALUE_STATS();
  9754. } /* for times */
  9755. count += times;
  9756. } while (bench_stats_check(start)
  9757. #ifdef MULTI_VALUE_STATISTICS
  9758. || runs < minimum_runs
  9759. #endif
  9760. );
  9761. exit:
  9762. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9763. wc_ecc_get_name(curveId));
  9764. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9765. useDeviceID, count, start, ret);
  9766. #ifdef MULTI_VALUE_STATISTICS
  9767. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9768. #endif
  9769. /* cleanup */
  9770. if (WC_ARRAY_OK(genKey)) {
  9771. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9772. wc_ecc_free(genKey[i]);
  9773. }
  9774. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9775. }
  9776. }
  9777. void bench_ecc(int useDeviceID, int curveId)
  9778. {
  9779. int ret = 0, i, times, count, pending = 0;
  9780. int deviceID;
  9781. int keySize;
  9782. char name[BENCH_ECC_NAME_SZ];
  9783. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9784. sizeof(ecc_key), HEAP_HINT);
  9785. #ifdef HAVE_ECC_DHE
  9786. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9787. sizeof(ecc_key), HEAP_HINT);
  9788. #endif
  9789. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9790. #ifdef HAVE_ECC_VERIFY
  9791. int verify[BENCH_MAX_PENDING];
  9792. #endif
  9793. #endif
  9794. word32 x[BENCH_MAX_PENDING];
  9795. double start = 0;
  9796. const char**desc = bench_desc_words[lng_index];
  9797. DECLARE_MULTI_VALUE_STATS_VARS()
  9798. #ifdef HAVE_ECC_DHE
  9799. WC_DECLARE_ARRAY(shared, byte,
  9800. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9801. #endif
  9802. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9803. WC_DECLARE_ARRAY(sig, byte,
  9804. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9805. WC_DECLARE_ARRAY(digest, byte,
  9806. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9807. #endif
  9808. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9809. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9810. XMEMSET(sig, 0, sizeof(sig));
  9811. XMEMSET(digest, 0, sizeof(digest));
  9812. #endif
  9813. #ifdef HAVE_ECC_DHE
  9814. XMEMSET(shared, 0, sizeof(shared));
  9815. #endif
  9816. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9817. sizeof(ecc_key), HEAP_HINT);
  9818. #ifdef HAVE_ECC_DHE
  9819. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9820. sizeof(ecc_key), HEAP_HINT);
  9821. WC_ALLOC_ARRAY(shared, byte,
  9822. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9823. #endif
  9824. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9825. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9826. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9827. #endif
  9828. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9829. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9830. /* init keys */
  9831. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9832. /* setup an context for each key */
  9833. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9834. goto exit;
  9835. }
  9836. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9837. #ifdef WOLFSSL_ASYNC_CRYPT
  9838. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9839. #endif
  9840. if (ret < 0) {
  9841. goto exit;
  9842. }
  9843. #ifdef HAVE_ECC_DHE
  9844. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9845. goto exit;
  9846. }
  9847. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9848. curveId)) > 0) {
  9849. goto exit;
  9850. }
  9851. #endif
  9852. }
  9853. #ifdef HAVE_ECC_DHE
  9854. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9855. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9856. !defined(HAVE_SELFTEST)
  9857. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9858. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9859. }
  9860. #endif
  9861. /* ECC Shared Secret */
  9862. bench_stats_start(&count, &start);
  9863. PRIVATE_KEY_UNLOCK();
  9864. do {
  9865. for (times = 0; times < agreeTimes || pending > 0; ) {
  9866. bench_async_poll(&pending);
  9867. /* while free pending slots in queue, submit ops */
  9868. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9869. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9870. &times, agreeTimes, &pending)) {
  9871. x[i] = (word32)keySize;
  9872. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9873. shared[i], &x[i]);
  9874. if (!bench_async_handle(&ret,
  9875. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9876. &pending)) {
  9877. goto exit_ecdhe;
  9878. }
  9879. }
  9880. } /* for i */
  9881. RECORD_MULTI_VALUE_STATS();
  9882. } /* for times */
  9883. count += times;
  9884. } while (bench_stats_check(start)
  9885. #ifdef MULTI_VALUE_STATISTICS
  9886. || runs < minimum_runs
  9887. #endif
  9888. );
  9889. PRIVATE_KEY_UNLOCK();
  9890. exit_ecdhe:
  9891. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9892. wc_ecc_get_name(curveId));
  9893. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9894. useDeviceID, count, start, ret);
  9895. #ifdef MULTI_VALUE_STATISTICS
  9896. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9897. #endif
  9898. RESET_MULTI_VALUE_STATS_VARS();
  9899. if (ret < 0) {
  9900. goto exit;
  9901. }
  9902. #endif /* HAVE_ECC_DHE */
  9903. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9904. /* Init digest to sign */
  9905. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9906. for (count = 0; count < keySize; count++) {
  9907. digest[i][count] = (byte)count;
  9908. }
  9909. }
  9910. /* ECC Sign */
  9911. bench_stats_start(&count, &start);
  9912. do {
  9913. for (times = 0; times < agreeTimes || pending > 0; ) {
  9914. bench_async_poll(&pending);
  9915. /* while free pending slots in queue, submit ops */
  9916. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9917. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9918. &times, agreeTimes, &pending)) {
  9919. if (genKey[i]->state == 0) {
  9920. x[i] = ECC_MAX_SIG_SIZE;
  9921. }
  9922. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9923. &x[i], GLOBAL_RNG, genKey[i]);
  9924. if (!bench_async_handle(&ret,
  9925. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9926. &pending)) {
  9927. goto exit_ecdsa_sign;
  9928. }
  9929. } /* bench_async_check */
  9930. } /* for i */
  9931. RECORD_MULTI_VALUE_STATS();
  9932. } /* for times */
  9933. count += times;
  9934. } while (bench_stats_check(start)
  9935. #ifdef MULTI_VALUE_STATISTICS
  9936. || runs < minimum_runs
  9937. #endif
  9938. );
  9939. exit_ecdsa_sign:
  9940. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9941. wc_ecc_get_name(curveId));
  9942. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9943. useDeviceID, count, start, ret);
  9944. #ifdef MULTI_VALUE_STATISTICS
  9945. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9946. #endif
  9947. RESET_MULTI_VALUE_STATS_VARS();
  9948. if (ret < 0) {
  9949. goto exit;
  9950. }
  9951. #ifdef HAVE_ECC_VERIFY
  9952. /* ECC Verify */
  9953. bench_stats_start(&count, &start);
  9954. do {
  9955. for (times = 0; times < agreeTimes || pending > 0; ) {
  9956. bench_async_poll(&pending);
  9957. /* while free pending slots in queue, submit ops */
  9958. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9959. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9960. &times, agreeTimes, &pending)) {
  9961. if (genKey[i]->state == 0) {
  9962. verify[i] = 0;
  9963. }
  9964. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9965. (word32)keySize, &verify[i],
  9966. genKey[i]);
  9967. if (!bench_async_handle(&ret,
  9968. BENCH_ASYNC_GET_DEV(genKey[i]),
  9969. 1, &times,
  9970. &pending)) {
  9971. goto exit_ecdsa_verify;
  9972. }
  9973. } /* if bench_async_check */
  9974. } /* for i */
  9975. RECORD_MULTI_VALUE_STATS();
  9976. } /* for times */
  9977. count += times;
  9978. } while (bench_stats_check(start)
  9979. #ifdef MULTI_VALUE_STATISTICS
  9980. || runs < minimum_runs
  9981. #endif
  9982. );
  9983. exit_ecdsa_verify:
  9984. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9985. wc_ecc_get_name(curveId));
  9986. bench_stats_asym_finish(name, keySize * 8, desc[5],
  9987. useDeviceID, count, start, ret);
  9988. #ifdef MULTI_VALUE_STATISTICS
  9989. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9990. #endif
  9991. #endif /* HAVE_ECC_VERIFY */
  9992. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  9993. exit:
  9994. /* cleanup */
  9995. if (WC_ARRAY_OK(genKey)) {
  9996. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9997. wc_ecc_free(genKey[i]);
  9998. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9999. }
  10000. #ifdef HAVE_ECC_DHE
  10001. if (WC_ARRAY_OK(genKey2)) {
  10002. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10003. wc_ecc_free(genKey2[i]);
  10004. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10005. }
  10006. #endif
  10007. #ifdef HAVE_ECC_DHE
  10008. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10009. #endif
  10010. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10011. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10012. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10013. #endif
  10014. (void)useDeviceID;
  10015. (void)pending;
  10016. (void)x;
  10017. (void)count;
  10018. (void)times;
  10019. (void)desc;
  10020. (void)start;
  10021. (void)name;
  10022. }
  10023. #ifdef HAVE_ECC_ENCRYPT
  10024. void bench_eccEncrypt(int curveId)
  10025. {
  10026. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  10027. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  10028. WC_SHA256_DIGEST_SIZE + \
  10029. (MAX_ECC_BITS+3)/4 + 2)
  10030. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  10031. #ifdef WOLFSSL_SMALL_STACK
  10032. ecc_key *userA = NULL, *userB = NULL;
  10033. byte *msg = NULL;
  10034. byte *out = NULL;
  10035. #else
  10036. ecc_key userA[1], userB[1];
  10037. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  10038. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  10039. #endif
  10040. char name[BENCH_ECC_NAME_SZ];
  10041. int keySize;
  10042. word32 bench_plainSz = bench_size;
  10043. int ret, i, count;
  10044. double start;
  10045. const char**desc = bench_desc_words[lng_index];
  10046. DECLARE_MULTI_VALUE_STATS_VARS()
  10047. #ifdef WOLFSSL_SMALL_STACK
  10048. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  10049. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10050. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  10051. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10052. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  10053. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10054. out = (byte *)XMALLOC(outSz,
  10055. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10056. if ((! userA) || (! userB) || (! msg) || (! out)) {
  10057. printf("bench_eccEncrypt malloc failed\n");
  10058. goto exit;
  10059. }
  10060. #endif
  10061. keySize = wc_ecc_get_curve_size_from_id(curveId);
  10062. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  10063. if (ret != 0) {
  10064. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  10065. goto exit;
  10066. }
  10067. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  10068. if (ret != 0) {
  10069. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  10070. goto exit;
  10071. }
  10072. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10073. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10074. !defined(HAVE_SELFTEST)
  10075. ret = wc_ecc_set_rng(userA, &gRng);
  10076. if (ret != 0) {
  10077. goto exit;
  10078. }
  10079. ret = wc_ecc_set_rng(userB, &gRng);
  10080. if (ret != 0) {
  10081. goto exit;
  10082. }
  10083. #endif
  10084. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  10085. #ifdef WOLFSSL_ASYNC_CRYPT
  10086. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  10087. #endif
  10088. if (ret != 0)
  10089. goto exit;
  10090. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  10091. #ifdef WOLFSSL_ASYNC_CRYPT
  10092. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  10093. #endif
  10094. if (ret != 0)
  10095. goto exit;
  10096. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  10097. msg[i] = (byte)i;
  10098. }
  10099. bench_stats_start(&count, &start);
  10100. do {
  10101. for (i = 0; i < ntimes; i++) {
  10102. /* encrypt msg to B */
  10103. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  10104. out, &outSz, NULL);
  10105. if (ret != 0) {
  10106. printf("wc_ecc_encrypt failed! %d\n", ret);
  10107. goto exit_enc;
  10108. }
  10109. RECORD_MULTI_VALUE_STATS();
  10110. }
  10111. count += i;
  10112. } while (bench_stats_check(start)
  10113. #ifdef MULTI_VALUE_STATISTICS
  10114. || runs < minimum_runs
  10115. #endif
  10116. );
  10117. exit_enc:
  10118. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10119. wc_ecc_get_name(curveId));
  10120. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10121. #ifdef MULTI_VALUE_STATISTICS
  10122. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10123. #endif
  10124. RESET_MULTI_VALUE_STATS_VARS();
  10125. if (ret != 0)
  10126. goto exit;
  10127. bench_stats_start(&count, &start);
  10128. do {
  10129. for (i = 0; i < ntimes; i++) {
  10130. /* decrypt msg from A */
  10131. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10132. &bench_plainSz, NULL);
  10133. if (ret != 0) {
  10134. printf("wc_ecc_decrypt failed! %d\n", ret);
  10135. goto exit_dec;
  10136. }
  10137. RECORD_MULTI_VALUE_STATS();
  10138. }
  10139. count += i;
  10140. } while (bench_stats_check(start)
  10141. #ifdef MULTI_VALUE_STATISTICS
  10142. || runs < minimum_runs
  10143. #endif
  10144. );
  10145. exit_dec:
  10146. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10147. #ifdef MULTI_VALUE_STATISTICS
  10148. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10149. #endif
  10150. exit:
  10151. /* cleanup */
  10152. #ifdef WOLFSSL_SMALL_STACK
  10153. if (userA) {
  10154. wc_ecc_free(userA);
  10155. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10156. }
  10157. if (userB) {
  10158. wc_ecc_free(userB);
  10159. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10160. }
  10161. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10162. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10163. #else
  10164. wc_ecc_free(userB);
  10165. wc_ecc_free(userA);
  10166. #endif
  10167. }
  10168. #endif
  10169. #ifdef WOLFSSL_SM2
  10170. static void bench_sm2_MakeKey(int useDeviceID)
  10171. {
  10172. int ret = 0, i, times, count = 0, pending = 0;
  10173. int deviceID;
  10174. int keySize;
  10175. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10176. sizeof(ecc_key), HEAP_HINT);
  10177. char name[BENCH_ECC_NAME_SZ];
  10178. double start = 0;
  10179. const char**desc = bench_desc_words[lng_index];
  10180. DECLARE_MULTI_VALUE_STATS_VARS()
  10181. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10182. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10183. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10184. sizeof(ecc_key), HEAP_HINT);
  10185. /* ECC Make Key */
  10186. bench_stats_start(&count, &start);
  10187. do {
  10188. /* while free pending slots in queue, submit ops */
  10189. for (times = 0; times < agreeTimes || pending > 0; ) {
  10190. bench_async_poll(&pending);
  10191. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10192. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10193. &times, agreeTimes, &pending)) {
  10194. wc_ecc_free(genKey[i]);
  10195. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10196. if (ret < 0) {
  10197. goto exit;
  10198. }
  10199. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10200. WC_ECC_FLAG_NONE);
  10201. if (!bench_async_handle(&ret,
  10202. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10203. &pending)) {
  10204. goto exit;
  10205. }
  10206. }
  10207. } /* for i */
  10208. RECORD_MULTI_VALUE_STATS();
  10209. } /* for times */
  10210. count += times;
  10211. } while (bench_stats_check(start)
  10212. #ifdef MULTI_VALUE_STATISTICS
  10213. || runs < minimum_runs
  10214. #endif
  10215. );
  10216. exit:
  10217. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10218. wc_ecc_get_name(ECC_SM2P256V1));
  10219. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10220. start, ret);
  10221. #ifdef MULTI_VALUE_STATISTICS
  10222. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10223. #endif
  10224. /* cleanup */
  10225. if (WC_ARRAY_OK(genKey)) {
  10226. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10227. wc_ecc_free(genKey[i]);
  10228. }
  10229. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10230. }
  10231. }
  10232. void bench_sm2(int useDeviceID)
  10233. {
  10234. int ret = 0, i, times, count, pending = 0;
  10235. int deviceID;
  10236. int keySize;
  10237. char name[BENCH_ECC_NAME_SZ];
  10238. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10239. sizeof(ecc_key), HEAP_HINT);
  10240. #ifdef HAVE_ECC_DHE
  10241. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10242. sizeof(ecc_key), HEAP_HINT);
  10243. #endif
  10244. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10245. #ifdef HAVE_ECC_VERIFY
  10246. int verify[BENCH_MAX_PENDING];
  10247. #endif
  10248. #endif
  10249. word32 x[BENCH_MAX_PENDING];
  10250. double start = 0;
  10251. const char**desc = bench_desc_words[lng_index];
  10252. DECLARE_MULTI_VALUE_STATS_VARS()
  10253. #ifdef HAVE_ECC_DHE
  10254. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10255. #endif
  10256. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10257. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10258. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10259. #endif
  10260. #ifdef HAVE_ECC_DHE
  10261. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10262. #endif
  10263. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10264. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10265. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10266. #endif
  10267. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10268. bench_sm2_MakeKey(useDeviceID);
  10269. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10270. sizeof(ecc_key), HEAP_HINT);
  10271. #ifdef HAVE_ECC_DHE
  10272. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10273. sizeof(ecc_key), HEAP_HINT);
  10274. #endif
  10275. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10276. /* init keys */
  10277. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10278. /* setup an context for each key */
  10279. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10280. goto exit;
  10281. }
  10282. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10283. #ifdef WOLFSSL_ASYNC_CRYPT
  10284. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10285. #endif
  10286. if (ret < 0) {
  10287. goto exit;
  10288. }
  10289. #ifdef HAVE_ECC_DHE
  10290. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10291. goto exit;
  10292. }
  10293. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10294. WC_ECC_FLAG_NONE)) > 0) {
  10295. goto exit;
  10296. }
  10297. #endif
  10298. }
  10299. #ifdef HAVE_ECC_DHE
  10300. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10301. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10302. !defined(HAVE_SELFTEST)
  10303. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10304. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10305. }
  10306. #endif
  10307. /* ECC Shared Secret */
  10308. bench_stats_start(&count, &start);
  10309. PRIVATE_KEY_UNLOCK();
  10310. do {
  10311. for (times = 0; times < agreeTimes || pending > 0; ) {
  10312. bench_async_poll(&pending);
  10313. /* while free pending slots in queue, submit ops */
  10314. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10315. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10316. &times, agreeTimes, &pending)) {
  10317. x[i] = (word32)keySize;
  10318. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10319. shared[i], &x[i]);
  10320. if (!bench_async_handle(&ret,
  10321. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10322. &pending)) {
  10323. goto exit_ecdhe;
  10324. }
  10325. }
  10326. } /* for i */
  10327. RECORD_MULTI_VALUE_STATS();
  10328. } /* for times */
  10329. count += times;
  10330. } while (bench_stats_check(start)
  10331. #ifdef MULTI_VALUE_STATISTICS
  10332. || runs < minimum_runs
  10333. #endif
  10334. );
  10335. PRIVATE_KEY_UNLOCK();
  10336. exit_ecdhe:
  10337. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10338. wc_ecc_get_name(ECC_SM2P256V1));
  10339. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10340. start, ret);
  10341. #ifdef MULTI_VALUE_STATISTICS
  10342. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10343. #endif
  10344. if (ret < 0) {
  10345. goto exit;
  10346. }
  10347. #endif /* HAVE_ECC_DHE */
  10348. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10349. /* Init digest to sign */
  10350. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10351. for (count = 0; count < keySize; count++) {
  10352. digest[i][count] = (byte)count;
  10353. }
  10354. }
  10355. RESET_MULTI_VALUE_STATS_VARS();
  10356. /* ECC Sign */
  10357. bench_stats_start(&count, &start);
  10358. do {
  10359. for (times = 0; times < agreeTimes || pending > 0; ) {
  10360. bench_async_poll(&pending);
  10361. /* while free pending slots in queue, submit ops */
  10362. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10363. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10364. &times, agreeTimes, &pending)) {
  10365. if (genKey[i]->state == 0)
  10366. x[i] = ECC_MAX_SIG_SIZE;
  10367. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10368. sig[i], &x[i], &gRng, genKey[i]);
  10369. if (!bench_async_handle(&ret,
  10370. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10371. &pending)) {
  10372. goto exit_ecdsa_sign;
  10373. }
  10374. }
  10375. } /* for i */
  10376. RECORD_MULTI_VALUE_STATS();
  10377. } /* for times */
  10378. count += times;
  10379. } while (bench_stats_check(start)
  10380. #ifdef MULTI_VALUE_STATISTICS
  10381. || runs < minimum_runs
  10382. #endif
  10383. );
  10384. exit_ecdsa_sign:
  10385. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10386. wc_ecc_get_name(ECC_SM2P256V1));
  10387. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10388. start, ret);
  10389. #ifdef MULTI_VALUE_STATISTICS
  10390. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10391. #endif
  10392. if (ret < 0) {
  10393. goto exit;
  10394. }
  10395. #ifdef HAVE_ECC_VERIFY
  10396. /* ECC Verify */
  10397. bench_stats_start(&count, &start);
  10398. do {
  10399. for (times = 0; times < agreeTimes || pending > 0; ) {
  10400. bench_async_poll(&pending);
  10401. /* while free pending slots in queue, submit ops */
  10402. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10403. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10404. &times, agreeTimes, &pending)) {
  10405. if (genKey[i]->state == 0)
  10406. verify[i] = 0;
  10407. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10408. (word32)keySize, &verify[i], genKey[i]);
  10409. if (!bench_async_handle(&ret,
  10410. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10411. &pending)) {
  10412. goto exit_ecdsa_verify;
  10413. }
  10414. }
  10415. } /* for i */
  10416. RECORD_MULTI_VALUE_STATS();
  10417. } /* for times */
  10418. count += times;
  10419. } while (bench_stats_check(start)
  10420. #ifdef MULTI_VALUE_STATISTICS
  10421. || runs < minimum_runs
  10422. #endif
  10423. );
  10424. exit_ecdsa_verify:
  10425. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10426. wc_ecc_get_name(ECC_SM2P256V1));
  10427. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10428. start, ret);
  10429. #ifdef MULTI_VALUE_STATISTICS
  10430. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10431. #endif
  10432. #endif /* HAVE_ECC_VERIFY */
  10433. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10434. exit:
  10435. /* cleanup */
  10436. if (WC_ARRAY_OK(genKey)) {
  10437. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10438. wc_ecc_free(genKey[i]);
  10439. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10440. }
  10441. #ifdef HAVE_ECC_DHE
  10442. if (WC_ARRAY_OK(genKey2)) {
  10443. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10444. wc_ecc_free(genKey2[i]);
  10445. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10446. }
  10447. #endif
  10448. #ifdef HAVE_ECC_DHE
  10449. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10450. #endif
  10451. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10452. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10453. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10454. #endif
  10455. (void)useDeviceID;
  10456. (void)pending;
  10457. (void)x;
  10458. (void)count;
  10459. (void)times;
  10460. (void)desc;
  10461. (void)start;
  10462. (void)name;
  10463. }
  10464. #endif /* WOLFSSL_SM2 */
  10465. #endif /* HAVE_ECC */
  10466. #ifdef HAVE_CURVE25519
  10467. void bench_curve25519KeyGen(int useDeviceID)
  10468. {
  10469. curve25519_key genKey;
  10470. double start;
  10471. int ret = 0, i, count;
  10472. const char**desc = bench_desc_words[lng_index];
  10473. DECLARE_MULTI_VALUE_STATS_VARS()
  10474. /* Key Gen */
  10475. bench_stats_start(&count, &start);
  10476. do {
  10477. for (i = 0; i < genTimes; i++) {
  10478. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10479. useDeviceID ? devId : INVALID_DEVID);
  10480. if (ret != 0) {
  10481. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10482. break;
  10483. }
  10484. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10485. wc_curve25519_free(&genKey);
  10486. if (ret != 0) {
  10487. printf("wc_curve25519_make_key failed: %d\n", ret);
  10488. break;
  10489. }
  10490. RECORD_MULTI_VALUE_STATS();
  10491. }
  10492. count += i;
  10493. } while (bench_stats_check(start)
  10494. #ifdef MULTI_VALUE_STATISTICS
  10495. || runs < minimum_runs
  10496. #endif
  10497. );
  10498. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10499. ret);
  10500. #ifdef MULTI_VALUE_STATISTICS
  10501. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10502. #endif
  10503. }
  10504. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10505. void bench_curve25519KeyAgree(int useDeviceID)
  10506. {
  10507. curve25519_key genKey, genKey2;
  10508. double start;
  10509. int ret, i, count;
  10510. byte shared[32];
  10511. const char**desc = bench_desc_words[lng_index];
  10512. word32 x = 0;
  10513. DECLARE_MULTI_VALUE_STATS_VARS()
  10514. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10515. useDeviceID ? devId : INVALID_DEVID);
  10516. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10517. useDeviceID ? devId : INVALID_DEVID);
  10518. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10519. if (ret != 0) {
  10520. printf("curve25519_make_key failed\n");
  10521. return;
  10522. }
  10523. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10524. if (ret != 0) {
  10525. printf("curve25519_make_key failed: %d\n", ret);
  10526. wc_curve25519_free(&genKey);
  10527. return;
  10528. }
  10529. /* Shared secret */
  10530. bench_stats_start(&count, &start);
  10531. do {
  10532. for (i = 0; i < agreeTimes; i++) {
  10533. x = sizeof(shared);
  10534. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10535. if (ret != 0) {
  10536. printf("curve25519_shared_secret failed: %d\n", ret);
  10537. goto exit;
  10538. }
  10539. RECORD_MULTI_VALUE_STATS();
  10540. }
  10541. count += i;
  10542. } while (bench_stats_check(start)
  10543. #ifdef MULTI_VALUE_STATISTICS
  10544. || runs < minimum_runs
  10545. #endif
  10546. );
  10547. exit:
  10548. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10549. ret);
  10550. #ifdef MULTI_VALUE_STATISTICS
  10551. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10552. #endif
  10553. wc_curve25519_free(&genKey2);
  10554. wc_curve25519_free(&genKey);
  10555. }
  10556. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10557. #endif /* HAVE_CURVE25519 */
  10558. #ifdef HAVE_ED25519
  10559. void bench_ed25519KeyGen(void)
  10560. {
  10561. #ifdef HAVE_ED25519_MAKE_KEY
  10562. ed25519_key genKey;
  10563. double start;
  10564. int i, count;
  10565. const char**desc = bench_desc_words[lng_index];
  10566. DECLARE_MULTI_VALUE_STATS_VARS()
  10567. /* Key Gen */
  10568. bench_stats_start(&count, &start);
  10569. do {
  10570. for (i = 0; i < genTimes; i++) {
  10571. wc_ed25519_init(&genKey);
  10572. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10573. wc_ed25519_free(&genKey);
  10574. RECORD_MULTI_VALUE_STATS();
  10575. }
  10576. count += i;
  10577. } while (bench_stats_check(start)
  10578. #ifdef MULTI_VALUE_STATISTICS
  10579. || runs < minimum_runs
  10580. #endif
  10581. );
  10582. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10583. #ifdef MULTI_VALUE_STATISTICS
  10584. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10585. #endif
  10586. #endif /* HAVE_ED25519_MAKE_KEY */
  10587. }
  10588. void bench_ed25519KeySign(void)
  10589. {
  10590. #ifdef HAVE_ED25519_MAKE_KEY
  10591. int ret;
  10592. #endif
  10593. ed25519_key genKey;
  10594. #ifdef HAVE_ED25519_SIGN
  10595. double start;
  10596. int i, count;
  10597. byte sig[ED25519_SIG_SIZE];
  10598. byte msg[512];
  10599. word32 x = 0;
  10600. const char**desc = bench_desc_words[lng_index];
  10601. DECLARE_MULTI_VALUE_STATS_VARS()
  10602. #endif
  10603. wc_ed25519_init(&genKey);
  10604. #ifdef HAVE_ED25519_MAKE_KEY
  10605. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10606. if (ret != 0) {
  10607. printf("ed25519_make_key failed\n");
  10608. return;
  10609. }
  10610. #endif
  10611. #ifdef HAVE_ED25519_SIGN
  10612. /* make dummy msg */
  10613. for (i = 0; i < (int)sizeof(msg); i++)
  10614. msg[i] = (byte)i;
  10615. bench_stats_start(&count, &start);
  10616. do {
  10617. for (i = 0; i < agreeTimes; i++) {
  10618. x = sizeof(sig);
  10619. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10620. if (ret != 0) {
  10621. printf("ed25519_sign_msg failed\n");
  10622. goto exit_ed_sign;
  10623. }
  10624. RECORD_MULTI_VALUE_STATS();
  10625. }
  10626. count += i;
  10627. } while (bench_stats_check(start)
  10628. #ifdef MULTI_VALUE_STATISTICS
  10629. || runs < minimum_runs
  10630. #endif
  10631. );
  10632. exit_ed_sign:
  10633. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10634. #ifdef MULTI_VALUE_STATISTICS
  10635. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10636. #endif
  10637. RESET_MULTI_VALUE_STATS_VARS();
  10638. #ifdef HAVE_ED25519_VERIFY
  10639. bench_stats_start(&count, &start);
  10640. do {
  10641. for (i = 0; i < agreeTimes; i++) {
  10642. int verify = 0;
  10643. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10644. &genKey);
  10645. if (ret != 0 || verify != 1) {
  10646. printf("ed25519_verify_msg failed\n");
  10647. goto exit_ed_verify;
  10648. }
  10649. RECORD_MULTI_VALUE_STATS();
  10650. }
  10651. count += i;
  10652. } while (bench_stats_check(start)
  10653. #ifdef MULTI_VALUE_STATISTICS
  10654. || runs < minimum_runs
  10655. #endif
  10656. );
  10657. exit_ed_verify:
  10658. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10659. #ifdef MULTI_VALUE_STATISTICS
  10660. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10661. #endif
  10662. #endif /* HAVE_ED25519_VERIFY */
  10663. #endif /* HAVE_ED25519_SIGN */
  10664. wc_ed25519_free(&genKey);
  10665. }
  10666. #endif /* HAVE_ED25519 */
  10667. #ifdef HAVE_CURVE448
  10668. void bench_curve448KeyGen(void)
  10669. {
  10670. curve448_key genKey;
  10671. double start;
  10672. int ret = 0, i, count;
  10673. const char**desc = bench_desc_words[lng_index];
  10674. DECLARE_MULTI_VALUE_STATS_VARS()
  10675. /* Key Gen */
  10676. bench_stats_start(&count, &start);
  10677. do {
  10678. for (i = 0; i < genTimes; i++) {
  10679. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10680. wc_curve448_free(&genKey);
  10681. if (ret != 0) {
  10682. printf("wc_curve448_make_key failed: %d\n", ret);
  10683. break;
  10684. }
  10685. RECORD_MULTI_VALUE_STATS();
  10686. }
  10687. count += i;
  10688. } while (bench_stats_check(start)
  10689. #ifdef MULTI_VALUE_STATISTICS
  10690. || runs < minimum_runs
  10691. #endif
  10692. );
  10693. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10694. #ifdef MULTI_VALUE_STATISTICS
  10695. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10696. #endif
  10697. }
  10698. #ifdef HAVE_CURVE448_SHARED_SECRET
  10699. void bench_curve448KeyAgree(void)
  10700. {
  10701. curve448_key genKey, genKey2;
  10702. double start;
  10703. int ret, i, count;
  10704. byte shared[56];
  10705. const char**desc = bench_desc_words[lng_index];
  10706. word32 x = 0;
  10707. DECLARE_MULTI_VALUE_STATS_VARS()
  10708. wc_curve448_init(&genKey);
  10709. wc_curve448_init(&genKey2);
  10710. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10711. if (ret != 0) {
  10712. printf("curve448_make_key failed\n");
  10713. return;
  10714. }
  10715. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10716. if (ret != 0) {
  10717. printf("curve448_make_key failed: %d\n", ret);
  10718. wc_curve448_free(&genKey);
  10719. return;
  10720. }
  10721. /* Shared secret */
  10722. bench_stats_start(&count, &start);
  10723. do {
  10724. for (i = 0; i < agreeTimes; i++) {
  10725. x = sizeof(shared);
  10726. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10727. if (ret != 0) {
  10728. printf("curve448_shared_secret failed: %d\n", ret);
  10729. goto exit;
  10730. }
  10731. RECORD_MULTI_VALUE_STATS();
  10732. }
  10733. count += i;
  10734. } while (bench_stats_check(start)
  10735. #ifdef MULTI_VALUE_STATISTICS
  10736. || runs < minimum_runs
  10737. #endif
  10738. );
  10739. exit:
  10740. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10741. #ifdef MULTI_VALUE_STATISTICS
  10742. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10743. #endif
  10744. wc_curve448_free(&genKey2);
  10745. wc_curve448_free(&genKey);
  10746. }
  10747. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10748. #endif /* HAVE_CURVE448 */
  10749. #ifdef HAVE_ED448
  10750. void bench_ed448KeyGen(void)
  10751. {
  10752. ed448_key genKey;
  10753. double start;
  10754. int i, count;
  10755. const char**desc = bench_desc_words[lng_index];
  10756. DECLARE_MULTI_VALUE_STATS_VARS()
  10757. /* Key Gen */
  10758. bench_stats_start(&count, &start);
  10759. do {
  10760. for (i = 0; i < genTimes; i++) {
  10761. wc_ed448_init(&genKey);
  10762. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10763. wc_ed448_free(&genKey);
  10764. RECORD_MULTI_VALUE_STATS();
  10765. }
  10766. count += i;
  10767. } while (bench_stats_check(start)
  10768. #ifdef MULTI_VALUE_STATISTICS
  10769. || runs < minimum_runs
  10770. #endif
  10771. );
  10772. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10773. #ifdef MULTI_VALUE_STATISTICS
  10774. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10775. #endif
  10776. }
  10777. void bench_ed448KeySign(void)
  10778. {
  10779. int ret;
  10780. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10781. #ifdef HAVE_ED448_SIGN
  10782. double start;
  10783. int i, count;
  10784. byte sig[ED448_SIG_SIZE];
  10785. byte msg[512];
  10786. word32 x = 0;
  10787. const char**desc = bench_desc_words[lng_index];
  10788. DECLARE_MULTI_VALUE_STATS_VARS()
  10789. #endif
  10790. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10791. wc_ed448_init(genKey);
  10792. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10793. if (ret != 0) {
  10794. printf("ed448_make_key failed\n");
  10795. goto exit;
  10796. }
  10797. #ifdef HAVE_ED448_SIGN
  10798. /* make dummy msg */
  10799. for (i = 0; i < (int)sizeof(msg); i++)
  10800. msg[i] = (byte)i;
  10801. bench_stats_start(&count, &start);
  10802. do {
  10803. for (i = 0; i < agreeTimes; i++) {
  10804. x = sizeof(sig);
  10805. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10806. NULL, 0);
  10807. if (ret != 0) {
  10808. printf("ed448_sign_msg failed\n");
  10809. goto exit;
  10810. }
  10811. RECORD_MULTI_VALUE_STATS();
  10812. }
  10813. count += i;
  10814. } while (bench_stats_check(start)
  10815. #ifdef MULTI_VALUE_STATISTICS
  10816. || runs < minimum_runs
  10817. #endif
  10818. );
  10819. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10820. #ifdef MULTI_VALUE_STATISTICS
  10821. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10822. #endif
  10823. RESET_MULTI_VALUE_STATS_VARS();
  10824. #ifdef HAVE_ED448_VERIFY
  10825. bench_stats_start(&count, &start);
  10826. do {
  10827. for (i = 0; i < agreeTimes; i++) {
  10828. int verify = 0;
  10829. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10830. genKey, NULL, 0);
  10831. if (ret != 0 || verify != 1) {
  10832. printf("ed448_verify_msg failed\n");
  10833. goto exit;
  10834. }
  10835. RECORD_MULTI_VALUE_STATS();
  10836. }
  10837. count += i;
  10838. } while (bench_stats_check(start)
  10839. #ifdef MULTI_VALUE_STATISTICS
  10840. || runs < minimum_runs
  10841. #endif
  10842. );
  10843. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10844. #ifdef MULTI_VALUE_STATISTICS
  10845. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10846. #endif
  10847. #endif /* HAVE_ED448_VERIFY */
  10848. #endif /* HAVE_ED448_SIGN */
  10849. exit:
  10850. wc_ed448_free(genKey);
  10851. WC_FREE_VAR(genKey, HEAP_HINT);
  10852. }
  10853. #endif /* HAVE_ED448 */
  10854. #ifdef WOLFCRYPT_HAVE_ECCSI
  10855. #ifdef WOLFCRYPT_ECCSI_KMS
  10856. void bench_eccsiKeyGen(void)
  10857. {
  10858. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10859. double start;
  10860. int i, count;
  10861. const char**desc = bench_desc_words[lng_index];
  10862. int ret;
  10863. DECLARE_MULTI_VALUE_STATS_VARS()
  10864. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10865. /* Key Gen */
  10866. bench_stats_start(&count, &start);
  10867. do {
  10868. for (i = 0; i < genTimes; i++) {
  10869. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10870. ret = wc_MakeEccsiKey(genKey, &gRng);
  10871. wc_FreeEccsiKey(genKey);
  10872. if (ret != 0) {
  10873. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10874. goto exit;
  10875. }
  10876. RECORD_MULTI_VALUE_STATS();
  10877. }
  10878. count += i;
  10879. } while (bench_stats_check(start)
  10880. #ifdef MULTI_VALUE_STATISTICS
  10881. || runs < minimum_runs
  10882. #endif
  10883. );
  10884. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10885. #ifdef MULTI_VALUE_STATISTICS
  10886. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10887. #endif
  10888. exit:
  10889. WC_FREE_VAR(genKey, HEAP_HINT);
  10890. }
  10891. void bench_eccsiPairGen(void)
  10892. {
  10893. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10894. double start;
  10895. int i, count;
  10896. const char**desc = bench_desc_words[lng_index];
  10897. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10898. ecc_point* pvt;
  10899. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10900. int ret;
  10901. DECLARE_MULTI_VALUE_STATS_VARS()
  10902. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10903. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10904. (void)mp_init(ssk);
  10905. pvt = wc_ecc_new_point();
  10906. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10907. (void)wc_MakeEccsiKey(genKey, &gRng);
  10908. /* RSK Gen */
  10909. bench_stats_start(&count, &start);
  10910. do {
  10911. for (i = 0; i < genTimes; i++) {
  10912. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10913. sizeof(id), ssk, pvt);
  10914. if (ret != 0) {
  10915. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10916. goto exit;
  10917. }
  10918. RECORD_MULTI_VALUE_STATS();
  10919. }
  10920. count += i;
  10921. } while (bench_stats_check(start)
  10922. #ifdef MULTI_VALUE_STATISTICS
  10923. || runs < minimum_runs
  10924. #endif
  10925. );
  10926. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10927. #ifdef MULTI_VALUE_STATISTICS
  10928. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10929. #endif
  10930. wc_FreeEccsiKey(genKey);
  10931. wc_ecc_del_point(pvt);
  10932. mp_free(ssk);
  10933. exit:
  10934. WC_FREE_VAR(genKey, HEAP_HINT);
  10935. WC_FREE_VAR(ssk, HEAP_HINT);
  10936. }
  10937. #endif
  10938. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10939. void bench_eccsiValidate(void)
  10940. {
  10941. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10942. double start;
  10943. int i, count;
  10944. const char**desc = bench_desc_words[lng_index];
  10945. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10946. ecc_point* pvt;
  10947. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10948. int valid;
  10949. int ret;
  10950. DECLARE_MULTI_VALUE_STATS_VARS()
  10951. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10952. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10953. (void)mp_init(ssk);
  10954. pvt = wc_ecc_new_point();
  10955. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10956. (void)wc_MakeEccsiKey(genKey, &gRng);
  10957. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10958. ssk, pvt);
  10959. /* Validation of RSK */
  10960. bench_stats_start(&count, &start);
  10961. do {
  10962. for (i = 0; i < genTimes; i++) {
  10963. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10964. sizeof(id), ssk, pvt, &valid);
  10965. if (ret != 0 || !valid) {
  10966. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10967. valid);
  10968. goto exit;
  10969. }
  10970. RECORD_MULTI_VALUE_STATS();
  10971. }
  10972. count += i;
  10973. } while (bench_stats_check(start)
  10974. #ifdef MULTI_VALUE_STATISTICS
  10975. || runs < minimum_runs
  10976. #endif
  10977. );
  10978. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10979. #ifdef MULTI_VALUE_STATISTICS
  10980. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10981. #endif
  10982. wc_FreeEccsiKey(genKey);
  10983. wc_ecc_del_point(pvt);
  10984. mp_free(ssk);
  10985. exit:
  10986. WC_FREE_VAR(genKey, HEAP_HINT);
  10987. WC_FREE_VAR(ssk, HEAP_HINT);
  10988. }
  10989. void bench_eccsi(void)
  10990. {
  10991. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10992. double start;
  10993. int i, count;
  10994. const char**desc = bench_desc_words[lng_index];
  10995. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10996. ecc_point* pvt;
  10997. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10998. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  10999. byte hash[WC_SHA256_DIGEST_SIZE];
  11000. byte hashSz = (byte)sizeof(hash);
  11001. byte sig[257];
  11002. word32 sigSz = sizeof(sig);
  11003. int ret;
  11004. int verified;
  11005. DECLARE_MULTI_VALUE_STATS_VARS()
  11006. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11007. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11008. (void)mp_init(ssk);
  11009. pvt = wc_ecc_new_point();
  11010. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11011. (void)wc_MakeEccsiKey(genKey, &gRng);
  11012. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11013. ssk, pvt);
  11014. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  11015. hash, &hashSz);
  11016. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  11017. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  11018. /* Encapsulate */
  11019. bench_stats_start(&count, &start);
  11020. do {
  11021. for (i = 0; i < genTimes; i++) {
  11022. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  11023. sizeof(msg), sig, &sigSz);
  11024. if (ret != 0) {
  11025. printf("wc_SignEccsiHash failed: %d\n", ret);
  11026. break;
  11027. }
  11028. RECORD_MULTI_VALUE_STATS();
  11029. }
  11030. count += i;
  11031. } while (bench_stats_check(start)
  11032. #ifdef MULTI_VALUE_STATISTICS
  11033. || runs < minimum_runs
  11034. #endif
  11035. );
  11036. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  11037. #ifdef MULTI_VALUE_STATISTICS
  11038. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11039. #endif
  11040. RESET_MULTI_VALUE_STATS_VARS();
  11041. /* Derive */
  11042. bench_stats_start(&count, &start);
  11043. do {
  11044. for (i = 0; i < genTimes; i++) {
  11045. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  11046. sizeof(msg), sig, sigSz, &verified);
  11047. if (ret != 0 || !verified) {
  11048. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  11049. verified);
  11050. goto exit;
  11051. }
  11052. RECORD_MULTI_VALUE_STATS();
  11053. }
  11054. count += i;
  11055. } while (bench_stats_check(start)
  11056. #ifdef MULTI_VALUE_STATISTICS
  11057. || runs < minimum_runs
  11058. #endif
  11059. );
  11060. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  11061. #ifdef MULTI_VALUE_STATISTICS
  11062. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11063. #endif
  11064. wc_FreeEccsiKey(genKey);
  11065. wc_ecc_del_point(pvt);
  11066. exit:
  11067. WC_FREE_VAR(genKey, HEAP_HINT);
  11068. WC_FREE_VAR(ssk, HEAP_HINT);
  11069. }
  11070. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  11071. #endif /* WOLFCRYPT_HAVE_ECCSI */
  11072. #ifdef WOLFCRYPT_HAVE_SAKKE
  11073. #ifdef WOLFCRYPT_SAKKE_KMS
  11074. void bench_sakkeKeyGen(void)
  11075. {
  11076. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11077. double start;
  11078. int i, count;
  11079. const char**desc = bench_desc_words[lng_index];
  11080. int ret;
  11081. DECLARE_MULTI_VALUE_STATS_VARS()
  11082. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11083. /* Key Gen */
  11084. bench_stats_start(&count, &start);
  11085. do {
  11086. for (i = 0; i < genTimes; i++) {
  11087. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11088. ret = wc_MakeSakkeKey(genKey, &gRng);
  11089. if (ret != 0) {
  11090. printf("wc_MakeSakkeKey failed: %d\n", ret);
  11091. goto exit;
  11092. }
  11093. wc_FreeSakkeKey(genKey);
  11094. RECORD_MULTI_VALUE_STATS();
  11095. }
  11096. count += i;
  11097. } while (bench_stats_check(start)
  11098. #ifdef MULTI_VALUE_STATISTICS
  11099. || runs < minimum_runs
  11100. #endif
  11101. );
  11102. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  11103. #ifdef MULTI_VALUE_STATISTICS
  11104. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11105. #endif
  11106. exit:
  11107. WC_FREE_VAR(genKey, HEAP_HINT);
  11108. }
  11109. void bench_sakkeRskGen(void)
  11110. {
  11111. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11112. double start;
  11113. int i, count;
  11114. const char**desc = bench_desc_words[lng_index];
  11115. ecc_point* rsk;
  11116. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11117. int ret;
  11118. DECLARE_MULTI_VALUE_STATS_VARS()
  11119. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11120. rsk = wc_ecc_new_point();
  11121. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11122. (void)wc_MakeSakkeKey(genKey, &gRng);
  11123. /* RSK Gen */
  11124. bench_stats_start(&count, &start);
  11125. do {
  11126. for (i = 0; i < genTimes; i++) {
  11127. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11128. if (ret != 0) {
  11129. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11130. goto exit;
  11131. }
  11132. RECORD_MULTI_VALUE_STATS();
  11133. }
  11134. count += i;
  11135. } while (bench_stats_check(start)
  11136. #ifdef MULTI_VALUE_STATISTICS
  11137. || runs < minimum_runs
  11138. #endif
  11139. );
  11140. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11141. #ifdef MULTI_VALUE_STATISTICS
  11142. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11143. #endif
  11144. wc_FreeSakkeKey(genKey);
  11145. wc_ecc_del_point(rsk);
  11146. exit:
  11147. WC_FREE_VAR(genKey, HEAP_HINT);
  11148. }
  11149. #endif
  11150. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11151. void bench_sakkeValidate(void)
  11152. {
  11153. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11154. double start;
  11155. int i, count;
  11156. const char**desc = bench_desc_words[lng_index];
  11157. ecc_point* rsk;
  11158. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11159. int valid;
  11160. int ret;
  11161. DECLARE_MULTI_VALUE_STATS_VARS()
  11162. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11163. rsk = wc_ecc_new_point();
  11164. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11165. (void)wc_MakeSakkeKey(genKey, &gRng);
  11166. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11167. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11168. /* Validation of RSK */
  11169. bench_stats_start(&count, &start);
  11170. do {
  11171. for (i = 0; i < genTimes; i++) {
  11172. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11173. if (ret != 0 || !valid) {
  11174. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11175. valid);
  11176. goto exit;
  11177. }
  11178. RECORD_MULTI_VALUE_STATS();
  11179. }
  11180. count += i;
  11181. } while (bench_stats_check(start)
  11182. #ifdef MULTI_VALUE_STATISTICS
  11183. || runs < minimum_runs
  11184. #endif
  11185. );
  11186. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11187. #ifdef MULTI_VALUE_STATISTICS
  11188. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11189. #endif
  11190. wc_FreeSakkeKey(genKey);
  11191. wc_ecc_del_point(rsk);
  11192. exit:
  11193. WC_FREE_VAR(genKey, HEAP_HINT);
  11194. }
  11195. void bench_sakke(void)
  11196. {
  11197. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11198. double start;
  11199. int i, count;
  11200. const char**desc = bench_desc_words[lng_index];
  11201. ecc_point* rsk;
  11202. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11203. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11204. byte ssv[sizeof(ssv_init)];
  11205. byte derSSV[sizeof(ssv)];
  11206. byte auth[257];
  11207. word16 authSz = sizeof(auth);
  11208. int ret = 0;
  11209. byte* table = NULL;
  11210. word32 len = 0;
  11211. byte* iTable = NULL;
  11212. word32 iTableLen = 0;
  11213. DECLARE_MULTI_VALUE_STATS_VARS()
  11214. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11215. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11216. rsk = wc_ecc_new_point();
  11217. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11218. (void)wc_MakeSakkeKey(genKey, &gRng);
  11219. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11220. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11221. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11222. /* Encapsulate */
  11223. bench_stats_start(&count, &start);
  11224. do {
  11225. for (i = 0; i < genTimes; i++) {
  11226. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11227. WC_HASH_TYPE_SHA256,
  11228. ssv, sizeof(ssv), auth, &authSz);
  11229. if (ret != 0) {
  11230. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11231. break;
  11232. }
  11233. RECORD_MULTI_VALUE_STATS();
  11234. } /* for */
  11235. count += i;
  11236. } while (bench_stats_check(start)
  11237. #ifdef MULTI_VALUE_STATISTICS
  11238. || runs < minimum_runs
  11239. #endif
  11240. );
  11241. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11242. 0, count, start, 0);
  11243. #ifdef MULTI_VALUE_STATISTICS
  11244. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11245. #endif
  11246. RESET_MULTI_VALUE_STATS_VARS();
  11247. /* Derive */
  11248. bench_stats_start(&count, &start);
  11249. do {
  11250. for (i = 0; i < genTimes; i++) {
  11251. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11252. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11253. sizeof(derSSV), auth, authSz);
  11254. if (ret != 0) {
  11255. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11256. break;
  11257. }
  11258. RECORD_MULTI_VALUE_STATS();
  11259. }
  11260. if (ret != 0) break;
  11261. count += i;
  11262. } while (bench_stats_check(start)
  11263. #ifdef MULTI_VALUE_STATISTICS
  11264. || runs < minimum_runs
  11265. #endif
  11266. );
  11267. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11268. 0, count, start, 0);
  11269. #ifdef MULTI_VALUE_STATISTICS
  11270. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11271. #endif
  11272. /* Calculate Point I and generate table. */
  11273. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11274. iTableLen = 0;
  11275. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11276. if (iTableLen != 0) {
  11277. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11278. if (iTable == NULL)
  11279. WC_ALLOC_DO_ON_FAILURE();
  11280. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11281. }
  11282. /* Encapsulate with Point I table */
  11283. bench_stats_start(&count, &start);
  11284. do {
  11285. for (i = 0; i < genTimes; i++) {
  11286. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11287. WC_HASH_TYPE_SHA256, ssv,
  11288. sizeof(ssv), auth, &authSz);
  11289. if (ret != 0) {
  11290. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11291. break;
  11292. }
  11293. RECORD_MULTI_VALUE_STATS();
  11294. }
  11295. count += i;
  11296. } while (bench_stats_check(start)
  11297. #ifdef MULTI_VALUE_STATISTICS
  11298. || runs < minimum_runs
  11299. #endif
  11300. );
  11301. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11302. count, start, 0);
  11303. #ifdef MULTI_VALUE_STATISTICS
  11304. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11305. #endif
  11306. RESET_MULTI_VALUE_STATS_VARS();
  11307. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11308. /* Derive with Point I table */
  11309. bench_stats_start(&count, &start);
  11310. do {
  11311. for (i = 0; i < genTimes; i++) {
  11312. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11313. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11314. sizeof(derSSV), auth, authSz);
  11315. if (ret != 0) {
  11316. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11317. break;
  11318. }
  11319. RECORD_MULTI_VALUE_STATS();
  11320. }
  11321. if (ret != 0) break;
  11322. count += i;
  11323. } while (bench_stats_check(start)
  11324. #ifdef MULTI_VALUE_STATISTICS
  11325. || runs < minimum_runs
  11326. #endif
  11327. );
  11328. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11329. count, start, 0);
  11330. #ifdef MULTI_VALUE_STATISTICS
  11331. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11332. #endif
  11333. RESET_MULTI_VALUE_STATS_VARS();
  11334. len = 0;
  11335. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11336. if (len > 0) {
  11337. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11338. if (table == NULL)
  11339. WC_ALLOC_DO_ON_FAILURE();
  11340. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11341. }
  11342. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11343. /* Derive with Point I table and RSK table */
  11344. bench_stats_start(&count, &start);
  11345. do {
  11346. for (i = 0; i < genTimes; i++) {
  11347. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11348. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11349. sizeof(derSSV), auth, authSz);
  11350. if (ret != 0) {
  11351. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11352. break;
  11353. }
  11354. RECORD_MULTI_VALUE_STATS();
  11355. }
  11356. if (ret != 0) break;
  11357. count += i;
  11358. } while (bench_stats_check(start)
  11359. #ifdef MULTI_VALUE_STATISTICS
  11360. || runs < minimum_runs
  11361. #endif
  11362. );
  11363. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11364. 0, count, start, 0);
  11365. #ifdef MULTI_VALUE_STATISTICS
  11366. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11367. #endif
  11368. RESET_MULTI_VALUE_STATS_VARS();
  11369. wc_ClearSakkePointITable(genKey);
  11370. /* Derive with RSK table */
  11371. bench_stats_start(&count, &start);
  11372. do {
  11373. for (i = 0; i < genTimes; i++) {
  11374. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11375. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11376. sizeof(derSSV), auth, authSz);
  11377. if (ret != 0) {
  11378. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11379. break;
  11380. }
  11381. RECORD_MULTI_VALUE_STATS();
  11382. }
  11383. if (ret != 0) break;
  11384. count += i;
  11385. } while (bench_stats_check(start)
  11386. #ifdef MULTI_VALUE_STATISTICS
  11387. || runs < minimum_runs
  11388. #endif
  11389. );
  11390. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11391. count, start, 0);
  11392. #ifdef MULTI_VALUE_STATISTICS
  11393. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11394. #endif
  11395. wc_FreeSakkeKey(genKey);
  11396. wc_ecc_del_point(rsk);
  11397. exit:
  11398. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11399. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11400. WC_FREE_VAR(genKey, HEAP_HINT);
  11401. }
  11402. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11403. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11404. #ifdef HAVE_FALCON
  11405. void bench_falconKeySign(byte level)
  11406. {
  11407. int ret = 0;
  11408. falcon_key key;
  11409. double start;
  11410. int i, count;
  11411. byte sig[FALCON_MAX_SIG_SIZE];
  11412. byte msg[512];
  11413. word32 x = 0;
  11414. const char**desc = bench_desc_words[lng_index];
  11415. DECLARE_MULTI_VALUE_STATS_VARS()
  11416. ret = wc_falcon_init(&key);
  11417. if (ret != 0) {
  11418. printf("wc_falcon_init failed %d\n", ret);
  11419. return;
  11420. }
  11421. ret = wc_falcon_set_level(&key, level);
  11422. if (ret != 0) {
  11423. printf("wc_falcon_set_level failed %d\n", ret);
  11424. }
  11425. if (ret == 0) {
  11426. if (level == 1) {
  11427. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11428. sizeof_bench_falcon_level1_key,
  11429. NULL, 0, &key);
  11430. }
  11431. else {
  11432. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11433. sizeof_bench_falcon_level5_key,
  11434. NULL, 0, &key);
  11435. }
  11436. if (ret != 0) {
  11437. printf("wc_falcon_import_private_key failed %d\n", ret);
  11438. }
  11439. }
  11440. /* make dummy msg */
  11441. for (i = 0; i < (int)sizeof(msg); i++) {
  11442. msg[i] = (byte)i;
  11443. }
  11444. bench_stats_start(&count, &start);
  11445. do {
  11446. for (i = 0; i < agreeTimes; i++) {
  11447. if (ret == 0) {
  11448. if (level == 1) {
  11449. x = FALCON_LEVEL1_SIG_SIZE;
  11450. }
  11451. else {
  11452. x = FALCON_LEVEL5_SIG_SIZE;
  11453. }
  11454. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11455. if (ret != 0) {
  11456. printf("wc_falcon_sign_msg failed\n");
  11457. }
  11458. }
  11459. RECORD_MULTI_VALUE_STATS();
  11460. }
  11461. count += i;
  11462. } while (bench_stats_check(start)
  11463. #ifdef MULTI_VALUE_STATISTICS
  11464. || runs < minimum_runs
  11465. #endif
  11466. );
  11467. if (ret == 0) {
  11468. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11469. count, start, ret);
  11470. #ifdef MULTI_VALUE_STATISTICS
  11471. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11472. #endif
  11473. }
  11474. RESET_MULTI_VALUE_STATS_VARS();
  11475. bench_stats_start(&count, &start);
  11476. do {
  11477. for (i = 0; i < agreeTimes; i++) {
  11478. if (ret == 0) {
  11479. int verify = 0;
  11480. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11481. &key);
  11482. if (ret != 0 || verify != 1) {
  11483. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11484. ret, verify);
  11485. ret = -1;
  11486. }
  11487. }
  11488. RECORD_MULTI_VALUE_STATS();
  11489. }
  11490. count += i;
  11491. } while (bench_stats_check(start)
  11492. #ifdef MULTI_VALUE_STATISTICS
  11493. || runs < minimum_runs
  11494. #endif
  11495. );
  11496. if (ret == 0) {
  11497. bench_stats_asym_finish("FALCON", level, desc[5],
  11498. 0, count, start, ret);
  11499. #ifdef MULTI_VALUE_STATISTICS
  11500. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11501. #endif
  11502. }
  11503. wc_falcon_free(&key);
  11504. }
  11505. #endif /* HAVE_FALCON */
  11506. #ifdef HAVE_DILITHIUM
  11507. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11508. #ifndef WOLFSSL_NO_ML_DSA_44
  11509. static const unsigned char bench_dilithium_level2_sig[] = {
  11510. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11511. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11512. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11513. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11514. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11515. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11516. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11517. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11518. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11519. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11520. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11521. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11522. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11523. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11524. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11525. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11526. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11527. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11528. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11529. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11530. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11531. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11532. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11533. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11534. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11535. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11536. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11537. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11538. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11539. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11540. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11541. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11542. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11543. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11544. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11545. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11546. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11547. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11548. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11549. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11550. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11551. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11552. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11553. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11554. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11555. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11556. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11557. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11558. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11559. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11560. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11561. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11562. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11563. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11564. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11565. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11566. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11567. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11568. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11569. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11570. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11571. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11572. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11573. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11574. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11575. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11576. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11577. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11578. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11579. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11580. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11581. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11582. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11583. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11584. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11585. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11586. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11587. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11588. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11589. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11590. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11591. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11592. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11593. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11594. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11595. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11596. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11597. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11598. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11599. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11600. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11601. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11602. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11603. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11604. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11605. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11606. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11607. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11608. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11609. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11610. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11611. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11612. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11613. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11614. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11615. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11616. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11617. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11618. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11619. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11620. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11621. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11622. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11623. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11624. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11625. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11626. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11627. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11628. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11629. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11630. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11631. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11632. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11633. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11634. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11635. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11636. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11637. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11638. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11639. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11640. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11641. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11642. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11643. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11644. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11645. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11646. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11647. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11648. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11649. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11650. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11651. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11652. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11653. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11654. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11655. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11656. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11657. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11658. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11659. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11660. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11661. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11662. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11663. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11664. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11665. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11666. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11667. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11668. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11669. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11670. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11671. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11672. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11673. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11674. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11675. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11676. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11677. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11678. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11679. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11680. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11681. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11682. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11683. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11684. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11685. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11686. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11687. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11688. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11689. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11690. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11691. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11692. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11693. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11694. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11695. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11696. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11697. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11698. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11699. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11700. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11701. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11702. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11703. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11704. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11705. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11706. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11707. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11708. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11709. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11710. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11711. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11712. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11713. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11714. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11715. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11716. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11717. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11718. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11719. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11720. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11721. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11722. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11723. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11724. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11725. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11726. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11727. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11728. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11729. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11730. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11731. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11732. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11733. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11734. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11735. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11736. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11737. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11738. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11739. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11740. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11741. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11742. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11743. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11744. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11745. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11746. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11747. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11748. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11749. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11750. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11751. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11752. };
  11753. static const int sizeof_bench_dilithium_level2_sig =
  11754. sizeof(bench_dilithium_level2_sig);
  11755. #endif
  11756. #ifndef WOLFSSL_NO_ML_DSA_65
  11757. static const unsigned char bench_dilithium_level3_sig[] = {
  11758. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11759. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11760. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11761. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11762. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11763. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11764. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11765. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11766. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11767. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11768. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11769. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11770. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11771. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11772. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11773. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11774. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11775. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11776. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11777. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11778. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11779. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11780. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11781. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11782. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11783. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11784. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11785. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11786. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11787. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11788. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11789. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11790. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11791. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11792. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11793. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11794. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11795. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11796. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11797. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11798. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11799. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11800. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11801. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11802. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11803. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11804. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11805. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11806. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11807. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11808. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11809. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11810. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11811. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11812. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11813. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11814. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11815. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11816. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11817. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11818. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11819. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11820. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11821. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11822. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11823. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11824. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11825. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11826. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11827. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11828. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11829. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11830. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11831. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11832. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11833. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11834. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11835. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11836. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11837. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11838. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11839. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11840. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11841. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11842. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11843. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11844. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11845. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11846. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11847. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11848. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11849. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11850. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11851. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11852. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11853. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11854. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11855. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11856. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11857. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11858. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11859. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11860. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11861. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11862. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11863. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11864. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11865. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11866. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11867. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11868. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11869. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11870. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11871. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11872. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11873. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11874. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11875. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11876. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11877. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11878. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11879. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11880. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11881. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11882. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11883. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11884. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11885. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11886. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11887. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11888. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11889. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11890. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11891. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11892. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11893. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11894. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11895. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11896. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11897. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11898. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11899. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11900. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11901. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11902. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11903. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11904. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11905. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11906. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11907. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11908. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11909. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11910. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11911. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11912. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11913. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11914. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11915. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11916. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11917. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11918. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11919. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11920. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11921. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11922. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11923. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11924. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11925. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11926. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11927. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11928. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11929. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11930. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11931. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11932. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11933. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11934. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11935. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11936. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11937. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11938. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11939. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11940. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11941. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11942. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11943. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11944. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11945. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11946. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11947. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11948. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11949. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11950. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11951. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11952. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11953. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11954. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11955. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11956. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11957. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11958. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11959. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11960. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11961. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11962. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11963. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11964. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11965. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11966. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11967. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11968. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11969. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11970. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11971. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11972. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11973. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11974. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11975. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11976. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11977. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11978. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11979. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11980. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11981. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11982. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  11983. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  11984. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  11985. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  11986. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  11987. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  11988. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  11989. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  11990. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  11991. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  11992. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  11993. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  11994. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  11995. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  11996. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  11997. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  11998. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  11999. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  12000. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  12001. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  12002. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  12003. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  12004. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  12005. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  12006. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  12007. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  12008. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  12009. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  12010. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  12011. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  12012. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  12013. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  12014. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  12015. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  12016. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  12017. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  12018. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  12019. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  12020. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  12021. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  12022. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  12023. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  12024. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  12025. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  12026. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  12027. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  12028. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  12029. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  12030. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  12031. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  12032. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  12033. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  12034. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  12035. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  12036. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  12037. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  12038. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  12039. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  12040. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  12041. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  12042. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  12043. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  12044. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  12045. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  12046. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  12047. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  12048. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  12049. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  12050. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  12051. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  12052. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  12053. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  12054. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  12055. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  12056. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  12057. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  12058. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  12059. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  12060. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  12061. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  12062. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  12063. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  12064. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  12065. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  12066. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  12067. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  12068. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  12069. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  12070. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  12071. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  12072. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  12073. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  12074. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  12075. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  12076. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  12077. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  12078. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  12079. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  12080. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  12081. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  12082. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  12083. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  12084. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  12085. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  12086. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  12087. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12088. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  12089. };
  12090. static const int sizeof_bench_dilithium_level3_sig =
  12091. sizeof(bench_dilithium_level3_sig);
  12092. #endif
  12093. #ifndef WOLFSSL_NO_ML_DSA_87
  12094. static const unsigned char bench_dilithium_level5_sig[] = {
  12095. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  12096. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  12097. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  12098. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  12099. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  12100. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  12101. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  12102. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  12103. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  12104. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  12105. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  12106. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  12107. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  12108. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  12109. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  12110. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  12111. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  12112. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  12113. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  12114. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  12115. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12116. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12117. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12118. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12119. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12120. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12121. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12122. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12123. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12124. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12125. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12126. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12127. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12128. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12129. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12130. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12131. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12132. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12133. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12134. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12135. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12136. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12137. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12138. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12139. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12140. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12141. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12142. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12143. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12144. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12145. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12146. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12147. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12148. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12149. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12150. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12151. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12152. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12153. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12154. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12155. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12156. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12157. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12158. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12159. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12160. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12161. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12162. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12163. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12164. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12165. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12166. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12167. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12168. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12169. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12170. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12171. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12172. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12173. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12174. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12175. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12176. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12177. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12178. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12179. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12180. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12181. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12182. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12183. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12184. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12185. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12186. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12187. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12188. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12189. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12190. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12191. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12192. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12193. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12194. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12195. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12196. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12197. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12198. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12199. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12200. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12201. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12202. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12203. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12204. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12205. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12206. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12207. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12208. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12209. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12210. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12211. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12212. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12213. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12214. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12215. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12216. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12217. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12218. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12219. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12220. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12221. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12222. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12223. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12224. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12225. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12226. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12227. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12228. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12229. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12230. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12231. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12232. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12233. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12234. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12235. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12236. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12237. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12238. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12239. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12240. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12241. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12242. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12243. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12244. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12245. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12246. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12247. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12248. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12249. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12250. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12251. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12252. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12253. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12254. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12255. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12256. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12257. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12258. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12259. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12260. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12261. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12262. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12263. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12264. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12265. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12266. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12267. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12268. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12269. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12270. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12271. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12272. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12273. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12274. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12275. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12276. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12277. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12278. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12279. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12280. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12281. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12282. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12283. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12284. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12285. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12286. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12287. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12288. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12289. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12290. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12291. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12292. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12293. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12294. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12295. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12296. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12297. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12298. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12299. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12300. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12301. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12302. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12303. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12304. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12305. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12306. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12307. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12308. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12309. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12310. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12311. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12312. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12313. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12314. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12315. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12316. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12317. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12318. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12319. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12320. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12321. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12322. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12323. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12324. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12325. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12326. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12327. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12328. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12329. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12330. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12331. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12332. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12333. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12334. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12335. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12336. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12337. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12338. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12339. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12340. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12341. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12342. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12343. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12344. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12345. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12346. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12347. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12348. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12349. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12350. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12351. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12352. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12353. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12354. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12355. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12356. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12357. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12358. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12359. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12360. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12361. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12362. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12363. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12364. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12365. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12366. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12367. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12368. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12369. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12370. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12371. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12372. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12373. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12374. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12375. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12376. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12377. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12378. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12379. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12380. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12381. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12382. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12383. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12384. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12385. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12386. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12387. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12388. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12389. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12390. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12391. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12392. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12393. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12394. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12395. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12396. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12397. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12398. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12399. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12400. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12401. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12402. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12403. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12404. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12405. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12406. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12407. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12408. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12409. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12410. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12411. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12412. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12413. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12414. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12415. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12416. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12417. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12418. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12419. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12420. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12421. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12422. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12423. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12424. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12425. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12426. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12427. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12428. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12429. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12430. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12431. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12432. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12433. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12434. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12435. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12436. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12437. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12438. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12439. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12440. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12441. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12442. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12443. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12444. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12445. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12446. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12447. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12448. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12449. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12450. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12451. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12452. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12453. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12454. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12455. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12456. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12457. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12458. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12459. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12460. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12461. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12462. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12463. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12464. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12465. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12466. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12467. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12468. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12469. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12470. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12471. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12472. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12473. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12474. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12475. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12476. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12477. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12478. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12479. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12480. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12481. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12482. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12483. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12484. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12485. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12486. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12487. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12488. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12489. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12490. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12491. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12492. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12493. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12494. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12495. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12496. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12497. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12498. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12499. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12500. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12501. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12502. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12503. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12504. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12505. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12506. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12507. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12508. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12509. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12510. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12511. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12512. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12513. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12514. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12515. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12516. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12517. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12518. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12519. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12520. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12521. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12522. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12523. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12524. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12525. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12526. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12527. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12528. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12529. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12530. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12531. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12532. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12533. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12534. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12535. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12536. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12537. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12538. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12539. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12540. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12541. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12542. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12543. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12544. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12545. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12546. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12547. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12548. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12549. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12550. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12551. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12552. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12553. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12554. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12555. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12556. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12557. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12558. };
  12559. static const int sizeof_bench_dilithium_level5_sig =
  12560. sizeof(bench_dilithium_level5_sig);
  12561. #endif
  12562. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12563. void bench_dilithiumKeySign(byte level)
  12564. {
  12565. int ret = 0;
  12566. dilithium_key key;
  12567. double start;
  12568. int i, count;
  12569. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12570. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12571. byte msg[512];
  12572. word32 x = 0;
  12573. #endif
  12574. const char**desc = bench_desc_words[lng_index];
  12575. DECLARE_MULTI_VALUE_STATS_VARS()
  12576. byte params = 0;
  12577. if (level == 2) {
  12578. params = 44;
  12579. }
  12580. else if (level == 3) {
  12581. params = 65;
  12582. }
  12583. else if (level == 5) {
  12584. params = 87;
  12585. }
  12586. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12587. /* make dummy msg */
  12588. for (i = 0; i < (int)sizeof(msg); i++) {
  12589. msg[i] = (byte)i;
  12590. }
  12591. #endif
  12592. ret = wc_dilithium_init(&key);
  12593. if (ret != 0) {
  12594. printf("wc_dilithium_init failed %d\n", ret);
  12595. return;
  12596. }
  12597. ret = wc_dilithium_set_level(&key, level);
  12598. if (ret != 0) {
  12599. printf("wc_dilithium_set_level() failed %d\n", ret);
  12600. }
  12601. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12602. bench_stats_start(&count, &start);
  12603. do {
  12604. for (i = 0; i < agreeTimes; i++) {
  12605. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12606. if (ret != 0) {
  12607. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12608. return;
  12609. }
  12610. }
  12611. count += i;
  12612. } while (bench_stats_check(start)
  12613. #ifdef MULTI_VALUE_STATISTICS
  12614. || runs < minimum_runs
  12615. #endif
  12616. );
  12617. if (ret == 0) {
  12618. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12619. start, ret);
  12620. #ifdef MULTI_VALUE_STATISTICS
  12621. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12622. #endif
  12623. }
  12624. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12625. #ifndef WOLFSSL_NO_ML_DSA_44
  12626. if (level == 2) {
  12627. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12628. sizeof_bench_dilithium_level2_key, &key);
  12629. }
  12630. #endif
  12631. #ifndef WOLFSSL_NO_ML_DSA_65
  12632. if (level == 3) {
  12633. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12634. sizeof_bench_dilithium_level3_key, &key);
  12635. }
  12636. #endif
  12637. #ifndef WOLFSSL_NO_ML_DSA_87
  12638. if (level == 5) {
  12639. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12640. sizeof_bench_dilithium_level5_key, &key);
  12641. }
  12642. #endif
  12643. if (ret != 0) {
  12644. printf("Failed to load private key\n");
  12645. return;
  12646. }
  12647. #endif
  12648. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12649. if (level == 2) {
  12650. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12651. }
  12652. else if (level == 3) {
  12653. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12654. }
  12655. else {
  12656. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12657. }
  12658. RESET_MULTI_VALUE_STATS_VARS();
  12659. bench_stats_start(&count, &start);
  12660. do {
  12661. for (i = 0; i < agreeTimes; i++) {
  12662. if (ret == 0) {
  12663. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12664. GLOBAL_RNG);
  12665. if (ret != 0) {
  12666. printf("wc_dilithium_sign_msg failed\n");
  12667. }
  12668. }
  12669. RECORD_MULTI_VALUE_STATS();
  12670. }
  12671. count += i;
  12672. } while (bench_stats_check(start)
  12673. #ifdef MULTI_VALUE_STATISTICS
  12674. || runs < minimum_runs
  12675. #endif
  12676. );
  12677. if (ret == 0) {
  12678. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12679. ret);
  12680. #ifdef MULTI_VALUE_STATISTICS
  12681. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12682. #endif
  12683. }
  12684. #endif
  12685. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12686. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12687. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12688. #ifndef WOLFSSL_NO_ML_DSA_44
  12689. if (level == 2) {
  12690. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12691. x = sizeof_bench_dilithium_level2_sig;
  12692. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12693. #endif
  12694. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12695. sizeof_bench_dilithium_level2_pubkey, &key);
  12696. }
  12697. #endif
  12698. #ifndef WOLFSSL_NO_ML_DSA_65
  12699. if (level == 3) {
  12700. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12701. x = sizeof_bench_dilithium_level3_sig;
  12702. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12703. #endif
  12704. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12705. sizeof_bench_dilithium_level3_pubkey, &key);
  12706. }
  12707. #endif
  12708. #ifndef WOLFSSL_NO_ML_DSA_87
  12709. if (level == 5) {
  12710. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12711. x = sizeof_bench_dilithium_level5_sig;
  12712. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12713. #endif
  12714. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12715. sizeof_bench_dilithium_level5_pubkey, &key);
  12716. }
  12717. #endif
  12718. if (ret != 0) {
  12719. printf("Failed to load public key\n");
  12720. return;
  12721. }
  12722. #endif
  12723. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12724. RESET_MULTI_VALUE_STATS_VARS();
  12725. bench_stats_start(&count, &start);
  12726. do {
  12727. for (i = 0; i < agreeTimes; i++) {
  12728. if (ret == 0) {
  12729. int verify = 0;
  12730. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12731. &verify, &key);
  12732. if (ret != 0 || verify != 1) {
  12733. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12734. ret, verify);
  12735. ret = -1;
  12736. }
  12737. }
  12738. RECORD_MULTI_VALUE_STATS();
  12739. }
  12740. count += i;
  12741. } while (bench_stats_check(start)
  12742. #ifdef MULTI_VALUE_STATISTICS
  12743. || runs < minimum_runs
  12744. #endif
  12745. );
  12746. if (ret == 0) {
  12747. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12748. ret);
  12749. #ifdef MULTI_VALUE_STATISTICS
  12750. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12751. #endif
  12752. }
  12753. #endif
  12754. wc_dilithium_free(&key);
  12755. }
  12756. #endif /* HAVE_DILITHIUM */
  12757. #ifdef HAVE_SPHINCS
  12758. void bench_sphincsKeySign(byte level, byte optim)
  12759. {
  12760. int ret = 0;
  12761. sphincs_key key;
  12762. double start;
  12763. int i, count;
  12764. byte sig[SPHINCS_MAX_SIG_SIZE];
  12765. byte msg[512];
  12766. word32 x = 0;
  12767. const char**desc = bench_desc_words[lng_index];
  12768. DECLARE_MULTI_VALUE_STATS_VARS()
  12769. ret = wc_sphincs_init(&key);
  12770. if (ret != 0) {
  12771. printf("wc_sphincs_init failed %d\n", ret);
  12772. return;
  12773. }
  12774. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12775. if (ret != 0) {
  12776. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12777. }
  12778. if (ret == 0) {
  12779. ret = -1;
  12780. if ((level == 1) && (optim == FAST_VARIANT)) {
  12781. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12782. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12783. }
  12784. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12785. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12786. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12787. }
  12788. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12789. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12790. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12791. }
  12792. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12793. ret = wc_sphincs_import_private_key(
  12794. bench_sphincs_small_level1_key,
  12795. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12796. }
  12797. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12798. ret = wc_sphincs_import_private_key(
  12799. bench_sphincs_small_level3_key,
  12800. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12801. }
  12802. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12803. ret = wc_sphincs_import_private_key(
  12804. bench_sphincs_small_level5_key,
  12805. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12806. }
  12807. if (ret != 0) {
  12808. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12809. }
  12810. }
  12811. /* make dummy msg */
  12812. for (i = 0; i < (int)sizeof(msg); i++) {
  12813. msg[i] = (byte)i;
  12814. }
  12815. bench_stats_start(&count, &start);
  12816. do {
  12817. for (i = 0; i < agreeTimes; i++) {
  12818. if (ret == 0) {
  12819. if ((level == 1) && (optim == FAST_VARIANT)) {
  12820. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12821. }
  12822. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12823. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12824. }
  12825. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12826. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12827. }
  12828. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12829. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12830. }
  12831. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12832. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12833. }
  12834. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12835. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12836. }
  12837. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12838. if (ret != 0) {
  12839. printf("wc_sphincs_sign_msg failed\n");
  12840. }
  12841. }
  12842. RECORD_MULTI_VALUE_STATS();
  12843. }
  12844. count += i;
  12845. } while (bench_stats_check(start)
  12846. #ifdef MULTI_VALUE_STATISTICS
  12847. || runs < minimum_runs
  12848. #endif
  12849. );
  12850. if (ret == 0) {
  12851. if (optim == FAST_VARIANT) {
  12852. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12853. start, ret);
  12854. }
  12855. else {
  12856. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12857. start, ret);
  12858. }
  12859. #ifdef MULTI_VALUE_STATISTICS
  12860. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12861. #endif
  12862. }
  12863. RESET_MULTI_VALUE_STATS_VARS();
  12864. bench_stats_start(&count, &start);
  12865. do {
  12866. for (i = 0; i < agreeTimes; i++) {
  12867. if (ret == 0) {
  12868. int verify = 0;
  12869. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12870. &key);
  12871. if (ret != 0 || verify != 1) {
  12872. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12873. ret, verify);
  12874. ret = -1;
  12875. }
  12876. }
  12877. RECORD_MULTI_VALUE_STATS();
  12878. }
  12879. count += i;
  12880. } while (bench_stats_check(start)
  12881. #ifdef MULTI_VALUE_STATISTICS
  12882. || runs < minimum_runs
  12883. #endif
  12884. );
  12885. if (ret == 0) {
  12886. if (optim == FAST_VARIANT) {
  12887. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12888. start, ret);
  12889. }
  12890. else {
  12891. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12892. start, ret);
  12893. }
  12894. #ifdef MULTI_VALUE_STATISTICS
  12895. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12896. #endif
  12897. }
  12898. wc_sphincs_free(&key);
  12899. }
  12900. #endif /* HAVE_SPHINCS */
  12901. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12902. #define WIN32_LEAN_AND_MEAN
  12903. #include <windows.h>
  12904. double current_time(int reset)
  12905. {
  12906. static int init = 0;
  12907. static LARGE_INTEGER freq;
  12908. LARGE_INTEGER count;
  12909. (void)reset;
  12910. if (!init) {
  12911. QueryPerformanceFrequency(&freq);
  12912. init = 1;
  12913. }
  12914. QueryPerformanceCounter(&count);
  12915. #ifdef BENCH_MICROSECOND
  12916. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12917. #else
  12918. return (double)count.QuadPart / freq.QuadPart;
  12919. #endif
  12920. }
  12921. #elif defined MICROCHIP_PIC32
  12922. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12923. #define CLOCK 80000000.0
  12924. #else
  12925. #define CLOCK 40000000.0
  12926. #endif
  12927. extern void WriteCoreTimer(word32 t);
  12928. extern word32 ReadCoreTimer(void);
  12929. double current_time(int reset)
  12930. {
  12931. unsigned int ns;
  12932. if (reset) {
  12933. WriteCoreTimer(0);
  12934. }
  12935. /* get timer in ns */
  12936. ns = ReadCoreTimer();
  12937. /* return seconds as a double */
  12938. return ( ns / CLOCK * 2.0);
  12939. }
  12940. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12941. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12942. /* declared above at line 239 */
  12943. /* extern double current_time(int reset); */
  12944. #elif defined(FREERTOS)
  12945. #ifdef PLATFORMIO
  12946. #include <freertos/FreeRTOS.h>
  12947. #include <freertos/task.h>
  12948. #else
  12949. #include "task.h"
  12950. #endif
  12951. #if defined(WOLFSSL_ESPIDF)
  12952. /* prototype definition */
  12953. int construct_argv();
  12954. extern char* __argv[22];
  12955. /* current_time(reset)
  12956. *
  12957. * Benchmark passage of time, in fractional seconds.
  12958. * [reset] is non zero to adjust timer or counter to zero
  12959. *
  12960. * Use care when repeatedly calling calling. See implementation. */
  12961. double current_time(int reset)
  12962. {
  12963. double ret;
  12964. #if ESP_IDF_VERSION_MAJOR >= 4
  12965. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12966. #else
  12967. portTickType tickCount;
  12968. #endif
  12969. #if defined(__XTENSA__)
  12970. (void)reset;
  12971. if (reset) {
  12972. /* TODO: Determine a mechanism for reset that does not interfere
  12973. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12974. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12975. ESP_LOGW(TAG, "Current_time() reset!");
  12976. portTICK_TYPE_ENTER_CRITICAL();
  12977. {
  12978. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12979. _esp_cpu_count_last = xthal_get_ccount();
  12980. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12981. }
  12982. portTICK_TYPE_EXIT_CRITICAL();
  12983. */
  12984. }
  12985. #else
  12986. /* Only reset the CPU counter for RISC-V */
  12987. if (reset) {
  12988. ESP_LOGV(TAG, "current_time() reset!");
  12989. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  12990. * unexpected rollovers in return values for Xtensa but not RISC-V?
  12991. * See also esp_get_cycle_count_ex() */
  12992. #ifdef __XTENSA__
  12993. _esp_cpu_count_last = xthal_get_ccount();
  12994. #else
  12995. #if ESP_IDF_VERSION_MAJOR >= 5
  12996. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12997. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12998. #else
  12999. cpu_hal_set_cycle_count((uint32_t)0);
  13000. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  13001. #endif
  13002. #endif
  13003. }
  13004. #endif
  13005. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  13006. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  13007. The count of ticks since vTaskStartScheduler was called,
  13008. typiclly in app_startup.c */
  13009. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13010. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  13011. if (tickCount == last_tickCount) {
  13012. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  13013. }
  13014. if (tickCount < last_tickCount) {
  13015. ESP_LOGW(TAG, "last_tickCount overflow?");
  13016. }
  13017. #endif
  13018. if (reset) {
  13019. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13020. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  13021. #endif
  13022. last_tickCount = tickCount;
  13023. }
  13024. else {
  13025. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13026. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  13027. #endif
  13028. }
  13029. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  13030. ret = (double)tickCount / configTICK_RATE_HZ;
  13031. #else
  13032. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  13033. "assuming 1000 Hz.");
  13034. ret = (double)(tickCount / 1000.0);
  13035. #endif /* configTICK_RATE_HZ */
  13036. return ret;
  13037. } /* current_time */
  13038. #else
  13039. /* current_time(reset)
  13040. *
  13041. * Benchmark passage of time, in fractional seconds.
  13042. * [reset] is non zero to adjust timer or counter to zero
  13043. *
  13044. * Use care when repeatedly calling calling. See implementation. */
  13045. double current_time(int reset)
  13046. {
  13047. portTickType tickCount = xTaskGetTickCount();
  13048. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  13049. #ifdef configTICK_RATE_HZ
  13050. return (double)tickCount / configTICK_RATE_HZ;
  13051. #else
  13052. return (double)tickCount / 1000;
  13053. #endif
  13054. }
  13055. #endif
  13056. #elif defined (WOLFSSL_TIRTOS)
  13057. extern double current_time(int reset);
  13058. #elif defined(FREESCALE_MQX)
  13059. double current_time(int reset)
  13060. {
  13061. TIME_STRUCT tv;
  13062. _time_get(&tv);
  13063. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  13064. }
  13065. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  13066. && defined(MAX3266X_RTC)
  13067. double current_time(int reset)
  13068. {
  13069. (void)reset;
  13070. return wc_MXC_RTC_Time();
  13071. }
  13072. #elif defined(FREESCALE_KSDK_BM)
  13073. double current_time(int reset)
  13074. {
  13075. return (double)OSA_TimeGetMsec() / 1000;
  13076. }
  13077. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  13078. double current_time(int reset)
  13079. {
  13080. (void)reset;
  13081. return (double)osKernelGetTickCount() / 1000.0;
  13082. }
  13083. #elif defined(WOLFSSL_EMBOS)
  13084. #include "RTOS.h"
  13085. double current_time(int reset)
  13086. {
  13087. double time_now;
  13088. double current_s = OS_GetTime() / 1000.0;
  13089. double current_us = OS_GetTime_us() / MILLION_VALUE;
  13090. time_now = (double)( current_s + current_us);
  13091. (void) reset;
  13092. return time_now;
  13093. }
  13094. #elif defined(WOLFSSL_SGX)
  13095. double current_time(int reset);
  13096. #elif defined(WOLFSSL_DEOS)
  13097. double current_time(int reset)
  13098. {
  13099. const uint32_t systemTickTimeInHz
  13100. = 1000000 / systemTickInMicroseconds();
  13101. const volatile uint32_t *systemTickPtr = systemTickPointer();
  13102. (void)reset;
  13103. return (double) *systemTickPtr/systemTickTimeInHz;
  13104. }
  13105. #elif defined(MICRIUM)
  13106. double current_time(int reset)
  13107. {
  13108. #if (OS_VERSION < 50000)
  13109. CPU_ERR err;
  13110. (void)reset;
  13111. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  13112. #else
  13113. RTOS_ERR err;
  13114. double ret = 0;
  13115. OS_TICK tick = OSTimeGet(&err);
  13116. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13117. (void)reset;
  13118. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13119. ret = ((double)tick)/rate;
  13120. }
  13121. return ret;
  13122. #endif
  13123. }
  13124. #elif defined(WOLFSSL_ZEPHYR)
  13125. #include <time.h>
  13126. double current_time(int reset)
  13127. {
  13128. int64_t t;
  13129. (void)reset;
  13130. #if defined(CONFIG_ARCH_POSIX)
  13131. k_cpu_idle();
  13132. #endif
  13133. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13134. return (double)(t / 1000);
  13135. }
  13136. #elif defined(WOLFSSL_NETBURNER)
  13137. #include <predef.h>
  13138. #include <utils.h>
  13139. #include <constants.h>
  13140. double current_time(int reset)
  13141. {
  13142. DWORD ticks = TimeTick; /* ticks since system start */
  13143. (void)reset;
  13144. return (double) ticks/TICKS_PER_SECOND;
  13145. }
  13146. #elif defined(WOLFSSL_RPIPICO)
  13147. #include "pico/stdlib.h"
  13148. double current_time(int reset)
  13149. {
  13150. (void)reset;
  13151. return (double) time_us_64() / 1000000;
  13152. }
  13153. #elif defined(THREADX)
  13154. #include "tx_api.h"
  13155. double current_time(int reset)
  13156. {
  13157. (void)reset;
  13158. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13159. }
  13160. #elif defined(WOLFSSL_XILINX)
  13161. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13162. #define COUNTS_PER_SECOND \
  13163. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13164. #else
  13165. #define COUNTS_PER_SECOND \
  13166. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13167. #endif
  13168. double current_time(int reset)
  13169. {
  13170. double timer;
  13171. uint64_t cntPct = 0;
  13172. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13173. /* Convert to milliseconds */
  13174. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13175. /* Convert to seconds.millisecond */
  13176. timer /= 1000;
  13177. return timer;
  13178. }
  13179. #elif defined(LINUX_RUSAGE_UTIME)
  13180. #include <sys/time.h>
  13181. #include <sys/resource.h>
  13182. static struct rusage base_rusage;
  13183. static struct rusage cur_rusage;
  13184. double current_time(int reset)
  13185. {
  13186. struct rusage rusage;
  13187. (void)reset;
  13188. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13189. if (reset)
  13190. base_rusage = rusage;
  13191. else
  13192. cur_rusage = rusage;
  13193. /* only consider user time, as system time is host-related overhead
  13194. * outside wolfcrypt.
  13195. */
  13196. return (double)rusage.ru_utime.tv_sec +
  13197. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13198. }
  13199. static void check_for_excessive_stime(const char *desc,
  13200. const char *desc_extra)
  13201. {
  13202. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13203. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13204. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13205. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13206. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13207. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13208. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13209. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13210. double stime_utime_ratio =
  13211. (cur_stime - start_stime) / (cur_utime - start_utime);
  13212. if (stime_utime_ratio > .1)
  13213. printf("%swarning, "
  13214. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13215. err_prefix, desc, desc_extra,
  13216. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13217. }
  13218. #elif defined(WOLFSSL_LINUXKM)
  13219. double current_time(int reset)
  13220. {
  13221. (void)reset;
  13222. u64 ns = ktime_get_ns();
  13223. return (double)ns / 1000000000.0;
  13224. }
  13225. #else
  13226. #include <sys/time.h>
  13227. double current_time(int reset)
  13228. {
  13229. struct timespec tv;
  13230. (void)reset;
  13231. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13232. #ifdef BENCH_MICROSECOND
  13233. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13234. #else
  13235. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13236. #endif
  13237. }
  13238. #endif /* _WIN32 */
  13239. #if defined(HAVE_GET_CYCLES)
  13240. #if defined(WOLFSSL_ESPIDF)
  13241. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13242. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13243. {
  13244. /* Reminder for long duration between calls with
  13245. * multiple overflows will not be detected. */
  13246. return esp_get_cycle_count_ex();
  13247. }
  13248. /* implement other architectures here */
  13249. #else
  13250. static WC_INLINE word64 get_intel_cycles(void)
  13251. {
  13252. unsigned int lo_c, hi_c;
  13253. __asm__ __volatile__ (
  13254. "cpuid\n\t"
  13255. "rdtsc"
  13256. : "=a"(lo_c), "=d"(hi_c) /* out */
  13257. : "a"(0) /* in */
  13258. : "%ebx", "%ecx"); /* clobber */
  13259. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13260. }
  13261. #endif
  13262. #endif /* HAVE_GET_CYCLES */
  13263. void benchmark_configure(word32 block_size)
  13264. {
  13265. /* must be greater than 0 */
  13266. if (block_size > 0) {
  13267. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13268. bench_size = block_size;
  13269. }
  13270. }
  13271. #ifndef NO_MAIN_DRIVER
  13272. #ifndef MAIN_NO_ARGS
  13273. #ifndef WOLFSSL_BENCHMARK_ALL
  13274. /* Display the algorithm string and keep to 80 characters per line.
  13275. *
  13276. * str Algorithm string to print.
  13277. * line Length of line used so far.
  13278. */
  13279. #ifndef BENCH_MAX_LINE
  13280. #define BENCH_MAX_LINE 80
  13281. #endif
  13282. static void print_alg(const char* str, int* line)
  13283. {
  13284. const char* const ident = " ";
  13285. if (*line == 0) {
  13286. printf("%s", ident);
  13287. *line = (int)XSTRLEN(ident);
  13288. }
  13289. printf(" %s", str);
  13290. *line += (int)XSTRLEN(str) + 1;
  13291. if (*line > BENCH_MAX_LINE) {
  13292. printf("\n");
  13293. *line = 0;
  13294. }
  13295. }
  13296. #endif /* WOLFSSL_BENCHMARK_ALL */
  13297. /* Display the usage options of the benchmark program. */
  13298. static void Usage(void)
  13299. {
  13300. int e = 0;
  13301. #ifndef WOLFSSL_BENCHMARK_ALL
  13302. int i;
  13303. int line;
  13304. #endif
  13305. printf("benchmark\n");
  13306. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13307. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13308. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13309. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13310. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13311. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13312. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13313. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13314. #else
  13315. e += 3;
  13316. #endif
  13317. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13318. #ifndef NO_RSA
  13319. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13320. #ifdef WOLFSSL_KEY_GEN
  13321. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13322. #endif
  13323. e++;
  13324. #else
  13325. e += 2;
  13326. #endif
  13327. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13328. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13329. #endif
  13330. e++;
  13331. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13332. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13333. #endif
  13334. e++;
  13335. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13336. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13337. #endif
  13338. e++;
  13339. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13340. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13341. #endif
  13342. e++;
  13343. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13344. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13345. #endif
  13346. e++;
  13347. #if defined(HAVE_ECC)
  13348. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13349. #endif
  13350. e++;
  13351. #ifndef WOLFSSL_BENCHMARK_ALL
  13352. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13353. line = 0;
  13354. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13355. print_alg(bench_cipher_opt[i].str, &line);
  13356. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13357. print_alg(bench_digest_opt[i].str, &line);
  13358. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13359. print_alg(bench_mac_opt[i].str, &line);
  13360. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13361. print_alg(bench_kdf_opt[i].str, &line);
  13362. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13363. print_alg(bench_asym_opt[i].str, &line);
  13364. for (i=0; bench_other_opt[i].str != NULL; i++)
  13365. print_alg(bench_other_opt[i].str, &line);
  13366. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13367. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13368. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13369. print_alg(bench_pq_asym_opt[i].str, &line);
  13370. #if defined(HAVE_SPHINCS)
  13371. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13372. print_alg(bench_pq_asym_opt2[i].str, &line);
  13373. #endif /* HAVE_SPHINCS */
  13374. #endif
  13375. #if defined(BENCH_PQ_STATEFUL_HBS)
  13376. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13377. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13378. #endif /* BENCH_PQ_STATEFUL_HBS */
  13379. printf("\n");
  13380. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13381. e++;
  13382. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13383. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13384. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13385. #ifdef WC_ENABLE_BENCH_THREADING
  13386. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13387. #endif
  13388. e++;
  13389. #ifdef WC_BENCH_TRACK_STATS
  13390. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13391. #endif
  13392. e++;
  13393. #ifndef NO_FILESYSTEM
  13394. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13395. #endif
  13396. e++;
  13397. #ifndef NO_FILESYSTEM
  13398. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13399. #endif
  13400. #ifdef MULTI_VALUE_STATISTICS
  13401. e++;
  13402. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13403. #endif
  13404. }
  13405. /* Match the command line argument with the string.
  13406. *
  13407. * arg Command line argument.
  13408. * str String to check for.
  13409. * return 1 if the command line argument matches the string, 0 otherwise.
  13410. */
  13411. static int string_matches(const char* arg, const char* str)
  13412. {
  13413. return XSTRCMP(arg, str) == 0;
  13414. }
  13415. #endif /* MAIN_NO_ARGS */
  13416. /*
  13417. ** ----------------------------------------------------------------------------
  13418. ** determine how the benchmarks are called, the function name varies:
  13419. ** ----------------------------------------------------------------------------
  13420. */
  13421. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13422. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13423. /* for some environments, we'll call a function wolf_benchmark_task: */
  13424. int wolf_benchmark_task(void)
  13425. #elif defined(MAIN_NO_ARGS)
  13426. /* otherwise we'll use main() with no arguments as desired: */
  13427. int main()
  13428. #else
  13429. /* else we'll be calling main with default arg parameters */
  13430. int main(int argc, char** argv)
  13431. #endif
  13432. {
  13433. /* Code for main() or wolf_benchmark_task() */
  13434. #ifdef WOLFSSL_ESPIDF
  13435. int argc = construct_argv();
  13436. char** argv = (char**)__argv;
  13437. #elif defined(MAIN_NO_ARGS)
  13438. int argc = 0;
  13439. char** argv = NULL;
  13440. #endif
  13441. return wolfcrypt_benchmark_main(argc, argv);
  13442. }
  13443. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13444. int wolfcrypt_benchmark_main(int argc, char** argv)
  13445. {
  13446. int ret = 0;
  13447. #ifndef MAIN_NO_ARGS
  13448. int optMatched;
  13449. #ifndef WOLFSSL_BENCHMARK_ALL
  13450. int i;
  13451. #endif
  13452. #endif
  13453. benchmark_static_init(1);
  13454. printf("%s------------------------------------------------------------------------------\n",
  13455. info_prefix);
  13456. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13457. printf("%s------------------------------------------------------------------------------\n",
  13458. info_prefix);
  13459. #ifndef MAIN_NO_ARGS
  13460. while (argc > 1) {
  13461. if (string_matches(argv[1], "-?")) {
  13462. if (--argc > 1) {
  13463. lng_index = XATOI((++argv)[1]);
  13464. if (lng_index<0 || lng_index>1) {
  13465. lng_index = 0;
  13466. }
  13467. }
  13468. Usage();
  13469. return 0;
  13470. }
  13471. else if (string_matches(argv[1], "-lng")) {
  13472. argc--;
  13473. argv++;
  13474. if (argc > 1) {
  13475. lng_index = XATOI(argv[1]);
  13476. if (lng_index<0 || lng_index>1) {
  13477. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13478. lng_index);
  13479. lng_index = 0;
  13480. }
  13481. }
  13482. }
  13483. else if (string_matches(argv[1], "-base10"))
  13484. base2 = 0;
  13485. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13486. else if (string_matches(argv[1], "-no_aad"))
  13487. aes_aad_options = AAD_SIZE_ZERO;
  13488. else if (string_matches(argv[1], "-all_aad"))
  13489. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13490. else if (string_matches(argv[1], "-aad_size")) {
  13491. argc--;
  13492. argv++;
  13493. if (argc > 1) {
  13494. aes_aad_size = (word32)XATOI(argv[1]);
  13495. aes_aad_options |= AAD_SIZE_CUSTOM;
  13496. }
  13497. }
  13498. #endif
  13499. else if (string_matches(argv[1], "-dgst_full"))
  13500. digest_stream = 0;
  13501. #ifdef HAVE_CHACHA
  13502. else if (string_matches(argv[1], "-enc_only"))
  13503. encrypt_only = 1;
  13504. #endif
  13505. #ifndef NO_RSA
  13506. else if (string_matches(argv[1], "-rsa_sign"))
  13507. rsa_sign_verify = 1;
  13508. #endif
  13509. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13510. else if (string_matches(argv[1], "-ffdhe2048"))
  13511. use_ffdhe = 2048;
  13512. #endif
  13513. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13514. else if (string_matches(argv[1], "-ffdhe3072"))
  13515. use_ffdhe = 3072;
  13516. #endif
  13517. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13518. else if (string_matches(argv[1], "-ffdhe4096"))
  13519. use_ffdhe = 4096;
  13520. #endif
  13521. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13522. else if (string_matches(argv[1], "-p256"))
  13523. bench_asym_algs |= BENCH_ECC_P256;
  13524. #endif
  13525. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13526. else if (string_matches(argv[1], "-p384"))
  13527. bench_asym_algs |= BENCH_ECC_P384;
  13528. #endif
  13529. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13530. else if (string_matches(argv[1], "-p521"))
  13531. bench_asym_algs |= BENCH_ECC_P521;
  13532. #endif
  13533. #ifdef BENCH_ASYM
  13534. else if (string_matches(argv[1], "-csv")) {
  13535. csv_format = 1;
  13536. }
  13537. #endif
  13538. #ifdef WC_ENABLE_BENCH_THREADING
  13539. else if (string_matches(argv[1], "-threads")) {
  13540. argc--;
  13541. argv++;
  13542. if (argc > 1) {
  13543. g_threadCount = XATOI(argv[1]);
  13544. if (g_threadCount < 1 || lng_index > 128){
  13545. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13546. g_threadCount);
  13547. g_threadCount = 0;
  13548. }
  13549. }
  13550. }
  13551. #endif
  13552. #ifdef WC_BENCH_TRACK_STATS
  13553. else if (string_matches(argv[1], "-print")) {
  13554. gPrintStats = 1;
  13555. }
  13556. #endif
  13557. else if (string_matches(argv[1], "-blocks")) {
  13558. argc--;
  13559. argv++;
  13560. if (argc > 1)
  13561. numBlocks = XATOI(argv[1]);
  13562. }
  13563. #ifndef NO_FILESYSTEM
  13564. else if (string_matches(argv[1], "-hash_input")) {
  13565. argc--;
  13566. argv++;
  13567. if (argc > 1)
  13568. hash_input = argv[1];
  13569. }
  13570. else if (string_matches(argv[1], "-cipher_input")) {
  13571. argc--;
  13572. argv++;
  13573. if (argc > 1)
  13574. cipher_input = argv[1];
  13575. }
  13576. #endif
  13577. #ifdef MULTI_VALUE_STATISTICS
  13578. else if (string_matches(argv[1], "-min_runs")) {
  13579. argc--;
  13580. argv++;
  13581. if (argc > 1) {
  13582. minimum_runs = XATOI(argv[1]);
  13583. }
  13584. }
  13585. #endif
  13586. else if (argv[1][0] == '-') {
  13587. optMatched = 0;
  13588. #ifndef WOLFSSL_BENCHMARK_ALL
  13589. /* Check known algorithm choosing command line options. */
  13590. /* Known cipher algorithms */
  13591. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13592. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13593. bench_cipher_algs |= bench_cipher_opt[i].val;
  13594. bench_all = 0;
  13595. optMatched = 1;
  13596. }
  13597. }
  13598. /* Known digest algorithms */
  13599. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13600. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13601. bench_digest_algs |= bench_digest_opt[i].val;
  13602. bench_all = 0;
  13603. optMatched = 1;
  13604. }
  13605. }
  13606. /* Known MAC algorithms */
  13607. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13608. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13609. bench_mac_algs |= bench_mac_opt[i].val;
  13610. bench_all = 0;
  13611. optMatched = 1;
  13612. }
  13613. }
  13614. /* Known KDF algorithms */
  13615. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13616. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13617. bench_kdf_algs |= bench_kdf_opt[i].val;
  13618. bench_all = 0;
  13619. optMatched = 1;
  13620. }
  13621. }
  13622. /* Known asymmetric algorithms */
  13623. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13624. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13625. bench_asym_algs |= bench_asym_opt[i].val;
  13626. bench_all = 0;
  13627. optMatched = 1;
  13628. }
  13629. }
  13630. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13631. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13632. /* Known asymmetric post-quantum algorithms */
  13633. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13634. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13635. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13636. bench_all = 0;
  13637. optMatched = 1;
  13638. }
  13639. }
  13640. #ifdef HAVE_SPHINCS
  13641. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13642. * -pq, so we need to do a special case for -pq since optMatched
  13643. * was set to 1 just above. */
  13644. if ((bench_pq_asym_opt[0].str != NULL) &&
  13645. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13646. {
  13647. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13648. bench_all = 0;
  13649. optMatched = 1;
  13650. }
  13651. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13652. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13653. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13654. bench_all = 0;
  13655. optMatched = 1;
  13656. }
  13657. }
  13658. #endif
  13659. #endif
  13660. /* Other known cryptographic algorithms */
  13661. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13662. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13663. bench_other_algs |= bench_other_opt[i].val;
  13664. bench_all = 0;
  13665. optMatched = 1;
  13666. }
  13667. }
  13668. #if defined(BENCH_PQ_STATEFUL_HBS)
  13669. /* post-quantum stateful hash-based signatures */
  13670. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13671. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13672. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13673. bench_all = 0;
  13674. optMatched = 1;
  13675. }
  13676. }
  13677. #endif /* BENCH_PQ_STATEFUL_HBS */
  13678. #endif
  13679. if (!optMatched) {
  13680. printf("Option not recognized: %s\n", argv[1]);
  13681. Usage();
  13682. return 1;
  13683. }
  13684. }
  13685. else {
  13686. /* parse for block size */
  13687. benchmark_configure((word32)XATOI(argv[1]));
  13688. }
  13689. argc--;
  13690. argv++;
  13691. }
  13692. #endif /* MAIN_NO_ARGS */
  13693. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13694. /* when defined, we'll always output CSV regardless of params.
  13695. ** this is typically convenient in embedded environments.
  13696. */
  13697. csv_format = 1;
  13698. #endif
  13699. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13700. if (g_threadCount > 1) {
  13701. ret = benchmark_test_threaded(NULL);
  13702. }
  13703. else
  13704. #endif
  13705. {
  13706. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13707. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13708. defined(CONFIG_IDF_TARGET_ESP32C6)
  13709. {
  13710. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13711. if (esp_gptimer == NULL) {
  13712. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13713. &esp_gptimer) );
  13714. }
  13715. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13716. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13717. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13718. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13719. }
  13720. #endif
  13721. #ifdef HAVE_STACK_SIZE
  13722. ret = StackSizeCheck(NULL, benchmark_test);
  13723. #else
  13724. ret = benchmark_test(NULL);
  13725. #endif
  13726. }
  13727. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13728. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13729. defined(CONFIG_IDF_TARGET_ESP32C6)
  13730. {
  13731. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13732. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13733. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13734. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13735. }
  13736. #endif
  13737. return ret;
  13738. }
  13739. #endif /* !NO_MAIN_DRIVER */
  13740. #else
  13741. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13742. int main(void) { return 0; }
  13743. #endif
  13744. #endif /* !NO_CRYPT_BENCHMARK */