benchmark.c 515 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196
  1. /* benchmark.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* wolfCrypt benchmark */
  22. /* Some common, optional build settings:
  23. * these can also be set in wolfssl/options.h or user_settings.h
  24. * -------------------------------------------------------------
  25. * make the binary always use CSV format:
  26. * WOLFSSL_BENCHMARK_FIXED_CSV
  27. *
  28. * choose to use the same units, regardless of scale. pick 1:
  29. * WOLFSSL_BENCHMARK_FIXED_UNITS_GB
  30. * WOLFSSL_BENCHMARK_FIXED_UNITS_MB
  31. * WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  32. * WOLFSSL_BENCHMARK_FIXED_UNITS_B
  33. *
  34. * when the output should be in machine-parseable format:
  35. * GENERATE_MACHINE_PARSEABLE_REPORT
  36. *
  37. * use microseconds as the unit of time:
  38. * BENCH_MICROSECOND
  39. *
  40. * display mean, max, min and sd of operation durations:
  41. * MULTI_VALUE_STATISTICS
  42. *
  43. * Enable tracking of the stats into an allocated linked list:
  44. * (use -print to display results):
  45. * WC_BENCH_TRACK_STATS
  46. *
  47. * set the default devId for cryptocb to the value instead of INVALID_DEVID
  48. * WC_USE_DEVID=0x1234
  49. *
  50. * Turn on benchmark timing debugging (CPU Cycles, RTOS ticks, etc)
  51. * DEBUG_WOLFSSL_BENCHMARK_TIMING
  52. *
  53. * Turn on timer debugging (used when CPU cycles not available)
  54. * WOLFSSL_BENCHMARK_TIMER_DEBUG
  55. */
  56. #ifdef HAVE_CONFIG_H
  57. #include <config.h>
  58. #endif
  59. #ifndef WOLFSSL_USER_SETTINGS
  60. #include <wolfssl/options.h>
  61. #endif
  62. #include <wolfssl/wolfcrypt/settings.h> /* also picks up user_settings.h */
  63. /* Macro to disable benchmark */
  64. #ifndef NO_CRYPT_BENCHMARK
  65. #define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
  66. #include <wolfssl/wolfcrypt/types.h>
  67. #include <wolfssl/wolfcrypt/wc_port.h>
  68. #include <wolfssl/wolfcrypt/wolfmath.h>
  69. #include <wolfssl/wolfcrypt/memory.h>
  70. #include <wolfssl/wolfcrypt/random.h>
  71. #include <wolfssl/wolfcrypt/error-crypt.h>
  72. #include <wolfssl/wolfcrypt/asn.h>
  73. #include <wolfssl/version.h>
  74. #ifdef WOLFSSL_LINUXKM
  75. /* remap current_time() -- collides with a function in kernel linux/fs.h */
  76. #define current_time benchmark_current_time
  77. #endif /* WOLFSSL_LINUXKM */
  78. #ifdef HAVE_CHACHA
  79. #include <wolfssl/wolfcrypt/chacha.h>
  80. #endif
  81. #ifdef HAVE_POLY1305
  82. #include <wolfssl/wolfcrypt/poly1305.h>
  83. #endif
  84. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  85. #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
  86. #endif
  87. #ifndef NO_AES
  88. #include <wolfssl/wolfcrypt/aes.h>
  89. #endif
  90. #ifdef HAVE_CAMELLIA
  91. #include <wolfssl/wolfcrypt/camellia.h>
  92. #endif
  93. #ifdef WOLFSSL_SM4
  94. #include <wolfssl/wolfcrypt/sm4.h>
  95. #endif
  96. #ifndef NO_MD5
  97. #include <wolfssl/wolfcrypt/md5.h>
  98. #endif
  99. #ifndef NO_SHA
  100. #include <wolfssl/wolfcrypt/sha.h>
  101. #endif
  102. #ifndef NO_SHA256
  103. #include <wolfssl/wolfcrypt/sha256.h>
  104. #endif
  105. #if defined(WOLFSSL_SHA512) || defined(WOLFSSL_SHA384)
  106. #include <wolfssl/wolfcrypt/sha512.h>
  107. #endif
  108. #ifdef WOLFSSL_SHA3
  109. #include <wolfssl/wolfcrypt/sha3.h>
  110. #endif
  111. #ifdef WOLFSSL_SM3
  112. #include <wolfssl/wolfcrypt/sm3.h>
  113. #endif
  114. #ifndef NO_RSA
  115. #include <wolfssl/wolfcrypt/rsa.h>
  116. #endif
  117. #ifdef WOLFSSL_RIPEMD
  118. #include <wolfssl/wolfcrypt/ripemd.h>
  119. #endif
  120. #ifdef WOLFSSL_CMAC
  121. #include <wolfssl/wolfcrypt/cmac.h>
  122. #endif
  123. #ifndef NO_DH
  124. #include <wolfssl/wolfcrypt/dh.h>
  125. #endif
  126. #ifndef NO_DES3
  127. #include <wolfssl/wolfcrypt/des3.h>
  128. #endif
  129. #ifndef NO_RC4
  130. #include <wolfssl/wolfcrypt/arc4.h>
  131. #endif
  132. #ifndef NO_HMAC
  133. #include <wolfssl/wolfcrypt/hmac.h>
  134. #endif
  135. #ifdef WOLFSSL_SIPHASH
  136. #include <wolfssl/wolfcrypt/siphash.h>
  137. #endif
  138. #include <wolfssl/wolfcrypt/kdf.h>
  139. #ifndef NO_PWDBASED
  140. #include <wolfssl/wolfcrypt/pwdbased.h>
  141. #endif
  142. #ifdef HAVE_ECC
  143. #include <wolfssl/wolfcrypt/ecc.h>
  144. #endif
  145. #ifdef WOLFSSL_SM2
  146. #include <wolfssl/wolfcrypt/sm2.h>
  147. #endif
  148. #ifdef HAVE_CURVE25519
  149. #include <wolfssl/wolfcrypt/curve25519.h>
  150. #endif
  151. #ifdef HAVE_ED25519
  152. #include <wolfssl/wolfcrypt/ed25519.h>
  153. #endif
  154. #ifdef HAVE_CURVE448
  155. #include <wolfssl/wolfcrypt/curve448.h>
  156. #endif
  157. #ifdef HAVE_ED448
  158. #include <wolfssl/wolfcrypt/ed448.h>
  159. #endif
  160. #ifdef WOLFSSL_HAVE_KYBER
  161. #include <wolfssl/wolfcrypt/kyber.h>
  162. #ifdef WOLFSSL_WC_KYBER
  163. #include <wolfssl/wolfcrypt/wc_kyber.h>
  164. #endif
  165. #if defined(HAVE_LIBOQS)
  166. #include <wolfssl/wolfcrypt/ext_kyber.h>
  167. #endif
  168. #endif
  169. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  170. #include <wolfssl/wolfcrypt/lms.h>
  171. #ifdef HAVE_LIBLMS
  172. #include <wolfssl/wolfcrypt/ext_lms.h>
  173. #else
  174. #include <wolfssl/wolfcrypt/wc_lms.h>
  175. #endif
  176. #endif
  177. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  178. #include <wolfssl/wolfcrypt/xmss.h>
  179. #ifdef HAVE_LIBXMSS
  180. #include <wolfssl/wolfcrypt/ext_xmss.h>
  181. #else
  182. #include <wolfssl/wolfcrypt/wc_xmss.h>
  183. #endif
  184. #endif
  185. #ifdef WOLFCRYPT_HAVE_ECCSI
  186. #include <wolfssl/wolfcrypt/eccsi.h>
  187. #endif
  188. #ifdef WOLFCRYPT_HAVE_SAKKE
  189. #include <wolfssl/wolfcrypt/sakke.h>
  190. #endif
  191. #if defined(HAVE_FALCON)
  192. #include <wolfssl/wolfcrypt/falcon.h>
  193. #endif
  194. #if defined(HAVE_DILITHIUM)
  195. #include <wolfssl/wolfcrypt/dilithium.h>
  196. #endif
  197. #if defined(HAVE_SPHINCS)
  198. #include <wolfssl/wolfcrypt/sphincs.h>
  199. #endif
  200. #ifdef WOLF_CRYPTO_CB
  201. #include <wolfssl/wolfcrypt/cryptocb.h>
  202. #ifdef HAVE_INTEL_QA_SYNC
  203. #include <wolfssl/wolfcrypt/port/intel/quickassist_sync.h>
  204. #endif
  205. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  206. #include <wolfssl/wolfcrypt/port/cavium/cavium_octeon_sync.h>
  207. #endif
  208. #ifdef HAVE_RENESAS_SYNC
  209. #include <wolfssl/wolfcrypt/port/renesas/renesas_sync.h>
  210. #endif
  211. #if defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
  212. #include <wolfssl/wolfcrypt/port/maxim/max3266x-cryptocb.h>
  213. #endif
  214. #endif
  215. #ifdef WOLFSSL_ASYNC_CRYPT
  216. #include <wolfssl/wolfcrypt/async.h>
  217. #endif
  218. #ifdef USE_FLAT_BENCHMARK_H
  219. #include "benchmark.h"
  220. #else
  221. #include "wolfcrypt/benchmark/benchmark.h"
  222. #endif
  223. /* define the max length for each string of metric reported */
  224. #ifndef WC_BENCH_MAX_LINE_LEN
  225. #define WC_BENCH_MAX_LINE_LEN 150
  226. #endif
  227. /* default units per second. See WOLFSSL_BENCHMARK_FIXED_UNITS_* to change */
  228. #define WOLFSSL_FIXED_UNIT "MB" /* may be re-set by fixed units */
  229. #define MILLION_VALUE 1000000.0
  230. #ifdef BENCH_MICROSECOND
  231. #define WOLFSSL_FIXED_TIME_UNIT "μs"
  232. #define WOLFSSL_BENCHMARK_FIXED_UNITS_KB
  233. #else
  234. #define WOLFSSL_FIXED_TIME_UNIT "s"
  235. #endif
  236. #ifdef MULTI_VALUE_STATISTICS
  237. #define STATS_CLAUSE_SEPARATOR ""
  238. #define DECLARE_MULTI_VALUE_STATS_VARS() double max = 0, min = 0, sum = 0,\
  239. squareSum = 0, prev = 0, delta;\
  240. int runs = 0;
  241. #define RECORD_MULTI_VALUE_STATS() if (runs == 0) {\
  242. delta = current_time(0) - start;\
  243. min = delta;\
  244. max = delta;\
  245. }\
  246. else {\
  247. delta = current_time(0) - prev;\
  248. }\
  249. if (max < delta)\
  250. max = delta;\
  251. else if (min > delta)\
  252. min = delta;\
  253. sum += delta;\
  254. squareSum += delta * delta;\
  255. runs++;\
  256. prev = current_time(0)
  257. #define RESET_MULTI_VALUE_STATS_VARS() prev = 0;\
  258. runs = 0;\
  259. sum = 0;\
  260. squareSum = 0
  261. #else
  262. #define STATS_CLAUSE_SEPARATOR "\n"
  263. #define DECLARE_MULTI_VALUE_STATS_VARS()
  264. #define RECORD_MULTI_VALUE_STATS() WC_DO_NOTHING
  265. #define RESET_MULTI_VALUE_STATS_VARS() WC_DO_NOTHING
  266. #endif
  267. #ifdef WOLFSSL_NO_FLOAT_FMT
  268. #define FLT_FMT "%0ld,%09lu"
  269. #define FLT_FMT_PREC "%0ld.%0*lu"
  270. #define FLT_FMT_PREC2 FLT_FMT_PREC
  271. #define FLT_FMT_ARGS(x) (long)(x), ((x) < 0) ? \
  272. (unsigned long)(-(((x) - (double)(long)(x)) * 1000000000.0)) : \
  273. (unsigned long)(((x) - (double)(long)(x)) * 1000000000.0)
  274. static const double pow_10_array[] = { 0.0, 1.0, 10.0, 100.0, 1000.0, \
  275. 10000.0, 100000.0, 1000000.0, \
  276. 10000000.0, 100000000.0, \
  277. 1000000000.0 };
  278. #define FLT_FMT_PREC_ARGS(p, x) \
  279. (long)(x), \
  280. p, \
  281. (x) >= 0.0 ? \
  282. (unsigned long int)((((x) - (double)(long)(x)) * \
  283. pow_10_array[(p)+1]) + 0.5) : \
  284. (unsigned long int)((((-(x)) - (double)((long)-(x))) * \
  285. pow_10_array[(p)+1]) + 0.5)
  286. #define FLT_FMT_PREC2_ARGS(w, p, x) FLT_FMT_PREC_ARGS(p, x)
  287. #else
  288. #define FLT_FMT "%f"
  289. #define FLT_FMT_PREC "%.*f"
  290. #define FLT_FMT_PREC2 "%*.*f"
  291. #define FLT_FMT_ARGS(x) x
  292. #define FLT_FMT_PREC_ARGS(p, x) p, x
  293. #define FLT_FMT_PREC2_ARGS(w, p, x) w, p, x
  294. #endif /* WOLFSSL_NO_FLOAT_FMT */
  295. #ifdef WOLFSSL_ESPIDF
  296. #include <wolfssl/wolfcrypt/port/Espressif/esp32-crypt.h>
  297. /* Benchmark uses 64 bit integer formatting support. When new nanolib is
  298. * enabled, all if the values in report are blank. */
  299. #ifdef CONFIG_NEWLIB_NANO_FORMAT
  300. #if CONFIG_NEWLIB_NANO_FORMAT == 1
  301. #error "Nano newlib formatting must not be enabled for benchmark"
  302. #endif
  303. #endif
  304. #if ESP_IDF_VERSION_MAJOR >= 5
  305. #define TFMT "%lu"
  306. #else
  307. #define TFMT "%d"
  308. #endif
  309. #ifdef configTICK_RATE_HZ
  310. /* Define CPU clock cycles per tick of FreeRTOS clock
  311. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ is typically a value like 240
  312. * configTICK_RATE_HZ is typically 100 or 1000.
  313. **/
  314. #if defined(CONFIG_IDF_TARGET_ESP8266)
  315. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  316. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  317. CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  318. #endif
  319. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  320. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ configCPU_CLOCK_HZ
  321. #endif
  322. #endif
  323. #ifndef CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ
  324. /* This section is for pre-v5 ESP-IDF */
  325. #if defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  326. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  327. CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
  328. #elif defined(CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ)
  329. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  330. CONFIG_ESP32C2_DEFAULT_CPU_FREQ_MHZ
  331. #elif defined(CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ)
  332. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  333. CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
  334. #elif defined(CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ)
  335. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  336. CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
  337. #elif defined(CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ)
  338. #define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ \
  339. CONFIG_ESP32H2_DEFAULT_CPU_FREQ_MHZ
  340. #else
  341. /* TODO unsupported */
  342. #endif /* older CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ */
  343. #endif
  344. #define CPU_TICK_CYCLES ( \
  345. (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE) \
  346. / configTICK_RATE_HZ \
  347. )
  348. #endif /* WOLFSSL_ESPIDF configTICK_RATE_HZ */
  349. #if defined(CONFIG_IDF_TARGET_ESP32C2)
  350. #include "driver/gptimer.h"
  351. static gptimer_handle_t esp_gptimer = NULL;
  352. static gptimer_config_t esp_timer_config = {
  353. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  354. .direction = GPTIMER_COUNT_UP,
  355. .resolution_hz = CONFIG_XTAL_FREQ * 100000,
  356. };
  357. #elif defined(CONFIG_IDF_TARGET_ESP32C3) || \
  358. defined(CONFIG_IDF_TARGET_ESP32C6)
  359. #include <esp_cpu.h>
  360. #if ESP_IDF_VERSION_MAJOR >= 5
  361. #include <driver/gptimer.h>
  362. #endif
  363. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  364. #define RESOLUTION_SCALE 100
  365. /* CONFIG_XTAL_FREQ = 40, CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  366. static gptimer_handle_t esp_gptimer = NULL;
  367. static gptimer_config_t esp_timer_config = {
  368. .clk_src = GPTIMER_CLK_SRC_DEFAULT,
  369. .direction = GPTIMER_COUNT_UP,
  370. /* CONFIG_XTAL_FREQ = 40,
  371. * CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ = 160 */
  372. .resolution_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ *
  373. (MILLION_VALUE / RESOLUTION_SCALE),
  374. };
  375. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  376. #elif defined(CONFIG_IDF_TARGET_ESP32) || \
  377. defined(CONFIG_IDF_TARGET_ESP32S2) || \
  378. defined(CONFIG_IDF_TARGET_ESP32S3)
  379. #include <xtensa/hal.h>
  380. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  381. /* no CPU HAL for ESP8266, we'll use RTOS tick calc estimates */
  382. #include <FreeRTOS.h>
  383. #include <esp_system.h>
  384. #include <esp_timer.h>
  385. #include <xtensa/hal.h>
  386. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  387. /* TODO add ESP32-H2 benchmark support */
  388. #else
  389. /* Other platform */
  390. #endif
  391. #include <esp_log.h>
  392. #endif /* WOLFSSL_ESPIDF */
  393. #if defined(HAVE_PTHREAD) || \
  394. (!defined(NO_CRYPT_BENCHMARK) && !defined(NO_STDIO_FILESYSTEM) && \
  395. !defined(NO_ERROR_STRINGS) && !defined(NO_MAIN_DRIVER) && \
  396. !defined(BENCH_EMBEDDED))
  397. #include <errno.h>
  398. #if !defined(WOLFSSL_ZEPHYR) && !defined(_WIN32)
  399. #include <unistd.h>
  400. #endif
  401. #endif
  402. #if defined(WOLFSSL_ZEPHYR) || defined(NO_STDIO_FILESYSTEM) || !defined(XFFLUSH)
  403. /* fflush in Zephyr doesn't work on stdout and stderr. Use
  404. * CONFIG_LOG_MODE_IMMEDIATE compilation option instead. */
  405. #undef XFFLUSH
  406. #define XFFLUSH(...) WC_DO_NOTHING
  407. #endif
  408. /* only for stack size check */
  409. #include <wolfssl/wolfcrypt/mem_track.h>
  410. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  411. #define WC_ENABLE_BENCH_THREADING
  412. #endif
  413. /* enable tracking of stats for threaded benchmark */
  414. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WC_BENCH_TRACK_STATS)
  415. #define WC_BENCH_TRACK_STATS
  416. #endif
  417. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  418. static const char info_prefix[] = "###, ";
  419. static const char err_prefix[] = "!!!, ";
  420. #else
  421. static const char info_prefix[] = "";
  422. static const char err_prefix[] = "";
  423. #endif
  424. /* printf mappings */
  425. #ifdef FREESCALE_MQX
  426. #include <mqx.h>
  427. /* see wc_port.h for fio.h and nio.h includes */
  428. #elif defined(FREESCALE_KSDK_1_3)
  429. #include "fsl_debug_console.h"
  430. #include "fsl_os_abstraction.h"
  431. #undef printf
  432. #define printf PRINTF
  433. #elif defined(WOLFSSL_DEOS)
  434. #include <deos.h>
  435. #include <printx.h>
  436. #undef printf
  437. #define printf printx
  438. #elif defined(MICRIUM)
  439. #if (OS_VERSION < 50000)
  440. #include <bsp_ser.h>
  441. void BSP_Ser_Printf (CPU_CHAR* format, ...);
  442. #undef printf
  443. #define printf BSP_Ser_Printf
  444. #endif
  445. #elif defined(WOLFSSL_ZEPHYR)
  446. #include <stdio.h>
  447. #define BENCH_EMBEDDED
  448. #define printf printfk
  449. static int printfk(const char *fmt, ...)
  450. {
  451. int ret;
  452. char line[WC_BENCH_MAX_LINE_LEN];
  453. va_list ap;
  454. va_start(ap, fmt);
  455. ret = vsnprintf(line, sizeof(line), fmt, ap);
  456. line[sizeof(line)-1] = '\0';
  457. printk("%s", line);
  458. va_end(ap);
  459. return ret;
  460. }
  461. #elif defined(WOLFSSL_TELIT_M2MB)
  462. #include <stdarg.h>
  463. #include <stdio.h>
  464. #include <string.h>
  465. #include "m2m_log.h" /* for M2M_LOG_INFO - not standard API */
  466. /* remap printf */
  467. #undef printf
  468. #define printf M2M_LOG_INFO
  469. /* OS requires occasional sleep() */
  470. #ifndef TEST_SLEEP_MS
  471. #define TEST_SLEEP_MS 50
  472. #endif
  473. #define TEST_SLEEP() m2mb_os_taskSleep(M2MB_OS_MS2TICKS(TEST_SLEEP_MS))
  474. /* don't use file system for these tests, since ./certs dir isn't loaded */
  475. #undef NO_FILESYSTEM
  476. #define NO_FILESYSTEM
  477. /* ANDROID_V454 (for android studio) displays information in a textview
  478. * and redirects printf to the textview output instead of using
  479. * __android_log_print() */
  480. #elif defined(ANDROID) && !defined(ANDROID_V454)
  481. #ifdef XMALLOC_USER
  482. #include <stdlib.h> /* we're using malloc / free direct here */
  483. #endif
  484. #ifndef STRING_USER
  485. #include <stdio.h>
  486. #endif
  487. #include <android/log.h>
  488. #define printf(...) \
  489. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  490. #define fprintf(fp, ...) \
  491. __android_log_print(ANDROID_LOG_DEBUG, "[WOLFCRYPT]", __VA_ARGS__)
  492. #else
  493. #if defined(XMALLOC_USER) || defined(FREESCALE_MQX)
  494. /* MQX classic needs for EXIT_FAILURE */
  495. #include <stdlib.h> /* we're using malloc / free direct here */
  496. #endif
  497. #if !defined(STRING_USER) && !defined(NO_STDIO_FILESYSTEM)
  498. #include <string.h>
  499. #include <stdio.h>
  500. #endif
  501. /* enable way for customer to override test/bench printf */
  502. #ifdef XPRINTF
  503. #undef printf
  504. #define printf XPRINTF
  505. #elif defined(NETOS)
  506. #undef printf
  507. #define printf dc_log_printf
  508. #endif
  509. #endif
  510. #ifdef HAVE_FIPS
  511. #include <wolfssl/wolfcrypt/fips_test.h>
  512. static void myFipsCb(int ok, int err, const char* hash)
  513. {
  514. printf("%sin my Fips callback, ok = %d, err = %d\n",
  515. ok ? info_prefix : err_prefix, ok, err);
  516. printf("%smessage = %s\n", ok ? info_prefix : err_prefix,
  517. wc_GetErrorString(err));
  518. printf("%shash = %s\n", ok ? info_prefix : err_prefix, hash);
  519. if (err == WC_NO_ERR_TRACE(IN_CORE_FIPS_E)) {
  520. printf("%sIn core integrity hash check failure, copy above hash\n",
  521. err_prefix);
  522. printf("%sinto verifyCore[] in fips_test.c and rebuild\n",
  523. err_prefix);
  524. }
  525. }
  526. #endif
  527. #ifdef WOLFSSL_STATIC_MEMORY
  528. static WOLFSSL_HEAP_HINT* HEAP_HINT;
  529. #else
  530. #define HEAP_HINT NULL
  531. #endif /* WOLFSSL_STATIC_MEMORY */
  532. #ifndef EXIT_FAILURE
  533. #define EXIT_FAILURE 1
  534. #endif
  535. #undef LIBCALL_CHECK_RET
  536. #if defined(NO_STDIO_FILESYSTEM) || defined(NO_ERROR_STRINGS) || \
  537. defined(NO_MAIN_DRIVER) || defined(BENCH_EMBEDDED)
  538. #define LIBCALL_CHECK_RET(...) __VA_ARGS__
  539. #else
  540. #define LIBCALL_CHECK_RET(...) do { \
  541. int _libcall_ret = (__VA_ARGS__); \
  542. if (_libcall_ret < 0) { \
  543. printf("%s%s L%d error %d for \"%s\"\n", \
  544. err_prefix, __FILE__, __LINE__, \
  545. errno, #__VA_ARGS__); \
  546. XFFLUSH(stdout); \
  547. _exit(1); \
  548. } \
  549. } while(0)
  550. #endif
  551. #undef THREAD_CHECK_RET
  552. #define THREAD_CHECK_RET(...) do { \
  553. int _thread_ret = (__VA_ARGS__); \
  554. if (_thread_ret != 0) { \
  555. errno = _thread_ret; \
  556. printf("%s%s L%d error %d for \"%s\"\n", \
  557. err_prefix, __FILE__, __LINE__, \
  558. _thread_ret, #__VA_ARGS__); \
  559. XFFLUSH(stdout); \
  560. _exit(1); \
  561. } \
  562. } while(0)
  563. /* optional macro to add sleep between tests */
  564. #ifndef TEST_SLEEP
  565. /* stub the sleep macro */
  566. #define TEST_SLEEP() WC_DO_NOTHING
  567. #endif
  568. #define TEST_STRING "Everyone gets Friday off."
  569. #define TEST_STRING_SZ 25
  570. /* Bit values for each algorithm that is able to be benchmarked.
  571. * Common grouping of algorithms also.
  572. * Each algorithm has a unique value for its type e.g. cipher.
  573. */
  574. /* Cipher algorithms. */
  575. #define BENCH_AES_CBC 0x00000001
  576. #define BENCH_AES_GCM 0x00000002
  577. #define BENCH_AES_ECB 0x00000004
  578. #define BENCH_AES_XTS 0x00000008
  579. #define BENCH_AES_CTR 0x00000010
  580. #define BENCH_AES_CCM 0x00000020
  581. #define BENCH_CAMELLIA 0x00000100
  582. #define BENCH_ARC4 0x00000200
  583. #define BENCH_CHACHA20 0x00001000
  584. #define BENCH_CHACHA20_POLY1305 0x00002000
  585. #define BENCH_DES 0x00004000
  586. #define BENCH_AES_CFB 0x00010000
  587. #define BENCH_AES_OFB 0x00020000
  588. #define BENCH_AES_SIV 0x00040000
  589. #define BENCH_SM4_CBC 0x00080000
  590. #define BENCH_SM4_GCM 0x00100000
  591. #define BENCH_SM4_CCM 0x00200000
  592. #define BENCH_SM4 (BENCH_SM4_CBC | BENCH_SM4_GCM | BENCH_SM4_CCM)
  593. /* Digest algorithms. */
  594. #define BENCH_MD5 0x00000001
  595. #define BENCH_POLY1305 0x00000002
  596. #define BENCH_SHA 0x00000004
  597. #define BENCH_SHA224 0x00000010
  598. #define BENCH_SHA256 0x00000020
  599. #define BENCH_SHA384 0x00000040
  600. #define BENCH_SHA512 0x00000080
  601. #define BENCH_SHA2 (BENCH_SHA224 | BENCH_SHA256 | \
  602. BENCH_SHA384 | BENCH_SHA512)
  603. #define BENCH_SHA3_224 0x00000100
  604. #define BENCH_SHA3_256 0x00000200
  605. #define BENCH_SHA3_384 0x00000400
  606. #define BENCH_SHA3_512 0x00000800
  607. #define BENCH_SHA3 (BENCH_SHA3_224 | BENCH_SHA3_256 | \
  608. BENCH_SHA3_384 | BENCH_SHA3_512)
  609. #define BENCH_SHAKE128 0x00001000
  610. #define BENCH_SHAKE256 0x00002000
  611. #define BENCH_SHAKE (BENCH_SHAKE128 | BENCH_SHAKE256)
  612. #define BENCH_RIPEMD 0x00004000
  613. #define BENCH_BLAKE2B 0x00008000
  614. #define BENCH_BLAKE2S 0x00010000
  615. #define BENCH_SM3 0x00020000
  616. /* MAC algorithms. */
  617. #define BENCH_CMAC 0x00000001
  618. #define BENCH_HMAC_MD5 0x00000002
  619. #define BENCH_HMAC_SHA 0x00000004
  620. #define BENCH_HMAC_SHA224 0x00000010
  621. #define BENCH_HMAC_SHA256 0x00000020
  622. #define BENCH_HMAC_SHA384 0x00000040
  623. #define BENCH_HMAC_SHA512 0x00000080
  624. #define BENCH_HMAC (BENCH_HMAC_MD5 | BENCH_HMAC_SHA | \
  625. BENCH_HMAC_SHA224 | BENCH_HMAC_SHA256 | \
  626. BENCH_HMAC_SHA384 | BENCH_HMAC_SHA512)
  627. #define BENCH_PBKDF2 0x00000100
  628. #define BENCH_SIPHASH 0x00000200
  629. /* KDF algorithms */
  630. #define BENCH_SRTP_KDF 0x00000001
  631. /* Asymmetric algorithms. */
  632. #define BENCH_RSA_KEYGEN 0x00000001
  633. #define BENCH_RSA 0x00000002
  634. #define BENCH_RSA_SZ 0x00000004
  635. #define BENCH_DH 0x00000010
  636. #define BENCH_ECC_MAKEKEY 0x00001000
  637. #define BENCH_ECC 0x00002000
  638. #define BENCH_ECC_ENCRYPT 0x00004000
  639. #define BENCH_ECC_ALL 0x00008000
  640. #define BENCH_CURVE25519_KEYGEN 0x00010000
  641. #define BENCH_CURVE25519_KA 0x00020000
  642. #define BENCH_ED25519_KEYGEN 0x00040000
  643. #define BENCH_ED25519_SIGN 0x00080000
  644. #define BENCH_CURVE448_KEYGEN 0x00100000
  645. #define BENCH_CURVE448_KA 0x00200000
  646. #define BENCH_ED448_KEYGEN 0x00400000
  647. #define BENCH_ED448_SIGN 0x00800000
  648. #define BENCH_ECC_P256 0x01000000
  649. #define BENCH_ECC_P384 0x02000000
  650. #define BENCH_ECC_P521 0x04000000
  651. #define BENCH_SM2 0x08000000
  652. #define BENCH_ECCSI_KEYGEN 0x00000020
  653. #define BENCH_ECCSI_PAIRGEN 0x00000040
  654. #define BENCH_ECCSI_VALIDATE 0x00000080
  655. #define BENCH_ECCSI 0x00000400
  656. #define BENCH_SAKKE_KEYGEN 0x10000000
  657. #define BENCH_SAKKE_RSKGEN 0x20000000
  658. #define BENCH_SAKKE_VALIDATE 0x40000000
  659. #define BENCH_SAKKE 0x80000000
  660. /* Post-Quantum Asymmetric algorithms. */
  661. #define BENCH_KYBER512 0x00000020
  662. #define BENCH_KYBER768 0x00000040
  663. #define BENCH_KYBER1024 0x00000080
  664. #define BENCH_KYBER (BENCH_KYBER512 | BENCH_KYBER768 | \
  665. BENCH_KYBER1024)
  666. #define BENCH_ML_KEM_512 0x00000020
  667. #define BENCH_ML_KEM_768 0x00000040
  668. #define BENCH_ML_KEM_1024 0x00000080
  669. #define BENCH_ML_KEM (BENCH_ML_KEM_512 | BENCH_ML_KEM_768 | \
  670. BENCH_ML_KEM_1024)
  671. #define BENCH_FALCON_LEVEL1_SIGN 0x00000001
  672. #define BENCH_FALCON_LEVEL5_SIGN 0x00000002
  673. #define BENCH_DILITHIUM_LEVEL2_SIGN 0x04000000
  674. #define BENCH_DILITHIUM_LEVEL3_SIGN 0x08000000
  675. #define BENCH_DILITHIUM_LEVEL5_SIGN 0x10000000
  676. #define BENCH_ML_DSA_44_SIGN 0x04000000
  677. #define BENCH_ML_DSA_65_SIGN 0x08000000
  678. #define BENCH_ML_DSA_87_SIGN 0x10000000
  679. #define BENCH_ML_DSA_SIGN (BENCH_ML_DSA_44_SIGN | \
  680. BENCH_ML_DSA_65_SIGN | \
  681. BENCH_ML_DSA_87_SIGN)
  682. /* Post-Quantum Asymmetric algorithms. (Part 2) */
  683. #define BENCH_SPHINCS_FAST_LEVEL1_SIGN 0x00000001
  684. #define BENCH_SPHINCS_FAST_LEVEL3_SIGN 0x00000002
  685. #define BENCH_SPHINCS_FAST_LEVEL5_SIGN 0x00000004
  686. #define BENCH_SPHINCS_SMALL_LEVEL1_SIGN 0x00000008
  687. #define BENCH_SPHINCS_SMALL_LEVEL3_SIGN 0x00000010
  688. #define BENCH_SPHINCS_SMALL_LEVEL5_SIGN 0x00000020
  689. /* Post-Quantum Stateful Hash-Based sig algorithms. */
  690. #define BENCH_LMS_HSS 0x00000001
  691. #define BENCH_XMSS_XMSSMT_SHA256 0x00000002
  692. #define BENCH_XMSS_XMSSMT_SHA512 0x00000004
  693. #define BENCH_XMSS_XMSSMT_SHAKE128 0x00000008
  694. #define BENCH_XMSS_XMSSMT_SHAKE256 0x00000010
  695. #ifndef NO_SHA256
  696. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA256
  697. #elif defined(WOLFSSL_SHA512)
  698. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHA512
  699. #elif defined(WOLFSSL_SHAKE128)
  700. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE128
  701. #elif defined(WOLFSSL_SHAKE256)
  702. #define BENCH_XMSS_XMSSMT BENCH_XMSS_XMSSMT_SHAKE256
  703. #else
  704. #define BENCH_XMSS_XMSSMT 0x00000000
  705. #endif
  706. /* Other */
  707. #define BENCH_RNG 0x00000001
  708. #define BENCH_SCRYPT 0x00000002
  709. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  710. /* Define AES_AUTH_ADD_SZ already here, since it's used in the
  711. * static declaration of `bench_Usage_msg1`. */
  712. #if !defined(AES_AUTH_ADD_SZ) && \
  713. defined(STM32_CRYPTO) && !defined(STM32_AESGCM_PARTIAL) || \
  714. defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  715. /* For STM32 use multiple of 4 to leverage crypto hardware
  716. * Xilinx Versal requires to use multiples of 16 bytes */
  717. #define AES_AUTH_ADD_SZ 16
  718. #endif
  719. #ifndef AES_AUTH_ADD_SZ
  720. #define AES_AUTH_ADD_SZ 13
  721. #endif
  722. #endif
  723. #if (defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)) || \
  724. (defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY))
  725. #define BENCH_PQ_STATEFUL_HBS
  726. #endif
  727. /* Benchmark all compiled in algorithms.
  728. * When 1, ignore other benchmark algorithm values.
  729. * 0, only benchmark algorithm values set.
  730. */
  731. static int bench_all = 1;
  732. /* Cipher algorithms to benchmark. */
  733. static word32 bench_cipher_algs = 0;
  734. /* Digest algorithms to benchmark. */
  735. static word32 bench_digest_algs = 0;
  736. /* MAC algorithms to benchmark. */
  737. static word32 bench_mac_algs = 0;
  738. /* KDF algorithms to benchmark. */
  739. static word32 bench_kdf_algs = 0;
  740. /* Asymmetric algorithms to benchmark. */
  741. static word32 bench_asym_algs = 0;
  742. /* Post-Quantum Asymmetric algorithms to benchmark. */
  743. static word32 bench_pq_asym_algs = 0;
  744. /* Post-Quantum Asymmetric algorithms to benchmark. (Part 2)*/
  745. static word32 bench_pq_asym_algs2 = 0;
  746. /* Other cryptographic algorithms to benchmark. */
  747. static word32 bench_other_algs = 0;
  748. /* Post-Quantum Stateful Hash-Based sig algorithms to benchmark. */
  749. static word32 bench_pq_hash_sig_algs = 0;
  750. #if !defined(WOLFSSL_BENCHMARK_ALL) && !defined(NO_MAIN_DRIVER)
  751. /* The mapping of command line option to bit values. */
  752. typedef struct bench_alg {
  753. /* Command line option string. */
  754. const char* str;
  755. /* Bit values to set. */
  756. word32 val;
  757. } bench_alg;
  758. #ifndef MAIN_NO_ARGS
  759. /* All recognized cipher algorithm choosing command line options. */
  760. static const bench_alg bench_cipher_opt[] = {
  761. { "-cipher", 0xffffffff },
  762. #ifdef HAVE_AES_CBC
  763. { "-aes-cbc", BENCH_AES_CBC },
  764. #endif
  765. #ifdef HAVE_AESGCM
  766. { "-aes-gcm", BENCH_AES_GCM },
  767. #endif
  768. #ifdef WOLFSSL_AES_DIRECT
  769. { "-aes-ecb", BENCH_AES_ECB },
  770. #endif
  771. #ifdef WOLFSSL_AES_XTS
  772. { "-aes-xts", BENCH_AES_XTS },
  773. #endif
  774. #ifdef WOLFSSL_AES_CFB
  775. { "-aes-cfb", BENCH_AES_CFB },
  776. #endif
  777. #ifdef WOLFSSL_AES_OFB
  778. { "-aes-ofb", BENCH_AES_OFB },
  779. #endif
  780. #ifdef WOLFSSL_AES_COUNTER
  781. { "-aes-ctr", BENCH_AES_CTR },
  782. #endif
  783. #ifdef HAVE_AESCCM
  784. { "-aes-ccm", BENCH_AES_CCM },
  785. #endif
  786. #ifdef WOLFSSL_AES_SIV
  787. { "-aes-siv", BENCH_AES_SIV },
  788. #endif
  789. #ifdef HAVE_CAMELLIA
  790. { "-camellia", BENCH_CAMELLIA },
  791. #endif
  792. #ifndef NO_RC4
  793. { "-arc4", BENCH_ARC4 },
  794. #endif
  795. #ifdef HAVE_CHACHA
  796. { "-chacha20", BENCH_CHACHA20 },
  797. #endif
  798. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  799. { "-chacha20-poly1305", BENCH_CHACHA20_POLY1305 },
  800. #endif
  801. #ifdef WOLFSSL_SM4_CBC
  802. { "-sm4-cbc", BENCH_SM4_CBC },
  803. #endif
  804. #ifdef WOLFSSL_SM4_GCM
  805. { "-sm4-gcm", BENCH_SM4_GCM },
  806. #endif
  807. #ifdef WOLFSSL_SM4_CCM
  808. { "-sm4-ccm", BENCH_SM4_CCM },
  809. #endif
  810. #ifdef WOLFSSL_SM4
  811. { "-sm4", BENCH_SM4 },
  812. #endif
  813. #ifndef NO_DES3
  814. { "-des", BENCH_DES },
  815. #endif
  816. { NULL, 0 }
  817. };
  818. /* All recognized digest algorithm choosing command line options. */
  819. static const bench_alg bench_digest_opt[] = {
  820. { "-digest", 0xffffffff },
  821. #ifndef NO_MD5
  822. { "-md5", BENCH_MD5 },
  823. #endif
  824. #ifdef HAVE_POLY1305
  825. { "-poly1305", BENCH_POLY1305 },
  826. #endif
  827. #ifndef NO_SHA
  828. { "-sha", BENCH_SHA },
  829. #endif
  830. #if defined(WOLFSSL_SHA224) || !defined(NO_SHA256) || defined(WOLFSSL_SHA384) \
  831. || defined(WOLFSSL_SHA512)
  832. { "-sha2", BENCH_SHA2 },
  833. #endif
  834. #ifdef WOLFSSL_SHA224
  835. { "-sha224", BENCH_SHA224 },
  836. #endif
  837. #ifndef NO_SHA256
  838. { "-sha256", BENCH_SHA256 },
  839. #endif
  840. #ifdef WOLFSSL_SHA384
  841. { "-sha384", BENCH_SHA384 },
  842. #endif
  843. #ifdef WOLFSSL_SHA512
  844. { "-sha512", BENCH_SHA512 },
  845. #endif
  846. #ifdef WOLFSSL_SHA3
  847. { "-sha3", BENCH_SHA3 },
  848. #ifndef WOLFSSL_NOSHA3_224
  849. { "-sha3-224", BENCH_SHA3_224 },
  850. #endif
  851. #ifndef WOLFSSL_NOSHA3_256
  852. { "-sha3-256", BENCH_SHA3_256 },
  853. #endif
  854. #ifndef WOLFSSL_NOSHA3_384
  855. { "-sha3-384", BENCH_SHA3_384 },
  856. #endif
  857. #ifndef WOLFSSL_NOSHA3_512
  858. { "-sha3-512", BENCH_SHA3_512 },
  859. #endif
  860. #if defined(WOLFSSL_SHAKE128) || defined(WOLFSSL_SHAKE256)
  861. { "-shake", BENCH_SHAKE },
  862. #endif
  863. #ifdef WOLFSSL_SHAKE128
  864. { "-shake128", BENCH_SHAKE128 },
  865. #endif
  866. #ifdef WOLFSSL_SHAKE256
  867. { "-shake256", BENCH_SHAKE256 },
  868. #endif
  869. #endif
  870. #ifdef WOLFSSL_SM3
  871. { "-sm3", BENCH_SM3 },
  872. #endif
  873. #ifdef WOLFSSL_RIPEMD
  874. { "-ripemd", BENCH_RIPEMD },
  875. #endif
  876. #ifdef HAVE_BLAKE2
  877. { "-blake2b", BENCH_BLAKE2B },
  878. #endif
  879. #ifdef HAVE_BLAKE2S
  880. { "-blake2s", BENCH_BLAKE2S },
  881. #endif
  882. { NULL, 0 }
  883. };
  884. /* All recognized MAC algorithm choosing command line options. */
  885. static const bench_alg bench_mac_opt[] = {
  886. { "-mac", 0xffffffff },
  887. #ifdef WOLFSSL_CMAC
  888. { "-cmac", BENCH_CMAC },
  889. #endif
  890. #ifndef NO_HMAC
  891. { "-hmac", BENCH_HMAC },
  892. #ifndef NO_MD5
  893. { "-hmac-md5", BENCH_HMAC_MD5 },
  894. #endif
  895. #ifndef NO_SHA
  896. { "-hmac-sha", BENCH_HMAC_SHA },
  897. #endif
  898. #ifdef WOLFSSL_SHA224
  899. { "-hmac-sha224", BENCH_HMAC_SHA224 },
  900. #endif
  901. #ifndef NO_SHA256
  902. { "-hmac-sha256", BENCH_HMAC_SHA256 },
  903. #endif
  904. #ifdef WOLFSSL_SHA384
  905. { "-hmac-sha384", BENCH_HMAC_SHA384 },
  906. #endif
  907. #ifdef WOLFSSL_SHA512
  908. { "-hmac-sha512", BENCH_HMAC_SHA512 },
  909. #endif
  910. #ifndef NO_PWDBASED
  911. { "-pbkdf2", BENCH_PBKDF2 },
  912. #endif
  913. #endif
  914. #ifdef WOLFSSL_SIPHASH
  915. { "-siphash", BENCH_SIPHASH },
  916. #endif
  917. { NULL, 0 }
  918. };
  919. /* All recognized KDF algorithm choosing command line options. */
  920. static const bench_alg bench_kdf_opt[] = {
  921. { "-kdf", 0xffffffff },
  922. #ifdef WC_SRTP_KDF
  923. { "-srtp-kdf", BENCH_SRTP_KDF },
  924. #endif
  925. { NULL, 0 }
  926. };
  927. /* All recognized asymmetric algorithm choosing command line options. */
  928. static const bench_alg bench_asym_opt[] = {
  929. { "-asym", 0xffffffff },
  930. #ifndef NO_RSA
  931. #ifdef WOLFSSL_KEY_GEN
  932. { "-rsa-kg", BENCH_RSA_KEYGEN },
  933. #endif
  934. { "-rsa", BENCH_RSA },
  935. #ifdef WOLFSSL_KEY_GEN
  936. { "-rsa-sz", BENCH_RSA_SZ },
  937. #endif
  938. #endif
  939. #ifndef NO_DH
  940. { "-dh", BENCH_DH },
  941. #endif
  942. #ifdef HAVE_ECC
  943. { "-ecc-kg", BENCH_ECC_MAKEKEY },
  944. { "-ecc", BENCH_ECC },
  945. #ifdef HAVE_ECC_ENCRYPT
  946. { "-ecc-enc", BENCH_ECC_ENCRYPT },
  947. #endif
  948. { "-ecc-all", BENCH_ECC_ALL },
  949. #endif
  950. #ifdef WOLFSSL_SM2
  951. { "-sm2", BENCH_SM2 },
  952. #endif
  953. #ifdef HAVE_CURVE25519
  954. { "-curve25519-kg", BENCH_CURVE25519_KEYGEN },
  955. #ifdef HAVE_CURVE25519_SHARED_SECRET
  956. { "-x25519", BENCH_CURVE25519_KA },
  957. #endif
  958. #endif
  959. #ifdef HAVE_ED25519
  960. { "-ed25519-kg", BENCH_ED25519_KEYGEN },
  961. { "-ed25519", BENCH_ED25519_SIGN },
  962. #endif
  963. #ifdef HAVE_CURVE448
  964. { "-curve448-kg", BENCH_CURVE448_KEYGEN },
  965. #ifdef HAVE_CURVE448_SHARED_SECRET
  966. { "-x448", BENCH_CURVE448_KA },
  967. #endif
  968. #endif
  969. #ifdef HAVE_ED448
  970. { "-ed448-kg", BENCH_ED448_KEYGEN },
  971. { "-ed448", BENCH_ED448_SIGN },
  972. #endif
  973. #ifdef WOLFCRYPT_HAVE_ECCSI
  974. { "-eccsi-kg", BENCH_ECCSI_KEYGEN },
  975. { "-eccsi-pair", BENCH_ECCSI_PAIRGEN },
  976. { "-eccsi-val", BENCH_ECCSI_VALIDATE },
  977. { "-eccsi", BENCH_ECCSI },
  978. #endif
  979. #ifdef WOLFCRYPT_HAVE_SAKKE
  980. { "-sakke-kg", BENCH_SAKKE_KEYGEN },
  981. { "-sakke-rsk", BENCH_SAKKE_RSKGEN },
  982. { "-sakke-val", BENCH_SAKKE_VALIDATE },
  983. { "-sakke", BENCH_SAKKE },
  984. #endif
  985. { NULL, 0 }
  986. };
  987. /* All recognized other cryptographic algorithm choosing command line options.
  988. */
  989. static const bench_alg bench_other_opt[] = {
  990. { "-other", 0xffffffff },
  991. #ifndef WC_NO_RNG
  992. { "-rng", BENCH_RNG },
  993. #endif
  994. #ifdef HAVE_SCRYPT
  995. { "-scrypt", BENCH_SCRYPT },
  996. #endif
  997. { NULL, 0}
  998. };
  999. #endif /* MAIN_NO_ARGS */
  1000. #endif /* !WOLFSSL_BENCHMARK_ALL && !NO_MAIN_DRIVER */
  1001. #if defined(BENCH_PQ_STATEFUL_HBS)
  1002. typedef struct bench_pq_hash_sig_alg {
  1003. /* Command line option string. */
  1004. const char* str;
  1005. /* Bit values to set. */
  1006. word32 val;
  1007. } bench_pq_hash_sig_alg;
  1008. static const bench_pq_hash_sig_alg bench_pq_hash_sig_opt[] = {
  1009. { "-pq_hash_sig", 0xffffffff},
  1010. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  1011. { "-lms_hss", BENCH_LMS_HSS},
  1012. #endif
  1013. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  1014. { "-xmss_xmssmt", BENCH_XMSS_XMSSMT},
  1015. #ifdef WC_XMSS_SHA256
  1016. { "-xmss_xmssmt_sha256", BENCH_XMSS_XMSSMT_SHA256},
  1017. #endif
  1018. #ifdef WC_XMSS_SHA512
  1019. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  1020. { "-xmss_xmssmt_sha512", BENCH_XMSS_XMSSMT_SHA512},
  1021. #endif
  1022. #endif
  1023. #ifdef WC_XMSS_SHAKE128
  1024. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  1025. { "-xmss_xmssmt_shake128", BENCH_XMSS_XMSSMT_SHAKE128},
  1026. #endif
  1027. #endif
  1028. #ifdef WC_XMSS_SHAKE256
  1029. { "-xmss_xmssmt_shake256", BENCH_XMSS_XMSSMT_SHAKE256},
  1030. #endif
  1031. #endif
  1032. { NULL, 0}
  1033. };
  1034. #endif /* BENCH_PQ_STATEFUL_HBS */
  1035. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  1036. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  1037. /* The post-quantum-specific mapping of command line option to bit values and
  1038. * OQS name. */
  1039. typedef struct bench_pq_alg {
  1040. /* Command line option string. */
  1041. const char* str;
  1042. /* Bit values to set. */
  1043. word32 val;
  1044. } bench_pq_alg;
  1045. /* All recognized post-quantum asymmetric algorithm choosing command line
  1046. * options. */
  1047. static const bench_pq_alg bench_pq_asym_opt[] = {
  1048. { "-pq", 0xffffffff },
  1049. #ifdef WOLFSSL_HAVE_KYBER
  1050. { "-kyber", BENCH_KYBER },
  1051. { "-kyber512", BENCH_KYBER512 },
  1052. { "-kyber768", BENCH_KYBER768 },
  1053. { "-kyber1024", BENCH_KYBER1024 },
  1054. { "-ml-kem", BENCH_ML_KEM },
  1055. { "-ml-kem-512", BENCH_ML_KEM_512 },
  1056. { "-ml-kem-768", BENCH_ML_KEM_768 },
  1057. { "-ml-kem-1024", BENCH_ML_KEM_1024 },
  1058. #endif
  1059. #if defined(HAVE_FALCON)
  1060. { "-falcon_level1", BENCH_FALCON_LEVEL1_SIGN },
  1061. { "-falcon_level5", BENCH_FALCON_LEVEL5_SIGN },
  1062. #endif
  1063. #if defined(HAVE_DILITHIUM)
  1064. { "-dilithium_level2", BENCH_DILITHIUM_LEVEL2_SIGN },
  1065. { "-dilithium_level3", BENCH_DILITHIUM_LEVEL3_SIGN },
  1066. { "-dilithium_level5", BENCH_DILITHIUM_LEVEL5_SIGN },
  1067. { "-ml-dsa", BENCH_ML_DSA_SIGN },
  1068. { "-ml-dsa-44", BENCH_ML_DSA_44_SIGN },
  1069. { "-ml-dsa-65", BENCH_ML_DSA_65_SIGN },
  1070. { "-ml-dsa-87", BENCH_ML_DSA_87_SIGN },
  1071. #endif
  1072. { NULL, 0 }
  1073. };
  1074. #if defined(HAVE_SPHINCS)
  1075. /* All recognized post-quantum asymmetric algorithm choosing command line
  1076. * options. (Part 2) */
  1077. static const bench_pq_alg bench_pq_asym_opt2[] = {
  1078. { "-pq", 0xffffffff },
  1079. { "-sphincs_fast_level1", BENCH_SPHINCS_FAST_LEVEL1_SIGN },
  1080. { "-sphincs_fast_level3", BENCH_SPHINCS_FAST_LEVEL3_SIGN },
  1081. { "-sphincs_fast_level5", BENCH_SPHINCS_FAST_LEVEL5_SIGN },
  1082. { "-sphincs_small_level1", BENCH_SPHINCS_SMALL_LEVEL1_SIGN },
  1083. { "-sphincs_small_level3", BENCH_SPHINCS_SMALL_LEVEL3_SIGN },
  1084. { "-sphincs_small_level5", BENCH_SPHINCS_SMALL_LEVEL5_SIGN },
  1085. { NULL, 0, }
  1086. };
  1087. #endif /* HAVE_SPHINCS */
  1088. #endif
  1089. #ifdef HAVE_WNR
  1090. const char* wnrConfigFile = "wnr-example.conf";
  1091. #endif
  1092. #if defined(WOLFSSL_MDK_ARM)
  1093. extern XFILE wolfSSL_fopen(const char *fname, const char *mode);
  1094. #define fopen wolfSSL_fopen
  1095. #endif
  1096. static int lng_index = 0;
  1097. #ifndef NO_MAIN_DRIVER
  1098. #ifndef MAIN_NO_ARGS
  1099. static const char* bench_Usage_msg1[][25] = {
  1100. /* 0 English */
  1101. { "-? <num> Help, print this usage\n",
  1102. " 0: English, 1: Japanese\n",
  1103. "-csv Print terminal output in csv format\n",
  1104. "-base10 Display bytes as power of 10 (eg 1 kB = 1000 Bytes)\n",
  1105. "-no_aad No additional authentication data passed.\n",
  1106. "-aad_size <num> With <num> bytes of AAD.\n",
  1107. ("-all_aad With AAD length of 0, "
  1108. WC_STRINGIFY(AES_AUTH_ADD_SZ)
  1109. " and\n"
  1110. " (if set via -aad_size) <aad_size> bytes.\n"
  1111. ),
  1112. "-dgst_full Full digest operation performed.\n",
  1113. "-rsa_sign Measure RSA sign/verify instead of encrypt/decrypt.\n",
  1114. "<keySz> -rsa-sz\n Measure RSA <key size> performance.\n",
  1115. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1116. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1117. "-p256 Measure ECC using P-256 curve.\n",
  1118. "-p384 Measure ECC using P-384 curve.\n",
  1119. "-p521 Measure ECC using P-521 curve.\n",
  1120. "-ecc-all Bench all enabled ECC curves.\n",
  1121. "-<alg> Algorithm to benchmark. Available algorithms include:\n",
  1122. ("-lng <num> Display benchmark result by specified language.\n"
  1123. " 0: English, 1: Japanese\n"
  1124. ),
  1125. "<num> Size of block in bytes\n",
  1126. ("-blocks <num> Number of blocks. Can be used together with the "
  1127. "'Size of block'\n"
  1128. " option, but must be used after that one.\n"
  1129. ),
  1130. "-threads <num> Number of threads to run\n",
  1131. "-print Show benchmark stats summary\n",
  1132. "-hash_input <file> Input data to use for hash benchmarking\n",
  1133. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1134. "-min_runs <num> Specify minimum number of operation runs\n"
  1135. },
  1136. #ifndef NO_MULTIBYTE_PRINT
  1137. /* 1 Japanese */
  1138. { "-? <num> ヘルプ, 使い方を表示します。\n",
  1139. " 0: 英語、 1: 日本語\n",
  1140. "-csv csv 形式で端末に出力します。\n",
  1141. "-base10 バイトを10のべき乗で表示します。(例 1 kB = 1000 Bytes)\n",
  1142. "-no_aad 追加の認証データを使用しません.\n",
  1143. "-aad_size <num> TBD.\n",
  1144. "-all_aad TBD.\n",
  1145. "-dgst_full フルの digest 暗号操作を実施します。\n",
  1146. "-rsa_sign 暗号/復号化の代わりに RSA の署名/検証を測定します。\n",
  1147. "<keySz> -rsa-sz\n RSA <key size> の性能を測定します。\n",
  1148. "-ffhdhe2048 Measure DH using FFDHE 2048-bit parameters.\n",
  1149. "-ffhdhe3072 Measure DH using FFDHE 3072-bit parameters.\n",
  1150. "-p256 Measure ECC using P-256 curve.\n",
  1151. "-p384 Measure ECC using P-384 curve.\n",
  1152. "-p521 Measure ECC using P-521 curve.\n",
  1153. "-ecc-all Bench all enabled ECC curves.\n",
  1154. ("-<alg> アルゴリズムのベンチマークを実施します。\n"
  1155. " 利用可能なアルゴリズムは下記を含みます:\n"
  1156. ),
  1157. ("-lng <num> 指定された言語でベンチマーク結果を表示します。\n"
  1158. " 0: 英語、 1: 日本語\n"
  1159. ),
  1160. "<num> ブロックサイズをバイト単位で指定します。\n",
  1161. "-blocks <num> TBD.\n",
  1162. "-threads <num> 実行するスレッド数\n",
  1163. "-print ベンチマーク統計の要約を表示する\n",
  1164. /* TODO: translate below */
  1165. "-hash_input <file> Input data to use for hash benchmarking\n",
  1166. "-cipher_input <file> Input data to use for cipher benchmarking\n",
  1167. "-min_runs <num> Specify minimum number of operation runs\n"
  1168. },
  1169. #endif
  1170. };
  1171. #endif /* MAIN_NO_ARGS */
  1172. #endif
  1173. static const char* bench_result_words1[][4] = {
  1174. { "took",
  1175. #ifdef BENCH_MICROSECOND
  1176. "microseconds"
  1177. #else
  1178. "seconds"
  1179. #endif
  1180. , "Cycles per byte", NULL }, /* 0 English */
  1181. #ifndef NO_MULTIBYTE_PRINT
  1182. { "を" , "秒で処理", "1バイトあたりのサイクル数", NULL }, /* 1 Japanese */
  1183. #endif
  1184. };
  1185. #if !defined(NO_RSA) || \
  1186. defined(HAVE_ECC) || !defined(NO_DH) || defined(HAVE_ECC_ENCRYPT) || \
  1187. defined(HAVE_CURVE25519) || defined(HAVE_CURVE25519_SHARED_SECRET) || \
  1188. defined(HAVE_ED25519) || defined(HAVE_CURVE448) || \
  1189. defined(HAVE_CURVE448_SHARED_SECRET) || defined(HAVE_ED448) || \
  1190. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM)
  1191. static const char* bench_desc_words[][15] = {
  1192. /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  1193. {"public", "private", "key gen", "agree" , "sign", "verify", "encrypt", "decrypt", "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 0 English */
  1194. #ifndef NO_MULTIBYTE_PRINT
  1195. {"公開鍵", "秘密鍵" ,"鍵生成" , "鍵共有" , "署名", "検証" , "暗号化" , "復号化" , "rsk gen", "encap", "derive", "valid", "pair gen", "decap", NULL}, /* 1 Japanese */
  1196. #endif
  1197. };
  1198. #endif
  1199. #ifdef MULTI_VALUE_STATISTICS
  1200. static const char* bench_result_words3[][5] = {
  1201. /* 0 English */
  1202. { "max duration", "min duration" , "mean duration", "sd", NULL },
  1203. /* TODO: Add japenese version */
  1204. { "max duration", "min duration" , "mean duration", "sd", NULL }
  1205. };
  1206. #endif
  1207. #if defined(__GNUC__) && defined(__x86_64__) && !defined(NO_ASM) && !defined(WOLFSSL_SGX)
  1208. #define HAVE_GET_CYCLES
  1209. static WC_INLINE word64 get_intel_cycles(void);
  1210. static THREAD_LS_T word64 total_cycles;
  1211. #define INIT_CYCLE_COUNTER
  1212. #define BEGIN_INTEL_CYCLES total_cycles = get_intel_cycles();
  1213. #define END_INTEL_CYCLES total_cycles = get_intel_cycles() - total_cycles;
  1214. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1215. #define SHOW_INTEL_CYCLES(b, n, s) \
  1216. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), \
  1217. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1218. bench_result_words1[lng_index][2], \
  1219. FLT_FMT_PREC2_ARGS(6, 2, count == 0 ? 0 : \
  1220. (double)total_cycles / ((word64)count*(s))))
  1221. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1222. (void)XSNPRINTF((b) + XSTRLEN(b), (n) - XSTRLEN(b), FLT_FMT_PREC "," \
  1223. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, count == 0 ? 0 : \
  1224. (double)total_cycles / ((word64)count*(s))))
  1225. #elif defined(LINUX_CYCLE_COUNT)
  1226. #include <linux/perf_event.h>
  1227. #include <sys/syscall.h>
  1228. #include <unistd.h>
  1229. static THREAD_LS_T word64 begin_cycles;
  1230. static THREAD_LS_T word64 total_cycles;
  1231. static THREAD_LS_T int cycles = -1;
  1232. static THREAD_LS_T struct perf_event_attr atr;
  1233. #define INIT_CYCLE_COUNTER do { \
  1234. atr.type = PERF_TYPE_HARDWARE; \
  1235. atr.config = PERF_COUNT_HW_CPU_CYCLES; \
  1236. cycles = (int)syscall(__NR_perf_event_open, &atr, 0, -1, -1, 0); \
  1237. } while (0);
  1238. #define BEGIN_INTEL_CYCLES read(cycles, &begin_cycles, sizeof(begin_cycles));
  1239. #define END_INTEL_CYCLES do { \
  1240. read(cycles, &total_cycles, sizeof(total_cycles)); \
  1241. total_cycles = total_cycles - begin_cycles; \
  1242. } while (0);
  1243. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1244. #define SHOW_INTEL_CYCLES(b, n, s) \
  1245. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1246. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1247. bench_result_words1[lng_index][2], \
  1248. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / \
  1249. (count*s)))
  1250. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1251. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC "," \
  1252. STATS_CLAUSE_SEPARATOR, FLT_FMT_PREC_ARGS(6, (double)total_cycles \
  1253. / (count*s)))
  1254. #elif defined(SYNERGY_CYCLE_COUNT)
  1255. #include "hal_data.h"
  1256. static THREAD_LS_T word64 begin_cycles;
  1257. static THREAD_LS_T word64 total_cycles;
  1258. #define INIT_CYCLE_COUNTER
  1259. #define BEGIN_INTEL_CYCLES begin_cycles = DWT->CYCCNT = 0;
  1260. #define END_INTEL_CYCLES total_cycles = DWT->CYCCNT - begin_cycles;
  1261. /* s == size in bytes that 1 count represents, normally BENCH_SIZE */
  1262. #define SHOW_INTEL_CYCLES(b, n, s) \
  1263. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1264. " %s = " FLT_FMT_PREC2 STATS_CLAUSE_SEPARATOR, \
  1265. bench_result_words1[lng_index][2], \
  1266. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)))
  1267. #define SHOW_INTEL_CYCLES_CSV(b, n, s) \
  1268. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1269. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1270. #elif defined(WOLFSSL_ESPIDF)
  1271. /* TAG for ESP_LOGx() */
  1272. static const char* TAG = "wolfssl_benchmark";
  1273. static THREAD_LS_T word64 begin_cycles = 0;
  1274. static THREAD_LS_T word64 begin_cycles_ticks = 0;
  1275. static THREAD_LS_T word64 end_cycles = 0;
  1276. static THREAD_LS_T word64 total_cycles = 0;
  1277. /* the return value, as a global var */
  1278. static THREAD_LS_T word64 _esp_get_cycle_count_ex = 0;
  1279. /* the last value seen, adjusted for an overflow, as a global var */
  1280. static THREAD_LS_T word64 _esp_cpu_count_last = 0;
  1281. static THREAD_LS_T TickType_t last_tickCount = 0; /* last FreeRTOS value */
  1282. /* esp_get_cpu_benchmark_cycles(void):
  1283. *
  1284. * Architecture-independant CPU clock counter.
  1285. * WARNING: the hal UINT xthal_get_ccount() quietly rolls over. */
  1286. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void);
  1287. /* Some vars for debugging, compare ticks to cycles */
  1288. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1289. static THREAD_LS_T word64 _esp_cpu_timer_last = 0;
  1290. static THREAD_LS_T word64 _esp_cpu_timer_diff = 0;
  1291. static THREAD_LS_T word64 _xthal_get_ccount_exAlt = 0;
  1292. static THREAD_LS_T word64 _xthal_get_ccount_exDiff = 0;
  1293. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1294. /* The ESP32 (both Xtensa and RISC-V have raw CPU counters). */
  1295. #if ESP_IDF_VERSION_MAJOR >= 5
  1296. /* esp_cpu_set_cycle_count() introduced in ESP-IDF v5 */
  1297. #define HAVE_GET_CYCLES
  1298. #define INIT_CYCLE_COUNTER do { \
  1299. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1300. esp_cpu_set_cycle_count(0); \
  1301. } while (0);
  1302. #else
  1303. #define HAVE_GET_CYCLES
  1304. #define INIT_CYCLE_COUNTER do { \
  1305. ESP_LOGV(TAG, "INIT_CYCLE_COUNTER"); \
  1306. } while (0);
  1307. #endif
  1308. #define BEGIN_ESP_CYCLES do { \
  1309. ESP_LOGV(TAG, "BEGIN_ESP_CYCLES"); \
  1310. begin_cycles = esp_get_cpu_benchmark_cycles(); \
  1311. begin_cycles_ticks = xTaskGetTickCount(); \
  1312. } while (0);
  1313. /* since it rolls over, we have something that will tolerate one */
  1314. #define END_ESP_CYCLES \
  1315. end_cycles = esp_get_cpu_benchmark_cycles(); \
  1316. ESP_LOGV(TAG,"END_ESP_CYCLES %llu - %llu", \
  1317. end_cycles, \
  1318. begin_cycles \
  1319. ); \
  1320. total_cycles = (end_cycles - begin_cycles);
  1321. #define SHOW_ESP_CYCLES(b, n, s) \
  1322. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), \
  1323. " %s = " FLT_FMT_PREC2 "\n", \
  1324. bench_result_words1[lng_index][2], \
  1325. FLT_FMT_PREC2_ARGS(6, 2, (double)total_cycles / (count*s)) \
  1326. )
  1327. #define SHOW_ESP_CYCLES_CSV(b, n, s) \
  1328. (void)XSNPRINTF(b + XSTRLEN(b), n - XSTRLEN(b), FLT_FMT_PREC ",\n", \
  1329. FLT_FMT_PREC_ARGS(6, (double)total_cycles / (count*s)))
  1330. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1331. /* 64 bit, unisgned, absolute difference
  1332. * used in CPU cycle counter debug calcs. */
  1333. static uint64_t esp_cycle_abs_diff(uint64_t x, uint64_t y)
  1334. {
  1335. uint64_t ret;
  1336. ret = (x > y) ? (x - y) : (y - x);
  1337. return ret;
  1338. }
  1339. #endif
  1340. /* esp_get_cycle_count_ex() is a single-overflow-tolerant extension to
  1341. ** the Espressif `unsigned xthal_get_ccount()` (Xtensa) or
  1342. ** `esp_cpu_get_cycle_count` (RISC-V) which are known to overflow
  1343. ** at least once during full benchmark tests.
  1344. **
  1345. ** To test timing overflow, add a delay longer than max cycles:
  1346. ** vTaskDelay( (const TickType_t)(configTICK_RATE_HZ * 17 * 5) );
  1347. */
  1348. uint64_t esp_get_cycle_count_ex()
  1349. {
  1350. /* reminder: unsigned long long max = 18,446,744,073,709,551,615 */
  1351. /* unsigned int max = 4,294,967,295 */
  1352. uint64_t thisVal = 0; /* CPU counter, "this current value" as read. */
  1353. uint64_t thisIncrement = 0; /* The adjusted increment amount. */
  1354. uint64_t expected_diff = 0; /* FreeRTOS estimated expected CPU diff.*/
  1355. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1356. uint64_t tickCount = 0; /* Current rtos tick counter. */
  1357. uint64_t tickDiff = 0; /* Tick difference from last check. */
  1358. uint64_t tickBeginDiff = 0; /* Tick difference from beginning. */
  1359. #endif
  1360. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1361. uint64_t thisTimerVal = 0; /* Timer Value as alternate to compare */
  1362. uint64_t diffDiff = 0; /* Difference between CPU & Timer differences:
  1363. * (current - last) */
  1364. #endif
  1365. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1366. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1367. defined(CONFIG_IDF_TARGET_ESP32C6)
  1368. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1369. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer, &thisTimerVal));
  1370. thisTimerVal = thisTimerVal * RESOLUTION_SCALE;
  1371. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1372. #if ESP_IDF_VERSION_MAJOR >= 5
  1373. thisVal = esp_cpu_get_cycle_count();
  1374. #else
  1375. thisVal = cpu_hal_get_cycle_count();
  1376. #endif
  1377. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1378. thisVal = esp_cpu_get_cycle_count();
  1379. #elif defined(CONFIG_IDF_TARGET_ESP8266)
  1380. thisVal = esp_timer_get_time();
  1381. #else
  1382. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa?
  1383. * Calling current_time(1) to reset time causes thisVal overflow,
  1384. * on Xtensa, but not on RISC-V architecture. See also, below */
  1385. #if defined(CONFIG_IDF_TARGET_ESP8266) || (ESP_IDF_VERSION_MAJOR < 5)
  1386. #ifndef configCPU_CLOCK_HZ
  1387. /* esp_cpu_get_cycle_count not available in ESP-IDF v4 */
  1388. #define configCPU_CLOCK_HZ \
  1389. (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1390. #endif
  1391. /* There's no CPU counter on the ESP8266 (Tensilica). Using RTOS */
  1392. thisVal = (uint64_t)xTaskGetTickCount() *
  1393. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1394. #elif defined(__XTENSA__)
  1395. thisVal = esp_cpu_get_cycle_count();
  1396. #else
  1397. /* Not Tensilica(ESP8266), not Xtensa(ESP32/-S2/-S3, then RISC-V */
  1398. thisVal = xthal_get_ccount(); /* or esp_cpu_get_cycle_count(); */
  1399. #endif
  1400. #endif
  1401. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1402. {
  1403. tickCount = xTaskGetTickCount(); /* Our local FreeRTOS tick count */
  1404. tickDiff = tickCount - last_tickCount; /* ticks since bench start */
  1405. expected_diff = CPU_TICK_CYCLES * tickDiff; /* CPU expected count */
  1406. ESP_LOGV(TAG, "CPU_TICK_CYCLES = %d", (int)CPU_TICK_CYCLES);
  1407. ESP_LOGV(TAG, "tickCount = %llu", tickCount);
  1408. ESP_LOGV(TAG, "last_tickCount = " TFMT, last_tickCount);
  1409. ESP_LOGV(TAG, "tickDiff = %llu", tickDiff);
  1410. ESP_LOGV(TAG, "expected_diff1 = %llu", expected_diff);
  1411. }
  1412. #endif
  1413. /* If either thisVal is smaller than last (overflow), and/or the
  1414. * expected value calculated from FreeRTOS tick difference that would
  1415. * have never fit into an unsigned 32 bit integer anyhow... then we
  1416. * need to adjust thisVal to save. */
  1417. if ( (thisVal < _esp_cpu_count_last) || (expected_diff > UINT_MAX) )
  1418. {
  1419. /* Warning: we assume the return type of esp_cpu_get_cycle_count()
  1420. ** will always be unsigned int (or uint32_t) to add UINT_MAX.
  1421. **
  1422. ** NOTE for long duration between calls with multiple overflows:
  1423. **
  1424. ** WILL NOT BE DETECTED - the return value will be INCORRECT.
  1425. **
  1426. ** At this time no single test overflows. This is currently only a
  1427. ** concern for cumulative counts over multiple tests. As long
  1428. ** as well call xthal_get_ccount_ex() with no more than one
  1429. ** overflow CPU tick count, all will be well.
  1430. */
  1431. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1432. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccount overflow at "
  1433. "(%llu < %llu) adding UINT_MAX = %llu.",
  1434. thisVal, _esp_cpu_count_last, (uint64_t) UINT_MAX);
  1435. #endif
  1436. #if !defined(CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ) && \
  1437. !defined(CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ)
  1438. #error "CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ not found"
  1439. #endif
  1440. /* double check expected diff calc */
  1441. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1442. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1443. expected_diff = (CONFIG_ESP8266_DEFAULT_CPU_FREQ_MHZ
  1444. * MILLION_VALUE)
  1445. * tickDiff / configTICK_RATE_HZ;
  1446. #else
  1447. expected_diff = (CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * MILLION_VALUE)
  1448. * tickDiff / configTICK_RATE_HZ;
  1449. #endif
  1450. ESP_LOGI(TAG, "expected_diff2 = %llu", expected_diff);
  1451. #endif
  1452. if (expected_diff > UINT_MAX) {
  1453. /* The number of cycles expected from FreeRTOS ticks is
  1454. * greater than the maximum size of an unsigned 32-bit
  1455. * integer, meaning multiple overflows occurred. */
  1456. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1457. ESP_LOGW(TAG, "expected_diff > UINT_MAX (%u)", UINT_MAX);
  1458. #endif
  1459. thisVal += expected_diff; /* FreeRTOS calc to our 64 bit val */
  1460. }
  1461. else {
  1462. thisVal += (word64)UINT_MAX; /* add 32 bit max to our 64 bit */
  1463. }
  1464. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1465. {
  1466. tickBeginDiff = tickCount - begin_cycles_ticks;
  1467. ESP_LOGI(TAG, "begin_cycles_ticks = %llu", begin_cycles_ticks);
  1468. ESP_LOGI(TAG, "tickDiff = %llu", tickDiff);
  1469. ESP_LOGI(TAG, "expected_diff = %llu", expected_diff);
  1470. ESP_LOGI(TAG, "tickBeginDiff = %llu", tickBeginDiff);
  1471. ESP_LOGW(TAG, WOLFSSL_ESPIDF_BLANKLINE_MESSAGE);
  1472. }
  1473. #endif
  1474. }
  1475. else {
  1476. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1477. ESP_LOGI(TAG, "thisVal, read CPU = %llu", thisVal);
  1478. #endif
  1479. } /* if thisVal adjustment check */
  1480. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1481. if (thisTimerVal < _esp_cpu_timer_last)
  1482. {
  1483. ESP_LOGW(TAG, "Alert: Detected xthal_get_ccountAlt overflow, "
  1484. "adding %ull", UINT_MAX);
  1485. thisTimerVal += (word64)UINT_MAX;
  1486. }
  1487. /* Check an alternate counter using a timer */
  1488. _esp_cpu_timer_diff = esp_cycle_abs_diff(_esp_cpu_count_last, _esp_cpu_timer_last);
  1489. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1490. /* Adjust our actual returned value that takes into account overflow,
  1491. * increment 64 bit extended total by this 32 bit differential: */
  1492. thisIncrement = (thisVal - _esp_cpu_count_last);
  1493. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1494. ESP_LOGI(TAG, "thisIncrement = %llu", thisIncrement);
  1495. #endif
  1496. /* Add our adjustment, taking into account overflows (see above) */
  1497. _esp_get_cycle_count_ex += thisIncrement;
  1498. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1499. _xthal_get_ccount_exDiff = esp_cycle_abs_diff(_esp_get_cycle_count_ex, _xthal_get_ccount_exAlt);
  1500. _xthal_get_ccount_exAlt += (thisTimerVal - _esp_cpu_timer_last);
  1501. diffDiff = esp_cycle_abs_diff(_xthal_get_ccount_exDiff, _esp_cpu_timer_diff);
  1502. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1503. /* all of this took some time, so reset the "last seen" value
  1504. * for the next measurement. */
  1505. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  1506. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  1507. defined(CONFIG_IDF_TARGET_ESP32C6)
  1508. {
  1509. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  1510. ESP_ERROR_CHECK(gptimer_get_raw_count(esp_gptimer,
  1511. &_esp_cpu_timer_last));
  1512. ESP_LOGI(TAG, "thisVal = %llu", thisVal);
  1513. ESP_LOGI(TAG, "thisTimerVal = %llu", thisTimerVal);
  1514. ESP_LOGI(TAG, "diffDiff = %llu", diffDiff);
  1515. ESP_LOGI(TAG, "_xthal_get_ccount_exDiff = %llu", _xthal_get_ccount_exDiff);
  1516. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  1517. #if ESP_IDF_VERSION_MAJOR >= 5
  1518. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1519. #else
  1520. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  1521. #endif
  1522. ESP_LOGV(TAG, "_xthal_get_ccount_last = %llu", _esp_cpu_count_last);
  1523. }
  1524. #elif defined(CONFIG_IDF_TARGET_ESP32H2)
  1525. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1526. #else
  1527. /* TODO: Why doesn't esp_cpu_get_cycle_count work for Xtensa
  1528. * when resetting CPU cycle counter? FreeRTOS tick collision?
  1529. * thisVal = esp_cpu_get_cycle_count(); See also, above
  1530. * or thisVal = xthal_get_ccount(); */
  1531. #if defined(CONFIG_IDF_TARGET_ESP8266)
  1532. /* There's no CPU counter on the ESP8266, so we'll estimate
  1533. * cycles based on defined CPU frequency from sdkconfig and
  1534. * the RTOS tick frequency */
  1535. _esp_cpu_count_last = (uint64_t)xTaskGetTickCount() *
  1536. (uint64_t)(configCPU_CLOCK_HZ / CONFIG_FREERTOS_HZ);
  1537. #elif ESP_IDF_VERSION_MAJOR < 5
  1538. _esp_cpu_count_last = xthal_get_ccount();
  1539. #else
  1540. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  1541. #endif
  1542. #endif
  1543. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  1544. ESP_LOGI(TAG, "_esp_cpu_count_last = %llu", _esp_cpu_count_last);
  1545. #endif
  1546. /* Return the 64 bit extended total from 32 bit counter. */
  1547. return _esp_get_cycle_count_ex;
  1548. } /* esp_get_cycle_count_ex for esp_get_cpu_benchmark_cycles() */
  1549. /* implement other architecture cycle counters here */
  1550. #else
  1551. /* if we don't know the platform, it is unlikely we can count CPU cycles */
  1552. #undef HAVE_GET_CYCLES
  1553. #define INIT_CYCLE_COUNTER
  1554. #define BEGIN_INTEL_CYCLES
  1555. #define END_INTEL_CYCLES
  1556. #ifdef MULTI_VALUE_STATISTICS
  1557. #define SHOW_INTEL_CYCLES(b, n, s) WC_DO_NOTHING
  1558. #define SHOW_INTEL_CYCLES_CSV(b, n, s) WC_DO_NOTHING
  1559. #else
  1560. #define SHOW_INTEL_CYCLES(b, n, s) b[XSTRLEN(b)] = '\n'
  1561. #define SHOW_INTEL_CYCLES_CSV(b, n, s) b[XSTRLEN(b)] = '\n'
  1562. #endif
  1563. #endif
  1564. /* determine benchmark buffer to use (if NO_FILESYSTEM) */
  1565. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  1566. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  1567. #define USE_CERT_BUFFERS_2048 /* default to 2048 */
  1568. #endif
  1569. #if defined(USE_CERT_BUFFERS_1024) || defined(USE_CERT_BUFFERS_2048) || \
  1570. defined(USE_CERT_BUFFERS_3072) || defined(USE_CERT_BUFFERS_4096) || \
  1571. !defined(NO_DH)
  1572. /* include test cert and key buffers for use with NO_FILESYSTEM */
  1573. #include <wolfssl/certs_test.h>
  1574. #endif
  1575. #if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
  1576. #include <wolfssl/wolfcrypt/blake2.h>
  1577. #endif
  1578. #ifdef _MSC_VER
  1579. /* 4996 warning to use MS extensions e.g., strcpy_s instead of strncpy */
  1580. #pragma warning(disable: 4996)
  1581. #endif
  1582. #ifdef WOLFSSL_CURRTIME_REMAP
  1583. #define current_time WOLFSSL_CURRTIME_REMAP
  1584. #else
  1585. double current_time(int reset);
  1586. #endif
  1587. #ifdef LINUX_RUSAGE_UTIME
  1588. static void check_for_excessive_stime(const char *desc,
  1589. const char *desc_extra);
  1590. #endif
  1591. #if !defined(WC_NO_RNG) && \
  1592. ((!defined(NO_RSA) && !defined(WOLFSSL_RSA_VERIFY_ONLY)) \
  1593. || !defined(NO_DH) || defined(WOLFSSL_KEY_GEN) || defined(HAVE_ECC) \
  1594. || defined(HAVE_CURVE25519) || defined(HAVE_ED25519) \
  1595. || defined(HAVE_CURVE448) || defined(HAVE_ED448) \
  1596. || defined(WOLFSSL_HAVE_KYBER))
  1597. #define HAVE_LOCAL_RNG
  1598. static THREAD_LS_T WC_RNG gRng;
  1599. #define GLOBAL_RNG &gRng
  1600. #else
  1601. #define GLOBAL_RNG NULL
  1602. #endif
  1603. #if defined(HAVE_ED25519) || defined(HAVE_CURVE25519) || \
  1604. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1605. defined(HAVE_ECC) || !defined(NO_DH) || \
  1606. !defined(NO_RSA) || defined(HAVE_SCRYPT) || \
  1607. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1608. defined(WOLFSSL_HAVE_LMS)
  1609. #define BENCH_ASYM
  1610. #endif
  1611. #if defined(BENCH_ASYM)
  1612. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  1613. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  1614. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  1615. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  1616. defined(WOLFSSL_HAVE_LMS)
  1617. static const char* bench_result_words2[][5] = {
  1618. #ifdef BENCH_MICROSECOND
  1619. { "ops took", "μsec" , "avg" , "ops/μsec", NULL }, /* 0 English
  1620. for μsec */
  1621. #else
  1622. { "ops took", "sec" , "avg" , "ops/sec", NULL }, /* 0 English */
  1623. #endif
  1624. #ifndef NO_MULTIBYTE_PRINT
  1625. { "回処理を", "秒で実施", "平均", "処理/秒", NULL }, /* 1 Japanese */
  1626. #endif
  1627. };
  1628. #endif
  1629. #endif
  1630. #ifdef WOLFSSL_CAAM
  1631. #include <wolfssl/wolfcrypt/port/caam/wolfcaam.h>
  1632. #ifdef WOLFSSL_SECO_CAAM
  1633. #define SECO_MAX_UPDATES 10000
  1634. #define SECO_BENCHMARK_NONCE 0x7777
  1635. #define SECO_KEY_STORE_ID 1
  1636. #endif
  1637. static THREAD_LS_T int devId = WOLFSSL_CAAM_DEVID;
  1638. #else
  1639. #ifdef WC_USE_DEVID
  1640. static THREAD_LS_T int devId = WC_USE_DEVID;
  1641. #else
  1642. static THREAD_LS_T int devId = INVALID_DEVID;
  1643. #endif
  1644. #endif
  1645. /* Asynchronous helper macros */
  1646. #ifdef WC_ENABLE_BENCH_THREADING
  1647. typedef struct ThreadData {
  1648. pthread_t thread_id;
  1649. } ThreadData;
  1650. static ThreadData* g_threadData;
  1651. static volatile int g_threadCount;
  1652. #endif
  1653. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
  1654. #ifndef NO_HW_BENCH
  1655. #define BENCH_DEVID
  1656. #endif
  1657. #ifndef HAVE_RENESAS_SYNC
  1658. #define BENCH_DEVID_GET_NAME(useDeviceID) (useDeviceID) ? "HW" : "SW"
  1659. #else
  1660. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1661. #endif
  1662. #else
  1663. #define BENCH_DEVID_GET_NAME(useDeviceID) ""
  1664. #endif
  1665. #ifdef WOLFSSL_ASYNC_CRYPT
  1666. static WOLF_EVENT_QUEUE eventQueue;
  1667. #define BENCH_ASYNC_GET_DEV(obj) (&(obj)->asyncDev)
  1668. #define BENCH_MAX_PENDING (WOLF_ASYNC_MAX_PENDING)
  1669. static int bench_async_check(int* ret, WC_ASYNC_DEV* asyncDev,
  1670. int callAgain, int* times, int limit, int* pending)
  1671. {
  1672. int allowNext = 0;
  1673. /* this state can be set from a different thread */
  1674. WOLF_EVENT_STATE state = asyncDev->event.state;
  1675. /* if algo doesn't require calling again then use this flow */
  1676. if (state == WOLF_EVENT_STATE_DONE) {
  1677. if (callAgain) {
  1678. /* needs called again, so allow it and handle completion in
  1679. * bench_async_handle */
  1680. allowNext = 1;
  1681. }
  1682. else {
  1683. *ret = asyncDev->event.ret;
  1684. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1685. (*times)++;
  1686. if (*pending > 0) /* to support case where async blocks */
  1687. (*pending)--;
  1688. if ((*times + *pending) < limit)
  1689. allowNext = 1;
  1690. }
  1691. }
  1692. /* if slot is available and we haven't reached limit, start another */
  1693. else if (state == WOLF_EVENT_STATE_READY && (*times + *pending) < limit) {
  1694. allowNext = 1;
  1695. }
  1696. return allowNext;
  1697. }
  1698. static int bench_async_handle(int* ret, WC_ASYNC_DEV* asyncDev,
  1699. int callAgain, int* times, int* pending)
  1700. {
  1701. WOLF_EVENT_STATE state = asyncDev->event.state;
  1702. if (*ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  1703. if (state == WOLF_EVENT_STATE_DONE) {
  1704. *ret = asyncDev->event.ret;
  1705. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1706. (*times)++;
  1707. (*pending)--;
  1708. }
  1709. else {
  1710. (*pending)++;
  1711. *ret = wc_AsyncHandle(asyncDev, &eventQueue,
  1712. callAgain ? WC_ASYNC_FLAG_CALL_AGAIN : WC_ASYNC_FLAG_NONE);
  1713. }
  1714. }
  1715. else if (*ret >= 0) {
  1716. *ret = asyncDev->event.ret;
  1717. asyncDev->event.state = WOLF_EVENT_STATE_READY;
  1718. (*times)++;
  1719. if (*pending > 0) /* to support case where async blocks */
  1720. (*pending)--;
  1721. }
  1722. return (*ret >= 0) ? 1 : 0;
  1723. }
  1724. static WC_INLINE int bench_async_poll(int* pending)
  1725. {
  1726. int ret, asyncDone = 0;
  1727. ret = wolfAsync_EventQueuePoll(&eventQueue, NULL, NULL, 0,
  1728. WOLF_POLL_FLAG_CHECK_HW, &asyncDone);
  1729. if (ret != 0) {
  1730. printf("%sAsync poll failed %d\n", err_prefix, ret);
  1731. return ret;
  1732. }
  1733. if (asyncDone == 0) {
  1734. #ifndef WC_NO_ASYNC_THREADING
  1735. /* give time to other threads */
  1736. wc_AsyncThreadYield();
  1737. #endif
  1738. }
  1739. (void)pending;
  1740. return asyncDone;
  1741. }
  1742. #else
  1743. #define BENCH_MAX_PENDING 1
  1744. #define BENCH_ASYNC_GET_DEV(obj) NULL
  1745. static WC_INLINE int bench_async_check(int* ret, void* asyncDev,
  1746. int callAgain, int* times, int limit, int* pending)
  1747. {
  1748. (void)ret;
  1749. (void)asyncDev;
  1750. (void)callAgain;
  1751. (void)times;
  1752. (void)limit;
  1753. (void)pending;
  1754. return 1;
  1755. }
  1756. static WC_INLINE int bench_async_handle(int* ret, void* asyncDev,
  1757. int callAgain, int* times, int* pending)
  1758. {
  1759. (void)asyncDev;
  1760. (void)callAgain;
  1761. (void)pending;
  1762. if (*ret >= 0) {
  1763. /* operation completed */
  1764. (*times)++;
  1765. return 1;
  1766. }
  1767. return 0;
  1768. }
  1769. #define bench_async_poll(p) WC_DO_NOTHING
  1770. #endif /* WOLFSSL_ASYNC_CRYPT */
  1771. /* maximum runtime for each benchmark */
  1772. #ifndef BENCH_MIN_RUNTIME_SEC
  1773. #define BENCH_MIN_RUNTIME_SEC 1.0F
  1774. #endif
  1775. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1776. #define AES_AUTH_TAG_SZ 16
  1777. #define BENCH_CIPHER_ADD AES_AUTH_TAG_SZ
  1778. static word32 aesAuthAddSz = AES_AUTH_ADD_SZ;
  1779. #if !defined(AES_AAD_OPTIONS_DEFAULT)
  1780. #if !defined(NO_MAIN_DRIVER)
  1781. #define AES_AAD_OPTIONS_DEFAULT 0x1U
  1782. #else
  1783. #define AES_AAD_OPTIONS_DEFAULT 0x3U
  1784. #endif
  1785. #endif
  1786. #define AES_AAD_STRING(s) \
  1787. (aesAuthAddSz == 0 ? (s "-no_AAD") : \
  1788. (aesAuthAddSz == AES_AUTH_ADD_SZ ? (s) : (s "-custom")))
  1789. enum en_aad_options {
  1790. AAD_SIZE_DEFAULT = 0x1U,
  1791. AAD_SIZE_ZERO = 0x2U,
  1792. AAD_SIZE_CUSTOM = 0x4U,
  1793. };
  1794. static word32 aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1795. static word32 aes_aad_size = 0;
  1796. static void bench_aes_aad_options_wrap(void (*fn)(int), int i)
  1797. {
  1798. word32 aesAuthAddSz_orig = aesAuthAddSz;
  1799. word32 options = aes_aad_options;
  1800. while(options) {
  1801. if (options & AAD_SIZE_DEFAULT) {
  1802. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1803. options &= ~(word32)AAD_SIZE_DEFAULT;
  1804. }
  1805. else if (options & AAD_SIZE_ZERO) {
  1806. aesAuthAddSz = 0;
  1807. options &= ~(word32)AAD_SIZE_ZERO;
  1808. }
  1809. else if (options & AAD_SIZE_CUSTOM) {
  1810. aesAuthAddSz = aes_aad_size;
  1811. options &= ~(word32)AAD_SIZE_CUSTOM;
  1812. }
  1813. fn(i);
  1814. aesAuthAddSz = aesAuthAddSz_orig;
  1815. }
  1816. }
  1817. #endif
  1818. #ifndef BENCH_CIPHER_ADD
  1819. #define BENCH_CIPHER_ADD 0
  1820. #endif
  1821. /* use kB instead of mB for embedded benchmarking */
  1822. #ifdef BENCH_EMBEDDED
  1823. #ifndef BENCH_NTIMES
  1824. #define BENCH_NTIMES 2
  1825. #endif
  1826. #ifndef BENCH_AGREETIMES
  1827. #define BENCH_AGREETIMES 2
  1828. #endif
  1829. enum BenchmarkBounds {
  1830. scryptCnt = 1,
  1831. ntimes = BENCH_NTIMES,
  1832. genTimes = BENCH_MAX_PENDING,
  1833. agreeTimes = BENCH_AGREETIMES
  1834. };
  1835. /* how many kB to test (en/de)cryption */
  1836. #define NUM_BLOCKS 25
  1837. #define BENCH_SIZE (1024uL)
  1838. #else
  1839. #ifndef BENCH_NTIMES
  1840. #define BENCH_NTIMES 100
  1841. #endif
  1842. #ifndef BENCH_AGREETIMES
  1843. #define BENCH_AGREETIMES 100
  1844. #endif
  1845. enum BenchmarkBounds {
  1846. scryptCnt = 10,
  1847. ntimes = BENCH_NTIMES,
  1848. genTimes = BENCH_MAX_PENDING, /* must be at least BENCH_MAX_PENDING */
  1849. agreeTimes = BENCH_AGREETIMES
  1850. };
  1851. /* how many megs to test (en/de)cryption */
  1852. #define NUM_BLOCKS 5
  1853. #define BENCH_SIZE (1024*1024uL)
  1854. #endif
  1855. static int numBlocks = NUM_BLOCKS;
  1856. static word32 bench_size = BENCH_SIZE;
  1857. static int base2 = 1;
  1858. static int digest_stream = 1;
  1859. #ifdef HAVE_CHACHA
  1860. static int encrypt_only = 0;
  1861. #endif
  1862. #ifdef HAVE_AES_CBC
  1863. static int cipher_same_buffer = 0;
  1864. #endif
  1865. #ifdef MULTI_VALUE_STATISTICS
  1866. static int minimum_runs = 0;
  1867. #endif
  1868. #ifndef NO_RSA
  1869. /* Don't measure RSA sign/verify by default */
  1870. static int rsa_sign_verify = 0;
  1871. #endif
  1872. #ifndef NO_DH
  1873. /* Use the FFDHE parameters */
  1874. static int use_ffdhe = 0;
  1875. #endif
  1876. /* Don't print out in CSV format by default */
  1877. static int csv_format = 0;
  1878. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  1879. /* Versal PLM maybe prints an error message to the same console.
  1880. * In order to not mix those outputs up, sleep a little while
  1881. * before erroring out.
  1882. */
  1883. #define SLEEP_ON_ERROR(ret) do{ if (ret != 0) { sleep(1); } }while(0)
  1884. #else
  1885. #define SLEEP_ON_ERROR(ret) do{ /* noop */ }while(0)
  1886. #endif
  1887. /* globals for cipher tests */
  1888. static THREAD_LS_T byte* bench_plain = NULL;
  1889. static THREAD_LS_T byte* bench_cipher = NULL;
  1890. #ifndef NO_FILESYSTEM
  1891. static THREAD_LS_T char* hash_input = NULL;
  1892. static THREAD_LS_T char* cipher_input = NULL;
  1893. #endif
  1894. static const XGEN_ALIGN byte bench_key_buf[] =
  1895. {
  1896. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1897. 0xfe,0xde,0xba,0x98,0x76,0x54,0x32,0x10,
  1898. 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67,
  1899. 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
  1900. 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
  1901. 0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
  1902. 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
  1903. 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
  1904. };
  1905. static const XGEN_ALIGN byte bench_iv_buf[] =
  1906. {
  1907. 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef,
  1908. 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1909. 0x11,0x21,0x31,0x41,0x51,0x61,0x71,0x81
  1910. };
  1911. static THREAD_LS_T byte* bench_key = NULL;
  1912. static THREAD_LS_T byte* bench_iv = NULL;
  1913. #ifdef HAVE_RENESAS_SYNC
  1914. static THREAD_LS_T byte* bench_key1 = NULL;
  1915. static THREAD_LS_T byte* bench_key2 = NULL;
  1916. #endif
  1917. #ifdef WOLFSSL_STATIC_MEMORY
  1918. #ifdef WOLFSSL_STATIC_MEMORY_TEST_SZ
  1919. static byte gBenchMemory[WOLFSSL_STATIC_MEMORY_TEST_SZ];
  1920. #elif defined(BENCH_EMBEDDED)
  1921. static byte gBenchMemory[50000];
  1922. #else
  1923. static byte gBenchMemory[400000];
  1924. #endif
  1925. #endif
  1926. /* This code handles cases with systems where static (non cost) ram variables
  1927. aren't properly initialized with data */
  1928. static void benchmark_static_init(int force)
  1929. {
  1930. static int gBenchStaticInit = 0;
  1931. if (gBenchStaticInit == 0 || force) {
  1932. gBenchStaticInit = 1;
  1933. /* Init static variables */
  1934. numBlocks = NUM_BLOCKS;
  1935. bench_size = BENCH_SIZE;
  1936. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  1937. aesAuthAddSz = AES_AUTH_ADD_SZ;
  1938. aes_aad_options = AES_AAD_OPTIONS_DEFAULT;
  1939. aes_aad_size = 0;
  1940. #endif
  1941. base2 = 1;
  1942. digest_stream = 1;
  1943. #ifdef MULTI_VALUE_STATISTICS
  1944. minimum_runs = 0;
  1945. #endif
  1946. bench_all = 1;
  1947. bench_cipher_algs = 0;
  1948. bench_digest_algs = 0;
  1949. bench_mac_algs = 0;
  1950. bench_kdf_algs = 0;
  1951. bench_asym_algs = 0;
  1952. bench_pq_asym_algs = 0;
  1953. bench_other_algs = 0;
  1954. bench_pq_hash_sig_algs = 0;
  1955. csv_format = 0;
  1956. }
  1957. }
  1958. /*****************************************************************************/
  1959. /* Begin Stats Functions */
  1960. /*****************************************************************************/
  1961. typedef enum bench_stat_type {
  1962. BENCH_STAT_ASYM,
  1963. BENCH_STAT_SYM,
  1964. BENCH_STAT_IGNORE,
  1965. } bench_stat_type_t;
  1966. #ifdef WC_BENCH_TRACK_STATS
  1967. static int gPrintStats = 0;
  1968. #ifdef WC_ENABLE_BENCH_THREADING
  1969. static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
  1970. #endif
  1971. #ifndef BENCH_MAX_NAME_SZ
  1972. #define BENCH_MAX_NAME_SZ 24
  1973. #endif
  1974. typedef struct bench_stats {
  1975. struct bench_stats* next;
  1976. struct bench_stats* prev;
  1977. char algo[BENCH_MAX_NAME_SZ+1]; /* may not be static, so make copy */
  1978. const char* desc;
  1979. double perfsec;
  1980. int strength;
  1981. int useDeviceID;
  1982. int finishCount;
  1983. bench_stat_type_t type;
  1984. int lastRet;
  1985. const char* perftype;
  1986. } bench_stats_t;
  1987. static bench_stats_t* bench_stats_head;
  1988. static bench_stats_t* bench_stats_tail;
  1989. static bench_stats_t* bench_stats_add(bench_stat_type_t type,
  1990. const char* algo, int strength, const char* desc, int useDeviceID,
  1991. double perfsec, const char* perftype, int ret)
  1992. {
  1993. bench_stats_t* bstat = NULL;
  1994. #ifdef WC_ENABLE_BENCH_THREADING
  1995. /* protect bench_stats_head and bench_stats_tail access */
  1996. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  1997. #endif
  1998. if (algo != NULL) {
  1999. /* locate existing in list */
  2000. for (bstat = bench_stats_head; bstat != NULL; bstat = bstat->next) {
  2001. /* match based on algo, strength and desc */
  2002. if (XSTRNCMP(bstat->algo, algo, BENCH_MAX_NAME_SZ) == 0 &&
  2003. bstat->strength == strength &&
  2004. bstat->desc == desc &&
  2005. bstat->useDeviceID == useDeviceID) {
  2006. break;
  2007. }
  2008. }
  2009. }
  2010. if (bstat == NULL) {
  2011. /* allocate new and put on list */
  2012. bstat = (bench_stats_t*)XMALLOC(sizeof(bench_stats_t), NULL,
  2013. DYNAMIC_TYPE_INFO);
  2014. if (bstat) {
  2015. XMEMSET(bstat, 0, sizeof(bench_stats_t));
  2016. /* add to list */
  2017. bstat->next = NULL;
  2018. if (bench_stats_tail == NULL) {
  2019. bench_stats_head = bstat;
  2020. }
  2021. else {
  2022. bench_stats_tail->next = bstat;
  2023. bstat->prev = bench_stats_tail;
  2024. }
  2025. bench_stats_tail = bstat; /* add to the end either way */
  2026. }
  2027. }
  2028. if (bstat) {
  2029. bstat->type = type;
  2030. if (algo != NULL)
  2031. XSTRNCPY(bstat->algo, algo, BENCH_MAX_NAME_SZ);
  2032. bstat->strength = strength;
  2033. bstat->desc = desc;
  2034. bstat->useDeviceID = useDeviceID;
  2035. bstat->perfsec += perfsec;
  2036. bstat->finishCount++;
  2037. bstat->perftype = perftype;
  2038. if (bstat->lastRet > ret)
  2039. bstat->lastRet = ret; /* track last error */
  2040. }
  2041. #ifdef WC_ENABLE_BENCH_THREADING
  2042. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2043. #endif
  2044. return bstat;
  2045. }
  2046. void bench_stats_print(void)
  2047. {
  2048. bench_stats_t* bstat;
  2049. int digits;
  2050. #ifdef WC_ENABLE_BENCH_THREADING
  2051. /* protect bench_stats_head and bench_stats_tail access */
  2052. THREAD_CHECK_RET(pthread_mutex_lock(&bench_lock));
  2053. #endif
  2054. #ifdef BENCH_MICROSECOND
  2055. digits = 5;
  2056. #else
  2057. digits = 3;
  2058. #endif
  2059. for (bstat = bench_stats_head; bstat != NULL; ) {
  2060. if (bstat->type == BENCH_STAT_SYM) {
  2061. printf("%-16s%s " FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT
  2062. "\n", bstat->desc,
  2063. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2064. FLT_FMT_PREC2_ARGS(8, digits, bstat->perfsec),
  2065. base2 ? "MB" : "mB");
  2066. }
  2067. else {
  2068. printf("%-5s %4d %-9s %s " FLT_FMT_PREC " ops/"
  2069. WOLFSSL_FIXED_TIME_UNIT "ec\n",
  2070. bstat->algo, bstat->strength, bstat->desc,
  2071. BENCH_DEVID_GET_NAME(bstat->useDeviceID),
  2072. FLT_FMT_PREC_ARGS(digits, bstat->perfsec));
  2073. }
  2074. bstat = bstat->next;
  2075. }
  2076. #ifdef WC_ENABLE_BENCH_THREADING
  2077. THREAD_CHECK_RET(pthread_mutex_unlock(&bench_lock));
  2078. #endif
  2079. }
  2080. #endif /* WC_BENCH_TRACK_STATS */
  2081. static WC_INLINE void bench_stats_init(void)
  2082. {
  2083. #ifdef WC_BENCH_TRACK_STATS
  2084. bench_stats_head = NULL;
  2085. bench_stats_tail = NULL;
  2086. #endif
  2087. INIT_CYCLE_COUNTER
  2088. }
  2089. static WC_INLINE void bench_stats_start(int* count, double* start)
  2090. {
  2091. *count = 0;
  2092. *start = current_time(1);
  2093. #ifdef WOLFSSL_ESPIDF
  2094. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2095. ESP_LOGI(TAG, "bench_stats_start total_cycles = %llu"
  2096. ", start=" FLT_FMT,
  2097. total_cycles, FLT_FMT_ARGS(*start) );
  2098. #endif
  2099. BEGIN_ESP_CYCLES
  2100. #else
  2101. BEGIN_INTEL_CYCLES
  2102. #endif
  2103. }
  2104. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2105. #define bench_stats_start(count, start) do { \
  2106. SAVE_VECTOR_REGISTERS(pr_err( \
  2107. "SAVE_VECTOR_REGISTERS failed for benchmark run."); \
  2108. return; ); \
  2109. bench_stats_start(count, start); \
  2110. } while (0)
  2111. #endif
  2112. static WC_INLINE int bench_stats_check(double start)
  2113. {
  2114. int ret = 0;
  2115. double this_current_time = 0.0;
  2116. this_current_time = current_time(0); /* get the timestamp, no reset */
  2117. #if defined(DEBUG_WOLFSSL_BENCHMARK_TIMING) && defined(WOLFSSL_ESPIDF)
  2118. #if defined(WOLFSSL_ESPIDF)
  2119. ESP_LOGI(TAG, "bench_stats_check Current time = %f, start = %f",
  2120. this_current_time, start );
  2121. #endif
  2122. #endif
  2123. ret = ((this_current_time - start) < BENCH_MIN_RUNTIME_SEC
  2124. #ifdef BENCH_MICROSECOND
  2125. * 1000000
  2126. #endif
  2127. );
  2128. return ret;
  2129. }
  2130. /* return text for units and scale the value of blocks as needed */
  2131. static const char* get_blocktype(double* blocks)
  2132. {
  2133. const char* rt;
  2134. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2135. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2136. #undef WOLFSSL_FIXED_UNIT
  2137. #define WOLFSSL_FIXED_UNIT "GB"
  2138. *blocks /= (1024UL * 1024UL * 1024UL);
  2139. rt = "GiB";
  2140. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2141. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2142. #undef WOLFSSL_FIXED_UNIT
  2143. #define WOLFSSL_FIXED_UNIT "MB"
  2144. *blocks /= (1024UL * 1024UL);
  2145. rt = "MiB";
  2146. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2147. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2148. #undef WOLFSSL_FIXED_UNIT
  2149. #define WOLFSSL_FIXED_UNIT "KB"
  2150. *blocks /= 1024;
  2151. rt = "KiB";
  2152. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2153. #undef WOLFSSL_FIXED_UNIT
  2154. #define WOLFSSL_FIXED_UNIT "bytes"
  2155. (void)(*blocks); /* no adjustment, just appease compiler for not used */
  2156. rt = "bytes";
  2157. #else
  2158. /* If no user-specified, auto-scale each metric (results vary).
  2159. * Determine if we should show as KB or MB or bytes. No GiB here. */
  2160. if (*blocks > (1024UL * 1024UL)) {
  2161. *blocks /= (1024UL * 1024UL);
  2162. rt = "MiB";
  2163. }
  2164. else if (*blocks > 1024) {
  2165. *blocks /= 1024;
  2166. rt = "KiB";
  2167. }
  2168. else {
  2169. rt = "bytes";
  2170. }
  2171. #endif
  2172. return rt;
  2173. }
  2174. /* return text for units and scale the value of blocks as needed for base2 */
  2175. static const char* get_blocktype_base10(double* blocks)
  2176. {
  2177. const char* rt;
  2178. #if ( defined(WOLFSSL_BENCHMARK_FIXED_UNITS_G) || \
  2179. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_GB))
  2180. *blocks /= (1000UL * 1000UL * 1000UL);
  2181. rt = "GB";
  2182. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_M) || \
  2183. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_MB))
  2184. *blocks /= (1000UL * 1000UL);
  2185. rt = "MB";
  2186. #elif (defined(WOLFSSL_BENCHMARK_FIXED_UNITS_K) || \
  2187. defined(WOLFSSL_BENCHMARK_FIXED_UNITS_KB))
  2188. *blocks /= (1000UL);
  2189. rt = "KB";
  2190. #elif defined (WOLFSSL_BENCHMARK_FIXED_UNITS_B)
  2191. (void)(*blocks); /* no adjustment, just appease compiler */
  2192. rt = "bytes";
  2193. #else
  2194. /* If not user-specified, auto-scale each metric (results vary).
  2195. * Determine if we should show as KB or MB or bytes */
  2196. if (*blocks > (1000UL * 1000UL)) {
  2197. *blocks /= (1000UL * 1000UL);
  2198. rt = "MB";
  2199. }
  2200. else if (*blocks > 1000) {
  2201. *blocks /= 1000; /* make KB */
  2202. rt = "KB";
  2203. }
  2204. else {
  2205. rt = "bytes";
  2206. }
  2207. #endif
  2208. return rt;
  2209. }
  2210. #ifdef MULTI_VALUE_STATISTICS
  2211. static double wc_sqroot(double in)
  2212. {
  2213. /* do 32 iterations for the sqroot */
  2214. int iter = 32;
  2215. double root = in/3.0;
  2216. if (in < 0.0)
  2217. return -1;
  2218. for (int i=0; i < iter; i++)
  2219. root = (root + in / root) / 2.0;
  2220. return root;
  2221. }
  2222. static void bench_multi_value_stats(double max, double min, double sum,
  2223. double squareSum, int runs)
  2224. {
  2225. double mean = 0;
  2226. double sd = 0;
  2227. char msg[WC_BENCH_MAX_LINE_LEN];
  2228. const char** word = bench_result_words3[lng_index];
  2229. XMEMSET(msg, 0, sizeof(msg));
  2230. mean = sum / runs;
  2231. /* Calculating standard deviation */
  2232. sd = (squareSum / runs) - (mean * mean);
  2233. sd = wc_sqroot(sd);
  2234. if (csv_format == 1) {
  2235. (void)XSNPRINTF(msg, sizeof(msg), FLT_FMT_PREC2 ","
  2236. FLT_FMT_PREC2 "," FLT_FMT_PREC2 "," FLT_FMT_PREC2 ",\n",
  2237. FLT_FMT_PREC2_ARGS(3, 3, max),
  2238. FLT_FMT_PREC2_ARGS(3, 3, min),
  2239. FLT_FMT_PREC2_ARGS(3, 3, mean),
  2240. FLT_FMT_PREC2_ARGS(3, 3, sd));
  2241. }
  2242. else{
  2243. (void)XSNPRINTF(msg, sizeof(msg), ", %s " FLT_FMT_PREC2 " "
  2244. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2245. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2246. WOLFSSL_FIXED_TIME_UNIT ", %s " FLT_FMT_PREC2 " "
  2247. WOLFSSL_FIXED_TIME_UNIT "\n",
  2248. word[0], FLT_FMT_PREC2_ARGS(3, 3, max),
  2249. word[1], FLT_FMT_PREC2_ARGS(3, 3, min),
  2250. word[2], FLT_FMT_PREC2_ARGS(3, 3, mean),
  2251. word[3], FLT_FMT_PREC2_ARGS(3, 3, sd));
  2252. }
  2253. printf("%s", msg);
  2254. #ifndef WOLFSSL_SGX
  2255. XFFLUSH(stdout);
  2256. #endif
  2257. }
  2258. #endif
  2259. /* countSz is number of bytes that 1 count represents. Normally bench_size,
  2260. * except for AES direct that operates on AES_BLOCK_SIZE blocks */
  2261. static void bench_stats_sym_finish(const char* desc, int useDeviceID,
  2262. int count, word32 countSz,
  2263. double start, int ret)
  2264. {
  2265. double total, persec = 0, blocks = (double)count;
  2266. const char* blockType;
  2267. char msg[WC_BENCH_MAX_LINE_LEN];
  2268. const char** word = bench_result_words1[lng_index];
  2269. static int sym_header_printed = 0;
  2270. XMEMSET(msg, 0, sizeof(msg));
  2271. #ifdef WOLFSSL_ESPIDF
  2272. END_ESP_CYCLES
  2273. #else
  2274. END_INTEL_CYCLES
  2275. #endif
  2276. total = current_time(0) - start;
  2277. #if defined(WOLFSSL_ESPIDF) && defined(DEBUG_WOLFSSL_BENCHMARK_TIMING)
  2278. ESP_LOGI(TAG, "%s total_cycles = %llu", desc, total_cycles);
  2279. #endif
  2280. #ifdef LINUX_RUSAGE_UTIME
  2281. check_for_excessive_stime(desc, "");
  2282. #endif
  2283. /* calculate actual bytes */
  2284. blocks *= countSz;
  2285. if (csv_format == 1) {
  2286. /* only print out header once */
  2287. if (sym_header_printed == 0) {
  2288. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2289. /* machine parseable CSV */
  2290. #ifdef HAVE_GET_CYCLES
  2291. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2292. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2293. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2294. ",cycles_total,Cycles per byte,");
  2295. #else
  2296. printf("%s", "\"sym\",Algorithm,HW/SW,bytes_total,"
  2297. WOLFSSL_FIXED_TIME_UNIT "econds_total,"
  2298. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2299. ",cycles_total,");
  2300. #endif
  2301. #else
  2302. /* normal CSV */
  2303. #ifdef BENCH_DEVID
  2304. #define BENCH_DEVID_COLUMN_HEADER "HW/SW,"
  2305. #else
  2306. #define BENCH_DEVID_COLUMN_HEADER
  2307. #endif
  2308. #ifdef HAVE_GET_CYCLES
  2309. printf("\n\nSymmetric Ciphers:\n\n");
  2310. printf("Algorithm,"
  2311. BENCH_DEVID_COLUMN_HEADER
  2312. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT
  2313. ",Cycles per byte,");
  2314. #else
  2315. printf("\n\nSymmetric Ciphers:\n\n");
  2316. printf("Algorithm,"
  2317. BENCH_DEVID_COLUMN_HEADER
  2318. WOLFSSL_FIXED_UNIT "/" WOLFSSL_FIXED_TIME_UNIT ",");
  2319. #endif
  2320. #endif
  2321. #ifdef MULTI_VALUE_STATISTICS
  2322. printf("max duration,min duration,mean duration,sd,\n");
  2323. #else
  2324. printf("\n");
  2325. #endif
  2326. sym_header_printed = 1;
  2327. }
  2328. }
  2329. /* determine if we have fixed units, or auto-scale bits or bytes for units.
  2330. * note that the blockType text is assigned AND the blocks param is scaled.
  2331. */
  2332. if (base2) {
  2333. blockType = get_blocktype(&blocks);
  2334. }
  2335. else {
  2336. blockType = get_blocktype_base10(&blocks);
  2337. }
  2338. /* calculate blocks per second */
  2339. if (total > 0) {
  2340. persec = (1 / total) * blocks;
  2341. }
  2342. SLEEP_ON_ERROR(ret);
  2343. /* format and print to terminal */
  2344. if (csv_format == 1) {
  2345. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2346. #ifdef WOLFSSL_ESPIDF
  2347. unsigned long bytes_processed =
  2348. (unsigned long)count * (unsigned long)countSz;
  2349. #else
  2350. word64 bytes_processed = (word64)count * (word64)countSz;
  2351. #endif
  2352. /* note this codepath brings in all the fields from the non-CSV case. */
  2353. #ifdef WOLFSSL_ESPIDF
  2354. #ifdef HAVE_GET_CYCLES
  2355. (void)XSNPRINTF(msg, sizeof(msg),
  2356. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2357. BENCH_DEVID_GET_NAME(useDeviceID),
  2358. bytes_processed, FLT_FMT_ARGS(total),
  2359. FLT_FMT_ARGS(persec),
  2360. (long unsigned int) total_cycles);
  2361. #else
  2362. #warning "HAVE_GET_CYCLES should be defined for WOLFSSL_ESPIDF"
  2363. #endif
  2364. /* implement other architectures here */
  2365. #else
  2366. #ifdef HAVE_GET_CYCLES
  2367. (void)XSNPRINTF(msg, sizeof(msg),
  2368. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",%lu,", desc,
  2369. BENCH_DEVID_GET_NAME(useDeviceID),
  2370. bytes_processed, FLT_FMT_ARGS(total),
  2371. FLT_FMT_ARGS(persec), total_cycles);
  2372. #else
  2373. (void)XSNPRINTF(msg, sizeof(msg),
  2374. "sym,%s,%s,%lu," FLT_FMT "," FLT_FMT ",", desc,
  2375. BENCH_DEVID_GET_NAME(useDeviceID),
  2376. bytes_processed, FLT_FMT_ARGS(total),
  2377. FLT_FMT_ARGS(persec));
  2378. #endif
  2379. #endif
  2380. #elif defined(BENCH_DEVID)
  2381. (void)XSNPRINTF(msg, sizeof(msg), "%s,%s," FLT_FMT ",", desc,
  2382. BENCH_DEVID_GET_NAME(useDeviceID), FLT_FMT_ARGS(persec));
  2383. #else
  2384. (void)XSNPRINTF(msg, sizeof(msg), "%s," FLT_FMT ",", desc,
  2385. FLT_FMT_ARGS(persec));
  2386. #endif
  2387. #ifdef WOLFSSL_ESPIDF
  2388. SHOW_ESP_CYCLES_CSV(msg, sizeof(msg), countSz);
  2389. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  2390. ESP_LOGI(TAG, "bench_stats_sym_finish total_cycles = %llu",
  2391. total_cycles);
  2392. #endif
  2393. /* implement other cycle counters here */
  2394. #else
  2395. /* the default cycle counter is Intel */
  2396. SHOW_INTEL_CYCLES_CSV(msg, sizeof(msg), (unsigned)countSz);
  2397. #endif
  2398. } /* if (csv_format == 1) */
  2399. else {
  2400. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2401. #ifdef HAVE_GET_CYCLES
  2402. (void)XSNPRINTF(msg, sizeof(msg),
  2403. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2404. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ", %lu cycles,",
  2405. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2406. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2407. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2408. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType,
  2409. (unsigned long) total_cycles);
  2410. #else
  2411. (void)XSNPRINTF(msg, sizeof(msg),
  2412. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2413. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT ",",
  2414. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2415. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2416. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2417. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2418. #endif /* HAVE_GET_CYCLES */
  2419. #else
  2420. (void)XSNPRINTF(msg, sizeof(msg),
  2421. "%-24s%s " FLT_FMT_PREC2 " %s %s " FLT_FMT_PREC2 " %s, "
  2422. FLT_FMT_PREC2 " %s/" WOLFSSL_FIXED_TIME_UNIT,
  2423. desc, BENCH_DEVID_GET_NAME(useDeviceID),
  2424. FLT_FMT_PREC2_ARGS(5, 0, blocks), blockType,
  2425. word[0], FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2426. FLT_FMT_PREC2_ARGS(8, 3, persec), blockType);
  2427. #endif
  2428. #ifdef WOLFSSL_ESPIDF
  2429. SHOW_ESP_CYCLES(msg, sizeof(msg), countSz);
  2430. /* implement other architecture cycle counters here */
  2431. #else
  2432. SHOW_INTEL_CYCLES(msg, sizeof(msg), (unsigned)countSz);
  2433. #endif
  2434. } /* not CSV format */
  2435. printf("%s", msg);
  2436. /* show errors */
  2437. if (ret < 0) {
  2438. printf("%sBenchmark %s failed: %d\n", err_prefix, desc, ret);
  2439. }
  2440. #ifndef WOLFSSL_SGX
  2441. XFFLUSH(stdout);
  2442. #endif
  2443. #ifdef WC_BENCH_TRACK_STATS
  2444. /* Add to thread stats */
  2445. bench_stats_add(BENCH_STAT_SYM, desc, 0, desc, useDeviceID, persec,
  2446. blockType, ret);
  2447. #endif
  2448. (void)useDeviceID;
  2449. (void)ret;
  2450. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2451. RESTORE_VECTOR_REGISTERS();
  2452. #endif
  2453. TEST_SLEEP();
  2454. } /* bench_stats_sym_finish */
  2455. #ifdef BENCH_ASYM
  2456. #if defined(HAVE_ECC) || !defined(NO_RSA) || !defined(NO_DH) || \
  2457. defined(HAVE_CURVE25519) || defined(HAVE_ED25519) || \
  2458. defined(HAVE_CURVE448) || defined(HAVE_ED448) || \
  2459. defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_DILITHIUM) || \
  2460. defined(WOLFSSL_HAVE_LMS)
  2461. static void bench_stats_asym_finish_ex(const char* algo, int strength,
  2462. const char* desc, const char* desc_extra, int useDeviceID, int count,
  2463. double start, int ret)
  2464. {
  2465. double total, each = 0, opsSec, milliEach;
  2466. const char **word = bench_result_words2[lng_index];
  2467. #ifdef WC_BENCH_TRACK_STATS
  2468. const char* kOpsSec = "Ops/Sec";
  2469. #endif
  2470. char msg[256];
  2471. static int asym_header_printed = 0;
  2472. #ifdef BENCH_MICROSECOND
  2473. const int digits = 5;
  2474. #else
  2475. const int digits = 3;
  2476. #endif
  2477. XMEMSET(msg, 0, sizeof(msg));
  2478. total = current_time(0) - start;
  2479. #ifdef LINUX_RUSAGE_UTIME
  2480. check_for_excessive_stime(desc, desc_extra);
  2481. #endif
  2482. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2483. #ifdef WOLFSSL_ESPIDF
  2484. END_ESP_CYCLES
  2485. #else
  2486. END_INTEL_CYCLES
  2487. #endif
  2488. #endif
  2489. /* some sanity checks on the final numbers */
  2490. if (count > 0) {
  2491. each = total / count; /* per second */
  2492. }
  2493. else {
  2494. count = 0;
  2495. each = 0;
  2496. }
  2497. if (total > 0) {
  2498. opsSec = count / total; /* ops second */
  2499. }
  2500. else {
  2501. opsSec = 0;
  2502. }
  2503. #ifdef BENCH_MICROSECOND
  2504. milliEach = each / 1000; /* milliseconds */
  2505. #else
  2506. milliEach = each * 1000; /* milliseconds */
  2507. #endif
  2508. SLEEP_ON_ERROR(ret);
  2509. #ifdef MULTI_VALUE_STATISTICS /* Print without avg ms */
  2510. (void)milliEach;
  2511. /* format and print to terminal */
  2512. if (csv_format == 1) {
  2513. /* only print out header once */
  2514. if (asym_header_printed == 0) {
  2515. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2516. #ifdef HAVE_GET_CYCLES
  2517. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2518. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2519. "ecs,cycles,cycles/op,");
  2520. #else
  2521. printf("%s", "\"asym\",Algorithm,key size,operation,ops/"
  2522. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2523. "ecs,");
  2524. #endif
  2525. #else
  2526. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2527. printf("%sAlgorithm,key size,operation,ops/"
  2528. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2529. #endif
  2530. printf("max duration,min duration,mean duration,sd,\n");
  2531. asym_header_printed = 1;
  2532. }
  2533. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2534. #ifdef HAVE_GET_CYCLES
  2535. (void)XSNPRINTF(msg, sizeof(msg),
  2536. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2537. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2538. algo, strength, desc, desc_extra,
  2539. FLT_FMT_PREC_ARGS(digits, opsSec),
  2540. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2541. FLT_FMT_PREC_ARGS(6,
  2542. (double)total_cycles / (double)count));
  2543. #else
  2544. (void)XSNPRINTF(msg, sizeof(msg),
  2545. "asym,%s,%d,%s%s," FLT_FMT_PREC ",%d,"
  2546. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2547. algo, strength, desc, desc_extra,
  2548. FLT_FMT_PREC_ARGS(digits, opsSec),
  2549. count, FLT_FMT_ARGS(total));
  2550. #endif
  2551. #else
  2552. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s,"
  2553. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2554. algo, strength, desc, desc_extra,
  2555. FLT_FMT_PREC_ARGS(digits, opsSec));
  2556. #endif
  2557. } /* if (csv_format == 1) */
  2558. else {
  2559. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2560. #ifdef HAVE_GET_CYCLES
  2561. (void)XSNPRINTF(msg, sizeof(msg),
  2562. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2563. FLT_FMT_PREC " %s, %lu cycles" STATS_CLAUSE_SEPARATOR,
  2564. algo, strength, desc, desc_extra,
  2565. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2566. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2567. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2568. (unsigned long)total_cycles);
  2569. #else
  2570. (void)XSNPRINTF(msg, sizeof(msg),
  2571. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2572. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2573. algo, strength, desc, desc_extra,
  2574. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2575. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2576. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2577. #endif /* HAVE_GET_CYCLES */
  2578. #else
  2579. (void)XSNPRINTF(msg, sizeof(msg),
  2580. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, "
  2581. FLT_FMT_PREC " %s" STATS_CLAUSE_SEPARATOR,
  2582. algo, strength, desc, desc_extra,
  2583. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2584. FLT_FMT_PREC2_ARGS(5, 3, total), word[1],
  2585. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2586. #endif
  2587. }
  2588. #else /* MULTI_VALUE_STATISTICS. Print with avg ms */
  2589. /* format and print to terminal */
  2590. if (csv_format == 1) {
  2591. /* only print out header once */
  2592. if (asym_header_printed == 0) {
  2593. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2594. #ifdef HAVE_GET_CYCLES
  2595. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2596. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2597. "ecs,cycles,cycles/op,");
  2598. #else
  2599. printf("%s", "\"asym\",Algorithm,key size,operation,avg ms,ops/"
  2600. WOLFSSL_FIXED_TIME_UNIT "ec,ops," WOLFSSL_FIXED_TIME_UNIT
  2601. "ecs,");
  2602. #endif
  2603. #else
  2604. printf("\n%sAsymmetric Ciphers:\n\n", info_prefix);
  2605. printf("%sAlgorithm,key size,operation,avg ms,ops/"
  2606. WOLFSSL_FIXED_TIME_UNIT "ec,", info_prefix);
  2607. #endif
  2608. printf("\n");
  2609. asym_header_printed = 1;
  2610. }
  2611. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2612. #ifdef HAVE_GET_CYCLES
  2613. (void)XSNPRINTF(msg, sizeof(msg),
  2614. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2615. FLT_FMT ",%lu," FLT_FMT_PREC STATS_CLAUSE_SEPARATOR,
  2616. algo, strength, desc, desc_extra,
  2617. FLT_FMT_PREC_ARGS(3, milliEach),
  2618. FLT_FMT_PREC_ARGS(digits, opsSec),
  2619. count, FLT_FMT_ARGS(total), (unsigned long)total_cycles,
  2620. FLT_FMT_PREC_ARGS(6,
  2621. (double)total_cycles / (double)count));
  2622. #else
  2623. (void)XSNPRINTF(msg, sizeof(msg),
  2624. "asym,%s,%d,%s%s," FLT_FMT_PREC "," FLT_FMT_PREC ",%d,"
  2625. FLT_FMT STATS_CLAUSE_SEPARATOR,
  2626. algo, strength, desc, desc_extra,
  2627. FLT_FMT_PREC_ARGS(3, milliEach),
  2628. FLT_FMT_PREC_ARGS(digits, opsSec),
  2629. count, FLT_FMT_ARGS(total));
  2630. #endif
  2631. #else
  2632. (void)XSNPRINTF(msg, sizeof(msg), "%s,%d,%s%s," FLT_FMT_PREC ","
  2633. FLT_FMT_PREC "," STATS_CLAUSE_SEPARATOR,
  2634. algo, strength, desc, desc_extra,
  2635. FLT_FMT_PREC_ARGS(3, milliEach),
  2636. FLT_FMT_PREC_ARGS(digits, opsSec));
  2637. #endif
  2638. } /* if (csv_format == 1) */
  2639. else {
  2640. #ifdef GENERATE_MACHINE_PARSEABLE_REPORT
  2641. #ifdef HAVE_GET_CYCLES
  2642. (void)XSNPRINTF(msg, sizeof(msg),
  2643. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2644. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s, %lu cycles"
  2645. STATS_CLAUSE_SEPARATOR,
  2646. algo, strength, desc, desc_extra,
  2647. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2648. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2649. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2650. FLT_FMT_PREC_ARGS(digits, opsSec), word[3],
  2651. (unsigned long)total_cycles);
  2652. #else
  2653. (void)XSNPRINTF(msg, sizeof(msg),
  2654. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2655. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2656. STATS_CLAUSE_SEPARATOR,
  2657. algo, strength, desc, desc_extra,
  2658. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2659. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2660. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2661. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2662. #endif /* HAVE_GET_CYCLES */
  2663. #else
  2664. (void)XSNPRINTF(msg, sizeof(msg),
  2665. "%-6s %5d %8s%-2s %s %6d %s " FLT_FMT_PREC2 " %s, %s "
  2666. FLT_FMT_PREC2 " ms, " FLT_FMT_PREC " %s"
  2667. STATS_CLAUSE_SEPARATOR,
  2668. algo, strength, desc, desc_extra,
  2669. BENCH_DEVID_GET_NAME(useDeviceID), count, word[0],
  2670. FLT_FMT_PREC2_ARGS(5, 3, total), word[1], word[2],
  2671. FLT_FMT_PREC2_ARGS(5, 3, milliEach),
  2672. FLT_FMT_PREC_ARGS(digits, opsSec), word[3]);
  2673. #endif
  2674. }
  2675. #endif /* MULTI_VALUE_STATISTICS */
  2676. printf("%s", msg);
  2677. /* show errors */
  2678. if (ret < 0) {
  2679. printf("%sBenchmark %s %s %d failed: %d\n",
  2680. err_prefix, algo, desc, strength, ret);
  2681. }
  2682. #ifndef WOLFSSL_SGX
  2683. XFFLUSH(stdout);
  2684. #endif
  2685. #ifdef WC_BENCH_TRACK_STATS
  2686. /* Add to thread stats */
  2687. bench_stats_add(BENCH_STAT_ASYM, algo, strength, desc, useDeviceID, opsSec,
  2688. kOpsSec, ret);
  2689. #endif
  2690. (void)useDeviceID;
  2691. (void)ret;
  2692. #ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
  2693. RESTORE_VECTOR_REGISTERS();
  2694. #endif
  2695. TEST_SLEEP();
  2696. } /* bench_stats_asym_finish_ex */
  2697. static void bench_stats_asym_finish(const char* algo, int strength,
  2698. const char* desc, int useDeviceID, int count, double start, int ret)
  2699. {
  2700. bench_stats_asym_finish_ex(algo, strength, desc, "", useDeviceID, count,
  2701. start, ret);
  2702. }
  2703. #endif
  2704. #endif /* BENCH_ASYM */
  2705. static WC_INLINE void bench_stats_free(void)
  2706. {
  2707. #ifdef WC_BENCH_TRACK_STATS
  2708. bench_stats_t* bstat;
  2709. for (bstat = bench_stats_head; bstat != NULL; ) {
  2710. bench_stats_t* next = bstat->next;
  2711. XFREE(bstat, NULL, DYNAMIC_TYPE_INFO);
  2712. bstat = next;
  2713. }
  2714. bench_stats_head = NULL;
  2715. bench_stats_tail = NULL;
  2716. #endif
  2717. }
  2718. /*****************************************************************************/
  2719. /* End Stats Functions */
  2720. /*****************************************************************************/
  2721. static void* benchmarks_do(void* args)
  2722. {
  2723. long bench_buf_size;
  2724. #ifdef WOLFSSL_ASYNC_CRYPT
  2725. #ifndef WC_NO_ASYNC_THREADING
  2726. ThreadData* threadData = (ThreadData*)args;
  2727. if (wolfAsync_DevOpenThread(&devId, &threadData->thread_id) < 0)
  2728. #else
  2729. if (wolfAsync_DevOpen(&devId) < 0)
  2730. #endif
  2731. {
  2732. printf("%sAsync device open failed\n%sRunning without async\n",
  2733. err_prefix, err_prefix);
  2734. }
  2735. #endif /* WOLFSSL_ASYNC_CRYPT */
  2736. (void)args;
  2737. #ifdef WOLFSSL_ASYNC_CRYPT
  2738. if (wolfEventQueue_Init(&eventQueue) != 0) {
  2739. printf("%sAsync event queue init failure!\n", err_prefix);
  2740. }
  2741. #endif
  2742. #ifdef WOLF_CRYPTO_CB
  2743. #ifdef HAVE_INTEL_QA_SYNC
  2744. devId = wc_CryptoCb_InitIntelQa();
  2745. if (devId == INVALID_DEVID) {
  2746. printf("%sCouldn't init the Intel QA\n", err_prefix);
  2747. }
  2748. #endif
  2749. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  2750. devId = wc_CryptoCb_InitOcteon();
  2751. if (devId == INVALID_DEVID) {
  2752. printf("%sCouldn't get the Octeon device ID\n", err_prefix);
  2753. }
  2754. #endif
  2755. #ifdef HAVE_RENESAS_SYNC
  2756. devId = wc_CryptoCb_CryptInitRenesasCmn(NULL, &guser_PKCbInfo);
  2757. if (devId == INVALID_DEVID) {
  2758. printf("%sCouldn't get the Renesas device ID\n", err_prefix);
  2759. }
  2760. #endif
  2761. #endif
  2762. #if defined(HAVE_LOCAL_RNG)
  2763. {
  2764. int rngRet;
  2765. #ifndef HAVE_FIPS
  2766. rngRet = wc_InitRng_ex(&gRng, HEAP_HINT, devId);
  2767. #else
  2768. rngRet = wc_InitRng(&gRng);
  2769. #endif
  2770. if (rngRet < 0) {
  2771. printf("%sInitRNG failed\n", err_prefix);
  2772. return NULL;
  2773. }
  2774. }
  2775. #endif
  2776. /* setup bench plain, cipher, key and iv globals */
  2777. /* make sure bench buffer is multiple of 16 (AES block size) */
  2778. bench_buf_size = (int)bench_size + BENCH_CIPHER_ADD;
  2779. if (bench_buf_size % 16)
  2780. bench_buf_size += 16 - (bench_buf_size % 16);
  2781. #ifdef WOLFSSL_AFALG_XILINX_AES
  2782. bench_plain = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2783. bench_cipher = (byte*)aligned_alloc(64, (size_t)bench_buf_size + 16); /* native heap */
  2784. #else
  2785. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2786. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2787. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16,
  2788. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2789. #endif
  2790. if (bench_plain == NULL || bench_cipher == NULL) {
  2791. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2792. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2793. bench_plain = bench_cipher = NULL;
  2794. printf("%sBenchmark block buffer alloc failed!\n", err_prefix);
  2795. goto exit;
  2796. }
  2797. #ifndef NO_FILESYSTEM
  2798. if (hash_input) {
  2799. size_t rawSz;
  2800. XFILE file;
  2801. file = XFOPEN(hash_input, "rb");
  2802. if (file == XBADFILE)
  2803. goto exit;
  2804. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2805. XFCLOSE(file);
  2806. goto exit;
  2807. }
  2808. bench_buf_size = XFTELL(file);
  2809. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2810. XFCLOSE(file);
  2811. goto exit;
  2812. }
  2813. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2814. rawSz = (size_t)bench_buf_size;
  2815. if (bench_buf_size % 16)
  2816. bench_buf_size += 16 - (bench_buf_size % 16);
  2817. bench_size = (word32)bench_buf_size;
  2818. bench_plain = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2819. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2820. if (bench_plain == NULL) {
  2821. XFCLOSE(file);
  2822. goto exit;
  2823. }
  2824. if ((size_t)XFREAD(bench_plain, 1, rawSz, file)
  2825. != rawSz) {
  2826. XFCLOSE(file);
  2827. goto exit;
  2828. }
  2829. XFCLOSE(file);
  2830. }
  2831. else {
  2832. XMEMSET(bench_plain, 0, (size_t)bench_buf_size);
  2833. }
  2834. if (cipher_input) {
  2835. size_t rawSz;
  2836. XFILE file;
  2837. file = XFOPEN(cipher_input, "rb");
  2838. if (file == XBADFILE)
  2839. goto exit;
  2840. if (XFSEEK(file, 0, XSEEK_END) != 0) {
  2841. XFCLOSE(file);
  2842. goto exit;
  2843. }
  2844. bench_buf_size = XFTELL(file);
  2845. if(XFSEEK(file, 0, XSEEK_SET) != 0) {
  2846. XFCLOSE(file);
  2847. goto exit;
  2848. }
  2849. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2850. rawSz = (size_t)bench_buf_size;
  2851. if (bench_buf_size % 16)
  2852. bench_buf_size += 16 - (bench_buf_size % 16);
  2853. if (bench_size > (word32)bench_buf_size)
  2854. bench_size = (word32)bench_buf_size;
  2855. bench_cipher = (byte*)XMALLOC((size_t)bench_buf_size + 16*2,
  2856. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2857. if (bench_cipher == NULL) {
  2858. XFCLOSE(file);
  2859. goto exit;
  2860. }
  2861. if ((size_t)XFREAD(bench_cipher, 1, rawSz, file)
  2862. != rawSz) {
  2863. XFCLOSE(file);
  2864. goto exit;
  2865. }
  2866. XFCLOSE(file);
  2867. }
  2868. else {
  2869. XMEMSET(bench_cipher, 0, (size_t)bench_buf_size);
  2870. }
  2871. #endif
  2872. #if defined(WOLFSSL_ASYNC_CRYPT) || defined(HAVE_INTEL_QA_SYNC)
  2873. bench_key = (byte*)XMALLOC(sizeof(bench_key_buf),
  2874. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2875. bench_iv = (byte*)XMALLOC(sizeof(bench_iv_buf),
  2876. HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2877. if (bench_key == NULL || bench_iv == NULL) {
  2878. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2879. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  2880. bench_key = bench_iv = NULL;
  2881. printf("%sBenchmark cipher buffer alloc failed!\n", err_prefix);
  2882. goto exit;
  2883. }
  2884. XMEMCPY(bench_key, bench_key_buf, sizeof(bench_key_buf));
  2885. XMEMCPY(bench_iv, bench_iv_buf, sizeof(bench_iv_buf));
  2886. #elif defined(HAVE_RENESAS_SYNC)
  2887. bench_key1 = (byte*)guser_PKCbInfo.wrapped_key_aes128;
  2888. bench_key2 = (byte*)guser_PKCbInfo.wrapped_key_aes256;
  2889. bench_key = (byte*)bench_key_buf;
  2890. bench_iv = (byte*)bench_iv_buf;
  2891. #else
  2892. bench_key = (byte*)bench_key_buf;
  2893. bench_iv = (byte*)bench_iv_buf;
  2894. #endif
  2895. #ifndef WC_NO_RNG
  2896. if (bench_all || (bench_other_algs & BENCH_RNG))
  2897. bench_rng();
  2898. #endif /* WC_NO_RNG */
  2899. #ifndef NO_AES
  2900. #ifdef HAVE_AES_CBC
  2901. if (bench_all || (bench_cipher_algs & BENCH_AES_CBC)) {
  2902. #ifndef NO_SW_BENCH
  2903. bench_aescbc(0);
  2904. #endif
  2905. #if defined(BENCH_DEVID)
  2906. bench_aescbc(1);
  2907. #endif
  2908. }
  2909. #endif
  2910. #ifdef HAVE_AESGCM
  2911. if (bench_all || (bench_cipher_algs & BENCH_AES_GCM)) {
  2912. #ifndef NO_SW_BENCH
  2913. bench_aes_aad_options_wrap(bench_aesgcm, 0);
  2914. #endif
  2915. #if ((defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_3DES)) || \
  2916. defined(HAVE_INTEL_QA_SYNC) || defined(HAVE_CAVIUM_OCTEON_SYNC) || \
  2917. defined(HAVE_RENESAS_SYNC) || defined(WOLFSSL_CAAM)) || \
  2918. ((defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)) && \
  2919. defined(WOLF_CRYPTO_CB)) && !defined(NO_HW_BENCH)
  2920. bench_aes_aad_options_wrap(bench_aesgcm, 1);
  2921. #endif
  2922. #ifndef NO_SW_BENCH
  2923. bench_gmac(0);
  2924. #endif
  2925. #if defined(BENCH_DEVID)
  2926. bench_gmac(1);
  2927. #endif
  2928. }
  2929. #endif
  2930. #ifdef HAVE_AES_ECB
  2931. if (bench_all || (bench_cipher_algs & BENCH_AES_ECB)) {
  2932. #ifndef NO_SW_BENCH
  2933. bench_aesecb(0);
  2934. #endif
  2935. #ifdef BENCH_DEVID
  2936. bench_aesecb(1);
  2937. #endif
  2938. }
  2939. #endif
  2940. #ifdef WOLFSSL_AES_XTS
  2941. if (bench_all || (bench_cipher_algs & BENCH_AES_XTS))
  2942. bench_aesxts();
  2943. #endif
  2944. #ifdef WOLFSSL_AES_CFB
  2945. if (bench_all || (bench_cipher_algs & BENCH_AES_CFB))
  2946. bench_aescfb();
  2947. #endif
  2948. #ifdef WOLFSSL_AES_OFB
  2949. if (bench_all || (bench_cipher_algs & BENCH_AES_OFB))
  2950. bench_aesofb();
  2951. #endif
  2952. #ifdef WOLFSSL_AES_COUNTER
  2953. if (bench_all || (bench_cipher_algs & BENCH_AES_CTR)) {
  2954. bench_aesctr(0);
  2955. #ifdef BENCH_DEVID
  2956. bench_aesctr(1);
  2957. #endif
  2958. }
  2959. #endif
  2960. #ifdef HAVE_AESCCM
  2961. if (bench_all || (bench_cipher_algs & BENCH_AES_CCM)) {
  2962. bench_aes_aad_options_wrap(bench_aesccm, 0);
  2963. #ifdef BENCH_DEVID
  2964. bench_aes_aad_options_wrap(bench_aesccm, 1);
  2965. #endif
  2966. }
  2967. #endif
  2968. #ifdef WOLFSSL_AES_SIV
  2969. if (bench_all || (bench_cipher_algs & BENCH_AES_SIV))
  2970. bench_aessiv();
  2971. #endif
  2972. #endif /* !NO_AES */
  2973. #ifdef HAVE_CAMELLIA
  2974. if (bench_all || (bench_cipher_algs & BENCH_CAMELLIA))
  2975. bench_camellia();
  2976. #endif
  2977. #ifdef WOLFSSL_SM4_CBC
  2978. if (bench_all || (bench_cipher_algs & BENCH_SM4_CBC))
  2979. bench_sm4_cbc();
  2980. #endif
  2981. #ifdef WOLFSSL_SM4_GCM
  2982. if (bench_all || (bench_cipher_algs & BENCH_SM4_GCM))
  2983. bench_sm4_gcm();
  2984. #endif
  2985. #ifdef WOLFSSL_SM4_CCM
  2986. if (bench_all || (bench_cipher_algs & BENCH_SM4_CCM))
  2987. bench_sm4_ccm();
  2988. #endif
  2989. #ifndef NO_RC4
  2990. if (bench_all || (bench_cipher_algs & BENCH_ARC4)) {
  2991. #ifndef NO_SW_BENCH
  2992. bench_arc4(0);
  2993. #endif
  2994. #ifdef BENCH_DEVID
  2995. bench_arc4(1);
  2996. #endif
  2997. }
  2998. #endif
  2999. #ifdef HAVE_CHACHA
  3000. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20))
  3001. bench_chacha();
  3002. #endif
  3003. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  3004. if (bench_all || (bench_cipher_algs & BENCH_CHACHA20_POLY1305))
  3005. bench_chacha20_poly1305_aead();
  3006. #endif
  3007. #ifndef NO_DES3
  3008. if (bench_all || (bench_cipher_algs & BENCH_DES)) {
  3009. #ifndef NO_SW_BENCH
  3010. bench_des(0);
  3011. #endif
  3012. #ifdef BENCH_DEVID
  3013. bench_des(1);
  3014. #endif
  3015. }
  3016. #endif
  3017. #ifndef NO_MD5
  3018. if (bench_all || (bench_digest_algs & BENCH_MD5)) {
  3019. #ifndef NO_SW_BENCH
  3020. bench_md5(0);
  3021. #endif
  3022. #ifdef BENCH_DEVID
  3023. bench_md5(1);
  3024. #endif
  3025. }
  3026. #endif
  3027. #ifdef HAVE_POLY1305
  3028. if (bench_all || (bench_digest_algs & BENCH_POLY1305))
  3029. bench_poly1305();
  3030. #endif
  3031. #ifndef NO_SHA
  3032. if (bench_all || (bench_digest_algs & BENCH_SHA)) {
  3033. #ifndef NO_SW_BENCH
  3034. bench_sha(0);
  3035. #endif
  3036. #ifdef BENCH_DEVID
  3037. bench_sha(1);
  3038. #endif
  3039. }
  3040. #endif
  3041. #ifdef WOLFSSL_SHA224
  3042. if (bench_all || (bench_digest_algs & BENCH_SHA224)) {
  3043. #ifndef NO_SW_BENCH
  3044. bench_sha224(0);
  3045. #endif
  3046. #ifdef BENCH_DEVID
  3047. bench_sha224(1);
  3048. #endif
  3049. }
  3050. #endif
  3051. #ifndef NO_SHA256
  3052. if (bench_all || (bench_digest_algs & BENCH_SHA256)) {
  3053. #ifndef NO_SW_BENCH
  3054. bench_sha256(0);
  3055. #endif
  3056. #ifdef BENCH_DEVID
  3057. bench_sha256(1);
  3058. #endif
  3059. }
  3060. #endif
  3061. #ifdef WOLFSSL_SHA384
  3062. if (bench_all || (bench_digest_algs & BENCH_SHA384)) {
  3063. #ifndef NO_SW_BENCH
  3064. bench_sha384(0);
  3065. #endif
  3066. #ifdef BENCH_DEVID
  3067. bench_sha384(1);
  3068. #endif
  3069. }
  3070. #endif
  3071. #ifdef WOLFSSL_SHA512
  3072. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3073. #ifndef NO_SW_BENCH
  3074. bench_sha512(0);
  3075. #endif
  3076. #ifdef BENCH_DEVID
  3077. bench_sha512(1);
  3078. #endif
  3079. }
  3080. #if !defined(WOLFSSL_NOSHA512_224) && \
  3081. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3082. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3083. #ifndef NO_SW_BENCH
  3084. bench_sha512_224(0);
  3085. #endif
  3086. #ifdef BENCH_DEVID
  3087. bench_sha512_224(1);
  3088. #endif
  3089. }
  3090. #endif /* WOLFSSL_NOSHA512_224 */
  3091. #if !defined(WOLFSSL_NOSHA512_256) && \
  3092. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  3093. if (bench_all || (bench_digest_algs & BENCH_SHA512)) {
  3094. #ifndef NO_SW_BENCH
  3095. bench_sha512_256(0);
  3096. #endif
  3097. #ifdef BENCH_DEVID
  3098. bench_sha512_256(1);
  3099. #endif
  3100. }
  3101. #endif /* WOLFSSL_NOSHA512_256 */
  3102. #endif /* WOLFSSL_SHA512 */
  3103. #ifdef WOLFSSL_SHA3
  3104. #ifndef WOLFSSL_NOSHA3_224
  3105. if (bench_all || (bench_digest_algs & BENCH_SHA3_224)) {
  3106. #ifndef NO_SW_BENCH
  3107. bench_sha3_224(0);
  3108. #endif
  3109. #ifdef BENCH_DEVID
  3110. bench_sha3_224(1);
  3111. #endif
  3112. }
  3113. #endif /* WOLFSSL_NOSHA3_224 */
  3114. #ifndef WOLFSSL_NOSHA3_256
  3115. if (bench_all || (bench_digest_algs & BENCH_SHA3_256)) {
  3116. #ifndef NO_SW_BENCH
  3117. bench_sha3_256(0);
  3118. #endif
  3119. #ifdef BENCH_DEVID
  3120. bench_sha3_256(1);
  3121. #endif
  3122. }
  3123. #endif /* WOLFSSL_NOSHA3_256 */
  3124. #ifndef WOLFSSL_NOSHA3_384
  3125. if (bench_all || (bench_digest_algs & BENCH_SHA3_384)) {
  3126. #ifndef NO_SW_BENCH
  3127. bench_sha3_384(0);
  3128. #endif
  3129. #ifdef BENCH_DEVID
  3130. bench_sha3_384(1);
  3131. #endif
  3132. }
  3133. #endif /* WOLFSSL_NOSHA3_384 */
  3134. #ifndef WOLFSSL_NOSHA3_512
  3135. if (bench_all || (bench_digest_algs & BENCH_SHA3_512)) {
  3136. #ifndef NO_SW_BENCH
  3137. bench_sha3_512(0);
  3138. #endif
  3139. #ifdef BENCH_DEVID
  3140. bench_sha3_512(1);
  3141. #endif
  3142. }
  3143. #endif /* WOLFSSL_NOSHA3_512 */
  3144. #ifdef WOLFSSL_SHAKE128
  3145. if (bench_all || (bench_digest_algs & BENCH_SHAKE128)) {
  3146. #ifndef NO_SW_BENCH
  3147. bench_shake128(0);
  3148. #endif
  3149. #ifdef BENCH_DEVID
  3150. bench_shake128(1);
  3151. #endif
  3152. }
  3153. #endif /* WOLFSSL_SHAKE128 */
  3154. #ifdef WOLFSSL_SHAKE256
  3155. if (bench_all || (bench_digest_algs & BENCH_SHAKE256)) {
  3156. #ifndef NO_SW_BENCH
  3157. bench_shake256(0);
  3158. #endif
  3159. #ifdef BENCH_DEVID
  3160. bench_shake256(1);
  3161. #endif
  3162. }
  3163. #endif /* WOLFSSL_SHAKE256 */
  3164. #endif
  3165. #ifdef WOLFSSL_SM3
  3166. if (bench_all || (bench_digest_algs & BENCH_SM3)) {
  3167. #ifndef NO_SW_BENCH
  3168. bench_sm3(0);
  3169. #endif
  3170. #ifdef BENCH_DEVID
  3171. bench_sm3(1);
  3172. #endif
  3173. }
  3174. #endif
  3175. #ifdef WOLFSSL_RIPEMD
  3176. if (bench_all || (bench_digest_algs & BENCH_RIPEMD))
  3177. bench_ripemd();
  3178. #endif
  3179. #ifdef HAVE_BLAKE2
  3180. if (bench_all || (bench_digest_algs & BENCH_BLAKE2B))
  3181. bench_blake2b();
  3182. #endif
  3183. #ifdef HAVE_BLAKE2S
  3184. if (bench_all || (bench_digest_algs & BENCH_BLAKE2S))
  3185. bench_blake2s();
  3186. #endif
  3187. #ifdef WOLFSSL_CMAC
  3188. if (bench_all || (bench_mac_algs & BENCH_CMAC)) {
  3189. bench_cmac(0);
  3190. #ifdef BENCH_DEVID
  3191. bench_cmac(1);
  3192. #endif
  3193. }
  3194. #endif
  3195. #ifndef NO_HMAC
  3196. #ifndef NO_MD5
  3197. if (bench_all || (bench_mac_algs & BENCH_HMAC_MD5)) {
  3198. #ifndef NO_SW_BENCH
  3199. bench_hmac_md5(0);
  3200. #endif
  3201. #ifdef BENCH_DEVID
  3202. bench_hmac_md5(1);
  3203. #endif
  3204. }
  3205. #endif
  3206. #ifndef NO_SHA
  3207. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA)) {
  3208. #ifndef NO_SW_BENCH
  3209. bench_hmac_sha(0);
  3210. #endif
  3211. #ifdef BENCH_DEVID
  3212. bench_hmac_sha(1);
  3213. #endif
  3214. }
  3215. #endif
  3216. #ifdef WOLFSSL_SHA224
  3217. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA224)) {
  3218. #ifndef NO_SW_BENCH
  3219. bench_hmac_sha224(0);
  3220. #endif
  3221. #ifdef BENCH_DEVID
  3222. bench_hmac_sha224(1);
  3223. #endif
  3224. }
  3225. #endif
  3226. #ifndef NO_SHA256
  3227. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA256)) {
  3228. #ifndef NO_SW_BENCH
  3229. bench_hmac_sha256(0);
  3230. #endif
  3231. #ifdef BENCH_DEVID
  3232. bench_hmac_sha256(1);
  3233. #endif
  3234. }
  3235. #endif
  3236. #ifdef WOLFSSL_SHA384
  3237. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA384)) {
  3238. #ifndef NO_SW_BENCH
  3239. bench_hmac_sha384(0);
  3240. #endif
  3241. #ifdef BENCH_DEVID
  3242. bench_hmac_sha384(1);
  3243. #endif
  3244. }
  3245. #endif
  3246. #ifdef WOLFSSL_SHA512
  3247. if (bench_all || (bench_mac_algs & BENCH_HMAC_SHA512)) {
  3248. #ifndef NO_SW_BENCH
  3249. bench_hmac_sha512(0);
  3250. #endif
  3251. #ifdef BENCH_DEVID
  3252. bench_hmac_sha512(1);
  3253. #endif
  3254. }
  3255. #endif
  3256. #ifndef NO_PWDBASED
  3257. if (bench_all || (bench_mac_algs & BENCH_PBKDF2)) {
  3258. bench_pbkdf2();
  3259. }
  3260. #endif
  3261. #endif /* NO_HMAC */
  3262. #ifdef WOLFSSL_SIPHASH
  3263. if (bench_all || (bench_mac_algs & BENCH_SIPHASH)) {
  3264. bench_siphash();
  3265. }
  3266. #endif
  3267. #ifdef WC_SRTP_KDF
  3268. if (bench_all || (bench_kdf_algs & BENCH_SRTP_KDF)) {
  3269. bench_srtpkdf();
  3270. }
  3271. #endif
  3272. #ifdef HAVE_SCRYPT
  3273. if (bench_all || (bench_other_algs & BENCH_SCRYPT))
  3274. bench_scrypt();
  3275. #endif
  3276. #ifndef NO_RSA
  3277. #ifndef HAVE_RENESAS_SYNC
  3278. #ifdef WOLFSSL_KEY_GEN
  3279. if (bench_all || (bench_asym_algs & BENCH_RSA_KEYGEN)) {
  3280. #ifndef NO_SW_BENCH
  3281. if (((word32)bench_asym_algs == 0xFFFFFFFFU) ||
  3282. (bench_asym_algs & BENCH_RSA_SZ) == 0) {
  3283. bench_rsaKeyGen(0);
  3284. }
  3285. else {
  3286. bench_rsaKeyGen_size(0, bench_size);
  3287. }
  3288. #endif
  3289. #ifdef BENCH_DEVID
  3290. if (bench_asym_algs & BENCH_RSA_SZ) {
  3291. bench_rsaKeyGen_size(1, bench_size);
  3292. }
  3293. else {
  3294. bench_rsaKeyGen(1);
  3295. }
  3296. #endif
  3297. }
  3298. #endif
  3299. if (bench_all || (bench_asym_algs & BENCH_RSA)) {
  3300. #ifndef NO_SW_BENCH
  3301. bench_rsa(0);
  3302. #endif
  3303. #ifdef BENCH_DEVID
  3304. bench_rsa(1);
  3305. #endif
  3306. }
  3307. #ifdef WOLFSSL_KEY_GEN
  3308. if (bench_asym_algs & BENCH_RSA_SZ) {
  3309. #ifndef NO_SW_BENCH
  3310. bench_rsa_key(0, bench_size);
  3311. #endif
  3312. #ifdef BENCH_DEVID
  3313. bench_rsa_key(1, bench_size);
  3314. #endif
  3315. }
  3316. #endif
  3317. #endif
  3318. #endif
  3319. #ifndef NO_DH
  3320. if (bench_all || (bench_asym_algs & BENCH_DH)) {
  3321. #ifndef NO_SW_BENCH
  3322. bench_dh(0);
  3323. #endif
  3324. #ifdef BENCH_DEVID
  3325. bench_dh(1);
  3326. #endif
  3327. }
  3328. #endif
  3329. #ifdef WOLFSSL_HAVE_KYBER
  3330. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER)) {
  3331. #ifndef WOLFSSL_NO_ML_KEM
  3332. #ifdef WOLFSSL_KYBER512
  3333. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3334. bench_kyber(WC_ML_KEM_512);
  3335. }
  3336. #endif
  3337. #ifdef WOLFSSL_KYBER768
  3338. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3339. bench_kyber(WC_ML_KEM_768);
  3340. }
  3341. #endif
  3342. #ifdef WOLFSSL_KYBER1024
  3343. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3344. bench_kyber(WC_ML_KEM_1024);
  3345. }
  3346. #endif
  3347. #endif
  3348. #ifdef WOLFSSL_KYBER_ORIGINAL
  3349. #ifdef WOLFSSL_KYBER512
  3350. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER512)) {
  3351. bench_kyber(KYBER512);
  3352. }
  3353. #endif
  3354. #ifdef WOLFSSL_KYBER768
  3355. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER768)) {
  3356. bench_kyber(KYBER768);
  3357. }
  3358. #endif
  3359. #ifdef WOLFSSL_KYBER1024
  3360. if (bench_all || (bench_pq_asym_algs & BENCH_KYBER1024)) {
  3361. bench_kyber(KYBER1024);
  3362. }
  3363. #endif
  3364. #endif
  3365. }
  3366. #endif
  3367. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  3368. if (bench_all || (bench_pq_hash_sig_algs & BENCH_LMS_HSS)) {
  3369. bench_lms();
  3370. }
  3371. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  3372. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  3373. if (bench_all) {
  3374. bench_pq_hash_sig_algs |= BENCH_XMSS_XMSSMT;
  3375. }
  3376. #ifndef NO_SHA256
  3377. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA256) {
  3378. bench_xmss(WC_HASH_TYPE_SHA256);
  3379. }
  3380. #endif
  3381. #ifdef WOLFSSL_SHA512
  3382. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHA512) {
  3383. bench_xmss(WC_HASH_TYPE_SHA512);
  3384. }
  3385. #endif
  3386. #ifdef WOLFSSL_SHAKE128
  3387. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE128) {
  3388. bench_xmss(WC_HASH_TYPE_SHAKE128);
  3389. }
  3390. #endif
  3391. #ifdef WOLFSSL_SHAKE256
  3392. if (bench_pq_hash_sig_algs & BENCH_XMSS_XMSSMT_SHAKE256) {
  3393. bench_xmss(WC_HASH_TYPE_SHAKE256);
  3394. }
  3395. #endif
  3396. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  3397. #ifdef HAVE_ECC
  3398. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY) ||
  3399. (bench_asym_algs & BENCH_ECC) ||
  3400. (bench_asym_algs & BENCH_ECC_ALL) ||
  3401. (bench_asym_algs & BENCH_ECC_ENCRYPT)) {
  3402. if (bench_asym_algs & BENCH_ECC_ALL) {
  3403. #if defined(HAVE_FIPS) || defined(HAVE_SELFTEST)
  3404. printf("%snot supported in FIPS mode (no ending enum value)\n",
  3405. err_prefix);
  3406. #else
  3407. int curveId = (int)ECC_SECP192R1;
  3408. /* set make key and encrypt */
  3409. bench_asym_algs |= BENCH_ECC_MAKEKEY | BENCH_ECC |
  3410. BENCH_ECC_ENCRYPT;
  3411. if (csv_format != 1) {
  3412. printf("\n%sECC Benchmarks:\n", info_prefix);
  3413. }
  3414. do {
  3415. #ifdef WOLFCRYPT_HAVE_SAKKE
  3416. /* SAKKE is not usable with ECDH/ECDSA. Run separate test. */
  3417. if (curveId == ECC_SAKKE_1) {
  3418. curveId++;
  3419. continue;
  3420. }
  3421. #endif
  3422. if (wc_ecc_get_curve_size_from_id(curveId) !=
  3423. WC_NO_ERR_TRACE(ECC_BAD_ARG_E)) {
  3424. bench_ecc_curve(curveId);
  3425. if (csv_format != 1) {
  3426. printf("\n");
  3427. }
  3428. }
  3429. curveId++;
  3430. } while (curveId != (int)ECC_CURVE_MAX);
  3431. #endif
  3432. }
  3433. else if (bench_asym_algs & BENCH_ECC_P256) {
  3434. bench_ecc_curve((int)ECC_SECP256R1);
  3435. }
  3436. else if (bench_asym_algs & BENCH_ECC_P384) {
  3437. bench_ecc_curve((int)ECC_SECP384R1);
  3438. }
  3439. else if (bench_asym_algs & BENCH_ECC_P521) {
  3440. bench_ecc_curve((int)ECC_SECP521R1);
  3441. }
  3442. else {
  3443. #ifndef NO_ECC256
  3444. bench_ecc_curve((int)ECC_SECP256R1);
  3445. #elif defined(HAVE_ECC384)
  3446. bench_ecc_curve((int)ECC_SECP384R1);
  3447. #elif defined(HAVE_ECC521)
  3448. bench_ecc_curve((int)ECC_SECP521R1);
  3449. #endif
  3450. #ifdef HAVE_ECC_BRAINPOOL
  3451. bench_ecc_curve((int)ECC_BRAINPOOLP256R1);
  3452. #endif
  3453. }
  3454. }
  3455. #endif
  3456. #ifdef WOLFSSL_SM2
  3457. if (bench_all || (bench_asym_algs & BENCH_SM2)) {
  3458. bench_sm2(0);
  3459. }
  3460. #endif
  3461. #ifdef HAVE_CURVE25519
  3462. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KEYGEN)) {
  3463. bench_curve25519KeyGen(0);
  3464. #ifdef BENCH_DEVID
  3465. bench_curve25519KeyGen(1);
  3466. #endif
  3467. }
  3468. #ifdef HAVE_CURVE25519_SHARED_SECRET
  3469. if (bench_all || (bench_asym_algs & BENCH_CURVE25519_KA)) {
  3470. bench_curve25519KeyAgree(0);
  3471. #ifdef BENCH_DEVID
  3472. bench_curve25519KeyAgree(1);
  3473. #endif
  3474. }
  3475. #endif
  3476. #endif
  3477. #ifdef HAVE_ED25519
  3478. if (bench_all || (bench_asym_algs & BENCH_ED25519_KEYGEN))
  3479. bench_ed25519KeyGen();
  3480. if (bench_all || (bench_asym_algs & BENCH_ED25519_SIGN))
  3481. bench_ed25519KeySign();
  3482. #endif
  3483. #ifdef HAVE_CURVE448
  3484. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KEYGEN))
  3485. bench_curve448KeyGen();
  3486. #ifdef HAVE_CURVE448_SHARED_SECRET
  3487. if (bench_all || (bench_asym_algs & BENCH_CURVE448_KA))
  3488. bench_curve448KeyAgree();
  3489. #endif
  3490. #endif
  3491. #ifdef HAVE_ED448
  3492. if (bench_all || (bench_asym_algs & BENCH_ED448_KEYGEN))
  3493. bench_ed448KeyGen();
  3494. if (bench_all || (bench_asym_algs & BENCH_ED448_SIGN))
  3495. bench_ed448KeySign();
  3496. #endif
  3497. #ifdef WOLFCRYPT_HAVE_ECCSI
  3498. #ifdef WOLFCRYPT_ECCSI_KMS
  3499. if (bench_all || (bench_asym_algs & BENCH_ECCSI_KEYGEN)) {
  3500. bench_eccsiKeyGen();
  3501. }
  3502. if (bench_all || (bench_asym_algs & BENCH_ECCSI_PAIRGEN)) {
  3503. bench_eccsiPairGen();
  3504. }
  3505. #endif
  3506. #ifdef WOLFCRYPT_ECCSI_CLIENT
  3507. if (bench_all || (bench_asym_algs & BENCH_ECCSI_VALIDATE)) {
  3508. bench_eccsiValidate();
  3509. }
  3510. if (bench_all || (bench_asym_algs & BENCH_ECCSI)) {
  3511. bench_eccsi();
  3512. }
  3513. #endif
  3514. #endif
  3515. #ifdef WOLFCRYPT_HAVE_SAKKE
  3516. #ifdef WOLFCRYPT_SAKKE_KMS
  3517. if (bench_all || (bench_asym_algs & BENCH_SAKKE_KEYGEN)) {
  3518. bench_sakkeKeyGen();
  3519. }
  3520. if (bench_all || (bench_asym_algs & BENCH_SAKKE_RSKGEN)) {
  3521. bench_sakkeRskGen();
  3522. }
  3523. #endif
  3524. #ifdef WOLFCRYPT_SAKKE_CLIENT
  3525. if (bench_all || (bench_asym_algs & BENCH_SAKKE_VALIDATE)) {
  3526. bench_sakkeValidate();
  3527. }
  3528. if (bench_all || (bench_asym_algs & BENCH_SAKKE)) {
  3529. bench_sakke();
  3530. }
  3531. #endif
  3532. #endif
  3533. #ifdef HAVE_FALCON
  3534. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL1_SIGN))
  3535. bench_falconKeySign(1);
  3536. if (bench_all || (bench_pq_asym_algs & BENCH_FALCON_LEVEL5_SIGN))
  3537. bench_falconKeySign(5);
  3538. #endif
  3539. #ifdef HAVE_DILITHIUM
  3540. #ifndef WOLFSSL_NO_ML_DSA_44
  3541. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL2_SIGN))
  3542. bench_dilithiumKeySign(2);
  3543. #endif
  3544. #ifndef WOLFSSL_NO_ML_DSA_65
  3545. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL3_SIGN))
  3546. bench_dilithiumKeySign(3);
  3547. #endif
  3548. #ifndef WOLFSSL_NO_ML_DSA_87
  3549. if (bench_all || (bench_pq_asym_algs & BENCH_DILITHIUM_LEVEL5_SIGN))
  3550. bench_dilithiumKeySign(5);
  3551. #endif
  3552. #endif
  3553. #ifdef HAVE_SPHINCS
  3554. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL1_SIGN))
  3555. bench_sphincsKeySign(1, FAST_VARIANT);
  3556. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL3_SIGN))
  3557. bench_sphincsKeySign(3, FAST_VARIANT);
  3558. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_FAST_LEVEL5_SIGN))
  3559. bench_sphincsKeySign(5, FAST_VARIANT);
  3560. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL1_SIGN))
  3561. bench_sphincsKeySign(1, SMALL_VARIANT);
  3562. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL3_SIGN))
  3563. bench_sphincsKeySign(3, SMALL_VARIANT);
  3564. if (bench_all || (bench_pq_asym_algs2 & BENCH_SPHINCS_SMALL_LEVEL5_SIGN))
  3565. bench_sphincsKeySign(5, SMALL_VARIANT);
  3566. #endif
  3567. exit:
  3568. /* free benchmark buffers */
  3569. XFREE(bench_plain, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3570. XFREE(bench_cipher, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3571. #ifdef WOLFSSL_ASYNC_CRYPT
  3572. XFREE(bench_key, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3573. XFREE(bench_iv, HEAP_HINT, DYNAMIC_TYPE_WOLF_BIGINT);
  3574. #endif
  3575. #if defined(HAVE_LOCAL_RNG)
  3576. wc_FreeRng(&gRng);
  3577. #endif
  3578. /* cleanup the thread if fixed point cache is enabled and have thread local */
  3579. #if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC)
  3580. wc_ecc_fp_free();
  3581. #endif
  3582. (void)bench_cipher_algs;
  3583. (void)bench_digest_algs;
  3584. (void)bench_mac_algs;
  3585. (void)bench_asym_algs;
  3586. (void)bench_other_algs;
  3587. (void)bench_pq_asym_algs;
  3588. (void)bench_pq_asym_algs2;
  3589. return NULL;
  3590. }
  3591. int benchmark_init(void)
  3592. {
  3593. int ret = 0;
  3594. benchmark_static_init(0);
  3595. #ifdef WOLFSSL_STATIC_MEMORY
  3596. ret = wc_LoadStaticMemory(&HEAP_HINT, gBenchMemory,
  3597. sizeof(gBenchMemory), WOLFMEM_GENERAL, 1);
  3598. if (ret != 0) {
  3599. printf("%sunable to load static memory %d\n", err_prefix, ret);
  3600. }
  3601. #endif /* WOLFSSL_STATIC_MEMORY */
  3602. if ((ret = wolfCrypt_Init()) != 0) {
  3603. printf("%swolfCrypt_Init failed %d\n", err_prefix, ret);
  3604. return EXIT_FAILURE;
  3605. }
  3606. #ifdef HAVE_WC_INTROSPECTION
  3607. printf("Math: %s\n", wc_GetMathInfo());
  3608. #endif
  3609. #ifdef WOLFSSL_SECO_CAAM
  3610. if (wc_SECO_OpenHSM(SECO_KEY_STORE_ID,
  3611. SECO_BENCHMARK_NONCE, SECO_MAX_UPDATES, CAAM_KEYSTORE_CREATE)
  3612. != 0) {
  3613. printf("%sunable to open HSM\n", err_prefix);
  3614. wolfCrypt_Cleanup();
  3615. return EXIT_FAILURE;
  3616. }
  3617. #endif
  3618. #ifdef WC_RNG_SEED_CB
  3619. wc_SetSeed_Cb(wc_GenerateSeed);
  3620. #endif
  3621. bench_stats_init();
  3622. #if defined(DEBUG_WOLFSSL) && !defined(HAVE_VALGRIND)
  3623. wolfSSL_Debugging_ON();
  3624. #endif
  3625. printf("%swolfCrypt Benchmark (block bytes %d, min " FLT_FMT_PREC " sec each)\n",
  3626. info_prefix, (int)bench_size, FLT_FMT_PREC_ARGS(1, BENCH_MIN_RUNTIME_SEC));
  3627. #ifndef GENERATE_MACHINE_PARSEABLE_REPORT
  3628. if (csv_format == 1) {
  3629. printf("This format allows you to easily copy "
  3630. "the output to a csv file.");
  3631. }
  3632. #endif
  3633. #ifdef HAVE_WNR
  3634. ret = wc_InitNetRandom(wnrConfigFile, NULL, 5000);
  3635. if (ret != 0) {
  3636. printf("%sWhitewood netRandom config init failed %d\n",
  3637. err_prefix, ret);
  3638. }
  3639. #endif /* HAVE_WNR */
  3640. return ret;
  3641. }
  3642. int benchmark_free(void)
  3643. {
  3644. int ret;
  3645. #ifdef WC_BENCH_TRACK_STATS
  3646. if (gPrintStats || devId != INVALID_DEVID) {
  3647. bench_stats_print();
  3648. }
  3649. #endif
  3650. bench_stats_free();
  3651. #ifdef WOLF_CRYPTO_CB
  3652. #ifdef HAVE_INTEL_QA_SYNC
  3653. wc_CryptoCb_CleanupIntelQa(&devId);
  3654. #endif
  3655. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  3656. wc_CryptoCb_CleanupOcteon(&devId);
  3657. #endif
  3658. #ifdef HAVE_RENESAS_SYNC
  3659. wc_CryptoCb_CleanupRenesasCmn(&devId);
  3660. #endif
  3661. #endif
  3662. #ifdef WOLFSSL_ASYNC_CRYPT
  3663. /* free event queue */
  3664. wolfEventQueue_Free(&eventQueue);
  3665. /* close device */
  3666. wolfAsync_DevClose(&devId);
  3667. #endif
  3668. #ifdef HAVE_WNR
  3669. ret = wc_FreeNetRandom();
  3670. if (ret < 0) {
  3671. printf("%sFailed to free netRandom context %d\n", err_prefix, ret);
  3672. }
  3673. #endif
  3674. #ifdef WOLFSSL_SECO_CAAM
  3675. if (wc_SECO_CloseHSM() != 0) {
  3676. printf("%sError closing down the key store\n", err_prefix);
  3677. }
  3678. #endif
  3679. if ((ret = wolfCrypt_Cleanup()) != 0) {
  3680. printf("%serror %d with wolfCrypt_Cleanup\n", err_prefix, ret);
  3681. }
  3682. return ret;
  3683. }
  3684. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  3685. static THREAD_RETURN WOLFSSL_THREAD run_bench(void* args)
  3686. {
  3687. benchmark_test(args);
  3688. EXIT_TEST(0);
  3689. }
  3690. static int benchmark_test_threaded(void* args)
  3691. {
  3692. int i;
  3693. printf("%sThreads: %d\n", info_prefix, g_threadCount);
  3694. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3695. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3696. if (g_threadData == NULL) {
  3697. printf("%sThread data alloc failed!\n", err_prefix);
  3698. return EXIT_FAILURE;
  3699. }
  3700. for (i = 0; i < g_threadCount; i++) {
  3701. THREAD_CHECK_RET(pthread_create(&g_threadData[i].thread_id,
  3702. NULL, run_bench, args));
  3703. }
  3704. for (i = 0; i < g_threadCount; i++) {
  3705. THREAD_CHECK_RET(pthread_join(g_threadData[i].thread_id, 0));
  3706. }
  3707. printf("\n");
  3708. bench_stats_print();
  3709. return 0;
  3710. }
  3711. #endif
  3712. /* so embedded projects can pull in tests on their own */
  3713. #ifdef HAVE_STACK_SIZE
  3714. THREAD_RETURN WOLFSSL_THREAD benchmark_test(void* args)
  3715. #else
  3716. int benchmark_test(void *args)
  3717. #endif
  3718. {
  3719. int ret;
  3720. (void)args;
  3721. #ifdef HAVE_FIPS
  3722. wolfCrypt_SetCb_fips(myFipsCb);
  3723. #endif
  3724. ret = benchmark_init();
  3725. if (ret != 0)
  3726. EXIT_TEST(ret);
  3727. #if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_NO_ASYNC_THREADING)
  3728. {
  3729. /* See the documentation when turning on WOLFSSL_ASYNC_CRYPT
  3730. **
  3731. ** Chapter Two, Build Options:
  3732. **
  3733. ** https://www.wolfssl.com/documentation/manuals/wolfssl/wolfSSL-Manual.pdf
  3734. **
  3735. ** asynchronous cryptography using hardware based adapters such as
  3736. ** the Intel QuickAssist or Marvell (Cavium) Nitrox V.
  3737. */
  3738. int i;
  3739. if (g_threadCount == 0) {
  3740. #ifdef WC_ASYNC_BENCH_THREAD_COUNT
  3741. g_threadCount = WC_ASYNC_BENCH_THREAD_COUNT;
  3742. #else
  3743. g_threadCount = wc_AsyncGetNumberOfCpus();
  3744. if (g_threadCount > 0) {
  3745. g_threadCount /= 2; /* use physical core count */
  3746. }
  3747. #endif
  3748. }
  3749. if (g_threadCount <= 0) {
  3750. g_threadCount = 1;
  3751. }
  3752. printf("%sCPUs: %d\n", info_prefix, g_threadCount);
  3753. g_threadData = (ThreadData*)XMALLOC(sizeof(ThreadData) * g_threadCount,
  3754. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3755. if (g_threadData == NULL) {
  3756. printf("%sThread data alloc failed!\n", err_prefix);
  3757. EXIT_TEST(EXIT_FAILURE);
  3758. }
  3759. /* Create threads */
  3760. for (i = 0; i < g_threadCount; i++) {
  3761. ret = wc_AsyncThreadCreate(&g_threadData[i].thread_id,
  3762. benchmarks_do, &g_threadData[i]);
  3763. if (ret != 0) {
  3764. printf("%sError creating benchmark thread %d\n", err_prefix, ret);
  3765. EXIT_TEST(EXIT_FAILURE);
  3766. }
  3767. }
  3768. /* Start threads */
  3769. for (i = 0; i < g_threadCount; i++) {
  3770. wc_AsyncThreadJoin(&g_threadData[i].thread_id);
  3771. }
  3772. XFREE(g_threadData, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  3773. }
  3774. #else
  3775. benchmarks_do(NULL);
  3776. #endif
  3777. SLEEP_ON_ERROR(1);
  3778. printf("%sBenchmark complete\n", info_prefix);
  3779. ret = benchmark_free();
  3780. EXIT_TEST(ret);
  3781. }
  3782. #ifndef WC_NO_RNG
  3783. void bench_rng(void)
  3784. {
  3785. int ret, i, count;
  3786. double start;
  3787. long pos, len, remain;
  3788. WC_RNG myrng;
  3789. DECLARE_MULTI_VALUE_STATS_VARS()
  3790. #ifndef HAVE_FIPS
  3791. ret = wc_InitRng_ex(&myrng, HEAP_HINT, devId);
  3792. #else
  3793. ret = wc_InitRng(&myrng);
  3794. #endif
  3795. if (ret < 0) {
  3796. printf("InitRNG failed %d\n", ret);
  3797. return;
  3798. }
  3799. bench_stats_start(&count, &start);
  3800. do {
  3801. for (i = 0; i < numBlocks; i++) {
  3802. /* Split request to handle large RNG request */
  3803. pos = 0;
  3804. remain = (int)bench_size;
  3805. while (remain > 0) {
  3806. len = remain;
  3807. if (len > RNG_MAX_BLOCK_LEN)
  3808. len = RNG_MAX_BLOCK_LEN;
  3809. ret = wc_RNG_GenerateBlock(&myrng, &bench_plain[pos],
  3810. (word32)len);
  3811. if (ret < 0)
  3812. goto exit_rng;
  3813. remain -= len;
  3814. pos += len;
  3815. }
  3816. RECORD_MULTI_VALUE_STATS();
  3817. }
  3818. count += i;
  3819. } while (bench_stats_check(start)
  3820. #ifdef MULTI_VALUE_STATISTICS
  3821. || runs < minimum_runs
  3822. #endif
  3823. );
  3824. exit_rng:
  3825. bench_stats_sym_finish("RNG", 0, count, bench_size, start, ret);
  3826. #ifdef MULTI_VALUE_STATISTICS
  3827. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3828. #endif
  3829. wc_FreeRng(&myrng);
  3830. }
  3831. #endif /* WC_NO_RNG */
  3832. #ifndef NO_AES
  3833. #ifdef HAVE_AES_CBC
  3834. static void bench_aescbc_internal(int useDeviceID,
  3835. const byte* key, word32 keySz,
  3836. const byte* iv, const char* encLabel,
  3837. const char* decLabel)
  3838. {
  3839. const byte* in = bench_cipher;
  3840. byte* out = bench_plain;
  3841. int ret = 0, i, count = 0, times, pending = 0;
  3842. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3843. sizeof(Aes), HEAP_HINT);
  3844. double start;
  3845. DECLARE_MULTI_VALUE_STATS_VARS()
  3846. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3847. sizeof(Aes), HEAP_HINT);
  3848. /* init keys */
  3849. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3850. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  3851. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  3852. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  3853. goto exit;
  3854. }
  3855. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_ENCRYPTION);
  3856. if (ret != 0) {
  3857. printf("AesSetKey failed, ret = %d\n", ret);
  3858. goto exit;
  3859. }
  3860. }
  3861. if (cipher_same_buffer) {
  3862. in = bench_plain;
  3863. }
  3864. bench_stats_start(&count, &start);
  3865. do {
  3866. for (times = 0; times < numBlocks || pending > 0; ) {
  3867. bench_async_poll(&pending);
  3868. /* while free pending slots in queue, submit ops */
  3869. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3870. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3871. &times, numBlocks, &pending)) {
  3872. ret = wc_AesCbcEncrypt(enc[i], out, in, bench_size);
  3873. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3874. 0, &times, &pending)) {
  3875. goto exit_aes_enc;
  3876. }
  3877. }
  3878. } /* for i */
  3879. RECORD_MULTI_VALUE_STATS();
  3880. } /* for times */
  3881. count += times;
  3882. } while (bench_stats_check(start)
  3883. #ifdef MULTI_VALUE_STATISTICS
  3884. || runs < minimum_runs
  3885. #endif
  3886. );
  3887. exit_aes_enc:
  3888. bench_stats_sym_finish(encLabel, useDeviceID, count,
  3889. bench_size, start, ret);
  3890. #ifdef MULTI_VALUE_STATISTICS
  3891. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3892. #endif
  3893. if (ret < 0) {
  3894. goto exit;
  3895. }
  3896. #ifdef HAVE_AES_DECRYPT
  3897. /* init keys */
  3898. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3899. ret = wc_AesSetKey(enc[i], key, keySz, iv, AES_DECRYPTION);
  3900. if (ret != 0) {
  3901. printf("AesSetKey failed, ret = %d\n", ret);
  3902. goto exit;
  3903. }
  3904. }
  3905. RESET_MULTI_VALUE_STATS_VARS();
  3906. bench_stats_start(&count, &start);
  3907. do {
  3908. for (times = 0; times < numBlocks || pending > 0; ) {
  3909. bench_async_poll(&pending);
  3910. /* while free pending slots in queue, submit ops */
  3911. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3912. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  3913. &times, numBlocks, &pending)) {
  3914. ret = wc_AesCbcDecrypt(enc[i], out, in, bench_size);
  3915. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  3916. 0, &times, &pending)) {
  3917. goto exit_aes_dec;
  3918. }
  3919. }
  3920. } /* for i */
  3921. RECORD_MULTI_VALUE_STATS();
  3922. } /* for times */
  3923. count += times;
  3924. } while (bench_stats_check(start)
  3925. #ifdef MULTI_VALUE_STATISTICS
  3926. || runs < minimum_runs
  3927. #endif
  3928. );
  3929. exit_aes_dec:
  3930. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  3931. start, ret);
  3932. #ifdef MULTI_VALUE_STATISTICS
  3933. bench_multi_value_stats(max, min, sum, squareSum, runs);
  3934. #endif
  3935. #endif /* HAVE_AES_DECRYPT */
  3936. (void)decLabel;
  3937. exit:
  3938. if (WC_ARRAY_OK(enc)) {
  3939. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  3940. wc_AesFree(enc[i]);
  3941. }
  3942. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  3943. }
  3944. }
  3945. void bench_aescbc(int useDeviceID)
  3946. {
  3947. #ifdef WOLFSSL_AES_128
  3948. #ifdef HAVE_RENESAS_SYNC
  3949. bench_aescbc_internal(useDeviceID, bench_key1, 16, bench_iv,
  3950. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3951. #else
  3952. bench_aescbc_internal(useDeviceID, bench_key, 16, bench_iv,
  3953. "AES-128-CBC-enc", "AES-128-CBC-dec");
  3954. #endif
  3955. #endif
  3956. #ifdef WOLFSSL_AES_192
  3957. bench_aescbc_internal(useDeviceID, bench_key, 24, bench_iv,
  3958. "AES-192-CBC-enc", "AES-192-CBC-dec");
  3959. #endif
  3960. #ifdef WOLFSSL_AES_256
  3961. #ifdef HAVE_RENESAS_SYNC
  3962. bench_aescbc_internal(useDeviceID, bench_key2, 32, bench_iv,
  3963. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3964. #else
  3965. bench_aescbc_internal(useDeviceID, bench_key, 32, bench_iv,
  3966. "AES-256-CBC-enc", "AES-256-CBC-dec");
  3967. #endif
  3968. #endif
  3969. }
  3970. #endif /* HAVE_AES_CBC */
  3971. #ifdef HAVE_AESGCM
  3972. static void bench_aesgcm_internal(int useDeviceID,
  3973. const byte* key, word32 keySz,
  3974. const byte* iv, word32 ivSz,
  3975. const char* encLabel, const char* decLabel)
  3976. {
  3977. int ret = 0, i, count = 0, times, pending = 0;
  3978. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3979. sizeof(Aes), HEAP_HINT);
  3980. #ifdef HAVE_AES_DECRYPT
  3981. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3982. sizeof(Aes), HEAP_HINT);
  3983. #endif
  3984. double start;
  3985. DECLARE_MULTI_VALUE_STATS_VARS()
  3986. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3987. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3988. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  3989. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  3990. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  3991. sizeof(Aes), HEAP_HINT);
  3992. #ifdef HAVE_AES_DECRYPT
  3993. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  3994. sizeof(Aes), HEAP_HINT);
  3995. #endif
  3996. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  3997. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  3998. /* init keys */
  3999. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4000. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4001. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4002. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4003. goto exit;
  4004. }
  4005. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4006. if (ret != 0) {
  4007. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4008. goto exit;
  4009. }
  4010. }
  4011. /* GCM uses same routine in backend for both encrypt and decrypt */
  4012. bench_stats_start(&count, &start);
  4013. do {
  4014. for (times = 0; times < numBlocks || pending > 0; ) {
  4015. bench_async_poll(&pending);
  4016. /* while free pending slots in queue, submit ops */
  4017. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4018. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4019. &times, numBlocks, &pending)) {
  4020. ret = wc_AesGcmEncrypt(enc[i], bench_cipher,
  4021. bench_plain, bench_size,
  4022. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4023. bench_additional, aesAuthAddSz);
  4024. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4025. 0, &times, &pending)) {
  4026. goto exit_aes_gcm;
  4027. }
  4028. }
  4029. } /* for i */
  4030. RECORD_MULTI_VALUE_STATS();
  4031. } /* for times */
  4032. count += times;
  4033. } while (bench_stats_check(start)
  4034. #ifdef MULTI_VALUE_STATISTICS
  4035. || runs < minimum_runs
  4036. #endif
  4037. );
  4038. exit_aes_gcm:
  4039. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4040. start, ret);
  4041. #ifdef MULTI_VALUE_STATISTICS
  4042. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4043. #endif
  4044. #ifdef HAVE_AES_DECRYPT
  4045. RESET_MULTI_VALUE_STATS_VARS();
  4046. /* init keys */
  4047. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4048. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4049. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4050. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4051. goto exit;
  4052. }
  4053. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4054. if (ret != 0) {
  4055. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4056. goto exit;
  4057. }
  4058. }
  4059. bench_stats_start(&count, &start);
  4060. do {
  4061. for (times = 0; times < numBlocks || pending > 0; ) {
  4062. bench_async_poll(&pending);
  4063. /* while free pending slots in queue, submit ops */
  4064. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4065. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4066. &times, numBlocks, &pending)) {
  4067. ret = wc_AesGcmDecrypt(dec[i], bench_plain,
  4068. bench_cipher, bench_size,
  4069. iv, ivSz, bench_tag, AES_AUTH_TAG_SZ,
  4070. bench_additional, aesAuthAddSz);
  4071. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4072. 0, &times, &pending)) {
  4073. goto exit_aes_gcm_dec;
  4074. }
  4075. }
  4076. } /* for i */
  4077. RECORD_MULTI_VALUE_STATS();
  4078. } /* for times */
  4079. count += times;
  4080. } while (bench_stats_check(start)
  4081. #ifdef MULTI_VALUE_STATISTICS
  4082. || runs < minimum_runs
  4083. #endif
  4084. );
  4085. exit_aes_gcm_dec:
  4086. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4087. start, ret);
  4088. #ifdef MULTI_VALUE_STATISTICS
  4089. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4090. #endif
  4091. #endif /* HAVE_AES_DECRYPT */
  4092. (void)decLabel;
  4093. exit:
  4094. if (ret < 0) {
  4095. printf("bench_aesgcm failed: %d\n", ret);
  4096. }
  4097. #ifdef HAVE_AES_DECRYPT
  4098. if (WC_ARRAY_OK(dec)) {
  4099. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4100. wc_AesFree(dec[i]);
  4101. }
  4102. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4103. }
  4104. #endif
  4105. if (WC_ARRAY_OK(enc)) {
  4106. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4107. wc_AesFree(enc[i]);
  4108. }
  4109. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4110. }
  4111. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4112. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4113. }
  4114. #ifdef WOLFSSL_AESGCM_STREAM
  4115. static void bench_aesgcm_stream_internal(int useDeviceID,
  4116. const byte* key, word32 keySz, const byte* iv, word32 ivSz,
  4117. const char* encLabel, const char* decLabel)
  4118. {
  4119. int ret = 0, i, count = 0, times, pending = 0;
  4120. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4121. sizeof(Aes), HEAP_HINT);
  4122. #ifdef HAVE_AES_DECRYPT
  4123. WC_DECLARE_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4124. sizeof(Aes), HEAP_HINT);
  4125. #endif
  4126. double start;
  4127. DECLARE_MULTI_VALUE_STATS_VARS()
  4128. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4129. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4130. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4131. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4132. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4133. sizeof(Aes), HEAP_HINT);
  4134. #ifdef HAVE_AES_DECRYPT
  4135. WC_CALLOC_ARRAY(dec, Aes, BENCH_MAX_PENDING,
  4136. sizeof(Aes), HEAP_HINT);
  4137. #endif
  4138. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4139. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4140. /* init keys */
  4141. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4142. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4143. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4144. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4145. goto exit;
  4146. }
  4147. ret = wc_AesGcmSetKey(enc[i], key, keySz);
  4148. if (ret != 0) {
  4149. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4150. goto exit;
  4151. }
  4152. }
  4153. /* GCM uses same routine in backend for both encrypt and decrypt */
  4154. bench_stats_start(&count, &start);
  4155. do {
  4156. for (times = 0; times < numBlocks || pending > 0; ) {
  4157. bench_async_poll(&pending);
  4158. /* while free pending slots in queue, submit ops */
  4159. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4160. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4161. &times, numBlocks, &pending)) {
  4162. ret = wc_AesGcmEncryptInit(enc[i], NULL, 0, iv, ivSz);
  4163. if (ret == 0) {
  4164. ret = wc_AesGcmEncryptUpdate(enc[i], bench_cipher,
  4165. bench_plain, bench_size, bench_additional,
  4166. aesAuthAddSz);
  4167. }
  4168. if (ret == 0) {
  4169. ret = wc_AesGcmEncryptFinal(enc[i], bench_tag,
  4170. AES_AUTH_TAG_SZ);
  4171. }
  4172. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4173. 0, &times, &pending)) {
  4174. goto exit_aes_gcm;
  4175. }
  4176. }
  4177. } /* for i */
  4178. RECORD_MULTI_VALUE_STATS();
  4179. } /* for times */
  4180. count += times;
  4181. } while (bench_stats_check(start)
  4182. #ifdef MULTI_VALUE_STATISTICS
  4183. || runs < minimum_runs
  4184. #endif
  4185. );
  4186. exit_aes_gcm:
  4187. bench_stats_sym_finish(encLabel, useDeviceID, count, bench_size,
  4188. start, ret);
  4189. #ifdef MULTI_VALUE_STATISTICS
  4190. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4191. #endif
  4192. #ifdef HAVE_AES_DECRYPT
  4193. /* init keys */
  4194. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4195. if ((ret = wc_AesInit(dec[i], HEAP_HINT,
  4196. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4197. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4198. goto exit;
  4199. }
  4200. ret = wc_AesGcmSetKey(dec[i], key, keySz);
  4201. if (ret != 0) {
  4202. printf("AesGcmSetKey failed, ret = %d\n", ret);
  4203. goto exit;
  4204. }
  4205. }
  4206. RESET_MULTI_VALUE_STATS_VARS();
  4207. bench_stats_start(&count, &start);
  4208. do {
  4209. for (times = 0; times < numBlocks || pending > 0; ) {
  4210. bench_async_poll(&pending);
  4211. /* while free pending slots in queue, submit ops */
  4212. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4213. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dec[i]), 0,
  4214. &times, numBlocks, &pending)) {
  4215. ret = wc_AesGcmDecryptInit(enc[i], NULL, 0, iv, ivSz);
  4216. if (ret == 0) {
  4217. ret = wc_AesGcmDecryptUpdate(enc[i], bench_plain,
  4218. bench_cipher, bench_size, bench_additional,
  4219. aesAuthAddSz);
  4220. }
  4221. if (ret == 0) {
  4222. ret = wc_AesGcmDecryptFinal(enc[i], bench_tag,
  4223. AES_AUTH_TAG_SZ);
  4224. }
  4225. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(dec[i]),
  4226. 0, &times, &pending)) {
  4227. goto exit_aes_gcm_dec;
  4228. }
  4229. }
  4230. } /* for i */
  4231. RECORD_MULTI_VALUE_STATS();
  4232. } /* for times */
  4233. count += times;
  4234. } while (bench_stats_check(start)
  4235. #ifdef MULTI_VALUE_STATISTICS
  4236. || runs < minimum_runs
  4237. #endif
  4238. );
  4239. exit_aes_gcm_dec:
  4240. bench_stats_sym_finish(decLabel, useDeviceID, count, bench_size,
  4241. start, ret);
  4242. #ifdef MULTI_VALUE_STATISTICS
  4243. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4244. #endif
  4245. #endif /* HAVE_AES_DECRYPT */
  4246. (void)decLabel;
  4247. exit:
  4248. if (ret < 0) {
  4249. printf("bench_aesgcm failed: %d\n", ret);
  4250. }
  4251. #ifdef HAVE_AES_DECRYPT
  4252. if (WC_ARRAY_OK(dec)) {
  4253. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4254. wc_AesFree(dec[i]);
  4255. }
  4256. WC_FREE_ARRAY(dec, BENCH_MAX_PENDING, HEAP_HINT);
  4257. }
  4258. #endif
  4259. if (WC_ARRAY_OK(enc)) {
  4260. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4261. wc_AesFree(enc[i]);
  4262. }
  4263. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4264. }
  4265. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4266. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4267. }
  4268. #endif
  4269. void bench_aesgcm(int useDeviceID)
  4270. {
  4271. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-" #dir)
  4272. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4273. && !defined(WOLFSSL_XILINX_CRYPT) \
  4274. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4275. #ifdef HAVE_RENESAS_SYNC
  4276. bench_aesgcm_internal(useDeviceID, bench_key1, 16, bench_iv, 12,
  4277. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4278. #else
  4279. bench_aesgcm_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4280. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4281. #endif
  4282. #endif
  4283. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4284. && !defined(WOLFSSL_XILINX_CRYPT)
  4285. bench_aesgcm_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4286. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4287. #endif
  4288. #ifdef WOLFSSL_AES_256
  4289. #ifdef HAVE_RENESAS_SYNC
  4290. bench_aesgcm_internal(useDeviceID, bench_key2, 32, bench_iv, 12,
  4291. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4292. #else
  4293. bench_aesgcm_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4294. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4295. #endif
  4296. #endif
  4297. #ifdef WOLFSSL_AESGCM_STREAM
  4298. #undef AES_GCM_STRING
  4299. #define AES_GCM_STRING(n, dir) AES_AAD_STRING("AES-" #n "-GCM-STREAM-" #dir)
  4300. #if defined(WOLFSSL_AES_128) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4301. && !defined(WOLFSSL_XILINX_CRYPT) \
  4302. || defined(WOLFSSL_XILINX_CRYPT_VERSAL)
  4303. bench_aesgcm_stream_internal(useDeviceID, bench_key, 16, bench_iv, 12,
  4304. AES_GCM_STRING(128, enc), AES_GCM_STRING(128, dec));
  4305. #endif
  4306. #if defined(WOLFSSL_AES_192) && !defined(WOLFSSL_AFALG_XILINX_AES) \
  4307. && !defined(WOLFSSL_XILINX_CRYPT)
  4308. bench_aesgcm_stream_internal(useDeviceID, bench_key, 24, bench_iv, 12,
  4309. AES_GCM_STRING(192, enc), AES_GCM_STRING(192, dec));
  4310. #endif
  4311. #ifdef WOLFSSL_AES_256
  4312. bench_aesgcm_stream_internal(useDeviceID, bench_key, 32, bench_iv, 12,
  4313. AES_GCM_STRING(256, enc), AES_GCM_STRING(256, dec));
  4314. #endif
  4315. #endif /* WOLFSSL_AESGCM_STREAM */
  4316. #undef AES_GCM_STRING
  4317. }
  4318. /* GMAC */
  4319. void bench_gmac(int useDeviceID)
  4320. {
  4321. int ret, count = 0;
  4322. Gmac gmac;
  4323. double start;
  4324. byte tag[AES_AUTH_TAG_SZ];
  4325. DECLARE_MULTI_VALUE_STATS_VARS()
  4326. /* determine GCM GHASH method */
  4327. #ifdef GCM_SMALL
  4328. const char* gmacStr = "GMAC Small";
  4329. #elif defined(GCM_TABLE)
  4330. const char* gmacStr = "GMAC Table";
  4331. #elif defined(GCM_TABLE_4BIT)
  4332. const char* gmacStr = "GMAC Table 4-bit";
  4333. #elif defined(GCM_WORD32)
  4334. const char* gmacStr = "GMAC Word32";
  4335. #else
  4336. const char* gmacStr = "GMAC Default";
  4337. #endif
  4338. /* init keys */
  4339. XMEMSET(bench_plain, 0, bench_size);
  4340. XMEMSET(tag, 0, sizeof(tag));
  4341. XMEMSET(&gmac, 0, sizeof(Gmac)); /* clear context */
  4342. (void)wc_AesInit((Aes*)&gmac, HEAP_HINT,
  4343. useDeviceID ? devId: INVALID_DEVID);
  4344. #ifdef HAVE_RENESAS_SYNC
  4345. wc_GmacSetKey(&gmac, bench_key1, 16);
  4346. #else
  4347. wc_GmacSetKey(&gmac, bench_key, 16);
  4348. #endif
  4349. bench_stats_start(&count, &start);
  4350. do {
  4351. ret = wc_GmacUpdate(&gmac, bench_iv, 12, bench_plain, bench_size,
  4352. tag, sizeof(tag));
  4353. count++;
  4354. RECORD_MULTI_VALUE_STATS();
  4355. } while (bench_stats_check(start)
  4356. #ifdef MULTI_VALUE_STATISTICS
  4357. || runs < minimum_runs
  4358. #endif
  4359. );
  4360. wc_AesFree((Aes*)&gmac);
  4361. bench_stats_sym_finish(gmacStr, 0, count, bench_size, start, ret);
  4362. #ifdef MULTI_VALUE_STATISTICS
  4363. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4364. #endif
  4365. }
  4366. #endif /* HAVE_AESGCM */
  4367. #ifdef HAVE_AES_ECB
  4368. static void bench_aesecb_internal(int useDeviceID,
  4369. const byte* key, word32 keySz,
  4370. const char* encLabel, const char* decLabel)
  4371. {
  4372. int ret = 0, i, count = 0, times, pending = 0;
  4373. WC_DECLARE_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4374. sizeof(Aes), HEAP_HINT);
  4375. double start;
  4376. DECLARE_MULTI_VALUE_STATS_VARS()
  4377. #ifdef HAVE_FIPS
  4378. const word32 benchSz = AES_BLOCK_SIZE;
  4379. #else
  4380. const word32 benchSz = bench_size;
  4381. #endif
  4382. WC_CALLOC_ARRAY(enc, Aes, BENCH_MAX_PENDING,
  4383. sizeof(Aes), HEAP_HINT);
  4384. /* init keys */
  4385. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4386. if ((ret = wc_AesInit(enc[i], HEAP_HINT,
  4387. useDeviceID ? devId: INVALID_DEVID)) != 0) {
  4388. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4389. goto exit;
  4390. }
  4391. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_ENCRYPTION);
  4392. if (ret != 0) {
  4393. printf("AesSetKey failed, ret = %d\n", ret);
  4394. goto exit;
  4395. }
  4396. }
  4397. bench_stats_start(&count, &start);
  4398. do {
  4399. int outer_loop_limit = (int)((bench_size / benchSz) * 10) + 1;
  4400. for (times = 0;
  4401. times < outer_loop_limit /* numBlocks */ || pending > 0;
  4402. ) {
  4403. bench_async_poll(&pending);
  4404. /* while free pending slots in queue, submit ops */
  4405. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4406. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4407. &times, outer_loop_limit, &pending)) {
  4408. #ifdef HAVE_FIPS
  4409. wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
  4410. #else
  4411. wc_AesEcbEncrypt(enc[i], bench_cipher, bench_plain,
  4412. benchSz);
  4413. #endif
  4414. ret = 0;
  4415. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4416. 0, &times, &pending)) {
  4417. goto exit_aes_enc;
  4418. }
  4419. }
  4420. } /* for i */
  4421. RECORD_MULTI_VALUE_STATS();
  4422. } /* for times */
  4423. count += times;
  4424. } while (bench_stats_check(start)
  4425. #ifdef MULTI_VALUE_STATISTICS
  4426. || runs < minimum_runs
  4427. #endif
  4428. );
  4429. exit_aes_enc:
  4430. bench_stats_sym_finish(encLabel, useDeviceID, count, benchSz,
  4431. start, ret);
  4432. #ifdef MULTI_VALUE_STATISTICS
  4433. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4434. #endif
  4435. #ifdef HAVE_AES_DECRYPT
  4436. /* init keys */
  4437. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4438. ret = wc_AesSetKey(enc[i], key, keySz, bench_iv, AES_DECRYPTION);
  4439. if (ret != 0) {
  4440. printf("AesSetKey failed, ret = %d\n", ret);
  4441. goto exit;
  4442. }
  4443. }
  4444. RESET_MULTI_VALUE_STATS_VARS();
  4445. bench_stats_start(&count, &start);
  4446. do {
  4447. int outer_loop_limit = (int)(10 * (bench_size / benchSz)) + 1;
  4448. for (times = 0; times < outer_loop_limit || pending > 0; ) {
  4449. bench_async_poll(&pending);
  4450. /* while free pending slots in queue, submit ops */
  4451. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4452. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  4453. &times, outer_loop_limit, &pending)) {
  4454. #ifdef HAVE_FIPS
  4455. wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
  4456. #else
  4457. wc_AesEcbDecrypt(enc[i], bench_plain, bench_cipher,
  4458. benchSz);
  4459. #endif
  4460. ret = 0;
  4461. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  4462. 0, &times, &pending)) {
  4463. goto exit_aes_dec;
  4464. }
  4465. }
  4466. } /* for i */
  4467. RECORD_MULTI_VALUE_STATS();
  4468. } /* for times */
  4469. count += times;
  4470. } while (bench_stats_check(start)
  4471. #ifdef MULTI_VALUE_STATISTICS
  4472. || runs < minimum_runs
  4473. #endif
  4474. );
  4475. exit_aes_dec:
  4476. bench_stats_sym_finish(decLabel, useDeviceID, count, benchSz,
  4477. start, ret);
  4478. #ifdef MULTI_VALUE_STATISTICS
  4479. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4480. #endif
  4481. #endif /* HAVE_AES_DECRYPT */
  4482. (void)decLabel;
  4483. exit:
  4484. if (WC_ARRAY_OK(enc)) {
  4485. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  4486. wc_AesFree(enc[i]);
  4487. }
  4488. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  4489. }
  4490. }
  4491. void bench_aesecb(int useDeviceID)
  4492. {
  4493. #ifdef WOLFSSL_AES_128
  4494. bench_aesecb_internal(useDeviceID, bench_key, 16,
  4495. "AES-128-ECB-enc", "AES-128-ECB-dec");
  4496. #endif
  4497. #ifdef WOLFSSL_AES_192
  4498. bench_aesecb_internal(useDeviceID, bench_key, 24,
  4499. "AES-192-ECB-enc", "AES-192-ECB-dec");
  4500. #endif
  4501. #ifdef WOLFSSL_AES_256
  4502. bench_aesecb_internal(useDeviceID, bench_key, 32,
  4503. "AES-256-ECB-enc", "AES-256-ECB-dec");
  4504. #endif
  4505. }
  4506. #endif /* HAVE_AES_ECB */
  4507. #ifdef WOLFSSL_AES_CFB
  4508. static void bench_aescfb_internal(const byte* key,
  4509. word32 keySz, const byte* iv,
  4510. const char* label)
  4511. {
  4512. Aes enc;
  4513. double start;
  4514. int i, ret, count;
  4515. DECLARE_MULTI_VALUE_STATS_VARS()
  4516. ret = wc_AesInit(&enc, HEAP_HINT, INVALID_DEVID);
  4517. if (ret != 0) {
  4518. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4519. return;
  4520. }
  4521. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4522. if (ret != 0) {
  4523. printf("AesSetKey failed, ret = %d\n", ret);
  4524. goto out;
  4525. }
  4526. bench_stats_start(&count, &start);
  4527. do {
  4528. for (i = 0; i < numBlocks; i++) {
  4529. if((ret = wc_AesCfbEncrypt(&enc, bench_plain, bench_cipher,
  4530. bench_size)) != 0) {
  4531. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4532. goto out;
  4533. }
  4534. RECORD_MULTI_VALUE_STATS();
  4535. }
  4536. count += i;
  4537. } while (bench_stats_check(start)
  4538. #ifdef MULTI_VALUE_STATISTICS
  4539. || runs < minimum_runs
  4540. #endif
  4541. );
  4542. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4543. #ifdef MULTI_VALUE_STATISTICS
  4544. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4545. #endif
  4546. out:
  4547. wc_AesFree(&enc);
  4548. return;
  4549. }
  4550. void bench_aescfb(void)
  4551. {
  4552. #ifdef WOLFSSL_AES_128
  4553. bench_aescfb_internal(bench_key, 16, bench_iv, "AES-128-CFB");
  4554. #endif
  4555. #ifdef WOLFSSL_AES_192
  4556. bench_aescfb_internal(bench_key, 24, bench_iv, "AES-192-CFB");
  4557. #endif
  4558. #ifdef WOLFSSL_AES_256
  4559. bench_aescfb_internal(bench_key, 32, bench_iv, "AES-256-CFB");
  4560. #endif
  4561. }
  4562. #endif /* WOLFSSL_AES_CFB */
  4563. #ifdef WOLFSSL_AES_OFB
  4564. static void bench_aesofb_internal(const byte* key,
  4565. word32 keySz, const byte* iv,
  4566. const char* label)
  4567. {
  4568. Aes enc;
  4569. double start;
  4570. int i, ret, count;
  4571. DECLARE_MULTI_VALUE_STATS_VARS()
  4572. ret = wc_AesInit(&enc, NULL, INVALID_DEVID);
  4573. if (ret != 0) {
  4574. printf("AesInit failed at L%d, ret = %d\n", __LINE__, ret);
  4575. return;
  4576. }
  4577. ret = wc_AesSetKey(&enc, key, keySz, iv, AES_ENCRYPTION);
  4578. if (ret != 0) {
  4579. printf("AesSetKey failed, ret = %d\n", ret);
  4580. return;
  4581. }
  4582. bench_stats_start(&count, &start);
  4583. do {
  4584. for (i = 0; i < numBlocks; i++) {
  4585. if((ret = wc_AesOfbEncrypt(&enc, bench_plain, bench_cipher,
  4586. bench_size)) != 0) {
  4587. printf("wc_AesCfbEncrypt failed, ret = %d\n", ret);
  4588. return;
  4589. }
  4590. RECORD_MULTI_VALUE_STATS();
  4591. }
  4592. count += i;
  4593. } while (bench_stats_check(start)
  4594. #ifdef MULTI_VALUE_STATISTICS
  4595. || runs < minimum_runs
  4596. #endif
  4597. );
  4598. bench_stats_sym_finish(label, 0, count, bench_size, start, ret);
  4599. #ifdef MULTI_VALUE_STATISTICS
  4600. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4601. #endif
  4602. wc_AesFree(&enc);
  4603. }
  4604. void bench_aesofb(void)
  4605. {
  4606. #ifdef WOLFSSL_AES_128
  4607. bench_aesofb_internal(bench_key, 16, bench_iv, "AES-128-OFB");
  4608. #endif
  4609. #ifdef WOLFSSL_AES_192
  4610. bench_aesofb_internal(bench_key, 24, bench_iv, "AES-192-OFB");
  4611. #endif
  4612. #ifdef WOLFSSL_AES_256
  4613. bench_aesofb_internal(bench_key, 32, bench_iv, "AES-256-OFB");
  4614. #endif
  4615. }
  4616. #endif /* WOLFSSL_AES_CFB */
  4617. #ifdef WOLFSSL_AES_XTS
  4618. void bench_aesxts(void)
  4619. {
  4620. WC_DECLARE_VAR(aes, XtsAes, 1, HEAP_HINT);
  4621. double start;
  4622. int i, count, ret;
  4623. DECLARE_MULTI_VALUE_STATS_VARS()
  4624. static const unsigned char k1[] = {
  4625. 0xa1, 0xb9, 0x0c, 0xba, 0x3f, 0x06, 0xac, 0x35,
  4626. 0x3b, 0x2c, 0x34, 0x38, 0x76, 0x08, 0x17, 0x62,
  4627. 0x09, 0x09, 0x23, 0x02, 0x6e, 0x91, 0x77, 0x18,
  4628. 0x15, 0xf2, 0x9d, 0xab, 0x01, 0x93, 0x2f, 0x2f
  4629. };
  4630. static const unsigned char i1[] = {
  4631. 0x4f, 0xae, 0xf7, 0x11, 0x7c, 0xda, 0x59, 0xc6,
  4632. 0x6e, 0x4b, 0x92, 0x01, 0x3e, 0x76, 0x8a, 0xd5
  4633. };
  4634. WC_ALLOC_VAR(aes, XtsAes, 1, HEAP_HINT);
  4635. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_ENCRYPTION,
  4636. HEAP_HINT, devId);
  4637. if (ret != 0) {
  4638. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4639. goto exit;
  4640. }
  4641. bench_stats_start(&count, &start);
  4642. do {
  4643. for (i = 0; i < numBlocks; i++) {
  4644. if ((ret = wc_AesXtsEncrypt(aes, bench_cipher, bench_plain,
  4645. bench_size, i1, sizeof(i1))) != 0) {
  4646. printf("wc_AesXtsEncrypt failed, ret = %d\n", ret);
  4647. goto exit;
  4648. }
  4649. RECORD_MULTI_VALUE_STATS();
  4650. }
  4651. count += i;
  4652. } while (bench_stats_check(start)
  4653. #ifdef MULTI_VALUE_STATISTICS
  4654. || runs < minimum_runs
  4655. #endif
  4656. );
  4657. bench_stats_sym_finish("AES-XTS-enc", 0, count, bench_size, start, ret);
  4658. #ifdef MULTI_VALUE_STATISTICS
  4659. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4660. #endif
  4661. wc_AesXtsFree(aes);
  4662. /* decryption benchmark */
  4663. ret = wc_AesXtsSetKey(aes, k1, sizeof(k1), AES_DECRYPTION,
  4664. HEAP_HINT, devId);
  4665. if (ret != 0) {
  4666. printf("wc_AesXtsSetKey failed, ret = %d\n", ret);
  4667. goto exit;
  4668. }
  4669. RESET_MULTI_VALUE_STATS_VARS();
  4670. bench_stats_start(&count, &start);
  4671. do {
  4672. for (i = 0; i < numBlocks; i++) {
  4673. if ((ret = wc_AesXtsDecrypt(aes, bench_plain, bench_cipher,
  4674. bench_size, i1, sizeof(i1))) != 0) {
  4675. printf("wc_AesXtsDecrypt failed, ret = %d\n", ret);
  4676. goto exit;
  4677. }
  4678. RECORD_MULTI_VALUE_STATS();
  4679. }
  4680. count += i;
  4681. } while (bench_stats_check(start)
  4682. #ifdef MULTI_VALUE_STATISTICS
  4683. || runs < minimum_runs
  4684. #endif
  4685. );
  4686. bench_stats_sym_finish("AES-XTS-dec", 0, count, bench_size, start, ret);
  4687. #ifdef MULTI_VALUE_STATISTICS
  4688. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4689. #endif
  4690. exit:
  4691. wc_AesXtsFree(aes);
  4692. WC_FREE_VAR(aes, HEAP_HINT);
  4693. }
  4694. #endif /* WOLFSSL_AES_XTS */
  4695. #ifdef WOLFSSL_AES_COUNTER
  4696. static void bench_aesctr_internal(const byte* key, word32 keySz,
  4697. const byte* iv, const char* label,
  4698. int useDeviceID)
  4699. {
  4700. Aes enc;
  4701. double start;
  4702. int i, count, ret = 0;
  4703. DECLARE_MULTI_VALUE_STATS_VARS()
  4704. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4705. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  4706. printf("wc_AesInit failed, ret = %d\n", ret);
  4707. }
  4708. if (wc_AesSetKeyDirect(&enc, key, keySz, iv, AES_ENCRYPTION) < 0) {
  4709. printf("wc_AesSetKeyDirect failed, ret = %d\n", ret);
  4710. return;
  4711. }
  4712. bench_stats_start(&count, &start);
  4713. do {
  4714. for (i = 0; i < numBlocks; i++) {
  4715. if((ret = wc_AesCtrEncrypt(&enc, bench_plain, bench_cipher,
  4716. bench_size)) != 0) {
  4717. printf("wc_AesCtrEncrypt failed, ret = %d\n", ret);
  4718. return;
  4719. }
  4720. RECORD_MULTI_VALUE_STATS();
  4721. }
  4722. count += i;
  4723. } while (bench_stats_check(start)
  4724. #ifdef MULTI_VALUE_STATISTICS
  4725. || runs < minimum_runs
  4726. #endif
  4727. );
  4728. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  4729. #ifdef MULTI_VALUE_STATISTICS
  4730. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4731. #endif
  4732. wc_AesFree(&enc);
  4733. }
  4734. void bench_aesctr(int useDeviceID)
  4735. {
  4736. #ifdef WOLFSSL_AES_128
  4737. bench_aesctr_internal(bench_key, 16, bench_iv, "AES-128-CTR", useDeviceID);
  4738. #endif
  4739. #ifdef WOLFSSL_AES_192
  4740. bench_aesctr_internal(bench_key, 24, bench_iv, "AES-192-CTR", useDeviceID);
  4741. #endif
  4742. #ifdef WOLFSSL_AES_256
  4743. bench_aesctr_internal(bench_key, 32, bench_iv, "AES-256-CTR", useDeviceID);
  4744. #endif
  4745. }
  4746. #endif /* WOLFSSL_AES_COUNTER */
  4747. #ifdef HAVE_AESCCM
  4748. void bench_aesccm(int useDeviceID)
  4749. {
  4750. Aes enc;
  4751. int enc_inited = 0;
  4752. double start;
  4753. int ret, i, count;
  4754. DECLARE_MULTI_VALUE_STATS_VARS()
  4755. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4756. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4757. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  4758. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  4759. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  4760. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  4761. if ((ret = wc_AesInit(&enc, HEAP_HINT,
  4762. useDeviceID ? devId : INVALID_DEVID)) != 0)
  4763. {
  4764. printf("wc_AesInit failed, ret = %d\n", ret);
  4765. goto exit;
  4766. }
  4767. if ((ret = wc_AesCcmSetKey(&enc, bench_key, 16)) != 0) {
  4768. printf("wc_AesCcmSetKey failed, ret = %d\n", ret);
  4769. goto exit;
  4770. }
  4771. enc_inited = 1;
  4772. bench_stats_start(&count, &start);
  4773. do {
  4774. for (i = 0; i < numBlocks; i++) {
  4775. ret |= wc_AesCcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  4776. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4777. bench_additional, 0);
  4778. RECORD_MULTI_VALUE_STATS();
  4779. }
  4780. count += i;
  4781. } while (bench_stats_check(start)
  4782. #ifdef MULTI_VALUE_STATISTICS
  4783. || runs < minimum_runs
  4784. #endif
  4785. );
  4786. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-enc"), useDeviceID, count,
  4787. bench_size, start, ret);
  4788. #ifdef MULTI_VALUE_STATISTICS
  4789. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4790. #endif
  4791. if (ret != 0) {
  4792. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4793. goto exit;
  4794. }
  4795. #ifdef HAVE_AES_DECRYPT
  4796. RESET_MULTI_VALUE_STATS_VARS();
  4797. bench_stats_start(&count, &start);
  4798. do {
  4799. for (i = 0; i < numBlocks; i++) {
  4800. ret |= wc_AesCcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  4801. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  4802. bench_additional, 0);
  4803. RECORD_MULTI_VALUE_STATS();
  4804. }
  4805. count += i;
  4806. } while (bench_stats_check(start)
  4807. #ifdef MULTI_VALUE_STATISTICS
  4808. || runs < minimum_runs
  4809. #endif
  4810. );
  4811. bench_stats_sym_finish(AES_AAD_STRING("AES-CCM-dec"), useDeviceID, count,
  4812. bench_size, start, ret);
  4813. #ifdef MULTI_VALUE_STATISTICS
  4814. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4815. #endif
  4816. if (ret != 0) {
  4817. printf("wc_AesCcmEncrypt failed, ret = %d\n", ret);
  4818. goto exit;
  4819. }
  4820. #endif
  4821. exit:
  4822. if (enc_inited)
  4823. wc_AesFree(&enc);
  4824. WC_FREE_VAR(bench_additional, HEAP_HINT);
  4825. WC_FREE_VAR(bench_tag, HEAP_HINT);
  4826. }
  4827. #endif /* HAVE_AESCCM */
  4828. #ifdef WOLFSSL_AES_SIV
  4829. static void bench_aessiv_internal(const byte* key, word32 keySz, const char*
  4830. encLabel, const char* decLabel)
  4831. {
  4832. int i;
  4833. int ret = 0;
  4834. byte assoc[AES_BLOCK_SIZE];
  4835. byte nonce[AES_BLOCK_SIZE];
  4836. byte siv[AES_BLOCK_SIZE];
  4837. int count = 0;
  4838. double start;
  4839. DECLARE_MULTI_VALUE_STATS_VARS()
  4840. bench_stats_start(&count, &start);
  4841. do {
  4842. for (i = 0; i < numBlocks; i++) {
  4843. ret = wc_AesSivEncrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4844. AES_BLOCK_SIZE, bench_plain, bench_size,
  4845. siv, bench_cipher);
  4846. if (ret != 0) {
  4847. printf("wc_AesSivEncrypt failed (%d)\n", ret);
  4848. return;
  4849. }
  4850. RECORD_MULTI_VALUE_STATS();
  4851. }
  4852. count += i;
  4853. } while (bench_stats_check(start)
  4854. #ifdef MULTI_VALUE_STATISTICS
  4855. || runs < minimum_runs
  4856. #endif
  4857. );
  4858. bench_stats_sym_finish(encLabel, 0, count, bench_size, start, ret);
  4859. #ifdef MULTI_VALUE_STATISTICS
  4860. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4861. #endif
  4862. RESET_MULTI_VALUE_STATS_VARS();
  4863. bench_stats_start(&count, &start);
  4864. do {
  4865. for (i = 0; i < numBlocks; i++) {
  4866. ret = wc_AesSivDecrypt(key, keySz, assoc, AES_BLOCK_SIZE, nonce,
  4867. AES_BLOCK_SIZE, bench_cipher, bench_size,
  4868. siv, bench_plain);
  4869. if (ret != 0) {
  4870. printf("wc_AesSivDecrypt failed (%d)\n", ret);
  4871. return;
  4872. }
  4873. RECORD_MULTI_VALUE_STATS();
  4874. }
  4875. count += i;
  4876. } while (bench_stats_check(start)
  4877. #ifdef MULTI_VALUE_STATISTICS
  4878. || runs < minimum_runs
  4879. #endif
  4880. );
  4881. bench_stats_sym_finish(decLabel, 0, count, bench_size, start, ret);
  4882. #ifdef MULTI_VALUE_STATISTICS
  4883. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4884. #endif
  4885. }
  4886. void bench_aessiv(void)
  4887. {
  4888. bench_aessiv_internal(bench_key, 32, "AES-256-SIV-enc", "AES-256-SIV-dec");
  4889. bench_aessiv_internal(bench_key, 48, "AES-384-SIV-enc", "AES-384-SIV-dec");
  4890. bench_aessiv_internal(bench_key, 64, "AES-512-SIV-enc", "AES-512-SIV-dec");
  4891. }
  4892. #endif /* WOLFSSL_AES_SIV */
  4893. #endif /* !NO_AES */
  4894. #ifdef HAVE_POLY1305
  4895. void bench_poly1305(void)
  4896. {
  4897. Poly1305 enc;
  4898. byte mac[16];
  4899. double start;
  4900. int ret = 0, i, count;
  4901. DECLARE_MULTI_VALUE_STATS_VARS()
  4902. if (digest_stream) {
  4903. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4904. if (ret != 0) {
  4905. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4906. return;
  4907. }
  4908. bench_stats_start(&count, &start);
  4909. do {
  4910. for (i = 0; i < numBlocks; i++) {
  4911. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4912. if (ret != 0) {
  4913. printf("Poly1305Update failed: %d\n", ret);
  4914. break;
  4915. }
  4916. RECORD_MULTI_VALUE_STATS();
  4917. }
  4918. wc_Poly1305Final(&enc, mac);
  4919. count += i;
  4920. } while (bench_stats_check(start)
  4921. #ifdef MULTI_VALUE_STATISTICS
  4922. || runs < minimum_runs
  4923. #endif
  4924. );
  4925. }
  4926. else {
  4927. bench_stats_start(&count, &start);
  4928. do {
  4929. for (i = 0; i < numBlocks; i++) {
  4930. ret = wc_Poly1305SetKey(&enc, bench_key, 32);
  4931. if (ret != 0) {
  4932. printf("Poly1305SetKey failed, ret = %d\n", ret);
  4933. return;
  4934. }
  4935. ret = wc_Poly1305Update(&enc, bench_plain, bench_size);
  4936. if (ret != 0) {
  4937. printf("Poly1305Update failed: %d\n", ret);
  4938. break;
  4939. }
  4940. wc_Poly1305Final(&enc, mac);
  4941. RECORD_MULTI_VALUE_STATS();
  4942. }
  4943. count += i;
  4944. } while (bench_stats_check(start)
  4945. #ifdef MULTI_VALUE_STATISTICS
  4946. || runs < minimum_runs
  4947. #endif
  4948. );
  4949. }
  4950. bench_stats_sym_finish("POLY1305", 0, count, bench_size, start, ret);
  4951. #ifdef MULTI_VALUE_STATISTICS
  4952. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4953. #endif
  4954. }
  4955. #endif /* HAVE_POLY1305 */
  4956. #ifdef HAVE_CAMELLIA
  4957. void bench_camellia(void)
  4958. {
  4959. Camellia cam;
  4960. double start;
  4961. int ret, i, count;
  4962. DECLARE_MULTI_VALUE_STATS_VARS()
  4963. ret = wc_CamelliaSetKey(&cam, bench_key, 16, bench_iv);
  4964. if (ret != 0) {
  4965. printf("CamelliaSetKey failed, ret = %d\n", ret);
  4966. return;
  4967. }
  4968. bench_stats_start(&count, &start);
  4969. do {
  4970. for (i = 0; i < numBlocks; i++) {
  4971. ret = wc_CamelliaCbcEncrypt(&cam, bench_cipher, bench_plain,
  4972. bench_size);
  4973. if (ret < 0) {
  4974. printf("CamelliaCbcEncrypt failed: %d\n", ret);
  4975. return;
  4976. }
  4977. RECORD_MULTI_VALUE_STATS();
  4978. }
  4979. count += i;
  4980. } while (bench_stats_check(start)
  4981. #ifdef MULTI_VALUE_STATISTICS
  4982. || runs < minimum_runs
  4983. #endif
  4984. );
  4985. bench_stats_sym_finish("Camellia", 0, count, bench_size, start, ret);
  4986. #ifdef MULTI_VALUE_STATISTICS
  4987. bench_multi_value_stats(max, min, sum, squareSum, runs);
  4988. #endif
  4989. }
  4990. #endif
  4991. #ifdef WOLFSSL_SM4_CBC
  4992. void bench_sm4_cbc(void)
  4993. {
  4994. wc_Sm4 sm4;
  4995. double start;
  4996. int ret;
  4997. int i;
  4998. int count;
  4999. DECLARE_MULTI_VALUE_STATS_VARS()
  5000. ret = wc_Sm4SetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5001. if (ret != 0) {
  5002. printf("Sm4SetKey failed, ret = %d\n", ret);
  5003. return;
  5004. }
  5005. ret = wc_Sm4SetIV(&sm4, bench_iv);
  5006. if (ret != 0) {
  5007. printf("Sm4SetIV failed, ret = %d\n", ret);
  5008. return;
  5009. }
  5010. bench_stats_start(&count, &start);
  5011. do {
  5012. for (i = 0; i < numBlocks; i++) {
  5013. ret = wc_Sm4CbcEncrypt(&sm4, bench_cipher, bench_plain, bench_size);
  5014. if (ret < 0) {
  5015. printf("Sm4CbcEncrypt failed: %d\n", ret);
  5016. return;
  5017. }
  5018. RECORD_MULTI_VALUE_STATS();
  5019. }
  5020. count += i;
  5021. } while (bench_stats_check(start)
  5022. #ifdef MULTI_VALUE_STATISTICS
  5023. || runs < minimum_runs
  5024. #endif
  5025. );
  5026. bench_stats_sym_finish("SM4-CBC-enc", 0, count, bench_size, start, ret);
  5027. #ifdef MULTI_VALUE_STATISTICS
  5028. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5029. #endif
  5030. RESET_MULTI_VALUE_STATS_VARS();
  5031. bench_stats_start(&count, &start);
  5032. do {
  5033. for (i = 0; i < numBlocks; i++) {
  5034. ret = wc_Sm4CbcDecrypt(&sm4, bench_plain, bench_cipher, bench_size);
  5035. if (ret < 0) {
  5036. printf("Sm4CbcDecrypt failed: %d\n", ret);
  5037. return;
  5038. }
  5039. RECORD_MULTI_VALUE_STATS();
  5040. }
  5041. count += i;
  5042. } while (bench_stats_check(start)
  5043. #ifdef MULTI_VALUE_STATISTICS
  5044. || runs < minimum_runs
  5045. #endif
  5046. );
  5047. bench_stats_sym_finish("SM4-CBC-dec", 0, count, bench_size, start, ret);
  5048. #ifdef MULTI_VALUE_STATISTICS
  5049. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5050. #endif
  5051. }
  5052. #endif
  5053. #ifdef WOLFSSL_SM4_GCM
  5054. void bench_sm4_gcm(void)
  5055. {
  5056. wc_Sm4 sm4;
  5057. double start;
  5058. int ret;
  5059. int i;
  5060. int count;
  5061. DECLARE_MULTI_VALUE_STATS_VARS()
  5062. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5063. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5064. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5065. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5066. ret = wc_Sm4GcmSetKey(&sm4, bench_key, SM4_KEY_SIZE);
  5067. if (ret != 0) {
  5068. printf("Sm4GcmSetKey failed, ret = %d\n", ret);
  5069. goto exit;
  5070. }
  5071. bench_stats_start(&count, &start);
  5072. do {
  5073. for (i = 0; i < numBlocks; i++) {
  5074. ret = wc_Sm4GcmEncrypt(&sm4, bench_cipher, bench_plain, bench_size,
  5075. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5076. bench_additional, aesAuthAddSz);
  5077. if (ret < 0) {
  5078. printf("Sm4GcmEncrypt failed: %d\n", ret);
  5079. goto exit;
  5080. }
  5081. RECORD_MULTI_VALUE_STATS();
  5082. }
  5083. count += i;
  5084. } while (bench_stats_check(start)
  5085. #ifdef MULTI_VALUE_STATISTICS
  5086. || runs < minimum_runs
  5087. #endif
  5088. );
  5089. bench_stats_sym_finish("SM4-GCM-enc", 0, count, bench_size, start, ret);
  5090. #ifdef MULTI_VALUE_STATISTICS
  5091. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5092. #endif
  5093. RESET_MULTI_VALUE_STATS_VARS();
  5094. bench_stats_start(&count, &start);
  5095. do {
  5096. for (i = 0; i < numBlocks; i++) {
  5097. ret = wc_Sm4GcmDecrypt(&sm4, bench_plain, bench_cipher, bench_size,
  5098. bench_iv, GCM_NONCE_MID_SZ, bench_tag, SM4_BLOCK_SIZE,
  5099. bench_additional, aesAuthAddSz);
  5100. if (ret < 0) {
  5101. printf("Sm4GcmDecrypt failed: %d\n", ret);
  5102. goto exit;
  5103. }
  5104. RECORD_MULTI_VALUE_STATS();
  5105. }
  5106. count += i;
  5107. } while (bench_stats_check(start)
  5108. #ifdef MULTI_VALUE_STATISTICS
  5109. || runs < minimum_runs
  5110. #endif
  5111. );
  5112. bench_stats_sym_finish("SM4-GCM-dec", 0, count, bench_size, start, ret);
  5113. #ifdef MULTI_VALUE_STATISTICS
  5114. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5115. #endif
  5116. exit:
  5117. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5118. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5119. }
  5120. #endif
  5121. #ifdef WOLFSSL_SM4_CCM
  5122. void bench_sm4_ccm(void)
  5123. {
  5124. wc_Sm4 enc;
  5125. double start;
  5126. int ret, i, count;
  5127. DECLARE_MULTI_VALUE_STATS_VARS()
  5128. WC_DECLARE_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5129. WC_DECLARE_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5130. WC_ALLOC_VAR(bench_additional, byte, AES_AUTH_ADD_SZ, HEAP_HINT);
  5131. WC_ALLOC_VAR(bench_tag, byte, AES_AUTH_TAG_SZ, HEAP_HINT);
  5132. XMEMSET(bench_tag, 0, AES_AUTH_TAG_SZ);
  5133. XMEMSET(bench_additional, 0, AES_AUTH_ADD_SZ);
  5134. if ((ret = wc_Sm4SetKey(&enc, bench_key, 16)) != 0) {
  5135. printf("wc_Sm4SetKey failed, ret = %d\n", ret);
  5136. goto exit;
  5137. }
  5138. bench_stats_start(&count, &start);
  5139. do {
  5140. for (i = 0; i < numBlocks; i++) {
  5141. ret |= wc_Sm4CcmEncrypt(&enc, bench_cipher, bench_plain, bench_size,
  5142. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5143. bench_additional, 0);
  5144. RECORD_MULTI_VALUE_STATS();
  5145. }
  5146. count += i;
  5147. } while (bench_stats_check(start)
  5148. #ifdef MULTI_VALUE_STATISTICS
  5149. || runs < minimum_runs
  5150. #endif
  5151. );
  5152. bench_stats_sym_finish("SM4-CCM-enc", 0, count, bench_size, start, ret);
  5153. #ifdef MULTI_VALUE_STATISTICS
  5154. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5155. #endif
  5156. if (ret != 0) {
  5157. printf("wc_Sm4Encrypt failed, ret = %d\n", ret);
  5158. goto exit;
  5159. }
  5160. RESET_MULTI_VALUE_STATS_VARS();
  5161. bench_stats_start(&count, &start);
  5162. do {
  5163. for (i = 0; i < numBlocks; i++) {
  5164. ret |= wc_Sm4CcmDecrypt(&enc, bench_plain, bench_cipher, bench_size,
  5165. bench_iv, 12, bench_tag, AES_AUTH_TAG_SZ,
  5166. bench_additional, 0);
  5167. RECORD_MULTI_VALUE_STATS();
  5168. }
  5169. count += i;
  5170. } while (bench_stats_check(start)
  5171. #ifdef MULTI_VALUE_STATISTICS
  5172. || runs < minimum_runs
  5173. #endif
  5174. );
  5175. bench_stats_sym_finish("SM4-CCM-dec", 0, count, bench_size, start, ret);
  5176. #ifdef MULTI_VALUE_STATISTICS
  5177. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5178. #endif
  5179. if (ret != 0) {
  5180. printf("wc_Sm4Decrypt failed, ret = %d\n", ret);
  5181. goto exit;
  5182. }
  5183. exit:
  5184. WC_FREE_VAR(bench_additional, HEAP_HINT);
  5185. WC_FREE_VAR(bench_tag, HEAP_HINT);
  5186. }
  5187. #endif /* HAVE_AESCCM */
  5188. #ifndef NO_DES3
  5189. void bench_des(int useDeviceID)
  5190. {
  5191. int ret = 0, i, count = 0, times, pending = 0;
  5192. WC_DECLARE_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5193. sizeof(Des3), HEAP_HINT);
  5194. double start;
  5195. DECLARE_MULTI_VALUE_STATS_VARS()
  5196. WC_CALLOC_ARRAY(enc, Des3, BENCH_MAX_PENDING,
  5197. sizeof(Des3), HEAP_HINT);
  5198. /* init keys */
  5199. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5200. if ((ret = wc_Des3Init(enc[i], HEAP_HINT,
  5201. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5202. printf("Des3Init failed, ret = %d\n", ret);
  5203. goto exit;
  5204. }
  5205. ret = wc_Des3_SetKey(enc[i], bench_key, bench_iv, DES_ENCRYPTION);
  5206. if (ret != 0) {
  5207. printf("Des3_SetKey failed, ret = %d\n", ret);
  5208. goto exit;
  5209. }
  5210. }
  5211. bench_stats_start(&count, &start);
  5212. do {
  5213. for (times = 0; times < numBlocks || pending > 0; ) {
  5214. bench_async_poll(&pending);
  5215. /* while free pending slots in queue, submit ops */
  5216. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5217. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5218. &times, numBlocks, &pending)) {
  5219. ret = wc_Des3_CbcEncrypt(enc[i],
  5220. bench_cipher,
  5221. bench_plain, bench_size);
  5222. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5223. 0, &times, &pending)) {
  5224. goto exit_3des;
  5225. }
  5226. }
  5227. } /* for i */
  5228. RECORD_MULTI_VALUE_STATS();
  5229. } /* for times */
  5230. count += times;
  5231. } while (bench_stats_check(start)
  5232. #ifdef MULTI_VALUE_STATISTICS
  5233. || runs < minimum_runs
  5234. #endif
  5235. );
  5236. exit_3des:
  5237. bench_stats_sym_finish("3DES", useDeviceID, count, bench_size, start, ret);
  5238. #ifdef MULTI_VALUE_STATISTICS
  5239. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5240. #endif
  5241. exit:
  5242. if (WC_ARRAY_OK(enc)) {
  5243. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5244. wc_Des3Free(enc[i]);
  5245. }
  5246. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5247. }
  5248. }
  5249. #endif /* !NO_DES3 */
  5250. #ifndef NO_RC4
  5251. void bench_arc4(int useDeviceID)
  5252. {
  5253. int ret = 0, i, count = 0, times, pending = 0;
  5254. WC_DECLARE_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5255. sizeof(Arc4), HEAP_HINT);
  5256. double start;
  5257. DECLARE_MULTI_VALUE_STATS_VARS()
  5258. WC_CALLOC_ARRAY(enc, Arc4, BENCH_MAX_PENDING,
  5259. sizeof(Arc4), HEAP_HINT);
  5260. /* init keys */
  5261. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5262. if ((ret = wc_Arc4Init(enc[i], HEAP_HINT,
  5263. useDeviceID ? devId : INVALID_DEVID)) != 0) {
  5264. printf("Arc4Init failed, ret = %d\n", ret);
  5265. goto exit;
  5266. }
  5267. ret = wc_Arc4SetKey(enc[i], bench_key, 16);
  5268. if (ret != 0) {
  5269. printf("Arc4SetKey failed, ret = %d\n", ret);
  5270. goto exit;
  5271. }
  5272. }
  5273. bench_stats_start(&count, &start);
  5274. do {
  5275. for (times = 0; times < numBlocks || pending > 0; ) {
  5276. bench_async_poll(&pending);
  5277. /* while free pending slots in queue, submit ops */
  5278. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5279. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
  5280. &times, numBlocks, &pending)) {
  5281. ret = wc_Arc4Process(enc[i], bench_cipher, bench_plain,
  5282. bench_size);
  5283. if (!bench_async_handle(&ret, BENCH_ASYNC_GET_DEV(enc[i]),
  5284. 0, &times, &pending)) {
  5285. goto exit_arc4;
  5286. }
  5287. }
  5288. } /* for i */
  5289. RECORD_MULTI_VALUE_STATS();
  5290. } /* for times */
  5291. count += times;
  5292. } while (bench_stats_check(start)
  5293. #ifdef MULTI_VALUE_STATISTICS
  5294. || runs < minimum_runs
  5295. #endif
  5296. );
  5297. exit_arc4:
  5298. bench_stats_sym_finish("ARC4", useDeviceID, count, bench_size, start, ret);
  5299. #ifdef MULTI_VALUE_STATISTICS
  5300. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5301. #endif
  5302. exit:
  5303. if (WC_ARRAY_OK(enc)) {
  5304. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5305. wc_Arc4Free(enc[i]);
  5306. }
  5307. WC_FREE_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  5308. }
  5309. }
  5310. #endif /* !NO_RC4 */
  5311. #ifdef HAVE_CHACHA
  5312. void bench_chacha(void)
  5313. {
  5314. WC_DECLARE_VAR(enc, ChaCha, 1, HEAP_HINT);
  5315. double start;
  5316. int ret, i, count;
  5317. DECLARE_MULTI_VALUE_STATS_VARS()
  5318. WC_ALLOC_VAR(enc, ChaCha, 1, HEAP_HINT);
  5319. XMEMSET(enc, 0, sizeof(ChaCha));
  5320. wc_Chacha_SetKey(enc, bench_key, 16);
  5321. if (encrypt_only) {
  5322. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5323. if (ret < 0) {
  5324. printf("wc_Chacha_SetIV error: %d\n", ret);
  5325. goto exit;
  5326. }
  5327. bench_stats_start(&count, &start);
  5328. do {
  5329. for (i = 0; i < numBlocks; i++) {
  5330. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5331. bench_size);
  5332. if (ret < 0) {
  5333. printf("wc_Chacha_Process error: %d\n", ret);
  5334. goto exit;
  5335. }
  5336. RECORD_MULTI_VALUE_STATS();
  5337. }
  5338. count += i;
  5339. } while (bench_stats_check(start)
  5340. #ifdef MULTI_VALUE_STATISTICS
  5341. || runs < minimum_runs
  5342. #endif
  5343. );
  5344. }
  5345. else {
  5346. bench_stats_start(&count, &start);
  5347. do {
  5348. for (i = 0; i < numBlocks; i++) {
  5349. ret = wc_Chacha_SetIV(enc, bench_iv, 0);
  5350. if (ret < 0) {
  5351. printf("wc_Chacha_SetIV error: %d\n", ret);
  5352. goto exit;
  5353. }
  5354. ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
  5355. bench_size);
  5356. if (ret < 0) {
  5357. printf("wc_Chacha_Process error: %d\n", ret);
  5358. goto exit;
  5359. }
  5360. RECORD_MULTI_VALUE_STATS();
  5361. }
  5362. count += i;
  5363. } while (bench_stats_check(start)
  5364. #ifdef MULTI_VALUE_STATISTICS
  5365. || runs < minimum_runs
  5366. #endif
  5367. );
  5368. }
  5369. bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
  5370. #ifdef MULTI_VALUE_STATISTICS
  5371. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5372. #endif
  5373. exit:
  5374. WC_FREE_VAR(enc, HEAP_HINT);
  5375. }
  5376. #endif /* HAVE_CHACHA*/
  5377. #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
  5378. void bench_chacha20_poly1305_aead(void)
  5379. {
  5380. double start;
  5381. int ret = 0, i, count;
  5382. DECLARE_MULTI_VALUE_STATS_VARS()
  5383. WC_DECLARE_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5384. WC_ALLOC_VAR(authTag, byte, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE, HEAP_HINT);
  5385. XMEMSET(authTag, 0, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);
  5386. bench_stats_start(&count, &start);
  5387. do {
  5388. for (i = 0; i < numBlocks; i++) {
  5389. ret = wc_ChaCha20Poly1305_Encrypt(bench_key, bench_iv, NULL, 0,
  5390. bench_plain, bench_size, bench_cipher, authTag);
  5391. if (ret < 0) {
  5392. printf("wc_ChaCha20Poly1305_Encrypt error: %d\n", ret);
  5393. goto exit;
  5394. }
  5395. RECORD_MULTI_VALUE_STATS();
  5396. }
  5397. count += i;
  5398. } while (bench_stats_check(start)
  5399. #ifdef MULTI_VALUE_STATISTICS
  5400. || runs < minimum_runs
  5401. #endif
  5402. );
  5403. bench_stats_sym_finish("CHA-POLY", 0, count, bench_size, start, ret);
  5404. #ifdef MULTI_VALUE_STATISTICS
  5405. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5406. #endif
  5407. exit:
  5408. WC_FREE_VAR(authTag, HEAP_HINT);
  5409. }
  5410. #endif /* HAVE_CHACHA && HAVE_POLY1305 */
  5411. #ifndef NO_MD5
  5412. void bench_md5(int useDeviceID)
  5413. {
  5414. WC_DECLARE_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5415. sizeof(wc_Md5), HEAP_HINT);
  5416. double start = 0;
  5417. int ret = 0, i, count = 0, times, pending = 0;
  5418. DECLARE_MULTI_VALUE_STATS_VARS()
  5419. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5420. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5421. WC_CALLOC_ARRAY(hash, wc_Md5, BENCH_MAX_PENDING,
  5422. sizeof(wc_Md5), HEAP_HINT);
  5423. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5424. WC_MD5_DIGEST_SIZE, HEAP_HINT);
  5425. if (digest_stream) {
  5426. /* init keys */
  5427. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5428. ret = wc_InitMd5_ex(hash[i], HEAP_HINT,
  5429. useDeviceID ? devId : INVALID_DEVID);
  5430. if (ret != 0) {
  5431. printf("InitMd5_ex failed, ret = %d\n", ret);
  5432. goto exit;
  5433. }
  5434. #ifdef WOLFSSL_PIC32MZ_HASH
  5435. wc_Md5SizeSet(hash[i], numBlocks * bench_size);
  5436. #endif
  5437. }
  5438. bench_stats_start(&count, &start);
  5439. do {
  5440. for (times = 0; times < numBlocks || pending > 0; ) {
  5441. bench_async_poll(&pending);
  5442. /* while free pending slots in queue, submit ops */
  5443. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5444. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5445. 0, &times, numBlocks, &pending)) {
  5446. ret = wc_Md5Update(hash[i], bench_plain,
  5447. bench_size);
  5448. if (!bench_async_handle(&ret,
  5449. BENCH_ASYNC_GET_DEV(hash[i]),
  5450. 0, &times, &pending)) {
  5451. goto exit_md5;
  5452. }
  5453. }
  5454. } /* for i */
  5455. RECORD_MULTI_VALUE_STATS();
  5456. } /* for times */
  5457. count += times;
  5458. times = 0;
  5459. do {
  5460. bench_async_poll(&pending);
  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_Md5Final(hash[i], digest[i]);
  5465. if (!bench_async_handle(&ret,
  5466. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5467. &times, &pending)) {
  5468. goto exit_md5;
  5469. }
  5470. }
  5471. } /* for i */
  5472. } while (pending > 0);
  5473. } while (bench_stats_check(start)
  5474. #ifdef MULTI_VALUE_STATISTICS
  5475. || runs < minimum_runs
  5476. #endif
  5477. );
  5478. }
  5479. else {
  5480. bench_stats_start(&count, &start);
  5481. do {
  5482. for (times = 0; times < numBlocks; times++) {
  5483. ret = wc_InitMd5_ex(hash[0], HEAP_HINT, INVALID_DEVID);
  5484. if (ret == 0)
  5485. ret = wc_Md5Update(hash[0], bench_plain, bench_size);
  5486. if (ret == 0)
  5487. ret = wc_Md5Final(hash[0], digest[0]);
  5488. if (ret != 0)
  5489. goto exit_md5;
  5490. RECORD_MULTI_VALUE_STATS();
  5491. } /* for times */
  5492. count += times;
  5493. } while (bench_stats_check(start)
  5494. #ifdef MULTI_VALUE_STATISTICS
  5495. || runs < minimum_runs
  5496. #endif
  5497. );
  5498. }
  5499. exit_md5:
  5500. bench_stats_sym_finish("MD5", useDeviceID, count, bench_size, start, ret);
  5501. #ifdef MULTI_VALUE_STATISTICS
  5502. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5503. #endif
  5504. exit:
  5505. #ifdef WOLFSSL_ASYNC_CRYPT
  5506. if (WC_ARRAY_OK(hash)) {
  5507. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5508. wc_Md5Free(hash[i]);
  5509. }
  5510. }
  5511. #endif
  5512. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5513. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5514. }
  5515. #endif /* !NO_MD5 */
  5516. #ifndef NO_SHA
  5517. void bench_sha(int useDeviceID)
  5518. {
  5519. WC_DECLARE_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5520. sizeof(wc_Sha), HEAP_HINT);
  5521. double start;
  5522. int ret = 0, i, count = 0, times, pending = 0;
  5523. DECLARE_MULTI_VALUE_STATS_VARS()
  5524. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5525. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5526. WC_CALLOC_ARRAY(hash, wc_Sha, BENCH_MAX_PENDING,
  5527. sizeof(wc_Sha), HEAP_HINT);
  5528. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5529. WC_SHA_DIGEST_SIZE, HEAP_HINT);
  5530. if (digest_stream) {
  5531. /* init keys */
  5532. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5533. ret = wc_InitSha_ex(hash[i], HEAP_HINT,
  5534. useDeviceID ? devId : INVALID_DEVID);
  5535. if (ret != 0) {
  5536. printf("InitSha failed, ret = %d\n", ret);
  5537. goto exit;
  5538. }
  5539. #ifdef WOLFSSL_PIC32MZ_HASH
  5540. wc_ShaSizeSet(hash[i], numBlocks * bench_size);
  5541. #endif
  5542. }
  5543. bench_stats_start(&count, &start);
  5544. do {
  5545. for (times = 0; times < numBlocks || pending > 0; ) {
  5546. bench_async_poll(&pending);
  5547. /* while free pending slots in queue, submit ops */
  5548. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5549. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5550. 0, &times, numBlocks, &pending)) {
  5551. ret = wc_ShaUpdate(hash[i], bench_plain,
  5552. bench_size);
  5553. if (!bench_async_handle(&ret,
  5554. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5555. &times, &pending)) {
  5556. goto exit_sha;
  5557. }
  5558. }
  5559. } /* for i */
  5560. RECORD_MULTI_VALUE_STATS();
  5561. } /* for times */
  5562. count += times;
  5563. times = 0;
  5564. do {
  5565. bench_async_poll(&pending);
  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_ShaFinal(hash[i], digest[i]);
  5570. if (!bench_async_handle(&ret,
  5571. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5572. &times, &pending)) {
  5573. goto exit_sha;
  5574. }
  5575. }
  5576. } /* for i */
  5577. } while (pending > 0);
  5578. } while (bench_stats_check(start)
  5579. #ifdef MULTI_VALUE_STATISTICS
  5580. || runs < minimum_runs
  5581. #endif
  5582. );
  5583. }
  5584. else {
  5585. bench_stats_start(&count, &start);
  5586. do {
  5587. for (times = 0; times < numBlocks; times++) {
  5588. ret = wc_InitSha_ex(hash[0], HEAP_HINT,
  5589. useDeviceID ? devId : INVALID_DEVID);
  5590. if (ret == 0)
  5591. ret = wc_ShaUpdate(hash[0], bench_plain, bench_size);
  5592. if (ret == 0)
  5593. ret = wc_ShaFinal(hash[0], digest[0]);
  5594. if (ret != 0)
  5595. goto exit_sha;
  5596. RECORD_MULTI_VALUE_STATS();
  5597. } /* for times */
  5598. count += times;
  5599. } while (bench_stats_check(start)
  5600. #ifdef MULTI_VALUE_STATISTICS
  5601. || runs < minimum_runs
  5602. #endif
  5603. );
  5604. }
  5605. exit_sha:
  5606. bench_stats_sym_finish("SHA", useDeviceID, count, bench_size, start, ret);
  5607. #ifdef MULTI_VALUE_STATISTICS
  5608. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5609. #endif
  5610. exit:
  5611. if (WC_ARRAY_OK(hash)) {
  5612. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5613. wc_ShaFree(hash[i]);
  5614. }
  5615. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5616. }
  5617. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5618. }
  5619. #endif /* NO_SHA */
  5620. #ifdef WOLFSSL_SHA224
  5621. void bench_sha224(int useDeviceID)
  5622. {
  5623. WC_DECLARE_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5624. sizeof(wc_Sha224), HEAP_HINT);
  5625. double start;
  5626. int ret = 0, i, count = 0, times, pending = 0;
  5627. DECLARE_MULTI_VALUE_STATS_VARS()
  5628. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5629. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5630. WC_CALLOC_ARRAY(hash, wc_Sha224, BENCH_MAX_PENDING,
  5631. sizeof(wc_Sha224), HEAP_HINT);
  5632. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5633. WC_SHA224_DIGEST_SIZE, HEAP_HINT);
  5634. if (digest_stream) {
  5635. /* init keys */
  5636. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5637. ret = wc_InitSha224_ex(hash[i], HEAP_HINT,
  5638. useDeviceID ? devId : INVALID_DEVID);
  5639. if (ret != 0) {
  5640. printf("InitSha224_ex failed, ret = %d\n", ret);
  5641. goto exit;
  5642. }
  5643. }
  5644. bench_stats_start(&count, &start);
  5645. do {
  5646. for (times = 0; times < numBlocks || pending > 0; ) {
  5647. bench_async_poll(&pending);
  5648. /* while free pending slots in queue, submit ops */
  5649. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5650. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5651. 0, &times, numBlocks, &pending)) {
  5652. ret = wc_Sha224Update(hash[i], bench_plain,
  5653. bench_size);
  5654. if (!bench_async_handle(&ret,
  5655. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5656. &times, &pending)) {
  5657. goto exit_sha224;
  5658. }
  5659. }
  5660. } /* for i */
  5661. RECORD_MULTI_VALUE_STATS();
  5662. } /* for times */
  5663. count += times;
  5664. times = 0;
  5665. do {
  5666. bench_async_poll(&pending);
  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_Sha224Final(hash[i], digest[i]);
  5671. if (!bench_async_handle(&ret,
  5672. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5673. &times, &pending)) {
  5674. goto exit_sha224;
  5675. }
  5676. }
  5677. } /* for i */
  5678. } while (pending > 0);
  5679. } while (bench_stats_check(start)
  5680. #ifdef MULTI_VALUE_STATISTICS
  5681. || runs < minimum_runs
  5682. #endif
  5683. );
  5684. }
  5685. else {
  5686. bench_stats_start(&count, &start);
  5687. do {
  5688. for (times = 0; times < numBlocks; times++) {
  5689. ret = wc_InitSha224_ex(hash[0], HEAP_HINT,
  5690. useDeviceID ? devId : INVALID_DEVID);
  5691. if (ret == 0)
  5692. ret = wc_Sha224Update(hash[0], bench_plain, bench_size);
  5693. if (ret == 0)
  5694. ret = wc_Sha224Final(hash[0], digest[0]);
  5695. if (ret != 0)
  5696. goto exit_sha224;
  5697. } /* for times */
  5698. count += times;
  5699. } while (bench_stats_check(start)
  5700. #ifdef MULTI_VALUE_STATISTICS
  5701. || runs < minimum_runs
  5702. #endif
  5703. );
  5704. }
  5705. exit_sha224:
  5706. bench_stats_sym_finish("SHA-224", useDeviceID, count,
  5707. bench_size, start, ret);
  5708. #ifdef MULTI_VALUE_STATISTICS
  5709. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5710. #endif
  5711. exit:
  5712. if (WC_ARRAY_OK(hash)) {
  5713. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5714. wc_Sha224Free(hash[i]);
  5715. }
  5716. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5717. }
  5718. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5719. }
  5720. #endif
  5721. #ifndef NO_SHA256
  5722. void bench_sha256(int useDeviceID)
  5723. {
  5724. WC_DECLARE_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5725. sizeof(wc_Sha256), HEAP_HINT);
  5726. double start;
  5727. int ret = 0, i, count = 0, times, pending = 0;
  5728. DECLARE_MULTI_VALUE_STATS_VARS()
  5729. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5730. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5731. WC_CALLOC_ARRAY(hash, wc_Sha256, BENCH_MAX_PENDING,
  5732. sizeof(wc_Sha256), HEAP_HINT);
  5733. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5734. WC_SHA256_DIGEST_SIZE, HEAP_HINT);
  5735. if (digest_stream) {
  5736. /* init keys */
  5737. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5738. ret = wc_InitSha256_ex(hash[i], HEAP_HINT,
  5739. useDeviceID ? devId: INVALID_DEVID);
  5740. if (ret != 0) {
  5741. printf("InitSha256_ex failed, ret = %d\n", ret);
  5742. goto exit;
  5743. }
  5744. #ifdef WOLFSSL_PIC32MZ_HASH
  5745. wc_Sha256SizeSet(hash[i], numBlocks * bench_size);
  5746. #endif
  5747. }
  5748. bench_stats_start(&count, &start);
  5749. do {
  5750. for (times = 0; times < numBlocks || pending > 0; ) {
  5751. bench_async_poll(&pending);
  5752. /* while free pending slots in queue, submit ops */
  5753. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5754. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5755. 0, &times, numBlocks, &pending)) {
  5756. ret = wc_Sha256Update(hash[i], bench_plain,
  5757. bench_size);
  5758. if (!bench_async_handle(&ret,
  5759. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5760. &times, &pending)) {
  5761. goto exit_sha256;
  5762. }
  5763. }
  5764. } /* for i */
  5765. RECORD_MULTI_VALUE_STATS();
  5766. } /* for times */
  5767. count += times;
  5768. times = 0;
  5769. do {
  5770. bench_async_poll(&pending);
  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_Sha256Final(hash[i], digest[i]);
  5775. if (!bench_async_handle(&ret,
  5776. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5777. &times, &pending)) {
  5778. goto exit_sha256;
  5779. }
  5780. }
  5781. } /* for i */
  5782. } while (pending > 0);
  5783. } while (bench_stats_check(start)
  5784. #ifdef MULTI_VALUE_STATISTICS
  5785. || runs < minimum_runs
  5786. #endif
  5787. );
  5788. }
  5789. else {
  5790. bench_stats_start(&count, &start);
  5791. do {
  5792. for (times = 0; times < numBlocks; times++) {
  5793. ret = wc_InitSha256_ex(hash[0], HEAP_HINT,
  5794. useDeviceID ? devId: INVALID_DEVID);
  5795. if (ret == 0)
  5796. ret = wc_Sha256Update(hash[0], bench_plain, bench_size);
  5797. if (ret == 0)
  5798. ret = wc_Sha256Final(hash[0], digest[0]);
  5799. if (ret != 0)
  5800. goto exit_sha256;
  5801. RECORD_MULTI_VALUE_STATS();
  5802. } /* for times */
  5803. count += times;
  5804. } while (bench_stats_check(start)
  5805. #ifdef MULTI_VALUE_STATISTICS
  5806. || runs < minimum_runs
  5807. #endif
  5808. );
  5809. }
  5810. exit_sha256:
  5811. bench_stats_sym_finish("SHA-256", useDeviceID, count, bench_size,
  5812. start, ret);
  5813. #ifdef MULTI_VALUE_STATISTICS
  5814. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5815. #endif
  5816. exit:
  5817. if (WC_ARRAY_OK(hash)) {
  5818. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5819. wc_Sha256Free(hash[i]);
  5820. }
  5821. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5822. }
  5823. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5824. }
  5825. #endif
  5826. #ifdef WOLFSSL_SHA384
  5827. void bench_sha384(int useDeviceID)
  5828. {
  5829. WC_DECLARE_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5830. sizeof(wc_Sha384), HEAP_HINT);
  5831. double start;
  5832. int ret = 0, i, count = 0, times, pending = 0;
  5833. DECLARE_MULTI_VALUE_STATS_VARS()
  5834. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5835. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5836. WC_CALLOC_ARRAY(hash, wc_Sha384, BENCH_MAX_PENDING,
  5837. sizeof(wc_Sha384), HEAP_HINT);
  5838. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5839. WC_SHA384_DIGEST_SIZE, HEAP_HINT);
  5840. if (digest_stream) {
  5841. /* init keys */
  5842. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5843. ret = wc_InitSha384_ex(hash[i], HEAP_HINT,
  5844. useDeviceID ? devId : INVALID_DEVID);
  5845. if (ret != 0) {
  5846. printf("InitSha384_ex failed, ret = %d\n", ret);
  5847. goto exit;
  5848. }
  5849. }
  5850. bench_stats_start(&count, &start);
  5851. do {
  5852. for (times = 0; times < numBlocks || pending > 0; ) {
  5853. bench_async_poll(&pending);
  5854. /* while free pending slots in queue, submit ops */
  5855. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5856. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5857. 0, &times, numBlocks, &pending)) {
  5858. ret = wc_Sha384Update(hash[i], bench_plain,
  5859. bench_size);
  5860. if (!bench_async_handle(&ret,
  5861. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5862. &times, &pending)) {
  5863. goto exit_sha384;
  5864. }
  5865. }
  5866. } /* for i */
  5867. RECORD_MULTI_VALUE_STATS();
  5868. } /* for times */
  5869. count += times;
  5870. times = 0;
  5871. do {
  5872. bench_async_poll(&pending);
  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_Sha384Final(hash[i], digest[i]);
  5877. if (!bench_async_handle(&ret,
  5878. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5879. &times, &pending)) {
  5880. goto exit_sha384;
  5881. }
  5882. }
  5883. } /* for i */
  5884. } while (pending > 0);
  5885. } while (bench_stats_check(start)
  5886. #ifdef MULTI_VALUE_STATISTICS
  5887. || runs < minimum_runs
  5888. #endif
  5889. );
  5890. }
  5891. else {
  5892. bench_stats_start(&count, &start);
  5893. do {
  5894. for (times = 0; times < numBlocks; times++) {
  5895. ret = wc_InitSha384_ex(hash[0], HEAP_HINT,
  5896. useDeviceID ? devId : INVALID_DEVID);
  5897. if (ret == 0)
  5898. ret = wc_Sha384Update(hash[0], bench_plain, bench_size);
  5899. if (ret == 0)
  5900. ret = wc_Sha384Final(hash[0], digest[0]);
  5901. if (ret != 0)
  5902. goto exit_sha384;
  5903. RECORD_MULTI_VALUE_STATS();
  5904. } /* for times */
  5905. count += times;
  5906. } while (bench_stats_check(start)
  5907. #ifdef MULTI_VALUE_STATISTICS
  5908. || runs < minimum_runs
  5909. #endif
  5910. );
  5911. }
  5912. exit_sha384:
  5913. bench_stats_sym_finish("SHA-384", useDeviceID, count, bench_size,
  5914. start, ret);
  5915. #ifdef MULTI_VALUE_STATISTICS
  5916. bench_multi_value_stats(max, min, sum, squareSum, runs);
  5917. #endif
  5918. exit:
  5919. if (WC_ARRAY_OK(hash)) {
  5920. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5921. wc_Sha384Free(hash[i]);
  5922. }
  5923. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  5924. }
  5925. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  5926. }
  5927. #endif
  5928. #ifdef WOLFSSL_SHA512
  5929. void bench_sha512(int useDeviceID)
  5930. {
  5931. WC_DECLARE_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5932. sizeof(wc_Sha512), HEAP_HINT);
  5933. double start;
  5934. int ret = 0, i, count = 0, times, pending = 0;
  5935. DECLARE_MULTI_VALUE_STATS_VARS()
  5936. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5937. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5938. WC_CALLOC_ARRAY(hash, wc_Sha512, BENCH_MAX_PENDING,
  5939. sizeof(wc_Sha512), HEAP_HINT);
  5940. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  5941. WC_SHA512_DIGEST_SIZE, HEAP_HINT);
  5942. if (digest_stream) {
  5943. /* init keys */
  5944. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5945. ret = wc_InitSha512_ex(hash[i], HEAP_HINT,
  5946. useDeviceID ? devId : INVALID_DEVID);
  5947. if (ret != 0) {
  5948. printf("InitSha512_ex failed, ret = %d\n", ret);
  5949. goto exit;
  5950. }
  5951. }
  5952. bench_stats_start(&count, &start);
  5953. do {
  5954. for (times = 0; times < numBlocks || pending > 0; ) {
  5955. bench_async_poll(&pending);
  5956. /* while free pending slots in queue, submit ops */
  5957. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  5958. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  5959. 0, &times, numBlocks, &pending)) {
  5960. ret = wc_Sha512Update(hash[i], bench_plain,
  5961. bench_size);
  5962. if (!bench_async_handle(&ret,
  5963. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5964. &times, &pending)) {
  5965. goto exit_sha512;
  5966. }
  5967. }
  5968. } /* for i */
  5969. RECORD_MULTI_VALUE_STATS();
  5970. } /* for times */
  5971. count += times;
  5972. times = 0;
  5973. do {
  5974. bench_async_poll(&pending);
  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_Sha512Final(hash[i], digest[i]);
  5979. if (!bench_async_handle(&ret,
  5980. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  5981. &times, &pending)) {
  5982. goto exit_sha512;
  5983. }
  5984. }
  5985. } /* for i */
  5986. } while (pending > 0);
  5987. } while (bench_stats_check(start)
  5988. #ifdef MULTI_VALUE_STATISTICS
  5989. || runs < minimum_runs
  5990. #endif
  5991. );
  5992. }
  5993. else {
  5994. bench_stats_start(&count, &start);
  5995. do {
  5996. for (times = 0; times < numBlocks; times++) {
  5997. ret = wc_InitSha512_ex(hash[0], HEAP_HINT,
  5998. useDeviceID ? devId : INVALID_DEVID);
  5999. if (ret == 0)
  6000. ret = wc_Sha512Update(hash[0], bench_plain, bench_size);
  6001. if (ret == 0)
  6002. ret = wc_Sha512Final(hash[0], digest[0]);
  6003. if (ret != 0)
  6004. goto exit_sha512;
  6005. RECORD_MULTI_VALUE_STATS();
  6006. } /* for times */
  6007. count += times;
  6008. } while (bench_stats_check(start)
  6009. #ifdef MULTI_VALUE_STATISTICS
  6010. || runs < minimum_runs
  6011. #endif
  6012. );
  6013. }
  6014. exit_sha512:
  6015. bench_stats_sym_finish("SHA-512", useDeviceID, count, bench_size,
  6016. start, ret);
  6017. #ifdef MULTI_VALUE_STATISTICS
  6018. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6019. #endif
  6020. exit:
  6021. if (WC_ARRAY_OK(hash)) {
  6022. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6023. wc_Sha512Free(hash[i]);
  6024. }
  6025. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6026. }
  6027. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6028. }
  6029. #if !defined(WOLFSSL_NOSHA512_224) && \
  6030. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6031. void bench_sha512_224(int useDeviceID)
  6032. {
  6033. WC_DECLARE_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6034. sizeof(wc_Sha512_224), HEAP_HINT);
  6035. double start;
  6036. int ret = 0, i, count = 0, times, pending = 0;
  6037. DECLARE_MULTI_VALUE_STATS_VARS()
  6038. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6039. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6040. WC_CALLOC_ARRAY(hash, wc_Sha512_224, BENCH_MAX_PENDING,
  6041. sizeof(wc_Sha512_224), HEAP_HINT);
  6042. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6043. WC_SHA512_224_DIGEST_SIZE, HEAP_HINT);
  6044. if (digest_stream) {
  6045. /* init keys */
  6046. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6047. ret = wc_InitSha512_224_ex(hash[i], HEAP_HINT,
  6048. useDeviceID ? devId : INVALID_DEVID);
  6049. if (ret != 0) {
  6050. printf("InitSha512_224_ex failed, ret = %d\n", ret);
  6051. goto exit;
  6052. }
  6053. }
  6054. bench_stats_start(&count, &start);
  6055. do {
  6056. for (times = 0; times < numBlocks || pending > 0; ) {
  6057. bench_async_poll(&pending);
  6058. /* while free pending slots in queue, submit ops */
  6059. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6060. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6061. 0, &times, numBlocks, &pending)) {
  6062. ret = wc_Sha512_224Update(hash[i], bench_plain,
  6063. bench_size);
  6064. if (!bench_async_handle(&ret,
  6065. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6066. &times, &pending)) {
  6067. goto exit_sha512_224;
  6068. }
  6069. }
  6070. } /* for i */
  6071. RECORD_MULTI_VALUE_STATS();
  6072. } /* for times */
  6073. count += times;
  6074. times = 0;
  6075. do {
  6076. bench_async_poll(&pending);
  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_224Final(hash[i], digest[i]);
  6081. if (!bench_async_handle(&ret,
  6082. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6083. &times, &pending)) {
  6084. goto exit_sha512_224;
  6085. }
  6086. }
  6087. } /* for i */
  6088. } while (pending > 0);
  6089. } while (bench_stats_check(start)
  6090. #ifdef MULTI_VALUE_STATISTICS
  6091. || runs < minimum_runs
  6092. #endif
  6093. );
  6094. }
  6095. else {
  6096. bench_stats_start(&count, &start);
  6097. do {
  6098. for (times = 0; times < numBlocks; times++) {
  6099. ret = wc_InitSha512_224_ex(hash[0], HEAP_HINT,
  6100. useDeviceID ? devId : INVALID_DEVID);
  6101. if (ret == 0)
  6102. ret = wc_Sha512_224Update(hash[0], bench_plain, bench_size);
  6103. if (ret == 0)
  6104. ret = wc_Sha512_224Final(hash[0], digest[0]);
  6105. if (ret != 0)
  6106. goto exit_sha512_224;
  6107. RECORD_MULTI_VALUE_STATS();
  6108. } /* for times */
  6109. count += times;
  6110. } while (bench_stats_check(start)
  6111. #ifdef MULTI_VALUE_STATISTICS
  6112. || runs < minimum_runs
  6113. #endif
  6114. );
  6115. }
  6116. exit_sha512_224:
  6117. bench_stats_sym_finish("SHA-512/224", useDeviceID, count, bench_size,
  6118. start, ret);
  6119. #ifdef MULTI_VALUE_STATISTICS
  6120. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6121. #endif
  6122. exit:
  6123. if (WC_ARRAY_OK(hash)) {
  6124. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6125. wc_Sha512_224Free(hash[i]);
  6126. }
  6127. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6128. }
  6129. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6130. }
  6131. #endif /* WOLFSSL_NOSHA512_224 && !FIPS ... */
  6132. #if !defined(WOLFSSL_NOSHA512_256) && \
  6133. (!defined(HAVE_FIPS) || FIPS_VERSION_GE(5, 3)) && !defined(HAVE_SELFTEST)
  6134. void bench_sha512_256(int useDeviceID)
  6135. {
  6136. WC_DECLARE_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6137. sizeof(wc_Sha512_256), HEAP_HINT);
  6138. double start;
  6139. int ret = 0, i, count = 0, times, pending = 0;
  6140. DECLARE_MULTI_VALUE_STATS_VARS()
  6141. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6142. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6143. WC_CALLOC_ARRAY(hash, wc_Sha512_256, BENCH_MAX_PENDING,
  6144. sizeof(wc_Sha512_256), HEAP_HINT);
  6145. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6146. WC_SHA512_256_DIGEST_SIZE, HEAP_HINT);
  6147. if (digest_stream) {
  6148. /* init keys */
  6149. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6150. ret = wc_InitSha512_256_ex(hash[i], HEAP_HINT,
  6151. useDeviceID ? devId : INVALID_DEVID);
  6152. if (ret != 0) {
  6153. printf("InitSha512_256_ex failed, ret = %d\n", ret);
  6154. goto exit;
  6155. }
  6156. }
  6157. bench_stats_start(&count, &start);
  6158. do {
  6159. for (times = 0; times < numBlocks || pending > 0; ) {
  6160. bench_async_poll(&pending);
  6161. /* while free pending slots in queue, submit ops */
  6162. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6163. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6164. 0, &times, numBlocks, &pending)) {
  6165. ret = wc_Sha512_256Update(hash[i], bench_plain,
  6166. bench_size);
  6167. if (!bench_async_handle(&ret,
  6168. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6169. &times, &pending)) {
  6170. goto exit_sha512_256;
  6171. }
  6172. }
  6173. } /* for i */
  6174. RECORD_MULTI_VALUE_STATS();
  6175. } /* for times */
  6176. count += times;
  6177. times = 0;
  6178. do {
  6179. bench_async_poll(&pending);
  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_256Final(hash[i], digest[i]);
  6184. if (!bench_async_handle(&ret,
  6185. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6186. &times, &pending)) {
  6187. goto exit_sha512_256;
  6188. }
  6189. }
  6190. } /* for i */
  6191. } while (pending > 0);
  6192. } while (bench_stats_check(start)
  6193. #ifdef MULTI_VALUE_STATISTICS
  6194. || runs < minimum_runs
  6195. #endif
  6196. );
  6197. }
  6198. else {
  6199. bench_stats_start(&count, &start);
  6200. do {
  6201. for (times = 0; times < numBlocks; times++) {
  6202. ret = wc_InitSha512_256_ex(hash[0], HEAP_HINT,
  6203. useDeviceID ? devId : INVALID_DEVID);
  6204. if (ret == 0)
  6205. ret = wc_Sha512_256Update(hash[0], bench_plain, bench_size);
  6206. if (ret == 0)
  6207. ret = wc_Sha512_256Final(hash[0], digest[0]);
  6208. if (ret != 0)
  6209. goto exit_sha512_256;
  6210. RECORD_MULTI_VALUE_STATS();
  6211. } /* for times */
  6212. count += times;
  6213. } while (bench_stats_check(start)
  6214. #ifdef MULTI_VALUE_STATISTICS
  6215. || runs < minimum_runs
  6216. #endif
  6217. );
  6218. }
  6219. exit_sha512_256:
  6220. bench_stats_sym_finish("SHA-512/256", useDeviceID, count, bench_size,
  6221. start, ret);
  6222. #ifdef MULTI_VALUE_STATISTICS
  6223. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6224. #endif
  6225. exit:
  6226. if (WC_ARRAY_OK(hash)) {
  6227. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6228. wc_Sha512_256Free(hash[i]);
  6229. }
  6230. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6231. }
  6232. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6233. }
  6234. #endif /* WOLFSSL_NOSHA512_256 && !FIPS ... */
  6235. #endif /* WOLFSSL_SHA512 */
  6236. #ifdef WOLFSSL_SHA3
  6237. #ifndef WOLFSSL_NOSHA3_224
  6238. void bench_sha3_224(int useDeviceID)
  6239. {
  6240. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6241. sizeof(wc_Sha3), HEAP_HINT);
  6242. double start;
  6243. int ret = 0, i, count = 0, times, pending = 0;
  6244. DECLARE_MULTI_VALUE_STATS_VARS()
  6245. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6246. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6247. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6248. sizeof(wc_Sha3), HEAP_HINT);
  6249. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6250. WC_SHA3_224_DIGEST_SIZE, HEAP_HINT);
  6251. if (digest_stream) {
  6252. /* init keys */
  6253. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6254. ret = wc_InitSha3_224(hash[i], HEAP_HINT,
  6255. useDeviceID ? devId : INVALID_DEVID);
  6256. if (ret != 0) {
  6257. printf("InitSha3_224 failed, ret = %d\n", ret);
  6258. goto exit;
  6259. }
  6260. }
  6261. bench_stats_start(&count, &start);
  6262. do {
  6263. for (times = 0; times < numBlocks || pending > 0; ) {
  6264. bench_async_poll(&pending);
  6265. /* while free pending slots in queue, submit ops */
  6266. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6267. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6268. 0, &times, numBlocks, &pending)) {
  6269. ret = wc_Sha3_224_Update(hash[i], bench_plain,
  6270. bench_size);
  6271. if (!bench_async_handle(&ret,
  6272. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6273. &times, &pending)) {
  6274. goto exit_sha3_224;
  6275. }
  6276. }
  6277. } /* for i */
  6278. RECORD_MULTI_VALUE_STATS();
  6279. } /* for times */
  6280. count += times;
  6281. times = 0;
  6282. do {
  6283. bench_async_poll(&pending);
  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_Final(hash[i], digest[i]);
  6288. if (!bench_async_handle(&ret,
  6289. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6290. &times, &pending)) {
  6291. goto exit_sha3_224;
  6292. }
  6293. }
  6294. } /* for i */
  6295. } while (pending > 0);
  6296. } while (bench_stats_check(start)
  6297. #ifdef MULTI_VALUE_STATISTICS
  6298. || runs < minimum_runs
  6299. #endif
  6300. );
  6301. }
  6302. else {
  6303. bench_stats_start(&count, &start);
  6304. do {
  6305. for (times = 0; times < numBlocks; times++) {
  6306. ret = wc_InitSha3_224(hash[0], HEAP_HINT,
  6307. useDeviceID ? devId : INVALID_DEVID);
  6308. if (ret == 0)
  6309. ret = wc_Sha3_224_Update(hash[0], bench_plain, bench_size);
  6310. if (ret == 0)
  6311. ret = wc_Sha3_224_Final(hash[0], digest[0]);
  6312. if (ret != 0)
  6313. goto exit_sha3_224;
  6314. RECORD_MULTI_VALUE_STATS();
  6315. } /* for times */
  6316. count += times;
  6317. } while (bench_stats_check(start)
  6318. #ifdef MULTI_VALUE_STATISTICS
  6319. || runs < minimum_runs
  6320. #endif
  6321. );
  6322. }
  6323. exit_sha3_224:
  6324. bench_stats_sym_finish("SHA3-224", useDeviceID, count, bench_size,
  6325. start, ret);
  6326. #ifdef MULTI_VALUE_STATISTICS
  6327. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6328. #endif
  6329. exit:
  6330. if (WC_ARRAY_OK(hash)) {
  6331. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6332. wc_Sha3_224_Free(hash[i]);
  6333. }
  6334. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6335. }
  6336. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6337. }
  6338. #endif /* WOLFSSL_NOSHA3_224 */
  6339. #ifndef WOLFSSL_NOSHA3_256
  6340. void bench_sha3_256(int useDeviceID)
  6341. {
  6342. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6343. sizeof(wc_Sha3), HEAP_HINT);
  6344. double start;
  6345. DECLARE_MULTI_VALUE_STATS_VARS()
  6346. int ret = 0, i, count = 0, times, pending = 0;
  6347. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6348. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6349. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6350. sizeof(wc_Sha3), HEAP_HINT);
  6351. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6352. WC_SHA3_256_DIGEST_SIZE, HEAP_HINT);
  6353. if (digest_stream) {
  6354. /* init keys */
  6355. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6356. ret = wc_InitSha3_256(hash[i], HEAP_HINT,
  6357. useDeviceID ? devId : INVALID_DEVID);
  6358. if (ret != 0) {
  6359. printf("InitSha3_256 failed, ret = %d\n", ret);
  6360. goto exit;
  6361. }
  6362. }
  6363. bench_stats_start(&count, &start);
  6364. do {
  6365. for (times = 0; times < numBlocks || pending > 0; ) {
  6366. bench_async_poll(&pending);
  6367. /* while free pending slots in queue, submit ops */
  6368. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6369. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6370. 0, &times, numBlocks, &pending)) {
  6371. ret = wc_Sha3_256_Update(hash[i], bench_plain,
  6372. bench_size);
  6373. if (!bench_async_handle(&ret,
  6374. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6375. &times, &pending)) {
  6376. goto exit_sha3_256;
  6377. }
  6378. }
  6379. } /* for i */
  6380. RECORD_MULTI_VALUE_STATS();
  6381. } /* for times */
  6382. count += times;
  6383. times = 0;
  6384. do {
  6385. bench_async_poll(&pending);
  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_Final(hash[i], digest[i]);
  6390. if (!bench_async_handle(&ret,
  6391. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6392. &times, &pending)) {
  6393. goto exit_sha3_256;
  6394. }
  6395. }
  6396. } /* for i */
  6397. } while (pending > 0);
  6398. } while (bench_stats_check(start)
  6399. #ifdef MULTI_VALUE_STATISTICS
  6400. || runs < minimum_runs
  6401. #endif
  6402. );
  6403. }
  6404. else {
  6405. bench_stats_start(&count, &start);
  6406. do {
  6407. for (times = 0; times < numBlocks; times++) {
  6408. ret = wc_InitSha3_256(hash[0], HEAP_HINT,
  6409. useDeviceID ? devId : INVALID_DEVID);
  6410. if (ret == 0)
  6411. ret = wc_Sha3_256_Update(hash[0], bench_plain, bench_size);
  6412. if (ret == 0)
  6413. ret = wc_Sha3_256_Final(hash[0], digest[0]);
  6414. if (ret != 0)
  6415. goto exit_sha3_256;
  6416. RECORD_MULTI_VALUE_STATS();
  6417. } /* for times */
  6418. count += times;
  6419. } while (bench_stats_check(start)
  6420. #ifdef MULTI_VALUE_STATISTICS
  6421. || runs < minimum_runs
  6422. #endif
  6423. );
  6424. }
  6425. exit_sha3_256:
  6426. bench_stats_sym_finish("SHA3-256", useDeviceID, count, bench_size,
  6427. start, ret);
  6428. #ifdef MULTI_VALUE_STATISTICS
  6429. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6430. #endif
  6431. exit:
  6432. if (WC_ARRAY_OK(hash)) {
  6433. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6434. wc_Sha3_256_Free(hash[i]);
  6435. }
  6436. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6437. }
  6438. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6439. }
  6440. #endif /* WOLFSSL_NOSHA3_256 */
  6441. #ifndef WOLFSSL_NOSHA3_384
  6442. void bench_sha3_384(int useDeviceID)
  6443. {
  6444. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6445. sizeof(wc_Sha3), HEAP_HINT);
  6446. double start;
  6447. int ret = 0, i, count = 0, times, pending = 0;
  6448. DECLARE_MULTI_VALUE_STATS_VARS()
  6449. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6450. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6451. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6452. sizeof(wc_Sha3), HEAP_HINT);
  6453. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6454. WC_SHA3_384_DIGEST_SIZE, HEAP_HINT);
  6455. if (digest_stream) {
  6456. /* init keys */
  6457. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6458. ret = wc_InitSha3_384(hash[i], HEAP_HINT,
  6459. useDeviceID ? devId : INVALID_DEVID);
  6460. if (ret != 0) {
  6461. printf("InitSha3_384 failed, ret = %d\n", ret);
  6462. goto exit;
  6463. }
  6464. }
  6465. bench_stats_start(&count, &start);
  6466. do {
  6467. for (times = 0; times < numBlocks || pending > 0; ) {
  6468. bench_async_poll(&pending);
  6469. /* while free pending slots in queue, submit ops */
  6470. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6471. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6472. 0, &times, numBlocks, &pending)) {
  6473. ret = wc_Sha3_384_Update(hash[i], bench_plain,
  6474. bench_size);
  6475. if (!bench_async_handle(&ret,
  6476. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6477. &times, &pending)) {
  6478. goto exit_sha3_384;
  6479. }
  6480. }
  6481. } /* for i */
  6482. RECORD_MULTI_VALUE_STATS();
  6483. } /* for times */
  6484. count += times;
  6485. times = 0;
  6486. do {
  6487. bench_async_poll(&pending);
  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_Final(hash[i], digest[i]);
  6492. if (!bench_async_handle(&ret,
  6493. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6494. &times, &pending)) {
  6495. goto exit_sha3_384;
  6496. }
  6497. }
  6498. } /* for i */
  6499. } while (pending > 0);
  6500. } while (bench_stats_check(start)
  6501. #ifdef MULTI_VALUE_STATISTICS
  6502. || runs < minimum_runs
  6503. #endif
  6504. );
  6505. }
  6506. else {
  6507. bench_stats_start(&count, &start);
  6508. do {
  6509. for (times = 0; times < numBlocks; times++) {
  6510. ret = wc_InitSha3_384(hash[0], HEAP_HINT,
  6511. useDeviceID ? devId : INVALID_DEVID);
  6512. if (ret == 0)
  6513. ret = wc_Sha3_384_Update(hash[0], bench_plain, bench_size);
  6514. if (ret == 0)
  6515. ret = wc_Sha3_384_Final(hash[0], digest[0]);
  6516. if (ret != 0)
  6517. goto exit_sha3_384;
  6518. RECORD_MULTI_VALUE_STATS();
  6519. } /* for times */
  6520. count += times;
  6521. } while (bench_stats_check(start)
  6522. #ifdef MULTI_VALUE_STATISTICS
  6523. || runs < minimum_runs
  6524. #endif
  6525. );
  6526. }
  6527. exit_sha3_384:
  6528. bench_stats_sym_finish("SHA3-384", useDeviceID, count, bench_size,
  6529. start, ret);
  6530. #ifdef MULTI_VALUE_STATISTICS
  6531. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6532. #endif
  6533. exit:
  6534. if (WC_ARRAY_OK(hash)) {
  6535. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6536. wc_Sha3_384_Free(hash[i]);
  6537. }
  6538. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6539. }
  6540. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6541. }
  6542. #endif /* WOLFSSL_NOSHA3_384 */
  6543. #ifndef WOLFSSL_NOSHA3_512
  6544. void bench_sha3_512(int useDeviceID)
  6545. {
  6546. WC_DECLARE_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6547. sizeof(wc_Sha3), HEAP_HINT);
  6548. double start;
  6549. int ret = 0, i, count = 0, times, pending = 0;
  6550. DECLARE_MULTI_VALUE_STATS_VARS()
  6551. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6552. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6553. WC_CALLOC_ARRAY(hash, wc_Sha3, BENCH_MAX_PENDING,
  6554. sizeof(wc_Sha3), HEAP_HINT);
  6555. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6556. WC_SHA3_512_DIGEST_SIZE, HEAP_HINT);
  6557. if (digest_stream) {
  6558. /* init keys */
  6559. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6560. ret = wc_InitSha3_512(hash[i], HEAP_HINT,
  6561. useDeviceID ? devId : INVALID_DEVID);
  6562. if (ret != 0) {
  6563. printf("InitSha3_512 failed, ret = %d\n", ret);
  6564. goto exit;
  6565. }
  6566. }
  6567. bench_stats_start(&count, &start);
  6568. do {
  6569. for (times = 0; times < numBlocks || pending > 0; ) {
  6570. bench_async_poll(&pending);
  6571. /* while free pending slots in queue, submit ops */
  6572. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6573. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6574. 0, &times, numBlocks, &pending)) {
  6575. ret = wc_Sha3_512_Update(hash[i], bench_plain,
  6576. bench_size);
  6577. if (!bench_async_handle(&ret,
  6578. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6579. &times, &pending)) {
  6580. goto exit_sha3_512;
  6581. }
  6582. }
  6583. } /* for i */
  6584. RECORD_MULTI_VALUE_STATS();
  6585. } /* for times */
  6586. count += times;
  6587. times = 0;
  6588. do {
  6589. bench_async_poll(&pending);
  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_Final(hash[i], digest[i]);
  6594. if (!bench_async_handle(&ret,
  6595. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6596. &times, &pending)) {
  6597. goto exit_sha3_512;
  6598. }
  6599. }
  6600. } /* for i */
  6601. } while (pending > 0);
  6602. } while (bench_stats_check(start)
  6603. #ifdef MULTI_VALUE_STATISTICS
  6604. || runs < minimum_runs
  6605. #endif
  6606. );
  6607. }
  6608. else {
  6609. bench_stats_start(&count, &start);
  6610. do {
  6611. for (times = 0; times < numBlocks; times++) {
  6612. ret = wc_InitSha3_512(hash[0], HEAP_HINT,
  6613. useDeviceID ? devId : INVALID_DEVID);
  6614. if (ret == 0)
  6615. ret = wc_Sha3_512_Update(hash[0], bench_plain, bench_size);
  6616. if (ret == 0)
  6617. ret = wc_Sha3_512_Final(hash[0], digest[0]);
  6618. if (ret != 0)
  6619. goto exit_sha3_512;
  6620. RECORD_MULTI_VALUE_STATS();
  6621. } /* for times */
  6622. count += times;
  6623. } while (bench_stats_check(start)
  6624. #ifdef MULTI_VALUE_STATISTICS
  6625. || runs < minimum_runs
  6626. #endif
  6627. );
  6628. }
  6629. exit_sha3_512:
  6630. bench_stats_sym_finish("SHA3-512", useDeviceID, count, bench_size,
  6631. start, ret);
  6632. #ifdef MULTI_VALUE_STATISTICS
  6633. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6634. #endif
  6635. exit:
  6636. if (WC_ARRAY_OK(hash)) {
  6637. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6638. wc_Sha3_512_Free(hash[i]);
  6639. }
  6640. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6641. }
  6642. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6643. }
  6644. #endif /* WOLFSSL_NOSHA3_512 */
  6645. #ifdef WOLFSSL_SHAKE128
  6646. void bench_shake128(int useDeviceID)
  6647. {
  6648. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6649. sizeof(wc_Shake), HEAP_HINT);
  6650. double start;
  6651. int ret = 0, i, count = 0, times, pending = 0;
  6652. DECLARE_MULTI_VALUE_STATS_VARS()
  6653. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6654. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6655. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6656. sizeof(wc_Shake), HEAP_HINT);
  6657. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6658. WC_SHA3_128_BLOCK_SIZE, HEAP_HINT);
  6659. if (digest_stream) {
  6660. /* init keys */
  6661. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6662. ret = wc_InitShake128(hash[i], HEAP_HINT,
  6663. useDeviceID ? devId : INVALID_DEVID);
  6664. if (ret != 0) {
  6665. printf("InitShake128 failed, ret = %d\n", ret);
  6666. goto exit;
  6667. }
  6668. }
  6669. bench_stats_start(&count, &start);
  6670. do {
  6671. for (times = 0; times < numBlocks || pending > 0; ) {
  6672. bench_async_poll(&pending);
  6673. /* while free pending slots in queue, submit ops */
  6674. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6675. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6676. 0, &times, numBlocks, &pending)) {
  6677. ret = wc_Shake128_Update(hash[i], bench_plain,
  6678. bench_size);
  6679. if (!bench_async_handle(&ret,
  6680. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6681. &times, &pending)) {
  6682. goto exit_shake128;
  6683. }
  6684. }
  6685. } /* for i */
  6686. RECORD_MULTI_VALUE_STATS();
  6687. } /* for times */
  6688. count += times;
  6689. times = 0;
  6690. do {
  6691. bench_async_poll(&pending);
  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_Final(hash[i], digest[i],
  6696. WC_SHA3_128_BLOCK_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. } while (pending > 0);
  6705. } while (bench_stats_check(start)
  6706. #ifdef MULTI_VALUE_STATISTICS
  6707. || runs < minimum_runs
  6708. #endif
  6709. );
  6710. }
  6711. else {
  6712. bench_stats_start(&count, &start);
  6713. do {
  6714. for (times = 0; times < numBlocks; times++) {
  6715. ret = wc_InitShake128(hash[0], HEAP_HINT,
  6716. useDeviceID ? devId : INVALID_DEVID);
  6717. if (ret == 0)
  6718. ret = wc_Shake128_Update(hash[0], bench_plain, bench_size);
  6719. if (ret == 0)
  6720. ret = wc_Shake128_Final(hash[0], digest[0],
  6721. WC_SHA3_128_BLOCK_SIZE);
  6722. if (ret != 0)
  6723. goto exit_shake128;
  6724. RECORD_MULTI_VALUE_STATS();
  6725. } /* for times */
  6726. count += times;
  6727. } while (bench_stats_check(start)
  6728. #ifdef MULTI_VALUE_STATISTICS
  6729. || runs < minimum_runs
  6730. #endif
  6731. );
  6732. }
  6733. exit_shake128:
  6734. bench_stats_sym_finish("SHAKE128", useDeviceID, count, bench_size,
  6735. start, ret);
  6736. #ifdef MULTI_VALUE_STATISTICS
  6737. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6738. #endif
  6739. exit:
  6740. if (WC_ARRAY_OK(hash)) {
  6741. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6742. wc_Shake128_Free(hash[i]);
  6743. }
  6744. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6745. }
  6746. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6747. }
  6748. #endif /* WOLFSSL_SHAKE128 */
  6749. #ifdef WOLFSSL_SHAKE256
  6750. void bench_shake256(int useDeviceID)
  6751. {
  6752. WC_DECLARE_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6753. sizeof(wc_Shake), HEAP_HINT);
  6754. double start;
  6755. int ret = 0, i, count = 0, times, pending = 0;
  6756. DECLARE_MULTI_VALUE_STATS_VARS()
  6757. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6758. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6759. WC_CALLOC_ARRAY(hash, wc_Shake, BENCH_MAX_PENDING,
  6760. sizeof(wc_Shake), HEAP_HINT);
  6761. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  6762. WC_SHA3_256_BLOCK_SIZE, HEAP_HINT);
  6763. if (digest_stream) {
  6764. /* init keys */
  6765. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6766. ret = wc_InitShake256(hash[i], HEAP_HINT,
  6767. useDeviceID ? devId : INVALID_DEVID);
  6768. if (ret != 0) {
  6769. printf("InitShake256 failed, ret = %d\n", ret);
  6770. goto exit;
  6771. }
  6772. }
  6773. bench_stats_start(&count, &start);
  6774. do {
  6775. for (times = 0; times < numBlocks || pending > 0; ) {
  6776. bench_async_poll(&pending);
  6777. /* while free pending slots in queue, submit ops */
  6778. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6779. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6780. 0, &times, numBlocks, &pending)) {
  6781. ret = wc_Shake256_Update(hash[i], bench_plain,
  6782. bench_size);
  6783. if (!bench_async_handle(&ret,
  6784. BENCH_ASYNC_GET_DEV(hash[i]), 0,
  6785. &times, &pending)) {
  6786. goto exit_shake256;
  6787. }
  6788. }
  6789. } /* for i */
  6790. RECORD_MULTI_VALUE_STATS();
  6791. } /* for times */
  6792. count += times;
  6793. times = 0;
  6794. do {
  6795. bench_async_poll(&pending);
  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_Final(hash[i], digest[i],
  6800. WC_SHA3_256_BLOCK_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. } while (pending > 0);
  6809. } while (bench_stats_check(start)
  6810. #ifdef MULTI_VALUE_STATISTICS
  6811. || runs < minimum_runs
  6812. #endif
  6813. );
  6814. }
  6815. else {
  6816. bench_stats_start(&count, &start);
  6817. do {
  6818. for (times = 0; times < numBlocks; times++) {
  6819. ret = wc_InitShake256(hash[0], HEAP_HINT,
  6820. useDeviceID ? devId : INVALID_DEVID);
  6821. if (ret == 0)
  6822. ret = wc_Shake256_Update(hash[0], bench_plain, bench_size);
  6823. if (ret == 0)
  6824. ret = wc_Shake256_Final(hash[0], digest[0],
  6825. WC_SHA3_256_BLOCK_SIZE);
  6826. if (ret != 0)
  6827. goto exit_shake256;
  6828. RECORD_MULTI_VALUE_STATS();
  6829. } /* for times */
  6830. count += times;
  6831. } while (bench_stats_check(start)
  6832. #ifdef MULTI_VALUE_STATISTICS
  6833. || runs < minimum_runs
  6834. #endif
  6835. );
  6836. }
  6837. exit_shake256:
  6838. bench_stats_sym_finish("SHAKE256", useDeviceID, count, bench_size,
  6839. start, ret);
  6840. #ifdef MULTI_VALUE_STATISTICS
  6841. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6842. #endif
  6843. exit:
  6844. if (WC_ARRAY_OK(hash)) {
  6845. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6846. wc_Shake256_Free(hash[i]);
  6847. }
  6848. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6849. }
  6850. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6851. }
  6852. #endif /* WOLFSSL_SHAKE256 */
  6853. #endif
  6854. #ifdef WOLFSSL_SM3
  6855. void bench_sm3(int useDeviceID)
  6856. {
  6857. WC_DECLARE_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6858. sizeof(wc_Sm3), HEAP_HINT);
  6859. double start;
  6860. int ret = 0, i, count = 0, times, pending = 0;
  6861. DECLARE_MULTI_VALUE_STATS_VARS()
  6862. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6863. HEAP_HINT);
  6864. WC_CALLOC_ARRAY(hash, wc_Sm3, BENCH_MAX_PENDING,
  6865. sizeof(wc_Sm3), HEAP_HINT);
  6866. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, WC_SM3_DIGEST_SIZE,
  6867. HEAP_HINT);
  6868. if (digest_stream) {
  6869. /* init keys */
  6870. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6871. ret = wc_InitSm3(hash[i], HEAP_HINT,
  6872. useDeviceID ? devId: INVALID_DEVID);
  6873. if (ret != 0) {
  6874. printf("InitSm3 failed, ret = %d\n", ret);
  6875. goto exit;
  6876. }
  6877. }
  6878. bench_stats_start(&count, &start);
  6879. do {
  6880. for (times = 0; times < numBlocks || pending > 0; ) {
  6881. bench_async_poll(&pending);
  6882. /* while free pending slots in queue, submit ops */
  6883. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6884. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6885. 0, &times, numBlocks, &pending)) {
  6886. ret = wc_Sm3Update(hash[i], bench_plain,
  6887. bench_size);
  6888. if (!bench_async_handle(&ret,
  6889. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6890. goto exit_sm3;
  6891. }
  6892. }
  6893. } /* for i */
  6894. RECORD_MULTI_VALUE_STATS();
  6895. } /* for times */
  6896. count += times;
  6897. times = 0;
  6898. do {
  6899. bench_async_poll(&pending);
  6900. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6901. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(hash[i]),
  6902. 0, &times, numBlocks, &pending)) {
  6903. ret = wc_Sm3Final(hash[i], digest[i]);
  6904. if (!bench_async_handle(&ret,
  6905. BENCH_ASYNC_GET_DEV(hash[i]), 0, &times, &pending)) {
  6906. goto exit_sm3;
  6907. }
  6908. }
  6909. } /* for i */
  6910. } while (pending > 0);
  6911. } while (bench_stats_check(start)
  6912. #ifdef MULTI_VALUE_STATISTICS
  6913. || runs < minimum_runs
  6914. #endif
  6915. );
  6916. }
  6917. else {
  6918. bench_stats_start(&count, &start);
  6919. do {
  6920. for (times = 0; times < numBlocks; times++) {
  6921. ret = wc_InitSm3(hash[0], HEAP_HINT,
  6922. useDeviceID ? devId: INVALID_DEVID);
  6923. if (ret == 0)
  6924. ret = wc_Sm3Update(hash[0], bench_plain, bench_size);
  6925. if (ret == 0)
  6926. ret = wc_Sm3Final(hash[0], digest[0]);
  6927. if (ret != 0)
  6928. goto exit_sm3;
  6929. RECORD_MULTI_VALUE_STATS();
  6930. } /* for times */
  6931. count += times;
  6932. } while (bench_stats_check(start)
  6933. #ifdef MULTI_VALUE_STATISTICS
  6934. || runs < minimum_runs
  6935. #endif
  6936. );
  6937. }
  6938. exit_sm3:
  6939. bench_stats_sym_finish("SM3", useDeviceID, count, bench_size, start, ret);
  6940. #ifdef MULTI_VALUE_STATISTICS
  6941. bench_multi_value_stats(max, min, sum, squareSum, runs);
  6942. #endif
  6943. exit:
  6944. if (WC_ARRAY_OK(hash)) {
  6945. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  6946. wc_Sm3Free(hash[i]);
  6947. }
  6948. WC_FREE_ARRAY(hash, BENCH_MAX_PENDING, HEAP_HINT);
  6949. }
  6950. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  6951. }
  6952. #endif
  6953. #ifdef WOLFSSL_RIPEMD
  6954. void bench_ripemd(void)
  6955. {
  6956. RipeMd hash;
  6957. byte digest[RIPEMD_DIGEST_SIZE];
  6958. double start;
  6959. int i, count, ret = 0;
  6960. DECLARE_MULTI_VALUE_STATS_VARS()
  6961. if (digest_stream) {
  6962. ret = wc_InitRipeMd(&hash);
  6963. if (ret != 0) {
  6964. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6965. return;
  6966. }
  6967. bench_stats_start(&count, &start);
  6968. do {
  6969. for (i = 0; i < numBlocks; i++) {
  6970. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6971. if (ret != 0) {
  6972. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  6973. return;
  6974. }
  6975. RECORD_MULTI_VALUE_STATS();
  6976. }
  6977. ret = wc_RipeMdFinal(&hash, digest);
  6978. if (ret != 0) {
  6979. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  6980. return;
  6981. }
  6982. count += i;
  6983. } while (bench_stats_check(start)
  6984. #ifdef MULTI_VALUE_STATISTICS
  6985. || runs < minimum_runs
  6986. #endif
  6987. );
  6988. }
  6989. else {
  6990. bench_stats_start(&count, &start);
  6991. do {
  6992. for (i = 0; i < numBlocks; i++) {
  6993. ret = wc_InitRipeMd(&hash);
  6994. if (ret != 0) {
  6995. printf("wc_InitRipeMd failed, retval %d\n", ret);
  6996. return;
  6997. }
  6998. ret = wc_RipeMdUpdate(&hash, bench_plain, bench_size);
  6999. if (ret != 0) {
  7000. printf("wc_RipeMdUpdate failed, retval %d\n", ret);
  7001. return;
  7002. }
  7003. ret = wc_RipeMdFinal(&hash, digest);
  7004. if (ret != 0) {
  7005. printf("wc_RipeMdFinal failed, retval %d\n", ret);
  7006. return;
  7007. }
  7008. RECORD_MULTI_VALUE_STATS();
  7009. }
  7010. count += i;
  7011. } while (bench_stats_check(start)
  7012. #ifdef MULTI_VALUE_STATISTICS
  7013. || runs < minimum_runs
  7014. #endif
  7015. );
  7016. }
  7017. bench_stats_sym_finish("RIPEMD", 0, count, bench_size, start, ret);
  7018. #ifdef MULTI_VALUE_STATISTICS
  7019. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7020. #endif
  7021. return;
  7022. }
  7023. #endif
  7024. #ifdef HAVE_BLAKE2
  7025. void bench_blake2b(void)
  7026. {
  7027. Blake2b b2b;
  7028. byte digest[64];
  7029. double start;
  7030. int ret = 0, i, count;
  7031. DECLARE_MULTI_VALUE_STATS_VARS()
  7032. if (digest_stream) {
  7033. ret = wc_InitBlake2b(&b2b, 64);
  7034. if (ret != 0) {
  7035. printf("InitBlake2b failed, ret = %d\n", ret);
  7036. return;
  7037. }
  7038. bench_stats_start(&count, &start);
  7039. do {
  7040. for (i = 0; i < numBlocks; i++) {
  7041. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7042. if (ret != 0) {
  7043. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7044. return;
  7045. }
  7046. RECORD_MULTI_VALUE_STATS();
  7047. }
  7048. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7049. if (ret != 0) {
  7050. printf("Blake2bFinal failed, ret = %d\n", ret);
  7051. return;
  7052. }
  7053. count += i;
  7054. } while (bench_stats_check(start)
  7055. #ifdef MULTI_VALUE_STATISTICS
  7056. || runs < minimum_runs
  7057. #endif
  7058. );
  7059. }
  7060. else {
  7061. bench_stats_start(&count, &start);
  7062. do {
  7063. for (i = 0; i < numBlocks; i++) {
  7064. ret = wc_InitBlake2b(&b2b, 64);
  7065. if (ret != 0) {
  7066. printf("InitBlake2b failed, ret = %d\n", ret);
  7067. return;
  7068. }
  7069. ret = wc_Blake2bUpdate(&b2b, bench_plain, bench_size);
  7070. if (ret != 0) {
  7071. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7072. return;
  7073. }
  7074. ret = wc_Blake2bFinal(&b2b, digest, 64);
  7075. if (ret != 0) {
  7076. printf("Blake2bFinal failed, ret = %d\n", ret);
  7077. return;
  7078. }
  7079. RECORD_MULTI_VALUE_STATS();
  7080. }
  7081. count += i;
  7082. } while (bench_stats_check(start)
  7083. #ifdef MULTI_VALUE_STATISTICS
  7084. || runs < minimum_runs
  7085. #endif
  7086. );
  7087. }
  7088. bench_stats_sym_finish("BLAKE2b", 0, count, bench_size, start, ret);
  7089. #ifdef MULTI_VALUE_STATISTICS
  7090. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7091. #endif
  7092. }
  7093. #endif
  7094. #if defined(HAVE_BLAKE2S)
  7095. void bench_blake2s(void)
  7096. {
  7097. Blake2s b2s;
  7098. byte digest[32];
  7099. double start;
  7100. int ret = 0, i, count;
  7101. DECLARE_MULTI_VALUE_STATS_VARS()
  7102. if (digest_stream) {
  7103. ret = wc_InitBlake2s(&b2s, 32);
  7104. if (ret != 0) {
  7105. printf("InitBlake2s failed, ret = %d\n", ret);
  7106. return;
  7107. }
  7108. bench_stats_start(&count, &start);
  7109. do {
  7110. for (i = 0; i < numBlocks; i++) {
  7111. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7112. if (ret != 0) {
  7113. printf("Blake2sUpdate failed, ret = %d\n", ret);
  7114. return;
  7115. }
  7116. RECORD_MULTI_VALUE_STATS();
  7117. }
  7118. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7119. if (ret != 0) {
  7120. printf("Blake2sFinal failed, ret = %d\n", ret);
  7121. return;
  7122. }
  7123. count += i;
  7124. } while (bench_stats_check(start)
  7125. #ifdef MULTI_VALUE_STATISTICS
  7126. || runs < minimum_runs
  7127. #endif
  7128. );
  7129. }
  7130. else {
  7131. bench_stats_start(&count, &start);
  7132. do {
  7133. for (i = 0; i < numBlocks; i++) {
  7134. ret = wc_InitBlake2s(&b2s, 32);
  7135. if (ret != 0) {
  7136. printf("InitBlake2b failed, ret = %d\n", ret);
  7137. return;
  7138. }
  7139. ret = wc_Blake2sUpdate(&b2s, bench_plain, bench_size);
  7140. if (ret != 0) {
  7141. printf("Blake2bUpdate failed, ret = %d\n", ret);
  7142. return;
  7143. }
  7144. ret = wc_Blake2sFinal(&b2s, digest, 32);
  7145. if (ret != 0) {
  7146. printf("Blake2sFinal failed, ret = %d\n", ret);
  7147. return;
  7148. }
  7149. RECORD_MULTI_VALUE_STATS();
  7150. }
  7151. count += i;
  7152. } while (bench_stats_check(start)
  7153. #ifdef MULTI_VALUE_STATISTICS
  7154. || runs < minimum_runs
  7155. #endif
  7156. );
  7157. }
  7158. bench_stats_sym_finish("BLAKE2s", 0, count, bench_size, start, ret);
  7159. #ifdef MULTI_VALUE_STATISTICS
  7160. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7161. #endif
  7162. }
  7163. #endif
  7164. #ifdef WOLFSSL_CMAC
  7165. static void bench_cmac_helper(word32 keySz, const char* outMsg, int useDeviceID)
  7166. {
  7167. Cmac cmac;
  7168. byte digest[AES_BLOCK_SIZE];
  7169. word32 digestSz = sizeof(digest);
  7170. double start;
  7171. int ret, i, count;
  7172. DECLARE_MULTI_VALUE_STATS_VARS()
  7173. #ifdef WOLFSSL_SECO_CAAM
  7174. unsigned int keyID;
  7175. int keyGroup = 1; /* group one was chosen arbitrarily */
  7176. int keyInfo = CAAM_KEY_TRANSIENT;
  7177. int keyType = CAAM_KEYTYPE_AES128;
  7178. byte pubKey[AES_256_KEY_SIZE];
  7179. if (keySz == AES_256_KEY_SIZE) {
  7180. keyType = CAAM_KEYTYPE_AES256;
  7181. }
  7182. if (useDeviceID &&
  7183. wc_SECO_GenerateKey(CAAM_GENERATE_KEY, keyGroup, pubKey, 0, keyType,
  7184. keyInfo, &keyID) != 0) {
  7185. printf("Error generating key in hsm\n");
  7186. return;
  7187. }
  7188. #endif
  7189. (void)useDeviceID;
  7190. bench_stats_start(&count, &start);
  7191. do {
  7192. #ifdef HAVE_FIPS
  7193. ret = wc_InitCmac(&cmac, bench_key, keySz, WC_CMAC_AES, NULL);
  7194. #else
  7195. ret = wc_InitCmac_ex(&cmac, bench_key, keySz, WC_CMAC_AES, NULL,
  7196. HEAP_HINT, useDeviceID ? devId : INVALID_DEVID);
  7197. #endif
  7198. if (ret != 0) {
  7199. printf("InitCmac failed, ret = %d\n", ret);
  7200. return;
  7201. }
  7202. #ifdef WOLFSSL_SECO_CAAM
  7203. if (useDeviceID) {
  7204. wc_SECO_CMACSetKeyID(&cmac, keyID);
  7205. }
  7206. #endif
  7207. for (i = 0; i < numBlocks; i++) {
  7208. ret = wc_CmacUpdate(&cmac, bench_plain, bench_size);
  7209. if (ret != 0) {
  7210. printf("CmacUpdate failed, ret = %d\n", ret);
  7211. return;
  7212. }
  7213. RECORD_MULTI_VALUE_STATS();
  7214. }
  7215. /* Note: final force zero's the Cmac struct */
  7216. ret = wc_CmacFinal(&cmac, digest, &digestSz);
  7217. if (ret != 0) {
  7218. printf("CmacFinal failed, ret = %d\n", ret);
  7219. return;
  7220. }
  7221. count += i;
  7222. } while (bench_stats_check(start)
  7223. #ifdef MULTI_VALUE_STATISTICS
  7224. || runs < minimum_runs
  7225. #endif
  7226. );
  7227. bench_stats_sym_finish(outMsg, useDeviceID, count, bench_size, start, ret);
  7228. #ifdef MULTI_VALUE_STATISTICS
  7229. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7230. #endif
  7231. }
  7232. void bench_cmac(int useDeviceID)
  7233. {
  7234. #ifdef WOLFSSL_AES_128
  7235. bench_cmac_helper(16, "AES-128-CMAC", useDeviceID);
  7236. #endif
  7237. #ifdef WOLFSSL_AES_256
  7238. bench_cmac_helper(32, "AES-256-CMAC", useDeviceID);
  7239. #endif
  7240. }
  7241. #endif /* WOLFSSL_CMAC */
  7242. #ifdef HAVE_SCRYPT
  7243. void bench_scrypt(void)
  7244. {
  7245. byte derived[64];
  7246. double start;
  7247. int ret, i, count;
  7248. DECLARE_MULTI_VALUE_STATS_VARS()
  7249. bench_stats_start(&count, &start);
  7250. do {
  7251. for (i = 0; i < scryptCnt; i++) {
  7252. ret = wc_scrypt(derived, (byte*)"pleaseletmein", 13,
  7253. (byte*)"SodiumChloride", 14, 14, 8, 1,
  7254. sizeof(derived));
  7255. if (ret != 0) {
  7256. printf("scrypt failed, ret = %d\n", ret);
  7257. goto exit;
  7258. }
  7259. RECORD_MULTI_VALUE_STATS();
  7260. }
  7261. count += i;
  7262. } while (bench_stats_check(start)
  7263. #ifdef MULTI_VALUE_STATISTICS
  7264. || runs < minimum_runs
  7265. #endif
  7266. );
  7267. exit:
  7268. bench_stats_asym_finish("scrypt", 17, "", 0, count, start, ret);
  7269. #ifdef MULTI_VALUE_STATISTICS
  7270. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7271. #endif
  7272. }
  7273. #endif /* HAVE_SCRYPT */
  7274. #ifndef NO_HMAC
  7275. static void bench_hmac(int useDeviceID, int type, int digestSz,
  7276. const byte* key, word32 keySz, const char* label)
  7277. {
  7278. WC_DECLARE_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7279. sizeof(Hmac), HEAP_HINT);
  7280. double start;
  7281. int ret = 0, i, count = 0, times, pending = 0;
  7282. DECLARE_MULTI_VALUE_STATS_VARS()
  7283. #ifdef WOLFSSL_ASYNC_CRYPT
  7284. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7285. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7286. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING,
  7287. WC_MAX_DIGEST_SIZE, HEAP_HINT);
  7288. #else
  7289. byte digest[BENCH_MAX_PENDING][WC_MAX_DIGEST_SIZE];
  7290. #endif
  7291. (void)digestSz;
  7292. WC_CALLOC_ARRAY(hmac, Hmac, BENCH_MAX_PENDING,
  7293. sizeof(Hmac), HEAP_HINT);
  7294. /* init keys */
  7295. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7296. ret = wc_HmacInit(hmac[i], HEAP_HINT,
  7297. useDeviceID ? devId : INVALID_DEVID);
  7298. if (ret != 0) {
  7299. printf("wc_HmacInit failed for %s, ret = %d\n", label, ret);
  7300. goto exit;
  7301. }
  7302. ret = wc_HmacSetKey(hmac[i], type, key, keySz);
  7303. if (ret != 0) {
  7304. printf("wc_HmacSetKey failed for %s, ret = %d\n", label, ret);
  7305. goto exit;
  7306. }
  7307. }
  7308. bench_stats_start(&count, &start);
  7309. do {
  7310. for (times = 0; times < numBlocks || pending > 0; ) {
  7311. bench_async_poll(&pending);
  7312. /* while free pending slots in queue, submit ops */
  7313. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7314. if (bench_async_check(&ret,
  7315. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7316. &times, numBlocks, &pending)) {
  7317. ret = wc_HmacUpdate(hmac[i], bench_plain, bench_size);
  7318. if (!bench_async_handle(&ret,
  7319. BENCH_ASYNC_GET_DEV(hmac[i]),
  7320. 0, &times, &pending)) {
  7321. goto exit_hmac;
  7322. }
  7323. }
  7324. } /* for i */
  7325. } /* for times */
  7326. count += times;
  7327. times = 0;
  7328. do {
  7329. bench_async_poll(&pending);
  7330. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7331. if (bench_async_check(&ret,
  7332. BENCH_ASYNC_GET_DEV(hmac[i]), 0,
  7333. &times, numBlocks, &pending)) {
  7334. ret = wc_HmacFinal(hmac[i], digest[i]);
  7335. if (!bench_async_handle(&ret,
  7336. BENCH_ASYNC_GET_DEV(hmac[i]),
  7337. 0, &times, &pending)) {
  7338. goto exit_hmac;
  7339. }
  7340. }
  7341. RECORD_MULTI_VALUE_STATS();
  7342. } /* for i */
  7343. } while (pending > 0);
  7344. } while (bench_stats_check(start)
  7345. #ifdef MULTI_VALUE_STATISTICS
  7346. || runs < minimum_runs
  7347. #endif
  7348. );
  7349. exit_hmac:
  7350. bench_stats_sym_finish(label, useDeviceID, count, bench_size, start, ret);
  7351. #ifdef MULTI_VALUE_STATISTICS
  7352. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7353. #endif
  7354. exit:
  7355. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7356. wc_HmacFree(hmac[i]);
  7357. }
  7358. WC_FREE_ARRAY(hmac, BENCH_MAX_PENDING, HEAP_HINT);
  7359. #ifdef WOLFSSL_ASYNC_CRYPT
  7360. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  7361. #endif
  7362. }
  7363. #ifndef NO_MD5
  7364. void bench_hmac_md5(int useDeviceID)
  7365. {
  7366. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7367. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7368. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7369. bench_hmac(useDeviceID, WC_MD5, WC_MD5_DIGEST_SIZE, key, sizeof(key),
  7370. "HMAC-MD5");
  7371. }
  7372. #endif /* NO_MD5 */
  7373. #ifndef NO_SHA
  7374. void bench_hmac_sha(int useDeviceID)
  7375. {
  7376. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7377. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7378. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7379. 0x0b, 0x0b, 0x0b, 0x0b };
  7380. bench_hmac(useDeviceID, WC_SHA, WC_SHA_DIGEST_SIZE, key, sizeof(key),
  7381. "HMAC-SHA");
  7382. }
  7383. #endif /* NO_SHA */
  7384. #ifdef WOLFSSL_SHA224
  7385. void bench_hmac_sha224(int useDeviceID)
  7386. {
  7387. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7388. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7389. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7390. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7391. 0x0b, 0x0b, 0x0b, 0x0b };
  7392. bench_hmac(useDeviceID, WC_SHA224,
  7393. WC_SHA224_DIGEST_SIZE, key, sizeof(key),
  7394. "HMAC-SHA224");
  7395. }
  7396. #endif /* WOLFSSL_SHA224 */
  7397. #ifndef NO_SHA256
  7398. void bench_hmac_sha256(int useDeviceID)
  7399. {
  7400. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7401. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7402. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7403. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7404. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7405. bench_hmac(useDeviceID, WC_SHA256, WC_SHA256_DIGEST_SIZE, key, sizeof(key),
  7406. "HMAC-SHA256");
  7407. }
  7408. #endif /* NO_SHA256 */
  7409. #ifdef WOLFSSL_SHA384
  7410. void bench_hmac_sha384(int useDeviceID)
  7411. {
  7412. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7413. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7414. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7415. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7416. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7417. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7418. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7419. bench_hmac(useDeviceID, WC_SHA384, WC_SHA384_DIGEST_SIZE, key, sizeof(key),
  7420. "HMAC-SHA384");
  7421. }
  7422. #endif /* WOLFSSL_SHA384 */
  7423. #ifdef WOLFSSL_SHA512
  7424. void bench_hmac_sha512(int useDeviceID)
  7425. {
  7426. WOLFSSL_SMALL_STACK_STATIC const byte key[] = {
  7427. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7428. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7429. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7430. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7431. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7432. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7433. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
  7434. 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
  7435. bench_hmac(useDeviceID, WC_SHA512, WC_SHA512_DIGEST_SIZE, key, sizeof(key),
  7436. "HMAC-SHA512");
  7437. }
  7438. #endif /* WOLFSSL_SHA512 */
  7439. #ifndef NO_PWDBASED
  7440. void bench_pbkdf2(void)
  7441. {
  7442. double start;
  7443. int ret = 0, count = 0;
  7444. const char* passwd32 = "passwordpasswordpasswordpassword";
  7445. WOLFSSL_SMALL_STACK_STATIC const byte salt32[] = {
  7446. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7447. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7448. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06,
  7449. 0x78, 0x57, 0x8E, 0x5a, 0x5d, 0x63, 0xcb, 0x06 };
  7450. byte derived[32];
  7451. DECLARE_MULTI_VALUE_STATS_VARS()
  7452. bench_stats_start(&count, &start);
  7453. PRIVATE_KEY_UNLOCK();
  7454. do {
  7455. ret = wc_PBKDF2(derived, (const byte*)passwd32, (int)XSTRLEN(passwd32),
  7456. salt32, (int)sizeof(salt32), 1000, 32, WC_SHA256);
  7457. count++;
  7458. RECORD_MULTI_VALUE_STATS();
  7459. } while (bench_stats_check(start)
  7460. #ifdef MULTI_VALUE_STATISTICS
  7461. || runs < minimum_runs
  7462. #endif
  7463. );
  7464. PRIVATE_KEY_LOCK();
  7465. bench_stats_sym_finish("PBKDF2", 32, count, 32, start, ret);
  7466. #ifdef MULTI_VALUE_STATISTICS
  7467. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7468. #endif
  7469. }
  7470. #endif /* !NO_PWDBASED */
  7471. #endif /* NO_HMAC */
  7472. #ifdef WOLFSSL_SIPHASH
  7473. void bench_siphash(void)
  7474. {
  7475. double start;
  7476. int ret = 0, count;
  7477. const char* passwd16 = "passwordpassword";
  7478. byte out[16];
  7479. int i;
  7480. DECLARE_MULTI_VALUE_STATS_VARS()
  7481. bench_stats_start(&count, &start);
  7482. do {
  7483. for (i = 0; i < numBlocks; i++) {
  7484. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7485. out, 8);
  7486. RECORD_MULTI_VALUE_STATS();
  7487. }
  7488. count += i;
  7489. } while (bench_stats_check(start)
  7490. #ifdef MULTI_VALUE_STATISTICS
  7491. || runs < minimum_runs
  7492. #endif
  7493. );
  7494. bench_stats_sym_finish("SipHash-8", 1, count, bench_size, start, ret);
  7495. #ifdef MULTI_VALUE_STATISTICS
  7496. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7497. #endif
  7498. RESET_MULTI_VALUE_STATS_VARS();
  7499. bench_stats_start(&count, &start);
  7500. do {
  7501. for (i = 0; i < numBlocks; i++) {
  7502. ret = wc_SipHash((const byte*)passwd16, bench_plain, bench_size,
  7503. out, 16);
  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-16", 1, count, bench_size, start, ret);
  7513. #ifdef MULTI_VALUE_STATISTICS
  7514. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7515. #endif
  7516. }
  7517. #endif
  7518. #ifdef WC_SRTP_KDF
  7519. void bench_srtpkdf(void)
  7520. {
  7521. double start;
  7522. int count;
  7523. int ret = 0;
  7524. byte keyE[32];
  7525. byte keyA[20];
  7526. byte keyS[14];
  7527. const byte *key = bench_key_buf;
  7528. const byte salt[14] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
  7529. 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e };
  7530. const byte index[6] = { 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA };
  7531. int kdrIdx = 0;
  7532. int i;
  7533. DECLARE_MULTI_VALUE_STATS_VARS()
  7534. bench_stats_start(&count, &start);
  7535. PRIVATE_KEY_UNLOCK();
  7536. do {
  7537. for (i = 0; i < numBlocks; i++) {
  7538. ret = wc_SRTP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7539. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7540. keyS, sizeof(keyS));
  7541. RECORD_MULTI_VALUE_STATS();
  7542. }
  7543. count += i;
  7544. } while (bench_stats_check(start)
  7545. #ifdef MULTI_VALUE_STATISTICS
  7546. || runs < minimum_runs
  7547. #endif
  7548. );
  7549. PRIVATE_KEY_LOCK();
  7550. bench_stats_asym_finish("KDF", 128, "SRTP", 0, count, start, ret);
  7551. #ifdef MULTI_VALUE_STATISTICS
  7552. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7553. #endif
  7554. RESET_MULTI_VALUE_STATS_VARS();
  7555. bench_stats_start(&count, &start);
  7556. PRIVATE_KEY_UNLOCK();
  7557. do {
  7558. for (i = 0; i < numBlocks; i++) {
  7559. ret = wc_SRTP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7560. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7561. keyS, sizeof(keyS));
  7562. RECORD_MULTI_VALUE_STATS();
  7563. }
  7564. count += i;
  7565. } while (bench_stats_check(start)
  7566. #ifdef MULTI_VALUE_STATISTICS
  7567. || runs < minimum_runs
  7568. #endif
  7569. );
  7570. PRIVATE_KEY_LOCK();
  7571. bench_stats_asym_finish("KDF", 256, "SRTP", 0, count, start, ret);
  7572. #ifdef MULTI_VALUE_STATISTICS
  7573. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7574. #endif
  7575. RESET_MULTI_VALUE_STATS_VARS();
  7576. bench_stats_start(&count, &start);
  7577. PRIVATE_KEY_UNLOCK();
  7578. do {
  7579. for (i = 0; i < numBlocks; i++) {
  7580. ret = wc_SRTCP_KDF(key, AES_128_KEY_SIZE, salt, sizeof(salt),
  7581. kdrIdx, index, keyE, AES_128_KEY_SIZE, keyA, sizeof(keyA),
  7582. keyS, sizeof(keyS));
  7583. RECORD_MULTI_VALUE_STATS();
  7584. }
  7585. count += i;
  7586. } while (bench_stats_check(start)
  7587. #ifdef MULTI_VALUE_STATISTICS
  7588. || runs < minimum_runs
  7589. #endif
  7590. );
  7591. PRIVATE_KEY_LOCK();
  7592. bench_stats_asym_finish("KDF", 128, "SRTCP", 0, count, start, ret);
  7593. #ifdef MULTI_VALUE_STATISTICS
  7594. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7595. #endif
  7596. RESET_MULTI_VALUE_STATS_VARS();
  7597. bench_stats_start(&count, &start);
  7598. PRIVATE_KEY_UNLOCK();
  7599. do {
  7600. for (i = 0; i < numBlocks; i++) {
  7601. ret = wc_SRTCP_KDF(key, AES_256_KEY_SIZE, salt, sizeof(salt),
  7602. kdrIdx, index, keyE, AES_256_KEY_SIZE, keyA, sizeof(keyA),
  7603. keyS, sizeof(keyS));
  7604. RECORD_MULTI_VALUE_STATS();
  7605. }
  7606. count += i;
  7607. } while (bench_stats_check(start)
  7608. #ifdef MULTI_VALUE_STATISTICS
  7609. || runs < minimum_runs
  7610. #endif
  7611. );
  7612. PRIVATE_KEY_LOCK();
  7613. bench_stats_asym_finish("KDF", 256, "SRTCP", 0, count, start, ret);
  7614. #ifdef MULTI_VALUE_STATISTICS
  7615. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7616. #endif
  7617. }
  7618. #endif
  7619. #ifndef NO_RSA
  7620. #if defined(WOLFSSL_KEY_GEN)
  7621. static void bench_rsaKeyGen_helper(int useDeviceID, word32 keySz)
  7622. {
  7623. WC_DECLARE_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7624. sizeof(RsaKey), HEAP_HINT);
  7625. double start = 0;
  7626. int ret = 0, i, count = 0, times, pending = 0;
  7627. const long rsa_e_val = WC_RSA_EXPONENT;
  7628. const char**desc = bench_desc_words[lng_index];
  7629. DECLARE_MULTI_VALUE_STATS_VARS()
  7630. WC_CALLOC_ARRAY(genKey, RsaKey, BENCH_MAX_PENDING,
  7631. sizeof(RsaKey), HEAP_HINT);
  7632. bench_stats_start(&count, &start);
  7633. do {
  7634. /* while free pending slots in queue, submit ops */
  7635. for (times = 0; times < genTimes || pending > 0; ) {
  7636. bench_async_poll(&pending);
  7637. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7638. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]),
  7639. 0, &times, genTimes, &pending)) {
  7640. wc_FreeRsaKey(genKey[i]);
  7641. ret = wc_InitRsaKey_ex(genKey[i], HEAP_HINT, devId);
  7642. if (ret < 0) {
  7643. goto exit;
  7644. }
  7645. ret = wc_MakeRsaKey(genKey[i], (int)keySz, rsa_e_val,
  7646. &gRng);
  7647. if (!bench_async_handle(&ret,
  7648. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  7649. &times, &pending)) {
  7650. goto exit;
  7651. }
  7652. }
  7653. } /* for i */
  7654. RECORD_MULTI_VALUE_STATS();
  7655. } /* for times */
  7656. count += times;
  7657. } while (bench_stats_check(start)
  7658. #ifdef MULTI_VALUE_STATISTICS
  7659. || runs < minimum_runs
  7660. #endif
  7661. );
  7662. exit:
  7663. bench_stats_asym_finish("RSA", (int)keySz, desc[2], useDeviceID, count,
  7664. start, ret);
  7665. #ifdef MULTI_VALUE_STATISTICS
  7666. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7667. #endif
  7668. /* cleanup */
  7669. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7670. wc_FreeRsaKey(genKey[i]);
  7671. }
  7672. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  7673. }
  7674. void bench_rsaKeyGen(int useDeviceID)
  7675. {
  7676. int k;
  7677. #if !defined(RSA_MAX_SIZE) || !defined(RSA_MIN_SIZE)
  7678. static const word32 keySizes[2] = {1024, 2048 };
  7679. #elif RSA_MAX_SIZE >= 4096
  7680. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7681. (RSA_MIN_SIZE <= 1024)
  7682. static const word32 keySizes[4] = {1024, 2048, 3072, 4096 };
  7683. #else
  7684. static const word32 keySizes[3] = {2048, 3072, 4096};
  7685. #endif
  7686. #elif RSA_MAX_SIZE >= 3072
  7687. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7688. (RSA_MIN_SIZE <= 1024)
  7689. static const word32 keySizes[3] = {1024, 2048, 3072 };
  7690. #else
  7691. static const word32 keySizes[2] = {2048, 3072 };
  7692. #endif
  7693. #elif RSA_MAX_SIZE >= 2048
  7694. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7695. (RSA_MIN_SIZE <= 1024)
  7696. static const word32 keySizes[2] = {1024, 2048 };
  7697. #else
  7698. static const word32 keySizes[1] = {2048};
  7699. #endif
  7700. #else
  7701. #if (!defined(WOLFSSL_SP_MATH) || defined(WOLFSSL_SP_MATH_ALL)) && \
  7702. (RSA_MIN_SIZE <= 1024)
  7703. static const word32 keySizes[1] = {1024 };
  7704. #else
  7705. #error No candidate RSA key sizes to benchmark.
  7706. #endif
  7707. #endif
  7708. for (k = 0; k < (int)(sizeof(keySizes)/sizeof(int)); k++) {
  7709. bench_rsaKeyGen_helper(useDeviceID, keySizes[k]);
  7710. }
  7711. }
  7712. void bench_rsaKeyGen_size(int useDeviceID, word32 keySz)
  7713. {
  7714. bench_rsaKeyGen_helper(useDeviceID, keySz);
  7715. }
  7716. #endif /* WOLFSSL_KEY_GEN */
  7717. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  7718. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  7719. #if defined(WOLFSSL_MDK_SHELL)
  7720. static char *certRSAname = "certs/rsa2048.der";
  7721. /* set by shell command */
  7722. static void set_Bench_RSA_File(char * cert) { certRSAname = cert ; }
  7723. #elif defined(FREESCALE_MQX)
  7724. static char *certRSAname = "a:\\certs\\rsa2048.der";
  7725. #else
  7726. static const char *certRSAname = "certs/rsa2048.der";
  7727. #endif
  7728. #endif
  7729. #define RSA_BUF_SIZE 384 /* for up to 3072 bit */
  7730. #if defined(WOLFSSL_RSA_VERIFY_INLINE) || defined(WOLFSSL_RSA_PUBLIC_ONLY)
  7731. #if defined(USE_CERT_BUFFERS_2048)
  7732. static const unsigned char rsa_2048_sig[] = {
  7733. 0x8c, 0x9e, 0x37, 0xbf, 0xc3, 0xa6, 0xba, 0x1c,
  7734. 0x53, 0x22, 0x40, 0x4b, 0x8b, 0x0d, 0x3c, 0x0e,
  7735. 0x2e, 0x8c, 0x31, 0x2c, 0x47, 0xbf, 0x03, 0x48,
  7736. 0x18, 0x46, 0x73, 0x8d, 0xd7, 0xdd, 0x17, 0x64,
  7737. 0x0d, 0x7f, 0xdc, 0x74, 0xed, 0x80, 0xc3, 0xe8,
  7738. 0x9a, 0x18, 0x33, 0xd4, 0xe6, 0xc5, 0xe1, 0x54,
  7739. 0x75, 0xd1, 0xbb, 0x40, 0xde, 0xa8, 0xb9, 0x1b,
  7740. 0x14, 0xe8, 0xc1, 0x39, 0xeb, 0xa0, 0x69, 0x8a,
  7741. 0xc6, 0x9b, 0xef, 0x53, 0xb5, 0x23, 0x2b, 0x78,
  7742. 0x06, 0x43, 0x37, 0x11, 0x81, 0x84, 0x73, 0x33,
  7743. 0x33, 0xfe, 0xf7, 0x5d, 0x2b, 0x84, 0xd6, 0x83,
  7744. 0xd6, 0xdd, 0x55, 0x33, 0xef, 0xd1, 0xf7, 0x12,
  7745. 0xb0, 0xc2, 0x0e, 0xb1, 0x78, 0xd4, 0xa8, 0xa3,
  7746. 0x25, 0xeb, 0xed, 0x9a, 0xb3, 0xee, 0xc3, 0x7e,
  7747. 0xce, 0x13, 0x18, 0x86, 0x31, 0xe1, 0xef, 0x01,
  7748. 0x0f, 0x6e, 0x67, 0x24, 0x74, 0xbd, 0x0b, 0x7f,
  7749. 0xa9, 0xca, 0x6f, 0xaa, 0x83, 0x28, 0x90, 0x40,
  7750. 0xf1, 0xb5, 0x10, 0x0e, 0x26, 0x03, 0x05, 0x5d,
  7751. 0x87, 0xb4, 0xe0, 0x4c, 0x98, 0xd8, 0xc6, 0x42,
  7752. 0x89, 0x77, 0xeb, 0xb6, 0xd4, 0xe6, 0x26, 0xf3,
  7753. 0x31, 0x25, 0xde, 0x28, 0x38, 0x58, 0xe8, 0x2c,
  7754. 0xf4, 0x56, 0x7c, 0xb6, 0xfd, 0x99, 0xb0, 0xb0,
  7755. 0xf4, 0x83, 0xb6, 0x74, 0xa9, 0x5b, 0x9f, 0xe8,
  7756. 0xe9, 0xf1, 0xa1, 0x2a, 0xbd, 0xf6, 0x83, 0x28,
  7757. 0x09, 0xda, 0xa6, 0xd6, 0xcd, 0x61, 0x60, 0xf7,
  7758. 0x13, 0x4e, 0x46, 0x57, 0x38, 0x1e, 0x11, 0x92,
  7759. 0x6b, 0x6b, 0xcf, 0xd3, 0xf4, 0x8b, 0x66, 0x03,
  7760. 0x25, 0xa3, 0x7a, 0x2f, 0xce, 0xc1, 0x85, 0xa5,
  7761. 0x48, 0x91, 0x8a, 0xb3, 0x4f, 0x5d, 0x98, 0xb1,
  7762. 0x69, 0x58, 0x47, 0x69, 0x0c, 0x52, 0xdc, 0x42,
  7763. 0x4c, 0xef, 0xe8, 0xd4, 0x4d, 0x6a, 0x33, 0x7d,
  7764. 0x9e, 0xd2, 0x51, 0xe6, 0x41, 0xbf, 0x4f, 0xa2
  7765. };
  7766. #elif defined(USE_CERT_BUFFERS_3072)
  7767. static const unsigned char rsa_3072_sig[] = {
  7768. 0x1a, 0xd6, 0x0d, 0xfd, 0xe3, 0x41, 0x95, 0x76,
  7769. 0x27, 0x16, 0x7d, 0xc7, 0x94, 0x16, 0xca, 0xa8,
  7770. 0x26, 0x08, 0xbe, 0x78, 0x87, 0x72, 0x4c, 0xd9,
  7771. 0xa7, 0xfc, 0x33, 0x77, 0x2d, 0x53, 0x07, 0xb5,
  7772. 0x8c, 0xce, 0x48, 0x17, 0x9b, 0xff, 0x9f, 0x9b,
  7773. 0x17, 0xc4, 0xbb, 0x72, 0xed, 0xdb, 0xa0, 0x34,
  7774. 0x69, 0x5b, 0xc7, 0x4e, 0xbf, 0xec, 0x13, 0xc5,
  7775. 0x98, 0x71, 0x9a, 0x4e, 0x18, 0x0e, 0xcb, 0xe7,
  7776. 0xc6, 0xd5, 0x21, 0x31, 0x7c, 0x0d, 0xae, 0x14,
  7777. 0x2b, 0x87, 0x4f, 0x77, 0x95, 0x2e, 0x26, 0xe2,
  7778. 0x83, 0xfe, 0x49, 0x1e, 0x87, 0x19, 0x4a, 0x63,
  7779. 0x73, 0x75, 0xf1, 0xf5, 0x71, 0xd2, 0xce, 0xd4,
  7780. 0x39, 0x2b, 0xd9, 0xe0, 0x76, 0x70, 0xc8, 0xf8,
  7781. 0xed, 0xdf, 0x90, 0x57, 0x17, 0xb9, 0x16, 0xf6,
  7782. 0xe9, 0x49, 0x48, 0xce, 0x5a, 0x8b, 0xe4, 0x84,
  7783. 0x7c, 0xf3, 0x31, 0x68, 0x97, 0x45, 0x68, 0x38,
  7784. 0x50, 0x3a, 0x70, 0xbd, 0xb3, 0xd3, 0xd2, 0xe0,
  7785. 0x56, 0x5b, 0xc2, 0x0c, 0x2c, 0x10, 0x70, 0x7b,
  7786. 0xd4, 0x99, 0xf9, 0x38, 0x31, 0xb1, 0x86, 0xa0,
  7787. 0x07, 0xf1, 0xf6, 0x53, 0xb0, 0x44, 0x82, 0x40,
  7788. 0xd2, 0xab, 0x0e, 0x71, 0x5d, 0xe1, 0xea, 0x3a,
  7789. 0x77, 0xc9, 0xef, 0xfe, 0x54, 0x65, 0xa3, 0x49,
  7790. 0xfd, 0xa5, 0x33, 0xaa, 0x16, 0x1a, 0x38, 0xe7,
  7791. 0xaa, 0xb7, 0x13, 0xb2, 0x3b, 0xc7, 0x00, 0x87,
  7792. 0x12, 0xfe, 0xfd, 0xf4, 0x55, 0x6d, 0x1d, 0x4a,
  7793. 0x0e, 0xad, 0xd0, 0x4c, 0x55, 0x91, 0x60, 0xd9,
  7794. 0xef, 0x74, 0x69, 0x22, 0x8c, 0x51, 0x65, 0xc2,
  7795. 0x04, 0xac, 0xd3, 0x8d, 0xf7, 0x35, 0x29, 0x13,
  7796. 0x6d, 0x61, 0x7c, 0x39, 0x2f, 0x41, 0x4c, 0xdf,
  7797. 0x38, 0xfd, 0x1a, 0x7d, 0x42, 0xa7, 0x6f, 0x3f,
  7798. 0x3d, 0x9b, 0xd1, 0x97, 0xab, 0xc0, 0xa7, 0x28,
  7799. 0x1c, 0xc0, 0x02, 0x26, 0xeb, 0xce, 0xf9, 0xe1,
  7800. 0x34, 0x45, 0xaf, 0xbf, 0x8d, 0xb8, 0xe0, 0xff,
  7801. 0xd9, 0x6f, 0x77, 0xf3, 0xf7, 0xed, 0x6a, 0xbb,
  7802. 0x03, 0x52, 0xfb, 0x38, 0xfc, 0xea, 0x9f, 0xc9,
  7803. 0x98, 0xed, 0x21, 0x45, 0xaf, 0x43, 0x2b, 0x64,
  7804. 0x96, 0x82, 0x30, 0xe9, 0xb4, 0x36, 0x89, 0x77,
  7805. 0x07, 0x4a, 0xc6, 0x1f, 0x38, 0x7a, 0xee, 0xb6,
  7806. 0x86, 0xf6, 0x2f, 0x03, 0xec, 0xa2, 0xe5, 0x48,
  7807. 0xe5, 0x5a, 0xf5, 0x1c, 0xd2, 0xd9, 0xd8, 0x2d,
  7808. 0x9d, 0x06, 0x07, 0xc9, 0x8b, 0x5d, 0xe0, 0x0f,
  7809. 0x5e, 0x0c, 0x53, 0x27, 0xff, 0x23, 0xee, 0xca,
  7810. 0x5e, 0x4d, 0xf1, 0x95, 0x77, 0x78, 0x1f, 0xf2,
  7811. 0x44, 0x5b, 0x7d, 0x01, 0x49, 0x61, 0x6f, 0x6d,
  7812. 0xbf, 0xf5, 0x19, 0x06, 0x39, 0xe9, 0xe9, 0x29,
  7813. 0xde, 0x47, 0x5e, 0x2e, 0x1f, 0x68, 0xf4, 0x32,
  7814. 0x5e, 0xe9, 0xd0, 0xa7, 0xb4, 0x2a, 0x45, 0xdf,
  7815. 0x15, 0x7d, 0x0d, 0x5b, 0xef, 0xc6, 0x23, 0xac
  7816. };
  7817. #else
  7818. #error Not Supported Yet!
  7819. #endif
  7820. #endif /* WOLFSSL_RSA_VERIFY_INLINE || WOLFSSL_RSA_PUBLIC_ONLY */
  7821. static void bench_rsa_helper(int useDeviceID,
  7822. WC_ARRAY_ARG(rsaKey,
  7823. RsaKey,
  7824. BENCH_MAX_PENDING,
  7825. sizeof(RsaKey)),
  7826. word32 rsaKeySz)
  7827. {
  7828. int ret = 0, i, times, count = 0, pending = 0;
  7829. word32 idx = 0;
  7830. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7831. const char* messageStr = TEST_STRING;
  7832. const int len = (int)TEST_STRING_SZ;
  7833. #endif
  7834. double start = 0.0F;
  7835. const char**desc = bench_desc_words[lng_index];
  7836. DECLARE_MULTI_VALUE_STATS_VARS()
  7837. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7838. WC_DECLARE_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7839. #endif
  7840. WC_DECLARE_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7841. rsaKeySz, HEAP_HINT);
  7842. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7843. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7844. WC_DECLARE_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7845. rsaKeySz, HEAP_HINT);
  7846. #else
  7847. byte* out[BENCH_MAX_PENDING];
  7848. #endif
  7849. XMEMSET(out, 0, sizeof(out));
  7850. WC_ALLOC_HEAP_ARRAY(enc, byte, BENCH_MAX_PENDING,
  7851. rsaKeySz, HEAP_HINT);
  7852. #if (!defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  7853. !defined(WOLFSSL_RSA_PUBLIC_ONLY))
  7854. WC_ALLOC_HEAP_ARRAY(out, byte, BENCH_MAX_PENDING,
  7855. rsaKeySz, HEAP_HINT);
  7856. if (out[0] == NULL) {
  7857. ret = MEMORY_E;
  7858. goto exit;
  7859. }
  7860. #endif
  7861. if (enc[0] == NULL) {
  7862. ret = MEMORY_E;
  7863. goto exit;
  7864. }
  7865. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7866. WC_ALLOC_VAR(message, byte, TEST_STRING_SZ, HEAP_HINT);
  7867. XMEMCPY(message, messageStr, len);
  7868. #endif
  7869. if (!rsa_sign_verify) {
  7870. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  7871. /* begin public RSA */
  7872. bench_stats_start(&count, &start);
  7873. do {
  7874. for (times = 0; times < ntimes || pending > 0; ) {
  7875. bench_async_poll(&pending);
  7876. /* while free pending slots in queue, submit ops */
  7877. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7878. if (bench_async_check(&ret,
  7879. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7880. 1, &times, ntimes, &pending)) {
  7881. ret = wc_RsaPublicEncrypt(message, (word32)len, enc[i],
  7882. rsaKeySz/8, rsaKey[i],
  7883. GLOBAL_RNG);
  7884. if (!bench_async_handle(&ret,
  7885. BENCH_ASYNC_GET_DEV(
  7886. rsaKey[i]), 1, &times,
  7887. &pending)) {
  7888. goto exit_rsa_verify;
  7889. }
  7890. }
  7891. } /* for i */
  7892. RECORD_MULTI_VALUE_STATS();
  7893. } /* for times */
  7894. count += times;
  7895. } while (bench_stats_check(start)
  7896. #ifdef MULTI_VALUE_STATISTICS
  7897. || runs < minimum_runs
  7898. #endif
  7899. );
  7900. exit_rsa_verify:
  7901. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[0],
  7902. useDeviceID, count, start, ret);
  7903. #ifdef MULTI_VALUE_STATISTICS
  7904. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7905. #endif
  7906. #endif /* !WOLFSSL_RSA_VERIFY_ONLY */
  7907. #ifndef WOLFSSL_RSA_PUBLIC_ONLY
  7908. if (ret < 0) {
  7909. goto exit;
  7910. }
  7911. RESET_MULTI_VALUE_STATS_VARS();
  7912. /* capture resulting encrypt length */
  7913. idx = (word32)(rsaKeySz/8);
  7914. /* begin private async RSA */
  7915. bench_stats_start(&count, &start);
  7916. do {
  7917. for (times = 0; times < ntimes || pending > 0; ) {
  7918. bench_async_poll(&pending);
  7919. /* while free pending slots in queue, submit ops */
  7920. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7921. if (bench_async_check(&ret,
  7922. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7923. 1, &times, ntimes, &pending)) {
  7924. ret = wc_RsaPrivateDecrypt(enc[i], idx, out[i],
  7925. rsaKeySz/8, rsaKey[i]);
  7926. if (!bench_async_handle(&ret,
  7927. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7928. 1, &times, &pending)) {
  7929. goto exit_rsa_pub;
  7930. }
  7931. }
  7932. } /* for i */
  7933. RECORD_MULTI_VALUE_STATS();
  7934. } /* for times */
  7935. count += times;
  7936. } while (bench_stats_check(start)
  7937. #ifdef MULTI_VALUE_STATISTICS
  7938. || runs < minimum_runs
  7939. #endif
  7940. );
  7941. exit_rsa_pub:
  7942. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[1],
  7943. useDeviceID, count, start, ret);
  7944. #ifdef MULTI_VALUE_STATISTICS
  7945. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7946. #endif
  7947. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY */
  7948. }
  7949. else {
  7950. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  7951. /* begin RSA sign */
  7952. bench_stats_start(&count, &start);
  7953. do {
  7954. for (times = 0; times < ntimes || pending > 0; ) {
  7955. bench_async_poll(&pending);
  7956. /* while free pending slots in queue, submit ops */
  7957. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7958. if (bench_async_check(&ret,
  7959. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7960. 1, &times, ntimes, &pending)) {
  7961. ret = wc_RsaSSL_Sign(message, len, enc[i],
  7962. rsaKeySz/8, rsaKey[i], GLOBAL_RNG);
  7963. if (!bench_async_handle(&ret,
  7964. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  7965. 1, &times, &pending)) {
  7966. goto exit_rsa_sign;
  7967. }
  7968. }
  7969. } /* for i */
  7970. RECORD_MULTI_VALUE_STATS();
  7971. } /* for times */
  7972. count += times;
  7973. } while (bench_stats_check(start)
  7974. #ifdef MULTI_VALUE_STATISTICS
  7975. || runs < minimum_runs
  7976. #endif
  7977. );
  7978. exit_rsa_sign:
  7979. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[4], useDeviceID,
  7980. count, start, ret);
  7981. #ifdef MULTI_VALUE_STATISTICS
  7982. bench_multi_value_stats(max, min, sum, squareSum, runs);
  7983. #endif
  7984. if (ret < 0) {
  7985. goto exit;
  7986. }
  7987. RESET_MULTI_VALUE_STATS_VARS();
  7988. #endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
  7989. /* capture resulting encrypt length */
  7990. idx = rsaKeySz/8;
  7991. /* begin RSA verify */
  7992. bench_stats_start(&count, &start);
  7993. do {
  7994. for (times = 0; times < ntimes || pending > 0; ) {
  7995. bench_async_poll(&pending);
  7996. /* while free pending slots in queue, submit ops */
  7997. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  7998. if (bench_async_check(&ret,
  7999. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8000. 1, &times, ntimes, &pending)) {
  8001. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
  8002. !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8003. ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
  8004. rsaKeySz/8, rsaKey[i]);
  8005. #elif defined(USE_CERT_BUFFERS_2048)
  8006. XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
  8007. idx = sizeof(rsa_2048_sig);
  8008. out[i] = NULL;
  8009. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8010. &out[i], rsaKey[i]);
  8011. if (ret > 0) {
  8012. ret = 0;
  8013. }
  8014. #elif defined(USE_CERT_BUFFERS_3072)
  8015. XMEMCPY(enc[i], rsa_3072_sig, sizeof(rsa_3072_sig));
  8016. idx = sizeof(rsa_3072_sig);
  8017. out[i] = NULL;
  8018. ret = wc_RsaSSL_VerifyInline(enc[i], idx,
  8019. &out[i], rsaKey[i]);
  8020. if (ret > 0)
  8021. ret = 0;
  8022. #endif
  8023. if (!bench_async_handle(&ret,
  8024. BENCH_ASYNC_GET_DEV(rsaKey[i]),
  8025. 1, &times, &pending)) {
  8026. goto exit_rsa_verifyinline;
  8027. }
  8028. }
  8029. } /* for i */
  8030. RECORD_MULTI_VALUE_STATS();
  8031. } /* for times */
  8032. count += times;
  8033. } while (bench_stats_check(start)
  8034. #ifdef MULTI_VALUE_STATISTICS
  8035. || runs < minimum_runs
  8036. #endif
  8037. );
  8038. exit_rsa_verifyinline:
  8039. bench_stats_asym_finish("RSA", (int)rsaKeySz, desc[5],
  8040. useDeviceID, count, start, ret);
  8041. #ifdef MULTI_VALUE_STATISTICS
  8042. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8043. #endif
  8044. }
  8045. exit:
  8046. WC_FREE_HEAP_ARRAY(enc, BENCH_MAX_PENDING, HEAP_HINT);
  8047. #if !defined(WOLFSSL_RSA_VERIFY_INLINE) && !defined(WOLFSSL_RSA_PUBLIC_ONLY)
  8048. WC_FREE_HEAP_ARRAY(out, BENCH_MAX_PENDING, HEAP_HINT);
  8049. #endif
  8050. #ifndef WOLFSSL_RSA_VERIFY_ONLY
  8051. WC_FREE_VAR(message, HEAP_HINT);
  8052. #endif
  8053. }
  8054. void bench_rsa(int useDeviceID)
  8055. {
  8056. int i;
  8057. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8058. sizeof(RsaKey), HEAP_HINT);
  8059. int ret = 0;
  8060. word32 rsaKeySz = 0;
  8061. const byte* tmp;
  8062. size_t bytes;
  8063. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8064. word32 idx;
  8065. #endif
  8066. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8067. sizeof(RsaKey), HEAP_HINT);
  8068. #ifdef USE_CERT_BUFFERS_1024
  8069. tmp = rsa_key_der_1024;
  8070. bytes = (size_t)sizeof_rsa_key_der_1024;
  8071. rsaKeySz = 1024;
  8072. #elif defined(USE_CERT_BUFFERS_2048)
  8073. tmp = rsa_key_der_2048;
  8074. bytes = (size_t)sizeof_rsa_key_der_2048;
  8075. rsaKeySz = 2048;
  8076. #elif defined(USE_CERT_BUFFERS_3072)
  8077. tmp = rsa_key_der_3072;
  8078. bytes = (size_t)sizeof_rsa_key_der_3072;
  8079. rsaKeySz = 3072;
  8080. #elif defined(USE_CERT_BUFFERS_4096)
  8081. tmp = client_key_der_4096;
  8082. bytes = (size_t)sizeof_client_key_der_4096;
  8083. rsaKeySz = 4096;
  8084. #else
  8085. #error "need a cert buffer size"
  8086. #endif /* USE_CERT_BUFFERS */
  8087. /* init keys */
  8088. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8089. /* setup an async context for each key */
  8090. ret = wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8091. useDeviceID ? devId : INVALID_DEVID);
  8092. if (ret < 0) {
  8093. goto exit;
  8094. }
  8095. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8096. #ifdef WC_RSA_BLINDING
  8097. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8098. if (ret != 0)
  8099. goto exit;
  8100. #endif
  8101. #endif
  8102. #if !defined(WOLFSSL_RSA_PUBLIC_ONLY) && !defined(WOLFSSL_RSA_VERIFY_ONLY)
  8103. /* decode the private key */
  8104. idx = 0;
  8105. if ((ret = wc_RsaPrivateKeyDecode(tmp, &idx,
  8106. rsaKey[i], (word32)bytes)) != 0) {
  8107. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8108. goto exit;
  8109. }
  8110. #elif defined(WOLFSSL_PUBLIC_MP)
  8111. /* get offset to public portion of the RSA key */
  8112. #ifdef USE_CERT_BUFFERS_1024
  8113. bytes = 11;
  8114. #elif defined(USE_CERT_BUFFERS_2048) || defined(USE_CERT_BUFFERS_3072)
  8115. bytes = 12;
  8116. #endif
  8117. ret = mp_read_unsigned_bin(&rsaKey[i]->n, &tmp[bytes], rsaKeySz/8);
  8118. if (ret != 0) {
  8119. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8120. goto exit;
  8121. }
  8122. ret = mp_set_int(&rsaKey[i]->e, WC_RSA_EXPONENT);
  8123. if (ret != 0) {
  8124. printf("wc_RsaPrivateKeyDecode failed! %d\n", ret);
  8125. goto exit;
  8126. }
  8127. #else
  8128. /* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
  8129. rsaKeySz = 0;
  8130. #endif
  8131. }
  8132. if (rsaKeySz > 0) {
  8133. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8134. }
  8135. (void)bytes;
  8136. (void)tmp;
  8137. exit:
  8138. /* cleanup */
  8139. if (WC_ARRAY_OK(rsaKey)) {
  8140. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8141. wc_FreeRsaKey(rsaKey[i]);
  8142. }
  8143. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8144. }
  8145. }
  8146. #ifdef WOLFSSL_KEY_GEN
  8147. /* bench any size of RSA key */
  8148. void bench_rsa_key(int useDeviceID, word32 rsaKeySz)
  8149. {
  8150. int ret = 0, i, pending = 0;
  8151. WC_DECLARE_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8152. sizeof(RsaKey), HEAP_HINT);
  8153. int isPending[BENCH_MAX_PENDING];
  8154. long exp = 65537L;
  8155. /* clear for done cleanup */
  8156. XMEMSET(isPending, 0, sizeof(isPending));
  8157. WC_CALLOC_ARRAY(rsaKey, RsaKey, BENCH_MAX_PENDING,
  8158. sizeof(RsaKey), HEAP_HINT);
  8159. /* init keys */
  8160. do {
  8161. pending = 0;
  8162. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8163. if (!isPending[i]) { /* if making the key is pending then just call
  8164. * wc_MakeRsaKey again */
  8165. /* setup an async context for each key */
  8166. if (wc_InitRsaKey_ex(rsaKey[i], HEAP_HINT,
  8167. useDeviceID ? devId : INVALID_DEVID) < 0) {
  8168. goto exit;
  8169. }
  8170. #ifdef WC_RSA_BLINDING
  8171. ret = wc_RsaSetRNG(rsaKey[i], &gRng);
  8172. if (ret != 0)
  8173. goto exit;
  8174. #endif
  8175. }
  8176. /* create the RSA key */
  8177. ret = wc_MakeRsaKey(rsaKey[i], (int)rsaKeySz, exp, &gRng);
  8178. if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
  8179. isPending[i] = 1;
  8180. pending = 1;
  8181. }
  8182. else if (ret != 0) {
  8183. printf("wc_MakeRsaKey failed! %d\n", ret);
  8184. goto exit;
  8185. }
  8186. } /* for i */
  8187. } while (pending > 0);
  8188. bench_rsa_helper(useDeviceID, rsaKey, rsaKeySz);
  8189. exit:
  8190. /* cleanup */
  8191. if (WC_ARRAY_OK(rsaKey)) {
  8192. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8193. wc_FreeRsaKey(rsaKey[i]);
  8194. }
  8195. WC_FREE_ARRAY(rsaKey, BENCH_MAX_PENDING, HEAP_HINT);
  8196. }
  8197. }
  8198. #endif /* WOLFSSL_KEY_GEN */
  8199. #endif /* !NO_RSA */
  8200. #ifndef NO_DH
  8201. #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
  8202. !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
  8203. #if defined(WOLFSSL_MDK_SHELL)
  8204. static char *certDHname = "certs/dh2048.der";
  8205. /* set by shell command */
  8206. void set_Bench_DH_File(char * cert) { certDHname = cert ; }
  8207. #elif defined(FREESCALE_MQX)
  8208. static char *certDHname = "a:\\certs\\dh2048.der";
  8209. #elif defined(NO_ASN)
  8210. /* do nothing, but don't need a file */
  8211. #else
  8212. static const char *certDHname = "certs/dh2048.der";
  8213. #endif
  8214. #endif
  8215. #ifdef HAVE_FFDHE_4096
  8216. #define BENCH_DH_KEY_SIZE 512 /* for 4096 bit */
  8217. #else
  8218. #define BENCH_DH_KEY_SIZE 384 /* for 3072 bit */
  8219. #endif
  8220. #define BENCH_DH_PRIV_SIZE (BENCH_DH_KEY_SIZE/8)
  8221. void bench_dh(int useDeviceID)
  8222. {
  8223. int ret = 0, i;
  8224. int count = 0, times, pending = 0;
  8225. const byte* tmp = NULL;
  8226. double start = 0.0F;
  8227. WC_DECLARE_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8228. sizeof(DhKey), HEAP_HINT);
  8229. int dhKeySz = BENCH_DH_KEY_SIZE * 8; /* used in printf */
  8230. const char**desc = bench_desc_words[lng_index];
  8231. #ifndef NO_ASN
  8232. size_t bytes = 0;
  8233. word32 idx;
  8234. #endif
  8235. word32 pubSz[BENCH_MAX_PENDING];
  8236. word32 privSz[BENCH_MAX_PENDING];
  8237. word32 pubSz2 = BENCH_DH_KEY_SIZE;
  8238. word32 privSz2 = BENCH_DH_PRIV_SIZE;
  8239. word32 agreeSz[BENCH_MAX_PENDING];
  8240. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072) || defined(HAVE_FFDHE_4096)
  8241. #ifdef HAVE_PUBLIC_FFDHE
  8242. const DhParams *params = NULL;
  8243. #else
  8244. int paramName = 0;
  8245. #endif
  8246. #endif
  8247. DECLARE_MULTI_VALUE_STATS_VARS()
  8248. WC_DECLARE_ARRAY(pub, byte, BENCH_MAX_PENDING,
  8249. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8250. WC_DECLARE_VAR(pub2, byte,
  8251. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8252. WC_DECLARE_ARRAY(agree, byte, BENCH_MAX_PENDING,
  8253. BENCH_DH_KEY_SIZE, HEAP_HINT);
  8254. WC_DECLARE_ARRAY(priv, byte, BENCH_MAX_PENDING,
  8255. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8256. WC_DECLARE_VAR(priv2, byte,
  8257. BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8258. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  8259. XMEMSET(pub, 0, sizeof(pub));
  8260. XMEMSET(agree, 0, sizeof(agree));
  8261. XMEMSET(priv, 0, sizeof(priv));
  8262. WC_CALLOC_ARRAY(dhKey, DhKey, BENCH_MAX_PENDING,
  8263. sizeof(DhKey), HEAP_HINT);
  8264. WC_ALLOC_ARRAY(pub, byte,
  8265. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8266. WC_ALLOC_ARRAY(agree, byte,
  8267. BENCH_MAX_PENDING, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8268. WC_ALLOC_ARRAY(priv, byte,
  8269. BENCH_MAX_PENDING, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8270. WC_ALLOC_VAR(pub2, byte, BENCH_DH_KEY_SIZE, HEAP_HINT);
  8271. WC_ALLOC_VAR(priv2, byte, BENCH_DH_PRIV_SIZE, HEAP_HINT);
  8272. (void)tmp;
  8273. if (!use_ffdhe) {
  8274. #if defined(NO_ASN)
  8275. dhKeySz = 1024;
  8276. /* do nothing, but don't use default FILE */
  8277. #elif defined(USE_CERT_BUFFERS_1024)
  8278. tmp = dh_key_der_1024;
  8279. bytes = (size_t)sizeof_dh_key_der_1024;
  8280. dhKeySz = 1024;
  8281. #elif defined(USE_CERT_BUFFERS_2048)
  8282. tmp = dh_key_der_2048;
  8283. bytes = (size_t)sizeof_dh_key_der_2048;
  8284. dhKeySz = 2048;
  8285. #elif defined(USE_CERT_BUFFERS_3072)
  8286. tmp = dh_key_der_3072;
  8287. bytes = (size_t)sizeof_dh_key_der_3072;
  8288. dhKeySz = 3072;
  8289. #elif defined(USE_CERT_BUFFERS_4096)
  8290. tmp = dh_key_der_4096;
  8291. bytes = (size_t)sizeof_dh_key_der_4096;
  8292. dhKeySz = 4096;
  8293. #else
  8294. #error "need to define a cert buffer size"
  8295. #endif /* USE_CERT_BUFFERS */
  8296. }
  8297. #ifdef HAVE_FFDHE_2048
  8298. else if (use_ffdhe == 2048) {
  8299. #ifdef HAVE_PUBLIC_FFDHE
  8300. params = wc_Dh_ffdhe2048_Get();
  8301. #else
  8302. paramName = WC_FFDHE_2048;
  8303. #endif
  8304. dhKeySz = 2048;
  8305. }
  8306. #endif
  8307. #ifdef HAVE_FFDHE_3072
  8308. else if (use_ffdhe == 3072) {
  8309. #ifdef HAVE_PUBLIC_FFDHE
  8310. params = wc_Dh_ffdhe3072_Get();
  8311. #else
  8312. paramName = WC_FFDHE_3072;
  8313. #endif
  8314. dhKeySz = 3072;
  8315. }
  8316. #endif
  8317. #ifdef HAVE_FFDHE_4096
  8318. else if (use_ffdhe == 4096) {
  8319. #ifdef HAVE_PUBLIC_FFDHE
  8320. params = wc_Dh_ffdhe4096_Get();
  8321. #else
  8322. paramName = WC_FFDHE_4096;
  8323. #endif
  8324. dhKeySz = 4096;
  8325. }
  8326. #endif
  8327. /* init keys */
  8328. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8329. /* setup an async context for each key */
  8330. ret = wc_InitDhKey_ex(dhKey[i], HEAP_HINT,
  8331. useDeviceID ? devId : INVALID_DEVID);
  8332. if (ret != 0)
  8333. goto exit;
  8334. /* setup key */
  8335. if (!use_ffdhe) {
  8336. #ifdef NO_ASN
  8337. ret = wc_DhSetKey(dhKey[i], dh_p,
  8338. sizeof(dh_p), dh_g, sizeof(dh_g));
  8339. #else
  8340. idx = 0;
  8341. ret = wc_DhKeyDecode(tmp, &idx, dhKey[i], (word32)bytes);
  8342. #endif
  8343. }
  8344. #if defined(HAVE_FFDHE_2048) || defined(HAVE_FFDHE_3072)
  8345. #ifdef HAVE_PUBLIC_FFDHE
  8346. else if (params != NULL) {
  8347. ret = wc_DhSetKey(dhKey[i], params->p, params->p_len,
  8348. params->g, params->g_len);
  8349. }
  8350. #else
  8351. else if (paramName != 0) {
  8352. ret = wc_DhSetNamedKey(dhKey[i], paramName);
  8353. }
  8354. #endif
  8355. #endif
  8356. if (ret != 0) {
  8357. printf("DhKeyDecode failed %d, can't benchmark\n", ret);
  8358. goto exit;
  8359. }
  8360. }
  8361. /* Key Gen */
  8362. bench_stats_start(&count, &start);
  8363. PRIVATE_KEY_UNLOCK();
  8364. do {
  8365. /* while free pending slots in queue, submit ops */
  8366. for (times = 0; times < genTimes || pending > 0; ) {
  8367. bench_async_poll(&pending);
  8368. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8369. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8370. 0, &times, genTimes, &pending)) {
  8371. privSz[i] = BENCH_DH_PRIV_SIZE;
  8372. pubSz[i] = BENCH_DH_KEY_SIZE;
  8373. ret = wc_DhGenerateKeyPair(dhKey[i], &gRng,
  8374. priv[i], &privSz[i],
  8375. pub[i], &pubSz[i]);
  8376. if (!bench_async_handle(&ret,
  8377. BENCH_ASYNC_GET_DEV(dhKey[i]),
  8378. 0, &times, &pending)) {
  8379. goto exit_dh_gen;
  8380. }
  8381. }
  8382. } /* for i */
  8383. RECORD_MULTI_VALUE_STATS();
  8384. } /* for times */
  8385. count += times;
  8386. } while (bench_stats_check(start)
  8387. #ifdef MULTI_VALUE_STATISTICS
  8388. || runs < minimum_runs
  8389. #endif
  8390. );
  8391. PRIVATE_KEY_LOCK();
  8392. exit_dh_gen:
  8393. bench_stats_asym_finish("DH", dhKeySz, desc[2],
  8394. useDeviceID, count, start, ret);
  8395. #ifdef MULTI_VALUE_STATISTICS
  8396. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8397. #endif
  8398. if (ret < 0) {
  8399. goto exit;
  8400. }
  8401. RESET_MULTI_VALUE_STATS_VARS();
  8402. /* Generate key to use as other public */
  8403. PRIVATE_KEY_UNLOCK();
  8404. ret = wc_DhGenerateKeyPair(dhKey[0], &gRng,
  8405. priv2, &privSz2, pub2, &pubSz2);
  8406. PRIVATE_KEY_LOCK();
  8407. #ifdef WOLFSSL_ASYNC_CRYPT
  8408. ret = wc_AsyncWait(ret, &dhKey[0]->asyncDev, WC_ASYNC_FLAG_NONE);
  8409. #endif
  8410. /* Key Agree */
  8411. bench_stats_start(&count, &start);
  8412. PRIVATE_KEY_UNLOCK();
  8413. do {
  8414. for (times = 0; times < agreeTimes || pending > 0; ) {
  8415. bench_async_poll(&pending);
  8416. /* while free pending slots in queue, submit ops */
  8417. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8418. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(dhKey[i]),
  8419. 0, &times, agreeTimes, &pending)) {
  8420. ret = wc_DhAgree(dhKey[i], agree[i], &agreeSz[i], priv[i],
  8421. privSz[i], pub2, pubSz2);
  8422. if (!bench_async_handle(&ret,
  8423. BENCH_ASYNC_GET_DEV(dhKey[i]), 0, &times, &pending)) {
  8424. goto exit;
  8425. }
  8426. }
  8427. } /* for i */
  8428. RECORD_MULTI_VALUE_STATS();
  8429. } /* for times */
  8430. count += times;
  8431. } while (bench_stats_check(start)
  8432. #ifdef MULTI_VALUE_STATISTICS
  8433. || runs < minimum_runs
  8434. #endif
  8435. );
  8436. PRIVATE_KEY_LOCK();
  8437. exit:
  8438. bench_stats_asym_finish("DH", dhKeySz, desc[3],
  8439. useDeviceID, count, start, ret);
  8440. #ifdef MULTI_VALUE_STATISTICS
  8441. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8442. #endif
  8443. /* cleanup */
  8444. if (WC_ARRAY_OK(dhKey)) {
  8445. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  8446. wc_FreeDhKey(dhKey[i]);
  8447. }
  8448. WC_FREE_ARRAY(dhKey, BENCH_MAX_PENDING, HEAP_HINT);
  8449. }
  8450. WC_FREE_ARRAY(pub, BENCH_MAX_PENDING, HEAP_HINT);
  8451. WC_FREE_VAR(pub2, HEAP_HINT);
  8452. WC_FREE_ARRAY(priv, BENCH_MAX_PENDING, HEAP_HINT);
  8453. WC_FREE_VAR(priv2, HEAP_HINT);
  8454. WC_FREE_ARRAY(agree, BENCH_MAX_PENDING, HEAP_HINT);
  8455. }
  8456. #endif /* !NO_DH */
  8457. #ifdef WOLFSSL_HAVE_KYBER
  8458. static void bench_kyber_keygen(int type, const char* name, int keySize,
  8459. KyberKey* key)
  8460. {
  8461. int ret = 0, times, count, pending = 0;
  8462. double start;
  8463. const char**desc = bench_desc_words[lng_index];
  8464. DECLARE_MULTI_VALUE_STATS_VARS()
  8465. /* KYBER Make Key */
  8466. bench_stats_start(&count, &start);
  8467. do {
  8468. /* while free pending slots in queue, submit ops */
  8469. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8470. wc_KyberKey_Free(key);
  8471. ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
  8472. if (ret != 0)
  8473. goto exit;
  8474. #ifdef KYBER_NONDETERMINISTIC
  8475. ret = wc_KyberKey_MakeKey(key, &gRng);
  8476. #else
  8477. unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
  8478. ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
  8479. #endif
  8480. if (ret != 0)
  8481. goto exit;
  8482. RECORD_MULTI_VALUE_STATS();
  8483. } /* for times */
  8484. count += times;
  8485. } while (bench_stats_check(start)
  8486. #ifdef MULTI_VALUE_STATISTICS
  8487. || runs < minimum_runs
  8488. #endif
  8489. );
  8490. exit:
  8491. bench_stats_asym_finish(name, keySize, desc[2], 0, count, start, ret);
  8492. #ifdef MULTI_VALUE_STATISTICS
  8493. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8494. #endif
  8495. }
  8496. static void bench_kyber_encap(const char* name, int keySize, KyberKey* key)
  8497. {
  8498. int ret = 0, times, count, pending = 0;
  8499. double start;
  8500. const char**desc = bench_desc_words[lng_index];
  8501. byte ct[KYBER_MAX_CIPHER_TEXT_SIZE];
  8502. byte ss[KYBER_SS_SZ];
  8503. word32 ctSz;
  8504. DECLARE_MULTI_VALUE_STATS_VARS()
  8505. ret = wc_KyberKey_CipherTextSize(key, &ctSz);
  8506. if (ret != 0) {
  8507. return;
  8508. }
  8509. /* KYBER Encapsulate */
  8510. bench_stats_start(&count, &start);
  8511. do {
  8512. /* while free pending slots in queue, submit ops */
  8513. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8514. #ifdef KYBER_NONDETERMINISTIC
  8515. ret = wc_KyberKey_Encapsulate(key, ct, ss, &gRng);
  8516. #else
  8517. unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
  8518. ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
  8519. sizeof(rand));
  8520. #endif
  8521. if (ret != 0)
  8522. goto exit_encap;
  8523. RECORD_MULTI_VALUE_STATS();
  8524. } /* for times */
  8525. count += times;
  8526. } while (bench_stats_check(start)
  8527. #ifdef MULTI_VALUE_STATISTICS
  8528. || runs < minimum_runs
  8529. #endif
  8530. );
  8531. exit_encap:
  8532. bench_stats_asym_finish(name, keySize, desc[9], 0, count, start, ret);
  8533. #ifdef MULTI_VALUE_STATISTICS
  8534. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8535. #endif
  8536. RESET_MULTI_VALUE_STATS_VARS();
  8537. /* KYBER Decapsulate */
  8538. bench_stats_start(&count, &start);
  8539. do {
  8540. /* while free pending slots in queue, submit ops */
  8541. for (times = 0; times < agreeTimes || pending > 0; times++) {
  8542. ret = wc_KyberKey_Decapsulate(key, ss, ct, ctSz);
  8543. if (ret != 0)
  8544. goto exit_decap;
  8545. RECORD_MULTI_VALUE_STATS();
  8546. } /* for times */
  8547. count += times;
  8548. } while (bench_stats_check(start)
  8549. #ifdef MULTI_VALUE_STATISTICS
  8550. || runs < minimum_runs
  8551. #endif
  8552. );
  8553. exit_decap:
  8554. bench_stats_asym_finish(name, keySize, desc[13], 0, count, start, ret);
  8555. #ifdef MULTI_VALUE_STATISTICS
  8556. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8557. #endif
  8558. }
  8559. void bench_kyber(int type)
  8560. {
  8561. KyberKey key;
  8562. const char* name = NULL;
  8563. int keySize = 0;
  8564. switch (type) {
  8565. #ifndef WOLFSSL_NO_ML_KEM
  8566. #ifdef WOLFSSL_WC_ML_KEM_512
  8567. case WC_ML_KEM_512:
  8568. name = "ML-KEM 512 ";
  8569. keySize = 128;
  8570. break;
  8571. #endif
  8572. #ifdef WOLFSSL_WC_ML_KEM_768
  8573. case WC_ML_KEM_768:
  8574. name = "ML-KEM 768 ";
  8575. keySize = 192;
  8576. break;
  8577. #endif
  8578. #ifdef WOLFSSL_WC_ML_KEM_1024
  8579. case WC_ML_KEM_1024:
  8580. name = "ML-KEM 1024 ";
  8581. keySize = 256;
  8582. break;
  8583. #endif
  8584. #endif
  8585. #ifdef WOLFSSL_KYBER_ORIGINAL
  8586. #ifdef WOLFSSL_KYBER512
  8587. case KYBER512:
  8588. name = "KYBER512 ";
  8589. keySize = 128;
  8590. break;
  8591. #endif
  8592. #ifdef WOLFSSL_KYBER768
  8593. case KYBER768:
  8594. name = "KYBER768 ";
  8595. keySize = 192;
  8596. break;
  8597. #endif
  8598. #ifdef WOLFSSL_KYBER1024
  8599. case KYBER1024:
  8600. name = "KYBER1024";
  8601. keySize = 256;
  8602. break;
  8603. #endif
  8604. #endif
  8605. }
  8606. bench_kyber_keygen(type, name, keySize, &key);
  8607. bench_kyber_encap(name, keySize, &key);
  8608. wc_KyberKey_Free(&key);
  8609. }
  8610. #endif
  8611. #if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY)
  8612. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8613. /* WC_LMS_PARM_L2_H10_W2
  8614. * signature length: 9300 */
  8615. static const byte lms_priv_L2_H10_W2[64] =
  8616. {
  8617. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8618. 0x62,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8619. 0xC7,0x74,0x25,0x5B,0x2C,0xE8,0xDA,0x53,
  8620. 0xF0,0x7C,0x04,0x3F,0x64,0x2D,0x26,0x2C,
  8621. 0x46,0x1D,0xC8,0x90,0x77,0x59,0xD6,0xC0,
  8622. 0x56,0x46,0x7D,0x97,0x64,0xF2,0xA3,0xA1,
  8623. 0xF8,0xD0,0x3B,0x5F,0xAC,0x40,0xB9,0x9E,
  8624. 0x83,0x67,0xBF,0x92,0x8D,0xFE,0x45,0x79
  8625. };
  8626. static const byte lms_pub_L2_H10_W2[60] =
  8627. {
  8628. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8629. 0x00,0x00,0x00,0x02,0xF8,0xD0,0x3B,0x5F,
  8630. 0xAC,0x40,0xB9,0x9E,0x83,0x67,0xBF,0x92,
  8631. 0x8D,0xFE,0x45,0x79,0x41,0xBC,0x2A,0x3B,
  8632. 0x9F,0xC0,0x11,0x12,0x93,0xF0,0x5A,0xA5,
  8633. 0xC1,0x88,0x29,0x79,0x6C,0x3E,0x0A,0x0F,
  8634. 0xEC,0x3B,0x3E,0xE4,0x38,0xD3,0xD2,0x34,
  8635. 0x7F,0xC8,0x91,0xB0
  8636. };
  8637. /* WC_LMS_PARM_L2_H10_W4
  8638. * signature length: 5076 */
  8639. static const byte lms_priv_L2_H10_W4[64] =
  8640. {
  8641. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8642. 0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  8643. 0xAE,0x28,0x87,0x19,0x4F,0x4B,0x68,0x61,
  8644. 0x93,0x9A,0xC7,0x0E,0x33,0xB8,0xCE,0x96,
  8645. 0x66,0x0D,0xC7,0xB1,0xFA,0x94,0x80,0xA2,
  8646. 0x28,0x9B,0xCF,0xE2,0x08,0xB5,0x25,0xAC,
  8647. 0xFB,0xB8,0x65,0x5E,0xD1,0xCC,0x31,0xDA,
  8648. 0x2E,0x49,0x3A,0xEE,0xAF,0x63,0x70,0x5E
  8649. };
  8650. static const byte lms_pub_L2_H10_W4[60] =
  8651. {
  8652. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x06,
  8653. 0x00,0x00,0x00,0x03,0xFB,0xB8,0x65,0x5E,
  8654. 0xD1,0xCC,0x31,0xDA,0x2E,0x49,0x3A,0xEE,
  8655. 0xAF,0x63,0x70,0x5E,0xA2,0xD5,0xB6,0x15,
  8656. 0x33,0x8C,0x9B,0xE9,0xE1,0x91,0x40,0x1A,
  8657. 0x12,0xE0,0xD7,0xBD,0xE4,0xE0,0x76,0xF5,
  8658. 0x04,0x90,0x76,0xA5,0x9A,0xA7,0x4E,0xFE,
  8659. 0x6B,0x9A,0xD3,0x14
  8660. };
  8661. /* WC_LMS_PARM_L3_H5_W4
  8662. * signature length: 7160 */
  8663. static const byte lms_priv_L3_H5_W4[64] =
  8664. {
  8665. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8666. 0x53,0x53,0x53,0xFF,0xFF,0xFF,0xFF,0xFF,
  8667. 0x38,0xD1,0xBE,0x68,0xD1,0x93,0xE1,0x14,
  8668. 0x6C,0x8B,0xED,0xE2,0x25,0x88,0xED,0xAC,
  8669. 0x57,0xBD,0x87,0x9F,0x54,0xF3,0x58,0xD9,
  8670. 0x4D,0xF5,0x6A,0xBD,0x71,0x99,0x6A,0x28,
  8671. 0x2F,0xE1,0xFC,0xD1,0xD1,0x0C,0x7C,0xF8,
  8672. 0xB4,0xDC,0xDF,0x7F,0x14,0x1A,0x7B,0x50
  8673. };
  8674. static const byte lms_pub_L3_H5_W4[60] =
  8675. {
  8676. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8677. 0x00,0x00,0x00,0x03,0x2F,0xE1,0xFC,0xD1,
  8678. 0xD1,0x0C,0x7C,0xF8,0xB4,0xDC,0xDF,0x7F,
  8679. 0x14,0x1A,0x7B,0x50,0x8E,0x3A,0xD4,0x05,
  8680. 0x0C,0x95,0x59,0xA0,0xCA,0x7A,0xD8,0xD6,
  8681. 0x5D,0xBD,0x42,0xBB,0xD5,0x82,0xB8,0x9C,
  8682. 0x52,0x37,0xB7,0x45,0x03,0xC2,0x06,0xCE,
  8683. 0xAB,0x4B,0x51,0x39
  8684. };
  8685. /* WC_LMS_PARM_L3_H5_W8
  8686. * signature length: 3992 */
  8687. static const byte lms_priv_L3_H5_W8[64] =
  8688. {
  8689. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8690. 0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,0xFF,
  8691. 0xA5,0x46,0x97,0x0C,0xA1,0x3C,0xEA,0x17,
  8692. 0x5C,0x9D,0x59,0xF4,0x0E,0x27,0x37,0xF3,
  8693. 0x6A,0x1C,0xF7,0x29,0x4A,0xCC,0xCD,0x7B,
  8694. 0x4F,0xE7,0x37,0x6E,0xEF,0xC1,0xBD,0xBD,
  8695. 0x04,0x5D,0x8E,0xDD,0xAA,0x47,0xCC,0xE6,
  8696. 0xCE,0x78,0x46,0x20,0x41,0x87,0xE0,0x85
  8697. };
  8698. static const byte lms_pub_L3_H5_W8[60] =
  8699. {
  8700. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x05,
  8701. 0x00,0x00,0x00,0x04,0x04,0x5D,0x8E,0xDD,
  8702. 0xAA,0x47,0xCC,0xE6,0xCE,0x78,0x46,0x20,
  8703. 0x41,0x87,0xE0,0x85,0x0D,0x2C,0x46,0xB9,
  8704. 0x39,0x8C,0xA3,0x92,0x4F,0xCE,0x50,0x96,
  8705. 0x90,0x9C,0xF3,0x36,0x2E,0x09,0x15,0x3B,
  8706. 0x4B,0x34,0x17,0xE7,0xE2,0x55,0xFC,0x5B,
  8707. 0x83,0xAB,0x43,0xAF
  8708. };
  8709. /* WC_LMS_PARM_L3_H10_W4
  8710. * signature length: 7640 */
  8711. static const byte lms_priv_L3_H10_W4[64] =
  8712. {
  8713. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8714. 0x63,0x63,0x63,0xFF,0xFF,0xFF,0xFF,0xFF,
  8715. 0xDF,0x98,0xAB,0xEC,0xFE,0x13,0x9F,0xF8,
  8716. 0xD7,0x2B,0x4F,0x4C,0x79,0x34,0xB8,0x89,
  8717. 0x24,0x6B,0x26,0x7D,0x7A,0x2E,0xA2,0xCB,
  8718. 0x82,0x75,0x4E,0x96,0x54,0x49,0xED,0xA0,
  8719. 0xAF,0xC7,0xA5,0xEE,0x8A,0xA2,0x83,0x99,
  8720. 0x4B,0x18,0x59,0x2B,0x66,0xC0,0x32,0xDB
  8721. };
  8722. static const byte lms_pub_L3_H10_W4[60] =
  8723. {
  8724. 0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x06,
  8725. 0x00,0x00,0x00,0x03,0xAF,0xC7,0xA5,0xEE,
  8726. 0x8A,0xA2,0x83,0x99,0x4B,0x18,0x59,0x2B,
  8727. 0x66,0xC0,0x32,0xDB,0xC4,0x18,0xEB,0x11,
  8728. 0x17,0x7D,0xAA,0x93,0xFD,0xA0,0x70,0x4D,
  8729. 0x68,0x4B,0x63,0x8F,0xC2,0xE7,0xCA,0x34,
  8730. 0x14,0x31,0x0D,0xAA,0x18,0xBF,0x9B,0x32,
  8731. 0x8D,0x78,0xD5,0xA8
  8732. };
  8733. /* WC_LMS_PARM_L4_H5_W8
  8734. * signature length: 5340 */
  8735. static const byte lms_priv_L4_H5_W8[64] =
  8736. {
  8737. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  8738. 0x54,0x54,0x54,0x54,0xFF,0xFF,0xFF,0xFF,
  8739. 0x46,0x8F,0x2A,0x4A,0x14,0x26,0xF0,0x89,
  8740. 0xFE,0xED,0x66,0x0F,0x73,0x69,0xB1,0x4C,
  8741. 0x47,0xA1,0x35,0x9F,0x7B,0xBA,0x08,0x03,
  8742. 0xEE,0xA2,0xEB,0xAD,0xB4,0x82,0x52,0x1F,
  8743. 0xFD,0x9B,0x22,0x82,0x42,0x1A,0x96,0x1E,
  8744. 0xE4,0xA1,0x9C,0x33,0xED,0xE6,0x9F,0xAB
  8745. };
  8746. static const byte lms_pub_L4_H5_W8[60] =
  8747. {
  8748. 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x05,
  8749. 0x00,0x00,0x00,0x04,0xFD,0x9B,0x22,0x82,
  8750. 0x42,0x1A,0x96,0x1E,0xE4,0xA1,0x9C,0x33,
  8751. 0xED,0xE6,0x9F,0xAB,0x6B,0x47,0x05,0x5B,
  8752. 0xA7,0xAD,0xF6,0x88,0xA5,0x4F,0xCD,0xF1,
  8753. 0xDA,0x29,0x67,0xC3,0x7F,0x2C,0x11,0xFE,
  8754. 0x85,0x1A,0x7A,0xD8,0xD5,0x46,0x74,0x3B,
  8755. 0x74,0x24,0x12,0xC8
  8756. };
  8757. #endif
  8758. static int lms_write_key_mem(const byte* priv, word32 privSz, void* context)
  8759. {
  8760. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  8761. * BE USED FOR TESTING PURPOSES! Production applications should
  8762. * write only to non-volatile storage. */
  8763. XMEMCPY(context, priv, privSz);
  8764. return WC_LMS_RC_SAVED_TO_NV_MEMORY;
  8765. }
  8766. static int lms_read_key_mem(byte* priv, word32 privSz, void* context)
  8767. {
  8768. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  8769. * BE USED FOR TESTING PURPOSES! */
  8770. XMEMCPY(priv, context, privSz);
  8771. return WC_LMS_RC_READ_TO_MEMORY;
  8772. }
  8773. static byte lms_priv[HSS_MAX_PRIVATE_KEY_LEN];
  8774. static void bench_lms_keygen(enum wc_LmsParm parm, byte* pub)
  8775. {
  8776. WC_RNG rng;
  8777. LmsKey key;
  8778. int ret;
  8779. word32 pubLen = HSS_MAX_PUBLIC_KEY_LEN;
  8780. int times = 0;
  8781. int count = 0;
  8782. double start = 0.0F;
  8783. int levels;
  8784. int height;
  8785. int winternitz;
  8786. const char* str = wc_LmsKey_ParmToStr(parm);
  8787. DECLARE_MULTI_VALUE_STATS_VARS()
  8788. #ifndef HAVE_FIPS
  8789. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  8790. #else
  8791. ret = wc_InitRng(&rng);
  8792. #endif
  8793. if (ret != 0) {
  8794. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  8795. return;
  8796. }
  8797. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8798. if (ret) {
  8799. printf("wc_LmsKey_Init failed: %d\n", ret);
  8800. wc_FreeRng(&rng);
  8801. return;
  8802. }
  8803. count = 0;
  8804. bench_stats_start(&count, &start);
  8805. do {
  8806. /* LMS is stateful. Async queuing not practical. */
  8807. for (times = 0; times < 1; ++times) {
  8808. wc_LmsKey_Free(&key);
  8809. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8810. if (ret) {
  8811. printf("wc_LmsKey_Init failed: %d\n", ret);
  8812. goto exit_lms_keygen;
  8813. }
  8814. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8815. if (ret) {
  8816. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8817. goto exit_lms_keygen;
  8818. }
  8819. ret = wc_LmsKey_GetParameters(&key, &levels, &height, &winternitz);
  8820. if (ret) {
  8821. fprintf(stderr, "error: wc_LmsKey_GetParameters failed: %d\n",
  8822. ret);
  8823. goto exit_lms_keygen;
  8824. }
  8825. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8826. if (ret) {
  8827. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n",
  8828. ret);
  8829. goto exit_lms_keygen;
  8830. }
  8831. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8832. if (ret) {
  8833. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8834. goto exit_lms_keygen;
  8835. }
  8836. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8837. if (ret) {
  8838. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n",
  8839. ret);
  8840. goto exit_lms_keygen;
  8841. }
  8842. ret = wc_LmsKey_MakeKey(&key, &rng);
  8843. if (ret) {
  8844. printf("wc_LmsKey_MakeKey failed: %d\n", ret);
  8845. goto exit_lms_keygen;
  8846. }
  8847. RECORD_MULTI_VALUE_STATS();
  8848. }
  8849. count += times;
  8850. } while (bench_stats_check(start)
  8851. #ifdef MULTI_VALUE_STATISTICS
  8852. || runs < minimum_runs
  8853. #endif
  8854. );
  8855. bench_stats_asym_finish(str, levels * height, "keygen", 0,
  8856. count, start, ret);
  8857. #ifdef MULTI_VALUE_STATISTICS
  8858. bench_multi_value_stats(max, min, sum, squareSum, runs);
  8859. #endif
  8860. ret = wc_LmsKey_ExportPubRaw(&key, pub, &pubLen);
  8861. if (ret) {
  8862. fprintf(stderr, "error: wc_LmsKey_ExportPubRaw failed: %d\n", ret);
  8863. }
  8864. exit_lms_keygen:
  8865. wc_LmsKey_Free(&key);
  8866. wc_FreeRng(&rng);
  8867. }
  8868. static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
  8869. {
  8870. LmsKey key;
  8871. int ret = 0;
  8872. const char * msg = TEST_STRING;
  8873. word32 msgSz = TEST_STRING_SZ;
  8874. byte * sig = NULL;
  8875. word32 sigSz = 0;
  8876. word32 privLen = 0;
  8877. int loaded = 0;
  8878. int times = 0;
  8879. int count = 0;
  8880. double start = 0.0F;
  8881. const char * str = wc_LmsKey_ParmToStr(parm);
  8882. DECLARE_MULTI_VALUE_STATS_VARS()
  8883. ret = wc_LmsKey_Init(&key, NULL, INVALID_DEVID);
  8884. if (ret) {
  8885. printf("wc_LmsKey_Init failed: %d\n", ret);
  8886. goto exit_lms_sign_verify;
  8887. }
  8888. ret = wc_LmsKey_SetLmsParm(&key, parm);
  8889. if (ret) {
  8890. printf("wc_LmsKey_SetLmsParm failed: %d\n", ret);
  8891. goto exit_lms_sign_verify;
  8892. }
  8893. switch (parm) {
  8894. #ifndef WOLFSSL_NO_LMS_SHA256_256
  8895. case WC_LMS_PARM_L2_H10_W2:
  8896. XMEMCPY(lms_priv, lms_priv_L2_H10_W2, sizeof(lms_priv_L2_H10_W2));
  8897. XMEMCPY(key.pub, lms_pub_L2_H10_W2, HSS_MAX_PUBLIC_KEY_LEN);
  8898. break;
  8899. case WC_LMS_PARM_L2_H10_W4:
  8900. XMEMCPY(lms_priv, lms_priv_L2_H10_W4, sizeof(lms_priv_L2_H10_W4));
  8901. XMEMCPY(key.pub, lms_pub_L2_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8902. break;
  8903. case WC_LMS_PARM_L3_H5_W4:
  8904. XMEMCPY(lms_priv, lms_priv_L3_H5_W4, sizeof(lms_priv_L3_H5_W4));
  8905. XMEMCPY(key.pub, lms_pub_L3_H5_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8906. break;
  8907. case WC_LMS_PARM_L3_H5_W8:
  8908. XMEMCPY(lms_priv, lms_priv_L3_H5_W8, sizeof(lms_priv_L3_H5_W8));
  8909. XMEMCPY(key.pub, lms_pub_L3_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8910. break;
  8911. case WC_LMS_PARM_L3_H10_W4:
  8912. XMEMCPY(lms_priv, lms_priv_L3_H10_W4, sizeof(lms_priv_L3_H10_W4));
  8913. XMEMCPY(key.pub, lms_pub_L3_H10_W4, HSS_MAX_PUBLIC_KEY_LEN);
  8914. break;
  8915. case WC_LMS_PARM_L4_H5_W8:
  8916. XMEMCPY(lms_priv, lms_priv_L4_H5_W8, sizeof(lms_priv_L4_H5_W8));
  8917. XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
  8918. break;
  8919. case WC_LMS_PARM_NONE:
  8920. case WC_LMS_PARM_L1_H15_W2:
  8921. case WC_LMS_PARM_L1_H15_W4:
  8922. case WC_LMS_PARM_L2_H10_W8:
  8923. case WC_LMS_PARM_L3_H5_W2:
  8924. case WC_LMS_PARM_L1_H5_W1:
  8925. case WC_LMS_PARM_L1_H5_W2:
  8926. case WC_LMS_PARM_L1_H5_W4:
  8927. case WC_LMS_PARM_L1_H5_W8:
  8928. case WC_LMS_PARM_L1_H10_W2:
  8929. case WC_LMS_PARM_L1_H10_W4:
  8930. case WC_LMS_PARM_L1_H10_W8:
  8931. case WC_LMS_PARM_L1_H15_W8:
  8932. case WC_LMS_PARM_L1_H20_W2:
  8933. case WC_LMS_PARM_L1_H20_W4:
  8934. case WC_LMS_PARM_L1_H20_W8:
  8935. case WC_LMS_PARM_L2_H5_W2:
  8936. case WC_LMS_PARM_L2_H5_W4:
  8937. case WC_LMS_PARM_L2_H5_W8:
  8938. case WC_LMS_PARM_L2_H15_W2:
  8939. case WC_LMS_PARM_L2_H15_W4:
  8940. case WC_LMS_PARM_L2_H15_W8:
  8941. case WC_LMS_PARM_L2_H20_W2:
  8942. case WC_LMS_PARM_L2_H20_W4:
  8943. case WC_LMS_PARM_L2_H20_W8:
  8944. case WC_LMS_PARM_L3_H10_W8:
  8945. case WC_LMS_PARM_L4_H5_W2:
  8946. case WC_LMS_PARM_L4_H5_W4:
  8947. case WC_LMS_PARM_L4_H10_W4:
  8948. case WC_LMS_PARM_L4_H10_W8:
  8949. #endif
  8950. #ifdef WOLFSSL_LMS_SHA256_192
  8951. case WC_LMS_PARM_SHA256_192_L1_H5_W1:
  8952. case WC_LMS_PARM_SHA256_192_L1_H5_W2:
  8953. case WC_LMS_PARM_SHA256_192_L1_H5_W4:
  8954. case WC_LMS_PARM_SHA256_192_L1_H5_W8:
  8955. case WC_LMS_PARM_SHA256_192_L1_H10_W2:
  8956. case WC_LMS_PARM_SHA256_192_L1_H10_W4:
  8957. case WC_LMS_PARM_SHA256_192_L1_H10_W8:
  8958. case WC_LMS_PARM_SHA256_192_L1_H15_W2:
  8959. case WC_LMS_PARM_SHA256_192_L1_H15_W4:
  8960. case WC_LMS_PARM_SHA256_192_L2_H10_W2:
  8961. case WC_LMS_PARM_SHA256_192_L2_H10_W4:
  8962. case WC_LMS_PARM_SHA256_192_L2_H10_W8:
  8963. case WC_LMS_PARM_SHA256_192_L3_H5_W2:
  8964. case WC_LMS_PARM_SHA256_192_L3_H5_W4:
  8965. case WC_LMS_PARM_SHA256_192_L3_H5_W8:
  8966. case WC_LMS_PARM_SHA256_192_L3_H10_W4:
  8967. case WC_LMS_PARM_SHA256_192_L4_H5_W8:
  8968. #endif
  8969. default:
  8970. XMEMCPY(key.pub, pub, HSS_MAX_PUBLIC_KEY_LEN);
  8971. break;
  8972. }
  8973. ret = wc_LmsKey_SetWriteCb(&key, lms_write_key_mem);
  8974. if (ret) {
  8975. fprintf(stderr, "error: wc_LmsKey_SetWriteCb failed: %d\n", ret);
  8976. goto exit_lms_sign_verify;
  8977. }
  8978. ret = wc_LmsKey_SetReadCb(&key, lms_read_key_mem);
  8979. if (ret) {
  8980. fprintf(stderr, "error: wc_LmsKey_SetReadCb failed: %d\n", ret);
  8981. goto exit_lms_sign_verify;
  8982. }
  8983. ret = wc_LmsKey_SetContext(&key, (void*)lms_priv);
  8984. if (ret) {
  8985. fprintf(stderr, "error: wc_LmsKey_SetContext failed: %d\n", ret);
  8986. goto exit_lms_sign_verify;
  8987. }
  8988. /* Even with saved priv/pub keys, we must still reload the private
  8989. * key before using it. Reloading the private key is the bottleneck
  8990. * for larger heights. Only print load time in debug builds. */
  8991. count = 0;
  8992. bench_stats_start(&count, &start);
  8993. #ifndef WOLFSSL_WC_LMS_SMALL
  8994. do {
  8995. #ifdef WOLFSSL_WC_LMS
  8996. key.priv.inited = 0;
  8997. key.state = WC_LMS_STATE_PARMSET;
  8998. #endif
  8999. ret = wc_LmsKey_Reload(&key);
  9000. if (ret) {
  9001. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9002. goto exit_lms_sign_verify;
  9003. }
  9004. RECORD_MULTI_VALUE_STATS();
  9005. count++;
  9006. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9007. if (ret) {
  9008. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9009. goto exit_lms_sign_verify;
  9010. }
  9011. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9012. if (ret) {
  9013. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9014. goto exit_lms_sign_verify;
  9015. }
  9016. #ifdef HAVE_LIBLMS
  9017. break;
  9018. #endif
  9019. } while (bench_stats_check(start)
  9020. #ifdef MULTI_VALUE_STATISTICS
  9021. || runs < minimum_runs
  9022. #endif
  9023. );
  9024. bench_stats_asym_finish(str, (int)privLen, "load", 0,
  9025. count, start, ret);
  9026. #ifdef MULTI_VALUE_STATISTICS
  9027. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9028. #endif
  9029. RESET_MULTI_VALUE_STATS_VARS();
  9030. #else
  9031. ret = wc_LmsKey_Reload(&key);
  9032. if (ret) {
  9033. printf("wc_LmsKey_Reload failed: %d\n", ret);
  9034. goto exit_lms_sign_verify;
  9035. }
  9036. ret = wc_LmsKey_GetSigLen(&key, &sigSz);
  9037. if (ret) {
  9038. printf("wc_LmsKey_GetSigLen failed: %d\n", ret);
  9039. goto exit_lms_sign_verify;
  9040. }
  9041. ret = wc_LmsKey_GetPrivLen(&key, &privLen);
  9042. if (ret) {
  9043. printf("wc_LmsKey_GetPrivLen failed: %d\n", ret);
  9044. goto exit_lms_sign_verify;
  9045. }
  9046. #endif
  9047. loaded = 1;
  9048. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9049. if (sig == NULL) {
  9050. printf("bench_lms_sign_verify malloc failed\n");
  9051. goto exit_lms_sign_verify;
  9052. }
  9053. count = 0;
  9054. bench_stats_start(&count, &start);
  9055. do {
  9056. /* LMS is stateful. Async queuing not practical. */
  9057. #ifndef WOLFSSL_WC_LMS_SMALL
  9058. for (times = 0; times < ntimes; ++times)
  9059. #else
  9060. for (times = 0; times < 1; ++times)
  9061. #endif
  9062. {
  9063. ret = wc_LmsKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9064. if (ret) {
  9065. printf("wc_LmsKey_Sign failed: %d\n", ret);
  9066. goto exit_lms_sign_verify;
  9067. }
  9068. RECORD_MULTI_VALUE_STATS();
  9069. if (!wc_LmsKey_SigsLeft(&key)) {
  9070. break;
  9071. }
  9072. }
  9073. count += times;
  9074. } while (wc_LmsKey_SigsLeft(&key) && (bench_stats_check(start)
  9075. #ifdef MULTI_VALUE_STATISTICS
  9076. || runs < minimum_runs
  9077. #endif
  9078. ));
  9079. bench_stats_asym_finish(str, (int)sigSz, "sign", 0,
  9080. count, start, ret);
  9081. #ifdef MULTI_VALUE_STATISTICS
  9082. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9083. #endif
  9084. RESET_MULTI_VALUE_STATS_VARS();
  9085. count = 0;
  9086. bench_stats_start(&count, &start);
  9087. do {
  9088. /* LMS is stateful. Async queuing not practical. */
  9089. for (times = 0; times < ntimes; ++times) {
  9090. ret = wc_LmsKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9091. if (ret) {
  9092. printf("wc_LmsKey_Verify failed: %d\n", ret);
  9093. goto exit_lms_sign_verify;
  9094. }
  9095. RECORD_MULTI_VALUE_STATS();
  9096. }
  9097. count += times;
  9098. } while (bench_stats_check(start)
  9099. #ifdef MULTI_VALUE_STATISTICS
  9100. || runs < minimum_runs
  9101. #endif
  9102. );
  9103. exit_lms_sign_verify:
  9104. bench_stats_asym_finish(str, (int)sigSz, "verify", 0,
  9105. count, start, ret);
  9106. #ifdef MULTI_VALUE_STATISTICS
  9107. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9108. #endif
  9109. if (loaded) {
  9110. wc_LmsKey_Free(&key);
  9111. }
  9112. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9113. return;
  9114. }
  9115. void bench_lms(void)
  9116. {
  9117. byte pub[HSS_MAX_PUBLIC_KEY_LEN];
  9118. #ifndef WOLFSSL_NO_LMS_SHA256_256
  9119. #ifdef BENCH_LMS_SLOW_KEYGEN
  9120. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9121. bench_lms_keygen(WC_LMS_PARM_L1_H15_W2, pub);
  9122. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W2, pub);
  9123. bench_lms_keygen(WC_LMS_PARM_L1_H15_W4, pub);
  9124. bench_lms_sign_verify(WC_LMS_PARM_L1_H15_W4, pub);
  9125. #undef LMS_PARAMS_BENCHED
  9126. #define LMS_PARAMS_BENCHED
  9127. #endif
  9128. #endif
  9129. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9130. (LMS_MAX_HEIGHT >= 10))
  9131. bench_lms_keygen(WC_LMS_PARM_L2_H10_W2, pub);
  9132. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W2, pub);
  9133. bench_lms_keygen(WC_LMS_PARM_L2_H10_W4, pub);
  9134. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W4, pub);
  9135. #undef LMS_PARAMS_BENCHED
  9136. #define LMS_PARAMS_BENCHED
  9137. #ifdef BENCH_LMS_SLOW_KEYGEN
  9138. bench_lms_keygen(WC_LMS_PARM_L2_H10_W8, pub);
  9139. bench_lms_sign_verify(WC_LMS_PARM_L2_H10_W8, pub);
  9140. #endif
  9141. #endif
  9142. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9143. bench_lms_keygen(WC_LMS_PARM_L3_H5_W4, pub);
  9144. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W4, pub);
  9145. bench_lms_keygen(WC_LMS_PARM_L3_H5_W8, pub);
  9146. bench_lms_sign_verify(WC_LMS_PARM_L3_H5_W8, pub);
  9147. #undef LMS_PARAMS_BENCHED
  9148. #define LMS_PARAMS_BENCHED
  9149. #endif
  9150. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9151. (LMS_MAX_HEIGHT >= 10))
  9152. bench_lms_keygen(WC_LMS_PARM_L3_H10_W4, pub);
  9153. bench_lms_sign_verify(WC_LMS_PARM_L3_H10_W4, pub);
  9154. #endif
  9155. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9156. bench_lms_keygen(WC_LMS_PARM_L4_H5_W8, pub);
  9157. bench_lms_sign_verify(WC_LMS_PARM_L4_H5_W8, pub);
  9158. #endif
  9159. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9160. bench_lms_keygen(WC_LMS_PARM_L1_H5_W1, pub);
  9161. bench_lms_sign_verify(WC_LMS_PARM_L1_H5_W1, pub);
  9162. #endif
  9163. #endif /* !WOLFSSL_NO_LMS_SHA256_256 */
  9164. #ifdef WOLFSSL_LMS_SHA256_192
  9165. #ifdef BENCH_LMS_SLOW_KEYGEN
  9166. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_HEIGHT >= 15)
  9167. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9168. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W2, pub);
  9169. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9170. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H15_W4, pub);
  9171. #undef LMS_PARAMS_BENCHED
  9172. #define LMS_PARAMS_BENCHED
  9173. #endif
  9174. #endif
  9175. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 2) && \
  9176. (LMS_MAX_HEIGHT >= 10))
  9177. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9178. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W2, pub);
  9179. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9180. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W4, pub);
  9181. #undef LMS_PARAMS_BENCHED
  9182. #define LMS_PARAMS_BENCHED
  9183. #ifdef BENCH_LMS_SLOW_KEYGEN
  9184. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9185. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L2_H10_W8, pub);
  9186. #endif
  9187. #endif
  9188. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 3)
  9189. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9190. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W4, pub);
  9191. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9192. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H5_W8, pub);
  9193. #undef LMS_PARAMS_BENCHED
  9194. #define LMS_PARAMS_BENCHED
  9195. #endif
  9196. #if !defined(WOLFSSL_WC_LMS) || ((LMS_MAX_LEVELS >= 3) && \
  9197. (LMS_MAX_HEIGHT >= 10))
  9198. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9199. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L3_H10_W4, pub);
  9200. #endif
  9201. #if !defined(WOLFSSL_WC_LMS) || (LMS_MAX_LEVELS >= 4)
  9202. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9203. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L4_H5_W8, pub);
  9204. #endif
  9205. #if defined(WOLFSSL_WC_LMS) && !defined(LMS_PARAMS_BENCHED)
  9206. bench_lms_keygen(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9207. bench_lms_sign_verify(WC_LMS_PARM_SHA256_192_L1_H5_W1, pub);
  9208. #endif
  9209. #endif /* WOLFSSL_LMS_SHA256_192 */
  9210. return;
  9211. }
  9212. #endif /* if defined(WOLFSSL_HAVE_LMS) && !defined(WOLFSSL_LMS_VERIFY_ONLY) */
  9213. #if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY)
  9214. static enum wc_XmssRc xmss_write_key_mem(const byte * priv, word32 privSz,
  9215. void *context)
  9216. {
  9217. /* WARNING: THIS IS AN INSECURE WRITE CALLBACK THAT SHOULD ONLY
  9218. * BE USED FOR TESTING PURPOSES! Production applications should
  9219. * write only to non-volatile storage. */
  9220. XMEMCPY(context, priv, privSz);
  9221. return WC_XMSS_RC_SAVED_TO_NV_MEMORY;
  9222. }
  9223. static enum wc_XmssRc xmss_read_key_mem(byte * priv, word32 privSz,
  9224. void *context)
  9225. {
  9226. /* WARNING: THIS IS AN INSECURE READ CALLBACK THAT SHOULD ONLY
  9227. * BE USED FOR TESTING PURPOSES! */
  9228. XMEMCPY(priv, context, privSz);
  9229. return WC_XMSS_RC_READ_TO_MEMORY;
  9230. }
  9231. static void bench_xmss_sign_verify(const char * params)
  9232. {
  9233. WC_RNG rng;
  9234. XmssKey key;
  9235. word32 pkSz = 0;
  9236. word32 skSz = 0;
  9237. int freeRng = 0;
  9238. int freeKey = 0;
  9239. unsigned char * sk = NULL;
  9240. const char * msg = "XMSS post quantum signature test";
  9241. word32 msgSz = (word32) XSTRLEN(msg);
  9242. int ret = 0;
  9243. byte * sig = NULL;
  9244. word32 sigSz = 0;
  9245. int times = 0;
  9246. int count = 0;
  9247. double start = 0.0F;
  9248. #ifndef HAVE_FIPS
  9249. ret = wc_InitRng_ex(&rng, HEAP_HINT, INVALID_DEVID);
  9250. #else
  9251. ret = wc_InitRng(&rng);
  9252. #endif
  9253. if (ret != 0) {
  9254. fprintf(stderr, "error: wc_InitRng failed: %d\n", ret);
  9255. goto exit_xmss_sign_verify;
  9256. }
  9257. freeRng = 1;
  9258. ret = wc_XmssKey_Init(&key, NULL, INVALID_DEVID);
  9259. if (ret != 0) {
  9260. fprintf(stderr, "wc_XmssKey_Init failed: %d\n", ret);
  9261. goto exit_xmss_sign_verify;
  9262. }
  9263. ret = wc_XmssKey_SetParamStr(&key, params);
  9264. if (ret != 0) {
  9265. fprintf(stderr, "wc_XmssKey_SetParamStr failed: %d\n", ret);
  9266. goto exit_xmss_sign_verify;
  9267. }
  9268. ret = wc_XmssKey_GetPubLen(&key, &pkSz);
  9269. if (ret != 0) {
  9270. fprintf(stderr, "wc_XmssKey_GetPubLen failed: %d\n", ret);
  9271. goto exit_xmss_sign_verify;
  9272. }
  9273. #ifndef WOLFSSL_WC_XMSS
  9274. if (pkSz != XMSS_SHA256_PUBLEN) {
  9275. fprintf(stderr, "error: xmss pub len: got %u, expected %d\n", pkSz,
  9276. XMSS_SHA256_PUBLEN);
  9277. goto exit_xmss_sign_verify;
  9278. }
  9279. #endif
  9280. ret = wc_XmssKey_GetPrivLen(&key, &skSz);
  9281. if (ret != 0 || skSz <= 0) {
  9282. fprintf(stderr, "error: wc_XmssKey_GetPrivLen failed\n");
  9283. goto exit_xmss_sign_verify;
  9284. }
  9285. ret = wc_XmssKey_GetSigLen(&key, &sigSz);
  9286. if (ret != 0 || sigSz <= 0) {
  9287. fprintf(stderr, "error: wc_XmssKey_GetSigLen failed\n");
  9288. goto exit_xmss_sign_verify;
  9289. }
  9290. /* Allocate secret keys.*/
  9291. sk = (unsigned char *)XMALLOC(skSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9292. if (sk == NULL) {
  9293. fprintf(stderr, "error: allocate xmss sk failed\n");
  9294. goto exit_xmss_sign_verify;
  9295. }
  9296. /* Allocate signature array. */
  9297. sig = (byte *)XMALLOC(sigSz, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9298. if (sig == NULL) {
  9299. fprintf(stderr, "error: allocate xmss sig failed\n");
  9300. goto exit_xmss_sign_verify;
  9301. }
  9302. ret = wc_XmssKey_SetWriteCb(&key, xmss_write_key_mem);
  9303. if (ret != 0) {
  9304. fprintf(stderr, "error: wc_XmssKey_SetWriteCb failed: %d\n", ret);
  9305. goto exit_xmss_sign_verify;
  9306. }
  9307. ret = wc_XmssKey_SetReadCb(&key, xmss_read_key_mem);
  9308. if (ret != 0) {
  9309. fprintf(stderr, "error: wc_XmssKey_SetReadCb failed: %d\n", ret);
  9310. goto exit_xmss_sign_verify;
  9311. }
  9312. ret = wc_XmssKey_SetContext(&key, (void *)sk);
  9313. if (ret != 0) {
  9314. fprintf(stderr, "error: wc_XmssKey_SetContext failed: %d\n", ret);
  9315. goto exit_xmss_sign_verify;
  9316. }
  9317. #if defined(DEBUG_WOLFSSL) || defined(WOLFSSL_DEBUG_NONBLOCK)
  9318. fprintf(stderr, "params: %s\n", params);
  9319. fprintf(stderr, "pkSz: %d\n", pkSz);
  9320. fprintf(stderr, "skSz: %d\n", skSz);
  9321. fprintf(stderr, "sigSz: %d\n", sigSz);
  9322. #endif
  9323. /* Making the private key is the bottleneck for larger heights. */
  9324. count = 0;
  9325. bench_stats_start(&count, &start);
  9326. ret = wc_XmssKey_MakeKey(&key, &rng);
  9327. if (ret != 0) {
  9328. printf("wc_XmssKey_MakeKey failed: %d\n", ret);
  9329. goto exit_xmss_sign_verify;
  9330. }
  9331. /* Can only do one at a time - state changes after make key. */
  9332. count +=1;
  9333. bench_stats_check(start);
  9334. bench_stats_asym_finish(params, (int)skSz, "gen", 0, count, start, ret);
  9335. freeKey = 1;
  9336. count = 0;
  9337. bench_stats_start(&count, &start);
  9338. do {
  9339. /* XMSS is stateful. Async queuing not practical. */
  9340. #ifndef WOLFSSL_WC_XMSS_SMALL
  9341. for (times = 0; times < ntimes; ++times)
  9342. #else
  9343. for (times = 0; times < 1; ++times)
  9344. #endif
  9345. {
  9346. if (!wc_XmssKey_SigsLeft(&key))
  9347. break;
  9348. ret = wc_XmssKey_Sign(&key, sig, &sigSz, (byte *) msg, msgSz);
  9349. if (ret) {
  9350. printf("wc_XmssKey_Sign failed: %d\n", ret);
  9351. goto exit_xmss_sign_verify;
  9352. }
  9353. }
  9354. count += times;
  9355. } while (wc_XmssKey_SigsLeft(&key) && bench_stats_check(start));
  9356. bench_stats_asym_finish(params, (int)sigSz, "sign", 0, count, start, ret);
  9357. count = 0;
  9358. bench_stats_start(&count, &start);
  9359. do {
  9360. /* XMSS is stateful. Async queuing not practical. */
  9361. for (times = 0; times < ntimes; ++times) {
  9362. ret = wc_XmssKey_Verify(&key, sig, sigSz, (byte *) msg, msgSz);
  9363. if (ret) {
  9364. printf("wc_XmssKey_Verify failed: %d\n", ret);
  9365. goto exit_xmss_sign_verify;
  9366. }
  9367. }
  9368. count += times;
  9369. } while (bench_stats_check(start));
  9370. exit_xmss_sign_verify:
  9371. bench_stats_asym_finish(params, (int)sigSz, "verify", 0, count, start, ret);
  9372. /* Cleanup everything. */
  9373. XFREE(sig, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9374. sig = NULL;
  9375. XFREE(sk, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  9376. sk = NULL;
  9377. if (freeRng) {
  9378. wc_FreeRng(&rng);
  9379. }
  9380. if (freeKey) {
  9381. wc_XmssKey_Free(&key);
  9382. }
  9383. return;
  9384. }
  9385. void bench_xmss(int hash)
  9386. {
  9387. /* All NIST SP 800-208 approved SHA256 XMSS/XMSS^MT parameter
  9388. * sets.
  9389. *
  9390. * Note: not testing "XMSS-SHA2_16_256", "XMSS-SHA2_20_256",
  9391. * and "XMSSMT-SHA2_60/3_256", because their keygen can be
  9392. * very slow, their signatures and private keys quite large,
  9393. * and xmss private keys are not portable across different
  9394. * XMSS/XMSS^MT implementations.
  9395. *
  9396. * The bottleneck in key generation is the height of the first
  9397. * level tree (or h/d).
  9398. *
  9399. * h is the total height of the hyper tree, and d the number of
  9400. * trees.
  9401. */
  9402. /* h/d h d */
  9403. #ifdef WC_XMSS_SHA256
  9404. if (hash == WC_HASH_TYPE_SHA256) {
  9405. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9406. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9407. bench_xmss_sign_verify("XMSS-SHA2_10_256"); /* 10 10 1 */
  9408. #endif
  9409. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9410. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9411. bench_xmss_sign_verify("XMSS-SHA2_16_256"); /* 16 16 1 */
  9412. #endif
  9413. #endif
  9414. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9415. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9416. bench_xmss_sign_verify("XMSS-SHA2_20_256"); /* 20 20 1 */
  9417. #endif
  9418. #endif
  9419. #endif /* HASH_SIZE 256 */
  9420. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9421. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9422. bench_xmss_sign_verify("XMSS-SHA2_10_192"); /* 10 10 1 */
  9423. #endif
  9424. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9425. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9426. bench_xmss_sign_verify("XMSS-SHA2_16_192"); /* 16 16 1 */
  9427. #endif
  9428. #endif
  9429. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9430. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9431. bench_xmss_sign_verify("XMSS-SHA2_20_192"); /* 20 20 1 */
  9432. #endif
  9433. #endif
  9434. #endif /* HASH_SIZE 192 */
  9435. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9436. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9437. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_256"); /* 10 20 2 */
  9438. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_256"); /* 5 20 4 */
  9439. #endif
  9440. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9441. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9442. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_256"); /* 20 40 4 */
  9443. #endif
  9444. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_256"); /* 10 40 4 */
  9445. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_256"); /* 5 40 8 */
  9446. #endif
  9447. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9448. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9449. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_256"); /* 20 60 3 */
  9450. #endif
  9451. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_256"); /* 10 60 6 */
  9452. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_256"); /* 5 60 12 */
  9453. #endif
  9454. #endif /* HASH_SIZE 256 */
  9455. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9456. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9457. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_192"); /* 10 20 2 */
  9458. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_192"); /* 5 20 4 */
  9459. #endif
  9460. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9461. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9462. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_192"); /* 20 40 4 */
  9463. #endif
  9464. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_192"); /* 10 40 4 */
  9465. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_192"); /* 5 40 8 */
  9466. #endif
  9467. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9468. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9469. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_192"); /* 20 60 3 */
  9470. #endif
  9471. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_192"); /* 10 60 6 */
  9472. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_192"); /* 5 60 12 */
  9473. #endif
  9474. #endif /* HASH_SIZE 192 */
  9475. }
  9476. #endif
  9477. #ifdef WC_XMSS_SHA512
  9478. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9479. if (hash == WC_HASH_TYPE_SHA512) {
  9480. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9481. bench_xmss_sign_verify("XMSS-SHA2_10_512"); /* 10 10 1 */
  9482. #endif
  9483. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9484. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9485. bench_xmss_sign_verify("XMSS-SHA2_16_512"); /* 16 16 1 */
  9486. #endif
  9487. #endif
  9488. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9489. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9490. bench_xmss_sign_verify("XMSS-SHA2_20_512"); /* 20 20 1 */
  9491. #endif
  9492. #endif
  9493. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9494. bench_xmss_sign_verify("XMSSMT-SHA2_20/2_512"); /* 10 20 2 */
  9495. bench_xmss_sign_verify("XMSSMT-SHA2_20/4_512"); /* 5 20 4 */
  9496. #endif
  9497. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9498. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9499. bench_xmss_sign_verify("XMSSMT-SHA2_40/2_512"); /* 20 40 4 */
  9500. #endif
  9501. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9502. bench_xmss_sign_verify("XMSSMT-SHA2_40/4_512"); /* 10 40 4 */
  9503. #endif
  9504. bench_xmss_sign_verify("XMSSMT-SHA2_40/8_512"); /* 5 40 8 */
  9505. #endif
  9506. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9507. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9508. bench_xmss_sign_verify("XMSSMT-SHA2_60/3_512"); /* 20 60 3 */
  9509. #endif
  9510. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9511. bench_xmss_sign_verify("XMSSMT-SHA2_60/6_512"); /* 10 60 6 */
  9512. #endif
  9513. bench_xmss_sign_verify("XMSSMT-SHA2_60/12_512"); /* 5 60 12 */
  9514. #endif
  9515. }
  9516. #endif /* HASH_SIZE 512 */
  9517. #endif
  9518. #ifdef WC_XMSS_SHAKE128
  9519. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9520. if (hash == WC_HASH_TYPE_SHAKE128) {
  9521. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9522. bench_xmss_sign_verify("XMSS-SHAKE_10_256"); /* 10 10 1 */
  9523. #endif
  9524. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9525. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9526. bench_xmss_sign_verify("XMSS-SHAKE_16_256"); /* 16 16 1 */
  9527. #endif
  9528. #endif
  9529. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9530. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9531. bench_xmss_sign_verify("XMSS-SHAKE_20_256"); /* 20 20 1 */
  9532. #endif
  9533. #endif
  9534. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9535. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_256"); /* 10 20 2 */
  9536. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_256"); /* 5 20 4 */
  9537. #endif
  9538. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9539. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9540. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_256"); /* 20 40 4 */
  9541. #endif
  9542. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9543. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_256"); /* 10 40 4 */
  9544. #endif
  9545. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_256"); /* 5 40 8 */
  9546. #endif
  9547. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9548. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9549. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_256"); /* 20 60 3 */
  9550. #endif
  9551. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9552. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_256"); /* 10 60 6 */
  9553. #endif
  9554. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_256"); /* 5 60 12 */
  9555. #endif
  9556. }
  9557. #endif /* HASH_SIZE 256 */
  9558. #endif
  9559. #ifdef WC_XMSS_SHAKE256
  9560. if (hash == WC_HASH_TYPE_SHAKE256) {
  9561. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9562. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9563. bench_xmss_sign_verify("XMSS-SHAKE_10_512"); /* 10 10 1 */
  9564. #endif
  9565. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9566. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9567. bench_xmss_sign_verify("XMSS-SHAKE_16_512"); /* 16 16 1 */
  9568. #endif
  9569. #endif
  9570. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9571. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9572. bench_xmss_sign_verify("XMSS-SHAKE_20_512"); /* 20 20 1 */
  9573. #endif
  9574. #endif
  9575. #endif /* HASH_SIZE 512 */
  9576. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9577. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9578. bench_xmss_sign_verify("XMSS-SHAKE256_10_256"); /* 10 10 1 */
  9579. #endif
  9580. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9581. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9582. bench_xmss_sign_verify("XMSS-SHAKE256_16_256"); /* 16 16 1 */
  9583. #endif
  9584. #endif
  9585. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9586. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9587. bench_xmss_sign_verify("XMSS-SHAKE256_20_256"); /* 20 20 1 */
  9588. #endif
  9589. #endif
  9590. #endif /* HASH_SIZE 256 */
  9591. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9592. #if WOLFSSL_XMSS_MIN_HEIGHT <= 10 && WOLFSSL_XMSS_MAX_HEIGHT >= 10
  9593. bench_xmss_sign_verify("XMSS-SHAKE256_10_192"); /* 10 10 1 */
  9594. #endif
  9595. #if WOLFSSL_XMSS_MIN_HEIGHT <= 16 && WOLFSSL_XMSS_MAX_HEIGHT >= 16
  9596. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9597. bench_xmss_sign_verify("XMSS-SHAKE256_16_192"); /* 16 16 1 */
  9598. #endif
  9599. #endif
  9600. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9601. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9602. bench_xmss_sign_verify("XMSS-SHAKE256_20_192"); /* 20 20 1 */
  9603. #endif
  9604. #endif
  9605. #endif /* HASH_SIZE 192 */
  9606. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 512 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 512
  9607. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9608. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9609. bench_xmss_sign_verify("XMSSMT-SHAKE_20/2_512"); /* 10 20 2 */
  9610. #endif
  9611. bench_xmss_sign_verify("XMSSMT-SHAKE_20/4_512"); /* 5 20 4 */
  9612. #endif
  9613. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9614. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9615. bench_xmss_sign_verify("XMSSMT-SHAKE_40/2_512"); /* 20 40 4 */
  9616. #endif
  9617. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9618. bench_xmss_sign_verify("XMSSMT-SHAKE_40/4_512"); /* 10 40 4 */
  9619. #endif
  9620. bench_xmss_sign_verify("XMSSMT-SHAKE_40/8_512"); /* 5 40 8 */
  9621. #endif
  9622. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9623. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9624. bench_xmss_sign_verify("XMSSMT-SHAKE_60/3_512"); /* 20 60 3 */
  9625. #endif
  9626. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9627. bench_xmss_sign_verify("XMSSMT-SHAKE_60/6_512"); /* 10 60 6 */
  9628. #endif
  9629. bench_xmss_sign_verify("XMSSMT-SHAKE_60/12_512"); /* 5 60 12 */
  9630. #endif
  9631. #endif /* HASH_SIZE 512 */
  9632. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 256 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 256
  9633. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9634. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_256"); /* 10 20 2 */
  9635. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_256"); /* 5 20 4 */
  9636. #endif
  9637. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9638. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9639. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_256"); /* 20 40 4 */
  9640. #endif
  9641. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9642. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_256"); /* 10 40 4 */
  9643. #endif
  9644. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_256"); /* 5 40 8 */
  9645. #endif
  9646. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9647. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9648. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_256"); /* 20 60 3 */
  9649. #endif
  9650. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9651. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_256"); /* 10 60 6 */
  9652. #endif
  9653. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_256");/* 5 60 12 */
  9654. #endif
  9655. #endif /* HASH_SIZE 256 */
  9656. #if WOLFSSL_WC_XMSS_MIN_HASH_SIZE <= 192 && WOLFSSL_WC_XMSS_MAX_HASH_SIZE >= 192
  9657. #if WOLFSSL_XMSS_MIN_HEIGHT <= 20 && WOLFSSL_XMSS_MAX_HEIGHT >= 20
  9658. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/2_192"); /* 10 20 2 */
  9659. bench_xmss_sign_verify("XMSSMT-SHAKE256_20/4_192"); /* 5 20 4 */
  9660. #endif
  9661. #if WOLFSSL_XMSS_MIN_HEIGHT <= 40 && WOLFSSL_XMSS_MAX_HEIGHT >= 40
  9662. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9663. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/2_192"); /* 20 40 4 */
  9664. #endif
  9665. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9666. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/4_192"); /* 10 40 4 */
  9667. #endif
  9668. bench_xmss_sign_verify("XMSSMT-SHAKE256_40/8_192"); /* 5 40 8 */
  9669. #endif
  9670. #if WOLFSSL_XMSS_MIN_HEIGHT <= 60 && WOLFSSL_XMSS_MAX_HEIGHT >= 60
  9671. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9672. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/3_192"); /* 20 60 3 */
  9673. #endif
  9674. #ifdef BENCH_XMSS_SLOW_KEYGEN
  9675. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/6_192"); /* 10 60 6 */
  9676. #endif
  9677. bench_xmss_sign_verify("XMSSMT-SHAKE256_60/12_192");/* 5 60 12 */
  9678. #endif
  9679. #endif /* HASH_SIZE 192 */
  9680. }
  9681. #endif
  9682. return;
  9683. }
  9684. #endif /* if defined(WOLFSSL_HAVE_XMSS) && !defined(WOLFSSL_XMSS_VERIFY_ONLY) */
  9685. #ifdef HAVE_ECC
  9686. /* Maximum ECC name plus null terminator:
  9687. * "ECC [%15s]" and "ECDHE [%15s]" and "ECDSA [%15s]" */
  9688. #define BENCH_ECC_NAME_SZ (ECC_MAXNAME + 8)
  9689. /* run all benchmarks on a curve */
  9690. void bench_ecc_curve(int curveId)
  9691. {
  9692. if (bench_all || (bench_asym_algs & BENCH_ECC_MAKEKEY)) {
  9693. #ifndef NO_SW_BENCH
  9694. bench_eccMakeKey(0, curveId);
  9695. #endif
  9696. #if defined(BENCH_DEVID)
  9697. bench_eccMakeKey(1, curveId);
  9698. #endif
  9699. }
  9700. if (bench_all || (bench_asym_algs & BENCH_ECC)) {
  9701. #ifndef NO_SW_BENCH
  9702. bench_ecc(0, curveId);
  9703. #endif
  9704. #if defined(BENCH_DEVID)
  9705. bench_ecc(1, curveId);
  9706. #endif
  9707. }
  9708. #ifdef HAVE_ECC_ENCRYPT
  9709. if (bench_all || (bench_asym_algs & BENCH_ECC_ENCRYPT))
  9710. bench_eccEncrypt(curveId);
  9711. #endif
  9712. }
  9713. void bench_eccMakeKey(int useDeviceID, int curveId)
  9714. {
  9715. int ret = 0, i, times, count = 0, pending = 0;
  9716. int deviceID;
  9717. int keySize = 0;
  9718. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9719. sizeof(ecc_key), HEAP_HINT);
  9720. char name[BENCH_ECC_NAME_SZ];
  9721. double start = 0;
  9722. const char**desc = bench_desc_words[lng_index];
  9723. DECLARE_MULTI_VALUE_STATS_VARS()
  9724. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9725. sizeof(ecc_key), HEAP_HINT);
  9726. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9727. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9728. /* ECC Make Key */
  9729. bench_stats_start(&count, &start);
  9730. do {
  9731. /* while free pending slots in queue, submit ops */
  9732. for (times = 0; times < agreeTimes || pending > 0; ) {
  9733. bench_async_poll(&pending);
  9734. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9735. if (bench_async_check(&ret,
  9736. BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  9737. &times, agreeTimes, &pending)) {
  9738. wc_ecc_free(genKey[i]);
  9739. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  9740. if (ret < 0) {
  9741. goto exit;
  9742. }
  9743. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i],
  9744. curveId);
  9745. if (!bench_async_handle(&ret,
  9746. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  9747. &pending)) {
  9748. goto exit;
  9749. }
  9750. }
  9751. } /* for i */
  9752. RECORD_MULTI_VALUE_STATS();
  9753. } /* for times */
  9754. count += times;
  9755. } while (bench_stats_check(start)
  9756. #ifdef MULTI_VALUE_STATISTICS
  9757. || runs < minimum_runs
  9758. #endif
  9759. );
  9760. exit:
  9761. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  9762. wc_ecc_get_name(curveId));
  9763. bench_stats_asym_finish(name, keySize * 8, desc[2],
  9764. useDeviceID, count, start, ret);
  9765. #ifdef MULTI_VALUE_STATISTICS
  9766. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9767. #endif
  9768. /* cleanup */
  9769. if (WC_ARRAY_OK(genKey)) {
  9770. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9771. wc_ecc_free(genKey[i]);
  9772. }
  9773. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9774. }
  9775. }
  9776. void bench_ecc(int useDeviceID, int curveId)
  9777. {
  9778. int ret = 0, i, times, count, pending = 0;
  9779. int deviceID;
  9780. int keySize;
  9781. char name[BENCH_ECC_NAME_SZ];
  9782. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9783. sizeof(ecc_key), HEAP_HINT);
  9784. #ifdef HAVE_ECC_DHE
  9785. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9786. sizeof(ecc_key), HEAP_HINT);
  9787. #endif
  9788. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9789. #ifdef HAVE_ECC_VERIFY
  9790. int verify[BENCH_MAX_PENDING];
  9791. #endif
  9792. #endif
  9793. word32 x[BENCH_MAX_PENDING];
  9794. double start = 0;
  9795. const char**desc = bench_desc_words[lng_index];
  9796. DECLARE_MULTI_VALUE_STATS_VARS()
  9797. #ifdef HAVE_ECC_DHE
  9798. WC_DECLARE_ARRAY(shared, byte,
  9799. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9800. #endif
  9801. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9802. WC_DECLARE_ARRAY(sig, byte,
  9803. BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9804. WC_DECLARE_ARRAY(digest, byte,
  9805. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9806. #endif
  9807. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9808. /* old scan-build misfires -Wmaybe-uninitialized on these. */
  9809. XMEMSET(sig, 0, sizeof(sig));
  9810. XMEMSET(digest, 0, sizeof(digest));
  9811. #endif
  9812. #ifdef HAVE_ECC_DHE
  9813. XMEMSET(shared, 0, sizeof(shared));
  9814. #endif
  9815. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  9816. sizeof(ecc_key), HEAP_HINT);
  9817. #ifdef HAVE_ECC_DHE
  9818. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  9819. sizeof(ecc_key), HEAP_HINT);
  9820. WC_ALLOC_ARRAY(shared, byte,
  9821. BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9822. #endif
  9823. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9824. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  9825. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  9826. #endif
  9827. deviceID = useDeviceID ? devId : INVALID_DEVID;
  9828. keySize = wc_ecc_get_curve_size_from_id(curveId);
  9829. /* init keys */
  9830. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9831. /* setup an context for each key */
  9832. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  9833. goto exit;
  9834. }
  9835. ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
  9836. #ifdef WOLFSSL_ASYNC_CRYPT
  9837. ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
  9838. #endif
  9839. if (ret < 0) {
  9840. goto exit;
  9841. }
  9842. #ifdef HAVE_ECC_DHE
  9843. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  9844. goto exit;
  9845. }
  9846. if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
  9847. curveId)) > 0) {
  9848. goto exit;
  9849. }
  9850. #endif
  9851. }
  9852. #ifdef HAVE_ECC_DHE
  9853. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  9854. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  9855. !defined(HAVE_SELFTEST)
  9856. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9857. (void)wc_ecc_set_rng(genKey[i], &gRng);
  9858. }
  9859. #endif
  9860. /* ECC Shared Secret */
  9861. bench_stats_start(&count, &start);
  9862. PRIVATE_KEY_UNLOCK();
  9863. do {
  9864. for (times = 0; times < agreeTimes || pending > 0; ) {
  9865. bench_async_poll(&pending);
  9866. /* while free pending slots in queue, submit ops */
  9867. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9868. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9869. &times, agreeTimes, &pending)) {
  9870. x[i] = (word32)keySize;
  9871. ret = wc_ecc_shared_secret(genKey[i], genKey2[i],
  9872. shared[i], &x[i]);
  9873. if (!bench_async_handle(&ret,
  9874. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9875. &pending)) {
  9876. goto exit_ecdhe;
  9877. }
  9878. }
  9879. } /* for i */
  9880. RECORD_MULTI_VALUE_STATS();
  9881. } /* for times */
  9882. count += times;
  9883. } while (bench_stats_check(start)
  9884. #ifdef MULTI_VALUE_STATISTICS
  9885. || runs < minimum_runs
  9886. #endif
  9887. );
  9888. PRIVATE_KEY_UNLOCK();
  9889. exit_ecdhe:
  9890. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  9891. wc_ecc_get_name(curveId));
  9892. bench_stats_asym_finish(name, keySize * 8, desc[3],
  9893. useDeviceID, count, start, ret);
  9894. #ifdef MULTI_VALUE_STATISTICS
  9895. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9896. #endif
  9897. RESET_MULTI_VALUE_STATS_VARS();
  9898. if (ret < 0) {
  9899. goto exit;
  9900. }
  9901. #endif /* HAVE_ECC_DHE */
  9902. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  9903. /* Init digest to sign */
  9904. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9905. for (count = 0; count < keySize; count++) {
  9906. digest[i][count] = (byte)count;
  9907. }
  9908. }
  9909. /* ECC Sign */
  9910. bench_stats_start(&count, &start);
  9911. do {
  9912. for (times = 0; times < agreeTimes || pending > 0; ) {
  9913. bench_async_poll(&pending);
  9914. /* while free pending slots in queue, submit ops */
  9915. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9916. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9917. &times, agreeTimes, &pending)) {
  9918. if (genKey[i]->state == 0) {
  9919. x[i] = ECC_MAX_SIG_SIZE;
  9920. }
  9921. ret = wc_ecc_sign_hash(digest[i], (word32)keySize, sig[i],
  9922. &x[i], GLOBAL_RNG, genKey[i]);
  9923. if (!bench_async_handle(&ret,
  9924. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  9925. &pending)) {
  9926. goto exit_ecdsa_sign;
  9927. }
  9928. } /* bench_async_check */
  9929. } /* for i */
  9930. RECORD_MULTI_VALUE_STATS();
  9931. } /* for times */
  9932. count += times;
  9933. } while (bench_stats_check(start)
  9934. #ifdef MULTI_VALUE_STATISTICS
  9935. || runs < minimum_runs
  9936. #endif
  9937. );
  9938. exit_ecdsa_sign:
  9939. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9940. wc_ecc_get_name(curveId));
  9941. bench_stats_asym_finish(name, keySize * 8, desc[4],
  9942. useDeviceID, count, start, ret);
  9943. #ifdef MULTI_VALUE_STATISTICS
  9944. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9945. #endif
  9946. RESET_MULTI_VALUE_STATS_VARS();
  9947. if (ret < 0) {
  9948. goto exit;
  9949. }
  9950. #ifdef HAVE_ECC_VERIFY
  9951. /* ECC Verify */
  9952. bench_stats_start(&count, &start);
  9953. do {
  9954. for (times = 0; times < agreeTimes || pending > 0; ) {
  9955. bench_async_poll(&pending);
  9956. /* while free pending slots in queue, submit ops */
  9957. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  9958. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  9959. &times, agreeTimes, &pending)) {
  9960. if (genKey[i]->state == 0) {
  9961. verify[i] = 0;
  9962. }
  9963. ret = wc_ecc_verify_hash(sig[i], x[i], digest[i],
  9964. (word32)keySize, &verify[i],
  9965. genKey[i]);
  9966. if (!bench_async_handle(&ret,
  9967. BENCH_ASYNC_GET_DEV(genKey[i]),
  9968. 1, &times,
  9969. &pending)) {
  9970. goto exit_ecdsa_verify;
  9971. }
  9972. } /* if bench_async_check */
  9973. } /* for i */
  9974. RECORD_MULTI_VALUE_STATS();
  9975. } /* for times */
  9976. count += times;
  9977. } while (bench_stats_check(start)
  9978. #ifdef MULTI_VALUE_STATISTICS
  9979. || runs < minimum_runs
  9980. #endif
  9981. );
  9982. exit_ecdsa_verify:
  9983. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  9984. wc_ecc_get_name(curveId));
  9985. bench_stats_asym_finish(name, keySize * 8, desc[5],
  9986. useDeviceID, count, start, ret);
  9987. #ifdef MULTI_VALUE_STATISTICS
  9988. bench_multi_value_stats(max, min, sum, squareSum, runs);
  9989. #endif
  9990. #endif /* HAVE_ECC_VERIFY */
  9991. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  9992. exit:
  9993. /* cleanup */
  9994. if (WC_ARRAY_OK(genKey)) {
  9995. for (i = 0; i < BENCH_MAX_PENDING; i++)
  9996. wc_ecc_free(genKey[i]);
  9997. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  9998. }
  9999. #ifdef HAVE_ECC_DHE
  10000. if (WC_ARRAY_OK(genKey2)) {
  10001. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10002. wc_ecc_free(genKey2[i]);
  10003. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10004. }
  10005. #endif
  10006. #ifdef HAVE_ECC_DHE
  10007. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10008. #endif
  10009. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10010. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10011. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10012. #endif
  10013. (void)useDeviceID;
  10014. (void)pending;
  10015. (void)x;
  10016. (void)count;
  10017. (void)times;
  10018. (void)desc;
  10019. (void)start;
  10020. (void)name;
  10021. }
  10022. #ifdef HAVE_ECC_ENCRYPT
  10023. void bench_eccEncrypt(int curveId)
  10024. {
  10025. #define BENCH_ECCENCRYPT_MSG_SIZE 48
  10026. #define BENCH_ECCENCRYPT_OUT_SIZE (BENCH_ECCENCRYPT_MSG_SIZE + \
  10027. WC_SHA256_DIGEST_SIZE + \
  10028. (MAX_ECC_BITS+3)/4 + 2)
  10029. word32 outSz = BENCH_ECCENCRYPT_OUT_SIZE;
  10030. #ifdef WOLFSSL_SMALL_STACK
  10031. ecc_key *userA = NULL, *userB = NULL;
  10032. byte *msg = NULL;
  10033. byte *out = NULL;
  10034. #else
  10035. ecc_key userA[1], userB[1];
  10036. byte msg[BENCH_ECCENCRYPT_MSG_SIZE];
  10037. byte out[BENCH_ECCENCRYPT_OUT_SIZE];
  10038. #endif
  10039. char name[BENCH_ECC_NAME_SZ];
  10040. int keySize;
  10041. word32 bench_plainSz = bench_size;
  10042. int ret, i, count;
  10043. double start;
  10044. const char**desc = bench_desc_words[lng_index];
  10045. DECLARE_MULTI_VALUE_STATS_VARS()
  10046. #ifdef WOLFSSL_SMALL_STACK
  10047. userA = (ecc_key *)XMALLOC(sizeof(*userA),
  10048. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10049. userB = (ecc_key *)XMALLOC(sizeof(*userB),
  10050. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10051. msg = (byte *)XMALLOC(BENCH_ECCENCRYPT_MSG_SIZE,
  10052. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10053. out = (byte *)XMALLOC(outSz,
  10054. HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10055. if ((! userA) || (! userB) || (! msg) || (! out)) {
  10056. printf("bench_eccEncrypt malloc failed\n");
  10057. goto exit;
  10058. }
  10059. #endif
  10060. keySize = wc_ecc_get_curve_size_from_id(curveId);
  10061. ret = wc_ecc_init_ex(userA, HEAP_HINT, devId);
  10062. if (ret != 0) {
  10063. printf("wc_ecc_encrypt make key A failed: %d\n", ret);
  10064. goto exit;
  10065. }
  10066. ret = wc_ecc_init_ex(userB, HEAP_HINT, devId);
  10067. if (ret != 0) {
  10068. printf("wc_ecc_encrypt make key B failed: %d\n", ret);
  10069. goto exit;
  10070. }
  10071. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10072. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10073. !defined(HAVE_SELFTEST)
  10074. ret = wc_ecc_set_rng(userA, &gRng);
  10075. if (ret != 0) {
  10076. goto exit;
  10077. }
  10078. ret = wc_ecc_set_rng(userB, &gRng);
  10079. if (ret != 0) {
  10080. goto exit;
  10081. }
  10082. #endif
  10083. ret = wc_ecc_make_key_ex(&gRng, keySize, userA, curveId);
  10084. #ifdef WOLFSSL_ASYNC_CRYPT
  10085. ret = wc_AsyncWait(ret, &userA->asyncDev, WC_ASYNC_FLAG_NONE);
  10086. #endif
  10087. if (ret != 0)
  10088. goto exit;
  10089. ret = wc_ecc_make_key_ex(&gRng, keySize, userB, curveId);
  10090. #ifdef WOLFSSL_ASYNC_CRYPT
  10091. ret = wc_AsyncWait(ret, &userB->asyncDev, WC_ASYNC_FLAG_NONE);
  10092. #endif
  10093. if (ret != 0)
  10094. goto exit;
  10095. for (i = 0; i < BENCH_ECCENCRYPT_MSG_SIZE; i++) {
  10096. msg[i] = (byte)i;
  10097. }
  10098. bench_stats_start(&count, &start);
  10099. do {
  10100. for (i = 0; i < ntimes; i++) {
  10101. /* encrypt msg to B */
  10102. ret = wc_ecc_encrypt(userA, userB, msg, BENCH_ECCENCRYPT_MSG_SIZE,
  10103. out, &outSz, NULL);
  10104. if (ret != 0) {
  10105. printf("wc_ecc_encrypt failed! %d\n", ret);
  10106. goto exit_enc;
  10107. }
  10108. RECORD_MULTI_VALUE_STATS();
  10109. }
  10110. count += i;
  10111. } while (bench_stats_check(start)
  10112. #ifdef MULTI_VALUE_STATISTICS
  10113. || runs < minimum_runs
  10114. #endif
  10115. );
  10116. exit_enc:
  10117. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10118. wc_ecc_get_name(curveId));
  10119. bench_stats_asym_finish(name, keySize * 8, desc[6], 0, count, start, ret);
  10120. #ifdef MULTI_VALUE_STATISTICS
  10121. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10122. #endif
  10123. RESET_MULTI_VALUE_STATS_VARS();
  10124. if (ret != 0)
  10125. goto exit;
  10126. bench_stats_start(&count, &start);
  10127. do {
  10128. for (i = 0; i < ntimes; i++) {
  10129. /* decrypt msg from A */
  10130. ret = wc_ecc_decrypt(userB, userA, out, outSz, bench_plain,
  10131. &bench_plainSz, NULL);
  10132. if (ret != 0) {
  10133. printf("wc_ecc_decrypt failed! %d\n", ret);
  10134. goto exit_dec;
  10135. }
  10136. RECORD_MULTI_VALUE_STATS();
  10137. }
  10138. count += i;
  10139. } while (bench_stats_check(start)
  10140. #ifdef MULTI_VALUE_STATISTICS
  10141. || runs < minimum_runs
  10142. #endif
  10143. );
  10144. exit_dec:
  10145. bench_stats_asym_finish(name, keySize * 8, desc[7], 0, count, start, ret);
  10146. #ifdef MULTI_VALUE_STATISTICS
  10147. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10148. #endif
  10149. exit:
  10150. /* cleanup */
  10151. #ifdef WOLFSSL_SMALL_STACK
  10152. if (userA) {
  10153. wc_ecc_free(userA);
  10154. XFREE(userA, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10155. }
  10156. if (userB) {
  10157. wc_ecc_free(userB);
  10158. XFREE(userB, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10159. }
  10160. XFREE(msg, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10161. XFREE(out, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  10162. #else
  10163. wc_ecc_free(userB);
  10164. wc_ecc_free(userA);
  10165. #endif
  10166. }
  10167. #endif
  10168. #ifdef WOLFSSL_SM2
  10169. static void bench_sm2_MakeKey(int useDeviceID)
  10170. {
  10171. int ret = 0, i, times, count = 0, pending = 0;
  10172. int deviceID;
  10173. int keySize;
  10174. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10175. sizeof(ecc_key), HEAP_HINT);
  10176. char name[BENCH_ECC_NAME_SZ];
  10177. double start = 0;
  10178. const char**desc = bench_desc_words[lng_index];
  10179. DECLARE_MULTI_VALUE_STATS_VARS()
  10180. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10181. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10182. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10183. sizeof(ecc_key), HEAP_HINT);
  10184. /* ECC Make Key */
  10185. bench_stats_start(&count, &start);
  10186. do {
  10187. /* while free pending slots in queue, submit ops */
  10188. for (times = 0; times < agreeTimes || pending > 0; ) {
  10189. bench_async_poll(&pending);
  10190. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10191. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 0,
  10192. &times, agreeTimes, &pending)) {
  10193. wc_ecc_free(genKey[i]);
  10194. ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID);
  10195. if (ret < 0) {
  10196. goto exit;
  10197. }
  10198. ret = wc_ecc_sm2_make_key(&gRng, genKey[i],
  10199. WC_ECC_FLAG_NONE);
  10200. if (!bench_async_handle(&ret,
  10201. BENCH_ASYNC_GET_DEV(genKey[i]), 0, &times,
  10202. &pending)) {
  10203. goto exit;
  10204. }
  10205. }
  10206. } /* for i */
  10207. RECORD_MULTI_VALUE_STATS();
  10208. } /* for times */
  10209. count += times;
  10210. } while (bench_stats_check(start)
  10211. #ifdef MULTI_VALUE_STATISTICS
  10212. || runs < minimum_runs
  10213. #endif
  10214. );
  10215. exit:
  10216. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECC [%15s]",
  10217. wc_ecc_get_name(ECC_SM2P256V1));
  10218. bench_stats_asym_finish(name, keySize * 8, desc[2], useDeviceID, count,
  10219. start, ret);
  10220. #ifdef MULTI_VALUE_STATISTICS
  10221. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10222. #endif
  10223. /* cleanup */
  10224. if (WC_ARRAY_OK(genKey)) {
  10225. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10226. wc_ecc_free(genKey[i]);
  10227. }
  10228. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10229. }
  10230. }
  10231. void bench_sm2(int useDeviceID)
  10232. {
  10233. int ret = 0, i, times, count, pending = 0;
  10234. int deviceID;
  10235. int keySize;
  10236. char name[BENCH_ECC_NAME_SZ];
  10237. WC_DECLARE_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10238. sizeof(ecc_key), HEAP_HINT);
  10239. #ifdef HAVE_ECC_DHE
  10240. WC_DECLARE_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10241. sizeof(ecc_key), HEAP_HINT);
  10242. #endif
  10243. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10244. #ifdef HAVE_ECC_VERIFY
  10245. int verify[BENCH_MAX_PENDING];
  10246. #endif
  10247. #endif
  10248. word32 x[BENCH_MAX_PENDING];
  10249. double start = 0;
  10250. const char**desc = bench_desc_words[lng_index];
  10251. DECLARE_MULTI_VALUE_STATS_VARS()
  10252. #ifdef HAVE_ECC_DHE
  10253. WC_DECLARE_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10254. #endif
  10255. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10256. WC_DECLARE_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10257. WC_DECLARE_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10258. #endif
  10259. #ifdef HAVE_ECC_DHE
  10260. WC_ALLOC_ARRAY(shared, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10261. #endif
  10262. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10263. WC_ALLOC_ARRAY(sig, byte, BENCH_MAX_PENDING, ECC_MAX_SIG_SIZE, HEAP_HINT);
  10264. WC_ALLOC_ARRAY(digest, byte, BENCH_MAX_PENDING, MAX_ECC_BYTES, HEAP_HINT);
  10265. #endif
  10266. deviceID = useDeviceID ? devId : INVALID_DEVID;
  10267. bench_sm2_MakeKey(useDeviceID);
  10268. WC_CALLOC_ARRAY(genKey, ecc_key, BENCH_MAX_PENDING,
  10269. sizeof(ecc_key), HEAP_HINT);
  10270. #ifdef HAVE_ECC_DHE
  10271. WC_CALLOC_ARRAY(genKey2, ecc_key, BENCH_MAX_PENDING,
  10272. sizeof(ecc_key), HEAP_HINT);
  10273. #endif
  10274. keySize = wc_ecc_get_curve_size_from_id(ECC_SM2P256V1);
  10275. /* init keys */
  10276. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10277. /* setup an context for each key */
  10278. if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
  10279. goto exit;
  10280. }
  10281. ret = wc_ecc_sm2_make_key(&gRng, genKey[i], WC_ECC_FLAG_NONE);
  10282. #ifdef WOLFSSL_ASYNC_CRYPT
  10283. ret = wc_AsyncWait(ret, genKey[i].asyncDev, WC_ASYNC_FLAG_NONE);
  10284. #endif
  10285. if (ret < 0) {
  10286. goto exit;
  10287. }
  10288. #ifdef HAVE_ECC_DHE
  10289. if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
  10290. goto exit;
  10291. }
  10292. if ((ret = wc_ecc_sm2_make_key(&gRng, genKey2[i],
  10293. WC_ECC_FLAG_NONE)) > 0) {
  10294. goto exit;
  10295. }
  10296. #endif
  10297. }
  10298. #ifdef HAVE_ECC_DHE
  10299. #if defined(ECC_TIMING_RESISTANT) && (!defined(HAVE_FIPS) || \
  10300. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION != 2))) && \
  10301. !defined(HAVE_SELFTEST)
  10302. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10303. (void)wc_ecc_set_rng(genKey[i], &gRng);
  10304. }
  10305. #endif
  10306. /* ECC Shared Secret */
  10307. bench_stats_start(&count, &start);
  10308. PRIVATE_KEY_UNLOCK();
  10309. do {
  10310. for (times = 0; times < agreeTimes || pending > 0; ) {
  10311. bench_async_poll(&pending);
  10312. /* while free pending slots in queue, submit ops */
  10313. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10314. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10315. &times, agreeTimes, &pending)) {
  10316. x[i] = (word32)keySize;
  10317. ret = wc_ecc_sm2_shared_secret(genKey[i], genKey2[i],
  10318. shared[i], &x[i]);
  10319. if (!bench_async_handle(&ret,
  10320. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10321. &pending)) {
  10322. goto exit_ecdhe;
  10323. }
  10324. }
  10325. } /* for i */
  10326. RECORD_MULTI_VALUE_STATS();
  10327. } /* for times */
  10328. count += times;
  10329. } while (bench_stats_check(start)
  10330. #ifdef MULTI_VALUE_STATISTICS
  10331. || runs < minimum_runs
  10332. #endif
  10333. );
  10334. PRIVATE_KEY_UNLOCK();
  10335. exit_ecdhe:
  10336. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDHE [%15s]",
  10337. wc_ecc_get_name(ECC_SM2P256V1));
  10338. bench_stats_asym_finish(name, keySize * 8, desc[3], useDeviceID, count,
  10339. start, ret);
  10340. #ifdef MULTI_VALUE_STATISTICS
  10341. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10342. #endif
  10343. if (ret < 0) {
  10344. goto exit;
  10345. }
  10346. #endif /* HAVE_ECC_DHE */
  10347. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10348. /* Init digest to sign */
  10349. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10350. for (count = 0; count < keySize; count++) {
  10351. digest[i][count] = (byte)count;
  10352. }
  10353. }
  10354. RESET_MULTI_VALUE_STATS_VARS();
  10355. /* ECC Sign */
  10356. bench_stats_start(&count, &start);
  10357. do {
  10358. for (times = 0; times < agreeTimes || pending > 0; ) {
  10359. bench_async_poll(&pending);
  10360. /* while free pending slots in queue, submit ops */
  10361. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10362. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10363. &times, agreeTimes, &pending)) {
  10364. if (genKey[i]->state == 0)
  10365. x[i] = ECC_MAX_SIG_SIZE;
  10366. ret = wc_ecc_sm2_sign_hash(digest[i], (word32)keySize,
  10367. sig[i], &x[i], &gRng, genKey[i]);
  10368. if (!bench_async_handle(&ret,
  10369. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10370. &pending)) {
  10371. goto exit_ecdsa_sign;
  10372. }
  10373. }
  10374. } /* for i */
  10375. RECORD_MULTI_VALUE_STATS();
  10376. } /* for times */
  10377. count += times;
  10378. } while (bench_stats_check(start)
  10379. #ifdef MULTI_VALUE_STATISTICS
  10380. || runs < minimum_runs
  10381. #endif
  10382. );
  10383. exit_ecdsa_sign:
  10384. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10385. wc_ecc_get_name(ECC_SM2P256V1));
  10386. bench_stats_asym_finish(name, keySize * 8, desc[4], useDeviceID, count,
  10387. start, ret);
  10388. #ifdef MULTI_VALUE_STATISTICS
  10389. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10390. #endif
  10391. if (ret < 0) {
  10392. goto exit;
  10393. }
  10394. #ifdef HAVE_ECC_VERIFY
  10395. /* ECC Verify */
  10396. bench_stats_start(&count, &start);
  10397. do {
  10398. for (times = 0; times < agreeTimes || pending > 0; ) {
  10399. bench_async_poll(&pending);
  10400. /* while free pending slots in queue, submit ops */
  10401. for (i = 0; i < BENCH_MAX_PENDING; i++) {
  10402. if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(genKey[i]), 1,
  10403. &times, agreeTimes, &pending)) {
  10404. if (genKey[i]->state == 0)
  10405. verify[i] = 0;
  10406. ret = wc_ecc_sm2_verify_hash(sig[i], x[i], digest[i],
  10407. (word32)keySize, &verify[i], genKey[i]);
  10408. if (!bench_async_handle(&ret,
  10409. BENCH_ASYNC_GET_DEV(genKey[i]), 1, &times,
  10410. &pending)) {
  10411. goto exit_ecdsa_verify;
  10412. }
  10413. }
  10414. } /* for i */
  10415. RECORD_MULTI_VALUE_STATS();
  10416. } /* for times */
  10417. count += times;
  10418. } while (bench_stats_check(start)
  10419. #ifdef MULTI_VALUE_STATISTICS
  10420. || runs < minimum_runs
  10421. #endif
  10422. );
  10423. exit_ecdsa_verify:
  10424. (void)XSNPRINTF(name, BENCH_ECC_NAME_SZ, "ECDSA [%15s]",
  10425. wc_ecc_get_name(ECC_SM2P256V1));
  10426. bench_stats_asym_finish(name, keySize * 8, desc[5], useDeviceID, count,
  10427. start, ret);
  10428. #ifdef MULTI_VALUE_STATISTICS
  10429. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10430. #endif
  10431. #endif /* HAVE_ECC_VERIFY */
  10432. #endif /* !NO_ASN && HAVE_ECC_SIGN */
  10433. exit:
  10434. /* cleanup */
  10435. if (WC_ARRAY_OK(genKey)) {
  10436. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10437. wc_ecc_free(genKey[i]);
  10438. WC_FREE_ARRAY(genKey, BENCH_MAX_PENDING, HEAP_HINT);
  10439. }
  10440. #ifdef HAVE_ECC_DHE
  10441. if (WC_ARRAY_OK(genKey2)) {
  10442. for (i = 0; i < BENCH_MAX_PENDING; i++)
  10443. wc_ecc_free(genKey2[i]);
  10444. WC_FREE_ARRAY(genKey2, BENCH_MAX_PENDING, HEAP_HINT);
  10445. }
  10446. #endif
  10447. #ifdef HAVE_ECC_DHE
  10448. WC_FREE_ARRAY(shared, BENCH_MAX_PENDING, HEAP_HINT);
  10449. #endif
  10450. #if !defined(NO_ASN) && defined(HAVE_ECC_SIGN)
  10451. WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
  10452. WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
  10453. #endif
  10454. (void)useDeviceID;
  10455. (void)pending;
  10456. (void)x;
  10457. (void)count;
  10458. (void)times;
  10459. (void)desc;
  10460. (void)start;
  10461. (void)name;
  10462. }
  10463. #endif /* WOLFSSL_SM2 */
  10464. #endif /* HAVE_ECC */
  10465. #ifdef HAVE_CURVE25519
  10466. void bench_curve25519KeyGen(int useDeviceID)
  10467. {
  10468. curve25519_key genKey;
  10469. double start;
  10470. int ret = 0, i, count;
  10471. const char**desc = bench_desc_words[lng_index];
  10472. DECLARE_MULTI_VALUE_STATS_VARS()
  10473. /* Key Gen */
  10474. bench_stats_start(&count, &start);
  10475. do {
  10476. for (i = 0; i < genTimes; i++) {
  10477. ret = wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10478. useDeviceID ? devId : INVALID_DEVID);
  10479. if (ret != 0) {
  10480. printf("wc_curve25519_init_ex failed: %d\n", ret);
  10481. break;
  10482. }
  10483. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10484. wc_curve25519_free(&genKey);
  10485. if (ret != 0) {
  10486. printf("wc_curve25519_make_key failed: %d\n", ret);
  10487. break;
  10488. }
  10489. RECORD_MULTI_VALUE_STATS();
  10490. }
  10491. count += i;
  10492. } while (bench_stats_check(start)
  10493. #ifdef MULTI_VALUE_STATISTICS
  10494. || runs < minimum_runs
  10495. #endif
  10496. );
  10497. bench_stats_asym_finish("CURVE", 25519, desc[2], useDeviceID, count, start,
  10498. ret);
  10499. #ifdef MULTI_VALUE_STATISTICS
  10500. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10501. #endif
  10502. }
  10503. #ifdef HAVE_CURVE25519_SHARED_SECRET
  10504. void bench_curve25519KeyAgree(int useDeviceID)
  10505. {
  10506. curve25519_key genKey, genKey2;
  10507. double start;
  10508. int ret, i, count;
  10509. byte shared[32];
  10510. const char**desc = bench_desc_words[lng_index];
  10511. word32 x = 0;
  10512. DECLARE_MULTI_VALUE_STATS_VARS()
  10513. wc_curve25519_init_ex(&genKey, HEAP_HINT,
  10514. useDeviceID ? devId : INVALID_DEVID);
  10515. wc_curve25519_init_ex(&genKey2, HEAP_HINT,
  10516. useDeviceID ? devId : INVALID_DEVID);
  10517. ret = wc_curve25519_make_key(&gRng, 32, &genKey);
  10518. if (ret != 0) {
  10519. printf("curve25519_make_key failed\n");
  10520. return;
  10521. }
  10522. ret = wc_curve25519_make_key(&gRng, 32, &genKey2);
  10523. if (ret != 0) {
  10524. printf("curve25519_make_key failed: %d\n", ret);
  10525. wc_curve25519_free(&genKey);
  10526. return;
  10527. }
  10528. /* Shared secret */
  10529. bench_stats_start(&count, &start);
  10530. do {
  10531. for (i = 0; i < agreeTimes; i++) {
  10532. x = sizeof(shared);
  10533. ret = wc_curve25519_shared_secret(&genKey, &genKey2, shared, &x);
  10534. if (ret != 0) {
  10535. printf("curve25519_shared_secret failed: %d\n", ret);
  10536. goto exit;
  10537. }
  10538. RECORD_MULTI_VALUE_STATS();
  10539. }
  10540. count += i;
  10541. } while (bench_stats_check(start)
  10542. #ifdef MULTI_VALUE_STATISTICS
  10543. || runs < minimum_runs
  10544. #endif
  10545. );
  10546. exit:
  10547. bench_stats_asym_finish("CURVE", 25519, desc[3], useDeviceID, count, start,
  10548. ret);
  10549. #ifdef MULTI_VALUE_STATISTICS
  10550. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10551. #endif
  10552. wc_curve25519_free(&genKey2);
  10553. wc_curve25519_free(&genKey);
  10554. }
  10555. #endif /* HAVE_CURVE25519_SHARED_SECRET */
  10556. #endif /* HAVE_CURVE25519 */
  10557. #ifdef HAVE_ED25519
  10558. void bench_ed25519KeyGen(void)
  10559. {
  10560. #ifdef HAVE_ED25519_MAKE_KEY
  10561. ed25519_key genKey;
  10562. double start;
  10563. int i, count;
  10564. const char**desc = bench_desc_words[lng_index];
  10565. DECLARE_MULTI_VALUE_STATS_VARS()
  10566. /* Key Gen */
  10567. bench_stats_start(&count, &start);
  10568. do {
  10569. for (i = 0; i < genTimes; i++) {
  10570. wc_ed25519_init(&genKey);
  10571. (void)wc_ed25519_make_key(&gRng, 32, &genKey);
  10572. wc_ed25519_free(&genKey);
  10573. RECORD_MULTI_VALUE_STATS();
  10574. }
  10575. count += i;
  10576. } while (bench_stats_check(start)
  10577. #ifdef MULTI_VALUE_STATISTICS
  10578. || runs < minimum_runs
  10579. #endif
  10580. );
  10581. bench_stats_asym_finish("ED", 25519, desc[2], 0, count, start, 0);
  10582. #ifdef MULTI_VALUE_STATISTICS
  10583. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10584. #endif
  10585. #endif /* HAVE_ED25519_MAKE_KEY */
  10586. }
  10587. void bench_ed25519KeySign(void)
  10588. {
  10589. #ifdef HAVE_ED25519_MAKE_KEY
  10590. int ret;
  10591. #endif
  10592. ed25519_key genKey;
  10593. #ifdef HAVE_ED25519_SIGN
  10594. double start;
  10595. int i, count;
  10596. byte sig[ED25519_SIG_SIZE];
  10597. byte msg[512];
  10598. word32 x = 0;
  10599. const char**desc = bench_desc_words[lng_index];
  10600. DECLARE_MULTI_VALUE_STATS_VARS()
  10601. #endif
  10602. wc_ed25519_init(&genKey);
  10603. #ifdef HAVE_ED25519_MAKE_KEY
  10604. ret = wc_ed25519_make_key(&gRng, ED25519_KEY_SIZE, &genKey);
  10605. if (ret != 0) {
  10606. printf("ed25519_make_key failed\n");
  10607. return;
  10608. }
  10609. #endif
  10610. #ifdef HAVE_ED25519_SIGN
  10611. /* make dummy msg */
  10612. for (i = 0; i < (int)sizeof(msg); i++)
  10613. msg[i] = (byte)i;
  10614. bench_stats_start(&count, &start);
  10615. do {
  10616. for (i = 0; i < agreeTimes; i++) {
  10617. x = sizeof(sig);
  10618. ret = wc_ed25519_sign_msg(msg, sizeof(msg), sig, &x, &genKey);
  10619. if (ret != 0) {
  10620. printf("ed25519_sign_msg failed\n");
  10621. goto exit_ed_sign;
  10622. }
  10623. RECORD_MULTI_VALUE_STATS();
  10624. }
  10625. count += i;
  10626. } while (bench_stats_check(start)
  10627. #ifdef MULTI_VALUE_STATISTICS
  10628. || runs < minimum_runs
  10629. #endif
  10630. );
  10631. exit_ed_sign:
  10632. bench_stats_asym_finish("ED", 25519, desc[4], 0, count, start, ret);
  10633. #ifdef MULTI_VALUE_STATISTICS
  10634. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10635. #endif
  10636. RESET_MULTI_VALUE_STATS_VARS();
  10637. #ifdef HAVE_ED25519_VERIFY
  10638. bench_stats_start(&count, &start);
  10639. do {
  10640. for (i = 0; i < agreeTimes; i++) {
  10641. int verify = 0;
  10642. ret = wc_ed25519_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10643. &genKey);
  10644. if (ret != 0 || verify != 1) {
  10645. printf("ed25519_verify_msg failed\n");
  10646. goto exit_ed_verify;
  10647. }
  10648. RECORD_MULTI_VALUE_STATS();
  10649. }
  10650. count += i;
  10651. } while (bench_stats_check(start)
  10652. #ifdef MULTI_VALUE_STATISTICS
  10653. || runs < minimum_runs
  10654. #endif
  10655. );
  10656. exit_ed_verify:
  10657. bench_stats_asym_finish("ED", 25519, desc[5], 0, count, start, ret);
  10658. #ifdef MULTI_VALUE_STATISTICS
  10659. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10660. #endif
  10661. #endif /* HAVE_ED25519_VERIFY */
  10662. #endif /* HAVE_ED25519_SIGN */
  10663. wc_ed25519_free(&genKey);
  10664. }
  10665. #endif /* HAVE_ED25519 */
  10666. #ifdef HAVE_CURVE448
  10667. void bench_curve448KeyGen(void)
  10668. {
  10669. curve448_key genKey;
  10670. double start;
  10671. int ret = 0, i, count;
  10672. const char**desc = bench_desc_words[lng_index];
  10673. DECLARE_MULTI_VALUE_STATS_VARS()
  10674. /* Key Gen */
  10675. bench_stats_start(&count, &start);
  10676. do {
  10677. for (i = 0; i < genTimes; i++) {
  10678. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10679. wc_curve448_free(&genKey);
  10680. if (ret != 0) {
  10681. printf("wc_curve448_make_key failed: %d\n", ret);
  10682. break;
  10683. }
  10684. RECORD_MULTI_VALUE_STATS();
  10685. }
  10686. count += i;
  10687. } while (bench_stats_check(start)
  10688. #ifdef MULTI_VALUE_STATISTICS
  10689. || runs < minimum_runs
  10690. #endif
  10691. );
  10692. bench_stats_asym_finish("CURVE", 448, desc[2], 0, count, start, ret);
  10693. #ifdef MULTI_VALUE_STATISTICS
  10694. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10695. #endif
  10696. }
  10697. #ifdef HAVE_CURVE448_SHARED_SECRET
  10698. void bench_curve448KeyAgree(void)
  10699. {
  10700. curve448_key genKey, genKey2;
  10701. double start;
  10702. int ret, i, count;
  10703. byte shared[56];
  10704. const char**desc = bench_desc_words[lng_index];
  10705. word32 x = 0;
  10706. DECLARE_MULTI_VALUE_STATS_VARS()
  10707. wc_curve448_init(&genKey);
  10708. wc_curve448_init(&genKey2);
  10709. ret = wc_curve448_make_key(&gRng, 56, &genKey);
  10710. if (ret != 0) {
  10711. printf("curve448_make_key failed\n");
  10712. return;
  10713. }
  10714. ret = wc_curve448_make_key(&gRng, 56, &genKey2);
  10715. if (ret != 0) {
  10716. printf("curve448_make_key failed: %d\n", ret);
  10717. wc_curve448_free(&genKey);
  10718. return;
  10719. }
  10720. /* Shared secret */
  10721. bench_stats_start(&count, &start);
  10722. do {
  10723. for (i = 0; i < agreeTimes; i++) {
  10724. x = sizeof(shared);
  10725. ret = wc_curve448_shared_secret(&genKey, &genKey2, shared, &x);
  10726. if (ret != 0) {
  10727. printf("curve448_shared_secret failed: %d\n", ret);
  10728. goto exit;
  10729. }
  10730. RECORD_MULTI_VALUE_STATS();
  10731. }
  10732. count += i;
  10733. } while (bench_stats_check(start)
  10734. #ifdef MULTI_VALUE_STATISTICS
  10735. || runs < minimum_runs
  10736. #endif
  10737. );
  10738. exit:
  10739. bench_stats_asym_finish("CURVE", 448, desc[3], 0, count, start, ret);
  10740. #ifdef MULTI_VALUE_STATISTICS
  10741. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10742. #endif
  10743. wc_curve448_free(&genKey2);
  10744. wc_curve448_free(&genKey);
  10745. }
  10746. #endif /* HAVE_CURVE448_SHARED_SECRET */
  10747. #endif /* HAVE_CURVE448 */
  10748. #ifdef HAVE_ED448
  10749. void bench_ed448KeyGen(void)
  10750. {
  10751. ed448_key genKey;
  10752. double start;
  10753. int i, count;
  10754. const char**desc = bench_desc_words[lng_index];
  10755. DECLARE_MULTI_VALUE_STATS_VARS()
  10756. /* Key Gen */
  10757. bench_stats_start(&count, &start);
  10758. do {
  10759. for (i = 0; i < genTimes; i++) {
  10760. wc_ed448_init(&genKey);
  10761. (void)wc_ed448_make_key(&gRng, ED448_KEY_SIZE, &genKey);
  10762. wc_ed448_free(&genKey);
  10763. RECORD_MULTI_VALUE_STATS();
  10764. }
  10765. count += i;
  10766. } while (bench_stats_check(start)
  10767. #ifdef MULTI_VALUE_STATISTICS
  10768. || runs < minimum_runs
  10769. #endif
  10770. );
  10771. bench_stats_asym_finish("ED", 448, desc[2], 0, count, start, 0);
  10772. #ifdef MULTI_VALUE_STATISTICS
  10773. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10774. #endif
  10775. }
  10776. void bench_ed448KeySign(void)
  10777. {
  10778. int ret;
  10779. WC_DECLARE_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10780. #ifdef HAVE_ED448_SIGN
  10781. double start;
  10782. int i, count;
  10783. byte sig[ED448_SIG_SIZE];
  10784. byte msg[512];
  10785. word32 x = 0;
  10786. const char**desc = bench_desc_words[lng_index];
  10787. DECLARE_MULTI_VALUE_STATS_VARS()
  10788. #endif
  10789. WC_ALLOC_VAR(genKey, ed448_key, 1, HEAP_HINT);
  10790. wc_ed448_init(genKey);
  10791. ret = wc_ed448_make_key(&gRng, ED448_KEY_SIZE, genKey);
  10792. if (ret != 0) {
  10793. printf("ed448_make_key failed\n");
  10794. goto exit;
  10795. }
  10796. #ifdef HAVE_ED448_SIGN
  10797. /* make dummy msg */
  10798. for (i = 0; i < (int)sizeof(msg); i++)
  10799. msg[i] = (byte)i;
  10800. bench_stats_start(&count, &start);
  10801. do {
  10802. for (i = 0; i < agreeTimes; i++) {
  10803. x = sizeof(sig);
  10804. ret = wc_ed448_sign_msg(msg, sizeof(msg), sig, &x, genKey,
  10805. NULL, 0);
  10806. if (ret != 0) {
  10807. printf("ed448_sign_msg failed\n");
  10808. goto exit;
  10809. }
  10810. RECORD_MULTI_VALUE_STATS();
  10811. }
  10812. count += i;
  10813. } while (bench_stats_check(start)
  10814. #ifdef MULTI_VALUE_STATISTICS
  10815. || runs < minimum_runs
  10816. #endif
  10817. );
  10818. bench_stats_asym_finish("ED", 448, desc[4], 0, count, start, ret);
  10819. #ifdef MULTI_VALUE_STATISTICS
  10820. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10821. #endif
  10822. RESET_MULTI_VALUE_STATS_VARS();
  10823. #ifdef HAVE_ED448_VERIFY
  10824. bench_stats_start(&count, &start);
  10825. do {
  10826. for (i = 0; i < agreeTimes; i++) {
  10827. int verify = 0;
  10828. ret = wc_ed448_verify_msg(sig, x, msg, sizeof(msg), &verify,
  10829. genKey, NULL, 0);
  10830. if (ret != 0 || verify != 1) {
  10831. printf("ed448_verify_msg failed\n");
  10832. goto exit;
  10833. }
  10834. RECORD_MULTI_VALUE_STATS();
  10835. }
  10836. count += i;
  10837. } while (bench_stats_check(start)
  10838. #ifdef MULTI_VALUE_STATISTICS
  10839. || runs < minimum_runs
  10840. #endif
  10841. );
  10842. bench_stats_asym_finish("ED", 448, desc[5], 0, count, start, ret);
  10843. #ifdef MULTI_VALUE_STATISTICS
  10844. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10845. #endif
  10846. #endif /* HAVE_ED448_VERIFY */
  10847. #endif /* HAVE_ED448_SIGN */
  10848. exit:
  10849. wc_ed448_free(genKey);
  10850. WC_FREE_VAR(genKey, HEAP_HINT);
  10851. }
  10852. #endif /* HAVE_ED448 */
  10853. #ifdef WOLFCRYPT_HAVE_ECCSI
  10854. #ifdef WOLFCRYPT_ECCSI_KMS
  10855. void bench_eccsiKeyGen(void)
  10856. {
  10857. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10858. double start;
  10859. int i, count;
  10860. const char**desc = bench_desc_words[lng_index];
  10861. int ret;
  10862. DECLARE_MULTI_VALUE_STATS_VARS()
  10863. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10864. /* Key Gen */
  10865. bench_stats_start(&count, &start);
  10866. do {
  10867. for (i = 0; i < genTimes; i++) {
  10868. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10869. ret = wc_MakeEccsiKey(genKey, &gRng);
  10870. wc_FreeEccsiKey(genKey);
  10871. if (ret != 0) {
  10872. printf("wc_MakeEccsiKey failed: %d\n", ret);
  10873. goto exit;
  10874. }
  10875. RECORD_MULTI_VALUE_STATS();
  10876. }
  10877. count += i;
  10878. } while (bench_stats_check(start)
  10879. #ifdef MULTI_VALUE_STATISTICS
  10880. || runs < minimum_runs
  10881. #endif
  10882. );
  10883. bench_stats_asym_finish("ECCSI", 256, desc[2], 0, count, start, 0);
  10884. #ifdef MULTI_VALUE_STATISTICS
  10885. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10886. #endif
  10887. exit:
  10888. WC_FREE_VAR(genKey, HEAP_HINT);
  10889. }
  10890. void bench_eccsiPairGen(void)
  10891. {
  10892. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10893. double start;
  10894. int i, count;
  10895. const char**desc = bench_desc_words[lng_index];
  10896. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10897. ecc_point* pvt;
  10898. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10899. int ret;
  10900. DECLARE_MULTI_VALUE_STATS_VARS()
  10901. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10902. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10903. (void)mp_init(ssk);
  10904. pvt = wc_ecc_new_point();
  10905. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10906. (void)wc_MakeEccsiKey(genKey, &gRng);
  10907. /* RSK Gen */
  10908. bench_stats_start(&count, &start);
  10909. do {
  10910. for (i = 0; i < genTimes; i++) {
  10911. ret = wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id,
  10912. sizeof(id), ssk, pvt);
  10913. if (ret != 0) {
  10914. printf("wc_MakeEccsiPair failed: %d\n", ret);
  10915. goto exit;
  10916. }
  10917. RECORD_MULTI_VALUE_STATS();
  10918. }
  10919. count += i;
  10920. } while (bench_stats_check(start)
  10921. #ifdef MULTI_VALUE_STATISTICS
  10922. || runs < minimum_runs
  10923. #endif
  10924. );
  10925. bench_stats_asym_finish("ECCSI", 256, desc[12], 0, count, start, 0);
  10926. #ifdef MULTI_VALUE_STATISTICS
  10927. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10928. #endif
  10929. wc_FreeEccsiKey(genKey);
  10930. wc_ecc_del_point(pvt);
  10931. mp_free(ssk);
  10932. exit:
  10933. WC_FREE_VAR(genKey, HEAP_HINT);
  10934. WC_FREE_VAR(ssk, HEAP_HINT);
  10935. }
  10936. #endif
  10937. #ifdef WOLFCRYPT_ECCSI_CLIENT
  10938. void bench_eccsiValidate(void)
  10939. {
  10940. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10941. double start;
  10942. int i, count;
  10943. const char**desc = bench_desc_words[lng_index];
  10944. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10945. ecc_point* pvt;
  10946. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10947. int valid;
  10948. int ret;
  10949. DECLARE_MULTI_VALUE_STATS_VARS()
  10950. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10951. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  10952. (void)mp_init(ssk);
  10953. pvt = wc_ecc_new_point();
  10954. wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  10955. (void)wc_MakeEccsiKey(genKey, &gRng);
  10956. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  10957. ssk, pvt);
  10958. /* Validation of RSK */
  10959. bench_stats_start(&count, &start);
  10960. do {
  10961. for (i = 0; i < genTimes; i++) {
  10962. ret = wc_ValidateEccsiPair(genKey, WC_HASH_TYPE_SHA256, id,
  10963. sizeof(id), ssk, pvt, &valid);
  10964. if (ret != 0 || !valid) {
  10965. printf("wc_ValidateEccsiPair failed: %d (valid=%d))\n", ret,
  10966. valid);
  10967. goto exit;
  10968. }
  10969. RECORD_MULTI_VALUE_STATS();
  10970. }
  10971. count += i;
  10972. } while (bench_stats_check(start)
  10973. #ifdef MULTI_VALUE_STATISTICS
  10974. || runs < minimum_runs
  10975. #endif
  10976. );
  10977. bench_stats_asym_finish("ECCSI", 256, desc[11], 0, count, start, 0);
  10978. #ifdef MULTI_VALUE_STATISTICS
  10979. bench_multi_value_stats(max, min, sum, squareSum, runs);
  10980. #endif
  10981. wc_FreeEccsiKey(genKey);
  10982. wc_ecc_del_point(pvt);
  10983. mp_free(ssk);
  10984. exit:
  10985. WC_FREE_VAR(genKey, HEAP_HINT);
  10986. WC_FREE_VAR(ssk, HEAP_HINT);
  10987. }
  10988. void bench_eccsi(void)
  10989. {
  10990. WC_DECLARE_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  10991. double start;
  10992. int i, count;
  10993. const char**desc = bench_desc_words[lng_index];
  10994. WC_DECLARE_VAR(ssk, mp_int, 1, HEAP_HINT);
  10995. ecc_point* pvt;
  10996. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  10997. static const byte msg[] = { 0x01, 0x23, 0x34, 0x45 };
  10998. byte hash[WC_SHA256_DIGEST_SIZE];
  10999. byte hashSz = (byte)sizeof(hash);
  11000. byte sig[257];
  11001. word32 sigSz = sizeof(sig);
  11002. int ret;
  11003. int verified;
  11004. DECLARE_MULTI_VALUE_STATS_VARS()
  11005. WC_ALLOC_VAR(genKey, EccsiKey, 1, HEAP_HINT);
  11006. WC_ALLOC_VAR(ssk, mp_int, 1, HEAP_HINT);
  11007. (void)mp_init(ssk);
  11008. pvt = wc_ecc_new_point();
  11009. (void)wc_InitEccsiKey(genKey, NULL, INVALID_DEVID);
  11010. (void)wc_MakeEccsiKey(genKey, &gRng);
  11011. (void)wc_MakeEccsiPair(genKey, &gRng, WC_HASH_TYPE_SHA256, id, sizeof(id),
  11012. ssk, pvt);
  11013. (void)wc_HashEccsiId(genKey, WC_HASH_TYPE_SHA256, id, sizeof(id), pvt,
  11014. hash, &hashSz);
  11015. (void)wc_SetEccsiHash(genKey, hash, hashSz);
  11016. (void)wc_SetEccsiPair(genKey, ssk, pvt);
  11017. /* Encapsulate */
  11018. bench_stats_start(&count, &start);
  11019. do {
  11020. for (i = 0; i < genTimes; i++) {
  11021. ret = wc_SignEccsiHash(genKey, &gRng, WC_HASH_TYPE_SHA256, msg,
  11022. sizeof(msg), sig, &sigSz);
  11023. if (ret != 0) {
  11024. printf("wc_SignEccsiHash failed: %d\n", ret);
  11025. break;
  11026. }
  11027. RECORD_MULTI_VALUE_STATS();
  11028. }
  11029. count += i;
  11030. } while (bench_stats_check(start)
  11031. #ifdef MULTI_VALUE_STATISTICS
  11032. || runs < minimum_runs
  11033. #endif
  11034. );
  11035. bench_stats_asym_finish("ECCSI", 256, desc[4], 0, count, start, 0);
  11036. #ifdef MULTI_VALUE_STATISTICS
  11037. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11038. #endif
  11039. RESET_MULTI_VALUE_STATS_VARS();
  11040. /* Derive */
  11041. bench_stats_start(&count, &start);
  11042. do {
  11043. for (i = 0; i < genTimes; i++) {
  11044. ret = wc_VerifyEccsiHash(genKey, WC_HASH_TYPE_SHA256, msg,
  11045. sizeof(msg), sig, sigSz, &verified);
  11046. if (ret != 0 || !verified) {
  11047. printf("wc_VerifyEccsiHash failed: %d (verified: %d)\n", ret,
  11048. verified);
  11049. goto exit;
  11050. }
  11051. RECORD_MULTI_VALUE_STATS();
  11052. }
  11053. count += i;
  11054. } while (bench_stats_check(start)
  11055. #ifdef MULTI_VALUE_STATISTICS
  11056. || runs < minimum_runs
  11057. #endif
  11058. );
  11059. bench_stats_asym_finish("ECCSI", 256, desc[5], 0, count, start, 0);
  11060. #ifdef MULTI_VALUE_STATISTICS
  11061. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11062. #endif
  11063. wc_FreeEccsiKey(genKey);
  11064. wc_ecc_del_point(pvt);
  11065. exit:
  11066. WC_FREE_VAR(genKey, HEAP_HINT);
  11067. WC_FREE_VAR(ssk, HEAP_HINT);
  11068. }
  11069. #endif /* WOLFCRYPT_ECCSI_CLIENT */
  11070. #endif /* WOLFCRYPT_HAVE_ECCSI */
  11071. #ifdef WOLFCRYPT_HAVE_SAKKE
  11072. #ifdef WOLFCRYPT_SAKKE_KMS
  11073. void bench_sakkeKeyGen(void)
  11074. {
  11075. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11076. double start;
  11077. int i, count;
  11078. const char**desc = bench_desc_words[lng_index];
  11079. int ret;
  11080. DECLARE_MULTI_VALUE_STATS_VARS()
  11081. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11082. /* Key Gen */
  11083. bench_stats_start(&count, &start);
  11084. do {
  11085. for (i = 0; i < genTimes; i++) {
  11086. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11087. ret = wc_MakeSakkeKey(genKey, &gRng);
  11088. if (ret != 0) {
  11089. printf("wc_MakeSakkeKey failed: %d\n", ret);
  11090. goto exit;
  11091. }
  11092. wc_FreeSakkeKey(genKey);
  11093. RECORD_MULTI_VALUE_STATS();
  11094. }
  11095. count += i;
  11096. } while (bench_stats_check(start)
  11097. #ifdef MULTI_VALUE_STATISTICS
  11098. || runs < minimum_runs
  11099. #endif
  11100. );
  11101. bench_stats_asym_finish("SAKKE", 1024, desc[2], 0, count, start, 0);
  11102. #ifdef MULTI_VALUE_STATISTICS
  11103. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11104. #endif
  11105. exit:
  11106. WC_FREE_VAR(genKey, HEAP_HINT);
  11107. }
  11108. void bench_sakkeRskGen(void)
  11109. {
  11110. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11111. double start;
  11112. int i, count;
  11113. const char**desc = bench_desc_words[lng_index];
  11114. ecc_point* rsk;
  11115. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11116. int ret;
  11117. DECLARE_MULTI_VALUE_STATS_VARS()
  11118. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11119. rsk = wc_ecc_new_point();
  11120. wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11121. (void)wc_MakeSakkeKey(genKey, &gRng);
  11122. /* RSK Gen */
  11123. bench_stats_start(&count, &start);
  11124. do {
  11125. for (i = 0; i < genTimes; i++) {
  11126. ret = wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11127. if (ret != 0) {
  11128. printf("wc_MakeSakkeRsk failed: %d\n", ret);
  11129. goto exit;
  11130. }
  11131. RECORD_MULTI_VALUE_STATS();
  11132. }
  11133. count += i;
  11134. } while (bench_stats_check(start)
  11135. #ifdef MULTI_VALUE_STATISTICS
  11136. || runs < minimum_runs
  11137. #endif
  11138. );
  11139. bench_stats_asym_finish("SAKKE", 1024, desc[8], 0, count, start, 0);
  11140. #ifdef MULTI_VALUE_STATISTICS
  11141. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11142. #endif
  11143. wc_FreeSakkeKey(genKey);
  11144. wc_ecc_del_point(rsk);
  11145. exit:
  11146. WC_FREE_VAR(genKey, HEAP_HINT);
  11147. }
  11148. #endif
  11149. #ifdef WOLFCRYPT_SAKKE_CLIENT
  11150. void bench_sakkeValidate(void)
  11151. {
  11152. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11153. double start;
  11154. int i, count;
  11155. const char**desc = bench_desc_words[lng_index];
  11156. ecc_point* rsk;
  11157. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11158. int valid;
  11159. int ret;
  11160. DECLARE_MULTI_VALUE_STATS_VARS()
  11161. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11162. rsk = wc_ecc_new_point();
  11163. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11164. (void)wc_MakeSakkeKey(genKey, &gRng);
  11165. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11166. (void)wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11167. /* Validation of RSK */
  11168. bench_stats_start(&count, &start);
  11169. do {
  11170. for (i = 0; i < genTimes; i++) {
  11171. ret = wc_ValidateSakkeRsk(genKey, id, sizeof(id), rsk, &valid);
  11172. if (ret != 0 || !valid) {
  11173. printf("wc_ValidateSakkeRsk failed: %d (valid=%d))\n", ret,
  11174. valid);
  11175. goto exit;
  11176. }
  11177. RECORD_MULTI_VALUE_STATS();
  11178. }
  11179. count += i;
  11180. } while (bench_stats_check(start)
  11181. #ifdef MULTI_VALUE_STATISTICS
  11182. || runs < minimum_runs
  11183. #endif
  11184. );
  11185. bench_stats_asym_finish("SAKKE", 1024, desc[11], 0, count, start, 0);
  11186. #ifdef MULTI_VALUE_STATISTICS
  11187. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11188. #endif
  11189. wc_FreeSakkeKey(genKey);
  11190. wc_ecc_del_point(rsk);
  11191. exit:
  11192. WC_FREE_VAR(genKey, HEAP_HINT);
  11193. }
  11194. void bench_sakke(void)
  11195. {
  11196. WC_DECLARE_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11197. double start;
  11198. int i, count;
  11199. const char**desc = bench_desc_words[lng_index];
  11200. ecc_point* rsk;
  11201. static const byte id[] = { 0x01, 0x23, 0x34, 0x45 };
  11202. static const byte ssv_init[] = { 0x01, 0x23, 0x34, 0x45 };
  11203. byte ssv[sizeof(ssv_init)];
  11204. byte derSSV[sizeof(ssv)];
  11205. byte auth[257];
  11206. word16 authSz = sizeof(auth);
  11207. int ret = 0;
  11208. byte* table = NULL;
  11209. word32 len = 0;
  11210. byte* iTable = NULL;
  11211. word32 iTableLen = 0;
  11212. DECLARE_MULTI_VALUE_STATS_VARS()
  11213. WC_ALLOC_VAR(genKey, SakkeKey, 1, HEAP_HINT);
  11214. XMEMCPY(ssv, ssv_init, sizeof ssv);
  11215. rsk = wc_ecc_new_point();
  11216. (void)wc_InitSakkeKey_ex(genKey, 128, ECC_SAKKE_1, NULL, INVALID_DEVID);
  11217. (void)wc_MakeSakkeKey(genKey, &gRng);
  11218. (void)wc_MakeSakkeRsk(genKey, id, sizeof(id), rsk);
  11219. (void)wc_SetSakkeRsk(genKey, rsk, NULL, 0);
  11220. (void)wc_SetSakkeIdentity(genKey, id, sizeof(id));
  11221. /* Encapsulate */
  11222. bench_stats_start(&count, &start);
  11223. do {
  11224. for (i = 0; i < genTimes; i++) {
  11225. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11226. WC_HASH_TYPE_SHA256,
  11227. ssv, sizeof(ssv), auth, &authSz);
  11228. if (ret != 0) {
  11229. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11230. break;
  11231. }
  11232. RECORD_MULTI_VALUE_STATS();
  11233. } /* for */
  11234. count += i;
  11235. } while (bench_stats_check(start)
  11236. #ifdef MULTI_VALUE_STATISTICS
  11237. || runs < minimum_runs
  11238. #endif
  11239. );
  11240. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-1",
  11241. 0, count, start, 0);
  11242. #ifdef MULTI_VALUE_STATISTICS
  11243. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11244. #endif
  11245. RESET_MULTI_VALUE_STATS_VARS();
  11246. /* Derive */
  11247. bench_stats_start(&count, &start);
  11248. do {
  11249. for (i = 0; i < genTimes; i++) {
  11250. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11251. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11252. sizeof(derSSV), auth, authSz);
  11253. if (ret != 0) {
  11254. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11255. break;
  11256. }
  11257. RECORD_MULTI_VALUE_STATS();
  11258. }
  11259. if (ret != 0) break;
  11260. count += i;
  11261. } while (bench_stats_check(start)
  11262. #ifdef MULTI_VALUE_STATISTICS
  11263. || runs < minimum_runs
  11264. #endif
  11265. );
  11266. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-1",
  11267. 0, count, start, 0);
  11268. #ifdef MULTI_VALUE_STATISTICS
  11269. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11270. #endif
  11271. /* Calculate Point I and generate table. */
  11272. (void)wc_MakeSakkePointI(genKey, id, sizeof(id));
  11273. iTableLen = 0;
  11274. (void)wc_GenerateSakkePointITable(genKey, NULL, &iTableLen);
  11275. if (iTableLen != 0) {
  11276. iTable = (byte*)XMALLOC(iTableLen, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11277. if (iTable == NULL)
  11278. WC_ALLOC_DO_ON_FAILURE();
  11279. (void)wc_GenerateSakkePointITable(genKey, iTable, &iTableLen);
  11280. }
  11281. /* Encapsulate with Point I table */
  11282. bench_stats_start(&count, &start);
  11283. do {
  11284. for (i = 0; i < genTimes; i++) {
  11285. ret = wc_MakeSakkeEncapsulatedSSV(genKey,
  11286. WC_HASH_TYPE_SHA256, ssv,
  11287. sizeof(ssv), auth, &authSz);
  11288. if (ret != 0) {
  11289. printf("wc_MakeSakkeEncapsulatedSSV failed: %d\n", ret);
  11290. break;
  11291. }
  11292. RECORD_MULTI_VALUE_STATS();
  11293. }
  11294. count += i;
  11295. } while (bench_stats_check(start)
  11296. #ifdef MULTI_VALUE_STATISTICS
  11297. || runs < minimum_runs
  11298. #endif
  11299. );
  11300. bench_stats_asym_finish_ex("SAKKE", 1024, desc[9], "-2", 0,
  11301. count, start, 0);
  11302. #ifdef MULTI_VALUE_STATISTICS
  11303. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11304. #endif
  11305. RESET_MULTI_VALUE_STATS_VARS();
  11306. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11307. /* Derive with Point I table */
  11308. bench_stats_start(&count, &start);
  11309. do {
  11310. for (i = 0; i < genTimes; i++) {
  11311. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11312. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11313. sizeof(derSSV), auth, authSz);
  11314. if (ret != 0) {
  11315. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11316. break;
  11317. }
  11318. RECORD_MULTI_VALUE_STATS();
  11319. }
  11320. if (ret != 0) break;
  11321. count += i;
  11322. } while (bench_stats_check(start)
  11323. #ifdef MULTI_VALUE_STATISTICS
  11324. || runs < minimum_runs
  11325. #endif
  11326. );
  11327. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-2", 0,
  11328. count, start, 0);
  11329. #ifdef MULTI_VALUE_STATISTICS
  11330. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11331. #endif
  11332. RESET_MULTI_VALUE_STATS_VARS();
  11333. len = 0;
  11334. (void)wc_GenerateSakkeRskTable(genKey, rsk, NULL, &len);
  11335. if (len > 0) {
  11336. table = (byte*)XMALLOC(len, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11337. if (table == NULL)
  11338. WC_ALLOC_DO_ON_FAILURE();
  11339. (void)wc_GenerateSakkeRskTable(genKey, rsk, table, &len);
  11340. }
  11341. (void)wc_SetSakkeRsk(genKey, rsk, table, len);
  11342. /* Derive with Point I table and RSK table */
  11343. bench_stats_start(&count, &start);
  11344. do {
  11345. for (i = 0; i < genTimes; i++) {
  11346. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11347. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11348. sizeof(derSSV), auth, authSz);
  11349. if (ret != 0) {
  11350. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11351. break;
  11352. }
  11353. RECORD_MULTI_VALUE_STATS();
  11354. }
  11355. if (ret != 0) break;
  11356. count += i;
  11357. } while (bench_stats_check(start)
  11358. #ifdef MULTI_VALUE_STATISTICS
  11359. || runs < minimum_runs
  11360. #endif
  11361. );
  11362. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-3",
  11363. 0, count, start, 0);
  11364. #ifdef MULTI_VALUE_STATISTICS
  11365. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11366. #endif
  11367. RESET_MULTI_VALUE_STATS_VARS();
  11368. wc_ClearSakkePointITable(genKey);
  11369. /* Derive with RSK table */
  11370. bench_stats_start(&count, &start);
  11371. do {
  11372. for (i = 0; i < genTimes; i++) {
  11373. XMEMCPY(derSSV, ssv, sizeof(ssv));
  11374. ret = wc_DeriveSakkeSSV(genKey, WC_HASH_TYPE_SHA256, derSSV,
  11375. sizeof(derSSV), auth, authSz);
  11376. if (ret != 0) {
  11377. printf("wc_DeriveSakkeSSV failed: %d\n", ret);
  11378. break;
  11379. }
  11380. RECORD_MULTI_VALUE_STATS();
  11381. }
  11382. if (ret != 0) break;
  11383. count += i;
  11384. } while (bench_stats_check(start)
  11385. #ifdef MULTI_VALUE_STATISTICS
  11386. || runs < minimum_runs
  11387. #endif
  11388. );
  11389. bench_stats_asym_finish_ex("SAKKE", 1024, desc[10], "-4", 0,
  11390. count, start, 0);
  11391. #ifdef MULTI_VALUE_STATISTICS
  11392. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11393. #endif
  11394. wc_FreeSakkeKey(genKey);
  11395. wc_ecc_del_point(rsk);
  11396. exit:
  11397. XFREE(iTable, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11398. XFREE(table, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
  11399. WC_FREE_VAR(genKey, HEAP_HINT);
  11400. }
  11401. #endif /* WOLFCRYPT_SAKKE_CLIENT */
  11402. #endif /* WOLFCRYPT_HAVE_SAKKE */
  11403. #ifdef HAVE_FALCON
  11404. void bench_falconKeySign(byte level)
  11405. {
  11406. int ret = 0;
  11407. falcon_key key;
  11408. double start;
  11409. int i, count;
  11410. byte sig[FALCON_MAX_SIG_SIZE];
  11411. byte msg[512];
  11412. word32 x = 0;
  11413. const char**desc = bench_desc_words[lng_index];
  11414. DECLARE_MULTI_VALUE_STATS_VARS()
  11415. ret = wc_falcon_init(&key);
  11416. if (ret != 0) {
  11417. printf("wc_falcon_init failed %d\n", ret);
  11418. return;
  11419. }
  11420. ret = wc_falcon_set_level(&key, level);
  11421. if (ret != 0) {
  11422. printf("wc_falcon_set_level failed %d\n", ret);
  11423. }
  11424. if (ret == 0) {
  11425. if (level == 1) {
  11426. ret = wc_falcon_import_private_key(bench_falcon_level1_key,
  11427. sizeof_bench_falcon_level1_key,
  11428. NULL, 0, &key);
  11429. }
  11430. else {
  11431. ret = wc_falcon_import_private_key(bench_falcon_level5_key,
  11432. sizeof_bench_falcon_level5_key,
  11433. NULL, 0, &key);
  11434. }
  11435. if (ret != 0) {
  11436. printf("wc_falcon_import_private_key failed %d\n", ret);
  11437. }
  11438. }
  11439. /* make dummy msg */
  11440. for (i = 0; i < (int)sizeof(msg); i++) {
  11441. msg[i] = (byte)i;
  11442. }
  11443. bench_stats_start(&count, &start);
  11444. do {
  11445. for (i = 0; i < agreeTimes; i++) {
  11446. if (ret == 0) {
  11447. if (level == 1) {
  11448. x = FALCON_LEVEL1_SIG_SIZE;
  11449. }
  11450. else {
  11451. x = FALCON_LEVEL5_SIG_SIZE;
  11452. }
  11453. ret = wc_falcon_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  11454. if (ret != 0) {
  11455. printf("wc_falcon_sign_msg failed\n");
  11456. }
  11457. }
  11458. RECORD_MULTI_VALUE_STATS();
  11459. }
  11460. count += i;
  11461. } while (bench_stats_check(start)
  11462. #ifdef MULTI_VALUE_STATISTICS
  11463. || runs < minimum_runs
  11464. #endif
  11465. );
  11466. if (ret == 0) {
  11467. bench_stats_asym_finish("FALCON", level, desc[4], 0,
  11468. count, start, ret);
  11469. #ifdef MULTI_VALUE_STATISTICS
  11470. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11471. #endif
  11472. }
  11473. RESET_MULTI_VALUE_STATS_VARS();
  11474. bench_stats_start(&count, &start);
  11475. do {
  11476. for (i = 0; i < agreeTimes; i++) {
  11477. if (ret == 0) {
  11478. int verify = 0;
  11479. ret = wc_falcon_verify_msg(sig, x, msg, sizeof(msg), &verify,
  11480. &key);
  11481. if (ret != 0 || verify != 1) {
  11482. printf("wc_falcon_verify_msg failed %d, verify %d\n",
  11483. ret, verify);
  11484. ret = -1;
  11485. }
  11486. }
  11487. RECORD_MULTI_VALUE_STATS();
  11488. }
  11489. count += i;
  11490. } while (bench_stats_check(start)
  11491. #ifdef MULTI_VALUE_STATISTICS
  11492. || runs < minimum_runs
  11493. #endif
  11494. );
  11495. if (ret == 0) {
  11496. bench_stats_asym_finish("FALCON", level, desc[5],
  11497. 0, count, start, ret);
  11498. #ifdef MULTI_VALUE_STATISTICS
  11499. bench_multi_value_stats(max, min, sum, squareSum, runs);
  11500. #endif
  11501. }
  11502. wc_falcon_free(&key);
  11503. }
  11504. #endif /* HAVE_FALCON */
  11505. #ifdef HAVE_DILITHIUM
  11506. #if defined(WOLFSSL_DILITHIUM_NO_SIGN) && !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  11507. #ifndef WOLFSSL_NO_ML_DSA_44
  11508. static const unsigned char bench_dilithium_level2_sig[] = {
  11509. 0x5e, 0xc1, 0xce, 0x0e, 0x31, 0xea, 0x10, 0x52, 0xa3, 0x7a,
  11510. 0xfe, 0x4d, 0xac, 0x07, 0x89, 0x5a, 0x45, 0xbd, 0x5a, 0xe5,
  11511. 0x22, 0xed, 0x98, 0x4d, 0x2f, 0xc8, 0x27, 0x00, 0x99, 0x40,
  11512. 0x00, 0x79, 0xcd, 0x93, 0x27, 0xd0, 0x40, 0x33, 0x79, 0x4f,
  11513. 0xe5, 0x16, 0x89, 0x9f, 0xbd, 0xa6, 0x3f, 0xdd, 0x68, 0x74,
  11514. 0x73, 0xc3, 0x97, 0x54, 0x11, 0x1d, 0xc8, 0xb8, 0xc8, 0xfd,
  11515. 0x3a, 0xbe, 0xca, 0x17, 0x0f, 0x10, 0x6d, 0x89, 0x6d, 0xe0,
  11516. 0xb2, 0xff, 0x3b, 0xe5, 0xa1, 0x75, 0xea, 0x35, 0x16, 0xa3,
  11517. 0x0c, 0x6e, 0x4a, 0x7b, 0xdb, 0x28, 0xc6, 0x2a, 0x76, 0x0e,
  11518. 0x78, 0x78, 0xa0, 0x4f, 0x4e, 0xf8, 0x99, 0xff, 0xe7, 0x47,
  11519. 0x7e, 0xc4, 0x62, 0xa7, 0xb4, 0xb9, 0x2b, 0xc1, 0xc7, 0xd0,
  11520. 0x00, 0xb6, 0xaa, 0xa7, 0x37, 0xd5, 0x1e, 0x19, 0xc4, 0xc4,
  11521. 0x59, 0x2f, 0xa5, 0x09, 0xa3, 0xda, 0x5d, 0xd4, 0x48, 0x64,
  11522. 0x16, 0x0e, 0x92, 0xdf, 0x61, 0xb7, 0x25, 0x3b, 0x90, 0x5a,
  11523. 0x08, 0xb5, 0x88, 0xe8, 0x64, 0x80, 0x63, 0xee, 0xbf, 0x59,
  11524. 0x0f, 0x4a, 0x48, 0x1e, 0x77, 0xa9, 0x46, 0xc6, 0x9c, 0x0b,
  11525. 0x83, 0xad, 0xb5, 0xbf, 0xb5, 0x5b, 0x99, 0xf3, 0x55, 0xe8,
  11526. 0xe5, 0xe7, 0x5c, 0x12, 0xac, 0x06, 0x06, 0xe0, 0xc0, 0x32,
  11527. 0x5d, 0xb6, 0x9f, 0x2b, 0x8e, 0x19, 0x5c, 0x2a, 0x58, 0xbb,
  11528. 0x37, 0xf1, 0x68, 0x56, 0x8b, 0x74, 0x94, 0x58, 0x48, 0x28,
  11529. 0xee, 0xf7, 0x0a, 0x8f, 0xad, 0x43, 0x67, 0xe1, 0xa3, 0x8c,
  11530. 0x3b, 0x35, 0x48, 0xcc, 0x52, 0x14, 0x36, 0x99, 0x18, 0x71,
  11531. 0x1c, 0xb2, 0xfc, 0x82, 0xda, 0xac, 0xd5, 0x55, 0x0a, 0x77,
  11532. 0x44, 0x6a, 0x48, 0xed, 0xfc, 0x5a, 0x68, 0xa6, 0x4d, 0x65,
  11533. 0xe7, 0x30, 0xaa, 0x23, 0x66, 0x84, 0xdf, 0x83, 0xf1, 0x17,
  11534. 0x5c, 0x46, 0xfe, 0x63, 0xcb, 0xc3, 0x6e, 0x4e, 0x47, 0x8d,
  11535. 0x30, 0x48, 0x06, 0xda, 0x97, 0x6b, 0x04, 0x5d, 0x44, 0xf3,
  11536. 0xb7, 0x2a, 0x6d, 0x2b, 0xbb, 0xcd, 0x97, 0x4e, 0x26, 0x8e,
  11537. 0xc9, 0x03, 0x0b, 0x5d, 0x68, 0xed, 0x81, 0xf7, 0x19, 0x61,
  11538. 0x81, 0xe9, 0xac, 0x3a, 0x35, 0xcd, 0xe8, 0xfd, 0x99, 0xdb,
  11539. 0x89, 0x83, 0x7d, 0x23, 0x6a, 0xc1, 0xc1, 0x10, 0xe9, 0xd3,
  11540. 0xfa, 0x9e, 0x5a, 0xcd, 0x73, 0xa3, 0x0a, 0x37, 0xa3, 0x12,
  11541. 0xef, 0x72, 0xa2, 0x28, 0xd4, 0x3d, 0x67, 0x53, 0x24, 0x0d,
  11542. 0x61, 0x98, 0xbb, 0x07, 0xf3, 0xa7, 0x79, 0x22, 0x74, 0x57,
  11543. 0x99, 0xe8, 0x7a, 0xbf, 0x90, 0x84, 0xa2, 0x6b, 0x29, 0x34,
  11544. 0xac, 0xc9, 0xff, 0x67, 0x82, 0xd0, 0xd2, 0x7d, 0x69, 0xc0,
  11545. 0xf3, 0xd7, 0x4b, 0x5c, 0xf2, 0xa8, 0x53, 0x8b, 0x78, 0x57,
  11546. 0xfc, 0x74, 0xf5, 0x81, 0x6e, 0xc2, 0x5b, 0x32, 0x52, 0x9e,
  11547. 0x58, 0x84, 0xa1, 0x71, 0xd5, 0x8c, 0xf5, 0x16, 0x36, 0x4d,
  11548. 0x11, 0xd4, 0xb5, 0xc2, 0x05, 0xc4, 0x03, 0xce, 0x83, 0xea,
  11549. 0x0b, 0x6a, 0x2e, 0xf6, 0x28, 0x5e, 0xb2, 0x40, 0x8c, 0xa3,
  11550. 0x6a, 0xc7, 0xee, 0x04, 0x54, 0x93, 0x0f, 0x3b, 0xf9, 0x57,
  11551. 0x92, 0x00, 0xf1, 0xc7, 0x1b, 0x48, 0x63, 0xcb, 0xd3, 0xdd,
  11552. 0x40, 0x90, 0x46, 0xb0, 0x87, 0x2a, 0xb8, 0xec, 0xbc, 0x07,
  11553. 0x09, 0x83, 0x25, 0xb1, 0x88, 0x2c, 0xa0, 0x0a, 0x40, 0x4f,
  11554. 0xfd, 0xec, 0xfd, 0xbe, 0x18, 0xae, 0xdd, 0x83, 0x89, 0x83,
  11555. 0x2d, 0x10, 0xb4, 0x14, 0x30, 0xac, 0x6c, 0xd9, 0xc9, 0xaa,
  11556. 0xbc, 0xdb, 0x5e, 0x14, 0xab, 0x19, 0x64, 0xaa, 0xb1, 0x9c,
  11557. 0xc3, 0xf5, 0xdc, 0x2b, 0xcd, 0x26, 0x0b, 0x81, 0x1a, 0x0e,
  11558. 0x0a, 0xd6, 0x39, 0x79, 0x10, 0x06, 0xbf, 0xe0, 0xc1, 0x8b,
  11559. 0x20, 0x24, 0x90, 0x8b, 0x0f, 0xa4, 0x2d, 0x2d, 0x46, 0x2a,
  11560. 0xd4, 0xf3, 0xa9, 0x58, 0x4b, 0xd9, 0xa6, 0x6c, 0x75, 0x3d,
  11561. 0xbc, 0x36, 0x76, 0x7f, 0xef, 0x1b, 0xa1, 0x41, 0xba, 0xd0,
  11562. 0xfe, 0x16, 0x19, 0xc3, 0x92, 0xe3, 0x59, 0x07, 0x3f, 0x48,
  11563. 0x11, 0x70, 0xe0, 0x8a, 0xff, 0x97, 0xbc, 0x71, 0xd5, 0xb9,
  11564. 0x4a, 0x9b, 0x4c, 0xb8, 0x4b, 0x50, 0xd6, 0x43, 0xe8, 0x84,
  11565. 0x0a, 0x95, 0xd0, 0x20, 0x28, 0xd3, 0x20, 0x4a, 0x0e, 0x1b,
  11566. 0xe6, 0x5d, 0x2f, 0x0c, 0xdb, 0x76, 0xab, 0xa3, 0xc2, 0xad,
  11567. 0xd5, 0x86, 0xae, 0xb9, 0x26, 0xb2, 0x5d, 0x72, 0x27, 0xbb,
  11568. 0xec, 0x23, 0x9f, 0x42, 0x90, 0x58, 0xe1, 0xf8, 0xe9, 0x63,
  11569. 0xdf, 0x1a, 0x46, 0x53, 0x65, 0x05, 0xfb, 0x20, 0x21, 0xa6,
  11570. 0x64, 0xc8, 0x5c, 0x67, 0x6b, 0x41, 0x6c, 0x04, 0x34, 0xeb,
  11571. 0x05, 0x71, 0xeb, 0xbe, 0xed, 0x6d, 0xa2, 0x96, 0x67, 0x45,
  11572. 0xe7, 0x47, 0x22, 0x64, 0xaf, 0x82, 0xf8, 0x78, 0x0e, 0xe6,
  11573. 0xa1, 0x4a, 0x2d, 0x82, 0x1e, 0xd0, 0xc2, 0x79, 0x4e, 0x29,
  11574. 0x89, 0xd9, 0xf3, 0x3f, 0xb6, 0xc4, 0xee, 0x69, 0xb2, 0x8f,
  11575. 0x8b, 0xd9, 0x13, 0xd9, 0x6e, 0x3a, 0xc5, 0x9f, 0xdf, 0x25,
  11576. 0xb7, 0xc3, 0x16, 0xb8, 0xa2, 0x85, 0x17, 0xae, 0xe9, 0x95,
  11577. 0x5d, 0xb8, 0x1d, 0x21, 0xbb, 0xd9, 0x38, 0x11, 0x8f, 0x44,
  11578. 0xea, 0xe8, 0x4c, 0x91, 0x82, 0xf5, 0x45, 0xee, 0x8f, 0xf5,
  11579. 0x6a, 0x0d, 0x08, 0xe7, 0x6b, 0xb0, 0x91, 0xd5, 0x42, 0x17,
  11580. 0x8c, 0x37, 0x6a, 0x5a, 0x0a, 0x87, 0x53, 0x76, 0xc3, 0x59,
  11581. 0x35, 0x13, 0x1c, 0xf1, 0x72, 0x2c, 0x2b, 0xb2, 0x9e, 0xda,
  11582. 0x10, 0x2a, 0xce, 0x38, 0xb4, 0x67, 0x8c, 0x4b, 0x08, 0xa1,
  11583. 0xb6, 0xa3, 0x08, 0x9c, 0xeb, 0xd8, 0x93, 0x1b, 0x29, 0x5a,
  11584. 0xa7, 0x03, 0x17, 0x7e, 0xec, 0x58, 0x6b, 0x5b, 0xc5, 0x46,
  11585. 0x03, 0x33, 0x7f, 0x0e, 0x93, 0x9a, 0xdd, 0xb5, 0x89, 0xb1,
  11586. 0x16, 0x4c, 0xa7, 0xd8, 0x0e, 0x73, 0xd8, 0xc3, 0xd2, 0x36,
  11587. 0x85, 0x66, 0xcb, 0x5b, 0x64, 0xf2, 0xdc, 0xba, 0x39, 0xcc,
  11588. 0xa5, 0xe0, 0x9b, 0xaa, 0x2a, 0x95, 0x6d, 0xdc, 0x49, 0xde,
  11589. 0x3b, 0x61, 0xa2, 0x3b, 0x1f, 0xed, 0x32, 0xfa, 0x10, 0xe4,
  11590. 0x88, 0x59, 0xca, 0x5a, 0xe4, 0xf9, 0x5e, 0xe2, 0xca, 0x21,
  11591. 0x5a, 0xdc, 0x02, 0x73, 0x7a, 0xc8, 0x90, 0x7a, 0x8e, 0x91,
  11592. 0x19, 0x04, 0x53, 0x3c, 0x50, 0x15, 0x8a, 0x84, 0x93, 0x8f,
  11593. 0xac, 0x99, 0x82, 0xdd, 0xc6, 0xce, 0xfb, 0x18, 0x84, 0x29,
  11594. 0x2a, 0x8d, 0xa2, 0xc5, 0x7f, 0x87, 0xce, 0x4c, 0xf5, 0xdf,
  11595. 0x73, 0xd2, 0xba, 0xc2, 0x4f, 0xe3, 0x74, 0xa5, 0x8f, 0xc3,
  11596. 0xf4, 0x99, 0xd1, 0xe8, 0x4e, 0xb8, 0xe0, 0x2e, 0xef, 0xd6,
  11597. 0x87, 0x70, 0xcf, 0x45, 0x3b, 0xff, 0x03, 0xfd, 0x59, 0x7f,
  11598. 0x7c, 0xd0, 0x4e, 0x49, 0xf7, 0xd5, 0x08, 0xd9, 0x06, 0x53,
  11599. 0x90, 0x0a, 0x5a, 0x1b, 0x2e, 0xf5, 0xb0, 0x85, 0xb6, 0xb6,
  11600. 0x61, 0xa5, 0x71, 0x47, 0xbf, 0x4a, 0xf6, 0xae, 0x9a, 0x19,
  11601. 0x6c, 0xd8, 0x2d, 0x9b, 0xb4, 0x40, 0x9e, 0x15, 0x77, 0x2e,
  11602. 0x7e, 0xe9, 0xb4, 0x3d, 0x0f, 0x1b, 0xb5, 0x1c, 0xc2, 0x58,
  11603. 0x4e, 0x4b, 0xf6, 0x53, 0x9e, 0x6f, 0x09, 0x55, 0xa0, 0xb8,
  11604. 0x73, 0x11, 0x64, 0x70, 0x54, 0xb4, 0xcb, 0xb7, 0x27, 0xe5,
  11605. 0xdf, 0x58, 0x67, 0x5b, 0xc0, 0xd6, 0xf5, 0x64, 0xa6, 0x66,
  11606. 0x6d, 0xdf, 0xd8, 0xf8, 0xd6, 0x85, 0xba, 0xba, 0x30, 0xa7,
  11607. 0xca, 0x34, 0xf4, 0x9a, 0xba, 0x0a, 0xfb, 0x0e, 0xa0, 0x65,
  11608. 0x98, 0x78, 0xee, 0xaa, 0x14, 0x6a, 0x99, 0x77, 0x67, 0xad,
  11609. 0x01, 0x95, 0x5e, 0x50, 0x22, 0xe9, 0x74, 0x95, 0xa7, 0x13,
  11610. 0x3f, 0xdd, 0xa6, 0x69, 0x64, 0xf6, 0x50, 0x06, 0x6d, 0xba,
  11611. 0x90, 0x5a, 0x8c, 0x81, 0xa0, 0xda, 0x55, 0xe9, 0x97, 0x0e,
  11612. 0xd7, 0x10, 0x8e, 0x1f, 0x23, 0x65, 0xd9, 0x14, 0xd4, 0xde,
  11613. 0xa5, 0xf9, 0xec, 0xb6, 0xad, 0x65, 0xce, 0x0b, 0x1b, 0x0a,
  11614. 0x4c, 0x7d, 0xb0, 0x97, 0xa6, 0xfe, 0x67, 0xfb, 0x4f, 0x8f,
  11615. 0x00, 0x92, 0xb6, 0x0d, 0x20, 0x78, 0x65, 0x1d, 0x9a, 0x56,
  11616. 0x57, 0xc6, 0x15, 0x88, 0xba, 0x55, 0x02, 0x7a, 0x9a, 0xac,
  11617. 0x50, 0x4c, 0xc7, 0x9e, 0x66, 0x8b, 0xfc, 0xf3, 0x67, 0x48,
  11618. 0x07, 0xbf, 0x84, 0x94, 0x9b, 0x22, 0x2a, 0xae, 0x1b, 0x25,
  11619. 0xe9, 0x94, 0x06, 0xa7, 0xe8, 0x61, 0x52, 0x89, 0xdc, 0x93,
  11620. 0x6e, 0x89, 0xdc, 0x30, 0x6e, 0xd9, 0xee, 0xcb, 0x12, 0x38,
  11621. 0x58, 0x9d, 0x8b, 0xc5, 0x05, 0x2c, 0x50, 0x4e, 0xc8, 0xc2,
  11622. 0xe0, 0x65, 0xb6, 0x49, 0xc4, 0xf0, 0x1e, 0x5c, 0x8e, 0x3c,
  11623. 0xe9, 0x77, 0xd2, 0x9e, 0xa8, 0xd5, 0xf5, 0xd9, 0xc5, 0xad,
  11624. 0x5b, 0x74, 0x48, 0x08, 0x3a, 0x30, 0x84, 0x57, 0x71, 0x1e,
  11625. 0x69, 0x45, 0x09, 0xdd, 0xea, 0x62, 0xec, 0x7c, 0xa3, 0xf9,
  11626. 0x92, 0xee, 0x16, 0xdc, 0xe5, 0x9d, 0xcf, 0xb7, 0x08, 0x51,
  11627. 0x8a, 0x76, 0x3a, 0x23, 0x94, 0x50, 0x8e, 0x4d, 0x3a, 0xea,
  11628. 0xf3, 0xc1, 0x53, 0x2c, 0x65, 0x9c, 0x36, 0x8c, 0x10, 0xe3,
  11629. 0x9c, 0x01, 0xa4, 0xe6, 0x45, 0x77, 0xa6, 0x5d, 0x7e, 0x37,
  11630. 0x31, 0x95, 0x2f, 0xec, 0x61, 0x92, 0x69, 0x65, 0x53, 0x54,
  11631. 0x6d, 0xbe, 0x9e, 0x5a, 0x68, 0x12, 0xc4, 0xe7, 0xe4, 0x06,
  11632. 0x51, 0x5a, 0xc0, 0x63, 0xb9, 0x69, 0xb8, 0x3c, 0xd8, 0xae,
  11633. 0x8b, 0xff, 0x96, 0x4d, 0x55, 0xce, 0x25, 0x2b, 0x8b, 0x89,
  11634. 0xc9, 0x3a, 0x16, 0x48, 0x2a, 0x73, 0xb2, 0x70, 0x8b, 0x62,
  11635. 0xd5, 0xb1, 0xa0, 0x30, 0xe5, 0x46, 0xab, 0x8b, 0xc3, 0xeb,
  11636. 0x37, 0x2f, 0xbd, 0xb8, 0x4e, 0x6c, 0x30, 0xdc, 0x6c, 0x8a,
  11637. 0xf1, 0x89, 0x06, 0xce, 0x64, 0x0a, 0x3e, 0xb2, 0x16, 0x31,
  11638. 0xa1, 0xe4, 0x4b, 0x98, 0xe7, 0xf1, 0x99, 0x76, 0x00, 0x5f,
  11639. 0xd2, 0xd3, 0x30, 0xf0, 0xbf, 0xa7, 0x4a, 0xf6, 0x9e, 0xa5,
  11640. 0x75, 0x74, 0x78, 0xfe, 0xec, 0x72, 0x7c, 0x89, 0xe9, 0xf6,
  11641. 0x0d, 0x7e, 0x15, 0xd6, 0xd8, 0x79, 0x85, 0x3c, 0xcf, 0xb0,
  11642. 0x21, 0xc8, 0x9c, 0x54, 0x87, 0x63, 0xb3, 0x05, 0xbb, 0x8a,
  11643. 0x02, 0xe4, 0x79, 0xdc, 0xa1, 0xa2, 0xd3, 0x19, 0xd8, 0x86,
  11644. 0xff, 0x8a, 0x0e, 0x82, 0x89, 0xaf, 0xaa, 0x62, 0x2e, 0xd4,
  11645. 0xb2, 0xd0, 0x5d, 0x0d, 0x4f, 0x2a, 0xda, 0x0e, 0x9f, 0x8a,
  11646. 0x2b, 0x32, 0xe9, 0x09, 0xf5, 0x55, 0x51, 0xe7, 0xd5, 0x69,
  11647. 0x12, 0xdd, 0x33, 0x6b, 0x3d, 0xd7, 0xe9, 0xfd, 0xb2, 0xa7,
  11648. 0xf5, 0x97, 0x2a, 0x6d, 0x89, 0x30, 0x65, 0x2a, 0x0d, 0xf2,
  11649. 0x00, 0x81, 0xbe, 0xfb, 0xd9, 0xd7, 0x1b, 0xc2, 0x48, 0x7a,
  11650. 0x22, 0x30, 0xae, 0x35, 0xf6, 0x32, 0x41, 0x9d, 0xd9, 0x12,
  11651. 0xb3, 0xa7, 0x6d, 0xba, 0x74, 0x93, 0x2d, 0x0d, 0xb2, 0xb6,
  11652. 0xdc, 0xa9, 0x98, 0x5b, 0x3b, 0xaa, 0x2b, 0x47, 0x06, 0xc4,
  11653. 0x36, 0xfd, 0x04, 0x10, 0x94, 0x61, 0x61, 0x47, 0x1c, 0x02,
  11654. 0x54, 0x85, 0x4a, 0xcb, 0x75, 0x6b, 0x75, 0xf5, 0xb4, 0x61,
  11655. 0x26, 0xb3, 0x12, 0x43, 0x31, 0x55, 0xb5, 0xda, 0x4b, 0xb5,
  11656. 0x11, 0xb4, 0xb8, 0xfb, 0x0a, 0xd9, 0xa7, 0x0e, 0x9f, 0x2a,
  11657. 0x74, 0x01, 0xf6, 0x1a, 0x33, 0x10, 0x9e, 0x66, 0xff, 0x82,
  11658. 0xfa, 0xa9, 0xa4, 0xa0, 0x9b, 0x25, 0x2d, 0x16, 0xbf, 0x60,
  11659. 0x0d, 0x87, 0xea, 0x94, 0xad, 0xdd, 0xc4, 0xd0, 0xa8, 0xdd,
  11660. 0x2d, 0xc7, 0xc8, 0xac, 0x39, 0x9e, 0x87, 0x69, 0xc4, 0x3a,
  11661. 0xbc, 0x28, 0x7e, 0x36, 0x69, 0xfd, 0x20, 0x25, 0xac, 0xa3,
  11662. 0xa7, 0x37, 0x96, 0xe9, 0x8a, 0x65, 0xe4, 0xb0, 0x2a, 0x61,
  11663. 0x23, 0x28, 0x64, 0xff, 0x17, 0x6c, 0x36, 0x9e, 0x0a, 0xba,
  11664. 0xe4, 0x4b, 0xeb, 0x84, 0x24, 0x20, 0x57, 0x0f, 0x34, 0x05,
  11665. 0x95, 0x56, 0xc3, 0x2f, 0x2b, 0xf0, 0x36, 0xef, 0xca, 0x68,
  11666. 0xfe, 0x78, 0xf8, 0x98, 0x09, 0x4a, 0x25, 0xcc, 0x17, 0xbe,
  11667. 0x05, 0x00, 0xff, 0xf9, 0xa5, 0x5b, 0xe6, 0xaa, 0x5b, 0x56,
  11668. 0xb6, 0x89, 0x64, 0x9c, 0x16, 0x48, 0xe1, 0xcd, 0x67, 0x87,
  11669. 0xdd, 0xba, 0xbd, 0x02, 0x0d, 0xd8, 0xb4, 0xc9, 0x7c, 0x37,
  11670. 0x92, 0xd0, 0x39, 0x46, 0xd2, 0xc4, 0x78, 0x13, 0xf0, 0x76,
  11671. 0x45, 0x5f, 0xeb, 0x52, 0xd2, 0x3f, 0x61, 0x87, 0x34, 0x09,
  11672. 0xb7, 0x24, 0x4e, 0x93, 0xf3, 0xc5, 0x10, 0x19, 0x66, 0x66,
  11673. 0x3f, 0x15, 0xe3, 0x05, 0x55, 0x43, 0xb7, 0xf4, 0x62, 0x57,
  11674. 0xb4, 0xd9, 0xef, 0x46, 0x47, 0xb5, 0xfb, 0x79, 0xc9, 0x67,
  11675. 0xc5, 0xc3, 0x18, 0x91, 0x73, 0x75, 0xec, 0xd5, 0x68, 0x2b,
  11676. 0xf6, 0x42, 0xb4, 0xff, 0xfb, 0x27, 0x61, 0x77, 0x28, 0x10,
  11677. 0x6b, 0xce, 0x19, 0xad, 0x87, 0xc3, 0x85, 0xe3, 0x78, 0x00,
  11678. 0xdb, 0x21, 0xee, 0xd8, 0xfa, 0x9c, 0x81, 0x11, 0x97, 0xac,
  11679. 0xd0, 0x50, 0x89, 0x45, 0x23, 0xf6, 0x85, 0x7d, 0x60, 0xb2,
  11680. 0xad, 0x0c, 0x5d, 0xd8, 0x9e, 0xe4, 0xe1, 0x25, 0xb2, 0x13,
  11681. 0x1a, 0x54, 0x54, 0xfd, 0x7b, 0xab, 0x85, 0x20, 0xe8, 0xda,
  11682. 0x52, 0x0f, 0xac, 0x49, 0x70, 0xf1, 0x4c, 0x66, 0x74, 0x8c,
  11683. 0x87, 0x6e, 0xca, 0xc1, 0x0d, 0x92, 0xc0, 0xa8, 0x08, 0xfd,
  11684. 0x0f, 0x60, 0x55, 0xaf, 0x24, 0xcb, 0x04, 0xb7, 0xff, 0xa9,
  11685. 0xc5, 0x07, 0x26, 0xf6, 0xe2, 0x1e, 0x2f, 0xd1, 0x99, 0x6d,
  11686. 0xef, 0xc0, 0xdb, 0x5b, 0xf7, 0x06, 0x80, 0x92, 0x5f, 0x56,
  11687. 0x54, 0xdb, 0x2e, 0xba, 0x93, 0xb2, 0x94, 0xf2, 0xad, 0xbc,
  11688. 0x91, 0x6e, 0x4e, 0xce, 0x21, 0xc4, 0x8b, 0x18, 0xc4, 0xfc,
  11689. 0xab, 0xb4, 0x4f, 0xd7, 0xa2, 0xef, 0x55, 0x00, 0x6d, 0x34,
  11690. 0x17, 0x59, 0x8d, 0x79, 0x75, 0x02, 0xa3, 0x7a, 0x52, 0x57,
  11691. 0x5c, 0x26, 0xb9, 0xae, 0xd6, 0x19, 0x2e, 0x31, 0x02, 0x98,
  11692. 0x98, 0xe5, 0x3d, 0xc2, 0xa5, 0x56, 0xb6, 0x02, 0xae, 0x0d,
  11693. 0x3b, 0x35, 0x97, 0xd2, 0x43, 0x38, 0x8a, 0x65, 0xfa, 0x86,
  11694. 0x20, 0xb7, 0xb5, 0xb0, 0xda, 0x19, 0x01, 0x2f, 0x13, 0xb5,
  11695. 0x6d, 0xbd, 0xb2, 0x34, 0xa7, 0xff, 0xae, 0x7e, 0x8f, 0x98,
  11696. 0x1b, 0xc4, 0x27, 0xbd, 0xa9, 0x64, 0xdc, 0xab, 0x2a, 0xd2,
  11697. 0xb4, 0x27, 0xd0, 0x25, 0xdd, 0xff, 0xdc, 0x0a, 0x96, 0xd3,
  11698. 0x85, 0x3e, 0xc5, 0x11, 0x34, 0x60, 0xa2, 0x33, 0x92, 0x90,
  11699. 0xbb, 0x4c, 0x86, 0xdd, 0xd6, 0x1e, 0xcb, 0x0a, 0x17, 0xc6,
  11700. 0x87, 0x4e, 0x3e, 0x7a, 0x4b, 0xab, 0xef, 0x0a, 0x00, 0x3d,
  11701. 0x94, 0x34, 0x8b, 0x63, 0x36, 0xd9, 0xaf, 0x5d, 0x63, 0x40,
  11702. 0xbb, 0x32, 0x4b, 0x64, 0xf0, 0x31, 0x48, 0xdb, 0x44, 0x2b,
  11703. 0x48, 0x60, 0x6a, 0xea, 0xa4, 0x8c, 0xdd, 0xaf, 0x81, 0x3f,
  11704. 0x86, 0x81, 0x99, 0x7a, 0x98, 0xe1, 0xff, 0x21, 0x7a, 0x28,
  11705. 0xbc, 0x33, 0xe6, 0x4e, 0xb0, 0x85, 0x6b, 0xec, 0x11, 0x37,
  11706. 0x81, 0x7f, 0xf9, 0xdc, 0xbf, 0x1a, 0xa6, 0x6d, 0x4d, 0x0f,
  11707. 0x5b, 0x99, 0x73, 0xb8, 0xd2, 0x6e, 0x37, 0xf0, 0x71, 0xf1,
  11708. 0x1a, 0xc3, 0x5c, 0xea, 0x12, 0x5f, 0x2e, 0x85, 0x3f, 0xfd,
  11709. 0xd5, 0x87, 0x67, 0x9f, 0x67, 0x9f, 0xd7, 0xef, 0x9f, 0x81,
  11710. 0xa4, 0xbc, 0x63, 0x1d, 0x00, 0x81, 0xf6, 0x20, 0x77, 0xae,
  11711. 0x0b, 0x90, 0xe5, 0x9c, 0xa9, 0x44, 0xb5, 0xd7, 0xb1, 0x61,
  11712. 0x33, 0x4f, 0x75, 0xa9, 0xb7, 0xf4, 0xa4, 0x72, 0x9e, 0x72,
  11713. 0xec, 0x7b, 0xcd, 0x83, 0xb3, 0xd6, 0x22, 0x50, 0x50, 0x97,
  11714. 0x0f, 0x63, 0x0f, 0xe1, 0x15, 0xb3, 0x07, 0xb6, 0xa3, 0xfa,
  11715. 0x2f, 0xb5, 0xf3, 0x5b, 0x5d, 0x7f, 0x90, 0x20, 0xcd, 0x5f,
  11716. 0x40, 0x48, 0x87, 0x43, 0xfd, 0xa3, 0x69, 0xdc, 0xf8, 0x51,
  11717. 0x08, 0x67, 0xc2, 0x2d, 0xff, 0xfe, 0xbf, 0x85, 0x3e, 0x80,
  11718. 0xff, 0x91, 0x62, 0xc5, 0x83, 0xe0, 0x80, 0xeb, 0xce, 0xdc,
  11719. 0xff, 0xb1, 0xdb, 0x02, 0xb7, 0x01, 0x1e, 0xa6, 0xf0, 0x32,
  11720. 0xfb, 0x95, 0x6a, 0x47, 0x44, 0x84, 0x42, 0x6e, 0x3a, 0xb1,
  11721. 0xcf, 0xf9, 0x28, 0xb4, 0x3a, 0x8e, 0xa7, 0x8d, 0x48, 0x81,
  11722. 0x1c, 0x7e, 0xf5, 0x0b, 0x46, 0x7e, 0x92, 0x4e, 0xb9, 0xa8,
  11723. 0x36, 0xb8, 0x81, 0x6d, 0x8c, 0x70, 0x59, 0x33, 0x12, 0x61,
  11724. 0xbb, 0xe6, 0x10, 0x8a, 0xe4, 0xc1, 0x2c, 0x50, 0x12, 0xbf,
  11725. 0xd3, 0xc6, 0x3c, 0x53, 0x91, 0x50, 0x07, 0xc8, 0x85, 0x32,
  11726. 0x3c, 0xe1, 0x67, 0x99, 0x68, 0xc1, 0xf4, 0x74, 0x86, 0x35,
  11727. 0x8a, 0x6c, 0x75, 0x1d, 0x8f, 0x8a, 0x60, 0xe1, 0xc7, 0x59,
  11728. 0x4e, 0xb0, 0xe0, 0x45, 0x5a, 0x11, 0x05, 0x24, 0xa7, 0x8d,
  11729. 0x39, 0x93, 0x60, 0x4c, 0xc5, 0x9e, 0x8a, 0x70, 0xcc, 0x44,
  11730. 0x96, 0x92, 0xc8, 0xf7, 0x23, 0x14, 0xc7, 0xf4, 0x82, 0x9d,
  11731. 0x5b, 0x1c, 0x26, 0xd0, 0x3c, 0x76, 0x36, 0xe9, 0x98, 0x8a,
  11732. 0xbb, 0xe6, 0xa0, 0xad, 0xed, 0xf7, 0xd9, 0x06, 0x50, 0x67,
  11733. 0x79, 0x50, 0x4e, 0xd5, 0x80, 0x4e, 0x59, 0x72, 0x5d, 0x8b,
  11734. 0xcb, 0x86, 0x3b, 0x57, 0xc4, 0xb2, 0x3d, 0xbc, 0x35, 0x6d,
  11735. 0xb1, 0x50, 0xf5, 0x8c, 0xf2, 0x89, 0x72, 0x20, 0xd0, 0x47,
  11736. 0x68, 0x13, 0x42, 0x25, 0x1a, 0xb6, 0xc5, 0x07, 0xdf, 0x45,
  11737. 0x11, 0xa9, 0x05, 0x5d, 0xad, 0xf0, 0x49, 0x9e, 0x70, 0x78,
  11738. 0xed, 0xe7, 0xf9, 0x00, 0x1f, 0x62, 0x76, 0x47, 0xb5, 0x48,
  11739. 0x4f, 0x2c, 0x2e, 0xe3, 0x78, 0x6a, 0x44, 0x46, 0x1e, 0x6b,
  11740. 0x00, 0x74, 0x54, 0xb9, 0xd1, 0x4f, 0x6d, 0x45, 0xc1, 0xa6,
  11741. 0x45, 0x2e, 0x1a, 0xaf, 0x94, 0x3f, 0xd0, 0x72, 0x67, 0x0d,
  11742. 0x2e, 0xa9, 0x8d, 0x16, 0xc4, 0x05, 0x01, 0x07, 0x13, 0x1b,
  11743. 0x1c, 0x3d, 0x43, 0x71, 0x91, 0x95, 0x9a, 0xae, 0xaf, 0xc4,
  11744. 0xe5, 0xe6, 0xe9, 0xff, 0x02, 0x0c, 0x0f, 0x3e, 0x62, 0x67,
  11745. 0x68, 0x81, 0xc7, 0xd0, 0xd8, 0xdd, 0xe0, 0xf5, 0x0b, 0x25,
  11746. 0x35, 0x45, 0x4a, 0x4b, 0x63, 0x74, 0x79, 0x7e, 0x82, 0xa2,
  11747. 0xaf, 0xc6, 0xc7, 0xcc, 0xd2, 0xfa, 0x2a, 0x2d, 0x2f, 0x32,
  11748. 0x35, 0x38, 0x3f, 0x4c, 0x7f, 0x80, 0x81, 0x8b, 0x9b, 0x9c,
  11749. 0x9d, 0xa7, 0xa9, 0xcb, 0xe9, 0xf0, 0x00, 0x00, 0x00, 0x00,
  11750. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x20, 0x32, 0x46,
  11751. };
  11752. static const int sizeof_bench_dilithium_level2_sig =
  11753. sizeof(bench_dilithium_level2_sig);
  11754. #endif
  11755. #ifndef WOLFSSL_NO_ML_DSA_65
  11756. static const unsigned char bench_dilithium_level3_sig[] = {
  11757. 0x3e, 0xff, 0xf4, 0x48, 0x80, 0x2d, 0x88, 0x87, 0xf4, 0xcc,
  11758. 0xa4, 0x61, 0xe1, 0x27, 0x20, 0x55, 0x66, 0xc8, 0xfe, 0x3e,
  11759. 0xdd, 0xf5, 0x5c, 0x70, 0x6c, 0x54, 0xba, 0x50, 0x8a, 0xa2,
  11760. 0x4b, 0x88, 0xbc, 0xb8, 0x87, 0xf9, 0x4e, 0x50, 0x3a, 0x04,
  11761. 0x18, 0xb3, 0xf4, 0x5f, 0x77, 0x4a, 0x7e, 0xa8, 0xf5, 0xca,
  11762. 0x49, 0x00, 0xdc, 0x24, 0xaa, 0x05, 0x35, 0x0f, 0x34, 0xf7,
  11763. 0xbf, 0x09, 0xa6, 0xcf, 0x75, 0x37, 0x07, 0xcd, 0x07, 0x99,
  11764. 0x92, 0x1d, 0xc7, 0xc9, 0x17, 0x1c, 0xdd, 0x27, 0x8c, 0x66,
  11765. 0xf2, 0x8b, 0x75, 0xb0, 0x86, 0x2d, 0xbd, 0x51, 0x16, 0xc2,
  11766. 0x50, 0xe0, 0x7e, 0x0a, 0x21, 0x58, 0x93, 0x22, 0x06, 0xcb,
  11767. 0x85, 0x8b, 0xfd, 0x97, 0x61, 0xc0, 0xdb, 0xab, 0xfa, 0x4a,
  11768. 0x69, 0xef, 0x9c, 0xc1, 0x4e, 0xae, 0xb2, 0xb3, 0xa2, 0x74,
  11769. 0xa4, 0x94, 0x0a, 0xed, 0x39, 0x9e, 0xe8, 0x58, 0xeb, 0xfd,
  11770. 0x43, 0x05, 0x73, 0x38, 0xd6, 0xbb, 0xeb, 0xb9, 0x9d, 0x3b,
  11771. 0xf8, 0x85, 0xb4, 0x4b, 0x16, 0x5c, 0x9e, 0xfe, 0xb8, 0x13,
  11772. 0xf8, 0x68, 0x44, 0x90, 0x05, 0x61, 0xb3, 0xed, 0x6f, 0x47,
  11773. 0xc9, 0x50, 0xcf, 0x6c, 0xc0, 0xac, 0xdf, 0x4c, 0x4c, 0x1b,
  11774. 0x42, 0xce, 0x0a, 0x32, 0x69, 0xb0, 0xfd, 0x87, 0xef, 0xf3,
  11775. 0x9c, 0xcc, 0xba, 0x2f, 0x03, 0xd7, 0xdb, 0x76, 0xee, 0xa0,
  11776. 0x71, 0x4a, 0x80, 0xcb, 0x90, 0x9e, 0xbb, 0x8f, 0x00, 0x46,
  11777. 0x81, 0xe0, 0xde, 0xa6, 0x43, 0xb5, 0x37, 0x79, 0xf2, 0x35,
  11778. 0xce, 0x9e, 0xd2, 0xb1, 0x5b, 0xff, 0x91, 0xfb, 0x98, 0xc1,
  11779. 0xe1, 0x66, 0x2c, 0x00, 0x1b, 0x89, 0xf2, 0x57, 0x81, 0x73,
  11780. 0x7e, 0x9f, 0x8d, 0x50, 0xd0, 0xe0, 0xe3, 0x93, 0xf2, 0x87,
  11781. 0x41, 0x64, 0x6c, 0xb7, 0x09, 0x60, 0x91, 0x4e, 0x0b, 0xbe,
  11782. 0xbe, 0xd4, 0x98, 0xfa, 0x14, 0x8c, 0x46, 0x09, 0xfa, 0xaa,
  11783. 0x82, 0xd6, 0xdd, 0x65, 0x93, 0x39, 0x45, 0x50, 0x90, 0x10,
  11784. 0xae, 0x1b, 0xff, 0xab, 0x7e, 0x86, 0xda, 0xb9, 0x4d, 0xf1,
  11785. 0xc2, 0x00, 0x54, 0x66, 0xee, 0x40, 0xc0, 0x56, 0x2f, 0xe8,
  11786. 0x43, 0x89, 0xbb, 0xb8, 0x59, 0x24, 0x63, 0x45, 0x9a, 0xde,
  11787. 0x08, 0xf3, 0x16, 0x94, 0xd2, 0x8d, 0xee, 0xf9, 0xbe, 0x4f,
  11788. 0x29, 0xe1, 0x4b, 0x5e, 0x2b, 0x14, 0xef, 0x66, 0xe2, 0x12,
  11789. 0xf8, 0x87, 0x2e, 0xb1, 0x75, 0x8b, 0x21, 0xb5, 0x8f, 0x8e,
  11790. 0xc5, 0x0e, 0x60, 0x27, 0x15, 0xbd, 0x72, 0xe4, 0x26, 0x4e,
  11791. 0x62, 0x7d, 0x3a, 0x46, 0x49, 0x93, 0xa9, 0x52, 0x7f, 0xc2,
  11792. 0x27, 0xb9, 0x55, 0x6a, 0x45, 0x9f, 0x2c, 0x7a, 0x5a, 0xc9,
  11793. 0xf4, 0x55, 0xaf, 0x49, 0xb3, 0xd5, 0xc0, 0x84, 0xdb, 0x89,
  11794. 0x5f, 0x21, 0x04, 0xf5, 0x4c, 0x66, 0x1e, 0x2e, 0x69, 0xdf,
  11795. 0x5b, 0x14, 0x60, 0x89, 0x84, 0xf8, 0xa3, 0xaf, 0xdf, 0xb9,
  11796. 0x18, 0x5e, 0xbf, 0x81, 0x95, 0x9a, 0x5e, 0x4f, 0x24, 0x45,
  11797. 0xad, 0xab, 0xe2, 0x36, 0x7c, 0x19, 0xde, 0xc0, 0xf4, 0x1a,
  11798. 0x42, 0xb2, 0xc2, 0x58, 0x2f, 0x5f, 0xd0, 0x2e, 0x28, 0x33,
  11799. 0x59, 0x75, 0xc2, 0xde, 0x41, 0xe3, 0x9b, 0x85, 0x46, 0xad,
  11800. 0x6d, 0xf1, 0x06, 0xf0, 0x6a, 0xb9, 0xed, 0x71, 0x7b, 0xfd,
  11801. 0xf1, 0xc4, 0x56, 0xd8, 0xb3, 0x1a, 0x5f, 0x04, 0xae, 0xe8,
  11802. 0xce, 0xde, 0xa1, 0x6d, 0x46, 0x2a, 0x4f, 0x62, 0xee, 0x25,
  11803. 0xdf, 0x22, 0x21, 0xb2, 0x8f, 0x5f, 0x26, 0x33, 0x5a, 0xdd,
  11804. 0xbe, 0x08, 0xb3, 0x93, 0x16, 0x16, 0xad, 0x2e, 0x00, 0xb8,
  11805. 0x14, 0x0c, 0x10, 0xa3, 0x29, 0x89, 0x1f, 0xd7, 0x06, 0x7a,
  11806. 0x09, 0xf3, 0x84, 0xf9, 0x18, 0x04, 0x56, 0x2f, 0x7f, 0xbd,
  11807. 0x8e, 0x12, 0xdf, 0x4d, 0x58, 0x5c, 0x1d, 0x81, 0x0c, 0x7d,
  11808. 0x62, 0x02, 0xe0, 0xf9, 0x1b, 0x69, 0xe9, 0x38, 0x45, 0x84,
  11809. 0x2d, 0x9a, 0x4a, 0x3d, 0x7b, 0x48, 0xd5, 0x0d, 0x76, 0xba,
  11810. 0xff, 0x20, 0x00, 0xf8, 0x42, 0x7f, 0xd2, 0x25, 0x70, 0x90,
  11811. 0x88, 0xb3, 0x98, 0xac, 0xe9, 0xd9, 0xac, 0x58, 0xa6, 0x49,
  11812. 0xcc, 0x93, 0xa5, 0x04, 0x0c, 0x68, 0x53, 0x64, 0x72, 0x8c,
  11813. 0xfc, 0x8d, 0x61, 0xeb, 0x3f, 0x93, 0x8b, 0x85, 0x98, 0x05,
  11814. 0xce, 0x06, 0xd7, 0xbf, 0xbb, 0xa5, 0x22, 0xda, 0xe9, 0x8a,
  11815. 0x29, 0x30, 0x5e, 0x82, 0xe4, 0x46, 0x7c, 0x36, 0x5e, 0xf5,
  11816. 0xc7, 0xe3, 0x09, 0xdf, 0x20, 0x76, 0x73, 0x33, 0x31, 0x75,
  11817. 0xc2, 0x99, 0xe9, 0x74, 0x43, 0x82, 0xb1, 0xeb, 0x74, 0x6f,
  11818. 0xad, 0x59, 0x48, 0x12, 0xa0, 0x24, 0xe3, 0x38, 0x48, 0x61,
  11819. 0x0c, 0xf6, 0x38, 0x83, 0x3a, 0xcd, 0xd6, 0x45, 0x10, 0x0e,
  11820. 0x09, 0x79, 0x31, 0x30, 0x80, 0xfb, 0x34, 0x60, 0x1e, 0x72,
  11821. 0x98, 0xe9, 0x5c, 0xbf, 0xab, 0x21, 0x7f, 0xa3, 0x19, 0x7e,
  11822. 0x8c, 0xa9, 0xa7, 0xfc, 0x25, 0xe0, 0x8e, 0x6d, 0xa1, 0xb9,
  11823. 0x7b, 0x5b, 0x37, 0x33, 0x96, 0xd8, 0x6e, 0x7a, 0xce, 0xa6,
  11824. 0x1a, 0xbd, 0xe6, 0x6e, 0x62, 0xc4, 0x8c, 0x69, 0xfe, 0xe4,
  11825. 0xcb, 0x0a, 0xa1, 0x6c, 0x66, 0x0e, 0x1a, 0x5e, 0xb9, 0xd1,
  11826. 0x4a, 0xa3, 0x91, 0x39, 0xcf, 0x85, 0x07, 0x5b, 0xaf, 0x99,
  11827. 0x11, 0xca, 0xee, 0x6f, 0x2e, 0x33, 0xda, 0x60, 0xbf, 0xd6,
  11828. 0xa0, 0x7a, 0xdb, 0x91, 0x13, 0xb7, 0xa3, 0x5d, 0x0e, 0x1e,
  11829. 0x3b, 0xf9, 0x7a, 0x3e, 0x4f, 0x8d, 0xb3, 0x81, 0xe8, 0x0c,
  11830. 0x4d, 0x48, 0x61, 0x06, 0x14, 0x0f, 0x3e, 0x33, 0x9e, 0xea,
  11831. 0xa6, 0xd8, 0xd8, 0x4d, 0x9b, 0x00, 0x34, 0x0d, 0x31, 0x62,
  11832. 0x54, 0x93, 0x04, 0xd2, 0x02, 0x21, 0x38, 0x91, 0x58, 0xca,
  11833. 0x77, 0xd3, 0x6c, 0xd1, 0x94, 0x05, 0xfa, 0x30, 0x6a, 0x0b,
  11834. 0xf0, 0x52, 0x52, 0xb7, 0xdb, 0x34, 0xff, 0x18, 0x5c, 0x78,
  11835. 0x25, 0x44, 0x39, 0xe4, 0x54, 0x8a, 0xf1, 0x49, 0x04, 0xab,
  11836. 0x8a, 0x5f, 0x87, 0xe1, 0x6e, 0x1a, 0xf2, 0xba, 0x39, 0xb4,
  11837. 0x7c, 0x71, 0x5b, 0xbe, 0x8d, 0xbb, 0xed, 0x3b, 0xed, 0x20,
  11838. 0x95, 0xdf, 0xa7, 0x50, 0xb5, 0x66, 0xff, 0xd0, 0x3a, 0x92,
  11839. 0xde, 0xf2, 0xa3, 0xf2, 0xd6, 0x48, 0x6b, 0xd8, 0xef, 0x80,
  11840. 0x4d, 0xc2, 0x3c, 0xc7, 0xc6, 0x6e, 0xdf, 0xd1, 0x54, 0xfb,
  11841. 0x22, 0xac, 0x1a, 0x11, 0x81, 0x02, 0xc7, 0x66, 0xe0, 0xf3,
  11842. 0xad, 0x0b, 0xd0, 0xec, 0xae, 0x93, 0x53, 0xa5, 0xbf, 0xa5,
  11843. 0x17, 0x59, 0x14, 0x7d, 0x7e, 0x1e, 0x26, 0x15, 0x7a, 0x74,
  11844. 0xfb, 0xb1, 0x7a, 0x0e, 0xd3, 0xb5, 0x7c, 0x8c, 0x3a, 0xd7,
  11845. 0x45, 0x38, 0x55, 0xae, 0x4b, 0xe1, 0xfe, 0x5b, 0x57, 0x20,
  11846. 0x73, 0x38, 0xb9, 0x67, 0x34, 0xb1, 0xf3, 0x15, 0xb0, 0xb7,
  11847. 0x46, 0xa7, 0x1b, 0x19, 0x6d, 0xaf, 0x5e, 0x2c, 0x9c, 0x02,
  11848. 0x3f, 0x0f, 0xa3, 0x56, 0x2f, 0x9f, 0x1a, 0x82, 0x0e, 0xb4,
  11849. 0x46, 0xf5, 0x69, 0x89, 0x91, 0xf9, 0x2d, 0x99, 0x45, 0xa6,
  11850. 0x3c, 0x82, 0x74, 0xac, 0xeb, 0x58, 0x4a, 0xdd, 0x03, 0xaf,
  11851. 0xd1, 0x0a, 0xca, 0x4b, 0xe8, 0x4c, 0x63, 0xd4, 0x73, 0x94,
  11852. 0xbf, 0xd1, 0xc5, 0x8a, 0x3f, 0x6e, 0x58, 0xfc, 0x70, 0x76,
  11853. 0x69, 0x92, 0x05, 0xe0, 0xb9, 0xed, 0x5f, 0x19, 0xd7, 0x6f,
  11854. 0xd0, 0x35, 0xbb, 0x5a, 0x8d, 0x45, 0xac, 0x43, 0xcb, 0x74,
  11855. 0xcc, 0x92, 0xc3, 0x62, 0x56, 0x02, 0xb0, 0x0a, 0xb6, 0x88,
  11856. 0x40, 0x6f, 0x76, 0x1b, 0x89, 0xe4, 0x51, 0xeb, 0x7e, 0x08,
  11857. 0x8c, 0xce, 0x24, 0xc8, 0xd8, 0x58, 0xbd, 0x0e, 0x48, 0x57,
  11858. 0xc8, 0x9f, 0xad, 0x64, 0xcf, 0x69, 0x72, 0x35, 0xbf, 0x04,
  11859. 0x09, 0xfb, 0x0e, 0x62, 0x92, 0x76, 0x8b, 0x8d, 0xd5, 0x16,
  11860. 0xa2, 0x51, 0xdb, 0x71, 0xa9, 0x08, 0xb2, 0xf9, 0x1e, 0x07,
  11861. 0xe7, 0xf8, 0xf4, 0x79, 0x59, 0x2f, 0x8f, 0xf1, 0x5b, 0x45,
  11862. 0xe1, 0xb8, 0xb7, 0xef, 0x86, 0x69, 0x71, 0x51, 0x1c, 0xe5,
  11863. 0x61, 0xee, 0xb8, 0x1d, 0xa7, 0xdc, 0x48, 0xba, 0x51, 0xa5,
  11864. 0x70, 0x4d, 0xfd, 0x2c, 0x46, 0x21, 0x63, 0x0c, 0x9f, 0xb7,
  11865. 0x68, 0x58, 0x7b, 0xb3, 0x7d, 0x64, 0xfd, 0xaf, 0x87, 0x3d,
  11866. 0x86, 0x06, 0x36, 0x8a, 0x6d, 0xfe, 0xdf, 0xce, 0xa8, 0x16,
  11867. 0x42, 0x46, 0x15, 0xe5, 0xcf, 0x48, 0xa6, 0x4b, 0xe5, 0xc1,
  11868. 0xad, 0x14, 0x3a, 0x6d, 0xeb, 0xf9, 0xc9, 0x32, 0xd1, 0x82,
  11869. 0x60, 0x23, 0xf0, 0xff, 0xa7, 0xe6, 0x2e, 0xd6, 0x8d, 0x9d,
  11870. 0x4f, 0x6d, 0xb3, 0xc4, 0xad, 0xd9, 0xf0, 0xf5, 0x5c, 0x47,
  11871. 0x6c, 0x67, 0xf4, 0x0e, 0x18, 0x25, 0xbb, 0x67, 0xfa, 0x11,
  11872. 0x70, 0xd5, 0xbc, 0x3a, 0x34, 0xae, 0xa2, 0x76, 0x4b, 0x9f,
  11873. 0x59, 0x01, 0x18, 0x69, 0x44, 0xc4, 0x8a, 0xff, 0x00, 0xfc,
  11874. 0x2a, 0x45, 0xa9, 0x50, 0x8e, 0x37, 0x6b, 0x78, 0x14, 0x69,
  11875. 0xe7, 0x92, 0x3d, 0xf1, 0x34, 0xd5, 0x5c, 0x48, 0xc2, 0x50,
  11876. 0xb3, 0x0c, 0x7d, 0x54, 0x05, 0x31, 0x1e, 0xce, 0xaa, 0xc1,
  11877. 0x4c, 0xc9, 0x13, 0x33, 0x26, 0x1f, 0x56, 0x7e, 0x7e, 0x74,
  11878. 0xd3, 0x78, 0x3e, 0x00, 0x4a, 0xc8, 0xc6, 0x20, 0x5b, 0xb8,
  11879. 0x80, 0xb4, 0x13, 0x35, 0x23, 0xff, 0x50, 0xde, 0x25, 0x92,
  11880. 0x67, 0x08, 0xb8, 0xa3, 0xb6, 0x39, 0xd4, 0x30, 0xdc, 0xa5,
  11881. 0x88, 0x8a, 0x44, 0x08, 0x8b, 0x6d, 0x2e, 0xb8, 0xf3, 0x0d,
  11882. 0x23, 0xda, 0x35, 0x08, 0x5a, 0x92, 0xe1, 0x40, 0xac, 0xc7,
  11883. 0x15, 0x05, 0x8a, 0xdf, 0xe5, 0x71, 0xd8, 0xe0, 0xd7, 0x9f,
  11884. 0x58, 0x03, 0xf4, 0xec, 0x99, 0x3c, 0xb0, 0xe0, 0x07, 0x42,
  11885. 0x9b, 0xa0, 0x10, 0x7c, 0x24, 0x60, 0x19, 0xe8, 0x84, 0xd4,
  11886. 0xb1, 0x86, 0x19, 0x0a, 0x52, 0x70, 0x6e, 0xc2, 0x3c, 0xe2,
  11887. 0x73, 0x8d, 0xfe, 0xf8, 0x7e, 0xdf, 0x78, 0xe7, 0x92, 0x36,
  11888. 0x10, 0xf7, 0x2d, 0x76, 0x93, 0x8a, 0x0f, 0x20, 0xc8, 0x30,
  11889. 0x59, 0x81, 0xff, 0x3b, 0x70, 0x22, 0xce, 0x6e, 0x23, 0x68,
  11890. 0x35, 0x59, 0x0e, 0xcf, 0xf8, 0xf6, 0xcd, 0x45, 0xb6, 0x41,
  11891. 0xba, 0xda, 0xe6, 0x35, 0x0b, 0xd1, 0xef, 0xa5, 0x7c, 0xe0,
  11892. 0xb9, 0x6f, 0x5b, 0xa9, 0xab, 0x87, 0xe3, 0x3b, 0x92, 0xce,
  11893. 0xbe, 0xfe, 0xf7, 0xab, 0x82, 0xa3, 0xe6, 0xbd, 0xfe, 0xce,
  11894. 0xa6, 0x17, 0xcb, 0x4c, 0xb4, 0x4c, 0xd6, 0xfe, 0xbb, 0x1c,
  11895. 0x10, 0xde, 0x29, 0x3e, 0x92, 0x66, 0x20, 0xf8, 0xee, 0x83,
  11896. 0x86, 0x66, 0xe0, 0x66, 0x97, 0x85, 0xaf, 0x3a, 0x8f, 0xa9,
  11897. 0x97, 0x09, 0xde, 0x77, 0xda, 0xb7, 0x81, 0x41, 0x10, 0xca,
  11898. 0x66, 0x00, 0xec, 0xf8, 0x46, 0x73, 0xa6, 0x24, 0x36, 0xec,
  11899. 0x25, 0xbe, 0x93, 0x5e, 0x74, 0x9f, 0xbe, 0xf4, 0x84, 0x15,
  11900. 0x9c, 0xc5, 0x43, 0xd9, 0xea, 0x5a, 0xcc, 0x2c, 0x4e, 0x2e,
  11901. 0x4e, 0x32, 0xa6, 0x88, 0xb1, 0x25, 0x34, 0xf7, 0xba, 0xab,
  11902. 0xd3, 0xa0, 0xc2, 0x06, 0x70, 0xed, 0x66, 0x4d, 0x71, 0x34,
  11903. 0xaf, 0x10, 0x99, 0x10, 0x11, 0x4f, 0xe4, 0x7d, 0x42, 0x03,
  11904. 0x04, 0x02, 0xc2, 0x41, 0x85, 0x1e, 0xc4, 0xca, 0xae, 0xf0,
  11905. 0x83, 0x78, 0x34, 0x98, 0x55, 0x8b, 0x4c, 0xa0, 0x14, 0xea,
  11906. 0x15, 0x2c, 0xa1, 0x30, 0xd8, 0xcf, 0xac, 0xd4, 0xca, 0xf7,
  11907. 0xf4, 0xc4, 0x20, 0xca, 0xa1, 0xef, 0xce, 0x5d, 0x6b, 0x32,
  11908. 0xb6, 0xf0, 0x22, 0x08, 0x49, 0x21, 0x0c, 0x57, 0x0f, 0xf8,
  11909. 0xc0, 0xd2, 0xe3, 0xc0, 0xa6, 0x31, 0xc7, 0x87, 0x96, 0xa9,
  11910. 0xfe, 0x69, 0xa0, 0x7f, 0xf7, 0x8e, 0x31, 0x92, 0x37, 0xce,
  11911. 0xde, 0x36, 0x3f, 0xf5, 0x7d, 0x07, 0xaa, 0xa9, 0x43, 0xee,
  11912. 0x3c, 0x8c, 0xd3, 0x7d, 0x2c, 0xa6, 0xc3, 0x98, 0xab, 0xbe,
  11913. 0x90, 0x4c, 0xa5, 0x5a, 0x27, 0xeb, 0x0e, 0xed, 0xa1, 0x1e,
  11914. 0x3e, 0x44, 0xa3, 0x4b, 0x49, 0xad, 0xe4, 0x19, 0x90, 0xc8,
  11915. 0x9e, 0x6e, 0x5b, 0x68, 0xbc, 0x37, 0x54, 0xaf, 0xa6, 0xb7,
  11916. 0x71, 0x5c, 0x5d, 0x74, 0x83, 0xf4, 0xb9, 0x2f, 0xe5, 0x1a,
  11917. 0x0c, 0x73, 0x30, 0x56, 0x82, 0x04, 0xb3, 0x0e, 0x32, 0x98,
  11918. 0xfd, 0x27, 0xa0, 0xfe, 0xe0, 0xe0, 0xf5, 0xb7, 0xe0, 0x47,
  11919. 0x2a, 0xa6, 0x4a, 0xe0, 0xfc, 0xb5, 0xd8, 0xfd, 0x01, 0xfe,
  11920. 0x4e, 0x96, 0x17, 0x06, 0xcc, 0x92, 0x7c, 0xa1, 0x2f, 0xb5,
  11921. 0x04, 0x08, 0x76, 0xcc, 0x40, 0x75, 0x37, 0x4d, 0x2c, 0x74,
  11922. 0xcd, 0xc7, 0x62, 0xa6, 0xe6, 0xd8, 0x9e, 0x21, 0x7f, 0x2e,
  11923. 0xf5, 0x2c, 0xcf, 0x0b, 0x3f, 0xd7, 0xed, 0x17, 0xee, 0x92,
  11924. 0xaf, 0xf9, 0xa4, 0x71, 0x5d, 0x5f, 0x81, 0xb9, 0x2f, 0x12,
  11925. 0xe5, 0x57, 0x2d, 0x1e, 0xf1, 0x67, 0x47, 0x2a, 0xde, 0xab,
  11926. 0xf2, 0xea, 0xb7, 0xb5, 0x83, 0xdc, 0x46, 0xd4, 0xf3, 0x25,
  11927. 0x65, 0x15, 0x4d, 0x66, 0x34, 0x54, 0xab, 0x94, 0x89, 0x80,
  11928. 0x39, 0xd3, 0x39, 0xe3, 0xa2, 0xb1, 0x91, 0x2a, 0x5e, 0x55,
  11929. 0xe1, 0xa4, 0x0f, 0xc3, 0x4b, 0x5a, 0xa5, 0x4a, 0xb3, 0xc0,
  11930. 0x40, 0xea, 0x16, 0x0c, 0xd5, 0x2d, 0x83, 0x3e, 0x28, 0x20,
  11931. 0xac, 0x0a, 0x1b, 0x5b, 0x87, 0xcf, 0xf1, 0x51, 0xd6, 0xda,
  11932. 0xd1, 0xc9, 0xb1, 0x27, 0xf5, 0x62, 0x03, 0x10, 0xcf, 0x76,
  11933. 0x28, 0xa2, 0xea, 0x4b, 0x76, 0xaf, 0x9c, 0x3d, 0xf1, 0x1b,
  11934. 0x92, 0xff, 0xb0, 0xca, 0x16, 0xa2, 0x29, 0x94, 0x0e, 0x1e,
  11935. 0x51, 0xfb, 0xe1, 0x2b, 0x5a, 0x50, 0xfd, 0xaf, 0xab, 0xd7,
  11936. 0x32, 0xaa, 0x43, 0xa7, 0xcb, 0xd3, 0xd3, 0xe9, 0x1e, 0xb1,
  11937. 0x70, 0xd2, 0xbb, 0x15, 0x68, 0x49, 0xee, 0x6e, 0x1e, 0xc5,
  11938. 0x64, 0x4b, 0x26, 0x08, 0xe7, 0x32, 0x1c, 0x1d, 0x73, 0x8f,
  11939. 0x42, 0xfe, 0xeb, 0x67, 0x89, 0x42, 0x25, 0x40, 0xd6, 0x15,
  11940. 0x02, 0x55, 0x87, 0xe3, 0x87, 0xdd, 0x78, 0xc1, 0x01, 0x94,
  11941. 0xbc, 0x30, 0x5f, 0xbd, 0x89, 0xe1, 0xb0, 0x5c, 0xcd, 0xb7,
  11942. 0x68, 0xd5, 0xbb, 0xf4, 0xa0, 0x5d, 0x3d, 0xdd, 0x89, 0x12,
  11943. 0xc7, 0xb8, 0x5d, 0x51, 0x8a, 0xf4, 0xd5, 0x05, 0xc6, 0xdd,
  11944. 0x7b, 0x44, 0x38, 0xce, 0xb1, 0x24, 0x24, 0xe1, 0x9d, 0xc7,
  11945. 0x80, 0x86, 0x46, 0x2a, 0xd2, 0xa4, 0x0f, 0xec, 0xd3, 0x6b,
  11946. 0x31, 0xc0, 0x05, 0x31, 0xff, 0xf5, 0x1a, 0x33, 0x35, 0x68,
  11947. 0x2e, 0x68, 0x24, 0xbd, 0x62, 0xfc, 0x46, 0x79, 0x54, 0x5e,
  11948. 0x1e, 0x27, 0x93, 0x07, 0xed, 0x78, 0x94, 0x50, 0x42, 0x98,
  11949. 0x53, 0x88, 0xb7, 0x57, 0x04, 0x7d, 0xe2, 0xe1, 0xb5, 0x61,
  11950. 0x9e, 0x5a, 0x88, 0x31, 0x3e, 0x6c, 0x69, 0xbc, 0x8a, 0xe6,
  11951. 0xbc, 0x9d, 0x20, 0x7a, 0x86, 0xe5, 0x73, 0x93, 0x02, 0xc5,
  11952. 0xde, 0xdc, 0xcc, 0xbf, 0x89, 0x76, 0xdc, 0x4e, 0xa1, 0x89,
  11953. 0xe7, 0x95, 0x75, 0x01, 0xf7, 0x43, 0xaa, 0x3f, 0x1b, 0xb7,
  11954. 0x8c, 0x92, 0x66, 0x22, 0xbe, 0x34, 0xf1, 0x2f, 0xc3, 0xc7,
  11955. 0x21, 0xaf, 0x25, 0x57, 0x9a, 0x2c, 0x80, 0xf0, 0xb3, 0xdd,
  11956. 0xb3, 0xb2, 0x82, 0x97, 0x85, 0x73, 0xa9, 0x76, 0xe4, 0x37,
  11957. 0xa2, 0x65, 0xf9, 0xc1, 0x3d, 0x11, 0xbf, 0xcb, 0x3c, 0x8e,
  11958. 0xdd, 0xaf, 0x98, 0x57, 0x6a, 0xe1, 0x33, 0xe7, 0xf0, 0xff,
  11959. 0xed, 0x61, 0x53, 0xfe, 0x1e, 0x2d, 0x06, 0x2f, 0xb8, 0x9e,
  11960. 0xf9, 0xa5, 0x21, 0x06, 0xf3, 0x72, 0xf6, 0xa3, 0x77, 0xbb,
  11961. 0x63, 0x6e, 0x52, 0xb2, 0x42, 0x47, 0x9b, 0x92, 0x4c, 0xf8,
  11962. 0xd2, 0xe6, 0x02, 0xa5, 0x57, 0x2d, 0x6f, 0x30, 0x05, 0xe2,
  11963. 0xfd, 0x33, 0xe5, 0xb6, 0x23, 0x85, 0x89, 0x4a, 0x99, 0x20,
  11964. 0x33, 0xea, 0x2f, 0xcd, 0x28, 0x27, 0xff, 0xfd, 0x2e, 0x73,
  11965. 0x52, 0x29, 0x19, 0x7c, 0x65, 0xf5, 0x6a, 0xaa, 0x97, 0x6e,
  11966. 0xe9, 0x42, 0xa8, 0x55, 0x97, 0x56, 0x92, 0x9d, 0xd2, 0xd1,
  11967. 0xc4, 0x30, 0xaa, 0x95, 0x86, 0xba, 0x71, 0xdd, 0x2f, 0xf1,
  11968. 0xed, 0x66, 0x54, 0x78, 0x4b, 0x13, 0x31, 0xed, 0x9d, 0x2c,
  11969. 0xae, 0x0a, 0xc3, 0xca, 0xfb, 0x3f, 0x92, 0x92, 0x30, 0xa3,
  11970. 0x8e, 0xc8, 0x6d, 0x7b, 0x42, 0xd5, 0x5d, 0x99, 0x79, 0x42,
  11971. 0x28, 0x63, 0x9f, 0x97, 0x8e, 0x94, 0x6d, 0x1d, 0xb4, 0x21,
  11972. 0x39, 0xc7, 0x64, 0x48, 0x44, 0x5e, 0x15, 0x10, 0x45, 0x9f,
  11973. 0x8a, 0x01, 0x45, 0x20, 0x5c, 0xd1, 0x28, 0x0d, 0xe9, 0xfb,
  11974. 0xa9, 0x72, 0x68, 0x07, 0x31, 0x20, 0x75, 0x76, 0x82, 0x76,
  11975. 0x5d, 0x7c, 0xc1, 0x5d, 0x42, 0x40, 0xfd, 0x06, 0xa9, 0x66,
  11976. 0xb0, 0x36, 0x55, 0x86, 0x6c, 0x96, 0xbd, 0xb8, 0xf7, 0x36,
  11977. 0x87, 0xf2, 0xa1, 0x37, 0xd8, 0x2d, 0x83, 0xf5, 0xdc, 0xd8,
  11978. 0xde, 0x9e, 0x69, 0xd6, 0xe1, 0x0d, 0xd5, 0x93, 0xc5, 0xee,
  11979. 0xba, 0xd3, 0x40, 0x71, 0xbb, 0xc7, 0xbb, 0x50, 0x1a, 0x10,
  11980. 0x80, 0x99, 0x62, 0x1c, 0xe3, 0x1f, 0xa2, 0xcc, 0x98, 0xe1,
  11981. 0xaa, 0xff, 0xd9, 0x69, 0xe7, 0x87, 0x04, 0x87, 0x76, 0xec,
  11982. 0x55, 0x18, 0xaf, 0x82, 0x34, 0x4d, 0x4f, 0xf7, 0x57, 0x1f,
  11983. 0xa5, 0x43, 0xcc, 0xe9, 0x7a, 0x4a, 0xc8, 0xb4, 0x1f, 0x61,
  11984. 0x40, 0x5e, 0x1d, 0x11, 0xdd, 0xdc, 0xdc, 0xb4, 0x57, 0xf9,
  11985. 0x47, 0x96, 0xbc, 0x47, 0x29, 0xf8, 0xf2, 0x43, 0xc4, 0xa0,
  11986. 0x8c, 0x14, 0x5e, 0x73, 0x52, 0xac, 0xac, 0x39, 0x3b, 0x06,
  11987. 0x19, 0x1a, 0xca, 0x22, 0xc8, 0x96, 0x12, 0x2e, 0x4c, 0x7b,
  11988. 0xa0, 0x96, 0x53, 0x16, 0xce, 0x6d, 0x6e, 0xac, 0xb2, 0x07,
  11989. 0x17, 0x22, 0x07, 0x30, 0x20, 0x84, 0x9b, 0x0e, 0x92, 0x31,
  11990. 0x07, 0xe2, 0x77, 0xcd, 0x6a, 0x3e, 0x16, 0x4f, 0xd6, 0x12,
  11991. 0x88, 0x8a, 0x70, 0x5a, 0x87, 0xd8, 0xb9, 0xef, 0x76, 0xab,
  11992. 0x14, 0x65, 0x87, 0x3a, 0xef, 0xd8, 0x0e, 0x24, 0x40, 0x73,
  11993. 0x93, 0x2b, 0xbf, 0xac, 0xfe, 0x96, 0x8a, 0x9d, 0x12, 0xe6,
  11994. 0xc1, 0x5b, 0x00, 0x3b, 0x23, 0xee, 0xe2, 0x10, 0xb6, 0xbe,
  11995. 0x0e, 0x2f, 0xa2, 0x77, 0x16, 0x17, 0xfc, 0x4b, 0x2c, 0xd7,
  11996. 0x9c, 0xad, 0x66, 0xb4, 0xf2, 0xfd, 0xc1, 0xaf, 0x81, 0x12,
  11997. 0xd9, 0xed, 0x14, 0x32, 0xcf, 0x1b, 0xee, 0xc6, 0x63, 0xe8,
  11998. 0xe5, 0xe6, 0xb6, 0x91, 0x8d, 0x1b, 0x90, 0x75, 0x5d, 0x69,
  11999. 0x4c, 0x5d, 0xd6, 0xac, 0x79, 0xe8, 0xb6, 0xdf, 0xbf, 0x43,
  12000. 0x39, 0xd3, 0xb8, 0xf0, 0x39, 0xf4, 0x90, 0xaf, 0x73, 0x26,
  12001. 0xc7, 0x73, 0x6f, 0x93, 0xbb, 0xce, 0x6e, 0xdc, 0x1c, 0xd0,
  12002. 0x36, 0x23, 0x17, 0xb2, 0x39, 0x37, 0x15, 0xf5, 0x3a, 0x61,
  12003. 0xa9, 0x15, 0x52, 0x6e, 0xc5, 0x3a, 0x63, 0x79, 0x5d, 0x45,
  12004. 0xdc, 0x3a, 0xd5, 0x26, 0x01, 0x56, 0x97, 0x80, 0x7f, 0x83,
  12005. 0xf9, 0xec, 0xde, 0xa0, 0x2e, 0x7a, 0xb2, 0x4b, 0x04, 0x63,
  12006. 0x60, 0x05, 0xce, 0x96, 0xeb, 0xe0, 0x0a, 0x5f, 0xb0, 0x7e,
  12007. 0x6d, 0x0a, 0x24, 0x32, 0x47, 0x82, 0x7f, 0x0b, 0xd7, 0xe9,
  12008. 0xd5, 0x14, 0xa9, 0x6b, 0x10, 0x5d, 0x1e, 0x1f, 0x8a, 0xad,
  12009. 0x70, 0x91, 0xd4, 0x33, 0x1d, 0xc2, 0x3e, 0xf8, 0xc8, 0x52,
  12010. 0x9a, 0x27, 0x1f, 0x45, 0x2f, 0xb5, 0xc7, 0xb1, 0x8b, 0xf9,
  12011. 0xc6, 0x7b, 0xb5, 0x92, 0x7a, 0xdd, 0xeb, 0x07, 0x6c, 0x6f,
  12012. 0x11, 0xd7, 0x5b, 0x56, 0x56, 0xec, 0x88, 0x1c, 0xc9, 0xb4,
  12013. 0xe8, 0x43, 0xab, 0xdf, 0x0b, 0xc5, 0x28, 0xba, 0x70, 0x5d,
  12014. 0xd3, 0xb2, 0xe2, 0xcf, 0xa7, 0xbb, 0x53, 0x04, 0x6b, 0x73,
  12015. 0xdf, 0x27, 0xa6, 0x63, 0x58, 0xe1, 0x39, 0x26, 0x2a, 0x1a,
  12016. 0x21, 0xec, 0xbb, 0x5f, 0x46, 0x98, 0x3d, 0x48, 0x66, 0xfe,
  12017. 0xf3, 0xcb, 0xfc, 0x6e, 0x99, 0x82, 0x91, 0xce, 0x53, 0xfd,
  12018. 0x75, 0xc9, 0xb6, 0x08, 0xa8, 0xf3, 0xe4, 0xe0, 0xa0, 0x24,
  12019. 0x45, 0xb4, 0x69, 0x11, 0xac, 0x06, 0x1c, 0x39, 0x71, 0xcf,
  12020. 0x72, 0xfc, 0x77, 0x9b, 0x5f, 0xf4, 0x8b, 0x02, 0x31, 0xf3,
  12021. 0x67, 0xd1, 0x9b, 0xe0, 0x49, 0xa4, 0x69, 0x20, 0x99, 0x38,
  12022. 0xa7, 0xf5, 0x43, 0xd2, 0x45, 0x9f, 0x7a, 0xe7, 0xad, 0x7e,
  12023. 0x36, 0xee, 0xfd, 0x8c, 0xc5, 0x6a, 0x12, 0x58, 0x15, 0x3b,
  12024. 0x02, 0x81, 0x73, 0x8b, 0x10, 0xda, 0x21, 0xc7, 0x1d, 0x38,
  12025. 0xd8, 0x40, 0x7a, 0xa3, 0x59, 0x55, 0x35, 0x44, 0xa9, 0x9c,
  12026. 0xf5, 0xf4, 0xe4, 0x14, 0xc1, 0xc4, 0x15, 0x26, 0x01, 0xe3,
  12027. 0x31, 0xbf, 0xdc, 0xbc, 0x69, 0x0b, 0xcf, 0x71, 0x8c, 0xdb,
  12028. 0x16, 0xab, 0x36, 0x3e, 0xb3, 0xa4, 0x9f, 0xcc, 0xbf, 0xa2,
  12029. 0x93, 0x93, 0x9a, 0x3b, 0xaf, 0x72, 0x8d, 0x8b, 0x92, 0x44,
  12030. 0x5d, 0x6f, 0xc5, 0xf0, 0xdc, 0x65, 0x62, 0xea, 0xba, 0x33,
  12031. 0xe7, 0x6c, 0xa4, 0x35, 0xcf, 0xd9, 0xbc, 0x3c, 0xbf, 0x25,
  12032. 0x7b, 0x7c, 0x0b, 0x62, 0x92, 0x5a, 0x66, 0x63, 0xe1, 0x27,
  12033. 0x89, 0x12, 0xe2, 0xae, 0xb7, 0xf8, 0x04, 0x70, 0xda, 0x4a,
  12034. 0x3d, 0xa6, 0x67, 0x12, 0x14, 0x9e, 0x8e, 0xdc, 0xa2, 0xf2,
  12035. 0x3d, 0xc7, 0xd2, 0x8f, 0x18, 0x3a, 0x53, 0x8c, 0x83, 0x5d,
  12036. 0x66, 0xbb, 0x9f, 0x8c, 0xaf, 0xa8, 0x73, 0x08, 0x2e, 0x6d,
  12037. 0x30, 0xa0, 0xd0, 0x20, 0x94, 0x48, 0xad, 0x5e, 0x31, 0xfd,
  12038. 0x5e, 0xfd, 0xf9, 0xb5, 0xa2, 0x39, 0xa3, 0xb9, 0xdf, 0x4d,
  12039. 0xa4, 0xb1, 0x54, 0xcc, 0x92, 0x63, 0x2c, 0x66, 0x2d, 0x01,
  12040. 0x88, 0x8b, 0x7d, 0xc6, 0x5c, 0x9f, 0x18, 0x9a, 0x53, 0x91,
  12041. 0x59, 0x66, 0x70, 0xd7, 0x81, 0x0e, 0xa1, 0x3c, 0x7e, 0x86,
  12042. 0x85, 0x64, 0x38, 0x6f, 0xec, 0x76, 0x57, 0x80, 0x41, 0x9d,
  12043. 0xef, 0x61, 0xb8, 0xb2, 0x8a, 0xeb, 0xe9, 0x26, 0xbb, 0x69,
  12044. 0xb3, 0x8d, 0xd4, 0x6b, 0x05, 0xd8, 0x55, 0x1c, 0xbd, 0x9f,
  12045. 0x6b, 0x23, 0x46, 0x2b, 0xf7, 0xfb, 0x4d, 0x33, 0x3b, 0x21,
  12046. 0x6d, 0xea, 0x1b, 0x15, 0xaf, 0x0f, 0x8c, 0x98, 0xc8, 0xf4,
  12047. 0xd1, 0x3c, 0xdd, 0x21, 0xd0, 0x45, 0xdc, 0xaf, 0x89, 0x89,
  12048. 0xbf, 0xde, 0xbf, 0x46, 0x9e, 0x9e, 0x18, 0x56, 0x9d, 0x05,
  12049. 0x4d, 0x63, 0x5f, 0x1c, 0xd9, 0x15, 0xd1, 0x43, 0x17, 0x0c,
  12050. 0x48, 0x3d, 0x36, 0x8b, 0x14, 0x87, 0xc8, 0x10, 0x44, 0xdf,
  12051. 0x9c, 0xfd, 0x6e, 0x88, 0x88, 0xae, 0x7f, 0x7f, 0x67, 0xa3,
  12052. 0x33, 0x4d, 0xa3, 0x84, 0x8b, 0x58, 0x07, 0x17, 0xd8, 0x1d,
  12053. 0x9e, 0x43, 0xd6, 0x41, 0x9c, 0xff, 0xfa, 0x35, 0xa2, 0x42,
  12054. 0xa9, 0x5d, 0xa9, 0x4b, 0x95, 0x23, 0x6a, 0x6e, 0x42, 0xd7,
  12055. 0xa2, 0x0a, 0x70, 0x00, 0x61, 0x8b, 0x45, 0xbb, 0xac, 0x20,
  12056. 0x27, 0xcd, 0xfc, 0x61, 0x17, 0xfe, 0xab, 0x6b, 0xe8, 0xe0,
  12057. 0x51, 0xab, 0xa3, 0xbf, 0xe4, 0x85, 0x69, 0x8e, 0xd7, 0xa6,
  12058. 0x62, 0x33, 0x8f, 0x7c, 0xba, 0x48, 0xfa, 0x83, 0x94, 0xa5,
  12059. 0xdf, 0xa1, 0x76, 0xdc, 0xa9, 0x4b, 0x3c, 0x27, 0xff, 0xd9,
  12060. 0xbe, 0xf4, 0x80, 0x5a, 0xca, 0x33, 0xf3, 0x9a, 0x1d, 0xf8,
  12061. 0xf3, 0xe1, 0x83, 0x27, 0x0b, 0x59, 0x87, 0x31, 0x7d, 0x4f,
  12062. 0x5a, 0x5e, 0xe1, 0xbe, 0xa9, 0x68, 0xe9, 0x6f, 0x10, 0x0a,
  12063. 0xe2, 0x70, 0x05, 0xaa, 0xcb, 0xdd, 0x41, 0xd7, 0x49, 0x8a,
  12064. 0x98, 0xa0, 0x40, 0x2d, 0xc6, 0x56, 0x49, 0xca, 0x60, 0x16,
  12065. 0x9c, 0x38, 0xc9, 0xfe, 0x99, 0x15, 0xfb, 0x79, 0x01, 0x33,
  12066. 0xcd, 0x54, 0x2f, 0xf3, 0x70, 0x37, 0x82, 0x36, 0x32, 0x76,
  12067. 0x8f, 0x63, 0x00, 0xa2, 0x42, 0xce, 0x39, 0x90, 0xfc, 0xf8,
  12068. 0xff, 0x34, 0x38, 0x0a, 0x17, 0x5e, 0x9d, 0x34, 0x86, 0xde,
  12069. 0x33, 0x45, 0xac, 0xbf, 0x81, 0xdf, 0xd2, 0xbc, 0xc7, 0xd7,
  12070. 0xd1, 0xee, 0xde, 0x2b, 0x5b, 0x50, 0x56, 0xb5, 0x88, 0x00,
  12071. 0x92, 0x76, 0x5a, 0x34, 0x0c, 0xfe, 0x8f, 0xc5, 0xa0, 0x92,
  12072. 0xb0, 0xed, 0x43, 0xe7, 0x81, 0x39, 0x36, 0x6e, 0xb7, 0x4d,
  12073. 0x5b, 0xcf, 0xc7, 0xf0, 0x83, 0xe5, 0xdc, 0xb7, 0x74, 0xf4,
  12074. 0xf3, 0xbd, 0xa8, 0xa6, 0x7b, 0xe0, 0xc5, 0x50, 0xaa, 0xc7,
  12075. 0x83, 0x4d, 0xd9, 0xc5, 0x97, 0x03, 0x7c, 0x0c, 0x3b, 0x3a,
  12076. 0x18, 0xb2, 0x8c, 0xee, 0x67, 0x91, 0x38, 0x84, 0x8f, 0xef,
  12077. 0xb4, 0xf4, 0xe4, 0x7c, 0x1a, 0x3f, 0xa3, 0x0a, 0xd9, 0xba,
  12078. 0xff, 0x56, 0xd8, 0xe2, 0x82, 0xfc, 0x58, 0x8f, 0xf6, 0x12,
  12079. 0x10, 0x65, 0x6a, 0x68, 0x53, 0x2d, 0x9f, 0x2c, 0x77, 0xd1,
  12080. 0xb8, 0x21, 0x8a, 0xcb, 0xe9, 0xd4, 0x25, 0x18, 0x22, 0x46,
  12081. 0x3e, 0x72, 0x29, 0x2a, 0x68, 0x70, 0x73, 0xe2, 0x61, 0xa2,
  12082. 0xa8, 0x1f, 0x24, 0x48, 0x92, 0xa0, 0xd4, 0xdd, 0xde, 0xe5,
  12083. 0x02, 0x1b, 0x59, 0x5c, 0x7e, 0x92, 0x9c, 0xd8, 0xf4, 0x2d,
  12084. 0x6b, 0x79, 0x7b, 0xc7, 0xcd, 0xef, 0x21, 0x2a, 0x50, 0x7e,
  12085. 0xba, 0xdd, 0x02, 0x45, 0x7e, 0xc1, 0xdd, 0xeb, 0x00, 0x00,
  12086. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12087. 0x00, 0x00, 0x00, 0x03, 0x0c, 0x15, 0x1c, 0x22, 0x28,
  12088. };
  12089. static const int sizeof_bench_dilithium_level3_sig =
  12090. sizeof(bench_dilithium_level3_sig);
  12091. #endif
  12092. #ifndef WOLFSSL_NO_ML_DSA_87
  12093. static const unsigned char bench_dilithium_level5_sig[] = {
  12094. 0x78, 0xed, 0x1a, 0x3f, 0x41, 0xab, 0xf8, 0x93, 0x80, 0xf0,
  12095. 0xc6, 0xbf, 0x4a, 0xde, 0xaf, 0x29, 0x93, 0xe5, 0x9a, 0xbf,
  12096. 0x38, 0x08, 0x18, 0x33, 0xca, 0x7d, 0x5e, 0x65, 0xa4, 0xd2,
  12097. 0xd7, 0x45, 0xe3, 0xe7, 0x58, 0xfb, 0x05, 0xab, 0x65, 0x57,
  12098. 0xac, 0x6f, 0xf5, 0x43, 0x28, 0x5f, 0x9c, 0x9a, 0x3e, 0x35,
  12099. 0x84, 0xe4, 0xef, 0xa5, 0x57, 0x17, 0xad, 0x51, 0x44, 0x70,
  12100. 0x09, 0x00, 0x81, 0xbe, 0xfe, 0x14, 0x01, 0xfe, 0x0c, 0x94,
  12101. 0xbe, 0xa9, 0x89, 0xfd, 0x47, 0xfc, 0xb9, 0xd8, 0x17, 0x4d,
  12102. 0xd8, 0x73, 0xd5, 0x50, 0x9f, 0x13, 0x6c, 0x07, 0x71, 0x47,
  12103. 0xaa, 0x3c, 0xc0, 0x64, 0x00, 0x19, 0x2e, 0x74, 0x51, 0x0e,
  12104. 0x0f, 0x25, 0x30, 0x7f, 0x13, 0x96, 0xc6, 0xc5, 0xbf, 0xd4,
  12105. 0x82, 0xd3, 0x0d, 0xd3, 0x65, 0x4c, 0x72, 0x67, 0xe2, 0x37,
  12106. 0x6b, 0x3c, 0x8e, 0xa3, 0x36, 0x84, 0xe9, 0xaa, 0xac, 0x7d,
  12107. 0xf3, 0xac, 0xfc, 0x01, 0x50, 0x87, 0x88, 0xf6, 0xbf, 0x84,
  12108. 0xc3, 0xa0, 0x23, 0xe4, 0xe8, 0x01, 0x38, 0x39, 0x30, 0x8a,
  12109. 0xf3, 0xba, 0x92, 0x62, 0x37, 0xd7, 0x20, 0xd7, 0xf7, 0x41,
  12110. 0xff, 0xae, 0x81, 0x02, 0x29, 0x2a, 0x66, 0x8b, 0x20, 0xbe,
  12111. 0x61, 0x8d, 0xfb, 0x7c, 0x70, 0x14, 0xad, 0xf4, 0x94, 0x8c,
  12112. 0xee, 0x64, 0x3b, 0x9f, 0xe1, 0x6e, 0x68, 0x17, 0x07, 0xb8,
  12113. 0xfc, 0x99, 0xdc, 0xde, 0x69, 0x58, 0x8c, 0x97, 0x7d, 0xb3,
  12114. 0x2c, 0x9e, 0x90, 0x33, 0x2e, 0x7b, 0xbf, 0xf8, 0x6f, 0xf8,
  12115. 0x12, 0x64, 0xda, 0xc0, 0xfb, 0x30, 0xe6, 0xbf, 0x7b, 0x9a,
  12116. 0xde, 0xb5, 0xac, 0x9d, 0x6b, 0xcb, 0xe1, 0x0d, 0xf1, 0xbb,
  12117. 0xf3, 0x97, 0xc5, 0x08, 0xd3, 0x3e, 0xe3, 0xa4, 0xeb, 0x6f,
  12118. 0x6b, 0x62, 0x61, 0xc5, 0x0b, 0xa8, 0x02, 0xc2, 0xf1, 0xbe,
  12119. 0xbb, 0x93, 0x13, 0xa5, 0x8d, 0x7b, 0x5a, 0x6d, 0x1f, 0x28,
  12120. 0xbc, 0x35, 0xd8, 0xe8, 0xcf, 0x80, 0x8b, 0x4b, 0x02, 0x80,
  12121. 0x3b, 0xdc, 0x00, 0xce, 0x88, 0xb0, 0x62, 0x35, 0x7d, 0x51,
  12122. 0x7f, 0x5c, 0xb2, 0x23, 0x85, 0x47, 0x7e, 0x73, 0x88, 0x65,
  12123. 0xfd, 0x0d, 0x47, 0x33, 0xef, 0xb9, 0x75, 0x05, 0x86, 0x5d,
  12124. 0xd3, 0x98, 0xa6, 0x91, 0xe6, 0x8c, 0xe2, 0x71, 0x7a, 0x95,
  12125. 0xe0, 0x8c, 0x54, 0x4b, 0x68, 0x4d, 0x5a, 0xec, 0xad, 0xae,
  12126. 0x54, 0x4e, 0x3b, 0x0e, 0xcd, 0x70, 0xe6, 0x81, 0xbf, 0xf4,
  12127. 0x86, 0xab, 0xfe, 0xd8, 0xed, 0x69, 0xdd, 0x0f, 0x75, 0x8f,
  12128. 0x8e, 0xcd, 0x72, 0x40, 0x21, 0xee, 0x80, 0x6f, 0x9e, 0xa0,
  12129. 0x80, 0xf7, 0xf6, 0xa2, 0xf5, 0x04, 0x82, 0xea, 0xb6, 0xb1,
  12130. 0xa3, 0xfe, 0xa2, 0x2d, 0x83, 0xc7, 0x01, 0x4b, 0x27, 0x19,
  12131. 0x6a, 0x31, 0x04, 0x70, 0xce, 0x75, 0x22, 0x4b, 0x7a, 0x21,
  12132. 0x29, 0xfd, 0xe9, 0xcb, 0xbb, 0xca, 0x95, 0x0a, 0xd8, 0xcd,
  12133. 0x20, 0x2a, 0xb7, 0xbe, 0xdf, 0x2f, 0x0f, 0xfa, 0xf1, 0xc0,
  12134. 0x39, 0xf3, 0x74, 0x22, 0x05, 0x33, 0xca, 0x2a, 0x9c, 0x9f,
  12135. 0x06, 0x71, 0x90, 0x1e, 0x74, 0x4b, 0xbe, 0x9a, 0xc7, 0x1e,
  12136. 0x37, 0x9b, 0x96, 0x19, 0xfd, 0xa0, 0x61, 0x87, 0x93, 0xab,
  12137. 0x75, 0x79, 0xac, 0x2f, 0x83, 0xe1, 0x8c, 0x70, 0x54, 0x70,
  12138. 0x01, 0x93, 0xce, 0x76, 0x7a, 0x08, 0xe7, 0x75, 0xfb, 0x5e,
  12139. 0xa4, 0xcc, 0xd6, 0xeb, 0x90, 0xe2, 0x57, 0x07, 0x53, 0x88,
  12140. 0x8f, 0x7f, 0x29, 0x39, 0x80, 0xc4, 0x7f, 0x70, 0x6f, 0xff,
  12141. 0x44, 0x25, 0x2b, 0x9e, 0xa1, 0xbb, 0xda, 0x43, 0x53, 0x14,
  12142. 0xf8, 0x97, 0x08, 0xa4, 0xaf, 0xa0, 0xa5, 0x0c, 0xfa, 0xcc,
  12143. 0xba, 0xcd, 0x4f, 0xd3, 0x90, 0x28, 0x02, 0x25, 0xbe, 0xc6,
  12144. 0x35, 0x66, 0x99, 0xb0, 0x69, 0x46, 0xe5, 0xbf, 0x7e, 0x4f,
  12145. 0x53, 0x11, 0x1f, 0xa5, 0x2c, 0x9b, 0xd1, 0x70, 0x90, 0x34,
  12146. 0x66, 0xaa, 0x9f, 0xa8, 0x02, 0x3a, 0x05, 0x2b, 0x0a, 0xd0,
  12147. 0x72, 0x5d, 0x01, 0x7b, 0x02, 0xce, 0x18, 0xb9, 0x63, 0xd1,
  12148. 0x7d, 0xd2, 0x34, 0xa3, 0x2d, 0xaa, 0x78, 0xf0, 0x30, 0x6e,
  12149. 0x59, 0xe3, 0xf1, 0x1e, 0xf1, 0x33, 0x41, 0xde, 0xc4, 0x4e,
  12150. 0x88, 0x61, 0xc3, 0xb4, 0x6b, 0x21, 0x5d, 0xcc, 0x69, 0x44,
  12151. 0xf3, 0xb0, 0x84, 0x54, 0x2a, 0x23, 0x22, 0xa2, 0xc4, 0xba,
  12152. 0xad, 0x00, 0x57, 0x5b, 0xdf, 0xa0, 0xf7, 0x1c, 0x00, 0xc3,
  12153. 0x23, 0x93, 0xc0, 0x2f, 0x3b, 0x9d, 0x6e, 0x8c, 0x38, 0xa6,
  12154. 0x5e, 0xd8, 0x98, 0x7a, 0x6c, 0x90, 0xd5, 0x40, 0x3f, 0x8c,
  12155. 0xc3, 0xf0, 0x92, 0x66, 0xc4, 0xe5, 0xa8, 0x42, 0x25, 0x4c,
  12156. 0x56, 0x42, 0x37, 0x9a, 0xa4, 0x1d, 0xf5, 0xb0, 0xe3, 0x8a,
  12157. 0x9c, 0x57, 0x52, 0x63, 0xdc, 0xd9, 0xb0, 0xbf, 0xc3, 0xfc,
  12158. 0xfc, 0x6c, 0xab, 0x41, 0xae, 0xec, 0xc7, 0x40, 0x80, 0xb6,
  12159. 0x0b, 0x3c, 0xa9, 0xf5, 0x4f, 0x2d, 0xf6, 0x72, 0xe3, 0xba,
  12160. 0x13, 0x2c, 0x73, 0x61, 0x98, 0x66, 0x6f, 0x03, 0x88, 0x3b,
  12161. 0xe6, 0x95, 0x43, 0x33, 0x3b, 0xfe, 0xfd, 0x63, 0x8c, 0x00,
  12162. 0x8a, 0x67, 0x1c, 0x46, 0x0e, 0x0b, 0x51, 0x26, 0x79, 0x4f,
  12163. 0x7b, 0xb1, 0x36, 0x34, 0x52, 0x41, 0x7e, 0x74, 0xbb, 0x71,
  12164. 0x52, 0x8f, 0xcc, 0xf2, 0x99, 0x24, 0x3f, 0x18, 0xe6, 0xcf,
  12165. 0xdf, 0x6b, 0xfe, 0x77, 0xfa, 0xa8, 0x3f, 0xe3, 0x6b, 0xb7,
  12166. 0x32, 0x30, 0x8e, 0x16, 0x08, 0x59, 0x66, 0xdf, 0x95, 0x75,
  12167. 0x7d, 0xa3, 0x80, 0xf0, 0x0c, 0x1a, 0xa8, 0xe7, 0x87, 0x2f,
  12168. 0xe3, 0x39, 0x11, 0x82, 0x00, 0x3e, 0xe5, 0x71, 0x05, 0x7d,
  12169. 0x0c, 0x90, 0xae, 0xbc, 0xbf, 0xe0, 0x4b, 0x8f, 0x91, 0x85,
  12170. 0x1d, 0x0a, 0xa2, 0x36, 0x66, 0x18, 0x78, 0xd0, 0x0a, 0xa0,
  12171. 0xaf, 0x0f, 0x1c, 0x01, 0xdb, 0xb2, 0x21, 0x96, 0x25, 0xf7,
  12172. 0x9e, 0x3a, 0x9e, 0xc3, 0xe8, 0x92, 0x34, 0xaf, 0x7e, 0x3b,
  12173. 0x5f, 0xd9, 0x23, 0x97, 0x09, 0xf1, 0x87, 0x31, 0x3a, 0x94,
  12174. 0xc8, 0x9b, 0x52, 0xf4, 0x57, 0x54, 0x7b, 0x3e, 0x50, 0xd3,
  12175. 0x75, 0x2a, 0xba, 0x97, 0xd7, 0xec, 0x95, 0x6c, 0x35, 0x63,
  12176. 0xa4, 0xa1, 0x8f, 0xf5, 0xcc, 0xbe, 0x42, 0x65, 0x4e, 0x69,
  12177. 0x35, 0x55, 0xa5, 0x3e, 0xc4, 0xf0, 0xde, 0x60, 0x54, 0xdf,
  12178. 0xbb, 0x83, 0xad, 0xdf, 0xa5, 0x24, 0x8f, 0xbe, 0x0b, 0x16,
  12179. 0xfc, 0xf2, 0x64, 0xd5, 0x79, 0x68, 0xf3, 0x91, 0x81, 0x2a,
  12180. 0xd7, 0x1c, 0xc0, 0xdd, 0xe6, 0xb6, 0xb3, 0xa2, 0x4f, 0xc0,
  12181. 0x6d, 0x77, 0x02, 0xee, 0x43, 0xd6, 0x5e, 0x82, 0x66, 0x7f,
  12182. 0xb4, 0xe6, 0x5c, 0xff, 0x87, 0x1e, 0x1d, 0x6f, 0x1d, 0x96,
  12183. 0x6d, 0xbd, 0x90, 0x57, 0x65, 0xc2, 0x01, 0x35, 0xfa, 0x9a,
  12184. 0xc6, 0xe0, 0x4e, 0x2c, 0x4b, 0x16, 0xfa, 0x0d, 0x38, 0x87,
  12185. 0x39, 0x2c, 0x2b, 0x48, 0x14, 0x92, 0x3d, 0x83, 0x00, 0xa9,
  12186. 0x1a, 0x3d, 0x4d, 0x30, 0x23, 0x48, 0xcd, 0xd5, 0xcd, 0x01,
  12187. 0xb1, 0x45, 0x85, 0xcc, 0x66, 0x47, 0x1d, 0x63, 0x3d, 0x70,
  12188. 0xb8, 0x0c, 0xfd, 0xe3, 0xb2, 0x0f, 0x64, 0x6e, 0xb9, 0x2b,
  12189. 0xe5, 0xb0, 0x4d, 0x44, 0x4d, 0x66, 0x1a, 0xfa, 0x49, 0xbb,
  12190. 0xc3, 0xb8, 0xad, 0x64, 0x23, 0x7e, 0x71, 0x9f, 0x59, 0xec,
  12191. 0x25, 0xa8, 0x5e, 0x11, 0xd6, 0x6e, 0xc9, 0x09, 0xe7, 0xb9,
  12192. 0x6a, 0x63, 0x91, 0xaa, 0x5d, 0xd2, 0x8c, 0x91, 0xe8, 0x8d,
  12193. 0x35, 0x6d, 0x10, 0xf6, 0xfc, 0x6a, 0x3c, 0x77, 0x90, 0xf8,
  12194. 0x2a, 0x49, 0x13, 0x7f, 0xdb, 0xf5, 0x0c, 0xe9, 0xc8, 0x57,
  12195. 0xc6, 0xfd, 0x26, 0x8d, 0x79, 0xb5, 0xdd, 0x47, 0x74, 0x6e,
  12196. 0xe8, 0x8f, 0x50, 0xf5, 0xa7, 0x9e, 0xd1, 0x74, 0x10, 0xbb,
  12197. 0xf4, 0x8f, 0x8f, 0x0d, 0xcd, 0x1f, 0xf6, 0x59, 0xb8, 0x6c,
  12198. 0xd2, 0x37, 0x83, 0x28, 0xb2, 0x36, 0xc1, 0x39, 0x5b, 0xde,
  12199. 0x59, 0xee, 0x77, 0xa2, 0x6e, 0x67, 0xc6, 0xea, 0x1d, 0x2b,
  12200. 0x41, 0x8f, 0x6f, 0x96, 0x94, 0x1b, 0x5d, 0xab, 0x30, 0x53,
  12201. 0x1e, 0xf8, 0x17, 0x06, 0xea, 0xcc, 0x98, 0xa8, 0xdf, 0x81,
  12202. 0xe1, 0x80, 0xb7, 0xad, 0x69, 0xcb, 0x8f, 0x81, 0x1e, 0x76,
  12203. 0x75, 0x3c, 0x11, 0x9b, 0x38, 0x95, 0xa7, 0x87, 0x1f, 0xd9,
  12204. 0x76, 0x82, 0x21, 0x13, 0x25, 0x20, 0x42, 0xd3, 0x8c, 0xd9,
  12205. 0x1c, 0x64, 0xed, 0xe9, 0x55, 0xb5, 0x29, 0x98, 0x85, 0x7c,
  12206. 0x01, 0x94, 0xaa, 0xdd, 0x8c, 0x78, 0x08, 0x99, 0x99, 0x5a,
  12207. 0xf6, 0x61, 0x4c, 0xe0, 0x99, 0xf8, 0x15, 0x74, 0x2e, 0x0d,
  12208. 0x14, 0x89, 0x11, 0x84, 0xcd, 0x78, 0x0c, 0x6b, 0x48, 0xde,
  12209. 0xb4, 0xd6, 0x05, 0xbd, 0x99, 0x58, 0xb7, 0xe5, 0xc5, 0x7a,
  12210. 0x43, 0x18, 0x55, 0x33, 0x16, 0x2b, 0xfa, 0x27, 0xf5, 0xbb,
  12211. 0xaa, 0x52, 0xb5, 0x28, 0x5c, 0xfe, 0x61, 0x7f, 0x7a, 0x70,
  12212. 0xc2, 0x32, 0x4b, 0x05, 0x8d, 0x7b, 0x4d, 0x22, 0x57, 0x25,
  12213. 0x40, 0x46, 0x7c, 0xad, 0x2f, 0x8a, 0xc8, 0x16, 0xd6, 0xac,
  12214. 0x4e, 0xe3, 0xe3, 0x29, 0xe4, 0xe8, 0x00, 0x2b, 0xc9, 0xe3,
  12215. 0x3a, 0x6f, 0x66, 0xf1, 0x37, 0x37, 0x52, 0x88, 0x77, 0xf6,
  12216. 0xbd, 0x59, 0x5f, 0xf8, 0x11, 0x46, 0x7b, 0x12, 0x88, 0x2f,
  12217. 0x4b, 0x0d, 0x16, 0x89, 0x3e, 0x2a, 0x56, 0x58, 0xa8, 0x1c,
  12218. 0xee, 0x23, 0xd5, 0x66, 0x86, 0x5f, 0x59, 0x55, 0xac, 0x07,
  12219. 0xfd, 0xda, 0x6b, 0xf1, 0xc7, 0x01, 0x19, 0xdb, 0xff, 0x63,
  12220. 0x6f, 0x27, 0xdb, 0xa1, 0xc7, 0xe9, 0xe0, 0xdb, 0xe4, 0x9a,
  12221. 0xce, 0xf5, 0xac, 0x68, 0xab, 0x59, 0x0c, 0x83, 0xa3, 0x1c,
  12222. 0x2a, 0x86, 0x55, 0xe2, 0xaa, 0xa1, 0xb3, 0xed, 0xc2, 0x2d,
  12223. 0x43, 0xc5, 0x13, 0x68, 0xe4, 0x83, 0x3e, 0xd5, 0x7f, 0xf7,
  12224. 0xd5, 0xd0, 0x60, 0xd3, 0x70, 0x7f, 0x88, 0xaa, 0xca, 0x74,
  12225. 0xcc, 0x50, 0x8d, 0x55, 0x9c, 0xfe, 0x4a, 0xc6, 0xc9, 0x36,
  12226. 0xf7, 0x27, 0x26, 0x64, 0xd3, 0x6c, 0xdb, 0x16, 0x31, 0x81,
  12227. 0xe9, 0xce, 0x73, 0x60, 0x61, 0x9c, 0x0f, 0xb5, 0x6e, 0x68,
  12228. 0xbc, 0xb1, 0x9e, 0x9f, 0xcd, 0x6c, 0x27, 0x31, 0x2d, 0x40,
  12229. 0x36, 0xce, 0x91, 0xee, 0x47, 0xdc, 0xa0, 0x4f, 0xd7, 0x14,
  12230. 0x4f, 0x93, 0x00, 0xc4, 0x34, 0xca, 0xd4, 0x42, 0x21, 0x90,
  12231. 0xf6, 0x9d, 0xea, 0x45, 0x15, 0xfe, 0x2d, 0xd6, 0xab, 0xc2,
  12232. 0x36, 0x47, 0xc0, 0x5b, 0xd2, 0xae, 0x53, 0x33, 0xb0, 0x2d,
  12233. 0x29, 0xa3, 0x14, 0xda, 0xa4, 0x48, 0xc1, 0x57, 0x0c, 0xdc,
  12234. 0x72, 0x4a, 0xd0, 0xf5, 0x5b, 0x9a, 0x57, 0x1d, 0x06, 0xc8,
  12235. 0x0f, 0xc7, 0x5b, 0x70, 0xbb, 0x27, 0xf4, 0xe2, 0xf4, 0xf3,
  12236. 0x3c, 0xdc, 0xba, 0x43, 0xc4, 0x4e, 0xe2, 0x96, 0xd4, 0x6c,
  12237. 0x33, 0x3e, 0xbf, 0x85, 0xf7, 0x3c, 0x1d, 0x46, 0x59, 0x4e,
  12238. 0xa1, 0xa7, 0xa3, 0x76, 0x55, 0x8a, 0x72, 0x83, 0xd0, 0x45,
  12239. 0x86, 0x38, 0xa5, 0x4d, 0xc8, 0x62, 0xe4, 0x8a, 0xd5, 0x8e,
  12240. 0xb7, 0x4c, 0x6e, 0xaf, 0xa4, 0xbe, 0x88, 0x87, 0x77, 0xd1,
  12241. 0x7b, 0xb2, 0x1d, 0xe0, 0x1e, 0x53, 0x30, 0x31, 0x15, 0x6c,
  12242. 0x10, 0x81, 0x03, 0x55, 0xa7, 0x69, 0xb6, 0xa5, 0x48, 0xf4,
  12243. 0xb2, 0x3b, 0x76, 0x8b, 0x2e, 0x42, 0xa6, 0xaa, 0x7e, 0x66,
  12244. 0x57, 0xc2, 0x11, 0xc5, 0x2c, 0x7d, 0x96, 0xdf, 0xe3, 0x58,
  12245. 0x12, 0x98, 0x18, 0x0d, 0x87, 0xbd, 0x64, 0xbd, 0xfe, 0x6d,
  12246. 0xad, 0x6d, 0x1e, 0xf6, 0x34, 0x01, 0xb5, 0x56, 0xe8, 0x6a,
  12247. 0xb3, 0x8c, 0x70, 0x84, 0x36, 0x17, 0xd6, 0x4b, 0xaa, 0x57,
  12248. 0xab, 0xb3, 0x45, 0x30, 0x36, 0x10, 0xd4, 0xee, 0x8a, 0xc9,
  12249. 0x29, 0xd1, 0x92, 0x9b, 0xe2, 0x7c, 0x12, 0xd1, 0x29, 0x62,
  12250. 0x41, 0x69, 0xae, 0x3a, 0x50, 0xcc, 0x89, 0x50, 0x2e, 0xe6,
  12251. 0x07, 0xf8, 0x9c, 0x98, 0x80, 0xd5, 0xa3, 0xc8, 0x74, 0xfb,
  12252. 0xfc, 0x91, 0x16, 0x02, 0xdc, 0xf0, 0x42, 0x49, 0xbc, 0xc9,
  12253. 0x2f, 0x7f, 0x8d, 0x93, 0xf7, 0xf0, 0x74, 0xb7, 0xd1, 0x55,
  12254. 0xfc, 0x79, 0x03, 0x37, 0xfb, 0xf6, 0x7d, 0x2f, 0x2d, 0xf8,
  12255. 0x6b, 0xc5, 0xf9, 0x66, 0x38, 0xf5, 0xfd, 0x64, 0xc6, 0x08,
  12256. 0x99, 0xb3, 0x25, 0xad, 0xf4, 0xfd, 0x69, 0x2f, 0xf1, 0x18,
  12257. 0x46, 0xd6, 0x5c, 0x1a, 0x37, 0xcd, 0xee, 0xa3, 0xbf, 0x0f,
  12258. 0x57, 0x5c, 0xc3, 0x97, 0x94, 0x84, 0x89, 0xbe, 0x00, 0xf6,
  12259. 0x40, 0xe9, 0x5a, 0x52, 0xaf, 0x3a, 0x5b, 0xf4, 0x56, 0xb0,
  12260. 0x04, 0x49, 0xc6, 0x32, 0x8c, 0xa1, 0x0a, 0xd8, 0x88, 0xa1,
  12261. 0xc3, 0xb7, 0x8b, 0x96, 0xc3, 0x39, 0x51, 0x50, 0x83, 0xa6,
  12262. 0xf0, 0x6d, 0xe7, 0x6e, 0x20, 0xff, 0x9d, 0xac, 0x03, 0x57,
  12263. 0xbc, 0xcb, 0x6a, 0x19, 0xa7, 0xc5, 0xd2, 0x44, 0x4f, 0x17,
  12264. 0x1e, 0x9a, 0x8d, 0x97, 0x25, 0x55, 0x52, 0x49, 0xe2, 0x48,
  12265. 0xae, 0x4b, 0x3f, 0x94, 0x5a, 0xb2, 0x2d, 0x40, 0xd9, 0x85,
  12266. 0xef, 0x03, 0xa0, 0xd3, 0x66, 0x9a, 0x8f, 0x7b, 0xc0, 0x8d,
  12267. 0x54, 0x95, 0x42, 0x49, 0xeb, 0x15, 0x00, 0xf3, 0x6d, 0x6f,
  12268. 0x40, 0xf2, 0x8b, 0xc1, 0x50, 0xa6, 0x22, 0x3b, 0xd6, 0x88,
  12269. 0xa1, 0xf7, 0xb0, 0x1f, 0xcd, 0x20, 0x4e, 0x5b, 0xad, 0x66,
  12270. 0x4a, 0xda, 0x40, 0xee, 0x4c, 0x4c, 0x3e, 0xa7, 0x75, 0x51,
  12271. 0x90, 0xba, 0xee, 0x59, 0xbc, 0xe3, 0xcd, 0x4d, 0xb9, 0x57,
  12272. 0xb7, 0xf8, 0xc1, 0xb9, 0x8d, 0x0f, 0x58, 0x2c, 0x4c, 0x98,
  12273. 0xa6, 0x9c, 0xd9, 0x0e, 0x25, 0x4f, 0xea, 0x4c, 0x15, 0x0b,
  12274. 0x89, 0xe4, 0xac, 0xa1, 0x5a, 0xa1, 0xfd, 0x5b, 0xc6, 0xfe,
  12275. 0xf0, 0xf1, 0x4c, 0xa7, 0x60, 0xbc, 0xc3, 0xa5, 0x80, 0x00,
  12276. 0x3b, 0x3f, 0x22, 0x38, 0x60, 0x40, 0x76, 0x52, 0x83, 0x32,
  12277. 0xee, 0x20, 0x6a, 0xf9, 0x1e, 0x6b, 0x99, 0x52, 0xe7, 0x04,
  12278. 0xdc, 0x5a, 0x9d, 0x77, 0x8a, 0xdd, 0x9b, 0x53, 0x19, 0xff,
  12279. 0x69, 0x8c, 0xbc, 0xc6, 0xe0, 0x79, 0x0d, 0x3d, 0x3d, 0x54,
  12280. 0x5b, 0xe0, 0x47, 0x5b, 0x71, 0x05, 0x98, 0x8f, 0xbb, 0x65,
  12281. 0xe1, 0x31, 0x9a, 0xc8, 0x1e, 0x7a, 0x4a, 0xf8, 0xcb, 0x17,
  12282. 0xd1, 0x83, 0x58, 0xb1, 0xc0, 0xe4, 0xb1, 0x85, 0xca, 0xa5,
  12283. 0xf8, 0x0e, 0xd1, 0x0c, 0xe8, 0x71, 0xc3, 0xfa, 0xbf, 0x1d,
  12284. 0xd6, 0x98, 0x03, 0xed, 0x77, 0x3b, 0x55, 0xaf, 0x69, 0x72,
  12285. 0x6b, 0x42, 0x31, 0x98, 0x95, 0xd5, 0x79, 0xa5, 0x4c, 0x51,
  12286. 0xcf, 0x02, 0x65, 0x93, 0xf2, 0x71, 0xdc, 0xde, 0x9a, 0xa3,
  12287. 0x86, 0xa7, 0xea, 0xcf, 0xd7, 0xe5, 0x00, 0xde, 0x40, 0x02,
  12288. 0xcd, 0x6b, 0x46, 0x0b, 0xbb, 0xbf, 0x77, 0x5f, 0x9d, 0x7c,
  12289. 0xa4, 0x7f, 0x7c, 0x8a, 0xba, 0xd6, 0x99, 0xc5, 0xaa, 0x06,
  12290. 0x36, 0xe1, 0x7e, 0x9c, 0x6f, 0x28, 0xd4, 0x6e, 0x1d, 0x5b,
  12291. 0xdd, 0x01, 0x24, 0xbd, 0x6c, 0x5d, 0x87, 0x3c, 0xc1, 0xf6,
  12292. 0x93, 0x37, 0xe2, 0x3b, 0x70, 0xc4, 0xd8, 0x10, 0x0e, 0x44,
  12293. 0x37, 0x00, 0xe3, 0x07, 0xbd, 0x67, 0xd3, 0x9d, 0xe6, 0xe7,
  12294. 0x48, 0x1b, 0xe0, 0x79, 0xb3, 0x30, 0x91, 0x89, 0x0f, 0x89,
  12295. 0x77, 0xfa, 0x13, 0x85, 0xd0, 0x32, 0xbd, 0xc1, 0x9e, 0x52,
  12296. 0x04, 0x80, 0x54, 0xb1, 0x08, 0x39, 0x20, 0xda, 0x3e, 0xf1,
  12297. 0xd9, 0x15, 0x74, 0x55, 0x06, 0xfc, 0x4d, 0x85, 0xd4, 0x98,
  12298. 0x02, 0x64, 0x10, 0x86, 0xd7, 0xcd, 0x01, 0x0d, 0x85, 0xa0,
  12299. 0x78, 0xb0, 0x58, 0x99, 0x7b, 0xdf, 0xe4, 0x8c, 0x3f, 0xab,
  12300. 0xc0, 0xbc, 0xa5, 0x30, 0x28, 0xe1, 0x4e, 0x02, 0x98, 0xab,
  12301. 0x03, 0xf3, 0x21, 0xe7, 0xa7, 0xe7, 0xc3, 0x5f, 0x98, 0xc0,
  12302. 0x83, 0x02, 0xe8, 0x8a, 0x30, 0x75, 0x95, 0xcf, 0x77, 0x83,
  12303. 0xfb, 0x32, 0x5a, 0xf9, 0x13, 0xed, 0xdb, 0xda, 0xc3, 0x84,
  12304. 0x4b, 0x8f, 0x1a, 0xf0, 0xad, 0x8e, 0xcf, 0xe3, 0xa7, 0x2b,
  12305. 0xb5, 0x44, 0x75, 0xd6, 0xda, 0x33, 0x81, 0x22, 0xa7, 0x6a,
  12306. 0xbd, 0x21, 0x64, 0x85, 0xfa, 0x65, 0x8e, 0xc4, 0x58, 0xec,
  12307. 0xc4, 0x18, 0x90, 0xa3, 0xcc, 0x2e, 0xaa, 0xa2, 0x2e, 0x46,
  12308. 0x7a, 0x4a, 0x35, 0xbf, 0x58, 0x78, 0x2b, 0x1e, 0x72, 0xe5,
  12309. 0x80, 0xc9, 0xe0, 0x9e, 0x43, 0x01, 0xcc, 0xe1, 0x0c, 0x00,
  12310. 0xe9, 0xc1, 0xa5, 0x1a, 0x9b, 0x4e, 0x6e, 0x34, 0x32, 0xfd,
  12311. 0x86, 0xb7, 0xae, 0xc3, 0x6e, 0x69, 0x04, 0xf6, 0x6a, 0x92,
  12312. 0x78, 0xb1, 0x1f, 0x9d, 0x5e, 0x0c, 0xf9, 0xc4, 0x1a, 0xf6,
  12313. 0xb4, 0x8a, 0x63, 0xb5, 0x87, 0x5b, 0xfb, 0x50, 0xbf, 0xd5,
  12314. 0x17, 0x97, 0x8e, 0x55, 0x1c, 0xfe, 0x82, 0xf6, 0xa7, 0x9c,
  12315. 0x0b, 0xc9, 0x0a, 0xf6, 0x7f, 0x70, 0xd1, 0x00, 0xed, 0x1c,
  12316. 0x6c, 0x3a, 0x95, 0xed, 0x61, 0xa4, 0xd6, 0x57, 0xfb, 0x57,
  12317. 0xf8, 0x9b, 0x4c, 0xce, 0x50, 0x26, 0x5c, 0x19, 0xd2, 0xa7,
  12318. 0xd6, 0xe8, 0x3c, 0x29, 0x34, 0xfb, 0x26, 0x7f, 0xc5, 0x78,
  12319. 0xbf, 0xfe, 0xb6, 0x2a, 0x5a, 0x62, 0x8e, 0x31, 0x9b, 0x57,
  12320. 0xa4, 0xe7, 0x4d, 0x3d, 0x18, 0x05, 0xf0, 0x94, 0xbb, 0x04,
  12321. 0xfa, 0x0a, 0x92, 0xf4, 0xc6, 0x7f, 0x16, 0xa2, 0x31, 0xed,
  12322. 0xc1, 0xb4, 0x62, 0x54, 0x3a, 0x23, 0x12, 0x6a, 0x76, 0xcc,
  12323. 0x8c, 0x91, 0x89, 0x58, 0x8c, 0x20, 0x23, 0xd9, 0xaa, 0x0d,
  12324. 0x80, 0xbe, 0xb9, 0xb4, 0x40, 0x1e, 0xff, 0xa9, 0xf7, 0x71,
  12325. 0x0a, 0xa0, 0x0a, 0xdf, 0x11, 0x0b, 0x66, 0x3f, 0xf2, 0x4d,
  12326. 0x5d, 0x39, 0x7c, 0x77, 0xe1, 0xb1, 0x09, 0xa1, 0x6b, 0x2e,
  12327. 0x30, 0x43, 0x33, 0x80, 0x6e, 0x6a, 0x1d, 0x47, 0xd9, 0xd6,
  12328. 0xac, 0xdc, 0x3f, 0x16, 0xb1, 0x58, 0x11, 0x9f, 0x67, 0xd7,
  12329. 0x15, 0x45, 0xd8, 0xc3, 0x69, 0x24, 0x8d, 0xac, 0xff, 0xc3,
  12330. 0x43, 0xfd, 0x24, 0xaf, 0xf1, 0xc8, 0x3a, 0xc7, 0xd6, 0x1f,
  12331. 0x56, 0x26, 0x16, 0xe6, 0x30, 0xcd, 0x6e, 0x0a, 0x63, 0x2a,
  12332. 0x7b, 0x86, 0xd7, 0x65, 0x39, 0x45, 0x7c, 0xe6, 0xa0, 0xe6,
  12333. 0x38, 0xed, 0x54, 0x84, 0x00, 0x4d, 0x8e, 0xc2, 0xba, 0x56,
  12334. 0x9b, 0xf3, 0xe1, 0xe8, 0x7d, 0xfe, 0x47, 0xf0, 0x58, 0xe7,
  12335. 0x59, 0x60, 0x97, 0x2e, 0x57, 0x1a, 0x09, 0x1f, 0x8b, 0x2b,
  12336. 0x0b, 0x47, 0x75, 0xc0, 0xb3, 0x79, 0xce, 0x10, 0x47, 0x6d,
  12337. 0xfc, 0xcb, 0x22, 0x61, 0x5c, 0x39, 0xc4, 0x3f, 0xc5, 0xef,
  12338. 0xb8, 0xc8, 0x88, 0x52, 0xce, 0x90, 0x17, 0xf5, 0x3c, 0xa9,
  12339. 0x87, 0x6f, 0xcb, 0x2f, 0x11, 0x53, 0x65, 0x9b, 0x74, 0x21,
  12340. 0x3e, 0xdd, 0x7b, 0x1f, 0x19, 0x9f, 0x53, 0xe6, 0xab, 0xc0,
  12341. 0x56, 0xba, 0x80, 0x19, 0x5d, 0x3f, 0xc7, 0xe2, 0xfb, 0x8c,
  12342. 0xe2, 0x93, 0xe0, 0x31, 0xc9, 0x33, 0x31, 0x23, 0x31, 0xa1,
  12343. 0x36, 0x4c, 0x62, 0xd8, 0x0a, 0xfd, 0x85, 0x97, 0xae, 0xa9,
  12344. 0xe9, 0x58, 0x29, 0x17, 0x33, 0x09, 0x5a, 0x8e, 0xa3, 0x90,
  12345. 0x41, 0xd3, 0xfc, 0x24, 0x98, 0x61, 0x4d, 0x30, 0x1f, 0x76,
  12346. 0x8f, 0xfc, 0xd0, 0x96, 0x8b, 0x2e, 0x9b, 0x24, 0x73, 0x35,
  12347. 0x00, 0xb7, 0xf6, 0xe8, 0xba, 0xec, 0x98, 0x74, 0x41, 0xa4,
  12348. 0x47, 0x10, 0x0d, 0xbc, 0xba, 0xd1, 0xe7, 0xdb, 0x12, 0xcb,
  12349. 0x5f, 0x02, 0xb1, 0xa6, 0xa0, 0xd7, 0x28, 0x30, 0x3e, 0x0a,
  12350. 0x5c, 0x5f, 0xe6, 0x2f, 0x3c, 0xde, 0x46, 0x60, 0xaf, 0x07,
  12351. 0x5f, 0xed, 0x08, 0xc0, 0x06, 0x58, 0xba, 0xd7, 0x36, 0x5b,
  12352. 0xa0, 0x4a, 0xf7, 0xa1, 0x05, 0x9b, 0x00, 0xda, 0x49, 0xdc,
  12353. 0xbf, 0xea, 0xe1, 0x03, 0xda, 0x95, 0x95, 0xa0, 0xfa, 0x2e,
  12354. 0xf1, 0x60, 0x11, 0x47, 0xdd, 0xb3, 0xfb, 0x0b, 0xa2, 0x92,
  12355. 0xcf, 0x73, 0xbb, 0xce, 0x82, 0x71, 0xbc, 0xbd, 0x50, 0x64,
  12356. 0xf1, 0x96, 0x48, 0x48, 0x93, 0xf8, 0xdc, 0x1c, 0x18, 0x12,
  12357. 0xc6, 0x17, 0x6a, 0xa9, 0xc1, 0x4d, 0x6f, 0x76, 0xda, 0x2f,
  12358. 0x4e, 0x59, 0xdd, 0x8b, 0x1c, 0xa5, 0x30, 0xb6, 0xe9, 0x88,
  12359. 0x8f, 0x75, 0x0c, 0xcd, 0xd8, 0x61, 0xf4, 0x28, 0xc5, 0x9a,
  12360. 0xcd, 0x77, 0x0d, 0x36, 0x5f, 0x75, 0xa5, 0x0a, 0x77, 0x20,
  12361. 0x28, 0x5a, 0xac, 0x5f, 0xa1, 0x83, 0x67, 0x70, 0xb7, 0xd8,
  12362. 0x23, 0x48, 0x60, 0xa8, 0xd0, 0xaf, 0xee, 0x7a, 0xb8, 0x25,
  12363. 0xd7, 0x8f, 0x82, 0x8c, 0xd0, 0x81, 0x7a, 0x49, 0x69, 0xe4,
  12364. 0x22, 0x73, 0x29, 0x48, 0xc8, 0x09, 0x72, 0x16, 0xf8, 0x3d,
  12365. 0xff, 0x13, 0xac, 0x98, 0x03, 0x76, 0x33, 0xcb, 0x19, 0xb0,
  12366. 0x22, 0x5b, 0x1e, 0x16, 0x29, 0xb9, 0xcc, 0xa6, 0x92, 0xd8,
  12367. 0xed, 0x93, 0x0f, 0xbd, 0x10, 0x98, 0x53, 0x0a, 0x07, 0x7f,
  12368. 0xd6, 0x51, 0x76, 0xda, 0xdc, 0x0c, 0xeb, 0x2a, 0x95, 0xd0,
  12369. 0x3e, 0xa6, 0xc4, 0xc6, 0xd8, 0xfb, 0x1b, 0x2a, 0x7f, 0xf1,
  12370. 0x08, 0xbe, 0xd3, 0xed, 0x67, 0x63, 0x5f, 0x1d, 0x29, 0xdb,
  12371. 0x47, 0x03, 0x4a, 0xf4, 0x6b, 0xb4, 0x46, 0x02, 0x28, 0x4f,
  12372. 0x88, 0x9b, 0x46, 0x66, 0x40, 0x56, 0x34, 0x4c, 0xec, 0x8e,
  12373. 0x0b, 0x5d, 0x14, 0x94, 0x91, 0xfc, 0xdc, 0x0c, 0xdc, 0x5b,
  12374. 0x45, 0x12, 0x7e, 0xa1, 0xe9, 0x75, 0x38, 0xcb, 0xd3, 0x6b,
  12375. 0xd7, 0xa4, 0x24, 0x94, 0x78, 0x09, 0x7f, 0x77, 0xc8, 0x6d,
  12376. 0xe1, 0x82, 0x1c, 0x1c, 0x91, 0xc6, 0x38, 0x9e, 0x3b, 0x3d,
  12377. 0x31, 0xdd, 0x9e, 0x46, 0x58, 0x7a, 0x42, 0x16, 0x6f, 0xfd,
  12378. 0x7d, 0x8c, 0xf5, 0xf0, 0x9f, 0x92, 0x6e, 0xbe, 0x47, 0xa6,
  12379. 0x1e, 0x8e, 0x82, 0x15, 0x24, 0xc3, 0x1b, 0xb0, 0xd1, 0x68,
  12380. 0xf9, 0xd1, 0x7c, 0x60, 0x98, 0x86, 0xd9, 0x53, 0xa2, 0x38,
  12381. 0x62, 0xf4, 0x72, 0x71, 0xcb, 0xb9, 0x35, 0xef, 0xb9, 0x49,
  12382. 0x3a, 0x73, 0xb2, 0xd7, 0x0f, 0x90, 0xf5, 0x2c, 0x5b, 0xf5,
  12383. 0xfd, 0x39, 0x17, 0xf7, 0xe4, 0x69, 0x81, 0x0f, 0x6b, 0xe7,
  12384. 0x32, 0xd2, 0xdc, 0x5d, 0x40, 0xbf, 0x41, 0x95, 0x89, 0x81,
  12385. 0x29, 0x80, 0x40, 0xa3, 0xac, 0xd2, 0xc7, 0xf7, 0xe8, 0xd0,
  12386. 0x45, 0xed, 0x48, 0x43, 0x3a, 0xed, 0x8d, 0xef, 0x37, 0xe1,
  12387. 0x24, 0x9a, 0x67, 0x9a, 0x6b, 0x71, 0x4f, 0x9a, 0xb9, 0x2c,
  12388. 0x1b, 0x10, 0x48, 0xe2, 0x31, 0x1e, 0xbb, 0xf2, 0x4a, 0xad,
  12389. 0x04, 0xc7, 0xd7, 0xf2, 0xe8, 0x83, 0x5f, 0xe8, 0xa2, 0x81,
  12390. 0x95, 0xf9, 0x60, 0x51, 0x9c, 0x99, 0x76, 0x69, 0x76, 0x4e,
  12391. 0xbd, 0x44, 0x52, 0x36, 0xca, 0xd8, 0x6e, 0xf7, 0x1a, 0xa1,
  12392. 0x54, 0xdf, 0x90, 0x52, 0x94, 0xb6, 0x3a, 0xcb, 0x43, 0x56,
  12393. 0x11, 0xde, 0xa0, 0xe1, 0x45, 0x8a, 0x80, 0x2d, 0xaf, 0x1f,
  12394. 0x24, 0x3f, 0x80, 0x17, 0x1f, 0x28, 0xbb, 0xcc, 0x1a, 0xd2,
  12395. 0x2d, 0xa6, 0x9e, 0xe0, 0xdc, 0xf0, 0x98, 0x16, 0x58, 0x88,
  12396. 0xc6, 0xf1, 0x81, 0x71, 0x91, 0x8f, 0xa2, 0xab, 0xa5, 0xe6,
  12397. 0x68, 0x1f, 0xa5, 0x86, 0xb5, 0xd9, 0x05, 0xba, 0x50, 0x67,
  12398. 0x0b, 0x1e, 0xfe, 0x42, 0x50, 0xf8, 0x01, 0xf8, 0x38, 0x92,
  12399. 0x57, 0x86, 0x08, 0x47, 0xee, 0x23, 0x11, 0x60, 0x61, 0x1a,
  12400. 0x77, 0x3c, 0x1a, 0x8e, 0x08, 0xe3, 0xaf, 0x84, 0x04, 0x75,
  12401. 0x15, 0x47, 0x7a, 0x83, 0x8e, 0x92, 0x3e, 0xe8, 0xf0, 0xc2,
  12402. 0x81, 0x89, 0x3b, 0x73, 0x81, 0xe5, 0xe8, 0x97, 0x97, 0x63,
  12403. 0x64, 0xf3, 0xa9, 0x1b, 0x61, 0x65, 0x7f, 0x0e, 0x47, 0x6b,
  12404. 0x14, 0x57, 0x29, 0x8f, 0x91, 0x35, 0x43, 0x10, 0x12, 0x86,
  12405. 0x99, 0xec, 0xc8, 0x9e, 0x67, 0x90, 0x20, 0x21, 0x3c, 0x83,
  12406. 0xdb, 0x73, 0x4e, 0x8e, 0x7d, 0x86, 0xde, 0xb8, 0xd8, 0xfa,
  12407. 0x23, 0x1f, 0x5a, 0xe4, 0xc7, 0x0c, 0x1d, 0x5e, 0xd1, 0x10,
  12408. 0x58, 0xd5, 0x86, 0xfa, 0x40, 0x30, 0x0a, 0x78, 0x0a, 0xa5,
  12409. 0x56, 0xd5, 0xe6, 0x86, 0xd4, 0x14, 0x77, 0x32, 0xcd, 0x07,
  12410. 0xf9, 0xbe, 0x7a, 0xd8, 0xbc, 0x91, 0xe0, 0xda, 0x76, 0x6b,
  12411. 0x97, 0x10, 0xda, 0xea, 0x27, 0xa2, 0x67, 0x6d, 0x94, 0x27,
  12412. 0x6e, 0xea, 0xca, 0x56, 0x45, 0x32, 0x1d, 0x38, 0x12, 0x21,
  12413. 0x33, 0x2c, 0x3c, 0x5c, 0x33, 0xb0, 0x9e, 0x80, 0x0b, 0x4e,
  12414. 0xbb, 0x09, 0x5e, 0x56, 0x54, 0xb0, 0x9b, 0x7e, 0xb6, 0x00,
  12415. 0xe8, 0x63, 0x19, 0x85, 0xf1, 0x4d, 0x65, 0x9d, 0x1f, 0x8d,
  12416. 0x18, 0xcc, 0x63, 0xc6, 0xd9, 0xa6, 0xbc, 0xe7, 0x42, 0x55,
  12417. 0x12, 0xdc, 0x8c, 0x26, 0x2d, 0x8d, 0xc2, 0xe9, 0x3b, 0xbc,
  12418. 0xed, 0x06, 0x08, 0x31, 0xb0, 0xe0, 0x99, 0xe2, 0x86, 0x81,
  12419. 0x88, 0x4a, 0xac, 0x1f, 0x4a, 0xb2, 0x1e, 0x1e, 0x4c, 0xb2,
  12420. 0x9f, 0x27, 0xa0, 0xd9, 0x8a, 0x7e, 0xe7, 0xa3, 0xad, 0xeb,
  12421. 0x2c, 0xfd, 0x14, 0xc6, 0x4b, 0x26, 0xce, 0x38, 0xb9, 0x01,
  12422. 0x9e, 0xde, 0xc8, 0x7b, 0x82, 0x2f, 0xaa, 0x72, 0x80, 0xbe,
  12423. 0x3a, 0x35, 0x95, 0xc8, 0xf3, 0x7c, 0x36, 0x68, 0x02, 0xdc,
  12424. 0xa2, 0xda, 0xef, 0xd7, 0xf1, 0x3e, 0x81, 0xb3, 0x5d, 0x2f,
  12425. 0xcf, 0x7e, 0xe6, 0x9c, 0xa0, 0x32, 0x29, 0x8b, 0x52, 0x24,
  12426. 0xbd, 0x0d, 0x36, 0xdc, 0x1d, 0xcc, 0x6a, 0x0a, 0x74, 0x52,
  12427. 0x1b, 0x68, 0x4d, 0x15, 0x05, 0x47, 0xe1, 0x2f, 0x97, 0x45,
  12428. 0x52, 0x17, 0x4b, 0x2a, 0x3b, 0x74, 0xc5, 0x20, 0x35, 0x5c,
  12429. 0x37, 0xae, 0xe6, 0xa7, 0x24, 0x0f, 0x34, 0x70, 0xea, 0x7c,
  12430. 0x03, 0xa3, 0xde, 0x2d, 0x22, 0x55, 0x88, 0x01, 0x45, 0xf2,
  12431. 0x5f, 0x1f, 0xaf, 0x3b, 0xb1, 0xa6, 0x5d, 0xcd, 0x93, 0xfb,
  12432. 0xf8, 0x2f, 0x87, 0xcc, 0x26, 0xc5, 0x36, 0xde, 0x06, 0x9b,
  12433. 0xe9, 0xa7, 0x66, 0x7e, 0x8c, 0xcd, 0x99, 0x6b, 0x51, 0x1c,
  12434. 0xb0, 0xa0, 0xfa, 0xc7, 0x46, 0xfe, 0x65, 0xe4, 0x80, 0x5b,
  12435. 0x5f, 0x24, 0x3b, 0xa4, 0xe6, 0x81, 0x31, 0xe5, 0x87, 0x2c,
  12436. 0xa4, 0x83, 0xaf, 0x8b, 0x9f, 0x89, 0xb4, 0x3c, 0x7a, 0xbe,
  12437. 0x4c, 0xb3, 0xbf, 0x3d, 0xec, 0x78, 0xb0, 0x8a, 0xdd, 0xc8,
  12438. 0x43, 0x8c, 0x45, 0xa1, 0xa3, 0x3a, 0x82, 0x7d, 0x06, 0xdf,
  12439. 0x20, 0x27, 0x9b, 0x4e, 0x09, 0x90, 0x6a, 0x23, 0xbf, 0x1b,
  12440. 0x04, 0x1d, 0x50, 0xe2, 0xb4, 0xff, 0xe0, 0xd0, 0x9b, 0x40,
  12441. 0x2b, 0xc0, 0x52, 0xc1, 0x39, 0x29, 0x60, 0x83, 0x06, 0x9b,
  12442. 0x48, 0xb8, 0xa7, 0xe1, 0x2b, 0xfb, 0xf0, 0x2b, 0x82, 0xf1,
  12443. 0xda, 0xc9, 0x30, 0x47, 0x3f, 0xf5, 0xf9, 0xf7, 0x6c, 0xf0,
  12444. 0x0f, 0xe7, 0xb1, 0x4d, 0x46, 0x49, 0xf8, 0xb3, 0xe1, 0xfe,
  12445. 0x85, 0x61, 0xcc, 0xf7, 0xfa, 0xd2, 0xf1, 0xbc, 0xf0, 0x7f,
  12446. 0x3b, 0xe6, 0x45, 0xa2, 0x1b, 0x55, 0xf6, 0x0c, 0x02, 0x95,
  12447. 0xdc, 0x78, 0x94, 0xa0, 0xc4, 0x6a, 0x21, 0x7e, 0xa8, 0x5f,
  12448. 0xbd, 0xc3, 0xb3, 0x4d, 0x9b, 0x30, 0x31, 0x1d, 0x5b, 0x8b,
  12449. 0x45, 0x3c, 0x18, 0xe9, 0x61, 0xe8, 0x76, 0x3e, 0x91, 0xd2,
  12450. 0xfd, 0x1a, 0xd7, 0x30, 0x4d, 0xfe, 0xef, 0x7f, 0xc0, 0x7e,
  12451. 0x45, 0x43, 0xe9, 0xf9, 0x23, 0xfe, 0xd8, 0xef, 0xbc, 0xd6,
  12452. 0x99, 0x79, 0x54, 0xed, 0x7a, 0x8b, 0x39, 0xa6, 0xe7, 0x9d,
  12453. 0x3f, 0x9f, 0x35, 0xe1, 0xe4, 0xd5, 0x26, 0x31, 0x3a, 0x44,
  12454. 0x03, 0x79, 0xde, 0xdc, 0x29, 0x1e, 0x8e, 0x26, 0x41, 0xc6,
  12455. 0x60, 0xaa, 0xfd, 0xe1, 0x5e, 0xa6, 0xc0, 0x2f, 0x90, 0x1e,
  12456. 0x3b, 0xc1, 0xe6, 0xf6, 0xde, 0x60, 0x87, 0x57, 0x51, 0x11,
  12457. 0x6a, 0x8e, 0x9d, 0x70, 0x9d, 0x6d, 0x36, 0x21, 0x05, 0x55,
  12458. 0xc1, 0x56, 0x9b, 0xc9, 0x91, 0x50, 0x3e, 0xb4, 0xbd, 0x19,
  12459. 0x53, 0x44, 0x99, 0xc7, 0xb8, 0xce, 0xce, 0x86, 0x06, 0x5d,
  12460. 0x99, 0x85, 0x33, 0xd4, 0x16, 0x21, 0x4a, 0xe9, 0x7e, 0x2e,
  12461. 0xcc, 0x7e, 0x3f, 0xc1, 0x47, 0x3b, 0x32, 0xd0, 0x57, 0x1c,
  12462. 0xc2, 0x26, 0x67, 0xf0, 0xd9, 0xc4, 0x9e, 0xbb, 0x65, 0xa4,
  12463. 0xf7, 0xf7, 0x8d, 0x7d, 0x08, 0xd4, 0x9c, 0x1e, 0x0f, 0xb9,
  12464. 0xff, 0x24, 0x2f, 0xaf, 0xfa, 0x24, 0x26, 0xb7, 0xb1, 0x78,
  12465. 0xc1, 0xd1, 0xfe, 0x85, 0x55, 0xa0, 0x86, 0x77, 0xf6, 0xc2,
  12466. 0xe0, 0x12, 0xe4, 0x45, 0x85, 0xd0, 0xe7, 0x68, 0xf0, 0x31,
  12467. 0x4c, 0x9c, 0xb0, 0x5f, 0x89, 0xca, 0xfe, 0xc2, 0xf0, 0x1e,
  12468. 0xeb, 0xee, 0x75, 0x64, 0xea, 0x09, 0xd4, 0x1c, 0x72, 0x12,
  12469. 0xd4, 0x31, 0xf0, 0x89, 0x71, 0x74, 0x6e, 0x01, 0x32, 0xca,
  12470. 0x8a, 0x91, 0x0c, 0xdf, 0xd7, 0x05, 0xe9, 0x35, 0xed, 0x06,
  12471. 0x1a, 0x17, 0x5a, 0xf3, 0x65, 0xc5, 0xbd, 0x37, 0xf2, 0x53,
  12472. 0x49, 0x2f, 0xcd, 0xc6, 0x15, 0xb3, 0x36, 0x88, 0xd8, 0x7a,
  12473. 0x2f, 0xfa, 0x21, 0x7f, 0x55, 0x20, 0xc6, 0xf4, 0x23, 0x59,
  12474. 0x6b, 0x3c, 0xeb, 0xe5, 0xd3, 0x78, 0xdc, 0x31, 0xeb, 0x87,
  12475. 0x86, 0x3d, 0x7c, 0x10, 0x64, 0x66, 0xa4, 0xad, 0x07, 0xe1,
  12476. 0x93, 0x15, 0x07, 0x4c, 0xe4, 0xb4, 0x4a, 0x06, 0xca, 0x2a,
  12477. 0x50, 0xa2, 0x85, 0xc6, 0xa1, 0x19, 0x89, 0x7f, 0x8a, 0x05,
  12478. 0x00, 0x23, 0x72, 0x5f, 0x89, 0x74, 0x8e, 0x22, 0xa1, 0x5d,
  12479. 0x26, 0xf9, 0xfe, 0xdf, 0x6d, 0x98, 0x3a, 0xc4, 0x7c, 0x93,
  12480. 0xcf, 0xc4, 0xfe, 0xed, 0x98, 0xb0, 0x31, 0x4c, 0x81, 0x83,
  12481. 0x0d, 0x5d, 0x3d, 0x0c, 0x27, 0x4e, 0xca, 0xcf, 0x38, 0x0c,
  12482. 0x37, 0xb0, 0xf8, 0xc5, 0xc8, 0x52, 0x14, 0xec, 0x53, 0x80,
  12483. 0xb9, 0xd8, 0x8a, 0x05, 0x4e, 0x31, 0x3d, 0x67, 0x57, 0xf0,
  12484. 0x7a, 0xa2, 0xc5, 0xc9, 0x02, 0x25, 0x69, 0x83, 0xb9, 0x3e,
  12485. 0x1b, 0x04, 0xbf, 0xb2, 0xe6, 0x97, 0x7a, 0x6b, 0x8e, 0x37,
  12486. 0x77, 0x2e, 0x16, 0x8b, 0x33, 0xe1, 0xea, 0x2b, 0x30, 0x01,
  12487. 0x6e, 0xa0, 0x28, 0x14, 0x17, 0xe9, 0x98, 0xa8, 0x89, 0x72,
  12488. 0x68, 0x64, 0x81, 0x60, 0xa8, 0xf7, 0x72, 0xdf, 0x1a, 0xae,
  12489. 0xf5, 0xf0, 0x9f, 0x69, 0x35, 0xbc, 0x58, 0x27, 0x38, 0xd6,
  12490. 0x7f, 0x7a, 0xd4, 0xc4, 0xf1, 0xcf, 0xee, 0x59, 0x49, 0x31,
  12491. 0xda, 0xc1, 0x08, 0x46, 0x65, 0x68, 0xe9, 0x44, 0x18, 0x2b,
  12492. 0xf2, 0x2a, 0x13, 0x60, 0x07, 0xae, 0xe4, 0x96, 0xdb, 0x0a,
  12493. 0x6f, 0x52, 0x23, 0x9a, 0xcf, 0x9d, 0xa4, 0xc5, 0xc1, 0x74,
  12494. 0xa8, 0x0e, 0xe1, 0x5e, 0xfa, 0xa4, 0x06, 0x9c, 0x2e, 0x70,
  12495. 0x08, 0x22, 0x25, 0x4f, 0xc1, 0xf1, 0x13, 0x5a, 0x66, 0xa0,
  12496. 0x6c, 0x59, 0xa3, 0xfc, 0x03, 0x9c, 0x8a, 0x23, 0x01, 0x00,
  12497. 0xa9, 0x49, 0xf0, 0x22, 0xa3, 0x8f, 0x6c, 0xef, 0xcb, 0x69,
  12498. 0x06, 0x3a, 0x69, 0x99, 0x96, 0xd2, 0xa7, 0xa0, 0x0b, 0x7e,
  12499. 0x44, 0x7d, 0x04, 0xff, 0x7e, 0x9e, 0x1e, 0x77, 0xa0, 0x30,
  12500. 0xd1, 0xdf, 0x18, 0xe4, 0xd8, 0xa5, 0x64, 0xbe, 0x8c, 0x80,
  12501. 0x28, 0xe2, 0x98, 0x5e, 0xec, 0x9e, 0xb1, 0x0a, 0xb5, 0x25,
  12502. 0xaa, 0xb8, 0x0f, 0x78, 0x30, 0x48, 0x06, 0xe5, 0x76, 0xf9,
  12503. 0x24, 0x96, 0x87, 0x2a, 0x91, 0x89, 0xb6, 0xce, 0x04, 0xdf,
  12504. 0xfc, 0x13, 0x42, 0x19, 0xba, 0x14, 0x46, 0x20, 0x08, 0x47,
  12505. 0xe1, 0x82, 0x57, 0x51, 0x74, 0x3b, 0x5b, 0x23, 0x5c, 0xb2,
  12506. 0x85, 0x8c, 0xed, 0xe6, 0xda, 0x4d, 0x56, 0xe8, 0x61, 0x31,
  12507. 0xec, 0x97, 0x27, 0xeb, 0xf2, 0xa7, 0x7c, 0x13, 0x1b, 0xc5,
  12508. 0x44, 0xfe, 0x63, 0x4b, 0x2b, 0x33, 0x22, 0x23, 0x60, 0x86,
  12509. 0x7c, 0x3b, 0x57, 0xba, 0x16, 0xde, 0x47, 0x04, 0x3e, 0x2b,
  12510. 0xe5, 0xbd, 0x23, 0xa0, 0xab, 0xdf, 0x5d, 0x6e, 0x20, 0xb1,
  12511. 0x37, 0x44, 0xcb, 0xbd, 0x03, 0xa9, 0x5c, 0xe6, 0x92, 0x5e,
  12512. 0x2f, 0x6f, 0x95, 0xc6, 0x5b, 0x6d, 0xab, 0x39, 0xdd, 0x1e,
  12513. 0x34, 0xd5, 0x21, 0xca, 0x92, 0xee, 0x59, 0xf0, 0xb9, 0x65,
  12514. 0xe6, 0x81, 0x49, 0xf8, 0x11, 0xec, 0x45, 0x14, 0x6a, 0x19,
  12515. 0xb4, 0xce, 0xbf, 0x9e, 0xf7, 0x32, 0x8d, 0x99, 0x78, 0xc3,
  12516. 0x07, 0x3d, 0xfd, 0x18, 0x2d, 0x0e, 0x06, 0x2f, 0x27, 0x24,
  12517. 0x6f, 0x16, 0xd8, 0x01, 0x33, 0xc8, 0xbb, 0x7f, 0x7d, 0xfa,
  12518. 0x73, 0xf6, 0x7d, 0x54, 0xf2, 0xd4, 0x8a, 0x53, 0xe1, 0x62,
  12519. 0x45, 0xf4, 0x01, 0xa6, 0x31, 0x6b, 0x3a, 0x06, 0x56, 0xfd,
  12520. 0x79, 0x7f, 0x58, 0xd8, 0x47, 0x33, 0x53, 0xc5, 0x78, 0x70,
  12521. 0xce, 0x81, 0x7f, 0x66, 0xa1, 0x58, 0x7c, 0x5a, 0xdb, 0x4a,
  12522. 0xad, 0x29, 0xff, 0x93, 0x75, 0x95, 0x35, 0xa9, 0xd2, 0xb1,
  12523. 0xeb, 0xa0, 0x4f, 0x10, 0x0a, 0xc9, 0x38, 0x69, 0xc8, 0x8d,
  12524. 0x57, 0xef, 0x99, 0x0f, 0xa5, 0x69, 0x86, 0xa6, 0xfb, 0x2b,
  12525. 0x37, 0xe4, 0xc7, 0xab, 0x3e, 0xcd, 0x8f, 0x3f, 0x93, 0x8c,
  12526. 0x0b, 0xc4, 0x4d, 0x16, 0xe0, 0xb0, 0x94, 0x5a, 0x0d, 0x17,
  12527. 0xaf, 0x6e, 0x4b, 0x2e, 0x18, 0x29, 0x0e, 0xe0, 0xf5, 0x72,
  12528. 0x1a, 0x21, 0x37, 0xef, 0x7d, 0x6a, 0x39, 0xe9, 0xa8, 0xd7,
  12529. 0x96, 0xd6, 0xb3, 0x7d, 0x83, 0x0c, 0x13, 0x30, 0x49, 0x03,
  12530. 0xe8, 0x6b, 0xe6, 0x77, 0xe8, 0x69, 0x48, 0x56, 0x5f, 0x39,
  12531. 0x63, 0xbc, 0x86, 0xa8, 0x26, 0xa1, 0xbd, 0x4b, 0x24, 0xbd,
  12532. 0xdd, 0xe8, 0x02, 0x64, 0xcb, 0xae, 0x24, 0x17, 0x62, 0xbd,
  12533. 0x27, 0xa7, 0x22, 0x60, 0x51, 0x0c, 0x53, 0xff, 0x9d, 0x63,
  12534. 0x1b, 0xf9, 0xff, 0x76, 0x3b, 0x74, 0x05, 0x98, 0x46, 0x0b,
  12535. 0xe8, 0xcb, 0xd4, 0x0a, 0xcd, 0x91, 0xdb, 0x5b, 0x21, 0x4d,
  12536. 0xa1, 0x87, 0xbd, 0xb7, 0x58, 0xec, 0x28, 0x00, 0x92, 0xc2,
  12537. 0x98, 0xe4, 0x8c, 0x1f, 0x9d, 0xa4, 0x80, 0x83, 0x40, 0xb9,
  12538. 0x63, 0xfe, 0xc9, 0x18, 0x3f, 0xd6, 0xab, 0x34, 0x00, 0x2c,
  12539. 0x53, 0x40, 0x38, 0x0e, 0xb1, 0x69, 0xa8, 0xb8, 0xa9, 0x2e,
  12540. 0x9b, 0x7b, 0x89, 0x8d, 0xff, 0x86, 0x01, 0x51, 0x42, 0xde,
  12541. 0x04, 0xd6, 0x1d, 0xd1, 0x29, 0x8d, 0x42, 0x46, 0x5f, 0xd6,
  12542. 0x02, 0xde, 0x73, 0xee, 0x2d, 0xe9, 0x6e, 0xb0, 0x3f, 0xf0,
  12543. 0x47, 0x72, 0xfe, 0x45, 0xff, 0x05, 0x82, 0x2d, 0xc6, 0x4f,
  12544. 0xc9, 0xd3, 0xec, 0xf9, 0x5a, 0x22, 0x50, 0x6c, 0x4f, 0x1e,
  12545. 0xc8, 0x5f, 0xfc, 0x2c, 0x04, 0x4f, 0xdf, 0xce, 0xe4, 0x18,
  12546. 0xd2, 0xd7, 0x8b, 0x67, 0x83, 0x39, 0x96, 0x47, 0x5e, 0x5b,
  12547. 0xad, 0x7f, 0x5d, 0x42, 0x56, 0x97, 0x71, 0x39, 0x28, 0x44,
  12548. 0x9d, 0x35, 0xde, 0xde, 0x03, 0x20, 0x34, 0x44, 0xdb, 0xdf,
  12549. 0xfc, 0xff, 0x1e, 0x3d, 0x58, 0x5f, 0x7a, 0x8e, 0x90, 0xa1,
  12550. 0xd3, 0xeb, 0x0c, 0x23, 0x3f, 0x4e, 0x61, 0x77, 0x79, 0xb2,
  12551. 0xdc, 0xfb, 0x21, 0x46, 0x5c, 0x82, 0xb6, 0xf6, 0x34, 0x3c,
  12552. 0x3f, 0x45, 0x4b, 0x80, 0x9e, 0xa4, 0xe6, 0x02, 0x13, 0x38,
  12553. 0x40, 0x7e, 0x87, 0x92, 0x96, 0x51, 0x63, 0x87, 0xae, 0xc8,
  12554. 0x02, 0x6a, 0x70, 0xc8, 0xcd, 0xd0, 0xe2, 0x00, 0x00, 0x00,
  12555. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
  12556. 0x12, 0x1c, 0x22, 0x2b, 0x33, 0x38, 0x3f,
  12557. };
  12558. static const int sizeof_bench_dilithium_level5_sig =
  12559. sizeof(bench_dilithium_level5_sig);
  12560. #endif
  12561. #endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
  12562. void bench_dilithiumKeySign(byte level)
  12563. {
  12564. int ret = 0;
  12565. dilithium_key key;
  12566. double start;
  12567. int i, count;
  12568. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12569. byte sig[DILITHIUM_MAX_SIG_SIZE];
  12570. byte msg[512];
  12571. word32 x = 0;
  12572. #endif
  12573. const char**desc = bench_desc_words[lng_index];
  12574. DECLARE_MULTI_VALUE_STATS_VARS()
  12575. byte params = 0;
  12576. if (level == 2) {
  12577. params = 44;
  12578. }
  12579. else if (level == 3) {
  12580. params = 65;
  12581. }
  12582. else if (level == 5) {
  12583. params = 87;
  12584. }
  12585. #if !defined(WOLFSSL_DILITHIUM_NO_SIGN) || !defined(WOLFSSL_DILITHIUM_NO_VERIFY)
  12586. /* make dummy msg */
  12587. for (i = 0; i < (int)sizeof(msg); i++) {
  12588. msg[i] = (byte)i;
  12589. }
  12590. #endif
  12591. ret = wc_dilithium_init(&key);
  12592. if (ret != 0) {
  12593. printf("wc_dilithium_init failed %d\n", ret);
  12594. return;
  12595. }
  12596. ret = wc_dilithium_set_level(&key, level);
  12597. if (ret != 0) {
  12598. printf("wc_dilithium_set_level() failed %d\n", ret);
  12599. }
  12600. #ifndef WOLFSSL_DILITHIUM_NO_MAKE_KEY
  12601. bench_stats_start(&count, &start);
  12602. do {
  12603. for (i = 0; i < agreeTimes; i++) {
  12604. ret = wc_dilithium_make_key(&key, GLOBAL_RNG);
  12605. if (ret != 0) {
  12606. printf("wc_dilithium_import_private_key failed %d\n", ret);
  12607. return;
  12608. }
  12609. }
  12610. count += i;
  12611. } while (bench_stats_check(start)
  12612. #ifdef MULTI_VALUE_STATISTICS
  12613. || runs < minimum_runs
  12614. #endif
  12615. );
  12616. if (ret == 0) {
  12617. bench_stats_asym_finish("ML-DSA", params, desc[2], 0, count,
  12618. start, ret);
  12619. #ifdef MULTI_VALUE_STATISTICS
  12620. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12621. #endif
  12622. }
  12623. #elif !defined WOLFSSL_DILITHIUM_NO_SIGN
  12624. #ifndef WOLFSSL_NO_ML_DSA_44
  12625. if (level == 2) {
  12626. ret = wc_dilithium_import_private(bench_dilithium_level2_key,
  12627. sizeof_bench_dilithium_level2_key, &key);
  12628. }
  12629. #endif
  12630. #ifndef WOLFSSL_NO_ML_DSA_65
  12631. if (level == 3) {
  12632. ret = wc_dilithium_import_private(bench_dilithium_level3_key,
  12633. sizeof_bench_dilithium_level3_key, &key);
  12634. }
  12635. #endif
  12636. #ifndef WOLFSSL_NO_ML_DSA_87
  12637. if (level == 5) {
  12638. ret = wc_dilithium_import_private(bench_dilithium_level5_key,
  12639. sizeof_bench_dilithium_level5_key, &key);
  12640. }
  12641. #endif
  12642. if (ret != 0) {
  12643. printf("Failed to load private key\n");
  12644. return;
  12645. }
  12646. #endif
  12647. #ifndef WOLFSSL_DILITHIUM_NO_SIGN
  12648. if (level == 2) {
  12649. x = DILITHIUM_LEVEL2_SIG_SIZE;
  12650. }
  12651. else if (level == 3) {
  12652. x = DILITHIUM_LEVEL3_SIG_SIZE;
  12653. }
  12654. else {
  12655. x = DILITHIUM_LEVEL5_SIG_SIZE;
  12656. }
  12657. RESET_MULTI_VALUE_STATS_VARS();
  12658. bench_stats_start(&count, &start);
  12659. do {
  12660. for (i = 0; i < agreeTimes; i++) {
  12661. if (ret == 0) {
  12662. ret = wc_dilithium_sign_msg(msg, sizeof(msg), sig, &x, &key,
  12663. GLOBAL_RNG);
  12664. if (ret != 0) {
  12665. printf("wc_dilithium_sign_msg failed\n");
  12666. }
  12667. }
  12668. RECORD_MULTI_VALUE_STATS();
  12669. }
  12670. count += i;
  12671. } while (bench_stats_check(start)
  12672. #ifdef MULTI_VALUE_STATISTICS
  12673. || runs < minimum_runs
  12674. #endif
  12675. );
  12676. if (ret == 0) {
  12677. bench_stats_asym_finish("ML-DSA", params, desc[4], 0, count, start,
  12678. ret);
  12679. #ifdef MULTI_VALUE_STATISTICS
  12680. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12681. #endif
  12682. }
  12683. #endif
  12684. #if !defined(WOLFSSL_DILITHIUM_NO_VERIFY) && \
  12685. (defined(WOLFSSL_DILITHIUM_NO_SIGN) || \
  12686. defined(WOLFSSL_DILITHIUM_NO_MAKE_KEY))
  12687. #ifndef WOLFSSL_NO_ML_DSA_44
  12688. if (level == 2) {
  12689. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12690. x = sizeof_bench_dilithium_level2_sig;
  12691. XMEMCPY(sig, bench_dilithium_level2_sig, x);
  12692. #endif
  12693. ret = wc_dilithium_import_public(bench_dilithium_level2_pubkey,
  12694. sizeof_bench_dilithium_level2_pubkey, &key);
  12695. }
  12696. #endif
  12697. #ifndef WOLFSSL_NO_ML_DSA_65
  12698. if (level == 3) {
  12699. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12700. x = sizeof_bench_dilithium_level3_sig;
  12701. XMEMCPY(sig, bench_dilithium_level3_sig, x);
  12702. #endif
  12703. ret = wc_dilithium_import_public(bench_dilithium_level3_pubkey,
  12704. sizeof_bench_dilithium_level3_pubkey, &key);
  12705. }
  12706. #endif
  12707. #ifndef WOLFSSL_NO_ML_DSA_87
  12708. if (level == 5) {
  12709. #ifdef WOLFSSL_DILITHIUM_NO_SIGN
  12710. x = sizeof_bench_dilithium_level5_sig;
  12711. XMEMCPY(sig, bench_dilithium_level5_sig, x);
  12712. #endif
  12713. ret = wc_dilithium_import_public(bench_dilithium_level5_pubkey,
  12714. sizeof_bench_dilithium_level5_pubkey, &key);
  12715. }
  12716. #endif
  12717. if (ret != 0) {
  12718. printf("Failed to load public key\n");
  12719. return;
  12720. }
  12721. #endif
  12722. #ifndef WOLFSSL_DILITHIUM_NO_VERIFY
  12723. RESET_MULTI_VALUE_STATS_VARS();
  12724. bench_stats_start(&count, &start);
  12725. do {
  12726. for (i = 0; i < agreeTimes; i++) {
  12727. if (ret == 0) {
  12728. int verify = 0;
  12729. ret = wc_dilithium_verify_msg(sig, x, msg, sizeof(msg),
  12730. &verify, &key);
  12731. if (ret != 0 || verify != 1) {
  12732. printf("wc_dilithium_verify_msg failed %d, verify %d\n",
  12733. ret, verify);
  12734. ret = -1;
  12735. }
  12736. }
  12737. RECORD_MULTI_VALUE_STATS();
  12738. }
  12739. count += i;
  12740. } while (bench_stats_check(start)
  12741. #ifdef MULTI_VALUE_STATISTICS
  12742. || runs < minimum_runs
  12743. #endif
  12744. );
  12745. if (ret == 0) {
  12746. bench_stats_asym_finish("ML-DSA", params, desc[5], 0, count, start,
  12747. ret);
  12748. #ifdef MULTI_VALUE_STATISTICS
  12749. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12750. #endif
  12751. }
  12752. #endif
  12753. wc_dilithium_free(&key);
  12754. }
  12755. #endif /* HAVE_DILITHIUM */
  12756. #ifdef HAVE_SPHINCS
  12757. void bench_sphincsKeySign(byte level, byte optim)
  12758. {
  12759. int ret = 0;
  12760. sphincs_key key;
  12761. double start;
  12762. int i, count;
  12763. byte sig[SPHINCS_MAX_SIG_SIZE];
  12764. byte msg[512];
  12765. word32 x = 0;
  12766. const char**desc = bench_desc_words[lng_index];
  12767. DECLARE_MULTI_VALUE_STATS_VARS()
  12768. ret = wc_sphincs_init(&key);
  12769. if (ret != 0) {
  12770. printf("wc_sphincs_init failed %d\n", ret);
  12771. return;
  12772. }
  12773. ret = wc_sphincs_set_level_and_optim(&key, level, optim);
  12774. if (ret != 0) {
  12775. printf("wc_sphincs_set_level_and_optim() failed %d\n", ret);
  12776. }
  12777. if (ret == 0) {
  12778. ret = -1;
  12779. if ((level == 1) && (optim == FAST_VARIANT)) {
  12780. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level1_key,
  12781. sizeof_bench_sphincs_fast_level1_key, NULL, 0, &key);
  12782. }
  12783. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12784. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level3_key,
  12785. sizeof_bench_sphincs_fast_level3_key, NULL, 0, &key);
  12786. }
  12787. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12788. ret = wc_sphincs_import_private_key(bench_sphincs_fast_level5_key,
  12789. sizeof_bench_sphincs_fast_level5_key, NULL, 0, &key);
  12790. }
  12791. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12792. ret = wc_sphincs_import_private_key(
  12793. bench_sphincs_small_level1_key,
  12794. sizeof_bench_sphincs_small_level1_key, NULL, 0, &key);
  12795. }
  12796. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12797. ret = wc_sphincs_import_private_key(
  12798. bench_sphincs_small_level3_key,
  12799. sizeof_bench_sphincs_small_level3_key, NULL, 0, &key);
  12800. }
  12801. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12802. ret = wc_sphincs_import_private_key(
  12803. bench_sphincs_small_level5_key,
  12804. sizeof_bench_sphincs_small_level5_key, NULL, 0, &key);
  12805. }
  12806. if (ret != 0) {
  12807. printf("wc_sphincs_import_private_key failed %d\n", ret);
  12808. }
  12809. }
  12810. /* make dummy msg */
  12811. for (i = 0; i < (int)sizeof(msg); i++) {
  12812. msg[i] = (byte)i;
  12813. }
  12814. bench_stats_start(&count, &start);
  12815. do {
  12816. for (i = 0; i < agreeTimes; i++) {
  12817. if (ret == 0) {
  12818. if ((level == 1) && (optim == FAST_VARIANT)) {
  12819. x = SPHINCS_FAST_LEVEL1_SIG_SIZE;
  12820. }
  12821. else if ((level == 3) && (optim == FAST_VARIANT)) {
  12822. x = SPHINCS_FAST_LEVEL3_SIG_SIZE;
  12823. }
  12824. else if ((level == 5) && (optim == FAST_VARIANT)) {
  12825. x = SPHINCS_FAST_LEVEL5_SIG_SIZE;
  12826. }
  12827. else if ((level == 1) && (optim == SMALL_VARIANT)) {
  12828. x = SPHINCS_SMALL_LEVEL1_SIG_SIZE;
  12829. }
  12830. else if ((level == 3) && (optim == SMALL_VARIANT)) {
  12831. x = SPHINCS_SMALL_LEVEL3_SIG_SIZE;
  12832. }
  12833. else if ((level == 5) && (optim == SMALL_VARIANT)) {
  12834. x = SPHINCS_SMALL_LEVEL5_SIG_SIZE;
  12835. }
  12836. ret = wc_sphincs_sign_msg(msg, sizeof(msg), sig, &x, &key, GLOBAL_RNG);
  12837. if (ret != 0) {
  12838. printf("wc_sphincs_sign_msg failed\n");
  12839. }
  12840. }
  12841. RECORD_MULTI_VALUE_STATS();
  12842. }
  12843. count += i;
  12844. } while (bench_stats_check(start)
  12845. #ifdef MULTI_VALUE_STATISTICS
  12846. || runs < minimum_runs
  12847. #endif
  12848. );
  12849. if (ret == 0) {
  12850. if (optim == FAST_VARIANT) {
  12851. bench_stats_asym_finish("SPHINCS-FAST", level, desc[4], 0, count,
  12852. start, ret);
  12853. }
  12854. else {
  12855. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[4], 0, count,
  12856. start, ret);
  12857. }
  12858. #ifdef MULTI_VALUE_STATISTICS
  12859. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12860. #endif
  12861. }
  12862. RESET_MULTI_VALUE_STATS_VARS();
  12863. bench_stats_start(&count, &start);
  12864. do {
  12865. for (i = 0; i < agreeTimes; i++) {
  12866. if (ret == 0) {
  12867. int verify = 0;
  12868. ret = wc_sphincs_verify_msg(sig, x, msg, sizeof(msg), &verify,
  12869. &key);
  12870. if (ret != 0 || verify != 1) {
  12871. printf("wc_sphincs_verify_msg failed %d, verify %d\n",
  12872. ret, verify);
  12873. ret = -1;
  12874. }
  12875. }
  12876. RECORD_MULTI_VALUE_STATS();
  12877. }
  12878. count += i;
  12879. } while (bench_stats_check(start)
  12880. #ifdef MULTI_VALUE_STATISTICS
  12881. || runs < minimum_runs
  12882. #endif
  12883. );
  12884. if (ret == 0) {
  12885. if (optim == FAST_VARIANT) {
  12886. bench_stats_asym_finish("SPHINCS-FAST", level, desc[5], 0, count,
  12887. start, ret);
  12888. }
  12889. else {
  12890. bench_stats_asym_finish("SPHINCS-SMALL", level, desc[5], 0, count,
  12891. start, ret);
  12892. }
  12893. #ifdef MULTI_VALUE_STATISTICS
  12894. bench_multi_value_stats(max, min, sum, squareSum, runs);
  12895. #endif
  12896. }
  12897. wc_sphincs_free(&key);
  12898. }
  12899. #endif /* HAVE_SPHINCS */
  12900. #if defined(_WIN32) && !defined(INTIME_RTOS)
  12901. #define WIN32_LEAN_AND_MEAN
  12902. #include <windows.h>
  12903. double current_time(int reset)
  12904. {
  12905. static int init = 0;
  12906. static LARGE_INTEGER freq;
  12907. LARGE_INTEGER count;
  12908. (void)reset;
  12909. if (!init) {
  12910. QueryPerformanceFrequency(&freq);
  12911. init = 1;
  12912. }
  12913. QueryPerformanceCounter(&count);
  12914. #ifdef BENCH_MICROSECOND
  12915. return ((double)count.QuadPart * 1000000) / freq.QuadPart;
  12916. #else
  12917. return (double)count.QuadPart / freq.QuadPart;
  12918. #endif
  12919. }
  12920. #elif defined MICROCHIP_PIC32
  12921. #if defined(WOLFSSL_MICROCHIP_PIC32MZ)
  12922. #define CLOCK 80000000.0
  12923. #else
  12924. #define CLOCK 40000000.0
  12925. #endif
  12926. extern void WriteCoreTimer(word32 t);
  12927. extern word32 ReadCoreTimer(void);
  12928. double current_time(int reset)
  12929. {
  12930. unsigned int ns;
  12931. if (reset) {
  12932. WriteCoreTimer(0);
  12933. }
  12934. /* get timer in ns */
  12935. ns = ReadCoreTimer();
  12936. /* return seconds as a double */
  12937. return ( ns / CLOCK * 2.0);
  12938. }
  12939. #elif defined(WOLFSSL_IAR_ARM_TIME) || defined (WOLFSSL_MDK_ARM) || \
  12940. defined(WOLFSSL_USER_CURRTIME) || defined(WOLFSSL_CURRTIME_REMAP)
  12941. /* declared above at line 239 */
  12942. /* extern double current_time(int reset); */
  12943. #elif defined(FREERTOS)
  12944. #ifdef PLATFORMIO
  12945. #include <freertos/FreeRTOS.h>
  12946. #include <freertos/task.h>
  12947. #else
  12948. #include "task.h"
  12949. #endif
  12950. #if defined(WOLFSSL_ESPIDF)
  12951. /* prototype definition */
  12952. int construct_argv();
  12953. extern char* __argv[22];
  12954. /* current_time(reset)
  12955. *
  12956. * Benchmark passage of time, in fractional seconds.
  12957. * [reset] is non zero to adjust timer or counter to zero
  12958. *
  12959. * Use care when repeatedly calling calling. See implementation. */
  12960. double current_time(int reset)
  12961. {
  12962. double ret;
  12963. #if ESP_IDF_VERSION_MAJOR >= 4
  12964. TickType_t tickCount; /* typically 32 bit, local FreeRTOS ticks */
  12965. #else
  12966. portTickType tickCount;
  12967. #endif
  12968. #if defined(__XTENSA__)
  12969. (void)reset;
  12970. if (reset) {
  12971. /* TODO: Determine a mechanism for reset that does not interfere
  12972. * with freeRTOS tick. Using this code for Xtensa appears to cause
  12973. * RTOS tick timer to stick. See "last_tickCount unchanged".
  12974. ESP_LOGW(TAG, "Current_time() reset!");
  12975. portTICK_TYPE_ENTER_CRITICAL();
  12976. {
  12977. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12978. _esp_cpu_count_last = xthal_get_ccount();
  12979. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12980. }
  12981. portTICK_TYPE_EXIT_CRITICAL();
  12982. */
  12983. }
  12984. #else
  12985. /* Only reset the CPU counter for RISC-V */
  12986. if (reset) {
  12987. ESP_LOGV(TAG, "current_time() reset!");
  12988. /* TODO: why does Espressif esp_cpu_get_cycle_count() cause
  12989. * unexpected rollovers in return values for Xtensa but not RISC-V?
  12990. * See also esp_get_cycle_count_ex() */
  12991. #ifdef __XTENSA__
  12992. _esp_cpu_count_last = xthal_get_ccount();
  12993. #else
  12994. #if ESP_IDF_VERSION_MAJOR >= 5
  12995. esp_cpu_set_cycle_count((esp_cpu_cycle_count_t)0);
  12996. _esp_cpu_count_last = esp_cpu_get_cycle_count();
  12997. #else
  12998. cpu_hal_set_cycle_count((uint32_t)0);
  12999. _esp_cpu_count_last = cpu_hal_get_cycle_count();
  13000. #endif
  13001. #endif
  13002. }
  13003. #endif
  13004. /* tick count == ms, if configTICK_RATE_HZ is set to 1000 */
  13005. tickCount = xTaskGetTickCount(); /* RTOS ticks, not CPU cycles!
  13006. The count of ticks since vTaskStartScheduler was called,
  13007. typiclly in app_startup.c */
  13008. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13009. ESP_LOGV(TAG, "tickCount = " TFMT, tickCount);
  13010. if (tickCount == last_tickCount) {
  13011. ESP_LOGW(TAG, "last_tickCount unchanged?" TFMT, tickCount);
  13012. }
  13013. if (tickCount < last_tickCount) {
  13014. ESP_LOGW(TAG, "last_tickCount overflow?");
  13015. }
  13016. #endif
  13017. if (reset) {
  13018. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13019. ESP_LOGW(TAG, "Assign last_tickCount = " TFMT, tickCount);
  13020. #endif
  13021. last_tickCount = tickCount;
  13022. }
  13023. else {
  13024. #ifdef DEBUG_WOLFSSL_BENCHMARK_TIMING
  13025. ESP_LOGV(TAG, "No Reset last_tickCount = " TFMT, tickCount);
  13026. #endif
  13027. }
  13028. #if defined(configTICK_RATE_HZ) && defined(CONFIG_FREERTOS_HZ)
  13029. ret = (double)tickCount / configTICK_RATE_HZ;
  13030. #else
  13031. ESP_LOGW(TAG, "Warning: configTICK_RATE_HZ not defined,"
  13032. "assuming 1000 Hz.");
  13033. ret = (double)(tickCount / 1000.0);
  13034. #endif /* configTICK_RATE_HZ */
  13035. return ret;
  13036. } /* current_time */
  13037. #else
  13038. /* current_time(reset)
  13039. *
  13040. * Benchmark passage of time, in fractional seconds.
  13041. * [reset] is non zero to adjust timer or counter to zero
  13042. *
  13043. * Use care when repeatedly calling calling. See implementation. */
  13044. double current_time(int reset)
  13045. {
  13046. portTickType tickCount = xTaskGetTickCount();
  13047. /* if configTICK_RATE_HZ is available use if (default is 1000) */
  13048. #ifdef configTICK_RATE_HZ
  13049. return (double)tickCount / configTICK_RATE_HZ;
  13050. #else
  13051. return (double)tickCount / 1000;
  13052. #endif
  13053. }
  13054. #endif
  13055. #elif defined (WOLFSSL_TIRTOS)
  13056. extern double current_time(int reset);
  13057. #elif defined(FREESCALE_MQX)
  13058. double current_time(int reset)
  13059. {
  13060. TIME_STRUCT tv;
  13061. _time_get(&tv);
  13062. return (double)tv.SECONDS + (double)tv.MILLISECONDS / 1000;
  13063. }
  13064. #elif (defined(WOLFSSL_MAX3266X_OLD) || defined(WOLFSSL_MAX3266X)) \
  13065. && defined(MAX3266X_RTC)
  13066. double current_time(int reset)
  13067. {
  13068. (void)reset;
  13069. return wc_MXC_RTC_Time();
  13070. }
  13071. #elif defined(FREESCALE_KSDK_BM)
  13072. double current_time(int reset)
  13073. {
  13074. return (double)OSA_TimeGetMsec() / 1000;
  13075. }
  13076. #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2)
  13077. double current_time(int reset)
  13078. {
  13079. (void)reset;
  13080. return (double)osKernelGetTickCount() / 1000.0;
  13081. }
  13082. #elif defined(WOLFSSL_EMBOS)
  13083. #include "RTOS.h"
  13084. double current_time(int reset)
  13085. {
  13086. double time_now;
  13087. double current_s = OS_GetTime() / 1000.0;
  13088. double current_us = OS_GetTime_us() / MILLION_VALUE;
  13089. time_now = (double)( current_s + current_us);
  13090. (void) reset;
  13091. return time_now;
  13092. }
  13093. #elif defined(WOLFSSL_SGX)
  13094. double current_time(int reset);
  13095. #elif defined(WOLFSSL_DEOS)
  13096. double current_time(int reset)
  13097. {
  13098. const uint32_t systemTickTimeInHz
  13099. = 1000000 / systemTickInMicroseconds();
  13100. const volatile uint32_t *systemTickPtr = systemTickPointer();
  13101. (void)reset;
  13102. return (double) *systemTickPtr/systemTickTimeInHz;
  13103. }
  13104. #elif defined(MICRIUM)
  13105. double current_time(int reset)
  13106. {
  13107. #if (OS_VERSION < 50000)
  13108. CPU_ERR err;
  13109. (void)reset;
  13110. return (double) CPU_TS_Get32()/CPU_TS_TmrFreqGet(&err);
  13111. #else
  13112. RTOS_ERR err;
  13113. double ret = 0;
  13114. OS_TICK tick = OSTimeGet(&err);
  13115. OS_RATE_HZ rate = OSTimeTickRateHzGet(&err);
  13116. (void)reset;
  13117. if (RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE) {
  13118. ret = ((double)tick)/rate;
  13119. }
  13120. return ret;
  13121. #endif
  13122. }
  13123. #elif defined(WOLFSSL_ZEPHYR)
  13124. #include <time.h>
  13125. double current_time(int reset)
  13126. {
  13127. int64_t t;
  13128. (void)reset;
  13129. #if defined(CONFIG_ARCH_POSIX)
  13130. k_cpu_idle();
  13131. #endif
  13132. t = k_uptime_get(); /* returns current uptime in milliseconds */
  13133. return (double)(t / 1000);
  13134. }
  13135. #elif defined(WOLFSSL_NETBURNER)
  13136. #include <predef.h>
  13137. #include <utils.h>
  13138. #include <constants.h>
  13139. double current_time(int reset)
  13140. {
  13141. DWORD ticks = TimeTick; /* ticks since system start */
  13142. (void)reset;
  13143. return (double) ticks/TICKS_PER_SECOND;
  13144. }
  13145. #elif defined(WOLFSSL_RPIPICO)
  13146. #include "pico/stdlib.h"
  13147. double current_time(int reset)
  13148. {
  13149. (void)reset;
  13150. return (double) time_us_64() / 1000000;
  13151. }
  13152. #elif defined(THREADX)
  13153. #include "tx_api.h"
  13154. double current_time(int reset)
  13155. {
  13156. (void)reset;
  13157. return (double) tx_time_get() / TX_TIMER_TICKS_PER_SECOND;
  13158. }
  13159. #elif defined(WOLFSSL_XILINX)
  13160. #ifdef XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13161. #define COUNTS_PER_SECOND \
  13162. XPAR_VERSAL_CIPS_0_PSPMC_0_PSV_CORTEXA72_0_TIMESTAMP_CLK_FREQ
  13163. #else
  13164. #define COUNTS_PER_SECOND \
  13165. XPAR_CPU_CORTEXA53_0_TIMESTAMP_CLK_FREQ
  13166. #endif
  13167. double current_time(int reset)
  13168. {
  13169. double timer;
  13170. uint64_t cntPct = 0;
  13171. asm volatile("mrs %0, CNTPCT_EL0" : "=r" (cntPct));
  13172. /* Convert to milliseconds */
  13173. timer = (double)(cntPct / (COUNTS_PER_SECOND / 1000));
  13174. /* Convert to seconds.millisecond */
  13175. timer /= 1000;
  13176. return timer;
  13177. }
  13178. #elif defined(LINUX_RUSAGE_UTIME)
  13179. #include <sys/time.h>
  13180. #include <sys/resource.h>
  13181. static struct rusage base_rusage;
  13182. static struct rusage cur_rusage;
  13183. double current_time(int reset)
  13184. {
  13185. struct rusage rusage;
  13186. (void)reset;
  13187. LIBCALL_CHECK_RET(getrusage(RUSAGE_SELF, &rusage));
  13188. if (reset)
  13189. base_rusage = rusage;
  13190. else
  13191. cur_rusage = rusage;
  13192. /* only consider user time, as system time is host-related overhead
  13193. * outside wolfcrypt.
  13194. */
  13195. return (double)rusage.ru_utime.tv_sec +
  13196. (double)rusage.ru_utime.tv_usec / MILLION_VALUE;
  13197. }
  13198. static void check_for_excessive_stime(const char *desc,
  13199. const char *desc_extra)
  13200. {
  13201. double start_utime = (double)base_rusage.ru_utime.tv_sec +
  13202. (double)base_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13203. double start_stime = (double)base_rusage.ru_stime.tv_sec +
  13204. (double)base_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13205. double cur_utime = (double)cur_rusage.ru_utime.tv_sec +
  13206. (double)cur_rusage.ru_utime.tv_usec / MILLION_VALUE;
  13207. double cur_stime = (double)cur_rusage.ru_stime.tv_sec +
  13208. (double)cur_rusage.ru_stime.tv_usec / MILLION_VALUE;
  13209. double stime_utime_ratio =
  13210. (cur_stime - start_stime) / (cur_utime - start_utime);
  13211. if (stime_utime_ratio > .1)
  13212. printf("%swarning, "
  13213. "excessive system time ratio for %s%s (" FLT_FMT_PREC "%%).\n",
  13214. err_prefix, desc, desc_extra,
  13215. FLT_FMT_PREC_ARGS(3, stime_utime_ratio * 100.0));
  13216. }
  13217. #elif defined(WOLFSSL_LINUXKM)
  13218. double current_time(int reset)
  13219. {
  13220. (void)reset;
  13221. u64 ns = ktime_get_ns();
  13222. return (double)ns / 1000000000.0;
  13223. }
  13224. #else
  13225. #include <sys/time.h>
  13226. double current_time(int reset)
  13227. {
  13228. struct timespec tv;
  13229. (void)reset;
  13230. LIBCALL_CHECK_RET(clock_gettime(CLOCK_REALTIME, &tv));
  13231. #ifdef BENCH_MICROSECOND
  13232. return (double)tv.tv_sec * 1000000 + (double)tv.tv_nsec / 1000;
  13233. #else
  13234. return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000;
  13235. #endif
  13236. }
  13237. #endif /* _WIN32 */
  13238. #if defined(HAVE_GET_CYCLES)
  13239. #if defined(WOLFSSL_ESPIDF)
  13240. /* Generic CPU cycle counter for either Xtensa or RISC-V */
  13241. static WC_INLINE word64 esp_get_cpu_benchmark_cycles(void)
  13242. {
  13243. /* Reminder for long duration between calls with
  13244. * multiple overflows will not be detected. */
  13245. return esp_get_cycle_count_ex();
  13246. }
  13247. /* implement other architectures here */
  13248. #else
  13249. static WC_INLINE word64 get_intel_cycles(void)
  13250. {
  13251. unsigned int lo_c, hi_c;
  13252. __asm__ __volatile__ (
  13253. "cpuid\n\t"
  13254. "rdtsc"
  13255. : "=a"(lo_c), "=d"(hi_c) /* out */
  13256. : "a"(0) /* in */
  13257. : "%ebx", "%ecx"); /* clobber */
  13258. return ((word64)lo_c) | (((word64)hi_c) << 32);
  13259. }
  13260. #endif
  13261. #endif /* HAVE_GET_CYCLES */
  13262. void benchmark_configure(word32 block_size)
  13263. {
  13264. /* must be greater than 0 */
  13265. if (block_size > 0) {
  13266. numBlocks = (int)((word32)numBlocks * bench_size / block_size);
  13267. bench_size = block_size;
  13268. }
  13269. }
  13270. #ifndef NO_MAIN_DRIVER
  13271. #ifndef MAIN_NO_ARGS
  13272. #ifndef WOLFSSL_BENCHMARK_ALL
  13273. /* Display the algorithm string and keep to 80 characters per line.
  13274. *
  13275. * str Algorithm string to print.
  13276. * line Length of line used so far.
  13277. */
  13278. #ifndef BENCH_MAX_LINE
  13279. #define BENCH_MAX_LINE 80
  13280. #endif
  13281. static void print_alg(const char* str, int* line)
  13282. {
  13283. const char* const ident = " ";
  13284. if (*line == 0) {
  13285. printf("%s", ident);
  13286. *line = (int)XSTRLEN(ident);
  13287. }
  13288. printf(" %s", str);
  13289. *line += (int)XSTRLEN(str) + 1;
  13290. if (*line > BENCH_MAX_LINE) {
  13291. printf("\n");
  13292. *line = 0;
  13293. }
  13294. }
  13295. #endif /* WOLFSSL_BENCHMARK_ALL */
  13296. /* Display the usage options of the benchmark program. */
  13297. static void Usage(void)
  13298. {
  13299. int e = 0;
  13300. #ifndef WOLFSSL_BENCHMARK_ALL
  13301. int i;
  13302. int line;
  13303. #endif
  13304. printf("benchmark\n");
  13305. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -? */
  13306. printf("%s", bench_Usage_msg1[lng_index][e++]); /* English / Japanese */
  13307. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -csv */
  13308. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -base10 */
  13309. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13310. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -no_aad */
  13311. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -aad_size */
  13312. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -all_aad */
  13313. #else
  13314. e += 3;
  13315. #endif
  13316. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -dgst_full */
  13317. #ifndef NO_RSA
  13318. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -ras_sign */
  13319. #ifdef WOLFSSL_KEY_GEN
  13320. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -rsa-sz */
  13321. #endif
  13322. e++;
  13323. #else
  13324. e += 2;
  13325. #endif
  13326. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13327. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe2048 */
  13328. #endif
  13329. e++;
  13330. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13331. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ffdhe3072 */
  13332. #endif
  13333. e++;
  13334. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13335. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p256 */
  13336. #endif
  13337. e++;
  13338. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13339. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p384 */
  13340. #endif
  13341. e++;
  13342. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13343. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -p521 */
  13344. #endif
  13345. e++;
  13346. #if defined(HAVE_ECC)
  13347. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -ecc-all */
  13348. #endif
  13349. e++;
  13350. #ifndef WOLFSSL_BENCHMARK_ALL
  13351. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -<alg> */
  13352. line = 0;
  13353. for (i=0; bench_cipher_opt[i].str != NULL; i++)
  13354. print_alg(bench_cipher_opt[i].str, &line);
  13355. for (i=0; bench_digest_opt[i].str != NULL; i++)
  13356. print_alg(bench_digest_opt[i].str, &line);
  13357. for (i=0; bench_mac_opt[i].str != NULL; i++)
  13358. print_alg(bench_mac_opt[i].str, &line);
  13359. for (i=0; bench_kdf_opt[i].str != NULL; i++)
  13360. print_alg(bench_kdf_opt[i].str, &line);
  13361. for (i=0; bench_asym_opt[i].str != NULL; i++)
  13362. print_alg(bench_asym_opt[i].str, &line);
  13363. for (i=0; bench_other_opt[i].str != NULL; i++)
  13364. print_alg(bench_other_opt[i].str, &line);
  13365. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13366. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13367. for (i=0; bench_pq_asym_opt[i].str != NULL; i++)
  13368. print_alg(bench_pq_asym_opt[i].str, &line);
  13369. #if defined(HAVE_SPHINCS)
  13370. for (i=0; bench_pq_asym_opt2[i].str != NULL; i++)
  13371. print_alg(bench_pq_asym_opt2[i].str, &line);
  13372. #endif /* HAVE_SPHINCS */
  13373. #endif
  13374. #if defined(BENCH_PQ_STATEFUL_HBS)
  13375. for (i=0; bench_pq_hash_sig_opt[i].str != NULL; i++)
  13376. print_alg(bench_pq_hash_sig_opt[i].str, &line);
  13377. #endif /* BENCH_PQ_STATEFUL_HBS */
  13378. printf("\n");
  13379. #endif /* !WOLFSSL_BENCHMARK_ALL */
  13380. e++;
  13381. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -lng */
  13382. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option <num> */
  13383. printf("%s", bench_Usage_msg1[lng_index][e++]); /* option -blocks <num> */
  13384. #ifdef WC_ENABLE_BENCH_THREADING
  13385. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -threads <num> */
  13386. #endif
  13387. e++;
  13388. #ifdef WC_BENCH_TRACK_STATS
  13389. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -print */
  13390. #endif
  13391. e++;
  13392. #ifndef NO_FILESYSTEM
  13393. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -hash_input */
  13394. #endif
  13395. e++;
  13396. #ifndef NO_FILESYSTEM
  13397. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -cipher_input */
  13398. #endif
  13399. #ifdef MULTI_VALUE_STATISTICS
  13400. e++;
  13401. printf("%s", bench_Usage_msg1[lng_index][e]); /* option -min_runs */
  13402. #endif
  13403. }
  13404. /* Match the command line argument with the string.
  13405. *
  13406. * arg Command line argument.
  13407. * str String to check for.
  13408. * return 1 if the command line argument matches the string, 0 otherwise.
  13409. */
  13410. static int string_matches(const char* arg, const char* str)
  13411. {
  13412. return XSTRCMP(arg, str) == 0;
  13413. }
  13414. #endif /* MAIN_NO_ARGS */
  13415. /*
  13416. ** ----------------------------------------------------------------------------
  13417. ** determine how the benchmarks are called, the function name varies:
  13418. ** ----------------------------------------------------------------------------
  13419. */
  13420. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13421. #if defined(WOLFSSL_ESPIDF) || defined(_WIN32_WCE)
  13422. /* for some environments, we'll call a function wolf_benchmark_task: */
  13423. int wolf_benchmark_task(void)
  13424. #elif defined(MAIN_NO_ARGS)
  13425. /* otherwise we'll use main() with no arguments as desired: */
  13426. int main()
  13427. #else
  13428. /* else we'll be calling main with default arg parameters */
  13429. int main(int argc, char** argv)
  13430. #endif
  13431. {
  13432. /* Code for main() or wolf_benchmark_task() */
  13433. #ifdef WOLFSSL_ESPIDF
  13434. int argc = construct_argv();
  13435. char** argv = (char**)__argv;
  13436. #elif defined(MAIN_NO_ARGS)
  13437. int argc = 0;
  13438. char** argv = NULL;
  13439. #endif
  13440. return wolfcrypt_benchmark_main(argc, argv);
  13441. }
  13442. #endif /* !NO_MAIN_DRIVER && !NO_MAIN_FUNCTION */
  13443. int wolfcrypt_benchmark_main(int argc, char** argv)
  13444. {
  13445. int ret = 0;
  13446. #ifndef MAIN_NO_ARGS
  13447. int optMatched;
  13448. #ifndef WOLFSSL_BENCHMARK_ALL
  13449. int i;
  13450. #endif
  13451. #endif
  13452. benchmark_static_init(1);
  13453. printf("%s------------------------------------------------------------------------------\n",
  13454. info_prefix);
  13455. printf("%s wolfSSL version %s\n", info_prefix, LIBWOLFSSL_VERSION_STRING);
  13456. printf("%s------------------------------------------------------------------------------\n",
  13457. info_prefix);
  13458. #ifndef MAIN_NO_ARGS
  13459. while (argc > 1) {
  13460. if (string_matches(argv[1], "-?")) {
  13461. if (--argc > 1) {
  13462. lng_index = XATOI((++argv)[1]);
  13463. if (lng_index<0 || lng_index>1) {
  13464. lng_index = 0;
  13465. }
  13466. }
  13467. Usage();
  13468. return 0;
  13469. }
  13470. else if (string_matches(argv[1], "-lng")) {
  13471. argc--;
  13472. argv++;
  13473. if (argc > 1) {
  13474. lng_index = XATOI(argv[1]);
  13475. if (lng_index<0 || lng_index>1) {
  13476. printf("invalid number(%d) is specified. [<num> :0-1]\n",
  13477. lng_index);
  13478. lng_index = 0;
  13479. }
  13480. }
  13481. }
  13482. else if (string_matches(argv[1], "-base10"))
  13483. base2 = 0;
  13484. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  13485. else if (string_matches(argv[1], "-no_aad"))
  13486. aes_aad_options = AAD_SIZE_ZERO;
  13487. else if (string_matches(argv[1], "-all_aad"))
  13488. aes_aad_options |= AAD_SIZE_ZERO | AAD_SIZE_DEFAULT;
  13489. else if (string_matches(argv[1], "-aad_size")) {
  13490. argc--;
  13491. argv++;
  13492. if (argc > 1) {
  13493. aes_aad_size = (word32)XATOI(argv[1]);
  13494. aes_aad_options |= AAD_SIZE_CUSTOM;
  13495. }
  13496. }
  13497. #endif
  13498. else if (string_matches(argv[1], "-dgst_full"))
  13499. digest_stream = 0;
  13500. #ifdef HAVE_CHACHA
  13501. else if (string_matches(argv[1], "-enc_only"))
  13502. encrypt_only = 1;
  13503. #endif
  13504. #ifndef NO_RSA
  13505. else if (string_matches(argv[1], "-rsa_sign"))
  13506. rsa_sign_verify = 1;
  13507. #endif
  13508. #if !defined(NO_DH) && defined(HAVE_FFDHE_2048)
  13509. else if (string_matches(argv[1], "-ffdhe2048"))
  13510. use_ffdhe = 2048;
  13511. #endif
  13512. #if !defined(NO_DH) && defined(HAVE_FFDHE_3072)
  13513. else if (string_matches(argv[1], "-ffdhe3072"))
  13514. use_ffdhe = 3072;
  13515. #endif
  13516. #if !defined(NO_DH) && defined(HAVE_FFDHE_4096)
  13517. else if (string_matches(argv[1], "-ffdhe4096"))
  13518. use_ffdhe = 4096;
  13519. #endif
  13520. #if defined(HAVE_ECC) && !defined(NO_ECC256)
  13521. else if (string_matches(argv[1], "-p256"))
  13522. bench_asym_algs |= BENCH_ECC_P256;
  13523. #endif
  13524. #if defined(HAVE_ECC) && defined(HAVE_ECC384)
  13525. else if (string_matches(argv[1], "-p384"))
  13526. bench_asym_algs |= BENCH_ECC_P384;
  13527. #endif
  13528. #if defined(HAVE_ECC) && defined(HAVE_ECC521)
  13529. else if (string_matches(argv[1], "-p521"))
  13530. bench_asym_algs |= BENCH_ECC_P521;
  13531. #endif
  13532. #ifdef BENCH_ASYM
  13533. else if (string_matches(argv[1], "-csv")) {
  13534. csv_format = 1;
  13535. }
  13536. #endif
  13537. #ifdef WC_ENABLE_BENCH_THREADING
  13538. else if (string_matches(argv[1], "-threads")) {
  13539. argc--;
  13540. argv++;
  13541. if (argc > 1) {
  13542. g_threadCount = XATOI(argv[1]);
  13543. if (g_threadCount < 1 || lng_index > 128){
  13544. printf("invalid number(%d) is specified. [<num> :1-128]\n",
  13545. g_threadCount);
  13546. g_threadCount = 0;
  13547. }
  13548. }
  13549. }
  13550. #endif
  13551. #ifdef WC_BENCH_TRACK_STATS
  13552. else if (string_matches(argv[1], "-print")) {
  13553. gPrintStats = 1;
  13554. }
  13555. #endif
  13556. else if (string_matches(argv[1], "-blocks")) {
  13557. argc--;
  13558. argv++;
  13559. if (argc > 1)
  13560. numBlocks = XATOI(argv[1]);
  13561. }
  13562. #ifndef NO_FILESYSTEM
  13563. else if (string_matches(argv[1], "-hash_input")) {
  13564. argc--;
  13565. argv++;
  13566. if (argc > 1)
  13567. hash_input = argv[1];
  13568. }
  13569. else if (string_matches(argv[1], "-cipher_input")) {
  13570. argc--;
  13571. argv++;
  13572. if (argc > 1)
  13573. cipher_input = argv[1];
  13574. }
  13575. #endif
  13576. #ifdef MULTI_VALUE_STATISTICS
  13577. else if (string_matches(argv[1], "-min_runs")) {
  13578. argc--;
  13579. argv++;
  13580. if (argc > 1) {
  13581. minimum_runs = XATOI(argv[1]);
  13582. }
  13583. }
  13584. #endif
  13585. else if (argv[1][0] == '-') {
  13586. optMatched = 0;
  13587. #ifndef WOLFSSL_BENCHMARK_ALL
  13588. /* Check known algorithm choosing command line options. */
  13589. /* Known cipher algorithms */
  13590. for (i=0; !optMatched && bench_cipher_opt[i].str != NULL; i++) {
  13591. if (string_matches(argv[1], bench_cipher_opt[i].str)) {
  13592. bench_cipher_algs |= bench_cipher_opt[i].val;
  13593. bench_all = 0;
  13594. optMatched = 1;
  13595. }
  13596. }
  13597. /* Known digest algorithms */
  13598. for (i=0; !optMatched && bench_digest_opt[i].str != NULL; i++) {
  13599. if (string_matches(argv[1], bench_digest_opt[i].str)) {
  13600. bench_digest_algs |= bench_digest_opt[i].val;
  13601. bench_all = 0;
  13602. optMatched = 1;
  13603. }
  13604. }
  13605. /* Known MAC algorithms */
  13606. for (i=0; !optMatched && bench_mac_opt[i].str != NULL; i++) {
  13607. if (string_matches(argv[1], bench_mac_opt[i].str)) {
  13608. bench_mac_algs |= bench_mac_opt[i].val;
  13609. bench_all = 0;
  13610. optMatched = 1;
  13611. }
  13612. }
  13613. /* Known KDF algorithms */
  13614. for (i=0; !optMatched && bench_kdf_opt[i].str != NULL; i++) {
  13615. if (string_matches(argv[1], bench_kdf_opt[i].str)) {
  13616. bench_kdf_algs |= bench_kdf_opt[i].val;
  13617. bench_all = 0;
  13618. optMatched = 1;
  13619. }
  13620. }
  13621. /* Known asymmetric algorithms */
  13622. for (i=0; !optMatched && bench_asym_opt[i].str != NULL; i++) {
  13623. if (string_matches(argv[1], bench_asym_opt[i].str)) {
  13624. bench_asym_algs |= bench_asym_opt[i].val;
  13625. bench_all = 0;
  13626. optMatched = 1;
  13627. }
  13628. }
  13629. #if defined(WOLFSSL_HAVE_KYBER) || defined(HAVE_FALCON) || \
  13630. defined(HAVE_DILITHIUM) || defined(HAVE_SPHINCS)
  13631. /* Known asymmetric post-quantum algorithms */
  13632. for (i=0; !optMatched && bench_pq_asym_opt[i].str != NULL; i++) {
  13633. if (string_matches(argv[1], bench_pq_asym_opt[i].str)) {
  13634. bench_pq_asym_algs |= bench_pq_asym_opt[i].val;
  13635. bench_all = 0;
  13636. optMatched = 1;
  13637. }
  13638. }
  13639. #ifdef HAVE_SPHINCS
  13640. /* Both bench_pq_asym_opt and bench_pq_asym_opt2 are looking for
  13641. * -pq, so we need to do a special case for -pq since optMatched
  13642. * was set to 1 just above. */
  13643. if ((bench_pq_asym_opt[0].str != NULL) &&
  13644. string_matches(argv[1], bench_pq_asym_opt[0].str))
  13645. {
  13646. bench_pq_asym_algs2 |= bench_pq_asym_opt2[0].val;
  13647. bench_all = 0;
  13648. optMatched = 1;
  13649. }
  13650. for (i=1; !optMatched && bench_pq_asym_opt2[i].str != NULL; i++) {
  13651. if (string_matches(argv[1], bench_pq_asym_opt2[i].str)) {
  13652. bench_pq_asym_algs2 |= bench_pq_asym_opt2[i].val;
  13653. bench_all = 0;
  13654. optMatched = 1;
  13655. }
  13656. }
  13657. #endif
  13658. #endif
  13659. /* Other known cryptographic algorithms */
  13660. for (i=0; !optMatched && bench_other_opt[i].str != NULL; i++) {
  13661. if (string_matches(argv[1], bench_other_opt[i].str)) {
  13662. bench_other_algs |= bench_other_opt[i].val;
  13663. bench_all = 0;
  13664. optMatched = 1;
  13665. }
  13666. }
  13667. #if defined(BENCH_PQ_STATEFUL_HBS)
  13668. /* post-quantum stateful hash-based signatures */
  13669. for (i=0; !optMatched && bench_pq_hash_sig_opt[i].str != NULL; i++) {
  13670. if (string_matches(argv[1], bench_pq_hash_sig_opt[i].str)) {
  13671. bench_pq_hash_sig_algs |= bench_pq_hash_sig_opt[i].val;
  13672. bench_all = 0;
  13673. optMatched = 1;
  13674. }
  13675. }
  13676. #endif /* BENCH_PQ_STATEFUL_HBS */
  13677. #endif
  13678. if (!optMatched) {
  13679. printf("Option not recognized: %s\n", argv[1]);
  13680. Usage();
  13681. return 1;
  13682. }
  13683. }
  13684. else {
  13685. /* parse for block size */
  13686. benchmark_configure((word32)XATOI(argv[1]));
  13687. }
  13688. argc--;
  13689. argv++;
  13690. }
  13691. #endif /* MAIN_NO_ARGS */
  13692. #if defined(WOLFSSL_BENCHMARK_FIXED_CSV)
  13693. /* when defined, we'll always output CSV regardless of params.
  13694. ** this is typically convenient in embedded environments.
  13695. */
  13696. csv_format = 1;
  13697. #endif
  13698. #if defined(WC_ENABLE_BENCH_THREADING) && !defined(WOLFSSL_ASYNC_CRYPT)
  13699. if (g_threadCount > 1) {
  13700. ret = benchmark_test_threaded(NULL);
  13701. }
  13702. else
  13703. #endif
  13704. {
  13705. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13706. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13707. defined(CONFIG_IDF_TARGET_ESP32C6)
  13708. {
  13709. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13710. if (esp_gptimer == NULL) {
  13711. ESP_ERROR_CHECK(gptimer_new_timer(&esp_timer_config,
  13712. &esp_gptimer) );
  13713. }
  13714. ESP_ERROR_CHECK(gptimer_enable(esp_gptimer));
  13715. ESP_ERROR_CHECK(gptimer_start(esp_gptimer));
  13716. ESP_LOGI(TAG, "Enable %s timer", CONFIG_IDF_TARGET);
  13717. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13718. }
  13719. #endif
  13720. #ifdef HAVE_STACK_SIZE
  13721. ret = StackSizeCheck(NULL, benchmark_test);
  13722. #else
  13723. ret = benchmark_test(NULL);
  13724. #endif
  13725. }
  13726. #if defined(CONFIG_IDF_TARGET_ESP32C2) || \
  13727. defined(CONFIG_IDF_TARGET_ESP32C3) || \
  13728. defined(CONFIG_IDF_TARGET_ESP32C6)
  13729. {
  13730. #ifdef WOLFSSL_BENCHMARK_TIMER_DEBUG
  13731. ESP_ERROR_CHECK(gptimer_stop(esp_gptimer));
  13732. ESP_ERROR_CHECK(gptimer_disable(esp_gptimer));
  13733. #endif /* WOLFSSL_BENCHMARK_TIMER_DEBUG */
  13734. }
  13735. #endif
  13736. return ret;
  13737. }
  13738. #endif /* !NO_MAIN_DRIVER */
  13739. #else
  13740. #if !defined(NO_MAIN_DRIVER) && !defined(NO_MAIN_FUNCTION)
  13741. int main(void) { return 0; }
  13742. #endif
  13743. #endif /* !NO_CRYPT_BENCHMARK */