benchmark.c 518 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263
  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. #if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
  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. #include <wolfssl/wolfcrypt/cpuid.h>
  219. #ifdef USE_FLAT_BENCHMARK_H
  220. #include "benchmark.h"
  221. #else
  222. #include "wolfcrypt/benchmark/benchmark.h"
  223. #endif
  224. /* define the max length for each string of metric reported */
  225. #ifndef WC_BENCH_MAX_LINE_LEN
  226. #define WC_BENCH_MAX_LINE_LEN 150
  227. #endif
  228. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  229. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  230. #define MILLION_VALUE 1000000.0
  231. #ifdef BENCH_MICROSECOND
  232. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  233. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  234. #else
  235. #define WOLFSSL_FIXED_TIME_UNIT "s"
  236. #endif
  237. #ifdef MULTI_VALUE_STATISTICS
  238. #define STATS_CLAUSE_SEPARATOR ""
  239. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  240. squareSum = 0, prev = 0, delta;\
  241. int runs = 0;
  242. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  243. delta = current_time(0) - start;\
  244. min = delta;\
  245. max = delta;\
  246. }\
  247. else {\
  248. delta = current_time(0) - prev;\
  249. }\
  250. if (max < delta)\
  251. max = delta;\
  252. else if (min > delta)\
  253. min = delta;\
  254. sum += delta;\
  255. squareSum += delta * delta;\
  256. runs++;\
  257. prev = current_time(0)
  258. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  259. runs = 0;\
  260. sum = 0;\
  261. squareSum = 0
  262. #else
  263. #define STATS_CLAUSE_SEPARATOR "\n"
  264. #define DECLARE_MULTI_VALUE_STATS_VARS()
  265. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  266. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  267. #endif
  268. #ifdef WOLFSSL_NO_FLOAT_FMT
  269. #define FLT_FMT "%0ld,%09lu"
  270. #define FLT_FMT_PREC "%0ld.%0*lu"
  271. #define FLT_FMT_PREC2 FLT_FMT_PREC
  272. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  273. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  274. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  275. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  276. 10000.0, 100000.0, 1000000.0, \
  277. 10000000.0, 100000000.0, \
  278. 1000000000.0 };
  279. #define FLT_FMT_PREC_ARGS(p, x) \
  280. (long)(x), \
  281. p, \
  282. (x) >= 0.0 ? \
  283. (unsigned long int)((((x) - (double)(long)(x)) * \
  284. pow_10_array[(p)+1]) + 0.5) : \
  285. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  286. pow_10_array[(p)+1]) + 0.5)
  287. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  288. #else
  289. #define FLT_FMT "%f"
  290. #define FLT_FMT_PREC "%.*f"
  291. #define FLT_FMT_PREC2 "%*.*f"
  292. #define FLT_FMT_ARGS(x) x
  293. #define FLT_FMT_PREC_ARGS(p, x) p, x
  294. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  295. #endif /* WOLFSSL_NO_FLOAT_FMT */
  296. #ifdef WOLFSSL_ESPIDF
  297. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  298. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  299. * enabled, all if the values in report are blank. */
  300. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  301. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  302. #error "Nano newlib formatting must not be enabled for benchmark"
  303. #endif
  304. #endif
  305. #if ESP_IDF_VERSION_MAJOR >= 5
  306. #define TFMT "%lu"
  307. #else
  308. #define TFMT "%d"
  309. #endif
  310. #ifdef configTICK_RATE_HZ
  311. /* Define CPU clock cycles per tick of FreeRTOS clock
  312. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  313. * configTICK_RATE_HZ is typically 100 or 1000.
  314. **/
  315. #if defined(CONFIG_IDF_TARGET_ESP8266)
  316. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  317. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  318. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  319. #endif
  320. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  321. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  322. #endif
  323. #endif
  324. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  325. /* This section is for pre-v5 ESP-IDF */
  326. #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  327. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  328. CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
  329. #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
  330. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  331. CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
  332. #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
  333. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  334. CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
  335. #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
  336. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  337. CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
  338. #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
  339. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  340. CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
  341. #else
  342. /* TODO unsupported */
  343. #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
  344. #endif
  345. #define CPU_TICK_CYCLES ( \
  346. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  347. / configTICK_RATE_HZ \
  348. )
  349. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  350. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  351. #include "driver/gptimer.h"
  352. static gptimer_handle_t esp_gptimer = NULL;
  353. static gptimer_config_t esp_timer_config = {
  354. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  355. .direction = GPTIMER_COUNT_UP,
  356. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  357. };
  358. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  359. defined(CONFIG_IDF_TARGET_ESP32C6)
  360. #include <esp_cpu.h>
  361. #if ESP_IDF_VERSION_MAJOR >= 5
  362. #include <driver/gptimer.h>
  363. #endif
  364. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  365. #define RESOLUTION_SCALE 100
  366. /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  367. static gptimer_handle_t esp_gptimer = NULL;
  368. static gptimer_config_t esp_timer_config = {
  369. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  370. .direction = GPTIMER_COUNT_UP,
  371. /* CONFIG_XTAL_FREQ = 40,
  372. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  373. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  374. (MILLION_VALUE / RESOLUTION_SCALE),
  375. };
  376. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  377. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  378. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  379. defined(CONFIG_IDF_TARGET_ESP32S3)
  380. #include <xtensa/hal.h>
  381. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  382. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  383. #include <FreeRTOS.h>
  384. #include <esp_system.h>
  385. #include <esp_timer.h>
  386. #include <xtensa/hal.h>
  387. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  388. /* TODO add ESP32-H2 benchmark support */
  389. #else
  390. /* Other platform */
  391. #endif
  392. #include <esp_log.h>
  393. #endif /* WOLFSSL_ESPIDF */
  394. #if defined(HAVE_PTHREAD) || \
  395. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  396. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  397. !defined(BENCH_EMBEDDED))
  398. #include <errno.h>
  399. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  400. #include <unistd.h>
  401. #endif
  402. #endif
  403. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  404. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  405. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  406. #undef XFFLUSH
  407. #define XFFLUSH(...) WC_DO_NOTHING
  408. #endif
  409. /* only for stack size check */
  410. #include <wolfssl/wolfcrypt/mem_track.h>
  411. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  412. #define WC_ENABLE_BENCH_THREADING
  413. #endif
  414. /* enable tracking of stats for threaded benchmark */
  415. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  416. #define WC_BENCH_TRACK_STATS
  417. #endif
  418. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  419. static const char info_prefix[] = "###, ";
  420. static const char err_prefix[] = "!!!, ";
  421. #else
  422. static const char info_prefix[] = "";
  423. static const char err_prefix[] = "";
  424. #endif
  425. /* printf mappings */
  426. #ifdef FREESCALE_MQX
  427. #include <mqx.h>
  428. /* see wc_port.h for fio.h and nio.h includes */
  429. #elif defined(FREESCALE_KSDK_1_3)
  430. #include "fsl_debug_console.h"
  431. #include "fsl_os_abstraction.h"
  432. #undef printf
  433. #define printf PRINTF
  434. #elif defined(WOLFSSL_DEOS)
  435. #include <deos.h>
  436. #include <printx.h>
  437. #undef printf
  438. #define printf printx
  439. #elif defined(MICRIUM)
  440. #if (OS_VERSION < 50000)
  441. #include <bsp_ser.h>
  442. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  443. #undef printf
  444. #define printf BSP_Ser_Printf
  445. #endif
  446. #elif defined(WOLFSSL_ZEPHYR)
  447. #include <stdio.h>
  448. #include <stdarg.h>
  449. #define BENCH_EMBEDDED
  450. #define printf printfk
  451. static int printfk(const char *fmt, ...)
  452. {
  453. int ret;
  454. char line[WC_BENCH_MAX_LINE_LEN];
  455. va_list ap;
  456. va_start(ap, fmt);
  457. ret = vsnprintf(line, sizeof(line), fmt, ap);
  458. line[sizeof(line)-1] = '\0';
  459. printk("%s", line);
  460. va_end(ap);
  461. return ret;
  462. }
  463. #elif defined(WOLFSSL_TELIT_M2MB)
  464. #include <stdarg.h>
  465. #include <stdio.h>
  466. #include <string.h>
  467. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  468. /* remap printf */
  469. #undef printf
  470. #define printf M2M_LOG_INFO
  471. /* OS requires occasional sleep() */
  472. #ifndef TEST_SLEEP_MS
  473. #define TEST_SLEEP_MS 50
  474. #endif
  475. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  476. /* don't use file system for these tests, since ./certs dir isn't loaded */
  477. #undef NO_FILESYSTEM
  478. #define NO_FILESYSTEM
  479. /* ANDROID_V454 (for android studio) displays information in a textview
  480. * and redirects printf to the textview output instead of using
  481. * __android_log_print() */
  482. #elif defined(ANDROID) && !defined(ANDROID_V454)
  483. #ifdef XMALLOC_USER
  484. #include <stdlib.h> /* we're using malloc / free direct here */
  485. #endif
  486. #ifndef STRING_USER
  487. #include <stdio.h>
  488. #endif
  489. #include <android/log.h>
  490. #define printf(...) \
  491. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  492. #define fprintf(fp, ...) \
  493. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  494. #else
  495. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  496. /* MQX classic needs for EXIT_FAILURE */
  497. #include <stdlib.h> /* we're using malloc / free direct here */
  498. #endif
  499. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  500. #include <string.h>
  501. #include <stdio.h>
  502. #endif
  503. /* enable way for customer to override test/bench printf */
  504. #ifdef XPRINTF
  505. #undef printf
  506. #define printf XPRINTF
  507. #elif defined(NETOS)
  508. #undef printf
  509. #define printf dc_log_printf
  510. #endif
  511. #endif
  512. #ifdef HAVE_FIPS
  513. #include <wolfssl/wolfcrypt/fips_test.h>
  514. static void myFipsCb(int ok, int err, const char* hash)
  515. {
  516. printf("%sin my Fips callback, ok = %d, err = %d\n",
  517. ok ? info_prefix : err_prefix, ok, err);
  518. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  519. wc_GetErrorString(err));
  520. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  521. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  522. printf("%sIn core integrity hash check failure, copy above hash\n",
  523. err_prefix);
  524. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  525. err_prefix);
  526. }
  527. }
  528. #endif
  529. #ifdef WOLFSSL_STATIC_MEMORY
  530. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  531. #else
  532. #define HEAP_HINT NULL
  533. #endif /* WOLFSSL_STATIC_MEMORY */
  534. #ifndef EXIT_FAILURE
  535. #define EXIT_FAILURE 1
  536. #endif
  537. #undef LIBCALL_CHECK_RET
  538. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  539. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  540. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  541. #else
  542. #define LIBCALL_CHECK_RET(...) do { \
  543. int _libcall_ret = (__VA_ARGS__); \
  544. if (_libcall_ret < 0) { \
  545. printf("%s%s L%d error %d for \"%s\"\n", \
  546. err_prefix, __FILE__, __LINE__, \
  547. errno, #__VA_ARGS__); \
  548. XFFLUSH(stdout); \
  549. _exit(1); \
  550. } \
  551. } while(0)
  552. #endif
  553. #undef THREAD_CHECK_RET
  554. #define THREAD_CHECK_RET(...) do { \
  555. int _thread_ret = (__VA_ARGS__); \
  556. if (_thread_ret != 0) { \
  557. errno = _thread_ret; \
  558. printf("%s%s L%d error %d for \"%s\"\n", \
  559. err_prefix, __FILE__, __LINE__, \
  560. _thread_ret, #__VA_ARGS__); \
  561. XFFLUSH(stdout); \
  562. _exit(1); \
  563. } \
  564. } while(0)
  565. /* optional macro to add sleep between tests */
  566. #ifndef TEST_SLEEP
  567. /* stub the sleep macro */
  568. #define TEST_SLEEP() WC_DO_NOTHING
  569. #endif
  570. #define TEST_STRING "Everyone gets Friday off."
  571. #define TEST_STRING_SZ 25
  572. /* Bit values for each algorithm that is able to be benchmarked.
  573. * Common grouping of algorithms also.
  574. * Each algorithm has a unique value for its type e.g. cipher.
  575. */
  576. /* Cipher algorithms. */
  577. #define BENCH_AES_CBC 0x00000001
  578. #define BENCH_AES_GCM 0x00000002
  579. #define BENCH_AES_ECB 0x00000004
  580. #define BENCH_AES_XTS 0x00000008
  581. #define BENCH_AES_CTR 0x00000010
  582. #define BENCH_AES_CCM 0x00000020
  583. #define BENCH_CAMELLIA 0x00000100
  584. #define BENCH_ARC4 0x00000200
  585. #define BENCH_CHACHA20 0x00001000
  586. #define BENCH_CHACHA20_POLY1305 0x00002000
  587. #define BENCH_DES 0x00004000
  588. #define BENCH_AES_CFB 0x00010000
  589. #define BENCH_AES_OFB 0x00020000
  590. #define BENCH_AES_SIV 0x00040000
  591. #define BENCH_SM4_CBC 0x00080000
  592. #define BENCH_SM4_GCM 0x00100000
  593. #define BENCH_SM4_CCM 0x00200000
  594. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  595. /* Digest algorithms. */
  596. #define BENCH_MD5 0x00000001
  597. #define BENCH_POLY1305 0x00000002
  598. #define BENCH_SHA 0x00000004
  599. #define BENCH_SHA224 0x00000010
  600. #define BENCH_SHA256 0x00000020
  601. #define BENCH_SHA384 0x00000040
  602. #define BENCH_SHA512 0x00000080
  603. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  604. BENCH_SHA384 | BENCH_SHA512)
  605. #define BENCH_SHA3_224 0x00000100
  606. #define BENCH_SHA3_256 0x00000200
  607. #define BENCH_SHA3_384 0x00000400
  608. #define BENCH_SHA3_512 0x00000800
  609. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  610. BENCH_SHA3_384 | BENCH_SHA3_512)
  611. #define BENCH_SHAKE128 0x00001000
  612. #define BENCH_SHAKE256 0x00002000
  613. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  614. #define BENCH_RIPEMD 0x00004000
  615. #define BENCH_BLAKE2B 0x00008000
  616. #define BENCH_BLAKE2S 0x00010000
  617. #define BENCH_SM3 0x00020000
  618. /* MAC algorithms. */
  619. #define BENCH_CMAC 0x00000001
  620. #define BENCH_HMAC_MD5 0x00000002
  621. #define BENCH_HMAC_SHA 0x00000004
  622. #define BENCH_HMAC_SHA224 0x00000010
  623. #define BENCH_HMAC_SHA256 0x00000020
  624. #define BENCH_HMAC_SHA384 0x00000040
  625. #define BENCH_HMAC_SHA512 0x00000080
  626. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  627. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  628. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  629. #define BENCH_PBKDF2 0x00000100
  630. #define BENCH_SIPHASH 0x00000200
  631. /* KDF algorithms */
  632. #define BENCH_SRTP_KDF 0x00000001
  633. /* Asymmetric algorithms. */
  634. #define BENCH_RSA_KEYGEN 0x00000001
  635. #define BENCH_RSA 0x00000002
  636. #define BENCH_RSA_SZ 0x00000004
  637. #define BENCH_DH 0x00000010
  638. #define BENCH_ECC_MAKEKEY 0x00001000
  639. #define BENCH_ECC 0x00002000
  640. #define BENCH_ECC_ENCRYPT 0x00004000
  641. #define BENCH_ECC_ALL 0x00008000
  642. #define BENCH_CURVE25519_KEYGEN 0x00010000
  643. #define BENCH_CURVE25519_KA 0x00020000
  644. #define BENCH_ED25519_KEYGEN 0x00040000
  645. #define BENCH_ED25519_SIGN 0x00080000
  646. #define BENCH_CURVE448_KEYGEN 0x00100000
  647. #define BENCH_CURVE448_KA 0x00200000
  648. #define BENCH_ED448_KEYGEN 0x00400000
  649. #define BENCH_ED448_SIGN 0x00800000
  650. #define BENCH_ECC_P256 0x01000000
  651. #define BENCH_ECC_P384 0x02000000
  652. #define BENCH_ECC_P521 0x04000000
  653. #define BENCH_SM2 0x08000000
  654. #define BENCH_ECCSI_KEYGEN 0x00000020
  655. #define BENCH_ECCSI_PAIRGEN 0x00000040
  656. #define BENCH_ECCSI_VALIDATE 0x00000080
  657. #define BENCH_ECCSI 0x00000400
  658. #define BENCH_SAKKE_KEYGEN 0x10000000
  659. #define BENCH_SAKKE_RSKGEN 0x20000000
  660. #define BENCH_SAKKE_VALIDATE 0x40000000
  661. #define BENCH_SAKKE 0x80000000
  662. /* Post-Quantum Asymmetric algorithms. */
  663. #define BENCH_KYBER512 0x00000020
  664. #define BENCH_KYBER768 0x00000040
  665. #define BENCH_KYBER1024 0x00000080
  666. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  667. BENCH_KYBER1024)
  668. #define BENCH_ML_KEM_512 0x00000020
  669. #define BENCH_ML_KEM_768 0x00000040
  670. #define BENCH_ML_KEM_1024 0x00000080
  671. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  672. BENCH_ML_KEM_1024)
  673. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  674. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  675. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  676. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  677. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  678. #define BENCH_ML_DSA_44_SIGN 0x04000000
  679. #define BENCH_ML_DSA_65_SIGN 0x08000000
  680. #define BENCH_ML_DSA_87_SIGN 0x10000000
  681. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  682. BENCH_ML_DSA_65_SIGN | \
  683. BENCH_ML_DSA_87_SIGN)
  684. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  685. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  686. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  687. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  688. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  689. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  690. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  691. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  692. #define BENCH_LMS_HSS 0x00000001
  693. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  694. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  695. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  696. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  697. #ifndef NO_SHA256
  698. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  699. #elif defined(WOLFSSL_SHA512)
  700. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  701. #elif defined(WOLFSSL_SHAKE128)
  702. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  703. #elif defined(WOLFSSL_SHAKE256)
  704. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  705. #else
  706. #define BENCH_XMSS_XMSSMT 0x00000000
  707. #endif
  708. /* Other */
  709. #define BENCH_RNG 0x00000001
  710. #define BENCH_SCRYPT 0x00000002
  711. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  712. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  713. * static declaration of `bench_Usage_msg1`. */
  714. #if !defined(AES_AUTH_ADD_SZ) && \
  715. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  716. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  717. /* For STM32 use multiple of 4 to leverage crypto hardware
  718. * Xilinx Versal requires to use multiples of 16 bytes */
  719. #define AES_AUTH_ADD_SZ 16
  720. #endif
  721. #ifndef AES_AUTH_ADD_SZ
  722. #define AES_AUTH_ADD_SZ 13
  723. #endif
  724. #endif
  725. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  726. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  727. #define BENCH_PQ_STATEFUL_HBS
  728. #endif
  729. /* Benchmark all compiled in algorithms.
  730. * When 1, ignore other benchmark algorithm values.
  731. * 0, only benchmark algorithm values set.
  732. */
  733. static int bench_all = 1;
  734. /* Cipher algorithms to benchmark. */
  735. static word32 bench_cipher_algs = 0;
  736. /* Digest algorithms to benchmark. */
  737. static word32 bench_digest_algs = 0;
  738. /* MAC algorithms to benchmark. */
  739. static word32 bench_mac_algs = 0;
  740. /* KDF algorithms to benchmark. */
  741. static word32 bench_kdf_algs = 0;
  742. /* Asymmetric algorithms to benchmark. */
  743. static word32 bench_asym_algs = 0;
  744. /* Post-Quantum Asymmetric algorithms to benchmark. */
  745. static word32 bench_pq_asym_algs = 0;
  746. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  747. static word32 bench_pq_asym_algs2 = 0;
  748. /* Other cryptographic algorithms to benchmark. */
  749. static word32 bench_other_algs = 0;
  750. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  751. static word32 bench_pq_hash_sig_algs = 0;
  752. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  753. /* The mapping of command line option to bit values. */
  754. typedef struct bench_alg {
  755. /* Command line option string. */
  756. const char* str;
  757. /* Bit values to set. */
  758. word32 val;
  759. } bench_alg;
  760. #ifndef MAIN_NO_ARGS
  761. /* All recognized cipher algorithm choosing command line options. */
  762. static const bench_alg bench_cipher_opt[] = {
  763. { "-cipher", 0xffffffff },
  764. #ifdef HAVE_AES_CBC
  765. { "-aes-cbc", BENCH_AES_CBC },
  766. #endif
  767. #ifdef HAVE_AESGCM
  768. { "-aes-gcm", BENCH_AES_GCM },
  769. #endif
  770. #ifdef WOLFSSL_AES_DIRECT
  771. { "-aes-ecb", BENCH_AES_ECB },
  772. #endif
  773. #ifdef WOLFSSL_AES_XTS
  774. { "-aes-xts", BENCH_AES_XTS },
  775. #endif
  776. #ifdef WOLFSSL_AES_CFB
  777. { "-aes-cfb", BENCH_AES_CFB },
  778. #endif
  779. #ifdef WOLFSSL_AES_OFB
  780. { "-aes-ofb", BENCH_AES_OFB },
  781. #endif
  782. #ifdef WOLFSSL_AES_COUNTER
  783. { "-aes-ctr", BENCH_AES_CTR },
  784. #endif
  785. #ifdef HAVE_AESCCM
  786. { "-aes-ccm", BENCH_AES_CCM },
  787. #endif
  788. #ifdef WOLFSSL_AES_SIV
  789. { "-aes-siv", BENCH_AES_SIV },
  790. #endif
  791. #ifdef HAVE_CAMELLIA
  792. { "-camellia", BENCH_CAMELLIA },
  793. #endif
  794. #ifndef NO_RC4
  795. { "-arc4", BENCH_ARC4 },
  796. #endif
  797. #ifdef HAVE_CHACHA
  798. { "-chacha20", BENCH_CHACHA20 },
  799. #endif
  800. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  801. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  802. #endif
  803. #ifdef WOLFSSL_SM4_CBC
  804. { "-sm4-cbc", BENCH_SM4_CBC },
  805. #endif
  806. #ifdef WOLFSSL_SM4_GCM
  807. { "-sm4-gcm", BENCH_SM4_GCM },
  808. #endif
  809. #ifdef WOLFSSL_SM4_CCM
  810. { "-sm4-ccm", BENCH_SM4_CCM },
  811. #endif
  812. #ifdef WOLFSSL_SM4
  813. { "-sm4", BENCH_SM4 },
  814. #endif
  815. #ifndef NO_DES3
  816. { "-des", BENCH_DES },
  817. #endif
  818. { NULL, 0 }
  819. };
  820. /* All recognized digest algorithm choosing command line options. */
  821. static const bench_alg bench_digest_opt[] = {
  822. { "-digest", 0xffffffff },
  823. #ifndef NO_MD5
  824. { "-md5", BENCH_MD5 },
  825. #endif
  826. #ifdef HAVE_POLY1305
  827. { "-poly1305", BENCH_POLY1305 },
  828. #endif
  829. #ifndef NO_SHA
  830. { "-sha", BENCH_SHA },
  831. #endif
  832. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  833. || defined(WOLFSSL_SHA512)
  834. { "-sha2", BENCH_SHA2 },
  835. #endif
  836. #ifdef WOLFSSL_SHA224
  837. { "-sha224", BENCH_SHA224 },
  838. #endif
  839. #ifndef NO_SHA256
  840. { "-sha256", BENCH_SHA256 },
  841. #endif
  842. #ifdef WOLFSSL_SHA384
  843. { "-sha384", BENCH_SHA384 },
  844. #endif
  845. #ifdef WOLFSSL_SHA512
  846. { "-sha512", BENCH_SHA512 },
  847. #endif
  848. #ifdef WOLFSSL_SHA3
  849. { "-sha3", BENCH_SHA3 },
  850. #ifndef WOLFSSL_NOSHA3_224
  851. { "-sha3-224", BENCH_SHA3_224 },
  852. #endif
  853. #ifndef WOLFSSL_NOSHA3_256
  854. { "-sha3-256", BENCH_SHA3_256 },
  855. #endif
  856. #ifndef WOLFSSL_NOSHA3_384
  857. { "-sha3-384", BENCH_SHA3_384 },
  858. #endif
  859. #ifndef WOLFSSL_NOSHA3_512
  860. { "-sha3-512", BENCH_SHA3_512 },
  861. #endif
  862. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  863. { "-shake", BENCH_SHAKE },
  864. #endif
  865. #ifdef WOLFSSL_SHAKE128
  866. { "-shake128", BENCH_SHAKE128 },
  867. #endif
  868. #ifdef WOLFSSL_SHAKE256
  869. { "-shake256", BENCH_SHAKE256 },
  870. #endif
  871. #endif
  872. #ifdef WOLFSSL_SM3
  873. { "-sm3", BENCH_SM3 },
  874. #endif
  875. #ifdef WOLFSSL_RIPEMD
  876. { "-ripemd", BENCH_RIPEMD },
  877. #endif
  878. #ifdef HAVE_BLAKE2
  879. { "-blake2b", BENCH_BLAKE2B },
  880. #endif
  881. #ifdef HAVE_BLAKE2S
  882. { "-blake2s", BENCH_BLAKE2S },
  883. #endif
  884. { NULL, 0 }
  885. };
  886. /* All recognized MAC algorithm choosing command line options. */
  887. static const bench_alg bench_mac_opt[] = {
  888. { "-mac", 0xffffffff },
  889. #ifdef WOLFSSL_CMAC
  890. { "-cmac", BENCH_CMAC },
  891. #endif
  892. #ifndef NO_HMAC
  893. { "-hmac", BENCH_HMAC },
  894. #ifndef NO_MD5
  895. { "-hmac-md5", BENCH_HMAC_MD5 },
  896. #endif
  897. #ifndef NO_SHA
  898. { "-hmac-sha", BENCH_HMAC_SHA },
  899. #endif
  900. #ifdef WOLFSSL_SHA224
  901. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  902. #endif
  903. #ifndef NO_SHA256
  904. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  905. #endif
  906. #ifdef WOLFSSL_SHA384
  907. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  908. #endif
  909. #ifdef WOLFSSL_SHA512
  910. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  911. #endif
  912. #ifndef NO_PWDBASED
  913. { "-pbkdf2", BENCH_PBKDF2 },
  914. #endif
  915. #endif
  916. #ifdef WOLFSSL_SIPHASH
  917. { "-siphash", BENCH_SIPHASH },
  918. #endif
  919. { NULL, 0 }
  920. };
  921. /* All recognized KDF algorithm choosing command line options. */
  922. static const bench_alg bench_kdf_opt[] = {
  923. { "-kdf", 0xffffffff },
  924. #ifdef WC_SRTP_KDF
  925. { "-srtp-kdf", BENCH_SRTP_KDF },
  926. #endif
  927. { NULL, 0 }
  928. };
  929. /* All recognized asymmetric algorithm choosing command line options. */
  930. static const bench_alg bench_asym_opt[] = {
  931. { "-asym", 0xffffffff },
  932. #ifndef NO_RSA
  933. #ifdef WOLFSSL_KEY_GEN
  934. { "-rsa-kg", BENCH_RSA_KEYGEN },
  935. #endif
  936. { "-rsa", BENCH_RSA },
  937. #ifdef WOLFSSL_KEY_GEN
  938. { "-rsa-sz", BENCH_RSA_SZ },
  939. #endif
  940. #endif
  941. #ifndef NO_DH
  942. { "-dh", BENCH_DH },
  943. #endif
  944. #ifdef HAVE_ECC
  945. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  946. { "-ecc", BENCH_ECC },
  947. #ifdef HAVE_ECC_ENCRYPT
  948. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  949. #endif
  950. { "-ecc-all", BENCH_ECC_ALL },
  951. #endif
  952. #ifdef WOLFSSL_SM2
  953. { "-sm2", BENCH_SM2 },
  954. #endif
  955. #ifdef HAVE_CURVE25519
  956. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  957. #ifdef HAVE_CURVE25519_SHARED_SECRET
  958. { "-x25519", BENCH_CURVE25519_KA },
  959. #endif
  960. #endif
  961. #ifdef HAVE_ED25519
  962. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  963. { "-ed25519", BENCH_ED25519_SIGN },
  964. #endif
  965. #ifdef HAVE_CURVE448
  966. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  967. #ifdef HAVE_CURVE448_SHARED_SECRET
  968. { "-x448", BENCH_CURVE448_KA },
  969. #endif
  970. #endif
  971. #ifdef HAVE_ED448
  972. { "-ed448-kg", BENCH_ED448_KEYGEN },
  973. { "-ed448", BENCH_ED448_SIGN },
  974. #endif
  975. #ifdef WOLFCRYPT_HAVE_ECCSI
  976. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  977. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  978. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  979. { "-eccsi", BENCH_ECCSI },
  980. #endif
  981. #ifdef WOLFCRYPT_HAVE_SAKKE
  982. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  983. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  984. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  985. { "-sakke", BENCH_SAKKE },
  986. #endif
  987. { NULL, 0 }
  988. };
  989. /* All recognized other cryptographic algorithm choosing command line options.
  990. */
  991. static const bench_alg bench_other_opt[] = {
  992. { "-other", 0xffffffff },
  993. #ifndef WC_NO_RNG
  994. { "-rng", BENCH_RNG },
  995. #endif
  996. #ifdef HAVE_SCRYPT
  997. { "-scrypt", BENCH_SCRYPT },
  998. #endif
  999. { NULL, 0}
  1000. };
  1001. #endif /* MAIN_NO_ARGS */
  1002. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  1003. #if defined(BENCH_PQ_STATEFUL_HBS)
  1004. typedef struct bench_pq_hash_sig_alg {
  1005. /* Command line option string. */
  1006. const char* str;
  1007. /* Bit values to set. */
  1008. word32 val;
  1009. } bench_pq_hash_sig_alg;
  1010. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  1011. { "-pq_hash_sig", 0xffffffff},
  1012. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  1013. { "-lms_hss", BENCH_LMS_HSS},
  1014. #endif
  1015. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  1016. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  1017. #ifdef WC_XMSS_SHA256
  1018. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  1019. #endif
  1020. #ifdef WC_XMSS_SHA512
  1021. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  1022. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  1023. #endif
  1024. #endif
  1025. #ifdef WC_XMSS_SHAKE128
  1026. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  1027. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  1028. #endif
  1029. #endif
  1030. #ifdef WC_XMSS_SHAKE256
  1031. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  1032. #endif
  1033. #endif
  1034. { NULL, 0}
  1035. };
  1036. #endif /* BENCH_PQ_STATEFUL_HBS */
  1037. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1038. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1039. /* The post-quantum-specific mapping of command line option to bit values and
  1040. * OQS name. */
  1041. typedef struct bench_pq_alg {
  1042. /* Command line option string. */
  1043. const char* str;
  1044. /* Bit values to set. */
  1045. word32 val;
  1046. } bench_pq_alg;
  1047. /* All recognized post-quantum asymmetric algorithm choosing command line
  1048. * options. */
  1049. static const bench_pq_alg bench_pq_asym_opt[] = {
  1050. { "-pq", 0xffffffff },
  1051. #ifdef WOLFSSL_HAVE_KYBER
  1052. { "-kyber", BENCH_KYBER },
  1053. { "-kyber512", BENCH_KYBER512 },
  1054. { "-kyber768", BENCH_KYBER768 },
  1055. { "-kyber1024", BENCH_KYBER1024 },
  1056. { "-ml-kem", BENCH_ML_KEM },
  1057. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1058. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1059. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1060. #endif
  1061. #if defined(HAVE_FALCON)
  1062. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1063. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1064. #endif
  1065. #if defined(HAVE_DILITHIUM)
  1066. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1067. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1068. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1069. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1070. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1071. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1072. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1073. #endif
  1074. { NULL, 0 }
  1075. };
  1076. #if defined(HAVE_SPHINCS)
  1077. /* All recognized post-quantum asymmetric algorithm choosing command line
  1078. * options. (Part 2) */
  1079. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1080. { "-pq", 0xffffffff },
  1081. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1082. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1083. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1084. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1085. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1086. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1087. { NULL, 0, }
  1088. };
  1089. #endif /* HAVE_SPHINCS */
  1090. #endif
  1091. #ifdef HAVE_WNR
  1092. const char* wnrConfigFile = "wnr-example.conf";
  1093. #endif
  1094. #if defined(WOLFSSL_MDK_ARM)
  1095. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1096. #define fopen wolfSSL_fopen
  1097. #endif
  1098. static int lng_index = 0;
  1099. #ifndef NO_MAIN_DRIVER
  1100. #ifndef MAIN_NO_ARGS
  1101. static const char* bench_Usage_msg1[][25] = {
  1102. /* 0 English */
  1103. { "-? <num> Help, print this usage\n",
  1104. " 0: English, 1: Japanese\n",
  1105. "-csv Print terminal output in csv format\n",
  1106. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1107. "-no_aad No additional authentication data passed.\n",
  1108. "-aad_size <num> With <num> bytes of AAD.\n",
  1109. ("-all_aad With AAD length of 0, "
  1110. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1111. " and\n"
  1112. " (if set via -aad_size) <aad_size> bytes.\n"
  1113. ),
  1114. "-dgst_full Full digest operation performed.\n",
  1115. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1116. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1117. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1118. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1119. "-p256 Measure ECC using P-256 curve.\n",
  1120. "-p384 Measure ECC using P-384 curve.\n",
  1121. "-p521 Measure ECC using P-521 curve.\n",
  1122. "-ecc-all Bench all enabled ECC curves.\n",
  1123. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1124. ("-lng <num> Display benchmark result by specified language.\n"
  1125. " 0: English, 1: Japanese\n"
  1126. ),
  1127. "<num> Size of block in bytes\n",
  1128. ("-blocks <num> Number of blocks. Can be used together with the "
  1129. "'Size of block'\n"
  1130. " option, but must be used after that one.\n"
  1131. ),
  1132. "-threads <num> Number of threads to run\n",
  1133. "-print Show benchmark stats summary\n",
  1134. "-hash_input <file> Input data to use for hash benchmarking\n",
  1135. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1136. "-min_runs <num> Specify minimum number of operation runs\n"
  1137. },
  1138. #ifndef NO_MULTIBYTE_PRINT
  1139. /* 1 Japanese */
  1140. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1141. " 0: 英語、 1: 日本語\n",
  1142. "-csv csv 形式で端末に出力します。\n",
  1143. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1144. "-no_aad 追加の認証データを使用しません.\n",
  1145. "-aad_size <num> TBD.\n",
  1146. "-all_aad TBD.\n",
  1147. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1148. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1149. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1150. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1151. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1152. "-p256 Measure ECC using P-256 curve.\n",
  1153. "-p384 Measure ECC using P-384 curve.\n",
  1154. "-p521 Measure ECC using P-521 curve.\n",
  1155. "-ecc-all Bench all enabled ECC curves.\n",
  1156. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1157. " 利用可能なアルゴリズムは下記を含みます:\n"
  1158. ),
  1159. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1160. " 0: 英語、 1: 日本語\n"
  1161. ),
  1162. "<num> ブロックサイズをバイト単位で指定します。\n",
  1163. "-blocks <num> TBD.\n",
  1164. "-threads <num> 実行するスレッド数\n",
  1165. "-print ベンチマーク統計の要約を表示する\n",
  1166. /* TODO: translate below */
  1167. "-hash_input <file> Input data to use for hash benchmarking\n",
  1168. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1169. "-min_runs <num> Specify minimum number of operation runs\n"
  1170. },
  1171. #endif
  1172. };
  1173. #endif /* MAIN_NO_ARGS */
  1174. #endif
  1175. static const char* bench_result_words1[][4] = {
  1176. { "took",
  1177. #ifdef BENCH_MICROSECOND
  1178. "microseconds"
  1179. #else
  1180. "seconds"
  1181. #endif
  1182. , "Cycles per byte", NULL }, /* 0 English */
  1183. #ifndef NO_MULTIBYTE_PRINT
  1184. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1185. #endif
  1186. };
  1187. #if !defined(NO_RSA) || \
  1188. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1189. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1190. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1191. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1192. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1193. static const char* bench_desc_words[][15] = {
  1194. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1195. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1196. #ifndef NO_MULTIBYTE_PRINT
  1197. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1198. #endif
  1199. };
  1200. #endif
  1201. #ifdef MULTI_VALUE_STATISTICS
  1202. static const char* bench_result_words3[][5] = {
  1203. /* 0 English */
  1204. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1205. /* TODO: Add japenese version */
  1206. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1207. };
  1208. #endif
  1209. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1210. #define HAVE_GET_CYCLES
  1211. static WC_INLINE word64 get_intel_cycles(void);
  1212. static THREAD_LS_T word64 total_cycles;
  1213. #define INIT_CYCLE_COUNTER
  1214. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1215. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1216. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1217. #define SHOW_INTEL_CYCLES(b, n, s) \
  1218. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1219. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1220. bench_result_words1[lng_index][2], \
  1221. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1222. (double)total_cycles / ((word64)count*(s))))
  1223. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1224. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1225. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1226. (double)total_cycles / ((word64)count*(s))))
  1227. #elif defined(LINUX_CYCLE_COUNT)
  1228. #include <linux/perf_event.h>
  1229. #include <sys/syscall.h>
  1230. #include <unistd.h>
  1231. static THREAD_LS_T word64 begin_cycles;
  1232. static THREAD_LS_T word64 total_cycles;
  1233. static THREAD_LS_T int cycles = -1;
  1234. static THREAD_LS_T struct perf_event_attr atr;
  1235. #define INIT_CYCLE_COUNTER do { \
  1236. atr.type = PERF_TYPE_HARDWARE; \
  1237. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1238. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1239. } while (0);
  1240. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1241. #define END_INTEL_CYCLES do { \
  1242. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1243. total_cycles = total_cycles - begin_cycles; \
  1244. } while (0);
  1245. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1246. #define SHOW_INTEL_CYCLES(b, n, s) \
  1247. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1248. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1249. bench_result_words1[lng_index][2], \
  1250. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1251. (count*s)))
  1252. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1253. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1254. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1255. / (count*s)))
  1256. #elif defined(SYNERGY_CYCLE_COUNT)
  1257. #include "hal_data.h"
  1258. static THREAD_LS_T word64 begin_cycles;
  1259. static THREAD_LS_T word64 total_cycles;
  1260. #define INIT_CYCLE_COUNTER
  1261. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1262. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1263. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1264. #define SHOW_INTEL_CYCLES(b, n, s) \
  1265. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1266. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1267. bench_result_words1[lng_index][2], \
  1268. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1269. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1270. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1271. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1272. #elif defined(WOLFSSL_ESPIDF)
  1273. /* TAG for ESP_LOGx() */
  1274. static const char* TAG = "wolfssl_benchmark";
  1275. static THREAD_LS_T word64 begin_cycles = 0;
  1276. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1277. static THREAD_LS_T word64 end_cycles = 0;
  1278. static THREAD_LS_T word64 total_cycles = 0;
  1279. /* the return value, as a global var */
  1280. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1281. /* the last value seen, adjusted for an overflow, as a global var */
  1282. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1283. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1284. /* esp_get_cpu_benchmark_cycles(void):
  1285. *
  1286. * Architecture-independant CPU clock counter.
  1287. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1288. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1289. /* Some vars for debugging, compare ticks to cycles */
  1290. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1291. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1292. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1293. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1294. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1295. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1296. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1297. #if ESP_IDF_VERSION_MAJOR >= 5
  1298. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1299. #define HAVE_GET_CYCLES
  1300. #define INIT_CYCLE_COUNTER do { \
  1301. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1302. esp_cpu_set_cycle_count(0); \
  1303. } while (0);
  1304. #else
  1305. #define HAVE_GET_CYCLES
  1306. #define INIT_CYCLE_COUNTER do { \
  1307. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1308. } while (0);
  1309. #endif
  1310. #define BEGIN_ESP_CYCLES do { \
  1311. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1312. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1313. begin_cycles_ticks = xTaskGetTickCount(); \
  1314. } while (0);
  1315. /* since it rolls over, we have something that will tolerate one */
  1316. #define END_ESP_CYCLES \
  1317. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1318. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1319. end_cycles, \
  1320. begin_cycles \
  1321. ); \
  1322. total_cycles = (end_cycles - begin_cycles);
  1323. #define SHOW_ESP_CYCLES(b, n, s) \
  1324. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1325. " %s = " FLT_FMT_PREC2 "\n", \
  1326. bench_result_words1[lng_index][2], \
  1327. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1328. )
  1329. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1330. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1331. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1332. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1333. /* 64 bit, unisgned, absolute difference
  1334. * used in CPU cycle counter debug calcs. */
  1335. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1336. {
  1337. uint64_t ret;
  1338. ret = (x > y) ? (x - y) : (y - x);
  1339. return ret;
  1340. }
  1341. #endif
  1342. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1343. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1344. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1345. ** at least once during full benchmark tests.
  1346. **
  1347. ** To test timing overflow, add a delay longer than max cycles:
  1348. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1349. */
  1350. uint64_t esp_get_cycle_count_ex()
  1351. {
  1352. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1353. /* unsigned int max = 4,294,967,295 */
  1354. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1355. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1356. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1357. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1358. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1359. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1360. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1361. #endif
  1362. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1363. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1364. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1365. * (current - last) */
  1366. #endif
  1367. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1368. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1369. defined(CONFIG_IDF_TARGET_ESP32C6)
  1370. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1371. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1372. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1373. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1374. #if ESP_IDF_VERSION_MAJOR >= 5
  1375. thisVal = esp_cpu_get_cycle_count();
  1376. #else
  1377. thisVal = cpu_hal_get_cycle_count();
  1378. #endif
  1379. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1380. thisVal = esp_cpu_get_cycle_count();
  1381. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  1382. thisVal = esp_timer_get_time();
  1383. #else
  1384. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1385. * Calling current_time(1) to reset time causes thisVal overflow,
  1386. * on Xtensa, but not on RISC-V architecture. See also, below */
  1387. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1388. #ifndef configCPU_CLOCK_HZ
  1389. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1390. #define configCPU_CLOCK_HZ \
  1391. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1392. #endif
  1393. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1394. thisVal = (uint64_t)xTaskGetTickCount() *
  1395. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1396. #elif defined(__XTENSA__)
  1397. thisVal = esp_cpu_get_cycle_count();
  1398. #else
  1399. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1400. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1401. #endif
  1402. #endif
  1403. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1404. {
  1405. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1406. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1407. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1408. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1409. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1410. ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
  1411. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1412. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1413. }
  1414. #endif
  1415. /* If either thisVal is smaller than last (overflow), and/or the
  1416. * expected value calculated from FreeRTOS tick difference that would
  1417. * have never fit into an unsigned 32 bit integer anyhow... then we
  1418. * need to adjust thisVal to save. */
  1419. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1420. {
  1421. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1422. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1423. **
  1424. ** NOTE for long duration between calls with multiple overflows:
  1425. **
  1426. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1427. **
  1428. ** At this time no single test overflows. This is currently only a
  1429. ** concern for cumulative counts over multiple tests. As long
  1430. ** as well call xthal_get_ccount_ex() with no more than one
  1431. ** overflow CPU tick count, all will be well.
  1432. */
  1433. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1434. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1435. "(%llu < %llu) adding UINT_MAX = %llu.",
  1436. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1437. #endif
  1438. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1439. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1440. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1441. #endif
  1442. /* double check expected diff calc */
  1443. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1444. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1445. expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  1446. * MILLION_VALUE)
  1447. * tickDiff / configTICK_RATE_HZ;
  1448. #else
  1449. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1450. * tickDiff / configTICK_RATE_HZ;
  1451. #endif
  1452. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1453. #endif
  1454. if (expected_diff > UINT_MAX) {
  1455. /* The number of cycles expected from FreeRTOS ticks is
  1456. * greater than the maximum size of an unsigned 32-bit
  1457. * integer, meaning multiple overflows occurred. */
  1458. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1459. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1460. #endif
  1461. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1462. }
  1463. else {
  1464. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1465. }
  1466. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1467. {
  1468. tickBeginDiff = tickCount - begin_cycles_ticks;
  1469. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1470. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1471. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1472. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1473. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1474. }
  1475. #endif
  1476. }
  1477. else {
  1478. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1479. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1480. #endif
  1481. } /* if thisVal adjustment check */
  1482. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1483. if (thisTimerVal < _esp_cpu_timer_last)
  1484. {
  1485. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1486. "adding %ull", UINT_MAX);
  1487. thisTimerVal += (word64)UINT_MAX;
  1488. }
  1489. /* Check an alternate counter using a timer */
  1490. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1491. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1492. /* Adjust our actual returned value that takes into account overflow,
  1493. * increment 64 bit extended total by this 32 bit differential: */
  1494. thisIncrement = (thisVal - _esp_cpu_count_last);
  1495. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1496. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1497. #endif
  1498. /* Add our adjustment, taking into account overflows (see above) */
  1499. _esp_get_cycle_count_ex += thisIncrement;
  1500. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1501. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1502. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1503. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1504. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1505. /* all of this took some time, so reset the "last seen" value
  1506. * for the next measurement. */
  1507. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1508. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1509. defined(CONFIG_IDF_TARGET_ESP32C6)
  1510. {
  1511. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1512. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1513. &_esp_cpu_timer_last));
  1514. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1515. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1516. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1517. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1518. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1519. #if ESP_IDF_VERSION_MAJOR >= 5
  1520. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1521. #else
  1522. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  1523. #endif
  1524. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1525. }
  1526. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1527. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1528. #else
  1529. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1530. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1531. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1532. * or thisVal = xthal_get_ccount(); */
  1533. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1534. /* There's no CPU counter on the ESP8266, so we'll estimate
  1535. * cycles based on defined CPU frequency from sdkconfig and
  1536. * the RTOS tick frequency */
  1537. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1538. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1539. #elif ESP_IDF_VERSION_MAJOR < 5
  1540. _esp_cpu_count_last = xthal_get_ccount();
  1541. #else
  1542. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1543. #endif
  1544. #endif
  1545. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1546. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1547. #endif
  1548. /* Return the 64 bit extended total from 32 bit counter. */
  1549. return _esp_get_cycle_count_ex;
  1550. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1551. /* implement other architecture cycle counters here */
  1552. #else
  1553. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1554. #undef HAVE_GET_CYCLES
  1555. #define INIT_CYCLE_COUNTER
  1556. #define BEGIN_INTEL_CYCLES
  1557. #define END_INTEL_CYCLES
  1558. #ifdef MULTI_VALUE_STATISTICS
  1559. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1560. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1561. #else
  1562. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1563. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1564. #endif
  1565. #endif
  1566. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1567. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1568. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1569. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1570. #endif
  1571. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1572. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1573. !defined(NO_DH)
  1574. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1575. #include <wolfssl/certs_test.h>
  1576. #endif
  1577. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1578. #include <wolfssl/wolfcrypt/blake2.h>
  1579. #endif
  1580. #ifdef _MSC_VER
  1581. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1582. #pragma warning(disable: 4996)
  1583. #endif
  1584. #ifdef WOLFSSL_CURRTIME_REMAP
  1585. #define current_time WOLFSSL_CURRTIME_REMAP
  1586. #else
  1587. double current_time(int reset);
  1588. #endif
  1589. #ifdef LINUX_RUSAGE_UTIME
  1590. static void check_for_excessive_stime(const char *desc,
  1591. const char *desc_extra);
  1592. #endif
  1593. #if !defined(WC_NO_RNG) && \
  1594. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1595. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1596. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1597. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1598. || defined(WOLFSSL_HAVE_KYBER))
  1599. #define HAVE_LOCAL_RNG
  1600. static THREAD_LS_T WC_RNG gRng;
  1601. #define GLOBAL_RNG &gRng
  1602. #else
  1603. #define GLOBAL_RNG NULL
  1604. #endif
  1605. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1606. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1607. defined(HAVE_ECC) || !defined(NO_DH) || \
  1608. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1609. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1610. defined(WOLFSSL_HAVE_LMS)
  1611. #define BENCH_ASYM
  1612. #endif
  1613. #if defined(BENCH_ASYM)
  1614. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1615. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1616. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1617. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1618. defined(WOLFSSL_HAVE_LMS)
  1619. static const char* bench_result_words2[][5] = {
  1620. #ifdef BENCH_MICROSECOND
  1621. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1622. for μsec */
  1623. #else
  1624. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1625. #endif
  1626. #ifndef NO_MULTIBYTE_PRINT
  1627. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1628. #endif
  1629. };
  1630. #endif
  1631. #endif
  1632. #ifdef WOLFSSL_CAAM
  1633. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1634. #ifdef WOLFSSL_SECO_CAAM
  1635. #define SECO_MAX_UPDATES 10000
  1636. #define SECO_BENCHMARK_NONCE 0x7777
  1637. #define SECO_KEY_STORE_ID 1
  1638. #endif
  1639. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1640. #else
  1641. #ifdef WC_USE_DEVID
  1642. static THREAD_LS_T int devId = WC_USE_DEVID;
  1643. #else
  1644. static THREAD_LS_T int devId = INVALID_DEVID;
  1645. #endif
  1646. #endif
  1647. /* Asynchronous helper macros */
  1648. #ifdef WC_ENABLE_BENCH_THREADING
  1649. typedef struct ThreadData {
  1650. pthread_t thread_id;
  1651. } ThreadData;
  1652. static ThreadData* g_threadData;
  1653. static volatile int g_threadCount;
  1654. #endif
  1655. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1656. #ifndef NO_HW_BENCH
  1657. #define BENCH_DEVID
  1658. #endif
  1659. #ifndef HAVE_RENESAS_SYNC
  1660. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1661. #else
  1662. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1663. #endif
  1664. #else
  1665. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1666. #endif
  1667. #ifdef WOLFSSL_ASYNC_CRYPT
  1668. static WOLF_EVENT_QUEUE eventQueue;
  1669. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1670. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1671. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1672. int callAgain, int* times, int limit, int* pending)
  1673. {
  1674. int allowNext = 0;
  1675. /* this state can be set from a different thread */
  1676. WOLF_EVENT_STATE state = asyncDev->event.state;
  1677. /* if algo doesn't require calling again then use this flow */
  1678. if (state == WOLF_EVENT_STATE_DONE) {
  1679. if (callAgain) {
  1680. /* needs called again, so allow it and handle completion in
  1681. * bench_async_handle */
  1682. allowNext = 1;
  1683. }
  1684. else {
  1685. *ret = asyncDev->event.ret;
  1686. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1687. (*times)++;
  1688. if (*pending > 0) /* to support case where async blocks */
  1689. (*pending)--;
  1690. if ((*times + *pending) < limit)
  1691. allowNext = 1;
  1692. }
  1693. }
  1694. /* if slot is available and we haven't reached limit, start another */
  1695. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1696. allowNext = 1;
  1697. }
  1698. return allowNext;
  1699. }
  1700. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1701. int callAgain, int* times, int* pending)
  1702. {
  1703. WOLF_EVENT_STATE state = asyncDev->event.state;
  1704. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1705. if (state == WOLF_EVENT_STATE_DONE) {
  1706. *ret = asyncDev->event.ret;
  1707. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1708. (*times)++;
  1709. (*pending)--;
  1710. }
  1711. else {
  1712. (*pending)++;
  1713. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1714. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1715. }
  1716. }
  1717. else if (*ret >= 0) {
  1718. *ret = asyncDev->event.ret;
  1719. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1720. (*times)++;
  1721. if (*pending > 0) /* to support case where async blocks */
  1722. (*pending)--;
  1723. }
  1724. return (*ret >= 0) ? 1 : 0;
  1725. }
  1726. static WC_INLINE int bench_async_poll(int* pending)
  1727. {
  1728. int ret, asyncDone = 0;
  1729. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1730. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1731. if (ret != 0) {
  1732. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1733. return ret;
  1734. }
  1735. if (asyncDone == 0) {
  1736. #ifndef WC_NO_ASYNC_THREADING
  1737. /* give time to other threads */
  1738. wc_AsyncThreadYield();
  1739. #endif
  1740. }
  1741. (void)pending;
  1742. return asyncDone;
  1743. }
  1744. #else
  1745. #define BENCH_MAX_PENDING 1
  1746. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1747. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1748. int callAgain, int* times, int limit, int* pending)
  1749. {
  1750. (void)ret;
  1751. (void)asyncDev;
  1752. (void)callAgain;
  1753. (void)times;
  1754. (void)limit;
  1755. (void)pending;
  1756. return 1;
  1757. }
  1758. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1759. int callAgain, int* times, int* pending)
  1760. {
  1761. (void)asyncDev;
  1762. (void)callAgain;
  1763. (void)pending;
  1764. if (*ret >= 0) {
  1765. /* operation completed */
  1766. (*times)++;
  1767. return 1;
  1768. }
  1769. return 0;
  1770. }
  1771. #define bench_async_poll(p) WC_DO_NOTHING
  1772. #endif /* WOLFSSL_ASYNC_CRYPT */
  1773. /* maximum runtime for each benchmark */
  1774. #ifndef BENCH_MIN_RUNTIME_SEC
  1775. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1776. #endif
  1777. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1778. #define AES_AUTH_TAG_SZ 16
  1779. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1780. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1781. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1782. #if !defined(NO_MAIN_DRIVER)
  1783. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1784. #else
  1785. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1786. #endif
  1787. #endif
  1788. #define AES_AAD_STRING(s) \
  1789. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1790. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1791. enum en_aad_options {
  1792. AAD_SIZE_DEFAULT = 0x1U,
  1793. AAD_SIZE_ZERO = 0x2U,
  1794. AAD_SIZE_CUSTOM = 0x4U,
  1795. };
  1796. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1797. static word32 aes_aad_size = 0;
  1798. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1799. {
  1800. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1801. word32 options = aes_aad_options;
  1802. while(options) {
  1803. if (options & AAD_SIZE_DEFAULT) {
  1804. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1805. options &= ~(word32)AAD_SIZE_DEFAULT;
  1806. }
  1807. else if (options & AAD_SIZE_ZERO) {
  1808. aesAuthAddSz = 0;
  1809. options &= ~(word32)AAD_SIZE_ZERO;
  1810. }
  1811. else if (options & AAD_SIZE_CUSTOM) {
  1812. aesAuthAddSz = aes_aad_size;
  1813. options &= ~(word32)AAD_SIZE_CUSTOM;
  1814. }
  1815. fn(i);
  1816. aesAuthAddSz = aesAuthAddSz_orig;
  1817. }
  1818. }
  1819. #endif
  1820. #ifndef BENCH_CIPHER_ADD
  1821. #define BENCH_CIPHER_ADD 0
  1822. #endif
  1823. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  1824. #warning Large/Unalligned AuthSz could result in errors with /dev/crypto
  1825. #endif
  1826. /* use kB instead of mB for embedded benchmarking */
  1827. #ifdef BENCH_EMBEDDED
  1828. #ifndef BENCH_NTIMES
  1829. #define BENCH_NTIMES 2
  1830. #endif
  1831. #ifndef BENCH_AGREETIMES
  1832. #define BENCH_AGREETIMES 2
  1833. #endif
  1834. enum BenchmarkBounds {
  1835. scryptCnt = 1,
  1836. ntimes = BENCH_NTIMES,
  1837. genTimes = BENCH_MAX_PENDING,
  1838. agreeTimes = BENCH_AGREETIMES
  1839. };
  1840. /* how many kB to test (en/de)cryption */
  1841. #define NUM_BLOCKS 25
  1842. #define BENCH_SIZE (1024uL)
  1843. #else
  1844. #ifndef BENCH_NTIMES
  1845. #define BENCH_NTIMES 100
  1846. #endif
  1847. #ifndef BENCH_AGREETIMES
  1848. #define BENCH_AGREETIMES 100
  1849. #endif
  1850. enum BenchmarkBounds {
  1851. scryptCnt = 10,
  1852. ntimes = BENCH_NTIMES,
  1853. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1854. agreeTimes = BENCH_AGREETIMES
  1855. };
  1856. /* how many megs to test (en/de)cryption */
  1857. #define NUM_BLOCKS 5
  1858. #define BENCH_SIZE (1024*1024uL)
  1859. #endif
  1860. static int numBlocks = NUM_BLOCKS;
  1861. static word32 bench_size = BENCH_SIZE;
  1862. static int base2 = 1;
  1863. static int digest_stream = 1;
  1864. #ifdef HAVE_CHACHA
  1865. static int encrypt_only = 0;
  1866. #endif
  1867. #ifdef HAVE_AES_CBC
  1868. static int cipher_same_buffer = 0;
  1869. #endif
  1870. #ifdef MULTI_VALUE_STATISTICS
  1871. static int minimum_runs = 0;
  1872. #endif
  1873. #ifndef NO_RSA
  1874. /* Don't measure RSA sign/verify by default */
  1875. static int rsa_sign_verify = 0;
  1876. #endif
  1877. #ifndef NO_DH
  1878. /* Use the FFDHE parameters */
  1879. static int use_ffdhe = 0;
  1880. #endif
  1881. /* Don't print out in CSV format by default */
  1882. static int csv_format = 0;
  1883. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1884. /* Versal PLM maybe prints an error message to the same console.
  1885. * In order to not mix those outputs up, sleep a little while
  1886. * before erroring out.
  1887. */
  1888. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1889. #else
  1890. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1891. #endif
  1892. /* globals for cipher tests */
  1893. static THREAD_LS_T byte* bench_plain = NULL;
  1894. static THREAD_LS_T byte* bench_cipher = NULL;
  1895. #ifndef NO_FILESYSTEM
  1896. static THREAD_LS_T char* hash_input = NULL;
  1897. static THREAD_LS_T char* cipher_input = NULL;
  1898. #endif
  1899. static const XGEN_ALIGN byte bench_key_buf[] =
  1900. {
  1901. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1902. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1903. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1904. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1905. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1906. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1907. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1908. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1909. };
  1910. static const XGEN_ALIGN byte bench_iv_buf[] =
  1911. {
  1912. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1913. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1914. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1915. };
  1916. static THREAD_LS_T byte* bench_key = NULL;
  1917. static THREAD_LS_T byte* bench_iv = NULL;
  1918. #ifdef HAVE_RENESAS_SYNC
  1919. static THREAD_LS_T byte* bench_key1 = NULL;
  1920. static THREAD_LS_T byte* bench_key2 = NULL;
  1921. #endif
  1922. #ifdef WOLFSSL_STATIC_MEMORY
  1923. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1924. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1925. #elif defined(BENCH_EMBEDDED)
  1926. static byte gBenchMemory[50000];
  1927. #else
  1928. static byte gBenchMemory[400000];
  1929. #endif
  1930. #endif
  1931. /* This code handles cases with systems where static (non cost) ram variables
  1932. aren't properly initialized with data */
  1933. static void benchmark_static_init(int force)
  1934. {
  1935. static int gBenchStaticInit = 0;
  1936. if (gBenchStaticInit == 0 || force) {
  1937. gBenchStaticInit = 1;
  1938. /* Init static variables */
  1939. numBlocks = NUM_BLOCKS;
  1940. bench_size = BENCH_SIZE;
  1941. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1942. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1943. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1944. aes_aad_size = 0;
  1945. #endif
  1946. base2 = 1;
  1947. digest_stream = 1;
  1948. #ifdef MULTI_VALUE_STATISTICS
  1949. minimum_runs = 0;
  1950. #endif
  1951. bench_all = 1;
  1952. bench_cipher_algs = 0;
  1953. bench_digest_algs = 0;
  1954. bench_mac_algs = 0;
  1955. bench_kdf_algs = 0;
  1956. bench_asym_algs = 0;
  1957. bench_pq_asym_algs = 0;
  1958. bench_other_algs = 0;
  1959. bench_pq_hash_sig_algs = 0;
  1960. csv_format = 0;
  1961. }
  1962. }
  1963. /*****************************************************************************/
  1964. /* Begin Stats Functions */
  1965. /*****************************************************************************/
  1966. typedef enum bench_stat_type {
  1967. BENCH_STAT_ASYM,
  1968. BENCH_STAT_SYM,
  1969. BENCH_STAT_IGNORE,
  1970. } bench_stat_type_t;
  1971. #ifdef WC_BENCH_TRACK_STATS
  1972. static int gPrintStats = 0;
  1973. #ifdef WC_ENABLE_BENCH_THREADING
  1974. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1975. #endif
  1976. #ifndef BENCH_MAX_NAME_SZ
  1977. #define BENCH_MAX_NAME_SZ 24
  1978. #endif
  1979. typedef struct bench_stats {
  1980. struct bench_stats* next;
  1981. struct bench_stats* prev;
  1982. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1983. const char* desc;
  1984. double perfsec;
  1985. int strength;
  1986. int useDeviceID;
  1987. int finishCount;
  1988. bench_stat_type_t type;
  1989. int lastRet;
  1990. const char* perftype;
  1991. } bench_stats_t;
  1992. static bench_stats_t* bench_stats_head;
  1993. static bench_stats_t* bench_stats_tail;
  1994. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1995. const char* algo, int strength, const char* desc, int useDeviceID,
  1996. double perfsec, const char* perftype, int ret)
  1997. {
  1998. bench_stats_t* bstat = NULL;
  1999. #ifdef WC_ENABLE_BENCH_THREADING
  2000. /* protect bench_stats_head and bench_stats_tail access */
  2001. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2002. #endif
  2003. if (algo != NULL) {
  2004. /* locate existing in list */
  2005. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  2006. /* match based on algo, strength and desc */
  2007. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  2008. bstat->strength == strength &&
  2009. bstat->desc == desc &&
  2010. bstat->useDeviceID == useDeviceID) {
  2011. break;
  2012. }
  2013. }
  2014. }
  2015. if (bstat == NULL) {
  2016. /* allocate new and put on list */
  2017. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  2018. DYNAMIC_TYPE_INFO);
  2019. if (bstat) {
  2020. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  2021. /* add to list */
  2022. bstat->next = NULL;
  2023. if (bench_stats_tail == NULL) {
  2024. bench_stats_head = bstat;
  2025. }
  2026. else {
  2027. bench_stats_tail->next = bstat;
  2028. bstat->prev = bench_stats_tail;
  2029. }
  2030. bench_stats_tail = bstat; /* add to the end either way */
  2031. }
  2032. }
  2033. if (bstat) {
  2034. bstat->type = type;
  2035. if (algo != NULL)
  2036. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  2037. bstat->strength = strength;
  2038. bstat->desc = desc;
  2039. bstat->useDeviceID = useDeviceID;
  2040. bstat->perfsec += perfsec;
  2041. bstat->finishCount++;
  2042. bstat->perftype = perftype;
  2043. if (bstat->lastRet > ret)
  2044. bstat->lastRet = ret; /* track last error */
  2045. }
  2046. #ifdef WC_ENABLE_BENCH_THREADING
  2047. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2048. #endif
  2049. return bstat;
  2050. }
  2051. void bench_stats_print(void)
  2052. {
  2053. bench_stats_t* bstat;
  2054. int digits;
  2055. #ifdef WC_ENABLE_BENCH_THREADING
  2056. /* protect bench_stats_head and bench_stats_tail access */
  2057. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2058. #endif
  2059. #ifdef BENCH_MICROSECOND
  2060. digits = 5;
  2061. #else
  2062. digits = 3;
  2063. #endif
  2064. for (bstat = bench_stats_head; bstat != NULL; ) {
  2065. if (bstat->type == BENCH_STAT_SYM) {
  2066. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2067. "\n", bstat->desc,
  2068. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2069. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2070. base2 ? "MB" : "mB");
  2071. }
  2072. else {
  2073. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2074. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2075. bstat->algo, bstat->strength, bstat->desc,
  2076. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2077. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2078. }
  2079. bstat = bstat->next;
  2080. }
  2081. #ifdef WC_ENABLE_BENCH_THREADING
  2082. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2083. #endif
  2084. }
  2085. #endif /* WC_BENCH_TRACK_STATS */
  2086. static WC_INLINE void bench_stats_init(void)
  2087. {
  2088. #ifdef WC_BENCH_TRACK_STATS
  2089. bench_stats_head = NULL;
  2090. bench_stats_tail = NULL;
  2091. #endif
  2092. INIT_CYCLE_COUNTER
  2093. }
  2094. static WC_INLINE void bench_stats_start(int* count, double* start)
  2095. {
  2096. *count = 0;
  2097. *start = current_time(1);
  2098. #ifdef WOLFSSL_ESPIDF
  2099. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2100. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
  2101. ", start=" FLT_FMT,
  2102. total_cycles, FLT_FMT_ARGS(*start) );
  2103. #endif
  2104. BEGIN_ESP_CYCLES
  2105. #else
  2106. BEGIN_INTEL_CYCLES
  2107. #endif
  2108. }
  2109. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2110. #define bench_stats_start(count, start) do { \
  2111. SAVE_VECTOR_REGISTERS(pr_err( \
  2112. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2113. return; ); \
  2114. bench_stats_start(count, start); \
  2115. } while (0)
  2116. #endif
  2117. static WC_INLINE int bench_stats_check(double start)
  2118. {
  2119. int ret = 0;
  2120. double this_current_time = 0.0;
  2121. this_current_time = current_time(0); /* get the timestamp, no reset */
  2122. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2123. #if defined(WOLFSSL_ESPIDF)
  2124. ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
  2125. this_current_time, start );
  2126. #endif
  2127. #endif
  2128. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2129. #ifdef BENCH_MICROSECOND
  2130. * 1000000
  2131. #endif
  2132. );
  2133. return ret;
  2134. }
  2135. /* return text for units and scale the value of blocks as needed */
  2136. static const char* get_blocktype(double* blocks)
  2137. {
  2138. const char* rt;
  2139. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2140. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2141. #undef WOLFSSL_FIXED_UNIT
  2142. #define WOLFSSL_FIXED_UNIT "GB"
  2143. *blocks /= (1024UL * 1024UL * 1024UL);
  2144. rt = "GiB";
  2145. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2146. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2147. #undef WOLFSSL_FIXED_UNIT
  2148. #define WOLFSSL_FIXED_UNIT "MB"
  2149. *blocks /= (1024UL * 1024UL);
  2150. rt = "MiB";
  2151. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2152. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2153. #undef WOLFSSL_FIXED_UNIT
  2154. #define WOLFSSL_FIXED_UNIT "KB"
  2155. *blocks /= 1024;
  2156. rt = "KiB";
  2157. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2158. #undef WOLFSSL_FIXED_UNIT
  2159. #define WOLFSSL_FIXED_UNIT "bytes"
  2160. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2161. rt = "bytes";
  2162. #else
  2163. /* If no user-specified, auto-scale each metric (results vary).
  2164. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2165. if (*blocks > (1024UL * 1024UL)) {
  2166. *blocks /= (1024UL * 1024UL);
  2167. rt = "MiB";
  2168. }
  2169. else if (*blocks > 1024) {
  2170. *blocks /= 1024;
  2171. rt = "KiB";
  2172. }
  2173. else {
  2174. rt = "bytes";
  2175. }
  2176. #endif
  2177. return rt;
  2178. }
  2179. /* return text for units and scale the value of blocks as needed for base2 */
  2180. static const char* get_blocktype_base10(double* blocks)
  2181. {
  2182. const char* rt;
  2183. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2184. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2185. *blocks /= (1000UL * 1000UL * 1000UL);
  2186. rt = "GB";
  2187. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2188. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2189. *blocks /= (1000UL * 1000UL);
  2190. rt = "MB";
  2191. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2192. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2193. *blocks /= (1000UL);
  2194. rt = "KB";
  2195. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2196. (void)(*blocks); /* no adjustment, just appease compiler */
  2197. rt = "bytes";
  2198. #else
  2199. /* If not user-specified, auto-scale each metric (results vary).
  2200. * Determine if we should show as KB or MB or bytes */
  2201. if (*blocks > (1000UL * 1000UL)) {
  2202. *blocks /= (1000UL * 1000UL);
  2203. rt = "MB";
  2204. }
  2205. else if (*blocks > 1000) {
  2206. *blocks /= 1000; /* make KB */
  2207. rt = "KB";
  2208. }
  2209. else {
  2210. rt = "bytes";
  2211. }
  2212. #endif
  2213. return rt;
  2214. }
  2215. #ifdef MULTI_VALUE_STATISTICS
  2216. static double wc_sqroot(double in)
  2217. {
  2218. /* do 32 iterations for the sqroot */
  2219. int iter = 32;
  2220. double root = in/3.0;
  2221. if (in < 0.0)
  2222. return -1;
  2223. for (int i=0; i < iter; i++)
  2224. root = (root + in / root) / 2.0;
  2225. return root;
  2226. }
  2227. static void bench_multi_value_stats(double max, double min, double sum,
  2228. double squareSum, int runs)
  2229. {
  2230. double mean = 0;
  2231. double sd = 0;
  2232. char msg[WC_BENCH_MAX_LINE_LEN];
  2233. const char** word = bench_result_words3[lng_index];
  2234. XMEMSET(msg, 0, sizeof(msg));
  2235. mean = sum / runs;
  2236. /* Calculating standard deviation */
  2237. sd = (squareSum / runs) - (mean * mean);
  2238. sd = wc_sqroot(sd);
  2239. if (csv_format == 1) {
  2240. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2241. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2242. FLT_FMT_PREC2_ARGS(3, 3, max),
  2243. FLT_FMT_PREC2_ARGS(3, 3, min),
  2244. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2245. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2246. }
  2247. else{
  2248. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2249. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2250. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2251. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2252. WOLFSSL_FIXED_TIME_UNIT "\n",
  2253. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2254. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2255. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2256. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2257. }
  2258. printf("%s", msg);
  2259. #ifndef WOLFSSL_SGX
  2260. XFFLUSH(stdout);
  2261. #endif
  2262. }
  2263. #endif
  2264. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2265. * except for AES direct that operates on WC_AES_BLOCK_SIZE blocks */
  2266. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2267. int count, word32 countSz,
  2268. double start, int ret)
  2269. {
  2270. double total, persec = 0, blocks = (double)count;
  2271. const char* blockType;
  2272. char msg[WC_BENCH_MAX_LINE_LEN];
  2273. const char** word = bench_result_words1[lng_index];
  2274. static int sym_header_printed = 0;
  2275. XMEMSET(msg, 0, sizeof(msg));
  2276. #ifdef WOLFSSL_ESPIDF
  2277. END_ESP_CYCLES
  2278. #else
  2279. END_INTEL_CYCLES
  2280. #endif
  2281. total = current_time(0) - start;
  2282. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2283. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2284. #endif
  2285. #ifdef LINUX_RUSAGE_UTIME
  2286. check_for_excessive_stime(desc, "");
  2287. #endif
  2288. /* calculate actual bytes */
  2289. blocks *= countSz;
  2290. if (csv_format == 1) {
  2291. /* only print out header once */
  2292. if (sym_header_printed == 0) {
  2293. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2294. /* machine parseable CSV */
  2295. #ifdef HAVE_GET_CYCLES
  2296. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2297. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2298. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2299. ",cycles_total,Cycles per byte,");
  2300. #else
  2301. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2302. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2303. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2304. ",cycles_total,");
  2305. #endif
  2306. #else
  2307. /* normal CSV */
  2308. #ifdef BENCH_DEVID
  2309. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2310. #else
  2311. #define BENCH_DEVID_COLUMN_HEADER
  2312. #endif
  2313. #ifdef HAVE_GET_CYCLES
  2314. printf("\n\nSymmetric Ciphers:\n\n");
  2315. printf("Algorithm,"
  2316. BENCH_DEVID_COLUMN_HEADER
  2317. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2318. ",Cycles per byte,");
  2319. #else
  2320. printf("\n\nSymmetric Ciphers:\n\n");
  2321. printf("Algorithm,"
  2322. BENCH_DEVID_COLUMN_HEADER
  2323. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2324. #endif
  2325. #endif
  2326. #ifdef MULTI_VALUE_STATISTICS
  2327. printf("max duration,min duration,mean duration,sd,\n");
  2328. #else
  2329. printf("\n");
  2330. #endif
  2331. sym_header_printed = 1;
  2332. }
  2333. }
  2334. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2335. * note that the blockType text is assigned AND the blocks param is scaled.
  2336. */
  2337. if (base2) {
  2338. blockType = get_blocktype(&blocks);
  2339. }
  2340. else {
  2341. blockType = get_blocktype_base10(&blocks);
  2342. }
  2343. /* calculate blocks per second */
  2344. if (total > 0) {
  2345. persec = (1 / total) * blocks;
  2346. }
  2347. SLEEP_ON_ERROR(ret);
  2348. /* format and print to terminal */
  2349. if (csv_format == 1) {
  2350. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2351. #ifdef WOLFSSL_ESPIDF
  2352. unsigned long bytes_processed =
  2353. (unsigned long)count * (unsigned long)countSz;
  2354. #else
  2355. word64 bytes_processed = (word64)count * (word64)countSz;
  2356. #endif
  2357. /* note this codepath brings in all the fields from the non-CSV case. */
  2358. #ifdef WOLFSSL_ESPIDF
  2359. #ifdef HAVE_GET_CYCLES
  2360. (void)XSNPRINTF(msg, sizeof(msg),
  2361. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2362. BENCH_DEVID_GET_NAME(useDeviceID),
  2363. bytes_processed, FLT_FMT_ARGS(total),
  2364. FLT_FMT_ARGS(persec),
  2365. (long unsigned int) total_cycles);
  2366. #else
  2367. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2368. #endif
  2369. /* implement other architectures here */
  2370. #else
  2371. #ifdef HAVE_GET_CYCLES
  2372. (void)XSNPRINTF(msg, sizeof(msg),
  2373. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2374. BENCH_DEVID_GET_NAME(useDeviceID),
  2375. bytes_processed, FLT_FMT_ARGS(total),
  2376. FLT_FMT_ARGS(persec), total_cycles);
  2377. #else
  2378. (void)XSNPRINTF(msg, sizeof(msg),
  2379. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2380. BENCH_DEVID_GET_NAME(useDeviceID),
  2381. bytes_processed, FLT_FMT_ARGS(total),
  2382. FLT_FMT_ARGS(persec));
  2383. #endif
  2384. #endif
  2385. #elif defined(BENCH_DEVID)
  2386. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2387. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2388. #else
  2389. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2390. FLT_FMT_ARGS(persec));
  2391. #endif
  2392. #ifdef WOLFSSL_ESPIDF
  2393. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2394. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2395. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2396. total_cycles);
  2397. #endif
  2398. /* implement other cycle counters here */
  2399. #else
  2400. /* the default cycle counter is Intel */
  2401. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2402. #endif
  2403. } /* if (csv_format == 1) */
  2404. else {
  2405. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2406. #ifdef HAVE_GET_CYCLES
  2407. (void)XSNPRINTF(msg, sizeof(msg),
  2408. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2409. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2410. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2411. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2412. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2413. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2414. (unsigned long) total_cycles);
  2415. #else
  2416. (void)XSNPRINTF(msg, sizeof(msg),
  2417. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2418. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2419. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2420. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2421. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2422. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2423. #endif /* HAVE_GET_CYCLES */
  2424. #else
  2425. (void)XSNPRINTF(msg, sizeof(msg),
  2426. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2427. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2428. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2429. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2430. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2431. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2432. #endif
  2433. #ifdef WOLFSSL_ESPIDF
  2434. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2435. /* implement other architecture cycle counters here */
  2436. #else
  2437. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2438. #endif
  2439. } /* not CSV format */
  2440. printf("%s", msg);
  2441. /* show errors */
  2442. if (ret < 0) {
  2443. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2444. }
  2445. #ifndef WOLFSSL_SGX
  2446. XFFLUSH(stdout);
  2447. #endif
  2448. #ifdef WC_BENCH_TRACK_STATS
  2449. /* Add to thread stats */
  2450. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2451. blockType, ret);
  2452. #endif
  2453. (void)useDeviceID;
  2454. (void)ret;
  2455. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2456. RESTORE_VECTOR_REGISTERS();
  2457. #endif
  2458. TEST_SLEEP();
  2459. } /* bench_stats_sym_finish */
  2460. #ifdef BENCH_ASYM
  2461. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2462. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2463. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2464. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  2465. defined(WOLFSSL_HAVE_LMS)
  2466. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2467. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2468. double start, int ret)
  2469. {
  2470. double total, each = 0, opsSec, milliEach;
  2471. const char **word = bench_result_words2[lng_index];
  2472. #ifdef WC_BENCH_TRACK_STATS
  2473. const char* kOpsSec = "Ops/Sec";
  2474. #endif
  2475. char msg[256];
  2476. static int asym_header_printed = 0;
  2477. #ifdef BENCH_MICROSECOND
  2478. const int digits = 5;
  2479. #else
  2480. const int digits = 3;
  2481. #endif
  2482. XMEMSET(msg, 0, sizeof(msg));
  2483. total = current_time(0) - start;
  2484. #ifdef LINUX_RUSAGE_UTIME
  2485. check_for_excessive_stime(desc, desc_extra);
  2486. #endif
  2487. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2488. #ifdef WOLFSSL_ESPIDF
  2489. END_ESP_CYCLES
  2490. #else
  2491. END_INTEL_CYCLES
  2492. #endif
  2493. #endif
  2494. /* some sanity checks on the final numbers */
  2495. if (count > 0) {
  2496. each = total / count; /* per second */
  2497. }
  2498. else {
  2499. count = 0;
  2500. each = 0;
  2501. }
  2502. if (total > 0) {
  2503. opsSec = count / total; /* ops second */
  2504. }
  2505. else {
  2506. opsSec = 0;
  2507. }
  2508. #ifdef BENCH_MICROSECOND
  2509. milliEach = each / 1000; /* milliseconds */
  2510. #else
  2511. milliEach = each * 1000; /* milliseconds */
  2512. #endif
  2513. SLEEP_ON_ERROR(ret);
  2514. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2515. (void)milliEach;
  2516. /* format and print to terminal */
  2517. if (csv_format == 1) {
  2518. /* only print out header once */
  2519. if (asym_header_printed == 0) {
  2520. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2521. #ifdef HAVE_GET_CYCLES
  2522. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2523. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2524. "ecs,cycles,cycles/op,");
  2525. #else
  2526. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2527. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2528. "ecs,");
  2529. #endif
  2530. #else
  2531. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2532. printf("%sAlgorithm,key size,operation,ops/"
  2533. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2534. #endif
  2535. printf("max duration,min duration,mean duration,sd,\n");
  2536. asym_header_printed = 1;
  2537. }
  2538. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2539. #ifdef HAVE_GET_CYCLES
  2540. (void)XSNPRINTF(msg, sizeof(msg),
  2541. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2542. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2543. algo, strength, desc, desc_extra,
  2544. FLT_FMT_PREC_ARGS(digits, opsSec),
  2545. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2546. FLT_FMT_PREC_ARGS(6,
  2547. (double)total_cycles / (double)count));
  2548. #else
  2549. (void)XSNPRINTF(msg, sizeof(msg),
  2550. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2551. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2552. algo, strength, desc, desc_extra,
  2553. FLT_FMT_PREC_ARGS(digits, opsSec),
  2554. count, FLT_FMT_ARGS(total));
  2555. #endif
  2556. #else
  2557. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2558. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2559. algo, strength, desc, desc_extra,
  2560. FLT_FMT_PREC_ARGS(digits, opsSec));
  2561. #endif
  2562. } /* if (csv_format == 1) */
  2563. else {
  2564. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2565. #ifdef HAVE_GET_CYCLES
  2566. (void)XSNPRINTF(msg, sizeof(msg),
  2567. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2568. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2569. algo, strength, desc, desc_extra,
  2570. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2571. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2572. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2573. (unsigned long)total_cycles);
  2574. #else
  2575. (void)XSNPRINTF(msg, sizeof(msg),
  2576. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2577. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2578. algo, strength, desc, desc_extra,
  2579. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2580. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2581. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2582. #endif /* HAVE_GET_CYCLES */
  2583. #else
  2584. (void)XSNPRINTF(msg, sizeof(msg),
  2585. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2586. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2587. algo, strength, desc, desc_extra,
  2588. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2589. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2590. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2591. #endif
  2592. }
  2593. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2594. /* format and print to terminal */
  2595. if (csv_format == 1) {
  2596. /* only print out header once */
  2597. if (asym_header_printed == 0) {
  2598. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2599. #ifdef HAVE_GET_CYCLES
  2600. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2601. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2602. "ecs,cycles,cycles/op,");
  2603. #else
  2604. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2605. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2606. "ecs,");
  2607. #endif
  2608. #else
  2609. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2610. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2611. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2612. #endif
  2613. printf("\n");
  2614. asym_header_printed = 1;
  2615. }
  2616. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2617. #ifdef HAVE_GET_CYCLES
  2618. (void)XSNPRINTF(msg, sizeof(msg),
  2619. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2620. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2621. algo, strength, desc, desc_extra,
  2622. FLT_FMT_PREC_ARGS(3, milliEach),
  2623. FLT_FMT_PREC_ARGS(digits, opsSec),
  2624. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2625. FLT_FMT_PREC_ARGS(6,
  2626. (double)total_cycles / (double)count));
  2627. #else
  2628. (void)XSNPRINTF(msg, sizeof(msg),
  2629. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2630. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2631. algo, strength, desc, desc_extra,
  2632. FLT_FMT_PREC_ARGS(3, milliEach),
  2633. FLT_FMT_PREC_ARGS(digits, opsSec),
  2634. count, FLT_FMT_ARGS(total));
  2635. #endif
  2636. #else
  2637. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2638. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2639. algo, strength, desc, desc_extra,
  2640. FLT_FMT_PREC_ARGS(3, milliEach),
  2641. FLT_FMT_PREC_ARGS(digits, opsSec));
  2642. #endif
  2643. } /* if (csv_format == 1) */
  2644. else {
  2645. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2646. #ifdef HAVE_GET_CYCLES
  2647. (void)XSNPRINTF(msg, sizeof(msg),
  2648. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2649. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2650. STATS_CLAUSE_SEPARATOR,
  2651. algo, strength, desc, desc_extra,
  2652. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2653. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2654. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2655. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2656. (unsigned long)total_cycles);
  2657. #else
  2658. (void)XSNPRINTF(msg, sizeof(msg),
  2659. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2660. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2661. STATS_CLAUSE_SEPARATOR,
  2662. algo, strength, desc, desc_extra,
  2663. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2664. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2665. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2666. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2667. #endif /* HAVE_GET_CYCLES */
  2668. #else
  2669. (void)XSNPRINTF(msg, sizeof(msg),
  2670. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2671. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2672. STATS_CLAUSE_SEPARATOR,
  2673. algo, strength, desc, desc_extra,
  2674. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2675. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2676. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2677. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2678. #endif
  2679. }
  2680. #endif /* MULTI_VALUE_STATISTICS */
  2681. printf("%s", msg);
  2682. /* show errors */
  2683. if (ret < 0) {
  2684. printf("%sBenchmark %s %s %d failed: %d\n",
  2685. err_prefix, algo, desc, strength, ret);
  2686. }
  2687. #ifndef WOLFSSL_SGX
  2688. XFFLUSH(stdout);
  2689. #endif
  2690. #ifdef WC_BENCH_TRACK_STATS
  2691. /* Add to thread stats */
  2692. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2693. kOpsSec, ret);
  2694. #endif
  2695. (void)useDeviceID;
  2696. (void)ret;
  2697. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2698. RESTORE_VECTOR_REGISTERS();
  2699. #endif
  2700. TEST_SLEEP();
  2701. } /* bench_stats_asym_finish_ex */
  2702. static void bench_stats_asym_finish(const char* algo, int strength,
  2703. const char* desc, int useDeviceID, int count, double start, int ret)
  2704. {
  2705. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2706. start, ret);
  2707. }
  2708. #endif
  2709. #endif /* BENCH_ASYM */
  2710. static WC_INLINE void bench_stats_free(void)
  2711. {
  2712. #ifdef WC_BENCH_TRACK_STATS
  2713. bench_stats_t* bstat;
  2714. for (bstat = bench_stats_head; bstat != NULL; ) {
  2715. bench_stats_t* next = bstat->next;
  2716. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2717. bstat = next;
  2718. }
  2719. bench_stats_head = NULL;
  2720. bench_stats_tail = NULL;
  2721. #endif
  2722. }
  2723. /*****************************************************************************/
  2724. /* End Stats Functions */
  2725. /*****************************************************************************/
  2726. static void* benchmarks_do(void* args)
  2727. {
  2728. long bench_buf_size;
  2729. #ifdef WOLFSSL_ASYNC_CRYPT
  2730. #ifndef WC_NO_ASYNC_THREADING
  2731. ThreadData* threadData = (ThreadData*)args;
  2732. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2733. #else
  2734. if (wolfAsync_DevOpen(&devId) < 0)
  2735. #endif
  2736. {
  2737. printf("%sAsync device open failed\n%sRunning without async\n",
  2738. err_prefix, err_prefix);
  2739. }
  2740. #endif /* WOLFSSL_ASYNC_CRYPT */
  2741. (void)args;
  2742. #ifdef WOLFSSL_ASYNC_CRYPT
  2743. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2744. printf("%sAsync event queue init failure!\n", err_prefix);
  2745. }
  2746. #endif
  2747. #ifdef WOLF_CRYPTO_CB
  2748. #ifdef HAVE_INTEL_QA_SYNC
  2749. devId = wc_CryptoCb_InitIntelQa();
  2750. if (devId == INVALID_DEVID) {
  2751. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2752. }
  2753. #endif
  2754. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2755. devId = wc_CryptoCb_InitOcteon();
  2756. if (devId == INVALID_DEVID) {
  2757. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2758. }
  2759. #endif
  2760. #ifdef HAVE_RENESAS_SYNC
  2761. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2762. if (devId == INVALID_DEVID) {
  2763. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2764. }
  2765. #endif
  2766. #endif
  2767. #if defined(HAVE_LOCAL_RNG)
  2768. {
  2769. int rngRet;
  2770. #ifndef HAVE_FIPS
  2771. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2772. #else
  2773. rngRet = wc_InitRng(&gRng);
  2774. #endif
  2775. if (rngRet < 0) {
  2776. printf("%sInitRNG failed\n", err_prefix);
  2777. return NULL;
  2778. }
  2779. }
  2780. #endif
  2781. /* setup bench plain, cipher, key and iv globals */
  2782. /* make sure bench buffer is multiple of 16 (AES block size) */
  2783. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2784. if (bench_buf_size % 16)
  2785. bench_buf_size += 16 - (bench_buf_size % 16);
  2786. #ifdef WOLFSSL_AFALG_XILINX_AES
  2787. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2788. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2789. #else
  2790. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2791. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2792. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2793. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2794. #endif
  2795. if (bench_plain == NULL || bench_cipher == NULL) {
  2796. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2797. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2798. bench_plain = bench_cipher = NULL;
  2799. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2800. goto exit;
  2801. }
  2802. #ifndef NO_FILESYSTEM
  2803. if (hash_input) {
  2804. size_t rawSz;
  2805. XFILE file;
  2806. file = XFOPEN(hash_input, "rb");
  2807. if (file == XBADFILE)
  2808. goto exit;
  2809. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2810. XFCLOSE(file);
  2811. goto exit;
  2812. }
  2813. bench_buf_size = XFTELL(file);
  2814. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2815. XFCLOSE(file);
  2816. goto exit;
  2817. }
  2818. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2819. rawSz = (size_t)bench_buf_size;
  2820. if (bench_buf_size % 16)
  2821. bench_buf_size += 16 - (bench_buf_size % 16);
  2822. bench_size = (word32)bench_buf_size;
  2823. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2824. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2825. if (bench_plain == NULL) {
  2826. XFCLOSE(file);
  2827. goto exit;
  2828. }
  2829. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2830. != rawSz) {
  2831. XFCLOSE(file);
  2832. goto exit;
  2833. }
  2834. XFCLOSE(file);
  2835. }
  2836. else {
  2837. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2838. }
  2839. if (cipher_input) {
  2840. size_t rawSz;
  2841. XFILE file;
  2842. file = XFOPEN(cipher_input, "rb");
  2843. if (file == XBADFILE)
  2844. goto exit;
  2845. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2846. XFCLOSE(file);
  2847. goto exit;
  2848. }
  2849. bench_buf_size = XFTELL(file);
  2850. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2851. XFCLOSE(file);
  2852. goto exit;
  2853. }
  2854. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2855. rawSz = (size_t)bench_buf_size;
  2856. if (bench_buf_size % 16)
  2857. bench_buf_size += 16 - (bench_buf_size % 16);
  2858. if (bench_size > (word32)bench_buf_size)
  2859. bench_size = (word32)bench_buf_size;
  2860. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2861. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2862. if (bench_cipher == NULL) {
  2863. XFCLOSE(file);
  2864. goto exit;
  2865. }
  2866. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2867. != rawSz) {
  2868. XFCLOSE(file);
  2869. goto exit;
  2870. }
  2871. XFCLOSE(file);
  2872. }
  2873. else {
  2874. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2875. }
  2876. #endif
  2877. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2878. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2879. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2880. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2881. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2882. if (bench_key == NULL || bench_iv == NULL) {
  2883. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2884. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2885. bench_key = bench_iv = NULL;
  2886. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2887. goto exit;
  2888. }
  2889. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2890. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2891. #elif defined(HAVE_RENESAS_SYNC)
  2892. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2893. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2894. bench_key = (byte*)bench_key_buf;
  2895. bench_iv = (byte*)bench_iv_buf;
  2896. #else
  2897. bench_key = (byte*)bench_key_buf;
  2898. bench_iv = (byte*)bench_iv_buf;
  2899. #endif
  2900. #ifndef WC_NO_RNG
  2901. if (bench_all || (bench_other_algs & BENCH_RNG))
  2902. bench_rng();
  2903. #endif /* WC_NO_RNG */
  2904. #ifndef NO_AES
  2905. #ifdef HAVE_AES_CBC
  2906. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2907. #ifndef NO_SW_BENCH
  2908. bench_aescbc(0);
  2909. #endif
  2910. #if defined(BENCH_DEVID)
  2911. bench_aescbc(1);
  2912. #endif
  2913. }
  2914. #endif
  2915. #ifdef HAVE_AESGCM
  2916. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2917. #ifndef NO_SW_BENCH
  2918. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2919. #endif
  2920. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2921. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2922. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2923. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2924. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2925. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2926. #endif
  2927. #ifndef NO_SW_BENCH
  2928. bench_gmac(0);
  2929. #endif
  2930. #if defined(BENCH_DEVID)
  2931. bench_gmac(1);
  2932. #endif
  2933. }
  2934. #endif
  2935. #ifdef HAVE_AES_ECB
  2936. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2937. #ifndef NO_SW_BENCH
  2938. bench_aesecb(0);
  2939. #endif
  2940. #ifdef BENCH_DEVID
  2941. bench_aesecb(1);
  2942. #endif
  2943. }
  2944. #endif
  2945. #ifdef WOLFSSL_AES_XTS
  2946. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2947. bench_aesxts();
  2948. #endif
  2949. #ifdef WOLFSSL_AES_CFB
  2950. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2951. bench_aescfb();
  2952. #endif
  2953. #ifdef WOLFSSL_AES_OFB
  2954. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2955. bench_aesofb();
  2956. #endif
  2957. #ifdef WOLFSSL_AES_COUNTER
  2958. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2959. bench_aesctr(0);
  2960. #ifdef BENCH_DEVID
  2961. bench_aesctr(1);
  2962. #endif
  2963. }
  2964. #endif
  2965. #ifdef HAVE_AESCCM
  2966. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2967. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2968. #ifdef BENCH_DEVID
  2969. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2970. #endif
  2971. }
  2972. #endif
  2973. #ifdef WOLFSSL_AES_SIV
  2974. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2975. bench_aessiv();
  2976. #endif
  2977. #endif /* !NO_AES */
  2978. #ifdef HAVE_CAMELLIA
  2979. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2980. bench_camellia();
  2981. #endif
  2982. #ifdef WOLFSSL_SM4_CBC
  2983. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2984. bench_sm4_cbc();
  2985. #endif
  2986. #ifdef WOLFSSL_SM4_GCM
  2987. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2988. bench_sm4_gcm();
  2989. #endif
  2990. #ifdef WOLFSSL_SM4_CCM
  2991. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2992. bench_sm4_ccm();
  2993. #endif
  2994. #ifndef NO_RC4
  2995. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2996. #ifndef NO_SW_BENCH
  2997. bench_arc4(0);
  2998. #endif
  2999. #ifdef BENCH_DEVID
  3000. bench_arc4(1);
  3001. #endif
  3002. }
  3003. #endif
  3004. #ifdef HAVE_CHACHA
  3005. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  3006. bench_chacha();
  3007. #endif
  3008. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  3009. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  3010. bench_chacha20_poly1305_aead();
  3011. #endif
  3012. #ifndef NO_DES3
  3013. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  3014. #ifndef NO_SW_BENCH
  3015. bench_des(0);
  3016. #endif
  3017. #ifdef BENCH_DEVID
  3018. bench_des(1);
  3019. #endif
  3020. }
  3021. #endif
  3022. #ifndef NO_MD5
  3023. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  3024. #ifndef NO_SW_BENCH
  3025. bench_md5(0);
  3026. #endif
  3027. #ifdef BENCH_DEVID
  3028. bench_md5(1);
  3029. #endif
  3030. }
  3031. #endif
  3032. #ifdef HAVE_POLY1305
  3033. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  3034. bench_poly1305();
  3035. #endif
  3036. #ifndef NO_SHA
  3037. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  3038. #ifndef NO_SW_BENCH
  3039. bench_sha(0);
  3040. #endif
  3041. #ifdef BENCH_DEVID
  3042. bench_sha(1);
  3043. #endif
  3044. }
  3045. #endif
  3046. #ifdef WOLFSSL_SHA224
  3047. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  3048. #ifndef NO_SW_BENCH
  3049. bench_sha224(0);
  3050. #endif
  3051. #ifdef BENCH_DEVID
  3052. bench_sha224(1);
  3053. #endif
  3054. }
  3055. #endif
  3056. #ifndef NO_SHA256
  3057. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  3058. #ifndef NO_SW_BENCH
  3059. bench_sha256(0);
  3060. #endif
  3061. #ifdef BENCH_DEVID
  3062. bench_sha256(1);
  3063. #endif
  3064. }
  3065. #endif
  3066. #ifdef WOLFSSL_SHA384
  3067. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3068. #ifndef NO_SW_BENCH
  3069. bench_sha384(0);
  3070. #endif
  3071. #ifdef BENCH_DEVID
  3072. bench_sha384(1);
  3073. #endif
  3074. }
  3075. #endif
  3076. #ifdef WOLFSSL_SHA512
  3077. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3078. #ifndef NO_SW_BENCH
  3079. bench_sha512(0);
  3080. #endif
  3081. #ifdef BENCH_DEVID
  3082. bench_sha512(1);
  3083. #endif
  3084. }
  3085. #if !defined(WOLFSSL_NOSHA512_224) && \
  3086. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3087. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3088. #ifndef NO_SW_BENCH
  3089. bench_sha512_224(0);
  3090. #endif
  3091. #ifdef BENCH_DEVID
  3092. bench_sha512_224(1);
  3093. #endif
  3094. }
  3095. #endif /* WOLFSSL_NOSHA512_224 */
  3096. #if !defined(WOLFSSL_NOSHA512_256) && \
  3097. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3098. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3099. #ifndef NO_SW_BENCH
  3100. bench_sha512_256(0);
  3101. #endif
  3102. #ifdef BENCH_DEVID
  3103. bench_sha512_256(1);
  3104. #endif
  3105. }
  3106. #endif /* WOLFSSL_NOSHA512_256 */
  3107. #endif /* WOLFSSL_SHA512 */
  3108. #ifdef WOLFSSL_SHA3
  3109. #ifndef WOLFSSL_NOSHA3_224
  3110. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3111. #ifndef NO_SW_BENCH
  3112. bench_sha3_224(0);
  3113. #endif
  3114. #ifdef BENCH_DEVID
  3115. bench_sha3_224(1);
  3116. #endif
  3117. }
  3118. #endif /* WOLFSSL_NOSHA3_224 */
  3119. #ifndef WOLFSSL_NOSHA3_256
  3120. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3121. #ifndef NO_SW_BENCH
  3122. bench_sha3_256(0);
  3123. #endif
  3124. #ifdef BENCH_DEVID
  3125. bench_sha3_256(1);
  3126. #endif
  3127. }
  3128. #endif /* WOLFSSL_NOSHA3_256 */
  3129. #ifndef WOLFSSL_NOSHA3_384
  3130. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3131. #ifndef NO_SW_BENCH
  3132. bench_sha3_384(0);
  3133. #endif
  3134. #ifdef BENCH_DEVID
  3135. bench_sha3_384(1);
  3136. #endif
  3137. }
  3138. #endif /* WOLFSSL_NOSHA3_384 */
  3139. #ifndef WOLFSSL_NOSHA3_512
  3140. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3141. #ifndef NO_SW_BENCH
  3142. bench_sha3_512(0);
  3143. #endif
  3144. #ifdef BENCH_DEVID
  3145. bench_sha3_512(1);
  3146. #endif
  3147. }
  3148. #endif /* WOLFSSL_NOSHA3_512 */
  3149. #ifdef WOLFSSL_SHAKE128
  3150. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3151. #ifndef NO_SW_BENCH
  3152. bench_shake128(0);
  3153. #endif
  3154. #ifdef BENCH_DEVID
  3155. bench_shake128(1);
  3156. #endif
  3157. }
  3158. #endif /* WOLFSSL_SHAKE128 */
  3159. #ifdef WOLFSSL_SHAKE256
  3160. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3161. #ifndef NO_SW_BENCH
  3162. bench_shake256(0);
  3163. #endif
  3164. #ifdef BENCH_DEVID
  3165. bench_shake256(1);
  3166. #endif
  3167. }
  3168. #endif /* WOLFSSL_SHAKE256 */
  3169. #endif
  3170. #ifdef WOLFSSL_SM3
  3171. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3172. #ifndef NO_SW_BENCH
  3173. bench_sm3(0);
  3174. #endif
  3175. #ifdef BENCH_DEVID
  3176. bench_sm3(1);
  3177. #endif
  3178. }
  3179. #endif
  3180. #ifdef WOLFSSL_RIPEMD
  3181. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3182. bench_ripemd();
  3183. #endif
  3184. #ifdef HAVE_BLAKE2
  3185. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3186. bench_blake2b();
  3187. #endif
  3188. #ifdef HAVE_BLAKE2S
  3189. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3190. bench_blake2s();
  3191. #endif
  3192. #ifdef WOLFSSL_CMAC
  3193. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3194. bench_cmac(0);
  3195. #ifdef BENCH_DEVID
  3196. bench_cmac(1);
  3197. #endif
  3198. }
  3199. #endif
  3200. #ifndef NO_HMAC
  3201. #ifndef NO_MD5
  3202. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3203. #ifndef NO_SW_BENCH
  3204. bench_hmac_md5(0);
  3205. #endif
  3206. #ifdef BENCH_DEVID
  3207. bench_hmac_md5(1);
  3208. #endif
  3209. }
  3210. #endif
  3211. #ifndef NO_SHA
  3212. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3213. #ifndef NO_SW_BENCH
  3214. bench_hmac_sha(0);
  3215. #endif
  3216. #ifdef BENCH_DEVID
  3217. bench_hmac_sha(1);
  3218. #endif
  3219. }
  3220. #endif
  3221. #ifdef WOLFSSL_SHA224
  3222. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3223. #ifndef NO_SW_BENCH
  3224. bench_hmac_sha224(0);
  3225. #endif
  3226. #ifdef BENCH_DEVID
  3227. bench_hmac_sha224(1);
  3228. #endif
  3229. }
  3230. #endif
  3231. #ifndef NO_SHA256
  3232. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3233. #ifndef NO_SW_BENCH
  3234. bench_hmac_sha256(0);
  3235. #endif
  3236. #ifdef BENCH_DEVID
  3237. bench_hmac_sha256(1);
  3238. #endif
  3239. }
  3240. #endif
  3241. #ifdef WOLFSSL_SHA384
  3242. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3243. #ifndef NO_SW_BENCH
  3244. bench_hmac_sha384(0);
  3245. #endif
  3246. #ifdef BENCH_DEVID
  3247. bench_hmac_sha384(1);
  3248. #endif
  3249. }
  3250. #endif
  3251. #ifdef WOLFSSL_SHA512
  3252. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3253. #ifndef NO_SW_BENCH
  3254. bench_hmac_sha512(0);
  3255. #endif
  3256. #ifdef BENCH_DEVID
  3257. bench_hmac_sha512(1);
  3258. #endif
  3259. }
  3260. #endif
  3261. #ifndef NO_PWDBASED
  3262. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3263. bench_pbkdf2();
  3264. }
  3265. #endif
  3266. #endif /* NO_HMAC */
  3267. #ifdef WOLFSSL_SIPHASH
  3268. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3269. bench_siphash();
  3270. }
  3271. #endif
  3272. #ifdef WC_SRTP_KDF
  3273. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3274. bench_srtpkdf();
  3275. }
  3276. #endif
  3277. #ifdef HAVE_SCRYPT
  3278. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3279. bench_scrypt();
  3280. #endif
  3281. #ifndef NO_RSA
  3282. #ifndef HAVE_RENESAS_SYNC
  3283. #ifdef WOLFSSL_KEY_GEN
  3284. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3285. #ifndef NO_SW_BENCH
  3286. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3287. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3288. bench_rsaKeyGen(0);
  3289. }
  3290. else {
  3291. bench_rsaKeyGen_size(0, bench_size);
  3292. }
  3293. #endif
  3294. #ifdef BENCH_DEVID
  3295. if (bench_asym_algs & BENCH_RSA_SZ) {
  3296. bench_rsaKeyGen_size(1, bench_size);
  3297. }
  3298. else {
  3299. bench_rsaKeyGen(1);
  3300. }
  3301. #endif
  3302. }
  3303. #endif
  3304. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3305. #ifndef NO_SW_BENCH
  3306. bench_rsa(0);
  3307. #endif
  3308. #ifdef BENCH_DEVID
  3309. bench_rsa(1);
  3310. #endif
  3311. }
  3312. #ifdef WOLFSSL_KEY_GEN
  3313. if (bench_asym_algs & BENCH_RSA_SZ) {
  3314. #ifndef NO_SW_BENCH
  3315. bench_rsa_key(0, bench_size);
  3316. #endif
  3317. #ifdef BENCH_DEVID
  3318. bench_rsa_key(1, bench_size);
  3319. #endif
  3320. }
  3321. #endif
  3322. #endif
  3323. #endif
  3324. #ifndef NO_DH
  3325. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3326. #ifndef NO_SW_BENCH
  3327. bench_dh(0);
  3328. #endif
  3329. #ifdef BENCH_DEVID
  3330. bench_dh(1);
  3331. #endif
  3332. }
  3333. #endif
  3334. #ifdef WOLFSSL_HAVE_KYBER
  3335. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3336. #ifndef WOLFSSL_NO_ML_KEM
  3337. #ifdef WOLFSSL_KYBER512
  3338. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3339. bench_kyber(WC_ML_KEM_512);
  3340. }
  3341. #endif
  3342. #ifdef WOLFSSL_KYBER768
  3343. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3344. bench_kyber(WC_ML_KEM_768);
  3345. }
  3346. #endif
  3347. #ifdef WOLFSSL_KYBER1024
  3348. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3349. bench_kyber(WC_ML_KEM_1024);
  3350. }
  3351. #endif
  3352. #endif
  3353. #ifdef WOLFSSL_KYBER_ORIGINAL
  3354. #ifdef WOLFSSL_KYBER512
  3355. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3356. bench_kyber(KYBER512);
  3357. }
  3358. #endif
  3359. #ifdef WOLFSSL_KYBER768
  3360. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3361. bench_kyber(KYBER768);
  3362. }
  3363. #endif
  3364. #ifdef WOLFSSL_KYBER1024
  3365. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3366. bench_kyber(KYBER1024);
  3367. }
  3368. #endif
  3369. #endif
  3370. }
  3371. #endif
  3372. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3373. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3374. bench_lms();
  3375. }
  3376. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3377. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3378. if (bench_all) {
  3379. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3380. }
  3381. #ifndef NO_SHA256
  3382. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3383. bench_xmss(WC_HASH_TYPE_SHA256);
  3384. }
  3385. #endif
  3386. #ifdef WOLFSSL_SHA512
  3387. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3388. bench_xmss(WC_HASH_TYPE_SHA512);
  3389. }
  3390. #endif
  3391. #ifdef WOLFSSL_SHAKE128
  3392. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3393. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3394. }
  3395. #endif
  3396. #ifdef WOLFSSL_SHAKE256
  3397. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3398. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3399. }
  3400. #endif
  3401. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3402. #ifdef HAVE_ECC
  3403. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3404. (bench_asym_algs & BENCH_ECC) ||
  3405. (bench_asym_algs & BENCH_ECC_ALL) ||
  3406. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3407. if (bench_asym_algs & BENCH_ECC_ALL) {
  3408. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3409. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3410. err_prefix);
  3411. #else
  3412. int curveId = (int)ECC_SECP192R1;
  3413. /* set make key and encrypt */
  3414. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3415. BENCH_ECC_ENCRYPT;
  3416. if (csv_format != 1) {
  3417. printf("\n%sECC Benchmarks:\n", info_prefix);
  3418. }
  3419. do {
  3420. #ifdef WOLFCRYPT_HAVE_SAKKE
  3421. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3422. if (curveId == ECC_SAKKE_1) {
  3423. curveId++;
  3424. continue;
  3425. }
  3426. #endif
  3427. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3428. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3429. bench_ecc_curve(curveId);
  3430. if (csv_format != 1) {
  3431. printf("\n");
  3432. }
  3433. }
  3434. curveId++;
  3435. } while (curveId != (int)ECC_CURVE_MAX);
  3436. #endif
  3437. }
  3438. else if (bench_asym_algs & BENCH_ECC_P256) {
  3439. bench_ecc_curve((int)ECC_SECP256R1);
  3440. }
  3441. else if (bench_asym_algs & BENCH_ECC_P384) {
  3442. bench_ecc_curve((int)ECC_SECP384R1);
  3443. }
  3444. else if (bench_asym_algs & BENCH_ECC_P521) {
  3445. bench_ecc_curve((int)ECC_SECP521R1);
  3446. }
  3447. else {
  3448. #ifndef NO_ECC256
  3449. bench_ecc_curve((int)ECC_SECP256R1);
  3450. #elif defined(HAVE_ECC384)
  3451. bench_ecc_curve((int)ECC_SECP384R1);
  3452. #elif defined(HAVE_ECC521)
  3453. bench_ecc_curve((int)ECC_SECP521R1);
  3454. #endif
  3455. #ifdef HAVE_ECC_BRAINPOOL
  3456. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3457. #endif
  3458. }
  3459. }
  3460. #endif
  3461. #ifdef WOLFSSL_SM2
  3462. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3463. bench_sm2(0);
  3464. }
  3465. #endif
  3466. #ifdef HAVE_CURVE25519
  3467. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3468. bench_curve25519KeyGen(0);
  3469. #ifdef BENCH_DEVID
  3470. bench_curve25519KeyGen(1);
  3471. #endif
  3472. }
  3473. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3474. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3475. bench_curve25519KeyAgree(0);
  3476. #ifdef BENCH_DEVID
  3477. bench_curve25519KeyAgree(1);
  3478. #endif
  3479. }
  3480. #endif
  3481. #endif
  3482. #ifdef HAVE_ED25519
  3483. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3484. bench_ed25519KeyGen();
  3485. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3486. bench_ed25519KeySign();
  3487. #endif
  3488. #ifdef HAVE_CURVE448
  3489. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3490. bench_curve448KeyGen();
  3491. #ifdef HAVE_CURVE448_SHARED_SECRET
  3492. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3493. bench_curve448KeyAgree();
  3494. #endif
  3495. #endif
  3496. #ifdef HAVE_ED448
  3497. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3498. bench_ed448KeyGen();
  3499. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3500. bench_ed448KeySign();
  3501. #endif
  3502. #ifdef WOLFCRYPT_HAVE_ECCSI
  3503. #ifdef WOLFCRYPT_ECCSI_KMS
  3504. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3505. bench_eccsiKeyGen();
  3506. }
  3507. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3508. bench_eccsiPairGen();
  3509. }
  3510. #endif
  3511. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3512. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3513. bench_eccsiValidate();
  3514. }
  3515. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3516. bench_eccsi();
  3517. }
  3518. #endif
  3519. #endif
  3520. #ifdef WOLFCRYPT_HAVE_SAKKE
  3521. #ifdef WOLFCRYPT_SAKKE_KMS
  3522. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3523. bench_sakkeKeyGen();
  3524. }
  3525. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3526. bench_sakkeRskGen();
  3527. }
  3528. #endif
  3529. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3530. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3531. bench_sakkeValidate();
  3532. }
  3533. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3534. bench_sakke();
  3535. }
  3536. #endif
  3537. #endif
  3538. #ifdef HAVE_FALCON
  3539. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3540. bench_falconKeySign(1);
  3541. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3542. bench_falconKeySign(5);
  3543. #endif
  3544. #ifdef HAVE_DILITHIUM
  3545. #ifndef WOLFSSL_NO_ML_DSA_44
  3546. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3547. bench_dilithiumKeySign(2);
  3548. #endif
  3549. #ifndef WOLFSSL_NO_ML_DSA_65
  3550. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3551. bench_dilithiumKeySign(3);
  3552. #endif
  3553. #ifndef WOLFSSL_NO_ML_DSA_87
  3554. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3555. bench_dilithiumKeySign(5);
  3556. #endif
  3557. #endif
  3558. #ifdef HAVE_SPHINCS
  3559. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3560. bench_sphincsKeySign(1, FAST_VARIANT);
  3561. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3562. bench_sphincsKeySign(3, FAST_VARIANT);
  3563. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3564. bench_sphincsKeySign(5, FAST_VARIANT);
  3565. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3566. bench_sphincsKeySign(1, SMALL_VARIANT);
  3567. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3568. bench_sphincsKeySign(3, SMALL_VARIANT);
  3569. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3570. bench_sphincsKeySign(5, SMALL_VARIANT);
  3571. #endif
  3572. exit:
  3573. /* free benchmark buffers */
  3574. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3575. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3576. #ifdef WOLFSSL_ASYNC_CRYPT
  3577. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3578. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3579. #endif
  3580. #if defined(HAVE_LOCAL_RNG)
  3581. wc_FreeRng(&gRng);
  3582. #endif
  3583. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3584. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3585. wc_ecc_fp_free();
  3586. #endif
  3587. (void)bench_cipher_algs;
  3588. (void)bench_digest_algs;
  3589. (void)bench_mac_algs;
  3590. (void)bench_asym_algs;
  3591. (void)bench_other_algs;
  3592. (void)bench_pq_asym_algs;
  3593. (void)bench_pq_asym_algs2;
  3594. return NULL;
  3595. }
  3596. #if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
  3597. static void print_cpu_features(void)
  3598. {
  3599. word32 cpuid_flags = cpuid_get_flags();
  3600. printf("CPU: ");
  3601. #ifdef HAVE_CPUID_INTEL
  3602. printf("Intel");
  3603. #ifdef WOLFSSL_X86_64_BUILD
  3604. printf(" x86_64");
  3605. #else
  3606. printf(" x86");
  3607. #endif
  3608. printf(" -");
  3609. if (IS_INTEL_AVX1(cpuid_flags)) printf(" avx1");
  3610. if (IS_INTEL_AVX2(cpuid_flags)) printf(" avx2");
  3611. if (IS_INTEL_RDRAND(cpuid_flags)) printf(" rdrand");
  3612. if (IS_INTEL_RDSEED(cpuid_flags)) printf(" rdseed");
  3613. if (IS_INTEL_BMI2(cpuid_flags)) printf(" bmi2");
  3614. if (IS_INTEL_AESNI(cpuid_flags)) printf(" aesni");
  3615. if (IS_INTEL_ADX(cpuid_flags)) printf(" adx");
  3616. if (IS_INTEL_MOVBE(cpuid_flags)) printf(" movbe");
  3617. if (IS_INTEL_BMI1(cpuid_flags)) printf(" bmi1");
  3618. if (IS_INTEL_SHA(cpuid_flags)) printf(" sha");
  3619. #endif
  3620. #ifdef __aarch64__
  3621. printf("Aarch64 -");
  3622. if (IS_AARCH64_AES(cpuid_flags)) printf(" aes");
  3623. if (IS_AARCH64_PMULL(cpuid_flags)) printf(" pmull");
  3624. if (IS_AARCH64_SHA256(cpuid_flags)) printf(" sha256");
  3625. if (IS_AARCH64_SHA512(cpuid_flags)) printf(" sha512");
  3626. if (IS_AARCH64_RDM(cpuid_flags)) printf(" rdm");
  3627. if (IS_AARCH64_SHA3(cpuid_flags)) printf(" sha3");
  3628. if (IS_AARCH64_SM3(cpuid_flags)) printf(" sm3");
  3629. if (IS_AARCH64_SM4(cpuid_flags)) printf(" sm4");
  3630. #endif
  3631. printf("\n");
  3632. }
  3633. #endif
  3634. int benchmark_init(void)
  3635. {
  3636. int ret = 0;
  3637. benchmark_static_init(0);
  3638. #ifdef WOLFSSL_STATIC_MEMORY
  3639. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3640. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3641. if (ret != 0) {
  3642. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3643. }
  3644. #endif /* WOLFSSL_STATIC_MEMORY */
  3645. if ((ret = wolfCrypt_Init()) != 0) {
  3646. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3647. return EXIT_FAILURE;
  3648. }
  3649. #if defined(HAVE_CPUID) && defined(WOLFSSL_TEST_STATIC_BUILD)
  3650. print_cpu_features();
  3651. #endif
  3652. #ifdef HAVE_WC_INTROSPECTION
  3653. printf("Math: %s\n", wc_GetMathInfo());
  3654. #endif
  3655. #ifdef WOLFSSL_SECO_CAAM
  3656. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3657. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3658. != 0) {
  3659. printf("%sunable to open HSM\n", err_prefix);
  3660. wolfCrypt_Cleanup();
  3661. return EXIT_FAILURE;
  3662. }
  3663. #endif
  3664. #ifdef WC_RNG_SEED_CB
  3665. wc_SetSeed_Cb(wc_GenerateSeed);
  3666. #endif
  3667. bench_stats_init();
  3668. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3669. wolfSSL_Debugging_ON();
  3670. #endif
  3671. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3672. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3673. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3674. if (csv_format == 1) {
  3675. printf("This format allows you to easily copy "
  3676. "the output to a csv file.");
  3677. }
  3678. #endif
  3679. #ifdef HAVE_WNR
  3680. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3681. if (ret != 0) {
  3682. printf("%sWhitewood netRandom config init failed %d\n",
  3683. err_prefix, ret);
  3684. }
  3685. #endif /* HAVE_WNR */
  3686. return ret;
  3687. }
  3688. int benchmark_free(void)
  3689. {
  3690. int ret;
  3691. #ifdef WC_BENCH_TRACK_STATS
  3692. if (gPrintStats || devId != INVALID_DEVID) {
  3693. bench_stats_print();
  3694. }
  3695. #endif
  3696. bench_stats_free();
  3697. #ifdef WOLF_CRYPTO_CB
  3698. #ifdef HAVE_INTEL_QA_SYNC
  3699. wc_CryptoCb_CleanupIntelQa(&devId);
  3700. #endif
  3701. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3702. wc_CryptoCb_CleanupOcteon(&devId);
  3703. #endif
  3704. #ifdef HAVE_RENESAS_SYNC
  3705. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3706. #endif
  3707. #endif
  3708. #ifdef WOLFSSL_ASYNC_CRYPT
  3709. /* free event queue */
  3710. wolfEventQueue_Free(&eventQueue);
  3711. /* close device */
  3712. wolfAsync_DevClose(&devId);
  3713. #endif
  3714. #ifdef HAVE_WNR
  3715. ret = wc_FreeNetRandom();
  3716. if (ret < 0) {
  3717. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3718. }
  3719. #endif
  3720. #ifdef WOLFSSL_SECO_CAAM
  3721. if (wc_SECO_CloseHSM() != 0) {
  3722. printf("%sError closing down the key store\n", err_prefix);
  3723. }
  3724. #endif
  3725. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3726. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3727. }
  3728. return ret;
  3729. }
  3730. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3731. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3732. {
  3733. benchmark_test(args);
  3734. EXIT_TEST(0);
  3735. }
  3736. static int benchmark_test_threaded(void* args)
  3737. {
  3738. int i;
  3739. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3740. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3741. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3742. if (g_threadData == NULL) {
  3743. printf("%sThread data alloc failed!\n", err_prefix);
  3744. return EXIT_FAILURE;
  3745. }
  3746. for (i = 0; i < g_threadCount; i++) {
  3747. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3748. NULL, run_bench, args));
  3749. }
  3750. for (i = 0; i < g_threadCount; i++) {
  3751. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3752. }
  3753. printf("\n");
  3754. bench_stats_print();
  3755. return 0;
  3756. }
  3757. #endif
  3758. /* so embedded projects can pull in tests on their own */
  3759. #ifdef HAVE_STACK_SIZE
  3760. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3761. #else
  3762. int benchmark_test(void *args)
  3763. #endif
  3764. {
  3765. int ret;
  3766. (void)args;
  3767. #ifdef HAVE_FIPS
  3768. wolfCrypt_SetCb_fips(myFipsCb);
  3769. #endif
  3770. ret = benchmark_init();
  3771. if (ret != 0)
  3772. EXIT_TEST(ret);
  3773. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3774. {
  3775. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3776. **
  3777. ** Chapter Two, Build Options:
  3778. **
  3779. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3780. **
  3781. ** asynchronous cryptography using hardware based adapters such as
  3782. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3783. */
  3784. int i;
  3785. if (g_threadCount == 0) {
  3786. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3787. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3788. #else
  3789. g_threadCount = wc_AsyncGetNumberOfCpus();
  3790. if (g_threadCount > 0) {
  3791. g_threadCount /= 2; /* use physical core count */
  3792. }
  3793. #endif
  3794. }
  3795. if (g_threadCount <= 0) {
  3796. g_threadCount = 1;
  3797. }
  3798. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3799. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3800. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3801. if (g_threadData == NULL) {
  3802. printf("%sThread data alloc failed!\n", err_prefix);
  3803. EXIT_TEST(EXIT_FAILURE);
  3804. }
  3805. /* Create threads */
  3806. for (i = 0; i < g_threadCount; i++) {
  3807. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3808. benchmarks_do, &g_threadData[i]);
  3809. if (ret != 0) {
  3810. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3811. EXIT_TEST(EXIT_FAILURE);
  3812. }
  3813. }
  3814. /* Start threads */
  3815. for (i = 0; i < g_threadCount; i++) {
  3816. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3817. }
  3818. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3819. }
  3820. #else
  3821. benchmarks_do(NULL);
  3822. #endif
  3823. SLEEP_ON_ERROR(1);
  3824. printf("%sBenchmark complete\n", info_prefix);
  3825. ret = benchmark_free();
  3826. EXIT_TEST(ret);
  3827. }
  3828. #ifndef WC_NO_RNG
  3829. void bench_rng(void)
  3830. {
  3831. int ret, i, count;
  3832. double start;
  3833. long pos, len, remain;
  3834. WC_RNG myrng;
  3835. DECLARE_MULTI_VALUE_STATS_VARS()
  3836. #ifndef HAVE_FIPS
  3837. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3838. #else
  3839. ret = wc_InitRng(&myrng);
  3840. #endif
  3841. if (ret < 0) {
  3842. printf("InitRNG failed %d\n", ret);
  3843. return;
  3844. }
  3845. bench_stats_start(&count, &start);
  3846. do {
  3847. for (i = 0; i < numBlocks; i++) {
  3848. /* Split request to handle large RNG request */
  3849. pos = 0;
  3850. remain = (int)bench_size;
  3851. while (remain > 0) {
  3852. len = remain;
  3853. if (len > RNG_MAX_BLOCK_LEN)
  3854. len = RNG_MAX_BLOCK_LEN;
  3855. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3856. (word32)len);
  3857. if (ret < 0)
  3858. goto exit_rng;
  3859. remain -= len;
  3860. pos += len;
  3861. }
  3862. RECORD_MULTI_VALUE_STATS();
  3863. }
  3864. count += i;
  3865. } while (bench_stats_check(start)
  3866. #ifdef MULTI_VALUE_STATISTICS
  3867. || runs < minimum_runs
  3868. #endif
  3869. );
  3870. exit_rng:
  3871. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3872. #ifdef MULTI_VALUE_STATISTICS
  3873. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3874. #endif
  3875. wc_FreeRng(&myrng);
  3876. }
  3877. #endif /* WC_NO_RNG */
  3878. #ifndef NO_AES
  3879. #ifdef HAVE_AES_CBC
  3880. static void bench_aescbc_internal(int useDeviceID,
  3881. const byte* key, word32 keySz,
  3882. const byte* iv, const char* encLabel,
  3883. const char* decLabel)
  3884. {
  3885. const byte* in = bench_cipher;
  3886. byte* out = bench_plain;
  3887. int ret = 0, i, count = 0, times, pending = 0;
  3888. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3889. sizeof(Aes), HEAP_HINT);
  3890. double start;
  3891. DECLARE_MULTI_VALUE_STATS_VARS()
  3892. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3893. sizeof(Aes), HEAP_HINT);
  3894. /* init keys */
  3895. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3896. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3897. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3898. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3899. goto exit;
  3900. }
  3901. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3902. if (ret != 0) {
  3903. printf("AesSetKey failed, ret = %d\n", ret);
  3904. goto exit;
  3905. }
  3906. }
  3907. if (cipher_same_buffer) {
  3908. in = bench_plain;
  3909. }
  3910. bench_stats_start(&count, &start);
  3911. do {
  3912. for (times = 0; times < numBlocks || pending > 0; ) {
  3913. bench_async_poll(&pending);
  3914. /* while free pending slots in queue, submit ops */
  3915. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3916. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3917. &times, numBlocks, &pending)) {
  3918. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3919. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3920. 0, &times, &pending)) {
  3921. goto exit_aes_enc;
  3922. }
  3923. }
  3924. } /* for i */
  3925. RECORD_MULTI_VALUE_STATS();
  3926. } /* for times */
  3927. count += times;
  3928. } while (bench_stats_check(start)
  3929. #ifdef MULTI_VALUE_STATISTICS
  3930. || runs < minimum_runs
  3931. #endif
  3932. );
  3933. exit_aes_enc:
  3934. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3935. bench_size, start, ret);
  3936. #ifdef MULTI_VALUE_STATISTICS
  3937. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3938. #endif
  3939. if (ret < 0) {
  3940. goto exit;
  3941. }
  3942. #ifdef HAVE_AES_DECRYPT
  3943. /* init keys */
  3944. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3945. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3946. if (ret != 0) {
  3947. printf("AesSetKey failed, ret = %d\n", ret);
  3948. goto exit;
  3949. }
  3950. }
  3951. RESET_MULTI_VALUE_STATS_VARS();
  3952. bench_stats_start(&count, &start);
  3953. do {
  3954. for (times = 0; times < numBlocks || pending > 0; ) {
  3955. bench_async_poll(&pending);
  3956. /* while free pending slots in queue, submit ops */
  3957. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3958. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3959. &times, numBlocks, &pending)) {
  3960. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3961. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3962. 0, &times, &pending)) {
  3963. goto exit_aes_dec;
  3964. }
  3965. }
  3966. } /* for i */
  3967. RECORD_MULTI_VALUE_STATS();
  3968. } /* for times */
  3969. count += times;
  3970. } while (bench_stats_check(start)
  3971. #ifdef MULTI_VALUE_STATISTICS
  3972. || runs < minimum_runs
  3973. #endif
  3974. );
  3975. exit_aes_dec:
  3976. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3977. start, ret);
  3978. #ifdef MULTI_VALUE_STATISTICS
  3979. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3980. #endif
  3981. #endif /* HAVE_AES_DECRYPT */
  3982. (void)decLabel;
  3983. exit:
  3984. if (WC_ARRAY_OK(enc)) {
  3985. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3986. wc_AesFree(enc[i]);
  3987. }
  3988. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3989. }
  3990. }
  3991. void bench_aescbc(int useDeviceID)
  3992. {
  3993. #ifdef WOLFSSL_AES_128
  3994. #ifdef HAVE_RENESAS_SYNC
  3995. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3996. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3997. #else
  3998. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3999. "AES-128-CBC-enc", "AES-128-CBC-dec");
  4000. #endif
  4001. #endif
  4002. #ifdef WOLFSSL_AES_192
  4003. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  4004. "AES-192-CBC-enc", "AES-192-CBC-dec");
  4005. #endif
  4006. #ifdef WOLFSSL_AES_256
  4007. #ifdef HAVE_RENESAS_SYNC
  4008. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  4009. "AES-256-CBC-enc", "AES-256-CBC-dec");
  4010. #else
  4011. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  4012. "AES-256-CBC-enc", "AES-256-CBC-dec");
  4013. #endif
  4014. #endif
  4015. }
  4016. #endif /* HAVE_AES_CBC */
  4017. #ifdef HAVE_AESGCM
  4018. static void bench_aesgcm_internal(int useDeviceID,
  4019. const byte* key, word32 keySz,
  4020. const byte* iv, word32 ivSz,
  4021. const char* encLabel, const char* decLabel)
  4022. {
  4023. int ret = 0, i, count = 0, times, pending = 0;
  4024. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4025. sizeof(Aes), HEAP_HINT);
  4026. #ifdef HAVE_AES_DECRYPT
  4027. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4028. sizeof(Aes), HEAP_HINT);
  4029. #endif
  4030. double start;
  4031. DECLARE_MULTI_VALUE_STATS_VARS()
  4032. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4033. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4034. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4035. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4036. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4037. sizeof(Aes), HEAP_HINT);
  4038. #ifdef HAVE_AES_DECRYPT
  4039. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4040. sizeof(Aes), HEAP_HINT);
  4041. #endif
  4042. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4043. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4044. /* init keys */
  4045. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4046. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4047. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4048. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4049. goto exit;
  4050. }
  4051. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4052. if (ret != 0) {
  4053. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4054. goto exit;
  4055. }
  4056. }
  4057. /* GCM uses same routine in backend for both encrypt and decrypt */
  4058. bench_stats_start(&count, &start);
  4059. do {
  4060. for (times = 0; times < numBlocks || pending > 0; ) {
  4061. bench_async_poll(&pending);
  4062. /* while free pending slots in queue, submit ops */
  4063. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4064. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4065. &times, numBlocks, &pending)) {
  4066. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  4067. bench_plain, bench_size,
  4068. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4069. bench_additional, aesAuthAddSz);
  4070. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4071. 0, &times, &pending)) {
  4072. goto exit_aes_gcm;
  4073. }
  4074. }
  4075. } /* for i */
  4076. RECORD_MULTI_VALUE_STATS();
  4077. } /* for times */
  4078. count += times;
  4079. } while (bench_stats_check(start)
  4080. #ifdef MULTI_VALUE_STATISTICS
  4081. || runs < minimum_runs
  4082. #endif
  4083. );
  4084. exit_aes_gcm:
  4085. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4086. start, ret);
  4087. #ifdef MULTI_VALUE_STATISTICS
  4088. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4089. #endif
  4090. #ifdef HAVE_AES_DECRYPT
  4091. RESET_MULTI_VALUE_STATS_VARS();
  4092. /* init keys */
  4093. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4094. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4095. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4096. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4097. goto exit;
  4098. }
  4099. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4100. if (ret != 0) {
  4101. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4102. goto exit;
  4103. }
  4104. }
  4105. bench_stats_start(&count, &start);
  4106. do {
  4107. for (times = 0; times < numBlocks || pending > 0; ) {
  4108. bench_async_poll(&pending);
  4109. /* while free pending slots in queue, submit ops */
  4110. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4111. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4112. &times, numBlocks, &pending)) {
  4113. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4114. bench_cipher, bench_size,
  4115. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4116. bench_additional, aesAuthAddSz);
  4117. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4118. 0, &times, &pending)) {
  4119. goto exit_aes_gcm_dec;
  4120. }
  4121. }
  4122. } /* for i */
  4123. RECORD_MULTI_VALUE_STATS();
  4124. } /* for times */
  4125. count += times;
  4126. } while (bench_stats_check(start)
  4127. #ifdef MULTI_VALUE_STATISTICS
  4128. || runs < minimum_runs
  4129. #endif
  4130. );
  4131. exit_aes_gcm_dec:
  4132. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4133. start, ret);
  4134. #ifdef MULTI_VALUE_STATISTICS
  4135. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4136. #endif
  4137. #endif /* HAVE_AES_DECRYPT */
  4138. (void)decLabel;
  4139. exit:
  4140. if (ret < 0) {
  4141. printf("bench_aesgcm failed: %d\n", ret);
  4142. }
  4143. #ifdef HAVE_AES_DECRYPT
  4144. if (WC_ARRAY_OK(dec)) {
  4145. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4146. wc_AesFree(dec[i]);
  4147. }
  4148. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4149. }
  4150. #endif
  4151. if (WC_ARRAY_OK(enc)) {
  4152. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4153. wc_AesFree(enc[i]);
  4154. }
  4155. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4156. }
  4157. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4158. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4159. }
  4160. #ifdef WOLFSSL_AESGCM_STREAM
  4161. static void bench_aesgcm_stream_internal(int useDeviceID,
  4162. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4163. const char* encLabel, const char* decLabel)
  4164. {
  4165. int ret = 0, i, count = 0, times, pending = 0;
  4166. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4167. sizeof(Aes), HEAP_HINT);
  4168. #ifdef HAVE_AES_DECRYPT
  4169. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4170. sizeof(Aes), HEAP_HINT);
  4171. #endif
  4172. double start;
  4173. DECLARE_MULTI_VALUE_STATS_VARS()
  4174. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4175. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4176. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4177. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4178. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4179. sizeof(Aes), HEAP_HINT);
  4180. #ifdef HAVE_AES_DECRYPT
  4181. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4182. sizeof(Aes), HEAP_HINT);
  4183. #endif
  4184. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4185. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4186. /* init keys */
  4187. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4188. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4189. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4190. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4191. goto exit;
  4192. }
  4193. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4194. if (ret != 0) {
  4195. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4196. goto exit;
  4197. }
  4198. }
  4199. /* GCM uses same routine in backend for both encrypt and decrypt */
  4200. bench_stats_start(&count, &start);
  4201. do {
  4202. for (times = 0; times < numBlocks || pending > 0; ) {
  4203. bench_async_poll(&pending);
  4204. /* while free pending slots in queue, submit ops */
  4205. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4206. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4207. &times, numBlocks, &pending)) {
  4208. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4209. if (ret == 0) {
  4210. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4211. bench_plain, bench_size, bench_additional,
  4212. aesAuthAddSz);
  4213. }
  4214. if (ret == 0) {
  4215. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4216. AES_AUTH_TAG_SZ);
  4217. }
  4218. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4219. 0, &times, &pending)) {
  4220. goto exit_aes_gcm;
  4221. }
  4222. }
  4223. } /* for i */
  4224. RECORD_MULTI_VALUE_STATS();
  4225. } /* for times */
  4226. count += times;
  4227. } while (bench_stats_check(start)
  4228. #ifdef MULTI_VALUE_STATISTICS
  4229. || runs < minimum_runs
  4230. #endif
  4231. );
  4232. exit_aes_gcm:
  4233. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4234. start, ret);
  4235. #ifdef MULTI_VALUE_STATISTICS
  4236. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4237. #endif
  4238. #ifdef HAVE_AES_DECRYPT
  4239. /* init keys */
  4240. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4241. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4242. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4243. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4244. goto exit;
  4245. }
  4246. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4247. if (ret != 0) {
  4248. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4249. goto exit;
  4250. }
  4251. }
  4252. RESET_MULTI_VALUE_STATS_VARS();
  4253. bench_stats_start(&count, &start);
  4254. do {
  4255. for (times = 0; times < numBlocks || pending > 0; ) {
  4256. bench_async_poll(&pending);
  4257. /* while free pending slots in queue, submit ops */
  4258. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4259. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4260. &times, numBlocks, &pending)) {
  4261. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4262. if (ret == 0) {
  4263. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4264. bench_cipher, bench_size, bench_additional,
  4265. aesAuthAddSz);
  4266. }
  4267. if (ret == 0) {
  4268. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4269. AES_AUTH_TAG_SZ);
  4270. }
  4271. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4272. 0, &times, &pending)) {
  4273. goto exit_aes_gcm_dec;
  4274. }
  4275. }
  4276. } /* for i */
  4277. RECORD_MULTI_VALUE_STATS();
  4278. } /* for times */
  4279. count += times;
  4280. } while (bench_stats_check(start)
  4281. #ifdef MULTI_VALUE_STATISTICS
  4282. || runs < minimum_runs
  4283. #endif
  4284. );
  4285. exit_aes_gcm_dec:
  4286. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4287. start, ret);
  4288. #ifdef MULTI_VALUE_STATISTICS
  4289. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4290. #endif
  4291. #endif /* HAVE_AES_DECRYPT */
  4292. (void)decLabel;
  4293. exit:
  4294. if (ret < 0) {
  4295. printf("bench_aesgcm failed: %d\n", ret);
  4296. }
  4297. #ifdef HAVE_AES_DECRYPT
  4298. if (WC_ARRAY_OK(dec)) {
  4299. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4300. wc_AesFree(dec[i]);
  4301. }
  4302. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4303. }
  4304. #endif
  4305. if (WC_ARRAY_OK(enc)) {
  4306. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4307. wc_AesFree(enc[i]);
  4308. }
  4309. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4310. }
  4311. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4312. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4313. }
  4314. #endif
  4315. void bench_aesgcm(int useDeviceID)
  4316. {
  4317. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4318. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4319. && !defined(WOLFSSL_XILINX_CRYPT) \
  4320. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4321. #ifdef HAVE_RENESAS_SYNC
  4322. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4323. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4324. #else
  4325. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4326. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4327. #endif
  4328. #endif
  4329. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4330. && !defined(WOLFSSL_XILINX_CRYPT)
  4331. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4332. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4333. #endif
  4334. #ifdef WOLFSSL_AES_256
  4335. #ifdef HAVE_RENESAS_SYNC
  4336. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4337. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4338. #else
  4339. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4340. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4341. #endif
  4342. #endif
  4343. #ifdef WOLFSSL_AESGCM_STREAM
  4344. #undef AES_GCM_STRING
  4345. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4346. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4347. && !defined(WOLFSSL_XILINX_CRYPT) \
  4348. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4349. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4350. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4351. #endif
  4352. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4353. && !defined(WOLFSSL_XILINX_CRYPT)
  4354. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4355. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4356. #endif
  4357. #ifdef WOLFSSL_AES_256
  4358. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4359. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4360. #endif
  4361. #endif /* WOLFSSL_AESGCM_STREAM */
  4362. #undef AES_GCM_STRING
  4363. }
  4364. /* GMAC */
  4365. void bench_gmac(int useDeviceID)
  4366. {
  4367. int ret, count = 0;
  4368. Gmac gmac;
  4369. double start;
  4370. byte tag[AES_AUTH_TAG_SZ];
  4371. DECLARE_MULTI_VALUE_STATS_VARS()
  4372. /* determine GCM GHASH method */
  4373. #ifdef GCM_SMALL
  4374. const char* gmacStr = "GMAC Small";
  4375. #elif defined(GCM_TABLE)
  4376. const char* gmacStr = "GMAC Table";
  4377. #elif defined(GCM_TABLE_4BIT)
  4378. const char* gmacStr = "GMAC Table 4-bit";
  4379. #elif defined(GCM_WORD32)
  4380. const char* gmacStr = "GMAC Word32";
  4381. #else
  4382. const char* gmacStr = "GMAC Default";
  4383. #endif
  4384. /* Implementations of /Dev/Crypto will error out if the size of Auth in is */
  4385. /* greater than the system's page size */
  4386. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  4387. bench_size = WOLFSSL_AUTHSZ_BENCH;
  4388. #elif defined(WOLFSSL_DEVCRYPTO)
  4389. bench_size = sysconf(_SC_PAGESIZE);
  4390. #endif
  4391. /* init keys */
  4392. XMEMSET(bench_plain, 0, bench_size);
  4393. XMEMSET(tag, 0, sizeof(tag));
  4394. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4395. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4396. useDeviceID ? devId: INVALID_DEVID);
  4397. #ifdef HAVE_RENESAS_SYNC
  4398. wc_GmacSetKey(&gmac, bench_key1, 16);
  4399. #else
  4400. wc_GmacSetKey(&gmac, bench_key, 16);
  4401. #endif
  4402. bench_stats_start(&count, &start);
  4403. do {
  4404. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4405. tag, sizeof(tag));
  4406. count++;
  4407. RECORD_MULTI_VALUE_STATS();
  4408. } while (bench_stats_check(start)
  4409. #ifdef MULTI_VALUE_STATISTICS
  4410. || runs < minimum_runs
  4411. #endif
  4412. );
  4413. wc_AesFree((Aes*)&gmac);
  4414. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4415. #ifdef MULTI_VALUE_STATISTICS
  4416. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4417. #endif
  4418. #if defined(WOLFSSL_DEVCRYPTO)
  4419. if (ret != 0 && (bench_size > sysconf(_SC_PAGESIZE))) {
  4420. printf("authIn Buffer Size[%d] greater than System Page Size[%ld]\n",
  4421. bench_size, sysconf(_SC_PAGESIZE));
  4422. }
  4423. bench_size = BENCH_SIZE;
  4424. #endif
  4425. }
  4426. #endif /* HAVE_AESGCM */
  4427. #ifdef HAVE_AES_ECB
  4428. static void bench_aesecb_internal(int useDeviceID,
  4429. const byte* key, word32 keySz,
  4430. const char* encLabel, const char* decLabel)
  4431. {
  4432. int ret = 0, i, count = 0, times, pending = 0;
  4433. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4434. sizeof(Aes), HEAP_HINT);
  4435. double start;
  4436. DECLARE_MULTI_VALUE_STATS_VARS()
  4437. #ifdef HAVE_FIPS
  4438. const word32 benchSz = WC_AES_BLOCK_SIZE;
  4439. #else
  4440. const word32 benchSz = bench_size;
  4441. #endif
  4442. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4443. sizeof(Aes), HEAP_HINT);
  4444. /* init keys */
  4445. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4446. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4447. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4448. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4449. goto exit;
  4450. }
  4451. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4452. if (ret != 0) {
  4453. printf("AesSetKey failed, ret = %d\n", ret);
  4454. goto exit;
  4455. }
  4456. }
  4457. bench_stats_start(&count, &start);
  4458. do {
  4459. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4460. for (times = 0;
  4461. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4462. ) {
  4463. bench_async_poll(&pending);
  4464. /* while free pending slots in queue, submit ops */
  4465. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4466. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4467. &times, outer_loop_limit, &pending)) {
  4468. #ifdef HAVE_FIPS
  4469. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4470. #else
  4471. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4472. benchSz);
  4473. #endif
  4474. ret = 0;
  4475. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4476. 0, &times, &pending)) {
  4477. goto exit_aes_enc;
  4478. }
  4479. }
  4480. } /* for i */
  4481. RECORD_MULTI_VALUE_STATS();
  4482. } /* for times */
  4483. count += times;
  4484. } while (bench_stats_check(start)
  4485. #ifdef MULTI_VALUE_STATISTICS
  4486. || runs < minimum_runs
  4487. #endif
  4488. );
  4489. exit_aes_enc:
  4490. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4491. start, ret);
  4492. #ifdef MULTI_VALUE_STATISTICS
  4493. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4494. #endif
  4495. #ifdef HAVE_AES_DECRYPT
  4496. /* init keys */
  4497. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4498. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4499. if (ret != 0) {
  4500. printf("AesSetKey failed, ret = %d\n", ret);
  4501. goto exit;
  4502. }
  4503. }
  4504. RESET_MULTI_VALUE_STATS_VARS();
  4505. bench_stats_start(&count, &start);
  4506. do {
  4507. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4508. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4509. bench_async_poll(&pending);
  4510. /* while free pending slots in queue, submit ops */
  4511. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4512. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4513. &times, outer_loop_limit, &pending)) {
  4514. #ifdef HAVE_FIPS
  4515. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4516. #else
  4517. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4518. benchSz);
  4519. #endif
  4520. ret = 0;
  4521. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4522. 0, &times, &pending)) {
  4523. goto exit_aes_dec;
  4524. }
  4525. }
  4526. } /* for i */
  4527. RECORD_MULTI_VALUE_STATS();
  4528. } /* for times */
  4529. count += times;
  4530. } while (bench_stats_check(start)
  4531. #ifdef MULTI_VALUE_STATISTICS
  4532. || runs < minimum_runs
  4533. #endif
  4534. );
  4535. exit_aes_dec:
  4536. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4537. start, ret);
  4538. #ifdef MULTI_VALUE_STATISTICS
  4539. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4540. #endif
  4541. #endif /* HAVE_AES_DECRYPT */
  4542. (void)decLabel;
  4543. exit:
  4544. if (WC_ARRAY_OK(enc)) {
  4545. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4546. wc_AesFree(enc[i]);
  4547. }
  4548. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4549. }
  4550. }
  4551. void bench_aesecb(int useDeviceID)
  4552. {
  4553. #ifdef WOLFSSL_AES_128
  4554. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4555. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4556. #endif
  4557. #ifdef WOLFSSL_AES_192
  4558. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4559. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4560. #endif
  4561. #ifdef WOLFSSL_AES_256
  4562. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4563. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4564. #endif
  4565. }
  4566. #endif /* HAVE_AES_ECB */
  4567. #ifdef WOLFSSL_AES_CFB
  4568. static void bench_aescfb_internal(const byte* key,
  4569. word32 keySz, const byte* iv,
  4570. const char* label)
  4571. {
  4572. Aes enc;
  4573. double start;
  4574. int i, ret, count;
  4575. DECLARE_MULTI_VALUE_STATS_VARS()
  4576. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4577. if (ret != 0) {
  4578. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4579. return;
  4580. }
  4581. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4582. if (ret != 0) {
  4583. printf("AesSetKey failed, ret = %d\n", ret);
  4584. goto out;
  4585. }
  4586. bench_stats_start(&count, &start);
  4587. do {
  4588. for (i = 0; i < numBlocks; i++) {
  4589. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4590. bench_size)) != 0) {
  4591. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4592. goto out;
  4593. }
  4594. RECORD_MULTI_VALUE_STATS();
  4595. }
  4596. count += i;
  4597. } while (bench_stats_check(start)
  4598. #ifdef MULTI_VALUE_STATISTICS
  4599. || runs < minimum_runs
  4600. #endif
  4601. );
  4602. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4603. #ifdef MULTI_VALUE_STATISTICS
  4604. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4605. #endif
  4606. out:
  4607. wc_AesFree(&enc);
  4608. return;
  4609. }
  4610. void bench_aescfb(void)
  4611. {
  4612. #ifdef WOLFSSL_AES_128
  4613. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4614. #endif
  4615. #ifdef WOLFSSL_AES_192
  4616. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4617. #endif
  4618. #ifdef WOLFSSL_AES_256
  4619. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4620. #endif
  4621. }
  4622. #endif /* WOLFSSL_AES_CFB */
  4623. #ifdef WOLFSSL_AES_OFB
  4624. static void bench_aesofb_internal(const byte* key,
  4625. word32 keySz, const byte* iv,
  4626. const char* label)
  4627. {
  4628. Aes enc;
  4629. double start;
  4630. int i, ret, count;
  4631. DECLARE_MULTI_VALUE_STATS_VARS()
  4632. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4633. if (ret != 0) {
  4634. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4635. return;
  4636. }
  4637. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4638. if (ret != 0) {
  4639. printf("AesSetKey failed, ret = %d\n", ret);
  4640. return;
  4641. }
  4642. bench_stats_start(&count, &start);
  4643. do {
  4644. for (i = 0; i < numBlocks; i++) {
  4645. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4646. bench_size)) != 0) {
  4647. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4648. return;
  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(label, 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_AesFree(&enc);
  4663. }
  4664. void bench_aesofb(void)
  4665. {
  4666. #ifdef WOLFSSL_AES_128
  4667. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4668. #endif
  4669. #ifdef WOLFSSL_AES_192
  4670. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4671. #endif
  4672. #ifdef WOLFSSL_AES_256
  4673. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4674. #endif
  4675. }
  4676. #endif /* WOLFSSL_AES_CFB */
  4677. #ifdef WOLFSSL_AES_XTS
  4678. void bench_aesxts(void)
  4679. {
  4680. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4681. double start;
  4682. int i, count, ret;
  4683. DECLARE_MULTI_VALUE_STATS_VARS()
  4684. static const unsigned char k1[] = {
  4685. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4686. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4687. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4688. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4689. };
  4690. static const unsigned char i1[] = {
  4691. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4692. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4693. };
  4694. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4695. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4696. HEAP_HINT, devId);
  4697. if (ret != 0) {
  4698. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4699. goto exit;
  4700. }
  4701. bench_stats_start(&count, &start);
  4702. do {
  4703. for (i = 0; i < numBlocks; i++) {
  4704. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4705. bench_size, i1, sizeof(i1))) != 0) {
  4706. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4707. goto exit;
  4708. }
  4709. RECORD_MULTI_VALUE_STATS();
  4710. }
  4711. count += i;
  4712. } while (bench_stats_check(start)
  4713. #ifdef MULTI_VALUE_STATISTICS
  4714. || runs < minimum_runs
  4715. #endif
  4716. );
  4717. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4718. #ifdef MULTI_VALUE_STATISTICS
  4719. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4720. #endif
  4721. wc_AesXtsFree(aes);
  4722. /* decryption benchmark */
  4723. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4724. HEAP_HINT, devId);
  4725. if (ret != 0) {
  4726. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4727. goto exit;
  4728. }
  4729. RESET_MULTI_VALUE_STATS_VARS();
  4730. bench_stats_start(&count, &start);
  4731. do {
  4732. for (i = 0; i < numBlocks; i++) {
  4733. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4734. bench_size, i1, sizeof(i1))) != 0) {
  4735. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4736. goto exit;
  4737. }
  4738. RECORD_MULTI_VALUE_STATS();
  4739. }
  4740. count += i;
  4741. } while (bench_stats_check(start)
  4742. #ifdef MULTI_VALUE_STATISTICS
  4743. || runs < minimum_runs
  4744. #endif
  4745. );
  4746. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4747. #ifdef MULTI_VALUE_STATISTICS
  4748. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4749. #endif
  4750. exit:
  4751. wc_AesXtsFree(aes);
  4752. WC_FREE_VAR(aes, HEAP_HINT);
  4753. }
  4754. #endif /* WOLFSSL_AES_XTS */
  4755. #ifdef WOLFSSL_AES_COUNTER
  4756. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4757. const byte* iv, const char* label,
  4758. int useDeviceID)
  4759. {
  4760. Aes enc;
  4761. double start;
  4762. int i, count, ret = 0;
  4763. DECLARE_MULTI_VALUE_STATS_VARS()
  4764. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4765. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4766. printf("wc_AesInit failed, ret = %d\n", ret);
  4767. }
  4768. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4769. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4770. return;
  4771. }
  4772. bench_stats_start(&count, &start);
  4773. do {
  4774. for (i = 0; i < numBlocks; i++) {
  4775. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4776. bench_size)) != 0) {
  4777. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4778. return;
  4779. }
  4780. RECORD_MULTI_VALUE_STATS();
  4781. }
  4782. count += i;
  4783. } while (bench_stats_check(start)
  4784. #ifdef MULTI_VALUE_STATISTICS
  4785. || runs < minimum_runs
  4786. #endif
  4787. );
  4788. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4789. #ifdef MULTI_VALUE_STATISTICS
  4790. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4791. #endif
  4792. wc_AesFree(&enc);
  4793. }
  4794. void bench_aesctr(int useDeviceID)
  4795. {
  4796. #ifdef WOLFSSL_AES_128
  4797. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4798. #endif
  4799. #ifdef WOLFSSL_AES_192
  4800. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4801. #endif
  4802. #ifdef WOLFSSL_AES_256
  4803. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4804. #endif
  4805. }
  4806. #endif /* WOLFSSL_AES_COUNTER */
  4807. #ifdef HAVE_AESCCM
  4808. void bench_aesccm(int useDeviceID)
  4809. {
  4810. Aes enc;
  4811. int enc_inited = 0;
  4812. double start;
  4813. int ret, i, count;
  4814. DECLARE_MULTI_VALUE_STATS_VARS()
  4815. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4816. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4817. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4818. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4819. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4820. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4821. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4822. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4823. {
  4824. printf("wc_AesInit failed, ret = %d\n", ret);
  4825. goto exit;
  4826. }
  4827. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4828. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4829. goto exit;
  4830. }
  4831. enc_inited = 1;
  4832. bench_stats_start(&count, &start);
  4833. do {
  4834. for (i = 0; i < numBlocks; i++) {
  4835. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4836. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4837. bench_additional, 0);
  4838. RECORD_MULTI_VALUE_STATS();
  4839. }
  4840. count += i;
  4841. } while (bench_stats_check(start)
  4842. #ifdef MULTI_VALUE_STATISTICS
  4843. || runs < minimum_runs
  4844. #endif
  4845. );
  4846. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4847. bench_size, start, ret);
  4848. #ifdef MULTI_VALUE_STATISTICS
  4849. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4850. #endif
  4851. if (ret != 0) {
  4852. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4853. goto exit;
  4854. }
  4855. #ifdef HAVE_AES_DECRYPT
  4856. RESET_MULTI_VALUE_STATS_VARS();
  4857. bench_stats_start(&count, &start);
  4858. do {
  4859. for (i = 0; i < numBlocks; i++) {
  4860. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4861. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4862. bench_additional, 0);
  4863. RECORD_MULTI_VALUE_STATS();
  4864. }
  4865. count += i;
  4866. } while (bench_stats_check(start)
  4867. #ifdef MULTI_VALUE_STATISTICS
  4868. || runs < minimum_runs
  4869. #endif
  4870. );
  4871. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4872. bench_size, start, ret);
  4873. #ifdef MULTI_VALUE_STATISTICS
  4874. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4875. #endif
  4876. if (ret != 0) {
  4877. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4878. goto exit;
  4879. }
  4880. #endif
  4881. exit:
  4882. if (enc_inited)
  4883. wc_AesFree(&enc);
  4884. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4885. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4886. }
  4887. #endif /* HAVE_AESCCM */
  4888. #ifdef WOLFSSL_AES_SIV
  4889. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4890. encLabel, const char* decLabel)
  4891. {
  4892. int i;
  4893. int ret = 0;
  4894. byte assoc[WC_AES_BLOCK_SIZE];
  4895. byte nonce[WC_AES_BLOCK_SIZE];
  4896. byte siv[WC_AES_BLOCK_SIZE];
  4897. int count = 0;
  4898. double start;
  4899. DECLARE_MULTI_VALUE_STATS_VARS()
  4900. bench_stats_start(&count, &start);
  4901. do {
  4902. for (i = 0; i < numBlocks; i++) {
  4903. ret = wc_AesSivEncrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4904. WC_AES_BLOCK_SIZE, bench_plain, bench_size,
  4905. siv, bench_cipher);
  4906. if (ret != 0) {
  4907. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4908. return;
  4909. }
  4910. RECORD_MULTI_VALUE_STATS();
  4911. }
  4912. count += i;
  4913. } while (bench_stats_check(start)
  4914. #ifdef MULTI_VALUE_STATISTICS
  4915. || runs < minimum_runs
  4916. #endif
  4917. );
  4918. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4919. #ifdef MULTI_VALUE_STATISTICS
  4920. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4921. #endif
  4922. RESET_MULTI_VALUE_STATS_VARS();
  4923. bench_stats_start(&count, &start);
  4924. do {
  4925. for (i = 0; i < numBlocks; i++) {
  4926. ret = wc_AesSivDecrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4927. WC_AES_BLOCK_SIZE, bench_cipher, bench_size,
  4928. siv, bench_plain);
  4929. if (ret != 0) {
  4930. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4931. return;
  4932. }
  4933. RECORD_MULTI_VALUE_STATS();
  4934. }
  4935. count += i;
  4936. } while (bench_stats_check(start)
  4937. #ifdef MULTI_VALUE_STATISTICS
  4938. || runs < minimum_runs
  4939. #endif
  4940. );
  4941. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4942. #ifdef MULTI_VALUE_STATISTICS
  4943. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4944. #endif
  4945. }
  4946. void bench_aessiv(void)
  4947. {
  4948. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4949. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4950. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4951. }
  4952. #endif /* WOLFSSL_AES_SIV */
  4953. #endif /* !NO_AES */
  4954. #ifdef HAVE_POLY1305
  4955. void bench_poly1305(void)
  4956. {
  4957. Poly1305 enc;
  4958. byte mac[16];
  4959. double start;
  4960. int ret = 0, i, count;
  4961. DECLARE_MULTI_VALUE_STATS_VARS()
  4962. if (digest_stream) {
  4963. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4964. if (ret != 0) {
  4965. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4966. return;
  4967. }
  4968. bench_stats_start(&count, &start);
  4969. do {
  4970. for (i = 0; i < numBlocks; i++) {
  4971. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4972. if (ret != 0) {
  4973. printf("Poly1305Update failed: %d\n", ret);
  4974. break;
  4975. }
  4976. RECORD_MULTI_VALUE_STATS();
  4977. }
  4978. wc_Poly1305Final(&enc, mac);
  4979. count += i;
  4980. } while (bench_stats_check(start)
  4981. #ifdef MULTI_VALUE_STATISTICS
  4982. || runs < minimum_runs
  4983. #endif
  4984. );
  4985. }
  4986. else {
  4987. bench_stats_start(&count, &start);
  4988. do {
  4989. for (i = 0; i < numBlocks; i++) {
  4990. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4991. if (ret != 0) {
  4992. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4993. return;
  4994. }
  4995. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4996. if (ret != 0) {
  4997. printf("Poly1305Update failed: %d\n", ret);
  4998. break;
  4999. }
  5000. wc_Poly1305Final(&enc, mac);
  5001. RECORD_MULTI_VALUE_STATS();
  5002. }
  5003. count += i;
  5004. } while (bench_stats_check(start)
  5005. #ifdef MULTI_VALUE_STATISTICS
  5006. || runs < minimum_runs
  5007. #endif
  5008. );
  5009. }
  5010. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  5011. #ifdef MULTI_VALUE_STATISTICS
  5012. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5013. #endif
  5014. }
  5015. #endif /* HAVE_POLY1305 */
  5016. #ifdef HAVE_CAMELLIA
  5017. void bench_camellia(void)
  5018. {
  5019. wc_Camellia cam;
  5020. double start;
  5021. int ret, i, count;
  5022. DECLARE_MULTI_VALUE_STATS_VARS()
  5023. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  5024. if (ret != 0) {
  5025. printf("CamelliaSetKey failed, ret = %d\n", ret);
  5026. return;
  5027. }
  5028. bench_stats_start(&count, &start);
  5029. do {
  5030. for (i = 0; i < numBlocks; i++) {
  5031. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  5032. bench_size);
  5033. if (ret < 0) {
  5034. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  5035. return;
  5036. }
  5037. RECORD_MULTI_VALUE_STATS();
  5038. }
  5039. count += i;
  5040. } while (bench_stats_check(start)
  5041. #ifdef MULTI_VALUE_STATISTICS
  5042. || runs < minimum_runs
  5043. #endif
  5044. );
  5045. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  5046. #ifdef MULTI_VALUE_STATISTICS
  5047. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5048. #endif
  5049. }
  5050. #endif
  5051. #ifdef WOLFSSL_SM4_CBC
  5052. void bench_sm4_cbc(void)
  5053. {
  5054. wc_Sm4 sm4;
  5055. double start;
  5056. int ret;
  5057. int i;
  5058. int count;
  5059. DECLARE_MULTI_VALUE_STATS_VARS()
  5060. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5061. if (ret != 0) {
  5062. printf("Sm4SetKey failed, ret = %d\n", ret);
  5063. return;
  5064. }
  5065. ret = wc_Sm4SetIV(&sm4, bench_iv);
  5066. if (ret != 0) {
  5067. printf("Sm4SetIV failed, ret = %d\n", ret);
  5068. return;
  5069. }
  5070. bench_stats_start(&count, &start);
  5071. do {
  5072. for (i = 0; i < numBlocks; i++) {
  5073. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  5074. if (ret < 0) {
  5075. printf("Sm4CbcEncrypt failed: %d\n", ret);
  5076. return;
  5077. }
  5078. RECORD_MULTI_VALUE_STATS();
  5079. }
  5080. count += i;
  5081. } while (bench_stats_check(start)
  5082. #ifdef MULTI_VALUE_STATISTICS
  5083. || runs < minimum_runs
  5084. #endif
  5085. );
  5086. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5087. #ifdef MULTI_VALUE_STATISTICS
  5088. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5089. #endif
  5090. RESET_MULTI_VALUE_STATS_VARS();
  5091. bench_stats_start(&count, &start);
  5092. do {
  5093. for (i = 0; i < numBlocks; i++) {
  5094. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5095. if (ret < 0) {
  5096. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5097. return;
  5098. }
  5099. RECORD_MULTI_VALUE_STATS();
  5100. }
  5101. count += i;
  5102. } while (bench_stats_check(start)
  5103. #ifdef MULTI_VALUE_STATISTICS
  5104. || runs < minimum_runs
  5105. #endif
  5106. );
  5107. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5108. #ifdef MULTI_VALUE_STATISTICS
  5109. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5110. #endif
  5111. }
  5112. #endif
  5113. #ifdef WOLFSSL_SM4_GCM
  5114. void bench_sm4_gcm(void)
  5115. {
  5116. wc_Sm4 sm4;
  5117. double start;
  5118. int ret;
  5119. int i;
  5120. int count;
  5121. DECLARE_MULTI_VALUE_STATS_VARS()
  5122. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5123. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5124. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5125. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5126. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5127. if (ret != 0) {
  5128. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5129. goto exit;
  5130. }
  5131. bench_stats_start(&count, &start);
  5132. do {
  5133. for (i = 0; i < numBlocks; i++) {
  5134. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5135. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5136. bench_additional, aesAuthAddSz);
  5137. if (ret < 0) {
  5138. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5139. goto exit;
  5140. }
  5141. RECORD_MULTI_VALUE_STATS();
  5142. }
  5143. count += i;
  5144. } while (bench_stats_check(start)
  5145. #ifdef MULTI_VALUE_STATISTICS
  5146. || runs < minimum_runs
  5147. #endif
  5148. );
  5149. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5150. #ifdef MULTI_VALUE_STATISTICS
  5151. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5152. #endif
  5153. RESET_MULTI_VALUE_STATS_VARS();
  5154. bench_stats_start(&count, &start);
  5155. do {
  5156. for (i = 0; i < numBlocks; i++) {
  5157. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5158. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5159. bench_additional, aesAuthAddSz);
  5160. if (ret < 0) {
  5161. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5162. goto exit;
  5163. }
  5164. RECORD_MULTI_VALUE_STATS();
  5165. }
  5166. count += i;
  5167. } while (bench_stats_check(start)
  5168. #ifdef MULTI_VALUE_STATISTICS
  5169. || runs < minimum_runs
  5170. #endif
  5171. );
  5172. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5173. #ifdef MULTI_VALUE_STATISTICS
  5174. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5175. #endif
  5176. exit:
  5177. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5178. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5179. }
  5180. #endif
  5181. #ifdef WOLFSSL_SM4_CCM
  5182. void bench_sm4_ccm(void)
  5183. {
  5184. wc_Sm4 enc;
  5185. double start;
  5186. int ret, i, count;
  5187. DECLARE_MULTI_VALUE_STATS_VARS()
  5188. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5189. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5190. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5191. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5192. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5193. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5194. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5195. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5196. goto exit;
  5197. }
  5198. bench_stats_start(&count, &start);
  5199. do {
  5200. for (i = 0; i < numBlocks; i++) {
  5201. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5202. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5203. bench_additional, 0);
  5204. RECORD_MULTI_VALUE_STATS();
  5205. }
  5206. count += i;
  5207. } while (bench_stats_check(start)
  5208. #ifdef MULTI_VALUE_STATISTICS
  5209. || runs < minimum_runs
  5210. #endif
  5211. );
  5212. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5213. #ifdef MULTI_VALUE_STATISTICS
  5214. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5215. #endif
  5216. if (ret != 0) {
  5217. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5218. goto exit;
  5219. }
  5220. RESET_MULTI_VALUE_STATS_VARS();
  5221. bench_stats_start(&count, &start);
  5222. do {
  5223. for (i = 0; i < numBlocks; i++) {
  5224. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5225. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5226. bench_additional, 0);
  5227. RECORD_MULTI_VALUE_STATS();
  5228. }
  5229. count += i;
  5230. } while (bench_stats_check(start)
  5231. #ifdef MULTI_VALUE_STATISTICS
  5232. || runs < minimum_runs
  5233. #endif
  5234. );
  5235. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5236. #ifdef MULTI_VALUE_STATISTICS
  5237. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5238. #endif
  5239. if (ret != 0) {
  5240. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5241. goto exit;
  5242. }
  5243. exit:
  5244. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5245. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5246. }
  5247. #endif /* HAVE_AESCCM */
  5248. #ifndef NO_DES3
  5249. void bench_des(int useDeviceID)
  5250. {
  5251. int ret = 0, i, count = 0, times, pending = 0;
  5252. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5253. sizeof(Des3), HEAP_HINT);
  5254. double start;
  5255. DECLARE_MULTI_VALUE_STATS_VARS()
  5256. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5257. sizeof(Des3), HEAP_HINT);
  5258. /* init keys */
  5259. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5260. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5261. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5262. printf("Des3Init failed, ret = %d\n", ret);
  5263. goto exit;
  5264. }
  5265. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5266. if (ret != 0) {
  5267. printf("Des3_SetKey failed, ret = %d\n", ret);
  5268. goto exit;
  5269. }
  5270. }
  5271. bench_stats_start(&count, &start);
  5272. do {
  5273. for (times = 0; times < numBlocks || pending > 0; ) {
  5274. bench_async_poll(&pending);
  5275. /* while free pending slots in queue, submit ops */
  5276. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5277. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5278. &times, numBlocks, &pending)) {
  5279. ret = wc_Des3_CbcEncrypt(enc[i],
  5280. bench_cipher,
  5281. bench_plain, bench_size);
  5282. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5283. 0, &times, &pending)) {
  5284. goto exit_3des;
  5285. }
  5286. }
  5287. } /* for i */
  5288. RECORD_MULTI_VALUE_STATS();
  5289. } /* for times */
  5290. count += times;
  5291. } while (bench_stats_check(start)
  5292. #ifdef MULTI_VALUE_STATISTICS
  5293. || runs < minimum_runs
  5294. #endif
  5295. );
  5296. exit_3des:
  5297. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5298. #ifdef MULTI_VALUE_STATISTICS
  5299. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5300. #endif
  5301. exit:
  5302. if (WC_ARRAY_OK(enc)) {
  5303. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5304. wc_Des3Free(enc[i]);
  5305. }
  5306. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5307. }
  5308. }
  5309. #endif /* !NO_DES3 */
  5310. #ifndef NO_RC4
  5311. void bench_arc4(int useDeviceID)
  5312. {
  5313. int ret = 0, i, count = 0, times, pending = 0;
  5314. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5315. sizeof(Arc4), HEAP_HINT);
  5316. double start;
  5317. DECLARE_MULTI_VALUE_STATS_VARS()
  5318. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5319. sizeof(Arc4), HEAP_HINT);
  5320. /* init keys */
  5321. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5322. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5323. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5324. printf("Arc4Init failed, ret = %d\n", ret);
  5325. goto exit;
  5326. }
  5327. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5328. if (ret != 0) {
  5329. printf("Arc4SetKey failed, ret = %d\n", ret);
  5330. goto exit;
  5331. }
  5332. }
  5333. bench_stats_start(&count, &start);
  5334. do {
  5335. for (times = 0; times < numBlocks || pending > 0; ) {
  5336. bench_async_poll(&pending);
  5337. /* while free pending slots in queue, submit ops */
  5338. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5339. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5340. &times, numBlocks, &pending)) {
  5341. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5342. bench_size);
  5343. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5344. 0, &times, &pending)) {
  5345. goto exit_arc4;
  5346. }
  5347. }
  5348. } /* for i */
  5349. RECORD_MULTI_VALUE_STATS();
  5350. } /* for times */
  5351. count += times;
  5352. } while (bench_stats_check(start)
  5353. #ifdef MULTI_VALUE_STATISTICS
  5354. || runs < minimum_runs
  5355. #endif
  5356. );
  5357. exit_arc4:
  5358. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5359. #ifdef MULTI_VALUE_STATISTICS
  5360. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5361. #endif
  5362. exit:
  5363. if (WC_ARRAY_OK(enc)) {
  5364. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5365. wc_Arc4Free(enc[i]);
  5366. }
  5367. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5368. }
  5369. }
  5370. #endif /* !NO_RC4 */
  5371. #ifdef HAVE_CHACHA
  5372. void bench_chacha(void)
  5373. {
  5374. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5375. double start;
  5376. int ret, i, count;
  5377. DECLARE_MULTI_VALUE_STATS_VARS()
  5378. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5379. XMEMSET(enc, 0, sizeof(ChaCha));
  5380. wc_Chacha_SetKey(enc, bench_key, 16);
  5381. if (encrypt_only) {
  5382. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5383. if (ret < 0) {
  5384. printf("wc_Chacha_SetIV error: %d\n", ret);
  5385. goto exit;
  5386. }
  5387. bench_stats_start(&count, &start);
  5388. do {
  5389. for (i = 0; i < numBlocks; i++) {
  5390. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5391. bench_size);
  5392. if (ret < 0) {
  5393. printf("wc_Chacha_Process 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. }
  5405. else {
  5406. bench_stats_start(&count, &start);
  5407. do {
  5408. for (i = 0; i < numBlocks; i++) {
  5409. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5410. if (ret < 0) {
  5411. printf("wc_Chacha_SetIV error: %d\n", ret);
  5412. goto exit;
  5413. }
  5414. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5415. bench_size);
  5416. if (ret < 0) {
  5417. printf("wc_Chacha_Process error: %d\n", ret);
  5418. goto exit;
  5419. }
  5420. RECORD_MULTI_VALUE_STATS();
  5421. }
  5422. count += i;
  5423. } while (bench_stats_check(start)
  5424. #ifdef MULTI_VALUE_STATISTICS
  5425. || runs < minimum_runs
  5426. #endif
  5427. );
  5428. }
  5429. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5430. #ifdef MULTI_VALUE_STATISTICS
  5431. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5432. #endif
  5433. exit:
  5434. WC_FREE_VAR(enc, HEAP_HINT);
  5435. }
  5436. #endif /* HAVE_CHACHA*/
  5437. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5438. void bench_chacha20_poly1305_aead(void)
  5439. {
  5440. double start;
  5441. int ret = 0, i, count;
  5442. DECLARE_MULTI_VALUE_STATS_VARS()
  5443. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5444. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5445. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5446. bench_stats_start(&count, &start);
  5447. do {
  5448. for (i = 0; i < numBlocks; i++) {
  5449. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5450. bench_plain, bench_size, bench_cipher, authTag);
  5451. if (ret < 0) {
  5452. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5453. goto exit;
  5454. }
  5455. RECORD_MULTI_VALUE_STATS();
  5456. }
  5457. count += i;
  5458. } while (bench_stats_check(start)
  5459. #ifdef MULTI_VALUE_STATISTICS
  5460. || runs < minimum_runs
  5461. #endif
  5462. );
  5463. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5464. #ifdef MULTI_VALUE_STATISTICS
  5465. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5466. #endif
  5467. exit:
  5468. WC_FREE_VAR(authTag, HEAP_HINT);
  5469. }
  5470. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5471. #ifndef NO_MD5
  5472. void bench_md5(int useDeviceID)
  5473. {
  5474. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5475. sizeof(wc_Md5), HEAP_HINT);
  5476. double start = 0;
  5477. int ret = 0, i, count = 0, times, pending = 0;
  5478. DECLARE_MULTI_VALUE_STATS_VARS()
  5479. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5480. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5481. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5482. sizeof(wc_Md5), HEAP_HINT);
  5483. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5484. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5485. if (digest_stream) {
  5486. /* init keys */
  5487. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5488. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5489. useDeviceID ? devId : INVALID_DEVID);
  5490. if (ret != 0) {
  5491. printf("InitMd5_ex failed, ret = %d\n", ret);
  5492. goto exit;
  5493. }
  5494. #ifdef WOLFSSL_PIC32MZ_HASH
  5495. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5496. #endif
  5497. }
  5498. bench_stats_start(&count, &start);
  5499. do {
  5500. for (times = 0; times < numBlocks || pending > 0; ) {
  5501. bench_async_poll(&pending);
  5502. /* while free pending slots in queue, submit ops */
  5503. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5504. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5505. 0, &times, numBlocks, &pending)) {
  5506. ret = wc_Md5Update(hash[i], bench_plain,
  5507. bench_size);
  5508. if (!bench_async_handle(&ret,
  5509. BENCH_ASYNC_GET_DEV(hash[i]),
  5510. 0, &times, &pending)) {
  5511. goto exit_md5;
  5512. }
  5513. }
  5514. } /* for i */
  5515. RECORD_MULTI_VALUE_STATS();
  5516. } /* for times */
  5517. count += times;
  5518. times = 0;
  5519. do {
  5520. bench_async_poll(&pending);
  5521. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5522. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5523. 0, &times, numBlocks, &pending)) {
  5524. ret = wc_Md5Final(hash[i], digest[i]);
  5525. if (!bench_async_handle(&ret,
  5526. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5527. &times, &pending)) {
  5528. goto exit_md5;
  5529. }
  5530. }
  5531. } /* for i */
  5532. } while (pending > 0);
  5533. } while (bench_stats_check(start)
  5534. #ifdef MULTI_VALUE_STATISTICS
  5535. || runs < minimum_runs
  5536. #endif
  5537. );
  5538. }
  5539. else {
  5540. bench_stats_start(&count, &start);
  5541. do {
  5542. for (times = 0; times < numBlocks; times++) {
  5543. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5544. if (ret == 0)
  5545. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5546. if (ret == 0)
  5547. ret = wc_Md5Final(hash[0], digest[0]);
  5548. if (ret != 0)
  5549. goto exit_md5;
  5550. RECORD_MULTI_VALUE_STATS();
  5551. } /* for times */
  5552. count += times;
  5553. } while (bench_stats_check(start)
  5554. #ifdef MULTI_VALUE_STATISTICS
  5555. || runs < minimum_runs
  5556. #endif
  5557. );
  5558. }
  5559. exit_md5:
  5560. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5561. #ifdef MULTI_VALUE_STATISTICS
  5562. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5563. #endif
  5564. exit:
  5565. #ifdef WOLFSSL_ASYNC_CRYPT
  5566. if (WC_ARRAY_OK(hash)) {
  5567. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5568. wc_Md5Free(hash[i]);
  5569. }
  5570. }
  5571. #endif
  5572. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5573. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5574. }
  5575. #endif /* !NO_MD5 */
  5576. #ifndef NO_SHA
  5577. void bench_sha(int useDeviceID)
  5578. {
  5579. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5580. sizeof(wc_Sha), HEAP_HINT);
  5581. double start;
  5582. int ret = 0, i, count = 0, times, pending = 0;
  5583. DECLARE_MULTI_VALUE_STATS_VARS()
  5584. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5585. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5586. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5587. sizeof(wc_Sha), HEAP_HINT);
  5588. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5589. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5590. if (digest_stream) {
  5591. /* init keys */
  5592. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5593. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5594. useDeviceID ? devId : INVALID_DEVID);
  5595. if (ret != 0) {
  5596. printf("InitSha failed, ret = %d\n", ret);
  5597. goto exit;
  5598. }
  5599. #ifdef WOLFSSL_PIC32MZ_HASH
  5600. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5601. #endif
  5602. }
  5603. bench_stats_start(&count, &start);
  5604. do {
  5605. for (times = 0; times < numBlocks || pending > 0; ) {
  5606. bench_async_poll(&pending);
  5607. /* while free pending slots in queue, submit ops */
  5608. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5609. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5610. 0, &times, numBlocks, &pending)) {
  5611. ret = wc_ShaUpdate(hash[i], bench_plain,
  5612. bench_size);
  5613. if (!bench_async_handle(&ret,
  5614. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5615. &times, &pending)) {
  5616. goto exit_sha;
  5617. }
  5618. }
  5619. } /* for i */
  5620. RECORD_MULTI_VALUE_STATS();
  5621. } /* for times */
  5622. count += times;
  5623. times = 0;
  5624. do {
  5625. bench_async_poll(&pending);
  5626. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5627. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5628. 0, &times, numBlocks, &pending)) {
  5629. ret = wc_ShaFinal(hash[i], digest[i]);
  5630. if (!bench_async_handle(&ret,
  5631. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5632. &times, &pending)) {
  5633. goto exit_sha;
  5634. }
  5635. }
  5636. } /* for i */
  5637. } while (pending > 0);
  5638. } while (bench_stats_check(start)
  5639. #ifdef MULTI_VALUE_STATISTICS
  5640. || runs < minimum_runs
  5641. #endif
  5642. );
  5643. }
  5644. else {
  5645. bench_stats_start(&count, &start);
  5646. do {
  5647. for (times = 0; times < numBlocks; times++) {
  5648. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5649. useDeviceID ? devId : INVALID_DEVID);
  5650. if (ret == 0)
  5651. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5652. if (ret == 0)
  5653. ret = wc_ShaFinal(hash[0], digest[0]);
  5654. if (ret != 0)
  5655. goto exit_sha;
  5656. RECORD_MULTI_VALUE_STATS();
  5657. } /* for times */
  5658. count += times;
  5659. } while (bench_stats_check(start)
  5660. #ifdef MULTI_VALUE_STATISTICS
  5661. || runs < minimum_runs
  5662. #endif
  5663. );
  5664. }
  5665. exit_sha:
  5666. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5667. #ifdef MULTI_VALUE_STATISTICS
  5668. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5669. #endif
  5670. exit:
  5671. if (WC_ARRAY_OK(hash)) {
  5672. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5673. wc_ShaFree(hash[i]);
  5674. }
  5675. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5676. }
  5677. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5678. }
  5679. #endif /* NO_SHA */
  5680. #ifdef WOLFSSL_SHA224
  5681. void bench_sha224(int useDeviceID)
  5682. {
  5683. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5684. sizeof(wc_Sha224), HEAP_HINT);
  5685. double start;
  5686. int ret = 0, i, count = 0, times, pending = 0;
  5687. DECLARE_MULTI_VALUE_STATS_VARS()
  5688. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5689. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5690. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5691. sizeof(wc_Sha224), HEAP_HINT);
  5692. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5693. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5694. if (digest_stream) {
  5695. /* init keys */
  5696. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5697. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5698. useDeviceID ? devId : INVALID_DEVID);
  5699. if (ret != 0) {
  5700. printf("InitSha224_ex failed, ret = %d\n", ret);
  5701. goto exit;
  5702. }
  5703. }
  5704. bench_stats_start(&count, &start);
  5705. do {
  5706. for (times = 0; times < numBlocks || pending > 0; ) {
  5707. bench_async_poll(&pending);
  5708. /* while free pending slots in queue, submit ops */
  5709. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5710. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5711. 0, &times, numBlocks, &pending)) {
  5712. ret = wc_Sha224Update(hash[i], bench_plain,
  5713. bench_size);
  5714. if (!bench_async_handle(&ret,
  5715. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5716. &times, &pending)) {
  5717. goto exit_sha224;
  5718. }
  5719. }
  5720. } /* for i */
  5721. RECORD_MULTI_VALUE_STATS();
  5722. } /* for times */
  5723. count += times;
  5724. times = 0;
  5725. do {
  5726. bench_async_poll(&pending);
  5727. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5728. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5729. 0, &times, numBlocks, &pending)) {
  5730. ret = wc_Sha224Final(hash[i], digest[i]);
  5731. if (!bench_async_handle(&ret,
  5732. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5733. &times, &pending)) {
  5734. goto exit_sha224;
  5735. }
  5736. }
  5737. } /* for i */
  5738. } while (pending > 0);
  5739. } while (bench_stats_check(start)
  5740. #ifdef MULTI_VALUE_STATISTICS
  5741. || runs < minimum_runs
  5742. #endif
  5743. );
  5744. }
  5745. else {
  5746. bench_stats_start(&count, &start);
  5747. do {
  5748. for (times = 0; times < numBlocks; times++) {
  5749. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5750. useDeviceID ? devId : INVALID_DEVID);
  5751. if (ret == 0)
  5752. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5753. if (ret == 0)
  5754. ret = wc_Sha224Final(hash[0], digest[0]);
  5755. if (ret != 0)
  5756. goto exit_sha224;
  5757. } /* for times */
  5758. count += times;
  5759. } while (bench_stats_check(start)
  5760. #ifdef MULTI_VALUE_STATISTICS
  5761. || runs < minimum_runs
  5762. #endif
  5763. );
  5764. }
  5765. exit_sha224:
  5766. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5767. bench_size, start, ret);
  5768. #ifdef MULTI_VALUE_STATISTICS
  5769. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5770. #endif
  5771. exit:
  5772. if (WC_ARRAY_OK(hash)) {
  5773. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5774. wc_Sha224Free(hash[i]);
  5775. }
  5776. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5777. }
  5778. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5779. }
  5780. #endif
  5781. #ifndef NO_SHA256
  5782. void bench_sha256(int useDeviceID)
  5783. {
  5784. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5785. sizeof(wc_Sha256), HEAP_HINT);
  5786. double start;
  5787. int ret = 0, i, count = 0, times, pending = 0;
  5788. DECLARE_MULTI_VALUE_STATS_VARS()
  5789. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5790. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5791. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5792. sizeof(wc_Sha256), HEAP_HINT);
  5793. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5794. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5795. if (digest_stream) {
  5796. /* init keys */
  5797. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5798. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5799. useDeviceID ? devId: INVALID_DEVID);
  5800. if (ret != 0) {
  5801. printf("InitSha256_ex failed, ret = %d\n", ret);
  5802. goto exit;
  5803. }
  5804. #ifdef WOLFSSL_PIC32MZ_HASH
  5805. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5806. #endif
  5807. }
  5808. bench_stats_start(&count, &start);
  5809. do {
  5810. for (times = 0; times < numBlocks || pending > 0; ) {
  5811. bench_async_poll(&pending);
  5812. /* while free pending slots in queue, submit ops */
  5813. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5814. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5815. 0, &times, numBlocks, &pending)) {
  5816. ret = wc_Sha256Update(hash[i], bench_plain,
  5817. bench_size);
  5818. if (!bench_async_handle(&ret,
  5819. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5820. &times, &pending)) {
  5821. goto exit_sha256;
  5822. }
  5823. }
  5824. } /* for i */
  5825. RECORD_MULTI_VALUE_STATS();
  5826. } /* for times */
  5827. count += times;
  5828. times = 0;
  5829. do {
  5830. bench_async_poll(&pending);
  5831. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5832. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5833. 0, &times, numBlocks, &pending)) {
  5834. ret = wc_Sha256Final(hash[i], digest[i]);
  5835. if (!bench_async_handle(&ret,
  5836. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5837. &times, &pending)) {
  5838. goto exit_sha256;
  5839. }
  5840. }
  5841. } /* for i */
  5842. } while (pending > 0);
  5843. } while (bench_stats_check(start)
  5844. #ifdef MULTI_VALUE_STATISTICS
  5845. || runs < minimum_runs
  5846. #endif
  5847. );
  5848. }
  5849. else {
  5850. bench_stats_start(&count, &start);
  5851. do {
  5852. for (times = 0; times < numBlocks; times++) {
  5853. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5854. useDeviceID ? devId: INVALID_DEVID);
  5855. if (ret == 0)
  5856. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5857. if (ret == 0)
  5858. ret = wc_Sha256Final(hash[0], digest[0]);
  5859. if (ret != 0)
  5860. goto exit_sha256;
  5861. RECORD_MULTI_VALUE_STATS();
  5862. } /* for times */
  5863. count += times;
  5864. } while (bench_stats_check(start)
  5865. #ifdef MULTI_VALUE_STATISTICS
  5866. || runs < minimum_runs
  5867. #endif
  5868. );
  5869. }
  5870. exit_sha256:
  5871. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5872. start, ret);
  5873. #ifdef MULTI_VALUE_STATISTICS
  5874. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5875. #endif
  5876. exit:
  5877. if (WC_ARRAY_OK(hash)) {
  5878. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5879. wc_Sha256Free(hash[i]);
  5880. }
  5881. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5882. }
  5883. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5884. }
  5885. #endif
  5886. #ifdef WOLFSSL_SHA384
  5887. void bench_sha384(int useDeviceID)
  5888. {
  5889. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5890. sizeof(wc_Sha384), HEAP_HINT);
  5891. double start;
  5892. int ret = 0, i, count = 0, times, pending = 0;
  5893. DECLARE_MULTI_VALUE_STATS_VARS()
  5894. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5895. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5896. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5897. sizeof(wc_Sha384), HEAP_HINT);
  5898. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5899. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5900. if (digest_stream) {
  5901. /* init keys */
  5902. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5903. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5904. useDeviceID ? devId : INVALID_DEVID);
  5905. if (ret != 0) {
  5906. printf("InitSha384_ex failed, ret = %d\n", ret);
  5907. goto exit;
  5908. }
  5909. }
  5910. bench_stats_start(&count, &start);
  5911. do {
  5912. for (times = 0; times < numBlocks || pending > 0; ) {
  5913. bench_async_poll(&pending);
  5914. /* while free pending slots in queue, submit ops */
  5915. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5916. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5917. 0, &times, numBlocks, &pending)) {
  5918. ret = wc_Sha384Update(hash[i], bench_plain,
  5919. bench_size);
  5920. if (!bench_async_handle(&ret,
  5921. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5922. &times, &pending)) {
  5923. goto exit_sha384;
  5924. }
  5925. }
  5926. } /* for i */
  5927. RECORD_MULTI_VALUE_STATS();
  5928. } /* for times */
  5929. count += times;
  5930. times = 0;
  5931. do {
  5932. bench_async_poll(&pending);
  5933. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5934. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5935. 0, &times, numBlocks, &pending)) {
  5936. ret = wc_Sha384Final(hash[i], digest[i]);
  5937. if (!bench_async_handle(&ret,
  5938. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5939. &times, &pending)) {
  5940. goto exit_sha384;
  5941. }
  5942. }
  5943. } /* for i */
  5944. } while (pending > 0);
  5945. } while (bench_stats_check(start)
  5946. #ifdef MULTI_VALUE_STATISTICS
  5947. || runs < minimum_runs
  5948. #endif
  5949. );
  5950. }
  5951. else {
  5952. bench_stats_start(&count, &start);
  5953. do {
  5954. for (times = 0; times < numBlocks; times++) {
  5955. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5956. useDeviceID ? devId : INVALID_DEVID);
  5957. if (ret == 0)
  5958. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5959. if (ret == 0)
  5960. ret = wc_Sha384Final(hash[0], digest[0]);
  5961. if (ret != 0)
  5962. goto exit_sha384;
  5963. RECORD_MULTI_VALUE_STATS();
  5964. } /* for times */
  5965. count += times;
  5966. } while (bench_stats_check(start)
  5967. #ifdef MULTI_VALUE_STATISTICS
  5968. || runs < minimum_runs
  5969. #endif
  5970. );
  5971. }
  5972. exit_sha384:
  5973. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5974. start, ret);
  5975. #ifdef MULTI_VALUE_STATISTICS
  5976. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5977. #endif
  5978. exit:
  5979. if (WC_ARRAY_OK(hash)) {
  5980. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5981. wc_Sha384Free(hash[i]);
  5982. }
  5983. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5984. }
  5985. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5986. }
  5987. #endif
  5988. #ifdef WOLFSSL_SHA512
  5989. void bench_sha512(int useDeviceID)
  5990. {
  5991. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5992. sizeof(wc_Sha512), HEAP_HINT);
  5993. double start;
  5994. int ret = 0, i, count = 0, times, pending = 0;
  5995. DECLARE_MULTI_VALUE_STATS_VARS()
  5996. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5997. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5998. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5999. sizeof(wc_Sha512), HEAP_HINT);
  6000. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6001. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  6002. if (digest_stream) {
  6003. /* init keys */
  6004. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6005. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  6006. useDeviceID ? devId : INVALID_DEVID);
  6007. if (ret != 0) {
  6008. printf("InitSha512_ex failed, ret = %d\n", ret);
  6009. goto exit;
  6010. }
  6011. }
  6012. bench_stats_start(&count, &start);
  6013. do {
  6014. for (times = 0; times < numBlocks || pending > 0; ) {
  6015. bench_async_poll(&pending);
  6016. /* while free pending slots in queue, submit ops */
  6017. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6018. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6019. 0, &times, numBlocks, &pending)) {
  6020. ret = wc_Sha512Update(hash[i], bench_plain,
  6021. bench_size);
  6022. if (!bench_async_handle(&ret,
  6023. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6024. &times, &pending)) {
  6025. goto exit_sha512;
  6026. }
  6027. }
  6028. } /* for i */
  6029. RECORD_MULTI_VALUE_STATS();
  6030. } /* for times */
  6031. count += times;
  6032. times = 0;
  6033. do {
  6034. bench_async_poll(&pending);
  6035. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6036. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6037. 0, &times, numBlocks, &pending)) {
  6038. ret = wc_Sha512Final(hash[i], digest[i]);
  6039. if (!bench_async_handle(&ret,
  6040. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6041. &times, &pending)) {
  6042. goto exit_sha512;
  6043. }
  6044. }
  6045. } /* for i */
  6046. } while (pending > 0);
  6047. } while (bench_stats_check(start)
  6048. #ifdef MULTI_VALUE_STATISTICS
  6049. || runs < minimum_runs
  6050. #endif
  6051. );
  6052. }
  6053. else {
  6054. bench_stats_start(&count, &start);
  6055. do {
  6056. for (times = 0; times < numBlocks; times++) {
  6057. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  6058. useDeviceID ? devId : INVALID_DEVID);
  6059. if (ret == 0)
  6060. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  6061. if (ret == 0)
  6062. ret = wc_Sha512Final(hash[0], digest[0]);
  6063. if (ret != 0)
  6064. goto exit_sha512;
  6065. RECORD_MULTI_VALUE_STATS();
  6066. } /* for times */
  6067. count += times;
  6068. } while (bench_stats_check(start)
  6069. #ifdef MULTI_VALUE_STATISTICS
  6070. || runs < minimum_runs
  6071. #endif
  6072. );
  6073. }
  6074. exit_sha512:
  6075. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  6076. start, ret);
  6077. #ifdef MULTI_VALUE_STATISTICS
  6078. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6079. #endif
  6080. exit:
  6081. if (WC_ARRAY_OK(hash)) {
  6082. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6083. wc_Sha512Free(hash[i]);
  6084. }
  6085. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6086. }
  6087. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6088. }
  6089. #if !defined(WOLFSSL_NOSHA512_224) && \
  6090. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6091. void bench_sha512_224(int useDeviceID)
  6092. {
  6093. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6094. sizeof(wc_Sha512_224), HEAP_HINT);
  6095. double start;
  6096. int ret = 0, i, count = 0, times, pending = 0;
  6097. DECLARE_MULTI_VALUE_STATS_VARS()
  6098. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6099. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6100. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6101. sizeof(wc_Sha512_224), HEAP_HINT);
  6102. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6103. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6104. if (digest_stream) {
  6105. /* init keys */
  6106. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6107. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6108. useDeviceID ? devId : INVALID_DEVID);
  6109. if (ret != 0) {
  6110. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6111. goto exit;
  6112. }
  6113. }
  6114. bench_stats_start(&count, &start);
  6115. do {
  6116. for (times = 0; times < numBlocks || pending > 0; ) {
  6117. bench_async_poll(&pending);
  6118. /* while free pending slots in queue, submit ops */
  6119. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6120. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6121. 0, &times, numBlocks, &pending)) {
  6122. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6123. bench_size);
  6124. if (!bench_async_handle(&ret,
  6125. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6126. &times, &pending)) {
  6127. goto exit_sha512_224;
  6128. }
  6129. }
  6130. } /* for i */
  6131. RECORD_MULTI_VALUE_STATS();
  6132. } /* for times */
  6133. count += times;
  6134. times = 0;
  6135. do {
  6136. bench_async_poll(&pending);
  6137. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6138. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6139. 0, &times, numBlocks, &pending)) {
  6140. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6141. if (!bench_async_handle(&ret,
  6142. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6143. &times, &pending)) {
  6144. goto exit_sha512_224;
  6145. }
  6146. }
  6147. } /* for i */
  6148. } while (pending > 0);
  6149. } while (bench_stats_check(start)
  6150. #ifdef MULTI_VALUE_STATISTICS
  6151. || runs < minimum_runs
  6152. #endif
  6153. );
  6154. }
  6155. else {
  6156. bench_stats_start(&count, &start);
  6157. do {
  6158. for (times = 0; times < numBlocks; times++) {
  6159. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6160. useDeviceID ? devId : INVALID_DEVID);
  6161. if (ret == 0)
  6162. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6163. if (ret == 0)
  6164. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6165. if (ret != 0)
  6166. goto exit_sha512_224;
  6167. RECORD_MULTI_VALUE_STATS();
  6168. } /* for times */
  6169. count += times;
  6170. } while (bench_stats_check(start)
  6171. #ifdef MULTI_VALUE_STATISTICS
  6172. || runs < minimum_runs
  6173. #endif
  6174. );
  6175. }
  6176. exit_sha512_224:
  6177. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6178. start, ret);
  6179. #ifdef MULTI_VALUE_STATISTICS
  6180. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6181. #endif
  6182. exit:
  6183. if (WC_ARRAY_OK(hash)) {
  6184. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6185. wc_Sha512_224Free(hash[i]);
  6186. }
  6187. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6188. }
  6189. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6190. }
  6191. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6192. #if !defined(WOLFSSL_NOSHA512_256) && \
  6193. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6194. void bench_sha512_256(int useDeviceID)
  6195. {
  6196. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6197. sizeof(wc_Sha512_256), HEAP_HINT);
  6198. double start;
  6199. int ret = 0, i, count = 0, times, pending = 0;
  6200. DECLARE_MULTI_VALUE_STATS_VARS()
  6201. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6202. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6203. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6204. sizeof(wc_Sha512_256), HEAP_HINT);
  6205. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6206. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6207. if (digest_stream) {
  6208. /* init keys */
  6209. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6210. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6211. useDeviceID ? devId : INVALID_DEVID);
  6212. if (ret != 0) {
  6213. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6214. goto exit;
  6215. }
  6216. }
  6217. bench_stats_start(&count, &start);
  6218. do {
  6219. for (times = 0; times < numBlocks || pending > 0; ) {
  6220. bench_async_poll(&pending);
  6221. /* while free pending slots in queue, submit ops */
  6222. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6223. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6224. 0, &times, numBlocks, &pending)) {
  6225. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6226. bench_size);
  6227. if (!bench_async_handle(&ret,
  6228. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6229. &times, &pending)) {
  6230. goto exit_sha512_256;
  6231. }
  6232. }
  6233. } /* for i */
  6234. RECORD_MULTI_VALUE_STATS();
  6235. } /* for times */
  6236. count += times;
  6237. times = 0;
  6238. do {
  6239. bench_async_poll(&pending);
  6240. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6241. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6242. 0, &times, numBlocks, &pending)) {
  6243. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6244. if (!bench_async_handle(&ret,
  6245. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6246. &times, &pending)) {
  6247. goto exit_sha512_256;
  6248. }
  6249. }
  6250. } /* for i */
  6251. } while (pending > 0);
  6252. } while (bench_stats_check(start)
  6253. #ifdef MULTI_VALUE_STATISTICS
  6254. || runs < minimum_runs
  6255. #endif
  6256. );
  6257. }
  6258. else {
  6259. bench_stats_start(&count, &start);
  6260. do {
  6261. for (times = 0; times < numBlocks; times++) {
  6262. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6263. useDeviceID ? devId : INVALID_DEVID);
  6264. if (ret == 0)
  6265. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6266. if (ret == 0)
  6267. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6268. if (ret != 0)
  6269. goto exit_sha512_256;
  6270. RECORD_MULTI_VALUE_STATS();
  6271. } /* for times */
  6272. count += times;
  6273. } while (bench_stats_check(start)
  6274. #ifdef MULTI_VALUE_STATISTICS
  6275. || runs < minimum_runs
  6276. #endif
  6277. );
  6278. }
  6279. exit_sha512_256:
  6280. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6281. start, ret);
  6282. #ifdef MULTI_VALUE_STATISTICS
  6283. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6284. #endif
  6285. exit:
  6286. if (WC_ARRAY_OK(hash)) {
  6287. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6288. wc_Sha512_256Free(hash[i]);
  6289. }
  6290. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6291. }
  6292. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6293. }
  6294. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6295. #endif /* WOLFSSL_SHA512 */
  6296. #ifdef WOLFSSL_SHA3
  6297. #ifndef WOLFSSL_NOSHA3_224
  6298. void bench_sha3_224(int useDeviceID)
  6299. {
  6300. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6301. sizeof(wc_Sha3), HEAP_HINT);
  6302. double start;
  6303. int ret = 0, i, count = 0, times, pending = 0;
  6304. DECLARE_MULTI_VALUE_STATS_VARS()
  6305. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6306. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6307. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6308. sizeof(wc_Sha3), HEAP_HINT);
  6309. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6310. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6311. if (digest_stream) {
  6312. /* init keys */
  6313. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6314. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6315. useDeviceID ? devId : INVALID_DEVID);
  6316. if (ret != 0) {
  6317. printf("InitSha3_224 failed, ret = %d\n", ret);
  6318. goto exit;
  6319. }
  6320. }
  6321. bench_stats_start(&count, &start);
  6322. do {
  6323. for (times = 0; times < numBlocks || pending > 0; ) {
  6324. bench_async_poll(&pending);
  6325. /* while free pending slots in queue, submit ops */
  6326. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6327. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6328. 0, &times, numBlocks, &pending)) {
  6329. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6330. bench_size);
  6331. if (!bench_async_handle(&ret,
  6332. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6333. &times, &pending)) {
  6334. goto exit_sha3_224;
  6335. }
  6336. }
  6337. } /* for i */
  6338. RECORD_MULTI_VALUE_STATS();
  6339. } /* for times */
  6340. count += times;
  6341. times = 0;
  6342. do {
  6343. bench_async_poll(&pending);
  6344. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6345. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6346. 0, &times, numBlocks, &pending)) {
  6347. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6348. if (!bench_async_handle(&ret,
  6349. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6350. &times, &pending)) {
  6351. goto exit_sha3_224;
  6352. }
  6353. }
  6354. } /* for i */
  6355. } while (pending > 0);
  6356. } while (bench_stats_check(start)
  6357. #ifdef MULTI_VALUE_STATISTICS
  6358. || runs < minimum_runs
  6359. #endif
  6360. );
  6361. }
  6362. else {
  6363. bench_stats_start(&count, &start);
  6364. do {
  6365. for (times = 0; times < numBlocks; times++) {
  6366. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6367. useDeviceID ? devId : INVALID_DEVID);
  6368. if (ret == 0)
  6369. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6370. if (ret == 0)
  6371. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6372. if (ret != 0)
  6373. goto exit_sha3_224;
  6374. RECORD_MULTI_VALUE_STATS();
  6375. } /* for times */
  6376. count += times;
  6377. } while (bench_stats_check(start)
  6378. #ifdef MULTI_VALUE_STATISTICS
  6379. || runs < minimum_runs
  6380. #endif
  6381. );
  6382. }
  6383. exit_sha3_224:
  6384. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6385. start, ret);
  6386. #ifdef MULTI_VALUE_STATISTICS
  6387. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6388. #endif
  6389. exit:
  6390. if (WC_ARRAY_OK(hash)) {
  6391. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6392. wc_Sha3_224_Free(hash[i]);
  6393. }
  6394. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6395. }
  6396. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6397. }
  6398. #endif /* WOLFSSL_NOSHA3_224 */
  6399. #ifndef WOLFSSL_NOSHA3_256
  6400. void bench_sha3_256(int useDeviceID)
  6401. {
  6402. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6403. sizeof(wc_Sha3), HEAP_HINT);
  6404. double start;
  6405. DECLARE_MULTI_VALUE_STATS_VARS()
  6406. int ret = 0, i, count = 0, times, pending = 0;
  6407. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6408. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6409. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6410. sizeof(wc_Sha3), HEAP_HINT);
  6411. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6412. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6413. if (digest_stream) {
  6414. /* init keys */
  6415. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6416. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6417. useDeviceID ? devId : INVALID_DEVID);
  6418. if (ret != 0) {
  6419. printf("InitSha3_256 failed, ret = %d\n", ret);
  6420. goto exit;
  6421. }
  6422. }
  6423. bench_stats_start(&count, &start);
  6424. do {
  6425. for (times = 0; times < numBlocks || pending > 0; ) {
  6426. bench_async_poll(&pending);
  6427. /* while free pending slots in queue, submit ops */
  6428. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6429. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6430. 0, &times, numBlocks, &pending)) {
  6431. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6432. bench_size);
  6433. if (!bench_async_handle(&ret,
  6434. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6435. &times, &pending)) {
  6436. goto exit_sha3_256;
  6437. }
  6438. }
  6439. } /* for i */
  6440. RECORD_MULTI_VALUE_STATS();
  6441. } /* for times */
  6442. count += times;
  6443. times = 0;
  6444. do {
  6445. bench_async_poll(&pending);
  6446. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6447. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6448. 0, &times, numBlocks, &pending)) {
  6449. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6450. if (!bench_async_handle(&ret,
  6451. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6452. &times, &pending)) {
  6453. goto exit_sha3_256;
  6454. }
  6455. }
  6456. } /* for i */
  6457. } while (pending > 0);
  6458. } while (bench_stats_check(start)
  6459. #ifdef MULTI_VALUE_STATISTICS
  6460. || runs < minimum_runs
  6461. #endif
  6462. );
  6463. }
  6464. else {
  6465. bench_stats_start(&count, &start);
  6466. do {
  6467. for (times = 0; times < numBlocks; times++) {
  6468. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6469. useDeviceID ? devId : INVALID_DEVID);
  6470. if (ret == 0)
  6471. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6472. if (ret == 0)
  6473. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6474. if (ret != 0)
  6475. goto exit_sha3_256;
  6476. RECORD_MULTI_VALUE_STATS();
  6477. } /* for times */
  6478. count += times;
  6479. } while (bench_stats_check(start)
  6480. #ifdef MULTI_VALUE_STATISTICS
  6481. || runs < minimum_runs
  6482. #endif
  6483. );
  6484. }
  6485. exit_sha3_256:
  6486. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6487. start, ret);
  6488. #ifdef MULTI_VALUE_STATISTICS
  6489. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6490. #endif
  6491. exit:
  6492. if (WC_ARRAY_OK(hash)) {
  6493. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6494. wc_Sha3_256_Free(hash[i]);
  6495. }
  6496. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6497. }
  6498. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6499. }
  6500. #endif /* WOLFSSL_NOSHA3_256 */
  6501. #ifndef WOLFSSL_NOSHA3_384
  6502. void bench_sha3_384(int useDeviceID)
  6503. {
  6504. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6505. sizeof(wc_Sha3), HEAP_HINT);
  6506. double start;
  6507. int ret = 0, i, count = 0, times, pending = 0;
  6508. DECLARE_MULTI_VALUE_STATS_VARS()
  6509. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6510. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6511. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6512. sizeof(wc_Sha3), HEAP_HINT);
  6513. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6514. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6515. if (digest_stream) {
  6516. /* init keys */
  6517. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6518. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6519. useDeviceID ? devId : INVALID_DEVID);
  6520. if (ret != 0) {
  6521. printf("InitSha3_384 failed, ret = %d\n", ret);
  6522. goto exit;
  6523. }
  6524. }
  6525. bench_stats_start(&count, &start);
  6526. do {
  6527. for (times = 0; times < numBlocks || pending > 0; ) {
  6528. bench_async_poll(&pending);
  6529. /* while free pending slots in queue, submit ops */
  6530. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6531. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6532. 0, &times, numBlocks, &pending)) {
  6533. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6534. bench_size);
  6535. if (!bench_async_handle(&ret,
  6536. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6537. &times, &pending)) {
  6538. goto exit_sha3_384;
  6539. }
  6540. }
  6541. } /* for i */
  6542. RECORD_MULTI_VALUE_STATS();
  6543. } /* for times */
  6544. count += times;
  6545. times = 0;
  6546. do {
  6547. bench_async_poll(&pending);
  6548. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6549. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6550. 0, &times, numBlocks, &pending)) {
  6551. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6552. if (!bench_async_handle(&ret,
  6553. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6554. &times, &pending)) {
  6555. goto exit_sha3_384;
  6556. }
  6557. }
  6558. } /* for i */
  6559. } while (pending > 0);
  6560. } while (bench_stats_check(start)
  6561. #ifdef MULTI_VALUE_STATISTICS
  6562. || runs < minimum_runs
  6563. #endif
  6564. );
  6565. }
  6566. else {
  6567. bench_stats_start(&count, &start);
  6568. do {
  6569. for (times = 0; times < numBlocks; times++) {
  6570. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6571. useDeviceID ? devId : INVALID_DEVID);
  6572. if (ret == 0)
  6573. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6574. if (ret == 0)
  6575. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6576. if (ret != 0)
  6577. goto exit_sha3_384;
  6578. RECORD_MULTI_VALUE_STATS();
  6579. } /* for times */
  6580. count += times;
  6581. } while (bench_stats_check(start)
  6582. #ifdef MULTI_VALUE_STATISTICS
  6583. || runs < minimum_runs
  6584. #endif
  6585. );
  6586. }
  6587. exit_sha3_384:
  6588. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6589. start, ret);
  6590. #ifdef MULTI_VALUE_STATISTICS
  6591. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6592. #endif
  6593. exit:
  6594. if (WC_ARRAY_OK(hash)) {
  6595. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6596. wc_Sha3_384_Free(hash[i]);
  6597. }
  6598. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6599. }
  6600. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6601. }
  6602. #endif /* WOLFSSL_NOSHA3_384 */
  6603. #ifndef WOLFSSL_NOSHA3_512
  6604. void bench_sha3_512(int useDeviceID)
  6605. {
  6606. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6607. sizeof(wc_Sha3), HEAP_HINT);
  6608. double start;
  6609. int ret = 0, i, count = 0, times, pending = 0;
  6610. DECLARE_MULTI_VALUE_STATS_VARS()
  6611. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6612. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6613. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6614. sizeof(wc_Sha3), HEAP_HINT);
  6615. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6616. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6617. if (digest_stream) {
  6618. /* init keys */
  6619. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6620. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6621. useDeviceID ? devId : INVALID_DEVID);
  6622. if (ret != 0) {
  6623. printf("InitSha3_512 failed, ret = %d\n", ret);
  6624. goto exit;
  6625. }
  6626. }
  6627. bench_stats_start(&count, &start);
  6628. do {
  6629. for (times = 0; times < numBlocks || pending > 0; ) {
  6630. bench_async_poll(&pending);
  6631. /* while free pending slots in queue, submit ops */
  6632. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6633. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6634. 0, &times, numBlocks, &pending)) {
  6635. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6636. bench_size);
  6637. if (!bench_async_handle(&ret,
  6638. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6639. &times, &pending)) {
  6640. goto exit_sha3_512;
  6641. }
  6642. }
  6643. } /* for i */
  6644. RECORD_MULTI_VALUE_STATS();
  6645. } /* for times */
  6646. count += times;
  6647. times = 0;
  6648. do {
  6649. bench_async_poll(&pending);
  6650. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6651. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6652. 0, &times, numBlocks, &pending)) {
  6653. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6654. if (!bench_async_handle(&ret,
  6655. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6656. &times, &pending)) {
  6657. goto exit_sha3_512;
  6658. }
  6659. }
  6660. } /* for i */
  6661. } while (pending > 0);
  6662. } while (bench_stats_check(start)
  6663. #ifdef MULTI_VALUE_STATISTICS
  6664. || runs < minimum_runs
  6665. #endif
  6666. );
  6667. }
  6668. else {
  6669. bench_stats_start(&count, &start);
  6670. do {
  6671. for (times = 0; times < numBlocks; times++) {
  6672. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6673. useDeviceID ? devId : INVALID_DEVID);
  6674. if (ret == 0)
  6675. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6676. if (ret == 0)
  6677. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6678. if (ret != 0)
  6679. goto exit_sha3_512;
  6680. RECORD_MULTI_VALUE_STATS();
  6681. } /* for times */
  6682. count += times;
  6683. } while (bench_stats_check(start)
  6684. #ifdef MULTI_VALUE_STATISTICS
  6685. || runs < minimum_runs
  6686. #endif
  6687. );
  6688. }
  6689. exit_sha3_512:
  6690. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6691. start, ret);
  6692. #ifdef MULTI_VALUE_STATISTICS
  6693. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6694. #endif
  6695. exit:
  6696. if (WC_ARRAY_OK(hash)) {
  6697. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6698. wc_Sha3_512_Free(hash[i]);
  6699. }
  6700. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6701. }
  6702. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6703. }
  6704. #endif /* WOLFSSL_NOSHA3_512 */
  6705. #ifdef WOLFSSL_SHAKE128
  6706. void bench_shake128(int useDeviceID)
  6707. {
  6708. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6709. sizeof(wc_Shake), HEAP_HINT);
  6710. double start;
  6711. int ret = 0, i, count = 0, times, pending = 0;
  6712. DECLARE_MULTI_VALUE_STATS_VARS()
  6713. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6714. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6715. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6716. sizeof(wc_Shake), HEAP_HINT);
  6717. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6718. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6719. if (digest_stream) {
  6720. /* init keys */
  6721. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6722. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6723. useDeviceID ? devId : INVALID_DEVID);
  6724. if (ret != 0) {
  6725. printf("InitShake128 failed, ret = %d\n", ret);
  6726. goto exit;
  6727. }
  6728. }
  6729. bench_stats_start(&count, &start);
  6730. do {
  6731. for (times = 0; times < numBlocks || pending > 0; ) {
  6732. bench_async_poll(&pending);
  6733. /* while free pending slots in queue, submit ops */
  6734. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6735. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6736. 0, &times, numBlocks, &pending)) {
  6737. ret = wc_Shake128_Update(hash[i], bench_plain,
  6738. bench_size);
  6739. if (!bench_async_handle(&ret,
  6740. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6741. &times, &pending)) {
  6742. goto exit_shake128;
  6743. }
  6744. }
  6745. } /* for i */
  6746. RECORD_MULTI_VALUE_STATS();
  6747. } /* for times */
  6748. count += times;
  6749. times = 0;
  6750. do {
  6751. bench_async_poll(&pending);
  6752. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6753. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6754. 0, &times, numBlocks, &pending)) {
  6755. ret = wc_Shake128_Final(hash[i], digest[i],
  6756. WC_SHA3_128_BLOCK_SIZE);
  6757. if (!bench_async_handle(&ret,
  6758. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6759. &times, &pending)) {
  6760. goto exit_shake128;
  6761. }
  6762. }
  6763. } /* for i */
  6764. } while (pending > 0);
  6765. } while (bench_stats_check(start)
  6766. #ifdef MULTI_VALUE_STATISTICS
  6767. || runs < minimum_runs
  6768. #endif
  6769. );
  6770. }
  6771. else {
  6772. bench_stats_start(&count, &start);
  6773. do {
  6774. for (times = 0; times < numBlocks; times++) {
  6775. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6776. useDeviceID ? devId : INVALID_DEVID);
  6777. if (ret == 0)
  6778. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6779. if (ret == 0)
  6780. ret = wc_Shake128_Final(hash[0], digest[0],
  6781. WC_SHA3_128_BLOCK_SIZE);
  6782. if (ret != 0)
  6783. goto exit_shake128;
  6784. RECORD_MULTI_VALUE_STATS();
  6785. } /* for times */
  6786. count += times;
  6787. } while (bench_stats_check(start)
  6788. #ifdef MULTI_VALUE_STATISTICS
  6789. || runs < minimum_runs
  6790. #endif
  6791. );
  6792. }
  6793. exit_shake128:
  6794. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6795. start, ret);
  6796. #ifdef MULTI_VALUE_STATISTICS
  6797. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6798. #endif
  6799. exit:
  6800. if (WC_ARRAY_OK(hash)) {
  6801. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6802. wc_Shake128_Free(hash[i]);
  6803. }
  6804. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6805. }
  6806. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6807. }
  6808. #endif /* WOLFSSL_SHAKE128 */
  6809. #ifdef WOLFSSL_SHAKE256
  6810. void bench_shake256(int useDeviceID)
  6811. {
  6812. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6813. sizeof(wc_Shake), HEAP_HINT);
  6814. double start;
  6815. int ret = 0, i, count = 0, times, pending = 0;
  6816. DECLARE_MULTI_VALUE_STATS_VARS()
  6817. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6818. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6819. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6820. sizeof(wc_Shake), HEAP_HINT);
  6821. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6822. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6823. if (digest_stream) {
  6824. /* init keys */
  6825. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6826. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6827. useDeviceID ? devId : INVALID_DEVID);
  6828. if (ret != 0) {
  6829. printf("InitShake256 failed, ret = %d\n", ret);
  6830. goto exit;
  6831. }
  6832. }
  6833. bench_stats_start(&count, &start);
  6834. do {
  6835. for (times = 0; times < numBlocks || pending > 0; ) {
  6836. bench_async_poll(&pending);
  6837. /* while free pending slots in queue, submit ops */
  6838. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6839. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6840. 0, &times, numBlocks, &pending)) {
  6841. ret = wc_Shake256_Update(hash[i], bench_plain,
  6842. bench_size);
  6843. if (!bench_async_handle(&ret,
  6844. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6845. &times, &pending)) {
  6846. goto exit_shake256;
  6847. }
  6848. }
  6849. } /* for i */
  6850. RECORD_MULTI_VALUE_STATS();
  6851. } /* for times */
  6852. count += times;
  6853. times = 0;
  6854. do {
  6855. bench_async_poll(&pending);
  6856. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6857. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6858. 0, &times, numBlocks, &pending)) {
  6859. ret = wc_Shake256_Final(hash[i], digest[i],
  6860. WC_SHA3_256_BLOCK_SIZE);
  6861. if (!bench_async_handle(&ret,
  6862. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6863. &times, &pending)) {
  6864. goto exit_shake256;
  6865. }
  6866. }
  6867. } /* for i */
  6868. } while (pending > 0);
  6869. } while (bench_stats_check(start)
  6870. #ifdef MULTI_VALUE_STATISTICS
  6871. || runs < minimum_runs
  6872. #endif
  6873. );
  6874. }
  6875. else {
  6876. bench_stats_start(&count, &start);
  6877. do {
  6878. for (times = 0; times < numBlocks; times++) {
  6879. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6880. useDeviceID ? devId : INVALID_DEVID);
  6881. if (ret == 0)
  6882. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6883. if (ret == 0)
  6884. ret = wc_Shake256_Final(hash[0], digest[0],
  6885. WC_SHA3_256_BLOCK_SIZE);
  6886. if (ret != 0)
  6887. goto exit_shake256;
  6888. RECORD_MULTI_VALUE_STATS();
  6889. } /* for times */
  6890. count += times;
  6891. } while (bench_stats_check(start)
  6892. #ifdef MULTI_VALUE_STATISTICS
  6893. || runs < minimum_runs
  6894. #endif
  6895. );
  6896. }
  6897. exit_shake256:
  6898. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6899. start, ret);
  6900. #ifdef MULTI_VALUE_STATISTICS
  6901. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6902. #endif
  6903. exit:
  6904. if (WC_ARRAY_OK(hash)) {
  6905. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6906. wc_Shake256_Free(hash[i]);
  6907. }
  6908. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6909. }
  6910. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6911. }
  6912. #endif /* WOLFSSL_SHAKE256 */
  6913. #endif
  6914. #ifdef WOLFSSL_SM3
  6915. void bench_sm3(int useDeviceID)
  6916. {
  6917. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6918. sizeof(wc_Sm3), HEAP_HINT);
  6919. double start;
  6920. int ret = 0, i, count = 0, times, pending = 0;
  6921. DECLARE_MULTI_VALUE_STATS_VARS()
  6922. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6923. HEAP_HINT);
  6924. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6925. sizeof(wc_Sm3), HEAP_HINT);
  6926. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6927. HEAP_HINT);
  6928. if (digest_stream) {
  6929. /* init keys */
  6930. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6931. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6932. useDeviceID ? devId: INVALID_DEVID);
  6933. if (ret != 0) {
  6934. printf("InitSm3 failed, ret = %d\n", ret);
  6935. goto exit;
  6936. }
  6937. }
  6938. bench_stats_start(&count, &start);
  6939. do {
  6940. for (times = 0; times < numBlocks || pending > 0; ) {
  6941. bench_async_poll(&pending);
  6942. /* while free pending slots in queue, submit ops */
  6943. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6944. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6945. 0, &times, numBlocks, &pending)) {
  6946. ret = wc_Sm3Update(hash[i], bench_plain,
  6947. bench_size);
  6948. if (!bench_async_handle(&ret,
  6949. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6950. goto exit_sm3;
  6951. }
  6952. }
  6953. } /* for i */
  6954. RECORD_MULTI_VALUE_STATS();
  6955. } /* for times */
  6956. count += times;
  6957. times = 0;
  6958. do {
  6959. bench_async_poll(&pending);
  6960. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6961. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6962. 0, &times, numBlocks, &pending)) {
  6963. ret = wc_Sm3Final(hash[i], digest[i]);
  6964. if (!bench_async_handle(&ret,
  6965. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6966. goto exit_sm3;
  6967. }
  6968. }
  6969. } /* for i */
  6970. } while (pending > 0);
  6971. } while (bench_stats_check(start)
  6972. #ifdef MULTI_VALUE_STATISTICS
  6973. || runs < minimum_runs
  6974. #endif
  6975. );
  6976. }
  6977. else {
  6978. bench_stats_start(&count, &start);
  6979. do {
  6980. for (times = 0; times < numBlocks; times++) {
  6981. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6982. useDeviceID ? devId: INVALID_DEVID);
  6983. if (ret == 0)
  6984. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6985. if (ret == 0)
  6986. ret = wc_Sm3Final(hash[0], digest[0]);
  6987. if (ret != 0)
  6988. goto exit_sm3;
  6989. RECORD_MULTI_VALUE_STATS();
  6990. } /* for times */
  6991. count += times;
  6992. } while (bench_stats_check(start)
  6993. #ifdef MULTI_VALUE_STATISTICS
  6994. || runs < minimum_runs
  6995. #endif
  6996. );
  6997. }
  6998. exit_sm3:
  6999. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  7000. #ifdef MULTI_VALUE_STATISTICS
  7001. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7002. #endif
  7003. exit:
  7004. if (WC_ARRAY_OK(hash)) {
  7005. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7006. wc_Sm3Free(hash[i]);
  7007. }
  7008. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  7009. }
  7010. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7011. }
  7012. #endif
  7013. #ifdef WOLFSSL_RIPEMD
  7014. void bench_ripemd(void)
  7015. {
  7016. RipeMd hash;
  7017. byte digest[RIPEMD_DIGEST_SIZE];
  7018. double start;
  7019. int i, count, ret = 0;
  7020. DECLARE_MULTI_VALUE_STATS_VARS()
  7021. if (digest_stream) {
  7022. ret = wc_InitRipeMd(&hash);
  7023. if (ret != 0) {
  7024. printf("wc_InitRipeMd failed, retval %d\n", ret);
  7025. return;
  7026. }
  7027. bench_stats_start(&count, &start);
  7028. do {
  7029. for (i = 0; i < numBlocks; i++) {
  7030. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  7031. if (ret != 0) {
  7032. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7033. return;
  7034. }
  7035. RECORD_MULTI_VALUE_STATS();
  7036. }
  7037. ret = wc_RipeMdFinal(&hash, digest);
  7038. if (ret != 0) {
  7039. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7040. return;
  7041. }
  7042. count += i;
  7043. } while (bench_stats_check(start)
  7044. #ifdef MULTI_VALUE_STATISTICS
  7045. || runs < minimum_runs
  7046. #endif
  7047. );
  7048. }
  7049. else {
  7050. bench_stats_start(&count, &start);
  7051. do {
  7052. for (i = 0; i < numBlocks; i++) {
  7053. ret = wc_InitRipeMd(&hash);
  7054. if (ret != 0) {
  7055. printf("wc_InitRipeMd failed, retval %d\n", ret);
  7056. return;
  7057. }
  7058. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  7059. if (ret != 0) {
  7060. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7061. return;
  7062. }
  7063. ret = wc_RipeMdFinal(&hash, digest);
  7064. if (ret != 0) {
  7065. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7066. return;
  7067. }
  7068. RECORD_MULTI_VALUE_STATS();
  7069. }
  7070. count += i;
  7071. } while (bench_stats_check(start)
  7072. #ifdef MULTI_VALUE_STATISTICS
  7073. || runs < minimum_runs
  7074. #endif
  7075. );
  7076. }
  7077. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  7078. #ifdef MULTI_VALUE_STATISTICS
  7079. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7080. #endif
  7081. return;
  7082. }
  7083. #endif
  7084. #ifdef HAVE_BLAKE2
  7085. void bench_blake2b(void)
  7086. {
  7087. Blake2b b2b;
  7088. byte digest[64];
  7089. double start;
  7090. int ret = 0, i, count;
  7091. DECLARE_MULTI_VALUE_STATS_VARS()
  7092. if (digest_stream) {
  7093. ret = wc_InitBlake2b(&b2b, 64);
  7094. if (ret != 0) {
  7095. printf("InitBlake2b failed, ret = %d\n", ret);
  7096. return;
  7097. }
  7098. bench_stats_start(&count, &start);
  7099. do {
  7100. for (i = 0; i < numBlocks; i++) {
  7101. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7102. if (ret != 0) {
  7103. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7104. return;
  7105. }
  7106. RECORD_MULTI_VALUE_STATS();
  7107. }
  7108. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7109. if (ret != 0) {
  7110. printf("Blake2bFinal failed, ret = %d\n", ret);
  7111. return;
  7112. }
  7113. count += i;
  7114. } while (bench_stats_check(start)
  7115. #ifdef MULTI_VALUE_STATISTICS
  7116. || runs < minimum_runs
  7117. #endif
  7118. );
  7119. }
  7120. else {
  7121. bench_stats_start(&count, &start);
  7122. do {
  7123. for (i = 0; i < numBlocks; i++) {
  7124. ret = wc_InitBlake2b(&b2b, 64);
  7125. if (ret != 0) {
  7126. printf("InitBlake2b failed, ret = %d\n", ret);
  7127. return;
  7128. }
  7129. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7130. if (ret != 0) {
  7131. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7132. return;
  7133. }
  7134. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7135. if (ret != 0) {
  7136. printf("Blake2bFinal failed, ret = %d\n", ret);
  7137. return;
  7138. }
  7139. RECORD_MULTI_VALUE_STATS();
  7140. }
  7141. count += i;
  7142. } while (bench_stats_check(start)
  7143. #ifdef MULTI_VALUE_STATISTICS
  7144. || runs < minimum_runs
  7145. #endif
  7146. );
  7147. }
  7148. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7149. #ifdef MULTI_VALUE_STATISTICS
  7150. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7151. #endif
  7152. }
  7153. #endif
  7154. #if defined(HAVE_BLAKE2S)
  7155. void bench_blake2s(void)
  7156. {
  7157. Blake2s b2s;
  7158. byte digest[32];
  7159. double start;
  7160. int ret = 0, i, count;
  7161. DECLARE_MULTI_VALUE_STATS_VARS()
  7162. if (digest_stream) {
  7163. ret = wc_InitBlake2s(&b2s, 32);
  7164. if (ret != 0) {
  7165. printf("InitBlake2s failed, ret = %d\n", ret);
  7166. return;
  7167. }
  7168. bench_stats_start(&count, &start);
  7169. do {
  7170. for (i = 0; i < numBlocks; i++) {
  7171. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7172. if (ret != 0) {
  7173. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7174. return;
  7175. }
  7176. RECORD_MULTI_VALUE_STATS();
  7177. }
  7178. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7179. if (ret != 0) {
  7180. printf("Blake2sFinal failed, ret = %d\n", ret);
  7181. return;
  7182. }
  7183. count += i;
  7184. } while (bench_stats_check(start)
  7185. #ifdef MULTI_VALUE_STATISTICS
  7186. || runs < minimum_runs
  7187. #endif
  7188. );
  7189. }
  7190. else {
  7191. bench_stats_start(&count, &start);
  7192. do {
  7193. for (i = 0; i < numBlocks; i++) {
  7194. ret = wc_InitBlake2s(&b2s, 32);
  7195. if (ret != 0) {
  7196. printf("InitBlake2b failed, ret = %d\n", ret);
  7197. return;
  7198. }
  7199. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7200. if (ret != 0) {
  7201. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7202. return;
  7203. }
  7204. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7205. if (ret != 0) {
  7206. printf("Blake2sFinal failed, ret = %d\n", ret);
  7207. return;
  7208. }
  7209. RECORD_MULTI_VALUE_STATS();
  7210. }
  7211. count += i;
  7212. } while (bench_stats_check(start)
  7213. #ifdef MULTI_VALUE_STATISTICS
  7214. || runs < minimum_runs
  7215. #endif
  7216. );
  7217. }
  7218. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7219. #ifdef MULTI_VALUE_STATISTICS
  7220. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7221. #endif
  7222. }
  7223. #endif
  7224. #ifdef WOLFSSL_CMAC
  7225. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7226. {
  7227. Cmac cmac;
  7228. byte digest[WC_AES_BLOCK_SIZE];
  7229. word32 digestSz = sizeof(digest);
  7230. double start;
  7231. int ret, i, count;
  7232. DECLARE_MULTI_VALUE_STATS_VARS()
  7233. #ifdef WOLFSSL_SECO_CAAM
  7234. unsigned int keyID;
  7235. int keyGroup = 1; /* group one was chosen arbitrarily */
  7236. int keyInfo = CAAM_KEY_TRANSIENT;
  7237. int keyType = CAAM_KEYTYPE_AES128;
  7238. byte pubKey[AES_256_KEY_SIZE];
  7239. if (keySz == AES_256_KEY_SIZE) {
  7240. keyType = CAAM_KEYTYPE_AES256;
  7241. }
  7242. if (useDeviceID &&
  7243. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7244. keyInfo, &keyID) != 0) {
  7245. printf("Error generating key in hsm\n");
  7246. return;
  7247. }
  7248. #endif
  7249. (void)useDeviceID;
  7250. bench_stats_start(&count, &start);
  7251. do {
  7252. #ifdef HAVE_FIPS
  7253. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7254. #else
  7255. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7256. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7257. #endif
  7258. if (ret != 0) {
  7259. printf("InitCmac failed, ret = %d\n", ret);
  7260. return;
  7261. }
  7262. #ifdef WOLFSSL_SECO_CAAM
  7263. if (useDeviceID) {
  7264. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7265. }
  7266. #endif
  7267. for (i = 0; i < numBlocks; i++) {
  7268. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7269. if (ret != 0) {
  7270. printf("CmacUpdate failed, ret = %d\n", ret);
  7271. return;
  7272. }
  7273. RECORD_MULTI_VALUE_STATS();
  7274. }
  7275. /* Note: final force zero's the Cmac struct */
  7276. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7277. if (ret != 0) {
  7278. printf("CmacFinal failed, ret = %d\n", ret);
  7279. return;
  7280. }
  7281. count += i;
  7282. } while (bench_stats_check(start)
  7283. #ifdef MULTI_VALUE_STATISTICS
  7284. || runs < minimum_runs
  7285. #endif
  7286. );
  7287. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7288. #ifdef MULTI_VALUE_STATISTICS
  7289. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7290. #endif
  7291. }
  7292. void bench_cmac(int useDeviceID)
  7293. {
  7294. #ifdef WOLFSSL_AES_128
  7295. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7296. #endif
  7297. #ifdef WOLFSSL_AES_256
  7298. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7299. #endif
  7300. }
  7301. #endif /* WOLFSSL_CMAC */
  7302. #ifdef HAVE_SCRYPT
  7303. void bench_scrypt(void)
  7304. {
  7305. byte derived[64];
  7306. double start;
  7307. int ret, i, count;
  7308. DECLARE_MULTI_VALUE_STATS_VARS()
  7309. bench_stats_start(&count, &start);
  7310. do {
  7311. for (i = 0; i < scryptCnt; i++) {
  7312. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7313. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7314. sizeof(derived));
  7315. if (ret != 0) {
  7316. printf("scrypt failed, ret = %d\n", ret);
  7317. goto exit;
  7318. }
  7319. RECORD_MULTI_VALUE_STATS();
  7320. }
  7321. count += i;
  7322. } while (bench_stats_check(start)
  7323. #ifdef MULTI_VALUE_STATISTICS
  7324. || runs < minimum_runs
  7325. #endif
  7326. );
  7327. exit:
  7328. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7329. #ifdef MULTI_VALUE_STATISTICS
  7330. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7331. #endif
  7332. }
  7333. #endif /* HAVE_SCRYPT */
  7334. #ifndef NO_HMAC
  7335. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7336. const byte* key, word32 keySz, const char* label)
  7337. {
  7338. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7339. sizeof(Hmac), HEAP_HINT);
  7340. double start;
  7341. int ret = 0, i, count = 0, times, pending = 0;
  7342. DECLARE_MULTI_VALUE_STATS_VARS()
  7343. #ifdef WOLFSSL_ASYNC_CRYPT
  7344. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7345. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7346. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7347. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7348. #else
  7349. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7350. #endif
  7351. (void)digestSz;
  7352. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7353. sizeof(Hmac), HEAP_HINT);
  7354. /* init keys */
  7355. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7356. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7357. useDeviceID ? devId : INVALID_DEVID);
  7358. if (ret != 0) {
  7359. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7360. goto exit;
  7361. }
  7362. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7363. if (ret != 0) {
  7364. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7365. goto exit;
  7366. }
  7367. }
  7368. bench_stats_start(&count, &start);
  7369. do {
  7370. for (times = 0; times < numBlocks || pending > 0; ) {
  7371. bench_async_poll(&pending);
  7372. /* while free pending slots in queue, submit ops */
  7373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7374. if (bench_async_check(&ret,
  7375. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7376. &times, numBlocks, &pending)) {
  7377. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7378. if (!bench_async_handle(&ret,
  7379. BENCH_ASYNC_GET_DEV(hmac[i]),
  7380. 0, &times, &pending)) {
  7381. goto exit_hmac;
  7382. }
  7383. }
  7384. } /* for i */
  7385. } /* for times */
  7386. count += times;
  7387. times = 0;
  7388. do {
  7389. bench_async_poll(&pending);
  7390. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7391. if (bench_async_check(&ret,
  7392. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7393. &times, numBlocks, &pending)) {
  7394. ret = wc_HmacFinal(hmac[i], digest[i]);
  7395. if (!bench_async_handle(&ret,
  7396. BENCH_ASYNC_GET_DEV(hmac[i]),
  7397. 0, &times, &pending)) {
  7398. goto exit_hmac;
  7399. }
  7400. }
  7401. RECORD_MULTI_VALUE_STATS();
  7402. } /* for i */
  7403. } while (pending > 0);
  7404. } while (bench_stats_check(start)
  7405. #ifdef MULTI_VALUE_STATISTICS
  7406. || runs < minimum_runs
  7407. #endif
  7408. );
  7409. exit_hmac:
  7410. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7411. #ifdef MULTI_VALUE_STATISTICS
  7412. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7413. #endif
  7414. exit:
  7415. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7416. wc_HmacFree(hmac[i]);
  7417. }
  7418. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7419. #ifdef WOLFSSL_ASYNC_CRYPT
  7420. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7421. #endif
  7422. }
  7423. #ifndef NO_MD5
  7424. void bench_hmac_md5(int useDeviceID)
  7425. {
  7426. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7427. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7428. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7429. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7430. "HMAC-MD5");
  7431. }
  7432. #endif /* NO_MD5 */
  7433. #ifndef NO_SHA
  7434. void bench_hmac_sha(int useDeviceID)
  7435. {
  7436. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7437. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7438. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7439. 0x0b, 0x0b, 0x0b, 0x0b };
  7440. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7441. "HMAC-SHA");
  7442. }
  7443. #endif /* NO_SHA */
  7444. #ifdef WOLFSSL_SHA224
  7445. void bench_hmac_sha224(int useDeviceID)
  7446. {
  7447. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7448. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7449. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7450. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7451. 0x0b, 0x0b, 0x0b, 0x0b };
  7452. bench_hmac(useDeviceID, WC_SHA224,
  7453. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7454. "HMAC-SHA224");
  7455. }
  7456. #endif /* WOLFSSL_SHA224 */
  7457. #ifndef NO_SHA256
  7458. void bench_hmac_sha256(int useDeviceID)
  7459. {
  7460. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7461. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7462. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7463. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7464. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7465. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7466. "HMAC-SHA256");
  7467. }
  7468. #endif /* NO_SHA256 */
  7469. #ifdef WOLFSSL_SHA384
  7470. void bench_hmac_sha384(int useDeviceID)
  7471. {
  7472. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7473. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7474. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7475. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7476. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7477. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7478. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7479. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7480. "HMAC-SHA384");
  7481. }
  7482. #endif /* WOLFSSL_SHA384 */
  7483. #ifdef WOLFSSL_SHA512
  7484. void bench_hmac_sha512(int useDeviceID)
  7485. {
  7486. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7487. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7488. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7489. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7490. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7491. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7492. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7493. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7494. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7495. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7496. "HMAC-SHA512");
  7497. }
  7498. #endif /* WOLFSSL_SHA512 */
  7499. #ifndef NO_PWDBASED
  7500. void bench_pbkdf2(void)
  7501. {
  7502. double start;
  7503. int ret = 0, count = 0;
  7504. const char* passwd32 = "passwordpasswordpasswordpassword";
  7505. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7506. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7507. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7508. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7509. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7510. byte derived[32];
  7511. DECLARE_MULTI_VALUE_STATS_VARS()
  7512. bench_stats_start(&count, &start);
  7513. PRIVATE_KEY_UNLOCK();
  7514. do {
  7515. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7516. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7517. count++;
  7518. RECORD_MULTI_VALUE_STATS();
  7519. } while (bench_stats_check(start)
  7520. #ifdef MULTI_VALUE_STATISTICS
  7521. || runs < minimum_runs
  7522. #endif
  7523. );
  7524. PRIVATE_KEY_LOCK();
  7525. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7526. #ifdef MULTI_VALUE_STATISTICS
  7527. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7528. #endif
  7529. }
  7530. #endif /* !NO_PWDBASED */
  7531. #endif /* NO_HMAC */
  7532. #ifdef WOLFSSL_SIPHASH
  7533. void bench_siphash(void)
  7534. {
  7535. double start;
  7536. int ret = 0, count;
  7537. const char* passwd16 = "passwordpassword";
  7538. byte out[16];
  7539. int i;
  7540. DECLARE_MULTI_VALUE_STATS_VARS()
  7541. bench_stats_start(&count, &start);
  7542. do {
  7543. for (i = 0; i < numBlocks; i++) {
  7544. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7545. out, 8);
  7546. RECORD_MULTI_VALUE_STATS();
  7547. }
  7548. count += i;
  7549. } while (bench_stats_check(start)
  7550. #ifdef MULTI_VALUE_STATISTICS
  7551. || runs < minimum_runs
  7552. #endif
  7553. );
  7554. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7555. #ifdef MULTI_VALUE_STATISTICS
  7556. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7557. #endif
  7558. RESET_MULTI_VALUE_STATS_VARS();
  7559. bench_stats_start(&count, &start);
  7560. do {
  7561. for (i = 0; i < numBlocks; i++) {
  7562. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7563. out, 16);
  7564. RECORD_MULTI_VALUE_STATS();
  7565. }
  7566. count += i;
  7567. } while (bench_stats_check(start)
  7568. #ifdef MULTI_VALUE_STATISTICS
  7569. || runs < minimum_runs
  7570. #endif
  7571. );
  7572. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7573. #ifdef MULTI_VALUE_STATISTICS
  7574. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7575. #endif
  7576. }
  7577. #endif
  7578. #ifdef WC_SRTP_KDF
  7579. void bench_srtpkdf(void)
  7580. {
  7581. double start;
  7582. int count;
  7583. int ret = 0;
  7584. byte keyE[32];
  7585. byte keyA[20];
  7586. byte keyS[14];
  7587. const byte *key = bench_key_buf;
  7588. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7589. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7590. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7591. int kdrIdx = 0;
  7592. int i;
  7593. DECLARE_MULTI_VALUE_STATS_VARS()
  7594. bench_stats_start(&count, &start);
  7595. PRIVATE_KEY_UNLOCK();
  7596. do {
  7597. for (i = 0; i < numBlocks; i++) {
  7598. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7599. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7600. keyS, sizeof(keyS));
  7601. RECORD_MULTI_VALUE_STATS();
  7602. }
  7603. count += i;
  7604. } while (bench_stats_check(start)
  7605. #ifdef MULTI_VALUE_STATISTICS
  7606. || runs < minimum_runs
  7607. #endif
  7608. );
  7609. PRIVATE_KEY_LOCK();
  7610. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7611. #ifdef MULTI_VALUE_STATISTICS
  7612. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7613. #endif
  7614. RESET_MULTI_VALUE_STATS_VARS();
  7615. bench_stats_start(&count, &start);
  7616. PRIVATE_KEY_UNLOCK();
  7617. do {
  7618. for (i = 0; i < numBlocks; i++) {
  7619. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7620. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7621. keyS, sizeof(keyS));
  7622. RECORD_MULTI_VALUE_STATS();
  7623. }
  7624. count += i;
  7625. } while (bench_stats_check(start)
  7626. #ifdef MULTI_VALUE_STATISTICS
  7627. || runs < minimum_runs
  7628. #endif
  7629. );
  7630. PRIVATE_KEY_LOCK();
  7631. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7632. #ifdef MULTI_VALUE_STATISTICS
  7633. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7634. #endif
  7635. RESET_MULTI_VALUE_STATS_VARS();
  7636. bench_stats_start(&count, &start);
  7637. PRIVATE_KEY_UNLOCK();
  7638. do {
  7639. for (i = 0; i < numBlocks; i++) {
  7640. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7641. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7642. keyS, sizeof(keyS));
  7643. RECORD_MULTI_VALUE_STATS();
  7644. }
  7645. count += i;
  7646. } while (bench_stats_check(start)
  7647. #ifdef MULTI_VALUE_STATISTICS
  7648. || runs < minimum_runs
  7649. #endif
  7650. );
  7651. PRIVATE_KEY_LOCK();
  7652. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7653. #ifdef MULTI_VALUE_STATISTICS
  7654. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7655. #endif
  7656. RESET_MULTI_VALUE_STATS_VARS();
  7657. bench_stats_start(&count, &start);
  7658. PRIVATE_KEY_UNLOCK();
  7659. do {
  7660. for (i = 0; i < numBlocks; i++) {
  7661. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7662. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7663. keyS, sizeof(keyS));
  7664. RECORD_MULTI_VALUE_STATS();
  7665. }
  7666. count += i;
  7667. } while (bench_stats_check(start)
  7668. #ifdef MULTI_VALUE_STATISTICS
  7669. || runs < minimum_runs
  7670. #endif
  7671. );
  7672. PRIVATE_KEY_LOCK();
  7673. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7674. #ifdef MULTI_VALUE_STATISTICS
  7675. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7676. #endif
  7677. }
  7678. #endif
  7679. #ifndef NO_RSA
  7680. #if defined(WOLFSSL_KEY_GEN)
  7681. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7682. {
  7683. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7684. sizeof(RsaKey), HEAP_HINT);
  7685. double start = 0;
  7686. int ret = 0, i, count = 0, times, pending = 0;
  7687. const long rsa_e_val = WC_RSA_EXPONENT;
  7688. const char**desc = bench_desc_words[lng_index];
  7689. DECLARE_MULTI_VALUE_STATS_VARS()
  7690. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7691. sizeof(RsaKey), HEAP_HINT);
  7692. bench_stats_start(&count, &start);
  7693. do {
  7694. /* while free pending slots in queue, submit ops */
  7695. for (times = 0; times < genTimes || pending > 0; ) {
  7696. bench_async_poll(&pending);
  7697. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7698. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7699. 0, &times, genTimes, &pending)) {
  7700. wc_FreeRsaKey(genKey[i]);
  7701. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7702. if (ret < 0) {
  7703. goto exit;
  7704. }
  7705. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7706. &gRng);
  7707. if (!bench_async_handle(&ret,
  7708. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7709. &times, &pending)) {
  7710. goto exit;
  7711. }
  7712. }
  7713. } /* for i */
  7714. RECORD_MULTI_VALUE_STATS();
  7715. } /* for times */
  7716. count += times;
  7717. } while (bench_stats_check(start)
  7718. #ifdef MULTI_VALUE_STATISTICS
  7719. || runs < minimum_runs
  7720. #endif
  7721. );
  7722. exit:
  7723. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7724. start, ret);
  7725. #ifdef MULTI_VALUE_STATISTICS
  7726. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7727. #endif
  7728. /* cleanup */
  7729. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7730. wc_FreeRsaKey(genKey[i]);
  7731. }
  7732. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7733. }
  7734. void bench_rsaKeyGen(int useDeviceID)
  7735. {
  7736. int k;
  7737. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7738. static const word32 keySizes[2] = {1024, 2048 };
  7739. #elif RSA_MAX_SIZE >= 4096
  7740. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7741. (RSA_MIN_SIZE <= 1024)
  7742. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7743. #else
  7744. static const word32 keySizes[3] = {2048, 3072, 4096};
  7745. #endif
  7746. #elif RSA_MAX_SIZE >= 3072
  7747. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7748. (RSA_MIN_SIZE <= 1024)
  7749. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7750. #else
  7751. static const word32 keySizes[2] = {2048, 3072 };
  7752. #endif
  7753. #elif RSA_MAX_SIZE >= 2048
  7754. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7755. (RSA_MIN_SIZE <= 1024)
  7756. static const word32 keySizes[2] = {1024, 2048 };
  7757. #else
  7758. static const word32 keySizes[1] = {2048};
  7759. #endif
  7760. #else
  7761. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7762. (RSA_MIN_SIZE <= 1024)
  7763. static const word32 keySizes[1] = {1024 };
  7764. #else
  7765. #error No candidate RSA key sizes to benchmark.
  7766. #endif
  7767. #endif
  7768. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7769. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7770. }
  7771. }
  7772. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7773. {
  7774. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7775. }
  7776. #endif /* WOLFSSL_KEY_GEN */
  7777. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7778. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7779. #if defined(WOLFSSL_MDK_SHELL)
  7780. static char *certRSAname = "certs/rsa2048.der";
  7781. /* set by shell command */
  7782. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7783. #elif defined(FREESCALE_MQX)
  7784. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7785. #else
  7786. static const char *certRSAname = "certs/rsa2048.der";
  7787. #endif
  7788. #endif
  7789. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7790. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7791. #if defined(USE_CERT_BUFFERS_2048)
  7792. static const unsigned char rsa_2048_sig[] = {
  7793. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7794. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7795. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7796. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7797. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7798. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7799. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7800. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7801. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7802. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7803. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7804. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7805. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7806. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7807. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7808. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7809. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7810. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7811. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7812. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7813. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7814. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7815. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7816. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7817. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7818. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7819. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7820. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7821. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7822. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7823. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7824. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7825. };
  7826. #elif defined(USE_CERT_BUFFERS_3072)
  7827. static const unsigned char rsa_3072_sig[] = {
  7828. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7829. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7830. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7831. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7832. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7833. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7834. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7835. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7836. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7837. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7838. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7839. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7840. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7841. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7842. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7843. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7844. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7845. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7846. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7847. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7848. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7849. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7850. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7851. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7852. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7853. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7854. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7855. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7856. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7857. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7858. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7859. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7860. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7861. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7862. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7863. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7864. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7865. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7866. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7867. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7868. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7869. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7870. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7871. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7872. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7873. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7874. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7875. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7876. };
  7877. #else
  7878. #error Not Supported Yet!
  7879. #endif
  7880. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7881. static void bench_rsa_helper(int useDeviceID,
  7882. WC_ARRAY_ARG(rsaKey,
  7883. RsaKey,
  7884. BENCH_MAX_PENDING,
  7885. sizeof(RsaKey)),
  7886. word32 rsaKeySz)
  7887. {
  7888. int ret = 0, i, times, count = 0, pending = 0;
  7889. word32 idx = 0;
  7890. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7891. const char* messageStr = TEST_STRING;
  7892. const int len = (int)TEST_STRING_SZ;
  7893. #endif
  7894. double start = 0.0F;
  7895. const char**desc = bench_desc_words[lng_index];
  7896. DECLARE_MULTI_VALUE_STATS_VARS()
  7897. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7898. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7899. #endif
  7900. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7901. rsaKeySz, HEAP_HINT);
  7902. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7903. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7904. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7905. rsaKeySz, HEAP_HINT);
  7906. #else
  7907. byte* out[BENCH_MAX_PENDING];
  7908. #endif
  7909. XMEMSET(out, 0, sizeof(out));
  7910. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7911. rsaKeySz, HEAP_HINT);
  7912. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7913. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7914. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7915. rsaKeySz, HEAP_HINT);
  7916. if (out[0] == NULL) {
  7917. ret = MEMORY_E;
  7918. goto exit;
  7919. }
  7920. #endif
  7921. if (enc[0] == NULL) {
  7922. ret = MEMORY_E;
  7923. goto exit;
  7924. }
  7925. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7926. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7927. XMEMCPY(message, messageStr, len);
  7928. #endif
  7929. if (!rsa_sign_verify) {
  7930. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7931. /* begin public RSA */
  7932. bench_stats_start(&count, &start);
  7933. do {
  7934. for (times = 0; times < ntimes || pending > 0; ) {
  7935. bench_async_poll(&pending);
  7936. /* while free pending slots in queue, submit ops */
  7937. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7938. if (bench_async_check(&ret,
  7939. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7940. 1, &times, ntimes, &pending)) {
  7941. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7942. rsaKeySz/8, rsaKey[i],
  7943. GLOBAL_RNG);
  7944. if (!bench_async_handle(&ret,
  7945. BENCH_ASYNC_GET_DEV(
  7946. rsaKey[i]), 1, &times,
  7947. &pending)) {
  7948. goto exit_rsa_verify;
  7949. }
  7950. }
  7951. } /* for i */
  7952. RECORD_MULTI_VALUE_STATS();
  7953. } /* for times */
  7954. count += times;
  7955. } while (bench_stats_check(start)
  7956. #ifdef MULTI_VALUE_STATISTICS
  7957. || runs < minimum_runs
  7958. #endif
  7959. );
  7960. exit_rsa_verify:
  7961. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7962. useDeviceID, count, start, ret);
  7963. #ifdef MULTI_VALUE_STATISTICS
  7964. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7965. #endif
  7966. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7967. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7968. if (ret < 0) {
  7969. goto exit;
  7970. }
  7971. RESET_MULTI_VALUE_STATS_VARS();
  7972. /* capture resulting encrypt length */
  7973. idx = (word32)(rsaKeySz/8);
  7974. /* begin private async RSA */
  7975. bench_stats_start(&count, &start);
  7976. do {
  7977. for (times = 0; times < ntimes || pending > 0; ) {
  7978. bench_async_poll(&pending);
  7979. /* while free pending slots in queue, submit ops */
  7980. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7981. if (bench_async_check(&ret,
  7982. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7983. 1, &times, ntimes, &pending)) {
  7984. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7985. rsaKeySz/8, rsaKey[i]);
  7986. if (!bench_async_handle(&ret,
  7987. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7988. 1, &times, &pending)) {
  7989. goto exit_rsa_pub;
  7990. }
  7991. }
  7992. } /* for i */
  7993. RECORD_MULTI_VALUE_STATS();
  7994. } /* for times */
  7995. count += times;
  7996. } while (bench_stats_check(start)
  7997. #ifdef MULTI_VALUE_STATISTICS
  7998. || runs < minimum_runs
  7999. #endif
  8000. );
  8001. exit_rsa_pub:
  8002. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  8003. useDeviceID, count, start, ret);
  8004. #ifdef MULTI_VALUE_STATISTICS
  8005. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8006. #endif
  8007. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  8008. }
  8009. else {
  8010. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8011. /* begin RSA sign */
  8012. bench_stats_start(&count, &start);
  8013. do {
  8014. for (times = 0; times < ntimes || pending > 0; ) {
  8015. bench_async_poll(&pending);
  8016. /* while free pending slots in queue, submit ops */
  8017. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8018. if (bench_async_check(&ret,
  8019. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8020. 1, &times, ntimes, &pending)) {
  8021. ret = wc_RsaSSL_Sign(message, len, enc[i],
  8022. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  8023. if (!bench_async_handle(&ret,
  8024. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8025. 1, &times, &pending)) {
  8026. goto exit_rsa_sign;
  8027. }
  8028. }
  8029. } /* for i */
  8030. RECORD_MULTI_VALUE_STATS();
  8031. } /* for times */
  8032. count += times;
  8033. } while (bench_stats_check(start)
  8034. #ifdef MULTI_VALUE_STATISTICS
  8035. || runs < minimum_runs
  8036. #endif
  8037. );
  8038. exit_rsa_sign:
  8039. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  8040. count, start, ret);
  8041. #ifdef MULTI_VALUE_STATISTICS
  8042. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8043. #endif
  8044. if (ret < 0) {
  8045. goto exit;
  8046. }
  8047. RESET_MULTI_VALUE_STATS_VARS();
  8048. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  8049. /* capture resulting encrypt length */
  8050. idx = rsaKeySz/8;
  8051. /* begin RSA verify */
  8052. bench_stats_start(&count, &start);
  8053. do {
  8054. for (times = 0; times < ntimes || pending > 0; ) {
  8055. bench_async_poll(&pending);
  8056. /* while free pending slots in queue, submit ops */
  8057. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8058. if (bench_async_check(&ret,
  8059. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8060. 1, &times, ntimes, &pending)) {
  8061. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  8062. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8063. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  8064. rsaKeySz/8, rsaKey[i]);
  8065. #elif defined(USE_CERT_BUFFERS_2048)
  8066. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  8067. idx = sizeof(rsa_2048_sig);
  8068. out[i] = NULL;
  8069. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8070. &out[i], rsaKey[i]);
  8071. if (ret > 0) {
  8072. ret = 0;
  8073. }
  8074. #elif defined(USE_CERT_BUFFERS_3072)
  8075. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  8076. idx = sizeof(rsa_3072_sig);
  8077. out[i] = NULL;
  8078. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8079. &out[i], rsaKey[i]);
  8080. if (ret > 0)
  8081. ret = 0;
  8082. #endif
  8083. if (!bench_async_handle(&ret,
  8084. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8085. 1, &times, &pending)) {
  8086. goto exit_rsa_verifyinline;
  8087. }
  8088. }
  8089. } /* for i */
  8090. RECORD_MULTI_VALUE_STATS();
  8091. } /* for times */
  8092. count += times;
  8093. } while (bench_stats_check(start)
  8094. #ifdef MULTI_VALUE_STATISTICS
  8095. || runs < minimum_runs
  8096. #endif
  8097. );
  8098. exit_rsa_verifyinline:
  8099. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8100. useDeviceID, count, start, ret);
  8101. #ifdef MULTI_VALUE_STATISTICS
  8102. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8103. #endif
  8104. }
  8105. exit:
  8106. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8107. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8108. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8109. #endif
  8110. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8111. WC_FREE_VAR(message, HEAP_HINT);
  8112. #endif
  8113. }
  8114. void bench_rsa(int useDeviceID)
  8115. {
  8116. int i;
  8117. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8118. sizeof(RsaKey), HEAP_HINT);
  8119. int ret = 0;
  8120. word32 rsaKeySz = 0;
  8121. const byte* tmp;
  8122. size_t bytes;
  8123. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8124. word32 idx;
  8125. #endif
  8126. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8127. sizeof(RsaKey), HEAP_HINT);
  8128. #ifdef USE_CERT_BUFFERS_1024
  8129. tmp = rsa_key_der_1024;
  8130. bytes = (size_t)sizeof_rsa_key_der_1024;
  8131. rsaKeySz = 1024;
  8132. #elif defined(USE_CERT_BUFFERS_2048)
  8133. tmp = rsa_key_der_2048;
  8134. bytes = (size_t)sizeof_rsa_key_der_2048;
  8135. rsaKeySz = 2048;
  8136. #elif defined(USE_CERT_BUFFERS_3072)
  8137. tmp = rsa_key_der_3072;
  8138. bytes = (size_t)sizeof_rsa_key_der_3072;
  8139. rsaKeySz = 3072;
  8140. #elif defined(USE_CERT_BUFFERS_4096)
  8141. tmp = client_key_der_4096;
  8142. bytes = (size_t)sizeof_client_key_der_4096;
  8143. rsaKeySz = 4096;
  8144. #else
  8145. #error "need a cert buffer size"
  8146. #endif /* USE_CERT_BUFFERS */
  8147. /* init keys */
  8148. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8149. /* setup an async context for each key */
  8150. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8151. useDeviceID ? devId : INVALID_DEVID);
  8152. if (ret < 0) {
  8153. goto exit;
  8154. }
  8155. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8156. #ifdef WC_RSA_BLINDING
  8157. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8158. if (ret != 0)
  8159. goto exit;
  8160. #endif
  8161. #endif
  8162. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8163. /* decode the private key */
  8164. idx = 0;
  8165. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8166. rsaKey[i], (word32)bytes)) != 0) {
  8167. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8168. goto exit;
  8169. }
  8170. #elif defined(WOLFSSL_PUBLIC_MP)
  8171. /* get offset to public portion of the RSA key */
  8172. #ifdef USE_CERT_BUFFERS_1024
  8173. bytes = 11;
  8174. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8175. bytes = 12;
  8176. #endif
  8177. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8178. if (ret != 0) {
  8179. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8180. goto exit;
  8181. }
  8182. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8183. if (ret != 0) {
  8184. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8185. goto exit;
  8186. }
  8187. #else
  8188. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8189. rsaKeySz = 0;
  8190. #endif
  8191. }
  8192. if (rsaKeySz > 0) {
  8193. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8194. }
  8195. (void)bytes;
  8196. (void)tmp;
  8197. exit:
  8198. /* cleanup */
  8199. if (WC_ARRAY_OK(rsaKey)) {
  8200. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8201. wc_FreeRsaKey(rsaKey[i]);
  8202. }
  8203. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8204. }
  8205. }
  8206. #ifdef WOLFSSL_KEY_GEN
  8207. /* bench any size of RSA key */
  8208. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8209. {
  8210. int ret = 0, i, pending = 0;
  8211. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8212. sizeof(RsaKey), HEAP_HINT);
  8213. int isPending[BENCH_MAX_PENDING];
  8214. long exp = 65537L;
  8215. /* clear for done cleanup */
  8216. XMEMSET(isPending, 0, sizeof(isPending));
  8217. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8218. sizeof(RsaKey), HEAP_HINT);
  8219. /* init keys */
  8220. do {
  8221. pending = 0;
  8222. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8223. if (!isPending[i]) { /* if making the key is pending then just call
  8224. * wc_MakeRsaKey again */
  8225. /* setup an async context for each key */
  8226. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8227. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8228. goto exit;
  8229. }
  8230. #ifdef WC_RSA_BLINDING
  8231. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8232. if (ret != 0)
  8233. goto exit;
  8234. #endif
  8235. }
  8236. /* create the RSA key */
  8237. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8238. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8239. isPending[i] = 1;
  8240. pending = 1;
  8241. }
  8242. else if (ret != 0) {
  8243. printf("wc_MakeRsaKey failed! %d\n", ret);
  8244. goto exit;
  8245. }
  8246. } /* for i */
  8247. } while (pending > 0);
  8248. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8249. exit:
  8250. /* cleanup */
  8251. if (WC_ARRAY_OK(rsaKey)) {
  8252. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8253. wc_FreeRsaKey(rsaKey[i]);
  8254. }
  8255. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8256. }
  8257. }
  8258. #endif /* WOLFSSL_KEY_GEN */
  8259. #endif /* !NO_RSA */
  8260. #ifndef NO_DH
  8261. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8262. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8263. #if defined(WOLFSSL_MDK_SHELL)
  8264. static char *certDHname = "certs/dh2048.der";
  8265. /* set by shell command */
  8266. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8267. #elif defined(FREESCALE_MQX)
  8268. static char *certDHname = "a:\\certs\\dh2048.der";
  8269. #elif defined(NO_ASN)
  8270. /* do nothing, but don't need a file */
  8271. #else
  8272. static const char *certDHname = "certs/dh2048.der";
  8273. #endif
  8274. #endif
  8275. #ifdef HAVE_FFDHE_4096
  8276. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8277. #else
  8278. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8279. #endif
  8280. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8281. void bench_dh(int useDeviceID)
  8282. {
  8283. int ret = 0, i;
  8284. int count = 0, times, pending = 0;
  8285. const byte* tmp = NULL;
  8286. double start = 0.0F;
  8287. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8288. sizeof(DhKey), HEAP_HINT);
  8289. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8290. const char**desc = bench_desc_words[lng_index];
  8291. #ifndef NO_ASN
  8292. size_t bytes = 0;
  8293. word32 idx;
  8294. #endif
  8295. word32 pubSz[BENCH_MAX_PENDING];
  8296. word32 privSz[BENCH_MAX_PENDING];
  8297. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8298. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8299. word32 agreeSz[BENCH_MAX_PENDING];
  8300. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8301. #ifdef HAVE_PUBLIC_FFDHE
  8302. const DhParams *params = NULL;
  8303. #else
  8304. int paramName = 0;
  8305. #endif
  8306. #endif
  8307. DECLARE_MULTI_VALUE_STATS_VARS()
  8308. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8309. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8310. WC_DECLARE_VAR(pub2, byte,
  8311. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8312. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8313. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8314. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8315. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8316. WC_DECLARE_VAR(priv2, byte,
  8317. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8318. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8319. XMEMSET(pub, 0, sizeof(pub));
  8320. XMEMSET(agree, 0, sizeof(agree));
  8321. XMEMSET(priv, 0, sizeof(priv));
  8322. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8323. sizeof(DhKey), HEAP_HINT);
  8324. WC_ALLOC_ARRAY(pub, byte,
  8325. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8326. WC_ALLOC_ARRAY(agree, byte,
  8327. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8328. WC_ALLOC_ARRAY(priv, byte,
  8329. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8330. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8331. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8332. (void)tmp;
  8333. if (!use_ffdhe) {
  8334. #if defined(NO_ASN)
  8335. dhKeySz = 1024;
  8336. /* do nothing, but don't use default FILE */
  8337. #elif defined(USE_CERT_BUFFERS_1024)
  8338. tmp = dh_key_der_1024;
  8339. bytes = (size_t)sizeof_dh_key_der_1024;
  8340. dhKeySz = 1024;
  8341. #elif defined(USE_CERT_BUFFERS_2048)
  8342. tmp = dh_key_der_2048;
  8343. bytes = (size_t)sizeof_dh_key_der_2048;
  8344. dhKeySz = 2048;
  8345. #elif defined(USE_CERT_BUFFERS_3072)
  8346. tmp = dh_key_der_3072;
  8347. bytes = (size_t)sizeof_dh_key_der_3072;
  8348. dhKeySz = 3072;
  8349. #elif defined(USE_CERT_BUFFERS_4096)
  8350. tmp = dh_key_der_4096;
  8351. bytes = (size_t)sizeof_dh_key_der_4096;
  8352. dhKeySz = 4096;
  8353. #else
  8354. #error "need to define a cert buffer size"
  8355. #endif /* USE_CERT_BUFFERS */
  8356. }
  8357. #ifdef HAVE_FFDHE_2048
  8358. else if (use_ffdhe == 2048) {
  8359. #ifdef HAVE_PUBLIC_FFDHE
  8360. params = wc_Dh_ffdhe2048_Get();
  8361. #else
  8362. paramName = WC_FFDHE_2048;
  8363. #endif
  8364. dhKeySz = 2048;
  8365. }
  8366. #endif
  8367. #ifdef HAVE_FFDHE_3072
  8368. else if (use_ffdhe == 3072) {
  8369. #ifdef HAVE_PUBLIC_FFDHE
  8370. params = wc_Dh_ffdhe3072_Get();
  8371. #else
  8372. paramName = WC_FFDHE_3072;
  8373. #endif
  8374. dhKeySz = 3072;
  8375. }
  8376. #endif
  8377. #ifdef HAVE_FFDHE_4096
  8378. else if (use_ffdhe == 4096) {
  8379. #ifdef HAVE_PUBLIC_FFDHE
  8380. params = wc_Dh_ffdhe4096_Get();
  8381. #else
  8382. paramName = WC_FFDHE_4096;
  8383. #endif
  8384. dhKeySz = 4096;
  8385. }
  8386. #endif
  8387. /* init keys */
  8388. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8389. /* setup an async context for each key */
  8390. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8391. useDeviceID ? devId : INVALID_DEVID);
  8392. if (ret != 0)
  8393. goto exit;
  8394. /* setup key */
  8395. if (!use_ffdhe) {
  8396. #ifdef NO_ASN
  8397. ret = wc_DhSetKey(dhKey[i], dh_p,
  8398. sizeof(dh_p), dh_g, sizeof(dh_g));
  8399. #else
  8400. idx = 0;
  8401. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8402. #endif
  8403. }
  8404. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8405. #ifdef HAVE_PUBLIC_FFDHE
  8406. else if (params != NULL) {
  8407. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8408. params->g, params->g_len);
  8409. }
  8410. #else
  8411. else if (paramName != 0) {
  8412. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8413. }
  8414. #endif
  8415. #endif
  8416. if (ret != 0) {
  8417. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8418. goto exit;
  8419. }
  8420. }
  8421. /* Key Gen */
  8422. bench_stats_start(&count, &start);
  8423. PRIVATE_KEY_UNLOCK();
  8424. do {
  8425. /* while free pending slots in queue, submit ops */
  8426. for (times = 0; times < genTimes || pending > 0; ) {
  8427. bench_async_poll(&pending);
  8428. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8429. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8430. 0, &times, genTimes, &pending)) {
  8431. privSz[i] = BENCH_DH_PRIV_SIZE;
  8432. pubSz[i] = BENCH_DH_KEY_SIZE;
  8433. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8434. priv[i], &privSz[i],
  8435. pub[i], &pubSz[i]);
  8436. if (!bench_async_handle(&ret,
  8437. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8438. 0, &times, &pending)) {
  8439. goto exit_dh_gen;
  8440. }
  8441. }
  8442. } /* for i */
  8443. RECORD_MULTI_VALUE_STATS();
  8444. } /* for times */
  8445. count += times;
  8446. } while (bench_stats_check(start)
  8447. #ifdef MULTI_VALUE_STATISTICS
  8448. || runs < minimum_runs
  8449. #endif
  8450. );
  8451. PRIVATE_KEY_LOCK();
  8452. exit_dh_gen:
  8453. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8454. useDeviceID, count, start, ret);
  8455. #ifdef MULTI_VALUE_STATISTICS
  8456. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8457. #endif
  8458. if (ret < 0) {
  8459. goto exit;
  8460. }
  8461. RESET_MULTI_VALUE_STATS_VARS();
  8462. /* Generate key to use as other public */
  8463. PRIVATE_KEY_UNLOCK();
  8464. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8465. priv2, &privSz2, pub2, &pubSz2);
  8466. PRIVATE_KEY_LOCK();
  8467. #ifdef WOLFSSL_ASYNC_CRYPT
  8468. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8469. #endif
  8470. /* Key Agree */
  8471. bench_stats_start(&count, &start);
  8472. PRIVATE_KEY_UNLOCK();
  8473. do {
  8474. for (times = 0; times < agreeTimes || pending > 0; ) {
  8475. bench_async_poll(&pending);
  8476. /* while free pending slots in queue, submit ops */
  8477. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8478. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8479. 0, &times, agreeTimes, &pending)) {
  8480. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8481. privSz[i], pub2, pubSz2);
  8482. if (!bench_async_handle(&ret,
  8483. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8484. goto exit;
  8485. }
  8486. }
  8487. } /* for i */
  8488. RECORD_MULTI_VALUE_STATS();
  8489. } /* for times */
  8490. count += times;
  8491. } while (bench_stats_check(start)
  8492. #ifdef MULTI_VALUE_STATISTICS
  8493. || runs < minimum_runs
  8494. #endif
  8495. );
  8496. PRIVATE_KEY_LOCK();
  8497. exit:
  8498. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8499. useDeviceID, count, start, ret);
  8500. #ifdef MULTI_VALUE_STATISTICS
  8501. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8502. #endif
  8503. /* cleanup */
  8504. if (WC_ARRAY_OK(dhKey)) {
  8505. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8506. wc_FreeDhKey(dhKey[i]);
  8507. }
  8508. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8509. }
  8510. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8511. WC_FREE_VAR(pub2, HEAP_HINT);
  8512. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8513. WC_FREE_VAR(priv2, HEAP_HINT);
  8514. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8515. }
  8516. #endif /* !NO_DH */
  8517. #ifdef WOLFSSL_HAVE_KYBER
  8518. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8519. KyberKey* key)
  8520. {
  8521. int ret = 0, times, count, pending = 0;
  8522. double start;
  8523. const char**desc = bench_desc_words[lng_index];
  8524. DECLARE_MULTI_VALUE_STATS_VARS()
  8525. /* KYBER Make Key */
  8526. bench_stats_start(&count, &start);
  8527. do {
  8528. /* while free pending slots in queue, submit ops */
  8529. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8530. wc_KyberKey_Free(key);
  8531. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8532. if (ret != 0)
  8533. goto exit;
  8534. #ifdef KYBER_NONDETERMINISTIC
  8535. ret = wc_KyberKey_MakeKey(key, &gRng);
  8536. #else
  8537. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8538. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8539. #endif
  8540. if (ret != 0)
  8541. goto exit;
  8542. RECORD_MULTI_VALUE_STATS();
  8543. } /* for times */
  8544. count += times;
  8545. } while (bench_stats_check(start)
  8546. #ifdef MULTI_VALUE_STATISTICS
  8547. || runs < minimum_runs
  8548. #endif
  8549. );
  8550. exit:
  8551. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8552. #ifdef MULTI_VALUE_STATISTICS
  8553. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8554. #endif
  8555. }
  8556. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8557. {
  8558. int ret = 0, times, count, pending = 0;
  8559. double start;
  8560. const char**desc = bench_desc_words[lng_index];
  8561. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8562. byte ss[KYBER_SS_SZ];
  8563. word32 ctSz;
  8564. DECLARE_MULTI_VALUE_STATS_VARS()
  8565. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8566. if (ret != 0) {
  8567. return;
  8568. }
  8569. /* KYBER Encapsulate */
  8570. bench_stats_start(&count, &start);
  8571. do {
  8572. /* while free pending slots in queue, submit ops */
  8573. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8574. #ifdef KYBER_NONDETERMINISTIC
  8575. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8576. #else
  8577. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8578. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8579. sizeof(rand));
  8580. #endif
  8581. if (ret != 0)
  8582. goto exit_encap;
  8583. RECORD_MULTI_VALUE_STATS();
  8584. } /* for times */
  8585. count += times;
  8586. } while (bench_stats_check(start)
  8587. #ifdef MULTI_VALUE_STATISTICS
  8588. || runs < minimum_runs
  8589. #endif
  8590. );
  8591. exit_encap:
  8592. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8593. #ifdef MULTI_VALUE_STATISTICS
  8594. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8595. #endif
  8596. RESET_MULTI_VALUE_STATS_VARS();
  8597. /* KYBER Decapsulate */
  8598. bench_stats_start(&count, &start);
  8599. do {
  8600. /* while free pending slots in queue, submit ops */
  8601. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8602. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8603. if (ret != 0)
  8604. goto exit_decap;
  8605. RECORD_MULTI_VALUE_STATS();
  8606. } /* for times */
  8607. count += times;
  8608. } while (bench_stats_check(start)
  8609. #ifdef MULTI_VALUE_STATISTICS
  8610. || runs < minimum_runs
  8611. #endif
  8612. );
  8613. exit_decap:
  8614. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8615. #ifdef MULTI_VALUE_STATISTICS
  8616. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8617. #endif
  8618. }
  8619. void bench_kyber(int type)
  8620. {
  8621. KyberKey key;
  8622. const char* name = NULL;
  8623. int keySize = 0;
  8624. switch (type) {
  8625. #ifndef WOLFSSL_NO_ML_KEM
  8626. #ifdef WOLFSSL_WC_ML_KEM_512
  8627. case WC_ML_KEM_512:
  8628. name = "ML-KEM 512 ";
  8629. keySize = 128;
  8630. break;
  8631. #endif
  8632. #ifdef WOLFSSL_WC_ML_KEM_768
  8633. case WC_ML_KEM_768:
  8634. name = "ML-KEM 768 ";
  8635. keySize = 192;
  8636. break;
  8637. #endif
  8638. #ifdef WOLFSSL_WC_ML_KEM_1024
  8639. case WC_ML_KEM_1024:
  8640. name = "ML-KEM 1024 ";
  8641. keySize = 256;
  8642. break;
  8643. #endif
  8644. #endif
  8645. #ifdef WOLFSSL_KYBER_ORIGINAL
  8646. #ifdef WOLFSSL_KYBER512
  8647. case KYBER512:
  8648. name = "KYBER512 ";
  8649. keySize = 128;
  8650. break;
  8651. #endif
  8652. #ifdef WOLFSSL_KYBER768
  8653. case KYBER768:
  8654. name = "KYBER768 ";
  8655. keySize = 192;
  8656. break;
  8657. #endif
  8658. #ifdef WOLFSSL_KYBER1024
  8659. case KYBER1024:
  8660. name = "KYBER1024";
  8661. keySize = 256;
  8662. break;
  8663. #endif
  8664. #endif
  8665. }
  8666. bench_kyber_keygen(type, name, keySize, &key);
  8667. bench_kyber_encap(name, keySize, &key);
  8668. wc_KyberKey_Free(&key);
  8669. }
  8670. #endif
  8671. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8672. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8673. /* WC_LMS_PARM_L2_H10_W2
  8674. * signature length: 9300 */
  8675. static const byte lms_priv_L2_H10_W2[64] =
  8676. {
  8677. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8678. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8679. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8680. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8681. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8682. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8683. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8684. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8685. };
  8686. static const byte lms_pub_L2_H10_W2[60] =
  8687. {
  8688. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8689. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8690. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8691. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8692. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8693. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8694. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8695. 0x7F,0xC8,0x91,0xB0
  8696. };
  8697. /* WC_LMS_PARM_L2_H10_W4
  8698. * signature length: 5076 */
  8699. static const byte lms_priv_L2_H10_W4[64] =
  8700. {
  8701. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8702. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8703. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8704. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8705. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8706. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8707. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8708. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8709. };
  8710. static const byte lms_pub_L2_H10_W4[60] =
  8711. {
  8712. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8713. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8714. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8715. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8716. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8717. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8718. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8719. 0x6B,0x9A,0xD3,0x14
  8720. };
  8721. /* WC_LMS_PARM_L3_H5_W4
  8722. * signature length: 7160 */
  8723. static const byte lms_priv_L3_H5_W4[64] =
  8724. {
  8725. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8726. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8727. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8728. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8729. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8730. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8731. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8732. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8733. };
  8734. static const byte lms_pub_L3_H5_W4[60] =
  8735. {
  8736. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8737. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8738. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8739. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8740. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8741. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8742. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8743. 0xAB,0x4B,0x51,0x39
  8744. };
  8745. /* WC_LMS_PARM_L3_H5_W8
  8746. * signature length: 3992 */
  8747. static const byte lms_priv_L3_H5_W8[64] =
  8748. {
  8749. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8750. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8751. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8752. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8753. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8754. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8755. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8756. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8757. };
  8758. static const byte lms_pub_L3_H5_W8[60] =
  8759. {
  8760. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8761. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8762. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8763. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8764. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8765. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8766. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8767. 0x83,0xAB,0x43,0xAF
  8768. };
  8769. /* WC_LMS_PARM_L3_H10_W4
  8770. * signature length: 7640 */
  8771. static const byte lms_priv_L3_H10_W4[64] =
  8772. {
  8773. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8774. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8775. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8776. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8777. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8778. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8779. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8780. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8781. };
  8782. static const byte lms_pub_L3_H10_W4[60] =
  8783. {
  8784. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8785. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8786. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8787. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8788. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8789. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8790. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8791. 0x8D,0x78,0xD5,0xA8
  8792. };
  8793. /* WC_LMS_PARM_L4_H5_W8
  8794. * signature length: 5340 */
  8795. static const byte lms_priv_L4_H5_W8[64] =
  8796. {
  8797. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8798. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8799. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8800. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8801. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8802. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8803. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8804. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8805. };
  8806. static const byte lms_pub_L4_H5_W8[60] =
  8807. {
  8808. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8809. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8810. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8811. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8812. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8813. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8814. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8815. 0x74,0x24,0x12,0xC8
  8816. };
  8817. #endif
  8818. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8819. {
  8820. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8821. * BE USED FOR TESTING PURPOSES! Production applications should
  8822. * write only to non-volatile storage. */
  8823. XMEMCPY(context, priv, privSz);
  8824. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8825. }
  8826. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8827. {
  8828. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8829. * BE USED FOR TESTING PURPOSES! */
  8830. XMEMCPY(priv, context, privSz);
  8831. return WC_LMS_RC_READ_TO_MEMORY;
  8832. }
  8833. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8834. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8835. {
  8836. WC_RNG rng;
  8837. LmsKey key;
  8838. int ret;
  8839. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8840. int times = 0;
  8841. int count = 0;
  8842. double start = 0.0F;
  8843. int levels;
  8844. int height;
  8845. int winternitz;
  8846. const char* str = wc_LmsKey_ParmToStr(parm);
  8847. DECLARE_MULTI_VALUE_STATS_VARS()
  8848. #ifndef HAVE_FIPS
  8849. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8850. #else
  8851. ret = wc_InitRng(&rng);
  8852. #endif
  8853. if (ret != 0) {
  8854. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8855. return;
  8856. }
  8857. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8858. if (ret) {
  8859. printf("wc_LmsKey_Init failed: %d\n", ret);
  8860. wc_FreeRng(&rng);
  8861. return;
  8862. }
  8863. count = 0;
  8864. bench_stats_start(&count, &start);
  8865. do {
  8866. /* LMS is stateful. Async queuing not practical. */
  8867. for (times = 0; times < 1; ++times) {
  8868. wc_LmsKey_Free(&key);
  8869. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8870. if (ret) {
  8871. printf("wc_LmsKey_Init failed: %d\n", ret);
  8872. goto exit_lms_keygen;
  8873. }
  8874. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8875. if (ret) {
  8876. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8877. goto exit_lms_keygen;
  8878. }
  8879. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8880. if (ret) {
  8881. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8882. ret);
  8883. goto exit_lms_keygen;
  8884. }
  8885. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8886. if (ret) {
  8887. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8888. ret);
  8889. goto exit_lms_keygen;
  8890. }
  8891. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8892. if (ret) {
  8893. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8894. goto exit_lms_keygen;
  8895. }
  8896. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8897. if (ret) {
  8898. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8899. ret);
  8900. goto exit_lms_keygen;
  8901. }
  8902. ret = wc_LmsKey_MakeKey(&key, &rng);
  8903. if (ret) {
  8904. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8905. goto exit_lms_keygen;
  8906. }
  8907. RECORD_MULTI_VALUE_STATS();
  8908. }
  8909. count += times;
  8910. } while (bench_stats_check(start)
  8911. #ifdef MULTI_VALUE_STATISTICS
  8912. || runs < minimum_runs
  8913. #endif
  8914. );
  8915. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8916. count, start, ret);
  8917. #ifdef MULTI_VALUE_STATISTICS
  8918. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8919. #endif
  8920. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8921. if (ret) {
  8922. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8923. }
  8924. exit_lms_keygen:
  8925. wc_LmsKey_Free(&key);
  8926. wc_FreeRng(&rng);
  8927. }
  8928. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8929. {
  8930. LmsKey key;
  8931. int ret = 0;
  8932. const char * msg = TEST_STRING;
  8933. word32 msgSz = TEST_STRING_SZ;
  8934. byte * sig = NULL;
  8935. word32 sigSz = 0;
  8936. word32 privLen = 0;
  8937. int loaded = 0;
  8938. int times = 0;
  8939. int count = 0;
  8940. double start = 0.0F;
  8941. const char * str = wc_LmsKey_ParmToStr(parm);
  8942. DECLARE_MULTI_VALUE_STATS_VARS()
  8943. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8944. if (ret) {
  8945. printf("wc_LmsKey_Init failed: %d\n", ret);
  8946. goto exit_lms_sign_verify;
  8947. }
  8948. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8949. if (ret) {
  8950. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8951. goto exit_lms_sign_verify;
  8952. }
  8953. switch (parm) {
  8954. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8955. case WC_LMS_PARM_L2_H10_W2:
  8956. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8957. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8958. break;
  8959. case WC_LMS_PARM_L2_H10_W4:
  8960. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8961. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8962. break;
  8963. case WC_LMS_PARM_L3_H5_W4:
  8964. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8965. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8966. break;
  8967. case WC_LMS_PARM_L3_H5_W8:
  8968. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8969. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8970. break;
  8971. case WC_LMS_PARM_L3_H10_W4:
  8972. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8973. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8974. break;
  8975. case WC_LMS_PARM_L4_H5_W8:
  8976. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8977. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8978. break;
  8979. case WC_LMS_PARM_NONE:
  8980. case WC_LMS_PARM_L1_H15_W2:
  8981. case WC_LMS_PARM_L1_H15_W4:
  8982. case WC_LMS_PARM_L2_H10_W8:
  8983. case WC_LMS_PARM_L3_H5_W2:
  8984. case WC_LMS_PARM_L1_H5_W1:
  8985. case WC_LMS_PARM_L1_H5_W2:
  8986. case WC_LMS_PARM_L1_H5_W4:
  8987. case WC_LMS_PARM_L1_H5_W8:
  8988. case WC_LMS_PARM_L1_H10_W2:
  8989. case WC_LMS_PARM_L1_H10_W4:
  8990. case WC_LMS_PARM_L1_H10_W8:
  8991. case WC_LMS_PARM_L1_H15_W8:
  8992. case WC_LMS_PARM_L1_H20_W2:
  8993. case WC_LMS_PARM_L1_H20_W4:
  8994. case WC_LMS_PARM_L1_H20_W8:
  8995. case WC_LMS_PARM_L2_H5_W2:
  8996. case WC_LMS_PARM_L2_H5_W4:
  8997. case WC_LMS_PARM_L2_H5_W8:
  8998. case WC_LMS_PARM_L2_H15_W2:
  8999. case WC_LMS_PARM_L2_H15_W4:
  9000. case WC_LMS_PARM_L2_H15_W8:
  9001. case WC_LMS_PARM_L2_H20_W2:
  9002. case WC_LMS_PARM_L2_H20_W4:
  9003. case WC_LMS_PARM_L2_H20_W8:
  9004. case WC_LMS_PARM_L3_H10_W8:
  9005. case WC_LMS_PARM_L4_H5_W2:
  9006. case WC_LMS_PARM_L4_H5_W4:
  9007. case WC_LMS_PARM_L4_H10_W4:
  9008. case WC_LMS_PARM_L4_H10_W8:
  9009. #endif
  9010. #ifdef WOLFSSL_LMS_SHA256_192
  9011. case WC_LMS_PARM_SHA256_192_L1_H5_W1:
  9012. case WC_LMS_PARM_SHA256_192_L1_H5_W2:
  9013. case WC_LMS_PARM_SHA256_192_L1_H5_W4:
  9014. case WC_LMS_PARM_SHA256_192_L1_H5_W8:
  9015. case WC_LMS_PARM_SHA256_192_L1_H10_W2:
  9016. case WC_LMS_PARM_SHA256_192_L1_H10_W4:
  9017. case WC_LMS_PARM_SHA256_192_L1_H10_W8:
  9018. case WC_LMS_PARM_SHA256_192_L1_H15_W2:
  9019. case WC_LMS_PARM_SHA256_192_L1_H15_W4:
  9020. case WC_LMS_PARM_SHA256_192_L2_H10_W2:
  9021. case WC_LMS_PARM_SHA256_192_L2_H10_W4:
  9022. case WC_LMS_PARM_SHA256_192_L2_H10_W8:
  9023. case WC_LMS_PARM_SHA256_192_L3_H5_W2:
  9024. case WC_LMS_PARM_SHA256_192_L3_H5_W4:
  9025. case WC_LMS_PARM_SHA256_192_L3_H5_W8:
  9026. case WC_LMS_PARM_SHA256_192_L3_H10_W4:
  9027. case WC_LMS_PARM_SHA256_192_L4_H5_W8:
  9028. #endif
  9029. default:
  9030. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  9031. break;
  9032. }
  9033. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  9034. if (ret) {
  9035. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  9036. goto exit_lms_sign_verify;
  9037. }
  9038. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  9039. if (ret) {
  9040. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  9041. goto exit_lms_sign_verify;
  9042. }
  9043. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  9044. if (ret) {
  9045. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  9046. goto exit_lms_sign_verify;
  9047. }
  9048. /* Even with saved priv/pub keys, we must still reload the private
  9049. * key before using it. Reloading the private key is the bottleneck
  9050. * for larger heights. Only print load time in debug builds. */
  9051. count = 0;
  9052. bench_stats_start(&count, &start);
  9053. #ifndef WOLFSSL_WC_LMS_SMALL
  9054. do {
  9055. #ifdef WOLFSSL_WC_LMS
  9056. key.priv.inited = 0;
  9057. key.state = WC_LMS_STATE_PARMSET;
  9058. #endif
  9059. ret = wc_LmsKey_Reload(&key);
  9060. if (ret) {
  9061. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9062. goto exit_lms_sign_verify;
  9063. }
  9064. RECORD_MULTI_VALUE_STATS();
  9065. count++;
  9066. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9067. if (ret) {
  9068. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9069. goto exit_lms_sign_verify;
  9070. }
  9071. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9072. if (ret) {
  9073. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9074. goto exit_lms_sign_verify;
  9075. }
  9076. #ifdef HAVE_LIBLMS
  9077. break;
  9078. #endif
  9079. } while (bench_stats_check(start)
  9080. #ifdef MULTI_VALUE_STATISTICS
  9081. || runs < minimum_runs
  9082. #endif
  9083. );
  9084. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  9085. count, start, ret);
  9086. #ifdef MULTI_VALUE_STATISTICS
  9087. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9088. #endif
  9089. RESET_MULTI_VALUE_STATS_VARS();
  9090. #else
  9091. ret = wc_LmsKey_Reload(&key);
  9092. if (ret) {
  9093. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9094. goto exit_lms_sign_verify;
  9095. }
  9096. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9097. if (ret) {
  9098. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9099. goto exit_lms_sign_verify;
  9100. }
  9101. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9102. if (ret) {
  9103. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9104. goto exit_lms_sign_verify;
  9105. }
  9106. #endif
  9107. loaded = 1;
  9108. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9109. if (sig == NULL) {
  9110. printf("bench_lms_sign_verify malloc failed\n");
  9111. goto exit_lms_sign_verify;
  9112. }
  9113. count = 0;
  9114. bench_stats_start(&count, &start);
  9115. do {
  9116. /* LMS is stateful. Async queuing not practical. */
  9117. #ifndef WOLFSSL_WC_LMS_SMALL
  9118. for (times = 0; times < ntimes; ++times)
  9119. #else
  9120. for (times = 0; times < 1; ++times)
  9121. #endif
  9122. {
  9123. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9124. if (ret) {
  9125. printf("wc_LmsKey_Sign failed: %d\n", ret);
  9126. goto exit_lms_sign_verify;
  9127. }
  9128. RECORD_MULTI_VALUE_STATS();
  9129. if (!wc_LmsKey_SigsLeft(&key)) {
  9130. break;
  9131. }
  9132. }
  9133. count += times;
  9134. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9135. #ifdef MULTI_VALUE_STATISTICS
  9136. || runs < minimum_runs
  9137. #endif
  9138. ));
  9139. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9140. count, start, ret);
  9141. #ifdef MULTI_VALUE_STATISTICS
  9142. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9143. #endif
  9144. RESET_MULTI_VALUE_STATS_VARS();
  9145. count = 0;
  9146. bench_stats_start(&count, &start);
  9147. do {
  9148. /* LMS is stateful. Async queuing not practical. */
  9149. for (times = 0; times < ntimes; ++times) {
  9150. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9151. if (ret) {
  9152. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9153. goto exit_lms_sign_verify;
  9154. }
  9155. RECORD_MULTI_VALUE_STATS();
  9156. }
  9157. count += times;
  9158. } while (bench_stats_check(start)
  9159. #ifdef MULTI_VALUE_STATISTICS
  9160. || runs < minimum_runs
  9161. #endif
  9162. );
  9163. exit_lms_sign_verify:
  9164. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9165. count, start, ret);
  9166. #ifdef MULTI_VALUE_STATISTICS
  9167. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9168. #endif
  9169. if (loaded) {
  9170. wc_LmsKey_Free(&key);
  9171. }
  9172. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9173. return;
  9174. }
  9175. void bench_lms(void)
  9176. {
  9177. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9178. #ifndef WOLFSSL_NO_LMS_SHA256_256
  9179. #ifdef BENCH_LMS_SLOW_KEYGEN
  9180. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9181. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9182. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9183. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9184. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9185. #undef LMS_PARAMS_BENCHED
  9186. #define LMS_PARAMS_BENCHED
  9187. #endif
  9188. #endif
  9189. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9190. (LMS_MAX_HEIGHT >= 10))
  9191. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9192. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9193. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9194. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9195. #undef LMS_PARAMS_BENCHED
  9196. #define LMS_PARAMS_BENCHED
  9197. #ifdef BENCH_LMS_SLOW_KEYGEN
  9198. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9199. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9200. #endif
  9201. #endif
  9202. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9203. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9204. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9205. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9206. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9207. #undef LMS_PARAMS_BENCHED
  9208. #define LMS_PARAMS_BENCHED
  9209. #endif
  9210. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9211. (LMS_MAX_HEIGHT >= 10))
  9212. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9213. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9214. #endif
  9215. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9216. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9217. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9218. #endif
  9219. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9220. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9221. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9222. #endif
  9223. #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
  9224. #ifdef WOLFSSL_LMS_SHA256_192
  9225. #ifdef BENCH_LMS_SLOW_KEYGEN
  9226. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9227. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9228. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9229. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9230. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9231. #undef LMS_PARAMS_BENCHED
  9232. #define LMS_PARAMS_BENCHED
  9233. #endif
  9234. #endif
  9235. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9236. (LMS_MAX_HEIGHT >= 10))
  9237. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9238. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9239. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9240. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9241. #undef LMS_PARAMS_BENCHED
  9242. #define LMS_PARAMS_BENCHED
  9243. #ifdef BENCH_LMS_SLOW_KEYGEN
  9244. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9245. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9246. #endif
  9247. #endif
  9248. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9249. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9250. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9251. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9252. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9253. #undef LMS_PARAMS_BENCHED
  9254. #define LMS_PARAMS_BENCHED
  9255. #endif
  9256. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9257. (LMS_MAX_HEIGHT >= 10))
  9258. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9259. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9260. #endif
  9261. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9262. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9263. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9264. #endif
  9265. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9266. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9267. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9268. #endif
  9269. #endif /* WOLFSSL_LMS_SHA256_192 */
  9270. return;
  9271. }
  9272. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9273. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9274. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9275. void *context)
  9276. {
  9277. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9278. * BE USED FOR TESTING PURPOSES! Production applications should
  9279. * write only to non-volatile storage. */
  9280. XMEMCPY(context, priv, privSz);
  9281. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9282. }
  9283. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9284. void *context)
  9285. {
  9286. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9287. * BE USED FOR TESTING PURPOSES! */
  9288. XMEMCPY(priv, context, privSz);
  9289. return WC_XMSS_RC_READ_TO_MEMORY;
  9290. }
  9291. static void bench_xmss_sign_verify(const char * params)
  9292. {
  9293. WC_RNG rng;
  9294. XmssKey key;
  9295. word32 pkSz = 0;
  9296. word32 skSz = 0;
  9297. int freeRng = 0;
  9298. int freeKey = 0;
  9299. unsigned char * sk = NULL;
  9300. const char * msg = "XMSS post quantum signature test";
  9301. word32 msgSz = (word32) XSTRLEN(msg);
  9302. int ret = 0;
  9303. byte * sig = NULL;
  9304. word32 sigSz = 0;
  9305. int times = 0;
  9306. int count = 0;
  9307. double start = 0.0F;
  9308. #ifndef HAVE_FIPS
  9309. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9310. #else
  9311. ret = wc_InitRng(&rng);
  9312. #endif
  9313. if (ret != 0) {
  9314. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9315. goto exit_xmss_sign_verify;
  9316. }
  9317. freeRng = 1;
  9318. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9319. if (ret != 0) {
  9320. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9321. goto exit_xmss_sign_verify;
  9322. }
  9323. ret = wc_XmssKey_SetParamStr(&key, params);
  9324. if (ret != 0) {
  9325. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9326. goto exit_xmss_sign_verify;
  9327. }
  9328. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9329. if (ret != 0) {
  9330. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9331. goto exit_xmss_sign_verify;
  9332. }
  9333. #ifndef WOLFSSL_WC_XMSS
  9334. if (pkSz != XMSS_SHA256_PUBLEN) {
  9335. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9336. XMSS_SHA256_PUBLEN);
  9337. goto exit_xmss_sign_verify;
  9338. }
  9339. #endif
  9340. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9341. if (ret != 0 || skSz <= 0) {
  9342. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9343. goto exit_xmss_sign_verify;
  9344. }
  9345. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9346. if (ret != 0 || sigSz <= 0) {
  9347. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9348. goto exit_xmss_sign_verify;
  9349. }
  9350. /* Allocate secret keys.*/
  9351. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9352. if (sk == NULL) {
  9353. fprintf(stderr, "error: allocate xmss sk failed\n");
  9354. goto exit_xmss_sign_verify;
  9355. }
  9356. /* Allocate signature array. */
  9357. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9358. if (sig == NULL) {
  9359. fprintf(stderr, "error: allocate xmss sig failed\n");
  9360. goto exit_xmss_sign_verify;
  9361. }
  9362. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9363. if (ret != 0) {
  9364. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9365. goto exit_xmss_sign_verify;
  9366. }
  9367. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9368. if (ret != 0) {
  9369. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9370. goto exit_xmss_sign_verify;
  9371. }
  9372. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9373. if (ret != 0) {
  9374. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9375. goto exit_xmss_sign_verify;
  9376. }
  9377. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9378. fprintf(stderr, "params: %s\n", params);
  9379. fprintf(stderr, "pkSz: %d\n", pkSz);
  9380. fprintf(stderr, "skSz: %d\n", skSz);
  9381. fprintf(stderr, "sigSz: %d\n", sigSz);
  9382. #endif
  9383. /* Making the private key is the bottleneck for larger heights. */
  9384. count = 0;
  9385. bench_stats_start(&count, &start);
  9386. ret = wc_XmssKey_MakeKey(&key, &rng);
  9387. if (ret != 0) {
  9388. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9389. goto exit_xmss_sign_verify;
  9390. }
  9391. /* Can only do one at a time - state changes after make key. */
  9392. count +=1;
  9393. bench_stats_check(start);
  9394. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9395. freeKey = 1;
  9396. count = 0;
  9397. bench_stats_start(&count, &start);
  9398. do {
  9399. /* XMSS is stateful. Async queuing not practical. */
  9400. #ifndef WOLFSSL_WC_XMSS_SMALL
  9401. for (times = 0; times < ntimes; ++times)
  9402. #else
  9403. for (times = 0; times < 1; ++times)
  9404. #endif
  9405. {
  9406. if (!wc_XmssKey_SigsLeft(&key))
  9407. break;
  9408. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9409. if (ret) {
  9410. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9411. goto exit_xmss_sign_verify;
  9412. }
  9413. }
  9414. count += times;
  9415. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9416. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9417. count = 0;
  9418. bench_stats_start(&count, &start);
  9419. do {
  9420. /* XMSS is stateful. Async queuing not practical. */
  9421. for (times = 0; times < ntimes; ++times) {
  9422. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9423. if (ret) {
  9424. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9425. goto exit_xmss_sign_verify;
  9426. }
  9427. }
  9428. count += times;
  9429. } while (bench_stats_check(start));
  9430. exit_xmss_sign_verify:
  9431. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9432. /* Cleanup everything. */
  9433. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9434. sig = NULL;
  9435. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9436. sk = NULL;
  9437. if (freeRng) {
  9438. wc_FreeRng(&rng);
  9439. }
  9440. if (freeKey) {
  9441. wc_XmssKey_Free(&key);
  9442. }
  9443. return;
  9444. }
  9445. void bench_xmss(int hash)
  9446. {
  9447. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9448. * sets.
  9449. *
  9450. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9451. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9452. * very slow, their signatures and private keys quite large,
  9453. * and xmss private keys are not portable across different
  9454. * XMSS/XMSS^MT implementations.
  9455. *
  9456. * The bottleneck in key generation is the height of the first
  9457. * level tree (or h/d).
  9458. *
  9459. * h is the total height of the hyper tree, and d the number of
  9460. * trees.
  9461. */
  9462. /* h/d h d */
  9463. #ifdef WC_XMSS_SHA256
  9464. if (hash == WC_HASH_TYPE_SHA256) {
  9465. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9466. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9467. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9468. #endif
  9469. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9470. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9471. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9472. #endif
  9473. #endif
  9474. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9475. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9476. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9477. #endif
  9478. #endif
  9479. #endif /* HASH_SIZE 256 */
  9480. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9481. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9482. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 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_192"); /* 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_192"); /* 20 20 1 */
  9492. #endif
  9493. #endif
  9494. #endif /* HASH_SIZE 192 */
  9495. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9496. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9497. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9498. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9499. #endif
  9500. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9501. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9502. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9503. #endif
  9504. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9505. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 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_256"); /* 20 60 3 */
  9510. #endif
  9511. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9512. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9513. #endif
  9514. #endif /* HASH_SIZE 256 */
  9515. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9516. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9517. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9518. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9519. #endif
  9520. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9521. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9522. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9523. #endif
  9524. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9525. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9526. #endif
  9527. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9528. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9529. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9530. #endif
  9531. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9532. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9533. #endif
  9534. #endif /* HASH_SIZE 192 */
  9535. }
  9536. #endif
  9537. #ifdef WC_XMSS_SHA512
  9538. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9539. if (hash == WC_HASH_TYPE_SHA512) {
  9540. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9541. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9542. #endif
  9543. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9544. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9545. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9546. #endif
  9547. #endif
  9548. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9549. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9550. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9551. #endif
  9552. #endif
  9553. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9554. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9555. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9556. #endif
  9557. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9558. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9559. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9560. #endif
  9561. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9562. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9563. #endif
  9564. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9565. #endif
  9566. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9567. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9568. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9569. #endif
  9570. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9571. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9572. #endif
  9573. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9574. #endif
  9575. }
  9576. #endif /* HASH_SIZE 512 */
  9577. #endif
  9578. #ifdef WC_XMSS_SHAKE128
  9579. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9580. if (hash == WC_HASH_TYPE_SHAKE128) {
  9581. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9582. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9583. #endif
  9584. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9585. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9586. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9587. #endif
  9588. #endif
  9589. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9590. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9591. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9592. #endif
  9593. #endif
  9594. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9595. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9596. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9597. #endif
  9598. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9599. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9600. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9601. #endif
  9602. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9603. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9604. #endif
  9605. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9606. #endif
  9607. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9608. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9609. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9610. #endif
  9611. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9612. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9613. #endif
  9614. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9615. #endif
  9616. }
  9617. #endif /* HASH_SIZE 256 */
  9618. #endif
  9619. #ifdef WC_XMSS_SHAKE256
  9620. if (hash == WC_HASH_TYPE_SHAKE256) {
  9621. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9622. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9623. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9624. #endif
  9625. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9626. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9627. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9628. #endif
  9629. #endif
  9630. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9631. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9632. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9633. #endif
  9634. #endif
  9635. #endif /* HASH_SIZE 512 */
  9636. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9637. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9638. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9639. #endif
  9640. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9641. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9642. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9643. #endif
  9644. #endif
  9645. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9646. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9647. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9648. #endif
  9649. #endif
  9650. #endif /* HASH_SIZE 256 */
  9651. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9652. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9653. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9654. #endif
  9655. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9656. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9657. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9658. #endif
  9659. #endif
  9660. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9661. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9662. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9663. #endif
  9664. #endif
  9665. #endif /* HASH_SIZE 192 */
  9666. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9667. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9668. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9669. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9670. #endif
  9671. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9672. #endif
  9673. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9674. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9675. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9676. #endif
  9677. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9678. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9679. #endif
  9680. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9681. #endif
  9682. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9683. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9684. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9685. #endif
  9686. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9687. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9688. #endif
  9689. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9690. #endif
  9691. #endif /* HASH_SIZE 512 */
  9692. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9693. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9694. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9695. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9696. #endif
  9697. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9698. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9699. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9700. #endif
  9701. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9702. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9703. #endif
  9704. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9705. #endif
  9706. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9707. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9708. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9709. #endif
  9710. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9711. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9712. #endif
  9713. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9714. #endif
  9715. #endif /* HASH_SIZE 256 */
  9716. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9717. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9718. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9719. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9720. #endif
  9721. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9722. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9723. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9724. #endif
  9725. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9726. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9727. #endif
  9728. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9729. #endif
  9730. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9731. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9732. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9733. #endif
  9734. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9735. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9736. #endif
  9737. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9738. #endif
  9739. #endif /* HASH_SIZE 192 */
  9740. }
  9741. #endif
  9742. return;
  9743. }
  9744. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9745. #ifdef HAVE_ECC
  9746. /* Maximum ECC name plus null terminator:
  9747. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9748. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9749. /* run all benchmarks on a curve */
  9750. void bench_ecc_curve(int curveId)
  9751. {
  9752. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9753. #ifndef NO_SW_BENCH
  9754. bench_eccMakeKey(0, curveId);
  9755. #endif
  9756. #if defined(BENCH_DEVID)
  9757. bench_eccMakeKey(1, curveId);
  9758. #endif
  9759. }
  9760. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9761. #ifndef NO_SW_BENCH
  9762. bench_ecc(0, curveId);
  9763. #endif
  9764. #if defined(BENCH_DEVID)
  9765. bench_ecc(1, curveId);
  9766. #endif
  9767. }
  9768. #ifdef HAVE_ECC_ENCRYPT
  9769. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9770. bench_eccEncrypt(curveId);
  9771. #endif
  9772. }
  9773. void bench_eccMakeKey(int useDeviceID, int curveId)
  9774. {
  9775. int ret = 0, i, times, count = 0, pending = 0;
  9776. int deviceID;
  9777. int keySize = 0;
  9778. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9779. sizeof(ecc_key), HEAP_HINT);
  9780. char name[BENCH_ECC_NAME_SZ];
  9781. double start = 0;
  9782. const char**desc = bench_desc_words[lng_index];
  9783. DECLARE_MULTI_VALUE_STATS_VARS()
  9784. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9785. sizeof(ecc_key), HEAP_HINT);
  9786. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9787. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9788. /* ECC Make Key */
  9789. bench_stats_start(&count, &start);
  9790. do {
  9791. /* while free pending slots in queue, submit ops */
  9792. for (times = 0; times < agreeTimes || pending > 0; ) {
  9793. bench_async_poll(&pending);
  9794. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9795. if (bench_async_check(&ret,
  9796. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9797. &times, agreeTimes, &pending)) {
  9798. wc_ecc_free(genKey[i]);
  9799. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9800. if (ret < 0) {
  9801. goto exit;
  9802. }
  9803. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9804. curveId);
  9805. if (!bench_async_handle(&ret,
  9806. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9807. &pending)) {
  9808. goto exit;
  9809. }
  9810. }
  9811. } /* for i */
  9812. RECORD_MULTI_VALUE_STATS();
  9813. } /* for times */
  9814. count += times;
  9815. } while (bench_stats_check(start)
  9816. #ifdef MULTI_VALUE_STATISTICS
  9817. || runs < minimum_runs
  9818. #endif
  9819. );
  9820. exit:
  9821. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9822. wc_ecc_get_name(curveId));
  9823. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9824. useDeviceID, count, start, ret);
  9825. #ifdef MULTI_VALUE_STATISTICS
  9826. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9827. #endif
  9828. /* cleanup */
  9829. if (WC_ARRAY_OK(genKey)) {
  9830. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9831. wc_ecc_free(genKey[i]);
  9832. }
  9833. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9834. }
  9835. }
  9836. void bench_ecc(int useDeviceID, int curveId)
  9837. {
  9838. int ret = 0, i, times, count, pending = 0;
  9839. int deviceID;
  9840. int keySize;
  9841. char name[BENCH_ECC_NAME_SZ];
  9842. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9843. sizeof(ecc_key), HEAP_HINT);
  9844. #ifdef HAVE_ECC_DHE
  9845. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9846. sizeof(ecc_key), HEAP_HINT);
  9847. #endif
  9848. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9849. #ifdef HAVE_ECC_VERIFY
  9850. int verify[BENCH_MAX_PENDING];
  9851. #endif
  9852. #endif
  9853. word32 x[BENCH_MAX_PENDING];
  9854. double start = 0;
  9855. const char**desc = bench_desc_words[lng_index];
  9856. DECLARE_MULTI_VALUE_STATS_VARS()
  9857. #ifdef HAVE_ECC_DHE
  9858. WC_DECLARE_ARRAY(shared, byte,
  9859. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9860. #endif
  9861. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9862. WC_DECLARE_ARRAY(sig, byte,
  9863. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9864. WC_DECLARE_ARRAY(digest, byte,
  9865. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9866. #endif
  9867. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9868. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9869. XMEMSET(sig, 0, sizeof(sig));
  9870. XMEMSET(digest, 0, sizeof(digest));
  9871. #endif
  9872. #ifdef HAVE_ECC_DHE
  9873. XMEMSET(shared, 0, sizeof(shared));
  9874. #endif
  9875. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9876. sizeof(ecc_key), HEAP_HINT);
  9877. #ifdef HAVE_ECC_DHE
  9878. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9879. sizeof(ecc_key), HEAP_HINT);
  9880. WC_ALLOC_ARRAY(shared, byte,
  9881. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9882. #endif
  9883. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9884. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9885. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9886. #endif
  9887. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9888. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9889. /* init keys */
  9890. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9891. /* setup an context for each key */
  9892. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9893. goto exit;
  9894. }
  9895. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9896. #ifdef WOLFSSL_ASYNC_CRYPT
  9897. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9898. #endif
  9899. if (ret < 0) {
  9900. goto exit;
  9901. }
  9902. #ifdef HAVE_ECC_DHE
  9903. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9904. goto exit;
  9905. }
  9906. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9907. curveId)) > 0) {
  9908. goto exit;
  9909. }
  9910. #endif
  9911. }
  9912. #ifdef HAVE_ECC_DHE
  9913. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9914. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9915. !defined(HAVE_SELFTEST)
  9916. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9917. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9918. }
  9919. #endif
  9920. /* ECC Shared Secret */
  9921. bench_stats_start(&count, &start);
  9922. PRIVATE_KEY_UNLOCK();
  9923. do {
  9924. for (times = 0; times < agreeTimes || pending > 0; ) {
  9925. bench_async_poll(&pending);
  9926. /* while free pending slots in queue, submit ops */
  9927. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9928. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9929. &times, agreeTimes, &pending)) {
  9930. x[i] = (word32)keySize;
  9931. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9932. shared[i], &x[i]);
  9933. if (!bench_async_handle(&ret,
  9934. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9935. &pending)) {
  9936. goto exit_ecdhe;
  9937. }
  9938. }
  9939. } /* for i */
  9940. RECORD_MULTI_VALUE_STATS();
  9941. } /* for times */
  9942. count += times;
  9943. } while (bench_stats_check(start)
  9944. #ifdef MULTI_VALUE_STATISTICS
  9945. || runs < minimum_runs
  9946. #endif
  9947. );
  9948. PRIVATE_KEY_UNLOCK();
  9949. exit_ecdhe:
  9950. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9951. wc_ecc_get_name(curveId));
  9952. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9953. useDeviceID, count, start, ret);
  9954. #ifdef MULTI_VALUE_STATISTICS
  9955. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9956. #endif
  9957. RESET_MULTI_VALUE_STATS_VARS();
  9958. if (ret < 0) {
  9959. goto exit;
  9960. }
  9961. #endif /* HAVE_ECC_DHE */
  9962. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9963. /* Init digest to sign */
  9964. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9965. for (count = 0; count < keySize; count++) {
  9966. digest[i][count] = (byte)count;
  9967. }
  9968. }
  9969. /* ECC Sign */
  9970. bench_stats_start(&count, &start);
  9971. do {
  9972. for (times = 0; times < agreeTimes || pending > 0; ) {
  9973. bench_async_poll(&pending);
  9974. /* while free pending slots in queue, submit ops */
  9975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9976. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9977. &times, agreeTimes, &pending)) {
  9978. if (genKey[i]->state == 0) {
  9979. x[i] = ECC_MAX_SIG_SIZE;
  9980. }
  9981. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9982. &x[i], GLOBAL_RNG, genKey[i]);
  9983. if (!bench_async_handle(&ret,
  9984. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9985. &pending)) {
  9986. goto exit_ecdsa_sign;
  9987. }
  9988. } /* bench_async_check */
  9989. } /* for i */
  9990. RECORD_MULTI_VALUE_STATS();
  9991. } /* for times */
  9992. count += times;
  9993. } while (bench_stats_check(start)
  9994. #ifdef MULTI_VALUE_STATISTICS
  9995. || runs < minimum_runs
  9996. #endif
  9997. );
  9998. exit_ecdsa_sign:
  9999. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10000. wc_ecc_get_name(curveId));
  10001. bench_stats_asym_finish(name, keySize * 8, desc[4],
  10002. useDeviceID, count, start, ret);
  10003. #ifdef MULTI_VALUE_STATISTICS
  10004. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10005. #endif
  10006. RESET_MULTI_VALUE_STATS_VARS();
  10007. if (ret < 0) {
  10008. goto exit;
  10009. }
  10010. #ifdef HAVE_ECC_VERIFY
  10011. /* ECC Verify */
  10012. bench_stats_start(&count, &start);
  10013. do {
  10014. for (times = 0; times < agreeTimes || pending > 0; ) {
  10015. bench_async_poll(&pending);
  10016. /* while free pending slots in queue, submit ops */
  10017. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10018. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10019. &times, agreeTimes, &pending)) {
  10020. if (genKey[i]->state == 0) {
  10021. verify[i] = 0;
  10022. }
  10023. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  10024. (word32)keySize, &verify[i],
  10025. genKey[i]);
  10026. if (!bench_async_handle(&ret,
  10027. BENCH_ASYNC_GET_DEV(genKey[i]),
  10028. 1, &times,
  10029. &pending)) {
  10030. goto exit_ecdsa_verify;
  10031. }
  10032. } /* if bench_async_check */
  10033. } /* for i */
  10034. RECORD_MULTI_VALUE_STATS();
  10035. } /* for times */
  10036. count += times;
  10037. } while (bench_stats_check(start)
  10038. #ifdef MULTI_VALUE_STATISTICS
  10039. || runs < minimum_runs
  10040. #endif
  10041. );
  10042. exit_ecdsa_verify:
  10043. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10044. wc_ecc_get_name(curveId));
  10045. bench_stats_asym_finish(name, keySize * 8, desc[5],
  10046. useDeviceID, count, start, ret);
  10047. #ifdef MULTI_VALUE_STATISTICS
  10048. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10049. #endif
  10050. #endif /* HAVE_ECC_VERIFY */
  10051. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10052. exit:
  10053. /* cleanup */
  10054. if (WC_ARRAY_OK(genKey)) {
  10055. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10056. wc_ecc_free(genKey[i]);
  10057. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10058. }
  10059. #ifdef HAVE_ECC_DHE
  10060. if (WC_ARRAY_OK(genKey2)) {
  10061. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10062. wc_ecc_free(genKey2[i]);
  10063. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10064. }
  10065. #endif
  10066. #ifdef HAVE_ECC_DHE
  10067. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10068. #endif
  10069. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10070. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10071. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10072. #endif
  10073. (void)useDeviceID;
  10074. (void)pending;
  10075. (void)x;
  10076. (void)count;
  10077. (void)times;
  10078. (void)desc;
  10079. (void)start;
  10080. (void)name;
  10081. }
  10082. #ifdef HAVE_ECC_ENCRYPT
  10083. void bench_eccEncrypt(int curveId)
  10084. {
  10085. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  10086. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  10087. WC_SHA256_DIGEST_SIZE + \
  10088. (MAX_ECC_BITS+3)/4 + 2)
  10089. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  10090. #ifdef WOLFSSL_SMALL_STACK
  10091. ecc_key *userA = NULL, *userB = NULL;
  10092. byte *msg = NULL;
  10093. byte *out = NULL;
  10094. #else
  10095. ecc_key userA[1], userB[1];
  10096. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  10097. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  10098. #endif
  10099. char name[BENCH_ECC_NAME_SZ];
  10100. int keySize;
  10101. word32 bench_plainSz = bench_size;
  10102. int ret, i, count;
  10103. double start;
  10104. const char**desc = bench_desc_words[lng_index];
  10105. DECLARE_MULTI_VALUE_STATS_VARS()
  10106. #ifdef WOLFSSL_SMALL_STACK
  10107. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  10108. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10109. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  10110. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10111. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  10112. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10113. out = (byte *)XMALLOC(outSz,
  10114. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10115. if ((! userA) || (! userB) || (! msg) || (! out)) {
  10116. printf("bench_eccEncrypt malloc failed\n");
  10117. goto exit;
  10118. }
  10119. #endif
  10120. keySize = wc_ecc_get_curve_size_from_id(curveId);
  10121. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  10122. if (ret != 0) {
  10123. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  10124. goto exit;
  10125. }
  10126. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  10127. if (ret != 0) {
  10128. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  10129. goto exit;
  10130. }
  10131. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10132. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10133. !defined(HAVE_SELFTEST)
  10134. ret = wc_ecc_set_rng(userA, &gRng);
  10135. if (ret != 0) {
  10136. goto exit;
  10137. }
  10138. ret = wc_ecc_set_rng(userB, &gRng);
  10139. if (ret != 0) {
  10140. goto exit;
  10141. }
  10142. #endif
  10143. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  10144. #ifdef WOLFSSL_ASYNC_CRYPT
  10145. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  10146. #endif
  10147. if (ret != 0)
  10148. goto exit;
  10149. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  10150. #ifdef WOLFSSL_ASYNC_CRYPT
  10151. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  10152. #endif
  10153. if (ret != 0)
  10154. goto exit;
  10155. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  10156. msg[i] = (byte)i;
  10157. }
  10158. bench_stats_start(&count, &start);
  10159. do {
  10160. for (i = 0; i < ntimes; i++) {
  10161. /* encrypt msg to B */
  10162. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  10163. out, &outSz, NULL);
  10164. if (ret != 0) {
  10165. printf("wc_ecc_encrypt failed! %d\n", ret);
  10166. goto exit_enc;
  10167. }
  10168. RECORD_MULTI_VALUE_STATS();
  10169. }
  10170. count += i;
  10171. } while (bench_stats_check(start)
  10172. #ifdef MULTI_VALUE_STATISTICS
  10173. || runs < minimum_runs
  10174. #endif
  10175. );
  10176. exit_enc:
  10177. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10178. wc_ecc_get_name(curveId));
  10179. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10180. #ifdef MULTI_VALUE_STATISTICS
  10181. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10182. #endif
  10183. RESET_MULTI_VALUE_STATS_VARS();
  10184. if (ret != 0)
  10185. goto exit;
  10186. bench_stats_start(&count, &start);
  10187. do {
  10188. for (i = 0; i < ntimes; i++) {
  10189. /* decrypt msg from A */
  10190. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10191. &bench_plainSz, NULL);
  10192. if (ret != 0) {
  10193. printf("wc_ecc_decrypt failed! %d\n", ret);
  10194. goto exit_dec;
  10195. }
  10196. RECORD_MULTI_VALUE_STATS();
  10197. }
  10198. count += i;
  10199. } while (bench_stats_check(start)
  10200. #ifdef MULTI_VALUE_STATISTICS
  10201. || runs < minimum_runs
  10202. #endif
  10203. );
  10204. exit_dec:
  10205. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10206. #ifdef MULTI_VALUE_STATISTICS
  10207. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10208. #endif
  10209. exit:
  10210. /* cleanup */
  10211. #ifdef WOLFSSL_SMALL_STACK
  10212. if (userA) {
  10213. wc_ecc_free(userA);
  10214. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10215. }
  10216. if (userB) {
  10217. wc_ecc_free(userB);
  10218. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10219. }
  10220. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10221. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10222. #else
  10223. wc_ecc_free(userB);
  10224. wc_ecc_free(userA);
  10225. #endif
  10226. }
  10227. #endif
  10228. #ifdef WOLFSSL_SM2
  10229. static void bench_sm2_MakeKey(int useDeviceID)
  10230. {
  10231. int ret = 0, i, times, count = 0, pending = 0;
  10232. int deviceID;
  10233. int keySize;
  10234. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10235. sizeof(ecc_key), HEAP_HINT);
  10236. char name[BENCH_ECC_NAME_SZ];
  10237. double start = 0;
  10238. const char**desc = bench_desc_words[lng_index];
  10239. DECLARE_MULTI_VALUE_STATS_VARS()
  10240. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10241. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10242. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10243. sizeof(ecc_key), HEAP_HINT);
  10244. /* ECC Make Key */
  10245. bench_stats_start(&count, &start);
  10246. do {
  10247. /* while free pending slots in queue, submit ops */
  10248. for (times = 0; times < agreeTimes || pending > 0; ) {
  10249. bench_async_poll(&pending);
  10250. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10251. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10252. &times, agreeTimes, &pending)) {
  10253. wc_ecc_free(genKey[i]);
  10254. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10255. if (ret < 0) {
  10256. goto exit;
  10257. }
  10258. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10259. WC_ECC_FLAG_NONE);
  10260. if (!bench_async_handle(&ret,
  10261. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10262. &pending)) {
  10263. goto exit;
  10264. }
  10265. }
  10266. } /* for i */
  10267. RECORD_MULTI_VALUE_STATS();
  10268. } /* for times */
  10269. count += times;
  10270. } while (bench_stats_check(start)
  10271. #ifdef MULTI_VALUE_STATISTICS
  10272. || runs < minimum_runs
  10273. #endif
  10274. );
  10275. exit:
  10276. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10277. wc_ecc_get_name(ECC_SM2P256V1));
  10278. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10279. start, ret);
  10280. #ifdef MULTI_VALUE_STATISTICS
  10281. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10282. #endif
  10283. /* cleanup */
  10284. if (WC_ARRAY_OK(genKey)) {
  10285. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10286. wc_ecc_free(genKey[i]);
  10287. }
  10288. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10289. }
  10290. }
  10291. void bench_sm2(int useDeviceID)
  10292. {
  10293. int ret = 0, i, times, count, pending = 0;
  10294. int deviceID;
  10295. int keySize;
  10296. char name[BENCH_ECC_NAME_SZ];
  10297. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10298. sizeof(ecc_key), HEAP_HINT);
  10299. #ifdef HAVE_ECC_DHE
  10300. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10301. sizeof(ecc_key), HEAP_HINT);
  10302. #endif
  10303. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10304. #ifdef HAVE_ECC_VERIFY
  10305. int verify[BENCH_MAX_PENDING];
  10306. #endif
  10307. #endif
  10308. word32 x[BENCH_MAX_PENDING];
  10309. double start = 0;
  10310. const char**desc = bench_desc_words[lng_index];
  10311. DECLARE_MULTI_VALUE_STATS_VARS()
  10312. #ifdef HAVE_ECC_DHE
  10313. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10314. #endif
  10315. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10316. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10317. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10318. #endif
  10319. #ifdef HAVE_ECC_DHE
  10320. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10321. #endif
  10322. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10323. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10324. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10325. #endif
  10326. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10327. bench_sm2_MakeKey(useDeviceID);
  10328. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10329. sizeof(ecc_key), HEAP_HINT);
  10330. #ifdef HAVE_ECC_DHE
  10331. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10332. sizeof(ecc_key), HEAP_HINT);
  10333. #endif
  10334. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10335. /* init keys */
  10336. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10337. /* setup an context for each key */
  10338. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10339. goto exit;
  10340. }
  10341. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10342. #ifdef WOLFSSL_ASYNC_CRYPT
  10343. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10344. #endif
  10345. if (ret < 0) {
  10346. goto exit;
  10347. }
  10348. #ifdef HAVE_ECC_DHE
  10349. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10350. goto exit;
  10351. }
  10352. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10353. WC_ECC_FLAG_NONE)) > 0) {
  10354. goto exit;
  10355. }
  10356. #endif
  10357. }
  10358. #ifdef HAVE_ECC_DHE
  10359. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10360. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10361. !defined(HAVE_SELFTEST)
  10362. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10363. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10364. }
  10365. #endif
  10366. /* ECC Shared Secret */
  10367. bench_stats_start(&count, &start);
  10368. PRIVATE_KEY_UNLOCK();
  10369. do {
  10370. for (times = 0; times < agreeTimes || pending > 0; ) {
  10371. bench_async_poll(&pending);
  10372. /* while free pending slots in queue, submit ops */
  10373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10374. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10375. &times, agreeTimes, &pending)) {
  10376. x[i] = (word32)keySize;
  10377. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10378. shared[i], &x[i]);
  10379. if (!bench_async_handle(&ret,
  10380. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10381. &pending)) {
  10382. goto exit_ecdhe;
  10383. }
  10384. }
  10385. } /* for i */
  10386. RECORD_MULTI_VALUE_STATS();
  10387. } /* for times */
  10388. count += times;
  10389. } while (bench_stats_check(start)
  10390. #ifdef MULTI_VALUE_STATISTICS
  10391. || runs < minimum_runs
  10392. #endif
  10393. );
  10394. PRIVATE_KEY_UNLOCK();
  10395. exit_ecdhe:
  10396. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10397. wc_ecc_get_name(ECC_SM2P256V1));
  10398. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10399. start, ret);
  10400. #ifdef MULTI_VALUE_STATISTICS
  10401. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10402. #endif
  10403. if (ret < 0) {
  10404. goto exit;
  10405. }
  10406. #endif /* HAVE_ECC_DHE */
  10407. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10408. /* Init digest to sign */
  10409. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10410. for (count = 0; count < keySize; count++) {
  10411. digest[i][count] = (byte)count;
  10412. }
  10413. }
  10414. RESET_MULTI_VALUE_STATS_VARS();
  10415. /* ECC Sign */
  10416. bench_stats_start(&count, &start);
  10417. do {
  10418. for (times = 0; times < agreeTimes || pending > 0; ) {
  10419. bench_async_poll(&pending);
  10420. /* while free pending slots in queue, submit ops */
  10421. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10422. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10423. &times, agreeTimes, &pending)) {
  10424. if (genKey[i]->state == 0)
  10425. x[i] = ECC_MAX_SIG_SIZE;
  10426. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10427. sig[i], &x[i], &gRng, genKey[i]);
  10428. if (!bench_async_handle(&ret,
  10429. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10430. &pending)) {
  10431. goto exit_ecdsa_sign;
  10432. }
  10433. }
  10434. } /* for i */
  10435. RECORD_MULTI_VALUE_STATS();
  10436. } /* for times */
  10437. count += times;
  10438. } while (bench_stats_check(start)
  10439. #ifdef MULTI_VALUE_STATISTICS
  10440. || runs < minimum_runs
  10441. #endif
  10442. );
  10443. exit_ecdsa_sign:
  10444. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10445. wc_ecc_get_name(ECC_SM2P256V1));
  10446. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10447. start, ret);
  10448. #ifdef MULTI_VALUE_STATISTICS
  10449. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10450. #endif
  10451. if (ret < 0) {
  10452. goto exit;
  10453. }
  10454. #ifdef HAVE_ECC_VERIFY
  10455. /* ECC Verify */
  10456. bench_stats_start(&count, &start);
  10457. do {
  10458. for (times = 0; times < agreeTimes || pending > 0; ) {
  10459. bench_async_poll(&pending);
  10460. /* while free pending slots in queue, submit ops */
  10461. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10462. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10463. &times, agreeTimes, &pending)) {
  10464. if (genKey[i]->state == 0)
  10465. verify[i] = 0;
  10466. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10467. (word32)keySize, &verify[i], genKey[i]);
  10468. if (!bench_async_handle(&ret,
  10469. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10470. &pending)) {
  10471. goto exit_ecdsa_verify;
  10472. }
  10473. }
  10474. } /* for i */
  10475. RECORD_MULTI_VALUE_STATS();
  10476. } /* for times */
  10477. count += times;
  10478. } while (bench_stats_check(start)
  10479. #ifdef MULTI_VALUE_STATISTICS
  10480. || runs < minimum_runs
  10481. #endif
  10482. );
  10483. exit_ecdsa_verify:
  10484. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10485. wc_ecc_get_name(ECC_SM2P256V1));
  10486. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10487. start, ret);
  10488. #ifdef MULTI_VALUE_STATISTICS
  10489. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10490. #endif
  10491. #endif /* HAVE_ECC_VERIFY */
  10492. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10493. exit:
  10494. /* cleanup */
  10495. if (WC_ARRAY_OK(genKey)) {
  10496. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10497. wc_ecc_free(genKey[i]);
  10498. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10499. }
  10500. #ifdef HAVE_ECC_DHE
  10501. if (WC_ARRAY_OK(genKey2)) {
  10502. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10503. wc_ecc_free(genKey2[i]);
  10504. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10505. }
  10506. #endif
  10507. #ifdef HAVE_ECC_DHE
  10508. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10509. #endif
  10510. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10511. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10512. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10513. #endif
  10514. (void)useDeviceID;
  10515. (void)pending;
  10516. (void)x;
  10517. (void)count;
  10518. (void)times;
  10519. (void)desc;
  10520. (void)start;
  10521. (void)name;
  10522. }
  10523. #endif /* WOLFSSL_SM2 */
  10524. #endif /* HAVE_ECC */
  10525. #ifdef HAVE_CURVE25519
  10526. void bench_curve25519KeyGen(int useDeviceID)
  10527. {
  10528. curve25519_key genKey;
  10529. double start;
  10530. int ret = 0, i, count;
  10531. const char**desc = bench_desc_words[lng_index];
  10532. DECLARE_MULTI_VALUE_STATS_VARS()
  10533. /* Key Gen */
  10534. bench_stats_start(&count, &start);
  10535. do {
  10536. for (i = 0; i < genTimes; i++) {
  10537. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10538. useDeviceID ? devId : INVALID_DEVID);
  10539. if (ret != 0) {
  10540. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10541. break;
  10542. }
  10543. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10544. wc_curve25519_free(&genKey);
  10545. if (ret != 0) {
  10546. printf("wc_curve25519_make_key failed: %d\n", ret);
  10547. break;
  10548. }
  10549. RECORD_MULTI_VALUE_STATS();
  10550. }
  10551. count += i;
  10552. } while (bench_stats_check(start)
  10553. #ifdef MULTI_VALUE_STATISTICS
  10554. || runs < minimum_runs
  10555. #endif
  10556. );
  10557. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10558. ret);
  10559. #ifdef MULTI_VALUE_STATISTICS
  10560. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10561. #endif
  10562. }
  10563. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10564. void bench_curve25519KeyAgree(int useDeviceID)
  10565. {
  10566. curve25519_key genKey, genKey2;
  10567. double start;
  10568. int ret, i, count;
  10569. byte shared[32];
  10570. const char**desc = bench_desc_words[lng_index];
  10571. word32 x = 0;
  10572. DECLARE_MULTI_VALUE_STATS_VARS()
  10573. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10574. useDeviceID ? devId : INVALID_DEVID);
  10575. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10576. useDeviceID ? devId : INVALID_DEVID);
  10577. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10578. if (ret != 0) {
  10579. printf("curve25519_make_key failed\n");
  10580. return;
  10581. }
  10582. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10583. if (ret != 0) {
  10584. printf("curve25519_make_key failed: %d\n", ret);
  10585. wc_curve25519_free(&genKey);
  10586. return;
  10587. }
  10588. /* Shared secret */
  10589. bench_stats_start(&count, &start);
  10590. do {
  10591. for (i = 0; i < agreeTimes; i++) {
  10592. x = sizeof(shared);
  10593. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10594. if (ret != 0) {
  10595. printf("curve25519_shared_secret failed: %d\n", ret);
  10596. goto exit;
  10597. }
  10598. RECORD_MULTI_VALUE_STATS();
  10599. }
  10600. count += i;
  10601. } while (bench_stats_check(start)
  10602. #ifdef MULTI_VALUE_STATISTICS
  10603. || runs < minimum_runs
  10604. #endif
  10605. );
  10606. exit:
  10607. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10608. ret);
  10609. #ifdef MULTI_VALUE_STATISTICS
  10610. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10611. #endif
  10612. wc_curve25519_free(&genKey2);
  10613. wc_curve25519_free(&genKey);
  10614. }
  10615. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10616. #endif /* HAVE_CURVE25519 */
  10617. #ifdef HAVE_ED25519
  10618. void bench_ed25519KeyGen(void)
  10619. {
  10620. #ifdef HAVE_ED25519_MAKE_KEY
  10621. ed25519_key genKey;
  10622. double start;
  10623. int i, count;
  10624. const char**desc = bench_desc_words[lng_index];
  10625. DECLARE_MULTI_VALUE_STATS_VARS()
  10626. /* Key Gen */
  10627. bench_stats_start(&count, &start);
  10628. do {
  10629. for (i = 0; i < genTimes; i++) {
  10630. wc_ed25519_init(&genKey);
  10631. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10632. wc_ed25519_free(&genKey);
  10633. RECORD_MULTI_VALUE_STATS();
  10634. }
  10635. count += i;
  10636. } while (bench_stats_check(start)
  10637. #ifdef MULTI_VALUE_STATISTICS
  10638. || runs < minimum_runs
  10639. #endif
  10640. );
  10641. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10642. #ifdef MULTI_VALUE_STATISTICS
  10643. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10644. #endif
  10645. #endif /* HAVE_ED25519_MAKE_KEY */
  10646. }
  10647. void bench_ed25519KeySign(void)
  10648. {
  10649. #ifdef HAVE_ED25519_MAKE_KEY
  10650. int ret;
  10651. #endif
  10652. ed25519_key genKey;
  10653. #ifdef HAVE_ED25519_SIGN
  10654. double start;
  10655. int i, count;
  10656. byte sig[ED25519_SIG_SIZE];
  10657. byte msg[512];
  10658. word32 x = 0;
  10659. const char**desc = bench_desc_words[lng_index];
  10660. DECLARE_MULTI_VALUE_STATS_VARS()
  10661. #endif
  10662. wc_ed25519_init(&genKey);
  10663. #ifdef HAVE_ED25519_MAKE_KEY
  10664. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10665. if (ret != 0) {
  10666. printf("ed25519_make_key failed\n");
  10667. return;
  10668. }
  10669. #endif
  10670. #ifdef HAVE_ED25519_SIGN
  10671. /* make dummy msg */
  10672. for (i = 0; i < (int)sizeof(msg); i++)
  10673. msg[i] = (byte)i;
  10674. bench_stats_start(&count, &start);
  10675. do {
  10676. for (i = 0; i < agreeTimes; i++) {
  10677. x = sizeof(sig);
  10678. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10679. if (ret != 0) {
  10680. printf("ed25519_sign_msg failed\n");
  10681. goto exit_ed_sign;
  10682. }
  10683. RECORD_MULTI_VALUE_STATS();
  10684. }
  10685. count += i;
  10686. } while (bench_stats_check(start)
  10687. #ifdef MULTI_VALUE_STATISTICS
  10688. || runs < minimum_runs
  10689. #endif
  10690. );
  10691. exit_ed_sign:
  10692. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10693. #ifdef MULTI_VALUE_STATISTICS
  10694. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10695. #endif
  10696. RESET_MULTI_VALUE_STATS_VARS();
  10697. #ifdef HAVE_ED25519_VERIFY
  10698. bench_stats_start(&count, &start);
  10699. do {
  10700. for (i = 0; i < agreeTimes; i++) {
  10701. int verify = 0;
  10702. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10703. &genKey);
  10704. if (ret != 0 || verify != 1) {
  10705. printf("ed25519_verify_msg failed\n");
  10706. goto exit_ed_verify;
  10707. }
  10708. RECORD_MULTI_VALUE_STATS();
  10709. }
  10710. count += i;
  10711. } while (bench_stats_check(start)
  10712. #ifdef MULTI_VALUE_STATISTICS
  10713. || runs < minimum_runs
  10714. #endif
  10715. );
  10716. exit_ed_verify:
  10717. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10718. #ifdef MULTI_VALUE_STATISTICS
  10719. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10720. #endif
  10721. #endif /* HAVE_ED25519_VERIFY */
  10722. #endif /* HAVE_ED25519_SIGN */
  10723. wc_ed25519_free(&genKey);
  10724. }
  10725. #endif /* HAVE_ED25519 */
  10726. #ifdef HAVE_CURVE448
  10727. void bench_curve448KeyGen(void)
  10728. {
  10729. curve448_key genKey;
  10730. double start;
  10731. int ret = 0, i, count;
  10732. const char**desc = bench_desc_words[lng_index];
  10733. DECLARE_MULTI_VALUE_STATS_VARS()
  10734. /* Key Gen */
  10735. bench_stats_start(&count, &start);
  10736. do {
  10737. for (i = 0; i < genTimes; i++) {
  10738. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10739. wc_curve448_free(&genKey);
  10740. if (ret != 0) {
  10741. printf("wc_curve448_make_key failed: %d\n", ret);
  10742. break;
  10743. }
  10744. RECORD_MULTI_VALUE_STATS();
  10745. }
  10746. count += i;
  10747. } while (bench_stats_check(start)
  10748. #ifdef MULTI_VALUE_STATISTICS
  10749. || runs < minimum_runs
  10750. #endif
  10751. );
  10752. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10753. #ifdef MULTI_VALUE_STATISTICS
  10754. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10755. #endif
  10756. }
  10757. #ifdef HAVE_CURVE448_SHARED_SECRET
  10758. void bench_curve448KeyAgree(void)
  10759. {
  10760. curve448_key genKey, genKey2;
  10761. double start;
  10762. int ret, i, count;
  10763. byte shared[56];
  10764. const char**desc = bench_desc_words[lng_index];
  10765. word32 x = 0;
  10766. DECLARE_MULTI_VALUE_STATS_VARS()
  10767. wc_curve448_init(&genKey);
  10768. wc_curve448_init(&genKey2);
  10769. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10770. if (ret != 0) {
  10771. printf("curve448_make_key failed\n");
  10772. return;
  10773. }
  10774. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10775. if (ret != 0) {
  10776. printf("curve448_make_key failed: %d\n", ret);
  10777. wc_curve448_free(&genKey);
  10778. return;
  10779. }
  10780. /* Shared secret */
  10781. bench_stats_start(&count, &start);
  10782. do {
  10783. for (i = 0; i < agreeTimes; i++) {
  10784. x = sizeof(shared);
  10785. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10786. if (ret != 0) {
  10787. printf("curve448_shared_secret failed: %d\n", ret);
  10788. goto exit;
  10789. }
  10790. RECORD_MULTI_VALUE_STATS();
  10791. }
  10792. count += i;
  10793. } while (bench_stats_check(start)
  10794. #ifdef MULTI_VALUE_STATISTICS
  10795. || runs < minimum_runs
  10796. #endif
  10797. );
  10798. exit:
  10799. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10800. #ifdef MULTI_VALUE_STATISTICS
  10801. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10802. #endif
  10803. wc_curve448_free(&genKey2);
  10804. wc_curve448_free(&genKey);
  10805. }
  10806. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10807. #endif /* HAVE_CURVE448 */
  10808. #ifdef HAVE_ED448
  10809. void bench_ed448KeyGen(void)
  10810. {
  10811. ed448_key genKey;
  10812. double start;
  10813. int i, count;
  10814. const char**desc = bench_desc_words[lng_index];
  10815. DECLARE_MULTI_VALUE_STATS_VARS()
  10816. /* Key Gen */
  10817. bench_stats_start(&count, &start);
  10818. do {
  10819. for (i = 0; i < genTimes; i++) {
  10820. wc_ed448_init(&genKey);
  10821. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10822. wc_ed448_free(&genKey);
  10823. RECORD_MULTI_VALUE_STATS();
  10824. }
  10825. count += i;
  10826. } while (bench_stats_check(start)
  10827. #ifdef MULTI_VALUE_STATISTICS
  10828. || runs < minimum_runs
  10829. #endif
  10830. );
  10831. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10832. #ifdef MULTI_VALUE_STATISTICS
  10833. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10834. #endif
  10835. }
  10836. void bench_ed448KeySign(void)
  10837. {
  10838. int ret;
  10839. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10840. #ifdef HAVE_ED448_SIGN
  10841. double start;
  10842. int i, count;
  10843. byte sig[ED448_SIG_SIZE];
  10844. byte msg[512];
  10845. word32 x = 0;
  10846. const char**desc = bench_desc_words[lng_index];
  10847. DECLARE_MULTI_VALUE_STATS_VARS()
  10848. #endif
  10849. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10850. wc_ed448_init(genKey);
  10851. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10852. if (ret != 0) {
  10853. printf("ed448_make_key failed\n");
  10854. goto exit;
  10855. }
  10856. #ifdef HAVE_ED448_SIGN
  10857. /* make dummy msg */
  10858. for (i = 0; i < (int)sizeof(msg); i++)
  10859. msg[i] = (byte)i;
  10860. bench_stats_start(&count, &start);
  10861. do {
  10862. for (i = 0; i < agreeTimes; i++) {
  10863. x = sizeof(sig);
  10864. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10865. NULL, 0);
  10866. if (ret != 0) {
  10867. printf("ed448_sign_msg failed\n");
  10868. goto exit;
  10869. }
  10870. RECORD_MULTI_VALUE_STATS();
  10871. }
  10872. count += i;
  10873. } while (bench_stats_check(start)
  10874. #ifdef MULTI_VALUE_STATISTICS
  10875. || runs < minimum_runs
  10876. #endif
  10877. );
  10878. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10879. #ifdef MULTI_VALUE_STATISTICS
  10880. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10881. #endif
  10882. RESET_MULTI_VALUE_STATS_VARS();
  10883. #ifdef HAVE_ED448_VERIFY
  10884. bench_stats_start(&count, &start);
  10885. do {
  10886. for (i = 0; i < agreeTimes; i++) {
  10887. int verify = 0;
  10888. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10889. genKey, NULL, 0);
  10890. if (ret != 0 || verify != 1) {
  10891. printf("ed448_verify_msg failed\n");
  10892. goto exit;
  10893. }
  10894. RECORD_MULTI_VALUE_STATS();
  10895. }
  10896. count += i;
  10897. } while (bench_stats_check(start)
  10898. #ifdef MULTI_VALUE_STATISTICS
  10899. || runs < minimum_runs
  10900. #endif
  10901. );
  10902. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10903. #ifdef MULTI_VALUE_STATISTICS
  10904. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10905. #endif
  10906. #endif /* HAVE_ED448_VERIFY */
  10907. #endif /* HAVE_ED448_SIGN */
  10908. exit:
  10909. wc_ed448_free(genKey);
  10910. WC_FREE_VAR(genKey, HEAP_HINT);
  10911. }
  10912. #endif /* HAVE_ED448 */
  10913. #ifdef WOLFCRYPT_HAVE_ECCSI
  10914. #ifdef WOLFCRYPT_ECCSI_KMS
  10915. void bench_eccsiKeyGen(void)
  10916. {
  10917. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10918. double start;
  10919. int i, count;
  10920. const char**desc = bench_desc_words[lng_index];
  10921. int ret;
  10922. DECLARE_MULTI_VALUE_STATS_VARS()
  10923. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10924. /* Key Gen */
  10925. bench_stats_start(&count, &start);
  10926. do {
  10927. for (i = 0; i < genTimes; i++) {
  10928. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10929. ret = wc_MakeEccsiKey(genKey, &gRng);
  10930. wc_FreeEccsiKey(genKey);
  10931. if (ret != 0) {
  10932. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10933. goto exit;
  10934. }
  10935. RECORD_MULTI_VALUE_STATS();
  10936. }
  10937. count += i;
  10938. } while (bench_stats_check(start)
  10939. #ifdef MULTI_VALUE_STATISTICS
  10940. || runs < minimum_runs
  10941. #endif
  10942. );
  10943. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10944. #ifdef MULTI_VALUE_STATISTICS
  10945. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10946. #endif
  10947. exit:
  10948. WC_FREE_VAR(genKey, HEAP_HINT);
  10949. }
  10950. void bench_eccsiPairGen(void)
  10951. {
  10952. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10953. double start;
  10954. int i, count;
  10955. const char**desc = bench_desc_words[lng_index];
  10956. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10957. ecc_point* pvt;
  10958. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10959. int ret;
  10960. DECLARE_MULTI_VALUE_STATS_VARS()
  10961. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10962. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10963. (void)mp_init(ssk);
  10964. pvt = wc_ecc_new_point();
  10965. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10966. (void)wc_MakeEccsiKey(genKey, &gRng);
  10967. /* RSK Gen */
  10968. bench_stats_start(&count, &start);
  10969. do {
  10970. for (i = 0; i < genTimes; i++) {
  10971. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10972. sizeof(id), ssk, pvt);
  10973. if (ret != 0) {
  10974. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10975. goto exit;
  10976. }
  10977. RECORD_MULTI_VALUE_STATS();
  10978. }
  10979. count += i;
  10980. } while (bench_stats_check(start)
  10981. #ifdef MULTI_VALUE_STATISTICS
  10982. || runs < minimum_runs
  10983. #endif
  10984. );
  10985. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10986. #ifdef MULTI_VALUE_STATISTICS
  10987. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10988. #endif
  10989. wc_FreeEccsiKey(genKey);
  10990. wc_ecc_del_point(pvt);
  10991. mp_free(ssk);
  10992. exit:
  10993. WC_FREE_VAR(genKey, HEAP_HINT);
  10994. WC_FREE_VAR(ssk, HEAP_HINT);
  10995. }
  10996. #endif
  10997. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10998. void bench_eccsiValidate(void)
  10999. {
  11000. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11001. double start;
  11002. int i, count;
  11003. const char**desc = bench_desc_words[lng_index];
  11004. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  11005. ecc_point* pvt;
  11006. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11007. int valid;
  11008. int ret;
  11009. DECLARE_MULTI_VALUE_STATS_VARS()
  11010. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11011. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11012. (void)mp_init(ssk);
  11013. pvt = wc_ecc_new_point();
  11014. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11015. (void)wc_MakeEccsiKey(genKey, &gRng);
  11016. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11017. ssk, pvt);
  11018. /* Validation of RSK */
  11019. bench_stats_start(&count, &start);
  11020. do {
  11021. for (i = 0; i < genTimes; i++) {
  11022. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  11023. sizeof(id), ssk, pvt, &valid);
  11024. if (ret != 0 || !valid) {
  11025. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  11026. valid);
  11027. goto exit;
  11028. }
  11029. RECORD_MULTI_VALUE_STATS();
  11030. }
  11031. count += i;
  11032. } while (bench_stats_check(start)
  11033. #ifdef MULTI_VALUE_STATISTICS
  11034. || runs < minimum_runs
  11035. #endif
  11036. );
  11037. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  11038. #ifdef MULTI_VALUE_STATISTICS
  11039. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11040. #endif
  11041. wc_FreeEccsiKey(genKey);
  11042. wc_ecc_del_point(pvt);
  11043. mp_free(ssk);
  11044. exit:
  11045. WC_FREE_VAR(genKey, HEAP_HINT);
  11046. WC_FREE_VAR(ssk, HEAP_HINT);
  11047. }
  11048. void bench_eccsi(void)
  11049. {
  11050. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11051. double start;
  11052. int i, count;
  11053. const char**desc = bench_desc_words[lng_index];
  11054. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  11055. ecc_point* pvt;
  11056. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11057. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  11058. byte hash[WC_SHA256_DIGEST_SIZE];
  11059. byte hashSz = (byte)sizeof(hash);
  11060. byte sig[257];
  11061. word32 sigSz = sizeof(sig);
  11062. int ret;
  11063. int verified;
  11064. DECLARE_MULTI_VALUE_STATS_VARS()
  11065. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11066. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11067. (void)mp_init(ssk);
  11068. pvt = wc_ecc_new_point();
  11069. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11070. (void)wc_MakeEccsiKey(genKey, &gRng);
  11071. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11072. ssk, pvt);
  11073. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  11074. hash, &hashSz);
  11075. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  11076. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  11077. /* Encapsulate */
  11078. bench_stats_start(&count, &start);
  11079. do {
  11080. for (i = 0; i < genTimes; i++) {
  11081. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  11082. sizeof(msg), sig, &sigSz);
  11083. if (ret != 0) {
  11084. printf("wc_SignEccsiHash failed: %d\n", ret);
  11085. break;
  11086. }
  11087. RECORD_MULTI_VALUE_STATS();
  11088. }
  11089. count += i;
  11090. } while (bench_stats_check(start)
  11091. #ifdef MULTI_VALUE_STATISTICS
  11092. || runs < minimum_runs
  11093. #endif
  11094. );
  11095. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  11096. #ifdef MULTI_VALUE_STATISTICS
  11097. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11098. #endif
  11099. RESET_MULTI_VALUE_STATS_VARS();
  11100. /* Derive */
  11101. bench_stats_start(&count, &start);
  11102. do {
  11103. for (i = 0; i < genTimes; i++) {
  11104. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  11105. sizeof(msg), sig, sigSz, &verified);
  11106. if (ret != 0 || !verified) {
  11107. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  11108. verified);
  11109. goto exit;
  11110. }
  11111. RECORD_MULTI_VALUE_STATS();
  11112. }
  11113. count += i;
  11114. } while (bench_stats_check(start)
  11115. #ifdef MULTI_VALUE_STATISTICS
  11116. || runs < minimum_runs
  11117. #endif
  11118. );
  11119. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  11120. #ifdef MULTI_VALUE_STATISTICS
  11121. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11122. #endif
  11123. wc_FreeEccsiKey(genKey);
  11124. wc_ecc_del_point(pvt);
  11125. exit:
  11126. WC_FREE_VAR(genKey, HEAP_HINT);
  11127. WC_FREE_VAR(ssk, HEAP_HINT);
  11128. }
  11129. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  11130. #endif /* WOLFCRYPT_HAVE_ECCSI */
  11131. #ifdef WOLFCRYPT_HAVE_SAKKE
  11132. #ifdef WOLFCRYPT_SAKKE_KMS
  11133. void bench_sakkeKeyGen(void)
  11134. {
  11135. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11136. double start;
  11137. int i, count;
  11138. const char**desc = bench_desc_words[lng_index];
  11139. int ret;
  11140. DECLARE_MULTI_VALUE_STATS_VARS()
  11141. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11142. /* Key Gen */
  11143. bench_stats_start(&count, &start);
  11144. do {
  11145. for (i = 0; i < genTimes; i++) {
  11146. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11147. ret = wc_MakeSakkeKey(genKey, &gRng);
  11148. if (ret != 0) {
  11149. printf("wc_MakeSakkeKey failed: %d\n", ret);
  11150. goto exit;
  11151. }
  11152. wc_FreeSakkeKey(genKey);
  11153. RECORD_MULTI_VALUE_STATS();
  11154. }
  11155. count += i;
  11156. } while (bench_stats_check(start)
  11157. #ifdef MULTI_VALUE_STATISTICS
  11158. || runs < minimum_runs
  11159. #endif
  11160. );
  11161. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  11162. #ifdef MULTI_VALUE_STATISTICS
  11163. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11164. #endif
  11165. exit:
  11166. WC_FREE_VAR(genKey, HEAP_HINT);
  11167. }
  11168. void bench_sakkeRskGen(void)
  11169. {
  11170. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11171. double start;
  11172. int i, count;
  11173. const char**desc = bench_desc_words[lng_index];
  11174. ecc_point* rsk;
  11175. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11176. int ret;
  11177. DECLARE_MULTI_VALUE_STATS_VARS()
  11178. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11179. rsk = wc_ecc_new_point();
  11180. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11181. (void)wc_MakeSakkeKey(genKey, &gRng);
  11182. /* RSK Gen */
  11183. bench_stats_start(&count, &start);
  11184. do {
  11185. for (i = 0; i < genTimes; i++) {
  11186. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11187. if (ret != 0) {
  11188. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11189. goto exit;
  11190. }
  11191. RECORD_MULTI_VALUE_STATS();
  11192. }
  11193. count += i;
  11194. } while (bench_stats_check(start)
  11195. #ifdef MULTI_VALUE_STATISTICS
  11196. || runs < minimum_runs
  11197. #endif
  11198. );
  11199. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11200. #ifdef MULTI_VALUE_STATISTICS
  11201. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11202. #endif
  11203. wc_FreeSakkeKey(genKey);
  11204. wc_ecc_del_point(rsk);
  11205. exit:
  11206. WC_FREE_VAR(genKey, HEAP_HINT);
  11207. }
  11208. #endif
  11209. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11210. void bench_sakkeValidate(void)
  11211. {
  11212. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11213. double start;
  11214. int i, count;
  11215. const char**desc = bench_desc_words[lng_index];
  11216. ecc_point* rsk;
  11217. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11218. int valid;
  11219. int ret;
  11220. DECLARE_MULTI_VALUE_STATS_VARS()
  11221. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11222. rsk = wc_ecc_new_point();
  11223. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11224. (void)wc_MakeSakkeKey(genKey, &gRng);
  11225. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11226. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11227. /* Validation of RSK */
  11228. bench_stats_start(&count, &start);
  11229. do {
  11230. for (i = 0; i < genTimes; i++) {
  11231. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11232. if (ret != 0 || !valid) {
  11233. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11234. valid);
  11235. goto exit;
  11236. }
  11237. RECORD_MULTI_VALUE_STATS();
  11238. }
  11239. count += i;
  11240. } while (bench_stats_check(start)
  11241. #ifdef MULTI_VALUE_STATISTICS
  11242. || runs < minimum_runs
  11243. #endif
  11244. );
  11245. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11246. #ifdef MULTI_VALUE_STATISTICS
  11247. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11248. #endif
  11249. wc_FreeSakkeKey(genKey);
  11250. wc_ecc_del_point(rsk);
  11251. exit:
  11252. WC_FREE_VAR(genKey, HEAP_HINT);
  11253. }
  11254. void bench_sakke(void)
  11255. {
  11256. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11257. double start;
  11258. int i, count;
  11259. const char**desc = bench_desc_words[lng_index];
  11260. ecc_point* rsk;
  11261. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11262. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11263. byte ssv[sizeof(ssv_init)];
  11264. byte derSSV[sizeof(ssv)];
  11265. byte auth[257];
  11266. word16 authSz = sizeof(auth);
  11267. int ret = 0;
  11268. byte* table = NULL;
  11269. word32 len = 0;
  11270. byte* iTable = NULL;
  11271. word32 iTableLen = 0;
  11272. DECLARE_MULTI_VALUE_STATS_VARS()
  11273. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11274. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11275. rsk = wc_ecc_new_point();
  11276. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11277. (void)wc_MakeSakkeKey(genKey, &gRng);
  11278. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11279. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11280. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11281. /* Encapsulate */
  11282. bench_stats_start(&count, &start);
  11283. do {
  11284. for (i = 0; i < genTimes; i++) {
  11285. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11286. WC_HASH_TYPE_SHA256,
  11287. ssv, sizeof(ssv), auth, &authSz);
  11288. if (ret != 0) {
  11289. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11290. break;
  11291. }
  11292. RECORD_MULTI_VALUE_STATS();
  11293. } /* for */
  11294. count += i;
  11295. } while (bench_stats_check(start)
  11296. #ifdef MULTI_VALUE_STATISTICS
  11297. || runs < minimum_runs
  11298. #endif
  11299. );
  11300. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11301. 0, count, start, 0);
  11302. #ifdef MULTI_VALUE_STATISTICS
  11303. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11304. #endif
  11305. RESET_MULTI_VALUE_STATS_VARS();
  11306. /* Derive */
  11307. bench_stats_start(&count, &start);
  11308. do {
  11309. for (i = 0; i < genTimes; i++) {
  11310. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11311. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11312. sizeof(derSSV), auth, authSz);
  11313. if (ret != 0) {
  11314. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11315. break;
  11316. }
  11317. RECORD_MULTI_VALUE_STATS();
  11318. }
  11319. if (ret != 0) break;
  11320. count += i;
  11321. } while (bench_stats_check(start)
  11322. #ifdef MULTI_VALUE_STATISTICS
  11323. || runs < minimum_runs
  11324. #endif
  11325. );
  11326. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11327. 0, count, start, 0);
  11328. #ifdef MULTI_VALUE_STATISTICS
  11329. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11330. #endif
  11331. /* Calculate Point I and generate table. */
  11332. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11333. iTableLen = 0;
  11334. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11335. if (iTableLen != 0) {
  11336. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11337. if (iTable == NULL)
  11338. WC_ALLOC_DO_ON_FAILURE();
  11339. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11340. }
  11341. /* Encapsulate with Point I table */
  11342. bench_stats_start(&count, &start);
  11343. do {
  11344. for (i = 0; i < genTimes; i++) {
  11345. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11346. WC_HASH_TYPE_SHA256, ssv,
  11347. sizeof(ssv), auth, &authSz);
  11348. if (ret != 0) {
  11349. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11350. break;
  11351. }
  11352. RECORD_MULTI_VALUE_STATS();
  11353. }
  11354. count += i;
  11355. } while (bench_stats_check(start)
  11356. #ifdef MULTI_VALUE_STATISTICS
  11357. || runs < minimum_runs
  11358. #endif
  11359. );
  11360. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11361. count, start, 0);
  11362. #ifdef MULTI_VALUE_STATISTICS
  11363. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11364. #endif
  11365. RESET_MULTI_VALUE_STATS_VARS();
  11366. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11367. /* Derive with Point I table */
  11368. bench_stats_start(&count, &start);
  11369. do {
  11370. for (i = 0; i < genTimes; i++) {
  11371. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11372. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11373. sizeof(derSSV), auth, authSz);
  11374. if (ret != 0) {
  11375. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11376. break;
  11377. }
  11378. RECORD_MULTI_VALUE_STATS();
  11379. }
  11380. if (ret != 0) break;
  11381. count += i;
  11382. } while (bench_stats_check(start)
  11383. #ifdef MULTI_VALUE_STATISTICS
  11384. || runs < minimum_runs
  11385. #endif
  11386. );
  11387. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11388. count, start, 0);
  11389. #ifdef MULTI_VALUE_STATISTICS
  11390. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11391. #endif
  11392. RESET_MULTI_VALUE_STATS_VARS();
  11393. len = 0;
  11394. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11395. if (len > 0) {
  11396. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11397. if (table == NULL)
  11398. WC_ALLOC_DO_ON_FAILURE();
  11399. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11400. }
  11401. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11402. /* Derive with Point I table and RSK table */
  11403. bench_stats_start(&count, &start);
  11404. do {
  11405. for (i = 0; i < genTimes; i++) {
  11406. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11407. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11408. sizeof(derSSV), auth, authSz);
  11409. if (ret != 0) {
  11410. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11411. break;
  11412. }
  11413. RECORD_MULTI_VALUE_STATS();
  11414. }
  11415. if (ret != 0) break;
  11416. count += i;
  11417. } while (bench_stats_check(start)
  11418. #ifdef MULTI_VALUE_STATISTICS
  11419. || runs < minimum_runs
  11420. #endif
  11421. );
  11422. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11423. 0, count, start, 0);
  11424. #ifdef MULTI_VALUE_STATISTICS
  11425. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11426. #endif
  11427. RESET_MULTI_VALUE_STATS_VARS();
  11428. wc_ClearSakkePointITable(genKey);
  11429. /* Derive with RSK table */
  11430. bench_stats_start(&count, &start);
  11431. do {
  11432. for (i = 0; i < genTimes; i++) {
  11433. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11434. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11435. sizeof(derSSV), auth, authSz);
  11436. if (ret != 0) {
  11437. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11438. break;
  11439. }
  11440. RECORD_MULTI_VALUE_STATS();
  11441. }
  11442. if (ret != 0) break;
  11443. count += i;
  11444. } while (bench_stats_check(start)
  11445. #ifdef MULTI_VALUE_STATISTICS
  11446. || runs < minimum_runs
  11447. #endif
  11448. );
  11449. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11450. count, start, 0);
  11451. #ifdef MULTI_VALUE_STATISTICS
  11452. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11453. #endif
  11454. wc_FreeSakkeKey(genKey);
  11455. wc_ecc_del_point(rsk);
  11456. exit:
  11457. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11458. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11459. WC_FREE_VAR(genKey, HEAP_HINT);
  11460. }
  11461. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11462. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11463. #ifdef HAVE_FALCON
  11464. void bench_falconKeySign(byte level)
  11465. {
  11466. int ret = 0;
  11467. falcon_key key;
  11468. double start;
  11469. int i, count;
  11470. byte sig[FALCON_MAX_SIG_SIZE];
  11471. byte msg[512];
  11472. word32 x = 0;
  11473. const char**desc = bench_desc_words[lng_index];
  11474. DECLARE_MULTI_VALUE_STATS_VARS()
  11475. ret = wc_falcon_init(&key);
  11476. if (ret != 0) {
  11477. printf("wc_falcon_init failed %d\n", ret);
  11478. return;
  11479. }
  11480. ret = wc_falcon_set_level(&key, level);
  11481. if (ret != 0) {
  11482. printf("wc_falcon_set_level failed %d\n", ret);
  11483. }
  11484. if (ret == 0) {
  11485. if (level == 1) {
  11486. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11487. sizeof_bench_falcon_level1_key,
  11488. NULL, 0, &key);
  11489. }
  11490. else {
  11491. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11492. sizeof_bench_falcon_level5_key,
  11493. NULL, 0, &key);
  11494. }
  11495. if (ret != 0) {
  11496. printf("wc_falcon_import_private_key failed %d\n", ret);
  11497. }
  11498. }
  11499. /* make dummy msg */
  11500. for (i = 0; i < (int)sizeof(msg); i++) {
  11501. msg[i] = (byte)i;
  11502. }
  11503. bench_stats_start(&count, &start);
  11504. do {
  11505. for (i = 0; i < agreeTimes; i++) {
  11506. if (ret == 0) {
  11507. if (level == 1) {
  11508. x = FALCON_LEVEL1_SIG_SIZE;
  11509. }
  11510. else {
  11511. x = FALCON_LEVEL5_SIG_SIZE;
  11512. }
  11513. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11514. if (ret != 0) {
  11515. printf("wc_falcon_sign_msg failed\n");
  11516. }
  11517. }
  11518. RECORD_MULTI_VALUE_STATS();
  11519. }
  11520. count += i;
  11521. } while (bench_stats_check(start)
  11522. #ifdef MULTI_VALUE_STATISTICS
  11523. || runs < minimum_runs
  11524. #endif
  11525. );
  11526. if (ret == 0) {
  11527. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11528. count, start, ret);
  11529. #ifdef MULTI_VALUE_STATISTICS
  11530. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11531. #endif
  11532. }
  11533. RESET_MULTI_VALUE_STATS_VARS();
  11534. bench_stats_start(&count, &start);
  11535. do {
  11536. for (i = 0; i < agreeTimes; i++) {
  11537. if (ret == 0) {
  11538. int verify = 0;
  11539. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11540. &key);
  11541. if (ret != 0 || verify != 1) {
  11542. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11543. ret, verify);
  11544. ret = -1;
  11545. }
  11546. }
  11547. RECORD_MULTI_VALUE_STATS();
  11548. }
  11549. count += i;
  11550. } while (bench_stats_check(start)
  11551. #ifdef MULTI_VALUE_STATISTICS
  11552. || runs < minimum_runs
  11553. #endif
  11554. );
  11555. if (ret == 0) {
  11556. bench_stats_asym_finish("FALCON", level, desc[5],
  11557. 0, count, start, ret);
  11558. #ifdef MULTI_VALUE_STATISTICS
  11559. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11560. #endif
  11561. }
  11562. wc_falcon_free(&key);
  11563. }
  11564. #endif /* HAVE_FALCON */
  11565. #ifdef HAVE_DILITHIUM
  11566. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11567. #ifndef WOLFSSL_NO_ML_DSA_44
  11568. static const unsigned char bench_dilithium_level2_sig[] = {
  11569. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11570. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11571. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11572. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11573. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11574. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11575. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11576. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11577. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11578. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11579. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11580. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11581. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11582. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11583. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11584. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11585. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11586. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11587. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11588. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11589. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11590. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11591. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11592. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11593. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11594. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11595. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11596. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11597. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11598. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11599. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11600. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11601. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11602. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11603. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11604. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11605. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11606. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11607. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11608. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11609. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11610. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11611. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11612. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11613. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11614. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11615. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11616. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11617. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11618. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11619. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11620. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11621. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11622. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11623. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11624. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11625. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11626. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11627. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11628. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11629. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11630. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11631. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11632. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11633. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11634. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11635. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11636. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11637. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11638. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11639. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11640. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11641. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11642. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11643. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11644. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11645. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11646. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11647. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11648. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11649. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11650. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11651. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11652. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11653. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11654. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11655. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11656. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11657. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11658. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11659. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11660. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11661. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11662. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11663. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11664. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11665. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11666. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11667. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11668. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11669. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11670. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11671. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11672. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11673. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11674. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11675. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11676. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11677. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11678. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11679. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11680. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11681. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11682. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11683. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11684. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11685. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11686. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11687. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11688. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11689. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11690. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11691. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11692. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11693. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11694. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11695. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11696. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11697. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11698. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11699. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11700. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11701. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11702. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11703. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11704. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11705. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11706. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11707. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11708. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11709. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11710. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11711. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11712. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11713. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11714. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11715. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11716. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11717. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11718. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11719. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11720. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11721. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11722. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11723. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11724. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11725. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11726. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11727. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11728. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11729. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11730. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11731. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11732. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11733. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11734. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11735. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11736. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11737. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11738. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11739. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11740. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11741. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11742. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11743. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11744. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11745. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11746. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11747. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11748. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11749. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11750. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11751. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11752. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11753. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11754. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11755. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11756. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11757. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11758. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11759. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11760. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11761. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11762. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11763. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11764. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11765. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11766. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11767. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11768. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11769. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11770. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11771. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11772. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11773. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11774. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11775. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11776. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11777. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11778. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11779. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11780. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11781. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11782. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11783. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11784. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11785. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11786. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11787. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11788. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11789. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11790. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11791. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11792. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11793. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11794. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11795. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11796. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11797. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11798. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11799. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11800. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11801. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11802. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11803. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11804. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11805. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11806. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11807. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11808. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11809. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11810. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11811. };
  11812. static const int sizeof_bench_dilithium_level2_sig =
  11813. sizeof(bench_dilithium_level2_sig);
  11814. #endif
  11815. #ifndef WOLFSSL_NO_ML_DSA_65
  11816. static const unsigned char bench_dilithium_level3_sig[] = {
  11817. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11818. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11819. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11820. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11821. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11822. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11823. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11824. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11825. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11826. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11827. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11828. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11829. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11830. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11831. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11832. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11833. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11834. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11835. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11836. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11837. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11838. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11839. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11840. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11841. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11842. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11843. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11844. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11845. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11846. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11847. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11848. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11849. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11850. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11851. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11852. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11853. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11854. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11855. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11856. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11857. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11858. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11859. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11860. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11861. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11862. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11863. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11864. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11865. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11866. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11867. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11868. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11869. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11870. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11871. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11872. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11873. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11874. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11875. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11876. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11877. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11878. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11879. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11880. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11881. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11882. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11883. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11884. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11885. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11886. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11887. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11888. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11889. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11890. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11891. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11892. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11893. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11894. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11895. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11896. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11897. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11898. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11899. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11900. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11901. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11902. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11903. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11904. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11905. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11906. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11907. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11908. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11909. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11910. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11911. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11912. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11913. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11914. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11915. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11916. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11917. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11918. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11919. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11920. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11921. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11922. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11923. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11924. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11925. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11926. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11927. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11928. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11929. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11930. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11931. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11932. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11933. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11934. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11935. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11936. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11937. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11938. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11939. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11940. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11941. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11942. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11943. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11944. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11945. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11946. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11947. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11948. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11949. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11950. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11951. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11952. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11953. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11954. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11955. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11956. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11957. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11958. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11959. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11960. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11961. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11962. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11963. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11964. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11965. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11966. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11967. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11968. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11969. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11970. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11971. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11972. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11973. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11974. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11975. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11976. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11977. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11978. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11979. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11980. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11981. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11982. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11983. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11984. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11985. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11986. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11987. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11988. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11989. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11990. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11991. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11992. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11993. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11994. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11995. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11996. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11997. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11998. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11999. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  12000. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  12001. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  12002. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  12003. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  12004. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  12005. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  12006. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  12007. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  12008. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  12009. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  12010. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  12011. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  12012. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  12013. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  12014. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  12015. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  12016. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  12017. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  12018. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  12019. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  12020. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  12021. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  12022. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  12023. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  12024. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  12025. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  12026. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  12027. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  12028. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  12029. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  12030. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  12031. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  12032. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  12033. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  12034. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  12035. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  12036. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  12037. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  12038. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  12039. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  12040. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  12041. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  12042. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  12043. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  12044. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  12045. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  12046. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  12047. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  12048. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  12049. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  12050. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  12051. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  12052. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  12053. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  12054. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  12055. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  12056. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  12057. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  12058. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  12059. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  12060. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  12061. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  12062. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  12063. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  12064. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  12065. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  12066. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  12067. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  12068. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  12069. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  12070. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  12071. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  12072. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  12073. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  12074. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  12075. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  12076. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  12077. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  12078. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  12079. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  12080. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  12081. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  12082. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  12083. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  12084. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  12085. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  12086. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  12087. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  12088. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  12089. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  12090. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  12091. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  12092. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  12093. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  12094. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  12095. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  12096. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  12097. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  12098. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  12099. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  12100. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  12101. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  12102. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  12103. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  12104. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  12105. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  12106. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  12107. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  12108. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  12109. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  12110. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  12111. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  12112. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  12113. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  12114. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  12115. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  12116. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  12117. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  12118. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  12119. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  12120. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  12121. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  12122. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  12123. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  12124. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  12125. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  12126. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  12127. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  12128. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  12129. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  12130. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  12131. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  12132. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  12133. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  12134. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  12135. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  12136. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  12137. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  12138. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  12139. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  12140. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  12141. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  12142. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  12143. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  12144. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  12145. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  12146. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12147. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  12148. };
  12149. static const int sizeof_bench_dilithium_level3_sig =
  12150. sizeof(bench_dilithium_level3_sig);
  12151. #endif
  12152. #ifndef WOLFSSL_NO_ML_DSA_87
  12153. static const unsigned char bench_dilithium_level5_sig[] = {
  12154. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  12155. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  12156. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  12157. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  12158. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  12159. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  12160. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  12161. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  12162. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  12163. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  12164. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  12165. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  12166. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  12167. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  12168. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  12169. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  12170. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  12171. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  12172. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  12173. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  12174. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12175. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12176. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12177. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12178. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12179. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12180. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12181. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12182. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12183. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12184. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12185. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12186. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12187. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12188. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12189. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12190. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12191. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12192. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12193. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12194. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12195. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12196. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12197. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12198. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12199. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12200. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12201. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12202. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12203. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12204. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12205. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12206. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12207. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12208. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12209. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12210. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12211. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12212. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12213. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12214. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12215. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12216. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12217. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12218. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12219. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12220. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12221. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12222. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12223. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12224. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12225. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12226. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12227. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12228. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12229. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12230. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12231. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12232. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12233. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12234. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12235. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12236. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12237. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12238. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12239. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12240. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12241. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12242. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12243. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12244. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12245. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12246. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12247. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12248. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12249. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12250. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12251. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12252. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12253. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12254. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12255. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12256. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12257. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12258. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12259. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12260. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12261. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12262. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12263. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12264. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12265. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12266. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12267. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12268. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12269. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12270. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12271. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12272. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12273. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12274. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12275. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12276. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12277. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12278. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12279. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12280. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12281. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12282. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12283. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12284. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12285. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12286. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12287. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12288. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12289. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12290. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12291. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12292. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12293. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12294. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12295. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12296. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12297. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12298. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12299. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12300. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12301. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12302. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12303. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12304. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12305. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12306. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12307. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12308. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12309. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12310. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12311. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12312. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12313. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12314. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12315. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12316. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12317. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12318. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12319. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12320. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12321. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12322. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12323. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12324. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12325. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12326. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12327. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12328. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12329. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12330. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12331. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12332. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12333. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12334. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12335. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12336. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12337. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12338. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12339. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12340. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12341. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12342. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12343. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12344. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12345. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12346. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12347. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12348. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12349. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12350. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12351. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12352. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12353. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12354. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12355. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12356. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12357. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12358. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12359. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12360. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12361. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12362. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12363. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12364. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12365. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12366. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12367. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12368. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12369. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12370. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12371. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12372. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12373. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12374. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12375. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12376. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12377. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12378. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12379. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12380. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12381. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12382. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12383. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12384. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12385. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12386. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12387. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12388. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12389. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12390. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12391. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12392. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12393. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12394. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12395. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12396. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12397. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12398. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12399. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12400. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12401. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12402. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12403. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12404. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12405. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12406. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12407. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12408. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12409. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12410. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12411. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12412. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12413. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12414. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12415. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12416. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12417. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12418. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12419. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12420. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12421. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12422. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12423. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12424. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12425. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12426. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12427. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12428. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12429. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12430. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12431. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12432. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12433. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12434. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12435. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12436. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12437. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12438. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12439. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12440. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12441. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12442. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12443. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12444. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12445. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12446. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12447. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12448. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12449. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12450. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12451. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12452. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12453. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12454. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12455. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12456. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12457. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12458. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12459. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12460. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12461. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12462. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12463. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12464. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12465. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12466. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12467. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12468. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12469. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12470. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12471. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12472. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12473. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12474. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12475. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12476. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12477. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12478. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12479. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12480. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12481. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12482. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12483. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12484. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12485. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12486. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12487. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12488. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12489. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12490. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12491. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12492. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12493. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12494. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12495. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12496. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12497. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12498. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12499. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12500. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12501. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12502. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12503. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12504. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12505. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12506. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12507. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12508. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12509. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12510. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12511. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12512. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12513. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12514. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12515. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12516. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12517. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12518. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12519. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12520. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12521. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12522. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12523. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12524. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12525. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12526. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12527. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12528. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12529. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12530. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12531. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12532. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12533. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12534. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12535. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12536. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12537. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12538. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12539. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12540. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12541. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12542. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12543. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12544. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12545. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12546. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12547. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12548. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12549. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12550. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12551. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12552. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12553. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12554. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12555. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12556. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12557. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12558. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12559. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12560. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12561. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12562. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12563. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12564. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12565. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12566. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12567. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12568. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12569. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12570. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12571. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12572. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12573. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12574. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12575. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12576. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12577. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12578. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12579. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12580. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12581. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12582. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12583. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12584. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12585. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12586. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12587. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12588. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12589. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12590. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12591. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12592. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12593. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12594. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12595. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12596. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12597. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12598. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12599. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12600. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12601. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12602. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12603. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12604. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12605. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12606. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12607. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12608. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12609. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12610. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12611. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12612. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12613. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12614. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12615. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12616. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12617. };
  12618. static const int sizeof_bench_dilithium_level5_sig =
  12619. sizeof(bench_dilithium_level5_sig);
  12620. #endif
  12621. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12622. void bench_dilithiumKeySign(byte level)
  12623. {
  12624. int ret = 0;
  12625. dilithium_key key;
  12626. double start;
  12627. int i, count;
  12628. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12629. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12630. byte msg[512];
  12631. word32 x = 0;
  12632. #endif
  12633. const char**desc = bench_desc_words[lng_index];
  12634. DECLARE_MULTI_VALUE_STATS_VARS()
  12635. byte params = 0;
  12636. if (level == 2) {
  12637. params = 44;
  12638. }
  12639. else if (level == 3) {
  12640. params = 65;
  12641. }
  12642. else if (level == 5) {
  12643. params = 87;
  12644. }
  12645. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12646. /* make dummy msg */
  12647. for (i = 0; i < (int)sizeof(msg); i++) {
  12648. msg[i] = (byte)i;
  12649. }
  12650. #endif
  12651. ret = wc_dilithium_init(&key);
  12652. if (ret != 0) {
  12653. printf("wc_dilithium_init failed %d\n", ret);
  12654. return;
  12655. }
  12656. ret = wc_dilithium_set_level(&key, level);
  12657. if (ret != 0) {
  12658. printf("wc_dilithium_set_level() failed %d\n", ret);
  12659. }
  12660. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12661. bench_stats_start(&count, &start);
  12662. do {
  12663. for (i = 0; i < agreeTimes; i++) {
  12664. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12665. if (ret != 0) {
  12666. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12667. return;
  12668. }
  12669. }
  12670. count += i;
  12671. } while (bench_stats_check(start)
  12672. #ifdef MULTI_VALUE_STATISTICS
  12673. || runs < minimum_runs
  12674. #endif
  12675. );
  12676. if (ret == 0) {
  12677. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12678. start, ret);
  12679. #ifdef MULTI_VALUE_STATISTICS
  12680. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12681. #endif
  12682. }
  12683. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12684. #ifndef WOLFSSL_NO_ML_DSA_44
  12685. if (level == 2) {
  12686. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12687. sizeof_bench_dilithium_level2_key, &key);
  12688. }
  12689. #endif
  12690. #ifndef WOLFSSL_NO_ML_DSA_65
  12691. if (level == 3) {
  12692. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12693. sizeof_bench_dilithium_level3_key, &key);
  12694. }
  12695. #endif
  12696. #ifndef WOLFSSL_NO_ML_DSA_87
  12697. if (level == 5) {
  12698. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12699. sizeof_bench_dilithium_level5_key, &key);
  12700. }
  12701. #endif
  12702. if (ret != 0) {
  12703. printf("Failed to load private key\n");
  12704. return;
  12705. }
  12706. #endif
  12707. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12708. if (level == 2) {
  12709. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12710. }
  12711. else if (level == 3) {
  12712. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12713. }
  12714. else {
  12715. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12716. }
  12717. RESET_MULTI_VALUE_STATS_VARS();
  12718. bench_stats_start(&count, &start);
  12719. do {
  12720. for (i = 0; i < agreeTimes; i++) {
  12721. if (ret == 0) {
  12722. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12723. GLOBAL_RNG);
  12724. if (ret != 0) {
  12725. printf("wc_dilithium_sign_msg failed\n");
  12726. }
  12727. }
  12728. RECORD_MULTI_VALUE_STATS();
  12729. }
  12730. count += i;
  12731. } while (bench_stats_check(start)
  12732. #ifdef MULTI_VALUE_STATISTICS
  12733. || runs < minimum_runs
  12734. #endif
  12735. );
  12736. if (ret == 0) {
  12737. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12738. ret);
  12739. #ifdef MULTI_VALUE_STATISTICS
  12740. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12741. #endif
  12742. }
  12743. #endif
  12744. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12745. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12746. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12747. #ifndef WOLFSSL_NO_ML_DSA_44
  12748. if (level == 2) {
  12749. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12750. x = sizeof_bench_dilithium_level2_sig;
  12751. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12752. #endif
  12753. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12754. sizeof_bench_dilithium_level2_pubkey, &key);
  12755. }
  12756. #endif
  12757. #ifndef WOLFSSL_NO_ML_DSA_65
  12758. if (level == 3) {
  12759. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12760. x = sizeof_bench_dilithium_level3_sig;
  12761. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12762. #endif
  12763. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12764. sizeof_bench_dilithium_level3_pubkey, &key);
  12765. }
  12766. #endif
  12767. #ifndef WOLFSSL_NO_ML_DSA_87
  12768. if (level == 5) {
  12769. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12770. x = sizeof_bench_dilithium_level5_sig;
  12771. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12772. #endif
  12773. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12774. sizeof_bench_dilithium_level5_pubkey, &key);
  12775. }
  12776. #endif
  12777. if (ret != 0) {
  12778. printf("Failed to load public key\n");
  12779. return;
  12780. }
  12781. #endif
  12782. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12783. RESET_MULTI_VALUE_STATS_VARS();
  12784. bench_stats_start(&count, &start);
  12785. do {
  12786. for (i = 0; i < agreeTimes; i++) {
  12787. if (ret == 0) {
  12788. int verify = 0;
  12789. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12790. &verify, &key);
  12791. if (ret != 0 || verify != 1) {
  12792. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12793. ret, verify);
  12794. ret = -1;
  12795. }
  12796. }
  12797. RECORD_MULTI_VALUE_STATS();
  12798. }
  12799. count += i;
  12800. } while (bench_stats_check(start)
  12801. #ifdef MULTI_VALUE_STATISTICS
  12802. || runs < minimum_runs
  12803. #endif
  12804. );
  12805. if (ret == 0) {
  12806. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12807. ret);
  12808. #ifdef MULTI_VALUE_STATISTICS
  12809. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12810. #endif
  12811. }
  12812. #endif
  12813. wc_dilithium_free(&key);
  12814. }
  12815. #endif /* HAVE_DILITHIUM */
  12816. #ifdef HAVE_SPHINCS
  12817. void bench_sphincsKeySign(byte level, byte optim)
  12818. {
  12819. int ret = 0;
  12820. sphincs_key key;
  12821. double start;
  12822. int i, count;
  12823. byte sig[SPHINCS_MAX_SIG_SIZE];
  12824. byte msg[512];
  12825. word32 x = 0;
  12826. const char**desc = bench_desc_words[lng_index];
  12827. DECLARE_MULTI_VALUE_STATS_VARS()
  12828. ret = wc_sphincs_init(&key);
  12829. if (ret != 0) {
  12830. printf("wc_sphincs_init failed %d\n", ret);
  12831. return;
  12832. }
  12833. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12834. if (ret != 0) {
  12835. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12836. }
  12837. if (ret == 0) {
  12838. ret = -1;
  12839. if ((level == 1) && (optim == FAST_VARIANT)) {
  12840. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12841. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12842. }
  12843. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12844. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12845. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12846. }
  12847. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12848. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12849. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12850. }
  12851. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12852. ret = wc_sphincs_import_private_key(
  12853. bench_sphincs_small_level1_key,
  12854. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12855. }
  12856. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12857. ret = wc_sphincs_import_private_key(
  12858. bench_sphincs_small_level3_key,
  12859. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12860. }
  12861. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12862. ret = wc_sphincs_import_private_key(
  12863. bench_sphincs_small_level5_key,
  12864. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12865. }
  12866. if (ret != 0) {
  12867. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12868. }
  12869. }
  12870. /* make dummy msg */
  12871. for (i = 0; i < (int)sizeof(msg); i++) {
  12872. msg[i] = (byte)i;
  12873. }
  12874. bench_stats_start(&count, &start);
  12875. do {
  12876. for (i = 0; i < agreeTimes; i++) {
  12877. if (ret == 0) {
  12878. if ((level == 1) && (optim == FAST_VARIANT)) {
  12879. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12880. }
  12881. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12882. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12883. }
  12884. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12885. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12886. }
  12887. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12888. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12889. }
  12890. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12891. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12892. }
  12893. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12894. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12895. }
  12896. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12897. if (ret != 0) {
  12898. printf("wc_sphincs_sign_msg failed\n");
  12899. }
  12900. }
  12901. RECORD_MULTI_VALUE_STATS();
  12902. }
  12903. count += i;
  12904. } while (bench_stats_check(start)
  12905. #ifdef MULTI_VALUE_STATISTICS
  12906. || runs < minimum_runs
  12907. #endif
  12908. );
  12909. if (ret == 0) {
  12910. if (optim == FAST_VARIANT) {
  12911. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12912. start, ret);
  12913. }
  12914. else {
  12915. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12916. start, ret);
  12917. }
  12918. #ifdef MULTI_VALUE_STATISTICS
  12919. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12920. #endif
  12921. }
  12922. RESET_MULTI_VALUE_STATS_VARS();
  12923. bench_stats_start(&count, &start);
  12924. do {
  12925. for (i = 0; i < agreeTimes; i++) {
  12926. if (ret == 0) {
  12927. int verify = 0;
  12928. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12929. &key);
  12930. if (ret != 0 || verify != 1) {
  12931. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12932. ret, verify);
  12933. ret = -1;
  12934. }
  12935. }
  12936. RECORD_MULTI_VALUE_STATS();
  12937. }
  12938. count += i;
  12939. } while (bench_stats_check(start)
  12940. #ifdef MULTI_VALUE_STATISTICS
  12941. || runs < minimum_runs
  12942. #endif
  12943. );
  12944. if (ret == 0) {
  12945. if (optim == FAST_VARIANT) {
  12946. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12947. start, ret);
  12948. }
  12949. else {
  12950. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12951. start, ret);
  12952. }
  12953. #ifdef MULTI_VALUE_STATISTICS
  12954. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12955. #endif
  12956. }
  12957. wc_sphincs_free(&key);
  12958. }
  12959. #endif /* HAVE_SPHINCS */
  12960. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12961. #define WIN32_LEAN_AND_MEAN
  12962. #include <windows.h>
  12963. double current_time(int reset)
  12964. {
  12965. static int init = 0;
  12966. static LARGE_INTEGER freq;
  12967. LARGE_INTEGER count;
  12968. (void)reset;
  12969. if (!init) {
  12970. QueryPerformanceFrequency(&freq);
  12971. init = 1;
  12972. }
  12973. QueryPerformanceCounter(&count);
  12974. #ifdef BENCH_MICROSECOND
  12975. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12976. #else
  12977. return (double)count.QuadPart / freq.QuadPart;
  12978. #endif
  12979. }
  12980. #elif defined MICROCHIP_PIC32
  12981. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12982. #define CLOCK 80000000.0
  12983. #else
  12984. #define CLOCK 40000000.0
  12985. #endif
  12986. extern void WriteCoreTimer(word32 t);
  12987. extern word32 ReadCoreTimer(void);
  12988. double current_time(int reset)
  12989. {
  12990. unsigned int ns;
  12991. if (reset) {
  12992. WriteCoreTimer(0);
  12993. }
  12994. /* get timer in ns */
  12995. ns = ReadCoreTimer();
  12996. /* return seconds as a double */
  12997. return ( ns / CLOCK * 2.0);
  12998. }
  12999. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  13000. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  13001. /* declared above at line 239 */
  13002. /* extern double current_time(int reset); */
  13003. #elif defined(FREERTOS)
  13004. #ifdef PLATFORMIO
  13005. #include <freertos/FreeRTOS.h>
  13006. #include <freertos/task.h>
  13007. #else
  13008. #include "task.h"
  13009. #endif
  13010. #if defined(WOLFSSL_ESPIDF)
  13011. /* prototype definition */
  13012. int construct_argv();
  13013. extern char* __argv[22];
  13014. /* current_time(reset)
  13015. *
  13016. * Benchmark passage of time, in fractional seconds.
  13017. * [reset] is non zero to adjust timer or counter to zero
  13018. *
  13019. * Use care when repeatedly calling calling. See implementation. */
  13020. double current_time(int reset)
  13021. {
  13022. double ret;
  13023. #if ESP_IDF_VERSION_MAJOR >= 4
  13024. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  13025. #else
  13026. portTickType tickCount;
  13027. #endif
  13028. #if defined(__XTENSA__)
  13029. (void)reset;
  13030. if (reset) {
  13031. /* TODO: Determine a mechanism for reset that does not interfere
  13032. * with freeRTOS tick. Using this code for Xtensa appears to cause
  13033. * RTOS tick timer to stick. See "last_tickCount unchanged".
  13034. ESP_LOGW(TAG, "Current_time() reset!");
  13035. portTICK_TYPE_ENTER_CRITICAL();
  13036. {
  13037. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  13038. _esp_cpu_count_last = xthal_get_ccount();
  13039. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  13040. }
  13041. portTICK_TYPE_EXIT_CRITICAL();
  13042. */
  13043. }
  13044. #else
  13045. /* Only reset the CPU counter for RISC-V */
  13046. if (reset) {
  13047. ESP_LOGV(TAG, "current_time() reset!");
  13048. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  13049. * unexpected rollovers in return values for Xtensa but not RISC-V?
  13050. * See also esp_get_cycle_count_ex() */
  13051. #ifdef __XTENSA__
  13052. _esp_cpu_count_last = xthal_get_ccount();
  13053. #else
  13054. #if ESP_IDF_VERSION_MAJOR >= 5
  13055. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  13056. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  13057. #else
  13058. cpu_hal_set_cycle_count((uint32_t)0);
  13059. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  13060. #endif
  13061. #endif
  13062. }
  13063. #endif
  13064. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  13065. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  13066. The count of ticks since vTaskStartScheduler was called,
  13067. typiclly in app_startup.c */
  13068. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13069. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  13070. if (tickCount == last_tickCount) {
  13071. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  13072. }
  13073. if (tickCount < last_tickCount) {
  13074. ESP_LOGW(TAG, "last_tickCount overflow?");
  13075. }
  13076. #endif
  13077. if (reset) {
  13078. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13079. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  13080. #endif
  13081. last_tickCount = tickCount;
  13082. }
  13083. else {
  13084. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13085. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  13086. #endif
  13087. }
  13088. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  13089. ret = (double)tickCount / configTICK_RATE_HZ;
  13090. #else
  13091. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  13092. "assuming 1000 Hz.");
  13093. ret = (double)(tickCount / 1000.0);
  13094. #endif /* configTICK_RATE_HZ */
  13095. return ret;
  13096. } /* current_time */
  13097. #else
  13098. /* current_time(reset)
  13099. *
  13100. * Benchmark passage of time, in fractional seconds.
  13101. * [reset] is non zero to adjust timer or counter to zero
  13102. *
  13103. * Use care when repeatedly calling calling. See implementation. */
  13104. double current_time(int reset)
  13105. {
  13106. portTickType tickCount = xTaskGetTickCount();
  13107. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  13108. #ifdef configTICK_RATE_HZ
  13109. return (double)tickCount / configTICK_RATE_HZ;
  13110. #else
  13111. return (double)tickCount / 1000;
  13112. #endif
  13113. }
  13114. #endif
  13115. #elif defined (WOLFSSL_TIRTOS)
  13116. extern double current_time(int reset);
  13117. #elif defined(FREESCALE_MQX)
  13118. double current_time(int reset)
  13119. {
  13120. TIME_STRUCT tv;
  13121. _time_get(&tv);
  13122. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  13123. }
  13124. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  13125. && defined(MAX3266X_RTC)
  13126. double current_time(int reset)
  13127. {
  13128. (void)reset;
  13129. return wc_MXC_RTC_Time();
  13130. }
  13131. #elif defined(FREESCALE_KSDK_BM)
  13132. double current_time(int reset)
  13133. {
  13134. return (double)OSA_TimeGetMsec() / 1000;
  13135. }
  13136. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  13137. double current_time(int reset)
  13138. {
  13139. (void)reset;
  13140. return (double)osKernelGetTickCount() / 1000.0;
  13141. }
  13142. #elif defined(WOLFSSL_EMBOS)
  13143. #include "RTOS.h"
  13144. double current_time(int reset)
  13145. {
  13146. double time_now;
  13147. double current_s = OS_GetTime() / 1000.0;
  13148. double current_us = OS_GetTime_us() / MILLION_VALUE;
  13149. time_now = (double)( current_s + current_us);
  13150. (void) reset;
  13151. return time_now;
  13152. }
  13153. #elif defined(WOLFSSL_SGX)
  13154. double current_time(int reset);
  13155. #elif defined(WOLFSSL_DEOS)
  13156. double current_time(int reset)
  13157. {
  13158. const uint32_t systemTickTimeInHz
  13159. = 1000000 / systemTickInMicroseconds();
  13160. const volatile uint32_t *systemTickPtr = systemTickPointer();
  13161. (void)reset;
  13162. return (double) *systemTickPtr/systemTickTimeInHz;
  13163. }
  13164. #elif defined(MICRIUM)
  13165. double current_time(int reset)
  13166. {
  13167. #if (OS_VERSION < 50000)
  13168. CPU_ERR err;
  13169. (void)reset;
  13170. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  13171. #else
  13172. RTOS_ERR err;
  13173. double ret = 0;
  13174. OS_TICK tick = OSTimeGet(&err);
  13175. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13176. (void)reset;
  13177. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13178. ret = ((double)tick)/rate;
  13179. }
  13180. return ret;
  13181. #endif
  13182. }
  13183. #elif defined(WOLFSSL_ZEPHYR)
  13184. #include <time.h>
  13185. double current_time(int reset)
  13186. {
  13187. int64_t t;
  13188. (void)reset;
  13189. #if defined(CONFIG_ARCH_POSIX)
  13190. k_cpu_idle();
  13191. #endif
  13192. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13193. return (double)(t / 1000);
  13194. }
  13195. #elif defined(WOLFSSL_NETBURNER)
  13196. #include <predef.h>
  13197. #include <utils.h>
  13198. #include <constants.h>
  13199. double current_time(int reset)
  13200. {
  13201. DWORD ticks = TimeTick; /* ticks since system start */
  13202. (void)reset;
  13203. return (double) ticks/TICKS_PER_SECOND;
  13204. }
  13205. #elif defined(WOLFSSL_RPIPICO)
  13206. #include "pico/stdlib.h"
  13207. double current_time(int reset)
  13208. {
  13209. (void)reset;
  13210. return (double) time_us_64() / 1000000;
  13211. }
  13212. #elif defined(THREADX)
  13213. #include "tx_api.h"
  13214. double current_time(int reset)
  13215. {
  13216. (void)reset;
  13217. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13218. }
  13219. #elif defined(WOLFSSL_XILINX)
  13220. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13221. #define COUNTS_PER_SECOND \
  13222. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13223. #else
  13224. #define COUNTS_PER_SECOND \
  13225. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13226. #endif
  13227. double current_time(int reset)
  13228. {
  13229. double timer;
  13230. uint64_t cntPct = 0;
  13231. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13232. /* Convert to milliseconds */
  13233. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13234. /* Convert to seconds.millisecond */
  13235. timer /= 1000;
  13236. return timer;
  13237. }
  13238. #elif defined(LINUX_RUSAGE_UTIME)
  13239. #include <sys/time.h>
  13240. #include <sys/resource.h>
  13241. static struct rusage base_rusage;
  13242. static struct rusage cur_rusage;
  13243. double current_time(int reset)
  13244. {
  13245. struct rusage rusage;
  13246. (void)reset;
  13247. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13248. if (reset)
  13249. base_rusage = rusage;
  13250. else
  13251. cur_rusage = rusage;
  13252. /* only consider user time, as system time is host-related overhead
  13253. * outside wolfcrypt.
  13254. */
  13255. return (double)rusage.ru_utime.tv_sec +
  13256. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13257. }
  13258. static void check_for_excessive_stime(const char *desc,
  13259. const char *desc_extra)
  13260. {
  13261. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13262. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13263. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13264. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13265. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13266. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13267. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13268. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13269. double stime_utime_ratio =
  13270. (cur_stime - start_stime) / (cur_utime - start_utime);
  13271. if (stime_utime_ratio > .1)
  13272. printf("%swarning, "
  13273. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13274. err_prefix, desc, desc_extra,
  13275. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13276. }
  13277. #elif defined(WOLFSSL_LINUXKM)
  13278. double current_time(int reset)
  13279. {
  13280. (void)reset;
  13281. u64 ns = ktime_get_ns();
  13282. return (double)ns / 1000000000.0;
  13283. }
  13284. #else
  13285. #include <time.h>
  13286. #include <sys/time.h>
  13287. double current_time(int reset)
  13288. {
  13289. struct timespec tv;
  13290. (void)reset;
  13291. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13292. #ifdef BENCH_MICROSECOND
  13293. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13294. #else
  13295. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13296. #endif
  13297. }
  13298. #endif /* _WIN32 */
  13299. #if defined(HAVE_GET_CYCLES)
  13300. #if defined(WOLFSSL_ESPIDF)
  13301. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13302. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13303. {
  13304. /* Reminder for long duration between calls with
  13305. * multiple overflows will not be detected. */
  13306. return esp_get_cycle_count_ex();
  13307. }
  13308. /* implement other architectures here */
  13309. #else
  13310. static WC_INLINE word64 get_intel_cycles(void)
  13311. {
  13312. unsigned int lo_c, hi_c;
  13313. __asm__ __volatile__ (
  13314. "cpuid\n\t"
  13315. "rdtsc"
  13316. : "=a"(lo_c), "=d"(hi_c) /* out */
  13317. : "a"(0) /* in */
  13318. : "%ebx", "%ecx"); /* clobber */
  13319. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13320. }
  13321. #endif
  13322. #endif /* HAVE_GET_CYCLES */
  13323. void benchmark_configure(word32 block_size)
  13324. {
  13325. /* must be greater than 0 */
  13326. if (block_size > 0) {
  13327. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13328. bench_size = block_size;
  13329. }
  13330. }
  13331. #ifndef NO_MAIN_DRIVER
  13332. #ifndef MAIN_NO_ARGS
  13333. #ifndef WOLFSSL_BENCHMARK_ALL
  13334. /* Display the algorithm string and keep to 80 characters per line.
  13335. *
  13336. * str Algorithm string to print.
  13337. * line Length of line used so far.
  13338. */
  13339. #ifndef BENCH_MAX_LINE
  13340. #define BENCH_MAX_LINE 80
  13341. #endif
  13342. static void print_alg(const char* str, int* line)
  13343. {
  13344. const char* const ident = " ";
  13345. if (*line == 0) {
  13346. printf("%s", ident);
  13347. *line = (int)XSTRLEN(ident);
  13348. }
  13349. printf(" %s", str);
  13350. *line += (int)XSTRLEN(str) + 1;
  13351. if (*line > BENCH_MAX_LINE) {
  13352. printf("\n");
  13353. *line = 0;
  13354. }
  13355. }
  13356. #endif /* WOLFSSL_BENCHMARK_ALL */
  13357. /* Display the usage options of the benchmark program. */
  13358. static void Usage(void)
  13359. {
  13360. int e = 0;
  13361. #ifndef WOLFSSL_BENCHMARK_ALL
  13362. int i;
  13363. int line;
  13364. #endif
  13365. printf("benchmark\n");
  13366. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13367. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13368. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13369. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13370. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13371. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13372. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13373. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13374. #else
  13375. e += 3;
  13376. #endif
  13377. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13378. #ifndef NO_RSA
  13379. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13380. #ifdef WOLFSSL_KEY_GEN
  13381. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13382. #endif
  13383. e++;
  13384. #else
  13385. e += 2;
  13386. #endif
  13387. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13388. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13389. #endif
  13390. e++;
  13391. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13392. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13393. #endif
  13394. e++;
  13395. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13396. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13397. #endif
  13398. e++;
  13399. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13400. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13401. #endif
  13402. e++;
  13403. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13404. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13405. #endif
  13406. e++;
  13407. #if defined(HAVE_ECC)
  13408. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13409. #endif
  13410. e++;
  13411. #ifndef WOLFSSL_BENCHMARK_ALL
  13412. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13413. line = 0;
  13414. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13415. print_alg(bench_cipher_opt[i].str, &line);
  13416. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13417. print_alg(bench_digest_opt[i].str, &line);
  13418. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13419. print_alg(bench_mac_opt[i].str, &line);
  13420. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13421. print_alg(bench_kdf_opt[i].str, &line);
  13422. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13423. print_alg(bench_asym_opt[i].str, &line);
  13424. for (i=0; bench_other_opt[i].str != NULL; i++)
  13425. print_alg(bench_other_opt[i].str, &line);
  13426. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13427. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13428. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13429. print_alg(bench_pq_asym_opt[i].str, &line);
  13430. #if defined(HAVE_SPHINCS)
  13431. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13432. print_alg(bench_pq_asym_opt2[i].str, &line);
  13433. #endif /* HAVE_SPHINCS */
  13434. #endif
  13435. #if defined(BENCH_PQ_STATEFUL_HBS)
  13436. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13437. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13438. #endif /* BENCH_PQ_STATEFUL_HBS */
  13439. printf("\n");
  13440. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13441. e++;
  13442. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13443. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13444. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13445. #ifdef WC_ENABLE_BENCH_THREADING
  13446. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13447. #endif
  13448. e++;
  13449. #ifdef WC_BENCH_TRACK_STATS
  13450. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13451. #endif
  13452. e++;
  13453. #ifndef NO_FILESYSTEM
  13454. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13455. #endif
  13456. e++;
  13457. #ifndef NO_FILESYSTEM
  13458. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13459. #endif
  13460. #ifdef MULTI_VALUE_STATISTICS
  13461. e++;
  13462. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13463. #endif
  13464. }
  13465. /* Match the command line argument with the string.
  13466. *
  13467. * arg Command line argument.
  13468. * str String to check for.
  13469. * return 1 if the command line argument matches the string, 0 otherwise.
  13470. */
  13471. static int string_matches(const char* arg, const char* str)
  13472. {
  13473. return XSTRCMP(arg, str) == 0;
  13474. }
  13475. #endif /* MAIN_NO_ARGS */
  13476. /*
  13477. ** ----------------------------------------------------------------------------
  13478. ** determine how the benchmarks are called, the function name varies:
  13479. ** ----------------------------------------------------------------------------
  13480. */
  13481. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13482. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13483. /* for some environments, we'll call a function wolf_benchmark_task: */
  13484. int wolf_benchmark_task(void)
  13485. #elif defined(MAIN_NO_ARGS)
  13486. /* otherwise we'll use main() with no arguments as desired: */
  13487. int main()
  13488. #else
  13489. /* else we'll be calling main with default arg parameters */
  13490. int main(int argc, char** argv)
  13491. #endif
  13492. {
  13493. /* Code for main() or wolf_benchmark_task() */
  13494. #ifdef WOLFSSL_ESPIDF
  13495. int argc = construct_argv();
  13496. char** argv = (char**)__argv;
  13497. #elif defined(MAIN_NO_ARGS)
  13498. int argc = 0;
  13499. char** argv = NULL;
  13500. #endif
  13501. return wolfcrypt_benchmark_main(argc, argv);
  13502. }
  13503. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13504. int wolfcrypt_benchmark_main(int argc, char** argv)
  13505. {
  13506. int ret = 0;
  13507. #ifndef MAIN_NO_ARGS
  13508. int optMatched;
  13509. #ifndef WOLFSSL_BENCHMARK_ALL
  13510. int i;
  13511. #endif
  13512. #endif
  13513. benchmark_static_init(1);
  13514. printf("%s------------------------------------------------------------------------------\n",
  13515. info_prefix);
  13516. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13517. printf("%s------------------------------------------------------------------------------\n",
  13518. info_prefix);
  13519. #ifndef MAIN_NO_ARGS
  13520. while (argc > 1) {
  13521. if (string_matches(argv[1], "-?")) {
  13522. if (--argc > 1) {
  13523. lng_index = XATOI((++argv)[1]);
  13524. if (lng_index<0 || lng_index>1) {
  13525. lng_index = 0;
  13526. }
  13527. }
  13528. Usage();
  13529. return 0;
  13530. }
  13531. else if (string_matches(argv[1], "-lng")) {
  13532. argc--;
  13533. argv++;
  13534. if (argc > 1) {
  13535. lng_index = XATOI(argv[1]);
  13536. if (lng_index<0 || lng_index>1) {
  13537. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13538. lng_index);
  13539. lng_index = 0;
  13540. }
  13541. }
  13542. }
  13543. else if (string_matches(argv[1], "-base10"))
  13544. base2 = 0;
  13545. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13546. else if (string_matches(argv[1], "-no_aad"))
  13547. aes_aad_options = AAD_SIZE_ZERO;
  13548. else if (string_matches(argv[1], "-all_aad"))
  13549. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13550. else if (string_matches(argv[1], "-aad_size")) {
  13551. argc--;
  13552. argv++;
  13553. if (argc > 1) {
  13554. aes_aad_size = (word32)XATOI(argv[1]);
  13555. aes_aad_options |= AAD_SIZE_CUSTOM;
  13556. }
  13557. }
  13558. #endif
  13559. else if (string_matches(argv[1], "-dgst_full"))
  13560. digest_stream = 0;
  13561. #ifdef HAVE_CHACHA
  13562. else if (string_matches(argv[1], "-enc_only"))
  13563. encrypt_only = 1;
  13564. #endif
  13565. #ifndef NO_RSA
  13566. else if (string_matches(argv[1], "-rsa_sign"))
  13567. rsa_sign_verify = 1;
  13568. #endif
  13569. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13570. else if (string_matches(argv[1], "-ffdhe2048"))
  13571. use_ffdhe = 2048;
  13572. #endif
  13573. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13574. else if (string_matches(argv[1], "-ffdhe3072"))
  13575. use_ffdhe = 3072;
  13576. #endif
  13577. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13578. else if (string_matches(argv[1], "-ffdhe4096"))
  13579. use_ffdhe = 4096;
  13580. #endif
  13581. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13582. else if (string_matches(argv[1], "-p256"))
  13583. bench_asym_algs |= BENCH_ECC_P256;
  13584. #endif
  13585. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13586. else if (string_matches(argv[1], "-p384"))
  13587. bench_asym_algs |= BENCH_ECC_P384;
  13588. #endif
  13589. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13590. else if (string_matches(argv[1], "-p521"))
  13591. bench_asym_algs |= BENCH_ECC_P521;
  13592. #endif
  13593. #ifdef BENCH_ASYM
  13594. else if (string_matches(argv[1], "-csv")) {
  13595. csv_format = 1;
  13596. }
  13597. #endif
  13598. #ifdef WC_ENABLE_BENCH_THREADING
  13599. else if (string_matches(argv[1], "-threads")) {
  13600. argc--;
  13601. argv++;
  13602. if (argc > 1) {
  13603. g_threadCount = XATOI(argv[1]);
  13604. if (g_threadCount < 1 || lng_index > 128){
  13605. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13606. g_threadCount);
  13607. g_threadCount = 0;
  13608. }
  13609. }
  13610. }
  13611. #endif
  13612. #ifdef WC_BENCH_TRACK_STATS
  13613. else if (string_matches(argv[1], "-print")) {
  13614. gPrintStats = 1;
  13615. }
  13616. #endif
  13617. else if (string_matches(argv[1], "-blocks")) {
  13618. argc--;
  13619. argv++;
  13620. if (argc > 1)
  13621. numBlocks = XATOI(argv[1]);
  13622. }
  13623. #ifndef NO_FILESYSTEM
  13624. else if (string_matches(argv[1], "-hash_input")) {
  13625. argc--;
  13626. argv++;
  13627. if (argc > 1)
  13628. hash_input = argv[1];
  13629. }
  13630. else if (string_matches(argv[1], "-cipher_input")) {
  13631. argc--;
  13632. argv++;
  13633. if (argc > 1)
  13634. cipher_input = argv[1];
  13635. }
  13636. #endif
  13637. #ifdef MULTI_VALUE_STATISTICS
  13638. else if (string_matches(argv[1], "-min_runs")) {
  13639. argc--;
  13640. argv++;
  13641. if (argc > 1) {
  13642. minimum_runs = XATOI(argv[1]);
  13643. }
  13644. }
  13645. #endif
  13646. else if (argv[1][0] == '-') {
  13647. optMatched = 0;
  13648. #ifndef WOLFSSL_BENCHMARK_ALL
  13649. /* Check known algorithm choosing command line options. */
  13650. /* Known cipher algorithms */
  13651. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13652. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13653. bench_cipher_algs |= bench_cipher_opt[i].val;
  13654. bench_all = 0;
  13655. optMatched = 1;
  13656. }
  13657. }
  13658. /* Known digest algorithms */
  13659. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13660. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13661. bench_digest_algs |= bench_digest_opt[i].val;
  13662. bench_all = 0;
  13663. optMatched = 1;
  13664. }
  13665. }
  13666. /* Known MAC algorithms */
  13667. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13668. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13669. bench_mac_algs |= bench_mac_opt[i].val;
  13670. bench_all = 0;
  13671. optMatched = 1;
  13672. }
  13673. }
  13674. /* Known KDF algorithms */
  13675. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13676. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13677. bench_kdf_algs |= bench_kdf_opt[i].val;
  13678. bench_all = 0;
  13679. optMatched = 1;
  13680. }
  13681. }
  13682. /* Known asymmetric algorithms */
  13683. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13684. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13685. bench_asym_algs |= bench_asym_opt[i].val;
  13686. bench_all = 0;
  13687. optMatched = 1;
  13688. }
  13689. }
  13690. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13691. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13692. /* Known asymmetric post-quantum algorithms */
  13693. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13694. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13695. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13696. bench_all = 0;
  13697. optMatched = 1;
  13698. }
  13699. }
  13700. #ifdef HAVE_SPHINCS
  13701. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13702. * -pq, so we need to do a special case for -pq since optMatched
  13703. * was set to 1 just above. */
  13704. if ((bench_pq_asym_opt[0].str != NULL) &&
  13705. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13706. {
  13707. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13708. bench_all = 0;
  13709. optMatched = 1;
  13710. }
  13711. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13712. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13713. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13714. bench_all = 0;
  13715. optMatched = 1;
  13716. }
  13717. }
  13718. #endif
  13719. #endif
  13720. /* Other known cryptographic algorithms */
  13721. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13722. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13723. bench_other_algs |= bench_other_opt[i].val;
  13724. bench_all = 0;
  13725. optMatched = 1;
  13726. }
  13727. }
  13728. #if defined(BENCH_PQ_STATEFUL_HBS)
  13729. /* post-quantum stateful hash-based signatures */
  13730. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13731. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13732. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13733. bench_all = 0;
  13734. optMatched = 1;
  13735. }
  13736. }
  13737. #endif /* BENCH_PQ_STATEFUL_HBS */
  13738. #endif
  13739. if (!optMatched) {
  13740. printf("Option not recognized: %s\n", argv[1]);
  13741. Usage();
  13742. return 1;
  13743. }
  13744. }
  13745. else {
  13746. /* parse for block size */
  13747. benchmark_configure((word32)XATOI(argv[1]));
  13748. }
  13749. argc--;
  13750. argv++;
  13751. }
  13752. #endif /* MAIN_NO_ARGS */
  13753. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13754. /* when defined, we'll always output CSV regardless of params.
  13755. ** this is typically convenient in embedded environments.
  13756. */
  13757. csv_format = 1;
  13758. #endif
  13759. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13760. if (g_threadCount > 1) {
  13761. ret = benchmark_test_threaded(NULL);
  13762. }
  13763. else
  13764. #endif
  13765. {
  13766. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13767. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13768. defined(CONFIG_IDF_TARGET_ESP32C6)
  13769. {
  13770. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13771. if (esp_gptimer == NULL) {
  13772. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13773. &esp_gptimer) );
  13774. }
  13775. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13776. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13777. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13778. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13779. }
  13780. #endif
  13781. #ifdef HAVE_STACK_SIZE
  13782. ret = StackSizeCheck(NULL, benchmark_test);
  13783. #else
  13784. ret = benchmark_test(NULL);
  13785. #endif
  13786. }
  13787. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13788. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13789. defined(CONFIG_IDF_TARGET_ESP32C6)
  13790. {
  13791. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13792. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13793. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13794. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13795. }
  13796. #endif
  13797. return ret;
  13798. }
  13799. #endif /* !NO_MAIN_DRIVER */
  13800. #else
  13801. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13802. int main(void) { return 0; }
  13803. #endif
  13804. #endif /* !NO_CRYPT_BENCHMARK */