benchmark.c 511 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069
  1. /* benchmark.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* wolfCrypt benchmark */
  22. /* Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. * make the binary always use CSV format:
  26. * WOLFSSL_BENCHMARK_FIXED_CSV
  27. *
  28. * choose to use the same units, regardless of scale. pick 1:
  29. * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
  30. * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
  31. * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  32. * WOLFSSL_BENCHMARK_FIXED_UNITS_B
  33. *
  34. * when the output should be in machine-parseable format:
  35. * GENERATE_MACHINE_PARSEABLE_REPORT
  36. *
  37. * use microseconds as the unit of time:
  38. * BENCH_MICROSECOND
  39. *
  40. * display mean, max, min and sd of operation durations:
  41. * MULTI_VALUE_STATISTICS
  42. *
  43. * Enable tracking of the stats into an allocated linked list:
  44. * (use -print to display results):
  45. * WC_BENCH_TRACK_STATS
  46. *
  47. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  48. * WC_USE_DEVID=0x1234
  49. *
  50. * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  51. * DEBUG_WOLFSSL_BENCHMARK_TIMING
  52. *
  53. * Turn on timer debugging (used when CPU cycles not available)
  54. * WOLFSSL_BENCHMARK_TIMER_DEBUG
  55. */
  56. #ifdef HAVE_CONFIG_H
  57. #include <config.h>
  58. #endif
  59. #ifndef WOLFSSL_USER_SETTINGS
  60. #include <wolfssl/options.h>
  61. #endif
  62. #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
  63. /* Macro to disable benchmark */
  64. #ifndef NO_CRYPT_BENCHMARK
  65. #define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
  66. #include <wolfssl/wolfcrypt/types.h>
  67. #include <wolfssl/wolfcrypt/wc_port.h>
  68. #include <wolfssl/wolfcrypt/wolfmath.h>
  69. #include <wolfssl/wolfcrypt/memory.h>
  70. #include <wolfssl/wolfcrypt/random.h>
  71. #include <wolfssl/wolfcrypt/error-crypt.h>
  72. #include <wolfssl/wolfcrypt/asn.h>
  73. #include <wolfssl/version.h>
  74. #ifdef WOLFSSL_LINUXKM
  75. /* remap current_time() -- collides with a function in kernel linux/fs.h */
  76. #define current_time benchmark_current_time
  77. #endif /* WOLFSSL_LINUXKM */
  78. #ifdef HAVE_CHACHA
  79. #include <wolfssl/wolfcrypt/chacha.h>
  80. #endif
  81. #ifdef HAVE_POLY1305
  82. #include <wolfssl/wolfcrypt/poly1305.h>
  83. #endif
  84. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  86. #endif
  87. #ifndef NO_AES
  88. #include <wolfssl/wolfcrypt/aes.h>
  89. #endif
  90. #ifdef HAVE_CAMELLIA
  91. #include <wolfssl/wolfcrypt/camellia.h>
  92. #endif
  93. #ifdef WOLFSSL_SM4
  94. #include <wolfssl/wolfcrypt/sm4.h>
  95. #endif
  96. #ifndef NO_MD5
  97. #include <wolfssl/wolfcrypt/md5.h>
  98. #endif
  99. #ifndef NO_SHA
  100. #include <wolfssl/wolfcrypt/sha.h>
  101. #endif
  102. #ifndef NO_SHA256
  103. #include <wolfssl/wolfcrypt/sha256.h>
  104. #endif
  105. #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
  106. #include <wolfssl/wolfcrypt/sha512.h>
  107. #endif
  108. #ifdef WOLFSSL_SHA3
  109. #include <wolfssl/wolfcrypt/sha3.h>
  110. #endif
  111. #ifdef WOLFSSL_SM3
  112. #include <wolfssl/wolfcrypt/sm3.h>
  113. #endif
  114. #ifndef NO_RSA
  115. #include <wolfssl/wolfcrypt/rsa.h>
  116. #endif
  117. #ifdef WOLFSSL_RIPEMD
  118. #include <wolfssl/wolfcrypt/ripemd.h>
  119. #endif
  120. #ifdef WOLFSSL_CMAC
  121. #include <wolfssl/wolfcrypt/cmac.h>
  122. #endif
  123. #ifndef NO_DH
  124. #include <wolfssl/wolfcrypt/dh.h>
  125. #endif
  126. #ifndef NO_DES3
  127. #include <wolfssl/wolfcrypt/des3.h>
  128. #endif
  129. #ifndef NO_RC4
  130. #include <wolfssl/wolfcrypt/arc4.h>
  131. #endif
  132. #ifndef NO_HMAC
  133. #include <wolfssl/wolfcrypt/hmac.h>
  134. #endif
  135. #ifdef WOLFSSL_SIPHASH
  136. #include <wolfssl/wolfcrypt/siphash.h>
  137. #endif
  138. #include <wolfssl/wolfcrypt/kdf.h>
  139. #ifndef NO_PWDBASED
  140. #include <wolfssl/wolfcrypt/pwdbased.h>
  141. #endif
  142. #ifdef HAVE_ECC
  143. #include <wolfssl/wolfcrypt/ecc.h>
  144. #endif
  145. #ifdef WOLFSSL_SM2
  146. #include <wolfssl/wolfcrypt/sm2.h>
  147. #endif
  148. #ifdef HAVE_CURVE25519
  149. #include <wolfssl/wolfcrypt/curve25519.h>
  150. #endif
  151. #ifdef HAVE_ED25519
  152. #include <wolfssl/wolfcrypt/ed25519.h>
  153. #endif
  154. #ifdef HAVE_CURVE448
  155. #include <wolfssl/wolfcrypt/curve448.h>
  156. #endif
  157. #ifdef HAVE_ED448
  158. #include <wolfssl/wolfcrypt/ed448.h>
  159. #endif
  160. #ifdef WOLFSSL_HAVE_KYBER
  161. #include <wolfssl/wolfcrypt/kyber.h>
  162. #ifdef WOLFSSL_WC_KYBER
  163. #include <wolfssl/wolfcrypt/wc_kyber.h>
  164. #endif
  165. #if defined(HAVE_LIBOQS)
  166. #include <wolfssl/wolfcrypt/ext_kyber.h>
  167. #endif
  168. #endif
  169. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  170. #include <wolfssl/wolfcrypt/lms.h>
  171. #ifdef HAVE_LIBLMS
  172. #include <wolfssl/wolfcrypt/ext_lms.h>
  173. #else
  174. #include <wolfssl/wolfcrypt/wc_lms.h>
  175. #endif
  176. #endif
  177. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  178. #include <wolfssl/wolfcrypt/xmss.h>
  179. #ifdef HAVE_LIBXMSS
  180. #include <wolfssl/wolfcrypt/ext_xmss.h>
  181. #else
  182. #include <wolfssl/wolfcrypt/wc_xmss.h>
  183. #endif
  184. #endif
  185. #ifdef WOLFCRYPT_HAVE_ECCSI
  186. #include <wolfssl/wolfcrypt/eccsi.h>
  187. #endif
  188. #ifdef WOLFCRYPT_HAVE_SAKKE
  189. #include <wolfssl/wolfcrypt/sakke.h>
  190. #endif
  191. #if defined(HAVE_FALCON)
  192. #include <wolfssl/wolfcrypt/falcon.h>
  193. #endif
  194. #if defined(HAVE_DILITHIUM)
  195. #include <wolfssl/wolfcrypt/dilithium.h>
  196. #endif
  197. #if defined(HAVE_SPHINCS)
  198. #include <wolfssl/wolfcrypt/sphincs.h>
  199. #endif
  200. #ifdef WOLF_CRYPTO_CB
  201. #include <wolfssl/wolfcrypt/cryptocb.h>
  202. #ifdef HAVE_INTEL_QA_SYNC
  203. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  204. #endif
  205. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  206. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  207. #endif
  208. #ifdef HAVE_RENESAS_SYNC
  209. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  210. #endif
  211. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  212. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  213. #endif
  214. #endif
  215. #ifdef WOLFSSL_ASYNC_CRYPT
  216. #include <wolfssl/wolfcrypt/async.h>
  217. #endif
  218. #ifdef USE_FLAT_BENCHMARK_H
  219. #include "benchmark.h"
  220. #else
  221. #include "wolfcrypt/benchmark/benchmark.h"
  222. #endif
  223. /* define the max length for each string of metric reported */
  224. #ifndef WC_BENCH_MAX_LINE_LEN
  225. #define WC_BENCH_MAX_LINE_LEN 150
  226. #endif
  227. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  228. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  229. #define MILLION_VALUE 1000000.0
  230. #ifdef BENCH_MICROSECOND
  231. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  232. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  233. #else
  234. #define WOLFSSL_FIXED_TIME_UNIT "s"
  235. #endif
  236. #ifdef MULTI_VALUE_STATISTICS
  237. #define STATS_CLAUSE_SEPARATOR ""
  238. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  239. squareSum = 0, prev = 0, delta;\
  240. int runs = 0;
  241. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  242. delta = current_time(0) - start;\
  243. min = delta;\
  244. max = delta;\
  245. }\
  246. else {\
  247. delta = current_time(0) - prev;\
  248. }\
  249. if (max < delta)\
  250. max = delta;\
  251. else if (min > delta)\
  252. min = delta;\
  253. sum += delta;\
  254. squareSum += delta * delta;\
  255. runs++;\
  256. prev = current_time(0)
  257. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  258. runs = 0;\
  259. sum = 0;\
  260. squareSum = 0
  261. #else
  262. #define STATS_CLAUSE_SEPARATOR "\n"
  263. #define DECLARE_MULTI_VALUE_STATS_VARS()
  264. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  265. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  266. #endif
  267. #ifdef WOLFSSL_NO_FLOAT_FMT
  268. #define FLT_FMT "%0ld,%09lu"
  269. #define FLT_FMT_PREC "%0ld.%0*lu"
  270. #define FLT_FMT_PREC2 FLT_FMT_PREC
  271. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  272. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  273. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  274. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  275. 10000.0, 100000.0, 1000000.0, \
  276. 10000000.0, 100000000.0, \
  277. 1000000000.0 };
  278. #define FLT_FMT_PREC_ARGS(p, x) \
  279. (long)(x), \
  280. p, \
  281. (x) >= 0.0 ? \
  282. (unsigned long int)((((x) - (double)(long)(x)) * \
  283. pow_10_array[(p)+1]) + 0.5) : \
  284. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  285. pow_10_array[(p)+1]) + 0.5)
  286. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  287. #else
  288. #define FLT_FMT "%f"
  289. #define FLT_FMT_PREC "%.*f"
  290. #define FLT_FMT_PREC2 "%*.*f"
  291. #define FLT_FMT_ARGS(x) x
  292. #define FLT_FMT_PREC_ARGS(p, x) p, x
  293. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  294. #endif /* WOLFSSL_NO_FLOAT_FMT */
  295. #ifdef WOLFSSL_ESPIDF
  296. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  297. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  298. * enabled, all if the values in report are blank. */
  299. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  300. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  301. #error "Nano newlib formatting must not be enabled for benchmark"
  302. #endif
  303. #endif
  304. #if ESP_IDF_VERSION_MAJOR >= 5
  305. #define TFMT "%lu"
  306. #else
  307. #define TFMT "%d"
  308. #endif
  309. #ifdef configTICK_RATE_HZ
  310. /* Define CPU clock cycles per tick of FreeRTOS clock
  311. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  312. * configTICK_RATE_HZ is typically 100 or 1000.
  313. **/
  314. #if defined(CONFIG_IDF_TARGET_ESP8266)
  315. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  316. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  317. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  318. #endif
  319. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  320. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  321. #endif
  322. #endif
  323. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  324. /* This section is for pre-v5 ESP-IDF */
  325. #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  326. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  327. CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
  328. #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
  329. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  330. CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
  331. #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
  332. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  333. CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
  334. #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
  335. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  336. CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
  337. #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
  338. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  339. CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
  340. #else
  341. /* TODO unsupported */
  342. #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
  343. #endif
  344. #define CPU_TICK_CYCLES ( \
  345. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  346. / configTICK_RATE_HZ \
  347. )
  348. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  349. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  350. #include "driver/gptimer.h"
  351. static gptimer_handle_t esp_gptimer = NULL;
  352. static gptimer_config_t esp_timer_config = {
  353. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  354. .direction = GPTIMER_COUNT_UP,
  355. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  356. };
  357. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  358. defined(CONFIG_IDF_TARGET_ESP32C6)
  359. #include <esp_cpu.h>
  360. #if ESP_IDF_VERSION_MAJOR >= 5
  361. #include <driver/gptimer.h>
  362. #endif
  363. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  364. #define RESOLUTION_SCALE 100
  365. /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  366. static gptimer_handle_t esp_gptimer = NULL;
  367. static gptimer_config_t esp_timer_config = {
  368. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  369. .direction = GPTIMER_COUNT_UP,
  370. /* CONFIG_XTAL_FREQ = 40,
  371. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  372. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  373. (MILLION_VALUE / RESOLUTION_SCALE),
  374. };
  375. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  376. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  377. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  378. defined(CONFIG_IDF_TARGET_ESP32S3)
  379. #include <xtensa/hal.h>
  380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  381. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  382. #include <FreeRTOS.h>
  383. #include <esp_system.h>
  384. #include <esp_timer.h>
  385. #include <xtensa/hal.h>
  386. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  387. /* TODO add ESP32-H2 benchmark support */
  388. #else
  389. /* Other platform */
  390. #endif
  391. #include <esp_log.h>
  392. #endif /* WOLFSSL_ESPIDF */
  393. #if defined(HAVE_PTHREAD) || \
  394. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  395. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  396. !defined(BENCH_EMBEDDED))
  397. #include <errno.h>
  398. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  399. #include <unistd.h>
  400. #endif
  401. #endif
  402. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  403. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  404. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  405. #undef XFFLUSH
  406. #define XFFLUSH(...) WC_DO_NOTHING
  407. #endif
  408. /* only for stack size check */
  409. #include <wolfssl/wolfcrypt/mem_track.h>
  410. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  411. #define WC_ENABLE_BENCH_THREADING
  412. #endif
  413. /* enable tracking of stats for threaded benchmark */
  414. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  415. #define WC_BENCH_TRACK_STATS
  416. #endif
  417. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  418. static const char info_prefix[] = "###, ";
  419. static const char err_prefix[] = "!!!, ";
  420. #else
  421. static const char info_prefix[] = "";
  422. static const char err_prefix[] = "";
  423. #endif
  424. /* printf mappings */
  425. #ifdef FREESCALE_MQX
  426. #include <mqx.h>
  427. /* see wc_port.h for fio.h and nio.h includes */
  428. #elif defined(FREESCALE_KSDK_1_3)
  429. #include "fsl_debug_console.h"
  430. #include "fsl_os_abstraction.h"
  431. #undef printf
  432. #define printf PRINTF
  433. #elif defined(WOLFSSL_DEOS)
  434. #include <deos.h>
  435. #include <printx.h>
  436. #undef printf
  437. #define printf printx
  438. #elif defined(MICRIUM)
  439. #if (OS_VERSION < 50000)
  440. #include <bsp_ser.h>
  441. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  442. #undef printf
  443. #define printf BSP_Ser_Printf
  444. #endif
  445. #elif defined(WOLFSSL_ZEPHYR)
  446. #include <stdio.h>
  447. #define BENCH_EMBEDDED
  448. #define printf printfk
  449. static int printfk(const char *fmt, ...)
  450. {
  451. int ret;
  452. char line[WC_BENCH_MAX_LINE_LEN];
  453. va_list ap;
  454. va_start(ap, fmt);
  455. ret = vsnprintf(line, sizeof(line), fmt, ap);
  456. line[sizeof(line)-1] = '\0';
  457. printk("%s", line);
  458. va_end(ap);
  459. return ret;
  460. }
  461. #elif defined(WOLFSSL_TELIT_M2MB)
  462. #include <stdarg.h>
  463. #include <stdio.h>
  464. #include <string.h>
  465. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  466. /* remap printf */
  467. #undef printf
  468. #define printf M2M_LOG_INFO
  469. /* OS requires occasional sleep() */
  470. #ifndef TEST_SLEEP_MS
  471. #define TEST_SLEEP_MS 50
  472. #endif
  473. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  474. /* don't use file system for these tests, since ./certs dir isn't loaded */
  475. #undef NO_FILESYSTEM
  476. #define NO_FILESYSTEM
  477. /* ANDROID_V454 (for android studio) displays information in a textview
  478. * and redirects printf to the textview output instead of using
  479. * __android_log_print() */
  480. #elif defined(ANDROID) && !defined(ANDROID_V454)
  481. #ifdef XMALLOC_USER
  482. #include <stdlib.h> /* we're using malloc / free direct here */
  483. #endif
  484. #ifndef STRING_USER
  485. #include <stdio.h>
  486. #endif
  487. #include <android/log.h>
  488. #define printf(...) \
  489. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  490. #define fprintf(fp, ...) \
  491. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  492. #else
  493. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  494. /* MQX classic needs for EXIT_FAILURE */
  495. #include <stdlib.h> /* we're using malloc / free direct here */
  496. #endif
  497. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  498. #include <string.h>
  499. #include <stdio.h>
  500. #endif
  501. /* enable way for customer to override test/bench printf */
  502. #ifdef XPRINTF
  503. #undef printf
  504. #define printf XPRINTF
  505. #elif defined(NETOS)
  506. #undef printf
  507. #define printf dc_log_printf
  508. #endif
  509. #endif
  510. #ifdef HAVE_FIPS
  511. #include <wolfssl/wolfcrypt/fips_test.h>
  512. static void myFipsCb(int ok, int err, const char* hash)
  513. {
  514. printf("%sin my Fips callback, ok = %d, err = %d\n",
  515. ok ? info_prefix : err_prefix, ok, err);
  516. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  517. wc_GetErrorString(err));
  518. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  519. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  520. printf("%sIn core integrity hash check failure, copy above hash\n",
  521. err_prefix);
  522. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  523. err_prefix);
  524. }
  525. }
  526. #endif
  527. #ifdef WOLFSSL_STATIC_MEMORY
  528. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  529. #else
  530. #define HEAP_HINT NULL
  531. #endif /* WOLFSSL_STATIC_MEMORY */
  532. #ifndef EXIT_FAILURE
  533. #define EXIT_FAILURE 1
  534. #endif
  535. #undef LIBCALL_CHECK_RET
  536. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  537. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  538. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  539. #else
  540. #define LIBCALL_CHECK_RET(...) do { \
  541. int _libcall_ret = (__VA_ARGS__); \
  542. if (_libcall_ret < 0) { \
  543. printf("%s%s L%d error %d for \"%s\"\n", \
  544. err_prefix, __FILE__, __LINE__, \
  545. errno, #__VA_ARGS__); \
  546. XFFLUSH(stdout); \
  547. _exit(1); \
  548. } \
  549. } while(0)
  550. #endif
  551. #undef THREAD_CHECK_RET
  552. #define THREAD_CHECK_RET(...) do { \
  553. int _thread_ret = (__VA_ARGS__); \
  554. if (_thread_ret != 0) { \
  555. errno = _thread_ret; \
  556. printf("%s%s L%d error %d for \"%s\"\n", \
  557. err_prefix, __FILE__, __LINE__, \
  558. _thread_ret, #__VA_ARGS__); \
  559. XFFLUSH(stdout); \
  560. _exit(1); \
  561. } \
  562. } while(0)
  563. /* optional macro to add sleep between tests */
  564. #ifndef TEST_SLEEP
  565. /* stub the sleep macro */
  566. #define TEST_SLEEP() WC_DO_NOTHING
  567. #endif
  568. #define TEST_STRING "Everyone gets Friday off."
  569. #define TEST_STRING_SZ 25
  570. /* Bit values for each algorithm that is able to be benchmarked.
  571. * Common grouping of algorithms also.
  572. * Each algorithm has a unique value for its type e.g. cipher.
  573. */
  574. /* Cipher algorithms. */
  575. #define BENCH_AES_CBC 0x00000001
  576. #define BENCH_AES_GCM 0x00000002
  577. #define BENCH_AES_ECB 0x00000004
  578. #define BENCH_AES_XTS 0x00000008
  579. #define BENCH_AES_CTR 0x00000010
  580. #define BENCH_AES_CCM 0x00000020
  581. #define BENCH_CAMELLIA 0x00000100
  582. #define BENCH_ARC4 0x00000200
  583. #define BENCH_CHACHA20 0x00001000
  584. #define BENCH_CHACHA20_POLY1305 0x00002000
  585. #define BENCH_DES 0x00004000
  586. #define BENCH_AES_CFB 0x00010000
  587. #define BENCH_AES_OFB 0x00020000
  588. #define BENCH_AES_SIV 0x00040000
  589. #define BENCH_SM4_CBC 0x00080000
  590. #define BENCH_SM4_GCM 0x00100000
  591. #define BENCH_SM4_CCM 0x00200000
  592. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  593. /* Digest algorithms. */
  594. #define BENCH_MD5 0x00000001
  595. #define BENCH_POLY1305 0x00000002
  596. #define BENCH_SHA 0x00000004
  597. #define BENCH_SHA224 0x00000010
  598. #define BENCH_SHA256 0x00000020
  599. #define BENCH_SHA384 0x00000040
  600. #define BENCH_SHA512 0x00000080
  601. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  602. BENCH_SHA384 | BENCH_SHA512)
  603. #define BENCH_SHA3_224 0x00000100
  604. #define BENCH_SHA3_256 0x00000200
  605. #define BENCH_SHA3_384 0x00000400
  606. #define BENCH_SHA3_512 0x00000800
  607. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  608. BENCH_SHA3_384 | BENCH_SHA3_512)
  609. #define BENCH_SHAKE128 0x00001000
  610. #define BENCH_SHAKE256 0x00002000
  611. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  612. #define BENCH_RIPEMD 0x00004000
  613. #define BENCH_BLAKE2B 0x00008000
  614. #define BENCH_BLAKE2S 0x00010000
  615. #define BENCH_SM3 0x00020000
  616. /* MAC algorithms. */
  617. #define BENCH_CMAC 0x00000001
  618. #define BENCH_HMAC_MD5 0x00000002
  619. #define BENCH_HMAC_SHA 0x00000004
  620. #define BENCH_HMAC_SHA224 0x00000010
  621. #define BENCH_HMAC_SHA256 0x00000020
  622. #define BENCH_HMAC_SHA384 0x00000040
  623. #define BENCH_HMAC_SHA512 0x00000080
  624. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  625. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  626. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  627. #define BENCH_PBKDF2 0x00000100
  628. #define BENCH_SIPHASH 0x00000200
  629. /* KDF algorithms */
  630. #define BENCH_SRTP_KDF 0x00000001
  631. /* Asymmetric algorithms. */
  632. #define BENCH_RSA_KEYGEN 0x00000001
  633. #define BENCH_RSA 0x00000002
  634. #define BENCH_RSA_SZ 0x00000004
  635. #define BENCH_DH 0x00000010
  636. #define BENCH_ECC_MAKEKEY 0x00001000
  637. #define BENCH_ECC 0x00002000
  638. #define BENCH_ECC_ENCRYPT 0x00004000
  639. #define BENCH_ECC_ALL 0x00008000
  640. #define BENCH_CURVE25519_KEYGEN 0x00010000
  641. #define BENCH_CURVE25519_KA 0x00020000
  642. #define BENCH_ED25519_KEYGEN 0x00040000
  643. #define BENCH_ED25519_SIGN 0x00080000
  644. #define BENCH_CURVE448_KEYGEN 0x00100000
  645. #define BENCH_CURVE448_KA 0x00200000
  646. #define BENCH_ED448_KEYGEN 0x00400000
  647. #define BENCH_ED448_SIGN 0x00800000
  648. #define BENCH_ECC_P256 0x01000000
  649. #define BENCH_ECC_P384 0x02000000
  650. #define BENCH_ECC_P521 0x04000000
  651. #define BENCH_SM2 0x08000000
  652. #define BENCH_ECCSI_KEYGEN 0x00000020
  653. #define BENCH_ECCSI_PAIRGEN 0x00000040
  654. #define BENCH_ECCSI_VALIDATE 0x00000080
  655. #define BENCH_ECCSI 0x00000400
  656. #define BENCH_SAKKE_KEYGEN 0x10000000
  657. #define BENCH_SAKKE_RSKGEN 0x20000000
  658. #define BENCH_SAKKE_VALIDATE 0x40000000
  659. #define BENCH_SAKKE 0x80000000
  660. /* Post-Quantum Asymmetric algorithms. */
  661. #define BENCH_KYBER512 0x00000020
  662. #define BENCH_KYBER768 0x00000040
  663. #define BENCH_KYBER1024 0x00000080
  664. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  665. BENCH_KYBER1024)
  666. #define BENCH_ML_KEM_512 0x00000020
  667. #define BENCH_ML_KEM_768 0x00000040
  668. #define BENCH_ML_KEM_1024 0x00000080
  669. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  670. BENCH_ML_KEM_1024)
  671. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  672. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  673. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  674. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  675. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  676. #define BENCH_ML_DSA_44_SIGN 0x04000000
  677. #define BENCH_ML_DSA_65_SIGN 0x08000000
  678. #define BENCH_ML_DSA_87_SIGN 0x10000000
  679. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  680. BENCH_ML_DSA_65_SIGN | \
  681. BENCH_ML_DSA_87_SIGN)
  682. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  683. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  684. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  685. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  686. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  687. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  688. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  689. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  690. #define BENCH_LMS_HSS 0x00000001
  691. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  692. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  693. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  694. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  695. #ifndef NO_SHA256
  696. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  697. #elif defined(WOLFSSL_SHA512)
  698. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  699. #elif defined(WOLFSSL_SHAKE128)
  700. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  701. #elif defined(WOLFSSL_SHAKE256)
  702. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  703. #else
  704. #define BENCH_XMSS_XMSSMT 0x00000000
  705. #endif
  706. /* Other */
  707. #define BENCH_RNG 0x00000001
  708. #define BENCH_SCRYPT 0x00000002
  709. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  710. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  711. * static declaration of `bench_Usage_msg1`. */
  712. #if !defined(AES_AUTH_ADD_SZ) && \
  713. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  714. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  715. /* For STM32 use multiple of 4 to leverage crypto hardware
  716. * Xilinx Versal requires to use multiples of 16 bytes */
  717. #define AES_AUTH_ADD_SZ 16
  718. #endif
  719. #ifndef AES_AUTH_ADD_SZ
  720. #define AES_AUTH_ADD_SZ 13
  721. #endif
  722. #endif
  723. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  724. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  725. #define BENCH_PQ_STATEFUL_HBS
  726. #endif
  727. /* Benchmark all compiled in algorithms.
  728. * When 1, ignore other benchmark algorithm values.
  729. * 0, only benchmark algorithm values set.
  730. */
  731. static int bench_all = 1;
  732. /* Cipher algorithms to benchmark. */
  733. static word32 bench_cipher_algs = 0;
  734. /* Digest algorithms to benchmark. */
  735. static word32 bench_digest_algs = 0;
  736. /* MAC algorithms to benchmark. */
  737. static word32 bench_mac_algs = 0;
  738. /* KDF algorithms to benchmark. */
  739. static word32 bench_kdf_algs = 0;
  740. /* Asymmetric algorithms to benchmark. */
  741. static word32 bench_asym_algs = 0;
  742. /* Post-Quantum Asymmetric algorithms to benchmark. */
  743. static word32 bench_pq_asym_algs = 0;
  744. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  745. static word32 bench_pq_asym_algs2 = 0;
  746. /* Other cryptographic algorithms to benchmark. */
  747. static word32 bench_other_algs = 0;
  748. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  749. static word32 bench_pq_hash_sig_algs = 0;
  750. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  751. /* The mapping of command line option to bit values. */
  752. typedef struct bench_alg {
  753. /* Command line option string. */
  754. const char* str;
  755. /* Bit values to set. */
  756. word32 val;
  757. } bench_alg;
  758. #ifndef MAIN_NO_ARGS
  759. /* All recognized cipher algorithm choosing command line options. */
  760. static const bench_alg bench_cipher_opt[] = {
  761. { "-cipher", 0xffffffff },
  762. #ifdef HAVE_AES_CBC
  763. { "-aes-cbc", BENCH_AES_CBC },
  764. #endif
  765. #ifdef HAVE_AESGCM
  766. { "-aes-gcm", BENCH_AES_GCM },
  767. #endif
  768. #ifdef WOLFSSL_AES_DIRECT
  769. { "-aes-ecb", BENCH_AES_ECB },
  770. #endif
  771. #ifdef WOLFSSL_AES_XTS
  772. { "-aes-xts", BENCH_AES_XTS },
  773. #endif
  774. #ifdef WOLFSSL_AES_CFB
  775. { "-aes-cfb", BENCH_AES_CFB },
  776. #endif
  777. #ifdef WOLFSSL_AES_OFB
  778. { "-aes-ofb", BENCH_AES_OFB },
  779. #endif
  780. #ifdef WOLFSSL_AES_COUNTER
  781. { "-aes-ctr", BENCH_AES_CTR },
  782. #endif
  783. #ifdef HAVE_AESCCM
  784. { "-aes-ccm", BENCH_AES_CCM },
  785. #endif
  786. #ifdef WOLFSSL_AES_SIV
  787. { "-aes-siv", BENCH_AES_SIV },
  788. #endif
  789. #ifdef HAVE_CAMELLIA
  790. { "-camellia", BENCH_CAMELLIA },
  791. #endif
  792. #ifndef NO_RC4
  793. { "-arc4", BENCH_ARC4 },
  794. #endif
  795. #ifdef HAVE_CHACHA
  796. { "-chacha20", BENCH_CHACHA20 },
  797. #endif
  798. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  799. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  800. #endif
  801. #ifdef WOLFSSL_SM4_CBC
  802. { "-sm4-cbc", BENCH_SM4_CBC },
  803. #endif
  804. #ifdef WOLFSSL_SM4_GCM
  805. { "-sm4-gcm", BENCH_SM4_GCM },
  806. #endif
  807. #ifdef WOLFSSL_SM4_CCM
  808. { "-sm4-ccm", BENCH_SM4_CCM },
  809. #endif
  810. #ifdef WOLFSSL_SM4
  811. { "-sm4", BENCH_SM4 },
  812. #endif
  813. #ifndef NO_DES3
  814. { "-des", BENCH_DES },
  815. #endif
  816. { NULL, 0 }
  817. };
  818. /* All recognized digest algorithm choosing command line options. */
  819. static const bench_alg bench_digest_opt[] = {
  820. { "-digest", 0xffffffff },
  821. #ifndef NO_MD5
  822. { "-md5", BENCH_MD5 },
  823. #endif
  824. #ifdef HAVE_POLY1305
  825. { "-poly1305", BENCH_POLY1305 },
  826. #endif
  827. #ifndef NO_SHA
  828. { "-sha", BENCH_SHA },
  829. #endif
  830. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  831. || defined(WOLFSSL_SHA512)
  832. { "-sha2", BENCH_SHA2 },
  833. #endif
  834. #ifdef WOLFSSL_SHA224
  835. { "-sha224", BENCH_SHA224 },
  836. #endif
  837. #ifndef NO_SHA256
  838. { "-sha256", BENCH_SHA256 },
  839. #endif
  840. #ifdef WOLFSSL_SHA384
  841. { "-sha384", BENCH_SHA384 },
  842. #endif
  843. #ifdef WOLFSSL_SHA512
  844. { "-sha512", BENCH_SHA512 },
  845. #endif
  846. #ifdef WOLFSSL_SHA3
  847. { "-sha3", BENCH_SHA3 },
  848. #ifndef WOLFSSL_NOSHA3_224
  849. { "-sha3-224", BENCH_SHA3_224 },
  850. #endif
  851. #ifndef WOLFSSL_NOSHA3_256
  852. { "-sha3-256", BENCH_SHA3_256 },
  853. #endif
  854. #ifndef WOLFSSL_NOSHA3_384
  855. { "-sha3-384", BENCH_SHA3_384 },
  856. #endif
  857. #ifndef WOLFSSL_NOSHA3_512
  858. { "-sha3-512", BENCH_SHA3_512 },
  859. #endif
  860. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  861. { "-shake", BENCH_SHAKE },
  862. #endif
  863. #ifdef WOLFSSL_SHAKE128
  864. { "-shake128", BENCH_SHAKE128 },
  865. #endif
  866. #ifdef WOLFSSL_SHAKE256
  867. { "-shake256", BENCH_SHAKE256 },
  868. #endif
  869. #endif
  870. #ifdef WOLFSSL_SM3
  871. { "-sm3", BENCH_SM3 },
  872. #endif
  873. #ifdef WOLFSSL_RIPEMD
  874. { "-ripemd", BENCH_RIPEMD },
  875. #endif
  876. #ifdef HAVE_BLAKE2
  877. { "-blake2b", BENCH_BLAKE2B },
  878. #endif
  879. #ifdef HAVE_BLAKE2S
  880. { "-blake2s", BENCH_BLAKE2S },
  881. #endif
  882. { NULL, 0 }
  883. };
  884. /* All recognized MAC algorithm choosing command line options. */
  885. static const bench_alg bench_mac_opt[] = {
  886. { "-mac", 0xffffffff },
  887. #ifdef WOLFSSL_CMAC
  888. { "-cmac", BENCH_CMAC },
  889. #endif
  890. #ifndef NO_HMAC
  891. { "-hmac", BENCH_HMAC },
  892. #ifndef NO_MD5
  893. { "-hmac-md5", BENCH_HMAC_MD5 },
  894. #endif
  895. #ifndef NO_SHA
  896. { "-hmac-sha", BENCH_HMAC_SHA },
  897. #endif
  898. #ifdef WOLFSSL_SHA224
  899. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  900. #endif
  901. #ifndef NO_SHA256
  902. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  903. #endif
  904. #ifdef WOLFSSL_SHA384
  905. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  906. #endif
  907. #ifdef WOLFSSL_SHA512
  908. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  909. #endif
  910. #ifndef NO_PWDBASED
  911. { "-pbkdf2", BENCH_PBKDF2 },
  912. #endif
  913. #endif
  914. #ifdef WOLFSSL_SIPHASH
  915. { "-siphash", BENCH_SIPHASH },
  916. #endif
  917. { NULL, 0 }
  918. };
  919. /* All recognized KDF algorithm choosing command line options. */
  920. static const bench_alg bench_kdf_opt[] = {
  921. { "-kdf", 0xffffffff },
  922. #ifdef WC_SRTP_KDF
  923. { "-srtp-kdf", BENCH_SRTP_KDF },
  924. #endif
  925. { NULL, 0 }
  926. };
  927. /* All recognized asymmetric algorithm choosing command line options. */
  928. static const bench_alg bench_asym_opt[] = {
  929. { "-asym", 0xffffffff },
  930. #ifndef NO_RSA
  931. #ifdef WOLFSSL_KEY_GEN
  932. { "-rsa-kg", BENCH_RSA_KEYGEN },
  933. #endif
  934. { "-rsa", BENCH_RSA },
  935. #ifdef WOLFSSL_KEY_GEN
  936. { "-rsa-sz", BENCH_RSA_SZ },
  937. #endif
  938. #endif
  939. #ifndef NO_DH
  940. { "-dh", BENCH_DH },
  941. #endif
  942. #ifdef HAVE_ECC
  943. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  944. { "-ecc", BENCH_ECC },
  945. #ifdef HAVE_ECC_ENCRYPT
  946. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  947. #endif
  948. { "-ecc-all", BENCH_ECC_ALL },
  949. #endif
  950. #ifdef WOLFSSL_SM2
  951. { "-sm2", BENCH_SM2 },
  952. #endif
  953. #ifdef HAVE_CURVE25519
  954. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  955. #ifdef HAVE_CURVE25519_SHARED_SECRET
  956. { "-x25519", BENCH_CURVE25519_KA },
  957. #endif
  958. #endif
  959. #ifdef HAVE_ED25519
  960. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  961. { "-ed25519", BENCH_ED25519_SIGN },
  962. #endif
  963. #ifdef HAVE_CURVE448
  964. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  965. #ifdef HAVE_CURVE448_SHARED_SECRET
  966. { "-x448", BENCH_CURVE448_KA },
  967. #endif
  968. #endif
  969. #ifdef HAVE_ED448
  970. { "-ed448-kg", BENCH_ED448_KEYGEN },
  971. { "-ed448", BENCH_ED448_SIGN },
  972. #endif
  973. #ifdef WOLFCRYPT_HAVE_ECCSI
  974. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  975. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  976. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  977. { "-eccsi", BENCH_ECCSI },
  978. #endif
  979. #ifdef WOLFCRYPT_HAVE_SAKKE
  980. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  981. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  982. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  983. { "-sakke", BENCH_SAKKE },
  984. #endif
  985. { NULL, 0 }
  986. };
  987. /* All recognized other cryptographic algorithm choosing command line options.
  988. */
  989. static const bench_alg bench_other_opt[] = {
  990. { "-other", 0xffffffff },
  991. #ifndef WC_NO_RNG
  992. { "-rng", BENCH_RNG },
  993. #endif
  994. #ifdef HAVE_SCRYPT
  995. { "-scrypt", BENCH_SCRYPT },
  996. #endif
  997. { NULL, 0}
  998. };
  999. #endif /* MAIN_NO_ARGS */
  1000. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  1001. #if defined(BENCH_PQ_STATEFUL_HBS)
  1002. typedef struct bench_pq_hash_sig_alg {
  1003. /* Command line option string. */
  1004. const char* str;
  1005. /* Bit values to set. */
  1006. word32 val;
  1007. } bench_pq_hash_sig_alg;
  1008. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  1009. { "-pq_hash_sig", 0xffffffff},
  1010. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  1011. { "-lms_hss", BENCH_LMS_HSS},
  1012. #endif
  1013. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  1014. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  1015. #ifdef WC_XMSS_SHA256
  1016. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  1017. #endif
  1018. #ifdef WC_XMSS_SHA512
  1019. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  1020. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  1021. #endif
  1022. #endif
  1023. #ifdef WC_XMSS_SHAKE128
  1024. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  1025. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  1026. #endif
  1027. #endif
  1028. #ifdef WC_XMSS_SHAKE256
  1029. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  1030. #endif
  1031. #endif
  1032. { NULL, 0}
  1033. };
  1034. #endif /* BENCH_PQ_STATEFUL_HBS */
  1035. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1036. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1037. /* The post-quantum-specific mapping of command line option to bit values and
  1038. * OQS name. */
  1039. typedef struct bench_pq_alg {
  1040. /* Command line option string. */
  1041. const char* str;
  1042. /* Bit values to set. */
  1043. word32 val;
  1044. } bench_pq_alg;
  1045. /* All recognized post-quantum asymmetric algorithm choosing command line
  1046. * options. */
  1047. static const bench_pq_alg bench_pq_asym_opt[] = {
  1048. { "-pq", 0xffffffff },
  1049. #ifdef WOLFSSL_HAVE_KYBER
  1050. { "-kyber", BENCH_KYBER },
  1051. { "-kyber512", BENCH_KYBER512 },
  1052. { "-kyber768", BENCH_KYBER768 },
  1053. { "-kyber1024", BENCH_KYBER1024 },
  1054. { "-ml-kem", BENCH_ML_KEM },
  1055. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1056. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1057. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1058. #endif
  1059. #if defined(HAVE_FALCON)
  1060. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1061. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1062. #endif
  1063. #if defined(HAVE_DILITHIUM)
  1064. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1065. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1066. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1067. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1068. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1069. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1070. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1071. #endif
  1072. { NULL, 0 }
  1073. };
  1074. #if defined(HAVE_SPHINCS)
  1075. /* All recognized post-quantum asymmetric algorithm choosing command line
  1076. * options. (Part 2) */
  1077. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1078. { "-pq", 0xffffffff },
  1079. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1080. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1081. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1082. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1083. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1084. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1085. { NULL, 0, }
  1086. };
  1087. #endif /* HAVE_SPHINCS */
  1088. #endif
  1089. #ifdef HAVE_WNR
  1090. const char* wnrConfigFile = "wnr-example.conf";
  1091. #endif
  1092. #if defined(WOLFSSL_MDK_ARM)
  1093. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1094. #define fopen wolfSSL_fopen
  1095. #endif
  1096. static int lng_index = 0;
  1097. #ifndef NO_MAIN_DRIVER
  1098. #ifndef MAIN_NO_ARGS
  1099. static const char* bench_Usage_msg1[][25] = {
  1100. /* 0 English */
  1101. { "-? <num> Help, print this usage\n",
  1102. " 0: English, 1: Japanese\n",
  1103. "-csv Print terminal output in csv format\n",
  1104. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1105. "-no_aad No additional authentication data passed.\n",
  1106. "-aad_size <num> With <num> bytes of AAD.\n",
  1107. ("-all_aad With AAD length of 0, "
  1108. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1109. " and\n"
  1110. " (if set via -aad_size) <aad_size> bytes.\n"
  1111. ),
  1112. "-dgst_full Full digest operation performed.\n",
  1113. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1114. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1115. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1116. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1117. "-p256 Measure ECC using P-256 curve.\n",
  1118. "-p384 Measure ECC using P-384 curve.\n",
  1119. "-p521 Measure ECC using P-521 curve.\n",
  1120. "-ecc-all Bench all enabled ECC curves.\n",
  1121. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1122. ("-lng <num> Display benchmark result by specified language.\n"
  1123. " 0: English, 1: Japanese\n"
  1124. ),
  1125. "<num> Size of block in bytes\n",
  1126. ("-blocks <num> Number of blocks. Can be used together with the "
  1127. "'Size of block'\n"
  1128. " option, but must be used after that one.\n"
  1129. ),
  1130. "-threads <num> Number of threads to run\n",
  1131. "-print Show benchmark stats summary\n",
  1132. "-hash_input <file> Input data to use for hash benchmarking\n",
  1133. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1134. "-min_runs <num> Specify minimum number of operation runs\n"
  1135. },
  1136. #ifndef NO_MULTIBYTE_PRINT
  1137. /* 1 Japanese */
  1138. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1139. " 0: 英語、 1: 日本語\n",
  1140. "-csv csv 形式で端末に出力します。\n",
  1141. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1142. "-no_aad 追加の認証データを使用しません.\n",
  1143. "-aad_size <num> TBD.\n",
  1144. "-all_aad TBD.\n",
  1145. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1146. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1147. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1148. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1149. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1150. "-p256 Measure ECC using P-256 curve.\n",
  1151. "-p384 Measure ECC using P-384 curve.\n",
  1152. "-p521 Measure ECC using P-521 curve.\n",
  1153. "-ecc-all Bench all enabled ECC curves.\n",
  1154. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1155. " 利用可能なアルゴリズムは下記を含みます:\n"
  1156. ),
  1157. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1158. " 0: 英語、 1: 日本語\n"
  1159. ),
  1160. "<num> ブロックサイズをバイト単位で指定します。\n",
  1161. "-blocks <num> TBD.\n",
  1162. "-threads <num> 実行するスレッド数\n",
  1163. "-print ベンチマーク統計の要約を表示する\n",
  1164. /* TODO: translate below */
  1165. "-hash_input <file> Input data to use for hash benchmarking\n",
  1166. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1167. "-min_runs <num> Specify minimum number of operation runs\n"
  1168. },
  1169. #endif
  1170. };
  1171. #endif /* MAIN_NO_ARGS */
  1172. #endif
  1173. static const char* bench_result_words1[][4] = {
  1174. { "took",
  1175. #ifdef BENCH_MICROSECOND
  1176. "microseconds"
  1177. #else
  1178. "seconds"
  1179. #endif
  1180. , "Cycles per byte", NULL }, /* 0 English */
  1181. #ifndef NO_MULTIBYTE_PRINT
  1182. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1183. #endif
  1184. };
  1185. #if !defined(NO_RSA) || \
  1186. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1187. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1188. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1189. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1190. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1191. static const char* bench_desc_words[][15] = {
  1192. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1193. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1194. #ifndef NO_MULTIBYTE_PRINT
  1195. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1196. #endif
  1197. };
  1198. #endif
  1199. #ifdef MULTI_VALUE_STATISTICS
  1200. static const char* bench_result_words3[][5] = {
  1201. /* 0 English */
  1202. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1203. /* TODO: Add japenese version */
  1204. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1205. };
  1206. #endif
  1207. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1208. #define HAVE_GET_CYCLES
  1209. static WC_INLINE word64 get_intel_cycles(void);
  1210. static THREAD_LS_T word64 total_cycles;
  1211. #define INIT_CYCLE_COUNTER
  1212. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1213. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1214. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1215. #define SHOW_INTEL_CYCLES(b, n, s) \
  1216. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1217. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1218. bench_result_words1[lng_index][2], \
  1219. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1220. (double)total_cycles / ((word64)count*(s))))
  1221. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1222. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1223. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1224. (double)total_cycles / ((word64)count*(s))))
  1225. #elif defined(LINUX_CYCLE_COUNT)
  1226. #include <linux/perf_event.h>
  1227. #include <sys/syscall.h>
  1228. #include <unistd.h>
  1229. static THREAD_LS_T word64 begin_cycles;
  1230. static THREAD_LS_T word64 total_cycles;
  1231. static THREAD_LS_T int cycles = -1;
  1232. static THREAD_LS_T struct perf_event_attr atr;
  1233. #define INIT_CYCLE_COUNTER do { \
  1234. atr.type = PERF_TYPE_HARDWARE; \
  1235. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1236. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1237. } while (0);
  1238. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1239. #define END_INTEL_CYCLES do { \
  1240. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1241. total_cycles = total_cycles - begin_cycles; \
  1242. } while (0);
  1243. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1244. #define SHOW_INTEL_CYCLES(b, n, s) \
  1245. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1246. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1247. bench_result_words1[lng_index][2], \
  1248. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1249. (count*s)))
  1250. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1251. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1252. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1253. / (count*s)))
  1254. #elif defined(SYNERGY_CYCLE_COUNT)
  1255. #include "hal_data.h"
  1256. static THREAD_LS_T word64 begin_cycles;
  1257. static THREAD_LS_T word64 total_cycles;
  1258. #define INIT_CYCLE_COUNTER
  1259. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1260. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1261. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1262. #define SHOW_INTEL_CYCLES(b, n, s) \
  1263. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1264. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1265. bench_result_words1[lng_index][2], \
  1266. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1267. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1268. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1269. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1270. #elif defined(WOLFSSL_ESPIDF)
  1271. /* TAG for ESP_LOGx() */
  1272. static const char* TAG = "wolfssl_benchmark";
  1273. static THREAD_LS_T word64 begin_cycles = 0;
  1274. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1275. static THREAD_LS_T word64 end_cycles = 0;
  1276. static THREAD_LS_T word64 total_cycles = 0;
  1277. /* the return value, as a global var */
  1278. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1279. /* the last value seen, adjusted for an overflow, as a global var */
  1280. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1281. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1282. /* esp_get_cpu_benchmark_cycles(void):
  1283. *
  1284. * Architecture-independant CPU clock counter.
  1285. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1286. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1287. /* Some vars for debugging, compare ticks to cycles */
  1288. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1289. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1290. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1291. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1292. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1293. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1294. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1295. #if ESP_IDF_VERSION_MAJOR >= 5
  1296. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1297. #define HAVE_GET_CYCLES
  1298. #define INIT_CYCLE_COUNTER do { \
  1299. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1300. esp_cpu_set_cycle_count(0); \
  1301. } while (0);
  1302. #else
  1303. #define HAVE_GET_CYCLES
  1304. #define INIT_CYCLE_COUNTER do { \
  1305. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1306. } while (0);
  1307. #endif
  1308. #define BEGIN_ESP_CYCLES do { \
  1309. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1310. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1311. begin_cycles_ticks = xTaskGetTickCount(); \
  1312. } while (0);
  1313. /* since it rolls over, we have something that will tolerate one */
  1314. #define END_ESP_CYCLES \
  1315. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1316. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1317. end_cycles, \
  1318. begin_cycles \
  1319. ); \
  1320. total_cycles = (end_cycles - begin_cycles);
  1321. #define SHOW_ESP_CYCLES(b, n, s) \
  1322. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1323. " %s = " FLT_FMT_PREC2 "\n", \
  1324. bench_result_words1[lng_index][2], \
  1325. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1326. )
  1327. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1328. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1329. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1330. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1331. /* 64 bit, unisgned, absolute difference
  1332. * used in CPU cycle counter debug calcs. */
  1333. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1334. {
  1335. uint64_t ret;
  1336. ret = (x > y) ? (x - y) : (y - x);
  1337. return ret;
  1338. }
  1339. #endif
  1340. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1341. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1342. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1343. ** at least once during full benchmark tests.
  1344. **
  1345. ** To test timing overflow, add a delay longer than max cycles:
  1346. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1347. */
  1348. uint64_t esp_get_cycle_count_ex()
  1349. {
  1350. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1351. /* unsigned int max = 4,294,967,295 */
  1352. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1353. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1354. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1355. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1356. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1357. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1358. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1359. #endif
  1360. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1361. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1362. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1363. * (current - last) */
  1364. #endif
  1365. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1366. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1367. defined(CONFIG_IDF_TARGET_ESP32C6)
  1368. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1369. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1370. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1371. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1372. #if ESP_IDF_VERSION_MAJOR >= 5
  1373. thisVal = esp_cpu_get_cycle_count();
  1374. #else
  1375. thisVal = cpu_hal_get_cycle_count();
  1376. #endif
  1377. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1378. thisVal = esp_cpu_get_cycle_count();
  1379. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  1380. thisVal = esp_timer_get_time();
  1381. #else
  1382. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1383. * Calling current_time(1) to reset time causes thisVal overflow,
  1384. * on Xtensa, but not on RISC-V architecture. See also, below */
  1385. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1386. #ifndef configCPU_CLOCK_HZ
  1387. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1388. #define configCPU_CLOCK_HZ \
  1389. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1390. #endif
  1391. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1392. thisVal = (uint64_t)xTaskGetTickCount() *
  1393. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1394. #elif defined(__XTENSA__)
  1395. thisVal = esp_cpu_get_cycle_count();
  1396. #else
  1397. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1398. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1399. #endif
  1400. #endif
  1401. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1402. {
  1403. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1404. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1405. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1406. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1407. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1408. ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
  1409. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1410. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1411. }
  1412. #endif
  1413. /* If either thisVal is smaller than last (overflow), and/or the
  1414. * expected value calculated from FreeRTOS tick difference that would
  1415. * have never fit into an unsigned 32 bit integer anyhow... then we
  1416. * need to adjust thisVal to save. */
  1417. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1418. {
  1419. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1420. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1421. **
  1422. ** NOTE for long duration between calls with multiple overflows:
  1423. **
  1424. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1425. **
  1426. ** At this time no single test overflows. This is currently only a
  1427. ** concern for cumulative counts over multiple tests. As long
  1428. ** as well call xthal_get_ccount_ex() with no more than one
  1429. ** overflow CPU tick count, all will be well.
  1430. */
  1431. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1432. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1433. "(%llu < %llu) adding UINT_MAX = %llu.",
  1434. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1435. #endif
  1436. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1437. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1438. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1439. #endif
  1440. /* double check expected diff calc */
  1441. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1442. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1443. expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  1444. * MILLION_VALUE)
  1445. * tickDiff / configTICK_RATE_HZ;
  1446. #else
  1447. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1448. * tickDiff / configTICK_RATE_HZ;
  1449. #endif
  1450. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1451. #endif
  1452. if (expected_diff > UINT_MAX) {
  1453. /* The number of cycles expected from FreeRTOS ticks is
  1454. * greater than the maximum size of an unsigned 32-bit
  1455. * integer, meaning multiple overflows occurred. */
  1456. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1457. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1458. #endif
  1459. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1460. }
  1461. else {
  1462. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1463. }
  1464. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1465. {
  1466. tickBeginDiff = tickCount - begin_cycles_ticks;
  1467. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1468. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1469. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1470. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1471. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1472. }
  1473. #endif
  1474. }
  1475. else {
  1476. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1477. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1478. #endif
  1479. } /* if thisVal adjustment check */
  1480. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1481. if (thisTimerVal < _esp_cpu_timer_last)
  1482. {
  1483. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1484. "adding %ull", UINT_MAX);
  1485. thisTimerVal += (word64)UINT_MAX;
  1486. }
  1487. /* Check an alternate counter using a timer */
  1488. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1489. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1490. /* Adjust our actual returned value that takes into account overflow,
  1491. * increment 64 bit extended total by this 32 bit differential: */
  1492. thisIncrement = (thisVal - _esp_cpu_count_last);
  1493. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1494. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1495. #endif
  1496. /* Add our adjustment, taking into account overflows (see above) */
  1497. _esp_get_cycle_count_ex += thisIncrement;
  1498. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1499. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1500. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1501. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1502. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1503. /* all of this took some time, so reset the "last seen" value
  1504. * for the next measurement. */
  1505. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1506. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1507. defined(CONFIG_IDF_TARGET_ESP32C6)
  1508. {
  1509. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1510. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1511. &_esp_cpu_timer_last));
  1512. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1513. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1514. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1515. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1516. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1517. #if ESP_IDF_VERSION_MAJOR >= 5
  1518. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1519. #else
  1520. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  1521. #endif
  1522. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1523. }
  1524. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1525. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1526. #else
  1527. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1528. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1529. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1530. * or thisVal = xthal_get_ccount(); */
  1531. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1532. /* There's no CPU counter on the ESP8266, so we'll estimate
  1533. * cycles based on defined CPU frequency from sdkconfig and
  1534. * the RTOS tick frequency */
  1535. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1536. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1537. #elif ESP_IDF_VERSION_MAJOR < 5
  1538. _esp_cpu_count_last = xthal_get_ccount();
  1539. #else
  1540. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1541. #endif
  1542. #endif
  1543. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1544. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1545. #endif
  1546. /* Return the 64 bit extended total from 32 bit counter. */
  1547. return _esp_get_cycle_count_ex;
  1548. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1549. /* implement other architecture cycle counters here */
  1550. #else
  1551. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1552. #undef HAVE_GET_CYCLES
  1553. #define INIT_CYCLE_COUNTER
  1554. #define BEGIN_INTEL_CYCLES
  1555. #define END_INTEL_CYCLES
  1556. #ifdef MULTI_VALUE_STATISTICS
  1557. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1558. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1559. #else
  1560. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1561. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1562. #endif
  1563. #endif
  1564. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1565. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1566. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1567. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1568. #endif
  1569. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1570. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1571. !defined(NO_DH)
  1572. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1573. #include <wolfssl/certs_test.h>
  1574. #endif
  1575. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1576. #include <wolfssl/wolfcrypt/blake2.h>
  1577. #endif
  1578. #ifdef _MSC_VER
  1579. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1580. #pragma warning(disable: 4996)
  1581. #endif
  1582. #ifdef WOLFSSL_CURRTIME_REMAP
  1583. #define current_time WOLFSSL_CURRTIME_REMAP
  1584. #else
  1585. double current_time(int reset);
  1586. #endif
  1587. #ifdef LINUX_RUSAGE_UTIME
  1588. static void check_for_excessive_stime(const char *desc,
  1589. const char *desc_extra);
  1590. #endif
  1591. #if !defined(WC_NO_RNG) && \
  1592. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1593. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1594. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1595. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1596. || defined(WOLFSSL_HAVE_KYBER))
  1597. #define HAVE_LOCAL_RNG
  1598. static THREAD_LS_T WC_RNG gRng;
  1599. #define GLOBAL_RNG &gRng
  1600. #else
  1601. #define GLOBAL_RNG NULL
  1602. #endif
  1603. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1604. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1605. defined(HAVE_ECC) || !defined(NO_DH) || \
  1606. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1607. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1608. #define BENCH_ASYM
  1609. #endif
  1610. #if defined(BENCH_ASYM)
  1611. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1612. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1613. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1614. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1615. static const char* bench_result_words2[][5] = {
  1616. #ifdef BENCH_MICROSECOND
  1617. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1618. for μsec */
  1619. #else
  1620. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1621. #endif
  1622. #ifndef NO_MULTIBYTE_PRINT
  1623. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1624. #endif
  1625. };
  1626. #endif
  1627. #endif
  1628. #ifdef WOLFSSL_CAAM
  1629. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1630. #ifdef WOLFSSL_SECO_CAAM
  1631. #define SECO_MAX_UPDATES 10000
  1632. #define SECO_BENCHMARK_NONCE 0x7777
  1633. #define SECO_KEY_STORE_ID 1
  1634. #endif
  1635. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1636. #else
  1637. #ifdef WC_USE_DEVID
  1638. static THREAD_LS_T int devId = WC_USE_DEVID;
  1639. #else
  1640. static THREAD_LS_T int devId = INVALID_DEVID;
  1641. #endif
  1642. #endif
  1643. /* Asynchronous helper macros */
  1644. #ifdef WC_ENABLE_BENCH_THREADING
  1645. typedef struct ThreadData {
  1646. pthread_t thread_id;
  1647. } ThreadData;
  1648. static ThreadData* g_threadData;
  1649. static volatile int g_threadCount;
  1650. #endif
  1651. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1652. #ifndef NO_HW_BENCH
  1653. #define BENCH_DEVID
  1654. #endif
  1655. #ifndef HAVE_RENESAS_SYNC
  1656. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1657. #else
  1658. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1659. #endif
  1660. #else
  1661. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1662. #endif
  1663. #ifdef WOLFSSL_ASYNC_CRYPT
  1664. static WOLF_EVENT_QUEUE eventQueue;
  1665. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1666. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1667. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1668. int callAgain, int* times, int limit, int* pending)
  1669. {
  1670. int allowNext = 0;
  1671. /* this state can be set from a different thread */
  1672. WOLF_EVENT_STATE state = asyncDev->event.state;
  1673. /* if algo doesn't require calling again then use this flow */
  1674. if (state == WOLF_EVENT_STATE_DONE) {
  1675. if (callAgain) {
  1676. /* needs called again, so allow it and handle completion in
  1677. * bench_async_handle */
  1678. allowNext = 1;
  1679. }
  1680. else {
  1681. *ret = asyncDev->event.ret;
  1682. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1683. (*times)++;
  1684. if (*pending > 0) /* to support case where async blocks */
  1685. (*pending)--;
  1686. if ((*times + *pending) < limit)
  1687. allowNext = 1;
  1688. }
  1689. }
  1690. /* if slot is available and we haven't reached limit, start another */
  1691. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1692. allowNext = 1;
  1693. }
  1694. return allowNext;
  1695. }
  1696. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1697. int callAgain, int* times, int* pending)
  1698. {
  1699. WOLF_EVENT_STATE state = asyncDev->event.state;
  1700. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1701. if (state == WOLF_EVENT_STATE_DONE) {
  1702. *ret = asyncDev->event.ret;
  1703. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1704. (*times)++;
  1705. (*pending)--;
  1706. }
  1707. else {
  1708. (*pending)++;
  1709. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1710. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1711. }
  1712. }
  1713. else if (*ret >= 0) {
  1714. *ret = asyncDev->event.ret;
  1715. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1716. (*times)++;
  1717. if (*pending > 0) /* to support case where async blocks */
  1718. (*pending)--;
  1719. }
  1720. return (*ret >= 0) ? 1 : 0;
  1721. }
  1722. static WC_INLINE int bench_async_poll(int* pending)
  1723. {
  1724. int ret, asyncDone = 0;
  1725. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1726. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1727. if (ret != 0) {
  1728. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1729. return ret;
  1730. }
  1731. if (asyncDone == 0) {
  1732. #ifndef WC_NO_ASYNC_THREADING
  1733. /* give time to other threads */
  1734. wc_AsyncThreadYield();
  1735. #endif
  1736. }
  1737. (void)pending;
  1738. return asyncDone;
  1739. }
  1740. #else
  1741. #define BENCH_MAX_PENDING 1
  1742. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1743. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1744. int callAgain, int* times, int limit, int* pending)
  1745. {
  1746. (void)ret;
  1747. (void)asyncDev;
  1748. (void)callAgain;
  1749. (void)times;
  1750. (void)limit;
  1751. (void)pending;
  1752. return 1;
  1753. }
  1754. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1755. int callAgain, int* times, int* pending)
  1756. {
  1757. (void)asyncDev;
  1758. (void)callAgain;
  1759. (void)pending;
  1760. if (*ret >= 0) {
  1761. /* operation completed */
  1762. (*times)++;
  1763. return 1;
  1764. }
  1765. return 0;
  1766. }
  1767. #define bench_async_poll(p) WC_DO_NOTHING
  1768. #endif /* WOLFSSL_ASYNC_CRYPT */
  1769. /* maximum runtime for each benchmark */
  1770. #ifndef BENCH_MIN_RUNTIME_SEC
  1771. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1772. #endif
  1773. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1774. #define AES_AUTH_TAG_SZ 16
  1775. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1776. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1777. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1778. #if !defined(NO_MAIN_DRIVER)
  1779. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1780. #else
  1781. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1782. #endif
  1783. #endif
  1784. #define AES_AAD_STRING(s) \
  1785. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1786. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1787. enum en_aad_options {
  1788. AAD_SIZE_DEFAULT = 0x1U,
  1789. AAD_SIZE_ZERO = 0x2U,
  1790. AAD_SIZE_CUSTOM = 0x4U,
  1791. };
  1792. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1793. static word32 aes_aad_size = 0;
  1794. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1795. {
  1796. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1797. word32 options = aes_aad_options;
  1798. while(options) {
  1799. if (options & AAD_SIZE_DEFAULT) {
  1800. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1801. options &= ~(word32)AAD_SIZE_DEFAULT;
  1802. }
  1803. else if (options & AAD_SIZE_ZERO) {
  1804. aesAuthAddSz = 0;
  1805. options &= ~(word32)AAD_SIZE_ZERO;
  1806. }
  1807. else if (options & AAD_SIZE_CUSTOM) {
  1808. aesAuthAddSz = aes_aad_size;
  1809. options &= ~(word32)AAD_SIZE_CUSTOM;
  1810. }
  1811. fn(i);
  1812. aesAuthAddSz = aesAuthAddSz_orig;
  1813. }
  1814. }
  1815. #endif
  1816. #ifndef BENCH_CIPHER_ADD
  1817. #define BENCH_CIPHER_ADD 0
  1818. #endif
  1819. /* use kB instead of mB for embedded benchmarking */
  1820. #ifdef BENCH_EMBEDDED
  1821. #ifndef BENCH_NTIMES
  1822. #define BENCH_NTIMES 2
  1823. #endif
  1824. #ifndef BENCH_AGREETIMES
  1825. #define BENCH_AGREETIMES 2
  1826. #endif
  1827. enum BenchmarkBounds {
  1828. scryptCnt = 1,
  1829. ntimes = BENCH_NTIMES,
  1830. genTimes = BENCH_MAX_PENDING,
  1831. agreeTimes = BENCH_AGREETIMES
  1832. };
  1833. /* how many kB to test (en/de)cryption */
  1834. #define NUM_BLOCKS 25
  1835. #define BENCH_SIZE (1024uL)
  1836. #else
  1837. #ifndef BENCH_NTIMES
  1838. #define BENCH_NTIMES 100
  1839. #endif
  1840. #ifndef BENCH_AGREETIMES
  1841. #define BENCH_AGREETIMES 100
  1842. #endif
  1843. enum BenchmarkBounds {
  1844. scryptCnt = 10,
  1845. ntimes = BENCH_NTIMES,
  1846. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1847. agreeTimes = BENCH_AGREETIMES
  1848. };
  1849. /* how many megs to test (en/de)cryption */
  1850. #define NUM_BLOCKS 5
  1851. #define BENCH_SIZE (1024*1024uL)
  1852. #endif
  1853. static int numBlocks = NUM_BLOCKS;
  1854. static word32 bench_size = BENCH_SIZE;
  1855. static int base2 = 1;
  1856. static int digest_stream = 1;
  1857. #ifdef HAVE_CHACHA
  1858. static int encrypt_only = 0;
  1859. #endif
  1860. #ifdef HAVE_AES_CBC
  1861. static int cipher_same_buffer = 0;
  1862. #endif
  1863. #ifdef MULTI_VALUE_STATISTICS
  1864. static int minimum_runs = 0;
  1865. #endif
  1866. #ifndef NO_RSA
  1867. /* Don't measure RSA sign/verify by default */
  1868. static int rsa_sign_verify = 0;
  1869. #endif
  1870. #ifndef NO_DH
  1871. /* Use the FFDHE parameters */
  1872. static int use_ffdhe = 0;
  1873. #endif
  1874. /* Don't print out in CSV format by default */
  1875. static int csv_format = 0;
  1876. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1877. /* Versal PLM maybe prints an error message to the same console.
  1878. * In order to not mix those outputs up, sleep a little while
  1879. * before erroring out.
  1880. */
  1881. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1882. #else
  1883. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1884. #endif
  1885. /* globals for cipher tests */
  1886. static THREAD_LS_T byte* bench_plain = NULL;
  1887. static THREAD_LS_T byte* bench_cipher = NULL;
  1888. #ifndef NO_FILESYSTEM
  1889. static THREAD_LS_T char* hash_input = NULL;
  1890. static THREAD_LS_T char* cipher_input = NULL;
  1891. #endif
  1892. static const XGEN_ALIGN byte bench_key_buf[] =
  1893. {
  1894. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1895. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1896. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1897. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1898. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1899. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1900. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1901. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1902. };
  1903. static const XGEN_ALIGN byte bench_iv_buf[] =
  1904. {
  1905. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1906. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1907. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1908. };
  1909. static THREAD_LS_T byte* bench_key = NULL;
  1910. static THREAD_LS_T byte* bench_iv = NULL;
  1911. #ifdef HAVE_RENESAS_SYNC
  1912. static THREAD_LS_T byte* bench_key1 = NULL;
  1913. static THREAD_LS_T byte* bench_key2 = NULL;
  1914. #endif
  1915. #ifdef WOLFSSL_STATIC_MEMORY
  1916. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1917. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1918. #elif defined(BENCH_EMBEDDED)
  1919. static byte gBenchMemory[50000];
  1920. #else
  1921. static byte gBenchMemory[400000];
  1922. #endif
  1923. #endif
  1924. /* This code handles cases with systems where static (non cost) ram variables
  1925. aren't properly initialized with data */
  1926. static void benchmark_static_init(int force)
  1927. {
  1928. static int gBenchStaticInit = 0;
  1929. if (gBenchStaticInit == 0 || force) {
  1930. gBenchStaticInit = 1;
  1931. /* Init static variables */
  1932. numBlocks = NUM_BLOCKS;
  1933. bench_size = BENCH_SIZE;
  1934. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1935. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1936. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1937. aes_aad_size = 0;
  1938. #endif
  1939. base2 = 1;
  1940. digest_stream = 1;
  1941. #ifdef MULTI_VALUE_STATISTICS
  1942. minimum_runs = 0;
  1943. #endif
  1944. bench_all = 1;
  1945. bench_cipher_algs = 0;
  1946. bench_digest_algs = 0;
  1947. bench_mac_algs = 0;
  1948. bench_kdf_algs = 0;
  1949. bench_asym_algs = 0;
  1950. bench_pq_asym_algs = 0;
  1951. bench_other_algs = 0;
  1952. bench_pq_hash_sig_algs = 0;
  1953. csv_format = 0;
  1954. }
  1955. }
  1956. /*****************************************************************************/
  1957. /* Begin Stats Functions */
  1958. /*****************************************************************************/
  1959. typedef enum bench_stat_type {
  1960. BENCH_STAT_ASYM,
  1961. BENCH_STAT_SYM,
  1962. BENCH_STAT_IGNORE,
  1963. } bench_stat_type_t;
  1964. #ifdef WC_BENCH_TRACK_STATS
  1965. static int gPrintStats = 0;
  1966. #ifdef WC_ENABLE_BENCH_THREADING
  1967. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1968. #endif
  1969. #ifndef BENCH_MAX_NAME_SZ
  1970. #define BENCH_MAX_NAME_SZ 24
  1971. #endif
  1972. typedef struct bench_stats {
  1973. struct bench_stats* next;
  1974. struct bench_stats* prev;
  1975. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1976. const char* desc;
  1977. double perfsec;
  1978. int strength;
  1979. int useDeviceID;
  1980. int finishCount;
  1981. bench_stat_type_t type;
  1982. int lastRet;
  1983. const char* perftype;
  1984. } bench_stats_t;
  1985. static bench_stats_t* bench_stats_head;
  1986. static bench_stats_t* bench_stats_tail;
  1987. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1988. const char* algo, int strength, const char* desc, int useDeviceID,
  1989. double perfsec, const char* perftype, int ret)
  1990. {
  1991. bench_stats_t* bstat = NULL;
  1992. #ifdef WC_ENABLE_BENCH_THREADING
  1993. /* protect bench_stats_head and bench_stats_tail access */
  1994. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  1995. #endif
  1996. if (algo != NULL) {
  1997. /* locate existing in list */
  1998. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  1999. /* match based on algo, strength and desc */
  2000. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  2001. bstat->strength == strength &&
  2002. bstat->desc == desc &&
  2003. bstat->useDeviceID == useDeviceID) {
  2004. break;
  2005. }
  2006. }
  2007. }
  2008. if (bstat == NULL) {
  2009. /* allocate new and put on list */
  2010. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  2011. DYNAMIC_TYPE_INFO);
  2012. if (bstat) {
  2013. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  2014. /* add to list */
  2015. bstat->next = NULL;
  2016. if (bench_stats_tail == NULL) {
  2017. bench_stats_head = bstat;
  2018. }
  2019. else {
  2020. bench_stats_tail->next = bstat;
  2021. bstat->prev = bench_stats_tail;
  2022. }
  2023. bench_stats_tail = bstat; /* add to the end either way */
  2024. }
  2025. }
  2026. if (bstat) {
  2027. bstat->type = type;
  2028. if (algo != NULL)
  2029. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  2030. bstat->strength = strength;
  2031. bstat->desc = desc;
  2032. bstat->useDeviceID = useDeviceID;
  2033. bstat->perfsec += perfsec;
  2034. bstat->finishCount++;
  2035. bstat->perftype = perftype;
  2036. if (bstat->lastRet > ret)
  2037. bstat->lastRet = ret; /* track last error */
  2038. }
  2039. #ifdef WC_ENABLE_BENCH_THREADING
  2040. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2041. #endif
  2042. return bstat;
  2043. }
  2044. void bench_stats_print(void)
  2045. {
  2046. bench_stats_t* bstat;
  2047. int digits;
  2048. #ifdef WC_ENABLE_BENCH_THREADING
  2049. /* protect bench_stats_head and bench_stats_tail access */
  2050. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2051. #endif
  2052. #ifdef BENCH_MICROSECOND
  2053. digits = 5;
  2054. #else
  2055. digits = 3;
  2056. #endif
  2057. for (bstat = bench_stats_head; bstat != NULL; ) {
  2058. if (bstat->type == BENCH_STAT_SYM) {
  2059. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2060. "\n", bstat->desc,
  2061. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2062. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2063. base2 ? "MB" : "mB");
  2064. }
  2065. else {
  2066. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2067. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2068. bstat->algo, bstat->strength, bstat->desc,
  2069. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2070. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2071. }
  2072. bstat = bstat->next;
  2073. }
  2074. #ifdef WC_ENABLE_BENCH_THREADING
  2075. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2076. #endif
  2077. }
  2078. #endif /* WC_BENCH_TRACK_STATS */
  2079. static WC_INLINE void bench_stats_init(void)
  2080. {
  2081. #ifdef WC_BENCH_TRACK_STATS
  2082. bench_stats_head = NULL;
  2083. bench_stats_tail = NULL;
  2084. #endif
  2085. INIT_CYCLE_COUNTER
  2086. }
  2087. static WC_INLINE void bench_stats_start(int* count, double* start)
  2088. {
  2089. *count = 0;
  2090. *start = current_time(1);
  2091. #ifdef WOLFSSL_ESPIDF
  2092. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2093. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
  2094. ", start=" FLT_FMT,
  2095. total_cycles, FLT_FMT_ARGS(*start) );
  2096. #endif
  2097. BEGIN_ESP_CYCLES
  2098. #else
  2099. BEGIN_INTEL_CYCLES
  2100. #endif
  2101. }
  2102. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2103. #define bench_stats_start(count, start) do { \
  2104. SAVE_VECTOR_REGISTERS(pr_err( \
  2105. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2106. return; ); \
  2107. bench_stats_start(count, start); \
  2108. } while (0)
  2109. #endif
  2110. static WC_INLINE int bench_stats_check(double start)
  2111. {
  2112. int ret = 0;
  2113. double this_current_time = 0.0;
  2114. this_current_time = current_time(0); /* get the timestamp, no reset */
  2115. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2116. #if defined(WOLFSSL_ESPIDF)
  2117. ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
  2118. this_current_time, start );
  2119. #endif
  2120. #endif
  2121. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2122. #ifdef BENCH_MICROSECOND
  2123. * 1000000
  2124. #endif
  2125. );
  2126. return ret;
  2127. }
  2128. /* return text for units and scale the value of blocks as needed */
  2129. static const char* get_blocktype(double* blocks)
  2130. {
  2131. const char* rt;
  2132. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2133. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2134. #undef WOLFSSL_FIXED_UNIT
  2135. #define WOLFSSL_FIXED_UNIT "GB"
  2136. *blocks /= (1024UL * 1024UL * 1024UL);
  2137. rt = "GiB";
  2138. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2139. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2140. #undef WOLFSSL_FIXED_UNIT
  2141. #define WOLFSSL_FIXED_UNIT "MB"
  2142. *blocks /= (1024UL * 1024UL);
  2143. rt = "MiB";
  2144. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2145. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2146. #undef WOLFSSL_FIXED_UNIT
  2147. #define WOLFSSL_FIXED_UNIT "KB"
  2148. *blocks /= 1024;
  2149. rt = "KiB";
  2150. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2151. #undef WOLFSSL_FIXED_UNIT
  2152. #define WOLFSSL_FIXED_UNIT "bytes"
  2153. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2154. rt = "bytes";
  2155. #else
  2156. /* If no user-specified, auto-scale each metric (results vary).
  2157. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2158. if (*blocks > (1024UL * 1024UL)) {
  2159. *blocks /= (1024UL * 1024UL);
  2160. rt = "MiB";
  2161. }
  2162. else if (*blocks > 1024) {
  2163. *blocks /= 1024;
  2164. rt = "KiB";
  2165. }
  2166. else {
  2167. rt = "bytes";
  2168. }
  2169. #endif
  2170. return rt;
  2171. }
  2172. /* return text for units and scale the value of blocks as needed for base2 */
  2173. static const char* get_blocktype_base10(double* blocks)
  2174. {
  2175. const char* rt;
  2176. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2177. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2178. *blocks /= (1000UL * 1000UL * 1000UL);
  2179. rt = "GB";
  2180. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2181. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2182. *blocks /= (1000UL * 1000UL);
  2183. rt = "MB";
  2184. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2185. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2186. *blocks /= (1000UL);
  2187. rt = "KB";
  2188. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2189. (void)(*blocks); /* no adjustment, just appease compiler */
  2190. rt = "bytes";
  2191. #else
  2192. /* If not user-specified, auto-scale each metric (results vary).
  2193. * Determine if we should show as KB or MB or bytes */
  2194. if (*blocks > (1000UL * 1000UL)) {
  2195. *blocks /= (1000UL * 1000UL);
  2196. rt = "MB";
  2197. }
  2198. else if (*blocks > 1000) {
  2199. *blocks /= 1000; /* make KB */
  2200. rt = "KB";
  2201. }
  2202. else {
  2203. rt = "bytes";
  2204. }
  2205. #endif
  2206. return rt;
  2207. }
  2208. #ifdef MULTI_VALUE_STATISTICS
  2209. static double wc_sqroot(double in)
  2210. {
  2211. /* do 32 iterations for the sqroot */
  2212. int iter = 32;
  2213. double root = in/3.0;
  2214. if (in < 0.0)
  2215. return -1;
  2216. for (int i=0; i < iter; i++)
  2217. root = (root + in / root) / 2.0;
  2218. return root;
  2219. }
  2220. static void bench_multi_value_stats(double max, double min, double sum,
  2221. double squareSum, int runs)
  2222. {
  2223. double mean = 0;
  2224. double sd = 0;
  2225. char msg[WC_BENCH_MAX_LINE_LEN];
  2226. const char** word = bench_result_words3[lng_index];
  2227. XMEMSET(msg, 0, sizeof(msg));
  2228. mean = sum / runs;
  2229. /* Calculating standard deviation */
  2230. sd = (squareSum / runs) - (mean * mean);
  2231. sd = wc_sqroot(sd);
  2232. if (csv_format == 1) {
  2233. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2234. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2235. FLT_FMT_PREC2_ARGS(3, 3, max),
  2236. FLT_FMT_PREC2_ARGS(3, 3, min),
  2237. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2238. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2239. }
  2240. else{
  2241. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2242. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2243. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2244. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2245. WOLFSSL_FIXED_TIME_UNIT "\n",
  2246. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2247. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2248. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2249. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2250. }
  2251. printf("%s", msg);
  2252. #ifndef WOLFSSL_SGX
  2253. XFFLUSH(stdout);
  2254. #endif
  2255. }
  2256. #endif
  2257. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2258. * except for AES direct that operates on AES_BLOCK_SIZE blocks */
  2259. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2260. int count, word32 countSz,
  2261. double start, int ret)
  2262. {
  2263. double total, persec = 0, blocks = (double)count;
  2264. const char* blockType;
  2265. char msg[WC_BENCH_MAX_LINE_LEN];
  2266. const char** word = bench_result_words1[lng_index];
  2267. static int sym_header_printed = 0;
  2268. XMEMSET(msg, 0, sizeof(msg));
  2269. #ifdef WOLFSSL_ESPIDF
  2270. END_ESP_CYCLES
  2271. #else
  2272. END_INTEL_CYCLES
  2273. #endif
  2274. total = current_time(0) - start;
  2275. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2276. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2277. #endif
  2278. #ifdef LINUX_RUSAGE_UTIME
  2279. check_for_excessive_stime(desc, "");
  2280. #endif
  2281. /* calculate actual bytes */
  2282. blocks *= countSz;
  2283. if (csv_format == 1) {
  2284. /* only print out header once */
  2285. if (sym_header_printed == 0) {
  2286. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2287. /* machine parseable CSV */
  2288. #ifdef HAVE_GET_CYCLES
  2289. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2290. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2291. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2292. ",cycles_total,Cycles per byte,");
  2293. #else
  2294. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2295. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2296. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2297. ",cycles_total,");
  2298. #endif
  2299. #else
  2300. /* normal CSV */
  2301. #ifdef BENCH_DEVID
  2302. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2303. #else
  2304. #define BENCH_DEVID_COLUMN_HEADER
  2305. #endif
  2306. #ifdef HAVE_GET_CYCLES
  2307. printf("\n\nSymmetric Ciphers:\n\n");
  2308. printf("Algorithm,"
  2309. BENCH_DEVID_COLUMN_HEADER
  2310. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2311. ",Cycles per byte,");
  2312. #else
  2313. printf("\n\nSymmetric Ciphers:\n\n");
  2314. printf("Algorithm,"
  2315. BENCH_DEVID_COLUMN_HEADER
  2316. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2317. #endif
  2318. #endif
  2319. #ifdef MULTI_VALUE_STATISTICS
  2320. printf("max duration,min duration,mean duration,sd,\n");
  2321. #else
  2322. printf("\n");
  2323. #endif
  2324. sym_header_printed = 1;
  2325. }
  2326. }
  2327. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2328. * note that the blockType text is assigned AND the blocks param is scaled.
  2329. */
  2330. if (base2) {
  2331. blockType = get_blocktype(&blocks);
  2332. }
  2333. else {
  2334. blockType = get_blocktype_base10(&blocks);
  2335. }
  2336. /* calculate blocks per second */
  2337. if (total > 0) {
  2338. persec = (1 / total) * blocks;
  2339. }
  2340. SLEEP_ON_ERROR(ret);
  2341. /* format and print to terminal */
  2342. if (csv_format == 1) {
  2343. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2344. #ifdef WOLFSSL_ESPIDF
  2345. unsigned long bytes_processed =
  2346. (unsigned long)count * (unsigned long)countSz;
  2347. #else
  2348. word64 bytes_processed = (word64)count * (word64)countSz;
  2349. #endif
  2350. /* note this codepath brings in all the fields from the non-CSV case. */
  2351. #ifdef WOLFSSL_ESPIDF
  2352. #ifdef HAVE_GET_CYCLES
  2353. (void)XSNPRINTF(msg, sizeof(msg),
  2354. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2355. BENCH_DEVID_GET_NAME(useDeviceID),
  2356. bytes_processed, FLT_FMT_ARGS(total),
  2357. FLT_FMT_ARGS(persec),
  2358. (long unsigned int) total_cycles);
  2359. #else
  2360. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2361. #endif
  2362. /* implement other architectures here */
  2363. #else
  2364. #ifdef HAVE_GET_CYCLES
  2365. (void)XSNPRINTF(msg, sizeof(msg),
  2366. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2367. BENCH_DEVID_GET_NAME(useDeviceID),
  2368. bytes_processed, FLT_FMT_ARGS(total),
  2369. FLT_FMT_ARGS(persec), total_cycles);
  2370. #else
  2371. (void)XSNPRINTF(msg, sizeof(msg),
  2372. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2373. BENCH_DEVID_GET_NAME(useDeviceID),
  2374. bytes_processed, FLT_FMT_ARGS(total),
  2375. FLT_FMT_ARGS(persec));
  2376. #endif
  2377. #endif
  2378. #elif defined(BENCH_DEVID)
  2379. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2380. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2381. #else
  2382. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2383. FLT_FMT_ARGS(persec));
  2384. #endif
  2385. #ifdef WOLFSSL_ESPIDF
  2386. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2387. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2388. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2389. total_cycles);
  2390. #endif
  2391. /* implement other cycle counters here */
  2392. #else
  2393. /* the default cycle counter is Intel */
  2394. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2395. #endif
  2396. } /* if (csv_format == 1) */
  2397. else {
  2398. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2399. #ifdef HAVE_GET_CYCLES
  2400. (void)XSNPRINTF(msg, sizeof(msg),
  2401. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2402. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2403. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2404. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2405. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2406. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2407. (unsigned long) total_cycles);
  2408. #else
  2409. (void)XSNPRINTF(msg, sizeof(msg),
  2410. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2411. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2412. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2413. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2414. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2415. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2416. #endif /* HAVE_GET_CYCLES */
  2417. #else
  2418. (void)XSNPRINTF(msg, sizeof(msg),
  2419. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2420. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2421. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2422. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2423. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2424. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2425. #endif
  2426. #ifdef WOLFSSL_ESPIDF
  2427. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2428. /* implement other architecture cycle counters here */
  2429. #else
  2430. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2431. #endif
  2432. } /* not CSV format */
  2433. printf("%s", msg);
  2434. /* show errors */
  2435. if (ret < 0) {
  2436. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2437. }
  2438. #ifndef WOLFSSL_SGX
  2439. XFFLUSH(stdout);
  2440. #endif
  2441. #ifdef WC_BENCH_TRACK_STATS
  2442. /* Add to thread stats */
  2443. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2444. blockType, ret);
  2445. #endif
  2446. (void)useDeviceID;
  2447. (void)ret;
  2448. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2449. RESTORE_VECTOR_REGISTERS();
  2450. #endif
  2451. TEST_SLEEP();
  2452. } /* bench_stats_sym_finish */
  2453. #ifdef BENCH_ASYM
  2454. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2455. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2456. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2457. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  2458. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2459. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2460. double start, int ret)
  2461. {
  2462. double total, each = 0, opsSec, milliEach;
  2463. const char **word = bench_result_words2[lng_index];
  2464. #ifdef WC_BENCH_TRACK_STATS
  2465. const char* kOpsSec = "Ops/Sec";
  2466. #endif
  2467. char msg[256];
  2468. static int asym_header_printed = 0;
  2469. #ifdef BENCH_MICROSECOND
  2470. const int digits = 5;
  2471. #else
  2472. const int digits = 3;
  2473. #endif
  2474. XMEMSET(msg, 0, sizeof(msg));
  2475. total = current_time(0) - start;
  2476. #ifdef LINUX_RUSAGE_UTIME
  2477. check_for_excessive_stime(desc, desc_extra);
  2478. #endif
  2479. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2480. #ifdef WOLFSSL_ESPIDF
  2481. END_ESP_CYCLES
  2482. #else
  2483. END_INTEL_CYCLES
  2484. #endif
  2485. #endif
  2486. /* some sanity checks on the final numbers */
  2487. if (count > 0) {
  2488. each = total / count; /* per second */
  2489. }
  2490. else {
  2491. count = 0;
  2492. each = 0;
  2493. }
  2494. if (total > 0) {
  2495. opsSec = count / total; /* ops second */
  2496. }
  2497. else {
  2498. opsSec = 0;
  2499. }
  2500. #ifdef BENCH_MICROSECOND
  2501. milliEach = each / 1000; /* milliseconds */
  2502. #else
  2503. milliEach = each * 1000; /* milliseconds */
  2504. #endif
  2505. SLEEP_ON_ERROR(ret);
  2506. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2507. (void)milliEach;
  2508. /* format and print to terminal */
  2509. if (csv_format == 1) {
  2510. /* only print out header once */
  2511. if (asym_header_printed == 0) {
  2512. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2513. #ifdef HAVE_GET_CYCLES
  2514. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2515. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2516. "ecs,cycles,cycles/op,");
  2517. #else
  2518. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2519. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2520. "ecs,");
  2521. #endif
  2522. #else
  2523. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2524. printf("%sAlgorithm,key size,operation,ops/"
  2525. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2526. #endif
  2527. printf("max duration,min duration,mean duration,sd,\n");
  2528. asym_header_printed = 1;
  2529. }
  2530. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2531. #ifdef HAVE_GET_CYCLES
  2532. (void)XSNPRINTF(msg, sizeof(msg),
  2533. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2534. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2535. algo, strength, desc, desc_extra,
  2536. FLT_FMT_PREC_ARGS(digits, opsSec),
  2537. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2538. FLT_FMT_PREC_ARGS(6,
  2539. (double)total_cycles / (double)count));
  2540. #else
  2541. (void)XSNPRINTF(msg, sizeof(msg),
  2542. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2543. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2544. algo, strength, desc, desc_extra,
  2545. FLT_FMT_PREC_ARGS(digits, opsSec),
  2546. count, FLT_FMT_ARGS(total));
  2547. #endif
  2548. #else
  2549. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2550. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2551. algo, strength, desc, desc_extra,
  2552. FLT_FMT_PREC_ARGS(digits, opsSec));
  2553. #endif
  2554. } /* if (csv_format == 1) */
  2555. else {
  2556. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2557. #ifdef HAVE_GET_CYCLES
  2558. (void)XSNPRINTF(msg, sizeof(msg),
  2559. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2560. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2561. algo, strength, desc, desc_extra,
  2562. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2563. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2564. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2565. (unsigned long)total_cycles);
  2566. #else
  2567. (void)XSNPRINTF(msg, sizeof(msg),
  2568. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2569. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2570. algo, strength, desc, desc_extra,
  2571. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2572. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2573. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2574. #endif /* HAVE_GET_CYCLES */
  2575. #else
  2576. (void)XSNPRINTF(msg, sizeof(msg),
  2577. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2578. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2579. algo, strength, desc, desc_extra,
  2580. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2581. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2582. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2583. #endif
  2584. }
  2585. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2586. /* format and print to terminal */
  2587. if (csv_format == 1) {
  2588. /* only print out header once */
  2589. if (asym_header_printed == 0) {
  2590. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2591. #ifdef HAVE_GET_CYCLES
  2592. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2593. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2594. "ecs,cycles,cycles/op,");
  2595. #else
  2596. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2597. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2598. "ecs,");
  2599. #endif
  2600. #else
  2601. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2602. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2603. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2604. #endif
  2605. printf("\n");
  2606. asym_header_printed = 1;
  2607. }
  2608. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2609. #ifdef HAVE_GET_CYCLES
  2610. (void)XSNPRINTF(msg, sizeof(msg),
  2611. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2612. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2613. algo, strength, desc, desc_extra,
  2614. FLT_FMT_PREC_ARGS(3, milliEach),
  2615. FLT_FMT_PREC_ARGS(digits, opsSec),
  2616. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2617. FLT_FMT_PREC_ARGS(6,
  2618. (double)total_cycles / (double)count));
  2619. #else
  2620. (void)XSNPRINTF(msg, sizeof(msg),
  2621. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2622. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2623. algo, strength, desc, desc_extra,
  2624. FLT_FMT_PREC_ARGS(3, milliEach),
  2625. FLT_FMT_PREC_ARGS(digits, opsSec),
  2626. count, FLT_FMT_ARGS(total));
  2627. #endif
  2628. #else
  2629. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2630. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2631. algo, strength, desc, desc_extra,
  2632. FLT_FMT_PREC_ARGS(3, milliEach),
  2633. FLT_FMT_PREC_ARGS(digits, opsSec));
  2634. #endif
  2635. } /* if (csv_format == 1) */
  2636. else {
  2637. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2638. #ifdef HAVE_GET_CYCLES
  2639. (void)XSNPRINTF(msg, sizeof(msg),
  2640. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2641. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2642. STATS_CLAUSE_SEPARATOR,
  2643. algo, strength, desc, desc_extra,
  2644. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2645. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2646. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2647. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2648. (unsigned long)total_cycles);
  2649. #else
  2650. (void)XSNPRINTF(msg, sizeof(msg),
  2651. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2652. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2653. STATS_CLAUSE_SEPARATOR,
  2654. algo, strength, desc, desc_extra,
  2655. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2656. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2657. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2658. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2659. #endif /* HAVE_GET_CYCLES */
  2660. #else
  2661. (void)XSNPRINTF(msg, sizeof(msg),
  2662. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2663. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2664. STATS_CLAUSE_SEPARATOR,
  2665. algo, strength, desc, desc_extra,
  2666. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2667. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2668. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2669. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2670. #endif
  2671. }
  2672. #endif /* MULTI_VALUE_STATISTICS */
  2673. printf("%s", msg);
  2674. /* show errors */
  2675. if (ret < 0) {
  2676. printf("%sBenchmark %s %s %d failed: %d\n",
  2677. err_prefix, algo, desc, strength, ret);
  2678. }
  2679. #ifndef WOLFSSL_SGX
  2680. XFFLUSH(stdout);
  2681. #endif
  2682. #ifdef WC_BENCH_TRACK_STATS
  2683. /* Add to thread stats */
  2684. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2685. kOpsSec, ret);
  2686. #endif
  2687. (void)useDeviceID;
  2688. (void)ret;
  2689. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2690. RESTORE_VECTOR_REGISTERS();
  2691. #endif
  2692. TEST_SLEEP();
  2693. } /* bench_stats_asym_finish_ex */
  2694. static void bench_stats_asym_finish(const char* algo, int strength,
  2695. const char* desc, int useDeviceID, int count, double start, int ret)
  2696. {
  2697. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2698. start, ret);
  2699. }
  2700. #endif
  2701. #endif /* BENCH_ASYM */
  2702. static WC_INLINE void bench_stats_free(void)
  2703. {
  2704. #ifdef WC_BENCH_TRACK_STATS
  2705. bench_stats_t* bstat;
  2706. for (bstat = bench_stats_head; bstat != NULL; ) {
  2707. bench_stats_t* next = bstat->next;
  2708. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2709. bstat = next;
  2710. }
  2711. bench_stats_head = NULL;
  2712. bench_stats_tail = NULL;
  2713. #endif
  2714. }
  2715. /*****************************************************************************/
  2716. /* End Stats Functions */
  2717. /*****************************************************************************/
  2718. static void* benchmarks_do(void* args)
  2719. {
  2720. long bench_buf_size;
  2721. #ifdef WOLFSSL_ASYNC_CRYPT
  2722. #ifndef WC_NO_ASYNC_THREADING
  2723. ThreadData* threadData = (ThreadData*)args;
  2724. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2725. #else
  2726. if (wolfAsync_DevOpen(&devId) < 0)
  2727. #endif
  2728. {
  2729. printf("%sAsync device open failed\n%sRunning without async\n",
  2730. err_prefix, err_prefix);
  2731. }
  2732. #endif /* WOLFSSL_ASYNC_CRYPT */
  2733. (void)args;
  2734. #ifdef WOLFSSL_ASYNC_CRYPT
  2735. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2736. printf("%sAsync event queue init failure!\n", err_prefix);
  2737. }
  2738. #endif
  2739. #ifdef WOLF_CRYPTO_CB
  2740. #ifdef HAVE_INTEL_QA_SYNC
  2741. devId = wc_CryptoCb_InitIntelQa();
  2742. if (devId == INVALID_DEVID) {
  2743. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2744. }
  2745. #endif
  2746. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2747. devId = wc_CryptoCb_InitOcteon();
  2748. if (devId == INVALID_DEVID) {
  2749. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2750. }
  2751. #endif
  2752. #ifdef HAVE_RENESAS_SYNC
  2753. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2754. if (devId == INVALID_DEVID) {
  2755. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2756. }
  2757. #endif
  2758. #endif
  2759. #if defined(HAVE_LOCAL_RNG)
  2760. {
  2761. int rngRet;
  2762. #ifndef HAVE_FIPS
  2763. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2764. #else
  2765. rngRet = wc_InitRng(&gRng);
  2766. #endif
  2767. if (rngRet < 0) {
  2768. printf("%sInitRNG failed\n", err_prefix);
  2769. return NULL;
  2770. }
  2771. }
  2772. #endif
  2773. /* setup bench plain, cipher, key and iv globals */
  2774. /* make sure bench buffer is multiple of 16 (AES block size) */
  2775. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2776. if (bench_buf_size % 16)
  2777. bench_buf_size += 16 - (bench_buf_size % 16);
  2778. #ifdef WOLFSSL_AFALG_XILINX_AES
  2779. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2780. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16);
  2781. #else
  2782. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2783. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2784. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2785. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2786. #endif
  2787. if (bench_plain == NULL || bench_cipher == NULL) {
  2788. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2789. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2790. bench_plain = bench_cipher = NULL;
  2791. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2792. goto exit;
  2793. }
  2794. #ifndef NO_FILESYSTEM
  2795. if (hash_input) {
  2796. size_t rawSz;
  2797. XFILE file;
  2798. file = XFOPEN(hash_input, "rb");
  2799. if (file == XBADFILE)
  2800. goto exit;
  2801. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2802. XFCLOSE(file);
  2803. goto exit;
  2804. }
  2805. bench_buf_size = XFTELL(file);
  2806. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2807. XFCLOSE(file);
  2808. goto exit;
  2809. }
  2810. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2811. rawSz = (size_t)bench_buf_size;
  2812. if (bench_buf_size % 16)
  2813. bench_buf_size += 16 - (bench_buf_size % 16);
  2814. bench_size = (word32)bench_buf_size;
  2815. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2816. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2817. if (bench_plain == NULL) {
  2818. XFCLOSE(file);
  2819. goto exit;
  2820. }
  2821. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2822. != rawSz) {
  2823. XFCLOSE(file);
  2824. goto exit;
  2825. }
  2826. XFCLOSE(file);
  2827. }
  2828. else {
  2829. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2830. }
  2831. if (cipher_input) {
  2832. size_t rawSz;
  2833. XFILE file;
  2834. file = XFOPEN(cipher_input, "rb");
  2835. if (file == XBADFILE)
  2836. goto exit;
  2837. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2838. XFCLOSE(file);
  2839. goto exit;
  2840. }
  2841. bench_buf_size = XFTELL(file);
  2842. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2843. XFCLOSE(file);
  2844. goto exit;
  2845. }
  2846. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2847. rawSz = (size_t)bench_buf_size;
  2848. if (bench_buf_size % 16)
  2849. bench_buf_size += 16 - (bench_buf_size % 16);
  2850. if (bench_size > (word32)bench_buf_size)
  2851. bench_size = (word32)bench_buf_size;
  2852. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2853. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2854. if (bench_cipher == NULL) {
  2855. XFCLOSE(file);
  2856. goto exit;
  2857. }
  2858. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2859. != rawSz) {
  2860. XFCLOSE(file);
  2861. goto exit;
  2862. }
  2863. XFCLOSE(file);
  2864. }
  2865. else {
  2866. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2867. }
  2868. #endif
  2869. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2870. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2871. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2872. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2873. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2874. if (bench_key == NULL || bench_iv == NULL) {
  2875. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2876. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2877. bench_key = bench_iv = NULL;
  2878. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2879. goto exit;
  2880. }
  2881. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2882. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2883. #elif defined(HAVE_RENESAS_SYNC)
  2884. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2885. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2886. bench_key = (byte*)bench_key_buf;
  2887. bench_iv = (byte*)bench_iv_buf;
  2888. #else
  2889. bench_key = (byte*)bench_key_buf;
  2890. bench_iv = (byte*)bench_iv_buf;
  2891. #endif
  2892. #ifndef WC_NO_RNG
  2893. if (bench_all || (bench_other_algs & BENCH_RNG))
  2894. bench_rng();
  2895. #endif /* WC_NO_RNG */
  2896. #ifndef NO_AES
  2897. #ifdef HAVE_AES_CBC
  2898. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2899. #ifndef NO_SW_BENCH
  2900. bench_aescbc(0);
  2901. #endif
  2902. #if defined(BENCH_DEVID)
  2903. bench_aescbc(1);
  2904. #endif
  2905. }
  2906. #endif
  2907. #ifdef HAVE_AESGCM
  2908. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2909. #ifndef NO_SW_BENCH
  2910. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2911. #endif
  2912. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2913. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2914. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2915. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2916. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2917. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2918. #endif
  2919. #ifndef NO_SW_BENCH
  2920. bench_gmac(0);
  2921. #endif
  2922. #if defined(BENCH_DEVID)
  2923. bench_gmac(1);
  2924. #endif
  2925. }
  2926. #endif
  2927. #ifdef HAVE_AES_ECB
  2928. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2929. #ifndef NO_SW_BENCH
  2930. bench_aesecb(0);
  2931. #endif
  2932. #ifdef BENCH_DEVID
  2933. bench_aesecb(1);
  2934. #endif
  2935. }
  2936. #endif
  2937. #ifdef WOLFSSL_AES_XTS
  2938. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2939. bench_aesxts();
  2940. #endif
  2941. #ifdef WOLFSSL_AES_CFB
  2942. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2943. bench_aescfb();
  2944. #endif
  2945. #ifdef WOLFSSL_AES_OFB
  2946. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2947. bench_aesofb();
  2948. #endif
  2949. #ifdef WOLFSSL_AES_COUNTER
  2950. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2951. bench_aesctr(0);
  2952. #ifdef BENCH_DEVID
  2953. bench_aesctr(1);
  2954. #endif
  2955. }
  2956. #endif
  2957. #ifdef HAVE_AESCCM
  2958. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2959. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2960. #ifdef BENCH_DEVID
  2961. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2962. #endif
  2963. }
  2964. #endif
  2965. #ifdef WOLFSSL_AES_SIV
  2966. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2967. bench_aessiv();
  2968. #endif
  2969. #endif /* !NO_AES */
  2970. #ifdef HAVE_CAMELLIA
  2971. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2972. bench_camellia();
  2973. #endif
  2974. #ifdef WOLFSSL_SM4_CBC
  2975. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2976. bench_sm4_cbc();
  2977. #endif
  2978. #ifdef WOLFSSL_SM4_GCM
  2979. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2980. bench_sm4_gcm();
  2981. #endif
  2982. #ifdef WOLFSSL_SM4_CCM
  2983. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2984. bench_sm4_ccm();
  2985. #endif
  2986. #ifndef NO_RC4
  2987. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2988. #ifndef NO_SW_BENCH
  2989. bench_arc4(0);
  2990. #endif
  2991. #ifdef BENCH_DEVID
  2992. bench_arc4(1);
  2993. #endif
  2994. }
  2995. #endif
  2996. #ifdef HAVE_CHACHA
  2997. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  2998. bench_chacha();
  2999. #endif
  3000. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  3001. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  3002. bench_chacha20_poly1305_aead();
  3003. #endif
  3004. #ifndef NO_DES3
  3005. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  3006. #ifndef NO_SW_BENCH
  3007. bench_des(0);
  3008. #endif
  3009. #ifdef BENCH_DEVID
  3010. bench_des(1);
  3011. #endif
  3012. }
  3013. #endif
  3014. #ifndef NO_MD5
  3015. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  3016. #ifndef NO_SW_BENCH
  3017. bench_md5(0);
  3018. #endif
  3019. #ifdef BENCH_DEVID
  3020. bench_md5(1);
  3021. #endif
  3022. }
  3023. #endif
  3024. #ifdef HAVE_POLY1305
  3025. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  3026. bench_poly1305();
  3027. #endif
  3028. #ifndef NO_SHA
  3029. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  3030. #ifndef NO_SW_BENCH
  3031. bench_sha(0);
  3032. #endif
  3033. #ifdef BENCH_DEVID
  3034. bench_sha(1);
  3035. #endif
  3036. }
  3037. #endif
  3038. #ifdef WOLFSSL_SHA224
  3039. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  3040. #ifndef NO_SW_BENCH
  3041. bench_sha224(0);
  3042. #endif
  3043. #ifdef BENCH_DEVID
  3044. bench_sha224(1);
  3045. #endif
  3046. }
  3047. #endif
  3048. #ifndef NO_SHA256
  3049. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  3050. #ifndef NO_SW_BENCH
  3051. bench_sha256(0);
  3052. #endif
  3053. #ifdef BENCH_DEVID
  3054. bench_sha256(1);
  3055. #endif
  3056. }
  3057. #endif
  3058. #ifdef WOLFSSL_SHA384
  3059. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3060. #ifndef NO_SW_BENCH
  3061. bench_sha384(0);
  3062. #endif
  3063. #ifdef BENCH_DEVID
  3064. bench_sha384(1);
  3065. #endif
  3066. }
  3067. #endif
  3068. #ifdef WOLFSSL_SHA512
  3069. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3070. #ifndef NO_SW_BENCH
  3071. bench_sha512(0);
  3072. #endif
  3073. #ifdef BENCH_DEVID
  3074. bench_sha512(1);
  3075. #endif
  3076. }
  3077. #if !defined(WOLFSSL_NOSHA512_224) && \
  3078. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3079. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3080. #ifndef NO_SW_BENCH
  3081. bench_sha512_224(0);
  3082. #endif
  3083. #ifdef BENCH_DEVID
  3084. bench_sha512_224(1);
  3085. #endif
  3086. }
  3087. #endif /* WOLFSSL_NOSHA512_224 */
  3088. #if !defined(WOLFSSL_NOSHA512_256) && \
  3089. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3090. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3091. #ifndef NO_SW_BENCH
  3092. bench_sha512_256(0);
  3093. #endif
  3094. #ifdef BENCH_DEVID
  3095. bench_sha512_256(1);
  3096. #endif
  3097. }
  3098. #endif /* WOLFSSL_NOSHA512_256 */
  3099. #endif /* WOLFSSL_SHA512 */
  3100. #ifdef WOLFSSL_SHA3
  3101. #ifndef WOLFSSL_NOSHA3_224
  3102. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3103. #ifndef NO_SW_BENCH
  3104. bench_sha3_224(0);
  3105. #endif
  3106. #ifdef BENCH_DEVID
  3107. bench_sha3_224(1);
  3108. #endif
  3109. }
  3110. #endif /* WOLFSSL_NOSHA3_224 */
  3111. #ifndef WOLFSSL_NOSHA3_256
  3112. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3113. #ifndef NO_SW_BENCH
  3114. bench_sha3_256(0);
  3115. #endif
  3116. #ifdef BENCH_DEVID
  3117. bench_sha3_256(1);
  3118. #endif
  3119. }
  3120. #endif /* WOLFSSL_NOSHA3_256 */
  3121. #ifndef WOLFSSL_NOSHA3_384
  3122. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3123. #ifndef NO_SW_BENCH
  3124. bench_sha3_384(0);
  3125. #endif
  3126. #ifdef BENCH_DEVID
  3127. bench_sha3_384(1);
  3128. #endif
  3129. }
  3130. #endif /* WOLFSSL_NOSHA3_384 */
  3131. #ifndef WOLFSSL_NOSHA3_512
  3132. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3133. #ifndef NO_SW_BENCH
  3134. bench_sha3_512(0);
  3135. #endif
  3136. #ifdef BENCH_DEVID
  3137. bench_sha3_512(1);
  3138. #endif
  3139. }
  3140. #endif /* WOLFSSL_NOSHA3_512 */
  3141. #ifdef WOLFSSL_SHAKE128
  3142. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3143. #ifndef NO_SW_BENCH
  3144. bench_shake128(0);
  3145. #endif
  3146. #ifdef BENCH_DEVID
  3147. bench_shake128(1);
  3148. #endif
  3149. }
  3150. #endif /* WOLFSSL_SHAKE128 */
  3151. #ifdef WOLFSSL_SHAKE256
  3152. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3153. #ifndef NO_SW_BENCH
  3154. bench_shake256(0);
  3155. #endif
  3156. #ifdef BENCH_DEVID
  3157. bench_shake256(1);
  3158. #endif
  3159. }
  3160. #endif /* WOLFSSL_SHAKE256 */
  3161. #endif
  3162. #ifdef WOLFSSL_SM3
  3163. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3164. #ifndef NO_SW_BENCH
  3165. bench_sm3(0);
  3166. #endif
  3167. #ifdef BENCH_DEVID
  3168. bench_sm3(1);
  3169. #endif
  3170. }
  3171. #endif
  3172. #ifdef WOLFSSL_RIPEMD
  3173. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3174. bench_ripemd();
  3175. #endif
  3176. #ifdef HAVE_BLAKE2
  3177. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3178. bench_blake2b();
  3179. #endif
  3180. #ifdef HAVE_BLAKE2S
  3181. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3182. bench_blake2s();
  3183. #endif
  3184. #ifdef WOLFSSL_CMAC
  3185. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3186. bench_cmac(0);
  3187. #ifdef BENCH_DEVID
  3188. bench_cmac(1);
  3189. #endif
  3190. }
  3191. #endif
  3192. #ifndef NO_HMAC
  3193. #ifndef NO_MD5
  3194. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3195. #ifndef NO_SW_BENCH
  3196. bench_hmac_md5(0);
  3197. #endif
  3198. #ifdef BENCH_DEVID
  3199. bench_hmac_md5(1);
  3200. #endif
  3201. }
  3202. #endif
  3203. #ifndef NO_SHA
  3204. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3205. #ifndef NO_SW_BENCH
  3206. bench_hmac_sha(0);
  3207. #endif
  3208. #ifdef BENCH_DEVID
  3209. bench_hmac_sha(1);
  3210. #endif
  3211. }
  3212. #endif
  3213. #ifdef WOLFSSL_SHA224
  3214. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3215. #ifndef NO_SW_BENCH
  3216. bench_hmac_sha224(0);
  3217. #endif
  3218. #ifdef BENCH_DEVID
  3219. bench_hmac_sha224(1);
  3220. #endif
  3221. }
  3222. #endif
  3223. #ifndef NO_SHA256
  3224. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3225. #ifndef NO_SW_BENCH
  3226. bench_hmac_sha256(0);
  3227. #endif
  3228. #ifdef BENCH_DEVID
  3229. bench_hmac_sha256(1);
  3230. #endif
  3231. }
  3232. #endif
  3233. #ifdef WOLFSSL_SHA384
  3234. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3235. #ifndef NO_SW_BENCH
  3236. bench_hmac_sha384(0);
  3237. #endif
  3238. #ifdef BENCH_DEVID
  3239. bench_hmac_sha384(1);
  3240. #endif
  3241. }
  3242. #endif
  3243. #ifdef WOLFSSL_SHA512
  3244. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3245. #ifndef NO_SW_BENCH
  3246. bench_hmac_sha512(0);
  3247. #endif
  3248. #ifdef BENCH_DEVID
  3249. bench_hmac_sha512(1);
  3250. #endif
  3251. }
  3252. #endif
  3253. #ifndef NO_PWDBASED
  3254. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3255. bench_pbkdf2();
  3256. }
  3257. #endif
  3258. #endif /* NO_HMAC */
  3259. #ifdef WOLFSSL_SIPHASH
  3260. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3261. bench_siphash();
  3262. }
  3263. #endif
  3264. #ifdef WC_SRTP_KDF
  3265. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3266. bench_srtpkdf();
  3267. }
  3268. #endif
  3269. #ifdef HAVE_SCRYPT
  3270. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3271. bench_scrypt();
  3272. #endif
  3273. #ifndef NO_RSA
  3274. #ifndef HAVE_RENESAS_SYNC
  3275. #ifdef WOLFSSL_KEY_GEN
  3276. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3277. #ifndef NO_SW_BENCH
  3278. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3279. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3280. bench_rsaKeyGen(0);
  3281. }
  3282. else {
  3283. bench_rsaKeyGen_size(0, bench_size);
  3284. }
  3285. #endif
  3286. #ifdef BENCH_DEVID
  3287. if (bench_asym_algs & BENCH_RSA_SZ) {
  3288. bench_rsaKeyGen_size(1, bench_size);
  3289. }
  3290. else {
  3291. bench_rsaKeyGen(1);
  3292. }
  3293. #endif
  3294. }
  3295. #endif
  3296. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3297. #ifndef NO_SW_BENCH
  3298. bench_rsa(0);
  3299. #endif
  3300. #ifdef BENCH_DEVID
  3301. bench_rsa(1);
  3302. #endif
  3303. }
  3304. #ifdef WOLFSSL_KEY_GEN
  3305. if (bench_asym_algs & BENCH_RSA_SZ) {
  3306. #ifndef NO_SW_BENCH
  3307. bench_rsa_key(0, bench_size);
  3308. #endif
  3309. #ifdef BENCH_DEVID
  3310. bench_rsa_key(1, bench_size);
  3311. #endif
  3312. }
  3313. #endif
  3314. #endif
  3315. #endif
  3316. #ifndef NO_DH
  3317. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3318. #ifndef NO_SW_BENCH
  3319. bench_dh(0);
  3320. #endif
  3321. #ifdef BENCH_DEVID
  3322. bench_dh(1);
  3323. #endif
  3324. }
  3325. #endif
  3326. #ifdef WOLFSSL_HAVE_KYBER
  3327. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3328. #ifdef WOLFSSL_KYBER512
  3329. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3330. bench_kyber(KYBER512);
  3331. }
  3332. #endif
  3333. #ifdef WOLFSSL_KYBER768
  3334. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3335. bench_kyber(KYBER768);
  3336. }
  3337. #endif
  3338. #ifdef WOLFSSL_KYBER1024
  3339. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3340. bench_kyber(KYBER1024);
  3341. }
  3342. #endif
  3343. }
  3344. #endif
  3345. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3346. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3347. bench_lms();
  3348. }
  3349. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3350. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3351. if (bench_all) {
  3352. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3353. }
  3354. #ifndef NO_SHA256
  3355. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3356. bench_xmss(WC_HASH_TYPE_SHA256);
  3357. }
  3358. #endif
  3359. #ifdef WOLFSSL_SHA512
  3360. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3361. bench_xmss(WC_HASH_TYPE_SHA512);
  3362. }
  3363. #endif
  3364. #ifdef WOLFSSL_SHAKE128
  3365. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3366. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3367. }
  3368. #endif
  3369. #ifdef WOLFSSL_SHAKE256
  3370. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3371. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3372. }
  3373. #endif
  3374. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3375. #ifdef HAVE_ECC
  3376. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3377. (bench_asym_algs & BENCH_ECC) ||
  3378. (bench_asym_algs & BENCH_ECC_ALL) ||
  3379. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3380. if (bench_asym_algs & BENCH_ECC_ALL) {
  3381. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3382. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3383. err_prefix);
  3384. #else
  3385. int curveId = (int)ECC_SECP192R1;
  3386. /* set make key and encrypt */
  3387. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3388. BENCH_ECC_ENCRYPT;
  3389. if (csv_format != 1) {
  3390. printf("\n%sECC Benchmarks:\n", info_prefix);
  3391. }
  3392. do {
  3393. #ifdef WOLFCRYPT_HAVE_SAKKE
  3394. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3395. if (curveId == ECC_SAKKE_1) {
  3396. curveId++;
  3397. continue;
  3398. }
  3399. #endif
  3400. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3401. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3402. bench_ecc_curve(curveId);
  3403. if (csv_format != 1) {
  3404. printf("\n");
  3405. }
  3406. }
  3407. curveId++;
  3408. } while (curveId != (int)ECC_CURVE_MAX);
  3409. #endif
  3410. }
  3411. else if (bench_asym_algs & BENCH_ECC_P256) {
  3412. bench_ecc_curve((int)ECC_SECP256R1);
  3413. }
  3414. else if (bench_asym_algs & BENCH_ECC_P384) {
  3415. bench_ecc_curve((int)ECC_SECP384R1);
  3416. }
  3417. else if (bench_asym_algs & BENCH_ECC_P521) {
  3418. bench_ecc_curve((int)ECC_SECP521R1);
  3419. }
  3420. else {
  3421. #ifndef NO_ECC256
  3422. bench_ecc_curve((int)ECC_SECP256R1);
  3423. #elif defined(HAVE_ECC384)
  3424. bench_ecc_curve((int)ECC_SECP384R1);
  3425. #elif defined(HAVE_ECC521)
  3426. bench_ecc_curve((int)ECC_SECP521R1);
  3427. #endif
  3428. #ifdef HAVE_ECC_BRAINPOOL
  3429. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3430. #endif
  3431. }
  3432. }
  3433. #endif
  3434. #ifdef WOLFSSL_SM2
  3435. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3436. bench_sm2(0);
  3437. }
  3438. #endif
  3439. #ifdef HAVE_CURVE25519
  3440. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3441. bench_curve25519KeyGen(0);
  3442. #ifdef BENCH_DEVID
  3443. bench_curve25519KeyGen(1);
  3444. #endif
  3445. }
  3446. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3447. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3448. bench_curve25519KeyAgree(0);
  3449. #ifdef BENCH_DEVID
  3450. bench_curve25519KeyAgree(1);
  3451. #endif
  3452. }
  3453. #endif
  3454. #endif
  3455. #ifdef HAVE_ED25519
  3456. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3457. bench_ed25519KeyGen();
  3458. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3459. bench_ed25519KeySign();
  3460. #endif
  3461. #ifdef HAVE_CURVE448
  3462. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3463. bench_curve448KeyGen();
  3464. #ifdef HAVE_CURVE448_SHARED_SECRET
  3465. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3466. bench_curve448KeyAgree();
  3467. #endif
  3468. #endif
  3469. #ifdef HAVE_ED448
  3470. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3471. bench_ed448KeyGen();
  3472. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3473. bench_ed448KeySign();
  3474. #endif
  3475. #ifdef WOLFCRYPT_HAVE_ECCSI
  3476. #ifdef WOLFCRYPT_ECCSI_KMS
  3477. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3478. bench_eccsiKeyGen();
  3479. }
  3480. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3481. bench_eccsiPairGen();
  3482. }
  3483. #endif
  3484. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3485. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3486. bench_eccsiValidate();
  3487. }
  3488. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3489. bench_eccsi();
  3490. }
  3491. #endif
  3492. #endif
  3493. #ifdef WOLFCRYPT_HAVE_SAKKE
  3494. #ifdef WOLFCRYPT_SAKKE_KMS
  3495. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3496. bench_sakkeKeyGen();
  3497. }
  3498. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3499. bench_sakkeRskGen();
  3500. }
  3501. #endif
  3502. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3503. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3504. bench_sakkeValidate();
  3505. }
  3506. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3507. bench_sakke();
  3508. }
  3509. #endif
  3510. #endif
  3511. #ifdef HAVE_FALCON
  3512. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3513. bench_falconKeySign(1);
  3514. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3515. bench_falconKeySign(5);
  3516. #endif
  3517. #ifdef HAVE_DILITHIUM
  3518. #ifndef WOLFSSL_NO_ML_DSA_44
  3519. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3520. bench_dilithiumKeySign(2);
  3521. #endif
  3522. #ifndef WOLFSSL_NO_ML_DSA_65
  3523. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3524. bench_dilithiumKeySign(3);
  3525. #endif
  3526. #ifndef WOLFSSL_NO_ML_DSA_87
  3527. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3528. bench_dilithiumKeySign(5);
  3529. #endif
  3530. #endif
  3531. #ifdef HAVE_SPHINCS
  3532. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3533. bench_sphincsKeySign(1, FAST_VARIANT);
  3534. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3535. bench_sphincsKeySign(3, FAST_VARIANT);
  3536. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3537. bench_sphincsKeySign(5, FAST_VARIANT);
  3538. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3539. bench_sphincsKeySign(1, SMALL_VARIANT);
  3540. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3541. bench_sphincsKeySign(3, SMALL_VARIANT);
  3542. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3543. bench_sphincsKeySign(5, SMALL_VARIANT);
  3544. #endif
  3545. exit:
  3546. /* free benchmark buffers */
  3547. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3548. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3549. #ifdef WOLFSSL_ASYNC_CRYPT
  3550. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3551. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3552. #endif
  3553. #if defined(HAVE_LOCAL_RNG)
  3554. wc_FreeRng(&gRng);
  3555. #endif
  3556. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3557. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3558. wc_ecc_fp_free();
  3559. #endif
  3560. (void)bench_cipher_algs;
  3561. (void)bench_digest_algs;
  3562. (void)bench_mac_algs;
  3563. (void)bench_asym_algs;
  3564. (void)bench_other_algs;
  3565. (void)bench_pq_asym_algs;
  3566. (void)bench_pq_asym_algs2;
  3567. return NULL;
  3568. }
  3569. int benchmark_init(void)
  3570. {
  3571. int ret = 0;
  3572. benchmark_static_init(0);
  3573. #ifdef WOLFSSL_STATIC_MEMORY
  3574. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3575. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3576. if (ret != 0) {
  3577. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3578. }
  3579. #endif /* WOLFSSL_STATIC_MEMORY */
  3580. if ((ret = wolfCrypt_Init()) != 0) {
  3581. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3582. return EXIT_FAILURE;
  3583. }
  3584. #ifdef HAVE_WC_INTROSPECTION
  3585. printf("Math: %s\n", wc_GetMathInfo());
  3586. #endif
  3587. #ifdef WOLFSSL_SECO_CAAM
  3588. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3589. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3590. != 0) {
  3591. printf("%sunable to open HSM\n", err_prefix);
  3592. wolfCrypt_Cleanup();
  3593. return EXIT_FAILURE;
  3594. }
  3595. #endif
  3596. #ifdef WC_RNG_SEED_CB
  3597. wc_SetSeed_Cb(wc_GenerateSeed);
  3598. #endif
  3599. bench_stats_init();
  3600. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3601. wolfSSL_Debugging_ON();
  3602. #endif
  3603. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3604. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3605. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3606. if (csv_format == 1) {
  3607. printf("This format allows you to easily copy "
  3608. "the output to a csv file.");
  3609. }
  3610. #endif
  3611. #ifdef HAVE_WNR
  3612. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3613. if (ret != 0) {
  3614. printf("%sWhitewood netRandom config init failed %d\n",
  3615. err_prefix, ret);
  3616. }
  3617. #endif /* HAVE_WNR */
  3618. return ret;
  3619. }
  3620. int benchmark_free(void)
  3621. {
  3622. int ret;
  3623. #ifdef WC_BENCH_TRACK_STATS
  3624. if (gPrintStats || devId != INVALID_DEVID) {
  3625. bench_stats_print();
  3626. }
  3627. #endif
  3628. bench_stats_free();
  3629. #ifdef WOLF_CRYPTO_CB
  3630. #ifdef HAVE_INTEL_QA_SYNC
  3631. wc_CryptoCb_CleanupIntelQa(&devId);
  3632. #endif
  3633. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3634. wc_CryptoCb_CleanupOcteon(&devId);
  3635. #endif
  3636. #ifdef HAVE_RENESAS_SYNC
  3637. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3638. #endif
  3639. #endif
  3640. #ifdef WOLFSSL_ASYNC_CRYPT
  3641. /* free event queue */
  3642. wolfEventQueue_Free(&eventQueue);
  3643. /* close device */
  3644. wolfAsync_DevClose(&devId);
  3645. #endif
  3646. #ifdef HAVE_WNR
  3647. ret = wc_FreeNetRandom();
  3648. if (ret < 0) {
  3649. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3650. }
  3651. #endif
  3652. #ifdef WOLFSSL_SECO_CAAM
  3653. if (wc_SECO_CloseHSM() != 0) {
  3654. printf("%sError closing down the key store\n", err_prefix);
  3655. }
  3656. #endif
  3657. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3658. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3659. }
  3660. return ret;
  3661. }
  3662. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3663. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3664. {
  3665. benchmark_test(args);
  3666. EXIT_TEST(0);
  3667. }
  3668. static int benchmark_test_threaded(void* args)
  3669. {
  3670. int i;
  3671. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3672. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3673. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3674. if (g_threadData == NULL) {
  3675. printf("%sThread data alloc failed!\n", err_prefix);
  3676. return EXIT_FAILURE;
  3677. }
  3678. for (i = 0; i < g_threadCount; i++) {
  3679. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3680. NULL, run_bench, args));
  3681. }
  3682. for (i = 0; i < g_threadCount; i++) {
  3683. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3684. }
  3685. printf("\n");
  3686. bench_stats_print();
  3687. return 0;
  3688. }
  3689. #endif
  3690. /* so embedded projects can pull in tests on their own */
  3691. #ifdef HAVE_STACK_SIZE
  3692. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3693. #else
  3694. int benchmark_test(void *args)
  3695. #endif
  3696. {
  3697. int ret;
  3698. (void)args;
  3699. #ifdef HAVE_FIPS
  3700. wolfCrypt_SetCb_fips(myFipsCb);
  3701. #endif
  3702. ret = benchmark_init();
  3703. if (ret != 0)
  3704. EXIT_TEST(ret);
  3705. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3706. {
  3707. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3708. **
  3709. ** Chapter Two, Build Options:
  3710. **
  3711. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3712. **
  3713. ** asynchronous cryptography using hardware based adapters such as
  3714. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3715. */
  3716. int i;
  3717. if (g_threadCount == 0) {
  3718. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3719. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3720. #else
  3721. g_threadCount = wc_AsyncGetNumberOfCpus();
  3722. if (g_threadCount > 0) {
  3723. g_threadCount /= 2; /* use physical core count */
  3724. }
  3725. #endif
  3726. }
  3727. if (g_threadCount <= 0) {
  3728. g_threadCount = 1;
  3729. }
  3730. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3731. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3732. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3733. if (g_threadData == NULL) {
  3734. printf("%sThread data alloc failed!\n", err_prefix);
  3735. EXIT_TEST(EXIT_FAILURE);
  3736. }
  3737. /* Create threads */
  3738. for (i = 0; i < g_threadCount; i++) {
  3739. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3740. benchmarks_do, &g_threadData[i]);
  3741. if (ret != 0) {
  3742. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3743. EXIT_TEST(EXIT_FAILURE);
  3744. }
  3745. }
  3746. /* Start threads */
  3747. for (i = 0; i < g_threadCount; i++) {
  3748. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3749. }
  3750. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3751. }
  3752. #else
  3753. benchmarks_do(NULL);
  3754. #endif
  3755. SLEEP_ON_ERROR(1);
  3756. printf("%sBenchmark complete\n", info_prefix);
  3757. ret = benchmark_free();
  3758. EXIT_TEST(ret);
  3759. }
  3760. #ifndef WC_NO_RNG
  3761. void bench_rng(void)
  3762. {
  3763. int ret, i, count;
  3764. double start;
  3765. long pos, len, remain;
  3766. WC_RNG myrng;
  3767. DECLARE_MULTI_VALUE_STATS_VARS()
  3768. #ifndef HAVE_FIPS
  3769. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3770. #else
  3771. ret = wc_InitRng(&myrng);
  3772. #endif
  3773. if (ret < 0) {
  3774. printf("InitRNG failed %d\n", ret);
  3775. return;
  3776. }
  3777. bench_stats_start(&count, &start);
  3778. do {
  3779. for (i = 0; i < numBlocks; i++) {
  3780. /* Split request to handle large RNG request */
  3781. pos = 0;
  3782. remain = (int)bench_size;
  3783. while (remain > 0) {
  3784. len = remain;
  3785. if (len > RNG_MAX_BLOCK_LEN)
  3786. len = RNG_MAX_BLOCK_LEN;
  3787. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3788. (word32)len);
  3789. if (ret < 0)
  3790. goto exit_rng;
  3791. remain -= len;
  3792. pos += len;
  3793. }
  3794. RECORD_MULTI_VALUE_STATS();
  3795. }
  3796. count += i;
  3797. } while (bench_stats_check(start)
  3798. #ifdef MULTI_VALUE_STATISTICS
  3799. || runs < minimum_runs
  3800. #endif
  3801. );
  3802. exit_rng:
  3803. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3804. #ifdef MULTI_VALUE_STATISTICS
  3805. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3806. #endif
  3807. wc_FreeRng(&myrng);
  3808. }
  3809. #endif /* WC_NO_RNG */
  3810. #ifndef NO_AES
  3811. #ifdef HAVE_AES_CBC
  3812. static void bench_aescbc_internal(int useDeviceID,
  3813. const byte* key, word32 keySz,
  3814. const byte* iv, const char* encLabel,
  3815. const char* decLabel)
  3816. {
  3817. const byte* in = bench_cipher;
  3818. byte* out = bench_plain;
  3819. int ret = 0, i, count = 0, times, pending = 0;
  3820. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3821. sizeof(Aes), HEAP_HINT);
  3822. double start;
  3823. DECLARE_MULTI_VALUE_STATS_VARS()
  3824. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3825. sizeof(Aes), HEAP_HINT);
  3826. /* init keys */
  3827. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3828. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3829. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3830. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3831. goto exit;
  3832. }
  3833. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3834. if (ret != 0) {
  3835. printf("AesSetKey failed, ret = %d\n", ret);
  3836. goto exit;
  3837. }
  3838. }
  3839. if (cipher_same_buffer) {
  3840. in = bench_plain;
  3841. }
  3842. bench_stats_start(&count, &start);
  3843. do {
  3844. for (times = 0; times < numBlocks || pending > 0; ) {
  3845. bench_async_poll(&pending);
  3846. /* while free pending slots in queue, submit ops */
  3847. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3848. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3849. &times, numBlocks, &pending)) {
  3850. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3851. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3852. 0, &times, &pending)) {
  3853. goto exit_aes_enc;
  3854. }
  3855. }
  3856. } /* for i */
  3857. RECORD_MULTI_VALUE_STATS();
  3858. } /* for times */
  3859. count += times;
  3860. } while (bench_stats_check(start)
  3861. #ifdef MULTI_VALUE_STATISTICS
  3862. || runs < minimum_runs
  3863. #endif
  3864. );
  3865. exit_aes_enc:
  3866. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3867. bench_size, start, ret);
  3868. #ifdef MULTI_VALUE_STATISTICS
  3869. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3870. #endif
  3871. if (ret < 0) {
  3872. goto exit;
  3873. }
  3874. #ifdef HAVE_AES_DECRYPT
  3875. /* init keys */
  3876. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3877. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3878. if (ret != 0) {
  3879. printf("AesSetKey failed, ret = %d\n", ret);
  3880. goto exit;
  3881. }
  3882. }
  3883. RESET_MULTI_VALUE_STATS_VARS();
  3884. bench_stats_start(&count, &start);
  3885. do {
  3886. for (times = 0; times < numBlocks || pending > 0; ) {
  3887. bench_async_poll(&pending);
  3888. /* while free pending slots in queue, submit ops */
  3889. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3890. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3891. &times, numBlocks, &pending)) {
  3892. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3893. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3894. 0, &times, &pending)) {
  3895. goto exit_aes_dec;
  3896. }
  3897. }
  3898. } /* for i */
  3899. RECORD_MULTI_VALUE_STATS();
  3900. } /* for times */
  3901. count += times;
  3902. } while (bench_stats_check(start)
  3903. #ifdef MULTI_VALUE_STATISTICS
  3904. || runs < minimum_runs
  3905. #endif
  3906. );
  3907. exit_aes_dec:
  3908. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3909. start, ret);
  3910. #ifdef MULTI_VALUE_STATISTICS
  3911. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3912. #endif
  3913. #endif /* HAVE_AES_DECRYPT */
  3914. (void)decLabel;
  3915. exit:
  3916. if (WC_ARRAY_OK(enc)) {
  3917. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3918. wc_AesFree(enc[i]);
  3919. }
  3920. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3921. }
  3922. }
  3923. void bench_aescbc(int useDeviceID)
  3924. {
  3925. #ifdef WOLFSSL_AES_128
  3926. #ifdef HAVE_RENESAS_SYNC
  3927. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3928. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3929. #else
  3930. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3931. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3932. #endif
  3933. #endif
  3934. #ifdef WOLFSSL_AES_192
  3935. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3936. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3937. #endif
  3938. #ifdef WOLFSSL_AES_256
  3939. #ifdef HAVE_RENESAS_SYNC
  3940. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3941. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3942. #else
  3943. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3944. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3945. #endif
  3946. #endif
  3947. }
  3948. #endif /* HAVE_AES_CBC */
  3949. #ifdef HAVE_AESGCM
  3950. static void bench_aesgcm_internal(int useDeviceID,
  3951. const byte* key, word32 keySz,
  3952. const byte* iv, word32 ivSz,
  3953. const char* encLabel, const char* decLabel)
  3954. {
  3955. int ret = 0, i, count = 0, times, pending = 0;
  3956. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3957. sizeof(Aes), HEAP_HINT);
  3958. #ifdef HAVE_AES_DECRYPT
  3959. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3960. sizeof(Aes), HEAP_HINT);
  3961. #endif
  3962. double start;
  3963. DECLARE_MULTI_VALUE_STATS_VARS()
  3964. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3965. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3966. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3967. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3968. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3969. sizeof(Aes), HEAP_HINT);
  3970. #ifdef HAVE_AES_DECRYPT
  3971. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3972. sizeof(Aes), HEAP_HINT);
  3973. #endif
  3974. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  3975. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  3976. /* init keys */
  3977. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3978. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3979. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3980. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3981. goto exit;
  3982. }
  3983. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  3984. if (ret != 0) {
  3985. printf("AesGcmSetKey failed, ret = %d\n", ret);
  3986. goto exit;
  3987. }
  3988. }
  3989. /* GCM uses same routine in backend for both encrypt and decrypt */
  3990. bench_stats_start(&count, &start);
  3991. do {
  3992. for (times = 0; times < numBlocks || pending > 0; ) {
  3993. bench_async_poll(&pending);
  3994. /* while free pending slots in queue, submit ops */
  3995. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3996. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3997. &times, numBlocks, &pending)) {
  3998. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  3999. bench_plain, bench_size,
  4000. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4001. bench_additional, aesAuthAddSz);
  4002. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4003. 0, &times, &pending)) {
  4004. goto exit_aes_gcm;
  4005. }
  4006. }
  4007. } /* for i */
  4008. RECORD_MULTI_VALUE_STATS();
  4009. } /* for times */
  4010. count += times;
  4011. } while (bench_stats_check(start)
  4012. #ifdef MULTI_VALUE_STATISTICS
  4013. || runs < minimum_runs
  4014. #endif
  4015. );
  4016. exit_aes_gcm:
  4017. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4018. start, ret);
  4019. #ifdef MULTI_VALUE_STATISTICS
  4020. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4021. #endif
  4022. #ifdef HAVE_AES_DECRYPT
  4023. RESET_MULTI_VALUE_STATS_VARS();
  4024. /* init keys */
  4025. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4026. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4027. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4028. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4029. goto exit;
  4030. }
  4031. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4032. if (ret != 0) {
  4033. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4034. goto exit;
  4035. }
  4036. }
  4037. bench_stats_start(&count, &start);
  4038. do {
  4039. for (times = 0; times < numBlocks || pending > 0; ) {
  4040. bench_async_poll(&pending);
  4041. /* while free pending slots in queue, submit ops */
  4042. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4043. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4044. &times, numBlocks, &pending)) {
  4045. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4046. bench_cipher, bench_size,
  4047. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4048. bench_additional, aesAuthAddSz);
  4049. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4050. 0, &times, &pending)) {
  4051. goto exit_aes_gcm_dec;
  4052. }
  4053. }
  4054. } /* for i */
  4055. RECORD_MULTI_VALUE_STATS();
  4056. } /* for times */
  4057. count += times;
  4058. } while (bench_stats_check(start)
  4059. #ifdef MULTI_VALUE_STATISTICS
  4060. || runs < minimum_runs
  4061. #endif
  4062. );
  4063. exit_aes_gcm_dec:
  4064. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4065. start, ret);
  4066. #ifdef MULTI_VALUE_STATISTICS
  4067. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4068. #endif
  4069. #endif /* HAVE_AES_DECRYPT */
  4070. (void)decLabel;
  4071. exit:
  4072. if (ret < 0) {
  4073. printf("bench_aesgcm failed: %d\n", ret);
  4074. }
  4075. #ifdef HAVE_AES_DECRYPT
  4076. if (WC_ARRAY_OK(dec)) {
  4077. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4078. wc_AesFree(dec[i]);
  4079. }
  4080. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4081. }
  4082. #endif
  4083. if (WC_ARRAY_OK(enc)) {
  4084. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4085. wc_AesFree(enc[i]);
  4086. }
  4087. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4088. }
  4089. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4090. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4091. }
  4092. #ifdef WOLFSSL_AESGCM_STREAM
  4093. static void bench_aesgcm_stream_internal(int useDeviceID,
  4094. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4095. const char* encLabel, const char* decLabel)
  4096. {
  4097. int ret = 0, i, count = 0, times, pending = 0;
  4098. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4099. sizeof(Aes), HEAP_HINT);
  4100. #ifdef HAVE_AES_DECRYPT
  4101. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4102. sizeof(Aes), HEAP_HINT);
  4103. #endif
  4104. double start;
  4105. DECLARE_MULTI_VALUE_STATS_VARS()
  4106. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4107. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4108. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4109. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4110. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4111. sizeof(Aes), HEAP_HINT);
  4112. #ifdef HAVE_AES_DECRYPT
  4113. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4114. sizeof(Aes), HEAP_HINT);
  4115. #endif
  4116. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4117. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4118. /* init keys */
  4119. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4120. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4121. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4122. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4123. goto exit;
  4124. }
  4125. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4126. if (ret != 0) {
  4127. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4128. goto exit;
  4129. }
  4130. }
  4131. /* GCM uses same routine in backend for both encrypt and decrypt */
  4132. bench_stats_start(&count, &start);
  4133. do {
  4134. for (times = 0; times < numBlocks || pending > 0; ) {
  4135. bench_async_poll(&pending);
  4136. /* while free pending slots in queue, submit ops */
  4137. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4138. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4139. &times, numBlocks, &pending)) {
  4140. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4141. if (ret == 0) {
  4142. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4143. bench_plain, bench_size, bench_additional,
  4144. aesAuthAddSz);
  4145. }
  4146. if (ret == 0) {
  4147. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4148. AES_AUTH_TAG_SZ);
  4149. }
  4150. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4151. 0, &times, &pending)) {
  4152. goto exit_aes_gcm;
  4153. }
  4154. }
  4155. } /* for i */
  4156. RECORD_MULTI_VALUE_STATS();
  4157. } /* for times */
  4158. count += times;
  4159. } while (bench_stats_check(start)
  4160. #ifdef MULTI_VALUE_STATISTICS
  4161. || runs < minimum_runs
  4162. #endif
  4163. );
  4164. exit_aes_gcm:
  4165. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4166. start, ret);
  4167. #ifdef MULTI_VALUE_STATISTICS
  4168. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4169. #endif
  4170. #ifdef HAVE_AES_DECRYPT
  4171. /* init keys */
  4172. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4173. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4174. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4175. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4176. goto exit;
  4177. }
  4178. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4179. if (ret != 0) {
  4180. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4181. goto exit;
  4182. }
  4183. }
  4184. RESET_MULTI_VALUE_STATS_VARS();
  4185. bench_stats_start(&count, &start);
  4186. do {
  4187. for (times = 0; times < numBlocks || pending > 0; ) {
  4188. bench_async_poll(&pending);
  4189. /* while free pending slots in queue, submit ops */
  4190. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4191. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4192. &times, numBlocks, &pending)) {
  4193. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4194. if (ret == 0) {
  4195. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4196. bench_cipher, bench_size, bench_additional,
  4197. aesAuthAddSz);
  4198. }
  4199. if (ret == 0) {
  4200. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4201. AES_AUTH_TAG_SZ);
  4202. }
  4203. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4204. 0, &times, &pending)) {
  4205. goto exit_aes_gcm_dec;
  4206. }
  4207. }
  4208. } /* for i */
  4209. RECORD_MULTI_VALUE_STATS();
  4210. } /* for times */
  4211. count += times;
  4212. } while (bench_stats_check(start)
  4213. #ifdef MULTI_VALUE_STATISTICS
  4214. || runs < minimum_runs
  4215. #endif
  4216. );
  4217. exit_aes_gcm_dec:
  4218. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4219. start, ret);
  4220. #ifdef MULTI_VALUE_STATISTICS
  4221. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4222. #endif
  4223. #endif /* HAVE_AES_DECRYPT */
  4224. (void)decLabel;
  4225. exit:
  4226. if (ret < 0) {
  4227. printf("bench_aesgcm failed: %d\n", ret);
  4228. }
  4229. #ifdef HAVE_AES_DECRYPT
  4230. if (WC_ARRAY_OK(dec)) {
  4231. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4232. wc_AesFree(dec[i]);
  4233. }
  4234. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4235. }
  4236. #endif
  4237. if (WC_ARRAY_OK(enc)) {
  4238. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4239. wc_AesFree(enc[i]);
  4240. }
  4241. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4242. }
  4243. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4244. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4245. }
  4246. #endif
  4247. void bench_aesgcm(int useDeviceID)
  4248. {
  4249. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4250. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4251. && !defined(WOLFSSL_XILINX_CRYPT) \
  4252. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4253. #ifdef HAVE_RENESAS_SYNC
  4254. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4255. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4256. #else
  4257. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4258. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4259. #endif
  4260. #endif
  4261. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4262. && !defined(WOLFSSL_XILINX_CRYPT)
  4263. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4264. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4265. #endif
  4266. #ifdef WOLFSSL_AES_256
  4267. #ifdef HAVE_RENESAS_SYNC
  4268. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4269. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4270. #else
  4271. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4272. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4273. #endif
  4274. #endif
  4275. #ifdef WOLFSSL_AESGCM_STREAM
  4276. #undef AES_GCM_STRING
  4277. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4278. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4279. && !defined(WOLFSSL_XILINX_CRYPT) \
  4280. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4281. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4282. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4283. #endif
  4284. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4285. && !defined(WOLFSSL_XILINX_CRYPT)
  4286. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4287. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4288. #endif
  4289. #ifdef WOLFSSL_AES_256
  4290. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4291. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4292. #endif
  4293. #endif /* WOLFSSL_AESGCM_STREAM */
  4294. #undef AES_GCM_STRING
  4295. }
  4296. /* GMAC */
  4297. void bench_gmac(int useDeviceID)
  4298. {
  4299. int ret, count = 0;
  4300. Gmac gmac;
  4301. double start;
  4302. byte tag[AES_AUTH_TAG_SZ];
  4303. DECLARE_MULTI_VALUE_STATS_VARS()
  4304. /* determine GCM GHASH method */
  4305. #ifdef GCM_SMALL
  4306. const char* gmacStr = "GMAC Small";
  4307. #elif defined(GCM_TABLE)
  4308. const char* gmacStr = "GMAC Table";
  4309. #elif defined(GCM_TABLE_4BIT)
  4310. const char* gmacStr = "GMAC Table 4-bit";
  4311. #elif defined(GCM_WORD32)
  4312. const char* gmacStr = "GMAC Word32";
  4313. #else
  4314. const char* gmacStr = "GMAC Default";
  4315. #endif
  4316. /* init keys */
  4317. XMEMSET(bench_plain, 0, bench_size);
  4318. XMEMSET(tag, 0, sizeof(tag));
  4319. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4320. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4321. useDeviceID ? devId: INVALID_DEVID);
  4322. #ifdef HAVE_RENESAS_SYNC
  4323. wc_GmacSetKey(&gmac, bench_key1, 16);
  4324. #else
  4325. wc_GmacSetKey(&gmac, bench_key, 16);
  4326. #endif
  4327. bench_stats_start(&count, &start);
  4328. do {
  4329. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4330. tag, sizeof(tag));
  4331. count++;
  4332. RECORD_MULTI_VALUE_STATS();
  4333. } while (bench_stats_check(start)
  4334. #ifdef MULTI_VALUE_STATISTICS
  4335. || runs < minimum_runs
  4336. #endif
  4337. );
  4338. wc_AesFree((Aes*)&gmac);
  4339. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4340. #ifdef MULTI_VALUE_STATISTICS
  4341. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4342. #endif
  4343. }
  4344. #endif /* HAVE_AESGCM */
  4345. #ifdef HAVE_AES_ECB
  4346. static void bench_aesecb_internal(int useDeviceID,
  4347. const byte* key, word32 keySz,
  4348. const char* encLabel, const char* decLabel)
  4349. {
  4350. int ret = 0, i, count = 0, times, pending = 0;
  4351. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4352. sizeof(Aes), HEAP_HINT);
  4353. double start;
  4354. DECLARE_MULTI_VALUE_STATS_VARS()
  4355. #ifdef HAVE_FIPS
  4356. const word32 benchSz = AES_BLOCK_SIZE;
  4357. #else
  4358. const word32 benchSz = bench_size;
  4359. #endif
  4360. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4361. sizeof(Aes), HEAP_HINT);
  4362. /* init keys */
  4363. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4364. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4365. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4366. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4367. goto exit;
  4368. }
  4369. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4370. if (ret != 0) {
  4371. printf("AesSetKey failed, ret = %d\n", ret);
  4372. goto exit;
  4373. }
  4374. }
  4375. bench_stats_start(&count, &start);
  4376. do {
  4377. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4378. for (times = 0;
  4379. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4380. ) {
  4381. bench_async_poll(&pending);
  4382. /* while free pending slots in queue, submit ops */
  4383. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4384. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4385. &times, outer_loop_limit, &pending)) {
  4386. #ifdef HAVE_FIPS
  4387. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4388. #else
  4389. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4390. benchSz);
  4391. #endif
  4392. ret = 0;
  4393. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4394. 0, &times, &pending)) {
  4395. goto exit_aes_enc;
  4396. }
  4397. }
  4398. } /* for i */
  4399. RECORD_MULTI_VALUE_STATS();
  4400. } /* for times */
  4401. count += times;
  4402. } while (bench_stats_check(start)
  4403. #ifdef MULTI_VALUE_STATISTICS
  4404. || runs < minimum_runs
  4405. #endif
  4406. );
  4407. exit_aes_enc:
  4408. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4409. start, ret);
  4410. #ifdef MULTI_VALUE_STATISTICS
  4411. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4412. #endif
  4413. #ifdef HAVE_AES_DECRYPT
  4414. /* init keys */
  4415. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4416. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4417. if (ret != 0) {
  4418. printf("AesSetKey failed, ret = %d\n", ret);
  4419. goto exit;
  4420. }
  4421. }
  4422. RESET_MULTI_VALUE_STATS_VARS();
  4423. bench_stats_start(&count, &start);
  4424. do {
  4425. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4426. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4427. bench_async_poll(&pending);
  4428. /* while free pending slots in queue, submit ops */
  4429. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4430. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4431. &times, outer_loop_limit, &pending)) {
  4432. #ifdef HAVE_FIPS
  4433. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4434. #else
  4435. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4436. benchSz);
  4437. #endif
  4438. ret = 0;
  4439. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4440. 0, &times, &pending)) {
  4441. goto exit_aes_dec;
  4442. }
  4443. }
  4444. } /* for i */
  4445. RECORD_MULTI_VALUE_STATS();
  4446. } /* for times */
  4447. count += times;
  4448. } while (bench_stats_check(start)
  4449. #ifdef MULTI_VALUE_STATISTICS
  4450. || runs < minimum_runs
  4451. #endif
  4452. );
  4453. exit_aes_dec:
  4454. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4455. start, ret);
  4456. #ifdef MULTI_VALUE_STATISTICS
  4457. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4458. #endif
  4459. #endif /* HAVE_AES_DECRYPT */
  4460. (void)decLabel;
  4461. exit:
  4462. if (WC_ARRAY_OK(enc)) {
  4463. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4464. wc_AesFree(enc[i]);
  4465. }
  4466. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4467. }
  4468. }
  4469. void bench_aesecb(int useDeviceID)
  4470. {
  4471. #ifdef WOLFSSL_AES_128
  4472. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4473. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4474. #endif
  4475. #ifdef WOLFSSL_AES_192
  4476. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4477. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4478. #endif
  4479. #ifdef WOLFSSL_AES_256
  4480. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4481. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4482. #endif
  4483. }
  4484. #endif /* HAVE_AES_ECB */
  4485. #ifdef WOLFSSL_AES_CFB
  4486. static void bench_aescfb_internal(const byte* key,
  4487. word32 keySz, const byte* iv,
  4488. const char* label)
  4489. {
  4490. Aes enc;
  4491. double start;
  4492. int i, ret, count;
  4493. DECLARE_MULTI_VALUE_STATS_VARS()
  4494. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4495. if (ret != 0) {
  4496. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4497. return;
  4498. }
  4499. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4500. if (ret != 0) {
  4501. printf("AesSetKey failed, ret = %d\n", ret);
  4502. goto out;
  4503. }
  4504. bench_stats_start(&count, &start);
  4505. do {
  4506. for (i = 0; i < numBlocks; i++) {
  4507. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4508. bench_size)) != 0) {
  4509. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4510. goto out;
  4511. }
  4512. RECORD_MULTI_VALUE_STATS();
  4513. }
  4514. count += i;
  4515. } while (bench_stats_check(start)
  4516. #ifdef MULTI_VALUE_STATISTICS
  4517. || runs < minimum_runs
  4518. #endif
  4519. );
  4520. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4521. #ifdef MULTI_VALUE_STATISTICS
  4522. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4523. #endif
  4524. out:
  4525. wc_AesFree(&enc);
  4526. return;
  4527. }
  4528. void bench_aescfb(void)
  4529. {
  4530. #ifdef WOLFSSL_AES_128
  4531. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4532. #endif
  4533. #ifdef WOLFSSL_AES_192
  4534. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4535. #endif
  4536. #ifdef WOLFSSL_AES_256
  4537. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4538. #endif
  4539. }
  4540. #endif /* WOLFSSL_AES_CFB */
  4541. #ifdef WOLFSSL_AES_OFB
  4542. static void bench_aesofb_internal(const byte* key,
  4543. word32 keySz, const byte* iv,
  4544. const char* label)
  4545. {
  4546. Aes enc;
  4547. double start;
  4548. int i, ret, count;
  4549. DECLARE_MULTI_VALUE_STATS_VARS()
  4550. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4551. if (ret != 0) {
  4552. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4553. return;
  4554. }
  4555. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4556. if (ret != 0) {
  4557. printf("AesSetKey failed, ret = %d\n", ret);
  4558. return;
  4559. }
  4560. bench_stats_start(&count, &start);
  4561. do {
  4562. for (i = 0; i < numBlocks; i++) {
  4563. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4564. bench_size)) != 0) {
  4565. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4566. return;
  4567. }
  4568. RECORD_MULTI_VALUE_STATS();
  4569. }
  4570. count += i;
  4571. } while (bench_stats_check(start)
  4572. #ifdef MULTI_VALUE_STATISTICS
  4573. || runs < minimum_runs
  4574. #endif
  4575. );
  4576. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4577. #ifdef MULTI_VALUE_STATISTICS
  4578. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4579. #endif
  4580. wc_AesFree(&enc);
  4581. }
  4582. void bench_aesofb(void)
  4583. {
  4584. #ifdef WOLFSSL_AES_128
  4585. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4586. #endif
  4587. #ifdef WOLFSSL_AES_192
  4588. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4589. #endif
  4590. #ifdef WOLFSSL_AES_256
  4591. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4592. #endif
  4593. }
  4594. #endif /* WOLFSSL_AES_CFB */
  4595. #ifdef WOLFSSL_AES_XTS
  4596. void bench_aesxts(void)
  4597. {
  4598. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4599. double start;
  4600. int i, count, ret;
  4601. DECLARE_MULTI_VALUE_STATS_VARS()
  4602. static const unsigned char k1[] = {
  4603. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4604. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4605. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4606. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4607. };
  4608. static const unsigned char i1[] = {
  4609. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4610. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4611. };
  4612. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4613. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4614. HEAP_HINT, devId);
  4615. if (ret != 0) {
  4616. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4617. goto exit;
  4618. }
  4619. bench_stats_start(&count, &start);
  4620. do {
  4621. for (i = 0; i < numBlocks; i++) {
  4622. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4623. bench_size, i1, sizeof(i1))) != 0) {
  4624. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4625. goto exit;
  4626. }
  4627. RECORD_MULTI_VALUE_STATS();
  4628. }
  4629. count += i;
  4630. } while (bench_stats_check(start)
  4631. #ifdef MULTI_VALUE_STATISTICS
  4632. || runs < minimum_runs
  4633. #endif
  4634. );
  4635. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4636. #ifdef MULTI_VALUE_STATISTICS
  4637. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4638. #endif
  4639. wc_AesXtsFree(aes);
  4640. /* decryption benchmark */
  4641. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4642. HEAP_HINT, devId);
  4643. if (ret != 0) {
  4644. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4645. goto exit;
  4646. }
  4647. RESET_MULTI_VALUE_STATS_VARS();
  4648. bench_stats_start(&count, &start);
  4649. do {
  4650. for (i = 0; i < numBlocks; i++) {
  4651. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4652. bench_size, i1, sizeof(i1))) != 0) {
  4653. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4654. goto exit;
  4655. }
  4656. RECORD_MULTI_VALUE_STATS();
  4657. }
  4658. count += i;
  4659. } while (bench_stats_check(start)
  4660. #ifdef MULTI_VALUE_STATISTICS
  4661. || runs < minimum_runs
  4662. #endif
  4663. );
  4664. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4665. #ifdef MULTI_VALUE_STATISTICS
  4666. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4667. #endif
  4668. exit:
  4669. wc_AesXtsFree(aes);
  4670. WC_FREE_VAR(aes, HEAP_HINT);
  4671. }
  4672. #endif /* WOLFSSL_AES_XTS */
  4673. #ifdef WOLFSSL_AES_COUNTER
  4674. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4675. const byte* iv, const char* label,
  4676. int useDeviceID)
  4677. {
  4678. Aes enc;
  4679. double start;
  4680. int i, count, ret = 0;
  4681. DECLARE_MULTI_VALUE_STATS_VARS()
  4682. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4683. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4684. printf("wc_AesInit failed, ret = %d\n", ret);
  4685. }
  4686. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4687. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4688. return;
  4689. }
  4690. bench_stats_start(&count, &start);
  4691. do {
  4692. for (i = 0; i < numBlocks; i++) {
  4693. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4694. bench_size)) != 0) {
  4695. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4696. return;
  4697. }
  4698. RECORD_MULTI_VALUE_STATS();
  4699. }
  4700. count += i;
  4701. } while (bench_stats_check(start)
  4702. #ifdef MULTI_VALUE_STATISTICS
  4703. || runs < minimum_runs
  4704. #endif
  4705. );
  4706. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4707. #ifdef MULTI_VALUE_STATISTICS
  4708. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4709. #endif
  4710. wc_AesFree(&enc);
  4711. }
  4712. void bench_aesctr(int useDeviceID)
  4713. {
  4714. #ifdef WOLFSSL_AES_128
  4715. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4716. #endif
  4717. #ifdef WOLFSSL_AES_192
  4718. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4719. #endif
  4720. #ifdef WOLFSSL_AES_256
  4721. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4722. #endif
  4723. }
  4724. #endif /* WOLFSSL_AES_COUNTER */
  4725. #ifdef HAVE_AESCCM
  4726. void bench_aesccm(int useDeviceID)
  4727. {
  4728. Aes enc;
  4729. int enc_inited = 0;
  4730. double start;
  4731. int ret, i, count;
  4732. DECLARE_MULTI_VALUE_STATS_VARS()
  4733. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4734. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4735. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4736. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4737. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4738. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4739. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4740. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4741. {
  4742. printf("wc_AesInit failed, ret = %d\n", ret);
  4743. goto exit;
  4744. }
  4745. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4746. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4747. goto exit;
  4748. }
  4749. enc_inited = 1;
  4750. bench_stats_start(&count, &start);
  4751. do {
  4752. for (i = 0; i < numBlocks; i++) {
  4753. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4754. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4755. bench_additional, 0);
  4756. RECORD_MULTI_VALUE_STATS();
  4757. }
  4758. count += i;
  4759. } while (bench_stats_check(start)
  4760. #ifdef MULTI_VALUE_STATISTICS
  4761. || runs < minimum_runs
  4762. #endif
  4763. );
  4764. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4765. bench_size, start, ret);
  4766. #ifdef MULTI_VALUE_STATISTICS
  4767. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4768. #endif
  4769. if (ret != 0) {
  4770. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4771. goto exit;
  4772. }
  4773. #ifdef HAVE_AES_DECRYPT
  4774. RESET_MULTI_VALUE_STATS_VARS();
  4775. bench_stats_start(&count, &start);
  4776. do {
  4777. for (i = 0; i < numBlocks; i++) {
  4778. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4779. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4780. bench_additional, 0);
  4781. RECORD_MULTI_VALUE_STATS();
  4782. }
  4783. count += i;
  4784. } while (bench_stats_check(start)
  4785. #ifdef MULTI_VALUE_STATISTICS
  4786. || runs < minimum_runs
  4787. #endif
  4788. );
  4789. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4790. bench_size, start, ret);
  4791. #ifdef MULTI_VALUE_STATISTICS
  4792. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4793. #endif
  4794. if (ret != 0) {
  4795. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4796. goto exit;
  4797. }
  4798. #endif
  4799. exit:
  4800. if (enc_inited)
  4801. wc_AesFree(&enc);
  4802. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4803. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4804. }
  4805. #endif /* HAVE_AESCCM */
  4806. #ifdef WOLFSSL_AES_SIV
  4807. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4808. encLabel, const char* decLabel)
  4809. {
  4810. int i;
  4811. int ret = 0;
  4812. byte assoc[AES_BLOCK_SIZE];
  4813. byte nonce[AES_BLOCK_SIZE];
  4814. byte siv[AES_BLOCK_SIZE];
  4815. int count = 0;
  4816. double start;
  4817. DECLARE_MULTI_VALUE_STATS_VARS()
  4818. bench_stats_start(&count, &start);
  4819. do {
  4820. for (i = 0; i < numBlocks; i++) {
  4821. ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4822. AES_BLOCK_SIZE, bench_plain, bench_size,
  4823. siv, bench_cipher);
  4824. if (ret != 0) {
  4825. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4826. return;
  4827. }
  4828. RECORD_MULTI_VALUE_STATS();
  4829. }
  4830. count += i;
  4831. } while (bench_stats_check(start)
  4832. #ifdef MULTI_VALUE_STATISTICS
  4833. || runs < minimum_runs
  4834. #endif
  4835. );
  4836. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4837. #ifdef MULTI_VALUE_STATISTICS
  4838. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4839. #endif
  4840. RESET_MULTI_VALUE_STATS_VARS();
  4841. bench_stats_start(&count, &start);
  4842. do {
  4843. for (i = 0; i < numBlocks; i++) {
  4844. ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4845. AES_BLOCK_SIZE, bench_cipher, bench_size,
  4846. siv, bench_plain);
  4847. if (ret != 0) {
  4848. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4849. return;
  4850. }
  4851. RECORD_MULTI_VALUE_STATS();
  4852. }
  4853. count += i;
  4854. } while (bench_stats_check(start)
  4855. #ifdef MULTI_VALUE_STATISTICS
  4856. || runs < minimum_runs
  4857. #endif
  4858. );
  4859. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4860. #ifdef MULTI_VALUE_STATISTICS
  4861. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4862. #endif
  4863. }
  4864. void bench_aessiv(void)
  4865. {
  4866. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4867. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4868. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4869. }
  4870. #endif /* WOLFSSL_AES_SIV */
  4871. #endif /* !NO_AES */
  4872. #ifdef HAVE_POLY1305
  4873. void bench_poly1305(void)
  4874. {
  4875. Poly1305 enc;
  4876. byte mac[16];
  4877. double start;
  4878. int ret = 0, i, count;
  4879. DECLARE_MULTI_VALUE_STATS_VARS()
  4880. if (digest_stream) {
  4881. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4882. if (ret != 0) {
  4883. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4884. return;
  4885. }
  4886. bench_stats_start(&count, &start);
  4887. do {
  4888. for (i = 0; i < numBlocks; i++) {
  4889. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4890. if (ret != 0) {
  4891. printf("Poly1305Update failed: %d\n", ret);
  4892. break;
  4893. }
  4894. RECORD_MULTI_VALUE_STATS();
  4895. }
  4896. wc_Poly1305Final(&enc, mac);
  4897. count += i;
  4898. } while (bench_stats_check(start)
  4899. #ifdef MULTI_VALUE_STATISTICS
  4900. || runs < minimum_runs
  4901. #endif
  4902. );
  4903. }
  4904. else {
  4905. bench_stats_start(&count, &start);
  4906. do {
  4907. for (i = 0; i < numBlocks; i++) {
  4908. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4909. if (ret != 0) {
  4910. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4911. return;
  4912. }
  4913. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4914. if (ret != 0) {
  4915. printf("Poly1305Update failed: %d\n", ret);
  4916. break;
  4917. }
  4918. wc_Poly1305Final(&enc, mac);
  4919. RECORD_MULTI_VALUE_STATS();
  4920. }
  4921. count += i;
  4922. } while (bench_stats_check(start)
  4923. #ifdef MULTI_VALUE_STATISTICS
  4924. || runs < minimum_runs
  4925. #endif
  4926. );
  4927. }
  4928. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4929. #ifdef MULTI_VALUE_STATISTICS
  4930. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4931. #endif
  4932. }
  4933. #endif /* HAVE_POLY1305 */
  4934. #ifdef HAVE_CAMELLIA
  4935. void bench_camellia(void)
  4936. {
  4937. Camellia cam;
  4938. double start;
  4939. int ret, i, count;
  4940. DECLARE_MULTI_VALUE_STATS_VARS()
  4941. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4942. if (ret != 0) {
  4943. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4944. return;
  4945. }
  4946. bench_stats_start(&count, &start);
  4947. do {
  4948. for (i = 0; i < numBlocks; i++) {
  4949. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4950. bench_size);
  4951. if (ret < 0) {
  4952. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4953. return;
  4954. }
  4955. RECORD_MULTI_VALUE_STATS();
  4956. }
  4957. count += i;
  4958. } while (bench_stats_check(start)
  4959. #ifdef MULTI_VALUE_STATISTICS
  4960. || runs < minimum_runs
  4961. #endif
  4962. );
  4963. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  4964. #ifdef MULTI_VALUE_STATISTICS
  4965. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4966. #endif
  4967. }
  4968. #endif
  4969. #ifdef WOLFSSL_SM4_CBC
  4970. void bench_sm4_cbc(void)
  4971. {
  4972. wc_Sm4 sm4;
  4973. double start;
  4974. int ret;
  4975. int i;
  4976. int count;
  4977. DECLARE_MULTI_VALUE_STATS_VARS()
  4978. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  4979. if (ret != 0) {
  4980. printf("Sm4SetKey failed, ret = %d\n", ret);
  4981. return;
  4982. }
  4983. ret = wc_Sm4SetIV(&sm4, bench_iv);
  4984. if (ret != 0) {
  4985. printf("Sm4SetIV failed, ret = %d\n", ret);
  4986. return;
  4987. }
  4988. bench_stats_start(&count, &start);
  4989. do {
  4990. for (i = 0; i < numBlocks; i++) {
  4991. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  4992. if (ret < 0) {
  4993. printf("Sm4CbcEncrypt failed: %d\n", ret);
  4994. return;
  4995. }
  4996. RECORD_MULTI_VALUE_STATS();
  4997. }
  4998. count += i;
  4999. } while (bench_stats_check(start)
  5000. #ifdef MULTI_VALUE_STATISTICS
  5001. || runs < minimum_runs
  5002. #endif
  5003. );
  5004. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5005. #ifdef MULTI_VALUE_STATISTICS
  5006. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5007. #endif
  5008. RESET_MULTI_VALUE_STATS_VARS();
  5009. bench_stats_start(&count, &start);
  5010. do {
  5011. for (i = 0; i < numBlocks; i++) {
  5012. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5013. if (ret < 0) {
  5014. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5015. return;
  5016. }
  5017. RECORD_MULTI_VALUE_STATS();
  5018. }
  5019. count += i;
  5020. } while (bench_stats_check(start)
  5021. #ifdef MULTI_VALUE_STATISTICS
  5022. || runs < minimum_runs
  5023. #endif
  5024. );
  5025. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5026. #ifdef MULTI_VALUE_STATISTICS
  5027. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5028. #endif
  5029. }
  5030. #endif
  5031. #ifdef WOLFSSL_SM4_GCM
  5032. void bench_sm4_gcm(void)
  5033. {
  5034. wc_Sm4 sm4;
  5035. double start;
  5036. int ret;
  5037. int i;
  5038. int count;
  5039. DECLARE_MULTI_VALUE_STATS_VARS()
  5040. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5041. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5042. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5043. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5044. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5045. if (ret != 0) {
  5046. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5047. goto exit;
  5048. }
  5049. bench_stats_start(&count, &start);
  5050. do {
  5051. for (i = 0; i < numBlocks; i++) {
  5052. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5053. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5054. bench_additional, aesAuthAddSz);
  5055. if (ret < 0) {
  5056. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5057. goto exit;
  5058. }
  5059. RECORD_MULTI_VALUE_STATS();
  5060. }
  5061. count += i;
  5062. } while (bench_stats_check(start)
  5063. #ifdef MULTI_VALUE_STATISTICS
  5064. || runs < minimum_runs
  5065. #endif
  5066. );
  5067. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5068. #ifdef MULTI_VALUE_STATISTICS
  5069. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5070. #endif
  5071. RESET_MULTI_VALUE_STATS_VARS();
  5072. bench_stats_start(&count, &start);
  5073. do {
  5074. for (i = 0; i < numBlocks; i++) {
  5075. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5076. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5077. bench_additional, aesAuthAddSz);
  5078. if (ret < 0) {
  5079. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5080. goto exit;
  5081. }
  5082. RECORD_MULTI_VALUE_STATS();
  5083. }
  5084. count += i;
  5085. } while (bench_stats_check(start)
  5086. #ifdef MULTI_VALUE_STATISTICS
  5087. || runs < minimum_runs
  5088. #endif
  5089. );
  5090. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5091. #ifdef MULTI_VALUE_STATISTICS
  5092. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5093. #endif
  5094. exit:
  5095. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5096. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5097. }
  5098. #endif
  5099. #ifdef WOLFSSL_SM4_CCM
  5100. void bench_sm4_ccm(void)
  5101. {
  5102. wc_Sm4 enc;
  5103. double start;
  5104. int ret, i, count;
  5105. DECLARE_MULTI_VALUE_STATS_VARS()
  5106. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5107. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5108. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5109. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5110. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5111. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5112. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5113. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5114. goto exit;
  5115. }
  5116. bench_stats_start(&count, &start);
  5117. do {
  5118. for (i = 0; i < numBlocks; i++) {
  5119. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5120. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5121. bench_additional, 0);
  5122. RECORD_MULTI_VALUE_STATS();
  5123. }
  5124. count += i;
  5125. } while (bench_stats_check(start)
  5126. #ifdef MULTI_VALUE_STATISTICS
  5127. || runs < minimum_runs
  5128. #endif
  5129. );
  5130. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5131. #ifdef MULTI_VALUE_STATISTICS
  5132. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5133. #endif
  5134. if (ret != 0) {
  5135. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5136. goto exit;
  5137. }
  5138. RESET_MULTI_VALUE_STATS_VARS();
  5139. bench_stats_start(&count, &start);
  5140. do {
  5141. for (i = 0; i < numBlocks; i++) {
  5142. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5143. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5144. bench_additional, 0);
  5145. RECORD_MULTI_VALUE_STATS();
  5146. }
  5147. count += i;
  5148. } while (bench_stats_check(start)
  5149. #ifdef MULTI_VALUE_STATISTICS
  5150. || runs < minimum_runs
  5151. #endif
  5152. );
  5153. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5154. #ifdef MULTI_VALUE_STATISTICS
  5155. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5156. #endif
  5157. if (ret != 0) {
  5158. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5159. goto exit;
  5160. }
  5161. exit:
  5162. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5163. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5164. }
  5165. #endif /* HAVE_AESCCM */
  5166. #ifndef NO_DES3
  5167. void bench_des(int useDeviceID)
  5168. {
  5169. int ret = 0, i, count = 0, times, pending = 0;
  5170. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5171. sizeof(Des3), HEAP_HINT);
  5172. double start;
  5173. DECLARE_MULTI_VALUE_STATS_VARS()
  5174. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5175. sizeof(Des3), HEAP_HINT);
  5176. /* init keys */
  5177. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5178. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5179. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5180. printf("Des3Init failed, ret = %d\n", ret);
  5181. goto exit;
  5182. }
  5183. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5184. if (ret != 0) {
  5185. printf("Des3_SetKey failed, ret = %d\n", ret);
  5186. goto exit;
  5187. }
  5188. }
  5189. bench_stats_start(&count, &start);
  5190. do {
  5191. for (times = 0; times < numBlocks || pending > 0; ) {
  5192. bench_async_poll(&pending);
  5193. /* while free pending slots in queue, submit ops */
  5194. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5195. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5196. &times, numBlocks, &pending)) {
  5197. ret = wc_Des3_CbcEncrypt(enc[i],
  5198. bench_cipher,
  5199. bench_plain, bench_size);
  5200. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5201. 0, &times, &pending)) {
  5202. goto exit_3des;
  5203. }
  5204. }
  5205. } /* for i */
  5206. RECORD_MULTI_VALUE_STATS();
  5207. } /* for times */
  5208. count += times;
  5209. } while (bench_stats_check(start)
  5210. #ifdef MULTI_VALUE_STATISTICS
  5211. || runs < minimum_runs
  5212. #endif
  5213. );
  5214. exit_3des:
  5215. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5216. #ifdef MULTI_VALUE_STATISTICS
  5217. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5218. #endif
  5219. exit:
  5220. if (WC_ARRAY_OK(enc)) {
  5221. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5222. wc_Des3Free(enc[i]);
  5223. }
  5224. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5225. }
  5226. }
  5227. #endif /* !NO_DES3 */
  5228. #ifndef NO_RC4
  5229. void bench_arc4(int useDeviceID)
  5230. {
  5231. int ret = 0, i, count = 0, times, pending = 0;
  5232. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5233. sizeof(Arc4), HEAP_HINT);
  5234. double start;
  5235. DECLARE_MULTI_VALUE_STATS_VARS()
  5236. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5237. sizeof(Arc4), HEAP_HINT);
  5238. /* init keys */
  5239. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5240. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5241. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5242. printf("Arc4Init failed, ret = %d\n", ret);
  5243. goto exit;
  5244. }
  5245. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5246. if (ret != 0) {
  5247. printf("Arc4SetKey failed, ret = %d\n", ret);
  5248. goto exit;
  5249. }
  5250. }
  5251. bench_stats_start(&count, &start);
  5252. do {
  5253. for (times = 0; times < numBlocks || pending > 0; ) {
  5254. bench_async_poll(&pending);
  5255. /* while free pending slots in queue, submit ops */
  5256. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5257. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5258. &times, numBlocks, &pending)) {
  5259. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5260. bench_size);
  5261. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5262. 0, &times, &pending)) {
  5263. goto exit_arc4;
  5264. }
  5265. }
  5266. } /* for i */
  5267. RECORD_MULTI_VALUE_STATS();
  5268. } /* for times */
  5269. count += times;
  5270. } while (bench_stats_check(start)
  5271. #ifdef MULTI_VALUE_STATISTICS
  5272. || runs < minimum_runs
  5273. #endif
  5274. );
  5275. exit_arc4:
  5276. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5277. #ifdef MULTI_VALUE_STATISTICS
  5278. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5279. #endif
  5280. exit:
  5281. if (WC_ARRAY_OK(enc)) {
  5282. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5283. wc_Arc4Free(enc[i]);
  5284. }
  5285. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5286. }
  5287. }
  5288. #endif /* !NO_RC4 */
  5289. #ifdef HAVE_CHACHA
  5290. void bench_chacha(void)
  5291. {
  5292. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5293. double start;
  5294. int ret, i, count;
  5295. DECLARE_MULTI_VALUE_STATS_VARS()
  5296. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5297. XMEMSET(enc, 0, sizeof(ChaCha));
  5298. wc_Chacha_SetKey(enc, bench_key, 16);
  5299. if (encrypt_only) {
  5300. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5301. if (ret < 0) {
  5302. printf("wc_Chacha_SetIV error: %d\n", ret);
  5303. goto exit;
  5304. }
  5305. bench_stats_start(&count, &start);
  5306. do {
  5307. for (i = 0; i < numBlocks; i++) {
  5308. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5309. bench_size);
  5310. if (ret < 0) {
  5311. printf("wc_Chacha_Process error: %d\n", ret);
  5312. goto exit;
  5313. }
  5314. RECORD_MULTI_VALUE_STATS();
  5315. }
  5316. count += i;
  5317. } while (bench_stats_check(start)
  5318. #ifdef MULTI_VALUE_STATISTICS
  5319. || runs < minimum_runs
  5320. #endif
  5321. );
  5322. }
  5323. else {
  5324. bench_stats_start(&count, &start);
  5325. do {
  5326. for (i = 0; i < numBlocks; i++) {
  5327. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5328. if (ret < 0) {
  5329. printf("wc_Chacha_SetIV error: %d\n", ret);
  5330. goto exit;
  5331. }
  5332. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5333. bench_size);
  5334. if (ret < 0) {
  5335. printf("wc_Chacha_Process error: %d\n", ret);
  5336. goto exit;
  5337. }
  5338. RECORD_MULTI_VALUE_STATS();
  5339. }
  5340. count += i;
  5341. } while (bench_stats_check(start)
  5342. #ifdef MULTI_VALUE_STATISTICS
  5343. || runs < minimum_runs
  5344. #endif
  5345. );
  5346. }
  5347. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5348. #ifdef MULTI_VALUE_STATISTICS
  5349. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5350. #endif
  5351. exit:
  5352. WC_FREE_VAR(enc, HEAP_HINT);
  5353. }
  5354. #endif /* HAVE_CHACHA*/
  5355. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5356. void bench_chacha20_poly1305_aead(void)
  5357. {
  5358. double start;
  5359. int ret = 0, i, count;
  5360. DECLARE_MULTI_VALUE_STATS_VARS()
  5361. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5362. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5363. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5364. bench_stats_start(&count, &start);
  5365. do {
  5366. for (i = 0; i < numBlocks; i++) {
  5367. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5368. bench_plain, bench_size, bench_cipher, authTag);
  5369. if (ret < 0) {
  5370. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5371. goto exit;
  5372. }
  5373. RECORD_MULTI_VALUE_STATS();
  5374. }
  5375. count += i;
  5376. } while (bench_stats_check(start)
  5377. #ifdef MULTI_VALUE_STATISTICS
  5378. || runs < minimum_runs
  5379. #endif
  5380. );
  5381. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5382. #ifdef MULTI_VALUE_STATISTICS
  5383. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5384. #endif
  5385. exit:
  5386. WC_FREE_VAR(authTag, HEAP_HINT);
  5387. }
  5388. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5389. #ifndef NO_MD5
  5390. void bench_md5(int useDeviceID)
  5391. {
  5392. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5393. sizeof(wc_Md5), HEAP_HINT);
  5394. double start = 0;
  5395. int ret = 0, i, count = 0, times, pending = 0;
  5396. DECLARE_MULTI_VALUE_STATS_VARS()
  5397. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5398. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5399. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5400. sizeof(wc_Md5), HEAP_HINT);
  5401. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5402. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5403. if (digest_stream) {
  5404. /* init keys */
  5405. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5406. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5407. useDeviceID ? devId : INVALID_DEVID);
  5408. if (ret != 0) {
  5409. printf("InitMd5_ex failed, ret = %d\n", ret);
  5410. goto exit;
  5411. }
  5412. #ifdef WOLFSSL_PIC32MZ_HASH
  5413. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5414. #endif
  5415. }
  5416. bench_stats_start(&count, &start);
  5417. do {
  5418. for (times = 0; times < numBlocks || pending > 0; ) {
  5419. bench_async_poll(&pending);
  5420. /* while free pending slots in queue, submit ops */
  5421. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5422. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5423. 0, &times, numBlocks, &pending)) {
  5424. ret = wc_Md5Update(hash[i], bench_plain,
  5425. bench_size);
  5426. if (!bench_async_handle(&ret,
  5427. BENCH_ASYNC_GET_DEV(hash[i]),
  5428. 0, &times, &pending)) {
  5429. goto exit_md5;
  5430. }
  5431. }
  5432. } /* for i */
  5433. RECORD_MULTI_VALUE_STATS();
  5434. } /* for times */
  5435. count += times;
  5436. times = 0;
  5437. do {
  5438. bench_async_poll(&pending);
  5439. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5440. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5441. 0, &times, numBlocks, &pending)) {
  5442. ret = wc_Md5Final(hash[i], digest[i]);
  5443. if (!bench_async_handle(&ret,
  5444. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5445. &times, &pending)) {
  5446. goto exit_md5;
  5447. }
  5448. }
  5449. } /* for i */
  5450. } while (pending > 0);
  5451. } while (bench_stats_check(start)
  5452. #ifdef MULTI_VALUE_STATISTICS
  5453. || runs < minimum_runs
  5454. #endif
  5455. );
  5456. }
  5457. else {
  5458. bench_stats_start(&count, &start);
  5459. do {
  5460. for (times = 0; times < numBlocks; times++) {
  5461. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5462. if (ret == 0)
  5463. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5464. if (ret == 0)
  5465. ret = wc_Md5Final(hash[0], digest[0]);
  5466. if (ret != 0)
  5467. goto exit_md5;
  5468. RECORD_MULTI_VALUE_STATS();
  5469. } /* for times */
  5470. count += times;
  5471. } while (bench_stats_check(start)
  5472. #ifdef MULTI_VALUE_STATISTICS
  5473. || runs < minimum_runs
  5474. #endif
  5475. );
  5476. }
  5477. exit_md5:
  5478. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5479. #ifdef MULTI_VALUE_STATISTICS
  5480. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5481. #endif
  5482. exit:
  5483. #ifdef WOLFSSL_ASYNC_CRYPT
  5484. if (WC_ARRAY_OK(hash)) {
  5485. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5486. wc_Md5Free(hash[i]);
  5487. }
  5488. }
  5489. #endif
  5490. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5491. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5492. }
  5493. #endif /* !NO_MD5 */
  5494. #ifndef NO_SHA
  5495. void bench_sha(int useDeviceID)
  5496. {
  5497. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5498. sizeof(wc_Sha), HEAP_HINT);
  5499. double start;
  5500. int ret = 0, i, count = 0, times, pending = 0;
  5501. DECLARE_MULTI_VALUE_STATS_VARS()
  5502. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5503. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5504. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5505. sizeof(wc_Sha), HEAP_HINT);
  5506. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5507. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5508. if (digest_stream) {
  5509. /* init keys */
  5510. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5511. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5512. useDeviceID ? devId : INVALID_DEVID);
  5513. if (ret != 0) {
  5514. printf("InitSha failed, ret = %d\n", ret);
  5515. goto exit;
  5516. }
  5517. #ifdef WOLFSSL_PIC32MZ_HASH
  5518. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5519. #endif
  5520. }
  5521. bench_stats_start(&count, &start);
  5522. do {
  5523. for (times = 0; times < numBlocks || pending > 0; ) {
  5524. bench_async_poll(&pending);
  5525. /* while free pending slots in queue, submit ops */
  5526. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5527. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5528. 0, &times, numBlocks, &pending)) {
  5529. ret = wc_ShaUpdate(hash[i], bench_plain,
  5530. bench_size);
  5531. if (!bench_async_handle(&ret,
  5532. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5533. &times, &pending)) {
  5534. goto exit_sha;
  5535. }
  5536. }
  5537. } /* for i */
  5538. RECORD_MULTI_VALUE_STATS();
  5539. } /* for times */
  5540. count += times;
  5541. times = 0;
  5542. do {
  5543. bench_async_poll(&pending);
  5544. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5545. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5546. 0, &times, numBlocks, &pending)) {
  5547. ret = wc_ShaFinal(hash[i], digest[i]);
  5548. if (!bench_async_handle(&ret,
  5549. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5550. &times, &pending)) {
  5551. goto exit_sha;
  5552. }
  5553. }
  5554. } /* for i */
  5555. } while (pending > 0);
  5556. } while (bench_stats_check(start)
  5557. #ifdef MULTI_VALUE_STATISTICS
  5558. || runs < minimum_runs
  5559. #endif
  5560. );
  5561. }
  5562. else {
  5563. bench_stats_start(&count, &start);
  5564. do {
  5565. for (times = 0; times < numBlocks; times++) {
  5566. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5567. useDeviceID ? devId : INVALID_DEVID);
  5568. if (ret == 0)
  5569. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5570. if (ret == 0)
  5571. ret = wc_ShaFinal(hash[0], digest[0]);
  5572. if (ret != 0)
  5573. goto exit_sha;
  5574. RECORD_MULTI_VALUE_STATS();
  5575. } /* for times */
  5576. count += times;
  5577. } while (bench_stats_check(start)
  5578. #ifdef MULTI_VALUE_STATISTICS
  5579. || runs < minimum_runs
  5580. #endif
  5581. );
  5582. }
  5583. exit_sha:
  5584. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5585. #ifdef MULTI_VALUE_STATISTICS
  5586. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5587. #endif
  5588. exit:
  5589. if (WC_ARRAY_OK(hash)) {
  5590. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5591. wc_ShaFree(hash[i]);
  5592. }
  5593. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5594. }
  5595. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5596. }
  5597. #endif /* NO_SHA */
  5598. #ifdef WOLFSSL_SHA224
  5599. void bench_sha224(int useDeviceID)
  5600. {
  5601. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5602. sizeof(wc_Sha224), HEAP_HINT);
  5603. double start;
  5604. int ret = 0, i, count = 0, times, pending = 0;
  5605. DECLARE_MULTI_VALUE_STATS_VARS()
  5606. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5607. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5608. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5609. sizeof(wc_Sha224), HEAP_HINT);
  5610. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5611. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5612. if (digest_stream) {
  5613. /* init keys */
  5614. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5615. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5616. useDeviceID ? devId : INVALID_DEVID);
  5617. if (ret != 0) {
  5618. printf("InitSha224_ex failed, ret = %d\n", ret);
  5619. goto exit;
  5620. }
  5621. }
  5622. bench_stats_start(&count, &start);
  5623. do {
  5624. for (times = 0; times < numBlocks || pending > 0; ) {
  5625. bench_async_poll(&pending);
  5626. /* while free pending slots in queue, submit ops */
  5627. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5628. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5629. 0, &times, numBlocks, &pending)) {
  5630. ret = wc_Sha224Update(hash[i], bench_plain,
  5631. bench_size);
  5632. if (!bench_async_handle(&ret,
  5633. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5634. &times, &pending)) {
  5635. goto exit_sha224;
  5636. }
  5637. }
  5638. } /* for i */
  5639. RECORD_MULTI_VALUE_STATS();
  5640. } /* for times */
  5641. count += times;
  5642. times = 0;
  5643. do {
  5644. bench_async_poll(&pending);
  5645. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5646. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5647. 0, &times, numBlocks, &pending)) {
  5648. ret = wc_Sha224Final(hash[i], digest[i]);
  5649. if (!bench_async_handle(&ret,
  5650. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5651. &times, &pending)) {
  5652. goto exit_sha224;
  5653. }
  5654. }
  5655. } /* for i */
  5656. } while (pending > 0);
  5657. } while (bench_stats_check(start)
  5658. #ifdef MULTI_VALUE_STATISTICS
  5659. || runs < minimum_runs
  5660. #endif
  5661. );
  5662. }
  5663. else {
  5664. bench_stats_start(&count, &start);
  5665. do {
  5666. for (times = 0; times < numBlocks; times++) {
  5667. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5668. useDeviceID ? devId : INVALID_DEVID);
  5669. if (ret == 0)
  5670. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5671. if (ret == 0)
  5672. ret = wc_Sha224Final(hash[0], digest[0]);
  5673. if (ret != 0)
  5674. goto exit_sha224;
  5675. } /* for times */
  5676. count += times;
  5677. } while (bench_stats_check(start)
  5678. #ifdef MULTI_VALUE_STATISTICS
  5679. || runs < minimum_runs
  5680. #endif
  5681. );
  5682. }
  5683. exit_sha224:
  5684. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5685. bench_size, start, ret);
  5686. #ifdef MULTI_VALUE_STATISTICS
  5687. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5688. #endif
  5689. exit:
  5690. if (WC_ARRAY_OK(hash)) {
  5691. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5692. wc_Sha224Free(hash[i]);
  5693. }
  5694. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5695. }
  5696. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5697. }
  5698. #endif
  5699. #ifndef NO_SHA256
  5700. void bench_sha256(int useDeviceID)
  5701. {
  5702. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5703. sizeof(wc_Sha256), HEAP_HINT);
  5704. double start;
  5705. int ret = 0, i, count = 0, times, pending = 0;
  5706. DECLARE_MULTI_VALUE_STATS_VARS()
  5707. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5708. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5709. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5710. sizeof(wc_Sha256), HEAP_HINT);
  5711. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5712. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5713. if (digest_stream) {
  5714. /* init keys */
  5715. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5716. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5717. useDeviceID ? devId: INVALID_DEVID);
  5718. if (ret != 0) {
  5719. printf("InitSha256_ex failed, ret = %d\n", ret);
  5720. goto exit;
  5721. }
  5722. #ifdef WOLFSSL_PIC32MZ_HASH
  5723. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5724. #endif
  5725. }
  5726. bench_stats_start(&count, &start);
  5727. do {
  5728. for (times = 0; times < numBlocks || pending > 0; ) {
  5729. bench_async_poll(&pending);
  5730. /* while free pending slots in queue, submit ops */
  5731. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5732. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5733. 0, &times, numBlocks, &pending)) {
  5734. ret = wc_Sha256Update(hash[i], bench_plain,
  5735. bench_size);
  5736. if (!bench_async_handle(&ret,
  5737. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5738. &times, &pending)) {
  5739. goto exit_sha256;
  5740. }
  5741. }
  5742. } /* for i */
  5743. RECORD_MULTI_VALUE_STATS();
  5744. } /* for times */
  5745. count += times;
  5746. times = 0;
  5747. do {
  5748. bench_async_poll(&pending);
  5749. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5750. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5751. 0, &times, numBlocks, &pending)) {
  5752. ret = wc_Sha256Final(hash[i], digest[i]);
  5753. if (!bench_async_handle(&ret,
  5754. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5755. &times, &pending)) {
  5756. goto exit_sha256;
  5757. }
  5758. }
  5759. } /* for i */
  5760. } while (pending > 0);
  5761. } while (bench_stats_check(start)
  5762. #ifdef MULTI_VALUE_STATISTICS
  5763. || runs < minimum_runs
  5764. #endif
  5765. );
  5766. }
  5767. else {
  5768. bench_stats_start(&count, &start);
  5769. do {
  5770. for (times = 0; times < numBlocks; times++) {
  5771. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5772. useDeviceID ? devId: INVALID_DEVID);
  5773. if (ret == 0)
  5774. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5775. if (ret == 0)
  5776. ret = wc_Sha256Final(hash[0], digest[0]);
  5777. if (ret != 0)
  5778. goto exit_sha256;
  5779. RECORD_MULTI_VALUE_STATS();
  5780. } /* for times */
  5781. count += times;
  5782. } while (bench_stats_check(start)
  5783. #ifdef MULTI_VALUE_STATISTICS
  5784. || runs < minimum_runs
  5785. #endif
  5786. );
  5787. }
  5788. exit_sha256:
  5789. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5790. start, ret);
  5791. #ifdef MULTI_VALUE_STATISTICS
  5792. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5793. #endif
  5794. exit:
  5795. if (WC_ARRAY_OK(hash)) {
  5796. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5797. wc_Sha256Free(hash[i]);
  5798. }
  5799. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5800. }
  5801. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5802. }
  5803. #endif
  5804. #ifdef WOLFSSL_SHA384
  5805. void bench_sha384(int useDeviceID)
  5806. {
  5807. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5808. sizeof(wc_Sha384), HEAP_HINT);
  5809. double start;
  5810. int ret = 0, i, count = 0, times, pending = 0;
  5811. DECLARE_MULTI_VALUE_STATS_VARS()
  5812. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5813. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5814. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5815. sizeof(wc_Sha384), HEAP_HINT);
  5816. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5817. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5818. if (digest_stream) {
  5819. /* init keys */
  5820. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5821. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5822. useDeviceID ? devId : INVALID_DEVID);
  5823. if (ret != 0) {
  5824. printf("InitSha384_ex failed, ret = %d\n", ret);
  5825. goto exit;
  5826. }
  5827. }
  5828. bench_stats_start(&count, &start);
  5829. do {
  5830. for (times = 0; times < numBlocks || pending > 0; ) {
  5831. bench_async_poll(&pending);
  5832. /* while free pending slots in queue, submit ops */
  5833. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5834. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5835. 0, &times, numBlocks, &pending)) {
  5836. ret = wc_Sha384Update(hash[i], bench_plain,
  5837. bench_size);
  5838. if (!bench_async_handle(&ret,
  5839. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5840. &times, &pending)) {
  5841. goto exit_sha384;
  5842. }
  5843. }
  5844. } /* for i */
  5845. RECORD_MULTI_VALUE_STATS();
  5846. } /* for times */
  5847. count += times;
  5848. times = 0;
  5849. do {
  5850. bench_async_poll(&pending);
  5851. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5852. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5853. 0, &times, numBlocks, &pending)) {
  5854. ret = wc_Sha384Final(hash[i], digest[i]);
  5855. if (!bench_async_handle(&ret,
  5856. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5857. &times, &pending)) {
  5858. goto exit_sha384;
  5859. }
  5860. }
  5861. } /* for i */
  5862. } while (pending > 0);
  5863. } while (bench_stats_check(start)
  5864. #ifdef MULTI_VALUE_STATISTICS
  5865. || runs < minimum_runs
  5866. #endif
  5867. );
  5868. }
  5869. else {
  5870. bench_stats_start(&count, &start);
  5871. do {
  5872. for (times = 0; times < numBlocks; times++) {
  5873. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5874. useDeviceID ? devId : INVALID_DEVID);
  5875. if (ret == 0)
  5876. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5877. if (ret == 0)
  5878. ret = wc_Sha384Final(hash[0], digest[0]);
  5879. if (ret != 0)
  5880. goto exit_sha384;
  5881. RECORD_MULTI_VALUE_STATS();
  5882. } /* for times */
  5883. count += times;
  5884. } while (bench_stats_check(start)
  5885. #ifdef MULTI_VALUE_STATISTICS
  5886. || runs < minimum_runs
  5887. #endif
  5888. );
  5889. }
  5890. exit_sha384:
  5891. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5892. start, ret);
  5893. #ifdef MULTI_VALUE_STATISTICS
  5894. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5895. #endif
  5896. exit:
  5897. if (WC_ARRAY_OK(hash)) {
  5898. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5899. wc_Sha384Free(hash[i]);
  5900. }
  5901. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5902. }
  5903. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5904. }
  5905. #endif
  5906. #ifdef WOLFSSL_SHA512
  5907. void bench_sha512(int useDeviceID)
  5908. {
  5909. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5910. sizeof(wc_Sha512), HEAP_HINT);
  5911. double start;
  5912. int ret = 0, i, count = 0, times, pending = 0;
  5913. DECLARE_MULTI_VALUE_STATS_VARS()
  5914. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5915. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5916. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5917. sizeof(wc_Sha512), HEAP_HINT);
  5918. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5919. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5920. if (digest_stream) {
  5921. /* init keys */
  5922. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5923. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5924. useDeviceID ? devId : INVALID_DEVID);
  5925. if (ret != 0) {
  5926. printf("InitSha512_ex failed, ret = %d\n", ret);
  5927. goto exit;
  5928. }
  5929. }
  5930. bench_stats_start(&count, &start);
  5931. do {
  5932. for (times = 0; times < numBlocks || pending > 0; ) {
  5933. bench_async_poll(&pending);
  5934. /* while free pending slots in queue, submit ops */
  5935. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5936. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5937. 0, &times, numBlocks, &pending)) {
  5938. ret = wc_Sha512Update(hash[i], bench_plain,
  5939. bench_size);
  5940. if (!bench_async_handle(&ret,
  5941. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5942. &times, &pending)) {
  5943. goto exit_sha512;
  5944. }
  5945. }
  5946. } /* for i */
  5947. RECORD_MULTI_VALUE_STATS();
  5948. } /* for times */
  5949. count += times;
  5950. times = 0;
  5951. do {
  5952. bench_async_poll(&pending);
  5953. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5954. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5955. 0, &times, numBlocks, &pending)) {
  5956. ret = wc_Sha512Final(hash[i], digest[i]);
  5957. if (!bench_async_handle(&ret,
  5958. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5959. &times, &pending)) {
  5960. goto exit_sha512;
  5961. }
  5962. }
  5963. } /* for i */
  5964. } while (pending > 0);
  5965. } while (bench_stats_check(start)
  5966. #ifdef MULTI_VALUE_STATISTICS
  5967. || runs < minimum_runs
  5968. #endif
  5969. );
  5970. }
  5971. else {
  5972. bench_stats_start(&count, &start);
  5973. do {
  5974. for (times = 0; times < numBlocks; times++) {
  5975. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  5976. useDeviceID ? devId : INVALID_DEVID);
  5977. if (ret == 0)
  5978. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  5979. if (ret == 0)
  5980. ret = wc_Sha512Final(hash[0], digest[0]);
  5981. if (ret != 0)
  5982. goto exit_sha512;
  5983. RECORD_MULTI_VALUE_STATS();
  5984. } /* for times */
  5985. count += times;
  5986. } while (bench_stats_check(start)
  5987. #ifdef MULTI_VALUE_STATISTICS
  5988. || runs < minimum_runs
  5989. #endif
  5990. );
  5991. }
  5992. exit_sha512:
  5993. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  5994. start, ret);
  5995. #ifdef MULTI_VALUE_STATISTICS
  5996. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5997. #endif
  5998. exit:
  5999. if (WC_ARRAY_OK(hash)) {
  6000. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6001. wc_Sha512Free(hash[i]);
  6002. }
  6003. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6004. }
  6005. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6006. }
  6007. #if !defined(WOLFSSL_NOSHA512_224) && \
  6008. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6009. void bench_sha512_224(int useDeviceID)
  6010. {
  6011. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6012. sizeof(wc_Sha512_224), HEAP_HINT);
  6013. double start;
  6014. int ret = 0, i, count = 0, times, pending = 0;
  6015. DECLARE_MULTI_VALUE_STATS_VARS()
  6016. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6017. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6018. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6019. sizeof(wc_Sha512_224), HEAP_HINT);
  6020. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6021. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6022. if (digest_stream) {
  6023. /* init keys */
  6024. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6025. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6026. useDeviceID ? devId : INVALID_DEVID);
  6027. if (ret != 0) {
  6028. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6029. goto exit;
  6030. }
  6031. }
  6032. bench_stats_start(&count, &start);
  6033. do {
  6034. for (times = 0; times < numBlocks || pending > 0; ) {
  6035. bench_async_poll(&pending);
  6036. /* while free pending slots in queue, submit ops */
  6037. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6038. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6039. 0, &times, numBlocks, &pending)) {
  6040. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6041. bench_size);
  6042. if (!bench_async_handle(&ret,
  6043. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6044. &times, &pending)) {
  6045. goto exit_sha512_224;
  6046. }
  6047. }
  6048. } /* for i */
  6049. RECORD_MULTI_VALUE_STATS();
  6050. } /* for times */
  6051. count += times;
  6052. times = 0;
  6053. do {
  6054. bench_async_poll(&pending);
  6055. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6056. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6057. 0, &times, numBlocks, &pending)) {
  6058. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6059. if (!bench_async_handle(&ret,
  6060. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6061. &times, &pending)) {
  6062. goto exit_sha512_224;
  6063. }
  6064. }
  6065. } /* for i */
  6066. } while (pending > 0);
  6067. } while (bench_stats_check(start)
  6068. #ifdef MULTI_VALUE_STATISTICS
  6069. || runs < minimum_runs
  6070. #endif
  6071. );
  6072. }
  6073. else {
  6074. bench_stats_start(&count, &start);
  6075. do {
  6076. for (times = 0; times < numBlocks; times++) {
  6077. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6078. useDeviceID ? devId : INVALID_DEVID);
  6079. if (ret == 0)
  6080. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6081. if (ret == 0)
  6082. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6083. if (ret != 0)
  6084. goto exit_sha512_224;
  6085. RECORD_MULTI_VALUE_STATS();
  6086. } /* for times */
  6087. count += times;
  6088. } while (bench_stats_check(start)
  6089. #ifdef MULTI_VALUE_STATISTICS
  6090. || runs < minimum_runs
  6091. #endif
  6092. );
  6093. }
  6094. exit_sha512_224:
  6095. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6096. start, ret);
  6097. #ifdef MULTI_VALUE_STATISTICS
  6098. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6099. #endif
  6100. exit:
  6101. if (WC_ARRAY_OK(hash)) {
  6102. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6103. wc_Sha512_224Free(hash[i]);
  6104. }
  6105. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6106. }
  6107. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6108. }
  6109. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6110. #if !defined(WOLFSSL_NOSHA512_256) && \
  6111. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6112. void bench_sha512_256(int useDeviceID)
  6113. {
  6114. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6115. sizeof(wc_Sha512_256), HEAP_HINT);
  6116. double start;
  6117. int ret = 0, i, count = 0, times, pending = 0;
  6118. DECLARE_MULTI_VALUE_STATS_VARS()
  6119. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6120. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6121. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6122. sizeof(wc_Sha512_256), HEAP_HINT);
  6123. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6124. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6125. if (digest_stream) {
  6126. /* init keys */
  6127. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6128. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6129. useDeviceID ? devId : INVALID_DEVID);
  6130. if (ret != 0) {
  6131. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6132. goto exit;
  6133. }
  6134. }
  6135. bench_stats_start(&count, &start);
  6136. do {
  6137. for (times = 0; times < numBlocks || pending > 0; ) {
  6138. bench_async_poll(&pending);
  6139. /* while free pending slots in queue, submit ops */
  6140. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6141. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6142. 0, &times, numBlocks, &pending)) {
  6143. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6144. bench_size);
  6145. if (!bench_async_handle(&ret,
  6146. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6147. &times, &pending)) {
  6148. goto exit_sha512_256;
  6149. }
  6150. }
  6151. } /* for i */
  6152. RECORD_MULTI_VALUE_STATS();
  6153. } /* for times */
  6154. count += times;
  6155. times = 0;
  6156. do {
  6157. bench_async_poll(&pending);
  6158. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6159. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6160. 0, &times, numBlocks, &pending)) {
  6161. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6162. if (!bench_async_handle(&ret,
  6163. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6164. &times, &pending)) {
  6165. goto exit_sha512_256;
  6166. }
  6167. }
  6168. } /* for i */
  6169. } while (pending > 0);
  6170. } while (bench_stats_check(start)
  6171. #ifdef MULTI_VALUE_STATISTICS
  6172. || runs < minimum_runs
  6173. #endif
  6174. );
  6175. }
  6176. else {
  6177. bench_stats_start(&count, &start);
  6178. do {
  6179. for (times = 0; times < numBlocks; times++) {
  6180. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6181. useDeviceID ? devId : INVALID_DEVID);
  6182. if (ret == 0)
  6183. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6184. if (ret == 0)
  6185. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6186. if (ret != 0)
  6187. goto exit_sha512_256;
  6188. RECORD_MULTI_VALUE_STATS();
  6189. } /* for times */
  6190. count += times;
  6191. } while (bench_stats_check(start)
  6192. #ifdef MULTI_VALUE_STATISTICS
  6193. || runs < minimum_runs
  6194. #endif
  6195. );
  6196. }
  6197. exit_sha512_256:
  6198. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6199. start, ret);
  6200. #ifdef MULTI_VALUE_STATISTICS
  6201. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6202. #endif
  6203. exit:
  6204. if (WC_ARRAY_OK(hash)) {
  6205. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6206. wc_Sha512_256Free(hash[i]);
  6207. }
  6208. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6209. }
  6210. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6211. }
  6212. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6213. #endif /* WOLFSSL_SHA512 */
  6214. #ifdef WOLFSSL_SHA3
  6215. #ifndef WOLFSSL_NOSHA3_224
  6216. void bench_sha3_224(int useDeviceID)
  6217. {
  6218. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6219. sizeof(wc_Sha3), HEAP_HINT);
  6220. double start;
  6221. int ret = 0, i, count = 0, times, pending = 0;
  6222. DECLARE_MULTI_VALUE_STATS_VARS()
  6223. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6224. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6225. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6226. sizeof(wc_Sha3), HEAP_HINT);
  6227. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6228. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6229. if (digest_stream) {
  6230. /* init keys */
  6231. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6232. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6233. useDeviceID ? devId : INVALID_DEVID);
  6234. if (ret != 0) {
  6235. printf("InitSha3_224 failed, ret = %d\n", ret);
  6236. goto exit;
  6237. }
  6238. }
  6239. bench_stats_start(&count, &start);
  6240. do {
  6241. for (times = 0; times < numBlocks || pending > 0; ) {
  6242. bench_async_poll(&pending);
  6243. /* while free pending slots in queue, submit ops */
  6244. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6245. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6246. 0, &times, numBlocks, &pending)) {
  6247. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6248. bench_size);
  6249. if (!bench_async_handle(&ret,
  6250. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6251. &times, &pending)) {
  6252. goto exit_sha3_224;
  6253. }
  6254. }
  6255. } /* for i */
  6256. RECORD_MULTI_VALUE_STATS();
  6257. } /* for times */
  6258. count += times;
  6259. times = 0;
  6260. do {
  6261. bench_async_poll(&pending);
  6262. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6263. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6264. 0, &times, numBlocks, &pending)) {
  6265. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6266. if (!bench_async_handle(&ret,
  6267. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6268. &times, &pending)) {
  6269. goto exit_sha3_224;
  6270. }
  6271. }
  6272. } /* for i */
  6273. } while (pending > 0);
  6274. } while (bench_stats_check(start)
  6275. #ifdef MULTI_VALUE_STATISTICS
  6276. || runs < minimum_runs
  6277. #endif
  6278. );
  6279. }
  6280. else {
  6281. bench_stats_start(&count, &start);
  6282. do {
  6283. for (times = 0; times < numBlocks; times++) {
  6284. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6285. useDeviceID ? devId : INVALID_DEVID);
  6286. if (ret == 0)
  6287. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6288. if (ret == 0)
  6289. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6290. if (ret != 0)
  6291. goto exit_sha3_224;
  6292. RECORD_MULTI_VALUE_STATS();
  6293. } /* for times */
  6294. count += times;
  6295. } while (bench_stats_check(start)
  6296. #ifdef MULTI_VALUE_STATISTICS
  6297. || runs < minimum_runs
  6298. #endif
  6299. );
  6300. }
  6301. exit_sha3_224:
  6302. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6303. start, ret);
  6304. #ifdef MULTI_VALUE_STATISTICS
  6305. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6306. #endif
  6307. exit:
  6308. if (WC_ARRAY_OK(hash)) {
  6309. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6310. wc_Sha3_224_Free(hash[i]);
  6311. }
  6312. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6313. }
  6314. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6315. }
  6316. #endif /* WOLFSSL_NOSHA3_224 */
  6317. #ifndef WOLFSSL_NOSHA3_256
  6318. void bench_sha3_256(int useDeviceID)
  6319. {
  6320. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6321. sizeof(wc_Sha3), HEAP_HINT);
  6322. double start;
  6323. DECLARE_MULTI_VALUE_STATS_VARS()
  6324. int ret = 0, i, count = 0, times, pending = 0;
  6325. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6326. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6327. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6328. sizeof(wc_Sha3), HEAP_HINT);
  6329. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6330. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6331. if (digest_stream) {
  6332. /* init keys */
  6333. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6334. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6335. useDeviceID ? devId : INVALID_DEVID);
  6336. if (ret != 0) {
  6337. printf("InitSha3_256 failed, ret = %d\n", ret);
  6338. goto exit;
  6339. }
  6340. }
  6341. bench_stats_start(&count, &start);
  6342. do {
  6343. for (times = 0; times < numBlocks || pending > 0; ) {
  6344. bench_async_poll(&pending);
  6345. /* while free pending slots in queue, submit ops */
  6346. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6347. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6348. 0, &times, numBlocks, &pending)) {
  6349. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6350. bench_size);
  6351. if (!bench_async_handle(&ret,
  6352. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6353. &times, &pending)) {
  6354. goto exit_sha3_256;
  6355. }
  6356. }
  6357. } /* for i */
  6358. RECORD_MULTI_VALUE_STATS();
  6359. } /* for times */
  6360. count += times;
  6361. times = 0;
  6362. do {
  6363. bench_async_poll(&pending);
  6364. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6365. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6366. 0, &times, numBlocks, &pending)) {
  6367. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6368. if (!bench_async_handle(&ret,
  6369. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6370. &times, &pending)) {
  6371. goto exit_sha3_256;
  6372. }
  6373. }
  6374. } /* for i */
  6375. } while (pending > 0);
  6376. } while (bench_stats_check(start)
  6377. #ifdef MULTI_VALUE_STATISTICS
  6378. || runs < minimum_runs
  6379. #endif
  6380. );
  6381. }
  6382. else {
  6383. bench_stats_start(&count, &start);
  6384. do {
  6385. for (times = 0; times < numBlocks; times++) {
  6386. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6387. useDeviceID ? devId : INVALID_DEVID);
  6388. if (ret == 0)
  6389. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6390. if (ret == 0)
  6391. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6392. if (ret != 0)
  6393. goto exit_sha3_256;
  6394. RECORD_MULTI_VALUE_STATS();
  6395. } /* for times */
  6396. count += times;
  6397. } while (bench_stats_check(start)
  6398. #ifdef MULTI_VALUE_STATISTICS
  6399. || runs < minimum_runs
  6400. #endif
  6401. );
  6402. }
  6403. exit_sha3_256:
  6404. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6405. start, ret);
  6406. #ifdef MULTI_VALUE_STATISTICS
  6407. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6408. #endif
  6409. exit:
  6410. if (WC_ARRAY_OK(hash)) {
  6411. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6412. wc_Sha3_256_Free(hash[i]);
  6413. }
  6414. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6415. }
  6416. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6417. }
  6418. #endif /* WOLFSSL_NOSHA3_256 */
  6419. #ifndef WOLFSSL_NOSHA3_384
  6420. void bench_sha3_384(int useDeviceID)
  6421. {
  6422. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6423. sizeof(wc_Sha3), HEAP_HINT);
  6424. double start;
  6425. int ret = 0, i, count = 0, times, pending = 0;
  6426. DECLARE_MULTI_VALUE_STATS_VARS()
  6427. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6428. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6429. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6430. sizeof(wc_Sha3), HEAP_HINT);
  6431. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6432. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6433. if (digest_stream) {
  6434. /* init keys */
  6435. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6436. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6437. useDeviceID ? devId : INVALID_DEVID);
  6438. if (ret != 0) {
  6439. printf("InitSha3_384 failed, ret = %d\n", ret);
  6440. goto exit;
  6441. }
  6442. }
  6443. bench_stats_start(&count, &start);
  6444. do {
  6445. for (times = 0; times < numBlocks || pending > 0; ) {
  6446. bench_async_poll(&pending);
  6447. /* while free pending slots in queue, submit ops */
  6448. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6449. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6450. 0, &times, numBlocks, &pending)) {
  6451. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6452. bench_size);
  6453. if (!bench_async_handle(&ret,
  6454. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6455. &times, &pending)) {
  6456. goto exit_sha3_384;
  6457. }
  6458. }
  6459. } /* for i */
  6460. RECORD_MULTI_VALUE_STATS();
  6461. } /* for times */
  6462. count += times;
  6463. times = 0;
  6464. do {
  6465. bench_async_poll(&pending);
  6466. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6467. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6468. 0, &times, numBlocks, &pending)) {
  6469. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6470. if (!bench_async_handle(&ret,
  6471. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6472. &times, &pending)) {
  6473. goto exit_sha3_384;
  6474. }
  6475. }
  6476. } /* for i */
  6477. } while (pending > 0);
  6478. } while (bench_stats_check(start)
  6479. #ifdef MULTI_VALUE_STATISTICS
  6480. || runs < minimum_runs
  6481. #endif
  6482. );
  6483. }
  6484. else {
  6485. bench_stats_start(&count, &start);
  6486. do {
  6487. for (times = 0; times < numBlocks; times++) {
  6488. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6489. useDeviceID ? devId : INVALID_DEVID);
  6490. if (ret == 0)
  6491. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6492. if (ret == 0)
  6493. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6494. if (ret != 0)
  6495. goto exit_sha3_384;
  6496. RECORD_MULTI_VALUE_STATS();
  6497. } /* for times */
  6498. count += times;
  6499. } while (bench_stats_check(start)
  6500. #ifdef MULTI_VALUE_STATISTICS
  6501. || runs < minimum_runs
  6502. #endif
  6503. );
  6504. }
  6505. exit_sha3_384:
  6506. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6507. start, ret);
  6508. #ifdef MULTI_VALUE_STATISTICS
  6509. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6510. #endif
  6511. exit:
  6512. if (WC_ARRAY_OK(hash)) {
  6513. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6514. wc_Sha3_384_Free(hash[i]);
  6515. }
  6516. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6517. }
  6518. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6519. }
  6520. #endif /* WOLFSSL_NOSHA3_384 */
  6521. #ifndef WOLFSSL_NOSHA3_512
  6522. void bench_sha3_512(int useDeviceID)
  6523. {
  6524. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6525. sizeof(wc_Sha3), HEAP_HINT);
  6526. double start;
  6527. int ret = 0, i, count = 0, times, pending = 0;
  6528. DECLARE_MULTI_VALUE_STATS_VARS()
  6529. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6530. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6531. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6532. sizeof(wc_Sha3), HEAP_HINT);
  6533. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6534. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6535. if (digest_stream) {
  6536. /* init keys */
  6537. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6538. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6539. useDeviceID ? devId : INVALID_DEVID);
  6540. if (ret != 0) {
  6541. printf("InitSha3_512 failed, ret = %d\n", ret);
  6542. goto exit;
  6543. }
  6544. }
  6545. bench_stats_start(&count, &start);
  6546. do {
  6547. for (times = 0; times < numBlocks || pending > 0; ) {
  6548. bench_async_poll(&pending);
  6549. /* while free pending slots in queue, submit ops */
  6550. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6551. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6552. 0, &times, numBlocks, &pending)) {
  6553. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6554. bench_size);
  6555. if (!bench_async_handle(&ret,
  6556. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6557. &times, &pending)) {
  6558. goto exit_sha3_512;
  6559. }
  6560. }
  6561. } /* for i */
  6562. RECORD_MULTI_VALUE_STATS();
  6563. } /* for times */
  6564. count += times;
  6565. times = 0;
  6566. do {
  6567. bench_async_poll(&pending);
  6568. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6569. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6570. 0, &times, numBlocks, &pending)) {
  6571. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6572. if (!bench_async_handle(&ret,
  6573. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6574. &times, &pending)) {
  6575. goto exit_sha3_512;
  6576. }
  6577. }
  6578. } /* for i */
  6579. } while (pending > 0);
  6580. } while (bench_stats_check(start)
  6581. #ifdef MULTI_VALUE_STATISTICS
  6582. || runs < minimum_runs
  6583. #endif
  6584. );
  6585. }
  6586. else {
  6587. bench_stats_start(&count, &start);
  6588. do {
  6589. for (times = 0; times < numBlocks; times++) {
  6590. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6591. useDeviceID ? devId : INVALID_DEVID);
  6592. if (ret == 0)
  6593. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6594. if (ret == 0)
  6595. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6596. if (ret != 0)
  6597. goto exit_sha3_512;
  6598. RECORD_MULTI_VALUE_STATS();
  6599. } /* for times */
  6600. count += times;
  6601. } while (bench_stats_check(start)
  6602. #ifdef MULTI_VALUE_STATISTICS
  6603. || runs < minimum_runs
  6604. #endif
  6605. );
  6606. }
  6607. exit_sha3_512:
  6608. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6609. start, ret);
  6610. #ifdef MULTI_VALUE_STATISTICS
  6611. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6612. #endif
  6613. exit:
  6614. if (WC_ARRAY_OK(hash)) {
  6615. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6616. wc_Sha3_512_Free(hash[i]);
  6617. }
  6618. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6619. }
  6620. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6621. }
  6622. #endif /* WOLFSSL_NOSHA3_512 */
  6623. #ifdef WOLFSSL_SHAKE128
  6624. void bench_shake128(int useDeviceID)
  6625. {
  6626. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6627. sizeof(wc_Shake), HEAP_HINT);
  6628. double start;
  6629. int ret = 0, i, count = 0, times, pending = 0;
  6630. DECLARE_MULTI_VALUE_STATS_VARS()
  6631. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6632. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6633. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6634. sizeof(wc_Shake), HEAP_HINT);
  6635. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6636. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6637. if (digest_stream) {
  6638. /* init keys */
  6639. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6640. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6641. useDeviceID ? devId : INVALID_DEVID);
  6642. if (ret != 0) {
  6643. printf("InitShake128 failed, ret = %d\n", ret);
  6644. goto exit;
  6645. }
  6646. }
  6647. bench_stats_start(&count, &start);
  6648. do {
  6649. for (times = 0; times < numBlocks || pending > 0; ) {
  6650. bench_async_poll(&pending);
  6651. /* while free pending slots in queue, submit ops */
  6652. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6653. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6654. 0, &times, numBlocks, &pending)) {
  6655. ret = wc_Shake128_Update(hash[i], bench_plain,
  6656. bench_size);
  6657. if (!bench_async_handle(&ret,
  6658. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6659. &times, &pending)) {
  6660. goto exit_shake128;
  6661. }
  6662. }
  6663. } /* for i */
  6664. RECORD_MULTI_VALUE_STATS();
  6665. } /* for times */
  6666. count += times;
  6667. times = 0;
  6668. do {
  6669. bench_async_poll(&pending);
  6670. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6671. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6672. 0, &times, numBlocks, &pending)) {
  6673. ret = wc_Shake128_Final(hash[i], digest[i],
  6674. WC_SHA3_128_BLOCK_SIZE);
  6675. if (!bench_async_handle(&ret,
  6676. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6677. &times, &pending)) {
  6678. goto exit_shake128;
  6679. }
  6680. }
  6681. } /* for i */
  6682. } while (pending > 0);
  6683. } while (bench_stats_check(start)
  6684. #ifdef MULTI_VALUE_STATISTICS
  6685. || runs < minimum_runs
  6686. #endif
  6687. );
  6688. }
  6689. else {
  6690. bench_stats_start(&count, &start);
  6691. do {
  6692. for (times = 0; times < numBlocks; times++) {
  6693. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6694. useDeviceID ? devId : INVALID_DEVID);
  6695. if (ret == 0)
  6696. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6697. if (ret == 0)
  6698. ret = wc_Shake128_Final(hash[0], digest[0],
  6699. WC_SHA3_128_BLOCK_SIZE);
  6700. if (ret != 0)
  6701. goto exit_shake128;
  6702. RECORD_MULTI_VALUE_STATS();
  6703. } /* for times */
  6704. count += times;
  6705. } while (bench_stats_check(start)
  6706. #ifdef MULTI_VALUE_STATISTICS
  6707. || runs < minimum_runs
  6708. #endif
  6709. );
  6710. }
  6711. exit_shake128:
  6712. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6713. start, ret);
  6714. #ifdef MULTI_VALUE_STATISTICS
  6715. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6716. #endif
  6717. exit:
  6718. if (WC_ARRAY_OK(hash)) {
  6719. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6720. wc_Shake128_Free(hash[i]);
  6721. }
  6722. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6723. }
  6724. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6725. }
  6726. #endif /* WOLFSSL_SHAKE128 */
  6727. #ifdef WOLFSSL_SHAKE256
  6728. void bench_shake256(int useDeviceID)
  6729. {
  6730. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6731. sizeof(wc_Shake), HEAP_HINT);
  6732. double start;
  6733. int ret = 0, i, count = 0, times, pending = 0;
  6734. DECLARE_MULTI_VALUE_STATS_VARS()
  6735. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6736. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6737. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6738. sizeof(wc_Shake), HEAP_HINT);
  6739. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6740. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6741. if (digest_stream) {
  6742. /* init keys */
  6743. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6744. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6745. useDeviceID ? devId : INVALID_DEVID);
  6746. if (ret != 0) {
  6747. printf("InitShake256 failed, ret = %d\n", ret);
  6748. goto exit;
  6749. }
  6750. }
  6751. bench_stats_start(&count, &start);
  6752. do {
  6753. for (times = 0; times < numBlocks || pending > 0; ) {
  6754. bench_async_poll(&pending);
  6755. /* while free pending slots in queue, submit ops */
  6756. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6757. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6758. 0, &times, numBlocks, &pending)) {
  6759. ret = wc_Shake256_Update(hash[i], bench_plain,
  6760. bench_size);
  6761. if (!bench_async_handle(&ret,
  6762. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6763. &times, &pending)) {
  6764. goto exit_shake256;
  6765. }
  6766. }
  6767. } /* for i */
  6768. RECORD_MULTI_VALUE_STATS();
  6769. } /* for times */
  6770. count += times;
  6771. times = 0;
  6772. do {
  6773. bench_async_poll(&pending);
  6774. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6775. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6776. 0, &times, numBlocks, &pending)) {
  6777. ret = wc_Shake256_Final(hash[i], digest[i],
  6778. WC_SHA3_256_BLOCK_SIZE);
  6779. if (!bench_async_handle(&ret,
  6780. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6781. &times, &pending)) {
  6782. goto exit_shake256;
  6783. }
  6784. }
  6785. } /* for i */
  6786. } while (pending > 0);
  6787. } while (bench_stats_check(start)
  6788. #ifdef MULTI_VALUE_STATISTICS
  6789. || runs < minimum_runs
  6790. #endif
  6791. );
  6792. }
  6793. else {
  6794. bench_stats_start(&count, &start);
  6795. do {
  6796. for (times = 0; times < numBlocks; times++) {
  6797. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6798. useDeviceID ? devId : INVALID_DEVID);
  6799. if (ret == 0)
  6800. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6801. if (ret == 0)
  6802. ret = wc_Shake256_Final(hash[0], digest[0],
  6803. WC_SHA3_256_BLOCK_SIZE);
  6804. if (ret != 0)
  6805. goto exit_shake256;
  6806. RECORD_MULTI_VALUE_STATS();
  6807. } /* for times */
  6808. count += times;
  6809. } while (bench_stats_check(start)
  6810. #ifdef MULTI_VALUE_STATISTICS
  6811. || runs < minimum_runs
  6812. #endif
  6813. );
  6814. }
  6815. exit_shake256:
  6816. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6817. start, ret);
  6818. #ifdef MULTI_VALUE_STATISTICS
  6819. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6820. #endif
  6821. exit:
  6822. if (WC_ARRAY_OK(hash)) {
  6823. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6824. wc_Shake256_Free(hash[i]);
  6825. }
  6826. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6827. }
  6828. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6829. }
  6830. #endif /* WOLFSSL_SHAKE256 */
  6831. #endif
  6832. #ifdef WOLFSSL_SM3
  6833. void bench_sm3(int useDeviceID)
  6834. {
  6835. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6836. sizeof(wc_Sm3), HEAP_HINT);
  6837. double start;
  6838. int ret = 0, i, count = 0, times, pending = 0;
  6839. DECLARE_MULTI_VALUE_STATS_VARS()
  6840. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6841. HEAP_HINT);
  6842. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6843. sizeof(wc_Sm3), HEAP_HINT);
  6844. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6845. HEAP_HINT);
  6846. if (digest_stream) {
  6847. /* init keys */
  6848. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6849. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6850. useDeviceID ? devId: INVALID_DEVID);
  6851. if (ret != 0) {
  6852. printf("InitSm3 failed, ret = %d\n", ret);
  6853. goto exit;
  6854. }
  6855. }
  6856. bench_stats_start(&count, &start);
  6857. do {
  6858. for (times = 0; times < numBlocks || pending > 0; ) {
  6859. bench_async_poll(&pending);
  6860. /* while free pending slots in queue, submit ops */
  6861. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6862. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6863. 0, &times, numBlocks, &pending)) {
  6864. ret = wc_Sm3Update(hash[i], bench_plain,
  6865. bench_size);
  6866. if (!bench_async_handle(&ret,
  6867. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6868. goto exit_sm3;
  6869. }
  6870. }
  6871. } /* for i */
  6872. RECORD_MULTI_VALUE_STATS();
  6873. } /* for times */
  6874. count += times;
  6875. times = 0;
  6876. do {
  6877. bench_async_poll(&pending);
  6878. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6879. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6880. 0, &times, numBlocks, &pending)) {
  6881. ret = wc_Sm3Final(hash[i], digest[i]);
  6882. if (!bench_async_handle(&ret,
  6883. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6884. goto exit_sm3;
  6885. }
  6886. }
  6887. } /* for i */
  6888. } while (pending > 0);
  6889. } while (bench_stats_check(start)
  6890. #ifdef MULTI_VALUE_STATISTICS
  6891. || runs < minimum_runs
  6892. #endif
  6893. );
  6894. }
  6895. else {
  6896. bench_stats_start(&count, &start);
  6897. do {
  6898. for (times = 0; times < numBlocks; times++) {
  6899. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6900. useDeviceID ? devId: INVALID_DEVID);
  6901. if (ret == 0)
  6902. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6903. if (ret == 0)
  6904. ret = wc_Sm3Final(hash[0], digest[0]);
  6905. if (ret != 0)
  6906. goto exit_sm3;
  6907. RECORD_MULTI_VALUE_STATS();
  6908. } /* for times */
  6909. count += times;
  6910. } while (bench_stats_check(start)
  6911. #ifdef MULTI_VALUE_STATISTICS
  6912. || runs < minimum_runs
  6913. #endif
  6914. );
  6915. }
  6916. exit_sm3:
  6917. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6918. #ifdef MULTI_VALUE_STATISTICS
  6919. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6920. #endif
  6921. exit:
  6922. if (WC_ARRAY_OK(hash)) {
  6923. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6924. wc_Sm3Free(hash[i]);
  6925. }
  6926. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6927. }
  6928. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6929. }
  6930. #endif
  6931. #ifdef WOLFSSL_RIPEMD
  6932. void bench_ripemd(void)
  6933. {
  6934. RipeMd hash;
  6935. byte digest[RIPEMD_DIGEST_SIZE];
  6936. double start;
  6937. int i, count, ret = 0;
  6938. DECLARE_MULTI_VALUE_STATS_VARS()
  6939. if (digest_stream) {
  6940. ret = wc_InitRipeMd(&hash);
  6941. if (ret != 0) {
  6942. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6943. return;
  6944. }
  6945. bench_stats_start(&count, &start);
  6946. do {
  6947. for (i = 0; i < numBlocks; i++) {
  6948. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6949. if (ret != 0) {
  6950. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6951. return;
  6952. }
  6953. RECORD_MULTI_VALUE_STATS();
  6954. }
  6955. ret = wc_RipeMdFinal(&hash, digest);
  6956. if (ret != 0) {
  6957. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6958. return;
  6959. }
  6960. count += i;
  6961. } while (bench_stats_check(start)
  6962. #ifdef MULTI_VALUE_STATISTICS
  6963. || runs < minimum_runs
  6964. #endif
  6965. );
  6966. }
  6967. else {
  6968. bench_stats_start(&count, &start);
  6969. do {
  6970. for (i = 0; i < numBlocks; i++) {
  6971. ret = wc_InitRipeMd(&hash);
  6972. if (ret != 0) {
  6973. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6974. return;
  6975. }
  6976. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6977. if (ret != 0) {
  6978. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6979. return;
  6980. }
  6981. ret = wc_RipeMdFinal(&hash, digest);
  6982. if (ret != 0) {
  6983. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6984. return;
  6985. }
  6986. RECORD_MULTI_VALUE_STATS();
  6987. }
  6988. count += i;
  6989. } while (bench_stats_check(start)
  6990. #ifdef MULTI_VALUE_STATISTICS
  6991. || runs < minimum_runs
  6992. #endif
  6993. );
  6994. }
  6995. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  6996. #ifdef MULTI_VALUE_STATISTICS
  6997. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6998. #endif
  6999. return;
  7000. }
  7001. #endif
  7002. #ifdef HAVE_BLAKE2
  7003. void bench_blake2b(void)
  7004. {
  7005. Blake2b b2b;
  7006. byte digest[64];
  7007. double start;
  7008. int ret = 0, i, count;
  7009. DECLARE_MULTI_VALUE_STATS_VARS()
  7010. if (digest_stream) {
  7011. ret = wc_InitBlake2b(&b2b, 64);
  7012. if (ret != 0) {
  7013. printf("InitBlake2b failed, ret = %d\n", ret);
  7014. return;
  7015. }
  7016. bench_stats_start(&count, &start);
  7017. do {
  7018. for (i = 0; i < numBlocks; i++) {
  7019. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7020. if (ret != 0) {
  7021. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7022. return;
  7023. }
  7024. RECORD_MULTI_VALUE_STATS();
  7025. }
  7026. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7027. if (ret != 0) {
  7028. printf("Blake2bFinal failed, ret = %d\n", ret);
  7029. return;
  7030. }
  7031. count += i;
  7032. } while (bench_stats_check(start)
  7033. #ifdef MULTI_VALUE_STATISTICS
  7034. || runs < minimum_runs
  7035. #endif
  7036. );
  7037. }
  7038. else {
  7039. bench_stats_start(&count, &start);
  7040. do {
  7041. for (i = 0; i < numBlocks; i++) {
  7042. ret = wc_InitBlake2b(&b2b, 64);
  7043. if (ret != 0) {
  7044. printf("InitBlake2b failed, ret = %d\n", ret);
  7045. return;
  7046. }
  7047. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7048. if (ret != 0) {
  7049. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7050. return;
  7051. }
  7052. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7053. if (ret != 0) {
  7054. printf("Blake2bFinal failed, ret = %d\n", ret);
  7055. return;
  7056. }
  7057. RECORD_MULTI_VALUE_STATS();
  7058. }
  7059. count += i;
  7060. } while (bench_stats_check(start)
  7061. #ifdef MULTI_VALUE_STATISTICS
  7062. || runs < minimum_runs
  7063. #endif
  7064. );
  7065. }
  7066. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7067. #ifdef MULTI_VALUE_STATISTICS
  7068. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7069. #endif
  7070. }
  7071. #endif
  7072. #if defined(HAVE_BLAKE2S)
  7073. void bench_blake2s(void)
  7074. {
  7075. Blake2s b2s;
  7076. byte digest[32];
  7077. double start;
  7078. int ret = 0, i, count;
  7079. DECLARE_MULTI_VALUE_STATS_VARS()
  7080. if (digest_stream) {
  7081. ret = wc_InitBlake2s(&b2s, 32);
  7082. if (ret != 0) {
  7083. printf("InitBlake2s failed, ret = %d\n", ret);
  7084. return;
  7085. }
  7086. bench_stats_start(&count, &start);
  7087. do {
  7088. for (i = 0; i < numBlocks; i++) {
  7089. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7090. if (ret != 0) {
  7091. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7092. return;
  7093. }
  7094. RECORD_MULTI_VALUE_STATS();
  7095. }
  7096. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7097. if (ret != 0) {
  7098. printf("Blake2sFinal failed, ret = %d\n", ret);
  7099. return;
  7100. }
  7101. count += i;
  7102. } while (bench_stats_check(start)
  7103. #ifdef MULTI_VALUE_STATISTICS
  7104. || runs < minimum_runs
  7105. #endif
  7106. );
  7107. }
  7108. else {
  7109. bench_stats_start(&count, &start);
  7110. do {
  7111. for (i = 0; i < numBlocks; i++) {
  7112. ret = wc_InitBlake2s(&b2s, 32);
  7113. if (ret != 0) {
  7114. printf("InitBlake2b failed, ret = %d\n", ret);
  7115. return;
  7116. }
  7117. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7118. if (ret != 0) {
  7119. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7120. return;
  7121. }
  7122. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7123. if (ret != 0) {
  7124. printf("Blake2sFinal failed, ret = %d\n", ret);
  7125. return;
  7126. }
  7127. RECORD_MULTI_VALUE_STATS();
  7128. }
  7129. count += i;
  7130. } while (bench_stats_check(start)
  7131. #ifdef MULTI_VALUE_STATISTICS
  7132. || runs < minimum_runs
  7133. #endif
  7134. );
  7135. }
  7136. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7137. #ifdef MULTI_VALUE_STATISTICS
  7138. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7139. #endif
  7140. }
  7141. #endif
  7142. #ifdef WOLFSSL_CMAC
  7143. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7144. {
  7145. Cmac cmac;
  7146. byte digest[AES_BLOCK_SIZE];
  7147. word32 digestSz = sizeof(digest);
  7148. double start;
  7149. int ret, i, count;
  7150. DECLARE_MULTI_VALUE_STATS_VARS()
  7151. #ifdef WOLFSSL_SECO_CAAM
  7152. unsigned int keyID;
  7153. int keyGroup = 1; /* group one was chosen arbitrarily */
  7154. int keyInfo = CAAM_KEY_TRANSIENT;
  7155. int keyType = CAAM_KEYTYPE_AES128;
  7156. byte pubKey[AES_256_KEY_SIZE];
  7157. if (keySz == AES_256_KEY_SIZE) {
  7158. keyType = CAAM_KEYTYPE_AES256;
  7159. }
  7160. if (useDeviceID &&
  7161. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7162. keyInfo, &keyID) != 0) {
  7163. printf("Error generating key in hsm\n");
  7164. return;
  7165. }
  7166. #endif
  7167. (void)useDeviceID;
  7168. bench_stats_start(&count, &start);
  7169. do {
  7170. #ifdef HAVE_FIPS
  7171. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7172. #else
  7173. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7174. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7175. #endif
  7176. if (ret != 0) {
  7177. printf("InitCmac failed, ret = %d\n", ret);
  7178. return;
  7179. }
  7180. #ifdef WOLFSSL_SECO_CAAM
  7181. if (useDeviceID) {
  7182. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7183. }
  7184. #endif
  7185. for (i = 0; i < numBlocks; i++) {
  7186. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7187. if (ret != 0) {
  7188. printf("CmacUpdate failed, ret = %d\n", ret);
  7189. return;
  7190. }
  7191. RECORD_MULTI_VALUE_STATS();
  7192. }
  7193. /* Note: final force zero's the Cmac struct */
  7194. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7195. if (ret != 0) {
  7196. printf("CmacFinal failed, ret = %d\n", ret);
  7197. return;
  7198. }
  7199. count += i;
  7200. } while (bench_stats_check(start)
  7201. #ifdef MULTI_VALUE_STATISTICS
  7202. || runs < minimum_runs
  7203. #endif
  7204. );
  7205. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7206. #ifdef MULTI_VALUE_STATISTICS
  7207. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7208. #endif
  7209. }
  7210. void bench_cmac(int useDeviceID)
  7211. {
  7212. #ifdef WOLFSSL_AES_128
  7213. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7214. #endif
  7215. #ifdef WOLFSSL_AES_256
  7216. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7217. #endif
  7218. }
  7219. #endif /* WOLFSSL_CMAC */
  7220. #ifdef HAVE_SCRYPT
  7221. void bench_scrypt(void)
  7222. {
  7223. byte derived[64];
  7224. double start;
  7225. int ret, i, count;
  7226. DECLARE_MULTI_VALUE_STATS_VARS()
  7227. bench_stats_start(&count, &start);
  7228. do {
  7229. for (i = 0; i < scryptCnt; i++) {
  7230. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7231. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7232. sizeof(derived));
  7233. if (ret != 0) {
  7234. printf("scrypt failed, ret = %d\n", ret);
  7235. goto exit;
  7236. }
  7237. RECORD_MULTI_VALUE_STATS();
  7238. }
  7239. count += i;
  7240. } while (bench_stats_check(start)
  7241. #ifdef MULTI_VALUE_STATISTICS
  7242. || runs < minimum_runs
  7243. #endif
  7244. );
  7245. exit:
  7246. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7247. #ifdef MULTI_VALUE_STATISTICS
  7248. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7249. #endif
  7250. }
  7251. #endif /* HAVE_SCRYPT */
  7252. #ifndef NO_HMAC
  7253. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7254. const byte* key, word32 keySz, const char* label)
  7255. {
  7256. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7257. sizeof(Hmac), HEAP_HINT);
  7258. double start;
  7259. int ret = 0, i, count = 0, times, pending = 0;
  7260. DECLARE_MULTI_VALUE_STATS_VARS()
  7261. #ifdef WOLFSSL_ASYNC_CRYPT
  7262. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7263. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7264. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7265. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7266. #else
  7267. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7268. #endif
  7269. (void)digestSz;
  7270. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7271. sizeof(Hmac), HEAP_HINT);
  7272. /* init keys */
  7273. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7274. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7275. useDeviceID ? devId : INVALID_DEVID);
  7276. if (ret != 0) {
  7277. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7278. goto exit;
  7279. }
  7280. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7281. if (ret != 0) {
  7282. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7283. goto exit;
  7284. }
  7285. }
  7286. bench_stats_start(&count, &start);
  7287. do {
  7288. for (times = 0; times < numBlocks || pending > 0; ) {
  7289. bench_async_poll(&pending);
  7290. /* while free pending slots in queue, submit ops */
  7291. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7292. if (bench_async_check(&ret,
  7293. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7294. &times, numBlocks, &pending)) {
  7295. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7296. if (!bench_async_handle(&ret,
  7297. BENCH_ASYNC_GET_DEV(hmac[i]),
  7298. 0, &times, &pending)) {
  7299. goto exit_hmac;
  7300. }
  7301. }
  7302. } /* for i */
  7303. } /* for times */
  7304. count += times;
  7305. times = 0;
  7306. do {
  7307. bench_async_poll(&pending);
  7308. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7309. if (bench_async_check(&ret,
  7310. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7311. &times, numBlocks, &pending)) {
  7312. ret = wc_HmacFinal(hmac[i], digest[i]);
  7313. if (!bench_async_handle(&ret,
  7314. BENCH_ASYNC_GET_DEV(hmac[i]),
  7315. 0, &times, &pending)) {
  7316. goto exit_hmac;
  7317. }
  7318. }
  7319. RECORD_MULTI_VALUE_STATS();
  7320. } /* for i */
  7321. } while (pending > 0);
  7322. } while (bench_stats_check(start)
  7323. #ifdef MULTI_VALUE_STATISTICS
  7324. || runs < minimum_runs
  7325. #endif
  7326. );
  7327. exit_hmac:
  7328. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7329. #ifdef MULTI_VALUE_STATISTICS
  7330. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7331. #endif
  7332. exit:
  7333. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7334. wc_HmacFree(hmac[i]);
  7335. }
  7336. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7337. #ifdef WOLFSSL_ASYNC_CRYPT
  7338. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7339. #endif
  7340. }
  7341. #ifndef NO_MD5
  7342. void bench_hmac_md5(int useDeviceID)
  7343. {
  7344. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7345. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7346. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7347. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7348. "HMAC-MD5");
  7349. }
  7350. #endif /* NO_MD5 */
  7351. #ifndef NO_SHA
  7352. void bench_hmac_sha(int useDeviceID)
  7353. {
  7354. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7355. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7356. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7357. 0x0b, 0x0b, 0x0b, 0x0b };
  7358. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7359. "HMAC-SHA");
  7360. }
  7361. #endif /* NO_SHA */
  7362. #ifdef WOLFSSL_SHA224
  7363. void bench_hmac_sha224(int useDeviceID)
  7364. {
  7365. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7366. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7367. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7368. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7369. 0x0b, 0x0b, 0x0b, 0x0b };
  7370. bench_hmac(useDeviceID, WC_SHA224,
  7371. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7372. "HMAC-SHA224");
  7373. }
  7374. #endif /* WOLFSSL_SHA224 */
  7375. #ifndef NO_SHA256
  7376. void bench_hmac_sha256(int useDeviceID)
  7377. {
  7378. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7379. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7380. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7381. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7382. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7383. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7384. "HMAC-SHA256");
  7385. }
  7386. #endif /* NO_SHA256 */
  7387. #ifdef WOLFSSL_SHA384
  7388. void bench_hmac_sha384(int useDeviceID)
  7389. {
  7390. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7391. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7392. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7393. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7394. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7395. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7396. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7397. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7398. "HMAC-SHA384");
  7399. }
  7400. #endif /* WOLFSSL_SHA384 */
  7401. #ifdef WOLFSSL_SHA512
  7402. void bench_hmac_sha512(int useDeviceID)
  7403. {
  7404. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7405. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7406. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7407. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7408. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7409. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7410. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7411. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7412. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7413. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7414. "HMAC-SHA512");
  7415. }
  7416. #endif /* WOLFSSL_SHA512 */
  7417. #ifndef NO_PWDBASED
  7418. void bench_pbkdf2(void)
  7419. {
  7420. double start;
  7421. int ret = 0, count = 0;
  7422. const char* passwd32 = "passwordpasswordpasswordpassword";
  7423. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7424. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7425. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7426. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7427. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7428. byte derived[32];
  7429. DECLARE_MULTI_VALUE_STATS_VARS()
  7430. bench_stats_start(&count, &start);
  7431. PRIVATE_KEY_UNLOCK();
  7432. do {
  7433. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7434. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7435. count++;
  7436. RECORD_MULTI_VALUE_STATS();
  7437. } while (bench_stats_check(start)
  7438. #ifdef MULTI_VALUE_STATISTICS
  7439. || runs < minimum_runs
  7440. #endif
  7441. );
  7442. PRIVATE_KEY_LOCK();
  7443. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7444. #ifdef MULTI_VALUE_STATISTICS
  7445. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7446. #endif
  7447. }
  7448. #endif /* !NO_PWDBASED */
  7449. #endif /* NO_HMAC */
  7450. #ifdef WOLFSSL_SIPHASH
  7451. void bench_siphash(void)
  7452. {
  7453. double start;
  7454. int ret = 0, count;
  7455. const char* passwd16 = "passwordpassword";
  7456. byte out[16];
  7457. int i;
  7458. DECLARE_MULTI_VALUE_STATS_VARS()
  7459. bench_stats_start(&count, &start);
  7460. do {
  7461. for (i = 0; i < numBlocks; i++) {
  7462. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7463. out, 8);
  7464. RECORD_MULTI_VALUE_STATS();
  7465. }
  7466. count += i;
  7467. } while (bench_stats_check(start)
  7468. #ifdef MULTI_VALUE_STATISTICS
  7469. || runs < minimum_runs
  7470. #endif
  7471. );
  7472. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7473. #ifdef MULTI_VALUE_STATISTICS
  7474. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7475. #endif
  7476. RESET_MULTI_VALUE_STATS_VARS();
  7477. bench_stats_start(&count, &start);
  7478. do {
  7479. for (i = 0; i < numBlocks; i++) {
  7480. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7481. out, 16);
  7482. RECORD_MULTI_VALUE_STATS();
  7483. }
  7484. count += i;
  7485. } while (bench_stats_check(start)
  7486. #ifdef MULTI_VALUE_STATISTICS
  7487. || runs < minimum_runs
  7488. #endif
  7489. );
  7490. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7491. #ifdef MULTI_VALUE_STATISTICS
  7492. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7493. #endif
  7494. }
  7495. #endif
  7496. #ifdef WC_SRTP_KDF
  7497. void bench_srtpkdf(void)
  7498. {
  7499. double start;
  7500. int count;
  7501. int ret = 0;
  7502. byte keyE[32];
  7503. byte keyA[20];
  7504. byte keyS[14];
  7505. const byte *key = bench_key_buf;
  7506. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7507. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7508. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7509. int kdrIdx = 0;
  7510. int i;
  7511. DECLARE_MULTI_VALUE_STATS_VARS()
  7512. bench_stats_start(&count, &start);
  7513. PRIVATE_KEY_UNLOCK();
  7514. do {
  7515. for (i = 0; i < numBlocks; i++) {
  7516. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7517. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7518. keyS, sizeof(keyS));
  7519. RECORD_MULTI_VALUE_STATS();
  7520. }
  7521. count += i;
  7522. } while (bench_stats_check(start)
  7523. #ifdef MULTI_VALUE_STATISTICS
  7524. || runs < minimum_runs
  7525. #endif
  7526. );
  7527. PRIVATE_KEY_LOCK();
  7528. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7529. #ifdef MULTI_VALUE_STATISTICS
  7530. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7531. #endif
  7532. RESET_MULTI_VALUE_STATS_VARS();
  7533. bench_stats_start(&count, &start);
  7534. PRIVATE_KEY_UNLOCK();
  7535. do {
  7536. for (i = 0; i < numBlocks; i++) {
  7537. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7538. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7539. keyS, sizeof(keyS));
  7540. RECORD_MULTI_VALUE_STATS();
  7541. }
  7542. count += i;
  7543. } while (bench_stats_check(start)
  7544. #ifdef MULTI_VALUE_STATISTICS
  7545. || runs < minimum_runs
  7546. #endif
  7547. );
  7548. PRIVATE_KEY_LOCK();
  7549. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7550. #ifdef MULTI_VALUE_STATISTICS
  7551. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7552. #endif
  7553. RESET_MULTI_VALUE_STATS_VARS();
  7554. bench_stats_start(&count, &start);
  7555. PRIVATE_KEY_UNLOCK();
  7556. do {
  7557. for (i = 0; i < numBlocks; i++) {
  7558. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7559. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7560. keyS, sizeof(keyS));
  7561. RECORD_MULTI_VALUE_STATS();
  7562. }
  7563. count += i;
  7564. } while (bench_stats_check(start)
  7565. #ifdef MULTI_VALUE_STATISTICS
  7566. || runs < minimum_runs
  7567. #endif
  7568. );
  7569. PRIVATE_KEY_LOCK();
  7570. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7571. #ifdef MULTI_VALUE_STATISTICS
  7572. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7573. #endif
  7574. RESET_MULTI_VALUE_STATS_VARS();
  7575. bench_stats_start(&count, &start);
  7576. PRIVATE_KEY_UNLOCK();
  7577. do {
  7578. for (i = 0; i < numBlocks; i++) {
  7579. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7580. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7581. keyS, sizeof(keyS));
  7582. RECORD_MULTI_VALUE_STATS();
  7583. }
  7584. count += i;
  7585. } while (bench_stats_check(start)
  7586. #ifdef MULTI_VALUE_STATISTICS
  7587. || runs < minimum_runs
  7588. #endif
  7589. );
  7590. PRIVATE_KEY_LOCK();
  7591. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7592. #ifdef MULTI_VALUE_STATISTICS
  7593. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7594. #endif
  7595. }
  7596. #endif
  7597. #ifndef NO_RSA
  7598. #if defined(WOLFSSL_KEY_GEN)
  7599. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7600. {
  7601. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7602. sizeof(RsaKey), HEAP_HINT);
  7603. double start = 0;
  7604. int ret = 0, i, count = 0, times, pending = 0;
  7605. const long rsa_e_val = WC_RSA_EXPONENT;
  7606. const char**desc = bench_desc_words[lng_index];
  7607. DECLARE_MULTI_VALUE_STATS_VARS()
  7608. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7609. sizeof(RsaKey), HEAP_HINT);
  7610. bench_stats_start(&count, &start);
  7611. do {
  7612. /* while free pending slots in queue, submit ops */
  7613. for (times = 0; times < genTimes || pending > 0; ) {
  7614. bench_async_poll(&pending);
  7615. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7616. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7617. 0, &times, genTimes, &pending)) {
  7618. wc_FreeRsaKey(genKey[i]);
  7619. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7620. if (ret < 0) {
  7621. goto exit;
  7622. }
  7623. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7624. &gRng);
  7625. if (!bench_async_handle(&ret,
  7626. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7627. &times, &pending)) {
  7628. goto exit;
  7629. }
  7630. }
  7631. } /* for i */
  7632. RECORD_MULTI_VALUE_STATS();
  7633. } /* for times */
  7634. count += times;
  7635. } while (bench_stats_check(start)
  7636. #ifdef MULTI_VALUE_STATISTICS
  7637. || runs < minimum_runs
  7638. #endif
  7639. );
  7640. exit:
  7641. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7642. start, ret);
  7643. #ifdef MULTI_VALUE_STATISTICS
  7644. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7645. #endif
  7646. /* cleanup */
  7647. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7648. wc_FreeRsaKey(genKey[i]);
  7649. }
  7650. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7651. }
  7652. void bench_rsaKeyGen(int useDeviceID)
  7653. {
  7654. int k;
  7655. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7656. static const word32 keySizes[2] = {1024, 2048 };
  7657. #elif RSA_MAX_SIZE >= 4096
  7658. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7659. (RSA_MIN_SIZE <= 1024)
  7660. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7661. #else
  7662. static const word32 keySizes[3] = {2048, 3072, 4096};
  7663. #endif
  7664. #elif RSA_MAX_SIZE >= 3072
  7665. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7666. (RSA_MIN_SIZE <= 1024)
  7667. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7668. #else
  7669. static const word32 keySizes[2] = {2048, 3072 };
  7670. #endif
  7671. #elif RSA_MAX_SIZE >= 2048
  7672. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7673. (RSA_MIN_SIZE <= 1024)
  7674. static const word32 keySizes[2] = {1024, 2048 };
  7675. #else
  7676. static const word32 keySizes[1] = {2048};
  7677. #endif
  7678. #else
  7679. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7680. (RSA_MIN_SIZE <= 1024)
  7681. static const word32 keySizes[1] = {1024 };
  7682. #else
  7683. #error No candidate RSA key sizes to benchmark.
  7684. #endif
  7685. #endif
  7686. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7687. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7688. }
  7689. }
  7690. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7691. {
  7692. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7693. }
  7694. #endif /* WOLFSSL_KEY_GEN */
  7695. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7696. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7697. #if defined(WOLFSSL_MDK_SHELL)
  7698. static char *certRSAname = "certs/rsa2048.der";
  7699. /* set by shell command */
  7700. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7701. #elif defined(FREESCALE_MQX)
  7702. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7703. #else
  7704. static const char *certRSAname = "certs/rsa2048.der";
  7705. #endif
  7706. #endif
  7707. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7708. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7709. #if defined(USE_CERT_BUFFERS_2048)
  7710. static const unsigned char rsa_2048_sig[] = {
  7711. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7712. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7713. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7714. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7715. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7716. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7717. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7718. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7719. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7720. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7721. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7722. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7723. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7724. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7725. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7726. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7727. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7728. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7729. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7730. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7731. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7732. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7733. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7734. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7735. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7736. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7737. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7738. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7739. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7740. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7741. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7742. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7743. };
  7744. #elif defined(USE_CERT_BUFFERS_3072)
  7745. static const unsigned char rsa_3072_sig[] = {
  7746. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7747. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7748. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7749. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7750. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7751. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7752. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7753. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7754. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7755. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7756. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7757. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7758. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7759. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7760. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7761. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7762. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7763. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7764. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7765. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7766. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7767. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7768. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7769. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7770. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7771. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7772. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7773. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7774. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7775. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7776. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7777. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7778. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7779. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7780. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7781. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7782. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7783. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7784. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7785. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7786. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7787. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7788. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7789. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7790. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7791. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7792. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7793. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7794. };
  7795. #else
  7796. #error Not Supported Yet!
  7797. #endif
  7798. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7799. static void bench_rsa_helper(int useDeviceID,
  7800. WC_ARRAY_ARG(rsaKey,
  7801. RsaKey,
  7802. BENCH_MAX_PENDING,
  7803. sizeof(RsaKey)),
  7804. word32 rsaKeySz)
  7805. {
  7806. int ret = 0, i, times, count = 0, pending = 0;
  7807. word32 idx = 0;
  7808. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7809. const char* messageStr = TEST_STRING;
  7810. const int len = (int)TEST_STRING_SZ;
  7811. #endif
  7812. double start = 0.0F;
  7813. const char**desc = bench_desc_words[lng_index];
  7814. DECLARE_MULTI_VALUE_STATS_VARS()
  7815. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7816. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7817. #endif
  7818. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7819. rsaKeySz, HEAP_HINT);
  7820. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7821. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7822. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7823. rsaKeySz, HEAP_HINT);
  7824. #else
  7825. byte* out[BENCH_MAX_PENDING];
  7826. #endif
  7827. XMEMSET(out, 0, sizeof(out));
  7828. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7829. rsaKeySz, HEAP_HINT);
  7830. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7831. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7832. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7833. rsaKeySz, HEAP_HINT);
  7834. if (out[0] == NULL) {
  7835. ret = MEMORY_E;
  7836. goto exit;
  7837. }
  7838. #endif
  7839. if (enc[0] == NULL) {
  7840. ret = MEMORY_E;
  7841. goto exit;
  7842. }
  7843. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7844. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7845. XMEMCPY(message, messageStr, len);
  7846. #endif
  7847. if (!rsa_sign_verify) {
  7848. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7849. /* begin public RSA */
  7850. bench_stats_start(&count, &start);
  7851. do {
  7852. for (times = 0; times < ntimes || pending > 0; ) {
  7853. bench_async_poll(&pending);
  7854. /* while free pending slots in queue, submit ops */
  7855. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7856. if (bench_async_check(&ret,
  7857. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7858. 1, &times, ntimes, &pending)) {
  7859. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7860. rsaKeySz/8, rsaKey[i],
  7861. GLOBAL_RNG);
  7862. if (!bench_async_handle(&ret,
  7863. BENCH_ASYNC_GET_DEV(
  7864. rsaKey[i]), 1, &times,
  7865. &pending)) {
  7866. goto exit_rsa_verify;
  7867. }
  7868. }
  7869. } /* for i */
  7870. RECORD_MULTI_VALUE_STATS();
  7871. } /* for times */
  7872. count += times;
  7873. } while (bench_stats_check(start)
  7874. #ifdef MULTI_VALUE_STATISTICS
  7875. || runs < minimum_runs
  7876. #endif
  7877. );
  7878. exit_rsa_verify:
  7879. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7880. useDeviceID, count, start, ret);
  7881. #ifdef MULTI_VALUE_STATISTICS
  7882. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7883. #endif
  7884. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7885. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7886. if (ret < 0) {
  7887. goto exit;
  7888. }
  7889. RESET_MULTI_VALUE_STATS_VARS();
  7890. /* capture resulting encrypt length */
  7891. idx = (word32)(rsaKeySz/8);
  7892. /* begin private async RSA */
  7893. bench_stats_start(&count, &start);
  7894. do {
  7895. for (times = 0; times < ntimes || pending > 0; ) {
  7896. bench_async_poll(&pending);
  7897. /* while free pending slots in queue, submit ops */
  7898. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7899. if (bench_async_check(&ret,
  7900. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7901. 1, &times, ntimes, &pending)) {
  7902. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7903. rsaKeySz/8, rsaKey[i]);
  7904. if (!bench_async_handle(&ret,
  7905. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7906. 1, &times, &pending)) {
  7907. goto exit_rsa_pub;
  7908. }
  7909. }
  7910. } /* for i */
  7911. RECORD_MULTI_VALUE_STATS();
  7912. } /* for times */
  7913. count += times;
  7914. } while (bench_stats_check(start)
  7915. #ifdef MULTI_VALUE_STATISTICS
  7916. || runs < minimum_runs
  7917. #endif
  7918. );
  7919. exit_rsa_pub:
  7920. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7921. useDeviceID, count, start, ret);
  7922. #ifdef MULTI_VALUE_STATISTICS
  7923. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7924. #endif
  7925. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7926. }
  7927. else {
  7928. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7929. /* begin RSA sign */
  7930. bench_stats_start(&count, &start);
  7931. do {
  7932. for (times = 0; times < ntimes || pending > 0; ) {
  7933. bench_async_poll(&pending);
  7934. /* while free pending slots in queue, submit ops */
  7935. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7936. if (bench_async_check(&ret,
  7937. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7938. 1, &times, ntimes, &pending)) {
  7939. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7940. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7941. if (!bench_async_handle(&ret,
  7942. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7943. 1, &times, &pending)) {
  7944. goto exit_rsa_sign;
  7945. }
  7946. }
  7947. } /* for i */
  7948. RECORD_MULTI_VALUE_STATS();
  7949. } /* for times */
  7950. count += times;
  7951. } while (bench_stats_check(start)
  7952. #ifdef MULTI_VALUE_STATISTICS
  7953. || runs < minimum_runs
  7954. #endif
  7955. );
  7956. exit_rsa_sign:
  7957. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7958. count, start, ret);
  7959. #ifdef MULTI_VALUE_STATISTICS
  7960. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7961. #endif
  7962. if (ret < 0) {
  7963. goto exit;
  7964. }
  7965. RESET_MULTI_VALUE_STATS_VARS();
  7966. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  7967. /* capture resulting encrypt length */
  7968. idx = rsaKeySz/8;
  7969. /* begin RSA verify */
  7970. bench_stats_start(&count, &start);
  7971. do {
  7972. for (times = 0; times < ntimes || pending > 0; ) {
  7973. bench_async_poll(&pending);
  7974. /* while free pending slots in queue, submit ops */
  7975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7976. if (bench_async_check(&ret,
  7977. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7978. 1, &times, ntimes, &pending)) {
  7979. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7980. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7981. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  7982. rsaKeySz/8, rsaKey[i]);
  7983. #elif defined(USE_CERT_BUFFERS_2048)
  7984. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  7985. idx = sizeof(rsa_2048_sig);
  7986. out[i] = NULL;
  7987. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7988. &out[i], rsaKey[i]);
  7989. if (ret > 0) {
  7990. ret = 0;
  7991. }
  7992. #elif defined(USE_CERT_BUFFERS_3072)
  7993. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  7994. idx = sizeof(rsa_3072_sig);
  7995. out[i] = NULL;
  7996. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  7997. &out[i], rsaKey[i]);
  7998. if (ret > 0)
  7999. ret = 0;
  8000. #endif
  8001. if (!bench_async_handle(&ret,
  8002. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8003. 1, &times, &pending)) {
  8004. goto exit_rsa_verifyinline;
  8005. }
  8006. }
  8007. } /* for i */
  8008. RECORD_MULTI_VALUE_STATS();
  8009. } /* for times */
  8010. count += times;
  8011. } while (bench_stats_check(start)
  8012. #ifdef MULTI_VALUE_STATISTICS
  8013. || runs < minimum_runs
  8014. #endif
  8015. );
  8016. exit_rsa_verifyinline:
  8017. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8018. useDeviceID, count, start, ret);
  8019. #ifdef MULTI_VALUE_STATISTICS
  8020. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8021. #endif
  8022. }
  8023. exit:
  8024. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8025. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8026. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8027. #endif
  8028. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8029. WC_FREE_VAR(message, HEAP_HINT);
  8030. #endif
  8031. }
  8032. void bench_rsa(int useDeviceID)
  8033. {
  8034. int i;
  8035. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8036. sizeof(RsaKey), HEAP_HINT);
  8037. int ret = 0;
  8038. word32 rsaKeySz = 0;
  8039. const byte* tmp;
  8040. size_t bytes;
  8041. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8042. word32 idx;
  8043. #endif
  8044. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8045. sizeof(RsaKey), HEAP_HINT);
  8046. #ifdef USE_CERT_BUFFERS_1024
  8047. tmp = rsa_key_der_1024;
  8048. bytes = (size_t)sizeof_rsa_key_der_1024;
  8049. rsaKeySz = 1024;
  8050. #elif defined(USE_CERT_BUFFERS_2048)
  8051. tmp = rsa_key_der_2048;
  8052. bytes = (size_t)sizeof_rsa_key_der_2048;
  8053. rsaKeySz = 2048;
  8054. #elif defined(USE_CERT_BUFFERS_3072)
  8055. tmp = rsa_key_der_3072;
  8056. bytes = (size_t)sizeof_rsa_key_der_3072;
  8057. rsaKeySz = 3072;
  8058. #elif defined(USE_CERT_BUFFERS_4096)
  8059. tmp = client_key_der_4096;
  8060. bytes = (size_t)sizeof_client_key_der_4096;
  8061. rsaKeySz = 4096;
  8062. #else
  8063. #error "need a cert buffer size"
  8064. #endif /* USE_CERT_BUFFERS */
  8065. /* init keys */
  8066. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8067. /* setup an async context for each key */
  8068. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8069. useDeviceID ? devId : INVALID_DEVID);
  8070. if (ret < 0) {
  8071. goto exit;
  8072. }
  8073. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8074. #ifdef WC_RSA_BLINDING
  8075. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8076. if (ret != 0)
  8077. goto exit;
  8078. #endif
  8079. #endif
  8080. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8081. /* decode the private key */
  8082. idx = 0;
  8083. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8084. rsaKey[i], (word32)bytes)) != 0) {
  8085. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8086. goto exit;
  8087. }
  8088. #elif defined(WOLFSSL_PUBLIC_MP)
  8089. /* get offset to public portion of the RSA key */
  8090. #ifdef USE_CERT_BUFFERS_1024
  8091. bytes = 11;
  8092. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8093. bytes = 12;
  8094. #endif
  8095. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8096. if (ret != 0) {
  8097. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8098. goto exit;
  8099. }
  8100. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8101. if (ret != 0) {
  8102. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8103. goto exit;
  8104. }
  8105. #else
  8106. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8107. rsaKeySz = 0;
  8108. #endif
  8109. }
  8110. if (rsaKeySz > 0) {
  8111. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8112. }
  8113. (void)bytes;
  8114. (void)tmp;
  8115. exit:
  8116. /* cleanup */
  8117. if (WC_ARRAY_OK(rsaKey)) {
  8118. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8119. wc_FreeRsaKey(rsaKey[i]);
  8120. }
  8121. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8122. }
  8123. }
  8124. #ifdef WOLFSSL_KEY_GEN
  8125. /* bench any size of RSA key */
  8126. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8127. {
  8128. int ret = 0, i, pending = 0;
  8129. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8130. sizeof(RsaKey), HEAP_HINT);
  8131. int isPending[BENCH_MAX_PENDING];
  8132. long exp = 65537L;
  8133. /* clear for done cleanup */
  8134. XMEMSET(isPending, 0, sizeof(isPending));
  8135. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8136. sizeof(RsaKey), HEAP_HINT);
  8137. /* init keys */
  8138. do {
  8139. pending = 0;
  8140. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8141. if (!isPending[i]) { /* if making the key is pending then just call
  8142. * wc_MakeRsaKey again */
  8143. /* setup an async context for each key */
  8144. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8145. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8146. goto exit;
  8147. }
  8148. #ifdef WC_RSA_BLINDING
  8149. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8150. if (ret != 0)
  8151. goto exit;
  8152. #endif
  8153. }
  8154. /* create the RSA key */
  8155. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8156. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8157. isPending[i] = 1;
  8158. pending = 1;
  8159. }
  8160. else if (ret != 0) {
  8161. printf("wc_MakeRsaKey failed! %d\n", ret);
  8162. goto exit;
  8163. }
  8164. } /* for i */
  8165. } while (pending > 0);
  8166. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8167. exit:
  8168. /* cleanup */
  8169. if (WC_ARRAY_OK(rsaKey)) {
  8170. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8171. wc_FreeRsaKey(rsaKey[i]);
  8172. }
  8173. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8174. }
  8175. }
  8176. #endif /* WOLFSSL_KEY_GEN */
  8177. #endif /* !NO_RSA */
  8178. #ifndef NO_DH
  8179. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8180. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8181. #if defined(WOLFSSL_MDK_SHELL)
  8182. static char *certDHname = "certs/dh2048.der";
  8183. /* set by shell command */
  8184. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8185. #elif defined(FREESCALE_MQX)
  8186. static char *certDHname = "a:\\certs\\dh2048.der";
  8187. #elif defined(NO_ASN)
  8188. /* do nothing, but don't need a file */
  8189. #else
  8190. static const char *certDHname = "certs/dh2048.der";
  8191. #endif
  8192. #endif
  8193. #ifdef HAVE_FFDHE_4096
  8194. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8195. #else
  8196. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8197. #endif
  8198. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8199. void bench_dh(int useDeviceID)
  8200. {
  8201. int ret = 0, i;
  8202. int count = 0, times, pending = 0;
  8203. const byte* tmp = NULL;
  8204. double start = 0.0F;
  8205. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8206. sizeof(DhKey), HEAP_HINT);
  8207. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8208. const char**desc = bench_desc_words[lng_index];
  8209. #ifndef NO_ASN
  8210. size_t bytes = 0;
  8211. word32 idx;
  8212. #endif
  8213. word32 pubSz[BENCH_MAX_PENDING];
  8214. word32 privSz[BENCH_MAX_PENDING];
  8215. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8216. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8217. word32 agreeSz[BENCH_MAX_PENDING];
  8218. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8219. #ifdef HAVE_PUBLIC_FFDHE
  8220. const DhParams *params = NULL;
  8221. #else
  8222. int paramName = 0;
  8223. #endif
  8224. #endif
  8225. DECLARE_MULTI_VALUE_STATS_VARS()
  8226. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8227. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8228. WC_DECLARE_VAR(pub2, byte,
  8229. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8230. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8231. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8232. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8233. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8234. WC_DECLARE_VAR(priv2, byte,
  8235. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8236. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8237. XMEMSET(pub, 0, sizeof(pub));
  8238. XMEMSET(agree, 0, sizeof(agree));
  8239. XMEMSET(priv, 0, sizeof(priv));
  8240. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8241. sizeof(DhKey), HEAP_HINT);
  8242. WC_ALLOC_ARRAY(pub, byte,
  8243. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8244. WC_ALLOC_ARRAY(agree, byte,
  8245. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8246. WC_ALLOC_ARRAY(priv, byte,
  8247. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8248. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8249. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8250. (void)tmp;
  8251. if (!use_ffdhe) {
  8252. #if defined(NO_ASN)
  8253. dhKeySz = 1024;
  8254. /* do nothing, but don't use default FILE */
  8255. #elif defined(USE_CERT_BUFFERS_1024)
  8256. tmp = dh_key_der_1024;
  8257. bytes = (size_t)sizeof_dh_key_der_1024;
  8258. dhKeySz = 1024;
  8259. #elif defined(USE_CERT_BUFFERS_2048)
  8260. tmp = dh_key_der_2048;
  8261. bytes = (size_t)sizeof_dh_key_der_2048;
  8262. dhKeySz = 2048;
  8263. #elif defined(USE_CERT_BUFFERS_3072)
  8264. tmp = dh_key_der_3072;
  8265. bytes = (size_t)sizeof_dh_key_der_3072;
  8266. dhKeySz = 3072;
  8267. #elif defined(USE_CERT_BUFFERS_4096)
  8268. tmp = dh_key_der_4096;
  8269. bytes = (size_t)sizeof_dh_key_der_4096;
  8270. dhKeySz = 4096;
  8271. #else
  8272. #error "need to define a cert buffer size"
  8273. #endif /* USE_CERT_BUFFERS */
  8274. }
  8275. #ifdef HAVE_FFDHE_2048
  8276. else if (use_ffdhe == 2048) {
  8277. #ifdef HAVE_PUBLIC_FFDHE
  8278. params = wc_Dh_ffdhe2048_Get();
  8279. #else
  8280. paramName = WC_FFDHE_2048;
  8281. #endif
  8282. dhKeySz = 2048;
  8283. }
  8284. #endif
  8285. #ifdef HAVE_FFDHE_3072
  8286. else if (use_ffdhe == 3072) {
  8287. #ifdef HAVE_PUBLIC_FFDHE
  8288. params = wc_Dh_ffdhe3072_Get();
  8289. #else
  8290. paramName = WC_FFDHE_3072;
  8291. #endif
  8292. dhKeySz = 3072;
  8293. }
  8294. #endif
  8295. #ifdef HAVE_FFDHE_4096
  8296. else if (use_ffdhe == 4096) {
  8297. #ifdef HAVE_PUBLIC_FFDHE
  8298. params = wc_Dh_ffdhe4096_Get();
  8299. #else
  8300. paramName = WC_FFDHE_4096;
  8301. #endif
  8302. dhKeySz = 4096;
  8303. }
  8304. #endif
  8305. /* init keys */
  8306. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8307. /* setup an async context for each key */
  8308. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8309. useDeviceID ? devId : INVALID_DEVID);
  8310. if (ret != 0)
  8311. goto exit;
  8312. /* setup key */
  8313. if (!use_ffdhe) {
  8314. #ifdef NO_ASN
  8315. ret = wc_DhSetKey(dhKey[i], dh_p,
  8316. sizeof(dh_p), dh_g, sizeof(dh_g));
  8317. #else
  8318. idx = 0;
  8319. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8320. #endif
  8321. }
  8322. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8323. #ifdef HAVE_PUBLIC_FFDHE
  8324. else if (params != NULL) {
  8325. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8326. params->g, params->g_len);
  8327. }
  8328. #else
  8329. else if (paramName != 0) {
  8330. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8331. }
  8332. #endif
  8333. #endif
  8334. if (ret != 0) {
  8335. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8336. goto exit;
  8337. }
  8338. }
  8339. /* Key Gen */
  8340. bench_stats_start(&count, &start);
  8341. PRIVATE_KEY_UNLOCK();
  8342. do {
  8343. /* while free pending slots in queue, submit ops */
  8344. for (times = 0; times < genTimes || pending > 0; ) {
  8345. bench_async_poll(&pending);
  8346. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8347. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8348. 0, &times, genTimes, &pending)) {
  8349. privSz[i] = BENCH_DH_PRIV_SIZE;
  8350. pubSz[i] = BENCH_DH_KEY_SIZE;
  8351. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8352. priv[i], &privSz[i],
  8353. pub[i], &pubSz[i]);
  8354. if (!bench_async_handle(&ret,
  8355. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8356. 0, &times, &pending)) {
  8357. goto exit_dh_gen;
  8358. }
  8359. }
  8360. } /* for i */
  8361. RECORD_MULTI_VALUE_STATS();
  8362. } /* for times */
  8363. count += times;
  8364. } while (bench_stats_check(start)
  8365. #ifdef MULTI_VALUE_STATISTICS
  8366. || runs < minimum_runs
  8367. #endif
  8368. );
  8369. PRIVATE_KEY_LOCK();
  8370. exit_dh_gen:
  8371. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8372. useDeviceID, count, start, ret);
  8373. #ifdef MULTI_VALUE_STATISTICS
  8374. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8375. #endif
  8376. if (ret < 0) {
  8377. goto exit;
  8378. }
  8379. RESET_MULTI_VALUE_STATS_VARS();
  8380. /* Generate key to use as other public */
  8381. PRIVATE_KEY_UNLOCK();
  8382. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8383. priv2, &privSz2, pub2, &pubSz2);
  8384. PRIVATE_KEY_LOCK();
  8385. #ifdef WOLFSSL_ASYNC_CRYPT
  8386. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8387. #endif
  8388. /* Key Agree */
  8389. bench_stats_start(&count, &start);
  8390. PRIVATE_KEY_UNLOCK();
  8391. do {
  8392. for (times = 0; times < agreeTimes || pending > 0; ) {
  8393. bench_async_poll(&pending);
  8394. /* while free pending slots in queue, submit ops */
  8395. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8396. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8397. 0, &times, agreeTimes, &pending)) {
  8398. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8399. privSz[i], pub2, pubSz2);
  8400. if (!bench_async_handle(&ret,
  8401. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8402. goto exit;
  8403. }
  8404. }
  8405. } /* for i */
  8406. RECORD_MULTI_VALUE_STATS();
  8407. } /* for times */
  8408. count += times;
  8409. } while (bench_stats_check(start)
  8410. #ifdef MULTI_VALUE_STATISTICS
  8411. || runs < minimum_runs
  8412. #endif
  8413. );
  8414. PRIVATE_KEY_LOCK();
  8415. exit:
  8416. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8417. useDeviceID, count, start, ret);
  8418. #ifdef MULTI_VALUE_STATISTICS
  8419. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8420. #endif
  8421. /* cleanup */
  8422. if (WC_ARRAY_OK(dhKey)) {
  8423. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8424. wc_FreeDhKey(dhKey[i]);
  8425. }
  8426. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8427. }
  8428. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8429. WC_FREE_VAR(pub2, HEAP_HINT);
  8430. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8431. WC_FREE_VAR(priv2, HEAP_HINT);
  8432. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8433. }
  8434. #endif /* !NO_DH */
  8435. #ifdef WOLFSSL_HAVE_KYBER
  8436. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8437. KyberKey* key)
  8438. {
  8439. int ret = 0, times, count, pending = 0;
  8440. double start;
  8441. const char**desc = bench_desc_words[lng_index];
  8442. DECLARE_MULTI_VALUE_STATS_VARS()
  8443. /* KYBER Make Key */
  8444. bench_stats_start(&count, &start);
  8445. do {
  8446. /* while free pending slots in queue, submit ops */
  8447. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8448. wc_KyberKey_Free(key);
  8449. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8450. if (ret != 0)
  8451. goto exit;
  8452. #ifdef KYBER_NONDETERMINISTIC
  8453. ret = wc_KyberKey_MakeKey(key, &gRng);
  8454. #else
  8455. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8456. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8457. #endif
  8458. if (ret != 0)
  8459. goto exit;
  8460. RECORD_MULTI_VALUE_STATS();
  8461. } /* for times */
  8462. count += times;
  8463. } while (bench_stats_check(start)
  8464. #ifdef MULTI_VALUE_STATISTICS
  8465. || runs < minimum_runs
  8466. #endif
  8467. );
  8468. exit:
  8469. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8470. #ifdef MULTI_VALUE_STATISTICS
  8471. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8472. #endif
  8473. }
  8474. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8475. {
  8476. int ret = 0, times, count, pending = 0;
  8477. double start;
  8478. const char**desc = bench_desc_words[lng_index];
  8479. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8480. byte ss[KYBER_SS_SZ];
  8481. word32 ctSz;
  8482. DECLARE_MULTI_VALUE_STATS_VARS()
  8483. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8484. if (ret != 0) {
  8485. return;
  8486. }
  8487. /* KYBER Encapsulate */
  8488. bench_stats_start(&count, &start);
  8489. do {
  8490. /* while free pending slots in queue, submit ops */
  8491. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8492. #ifdef KYBER_NONDETERMINISTIC
  8493. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8494. #else
  8495. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8496. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8497. sizeof(rand));
  8498. #endif
  8499. if (ret != 0)
  8500. goto exit_encap;
  8501. RECORD_MULTI_VALUE_STATS();
  8502. } /* for times */
  8503. count += times;
  8504. } while (bench_stats_check(start)
  8505. #ifdef MULTI_VALUE_STATISTICS
  8506. || runs < minimum_runs
  8507. #endif
  8508. );
  8509. exit_encap:
  8510. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8511. #ifdef MULTI_VALUE_STATISTICS
  8512. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8513. #endif
  8514. RESET_MULTI_VALUE_STATS_VARS();
  8515. /* KYBER Decapsulate */
  8516. bench_stats_start(&count, &start);
  8517. do {
  8518. /* while free pending slots in queue, submit ops */
  8519. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8520. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8521. if (ret != 0)
  8522. goto exit_decap;
  8523. RECORD_MULTI_VALUE_STATS();
  8524. } /* for times */
  8525. count += times;
  8526. } while (bench_stats_check(start)
  8527. #ifdef MULTI_VALUE_STATISTICS
  8528. || runs < minimum_runs
  8529. #endif
  8530. );
  8531. exit_decap:
  8532. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8533. #ifdef MULTI_VALUE_STATISTICS
  8534. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8535. #endif
  8536. }
  8537. void bench_kyber(int type)
  8538. {
  8539. KyberKey key;
  8540. const char* name = NULL;
  8541. int keySize = 0;
  8542. switch (type) {
  8543. #ifdef WOLFSSL_KYBER512
  8544. case KYBER512:
  8545. name = "KYBER512 ";
  8546. keySize = 128;
  8547. break;
  8548. #endif
  8549. #ifdef WOLFSSL_KYBER768
  8550. case KYBER768:
  8551. name = "KYBER768 ";
  8552. keySize = 192;
  8553. break;
  8554. #endif
  8555. #ifdef WOLFSSL_KYBER1024
  8556. case KYBER1024:
  8557. name = "KYBER1024";
  8558. keySize = 256;
  8559. break;
  8560. #endif
  8561. }
  8562. bench_kyber_keygen(type, name, keySize, &key);
  8563. bench_kyber_encap(name, keySize, &key);
  8564. wc_KyberKey_Free(&key);
  8565. }
  8566. #endif
  8567. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8568. /* WC_LMS_PARM_L2_H10_W2
  8569. * signature length: 9300 */
  8570. static const byte lms_priv_L2_H10_W2[64] =
  8571. {
  8572. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8573. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8574. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8575. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8576. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8577. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8578. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8579. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8580. };
  8581. static const byte lms_pub_L2_H10_W2[60] =
  8582. {
  8583. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8584. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8585. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8586. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8587. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8588. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8589. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8590. 0x7F,0xC8,0x91,0xB0
  8591. };
  8592. /* WC_LMS_PARM_L2_H10_W4
  8593. * signature length: 5076 */
  8594. static const byte lms_priv_L2_H10_W4[64] =
  8595. {
  8596. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8597. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8598. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8599. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8600. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8601. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8602. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8603. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8604. };
  8605. static const byte lms_pub_L2_H10_W4[60] =
  8606. {
  8607. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8608. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8609. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8610. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8611. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8612. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8613. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8614. 0x6B,0x9A,0xD3,0x14
  8615. };
  8616. /* WC_LMS_PARM_L3_H5_W4
  8617. * signature length: 7160 */
  8618. static const byte lms_priv_L3_H5_W4[64] =
  8619. {
  8620. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8621. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8622. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8623. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8624. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8625. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8626. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8627. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8628. };
  8629. static const byte lms_pub_L3_H5_W4[60] =
  8630. {
  8631. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8632. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8633. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8634. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8635. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8636. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8637. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8638. 0xAB,0x4B,0x51,0x39
  8639. };
  8640. /* WC_LMS_PARM_L3_H5_W8
  8641. * signature length: 3992 */
  8642. static const byte lms_priv_L3_H5_W8[64] =
  8643. {
  8644. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8645. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8646. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8647. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8648. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8649. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8650. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8651. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8652. };
  8653. static const byte lms_pub_L3_H5_W8[60] =
  8654. {
  8655. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8656. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8657. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8658. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8659. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8660. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8661. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8662. 0x83,0xAB,0x43,0xAF
  8663. };
  8664. /* WC_LMS_PARM_L3_H10_W4
  8665. * signature length: 7640 */
  8666. static const byte lms_priv_L3_H10_W4[64] =
  8667. {
  8668. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8669. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8670. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8671. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8672. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8673. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8674. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8675. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8676. };
  8677. static const byte lms_pub_L3_H10_W4[60] =
  8678. {
  8679. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8680. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8681. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8682. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8683. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8684. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8685. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8686. 0x8D,0x78,0xD5,0xA8
  8687. };
  8688. /* WC_LMS_PARM_L4_H5_W8
  8689. * signature length: 5340 */
  8690. static const byte lms_priv_L4_H5_W8[64] =
  8691. {
  8692. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8693. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8694. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8695. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8696. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8697. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8698. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8699. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8700. };
  8701. static const byte lms_pub_L4_H5_W8[60] =
  8702. {
  8703. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8704. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8705. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8706. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8707. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8708. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8709. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8710. 0x74,0x24,0x12,0xC8
  8711. };
  8712. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8713. {
  8714. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8715. * BE USED FOR TESTING PURPOSES! Production applications should
  8716. * write only to non-volatile storage. */
  8717. XMEMCPY(context, priv, privSz);
  8718. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8719. }
  8720. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8721. {
  8722. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8723. * BE USED FOR TESTING PURPOSES! */
  8724. XMEMCPY(priv, context, privSz);
  8725. return WC_LMS_RC_READ_TO_MEMORY;
  8726. }
  8727. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8728. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8729. {
  8730. WC_RNG rng;
  8731. LmsKey key;
  8732. int ret;
  8733. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8734. int times = 0;
  8735. int count = 0;
  8736. double start = 0.0F;
  8737. int levels;
  8738. int height;
  8739. int winternitz;
  8740. const char* str = wc_LmsKey_ParmToStr(parm);
  8741. DECLARE_MULTI_VALUE_STATS_VARS()
  8742. #ifndef HAVE_FIPS
  8743. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8744. #else
  8745. ret = wc_InitRng(&rng);
  8746. #endif
  8747. if (ret != 0) {
  8748. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8749. return;
  8750. }
  8751. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8752. if (ret) {
  8753. printf("wc_LmsKey_Init failed: %d\n", ret);
  8754. wc_FreeRng(&rng);
  8755. return;
  8756. }
  8757. count = 0;
  8758. bench_stats_start(&count, &start);
  8759. do {
  8760. /* LMS is stateful. Async queuing not practical. */
  8761. for (times = 0; times < 1; ++times) {
  8762. wc_LmsKey_Free(&key);
  8763. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8764. if (ret) {
  8765. printf("wc_LmsKey_Init failed: %d\n", ret);
  8766. goto exit_lms_keygen;
  8767. }
  8768. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8769. if (ret) {
  8770. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8771. goto exit_lms_keygen;
  8772. }
  8773. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8774. if (ret) {
  8775. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8776. ret);
  8777. goto exit_lms_keygen;
  8778. }
  8779. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8780. if (ret) {
  8781. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8782. ret);
  8783. goto exit_lms_keygen;
  8784. }
  8785. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8786. if (ret) {
  8787. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8788. goto exit_lms_keygen;
  8789. }
  8790. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8791. if (ret) {
  8792. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8793. ret);
  8794. goto exit_lms_keygen;
  8795. }
  8796. ret = wc_LmsKey_MakeKey(&key, &rng);
  8797. if (ret) {
  8798. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8799. goto exit_lms_keygen;
  8800. }
  8801. RECORD_MULTI_VALUE_STATS();
  8802. }
  8803. count += times;
  8804. } while (bench_stats_check(start)
  8805. #ifdef MULTI_VALUE_STATISTICS
  8806. || runs < minimum_runs
  8807. #endif
  8808. );
  8809. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8810. count, start, ret);
  8811. #ifdef MULTI_VALUE_STATISTICS
  8812. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8813. #endif
  8814. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8815. if (ret) {
  8816. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8817. }
  8818. exit_lms_keygen:
  8819. wc_LmsKey_Free(&key);
  8820. wc_FreeRng(&rng);
  8821. }
  8822. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8823. {
  8824. LmsKey key;
  8825. int ret = 0;
  8826. const char * msg = TEST_STRING;
  8827. word32 msgSz = TEST_STRING_SZ;
  8828. byte * sig = NULL;
  8829. word32 sigSz = 0;
  8830. word32 privLen = 0;
  8831. int loaded = 0;
  8832. int times = 0;
  8833. int count = 0;
  8834. double start = 0.0F;
  8835. const char * str = wc_LmsKey_ParmToStr(parm);
  8836. DECLARE_MULTI_VALUE_STATS_VARS()
  8837. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8838. if (ret) {
  8839. printf("wc_LmsKey_Init failed: %d\n", ret);
  8840. goto exit_lms_sign_verify;
  8841. }
  8842. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8843. if (ret) {
  8844. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8845. goto exit_lms_sign_verify;
  8846. }
  8847. switch (parm) {
  8848. case WC_LMS_PARM_L2_H10_W2:
  8849. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8850. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8851. break;
  8852. case WC_LMS_PARM_L2_H10_W4:
  8853. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8854. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8855. break;
  8856. case WC_LMS_PARM_L3_H5_W4:
  8857. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8858. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8859. break;
  8860. case WC_LMS_PARM_L3_H5_W8:
  8861. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8862. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8863. break;
  8864. case WC_LMS_PARM_L3_H10_W4:
  8865. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8866. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8867. break;
  8868. case WC_LMS_PARM_L4_H5_W8:
  8869. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8870. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8871. break;
  8872. case WC_LMS_PARM_NONE:
  8873. case WC_LMS_PARM_L1_H15_W2:
  8874. case WC_LMS_PARM_L1_H15_W4:
  8875. case WC_LMS_PARM_L2_H10_W8:
  8876. case WC_LMS_PARM_L3_H5_W2:
  8877. case WC_LMS_PARM_L1_H5_W1:
  8878. case WC_LMS_PARM_L1_H5_W2:
  8879. case WC_LMS_PARM_L1_H5_W4:
  8880. case WC_LMS_PARM_L1_H5_W8:
  8881. case WC_LMS_PARM_L1_H10_W2:
  8882. case WC_LMS_PARM_L1_H10_W4:
  8883. case WC_LMS_PARM_L1_H10_W8:
  8884. case WC_LMS_PARM_L1_H15_W8:
  8885. case WC_LMS_PARM_L1_H20_W2:
  8886. case WC_LMS_PARM_L1_H20_W4:
  8887. case WC_LMS_PARM_L1_H20_W8:
  8888. case WC_LMS_PARM_L2_H5_W2:
  8889. case WC_LMS_PARM_L2_H5_W4:
  8890. case WC_LMS_PARM_L2_H5_W8:
  8891. case WC_LMS_PARM_L2_H15_W2:
  8892. case WC_LMS_PARM_L2_H15_W4:
  8893. case WC_LMS_PARM_L2_H15_W8:
  8894. case WC_LMS_PARM_L2_H20_W2:
  8895. case WC_LMS_PARM_L2_H20_W4:
  8896. case WC_LMS_PARM_L2_H20_W8:
  8897. case WC_LMS_PARM_L3_H10_W8:
  8898. case WC_LMS_PARM_L4_H5_W2:
  8899. case WC_LMS_PARM_L4_H5_W4:
  8900. case WC_LMS_PARM_L4_H10_W4:
  8901. case WC_LMS_PARM_L4_H10_W8:
  8902. default:
  8903. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8904. break;
  8905. }
  8906. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8907. if (ret) {
  8908. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8909. goto exit_lms_sign_verify;
  8910. }
  8911. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8912. if (ret) {
  8913. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8914. goto exit_lms_sign_verify;
  8915. }
  8916. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8917. if (ret) {
  8918. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  8919. goto exit_lms_sign_verify;
  8920. }
  8921. /* Even with saved priv/pub keys, we must still reload the private
  8922. * key before using it. Reloading the private key is the bottleneck
  8923. * for larger heights. Only print load time in debug builds. */
  8924. count = 0;
  8925. bench_stats_start(&count, &start);
  8926. #ifndef WOLFSSL_WC_LMS_SMALL
  8927. do {
  8928. #ifdef WOLFSSL_WC_LMS
  8929. key.priv.inited = 0;
  8930. key.state = WC_LMS_STATE_PARMSET;
  8931. #endif
  8932. ret = wc_LmsKey_Reload(&key);
  8933. if (ret) {
  8934. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8935. goto exit_lms_sign_verify;
  8936. }
  8937. RECORD_MULTI_VALUE_STATS();
  8938. count++;
  8939. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8940. if (ret) {
  8941. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8942. goto exit_lms_sign_verify;
  8943. }
  8944. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8945. if (ret) {
  8946. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8947. goto exit_lms_sign_verify;
  8948. }
  8949. #ifdef HAVE_LIBLMS
  8950. break;
  8951. #endif
  8952. } while (bench_stats_check(start)
  8953. #ifdef MULTI_VALUE_STATISTICS
  8954. || runs < minimum_runs
  8955. #endif
  8956. );
  8957. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  8958. count, start, ret);
  8959. #ifdef MULTI_VALUE_STATISTICS
  8960. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8961. #endif
  8962. RESET_MULTI_VALUE_STATS_VARS();
  8963. #else
  8964. ret = wc_LmsKey_Reload(&key);
  8965. if (ret) {
  8966. printf("wc_LmsKey_Reload failed: %d\n", ret);
  8967. goto exit_lms_sign_verify;
  8968. }
  8969. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  8970. if (ret) {
  8971. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  8972. goto exit_lms_sign_verify;
  8973. }
  8974. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  8975. if (ret) {
  8976. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  8977. goto exit_lms_sign_verify;
  8978. }
  8979. #endif
  8980. loaded = 1;
  8981. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  8982. if (sig == NULL) {
  8983. printf("bench_lms_sign_verify malloc failed\n");
  8984. goto exit_lms_sign_verify;
  8985. }
  8986. count = 0;
  8987. bench_stats_start(&count, &start);
  8988. do {
  8989. /* LMS is stateful. Async queuing not practical. */
  8990. #ifndef WOLFSSL_WC_LMS_SMALL
  8991. for (times = 0; times < ntimes; ++times)
  8992. #else
  8993. for (times = 0; times < 1; ++times)
  8994. #endif
  8995. {
  8996. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  8997. if (ret) {
  8998. printf("wc_LmsKey_Sign failed: %d\n", ret);
  8999. goto exit_lms_sign_verify;
  9000. }
  9001. RECORD_MULTI_VALUE_STATS();
  9002. if (!wc_LmsKey_SigsLeft(&key)) {
  9003. break;
  9004. }
  9005. }
  9006. count += times;
  9007. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9008. #ifdef MULTI_VALUE_STATISTICS
  9009. || runs < minimum_runs
  9010. #endif
  9011. ));
  9012. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9013. count, start, ret);
  9014. #ifdef MULTI_VALUE_STATISTICS
  9015. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9016. #endif
  9017. RESET_MULTI_VALUE_STATS_VARS();
  9018. count = 0;
  9019. bench_stats_start(&count, &start);
  9020. do {
  9021. /* LMS is stateful. Async queuing not practical. */
  9022. for (times = 0; times < ntimes; ++times) {
  9023. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9024. if (ret) {
  9025. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9026. goto exit_lms_sign_verify;
  9027. }
  9028. RECORD_MULTI_VALUE_STATS();
  9029. }
  9030. count += times;
  9031. } while (bench_stats_check(start)
  9032. #ifdef MULTI_VALUE_STATISTICS
  9033. || runs < minimum_runs
  9034. #endif
  9035. );
  9036. exit_lms_sign_verify:
  9037. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9038. count, start, ret);
  9039. #ifdef MULTI_VALUE_STATISTICS
  9040. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9041. #endif
  9042. if (loaded) {
  9043. wc_LmsKey_Free(&key);
  9044. }
  9045. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9046. return;
  9047. }
  9048. void bench_lms(void)
  9049. {
  9050. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9051. #ifdef BENCH_LMS_SLOW_KEYGEN
  9052. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9053. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9054. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9055. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9056. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9057. #undef LMS_PARAMS_BENCHED
  9058. #define LMS_PARAMS_BENCHED
  9059. #endif
  9060. #endif
  9061. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9062. (LMS_MAX_HEIGHT >= 10))
  9063. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9064. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9065. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9066. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9067. #undef LMS_PARAMS_BENCHED
  9068. #define LMS_PARAMS_BENCHED
  9069. #ifdef BENCH_LMS_SLOW_KEYGEN
  9070. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9071. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9072. #endif
  9073. #endif
  9074. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9075. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9076. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9077. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9078. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9079. #undef LMS_PARAMS_BENCHED
  9080. #define LMS_PARAMS_BENCHED
  9081. #endif
  9082. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9083. (LMS_MAX_HEIGHT >= 10))
  9084. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9085. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9086. #endif
  9087. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9088. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9089. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9090. #endif
  9091. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9092. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9093. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9094. #endif
  9095. return;
  9096. }
  9097. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9098. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9099. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9100. void *context)
  9101. {
  9102. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9103. * BE USED FOR TESTING PURPOSES! Production applications should
  9104. * write only to non-volatile storage. */
  9105. XMEMCPY(context, priv, privSz);
  9106. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9107. }
  9108. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9109. void *context)
  9110. {
  9111. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9112. * BE USED FOR TESTING PURPOSES! */
  9113. XMEMCPY(priv, context, privSz);
  9114. return WC_XMSS_RC_READ_TO_MEMORY;
  9115. }
  9116. static void bench_xmss_sign_verify(const char * params)
  9117. {
  9118. WC_RNG rng;
  9119. XmssKey key;
  9120. word32 pkSz = 0;
  9121. word32 skSz = 0;
  9122. int freeRng = 0;
  9123. int freeKey = 0;
  9124. unsigned char * sk = NULL;
  9125. const char * msg = "XMSS post quantum signature test";
  9126. word32 msgSz = (word32) XSTRLEN(msg);
  9127. int ret = 0;
  9128. byte * sig = NULL;
  9129. word32 sigSz = 0;
  9130. int times = 0;
  9131. int count = 0;
  9132. double start = 0.0F;
  9133. #ifndef HAVE_FIPS
  9134. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9135. #else
  9136. ret = wc_InitRng(&rng);
  9137. #endif
  9138. if (ret != 0) {
  9139. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9140. goto exit_xmss_sign_verify;
  9141. }
  9142. freeRng = 1;
  9143. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9144. if (ret != 0) {
  9145. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9146. goto exit_xmss_sign_verify;
  9147. }
  9148. ret = wc_XmssKey_SetParamStr(&key, params);
  9149. if (ret != 0) {
  9150. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9151. goto exit_xmss_sign_verify;
  9152. }
  9153. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9154. if (ret != 0) {
  9155. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9156. goto exit_xmss_sign_verify;
  9157. }
  9158. #ifndef WOLFSSL_WC_XMSS
  9159. if (pkSz != XMSS_SHA256_PUBLEN) {
  9160. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9161. XMSS_SHA256_PUBLEN);
  9162. goto exit_xmss_sign_verify;
  9163. }
  9164. #endif
  9165. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9166. if (ret != 0 || skSz <= 0) {
  9167. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9168. goto exit_xmss_sign_verify;
  9169. }
  9170. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9171. if (ret != 0 || sigSz <= 0) {
  9172. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9173. goto exit_xmss_sign_verify;
  9174. }
  9175. /* Allocate secret keys.*/
  9176. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9177. if (sk == NULL) {
  9178. fprintf(stderr, "error: allocate xmss sk failed\n");
  9179. goto exit_xmss_sign_verify;
  9180. }
  9181. /* Allocate signature array. */
  9182. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9183. if (sig == NULL) {
  9184. fprintf(stderr, "error: allocate xmss sig failed\n");
  9185. goto exit_xmss_sign_verify;
  9186. }
  9187. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9188. if (ret != 0) {
  9189. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9190. goto exit_xmss_sign_verify;
  9191. }
  9192. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9193. if (ret != 0) {
  9194. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9195. goto exit_xmss_sign_verify;
  9196. }
  9197. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9198. if (ret != 0) {
  9199. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9200. goto exit_xmss_sign_verify;
  9201. }
  9202. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9203. fprintf(stderr, "params: %s\n", params);
  9204. fprintf(stderr, "pkSz: %d\n", pkSz);
  9205. fprintf(stderr, "skSz: %d\n", skSz);
  9206. fprintf(stderr, "sigSz: %d\n", sigSz);
  9207. #endif
  9208. /* Making the private key is the bottleneck for larger heights. */
  9209. count = 0;
  9210. bench_stats_start(&count, &start);
  9211. ret = wc_XmssKey_MakeKey(&key, &rng);
  9212. if (ret != 0) {
  9213. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9214. goto exit_xmss_sign_verify;
  9215. }
  9216. /* Can only do one at a time - state changes after make key. */
  9217. count +=1;
  9218. bench_stats_check(start);
  9219. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9220. freeKey = 1;
  9221. count = 0;
  9222. bench_stats_start(&count, &start);
  9223. do {
  9224. /* XMSS is stateful. Async queuing not practical. */
  9225. #ifndef WOLFSSL_WC_XMSS_SMALL
  9226. for (times = 0; times < ntimes; ++times)
  9227. #else
  9228. for (times = 0; times < 1; ++times)
  9229. #endif
  9230. {
  9231. if (!wc_XmssKey_SigsLeft(&key))
  9232. break;
  9233. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9234. if (ret) {
  9235. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9236. goto exit_xmss_sign_verify;
  9237. }
  9238. }
  9239. count += times;
  9240. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9241. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9242. count = 0;
  9243. bench_stats_start(&count, &start);
  9244. do {
  9245. /* XMSS is stateful. Async queuing not practical. */
  9246. for (times = 0; times < ntimes; ++times) {
  9247. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9248. if (ret) {
  9249. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9250. goto exit_xmss_sign_verify;
  9251. }
  9252. }
  9253. count += times;
  9254. } while (bench_stats_check(start));
  9255. exit_xmss_sign_verify:
  9256. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9257. /* Cleanup everything. */
  9258. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9259. sig = NULL;
  9260. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9261. sk = NULL;
  9262. if (freeRng) {
  9263. wc_FreeRng(&rng);
  9264. }
  9265. if (freeKey) {
  9266. wc_XmssKey_Free(&key);
  9267. }
  9268. return;
  9269. }
  9270. void bench_xmss(int hash)
  9271. {
  9272. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9273. * sets.
  9274. *
  9275. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9276. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9277. * very slow, their signatures and private keys quite large,
  9278. * and xmss private keys are not portable across different
  9279. * XMSS/XMSS^MT implementations.
  9280. *
  9281. * The bottleneck in key generation is the height of the first
  9282. * level tree (or h/d).
  9283. *
  9284. * h is the total height of the hyper tree, and d the number of
  9285. * trees.
  9286. */
  9287. /* h/d h d */
  9288. #ifdef WC_XMSS_SHA256
  9289. if (hash == WC_HASH_TYPE_SHA256) {
  9290. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9291. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9292. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9293. #endif
  9294. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9295. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9296. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9297. #endif
  9298. #endif
  9299. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9300. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9301. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9302. #endif
  9303. #endif
  9304. #endif /* HASH_SIZE 256 */
  9305. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9306. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9307. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9308. #endif
  9309. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9310. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9311. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9312. #endif
  9313. #endif
  9314. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9315. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9316. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9317. #endif
  9318. #endif
  9319. #endif /* HASH_SIZE 192 */
  9320. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9321. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9322. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9323. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9324. #endif
  9325. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9326. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9327. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9328. #endif
  9329. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9330. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9331. #endif
  9332. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9333. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9334. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9335. #endif
  9336. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9337. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9338. #endif
  9339. #endif /* HASH_SIZE 256 */
  9340. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9341. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9342. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9343. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9344. #endif
  9345. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9346. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9347. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9348. #endif
  9349. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9350. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9351. #endif
  9352. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9353. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9354. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9355. #endif
  9356. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9357. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9358. #endif
  9359. #endif /* HASH_SIZE 192 */
  9360. }
  9361. #endif
  9362. #ifdef WC_XMSS_SHA512
  9363. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9364. if (hash == WC_HASH_TYPE_SHA512) {
  9365. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9366. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9367. #endif
  9368. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9369. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9370. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9371. #endif
  9372. #endif
  9373. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9374. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9375. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9376. #endif
  9377. #endif
  9378. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9379. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9380. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9381. #endif
  9382. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9383. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9384. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9385. #endif
  9386. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9387. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9388. #endif
  9389. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9390. #endif
  9391. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9392. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9393. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9394. #endif
  9395. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9396. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9397. #endif
  9398. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9399. #endif
  9400. }
  9401. #endif /* HASH_SIZE 512 */
  9402. #endif
  9403. #ifdef WC_XMSS_SHAKE128
  9404. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9405. if (hash == WC_HASH_TYPE_SHAKE128) {
  9406. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9407. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9408. #endif
  9409. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9410. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9411. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9412. #endif
  9413. #endif
  9414. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9415. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9416. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9417. #endif
  9418. #endif
  9419. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9420. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9421. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9422. #endif
  9423. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9424. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9425. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9426. #endif
  9427. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9428. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9429. #endif
  9430. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9431. #endif
  9432. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9433. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9434. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9435. #endif
  9436. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9437. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9438. #endif
  9439. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9440. #endif
  9441. }
  9442. #endif /* HASH_SIZE 256 */
  9443. #endif
  9444. #ifdef WC_XMSS_SHAKE256
  9445. if (hash == WC_HASH_TYPE_SHAKE256) {
  9446. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9447. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9448. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9449. #endif
  9450. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9451. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9452. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9453. #endif
  9454. #endif
  9455. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9456. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9457. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9458. #endif
  9459. #endif
  9460. #endif /* HASH_SIZE 512 */
  9461. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9462. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9463. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9464. #endif
  9465. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9466. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9467. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9468. #endif
  9469. #endif
  9470. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9471. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9472. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9473. #endif
  9474. #endif
  9475. #endif /* HASH_SIZE 256 */
  9476. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9477. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9478. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9479. #endif
  9480. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9481. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9482. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9483. #endif
  9484. #endif
  9485. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9486. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9487. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9488. #endif
  9489. #endif
  9490. #endif /* HASH_SIZE 192 */
  9491. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9492. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9493. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9494. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9495. #endif
  9496. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9497. #endif
  9498. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9499. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9500. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9501. #endif
  9502. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9503. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9504. #endif
  9505. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9506. #endif
  9507. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9508. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9509. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9510. #endif
  9511. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9512. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9513. #endif
  9514. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9515. #endif
  9516. #endif /* HASH_SIZE 512 */
  9517. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9518. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9519. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9520. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9521. #endif
  9522. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9523. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9524. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9525. #endif
  9526. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9527. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9528. #endif
  9529. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9530. #endif
  9531. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9532. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9533. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9534. #endif
  9535. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9536. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9537. #endif
  9538. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9539. #endif
  9540. #endif /* HASH_SIZE 256 */
  9541. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9542. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9543. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9544. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9545. #endif
  9546. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9547. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9548. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9549. #endif
  9550. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9551. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9552. #endif
  9553. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9554. #endif
  9555. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9556. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9557. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9558. #endif
  9559. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9560. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9561. #endif
  9562. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9563. #endif
  9564. #endif /* HASH_SIZE 192 */
  9565. }
  9566. #endif
  9567. return;
  9568. }
  9569. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9570. #ifdef HAVE_ECC
  9571. /* Maximum ECC name plus null terminator:
  9572. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9573. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9574. /* run all benchmarks on a curve */
  9575. void bench_ecc_curve(int curveId)
  9576. {
  9577. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9578. #ifndef NO_SW_BENCH
  9579. bench_eccMakeKey(0, curveId);
  9580. #endif
  9581. #if defined(BENCH_DEVID)
  9582. bench_eccMakeKey(1, curveId);
  9583. #endif
  9584. }
  9585. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9586. #ifndef NO_SW_BENCH
  9587. bench_ecc(0, curveId);
  9588. #endif
  9589. #if defined(BENCH_DEVID)
  9590. bench_ecc(1, curveId);
  9591. #endif
  9592. }
  9593. #ifdef HAVE_ECC_ENCRYPT
  9594. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9595. bench_eccEncrypt(curveId);
  9596. #endif
  9597. }
  9598. void bench_eccMakeKey(int useDeviceID, int curveId)
  9599. {
  9600. int ret = 0, i, times, count = 0, pending = 0;
  9601. int deviceID;
  9602. int keySize = 0;
  9603. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9604. sizeof(ecc_key), HEAP_HINT);
  9605. char name[BENCH_ECC_NAME_SZ];
  9606. double start = 0;
  9607. const char**desc = bench_desc_words[lng_index];
  9608. DECLARE_MULTI_VALUE_STATS_VARS()
  9609. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9610. sizeof(ecc_key), HEAP_HINT);
  9611. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9612. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9613. /* ECC Make Key */
  9614. bench_stats_start(&count, &start);
  9615. do {
  9616. /* while free pending slots in queue, submit ops */
  9617. for (times = 0; times < agreeTimes || pending > 0; ) {
  9618. bench_async_poll(&pending);
  9619. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9620. if (bench_async_check(&ret,
  9621. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9622. &times, agreeTimes, &pending)) {
  9623. wc_ecc_free(genKey[i]);
  9624. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9625. if (ret < 0) {
  9626. goto exit;
  9627. }
  9628. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9629. curveId);
  9630. if (!bench_async_handle(&ret,
  9631. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9632. &pending)) {
  9633. goto exit;
  9634. }
  9635. }
  9636. } /* for i */
  9637. RECORD_MULTI_VALUE_STATS();
  9638. } /* for times */
  9639. count += times;
  9640. } while (bench_stats_check(start)
  9641. #ifdef MULTI_VALUE_STATISTICS
  9642. || runs < minimum_runs
  9643. #endif
  9644. );
  9645. exit:
  9646. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9647. wc_ecc_get_name(curveId));
  9648. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9649. useDeviceID, count, start, ret);
  9650. #ifdef MULTI_VALUE_STATISTICS
  9651. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9652. #endif
  9653. /* cleanup */
  9654. if (WC_ARRAY_OK(genKey)) {
  9655. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9656. wc_ecc_free(genKey[i]);
  9657. }
  9658. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9659. }
  9660. }
  9661. void bench_ecc(int useDeviceID, int curveId)
  9662. {
  9663. int ret = 0, i, times, count, pending = 0;
  9664. int deviceID;
  9665. int keySize;
  9666. char name[BENCH_ECC_NAME_SZ];
  9667. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9668. sizeof(ecc_key), HEAP_HINT);
  9669. #ifdef HAVE_ECC_DHE
  9670. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9671. sizeof(ecc_key), HEAP_HINT);
  9672. #endif
  9673. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9674. #ifdef HAVE_ECC_VERIFY
  9675. int verify[BENCH_MAX_PENDING];
  9676. #endif
  9677. #endif
  9678. word32 x[BENCH_MAX_PENDING];
  9679. double start = 0;
  9680. const char**desc = bench_desc_words[lng_index];
  9681. DECLARE_MULTI_VALUE_STATS_VARS()
  9682. #ifdef HAVE_ECC_DHE
  9683. WC_DECLARE_ARRAY(shared, byte,
  9684. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9685. #endif
  9686. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9687. WC_DECLARE_ARRAY(sig, byte,
  9688. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9689. WC_DECLARE_ARRAY(digest, byte,
  9690. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9691. #endif
  9692. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9693. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9694. XMEMSET(sig, 0, sizeof(sig));
  9695. XMEMSET(digest, 0, sizeof(digest));
  9696. #endif
  9697. #ifdef HAVE_ECC_DHE
  9698. XMEMSET(shared, 0, sizeof(shared));
  9699. #endif
  9700. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9701. sizeof(ecc_key), HEAP_HINT);
  9702. #ifdef HAVE_ECC_DHE
  9703. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9704. sizeof(ecc_key), HEAP_HINT);
  9705. WC_ALLOC_ARRAY(shared, byte,
  9706. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9707. #endif
  9708. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9709. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9710. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9711. #endif
  9712. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9713. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9714. /* init keys */
  9715. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9716. /* setup an context for each key */
  9717. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9718. goto exit;
  9719. }
  9720. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9721. #ifdef WOLFSSL_ASYNC_CRYPT
  9722. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9723. #endif
  9724. if (ret < 0) {
  9725. goto exit;
  9726. }
  9727. #ifdef HAVE_ECC_DHE
  9728. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9729. goto exit;
  9730. }
  9731. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9732. curveId)) > 0) {
  9733. goto exit;
  9734. }
  9735. #endif
  9736. }
  9737. #ifdef HAVE_ECC_DHE
  9738. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9739. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9740. !defined(HAVE_SELFTEST)
  9741. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9742. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9743. }
  9744. #endif
  9745. /* ECC Shared Secret */
  9746. bench_stats_start(&count, &start);
  9747. PRIVATE_KEY_UNLOCK();
  9748. do {
  9749. for (times = 0; times < agreeTimes || pending > 0; ) {
  9750. bench_async_poll(&pending);
  9751. /* while free pending slots in queue, submit ops */
  9752. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9753. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9754. &times, agreeTimes, &pending)) {
  9755. x[i] = (word32)keySize;
  9756. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9757. shared[i], &x[i]);
  9758. if (!bench_async_handle(&ret,
  9759. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9760. &pending)) {
  9761. goto exit_ecdhe;
  9762. }
  9763. }
  9764. } /* for i */
  9765. RECORD_MULTI_VALUE_STATS();
  9766. } /* for times */
  9767. count += times;
  9768. } while (bench_stats_check(start)
  9769. #ifdef MULTI_VALUE_STATISTICS
  9770. || runs < minimum_runs
  9771. #endif
  9772. );
  9773. PRIVATE_KEY_UNLOCK();
  9774. exit_ecdhe:
  9775. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9776. wc_ecc_get_name(curveId));
  9777. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9778. useDeviceID, count, start, ret);
  9779. #ifdef MULTI_VALUE_STATISTICS
  9780. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9781. #endif
  9782. RESET_MULTI_VALUE_STATS_VARS();
  9783. if (ret < 0) {
  9784. goto exit;
  9785. }
  9786. #endif /* HAVE_ECC_DHE */
  9787. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9788. /* Init digest to sign */
  9789. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9790. for (count = 0; count < keySize; count++) {
  9791. digest[i][count] = (byte)count;
  9792. }
  9793. }
  9794. /* ECC Sign */
  9795. bench_stats_start(&count, &start);
  9796. do {
  9797. for (times = 0; times < agreeTimes || pending > 0; ) {
  9798. bench_async_poll(&pending);
  9799. /* while free pending slots in queue, submit ops */
  9800. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9801. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9802. &times, agreeTimes, &pending)) {
  9803. if (genKey[i]->state == 0) {
  9804. x[i] = ECC_MAX_SIG_SIZE;
  9805. }
  9806. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9807. &x[i], GLOBAL_RNG, genKey[i]);
  9808. if (!bench_async_handle(&ret,
  9809. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9810. &pending)) {
  9811. goto exit_ecdsa_sign;
  9812. }
  9813. } /* bench_async_check */
  9814. } /* for i */
  9815. RECORD_MULTI_VALUE_STATS();
  9816. } /* for times */
  9817. count += times;
  9818. } while (bench_stats_check(start)
  9819. #ifdef MULTI_VALUE_STATISTICS
  9820. || runs < minimum_runs
  9821. #endif
  9822. );
  9823. exit_ecdsa_sign:
  9824. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9825. wc_ecc_get_name(curveId));
  9826. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9827. useDeviceID, count, start, ret);
  9828. #ifdef MULTI_VALUE_STATISTICS
  9829. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9830. #endif
  9831. RESET_MULTI_VALUE_STATS_VARS();
  9832. if (ret < 0) {
  9833. goto exit;
  9834. }
  9835. #ifdef HAVE_ECC_VERIFY
  9836. /* ECC Verify */
  9837. bench_stats_start(&count, &start);
  9838. do {
  9839. for (times = 0; times < agreeTimes || pending > 0; ) {
  9840. bench_async_poll(&pending);
  9841. /* while free pending slots in queue, submit ops */
  9842. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9843. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9844. &times, agreeTimes, &pending)) {
  9845. if (genKey[i]->state == 0) {
  9846. verify[i] = 0;
  9847. }
  9848. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9849. (word32)keySize, &verify[i],
  9850. genKey[i]);
  9851. if (!bench_async_handle(&ret,
  9852. BENCH_ASYNC_GET_DEV(genKey[i]),
  9853. 1, &times,
  9854. &pending)) {
  9855. goto exit_ecdsa_verify;
  9856. }
  9857. } /* if bench_async_check */
  9858. } /* for i */
  9859. RECORD_MULTI_VALUE_STATS();
  9860. } /* for times */
  9861. count += times;
  9862. } while (bench_stats_check(start)
  9863. #ifdef MULTI_VALUE_STATISTICS
  9864. || runs < minimum_runs
  9865. #endif
  9866. );
  9867. exit_ecdsa_verify:
  9868. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9869. wc_ecc_get_name(curveId));
  9870. bench_stats_asym_finish(name, keySize * 8, desc[5],
  9871. useDeviceID, count, start, ret);
  9872. #ifdef MULTI_VALUE_STATISTICS
  9873. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9874. #endif
  9875. #endif /* HAVE_ECC_VERIFY */
  9876. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  9877. exit:
  9878. /* cleanup */
  9879. if (WC_ARRAY_OK(genKey)) {
  9880. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9881. wc_ecc_free(genKey[i]);
  9882. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9883. }
  9884. #ifdef HAVE_ECC_DHE
  9885. if (WC_ARRAY_OK(genKey2)) {
  9886. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9887. wc_ecc_free(genKey2[i]);
  9888. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  9889. }
  9890. #endif
  9891. #ifdef HAVE_ECC_DHE
  9892. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  9893. #endif
  9894. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9895. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  9896. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  9897. #endif
  9898. (void)useDeviceID;
  9899. (void)pending;
  9900. (void)x;
  9901. (void)count;
  9902. (void)times;
  9903. (void)desc;
  9904. (void)start;
  9905. (void)name;
  9906. }
  9907. #ifdef HAVE_ECC_ENCRYPT
  9908. void bench_eccEncrypt(int curveId)
  9909. {
  9910. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  9911. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  9912. WC_SHA256_DIGEST_SIZE + \
  9913. (MAX_ECC_BITS+3)/4 + 2)
  9914. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  9915. #ifdef WOLFSSL_SMALL_STACK
  9916. ecc_key *userA = NULL, *userB = NULL;
  9917. byte *msg = NULL;
  9918. byte *out = NULL;
  9919. #else
  9920. ecc_key userA[1], userB[1];
  9921. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  9922. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  9923. #endif
  9924. char name[BENCH_ECC_NAME_SZ];
  9925. int keySize;
  9926. word32 bench_plainSz = bench_size;
  9927. int ret, i, count;
  9928. double start;
  9929. const char**desc = bench_desc_words[lng_index];
  9930. DECLARE_MULTI_VALUE_STATS_VARS()
  9931. #ifdef WOLFSSL_SMALL_STACK
  9932. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  9933. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9934. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  9935. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9936. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  9937. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9938. out = (byte *)XMALLOC(outSz,
  9939. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9940. if ((! userA) || (! userB) || (! msg) || (! out)) {
  9941. printf("bench_eccEncrypt malloc failed\n");
  9942. goto exit;
  9943. }
  9944. #endif
  9945. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9946. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  9947. if (ret != 0) {
  9948. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  9949. goto exit;
  9950. }
  9951. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  9952. if (ret != 0) {
  9953. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  9954. goto exit;
  9955. }
  9956. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9957. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9958. !defined(HAVE_SELFTEST)
  9959. ret = wc_ecc_set_rng(userA, &gRng);
  9960. if (ret != 0) {
  9961. goto exit;
  9962. }
  9963. ret = wc_ecc_set_rng(userB, &gRng);
  9964. if (ret != 0) {
  9965. goto exit;
  9966. }
  9967. #endif
  9968. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  9969. #ifdef WOLFSSL_ASYNC_CRYPT
  9970. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  9971. #endif
  9972. if (ret != 0)
  9973. goto exit;
  9974. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  9975. #ifdef WOLFSSL_ASYNC_CRYPT
  9976. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  9977. #endif
  9978. if (ret != 0)
  9979. goto exit;
  9980. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  9981. msg[i] = (byte)i;
  9982. }
  9983. bench_stats_start(&count, &start);
  9984. do {
  9985. for (i = 0; i < ntimes; i++) {
  9986. /* encrypt msg to B */
  9987. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  9988. out, &outSz, NULL);
  9989. if (ret != 0) {
  9990. printf("wc_ecc_encrypt failed! %d\n", ret);
  9991. goto exit_enc;
  9992. }
  9993. RECORD_MULTI_VALUE_STATS();
  9994. }
  9995. count += i;
  9996. } while (bench_stats_check(start)
  9997. #ifdef MULTI_VALUE_STATISTICS
  9998. || runs < minimum_runs
  9999. #endif
  10000. );
  10001. exit_enc:
  10002. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10003. wc_ecc_get_name(curveId));
  10004. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10005. #ifdef MULTI_VALUE_STATISTICS
  10006. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10007. #endif
  10008. RESET_MULTI_VALUE_STATS_VARS();
  10009. if (ret != 0)
  10010. goto exit;
  10011. bench_stats_start(&count, &start);
  10012. do {
  10013. for (i = 0; i < ntimes; i++) {
  10014. /* decrypt msg from A */
  10015. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10016. &bench_plainSz, NULL);
  10017. if (ret != 0) {
  10018. printf("wc_ecc_decrypt failed! %d\n", ret);
  10019. goto exit_dec;
  10020. }
  10021. RECORD_MULTI_VALUE_STATS();
  10022. }
  10023. count += i;
  10024. } while (bench_stats_check(start)
  10025. #ifdef MULTI_VALUE_STATISTICS
  10026. || runs < minimum_runs
  10027. #endif
  10028. );
  10029. exit_dec:
  10030. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10031. #ifdef MULTI_VALUE_STATISTICS
  10032. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10033. #endif
  10034. exit:
  10035. /* cleanup */
  10036. #ifdef WOLFSSL_SMALL_STACK
  10037. if (userA) {
  10038. wc_ecc_free(userA);
  10039. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10040. }
  10041. if (userB) {
  10042. wc_ecc_free(userB);
  10043. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10044. }
  10045. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10046. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10047. #else
  10048. wc_ecc_free(userB);
  10049. wc_ecc_free(userA);
  10050. #endif
  10051. }
  10052. #endif
  10053. #ifdef WOLFSSL_SM2
  10054. static void bench_sm2_MakeKey(int useDeviceID)
  10055. {
  10056. int ret = 0, i, times, count = 0, pending = 0;
  10057. int deviceID;
  10058. int keySize;
  10059. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10060. sizeof(ecc_key), HEAP_HINT);
  10061. char name[BENCH_ECC_NAME_SZ];
  10062. double start = 0;
  10063. const char**desc = bench_desc_words[lng_index];
  10064. DECLARE_MULTI_VALUE_STATS_VARS()
  10065. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10066. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10067. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10068. sizeof(ecc_key), HEAP_HINT);
  10069. /* ECC Make Key */
  10070. bench_stats_start(&count, &start);
  10071. do {
  10072. /* while free pending slots in queue, submit ops */
  10073. for (times = 0; times < agreeTimes || pending > 0; ) {
  10074. bench_async_poll(&pending);
  10075. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10076. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10077. &times, agreeTimes, &pending)) {
  10078. wc_ecc_free(genKey[i]);
  10079. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10080. if (ret < 0) {
  10081. goto exit;
  10082. }
  10083. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10084. WC_ECC_FLAG_NONE);
  10085. if (!bench_async_handle(&ret,
  10086. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10087. &pending)) {
  10088. goto exit;
  10089. }
  10090. }
  10091. } /* for i */
  10092. RECORD_MULTI_VALUE_STATS();
  10093. } /* for times */
  10094. count += times;
  10095. } while (bench_stats_check(start)
  10096. #ifdef MULTI_VALUE_STATISTICS
  10097. || runs < minimum_runs
  10098. #endif
  10099. );
  10100. exit:
  10101. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10102. wc_ecc_get_name(ECC_SM2P256V1));
  10103. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10104. start, ret);
  10105. #ifdef MULTI_VALUE_STATISTICS
  10106. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10107. #endif
  10108. /* cleanup */
  10109. if (WC_ARRAY_OK(genKey)) {
  10110. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10111. wc_ecc_free(genKey[i]);
  10112. }
  10113. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10114. }
  10115. }
  10116. void bench_sm2(int useDeviceID)
  10117. {
  10118. int ret = 0, i, times, count, pending = 0;
  10119. int deviceID;
  10120. int keySize;
  10121. char name[BENCH_ECC_NAME_SZ];
  10122. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10123. sizeof(ecc_key), HEAP_HINT);
  10124. #ifdef HAVE_ECC_DHE
  10125. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10126. sizeof(ecc_key), HEAP_HINT);
  10127. #endif
  10128. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10129. #ifdef HAVE_ECC_VERIFY
  10130. int verify[BENCH_MAX_PENDING];
  10131. #endif
  10132. #endif
  10133. word32 x[BENCH_MAX_PENDING];
  10134. double start = 0;
  10135. const char**desc = bench_desc_words[lng_index];
  10136. DECLARE_MULTI_VALUE_STATS_VARS()
  10137. #ifdef HAVE_ECC_DHE
  10138. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10139. #endif
  10140. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10141. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10142. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10143. #endif
  10144. #ifdef HAVE_ECC_DHE
  10145. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10146. #endif
  10147. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10148. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10149. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10150. #endif
  10151. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10152. bench_sm2_MakeKey(useDeviceID);
  10153. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10154. sizeof(ecc_key), HEAP_HINT);
  10155. #ifdef HAVE_ECC_DHE
  10156. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10157. sizeof(ecc_key), HEAP_HINT);
  10158. #endif
  10159. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10160. /* init keys */
  10161. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10162. /* setup an context for each key */
  10163. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10164. goto exit;
  10165. }
  10166. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10167. #ifdef WOLFSSL_ASYNC_CRYPT
  10168. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10169. #endif
  10170. if (ret < 0) {
  10171. goto exit;
  10172. }
  10173. #ifdef HAVE_ECC_DHE
  10174. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10175. goto exit;
  10176. }
  10177. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10178. WC_ECC_FLAG_NONE)) > 0) {
  10179. goto exit;
  10180. }
  10181. #endif
  10182. }
  10183. #ifdef HAVE_ECC_DHE
  10184. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10185. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10186. !defined(HAVE_SELFTEST)
  10187. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10188. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10189. }
  10190. #endif
  10191. /* ECC Shared Secret */
  10192. bench_stats_start(&count, &start);
  10193. PRIVATE_KEY_UNLOCK();
  10194. do {
  10195. for (times = 0; times < agreeTimes || pending > 0; ) {
  10196. bench_async_poll(&pending);
  10197. /* while free pending slots in queue, submit ops */
  10198. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10199. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10200. &times, agreeTimes, &pending)) {
  10201. x[i] = (word32)keySize;
  10202. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10203. shared[i], &x[i]);
  10204. if (!bench_async_handle(&ret,
  10205. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10206. &pending)) {
  10207. goto exit_ecdhe;
  10208. }
  10209. }
  10210. } /* for i */
  10211. RECORD_MULTI_VALUE_STATS();
  10212. } /* for times */
  10213. count += times;
  10214. } while (bench_stats_check(start)
  10215. #ifdef MULTI_VALUE_STATISTICS
  10216. || runs < minimum_runs
  10217. #endif
  10218. );
  10219. PRIVATE_KEY_UNLOCK();
  10220. exit_ecdhe:
  10221. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10222. wc_ecc_get_name(ECC_SM2P256V1));
  10223. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10224. start, ret);
  10225. #ifdef MULTI_VALUE_STATISTICS
  10226. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10227. #endif
  10228. if (ret < 0) {
  10229. goto exit;
  10230. }
  10231. #endif /* HAVE_ECC_DHE */
  10232. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10233. /* Init digest to sign */
  10234. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10235. for (count = 0; count < keySize; count++) {
  10236. digest[i][count] = (byte)count;
  10237. }
  10238. }
  10239. RESET_MULTI_VALUE_STATS_VARS();
  10240. /* ECC Sign */
  10241. bench_stats_start(&count, &start);
  10242. do {
  10243. for (times = 0; times < agreeTimes || pending > 0; ) {
  10244. bench_async_poll(&pending);
  10245. /* while free pending slots in queue, submit ops */
  10246. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10247. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10248. &times, agreeTimes, &pending)) {
  10249. if (genKey[i]->state == 0)
  10250. x[i] = ECC_MAX_SIG_SIZE;
  10251. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10252. sig[i], &x[i], &gRng, genKey[i]);
  10253. if (!bench_async_handle(&ret,
  10254. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10255. &pending)) {
  10256. goto exit_ecdsa_sign;
  10257. }
  10258. }
  10259. } /* for i */
  10260. RECORD_MULTI_VALUE_STATS();
  10261. } /* for times */
  10262. count += times;
  10263. } while (bench_stats_check(start)
  10264. #ifdef MULTI_VALUE_STATISTICS
  10265. || runs < minimum_runs
  10266. #endif
  10267. );
  10268. exit_ecdsa_sign:
  10269. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10270. wc_ecc_get_name(ECC_SM2P256V1));
  10271. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10272. start, ret);
  10273. #ifdef MULTI_VALUE_STATISTICS
  10274. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10275. #endif
  10276. if (ret < 0) {
  10277. goto exit;
  10278. }
  10279. #ifdef HAVE_ECC_VERIFY
  10280. /* ECC Verify */
  10281. bench_stats_start(&count, &start);
  10282. do {
  10283. for (times = 0; times < agreeTimes || pending > 0; ) {
  10284. bench_async_poll(&pending);
  10285. /* while free pending slots in queue, submit ops */
  10286. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10287. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10288. &times, agreeTimes, &pending)) {
  10289. if (genKey[i]->state == 0)
  10290. verify[i] = 0;
  10291. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10292. (word32)keySize, &verify[i], genKey[i]);
  10293. if (!bench_async_handle(&ret,
  10294. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10295. &pending)) {
  10296. goto exit_ecdsa_verify;
  10297. }
  10298. }
  10299. } /* for i */
  10300. RECORD_MULTI_VALUE_STATS();
  10301. } /* for times */
  10302. count += times;
  10303. } while (bench_stats_check(start)
  10304. #ifdef MULTI_VALUE_STATISTICS
  10305. || runs < minimum_runs
  10306. #endif
  10307. );
  10308. exit_ecdsa_verify:
  10309. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10310. wc_ecc_get_name(ECC_SM2P256V1));
  10311. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10312. start, ret);
  10313. #ifdef MULTI_VALUE_STATISTICS
  10314. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10315. #endif
  10316. #endif /* HAVE_ECC_VERIFY */
  10317. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10318. exit:
  10319. /* cleanup */
  10320. if (WC_ARRAY_OK(genKey)) {
  10321. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10322. wc_ecc_free(genKey[i]);
  10323. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10324. }
  10325. #ifdef HAVE_ECC_DHE
  10326. if (WC_ARRAY_OK(genKey2)) {
  10327. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10328. wc_ecc_free(genKey2[i]);
  10329. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10330. }
  10331. #endif
  10332. #ifdef HAVE_ECC_DHE
  10333. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10334. #endif
  10335. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10336. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10337. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10338. #endif
  10339. (void)useDeviceID;
  10340. (void)pending;
  10341. (void)x;
  10342. (void)count;
  10343. (void)times;
  10344. (void)desc;
  10345. (void)start;
  10346. (void)name;
  10347. }
  10348. #endif /* WOLFSSL_SM2 */
  10349. #endif /* HAVE_ECC */
  10350. #ifdef HAVE_CURVE25519
  10351. void bench_curve25519KeyGen(int useDeviceID)
  10352. {
  10353. curve25519_key genKey;
  10354. double start;
  10355. int ret = 0, i, count;
  10356. const char**desc = bench_desc_words[lng_index];
  10357. DECLARE_MULTI_VALUE_STATS_VARS()
  10358. /* Key Gen */
  10359. bench_stats_start(&count, &start);
  10360. do {
  10361. for (i = 0; i < genTimes; i++) {
  10362. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10363. useDeviceID ? devId : INVALID_DEVID);
  10364. if (ret != 0) {
  10365. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10366. break;
  10367. }
  10368. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10369. wc_curve25519_free(&genKey);
  10370. if (ret != 0) {
  10371. printf("wc_curve25519_make_key failed: %d\n", ret);
  10372. break;
  10373. }
  10374. RECORD_MULTI_VALUE_STATS();
  10375. }
  10376. count += i;
  10377. } while (bench_stats_check(start)
  10378. #ifdef MULTI_VALUE_STATISTICS
  10379. || runs < minimum_runs
  10380. #endif
  10381. );
  10382. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10383. ret);
  10384. #ifdef MULTI_VALUE_STATISTICS
  10385. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10386. #endif
  10387. }
  10388. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10389. void bench_curve25519KeyAgree(int useDeviceID)
  10390. {
  10391. curve25519_key genKey, genKey2;
  10392. double start;
  10393. int ret, i, count;
  10394. byte shared[32];
  10395. const char**desc = bench_desc_words[lng_index];
  10396. word32 x = 0;
  10397. DECLARE_MULTI_VALUE_STATS_VARS()
  10398. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10399. useDeviceID ? devId : INVALID_DEVID);
  10400. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10401. useDeviceID ? devId : INVALID_DEVID);
  10402. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10403. if (ret != 0) {
  10404. printf("curve25519_make_key failed\n");
  10405. return;
  10406. }
  10407. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10408. if (ret != 0) {
  10409. printf("curve25519_make_key failed: %d\n", ret);
  10410. wc_curve25519_free(&genKey);
  10411. return;
  10412. }
  10413. /* Shared secret */
  10414. bench_stats_start(&count, &start);
  10415. do {
  10416. for (i = 0; i < agreeTimes; i++) {
  10417. x = sizeof(shared);
  10418. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10419. if (ret != 0) {
  10420. printf("curve25519_shared_secret failed: %d\n", ret);
  10421. goto exit;
  10422. }
  10423. RECORD_MULTI_VALUE_STATS();
  10424. }
  10425. count += i;
  10426. } while (bench_stats_check(start)
  10427. #ifdef MULTI_VALUE_STATISTICS
  10428. || runs < minimum_runs
  10429. #endif
  10430. );
  10431. exit:
  10432. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10433. ret);
  10434. #ifdef MULTI_VALUE_STATISTICS
  10435. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10436. #endif
  10437. wc_curve25519_free(&genKey2);
  10438. wc_curve25519_free(&genKey);
  10439. }
  10440. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10441. #endif /* HAVE_CURVE25519 */
  10442. #ifdef HAVE_ED25519
  10443. void bench_ed25519KeyGen(void)
  10444. {
  10445. #ifdef HAVE_ED25519_MAKE_KEY
  10446. ed25519_key genKey;
  10447. double start;
  10448. int i, count;
  10449. const char**desc = bench_desc_words[lng_index];
  10450. DECLARE_MULTI_VALUE_STATS_VARS()
  10451. /* Key Gen */
  10452. bench_stats_start(&count, &start);
  10453. do {
  10454. for (i = 0; i < genTimes; i++) {
  10455. wc_ed25519_init(&genKey);
  10456. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10457. wc_ed25519_free(&genKey);
  10458. RECORD_MULTI_VALUE_STATS();
  10459. }
  10460. count += i;
  10461. } while (bench_stats_check(start)
  10462. #ifdef MULTI_VALUE_STATISTICS
  10463. || runs < minimum_runs
  10464. #endif
  10465. );
  10466. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10467. #ifdef MULTI_VALUE_STATISTICS
  10468. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10469. #endif
  10470. #endif /* HAVE_ED25519_MAKE_KEY */
  10471. }
  10472. void bench_ed25519KeySign(void)
  10473. {
  10474. #ifdef HAVE_ED25519_MAKE_KEY
  10475. int ret;
  10476. #endif
  10477. ed25519_key genKey;
  10478. #ifdef HAVE_ED25519_SIGN
  10479. double start;
  10480. int i, count;
  10481. byte sig[ED25519_SIG_SIZE];
  10482. byte msg[512];
  10483. word32 x = 0;
  10484. const char**desc = bench_desc_words[lng_index];
  10485. DECLARE_MULTI_VALUE_STATS_VARS()
  10486. #endif
  10487. wc_ed25519_init(&genKey);
  10488. #ifdef HAVE_ED25519_MAKE_KEY
  10489. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10490. if (ret != 0) {
  10491. printf("ed25519_make_key failed\n");
  10492. return;
  10493. }
  10494. #endif
  10495. #ifdef HAVE_ED25519_SIGN
  10496. /* make dummy msg */
  10497. for (i = 0; i < (int)sizeof(msg); i++)
  10498. msg[i] = (byte)i;
  10499. bench_stats_start(&count, &start);
  10500. do {
  10501. for (i = 0; i < agreeTimes; i++) {
  10502. x = sizeof(sig);
  10503. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10504. if (ret != 0) {
  10505. printf("ed25519_sign_msg failed\n");
  10506. goto exit_ed_sign;
  10507. }
  10508. RECORD_MULTI_VALUE_STATS();
  10509. }
  10510. count += i;
  10511. } while (bench_stats_check(start)
  10512. #ifdef MULTI_VALUE_STATISTICS
  10513. || runs < minimum_runs
  10514. #endif
  10515. );
  10516. exit_ed_sign:
  10517. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10518. #ifdef MULTI_VALUE_STATISTICS
  10519. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10520. #endif
  10521. RESET_MULTI_VALUE_STATS_VARS();
  10522. #ifdef HAVE_ED25519_VERIFY
  10523. bench_stats_start(&count, &start);
  10524. do {
  10525. for (i = 0; i < agreeTimes; i++) {
  10526. int verify = 0;
  10527. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10528. &genKey);
  10529. if (ret != 0 || verify != 1) {
  10530. printf("ed25519_verify_msg failed\n");
  10531. goto exit_ed_verify;
  10532. }
  10533. RECORD_MULTI_VALUE_STATS();
  10534. }
  10535. count += i;
  10536. } while (bench_stats_check(start)
  10537. #ifdef MULTI_VALUE_STATISTICS
  10538. || runs < minimum_runs
  10539. #endif
  10540. );
  10541. exit_ed_verify:
  10542. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10543. #ifdef MULTI_VALUE_STATISTICS
  10544. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10545. #endif
  10546. #endif /* HAVE_ED25519_VERIFY */
  10547. #endif /* HAVE_ED25519_SIGN */
  10548. wc_ed25519_free(&genKey);
  10549. }
  10550. #endif /* HAVE_ED25519 */
  10551. #ifdef HAVE_CURVE448
  10552. void bench_curve448KeyGen(void)
  10553. {
  10554. curve448_key genKey;
  10555. double start;
  10556. int ret = 0, i, count;
  10557. const char**desc = bench_desc_words[lng_index];
  10558. DECLARE_MULTI_VALUE_STATS_VARS()
  10559. /* Key Gen */
  10560. bench_stats_start(&count, &start);
  10561. do {
  10562. for (i = 0; i < genTimes; i++) {
  10563. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10564. wc_curve448_free(&genKey);
  10565. if (ret != 0) {
  10566. printf("wc_curve448_make_key failed: %d\n", ret);
  10567. break;
  10568. }
  10569. RECORD_MULTI_VALUE_STATS();
  10570. }
  10571. count += i;
  10572. } while (bench_stats_check(start)
  10573. #ifdef MULTI_VALUE_STATISTICS
  10574. || runs < minimum_runs
  10575. #endif
  10576. );
  10577. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10578. #ifdef MULTI_VALUE_STATISTICS
  10579. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10580. #endif
  10581. }
  10582. #ifdef HAVE_CURVE448_SHARED_SECRET
  10583. void bench_curve448KeyAgree(void)
  10584. {
  10585. curve448_key genKey, genKey2;
  10586. double start;
  10587. int ret, i, count;
  10588. byte shared[56];
  10589. const char**desc = bench_desc_words[lng_index];
  10590. word32 x = 0;
  10591. DECLARE_MULTI_VALUE_STATS_VARS()
  10592. wc_curve448_init(&genKey);
  10593. wc_curve448_init(&genKey2);
  10594. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10595. if (ret != 0) {
  10596. printf("curve448_make_key failed\n");
  10597. return;
  10598. }
  10599. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10600. if (ret != 0) {
  10601. printf("curve448_make_key failed: %d\n", ret);
  10602. wc_curve448_free(&genKey);
  10603. return;
  10604. }
  10605. /* Shared secret */
  10606. bench_stats_start(&count, &start);
  10607. do {
  10608. for (i = 0; i < agreeTimes; i++) {
  10609. x = sizeof(shared);
  10610. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10611. if (ret != 0) {
  10612. printf("curve448_shared_secret failed: %d\n", ret);
  10613. goto exit;
  10614. }
  10615. RECORD_MULTI_VALUE_STATS();
  10616. }
  10617. count += i;
  10618. } while (bench_stats_check(start)
  10619. #ifdef MULTI_VALUE_STATISTICS
  10620. || runs < minimum_runs
  10621. #endif
  10622. );
  10623. exit:
  10624. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10625. #ifdef MULTI_VALUE_STATISTICS
  10626. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10627. #endif
  10628. wc_curve448_free(&genKey2);
  10629. wc_curve448_free(&genKey);
  10630. }
  10631. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10632. #endif /* HAVE_CURVE448 */
  10633. #ifdef HAVE_ED448
  10634. void bench_ed448KeyGen(void)
  10635. {
  10636. ed448_key genKey;
  10637. double start;
  10638. int i, count;
  10639. const char**desc = bench_desc_words[lng_index];
  10640. DECLARE_MULTI_VALUE_STATS_VARS()
  10641. /* Key Gen */
  10642. bench_stats_start(&count, &start);
  10643. do {
  10644. for (i = 0; i < genTimes; i++) {
  10645. wc_ed448_init(&genKey);
  10646. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10647. wc_ed448_free(&genKey);
  10648. RECORD_MULTI_VALUE_STATS();
  10649. }
  10650. count += i;
  10651. } while (bench_stats_check(start)
  10652. #ifdef MULTI_VALUE_STATISTICS
  10653. || runs < minimum_runs
  10654. #endif
  10655. );
  10656. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10657. #ifdef MULTI_VALUE_STATISTICS
  10658. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10659. #endif
  10660. }
  10661. void bench_ed448KeySign(void)
  10662. {
  10663. int ret;
  10664. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10665. #ifdef HAVE_ED448_SIGN
  10666. double start;
  10667. int i, count;
  10668. byte sig[ED448_SIG_SIZE];
  10669. byte msg[512];
  10670. word32 x = 0;
  10671. const char**desc = bench_desc_words[lng_index];
  10672. DECLARE_MULTI_VALUE_STATS_VARS()
  10673. #endif
  10674. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10675. wc_ed448_init(genKey);
  10676. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10677. if (ret != 0) {
  10678. printf("ed448_make_key failed\n");
  10679. goto exit;
  10680. }
  10681. #ifdef HAVE_ED448_SIGN
  10682. /* make dummy msg */
  10683. for (i = 0; i < (int)sizeof(msg); i++)
  10684. msg[i] = (byte)i;
  10685. bench_stats_start(&count, &start);
  10686. do {
  10687. for (i = 0; i < agreeTimes; i++) {
  10688. x = sizeof(sig);
  10689. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10690. NULL, 0);
  10691. if (ret != 0) {
  10692. printf("ed448_sign_msg failed\n");
  10693. goto exit;
  10694. }
  10695. RECORD_MULTI_VALUE_STATS();
  10696. }
  10697. count += i;
  10698. } while (bench_stats_check(start)
  10699. #ifdef MULTI_VALUE_STATISTICS
  10700. || runs < minimum_runs
  10701. #endif
  10702. );
  10703. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10704. #ifdef MULTI_VALUE_STATISTICS
  10705. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10706. #endif
  10707. RESET_MULTI_VALUE_STATS_VARS();
  10708. #ifdef HAVE_ED448_VERIFY
  10709. bench_stats_start(&count, &start);
  10710. do {
  10711. for (i = 0; i < agreeTimes; i++) {
  10712. int verify = 0;
  10713. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10714. genKey, NULL, 0);
  10715. if (ret != 0 || verify != 1) {
  10716. printf("ed448_verify_msg failed\n");
  10717. goto exit;
  10718. }
  10719. RECORD_MULTI_VALUE_STATS();
  10720. }
  10721. count += i;
  10722. } while (bench_stats_check(start)
  10723. #ifdef MULTI_VALUE_STATISTICS
  10724. || runs < minimum_runs
  10725. #endif
  10726. );
  10727. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10728. #ifdef MULTI_VALUE_STATISTICS
  10729. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10730. #endif
  10731. #endif /* HAVE_ED448_VERIFY */
  10732. #endif /* HAVE_ED448_SIGN */
  10733. exit:
  10734. wc_ed448_free(genKey);
  10735. WC_FREE_VAR(genKey, HEAP_HINT);
  10736. }
  10737. #endif /* HAVE_ED448 */
  10738. #ifdef WOLFCRYPT_HAVE_ECCSI
  10739. #ifdef WOLFCRYPT_ECCSI_KMS
  10740. void bench_eccsiKeyGen(void)
  10741. {
  10742. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10743. double start;
  10744. int i, count;
  10745. const char**desc = bench_desc_words[lng_index];
  10746. int ret;
  10747. DECLARE_MULTI_VALUE_STATS_VARS()
  10748. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10749. /* Key Gen */
  10750. bench_stats_start(&count, &start);
  10751. do {
  10752. for (i = 0; i < genTimes; i++) {
  10753. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10754. ret = wc_MakeEccsiKey(genKey, &gRng);
  10755. wc_FreeEccsiKey(genKey);
  10756. if (ret != 0) {
  10757. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10758. goto exit;
  10759. }
  10760. RECORD_MULTI_VALUE_STATS();
  10761. }
  10762. count += i;
  10763. } while (bench_stats_check(start)
  10764. #ifdef MULTI_VALUE_STATISTICS
  10765. || runs < minimum_runs
  10766. #endif
  10767. );
  10768. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10769. #ifdef MULTI_VALUE_STATISTICS
  10770. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10771. #endif
  10772. exit:
  10773. WC_FREE_VAR(genKey, HEAP_HINT);
  10774. }
  10775. void bench_eccsiPairGen(void)
  10776. {
  10777. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10778. double start;
  10779. int i, count;
  10780. const char**desc = bench_desc_words[lng_index];
  10781. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10782. ecc_point* pvt;
  10783. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10784. int ret;
  10785. DECLARE_MULTI_VALUE_STATS_VARS()
  10786. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10787. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10788. (void)mp_init(ssk);
  10789. pvt = wc_ecc_new_point();
  10790. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10791. (void)wc_MakeEccsiKey(genKey, &gRng);
  10792. /* RSK Gen */
  10793. bench_stats_start(&count, &start);
  10794. do {
  10795. for (i = 0; i < genTimes; i++) {
  10796. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10797. sizeof(id), ssk, pvt);
  10798. if (ret != 0) {
  10799. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10800. goto exit;
  10801. }
  10802. RECORD_MULTI_VALUE_STATS();
  10803. }
  10804. count += i;
  10805. } while (bench_stats_check(start)
  10806. #ifdef MULTI_VALUE_STATISTICS
  10807. || runs < minimum_runs
  10808. #endif
  10809. );
  10810. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10811. #ifdef MULTI_VALUE_STATISTICS
  10812. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10813. #endif
  10814. wc_FreeEccsiKey(genKey);
  10815. wc_ecc_del_point(pvt);
  10816. mp_free(ssk);
  10817. exit:
  10818. WC_FREE_VAR(genKey, HEAP_HINT);
  10819. WC_FREE_VAR(ssk, HEAP_HINT);
  10820. }
  10821. #endif
  10822. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10823. void bench_eccsiValidate(void)
  10824. {
  10825. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10826. double start;
  10827. int i, count;
  10828. const char**desc = bench_desc_words[lng_index];
  10829. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10830. ecc_point* pvt;
  10831. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10832. int valid;
  10833. int ret;
  10834. DECLARE_MULTI_VALUE_STATS_VARS()
  10835. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10836. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10837. (void)mp_init(ssk);
  10838. pvt = wc_ecc_new_point();
  10839. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10840. (void)wc_MakeEccsiKey(genKey, &gRng);
  10841. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10842. ssk, pvt);
  10843. /* Validation of RSK */
  10844. bench_stats_start(&count, &start);
  10845. do {
  10846. for (i = 0; i < genTimes; i++) {
  10847. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10848. sizeof(id), ssk, pvt, &valid);
  10849. if (ret != 0 || !valid) {
  10850. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10851. valid);
  10852. goto exit;
  10853. }
  10854. RECORD_MULTI_VALUE_STATS();
  10855. }
  10856. count += i;
  10857. } while (bench_stats_check(start)
  10858. #ifdef MULTI_VALUE_STATISTICS
  10859. || runs < minimum_runs
  10860. #endif
  10861. );
  10862. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10863. #ifdef MULTI_VALUE_STATISTICS
  10864. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10865. #endif
  10866. wc_FreeEccsiKey(genKey);
  10867. wc_ecc_del_point(pvt);
  10868. mp_free(ssk);
  10869. exit:
  10870. WC_FREE_VAR(genKey, HEAP_HINT);
  10871. WC_FREE_VAR(ssk, HEAP_HINT);
  10872. }
  10873. void bench_eccsi(void)
  10874. {
  10875. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10876. double start;
  10877. int i, count;
  10878. const char**desc = bench_desc_words[lng_index];
  10879. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10880. ecc_point* pvt;
  10881. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10882. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  10883. byte hash[WC_SHA256_DIGEST_SIZE];
  10884. byte hashSz = (byte)sizeof(hash);
  10885. byte sig[257];
  10886. word32 sigSz = sizeof(sig);
  10887. int ret;
  10888. int verified;
  10889. DECLARE_MULTI_VALUE_STATS_VARS()
  10890. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10891. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10892. (void)mp_init(ssk);
  10893. pvt = wc_ecc_new_point();
  10894. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10895. (void)wc_MakeEccsiKey(genKey, &gRng);
  10896. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10897. ssk, pvt);
  10898. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  10899. hash, &hashSz);
  10900. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  10901. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  10902. /* Encapsulate */
  10903. bench_stats_start(&count, &start);
  10904. do {
  10905. for (i = 0; i < genTimes; i++) {
  10906. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  10907. sizeof(msg), sig, &sigSz);
  10908. if (ret != 0) {
  10909. printf("wc_SignEccsiHash failed: %d\n", ret);
  10910. break;
  10911. }
  10912. RECORD_MULTI_VALUE_STATS();
  10913. }
  10914. count += i;
  10915. } while (bench_stats_check(start)
  10916. #ifdef MULTI_VALUE_STATISTICS
  10917. || runs < minimum_runs
  10918. #endif
  10919. );
  10920. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  10921. #ifdef MULTI_VALUE_STATISTICS
  10922. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10923. #endif
  10924. RESET_MULTI_VALUE_STATS_VARS();
  10925. /* Derive */
  10926. bench_stats_start(&count, &start);
  10927. do {
  10928. for (i = 0; i < genTimes; i++) {
  10929. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  10930. sizeof(msg), sig, sigSz, &verified);
  10931. if (ret != 0 || !verified) {
  10932. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  10933. verified);
  10934. goto exit;
  10935. }
  10936. RECORD_MULTI_VALUE_STATS();
  10937. }
  10938. count += i;
  10939. } while (bench_stats_check(start)
  10940. #ifdef MULTI_VALUE_STATISTICS
  10941. || runs < minimum_runs
  10942. #endif
  10943. );
  10944. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  10945. #ifdef MULTI_VALUE_STATISTICS
  10946. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10947. #endif
  10948. wc_FreeEccsiKey(genKey);
  10949. wc_ecc_del_point(pvt);
  10950. exit:
  10951. WC_FREE_VAR(genKey, HEAP_HINT);
  10952. WC_FREE_VAR(ssk, HEAP_HINT);
  10953. }
  10954. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  10955. #endif /* WOLFCRYPT_HAVE_ECCSI */
  10956. #ifdef WOLFCRYPT_HAVE_SAKKE
  10957. #ifdef WOLFCRYPT_SAKKE_KMS
  10958. void bench_sakkeKeyGen(void)
  10959. {
  10960. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10961. double start;
  10962. int i, count;
  10963. const char**desc = bench_desc_words[lng_index];
  10964. int ret;
  10965. DECLARE_MULTI_VALUE_STATS_VARS()
  10966. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10967. /* Key Gen */
  10968. bench_stats_start(&count, &start);
  10969. do {
  10970. for (i = 0; i < genTimes; i++) {
  10971. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  10972. ret = wc_MakeSakkeKey(genKey, &gRng);
  10973. if (ret != 0) {
  10974. printf("wc_MakeSakkeKey failed: %d\n", ret);
  10975. goto exit;
  10976. }
  10977. wc_FreeSakkeKey(genKey);
  10978. RECORD_MULTI_VALUE_STATS();
  10979. }
  10980. count += i;
  10981. } while (bench_stats_check(start)
  10982. #ifdef MULTI_VALUE_STATISTICS
  10983. || runs < minimum_runs
  10984. #endif
  10985. );
  10986. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  10987. #ifdef MULTI_VALUE_STATISTICS
  10988. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10989. #endif
  10990. exit:
  10991. WC_FREE_VAR(genKey, HEAP_HINT);
  10992. }
  10993. void bench_sakkeRskGen(void)
  10994. {
  10995. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  10996. double start;
  10997. int i, count;
  10998. const char**desc = bench_desc_words[lng_index];
  10999. ecc_point* rsk;
  11000. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11001. int ret;
  11002. DECLARE_MULTI_VALUE_STATS_VARS()
  11003. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11004. rsk = wc_ecc_new_point();
  11005. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11006. (void)wc_MakeSakkeKey(genKey, &gRng);
  11007. /* RSK Gen */
  11008. bench_stats_start(&count, &start);
  11009. do {
  11010. for (i = 0; i < genTimes; i++) {
  11011. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11012. if (ret != 0) {
  11013. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11014. goto exit;
  11015. }
  11016. RECORD_MULTI_VALUE_STATS();
  11017. }
  11018. count += i;
  11019. } while (bench_stats_check(start)
  11020. #ifdef MULTI_VALUE_STATISTICS
  11021. || runs < minimum_runs
  11022. #endif
  11023. );
  11024. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11025. #ifdef MULTI_VALUE_STATISTICS
  11026. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11027. #endif
  11028. wc_FreeSakkeKey(genKey);
  11029. wc_ecc_del_point(rsk);
  11030. exit:
  11031. WC_FREE_VAR(genKey, HEAP_HINT);
  11032. }
  11033. #endif
  11034. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11035. void bench_sakkeValidate(void)
  11036. {
  11037. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11038. double start;
  11039. int i, count;
  11040. const char**desc = bench_desc_words[lng_index];
  11041. ecc_point* rsk;
  11042. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11043. int valid;
  11044. int ret;
  11045. DECLARE_MULTI_VALUE_STATS_VARS()
  11046. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11047. rsk = wc_ecc_new_point();
  11048. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11049. (void)wc_MakeSakkeKey(genKey, &gRng);
  11050. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11051. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11052. /* Validation of RSK */
  11053. bench_stats_start(&count, &start);
  11054. do {
  11055. for (i = 0; i < genTimes; i++) {
  11056. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11057. if (ret != 0 || !valid) {
  11058. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11059. valid);
  11060. goto exit;
  11061. }
  11062. RECORD_MULTI_VALUE_STATS();
  11063. }
  11064. count += i;
  11065. } while (bench_stats_check(start)
  11066. #ifdef MULTI_VALUE_STATISTICS
  11067. || runs < minimum_runs
  11068. #endif
  11069. );
  11070. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11071. #ifdef MULTI_VALUE_STATISTICS
  11072. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11073. #endif
  11074. wc_FreeSakkeKey(genKey);
  11075. wc_ecc_del_point(rsk);
  11076. exit:
  11077. WC_FREE_VAR(genKey, HEAP_HINT);
  11078. }
  11079. void bench_sakke(void)
  11080. {
  11081. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11082. double start;
  11083. int i, count;
  11084. const char**desc = bench_desc_words[lng_index];
  11085. ecc_point* rsk;
  11086. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11087. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11088. byte ssv[sizeof(ssv_init)];
  11089. byte derSSV[sizeof(ssv)];
  11090. byte auth[257];
  11091. word16 authSz = sizeof(auth);
  11092. int ret = 0;
  11093. byte* table = NULL;
  11094. word32 len = 0;
  11095. byte* iTable = NULL;
  11096. word32 iTableLen = 0;
  11097. DECLARE_MULTI_VALUE_STATS_VARS()
  11098. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11099. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11100. rsk = wc_ecc_new_point();
  11101. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11102. (void)wc_MakeSakkeKey(genKey, &gRng);
  11103. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11104. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11105. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11106. /* Encapsulate */
  11107. bench_stats_start(&count, &start);
  11108. do {
  11109. for (i = 0; i < genTimes; i++) {
  11110. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11111. WC_HASH_TYPE_SHA256,
  11112. ssv, sizeof(ssv), auth, &authSz);
  11113. if (ret != 0) {
  11114. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11115. break;
  11116. }
  11117. RECORD_MULTI_VALUE_STATS();
  11118. } /* for */
  11119. count += i;
  11120. } while (bench_stats_check(start)
  11121. #ifdef MULTI_VALUE_STATISTICS
  11122. || runs < minimum_runs
  11123. #endif
  11124. );
  11125. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11126. 0, count, start, 0);
  11127. #ifdef MULTI_VALUE_STATISTICS
  11128. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11129. #endif
  11130. RESET_MULTI_VALUE_STATS_VARS();
  11131. /* Derive */
  11132. bench_stats_start(&count, &start);
  11133. do {
  11134. for (i = 0; i < genTimes; i++) {
  11135. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11136. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11137. sizeof(derSSV), auth, authSz);
  11138. if (ret != 0) {
  11139. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11140. break;
  11141. }
  11142. RECORD_MULTI_VALUE_STATS();
  11143. }
  11144. if (ret != 0) break;
  11145. count += i;
  11146. } while (bench_stats_check(start)
  11147. #ifdef MULTI_VALUE_STATISTICS
  11148. || runs < minimum_runs
  11149. #endif
  11150. );
  11151. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11152. 0, count, start, 0);
  11153. #ifdef MULTI_VALUE_STATISTICS
  11154. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11155. #endif
  11156. /* Calculate Point I and generate table. */
  11157. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11158. iTableLen = 0;
  11159. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11160. if (iTableLen != 0) {
  11161. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11162. if (iTable == NULL)
  11163. WC_ALLOC_DO_ON_FAILURE();
  11164. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11165. }
  11166. /* Encapsulate with Point I table */
  11167. bench_stats_start(&count, &start);
  11168. do {
  11169. for (i = 0; i < genTimes; i++) {
  11170. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11171. WC_HASH_TYPE_SHA256, ssv,
  11172. sizeof(ssv), auth, &authSz);
  11173. if (ret != 0) {
  11174. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11175. break;
  11176. }
  11177. RECORD_MULTI_VALUE_STATS();
  11178. }
  11179. count += i;
  11180. } while (bench_stats_check(start)
  11181. #ifdef MULTI_VALUE_STATISTICS
  11182. || runs < minimum_runs
  11183. #endif
  11184. );
  11185. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11186. count, start, 0);
  11187. #ifdef MULTI_VALUE_STATISTICS
  11188. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11189. #endif
  11190. RESET_MULTI_VALUE_STATS_VARS();
  11191. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11192. /* Derive with Point I table */
  11193. bench_stats_start(&count, &start);
  11194. do {
  11195. for (i = 0; i < genTimes; i++) {
  11196. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11197. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11198. sizeof(derSSV), auth, authSz);
  11199. if (ret != 0) {
  11200. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11201. break;
  11202. }
  11203. RECORD_MULTI_VALUE_STATS();
  11204. }
  11205. if (ret != 0) break;
  11206. count += i;
  11207. } while (bench_stats_check(start)
  11208. #ifdef MULTI_VALUE_STATISTICS
  11209. || runs < minimum_runs
  11210. #endif
  11211. );
  11212. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11213. count, start, 0);
  11214. #ifdef MULTI_VALUE_STATISTICS
  11215. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11216. #endif
  11217. RESET_MULTI_VALUE_STATS_VARS();
  11218. len = 0;
  11219. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11220. if (len > 0) {
  11221. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11222. if (table == NULL)
  11223. WC_ALLOC_DO_ON_FAILURE();
  11224. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11225. }
  11226. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11227. /* Derive with Point I table and RSK table */
  11228. bench_stats_start(&count, &start);
  11229. do {
  11230. for (i = 0; i < genTimes; i++) {
  11231. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11232. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11233. sizeof(derSSV), auth, authSz);
  11234. if (ret != 0) {
  11235. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11236. break;
  11237. }
  11238. RECORD_MULTI_VALUE_STATS();
  11239. }
  11240. if (ret != 0) break;
  11241. count += i;
  11242. } while (bench_stats_check(start)
  11243. #ifdef MULTI_VALUE_STATISTICS
  11244. || runs < minimum_runs
  11245. #endif
  11246. );
  11247. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11248. 0, count, start, 0);
  11249. #ifdef MULTI_VALUE_STATISTICS
  11250. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11251. #endif
  11252. RESET_MULTI_VALUE_STATS_VARS();
  11253. wc_ClearSakkePointITable(genKey);
  11254. /* Derive with RSK table */
  11255. bench_stats_start(&count, &start);
  11256. do {
  11257. for (i = 0; i < genTimes; i++) {
  11258. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11259. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11260. sizeof(derSSV), auth, authSz);
  11261. if (ret != 0) {
  11262. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11263. break;
  11264. }
  11265. RECORD_MULTI_VALUE_STATS();
  11266. }
  11267. if (ret != 0) break;
  11268. count += i;
  11269. } while (bench_stats_check(start)
  11270. #ifdef MULTI_VALUE_STATISTICS
  11271. || runs < minimum_runs
  11272. #endif
  11273. );
  11274. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11275. count, start, 0);
  11276. #ifdef MULTI_VALUE_STATISTICS
  11277. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11278. #endif
  11279. wc_FreeSakkeKey(genKey);
  11280. wc_ecc_del_point(rsk);
  11281. exit:
  11282. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11283. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11284. WC_FREE_VAR(genKey, HEAP_HINT);
  11285. }
  11286. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11287. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11288. #ifdef HAVE_FALCON
  11289. void bench_falconKeySign(byte level)
  11290. {
  11291. int ret = 0;
  11292. falcon_key key;
  11293. double start;
  11294. int i, count;
  11295. byte sig[FALCON_MAX_SIG_SIZE];
  11296. byte msg[512];
  11297. word32 x = 0;
  11298. const char**desc = bench_desc_words[lng_index];
  11299. DECLARE_MULTI_VALUE_STATS_VARS()
  11300. ret = wc_falcon_init(&key);
  11301. if (ret != 0) {
  11302. printf("wc_falcon_init failed %d\n", ret);
  11303. return;
  11304. }
  11305. ret = wc_falcon_set_level(&key, level);
  11306. if (ret != 0) {
  11307. printf("wc_falcon_set_level failed %d\n", ret);
  11308. }
  11309. if (ret == 0) {
  11310. if (level == 1) {
  11311. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11312. sizeof_bench_falcon_level1_key,
  11313. NULL, 0, &key);
  11314. }
  11315. else {
  11316. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11317. sizeof_bench_falcon_level5_key,
  11318. NULL, 0, &key);
  11319. }
  11320. if (ret != 0) {
  11321. printf("wc_falcon_import_private_key failed %d\n", ret);
  11322. }
  11323. }
  11324. /* make dummy msg */
  11325. for (i = 0; i < (int)sizeof(msg); i++) {
  11326. msg[i] = (byte)i;
  11327. }
  11328. bench_stats_start(&count, &start);
  11329. do {
  11330. for (i = 0; i < agreeTimes; i++) {
  11331. if (ret == 0) {
  11332. if (level == 1) {
  11333. x = FALCON_LEVEL1_SIG_SIZE;
  11334. }
  11335. else {
  11336. x = FALCON_LEVEL5_SIG_SIZE;
  11337. }
  11338. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11339. if (ret != 0) {
  11340. printf("wc_falcon_sign_msg failed\n");
  11341. }
  11342. }
  11343. RECORD_MULTI_VALUE_STATS();
  11344. }
  11345. count += i;
  11346. } while (bench_stats_check(start)
  11347. #ifdef MULTI_VALUE_STATISTICS
  11348. || runs < minimum_runs
  11349. #endif
  11350. );
  11351. if (ret == 0) {
  11352. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11353. count, start, ret);
  11354. #ifdef MULTI_VALUE_STATISTICS
  11355. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11356. #endif
  11357. }
  11358. RESET_MULTI_VALUE_STATS_VARS();
  11359. bench_stats_start(&count, &start);
  11360. do {
  11361. for (i = 0; i < agreeTimes; i++) {
  11362. if (ret == 0) {
  11363. int verify = 0;
  11364. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11365. &key);
  11366. if (ret != 0 || verify != 1) {
  11367. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11368. ret, verify);
  11369. ret = -1;
  11370. }
  11371. }
  11372. RECORD_MULTI_VALUE_STATS();
  11373. }
  11374. count += i;
  11375. } while (bench_stats_check(start)
  11376. #ifdef MULTI_VALUE_STATISTICS
  11377. || runs < minimum_runs
  11378. #endif
  11379. );
  11380. if (ret == 0) {
  11381. bench_stats_asym_finish("FALCON", level, desc[5],
  11382. 0, count, start, ret);
  11383. #ifdef MULTI_VALUE_STATISTICS
  11384. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11385. #endif
  11386. }
  11387. wc_falcon_free(&key);
  11388. }
  11389. #endif /* HAVE_FALCON */
  11390. #ifdef HAVE_DILITHIUM
  11391. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11392. #ifndef WOLFSSL_NO_ML_DSA_44
  11393. static const unsigned char bench_dilithium_level2_sig[] = {
  11394. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11395. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11396. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11397. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11398. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11399. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11400. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11401. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11402. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11403. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11404. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11405. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11406. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11407. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11408. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11409. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11410. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11411. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11412. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11413. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11414. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11415. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11416. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11417. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11418. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11419. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11420. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11421. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11422. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11423. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11424. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11425. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11426. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11427. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11428. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11429. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11430. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11431. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11432. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11433. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11434. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11435. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11436. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11437. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11438. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11439. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11440. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11441. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11442. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11443. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11444. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11445. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11446. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11447. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11448. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11449. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11450. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11451. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11452. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11453. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11454. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11455. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11456. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11457. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11458. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11459. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11460. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11461. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11462. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11463. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11464. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11465. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11466. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11467. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11468. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11469. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11470. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11471. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11472. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11473. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11474. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11475. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11476. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11477. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11478. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11479. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11480. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11481. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11482. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11483. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11484. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11485. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11486. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11487. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11488. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11489. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11490. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11491. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11492. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11493. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11494. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11495. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11496. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11497. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11498. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11499. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11500. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11501. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11502. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11503. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11504. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11505. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11506. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11507. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11508. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11509. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11510. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11511. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11512. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11513. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11514. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11515. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11516. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11517. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11518. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11519. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11520. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11521. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11522. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11523. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11524. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11525. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11526. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11527. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11528. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11529. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11530. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11531. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11532. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11533. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11534. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11535. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11536. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11537. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11538. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11539. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11540. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11541. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11542. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11543. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11544. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11545. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11546. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11547. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11548. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11549. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11550. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11551. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11552. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11553. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11554. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11555. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11556. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11557. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11558. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11559. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11560. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11561. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11562. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11563. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11564. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11565. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11566. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11567. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11568. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11569. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11570. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11571. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11572. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11573. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11574. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11575. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11576. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11577. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11578. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11579. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11580. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11581. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11582. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11583. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11584. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11585. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11586. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11587. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11588. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11589. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11590. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11591. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11592. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11593. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11594. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11595. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11596. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11597. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11598. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11599. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11600. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11601. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11602. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11603. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11604. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11605. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11606. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11607. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11608. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11609. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11610. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11611. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11612. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11613. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11614. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11615. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11616. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11617. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11618. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11619. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11620. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11621. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11622. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11623. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11624. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11625. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11626. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11627. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11628. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11629. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11630. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11631. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11632. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11633. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11634. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11635. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11636. };
  11637. static const int sizeof_bench_dilithium_level2_sig =
  11638. sizeof(bench_dilithium_level2_sig);
  11639. #endif
  11640. #ifndef WOLFSSL_NO_ML_DSA_65
  11641. static const unsigned char bench_dilithium_level3_sig[] = {
  11642. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11643. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11644. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11645. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11646. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11647. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11648. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11649. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11650. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11651. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11652. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11653. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11654. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11655. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11656. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11657. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11658. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11659. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11660. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11661. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11662. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11663. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11664. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11665. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11666. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11667. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11668. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11669. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11670. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11671. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11672. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11673. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11674. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11675. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11676. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11677. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11678. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11679. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11680. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11681. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11682. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11683. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11684. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11685. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11686. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11687. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11688. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11689. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11690. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11691. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11692. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11693. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11694. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11695. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11696. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11697. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11698. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11699. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11700. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11701. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11702. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11703. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11704. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11705. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11706. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11707. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11708. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11709. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11710. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11711. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11712. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11713. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11714. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11715. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11716. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11717. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11718. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11719. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11720. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11721. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11722. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11723. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11724. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11725. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11726. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11727. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11728. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11729. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11730. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11731. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11732. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11733. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11734. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11735. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11736. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11737. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11738. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11739. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11740. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11741. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11742. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11743. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11744. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11745. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11746. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11747. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11748. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11749. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11750. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11751. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11752. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11753. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11754. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11755. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11756. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11757. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11758. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11759. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11760. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11761. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11762. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11763. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11764. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11765. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11766. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11767. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11768. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11769. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11770. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11771. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11772. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11773. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11774. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11775. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11776. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11777. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11778. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11779. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11780. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11781. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11782. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11783. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11784. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11785. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11786. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11787. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11788. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11789. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11790. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11791. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11792. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11793. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11794. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11795. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11796. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11797. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11798. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11799. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11800. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11801. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11802. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11803. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11804. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11805. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11806. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11807. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11808. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11809. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11810. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11811. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11812. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11813. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11814. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11815. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11816. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11817. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11818. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11819. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11820. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11821. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11822. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11823. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11824. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11825. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11826. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11827. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11828. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11829. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11830. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11831. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11832. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11833. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11834. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11835. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11836. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11837. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11838. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11839. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11840. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11841. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11842. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11843. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11844. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11845. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11846. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11847. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11848. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11849. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11850. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11851. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11852. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11853. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11854. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11855. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11856. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11857. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11858. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11859. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11860. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11861. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11862. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11863. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11864. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11865. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11866. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  11867. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  11868. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  11869. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  11870. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  11871. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  11872. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  11873. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  11874. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  11875. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  11876. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  11877. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  11878. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  11879. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  11880. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  11881. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  11882. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  11883. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  11884. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  11885. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  11886. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  11887. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  11888. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  11889. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  11890. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  11891. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  11892. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  11893. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  11894. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  11895. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  11896. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  11897. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  11898. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  11899. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  11900. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  11901. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  11902. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  11903. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  11904. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  11905. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  11906. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  11907. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  11908. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  11909. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  11910. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  11911. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  11912. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  11913. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  11914. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  11915. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  11916. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  11917. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  11918. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  11919. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  11920. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  11921. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  11922. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  11923. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  11924. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  11925. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  11926. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  11927. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  11928. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  11929. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  11930. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  11931. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  11932. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  11933. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  11934. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  11935. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  11936. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  11937. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  11938. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  11939. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  11940. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  11941. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  11942. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  11943. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  11944. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  11945. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  11946. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  11947. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  11948. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  11949. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  11950. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  11951. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  11952. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  11953. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  11954. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  11955. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  11956. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  11957. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  11958. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  11959. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  11960. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  11961. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  11962. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  11963. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  11964. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  11965. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  11966. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  11967. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  11968. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  11969. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  11970. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  11971. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11972. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  11973. };
  11974. static const int sizeof_bench_dilithium_level3_sig =
  11975. sizeof(bench_dilithium_level3_sig);
  11976. #endif
  11977. #ifndef WOLFSSL_NO_ML_DSA_87
  11978. static const unsigned char bench_dilithium_level5_sig[] = {
  11979. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  11980. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  11981. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  11982. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  11983. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  11984. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  11985. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  11986. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  11987. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  11988. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  11989. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  11990. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  11991. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  11992. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  11993. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  11994. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  11995. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  11996. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  11997. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  11998. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  11999. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12000. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12001. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12002. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12003. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12004. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12005. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12006. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12007. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12008. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12009. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12010. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12011. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12012. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12013. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12014. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12015. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12016. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12017. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12018. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12019. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12020. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12021. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12022. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12023. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12024. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12025. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12026. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12027. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12028. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12029. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12030. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12031. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12032. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12033. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12034. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12035. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12036. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12037. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12038. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12039. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12040. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12041. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12042. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12043. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12044. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12045. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12046. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12047. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12048. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12049. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12050. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12051. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12052. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12053. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12054. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12055. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12056. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12057. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12058. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12059. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12060. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12061. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12062. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12063. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12064. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12065. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12066. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12067. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12068. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12069. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12070. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12071. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12072. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12073. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12074. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12075. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12076. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12077. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12078. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12079. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12080. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12081. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12082. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12083. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12084. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12085. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12086. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12087. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12088. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12089. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12090. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12091. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12092. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12093. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12094. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12095. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12096. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12097. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12098. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12099. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12100. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12101. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12102. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12103. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12104. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12105. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12106. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12107. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12108. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12109. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12110. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12111. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12112. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12113. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12114. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12115. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12116. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12117. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12118. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12119. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12120. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12121. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12122. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12123. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12124. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12125. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12126. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12127. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12128. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12129. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12130. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12131. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12132. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12133. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12134. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12135. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12136. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12137. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12138. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12139. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12140. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12141. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12142. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12143. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12144. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12145. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12146. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12147. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12148. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12149. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12150. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12151. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12152. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12153. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12154. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12155. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12156. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12157. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12158. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12159. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12160. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12161. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12162. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12163. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12164. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12165. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12166. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12167. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12168. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12169. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12170. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12171. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12172. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12173. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12174. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12175. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12176. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12177. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12178. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12179. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12180. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12181. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12182. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12183. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12184. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12185. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12186. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12187. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12188. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12189. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12190. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12191. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12192. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12193. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12194. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12195. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12196. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12197. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12198. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12199. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12200. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12201. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12202. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12203. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12204. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12205. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12206. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12207. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12208. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12209. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12210. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12211. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12212. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12213. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12214. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12215. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12216. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12217. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12218. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12219. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12220. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12221. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12222. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12223. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12224. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12225. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12226. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12227. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12228. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12229. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12230. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12231. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12232. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12233. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12234. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12235. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12236. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12237. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12238. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12239. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12240. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12241. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12242. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12243. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12244. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12245. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12246. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12247. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12248. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12249. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12250. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12251. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12252. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12253. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12254. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12255. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12256. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12257. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12258. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12259. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12260. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12261. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12262. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12263. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12264. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12265. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12266. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12267. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12268. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12269. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12270. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12271. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12272. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12273. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12274. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12275. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12276. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12277. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12278. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12279. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12280. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12281. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12282. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12283. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12284. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12285. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12286. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12287. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12288. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12289. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12290. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12291. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12292. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12293. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12294. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12295. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12296. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12297. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12298. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12299. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12300. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12301. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12302. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12303. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12304. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12305. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12306. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12307. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12308. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12309. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12310. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12311. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12312. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12313. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12314. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12315. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12316. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12317. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12318. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12319. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12320. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12321. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12322. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12323. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12324. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12325. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12326. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12327. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12328. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12329. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12330. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12331. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12332. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12333. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12334. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12335. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12336. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12337. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12338. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12339. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12340. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12341. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12342. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12343. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12344. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12345. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12346. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12347. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12348. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12349. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12350. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12351. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12352. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12353. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12354. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12355. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12356. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12357. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12358. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12359. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12360. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12361. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12362. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12363. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12364. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12365. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12366. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12367. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12368. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12369. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12370. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12371. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12372. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12373. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12374. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12375. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12376. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12377. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12378. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12379. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12380. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12381. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12382. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12383. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12384. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12385. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12386. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12387. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12388. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12389. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12390. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12391. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12392. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12393. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12394. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12395. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12396. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12397. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12398. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12399. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12400. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12401. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12402. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12403. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12404. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12405. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12406. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12407. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12408. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12409. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12410. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12411. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12412. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12413. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12414. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12415. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12416. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12417. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12418. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12419. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12420. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12421. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12422. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12423. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12424. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12425. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12426. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12427. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12428. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12429. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12430. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12431. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12432. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12433. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12434. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12435. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12436. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12437. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12438. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12439. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12440. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12441. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12442. };
  12443. static const int sizeof_bench_dilithium_level5_sig =
  12444. sizeof(bench_dilithium_level5_sig);
  12445. #endif
  12446. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12447. void bench_dilithiumKeySign(byte level)
  12448. {
  12449. int ret = 0;
  12450. dilithium_key key;
  12451. double start;
  12452. int i, count;
  12453. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12454. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12455. byte msg[512];
  12456. word32 x = 0;
  12457. #endif
  12458. const char**desc = bench_desc_words[lng_index];
  12459. DECLARE_MULTI_VALUE_STATS_VARS()
  12460. byte params = 0;
  12461. if (level == 2) {
  12462. params = 44;
  12463. }
  12464. else if (level == 3) {
  12465. params = 65;
  12466. }
  12467. else if (level == 5) {
  12468. params = 87;
  12469. }
  12470. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12471. /* make dummy msg */
  12472. for (i = 0; i < (int)sizeof(msg); i++) {
  12473. msg[i] = (byte)i;
  12474. }
  12475. #endif
  12476. ret = wc_dilithium_init(&key);
  12477. if (ret != 0) {
  12478. printf("wc_dilithium_init failed %d\n", ret);
  12479. return;
  12480. }
  12481. ret = wc_dilithium_set_level(&key, level);
  12482. if (ret != 0) {
  12483. printf("wc_dilithium_set_level() failed %d\n", ret);
  12484. }
  12485. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12486. bench_stats_start(&count, &start);
  12487. do {
  12488. for (i = 0; i < agreeTimes; i++) {
  12489. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12490. if (ret != 0) {
  12491. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12492. return;
  12493. }
  12494. }
  12495. count += i;
  12496. } while (bench_stats_check(start)
  12497. #ifdef MULTI_VALUE_STATISTICS
  12498. || runs < minimum_runs
  12499. #endif
  12500. );
  12501. if (ret == 0) {
  12502. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12503. start, ret);
  12504. #ifdef MULTI_VALUE_STATISTICS
  12505. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12506. #endif
  12507. }
  12508. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12509. #ifndef WOLFSSL_NO_ML_DSA_44
  12510. if (level == 2) {
  12511. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12512. sizeof_bench_dilithium_level2_key, &key);
  12513. }
  12514. #endif
  12515. #ifndef WOLFSSL_NO_ML_DSA_65
  12516. if (level == 3) {
  12517. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12518. sizeof_bench_dilithium_level3_key, &key);
  12519. }
  12520. #endif
  12521. #ifndef WOLFSSL_NO_ML_DSA_87
  12522. if (level == 5) {
  12523. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12524. sizeof_bench_dilithium_level5_key, &key);
  12525. }
  12526. #endif
  12527. if (ret != 0) {
  12528. printf("Failed to load private key\n");
  12529. return;
  12530. }
  12531. #endif
  12532. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12533. if (level == 2) {
  12534. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12535. }
  12536. else if (level == 3) {
  12537. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12538. }
  12539. else {
  12540. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12541. }
  12542. RESET_MULTI_VALUE_STATS_VARS();
  12543. bench_stats_start(&count, &start);
  12544. do {
  12545. for (i = 0; i < agreeTimes; i++) {
  12546. if (ret == 0) {
  12547. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12548. GLOBAL_RNG);
  12549. if (ret != 0) {
  12550. printf("wc_dilithium_sign_msg failed\n");
  12551. }
  12552. }
  12553. RECORD_MULTI_VALUE_STATS();
  12554. }
  12555. count += i;
  12556. } while (bench_stats_check(start)
  12557. #ifdef MULTI_VALUE_STATISTICS
  12558. || runs < minimum_runs
  12559. #endif
  12560. );
  12561. if (ret == 0) {
  12562. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12563. ret);
  12564. #ifdef MULTI_VALUE_STATISTICS
  12565. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12566. #endif
  12567. }
  12568. #endif
  12569. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12570. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12571. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12572. #ifndef WOLFSSL_NO_ML_DSA_44
  12573. if (level == 2) {
  12574. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12575. x = sizeof_bench_dilithium_level2_sig;
  12576. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12577. #endif
  12578. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12579. sizeof_bench_dilithium_level2_pubkey, &key);
  12580. }
  12581. #endif
  12582. #ifndef WOLFSSL_NO_ML_DSA_65
  12583. if (level == 3) {
  12584. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12585. x = sizeof_bench_dilithium_level3_sig;
  12586. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12587. #endif
  12588. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12589. sizeof_bench_dilithium_level3_pubkey, &key);
  12590. }
  12591. #endif
  12592. #ifndef WOLFSSL_NO_ML_DSA_87
  12593. if (level == 5) {
  12594. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12595. x = sizeof_bench_dilithium_level5_sig;
  12596. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12597. #endif
  12598. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12599. sizeof_bench_dilithium_level5_pubkey, &key);
  12600. }
  12601. #endif
  12602. if (ret != 0) {
  12603. printf("Failed to load public key\n");
  12604. return;
  12605. }
  12606. #endif
  12607. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12608. RESET_MULTI_VALUE_STATS_VARS();
  12609. bench_stats_start(&count, &start);
  12610. do {
  12611. for (i = 0; i < agreeTimes; i++) {
  12612. if (ret == 0) {
  12613. int verify = 0;
  12614. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12615. &verify, &key);
  12616. if (ret != 0 || verify != 1) {
  12617. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12618. ret, verify);
  12619. ret = -1;
  12620. }
  12621. }
  12622. RECORD_MULTI_VALUE_STATS();
  12623. }
  12624. count += i;
  12625. } while (bench_stats_check(start)
  12626. #ifdef MULTI_VALUE_STATISTICS
  12627. || runs < minimum_runs
  12628. #endif
  12629. );
  12630. if (ret == 0) {
  12631. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12632. ret);
  12633. #ifdef MULTI_VALUE_STATISTICS
  12634. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12635. #endif
  12636. }
  12637. #endif
  12638. wc_dilithium_free(&key);
  12639. }
  12640. #endif /* HAVE_DILITHIUM */
  12641. #ifdef HAVE_SPHINCS
  12642. void bench_sphincsKeySign(byte level, byte optim)
  12643. {
  12644. int ret = 0;
  12645. sphincs_key key;
  12646. double start;
  12647. int i, count;
  12648. byte sig[SPHINCS_MAX_SIG_SIZE];
  12649. byte msg[512];
  12650. word32 x = 0;
  12651. const char**desc = bench_desc_words[lng_index];
  12652. DECLARE_MULTI_VALUE_STATS_VARS()
  12653. ret = wc_sphincs_init(&key);
  12654. if (ret != 0) {
  12655. printf("wc_sphincs_init failed %d\n", ret);
  12656. return;
  12657. }
  12658. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12659. if (ret != 0) {
  12660. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12661. }
  12662. if (ret == 0) {
  12663. ret = -1;
  12664. if ((level == 1) && (optim == FAST_VARIANT)) {
  12665. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12666. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12667. }
  12668. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12669. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12670. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12671. }
  12672. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12673. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12674. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12675. }
  12676. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12677. ret = wc_sphincs_import_private_key(
  12678. bench_sphincs_small_level1_key,
  12679. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12680. }
  12681. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12682. ret = wc_sphincs_import_private_key(
  12683. bench_sphincs_small_level3_key,
  12684. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12685. }
  12686. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12687. ret = wc_sphincs_import_private_key(
  12688. bench_sphincs_small_level5_key,
  12689. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12690. }
  12691. if (ret != 0) {
  12692. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12693. }
  12694. }
  12695. /* make dummy msg */
  12696. for (i = 0; i < (int)sizeof(msg); i++) {
  12697. msg[i] = (byte)i;
  12698. }
  12699. bench_stats_start(&count, &start);
  12700. do {
  12701. for (i = 0; i < agreeTimes; i++) {
  12702. if (ret == 0) {
  12703. if ((level == 1) && (optim == FAST_VARIANT)) {
  12704. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12705. }
  12706. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12707. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12708. }
  12709. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12710. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12711. }
  12712. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12713. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12714. }
  12715. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12716. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12717. }
  12718. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12719. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12720. }
  12721. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12722. if (ret != 0) {
  12723. printf("wc_sphincs_sign_msg failed\n");
  12724. }
  12725. }
  12726. RECORD_MULTI_VALUE_STATS();
  12727. }
  12728. count += i;
  12729. } while (bench_stats_check(start)
  12730. #ifdef MULTI_VALUE_STATISTICS
  12731. || runs < minimum_runs
  12732. #endif
  12733. );
  12734. if (ret == 0) {
  12735. if (optim == FAST_VARIANT) {
  12736. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12737. start, ret);
  12738. }
  12739. else {
  12740. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12741. start, ret);
  12742. }
  12743. #ifdef MULTI_VALUE_STATISTICS
  12744. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12745. #endif
  12746. }
  12747. RESET_MULTI_VALUE_STATS_VARS();
  12748. bench_stats_start(&count, &start);
  12749. do {
  12750. for (i = 0; i < agreeTimes; i++) {
  12751. if (ret == 0) {
  12752. int verify = 0;
  12753. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12754. &key);
  12755. if (ret != 0 || verify != 1) {
  12756. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12757. ret, verify);
  12758. ret = -1;
  12759. }
  12760. }
  12761. RECORD_MULTI_VALUE_STATS();
  12762. }
  12763. count += i;
  12764. } while (bench_stats_check(start)
  12765. #ifdef MULTI_VALUE_STATISTICS
  12766. || runs < minimum_runs
  12767. #endif
  12768. );
  12769. if (ret == 0) {
  12770. if (optim == FAST_VARIANT) {
  12771. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12772. start, ret);
  12773. }
  12774. else {
  12775. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12776. start, ret);
  12777. }
  12778. #ifdef MULTI_VALUE_STATISTICS
  12779. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12780. #endif
  12781. }
  12782. wc_sphincs_free(&key);
  12783. }
  12784. #endif /* HAVE_SPHINCS */
  12785. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12786. #define WIN32_LEAN_AND_MEAN
  12787. #include <windows.h>
  12788. double current_time(int reset)
  12789. {
  12790. static int init = 0;
  12791. static LARGE_INTEGER freq;
  12792. LARGE_INTEGER count;
  12793. (void)reset;
  12794. if (!init) {
  12795. QueryPerformanceFrequency(&freq);
  12796. init = 1;
  12797. }
  12798. QueryPerformanceCounter(&count);
  12799. #ifdef BENCH_MICROSECOND
  12800. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12801. #else
  12802. return (double)count.QuadPart / freq.QuadPart;
  12803. #endif
  12804. }
  12805. #elif defined MICROCHIP_PIC32
  12806. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12807. #define CLOCK 80000000.0
  12808. #else
  12809. #define CLOCK 40000000.0
  12810. #endif
  12811. extern void WriteCoreTimer(word32 t);
  12812. extern word32 ReadCoreTimer(void);
  12813. double current_time(int reset)
  12814. {
  12815. unsigned int ns;
  12816. if (reset) {
  12817. WriteCoreTimer(0);
  12818. }
  12819. /* get timer in ns */
  12820. ns = ReadCoreTimer();
  12821. /* return seconds as a double */
  12822. return ( ns / CLOCK * 2.0);
  12823. }
  12824. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12825. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12826. /* declared above at line 239 */
  12827. /* extern double current_time(int reset); */
  12828. #elif defined(FREERTOS)
  12829. #ifdef PLATFORMIO
  12830. #include <freertos/FreeRTOS.h>
  12831. #include <freertos/task.h>
  12832. #else
  12833. #include "task.h"
  12834. #endif
  12835. #if defined(WOLFSSL_ESPIDF)
  12836. /* prototype definition */
  12837. int construct_argv();
  12838. extern char* __argv[22];
  12839. /* current_time(reset)
  12840. *
  12841. * Benchmark passage of time, in fractional seconds.
  12842. * [reset] is non zero to adjust timer or counter to zero
  12843. *
  12844. * Use care when repeatedly calling calling. See implementation. */
  12845. double current_time(int reset)
  12846. {
  12847. double ret;
  12848. #if ESP_IDF_VERSION_MAJOR >= 4
  12849. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12850. #else
  12851. portTickType tickCount;
  12852. #endif
  12853. #if defined(__XTENSA__)
  12854. (void)reset;
  12855. if (reset) {
  12856. /* TODO: Determine a mechanism for reset that does not interfere
  12857. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12858. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12859. ESP_LOGW(TAG, "Current_time() reset!");
  12860. portTICK_TYPE_ENTER_CRITICAL();
  12861. {
  12862. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12863. _esp_cpu_count_last = xthal_get_ccount();
  12864. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12865. }
  12866. portTICK_TYPE_EXIT_CRITICAL();
  12867. */
  12868. }
  12869. #else
  12870. /* Only reset the CPU counter for RISC-V */
  12871. if (reset) {
  12872. ESP_LOGV(TAG, "current_time() reset!");
  12873. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  12874. * unexpected rollovers in return values for Xtensa but not RISC-V?
  12875. * See also esp_get_cycle_count_ex() */
  12876. #ifdef __XTENSA__
  12877. _esp_cpu_count_last = xthal_get_ccount();
  12878. #else
  12879. #if ESP_IDF_VERSION_MAJOR >= 5
  12880. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12881. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12882. #else
  12883. cpu_hal_set_cycle_count((uint32_t)0);
  12884. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  12885. #endif
  12886. #endif
  12887. }
  12888. #endif
  12889. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  12890. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  12891. The count of ticks since vTaskStartScheduler was called,
  12892. typiclly in app_startup.c */
  12893. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12894. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  12895. if (tickCount == last_tickCount) {
  12896. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  12897. }
  12898. if (tickCount < last_tickCount) {
  12899. ESP_LOGW(TAG, "last_tickCount overflow?");
  12900. }
  12901. #endif
  12902. if (reset) {
  12903. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12904. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  12905. #endif
  12906. last_tickCount = tickCount;
  12907. }
  12908. else {
  12909. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  12910. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  12911. #endif
  12912. }
  12913. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  12914. ret = (double)tickCount / configTICK_RATE_HZ;
  12915. #else
  12916. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  12917. "assuming 1000 Hz.");
  12918. ret = (double)(tickCount / 1000.0);
  12919. #endif /* configTICK_RATE_HZ */
  12920. return ret;
  12921. } /* current_time */
  12922. #else
  12923. /* current_time(reset)
  12924. *
  12925. * Benchmark passage of time, in fractional seconds.
  12926. * [reset] is non zero to adjust timer or counter to zero
  12927. *
  12928. * Use care when repeatedly calling calling. See implementation. */
  12929. double current_time(int reset)
  12930. {
  12931. portTickType tickCount = xTaskGetTickCount();
  12932. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  12933. #ifdef configTICK_RATE_HZ
  12934. return (double)tickCount / configTICK_RATE_HZ;
  12935. #else
  12936. return (double)tickCount / 1000;
  12937. #endif
  12938. }
  12939. #endif
  12940. #elif defined (WOLFSSL_TIRTOS)
  12941. extern double current_time(int reset);
  12942. #elif defined(FREESCALE_MQX)
  12943. double current_time(int reset)
  12944. {
  12945. TIME_STRUCT tv;
  12946. _time_get(&tv);
  12947. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  12948. }
  12949. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  12950. && defined(MAX3266X_RTC)
  12951. double current_time(int reset)
  12952. {
  12953. (void)reset;
  12954. return wc_MXC_RTC_Time();
  12955. }
  12956. #elif defined(FREESCALE_KSDK_BM)
  12957. double current_time(int reset)
  12958. {
  12959. return (double)OSA_TimeGetMsec() / 1000;
  12960. }
  12961. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  12962. double current_time(int reset)
  12963. {
  12964. (void)reset;
  12965. return (double)osKernelGetTickCount() / 1000.0;
  12966. }
  12967. #elif defined(WOLFSSL_EMBOS)
  12968. #include "RTOS.h"
  12969. double current_time(int reset)
  12970. {
  12971. double time_now;
  12972. double current_s = OS_GetTime() / 1000.0;
  12973. double current_us = OS_GetTime_us() / MILLION_VALUE;
  12974. time_now = (double)( current_s + current_us);
  12975. (void) reset;
  12976. return time_now;
  12977. }
  12978. #elif defined(WOLFSSL_SGX)
  12979. double current_time(int reset);
  12980. #elif defined(WOLFSSL_DEOS)
  12981. double current_time(int reset)
  12982. {
  12983. const uint32_t systemTickTimeInHz
  12984. = 1000000 / systemTickInMicroseconds();
  12985. const volatile uint32_t *systemTickPtr = systemTickPointer();
  12986. (void)reset;
  12987. return (double) *systemTickPtr/systemTickTimeInHz;
  12988. }
  12989. #elif defined(MICRIUM)
  12990. double current_time(int reset)
  12991. {
  12992. #if (OS_VERSION < 50000)
  12993. CPU_ERR err;
  12994. (void)reset;
  12995. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  12996. #else
  12997. RTOS_ERR err;
  12998. double ret = 0;
  12999. OS_TICK tick = OSTimeGet(&err);
  13000. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13001. (void)reset;
  13002. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13003. ret = ((double)tick)/rate;
  13004. }
  13005. return ret;
  13006. #endif
  13007. }
  13008. #elif defined(WOLFSSL_ZEPHYR)
  13009. #include <time.h>
  13010. double current_time(int reset)
  13011. {
  13012. int64_t t;
  13013. (void)reset;
  13014. #if defined(CONFIG_ARCH_POSIX)
  13015. k_cpu_idle();
  13016. #endif
  13017. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13018. return (double)(t / 1000);
  13019. }
  13020. #elif defined(WOLFSSL_NETBURNER)
  13021. #include <predef.h>
  13022. #include <utils.h>
  13023. #include <constants.h>
  13024. double current_time(int reset)
  13025. {
  13026. DWORD ticks = TimeTick; /* ticks since system start */
  13027. (void)reset;
  13028. return (double) ticks/TICKS_PER_SECOND;
  13029. }
  13030. #elif defined(THREADX)
  13031. #include "tx_api.h"
  13032. double current_time(int reset)
  13033. {
  13034. (void)reset;
  13035. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13036. }
  13037. #elif defined(WOLFSSL_XILINX)
  13038. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13039. #define COUNTS_PER_SECOND \
  13040. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13041. #else
  13042. #define COUNTS_PER_SECOND \
  13043. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13044. #endif
  13045. double current_time(int reset)
  13046. {
  13047. double timer;
  13048. uint64_t cntPct = 0;
  13049. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13050. /* Convert to milliseconds */
  13051. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13052. /* Convert to seconds.millisecond */
  13053. timer /= 1000;
  13054. return timer;
  13055. }
  13056. #elif defined(LINUX_RUSAGE_UTIME)
  13057. #include <sys/time.h>
  13058. #include <sys/resource.h>
  13059. static struct rusage base_rusage;
  13060. static struct rusage cur_rusage;
  13061. double current_time(int reset)
  13062. {
  13063. struct rusage rusage;
  13064. (void)reset;
  13065. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13066. if (reset)
  13067. base_rusage = rusage;
  13068. else
  13069. cur_rusage = rusage;
  13070. /* only consider user time, as system time is host-related overhead
  13071. * outside wolfcrypt.
  13072. */
  13073. return (double)rusage.ru_utime.tv_sec +
  13074. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13075. }
  13076. static void check_for_excessive_stime(const char *desc,
  13077. const char *desc_extra)
  13078. {
  13079. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13080. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13081. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13082. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13083. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13084. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13085. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13086. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13087. double stime_utime_ratio =
  13088. (cur_stime - start_stime) / (cur_utime - start_utime);
  13089. if (stime_utime_ratio > .1)
  13090. printf("%swarning, "
  13091. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13092. err_prefix, desc, desc_extra,
  13093. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13094. }
  13095. #elif defined(WOLFSSL_LINUXKM)
  13096. double current_time(int reset)
  13097. {
  13098. (void)reset;
  13099. u64 ns = ktime_get_ns();
  13100. return (double)ns / 1000000000.0;
  13101. }
  13102. #else
  13103. #include <sys/time.h>
  13104. double current_time(int reset)
  13105. {
  13106. struct timespec tv;
  13107. (void)reset;
  13108. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13109. #ifdef BENCH_MICROSECOND
  13110. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13111. #else
  13112. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13113. #endif
  13114. }
  13115. #endif /* _WIN32 */
  13116. #if defined(HAVE_GET_CYCLES)
  13117. #if defined(WOLFSSL_ESPIDF)
  13118. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13119. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13120. {
  13121. /* Reminder for long duration between calls with
  13122. * multiple overflows will not be detected. */
  13123. return esp_get_cycle_count_ex();
  13124. }
  13125. /* implement other architectures here */
  13126. #else
  13127. static WC_INLINE word64 get_intel_cycles(void)
  13128. {
  13129. unsigned int lo_c, hi_c;
  13130. __asm__ __volatile__ (
  13131. "cpuid\n\t"
  13132. "rdtsc"
  13133. : "=a"(lo_c), "=d"(hi_c) /* out */
  13134. : "a"(0) /* in */
  13135. : "%ebx", "%ecx"); /* clobber */
  13136. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13137. }
  13138. #endif
  13139. #endif /* HAVE_GET_CYCLES */
  13140. void benchmark_configure(word32 block_size)
  13141. {
  13142. /* must be greater than 0 */
  13143. if (block_size > 0) {
  13144. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13145. bench_size = block_size;
  13146. }
  13147. }
  13148. #ifndef NO_MAIN_DRIVER
  13149. #ifndef MAIN_NO_ARGS
  13150. #ifndef WOLFSSL_BENCHMARK_ALL
  13151. /* Display the algorithm string and keep to 80 characters per line.
  13152. *
  13153. * str Algorithm string to print.
  13154. * line Length of line used so far.
  13155. */
  13156. #ifndef BENCH_MAX_LINE
  13157. #define BENCH_MAX_LINE 80
  13158. #endif
  13159. static void print_alg(const char* str, int* line)
  13160. {
  13161. const char* const ident = " ";
  13162. if (*line == 0) {
  13163. printf("%s", ident);
  13164. *line = (int)XSTRLEN(ident);
  13165. }
  13166. printf(" %s", str);
  13167. *line += (int)XSTRLEN(str) + 1;
  13168. if (*line > BENCH_MAX_LINE) {
  13169. printf("\n");
  13170. *line = 0;
  13171. }
  13172. }
  13173. #endif /* WOLFSSL_BENCHMARK_ALL */
  13174. /* Display the usage options of the benchmark program. */
  13175. static void Usage(void)
  13176. {
  13177. int e = 0;
  13178. #ifndef WOLFSSL_BENCHMARK_ALL
  13179. int i;
  13180. int line;
  13181. #endif
  13182. printf("benchmark\n");
  13183. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13184. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13185. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13186. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13187. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13188. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13189. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13190. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13191. #else
  13192. e += 3;
  13193. #endif
  13194. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13195. #ifndef NO_RSA
  13196. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13197. #ifdef WOLFSSL_KEY_GEN
  13198. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13199. #endif
  13200. e++;
  13201. #else
  13202. e += 2;
  13203. #endif
  13204. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13205. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13206. #endif
  13207. e++;
  13208. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13209. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13210. #endif
  13211. e++;
  13212. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13213. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13214. #endif
  13215. e++;
  13216. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13217. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13218. #endif
  13219. e++;
  13220. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13221. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13222. #endif
  13223. e++;
  13224. #if defined(HAVE_ECC)
  13225. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13226. #endif
  13227. e++;
  13228. #ifndef WOLFSSL_BENCHMARK_ALL
  13229. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13230. line = 0;
  13231. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13232. print_alg(bench_cipher_opt[i].str, &line);
  13233. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13234. print_alg(bench_digest_opt[i].str, &line);
  13235. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13236. print_alg(bench_mac_opt[i].str, &line);
  13237. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13238. print_alg(bench_kdf_opt[i].str, &line);
  13239. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13240. print_alg(bench_asym_opt[i].str, &line);
  13241. for (i=0; bench_other_opt[i].str != NULL; i++)
  13242. print_alg(bench_other_opt[i].str, &line);
  13243. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13244. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13245. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13246. print_alg(bench_pq_asym_opt[i].str, &line);
  13247. #if defined(HAVE_SPHINCS)
  13248. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13249. print_alg(bench_pq_asym_opt2[i].str, &line);
  13250. #endif /* HAVE_SPHINCS */
  13251. #endif
  13252. #if defined(BENCH_PQ_STATEFUL_HBS)
  13253. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13254. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13255. #endif /* BENCH_PQ_STATEFUL_HBS */
  13256. printf("\n");
  13257. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13258. e++;
  13259. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13260. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13261. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13262. #ifdef WC_ENABLE_BENCH_THREADING
  13263. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13264. #endif
  13265. e++;
  13266. #ifdef WC_BENCH_TRACK_STATS
  13267. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13268. #endif
  13269. e++;
  13270. #ifndef NO_FILESYSTEM
  13271. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13272. #endif
  13273. e++;
  13274. #ifndef NO_FILESYSTEM
  13275. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13276. #endif
  13277. #ifdef MULTI_VALUE_STATISTICS
  13278. e++;
  13279. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13280. #endif
  13281. }
  13282. /* Match the command line argument with the string.
  13283. *
  13284. * arg Command line argument.
  13285. * str String to check for.
  13286. * return 1 if the command line argument matches the string, 0 otherwise.
  13287. */
  13288. static int string_matches(const char* arg, const char* str)
  13289. {
  13290. return XSTRCMP(arg, str) == 0;
  13291. }
  13292. #endif /* MAIN_NO_ARGS */
  13293. /*
  13294. ** ----------------------------------------------------------------------------
  13295. ** determine how the benchmarks are called, the function name varies:
  13296. ** ----------------------------------------------------------------------------
  13297. */
  13298. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13299. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13300. /* for some environments, we'll call a function wolf_benchmark_task: */
  13301. int wolf_benchmark_task(void)
  13302. #elif defined(MAIN_NO_ARGS)
  13303. /* otherwise we'll use main() with no arguments as desired: */
  13304. int main()
  13305. #else
  13306. /* else we'll be calling main with default arg parameters */
  13307. int main(int argc, char** argv)
  13308. #endif
  13309. {
  13310. /* Code for main() or wolf_benchmark_task() */
  13311. #ifdef WOLFSSL_ESPIDF
  13312. int argc = construct_argv();
  13313. char** argv = (char**)__argv;
  13314. #elif defined(MAIN_NO_ARGS)
  13315. int argc = 0;
  13316. char** argv = NULL;
  13317. #endif
  13318. return wolfcrypt_benchmark_main(argc, argv);
  13319. }
  13320. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13321. int wolfcrypt_benchmark_main(int argc, char** argv)
  13322. {
  13323. int ret = 0;
  13324. #ifndef MAIN_NO_ARGS
  13325. int optMatched;
  13326. #ifndef WOLFSSL_BENCHMARK_ALL
  13327. int i;
  13328. #endif
  13329. #endif
  13330. benchmark_static_init(1);
  13331. printf("%s------------------------------------------------------------------------------\n",
  13332. info_prefix);
  13333. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13334. printf("%s------------------------------------------------------------------------------\n",
  13335. info_prefix);
  13336. #ifndef MAIN_NO_ARGS
  13337. while (argc > 1) {
  13338. if (string_matches(argv[1], "-?")) {
  13339. if (--argc > 1) {
  13340. lng_index = XATOI((++argv)[1]);
  13341. if (lng_index<0 || lng_index>1) {
  13342. lng_index = 0;
  13343. }
  13344. }
  13345. Usage();
  13346. return 0;
  13347. }
  13348. else if (string_matches(argv[1], "-lng")) {
  13349. argc--;
  13350. argv++;
  13351. if (argc > 1) {
  13352. lng_index = XATOI(argv[1]);
  13353. if (lng_index<0 || lng_index>1) {
  13354. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13355. lng_index);
  13356. lng_index = 0;
  13357. }
  13358. }
  13359. }
  13360. else if (string_matches(argv[1], "-base10"))
  13361. base2 = 0;
  13362. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13363. else if (string_matches(argv[1], "-no_aad"))
  13364. aes_aad_options = AAD_SIZE_ZERO;
  13365. else if (string_matches(argv[1], "-all_aad"))
  13366. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13367. else if (string_matches(argv[1], "-aad_size")) {
  13368. argc--;
  13369. argv++;
  13370. if (argc > 1) {
  13371. aes_aad_size = (word32)XATOI(argv[1]);
  13372. aes_aad_options |= AAD_SIZE_CUSTOM;
  13373. }
  13374. }
  13375. #endif
  13376. else if (string_matches(argv[1], "-dgst_full"))
  13377. digest_stream = 0;
  13378. #ifdef HAVE_CHACHA
  13379. else if (string_matches(argv[1], "-enc_only"))
  13380. encrypt_only = 1;
  13381. #endif
  13382. #ifndef NO_RSA
  13383. else if (string_matches(argv[1], "-rsa_sign"))
  13384. rsa_sign_verify = 1;
  13385. #endif
  13386. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13387. else if (string_matches(argv[1], "-ffdhe2048"))
  13388. use_ffdhe = 2048;
  13389. #endif
  13390. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13391. else if (string_matches(argv[1], "-ffdhe3072"))
  13392. use_ffdhe = 3072;
  13393. #endif
  13394. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13395. else if (string_matches(argv[1], "-ffdhe4096"))
  13396. use_ffdhe = 4096;
  13397. #endif
  13398. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13399. else if (string_matches(argv[1], "-p256"))
  13400. bench_asym_algs |= BENCH_ECC_P256;
  13401. #endif
  13402. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13403. else if (string_matches(argv[1], "-p384"))
  13404. bench_asym_algs |= BENCH_ECC_P384;
  13405. #endif
  13406. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13407. else if (string_matches(argv[1], "-p521"))
  13408. bench_asym_algs |= BENCH_ECC_P521;
  13409. #endif
  13410. #ifdef BENCH_ASYM
  13411. else if (string_matches(argv[1], "-csv")) {
  13412. csv_format = 1;
  13413. }
  13414. #endif
  13415. #ifdef WC_ENABLE_BENCH_THREADING
  13416. else if (string_matches(argv[1], "-threads")) {
  13417. argc--;
  13418. argv++;
  13419. if (argc > 1) {
  13420. g_threadCount = XATOI(argv[1]);
  13421. if (g_threadCount < 1 || lng_index > 128){
  13422. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13423. g_threadCount);
  13424. g_threadCount = 0;
  13425. }
  13426. }
  13427. }
  13428. #endif
  13429. #ifdef WC_BENCH_TRACK_STATS
  13430. else if (string_matches(argv[1], "-print")) {
  13431. gPrintStats = 1;
  13432. }
  13433. #endif
  13434. else if (string_matches(argv[1], "-blocks")) {
  13435. argc--;
  13436. argv++;
  13437. if (argc > 1)
  13438. numBlocks = XATOI(argv[1]);
  13439. }
  13440. #ifndef NO_FILESYSTEM
  13441. else if (string_matches(argv[1], "-hash_input")) {
  13442. argc--;
  13443. argv++;
  13444. if (argc > 1)
  13445. hash_input = argv[1];
  13446. }
  13447. else if (string_matches(argv[1], "-cipher_input")) {
  13448. argc--;
  13449. argv++;
  13450. if (argc > 1)
  13451. cipher_input = argv[1];
  13452. }
  13453. #endif
  13454. #ifdef MULTI_VALUE_STATISTICS
  13455. else if (string_matches(argv[1], "-min_runs")) {
  13456. argc--;
  13457. argv++;
  13458. if (argc > 1) {
  13459. minimum_runs = XATOI(argv[1]);
  13460. }
  13461. }
  13462. #endif
  13463. else if (argv[1][0] == '-') {
  13464. optMatched = 0;
  13465. #ifndef WOLFSSL_BENCHMARK_ALL
  13466. /* Check known algorithm choosing command line options. */
  13467. /* Known cipher algorithms */
  13468. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13469. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13470. bench_cipher_algs |= bench_cipher_opt[i].val;
  13471. bench_all = 0;
  13472. optMatched = 1;
  13473. }
  13474. }
  13475. /* Known digest algorithms */
  13476. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13477. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13478. bench_digest_algs |= bench_digest_opt[i].val;
  13479. bench_all = 0;
  13480. optMatched = 1;
  13481. }
  13482. }
  13483. /* Known MAC algorithms */
  13484. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13485. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13486. bench_mac_algs |= bench_mac_opt[i].val;
  13487. bench_all = 0;
  13488. optMatched = 1;
  13489. }
  13490. }
  13491. /* Known KDF algorithms */
  13492. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13493. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13494. bench_kdf_algs |= bench_kdf_opt[i].val;
  13495. bench_all = 0;
  13496. optMatched = 1;
  13497. }
  13498. }
  13499. /* Known asymmetric algorithms */
  13500. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13501. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13502. bench_asym_algs |= bench_asym_opt[i].val;
  13503. bench_all = 0;
  13504. optMatched = 1;
  13505. }
  13506. }
  13507. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13508. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13509. /* Known asymmetric post-quantum algorithms */
  13510. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13511. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13512. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13513. bench_all = 0;
  13514. optMatched = 1;
  13515. }
  13516. }
  13517. #ifdef HAVE_SPHINCS
  13518. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13519. * -pq, so we need to do a special case for -pq since optMatched
  13520. * was set to 1 just above. */
  13521. if ((bench_pq_asym_opt[0].str != NULL) &&
  13522. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13523. {
  13524. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13525. bench_all = 0;
  13526. optMatched = 1;
  13527. }
  13528. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13529. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13530. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13531. bench_all = 0;
  13532. optMatched = 1;
  13533. }
  13534. }
  13535. #endif
  13536. #endif
  13537. /* Other known cryptographic algorithms */
  13538. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13539. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13540. bench_other_algs |= bench_other_opt[i].val;
  13541. bench_all = 0;
  13542. optMatched = 1;
  13543. }
  13544. }
  13545. #if defined(BENCH_PQ_STATEFUL_HBS)
  13546. /* post-quantum stateful hash-based signatures */
  13547. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13548. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13549. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13550. bench_all = 0;
  13551. optMatched = 1;
  13552. }
  13553. }
  13554. #endif /* BENCH_PQ_STATEFUL_HBS */
  13555. #endif
  13556. if (!optMatched) {
  13557. printf("Option not recognized: %s\n", argv[1]);
  13558. Usage();
  13559. return 1;
  13560. }
  13561. }
  13562. else {
  13563. /* parse for block size */
  13564. benchmark_configure((word32)XATOI(argv[1]));
  13565. }
  13566. argc--;
  13567. argv++;
  13568. }
  13569. #endif /* MAIN_NO_ARGS */
  13570. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13571. /* when defined, we'll always output CSV regardless of params.
  13572. ** this is typically convenient in embedded environments.
  13573. */
  13574. csv_format = 1;
  13575. #endif
  13576. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13577. if (g_threadCount > 1) {
  13578. ret = benchmark_test_threaded(NULL);
  13579. }
  13580. else
  13581. #endif
  13582. {
  13583. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13584. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13585. defined(CONFIG_IDF_TARGET_ESP32C6)
  13586. {
  13587. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13588. if (esp_gptimer == NULL) {
  13589. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13590. &esp_gptimer) );
  13591. }
  13592. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13593. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13594. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13595. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13596. }
  13597. #endif
  13598. #ifdef HAVE_STACK_SIZE
  13599. ret = StackSizeCheck(NULL, benchmark_test);
  13600. #else
  13601. ret = benchmark_test(NULL);
  13602. #endif
  13603. }
  13604. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13605. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13606. defined(CONFIG_IDF_TARGET_ESP32C6)
  13607. {
  13608. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13609. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13610. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13611. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13612. }
  13613. #endif
  13614. return ret;
  13615. }
  13616. #endif /* !NO_MAIN_DRIVER */
  13617. #else
  13618. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13619. int main(void) { return 0; }
  13620. #endif
  13621. #endif /* !NO_CRYPT_BENCHMARK */