benchmark.c 516 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216
  1. /* benchmark.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* wolfCrypt benchmark */
  22. /* Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. * make the binary always use CSV format:
  26. * WOLFSSL_BENCHMARK_FIXED_CSV
  27. *
  28. * choose to use the same units, regardless of scale. pick 1:
  29. * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
  30. * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
  31. * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  32. * WOLFSSL_BENCHMARK_FIXED_UNITS_B
  33. *
  34. * when the output should be in machine-parseable format:
  35. * GENERATE_MACHINE_PARSEABLE_REPORT
  36. *
  37. * use microseconds as the unit of time:
  38. * BENCH_MICROSECOND
  39. *
  40. * display mean, max, min and sd of operation durations:
  41. * MULTI_VALUE_STATISTICS
  42. *
  43. * Enable tracking of the stats into an allocated linked list:
  44. * (use -print to display results):
  45. * WC_BENCH_TRACK_STATS
  46. *
  47. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  48. * WC_USE_DEVID=0x1234
  49. *
  50. * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  51. * DEBUG_WOLFSSL_BENCHMARK_TIMING
  52. *
  53. * Turn on timer debugging (used when CPU cycles not available)
  54. * WOLFSSL_BENCHMARK_TIMER_DEBUG
  55. */
  56. #ifdef HAVE_CONFIG_H
  57. #include <config.h>
  58. #endif
  59. #if !defined(WOLFSSL_USER_SETTINGS) && !defined(WOLFSSL_NO_OPTIONS_H)
  60. #include <wolfssl/options.h>
  61. #endif
  62. #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
  63. /* Macro to disable benchmark */
  64. #ifndef NO_CRYPT_BENCHMARK
  65. #define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
  66. #include <wolfssl/wolfcrypt/types.h>
  67. #include <wolfssl/wolfcrypt/wc_port.h>
  68. #include <wolfssl/wolfcrypt/wolfmath.h>
  69. #include <wolfssl/wolfcrypt/memory.h>
  70. #include <wolfssl/wolfcrypt/random.h>
  71. #include <wolfssl/wolfcrypt/error-crypt.h>
  72. #include <wolfssl/wolfcrypt/asn.h>
  73. #include <wolfssl/version.h>
  74. #ifdef WOLFSSL_LINUXKM
  75. /* remap current_time() -- collides with a function in kernel linux/fs.h */
  76. #define current_time benchmark_current_time
  77. #endif /* WOLFSSL_LINUXKM */
  78. #ifdef HAVE_CHACHA
  79. #include <wolfssl/wolfcrypt/chacha.h>
  80. #endif
  81. #ifdef HAVE_POLY1305
  82. #include <wolfssl/wolfcrypt/poly1305.h>
  83. #endif
  84. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  86. #endif
  87. #ifndef NO_AES
  88. #include <wolfssl/wolfcrypt/aes.h>
  89. #endif
  90. #ifdef HAVE_CAMELLIA
  91. #include <wolfssl/wolfcrypt/camellia.h>
  92. #endif
  93. #ifdef WOLFSSL_SM4
  94. #include <wolfssl/wolfcrypt/sm4.h>
  95. #endif
  96. #ifndef NO_MD5
  97. #include <wolfssl/wolfcrypt/md5.h>
  98. #endif
  99. #ifndef NO_SHA
  100. #include <wolfssl/wolfcrypt/sha.h>
  101. #endif
  102. #ifndef NO_SHA256
  103. #include <wolfssl/wolfcrypt/sha256.h>
  104. #endif
  105. #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
  106. #include <wolfssl/wolfcrypt/sha512.h>
  107. #endif
  108. #ifdef WOLFSSL_SHA3
  109. #include <wolfssl/wolfcrypt/sha3.h>
  110. #endif
  111. #ifdef WOLFSSL_SM3
  112. #include <wolfssl/wolfcrypt/sm3.h>
  113. #endif
  114. #ifndef NO_RSA
  115. #include <wolfssl/wolfcrypt/rsa.h>
  116. #endif
  117. #ifdef WOLFSSL_RIPEMD
  118. #include <wolfssl/wolfcrypt/ripemd.h>
  119. #endif
  120. #ifdef WOLFSSL_CMAC
  121. #include <wolfssl/wolfcrypt/cmac.h>
  122. #endif
  123. #ifndef NO_DH
  124. #include <wolfssl/wolfcrypt/dh.h>
  125. #endif
  126. #ifndef NO_DES3
  127. #include <wolfssl/wolfcrypt/des3.h>
  128. #endif
  129. #ifndef NO_RC4
  130. #include <wolfssl/wolfcrypt/arc4.h>
  131. #endif
  132. #ifndef NO_HMAC
  133. #include <wolfssl/wolfcrypt/hmac.h>
  134. #endif
  135. #ifdef WOLFSSL_SIPHASH
  136. #include <wolfssl/wolfcrypt/siphash.h>
  137. #endif
  138. #include <wolfssl/wolfcrypt/kdf.h>
  139. #ifndef NO_PWDBASED
  140. #include <wolfssl/wolfcrypt/pwdbased.h>
  141. #endif
  142. #ifdef HAVE_ECC
  143. #include <wolfssl/wolfcrypt/ecc.h>
  144. #endif
  145. #ifdef WOLFSSL_SM2
  146. #include <wolfssl/wolfcrypt/sm2.h>
  147. #endif
  148. #ifdef HAVE_CURVE25519
  149. #include <wolfssl/wolfcrypt/curve25519.h>
  150. #endif
  151. #ifdef HAVE_ED25519
  152. #include <wolfssl/wolfcrypt/ed25519.h>
  153. #endif
  154. #ifdef HAVE_CURVE448
  155. #include <wolfssl/wolfcrypt/curve448.h>
  156. #endif
  157. #ifdef HAVE_ED448
  158. #include <wolfssl/wolfcrypt/ed448.h>
  159. #endif
  160. #ifdef WOLFSSL_HAVE_KYBER
  161. #include <wolfssl/wolfcrypt/kyber.h>
  162. #ifdef WOLFSSL_WC_KYBER
  163. #include <wolfssl/wolfcrypt/wc_kyber.h>
  164. #endif
  165. #if defined(HAVE_LIBOQS)
  166. #include <wolfssl/wolfcrypt/ext_kyber.h>
  167. #endif
  168. #endif
  169. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  170. #include <wolfssl/wolfcrypt/lms.h>
  171. #ifdef HAVE_LIBLMS
  172. #include <wolfssl/wolfcrypt/ext_lms.h>
  173. #else
  174. #include <wolfssl/wolfcrypt/wc_lms.h>
  175. #endif
  176. #endif
  177. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  178. #include <wolfssl/wolfcrypt/xmss.h>
  179. #ifdef HAVE_LIBXMSS
  180. #include <wolfssl/wolfcrypt/ext_xmss.h>
  181. #else
  182. #include <wolfssl/wolfcrypt/wc_xmss.h>
  183. #endif
  184. #endif
  185. #ifdef WOLFCRYPT_HAVE_ECCSI
  186. #include <wolfssl/wolfcrypt/eccsi.h>
  187. #endif
  188. #ifdef WOLFCRYPT_HAVE_SAKKE
  189. #include <wolfssl/wolfcrypt/sakke.h>
  190. #endif
  191. #if defined(HAVE_FALCON)
  192. #include <wolfssl/wolfcrypt/falcon.h>
  193. #endif
  194. #if defined(HAVE_DILITHIUM)
  195. #include <wolfssl/wolfcrypt/dilithium.h>
  196. #endif
  197. #if defined(HAVE_SPHINCS)
  198. #include <wolfssl/wolfcrypt/sphincs.h>
  199. #endif
  200. #ifdef WOLF_CRYPTO_CB
  201. #include <wolfssl/wolfcrypt/cryptocb.h>
  202. #ifdef HAVE_INTEL_QA_SYNC
  203. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  204. #endif
  205. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  206. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  207. #endif
  208. #ifdef HAVE_RENESAS_SYNC
  209. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  210. #endif
  211. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  212. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  213. #endif
  214. #endif
  215. #ifdef WOLFSSL_ASYNC_CRYPT
  216. #include <wolfssl/wolfcrypt/async.h>
  217. #endif
  218. #ifdef USE_FLAT_BENCHMARK_H
  219. #include "benchmark.h"
  220. #else
  221. #include "wolfcrypt/benchmark/benchmark.h"
  222. #endif
  223. /* define the max length for each string of metric reported */
  224. #ifndef WC_BENCH_MAX_LINE_LEN
  225. #define WC_BENCH_MAX_LINE_LEN 150
  226. #endif
  227. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  228. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  229. #define MILLION_VALUE 1000000.0
  230. #ifdef BENCH_MICROSECOND
  231. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  232. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  233. #else
  234. #define WOLFSSL_FIXED_TIME_UNIT "s"
  235. #endif
  236. #ifdef MULTI_VALUE_STATISTICS
  237. #define STATS_CLAUSE_SEPARATOR ""
  238. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  239. squareSum = 0, prev = 0, delta;\
  240. int runs = 0;
  241. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  242. delta = current_time(0) - start;\
  243. min = delta;\
  244. max = delta;\
  245. }\
  246. else {\
  247. delta = current_time(0) - prev;\
  248. }\
  249. if (max < delta)\
  250. max = delta;\
  251. else if (min > delta)\
  252. min = delta;\
  253. sum += delta;\
  254. squareSum += delta * delta;\
  255. runs++;\
  256. prev = current_time(0)
  257. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  258. runs = 0;\
  259. sum = 0;\
  260. squareSum = 0
  261. #else
  262. #define STATS_CLAUSE_SEPARATOR "\n"
  263. #define DECLARE_MULTI_VALUE_STATS_VARS()
  264. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  265. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  266. #endif
  267. #ifdef WOLFSSL_NO_FLOAT_FMT
  268. #define FLT_FMT "%0ld,%09lu"
  269. #define FLT_FMT_PREC "%0ld.%0*lu"
  270. #define FLT_FMT_PREC2 FLT_FMT_PREC
  271. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  272. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  273. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  274. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  275. 10000.0, 100000.0, 1000000.0, \
  276. 10000000.0, 100000000.0, \
  277. 1000000000.0 };
  278. #define FLT_FMT_PREC_ARGS(p, x) \
  279. (long)(x), \
  280. p, \
  281. (x) >= 0.0 ? \
  282. (unsigned long int)((((x) - (double)(long)(x)) * \
  283. pow_10_array[(p)+1]) + 0.5) : \
  284. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  285. pow_10_array[(p)+1]) + 0.5)
  286. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  287. #else
  288. #define FLT_FMT "%f"
  289. #define FLT_FMT_PREC "%.*f"
  290. #define FLT_FMT_PREC2 "%*.*f"
  291. #define FLT_FMT_ARGS(x) x
  292. #define FLT_FMT_PREC_ARGS(p, x) p, x
  293. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  294. #endif /* WOLFSSL_NO_FLOAT_FMT */
  295. #ifdef WOLFSSL_ESPIDF
  296. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  297. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  298. * enabled, all if the values in report are blank. */
  299. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  300. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  301. #error "Nano newlib formatting must not be enabled for benchmark"
  302. #endif
  303. #endif
  304. #if ESP_IDF_VERSION_MAJOR >= 5
  305. #define TFMT "%lu"
  306. #else
  307. #define TFMT "%d"
  308. #endif
  309. #ifdef configTICK_RATE_HZ
  310. /* Define CPU clock cycles per tick of FreeRTOS clock
  311. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  312. * configTICK_RATE_HZ is typically 100 or 1000.
  313. **/
  314. #if defined(CONFIG_IDF_TARGET_ESP8266)
  315. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  316. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  317. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  318. #endif
  319. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  320. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  321. #endif
  322. #endif
  323. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  324. /* This section is for pre-v5 ESP-IDF */
  325. #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  326. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  327. CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
  328. #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
  329. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  330. CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
  331. #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
  332. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  333. CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
  334. #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
  335. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  336. CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
  337. #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
  338. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  339. CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
  340. #else
  341. /* TODO unsupported */
  342. #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
  343. #endif
  344. #define CPU_TICK_CYCLES ( \
  345. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  346. / configTICK_RATE_HZ \
  347. )
  348. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  349. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  350. #include "driver/gptimer.h"
  351. static gptimer_handle_t esp_gptimer = NULL;
  352. static gptimer_config_t esp_timer_config = {
  353. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  354. .direction = GPTIMER_COUNT_UP,
  355. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  356. };
  357. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  358. defined(CONFIG_IDF_TARGET_ESP32C6)
  359. #include <esp_cpu.h>
  360. #if ESP_IDF_VERSION_MAJOR >= 5
  361. #include <driver/gptimer.h>
  362. #endif
  363. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  364. #define RESOLUTION_SCALE 100
  365. /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  366. static gptimer_handle_t esp_gptimer = NULL;
  367. static gptimer_config_t esp_timer_config = {
  368. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  369. .direction = GPTIMER_COUNT_UP,
  370. /* CONFIG_XTAL_FREQ = 40,
  371. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  372. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  373. (MILLION_VALUE / RESOLUTION_SCALE),
  374. };
  375. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  376. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  377. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  378. defined(CONFIG_IDF_TARGET_ESP32S3)
  379. #include <xtensa/hal.h>
  380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  381. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  382. #include <FreeRTOS.h>
  383. #include <esp_system.h>
  384. #include <esp_timer.h>
  385. #include <xtensa/hal.h>
  386. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  387. /* TODO add ESP32-H2 benchmark support */
  388. #else
  389. /* Other platform */
  390. #endif
  391. #include <esp_log.h>
  392. #endif /* WOLFSSL_ESPIDF */
  393. #if defined(HAVE_PTHREAD) || \
  394. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  395. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  396. !defined(BENCH_EMBEDDED))
  397. #include <errno.h>
  398. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  399. #include <unistd.h>
  400. #endif
  401. #endif
  402. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  403. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  404. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  405. #undef XFFLUSH
  406. #define XFFLUSH(...) WC_DO_NOTHING
  407. #endif
  408. /* only for stack size check */
  409. #include <wolfssl/wolfcrypt/mem_track.h>
  410. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  411. #define WC_ENABLE_BENCH_THREADING
  412. #endif
  413. /* enable tracking of stats for threaded benchmark */
  414. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  415. #define WC_BENCH_TRACK_STATS
  416. #endif
  417. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  418. static const char info_prefix[] = "###, ";
  419. static const char err_prefix[] = "!!!, ";
  420. #else
  421. static const char info_prefix[] = "";
  422. static const char err_prefix[] = "";
  423. #endif
  424. /* printf mappings */
  425. #ifdef FREESCALE_MQX
  426. #include <mqx.h>
  427. /* see wc_port.h for fio.h and nio.h includes */
  428. #elif defined(FREESCALE_KSDK_1_3)
  429. #include "fsl_debug_console.h"
  430. #include "fsl_os_abstraction.h"
  431. #undef printf
  432. #define printf PRINTF
  433. #elif defined(WOLFSSL_DEOS)
  434. #include <deos.h>
  435. #include <printx.h>
  436. #undef printf
  437. #define printf printx
  438. #elif defined(MICRIUM)
  439. #if (OS_VERSION < 50000)
  440. #include <bsp_ser.h>
  441. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  442. #undef printf
  443. #define printf BSP_Ser_Printf
  444. #endif
  445. #elif defined(WOLFSSL_ZEPHYR)
  446. #include <stdio.h>
  447. #include <stdarg.h>
  448. #define BENCH_EMBEDDED
  449. #define printf printfk
  450. static int printfk(const char *fmt, ...)
  451. {
  452. int ret;
  453. char line[WC_BENCH_MAX_LINE_LEN];
  454. va_list ap;
  455. va_start(ap, fmt);
  456. ret = vsnprintf(line, sizeof(line), fmt, ap);
  457. line[sizeof(line)-1] = '\0';
  458. printk("%s", line);
  459. va_end(ap);
  460. return ret;
  461. }
  462. #elif defined(WOLFSSL_TELIT_M2MB)
  463. #include <stdarg.h>
  464. #include <stdio.h>
  465. #include <string.h>
  466. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  467. /* remap printf */
  468. #undef printf
  469. #define printf M2M_LOG_INFO
  470. /* OS requires occasional sleep() */
  471. #ifndef TEST_SLEEP_MS
  472. #define TEST_SLEEP_MS 50
  473. #endif
  474. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  475. /* don't use file system for these tests, since ./certs dir isn't loaded */
  476. #undef NO_FILESYSTEM
  477. #define NO_FILESYSTEM
  478. /* ANDROID_V454 (for android studio) displays information in a textview
  479. * and redirects printf to the textview output instead of using
  480. * __android_log_print() */
  481. #elif defined(ANDROID) && !defined(ANDROID_V454)
  482. #ifdef XMALLOC_USER
  483. #include <stdlib.h> /* we're using malloc / free direct here */
  484. #endif
  485. #ifndef STRING_USER
  486. #include <stdio.h>
  487. #endif
  488. #include <android/log.h>
  489. #define printf(...) \
  490. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  491. #define fprintf(fp, ...) \
  492. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  493. #else
  494. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  495. /* MQX classic needs for EXIT_FAILURE */
  496. #include <stdlib.h> /* we're using malloc / free direct here */
  497. #endif
  498. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  499. #include <string.h>
  500. #include <stdio.h>
  501. #endif
  502. /* enable way for customer to override test/bench printf */
  503. #ifdef XPRINTF
  504. #undef printf
  505. #define printf XPRINTF
  506. #elif defined(NETOS)
  507. #undef printf
  508. #define printf dc_log_printf
  509. #endif
  510. #endif
  511. #ifdef HAVE_FIPS
  512. #include <wolfssl/wolfcrypt/fips_test.h>
  513. static void myFipsCb(int ok, int err, const char* hash)
  514. {
  515. printf("%sin my Fips callback, ok = %d, err = %d\n",
  516. ok ? info_prefix : err_prefix, ok, err);
  517. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  518. wc_GetErrorString(err));
  519. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  520. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  521. printf("%sIn core integrity hash check failure, copy above hash\n",
  522. err_prefix);
  523. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  524. err_prefix);
  525. }
  526. }
  527. #endif
  528. #ifdef WOLFSSL_STATIC_MEMORY
  529. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  530. #else
  531. #define HEAP_HINT NULL
  532. #endif /* WOLFSSL_STATIC_MEMORY */
  533. #ifndef EXIT_FAILURE
  534. #define EXIT_FAILURE 1
  535. #endif
  536. #undef LIBCALL_CHECK_RET
  537. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  538. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  539. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  540. #else
  541. #define LIBCALL_CHECK_RET(...) do { \
  542. int _libcall_ret = (__VA_ARGS__); \
  543. if (_libcall_ret < 0) { \
  544. printf("%s%s L%d error %d for \"%s\"\n", \
  545. err_prefix, __FILE__, __LINE__, \
  546. errno, #__VA_ARGS__); \
  547. XFFLUSH(stdout); \
  548. _exit(1); \
  549. } \
  550. } while(0)
  551. #endif
  552. #undef THREAD_CHECK_RET
  553. #define THREAD_CHECK_RET(...) do { \
  554. int _thread_ret = (__VA_ARGS__); \
  555. if (_thread_ret != 0) { \
  556. errno = _thread_ret; \
  557. printf("%s%s L%d error %d for \"%s\"\n", \
  558. err_prefix, __FILE__, __LINE__, \
  559. _thread_ret, #__VA_ARGS__); \
  560. XFFLUSH(stdout); \
  561. _exit(1); \
  562. } \
  563. } while(0)
  564. /* optional macro to add sleep between tests */
  565. #ifndef TEST_SLEEP
  566. /* stub the sleep macro */
  567. #define TEST_SLEEP() WC_DO_NOTHING
  568. #endif
  569. #define TEST_STRING "Everyone gets Friday off."
  570. #define TEST_STRING_SZ 25
  571. /* Bit values for each algorithm that is able to be benchmarked.
  572. * Common grouping of algorithms also.
  573. * Each algorithm has a unique value for its type e.g. cipher.
  574. */
  575. /* Cipher algorithms. */
  576. #define BENCH_AES_CBC 0x00000001
  577. #define BENCH_AES_GCM 0x00000002
  578. #define BENCH_AES_ECB 0x00000004
  579. #define BENCH_AES_XTS 0x00000008
  580. #define BENCH_AES_CTR 0x00000010
  581. #define BENCH_AES_CCM 0x00000020
  582. #define BENCH_CAMELLIA 0x00000100
  583. #define BENCH_ARC4 0x00000200
  584. #define BENCH_CHACHA20 0x00001000
  585. #define BENCH_CHACHA20_POLY1305 0x00002000
  586. #define BENCH_DES 0x00004000
  587. #define BENCH_AES_CFB 0x00010000
  588. #define BENCH_AES_OFB 0x00020000
  589. #define BENCH_AES_SIV 0x00040000
  590. #define BENCH_SM4_CBC 0x00080000
  591. #define BENCH_SM4_GCM 0x00100000
  592. #define BENCH_SM4_CCM 0x00200000
  593. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  594. /* Digest algorithms. */
  595. #define BENCH_MD5 0x00000001
  596. #define BENCH_POLY1305 0x00000002
  597. #define BENCH_SHA 0x00000004
  598. #define BENCH_SHA224 0x00000010
  599. #define BENCH_SHA256 0x00000020
  600. #define BENCH_SHA384 0x00000040
  601. #define BENCH_SHA512 0x00000080
  602. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  603. BENCH_SHA384 | BENCH_SHA512)
  604. #define BENCH_SHA3_224 0x00000100
  605. #define BENCH_SHA3_256 0x00000200
  606. #define BENCH_SHA3_384 0x00000400
  607. #define BENCH_SHA3_512 0x00000800
  608. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  609. BENCH_SHA3_384 | BENCH_SHA3_512)
  610. #define BENCH_SHAKE128 0x00001000
  611. #define BENCH_SHAKE256 0x00002000
  612. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  613. #define BENCH_RIPEMD 0x00004000
  614. #define BENCH_BLAKE2B 0x00008000
  615. #define BENCH_BLAKE2S 0x00010000
  616. #define BENCH_SM3 0x00020000
  617. /* MAC algorithms. */
  618. #define BENCH_CMAC 0x00000001
  619. #define BENCH_HMAC_MD5 0x00000002
  620. #define BENCH_HMAC_SHA 0x00000004
  621. #define BENCH_HMAC_SHA224 0x00000010
  622. #define BENCH_HMAC_SHA256 0x00000020
  623. #define BENCH_HMAC_SHA384 0x00000040
  624. #define BENCH_HMAC_SHA512 0x00000080
  625. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  626. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  627. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  628. #define BENCH_PBKDF2 0x00000100
  629. #define BENCH_SIPHASH 0x00000200
  630. /* KDF algorithms */
  631. #define BENCH_SRTP_KDF 0x00000001
  632. /* Asymmetric algorithms. */
  633. #define BENCH_RSA_KEYGEN 0x00000001
  634. #define BENCH_RSA 0x00000002
  635. #define BENCH_RSA_SZ 0x00000004
  636. #define BENCH_DH 0x00000010
  637. #define BENCH_ECC_MAKEKEY 0x00001000
  638. #define BENCH_ECC 0x00002000
  639. #define BENCH_ECC_ENCRYPT 0x00004000
  640. #define BENCH_ECC_ALL 0x00008000
  641. #define BENCH_CURVE25519_KEYGEN 0x00010000
  642. #define BENCH_CURVE25519_KA 0x00020000
  643. #define BENCH_ED25519_KEYGEN 0x00040000
  644. #define BENCH_ED25519_SIGN 0x00080000
  645. #define BENCH_CURVE448_KEYGEN 0x00100000
  646. #define BENCH_CURVE448_KA 0x00200000
  647. #define BENCH_ED448_KEYGEN 0x00400000
  648. #define BENCH_ED448_SIGN 0x00800000
  649. #define BENCH_ECC_P256 0x01000000
  650. #define BENCH_ECC_P384 0x02000000
  651. #define BENCH_ECC_P521 0x04000000
  652. #define BENCH_SM2 0x08000000
  653. #define BENCH_ECCSI_KEYGEN 0x00000020
  654. #define BENCH_ECCSI_PAIRGEN 0x00000040
  655. #define BENCH_ECCSI_VALIDATE 0x00000080
  656. #define BENCH_ECCSI 0x00000400
  657. #define BENCH_SAKKE_KEYGEN 0x10000000
  658. #define BENCH_SAKKE_RSKGEN 0x20000000
  659. #define BENCH_SAKKE_VALIDATE 0x40000000
  660. #define BENCH_SAKKE 0x80000000
  661. /* Post-Quantum Asymmetric algorithms. */
  662. #define BENCH_KYBER512 0x00000020
  663. #define BENCH_KYBER768 0x00000040
  664. #define BENCH_KYBER1024 0x00000080
  665. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  666. BENCH_KYBER1024)
  667. #define BENCH_ML_KEM_512 0x00000020
  668. #define BENCH_ML_KEM_768 0x00000040
  669. #define BENCH_ML_KEM_1024 0x00000080
  670. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  671. BENCH_ML_KEM_1024)
  672. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  673. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  674. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  675. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  676. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  677. #define BENCH_ML_DSA_44_SIGN 0x04000000
  678. #define BENCH_ML_DSA_65_SIGN 0x08000000
  679. #define BENCH_ML_DSA_87_SIGN 0x10000000
  680. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  681. BENCH_ML_DSA_65_SIGN | \
  682. BENCH_ML_DSA_87_SIGN)
  683. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  684. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  685. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  686. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  687. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  688. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  689. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  690. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  691. #define BENCH_LMS_HSS 0x00000001
  692. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  693. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  694. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  695. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  696. #ifndef NO_SHA256
  697. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  698. #elif defined(WOLFSSL_SHA512)
  699. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  700. #elif defined(WOLFSSL_SHAKE128)
  701. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  702. #elif defined(WOLFSSL_SHAKE256)
  703. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  704. #else
  705. #define BENCH_XMSS_XMSSMT 0x00000000
  706. #endif
  707. /* Other */
  708. #define BENCH_RNG 0x00000001
  709. #define BENCH_SCRYPT 0x00000002
  710. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  711. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  712. * static declaration of `bench_Usage_msg1`. */
  713. #if !defined(AES_AUTH_ADD_SZ) && \
  714. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  715. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  716. /* For STM32 use multiple of 4 to leverage crypto hardware
  717. * Xilinx Versal requires to use multiples of 16 bytes */
  718. #define AES_AUTH_ADD_SZ 16
  719. #endif
  720. #ifndef AES_AUTH_ADD_SZ
  721. #define AES_AUTH_ADD_SZ 13
  722. #endif
  723. #endif
  724. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  725. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  726. #define BENCH_PQ_STATEFUL_HBS
  727. #endif
  728. /* Benchmark all compiled in algorithms.
  729. * When 1, ignore other benchmark algorithm values.
  730. * 0, only benchmark algorithm values set.
  731. */
  732. static int bench_all = 1;
  733. /* Cipher algorithms to benchmark. */
  734. static word32 bench_cipher_algs = 0;
  735. /* Digest algorithms to benchmark. */
  736. static word32 bench_digest_algs = 0;
  737. /* MAC algorithms to benchmark. */
  738. static word32 bench_mac_algs = 0;
  739. /* KDF algorithms to benchmark. */
  740. static word32 bench_kdf_algs = 0;
  741. /* Asymmetric algorithms to benchmark. */
  742. static word32 bench_asym_algs = 0;
  743. /* Post-Quantum Asymmetric algorithms to benchmark. */
  744. static word32 bench_pq_asym_algs = 0;
  745. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  746. static word32 bench_pq_asym_algs2 = 0;
  747. /* Other cryptographic algorithms to benchmark. */
  748. static word32 bench_other_algs = 0;
  749. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  750. static word32 bench_pq_hash_sig_algs = 0;
  751. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  752. /* The mapping of command line option to bit values. */
  753. typedef struct bench_alg {
  754. /* Command line option string. */
  755. const char* str;
  756. /* Bit values to set. */
  757. word32 val;
  758. } bench_alg;
  759. #ifndef MAIN_NO_ARGS
  760. /* All recognized cipher algorithm choosing command line options. */
  761. static const bench_alg bench_cipher_opt[] = {
  762. { "-cipher", 0xffffffff },
  763. #ifdef HAVE_AES_CBC
  764. { "-aes-cbc", BENCH_AES_CBC },
  765. #endif
  766. #ifdef HAVE_AESGCM
  767. { "-aes-gcm", BENCH_AES_GCM },
  768. #endif
  769. #ifdef WOLFSSL_AES_DIRECT
  770. { "-aes-ecb", BENCH_AES_ECB },
  771. #endif
  772. #ifdef WOLFSSL_AES_XTS
  773. { "-aes-xts", BENCH_AES_XTS },
  774. #endif
  775. #ifdef WOLFSSL_AES_CFB
  776. { "-aes-cfb", BENCH_AES_CFB },
  777. #endif
  778. #ifdef WOLFSSL_AES_OFB
  779. { "-aes-ofb", BENCH_AES_OFB },
  780. #endif
  781. #ifdef WOLFSSL_AES_COUNTER
  782. { "-aes-ctr", BENCH_AES_CTR },
  783. #endif
  784. #ifdef HAVE_AESCCM
  785. { "-aes-ccm", BENCH_AES_CCM },
  786. #endif
  787. #ifdef WOLFSSL_AES_SIV
  788. { "-aes-siv", BENCH_AES_SIV },
  789. #endif
  790. #ifdef HAVE_CAMELLIA
  791. { "-camellia", BENCH_CAMELLIA },
  792. #endif
  793. #ifndef NO_RC4
  794. { "-arc4", BENCH_ARC4 },
  795. #endif
  796. #ifdef HAVE_CHACHA
  797. { "-chacha20", BENCH_CHACHA20 },
  798. #endif
  799. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  800. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  801. #endif
  802. #ifdef WOLFSSL_SM4_CBC
  803. { "-sm4-cbc", BENCH_SM4_CBC },
  804. #endif
  805. #ifdef WOLFSSL_SM4_GCM
  806. { "-sm4-gcm", BENCH_SM4_GCM },
  807. #endif
  808. #ifdef WOLFSSL_SM4_CCM
  809. { "-sm4-ccm", BENCH_SM4_CCM },
  810. #endif
  811. #ifdef WOLFSSL_SM4
  812. { "-sm4", BENCH_SM4 },
  813. #endif
  814. #ifndef NO_DES3
  815. { "-des", BENCH_DES },
  816. #endif
  817. { NULL, 0 }
  818. };
  819. /* All recognized digest algorithm choosing command line options. */
  820. static const bench_alg bench_digest_opt[] = {
  821. { "-digest", 0xffffffff },
  822. #ifndef NO_MD5
  823. { "-md5", BENCH_MD5 },
  824. #endif
  825. #ifdef HAVE_POLY1305
  826. { "-poly1305", BENCH_POLY1305 },
  827. #endif
  828. #ifndef NO_SHA
  829. { "-sha", BENCH_SHA },
  830. #endif
  831. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  832. || defined(WOLFSSL_SHA512)
  833. { "-sha2", BENCH_SHA2 },
  834. #endif
  835. #ifdef WOLFSSL_SHA224
  836. { "-sha224", BENCH_SHA224 },
  837. #endif
  838. #ifndef NO_SHA256
  839. { "-sha256", BENCH_SHA256 },
  840. #endif
  841. #ifdef WOLFSSL_SHA384
  842. { "-sha384", BENCH_SHA384 },
  843. #endif
  844. #ifdef WOLFSSL_SHA512
  845. { "-sha512", BENCH_SHA512 },
  846. #endif
  847. #ifdef WOLFSSL_SHA3
  848. { "-sha3", BENCH_SHA3 },
  849. #ifndef WOLFSSL_NOSHA3_224
  850. { "-sha3-224", BENCH_SHA3_224 },
  851. #endif
  852. #ifndef WOLFSSL_NOSHA3_256
  853. { "-sha3-256", BENCH_SHA3_256 },
  854. #endif
  855. #ifndef WOLFSSL_NOSHA3_384
  856. { "-sha3-384", BENCH_SHA3_384 },
  857. #endif
  858. #ifndef WOLFSSL_NOSHA3_512
  859. { "-sha3-512", BENCH_SHA3_512 },
  860. #endif
  861. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  862. { "-shake", BENCH_SHAKE },
  863. #endif
  864. #ifdef WOLFSSL_SHAKE128
  865. { "-shake128", BENCH_SHAKE128 },
  866. #endif
  867. #ifdef WOLFSSL_SHAKE256
  868. { "-shake256", BENCH_SHAKE256 },
  869. #endif
  870. #endif
  871. #ifdef WOLFSSL_SM3
  872. { "-sm3", BENCH_SM3 },
  873. #endif
  874. #ifdef WOLFSSL_RIPEMD
  875. { "-ripemd", BENCH_RIPEMD },
  876. #endif
  877. #ifdef HAVE_BLAKE2
  878. { "-blake2b", BENCH_BLAKE2B },
  879. #endif
  880. #ifdef HAVE_BLAKE2S
  881. { "-blake2s", BENCH_BLAKE2S },
  882. #endif
  883. { NULL, 0 }
  884. };
  885. /* All recognized MAC algorithm choosing command line options. */
  886. static const bench_alg bench_mac_opt[] = {
  887. { "-mac", 0xffffffff },
  888. #ifdef WOLFSSL_CMAC
  889. { "-cmac", BENCH_CMAC },
  890. #endif
  891. #ifndef NO_HMAC
  892. { "-hmac", BENCH_HMAC },
  893. #ifndef NO_MD5
  894. { "-hmac-md5", BENCH_HMAC_MD5 },
  895. #endif
  896. #ifndef NO_SHA
  897. { "-hmac-sha", BENCH_HMAC_SHA },
  898. #endif
  899. #ifdef WOLFSSL_SHA224
  900. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  901. #endif
  902. #ifndef NO_SHA256
  903. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  904. #endif
  905. #ifdef WOLFSSL_SHA384
  906. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  907. #endif
  908. #ifdef WOLFSSL_SHA512
  909. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  910. #endif
  911. #ifndef NO_PWDBASED
  912. { "-pbkdf2", BENCH_PBKDF2 },
  913. #endif
  914. #endif
  915. #ifdef WOLFSSL_SIPHASH
  916. { "-siphash", BENCH_SIPHASH },
  917. #endif
  918. { NULL, 0 }
  919. };
  920. /* All recognized KDF algorithm choosing command line options. */
  921. static const bench_alg bench_kdf_opt[] = {
  922. { "-kdf", 0xffffffff },
  923. #ifdef WC_SRTP_KDF
  924. { "-srtp-kdf", BENCH_SRTP_KDF },
  925. #endif
  926. { NULL, 0 }
  927. };
  928. /* All recognized asymmetric algorithm choosing command line options. */
  929. static const bench_alg bench_asym_opt[] = {
  930. { "-asym", 0xffffffff },
  931. #ifndef NO_RSA
  932. #ifdef WOLFSSL_KEY_GEN
  933. { "-rsa-kg", BENCH_RSA_KEYGEN },
  934. #endif
  935. { "-rsa", BENCH_RSA },
  936. #ifdef WOLFSSL_KEY_GEN
  937. { "-rsa-sz", BENCH_RSA_SZ },
  938. #endif
  939. #endif
  940. #ifndef NO_DH
  941. { "-dh", BENCH_DH },
  942. #endif
  943. #ifdef HAVE_ECC
  944. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  945. { "-ecc", BENCH_ECC },
  946. #ifdef HAVE_ECC_ENCRYPT
  947. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  948. #endif
  949. { "-ecc-all", BENCH_ECC_ALL },
  950. #endif
  951. #ifdef WOLFSSL_SM2
  952. { "-sm2", BENCH_SM2 },
  953. #endif
  954. #ifdef HAVE_CURVE25519
  955. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  956. #ifdef HAVE_CURVE25519_SHARED_SECRET
  957. { "-x25519", BENCH_CURVE25519_KA },
  958. #endif
  959. #endif
  960. #ifdef HAVE_ED25519
  961. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  962. { "-ed25519", BENCH_ED25519_SIGN },
  963. #endif
  964. #ifdef HAVE_CURVE448
  965. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  966. #ifdef HAVE_CURVE448_SHARED_SECRET
  967. { "-x448", BENCH_CURVE448_KA },
  968. #endif
  969. #endif
  970. #ifdef HAVE_ED448
  971. { "-ed448-kg", BENCH_ED448_KEYGEN },
  972. { "-ed448", BENCH_ED448_SIGN },
  973. #endif
  974. #ifdef WOLFCRYPT_HAVE_ECCSI
  975. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  976. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  977. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  978. { "-eccsi", BENCH_ECCSI },
  979. #endif
  980. #ifdef WOLFCRYPT_HAVE_SAKKE
  981. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  982. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  983. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  984. { "-sakke", BENCH_SAKKE },
  985. #endif
  986. { NULL, 0 }
  987. };
  988. /* All recognized other cryptographic algorithm choosing command line options.
  989. */
  990. static const bench_alg bench_other_opt[] = {
  991. { "-other", 0xffffffff },
  992. #ifndef WC_NO_RNG
  993. { "-rng", BENCH_RNG },
  994. #endif
  995. #ifdef HAVE_SCRYPT
  996. { "-scrypt", BENCH_SCRYPT },
  997. #endif
  998. { NULL, 0}
  999. };
  1000. #endif /* MAIN_NO_ARGS */
  1001. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  1002. #if defined(BENCH_PQ_STATEFUL_HBS)
  1003. typedef struct bench_pq_hash_sig_alg {
  1004. /* Command line option string. */
  1005. const char* str;
  1006. /* Bit values to set. */
  1007. word32 val;
  1008. } bench_pq_hash_sig_alg;
  1009. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  1010. { "-pq_hash_sig", 0xffffffff},
  1011. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  1012. { "-lms_hss", BENCH_LMS_HSS},
  1013. #endif
  1014. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  1015. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  1016. #ifdef WC_XMSS_SHA256
  1017. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  1018. #endif
  1019. #ifdef WC_XMSS_SHA512
  1020. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  1021. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  1022. #endif
  1023. #endif
  1024. #ifdef WC_XMSS_SHAKE128
  1025. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  1026. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  1027. #endif
  1028. #endif
  1029. #ifdef WC_XMSS_SHAKE256
  1030. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  1031. #endif
  1032. #endif
  1033. { NULL, 0}
  1034. };
  1035. #endif /* BENCH_PQ_STATEFUL_HBS */
  1036. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1037. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1038. /* The post-quantum-specific mapping of command line option to bit values and
  1039. * OQS name. */
  1040. typedef struct bench_pq_alg {
  1041. /* Command line option string. */
  1042. const char* str;
  1043. /* Bit values to set. */
  1044. word32 val;
  1045. } bench_pq_alg;
  1046. /* All recognized post-quantum asymmetric algorithm choosing command line
  1047. * options. */
  1048. static const bench_pq_alg bench_pq_asym_opt[] = {
  1049. { "-pq", 0xffffffff },
  1050. #ifdef WOLFSSL_HAVE_KYBER
  1051. { "-kyber", BENCH_KYBER },
  1052. { "-kyber512", BENCH_KYBER512 },
  1053. { "-kyber768", BENCH_KYBER768 },
  1054. { "-kyber1024", BENCH_KYBER1024 },
  1055. { "-ml-kem", BENCH_ML_KEM },
  1056. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1057. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1058. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1059. #endif
  1060. #if defined(HAVE_FALCON)
  1061. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1062. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1063. #endif
  1064. #if defined(HAVE_DILITHIUM)
  1065. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1066. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1067. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1068. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1069. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1070. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1071. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1072. #endif
  1073. { NULL, 0 }
  1074. };
  1075. #if defined(HAVE_SPHINCS)
  1076. /* All recognized post-quantum asymmetric algorithm choosing command line
  1077. * options. (Part 2) */
  1078. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1079. { "-pq", 0xffffffff },
  1080. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1081. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1082. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1083. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1084. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1085. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1086. { NULL, 0, }
  1087. };
  1088. #endif /* HAVE_SPHINCS */
  1089. #endif
  1090. #ifdef HAVE_WNR
  1091. const char* wnrConfigFile = "wnr-example.conf";
  1092. #endif
  1093. #if defined(WOLFSSL_MDK_ARM)
  1094. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1095. #define fopen wolfSSL_fopen
  1096. #endif
  1097. static int lng_index = 0;
  1098. #ifndef NO_MAIN_DRIVER
  1099. #ifndef MAIN_NO_ARGS
  1100. static const char* bench_Usage_msg1[][25] = {
  1101. /* 0 English */
  1102. { "-? <num> Help, print this usage\n",
  1103. " 0: English, 1: Japanese\n",
  1104. "-csv Print terminal output in csv format\n",
  1105. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1106. "-no_aad No additional authentication data passed.\n",
  1107. "-aad_size <num> With <num> bytes of AAD.\n",
  1108. ("-all_aad With AAD length of 0, "
  1109. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1110. " and\n"
  1111. " (if set via -aad_size) <aad_size> bytes.\n"
  1112. ),
  1113. "-dgst_full Full digest operation performed.\n",
  1114. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1115. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1116. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1117. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1118. "-p256 Measure ECC using P-256 curve.\n",
  1119. "-p384 Measure ECC using P-384 curve.\n",
  1120. "-p521 Measure ECC using P-521 curve.\n",
  1121. "-ecc-all Bench all enabled ECC curves.\n",
  1122. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1123. ("-lng <num> Display benchmark result by specified language.\n"
  1124. " 0: English, 1: Japanese\n"
  1125. ),
  1126. "<num> Size of block in bytes\n",
  1127. ("-blocks <num> Number of blocks. Can be used together with the "
  1128. "'Size of block'\n"
  1129. " option, but must be used after that one.\n"
  1130. ),
  1131. "-threads <num> Number of threads to run\n",
  1132. "-print Show benchmark stats summary\n",
  1133. "-hash_input <file> Input data to use for hash benchmarking\n",
  1134. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1135. "-min_runs <num> Specify minimum number of operation runs\n"
  1136. },
  1137. #ifndef NO_MULTIBYTE_PRINT
  1138. /* 1 Japanese */
  1139. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1140. " 0: 英語、 1: 日本語\n",
  1141. "-csv csv 形式で端末に出力します。\n",
  1142. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1143. "-no_aad 追加の認証データを使用しません.\n",
  1144. "-aad_size <num> TBD.\n",
  1145. "-all_aad TBD.\n",
  1146. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1147. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1148. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1149. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1150. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1151. "-p256 Measure ECC using P-256 curve.\n",
  1152. "-p384 Measure ECC using P-384 curve.\n",
  1153. "-p521 Measure ECC using P-521 curve.\n",
  1154. "-ecc-all Bench all enabled ECC curves.\n",
  1155. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1156. " 利用可能なアルゴリズムは下記を含みます:\n"
  1157. ),
  1158. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1159. " 0: 英語、 1: 日本語\n"
  1160. ),
  1161. "<num> ブロックサイズをバイト単位で指定します。\n",
  1162. "-blocks <num> TBD.\n",
  1163. "-threads <num> 実行するスレッド数\n",
  1164. "-print ベンチマーク統計の要約を表示する\n",
  1165. /* TODO: translate below */
  1166. "-hash_input <file> Input data to use for hash benchmarking\n",
  1167. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1168. "-min_runs <num> Specify minimum number of operation runs\n"
  1169. },
  1170. #endif
  1171. };
  1172. #endif /* MAIN_NO_ARGS */
  1173. #endif
  1174. static const char* bench_result_words1[][4] = {
  1175. { "took",
  1176. #ifdef BENCH_MICROSECOND
  1177. "microseconds"
  1178. #else
  1179. "seconds"
  1180. #endif
  1181. , "Cycles per byte", NULL }, /* 0 English */
  1182. #ifndef NO_MULTIBYTE_PRINT
  1183. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1184. #endif
  1185. };
  1186. #if !defined(NO_RSA) || \
  1187. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1188. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1189. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1190. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1191. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1192. static const char* bench_desc_words[][15] = {
  1193. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1194. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1195. #ifndef NO_MULTIBYTE_PRINT
  1196. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1197. #endif
  1198. };
  1199. #endif
  1200. #ifdef MULTI_VALUE_STATISTICS
  1201. static const char* bench_result_words3[][5] = {
  1202. /* 0 English */
  1203. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1204. /* TODO: Add japenese version */
  1205. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1206. };
  1207. #endif
  1208. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1209. #define HAVE_GET_CYCLES
  1210. static WC_INLINE word64 get_intel_cycles(void);
  1211. static THREAD_LS_T word64 total_cycles;
  1212. #define INIT_CYCLE_COUNTER
  1213. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1214. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1215. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1216. #define SHOW_INTEL_CYCLES(b, n, s) \
  1217. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1218. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1219. bench_result_words1[lng_index][2], \
  1220. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1221. (double)total_cycles / ((word64)count*(s))))
  1222. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1223. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1224. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1225. (double)total_cycles / ((word64)count*(s))))
  1226. #elif defined(LINUX_CYCLE_COUNT)
  1227. #include <linux/perf_event.h>
  1228. #include <sys/syscall.h>
  1229. #include <unistd.h>
  1230. static THREAD_LS_T word64 begin_cycles;
  1231. static THREAD_LS_T word64 total_cycles;
  1232. static THREAD_LS_T int cycles = -1;
  1233. static THREAD_LS_T struct perf_event_attr atr;
  1234. #define INIT_CYCLE_COUNTER do { \
  1235. atr.type = PERF_TYPE_HARDWARE; \
  1236. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1237. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1238. } while (0);
  1239. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1240. #define END_INTEL_CYCLES do { \
  1241. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1242. total_cycles = total_cycles - begin_cycles; \
  1243. } while (0);
  1244. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1245. #define SHOW_INTEL_CYCLES(b, n, s) \
  1246. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1247. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1248. bench_result_words1[lng_index][2], \
  1249. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1250. (count*s)))
  1251. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1252. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1253. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1254. / (count*s)))
  1255. #elif defined(SYNERGY_CYCLE_COUNT)
  1256. #include "hal_data.h"
  1257. static THREAD_LS_T word64 begin_cycles;
  1258. static THREAD_LS_T word64 total_cycles;
  1259. #define INIT_CYCLE_COUNTER
  1260. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1261. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1262. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1263. #define SHOW_INTEL_CYCLES(b, n, s) \
  1264. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1265. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1266. bench_result_words1[lng_index][2], \
  1267. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1268. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1269. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1270. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1271. #elif defined(WOLFSSL_ESPIDF)
  1272. /* TAG for ESP_LOGx() */
  1273. static const char* TAG = "wolfssl_benchmark";
  1274. static THREAD_LS_T word64 begin_cycles = 0;
  1275. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1276. static THREAD_LS_T word64 end_cycles = 0;
  1277. static THREAD_LS_T word64 total_cycles = 0;
  1278. /* the return value, as a global var */
  1279. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1280. /* the last value seen, adjusted for an overflow, as a global var */
  1281. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1282. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1283. /* esp_get_cpu_benchmark_cycles(void):
  1284. *
  1285. * Architecture-independant CPU clock counter.
  1286. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1287. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1288. /* Some vars for debugging, compare ticks to cycles */
  1289. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1290. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1291. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1292. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1293. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1294. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1295. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1296. #if ESP_IDF_VERSION_MAJOR >= 5
  1297. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1298. #define HAVE_GET_CYCLES
  1299. #define INIT_CYCLE_COUNTER do { \
  1300. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1301. esp_cpu_set_cycle_count(0); \
  1302. } while (0);
  1303. #else
  1304. #define HAVE_GET_CYCLES
  1305. #define INIT_CYCLE_COUNTER do { \
  1306. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1307. } while (0);
  1308. #endif
  1309. #define BEGIN_ESP_CYCLES do { \
  1310. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1311. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1312. begin_cycles_ticks = xTaskGetTickCount(); \
  1313. } while (0);
  1314. /* since it rolls over, we have something that will tolerate one */
  1315. #define END_ESP_CYCLES \
  1316. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1317. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1318. end_cycles, \
  1319. begin_cycles \
  1320. ); \
  1321. total_cycles = (end_cycles - begin_cycles);
  1322. #define SHOW_ESP_CYCLES(b, n, s) \
  1323. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1324. " %s = " FLT_FMT_PREC2 "\n", \
  1325. bench_result_words1[lng_index][2], \
  1326. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1327. )
  1328. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1329. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1330. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1331. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1332. /* 64 bit, unisgned, absolute difference
  1333. * used in CPU cycle counter debug calcs. */
  1334. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1335. {
  1336. uint64_t ret;
  1337. ret = (x > y) ? (x - y) : (y - x);
  1338. return ret;
  1339. }
  1340. #endif
  1341. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1342. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1343. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1344. ** at least once during full benchmark tests.
  1345. **
  1346. ** To test timing overflow, add a delay longer than max cycles:
  1347. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1348. */
  1349. uint64_t esp_get_cycle_count_ex()
  1350. {
  1351. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1352. /* unsigned int max = 4,294,967,295 */
  1353. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1354. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1355. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1356. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1357. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1358. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1359. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1360. #endif
  1361. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1362. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1363. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1364. * (current - last) */
  1365. #endif
  1366. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1367. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1368. defined(CONFIG_IDF_TARGET_ESP32C6)
  1369. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1370. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1371. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1372. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1373. #if ESP_IDF_VERSION_MAJOR >= 5
  1374. thisVal = esp_cpu_get_cycle_count();
  1375. #else
  1376. thisVal = cpu_hal_get_cycle_count();
  1377. #endif
  1378. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1379. thisVal = esp_cpu_get_cycle_count();
  1380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  1381. thisVal = esp_timer_get_time();
  1382. #else
  1383. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1384. * Calling current_time(1) to reset time causes thisVal overflow,
  1385. * on Xtensa, but not on RISC-V architecture. See also, below */
  1386. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1387. #ifndef configCPU_CLOCK_HZ
  1388. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1389. #define configCPU_CLOCK_HZ \
  1390. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1391. #endif
  1392. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1393. thisVal = (uint64_t)xTaskGetTickCount() *
  1394. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1395. #elif defined(__XTENSA__)
  1396. thisVal = esp_cpu_get_cycle_count();
  1397. #else
  1398. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1399. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1400. #endif
  1401. #endif
  1402. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1403. {
  1404. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1405. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1406. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1407. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1408. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1409. ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
  1410. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1411. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1412. }
  1413. #endif
  1414. /* If either thisVal is smaller than last (overflow), and/or the
  1415. * expected value calculated from FreeRTOS tick difference that would
  1416. * have never fit into an unsigned 32 bit integer anyhow... then we
  1417. * need to adjust thisVal to save. */
  1418. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1419. {
  1420. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1421. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1422. **
  1423. ** NOTE for long duration between calls with multiple overflows:
  1424. **
  1425. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1426. **
  1427. ** At this time no single test overflows. This is currently only a
  1428. ** concern for cumulative counts over multiple tests. As long
  1429. ** as well call xthal_get_ccount_ex() with no more than one
  1430. ** overflow CPU tick count, all will be well.
  1431. */
  1432. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1433. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1434. "(%llu < %llu) adding UINT_MAX = %llu.",
  1435. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1436. #endif
  1437. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1438. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1439. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1440. #endif
  1441. /* double check expected diff calc */
  1442. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1443. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1444. expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  1445. * MILLION_VALUE)
  1446. * tickDiff / configTICK_RATE_HZ;
  1447. #else
  1448. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1449. * tickDiff / configTICK_RATE_HZ;
  1450. #endif
  1451. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1452. #endif
  1453. if (expected_diff > UINT_MAX) {
  1454. /* The number of cycles expected from FreeRTOS ticks is
  1455. * greater than the maximum size of an unsigned 32-bit
  1456. * integer, meaning multiple overflows occurred. */
  1457. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1458. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1459. #endif
  1460. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1461. }
  1462. else {
  1463. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1464. }
  1465. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1466. {
  1467. tickBeginDiff = tickCount - begin_cycles_ticks;
  1468. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1469. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1470. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1471. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1472. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1473. }
  1474. #endif
  1475. }
  1476. else {
  1477. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1478. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1479. #endif
  1480. } /* if thisVal adjustment check */
  1481. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1482. if (thisTimerVal < _esp_cpu_timer_last)
  1483. {
  1484. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1485. "adding %ull", UINT_MAX);
  1486. thisTimerVal += (word64)UINT_MAX;
  1487. }
  1488. /* Check an alternate counter using a timer */
  1489. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1490. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1491. /* Adjust our actual returned value that takes into account overflow,
  1492. * increment 64 bit extended total by this 32 bit differential: */
  1493. thisIncrement = (thisVal - _esp_cpu_count_last);
  1494. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1495. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1496. #endif
  1497. /* Add our adjustment, taking into account overflows (see above) */
  1498. _esp_get_cycle_count_ex += thisIncrement;
  1499. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1500. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1501. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1502. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1503. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1504. /* all of this took some time, so reset the "last seen" value
  1505. * for the next measurement. */
  1506. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1507. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1508. defined(CONFIG_IDF_TARGET_ESP32C6)
  1509. {
  1510. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1511. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1512. &_esp_cpu_timer_last));
  1513. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1514. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1515. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1516. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1517. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1518. #if ESP_IDF_VERSION_MAJOR >= 5
  1519. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1520. #else
  1521. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  1522. #endif
  1523. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1524. }
  1525. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1526. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1527. #else
  1528. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1529. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1530. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1531. * or thisVal = xthal_get_ccount(); */
  1532. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1533. /* There's no CPU counter on the ESP8266, so we'll estimate
  1534. * cycles based on defined CPU frequency from sdkconfig and
  1535. * the RTOS tick frequency */
  1536. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1537. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1538. #elif ESP_IDF_VERSION_MAJOR < 5
  1539. _esp_cpu_count_last = xthal_get_ccount();
  1540. #else
  1541. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1542. #endif
  1543. #endif
  1544. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1545. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1546. #endif
  1547. /* Return the 64 bit extended total from 32 bit counter. */
  1548. return _esp_get_cycle_count_ex;
  1549. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1550. /* implement other architecture cycle counters here */
  1551. #else
  1552. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1553. #undef HAVE_GET_CYCLES
  1554. #define INIT_CYCLE_COUNTER
  1555. #define BEGIN_INTEL_CYCLES
  1556. #define END_INTEL_CYCLES
  1557. #ifdef MULTI_VALUE_STATISTICS
  1558. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1559. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1560. #else
  1561. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1562. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1563. #endif
  1564. #endif
  1565. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1566. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1567. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1568. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1569. #endif
  1570. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1571. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1572. !defined(NO_DH)
  1573. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1574. #include <wolfssl/certs_test.h>
  1575. #endif
  1576. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1577. #include <wolfssl/wolfcrypt/blake2.h>
  1578. #endif
  1579. #ifdef _MSC_VER
  1580. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1581. #pragma warning(disable: 4996)
  1582. #endif
  1583. #ifdef WOLFSSL_CURRTIME_REMAP
  1584. #define current_time WOLFSSL_CURRTIME_REMAP
  1585. #else
  1586. double current_time(int reset);
  1587. #endif
  1588. #ifdef LINUX_RUSAGE_UTIME
  1589. static void check_for_excessive_stime(const char *desc,
  1590. const char *desc_extra);
  1591. #endif
  1592. #if !defined(WC_NO_RNG) && \
  1593. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1594. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1595. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1596. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1597. || defined(WOLFSSL_HAVE_KYBER))
  1598. #define HAVE_LOCAL_RNG
  1599. static THREAD_LS_T WC_RNG gRng;
  1600. #define GLOBAL_RNG &gRng
  1601. #else
  1602. #define GLOBAL_RNG NULL
  1603. #endif
  1604. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1605. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1606. defined(HAVE_ECC) || !defined(NO_DH) || \
  1607. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1608. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1609. defined(WOLFSSL_HAVE_LMS)
  1610. #define BENCH_ASYM
  1611. #endif
  1612. #if defined(BENCH_ASYM)
  1613. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1614. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1615. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1616. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1617. defined(WOLFSSL_HAVE_LMS)
  1618. static const char* bench_result_words2[][5] = {
  1619. #ifdef BENCH_MICROSECOND
  1620. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1621. for μsec */
  1622. #else
  1623. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1624. #endif
  1625. #ifndef NO_MULTIBYTE_PRINT
  1626. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1627. #endif
  1628. };
  1629. #endif
  1630. #endif
  1631. #ifdef WOLFSSL_CAAM
  1632. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1633. #ifdef WOLFSSL_SECO_CAAM
  1634. #define SECO_MAX_UPDATES 10000
  1635. #define SECO_BENCHMARK_NONCE 0x7777
  1636. #define SECO_KEY_STORE_ID 1
  1637. #endif
  1638. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1639. #else
  1640. #ifdef WC_USE_DEVID
  1641. static THREAD_LS_T int devId = WC_USE_DEVID;
  1642. #else
  1643. static THREAD_LS_T int devId = INVALID_DEVID;
  1644. #endif
  1645. #endif
  1646. /* Asynchronous helper macros */
  1647. #ifdef WC_ENABLE_BENCH_THREADING
  1648. typedef struct ThreadData {
  1649. pthread_t thread_id;
  1650. } ThreadData;
  1651. static ThreadData* g_threadData;
  1652. static volatile int g_threadCount;
  1653. #endif
  1654. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1655. #ifndef NO_HW_BENCH
  1656. #define BENCH_DEVID
  1657. #endif
  1658. #ifndef HAVE_RENESAS_SYNC
  1659. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1660. #else
  1661. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1662. #endif
  1663. #else
  1664. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1665. #endif
  1666. #ifdef WOLFSSL_ASYNC_CRYPT
  1667. static WOLF_EVENT_QUEUE eventQueue;
  1668. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1669. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1670. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1671. int callAgain, int* times, int limit, int* pending)
  1672. {
  1673. int allowNext = 0;
  1674. /* this state can be set from a different thread */
  1675. WOLF_EVENT_STATE state = asyncDev->event.state;
  1676. /* if algo doesn't require calling again then use this flow */
  1677. if (state == WOLF_EVENT_STATE_DONE) {
  1678. if (callAgain) {
  1679. /* needs called again, so allow it and handle completion in
  1680. * bench_async_handle */
  1681. allowNext = 1;
  1682. }
  1683. else {
  1684. *ret = asyncDev->event.ret;
  1685. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1686. (*times)++;
  1687. if (*pending > 0) /* to support case where async blocks */
  1688. (*pending)--;
  1689. if ((*times + *pending) < limit)
  1690. allowNext = 1;
  1691. }
  1692. }
  1693. /* if slot is available and we haven't reached limit, start another */
  1694. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1695. allowNext = 1;
  1696. }
  1697. return allowNext;
  1698. }
  1699. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1700. int callAgain, int* times, int* pending)
  1701. {
  1702. WOLF_EVENT_STATE state = asyncDev->event.state;
  1703. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1704. if (state == WOLF_EVENT_STATE_DONE) {
  1705. *ret = asyncDev->event.ret;
  1706. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1707. (*times)++;
  1708. (*pending)--;
  1709. }
  1710. else {
  1711. (*pending)++;
  1712. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1713. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1714. }
  1715. }
  1716. else if (*ret >= 0) {
  1717. *ret = asyncDev->event.ret;
  1718. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1719. (*times)++;
  1720. if (*pending > 0) /* to support case where async blocks */
  1721. (*pending)--;
  1722. }
  1723. return (*ret >= 0) ? 1 : 0;
  1724. }
  1725. static WC_INLINE int bench_async_poll(int* pending)
  1726. {
  1727. int ret, asyncDone = 0;
  1728. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1729. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1730. if (ret != 0) {
  1731. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1732. return ret;
  1733. }
  1734. if (asyncDone == 0) {
  1735. #ifndef WC_NO_ASYNC_THREADING
  1736. /* give time to other threads */
  1737. wc_AsyncThreadYield();
  1738. #endif
  1739. }
  1740. (void)pending;
  1741. return asyncDone;
  1742. }
  1743. #else
  1744. #define BENCH_MAX_PENDING 1
  1745. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1746. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1747. int callAgain, int* times, int limit, int* pending)
  1748. {
  1749. (void)ret;
  1750. (void)asyncDev;
  1751. (void)callAgain;
  1752. (void)times;
  1753. (void)limit;
  1754. (void)pending;
  1755. return 1;
  1756. }
  1757. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1758. int callAgain, int* times, int* pending)
  1759. {
  1760. (void)asyncDev;
  1761. (void)callAgain;
  1762. (void)pending;
  1763. if (*ret >= 0) {
  1764. /* operation completed */
  1765. (*times)++;
  1766. return 1;
  1767. }
  1768. return 0;
  1769. }
  1770. #define bench_async_poll(p) WC_DO_NOTHING
  1771. #endif /* WOLFSSL_ASYNC_CRYPT */
  1772. /* maximum runtime for each benchmark */
  1773. #ifndef BENCH_MIN_RUNTIME_SEC
  1774. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1775. #endif
  1776. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1777. #define AES_AUTH_TAG_SZ 16
  1778. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1779. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1780. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1781. #if !defined(NO_MAIN_DRIVER)
  1782. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1783. #else
  1784. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1785. #endif
  1786. #endif
  1787. #define AES_AAD_STRING(s) \
  1788. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1789. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1790. enum en_aad_options {
  1791. AAD_SIZE_DEFAULT = 0x1U,
  1792. AAD_SIZE_ZERO = 0x2U,
  1793. AAD_SIZE_CUSTOM = 0x4U,
  1794. };
  1795. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1796. static word32 aes_aad_size = 0;
  1797. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1798. {
  1799. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1800. word32 options = aes_aad_options;
  1801. while(options) {
  1802. if (options & AAD_SIZE_DEFAULT) {
  1803. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1804. options &= ~(word32)AAD_SIZE_DEFAULT;
  1805. }
  1806. else if (options & AAD_SIZE_ZERO) {
  1807. aesAuthAddSz = 0;
  1808. options &= ~(word32)AAD_SIZE_ZERO;
  1809. }
  1810. else if (options & AAD_SIZE_CUSTOM) {
  1811. aesAuthAddSz = aes_aad_size;
  1812. options &= ~(word32)AAD_SIZE_CUSTOM;
  1813. }
  1814. fn(i);
  1815. aesAuthAddSz = aesAuthAddSz_orig;
  1816. }
  1817. }
  1818. #endif
  1819. #ifndef BENCH_CIPHER_ADD
  1820. #define BENCH_CIPHER_ADD 0
  1821. #endif
  1822. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  1823. #warning Large/Unalligned AuthSz could result in errors with /dev/crypto
  1824. #endif
  1825. /* use kB instead of mB for embedded benchmarking */
  1826. #ifdef BENCH_EMBEDDED
  1827. #ifndef BENCH_NTIMES
  1828. #define BENCH_NTIMES 2
  1829. #endif
  1830. #ifndef BENCH_AGREETIMES
  1831. #define BENCH_AGREETIMES 2
  1832. #endif
  1833. enum BenchmarkBounds {
  1834. scryptCnt = 1,
  1835. ntimes = BENCH_NTIMES,
  1836. genTimes = BENCH_MAX_PENDING,
  1837. agreeTimes = BENCH_AGREETIMES
  1838. };
  1839. /* how many kB to test (en/de)cryption */
  1840. #define NUM_BLOCKS 25
  1841. #define BENCH_SIZE (1024uL)
  1842. #else
  1843. #ifndef BENCH_NTIMES
  1844. #define BENCH_NTIMES 100
  1845. #endif
  1846. #ifndef BENCH_AGREETIMES
  1847. #define BENCH_AGREETIMES 100
  1848. #endif
  1849. enum BenchmarkBounds {
  1850. scryptCnt = 10,
  1851. ntimes = BENCH_NTIMES,
  1852. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1853. agreeTimes = BENCH_AGREETIMES
  1854. };
  1855. /* how many megs to test (en/de)cryption */
  1856. #define NUM_BLOCKS 5
  1857. #define BENCH_SIZE (1024*1024uL)
  1858. #endif
  1859. static int numBlocks = NUM_BLOCKS;
  1860. static word32 bench_size = BENCH_SIZE;
  1861. static int base2 = 1;
  1862. static int digest_stream = 1;
  1863. #ifdef HAVE_CHACHA
  1864. static int encrypt_only = 0;
  1865. #endif
  1866. #ifdef HAVE_AES_CBC
  1867. static int cipher_same_buffer = 0;
  1868. #endif
  1869. #ifdef MULTI_VALUE_STATISTICS
  1870. static int minimum_runs = 0;
  1871. #endif
  1872. #ifndef NO_RSA
  1873. /* Don't measure RSA sign/verify by default */
  1874. static int rsa_sign_verify = 0;
  1875. #endif
  1876. #ifndef NO_DH
  1877. /* Use the FFDHE parameters */
  1878. static int use_ffdhe = 0;
  1879. #endif
  1880. /* Don't print out in CSV format by default */
  1881. static int csv_format = 0;
  1882. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1883. /* Versal PLM maybe prints an error message to the same console.
  1884. * In order to not mix those outputs up, sleep a little while
  1885. * before erroring out.
  1886. */
  1887. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1888. #else
  1889. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1890. #endif
  1891. /* globals for cipher tests */
  1892. static THREAD_LS_T byte* bench_plain = NULL;
  1893. static THREAD_LS_T byte* bench_cipher = NULL;
  1894. #ifndef NO_FILESYSTEM
  1895. static THREAD_LS_T char* hash_input = NULL;
  1896. static THREAD_LS_T char* cipher_input = NULL;
  1897. #endif
  1898. static const XGEN_ALIGN byte bench_key_buf[] =
  1899. {
  1900. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1901. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1902. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1903. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1904. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1905. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1906. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1907. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1908. };
  1909. static const XGEN_ALIGN byte bench_iv_buf[] =
  1910. {
  1911. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1912. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1913. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1914. };
  1915. static THREAD_LS_T byte* bench_key = NULL;
  1916. static THREAD_LS_T byte* bench_iv = NULL;
  1917. #ifdef HAVE_RENESAS_SYNC
  1918. static THREAD_LS_T byte* bench_key1 = NULL;
  1919. static THREAD_LS_T byte* bench_key2 = NULL;
  1920. #endif
  1921. #ifdef WOLFSSL_STATIC_MEMORY
  1922. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1923. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1924. #elif defined(BENCH_EMBEDDED)
  1925. static byte gBenchMemory[50000];
  1926. #else
  1927. static byte gBenchMemory[400000];
  1928. #endif
  1929. #endif
  1930. /* This code handles cases with systems where static (non cost) ram variables
  1931. aren't properly initialized with data */
  1932. static void benchmark_static_init(int force)
  1933. {
  1934. static int gBenchStaticInit = 0;
  1935. if (gBenchStaticInit == 0 || force) {
  1936. gBenchStaticInit = 1;
  1937. /* Init static variables */
  1938. numBlocks = NUM_BLOCKS;
  1939. bench_size = BENCH_SIZE;
  1940. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1941. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1942. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1943. aes_aad_size = 0;
  1944. #endif
  1945. base2 = 1;
  1946. digest_stream = 1;
  1947. #ifdef MULTI_VALUE_STATISTICS
  1948. minimum_runs = 0;
  1949. #endif
  1950. bench_all = 1;
  1951. bench_cipher_algs = 0;
  1952. bench_digest_algs = 0;
  1953. bench_mac_algs = 0;
  1954. bench_kdf_algs = 0;
  1955. bench_asym_algs = 0;
  1956. bench_pq_asym_algs = 0;
  1957. bench_other_algs = 0;
  1958. bench_pq_hash_sig_algs = 0;
  1959. csv_format = 0;
  1960. }
  1961. }
  1962. /*****************************************************************************/
  1963. /* Begin Stats Functions */
  1964. /*****************************************************************************/
  1965. typedef enum bench_stat_type {
  1966. BENCH_STAT_ASYM,
  1967. BENCH_STAT_SYM,
  1968. BENCH_STAT_IGNORE,
  1969. } bench_stat_type_t;
  1970. #ifdef WC_BENCH_TRACK_STATS
  1971. static int gPrintStats = 0;
  1972. #ifdef WC_ENABLE_BENCH_THREADING
  1973. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1974. #endif
  1975. #ifndef BENCH_MAX_NAME_SZ
  1976. #define BENCH_MAX_NAME_SZ 24
  1977. #endif
  1978. typedef struct bench_stats {
  1979. struct bench_stats* next;
  1980. struct bench_stats* prev;
  1981. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1982. const char* desc;
  1983. double perfsec;
  1984. int strength;
  1985. int useDeviceID;
  1986. int finishCount;
  1987. bench_stat_type_t type;
  1988. int lastRet;
  1989. const char* perftype;
  1990. } bench_stats_t;
  1991. static bench_stats_t* bench_stats_head;
  1992. static bench_stats_t* bench_stats_tail;
  1993. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1994. const char* algo, int strength, const char* desc, int useDeviceID,
  1995. double perfsec, const char* perftype, int ret)
  1996. {
  1997. bench_stats_t* bstat = NULL;
  1998. #ifdef WC_ENABLE_BENCH_THREADING
  1999. /* protect bench_stats_head and bench_stats_tail access */
  2000. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2001. #endif
  2002. if (algo != NULL) {
  2003. /* locate existing in list */
  2004. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  2005. /* match based on algo, strength and desc */
  2006. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  2007. bstat->strength == strength &&
  2008. bstat->desc == desc &&
  2009. bstat->useDeviceID == useDeviceID) {
  2010. break;
  2011. }
  2012. }
  2013. }
  2014. if (bstat == NULL) {
  2015. /* allocate new and put on list */
  2016. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  2017. DYNAMIC_TYPE_INFO);
  2018. if (bstat) {
  2019. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  2020. /* add to list */
  2021. bstat->next = NULL;
  2022. if (bench_stats_tail == NULL) {
  2023. bench_stats_head = bstat;
  2024. }
  2025. else {
  2026. bench_stats_tail->next = bstat;
  2027. bstat->prev = bench_stats_tail;
  2028. }
  2029. bench_stats_tail = bstat; /* add to the end either way */
  2030. }
  2031. }
  2032. if (bstat) {
  2033. bstat->type = type;
  2034. if (algo != NULL)
  2035. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  2036. bstat->strength = strength;
  2037. bstat->desc = desc;
  2038. bstat->useDeviceID = useDeviceID;
  2039. bstat->perfsec += perfsec;
  2040. bstat->finishCount++;
  2041. bstat->perftype = perftype;
  2042. if (bstat->lastRet > ret)
  2043. bstat->lastRet = ret; /* track last error */
  2044. }
  2045. #ifdef WC_ENABLE_BENCH_THREADING
  2046. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2047. #endif
  2048. return bstat;
  2049. }
  2050. void bench_stats_print(void)
  2051. {
  2052. bench_stats_t* bstat;
  2053. int digits;
  2054. #ifdef WC_ENABLE_BENCH_THREADING
  2055. /* protect bench_stats_head and bench_stats_tail access */
  2056. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2057. #endif
  2058. #ifdef BENCH_MICROSECOND
  2059. digits = 5;
  2060. #else
  2061. digits = 3;
  2062. #endif
  2063. for (bstat = bench_stats_head; bstat != NULL; ) {
  2064. if (bstat->type == BENCH_STAT_SYM) {
  2065. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2066. "\n", bstat->desc,
  2067. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2068. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2069. base2 ? "MB" : "mB");
  2070. }
  2071. else {
  2072. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2073. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2074. bstat->algo, bstat->strength, bstat->desc,
  2075. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2076. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2077. }
  2078. bstat = bstat->next;
  2079. }
  2080. #ifdef WC_ENABLE_BENCH_THREADING
  2081. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2082. #endif
  2083. }
  2084. #endif /* WC_BENCH_TRACK_STATS */
  2085. static WC_INLINE void bench_stats_init(void)
  2086. {
  2087. #ifdef WC_BENCH_TRACK_STATS
  2088. bench_stats_head = NULL;
  2089. bench_stats_tail = NULL;
  2090. #endif
  2091. INIT_CYCLE_COUNTER
  2092. }
  2093. static WC_INLINE void bench_stats_start(int* count, double* start)
  2094. {
  2095. *count = 0;
  2096. *start = current_time(1);
  2097. #ifdef WOLFSSL_ESPIDF
  2098. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2099. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
  2100. ", start=" FLT_FMT,
  2101. total_cycles, FLT_FMT_ARGS(*start) );
  2102. #endif
  2103. BEGIN_ESP_CYCLES
  2104. #else
  2105. BEGIN_INTEL_CYCLES
  2106. #endif
  2107. }
  2108. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2109. #define bench_stats_start(count, start) do { \
  2110. SAVE_VECTOR_REGISTERS(pr_err( \
  2111. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2112. return; ); \
  2113. bench_stats_start(count, start); \
  2114. } while (0)
  2115. #endif
  2116. static WC_INLINE int bench_stats_check(double start)
  2117. {
  2118. int ret = 0;
  2119. double this_current_time = 0.0;
  2120. this_current_time = current_time(0); /* get the timestamp, no reset */
  2121. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2122. #if defined(WOLFSSL_ESPIDF)
  2123. ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
  2124. this_current_time, start );
  2125. #endif
  2126. #endif
  2127. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2128. #ifdef BENCH_MICROSECOND
  2129. * 1000000
  2130. #endif
  2131. );
  2132. return ret;
  2133. }
  2134. /* return text for units and scale the value of blocks as needed */
  2135. static const char* get_blocktype(double* blocks)
  2136. {
  2137. const char* rt;
  2138. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2139. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2140. #undef WOLFSSL_FIXED_UNIT
  2141. #define WOLFSSL_FIXED_UNIT "GB"
  2142. *blocks /= (1024UL * 1024UL * 1024UL);
  2143. rt = "GiB";
  2144. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2145. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2146. #undef WOLFSSL_FIXED_UNIT
  2147. #define WOLFSSL_FIXED_UNIT "MB"
  2148. *blocks /= (1024UL * 1024UL);
  2149. rt = "MiB";
  2150. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2151. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2152. #undef WOLFSSL_FIXED_UNIT
  2153. #define WOLFSSL_FIXED_UNIT "KB"
  2154. *blocks /= 1024;
  2155. rt = "KiB";
  2156. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2157. #undef WOLFSSL_FIXED_UNIT
  2158. #define WOLFSSL_FIXED_UNIT "bytes"
  2159. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2160. rt = "bytes";
  2161. #else
  2162. /* If no user-specified, auto-scale each metric (results vary).
  2163. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2164. if (*blocks > (1024UL * 1024UL)) {
  2165. *blocks /= (1024UL * 1024UL);
  2166. rt = "MiB";
  2167. }
  2168. else if (*blocks > 1024) {
  2169. *blocks /= 1024;
  2170. rt = "KiB";
  2171. }
  2172. else {
  2173. rt = "bytes";
  2174. }
  2175. #endif
  2176. return rt;
  2177. }
  2178. /* return text for units and scale the value of blocks as needed for base2 */
  2179. static const char* get_blocktype_base10(double* blocks)
  2180. {
  2181. const char* rt;
  2182. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2183. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2184. *blocks /= (1000UL * 1000UL * 1000UL);
  2185. rt = "GB";
  2186. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2187. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2188. *blocks /= (1000UL * 1000UL);
  2189. rt = "MB";
  2190. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2191. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2192. *blocks /= (1000UL);
  2193. rt = "KB";
  2194. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2195. (void)(*blocks); /* no adjustment, just appease compiler */
  2196. rt = "bytes";
  2197. #else
  2198. /* If not user-specified, auto-scale each metric (results vary).
  2199. * Determine if we should show as KB or MB or bytes */
  2200. if (*blocks > (1000UL * 1000UL)) {
  2201. *blocks /= (1000UL * 1000UL);
  2202. rt = "MB";
  2203. }
  2204. else if (*blocks > 1000) {
  2205. *blocks /= 1000; /* make KB */
  2206. rt = "KB";
  2207. }
  2208. else {
  2209. rt = "bytes";
  2210. }
  2211. #endif
  2212. return rt;
  2213. }
  2214. #ifdef MULTI_VALUE_STATISTICS
  2215. static double wc_sqroot(double in)
  2216. {
  2217. /* do 32 iterations for the sqroot */
  2218. int iter = 32;
  2219. double root = in/3.0;
  2220. if (in < 0.0)
  2221. return -1;
  2222. for (int i=0; i < iter; i++)
  2223. root = (root + in / root) / 2.0;
  2224. return root;
  2225. }
  2226. static void bench_multi_value_stats(double max, double min, double sum,
  2227. double squareSum, int runs)
  2228. {
  2229. double mean = 0;
  2230. double sd = 0;
  2231. char msg[WC_BENCH_MAX_LINE_LEN];
  2232. const char** word = bench_result_words3[lng_index];
  2233. XMEMSET(msg, 0, sizeof(msg));
  2234. mean = sum / runs;
  2235. /* Calculating standard deviation */
  2236. sd = (squareSum / runs) - (mean * mean);
  2237. sd = wc_sqroot(sd);
  2238. if (csv_format == 1) {
  2239. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2240. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2241. FLT_FMT_PREC2_ARGS(3, 3, max),
  2242. FLT_FMT_PREC2_ARGS(3, 3, min),
  2243. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2244. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2245. }
  2246. else{
  2247. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2248. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2249. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2250. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2251. WOLFSSL_FIXED_TIME_UNIT "\n",
  2252. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2253. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2254. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2255. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2256. }
  2257. printf("%s", msg);
  2258. #ifndef WOLFSSL_SGX
  2259. XFFLUSH(stdout);
  2260. #endif
  2261. }
  2262. #endif
  2263. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2264. * except for AES direct that operates on WC_AES_BLOCK_SIZE blocks */
  2265. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2266. int count, word32 countSz,
  2267. double start, int ret)
  2268. {
  2269. double total, persec = 0, blocks = (double)count;
  2270. const char* blockType;
  2271. char msg[WC_BENCH_MAX_LINE_LEN];
  2272. const char** word = bench_result_words1[lng_index];
  2273. static int sym_header_printed = 0;
  2274. XMEMSET(msg, 0, sizeof(msg));
  2275. #ifdef WOLFSSL_ESPIDF
  2276. END_ESP_CYCLES
  2277. #else
  2278. END_INTEL_CYCLES
  2279. #endif
  2280. total = current_time(0) - start;
  2281. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2282. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2283. #endif
  2284. #ifdef LINUX_RUSAGE_UTIME
  2285. check_for_excessive_stime(desc, "");
  2286. #endif
  2287. /* calculate actual bytes */
  2288. blocks *= countSz;
  2289. if (csv_format == 1) {
  2290. /* only print out header once */
  2291. if (sym_header_printed == 0) {
  2292. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2293. /* machine parseable CSV */
  2294. #ifdef HAVE_GET_CYCLES
  2295. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2296. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2297. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2298. ",cycles_total,Cycles per byte,");
  2299. #else
  2300. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2301. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2302. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2303. ",cycles_total,");
  2304. #endif
  2305. #else
  2306. /* normal CSV */
  2307. #ifdef BENCH_DEVID
  2308. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2309. #else
  2310. #define BENCH_DEVID_COLUMN_HEADER
  2311. #endif
  2312. #ifdef HAVE_GET_CYCLES
  2313. printf("\n\nSymmetric Ciphers:\n\n");
  2314. printf("Algorithm,"
  2315. BENCH_DEVID_COLUMN_HEADER
  2316. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2317. ",Cycles per byte,");
  2318. #else
  2319. printf("\n\nSymmetric Ciphers:\n\n");
  2320. printf("Algorithm,"
  2321. BENCH_DEVID_COLUMN_HEADER
  2322. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2323. #endif
  2324. #endif
  2325. #ifdef MULTI_VALUE_STATISTICS
  2326. printf("max duration,min duration,mean duration,sd,\n");
  2327. #else
  2328. printf("\n");
  2329. #endif
  2330. sym_header_printed = 1;
  2331. }
  2332. }
  2333. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2334. * note that the blockType text is assigned AND the blocks param is scaled.
  2335. */
  2336. if (base2) {
  2337. blockType = get_blocktype(&blocks);
  2338. }
  2339. else {
  2340. blockType = get_blocktype_base10(&blocks);
  2341. }
  2342. /* calculate blocks per second */
  2343. if (total > 0) {
  2344. persec = (1 / total) * blocks;
  2345. }
  2346. SLEEP_ON_ERROR(ret);
  2347. /* format and print to terminal */
  2348. if (csv_format == 1) {
  2349. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2350. #ifdef WOLFSSL_ESPIDF
  2351. unsigned long bytes_processed =
  2352. (unsigned long)count * (unsigned long)countSz;
  2353. #else
  2354. word64 bytes_processed = (word64)count * (word64)countSz;
  2355. #endif
  2356. /* note this codepath brings in all the fields from the non-CSV case. */
  2357. #ifdef WOLFSSL_ESPIDF
  2358. #ifdef HAVE_GET_CYCLES
  2359. (void)XSNPRINTF(msg, sizeof(msg),
  2360. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2361. BENCH_DEVID_GET_NAME(useDeviceID),
  2362. bytes_processed, FLT_FMT_ARGS(total),
  2363. FLT_FMT_ARGS(persec),
  2364. (long unsigned int) total_cycles);
  2365. #else
  2366. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2367. #endif
  2368. /* implement other architectures here */
  2369. #else
  2370. #ifdef HAVE_GET_CYCLES
  2371. (void)XSNPRINTF(msg, sizeof(msg),
  2372. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2373. BENCH_DEVID_GET_NAME(useDeviceID),
  2374. bytes_processed, FLT_FMT_ARGS(total),
  2375. FLT_FMT_ARGS(persec), total_cycles);
  2376. #else
  2377. (void)XSNPRINTF(msg, sizeof(msg),
  2378. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2379. BENCH_DEVID_GET_NAME(useDeviceID),
  2380. bytes_processed, FLT_FMT_ARGS(total),
  2381. FLT_FMT_ARGS(persec));
  2382. #endif
  2383. #endif
  2384. #elif defined(BENCH_DEVID)
  2385. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2386. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2387. #else
  2388. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2389. FLT_FMT_ARGS(persec));
  2390. #endif
  2391. #ifdef WOLFSSL_ESPIDF
  2392. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2393. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2394. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2395. total_cycles);
  2396. #endif
  2397. /* implement other cycle counters here */
  2398. #else
  2399. /* the default cycle counter is Intel */
  2400. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2401. #endif
  2402. } /* if (csv_format == 1) */
  2403. else {
  2404. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2405. #ifdef HAVE_GET_CYCLES
  2406. (void)XSNPRINTF(msg, sizeof(msg),
  2407. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2408. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2409. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2410. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2411. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2412. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2413. (unsigned long) total_cycles);
  2414. #else
  2415. (void)XSNPRINTF(msg, sizeof(msg),
  2416. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2417. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2418. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2419. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2420. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2421. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2422. #endif /* HAVE_GET_CYCLES */
  2423. #else
  2424. (void)XSNPRINTF(msg, sizeof(msg),
  2425. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2426. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2427. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2428. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2429. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2430. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2431. #endif
  2432. #ifdef WOLFSSL_ESPIDF
  2433. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2434. /* implement other architecture cycle counters here */
  2435. #else
  2436. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2437. #endif
  2438. } /* not CSV format */
  2439. printf("%s", msg);
  2440. /* show errors */
  2441. if (ret < 0) {
  2442. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2443. }
  2444. #ifndef WOLFSSL_SGX
  2445. XFFLUSH(stdout);
  2446. #endif
  2447. #ifdef WC_BENCH_TRACK_STATS
  2448. /* Add to thread stats */
  2449. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2450. blockType, ret);
  2451. #endif
  2452. (void)useDeviceID;
  2453. (void)ret;
  2454. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2455. RESTORE_VECTOR_REGISTERS();
  2456. #endif
  2457. TEST_SLEEP();
  2458. } /* bench_stats_sym_finish */
  2459. #ifdef BENCH_ASYM
  2460. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2461. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2462. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2463. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  2464. defined(WOLFSSL_HAVE_LMS)
  2465. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2466. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2467. double start, int ret)
  2468. {
  2469. double total, each = 0, opsSec, milliEach;
  2470. const char **word = bench_result_words2[lng_index];
  2471. #ifdef WC_BENCH_TRACK_STATS
  2472. const char* kOpsSec = "Ops/Sec";
  2473. #endif
  2474. char msg[256];
  2475. static int asym_header_printed = 0;
  2476. #ifdef BENCH_MICROSECOND
  2477. const int digits = 5;
  2478. #else
  2479. const int digits = 3;
  2480. #endif
  2481. XMEMSET(msg, 0, sizeof(msg));
  2482. total = current_time(0) - start;
  2483. #ifdef LINUX_RUSAGE_UTIME
  2484. check_for_excessive_stime(desc, desc_extra);
  2485. #endif
  2486. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2487. #ifdef WOLFSSL_ESPIDF
  2488. END_ESP_CYCLES
  2489. #else
  2490. END_INTEL_CYCLES
  2491. #endif
  2492. #endif
  2493. /* some sanity checks on the final numbers */
  2494. if (count > 0) {
  2495. each = total / count; /* per second */
  2496. }
  2497. else {
  2498. count = 0;
  2499. each = 0;
  2500. }
  2501. if (total > 0) {
  2502. opsSec = count / total; /* ops second */
  2503. }
  2504. else {
  2505. opsSec = 0;
  2506. }
  2507. #ifdef BENCH_MICROSECOND
  2508. milliEach = each / 1000; /* milliseconds */
  2509. #else
  2510. milliEach = each * 1000; /* milliseconds */
  2511. #endif
  2512. SLEEP_ON_ERROR(ret);
  2513. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2514. (void)milliEach;
  2515. /* format and print to terminal */
  2516. if (csv_format == 1) {
  2517. /* only print out header once */
  2518. if (asym_header_printed == 0) {
  2519. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2520. #ifdef HAVE_GET_CYCLES
  2521. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2522. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2523. "ecs,cycles,cycles/op,");
  2524. #else
  2525. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2526. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2527. "ecs,");
  2528. #endif
  2529. #else
  2530. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2531. printf("%sAlgorithm,key size,operation,ops/"
  2532. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2533. #endif
  2534. printf("max duration,min duration,mean duration,sd,\n");
  2535. asym_header_printed = 1;
  2536. }
  2537. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2538. #ifdef HAVE_GET_CYCLES
  2539. (void)XSNPRINTF(msg, sizeof(msg),
  2540. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2541. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2542. algo, strength, desc, desc_extra,
  2543. FLT_FMT_PREC_ARGS(digits, opsSec),
  2544. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2545. FLT_FMT_PREC_ARGS(6,
  2546. (double)total_cycles / (double)count));
  2547. #else
  2548. (void)XSNPRINTF(msg, sizeof(msg),
  2549. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2550. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2551. algo, strength, desc, desc_extra,
  2552. FLT_FMT_PREC_ARGS(digits, opsSec),
  2553. count, FLT_FMT_ARGS(total));
  2554. #endif
  2555. #else
  2556. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2557. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2558. algo, strength, desc, desc_extra,
  2559. FLT_FMT_PREC_ARGS(digits, opsSec));
  2560. #endif
  2561. } /* if (csv_format == 1) */
  2562. else {
  2563. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2564. #ifdef HAVE_GET_CYCLES
  2565. (void)XSNPRINTF(msg, sizeof(msg),
  2566. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2567. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2568. algo, strength, desc, desc_extra,
  2569. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2570. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2571. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2572. (unsigned long)total_cycles);
  2573. #else
  2574. (void)XSNPRINTF(msg, sizeof(msg),
  2575. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2576. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2577. algo, strength, desc, desc_extra,
  2578. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2579. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2580. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2581. #endif /* HAVE_GET_CYCLES */
  2582. #else
  2583. (void)XSNPRINTF(msg, sizeof(msg),
  2584. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2585. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2586. algo, strength, desc, desc_extra,
  2587. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2588. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2589. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2590. #endif
  2591. }
  2592. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2593. /* format and print to terminal */
  2594. if (csv_format == 1) {
  2595. /* only print out header once */
  2596. if (asym_header_printed == 0) {
  2597. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2598. #ifdef HAVE_GET_CYCLES
  2599. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2600. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2601. "ecs,cycles,cycles/op,");
  2602. #else
  2603. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2604. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2605. "ecs,");
  2606. #endif
  2607. #else
  2608. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2609. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2610. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2611. #endif
  2612. printf("\n");
  2613. asym_header_printed = 1;
  2614. }
  2615. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2616. #ifdef HAVE_GET_CYCLES
  2617. (void)XSNPRINTF(msg, sizeof(msg),
  2618. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2619. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2620. algo, strength, desc, desc_extra,
  2621. FLT_FMT_PREC_ARGS(3, milliEach),
  2622. FLT_FMT_PREC_ARGS(digits, opsSec),
  2623. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2624. FLT_FMT_PREC_ARGS(6,
  2625. (double)total_cycles / (double)count));
  2626. #else
  2627. (void)XSNPRINTF(msg, sizeof(msg),
  2628. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2629. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2630. algo, strength, desc, desc_extra,
  2631. FLT_FMT_PREC_ARGS(3, milliEach),
  2632. FLT_FMT_PREC_ARGS(digits, opsSec),
  2633. count, FLT_FMT_ARGS(total));
  2634. #endif
  2635. #else
  2636. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2637. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2638. algo, strength, desc, desc_extra,
  2639. FLT_FMT_PREC_ARGS(3, milliEach),
  2640. FLT_FMT_PREC_ARGS(digits, opsSec));
  2641. #endif
  2642. } /* if (csv_format == 1) */
  2643. else {
  2644. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2645. #ifdef HAVE_GET_CYCLES
  2646. (void)XSNPRINTF(msg, sizeof(msg),
  2647. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2648. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2649. STATS_CLAUSE_SEPARATOR,
  2650. algo, strength, desc, desc_extra,
  2651. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2652. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2653. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2654. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2655. (unsigned long)total_cycles);
  2656. #else
  2657. (void)XSNPRINTF(msg, sizeof(msg),
  2658. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2659. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2660. STATS_CLAUSE_SEPARATOR,
  2661. algo, strength, desc, desc_extra,
  2662. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2663. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2664. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2665. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2666. #endif /* HAVE_GET_CYCLES */
  2667. #else
  2668. (void)XSNPRINTF(msg, sizeof(msg),
  2669. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2670. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2671. STATS_CLAUSE_SEPARATOR,
  2672. algo, strength, desc, desc_extra,
  2673. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2674. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2675. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2676. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2677. #endif
  2678. }
  2679. #endif /* MULTI_VALUE_STATISTICS */
  2680. printf("%s", msg);
  2681. /* show errors */
  2682. if (ret < 0) {
  2683. printf("%sBenchmark %s %s %d failed: %d\n",
  2684. err_prefix, algo, desc, strength, ret);
  2685. }
  2686. #ifndef WOLFSSL_SGX
  2687. XFFLUSH(stdout);
  2688. #endif
  2689. #ifdef WC_BENCH_TRACK_STATS
  2690. /* Add to thread stats */
  2691. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2692. kOpsSec, ret);
  2693. #endif
  2694. (void)useDeviceID;
  2695. (void)ret;
  2696. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2697. RESTORE_VECTOR_REGISTERS();
  2698. #endif
  2699. TEST_SLEEP();
  2700. } /* bench_stats_asym_finish_ex */
  2701. static void bench_stats_asym_finish(const char* algo, int strength,
  2702. const char* desc, int useDeviceID, int count, double start, int ret)
  2703. {
  2704. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2705. start, ret);
  2706. }
  2707. #endif
  2708. #endif /* BENCH_ASYM */
  2709. static WC_INLINE void bench_stats_free(void)
  2710. {
  2711. #ifdef WC_BENCH_TRACK_STATS
  2712. bench_stats_t* bstat;
  2713. for (bstat = bench_stats_head; bstat != NULL; ) {
  2714. bench_stats_t* next = bstat->next;
  2715. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2716. bstat = next;
  2717. }
  2718. bench_stats_head = NULL;
  2719. bench_stats_tail = NULL;
  2720. #endif
  2721. }
  2722. /*****************************************************************************/
  2723. /* End Stats Functions */
  2724. /*****************************************************************************/
  2725. static void* benchmarks_do(void* args)
  2726. {
  2727. long bench_buf_size;
  2728. #ifdef WOLFSSL_ASYNC_CRYPT
  2729. #ifndef WC_NO_ASYNC_THREADING
  2730. ThreadData* threadData = (ThreadData*)args;
  2731. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2732. #else
  2733. if (wolfAsync_DevOpen(&devId) < 0)
  2734. #endif
  2735. {
  2736. printf("%sAsync device open failed\n%sRunning without async\n",
  2737. err_prefix, err_prefix);
  2738. }
  2739. #endif /* WOLFSSL_ASYNC_CRYPT */
  2740. (void)args;
  2741. #ifdef WOLFSSL_ASYNC_CRYPT
  2742. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2743. printf("%sAsync event queue init failure!\n", err_prefix);
  2744. }
  2745. #endif
  2746. #ifdef WOLF_CRYPTO_CB
  2747. #ifdef HAVE_INTEL_QA_SYNC
  2748. devId = wc_CryptoCb_InitIntelQa();
  2749. if (devId == INVALID_DEVID) {
  2750. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2751. }
  2752. #endif
  2753. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2754. devId = wc_CryptoCb_InitOcteon();
  2755. if (devId == INVALID_DEVID) {
  2756. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2757. }
  2758. #endif
  2759. #ifdef HAVE_RENESAS_SYNC
  2760. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2761. if (devId == INVALID_DEVID) {
  2762. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2763. }
  2764. #endif
  2765. #endif
  2766. #if defined(HAVE_LOCAL_RNG)
  2767. {
  2768. int rngRet;
  2769. #ifndef HAVE_FIPS
  2770. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2771. #else
  2772. rngRet = wc_InitRng(&gRng);
  2773. #endif
  2774. if (rngRet < 0) {
  2775. printf("%sInitRNG failed\n", err_prefix);
  2776. return NULL;
  2777. }
  2778. }
  2779. #endif
  2780. /* setup bench plain, cipher, key and iv globals */
  2781. /* make sure bench buffer is multiple of 16 (AES block size) */
  2782. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2783. if (bench_buf_size % 16)
  2784. bench_buf_size += 16 - (bench_buf_size % 16);
  2785. #ifdef WOLFSSL_AFALG_XILINX_AES
  2786. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2787. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2788. #else
  2789. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2790. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2791. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2792. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2793. #endif
  2794. if (bench_plain == NULL || bench_cipher == NULL) {
  2795. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2796. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2797. bench_plain = bench_cipher = NULL;
  2798. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2799. goto exit;
  2800. }
  2801. #ifndef NO_FILESYSTEM
  2802. if (hash_input) {
  2803. size_t rawSz;
  2804. XFILE file;
  2805. file = XFOPEN(hash_input, "rb");
  2806. if (file == XBADFILE)
  2807. goto exit;
  2808. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2809. XFCLOSE(file);
  2810. goto exit;
  2811. }
  2812. bench_buf_size = XFTELL(file);
  2813. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2814. XFCLOSE(file);
  2815. goto exit;
  2816. }
  2817. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2818. rawSz = (size_t)bench_buf_size;
  2819. if (bench_buf_size % 16)
  2820. bench_buf_size += 16 - (bench_buf_size % 16);
  2821. bench_size = (word32)bench_buf_size;
  2822. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2823. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2824. if (bench_plain == NULL) {
  2825. XFCLOSE(file);
  2826. goto exit;
  2827. }
  2828. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2829. != rawSz) {
  2830. XFCLOSE(file);
  2831. goto exit;
  2832. }
  2833. XFCLOSE(file);
  2834. }
  2835. else {
  2836. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2837. }
  2838. if (cipher_input) {
  2839. size_t rawSz;
  2840. XFILE file;
  2841. file = XFOPEN(cipher_input, "rb");
  2842. if (file == XBADFILE)
  2843. goto exit;
  2844. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2845. XFCLOSE(file);
  2846. goto exit;
  2847. }
  2848. bench_buf_size = XFTELL(file);
  2849. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2850. XFCLOSE(file);
  2851. goto exit;
  2852. }
  2853. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2854. rawSz = (size_t)bench_buf_size;
  2855. if (bench_buf_size % 16)
  2856. bench_buf_size += 16 - (bench_buf_size % 16);
  2857. if (bench_size > (word32)bench_buf_size)
  2858. bench_size = (word32)bench_buf_size;
  2859. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2860. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2861. if (bench_cipher == NULL) {
  2862. XFCLOSE(file);
  2863. goto exit;
  2864. }
  2865. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2866. != rawSz) {
  2867. XFCLOSE(file);
  2868. goto exit;
  2869. }
  2870. XFCLOSE(file);
  2871. }
  2872. else {
  2873. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2874. }
  2875. #endif
  2876. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2877. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2878. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2879. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2880. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2881. if (bench_key == NULL || bench_iv == NULL) {
  2882. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2883. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2884. bench_key = bench_iv = NULL;
  2885. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2886. goto exit;
  2887. }
  2888. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2889. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2890. #elif defined(HAVE_RENESAS_SYNC)
  2891. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2892. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2893. bench_key = (byte*)bench_key_buf;
  2894. bench_iv = (byte*)bench_iv_buf;
  2895. #else
  2896. bench_key = (byte*)bench_key_buf;
  2897. bench_iv = (byte*)bench_iv_buf;
  2898. #endif
  2899. #ifndef WC_NO_RNG
  2900. if (bench_all || (bench_other_algs & BENCH_RNG))
  2901. bench_rng();
  2902. #endif /* WC_NO_RNG */
  2903. #ifndef NO_AES
  2904. #ifdef HAVE_AES_CBC
  2905. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2906. #ifndef NO_SW_BENCH
  2907. bench_aescbc(0);
  2908. #endif
  2909. #if defined(BENCH_DEVID)
  2910. bench_aescbc(1);
  2911. #endif
  2912. }
  2913. #endif
  2914. #ifdef HAVE_AESGCM
  2915. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2916. #ifndef NO_SW_BENCH
  2917. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2918. #endif
  2919. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2920. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2921. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2922. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2923. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2924. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2925. #endif
  2926. #ifndef NO_SW_BENCH
  2927. bench_gmac(0);
  2928. #endif
  2929. #if defined(BENCH_DEVID)
  2930. bench_gmac(1);
  2931. #endif
  2932. }
  2933. #endif
  2934. #ifdef HAVE_AES_ECB
  2935. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2936. #ifndef NO_SW_BENCH
  2937. bench_aesecb(0);
  2938. #endif
  2939. #ifdef BENCH_DEVID
  2940. bench_aesecb(1);
  2941. #endif
  2942. }
  2943. #endif
  2944. #ifdef WOLFSSL_AES_XTS
  2945. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2946. bench_aesxts();
  2947. #endif
  2948. #ifdef WOLFSSL_AES_CFB
  2949. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2950. bench_aescfb();
  2951. #endif
  2952. #ifdef WOLFSSL_AES_OFB
  2953. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2954. bench_aesofb();
  2955. #endif
  2956. #ifdef WOLFSSL_AES_COUNTER
  2957. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2958. bench_aesctr(0);
  2959. #ifdef BENCH_DEVID
  2960. bench_aesctr(1);
  2961. #endif
  2962. }
  2963. #endif
  2964. #ifdef HAVE_AESCCM
  2965. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2966. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2967. #ifdef BENCH_DEVID
  2968. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2969. #endif
  2970. }
  2971. #endif
  2972. #ifdef WOLFSSL_AES_SIV
  2973. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2974. bench_aessiv();
  2975. #endif
  2976. #endif /* !NO_AES */
  2977. #ifdef HAVE_CAMELLIA
  2978. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2979. bench_camellia();
  2980. #endif
  2981. #ifdef WOLFSSL_SM4_CBC
  2982. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2983. bench_sm4_cbc();
  2984. #endif
  2985. #ifdef WOLFSSL_SM4_GCM
  2986. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2987. bench_sm4_gcm();
  2988. #endif
  2989. #ifdef WOLFSSL_SM4_CCM
  2990. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2991. bench_sm4_ccm();
  2992. #endif
  2993. #ifndef NO_RC4
  2994. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2995. #ifndef NO_SW_BENCH
  2996. bench_arc4(0);
  2997. #endif
  2998. #ifdef BENCH_DEVID
  2999. bench_arc4(1);
  3000. #endif
  3001. }
  3002. #endif
  3003. #ifdef HAVE_CHACHA
  3004. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  3005. bench_chacha();
  3006. #endif
  3007. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  3008. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  3009. bench_chacha20_poly1305_aead();
  3010. #endif
  3011. #ifndef NO_DES3
  3012. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  3013. #ifndef NO_SW_BENCH
  3014. bench_des(0);
  3015. #endif
  3016. #ifdef BENCH_DEVID
  3017. bench_des(1);
  3018. #endif
  3019. }
  3020. #endif
  3021. #ifndef NO_MD5
  3022. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  3023. #ifndef NO_SW_BENCH
  3024. bench_md5(0);
  3025. #endif
  3026. #ifdef BENCH_DEVID
  3027. bench_md5(1);
  3028. #endif
  3029. }
  3030. #endif
  3031. #ifdef HAVE_POLY1305
  3032. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  3033. bench_poly1305();
  3034. #endif
  3035. #ifndef NO_SHA
  3036. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  3037. #ifndef NO_SW_BENCH
  3038. bench_sha(0);
  3039. #endif
  3040. #ifdef BENCH_DEVID
  3041. bench_sha(1);
  3042. #endif
  3043. }
  3044. #endif
  3045. #ifdef WOLFSSL_SHA224
  3046. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  3047. #ifndef NO_SW_BENCH
  3048. bench_sha224(0);
  3049. #endif
  3050. #ifdef BENCH_DEVID
  3051. bench_sha224(1);
  3052. #endif
  3053. }
  3054. #endif
  3055. #ifndef NO_SHA256
  3056. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  3057. #ifndef NO_SW_BENCH
  3058. bench_sha256(0);
  3059. #endif
  3060. #ifdef BENCH_DEVID
  3061. bench_sha256(1);
  3062. #endif
  3063. }
  3064. #endif
  3065. #ifdef WOLFSSL_SHA384
  3066. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3067. #ifndef NO_SW_BENCH
  3068. bench_sha384(0);
  3069. #endif
  3070. #ifdef BENCH_DEVID
  3071. bench_sha384(1);
  3072. #endif
  3073. }
  3074. #endif
  3075. #ifdef WOLFSSL_SHA512
  3076. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3077. #ifndef NO_SW_BENCH
  3078. bench_sha512(0);
  3079. #endif
  3080. #ifdef BENCH_DEVID
  3081. bench_sha512(1);
  3082. #endif
  3083. }
  3084. #if !defined(WOLFSSL_NOSHA512_224) && \
  3085. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3086. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3087. #ifndef NO_SW_BENCH
  3088. bench_sha512_224(0);
  3089. #endif
  3090. #ifdef BENCH_DEVID
  3091. bench_sha512_224(1);
  3092. #endif
  3093. }
  3094. #endif /* WOLFSSL_NOSHA512_224 */
  3095. #if !defined(WOLFSSL_NOSHA512_256) && \
  3096. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3097. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3098. #ifndef NO_SW_BENCH
  3099. bench_sha512_256(0);
  3100. #endif
  3101. #ifdef BENCH_DEVID
  3102. bench_sha512_256(1);
  3103. #endif
  3104. }
  3105. #endif /* WOLFSSL_NOSHA512_256 */
  3106. #endif /* WOLFSSL_SHA512 */
  3107. #ifdef WOLFSSL_SHA3
  3108. #ifndef WOLFSSL_NOSHA3_224
  3109. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3110. #ifndef NO_SW_BENCH
  3111. bench_sha3_224(0);
  3112. #endif
  3113. #ifdef BENCH_DEVID
  3114. bench_sha3_224(1);
  3115. #endif
  3116. }
  3117. #endif /* WOLFSSL_NOSHA3_224 */
  3118. #ifndef WOLFSSL_NOSHA3_256
  3119. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3120. #ifndef NO_SW_BENCH
  3121. bench_sha3_256(0);
  3122. #endif
  3123. #ifdef BENCH_DEVID
  3124. bench_sha3_256(1);
  3125. #endif
  3126. }
  3127. #endif /* WOLFSSL_NOSHA3_256 */
  3128. #ifndef WOLFSSL_NOSHA3_384
  3129. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3130. #ifndef NO_SW_BENCH
  3131. bench_sha3_384(0);
  3132. #endif
  3133. #ifdef BENCH_DEVID
  3134. bench_sha3_384(1);
  3135. #endif
  3136. }
  3137. #endif /* WOLFSSL_NOSHA3_384 */
  3138. #ifndef WOLFSSL_NOSHA3_512
  3139. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3140. #ifndef NO_SW_BENCH
  3141. bench_sha3_512(0);
  3142. #endif
  3143. #ifdef BENCH_DEVID
  3144. bench_sha3_512(1);
  3145. #endif
  3146. }
  3147. #endif /* WOLFSSL_NOSHA3_512 */
  3148. #ifdef WOLFSSL_SHAKE128
  3149. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3150. #ifndef NO_SW_BENCH
  3151. bench_shake128(0);
  3152. #endif
  3153. #ifdef BENCH_DEVID
  3154. bench_shake128(1);
  3155. #endif
  3156. }
  3157. #endif /* WOLFSSL_SHAKE128 */
  3158. #ifdef WOLFSSL_SHAKE256
  3159. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3160. #ifndef NO_SW_BENCH
  3161. bench_shake256(0);
  3162. #endif
  3163. #ifdef BENCH_DEVID
  3164. bench_shake256(1);
  3165. #endif
  3166. }
  3167. #endif /* WOLFSSL_SHAKE256 */
  3168. #endif
  3169. #ifdef WOLFSSL_SM3
  3170. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3171. #ifndef NO_SW_BENCH
  3172. bench_sm3(0);
  3173. #endif
  3174. #ifdef BENCH_DEVID
  3175. bench_sm3(1);
  3176. #endif
  3177. }
  3178. #endif
  3179. #ifdef WOLFSSL_RIPEMD
  3180. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3181. bench_ripemd();
  3182. #endif
  3183. #ifdef HAVE_BLAKE2
  3184. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3185. bench_blake2b();
  3186. #endif
  3187. #ifdef HAVE_BLAKE2S
  3188. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3189. bench_blake2s();
  3190. #endif
  3191. #ifdef WOLFSSL_CMAC
  3192. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3193. bench_cmac(0);
  3194. #ifdef BENCH_DEVID
  3195. bench_cmac(1);
  3196. #endif
  3197. }
  3198. #endif
  3199. #ifndef NO_HMAC
  3200. #ifndef NO_MD5
  3201. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3202. #ifndef NO_SW_BENCH
  3203. bench_hmac_md5(0);
  3204. #endif
  3205. #ifdef BENCH_DEVID
  3206. bench_hmac_md5(1);
  3207. #endif
  3208. }
  3209. #endif
  3210. #ifndef NO_SHA
  3211. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3212. #ifndef NO_SW_BENCH
  3213. bench_hmac_sha(0);
  3214. #endif
  3215. #ifdef BENCH_DEVID
  3216. bench_hmac_sha(1);
  3217. #endif
  3218. }
  3219. #endif
  3220. #ifdef WOLFSSL_SHA224
  3221. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3222. #ifndef NO_SW_BENCH
  3223. bench_hmac_sha224(0);
  3224. #endif
  3225. #ifdef BENCH_DEVID
  3226. bench_hmac_sha224(1);
  3227. #endif
  3228. }
  3229. #endif
  3230. #ifndef NO_SHA256
  3231. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3232. #ifndef NO_SW_BENCH
  3233. bench_hmac_sha256(0);
  3234. #endif
  3235. #ifdef BENCH_DEVID
  3236. bench_hmac_sha256(1);
  3237. #endif
  3238. }
  3239. #endif
  3240. #ifdef WOLFSSL_SHA384
  3241. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3242. #ifndef NO_SW_BENCH
  3243. bench_hmac_sha384(0);
  3244. #endif
  3245. #ifdef BENCH_DEVID
  3246. bench_hmac_sha384(1);
  3247. #endif
  3248. }
  3249. #endif
  3250. #ifdef WOLFSSL_SHA512
  3251. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3252. #ifndef NO_SW_BENCH
  3253. bench_hmac_sha512(0);
  3254. #endif
  3255. #ifdef BENCH_DEVID
  3256. bench_hmac_sha512(1);
  3257. #endif
  3258. }
  3259. #endif
  3260. #ifndef NO_PWDBASED
  3261. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3262. bench_pbkdf2();
  3263. }
  3264. #endif
  3265. #endif /* NO_HMAC */
  3266. #ifdef WOLFSSL_SIPHASH
  3267. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3268. bench_siphash();
  3269. }
  3270. #endif
  3271. #ifdef WC_SRTP_KDF
  3272. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3273. bench_srtpkdf();
  3274. }
  3275. #endif
  3276. #ifdef HAVE_SCRYPT
  3277. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3278. bench_scrypt();
  3279. #endif
  3280. #ifndef NO_RSA
  3281. #ifndef HAVE_RENESAS_SYNC
  3282. #ifdef WOLFSSL_KEY_GEN
  3283. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3284. #ifndef NO_SW_BENCH
  3285. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3286. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3287. bench_rsaKeyGen(0);
  3288. }
  3289. else {
  3290. bench_rsaKeyGen_size(0, bench_size);
  3291. }
  3292. #endif
  3293. #ifdef BENCH_DEVID
  3294. if (bench_asym_algs & BENCH_RSA_SZ) {
  3295. bench_rsaKeyGen_size(1, bench_size);
  3296. }
  3297. else {
  3298. bench_rsaKeyGen(1);
  3299. }
  3300. #endif
  3301. }
  3302. #endif
  3303. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3304. #ifndef NO_SW_BENCH
  3305. bench_rsa(0);
  3306. #endif
  3307. #ifdef BENCH_DEVID
  3308. bench_rsa(1);
  3309. #endif
  3310. }
  3311. #ifdef WOLFSSL_KEY_GEN
  3312. if (bench_asym_algs & BENCH_RSA_SZ) {
  3313. #ifndef NO_SW_BENCH
  3314. bench_rsa_key(0, bench_size);
  3315. #endif
  3316. #ifdef BENCH_DEVID
  3317. bench_rsa_key(1, bench_size);
  3318. #endif
  3319. }
  3320. #endif
  3321. #endif
  3322. #endif
  3323. #ifndef NO_DH
  3324. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3325. #ifndef NO_SW_BENCH
  3326. bench_dh(0);
  3327. #endif
  3328. #ifdef BENCH_DEVID
  3329. bench_dh(1);
  3330. #endif
  3331. }
  3332. #endif
  3333. #ifdef WOLFSSL_HAVE_KYBER
  3334. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3335. #ifndef WOLFSSL_NO_ML_KEM
  3336. #ifdef WOLFSSL_KYBER512
  3337. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3338. bench_kyber(WC_ML_KEM_512);
  3339. }
  3340. #endif
  3341. #ifdef WOLFSSL_KYBER768
  3342. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3343. bench_kyber(WC_ML_KEM_768);
  3344. }
  3345. #endif
  3346. #ifdef WOLFSSL_KYBER1024
  3347. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3348. bench_kyber(WC_ML_KEM_1024);
  3349. }
  3350. #endif
  3351. #endif
  3352. #ifdef WOLFSSL_KYBER_ORIGINAL
  3353. #ifdef WOLFSSL_KYBER512
  3354. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3355. bench_kyber(KYBER512);
  3356. }
  3357. #endif
  3358. #ifdef WOLFSSL_KYBER768
  3359. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3360. bench_kyber(KYBER768);
  3361. }
  3362. #endif
  3363. #ifdef WOLFSSL_KYBER1024
  3364. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3365. bench_kyber(KYBER1024);
  3366. }
  3367. #endif
  3368. #endif
  3369. }
  3370. #endif
  3371. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3372. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3373. bench_lms();
  3374. }
  3375. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3376. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3377. if (bench_all) {
  3378. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3379. }
  3380. #ifndef NO_SHA256
  3381. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3382. bench_xmss(WC_HASH_TYPE_SHA256);
  3383. }
  3384. #endif
  3385. #ifdef WOLFSSL_SHA512
  3386. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3387. bench_xmss(WC_HASH_TYPE_SHA512);
  3388. }
  3389. #endif
  3390. #ifdef WOLFSSL_SHAKE128
  3391. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3392. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3393. }
  3394. #endif
  3395. #ifdef WOLFSSL_SHAKE256
  3396. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3397. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3398. }
  3399. #endif
  3400. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3401. #ifdef HAVE_ECC
  3402. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3403. (bench_asym_algs & BENCH_ECC) ||
  3404. (bench_asym_algs & BENCH_ECC_ALL) ||
  3405. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3406. if (bench_asym_algs & BENCH_ECC_ALL) {
  3407. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3408. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3409. err_prefix);
  3410. #else
  3411. int curveId = (int)ECC_SECP192R1;
  3412. /* set make key and encrypt */
  3413. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3414. BENCH_ECC_ENCRYPT;
  3415. if (csv_format != 1) {
  3416. printf("\n%sECC Benchmarks:\n", info_prefix);
  3417. }
  3418. do {
  3419. #ifdef WOLFCRYPT_HAVE_SAKKE
  3420. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3421. if (curveId == ECC_SAKKE_1) {
  3422. curveId++;
  3423. continue;
  3424. }
  3425. #endif
  3426. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3427. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3428. bench_ecc_curve(curveId);
  3429. if (csv_format != 1) {
  3430. printf("\n");
  3431. }
  3432. }
  3433. curveId++;
  3434. } while (curveId != (int)ECC_CURVE_MAX);
  3435. #endif
  3436. }
  3437. else if (bench_asym_algs & BENCH_ECC_P256) {
  3438. bench_ecc_curve((int)ECC_SECP256R1);
  3439. }
  3440. else if (bench_asym_algs & BENCH_ECC_P384) {
  3441. bench_ecc_curve((int)ECC_SECP384R1);
  3442. }
  3443. else if (bench_asym_algs & BENCH_ECC_P521) {
  3444. bench_ecc_curve((int)ECC_SECP521R1);
  3445. }
  3446. else {
  3447. #ifndef NO_ECC256
  3448. bench_ecc_curve((int)ECC_SECP256R1);
  3449. #elif defined(HAVE_ECC384)
  3450. bench_ecc_curve((int)ECC_SECP384R1);
  3451. #elif defined(HAVE_ECC521)
  3452. bench_ecc_curve((int)ECC_SECP521R1);
  3453. #endif
  3454. #ifdef HAVE_ECC_BRAINPOOL
  3455. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3456. #endif
  3457. }
  3458. }
  3459. #endif
  3460. #ifdef WOLFSSL_SM2
  3461. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3462. bench_sm2(0);
  3463. }
  3464. #endif
  3465. #ifdef HAVE_CURVE25519
  3466. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3467. bench_curve25519KeyGen(0);
  3468. #ifdef BENCH_DEVID
  3469. bench_curve25519KeyGen(1);
  3470. #endif
  3471. }
  3472. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3473. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3474. bench_curve25519KeyAgree(0);
  3475. #ifdef BENCH_DEVID
  3476. bench_curve25519KeyAgree(1);
  3477. #endif
  3478. }
  3479. #endif
  3480. #endif
  3481. #ifdef HAVE_ED25519
  3482. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3483. bench_ed25519KeyGen();
  3484. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3485. bench_ed25519KeySign();
  3486. #endif
  3487. #ifdef HAVE_CURVE448
  3488. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3489. bench_curve448KeyGen();
  3490. #ifdef HAVE_CURVE448_SHARED_SECRET
  3491. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3492. bench_curve448KeyAgree();
  3493. #endif
  3494. #endif
  3495. #ifdef HAVE_ED448
  3496. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3497. bench_ed448KeyGen();
  3498. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3499. bench_ed448KeySign();
  3500. #endif
  3501. #ifdef WOLFCRYPT_HAVE_ECCSI
  3502. #ifdef WOLFCRYPT_ECCSI_KMS
  3503. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3504. bench_eccsiKeyGen();
  3505. }
  3506. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3507. bench_eccsiPairGen();
  3508. }
  3509. #endif
  3510. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3511. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3512. bench_eccsiValidate();
  3513. }
  3514. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3515. bench_eccsi();
  3516. }
  3517. #endif
  3518. #endif
  3519. #ifdef WOLFCRYPT_HAVE_SAKKE
  3520. #ifdef WOLFCRYPT_SAKKE_KMS
  3521. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3522. bench_sakkeKeyGen();
  3523. }
  3524. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3525. bench_sakkeRskGen();
  3526. }
  3527. #endif
  3528. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3529. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3530. bench_sakkeValidate();
  3531. }
  3532. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3533. bench_sakke();
  3534. }
  3535. #endif
  3536. #endif
  3537. #ifdef HAVE_FALCON
  3538. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3539. bench_falconKeySign(1);
  3540. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3541. bench_falconKeySign(5);
  3542. #endif
  3543. #ifdef HAVE_DILITHIUM
  3544. #ifndef WOLFSSL_NO_ML_DSA_44
  3545. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3546. bench_dilithiumKeySign(2);
  3547. #endif
  3548. #ifndef WOLFSSL_NO_ML_DSA_65
  3549. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3550. bench_dilithiumKeySign(3);
  3551. #endif
  3552. #ifndef WOLFSSL_NO_ML_DSA_87
  3553. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3554. bench_dilithiumKeySign(5);
  3555. #endif
  3556. #endif
  3557. #ifdef HAVE_SPHINCS
  3558. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3559. bench_sphincsKeySign(1, FAST_VARIANT);
  3560. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3561. bench_sphincsKeySign(3, FAST_VARIANT);
  3562. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3563. bench_sphincsKeySign(5, FAST_VARIANT);
  3564. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3565. bench_sphincsKeySign(1, SMALL_VARIANT);
  3566. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3567. bench_sphincsKeySign(3, SMALL_VARIANT);
  3568. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3569. bench_sphincsKeySign(5, SMALL_VARIANT);
  3570. #endif
  3571. exit:
  3572. /* free benchmark buffers */
  3573. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3574. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3575. #ifdef WOLFSSL_ASYNC_CRYPT
  3576. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3577. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3578. #endif
  3579. #if defined(HAVE_LOCAL_RNG)
  3580. wc_FreeRng(&gRng);
  3581. #endif
  3582. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3583. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3584. wc_ecc_fp_free();
  3585. #endif
  3586. (void)bench_cipher_algs;
  3587. (void)bench_digest_algs;
  3588. (void)bench_mac_algs;
  3589. (void)bench_asym_algs;
  3590. (void)bench_other_algs;
  3591. (void)bench_pq_asym_algs;
  3592. (void)bench_pq_asym_algs2;
  3593. return NULL;
  3594. }
  3595. int benchmark_init(void)
  3596. {
  3597. int ret = 0;
  3598. benchmark_static_init(0);
  3599. #ifdef WOLFSSL_STATIC_MEMORY
  3600. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3601. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3602. if (ret != 0) {
  3603. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3604. }
  3605. #endif /* WOLFSSL_STATIC_MEMORY */
  3606. if ((ret = wolfCrypt_Init()) != 0) {
  3607. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3608. return EXIT_FAILURE;
  3609. }
  3610. #ifdef HAVE_WC_INTROSPECTION
  3611. printf("Math: %s\n", wc_GetMathInfo());
  3612. #endif
  3613. #ifdef WOLFSSL_SECO_CAAM
  3614. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3615. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3616. != 0) {
  3617. printf("%sunable to open HSM\n", err_prefix);
  3618. wolfCrypt_Cleanup();
  3619. return EXIT_FAILURE;
  3620. }
  3621. #endif
  3622. #ifdef WC_RNG_SEED_CB
  3623. wc_SetSeed_Cb(wc_GenerateSeed);
  3624. #endif
  3625. bench_stats_init();
  3626. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3627. wolfSSL_Debugging_ON();
  3628. #endif
  3629. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3630. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3631. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3632. if (csv_format == 1) {
  3633. printf("This format allows you to easily copy "
  3634. "the output to a csv file.");
  3635. }
  3636. #endif
  3637. #ifdef HAVE_WNR
  3638. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3639. if (ret != 0) {
  3640. printf("%sWhitewood netRandom config init failed %d\n",
  3641. err_prefix, ret);
  3642. }
  3643. #endif /* HAVE_WNR */
  3644. return ret;
  3645. }
  3646. int benchmark_free(void)
  3647. {
  3648. int ret;
  3649. #ifdef WC_BENCH_TRACK_STATS
  3650. if (gPrintStats || devId != INVALID_DEVID) {
  3651. bench_stats_print();
  3652. }
  3653. #endif
  3654. bench_stats_free();
  3655. #ifdef WOLF_CRYPTO_CB
  3656. #ifdef HAVE_INTEL_QA_SYNC
  3657. wc_CryptoCb_CleanupIntelQa(&devId);
  3658. #endif
  3659. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3660. wc_CryptoCb_CleanupOcteon(&devId);
  3661. #endif
  3662. #ifdef HAVE_RENESAS_SYNC
  3663. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3664. #endif
  3665. #endif
  3666. #ifdef WOLFSSL_ASYNC_CRYPT
  3667. /* free event queue */
  3668. wolfEventQueue_Free(&eventQueue);
  3669. /* close device */
  3670. wolfAsync_DevClose(&devId);
  3671. #endif
  3672. #ifdef HAVE_WNR
  3673. ret = wc_FreeNetRandom();
  3674. if (ret < 0) {
  3675. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3676. }
  3677. #endif
  3678. #ifdef WOLFSSL_SECO_CAAM
  3679. if (wc_SECO_CloseHSM() != 0) {
  3680. printf("%sError closing down the key store\n", err_prefix);
  3681. }
  3682. #endif
  3683. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3684. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3685. }
  3686. return ret;
  3687. }
  3688. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3689. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3690. {
  3691. benchmark_test(args);
  3692. EXIT_TEST(0);
  3693. }
  3694. static int benchmark_test_threaded(void* args)
  3695. {
  3696. int i;
  3697. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3698. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3699. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3700. if (g_threadData == NULL) {
  3701. printf("%sThread data alloc failed!\n", err_prefix);
  3702. return EXIT_FAILURE;
  3703. }
  3704. for (i = 0; i < g_threadCount; i++) {
  3705. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3706. NULL, run_bench, args));
  3707. }
  3708. for (i = 0; i < g_threadCount; i++) {
  3709. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3710. }
  3711. printf("\n");
  3712. bench_stats_print();
  3713. return 0;
  3714. }
  3715. #endif
  3716. /* so embedded projects can pull in tests on their own */
  3717. #ifdef HAVE_STACK_SIZE
  3718. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3719. #else
  3720. int benchmark_test(void *args)
  3721. #endif
  3722. {
  3723. int ret;
  3724. (void)args;
  3725. #ifdef HAVE_FIPS
  3726. wolfCrypt_SetCb_fips(myFipsCb);
  3727. #endif
  3728. ret = benchmark_init();
  3729. if (ret != 0)
  3730. EXIT_TEST(ret);
  3731. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3732. {
  3733. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3734. **
  3735. ** Chapter Two, Build Options:
  3736. **
  3737. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3738. **
  3739. ** asynchronous cryptography using hardware based adapters such as
  3740. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3741. */
  3742. int i;
  3743. if (g_threadCount == 0) {
  3744. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3745. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3746. #else
  3747. g_threadCount = wc_AsyncGetNumberOfCpus();
  3748. if (g_threadCount > 0) {
  3749. g_threadCount /= 2; /* use physical core count */
  3750. }
  3751. #endif
  3752. }
  3753. if (g_threadCount <= 0) {
  3754. g_threadCount = 1;
  3755. }
  3756. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3757. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3758. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3759. if (g_threadData == NULL) {
  3760. printf("%sThread data alloc failed!\n", err_prefix);
  3761. EXIT_TEST(EXIT_FAILURE);
  3762. }
  3763. /* Create threads */
  3764. for (i = 0; i < g_threadCount; i++) {
  3765. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3766. benchmarks_do, &g_threadData[i]);
  3767. if (ret != 0) {
  3768. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3769. EXIT_TEST(EXIT_FAILURE);
  3770. }
  3771. }
  3772. /* Start threads */
  3773. for (i = 0; i < g_threadCount; i++) {
  3774. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3775. }
  3776. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3777. }
  3778. #else
  3779. benchmarks_do(NULL);
  3780. #endif
  3781. SLEEP_ON_ERROR(1);
  3782. printf("%sBenchmark complete\n", info_prefix);
  3783. ret = benchmark_free();
  3784. EXIT_TEST(ret);
  3785. }
  3786. #ifndef WC_NO_RNG
  3787. void bench_rng(void)
  3788. {
  3789. int ret, i, count;
  3790. double start;
  3791. long pos, len, remain;
  3792. WC_RNG myrng;
  3793. DECLARE_MULTI_VALUE_STATS_VARS()
  3794. #ifndef HAVE_FIPS
  3795. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3796. #else
  3797. ret = wc_InitRng(&myrng);
  3798. #endif
  3799. if (ret < 0) {
  3800. printf("InitRNG failed %d\n", ret);
  3801. return;
  3802. }
  3803. bench_stats_start(&count, &start);
  3804. do {
  3805. for (i = 0; i < numBlocks; i++) {
  3806. /* Split request to handle large RNG request */
  3807. pos = 0;
  3808. remain = (int)bench_size;
  3809. while (remain > 0) {
  3810. len = remain;
  3811. if (len > RNG_MAX_BLOCK_LEN)
  3812. len = RNG_MAX_BLOCK_LEN;
  3813. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3814. (word32)len);
  3815. if (ret < 0)
  3816. goto exit_rng;
  3817. remain -= len;
  3818. pos += len;
  3819. }
  3820. RECORD_MULTI_VALUE_STATS();
  3821. }
  3822. count += i;
  3823. } while (bench_stats_check(start)
  3824. #ifdef MULTI_VALUE_STATISTICS
  3825. || runs < minimum_runs
  3826. #endif
  3827. );
  3828. exit_rng:
  3829. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3830. #ifdef MULTI_VALUE_STATISTICS
  3831. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3832. #endif
  3833. wc_FreeRng(&myrng);
  3834. }
  3835. #endif /* WC_NO_RNG */
  3836. #ifndef NO_AES
  3837. #ifdef HAVE_AES_CBC
  3838. static void bench_aescbc_internal(int useDeviceID,
  3839. const byte* key, word32 keySz,
  3840. const byte* iv, const char* encLabel,
  3841. const char* decLabel)
  3842. {
  3843. const byte* in = bench_cipher;
  3844. byte* out = bench_plain;
  3845. int ret = 0, i, count = 0, times, pending = 0;
  3846. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3847. sizeof(Aes), HEAP_HINT);
  3848. double start;
  3849. DECLARE_MULTI_VALUE_STATS_VARS()
  3850. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3851. sizeof(Aes), HEAP_HINT);
  3852. /* init keys */
  3853. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3854. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3855. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3856. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3857. goto exit;
  3858. }
  3859. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3860. if (ret != 0) {
  3861. printf("AesSetKey failed, ret = %d\n", ret);
  3862. goto exit;
  3863. }
  3864. }
  3865. if (cipher_same_buffer) {
  3866. in = bench_plain;
  3867. }
  3868. bench_stats_start(&count, &start);
  3869. do {
  3870. for (times = 0; times < numBlocks || pending > 0; ) {
  3871. bench_async_poll(&pending);
  3872. /* while free pending slots in queue, submit ops */
  3873. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3874. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3875. &times, numBlocks, &pending)) {
  3876. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3877. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3878. 0, &times, &pending)) {
  3879. goto exit_aes_enc;
  3880. }
  3881. }
  3882. } /* for i */
  3883. RECORD_MULTI_VALUE_STATS();
  3884. } /* for times */
  3885. count += times;
  3886. } while (bench_stats_check(start)
  3887. #ifdef MULTI_VALUE_STATISTICS
  3888. || runs < minimum_runs
  3889. #endif
  3890. );
  3891. exit_aes_enc:
  3892. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3893. bench_size, start, ret);
  3894. #ifdef MULTI_VALUE_STATISTICS
  3895. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3896. #endif
  3897. if (ret < 0) {
  3898. goto exit;
  3899. }
  3900. #ifdef HAVE_AES_DECRYPT
  3901. /* init keys */
  3902. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3903. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3904. if (ret != 0) {
  3905. printf("AesSetKey failed, ret = %d\n", ret);
  3906. goto exit;
  3907. }
  3908. }
  3909. RESET_MULTI_VALUE_STATS_VARS();
  3910. bench_stats_start(&count, &start);
  3911. do {
  3912. for (times = 0; times < numBlocks || pending > 0; ) {
  3913. bench_async_poll(&pending);
  3914. /* while free pending slots in queue, submit ops */
  3915. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3916. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3917. &times, numBlocks, &pending)) {
  3918. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3919. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3920. 0, &times, &pending)) {
  3921. goto exit_aes_dec;
  3922. }
  3923. }
  3924. } /* for i */
  3925. RECORD_MULTI_VALUE_STATS();
  3926. } /* for times */
  3927. count += times;
  3928. } while (bench_stats_check(start)
  3929. #ifdef MULTI_VALUE_STATISTICS
  3930. || runs < minimum_runs
  3931. #endif
  3932. );
  3933. exit_aes_dec:
  3934. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3935. start, ret);
  3936. #ifdef MULTI_VALUE_STATISTICS
  3937. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3938. #endif
  3939. #endif /* HAVE_AES_DECRYPT */
  3940. (void)decLabel;
  3941. exit:
  3942. if (WC_ARRAY_OK(enc)) {
  3943. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3944. wc_AesFree(enc[i]);
  3945. }
  3946. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3947. }
  3948. }
  3949. void bench_aescbc(int useDeviceID)
  3950. {
  3951. #ifdef WOLFSSL_AES_128
  3952. #ifdef HAVE_RENESAS_SYNC
  3953. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3954. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3955. #else
  3956. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3957. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3958. #endif
  3959. #endif
  3960. #ifdef WOLFSSL_AES_192
  3961. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3962. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3963. #endif
  3964. #ifdef WOLFSSL_AES_256
  3965. #ifdef HAVE_RENESAS_SYNC
  3966. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3967. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3968. #else
  3969. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3970. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3971. #endif
  3972. #endif
  3973. }
  3974. #endif /* HAVE_AES_CBC */
  3975. #ifdef HAVE_AESGCM
  3976. static void bench_aesgcm_internal(int useDeviceID,
  3977. const byte* key, word32 keySz,
  3978. const byte* iv, word32 ivSz,
  3979. const char* encLabel, const char* decLabel)
  3980. {
  3981. int ret = 0, i, count = 0, times, pending = 0;
  3982. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3983. sizeof(Aes), HEAP_HINT);
  3984. #ifdef HAVE_AES_DECRYPT
  3985. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3986. sizeof(Aes), HEAP_HINT);
  3987. #endif
  3988. double start;
  3989. DECLARE_MULTI_VALUE_STATS_VARS()
  3990. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3991. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3992. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3993. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3994. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3995. sizeof(Aes), HEAP_HINT);
  3996. #ifdef HAVE_AES_DECRYPT
  3997. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3998. sizeof(Aes), HEAP_HINT);
  3999. #endif
  4000. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4001. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4002. /* init keys */
  4003. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4004. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4005. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4006. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4007. goto exit;
  4008. }
  4009. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4010. if (ret != 0) {
  4011. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4012. goto exit;
  4013. }
  4014. }
  4015. /* GCM uses same routine in backend for both encrypt and decrypt */
  4016. bench_stats_start(&count, &start);
  4017. do {
  4018. for (times = 0; times < numBlocks || pending > 0; ) {
  4019. bench_async_poll(&pending);
  4020. /* while free pending slots in queue, submit ops */
  4021. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4022. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4023. &times, numBlocks, &pending)) {
  4024. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  4025. bench_plain, bench_size,
  4026. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4027. bench_additional, aesAuthAddSz);
  4028. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4029. 0, &times, &pending)) {
  4030. goto exit_aes_gcm;
  4031. }
  4032. }
  4033. } /* for i */
  4034. RECORD_MULTI_VALUE_STATS();
  4035. } /* for times */
  4036. count += times;
  4037. } while (bench_stats_check(start)
  4038. #ifdef MULTI_VALUE_STATISTICS
  4039. || runs < minimum_runs
  4040. #endif
  4041. );
  4042. exit_aes_gcm:
  4043. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4044. start, ret);
  4045. #ifdef MULTI_VALUE_STATISTICS
  4046. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4047. #endif
  4048. #ifdef HAVE_AES_DECRYPT
  4049. RESET_MULTI_VALUE_STATS_VARS();
  4050. /* init keys */
  4051. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4052. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4053. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4054. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4055. goto exit;
  4056. }
  4057. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4058. if (ret != 0) {
  4059. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4060. goto exit;
  4061. }
  4062. }
  4063. bench_stats_start(&count, &start);
  4064. do {
  4065. for (times = 0; times < numBlocks || pending > 0; ) {
  4066. bench_async_poll(&pending);
  4067. /* while free pending slots in queue, submit ops */
  4068. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4069. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4070. &times, numBlocks, &pending)) {
  4071. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4072. bench_cipher, bench_size,
  4073. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4074. bench_additional, aesAuthAddSz);
  4075. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4076. 0, &times, &pending)) {
  4077. goto exit_aes_gcm_dec;
  4078. }
  4079. }
  4080. } /* for i */
  4081. RECORD_MULTI_VALUE_STATS();
  4082. } /* for times */
  4083. count += times;
  4084. } while (bench_stats_check(start)
  4085. #ifdef MULTI_VALUE_STATISTICS
  4086. || runs < minimum_runs
  4087. #endif
  4088. );
  4089. exit_aes_gcm_dec:
  4090. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4091. start, ret);
  4092. #ifdef MULTI_VALUE_STATISTICS
  4093. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4094. #endif
  4095. #endif /* HAVE_AES_DECRYPT */
  4096. (void)decLabel;
  4097. exit:
  4098. if (ret < 0) {
  4099. printf("bench_aesgcm failed: %d\n", ret);
  4100. }
  4101. #ifdef HAVE_AES_DECRYPT
  4102. if (WC_ARRAY_OK(dec)) {
  4103. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4104. wc_AesFree(dec[i]);
  4105. }
  4106. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4107. }
  4108. #endif
  4109. if (WC_ARRAY_OK(enc)) {
  4110. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4111. wc_AesFree(enc[i]);
  4112. }
  4113. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4114. }
  4115. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4116. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4117. }
  4118. #ifdef WOLFSSL_AESGCM_STREAM
  4119. static void bench_aesgcm_stream_internal(int useDeviceID,
  4120. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4121. const char* encLabel, const char* decLabel)
  4122. {
  4123. int ret = 0, i, count = 0, times, pending = 0;
  4124. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4125. sizeof(Aes), HEAP_HINT);
  4126. #ifdef HAVE_AES_DECRYPT
  4127. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4128. sizeof(Aes), HEAP_HINT);
  4129. #endif
  4130. double start;
  4131. DECLARE_MULTI_VALUE_STATS_VARS()
  4132. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4133. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4134. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4135. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4136. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4137. sizeof(Aes), HEAP_HINT);
  4138. #ifdef HAVE_AES_DECRYPT
  4139. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4140. sizeof(Aes), HEAP_HINT);
  4141. #endif
  4142. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4143. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4144. /* init keys */
  4145. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4146. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4147. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4148. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4149. goto exit;
  4150. }
  4151. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4152. if (ret != 0) {
  4153. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4154. goto exit;
  4155. }
  4156. }
  4157. /* GCM uses same routine in backend for both encrypt and decrypt */
  4158. bench_stats_start(&count, &start);
  4159. do {
  4160. for (times = 0; times < numBlocks || pending > 0; ) {
  4161. bench_async_poll(&pending);
  4162. /* while free pending slots in queue, submit ops */
  4163. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4164. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4165. &times, numBlocks, &pending)) {
  4166. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4167. if (ret == 0) {
  4168. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4169. bench_plain, bench_size, bench_additional,
  4170. aesAuthAddSz);
  4171. }
  4172. if (ret == 0) {
  4173. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4174. AES_AUTH_TAG_SZ);
  4175. }
  4176. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4177. 0, &times, &pending)) {
  4178. goto exit_aes_gcm;
  4179. }
  4180. }
  4181. } /* for i */
  4182. RECORD_MULTI_VALUE_STATS();
  4183. } /* for times */
  4184. count += times;
  4185. } while (bench_stats_check(start)
  4186. #ifdef MULTI_VALUE_STATISTICS
  4187. || runs < minimum_runs
  4188. #endif
  4189. );
  4190. exit_aes_gcm:
  4191. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4192. start, ret);
  4193. #ifdef MULTI_VALUE_STATISTICS
  4194. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4195. #endif
  4196. #ifdef HAVE_AES_DECRYPT
  4197. /* init keys */
  4198. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4199. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4200. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4201. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4202. goto exit;
  4203. }
  4204. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4205. if (ret != 0) {
  4206. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4207. goto exit;
  4208. }
  4209. }
  4210. RESET_MULTI_VALUE_STATS_VARS();
  4211. bench_stats_start(&count, &start);
  4212. do {
  4213. for (times = 0; times < numBlocks || pending > 0; ) {
  4214. bench_async_poll(&pending);
  4215. /* while free pending slots in queue, submit ops */
  4216. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4217. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4218. &times, numBlocks, &pending)) {
  4219. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4220. if (ret == 0) {
  4221. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4222. bench_cipher, bench_size, bench_additional,
  4223. aesAuthAddSz);
  4224. }
  4225. if (ret == 0) {
  4226. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4227. AES_AUTH_TAG_SZ);
  4228. }
  4229. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4230. 0, &times, &pending)) {
  4231. goto exit_aes_gcm_dec;
  4232. }
  4233. }
  4234. } /* for i */
  4235. RECORD_MULTI_VALUE_STATS();
  4236. } /* for times */
  4237. count += times;
  4238. } while (bench_stats_check(start)
  4239. #ifdef MULTI_VALUE_STATISTICS
  4240. || runs < minimum_runs
  4241. #endif
  4242. );
  4243. exit_aes_gcm_dec:
  4244. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4245. start, ret);
  4246. #ifdef MULTI_VALUE_STATISTICS
  4247. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4248. #endif
  4249. #endif /* HAVE_AES_DECRYPT */
  4250. (void)decLabel;
  4251. exit:
  4252. if (ret < 0) {
  4253. printf("bench_aesgcm failed: %d\n", ret);
  4254. }
  4255. #ifdef HAVE_AES_DECRYPT
  4256. if (WC_ARRAY_OK(dec)) {
  4257. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4258. wc_AesFree(dec[i]);
  4259. }
  4260. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4261. }
  4262. #endif
  4263. if (WC_ARRAY_OK(enc)) {
  4264. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4265. wc_AesFree(enc[i]);
  4266. }
  4267. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4268. }
  4269. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4270. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4271. }
  4272. #endif
  4273. void bench_aesgcm(int useDeviceID)
  4274. {
  4275. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4276. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4277. && !defined(WOLFSSL_XILINX_CRYPT) \
  4278. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4279. #ifdef HAVE_RENESAS_SYNC
  4280. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4281. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4282. #else
  4283. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4284. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4285. #endif
  4286. #endif
  4287. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4288. && !defined(WOLFSSL_XILINX_CRYPT)
  4289. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4290. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4291. #endif
  4292. #ifdef WOLFSSL_AES_256
  4293. #ifdef HAVE_RENESAS_SYNC
  4294. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4295. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4296. #else
  4297. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4298. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4299. #endif
  4300. #endif
  4301. #ifdef WOLFSSL_AESGCM_STREAM
  4302. #undef AES_GCM_STRING
  4303. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4304. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4305. && !defined(WOLFSSL_XILINX_CRYPT) \
  4306. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4307. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4308. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4309. #endif
  4310. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4311. && !defined(WOLFSSL_XILINX_CRYPT)
  4312. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4313. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4314. #endif
  4315. #ifdef WOLFSSL_AES_256
  4316. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4317. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4318. #endif
  4319. #endif /* WOLFSSL_AESGCM_STREAM */
  4320. #undef AES_GCM_STRING
  4321. }
  4322. /* GMAC */
  4323. void bench_gmac(int useDeviceID)
  4324. {
  4325. int ret, count = 0;
  4326. Gmac gmac;
  4327. double start;
  4328. byte tag[AES_AUTH_TAG_SZ];
  4329. DECLARE_MULTI_VALUE_STATS_VARS()
  4330. /* determine GCM GHASH method */
  4331. #ifdef GCM_SMALL
  4332. const char* gmacStr = "GMAC Small";
  4333. #elif defined(GCM_TABLE)
  4334. const char* gmacStr = "GMAC Table";
  4335. #elif defined(GCM_TABLE_4BIT)
  4336. const char* gmacStr = "GMAC Table 4-bit";
  4337. #elif defined(GCM_WORD32)
  4338. const char* gmacStr = "GMAC Word32";
  4339. #else
  4340. const char* gmacStr = "GMAC Default";
  4341. #endif
  4342. /* Implementations of /Dev/Crypto will error out if the size of Auth in is */
  4343. /* greater than the system's page size */
  4344. #if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
  4345. bench_size = WOLFSSL_AUTHSZ_BENCH;
  4346. #elif defined(WOLFSSL_DEVCRYPTO)
  4347. bench_size = sysconf(_SC_PAGESIZE);
  4348. #endif
  4349. /* init keys */
  4350. XMEMSET(bench_plain, 0, bench_size);
  4351. XMEMSET(tag, 0, sizeof(tag));
  4352. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4353. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4354. useDeviceID ? devId: INVALID_DEVID);
  4355. #ifdef HAVE_RENESAS_SYNC
  4356. wc_GmacSetKey(&gmac, bench_key1, 16);
  4357. #else
  4358. wc_GmacSetKey(&gmac, bench_key, 16);
  4359. #endif
  4360. bench_stats_start(&count, &start);
  4361. do {
  4362. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4363. tag, sizeof(tag));
  4364. count++;
  4365. RECORD_MULTI_VALUE_STATS();
  4366. } while (bench_stats_check(start)
  4367. #ifdef MULTI_VALUE_STATISTICS
  4368. || runs < minimum_runs
  4369. #endif
  4370. );
  4371. wc_AesFree((Aes*)&gmac);
  4372. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4373. #ifdef MULTI_VALUE_STATISTICS
  4374. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4375. #endif
  4376. #if defined(WOLFSSL_DEVCRYPTO)
  4377. if (ret != 0 && (bench_size > sysconf(_SC_PAGESIZE))) {
  4378. printf("authIn Buffer Size[%d] greater than System Page Size[%ld]\n",
  4379. bench_size, sysconf(_SC_PAGESIZE));
  4380. }
  4381. bench_size = BENCH_SIZE;
  4382. #endif
  4383. }
  4384. #endif /* HAVE_AESGCM */
  4385. #ifdef HAVE_AES_ECB
  4386. static void bench_aesecb_internal(int useDeviceID,
  4387. const byte* key, word32 keySz,
  4388. const char* encLabel, const char* decLabel)
  4389. {
  4390. int ret = 0, i, count = 0, times, pending = 0;
  4391. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4392. sizeof(Aes), HEAP_HINT);
  4393. double start;
  4394. DECLARE_MULTI_VALUE_STATS_VARS()
  4395. #ifdef HAVE_FIPS
  4396. const word32 benchSz = WC_AES_BLOCK_SIZE;
  4397. #else
  4398. const word32 benchSz = bench_size;
  4399. #endif
  4400. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4401. sizeof(Aes), HEAP_HINT);
  4402. /* init keys */
  4403. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4404. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4405. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4406. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4407. goto exit;
  4408. }
  4409. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4410. if (ret != 0) {
  4411. printf("AesSetKey failed, ret = %d\n", ret);
  4412. goto exit;
  4413. }
  4414. }
  4415. bench_stats_start(&count, &start);
  4416. do {
  4417. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4418. for (times = 0;
  4419. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4420. ) {
  4421. bench_async_poll(&pending);
  4422. /* while free pending slots in queue, submit ops */
  4423. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4424. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4425. &times, outer_loop_limit, &pending)) {
  4426. #ifdef HAVE_FIPS
  4427. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4428. #else
  4429. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4430. benchSz);
  4431. #endif
  4432. ret = 0;
  4433. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4434. 0, &times, &pending)) {
  4435. goto exit_aes_enc;
  4436. }
  4437. }
  4438. } /* for i */
  4439. RECORD_MULTI_VALUE_STATS();
  4440. } /* for times */
  4441. count += times;
  4442. } while (bench_stats_check(start)
  4443. #ifdef MULTI_VALUE_STATISTICS
  4444. || runs < minimum_runs
  4445. #endif
  4446. );
  4447. exit_aes_enc:
  4448. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4449. start, ret);
  4450. #ifdef MULTI_VALUE_STATISTICS
  4451. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4452. #endif
  4453. #ifdef HAVE_AES_DECRYPT
  4454. /* init keys */
  4455. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4456. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4457. if (ret != 0) {
  4458. printf("AesSetKey failed, ret = %d\n", ret);
  4459. goto exit;
  4460. }
  4461. }
  4462. RESET_MULTI_VALUE_STATS_VARS();
  4463. bench_stats_start(&count, &start);
  4464. do {
  4465. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4466. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4467. bench_async_poll(&pending);
  4468. /* while free pending slots in queue, submit ops */
  4469. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4470. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4471. &times, outer_loop_limit, &pending)) {
  4472. #ifdef HAVE_FIPS
  4473. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4474. #else
  4475. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4476. benchSz);
  4477. #endif
  4478. ret = 0;
  4479. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4480. 0, &times, &pending)) {
  4481. goto exit_aes_dec;
  4482. }
  4483. }
  4484. } /* for i */
  4485. RECORD_MULTI_VALUE_STATS();
  4486. } /* for times */
  4487. count += times;
  4488. } while (bench_stats_check(start)
  4489. #ifdef MULTI_VALUE_STATISTICS
  4490. || runs < minimum_runs
  4491. #endif
  4492. );
  4493. exit_aes_dec:
  4494. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4495. start, ret);
  4496. #ifdef MULTI_VALUE_STATISTICS
  4497. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4498. #endif
  4499. #endif /* HAVE_AES_DECRYPT */
  4500. (void)decLabel;
  4501. exit:
  4502. if (WC_ARRAY_OK(enc)) {
  4503. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4504. wc_AesFree(enc[i]);
  4505. }
  4506. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4507. }
  4508. }
  4509. void bench_aesecb(int useDeviceID)
  4510. {
  4511. #ifdef WOLFSSL_AES_128
  4512. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4513. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4514. #endif
  4515. #ifdef WOLFSSL_AES_192
  4516. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4517. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4518. #endif
  4519. #ifdef WOLFSSL_AES_256
  4520. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4521. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4522. #endif
  4523. }
  4524. #endif /* HAVE_AES_ECB */
  4525. #ifdef WOLFSSL_AES_CFB
  4526. static void bench_aescfb_internal(const byte* key,
  4527. word32 keySz, const byte* iv,
  4528. const char* label)
  4529. {
  4530. Aes enc;
  4531. double start;
  4532. int i, ret, count;
  4533. DECLARE_MULTI_VALUE_STATS_VARS()
  4534. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4535. if (ret != 0) {
  4536. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4537. return;
  4538. }
  4539. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4540. if (ret != 0) {
  4541. printf("AesSetKey failed, ret = %d\n", ret);
  4542. goto out;
  4543. }
  4544. bench_stats_start(&count, &start);
  4545. do {
  4546. for (i = 0; i < numBlocks; i++) {
  4547. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4548. bench_size)) != 0) {
  4549. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4550. goto out;
  4551. }
  4552. RECORD_MULTI_VALUE_STATS();
  4553. }
  4554. count += i;
  4555. } while (bench_stats_check(start)
  4556. #ifdef MULTI_VALUE_STATISTICS
  4557. || runs < minimum_runs
  4558. #endif
  4559. );
  4560. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4561. #ifdef MULTI_VALUE_STATISTICS
  4562. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4563. #endif
  4564. out:
  4565. wc_AesFree(&enc);
  4566. return;
  4567. }
  4568. void bench_aescfb(void)
  4569. {
  4570. #ifdef WOLFSSL_AES_128
  4571. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4572. #endif
  4573. #ifdef WOLFSSL_AES_192
  4574. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4575. #endif
  4576. #ifdef WOLFSSL_AES_256
  4577. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4578. #endif
  4579. }
  4580. #endif /* WOLFSSL_AES_CFB */
  4581. #ifdef WOLFSSL_AES_OFB
  4582. static void bench_aesofb_internal(const byte* key,
  4583. word32 keySz, const byte* iv,
  4584. const char* label)
  4585. {
  4586. Aes enc;
  4587. double start;
  4588. int i, ret, count;
  4589. DECLARE_MULTI_VALUE_STATS_VARS()
  4590. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4591. if (ret != 0) {
  4592. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4593. return;
  4594. }
  4595. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4596. if (ret != 0) {
  4597. printf("AesSetKey failed, ret = %d\n", ret);
  4598. return;
  4599. }
  4600. bench_stats_start(&count, &start);
  4601. do {
  4602. for (i = 0; i < numBlocks; i++) {
  4603. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4604. bench_size)) != 0) {
  4605. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4606. return;
  4607. }
  4608. RECORD_MULTI_VALUE_STATS();
  4609. }
  4610. count += i;
  4611. } while (bench_stats_check(start)
  4612. #ifdef MULTI_VALUE_STATISTICS
  4613. || runs < minimum_runs
  4614. #endif
  4615. );
  4616. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4617. #ifdef MULTI_VALUE_STATISTICS
  4618. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4619. #endif
  4620. wc_AesFree(&enc);
  4621. }
  4622. void bench_aesofb(void)
  4623. {
  4624. #ifdef WOLFSSL_AES_128
  4625. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4626. #endif
  4627. #ifdef WOLFSSL_AES_192
  4628. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4629. #endif
  4630. #ifdef WOLFSSL_AES_256
  4631. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4632. #endif
  4633. }
  4634. #endif /* WOLFSSL_AES_CFB */
  4635. #ifdef WOLFSSL_AES_XTS
  4636. void bench_aesxts(void)
  4637. {
  4638. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4639. double start;
  4640. int i, count, ret;
  4641. DECLARE_MULTI_VALUE_STATS_VARS()
  4642. static const unsigned char k1[] = {
  4643. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4644. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4645. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4646. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4647. };
  4648. static const unsigned char i1[] = {
  4649. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4650. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4651. };
  4652. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4653. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4654. HEAP_HINT, devId);
  4655. if (ret != 0) {
  4656. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4657. goto exit;
  4658. }
  4659. bench_stats_start(&count, &start);
  4660. do {
  4661. for (i = 0; i < numBlocks; i++) {
  4662. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4663. bench_size, i1, sizeof(i1))) != 0) {
  4664. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4665. goto exit;
  4666. }
  4667. RECORD_MULTI_VALUE_STATS();
  4668. }
  4669. count += i;
  4670. } while (bench_stats_check(start)
  4671. #ifdef MULTI_VALUE_STATISTICS
  4672. || runs < minimum_runs
  4673. #endif
  4674. );
  4675. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4676. #ifdef MULTI_VALUE_STATISTICS
  4677. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4678. #endif
  4679. wc_AesXtsFree(aes);
  4680. /* decryption benchmark */
  4681. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4682. HEAP_HINT, devId);
  4683. if (ret != 0) {
  4684. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4685. goto exit;
  4686. }
  4687. RESET_MULTI_VALUE_STATS_VARS();
  4688. bench_stats_start(&count, &start);
  4689. do {
  4690. for (i = 0; i < numBlocks; i++) {
  4691. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4692. bench_size, i1, sizeof(i1))) != 0) {
  4693. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4694. goto exit;
  4695. }
  4696. RECORD_MULTI_VALUE_STATS();
  4697. }
  4698. count += i;
  4699. } while (bench_stats_check(start)
  4700. #ifdef MULTI_VALUE_STATISTICS
  4701. || runs < minimum_runs
  4702. #endif
  4703. );
  4704. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4705. #ifdef MULTI_VALUE_STATISTICS
  4706. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4707. #endif
  4708. exit:
  4709. wc_AesXtsFree(aes);
  4710. WC_FREE_VAR(aes, HEAP_HINT);
  4711. }
  4712. #endif /* WOLFSSL_AES_XTS */
  4713. #ifdef WOLFSSL_AES_COUNTER
  4714. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4715. const byte* iv, const char* label,
  4716. int useDeviceID)
  4717. {
  4718. Aes enc;
  4719. double start;
  4720. int i, count, ret = 0;
  4721. DECLARE_MULTI_VALUE_STATS_VARS()
  4722. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4723. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4724. printf("wc_AesInit failed, ret = %d\n", ret);
  4725. }
  4726. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4727. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4728. return;
  4729. }
  4730. bench_stats_start(&count, &start);
  4731. do {
  4732. for (i = 0; i < numBlocks; i++) {
  4733. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4734. bench_size)) != 0) {
  4735. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4736. return;
  4737. }
  4738. RECORD_MULTI_VALUE_STATS();
  4739. }
  4740. count += i;
  4741. } while (bench_stats_check(start)
  4742. #ifdef MULTI_VALUE_STATISTICS
  4743. || runs < minimum_runs
  4744. #endif
  4745. );
  4746. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4747. #ifdef MULTI_VALUE_STATISTICS
  4748. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4749. #endif
  4750. wc_AesFree(&enc);
  4751. }
  4752. void bench_aesctr(int useDeviceID)
  4753. {
  4754. #ifdef WOLFSSL_AES_128
  4755. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4756. #endif
  4757. #ifdef WOLFSSL_AES_192
  4758. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4759. #endif
  4760. #ifdef WOLFSSL_AES_256
  4761. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4762. #endif
  4763. }
  4764. #endif /* WOLFSSL_AES_COUNTER */
  4765. #ifdef HAVE_AESCCM
  4766. void bench_aesccm(int useDeviceID)
  4767. {
  4768. Aes enc;
  4769. int enc_inited = 0;
  4770. double start;
  4771. int ret, i, count;
  4772. DECLARE_MULTI_VALUE_STATS_VARS()
  4773. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4774. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4775. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4776. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4777. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4778. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4779. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4780. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4781. {
  4782. printf("wc_AesInit failed, ret = %d\n", ret);
  4783. goto exit;
  4784. }
  4785. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4786. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4787. goto exit;
  4788. }
  4789. enc_inited = 1;
  4790. bench_stats_start(&count, &start);
  4791. do {
  4792. for (i = 0; i < numBlocks; i++) {
  4793. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4794. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4795. bench_additional, 0);
  4796. RECORD_MULTI_VALUE_STATS();
  4797. }
  4798. count += i;
  4799. } while (bench_stats_check(start)
  4800. #ifdef MULTI_VALUE_STATISTICS
  4801. || runs < minimum_runs
  4802. #endif
  4803. );
  4804. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4805. bench_size, start, ret);
  4806. #ifdef MULTI_VALUE_STATISTICS
  4807. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4808. #endif
  4809. if (ret != 0) {
  4810. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4811. goto exit;
  4812. }
  4813. #ifdef HAVE_AES_DECRYPT
  4814. RESET_MULTI_VALUE_STATS_VARS();
  4815. bench_stats_start(&count, &start);
  4816. do {
  4817. for (i = 0; i < numBlocks; i++) {
  4818. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4819. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4820. bench_additional, 0);
  4821. RECORD_MULTI_VALUE_STATS();
  4822. }
  4823. count += i;
  4824. } while (bench_stats_check(start)
  4825. #ifdef MULTI_VALUE_STATISTICS
  4826. || runs < minimum_runs
  4827. #endif
  4828. );
  4829. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4830. bench_size, start, ret);
  4831. #ifdef MULTI_VALUE_STATISTICS
  4832. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4833. #endif
  4834. if (ret != 0) {
  4835. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4836. goto exit;
  4837. }
  4838. #endif
  4839. exit:
  4840. if (enc_inited)
  4841. wc_AesFree(&enc);
  4842. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4843. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4844. }
  4845. #endif /* HAVE_AESCCM */
  4846. #ifdef WOLFSSL_AES_SIV
  4847. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4848. encLabel, const char* decLabel)
  4849. {
  4850. int i;
  4851. int ret = 0;
  4852. byte assoc[WC_AES_BLOCK_SIZE];
  4853. byte nonce[WC_AES_BLOCK_SIZE];
  4854. byte siv[WC_AES_BLOCK_SIZE];
  4855. int count = 0;
  4856. double start;
  4857. DECLARE_MULTI_VALUE_STATS_VARS()
  4858. bench_stats_start(&count, &start);
  4859. do {
  4860. for (i = 0; i < numBlocks; i++) {
  4861. ret = wc_AesSivEncrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4862. WC_AES_BLOCK_SIZE, bench_plain, bench_size,
  4863. siv, bench_cipher);
  4864. if (ret != 0) {
  4865. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4866. return;
  4867. }
  4868. RECORD_MULTI_VALUE_STATS();
  4869. }
  4870. count += i;
  4871. } while (bench_stats_check(start)
  4872. #ifdef MULTI_VALUE_STATISTICS
  4873. || runs < minimum_runs
  4874. #endif
  4875. );
  4876. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4877. #ifdef MULTI_VALUE_STATISTICS
  4878. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4879. #endif
  4880. RESET_MULTI_VALUE_STATS_VARS();
  4881. bench_stats_start(&count, &start);
  4882. do {
  4883. for (i = 0; i < numBlocks; i++) {
  4884. ret = wc_AesSivDecrypt(key, keySz, assoc, WC_AES_BLOCK_SIZE, nonce,
  4885. WC_AES_BLOCK_SIZE, bench_cipher, bench_size,
  4886. siv, bench_plain);
  4887. if (ret != 0) {
  4888. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4889. return;
  4890. }
  4891. RECORD_MULTI_VALUE_STATS();
  4892. }
  4893. count += i;
  4894. } while (bench_stats_check(start)
  4895. #ifdef MULTI_VALUE_STATISTICS
  4896. || runs < minimum_runs
  4897. #endif
  4898. );
  4899. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4900. #ifdef MULTI_VALUE_STATISTICS
  4901. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4902. #endif
  4903. }
  4904. void bench_aessiv(void)
  4905. {
  4906. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4907. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4908. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4909. }
  4910. #endif /* WOLFSSL_AES_SIV */
  4911. #endif /* !NO_AES */
  4912. #ifdef HAVE_POLY1305
  4913. void bench_poly1305(void)
  4914. {
  4915. Poly1305 enc;
  4916. byte mac[16];
  4917. double start;
  4918. int ret = 0, i, count;
  4919. DECLARE_MULTI_VALUE_STATS_VARS()
  4920. if (digest_stream) {
  4921. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4922. if (ret != 0) {
  4923. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4924. return;
  4925. }
  4926. bench_stats_start(&count, &start);
  4927. do {
  4928. for (i = 0; i < numBlocks; i++) {
  4929. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4930. if (ret != 0) {
  4931. printf("Poly1305Update failed: %d\n", ret);
  4932. break;
  4933. }
  4934. RECORD_MULTI_VALUE_STATS();
  4935. }
  4936. wc_Poly1305Final(&enc, mac);
  4937. count += i;
  4938. } while (bench_stats_check(start)
  4939. #ifdef MULTI_VALUE_STATISTICS
  4940. || runs < minimum_runs
  4941. #endif
  4942. );
  4943. }
  4944. else {
  4945. bench_stats_start(&count, &start);
  4946. do {
  4947. for (i = 0; i < numBlocks; i++) {
  4948. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4949. if (ret != 0) {
  4950. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4951. return;
  4952. }
  4953. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4954. if (ret != 0) {
  4955. printf("Poly1305Update failed: %d\n", ret);
  4956. break;
  4957. }
  4958. wc_Poly1305Final(&enc, mac);
  4959. RECORD_MULTI_VALUE_STATS();
  4960. }
  4961. count += i;
  4962. } while (bench_stats_check(start)
  4963. #ifdef MULTI_VALUE_STATISTICS
  4964. || runs < minimum_runs
  4965. #endif
  4966. );
  4967. }
  4968. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4969. #ifdef MULTI_VALUE_STATISTICS
  4970. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4971. #endif
  4972. }
  4973. #endif /* HAVE_POLY1305 */
  4974. #ifdef HAVE_CAMELLIA
  4975. void bench_camellia(void)
  4976. {
  4977. wc_Camellia cam;
  4978. double start;
  4979. int ret, i, count;
  4980. DECLARE_MULTI_VALUE_STATS_VARS()
  4981. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4982. if (ret != 0) {
  4983. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4984. return;
  4985. }
  4986. bench_stats_start(&count, &start);
  4987. do {
  4988. for (i = 0; i < numBlocks; i++) {
  4989. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4990. bench_size);
  4991. if (ret < 0) {
  4992. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4993. return;
  4994. }
  4995. RECORD_MULTI_VALUE_STATS();
  4996. }
  4997. count += i;
  4998. } while (bench_stats_check(start)
  4999. #ifdef MULTI_VALUE_STATISTICS
  5000. || runs < minimum_runs
  5001. #endif
  5002. );
  5003. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  5004. #ifdef MULTI_VALUE_STATISTICS
  5005. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5006. #endif
  5007. }
  5008. #endif
  5009. #ifdef WOLFSSL_SM4_CBC
  5010. void bench_sm4_cbc(void)
  5011. {
  5012. wc_Sm4 sm4;
  5013. double start;
  5014. int ret;
  5015. int i;
  5016. int count;
  5017. DECLARE_MULTI_VALUE_STATS_VARS()
  5018. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5019. if (ret != 0) {
  5020. printf("Sm4SetKey failed, ret = %d\n", ret);
  5021. return;
  5022. }
  5023. ret = wc_Sm4SetIV(&sm4, bench_iv);
  5024. if (ret != 0) {
  5025. printf("Sm4SetIV failed, ret = %d\n", ret);
  5026. return;
  5027. }
  5028. bench_stats_start(&count, &start);
  5029. do {
  5030. for (i = 0; i < numBlocks; i++) {
  5031. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  5032. if (ret < 0) {
  5033. printf("Sm4CbcEncrypt failed: %d\n", ret);
  5034. return;
  5035. }
  5036. RECORD_MULTI_VALUE_STATS();
  5037. }
  5038. count += i;
  5039. } while (bench_stats_check(start)
  5040. #ifdef MULTI_VALUE_STATISTICS
  5041. || runs < minimum_runs
  5042. #endif
  5043. );
  5044. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5045. #ifdef MULTI_VALUE_STATISTICS
  5046. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5047. #endif
  5048. RESET_MULTI_VALUE_STATS_VARS();
  5049. bench_stats_start(&count, &start);
  5050. do {
  5051. for (i = 0; i < numBlocks; i++) {
  5052. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5053. if (ret < 0) {
  5054. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5055. return;
  5056. }
  5057. RECORD_MULTI_VALUE_STATS();
  5058. }
  5059. count += i;
  5060. } while (bench_stats_check(start)
  5061. #ifdef MULTI_VALUE_STATISTICS
  5062. || runs < minimum_runs
  5063. #endif
  5064. );
  5065. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5066. #ifdef MULTI_VALUE_STATISTICS
  5067. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5068. #endif
  5069. }
  5070. #endif
  5071. #ifdef WOLFSSL_SM4_GCM
  5072. void bench_sm4_gcm(void)
  5073. {
  5074. wc_Sm4 sm4;
  5075. double start;
  5076. int ret;
  5077. int i;
  5078. int count;
  5079. DECLARE_MULTI_VALUE_STATS_VARS()
  5080. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5081. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5082. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5083. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5084. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5085. if (ret != 0) {
  5086. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5087. goto exit;
  5088. }
  5089. bench_stats_start(&count, &start);
  5090. do {
  5091. for (i = 0; i < numBlocks; i++) {
  5092. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5093. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5094. bench_additional, aesAuthAddSz);
  5095. if (ret < 0) {
  5096. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5097. goto exit;
  5098. }
  5099. RECORD_MULTI_VALUE_STATS();
  5100. }
  5101. count += i;
  5102. } while (bench_stats_check(start)
  5103. #ifdef MULTI_VALUE_STATISTICS
  5104. || runs < minimum_runs
  5105. #endif
  5106. );
  5107. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5108. #ifdef MULTI_VALUE_STATISTICS
  5109. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5110. #endif
  5111. RESET_MULTI_VALUE_STATS_VARS();
  5112. bench_stats_start(&count, &start);
  5113. do {
  5114. for (i = 0; i < numBlocks; i++) {
  5115. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5116. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5117. bench_additional, aesAuthAddSz);
  5118. if (ret < 0) {
  5119. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5120. goto exit;
  5121. }
  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-GCM-dec", 0, count, bench_size, start, ret);
  5131. #ifdef MULTI_VALUE_STATISTICS
  5132. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5133. #endif
  5134. exit:
  5135. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5136. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5137. }
  5138. #endif
  5139. #ifdef WOLFSSL_SM4_CCM
  5140. void bench_sm4_ccm(void)
  5141. {
  5142. wc_Sm4 enc;
  5143. double start;
  5144. int ret, i, count;
  5145. DECLARE_MULTI_VALUE_STATS_VARS()
  5146. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5147. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5148. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5149. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5150. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5151. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5152. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5153. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5154. goto exit;
  5155. }
  5156. bench_stats_start(&count, &start);
  5157. do {
  5158. for (i = 0; i < numBlocks; i++) {
  5159. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5160. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5161. bench_additional, 0);
  5162. RECORD_MULTI_VALUE_STATS();
  5163. }
  5164. count += i;
  5165. } while (bench_stats_check(start)
  5166. #ifdef MULTI_VALUE_STATISTICS
  5167. || runs < minimum_runs
  5168. #endif
  5169. );
  5170. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5171. #ifdef MULTI_VALUE_STATISTICS
  5172. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5173. #endif
  5174. if (ret != 0) {
  5175. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5176. goto exit;
  5177. }
  5178. RESET_MULTI_VALUE_STATS_VARS();
  5179. bench_stats_start(&count, &start);
  5180. do {
  5181. for (i = 0; i < numBlocks; i++) {
  5182. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5183. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5184. bench_additional, 0);
  5185. RECORD_MULTI_VALUE_STATS();
  5186. }
  5187. count += i;
  5188. } while (bench_stats_check(start)
  5189. #ifdef MULTI_VALUE_STATISTICS
  5190. || runs < minimum_runs
  5191. #endif
  5192. );
  5193. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5194. #ifdef MULTI_VALUE_STATISTICS
  5195. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5196. #endif
  5197. if (ret != 0) {
  5198. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5199. goto exit;
  5200. }
  5201. exit:
  5202. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5203. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5204. }
  5205. #endif /* HAVE_AESCCM */
  5206. #ifndef NO_DES3
  5207. void bench_des(int useDeviceID)
  5208. {
  5209. int ret = 0, i, count = 0, times, pending = 0;
  5210. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5211. sizeof(Des3), HEAP_HINT);
  5212. double start;
  5213. DECLARE_MULTI_VALUE_STATS_VARS()
  5214. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5215. sizeof(Des3), HEAP_HINT);
  5216. /* init keys */
  5217. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5218. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5219. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5220. printf("Des3Init failed, ret = %d\n", ret);
  5221. goto exit;
  5222. }
  5223. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5224. if (ret != 0) {
  5225. printf("Des3_SetKey failed, ret = %d\n", ret);
  5226. goto exit;
  5227. }
  5228. }
  5229. bench_stats_start(&count, &start);
  5230. do {
  5231. for (times = 0; times < numBlocks || pending > 0; ) {
  5232. bench_async_poll(&pending);
  5233. /* while free pending slots in queue, submit ops */
  5234. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5235. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5236. &times, numBlocks, &pending)) {
  5237. ret = wc_Des3_CbcEncrypt(enc[i],
  5238. bench_cipher,
  5239. bench_plain, bench_size);
  5240. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5241. 0, &times, &pending)) {
  5242. goto exit_3des;
  5243. }
  5244. }
  5245. } /* for i */
  5246. RECORD_MULTI_VALUE_STATS();
  5247. } /* for times */
  5248. count += times;
  5249. } while (bench_stats_check(start)
  5250. #ifdef MULTI_VALUE_STATISTICS
  5251. || runs < minimum_runs
  5252. #endif
  5253. );
  5254. exit_3des:
  5255. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5256. #ifdef MULTI_VALUE_STATISTICS
  5257. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5258. #endif
  5259. exit:
  5260. if (WC_ARRAY_OK(enc)) {
  5261. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5262. wc_Des3Free(enc[i]);
  5263. }
  5264. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5265. }
  5266. }
  5267. #endif /* !NO_DES3 */
  5268. #ifndef NO_RC4
  5269. void bench_arc4(int useDeviceID)
  5270. {
  5271. int ret = 0, i, count = 0, times, pending = 0;
  5272. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5273. sizeof(Arc4), HEAP_HINT);
  5274. double start;
  5275. DECLARE_MULTI_VALUE_STATS_VARS()
  5276. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5277. sizeof(Arc4), HEAP_HINT);
  5278. /* init keys */
  5279. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5280. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5281. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5282. printf("Arc4Init failed, ret = %d\n", ret);
  5283. goto exit;
  5284. }
  5285. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5286. if (ret != 0) {
  5287. printf("Arc4SetKey failed, ret = %d\n", ret);
  5288. goto exit;
  5289. }
  5290. }
  5291. bench_stats_start(&count, &start);
  5292. do {
  5293. for (times = 0; times < numBlocks || pending > 0; ) {
  5294. bench_async_poll(&pending);
  5295. /* while free pending slots in queue, submit ops */
  5296. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5297. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5298. &times, numBlocks, &pending)) {
  5299. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5300. bench_size);
  5301. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5302. 0, &times, &pending)) {
  5303. goto exit_arc4;
  5304. }
  5305. }
  5306. } /* for i */
  5307. RECORD_MULTI_VALUE_STATS();
  5308. } /* for times */
  5309. count += times;
  5310. } while (bench_stats_check(start)
  5311. #ifdef MULTI_VALUE_STATISTICS
  5312. || runs < minimum_runs
  5313. #endif
  5314. );
  5315. exit_arc4:
  5316. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5317. #ifdef MULTI_VALUE_STATISTICS
  5318. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5319. #endif
  5320. exit:
  5321. if (WC_ARRAY_OK(enc)) {
  5322. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5323. wc_Arc4Free(enc[i]);
  5324. }
  5325. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5326. }
  5327. }
  5328. #endif /* !NO_RC4 */
  5329. #ifdef HAVE_CHACHA
  5330. void bench_chacha(void)
  5331. {
  5332. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5333. double start;
  5334. int ret, i, count;
  5335. DECLARE_MULTI_VALUE_STATS_VARS()
  5336. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5337. XMEMSET(enc, 0, sizeof(ChaCha));
  5338. wc_Chacha_SetKey(enc, bench_key, 16);
  5339. if (encrypt_only) {
  5340. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5341. if (ret < 0) {
  5342. printf("wc_Chacha_SetIV error: %d\n", ret);
  5343. goto exit;
  5344. }
  5345. bench_stats_start(&count, &start);
  5346. do {
  5347. for (i = 0; i < numBlocks; i++) {
  5348. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5349. bench_size);
  5350. if (ret < 0) {
  5351. printf("wc_Chacha_Process error: %d\n", ret);
  5352. goto exit;
  5353. }
  5354. RECORD_MULTI_VALUE_STATS();
  5355. }
  5356. count += i;
  5357. } while (bench_stats_check(start)
  5358. #ifdef MULTI_VALUE_STATISTICS
  5359. || runs < minimum_runs
  5360. #endif
  5361. );
  5362. }
  5363. else {
  5364. bench_stats_start(&count, &start);
  5365. do {
  5366. for (i = 0; i < numBlocks; i++) {
  5367. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5368. if (ret < 0) {
  5369. printf("wc_Chacha_SetIV error: %d\n", ret);
  5370. goto exit;
  5371. }
  5372. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5373. bench_size);
  5374. if (ret < 0) {
  5375. printf("wc_Chacha_Process error: %d\n", ret);
  5376. goto exit;
  5377. }
  5378. RECORD_MULTI_VALUE_STATS();
  5379. }
  5380. count += i;
  5381. } while (bench_stats_check(start)
  5382. #ifdef MULTI_VALUE_STATISTICS
  5383. || runs < minimum_runs
  5384. #endif
  5385. );
  5386. }
  5387. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5388. #ifdef MULTI_VALUE_STATISTICS
  5389. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5390. #endif
  5391. exit:
  5392. WC_FREE_VAR(enc, HEAP_HINT);
  5393. }
  5394. #endif /* HAVE_CHACHA*/
  5395. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5396. void bench_chacha20_poly1305_aead(void)
  5397. {
  5398. double start;
  5399. int ret = 0, i, count;
  5400. DECLARE_MULTI_VALUE_STATS_VARS()
  5401. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5402. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5403. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5404. bench_stats_start(&count, &start);
  5405. do {
  5406. for (i = 0; i < numBlocks; i++) {
  5407. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5408. bench_plain, bench_size, bench_cipher, authTag);
  5409. if (ret < 0) {
  5410. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5411. goto exit;
  5412. }
  5413. RECORD_MULTI_VALUE_STATS();
  5414. }
  5415. count += i;
  5416. } while (bench_stats_check(start)
  5417. #ifdef MULTI_VALUE_STATISTICS
  5418. || runs < minimum_runs
  5419. #endif
  5420. );
  5421. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5422. #ifdef MULTI_VALUE_STATISTICS
  5423. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5424. #endif
  5425. exit:
  5426. WC_FREE_VAR(authTag, HEAP_HINT);
  5427. }
  5428. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5429. #ifndef NO_MD5
  5430. void bench_md5(int useDeviceID)
  5431. {
  5432. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5433. sizeof(wc_Md5), HEAP_HINT);
  5434. double start = 0;
  5435. int ret = 0, i, count = 0, times, pending = 0;
  5436. DECLARE_MULTI_VALUE_STATS_VARS()
  5437. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5438. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5439. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5440. sizeof(wc_Md5), HEAP_HINT);
  5441. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5442. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5443. if (digest_stream) {
  5444. /* init keys */
  5445. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5446. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5447. useDeviceID ? devId : INVALID_DEVID);
  5448. if (ret != 0) {
  5449. printf("InitMd5_ex failed, ret = %d\n", ret);
  5450. goto exit;
  5451. }
  5452. #ifdef WOLFSSL_PIC32MZ_HASH
  5453. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5454. #endif
  5455. }
  5456. bench_stats_start(&count, &start);
  5457. do {
  5458. for (times = 0; times < numBlocks || pending > 0; ) {
  5459. bench_async_poll(&pending);
  5460. /* while free pending slots in queue, submit ops */
  5461. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5462. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5463. 0, &times, numBlocks, &pending)) {
  5464. ret = wc_Md5Update(hash[i], bench_plain,
  5465. bench_size);
  5466. if (!bench_async_handle(&ret,
  5467. BENCH_ASYNC_GET_DEV(hash[i]),
  5468. 0, &times, &pending)) {
  5469. goto exit_md5;
  5470. }
  5471. }
  5472. } /* for i */
  5473. RECORD_MULTI_VALUE_STATS();
  5474. } /* for times */
  5475. count += times;
  5476. times = 0;
  5477. do {
  5478. bench_async_poll(&pending);
  5479. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5480. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5481. 0, &times, numBlocks, &pending)) {
  5482. ret = wc_Md5Final(hash[i], digest[i]);
  5483. if (!bench_async_handle(&ret,
  5484. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5485. &times, &pending)) {
  5486. goto exit_md5;
  5487. }
  5488. }
  5489. } /* for i */
  5490. } while (pending > 0);
  5491. } while (bench_stats_check(start)
  5492. #ifdef MULTI_VALUE_STATISTICS
  5493. || runs < minimum_runs
  5494. #endif
  5495. );
  5496. }
  5497. else {
  5498. bench_stats_start(&count, &start);
  5499. do {
  5500. for (times = 0; times < numBlocks; times++) {
  5501. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5502. if (ret == 0)
  5503. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5504. if (ret == 0)
  5505. ret = wc_Md5Final(hash[0], digest[0]);
  5506. if (ret != 0)
  5507. goto exit_md5;
  5508. RECORD_MULTI_VALUE_STATS();
  5509. } /* for times */
  5510. count += times;
  5511. } while (bench_stats_check(start)
  5512. #ifdef MULTI_VALUE_STATISTICS
  5513. || runs < minimum_runs
  5514. #endif
  5515. );
  5516. }
  5517. exit_md5:
  5518. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5519. #ifdef MULTI_VALUE_STATISTICS
  5520. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5521. #endif
  5522. exit:
  5523. #ifdef WOLFSSL_ASYNC_CRYPT
  5524. if (WC_ARRAY_OK(hash)) {
  5525. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5526. wc_Md5Free(hash[i]);
  5527. }
  5528. }
  5529. #endif
  5530. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5531. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5532. }
  5533. #endif /* !NO_MD5 */
  5534. #ifndef NO_SHA
  5535. void bench_sha(int useDeviceID)
  5536. {
  5537. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5538. sizeof(wc_Sha), HEAP_HINT);
  5539. double start;
  5540. int ret = 0, i, count = 0, times, pending = 0;
  5541. DECLARE_MULTI_VALUE_STATS_VARS()
  5542. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5543. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5544. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5545. sizeof(wc_Sha), HEAP_HINT);
  5546. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5547. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5548. if (digest_stream) {
  5549. /* init keys */
  5550. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5551. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5552. useDeviceID ? devId : INVALID_DEVID);
  5553. if (ret != 0) {
  5554. printf("InitSha failed, ret = %d\n", ret);
  5555. goto exit;
  5556. }
  5557. #ifdef WOLFSSL_PIC32MZ_HASH
  5558. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5559. #endif
  5560. }
  5561. bench_stats_start(&count, &start);
  5562. do {
  5563. for (times = 0; times < numBlocks || pending > 0; ) {
  5564. bench_async_poll(&pending);
  5565. /* while free pending slots in queue, submit ops */
  5566. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5567. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5568. 0, &times, numBlocks, &pending)) {
  5569. ret = wc_ShaUpdate(hash[i], bench_plain,
  5570. bench_size);
  5571. if (!bench_async_handle(&ret,
  5572. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5573. &times, &pending)) {
  5574. goto exit_sha;
  5575. }
  5576. }
  5577. } /* for i */
  5578. RECORD_MULTI_VALUE_STATS();
  5579. } /* for times */
  5580. count += times;
  5581. times = 0;
  5582. do {
  5583. bench_async_poll(&pending);
  5584. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5585. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5586. 0, &times, numBlocks, &pending)) {
  5587. ret = wc_ShaFinal(hash[i], digest[i]);
  5588. if (!bench_async_handle(&ret,
  5589. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5590. &times, &pending)) {
  5591. goto exit_sha;
  5592. }
  5593. }
  5594. } /* for i */
  5595. } while (pending > 0);
  5596. } while (bench_stats_check(start)
  5597. #ifdef MULTI_VALUE_STATISTICS
  5598. || runs < minimum_runs
  5599. #endif
  5600. );
  5601. }
  5602. else {
  5603. bench_stats_start(&count, &start);
  5604. do {
  5605. for (times = 0; times < numBlocks; times++) {
  5606. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5607. useDeviceID ? devId : INVALID_DEVID);
  5608. if (ret == 0)
  5609. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5610. if (ret == 0)
  5611. ret = wc_ShaFinal(hash[0], digest[0]);
  5612. if (ret != 0)
  5613. goto exit_sha;
  5614. RECORD_MULTI_VALUE_STATS();
  5615. } /* for times */
  5616. count += times;
  5617. } while (bench_stats_check(start)
  5618. #ifdef MULTI_VALUE_STATISTICS
  5619. || runs < minimum_runs
  5620. #endif
  5621. );
  5622. }
  5623. exit_sha:
  5624. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5625. #ifdef MULTI_VALUE_STATISTICS
  5626. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5627. #endif
  5628. exit:
  5629. if (WC_ARRAY_OK(hash)) {
  5630. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5631. wc_ShaFree(hash[i]);
  5632. }
  5633. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5634. }
  5635. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5636. }
  5637. #endif /* NO_SHA */
  5638. #ifdef WOLFSSL_SHA224
  5639. void bench_sha224(int useDeviceID)
  5640. {
  5641. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5642. sizeof(wc_Sha224), HEAP_HINT);
  5643. double start;
  5644. int ret = 0, i, count = 0, times, pending = 0;
  5645. DECLARE_MULTI_VALUE_STATS_VARS()
  5646. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5647. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5648. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5649. sizeof(wc_Sha224), HEAP_HINT);
  5650. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5651. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5652. if (digest_stream) {
  5653. /* init keys */
  5654. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5655. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5656. useDeviceID ? devId : INVALID_DEVID);
  5657. if (ret != 0) {
  5658. printf("InitSha224_ex failed, ret = %d\n", ret);
  5659. goto exit;
  5660. }
  5661. }
  5662. bench_stats_start(&count, &start);
  5663. do {
  5664. for (times = 0; times < numBlocks || pending > 0; ) {
  5665. bench_async_poll(&pending);
  5666. /* while free pending slots in queue, submit ops */
  5667. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5668. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5669. 0, &times, numBlocks, &pending)) {
  5670. ret = wc_Sha224Update(hash[i], bench_plain,
  5671. bench_size);
  5672. if (!bench_async_handle(&ret,
  5673. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5674. &times, &pending)) {
  5675. goto exit_sha224;
  5676. }
  5677. }
  5678. } /* for i */
  5679. RECORD_MULTI_VALUE_STATS();
  5680. } /* for times */
  5681. count += times;
  5682. times = 0;
  5683. do {
  5684. bench_async_poll(&pending);
  5685. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5686. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5687. 0, &times, numBlocks, &pending)) {
  5688. ret = wc_Sha224Final(hash[i], digest[i]);
  5689. if (!bench_async_handle(&ret,
  5690. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5691. &times, &pending)) {
  5692. goto exit_sha224;
  5693. }
  5694. }
  5695. } /* for i */
  5696. } while (pending > 0);
  5697. } while (bench_stats_check(start)
  5698. #ifdef MULTI_VALUE_STATISTICS
  5699. || runs < minimum_runs
  5700. #endif
  5701. );
  5702. }
  5703. else {
  5704. bench_stats_start(&count, &start);
  5705. do {
  5706. for (times = 0; times < numBlocks; times++) {
  5707. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5708. useDeviceID ? devId : INVALID_DEVID);
  5709. if (ret == 0)
  5710. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5711. if (ret == 0)
  5712. ret = wc_Sha224Final(hash[0], digest[0]);
  5713. if (ret != 0)
  5714. goto exit_sha224;
  5715. } /* for times */
  5716. count += times;
  5717. } while (bench_stats_check(start)
  5718. #ifdef MULTI_VALUE_STATISTICS
  5719. || runs < minimum_runs
  5720. #endif
  5721. );
  5722. }
  5723. exit_sha224:
  5724. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5725. bench_size, start, ret);
  5726. #ifdef MULTI_VALUE_STATISTICS
  5727. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5728. #endif
  5729. exit:
  5730. if (WC_ARRAY_OK(hash)) {
  5731. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5732. wc_Sha224Free(hash[i]);
  5733. }
  5734. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5735. }
  5736. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5737. }
  5738. #endif
  5739. #ifndef NO_SHA256
  5740. void bench_sha256(int useDeviceID)
  5741. {
  5742. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5743. sizeof(wc_Sha256), HEAP_HINT);
  5744. double start;
  5745. int ret = 0, i, count = 0, times, pending = 0;
  5746. DECLARE_MULTI_VALUE_STATS_VARS()
  5747. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5748. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5749. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5750. sizeof(wc_Sha256), HEAP_HINT);
  5751. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5752. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5753. if (digest_stream) {
  5754. /* init keys */
  5755. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5756. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5757. useDeviceID ? devId: INVALID_DEVID);
  5758. if (ret != 0) {
  5759. printf("InitSha256_ex failed, ret = %d\n", ret);
  5760. goto exit;
  5761. }
  5762. #ifdef WOLFSSL_PIC32MZ_HASH
  5763. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5764. #endif
  5765. }
  5766. bench_stats_start(&count, &start);
  5767. do {
  5768. for (times = 0; times < numBlocks || pending > 0; ) {
  5769. bench_async_poll(&pending);
  5770. /* while free pending slots in queue, submit ops */
  5771. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5772. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5773. 0, &times, numBlocks, &pending)) {
  5774. ret = wc_Sha256Update(hash[i], bench_plain,
  5775. bench_size);
  5776. if (!bench_async_handle(&ret,
  5777. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5778. &times, &pending)) {
  5779. goto exit_sha256;
  5780. }
  5781. }
  5782. } /* for i */
  5783. RECORD_MULTI_VALUE_STATS();
  5784. } /* for times */
  5785. count += times;
  5786. times = 0;
  5787. do {
  5788. bench_async_poll(&pending);
  5789. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5790. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5791. 0, &times, numBlocks, &pending)) {
  5792. ret = wc_Sha256Final(hash[i], digest[i]);
  5793. if (!bench_async_handle(&ret,
  5794. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5795. &times, &pending)) {
  5796. goto exit_sha256;
  5797. }
  5798. }
  5799. } /* for i */
  5800. } while (pending > 0);
  5801. } while (bench_stats_check(start)
  5802. #ifdef MULTI_VALUE_STATISTICS
  5803. || runs < minimum_runs
  5804. #endif
  5805. );
  5806. }
  5807. else {
  5808. bench_stats_start(&count, &start);
  5809. do {
  5810. for (times = 0; times < numBlocks; times++) {
  5811. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5812. useDeviceID ? devId: INVALID_DEVID);
  5813. if (ret == 0)
  5814. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5815. if (ret == 0)
  5816. ret = wc_Sha256Final(hash[0], digest[0]);
  5817. if (ret != 0)
  5818. goto exit_sha256;
  5819. RECORD_MULTI_VALUE_STATS();
  5820. } /* for times */
  5821. count += times;
  5822. } while (bench_stats_check(start)
  5823. #ifdef MULTI_VALUE_STATISTICS
  5824. || runs < minimum_runs
  5825. #endif
  5826. );
  5827. }
  5828. exit_sha256:
  5829. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5830. start, ret);
  5831. #ifdef MULTI_VALUE_STATISTICS
  5832. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5833. #endif
  5834. exit:
  5835. if (WC_ARRAY_OK(hash)) {
  5836. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5837. wc_Sha256Free(hash[i]);
  5838. }
  5839. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5840. }
  5841. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5842. }
  5843. #endif
  5844. #ifdef WOLFSSL_SHA384
  5845. void bench_sha384(int useDeviceID)
  5846. {
  5847. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5848. sizeof(wc_Sha384), HEAP_HINT);
  5849. double start;
  5850. int ret = 0, i, count = 0, times, pending = 0;
  5851. DECLARE_MULTI_VALUE_STATS_VARS()
  5852. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5853. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5854. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5855. sizeof(wc_Sha384), HEAP_HINT);
  5856. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5857. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5858. if (digest_stream) {
  5859. /* init keys */
  5860. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5861. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5862. useDeviceID ? devId : INVALID_DEVID);
  5863. if (ret != 0) {
  5864. printf("InitSha384_ex failed, ret = %d\n", ret);
  5865. goto exit;
  5866. }
  5867. }
  5868. bench_stats_start(&count, &start);
  5869. do {
  5870. for (times = 0; times < numBlocks || pending > 0; ) {
  5871. bench_async_poll(&pending);
  5872. /* while free pending slots in queue, submit ops */
  5873. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5874. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5875. 0, &times, numBlocks, &pending)) {
  5876. ret = wc_Sha384Update(hash[i], bench_plain,
  5877. bench_size);
  5878. if (!bench_async_handle(&ret,
  5879. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5880. &times, &pending)) {
  5881. goto exit_sha384;
  5882. }
  5883. }
  5884. } /* for i */
  5885. RECORD_MULTI_VALUE_STATS();
  5886. } /* for times */
  5887. count += times;
  5888. times = 0;
  5889. do {
  5890. bench_async_poll(&pending);
  5891. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5892. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5893. 0, &times, numBlocks, &pending)) {
  5894. ret = wc_Sha384Final(hash[i], digest[i]);
  5895. if (!bench_async_handle(&ret,
  5896. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5897. &times, &pending)) {
  5898. goto exit_sha384;
  5899. }
  5900. }
  5901. } /* for i */
  5902. } while (pending > 0);
  5903. } while (bench_stats_check(start)
  5904. #ifdef MULTI_VALUE_STATISTICS
  5905. || runs < minimum_runs
  5906. #endif
  5907. );
  5908. }
  5909. else {
  5910. bench_stats_start(&count, &start);
  5911. do {
  5912. for (times = 0; times < numBlocks; times++) {
  5913. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5914. useDeviceID ? devId : INVALID_DEVID);
  5915. if (ret == 0)
  5916. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5917. if (ret == 0)
  5918. ret = wc_Sha384Final(hash[0], digest[0]);
  5919. if (ret != 0)
  5920. goto exit_sha384;
  5921. RECORD_MULTI_VALUE_STATS();
  5922. } /* for times */
  5923. count += times;
  5924. } while (bench_stats_check(start)
  5925. #ifdef MULTI_VALUE_STATISTICS
  5926. || runs < minimum_runs
  5927. #endif
  5928. );
  5929. }
  5930. exit_sha384:
  5931. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5932. start, ret);
  5933. #ifdef MULTI_VALUE_STATISTICS
  5934. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5935. #endif
  5936. exit:
  5937. if (WC_ARRAY_OK(hash)) {
  5938. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5939. wc_Sha384Free(hash[i]);
  5940. }
  5941. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5942. }
  5943. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5944. }
  5945. #endif
  5946. #ifdef WOLFSSL_SHA512
  5947. void bench_sha512(int useDeviceID)
  5948. {
  5949. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5950. sizeof(wc_Sha512), HEAP_HINT);
  5951. double start;
  5952. int ret = 0, i, count = 0, times, pending = 0;
  5953. DECLARE_MULTI_VALUE_STATS_VARS()
  5954. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5955. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5956. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5957. sizeof(wc_Sha512), HEAP_HINT);
  5958. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5959. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5960. if (digest_stream) {
  5961. /* init keys */
  5962. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5963. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5964. useDeviceID ? devId : INVALID_DEVID);
  5965. if (ret != 0) {
  5966. printf("InitSha512_ex failed, ret = %d\n", ret);
  5967. goto exit;
  5968. }
  5969. }
  5970. bench_stats_start(&count, &start);
  5971. do {
  5972. for (times = 0; times < numBlocks || pending > 0; ) {
  5973. bench_async_poll(&pending);
  5974. /* while free pending slots in queue, submit ops */
  5975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5976. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5977. 0, &times, numBlocks, &pending)) {
  5978. ret = wc_Sha512Update(hash[i], bench_plain,
  5979. bench_size);
  5980. if (!bench_async_handle(&ret,
  5981. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5982. &times, &pending)) {
  5983. goto exit_sha512;
  5984. }
  5985. }
  5986. } /* for i */
  5987. RECORD_MULTI_VALUE_STATS();
  5988. } /* for times */
  5989. count += times;
  5990. times = 0;
  5991. do {
  5992. bench_async_poll(&pending);
  5993. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5994. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5995. 0, &times, numBlocks, &pending)) {
  5996. ret = wc_Sha512Final(hash[i], digest[i]);
  5997. if (!bench_async_handle(&ret,
  5998. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5999. &times, &pending)) {
  6000. goto exit_sha512;
  6001. }
  6002. }
  6003. } /* for i */
  6004. } while (pending > 0);
  6005. } while (bench_stats_check(start)
  6006. #ifdef MULTI_VALUE_STATISTICS
  6007. || runs < minimum_runs
  6008. #endif
  6009. );
  6010. }
  6011. else {
  6012. bench_stats_start(&count, &start);
  6013. do {
  6014. for (times = 0; times < numBlocks; times++) {
  6015. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  6016. useDeviceID ? devId : INVALID_DEVID);
  6017. if (ret == 0)
  6018. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  6019. if (ret == 0)
  6020. ret = wc_Sha512Final(hash[0], digest[0]);
  6021. if (ret != 0)
  6022. goto exit_sha512;
  6023. RECORD_MULTI_VALUE_STATS();
  6024. } /* for times */
  6025. count += times;
  6026. } while (bench_stats_check(start)
  6027. #ifdef MULTI_VALUE_STATISTICS
  6028. || runs < minimum_runs
  6029. #endif
  6030. );
  6031. }
  6032. exit_sha512:
  6033. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  6034. start, ret);
  6035. #ifdef MULTI_VALUE_STATISTICS
  6036. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6037. #endif
  6038. exit:
  6039. if (WC_ARRAY_OK(hash)) {
  6040. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6041. wc_Sha512Free(hash[i]);
  6042. }
  6043. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6044. }
  6045. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6046. }
  6047. #if !defined(WOLFSSL_NOSHA512_224) && \
  6048. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6049. void bench_sha512_224(int useDeviceID)
  6050. {
  6051. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6052. sizeof(wc_Sha512_224), HEAP_HINT);
  6053. double start;
  6054. int ret = 0, i, count = 0, times, pending = 0;
  6055. DECLARE_MULTI_VALUE_STATS_VARS()
  6056. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6057. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6058. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6059. sizeof(wc_Sha512_224), HEAP_HINT);
  6060. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6061. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6062. if (digest_stream) {
  6063. /* init keys */
  6064. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6065. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6066. useDeviceID ? devId : INVALID_DEVID);
  6067. if (ret != 0) {
  6068. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6069. goto exit;
  6070. }
  6071. }
  6072. bench_stats_start(&count, &start);
  6073. do {
  6074. for (times = 0; times < numBlocks || pending > 0; ) {
  6075. bench_async_poll(&pending);
  6076. /* while free pending slots in queue, submit ops */
  6077. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6078. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6079. 0, &times, numBlocks, &pending)) {
  6080. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6081. bench_size);
  6082. if (!bench_async_handle(&ret,
  6083. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6084. &times, &pending)) {
  6085. goto exit_sha512_224;
  6086. }
  6087. }
  6088. } /* for i */
  6089. RECORD_MULTI_VALUE_STATS();
  6090. } /* for times */
  6091. count += times;
  6092. times = 0;
  6093. do {
  6094. bench_async_poll(&pending);
  6095. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6096. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6097. 0, &times, numBlocks, &pending)) {
  6098. ret = wc_Sha512_224Final(hash[i], digest[i]);
  6099. if (!bench_async_handle(&ret,
  6100. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6101. &times, &pending)) {
  6102. goto exit_sha512_224;
  6103. }
  6104. }
  6105. } /* for i */
  6106. } while (pending > 0);
  6107. } while (bench_stats_check(start)
  6108. #ifdef MULTI_VALUE_STATISTICS
  6109. || runs < minimum_runs
  6110. #endif
  6111. );
  6112. }
  6113. else {
  6114. bench_stats_start(&count, &start);
  6115. do {
  6116. for (times = 0; times < numBlocks; times++) {
  6117. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6118. useDeviceID ? devId : INVALID_DEVID);
  6119. if (ret == 0)
  6120. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6121. if (ret == 0)
  6122. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6123. if (ret != 0)
  6124. goto exit_sha512_224;
  6125. RECORD_MULTI_VALUE_STATS();
  6126. } /* for times */
  6127. count += times;
  6128. } while (bench_stats_check(start)
  6129. #ifdef MULTI_VALUE_STATISTICS
  6130. || runs < minimum_runs
  6131. #endif
  6132. );
  6133. }
  6134. exit_sha512_224:
  6135. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6136. start, ret);
  6137. #ifdef MULTI_VALUE_STATISTICS
  6138. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6139. #endif
  6140. exit:
  6141. if (WC_ARRAY_OK(hash)) {
  6142. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6143. wc_Sha512_224Free(hash[i]);
  6144. }
  6145. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6146. }
  6147. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6148. }
  6149. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6150. #if !defined(WOLFSSL_NOSHA512_256) && \
  6151. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6152. void bench_sha512_256(int useDeviceID)
  6153. {
  6154. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6155. sizeof(wc_Sha512_256), HEAP_HINT);
  6156. double start;
  6157. int ret = 0, i, count = 0, times, pending = 0;
  6158. DECLARE_MULTI_VALUE_STATS_VARS()
  6159. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6160. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6161. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6162. sizeof(wc_Sha512_256), HEAP_HINT);
  6163. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6164. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6165. if (digest_stream) {
  6166. /* init keys */
  6167. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6168. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6169. useDeviceID ? devId : INVALID_DEVID);
  6170. if (ret != 0) {
  6171. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6172. goto exit;
  6173. }
  6174. }
  6175. bench_stats_start(&count, &start);
  6176. do {
  6177. for (times = 0; times < numBlocks || pending > 0; ) {
  6178. bench_async_poll(&pending);
  6179. /* while free pending slots in queue, submit ops */
  6180. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6181. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6182. 0, &times, numBlocks, &pending)) {
  6183. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6184. bench_size);
  6185. if (!bench_async_handle(&ret,
  6186. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6187. &times, &pending)) {
  6188. goto exit_sha512_256;
  6189. }
  6190. }
  6191. } /* for i */
  6192. RECORD_MULTI_VALUE_STATS();
  6193. } /* for times */
  6194. count += times;
  6195. times = 0;
  6196. do {
  6197. bench_async_poll(&pending);
  6198. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6199. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6200. 0, &times, numBlocks, &pending)) {
  6201. ret = wc_Sha512_256Final(hash[i], digest[i]);
  6202. if (!bench_async_handle(&ret,
  6203. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6204. &times, &pending)) {
  6205. goto exit_sha512_256;
  6206. }
  6207. }
  6208. } /* for i */
  6209. } while (pending > 0);
  6210. } while (bench_stats_check(start)
  6211. #ifdef MULTI_VALUE_STATISTICS
  6212. || runs < minimum_runs
  6213. #endif
  6214. );
  6215. }
  6216. else {
  6217. bench_stats_start(&count, &start);
  6218. do {
  6219. for (times = 0; times < numBlocks; times++) {
  6220. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6221. useDeviceID ? devId : INVALID_DEVID);
  6222. if (ret == 0)
  6223. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6224. if (ret == 0)
  6225. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6226. if (ret != 0)
  6227. goto exit_sha512_256;
  6228. RECORD_MULTI_VALUE_STATS();
  6229. } /* for times */
  6230. count += times;
  6231. } while (bench_stats_check(start)
  6232. #ifdef MULTI_VALUE_STATISTICS
  6233. || runs < minimum_runs
  6234. #endif
  6235. );
  6236. }
  6237. exit_sha512_256:
  6238. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6239. start, ret);
  6240. #ifdef MULTI_VALUE_STATISTICS
  6241. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6242. #endif
  6243. exit:
  6244. if (WC_ARRAY_OK(hash)) {
  6245. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6246. wc_Sha512_256Free(hash[i]);
  6247. }
  6248. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6249. }
  6250. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6251. }
  6252. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6253. #endif /* WOLFSSL_SHA512 */
  6254. #ifdef WOLFSSL_SHA3
  6255. #ifndef WOLFSSL_NOSHA3_224
  6256. void bench_sha3_224(int useDeviceID)
  6257. {
  6258. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6259. sizeof(wc_Sha3), HEAP_HINT);
  6260. double start;
  6261. int ret = 0, i, count = 0, times, pending = 0;
  6262. DECLARE_MULTI_VALUE_STATS_VARS()
  6263. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6264. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6265. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6266. sizeof(wc_Sha3), HEAP_HINT);
  6267. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6268. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6269. if (digest_stream) {
  6270. /* init keys */
  6271. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6272. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6273. useDeviceID ? devId : INVALID_DEVID);
  6274. if (ret != 0) {
  6275. printf("InitSha3_224 failed, ret = %d\n", ret);
  6276. goto exit;
  6277. }
  6278. }
  6279. bench_stats_start(&count, &start);
  6280. do {
  6281. for (times = 0; times < numBlocks || pending > 0; ) {
  6282. bench_async_poll(&pending);
  6283. /* while free pending slots in queue, submit ops */
  6284. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6285. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6286. 0, &times, numBlocks, &pending)) {
  6287. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6288. bench_size);
  6289. if (!bench_async_handle(&ret,
  6290. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6291. &times, &pending)) {
  6292. goto exit_sha3_224;
  6293. }
  6294. }
  6295. } /* for i */
  6296. RECORD_MULTI_VALUE_STATS();
  6297. } /* for times */
  6298. count += times;
  6299. times = 0;
  6300. do {
  6301. bench_async_poll(&pending);
  6302. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6303. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6304. 0, &times, numBlocks, &pending)) {
  6305. ret = wc_Sha3_224_Final(hash[i], digest[i]);
  6306. if (!bench_async_handle(&ret,
  6307. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6308. &times, &pending)) {
  6309. goto exit_sha3_224;
  6310. }
  6311. }
  6312. } /* for i */
  6313. } while (pending > 0);
  6314. } while (bench_stats_check(start)
  6315. #ifdef MULTI_VALUE_STATISTICS
  6316. || runs < minimum_runs
  6317. #endif
  6318. );
  6319. }
  6320. else {
  6321. bench_stats_start(&count, &start);
  6322. do {
  6323. for (times = 0; times < numBlocks; times++) {
  6324. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6325. useDeviceID ? devId : INVALID_DEVID);
  6326. if (ret == 0)
  6327. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6328. if (ret == 0)
  6329. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6330. if (ret != 0)
  6331. goto exit_sha3_224;
  6332. RECORD_MULTI_VALUE_STATS();
  6333. } /* for times */
  6334. count += times;
  6335. } while (bench_stats_check(start)
  6336. #ifdef MULTI_VALUE_STATISTICS
  6337. || runs < minimum_runs
  6338. #endif
  6339. );
  6340. }
  6341. exit_sha3_224:
  6342. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6343. start, ret);
  6344. #ifdef MULTI_VALUE_STATISTICS
  6345. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6346. #endif
  6347. exit:
  6348. if (WC_ARRAY_OK(hash)) {
  6349. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6350. wc_Sha3_224_Free(hash[i]);
  6351. }
  6352. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6353. }
  6354. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6355. }
  6356. #endif /* WOLFSSL_NOSHA3_224 */
  6357. #ifndef WOLFSSL_NOSHA3_256
  6358. void bench_sha3_256(int useDeviceID)
  6359. {
  6360. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6361. sizeof(wc_Sha3), HEAP_HINT);
  6362. double start;
  6363. DECLARE_MULTI_VALUE_STATS_VARS()
  6364. int ret = 0, i, count = 0, times, pending = 0;
  6365. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6366. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6367. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6368. sizeof(wc_Sha3), HEAP_HINT);
  6369. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6370. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6371. if (digest_stream) {
  6372. /* init keys */
  6373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6374. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6375. useDeviceID ? devId : INVALID_DEVID);
  6376. if (ret != 0) {
  6377. printf("InitSha3_256 failed, ret = %d\n", ret);
  6378. goto exit;
  6379. }
  6380. }
  6381. bench_stats_start(&count, &start);
  6382. do {
  6383. for (times = 0; times < numBlocks || pending > 0; ) {
  6384. bench_async_poll(&pending);
  6385. /* while free pending slots in queue, submit ops */
  6386. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6387. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6388. 0, &times, numBlocks, &pending)) {
  6389. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6390. bench_size);
  6391. if (!bench_async_handle(&ret,
  6392. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6393. &times, &pending)) {
  6394. goto exit_sha3_256;
  6395. }
  6396. }
  6397. } /* for i */
  6398. RECORD_MULTI_VALUE_STATS();
  6399. } /* for times */
  6400. count += times;
  6401. times = 0;
  6402. do {
  6403. bench_async_poll(&pending);
  6404. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6405. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6406. 0, &times, numBlocks, &pending)) {
  6407. ret = wc_Sha3_256_Final(hash[i], digest[i]);
  6408. if (!bench_async_handle(&ret,
  6409. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6410. &times, &pending)) {
  6411. goto exit_sha3_256;
  6412. }
  6413. }
  6414. } /* for i */
  6415. } while (pending > 0);
  6416. } while (bench_stats_check(start)
  6417. #ifdef MULTI_VALUE_STATISTICS
  6418. || runs < minimum_runs
  6419. #endif
  6420. );
  6421. }
  6422. else {
  6423. bench_stats_start(&count, &start);
  6424. do {
  6425. for (times = 0; times < numBlocks; times++) {
  6426. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6427. useDeviceID ? devId : INVALID_DEVID);
  6428. if (ret == 0)
  6429. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6430. if (ret == 0)
  6431. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6432. if (ret != 0)
  6433. goto exit_sha3_256;
  6434. RECORD_MULTI_VALUE_STATS();
  6435. } /* for times */
  6436. count += times;
  6437. } while (bench_stats_check(start)
  6438. #ifdef MULTI_VALUE_STATISTICS
  6439. || runs < minimum_runs
  6440. #endif
  6441. );
  6442. }
  6443. exit_sha3_256:
  6444. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6445. start, ret);
  6446. #ifdef MULTI_VALUE_STATISTICS
  6447. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6448. #endif
  6449. exit:
  6450. if (WC_ARRAY_OK(hash)) {
  6451. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6452. wc_Sha3_256_Free(hash[i]);
  6453. }
  6454. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6455. }
  6456. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6457. }
  6458. #endif /* WOLFSSL_NOSHA3_256 */
  6459. #ifndef WOLFSSL_NOSHA3_384
  6460. void bench_sha3_384(int useDeviceID)
  6461. {
  6462. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6463. sizeof(wc_Sha3), HEAP_HINT);
  6464. double start;
  6465. int ret = 0, i, count = 0, times, pending = 0;
  6466. DECLARE_MULTI_VALUE_STATS_VARS()
  6467. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6468. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6469. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6470. sizeof(wc_Sha3), HEAP_HINT);
  6471. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6472. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6473. if (digest_stream) {
  6474. /* init keys */
  6475. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6476. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6477. useDeviceID ? devId : INVALID_DEVID);
  6478. if (ret != 0) {
  6479. printf("InitSha3_384 failed, ret = %d\n", ret);
  6480. goto exit;
  6481. }
  6482. }
  6483. bench_stats_start(&count, &start);
  6484. do {
  6485. for (times = 0; times < numBlocks || pending > 0; ) {
  6486. bench_async_poll(&pending);
  6487. /* while free pending slots in queue, submit ops */
  6488. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6489. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6490. 0, &times, numBlocks, &pending)) {
  6491. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6492. bench_size);
  6493. if (!bench_async_handle(&ret,
  6494. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6495. &times, &pending)) {
  6496. goto exit_sha3_384;
  6497. }
  6498. }
  6499. } /* for i */
  6500. RECORD_MULTI_VALUE_STATS();
  6501. } /* for times */
  6502. count += times;
  6503. times = 0;
  6504. do {
  6505. bench_async_poll(&pending);
  6506. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6507. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6508. 0, &times, numBlocks, &pending)) {
  6509. ret = wc_Sha3_384_Final(hash[i], digest[i]);
  6510. if (!bench_async_handle(&ret,
  6511. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6512. &times, &pending)) {
  6513. goto exit_sha3_384;
  6514. }
  6515. }
  6516. } /* for i */
  6517. } while (pending > 0);
  6518. } while (bench_stats_check(start)
  6519. #ifdef MULTI_VALUE_STATISTICS
  6520. || runs < minimum_runs
  6521. #endif
  6522. );
  6523. }
  6524. else {
  6525. bench_stats_start(&count, &start);
  6526. do {
  6527. for (times = 0; times < numBlocks; times++) {
  6528. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6529. useDeviceID ? devId : INVALID_DEVID);
  6530. if (ret == 0)
  6531. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6532. if (ret == 0)
  6533. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6534. if (ret != 0)
  6535. goto exit_sha3_384;
  6536. RECORD_MULTI_VALUE_STATS();
  6537. } /* for times */
  6538. count += times;
  6539. } while (bench_stats_check(start)
  6540. #ifdef MULTI_VALUE_STATISTICS
  6541. || runs < minimum_runs
  6542. #endif
  6543. );
  6544. }
  6545. exit_sha3_384:
  6546. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6547. start, ret);
  6548. #ifdef MULTI_VALUE_STATISTICS
  6549. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6550. #endif
  6551. exit:
  6552. if (WC_ARRAY_OK(hash)) {
  6553. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6554. wc_Sha3_384_Free(hash[i]);
  6555. }
  6556. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6557. }
  6558. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6559. }
  6560. #endif /* WOLFSSL_NOSHA3_384 */
  6561. #ifndef WOLFSSL_NOSHA3_512
  6562. void bench_sha3_512(int useDeviceID)
  6563. {
  6564. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6565. sizeof(wc_Sha3), HEAP_HINT);
  6566. double start;
  6567. int ret = 0, i, count = 0, times, pending = 0;
  6568. DECLARE_MULTI_VALUE_STATS_VARS()
  6569. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6570. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6571. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6572. sizeof(wc_Sha3), HEAP_HINT);
  6573. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6574. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6575. if (digest_stream) {
  6576. /* init keys */
  6577. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6578. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6579. useDeviceID ? devId : INVALID_DEVID);
  6580. if (ret != 0) {
  6581. printf("InitSha3_512 failed, ret = %d\n", ret);
  6582. goto exit;
  6583. }
  6584. }
  6585. bench_stats_start(&count, &start);
  6586. do {
  6587. for (times = 0; times < numBlocks || pending > 0; ) {
  6588. bench_async_poll(&pending);
  6589. /* while free pending slots in queue, submit ops */
  6590. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6591. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6592. 0, &times, numBlocks, &pending)) {
  6593. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6594. bench_size);
  6595. if (!bench_async_handle(&ret,
  6596. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6597. &times, &pending)) {
  6598. goto exit_sha3_512;
  6599. }
  6600. }
  6601. } /* for i */
  6602. RECORD_MULTI_VALUE_STATS();
  6603. } /* for times */
  6604. count += times;
  6605. times = 0;
  6606. do {
  6607. bench_async_poll(&pending);
  6608. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6609. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6610. 0, &times, numBlocks, &pending)) {
  6611. ret = wc_Sha3_512_Final(hash[i], digest[i]);
  6612. if (!bench_async_handle(&ret,
  6613. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6614. &times, &pending)) {
  6615. goto exit_sha3_512;
  6616. }
  6617. }
  6618. } /* for i */
  6619. } while (pending > 0);
  6620. } while (bench_stats_check(start)
  6621. #ifdef MULTI_VALUE_STATISTICS
  6622. || runs < minimum_runs
  6623. #endif
  6624. );
  6625. }
  6626. else {
  6627. bench_stats_start(&count, &start);
  6628. do {
  6629. for (times = 0; times < numBlocks; times++) {
  6630. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6631. useDeviceID ? devId : INVALID_DEVID);
  6632. if (ret == 0)
  6633. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6634. if (ret == 0)
  6635. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6636. if (ret != 0)
  6637. goto exit_sha3_512;
  6638. RECORD_MULTI_VALUE_STATS();
  6639. } /* for times */
  6640. count += times;
  6641. } while (bench_stats_check(start)
  6642. #ifdef MULTI_VALUE_STATISTICS
  6643. || runs < minimum_runs
  6644. #endif
  6645. );
  6646. }
  6647. exit_sha3_512:
  6648. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6649. start, ret);
  6650. #ifdef MULTI_VALUE_STATISTICS
  6651. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6652. #endif
  6653. exit:
  6654. if (WC_ARRAY_OK(hash)) {
  6655. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6656. wc_Sha3_512_Free(hash[i]);
  6657. }
  6658. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6659. }
  6660. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6661. }
  6662. #endif /* WOLFSSL_NOSHA3_512 */
  6663. #ifdef WOLFSSL_SHAKE128
  6664. void bench_shake128(int useDeviceID)
  6665. {
  6666. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6667. sizeof(wc_Shake), HEAP_HINT);
  6668. double start;
  6669. int ret = 0, i, count = 0, times, pending = 0;
  6670. DECLARE_MULTI_VALUE_STATS_VARS()
  6671. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6672. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6673. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6674. sizeof(wc_Shake), HEAP_HINT);
  6675. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6676. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6677. if (digest_stream) {
  6678. /* init keys */
  6679. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6680. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6681. useDeviceID ? devId : INVALID_DEVID);
  6682. if (ret != 0) {
  6683. printf("InitShake128 failed, ret = %d\n", ret);
  6684. goto exit;
  6685. }
  6686. }
  6687. bench_stats_start(&count, &start);
  6688. do {
  6689. for (times = 0; times < numBlocks || pending > 0; ) {
  6690. bench_async_poll(&pending);
  6691. /* while free pending slots in queue, submit ops */
  6692. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6693. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6694. 0, &times, numBlocks, &pending)) {
  6695. ret = wc_Shake128_Update(hash[i], bench_plain,
  6696. bench_size);
  6697. if (!bench_async_handle(&ret,
  6698. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6699. &times, &pending)) {
  6700. goto exit_shake128;
  6701. }
  6702. }
  6703. } /* for i */
  6704. RECORD_MULTI_VALUE_STATS();
  6705. } /* for times */
  6706. count += times;
  6707. times = 0;
  6708. do {
  6709. bench_async_poll(&pending);
  6710. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6711. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6712. 0, &times, numBlocks, &pending)) {
  6713. ret = wc_Shake128_Final(hash[i], digest[i],
  6714. WC_SHA3_128_BLOCK_SIZE);
  6715. if (!bench_async_handle(&ret,
  6716. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6717. &times, &pending)) {
  6718. goto exit_shake128;
  6719. }
  6720. }
  6721. } /* for i */
  6722. } while (pending > 0);
  6723. } while (bench_stats_check(start)
  6724. #ifdef MULTI_VALUE_STATISTICS
  6725. || runs < minimum_runs
  6726. #endif
  6727. );
  6728. }
  6729. else {
  6730. bench_stats_start(&count, &start);
  6731. do {
  6732. for (times = 0; times < numBlocks; times++) {
  6733. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6734. useDeviceID ? devId : INVALID_DEVID);
  6735. if (ret == 0)
  6736. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6737. if (ret == 0)
  6738. ret = wc_Shake128_Final(hash[0], digest[0],
  6739. WC_SHA3_128_BLOCK_SIZE);
  6740. if (ret != 0)
  6741. goto exit_shake128;
  6742. RECORD_MULTI_VALUE_STATS();
  6743. } /* for times */
  6744. count += times;
  6745. } while (bench_stats_check(start)
  6746. #ifdef MULTI_VALUE_STATISTICS
  6747. || runs < minimum_runs
  6748. #endif
  6749. );
  6750. }
  6751. exit_shake128:
  6752. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6753. start, ret);
  6754. #ifdef MULTI_VALUE_STATISTICS
  6755. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6756. #endif
  6757. exit:
  6758. if (WC_ARRAY_OK(hash)) {
  6759. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6760. wc_Shake128_Free(hash[i]);
  6761. }
  6762. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6763. }
  6764. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6765. }
  6766. #endif /* WOLFSSL_SHAKE128 */
  6767. #ifdef WOLFSSL_SHAKE256
  6768. void bench_shake256(int useDeviceID)
  6769. {
  6770. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6771. sizeof(wc_Shake), HEAP_HINT);
  6772. double start;
  6773. int ret = 0, i, count = 0, times, pending = 0;
  6774. DECLARE_MULTI_VALUE_STATS_VARS()
  6775. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6776. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6777. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6778. sizeof(wc_Shake), HEAP_HINT);
  6779. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6780. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6781. if (digest_stream) {
  6782. /* init keys */
  6783. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6784. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6785. useDeviceID ? devId : INVALID_DEVID);
  6786. if (ret != 0) {
  6787. printf("InitShake256 failed, ret = %d\n", ret);
  6788. goto exit;
  6789. }
  6790. }
  6791. bench_stats_start(&count, &start);
  6792. do {
  6793. for (times = 0; times < numBlocks || pending > 0; ) {
  6794. bench_async_poll(&pending);
  6795. /* while free pending slots in queue, submit ops */
  6796. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6797. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6798. 0, &times, numBlocks, &pending)) {
  6799. ret = wc_Shake256_Update(hash[i], bench_plain,
  6800. bench_size);
  6801. if (!bench_async_handle(&ret,
  6802. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6803. &times, &pending)) {
  6804. goto exit_shake256;
  6805. }
  6806. }
  6807. } /* for i */
  6808. RECORD_MULTI_VALUE_STATS();
  6809. } /* for times */
  6810. count += times;
  6811. times = 0;
  6812. do {
  6813. bench_async_poll(&pending);
  6814. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6815. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6816. 0, &times, numBlocks, &pending)) {
  6817. ret = wc_Shake256_Final(hash[i], digest[i],
  6818. WC_SHA3_256_BLOCK_SIZE);
  6819. if (!bench_async_handle(&ret,
  6820. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6821. &times, &pending)) {
  6822. goto exit_shake256;
  6823. }
  6824. }
  6825. } /* for i */
  6826. } while (pending > 0);
  6827. } while (bench_stats_check(start)
  6828. #ifdef MULTI_VALUE_STATISTICS
  6829. || runs < minimum_runs
  6830. #endif
  6831. );
  6832. }
  6833. else {
  6834. bench_stats_start(&count, &start);
  6835. do {
  6836. for (times = 0; times < numBlocks; times++) {
  6837. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6838. useDeviceID ? devId : INVALID_DEVID);
  6839. if (ret == 0)
  6840. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6841. if (ret == 0)
  6842. ret = wc_Shake256_Final(hash[0], digest[0],
  6843. WC_SHA3_256_BLOCK_SIZE);
  6844. if (ret != 0)
  6845. goto exit_shake256;
  6846. RECORD_MULTI_VALUE_STATS();
  6847. } /* for times */
  6848. count += times;
  6849. } while (bench_stats_check(start)
  6850. #ifdef MULTI_VALUE_STATISTICS
  6851. || runs < minimum_runs
  6852. #endif
  6853. );
  6854. }
  6855. exit_shake256:
  6856. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6857. start, ret);
  6858. #ifdef MULTI_VALUE_STATISTICS
  6859. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6860. #endif
  6861. exit:
  6862. if (WC_ARRAY_OK(hash)) {
  6863. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6864. wc_Shake256_Free(hash[i]);
  6865. }
  6866. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6867. }
  6868. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6869. }
  6870. #endif /* WOLFSSL_SHAKE256 */
  6871. #endif
  6872. #ifdef WOLFSSL_SM3
  6873. void bench_sm3(int useDeviceID)
  6874. {
  6875. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6876. sizeof(wc_Sm3), HEAP_HINT);
  6877. double start;
  6878. int ret = 0, i, count = 0, times, pending = 0;
  6879. DECLARE_MULTI_VALUE_STATS_VARS()
  6880. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6881. HEAP_HINT);
  6882. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6883. sizeof(wc_Sm3), HEAP_HINT);
  6884. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6885. HEAP_HINT);
  6886. if (digest_stream) {
  6887. /* init keys */
  6888. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6889. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6890. useDeviceID ? devId: INVALID_DEVID);
  6891. if (ret != 0) {
  6892. printf("InitSm3 failed, ret = %d\n", ret);
  6893. goto exit;
  6894. }
  6895. }
  6896. bench_stats_start(&count, &start);
  6897. do {
  6898. for (times = 0; times < numBlocks || pending > 0; ) {
  6899. bench_async_poll(&pending);
  6900. /* while free pending slots in queue, submit ops */
  6901. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6902. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6903. 0, &times, numBlocks, &pending)) {
  6904. ret = wc_Sm3Update(hash[i], bench_plain,
  6905. bench_size);
  6906. if (!bench_async_handle(&ret,
  6907. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6908. goto exit_sm3;
  6909. }
  6910. }
  6911. } /* for i */
  6912. RECORD_MULTI_VALUE_STATS();
  6913. } /* for times */
  6914. count += times;
  6915. times = 0;
  6916. do {
  6917. bench_async_poll(&pending);
  6918. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6919. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6920. 0, &times, numBlocks, &pending)) {
  6921. ret = wc_Sm3Final(hash[i], digest[i]);
  6922. if (!bench_async_handle(&ret,
  6923. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6924. goto exit_sm3;
  6925. }
  6926. }
  6927. } /* for i */
  6928. } while (pending > 0);
  6929. } while (bench_stats_check(start)
  6930. #ifdef MULTI_VALUE_STATISTICS
  6931. || runs < minimum_runs
  6932. #endif
  6933. );
  6934. }
  6935. else {
  6936. bench_stats_start(&count, &start);
  6937. do {
  6938. for (times = 0; times < numBlocks; times++) {
  6939. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6940. useDeviceID ? devId: INVALID_DEVID);
  6941. if (ret == 0)
  6942. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6943. if (ret == 0)
  6944. ret = wc_Sm3Final(hash[0], digest[0]);
  6945. if (ret != 0)
  6946. goto exit_sm3;
  6947. RECORD_MULTI_VALUE_STATS();
  6948. } /* for times */
  6949. count += times;
  6950. } while (bench_stats_check(start)
  6951. #ifdef MULTI_VALUE_STATISTICS
  6952. || runs < minimum_runs
  6953. #endif
  6954. );
  6955. }
  6956. exit_sm3:
  6957. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6958. #ifdef MULTI_VALUE_STATISTICS
  6959. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6960. #endif
  6961. exit:
  6962. if (WC_ARRAY_OK(hash)) {
  6963. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6964. wc_Sm3Free(hash[i]);
  6965. }
  6966. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6967. }
  6968. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6969. }
  6970. #endif
  6971. #ifdef WOLFSSL_RIPEMD
  6972. void bench_ripemd(void)
  6973. {
  6974. RipeMd hash;
  6975. byte digest[RIPEMD_DIGEST_SIZE];
  6976. double start;
  6977. int i, count, ret = 0;
  6978. DECLARE_MULTI_VALUE_STATS_VARS()
  6979. if (digest_stream) {
  6980. ret = wc_InitRipeMd(&hash);
  6981. if (ret != 0) {
  6982. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6983. return;
  6984. }
  6985. bench_stats_start(&count, &start);
  6986. do {
  6987. for (i = 0; i < numBlocks; i++) {
  6988. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6989. if (ret != 0) {
  6990. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6991. return;
  6992. }
  6993. RECORD_MULTI_VALUE_STATS();
  6994. }
  6995. ret = wc_RipeMdFinal(&hash, digest);
  6996. if (ret != 0) {
  6997. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6998. return;
  6999. }
  7000. count += i;
  7001. } while (bench_stats_check(start)
  7002. #ifdef MULTI_VALUE_STATISTICS
  7003. || runs < minimum_runs
  7004. #endif
  7005. );
  7006. }
  7007. else {
  7008. bench_stats_start(&count, &start);
  7009. do {
  7010. for (i = 0; i < numBlocks; i++) {
  7011. ret = wc_InitRipeMd(&hash);
  7012. if (ret != 0) {
  7013. printf("wc_InitRipeMd failed, retval %d\n", ret);
  7014. return;
  7015. }
  7016. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  7017. if (ret != 0) {
  7018. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7019. return;
  7020. }
  7021. ret = wc_RipeMdFinal(&hash, digest);
  7022. if (ret != 0) {
  7023. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7024. return;
  7025. }
  7026. RECORD_MULTI_VALUE_STATS();
  7027. }
  7028. count += i;
  7029. } while (bench_stats_check(start)
  7030. #ifdef MULTI_VALUE_STATISTICS
  7031. || runs < minimum_runs
  7032. #endif
  7033. );
  7034. }
  7035. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  7036. #ifdef MULTI_VALUE_STATISTICS
  7037. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7038. #endif
  7039. return;
  7040. }
  7041. #endif
  7042. #ifdef HAVE_BLAKE2
  7043. void bench_blake2b(void)
  7044. {
  7045. Blake2b b2b;
  7046. byte digest[64];
  7047. double start;
  7048. int ret = 0, i, count;
  7049. DECLARE_MULTI_VALUE_STATS_VARS()
  7050. if (digest_stream) {
  7051. ret = wc_InitBlake2b(&b2b, 64);
  7052. if (ret != 0) {
  7053. printf("InitBlake2b failed, ret = %d\n", ret);
  7054. return;
  7055. }
  7056. bench_stats_start(&count, &start);
  7057. do {
  7058. for (i = 0; i < numBlocks; i++) {
  7059. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7060. if (ret != 0) {
  7061. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7062. return;
  7063. }
  7064. RECORD_MULTI_VALUE_STATS();
  7065. }
  7066. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7067. if (ret != 0) {
  7068. printf("Blake2bFinal failed, ret = %d\n", ret);
  7069. return;
  7070. }
  7071. count += i;
  7072. } while (bench_stats_check(start)
  7073. #ifdef MULTI_VALUE_STATISTICS
  7074. || runs < minimum_runs
  7075. #endif
  7076. );
  7077. }
  7078. else {
  7079. bench_stats_start(&count, &start);
  7080. do {
  7081. for (i = 0; i < numBlocks; i++) {
  7082. ret = wc_InitBlake2b(&b2b, 64);
  7083. if (ret != 0) {
  7084. printf("InitBlake2b failed, ret = %d\n", ret);
  7085. return;
  7086. }
  7087. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7088. if (ret != 0) {
  7089. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7090. return;
  7091. }
  7092. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7093. if (ret != 0) {
  7094. printf("Blake2bFinal failed, ret = %d\n", ret);
  7095. return;
  7096. }
  7097. RECORD_MULTI_VALUE_STATS();
  7098. }
  7099. count += i;
  7100. } while (bench_stats_check(start)
  7101. #ifdef MULTI_VALUE_STATISTICS
  7102. || runs < minimum_runs
  7103. #endif
  7104. );
  7105. }
  7106. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7107. #ifdef MULTI_VALUE_STATISTICS
  7108. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7109. #endif
  7110. }
  7111. #endif
  7112. #if defined(HAVE_BLAKE2S)
  7113. void bench_blake2s(void)
  7114. {
  7115. Blake2s b2s;
  7116. byte digest[32];
  7117. double start;
  7118. int ret = 0, i, count;
  7119. DECLARE_MULTI_VALUE_STATS_VARS()
  7120. if (digest_stream) {
  7121. ret = wc_InitBlake2s(&b2s, 32);
  7122. if (ret != 0) {
  7123. printf("InitBlake2s failed, ret = %d\n", ret);
  7124. return;
  7125. }
  7126. bench_stats_start(&count, &start);
  7127. do {
  7128. for (i = 0; i < numBlocks; i++) {
  7129. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7130. if (ret != 0) {
  7131. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7132. return;
  7133. }
  7134. RECORD_MULTI_VALUE_STATS();
  7135. }
  7136. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7137. if (ret != 0) {
  7138. printf("Blake2sFinal failed, ret = %d\n", ret);
  7139. return;
  7140. }
  7141. count += i;
  7142. } while (bench_stats_check(start)
  7143. #ifdef MULTI_VALUE_STATISTICS
  7144. || runs < minimum_runs
  7145. #endif
  7146. );
  7147. }
  7148. else {
  7149. bench_stats_start(&count, &start);
  7150. do {
  7151. for (i = 0; i < numBlocks; i++) {
  7152. ret = wc_InitBlake2s(&b2s, 32);
  7153. if (ret != 0) {
  7154. printf("InitBlake2b failed, ret = %d\n", ret);
  7155. return;
  7156. }
  7157. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7158. if (ret != 0) {
  7159. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7160. return;
  7161. }
  7162. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7163. if (ret != 0) {
  7164. printf("Blake2sFinal failed, ret = %d\n", ret);
  7165. return;
  7166. }
  7167. RECORD_MULTI_VALUE_STATS();
  7168. }
  7169. count += i;
  7170. } while (bench_stats_check(start)
  7171. #ifdef MULTI_VALUE_STATISTICS
  7172. || runs < minimum_runs
  7173. #endif
  7174. );
  7175. }
  7176. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7177. #ifdef MULTI_VALUE_STATISTICS
  7178. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7179. #endif
  7180. }
  7181. #endif
  7182. #ifdef WOLFSSL_CMAC
  7183. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7184. {
  7185. Cmac cmac;
  7186. byte digest[WC_AES_BLOCK_SIZE];
  7187. word32 digestSz = sizeof(digest);
  7188. double start;
  7189. int ret, i, count;
  7190. DECLARE_MULTI_VALUE_STATS_VARS()
  7191. #ifdef WOLFSSL_SECO_CAAM
  7192. unsigned int keyID;
  7193. int keyGroup = 1; /* group one was chosen arbitrarily */
  7194. int keyInfo = CAAM_KEY_TRANSIENT;
  7195. int keyType = CAAM_KEYTYPE_AES128;
  7196. byte pubKey[AES_256_KEY_SIZE];
  7197. if (keySz == AES_256_KEY_SIZE) {
  7198. keyType = CAAM_KEYTYPE_AES256;
  7199. }
  7200. if (useDeviceID &&
  7201. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7202. keyInfo, &keyID) != 0) {
  7203. printf("Error generating key in hsm\n");
  7204. return;
  7205. }
  7206. #endif
  7207. (void)useDeviceID;
  7208. bench_stats_start(&count, &start);
  7209. do {
  7210. #ifdef HAVE_FIPS
  7211. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7212. #else
  7213. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7214. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7215. #endif
  7216. if (ret != 0) {
  7217. printf("InitCmac failed, ret = %d\n", ret);
  7218. return;
  7219. }
  7220. #ifdef WOLFSSL_SECO_CAAM
  7221. if (useDeviceID) {
  7222. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7223. }
  7224. #endif
  7225. for (i = 0; i < numBlocks; i++) {
  7226. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7227. if (ret != 0) {
  7228. printf("CmacUpdate failed, ret = %d\n", ret);
  7229. return;
  7230. }
  7231. RECORD_MULTI_VALUE_STATS();
  7232. }
  7233. /* Note: final force zero's the Cmac struct */
  7234. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7235. if (ret != 0) {
  7236. printf("CmacFinal failed, ret = %d\n", ret);
  7237. return;
  7238. }
  7239. count += i;
  7240. } while (bench_stats_check(start)
  7241. #ifdef MULTI_VALUE_STATISTICS
  7242. || runs < minimum_runs
  7243. #endif
  7244. );
  7245. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7246. #ifdef MULTI_VALUE_STATISTICS
  7247. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7248. #endif
  7249. }
  7250. void bench_cmac(int useDeviceID)
  7251. {
  7252. #ifdef WOLFSSL_AES_128
  7253. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7254. #endif
  7255. #ifdef WOLFSSL_AES_256
  7256. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7257. #endif
  7258. }
  7259. #endif /* WOLFSSL_CMAC */
  7260. #ifdef HAVE_SCRYPT
  7261. void bench_scrypt(void)
  7262. {
  7263. byte derived[64];
  7264. double start;
  7265. int ret, i, count;
  7266. DECLARE_MULTI_VALUE_STATS_VARS()
  7267. bench_stats_start(&count, &start);
  7268. do {
  7269. for (i = 0; i < scryptCnt; i++) {
  7270. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7271. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7272. sizeof(derived));
  7273. if (ret != 0) {
  7274. printf("scrypt failed, ret = %d\n", ret);
  7275. goto exit;
  7276. }
  7277. RECORD_MULTI_VALUE_STATS();
  7278. }
  7279. count += i;
  7280. } while (bench_stats_check(start)
  7281. #ifdef MULTI_VALUE_STATISTICS
  7282. || runs < minimum_runs
  7283. #endif
  7284. );
  7285. exit:
  7286. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7287. #ifdef MULTI_VALUE_STATISTICS
  7288. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7289. #endif
  7290. }
  7291. #endif /* HAVE_SCRYPT */
  7292. #ifndef NO_HMAC
  7293. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7294. const byte* key, word32 keySz, const char* label)
  7295. {
  7296. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7297. sizeof(Hmac), HEAP_HINT);
  7298. double start;
  7299. int ret = 0, i, count = 0, times, pending = 0;
  7300. DECLARE_MULTI_VALUE_STATS_VARS()
  7301. #ifdef WOLFSSL_ASYNC_CRYPT
  7302. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7303. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7304. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7305. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7306. #else
  7307. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7308. #endif
  7309. (void)digestSz;
  7310. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7311. sizeof(Hmac), HEAP_HINT);
  7312. /* init keys */
  7313. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7314. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7315. useDeviceID ? devId : INVALID_DEVID);
  7316. if (ret != 0) {
  7317. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7318. goto exit;
  7319. }
  7320. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7321. if (ret != 0) {
  7322. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7323. goto exit;
  7324. }
  7325. }
  7326. bench_stats_start(&count, &start);
  7327. do {
  7328. for (times = 0; times < numBlocks || pending > 0; ) {
  7329. bench_async_poll(&pending);
  7330. /* while free pending slots in queue, submit ops */
  7331. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7332. if (bench_async_check(&ret,
  7333. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7334. &times, numBlocks, &pending)) {
  7335. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7336. if (!bench_async_handle(&ret,
  7337. BENCH_ASYNC_GET_DEV(hmac[i]),
  7338. 0, &times, &pending)) {
  7339. goto exit_hmac;
  7340. }
  7341. }
  7342. } /* for i */
  7343. } /* for times */
  7344. count += times;
  7345. times = 0;
  7346. do {
  7347. bench_async_poll(&pending);
  7348. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7349. if (bench_async_check(&ret,
  7350. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7351. &times, numBlocks, &pending)) {
  7352. ret = wc_HmacFinal(hmac[i], digest[i]);
  7353. if (!bench_async_handle(&ret,
  7354. BENCH_ASYNC_GET_DEV(hmac[i]),
  7355. 0, &times, &pending)) {
  7356. goto exit_hmac;
  7357. }
  7358. }
  7359. RECORD_MULTI_VALUE_STATS();
  7360. } /* for i */
  7361. } while (pending > 0);
  7362. } while (bench_stats_check(start)
  7363. #ifdef MULTI_VALUE_STATISTICS
  7364. || runs < minimum_runs
  7365. #endif
  7366. );
  7367. exit_hmac:
  7368. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7369. #ifdef MULTI_VALUE_STATISTICS
  7370. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7371. #endif
  7372. exit:
  7373. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7374. wc_HmacFree(hmac[i]);
  7375. }
  7376. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7377. #ifdef WOLFSSL_ASYNC_CRYPT
  7378. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7379. #endif
  7380. }
  7381. #ifndef NO_MD5
  7382. void bench_hmac_md5(int useDeviceID)
  7383. {
  7384. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7385. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7386. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7387. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7388. "HMAC-MD5");
  7389. }
  7390. #endif /* NO_MD5 */
  7391. #ifndef NO_SHA
  7392. void bench_hmac_sha(int useDeviceID)
  7393. {
  7394. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7395. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7396. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7397. 0x0b, 0x0b, 0x0b, 0x0b };
  7398. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7399. "HMAC-SHA");
  7400. }
  7401. #endif /* NO_SHA */
  7402. #ifdef WOLFSSL_SHA224
  7403. void bench_hmac_sha224(int useDeviceID)
  7404. {
  7405. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  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 };
  7410. bench_hmac(useDeviceID, WC_SHA224,
  7411. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7412. "HMAC-SHA224");
  7413. }
  7414. #endif /* WOLFSSL_SHA224 */
  7415. #ifndef NO_SHA256
  7416. void bench_hmac_sha256(int useDeviceID)
  7417. {
  7418. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7419. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7420. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7421. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7422. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7423. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7424. "HMAC-SHA256");
  7425. }
  7426. #endif /* NO_SHA256 */
  7427. #ifdef WOLFSSL_SHA384
  7428. void bench_hmac_sha384(int useDeviceID)
  7429. {
  7430. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7431. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7432. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7433. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7434. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7435. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7436. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7437. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7438. "HMAC-SHA384");
  7439. }
  7440. #endif /* WOLFSSL_SHA384 */
  7441. #ifdef WOLFSSL_SHA512
  7442. void bench_hmac_sha512(int useDeviceID)
  7443. {
  7444. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7445. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7446. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7447. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7448. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7449. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7450. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7451. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7452. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7453. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7454. "HMAC-SHA512");
  7455. }
  7456. #endif /* WOLFSSL_SHA512 */
  7457. #ifndef NO_PWDBASED
  7458. void bench_pbkdf2(void)
  7459. {
  7460. double start;
  7461. int ret = 0, count = 0;
  7462. const char* passwd32 = "passwordpasswordpasswordpassword";
  7463. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7464. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7465. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7466. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7467. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7468. byte derived[32];
  7469. DECLARE_MULTI_VALUE_STATS_VARS()
  7470. bench_stats_start(&count, &start);
  7471. PRIVATE_KEY_UNLOCK();
  7472. do {
  7473. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7474. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7475. count++;
  7476. RECORD_MULTI_VALUE_STATS();
  7477. } while (bench_stats_check(start)
  7478. #ifdef MULTI_VALUE_STATISTICS
  7479. || runs < minimum_runs
  7480. #endif
  7481. );
  7482. PRIVATE_KEY_LOCK();
  7483. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7484. #ifdef MULTI_VALUE_STATISTICS
  7485. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7486. #endif
  7487. }
  7488. #endif /* !NO_PWDBASED */
  7489. #endif /* NO_HMAC */
  7490. #ifdef WOLFSSL_SIPHASH
  7491. void bench_siphash(void)
  7492. {
  7493. double start;
  7494. int ret = 0, count;
  7495. const char* passwd16 = "passwordpassword";
  7496. byte out[16];
  7497. int i;
  7498. DECLARE_MULTI_VALUE_STATS_VARS()
  7499. bench_stats_start(&count, &start);
  7500. do {
  7501. for (i = 0; i < numBlocks; i++) {
  7502. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7503. out, 8);
  7504. RECORD_MULTI_VALUE_STATS();
  7505. }
  7506. count += i;
  7507. } while (bench_stats_check(start)
  7508. #ifdef MULTI_VALUE_STATISTICS
  7509. || runs < minimum_runs
  7510. #endif
  7511. );
  7512. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7513. #ifdef MULTI_VALUE_STATISTICS
  7514. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7515. #endif
  7516. RESET_MULTI_VALUE_STATS_VARS();
  7517. bench_stats_start(&count, &start);
  7518. do {
  7519. for (i = 0; i < numBlocks; i++) {
  7520. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7521. out, 16);
  7522. RECORD_MULTI_VALUE_STATS();
  7523. }
  7524. count += i;
  7525. } while (bench_stats_check(start)
  7526. #ifdef MULTI_VALUE_STATISTICS
  7527. || runs < minimum_runs
  7528. #endif
  7529. );
  7530. bench_stats_sym_finish("SipHash-16", 1, count, bench_size, start, ret);
  7531. #ifdef MULTI_VALUE_STATISTICS
  7532. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7533. #endif
  7534. }
  7535. #endif
  7536. #ifdef WC_SRTP_KDF
  7537. void bench_srtpkdf(void)
  7538. {
  7539. double start;
  7540. int count;
  7541. int ret = 0;
  7542. byte keyE[32];
  7543. byte keyA[20];
  7544. byte keyS[14];
  7545. const byte *key = bench_key_buf;
  7546. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7547. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7548. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7549. int kdrIdx = 0;
  7550. int i;
  7551. DECLARE_MULTI_VALUE_STATS_VARS()
  7552. bench_stats_start(&count, &start);
  7553. PRIVATE_KEY_UNLOCK();
  7554. do {
  7555. for (i = 0; i < numBlocks; i++) {
  7556. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7557. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7558. keyS, sizeof(keyS));
  7559. RECORD_MULTI_VALUE_STATS();
  7560. }
  7561. count += i;
  7562. } while (bench_stats_check(start)
  7563. #ifdef MULTI_VALUE_STATISTICS
  7564. || runs < minimum_runs
  7565. #endif
  7566. );
  7567. PRIVATE_KEY_LOCK();
  7568. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7569. #ifdef MULTI_VALUE_STATISTICS
  7570. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7571. #endif
  7572. RESET_MULTI_VALUE_STATS_VARS();
  7573. bench_stats_start(&count, &start);
  7574. PRIVATE_KEY_UNLOCK();
  7575. do {
  7576. for (i = 0; i < numBlocks; i++) {
  7577. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7578. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7579. keyS, sizeof(keyS));
  7580. RECORD_MULTI_VALUE_STATS();
  7581. }
  7582. count += i;
  7583. } while (bench_stats_check(start)
  7584. #ifdef MULTI_VALUE_STATISTICS
  7585. || runs < minimum_runs
  7586. #endif
  7587. );
  7588. PRIVATE_KEY_LOCK();
  7589. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7590. #ifdef MULTI_VALUE_STATISTICS
  7591. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7592. #endif
  7593. RESET_MULTI_VALUE_STATS_VARS();
  7594. bench_stats_start(&count, &start);
  7595. PRIVATE_KEY_UNLOCK();
  7596. do {
  7597. for (i = 0; i < numBlocks; i++) {
  7598. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7599. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7600. keyS, sizeof(keyS));
  7601. RECORD_MULTI_VALUE_STATS();
  7602. }
  7603. count += i;
  7604. } while (bench_stats_check(start)
  7605. #ifdef MULTI_VALUE_STATISTICS
  7606. || runs < minimum_runs
  7607. #endif
  7608. );
  7609. PRIVATE_KEY_LOCK();
  7610. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7611. #ifdef MULTI_VALUE_STATISTICS
  7612. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7613. #endif
  7614. RESET_MULTI_VALUE_STATS_VARS();
  7615. bench_stats_start(&count, &start);
  7616. PRIVATE_KEY_UNLOCK();
  7617. do {
  7618. for (i = 0; i < numBlocks; i++) {
  7619. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7620. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7621. keyS, sizeof(keyS));
  7622. RECORD_MULTI_VALUE_STATS();
  7623. }
  7624. count += i;
  7625. } while (bench_stats_check(start)
  7626. #ifdef MULTI_VALUE_STATISTICS
  7627. || runs < minimum_runs
  7628. #endif
  7629. );
  7630. PRIVATE_KEY_LOCK();
  7631. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7632. #ifdef MULTI_VALUE_STATISTICS
  7633. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7634. #endif
  7635. }
  7636. #endif
  7637. #ifndef NO_RSA
  7638. #if defined(WOLFSSL_KEY_GEN)
  7639. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7640. {
  7641. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7642. sizeof(RsaKey), HEAP_HINT);
  7643. double start = 0;
  7644. int ret = 0, i, count = 0, times, pending = 0;
  7645. const long rsa_e_val = WC_RSA_EXPONENT;
  7646. const char**desc = bench_desc_words[lng_index];
  7647. DECLARE_MULTI_VALUE_STATS_VARS()
  7648. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7649. sizeof(RsaKey), HEAP_HINT);
  7650. bench_stats_start(&count, &start);
  7651. do {
  7652. /* while free pending slots in queue, submit ops */
  7653. for (times = 0; times < genTimes || pending > 0; ) {
  7654. bench_async_poll(&pending);
  7655. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7656. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7657. 0, &times, genTimes, &pending)) {
  7658. wc_FreeRsaKey(genKey[i]);
  7659. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7660. if (ret < 0) {
  7661. goto exit;
  7662. }
  7663. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7664. &gRng);
  7665. if (!bench_async_handle(&ret,
  7666. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7667. &times, &pending)) {
  7668. goto exit;
  7669. }
  7670. }
  7671. } /* for i */
  7672. RECORD_MULTI_VALUE_STATS();
  7673. } /* for times */
  7674. count += times;
  7675. } while (bench_stats_check(start)
  7676. #ifdef MULTI_VALUE_STATISTICS
  7677. || runs < minimum_runs
  7678. #endif
  7679. );
  7680. exit:
  7681. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7682. start, ret);
  7683. #ifdef MULTI_VALUE_STATISTICS
  7684. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7685. #endif
  7686. /* cleanup */
  7687. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7688. wc_FreeRsaKey(genKey[i]);
  7689. }
  7690. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7691. }
  7692. void bench_rsaKeyGen(int useDeviceID)
  7693. {
  7694. int k;
  7695. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7696. static const word32 keySizes[2] = {1024, 2048 };
  7697. #elif RSA_MAX_SIZE >= 4096
  7698. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7699. (RSA_MIN_SIZE <= 1024)
  7700. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7701. #else
  7702. static const word32 keySizes[3] = {2048, 3072, 4096};
  7703. #endif
  7704. #elif RSA_MAX_SIZE >= 3072
  7705. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7706. (RSA_MIN_SIZE <= 1024)
  7707. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7708. #else
  7709. static const word32 keySizes[2] = {2048, 3072 };
  7710. #endif
  7711. #elif RSA_MAX_SIZE >= 2048
  7712. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7713. (RSA_MIN_SIZE <= 1024)
  7714. static const word32 keySizes[2] = {1024, 2048 };
  7715. #else
  7716. static const word32 keySizes[1] = {2048};
  7717. #endif
  7718. #else
  7719. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7720. (RSA_MIN_SIZE <= 1024)
  7721. static const word32 keySizes[1] = {1024 };
  7722. #else
  7723. #error No candidate RSA key sizes to benchmark.
  7724. #endif
  7725. #endif
  7726. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7727. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7728. }
  7729. }
  7730. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7731. {
  7732. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7733. }
  7734. #endif /* WOLFSSL_KEY_GEN */
  7735. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7736. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7737. #if defined(WOLFSSL_MDK_SHELL)
  7738. static char *certRSAname = "certs/rsa2048.der";
  7739. /* set by shell command */
  7740. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7741. #elif defined(FREESCALE_MQX)
  7742. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7743. #else
  7744. static const char *certRSAname = "certs/rsa2048.der";
  7745. #endif
  7746. #endif
  7747. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7748. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7749. #if defined(USE_CERT_BUFFERS_2048)
  7750. static const unsigned char rsa_2048_sig[] = {
  7751. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7752. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7753. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7754. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7755. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7756. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7757. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7758. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7759. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7760. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7761. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7762. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7763. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7764. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7765. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7766. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7767. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7768. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7769. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7770. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7771. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7772. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7773. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7774. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7775. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7776. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7777. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7778. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7779. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7780. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7781. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7782. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7783. };
  7784. #elif defined(USE_CERT_BUFFERS_3072)
  7785. static const unsigned char rsa_3072_sig[] = {
  7786. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7787. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7788. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7789. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7790. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7791. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7792. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7793. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7794. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7795. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7796. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7797. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7798. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7799. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7800. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7801. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7802. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7803. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7804. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7805. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7806. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7807. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7808. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7809. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7810. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7811. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7812. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7813. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7814. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7815. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7816. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7817. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7818. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7819. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7820. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7821. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7822. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7823. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7824. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7825. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7826. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7827. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7828. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7829. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7830. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7831. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7832. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7833. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7834. };
  7835. #else
  7836. #error Not Supported Yet!
  7837. #endif
  7838. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7839. static void bench_rsa_helper(int useDeviceID,
  7840. WC_ARRAY_ARG(rsaKey,
  7841. RsaKey,
  7842. BENCH_MAX_PENDING,
  7843. sizeof(RsaKey)),
  7844. word32 rsaKeySz)
  7845. {
  7846. int ret = 0, i, times, count = 0, pending = 0;
  7847. word32 idx = 0;
  7848. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7849. const char* messageStr = TEST_STRING;
  7850. const int len = (int)TEST_STRING_SZ;
  7851. #endif
  7852. double start = 0.0F;
  7853. const char**desc = bench_desc_words[lng_index];
  7854. DECLARE_MULTI_VALUE_STATS_VARS()
  7855. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7856. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7857. #endif
  7858. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7859. rsaKeySz, HEAP_HINT);
  7860. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7861. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7862. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7863. rsaKeySz, HEAP_HINT);
  7864. #else
  7865. byte* out[BENCH_MAX_PENDING];
  7866. #endif
  7867. XMEMSET(out, 0, sizeof(out));
  7868. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7869. rsaKeySz, HEAP_HINT);
  7870. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7871. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7872. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7873. rsaKeySz, HEAP_HINT);
  7874. if (out[0] == NULL) {
  7875. ret = MEMORY_E;
  7876. goto exit;
  7877. }
  7878. #endif
  7879. if (enc[0] == NULL) {
  7880. ret = MEMORY_E;
  7881. goto exit;
  7882. }
  7883. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7884. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7885. XMEMCPY(message, messageStr, len);
  7886. #endif
  7887. if (!rsa_sign_verify) {
  7888. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7889. /* begin public RSA */
  7890. bench_stats_start(&count, &start);
  7891. do {
  7892. for (times = 0; times < ntimes || pending > 0; ) {
  7893. bench_async_poll(&pending);
  7894. /* while free pending slots in queue, submit ops */
  7895. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7896. if (bench_async_check(&ret,
  7897. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7898. 1, &times, ntimes, &pending)) {
  7899. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7900. rsaKeySz/8, rsaKey[i],
  7901. GLOBAL_RNG);
  7902. if (!bench_async_handle(&ret,
  7903. BENCH_ASYNC_GET_DEV(
  7904. rsaKey[i]), 1, &times,
  7905. &pending)) {
  7906. goto exit_rsa_verify;
  7907. }
  7908. }
  7909. } /* for i */
  7910. RECORD_MULTI_VALUE_STATS();
  7911. } /* for times */
  7912. count += times;
  7913. } while (bench_stats_check(start)
  7914. #ifdef MULTI_VALUE_STATISTICS
  7915. || runs < minimum_runs
  7916. #endif
  7917. );
  7918. exit_rsa_verify:
  7919. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7920. useDeviceID, count, start, ret);
  7921. #ifdef MULTI_VALUE_STATISTICS
  7922. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7923. #endif
  7924. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7925. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7926. if (ret < 0) {
  7927. goto exit;
  7928. }
  7929. RESET_MULTI_VALUE_STATS_VARS();
  7930. /* capture resulting encrypt length */
  7931. idx = (word32)(rsaKeySz/8);
  7932. /* begin private async RSA */
  7933. bench_stats_start(&count, &start);
  7934. do {
  7935. for (times = 0; times < ntimes || pending > 0; ) {
  7936. bench_async_poll(&pending);
  7937. /* while free pending slots in queue, submit ops */
  7938. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7939. if (bench_async_check(&ret,
  7940. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7941. 1, &times, ntimes, &pending)) {
  7942. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7943. rsaKeySz/8, rsaKey[i]);
  7944. if (!bench_async_handle(&ret,
  7945. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7946. 1, &times, &pending)) {
  7947. goto exit_rsa_pub;
  7948. }
  7949. }
  7950. } /* for i */
  7951. RECORD_MULTI_VALUE_STATS();
  7952. } /* for times */
  7953. count += times;
  7954. } while (bench_stats_check(start)
  7955. #ifdef MULTI_VALUE_STATISTICS
  7956. || runs < minimum_runs
  7957. #endif
  7958. );
  7959. exit_rsa_pub:
  7960. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7961. useDeviceID, count, start, ret);
  7962. #ifdef MULTI_VALUE_STATISTICS
  7963. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7964. #endif
  7965. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7966. }
  7967. else {
  7968. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7969. /* begin RSA sign */
  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. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7980. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7981. if (!bench_async_handle(&ret,
  7982. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7983. 1, &times, &pending)) {
  7984. goto exit_rsa_sign;
  7985. }
  7986. }
  7987. } /* for i */
  7988. RECORD_MULTI_VALUE_STATS();
  7989. } /* for times */
  7990. count += times;
  7991. } while (bench_stats_check(start)
  7992. #ifdef MULTI_VALUE_STATISTICS
  7993. || runs < minimum_runs
  7994. #endif
  7995. );
  7996. exit_rsa_sign:
  7997. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7998. count, start, ret);
  7999. #ifdef MULTI_VALUE_STATISTICS
  8000. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8001. #endif
  8002. if (ret < 0) {
  8003. goto exit;
  8004. }
  8005. RESET_MULTI_VALUE_STATS_VARS();
  8006. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  8007. /* capture resulting encrypt length */
  8008. idx = rsaKeySz/8;
  8009. /* begin RSA verify */
  8010. bench_stats_start(&count, &start);
  8011. do {
  8012. for (times = 0; times < ntimes || pending > 0; ) {
  8013. bench_async_poll(&pending);
  8014. /* while free pending slots in queue, submit ops */
  8015. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8016. if (bench_async_check(&ret,
  8017. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8018. 1, &times, ntimes, &pending)) {
  8019. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  8020. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8021. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  8022. rsaKeySz/8, rsaKey[i]);
  8023. #elif defined(USE_CERT_BUFFERS_2048)
  8024. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  8025. idx = sizeof(rsa_2048_sig);
  8026. out[i] = NULL;
  8027. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8028. &out[i], rsaKey[i]);
  8029. if (ret > 0) {
  8030. ret = 0;
  8031. }
  8032. #elif defined(USE_CERT_BUFFERS_3072)
  8033. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  8034. idx = sizeof(rsa_3072_sig);
  8035. out[i] = NULL;
  8036. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8037. &out[i], rsaKey[i]);
  8038. if (ret > 0)
  8039. ret = 0;
  8040. #endif
  8041. if (!bench_async_handle(&ret,
  8042. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8043. 1, &times, &pending)) {
  8044. goto exit_rsa_verifyinline;
  8045. }
  8046. }
  8047. } /* for i */
  8048. RECORD_MULTI_VALUE_STATS();
  8049. } /* for times */
  8050. count += times;
  8051. } while (bench_stats_check(start)
  8052. #ifdef MULTI_VALUE_STATISTICS
  8053. || runs < minimum_runs
  8054. #endif
  8055. );
  8056. exit_rsa_verifyinline:
  8057. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8058. useDeviceID, count, start, ret);
  8059. #ifdef MULTI_VALUE_STATISTICS
  8060. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8061. #endif
  8062. }
  8063. exit:
  8064. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8065. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8066. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8067. #endif
  8068. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8069. WC_FREE_VAR(message, HEAP_HINT);
  8070. #endif
  8071. }
  8072. void bench_rsa(int useDeviceID)
  8073. {
  8074. int i;
  8075. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8076. sizeof(RsaKey), HEAP_HINT);
  8077. int ret = 0;
  8078. word32 rsaKeySz = 0;
  8079. const byte* tmp;
  8080. size_t bytes;
  8081. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8082. word32 idx;
  8083. #endif
  8084. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8085. sizeof(RsaKey), HEAP_HINT);
  8086. #ifdef USE_CERT_BUFFERS_1024
  8087. tmp = rsa_key_der_1024;
  8088. bytes = (size_t)sizeof_rsa_key_der_1024;
  8089. rsaKeySz = 1024;
  8090. #elif defined(USE_CERT_BUFFERS_2048)
  8091. tmp = rsa_key_der_2048;
  8092. bytes = (size_t)sizeof_rsa_key_der_2048;
  8093. rsaKeySz = 2048;
  8094. #elif defined(USE_CERT_BUFFERS_3072)
  8095. tmp = rsa_key_der_3072;
  8096. bytes = (size_t)sizeof_rsa_key_der_3072;
  8097. rsaKeySz = 3072;
  8098. #elif defined(USE_CERT_BUFFERS_4096)
  8099. tmp = client_key_der_4096;
  8100. bytes = (size_t)sizeof_client_key_der_4096;
  8101. rsaKeySz = 4096;
  8102. #else
  8103. #error "need a cert buffer size"
  8104. #endif /* USE_CERT_BUFFERS */
  8105. /* init keys */
  8106. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8107. /* setup an async context for each key */
  8108. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8109. useDeviceID ? devId : INVALID_DEVID);
  8110. if (ret < 0) {
  8111. goto exit;
  8112. }
  8113. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8114. #ifdef WC_RSA_BLINDING
  8115. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8116. if (ret != 0)
  8117. goto exit;
  8118. #endif
  8119. #endif
  8120. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8121. /* decode the private key */
  8122. idx = 0;
  8123. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8124. rsaKey[i], (word32)bytes)) != 0) {
  8125. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8126. goto exit;
  8127. }
  8128. #elif defined(WOLFSSL_PUBLIC_MP)
  8129. /* get offset to public portion of the RSA key */
  8130. #ifdef USE_CERT_BUFFERS_1024
  8131. bytes = 11;
  8132. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8133. bytes = 12;
  8134. #endif
  8135. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8136. if (ret != 0) {
  8137. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8138. goto exit;
  8139. }
  8140. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8141. if (ret != 0) {
  8142. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8143. goto exit;
  8144. }
  8145. #else
  8146. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8147. rsaKeySz = 0;
  8148. #endif
  8149. }
  8150. if (rsaKeySz > 0) {
  8151. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8152. }
  8153. (void)bytes;
  8154. (void)tmp;
  8155. exit:
  8156. /* cleanup */
  8157. if (WC_ARRAY_OK(rsaKey)) {
  8158. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8159. wc_FreeRsaKey(rsaKey[i]);
  8160. }
  8161. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8162. }
  8163. }
  8164. #ifdef WOLFSSL_KEY_GEN
  8165. /* bench any size of RSA key */
  8166. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8167. {
  8168. int ret = 0, i, pending = 0;
  8169. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8170. sizeof(RsaKey), HEAP_HINT);
  8171. int isPending[BENCH_MAX_PENDING];
  8172. long exp = 65537L;
  8173. /* clear for done cleanup */
  8174. XMEMSET(isPending, 0, sizeof(isPending));
  8175. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8176. sizeof(RsaKey), HEAP_HINT);
  8177. /* init keys */
  8178. do {
  8179. pending = 0;
  8180. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8181. if (!isPending[i]) { /* if making the key is pending then just call
  8182. * wc_MakeRsaKey again */
  8183. /* setup an async context for each key */
  8184. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8185. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8186. goto exit;
  8187. }
  8188. #ifdef WC_RSA_BLINDING
  8189. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8190. if (ret != 0)
  8191. goto exit;
  8192. #endif
  8193. }
  8194. /* create the RSA key */
  8195. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8196. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8197. isPending[i] = 1;
  8198. pending = 1;
  8199. }
  8200. else if (ret != 0) {
  8201. printf("wc_MakeRsaKey failed! %d\n", ret);
  8202. goto exit;
  8203. }
  8204. } /* for i */
  8205. } while (pending > 0);
  8206. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8207. exit:
  8208. /* cleanup */
  8209. if (WC_ARRAY_OK(rsaKey)) {
  8210. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8211. wc_FreeRsaKey(rsaKey[i]);
  8212. }
  8213. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8214. }
  8215. }
  8216. #endif /* WOLFSSL_KEY_GEN */
  8217. #endif /* !NO_RSA */
  8218. #ifndef NO_DH
  8219. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8220. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8221. #if defined(WOLFSSL_MDK_SHELL)
  8222. static char *certDHname = "certs/dh2048.der";
  8223. /* set by shell command */
  8224. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8225. #elif defined(FREESCALE_MQX)
  8226. static char *certDHname = "a:\\certs\\dh2048.der";
  8227. #elif defined(NO_ASN)
  8228. /* do nothing, but don't need a file */
  8229. #else
  8230. static const char *certDHname = "certs/dh2048.der";
  8231. #endif
  8232. #endif
  8233. #ifdef HAVE_FFDHE_4096
  8234. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8235. #else
  8236. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8237. #endif
  8238. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8239. void bench_dh(int useDeviceID)
  8240. {
  8241. int ret = 0, i;
  8242. int count = 0, times, pending = 0;
  8243. const byte* tmp = NULL;
  8244. double start = 0.0F;
  8245. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8246. sizeof(DhKey), HEAP_HINT);
  8247. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8248. const char**desc = bench_desc_words[lng_index];
  8249. #ifndef NO_ASN
  8250. size_t bytes = 0;
  8251. word32 idx;
  8252. #endif
  8253. word32 pubSz[BENCH_MAX_PENDING];
  8254. word32 privSz[BENCH_MAX_PENDING];
  8255. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8256. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8257. word32 agreeSz[BENCH_MAX_PENDING];
  8258. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8259. #ifdef HAVE_PUBLIC_FFDHE
  8260. const DhParams *params = NULL;
  8261. #else
  8262. int paramName = 0;
  8263. #endif
  8264. #endif
  8265. DECLARE_MULTI_VALUE_STATS_VARS()
  8266. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8267. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8268. WC_DECLARE_VAR(pub2, byte,
  8269. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8270. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8271. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8272. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8273. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8274. WC_DECLARE_VAR(priv2, byte,
  8275. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8276. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8277. XMEMSET(pub, 0, sizeof(pub));
  8278. XMEMSET(agree, 0, sizeof(agree));
  8279. XMEMSET(priv, 0, sizeof(priv));
  8280. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8281. sizeof(DhKey), HEAP_HINT);
  8282. WC_ALLOC_ARRAY(pub, byte,
  8283. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8284. WC_ALLOC_ARRAY(agree, byte,
  8285. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8286. WC_ALLOC_ARRAY(priv, byte,
  8287. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8288. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8289. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8290. (void)tmp;
  8291. if (!use_ffdhe) {
  8292. #if defined(NO_ASN)
  8293. dhKeySz = 1024;
  8294. /* do nothing, but don't use default FILE */
  8295. #elif defined(USE_CERT_BUFFERS_1024)
  8296. tmp = dh_key_der_1024;
  8297. bytes = (size_t)sizeof_dh_key_der_1024;
  8298. dhKeySz = 1024;
  8299. #elif defined(USE_CERT_BUFFERS_2048)
  8300. tmp = dh_key_der_2048;
  8301. bytes = (size_t)sizeof_dh_key_der_2048;
  8302. dhKeySz = 2048;
  8303. #elif defined(USE_CERT_BUFFERS_3072)
  8304. tmp = dh_key_der_3072;
  8305. bytes = (size_t)sizeof_dh_key_der_3072;
  8306. dhKeySz = 3072;
  8307. #elif defined(USE_CERT_BUFFERS_4096)
  8308. tmp = dh_key_der_4096;
  8309. bytes = (size_t)sizeof_dh_key_der_4096;
  8310. dhKeySz = 4096;
  8311. #else
  8312. #error "need to define a cert buffer size"
  8313. #endif /* USE_CERT_BUFFERS */
  8314. }
  8315. #ifdef HAVE_FFDHE_2048
  8316. else if (use_ffdhe == 2048) {
  8317. #ifdef HAVE_PUBLIC_FFDHE
  8318. params = wc_Dh_ffdhe2048_Get();
  8319. #else
  8320. paramName = WC_FFDHE_2048;
  8321. #endif
  8322. dhKeySz = 2048;
  8323. }
  8324. #endif
  8325. #ifdef HAVE_FFDHE_3072
  8326. else if (use_ffdhe == 3072) {
  8327. #ifdef HAVE_PUBLIC_FFDHE
  8328. params = wc_Dh_ffdhe3072_Get();
  8329. #else
  8330. paramName = WC_FFDHE_3072;
  8331. #endif
  8332. dhKeySz = 3072;
  8333. }
  8334. #endif
  8335. #ifdef HAVE_FFDHE_4096
  8336. else if (use_ffdhe == 4096) {
  8337. #ifdef HAVE_PUBLIC_FFDHE
  8338. params = wc_Dh_ffdhe4096_Get();
  8339. #else
  8340. paramName = WC_FFDHE_4096;
  8341. #endif
  8342. dhKeySz = 4096;
  8343. }
  8344. #endif
  8345. /* init keys */
  8346. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8347. /* setup an async context for each key */
  8348. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8349. useDeviceID ? devId : INVALID_DEVID);
  8350. if (ret != 0)
  8351. goto exit;
  8352. /* setup key */
  8353. if (!use_ffdhe) {
  8354. #ifdef NO_ASN
  8355. ret = wc_DhSetKey(dhKey[i], dh_p,
  8356. sizeof(dh_p), dh_g, sizeof(dh_g));
  8357. #else
  8358. idx = 0;
  8359. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8360. #endif
  8361. }
  8362. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8363. #ifdef HAVE_PUBLIC_FFDHE
  8364. else if (params != NULL) {
  8365. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8366. params->g, params->g_len);
  8367. }
  8368. #else
  8369. else if (paramName != 0) {
  8370. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8371. }
  8372. #endif
  8373. #endif
  8374. if (ret != 0) {
  8375. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8376. goto exit;
  8377. }
  8378. }
  8379. /* Key Gen */
  8380. bench_stats_start(&count, &start);
  8381. PRIVATE_KEY_UNLOCK();
  8382. do {
  8383. /* while free pending slots in queue, submit ops */
  8384. for (times = 0; times < genTimes || pending > 0; ) {
  8385. bench_async_poll(&pending);
  8386. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8387. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8388. 0, &times, genTimes, &pending)) {
  8389. privSz[i] = BENCH_DH_PRIV_SIZE;
  8390. pubSz[i] = BENCH_DH_KEY_SIZE;
  8391. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8392. priv[i], &privSz[i],
  8393. pub[i], &pubSz[i]);
  8394. if (!bench_async_handle(&ret,
  8395. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8396. 0, &times, &pending)) {
  8397. goto exit_dh_gen;
  8398. }
  8399. }
  8400. } /* for i */
  8401. RECORD_MULTI_VALUE_STATS();
  8402. } /* for times */
  8403. count += times;
  8404. } while (bench_stats_check(start)
  8405. #ifdef MULTI_VALUE_STATISTICS
  8406. || runs < minimum_runs
  8407. #endif
  8408. );
  8409. PRIVATE_KEY_LOCK();
  8410. exit_dh_gen:
  8411. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8412. useDeviceID, count, start, ret);
  8413. #ifdef MULTI_VALUE_STATISTICS
  8414. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8415. #endif
  8416. if (ret < 0) {
  8417. goto exit;
  8418. }
  8419. RESET_MULTI_VALUE_STATS_VARS();
  8420. /* Generate key to use as other public */
  8421. PRIVATE_KEY_UNLOCK();
  8422. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8423. priv2, &privSz2, pub2, &pubSz2);
  8424. PRIVATE_KEY_LOCK();
  8425. #ifdef WOLFSSL_ASYNC_CRYPT
  8426. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8427. #endif
  8428. /* Key Agree */
  8429. bench_stats_start(&count, &start);
  8430. PRIVATE_KEY_UNLOCK();
  8431. do {
  8432. for (times = 0; times < agreeTimes || pending > 0; ) {
  8433. bench_async_poll(&pending);
  8434. /* while free pending slots in queue, submit ops */
  8435. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8436. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8437. 0, &times, agreeTimes, &pending)) {
  8438. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8439. privSz[i], pub2, pubSz2);
  8440. if (!bench_async_handle(&ret,
  8441. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8442. goto exit;
  8443. }
  8444. }
  8445. } /* for i */
  8446. RECORD_MULTI_VALUE_STATS();
  8447. } /* for times */
  8448. count += times;
  8449. } while (bench_stats_check(start)
  8450. #ifdef MULTI_VALUE_STATISTICS
  8451. || runs < minimum_runs
  8452. #endif
  8453. );
  8454. PRIVATE_KEY_LOCK();
  8455. exit:
  8456. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8457. useDeviceID, count, start, ret);
  8458. #ifdef MULTI_VALUE_STATISTICS
  8459. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8460. #endif
  8461. /* cleanup */
  8462. if (WC_ARRAY_OK(dhKey)) {
  8463. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8464. wc_FreeDhKey(dhKey[i]);
  8465. }
  8466. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8467. }
  8468. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8469. WC_FREE_VAR(pub2, HEAP_HINT);
  8470. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8471. WC_FREE_VAR(priv2, HEAP_HINT);
  8472. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8473. }
  8474. #endif /* !NO_DH */
  8475. #ifdef WOLFSSL_HAVE_KYBER
  8476. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8477. KyberKey* key)
  8478. {
  8479. int ret = 0, times, count, pending = 0;
  8480. double start;
  8481. const char**desc = bench_desc_words[lng_index];
  8482. DECLARE_MULTI_VALUE_STATS_VARS()
  8483. /* KYBER Make Key */
  8484. bench_stats_start(&count, &start);
  8485. do {
  8486. /* while free pending slots in queue, submit ops */
  8487. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8488. wc_KyberKey_Free(key);
  8489. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8490. if (ret != 0)
  8491. goto exit;
  8492. #ifdef KYBER_NONDETERMINISTIC
  8493. ret = wc_KyberKey_MakeKey(key, &gRng);
  8494. #else
  8495. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8496. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8497. #endif
  8498. if (ret != 0)
  8499. goto exit;
  8500. RECORD_MULTI_VALUE_STATS();
  8501. } /* for times */
  8502. count += times;
  8503. } while (bench_stats_check(start)
  8504. #ifdef MULTI_VALUE_STATISTICS
  8505. || runs < minimum_runs
  8506. #endif
  8507. );
  8508. exit:
  8509. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8510. #ifdef MULTI_VALUE_STATISTICS
  8511. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8512. #endif
  8513. }
  8514. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8515. {
  8516. int ret = 0, times, count, pending = 0;
  8517. double start;
  8518. const char**desc = bench_desc_words[lng_index];
  8519. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8520. byte ss[KYBER_SS_SZ];
  8521. word32 ctSz;
  8522. DECLARE_MULTI_VALUE_STATS_VARS()
  8523. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8524. if (ret != 0) {
  8525. return;
  8526. }
  8527. /* KYBER Encapsulate */
  8528. bench_stats_start(&count, &start);
  8529. do {
  8530. /* while free pending slots in queue, submit ops */
  8531. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8532. #ifdef KYBER_NONDETERMINISTIC
  8533. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8534. #else
  8535. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8536. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8537. sizeof(rand));
  8538. #endif
  8539. if (ret != 0)
  8540. goto exit_encap;
  8541. RECORD_MULTI_VALUE_STATS();
  8542. } /* for times */
  8543. count += times;
  8544. } while (bench_stats_check(start)
  8545. #ifdef MULTI_VALUE_STATISTICS
  8546. || runs < minimum_runs
  8547. #endif
  8548. );
  8549. exit_encap:
  8550. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8551. #ifdef MULTI_VALUE_STATISTICS
  8552. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8553. #endif
  8554. RESET_MULTI_VALUE_STATS_VARS();
  8555. /* KYBER Decapsulate */
  8556. bench_stats_start(&count, &start);
  8557. do {
  8558. /* while free pending slots in queue, submit ops */
  8559. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8560. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8561. if (ret != 0)
  8562. goto exit_decap;
  8563. RECORD_MULTI_VALUE_STATS();
  8564. } /* for times */
  8565. count += times;
  8566. } while (bench_stats_check(start)
  8567. #ifdef MULTI_VALUE_STATISTICS
  8568. || runs < minimum_runs
  8569. #endif
  8570. );
  8571. exit_decap:
  8572. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8573. #ifdef MULTI_VALUE_STATISTICS
  8574. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8575. #endif
  8576. }
  8577. void bench_kyber(int type)
  8578. {
  8579. KyberKey key;
  8580. const char* name = NULL;
  8581. int keySize = 0;
  8582. switch (type) {
  8583. #ifndef WOLFSSL_NO_ML_KEM
  8584. #ifdef WOLFSSL_WC_ML_KEM_512
  8585. case WC_ML_KEM_512:
  8586. name = "ML-KEM 512 ";
  8587. keySize = 128;
  8588. break;
  8589. #endif
  8590. #ifdef WOLFSSL_WC_ML_KEM_768
  8591. case WC_ML_KEM_768:
  8592. name = "ML-KEM 768 ";
  8593. keySize = 192;
  8594. break;
  8595. #endif
  8596. #ifdef WOLFSSL_WC_ML_KEM_1024
  8597. case WC_ML_KEM_1024:
  8598. name = "ML-KEM 1024 ";
  8599. keySize = 256;
  8600. break;
  8601. #endif
  8602. #endif
  8603. #ifdef WOLFSSL_KYBER_ORIGINAL
  8604. #ifdef WOLFSSL_KYBER512
  8605. case KYBER512:
  8606. name = "KYBER512 ";
  8607. keySize = 128;
  8608. break;
  8609. #endif
  8610. #ifdef WOLFSSL_KYBER768
  8611. case KYBER768:
  8612. name = "KYBER768 ";
  8613. keySize = 192;
  8614. break;
  8615. #endif
  8616. #ifdef WOLFSSL_KYBER1024
  8617. case KYBER1024:
  8618. name = "KYBER1024";
  8619. keySize = 256;
  8620. break;
  8621. #endif
  8622. #endif
  8623. }
  8624. bench_kyber_keygen(type, name, keySize, &key);
  8625. bench_kyber_encap(name, keySize, &key);
  8626. wc_KyberKey_Free(&key);
  8627. }
  8628. #endif
  8629. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8630. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8631. /* WC_LMS_PARM_L2_H10_W2
  8632. * signature length: 9300 */
  8633. static const byte lms_priv_L2_H10_W2[64] =
  8634. {
  8635. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8636. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8637. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8638. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8639. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8640. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8641. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8642. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8643. };
  8644. static const byte lms_pub_L2_H10_W2[60] =
  8645. {
  8646. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8647. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8648. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8649. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8650. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8651. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8652. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8653. 0x7F,0xC8,0x91,0xB0
  8654. };
  8655. /* WC_LMS_PARM_L2_H10_W4
  8656. * signature length: 5076 */
  8657. static const byte lms_priv_L2_H10_W4[64] =
  8658. {
  8659. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8660. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8661. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8662. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8663. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8664. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8665. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8666. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8667. };
  8668. static const byte lms_pub_L2_H10_W4[60] =
  8669. {
  8670. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8671. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8672. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8673. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8674. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8675. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8676. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8677. 0x6B,0x9A,0xD3,0x14
  8678. };
  8679. /* WC_LMS_PARM_L3_H5_W4
  8680. * signature length: 7160 */
  8681. static const byte lms_priv_L3_H5_W4[64] =
  8682. {
  8683. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8684. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8685. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8686. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8687. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8688. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8689. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8690. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8691. };
  8692. static const byte lms_pub_L3_H5_W4[60] =
  8693. {
  8694. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8695. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8696. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8697. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8698. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8699. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8700. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8701. 0xAB,0x4B,0x51,0x39
  8702. };
  8703. /* WC_LMS_PARM_L3_H5_W8
  8704. * signature length: 3992 */
  8705. static const byte lms_priv_L3_H5_W8[64] =
  8706. {
  8707. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8708. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8709. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8710. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8711. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8712. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8713. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8714. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8715. };
  8716. static const byte lms_pub_L3_H5_W8[60] =
  8717. {
  8718. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8719. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8720. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8721. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8722. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8723. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8724. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8725. 0x83,0xAB,0x43,0xAF
  8726. };
  8727. /* WC_LMS_PARM_L3_H10_W4
  8728. * signature length: 7640 */
  8729. static const byte lms_priv_L3_H10_W4[64] =
  8730. {
  8731. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8732. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8733. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8734. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8735. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8736. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8737. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8738. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8739. };
  8740. static const byte lms_pub_L3_H10_W4[60] =
  8741. {
  8742. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8743. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8744. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8745. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8746. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8747. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8748. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8749. 0x8D,0x78,0xD5,0xA8
  8750. };
  8751. /* WC_LMS_PARM_L4_H5_W8
  8752. * signature length: 5340 */
  8753. static const byte lms_priv_L4_H5_W8[64] =
  8754. {
  8755. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8756. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8757. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8758. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8759. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8760. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8761. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8762. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8763. };
  8764. static const byte lms_pub_L4_H5_W8[60] =
  8765. {
  8766. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8767. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8768. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8769. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8770. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8771. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8772. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8773. 0x74,0x24,0x12,0xC8
  8774. };
  8775. #endif
  8776. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8777. {
  8778. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8779. * BE USED FOR TESTING PURPOSES! Production applications should
  8780. * write only to non-volatile storage. */
  8781. XMEMCPY(context, priv, privSz);
  8782. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8783. }
  8784. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8785. {
  8786. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8787. * BE USED FOR TESTING PURPOSES! */
  8788. XMEMCPY(priv, context, privSz);
  8789. return WC_LMS_RC_READ_TO_MEMORY;
  8790. }
  8791. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8792. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8793. {
  8794. WC_RNG rng;
  8795. LmsKey key;
  8796. int ret;
  8797. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8798. int times = 0;
  8799. int count = 0;
  8800. double start = 0.0F;
  8801. int levels;
  8802. int height;
  8803. int winternitz;
  8804. const char* str = wc_LmsKey_ParmToStr(parm);
  8805. DECLARE_MULTI_VALUE_STATS_VARS()
  8806. #ifndef HAVE_FIPS
  8807. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8808. #else
  8809. ret = wc_InitRng(&rng);
  8810. #endif
  8811. if (ret != 0) {
  8812. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8813. return;
  8814. }
  8815. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8816. if (ret) {
  8817. printf("wc_LmsKey_Init failed: %d\n", ret);
  8818. wc_FreeRng(&rng);
  8819. return;
  8820. }
  8821. count = 0;
  8822. bench_stats_start(&count, &start);
  8823. do {
  8824. /* LMS is stateful. Async queuing not practical. */
  8825. for (times = 0; times < 1; ++times) {
  8826. wc_LmsKey_Free(&key);
  8827. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8828. if (ret) {
  8829. printf("wc_LmsKey_Init failed: %d\n", ret);
  8830. goto exit_lms_keygen;
  8831. }
  8832. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8833. if (ret) {
  8834. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8835. goto exit_lms_keygen;
  8836. }
  8837. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8838. if (ret) {
  8839. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8840. ret);
  8841. goto exit_lms_keygen;
  8842. }
  8843. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8844. if (ret) {
  8845. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8846. ret);
  8847. goto exit_lms_keygen;
  8848. }
  8849. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8850. if (ret) {
  8851. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8852. goto exit_lms_keygen;
  8853. }
  8854. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8855. if (ret) {
  8856. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8857. ret);
  8858. goto exit_lms_keygen;
  8859. }
  8860. ret = wc_LmsKey_MakeKey(&key, &rng);
  8861. if (ret) {
  8862. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8863. goto exit_lms_keygen;
  8864. }
  8865. RECORD_MULTI_VALUE_STATS();
  8866. }
  8867. count += times;
  8868. } while (bench_stats_check(start)
  8869. #ifdef MULTI_VALUE_STATISTICS
  8870. || runs < minimum_runs
  8871. #endif
  8872. );
  8873. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8874. count, start, ret);
  8875. #ifdef MULTI_VALUE_STATISTICS
  8876. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8877. #endif
  8878. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8879. if (ret) {
  8880. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8881. }
  8882. exit_lms_keygen:
  8883. wc_LmsKey_Free(&key);
  8884. wc_FreeRng(&rng);
  8885. }
  8886. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8887. {
  8888. LmsKey key;
  8889. int ret = 0;
  8890. const char * msg = TEST_STRING;
  8891. word32 msgSz = TEST_STRING_SZ;
  8892. byte * sig = NULL;
  8893. word32 sigSz = 0;
  8894. word32 privLen = 0;
  8895. int loaded = 0;
  8896. int times = 0;
  8897. int count = 0;
  8898. double start = 0.0F;
  8899. const char * str = wc_LmsKey_ParmToStr(parm);
  8900. DECLARE_MULTI_VALUE_STATS_VARS()
  8901. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8902. if (ret) {
  8903. printf("wc_LmsKey_Init failed: %d\n", ret);
  8904. goto exit_lms_sign_verify;
  8905. }
  8906. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8907. if (ret) {
  8908. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8909. goto exit_lms_sign_verify;
  8910. }
  8911. switch (parm) {
  8912. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8913. case WC_LMS_PARM_L2_H10_W2:
  8914. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8915. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8916. break;
  8917. case WC_LMS_PARM_L2_H10_W4:
  8918. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8919. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8920. break;
  8921. case WC_LMS_PARM_L3_H5_W4:
  8922. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8923. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8924. break;
  8925. case WC_LMS_PARM_L3_H5_W8:
  8926. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8927. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8928. break;
  8929. case WC_LMS_PARM_L3_H10_W4:
  8930. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8931. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8932. break;
  8933. case WC_LMS_PARM_L4_H5_W8:
  8934. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8935. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8936. break;
  8937. case WC_LMS_PARM_NONE:
  8938. case WC_LMS_PARM_L1_H15_W2:
  8939. case WC_LMS_PARM_L1_H15_W4:
  8940. case WC_LMS_PARM_L2_H10_W8:
  8941. case WC_LMS_PARM_L3_H5_W2:
  8942. case WC_LMS_PARM_L1_H5_W1:
  8943. case WC_LMS_PARM_L1_H5_W2:
  8944. case WC_LMS_PARM_L1_H5_W4:
  8945. case WC_LMS_PARM_L1_H5_W8:
  8946. case WC_LMS_PARM_L1_H10_W2:
  8947. case WC_LMS_PARM_L1_H10_W4:
  8948. case WC_LMS_PARM_L1_H10_W8:
  8949. case WC_LMS_PARM_L1_H15_W8:
  8950. case WC_LMS_PARM_L1_H20_W2:
  8951. case WC_LMS_PARM_L1_H20_W4:
  8952. case WC_LMS_PARM_L1_H20_W8:
  8953. case WC_LMS_PARM_L2_H5_W2:
  8954. case WC_LMS_PARM_L2_H5_W4:
  8955. case WC_LMS_PARM_L2_H5_W8:
  8956. case WC_LMS_PARM_L2_H15_W2:
  8957. case WC_LMS_PARM_L2_H15_W4:
  8958. case WC_LMS_PARM_L2_H15_W8:
  8959. case WC_LMS_PARM_L2_H20_W2:
  8960. case WC_LMS_PARM_L2_H20_W4:
  8961. case WC_LMS_PARM_L2_H20_W8:
  8962. case WC_LMS_PARM_L3_H10_W8:
  8963. case WC_LMS_PARM_L4_H5_W2:
  8964. case WC_LMS_PARM_L4_H5_W4:
  8965. case WC_LMS_PARM_L4_H10_W4:
  8966. case WC_LMS_PARM_L4_H10_W8:
  8967. #endif
  8968. #ifdef WOLFSSL_LMS_SHA256_192
  8969. case WC_LMS_PARM_SHA256_192_L1_H5_W1:
  8970. case WC_LMS_PARM_SHA256_192_L1_H5_W2:
  8971. case WC_LMS_PARM_SHA256_192_L1_H5_W4:
  8972. case WC_LMS_PARM_SHA256_192_L1_H5_W8:
  8973. case WC_LMS_PARM_SHA256_192_L1_H10_W2:
  8974. case WC_LMS_PARM_SHA256_192_L1_H10_W4:
  8975. case WC_LMS_PARM_SHA256_192_L1_H10_W8:
  8976. case WC_LMS_PARM_SHA256_192_L1_H15_W2:
  8977. case WC_LMS_PARM_SHA256_192_L1_H15_W4:
  8978. case WC_LMS_PARM_SHA256_192_L2_H10_W2:
  8979. case WC_LMS_PARM_SHA256_192_L2_H10_W4:
  8980. case WC_LMS_PARM_SHA256_192_L2_H10_W8:
  8981. case WC_LMS_PARM_SHA256_192_L3_H5_W2:
  8982. case WC_LMS_PARM_SHA256_192_L3_H5_W4:
  8983. case WC_LMS_PARM_SHA256_192_L3_H5_W8:
  8984. case WC_LMS_PARM_SHA256_192_L3_H10_W4:
  8985. case WC_LMS_PARM_SHA256_192_L4_H5_W8:
  8986. #endif
  8987. default:
  8988. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8989. break;
  8990. }
  8991. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8992. if (ret) {
  8993. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8994. goto exit_lms_sign_verify;
  8995. }
  8996. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8997. if (ret) {
  8998. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8999. goto exit_lms_sign_verify;
  9000. }
  9001. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  9002. if (ret) {
  9003. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  9004. goto exit_lms_sign_verify;
  9005. }
  9006. /* Even with saved priv/pub keys, we must still reload the private
  9007. * key before using it. Reloading the private key is the bottleneck
  9008. * for larger heights. Only print load time in debug builds. */
  9009. count = 0;
  9010. bench_stats_start(&count, &start);
  9011. #ifndef WOLFSSL_WC_LMS_SMALL
  9012. do {
  9013. #ifdef WOLFSSL_WC_LMS
  9014. key.priv.inited = 0;
  9015. key.state = WC_LMS_STATE_PARMSET;
  9016. #endif
  9017. ret = wc_LmsKey_Reload(&key);
  9018. if (ret) {
  9019. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9020. goto exit_lms_sign_verify;
  9021. }
  9022. RECORD_MULTI_VALUE_STATS();
  9023. count++;
  9024. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9025. if (ret) {
  9026. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9027. goto exit_lms_sign_verify;
  9028. }
  9029. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9030. if (ret) {
  9031. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9032. goto exit_lms_sign_verify;
  9033. }
  9034. #ifdef HAVE_LIBLMS
  9035. break;
  9036. #endif
  9037. } while (bench_stats_check(start)
  9038. #ifdef MULTI_VALUE_STATISTICS
  9039. || runs < minimum_runs
  9040. #endif
  9041. );
  9042. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  9043. count, start, ret);
  9044. #ifdef MULTI_VALUE_STATISTICS
  9045. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9046. #endif
  9047. RESET_MULTI_VALUE_STATS_VARS();
  9048. #else
  9049. ret = wc_LmsKey_Reload(&key);
  9050. if (ret) {
  9051. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9052. goto exit_lms_sign_verify;
  9053. }
  9054. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9055. if (ret) {
  9056. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9057. goto exit_lms_sign_verify;
  9058. }
  9059. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9060. if (ret) {
  9061. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9062. goto exit_lms_sign_verify;
  9063. }
  9064. #endif
  9065. loaded = 1;
  9066. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9067. if (sig == NULL) {
  9068. printf("bench_lms_sign_verify malloc failed\n");
  9069. goto exit_lms_sign_verify;
  9070. }
  9071. count = 0;
  9072. bench_stats_start(&count, &start);
  9073. do {
  9074. /* LMS is stateful. Async queuing not practical. */
  9075. #ifndef WOLFSSL_WC_LMS_SMALL
  9076. for (times = 0; times < ntimes; ++times)
  9077. #else
  9078. for (times = 0; times < 1; ++times)
  9079. #endif
  9080. {
  9081. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9082. if (ret) {
  9083. printf("wc_LmsKey_Sign failed: %d\n", ret);
  9084. goto exit_lms_sign_verify;
  9085. }
  9086. RECORD_MULTI_VALUE_STATS();
  9087. if (!wc_LmsKey_SigsLeft(&key)) {
  9088. break;
  9089. }
  9090. }
  9091. count += times;
  9092. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9093. #ifdef MULTI_VALUE_STATISTICS
  9094. || runs < minimum_runs
  9095. #endif
  9096. ));
  9097. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9098. count, start, ret);
  9099. #ifdef MULTI_VALUE_STATISTICS
  9100. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9101. #endif
  9102. RESET_MULTI_VALUE_STATS_VARS();
  9103. count = 0;
  9104. bench_stats_start(&count, &start);
  9105. do {
  9106. /* LMS is stateful. Async queuing not practical. */
  9107. for (times = 0; times < ntimes; ++times) {
  9108. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9109. if (ret) {
  9110. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9111. goto exit_lms_sign_verify;
  9112. }
  9113. RECORD_MULTI_VALUE_STATS();
  9114. }
  9115. count += times;
  9116. } while (bench_stats_check(start)
  9117. #ifdef MULTI_VALUE_STATISTICS
  9118. || runs < minimum_runs
  9119. #endif
  9120. );
  9121. exit_lms_sign_verify:
  9122. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9123. count, start, ret);
  9124. #ifdef MULTI_VALUE_STATISTICS
  9125. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9126. #endif
  9127. if (loaded) {
  9128. wc_LmsKey_Free(&key);
  9129. }
  9130. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9131. return;
  9132. }
  9133. void bench_lms(void)
  9134. {
  9135. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9136. #ifndef WOLFSSL_NO_LMS_SHA256_256
  9137. #ifdef BENCH_LMS_SLOW_KEYGEN
  9138. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9139. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9140. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9141. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9142. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9143. #undef LMS_PARAMS_BENCHED
  9144. #define LMS_PARAMS_BENCHED
  9145. #endif
  9146. #endif
  9147. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9148. (LMS_MAX_HEIGHT >= 10))
  9149. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9150. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9151. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9152. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9153. #undef LMS_PARAMS_BENCHED
  9154. #define LMS_PARAMS_BENCHED
  9155. #ifdef BENCH_LMS_SLOW_KEYGEN
  9156. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9157. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9158. #endif
  9159. #endif
  9160. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9161. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9162. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9163. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9164. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9165. #undef LMS_PARAMS_BENCHED
  9166. #define LMS_PARAMS_BENCHED
  9167. #endif
  9168. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9169. (LMS_MAX_HEIGHT >= 10))
  9170. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9171. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9172. #endif
  9173. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9174. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9175. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9176. #endif
  9177. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9178. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9179. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9180. #endif
  9181. #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
  9182. #ifdef WOLFSSL_LMS_SHA256_192
  9183. #ifdef BENCH_LMS_SLOW_KEYGEN
  9184. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9185. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9186. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9187. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9188. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9189. #undef LMS_PARAMS_BENCHED
  9190. #define LMS_PARAMS_BENCHED
  9191. #endif
  9192. #endif
  9193. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9194. (LMS_MAX_HEIGHT >= 10))
  9195. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9196. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9197. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9198. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9199. #undef LMS_PARAMS_BENCHED
  9200. #define LMS_PARAMS_BENCHED
  9201. #ifdef BENCH_LMS_SLOW_KEYGEN
  9202. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9203. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9204. #endif
  9205. #endif
  9206. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9207. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9208. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9209. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9210. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9211. #undef LMS_PARAMS_BENCHED
  9212. #define LMS_PARAMS_BENCHED
  9213. #endif
  9214. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9215. (LMS_MAX_HEIGHT >= 10))
  9216. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9217. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9218. #endif
  9219. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9220. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9221. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9222. #endif
  9223. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9224. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9225. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9226. #endif
  9227. #endif /* WOLFSSL_LMS_SHA256_192 */
  9228. return;
  9229. }
  9230. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9231. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9232. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9233. void *context)
  9234. {
  9235. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9236. * BE USED FOR TESTING PURPOSES! Production applications should
  9237. * write only to non-volatile storage. */
  9238. XMEMCPY(context, priv, privSz);
  9239. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9240. }
  9241. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9242. void *context)
  9243. {
  9244. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9245. * BE USED FOR TESTING PURPOSES! */
  9246. XMEMCPY(priv, context, privSz);
  9247. return WC_XMSS_RC_READ_TO_MEMORY;
  9248. }
  9249. static void bench_xmss_sign_verify(const char * params)
  9250. {
  9251. WC_RNG rng;
  9252. XmssKey key;
  9253. word32 pkSz = 0;
  9254. word32 skSz = 0;
  9255. int freeRng = 0;
  9256. int freeKey = 0;
  9257. unsigned char * sk = NULL;
  9258. const char * msg = "XMSS post quantum signature test";
  9259. word32 msgSz = (word32) XSTRLEN(msg);
  9260. int ret = 0;
  9261. byte * sig = NULL;
  9262. word32 sigSz = 0;
  9263. int times = 0;
  9264. int count = 0;
  9265. double start = 0.0F;
  9266. #ifndef HAVE_FIPS
  9267. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9268. #else
  9269. ret = wc_InitRng(&rng);
  9270. #endif
  9271. if (ret != 0) {
  9272. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9273. goto exit_xmss_sign_verify;
  9274. }
  9275. freeRng = 1;
  9276. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9277. if (ret != 0) {
  9278. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9279. goto exit_xmss_sign_verify;
  9280. }
  9281. ret = wc_XmssKey_SetParamStr(&key, params);
  9282. if (ret != 0) {
  9283. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9284. goto exit_xmss_sign_verify;
  9285. }
  9286. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9287. if (ret != 0) {
  9288. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9289. goto exit_xmss_sign_verify;
  9290. }
  9291. #ifndef WOLFSSL_WC_XMSS
  9292. if (pkSz != XMSS_SHA256_PUBLEN) {
  9293. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9294. XMSS_SHA256_PUBLEN);
  9295. goto exit_xmss_sign_verify;
  9296. }
  9297. #endif
  9298. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9299. if (ret != 0 || skSz <= 0) {
  9300. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9301. goto exit_xmss_sign_verify;
  9302. }
  9303. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9304. if (ret != 0 || sigSz <= 0) {
  9305. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9306. goto exit_xmss_sign_verify;
  9307. }
  9308. /* Allocate secret keys.*/
  9309. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9310. if (sk == NULL) {
  9311. fprintf(stderr, "error: allocate xmss sk failed\n");
  9312. goto exit_xmss_sign_verify;
  9313. }
  9314. /* Allocate signature array. */
  9315. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9316. if (sig == NULL) {
  9317. fprintf(stderr, "error: allocate xmss sig failed\n");
  9318. goto exit_xmss_sign_verify;
  9319. }
  9320. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9321. if (ret != 0) {
  9322. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9323. goto exit_xmss_sign_verify;
  9324. }
  9325. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9326. if (ret != 0) {
  9327. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9328. goto exit_xmss_sign_verify;
  9329. }
  9330. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9331. if (ret != 0) {
  9332. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9333. goto exit_xmss_sign_verify;
  9334. }
  9335. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9336. fprintf(stderr, "params: %s\n", params);
  9337. fprintf(stderr, "pkSz: %d\n", pkSz);
  9338. fprintf(stderr, "skSz: %d\n", skSz);
  9339. fprintf(stderr, "sigSz: %d\n", sigSz);
  9340. #endif
  9341. /* Making the private key is the bottleneck for larger heights. */
  9342. count = 0;
  9343. bench_stats_start(&count, &start);
  9344. ret = wc_XmssKey_MakeKey(&key, &rng);
  9345. if (ret != 0) {
  9346. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9347. goto exit_xmss_sign_verify;
  9348. }
  9349. /* Can only do one at a time - state changes after make key. */
  9350. count +=1;
  9351. bench_stats_check(start);
  9352. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9353. freeKey = 1;
  9354. count = 0;
  9355. bench_stats_start(&count, &start);
  9356. do {
  9357. /* XMSS is stateful. Async queuing not practical. */
  9358. #ifndef WOLFSSL_WC_XMSS_SMALL
  9359. for (times = 0; times < ntimes; ++times)
  9360. #else
  9361. for (times = 0; times < 1; ++times)
  9362. #endif
  9363. {
  9364. if (!wc_XmssKey_SigsLeft(&key))
  9365. break;
  9366. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9367. if (ret) {
  9368. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9369. goto exit_xmss_sign_verify;
  9370. }
  9371. }
  9372. count += times;
  9373. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9374. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9375. count = 0;
  9376. bench_stats_start(&count, &start);
  9377. do {
  9378. /* XMSS is stateful. Async queuing not practical. */
  9379. for (times = 0; times < ntimes; ++times) {
  9380. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9381. if (ret) {
  9382. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9383. goto exit_xmss_sign_verify;
  9384. }
  9385. }
  9386. count += times;
  9387. } while (bench_stats_check(start));
  9388. exit_xmss_sign_verify:
  9389. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9390. /* Cleanup everything. */
  9391. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9392. sig = NULL;
  9393. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9394. sk = NULL;
  9395. if (freeRng) {
  9396. wc_FreeRng(&rng);
  9397. }
  9398. if (freeKey) {
  9399. wc_XmssKey_Free(&key);
  9400. }
  9401. return;
  9402. }
  9403. void bench_xmss(int hash)
  9404. {
  9405. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9406. * sets.
  9407. *
  9408. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9409. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9410. * very slow, their signatures and private keys quite large,
  9411. * and xmss private keys are not portable across different
  9412. * XMSS/XMSS^MT implementations.
  9413. *
  9414. * The bottleneck in key generation is the height of the first
  9415. * level tree (or h/d).
  9416. *
  9417. * h is the total height of the hyper tree, and d the number of
  9418. * trees.
  9419. */
  9420. /* h/d h d */
  9421. #ifdef WC_XMSS_SHA256
  9422. if (hash == WC_HASH_TYPE_SHA256) {
  9423. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9424. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9425. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9426. #endif
  9427. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9428. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9429. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9430. #endif
  9431. #endif
  9432. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9433. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9434. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9435. #endif
  9436. #endif
  9437. #endif /* HASH_SIZE 256 */
  9438. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9439. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9440. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9441. #endif
  9442. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9443. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9444. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9445. #endif
  9446. #endif
  9447. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9448. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9449. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9450. #endif
  9451. #endif
  9452. #endif /* HASH_SIZE 192 */
  9453. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9454. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9455. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9456. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9457. #endif
  9458. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9459. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9460. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9461. #endif
  9462. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9463. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9464. #endif
  9465. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9466. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9467. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9468. #endif
  9469. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9470. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9471. #endif
  9472. #endif /* HASH_SIZE 256 */
  9473. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9474. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9475. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9476. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9477. #endif
  9478. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9479. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9480. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9481. #endif
  9482. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9483. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9484. #endif
  9485. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9486. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9487. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9488. #endif
  9489. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9490. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9491. #endif
  9492. #endif /* HASH_SIZE 192 */
  9493. }
  9494. #endif
  9495. #ifdef WC_XMSS_SHA512
  9496. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9497. if (hash == WC_HASH_TYPE_SHA512) {
  9498. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9499. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9500. #endif
  9501. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9502. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9503. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9504. #endif
  9505. #endif
  9506. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9507. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9508. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9509. #endif
  9510. #endif
  9511. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9512. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9513. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9514. #endif
  9515. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9516. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9517. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9518. #endif
  9519. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9520. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9521. #endif
  9522. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9523. #endif
  9524. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9525. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9526. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9527. #endif
  9528. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9529. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9530. #endif
  9531. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9532. #endif
  9533. }
  9534. #endif /* HASH_SIZE 512 */
  9535. #endif
  9536. #ifdef WC_XMSS_SHAKE128
  9537. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9538. if (hash == WC_HASH_TYPE_SHAKE128) {
  9539. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9540. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9541. #endif
  9542. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9543. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9544. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9545. #endif
  9546. #endif
  9547. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9548. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9549. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9550. #endif
  9551. #endif
  9552. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9553. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9554. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9555. #endif
  9556. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9557. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9558. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9559. #endif
  9560. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9561. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9562. #endif
  9563. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9564. #endif
  9565. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9566. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9567. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9568. #endif
  9569. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9570. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9571. #endif
  9572. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9573. #endif
  9574. }
  9575. #endif /* HASH_SIZE 256 */
  9576. #endif
  9577. #ifdef WC_XMSS_SHAKE256
  9578. if (hash == WC_HASH_TYPE_SHAKE256) {
  9579. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9580. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9581. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9582. #endif
  9583. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9584. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9585. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9586. #endif
  9587. #endif
  9588. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9589. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9590. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9591. #endif
  9592. #endif
  9593. #endif /* HASH_SIZE 512 */
  9594. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9595. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9596. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9597. #endif
  9598. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9599. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9600. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9601. #endif
  9602. #endif
  9603. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9604. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9605. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9606. #endif
  9607. #endif
  9608. #endif /* HASH_SIZE 256 */
  9609. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9610. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9611. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9612. #endif
  9613. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9614. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9615. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9616. #endif
  9617. #endif
  9618. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9619. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9620. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9621. #endif
  9622. #endif
  9623. #endif /* HASH_SIZE 192 */
  9624. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9625. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9626. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9627. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9628. #endif
  9629. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9630. #endif
  9631. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9632. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9633. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9634. #endif
  9635. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9636. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9637. #endif
  9638. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9639. #endif
  9640. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9641. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9642. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9643. #endif
  9644. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9645. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9646. #endif
  9647. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9648. #endif
  9649. #endif /* HASH_SIZE 512 */
  9650. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9651. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9652. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9653. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9654. #endif
  9655. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9656. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9657. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9658. #endif
  9659. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9660. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9661. #endif
  9662. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9663. #endif
  9664. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9665. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9666. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9667. #endif
  9668. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9669. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9670. #endif
  9671. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9672. #endif
  9673. #endif /* HASH_SIZE 256 */
  9674. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9675. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9676. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9677. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9678. #endif
  9679. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9680. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9681. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9682. #endif
  9683. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9684. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9685. #endif
  9686. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9687. #endif
  9688. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9689. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9690. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9691. #endif
  9692. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9693. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9694. #endif
  9695. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9696. #endif
  9697. #endif /* HASH_SIZE 192 */
  9698. }
  9699. #endif
  9700. return;
  9701. }
  9702. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9703. #ifdef HAVE_ECC
  9704. /* Maximum ECC name plus null terminator:
  9705. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9706. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9707. /* run all benchmarks on a curve */
  9708. void bench_ecc_curve(int curveId)
  9709. {
  9710. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9711. #ifndef NO_SW_BENCH
  9712. bench_eccMakeKey(0, curveId);
  9713. #endif
  9714. #if defined(BENCH_DEVID)
  9715. bench_eccMakeKey(1, curveId);
  9716. #endif
  9717. }
  9718. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9719. #ifndef NO_SW_BENCH
  9720. bench_ecc(0, curveId);
  9721. #endif
  9722. #if defined(BENCH_DEVID)
  9723. bench_ecc(1, curveId);
  9724. #endif
  9725. }
  9726. #ifdef HAVE_ECC_ENCRYPT
  9727. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9728. bench_eccEncrypt(curveId);
  9729. #endif
  9730. }
  9731. void bench_eccMakeKey(int useDeviceID, int curveId)
  9732. {
  9733. int ret = 0, i, times, count = 0, pending = 0;
  9734. int deviceID;
  9735. int keySize = 0;
  9736. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9737. sizeof(ecc_key), HEAP_HINT);
  9738. char name[BENCH_ECC_NAME_SZ];
  9739. double start = 0;
  9740. const char**desc = bench_desc_words[lng_index];
  9741. DECLARE_MULTI_VALUE_STATS_VARS()
  9742. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9743. sizeof(ecc_key), HEAP_HINT);
  9744. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9745. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9746. /* ECC Make Key */
  9747. bench_stats_start(&count, &start);
  9748. do {
  9749. /* while free pending slots in queue, submit ops */
  9750. for (times = 0; times < agreeTimes || pending > 0; ) {
  9751. bench_async_poll(&pending);
  9752. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9753. if (bench_async_check(&ret,
  9754. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9755. &times, agreeTimes, &pending)) {
  9756. wc_ecc_free(genKey[i]);
  9757. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9758. if (ret < 0) {
  9759. goto exit;
  9760. }
  9761. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9762. curveId);
  9763. if (!bench_async_handle(&ret,
  9764. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9765. &pending)) {
  9766. goto exit;
  9767. }
  9768. }
  9769. } /* for i */
  9770. RECORD_MULTI_VALUE_STATS();
  9771. } /* for times */
  9772. count += times;
  9773. } while (bench_stats_check(start)
  9774. #ifdef MULTI_VALUE_STATISTICS
  9775. || runs < minimum_runs
  9776. #endif
  9777. );
  9778. exit:
  9779. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9780. wc_ecc_get_name(curveId));
  9781. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9782. useDeviceID, count, start, ret);
  9783. #ifdef MULTI_VALUE_STATISTICS
  9784. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9785. #endif
  9786. /* cleanup */
  9787. if (WC_ARRAY_OK(genKey)) {
  9788. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9789. wc_ecc_free(genKey[i]);
  9790. }
  9791. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9792. }
  9793. }
  9794. void bench_ecc(int useDeviceID, int curveId)
  9795. {
  9796. int ret = 0, i, times, count, pending = 0;
  9797. int deviceID;
  9798. int keySize;
  9799. char name[BENCH_ECC_NAME_SZ];
  9800. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9801. sizeof(ecc_key), HEAP_HINT);
  9802. #ifdef HAVE_ECC_DHE
  9803. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9804. sizeof(ecc_key), HEAP_HINT);
  9805. #endif
  9806. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9807. #ifdef HAVE_ECC_VERIFY
  9808. int verify[BENCH_MAX_PENDING];
  9809. #endif
  9810. #endif
  9811. word32 x[BENCH_MAX_PENDING];
  9812. double start = 0;
  9813. const char**desc = bench_desc_words[lng_index];
  9814. DECLARE_MULTI_VALUE_STATS_VARS()
  9815. #ifdef HAVE_ECC_DHE
  9816. WC_DECLARE_ARRAY(shared, byte,
  9817. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9818. #endif
  9819. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9820. WC_DECLARE_ARRAY(sig, byte,
  9821. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9822. WC_DECLARE_ARRAY(digest, byte,
  9823. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9824. #endif
  9825. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9826. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9827. XMEMSET(sig, 0, sizeof(sig));
  9828. XMEMSET(digest, 0, sizeof(digest));
  9829. #endif
  9830. #ifdef HAVE_ECC_DHE
  9831. XMEMSET(shared, 0, sizeof(shared));
  9832. #endif
  9833. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9834. sizeof(ecc_key), HEAP_HINT);
  9835. #ifdef HAVE_ECC_DHE
  9836. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9837. sizeof(ecc_key), HEAP_HINT);
  9838. WC_ALLOC_ARRAY(shared, byte,
  9839. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9840. #endif
  9841. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9842. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9843. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9844. #endif
  9845. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9846. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9847. /* init keys */
  9848. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9849. /* setup an context for each key */
  9850. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9851. goto exit;
  9852. }
  9853. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9854. #ifdef WOLFSSL_ASYNC_CRYPT
  9855. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9856. #endif
  9857. if (ret < 0) {
  9858. goto exit;
  9859. }
  9860. #ifdef HAVE_ECC_DHE
  9861. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9862. goto exit;
  9863. }
  9864. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9865. curveId)) > 0) {
  9866. goto exit;
  9867. }
  9868. #endif
  9869. }
  9870. #ifdef HAVE_ECC_DHE
  9871. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9872. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9873. !defined(HAVE_SELFTEST)
  9874. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9875. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9876. }
  9877. #endif
  9878. /* ECC Shared Secret */
  9879. bench_stats_start(&count, &start);
  9880. PRIVATE_KEY_UNLOCK();
  9881. do {
  9882. for (times = 0; times < agreeTimes || pending > 0; ) {
  9883. bench_async_poll(&pending);
  9884. /* while free pending slots in queue, submit ops */
  9885. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9886. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9887. &times, agreeTimes, &pending)) {
  9888. x[i] = (word32)keySize;
  9889. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9890. shared[i], &x[i]);
  9891. if (!bench_async_handle(&ret,
  9892. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9893. &pending)) {
  9894. goto exit_ecdhe;
  9895. }
  9896. }
  9897. } /* for i */
  9898. RECORD_MULTI_VALUE_STATS();
  9899. } /* for times */
  9900. count += times;
  9901. } while (bench_stats_check(start)
  9902. #ifdef MULTI_VALUE_STATISTICS
  9903. || runs < minimum_runs
  9904. #endif
  9905. );
  9906. PRIVATE_KEY_UNLOCK();
  9907. exit_ecdhe:
  9908. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9909. wc_ecc_get_name(curveId));
  9910. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9911. useDeviceID, count, start, ret);
  9912. #ifdef MULTI_VALUE_STATISTICS
  9913. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9914. #endif
  9915. RESET_MULTI_VALUE_STATS_VARS();
  9916. if (ret < 0) {
  9917. goto exit;
  9918. }
  9919. #endif /* HAVE_ECC_DHE */
  9920. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9921. /* Init digest to sign */
  9922. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9923. for (count = 0; count < keySize; count++) {
  9924. digest[i][count] = (byte)count;
  9925. }
  9926. }
  9927. /* ECC Sign */
  9928. bench_stats_start(&count, &start);
  9929. do {
  9930. for (times = 0; times < agreeTimes || pending > 0; ) {
  9931. bench_async_poll(&pending);
  9932. /* while free pending slots in queue, submit ops */
  9933. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9934. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9935. &times, agreeTimes, &pending)) {
  9936. if (genKey[i]->state == 0) {
  9937. x[i] = ECC_MAX_SIG_SIZE;
  9938. }
  9939. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9940. &x[i], GLOBAL_RNG, genKey[i]);
  9941. if (!bench_async_handle(&ret,
  9942. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9943. &pending)) {
  9944. goto exit_ecdsa_sign;
  9945. }
  9946. } /* bench_async_check */
  9947. } /* for i */
  9948. RECORD_MULTI_VALUE_STATS();
  9949. } /* for times */
  9950. count += times;
  9951. } while (bench_stats_check(start)
  9952. #ifdef MULTI_VALUE_STATISTICS
  9953. || runs < minimum_runs
  9954. #endif
  9955. );
  9956. exit_ecdsa_sign:
  9957. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9958. wc_ecc_get_name(curveId));
  9959. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9960. useDeviceID, count, start, ret);
  9961. #ifdef MULTI_VALUE_STATISTICS
  9962. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9963. #endif
  9964. RESET_MULTI_VALUE_STATS_VARS();
  9965. if (ret < 0) {
  9966. goto exit;
  9967. }
  9968. #ifdef HAVE_ECC_VERIFY
  9969. /* ECC Verify */
  9970. bench_stats_start(&count, &start);
  9971. do {
  9972. for (times = 0; times < agreeTimes || pending > 0; ) {
  9973. bench_async_poll(&pending);
  9974. /* while free pending slots in queue, submit ops */
  9975. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9976. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9977. &times, agreeTimes, &pending)) {
  9978. if (genKey[i]->state == 0) {
  9979. verify[i] = 0;
  9980. }
  9981. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9982. (word32)keySize, &verify[i],
  9983. genKey[i]);
  9984. if (!bench_async_handle(&ret,
  9985. BENCH_ASYNC_GET_DEV(genKey[i]),
  9986. 1, &times,
  9987. &pending)) {
  9988. goto exit_ecdsa_verify;
  9989. }
  9990. } /* if bench_async_check */
  9991. } /* for i */
  9992. RECORD_MULTI_VALUE_STATS();
  9993. } /* for times */
  9994. count += times;
  9995. } while (bench_stats_check(start)
  9996. #ifdef MULTI_VALUE_STATISTICS
  9997. || runs < minimum_runs
  9998. #endif
  9999. );
  10000. exit_ecdsa_verify:
  10001. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10002. wc_ecc_get_name(curveId));
  10003. bench_stats_asym_finish(name, keySize * 8, desc[5],
  10004. useDeviceID, count, start, ret);
  10005. #ifdef MULTI_VALUE_STATISTICS
  10006. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10007. #endif
  10008. #endif /* HAVE_ECC_VERIFY */
  10009. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10010. exit:
  10011. /* cleanup */
  10012. if (WC_ARRAY_OK(genKey)) {
  10013. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10014. wc_ecc_free(genKey[i]);
  10015. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10016. }
  10017. #ifdef HAVE_ECC_DHE
  10018. if (WC_ARRAY_OK(genKey2)) {
  10019. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10020. wc_ecc_free(genKey2[i]);
  10021. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10022. }
  10023. #endif
  10024. #ifdef HAVE_ECC_DHE
  10025. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10026. #endif
  10027. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10028. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10029. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10030. #endif
  10031. (void)useDeviceID;
  10032. (void)pending;
  10033. (void)x;
  10034. (void)count;
  10035. (void)times;
  10036. (void)desc;
  10037. (void)start;
  10038. (void)name;
  10039. }
  10040. #ifdef HAVE_ECC_ENCRYPT
  10041. void bench_eccEncrypt(int curveId)
  10042. {
  10043. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  10044. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  10045. WC_SHA256_DIGEST_SIZE + \
  10046. (MAX_ECC_BITS+3)/4 + 2)
  10047. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  10048. #ifdef WOLFSSL_SMALL_STACK
  10049. ecc_key *userA = NULL, *userB = NULL;
  10050. byte *msg = NULL;
  10051. byte *out = NULL;
  10052. #else
  10053. ecc_key userA[1], userB[1];
  10054. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  10055. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  10056. #endif
  10057. char name[BENCH_ECC_NAME_SZ];
  10058. int keySize;
  10059. word32 bench_plainSz = bench_size;
  10060. int ret, i, count;
  10061. double start;
  10062. const char**desc = bench_desc_words[lng_index];
  10063. DECLARE_MULTI_VALUE_STATS_VARS()
  10064. #ifdef WOLFSSL_SMALL_STACK
  10065. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  10066. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10067. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  10068. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10069. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  10070. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10071. out = (byte *)XMALLOC(outSz,
  10072. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10073. if ((! userA) || (! userB) || (! msg) || (! out)) {
  10074. printf("bench_eccEncrypt malloc failed\n");
  10075. goto exit;
  10076. }
  10077. #endif
  10078. keySize = wc_ecc_get_curve_size_from_id(curveId);
  10079. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  10080. if (ret != 0) {
  10081. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  10082. goto exit;
  10083. }
  10084. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  10085. if (ret != 0) {
  10086. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  10087. goto exit;
  10088. }
  10089. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10090. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10091. !defined(HAVE_SELFTEST)
  10092. ret = wc_ecc_set_rng(userA, &gRng);
  10093. if (ret != 0) {
  10094. goto exit;
  10095. }
  10096. ret = wc_ecc_set_rng(userB, &gRng);
  10097. if (ret != 0) {
  10098. goto exit;
  10099. }
  10100. #endif
  10101. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  10102. #ifdef WOLFSSL_ASYNC_CRYPT
  10103. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  10104. #endif
  10105. if (ret != 0)
  10106. goto exit;
  10107. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  10108. #ifdef WOLFSSL_ASYNC_CRYPT
  10109. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  10110. #endif
  10111. if (ret != 0)
  10112. goto exit;
  10113. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  10114. msg[i] = (byte)i;
  10115. }
  10116. bench_stats_start(&count, &start);
  10117. do {
  10118. for (i = 0; i < ntimes; i++) {
  10119. /* encrypt msg to B */
  10120. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  10121. out, &outSz, NULL);
  10122. if (ret != 0) {
  10123. printf("wc_ecc_encrypt failed! %d\n", ret);
  10124. goto exit_enc;
  10125. }
  10126. RECORD_MULTI_VALUE_STATS();
  10127. }
  10128. count += i;
  10129. } while (bench_stats_check(start)
  10130. #ifdef MULTI_VALUE_STATISTICS
  10131. || runs < minimum_runs
  10132. #endif
  10133. );
  10134. exit_enc:
  10135. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10136. wc_ecc_get_name(curveId));
  10137. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10138. #ifdef MULTI_VALUE_STATISTICS
  10139. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10140. #endif
  10141. RESET_MULTI_VALUE_STATS_VARS();
  10142. if (ret != 0)
  10143. goto exit;
  10144. bench_stats_start(&count, &start);
  10145. do {
  10146. for (i = 0; i < ntimes; i++) {
  10147. /* decrypt msg from A */
  10148. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10149. &bench_plainSz, NULL);
  10150. if (ret != 0) {
  10151. printf("wc_ecc_decrypt failed! %d\n", ret);
  10152. goto exit_dec;
  10153. }
  10154. RECORD_MULTI_VALUE_STATS();
  10155. }
  10156. count += i;
  10157. } while (bench_stats_check(start)
  10158. #ifdef MULTI_VALUE_STATISTICS
  10159. || runs < minimum_runs
  10160. #endif
  10161. );
  10162. exit_dec:
  10163. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10164. #ifdef MULTI_VALUE_STATISTICS
  10165. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10166. #endif
  10167. exit:
  10168. /* cleanup */
  10169. #ifdef WOLFSSL_SMALL_STACK
  10170. if (userA) {
  10171. wc_ecc_free(userA);
  10172. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10173. }
  10174. if (userB) {
  10175. wc_ecc_free(userB);
  10176. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10177. }
  10178. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10179. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10180. #else
  10181. wc_ecc_free(userB);
  10182. wc_ecc_free(userA);
  10183. #endif
  10184. }
  10185. #endif
  10186. #ifdef WOLFSSL_SM2
  10187. static void bench_sm2_MakeKey(int useDeviceID)
  10188. {
  10189. int ret = 0, i, times, count = 0, pending = 0;
  10190. int deviceID;
  10191. int keySize;
  10192. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10193. sizeof(ecc_key), HEAP_HINT);
  10194. char name[BENCH_ECC_NAME_SZ];
  10195. double start = 0;
  10196. const char**desc = bench_desc_words[lng_index];
  10197. DECLARE_MULTI_VALUE_STATS_VARS()
  10198. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10199. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10200. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10201. sizeof(ecc_key), HEAP_HINT);
  10202. /* ECC Make Key */
  10203. bench_stats_start(&count, &start);
  10204. do {
  10205. /* while free pending slots in queue, submit ops */
  10206. for (times = 0; times < agreeTimes || pending > 0; ) {
  10207. bench_async_poll(&pending);
  10208. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10209. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10210. &times, agreeTimes, &pending)) {
  10211. wc_ecc_free(genKey[i]);
  10212. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10213. if (ret < 0) {
  10214. goto exit;
  10215. }
  10216. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10217. WC_ECC_FLAG_NONE);
  10218. if (!bench_async_handle(&ret,
  10219. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10220. &pending)) {
  10221. goto exit;
  10222. }
  10223. }
  10224. } /* for i */
  10225. RECORD_MULTI_VALUE_STATS();
  10226. } /* for times */
  10227. count += times;
  10228. } while (bench_stats_check(start)
  10229. #ifdef MULTI_VALUE_STATISTICS
  10230. || runs < minimum_runs
  10231. #endif
  10232. );
  10233. exit:
  10234. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10235. wc_ecc_get_name(ECC_SM2P256V1));
  10236. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10237. start, ret);
  10238. #ifdef MULTI_VALUE_STATISTICS
  10239. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10240. #endif
  10241. /* cleanup */
  10242. if (WC_ARRAY_OK(genKey)) {
  10243. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10244. wc_ecc_free(genKey[i]);
  10245. }
  10246. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10247. }
  10248. }
  10249. void bench_sm2(int useDeviceID)
  10250. {
  10251. int ret = 0, i, times, count, pending = 0;
  10252. int deviceID;
  10253. int keySize;
  10254. char name[BENCH_ECC_NAME_SZ];
  10255. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10256. sizeof(ecc_key), HEAP_HINT);
  10257. #ifdef HAVE_ECC_DHE
  10258. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10259. sizeof(ecc_key), HEAP_HINT);
  10260. #endif
  10261. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10262. #ifdef HAVE_ECC_VERIFY
  10263. int verify[BENCH_MAX_PENDING];
  10264. #endif
  10265. #endif
  10266. word32 x[BENCH_MAX_PENDING];
  10267. double start = 0;
  10268. const char**desc = bench_desc_words[lng_index];
  10269. DECLARE_MULTI_VALUE_STATS_VARS()
  10270. #ifdef HAVE_ECC_DHE
  10271. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10272. #endif
  10273. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10274. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10275. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10276. #endif
  10277. #ifdef HAVE_ECC_DHE
  10278. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10279. #endif
  10280. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10281. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10282. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10283. #endif
  10284. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10285. bench_sm2_MakeKey(useDeviceID);
  10286. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10287. sizeof(ecc_key), HEAP_HINT);
  10288. #ifdef HAVE_ECC_DHE
  10289. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10290. sizeof(ecc_key), HEAP_HINT);
  10291. #endif
  10292. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10293. /* init keys */
  10294. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10295. /* setup an context for each key */
  10296. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10297. goto exit;
  10298. }
  10299. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10300. #ifdef WOLFSSL_ASYNC_CRYPT
  10301. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10302. #endif
  10303. if (ret < 0) {
  10304. goto exit;
  10305. }
  10306. #ifdef HAVE_ECC_DHE
  10307. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10308. goto exit;
  10309. }
  10310. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10311. WC_ECC_FLAG_NONE)) > 0) {
  10312. goto exit;
  10313. }
  10314. #endif
  10315. }
  10316. #ifdef HAVE_ECC_DHE
  10317. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10318. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10319. !defined(HAVE_SELFTEST)
  10320. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10321. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10322. }
  10323. #endif
  10324. /* ECC Shared Secret */
  10325. bench_stats_start(&count, &start);
  10326. PRIVATE_KEY_UNLOCK();
  10327. do {
  10328. for (times = 0; times < agreeTimes || pending > 0; ) {
  10329. bench_async_poll(&pending);
  10330. /* while free pending slots in queue, submit ops */
  10331. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10332. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10333. &times, agreeTimes, &pending)) {
  10334. x[i] = (word32)keySize;
  10335. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10336. shared[i], &x[i]);
  10337. if (!bench_async_handle(&ret,
  10338. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10339. &pending)) {
  10340. goto exit_ecdhe;
  10341. }
  10342. }
  10343. } /* for i */
  10344. RECORD_MULTI_VALUE_STATS();
  10345. } /* for times */
  10346. count += times;
  10347. } while (bench_stats_check(start)
  10348. #ifdef MULTI_VALUE_STATISTICS
  10349. || runs < minimum_runs
  10350. #endif
  10351. );
  10352. PRIVATE_KEY_UNLOCK();
  10353. exit_ecdhe:
  10354. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10355. wc_ecc_get_name(ECC_SM2P256V1));
  10356. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10357. start, ret);
  10358. #ifdef MULTI_VALUE_STATISTICS
  10359. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10360. #endif
  10361. if (ret < 0) {
  10362. goto exit;
  10363. }
  10364. #endif /* HAVE_ECC_DHE */
  10365. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10366. /* Init digest to sign */
  10367. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10368. for (count = 0; count < keySize; count++) {
  10369. digest[i][count] = (byte)count;
  10370. }
  10371. }
  10372. RESET_MULTI_VALUE_STATS_VARS();
  10373. /* ECC Sign */
  10374. bench_stats_start(&count, &start);
  10375. do {
  10376. for (times = 0; times < agreeTimes || pending > 0; ) {
  10377. bench_async_poll(&pending);
  10378. /* while free pending slots in queue, submit ops */
  10379. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10380. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10381. &times, agreeTimes, &pending)) {
  10382. if (genKey[i]->state == 0)
  10383. x[i] = ECC_MAX_SIG_SIZE;
  10384. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10385. sig[i], &x[i], &gRng, genKey[i]);
  10386. if (!bench_async_handle(&ret,
  10387. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10388. &pending)) {
  10389. goto exit_ecdsa_sign;
  10390. }
  10391. }
  10392. } /* for i */
  10393. RECORD_MULTI_VALUE_STATS();
  10394. } /* for times */
  10395. count += times;
  10396. } while (bench_stats_check(start)
  10397. #ifdef MULTI_VALUE_STATISTICS
  10398. || runs < minimum_runs
  10399. #endif
  10400. );
  10401. exit_ecdsa_sign:
  10402. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10403. wc_ecc_get_name(ECC_SM2P256V1));
  10404. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10405. start, ret);
  10406. #ifdef MULTI_VALUE_STATISTICS
  10407. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10408. #endif
  10409. if (ret < 0) {
  10410. goto exit;
  10411. }
  10412. #ifdef HAVE_ECC_VERIFY
  10413. /* ECC Verify */
  10414. bench_stats_start(&count, &start);
  10415. do {
  10416. for (times = 0; times < agreeTimes || pending > 0; ) {
  10417. bench_async_poll(&pending);
  10418. /* while free pending slots in queue, submit ops */
  10419. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10420. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10421. &times, agreeTimes, &pending)) {
  10422. if (genKey[i]->state == 0)
  10423. verify[i] = 0;
  10424. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10425. (word32)keySize, &verify[i], genKey[i]);
  10426. if (!bench_async_handle(&ret,
  10427. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10428. &pending)) {
  10429. goto exit_ecdsa_verify;
  10430. }
  10431. }
  10432. } /* for i */
  10433. RECORD_MULTI_VALUE_STATS();
  10434. } /* for times */
  10435. count += times;
  10436. } while (bench_stats_check(start)
  10437. #ifdef MULTI_VALUE_STATISTICS
  10438. || runs < minimum_runs
  10439. #endif
  10440. );
  10441. exit_ecdsa_verify:
  10442. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10443. wc_ecc_get_name(ECC_SM2P256V1));
  10444. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10445. start, ret);
  10446. #ifdef MULTI_VALUE_STATISTICS
  10447. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10448. #endif
  10449. #endif /* HAVE_ECC_VERIFY */
  10450. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10451. exit:
  10452. /* cleanup */
  10453. if (WC_ARRAY_OK(genKey)) {
  10454. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10455. wc_ecc_free(genKey[i]);
  10456. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10457. }
  10458. #ifdef HAVE_ECC_DHE
  10459. if (WC_ARRAY_OK(genKey2)) {
  10460. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10461. wc_ecc_free(genKey2[i]);
  10462. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10463. }
  10464. #endif
  10465. #ifdef HAVE_ECC_DHE
  10466. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10467. #endif
  10468. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10469. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10470. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10471. #endif
  10472. (void)useDeviceID;
  10473. (void)pending;
  10474. (void)x;
  10475. (void)count;
  10476. (void)times;
  10477. (void)desc;
  10478. (void)start;
  10479. (void)name;
  10480. }
  10481. #endif /* WOLFSSL_SM2 */
  10482. #endif /* HAVE_ECC */
  10483. #ifdef HAVE_CURVE25519
  10484. void bench_curve25519KeyGen(int useDeviceID)
  10485. {
  10486. curve25519_key genKey;
  10487. double start;
  10488. int ret = 0, i, count;
  10489. const char**desc = bench_desc_words[lng_index];
  10490. DECLARE_MULTI_VALUE_STATS_VARS()
  10491. /* Key Gen */
  10492. bench_stats_start(&count, &start);
  10493. do {
  10494. for (i = 0; i < genTimes; i++) {
  10495. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10496. useDeviceID ? devId : INVALID_DEVID);
  10497. if (ret != 0) {
  10498. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10499. break;
  10500. }
  10501. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10502. wc_curve25519_free(&genKey);
  10503. if (ret != 0) {
  10504. printf("wc_curve25519_make_key failed: %d\n", ret);
  10505. break;
  10506. }
  10507. RECORD_MULTI_VALUE_STATS();
  10508. }
  10509. count += i;
  10510. } while (bench_stats_check(start)
  10511. #ifdef MULTI_VALUE_STATISTICS
  10512. || runs < minimum_runs
  10513. #endif
  10514. );
  10515. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10516. ret);
  10517. #ifdef MULTI_VALUE_STATISTICS
  10518. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10519. #endif
  10520. }
  10521. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10522. void bench_curve25519KeyAgree(int useDeviceID)
  10523. {
  10524. curve25519_key genKey, genKey2;
  10525. double start;
  10526. int ret, i, count;
  10527. byte shared[32];
  10528. const char**desc = bench_desc_words[lng_index];
  10529. word32 x = 0;
  10530. DECLARE_MULTI_VALUE_STATS_VARS()
  10531. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10532. useDeviceID ? devId : INVALID_DEVID);
  10533. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10534. useDeviceID ? devId : INVALID_DEVID);
  10535. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10536. if (ret != 0) {
  10537. printf("curve25519_make_key failed\n");
  10538. return;
  10539. }
  10540. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10541. if (ret != 0) {
  10542. printf("curve25519_make_key failed: %d\n", ret);
  10543. wc_curve25519_free(&genKey);
  10544. return;
  10545. }
  10546. /* Shared secret */
  10547. bench_stats_start(&count, &start);
  10548. do {
  10549. for (i = 0; i < agreeTimes; i++) {
  10550. x = sizeof(shared);
  10551. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10552. if (ret != 0) {
  10553. printf("curve25519_shared_secret failed: %d\n", ret);
  10554. goto exit;
  10555. }
  10556. RECORD_MULTI_VALUE_STATS();
  10557. }
  10558. count += i;
  10559. } while (bench_stats_check(start)
  10560. #ifdef MULTI_VALUE_STATISTICS
  10561. || runs < minimum_runs
  10562. #endif
  10563. );
  10564. exit:
  10565. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10566. ret);
  10567. #ifdef MULTI_VALUE_STATISTICS
  10568. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10569. #endif
  10570. wc_curve25519_free(&genKey2);
  10571. wc_curve25519_free(&genKey);
  10572. }
  10573. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10574. #endif /* HAVE_CURVE25519 */
  10575. #ifdef HAVE_ED25519
  10576. void bench_ed25519KeyGen(void)
  10577. {
  10578. #ifdef HAVE_ED25519_MAKE_KEY
  10579. ed25519_key genKey;
  10580. double start;
  10581. int i, count;
  10582. const char**desc = bench_desc_words[lng_index];
  10583. DECLARE_MULTI_VALUE_STATS_VARS()
  10584. /* Key Gen */
  10585. bench_stats_start(&count, &start);
  10586. do {
  10587. for (i = 0; i < genTimes; i++) {
  10588. wc_ed25519_init(&genKey);
  10589. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10590. wc_ed25519_free(&genKey);
  10591. RECORD_MULTI_VALUE_STATS();
  10592. }
  10593. count += i;
  10594. } while (bench_stats_check(start)
  10595. #ifdef MULTI_VALUE_STATISTICS
  10596. || runs < minimum_runs
  10597. #endif
  10598. );
  10599. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10600. #ifdef MULTI_VALUE_STATISTICS
  10601. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10602. #endif
  10603. #endif /* HAVE_ED25519_MAKE_KEY */
  10604. }
  10605. void bench_ed25519KeySign(void)
  10606. {
  10607. #ifdef HAVE_ED25519_MAKE_KEY
  10608. int ret;
  10609. #endif
  10610. ed25519_key genKey;
  10611. #ifdef HAVE_ED25519_SIGN
  10612. double start;
  10613. int i, count;
  10614. byte sig[ED25519_SIG_SIZE];
  10615. byte msg[512];
  10616. word32 x = 0;
  10617. const char**desc = bench_desc_words[lng_index];
  10618. DECLARE_MULTI_VALUE_STATS_VARS()
  10619. #endif
  10620. wc_ed25519_init(&genKey);
  10621. #ifdef HAVE_ED25519_MAKE_KEY
  10622. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10623. if (ret != 0) {
  10624. printf("ed25519_make_key failed\n");
  10625. return;
  10626. }
  10627. #endif
  10628. #ifdef HAVE_ED25519_SIGN
  10629. /* make dummy msg */
  10630. for (i = 0; i < (int)sizeof(msg); i++)
  10631. msg[i] = (byte)i;
  10632. bench_stats_start(&count, &start);
  10633. do {
  10634. for (i = 0; i < agreeTimes; i++) {
  10635. x = sizeof(sig);
  10636. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10637. if (ret != 0) {
  10638. printf("ed25519_sign_msg failed\n");
  10639. goto exit_ed_sign;
  10640. }
  10641. RECORD_MULTI_VALUE_STATS();
  10642. }
  10643. count += i;
  10644. } while (bench_stats_check(start)
  10645. #ifdef MULTI_VALUE_STATISTICS
  10646. || runs < minimum_runs
  10647. #endif
  10648. );
  10649. exit_ed_sign:
  10650. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10651. #ifdef MULTI_VALUE_STATISTICS
  10652. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10653. #endif
  10654. RESET_MULTI_VALUE_STATS_VARS();
  10655. #ifdef HAVE_ED25519_VERIFY
  10656. bench_stats_start(&count, &start);
  10657. do {
  10658. for (i = 0; i < agreeTimes; i++) {
  10659. int verify = 0;
  10660. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10661. &genKey);
  10662. if (ret != 0 || verify != 1) {
  10663. printf("ed25519_verify_msg failed\n");
  10664. goto exit_ed_verify;
  10665. }
  10666. RECORD_MULTI_VALUE_STATS();
  10667. }
  10668. count += i;
  10669. } while (bench_stats_check(start)
  10670. #ifdef MULTI_VALUE_STATISTICS
  10671. || runs < minimum_runs
  10672. #endif
  10673. );
  10674. exit_ed_verify:
  10675. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10676. #ifdef MULTI_VALUE_STATISTICS
  10677. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10678. #endif
  10679. #endif /* HAVE_ED25519_VERIFY */
  10680. #endif /* HAVE_ED25519_SIGN */
  10681. wc_ed25519_free(&genKey);
  10682. }
  10683. #endif /* HAVE_ED25519 */
  10684. #ifdef HAVE_CURVE448
  10685. void bench_curve448KeyGen(void)
  10686. {
  10687. curve448_key genKey;
  10688. double start;
  10689. int ret = 0, i, count;
  10690. const char**desc = bench_desc_words[lng_index];
  10691. DECLARE_MULTI_VALUE_STATS_VARS()
  10692. /* Key Gen */
  10693. bench_stats_start(&count, &start);
  10694. do {
  10695. for (i = 0; i < genTimes; i++) {
  10696. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10697. wc_curve448_free(&genKey);
  10698. if (ret != 0) {
  10699. printf("wc_curve448_make_key failed: %d\n", ret);
  10700. break;
  10701. }
  10702. RECORD_MULTI_VALUE_STATS();
  10703. }
  10704. count += i;
  10705. } while (bench_stats_check(start)
  10706. #ifdef MULTI_VALUE_STATISTICS
  10707. || runs < minimum_runs
  10708. #endif
  10709. );
  10710. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10711. #ifdef MULTI_VALUE_STATISTICS
  10712. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10713. #endif
  10714. }
  10715. #ifdef HAVE_CURVE448_SHARED_SECRET
  10716. void bench_curve448KeyAgree(void)
  10717. {
  10718. curve448_key genKey, genKey2;
  10719. double start;
  10720. int ret, i, count;
  10721. byte shared[56];
  10722. const char**desc = bench_desc_words[lng_index];
  10723. word32 x = 0;
  10724. DECLARE_MULTI_VALUE_STATS_VARS()
  10725. wc_curve448_init(&genKey);
  10726. wc_curve448_init(&genKey2);
  10727. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10728. if (ret != 0) {
  10729. printf("curve448_make_key failed\n");
  10730. return;
  10731. }
  10732. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10733. if (ret != 0) {
  10734. printf("curve448_make_key failed: %d\n", ret);
  10735. wc_curve448_free(&genKey);
  10736. return;
  10737. }
  10738. /* Shared secret */
  10739. bench_stats_start(&count, &start);
  10740. do {
  10741. for (i = 0; i < agreeTimes; i++) {
  10742. x = sizeof(shared);
  10743. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10744. if (ret != 0) {
  10745. printf("curve448_shared_secret failed: %d\n", ret);
  10746. goto exit;
  10747. }
  10748. RECORD_MULTI_VALUE_STATS();
  10749. }
  10750. count += i;
  10751. } while (bench_stats_check(start)
  10752. #ifdef MULTI_VALUE_STATISTICS
  10753. || runs < minimum_runs
  10754. #endif
  10755. );
  10756. exit:
  10757. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10758. #ifdef MULTI_VALUE_STATISTICS
  10759. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10760. #endif
  10761. wc_curve448_free(&genKey2);
  10762. wc_curve448_free(&genKey);
  10763. }
  10764. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10765. #endif /* HAVE_CURVE448 */
  10766. #ifdef HAVE_ED448
  10767. void bench_ed448KeyGen(void)
  10768. {
  10769. ed448_key genKey;
  10770. double start;
  10771. int i, count;
  10772. const char**desc = bench_desc_words[lng_index];
  10773. DECLARE_MULTI_VALUE_STATS_VARS()
  10774. /* Key Gen */
  10775. bench_stats_start(&count, &start);
  10776. do {
  10777. for (i = 0; i < genTimes; i++) {
  10778. wc_ed448_init(&genKey);
  10779. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10780. wc_ed448_free(&genKey);
  10781. RECORD_MULTI_VALUE_STATS();
  10782. }
  10783. count += i;
  10784. } while (bench_stats_check(start)
  10785. #ifdef MULTI_VALUE_STATISTICS
  10786. || runs < minimum_runs
  10787. #endif
  10788. );
  10789. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10790. #ifdef MULTI_VALUE_STATISTICS
  10791. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10792. #endif
  10793. }
  10794. void bench_ed448KeySign(void)
  10795. {
  10796. int ret;
  10797. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10798. #ifdef HAVE_ED448_SIGN
  10799. double start;
  10800. int i, count;
  10801. byte sig[ED448_SIG_SIZE];
  10802. byte msg[512];
  10803. word32 x = 0;
  10804. const char**desc = bench_desc_words[lng_index];
  10805. DECLARE_MULTI_VALUE_STATS_VARS()
  10806. #endif
  10807. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10808. wc_ed448_init(genKey);
  10809. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10810. if (ret != 0) {
  10811. printf("ed448_make_key failed\n");
  10812. goto exit;
  10813. }
  10814. #ifdef HAVE_ED448_SIGN
  10815. /* make dummy msg */
  10816. for (i = 0; i < (int)sizeof(msg); i++)
  10817. msg[i] = (byte)i;
  10818. bench_stats_start(&count, &start);
  10819. do {
  10820. for (i = 0; i < agreeTimes; i++) {
  10821. x = sizeof(sig);
  10822. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10823. NULL, 0);
  10824. if (ret != 0) {
  10825. printf("ed448_sign_msg failed\n");
  10826. goto exit;
  10827. }
  10828. RECORD_MULTI_VALUE_STATS();
  10829. }
  10830. count += i;
  10831. } while (bench_stats_check(start)
  10832. #ifdef MULTI_VALUE_STATISTICS
  10833. || runs < minimum_runs
  10834. #endif
  10835. );
  10836. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10837. #ifdef MULTI_VALUE_STATISTICS
  10838. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10839. #endif
  10840. RESET_MULTI_VALUE_STATS_VARS();
  10841. #ifdef HAVE_ED448_VERIFY
  10842. bench_stats_start(&count, &start);
  10843. do {
  10844. for (i = 0; i < agreeTimes; i++) {
  10845. int verify = 0;
  10846. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10847. genKey, NULL, 0);
  10848. if (ret != 0 || verify != 1) {
  10849. printf("ed448_verify_msg failed\n");
  10850. goto exit;
  10851. }
  10852. RECORD_MULTI_VALUE_STATS();
  10853. }
  10854. count += i;
  10855. } while (bench_stats_check(start)
  10856. #ifdef MULTI_VALUE_STATISTICS
  10857. || runs < minimum_runs
  10858. #endif
  10859. );
  10860. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10861. #ifdef MULTI_VALUE_STATISTICS
  10862. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10863. #endif
  10864. #endif /* HAVE_ED448_VERIFY */
  10865. #endif /* HAVE_ED448_SIGN */
  10866. exit:
  10867. wc_ed448_free(genKey);
  10868. WC_FREE_VAR(genKey, HEAP_HINT);
  10869. }
  10870. #endif /* HAVE_ED448 */
  10871. #ifdef WOLFCRYPT_HAVE_ECCSI
  10872. #ifdef WOLFCRYPT_ECCSI_KMS
  10873. void bench_eccsiKeyGen(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. int ret;
  10880. DECLARE_MULTI_VALUE_STATS_VARS()
  10881. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10882. /* Key Gen */
  10883. bench_stats_start(&count, &start);
  10884. do {
  10885. for (i = 0; i < genTimes; i++) {
  10886. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10887. ret = wc_MakeEccsiKey(genKey, &gRng);
  10888. wc_FreeEccsiKey(genKey);
  10889. if (ret != 0) {
  10890. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10891. goto exit;
  10892. }
  10893. RECORD_MULTI_VALUE_STATS();
  10894. }
  10895. count += i;
  10896. } while (bench_stats_check(start)
  10897. #ifdef MULTI_VALUE_STATISTICS
  10898. || runs < minimum_runs
  10899. #endif
  10900. );
  10901. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10902. #ifdef MULTI_VALUE_STATISTICS
  10903. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10904. #endif
  10905. exit:
  10906. WC_FREE_VAR(genKey, HEAP_HINT);
  10907. }
  10908. void bench_eccsiPairGen(void)
  10909. {
  10910. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10911. double start;
  10912. int i, count;
  10913. const char**desc = bench_desc_words[lng_index];
  10914. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10915. ecc_point* pvt;
  10916. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10917. int ret;
  10918. DECLARE_MULTI_VALUE_STATS_VARS()
  10919. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10920. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10921. (void)mp_init(ssk);
  10922. pvt = wc_ecc_new_point();
  10923. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10924. (void)wc_MakeEccsiKey(genKey, &gRng);
  10925. /* RSK Gen */
  10926. bench_stats_start(&count, &start);
  10927. do {
  10928. for (i = 0; i < genTimes; i++) {
  10929. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10930. sizeof(id), ssk, pvt);
  10931. if (ret != 0) {
  10932. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10933. goto exit;
  10934. }
  10935. RECORD_MULTI_VALUE_STATS();
  10936. }
  10937. count += i;
  10938. } while (bench_stats_check(start)
  10939. #ifdef MULTI_VALUE_STATISTICS
  10940. || runs < minimum_runs
  10941. #endif
  10942. );
  10943. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10944. #ifdef MULTI_VALUE_STATISTICS
  10945. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10946. #endif
  10947. wc_FreeEccsiKey(genKey);
  10948. wc_ecc_del_point(pvt);
  10949. mp_free(ssk);
  10950. exit:
  10951. WC_FREE_VAR(genKey, HEAP_HINT);
  10952. WC_FREE_VAR(ssk, HEAP_HINT);
  10953. }
  10954. #endif
  10955. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10956. void bench_eccsiValidate(void)
  10957. {
  10958. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10959. double start;
  10960. int i, count;
  10961. const char**desc = bench_desc_words[lng_index];
  10962. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10963. ecc_point* pvt;
  10964. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10965. int valid;
  10966. int ret;
  10967. DECLARE_MULTI_VALUE_STATS_VARS()
  10968. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10969. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10970. (void)mp_init(ssk);
  10971. pvt = wc_ecc_new_point();
  10972. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10973. (void)wc_MakeEccsiKey(genKey, &gRng);
  10974. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10975. ssk, pvt);
  10976. /* Validation of RSK */
  10977. bench_stats_start(&count, &start);
  10978. do {
  10979. for (i = 0; i < genTimes; i++) {
  10980. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10981. sizeof(id), ssk, pvt, &valid);
  10982. if (ret != 0 || !valid) {
  10983. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10984. valid);
  10985. goto exit;
  10986. }
  10987. RECORD_MULTI_VALUE_STATS();
  10988. }
  10989. count += i;
  10990. } while (bench_stats_check(start)
  10991. #ifdef MULTI_VALUE_STATISTICS
  10992. || runs < minimum_runs
  10993. #endif
  10994. );
  10995. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10996. #ifdef MULTI_VALUE_STATISTICS
  10997. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10998. #endif
  10999. wc_FreeEccsiKey(genKey);
  11000. wc_ecc_del_point(pvt);
  11001. mp_free(ssk);
  11002. exit:
  11003. WC_FREE_VAR(genKey, HEAP_HINT);
  11004. WC_FREE_VAR(ssk, HEAP_HINT);
  11005. }
  11006. void bench_eccsi(void)
  11007. {
  11008. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11009. double start;
  11010. int i, count;
  11011. const char**desc = bench_desc_words[lng_index];
  11012. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  11013. ecc_point* pvt;
  11014. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11015. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  11016. byte hash[WC_SHA256_DIGEST_SIZE];
  11017. byte hashSz = (byte)sizeof(hash);
  11018. byte sig[257];
  11019. word32 sigSz = sizeof(sig);
  11020. int ret;
  11021. int verified;
  11022. DECLARE_MULTI_VALUE_STATS_VARS()
  11023. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11024. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11025. (void)mp_init(ssk);
  11026. pvt = wc_ecc_new_point();
  11027. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11028. (void)wc_MakeEccsiKey(genKey, &gRng);
  11029. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11030. ssk, pvt);
  11031. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  11032. hash, &hashSz);
  11033. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  11034. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  11035. /* Encapsulate */
  11036. bench_stats_start(&count, &start);
  11037. do {
  11038. for (i = 0; i < genTimes; i++) {
  11039. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  11040. sizeof(msg), sig, &sigSz);
  11041. if (ret != 0) {
  11042. printf("wc_SignEccsiHash failed: %d\n", ret);
  11043. break;
  11044. }
  11045. RECORD_MULTI_VALUE_STATS();
  11046. }
  11047. count += i;
  11048. } while (bench_stats_check(start)
  11049. #ifdef MULTI_VALUE_STATISTICS
  11050. || runs < minimum_runs
  11051. #endif
  11052. );
  11053. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  11054. #ifdef MULTI_VALUE_STATISTICS
  11055. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11056. #endif
  11057. RESET_MULTI_VALUE_STATS_VARS();
  11058. /* Derive */
  11059. bench_stats_start(&count, &start);
  11060. do {
  11061. for (i = 0; i < genTimes; i++) {
  11062. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  11063. sizeof(msg), sig, sigSz, &verified);
  11064. if (ret != 0 || !verified) {
  11065. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  11066. verified);
  11067. goto exit;
  11068. }
  11069. RECORD_MULTI_VALUE_STATS();
  11070. }
  11071. count += i;
  11072. } while (bench_stats_check(start)
  11073. #ifdef MULTI_VALUE_STATISTICS
  11074. || runs < minimum_runs
  11075. #endif
  11076. );
  11077. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  11078. #ifdef MULTI_VALUE_STATISTICS
  11079. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11080. #endif
  11081. wc_FreeEccsiKey(genKey);
  11082. wc_ecc_del_point(pvt);
  11083. exit:
  11084. WC_FREE_VAR(genKey, HEAP_HINT);
  11085. WC_FREE_VAR(ssk, HEAP_HINT);
  11086. }
  11087. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  11088. #endif /* WOLFCRYPT_HAVE_ECCSI */
  11089. #ifdef WOLFCRYPT_HAVE_SAKKE
  11090. #ifdef WOLFCRYPT_SAKKE_KMS
  11091. void bench_sakkeKeyGen(void)
  11092. {
  11093. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11094. double start;
  11095. int i, count;
  11096. const char**desc = bench_desc_words[lng_index];
  11097. int ret;
  11098. DECLARE_MULTI_VALUE_STATS_VARS()
  11099. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11100. /* Key Gen */
  11101. bench_stats_start(&count, &start);
  11102. do {
  11103. for (i = 0; i < genTimes; i++) {
  11104. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11105. ret = wc_MakeSakkeKey(genKey, &gRng);
  11106. if (ret != 0) {
  11107. printf("wc_MakeSakkeKey failed: %d\n", ret);
  11108. goto exit;
  11109. }
  11110. wc_FreeSakkeKey(genKey);
  11111. RECORD_MULTI_VALUE_STATS();
  11112. }
  11113. count += i;
  11114. } while (bench_stats_check(start)
  11115. #ifdef MULTI_VALUE_STATISTICS
  11116. || runs < minimum_runs
  11117. #endif
  11118. );
  11119. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  11120. #ifdef MULTI_VALUE_STATISTICS
  11121. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11122. #endif
  11123. exit:
  11124. WC_FREE_VAR(genKey, HEAP_HINT);
  11125. }
  11126. void bench_sakkeRskGen(void)
  11127. {
  11128. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11129. double start;
  11130. int i, count;
  11131. const char**desc = bench_desc_words[lng_index];
  11132. ecc_point* rsk;
  11133. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11134. int ret;
  11135. DECLARE_MULTI_VALUE_STATS_VARS()
  11136. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11137. rsk = wc_ecc_new_point();
  11138. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11139. (void)wc_MakeSakkeKey(genKey, &gRng);
  11140. /* RSK Gen */
  11141. bench_stats_start(&count, &start);
  11142. do {
  11143. for (i = 0; i < genTimes; i++) {
  11144. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11145. if (ret != 0) {
  11146. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11147. goto exit;
  11148. }
  11149. RECORD_MULTI_VALUE_STATS();
  11150. }
  11151. count += i;
  11152. } while (bench_stats_check(start)
  11153. #ifdef MULTI_VALUE_STATISTICS
  11154. || runs < minimum_runs
  11155. #endif
  11156. );
  11157. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11158. #ifdef MULTI_VALUE_STATISTICS
  11159. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11160. #endif
  11161. wc_FreeSakkeKey(genKey);
  11162. wc_ecc_del_point(rsk);
  11163. exit:
  11164. WC_FREE_VAR(genKey, HEAP_HINT);
  11165. }
  11166. #endif
  11167. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11168. void bench_sakkeValidate(void)
  11169. {
  11170. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11171. double start;
  11172. int i, count;
  11173. const char**desc = bench_desc_words[lng_index];
  11174. ecc_point* rsk;
  11175. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11176. int valid;
  11177. int ret;
  11178. DECLARE_MULTI_VALUE_STATS_VARS()
  11179. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11180. rsk = wc_ecc_new_point();
  11181. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11182. (void)wc_MakeSakkeKey(genKey, &gRng);
  11183. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11184. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11185. /* Validation of RSK */
  11186. bench_stats_start(&count, &start);
  11187. do {
  11188. for (i = 0; i < genTimes; i++) {
  11189. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11190. if (ret != 0 || !valid) {
  11191. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11192. valid);
  11193. goto exit;
  11194. }
  11195. RECORD_MULTI_VALUE_STATS();
  11196. }
  11197. count += i;
  11198. } while (bench_stats_check(start)
  11199. #ifdef MULTI_VALUE_STATISTICS
  11200. || runs < minimum_runs
  11201. #endif
  11202. );
  11203. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11204. #ifdef MULTI_VALUE_STATISTICS
  11205. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11206. #endif
  11207. wc_FreeSakkeKey(genKey);
  11208. wc_ecc_del_point(rsk);
  11209. exit:
  11210. WC_FREE_VAR(genKey, HEAP_HINT);
  11211. }
  11212. void bench_sakke(void)
  11213. {
  11214. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11215. double start;
  11216. int i, count;
  11217. const char**desc = bench_desc_words[lng_index];
  11218. ecc_point* rsk;
  11219. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11220. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11221. byte ssv[sizeof(ssv_init)];
  11222. byte derSSV[sizeof(ssv)];
  11223. byte auth[257];
  11224. word16 authSz = sizeof(auth);
  11225. int ret = 0;
  11226. byte* table = NULL;
  11227. word32 len = 0;
  11228. byte* iTable = NULL;
  11229. word32 iTableLen = 0;
  11230. DECLARE_MULTI_VALUE_STATS_VARS()
  11231. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11232. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11233. rsk = wc_ecc_new_point();
  11234. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11235. (void)wc_MakeSakkeKey(genKey, &gRng);
  11236. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11237. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11238. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11239. /* Encapsulate */
  11240. bench_stats_start(&count, &start);
  11241. do {
  11242. for (i = 0; i < genTimes; i++) {
  11243. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11244. WC_HASH_TYPE_SHA256,
  11245. ssv, sizeof(ssv), auth, &authSz);
  11246. if (ret != 0) {
  11247. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11248. break;
  11249. }
  11250. RECORD_MULTI_VALUE_STATS();
  11251. } /* for */
  11252. count += i;
  11253. } while (bench_stats_check(start)
  11254. #ifdef MULTI_VALUE_STATISTICS
  11255. || runs < minimum_runs
  11256. #endif
  11257. );
  11258. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11259. 0, count, start, 0);
  11260. #ifdef MULTI_VALUE_STATISTICS
  11261. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11262. #endif
  11263. RESET_MULTI_VALUE_STATS_VARS();
  11264. /* Derive */
  11265. bench_stats_start(&count, &start);
  11266. do {
  11267. for (i = 0; i < genTimes; i++) {
  11268. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11269. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11270. sizeof(derSSV), auth, authSz);
  11271. if (ret != 0) {
  11272. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11273. break;
  11274. }
  11275. RECORD_MULTI_VALUE_STATS();
  11276. }
  11277. if (ret != 0) break;
  11278. count += i;
  11279. } while (bench_stats_check(start)
  11280. #ifdef MULTI_VALUE_STATISTICS
  11281. || runs < minimum_runs
  11282. #endif
  11283. );
  11284. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11285. 0, count, start, 0);
  11286. #ifdef MULTI_VALUE_STATISTICS
  11287. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11288. #endif
  11289. /* Calculate Point I and generate table. */
  11290. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11291. iTableLen = 0;
  11292. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11293. if (iTableLen != 0) {
  11294. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11295. if (iTable == NULL)
  11296. WC_ALLOC_DO_ON_FAILURE();
  11297. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11298. }
  11299. /* Encapsulate with Point I table */
  11300. bench_stats_start(&count, &start);
  11301. do {
  11302. for (i = 0; i < genTimes; i++) {
  11303. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11304. WC_HASH_TYPE_SHA256, ssv,
  11305. sizeof(ssv), auth, &authSz);
  11306. if (ret != 0) {
  11307. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11308. break;
  11309. }
  11310. RECORD_MULTI_VALUE_STATS();
  11311. }
  11312. count += i;
  11313. } while (bench_stats_check(start)
  11314. #ifdef MULTI_VALUE_STATISTICS
  11315. || runs < minimum_runs
  11316. #endif
  11317. );
  11318. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11319. count, start, 0);
  11320. #ifdef MULTI_VALUE_STATISTICS
  11321. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11322. #endif
  11323. RESET_MULTI_VALUE_STATS_VARS();
  11324. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11325. /* Derive with Point I table */
  11326. bench_stats_start(&count, &start);
  11327. do {
  11328. for (i = 0; i < genTimes; i++) {
  11329. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11330. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11331. sizeof(derSSV), auth, authSz);
  11332. if (ret != 0) {
  11333. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11334. break;
  11335. }
  11336. RECORD_MULTI_VALUE_STATS();
  11337. }
  11338. if (ret != 0) break;
  11339. count += i;
  11340. } while (bench_stats_check(start)
  11341. #ifdef MULTI_VALUE_STATISTICS
  11342. || runs < minimum_runs
  11343. #endif
  11344. );
  11345. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11346. count, start, 0);
  11347. #ifdef MULTI_VALUE_STATISTICS
  11348. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11349. #endif
  11350. RESET_MULTI_VALUE_STATS_VARS();
  11351. len = 0;
  11352. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11353. if (len > 0) {
  11354. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11355. if (table == NULL)
  11356. WC_ALLOC_DO_ON_FAILURE();
  11357. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11358. }
  11359. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11360. /* Derive with Point I table and RSK table */
  11361. bench_stats_start(&count, &start);
  11362. do {
  11363. for (i = 0; i < genTimes; i++) {
  11364. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11365. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11366. sizeof(derSSV), auth, authSz);
  11367. if (ret != 0) {
  11368. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11369. break;
  11370. }
  11371. RECORD_MULTI_VALUE_STATS();
  11372. }
  11373. if (ret != 0) break;
  11374. count += i;
  11375. } while (bench_stats_check(start)
  11376. #ifdef MULTI_VALUE_STATISTICS
  11377. || runs < minimum_runs
  11378. #endif
  11379. );
  11380. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11381. 0, count, start, 0);
  11382. #ifdef MULTI_VALUE_STATISTICS
  11383. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11384. #endif
  11385. RESET_MULTI_VALUE_STATS_VARS();
  11386. wc_ClearSakkePointITable(genKey);
  11387. /* Derive with RSK table */
  11388. bench_stats_start(&count, &start);
  11389. do {
  11390. for (i = 0; i < genTimes; i++) {
  11391. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11392. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11393. sizeof(derSSV), auth, authSz);
  11394. if (ret != 0) {
  11395. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11396. break;
  11397. }
  11398. RECORD_MULTI_VALUE_STATS();
  11399. }
  11400. if (ret != 0) break;
  11401. count += i;
  11402. } while (bench_stats_check(start)
  11403. #ifdef MULTI_VALUE_STATISTICS
  11404. || runs < minimum_runs
  11405. #endif
  11406. );
  11407. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11408. count, start, 0);
  11409. #ifdef MULTI_VALUE_STATISTICS
  11410. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11411. #endif
  11412. wc_FreeSakkeKey(genKey);
  11413. wc_ecc_del_point(rsk);
  11414. exit:
  11415. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11416. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11417. WC_FREE_VAR(genKey, HEAP_HINT);
  11418. }
  11419. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11420. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11421. #ifdef HAVE_FALCON
  11422. void bench_falconKeySign(byte level)
  11423. {
  11424. int ret = 0;
  11425. falcon_key key;
  11426. double start;
  11427. int i, count;
  11428. byte sig[FALCON_MAX_SIG_SIZE];
  11429. byte msg[512];
  11430. word32 x = 0;
  11431. const char**desc = bench_desc_words[lng_index];
  11432. DECLARE_MULTI_VALUE_STATS_VARS()
  11433. ret = wc_falcon_init(&key);
  11434. if (ret != 0) {
  11435. printf("wc_falcon_init failed %d\n", ret);
  11436. return;
  11437. }
  11438. ret = wc_falcon_set_level(&key, level);
  11439. if (ret != 0) {
  11440. printf("wc_falcon_set_level failed %d\n", ret);
  11441. }
  11442. if (ret == 0) {
  11443. if (level == 1) {
  11444. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11445. sizeof_bench_falcon_level1_key,
  11446. NULL, 0, &key);
  11447. }
  11448. else {
  11449. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11450. sizeof_bench_falcon_level5_key,
  11451. NULL, 0, &key);
  11452. }
  11453. if (ret != 0) {
  11454. printf("wc_falcon_import_private_key failed %d\n", ret);
  11455. }
  11456. }
  11457. /* make dummy msg */
  11458. for (i = 0; i < (int)sizeof(msg); i++) {
  11459. msg[i] = (byte)i;
  11460. }
  11461. bench_stats_start(&count, &start);
  11462. do {
  11463. for (i = 0; i < agreeTimes; i++) {
  11464. if (ret == 0) {
  11465. if (level == 1) {
  11466. x = FALCON_LEVEL1_SIG_SIZE;
  11467. }
  11468. else {
  11469. x = FALCON_LEVEL5_SIG_SIZE;
  11470. }
  11471. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11472. if (ret != 0) {
  11473. printf("wc_falcon_sign_msg failed\n");
  11474. }
  11475. }
  11476. RECORD_MULTI_VALUE_STATS();
  11477. }
  11478. count += i;
  11479. } while (bench_stats_check(start)
  11480. #ifdef MULTI_VALUE_STATISTICS
  11481. || runs < minimum_runs
  11482. #endif
  11483. );
  11484. if (ret == 0) {
  11485. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11486. count, start, ret);
  11487. #ifdef MULTI_VALUE_STATISTICS
  11488. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11489. #endif
  11490. }
  11491. RESET_MULTI_VALUE_STATS_VARS();
  11492. bench_stats_start(&count, &start);
  11493. do {
  11494. for (i = 0; i < agreeTimes; i++) {
  11495. if (ret == 0) {
  11496. int verify = 0;
  11497. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11498. &key);
  11499. if (ret != 0 || verify != 1) {
  11500. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11501. ret, verify);
  11502. ret = -1;
  11503. }
  11504. }
  11505. RECORD_MULTI_VALUE_STATS();
  11506. }
  11507. count += i;
  11508. } while (bench_stats_check(start)
  11509. #ifdef MULTI_VALUE_STATISTICS
  11510. || runs < minimum_runs
  11511. #endif
  11512. );
  11513. if (ret == 0) {
  11514. bench_stats_asym_finish("FALCON", level, desc[5],
  11515. 0, count, start, ret);
  11516. #ifdef MULTI_VALUE_STATISTICS
  11517. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11518. #endif
  11519. }
  11520. wc_falcon_free(&key);
  11521. }
  11522. #endif /* HAVE_FALCON */
  11523. #ifdef HAVE_DILITHIUM
  11524. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11525. #ifndef WOLFSSL_NO_ML_DSA_44
  11526. static const unsigned char bench_dilithium_level2_sig[] = {
  11527. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11528. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11529. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11530. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11531. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11532. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11533. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11534. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11535. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11536. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11537. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11538. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11539. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11540. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11541. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11542. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11543. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11544. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11545. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11546. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11547. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11548. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11549. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11550. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11551. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11552. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11553. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11554. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11555. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11556. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11557. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11558. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11559. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11560. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11561. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11562. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11563. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11564. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11565. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11566. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11567. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11568. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11569. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11570. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11571. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11572. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11573. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11574. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11575. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11576. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11577. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11578. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11579. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11580. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11581. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11582. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11583. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11584. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11585. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11586. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11587. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11588. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11589. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11590. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11591. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11592. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11593. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11594. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11595. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11596. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11597. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11598. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11599. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11600. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11601. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11602. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11603. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11604. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11605. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11606. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11607. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11608. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11609. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11610. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11611. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11612. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11613. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11614. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11615. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11616. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11617. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11618. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11619. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11620. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11621. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11622. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11623. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11624. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11625. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11626. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11627. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11628. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11629. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11630. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11631. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11632. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11633. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11634. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11635. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11636. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11637. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11638. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11639. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11640. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11641. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11642. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11643. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11644. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11645. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11646. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11647. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11648. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11649. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11650. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11651. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11652. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11653. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11654. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11655. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11656. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11657. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11658. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11659. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11660. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11661. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11662. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11663. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11664. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11665. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11666. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11667. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11668. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11669. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11670. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11671. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11672. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11673. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11674. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11675. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11676. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11677. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11678. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11679. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11680. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11681. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11682. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11683. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11684. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11685. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11686. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11687. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11688. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11689. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11690. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11691. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11692. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11693. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11694. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11695. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11696. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11697. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11698. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11699. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11700. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11701. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11702. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11703. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11704. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11705. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11706. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11707. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11708. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11709. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11710. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11711. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11712. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11713. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11714. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11715. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11716. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11717. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11718. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11719. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11720. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11721. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11722. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11723. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11724. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11725. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11726. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11727. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11728. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11729. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11730. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11731. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11732. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11733. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11734. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11735. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11736. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11737. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11738. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11739. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11740. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11741. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11742. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11743. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11744. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11745. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11746. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11747. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11748. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11749. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11750. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11751. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11752. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11753. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11754. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11755. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11756. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11757. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11758. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11759. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11760. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11761. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11762. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11763. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11764. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11765. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11766. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11767. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11768. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11769. };
  11770. static const int sizeof_bench_dilithium_level2_sig =
  11771. sizeof(bench_dilithium_level2_sig);
  11772. #endif
  11773. #ifndef WOLFSSL_NO_ML_DSA_65
  11774. static const unsigned char bench_dilithium_level3_sig[] = {
  11775. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11776. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11777. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11778. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11779. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11780. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11781. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11782. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11783. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11784. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11785. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11786. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11787. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11788. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11789. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11790. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11791. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11792. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11793. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11794. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11795. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11796. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11797. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11798. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11799. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11800. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11801. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11802. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11803. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11804. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11805. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11806. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11807. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11808. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11809. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11810. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11811. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11812. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11813. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11814. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11815. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11816. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11817. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11818. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11819. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11820. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11821. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11822. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11823. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11824. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11825. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11826. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11827. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11828. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11829. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11830. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11831. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11832. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11833. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11834. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11835. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11836. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11837. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11838. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11839. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11840. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11841. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11842. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11843. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11844. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11845. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11846. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11847. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11848. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11849. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11850. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11851. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11852. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11853. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11854. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11855. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11856. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11857. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11858. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11859. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11860. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11861. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11862. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11863. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11864. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11865. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11866. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11867. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11868. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11869. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11870. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11871. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11872. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11873. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11874. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11875. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11876. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11877. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11878. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11879. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11880. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11881. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11882. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11883. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11884. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11885. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11886. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11887. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11888. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11889. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11890. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11891. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11892. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11893. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11894. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11895. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11896. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11897. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11898. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11899. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11900. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11901. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11902. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11903. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11904. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11905. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11906. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11907. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11908. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11909. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11910. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11911. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11912. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11913. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11914. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11915. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11916. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11917. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11918. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11919. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11920. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11921. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11922. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11923. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11924. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11925. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11926. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11927. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11928. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11929. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11930. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11931. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11932. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11933. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11934. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11935. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11936. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11937. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11938. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11939. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11940. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11941. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11942. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11943. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11944. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11945. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11946. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11947. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11948. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11949. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11950. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11951. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11952. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11953. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11954. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11955. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11956. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11957. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11958. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11959. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11960. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11961. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11962. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11963. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11964. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11965. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11966. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11967. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11968. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11969. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11970. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11971. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11972. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11973. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11974. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11975. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11976. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11977. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11978. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11979. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11980. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11981. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11982. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11983. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11984. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11985. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11986. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11987. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11988. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11989. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11990. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11991. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11992. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11993. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11994. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11995. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11996. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11997. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11998. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11999. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  12000. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  12001. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  12002. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  12003. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  12004. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  12005. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  12006. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  12007. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  12008. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  12009. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  12010. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  12011. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  12012. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  12013. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  12014. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  12015. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  12016. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  12017. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  12018. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  12019. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  12020. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  12021. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  12022. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  12023. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  12024. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  12025. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  12026. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  12027. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  12028. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  12029. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  12030. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  12031. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  12032. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  12033. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  12034. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  12035. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  12036. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  12037. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  12038. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  12039. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  12040. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  12041. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  12042. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  12043. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  12044. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  12045. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  12046. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  12047. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  12048. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  12049. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  12050. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  12051. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  12052. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  12053. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  12054. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  12055. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  12056. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  12057. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  12058. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  12059. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  12060. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  12061. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  12062. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  12063. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  12064. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  12065. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  12066. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  12067. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  12068. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  12069. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  12070. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  12071. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  12072. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  12073. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  12074. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  12075. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  12076. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  12077. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  12078. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  12079. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  12080. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  12081. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  12082. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  12083. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  12084. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  12085. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  12086. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  12087. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  12088. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  12089. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  12090. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  12091. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  12092. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  12093. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  12094. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  12095. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  12096. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  12097. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  12098. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  12099. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  12100. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  12101. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  12102. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  12103. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  12104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12105. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  12106. };
  12107. static const int sizeof_bench_dilithium_level3_sig =
  12108. sizeof(bench_dilithium_level3_sig);
  12109. #endif
  12110. #ifndef WOLFSSL_NO_ML_DSA_87
  12111. static const unsigned char bench_dilithium_level5_sig[] = {
  12112. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  12113. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  12114. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  12115. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  12116. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  12117. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  12118. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  12119. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  12120. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  12121. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  12122. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  12123. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  12124. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  12125. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  12126. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  12127. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  12128. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  12129. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  12130. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  12131. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  12132. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12133. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12134. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12135. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12136. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12137. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12138. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12139. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12140. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12141. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12142. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12143. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12144. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12145. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12146. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12147. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12148. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12149. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12150. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12151. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12152. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12153. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12154. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12155. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12156. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12157. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12158. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12159. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12160. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12161. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12162. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12163. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12164. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12165. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12166. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12167. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12168. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12169. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12170. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12171. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12172. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12173. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12174. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12175. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12176. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12177. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12178. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12179. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12180. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12181. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12182. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12183. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12184. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12185. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12186. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12187. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12188. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12189. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12190. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12191. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12192. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12193. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12194. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12195. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12196. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12197. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12198. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12199. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12200. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12201. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12202. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12203. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12204. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12205. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12206. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12207. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12208. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12209. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12210. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12211. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12212. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12213. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12214. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12215. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12216. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12217. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12218. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12219. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12220. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12221. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12222. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12223. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12224. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12225. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12226. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12227. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12228. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12229. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12230. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12231. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12232. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12233. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12234. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12235. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12236. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12237. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12238. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12239. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12240. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12241. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12242. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12243. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12244. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12245. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12246. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12247. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12248. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12249. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12250. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12251. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12252. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12253. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12254. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12255. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12256. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12257. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12258. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12259. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12260. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12261. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12262. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12263. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12264. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12265. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12266. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12267. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12268. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12269. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12270. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12271. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12272. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12273. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12274. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12275. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12276. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12277. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12278. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12279. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12280. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12281. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12282. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12283. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12284. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12285. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12286. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12287. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12288. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12289. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12290. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12291. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12292. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12293. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12294. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12295. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12296. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12297. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12298. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12299. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12300. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12301. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12302. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12303. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12304. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12305. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12306. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12307. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12308. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12309. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12310. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12311. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12312. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12313. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12314. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12315. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12316. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12317. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12318. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12319. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12320. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12321. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12322. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12323. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12324. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12325. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12326. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12327. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12328. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12329. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12330. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12331. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12332. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12333. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12334. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12335. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12336. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12337. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12338. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12339. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12340. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12341. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12342. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12343. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12344. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12345. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12346. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12347. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12348. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12349. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12350. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12351. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12352. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12353. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12354. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12355. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12356. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12357. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12358. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12359. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12360. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12361. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12362. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12363. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12364. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12365. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12366. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12367. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12368. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12369. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12370. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12371. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12372. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12373. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12374. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12375. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12376. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12377. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12378. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12379. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12380. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12381. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12382. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12383. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12384. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12385. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12386. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12387. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12388. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12389. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12390. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12391. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12392. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12393. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12394. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12395. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12396. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12397. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12398. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12399. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12400. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12401. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12402. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12403. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12404. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12405. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12406. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12407. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12408. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12409. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12410. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12411. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12412. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12413. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12414. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12415. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12416. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12417. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12418. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12419. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12420. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12421. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12422. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12423. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12424. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12425. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12426. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12427. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12428. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12429. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12430. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12431. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12432. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12433. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12434. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12435. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12436. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12437. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12438. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12439. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12440. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12441. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12442. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12443. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12444. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12445. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12446. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12447. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12448. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12449. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12450. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12451. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12452. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12453. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12454. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12455. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12456. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12457. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12458. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12459. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12460. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12461. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12462. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12463. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12464. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12465. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12466. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12467. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12468. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12469. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12470. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12471. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12472. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12473. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12474. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12475. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12476. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12477. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12478. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12479. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12480. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12481. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12482. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12483. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12484. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12485. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12486. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12487. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12488. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12489. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12490. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12491. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12492. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12493. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12494. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12495. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12496. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12497. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12498. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12499. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12500. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12501. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12502. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12503. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12504. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12505. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12506. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12507. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12508. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12509. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12510. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12511. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12512. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12513. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12514. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12515. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12516. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12517. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12518. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12519. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12520. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12521. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12522. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12523. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12524. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12525. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12526. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12527. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12528. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12529. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12530. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12531. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12532. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12533. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12534. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12535. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12536. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12537. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12538. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12539. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12540. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12541. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12542. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12543. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12544. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12545. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12546. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12547. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12548. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12549. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12550. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12551. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12552. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12553. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12554. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12555. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12556. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12557. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12558. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12559. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12560. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12561. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12562. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12563. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12564. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12565. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12566. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12567. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12568. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12569. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12570. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12571. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12572. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12573. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12574. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12575. };
  12576. static const int sizeof_bench_dilithium_level5_sig =
  12577. sizeof(bench_dilithium_level5_sig);
  12578. #endif
  12579. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12580. void bench_dilithiumKeySign(byte level)
  12581. {
  12582. int ret = 0;
  12583. dilithium_key key;
  12584. double start;
  12585. int i, count;
  12586. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12587. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12588. byte msg[512];
  12589. word32 x = 0;
  12590. #endif
  12591. const char**desc = bench_desc_words[lng_index];
  12592. DECLARE_MULTI_VALUE_STATS_VARS()
  12593. byte params = 0;
  12594. if (level == 2) {
  12595. params = 44;
  12596. }
  12597. else if (level == 3) {
  12598. params = 65;
  12599. }
  12600. else if (level == 5) {
  12601. params = 87;
  12602. }
  12603. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12604. /* make dummy msg */
  12605. for (i = 0; i < (int)sizeof(msg); i++) {
  12606. msg[i] = (byte)i;
  12607. }
  12608. #endif
  12609. ret = wc_dilithium_init(&key);
  12610. if (ret != 0) {
  12611. printf("wc_dilithium_init failed %d\n", ret);
  12612. return;
  12613. }
  12614. ret = wc_dilithium_set_level(&key, level);
  12615. if (ret != 0) {
  12616. printf("wc_dilithium_set_level() failed %d\n", ret);
  12617. }
  12618. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12619. bench_stats_start(&count, &start);
  12620. do {
  12621. for (i = 0; i < agreeTimes; i++) {
  12622. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12623. if (ret != 0) {
  12624. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12625. return;
  12626. }
  12627. }
  12628. count += i;
  12629. } while (bench_stats_check(start)
  12630. #ifdef MULTI_VALUE_STATISTICS
  12631. || runs < minimum_runs
  12632. #endif
  12633. );
  12634. if (ret == 0) {
  12635. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12636. start, ret);
  12637. #ifdef MULTI_VALUE_STATISTICS
  12638. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12639. #endif
  12640. }
  12641. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12642. #ifndef WOLFSSL_NO_ML_DSA_44
  12643. if (level == 2) {
  12644. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12645. sizeof_bench_dilithium_level2_key, &key);
  12646. }
  12647. #endif
  12648. #ifndef WOLFSSL_NO_ML_DSA_65
  12649. if (level == 3) {
  12650. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12651. sizeof_bench_dilithium_level3_key, &key);
  12652. }
  12653. #endif
  12654. #ifndef WOLFSSL_NO_ML_DSA_87
  12655. if (level == 5) {
  12656. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12657. sizeof_bench_dilithium_level5_key, &key);
  12658. }
  12659. #endif
  12660. if (ret != 0) {
  12661. printf("Failed to load private key\n");
  12662. return;
  12663. }
  12664. #endif
  12665. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12666. if (level == 2) {
  12667. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12668. }
  12669. else if (level == 3) {
  12670. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12671. }
  12672. else {
  12673. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12674. }
  12675. RESET_MULTI_VALUE_STATS_VARS();
  12676. bench_stats_start(&count, &start);
  12677. do {
  12678. for (i = 0; i < agreeTimes; i++) {
  12679. if (ret == 0) {
  12680. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12681. GLOBAL_RNG);
  12682. if (ret != 0) {
  12683. printf("wc_dilithium_sign_msg failed\n");
  12684. }
  12685. }
  12686. RECORD_MULTI_VALUE_STATS();
  12687. }
  12688. count += i;
  12689. } while (bench_stats_check(start)
  12690. #ifdef MULTI_VALUE_STATISTICS
  12691. || runs < minimum_runs
  12692. #endif
  12693. );
  12694. if (ret == 0) {
  12695. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12696. ret);
  12697. #ifdef MULTI_VALUE_STATISTICS
  12698. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12699. #endif
  12700. }
  12701. #endif
  12702. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12703. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12704. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12705. #ifndef WOLFSSL_NO_ML_DSA_44
  12706. if (level == 2) {
  12707. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12708. x = sizeof_bench_dilithium_level2_sig;
  12709. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12710. #endif
  12711. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12712. sizeof_bench_dilithium_level2_pubkey, &key);
  12713. }
  12714. #endif
  12715. #ifndef WOLFSSL_NO_ML_DSA_65
  12716. if (level == 3) {
  12717. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12718. x = sizeof_bench_dilithium_level3_sig;
  12719. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12720. #endif
  12721. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12722. sizeof_bench_dilithium_level3_pubkey, &key);
  12723. }
  12724. #endif
  12725. #ifndef WOLFSSL_NO_ML_DSA_87
  12726. if (level == 5) {
  12727. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12728. x = sizeof_bench_dilithium_level5_sig;
  12729. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12730. #endif
  12731. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12732. sizeof_bench_dilithium_level5_pubkey, &key);
  12733. }
  12734. #endif
  12735. if (ret != 0) {
  12736. printf("Failed to load public key\n");
  12737. return;
  12738. }
  12739. #endif
  12740. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12741. RESET_MULTI_VALUE_STATS_VARS();
  12742. bench_stats_start(&count, &start);
  12743. do {
  12744. for (i = 0; i < agreeTimes; i++) {
  12745. if (ret == 0) {
  12746. int verify = 0;
  12747. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12748. &verify, &key);
  12749. if (ret != 0 || verify != 1) {
  12750. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12751. ret, verify);
  12752. ret = -1;
  12753. }
  12754. }
  12755. RECORD_MULTI_VALUE_STATS();
  12756. }
  12757. count += i;
  12758. } while (bench_stats_check(start)
  12759. #ifdef MULTI_VALUE_STATISTICS
  12760. || runs < minimum_runs
  12761. #endif
  12762. );
  12763. if (ret == 0) {
  12764. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12765. ret);
  12766. #ifdef MULTI_VALUE_STATISTICS
  12767. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12768. #endif
  12769. }
  12770. #endif
  12771. wc_dilithium_free(&key);
  12772. }
  12773. #endif /* HAVE_DILITHIUM */
  12774. #ifdef HAVE_SPHINCS
  12775. void bench_sphincsKeySign(byte level, byte optim)
  12776. {
  12777. int ret = 0;
  12778. sphincs_key key;
  12779. double start;
  12780. int i, count;
  12781. byte sig[SPHINCS_MAX_SIG_SIZE];
  12782. byte msg[512];
  12783. word32 x = 0;
  12784. const char**desc = bench_desc_words[lng_index];
  12785. DECLARE_MULTI_VALUE_STATS_VARS()
  12786. ret = wc_sphincs_init(&key);
  12787. if (ret != 0) {
  12788. printf("wc_sphincs_init failed %d\n", ret);
  12789. return;
  12790. }
  12791. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12792. if (ret != 0) {
  12793. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12794. }
  12795. if (ret == 0) {
  12796. ret = -1;
  12797. if ((level == 1) && (optim == FAST_VARIANT)) {
  12798. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12799. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12800. }
  12801. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12802. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12803. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12804. }
  12805. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12806. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12807. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12808. }
  12809. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12810. ret = wc_sphincs_import_private_key(
  12811. bench_sphincs_small_level1_key,
  12812. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12813. }
  12814. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12815. ret = wc_sphincs_import_private_key(
  12816. bench_sphincs_small_level3_key,
  12817. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12818. }
  12819. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12820. ret = wc_sphincs_import_private_key(
  12821. bench_sphincs_small_level5_key,
  12822. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12823. }
  12824. if (ret != 0) {
  12825. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12826. }
  12827. }
  12828. /* make dummy msg */
  12829. for (i = 0; i < (int)sizeof(msg); i++) {
  12830. msg[i] = (byte)i;
  12831. }
  12832. bench_stats_start(&count, &start);
  12833. do {
  12834. for (i = 0; i < agreeTimes; i++) {
  12835. if (ret == 0) {
  12836. if ((level == 1) && (optim == FAST_VARIANT)) {
  12837. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12838. }
  12839. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12840. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12841. }
  12842. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12843. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12844. }
  12845. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12846. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12847. }
  12848. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12849. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12850. }
  12851. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12852. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12853. }
  12854. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12855. if (ret != 0) {
  12856. printf("wc_sphincs_sign_msg failed\n");
  12857. }
  12858. }
  12859. RECORD_MULTI_VALUE_STATS();
  12860. }
  12861. count += i;
  12862. } while (bench_stats_check(start)
  12863. #ifdef MULTI_VALUE_STATISTICS
  12864. || runs < minimum_runs
  12865. #endif
  12866. );
  12867. if (ret == 0) {
  12868. if (optim == FAST_VARIANT) {
  12869. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12870. start, ret);
  12871. }
  12872. else {
  12873. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12874. start, ret);
  12875. }
  12876. #ifdef MULTI_VALUE_STATISTICS
  12877. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12878. #endif
  12879. }
  12880. RESET_MULTI_VALUE_STATS_VARS();
  12881. bench_stats_start(&count, &start);
  12882. do {
  12883. for (i = 0; i < agreeTimes; i++) {
  12884. if (ret == 0) {
  12885. int verify = 0;
  12886. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12887. &key);
  12888. if (ret != 0 || verify != 1) {
  12889. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12890. ret, verify);
  12891. ret = -1;
  12892. }
  12893. }
  12894. RECORD_MULTI_VALUE_STATS();
  12895. }
  12896. count += i;
  12897. } while (bench_stats_check(start)
  12898. #ifdef MULTI_VALUE_STATISTICS
  12899. || runs < minimum_runs
  12900. #endif
  12901. );
  12902. if (ret == 0) {
  12903. if (optim == FAST_VARIANT) {
  12904. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12905. start, ret);
  12906. }
  12907. else {
  12908. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12909. start, ret);
  12910. }
  12911. #ifdef MULTI_VALUE_STATISTICS
  12912. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12913. #endif
  12914. }
  12915. wc_sphincs_free(&key);
  12916. }
  12917. #endif /* HAVE_SPHINCS */
  12918. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12919. #define WIN32_LEAN_AND_MEAN
  12920. #include <windows.h>
  12921. double current_time(int reset)
  12922. {
  12923. static int init = 0;
  12924. static LARGE_INTEGER freq;
  12925. LARGE_INTEGER count;
  12926. (void)reset;
  12927. if (!init) {
  12928. QueryPerformanceFrequency(&freq);
  12929. init = 1;
  12930. }
  12931. QueryPerformanceCounter(&count);
  12932. #ifdef BENCH_MICROSECOND
  12933. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12934. #else
  12935. return (double)count.QuadPart / freq.QuadPart;
  12936. #endif
  12937. }
  12938. #elif defined MICROCHIP_PIC32
  12939. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12940. #define CLOCK 80000000.0
  12941. #else
  12942. #define CLOCK 40000000.0
  12943. #endif
  12944. extern void WriteCoreTimer(word32 t);
  12945. extern word32 ReadCoreTimer(void);
  12946. double current_time(int reset)
  12947. {
  12948. unsigned int ns;
  12949. if (reset) {
  12950. WriteCoreTimer(0);
  12951. }
  12952. /* get timer in ns */
  12953. ns = ReadCoreTimer();
  12954. /* return seconds as a double */
  12955. return ( ns / CLOCK * 2.0);
  12956. }
  12957. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12958. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12959. /* declared above at line 239 */
  12960. /* extern double current_time(int reset); */
  12961. #elif defined(FREERTOS)
  12962. #ifdef PLATFORMIO
  12963. #include <freertos/FreeRTOS.h>
  12964. #include <freertos/task.h>
  12965. #else
  12966. #include "task.h"
  12967. #endif
  12968. #if defined(WOLFSSL_ESPIDF)
  12969. /* prototype definition */
  12970. int construct_argv();
  12971. extern char* __argv[22];
  12972. /* current_time(reset)
  12973. *
  12974. * Benchmark passage of time, in fractional seconds.
  12975. * [reset] is non zero to adjust timer or counter to zero
  12976. *
  12977. * Use care when repeatedly calling calling. See implementation. */
  12978. double current_time(int reset)
  12979. {
  12980. double ret;
  12981. #if ESP_IDF_VERSION_MAJOR >= 4
  12982. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12983. #else
  12984. portTickType tickCount;
  12985. #endif
  12986. #if defined(__XTENSA__)
  12987. (void)reset;
  12988. if (reset) {
  12989. /* TODO: Determine a mechanism for reset that does not interfere
  12990. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12991. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12992. ESP_LOGW(TAG, "Current_time() reset!");
  12993. portTICK_TYPE_ENTER_CRITICAL();
  12994. {
  12995. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12996. _esp_cpu_count_last = xthal_get_ccount();
  12997. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12998. }
  12999. portTICK_TYPE_EXIT_CRITICAL();
  13000. */
  13001. }
  13002. #else
  13003. /* Only reset the CPU counter for RISC-V */
  13004. if (reset) {
  13005. ESP_LOGV(TAG, "current_time() reset!");
  13006. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  13007. * unexpected rollovers in return values for Xtensa but not RISC-V?
  13008. * See also esp_get_cycle_count_ex() */
  13009. #ifdef __XTENSA__
  13010. _esp_cpu_count_last = xthal_get_ccount();
  13011. #else
  13012. #if ESP_IDF_VERSION_MAJOR >= 5
  13013. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  13014. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  13015. #else
  13016. cpu_hal_set_cycle_count((uint32_t)0);
  13017. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  13018. #endif
  13019. #endif
  13020. }
  13021. #endif
  13022. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  13023. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  13024. The count of ticks since vTaskStartScheduler was called,
  13025. typiclly in app_startup.c */
  13026. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13027. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  13028. if (tickCount == last_tickCount) {
  13029. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  13030. }
  13031. if (tickCount < last_tickCount) {
  13032. ESP_LOGW(TAG, "last_tickCount overflow?");
  13033. }
  13034. #endif
  13035. if (reset) {
  13036. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13037. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  13038. #endif
  13039. last_tickCount = tickCount;
  13040. }
  13041. else {
  13042. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13043. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  13044. #endif
  13045. }
  13046. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  13047. ret = (double)tickCount / configTICK_RATE_HZ;
  13048. #else
  13049. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  13050. "assuming 1000 Hz.");
  13051. ret = (double)(tickCount / 1000.0);
  13052. #endif /* configTICK_RATE_HZ */
  13053. return ret;
  13054. } /* current_time */
  13055. #else
  13056. /* current_time(reset)
  13057. *
  13058. * Benchmark passage of time, in fractional seconds.
  13059. * [reset] is non zero to adjust timer or counter to zero
  13060. *
  13061. * Use care when repeatedly calling calling. See implementation. */
  13062. double current_time(int reset)
  13063. {
  13064. portTickType tickCount = xTaskGetTickCount();
  13065. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  13066. #ifdef configTICK_RATE_HZ
  13067. return (double)tickCount / configTICK_RATE_HZ;
  13068. #else
  13069. return (double)tickCount / 1000;
  13070. #endif
  13071. }
  13072. #endif
  13073. #elif defined (WOLFSSL_TIRTOS)
  13074. extern double current_time(int reset);
  13075. #elif defined(FREESCALE_MQX)
  13076. double current_time(int reset)
  13077. {
  13078. TIME_STRUCT tv;
  13079. _time_get(&tv);
  13080. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  13081. }
  13082. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  13083. && defined(MAX3266X_RTC)
  13084. double current_time(int reset)
  13085. {
  13086. (void)reset;
  13087. return wc_MXC_RTC_Time();
  13088. }
  13089. #elif defined(FREESCALE_KSDK_BM)
  13090. double current_time(int reset)
  13091. {
  13092. return (double)OSA_TimeGetMsec() / 1000;
  13093. }
  13094. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  13095. double current_time(int reset)
  13096. {
  13097. (void)reset;
  13098. return (double)osKernelGetTickCount() / 1000.0;
  13099. }
  13100. #elif defined(WOLFSSL_EMBOS)
  13101. #include "RTOS.h"
  13102. double current_time(int reset)
  13103. {
  13104. double time_now;
  13105. double current_s = OS_GetTime() / 1000.0;
  13106. double current_us = OS_GetTime_us() / MILLION_VALUE;
  13107. time_now = (double)( current_s + current_us);
  13108. (void) reset;
  13109. return time_now;
  13110. }
  13111. #elif defined(WOLFSSL_SGX)
  13112. double current_time(int reset);
  13113. #elif defined(WOLFSSL_DEOS)
  13114. double current_time(int reset)
  13115. {
  13116. const uint32_t systemTickTimeInHz
  13117. = 1000000 / systemTickInMicroseconds();
  13118. const volatile uint32_t *systemTickPtr = systemTickPointer();
  13119. (void)reset;
  13120. return (double) *systemTickPtr/systemTickTimeInHz;
  13121. }
  13122. #elif defined(MICRIUM)
  13123. double current_time(int reset)
  13124. {
  13125. #if (OS_VERSION < 50000)
  13126. CPU_ERR err;
  13127. (void)reset;
  13128. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  13129. #else
  13130. RTOS_ERR err;
  13131. double ret = 0;
  13132. OS_TICK tick = OSTimeGet(&err);
  13133. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13134. (void)reset;
  13135. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13136. ret = ((double)tick)/rate;
  13137. }
  13138. return ret;
  13139. #endif
  13140. }
  13141. #elif defined(WOLFSSL_ZEPHYR)
  13142. #include <time.h>
  13143. double current_time(int reset)
  13144. {
  13145. int64_t t;
  13146. (void)reset;
  13147. #if defined(CONFIG_ARCH_POSIX)
  13148. k_cpu_idle();
  13149. #endif
  13150. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13151. return (double)(t / 1000);
  13152. }
  13153. #elif defined(WOLFSSL_NETBURNER)
  13154. #include <predef.h>
  13155. #include <utils.h>
  13156. #include <constants.h>
  13157. double current_time(int reset)
  13158. {
  13159. DWORD ticks = TimeTick; /* ticks since system start */
  13160. (void)reset;
  13161. return (double) ticks/TICKS_PER_SECOND;
  13162. }
  13163. #elif defined(WOLFSSL_RPIPICO)
  13164. #include "pico/stdlib.h"
  13165. double current_time(int reset)
  13166. {
  13167. (void)reset;
  13168. return (double) time_us_64() / 1000000;
  13169. }
  13170. #elif defined(THREADX)
  13171. #include "tx_api.h"
  13172. double current_time(int reset)
  13173. {
  13174. (void)reset;
  13175. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13176. }
  13177. #elif defined(WOLFSSL_XILINX)
  13178. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13179. #define COUNTS_PER_SECOND \
  13180. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13181. #else
  13182. #define COUNTS_PER_SECOND \
  13183. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13184. #endif
  13185. double current_time(int reset)
  13186. {
  13187. double timer;
  13188. uint64_t cntPct = 0;
  13189. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13190. /* Convert to milliseconds */
  13191. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13192. /* Convert to seconds.millisecond */
  13193. timer /= 1000;
  13194. return timer;
  13195. }
  13196. #elif defined(LINUX_RUSAGE_UTIME)
  13197. #include <sys/time.h>
  13198. #include <sys/resource.h>
  13199. static struct rusage base_rusage;
  13200. static struct rusage cur_rusage;
  13201. double current_time(int reset)
  13202. {
  13203. struct rusage rusage;
  13204. (void)reset;
  13205. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13206. if (reset)
  13207. base_rusage = rusage;
  13208. else
  13209. cur_rusage = rusage;
  13210. /* only consider user time, as system time is host-related overhead
  13211. * outside wolfcrypt.
  13212. */
  13213. return (double)rusage.ru_utime.tv_sec +
  13214. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13215. }
  13216. static void check_for_excessive_stime(const char *desc,
  13217. const char *desc_extra)
  13218. {
  13219. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13220. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13221. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13222. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13223. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13224. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13225. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13226. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13227. double stime_utime_ratio =
  13228. (cur_stime - start_stime) / (cur_utime - start_utime);
  13229. if (stime_utime_ratio > .1)
  13230. printf("%swarning, "
  13231. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13232. err_prefix, desc, desc_extra,
  13233. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13234. }
  13235. #elif defined(WOLFSSL_LINUXKM)
  13236. double current_time(int reset)
  13237. {
  13238. (void)reset;
  13239. u64 ns = ktime_get_ns();
  13240. return (double)ns / 1000000000.0;
  13241. }
  13242. #else
  13243. #include <sys/time.h>
  13244. double current_time(int reset)
  13245. {
  13246. struct timespec tv;
  13247. (void)reset;
  13248. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13249. #ifdef BENCH_MICROSECOND
  13250. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13251. #else
  13252. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13253. #endif
  13254. }
  13255. #endif /* _WIN32 */
  13256. #if defined(HAVE_GET_CYCLES)
  13257. #if defined(WOLFSSL_ESPIDF)
  13258. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13259. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13260. {
  13261. /* Reminder for long duration between calls with
  13262. * multiple overflows will not be detected. */
  13263. return esp_get_cycle_count_ex();
  13264. }
  13265. /* implement other architectures here */
  13266. #else
  13267. static WC_INLINE word64 get_intel_cycles(void)
  13268. {
  13269. unsigned int lo_c, hi_c;
  13270. __asm__ __volatile__ (
  13271. "cpuid\n\t"
  13272. "rdtsc"
  13273. : "=a"(lo_c), "=d"(hi_c) /* out */
  13274. : "a"(0) /* in */
  13275. : "%ebx", "%ecx"); /* clobber */
  13276. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13277. }
  13278. #endif
  13279. #endif /* HAVE_GET_CYCLES */
  13280. void benchmark_configure(word32 block_size)
  13281. {
  13282. /* must be greater than 0 */
  13283. if (block_size > 0) {
  13284. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13285. bench_size = block_size;
  13286. }
  13287. }
  13288. #ifndef NO_MAIN_DRIVER
  13289. #ifndef MAIN_NO_ARGS
  13290. #ifndef WOLFSSL_BENCHMARK_ALL
  13291. /* Display the algorithm string and keep to 80 characters per line.
  13292. *
  13293. * str Algorithm string to print.
  13294. * line Length of line used so far.
  13295. */
  13296. #ifndef BENCH_MAX_LINE
  13297. #define BENCH_MAX_LINE 80
  13298. #endif
  13299. static void print_alg(const char* str, int* line)
  13300. {
  13301. const char* const ident = " ";
  13302. if (*line == 0) {
  13303. printf("%s", ident);
  13304. *line = (int)XSTRLEN(ident);
  13305. }
  13306. printf(" %s", str);
  13307. *line += (int)XSTRLEN(str) + 1;
  13308. if (*line > BENCH_MAX_LINE) {
  13309. printf("\n");
  13310. *line = 0;
  13311. }
  13312. }
  13313. #endif /* WOLFSSL_BENCHMARK_ALL */
  13314. /* Display the usage options of the benchmark program. */
  13315. static void Usage(void)
  13316. {
  13317. int e = 0;
  13318. #ifndef WOLFSSL_BENCHMARK_ALL
  13319. int i;
  13320. int line;
  13321. #endif
  13322. printf("benchmark\n");
  13323. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13324. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13325. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13326. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13327. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13328. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13329. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13330. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13331. #else
  13332. e += 3;
  13333. #endif
  13334. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13335. #ifndef NO_RSA
  13336. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13337. #ifdef WOLFSSL_KEY_GEN
  13338. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13339. #endif
  13340. e++;
  13341. #else
  13342. e += 2;
  13343. #endif
  13344. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13345. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13346. #endif
  13347. e++;
  13348. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13349. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13350. #endif
  13351. e++;
  13352. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13353. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13354. #endif
  13355. e++;
  13356. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13357. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13358. #endif
  13359. e++;
  13360. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13361. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13362. #endif
  13363. e++;
  13364. #if defined(HAVE_ECC)
  13365. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13366. #endif
  13367. e++;
  13368. #ifndef WOLFSSL_BENCHMARK_ALL
  13369. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13370. line = 0;
  13371. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13372. print_alg(bench_cipher_opt[i].str, &line);
  13373. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13374. print_alg(bench_digest_opt[i].str, &line);
  13375. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13376. print_alg(bench_mac_opt[i].str, &line);
  13377. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13378. print_alg(bench_kdf_opt[i].str, &line);
  13379. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13380. print_alg(bench_asym_opt[i].str, &line);
  13381. for (i=0; bench_other_opt[i].str != NULL; i++)
  13382. print_alg(bench_other_opt[i].str, &line);
  13383. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13384. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13385. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13386. print_alg(bench_pq_asym_opt[i].str, &line);
  13387. #if defined(HAVE_SPHINCS)
  13388. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13389. print_alg(bench_pq_asym_opt2[i].str, &line);
  13390. #endif /* HAVE_SPHINCS */
  13391. #endif
  13392. #if defined(BENCH_PQ_STATEFUL_HBS)
  13393. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13394. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13395. #endif /* BENCH_PQ_STATEFUL_HBS */
  13396. printf("\n");
  13397. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13398. e++;
  13399. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13400. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13401. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13402. #ifdef WC_ENABLE_BENCH_THREADING
  13403. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13404. #endif
  13405. e++;
  13406. #ifdef WC_BENCH_TRACK_STATS
  13407. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13408. #endif
  13409. e++;
  13410. #ifndef NO_FILESYSTEM
  13411. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13412. #endif
  13413. e++;
  13414. #ifndef NO_FILESYSTEM
  13415. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13416. #endif
  13417. #ifdef MULTI_VALUE_STATISTICS
  13418. e++;
  13419. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13420. #endif
  13421. }
  13422. /* Match the command line argument with the string.
  13423. *
  13424. * arg Command line argument.
  13425. * str String to check for.
  13426. * return 1 if the command line argument matches the string, 0 otherwise.
  13427. */
  13428. static int string_matches(const char* arg, const char* str)
  13429. {
  13430. return XSTRCMP(arg, str) == 0;
  13431. }
  13432. #endif /* MAIN_NO_ARGS */
  13433. /*
  13434. ** ----------------------------------------------------------------------------
  13435. ** determine how the benchmarks are called, the function name varies:
  13436. ** ----------------------------------------------------------------------------
  13437. */
  13438. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13439. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13440. /* for some environments, we'll call a function wolf_benchmark_task: */
  13441. int wolf_benchmark_task(void)
  13442. #elif defined(MAIN_NO_ARGS)
  13443. /* otherwise we'll use main() with no arguments as desired: */
  13444. int main()
  13445. #else
  13446. /* else we'll be calling main with default arg parameters */
  13447. int main(int argc, char** argv)
  13448. #endif
  13449. {
  13450. /* Code for main() or wolf_benchmark_task() */
  13451. #ifdef WOLFSSL_ESPIDF
  13452. int argc = construct_argv();
  13453. char** argv = (char**)__argv;
  13454. #elif defined(MAIN_NO_ARGS)
  13455. int argc = 0;
  13456. char** argv = NULL;
  13457. #endif
  13458. return wolfcrypt_benchmark_main(argc, argv);
  13459. }
  13460. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13461. int wolfcrypt_benchmark_main(int argc, char** argv)
  13462. {
  13463. int ret = 0;
  13464. #ifndef MAIN_NO_ARGS
  13465. int optMatched;
  13466. #ifndef WOLFSSL_BENCHMARK_ALL
  13467. int i;
  13468. #endif
  13469. #endif
  13470. benchmark_static_init(1);
  13471. printf("%s------------------------------------------------------------------------------\n",
  13472. info_prefix);
  13473. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13474. printf("%s------------------------------------------------------------------------------\n",
  13475. info_prefix);
  13476. #ifndef MAIN_NO_ARGS
  13477. while (argc > 1) {
  13478. if (string_matches(argv[1], "-?")) {
  13479. if (--argc > 1) {
  13480. lng_index = XATOI((++argv)[1]);
  13481. if (lng_index<0 || lng_index>1) {
  13482. lng_index = 0;
  13483. }
  13484. }
  13485. Usage();
  13486. return 0;
  13487. }
  13488. else if (string_matches(argv[1], "-lng")) {
  13489. argc--;
  13490. argv++;
  13491. if (argc > 1) {
  13492. lng_index = XATOI(argv[1]);
  13493. if (lng_index<0 || lng_index>1) {
  13494. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13495. lng_index);
  13496. lng_index = 0;
  13497. }
  13498. }
  13499. }
  13500. else if (string_matches(argv[1], "-base10"))
  13501. base2 = 0;
  13502. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13503. else if (string_matches(argv[1], "-no_aad"))
  13504. aes_aad_options = AAD_SIZE_ZERO;
  13505. else if (string_matches(argv[1], "-all_aad"))
  13506. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13507. else if (string_matches(argv[1], "-aad_size")) {
  13508. argc--;
  13509. argv++;
  13510. if (argc > 1) {
  13511. aes_aad_size = (word32)XATOI(argv[1]);
  13512. aes_aad_options |= AAD_SIZE_CUSTOM;
  13513. }
  13514. }
  13515. #endif
  13516. else if (string_matches(argv[1], "-dgst_full"))
  13517. digest_stream = 0;
  13518. #ifdef HAVE_CHACHA
  13519. else if (string_matches(argv[1], "-enc_only"))
  13520. encrypt_only = 1;
  13521. #endif
  13522. #ifndef NO_RSA
  13523. else if (string_matches(argv[1], "-rsa_sign"))
  13524. rsa_sign_verify = 1;
  13525. #endif
  13526. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13527. else if (string_matches(argv[1], "-ffdhe2048"))
  13528. use_ffdhe = 2048;
  13529. #endif
  13530. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13531. else if (string_matches(argv[1], "-ffdhe3072"))
  13532. use_ffdhe = 3072;
  13533. #endif
  13534. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13535. else if (string_matches(argv[1], "-ffdhe4096"))
  13536. use_ffdhe = 4096;
  13537. #endif
  13538. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13539. else if (string_matches(argv[1], "-p256"))
  13540. bench_asym_algs |= BENCH_ECC_P256;
  13541. #endif
  13542. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13543. else if (string_matches(argv[1], "-p384"))
  13544. bench_asym_algs |= BENCH_ECC_P384;
  13545. #endif
  13546. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13547. else if (string_matches(argv[1], "-p521"))
  13548. bench_asym_algs |= BENCH_ECC_P521;
  13549. #endif
  13550. #ifdef BENCH_ASYM
  13551. else if (string_matches(argv[1], "-csv")) {
  13552. csv_format = 1;
  13553. }
  13554. #endif
  13555. #ifdef WC_ENABLE_BENCH_THREADING
  13556. else if (string_matches(argv[1], "-threads")) {
  13557. argc--;
  13558. argv++;
  13559. if (argc > 1) {
  13560. g_threadCount = XATOI(argv[1]);
  13561. if (g_threadCount < 1 || lng_index > 128){
  13562. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13563. g_threadCount);
  13564. g_threadCount = 0;
  13565. }
  13566. }
  13567. }
  13568. #endif
  13569. #ifdef WC_BENCH_TRACK_STATS
  13570. else if (string_matches(argv[1], "-print")) {
  13571. gPrintStats = 1;
  13572. }
  13573. #endif
  13574. else if (string_matches(argv[1], "-blocks")) {
  13575. argc--;
  13576. argv++;
  13577. if (argc > 1)
  13578. numBlocks = XATOI(argv[1]);
  13579. }
  13580. #ifndef NO_FILESYSTEM
  13581. else if (string_matches(argv[1], "-hash_input")) {
  13582. argc--;
  13583. argv++;
  13584. if (argc > 1)
  13585. hash_input = argv[1];
  13586. }
  13587. else if (string_matches(argv[1], "-cipher_input")) {
  13588. argc--;
  13589. argv++;
  13590. if (argc > 1)
  13591. cipher_input = argv[1];
  13592. }
  13593. #endif
  13594. #ifdef MULTI_VALUE_STATISTICS
  13595. else if (string_matches(argv[1], "-min_runs")) {
  13596. argc--;
  13597. argv++;
  13598. if (argc > 1) {
  13599. minimum_runs = XATOI(argv[1]);
  13600. }
  13601. }
  13602. #endif
  13603. else if (argv[1][0] == '-') {
  13604. optMatched = 0;
  13605. #ifndef WOLFSSL_BENCHMARK_ALL
  13606. /* Check known algorithm choosing command line options. */
  13607. /* Known cipher algorithms */
  13608. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13609. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13610. bench_cipher_algs |= bench_cipher_opt[i].val;
  13611. bench_all = 0;
  13612. optMatched = 1;
  13613. }
  13614. }
  13615. /* Known digest algorithms */
  13616. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13617. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13618. bench_digest_algs |= bench_digest_opt[i].val;
  13619. bench_all = 0;
  13620. optMatched = 1;
  13621. }
  13622. }
  13623. /* Known MAC algorithms */
  13624. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13625. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13626. bench_mac_algs |= bench_mac_opt[i].val;
  13627. bench_all = 0;
  13628. optMatched = 1;
  13629. }
  13630. }
  13631. /* Known KDF algorithms */
  13632. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13633. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13634. bench_kdf_algs |= bench_kdf_opt[i].val;
  13635. bench_all = 0;
  13636. optMatched = 1;
  13637. }
  13638. }
  13639. /* Known asymmetric algorithms */
  13640. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13641. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13642. bench_asym_algs |= bench_asym_opt[i].val;
  13643. bench_all = 0;
  13644. optMatched = 1;
  13645. }
  13646. }
  13647. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13648. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13649. /* Known asymmetric post-quantum algorithms */
  13650. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13651. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13652. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13653. bench_all = 0;
  13654. optMatched = 1;
  13655. }
  13656. }
  13657. #ifdef HAVE_SPHINCS
  13658. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13659. * -pq, so we need to do a special case for -pq since optMatched
  13660. * was set to 1 just above. */
  13661. if ((bench_pq_asym_opt[0].str != NULL) &&
  13662. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13663. {
  13664. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13665. bench_all = 0;
  13666. optMatched = 1;
  13667. }
  13668. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13669. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13670. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13671. bench_all = 0;
  13672. optMatched = 1;
  13673. }
  13674. }
  13675. #endif
  13676. #endif
  13677. /* Other known cryptographic algorithms */
  13678. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13679. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13680. bench_other_algs |= bench_other_opt[i].val;
  13681. bench_all = 0;
  13682. optMatched = 1;
  13683. }
  13684. }
  13685. #if defined(BENCH_PQ_STATEFUL_HBS)
  13686. /* post-quantum stateful hash-based signatures */
  13687. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13688. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13689. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13690. bench_all = 0;
  13691. optMatched = 1;
  13692. }
  13693. }
  13694. #endif /* BENCH_PQ_STATEFUL_HBS */
  13695. #endif
  13696. if (!optMatched) {
  13697. printf("Option not recognized: %s\n", argv[1]);
  13698. Usage();
  13699. return 1;
  13700. }
  13701. }
  13702. else {
  13703. /* parse for block size */
  13704. benchmark_configure((word32)XATOI(argv[1]));
  13705. }
  13706. argc--;
  13707. argv++;
  13708. }
  13709. #endif /* MAIN_NO_ARGS */
  13710. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13711. /* when defined, we'll always output CSV regardless of params.
  13712. ** this is typically convenient in embedded environments.
  13713. */
  13714. csv_format = 1;
  13715. #endif
  13716. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13717. if (g_threadCount > 1) {
  13718. ret = benchmark_test_threaded(NULL);
  13719. }
  13720. else
  13721. #endif
  13722. {
  13723. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13724. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13725. defined(CONFIG_IDF_TARGET_ESP32C6)
  13726. {
  13727. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13728. if (esp_gptimer == NULL) {
  13729. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13730. &esp_gptimer) );
  13731. }
  13732. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13733. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13734. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13735. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13736. }
  13737. #endif
  13738. #ifdef HAVE_STACK_SIZE
  13739. ret = StackSizeCheck(NULL, benchmark_test);
  13740. #else
  13741. ret = benchmark_test(NULL);
  13742. #endif
  13743. }
  13744. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13745. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13746. defined(CONFIG_IDF_TARGET_ESP32C6)
  13747. {
  13748. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13749. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13750. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13751. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13752. }
  13753. #endif
  13754. return ret;
  13755. }
  13756. #endif /* !NO_MAIN_DRIVER */
  13757. #else
  13758. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13759. int main(void) { return 0; }
  13760. #endif
  13761. #endif /* !NO_CRYPT_BENCHMARK */